Merge lp:~fboucault/unity-2d/opengl_plus_composite_fix into lp:unity-2d/3.0

Proposed by Florian Boucault
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 618
Merged at revision: 617
Proposed branch: lp:~fboucault/unity-2d/opengl_plus_composite_fix
Merge into: lp:unity-2d/3.0
Diff against target: 128 lines (+66/-23)
2 files modified
libunity-2d-private/src/unity2ddeclarativeview.cpp (+63/-23)
libunity-2d-private/src/unity2ddeclarativeview.h (+3/-0)
To merge this branch: bzr merge lp:~fboucault/unity-2d/opengl_plus_composite_fix
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
Review via email: mp+66932@code.launchpad.net

Description of the change

[dash] Fix use of opengl rendering backend: artifacts were displayed, even more so with transparency enabled.

The cause of the issue was that the QGLWidget viewport was set on the QDeclarativeView
before having setup the QGLWidget's flags.
Implementation of Unity2dDeclarativeView is much clarified as a result and this change
impacts all the components using it:
- launcher
- dash
- spread

Synchronization to VBlank has also been activated.
Set viewport update mode to QGraphicsView::FullViewportUpdate when using OpenGL.

To post a comment you must log in.
618. By Florian Boucault

Set viewport update mode to QGraphicsView::FullViewportUpdate when using OpenGL.

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

The code seems fine, but I'm unable to reproduce the original problem at least when using with the OpenGLES QT backend.

Did you only see this issue when using with normal OpenGL? I'll reproduce this on my host machine tomorrow to see if I'm at least able to reproduce the issue.

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

When using OpenGL at my desktop I'm able to reproduce the issue this patch fixes. After applying the patch the transparency is now working same way when using without -opengl.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libunity-2d-private/src/unity2ddeclarativeview.cpp'
2--- libunity-2d-private/src/unity2ddeclarativeview.cpp 2011-06-13 00:31:52 +0000
3+++ libunity-2d-private/src/unity2ddeclarativeview.cpp 2011-07-05 18:52:39 +0000
4@@ -2,10 +2,9 @@
5 #include <QGLWidget>
6
7 Unity2DDeclarativeView::Unity2DDeclarativeView(QWidget *parent) :
8- QDeclarativeView(parent), m_useOpenGL(false)
9+ QDeclarativeView(parent), m_useOpenGL(false), m_transparentBackground(false)
10 {
11- setAttribute(Qt::WA_NoSystemBackground);
12- setTransparentBackground(false);
13+ setupViewport();
14 }
15
16 bool Unity2DDeclarativeView::useOpenGL() const
17@@ -19,36 +18,77 @@
18 return;
19 }
20
21- if (useOpenGL) {
22+ m_useOpenGL = useOpenGL;
23+ setupViewport();
24+
25+ Q_EMIT useOpenGLChanged(useOpenGL);
26+}
27+
28+bool Unity2DDeclarativeView::transparentBackground() const
29+{
30+ return m_transparentBackground;
31+}
32+
33+void Unity2DDeclarativeView::setTransparentBackground(bool transparentBackground)
34+{
35+ if (transparentBackground == m_transparentBackground) {
36+ return;
37+ }
38+
39+ m_transparentBackground = transparentBackground;
40+ setupViewport();
41+
42+ Q_EMIT transparentBackgroundChanged(transparentBackground);
43+}
44+
45+void Unity2DDeclarativeView::setupViewport()
46+{
47+ if (m_useOpenGL) {
48 QGLFormat format = QGLFormat::defaultFormat();
49 format.setSampleBuffers(false);
50+ /* Synchronise rendering with vblank */
51+ format.setSwapInterval(1);
52
53 QGLWidget *glWidget = new QGLWidget(format);
54- /* TODO: possibly faster, to be tested */
55+ /* TODO: possibly faster, to be tested, only works with non transparent windows */
56 //glWidget->setAutoFillBackground(false);
57
58+ if (m_transparentBackground) {
59+ glWidget->setAttribute(Qt::WA_TranslucentBackground, true);
60+ setAttribute(Qt::WA_TranslucentBackground, true);
61+ /* automatically set by setting WA_TranslucentBackground */
62+ setAttribute(Qt::WA_NoSystemBackground, true);
63+ setAttribute(Qt::WA_OpaquePaintEvent, true);
64+ } else {
65+ glWidget->setAttribute(Qt::WA_TranslucentBackground, false);
66+ setAttribute(Qt::WA_TranslucentBackground, false);
67+ setAttribute(Qt::WA_NoSystemBackground, true);
68+ setAttribute(Qt::WA_OpaquePaintEvent, true);
69+ }
70+
71 setViewport(glWidget);
72+ /* According to Qt's documentation: "This is the preferred update mode
73+ for viewports that do not support partial updates, such as QGLWidget [...]"
74+ */
75+ setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
76 } else {
77 setViewport(0);
78+ /* This is the default update mode */
79+ setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate);
80+
81+ if (m_transparentBackground) {
82+ viewport()->setAttribute(Qt::WA_TranslucentBackground, true);
83+ setAttribute(Qt::WA_TranslucentBackground, true);
84+ /* automatically set by setting WA_TranslucentBackground */
85+ setAttribute(Qt::WA_NoSystemBackground, true);
86+ setAttribute(Qt::WA_OpaquePaintEvent, false);
87+ } else {
88+ viewport()->setAttribute(Qt::WA_TranslucentBackground, false);
89+ setAttribute(Qt::WA_TranslucentBackground, false);
90+ setAttribute(Qt::WA_NoSystemBackground, true);
91+ setAttribute(Qt::WA_OpaquePaintEvent, true);
92+ }
93 }
94-
95- m_useOpenGL = useOpenGL;
96- Q_EMIT useOpenGLChanged(useOpenGL);
97-}
98-
99-bool Unity2DDeclarativeView::transparentBackground() const
100-{
101- return m_transparentBackground;
102-}
103-
104-void Unity2DDeclarativeView::setTransparentBackground(bool transparentBackground)
105-{
106- setAttribute(Qt::WA_TranslucentBackground, transparentBackground);
107- viewport()->setAttribute(Qt::WA_TranslucentBackground, transparentBackground);
108- setAttribute(Qt::WA_OpaquePaintEvent, !transparentBackground);
109-
110- m_transparentBackground = transparentBackground;
111- Q_EMIT transparentBackgroundChanged(transparentBackground);
112 }
113
114 #include <unity2ddeclarativeview.moc>
115
116=== modified file 'libunity-2d-private/src/unity2ddeclarativeview.h'
117--- libunity-2d-private/src/unity2ddeclarativeview.h 2011-06-13 00:31:52 +0000
118+++ libunity-2d-private/src/unity2ddeclarativeview.h 2011-07-05 18:52:39 +0000
119@@ -25,6 +25,9 @@
120 void useOpenGLChanged(bool);
121 void transparentBackgroundChanged(bool);
122
123+protected:
124+ void setupViewport();
125+
126 private:
127 bool m_useOpenGL;
128 bool m_transparentBackground;

Subscribers

People subscribed via source and target branches