Qt 4.8
Public Functions | Protected Variables | List of all members
QVGEGLWindowSurfaceDirect Class Reference

#include <qwindowsurface_vgegl_p.h>

Inheritance diagram for QVGEGLWindowSurfaceDirect:
QVGEGLWindowSurfacePrivate

Public Functions

void beginPaint (QWidget *widget)
 
void endPaint (QWidget *widget, const QRegion &region, QImage *image)
 
QEglContextensureContext (QWidget *widget)
 
 QVGEGLWindowSurfaceDirect (QWindowSurface *win)
 
bool scroll (QWidget *widget, const QRegion &area, int dx, int dy)
 
bool supportsStaticContents () const
 
QSize surfaceSize () const
 
virtual ~QVGEGLWindowSurfaceDirect ()
 
- Public Functions inherited from QVGEGLWindowSurfacePrivate
QVGPaintEnginepaintEngine ()
 
 QVGEGLWindowSurfacePrivate (QWindowSurface *win)
 
virtual VGImage surfaceImage () const
 
virtual ~QVGEGLWindowSurfacePrivate ()
 

Protected Variables

QEglContextcontext
 
bool isPaintingActive
 
bool needToSwap
 
QSize size
 
EGLSurface windowSurface
 
- Protected Variables inherited from QVGEGLWindowSurfacePrivate
QVGPaintEngineengine
 
QWindowSurfacewinSurface
 

Additional Inherited Members

- Protected Functions inherited from QVGEGLWindowSurfacePrivate
void destroyPaintEngine ()
 
QSize windowSurfaceSize (QWidget *widget) const
 

Detailed Description

Definition at line 121 of file qwindowsurface_vgegl_p.h.

Constructors and Destructors

◆ QVGEGLWindowSurfaceDirect()

QVGEGLWindowSurfaceDirect::QVGEGLWindowSurfaceDirect ( QWindowSurface win)

Definition at line 608 of file qwindowsurface_vgegl.cpp.

610  , context(0)
611  , isPaintingActive(false)
612  , needToSwap(false)
613  , windowSurface(EGL_NO_SURFACE)
614 {
615 }
QVGEGLWindowSurfacePrivate(QWindowSurface *win)

◆ ~QVGEGLWindowSurfaceDirect()

QVGEGLWindowSurfaceDirect::~QVGEGLWindowSurfaceDirect ( )
virtual

Definition at line 617 of file qwindowsurface_vgegl.cpp.

618 {
620  if (context) {
621  if (windowSurface != EGL_NO_SURFACE)
624  }
625 }
void qt_vg_destroy_context(QEglContext *context, int devType)
void destroySurface(EGLSurface surface)
Definition: qegl.cpp:415

Functions

◆ beginPaint()

void QVGEGLWindowSurfaceDirect::beginPaint ( QWidget widget)
virtual

Implements QVGEGLWindowSurfacePrivate.

Definition at line 722 of file qwindowsurface_vgegl.cpp.

723 {
724  QEglContext *context = ensureContext(widget);
725  if (context) {
726  context->makeCurrent(windowSurface);
727  isPaintingActive = true;
728  }
729 }
QEglContext * ensureContext(QWidget *widget)
bool makeCurrent(EGLSurface surface)
Definition: qegl.cpp:433

◆ endPaint()

void QVGEGLWindowSurfaceDirect::endPaint ( QWidget widget,
const QRegion region,
QImage image 
)
virtual

Implements QVGEGLWindowSurfacePrivate.

Definition at line 732 of file qwindowsurface_vgegl.cpp.

Referenced by beginPaint().

733 {
734  Q_UNUSED(region);
735  Q_UNUSED(image);
736  QEglContext *context = ensureContext(widget);
737  if (context) {
738  if (needToSwap) {
739  if (!isPaintingActive)
740  context->makeCurrent(windowSurface);
741  context->swapBuffers(windowSurface);
742  context->lazyDoneCurrent();
743  } else if (isPaintingActive) {
744  vgFlush();
745  context->lazyDoneCurrent();
746  }
747  isPaintingActive = false;
748  }
749 }
bool swapBuffers(EGLSurface surface)
Definition: qegl.cpp:525
QEglContext * ensureContext(QWidget *widget)
bool lazyDoneCurrent()
Definition: qegl.cpp:519
bool makeCurrent(EGLSurface surface)
Definition: qegl.cpp:433
#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

