Qt 4.8
Public Functions | Static Private Functions | Properties | Friends | List of all members
QEglContext Class Reference

#include <qeglcontext_p.h>

Public Functions

QEgl::API api () const
 
bool chooseConfig (const QEglProperties &properties, QEgl::PixelFormatMatch match=QEgl::ExactPixelFormat)
 
EGLConfig config () const
 
int configAttrib (int name) const
 
EGLContext context () const
 
bool createContext (QEglContext *shareContext=0, const QEglProperties *properties=0)
 
EGLSurface createSurface (QPaintDevice *device, const QEglProperties *properties=0)
 
void destroyContext ()
 
void destroySurface (EGLSurface surface)
 
EGLDisplay display ()
 
bool doneCurrent ()
 
bool isCurrent () const
 
bool isSharing () const
 
bool isValid () const
 
bool lazyDoneCurrent ()
 
bool makeCurrent (EGLSurface surface)
 
 QEglContext ()
 
void setApi (QEgl::API api)
 
void setConfig (EGLConfig config)
 
void setContext (EGLContext context)
 
bool swapBuffers (EGLSurface surface)
 
bool swapBuffersRegion2NOK (EGLSurface surface, const QRegion *region)
 
 ~QEglContext ()
 

Static Private Functions

static QEglContextcurrentContext (QEgl::API api)
 
static void setCurrentContext (QEgl::API api, QEglContext *context)
 

Properties

bool apiChanged
 
QEgl::API apiType
 
EGLConfig cfg
 
EGLContext ctx
 
bool current
 
EGLSurface currentSurface
 
bool ownsContext
 
bool sharing
 

Friends

class QMeeGoGraphicsSystem
 
class QMeeGoPixmapData
 

Detailed Description

Definition at line 64 of file qeglcontext_p.h.

Constructors and Destructors

◆ QEglContext()

QEglContext::QEglContext ( )

Definition at line 92 of file qegl.cpp.

94  , ctx(EGL_NO_CONTEXT)
96  , currentSurface(EGL_NO_SURFACE)
97  , current(false)
98  , ownsContext(true)
99  , sharing(false)
100  , apiChanged(false)
101 {
103 }
EGLContext ctx
EGLConfig cfg
EGLSurface currentSurface
QEgl::API apiType
#define QEGL_NO_CONFIG
Definition: qegl_p.h:129
static void ref()
Definition: qegl.cpp:67

◆ ~QEglContext()

QEglContext::~QEglContext ( )

Definition at line 105 of file qegl.cpp.

106 {
107  destroyContext();
108 
109  if (currentGLContext == this)
110  currentGLContext = 0;
111  if (currentVGContext == this)
112  currentVGContext = 0;
114 }
static QEglContext *volatile currentGLContext
Definition: qegl.cpp:89
void destroyContext()
Definition: qegl.cpp:425
static void deref()
Definition: qegl.cpp:68
static QEglContext *volatile currentVGContext
Definition: qegl.cpp:90

Functions

◆ api()

QEgl::API QEglContext::api ( ) const
inline

Definition at line 74 of file qeglcontext_p.h.

74 { return apiType; }
QEgl::API apiType

◆ chooseConfig()

bool QEglContext::chooseConfig ( const QEglProperties properties,
QEgl::PixelFormatMatch  match = QEgl::ExactPixelFormat 
)

Definition at line 348 of file qegl.cpp.

Referenced by createContext(), and QEgl::defaultConfig().

349 {
350  cfg = QEgl::chooseConfig(&properties, match);
351  return cfg != QEGL_NO_CONFIG;
352 }
static bool match(const uchar *found, const char *target, uint len)
EGLConfig cfg
#define QEGL_NO_CONFIG
Definition: qegl_p.h:129
Q_GUI_EXPORT EGLConfig chooseConfig(const QEglProperties *configAttribs, QEgl::PixelFormatMatch match=QEgl::ExactPixelFormat)
Definition: qegl.cpp:288

◆ config()

EGLConfig QEglContext::config ( ) const
inline

◆ configAttrib()

int QEglContext::configAttrib ( int  name) const

Definition at line 568 of file qegl.cpp.

