src/openvg/qwindowsurface_vgegl.cpp
branchRCL_3
changeset 7 3f74d0d4af4c
parent 4 3b1da2848fc7
child 8 740e5562c97f
equal deleted inserted replaced
6:dee5afe5301f 7:3f74d0d4af4c
   175         pd->next->prev = pd->prev;
   175         pd->next->prev = pd->prev;
   176     if (pd->prev) {
   176     if (pd->prev) {
   177         pd->prev->next = pd->next;
   177         pd->prev->next = pd->next;
   178     } else {
   178     } else {
   179         QVGSharedContext *shared = sharedContext();
   179         QVGSharedContext *shared = sharedContext();
   180         if (shared) {
   180         if (shared)
   181            shared->firstPixmap = pd->next;
   181            shared->firstPixmap = pd->next;
   182         }
       
   183     }
   182     }
   184 }
   183 }
   185 
   184 
   186 #else
   185 #else
   187 
   186 
   225     QEglContext *context;
   224     QEglContext *context;
   226 
   225 
   227     // Create the context object and open the display.
   226     // Create the context object and open the display.
   228     context = new QEglContext();
   227     context = new QEglContext();
   229     context->setApi(QEgl::OpenVG);
   228     context->setApi(QEgl::OpenVG);
   230     if (!context->openDisplay(device)) {
       
   231         delete context;
       
   232         return 0;
       
   233     }
       
   234 
   229 
   235     // Set the swap interval for the display.
   230     // Set the swap interval for the display.
   236     QByteArray interval = qgetenv("QT_VG_SWAP_INTERVAL");
   231     QByteArray interval = qgetenv("QT_VG_SWAP_INTERVAL");
   237     if (!interval.isEmpty())
   232     if (!interval.isEmpty())
   238         eglSwapInterval(context->display(), interval.toInt());
   233         eglSwapInterval(QEglContext::display(), interval.toInt());
   239     else
   234     else
   240         eglSwapInterval(context->display(), 1);
   235         eglSwapInterval(QEglContext::display(), 1);
   241 
   236 
   242 #ifdef EGL_RENDERABLE_TYPE
   237 #ifdef EGL_RENDERABLE_TYPE
   243     // Has the user specified an explicit EGL configuration to use?
   238     // Has the user specified an explicit EGL configuration to use?
   244     QByteArray configId = qgetenv("QT_VG_EGL_CONFIG");
   239     QByteArray configId = qgetenv("QT_VG_EGL_CONFIG");
   245     if (!configId.isEmpty()) {
   240     if (!configId.isEmpty()) {
   249             EGL_NONE
   244             EGL_NONE
   250         };
   245         };
   251         EGLint matching = 0;
   246         EGLint matching = 0;
   252         EGLConfig cfg;
   247         EGLConfig cfg;
   253         if (eglChooseConfig
   248         if (eglChooseConfig
   254                     (context->display(), properties, &cfg, 1, &matching) &&
   249                     (QEglContext::display(), properties, &cfg, 1, &matching) &&
   255                 matching > 0) {
   250                 matching > 0) {
   256             // Check that the selected configuration actually supports OpenVG
   251             // Check that the selected configuration actually supports OpenVG
   257             // and then create the context with it.
   252             // and then create the context with it.
   258             EGLint id = 0;
   253             EGLint id = 0;
   259             EGLint type = 0;
   254             EGLint type = 0;
   260             eglGetConfigAttrib
   255             eglGetConfigAttrib
   261                 (context->display(), cfg, EGL_CONFIG_ID, &id);
   256                 (QEglContext::display(), cfg, EGL_CONFIG_ID, &id);
   262             eglGetConfigAttrib
   257             eglGetConfigAttrib
   263                 (context->display(), cfg, EGL_RENDERABLE_TYPE, &type);
   258                 (QEglContext::display(), cfg, EGL_RENDERABLE_TYPE, &type);
   264             if (cfgId == id && (type & EGL_OPENVG_BIT) != 0) {
   259             if (cfgId == id && (type & EGL_OPENVG_BIT) != 0) {
   265                 context->setConfig(cfg);
   260                 context->setConfig(cfg);
   266                 if (!context->createContext()) {
   261                 if (!context->createContext()) {
   267                     delete context;
   262                     delete context;
   268                     return 0;
   263                     return 0;
   337     shared->context->makeCurrent(qt_vg_shared_surface());
   332     shared->context->makeCurrent(qt_vg_shared_surface());
   338     delete shared->engine;
   333     delete shared->engine;
   339     shared->engine = 0;
   334     shared->engine = 0;
   340     shared->context->doneCurrent();
   335     shared->context->doneCurrent();
   341     if (shared->surface != EGL_NO_SURFACE) {
   336     if (shared->surface != EGL_NO_SURFACE) {
   342         eglDestroySurface(shared->context->display(), shared->surface);
   337         eglDestroySurface(QEglContext::display(), shared->surface);
   343         shared->surface = EGL_NO_SURFACE;
   338         shared->surface = EGL_NO_SURFACE;
   344     }
   339     }
   345     delete shared->context;
   340     delete shared->context;
   346     shared->context = 0;
   341     shared->context = 0;
   347 }
   342 }
   415 #endif
   410 #endif
   416         {
   411         {
   417             attribs[4] = EGL_NONE;
   412             attribs[4] = EGL_NONE;
   418         }
   413         }
   419         shared->surface = eglCreatePbufferSurface
   414         shared->surface = eglCreatePbufferSurface
   420             (shared->context->display(), shared->context->config(), attribs);
   415             (QEglContext::display(), shared->context->config(), attribs);
   421     }
   416     }
   422     return shared->surface;
   417     return shared->surface;
   423 }
   418 }
   424 
   419 
   425 #else
   420 #else
   558             // for this window.  We have to create the VGImage with a
   553             // for this window.  We have to create the VGImage with a
   559             // current context, so activate the main surface for the window.
   554             // current context, so activate the main surface for the window.
   560             context->makeCurrent(mainSurface());
   555             context->makeCurrent(mainSurface());
   561             recreateBackBuffer = false;
   556             recreateBackBuffer = false;
   562             if (backBufferSurface != EGL_NO_SURFACE) {
   557             if (backBufferSurface != EGL_NO_SURFACE) {
   563                 eglDestroySurface(context->display(), backBufferSurface);
   558                 eglDestroySurface(QEglContext::display(), backBufferSurface);
   564                 backBufferSurface = EGL_NO_SURFACE;
   559                 backBufferSurface = EGL_NO_SURFACE;
   565             }
   560             }
   566             if (backBuffer != VG_INVALID_HANDLE) {
   561             if (backBuffer != VG_INVALID_HANDLE) {
   567                 vgDestroyImage(backBuffer);
   562                 vgDestroyImage(backBuffer);
   568             }
   563             }
   571                 (format, size.width(), size.height(),
   566                 (format, size.width(), size.height(),
   572                  VG_IMAGE_QUALITY_FASTER);
   567                  VG_IMAGE_QUALITY_FASTER);
   573             if (backBuffer != VG_INVALID_HANDLE) {
   568             if (backBuffer != VG_INVALID_HANDLE) {
   574                 // Create an EGL surface for rendering into the VGImage.
   569                 // Create an EGL surface for rendering into the VGImage.
   575                 backBufferSurface = eglCreatePbufferFromClientBuffer
   570                 backBufferSurface = eglCreatePbufferFromClientBuffer
   576                     (context->display(), EGL_OPENVG_IMAGE,
   571                     (QEglContext::display(), EGL_OPENVG_IMAGE,
   577                      (EGLClientBuffer)(backBuffer),
   572                      (EGLClientBuffer)(backBuffer),
   578                      context->config(), NULL);
   573                      context->config(), NULL);
   579                 if (backBufferSurface == EGL_NO_SURFACE) {
   574                 if (backBufferSurface == EGL_NO_SURFACE) {
   580                     vgDestroyImage(backBuffer);
   575                     vgDestroyImage(backBuffer);
   581                     backBuffer = VG_INVALID_HANDLE;
   576                     backBuffer = VG_INVALID_HANDLE;
   707         }
   702         }
   708         needToSwap = true;
   703         needToSwap = true;
   709 #if defined(QVG_DIRECT_TO_WINDOW)
   704 #if defined(QVG_DIRECT_TO_WINDOW)
   710         // Did we get a direct to window rendering surface?
   705         // Did we get a direct to window rendering surface?
   711         EGLint buffer = 0;
   706         EGLint buffer = 0;
   712         if (eglQueryContext(context->display(), context->context(),
   707         if (eglQueryContext(QEglContext::display(), context->context(),
   713                             EGL_RENDER_BUFFER, &buffer) &&
   708                             EGL_RENDER_BUFFER, &buffer) &&
   714                 buffer == EGL_SINGLE_BUFFER) {
   709                 buffer == EGL_SINGLE_BUFFER) {
   715             needToSwap = false;
   710             needToSwap = false;
   716         }
   711         }
   717 #endif
   712 #endif
   718 #if !defined(QVG_NO_PRESERVED_SWAP)
   713 #if !defined(QVG_NO_PRESERVED_SWAP)
   719         // Try to force the surface back buffer to preserve its contents.
   714         // Try to force the surface back buffer to preserve its contents.
   720         if (needToSwap) {
   715         if (needToSwap) {
   721             eglGetError();  // Clear error state first.
   716             eglGetError();  // Clear error state first.
   722             eglSurfaceAttrib(context->display(), surface,
   717             eglSurfaceAttrib(QEglContext::display(), surface,
   723                              EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED);
   718                              EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED);
   724             if (eglGetError() != EGL_SUCCESS) {
   719             if (eglGetError() != EGL_SUCCESS) {
   725                 qWarning("QVG: could not enable preserved swap");
   720                 qWarning("QVG: could not enable preserved swap");
   726             }
   721             }
   727         }
   722         }