QOpenKODEIntegration::QOpenKODEIntegration() : mEventLoopIntegration(0) , mFontDb(new QGenericUnixFontDatabase()) , mMainGlContext(0) { if (kdInitializeNV() == KD_ENOTINITIALIZED) { qFatal("Did not manage to initialize openkode"); } KDDisplaySystemNV *kdDisplaySystem = kdCreateDisplaySystemSnapshotNV(this); KDint32 displayCount = 0; kdGetDisplaySystemPropertyivNV(kdDisplaySystem, KD_DISPLAYPROPERTY_COUNT_NV, 0, &displayCount); for (int i = 0; i < displayCount; i++) { KDchar *displayName = 0; KDsize displayNameLength = 0; kdGetDisplaySystemPropertycvNV(kdDisplaySystem,KD_DISPLAYPROPERTY_NAME_NV,i,0,&displayNameLength); if (!displayNameLength) continue; displayName = new KDchar[displayNameLength]; kdGetDisplaySystemPropertycvNV(kdDisplaySystem,KD_DISPLAYPROPERTY_NAME_NV,i,displayName,&displayNameLength); KDDisplayNV *display = kdGetDisplayNV(displayName,this); if (!display || display == (void*)-1) { qErrnoWarning(kdGetError(), "Could not obtain KDDisplayNV pointer"); return; } if (displayNameLength) delete displayName; KDchar *desktopName = 0; KDsize desktopNameLength = 0; bool openkodeImpDoesNotFail = false; if (openkodeImpDoesNotFail) { qDebug() << "printing desktopname"; kdGetDisplayPropertycvNV(display,KD_DISPLAYPROPERTY_DESKTOP_NAME_NV,desktopName,&desktopNameLength); if (desktopNameLength) { desktopName = new KDchar[desktopNameLength]; kdGetDisplayPropertycvNV(display,KD_DISPLAYPROPERTY_DESKTOP_NAME_NV,desktopName,&desktopNameLength); } else { desktopName = KD_DEFAULT_DESKTOP_NV; } } else { desktopName = KD_DEFAULT_DESKTOP_NV; } KDDesktopNV *desktop = kdGetDesktopNV(desktopName,this); if (!desktop || desktop == (void*)-1) { qErrnoWarning(kdGetError(), "Could not obtain KDDesktopNV pointer"); kdReleaseDisplayNV(display); return; } if (desktopNameLength) delete desktopName; QOpenKODEScreen *screen = new QOpenKODEScreen(display,desktop); mScreens.append(screen); } }
QT_BEGIN_NAMESPACE QOpenKODEScreen::QOpenKODEScreen(KDDisplayNV *kdDisplay, KDDesktopNV *kdDesktop) : mIsFullScreen(false) { qDebug() << "QOpenKODEScreen::QOpenKODEIntegrationScreen()"; KDboolean enabled = KD_TRUE; kdSetDisplayPropertybvNV(kdDisplay, KD_DISPLAYPROPERTY_ENABLED_NV, &enabled); KDboolean power = KD_DISPLAY_POWER_ON; kdSetDisplayPropertyivNV(kdDisplay, KD_DISPLAYPROPERTY_POWER_NV, &power); kdSetDisplayPropertycvNV(kdDisplay, KD_DISPLAYPROPERTY_DESKTOP_NAME_NV, KD_DEFAULT_DESKTOP_NV); KDDisplayModeNV mode; if (kdGetDisplayModeNV(kdDisplay, &mode)) { qErrnoWarning(kdGetError(), "Could not get display mode"); return; } qDebug() << " - display mode " << mode.width << "x" << mode.height << " refresh " << mode.refresh; KDint desktopSize[] = { mode.width, mode.height }; if (kdSetDesktopPropertyivNV(kdDesktop, KD_DESKTOPPROPERTY_SIZE_NV, desktopSize)) { qErrnoWarning(kdGetError(), "Could not set desktop size"); return; } // Once we've set up the desktop and display we don't need them anymore kdReleaseDisplayNV(kdDisplay); kdReleaseDesktopNV(kdDesktop); mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (mEglDisplay == EGL_NO_DISPLAY) { qErrnoWarning("EGL failed to obtain display"); } /* Initialize EGL display */ EGLBoolean rvbool = eglInitialize(mEglDisplay, 0, 0); if (!rvbool) { qErrnoWarning("EGL failed to initialize display"); } // cursor = new QOpenKODECursor(this); mGeometry = QRect(0, 0, mode.width, mode.height); mDepth = 24; mFormat = QImage::Format_RGB32; }
KDint KD_APIENTRY kdMain(KDint argc, const KDchar *const *argv) { TEST_EXPR(kdQueryAttribi(9999, KD_NULL) == -1); TEST_EXPR(kdGetError() == KD_EINVAL); kdSetError(0); TEST_EXPR(kdQueryAttribcv(9999) == KD_NULL); TEST_EXPR(kdGetError() == KD_EINVAL); kdSetError(0); TEST_EXPR(kdQueryIndexedAttribcv(9999, 0) == KD_NULL); TEST_EXPR(kdGetError() == KD_EINVAL); kdSetError(0); return 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; }
KDint KD_APIENTRY kdMain(KDint argc, const KDchar *const *argv) { test_once_count = kdAtomicIntCreateVEN(0); KDThread *threads[THREAD_COUNT] = {KD_NULL}; for(KDint i = 0; i < THREAD_COUNT; i++) { threads[i] = kdThreadCreate(KD_NULL, test_func, KD_NULL); if(threads[i] == KD_NULL) { if(kdGetError() == KD_ENOSYS) { return 0; } TEST_FAIL(); } } for(KDint k = 0; k < THREAD_COUNT; k++) { kdThreadJoin(threads[k], KD_NULL); } TEST_EQ(kdAtomicIntLoadVEN(test_once_count), 1); kdAtomicIntFreeVEN(test_once_count); return 0; }
void QOpenKODEWindow::lower() { if (!m_kdWindow) return; KDboolean focus(false); if (kdSetWindowPropertybv(m_kdWindow, KD_WINDOWPROPERTY_FOCUS, &focus)) { qErrnoWarning(kdGetError(), "Could not set focus"); } }
void QOpenKODEWindow::setVisible(bool visible) { if (!m_kdWindow) return; KDboolean visibillity(visible); if (kdSetWindowPropertybv(m_kdWindow, KD_WINDOWPROPERTY_VISIBILITY, &visibillity)) { qErrnoWarning(kdGetError(), "Could not set visibillity property"); } }
void QOpenKODEWindow::setGeometry(const QRect &rect) { if (isFullScreen) { QList<QPlatformScreen *> screens = QApplicationPrivate::platformIntegration()->screens(); QOpenKODEScreen *screen = qobject_cast<QOpenKODEScreen *>(screens.at(0)); widget()->setGeometry(screen->geometry()); return; } bool needToDeleteContext = false; if (!isFullScreen) { const QRect geo = geometry(); if (geo.size() != rect.size()) { const KDint windowSize[2] = { rect.width(), rect.height() }; if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_SIZE, windowSize)) { qErrnoWarning(kdGetError(), "Could not set native window size"); //return; } else { needToDeleteContext = true; } } if (geo.topLeft() != rect.topLeft()) { const KDint windowPos[2] = { rect.x(), rect.y() }; if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_DESKTOP_OFFSET_NV, windowPos)) { qErrnoWarning(kdGetError(), "Could not set native window position"); //return; } else { needToDeleteContext = true; } } } //need to recreate context if (needToDeleteContext) { delete m_platformGlContext; QList<QPlatformScreen *> screens = QApplicationPrivate::platformIntegration()->screens(); QOpenKODEScreen *screen = qobject_cast<QOpenKODEScreen *>(screens.at(0)); 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); } }
// // Create a direcotry is platform depended. // KDbool AssetsManager::createDirectory ( const KDchar* szPath ) { KDint nRet = kdMkdir ( szPath ); if ( nRet != 0 && ( kdGetError ( ) != KD_EEXIST ) ) { return KD_FALSE; } return KD_TRUE; }
JNIEXPORT jlong JNICALL Java_jogamp_newt_driver_kd_WindowDriver_RealizeWindow (JNIEnv *env, jobject obj, jlong window) { KDWindow *w = (KDWindow*) (intptr_t) window; EGLNativeWindowType nativeWindow=0; jint res = kdRealizeWindow(w, &nativeWindow); if(res) { fprintf(stderr, "[RealizeWindow] failed: 0x%X, 0x%X\n", res, kdGetError()); nativeWindow = 0; } DBG_PRINT( "[RealizeWindow] ok: %p\n", nativeWindow); return (jlong) (intptr_t) nativeWindow; }
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; }
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; } }
KDvoid xmExample_05 ( KDvoid ) { const KDsize size[3] = { 1000, 100, 10000 }; KDvoid* buf; KDint i; kdLogMessage ( "Example 05. Memory allocation\n\n" ); // // Case 1 : kdMalloc // // 메모리 블럭을 할당한다. buf = kdMalloc ( size[ 0 ] ); // 메모리 블럭 할당이 정상적인지 확인한다. if ( buf != KD_NULL ) { kdLogMessage ( "Case 1 : Memory block is allocated." ); } else { // 메모리 블럭 할당 문제가 무엇인지 확인한다. if ( kdGetError ( ) == KD_ENOMEM ) { kdLogMessage ( "Case 1 : Not enough space." ); } else { kdHandleAssertion ( "kdMalloc", __FILE__, __LINE__ ); } } // // Case 2 : kdRealloc // // 할당된 메모리 블럭 사이즈를 줄여다가 다시 크게한다. for ( i = 1; i < 3; i++ ) { // 메모리 블럭을 리사이즈합니다. buf = kdRealloc ( buf, size[i] ); // 메모리 블럭 리사이즈가 정상인지 확인한다. if ( buf != KD_NULL ) { kdLogMessage ( "Case 2 : Memory block is resized." ); } else { // 메모리 블럭 리사이즈 문제가 무엇인지 확인한다. if ( kdGetError ( ) == KD_ENOMEM ) { kdLogMessage ( "Case 2 : Not enough space." ); } else { kdHandleAssertion ( "kdRealloc", __FILE__, __LINE__); } } } // // Case 3 : kdFree // // 메모리 블럭 해제한다. kdFree ( buf ); kdLogMessage ( "Case 3 : Allocated memory block is freed." ); }