37 ** |
37 ** |
38 ** $QT_END_LICENSE$ |
38 ** $QT_END_LICENSE$ |
39 ** |
39 ** |
40 ****************************************************************************/ |
40 ****************************************************************************/ |
41 |
41 |
42 #include "../src/gui/egl/qegl_p.h" |
|
43 #include "qwindowsurface_vgegl_p.h" |
42 #include "qwindowsurface_vgegl_p.h" |
44 #include "qpaintengine_vg_p.h" |
43 #include "qpaintengine_vg_p.h" |
45 #include "qpixmapdata_vg_p.h" |
44 #include "qpixmapdata_vg_p.h" |
46 #include "qvgimagepool_p.h" |
45 #include "qvgimagepool_p.h" |
47 #include "qvg_p.h" |
46 #include "qvg_p.h" |
48 |
|
49 |
47 |
50 #if !defined(QT_NO_EGL) |
48 #if !defined(QT_NO_EGL) |
51 |
49 |
52 QT_BEGIN_NAMESPACE |
50 QT_BEGIN_NAMESPACE |
53 |
51 |
231 context->setApi(QEgl::OpenVG); |
228 context->setApi(QEgl::OpenVG); |
232 |
229 |
233 // Set the swap interval for the display. |
230 // Set the swap interval for the display. |
234 QByteArray interval = qgetenv("QT_VG_SWAP_INTERVAL"); |
231 QByteArray interval = qgetenv("QT_VG_SWAP_INTERVAL"); |
235 if (!interval.isEmpty()) |
232 if (!interval.isEmpty()) |
236 eglSwapInterval(context->display(), interval.toInt()); |
233 eglSwapInterval(QEglContext::display(), interval.toInt()); |
237 else |
234 else |
238 eglSwapInterval(context->display(), 1); |
235 eglSwapInterval(QEglContext::display(), 1); |
239 |
236 |
240 #ifdef EGL_RENDERABLE_TYPE |
237 #ifdef EGL_RENDERABLE_TYPE |
241 // Has the user specified an explicit EGL configuration to use? |
238 // Has the user specified an explicit EGL configuration to use? |
242 QByteArray configId = qgetenv("QT_VG_EGL_CONFIG"); |
239 QByteArray configId = qgetenv("QT_VG_EGL_CONFIG"); |
243 if (!configId.isEmpty()) { |
240 if (!configId.isEmpty()) { |
247 EGL_NONE |
244 EGL_NONE |
248 }; |
245 }; |
249 EGLint matching = 0; |
246 EGLint matching = 0; |
250 EGLConfig cfg; |
247 EGLConfig cfg; |
251 if (eglChooseConfig |
248 if (eglChooseConfig |
252 (context->display(), properties, &cfg, 1, &matching) && |
249 (QEglContext::display(), properties, &cfg, 1, &matching) && |
253 matching > 0) { |
250 matching > 0) { |
254 // Check that the selected configuration actually supports OpenVG |
251 // Check that the selected configuration actually supports OpenVG |
255 // and then create the context with it. |
252 // and then create the context with it. |
256 EGLint id = 0; |
253 EGLint id = 0; |
257 EGLint type = 0; |
254 EGLint type = 0; |
258 eglGetConfigAttrib |
255 eglGetConfigAttrib |
259 (context->display(), cfg, EGL_CONFIG_ID, &id); |
256 (QEglContext::display(), cfg, EGL_CONFIG_ID, &id); |
260 eglGetConfigAttrib |
257 eglGetConfigAttrib |
261 (context->display(), cfg, EGL_RENDERABLE_TYPE, &type); |
258 (QEglContext::display(), cfg, EGL_RENDERABLE_TYPE, &type); |
262 if (cfgId == id && (type & EGL_OPENVG_BIT) != 0) { |
259 if (cfgId == id && (type & EGL_OPENVG_BIT) != 0) { |
263 context->setConfig(cfg); |
260 context->setConfig(cfg); |
264 if (!context->createContext()) { |
261 if (!context->createContext()) { |
265 delete context; |
262 delete context; |
266 return 0; |
263 return 0; |
335 shared->context->makeCurrent(qt_vg_shared_surface()); |
332 shared->context->makeCurrent(qt_vg_shared_surface()); |
336 delete shared->engine; |
333 delete shared->engine; |
337 shared->engine = 0; |
334 shared->engine = 0; |
338 shared->context->doneCurrent(); |
335 shared->context->doneCurrent(); |
339 if (shared->surface != EGL_NO_SURFACE) { |
336 if (shared->surface != EGL_NO_SURFACE) { |
340 eglDestroySurface(shared->context->display(), shared->surface); |
337 eglDestroySurface(QEglContext::display(), shared->surface); |
341 shared->surface = EGL_NO_SURFACE; |
338 shared->surface = EGL_NO_SURFACE; |
342 } |
339 } |
343 delete shared->context; |
340 delete shared->context; |
344 shared->context = 0; |
341 shared->context = 0; |
345 } |
342 } |
556 // for this window. We have to create the VGImage with a |
553 // for this window. We have to create the VGImage with a |
557 // current context, so activate the main surface for the window. |
554 // current context, so activate the main surface for the window. |
558 context->makeCurrent(mainSurface()); |
555 context->makeCurrent(mainSurface()); |
559 recreateBackBuffer = false; |
556 recreateBackBuffer = false; |
560 if (backBufferSurface != EGL_NO_SURFACE) { |
557 if (backBufferSurface != EGL_NO_SURFACE) { |
561 eglDestroySurface(context->display(), backBufferSurface); |
558 eglDestroySurface(QEglContext::display(), backBufferSurface); |
562 backBufferSurface = EGL_NO_SURFACE; |
559 backBufferSurface = EGL_NO_SURFACE; |
563 } |
560 } |
564 if (backBuffer != VG_INVALID_HANDLE) { |
561 if (backBuffer != VG_INVALID_HANDLE) { |
565 vgDestroyImage(backBuffer); |
562 vgDestroyImage(backBuffer); |
566 } |
563 } |
569 (format, size.width(), size.height(), |
566 (format, size.width(), size.height(), |
570 VG_IMAGE_QUALITY_FASTER); |
567 VG_IMAGE_QUALITY_FASTER); |
571 if (backBuffer != VG_INVALID_HANDLE) { |
568 if (backBuffer != VG_INVALID_HANDLE) { |
572 // Create an EGL surface for rendering into the VGImage. |
569 // Create an EGL surface for rendering into the VGImage. |
573 backBufferSurface = eglCreatePbufferFromClientBuffer |
570 backBufferSurface = eglCreatePbufferFromClientBuffer |
574 (context->display(), EGL_OPENVG_IMAGE, |
571 (QEglContext::display(), EGL_OPENVG_IMAGE, |
575 (EGLClientBuffer)(backBuffer), |
572 (EGLClientBuffer)(backBuffer), |
576 context->config(), NULL); |
573 context->config(), NULL); |
577 if (backBufferSurface == EGL_NO_SURFACE) { |
574 if (backBufferSurface == EGL_NO_SURFACE) { |
578 vgDestroyImage(backBuffer); |
575 vgDestroyImage(backBuffer); |
579 backBuffer = VG_INVALID_HANDLE; |
576 backBuffer = VG_INVALID_HANDLE; |
705 } |
702 } |
706 needToSwap = true; |
703 needToSwap = true; |
707 #if defined(QVG_DIRECT_TO_WINDOW) |
704 #if defined(QVG_DIRECT_TO_WINDOW) |
708 // Did we get a direct to window rendering surface? |
705 // Did we get a direct to window rendering surface? |
709 EGLint buffer = 0; |
706 EGLint buffer = 0; |
710 if (eglQueryContext(context->display(), context->context(), |
707 if (eglQueryContext(QEglContext::display(), context->context(), |
711 EGL_RENDER_BUFFER, &buffer) && |
708 EGL_RENDER_BUFFER, &buffer) && |
712 buffer == EGL_SINGLE_BUFFER) { |
709 buffer == EGL_SINGLE_BUFFER) { |
713 needToSwap = false; |
710 needToSwap = false; |
714 } |
711 } |
715 #endif |
712 #endif |
716 #if !defined(QVG_NO_PRESERVED_SWAP) |
713 #if !defined(QVG_NO_PRESERVED_SWAP) |
717 // Try to force the surface back buffer to preserve its contents. |
714 // Try to force the surface back buffer to preserve its contents. |
718 if (needToSwap) { |
715 if (needToSwap) { |
719 eglGetError(); // Clear error state first. |
716 eglGetError(); // Clear error state first. |
720 eglSurfaceAttrib(context->display(), surface, |
717 eglSurfaceAttrib(QEglContext::display(), surface, |
721 EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED); |
718 EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED); |
722 if (eglGetError() != EGL_SUCCESS) { |
719 if (eglGetError() != EGL_SUCCESS) { |
723 qWarning("QVG: could not enable preserved swap"); |
720 qWarning("QVG: could not enable preserved swap"); |
724 } |
721 } |
725 } |
722 } |