Qt 4.8
Classes | Macros | Functions
qwindowsurface_vgegl.cpp File Reference
#include "qwindowsurface_vgegl_p.h"
#include "qpaintengine_vg_p.h"
#include "qpixmapdata_vg_p.h"
#include "qvgimagepool_p.h"
#include "qvg_p.h"

Go to the source code of this file.

Classes

class  QVGSharedContext
 

Macros

#define QVG_NO_PRESERVED_SWAP   1
 

Functions

static QEglContextcreateContext (QPaintDevice *device)
 
 Q_GLOBAL_STATIC (QVGSharedContext, sharedContext)
 
QImage::Format qt_vg_config_to_image_format (QEglContext *context)
 
VGImageFormat qt_vg_config_to_vg_format (QEglContext *context)
 
QEglContextqt_vg_create_context (QPaintDevice *device, int devType)
 
QVGPaintEngineqt_vg_create_paint_engine (void)
 
void qt_vg_destroy_context (QEglContext *context, int devType)
 
void qt_vg_destroy_paint_engine (QVGPaintEngine *engine)
 
static void qt_vg_destroy_shared_context (QVGSharedContext *shared)
 
void qt_vg_hibernate_pixmaps (QVGSharedContext *shared)
 
void qt_vg_register_pixmap (QVGPixmapData *pd)
 
EGLSurface qt_vg_shared_surface (void)
 
void qt_vg_unregister_pixmap (QVGPixmapData *pd)
 

Macro Definition Documentation

◆ QVG_NO_PRESERVED_SWAP

#define QVG_NO_PRESERVED_SWAP   1

Definition at line 62 of file qwindowsurface_vgegl.cpp.

Function Documentation

◆ createContext()

static QEglContext* createContext ( QPaintDevice device)
static

Definition at line 213 of file qwindowsurface_vgegl.cpp.

Referenced by qt_vg_create_context(), qt_vg_shared_surface(), and QEglContext::setApi().

214 {
215  QEglContext *context;
216 
217  // Create the context object and open the display.
218  context = new QEglContext();
219  context->setApi(QEgl::OpenVG);
220 
221  // Set the swap interval for the display.
222  QByteArray interval = qgetenv("QT_VG_SWAP_INTERVAL");
223  if (!interval.isEmpty())
224  eglSwapInterval(QEgl::display(), interval.toInt());
225  else
226  eglSwapInterval(QEgl::display(), 1);
227 
228 #ifdef EGL_RENDERABLE_TYPE
229  // Has the user specified an explicit EGL configuration to use?
230  QByteArray configId = qgetenv("QT_VG_EGL_CONFIG");
231  if (!configId.isEmpty()) {
232  EGLint cfgId = configId.toInt();
233  EGLint properties[] = {
234  EGL_CONFIG_ID, cfgId,
235  EGL_NONE
236  };
237  EGLint matching = 0;
238  EGLConfig cfg;
239  if (eglChooseConfig
240  (QEgl::display(), properties, &cfg, 1, &matching) &&
241  matching > 0) {
242  // Check that the selected configuration actually supports OpenVG
243  // and then create the context with it.
244  EGLint id = 0;
245  EGLint type = 0;
246  eglGetConfigAttrib
247  (QEgl::display(), cfg, EGL_CONFIG_ID, &id);
248  eglGetConfigAttrib
249  (QEgl::display(), cfg, EGL_RENDERABLE_TYPE, &type);
250  if (cfgId == id && (type & EGL_OPENVG_BIT) != 0) {
251  context->setConfig(cfg);
252  if (!context->createContext()) {
253  delete context;
254  return 0;
255  }
256  return context;
257  } else {
258  qWarning("QT_VG_EGL_CONFIG: %d is not a valid OpenVG configuration", int(cfgId));
259  }
260  }
261  }
262 #endif
263 
264  // Choose an appropriate configuration for rendering into the device.
265  QEglProperties configProps;
266  configProps.setPaintDeviceFormat(device);
267  int redSize = configProps.value(EGL_RED_SIZE);
268  if (redSize == EGL_DONT_CARE || redSize == 0)
269  configProps.setPixelFormat(QImage::Format_ARGB32); // XXX
270  configProps.setValue(EGL_ALPHA_MASK_SIZE, 1);
271 #ifdef EGL_VG_ALPHA_FORMAT_PRE_BIT
272  configProps.setValue(EGL_SURFACE_TYPE, EGL_WINDOW_BIT
273  | EGL_SWAP_BEHAVIOR_PRESERVED_BIT
274  | EGL_VG_ALPHA_FORMAT_PRE_BIT);
275  configProps.setRenderableType(QEgl::OpenVG);
276  if (!context->chooseConfig(configProps)) {
277  // Try again without the "pre" bit.
278  configProps.setValue(EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_SWAP_BEHAVIOR_PRESERVED_BIT);
279  if (!context->chooseConfig(configProps)) {
280  delete context;
281  return 0;
282  }
283  }
284 #else
285  configProps.setValue(EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_SWAP_BEHAVIOR_PRESERVED_BIT);
286  configProps.setRenderableType(QEgl::OpenVG);
287  if (!context->chooseConfig(configProps)) {
288  delete context;
289  return 0;
290  }
291 #endif
292 
293  // Construct a new EGL context for the selected configuration.
294  if (!context->createContext()) {
295  delete context;
296  return 0;
297  }
298 
299  return context;
300 }
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
int type
Definition: qmetatype.cpp:239
bool createContext(QEglContext *shareContext=0, const QEglProperties *properties=0)
Definition: qegl.cpp:361
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int value(int name) const
bool chooseConfig(const QEglProperties &properties, QEgl::PixelFormatMatch match=QEgl::ExactPixelFormat)
Definition: qegl.cpp:348
void setValue(int name, int value)
void setApi(QEgl::API api)
Definition: qeglcontext_p.h:75
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
void setRenderableType(QEgl::API api)
Q_CORE_EXPORT void qWarning(const char *,...)
int toInt(bool *ok=0, int base=10) const
Returns the byte array converted to an int using base base, which is 10 by default and must be betwee...
void setConfig(EGLConfig config)
Definition: qeglcontext_p.h:97
void setPaintDeviceFormat(QPaintDevice *dev)
Definition: qegl_qpa.cpp:93
static const QCssKnownValue properties[NumProperties - 1]
Definition: qcssparser.cpp:67
void setPixelFormat(QImage::Format pixelFormat)
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421