◆ ensureContext()

QEglContext * QVGEGLWindowSurfaceDirect::ensureContext ( QWidget widget)
virtual

Implements QVGEGLWindowSurfacePrivate.

Definition at line 627 of file qwindowsurface_vgegl.cpp.

Referenced by beginPaint(), endPaint(), and scroll().

628 {
629  QSize newSize = windowSurfaceSize(widget);
630  QEglProperties surfaceProps;
631 
632 #if defined(QVG_RECREATE_ON_SIZE_CHANGE)
633 #if !defined(QVG_NO_SINGLE_CONTEXT)
634  if (context && size != newSize) {
635  // The surface size has changed, so we need to recreate it.
636  // We can keep the same context and paint engine.
637  size = newSize;
638  if (isPaintingActive)
639  context->doneCurrent();
641 #if defined(EGL_VG_ALPHA_FORMAT_PRE_BIT)
642  if (isPremultipliedContext(context)) {
643  surfaceProps.setValue
644  (EGL_VG_ALPHA_FORMAT, EGL_VG_ALPHA_FORMAT_PRE);
645  } else {
646  surfaceProps.removeValue(EGL_VG_ALPHA_FORMAT);
647  }
648 #endif
649  windowSurface = context->createSurface(widget, &surfaceProps);
650  isPaintingActive = false;
651  needToSwap = true;
652  }
653 #else
654  if (context && size != newSize) {
655  // The surface size has changed, so we need to recreate
656  // the EGL context for the widget. We also need to recreate
657  // the surface's paint engine if context sharing is not
658  // enabled because we cannot reuse the existing paint objects
659  // in the new context.
661  engine = 0;
664  context = 0;
665  windowSurface = EGL_NO_SURFACE;
666  }
667 #endif
668 #endif
669  if (!context) {
670  // Create a new EGL context and bind it to the widget surface.
671  size = newSize;
673  if (!context)
674  return 0;
675  // We want a direct to window rendering surface if possible.
676 #if defined(QVG_DIRECT_TO_WINDOW)
677  surfaceProps.setValue(EGL_RENDER_BUFFER, EGL_SINGLE_BUFFER);
678 #endif
679 #if defined(EGL_VG_ALPHA_FORMAT_PRE_BIT)
680  if (isPremultipliedContext(context)) {
681  surfaceProps.setValue
682  (EGL_VG_ALPHA_FORMAT, EGL_VG_ALPHA_FORMAT_PRE);
683  } else {
684  surfaceProps.removeValue(EGL_VG_ALPHA_FORMAT);
685  }
686 #endif
687  EGLSurface surface = context->createSurface(widget, &surfaceProps);
688  if (surface == EGL_NO_SURFACE) {
690  engine = 0;
692  context = 0;
693  return 0;
694  }
695  needToSwap = true;
696 #if defined(QVG_DIRECT_TO_WINDOW)
697  // Did we get a direct to window rendering surface?
698  EGLint buffer = 0;
699  if (eglQueryContext(QEgl::display(), context->context(),
700  EGL_RENDER_BUFFER, &buffer) &&
701  buffer == EGL_SINGLE_BUFFER) {
702  needToSwap = false;
703  }
704 #endif
705  windowSurface = surface;
706  isPaintingActive = false;
707  }
708 
709 #if !defined(QVG_NO_PRESERVED_SWAP)
710  // Try to force the surface back buffer to preserve its contents.
711  if (needToSwap) {
712  bool succeeded = eglSurfaceAttrib(QEgl::display(), windowSurface,
713  EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED);
714  if (!succeeded && eglGetError() != EGL_SUCCESS) {
715  qWarning("QVG: could not enable preserved swap");
716  }
717  }
718 #endif
719  return context;
720 }
EGLSurface createSurface(QPaintDevice *device, const QEglProperties *properties=0)
Definition: qegl.cpp:354
bool removeValue(int name)
void qt_vg_destroy_paint_engine(QVGPaintEngine *engine)
void setValue(int name, int value)
QEglContext * qt_vg_create_context(QPaintDevice *device, int devType)
EGLContext context() const
Definition: qeglcontext_p.h:91
bool doneCurrent()
Definition: qegl.cpp:485
Q_GUI_EXPORT EGLDisplay display()
Definition: qegl.cpp:589
void qt_vg_destroy_context(QEglContext *context, int devType)
Q_CORE_EXPORT void qWarning(const char *,...)
QSize windowSurfaceSize(QWidget *widget) const
void destroySurface(EGLSurface surface)
Definition: qegl.cpp:415
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53

