Ejemplo n.º 1
0
bool StWinHandles::registerClass(const StStringUtfWide& theName,
                                 WNDPROC                theProc) {
    HINSTANCE aModule = GetModuleHandleW(NULL);
    WNDCLASSW aClass; stMemZero(&aClass, sizeof(aClass));
    // redraw on resize, and request own DC for window
    aClass.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    aClass.lpfnWndProc   = theProc;
    aClass.cbClsExtra    = 0;
    aClass.cbWndExtra    = 0;
    aClass.hInstance     = aModule;
    aClass.hIcon         = LoadIconW(aModule, L"A");
    aClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
    aClass.hbrBackground = NULL;
    aClass.lpszMenuName  = NULL;
    aClass.lpszClassName = theName.toCString();
    if(RegisterClassW(&aClass) == 0) {
        stError(StString("WinAPI: Failed to register window class '") + theName.toUtf8() + "'");
        return false;
    }
    return true;
}
Ejemplo n.º 2
0
// function create GUI window
bool StWindowImpl::create() {
    myKeysState.reset();

    // replace default XError handler to ignore some errors
    XSetErrorHandler(stXErrorHandler);

    myInitState = STWIN_INITNOTSTART;
    // X-server implementation
    // create window on unix systems throw X-server
    int dummy;

    // open a connection to the X server
    StXDisplayH stXDisplay = new StXDisplay();
    if(!stXDisplay->isOpened()) {
        stXDisplay.nullify();
        stError("X, could not open display");
        myInitState = STWIN_ERROR_X_OPENDISPLAY;
        return false;
    }
    myMaster.stXDisplay = stXDisplay;
    Display* hDisplay = stXDisplay->hDisplay;

#if defined(ST_HAVE_EGL)
    myMaster.hRC = new StWinGlrc(eglGetDisplay(hDisplay), attribs.IsGlDebug, attribs.GlDepthSize);
    if(!myMaster.hRC->isValid()) {
        myMaster.close();
        mySlave.close();
        myInitState = STWIN_ERROR_X_GLRC_CREATE;
        return false;
    }

    XVisualInfo aVisInfo;
    aVisInfo.visualid = 0;
    if (eglGetConfigAttrib(myMaster.hRC->getDisplay(),
                           myMaster.hRC->getConfig(),
                           EGL_NATIVE_VISUAL_ID,
                           (EGLint* )&aVisInfo.visualid) != EGL_TRUE) {
        myMaster.close();
        mySlave.close();
        myInitState = STWIN_ERROR_X_GLRC_CREATE;
        return false;
    }

    int aNbVisuals = 0;
    stXDisplay->hVisInfo = XGetVisualInfo(hDisplay, VisualIDMask, &aVisInfo, &aNbVisuals);

#else // GLX

    // make sure OpenGL's GLX extension supported
    if(!glXQueryExtension(hDisplay, &dummy, &dummy)) {
        myMaster.close();
        stError("X, server has no OpenGL GLX extension");
        myInitState = STWIN_ERROR_X_NOGLX;
        return false;
    }

    int anAttribsBuff[] = {
        GLX_STEREO,        attribs.IsGlStereo ? True : False,
        GLX_X_RENDERABLE,  True,
        GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
        GLX_RENDER_TYPE,   GLX_RGBA_BIT,
        GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR,
        GLX_RED_SIZE,      8,
        GLX_GREEN_SIZE,    8,
        GLX_BLUE_SIZE,     8,
        GLX_ALPHA_SIZE,    0,
        GLX_DEPTH_SIZE,    attribs.GlDepthSize,
        GLX_STENCIL_SIZE,  0,
        GLX_DOUBLEBUFFER,  True,
        //GLX_SAMPLE_BUFFERS, 1,
        //GLX_SAMPLES,        4,
        None
    };

    // FBConfigs were added in GLX version 1.3
    int aGlxMajor = 0;
    int aGlxMinor = 0;
    const bool hasFBCfg = glXQueryVersion(hDisplay, &aGlxMajor, &aGlxMinor)
                       && ((aGlxMajor == 1 && aGlxMinor >= 3) || (aGlxMajor > 1));

    int aFBCount = 0;
    GLXFBConfig* aFBCfgList = NULL;
    if(hasFBCfg) {
        aFBCfgList = glXChooseFBConfig(hDisplay, DefaultScreen(hDisplay),
                                       anAttribsBuff, &aFBCount);
    }
    if(aFBCfgList == NULL
    && hasFBCfg
    && attribs.IsGlStereo) {
        ST_ERROR_LOG("X, no Quad Buffered visual");
        anAttribsBuff[1] = False;
        aFBCfgList = glXChooseFBConfig(hDisplay, DefaultScreen(hDisplay),
                                       anAttribsBuff, &aFBCount);
    }
    if(aFBCfgList != NULL
    && aFBCount >= 1) {
        stXDisplay->FBCfg    = aFBCfgList[0];
        stXDisplay->hVisInfo = glXGetVisualFromFBConfig(hDisplay, stXDisplay->FBCfg);
    } else {
        // try to use glXChooseVisual... pointless?
        int aDblBuff[] = {
            GLX_RGBA,
            GLX_DEPTH_SIZE, attribs.GlDepthSize,
            GLX_DOUBLEBUFFER,
            None
        };
        if(attribs.IsGlStereo) {
            // find an appropriate visual
            int aQuadBuff[] = {
                GLX_RGBA,
                GLX_DEPTH_SIZE, attribs.GlDepthSize,
                GLX_DOUBLEBUFFER,
                GLX_STEREO,
                None
            };

            stXDisplay->hVisInfo = glXChooseVisual(hDisplay, DefaultScreen(hDisplay), aQuadBuff);
            if(stXDisplay->hVisInfo == NULL) {
                ST_ERROR_LOG("X, no Quad Buffered visual");
                stXDisplay->hVisInfo = glXChooseVisual(hDisplay, DefaultScreen(hDisplay), aDblBuff);
                if(stXDisplay->hVisInfo == NULL) {
                    myMaster.close();
                    stError("X, no RGB visual with depth buffer");
                    myInitState = STWIN_ERROR_X_NORGB;
                    return false;
                }
            }
        } else {
            // find an appropriate visual
            // find an OpenGL-capable RGB visual with depth buffer
            stXDisplay->hVisInfo = glXChooseVisual(hDisplay, DefaultScreen(hDisplay), aDblBuff);
            if(stXDisplay->hVisInfo == NULL) {
                myMaster.close();
                stError("X, no RGB visual with depth buffer");
                myInitState = STWIN_ERROR_X_NORGB;
                return false;
            }
        }
    }
    XFree(aFBCfgList);
#endif

    if(attribs.Slave != StWinSlave_slaveOff) {
        // just copy handle
        mySlave.stXDisplay = stXDisplay;
    }

    // create an X window with the selected visual
    XSetWindowAttributes aWinAttribsX = createDefaultAttribs(stXDisplay);
    updateChildRect();

    Window aParentWin = (Window )myParentWin;
    if(aParentWin == 0 && !attribs.IsNoDecor) {
        aWinAttribsX.override_redirect = False;
        myMaster.hWindow = XCreateWindow(hDisplay, stXDisplay->getRootWindow(),
                                         myRectNorm.left(),  myRectNorm.top(),
                                         myRectNorm.width(), myRectNorm.height(),
                                         0, stXDisplay->getDepth(),
                                         InputOutput,
                                         stXDisplay->getVisual(),
                                         CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &aWinAttribsX);

        if(myMaster.hWindow == 0) {
            myMaster.close();
            stError("X, XCreateWindow failed for Master");
            myInitState = STWIN_ERROR_X_CREATEWIN;
            return false;
        }
        aParentWin = myMaster.hWindow;

        XSetStandardProperties(hDisplay, myMaster.hWindow,
                               myWindowTitle.toCString(),
                               myWindowTitle.toCString(),
                               None, NULL, 0, NULL);

        // setup WM_CLASS in sync with .desktop StartupWMClass entity
        // to ensure Window Manager would show an propriate icon for application
        XClassHint* aClassHint = XAllocClassHint();
        if(aClassHint != NULL) {
            StString aName = StProcess::getProcessName();
            StString aClass("sView");
            // const_cast should be harmless here and it seems to be just broken signature of XClassHint structure
            aClassHint->res_name  = const_cast<char* >(aName.toCString());
            aClassHint->res_class = const_cast<char* >(aClass.toCString());
            XSetClassHint(hDisplay, myMaster.hWindow, aClassHint);
            XFree(aClassHint);
        }
    }

    aWinAttribsX.override_redirect = True; // GL window always undecorated
    myMaster.hWindowGl = XCreateWindow(hDisplay, (aParentWin != 0) ? aParentWin : stXDisplay->getRootWindow(),
                                       0, 0, myRectNorm.width(), myRectNorm.height(),
                                       0, stXDisplay->getDepth(),
                                       InputOutput,
                                       stXDisplay->getVisual(),
                                       CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &aWinAttribsX);
    if(myMaster.hWindowGl == 0) {
        myMaster.close();
        stError("X, XCreateWindow failed for Master");
        myInitState = STWIN_ERROR_X_CREATEWIN;
        return false;
    }

    XSetStandardProperties(hDisplay, myMaster.hWindowGl,
                           "master window", "master window",
                           None, NULL, 0, NULL);

    if(attribs.Slave != StWinSlave_slaveOff) {
        aWinAttribsX.event_mask = NoEventMask; // we do not parse any events to slave window!
        aWinAttribsX.override_redirect = True; // slave window always undecorated
        mySlave.hWindowGl = XCreateWindow(hDisplay, stXDisplay->getRootWindow(),
                                          getSlaveLeft(),  getSlaveTop(),
                                          getSlaveWidth(), getSlaveHeight(),
                                          0, stXDisplay->getDepth(),
                                          InputOutput,
                                          stXDisplay->getVisual(),
                                          CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &aWinAttribsX);

        if(mySlave.hWindowGl == 0) {
            myMaster.close();
            mySlave.close();
            stError("X, XCreateWindow failed for Slave");
            myInitState = STWIN_ERROR_X_CREATEWIN;
            return false;
        }

        XSetStandardProperties(hDisplay, mySlave.hWindowGl,
                               "slave window", "slave window",
                               None, NULL, 0, NULL);
    }

    int isGlCtx = myMaster.glCreateContext(attribs.Slave != StWinSlave_slaveOff ? &mySlave : NULL,
                                           myRectNorm,
                                           attribs.GlDepthSize,
                                           attribs.IsGlStereo,
                                           attribs.IsGlDebug);
    if(isGlCtx != STWIN_INIT_SUCCESS) {
        myMaster.close();
        mySlave.close();
        myInitState = isGlCtx;
        return false;
    }

    myGlContext = new StGLContext(myResMgr);
    if(!myGlContext->stglInit()) {
        myMaster.close();
        mySlave.close();
        stError("Critical error - broken GL context!\nInvalid OpenGL driver?");
        myInitState = STWIN_ERROR_X_GLRC_CREATE;
        return false;
    }

    // handle close window event
    if(myMaster.hWindow != 0) {
        XSetWMProtocols(hDisplay, myMaster.hWindow, &(stXDisplay->wndDestroyAtom), 1);
    }

    // Announce XDND support
    myMaster.setupXDND();

    // Initialize XRandr events reception
    if(XRRQueryExtension(hDisplay, &myMaster.xrandrEventBase, &dummy)) {
        XRRSelectInput(hDisplay,
                       stXDisplay->getRootWindow(),
                       RRScreenChangeNotifyMask |
                       RRCrtcChangeNotifyMask   |
                       RROutputPropertyNotifyMask);
        myMaster.isRecXRandrEvents = true;
    } else {
        myMaster.isRecXRandrEvents = false;
    }

    // request the X window to be displayed on the screen
    if(attribs.Slave != StWinSlave_slaveOff) {

        // request the X window to be displayed on the screen
        if(!attribs.IsSlaveHidden && (!isSlaveIndependent() || myMonitors.size() > 1)) {
            XMapWindow(hDisplay, mySlave.hWindowGl);
            //XIfEvent(hDisplay, &myXEvent, stXWaitMapped, (char* )mySlave.hWindowGl);
        }
        // always hise mouse cursor on slave window
        mySlave.setupNoCursor();
    }
    if(!attribs.IsHidden) {
        if(myMaster.hWindow != 0) {
            XMapWindow(hDisplay, myMaster.hWindow);
            //XIfEvent(hDisplay, &myXEvent, stXWaitMapped, (char* )myMaster.hWindow);
        }
        XMapWindow(hDisplay, myMaster.hWindowGl);
        //XIfEvent(hDisplay, &myXEvent, stXWaitMapped, (char* )myMaster.hWindowGl);
    }

    // setup default icon
    if((Window )myParentWin == 0) {
        XpmCreatePixmapFromData(hDisplay, myMaster.hWindow, (char** )sview_xpm, &myMaster.iconImage, &myMaster.iconShape, NULL);
        XWMHints anIconHints;
        anIconHints.flags       = IconPixmapHint | IconMaskHint;
        anIconHints.icon_pixmap = myMaster.iconImage;
        anIconHints.icon_mask   = myMaster.iconShape;
        XSetWMHints(hDisplay, myMaster.hWindow, &anIconHints);
    }

    // we need this call to go around bugs
    if(!attribs.IsFullScreen && myMaster.hWindow != 0) {
        XMoveResizeWindow(hDisplay, myMaster.hWindow,
                          myRectNorm.left(),  myRectNorm.top(),
                          myRectNorm.width(), myRectNorm.height());
    }
    // flushes the output buffer, most client apps needn't use this cause buffer is automatically flushed as needed by calls to XNextEvent()...
    XFlush(hDisplay);
    myMonitors.registerUpdater(true);
    myIsUpdated = true;
    myInitState = STWIN_INIT_SUCCESS;
    return true;
}
Ejemplo n.º 3
0
bool StWindowImpl::onAndroidInitWindow() {
    myIsPaused = false;
    if(myParentWin->getWindow() == NULL) {
        return false;
    }

    if(!myMaster.hRC.isNull()) {
        myMaster.hWindowGl = myParentWin->getWindow();

        EGLint anEglErr = eglGetError();
        (void )anEglErr;

        EGLint aFormat = 0;
        if(eglGetConfigAttrib(myMaster.hRC->getDisplay(), myMaster.hRC->getConfig(), EGL_NATIVE_VISUAL_ID, &aFormat) == EGL_FALSE) {
            anEglErr = eglGetError();
        }
        ANativeWindow_setBuffersGeometry(myMaster.hWindowGl, 0, 0, aFormat);

        myMaster.eglSurface = eglCreateWindowSurface(myMaster.hRC->getDisplay(), myMaster.hRC->getConfig(), myMaster.hWindowGl, NULL);
        if(myMaster.eglSurface == NULL) {
            anEglErr = eglGetError();
        }

        // bind the rendering context to the window
        if(!myMaster.hRC->makeCurrent(myMaster.eglSurface)) {
            myMaster.close();
            mySlave.close();
            myInitState = STWIN_ERROR_X_GLRC_CREATE;
            stError("Critical error - broken EGL context!");
            return false;
        }

        const EGLint aWidth  = ANativeWindow_getWidth (myMaster.hWindowGl);
        const EGLint aHeight = ANativeWindow_getHeight(myMaster.hWindowGl);

        const bool isResized = myRectNorm.width()  != aWidth
                            || myRectNorm.height() != aHeight;
        myRectNorm.left()   = 0;
        myRectNorm.top()    = 0;
        myRectNorm.right()  = myRectNorm.left() + aWidth;
        myRectNorm.bottom() = myRectNorm.top()  + aHeight;
        myRectFull = myRectNorm;

        myInitState = STWIN_INIT_SUCCESS;
        if(isResized) {
            myStEvent.Size.init(getEventTime(), myRectNorm.width(), myRectNorm.height(), myForcedAspect);
            signals.onResize->emit(myStEvent.Size);
        }
        return true;
    }

    myMaster.hRC = new StWinGlrc(eglGetDisplay(EGL_DEFAULT_DISPLAY), attribs.IsGlDebug, attribs.GlDepthSize, attribs.GlStencilSize);
    if(!myMaster.hRC->isValid()) {
        myMaster.close();
        mySlave.close();
        myInitState = STWIN_ERROR_X_GLRC_CREATE;
        return false;
    }

    myMaster.hWindowGl = myParentWin->getWindow();
    myInitState = myMaster.glCreateContext(NULL, myRectNorm, attribs.GlDepthSize, attribs.GlStencilSize, attribs.IsGlStereo, attribs.IsGlDebug);
    if(myInitState != STWIN_INIT_SUCCESS) {
        return false;
    }

    EGLint aWidth = 0, aHeight = 0;
    if(myMaster.hWindowGl != NULL) {
        aWidth  = ANativeWindow_getWidth (myMaster.hWindowGl);
        aHeight = ANativeWindow_getHeight(myMaster.hWindowGl);
    } else if(myMaster.eglSurface != EGL_NO_SURFACE) {
        eglQuerySurface(myMaster.hRC->getDisplay(), myMaster.eglSurface, EGL_WIDTH,  &aWidth);
        eglQuerySurface(myMaster.hRC->getDisplay(), myMaster.eglSurface, EGL_HEIGHT, &aHeight);
    }

    myRectNorm.left()   = 0;
    myRectNorm.top()    = 0;
    myRectNorm.right()  = myRectNorm.left() + aWidth;
    myRectNorm.bottom() = myRectNorm.top()  + aHeight;
    myRectFull = myRectNorm;

    myGlContext = new StGLContext(myResMgr);
    if(!myGlContext->stglInit()) {
        myMaster.close();
        mySlave.close();
        stError("Critical error - broken GL context!\nInvalid OpenGL driver?");
        myInitState = STWIN_ERROR_X_GLRC_CREATE;
        return false;
    }
    myInitState = STWIN_INIT_SUCCESS;
    return true;
}
Ejemplo n.º 4
0
bool StApplication::open() {
    if(!myWindow.isNull()) {
        return true;
    }

    StSettings aGlobalSettings(myResMgr, "sview");
    if(!mySwitchTo.isNull()) {
        myRendId = mySwitchTo->getRendererId();
        myWindow = mySwitchTo;
        mySwitchTo.nullify();
        aGlobalSettings.saveString(ST_SETTING_RENDERER,      myRendId);
        aGlobalSettings.saveBool  (ST_SETTING_RENDERER_AUTO, false);
    } else {
        if(myRenderers.isEmpty()) {
            myWindow = new StWindow(myResMgr, myWinParent);
            myWindow->setMessagesQueue(myMsgQueue);
            myWindow->params.VSyncMode = params.VSyncMode;
        } else {
            bool isAuto = myRendId.isEqualsIgnoreCase(ST_SETTING_AUTO_VALUE);
            if(!isAuto) {
                for(size_t anIter = 0; anIter < myRenderers.size(); ++anIter) {
                    StHandle<StWindow> aWin = myRenderers[anIter];
                    if(myRendId == aWin->getRendererId()) {
                        myWindow = aWin;
                        aGlobalSettings.saveString(ST_SETTING_RENDERER,      myRendId);
                        aGlobalSettings.saveBool  (ST_SETTING_RENDERER_AUTO, isAuto);
                        break;
                    }
                }

                if(myWindow.isNull()) {
                    stError(StString("Output with id '" + myRendId + "' is not found."));
                    isAuto = true;
                }
            }

            if(isAuto) {
                // autodetection
                aGlobalSettings.saveString(ST_SETTING_RENDERER,      ST_SETTING_AUTO_VALUE);
                aGlobalSettings.saveBool  (ST_SETTING_RENDERER_AUTO, isAuto);
                myWindow = myRenderers[0];
                if(!myDevices.isEmpty()) {
                    StHandle<StOutDevice> aBestDev = myDevices[0];
                    for(size_t aDevIter = 0; aDevIter < myDevices.size(); ++aDevIter) {
                        const StHandle<StOutDevice>& aDev = myDevices[aDevIter];
                        if(aDev->Priority > aBestDev->Priority) {
                            aBestDev = aDev;
                        }
                    }
                    for(size_t anIter = 0; anIter < myRenderers.size(); ++anIter) {
                        const StHandle<StWindow>& aWin = myRenderers[anIter];
                        if(aBestDev->PluginId == aWin->getRendererId()) {
                            myWindow = aWin;
                            myWindow->setDevice(aBestDev->DeviceId);
                            break;
                        }
                    }
                }
            }
        }
        myWindow->setTitle(myTitle);
    }

    // synchronize devices enumeration
    const StString aPluginId = myWindow->getRendererId();
    const StString aDeviceId = myWindow->getDeviceId();
    for(size_t aDevIter = 0; aDevIter < myDevices.size(); ++aDevIter) {
        const StHandle<StOutDevice>& aDev = myDevices[aDevIter];
        if(aPluginId == aDev->PluginId
        && aDeviceId == aDev->DeviceId) {
            params.ActiveDevice->setValue((int32_t )aDevIter);
            break;
        }
    }

    // setup GL options before window creation
    const StWinAttr anAttribs[] = {
        StWinAttr_GlDebug, (StWinAttr )myGlDebug,
        StWinAttr_NULL
    };
    myWindow->setAttributes(anAttribs);

    myIsOpened = myWindow->create();
    if(myIsOpened) {
        // connect slots
        myWindow->signals.onRedraw    = stSlot(this, &StApplication::doDrawProxy);
        myWindow->signals.onClose     = stSlot(this, &StApplication::doClose);
        myWindow->signals.onPause     = stSlot(this, &StApplication::doPause);
        myWindow->signals.onResize    = stSlot(this, &StApplication::doResize);
        myWindow->signals.onAction    = stSlot(this, &StApplication::doAction);
        myWindow->signals.onKeyDown   = stSlot(this, &StApplication::doKeyDown);
        myWindow->signals.onKeyUp     = stSlot(this, &StApplication::doKeyUp);
        myWindow->signals.onKeyHold   = stSlot(this, &StApplication::doKeyHold);
        myWindow->signals.onMouseDown = stSlot(this, &StApplication::doMouseDown);
        myWindow->signals.onMouseUp   = stSlot(this, &StApplication::doMouseUp);
        myWindow->signals.onTouch     = stSlot(this, &StApplication::doTouch);
        myWindow->signals.onGesture   = stSlot(this, &StApplication::doGesture);
        myWindow->signals.onScroll    = stSlot(this, &StApplication::doScroll);
        myWindow->signals.onFileDrop  = stSlot(this, &StApplication::doFileDrop);
        myWindow->signals.onNavigate  = stSlot(this, &StApplication::doNavigate);
    }

    return myIsOpened;
}
Ejemplo n.º 5
0
void StAndroidGlue::threadEntry() {
    if(myJavaVM->AttachCurrentThread(&myThJniEnv, NULL) < 0) {
        ST_ERROR_LOG("Failed to attach working thread to Java VM");
        return;
    }

    THE_ANDROID_GLUE = this;
    StMessageBox::setCallback(msgBoxCallback);

    myConfig = AConfiguration_new();
    AConfiguration_fromAssetManager(myConfig, myActivity->assetManager);
    updateMonitors();
    printConfig();

    ALooper* aLooper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
    ALooper_addFd(aLooper, myMsgRead, LooperId_MAIN, ALOOPER_EVENT_INPUT, NULL, &myCmdPollSource);
    myLooper = aLooper;

    pthread_mutex_lock(&myMutex);
    myIsRunning = true;
    pthread_cond_broadcast(&myCond);
    pthread_mutex_unlock(&myMutex);

    // try to load stereo APIs
    /**jclass aJClass_Real3D = myThJniEnv->FindClass("com/lge/real3d/Real3D");
    if(aJClass_Real3D != NULL) {
        jmethodID aJMet_isStereoDisplayAvailable = myThJniEnv->GetStaticMethodID(aJClass_Real3D, "isStereoDisplayAvailable", "(Landroid/content/Contex;)Z");
        postMessage("com.lge.real3d.Real3D !!!");
    }

    jclass aJClass_HTC = myThJniEnv->FindClass("com/htc/view/DisplaySetting");
    if(aJClass_HTC != NULL) {
        jmethodID aJMet_isStereoDisplayAvailable = myThJniEnv->GetStaticMethodID(aJClass_HTC, "setStereoscopic3DFormat", "(Landroid/view/Surface;I)Z");
        postMessage("com.htc.view.DisplaySetting !!!");
    }

    jclass aJClass_Sharp = myThJniEnv->FindClass("jp/co/sharp/android/stereo3dlcd/SurfaceController");
    if(aJClass_Sharp != NULL) {
        jmethodID aJMet_setStereoView = myThJniEnv->GetMethodID(aJClass_Sharp, "setStereoView", "(Z)V");
        postMessage("jp.co.sharp.android.stereo3dlcd !!!");
    }*/

    createApplication();
    if(!myApp.isNull()) {
        if(!myApp->open()) {
            stError("Error: application can not be executed!");
        }
        myApp->exec();
    } else {
        stError("Error: no application to execute!");
    }
    myApp.nullify();

    // application is done but we are waiting for destroying event...
    bool isFirstWait = true;
    for(; !myToDestroy; ) {
        if(isFirstWait) {
            postExit();
            isFirstWait = false;
        }

        StAndroidPollSource* aSource = NULL;
        int aNbEvents = 0;
        ALooper_pollAll(-1, NULL, &aNbEvents, (void** )&aSource);
        if(aSource != NULL) {
            aSource->process(this, aSource);
        }
    }

    freeSavedState();
    pthread_mutex_lock(&myMutex);
    if(myInputQueue != NULL) {
        AInputQueue_detachLooper(myInputQueue);
    }
    AConfiguration_delete(myConfig);
    pthread_cond_broadcast(&myCond);
    pthread_mutex_unlock(&myMutex);

    myThJniEnv = NULL;
    StMessageBox::setCallback(NULL);
    THE_ANDROID_GLUE = NULL;

    myJavaVM->DetachCurrentThread();
}
Ejemplo n.º 6
0
bool StDXManager::init(const HWND       theWinHandle,
                       const int        theSizeX,
                       const int        theSizeY,
                       const bool       theFullscreen,
                       const StMonitor& theMonitor,
                       const StDXAdapterClass theAdapter) {
    const StString anAdapterStr = theMonitor.getName().subString(0, 12);
    if(!initDxLib()) {
        stError("StDXManager, Direct3DCreate9 failed!");
        return false;
    }

    const UINT aD3dAdaptersNb = getAdapterCount();
    UINT anAdapterId     = UINT(-1);
    UINT anAdapterVendor = UINT(-1);
    D3DADAPTER_IDENTIFIER9 anAdapterInfo;
    for(UINT anAdapterIter = 0; anAdapterIter < aD3dAdaptersNb; ++anAdapterIter) {
        getAdapterIdentifier(anAdapterIter, 0, &anAdapterInfo);
        switch(theAdapter) {
            case ST_DX_ADAPTER_AMD: {
                if(anAdapterInfo.VendorId != ST_DX_VENDOR_AMD) {
                    continue;
                }
                anAdapterVendor = anAdapterIter;
                break;
            }
            case ST_DX_ADAPTER_NVIDIA: {
                if(anAdapterInfo.VendorId != ST_DX_VENDOR_NVIDIA) {
                    continue;
                }
                anAdapterVendor = anAdapterIter;
                break;
            }
            case ST_DX_ADAPTER_ANY:
            default:
                break;
        }
        if(anAdapterStr == StString(anAdapterInfo.DeviceName)) {
            anAdapterId = anAdapterIter;
            break;
        }
    }
    if(theAdapter != ST_DX_ADAPTER_ANY) {
        if(anAdapterId     == UINT(-1)
        && anAdapterVendor != UINT(-1)) {
            anAdapterId = anAdapterVendor;
        }
        if(anAdapterId == UINT(-1)) {
            return false;
        }
    }
    if(anAdapterId == UINT(-1)) {
        // the default adapter is the primary display adapter
        anAdapterId = D3DADAPTER_DEFAULT;
    }

    // setup the present parameters
    if(getAdapterDisplayMode(anAdapterId, &myCurrMode) == D3D_OK) {
        myD3dParams.BackBufferFormat = myCurrMode.Format;
        myRefreshRate = myCurrMode.RefreshRate;
    }
    myD3dParams.Windowed         = !theFullscreen;        // is windowed?
    myD3dParams.BackBufferWidth  = theSizeX;
    myD3dParams.BackBufferHeight = theSizeY;
    myD3dParams.hDeviceWindow    = theWinHandle;

    // create the Video Device
    myD3dDevice = createAqbsDevice(anAdapterId, theWinHandle, myD3dParams);
    if(myD3dDevice == NULL) {
        HRESULT isOK = myD3dLib->CreateDevice(anAdapterId, D3DDEVTYPE_HAL, // the HAL (hardware accelerated layer) uses your 3d accelerator card
                                              theWinHandle,
                                              ST_D3D_DEVICE_FLAGS,
                                              &myD3dParams, &myD3dDevice);
        if(isOK < 0) {
            return false;
        }
    }
    // this normalizes the normal values (this is important for how lighting effects your models)
    ///myD3dDevice->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE);
    ST_DEBUG_LOG("Direct3D9, Created StDXManager device (WxH= " + theSizeX + "x"+ theSizeY + ")");
    return myD3dDevice != NULL;
}