◆ Q_GLOBAL_STATIC()

Q_GLOBAL_STATIC ( QVGSharedContext  ,
sharedContext   
)

◆ qt_vg_config_to_image_format()

QImage::Format qt_vg_config_to_image_format ( QEglContext context)

Definition at line 72 of file qwindowsurface_vgegl.cpp.

Referenced by qt_vg_config_to_vg_format().

73 {
74  EGLint red = context->configAttrib(EGL_RED_SIZE);
75  EGLint green = context->configAttrib(EGL_GREEN_SIZE);
76  EGLint blue = context->configAttrib(EGL_BLUE_SIZE);
77  EGLint alpha = context->configAttrib(EGL_ALPHA_SIZE);
78  QImage::Format argbFormat;
79 #ifdef EGL_VG_ALPHA_FORMAT_PRE_BIT
80  EGLint type = context->configAttrib(EGL_SURFACE_TYPE);
81  if ((type & EGL_VG_ALPHA_FORMAT_PRE_BIT) != 0)
83  else
84  argbFormat = QImage::Format_ARGB32;
85 #else
86  argbFormat = QImage::Format_ARGB32;
87 #endif
88  if (red == 8 && green == 8 && blue == 8 && alpha == 8)
89  return argbFormat;
90  else if (red == 8 && green == 8 && blue == 8 && alpha == 0)
91  return QImage::Format_RGB32;
92  else if (red == 5 && green == 6 && blue == 5 && alpha == 0)
93  return QImage::Format_RGB16;
94  else if (red == 4 && green == 4 && blue == 4 && alpha == 4)
96  else
97  return argbFormat; // XXX
98 }
Format
The following image formats are available in Qt.
Definition: qimage.h:91
int type
Definition: qmetatype.cpp:239
int configAttrib(int name) const
Definition: qegl.cpp:568

◆ qt_vg_config_to_vg_format()

VGImageFormat qt_vg_config_to_vg_format ( QEglContext context)

Definition at line 66 of file qwindowsurface_vgegl.cpp.

