Merge lp:~cimi/unity/unity.use-gtk3-style-context into lp:unity

Proposed by Andrea Cimitan
Status: Merged
Merged at revision: 1269
Proposed branch: lp:~cimi/unity/unity.use-gtk3-style-context
Merge into: lp:unity
Diff against target: 453 lines (+119/-188)
6 files modified
plugins/unityshell/src/PanelHomeButton.cpp (+2/-18)
plugins/unityshell/src/PanelIndicatorObjectEntryView.cpp (+43/-101)
plugins/unityshell/src/PanelMenuView.cpp (+26/-7)
plugins/unityshell/src/PanelStyle.cpp (+40/-48)
plugins/unityshell/src/PanelStyle.h (+3/-11)
plugins/unityshell/src/PanelView.cpp (+5/-3)
To merge this branch: bzr merge lp:~cimi/unity/unity.use-gtk3-style-context
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+66622@code.launchpad.net

Description of the change

First WIP of pure gtk+3 rendering

To post a comment you must log in.
Revision history for this message
Andrea Cimitan (cimi) wrote :

Visually looks perfect, but selecting widgets on the menubar is pretty slow. Need to profile unity and see where the slowdown comes from

Revision history for this message
Neil J. Patel (njpatel) wrote :

Awesome work dude, merging now!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/PanelHomeButton.cpp'
2--- plugins/unityshell/src/PanelHomeButton.cpp 2011-06-21 12:10:09 +0000
3+++ plugins/unityshell/src/PanelHomeButton.cpp 2011-07-01 17:47:29 +0000
4@@ -133,7 +133,6 @@
5 int width = _button_width;
6 int height = PANEL_HEIGHT;
7 GdkPixbuf *pixbuf;
8- GdkPixbuf *overlay;
9
10 SetMinMaxSize (_button_width, PANEL_HEIGHT);
11
12@@ -142,23 +141,8 @@
13 cairo_set_line_width (cr, 1);
14
15 /* button pressed effect */
16- if (_pressed) {
17- if (PanelStyle::GetDefault ()->IsAmbianceOrRadiance () && _opacity == 1.0f) {
18- /* loads background panel upside-down */
19- overlay = gdk_pixbuf_flip (PanelStyle::GetDefault ()->GetBackground (width - 2, height), FALSE);
20- if (GDK_IS_PIXBUF (overlay)) {
21- gdk_cairo_set_source_pixbuf (cr, overlay, 0, 0);
22- cairo_paint (cr);
23- g_object_unref (overlay);
24- }
25- } else {
26- /* draws an translucent overlay */
27- cairo_set_source_rgba (cr, 0.0f, 0.0f, 0.0f, 0.3f);
28- cairo_rectangle (cr, 0, 0, width-1, height);
29- cairo_fill (cr);
30- }
31- }
32-
33+ //FIXME(Cimi) removed the pressed effect
34+
35 pixbuf = PanelStyle::GetDefault ()->GetHomeButton ();
36 if (GDK_IS_PIXBUF (pixbuf))
37 {
38
39=== modified file 'plugins/unityshell/src/PanelIndicatorObjectEntryView.cpp'
40--- plugins/unityshell/src/PanelIndicatorObjectEntryView.cpp 2011-06-29 15:40:49 +0000
41+++ plugins/unityshell/src/PanelIndicatorObjectEntryView.cpp 2011-07-01 17:47:29 +0000
42@@ -147,10 +147,6 @@
43 int text_width = 0;
44 int text_height = 0;
45
46- PanelStyle *style = PanelStyle::GetDefault ();
47- nux::Color textcol = style->GetTextColor ();
48- nux::Color textshadowcol = style->GetTextShadow ();
49-
50 if (proxy_->show_now())
51 {
52 if (!pango_parse_markup (label.c_str(),
53@@ -246,25 +242,28 @@
54 {
55 pango_cairo_update_layout (cr, layout);
56
57- // Once for the homies that couldn't be here
58- cairo_set_source_rgba (cr,
59- textshadowcol.red,
60- textshadowcol.green,
61- textshadowcol.blue,
62- 1.0f - textshadowcol.red);
63- cairo_move_to (cr, x, (int)(((height - text_height)/2)+1));
64- pango_cairo_show_layout (cr, layout);
65- cairo_stroke (cr);
66-
67- // Once again for the homies that could
68- cairo_set_source_rgba (cr,
69- textcol.red,
70- textcol.green,
71- textcol.blue,
72- proxy_->label_sensitive() ? 1.0f : 0.5f);
73- cairo_move_to (cr, x, (int)((height - text_height)/2));
74- pango_cairo_show_layout (cr, layout);
75- cairo_stroke (cr);
76+ PanelStyle *style = PanelStyle::GetDefault ();
77+ GtkStyleContext *style_context = style->GetStyleContext ();
78+
79+ gtk_style_context_save (style_context);
80+
81+ GtkWidgetPath *widget_path = gtk_widget_path_new ();
82+ gtk_widget_path_iter_set_name (widget_path, -1 , "UnityPanelWidget");
83+ gtk_widget_path_append_type (widget_path, GTK_TYPE_MENU_BAR);
84+ gtk_widget_path_append_type (widget_path, GTK_TYPE_MENU_ITEM);
85+
86+ gtk_style_context_set_path (style_context, widget_path);
87+ gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENUBAR);
88+ gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENUITEM);
89+
90+ if (proxy_->active())
91+ gtk_style_context_set_state (style_context, GTK_STATE_FLAG_PRELIGHT);
92+
93+ gtk_render_layout (style_context, cr, x, (int)((height - text_height)/2), layout);
94+
95+ gtk_widget_path_free (widget_path);
96+
97+ gtk_style_context_restore (style_context);
98 }
99
100 cairo_destroy (cr);
101@@ -362,85 +361,28 @@
102
103 void draw_menu_bg(cairo_t* cr, int width, int height)
104 {
105- int radius = 4;
106- double x = 0;
107- double y = 0;
108- double xos = 0.5;
109- double yos = 0.5;
110- /* FIXME */
111- double mpi = 3.14159265358979323846;
112-
113 PanelStyle *style = PanelStyle::GetDefault ();
114- nux::Color bgtop = style->GetBackgroundTop ();
115- nux::Color bgbot = style->GetBackgroundBottom ();
116- nux::Color line = style->GetLineColor ();
117-
118- cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
119-
120- cairo_set_line_width (cr, 1.0);
121-
122- cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.2);
123-
124- cairo_move_to (cr, x+xos+radius, y+yos);
125- cairo_arc (cr, x+xos+width-xos*2-radius, y+yos+radius, radius, mpi*1.5, mpi*2);
126- cairo_line_to (cr, x+xos+width-xos*2, y+yos+height-yos*2+2);
127- cairo_line_to (cr, x+xos, y+yos+height-yos*2+2);
128- cairo_arc (cr, x+xos+radius, y+yos+radius, radius, mpi, mpi*1.5);
129-
130- cairo_pattern_t * pat = cairo_pattern_create_linear (x+xos, y, x+xos, y+height-yos*2+2);
131- cairo_pattern_add_color_stop_rgba (pat, 0.0,
132- bgtop.red,
133- bgtop.green,
134- bgtop.blue,
135- 1.0f - bgbot.red);
136- cairo_pattern_add_color_stop_rgba (pat, 1.0,
137- bgbot.red,
138- bgbot.green,
139- bgbot.blue,
140- 1.0f - bgtop.red);
141- cairo_set_source (cr, pat);
142- cairo_fill_preserve (cr);
143- cairo_pattern_destroy (pat);
144-
145- pat = cairo_pattern_create_linear (x+xos, y, x+xos, y+height-yos*2+2);
146- cairo_pattern_add_color_stop_rgba (pat, 0.0,
147- line.red,
148- line.green,
149- line.blue,
150- 1.0f);
151- cairo_pattern_add_color_stop_rgba (pat, 1.0,
152- line.red,
153- line.green,
154- line.blue,
155- 1.0f);
156- cairo_set_source (cr, pat);
157- cairo_stroke (cr);
158- cairo_pattern_destroy (pat);
159-
160- xos++;
161- yos++;
162-
163- /* enlarging the area to not draw the lightborder at bottom, ugly trick :P */
164- cairo_move_to (cr, x+radius+xos, y+yos);
165- cairo_arc (cr, x+xos+width-xos*2-radius, y+yos+radius, radius, mpi*1.5, mpi*2);
166- cairo_line_to (cr, x+xos+width-xos*2, y+yos+height-yos*2+3);
167- cairo_line_to (cr, x+xos, y+yos+height-yos*2+3);
168- cairo_arc (cr, x+xos+radius, y+yos+radius, radius, mpi, mpi*1.5);
169-
170- pat = cairo_pattern_create_linear (x+xos, y, x+xos, y+height-yos*2+3);
171- cairo_pattern_add_color_stop_rgba (pat, 0.0,
172- bgbot.red,
173- bgbot.green,
174- bgbot.blue,
175- 1.0f);
176- cairo_pattern_add_color_stop_rgba (pat, 1.0,
177- bgbot.red,
178- bgbot.green,
179- bgbot.blue,
180- 1.0f);
181- cairo_set_source (cr, pat);
182- cairo_stroke (cr);
183- cairo_pattern_destroy (pat);
184+ GtkStyleContext *style_context = style->GetStyleContext ();
185+
186+ gtk_style_context_save (style_context);
187+
188+ GtkWidgetPath *widget_path = gtk_widget_path_new ();
189+ gtk_widget_path_iter_set_name (widget_path, -1 , "UnityPanelWidget");
190+ gtk_widget_path_append_type (widget_path, GTK_TYPE_MENU_BAR);
191+ gtk_widget_path_append_type (widget_path, GTK_TYPE_MENU_ITEM);
192+
193+ gtk_style_context_set_path (style_context, widget_path);
194+ gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENUBAR);
195+ gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENUITEM);
196+ gtk_style_context_set_state (style_context, GTK_STATE_FLAG_PRELIGHT);
197+
198+ // FIXME(Cimi) probably some padding is needed here.
199+ gtk_render_background (style_context, cr, 0, 0, width, height);
200+ gtk_render_frame (style_context, cr, 0, 0, width, height);
201+
202+ gtk_widget_path_free (widget_path);
203+
204+ gtk_style_context_restore (style_context);
205 }
206
207 GdkPixbuf* make_pixbuf(int image_type, std::string const& image_data)
208
209=== modified file 'plugins/unityshell/src/PanelMenuView.cpp'
210--- plugins/unityshell/src/PanelMenuView.cpp 2011-06-21 12:29:49 +0000
211+++ plugins/unityshell/src/PanelMenuView.cpp 2011-07-01 17:47:29 +0000
212@@ -578,10 +578,26 @@
213
214 if (label)
215 {
216- nux::Color const& col = PanelStyle::GetDefault ()->GetTextColor();
217- float red = col.red;
218- float green = col.green;
219- float blue = col.blue;
220+ PanelStyle *style = PanelStyle::GetDefault ();
221+ GtkStyleContext *style_context = style->GetStyleContext ();
222+
223+ gtk_style_context_save (style_context);
224+
225+ GtkWidgetPath *widget_path = gtk_widget_path_new ();
226+ gtk_widget_path_iter_set_name (widget_path, -1 , "UnityPanelWidget");
227+ gtk_widget_path_append_type (widget_path, GTK_TYPE_MENU_BAR);
228+ gtk_widget_path_append_type (widget_path, GTK_TYPE_MENU_ITEM);
229+
230+ gtk_style_context_set_path (style_context, widget_path);
231+ gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENUBAR);
232+ gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_MENUITEM);
233+
234+ GdkRGBA rgba_text;
235+ gtk_style_context_get_color (style_context, GTK_STATE_FLAG_NORMAL, &rgba_text);
236+
237+ float red = rgba_text.red;
238+ float green = rgba_text.green;
239+ float blue = rgba_text.blue;
240
241 pango_cairo_update_layout (cr, layout);
242
243@@ -602,9 +618,12 @@
244 {
245 cairo_set_source_rgb (cr, red, green, blue);
246 }
247- cairo_move_to (cr, x, y);
248- pango_cairo_show_layout (cr, layout);
249- cairo_stroke (cr);
250+
251+ gtk_render_layout (style_context, cr, x, y, layout);
252+
253+ gtk_widget_path_free (widget_path);
254+
255+ gtk_style_context_restore (style_context);
256 }
257
258 cairo_destroy (cr);
259
260=== modified file 'plugins/unityshell/src/PanelStyle.cpp'
261--- plugins/unityshell/src/PanelStyle.cpp 2011-06-20 21:39:32 +0000
262+++ plugins/unityshell/src/PanelStyle.cpp 2011-07-01 17:47:29 +0000
263@@ -32,11 +32,12 @@
264
265 PanelStyle *_style = NULL;
266
267-nux::Color ColorFromGdkColor(GdkColor const& gc)
268+nux::Color ColorFromGdkRGBA(GdkRGBA const& color)
269 {
270- return nux::Color(gc.red / static_cast<float>(0xffff),
271- gc.green / static_cast<float>(0xffff),
272- gc.blue / static_cast<float>(0xffff));
273+ return nux::Color(color.red,
274+ color.green,
275+ color.blue,
276+ color.alpha);
277 }
278
279 }
280@@ -44,12 +45,17 @@
281 PanelStyle::PanelStyle ()
282 : _theme_name (NULL)
283 {
284- _offscreen = gtk_offscreen_window_new ();
285- gtk_widget_set_name (_offscreen, "UnityPanelWidget");
286- gtk_widget_set_size_request (_offscreen, 100, 24);
287- gtk_style_context_add_class (gtk_widget_get_style_context (_offscreen),
288- "menubar");
289- gtk_widget_show_all (_offscreen);
290+ _style_context = gtk_style_context_new ();
291+
292+ GtkWidgetPath *widget_path = gtk_widget_path_new ();
293+ gtk_widget_path_iter_set_name (widget_path, -1 , "UnityPanelWidget");
294+ gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW);
295+
296+ gtk_style_context_set_path (_style_context, widget_path);
297+ gtk_style_context_add_class (_style_context, "gnome-panel-menu-bar");
298+ gtk_style_context_add_class (_style_context, "unity-panel");
299+
300+ gtk_widget_path_free (widget_path);
301
302 _gtk_theme_changed_id = g_signal_connect (gtk_settings_get_default (), "notify::gtk-theme-name",
303 G_CALLBACK (PanelStyle::OnStyleChanged), this);
304@@ -62,8 +68,8 @@
305 if (_gtk_theme_changed_id)
306 g_signal_handler_disconnect (gtk_settings_get_default (),
307 _gtk_theme_changed_id);
308-
309- gtk_widget_destroy (_offscreen);
310+
311+ g_object_unref (_style_context);
312
313 if (_style == this)
314 _style = NULL;
315@@ -83,7 +89,7 @@
316 void
317 PanelStyle::Refresh ()
318 {
319- GtkStyle* style = NULL;
320+ GdkRGBA rgba_text;
321
322 if (_theme_name)
323 g_free (_theme_name);
324@@ -91,40 +97,19 @@
325 _theme_name = NULL;
326 g_object_get (gtk_settings_get_default (), "gtk-theme-name", &_theme_name, NULL);
327
328- style = gtk_widget_get_style (_offscreen);
329-
330- _text = ColorFromGdkColor(style->text[0]);
331- _text_shadow = ColorFromGdkColor(style->text[3]);
332- _line = ColorFromGdkColor(style->dark[0]);
333- _bg_top = ColorFromGdkColor(style->bg[1]);
334- _bg_bottom = ColorFromGdkColor(style->bg[0]);
335+ gtk_style_context_invalidate (_style_context);
336+
337+ gtk_style_context_get_color (_style_context, GTK_STATE_FLAG_NORMAL, &rgba_text);
338+
339+ _text = ColorFromGdkRGBA (rgba_text);
340
341 changed.emit ();
342 }
343
344-nux::Color const& PanelStyle::GetTextColor() const
345-{
346- return _text;
347-}
348-
349-nux::Color const& PanelStyle::GetBackgroundTop() const
350-{
351- return _bg_top;
352-}
353-
354-nux::Color const& PanelStyle::GetBackgroundBottom() const
355-{
356- return _bg_bottom;
357-}
358-
359-nux::Color const& PanelStyle::GetTextShadow() const
360-{
361- return _text_shadow;
362-}
363-
364-nux::Color const& PanelStyle::GetLineColor() const
365-{
366- return _line;
367+GtkStyleContext *
368+PanelStyle::GetStyleContext ()
369+{
370+ return _style_context;
371 }
372
373 void
374@@ -137,13 +122,20 @@
375 self->Refresh ();
376 }
377
378-GdkPixbuf *
379+nux::NBitmapData *
380 PanelStyle::GetBackground (int width, int height)
381 {
382- gtk_widget_set_size_request (_offscreen, width, height);
383- gdk_window_process_updates (gtk_widget_get_window (_offscreen), TRUE);
384-
385- return gtk_offscreen_window_get_pixbuf (GTK_OFFSCREEN_WINDOW (_offscreen));
386+ nux::CairoGraphics* context = new nux::CairoGraphics (CAIRO_FORMAT_ARGB32, width, height);
387+
388+ cairo_t* cr = context->GetContext ();
389+
390+ gtk_render_background (_style_context, cr, 0, 0, width, height);
391+
392+ nux::NBitmapData* bitmap = context->GetBitmap ();
393+
394+ delete context;
395+
396+ return bitmap;
397 }
398
399 nux::BaseTexture *
400
401=== modified file 'plugins/unityshell/src/PanelStyle.h'
402--- plugins/unityshell/src/PanelStyle.h 2011-05-13 02:38:16 +0000
403+++ plugins/unityshell/src/PanelStyle.h 2011-07-01 17:47:29 +0000
404@@ -48,13 +48,9 @@
405 PanelStyle ();
406 ~PanelStyle ();
407
408- nux::Color const& GetTextColor() const;
409- nux::Color const& GetBackgroundTop() const;
410- nux::Color const& GetBackgroundBottom() const;
411- nux::Color const& GetTextShadow() const;
412- nux::Color const& GetLineColor() const;
413+ GtkStyleContext * GetStyleContext ();
414
415- GdkPixbuf * GetBackground (int width, int height);
416+ nux::NBitmapData * GetBackground (int width, int height);
417
418 nux::BaseTexture * GetWindowButton (WindowButtonType type, WindowState state);
419
420@@ -71,13 +67,9 @@
421 gpointer data);
422 nux::BaseTexture * GetWindowButtonForTheme (WindowButtonType type, WindowState state);
423 private:
424- GtkWidget *_offscreen;
425+ GtkStyleContext *_style_context;
426 char *_theme_name;
427 nux::Color _text;
428- nux::Color _bg_top;
429- nux::Color _bg_bottom;
430- nux::Color _text_shadow;
431- nux::Color _line;
432
433 gulong _gtk_theme_changed_id;
434 };
435
436=== modified file 'plugins/unityshell/src/PanelView.cpp'
437--- plugins/unityshell/src/PanelView.cpp 2011-06-22 14:39:34 +0000
438+++ plugins/unityshell/src/PanelView.cpp 2011-07-01 17:47:29 +0000
439@@ -187,9 +187,11 @@
440 _last_height = geo.height;
441 _is_dirty = false;
442
443- GdkPixbuf *pixbuf = _style->GetBackground (geo.width, geo.height);
444- nux::BaseTexture * texture2D = nux::CreateTexture2DFromPixbuf (pixbuf, true);
445- g_object_unref (pixbuf);
446+ nux::NBitmapData * bitmap = _style->GetBackground (geo.width, geo.height);
447+ nux::BaseTexture * texture2D = nux::GetGraphicsDisplay ()->GetGpuDevice ()->CreateSystemCapableTexture ();
448+ texture2D->Update (bitmap);
449+ delete bitmap;
450+
451 nux::TexCoordXForm texxform;
452 texxform.SetTexCoordType (nux::TexCoordXForm::OFFSET_COORD);
453 texxform.SetWrap (nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);