Merge lp:~linaro-graphics-wg/glmark2/desktop-shadow into lp:glmark2/2011.11

Proposed by Alexandros Frantzis
Status: Merged
Approved by: Jesse Barker
Approved revision: 153
Merged at revision: 155
Proposed branch: lp:~linaro-graphics-wg/glmark2/desktop-shadow
Merge into: lp:glmark2/2011.11
Diff against target: 276 lines (+178/-11)
1 file modified
src/scene-desktop.cpp (+178/-11)
To merge this branch: bzr merge lp:~linaro-graphics-wg/glmark2/desktop-shadow
Reviewer Review Type Date Requested Status
Jesse Barker Approve
Review via email: mp+79268@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Jesse Barker (jesse-barker) wrote :
Download full text (10.9 KiB)

On Thu, Oct 13, 2011 at 5:33 AM, Alexandros Frantzis <email address hidden> wrote:
> Alexandros Frantzis has proposed merging lp:~linaro-graphics-wg/glmark2/desktop-shadow into lp:glmark2.
>
> Requested reviews:
>  Jesse Barker (jesse-barker)
>
> For more details, see:
> https://code.launchpad.net/~linaro-graphics-wg/glmark2/desktop-shadow/+merge/79268
> --
> https://code.launchpad.net/~linaro-graphics-wg/glmark2/desktop-shadow/+merge/79268
> You are requested to review the proposed merge of lp:~linaro-graphics-wg/glmark2/desktop-shadow into lp:glmark2.
>
> === added file 'data/textures/desktop-shadow-corner.png'
> Binary files data/textures/desktop-shadow-corner.png    1970-01-01 00:00:00 +0000 and data/textures/desktop-shadow-corner.png   2011-10-13 12:32:25 +0000 differ
> === added file 'data/textures/desktop-shadow.png'
> Binary files data/textures/desktop-shadow.png   1970-01-01 00:00:00 +0000 and data/textures/desktop-shadow.png  2011-10-13 12:32:25 +0000 differ
> === modified file 'src/scene-desktop.cpp'
> --- src/scene-desktop.cpp       2011-09-21 15:00:40 +0000
> +++ src/scene-desktop.cpp       2011-10-13 12:32:25 +0000
> @@ -104,7 +104,7 @@
>  class RenderObject
>  {
>  public:
> -    RenderObject() : texture_(0), fbo_(0) { }
> +    RenderObject() : texture_(0), fbo_(0), rotation_rad_(0) { }
>
>     virtual ~RenderObject() { release(); }
>
> @@ -199,17 +199,29 @@
>
>     virtual void render_to(RenderObject& target, Program& program = main_program)
>     {
> -        LibMatrix::vec2 final_pos(pos_ + size_);
> -        LibMatrix::vec2 ll(target.normalize_position(pos_));
> -        LibMatrix::vec2 ur(target.normalize_position(final_pos));
> +        LibMatrix::vec2 anchor(pos_);
> +        LibMatrix::vec2 ll(pos_ - anchor);
> +        LibMatrix::vec2 ur(pos_ + size_ - anchor);
>
> +        /* Calculate new position according to rotation value */
>         GLfloat position[2 * 4] = {
> -            ll.x(), ll.y(),
> -            ur.x(), ll.y(),
> -            ll.x(), ur.y(),
> -            ur.x(), ur.y(),
> +            rotate_x(ll.x(), ll.y()) + anchor.x(), rotate_y(ll.x(), ll.y()) + anchor.y(),
> +            rotate_x(ur.x(), ll.y()) + anchor.x(), rotate_y(ur.x(), ll.y()) + anchor.y(),
> +            rotate_x(ll.x(), ur.y()) + anchor.x(), rotate_y(ll.x(), ur.y()) + anchor.y(),
> +            rotate_x(ur.x(), ur.y()) + anchor.x(), rotate_y(ur.x(), ur.y()) + anchor.y(),
>         };
>
> +        /* Normalize position and write back to array */
> +        for (int i = 0; i < 4; i++) {
> +            const LibMatrix::vec2& v2(
> +                    target.normalize_position(
> +                        LibMatrix::vec2(position[2 * i], position[2 * i + 1])
> +                        )
> +                    );
> +            position[2 * i] = v2.x();
> +            position[2 * i + 1] = v2.y();
> +        }
> +
>         static const GLfloat texcoord[2 * 4] = {
>             0.0, 0.0,
>             1.0, 0.0,
> @@ -251,7 +263,7 @@
>     /**
>      * Normalizes a position from [0, size] to [-1.0, 1.0]
>      */
> -    LibMatrix::vec2 normalize_position(LibMatrix::vec2& pos)
> +    LibMatrix::vec2 normalize_position(const LibMatrix::vec2& pos)
...

Revision history for this message
Jesse Barker (jesse-barker) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'data/textures/desktop-shadow-corner.png'
2Binary files data/textures/desktop-shadow-corner.png 1970-01-01 00:00:00 +0000 and data/textures/desktop-shadow-corner.png 2011-10-13 12:32:25 +0000 differ
3=== added file 'data/textures/desktop-shadow.png'
4Binary files data/textures/desktop-shadow.png 1970-01-01 00:00:00 +0000 and data/textures/desktop-shadow.png 2011-10-13 12:32:25 +0000 differ
5=== modified file 'src/scene-desktop.cpp'
6--- src/scene-desktop.cpp 2011-09-21 15:00:40 +0000
7+++ src/scene-desktop.cpp 2011-10-13 12:32:25 +0000
8@@ -104,7 +104,7 @@
9 class RenderObject
10 {
11 public:
12- RenderObject() : texture_(0), fbo_(0) { }
13+ RenderObject() : texture_(0), fbo_(0), rotation_rad_(0) { }
14
15 virtual ~RenderObject() { release(); }
16
17@@ -199,17 +199,29 @@
18
19 virtual void render_to(RenderObject& target, Program& program = main_program)
20 {
21- LibMatrix::vec2 final_pos(pos_ + size_);
22- LibMatrix::vec2 ll(target.normalize_position(pos_));
23- LibMatrix::vec2 ur(target.normalize_position(final_pos));
24+ LibMatrix::vec2 anchor(pos_);
25+ LibMatrix::vec2 ll(pos_ - anchor);
26+ LibMatrix::vec2 ur(pos_ + size_ - anchor);
27
28+ /* Calculate new position according to rotation value */
29 GLfloat position[2 * 4] = {
30- ll.x(), ll.y(),
31- ur.x(), ll.y(),
32- ll.x(), ur.y(),
33- ur.x(), ur.y(),
34+ rotate_x(ll.x(), ll.y()) + anchor.x(), rotate_y(ll.x(), ll.y()) + anchor.y(),
35+ rotate_x(ur.x(), ll.y()) + anchor.x(), rotate_y(ur.x(), ll.y()) + anchor.y(),
36+ rotate_x(ll.x(), ur.y()) + anchor.x(), rotate_y(ll.x(), ur.y()) + anchor.y(),
37+ rotate_x(ur.x(), ur.y()) + anchor.x(), rotate_y(ur.x(), ur.y()) + anchor.y(),
38 };
39
40+ /* Normalize position and write back to array */
41+ for (int i = 0; i < 4; i++) {
42+ const LibMatrix::vec2& v2(
43+ target.normalize_position(
44+ LibMatrix::vec2(position[2 * i], position[2 * i + 1])
45+ )
46+ );
47+ position[2 * i] = v2.x();
48+ position[2 * i + 1] = v2.y();
49+ }
50+
51 static const GLfloat texcoord[2 * 4] = {
52 0.0, 0.0,
53 1.0, 0.0,
54@@ -251,7 +263,7 @@
55 /**
56 * Normalizes a position from [0, size] to [-1.0, 1.0]
57 */
58- LibMatrix::vec2 normalize_position(LibMatrix::vec2& pos)
59+ LibMatrix::vec2 normalize_position(const LibMatrix::vec2& pos)
60 {
61 return pos * 2.0 / size_ - 1.0;
62 }
63@@ -259,11 +271,15 @@
64 /**
65 * Normalizes a position from [0, size] to [0.0, 1.0]
66 */
67- LibMatrix::vec2 normalize_texcoord(LibMatrix::vec2& pos)
68+ LibMatrix::vec2 normalize_texcoord(const LibMatrix::vec2& pos)
69 {
70 return pos / size_;
71 }
72
73+ void rotation(float degrees)
74+ {
75+ rotation_rad_ = (M_PI * degrees / 180.0);
76+ }
77
78 protected:
79 void draw_quad_with_program(const GLfloat *position, const GLfloat *texcoord,
80@@ -298,6 +314,17 @@
81 GLuint fbo_;
82
83 private:
84+ float rotate_x(float x, float y)
85+ {
86+ return x * cos(rotation_rad_) - y * sin(rotation_rad_);
87+ }
88+
89+ float rotate_y(float x, float y)
90+ {
91+ return x * sin(rotation_rad_) + y * cos(rotation_rad_);
92+ }
93+
94+ float rotation_rad_;
95 static int use_count;
96
97 };
98@@ -550,8 +577,138 @@
99
100 };
101
102+/**
103+ * A RenderObject that draws a drop shadow around the window.
104+ */
105+class RenderWindowShadow : public RenderObject
106+{
107+public:
108+ using RenderObject::size;
109+
110+ RenderWindowShadow(unsigned int shadow_size, bool draw_contents = true) :
111+ RenderObject(), shadow_size_(shadow_size), draw_contents_(draw_contents) {}
112+
113+ virtual void init()
114+ {
115+ RenderObject::init();
116+
117+ /*
118+ * Only have one instance of the resources.
119+ * This works only if all windows have the same size, which
120+ * is currently the case for this scene. If this condition
121+ * ceases to be true we will need to create the resources per
122+ * object.
123+ */
124+ if (RenderWindowShadow::use_count == 0) {
125+ shadow_h_.init();
126+ shadow_v_.init();
127+ shadow_corner_.init();
128+ if (draw_contents_)
129+ window_contents_.init();
130+ }
131+
132+ RenderWindowShadow::use_count++;
133+ }
134+
135+ virtual void release()
136+ {
137+ RenderWindowShadow::use_count--;
138+
139+ /* Only have one instance of the data */
140+ if (RenderWindowShadow::use_count == 0) {
141+ shadow_h_.release();
142+ shadow_v_.release();
143+ shadow_corner_.release();
144+ if (draw_contents_)
145+ if (draw_contents_)
146+ window_contents_.release();
147+ }
148+
149+ RenderObject::release();
150+ }
151+
152+ virtual void size(const LibMatrix::vec2& size)
153+ {
154+ RenderObject::size(size);
155+ shadow_h_.size(LibMatrix::vec2(size.x() - shadow_size_,
156+ static_cast<double>(shadow_size_)));
157+ shadow_v_.size(LibMatrix::vec2(size.y() - shadow_size_,
158+ static_cast<double>(shadow_size_)));
159+ shadow_corner_.size(LibMatrix::vec2(static_cast<double>(shadow_size_),
160+ static_cast<double>(shadow_size_)));
161+ if (draw_contents_)
162+ window_contents_.size(size);
163+ }
164+
165+ virtual void render_to(RenderObject& target, Program& program)
166+ {
167+ (void)program;
168+
169+ glEnable(GL_BLEND);
170+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
171+
172+ /* Bottom shadow */
173+ shadow_h_.rotation(0.0);
174+ shadow_h_.position(position() +
175+ LibMatrix::vec2(shadow_size_,
176+ -shadow_h_.size().y()));
177+ shadow_h_.render_to(target);
178+
179+ /* Right shadow */
180+ shadow_v_.rotation(90.0);
181+ shadow_v_.position(position() +
182+ LibMatrix::vec2(size().x() + shadow_v_.size().y(), 0.0));
183+ shadow_v_.render_to(target);
184+
185+ /* Bottom right shadow */
186+ shadow_corner_.rotation(0.0);
187+ shadow_corner_.position(position() +
188+ LibMatrix::vec2(size().x(),
189+ -shadow_corner_.size().y()));
190+ shadow_corner_.render_to(target);
191+
192+ /* Top right shadow */
193+ shadow_corner_.rotation(90.0);
194+ shadow_corner_.position(position() + size() +
195+ LibMatrix::vec2(shadow_corner_.size().x(),
196+ -shadow_corner_.size().y()));
197+ shadow_corner_.render_to(target);
198+
199+ /* Bottom left shadow */
200+ shadow_corner_.rotation(-90.0);
201+ shadow_corner_.position(position());
202+ shadow_corner_.render_to(target);
203+
204+ /*
205+ * Blend the window contents with the target texture.
206+ */
207+ if (draw_contents_) {
208+ window_contents_.position(position());
209+ window_contents_.render_to(target);
210+ }
211+
212+ glDisable(GL_BLEND);
213+ }
214+
215+private:
216+ unsigned int shadow_size_;
217+ bool draw_contents_;
218+
219+ static int use_count;
220+ static RenderClearImage window_contents_;
221+ static RenderClearImage shadow_h_;
222+ static RenderClearImage shadow_v_;
223+ static RenderClearImage shadow_corner_;
224+
225+};
226+
227 int RenderWindowBlur::use_count = 0;
228 RenderClearImage RenderWindowBlur::window_contents_(GLMARK_DATA_PATH"/textures/desktop-window.png");
229+int RenderWindowShadow::use_count = 0;
230+RenderClearImage RenderWindowShadow::window_contents_(GLMARK_DATA_PATH"/textures/desktop-window.png");
231+RenderClearImage RenderWindowShadow::shadow_h_(GLMARK_DATA_PATH"/textures/desktop-shadow.png");
232+RenderClearImage RenderWindowShadow::shadow_v_(GLMARK_DATA_PATH"/textures/desktop-shadow.png");
233+RenderClearImage RenderWindowShadow::shadow_corner_(GLMARK_DATA_PATH"/textures/desktop-shadow-corner.png");
234
235 /*******************************
236 * SceneDesktop implementation *
237@@ -591,6 +748,8 @@
238 "the blur effect radius (in pixels)");
239 mOptions["separable"] = Scene::Option("separable", "true",
240 "use separable convolution for the blur effect");
241+ mOptions["shadow-size"] = Scene::Option("shadow-size", "20",
242+ "the size of the shadow (in pixels)");
243 }
244
245 SceneDesktop::~SceneDesktop()
246@@ -619,6 +778,7 @@
247 unsigned int passes(0);
248 unsigned int blur_radius(0);
249 float window_size_factor(0.0);
250+ unsigned int shadow_size(0);
251 bool separable(mOptions["separable"].value == "true");
252
253 ss << mOptions["windows"].value;
254@@ -632,6 +792,9 @@
255 ss.clear();
256 ss << mOptions["blur-radius"].value;
257 ss >> blur_radius;
258+ ss.clear();
259+ ss << mOptions["shadow-size"].value;
260+ ss >> shadow_size;
261
262 /* Ensure we get a transparent clear color for all following operations */
263 glClearColor(0.0, 0.0, 0.0, 0.0);
264@@ -654,7 +817,11 @@
265 for (unsigned int i = 0; i < windows; i++) {
266 LibMatrix::vec2 center(mCanvas.width() * (0.5 + 0.25 * cos(i * angular_step)),
267 mCanvas.height() * (0.5 + 0.25 * sin(i * angular_step)));
268- RenderObject* win(new RenderWindowBlur(passes, blur_radius, separable));
269+ RenderObject* win;
270+ if (mOptions["effect"].value == "shadow")
271+ win = new RenderWindowShadow(shadow_size);
272+ else
273+ win = new RenderWindowBlur(passes, blur_radius, separable);
274 (void)angular_step;
275
276 win->init();

Subscribers

People subscribed via source and target branches