Referenced by QVGEGLWindowSurfacePrivate::windowSurfaceSize().

67 {
70 }
VGImageFormat qt_vg_image_to_vg_format(QImage::Format format)
QImage::Format qt_vg_config_to_image_format(QEglContext *context)

◆ qt_vg_create_context()

QEglContext* qt_vg_create_context ( QPaintDevice device,
int  devType 
)

Definition at line 304 of file qwindowsurface_vgegl.cpp.

Referenced by QVGPixmapData::destroyImageAndContext(), QVGEGLWindowSurfaceDirect::ensureContext(), qt_vg_shared_surface(), QVGPixmapData::toVGImage(), and QVGEGLWindowSurfacePrivate::windowSurfaceSize().

305 {
306  QVGSharedContext *shared = sharedContext();
307  if (devType == QInternal::Widget)
308  ++(shared->widgetRefCount);
309  if (shared->context) {
310  ++(shared->refCount);
311  return shared->context;
312  } else {
313  shared->context = createContext(device);
314  shared->refCount = 1;
315  return shared->context;
316  }
317 }
static QEglContext * createContext(QPaintDevice *device)

◆ qt_vg_create_paint_engine()

QVGPaintEngine* qt_vg_create_paint_engine ( void  )

Definition at line 144 of file qwindowsurface_vgegl.cpp.

Referenced by QVGEGLWindowSurfacePrivate::paintEngine(), qt_vg_unregister_pixmap(), and QVGCompositionHelper::QVGCompositionHelper().

145 {
146  QVGSharedContext *shared = sharedContext();
147  if (!shared->engine)
148  shared->engine = new QVGPaintEngine();
149  return shared->engine;
150 }
QVGPaintEngine * engine

◆ qt_vg_destroy_context()

void qt_vg_destroy_context ( QEglContext context,
int  devType 
)

Definition at line 361 of file qwindowsurface_vgegl.cpp.

Referenced by QVGPixmapData::destroyImageAndContext(), QVGEGLWindowSurfaceDirect::ensureContext(), qt_vg_shared_surface(), QVGEGLWindowSurfacePrivate::windowSurfaceSize(), and QVGEGLWindowSurfaceDirect::~QVGEGLWindowSurfaceDirect().

362 {
363  QVGSharedContext *shared = sharedContext();
364  if (shared->context != context) {
365  // This is not the shared context. Shouldn't happen!
366  delete context;
367  return;
368  }
369  if (devType == QInternal::Widget)
370  --(shared->widgetRefCount);
371  if (--(shared->refCount) <= 0) {
373  } else if (shared->widgetRefCount <= 0 && devType == QInternal::Widget) {
374  // All of the widget window surfaces have been destroyed
375  // but we still have VG pixmaps active. Ask them to hibernate
376  // to free up GPU resources until a widget is shown again.
377  // This may eventually cause the EGLContext to be destroyed
378  // because nothing in the system needs a context, which will
379  // free up even more GPU resources.
380  qt_vg_hibernate_pixmaps(shared);
381  }
382 }
void qt_vg_hibernate_pixmaps(QVGSharedContext *shared)
static void qt_vg_destroy_shared_context(QVGSharedContext *shared)

◆ qt_vg_destroy_paint_engine()

void qt_vg_destroy_paint_engine ( QVGPaintEngine engine)

Definition at line 152 of file qwindowsurface_vgegl.cpp.

Referenced by QVGEGLWindowSurfacePrivate::destroyPaintEngine(), QVGEGLWindowSurfaceDirect::ensureContext(), and qt_vg_unregister_pixmap().

