Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git i/examples/widgets/widgets/calculator/calculator.cpp w/examples/widgets/widgets/calculator/calculator.cpp
- index cbcc29b2a8..f66847d354 100644
- --- i/examples/widgets/widgets/calculator/calculator.cpp
- +++ w/examples/widgets/widgets/calculator/calculator.cpp
- @@ -114,10 +114,13 @@ Calculator::Calculator(QWidget *parent)
- mainLayout->addWidget(clearButton, 1, 2, 1, 2);
- mainLayout->addWidget(clearAllButton, 1, 4, 1, 2);
- - mainLayout->addWidget(clearMemoryButton, 2, 0);
- + //mainLayout->addWidget(clearMemoryButton, 2, 0);
- + mainLayout->addWidget(new MyGLWidget, 2, 0);
- mainLayout->addWidget(readMemoryButton, 3, 0);
- mainLayout->addWidget(setMemoryButton, 4, 0);
- - mainLayout->addWidget(addToMemoryButton, 5, 0);
- + mainLayout->addWidget(new GLWidget, 5, 0);
- + //mainLayout->addWidget(addToMemoryButton, 5, 0);
- + //addToMemoryButton->winId();
- for (int i = 1; i < NumDigitButtons; ++i) {
- int row = ((9 - i) / 3) + 2;
- diff --git i/examples/widgets/widgets/calculator/calculator.h w/examples/widgets/widgets/calculator/calculator.h
- index 6d7e336347..1db67e3cb5 100644
- --- i/examples/widgets/widgets/calculator/calculator.h
- +++ w/examples/widgets/widgets/calculator/calculator.h
- @@ -53,6 +53,57 @@
- #include <QWidget>
- +
- +#include <QGLWidget>
- +#include <QOpenGLWidget>
- +#include <QOpenGLContext>
- +#include <QOpenGLFunctions>
- +
- +class GLWidget : public QGLWidget
- +{
- + Q_OBJECT
- +public:
- + explicit GLWidget(QWidget *parent = 0) {
- + setObjectName("Gl Widget");
- + }
- +
- +protected:
- +
- + void initializeGL()
- + {
- + qglClearColor( Qt::blue );
- + }
- + void paintGL()
- + {
- + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- + }
- +};
- +
- +class MyGLWidget : public QOpenGLWidget
- +{
- +public:
- + MyGLWidget(QWidget *parent = nullptr) : QOpenGLWidget(parent) { }
- +
- +protected:
- + void initializeGL()
- + {
- + // Set up the rendering context, load shaders and other resources, etc.:
- + QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
- + f->glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
- + }
- +
- + void resizeGL(int w, int h)
- + {
- + }
- +
- + void paintGL()
- + {
- + // Draw the scene:
- + QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
- + f->glClear(GL_COLOR_BUFFER_BIT);
- + }
- +};
- +
- QT_BEGIN_NAMESPACE
- class QLineEdit;
- QT_END_NAMESPACE
- diff --git i/examples/widgets/widgets/calculator/calculator.pro w/examples/widgets/widgets/calculator/calculator.pro
- index 5ee6928c7d..20eaeaac38 100644
- --- i/examples/widgets/widgets/calculator/calculator.pro
- +++ w/examples/widgets/widgets/calculator/calculator.pro
- @@ -1,4 +1,4 @@
- -QT += widgets
- +QT += widgets opengl
- HEADERS = button.h \
- calculator.h
- diff --git i/examples/widgets/widgets/calculator/main.cpp w/examples/widgets/widgets/calculator/main.cpp
- index a034bb262e..3e0457f552 100644
- --- i/examples/widgets/widgets/calculator/main.cpp
- +++ w/examples/widgets/widgets/calculator/main.cpp
- @@ -56,6 +56,8 @@ int main(int argc, char *argv[])
- {
- QApplication app(argc, argv);
- Calculator calc;
- + //GLWidget calc;
- + //calc.resize(200, 200);
- calc.show();
- return app.exec();
- }
- diff --git i/src/plugins/platforms/cocoa/qcocoaglcontext.h w/src/plugins/platforms/cocoa/qcocoaglcontext.h
- index 0530aa8201..c9ff2cef67 100644
- --- i/src/plugins/platforms/cocoa/qcocoaglcontext.h
- +++ w/src/plugins/platforms/cocoa/qcocoaglcontext.h
- @@ -77,7 +77,7 @@ public:
- QVariant nativeHandle() const;
- private:
- - void setActiveWindow(QWindow *window);
- + bool setActiveWindow(QWindow *window);
- void updateSurfaceFormat();
- NSOpenGLContext *m_context;
- diff --git i/src/plugins/platforms/cocoa/qcocoaglcontext.mm w/src/plugins/platforms/cocoa/qcocoaglcontext.mm
- index 35fa8d0c34..5296751e08 100644
- --- i/src/plugins/platforms/cocoa/qcocoaglcontext.mm
- +++ w/src/plugins/platforms/cocoa/qcocoaglcontext.mm
- @@ -251,7 +251,10 @@ void QCocoaGLContext::swapBuffers(QPlatformSurface *surface)
- return; // Nothing to do
- QWindow *window = static_cast<QCocoaWindow *>(surface)->window();
- - setActiveWindow(window);
- + if (!setActiveWindow(window)) {
- + qCDebug(lcQpaOpenGLContext) << "Not active window, skipping swapBuffers";
- + return;
- + }
- QMutexLocker locker(&s_contextMutex);
- [m_context flushBuffer];
- @@ -268,7 +271,10 @@ bool QCocoaGLContext::makeCurrent(QPlatformSurface *surface)
- return true;
- QWindow *window = static_cast<QCocoaWindow *>(surface)->window();
- - setActiveWindow(window);
- + if (!setActiveWindow(window)) {
- + qCDebug(lcQpaOpenGLContext) << "Not active window, skipping makeCurrent";
- + return false;
- + }
- // Disable high-resolution surfaces when using the software renderer, which has the
- // problem that the system silently falls back to a to using a low-resolution buffer
- @@ -289,23 +295,31 @@ bool QCocoaGLContext::makeCurrent(QPlatformSurface *surface)
- return true;
- }
- -void QCocoaGLContext::setActiveWindow(QWindow *window)
- +bool QCocoaGLContext::setActiveWindow(QWindow *window)
- {
- if (window == m_currentWindow.data())
- - return;
- + return true;
- if (m_currentWindow && m_currentWindow.data()->handle())
- static_cast<QCocoaWindow *>(m_currentWindow.data()->handle())->setCurrentContext(0);
- Q_ASSERT(window->handle());
- - m_currentWindow = window;
- -
- QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
- + m_context.view = cocoaWindow->view();
- + if (!m_context.view) {
- + qCDebug(lcQpaOpenGLContext) << "Associating" << cocoaWindow->view()
- + << "with" << m_context << "failed, probably too soon";
- + return false;
- + }
- +
- + m_currentWindow = window;
- cocoaWindow->setCurrentContext(this);
- Q_ASSERT(!cocoaWindow->isForeignWindow());
- [qnsview_cast(cocoaWindow->view()) setQCocoaGLContext:this];
- +
- + return true;
- }
- void QCocoaGLContext::updateSurfaceFormat()
- diff --git i/src/plugins/platforms/cocoa/qnsview_drawing.mm w/src/plugins/platforms/cocoa/qnsview_drawing.mm
- index 8ebe27f0c2..b0d2331689 100644
- --- i/src/plugins/platforms/cocoa/qnsview_drawing.mm
- +++ w/src/plugins/platforms/cocoa/qnsview_drawing.mm
- @@ -45,11 +45,6 @@
- - (void)setQCocoaGLContext:(QCocoaGLContext *)context
- {
- m_glContext = context;
- - [m_glContext->nsOpenGLContext() setView:self];
- - if (![m_glContext->nsOpenGLContext() view]) {
- - //was unable to set view
- - m_shouldSetGLContextinDrawRect = true;
- - }
- }
- #endif
- @@ -89,13 +84,6 @@
- - (void)updateRegion:(QRegion)dirtyRegion
- {
- -#ifndef QT_NO_OPENGL
- - if (m_glContext && m_shouldSetGLContextinDrawRect) {
- - [m_glContext->nsOpenGLContext() setView:self];
- - m_shouldSetGLContextinDrawRect = false;
- - }
- -#endif
- -
- m_platformWindow->handleExposeEvent(dirtyRegion);
- }
- diff --git i/src/plugins/styles/mac/qmacstyle_mac.mm w/src/plugins/styles/mac/qmacstyle_mac.mm
- index ae2765fc40..52431c4aaa 100644
- --- i/src/plugins/styles/mac/qmacstyle_mac.mm
- +++ w/src/plugins/styles/mac/qmacstyle_mac.mm
- @@ -1913,9 +1913,10 @@ void QMacStylePrivate::drawNSViewInRect(NSView *view, const QRectF &rect, QPaint
- restoreNSGraphicsContext(ctx);
- }
- -void QMacStylePrivate::resolveCurrentNSView(QWindow *window) const
- +void QMacStylePrivate::resolveCurrentNSView(QWindow *window, const QPoint &offset) const
- {
- backingStoreNSView = window ? (NSView *)window->winId() : nil;
- + topLevelOffset = offset;
- }
- QMacStyle::QMacStyle()
- @@ -2809,7 +2810,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai
- Q_D(const QMacStyle);
- QMacCGContext cg(p);
- QWindow *window = w && w->window() ? w->window()->windowHandle() : nullptr;
- - d->resolveCurrentNSView(window);
- + d->resolveCurrentNSView(window, w->mapTo(w->window(), QPoint(0, 0)));
- switch (pe) {
- case PE_IndicatorArrowUp:
- case PE_IndicatorArrowDown:
- @@ -3253,7 +3254,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
- Q_D(const QMacStyle);
- QMacCGContext cg(p);
- QWindow *window = w && w->window() ? w->window()->windowHandle() : nullptr;
- - d->resolveCurrentNSView(window);
- + d->resolveCurrentNSView(window, w->mapTo(w->window(), QPoint(0, 0)));
- switch (ce) {
- case CE_HeaderSection:
- if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
- @@ -4827,7 +4828,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
- Q_D(const QMacStyle);
- QMacCGContext cg(p);
- QWindow *window = widget && widget->window() ? widget->window()->windowHandle() : nullptr;
- - d->resolveCurrentNSView(window);
- + d->resolveCurrentNSView(window, widget->mapTo(widget->window(), QPoint(0, 0)));
- switch (cc) {
- case CC_ScrollBar:
- if (const QStyleOptionSlider *sb = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
- diff --git i/src/plugins/styles/mac/qmacstyle_mac_p_p.h w/src/plugins/styles/mac/qmacstyle_mac_p_p.h
- index 8c712e838a..0606356587 100644
- --- i/src/plugins/styles/mac/qmacstyle_mac_p_p.h
- +++ w/src/plugins/styles/mac/qmacstyle_mac_p_p.h
- @@ -266,7 +266,7 @@ public:
- void setupVerticalInvertedXform(CGContextRef cg, bool reverse, bool vertical, const CGRect &rect) const;
- void drawNSViewInRect(NSView *view, const QRectF &rect, QPainter *p, __attribute__((noescape)) DrawRectBlock drawRectBlock = nil) const;
- - void resolveCurrentNSView(QWindow *window) const;
- + void resolveCurrentNSView(QWindow *window, const QPoint &offset) const;
- void drawFocusRing(QPainter *p, const QRectF &targetRect, int hMargin, int vMargin, const CocoaControl &cw) const;
- @@ -289,6 +289,7 @@ public:
- mutable QPointer<QFocusFrame> focusWidget;
- QT_MANGLE_NAMESPACE(NotificationReceiver) *receiver;
- mutable NSView *backingStoreNSView;
- + mutable QPoint topLevelOffset;
- mutable QHash<CocoaControl, NSView *> cocoaControls;
- mutable QHash<CocoaControl, NSCell *> cocoaCells;
Add Comment
Please, Sign In to add comment