void WindowSurfaceImpl::handleSymbianWindowVisibilityChange(bool aVisible)
{
    if(mPaintingStarted)
    {
        // TODO window getting invisible in the middle of paint
        return;
    }
    
    if (!aVisible)
    {
        // Switch to sw rendering
        if(!isLocalSurfaceValid()) 
        {
            if(mMainSurface.localSurfaceInUse) 
            {
                deleteLocalSurface();
            }
            
            CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
            CleanupStack::PushL(bitmap);
            int err = bitmap->Create(TSize(mMainSurface.widget->width(), mMainSurface.widget->height()), 
                CCoeEnv::Static()->ScreenDevice()->DisplayMode());
            eglCopyBuffers(mEgl.display, mEgl.readSurface, bitmap);
            mMainSurface.localSurface = new QImage(QPixmap::fromSymbianCFbsBitmap(bitmap).toImage());
            CleanupStack::Pop(bitmap);
            
            mMainSurface.qSurface = NULL;
            mMainSurface.device = mMainSurface.localSurface;
            mMainSurface.type = WsTypeQtImage;
            mMainSurface.localSurfaceInUse = true;
        }
    }
    
    // Otherwise updateSurfaceData() will switch back to hw rendering
}
Example #2
0
/*  private native int _eglCopyBuffers ( int display , int surface , Graphics target ) ; */
KNIEXPORT KNI_RETURNTYPE_INT
Java_javax_microedition_khronos_egl_EGL10Impl__1eglCopyBuffers() {
    EGLDisplay display = (EGLDisplay) KNI_GetParameterAsInt(1);
    EGLSurface surface = (EGLSurface) KNI_GetParameterAsInt(2);
    jint width = KNI_GetParameterAsInt(4);
    jint height = KNI_GetParameterAsInt(5);
    jint flip = 0;

    JSR239_Pixmap *pixmap = (JSR239_Pixmap *) 0;
    EGLBoolean returnValue = EGL_FALSE;
    
    KNI_StartHandles(1);
    KNI_DeclareHandle(graphicsHandle);
    KNI_GetParameterAsObject(3, graphicsHandle);

    returnValue = (jint)eglCopyBuffers((EGLDisplay) display,
                                       (EGLSurface) surface,
                                       (NativePixmapType) pixmap);

#ifdef DEBUG
    printf("eglCopyBuffers(0x%x, 0x%x, 0x%x) = %d\n",
           display, surface, pixmap, returnValue);
#endif
        
    /* Workaround - use glReadPixels if eglCopyBuffers fails. */
    if (returnValue == EGL_FALSE) {
    
        pixmap = JSR239_getImagePixmap(graphicsHandle,
                                   width, height,
                                   4, 8, 8, 8, 8);
        if (!pixmap) {
            KNI_ThrowNew("java.lang.OutOfMemoryException", "eglCopyBuffers");
            goto exit;
        }
    
        // Enforce RGBA order of glReadPixels
        pixmap->aOffset = 24;
        pixmap->bOffset = 16;
        pixmap->gOffset = 8;
        pixmap->rOffset = 0;
    
        returnValue = eglCopyBuffersWorkaround((EGLDisplay) display,
                                               (EGLSurface) surface,
                                               pixmap);
        flip = 1;
    }
    
    if (returnValue == EGL_TRUE) {
        JSR239_putWindowContents(graphicsHandle, pixmap, flip);
    }

    if (pixmap) {
        JSR239_destroyPixmap(pixmap);
    }

 exit:
        
    KNI_EndHandles();
    KNI_ReturnInt((jint)returnValue);
}
void CEGLGraphicsInterface::CopyBitmapL(CFbsBitmap* aPixMap, CFbsBitmap* )
    {
    if (eglCopyBuffers(iEglDisplay, eglGetCurrentSurface(EGL_READ), aPixMap) == EGL_FALSE)
        {
        User::Leave(MapEGLErrorCodeToSymbian(eglGetError()));
        }
    aPixMap->SetDisplayMode(aPixMap->DisplayMode());
    }
Example #4
0
static void
event_loop(struct egl_manager *eman, EGLint surface_type, EGLint w, EGLint h)
{
   int window_w = w, window_h = h;

   if (surface_type == EGL_PBUFFER_BIT)
      printf("there will be no screen update if "
             "eglCopyBuffers() is not implemented\n");

   while (1) {
      while (XPending(eman->xdpy) > 0) {
         XEvent event;
         XNextEvent(eman->xdpy, &event);
         switch (event.type) {
         case Expose:
            /* we'll redraw below */
            break;
         case ConfigureNotify:
            window_w = event.xconfigure.width;
            window_h = event.xconfigure.height;
            if (surface_type == EGL_WINDOW_BIT)
               reshape(window_w, window_h);
            break;
         case KeyPress:
            {
               char buffer[10];
               int r, code;
               code = XLookupKeysym(&event.xkey, 0);
               if (code == XK_Left) {
                  view_roty += 5.0;
               }
               else if (code == XK_Right) {
                  view_roty -= 5.0;
               }
               else if (code == XK_Up) {
                  view_rotx += 5.0;
               }
               else if (code == XK_Down) {
                  view_rotx -= 5.0;
               }
               else {
                  r = XLookupString(&event.xkey, buffer, sizeof(buffer),
                                    NULL, NULL);
                  if (buffer[0] == 27) {
                     /* escape */
                     return;
                  }
               }
            }
         }
      }

      {
         static int frames = 0;
         static double tRot0 = -1.0, tRate0 = -1.0;
         double dt, t = current_time();
         if (tRot0 < 0.0)
            tRot0 = t;
         dt = t - tRot0;
         tRot0 = t;

         /* advance rotation for next frame */
         angle += 70.0 * dt;  /* 70 degrees per second */
         if (angle > 3600.0)
             angle -= 3600.0;

         switch (surface_type) {
         case GEARS_WINDOW:
	    draw();
            eglSwapBuffers(eman->dpy, eman->win);
            break;

	 case GEARS_PBUFFER:
	    draw();
	    if (!eglCopyBuffers(eman->dpy, eman->pbuf, eman->xpix))
	       break;
	    copy_gears(eman, w, h, window_w, window_h);
	    break;

	 case GEARS_PBUFFER_TEXTURE:
            eglMakeCurrent(eman->dpy, eman->pbuf, eman->pbuf, eman->ctx);
	    draw();
	    texture_gears(eman, surface_type);
	    break;

	 case GEARS_PIXMAP:
	    draw();
	    copy_gears(eman, w, h, window_w, window_h);
	    break;

	 case GEARS_PIXMAP_TEXTURE:
            eglMakeCurrent(eman->dpy, eman->pix, eman->pix, eman->ctx);
	    draw();
	    texture_gears(eman, surface_type);
	    break;

	 case GEARS_RENDERBUFFER:
	    glBindFramebuffer(GL_FRAMEBUFFER_EXT, eman->fbo);
	    draw();
	    glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0);
	    texture_gears(eman, surface_type);
	    break;
	 }

         frames++;

         if (tRate0 < 0.0)
            tRate0 = t;
         if (t - tRate0 >= 5.0) {
            GLfloat seconds = t - tRate0;
            GLfloat fps = frames / seconds;
            printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds,
                   fps);
            tRate0 = t;
            frames = 0;
         }
      }
   }
}