Referenced by qt_vg_config_to_image_format(), and qt_vg_unregister_pixmap().

569 {
570  EGLint value;
571  EGLBoolean success = eglGetConfigAttrib(QEgl::display(), cfg, name, &value);
572  if (success)
573  return value;
574  else
575  return EGL_DONT_CARE;
576 }
EGLConfig cfg
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
const char * name

◆ context()

EGLContext QEglContext::context ( ) const
inline

Definition at line 91 of file qeglcontext_p.h.

Referenced by QVGEGLWindowSurfaceDirect::ensureContext(), and setCurrentContext().

91 { return ctx; }
EGLContext ctx

◆ createContext()

bool QEglContext::createContext ( QEglContext shareContext = 0,
const QEglProperties properties = 0 
)

Definition at line 361 of file qegl.cpp.

Referenced by createContext(), and QX11GLSharedContexts::QX11GLSharedContexts().

362 {
363  // We need to select the correct API before calling eglCreateContext().
364 #ifdef QT_OPENGL_ES
365 #ifdef EGL_OPENGL_ES_API
366  if (apiType == QEgl::OpenGL)
367  eglBindAPI(EGL_OPENGL_ES_API);
368 #endif
369 #else
370 #ifdef EGL_OPENGL_API
371  if (apiType == QEgl::OpenGL)
372  eglBindAPI(EGL_OPENGL_API);
373 #endif
374 #endif //defined(QT_OPENGL_ES)
375 #ifdef EGL_OPENVG_API
376  if (apiType == QEgl::OpenVG)
377  eglBindAPI(EGL_OPENVG_API);
378 #endif
379 
380  // Create a new context for the configuration.
381  QEglProperties contextProps;
382  if (properties)
383  contextProps = *properties;
384 #ifdef QT_OPENGL_ES_2
385  if (apiType == QEgl::OpenGL)
386  contextProps.setValue(EGL_CONTEXT_CLIENT_VERSION, 2);
387 #endif
388  sharing = false;
389  if (shareContext && shareContext->ctx == EGL_NO_CONTEXT)
390  shareContext = 0;
391  if (shareContext) {
392  ctx = eglCreateContext(QEgl::display(), cfg, shareContext->ctx, contextProps.properties());
393  if (ctx == EGL_NO_CONTEXT) {
394  qWarning() << "QEglContext::createContext(): Could not share context:" << QEgl::errorString();
395  shareContext = 0;
396  } else {
397  sharing = true;
398  }
399  }
400  if (ctx == EGL_NO_CONTEXT) {
401  ctx = eglCreateContext(display(), cfg, EGL_NO_CONTEXT, contextProps.properties());
402  if (ctx == EGL_NO_CONTEXT) {
403  qWarning() << "QEglContext::createContext(): Unable to create EGL context:" << QEgl::errorString();
404 #ifdef Q_OS_SYMBIAN
405  S60->eglSurfaceCreationError = true;
406 #endif
407  return false;
408  }
409  }
410  return true;
411 }
const EGLint * properties() const
void setValue(int name, int value)
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
EGLContext ctx
EGLConfig cfg
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
Q_CORE_EXPORT void qWarning(const char *,...)
QEgl::API apiType
EGLDisplay display()
Definition: qeglcontext_p.h:94
static const QCssKnownValue properties[NumProperties - 1]
Definition: qcssparser.cpp:67

◆ createSurface()

EGLSurface QEglContext::createSurface ( QPaintDevice device,
const QEglProperties properties = 0 
)

Definition at line 354 of file qegl.cpp.

Referenced by QVGEGLWindowSurfaceDirect::ensureContext().

355 {
356  return QEgl::createSurface(device, cfg, properties);
357 }
EGLConfig cfg
Q_GUI_EXPORT EGLSurface createSurface(QPaintDevice *device, EGLConfig cfg, const QEglProperties *surfaceAttribs=0)
Definition: qegl_x11.cpp:333

◆ currentContext()

QEglContext * QEglContext::currentContext ( QEgl::API  api)
staticprivate

Definition at line 799 of file qegl.cpp.

