Merge lp:~smspillaz/unity/unity.fix_1180174 into lp:unity

Proposed by Sam Spilsbury
Status: Merged
Approved by: Stephen M. Webb
Approved revision: no longer in the source branch.
Merged at revision: 3323
Proposed branch: lp:~smspillaz/unity/unity.fix_1180174
Merge into: lp:unity
Diff against target: 263 lines (+115/-9)
5 files modified
launcher/Launcher.cpp (+8/-2)
launcher/LauncherDragWindow.cpp (+22/-1)
launcher/LauncherDragWindow.h (+9/-1)
launcher/SoftwareCenterLauncherIcon.cpp (+10/-4)
tests/test_launcher_drag_window.cpp (+66/-1)
To merge this branch: bzr merge lp:~smspillaz/unity/unity.fix_1180174
Reviewer Review Type Date Requested Status
Stephen M. Webb (community) Approve
MC Return (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+163834@code.launchpad.net

Commit message

LauncherDragWindow: defer icon paint until DrawContent rather than doing
so immediately

(LP: #1180174)

Description of the change

LauncherDragWindow: defer icon paint until DrawContent rather than doing
so immediately

(LP: #1180174)

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
MC Return (mc-return) wrote :

LGTM. +1.
Probably this might have the potential to fix bug #1169493 also... ?

review: Approve
Revision history for this message
Sam Spilsbury (smspillaz) wrote :

Sounds similar to what this fixed in my experimental branch, yes.

Revision history for this message
Stephen M. Webb (bregma) wrote :

Sweet.

review: Approve
Revision history for this message
Sam Spilsbury (smspillaz) wrote :

I can't confirm that by the way, don't have the hardware.

I did run into a slight issue with this on my experimental branch - namely that the icon got a white background for one frame.

Not sure why that is, something to do with that being on the icon layer config? In any case, nobody seems to have run into it here ...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/Launcher.cpp'
2--- launcher/Launcher.cpp 2013-04-10 17:47:05 +0000
3+++ launcher/Launcher.cpp 2013-05-15 05:07:37 +0000
4@@ -21,6 +21,8 @@
5 #include "config.h"
6 #include <math.h>
7
8+#include <functional>
9+
10 #include <Nux/Nux.h>
11 #include <Nux/VScrollBar.h>
12 #include <Nux/HLayout.h>
13@@ -1966,6 +1968,8 @@
14
15 void Launcher::StartIconDrag(AbstractLauncherIcon::Ptr const& icon)
16 {
17+ using namespace std::placeholders;
18+
19 if (!icon)
20 return;
21
22@@ -1975,8 +1979,10 @@
23
24 HideDragWindow();
25 _offscreen_drag_texture = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(GetWidth(), GetWidth(), 1, nux::BITFMT_R8G8B8A8);
26- _drag_window = new LauncherDragWindow(_offscreen_drag_texture);
27- RenderIconToTexture(nux::GetWindowThread()->GetGraphicsEngine(), _drag_icon, _offscreen_drag_texture);
28+ _drag_window = new LauncherDragWindow(_offscreen_drag_texture,
29+ std::bind(&Launcher::RenderIconToTexture, this,
30+ _1,
31+ _drag_icon, _offscreen_drag_texture));
32 ShowDragWindow();
33
34 ubus_.SendMessage(UBUS_LAUNCHER_ICON_START_DND);
35
36=== modified file 'launcher/LauncherDragWindow.cpp'
37--- launcher/LauncherDragWindow.cpp 2012-11-06 18:19:09 +0000
38+++ launcher/LauncherDragWindow.cpp 2013-05-15 05:07:37 +0000
39@@ -41,8 +41,11 @@
40
41 NUX_IMPLEMENT_OBJECT_TYPE(LauncherDragWindow);
42
43-LauncherDragWindow::LauncherDragWindow(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture)
44+LauncherDragWindow::LauncherDragWindow(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture,
45+ std::function<void(nux::GraphicsEngine &)> const &deferred_icon_render_func)
46 : nux::BaseWindow("")
47+ , icon_rendered_(false)
48+ , deferred_icon_render_func_(deferred_icon_render_func)
49 , animation_speed_(QUICK_ANIMATION_SPEED)
50 , cancelled_(false)
51 , texture_(texture)
52@@ -67,6 +70,11 @@
53 UnGrabKeyboard();
54 }
55
56+bool LauncherDragWindow::DrawContentOnNuxLayer() const
57+{
58+ return true;
59+}
60+
61 bool LauncherDragWindow::Animating() const
62 {
63 return bool(animation_timer_);
64@@ -150,6 +158,19 @@
65
66 GfxContext.PushClippingRectangle(geo);
67
68+ // Render the icon if we haven't already
69+ if (!icon_rendered_)
70+ {
71+ deferred_icon_render_func_ (GfxContext);
72+ icon_rendered_ = true;
73+ }
74+
75+ if (!DrawContentOnNuxLayer())
76+ {
77+ GfxContext.PopClippingRectangle();
78+ return;
79+ }
80+
81 nux::TexCoordXForm texxform;
82 texxform.FlipVCoord(true);
83
84
85=== modified file 'launcher/LauncherDragWindow.h'
86--- launcher/LauncherDragWindow.h 2012-10-31 16:33:47 +0000
87+++ launcher/LauncherDragWindow.h 2013-05-15 05:07:37 +0000
88@@ -20,6 +20,8 @@
89 #ifndef LAUNCHERDRAGWINDOW_H
90 #define LAUNCHERDRAGWINDOW_H
91
92+#include <functional>
93+
94 #include <Nux/Nux.h>
95 #include <Nux/BaseWindow.h>
96 #include <NuxGraphics/GraphicsEngine.h>
97@@ -36,7 +38,8 @@
98 {
99 NUX_DECLARE_OBJECT_TYPE(LauncherDragWindow, nux::BaseWindow);
100 public:
101- LauncherDragWindow(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture);
102+ LauncherDragWindow(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture,
103+ std::function<void(nux::GraphicsEngine &)> const &deferred_icon_render_func);
104 ~LauncherDragWindow();
105
106 void DrawContent(nux::GraphicsEngine& gfxContext, bool forceDraw);
107@@ -56,11 +59,16 @@
108 bool InspectKeyEvent(unsigned int event_type, unsigned int keysym, const char* character);
109 bool AcceptKeyNavFocus();
110
111+ virtual bool DrawContentOnNuxLayer() const;
112+
113 private:
114 void StartAnimation();
115 bool OnAnimationTimeout();
116 void CancelDrag();
117
118+ bool icon_rendered_;
119+ std::function<void(nux::GraphicsEngine &)> deferred_icon_render_func_;
120+
121 float animation_speed_;
122 bool cancelled_;
123 nux::ObjectPtr<nux::IOpenGLBaseTexture> texture_;
124
125=== modified file 'launcher/SoftwareCenterLauncherIcon.cpp'
126--- launcher/SoftwareCenterLauncherIcon.cpp 2013-04-05 19:09:21 +0000
127+++ launcher/SoftwareCenterLauncherIcon.cpp 2013-05-15 05:07:37 +0000
128@@ -21,6 +21,8 @@
129
130 #include "config.h"
131
132+#include <functional>
133+
134 #include <NuxCore/Logger.h>
135 #include <glib.h>
136 #include <glib/gi18n-lib.h>
137@@ -71,6 +73,8 @@
138
139 void SoftwareCenterLauncherIcon::Animate(nux::ObjectPtr<Launcher> const& launcher, int start_x, int start_y)
140 {
141+ using namespace std::placeholders;
142+
143 launcher_ = launcher;
144
145 // FIXME: this needs testing, if there is no useful coordinates
146@@ -87,12 +91,14 @@
147 1,
148 nux::BITFMT_R8G8B8A8);
149
150- drag_window_ = new LauncherDragWindow(icon_texture_);
151+ drag_window_ = new LauncherDragWindow(icon_texture_,
152+ std::bind (&Launcher::RenderIconToTexture,
153+ launcher.GetPointer(),
154+ _1,
155+ AbstractLauncherIcon::Ptr(this),
156+ icon_texture_));
157
158 launcher->ForceReveal(true);
159- launcher->RenderIconToTexture(nux::GetWindowThread()->GetGraphicsEngine(),
160- AbstractLauncherIcon::Ptr(this),
161- icon_texture_);
162
163 auto const& icon_center = GetCenter(launcher->monitor());
164 drag_window_->SetBaseXY(start_x, start_y);
165
166=== modified file 'tests/test_launcher_drag_window.cpp'
167--- tests/test_launcher_drag_window.cpp 2013-01-24 03:17:58 +0000
168+++ tests/test_launcher_drag_window.cpp 2013-05-15 05:07:37 +0000
169@@ -17,6 +17,8 @@
170 * Authored by: Marco Trevisan (Treviño) <marco.trevisan@canonical.com>
171 */
172
173+#include <functional>
174+
175 #include <gmock/gmock.h>
176
177 #include "LauncherDragWindow.h"
178@@ -35,14 +37,39 @@
179 {
180 namespace launcher
181 {
182+class StubLauncherDragWindow : public LauncherDragWindow
183+{
184+ public:
185+
186+ StubLauncherDragWindow(nux::ObjectPtr<nux::IOpenGLBaseTexture> const &texture,
187+ std::function<void(nux::GraphicsEngine&)> const &callback)
188+ : LauncherDragWindow(texture, callback)
189+ {}
190+
191+ protected:
192+
193+ bool DrawContentOnNuxLayer() const { return false; }
194+};
195+
196 struct TestLauncherDragWindow : public testing::Test
197 {
198 TestLauncherDragWindow()
199- : drag_window(new LauncherDragWindow(nux::ObjectPtr<nux::IOpenGLBaseTexture>(new nux::IOpenGLBaseTexture(nux::RTTEXTURE, ICON_WIDTH, ICON_HEIGHT, 24, 1, nux::BITFMT_B8G8R8A8))))
200+ : texture(new nux::IOpenGLBaseTexture(nux::RTTEXTURE, ICON_WIDTH, ICON_HEIGHT, 24, 1, nux::BITFMT_R8G8B8A8))
201+ , drag_window(new LauncherDragWindow(texture,
202+ [](nux::GraphicsEngine &){
203+ }))
204 {}
205
206+ nux::ObjectPtr<nux::IOpenGLBaseTexture> texture;
207 nux::ObjectPtr<LauncherDragWindow> drag_window;
208 };
209+
210+class DrawCallback
211+{
212+ public:
213+
214+ MOCK_METHOD0(callback, void());
215+};
216 }
217
218 TEST_F(TestLauncherDragWindow, Construction)
219@@ -53,6 +80,44 @@
220 EXPECT_FALSE(drag_window->Cancelled());
221 }
222
223+TEST_F(TestLauncherDragWindow, NoDrawOnConstruction)
224+{
225+ DrawCallback cb;
226+
227+ EXPECT_CALL(cb, callback()).Times(0);
228+
229+ drag_window.Adopt(new StubLauncherDragWindow (texture,
230+ std::bind(&DrawCallback::callback,
231+ &cb)));
232+}
233+
234+TEST_F(TestLauncherDragWindow, DrawOnFirstPaint)
235+{
236+ DrawCallback cb;
237+
238+ drag_window.Adopt(new StubLauncherDragWindow (texture,
239+ std::bind(&DrawCallback::callback,
240+ &cb)));
241+
242+ EXPECT_CALL(cb, callback()).Times(1);
243+
244+ drag_window->DrawContent(*(nux::GetGraphicsDisplay()->GetGraphicsEngine()), false);
245+}
246+
247+TEST_F(TestLauncherDragWindow, NoDrawOnSecondPaint)
248+{
249+ DrawCallback cb;
250+
251+ drag_window.Adopt(new StubLauncherDragWindow (texture,
252+ std::bind(&DrawCallback::callback,
253+ &cb)));
254+
255+ EXPECT_CALL(cb, callback()).Times(1);
256+
257+ drag_window->DrawContent(*(nux::GetGraphicsDisplay()->GetGraphicsEngine()), false);
258+ drag_window->DrawContent(*(nux::GetGraphicsDisplay()->GetGraphicsEngine()), false);
259+}
260+
261 TEST_F(TestLauncherDragWindow, EscapeRequestsCancellation)
262 {
263 nux::Event cancel;