Ejemplo n.º 1
0
QTaskOneScreen::QTaskOneScreen(EGLNativeDisplayType display)
    : m_depth(32)
    , m_format(QImage::Format_Invalid)
    , m_platformContext(0)
    , m_surface(0)
{
#ifdef QEGL_EXTRA_DEBUG
    qWarning("QTaskOneScreen %p\n", this);
#endif

    EGLint major, minor;
#ifdef QEGL_EXTRA_DEBUG
    EGLint index;
#endif
    if (!eglBindAPI(EGL_OPENGL_ES_API)) {
        qWarning("Could not bind GL_ES API\n");
        qFatal("EGL error");
    }

    m_dpy = eglGetDisplay(display);
    disp = m_dpy;
    if (m_dpy == EGL_NO_DISPLAY) {
        qWarning("Could not open egl display\n");
        qFatal("EGL error");
    }
    qWarning("Opened display %p\n", m_dpy);

    if (!eglInitialize(m_dpy, &major, &minor)) {
        qWarning("Could not initialize egl display\n");
        qFatal("EGL error");
    }

    qWarning("Initialized display %d %d\n", major, minor);

    int swapInterval = 1;
    QByteArray swapIntervalString = qgetenv("QT_QPA_EGLFS_SWAPINTERVAL");
    if (!swapIntervalString.isEmpty()) {
        bool ok;
        swapInterval = swapIntervalString.toInt(&ok);
        if (!ok)
            swapInterval = 1;
    }
    eglSwapInterval(m_dpy, swapInterval);

    m_cursor = new QTaskOneCursor(this);
}
bool QEglFSContext::makeCurrent(QPlatformSurface *surface)
{
    bool current = QEGLPlatformContext::makeCurrent(surface);
    if (current && !m_swapIntervalConfigured) {
        m_swapIntervalConfigured = true;
        int swapInterval = 1;
        QByteArray swapIntervalString = qgetenv("QT_QPA_EGLFS_SWAPINTERVAL");
        if (!swapIntervalString.isEmpty()) {
            bool ok;
            swapInterval = swapIntervalString.toInt(&ok);
            if (!ok)
                swapInterval = 1;
        }
        eglSwapInterval(eglDisplay(), swapInterval);
    }
    return current;
}
bool QEGLPlatformContext::makeCurrent(QPlatformSurface *surface)
{
    Q_ASSERT(surface->surface()->supportsOpenGL());

    eglBindAPI(m_api);

    EGLSurface eglSurface = eglSurfaceForPlatformSurface(surface);

    if (eglSurface == EGL_NO_SURFACE)
        return false;

    // shortcut: on some GPUs, eglMakeCurrent is not a cheap operation
    if (eglGetCurrentContext() == m_eglContext &&
        eglGetCurrentDisplay() == m_eglDisplay &&
        eglGetCurrentSurface(EGL_READ) == eglSurface &&
        eglGetCurrentSurface(EGL_DRAW) == eglSurface) {
        return true;
    }

    const bool ok = eglMakeCurrent(m_eglDisplay, eglSurface, eglSurface, m_eglContext);
    if (ok) {
        if (!m_swapIntervalEnvChecked) {
            m_swapIntervalEnvChecked = true;
            if (qEnvironmentVariableIsSet("QT_QPA_EGLFS_SWAPINTERVAL")) {
                QByteArray swapIntervalString = qgetenv("QT_QPA_EGLFS_SWAPINTERVAL");
                bool intervalOk;
                const int swapInterval = swapIntervalString.toInt(&intervalOk);
                if (intervalOk)
                    m_swapIntervalFromEnv = swapInterval;
            }
        }
        const int requestedSwapInterval = m_swapIntervalFromEnv >= 0
            ? m_swapIntervalFromEnv
            : surface->format().swapInterval();
        if (requestedSwapInterval >= 0 && m_swapInterval != requestedSwapInterval) {
            m_swapInterval = requestedSwapInterval;
            if (eglSurface != EGL_NO_SURFACE) // skip if using surfaceless context
                eglSwapInterval(eglDisplay(), m_swapInterval);
        }
    } else {
        qWarning("QEGLPlatformContext: eglMakeCurrent failed: %x", eglGetError());
    }

    return ok;
}
Ejemplo n.º 4
0
void EglFSWaylandContext::swapBuffers(QPlatformSurface *surface)
{
    EglFSWaylandWindow *window = static_cast<EglFSWaylandWindow *>(surface);
    EGLSurface eglSurface = window->surface();

    makeCurrent(surface);

    StateGuard stateGuard;

    if (!m_blitter)
        m_blitter = new EglFSWaylandBlitter(this);
    m_blitter->blit(window);

    eglSwapInterval(eglDisplay(), format().swapInterval());
    eglSwapBuffers(eglDisplay(), eglSurface);

    //window.setCanResize(true);
}
TEST_F(SurfaceTextureGLToGLTest, EglDestroySurfaceUnrefsBuffers) {
    sp<GraphicBuffer> buffers[2];

    // This test requires async mode to run on a single thread.
    EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface,
            mProducerEglSurface, mProducerEglContext));
    ASSERT_EQ(EGL_SUCCESS, eglGetError());
    EXPECT_TRUE(eglSwapInterval(mEglDisplay, 0));
    ASSERT_EQ(EGL_SUCCESS, eglGetError());

    for (int i = 0; i < 2; i++) {
        // Produce a frame
        EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface,
                mProducerEglSurface, mProducerEglContext));
        ASSERT_EQ(EGL_SUCCESS, eglGetError());
        glClear(GL_COLOR_BUFFER_BIT);
        eglSwapBuffers(mEglDisplay, mProducerEglSurface);

        // Consume a frame
        EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
                mEglContext));
        ASSERT_EQ(EGL_SUCCESS, eglGetError());
        mFW->waitForFrame();
        ASSERT_EQ(NO_ERROR, mST->updateTexImage());
        buffers[i] = mST->getCurrentBuffer();
    }

    // Destroy the GL texture object to release its ref on buffers[2].
    GLuint texID = TEX_ID;
    glDeleteTextures(1, &texID);

    // Destroy the EGLSurface
    EXPECT_TRUE(eglDestroySurface(mEglDisplay, mProducerEglSurface));
    ASSERT_EQ(EGL_SUCCESS, eglGetError());
    mProducerEglSurface = EGL_NO_SURFACE;

    // This test should have the only reference to buffer 0.
    EXPECT_EQ(1, buffers[0]->getStrongCount());

    // The GLConsumer should hold a single reference to buffer 1 in its
    // mCurrentBuffer member.  All of the references in the slots should have
    // been released.
    EXPECT_EQ(2, buffers[1]->getStrongCount());
}
Ejemplo n.º 6
0
	void GlContext::resize(uint32_t _width, uint32_t _height, uint32_t _flags)
	{
		BX_UNUSED(_width, _height);

#	if BX_PLATFORM_ANDROID
		if (NULL != m_display)
		{
			EGLint format;
			eglGetConfigAttrib(m_display, m_config, EGL_NATIVE_VISUAL_ID, &format);
			ANativeWindow_setBuffersGeometry( (ANativeWindow*)g_platformData.nwh, _width, _height, format);
		}
#	endif // BX_PLATFORM_ANDROID

		if (NULL != m_display)
		{
			bool vsync = !!(_flags&BGFX_RESET_VSYNC);
			eglSwapInterval(m_display, vsync ? 1 : 0);
		}
	}
