Beispiel #1
0
JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_kd_WindowDriver_CreateWindow
  (JNIEnv *env, jobject obj, jlong display, jlong jeglConfig)
{
    EGLDisplay dpy  = (EGLDisplay)(intptr_t)display;
    EGLConfig eglConfig = (EGLConfig)(intptr_t)jeglConfig;
    KDWindow *window = 0;

    if(dpy==NULL) {
        fprintf(stderr, "[CreateWindow] invalid display connection..\n");
        return 0;
    }

    JOGLKDUserdata * userData = kdMalloc(sizeof(JOGLKDUserdata));
    userData->magic = JOGL_KD_USERDATA_MAGIC;
    window = kdCreateWindow(dpy, eglConfig, (void *)userData);

    if(NULL==window) {
        kdFree(userData);
        fprintf(stderr, "[CreateWindow] failed: 0x%X\n", kdGetError());
    } else {
        userData->javaWindow = (*env)->NewGlobalRef(env, obj);
        userData->kdWindow = window;
        (*env)->CallVoidMethod(env, obj, windowCreatedID, (jlong) (intptr_t) userData);
        DBG_PRINT( "[CreateWindow] ok: %p, userdata %p\n", window, userData);
    }
    return (jlong) (intptr_t) window;
}
void QMinimalEglScreen::createAndSetPlatformContext()
{
    QSurfaceFormat platformFormat;

    QByteArray depthString = qgetenv("QT_QPA_EGLFS_DEPTH");
    if (depthString.toInt() == 16) {
        platformFormat.setDepthBufferSize(16);
        platformFormat.setRedBufferSize(5);
        platformFormat.setGreenBufferSize(6);
        platformFormat.setBlueBufferSize(5);
        m_depth = 16;
        m_format = QImage::Format_RGB16;
    } else {
        platformFormat.setDepthBufferSize(24);
        platformFormat.setStencilBufferSize(8);
        platformFormat.setRedBufferSize(8);
        platformFormat.setGreenBufferSize(8);
        platformFormat.setBlueBufferSize(8);
        m_depth = 32;
        m_format = QImage::Format_RGB32;
    }

    if (!qEnvironmentVariableIsEmpty("QT_QPA_EGLFS_MULTISAMPLE"))
        platformFormat.setSamples(4);

    EGLConfig config = q_configFromGLFormat(m_dpy, platformFormat);

    EGLNativeWindowType eglWindow = 0;
#ifdef Q_OPENKODE
    if (kdInitializeNV() == KD_ENOTINITIALIZED) {
        qFatal("Did not manage to initialize openkode");
    }
    KDWindow *window = kdCreateWindow(m_dpy,config,0);

    kdRealizeWindow(window,&eglWindow);
#endif

#ifdef QEGL_EXTRA_DEBUG
    q_printEglConfig(m_dpy, config);
#endif

    m_surface = eglCreateWindowSurface(m_dpy, config, eglWindow, NULL);
    if (m_surface == EGL_NO_SURFACE) {
        qWarning("Could not create the egl surface: error = 0x%x\n", eglGetError());
        eglTerminate(m_dpy);
        qFatal("EGL error");
    }
    //    qWarning("Created surface %dx%d\n", w, h);

    QEGLPlatformContext *platformContext = new QMinimalEglContext(platformFormat, 0, m_dpy);
    m_platformContext = platformContext;

    EGLint w,h;                    // screen size detection
    eglQuerySurface(m_dpy, m_surface, EGL_WIDTH, &w);
    eglQuerySurface(m_dpy, m_surface, EGL_HEIGHT, &h);

    m_geometry = QRect(0,0,w,h);

}
Beispiel #3
0
JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_kd_KDWindow_CreateWindow
  (JNIEnv *env, jobject obj, jlong display, jintArray jAttrs)
{
    jint * attrs = NULL;
    jsize attrsLen;
    EGLDisplay dpy  = (EGLDisplay)(intptr_t)display;
    KDWindow *window = 0;

    if(dpy==NULL) {
        fprintf(stderr, "[CreateWindow] invalid display connection..\n");
        return 0;
    }

    attrsLen = (*env)->GetArrayLength(env, jAttrs);
    if(0==attrsLen) {
        fprintf(stderr, "[CreateWindow] attribute array size 0..\n");
        return 0;
    }
    attrs = (*env)->GetIntArrayElements(env, jAttrs, 0);
    if(NULL==attrs) {
        fprintf(stderr, "[CreateWindow] attribute array NULL..\n");
        return 0;
    }

    JOGLKDUserdata * userData = kdMalloc(sizeof(JOGLKDUserdata));
    userData->magic = JOGL_KD_USERDATA_MAGIC;
    window = kdCreateWindow(dpy, attrs, (void *)userData);

    (*env)->ReleaseIntArrayElements(env, jAttrs, attrs, 0);

    if(NULL==window) {
        kdFree(userData);
        fprintf(stderr, "[CreateWindow] failed: 0x%X\n", kdGetError());
    } else {
        userData->javaWindow = (*env)->NewGlobalRef(env, obj);
        userData->kdWindow = window;
        (*env)->CallVoidMethod(env, obj, windowCreatedID, (jlong) (intptr_t) userData);
        DBG_PRINT( "[CreateWindow] ok: %p, userdata %p\n", window, userData);
    }
    return (jlong) (intptr_t) window;
}
Beispiel #4
0
QOpenKODEWindow::QOpenKODEWindow(QWidget *tlw)
    : QPlatformWindow(tlw), isFullScreen(false)
{
    if (tlw->platformWindowFormat().windowApi() == QPlatformWindowFormat::OpenVG) {
        m_eglApi = EGL_OPENVG_API;
    } else {
        m_eglContextAttrs.append(EGL_CONTEXT_CLIENT_VERSION);
        m_eglContextAttrs.append(2);

        m_eglApi = EGL_OPENGL_ES_API;
    }
    eglBindAPI(m_eglApi);

    m_eglContextAttrs.append(EGL_NONE);
    m_eglWindowAttrs.append(EGL_NONE);

    QList<QPlatformScreen *> screens = QApplicationPrivate::platformIntegration()->screens();
    //XXXX: jl figure out how to pick the correct screen.
//    Q_ASSERT(screens.size() > tlw->d_func()->screenNumber);
//    QOpenKODEScreen *screen = qobject_cast<QOpenKODEScreen *>(screens.at(tlw->d_func()->screenNumber));
    QOpenKODEScreen *screen = qobject_cast<QOpenKODEScreen *>(screens.at(0));
    if (!screen) {
        qErrnoWarning("Could not make QOpenKODEWindow without a screen");
    }

    QPlatformWindowFormat format = tlw->platformWindowFormat();
    format.setRedBufferSize(5);
    format.setGreenBufferSize(6);
    format.setBlueBufferSize(5);

    m_eglConfig = q_configFromQPlatformWindowFormat(screen->eglDisplay(),format);

    m_kdWindow = kdCreateWindow(screen->eglDisplay(),
                              m_eglConfig,
                              this);
    kdInstallCallback(kdProcessMouseEvents,KD_EVENT_INPUT_POINTER,this);
#ifdef KD_ATX_keyboard
    kdInstallCallback(kdProcessKeyEvents, KD_EVENT_INPUT_KEY_ATX,this);
#endif //KD_ATX_keyboard

    if (!m_kdWindow) {
        qErrnoWarning(kdGetError(), "Error creating native window");
        return;
    }

    KDboolean exclusive(false);
    if (kdSetWindowPropertybv(m_kdWindow,KD_WINDOWPROPERTY_DESKTOP_EXCLUSIVE_NV, &exclusive)) {
        isFullScreen = true;
    }

    if (isFullScreen) {
        tlw->setGeometry(screen->geometry());
        screen->setFullScreen(isFullScreen);
    }else {
        const KDint windowSize[2]  = { tlw->width(), tlw->height() };
        if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_SIZE, windowSize)) {
            qErrnoWarning(kdGetError(), "Could not set native window size");
        }
        KDboolean visibillity(false);
        if (kdSetWindowPropertybv(m_kdWindow, KD_WINDOWPROPERTY_VISIBILITY, &visibillity)) {
            qErrnoWarning(kdGetError(), "Could not set visibillity to false");
        }

        const KDint windowPos[2] = { tlw->x(), tlw->y() };
        if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_DESKTOP_OFFSET_NV, windowPos)) {
            qErrnoWarning(kdGetError(), "Could not set native window position");
            return;
        }
    }


    QOpenKODEIntegration *integration = static_cast<QOpenKODEIntegration *>(QApplicationPrivate::platformIntegration());

    if (!isFullScreen || (isFullScreen && !integration->mainGLContext())) {
        if (kdRealizeWindow(m_kdWindow, &m_eglWindow)) {
            qErrnoWarning(kdGetError(), "Could not realize native window");
            return;
        }

        EGLSurface surface = eglCreateWindowSurface(screen->eglDisplay(),m_eglConfig,m_eglWindow,m_eglWindowAttrs.constData());
        m_platformGlContext = new QEGLPlatformContext(screen->eglDisplay(), m_eglConfig,
                                                      m_eglContextAttrs.data(), surface, m_eglApi);
        integration->setMainGLContext(m_platformGLContext);
    } else {
        m_platformGlContext = integration->mainGLContext();
        kdDestroyWindow(m_kdWindow);
        m_kdWindow = 0;
    }
}
Beispiel #5
0
void QEglFSScreen::createAndSetPlatformContext()
{
    QPlatformWindowFormat platformFormat = QPlatformWindowFormat::defaultFormat();

    platformFormat.setWindowApi(QPlatformWindowFormat::OpenGL);

    QByteArray depthString = qgetenv("QT_QPA_EGLFS_DEPTH");
    if (depthString.toInt() == 16) {
        platformFormat.setDepth(16);
        platformFormat.setRedBufferSize(5);
        platformFormat.setGreenBufferSize(6);
        platformFormat.setBlueBufferSize(5);
        m_depth = 16;
        m_format = QImage::Format_RGB16;
    } else {
        platformFormat.setDepth(32);
        platformFormat.setRedBufferSize(8);
        platformFormat.setGreenBufferSize(8);
        platformFormat.setBlueBufferSize(8);
        m_depth = 32;
        m_format = QImage::Format_RGB32;
    }
    if (!qgetenv("QT_QPA_EGLFS_MULTISAMPLE").isEmpty()) {
        platformFormat.setSampleBuffers(true);
    }


    EGLConfig config = q_configFromQPlatformWindowFormat(m_dpy, platformFormat);

    EGLNativeWindowType eglWindow = 0;
#ifdef Q_OPENKODE
    if (kdInitializeNV() == KD_ENOTINITIALIZED) {
        qFatal("Did not manage to initialize openkode");
    }
    KDWindow *window = kdCreateWindow(m_dpy,config,0);

    kdRealizeWindow(window,&eglWindow);
#endif

    m_surface = eglCreateWindowSurface(m_dpy, config, eglWindow, NULL);
    if (m_surface == EGL_NO_SURFACE) {
        qWarning("Could not create the egl surface: error = 0x%x\n", eglGetError());
        eglTerminate(m_dpy);
        qFatal("EGL error");
    }
    //    qWarning("Created surface %dx%d\n", w, h);

#ifdef QEGL_EXTRA_DEBUG
    qWarning("Configuration %d matches requirements\n", (int)config);

    for (index = 0; attrs[index].attr != -1; ++index) {
        EGLint value;
        if (eglGetConfigAttrib(m_dpy, config, attrs[index].attr, &value)) {
            qWarning("\t%s: %d\n", attrs[index].name, (int)value);
        }
    }
    qWarning("\n");
#endif

    EGLint temp;
    EGLint attribList[32];

    temp = 0;

    attribList[temp++] = EGL_CONTEXT_CLIENT_VERSION;
    attribList[temp++] = 2; // GLES version 2
    attribList[temp++] = EGL_NONE;

    QEGLPlatformContext *platformContext = new QEGLPlatformContext(m_dpy,config,attribList,m_surface,EGL_OPENGL_ES_API);
    m_platformContext = platformContext;

    EGLint w,h;                    // screen size detection
    eglQuerySurface(m_dpy, m_surface, EGL_WIDTH, &w);
    eglQuerySurface(m_dpy, m_surface, EGL_HEIGHT, &h);

    m_geometry = QRect(0,0,w,h);

}
Beispiel #6
0
bool CWinSystemEGL::CreateNewWindow(const CStdString& name, bool fullScreen, RESOLUTION_INFO& res, PHANDLE_EVENT_FUNC userFunction)
{
#if defined(EMPOWER) && defined(HAS_OPENKODE)
  KDboolean b;
  KDDisplayModeNV  mode;
  KDint desktopSize[2] = { res.iWidth, res.iHeight };
#endif
#ifdef _WIN32
  EGL_BASE_CLASS::CreateNewWindow(name, fullScreen, res, userFunction);
#endif

  m_nWidth = res.iWidth;
  m_nHeight = res.iHeight;
  m_bFullScreen = fullScreen;

  EGLBoolean eglStatus;
  EGLint     configCount;
  EGLConfig* configList = NULL;  

#if defined(EMPOWER) && defined(HAS_OPENKODE)
  //CLog::Log(LOGDEBUG, "NV: GetDisplay");
  m_kdDisplay = kdGetDisplayNV(KD_DEFAULT_DISPLAY_NV, KD_NULL);
  if (!m_kdDisplay)
  {
    CLog::Log(LOGERROR, "Could not obtain KDDisplayNV pointer");
    return false;
  }
  b = KD_FALSE;
  //CLog::Log(LOGDEBUG, "NV: SetDisplayProperty");
  kdSetDisplayPropertybvNV(m_kdDisplay, KD_DISPLAYPROPERTY_ENABLED_NV, &b);
  kdReleaseDisplayNV(m_kdDisplay);

  // MZL: enable HDMI display
  //CLog::Log(LOGDEBUG, "NV: SetDisplayPropertybyNV");
  kdSetDisplayPropertybvNV(m_kdDisplay, KD_DISPLAYPROPERTY_ENABLED_NV, &b);
  m_kdDisplay = kdGetDisplayNV("Tegra:HDMI0", KD_NULL);
  if (!m_kdDisplay)
  {
    CLog::Log(LOGERROR, "Could not obtain KDDisplayNV pointer");
    return false;
  }
  b = KD_TRUE;
  kdSetDisplayPropertybvNV(m_kdDisplay, KD_DISPLAYPROPERTY_ENABLED_NV, &b);
  kdSetDisplayPropertycvNV(m_kdDisplay, KD_DISPLAYPROPERTY_DESKTOP_NAME_NV, KD_DEFAULT_DESKTOP_NV);

  mode.width   = res.iWidth;
  mode.height  = res.iHeight;
  mode.refresh = 60;
  //CLog::Log(LOGDEBUG, "NV: SetDisplayPropertyNV");
  if (kdSetDisplayModeNV(m_kdDisplay, &mode, KD_DISPLAY_PROTOCOL_AUTOMATIC_NV))
  {
    CLog::Log(LOGERROR, "Could not set display mode\n");
    return false;
  }

  //CLog::Log(LOGDEBUG, "NV: GetDesktopNV");
  m_kdDesktop = kdGetDesktopNV(KD_DEFAULT_DESKTOP_NV, KD_NULL);
  if (!m_kdDesktop)
  {
    CLog::Log(LOGERROR, "Could not obtain KDDesktopNV pointer");
    return false;
  } 

  //CLog::Log(LOGDEBUG, "NV: SetDesktopivNV");
  if (kdSetDesktopPropertyivNV(m_kdDesktop, KD_DESKTOPPROPERTY_SIZE_NV, desktopSize))
  {
    CLog::Log(LOGERROR, "Could not set desktop size");
    return false;
  }
#endif

#ifdef HAS_X11
  m_x11Display = XOpenDisplay(NULL);
  if (!m_x11Display)
  {
    CLog::Log(LOGERROR, "Could not open X11");
    return false;
  }

  XSetErrorHandler(ApplicationErrorHandler) ;
#endif

  //CLog::Log(LOGDEBUG, "eglGetDisplay");
#if defined(HAS_OPENKODE) || defined(HAS_GDL)
  m_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
#elif defined(_WIN32)
  m_display = eglGetDisplay(m_hDC);
#elif defined(HAS_X11)
  m_display = eglGetDisplay((EGLNativeDisplayType) m_x11Display);
#endif
  if (m_display == EGL_NO_DISPLAY) 
  {
    CLog::Log(LOGERROR, "EGL failed to obtain display");
    return false;
  }
   
  //CLog::Log(LOGDEBUG, "eglInitialize");
  if (!eglInitialize(m_display, 0, 0)) 
  {
    CLog::Log(LOGERROR, "EGL failed to initialize");
    return false;
  } 
  
  EGLint configAttrs[] = {
        EGL_RED_SIZE,        8,
        EGL_GREEN_SIZE,      8,
        EGL_BLUE_SIZE,       8,
        EGL_DEPTH_SIZE,     16,
        EGL_STENCIL_SIZE,    8,
        EGL_SAMPLE_BUFFERS,  0,
        EGL_SAMPLES,         0,
        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
        EGL_NONE
  };

  // Find out how many configurations suit our needs  
  //CLog::Log(LOGDEBUG, "eglChooseConfig");
  eglStatus = eglChooseConfig(m_display, configAttrs, NULL, 0, &configCount);
  if (!eglStatus || !configCount) 
  {
    CLog::Log(LOGERROR, "EGL failed to return any matching configurations");
    return false;
  }
    
  // Allocate room for the list of matching configurations
  configList = (EGLConfig*)malloc(configCount * sizeof(EGLConfig));
  if (!configList) 
  {
    CLog::Log(LOGERROR, "kdMalloc failure obtaining configuration list");
    return false;
  }

  // Obtain the configuration list from EGL
  eglStatus = eglChooseConfig(m_display, configAttrs,
                                configList, configCount, &configCount);
  if (!eglStatus || !configCount) 
  {
    CLog::Log(LOGERROR, "EGL failed to populate configuration list");
    return false;
  }
  
  // Select an EGL configuration that matches the native window
  m_config = configList[0];

  EGLint* attribList = NULL;

#ifdef EMPOWER
  EGLint windowAttrs[3];
  int windowIndex = 0;
  windowAttrs[windowIndex++] = EGL_RENDER_BUFFER;
  windowAttrs[windowIndex++] = EGL_BACK_BUFFER;
  windowAttrs[windowIndex++] = EGL_NONE;
  attribList = windowAttrs;
#endif

#ifdef HAS_OPENKODE
  //CLog::Log(LOGDEBUG, "KD: kdCreateWindow");
  m_kdWindow = kdCreateWindow(m_display, m_config, KD_NULL);
  if (!m_kdWindow)
  {
    CLog::Log(LOGERROR, "Error creating native window");
    return false;
  }

  //CLog::Log(LOGDEBUG, "KD: kdRealizeWindow");
  if (kdRealizeWindow(m_kdWindow, &m_nativeWindow))
  {
    CLog::Log(LOGERROR, "Could not realize native window");
    return false;
  }

#elif defined HAS_X11
  int screen = DefaultScreen(m_x11Display);

  XSetWindowAttributes windowAttributes;
  windowAttributes.colormap     = DefaultColormap(m_x11Display, screen);
  windowAttributes.border_pixel = 0;
  windowAttributes.event_mask   = ExposureMask           |
                                  VisibilityChangeMask   |
                                  KeyPressMask           |
                                  KeyReleaseMask         |
                                  ButtonPressMask        |
                                  ButtonReleaseMask      |
                                  PointerMotionMask      |
                                  StructureNotifyMask    |
                                  SubstructureNotifyMask |
                                  FocusChangeMask;

  m_nativeWindow = (NativeWindowType) XCreateWindow( m_x11Display,
                              RootWindow(m_x11Display, screen),
                              0, 0,     // x/y position of top-left outside corner of the window
                              res.iWidth, res.iHeight, // Width and height of window
                              0,        // Border width
                              DefaultDepth(m_x11Display, screen),
                              InputOutput,
                              DefaultVisual(m_x11Display, screen),
                              CWBorderPixel | CWColormap | CWEventMask,
                              &windowAttributes );

  XSetStandardProperties(m_x11Display, (Window) m_nativeWindow, name, name, None, NULL, 0, NULL);

  Atom wmDeleteMessage = XInternAtom(m_x11Display, "WM_DELETE_WINDOW", False);
  XSetWMProtocols(m_x11Display, (Window) m_nativeWindow, &wmDeleteMessage, 1);

  if (fullScreen && !SetFullScreen(fullScreen, res, false))
  {
    return false;
  }

   XMapRaised(m_x11Display, (Window) m_nativeWindow);
#endif

#ifdef _WIN32
  m_nativeWindow = m_hWnd;
 
  DEVMODE dm;
  ZeroMemory(&dm, sizeof(dm));
  dm.dmSize = sizeof(dm);
  EnumDisplaySettingsEx(NULL, ENUM_CURRENT_SETTINGS, &dm, 0);

  m_nLeft = (dm.dmPelsWidth / 2) - (m_nWidth / 2);
  m_nTop = (dm.dmPelsHeight / 2) - (m_nHeight / 2);

  RECT rc;
  rc.left = m_nLeft;
  rc.top = m_nTop;
  rc.right = rc.left + m_nWidth;
  rc.bottom = rc.top + m_nHeight;
  AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, false );
  SetWindowPos(m_hWnd, 0, rc.left, rc.top, 0, 0, SWP_NOSIZE);
