Merge lp:~3v1n0/unity/scale-decoration-cache-6.0 into lp:unity/6.0
- scale-decoration-cache-6.0
- Merge into 6.0
Proposed by
Marco Trevisan (Treviño)
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Brandon Schaefer | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 2738 | ||||
Proposed branch: | lp:~3v1n0/unity/scale-decoration-cache-6.0 | ||||
Merge into: | lp:unity/6.0 | ||||
Prerequisite: | lp:~3v1n0/unity/scale-close-middle-click-6.0 | ||||
Diff against target: |
517 lines (+165/-131) 2 files modified
plugins/unityshell/src/unityshell.cpp (+124/-80) plugins/unityshell/src/unityshell.h (+41/-51) |
||||
To merge this branch: | bzr merge lp:~3v1n0/unity/scale-decoration-cache-6.0 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Brandon Schaefer (community) | Approve | ||
Review via email:
|
Commit message
UnityWindow: when spreading, render once an empty decoration texture at full size and scale it via OpenGL
This saves a lot of drawing and improves the performances of the unity Spread. Also, don't redraw the decoration texture for selected windows if not needed.
Finally, cleanup the header file
Description of the change
Backported branch lp:~3v1n0/unity/scale-decoration-cache/+merge/126072
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'plugins/unityshell/src/unityshell.cpp' | |||
2 | --- plugins/unityshell/src/unityshell.cpp 2012-09-24 19:42:22 +0000 | |||
3 | +++ plugins/unityshell/src/unityshell.cpp 2012-09-24 19:42:22 +0000 | |||
4 | @@ -87,9 +87,6 @@ | |||
5 | 87 | 87 | ||
6 | 88 | UnityScreen* uScreen = 0; | 88 | UnityScreen* uScreen = 0; |
7 | 89 | 89 | ||
8 | 90 | const unsigned int SCALE_CLOSE_ICON_SIZE = 19; | ||
9 | 91 | const unsigned int SCALE_ITEMS_PADDING = 5; | ||
10 | 92 | |||
11 | 93 | void reset_glib_logging(); | 90 | void reset_glib_logging(); |
12 | 94 | void configure_logging(); | 91 | void configure_logging(); |
13 | 95 | void capture_g_log_calls(const gchar* log_domain, | 92 | void capture_g_log_calls(const gchar* log_domain, |
14 | @@ -111,8 +108,8 @@ | |||
15 | 111 | } // anon namespace | 108 | } // anon namespace |
16 | 112 | 109 | ||
17 | 113 | UnityScreen::UnityScreen(CompScreen* screen) | 110 | UnityScreen::UnityScreen(CompScreen* screen) |
20 | 114 | : BaseSwitchScreen (screen) | 111 | : BaseSwitchScreen(screen) |
21 | 115 | , PluginClassHandler <UnityScreen, CompScreen> (screen) | 112 | , PluginClassHandler <UnityScreen, CompScreen>(screen) |
22 | 116 | , screen(screen) | 113 | , screen(screen) |
23 | 117 | , cScreen(CompositeScreen::get(screen)) | 114 | , cScreen(CompositeScreen::get(screen)) |
24 | 118 | , gScreen(GLScreen::get(screen)) | 115 | , gScreen(GLScreen::get(screen)) |
25 | @@ -669,7 +666,12 @@ | |||
26 | 669 | UnityWindow::CleanupSharedTextures(); | 666 | UnityWindow::CleanupSharedTextures(); |
27 | 670 | 667 | ||
28 | 671 | if (WindowManager::Default()->IsScaleActive()) | 668 | if (WindowManager::Default()->IsScaleActive()) |
29 | 669 | { | ||
30 | 672 | UnityWindow::SetupSharedTextures(); | 670 | UnityWindow::SetupSharedTextures(); |
31 | 671 | |||
32 | 672 | for (auto const& swin : ScaleScreen::get(screen)->getWindows()) | ||
33 | 673 | UnityWindow::get(swin->window)->CleanupCachedTextures(); | ||
34 | 674 | } | ||
35 | 673 | } | 675 | } |
36 | 674 | 676 | ||
37 | 675 | void UnityScreen::paintDisplay() | 677 | void UnityScreen::paintDisplay() |
38 | @@ -3380,11 +3382,23 @@ | |||
39 | 3380 | GLTexture::List UnityWindow::close_prelight_tex_; | 3382 | GLTexture::List UnityWindow::close_prelight_tex_; |
40 | 3381 | GLTexture::List UnityWindow::close_pressed_tex_; | 3383 | GLTexture::List UnityWindow::close_pressed_tex_; |
41 | 3382 | 3384 | ||
42 | 3385 | namespace scale | ||
43 | 3386 | { | ||
44 | 3387 | namespace decoration | ||
45 | 3388 | { | ||
46 | 3389 | const unsigned CLOSE_SIZE = 19; | ||
47 | 3390 | const unsigned ITEMS_PADDING = 5; | ||
48 | 3391 | const unsigned RADIUS = 8; | ||
49 | 3392 | } | ||
50 | 3393 | } | ||
51 | 3394 | |||
52 | 3383 | struct UnityWindow::CairoContext | 3395 | struct UnityWindow::CairoContext |
53 | 3384 | { | 3396 | { |
57 | 3385 | CairoContext(int width, int height) | 3397 | CairoContext(unsigned width, unsigned height) |
58 | 3386 | : pixmap_(XCreatePixmap(screen->dpy(), screen->root(), width, height, 32)) | 3398 | : w_(width) |
59 | 3387 | , texture_(GLTexture::bindPixmapToTexture(pixmap_, width, height, 32)) | 3399 | , h_(height) |
60 | 3400 | , pixmap_(XCreatePixmap(screen->dpy(), screen->root(), w_, h_, 32)) | ||
61 | 3401 | , texture_(GLTexture::bindPixmapToTexture(pixmap_, w_, h_, 32)) | ||
62 | 3388 | , surface_(nullptr) | 3402 | , surface_(nullptr) |
63 | 3389 | , cr_(nullptr) | 3403 | , cr_(nullptr) |
64 | 3390 | { | 3404 | { |
65 | @@ -3406,7 +3420,7 @@ | |||
66 | 3406 | cairo_restore(cr_); | 3420 | cairo_restore(cr_); |
67 | 3407 | } | 3421 | } |
68 | 3408 | 3422 | ||
70 | 3409 | ~CairoContext () | 3423 | ~CairoContext() |
71 | 3410 | { | 3424 | { |
72 | 3411 | if (cr_) | 3425 | if (cr_) |
73 | 3412 | cairo_destroy(cr_); | 3426 | cairo_destroy(cr_); |
74 | @@ -3414,12 +3428,12 @@ | |||
75 | 3414 | if (surface_) | 3428 | if (surface_) |
76 | 3415 | cairo_surface_destroy(surface_); | 3429 | cairo_surface_destroy(surface_); |
77 | 3416 | 3430 | ||
78 | 3417 | texture_.clear(); | ||
79 | 3418 | |||
80 | 3419 | if (pixmap_) | 3431 | if (pixmap_) |
82 | 3420 | XFreePixmap(screen->dpy (), pixmap_); | 3432 | XFreePixmap(screen->dpy(), pixmap_); |
83 | 3421 | } | 3433 | } |
84 | 3422 | 3434 | ||
85 | 3435 | unsigned w_; | ||
86 | 3436 | unsigned h_; | ||
87 | 3423 | Pixmap pixmap_; | 3437 | Pixmap pixmap_; |
88 | 3424 | GLTexture::List texture_; | 3438 | GLTexture::List texture_; |
89 | 3425 | cairo_surface_t* surface_; | 3439 | cairo_surface_t* surface_; |
90 | @@ -3478,8 +3492,8 @@ | |||
91 | 3478 | } | 3492 | } |
92 | 3479 | } | 3493 | } |
93 | 3480 | 3494 | ||
96 | 3481 | WindowManager::Default()->initiate_spread.connect(sigc::mem_fun(this, &UnityWindow::OnInitiateSpreed)); | 3495 | WindowManager::Default()->initiate_spread.connect(sigc::mem_fun(this, &UnityWindow::OnInitiateSpread)); |
97 | 3482 | WindowManager::Default()->terminate_spread.connect(sigc::mem_fun(this, &UnityWindow::OnTerminateSpreed)); | 3496 | WindowManager::Default()->terminate_spread.connect(sigc::mem_fun(this, &UnityWindow::OnTerminateSpread)); |
98 | 3483 | } | 3497 | } |
99 | 3484 | 3498 | ||
100 | 3485 | void UnityWindow::AddProperties(GVariantBuilder* builder) | 3499 | void UnityWindow::AddProperties(GVariantBuilder* builder) |
101 | @@ -3505,8 +3519,9 @@ | |||
102 | 3505 | return "Window"; | 3519 | return "Window"; |
103 | 3506 | } | 3520 | } |
104 | 3507 | 3521 | ||
105 | 3522 | |||
106 | 3508 | void UnityWindow::DrawTexture(GLTexture::List const& textures, GLWindowPaintAttrib const& attrib, | 3523 | void UnityWindow::DrawTexture(GLTexture::List const& textures, GLWindowPaintAttrib const& attrib, |
108 | 3509 | GLMatrix const& transform, unsigned int mask, int x, int y) | 3524 | GLMatrix const& transform, unsigned int mask, int x, int y, double scale) |
109 | 3510 | { | 3525 | { |
110 | 3511 | for (auto const& texture : textures) | 3526 | for (auto const& texture : textures) |
111 | 3512 | { | 3527 | { |
112 | @@ -3527,12 +3542,40 @@ | |||
113 | 3527 | { | 3542 | { |
114 | 3528 | GLMatrix wTransform(transform); | 3543 | GLMatrix wTransform(transform); |
115 | 3529 | wTransform.translate(x, y, 0.0f); | 3544 | wTransform.translate(x, y, 0.0f); |
116 | 3545 | wTransform.scale(scale, scale, 1.0f); | ||
117 | 3530 | 3546 | ||
118 | 3531 | gWindow->glDrawTexture(texture, wTransform, attrib, mask); | 3547 | gWindow->glDrawTexture(texture, wTransform, attrib, mask); |
119 | 3532 | } | 3548 | } |
120 | 3533 | } | 3549 | } |
121 | 3534 | } | 3550 | } |
122 | 3535 | 3551 | ||
123 | 3552 | void UnityWindow::RenderDecoration(CairoContext const& context, double aspect) | ||
124 | 3553 | { | ||
125 | 3554 | cairo_save(context.cr_); | ||
126 | 3555 | |||
127 | 3556 | // Draw window decoration based on gtk style | ||
128 | 3557 | cairo_push_group(context.cr_); | ||
129 | 3558 | auto& style = panel::Style::Instance(); | ||
130 | 3559 | gtk_render_background(style.GetStyleContext(), context.cr_, 0, 0, context.w_, context.h_); | ||
131 | 3560 | gtk_render_frame(style.GetStyleContext(), context.cr_, 0, 0, context.w_, context.h_); | ||
132 | 3561 | cairo_pop_group_to_source(context.cr_); | ||
133 | 3562 | |||
134 | 3563 | // Round window decoration top border | ||
135 | 3564 | const double radius = scale::decoration::RADIUS * aspect; | ||
136 | 3565 | |||
137 | 3566 | cairo_new_sub_path(context.cr_); | ||
138 | 3567 | cairo_line_to(context.cr_, 0, context.h_); | ||
139 | 3568 | cairo_arc(context.cr_, radius, radius, radius, M_PI, -M_PI * 0.5f); | ||
140 | 3569 | cairo_line_to(context.cr_, context.w_ - radius, 0); | ||
141 | 3570 | cairo_arc(context.cr_, context.w_ - radius, radius, radius, M_PI * 0.5f, 0); | ||
142 | 3571 | cairo_line_to(context.cr_, context.w_, context.h_); | ||
143 | 3572 | cairo_close_path(context.cr_); | ||
144 | 3573 | |||
145 | 3574 | cairo_fill(context.cr_); | ||
146 | 3575 | |||
147 | 3576 | cairo_restore(context.cr_); | ||
148 | 3577 | } | ||
149 | 3578 | |||
150 | 3536 | void UnityWindow::RenderText(CairoContext const& context, int x, int y, int width, int height) | 3579 | void UnityWindow::RenderText(CairoContext const& context, int x, int y, int width, int height) |
151 | 3537 | { | 3580 | { |
152 | 3538 | panel::Style& style = panel::Style::Instance(); | 3581 | panel::Style& style = panel::Style::Instance(); |
153 | @@ -3552,11 +3595,11 @@ | |||
154 | 3552 | pango_cairo_context_set_resolution(pango_ctx, dpi / static_cast<float>(PANGO_SCALE)); | 3595 | pango_cairo_context_set_resolution(pango_ctx, dpi / static_cast<float>(PANGO_SCALE)); |
155 | 3553 | pango_layout_context_changed(layout); | 3596 | pango_layout_context_changed(layout); |
156 | 3554 | 3597 | ||
158 | 3555 | std::string const& win_title = WindowManager::Default()->GetWindowName(window->id()); | 3598 | decoration_title_ = WindowManager::Default()->GetWindowName(window->id()); |
159 | 3556 | pango_layout_set_height(layout, height); | 3599 | pango_layout_set_height(layout, height); |
160 | 3557 | pango_layout_set_width(layout, -1); //avoid wrap lines | 3600 | pango_layout_set_width(layout, -1); //avoid wrap lines |
161 | 3558 | pango_layout_set_auto_dir(layout, false); | 3601 | pango_layout_set_auto_dir(layout, false); |
163 | 3559 | pango_layout_set_text(layout, win_title.c_str(), -1); | 3602 | pango_layout_set_text(layout, decoration_title_.c_str(), -1); |
164 | 3560 | 3603 | ||
165 | 3561 | /* update the size of the pango layout */ | 3604 | /* update the size of the pango layout */ |
166 | 3562 | pango_cairo_update_layout(context.cr_, layout); | 3605 | pango_cairo_update_layout(context.cr_, layout); |
167 | @@ -3578,8 +3621,8 @@ | |||
168 | 3578 | pango_layout_get_extents(layout, nullptr, &lRect); | 3621 | pango_layout_get_extents(layout, nullptr, &lRect); |
169 | 3579 | int text_width = lRect.width / PANGO_SCALE; | 3622 | int text_width = lRect.width / PANGO_SCALE; |
170 | 3580 | int text_height = lRect.height / PANGO_SCALE; | 3623 | int text_height = lRect.height / PANGO_SCALE; |
171 | 3624 | int text_space = width - x; | ||
172 | 3581 | y += (height - text_height) / 2.0f; | 3625 | y += (height - text_height) / 2.0f; |
173 | 3582 | int text_space = width - x; | ||
174 | 3583 | 3626 | ||
175 | 3584 | if (text_width > text_space) | 3627 | if (text_width > text_space) |
176 | 3585 | { | 3628 | { |
177 | @@ -3606,49 +3649,19 @@ | |||
178 | 3606 | gtk_style_context_restore(style_context); | 3649 | gtk_style_context_restore(style_context); |
179 | 3607 | } | 3650 | } |
180 | 3608 | 3651 | ||
186 | 3609 | void UnityWindow::DrawWindowDecoration(GLWindowPaintAttrib const& attrib, | 3652 | void UnityWindow::BuildDecorationTexture() |
182 | 3610 | GLMatrix const& transform, | ||
183 | 3611 | unsigned int mask, | ||
184 | 3612 | bool highlighted, | ||
185 | 3613 | int x, int y, unsigned width, unsigned height) | ||
187 | 3614 | { | 3653 | { |
217 | 3615 | // Paint a fake window decoration | 3654 | if (!decoration_tex_.empty()) |
218 | 3616 | CairoContext context(width, height); | 3655 | return; |
219 | 3617 | 3656 | ||
220 | 3618 | cairo_save(context.cr_); | 3657 | auto const& border_extents = window->border(); |
221 | 3619 | 3658 | ||
222 | 3620 | // Draw window decoration based on gtk style | 3659 | if (WindowManager::Default()->IsWindowDecorated(window->id()) && border_extents.top > 0) |
194 | 3621 | cairo_push_group(context.cr_); | ||
195 | 3622 | auto& style = panel::Style::Instance(); | ||
196 | 3623 | gtk_render_background(style.GetStyleContext(), context.cr_, 0, 0, width, height); | ||
197 | 3624 | gtk_render_frame(style.GetStyleContext(), context.cr_, 0, 0, width, height); | ||
198 | 3625 | cairo_pop_group_to_source(context.cr_); | ||
199 | 3626 | |||
200 | 3627 | // Round window decoration top border | ||
201 | 3628 | const double aspect = ScaleWindow::get(window)->getCurrentPosition().scale; | ||
202 | 3629 | const double radius = 8.0 * aspect; | ||
203 | 3630 | |||
204 | 3631 | cairo_new_sub_path(context.cr_); | ||
205 | 3632 | cairo_line_to(context.cr_, 0, height); | ||
206 | 3633 | cairo_arc(context.cr_, radius, radius, radius, M_PI, -M_PI * 0.5f); | ||
207 | 3634 | cairo_line_to(context.cr_, width - radius, 0); | ||
208 | 3635 | cairo_arc(context.cr_, width - radius, radius, radius, M_PI * 0.5f, 0); | ||
209 | 3636 | cairo_line_to(context.cr_, width, height); | ||
210 | 3637 | cairo_close_path(context.cr_); | ||
211 | 3638 | |||
212 | 3639 | cairo_fill(context.cr_); | ||
213 | 3640 | |||
214 | 3641 | cairo_restore(context.cr_); | ||
215 | 3642 | |||
216 | 3643 | if (highlighted) | ||
223 | 3644 | { | 3660 | { |
227 | 3645 | // Draw windows title | 3661 | CairoContext context(window->borderRect().width(), border_extents.top); |
228 | 3646 | const float xText = SCALE_ITEMS_PADDING * 2 + SCALE_CLOSE_ICON_SIZE; | 3662 | RenderDecoration(context); |
229 | 3647 | RenderText(context, xText, 0.0, width - SCALE_ITEMS_PADDING, height); | 3663 | decoration_tex_ = context.texture_; |
230 | 3648 | } | 3664 | } |
231 | 3649 | |||
232 | 3650 | mask |= PAINT_WINDOW_BLEND_MASK; | ||
233 | 3651 | DrawTexture(context.texture_, attrib, transform, mask, x, y); | ||
234 | 3652 | } | 3665 | } |
235 | 3653 | 3666 | ||
236 | 3654 | void UnityWindow::LoadCloseIcon(panel::WindowState state, GLTexture::List& texture) | 3667 | void UnityWindow::LoadCloseIcon(panel::WindowState state, GLTexture::List& texture) |
237 | @@ -3663,7 +3676,7 @@ | |||
238 | 3663 | for (std::string const& file : files) | 3676 | for (std::string const& file : files) |
239 | 3664 | { | 3677 | { |
240 | 3665 | CompString file_name = file; | 3678 | CompString file_name = file; |
242 | 3666 | CompSize size(SCALE_CLOSE_ICON_SIZE, SCALE_CLOSE_ICON_SIZE); | 3679 | CompSize size(scale::decoration::CLOSE_SIZE, scale::decoration::CLOSE_SIZE); |
243 | 3667 | texture = GLTexture::readImageToTexture(file_name, plugin, size); | 3680 | texture = GLTexture::readImageToTexture(file_name, plugin, size); |
244 | 3668 | if (!texture.empty()) | 3681 | if (!texture.empty()) |
245 | 3669 | break; | 3682 | break; |
246 | @@ -3678,7 +3691,7 @@ | |||
247 | 3678 | suffix = "_pressed"; | 3691 | suffix = "_pressed"; |
248 | 3679 | 3692 | ||
249 | 3680 | CompString file_name(PKGDATADIR"/close_dash" + suffix + ".png"); | 3693 | CompString file_name(PKGDATADIR"/close_dash" + suffix + ".png"); |
251 | 3681 | CompSize size(SCALE_CLOSE_ICON_SIZE, SCALE_CLOSE_ICON_SIZE); | 3694 | CompSize size(scale::decoration::CLOSE_SIZE, scale::decoration::CLOSE_SIZE); |
252 | 3682 | texture = GLTexture::readImageToTexture(file_name, plugin, size); | 3695 | texture = GLTexture::readImageToTexture(file_name, plugin, size); |
253 | 3683 | } | 3696 | } |
254 | 3684 | } | 3697 | } |
255 | @@ -3697,6 +3710,13 @@ | |||
256 | 3697 | close_pressed_tex_.clear(); | 3710 | close_pressed_tex_.clear(); |
257 | 3698 | } | 3711 | } |
258 | 3699 | 3712 | ||
259 | 3713 | void UnityWindow::CleanupCachedTextures() | ||
260 | 3714 | { | ||
261 | 3715 | decoration_tex_.clear(); | ||
262 | 3716 | decoration_selected_tex_.clear(); | ||
263 | 3717 | decoration_title_.clear(); | ||
264 | 3718 | } | ||
265 | 3719 | |||
266 | 3700 | void UnityWindow::scalePaintDecoration(GLWindowPaintAttrib const& attrib, | 3720 | void UnityWindow::scalePaintDecoration(GLWindowPaintAttrib const& attrib, |
267 | 3701 | GLMatrix const& transform, | 3721 | GLMatrix const& transform, |
268 | 3702 | CompRegion const& region, | 3722 | CompRegion const& region, |
269 | @@ -3715,27 +3735,53 @@ | |||
270 | 3715 | return; | 3735 | return; |
271 | 3716 | 3736 | ||
272 | 3717 | auto const& scaled_geo = GetScaledGeometry(); | 3737 | auto const& scaled_geo = GetScaledGeometry(); |
273 | 3718 | auto const& decoration_extents = window->border(); | ||
274 | 3719 | auto const& pos = scale_win->getCurrentPosition(); | 3738 | auto const& pos = scale_win->getCurrentPosition(); |
275 | 3720 | 3739 | ||
276 | 3721 | const bool highlighted = (ss->getSelectedWindow() == window->id()); | 3740 | const bool highlighted = (ss->getSelectedWindow() == window->id()); |
277 | 3722 | int width = scaled_geo.width; | ||
278 | 3723 | int height = decoration_extents.top; | ||
279 | 3724 | int x = scaled_geo.x; | 3741 | int x = scaled_geo.x; |
280 | 3725 | int y = scaled_geo.y; | 3742 | int y = scaled_geo.y; |
281 | 3726 | 3743 | ||
282 | 3744 | mask |= PAINT_WINDOW_BLEND_MASK; | ||
283 | 3727 | 3745 | ||
284 | 3728 | // If window is not highlighted, we draw the decoration at scaled size | ||
285 | 3729 | if (!highlighted) | 3746 | if (!highlighted) |
295 | 3730 | height *= pos.scale; | 3747 | { |
296 | 3731 | 3748 | BuildDecorationTexture(); | |
297 | 3732 | DrawWindowDecoration(attrib, transform, mask, highlighted, x, y, width, height); | 3749 | DrawTexture(decoration_tex_, attrib, transform, mask, x, y, pos.scale); |
298 | 3733 | 3750 | close_button_geo_.Set(0, 0, 0, 0); | |
299 | 3734 | if (highlighted) | 3751 | } |
300 | 3735 | { | 3752 | else |
301 | 3736 | x += SCALE_ITEMS_PADDING; | 3753 | { |
302 | 3737 | y += (height - SCALE_CLOSE_ICON_SIZE) / 2.0f; | 3754 | auto const& decoration_extents = window->border(); |
303 | 3738 | mask |= PAINT_WINDOW_BLEND_MASK; | 3755 | int width = scaled_geo.width; |
304 | 3756 | int height = decoration_extents.top; | ||
305 | 3757 | bool redraw_decoration = true; | ||
306 | 3758 | |||
307 | 3759 | if (!decoration_selected_tex_.empty()) | ||
308 | 3760 | { | ||
309 | 3761 | GLTexture* texture = decoration_selected_tex_.front(); | ||
310 | 3762 | |||
311 | 3763 | if (texture->width() == width && texture->height() == height) | ||
312 | 3764 | { | ||
313 | 3765 | if (decoration_title_ == WindowManager::Default()->GetWindowName(window->id())) | ||
314 | 3766 | redraw_decoration = false; | ||
315 | 3767 | } | ||
316 | 3768 | } | ||
317 | 3769 | |||
318 | 3770 | if (redraw_decoration) | ||
319 | 3771 | { | ||
320 | 3772 | CairoContext context(width, height); | ||
321 | 3773 | RenderDecoration(context, pos.scale); | ||
322 | 3774 | |||
323 | 3775 | // Draw window title | ||
324 | 3776 | int text_x = scale::decoration::ITEMS_PADDING * 2 + scale::decoration::CLOSE_SIZE; | ||
325 | 3777 | RenderText(context, text_x, 0.0, width - scale::decoration::ITEMS_PADDING, height); | ||
326 | 3778 | decoration_selected_tex_ = context.texture_; | ||
327 | 3779 | } | ||
328 | 3780 | |||
329 | 3781 | DrawTexture(decoration_selected_tex_, attrib, transform, mask, x, y); | ||
330 | 3782 | |||
331 | 3783 | x += scale::decoration::ITEMS_PADDING; | ||
332 | 3784 | y += (height - scale::decoration::CLOSE_SIZE) / 2.0f; | ||
333 | 3739 | 3785 | ||
334 | 3740 | switch (close_icon_state_) | 3786 | switch (close_icon_state_) |
335 | 3741 | { | 3787 | { |
336 | @@ -3753,11 +3799,7 @@ | |||
337 | 3753 | break; | 3799 | break; |
338 | 3754 | } | 3800 | } |
339 | 3755 | 3801 | ||
345 | 3756 | close_button_geo_.Set(x, y, SCALE_CLOSE_ICON_SIZE, SCALE_CLOSE_ICON_SIZE); | 3802 | close_button_geo_.Set(x, y, scale::decoration::CLOSE_SIZE, scale::decoration::CLOSE_SIZE); |
341 | 3757 | } | ||
342 | 3758 | else if (!close_button_geo_.IsNull()) | ||
343 | 3759 | { | ||
344 | 3760 | close_button_geo_.Set(0, 0, 0, 0); | ||
346 | 3761 | } | 3803 | } |
347 | 3762 | } | 3804 | } |
348 | 3763 | 3805 | ||
349 | @@ -3777,7 +3819,7 @@ | |||
350 | 3777 | return nux::Geometry(x, y, width, height); | 3819 | return nux::Geometry(x, y, width, height); |
351 | 3778 | } | 3820 | } |
352 | 3779 | 3821 | ||
354 | 3780 | void UnityWindow::OnInitiateSpreed() | 3822 | void UnityWindow::OnInitiateSpread() |
355 | 3781 | { | 3823 | { |
356 | 3782 | close_icon_state_ = panel::WindowState::NORMAL; | 3824 | close_icon_state_ = panel::WindowState::NORMAL; |
357 | 3783 | middle_clicked_ = false; | 3825 | middle_clicked_ = false; |
358 | @@ -3790,13 +3832,15 @@ | |||
359 | 3790 | wm->Decorate(xid); | 3832 | wm->Decorate(xid); |
360 | 3791 | } | 3833 | } |
361 | 3792 | 3834 | ||
363 | 3793 | void UnityWindow::OnTerminateSpreed() | 3835 | void UnityWindow::OnTerminateSpread() |
364 | 3794 | { | 3836 | { |
365 | 3795 | WindowManager *wm = WindowManager::Default(); | 3837 | WindowManager *wm = WindowManager::Default(); |
366 | 3796 | Window xid = window->id(); | 3838 | Window xid = window->id(); |
367 | 3797 | 3839 | ||
368 | 3798 | if (wm->IsWindowDecorated(xid) && wm->IsWindowMaximized(xid)) | 3840 | if (wm->IsWindowDecorated(xid) && wm->IsWindowMaximized(xid)) |
369 | 3799 | wm->Undecorate(xid); | 3841 | wm->Undecorate(xid); |
370 | 3842 | |||
371 | 3843 | CleanupCachedTextures(); | ||
372 | 3800 | } | 3844 | } |
373 | 3801 | 3845 | ||
374 | 3802 | UnityWindow::~UnityWindow() | 3846 | UnityWindow::~UnityWindow() |
375 | 3803 | 3847 | ||
376 | === modified file 'plugins/unityshell/src/unityshell.h' | |||
377 | --- plugins/unityshell/src/unityshell.h 2012-09-24 19:42:22 +0000 | |||
378 | +++ plugins/unityshell/src/unityshell.h 2012-09-24 19:42:22 +0000 | |||
379 | @@ -359,34 +359,22 @@ | |||
380 | 359 | 359 | ||
381 | 360 | nux::Geometry last_bound; | 360 | nux::Geometry last_bound; |
382 | 361 | 361 | ||
388 | 362 | void minimize (); | 362 | void minimize(); |
389 | 363 | void unminimize (); | 363 | void unminimize(); |
390 | 364 | bool minimized (); | 364 | bool minimized(); |
391 | 365 | bool focus (); | 365 | bool focus(); |
392 | 366 | void activate (); | 366 | void activate(); |
393 | 367 | 367 | ||
395 | 368 | void updateFrameRegion (CompRegion ®ion); | 368 | void updateFrameRegion(CompRegion ®ion); |
396 | 369 | 369 | ||
397 | 370 | /* occlusion detection | 370 | /* occlusion detection |
398 | 371 | * and window hiding */ | 371 | * and window hiding */ |
403 | 372 | bool glPaint(const GLWindowPaintAttrib& attrib, | 372 | bool glPaint(GLWindowPaintAttrib const&, GLMatrix const&, CompRegion const&, unsigned mask); |
400 | 373 | const GLMatrix& matrix, | ||
401 | 374 | const CompRegion& region, | ||
402 | 375 | unsigned int mask); | ||
404 | 376 | 373 | ||
405 | 377 | /* basic window draw function */ | 374 | /* basic window draw function */ |
418 | 378 | bool glDraw(const GLMatrix& matrix, | 375 | bool glDraw(GLMatrix const&, GLWindowPaintAttrib const&, CompRegion const&, unsigned mask); |
419 | 379 | const GLWindowPaintAttrib& attrib, | 376 | |
420 | 380 | const CompRegion& region, | 377 | void updateIconPos (int &wx, int &wy, int x, int y, float width, float height); |
409 | 381 | unsigned intmask); | ||
410 | 382 | |||
411 | 383 | void updateIconPos (int &wx, | ||
412 | 384 | int &wy, | ||
413 | 385 | int x, | ||
414 | 386 | int y, | ||
415 | 387 | float width, | ||
416 | 388 | float height); | ||
417 | 389 | |||
421 | 390 | void windowNotify(CompWindowNotify n); | 378 | void windowNotify(CompWindowNotify n); |
422 | 391 | void moveNotify(int x, int y, bool immediate); | 379 | void moveNotify(int x, int y, bool immediate); |
423 | 392 | void resizeNotify(int x, int y, int w, int h); | 380 | void resizeNotify(int x, int y, int w, int h); |
424 | @@ -396,32 +384,26 @@ | |||
425 | 396 | CompPoint tryNotIntersectUI(CompPoint& pos); | 384 | CompPoint tryNotIntersectUI(CompPoint& pos); |
426 | 397 | nux::Geometry GetScaledGeometry(); | 385 | nux::Geometry GetScaledGeometry(); |
427 | 398 | 386 | ||
429 | 399 | void paintThumbnail (nux::Geometry const& bounding, float alpha); | 387 | void paintThumbnail(nux::Geometry const& bounding, float alpha); |
430 | 400 | 388 | ||
434 | 401 | void enterShowDesktop (); | 389 | void enterShowDesktop(); |
435 | 402 | void leaveShowDesktop (); | 390 | void leaveShowDesktop(); |
436 | 403 | bool HandleAnimations (unsigned int ms); | 391 | bool HandleAnimations(unsigned int ms); |
437 | 404 | 392 | ||
438 | 405 | bool handleEvent(XEvent *event); | 393 | bool handleEvent(XEvent *event); |
440 | 406 | 394 | void scalePaintDecoration(GLWindowPaintAttrib const&, GLMatrix const&, CompRegion const&, unsigned mask); | |
441 | 395 | |||
442 | 396 | //! Emited when CompWindowNotifyBeforeDestroy is received | ||
443 | 397 | sigc::signal<void> being_destroyed; | ||
444 | 398 | |||
445 | 399 | |||
446 | 400 | protected: | ||
447 | 401 | std::string GetName() const; | ||
448 | 402 | void AddProperties(GVariantBuilder* builder); | ||
449 | 403 | |||
450 | 404 | private: | ||
451 | 407 | typedef compiz::CompizMinimizedWindowHandler<UnityScreen, UnityWindow> | 405 | typedef compiz::CompizMinimizedWindowHandler<UnityScreen, UnityWindow> |
452 | 408 | UnityMinimizedHandler; | 406 | UnityMinimizedHandler; |
453 | 409 | std::unique_ptr <UnityMinimizedHandler> mMinimizeHandler; | ||
454 | 410 | std::unique_ptr <ShowdesktopHandler> mShowdesktopHandler; | ||
455 | 411 | |||
456 | 412 | //! Emited when CompWindowNotifyBeforeDestroy is received | ||
457 | 413 | sigc::signal<void> being_destroyed; | ||
458 | 414 | |||
459 | 415 | void scalePaintDecoration(const GLWindowPaintAttrib &, | ||
460 | 416 | const GLMatrix &, | ||
461 | 417 | const CompRegion &, | ||
462 | 418 | unsigned int); | ||
463 | 419 | |||
464 | 420 | protected: | ||
465 | 421 | std::string GetName() const; | ||
466 | 422 | void AddProperties(GVariantBuilder* builder); | ||
467 | 423 | |||
468 | 424 | private: | ||
469 | 425 | struct CairoContext; | 407 | struct CairoContext; |
470 | 426 | 408 | ||
471 | 427 | void DoEnableFocus (); | 409 | void DoEnableFocus (); |
472 | @@ -443,8 +425,8 @@ | |||
473 | 443 | void DoShow (); | 425 | void DoShow (); |
474 | 444 | void DoNotifyShown (); | 426 | void DoNotifyShown (); |
475 | 445 | 427 | ||
478 | 446 | void OnInitiateSpreed(); | 428 | void OnInitiateSpread(); |
479 | 447 | void OnTerminateSpreed(); | 429 | void OnTerminateSpread(); |
480 | 448 | 430 | ||
481 | 449 | void DoAddDamage (); | 431 | void DoAddDamage (); |
482 | 450 | ShowdesktopHandlerWindowInterface::PostPaintAction DoHandleAnimations (unsigned int ms); | 432 | ShowdesktopHandlerWindowInterface::PostPaintAction DoHandleAnimations (unsigned int ms); |
483 | @@ -457,20 +439,28 @@ | |||
484 | 457 | 439 | ||
485 | 458 | compiz::WindowInputRemoverLock::Ptr GetInputRemover (); | 440 | compiz::WindowInputRemoverLock::Ptr GetInputRemover (); |
486 | 459 | 441 | ||
493 | 460 | void DrawWindowDecoration(GLWindowPaintAttrib const& attrib, GLMatrix const& transform, | 442 | void RenderDecoration(CairoContext const&, double aspect = 1.0f); |
494 | 461 | unsigned int mask, bool highlighted, | 443 | void RenderText(CairoContext const&, int x, int y, int width, int height); |
495 | 462 | int x, int y, unsigned width, unsigned height); | 444 | void DrawTexture(GLTexture::List const& textures, GLWindowPaintAttrib const&, |
496 | 463 | void DrawTexture(GLTexture::List const& textures, GLWindowPaintAttrib const& attrib, | 445 | GLMatrix const&, unsigned mask, int x, int y, double scale = 1.0f); |
491 | 464 | GLMatrix const& transform, unsigned int mask, int x, int y); | ||
492 | 465 | void RenderText(CairoContext const& context, int x, int y, int width, int height); | ||
497 | 466 | 446 | ||
498 | 447 | void BuildDecorationTexture(); | ||
499 | 448 | void CleanupCachedTextures(); | ||
500 | 467 | static void SetupSharedTextures(); | 449 | static void SetupSharedTextures(); |
501 | 468 | static void CleanupSharedTextures(); | 450 | static void CleanupSharedTextures(); |
502 | 469 | static void LoadCloseIcon(panel::WindowState state, GLTexture::List& texture); | 451 | static void LoadCloseIcon(panel::WindowState state, GLTexture::List& texture); |
503 | 470 | 452 | ||
504 | 453 | public: | ||
505 | 454 | std::unique_ptr <UnityMinimizedHandler> mMinimizeHandler; | ||
506 | 455 | |||
507 | 456 | private: | ||
508 | 457 | std::unique_ptr <ShowdesktopHandler> mShowdesktopHandler; | ||
509 | 471 | static GLTexture::List close_normal_tex_; | 458 | static GLTexture::List close_normal_tex_; |
510 | 472 | static GLTexture::List close_prelight_tex_; | 459 | static GLTexture::List close_prelight_tex_; |
511 | 473 | static GLTexture::List close_pressed_tex_; | 460 | static GLTexture::List close_pressed_tex_; |
512 | 461 | GLTexture::List decoration_tex_; | ||
513 | 462 | GLTexture::List decoration_selected_tex_; | ||
514 | 463 | std::string decoration_title_; | ||
515 | 474 | compiz::WindowInputRemoverLock::Weak input_remover_; | 464 | compiz::WindowInputRemoverLock::Weak input_remover_; |
516 | 475 | panel::WindowState close_icon_state_; | 465 | panel::WindowState close_icon_state_; |
517 | 476 | nux::Geometry close_button_geo_; | 466 | nux::Geometry close_button_geo_; |
Confirmed still working :)