◆ scroll()

bool QVGEGLWindowSurfaceDirect::scroll ( QWidget widget,
const QRegion area,
int  dx,
int  dy 
)
virtual

Reimplemented from QVGEGLWindowSurfacePrivate.

Definition at line 760 of file qwindowsurface_vgegl.cpp.

761 {
762 #ifdef QVG_BUFFER_SCROLLING
763  QEglContext *context = ensureContext(widget);
764  if (context) {
765  context->makeCurrent(windowSurface);
766  QRect scrollRect = area.boundingRect();
767  int sx = scrollRect.x();
768  int sy = size.height() - scrollRect.y() - scrollRect.height();
769  vgSeti(VG_SCISSORING, VG_FALSE);
770  vgCopyPixels(sx + dx, sy - dy, sx, sy, scrollRect.width(), scrollRect.height());
771  context->lazyDoneCurrent();
772  return true;
773  }
774 #else
775  Q_UNUSED(widget);
776  Q_UNUSED(area);
777  Q_UNUSED(dx);
778  Q_UNUSED(dy);
779 #endif
780  return false;
781 }
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QRect boundingRect() const
Returns the bounding rectangle of this region.
Definition: qregion.cpp:4363
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QEglContext * ensureContext(QWidget *widget)
bool lazyDoneCurrent()
Definition: qegl.cpp:519
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
bool makeCurrent(EGLSurface surface)
Definition: qegl.cpp:433
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
int height() const
Returns the height.
Definition: qsize.h:129
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
#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

◆ supportsStaticContents()

bool QVGEGLWindowSurfaceDirect::supportsStaticContents ( ) const
virtual

Reimplemented from QVGEGLWindowSurfacePrivate.

Definition at line 751 of file qwindowsurface_vgegl.cpp.

752 {
753 #if defined(QVG_BUFFER_SCROLLING) && !defined(QVG_NO_PRESERVED_SWAP)
754  return true;
755 #else
757 #endif
758 }
virtual bool supportsStaticContents() const

◆ surfaceSize()

QSize QVGEGLWindowSurfaceDirect::surfaceSize ( ) const
inlinevirtual

Implements QVGEGLWindowSurfacePrivate.

Definition at line 130 of file qwindowsurface_vgegl_p.h.

Properties

◆ context

QEglContext* QVGEGLWindowSurfaceDirect::context
protected

Definition at line 135 of file qwindowsurface_vgegl_p.h.

Referenced by ensureContext().

◆ isPaintingActive

bool QVGEGLWindowSurfaceDirect::isPaintingActive
protected

Definition at line 137 of file qwindowsurface_vgegl_p.h.

Referenced by beginPaint(), endPaint(), and ensureContext().

◆ needToSwap

bool QVGEGLWindowSurfaceDirect::needToSwap
protected

Definition at line 138 of file qwindowsurface_vgegl_p.h.

Referenced by endPaint(), and ensureContext().

◆ size

QSize QVGEGLWindowSurfaceDirect::size
protected

Definition at line 136 of file qwindowsurface_vgegl_p.h.

Referenced by ensureContext(), and scroll().

◆ windowSurface

EGLSurface QVGEGLWindowSurfaceDirect::windowSurface
protected

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