From 8ede118779b0b4cde591f3bf5ec94f7a6f25e2a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lind?= Date: Wed, 7 Jul 2010 15:11:01 +0200 Subject: Make openkode work with new interfaces and moved egl stuff into plugin --- .../platforms/openkode/qopenkodeglintegration.cpp | 189 ++++----------------- .../platforms/openkode/qopenkodeglintegration.h | 14 +- .../platforms/openkode/qopenkodeintegration.cpp | 41 ++++- .../platforms/openkode/qopenkodeintegration.h | 9 +- src/plugins/platforms/openkode/qopenkodewindow.cpp | 160 ++++++++++++++--- src/plugins/platforms/openkode/qopenkodewindow.h | 14 +- .../platforms/openkode/qopenkodewindowsurface.cpp | 39 ++--- .../platforms/openkode/qopenkodewindowsurface.h | 8 +- 8 files changed, 239 insertions(+), 235 deletions(-) diff --git a/src/plugins/platforms/openkode/qopenkodeglintegration.cpp b/src/plugins/platforms/openkode/qopenkodeglintegration.cpp index 7223538..4296876 100644 --- a/src/plugins/platforms/openkode/qopenkodeglintegration.cpp +++ b/src/plugins/platforms/openkode/qopenkodeglintegration.cpp @@ -40,198 +40,69 @@ ****************************************************************************/ #include "qopenkodeglintegration.h" + +#include + #include #include #include #include -#include -void qt_eglproperties_set_glformat(QEglProperties& eglProperties, const QGLFormat& glFormat) +QEGLPlatformContext::QEGLPlatformContext(EGLDisplay display, EGLConfig config, EGLint contextAttrs[], EGLSurface surface, EGLenum eglApi) + : m_eglDisplay(display) + , m_eglSurface(surface) + , m_eglApi(eglApi) { - int redSize = glFormat.redBufferSize(); - int greenSize = glFormat.greenBufferSize(); - int blueSize = glFormat.blueBufferSize(); - int alphaSize = glFormat.alphaBufferSize(); - int depthSize = glFormat.depthBufferSize(); - int stencilSize = glFormat.stencilBufferSize(); - int sampleCount = glFormat.samples(); - - // QGLFormat uses a magic value of -1 to indicate "don't care", even when a buffer of that - // type has been requested. So we must check QGLFormat's booleans too if size is -1: - if (glFormat.alpha() && alphaSize <= 0) - alphaSize = 1; - if (glFormat.depth() && depthSize <= 0) - depthSize = 1; - if (glFormat.stencil() && stencilSize <= 0) - stencilSize = 1; - if (glFormat.sampleBuffers() && sampleCount <= 0) - sampleCount = 1; - - // We want to make sure 16-bit configs are chosen over 32-bit configs as they will provide - // the best performance. The EGL config selection algorithm is a bit stange in this regard: - // The selection criteria for EGL_BUFFER_SIZE is "AtLeast", so we can't use it to discard - // 32-bit configs completely from the selection. So it then comes to the sorting algorithm. - // The red/green/blue sizes have a sort priority of 3, so they are sorted by first. The sort - // order is special and described as "by larger _total_ number of color bits.". So EGL will - // put 32-bit configs in the list before the 16-bit configs. However, the spec also goes on - // to say "If the requested number of bits in attrib_list for a particular component is 0, - // then the number of bits for that component is not considered". This part of the spec also - // seems to imply that setting the red/green/blue bits to zero means none of the components - // are considered and EGL disregards the entire sorting rule. It then looks to the next - // highest priority rule, which is EGL_BUFFER_SIZE. Despite the selection criteria being - // "AtLeast" for EGL_BUFFER_SIZE, it's sort order is "smaller" meaning 16-bit configs are - // put in the list before 32-bit configs. So, to make sure 16-bit is preffered over 32-bit, - // we must set the red/green/blue sizes to zero. This has an unfortunate consequence that - // if the application sets the red/green/blue size to 5/6/5 on the QGLFormat, they will - // probably get a 32-bit config, even when there's an RGB565 config avaliable. Oh well. - - // Now normalize the values so -1 becomes 0 - redSize = redSize > 0 ? redSize : 0; - greenSize = greenSize > 0 ? greenSize : 0; - blueSize = blueSize > 0 ? blueSize : 0; - alphaSize = alphaSize > 0 ? alphaSize : 0; - depthSize = depthSize > 0 ? depthSize : 0; - stencilSize = stencilSize > 0 ? stencilSize : 0; - sampleCount = sampleCount > 0 ? sampleCount : 0; - - eglProperties.setValue(EGL_RED_SIZE, redSize); - eglProperties.setValue(EGL_GREEN_SIZE, greenSize); - eglProperties.setValue(EGL_BLUE_SIZE, blueSize); - eglProperties.setValue(EGL_ALPHA_SIZE, alphaSize); - eglProperties.setValue(EGL_DEPTH_SIZE, depthSize); - eglProperties.setValue(EGL_STENCIL_SIZE, stencilSize); - eglProperties.setValue(EGL_SAMPLES, sampleCount); - eglProperties.setValue(EGL_SAMPLE_BUFFERS, sampleCount ? 1 : 0); -} - -// Updates "format" with the parameters of the selected configuration. -void qt_glformat_from_eglconfig(QGLFormat& format, const EGLConfig config) -{ - EGLint redSize = 0; - EGLint greenSize = 0; - EGLint blueSize = 0; - EGLint alphaSize = 0; - EGLint depthSize = 0; - EGLint stencilSize = 0; - EGLint sampleCount = 0; - EGLint level = 0; - - EGLDisplay display = QEgl::display(); - eglGetConfigAttrib(display, config, EGL_RED_SIZE, &redSize); - eglGetConfigAttrib(display, config, EGL_GREEN_SIZE, &greenSize); - eglGetConfigAttrib(display, config, EGL_BLUE_SIZE, &blueSize); - eglGetConfigAttrib(display, config, EGL_ALPHA_SIZE, &alphaSize); - eglGetConfigAttrib(display, config, EGL_DEPTH_SIZE, &depthSize); - eglGetConfigAttrib(display, config, EGL_STENCIL_SIZE, &stencilSize); - eglGetConfigAttrib(display, config, EGL_SAMPLES, &sampleCount); - eglGetConfigAttrib(display, config, EGL_LEVEL, &level); - - format.setRedBufferSize(redSize); - format.setGreenBufferSize(greenSize); - format.setBlueBufferSize(blueSize); - format.setAlphaBufferSize(alphaSize); - format.setDepthBufferSize(depthSize); - format.setStencilBufferSize(stencilSize); - format.setSamples(sampleCount); - format.setPlane(level + 1); // EGL calls level 0 "normal" whereas Qt calls 1 "normal" - format.setDirectRendering(true); // All EGL contexts are direct-rendered - format.setRgba(true); // EGL doesn't support colour index rendering - format.setStereo(false); // EGL doesn't support stereo buffers - format.setAccumBufferSize(0); // EGL doesn't support accululation buffers - - // Clear the EGL error state because some of the above may - // have errored out because the attribute is not applicable - // to the surface type. Such errors don't matter. - eglGetError(); -} + if (m_eglSurface == EGL_NO_SURFACE) { + qWarning("Createing QEGLPlatformContext with no surface"); + } -QEGLPlatformContext::QEGLPlatformContext() -{ + eglBindAPI(m_eglApi); + m_eglContext = eglCreateContext(m_eglDisplay,config, KD_NULL,contextAttrs); + if (!m_eglContext) { + qErrnoWarning("QEGLPlatformContext could not create eglContext"); + } } QEGLPlatformContext::~QEGLPlatformContext() { if (m_eglSurface != EGL_NO_SURFACE) { doneCurrent(); - eglDestroySurface(QEgl::display(), m_eglSurface); + eglDestroySurface(m_eglDisplay, m_eglSurface); m_eglSurface = EGL_NO_SURFACE; } - if (m_context != EGL_NO_CONTEXT) { - eglDestroyContext(QEgl::display(), m_context); - m_context = EGL_NO_CONTEXT; - } -} - -bool QEGLPlatformContext::create(QPaintDevice* device, QGLFormat& format, QPlatformGLContext* shareContext) -{ - QEglProperties properties; - properties.setValue(EGL_CONTEXT_CLIENT_VERSION, 2); - //lets go with all defaults :) Seems like we get bad attributes for anything else - //qt_eglproperties_set_glformat(properties,format); - format.setDepthBufferSize(1); - EGLConfig config = QEgl::defaultConfig(device->devType(), QEgl::OpenGL,QEgl::Renderable); - QEGLPlatformContext *eglShareContext = static_cast(shareContext); - if (shareContext && eglShareContext->m_context != EGL_NO_CONTEXT) { - m_context = eglCreateContext(QEgl::display(), config, eglShareContext->m_context, properties.properties()); - if (m_context == EGL_NO_CONTEXT) { - qWarning() << "QEglContext::createContext(): Could not share context:" << QEgl::errorString(); - shareContext = 0; - } - } else { - m_context = eglCreateContext(QEgl::display(), config, EGL_NO_CONTEXT, properties.properties()); - if (m_context == EGL_NO_CONTEXT) { - qWarning() << "QEglContext::createContext(): Unable to create EGL context:" << QEgl::errorString(); - return false; - } + if (m_eglContext != EGL_NO_CONTEXT) { + eglDestroyContext(m_eglDisplay, m_eglContext); + m_eglContext = EGL_NO_CONTEXT; } - //Get/create the EGLSurface - if (device && device->devType() == QInternal::Widget){ - QWidget* widget = static_cast(device); - QGLWidget* glWidget = qobject_cast(widget); - - if (!widget->isTopLevel()) { - qWarning("Creating a GL context is only supported on top-level QWidgets"); - return false; - } - EGLNativeWindowType winId = (EGLNativeWindowType) widget->window()->winId(); - - m_eglSurface = eglCreateWindowSurface(QEgl::display(), config, winId, 0); - makeCurrent(); - glClearColor(0.0, 0.0, 0.0, 1.0); - swapBuffers(); - - - } else { - qDebug() << "QEGLPlatformContext::create: didn't create surface!!!!!"; - } - return true; - } void QEGLPlatformContext::makeCurrent() { - eglBindAPI(EGL_OPENGL_API); - bool ok = eglMakeCurrent(QEgl::display(), m_eglSurface, m_eglSurface, m_context); + eglBindAPI(m_eglApi); + bool ok = eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext); if (!ok) - qWarning() << "QEGLPlatformContext::makeCurrent(" << m_eglSurface << "):" << QEgl::errorString(); + qWarning() << "QEGLPlatformContext::makeCurrent(" << m_eglSurface << "):" << eglGetError(); } void QEGLPlatformContext::doneCurrent() { - eglBindAPI(EGL_OPENGL_ES_API); - bool ok = eglMakeCurrent(QEgl::display(), EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + eglBindAPI(m_eglApi); + bool ok = eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); if (!ok) - qWarning() << "QEGLPlatformContext::doneCurrent():" << QEgl::errorString(); + qWarning() << "QEGLPlatformContext::doneCurrent():" << eglGetError(); } void QEGLPlatformContext::swapBuffers() { - bool ok = eglSwapBuffers(QEgl::display(), m_eglSurface); + eglBindAPI(m_eglApi); + bool ok = eglSwapBuffers(m_eglDisplay, m_eglSurface); if (!ok) - qWarning() << "QEGLPlatformContext::swapBuffers():" << QEgl::errorString(); + qWarning() << "QEGLPlatformContext::swapBuffers():" << eglGetError(); } void* QEGLPlatformContext::getProcAddress(const QString& procName) { - eglGetProcAddress(qPrintable(procName)); + eglBindAPI(m_eglApi); + return (void *)eglGetProcAddress(qPrintable(procName)); } diff --git a/src/plugins/platforms/openkode/qopenkodeglintegration.h b/src/plugins/platforms/openkode/qopenkodeglintegration.h index b0b7a48..19d155a 100644 --- a/src/plugins/platforms/openkode/qopenkodeglintegration.h +++ b/src/plugins/platforms/openkode/qopenkodeglintegration.h @@ -42,29 +42,25 @@ #ifndef QOPENKODEGLINTEGRATION_H #define QOPENKODEGLINTEGRATION_H -#include -#include +#include #include -void qt_eglproperties_set_glformat(QEglProperties& eglProperties, const QGLFormat& glFormat); -// Updates "format" with the parameters of the selected configuration. -void qt_glformat_from_eglconfig(QGLFormat& format, const EGLConfig config); - class QEGLPlatformContext : public QPlatformGLContext { public: - QEGLPlatformContext(); + QEGLPlatformContext(EGLDisplay display, EGLConfig config, EGLint contextAttrs[], EGLSurface surface, EGLenum eglApi); ~QEGLPlatformContext(); - bool create(QPaintDevice* device, QGLFormat& format, QPlatformGLContext* shareContext); void makeCurrent(); void doneCurrent(); void swapBuffers(); void* getProcAddress(const QString& procName); private: - EGLContext m_context; + EGLContext m_eglContext; + EGLDisplay m_eglDisplay; EGLSurface m_eglSurface; + EGLenum m_eglApi; }; #endif //QOPENKODEGLINTEGRATION_H diff --git a/src/plugins/platforms/openkode/qopenkodeintegration.cpp b/src/plugins/platforms/openkode/qopenkodeintegration.cpp index 5e461ae..52b57d9 100644 --- a/src/plugins/platforms/openkode/qopenkodeintegration.cpp +++ b/src/plugins/platforms/openkode/qopenkodeintegration.cpp @@ -57,6 +57,8 @@ #include #include +#include + #include "GLES2/gl2ext.h" #include @@ -85,6 +87,19 @@ QOpenKODEScreen::QOpenKODEScreen() return; } + 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"); @@ -95,15 +110,26 @@ QOpenKODEScreen::QOpenKODEScreen() KDint desktopSize[] = { mode.width, mode.height }; - if (kdSetDesktopPropertyivNV(kdDesktop, KD_DESKTOPPROPERTY_SIZE_NV, desktopSize)) { - qErrnoWarning(kdGetError(), "Could not set desktop size"); - return; - } +// 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"); + } + const int defaultDpi = 72; mGeometry = QRect(0, 0, mode.width, mode.height); mPhysicalSize = QSize(mode.width * 25.4 / defaultDpi, mode.height * 25.4 / defaultDpi); @@ -212,17 +238,14 @@ QPlatformWindow *QOpenKODEIntegration::createPlatformWindow(QWidget *tlw, WId ) QWindowSurface *QOpenKODEIntegration::createWindowSurface(QWidget *widget, WId wid) const { - return new QOpenKODEWindowSurface(widget, wid); +// return new QOpenKODEWindowSurface(widget, wid); + return new QGLWindowSurface(widget); } bool QOpenKODEIntegration::hasOpenGL() const { return true; } -QPlatformGLContext *QOpenKODEIntegration::createGLContext() -{ - return new QEGLPlatformContext; -} GLuint QOpenKODEIntegration::blitterProgram() { diff --git a/src/plugins/platforms/openkode/qopenkodeintegration.h b/src/plugins/platforms/openkode/qopenkodeintegration.h index f53c520..9029086 100644 --- a/src/plugins/platforms/openkode/qopenkodeintegration.h +++ b/src/plugins/platforms/openkode/qopenkodeintegration.h @@ -46,10 +46,10 @@ #include #include -#include -#include +#include -# include +#include +#include QT_BEGIN_NAMESPACE @@ -57,6 +57,7 @@ struct KDDesktopNV; class QOpenKODEScreen : public QPlatformScreen { + Q_OBJECT public: QOpenKODEScreen(); ~QOpenKODEScreen() {} @@ -66,11 +67,13 @@ public: QImage::Format format() const { return mFormat; } QSize physicalSize() const { return mPhysicalSize; } + EGLDisplay eglDisplay() { return mEglDisplay; } public: QRect mGeometry; int mDepth; QImage::Format mFormat; QSize mPhysicalSize; + EGLDisplay mEglDisplay; }; class QOpenKODEIntegration : public QPlatformIntegration diff --git a/src/plugins/platforms/openkode/qopenkodewindow.cpp b/src/plugins/platforms/openkode/qopenkodewindow.cpp index 4d18a6f..88e6a75 100644 --- a/src/plugins/platforms/openkode/qopenkodewindow.cpp +++ b/src/plugins/platforms/openkode/qopenkodewindow.cpp @@ -39,40 +39,112 @@ ** ****************************************************************************/ #include "qopenkodewindow.h" +#include "qopenkodeintegration.h" +#include "qopenkodeglintegration.h" +#include #include -#include +#include + #include +#include +#include #include QOpenKODEWindow::QOpenKODEWindow(QWidget *tlw) : QPlatformWindow(tlw) { - /* Initialize EGL display */ - EGLBoolean rvbool = eglInitialize(QEgl::display(), KD_NULL, KD_NULL); - if (!rvbool) { - kdLogMessage("EGL failed to initialize display\n"); + EGLint configAttrs[] = { + EGL_RED_SIZE, 1, + EGL_GREEN_SIZE, 1, + EGL_BLUE_SIZE, 1, + EGL_BUFFER_SIZE, 16, + EGL_DEPTH_SIZE, 0, + EGL_LEVEL, 0, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, +// #ifdef EGL_NV_coverage_sample +// EGL_COVERAGE_BUFFERS_NV, 1, +// EGL_COVERAGE_SAMPLES_NV, 5, +// #endif + EGL_ALPHA_SIZE, 0, +// EGL_LUMINANCE_SIZE, 0, + EGL_ALPHA_MASK_SIZE, 0, + EGL_SAMPLES, 0, + EGL_SAMPLE_BUFFERS, 0, +// EGL_STENCIL_SIZE, 0, + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_TRANSPARENT_TYPE, EGL_NONE, + EGL_NONE + }; + EGLint contextAttrs[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, // NOTE: not needed for VG + EGL_NONE + }; + + // EGL_RENDER_BUFFER, EGL_BACK_BUFFER, +// m_eglWindowAttrs.append(EGL_RENDER_BUFFER); +// m_eglWindowAttrs.append(EGL_BACK_BUFFER); + m_eglWindowAttrs.append(EGL_NONE); + + EGLenum eglApi = EGL_OPENGL_ES_API; + eglBindAPI(eglApi); + + QList 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(screens.at(tlw->d_func()->screenNumber)); + QOpenKODEScreen *screen = qobject_cast(screens.at(0)); + if (!screen) { + qErrnoWarning("Could not make QOpenKODEWindow without a screen"); + } + + EGLint configCount; + // Find out how many configurations suit our needs + EGLBoolean eglStatus = eglChooseConfig(screen->eglDisplay(), configAttrs, + KD_NULL, 0, &configCount); + if (!eglStatus || !configCount) { + qErrnoWarning("EGL failed to return any matching configurations"); + } + + qDebug() << "config count" << configCount; + + // Allocate room for the list of matching configurations + EGLConfig *configList = (EGLConfig*)kdMalloc(configCount * sizeof(EGLConfig)); + if (!configList) { + qErrnoWarning("kdMalloc failure obtaining configuration list"); } - kdWindow = kdCreateWindow(QEgl::display(), - QEgl::defaultConfig(QInternal::Widget,QEgl::OpenGL,QEgl::Renderable), + // Obtain the configuration list from EGL + eglStatus = eglChooseConfig(screen->eglDisplay(), configAttrs, + configList, configCount, &configCount); + if (!eglStatus || !configCount) { + qErrnoWarning("EGL failed to populate configuration list"); + } + + // Select an EGL configuration that matches the native window + + m_eglConfig = configList[11]; + kdFree(configList);//free the list not the configs + + m_kdWindow = kdCreateWindow(screen->eglDisplay(), + m_eglConfig, KD_NULL); - if (!kdWindow) { + if (!m_kdWindow) { qErrnoWarning(kdGetError(), "Error creating native window"); return; } const KDint windowSize[2] = { tlw->width(), tlw->height()-1 }; - if (kdSetWindowPropertyiv(kdWindow, KD_WINDOWPROPERTY_SIZE, windowSize)) { + if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_SIZE, windowSize)) { qErrnoWarning(kdGetError(), "Could not set native window size"); return; } - KDboolean visibillity(false); - if (kdSetWindowPropertybv(kdWindow, KD_WINDOWPROPERTY_VISIBILITY, &visibillity)) { - qErrnoWarning(kdGetError(), "Could not set visibillity to false"); - } +// KDboolean visibillity(false); +// if (kdSetWindowPropertybv(m_kdWindow, KD_WINDOWPROPERTY_VISIBILITY, &visibillity)) { +// qErrnoWarning(kdGetError(), "Could not set visibillity to false"); +// } // const KDboolean windowExclusive[] = { false }; // if (kdSetWindowPropertybv(kdWindow, KD_WINDOWPROPERTY_DESKTOP_EXCLUSIVE_NV, windowExclusive)) { @@ -81,28 +153,44 @@ QOpenKODEWindow::QOpenKODEWindow(QWidget *tlw) // } // const KDint windowPos[2] = { tlw->x(), tlw->y() }; - if (kdSetWindowPropertyiv(kdWindow, KD_WINDOWPROPERTY_DESKTOP_OFFSET_NV, windowPos)) { + if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_DESKTOP_OFFSET_NV, windowPos)) { qErrnoWarning(kdGetError(), "Could not set native window position"); return; } - if (kdRealizeWindow(kdWindow, &eglWindow)) { + if (kdRealizeWindow(m_kdWindow, &m_eglWindow)) { qErrnoWarning(kdGetError(), "Could not realize native window"); return; } + + KDint32 layer = 1; + kdGetWindowPropertyiv(m_kdWindow,KD_WINDOWPROPERTY_DESKTOP_LAYER_NV,&layer); + qDebug() << "LAYER:" << layer; + + EGLSurface surface = eglCreateWindowSurface(screen->eglDisplay(),m_eglConfig,m_eglWindow,m_eglWindowAttrs.constData()); + + qDebug() << "surface id " << surface; + + m_platformGlContext = new QEGLPlatformContext(screen->eglDisplay(),m_eglConfig,contextAttrs,surface,eglApi); + m_platformGlContext->makeCurrent(); + glClearColor(0,0,0,0); + + } QOpenKODEWindow::~QOpenKODEWindow() { - qDebug() << "destroying window"; - kdDestroyWindow(kdWindow); + qDebug() << "destroying window" << m_kdWindow; +// delete m_platformGlContext; + kdDestroyWindow(m_kdWindow); } void QOpenKODEWindow::setGeometry(const QRect &rect) { + qDebug() << "setting geo"; const QRect geo = geometry(); if (geo.size() != rect.size()) { const KDint windowSize[2] = { rect.width(), rect.height() }; - if (kdSetWindowPropertyiv(kdWindow, KD_WINDOWPROPERTY_SIZE, windowSize)) { + if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_SIZE, windowSize)) { qErrnoWarning(kdGetError(), "Could not set native window size"); //return; } @@ -110,18 +198,50 @@ void QOpenKODEWindow::setGeometry(const QRect &rect) if (geo.topLeft() != rect.topLeft()) { const KDint windowPos[2] = { rect.x(), rect.y() }; - if (kdSetWindowPropertyiv(kdWindow, KD_WINDOWPROPERTY_DESKTOP_OFFSET_NV, windowPos)) { + if (kdSetWindowPropertyiv(m_kdWindow, KD_WINDOWPROPERTY_DESKTOP_OFFSET_NV, windowPos)) { qErrnoWarning(kdGetError(), "Could not set native window position"); //return; } } + delete m_platformGlContext; + + QList 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(screens.at(tlw->d_func()->screenNumber)); + QOpenKODEScreen *screen = qobject_cast(screens.at(0)); + +// if (kdRealizeWindow(m_kdWindow, &m_eglWindow)) { +// qErrnoWarning(kdGetError(), "Could not realize native window in geo"); +// return; +// } + + EGLint contextAttrs[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, // NOTE: not needed for VG + EGL_NONE + }; + + EGLenum eglApi = EGL_OPENGL_ES_API; + + EGLSurface surface = eglCreateWindowSurface(screen->eglDisplay(),m_eglConfig,m_eglWindow,m_eglWindowAttrs.constData()); + + qDebug() << "surface id " << surface; + + m_platformGlContext = new QEGLPlatformContext(screen->eglDisplay(),m_eglConfig,contextAttrs,surface,eglApi); + m_platformGlContext->makeCurrent(); + glClearColor(0,0,0,1); } void QOpenKODEWindow::setVisible(bool visible) { KDboolean visibillity(visible); - if (kdSetWindowPropertybv(kdWindow, KD_WINDOWPROPERTY_VISIBILITY, &visibillity)) { + if (kdSetWindowPropertybv(m_kdWindow, KD_WINDOWPROPERTY_VISIBILITY, &visibillity)) { qErrnoWarning(kdGetError(), "Could not set visibillity to false"); } } + +QPlatformGLContext *QOpenKODEWindow::glContext() +{ + return m_platformGlContext; +} diff --git a/src/plugins/platforms/openkode/qopenkodewindow.h b/src/plugins/platforms/openkode/qopenkodewindow.h index 741e676..04fa70a 100644 --- a/src/plugins/platforms/openkode/qopenkodewindow.h +++ b/src/plugins/platforms/openkode/qopenkodewindow.h @@ -43,9 +43,12 @@ #define QOPENKODEWINDOW_H #include +#include #include +class QEGLPlatformContext; + class QOpenKODEWindow : public QPlatformWindow { public: @@ -54,11 +57,16 @@ public: void setGeometry(const QRect &rect); void setVisible(bool visible); - WId winId() const { return WId(eglWindow); } + WId winId() const { return WId(m_eglWindow); } + + QPlatformGLContext *glContext(); private: - struct KDWindow *kdWindow; - EGLNativeWindowType eglWindow; + struct KDWindow *m_kdWindow; + EGLNativeWindowType m_eglWindow; + EGLConfig m_eglConfig; + QVector m_eglWindowAttrs; + QEGLPlatformContext *m_platformGlContext; }; #endif //QOPENKODEWINDOW_H diff --git a/src/plugins/platforms/openkode/qopenkodewindowsurface.cpp b/src/plugins/platforms/openkode/qopenkodewindowsurface.cpp index dacd019..a349031 100644 --- a/src/plugins/platforms/openkode/qopenkodewindowsurface.cpp +++ b/src/plugins/platforms/openkode/qopenkodewindowsurface.cpp @@ -45,21 +45,14 @@ #include "qopenkodewindow.h" #include +#include QT_BEGIN_NAMESPACE QOpenKODEWindowSurface::QOpenKODEWindowSurface - (QWidget *window, WId winId) - : QWindowSurface(window), - mSurface(EGL_NO_SURFACE), - mWin((EGLNativeWindowType) winId) + (QWidget *window, WId) + : QWindowSurface(window), m_platformGLContext(window->platformWindow()->glContext()) { - EGLConfig config = QEgl::defaultConfig(QInternal::Widget,QEgl::OpenGL,QEgl::Renderable); - mContext.setConfig(config); - if (!mContext.createContext()) { - qWarning("QOpenKODEWindowSurface: Unable to create context"); - return; - } } QOpenKODEWindowSurface::~QOpenKODEWindowSurface() @@ -72,19 +65,16 @@ QPaintDevice *QOpenKODEWindowSurface::paintDevice() } // ### TODO - this updates the entire toplevel, should only update the region -void QOpenKODEWindowSurface::flush(QWidget *, const QRegion ®ion, const QPoint &offset) +void QOpenKODEWindowSurface::flush(QWidget *widget, const QRegion ®ion, const QPoint &offset) { - mContext.makeCurrent(mSurface); + m_platformGLContext->makeCurrent(); if (!offset.isNull()) { qWarning("Offset flushing not supported yet"); return; } - if (!mContext.makeCurrent(mSurface)) { - qWarning("EGL couldn't make context/surface current: 0x%x", eglGetError()); - return; - } + m_platformGLContext->makeCurrent(); QRect boundingRect = region.boundingRect(); @@ -103,7 +93,7 @@ void QOpenKODEWindowSurface::flush(QWidget *, const QRegion ®ion, const QPoin y = boundingRect.y(); } -// qDebug() << "flush" << widget << offset << region.boundingRect() << mImage.format() << blitImage.format(); + qDebug() << "flush" << widget << offset << region.boundingRect() << mImage.format() << blitImage.format(); GLuint shaderProgram = QOpenKODEIntegration::blitterProgram(); @@ -159,8 +149,8 @@ void QOpenKODEWindowSurface::flush(QWidget *, const QRegion ®ion, const QPoin eglWaitGL(); - mContext.swapBuffers(mSurface); - mContext.doneCurrent(); + m_platformGLContext->swapBuffers(); + m_platformGLContext->doneCurrent(); eglWaitNative(EGL_CORE_NATIVE_ENGINE); } @@ -168,21 +158,14 @@ void QOpenKODEWindowSurface::flush(QWidget *, const QRegion ®ion, const QPoin void QOpenKODEWindowSurface::resize(const QSize &size) { QWindowSurface::resize(size); - mContext.destroySurface(mSurface); - mSurface = EGL_NO_SURFACE; mImage = QImage(); } void QOpenKODEWindowSurface::beginPaint(const QRegion ®ion) { Q_UNUSED(region); - if (mSurface == EGL_NO_SURFACE) { - EGLConfig config = QEgl::defaultConfig(QInternal::Widget,QEgl::OpenGL,QEgl::Renderable); - EGLint windowAttrs[] = { EGL_NONE }; - mSurface = eglCreateWindowSurface(QEgl::display(), config, mWin, windowAttrs); - if (mSurface == EGL_NO_SURFACE) { - qWarning("QEglContext::createSurface(): Unable to create EGL surface, error = 0x%x", eglGetError()); - } + if (mImage.isNull()) { + m_platformGLContext = window()->platformWindow()->glContext(); mImage = QImage(size(),QImage::Format_RGB32); } } diff --git a/src/plugins/platforms/openkode/qopenkodewindowsurface.h b/src/plugins/platforms/openkode/qopenkodewindowsurface.h index 568dbc2..4acd1d8 100644 --- a/src/plugins/platforms/openkode/qopenkodewindowsurface.h +++ b/src/plugins/platforms/openkode/qopenkodewindowsurface.h @@ -43,11 +43,13 @@ #define QWINDOWSURFACE_OPENKODE_H #include -#include + +#include QT_BEGIN_NAMESPACE class QOpenKODEWindow; +class QPlatformGLContext; class QOpenKODEWindowSurface : public QWindowSurface { @@ -65,9 +67,7 @@ public: private: QImage mImage; - EGLSurface mSurface; - QEglContext mContext; - EGLNativeWindowType mWin; + QPlatformGLContext *m_platformGLContext; }; QT_END_NAMESPACE -- cgit v0.12