Referenced by QMeeGoPixmapData::imageToEGLSharedImage(), makeCurrent(), and QMeeGoGraphicsSystem::setSurfaceScaling().

800 {
801  if (api == QEgl::OpenGL)
802  return currentGLContext;
803  else
804  return currentVGContext;
805 }
static QEglContext *volatile currentGLContext
Definition: qegl.cpp:89
QEgl::API api() const
Definition: qeglcontext_p.h:74
static QEglContext *volatile currentVGContext
Definition: qegl.cpp:90

◆ destroyContext()

void QEglContext::destroyContext ( )

Definition at line 425 of file qegl.cpp.

Referenced by ~QEglContext().

426 {
427  if (ctx != EGL_NO_CONTEXT && ownsContext)
428  eglDestroyContext(display(), ctx);
429  ctx = EGL_NO_CONTEXT;
430  cfg = 0;
431 }
EGLContext ctx
EGLConfig cfg
EGLDisplay display()
Definition: qeglcontext_p.h:94

◆ destroySurface()

void QEglContext::destroySurface ( EGLSurface  surface)

Definition at line 415 of file qegl.cpp.

Referenced by QVGEGLWindowSurfaceDirect::ensureContext(), QVGEGLWindowSurfacePrivate::windowSurfaceSize(), QVGEGLWindowSurfaceDirect::~QVGEGLWindowSurfaceDirect(), and QVGSharedContext::~QVGSharedContext().

416 {
417  if (surface != EGL_NO_SURFACE) {
418  if (surface == currentSurface)
419  doneCurrent();
420  eglDestroySurface(display(), surface);
421  }
422 }
bool doneCurrent()
Definition: qegl.cpp:485
EGLSurface currentSurface
EGLDisplay display()
Definition: qeglcontext_p.h:94

◆ display()

EGLDisplay QEglContext::display ( )
inline

◆ doneCurrent()

bool QEglContext::doneCurrent ( )

Definition at line 485 of file qegl.cpp.

Referenced by destroySurface(), QVGEGLWindowSurfaceDirect::ensureContext(), qt_vg_destroy_shared_context(), QX11GLSharedContexts::QX11GLSharedContexts(), QVGEGLWindowSurfacePrivate::windowSurfaceSize(), and QVGSharedContext::~QVGSharedContext().