#endif

#if defined(HAS_GDL)
  m_nativeWindow = (NativeWindowType)GDL_GRAPHICS_PLANE;
#endif

  m_surface = eglCreateWindowSurface(m_display, m_config, m_nativeWindow, attribList);
  if (!m_surface)
  { 
    CLog::Log(LOGERROR, "EGL couldn't create window");
    return false;
  }

#ifdef CANMORE
  eglStatus = eglBindAPI(EGL_OPENGL_ES_API);
  if (!eglStatus) 
  {
    CLog::Log(LOGERROR, "EGL failed to bind API");
    return false;
  }
#endif

  EGLint contextAttrs[] = 
  {
    EGL_CONTEXT_CLIENT_VERSION, 2,
    EGL_NONE
  };

  // Create an EGL context
  //CLog::Log(LOGDEBUG, "eglCreateContext");
  m_context = eglCreateContext(m_display, m_config, NULL, contextAttrs);
  if (!m_context) 
  {
    CLog::Log(LOGERROR, "EGL couldn't create context");
    return false;
  }

  // Make the context and surface current for rendering
  eglStatus = eglMakeCurrent(m_display, m_surface, m_surface, m_context);
  if (!eglStatus) 
  {
    CLog::Log(LOGERROR, "EGL couldn't make context/surface current");
    return false;
  }
 
  free(configList);

  eglSwapInterval(m_display, 0);

  m_bWindowCreated = true;

  CLog::Log(LOGINFO, "Window creation complete");
  return true;
}