Guest User

Untitled

a guest
Jul 18th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.94 KB | None | 0 0
  1. diff --git i/examples/widgets/widgets/calculator/calculator.cpp w/examples/widgets/widgets/calculator/calculator.cpp
  2. index cbcc29b2a8..f66847d354 100644
  3. --- i/examples/widgets/widgets/calculator/calculator.cpp
  4. +++ w/examples/widgets/widgets/calculator/calculator.cpp
  5. @@ -114,10 +114,13 @@ Calculator::Calculator(QWidget *parent)
  6. mainLayout->addWidget(clearButton, 1, 2, 1, 2);
  7. mainLayout->addWidget(clearAllButton, 1, 4, 1, 2);
  8.  
  9. - mainLayout->addWidget(clearMemoryButton, 2, 0);
  10. + //mainLayout->addWidget(clearMemoryButton, 2, 0);
  11. + mainLayout->addWidget(new MyGLWidget, 2, 0);
  12. mainLayout->addWidget(readMemoryButton, 3, 0);
  13. mainLayout->addWidget(setMemoryButton, 4, 0);
  14. - mainLayout->addWidget(addToMemoryButton, 5, 0);
  15. + mainLayout->addWidget(new GLWidget, 5, 0);
  16. + //mainLayout->addWidget(addToMemoryButton, 5, 0);
  17. + //addToMemoryButton->winId();
  18.  
  19. for (int i = 1; i < NumDigitButtons; ++i) {
  20. int row = ((9 - i) / 3) + 2;
  21. diff --git i/examples/widgets/widgets/calculator/calculator.h w/examples/widgets/widgets/calculator/calculator.h
  22. index 6d7e336347..1db67e3cb5 100644
  23. --- i/examples/widgets/widgets/calculator/calculator.h
  24. +++ w/examples/widgets/widgets/calculator/calculator.h
  25. @@ -53,6 +53,57 @@
  26.  
  27. #include <QWidget>
  28.  
  29. +
  30. +#include <QGLWidget>
  31. +#include <QOpenGLWidget>
  32. +#include <QOpenGLContext>
  33. +#include <QOpenGLFunctions>
  34. +
  35. +class GLWidget : public QGLWidget
  36. +{
  37. + Q_OBJECT
  38. +public:
  39. + explicit GLWidget(QWidget *parent = 0) {
  40. + setObjectName("Gl Widget");
  41. + }
  42. +
  43. +protected:
  44. +
  45. + void initializeGL()
  46. + {
  47. + qglClearColor( Qt::blue );
  48. + }
  49. + void paintGL()
  50. + {
  51. + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  52. + }
  53. +};
  54. +
  55. +class MyGLWidget : public QOpenGLWidget
  56. +{
  57. +public:
  58. + MyGLWidget(QWidget *parent = nullptr) : QOpenGLWidget(parent) { }
  59. +
  60. +protected:
  61. + void initializeGL()
  62. + {
  63. + // Set up the rendering context, load shaders and other resources, etc.:
  64. + QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
  65. + f->glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
  66. + }
  67. +
  68. + void resizeGL(int w, int h)
  69. + {
  70. + }
  71. +
  72. + void paintGL()
  73. + {
  74. + // Draw the scene:
  75. + QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
  76. + f->glClear(GL_COLOR_BUFFER_BIT);
  77. + }
  78. +};
  79. +
  80. QT_BEGIN_NAMESPACE
  81. class QLineEdit;
  82. QT_END_NAMESPACE
  83. diff --git i/examples/widgets/widgets/calculator/calculator.pro w/examples/widgets/widgets/calculator/calculator.pro
  84. index 5ee6928c7d..20eaeaac38 100644
  85. --- i/examples/widgets/widgets/calculator/calculator.pro
  86. +++ w/examples/widgets/widgets/calculator/calculator.pro
  87. @@ -1,4 +1,4 @@
  88. -QT += widgets
  89. +QT += widgets opengl
  90.  
  91. HEADERS = button.h \
  92. calculator.h
  93. diff --git i/examples/widgets/widgets/calculator/main.cpp w/examples/widgets/widgets/calculator/main.cpp
  94. index a034bb262e..3e0457f552 100644
  95. --- i/examples/widgets/widgets/calculator/main.cpp
  96. +++ w/examples/widgets/widgets/calculator/main.cpp
  97. @@ -56,6 +56,8 @@ int main(int argc, char *argv[])
  98. {
  99. QApplication app(argc, argv);
  100. Calculator calc;
  101. + //GLWidget calc;
  102. + //calc.resize(200, 200);
  103. calc.show();
  104. return app.exec();
  105. }
  106. diff --git i/src/plugins/platforms/cocoa/qcocoaglcontext.h w/src/plugins/platforms/cocoa/qcocoaglcontext.h
  107. index 0530aa8201..c9ff2cef67 100644
  108. --- i/src/plugins/platforms/cocoa/qcocoaglcontext.h
  109. +++ w/src/plugins/platforms/cocoa/qcocoaglcontext.h
  110. @@ -77,7 +77,7 @@ public:
  111. QVariant nativeHandle() const;
  112.  
  113. private:
  114. - void setActiveWindow(QWindow *window);
  115. + bool setActiveWindow(QWindow *window);
  116. void updateSurfaceFormat();
  117.  
  118. NSOpenGLContext *m_context;
  119. diff --git i/src/plugins/platforms/cocoa/qcocoaglcontext.mm w/src/plugins/platforms/cocoa/qcocoaglcontext.mm
  120. index 35fa8d0c34..5296751e08 100644
  121. --- i/src/plugins/platforms/cocoa/qcocoaglcontext.mm
  122. +++ w/src/plugins/platforms/cocoa/qcocoaglcontext.mm
  123. @@ -251,7 +251,10 @@ void QCocoaGLContext::swapBuffers(QPlatformSurface *surface)
  124. return; // Nothing to do
  125.  
  126. QWindow *window = static_cast<QCocoaWindow *>(surface)->window();
  127. - setActiveWindow(window);
  128. + if (!setActiveWindow(window)) {
  129. + qCDebug(lcQpaOpenGLContext) << "Not active window, skipping swapBuffers";
  130. + return;
  131. + }
  132.  
  133. QMutexLocker locker(&s_contextMutex);
  134. [m_context flushBuffer];
  135. @@ -268,7 +271,10 @@ bool QCocoaGLContext::makeCurrent(QPlatformSurface *surface)
  136. return true;
  137.  
  138. QWindow *window = static_cast<QCocoaWindow *>(surface)->window();
  139. - setActiveWindow(window);
  140. + if (!setActiveWindow(window)) {
  141. + qCDebug(lcQpaOpenGLContext) << "Not active window, skipping makeCurrent";
  142. + return false;
  143. + }
  144.  
  145. // Disable high-resolution surfaces when using the software renderer, which has the
  146. // problem that the system silently falls back to a to using a low-resolution buffer
  147. @@ -289,23 +295,31 @@ bool QCocoaGLContext::makeCurrent(QPlatformSurface *surface)
  148. return true;
  149. }
  150.  
  151. -void QCocoaGLContext::setActiveWindow(QWindow *window)
  152. +bool QCocoaGLContext::setActiveWindow(QWindow *window)
  153. {
  154. if (window == m_currentWindow.data())
  155. - return;
  156. + return true;
  157.  
  158. if (m_currentWindow && m_currentWindow.data()->handle())
  159. static_cast<QCocoaWindow *>(m_currentWindow.data()->handle())->setCurrentContext(0);
  160.  
  161. Q_ASSERT(window->handle());
  162.  
  163. - m_currentWindow = window;
  164. -
  165. QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
  166. + m_context.view = cocoaWindow->view();
  167. + if (!m_context.view) {
  168. + qCDebug(lcQpaOpenGLContext) << "Associating" << cocoaWindow->view()
  169. + << "with" << m_context << "failed, probably too soon";
  170. + return false;
  171. + }
  172. +
  173. + m_currentWindow = window;
  174. cocoaWindow->setCurrentContext(this);
  175.  
  176. Q_ASSERT(!cocoaWindow->isForeignWindow());
  177. [qnsview_cast(cocoaWindow->view()) setQCocoaGLContext:this];
  178. +
  179. + return true;
  180. }
  181.  
  182. void QCocoaGLContext::updateSurfaceFormat()
  183. diff --git i/src/plugins/platforms/cocoa/qnsview_drawing.mm w/src/plugins/platforms/cocoa/qnsview_drawing.mm
  184. index 8ebe27f0c2..b0d2331689 100644
  185. --- i/src/plugins/platforms/cocoa/qnsview_drawing.mm
  186. +++ w/src/plugins/platforms/cocoa/qnsview_drawing.mm
  187. @@ -45,11 +45,6 @@
  188. - (void)setQCocoaGLContext:(QCocoaGLContext *)context
  189. {
  190. m_glContext = context;
  191. - [m_glContext->nsOpenGLContext() setView:self];
  192. - if (![m_glContext->nsOpenGLContext() view]) {
  193. - //was unable to set view
  194. - m_shouldSetGLContextinDrawRect = true;
  195. - }
  196. }
  197. #endif
  198.  
  199. @@ -89,13 +84,6 @@
  200.  
  201. - (void)updateRegion:(QRegion)dirtyRegion
  202. {
  203. -#ifndef QT_NO_OPENGL
  204. - if (m_glContext && m_shouldSetGLContextinDrawRect) {
  205. - [m_glContext->nsOpenGLContext() setView:self];
  206. - m_shouldSetGLContextinDrawRect = false;
  207. - }
  208. -#endif
  209. -
  210. m_platformWindow->handleExposeEvent(dirtyRegion);
  211. }
  212.  
  213. diff --git i/src/plugins/styles/mac/qmacstyle_mac.mm w/src/plugins/styles/mac/qmacstyle_mac.mm
  214. index ae2765fc40..52431c4aaa 100644
  215. --- i/src/plugins/styles/mac/qmacstyle_mac.mm
  216. +++ w/src/plugins/styles/mac/qmacstyle_mac.mm
  217. @@ -1913,9 +1913,10 @@ void QMacStylePrivate::drawNSViewInRect(NSView *view, const QRectF &rect, QPaint
  218. restoreNSGraphicsContext(ctx);
  219. }
  220.  
  221. -void QMacStylePrivate::resolveCurrentNSView(QWindow *window) const
  222. +void QMacStylePrivate::resolveCurrentNSView(QWindow *window, const QPoint &offset) const
  223. {
  224. backingStoreNSView = window ? (NSView *)window->winId() : nil;
  225. + topLevelOffset = offset;
  226. }
  227.  
  228. QMacStyle::QMacStyle()
  229. @@ -2809,7 +2810,7 @@ void QMacStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPai
  230. Q_D(const QMacStyle);
  231. QMacCGContext cg(p);
  232. QWindow *window = w && w->window() ? w->window()->windowHandle() : nullptr;
  233. - d->resolveCurrentNSView(window);
  234. + d->resolveCurrentNSView(window, w->mapTo(w->window(), QPoint(0, 0)));
  235. switch (pe) {
  236. case PE_IndicatorArrowUp:
  237. case PE_IndicatorArrowDown:
  238. @@ -3253,7 +3254,7 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
  239. Q_D(const QMacStyle);
  240. QMacCGContext cg(p);
  241. QWindow *window = w && w->window() ? w->window()->windowHandle() : nullptr;
  242. - d->resolveCurrentNSView(window);
  243. + d->resolveCurrentNSView(window, w->mapTo(w->window(), QPoint(0, 0)));
  244. switch (ce) {
  245. case CE_HeaderSection:
  246. if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(opt)) {
  247. @@ -4827,7 +4828,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex
  248. Q_D(const QMacStyle);
  249. QMacCGContext cg(p);
  250. QWindow *window = widget && widget->window() ? widget->window()->windowHandle() : nullptr;
  251. - d->resolveCurrentNSView(window);
  252. + d->resolveCurrentNSView(window, widget->mapTo(widget->window(), QPoint(0, 0)));
  253. switch (cc) {
  254. case CC_ScrollBar:
  255. if (const QStyleOptionSlider *sb = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
  256. diff --git i/src/plugins/styles/mac/qmacstyle_mac_p_p.h w/src/plugins/styles/mac/qmacstyle_mac_p_p.h
  257. index 8c712e838a..0606356587 100644
  258. --- i/src/plugins/styles/mac/qmacstyle_mac_p_p.h
  259. +++ w/src/plugins/styles/mac/qmacstyle_mac_p_p.h
  260. @@ -266,7 +266,7 @@ public:
  261. void setupVerticalInvertedXform(CGContextRef cg, bool reverse, bool vertical, const CGRect &rect) const;
  262.  
  263. void drawNSViewInRect(NSView *view, const QRectF &rect, QPainter *p, __attribute__((noescape)) DrawRectBlock drawRectBlock = nil) const;
  264. - void resolveCurrentNSView(QWindow *window) const;
  265. + void resolveCurrentNSView(QWindow *window, const QPoint &offset) const;
  266.  
  267. void drawFocusRing(QPainter *p, const QRectF &targetRect, int hMargin, int vMargin, const CocoaControl &cw) const;
  268.  
  269. @@ -289,6 +289,7 @@ public:
  270. mutable QPointer<QFocusFrame> focusWidget;
  271. QT_MANGLE_NAMESPACE(NotificationReceiver) *receiver;
  272. mutable NSView *backingStoreNSView;
  273. + mutable QPoint topLevelOffset;
  274. mutable QHash<CocoaControl, NSView *> cocoaControls;
  275. mutable QHash<CocoaControl, NSCell *> cocoaCells;
Add Comment
Please, Sign In to add comment