486 {
487  // If the context is invalid, we assume that an error was reported
488  // when makeCurrent() was called.
489  if (ctx == EGL_NO_CONTEXT)
490  return false;
491 
492  current = false;
493  currentSurface = EGL_NO_SURFACE;
495 
496  // We need to select the correct API before calling eglMakeCurrent()
497  // with EGL_NO_CONTEXT because threads can have both OpenGL and OpenVG
498  // contexts active at the same time.
499 #ifdef EGL_OPENGL_ES_API
500  if (apiType == QEgl::OpenGL)
501  eglBindAPI(EGL_OPENGL_ES_API);
502 #endif
503 #ifdef EGL_OPENVG_API
504  if (apiType == QEgl::OpenVG)
505  eglBindAPI(EGL_OPENVG_API);
506 #endif
507 
508  bool ok = eglMakeCurrent(QEgl::display(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
509  if (!ok)
510  qWarning() << "QEglContext::doneCurrent():" << QEgl::errorString();
511  return ok;
512 }
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
EGLContext ctx
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
EGLSurface currentSurface
Q_CORE_EXPORT void qWarning(const char *,...)
QEgl::API apiType
static void setCurrentContext(QEgl::API api, QEglContext *context)
Definition: qegl.cpp:807

◆ isCurrent()

bool QEglContext::isCurrent ( ) const

Definition at line 121 of file qegl.cpp.

Referenced by QVGPixmapData::destroyImageAndContext().

122 {
123  return current;
124 }

◆ isSharing()

bool QEglContext::isSharing ( ) const
inline

Definition at line 72 of file qeglcontext_p.h.

72 { return sharing; }

◆ isValid()

bool QEglContext::isValid ( ) const

Definition at line 116 of file qegl.cpp.

Referenced by QX11GLSharedContexts::QX11GLSharedContexts().

117 {
118  return (ctx != EGL_NO_CONTEXT);
119 }
EGLContext ctx

◆ lazyDoneCurrent()

bool QEglContext::lazyDoneCurrent ( )

◆ makeCurrent()

bool QEglContext::makeCurrent ( EGLSurface  surface)

Definition at line 433 of file qegl.cpp.

Referenced by QVGEGLWindowSurfaceDirect::beginPaint(), QVGPixmapData::destroyImageAndContext(), QVGEGLWindowSurfaceDirect::endPaint(), qt_vg_destroy_shared_context(), qt_vg_hibernate_pixmaps(), QX11GLSharedContexts::QX11GLSharedContexts(), QVGEGLWindowSurfaceDirect::scroll(), QVGEGLWindowSurfacePrivate::windowSurfaceSize(), and QVGSharedContext::~QVGSharedContext().

434 {
435  if (ctx == EGL_NO_CONTEXT) {
436  qWarning() << "QEglContext::makeCurrent(): Cannot make invalid context current";
437  return false;
438  }
439 
440  if (surface == EGL_NO_SURFACE) {
441  qWarning() << "QEglContext::makeCurrent(): Cannot make invalid surface current";
442  return false;
443  }
444 
445 #ifdef Q_OS_SYMBIAN
446  apiChanged = false;
448  && currentContext(apiType)->ctx != eglGetCurrentContext()) {
449  // some other EGL based API active. Complete its rendering
450  eglWaitClient();
451  apiChanged = true;
452  }
453 #endif
454 
455  // If lazyDoneCurrent() was called on the surface, then we may be able
456  // to assume that it is still current within the thread.
457  if (surface == currentSurface && currentContext(apiType) == this
458  && !apiChanged) {
459  current = true;
460  return true;
461  }
462 
463  current = true;
464  currentSurface = surface;
465  setCurrentContext(apiType, this);
466 
467  // Force the right API to be bound before making the context current.
468  // The EGL implementation should be able to figure this out from ctx,
469  // but some systems require the API to be explicitly set anyway.
470 #ifdef EGL_OPENGL_ES_API
471  if (apiType == QEgl::OpenGL)
472  eglBindAPI(EGL_OPENGL_ES_API);
473 #endif
474 #ifdef EGL_OPENVG_API
475  if (apiType == QEgl::OpenVG)
476  eglBindAPI(EGL_OPENVG_API);
477 #endif
478 
479  bool ok = eglMakeCurrent(QEgl::display(), surface, surface, ctx);
480  if (!ok)
481  qWarning() << "QEglContext::makeCurrent(" << surface << "):" << QEgl::errorString();
482  return ok;
483 }
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
EGLContext ctx
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
EGLSurface currentSurface
Q_CORE_EXPORT void qWarning(const char *,...)
QEgl::API apiType
static QEglContext * currentContext(QEgl::API api)
Definition: qegl.cpp:799
static void setCurrentContext(QEgl::API api, QEglContext *context)
Definition: qegl.cpp:807

◆ setApi()

void QEglContext::setApi ( QEgl::API  api)
inline

Definition at line 75 of file qeglcontext_p.h.

Referenced by createContext().

75 { apiType = api; }
QEgl::API api() const
Definition: qeglcontext_p.h:74
QEgl::API apiType

◆ setConfig()

void QEglContext::setConfig ( EGLConfig  config)
inline

Definition at line 97 of file qeglcontext_p.h.

Referenced by createContext(), and QX11GLSharedContexts::QX11GLSharedContexts().

97 { cfg = config; }
EGLConfig config() const
Definition: qeglcontext_p.h:96
EGLConfig cfg

◆ setContext()

void QEglContext::setContext ( EGLContext  context)
inline

Definition at line 92 of file qeglcontext_p.h.

92 { ctx = context; ownsContext = false;}
EGLContext ctx
EGLContext context() const
Definition: qeglcontext_p.h:91

◆ setCurrentContext()

void QEglContext::setCurrentContext ( QEgl::API  api,
QEglContext context 
)
staticprivate

Definition at line 807 of file qegl.cpp.

Referenced by doneCurrent(), and makeCurrent().

808 {
809  if (api == QEgl::OpenGL)
811  else
813 }
EGLContext context() const
Definition: qeglcontext_p.h:91
static QEglContext *volatile currentGLContext
Definition: qegl.cpp:89
QEgl::API api() const
Definition: qeglcontext_p.h:74
static QEglContext *volatile currentVGContext
Definition: qegl.cpp:90

◆ swapBuffers()

bool QEglContext::swapBuffers ( EGLSurface  surface)

Definition at line 525 of file qegl.cpp.

Referenced by QVGEGLWindowSurfaceDirect::endPaint().

526 {
527  if(ctx == EGL_NO_CONTEXT)
528  return false;
529 
530  bool ok = eglSwapBuffers(QEgl::display(), surface);
531  if (!ok)
532  qWarning() << "QEglContext::swapBuffers():" << QEgl::errorString();
533 
534 #ifdef Q_OS_SYMBIAN
535  if (apiChanged) {
536  eglWaitClient();
537  apiChanged = false;
538  }
539 #endif
540  return ok;
541 }
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
EGLContext ctx
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
Q_CORE_EXPORT void qWarning(const char *,...)

◆ swapBuffersRegion2NOK()

bool QEglContext::swapBuffersRegion2NOK ( EGLSurface  surface,
const QRegion region 
)

Definition at line 543 of file qegl.cpp.

543  {
544  QVector<QRect> qrects = region->rects();
545  EGLint *gl_rects;
546  uint count;
547  uint i;
548 
549  count = qrects.size();
550  QVarLengthArray <EGLint> arr(4 * count);
551  gl_rects = arr.data();
552  for (i = 0; i < count; i++) {
553  QRect qrect = qrects[i];
554 
555  gl_rects[4 * i + 0] = qrect.x();
556  gl_rects[4 * i + 1] = qrect.y();
557  gl_rects[4 * i + 2] = qrect.width();
558  gl_rects[4 * i + 3] = qrect.height();
559  }
560 
561  bool ok = QEgl::eglSwapBuffersRegion2NOK(QEgl::display(), surface, count, gl_rects);
562 
563  if (!ok)
564  qWarning() << "QEglContext::swapBuffersRegion2NOK():" << QEgl::errorString();
565  return ok;
566 }
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int uint
Definition: qglobal.h:996
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QVector< QRect > rects() const
Returns an array of non-overlapping rectangles that make up the region.
Definition: qregion.cpp:4412
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Q_GUI_EXPORT EGLBoolean eglSwapBuffersRegion2NOK(EGLDisplay dpy, EGLSurface surface, EGLint count, const EGLint *rects)
Definition: qegl.cpp:651
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

Friends and Related Functions

◆ QMeeGoGraphicsSystem

friend class QMeeGoGraphicsSystem
friend

Definition at line 112 of file qeglcontext_p.h.

◆ QMeeGoPixmapData

friend class QMeeGoPixmapData
friend

Definition at line 113 of file qeglcontext_p.h.

Properties

◆ apiChanged

bool QEglContext::apiChanged
private

Definition at line 107 of file qeglcontext_p.h.

Referenced by makeCurrent(), and swapBuffers().

◆ apiType

QEgl::API QEglContext::apiType
private

Definition at line 100 of file qeglcontext_p.h.

Referenced by createContext(), doneCurrent(), and makeCurrent().

◆ cfg

EGLConfig QEglContext::cfg
private

◆ ctx

EGLContext QEglContext::ctx
private

◆ current

bool QEglContext::current
private

Definition at line 104 of file qeglcontext_p.h.

Referenced by doneCurrent(), isCurrent(), lazyDoneCurrent(), and makeCurrent().

◆ currentSurface

EGLSurface QEglContext::currentSurface
private

Definition at line 103 of file qeglcontext_p.h.

Referenced by destroySurface(), doneCurrent(), and makeCurrent().

◆ ownsContext

bool QEglContext::ownsContext
private

Definition at line 105 of file qeglcontext_p.h.

Referenced by destroyContext().

◆ sharing

bool QEglContext::sharing
private

Definition at line 106 of file qeglcontext_p.h.

Referenced by createContext().


The documentation for this class was generated from the following files: