Merge lp:~nick-dedekind/unity/static-cairo-text.TextureCacheFix into lp:unity

Proposed by Nick Dedekind
Status: Merged
Approved by: Nick Dedekind
Approved revision: no longer in the source branch.
Merged at revision: 2570
Proposed branch: lp:~nick-dedekind/unity/static-cairo-text.TextureCacheFix
Merge into: lp:unity
Diff against target: 86 lines (+37/-7)
2 files modified
unity-shared/StaticCairoText.cpp (+34/-7)
unity-shared/StaticCairoText.h (+3/-0)
To merge this branch: bzr merge lp:~nick-dedekind/unity/static-cairo-text.TextureCacheFix
Reviewer Review Type Date Requested Status
Neil J. Patel (community) Approve
Review via email: mp+119743@code.launchpad.net

Commit message

Added handlers for StaticCairoText::SetMaximumSize/SetMaximumWidth which cause cached texture to be updated if width has changed.
StaticCairoText::GetTextExtents now updates need_new_extent_cache_ to false once the texture has updated so that it is not re-cached every time called.

Description of the change

Added handlers for StaticCairoText::SetMaximumSize/SetMaximumWidth which cause cached texture to be updated if width has changed.
StaticCairoText::GetTextExtents now updates need_new_extent_cache_ to false once the texture has updated so that it is not re-cached every time called.

To post a comment you must log in.
Revision history for this message
Neil J. Patel (njpatel) wrote :

Works great, tested with trunk and the preview branches.

review: Approve
Revision history for this message
Unity Merger (unity-merger) wrote :

No commit message specified.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'unity-shared/StaticCairoText.cpp'
2--- unity-shared/StaticCairoText.cpp 2012-07-12 15:54:25 +0000
3+++ unity-shared/StaticCairoText.cpp 2012-08-15 16:32:19 +0000
4@@ -67,7 +67,7 @@
5
6 StaticCairoText* parent_;
7 bool accept_key_nav_focus_;
8- bool need_new_extent_cache_;
9+ mutable bool need_new_extent_cache_;
10 // The three following are all set in get text extents.
11 mutable Size cached_extent_;
12 mutable Size cached_base_;
13@@ -309,6 +309,29 @@
14 }
15 }
16
17+void StaticCairoText::SetMaximumSize(int w, int h)
18+{
19+ if (w != GetMaximumWidth())
20+ {
21+ pimpl->need_new_extent_cache_ = true;
22+ View::SetMaximumSize(w, h);
23+ pimpl->UpdateTexture();
24+ return;
25+ }
26+
27+ View::SetMaximumSize(w, h);
28+}
29+
30+void StaticCairoText::SetMaximumWidth(int w)
31+{
32+ if (w != GetMaximumWidth())
33+ {
34+ pimpl->need_new_extent_cache_ = true;
35+ View::SetMaximumWidth(w);
36+ pimpl->UpdateTexture();
37+ }
38+}
39+
40 std::string StaticCairoText::GetText() const
41 {
42 return pimpl->text_;
43@@ -333,12 +356,15 @@
44
45 void StaticCairoText::SetFont(std::string const& font)
46 {
47- pimpl->font_ = font;
48- pimpl->need_new_extent_cache_ = true;
49- Size s = GetTextExtents();
50- SetMinimumHeight(s.height);
51- NeedRedraw();
52- sigFontChanged.emit(this);
53+ if (pimpl->font_ != font)
54+ {
55+ pimpl->font_ = font;
56+ pimpl->need_new_extent_cache_ = true;
57+ Size s = GetTextExtents();
58+ SetMinimumHeight(s.height);
59+ NeedRedraw();
60+ sigFontChanged.emit(this);
61+ }
62 }
63
64 int StaticCairoText::GetLineCount() const
65@@ -440,6 +466,7 @@
66 result.height = std::ceil(static_cast<float>(logRect.height) / PANGO_SCALE);
67 cached_extent_ = result;
68 baseline_ = pango_layout_get_baseline(layout) / PANGO_SCALE;
69+ need_new_extent_cache_ = false;
70
71 // clean up
72 pango_font_description_free(desc);
73
74=== modified file 'unity-shared/StaticCairoText.h'
75--- unity-shared/StaticCairoText.h 2012-07-12 15:54:25 +0000
76+++ unity-shared/StaticCairoText.h 2012-08-15 16:32:19 +0000
77@@ -92,6 +92,9 @@
78
79 void SetAcceptKeyNavFocus(bool accept);
80
81+ void SetMaximumSize(int w, int h);
82+ void SetMaximumWidth(int w);
83+
84 protected:
85 // Key navigation
86 virtual bool AcceptKeyNavFocus();