153 {
154  Q_UNUSED(engine);
155 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ qt_vg_destroy_shared_context()

static void qt_vg_destroy_shared_context ( QVGSharedContext shared)
static

Definition at line 319 of file qwindowsurface_vgegl.cpp.

Referenced by qt_vg_destroy_context(), and qt_vg_hibernate_pixmaps().

320 {
322  delete shared->engine;
323  shared->engine = 0;
324  shared->context->doneCurrent();
325  if (shared->surface != EGL_NO_SURFACE) {
326  eglDestroySurface(QEgl::display(), shared->surface);
327  shared->surface = EGL_NO_SURFACE;
328  }
329  delete shared->context;
330  shared->context = 0;
331 }
EGLSurface qt_vg_shared_surface(void)
bool doneCurrent()
Definition: qegl.cpp:485
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
bool makeCurrent(EGLSurface surface)
Definition: qegl.cpp:433
QVGPaintEngine * engine

◆ qt_vg_hibernate_pixmaps()

void qt_vg_hibernate_pixmaps ( QVGSharedContext shared)

Definition at line 333 of file qwindowsurface_vgegl.cpp.

Referenced by qt_vg_destroy_context().

334 {
335  // Artificially increase the reference count to prevent the
336  // context from being destroyed until after we have finished
337  // the hibernation process.
338  ++(shared->refCount);
339 
340  // We need a context current to hibernate the VGImage objects.
342 
343  // Scan all QVGPixmapData objects in the system and hibernate them.
344  QVGPixmapData *pd = shared->firstPixmap;
345  while (pd != 0) {
346  pd->hibernate();
347  pd = pd->next;
348  }
349 
350  // Hibernate any remaining VGImage's in the image pool.
352 
353  // Don't need the current context any more.
354  shared->context->lazyDoneCurrent();
355 
356  // Decrease the reference count and destroy the context if necessary.
357  if (--(shared->refCount) <= 0)
359 }
EGLSurface qt_vg_shared_surface(void)
QVGPixmapData * next
QVGPixmapData * firstPixmap
static void qt_vg_destroy_shared_context(QVGSharedContext *shared)
static QVGImagePool * instance()
bool lazyDoneCurrent()
Definition: qegl.cpp:519
bool makeCurrent(EGLSurface surface)
Definition: qegl.cpp:433
virtual void hibernate()
virtual void hibernate()

◆ qt_vg_register_pixmap()

void qt_vg_register_pixmap ( QVGPixmapData pd)

Definition at line 157 of file qwindowsurface_vgegl.cpp.

Referenced by qt_vg_unregister_pixmap().

158 {
159  QVGSharedContext *shared = sharedContext();
160  pd->next = shared->firstPixmap;
161  pd->prev = 0;
162  if (shared->firstPixmap)
163  shared->firstPixmap->prev = pd;
164  shared->firstPixmap = pd;
165 }
QVGPixmapData * next
QVGPixmapData * prev
QVGPixmapData * firstPixmap

◆ qt_vg_shared_surface()

EGLSurface qt_vg_shared_surface ( void  )

Definition at line 384 of file qwindowsurface_vgegl.cpp.

Referenced by QVGPixmapData::destroyImageAndContext(), qt_vg_destroy_shared_context(), qt_vg_hibernate_pixmaps(), QVGEGLWindowSurfacePrivate::windowSurfaceSize(), and QVGSharedContext::~QVGSharedContext().

385 {
386  QVGSharedContext *shared = sharedContext();
387  if (shared->surface == EGL_NO_SURFACE) {
388  EGLint attribs[7];
389  attribs[0] = EGL_WIDTH;
390  attribs[1] = 16;
391  attribs[2] = EGL_HEIGHT;
392  attribs[3] = 16;
393 #ifdef EGL_VG_ALPHA_FORMAT_PRE_BIT
394  if (isPremultipliedContext(shared->context)) {
395  attribs[4] = EGL_VG_ALPHA_FORMAT;
396  attribs[5] = EGL_VG_ALPHA_FORMAT_PRE;
397  attribs[6] = EGL_NONE;
398  } else
399 #endif
400  {
401  attribs[4] = EGL_NONE;
402  }
403  shared->surface = eglCreatePbufferSurface
404  (QEgl::display(), shared->context->config(), attribs);
405  }
406  return shared->surface;
407 }
EGLConfig config() const
Definition: qeglcontext_p.h:96
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589

◆ qt_vg_unregister_pixmap()

void qt_vg_unregister_pixmap ( QVGPixmapData pd)

Definition at line 167 of file qwindowsurface_vgegl.cpp.

168 {
169  if (pd->next)
170  pd->next->prev = pd->prev;
171  if (pd->prev) {
172  pd->prev->next = pd->next;
173  } else {
174  QVGSharedContext *shared = sharedContext();
175  if (shared)
176  shared->firstPixmap = pd->next;
177  }
178 }
QVGPixmapData * next
QVGPixmapData * prev
QVGPixmapData * firstPixmap