Ejemplo n.º 7
0
    void EGLWindow::setVSyncEnabled(bool vsync) {
        mVSync = vsync;
        // we need to make our context current to set vsync
        // store previous context to restore when finished.
        ::EGLSurface oldRead = eglGetCurrentSurface(EGL_READ);
        EGL_CHECK_ERROR
        ::EGLSurface oldDraw = eglGetCurrentSurface(EGL_DRAW);
        EGL_CHECK_ERROR
        ::EGLContext  oldContext  = eglGetCurrentContext();
        EGL_CHECK_ERROR
        ::EGLDisplay dpy = mGLSupport->getGLDisplay();

        mContext->setCurrent();

        if (! mIsExternalGLControl )
        {
            eglSwapInterval(dpy, vsync ? mVSyncInterval : 0);
            EGL_CHECK_ERROR
        }
Ejemplo n.º 8
0
void egl_set_swap_interval(void *data, unsigned interval)
{
   /* Can be called before initialization.
    * Some contexts require that swap interval 
    * is known at startup time.
    */
   g_interval = interval;

   if (g_egl_dpy  == EGL_NO_DISPLAY)
      return;
   if (!(eglGetCurrentContext()))
      return;

   RARCH_LOG("[EGL]: eglSwapInterval(%u)\n", interval);
   if (!eglSwapInterval(g_egl_dpy, interval))
   {
      RARCH_ERR("[EGL]: eglSwapInterval() failed.\n");
      egl_report_error();
   }
}
Ejemplo n.º 9
0
bool CEGLWrapper::BindContext(EGLDisplay display, EGLSurface surface, EGLContext context)
{
    EGLBoolean status;
    status = eglMakeCurrent(display, surface, surface, context);
    CheckError();

    // For EGL backend, it needs to clear all the back buffers of the window
    // surface before drawing anything, otherwise the image will be blinking
    // heavily.  The default eglWindowSurface has 3 gdl surfaces as the back
    // buffer, that's why glClear should be called 3 times.
    eglSwapInterval(display, 0);
    glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
    glClear (GL_COLOR_BUFFER_BIT);
    eglSwapBuffers(display, surface);
    glClear (GL_COLOR_BUFFER_BIT);
    eglSwapBuffers(display, surface);
    glClear (GL_COLOR_BUFFER_BIT);
    eglSwapBuffers(display, surface);

    return status;
}
Ejemplo n.º 10
0
EGLint GLContext::Swap() {
  bool b = eglSwapBuffers(display_, surface_);
  if (!b) {
    EGLint err = eglGetError();
    if (err == EGL_BAD_SURFACE) {
      //Recreate surface
      InitEGLSurface();
      err = EGL_SUCCESS; //Still consider glContext is valid
    } else if (err == EGL_CONTEXT_LOST || err == EGL_BAD_CONTEXT) {
      //Context has been lost!!
      context_valid_ = false;
      Terminate();
      InitEGLContext();
    }

    return err;
  }
  if (restoreInterval_ && swapInterval_ != SWAPINTERVAL_DEFAULT) {
    eglSwapInterval(display_, swapInterval_); //Restore Swap interval
  }
  return EGL_SUCCESS;
}
Ejemplo n.º 11
0
int Java_org_yabause_android_YabauseRunnable_initViewport( int width, int height)
{
   int swidth;
   int sheight;
   int error;
   char * buf;

   g_Display = eglGetCurrentDisplay();
   g_Surface = eglGetCurrentSurface(EGL_READ);
   g_Context = eglGetCurrentContext();

   eglQuerySurface(g_Display,g_Surface,EGL_WIDTH,&swidth);
   eglQuerySurface(g_Display,g_Surface,EGL_HEIGHT,&sheight);
   
   glViewport(0,0,swidth,sheight);
   
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrthof(0, 320, 224, 0, 1, 0);
   
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();

   glMatrixMode(GL_TEXTURE);
   glLoadIdentity();
   
   glDisable(GL_BLEND);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   
   yprintf(glGetString(GL_VENDOR));
   yprintf(glGetString(GL_RENDERER));
   yprintf(glGetString(GL_VERSION));
   yprintf(glGetString(GL_EXTENSIONS));
   yprintf(eglQueryString(g_Display,EGL_EXTENSIONS));
   eglSwapInterval(g_Display,0);
   eglMakeCurrent(g_Display,EGL_NO_SURFACE,EGL_NO_SURFACE,EGL_NO_CONTEXT);
   return 0;
}
bool EglManager::makeCurrent(EGLSurface surface, EGLint* errOut) {
    if (isCurrent(surface)) return false;

    if (surface == EGL_NO_SURFACE) {
        // Ensure we always have a valid surface & context
        surface = mPBufferSurface;
    }
    if (!eglMakeCurrent(mEglDisplay, surface, surface, mEglContext)) {
        if (errOut) {
            *errOut = eglGetError();
            ALOGW("Failed to make current on surface %p, error=%s", (void*)surface,
                  egl_error_str(*errOut));
        } else {
            LOG_ALWAYS_FATAL("Failed to make current on surface %p, error=%s", (void*)surface,
                             eglErrorString());
        }
    }
    mCurrentSurface = surface;
    if (Properties::disableVsync) {
        eglSwapInterval(mEglDisplay, 0);
    }
    return true;
}
Ejemplo n.º 13
0
static void
egl_make_swapbuffers_nonblock(struct egl_state *egl)
{
	EGLint a = EGL_MIN_SWAP_INTERVAL;
	EGLint b = EGL_MAX_SWAP_INTERVAL;

	if (!eglGetConfigAttrib(egl->dpy, egl->conf, a, &a) ||
	    !eglGetConfigAttrib(egl->dpy, egl->conf, b, &b)) {
		fprintf(stderr, "warning: swap interval range unknown\n");
	} else if (a > 0) {
		fprintf(stderr, "warning: minimum swap interval is %d, "
			"while 0 is required to not deadlock on resize.\n", a);
	}

	/*
	 * We rely on the Wayland compositor to sync to vblank anyway.
	 * We just need to be able to call eglSwapBuffers() without the
	 * risk of waiting for a frame callback in it.
	 */
	if (!eglSwapInterval(egl->dpy, 0)) {
		fprintf(stderr, "error: eglSwapInterval() failed.\n");
	}
}
Ejemplo n.º 14
0
int
PND_gl_setswapinterval(_THIS, int interval)
{
    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
    EGLBoolean status;

    if (phdata->egl_initialized != SDL_TRUE) {
        return SDL_SetError("PND: EGL initialization failed, no OpenGL ES support");
    }

    /* Check if OpenGL ES connection has been initialized */
    if (phdata->egl_display != EGL_NO_DISPLAY) {
        /* Set swap OpenGL ES interval */
        status = eglSwapInterval(phdata->egl_display, interval);
        if (status == EGL_TRUE) {
            /* Return success to upper level */
            phdata->swapinterval = interval;
            return 0;
        }
    }

    /* Failed to set swap interval */
    return SDL_SetError("PND: Cannot set swap interval");
}
Ejemplo n.º 15
0
void GlContext::create(uint32_t _width, uint32_t _height)
{
    m_eglLibrary = eglOpen();

    BX_UNUSED(_width, _height);
    EGLNativeDisplayType ndt = EGL_DEFAULT_DISPLAY;
    EGLNativeWindowType nwt = (EGLNativeWindowType)NULL;
#	if BX_PLATFORM_WINDOWS
    ndt = GetDC(g_bgfxHwnd);
    nwt = g_bgfxHwnd;
#	endif // BX_PLATFORM_
    m_display = eglGetDisplay(ndt);
    BGFX_FATAL(m_display != EGL_NO_DISPLAY, Fatal::UnableToInitialize, "Failed to create display %p", m_display);

    EGLint major = 0;
    EGLint minor = 0;
    EGLBoolean success = eglInitialize(m_display, &major, &minor);
    BGFX_FATAL(success && major >= 1 && minor >= 3, Fatal::UnableToInitialize, "Failed to initialize %d.%d", major, minor);

    EGLint attrs[] =
    {
        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,

#	if BX_PLATFORM_ANDROID
        EGL_DEPTH_SIZE, 16,
#	else
        EGL_DEPTH_SIZE, 24,
#	endif // BX_PLATFORM_
        EGL_STENCIL_SIZE, 8,

        EGL_NONE
    };

    EGLint numConfig = 0;
    EGLConfig config;
    success = eglChooseConfig(m_display, attrs, &config, 1, &numConfig);
    BGFX_FATAL(success, Fatal::UnableToInitialize, "eglChooseConfig");

#	if BX_PLATFORM_ANDROID
    EGLint format;
    eglGetConfigAttrib(m_display, config, EGL_NATIVE_VISUAL_ID, &format);
    ANativeWindow_setBuffersGeometry(g_bgfxAndroidWindow, _width, _height, format);
    nwt = g_bgfxAndroidWindow;
#	endif // BX_PLATFORM_ANDROID

    m_surface = eglCreateWindowSurface(m_display, config, nwt, NULL);
    BGFX_FATAL(m_surface != EGL_NO_SURFACE, Fatal::UnableToInitialize, "Failed to create surface.");

    EGLint contextAttrs[] =
    {
#	if BGFX_CONFIG_RENDERER_OPENGLES >= 30
        EGL_CONTEXT_CLIENT_VERSION, 3,
#	elif BGFX_CONFIG_RENDERER_OPENGLES
        EGL_CONTEXT_CLIENT_VERSION, 2,
#	endif // BGFX_CONFIG_RENDERER_

        EGL_NONE
    };

    m_context = eglCreateContext(m_display, config, EGL_NO_CONTEXT, contextAttrs);
    BGFX_FATAL(m_context != EGL_NO_CONTEXT, Fatal::UnableToInitialize, "Failed to create context.");

    success = eglMakeCurrent(m_display, m_surface, m_surface, m_context);
    BGFX_FATAL(success, Fatal::UnableToInitialize, "Failed to set context.");

    eglSwapInterval(m_display, 0);

#	if BX_PLATFORM_EMSCRIPTEN
    emscripten_set_canvas_size(_width, _height);
#	endif // BX_PLATFORM_EMSCRIPTEN

    import();
}
Ejemplo n.º 16
0
void GlContext::resize(uint32_t /*_width*/, uint32_t /*_height*/, bool _vsync)
{
    eglSwapInterval(m_display, _vsync ? 1 : 0);
}
Ejemplo n.º 17
0
static void gfx_ctx_qnx_set_swap_interval(void *data, unsigned interval)
{
   (void)data;
   eglSwapInterval(g_egl_dpy, interval);
}
Ejemplo n.º 18
0
bool CEGLManager::generateSurface()
{
    if (EglDisplay == EGL_NO_DISPLAY)
        return false;

    if (EglSurface != EGL_NO_SURFACE)
        return true;

	// We should assign new WindowID on platforms, where WindowID may change at runtime,
	// at this time only Android support this feature.
	// this needs an update method instead!

#if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
	EglWindow = (ANativeWindow*)Data.OGLESAndroid.Window;
#endif

	EGLint EglOpenGLBIT = 0;

	// We need proper OpenGL BIT.
	switch (Params.DriverType)
	{
	case EDT_OGLES1:
		EglOpenGLBIT = EGL_OPENGL_ES_BIT;
		break;
	case EDT_OGLES2:
		EglOpenGLBIT = EGL_OPENGL_ES2_BIT;
		break;
	default:
		break;
	}

	EGLint Attribs[] =
	{
		EGL_RED_SIZE, 8,
		EGL_GREEN_SIZE, 8,
		EGL_BLUE_SIZE, 8,
		EGL_ALPHA_SIZE, Params.WithAlphaChannel ? 1:0,
		EGL_BUFFER_SIZE, Params.Bits,
		EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
		EGL_DEPTH_SIZE, Params.ZBufferBits,
		EGL_STENCIL_SIZE, Params.Stencilbuffer,
		EGL_SAMPLE_BUFFERS, Params.AntiAlias ? 1:0,
		EGL_SAMPLES, Params.AntiAlias,
#ifdef EGL_VERSION_1_3
		EGL_RENDERABLE_TYPE, EglOpenGLBIT,
#endif
		EGL_NONE, 0	
	};

	EglConfig = 0;
	EGLint NumConfigs = 0;
	u32 Steps = 5;

	// Choose the best EGL config.
	while (!eglChooseConfig(EglDisplay, Attribs, &EglConfig, 1, &NumConfigs) || !NumConfigs)
	{
		switch (Steps)
		{
		case 5: // samples
			if (Attribs[19] > 2)
				--Attribs[19];
			else
			{
				Attribs[17] = 0;
				Attribs[19] = 0;
				--Steps;
			}
			break;
		case 4: // alpha
			if (Attribs[7])
			{
				Attribs[7] = 0;

				if (Params.AntiAlias)
				{
					Attribs[17] = 1;
					Attribs[19] = Params.AntiAlias;
					Steps = 5;
				}
			}
			else
				--Steps;
			break;
		case 3: // stencil
			if (Attribs[15])
			{
				Attribs[15] = 0;

				if (Params.AntiAlias)
				{
					Attribs[17] = 1;
					Attribs[19] = Params.AntiAlias;
					Steps = 5;
				}
			}
			else
				--Steps;
			break;
		case 2: // depth size
			if (Attribs[13] > 16)
			{
				Attribs[13] -= 8;
			}
			else
				--Steps;
			break;
		case 1: // buffer size
			if (Attribs[9] > 16)
			{
				Attribs[9] -= 8;
			}
			else
				--Steps;
			break;
		default:
			os::Printer::log("Could not get config for EGL display.");
			return false;
		}
	}

	if (Params.AntiAlias && !Attribs[17])
		os::Printer::log("No multisampling.");

	if (Params.WithAlphaChannel && !Attribs[7])
		os::Printer::log("No alpha.");

	if (Params.Stencilbuffer && !Attribs[15])
		os::Printer::log("No stencil buffer.");

	if (Params.ZBufferBits > Attribs[13])
		os::Printer::log("No full depth buffer.");

	if (Params.Bits > Attribs[9])
		os::Printer::log("No full color buffer.");

#if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_)
    EGLint Format = 0;
    eglGetConfigAttrib(EglDisplay, EglConfig, EGL_NATIVE_VISUAL_ID, &Format);

    ANativeWindow_setBuffersGeometry(EglWindow, 0, 0, Format);
#endif
   
	// Now we are able to create EGL surface.
	EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, EglWindow, 0);
	
	if (EGL_NO_SURFACE == EglSurface)
		EglSurface = eglCreateWindowSurface(EglDisplay, EglConfig, 0, 0);

	if (EGL_NO_SURFACE == EglSurface)
		os::Printer::log("Could not create EGL surface.");

#ifdef EGL_VERSION_1_2
	if (MinorVersion > 1)
		eglBindAPI(EGL_OPENGL_ES_API);
#endif

    if (Params.Vsync)
		eglSwapInterval(EglDisplay, 1);

    return true;
}
int OpenGLView::regenerate() {
	int returnCode;
	EGLBoolean status;
	EGLint interval = 1;

	OpenGLView::m_renderMutex.lock();

    status = eglQuerySurface(m_egl_disp, m_egl_surf, EGL_WIDTH, &m_surface_width);
	if (status != EGL_TRUE) {
		perror("query surface width");
		return EXIT_FAILURE;
	}

    status = eglQuerySurface(m_egl_disp, m_egl_surf, EGL_HEIGHT, &m_surface_height);
	if (status != EGL_TRUE) {
		perror("query surface height");
		return EXIT_FAILURE;
	}

/*
	rc = screen_get_window_property_iv(m_screen_win, SCREEN_PROPERTY_ROTATION, &rotation);
	if (rc) {
		perror("screen_set_window_property_iv");
		return EXIT_FAILURE;
	}

	rc = screen_get_window_property_iv(m_screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);
	if (rc) {
		perror("screen_set_window_property_iv");
		return EXIT_FAILURE;
	}

	switch (angle - rotation) {
		case -270:
		case -90:
		case 90:
		case 270:
			temp = size[0];
			size[0] = size[1];
			size[1] = temp;
			skip = 0;
			break;
	}
*/

	status = eglMakeCurrent(m_egl_disp, NULL, NULL, NULL);
	if (status != EGL_TRUE) {
		OpenGLThread::eglPrintError("eglMakeCurrent");
		return EXIT_FAILURE;
	}

	status = eglDestroySurface(m_egl_disp, m_egl_surf);
	if (status != EGL_TRUE) {
		OpenGLThread::eglPrintError("eglMakeCurrent");
		return EXIT_FAILURE;
	}

	returnCode = setWindowPosition(m_x, m_y);
	if (returnCode) {
		perror("window position");
		return EXIT_FAILURE;
	}

	returnCode = setWindowSize(m_width, m_height);
	if (returnCode) {
		perror("window size");
		return EXIT_FAILURE;
	}
/*
	setWindowAngle(m_angle);
	if (returnCode) {
		perror("window angle");
		return EXIT_FAILURE;
	}
*/
	returnCode = setWindowSourceSize(m_width, m_height);
	if (returnCode) {
		perror("unable to set window source size");
		return EXIT_FAILURE;
	}

	returnCode = setWindowBufferSize(m_width, m_height);
	if (returnCode) {
		perror("buffer size");
		return EXIT_FAILURE;
	}

	m_egl_surf = eglCreateWindowSurface(m_egl_disp, m_egl_conf, m_screen_win, NULL);
	if (m_egl_surf == EGL_NO_SURFACE) {
		OpenGLThread::eglPrintError("eglCreateWindowSurface");
		return EXIT_FAILURE;
	}

	getGLContext();

    status = eglSwapInterval(m_egl_disp, interval);
	if (status != EGL_TRUE) {
		OpenGLThread::eglPrintError("eglSwapInterval");
		return EXIT_FAILURE;
	}

	OpenGLView::m_renderMutex.unlock();

	setAltered(false);

	setStale(true);

	return EXIT_SUCCESS;
}
int OpenGLView::initGL()
{
    int numberDisplays;
    int numberModes;
    int returnCode;
    EGLBoolean status;
    int type;
    EGLint attributes[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
    EGLint attrib_list[]= { EGL_RED_SIZE,        8,
                            EGL_GREEN_SIZE,      8,
                            EGL_BLUE_SIZE,       8,
                            EGL_SURFACE_TYPE,    EGL_WINDOW_BIT,
                            EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
                            EGL_NONE};

    // try this first as it will fail if an HDMI display is not attached
    if (m_api == GL_ES_2) {
        m_egl_ctx = eglCreateContext(m_egl_disp, m_egl_conf, EGL_NO_CONTEXT, attributes);
    } else {
        m_egl_ctx = eglCreateContext(m_egl_disp, m_egl_conf, EGL_NO_CONTEXT, NULL);
    }
    if (m_egl_ctx == EGL_NO_CONTEXT) {
        perror("eglCreateContext");
        return EXIT_FAILURE;
    }

	screen_get_context_property_iv(m_screen_ctx, SCREEN_PROPERTY_DISPLAY_COUNT, &numberDisplays);

	m_screen_dpy = (screen_display_t *)calloc(numberDisplays, sizeof(screen_display_t));
	screen_get_context_property_pv(m_screen_ctx, SCREEN_PROPERTY_DISPLAYS, (void **)m_screen_dpy);


	for (int index = 0; index < numberDisplays; index++) {
		int displayID;

        returnCode = screen_get_display_property_iv(m_screen_dpy[index], SCREEN_PROPERTY_ID,  (int *)&displayID);
    	if (returnCode) {
    		perror("display ID");
    		return EXIT_FAILURE;
    	} else {
			if (displayID == m_display) {
			    screen_get_display_property_iv(m_screen_dpy[index], SCREEN_PROPERTY_TYPE,  &type);
			    if (type == SCREEN_DISPLAY_TYPE_HDMI) {
			    	returnCode = screen_create_window(&m_screen_win, m_screen_ctx);
			    	if (returnCode) {
			            perror("screen_create_window");
			            return EXIT_FAILURE;
			        }
			    } else {
			    	returnCode = screen_create_window_type(&m_screen_win, m_screen_ctx, SCREEN_CHILD_WINDOW);
			    	if (returnCode) {
			            perror("screen_create_window (child window)");
			            return EXIT_FAILURE;
			        }
			    }
			    if (type == SCREEN_DISPLAY_TYPE_HDMI) {
					returnCode = screen_set_window_property_pv(m_screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&(m_screen_dpy[index]));
					if (returnCode) {
						perror("window display");
						return EXIT_FAILURE;
					}
		        }
			}
        }
	}

	qDebug()  << "OpenGLView::initialize: "<< m_screen_ctx << ":" << m_egl_disp << ":" << m_egl_conf << ":" << m_egl_ctx << ":" << m_screen_win;


	int format = SCREEN_FORMAT_RGBA8888;
	returnCode = screen_set_window_property_iv(m_screen_win, SCREEN_PROPERTY_FORMAT, &format);
	if (returnCode) {
		perror("screen_set_window_property_iv(SCREEN_PROPERTY_FORMAT)");
		return EXIT_FAILURE;
	}

	if (m_transparency > 0) {
		returnCode = setWindowTransparency(m_transparency);
		if (returnCode) {
			perror("transparency");
			return EXIT_FAILURE;
		}
	}

	returnCode = screen_get_window_property_pv(m_screen_win, SCREEN_PROPERTY_DISPLAY, (void **)&m_screen_disp);
	if (returnCode) {
		perror("screen_get_window_property_pv");
		return EXIT_FAILURE;
	}

	int angle = atoi(getenv("ORIENTATION"));

	screen_get_display_property_iv(m_screen_disp, SCREEN_PROPERTY_MODE_COUNT, &numberModes);

	m_screen_modes = (screen_display_mode_t *)calloc(numberModes, sizeof(screen_display_mode_t));
	returnCode = screen_get_display_property_pv(m_screen_disp, SCREEN_PROPERTY_MODE, (void**)m_screen_modes);
	if (returnCode) {
		perror("screen modes");
		return EXIT_FAILURE;
	}

    int dpi = calculateDPI();
    if (dpi == EXIT_FAILURE) {
        fprintf(stderr, "Unable to calculate dpi\n");
        return EXIT_FAILURE;
    }

	returnCode = setWindowPosition(m_x, m_y);
	if (returnCode) {
		perror("window position");
		return EXIT_FAILURE;
	}

	returnCode = setWindowSize(m_width, m_height);
	if (returnCode) {
		perror("window size");
		return EXIT_FAILURE;
	}

	returnCode = setWindowZ(m_z);
	if (returnCode) {
		perror("z order");
		return EXIT_FAILURE;
	}

	returnCode = setWindowBufferSize(m_width, m_height);
	if (returnCode) {
		perror("buffer size");
		return EXIT_FAILURE;
	}

	returnCode = setWindowAngle(m_angle);
	if (returnCode) {
		perror("angle");
		return EXIT_FAILURE;
	}

	returnCode = screen_create_window_buffers(m_screen_win, m_nbuffers);
	if (returnCode) {
		perror("screen_create_window_buffers");
		return EXIT_FAILURE;
	}


    if (m_api == GL_ES_1) {
        m_usage = SCREEN_USAGE_OPENGL_ES1 | SCREEN_USAGE_ROTATION;
    } else if (m_api == GL_ES_2) {
    	attrib_list[9] = EGL_OPENGL_ES2_BIT;
    	m_usage = SCREEN_USAGE_OPENGL_ES2 | SCREEN_USAGE_ROTATION;
    } else if (m_api == VG) {
    	attrib_list[9] = EGL_OPENVG_BIT;
    	m_usage = SCREEN_USAGE_OPENVG | SCREEN_USAGE_ROTATION;
    } else {
        fprintf(stderr, "invalid api setting\n");
        return EXIT_FAILURE;
    }

	returnCode = setWindowUsage(m_usage);
	if (returnCode) {
		perror("screen_set_window_property_iv(window usage)");
		return EXIT_FAILURE;
	}

	qDebug()  << "OpenGLView::initGL:eglCreateContext "<< m_egl_ctx;
	m_egl_surf = eglCreateWindowSurface(m_egl_disp, m_egl_conf, m_screen_win, NULL);
	if (m_egl_surf == EGL_NO_SURFACE) {
		OpenGLThread::eglPrintError("eglCreateWindowSurface");
		return EXIT_FAILURE;
	}

	getGLContext();

    EGLint interval = 1;
    status = eglSwapInterval(m_egl_disp, interval);
	if (status != EGL_TRUE) {
		OpenGLThread::eglPrintError("eglSwapInterval");
		return EXIT_FAILURE;
	}

    status = eglQuerySurface(m_egl_disp, m_egl_surf, EGL_WIDTH, &m_surface_width);
	if (status != EGL_TRUE) {
		perror("query surface width");
		return EXIT_FAILURE;
	}

    status = eglQuerySurface(m_egl_disp, m_egl_surf, EGL_HEIGHT, &m_surface_height);
	if (status != EGL_TRUE) {
		perror("query surface height");
		return EXIT_FAILURE;
	}

	returnCode = joinWindowGroup(m_group);
	if (returnCode) {
		perror("window group");
		return EXIT_FAILURE;
	}

	returnCode = setScreenWindowID(m_id);
	if (returnCode) {
		perror("window ID");
		return EXIT_FAILURE;
	}

	qDebug()  << "OpenGLView::initGL: "<< angle << ":" << numberModes << ":" << m_screen_modes[0].width << ":" << m_screen_modes[0].height << ":" << m_egl_disp << ":" << dpi;

	setInitialized(true);

	return EXIT_SUCCESS;
}
Ejemplo n.º 21
0
// Initialized EGL resources.
static bool initEGL()
{
    // Hard-coded to 32-bit/OpenGL ES 2.0.
    const EGLint eglConfigAttrs[] =
    {
        EGL_RED_SIZE,           8,
        EGL_GREEN_SIZE,         8,
        EGL_BLUE_SIZE,          8,
        EGL_ALPHA_SIZE,         8,
        EGL_DEPTH_SIZE,         24,
        EGL_STENCIL_SIZE,       8,
        EGL_SURFACE_TYPE,       EGL_WINDOW_BIT,
        EGL_RENDERABLE_TYPE,    EGL_OPENGL_ES2_BIT,
        EGL_NONE
    };
    
    EGLint eglConfigCount;
    const EGLint eglContextAttrs[] =
    {
        EGL_CONTEXT_CLIENT_VERSION,    2,
        EGL_NONE
    };

    const EGLint eglSurfaceAttrs[] =
    {
        EGL_RENDER_BUFFER,    EGL_BACK_BUFFER,
        EGL_NONE
    };

    if (__eglDisplay == EGL_NO_DISPLAY && __eglContext == EGL_NO_CONTEXT)
    {
        // Get the EGL display and initialize.
        __eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
        if (__eglDisplay == EGL_NO_DISPLAY)
        {
            checkErrorEGL("eglGetDisplay");
            goto error;
        }
    
        if (eglInitialize(__eglDisplay, NULL, NULL) != EGL_TRUE)
        {
            checkErrorEGL("eglInitialize");
            goto error;
        }
    
        if (eglChooseConfig(__eglDisplay, eglConfigAttrs, &__eglConfig, 1, &eglConfigCount) != EGL_TRUE || eglConfigCount == 0)
        {
            checkErrorEGL("eglChooseConfig");
            goto error;
        }
    
        __eglContext = eglCreateContext(__eglDisplay, __eglConfig, EGL_NO_CONTEXT, eglContextAttrs);
        if (__eglContext == EGL_NO_CONTEXT)
        {
            checkErrorEGL("eglCreateContext");
            goto error;
        }
    }
    
    // EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
    // guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
    // As soon as we picked a EGLConfig, we can safely reconfigure the
    // ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID.
    EGLint format;
    eglGetConfigAttrib(__eglDisplay, __eglConfig, EGL_NATIVE_VISUAL_ID, &format);
    ANativeWindow_setBuffersGeometry(__state->window, 0, 0, format);
    
    __eglSurface = eglCreateWindowSurface(__eglDisplay, __eglConfig, __state->window, eglSurfaceAttrs);
    if (__eglSurface == EGL_NO_SURFACE)
    {
        checkErrorEGL("eglCreateWindowSurface");
        goto error;
    }
    
    if (eglMakeCurrent(__eglDisplay, __eglSurface, __eglSurface, __eglContext) != EGL_TRUE)
    {
        checkErrorEGL("eglMakeCurrent");
        goto error;
    }
    
    eglQuerySurface(__eglDisplay, __eglSurface, EGL_WIDTH, &__width);
    eglQuerySurface(__eglDisplay, __eglSurface, EGL_HEIGHT, &__height);
    
    // Set vsync.
    eglSwapInterval(__eglDisplay, WINDOW_VSYNC ? 1 : 0);
    
    // Initialize OpenGL ES extensions.
    __glExtensions = (const char*)glGetString(GL_EXTENSIONS);
    
    if (strstr(__glExtensions, "GL_OES_vertex_array_object") || strstr(__glExtensions, "GL_ARB_vertex_array_object"))
    {
        // Disable VAO extension for now.
        glBindVertexArray = (PFNGLBINDVERTEXARRAYOESPROC)eglGetProcAddress("glBindVertexArrayOES");
        glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSOESPROC)eglGetProcAddress("glDeleteVertexArrays");
        glGenVertexArrays = (PFNGLGENVERTEXARRAYSOESPROC)eglGetProcAddress("glGenVertexArraysOES");
        glIsVertexArray = (PFNGLISVERTEXARRAYOESPROC)eglGetProcAddress("glIsVertexArrayOES");
    }
    
    return true;
    
error:
    return false;
}
Ejemplo n.º 22
0
//egl init
int common_eglinit(struct globalStruct* globals, int testID, int surfaceType, NATIVE_PIXMAP_STRUCT** pNativePixmapPtr)
{
	EGLint iMajorVersion, iMinorVersion;
	EGLint ai32ContextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
	globals->eglDisplay = eglGetDisplay((int)0);

	if (!eglInitialize(globals->eglDisplay, &iMajorVersion, &iMinorVersion))
		return 1;

	eglBindAPI(EGL_OPENGL_ES_API);
	if (!TestEGLError("eglBindAPI"))
		return 1;

	EGLint pi32ConfigAttribs[5];
	pi32ConfigAttribs[0] = EGL_SURFACE_TYPE;
	pi32ConfigAttribs[1] = EGL_WINDOW_BIT | EGL_PIXMAP_BIT;
	pi32ConfigAttribs[2] = EGL_RENDERABLE_TYPE;
	pi32ConfigAttribs[3] = EGL_OPENGL_ES2_BIT;
	pi32ConfigAttribs[4] = EGL_NONE;

	int iConfigs;
	if (!eglChooseConfig(globals->eglDisplay, pi32ConfigAttribs, &globals->eglConfig, 1, &iConfigs) || (iConfigs != 1))
	{
		SGXPERF_ERR_printf("Error: eglChooseConfig() failed.\n");
		return 1;
	}
	if(surfaceType == SGXPERF_SURFACE_TYPE_WINDOW)
		globals->eglSurface = eglCreateWindowSurface(globals->eglDisplay, globals->eglConfig, (EGLNativeWindowType) NULL, NULL);
	else if(surfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_16)
	{
		common_create_native_pixmap(SGXPERF_RGB565, 
						globals->inTextureWidth, globals->inTextureHeight, pNativePixmapPtr);
		globals->eglSurface = eglCreatePixmapSurface(globals->eglDisplay, globals->eglConfig, (EGLNativePixmapType)*pNativePixmapPtr, NULL);
	}
	else if(surfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_32)
	{
		common_create_native_pixmap(SGXPERF_ARGB8888, 
						globals->inTextureWidth, globals->inTextureHeight, pNativePixmapPtr);
		globals->eglSurface = eglCreatePixmapSurface(globals->eglDisplay, globals->eglConfig, (EGLNativePixmapType)*pNativePixmapPtr, NULL);
	}
  	else  
	    return 999;

	if (!TestEGLError("eglCreateSurface"))
		return 1;
		
	if(testID == 14) //Create one pixmap surface for context switch latency check
	{
		common_create_native_pixmap(SGXPERF_RGB565, 
						globals->inTextureWidth, globals->inTextureHeight, pNativePixmapPtr);
		globals->eglSurface2 = eglCreatePixmapSurface(globals->eglDisplay, globals->eglConfig, (EGLNativePixmapType)*pNativePixmapPtr, NULL);
	}  	
	if (!TestEGLError("eglCreateSurface"))
		return 1;		

	globals->eglContext = eglCreateContext(globals->eglDisplay, globals->eglConfig, NULL, ai32ContextAttribs);
	if (!TestEGLError("eglCreateContext"))
		return 1;

	eglMakeCurrent(globals->eglDisplay, globals->eglSurface, globals->eglSurface, globals->eglContext);
	if (!TestEGLError("eglMakeCurrent"))
		return 1;

	eglSwapInterval(globals->eglDisplay, 1);
	if (!TestEGLError("eglSwapInterval"))
		return 1;

	eglQuerySurface(globals->eglDisplay, globals->eglSurface, EGL_WIDTH, &globals->windowWidth);
	eglQuerySurface(globals->eglDisplay, globals->eglSurface, EGL_HEIGHT, &globals->windowHeight);
	
	SGXPERF_printf("Window width=%d, Height=%d\n", globals->windowWidth, globals->windowHeight);

	return 0;
}
bool QGLContext::chooseContext(const QGLContext* shareContext)
{
    Q_D(QGLContext);

    // Validate the device.
    if (!device())
        return false;
    int devType = device()->devType();
    if (devType != QInternal::Pixmap && devType != QInternal::Image && devType != QInternal::Widget) {
        qWarning("QGLContext::chooseContext(): Cannot create QGLContext's for paint device type %d", devType);
        return false;
    }

    // Get the display and initialize it.
    d->eglContext = new QEglContext();
    d->eglContext->setApi(QEgl::OpenGL);
    if (!d->eglContext->openDisplay(device())) {
        delete d->eglContext;
        d->eglContext = 0;
        return false;
    }

    // Construct the configuration we need for this surface.
    QEglProperties configProps;
    qt_egl_add_platform_config(configProps, device());
    qt_egl_set_format(configProps, devType, d->glFormat);
    configProps.setRenderableType(QEgl::OpenGL);

    // Search for a matching configuration, reducing the complexity
    // each time until we get something that matches.
    if (!d->eglContext->chooseConfig(configProps)) {
        delete d->eglContext;
        d->eglContext = 0;
        return false;
    }

    // Inform the higher layers about the actual format properties.
    qt_egl_update_format(*(d->eglContext), d->glFormat);

    // Create a new context for the configuration.
    if (!d->eglContext->createContext
            (shareContext ? shareContext->d_func()->eglContext : 0)) {
        delete d->eglContext;
        d->eglContext = 0;
        return false;
    }
    d->sharing = d->eglContext->isSharing();
    if (d->sharing && shareContext)
        const_cast<QGLContext *>(shareContext)->d_func()->sharing = true;

#if defined(EGL_VERSION_1_1)
    if (d->glFormat.swapInterval() != -1 && devType == QInternal::Widget)
        eglSwapInterval(d->eglContext->display(), d->glFormat.swapInterval());
#endif

    // Create the EGL surface to draw into.  We cannot use
    // QEglContext::createSurface() because it does not have
    // access to the QGLScreen.
    d->eglSurface = qt_egl_create_surface(d->eglContext, device());
    if (d->eglSurface == EGL_NO_SURFACE) {
        delete d->eglContext;
        d->eglContext = 0;
        return false;
    }

    return true;
}
Ejemplo n.º 24
0
void CGLContextEGL::SetVSync(bool enable, int &mode)
{
  eglSwapInterval(m_eglDisplay, enable ? 1 : 0);
}
Ejemplo n.º 25
0
void _glfwPlatformSwapInterval( int interval )
{
    if( _glfwWin.display != EGL_NO_DISPLAY )
        eglSwapInterval( _glfwWin.display, interval );
}
Ejemplo n.º 26
0
bool RendererGLES2::initContext(){
    
	// code followed is from ImgSdk and minimized.
	EGLint	majorVersion, minorVersion;
    
	m_eglContext = 0;
    
	m_hDC = GetDC(m_hWnd);
	m_eglDisplay = eglGetDisplay( m_hDC );
    
	if( m_eglDisplay == EGL_NO_DISPLAY )
		m_eglDisplay = eglGetDisplay((EGLNativeDisplayType)EGL_DEFAULT_DISPLAY);
    
	if(!eglInitialize(m_eglDisplay, &majorVersion, &minorVersion)){
		lge_debug_log("Unable to initialize EGL.");
		return false;
	}
    
	lge_debug_log("EGL %d.%d initialized.", majorVersion, minorVersion);
    
	if(!eglBindAPI(EGL_OPENGL_ES_API)){
		lge_debug_log( "Failed to bind OpenGL ES API." );
		return false;
	}
    
	m_eglConfig = setEGLConfiguration();
    
    
	EGLint ai32ContextAttribs[32];
	int	i = 0;
    
	//ai32ContextAttribs[i++] = EGL_CONTEXT_CLIENT_VERSION;
	//ai32ContextAttribs[i++] = 2;
    
	ai32ContextAttribs[i] = EGL_NONE;
    
	m_eglContext = eglCreateContext(m_eglDisplay, m_eglConfig, NULL, NULL);
    
	if( m_eglContext == EGL_NO_CONTEXT ){
		lge_debug_log( "Failed to create EGL Context." );
		return false;
	}
    
	EGLint		attrib_list[16];
	i = 0;
	attrib_list[i] = EGL_NONE;
    
	m_eglWindow = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_hWnd, NULL);
	
	if( m_eglWindow == EGL_NO_SURFACE){
		lge_debug_log( "Failed to create window surface." );
		return false;
	}
    
	if ( eglMakeCurrent(m_eglDisplay, m_eglWindow, m_eglWindow, m_eglContext) == EGL_TRUE )
		return eglSwapInterval(m_eglDisplay, 1) == EGL_TRUE;
	else{
		lge_debug_log("Failed to make current context." );
		return false;
	}
}
Ejemplo n.º 27
0
void GLContextEGL::swapInterval(int interval)
{
    ASSERT(m_surface);
    eglSwapInterval(m_display.eglDisplay(), interval);
}
Ejemplo n.º 28
0
void SkOSWindow::setVsync(bool vsync) {
    if (fWindow.fDisplay != EGL_NO_DISPLAY) {
        int swapInterval = vsync ? 1 : 0;
        eglSwapInterval(fWindow.fDisplay, swapInterval);
    }
}
Ejemplo n.º 29
0
void _glfwPlatformSwapInterval(int interval)
{
    eglSwapInterval(_glfw.egl.display, interval);
}
Ejemplo n.º 30
0
bool RendererGlLinux::initialize( void *window, RendererRef sharedRenderer )
{
	std::vector<EGLint> configAttribs;

	// OpenGL ES 3 also uses EGL_OPENGL_ES2_BIT
	configAttribs.push_back( EGL_RENDERABLE_TYPE ); configAttribs.push_back( EGL_OPENGL_ES2_BIT );
	configAttribs.push_back( EGL_SURFACE_TYPE    ); configAttribs.push_back( EGL_WINDOW_BIT );
	configAttribs.push_back( EGL_RED_SIZE        ); configAttribs.push_back( 8 );
	configAttribs.push_back( EGL_GREEN_SIZE      ); configAttribs.push_back( 8 );
	configAttribs.push_back( EGL_BLUE_SIZE       ); configAttribs.push_back( 8 );
	configAttribs.push_back( EGL_ALPHA_SIZE      ); configAttribs.push_back( 8 );
	configAttribs.push_back( EGL_DEPTH_SIZE      ); configAttribs.push_back( mRenderer->getOptions().getDepthBufferDepth() );
	configAttribs.push_back( EGL_STENCIL_SIZE    ); configAttribs.push_back( mRenderer->getOptions().getStencil() ? 8 : EGL_DONT_CARE );
	configAttribs.push_back( EGL_SAMPLE_BUFFERS  ); configAttribs.push_back( 1 );
	configAttribs.push_back( EGL_NONE            );

	mDisplay = eglGetDisplay( EGL_DEFAULT_DISPLAY );
	if( mDisplay == EGL_NO_DISPLAY) {
		return false;
	}

	EGLint majorVersion, minorVersion;
	if( ! eglInitialize( mDisplay, &majorVersion, &minorVersion ) ) {
		return false;
	}

	eglBindAPI( EGL_OPENGL_ES_API );
	if( eglGetError() != EGL_SUCCESS ) {
		return false;
	}

	EGLint configCount;
	if( ! eglChooseConfig( mDisplay, configAttribs.data(), &mConfig, 1, &configCount ) || (configCount != 1) ) {
		return false;
	}

	EGLint contextAttibutes[] = {
#if defined( CINDER_GL_ES_3 )
		EGL_CONTEXT_CLIENT_VERSION, 3,
#else
		EGL_CONTEXT_CLIENT_VERSION, 2,
#endif
		EGL_NONE
	};

	// Create context
	mContext = eglCreateContext( mDisplay, mConfig, EGL_NO_CONTEXT, contextAttibutes );
	if( eglGetError() != EGL_SUCCESS ) {
		return false;
	}
	checkGlStatus();

	// Create window surface
	EGL_DISPMANX_WINDOW_T* nativeWindow = reinterpret_cast<EGL_DISPMANX_WINDOW_T*>( window );

	DISPMANX_UPDATE_HANDLE_T  	update  = vc_dispmanx_update_start( 0 );
	DISPMANX_DISPLAY_HANDLE_T 	display = vc_dispmanx_display_open( 0 );
	int32_t 					layer = 0;
	VC_RECT_T					dst_rect = { 0, 0, nativeWindow->width, nativeWindow->height };
	DISPMANX_RESOURCE_HANDLE_T	src = 0;
	VC_RECT_T					src_rect = { 0, 0, nativeWindow->width << 16, nativeWindow->height << 16 };
	DISPMANX_PROTECTION_T 		protection = DISPMANX_PROTECTION_NONE;
	VC_DISPMANX_ALPHA_T			alpha = { DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS, 255, 0 };
	DISPMANX_CLAMP_T*			clamp = 0;
	DISPMANX_TRANSFORM_T 		transform = (DISPMANX_TRANSFORM_T)0;
	
	nativeWindow->element = vc_dispmanx_element_add( 
		update,
		display, 
		layer,
		&dst_rect, 
		src,
		&src_rect, 
		protection, 
		&alpha, 
		clamp, 
		transform 
	);	

	vc_dispmanx_update_submit_sync( update );

	mSurface = eglCreateWindowSurface( mDisplay, mConfig, nativeWindow, NULL );
	auto err = eglGetError();
	if( err != EGL_SUCCESS ) {
		return false;
	}

	eglMakeCurrent( mDisplay, mSurface, mSurface, mContext );
	if( eglGetError() != EGL_SUCCESS ) {
		return false;
	}
	checkGlStatus();

	gl::Environment::setEs();
	gl::env()->initializeFunctionPointers();
	checkGlStatus();

	std::shared_ptr<gl::PlatformDataLinux> platformData( new gl::PlatformDataLinux( mContext, mDisplay, mSurface, mConfig ) );
	platformData->mObjectTracking = mRenderer->getOptions().getObjectTracking();

	mCinderContext = gl::Context::createFromExisting( platformData );
	checkGlStatus();

	mCinderContext->makeCurrent();
	checkGlStatus();

	eglSwapInterval( mDisplay, 1 );
	checkGlStatus();

	return true;
}