Merge lp:~3v1n0/unity/icon-renderer-smartpool into lp:unity
- icon-renderer-smartpool
- Merge into trunk
Proposed by
Marco Trevisan (Treviño)
Status: | Superseded |
---|---|
Proposed branch: | lp:~3v1n0/unity/icon-renderer-smartpool |
Merge into: | lp:unity |
Prerequisite: | lp:~3v1n0/unity/launchers-resize-new |
Diff against target: |
751 lines (+206/-253) 3 files modified
plugins/unityshell/src/unityshell.cpp (+0/-1) unity-shared/IconRenderer.cpp (+204/-249) unity-shared/IconRenderer.h (+2/-3) |
To merge this branch: | bzr merge lp:~3v1n0/unity/icon-renderer-smartpool |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Nick Dedekind | Pending | ||
Review via email: mp+154079@code.launchpad.net |
Commit message
IconRenderer: add TexturePool static class used to cache all the icons textures using smart pointers
No need to delete textures manually anymore
Description of the change
Add a smart static class to IconRender to handle all the textures (disabling the ones not used anymore), so that everything is cleaned up automatically when needed.
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 2013-03-11 23:13:45 +0000 |
3 | +++ plugins/unityshell/src/unityshell.cpp 2013-03-19 13:21:04 +0000 |
4 | @@ -425,7 +425,6 @@ |
5 | notify_uninit(); |
6 | |
7 | unity_a11y_finalize(); |
8 | - ::unity::ui::IconRenderer::DestroyTextures(); |
9 | QuicklistManager::Destroy(); |
10 | |
11 | reset_glib_logging(); |
12 | |
13 | === modified file 'unity-shared/IconRenderer.cpp' |
14 | --- unity-shared/IconRenderer.cpp 2013-03-18 21:08:39 +0000 |
15 | +++ unity-shared/IconRenderer.cpp 2013-03-19 13:21:04 +0000 |
16 | @@ -25,7 +25,9 @@ |
17 | #include <NuxGraphics/GpuDevice.h> |
18 | #include <NuxGraphics/GLTextureResourceManager.h> |
19 | |
20 | +#include <UnityCore/GLibWrapper.h> |
21 | #include <NuxGraphics/CairoGraphics.h> |
22 | +#include "unity-shared/CairoTexture.h" |
23 | #include "GraphicsUtils.h" |
24 | |
25 | #include <gtk/gtk.h> |
26 | @@ -39,6 +41,8 @@ |
27 | { |
28 | namespace ui |
29 | { |
30 | +namespace |
31 | +{ |
32 | |
33 | #ifdef USE_GLES |
34 | #define VertexShaderHeader "#version 100\n" |
35 | @@ -171,6 +175,7 @@ |
36 | MUL result.color.rgb, temp, colorify_color; \n\ |
37 | MOV result.color.a, color; \n\ |
38 | END"); |
39 | +} // anonymous namespace |
40 | |
41 | // The local namespace is purely for namespacing the file local variables below. |
42 | namespace local |
43 | @@ -181,60 +186,83 @@ |
44 | { |
45 | SMALL = 0, |
46 | BIG, |
47 | - LAST, |
48 | + SIZE, |
49 | }; |
50 | - |
51 | -bool textures_created = false; |
52 | -nux::BaseTexture* progress_bar_trough = 0; |
53 | -nux::BaseTexture* progress_bar_fill = 0; |
54 | -nux::BaseTexture* pip_ltr = 0; |
55 | -nux::BaseTexture* pip_rtl = 0; |
56 | -nux::BaseTexture* large_pip_ltr = 0; |
57 | -nux::BaseTexture* large_pip_rtl = 0; |
58 | -nux::BaseTexture* arrow_ltr = 0; |
59 | -nux::BaseTexture* arrow_rtl = 0; |
60 | -nux::BaseTexture* arrow_empty_ltr = 0; |
61 | -nux::BaseTexture* arrow_empty_rtl = 0; |
62 | - |
63 | -// nux::BaseTexture* squircle_base = 0; |
64 | -// nux::BaseTexture* squircle_base_selected = 0; |
65 | -// nux::BaseTexture* squircle_edge = 0; |
66 | -// nux::BaseTexture* squircle_glow = 0; |
67 | -// nux::BaseTexture* squircle_shadow = 0; |
68 | -// nux::BaseTexture* squircle_shine = 0; |
69 | - |
70 | -std::vector<nux::BaseTexture*> icon_background; |
71 | -std::vector<nux::BaseTexture*> icon_selected_background; |
72 | -std::vector<nux::BaseTexture*> icon_edge; |
73 | -std::vector<nux::BaseTexture*> icon_glow; |
74 | -std::vector<nux::BaseTexture*> icon_shadow; |
75 | -std::vector<nux::BaseTexture*> icon_shine; |
76 | -nux::ObjectPtr<nux::IOpenGLBaseTexture> offscreen_progress_texture; |
77 | -nux::ObjectPtr<nux::IOpenGLShaderProgram> shader_program_uv_persp_correction; |
78 | +} // anonymous namespace |
79 | +} // local namespace |
80 | + |
81 | +struct IconRenderer::TexturesPool |
82 | +{ |
83 | + static std::shared_ptr<TexturesPool> Get() |
84 | + { |
85 | + static std::shared_ptr<TexturesPool> instance(new TexturesPool()); |
86 | + return instance; |
87 | + } |
88 | + |
89 | + nux::ObjectPtr<nux::BaseTexture> RenderLabelTexture(char label, int icon_size, nux::Color const& bg_color); |
90 | + |
91 | + BaseTexturePtr progress_bar_trough; |
92 | + BaseTexturePtr progress_bar_fill; |
93 | + BaseTexturePtr pip_ltr; |
94 | + BaseTexturePtr large_pip_ltr; |
95 | + // BaseTexturePtr pip_rtl; |
96 | + // BaseTexturePtr large_pip_rtl; |
97 | + BaseTexturePtr arrow_ltr; |
98 | + BaseTexturePtr arrow_rtl; |
99 | + BaseTexturePtr arrow_empty_ltr; |
100 | + // BaseTexturePtr arrow_empty_rtl; |
101 | + |
102 | + // BaseTexturePtr squircle_base; |
103 | + // BaseTexturePtr squircle_base_selected; |
104 | + // BaseTexturePtr squircle_edge; |
105 | + // BaseTexturePtr squircle_glow; |
106 | + // BaseTexturePtr squircle_shadow; |
107 | + // BaseTexturePtr squircle_shine; |
108 | + |
109 | + BaseTexturePtr icon_background[local::IconSize::SIZE]; |
110 | + BaseTexturePtr icon_selected_background[local::IconSize::SIZE]; |
111 | + BaseTexturePtr icon_edge[local::IconSize::SIZE]; |
112 | + BaseTexturePtr icon_glow[local::IconSize::SIZE]; |
113 | + BaseTexturePtr icon_shadow[local::IconSize::SIZE]; |
114 | + BaseTexturePtr icon_shine[local::IconSize::SIZE]; |
115 | + |
116 | + nux::ObjectPtr<nux::IOpenGLBaseTexture> offscreen_progress_texture; |
117 | + nux::ObjectPtr<nux::IOpenGLShaderProgram> shader_program_uv_persp_correction; |
118 | #ifndef USE_GLES |
119 | -nux::ObjectPtr<nux::IOpenGLAsmShaderProgram> asm_shader; |
120 | + nux::ObjectPtr<nux::IOpenGLAsmShaderProgram> asm_shader; |
121 | #endif |
122 | -std::map<char, nux::BaseTexture*> label_map; |
123 | - |
124 | -void generate_textures(); |
125 | -void destroy_textures(); |
126 | -} |
127 | -} |
128 | + |
129 | + std::map<char, BaseTexturePtr> labels; |
130 | + |
131 | +private: |
132 | + TexturesPool(); |
133 | + |
134 | + inline void LoadTexture(BaseTexturePtr &texture_ptr, std::string const& filename) |
135 | + { |
136 | + texture_ptr.Adopt(nux::CreateTexture2DFromFile(filename.c_str(), -1, true)); |
137 | + } |
138 | + |
139 | + inline void GenerateTextures(BaseTexturePtr (&texture)[local::IconSize::SIZE], |
140 | + std::string const& big_file, std::string const& small_file) |
141 | + { |
142 | + LoadTexture(texture[local::IconSize::SMALL], small_file); |
143 | + LoadTexture(texture[local::IconSize::BIG], big_file); |
144 | + } |
145 | + |
146 | + void SetupShaders(); |
147 | +}; |
148 | |
149 | IconRenderer::IconRenderer() |
150 | : icon_size(0) |
151 | , image_size(0) |
152 | , spacing(0) |
153 | + , textures_(TexturesPool::Get()) |
154 | { |
155 | pip_style = OUTSIDE_TILE; |
156 | - |
157 | - if (!local::textures_created) |
158 | - local::generate_textures(); |
159 | } |
160 | |
161 | IconRenderer::~IconRenderer() |
162 | -{ |
163 | -} |
164 | +{} |
165 | |
166 | void IconRenderer::SetTargetSize(int tile_size, int image_size_, int spacing_) |
167 | { |
168 | @@ -415,11 +443,11 @@ |
169 | float glow_intensity = arg.glow_intensity; |
170 | float shadow_intensity = 0.6f; |
171 | |
172 | - nux::BaseTexture* background = local::icon_background[size]; |
173 | - nux::BaseTexture* edge = local::icon_edge[size]; |
174 | - nux::BaseTexture* glow = local::icon_glow[size]; |
175 | - nux::BaseTexture* shine = local::icon_shine[size]; |
176 | - nux::BaseTexture* shadow = local::icon_shadow[size]; |
177 | + BaseTexturePtr background = textures_->icon_background[size]; |
178 | + BaseTexturePtr const& edge = textures_->icon_edge[size]; |
179 | + BaseTexturePtr const& glow = textures_->icon_glow[size]; |
180 | + BaseTexturePtr const& shine = textures_->icon_shine[size]; |
181 | + BaseTexturePtr const& shadow = textures_->icon_shadow[size]; |
182 | |
183 | nux::Color shortcut_color = arg.colorify; |
184 | |
185 | @@ -448,7 +476,7 @@ |
186 | glow_intensity = 1.0f; |
187 | shadow_intensity = 0.0f; |
188 | |
189 | - background = local::icon_selected_background[size]; |
190 | + background = textures_->icon_selected_background[size]; |
191 | } |
192 | else |
193 | { |
194 | @@ -480,8 +508,6 @@ |
195 | { |
196 | nux::Color shadow_color = background_tile_colorify * 0.3f; |
197 | |
198 | - // FIXME it is using the same transformation of the glow, |
199 | - // should have its own transformation. |
200 | RenderElement(GfxContext, |
201 | arg, |
202 | shadow->GetDeviceTexture(), |
203 | @@ -578,7 +604,7 @@ |
204 | |
205 | RenderElement(GfxContext, |
206 | arg, |
207 | - local::icon_glow[size]->GetDeviceTexture(), |
208 | + textures_->icon_glow[size]->GetDeviceTexture(), |
209 | arg.icon->GlowColor(), |
210 | nux::color::White, |
211 | fade_out * arg.alpha, |
212 | @@ -591,17 +617,17 @@ |
213 | // draw progress bar |
214 | if (arg.progress_bias > -1.0f && arg.progress_bias < 1.0f) |
215 | { |
216 | - if (local::offscreen_progress_texture->GetWidth() != icon_size || |
217 | - local::offscreen_progress_texture->GetHeight() != icon_size) |
218 | + if (textures_->offscreen_progress_texture->GetWidth() != icon_size || |
219 | + textures_->offscreen_progress_texture->GetHeight() != icon_size) |
220 | { |
221 | - local::offscreen_progress_texture = nux::GetGraphicsDisplay()->GetGpuDevice() |
222 | + textures_->offscreen_progress_texture = nux::GetGraphicsDisplay()->GetGpuDevice() |
223 | ->CreateSystemCapableDeviceTexture(icon_size, icon_size, 1, nux::BITFMT_R8G8B8A8); |
224 | } |
225 | - RenderProgressToTexture(GfxContext, local::offscreen_progress_texture, arg.progress, arg.progress_bias); |
226 | + RenderProgressToTexture(GfxContext, textures_->offscreen_progress_texture, arg.progress, arg.progress_bias); |
227 | |
228 | RenderElement(GfxContext, |
229 | arg, |
230 | - local::offscreen_progress_texture, |
231 | + textures_->offscreen_progress_texture, |
232 | nux::color::White, |
233 | nux::color::White, |
234 | arg.alpha, |
235 | @@ -634,12 +660,22 @@ |
236 | { |
237 | char shortcut = (char) arg.shortcut_label; |
238 | |
239 | - if (local::label_map.find(shortcut) == local::label_map.end()) |
240 | - local::label_map[shortcut] = RenderCharToTexture(shortcut, icon_size, icon_size, shortcut_color); |
241 | + BaseTexturePtr label; |
242 | + auto label_it = textures_->labels.find(shortcut); |
243 | + |
244 | + if (label_it != textures_->labels.end()) |
245 | + { |
246 | + label = label_it->second; |
247 | + } |
248 | + else |
249 | + { |
250 | + label = textures_->RenderLabelTexture(shortcut, icon_size, shortcut_color); |
251 | + textures_->labels[shortcut] = label; |
252 | + } |
253 | |
254 | RenderElement(GfxContext, |
255 | arg, |
256 | - local::label_map[shortcut]->GetDeviceTexture(), |
257 | + label->GetDeviceTexture(), |
258 | nux::Color(0xFFFFFFFF), |
259 | nux::color::White, |
260 | arg.alpha, |
261 | @@ -648,23 +684,19 @@ |
262 | } |
263 | } |
264 | |
265 | -nux::BaseTexture* IconRenderer::RenderCharToTexture(char label, int width, int height, nux::Color const& bg_color) |
266 | +nux::ObjectPtr<nux::BaseTexture> IconRenderer::TexturesPool::RenderLabelTexture(char label, int icon_size, nux::Color const& bg_color) |
267 | { |
268 | - nux::BaseTexture* texture = NULL; |
269 | - nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, width, height); |
270 | - cairo_t* cr = cg.GetInternalContext(); |
271 | - PangoLayout* layout = NULL; |
272 | - PangoFontDescription* desc = NULL; |
273 | - GtkSettings* settings = gtk_settings_get_default(); // not ref'ed |
274 | - gchar* fontName = NULL; |
275 | + nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, icon_size, icon_size); |
276 | + cairo_t* cr = cg.GetInternalContext(); |
277 | + glib::String font_name; |
278 | |
279 | - double label_ratio = 0.44f; |
280 | - double label_size = icon_size * label_ratio; |
281 | - double label_x = (icon_size - label_size) / 2; |
282 | - double label_y = (icon_size - label_size) / 2; |
283 | - double label_w = label_size; |
284 | - double label_h = label_size; |
285 | - double label_radius = 3.0f; |
286 | + const double label_ratio = 0.44f; |
287 | + const double label_size = icon_size * label_ratio; |
288 | + const double label_x = (icon_size - label_size) / 2.0f; |
289 | + const double label_y = (icon_size - label_size) / 2.0f; |
290 | + const double label_w = label_size; |
291 | + const double label_h = label_size; |
292 | + const double label_radius = 3.0f; |
293 | |
294 | cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
295 | cairo_paint(cr); |
296 | @@ -676,35 +708,27 @@ |
297 | cairo_set_source_rgba(cr, bg_color.red, bg_color.green, bg_color.blue, 0.20f); |
298 | cairo_fill(cr); |
299 | |
300 | - double text_ratio = 0.75; |
301 | - double text_size = label_size * text_ratio; |
302 | - layout = pango_cairo_create_layout(cr); |
303 | - g_object_get(settings, "gtk-font-name", &fontName, NULL); |
304 | - desc = pango_font_description_from_string(fontName); |
305 | - pango_font_description_set_absolute_size(desc, text_size * PANGO_SCALE); |
306 | - pango_layout_set_font_description(layout, desc); |
307 | + const double text_ratio = 0.75; |
308 | + double text_size = label_size * text_ratio; |
309 | + glib::Object<PangoLayout> layout(pango_cairo_create_layout(cr)); |
310 | + g_object_get(gtk_settings_get_default(), "gtk-font-name", &font_name, NULL); |
311 | + std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font_name), |
312 | + pango_font_description_free); |
313 | + pango_font_description_set_absolute_size(desc.get(), text_size * PANGO_SCALE); |
314 | + pango_layout_set_font_description(layout, desc.get()); |
315 | pango_layout_set_text(layout, &label, 1); |
316 | |
317 | - PangoRectangle logRect; |
318 | - PangoRectangle inkRect; |
319 | - pango_layout_get_extents(layout, &inkRect, &logRect); |
320 | + nux::Size extents; |
321 | + pango_layout_get_pixel_size(layout, &extents.width, &extents.height); |
322 | |
323 | // position and paint text |
324 | cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f); |
325 | - double x = label_x - ((logRect.width / PANGO_SCALE) - label_w) / 2.0f; |
326 | - double y = label_y - ((logRect.height / PANGO_SCALE) - label_h) / 2.0f - 1; |
327 | + double x = label_x - std::round((extents.width - label_w) / 2.0f); |
328 | + double y = label_y - std::round((extents.height - label_h) / 2.0f); |
329 | cairo_move_to(cr, x, y); |
330 | pango_cairo_show_layout(cr, layout); |
331 | |
332 | - nux::NBitmapData* bitmap = cg.GetBitmap(); |
333 | - texture = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture(); |
334 | - texture->Update(bitmap); |
335 | - delete bitmap; |
336 | - g_object_unref(layout); |
337 | - pango_font_description_free(desc); |
338 | - g_free(fontName); |
339 | - |
340 | - return texture; |
341 | + return texture_ptr_from_cairo_graphics(cg); |
342 | } |
343 | |
344 | void IconRenderer::RenderElement(nux::GraphicsEngine& GfxContext, |
345 | @@ -786,28 +810,28 @@ |
346 | |
347 | if (nux::GetWindowThread()->GetGraphicsEngine().UsingGLSLCodePath()) |
348 | { |
349 | - local::shader_program_uv_persp_correction->Begin(); |
350 | + textures_->shader_program_uv_persp_correction->Begin(); |
351 | |
352 | - int TextureObjectLocation = local::shader_program_uv_persp_correction->GetUniformLocationARB("TextureObject0"); |
353 | - VertexLocation = local::shader_program_uv_persp_correction->GetAttributeLocation("iVertex"); |
354 | - TextureCoord0Location = local::shader_program_uv_persp_correction->GetAttributeLocation("iTexCoord0"); |
355 | - FragmentColor = local::shader_program_uv_persp_correction->GetUniformLocationARB("color0"); |
356 | - ColorifyColor = local::shader_program_uv_persp_correction->GetUniformLocationARB("colorify_color"); |
357 | - DesatFactor = local::shader_program_uv_persp_correction->GetUniformLocationARB("desat_factor"); |
358 | + int TextureObjectLocation = textures_->shader_program_uv_persp_correction->GetUniformLocationARB("TextureObject0"); |
359 | + VertexLocation = textures_->shader_program_uv_persp_correction->GetAttributeLocation("iVertex"); |
360 | + TextureCoord0Location = textures_->shader_program_uv_persp_correction->GetAttributeLocation("iTexCoord0"); |
361 | + FragmentColor = textures_->shader_program_uv_persp_correction->GetUniformLocationARB("color0"); |
362 | + ColorifyColor = textures_->shader_program_uv_persp_correction->GetUniformLocationARB("colorify_color"); |
363 | + DesatFactor = textures_->shader_program_uv_persp_correction->GetUniformLocationARB("desat_factor"); |
364 | |
365 | if (TextureObjectLocation != -1) |
366 | CHECKGL(glUniform1iARB(TextureObjectLocation, 0)); |
367 | |
368 | - int VPMatrixLocation = local::shader_program_uv_persp_correction->GetUniformLocationARB("ViewProjectionMatrix"); |
369 | + int VPMatrixLocation = textures_->shader_program_uv_persp_correction->GetUniformLocationARB("ViewProjectionMatrix"); |
370 | if (VPMatrixLocation != -1) |
371 | { |
372 | - local::shader_program_uv_persp_correction->SetUniformLocMatrix4fv((GLint)VPMatrixLocation, 1, false, (GLfloat*) & (_stored_projection_matrix.m)); |
373 | + textures_->shader_program_uv_persp_correction->SetUniformLocMatrix4fv((GLint)VPMatrixLocation, 1, false, (GLfloat*) & (_stored_projection_matrix.m)); |
374 | } |
375 | } |
376 | #ifndef USE_GLES |
377 | else |
378 | { |
379 | - local::asm_shader->Begin(); |
380 | + textures_->asm_shader->Begin(); |
381 | |
382 | VertexLocation = nux::VTXATTRIB_POSITION; |
383 | TextureCoord0Location = nux::VTXATTRIB_TEXCOORD0; |
384 | @@ -869,12 +893,12 @@ |
385 | |
386 | if (nux::GetWindowThread()->GetGraphicsEngine().UsingGLSLCodePath()) |
387 | { |
388 | - local::shader_program_uv_persp_correction->End(); |
389 | + textures_->shader_program_uv_persp_correction->End(); |
390 | } |
391 | else |
392 | { |
393 | #ifndef USE_GLES |
394 | - local::asm_shader->End(); |
395 | + textures_->asm_shader->End(); |
396 | #endif |
397 | } |
398 | } |
399 | @@ -916,7 +940,7 @@ |
400 | |
401 | color = color * alpha; |
402 | |
403 | - nux::BaseTexture* texture; |
404 | + BaseTexturePtr texture; |
405 | |
406 | // markers are well outside screen bounds to start |
407 | int markers [3] = {-100, -100, -100}; |
408 | @@ -925,25 +949,25 @@ |
409 | { |
410 | scale = (pip_style == OUTSIDE_TILE) ? 1 : 2; |
411 | markers[0] = markerCenter; |
412 | - texture = local::arrow_empty_ltr; |
413 | + texture = textures_->arrow_empty_ltr; |
414 | } |
415 | else if (running == 1) |
416 | { |
417 | scale = (pip_style == OUTSIDE_TILE) ? 1 : 2; |
418 | markers[0] = markerCenter; |
419 | - texture = local::arrow_ltr; |
420 | + texture = textures_->arrow_ltr; |
421 | } |
422 | else if (running == 2) |
423 | { |
424 | if (pip_style == OUTSIDE_TILE) |
425 | { |
426 | - texture = local::pip_ltr; |
427 | + texture = textures_->pip_ltr; |
428 | markers[0] = markerCenter - 2; |
429 | markers[1] = markerCenter + 2; |
430 | } |
431 | else |
432 | { |
433 | - texture = local::large_pip_ltr; |
434 | + texture = textures_->large_pip_ltr; |
435 | markers[0] = markerCenter - 4; |
436 | markers[1] = markerCenter + 4; |
437 | } |
438 | @@ -952,31 +976,30 @@ |
439 | { |
440 | if (pip_style == OUTSIDE_TILE) |
441 | { |
442 | - texture = local::pip_ltr; |
443 | + texture = textures_->pip_ltr; |
444 | markers[0] = markerCenter - 4; |
445 | markers[1] = markerCenter; |
446 | markers[2] = markerCenter + 4; |
447 | } |
448 | else |
449 | { |
450 | - texture = local::large_pip_ltr; |
451 | + texture = textures_->large_pip_ltr; |
452 | markers[0] = markerCenter - 8; |
453 | markers[1] = markerCenter; |
454 | markers[2] = markerCenter + 8; |
455 | } |
456 | } |
457 | |
458 | - |
459 | for (int i = 0; i < 3; i++) |
460 | { |
461 | int center = markers[i]; |
462 | if (center == -100) |
463 | break; |
464 | - |
465 | + |
466 | GfxContext.QRP_1Tex(markerX, |
467 | - center - ((texture->GetHeight() * scale) / 2) - 1, |
468 | - (float) texture->GetWidth() * scale, |
469 | - (float) texture->GetHeight() * scale, |
470 | + center - std::round((texture->GetHeight() * scale) / 2.0f), |
471 | + texture->GetWidth() * scale, |
472 | + texture->GetHeight() * scale, |
473 | texture->GetDeviceTexture(), |
474 | texxform, |
475 | color); |
476 | @@ -988,11 +1011,11 @@ |
477 | nux::TexCoordXForm texxform; |
478 | |
479 | nux::Color color = nux::color::LightGrey * alpha; |
480 | - GfxContext.QRP_1Tex((geo.x + geo.width) - local::arrow_rtl->GetWidth(), |
481 | - markerCenter - (local::arrow_rtl->GetHeight() / 2) - 1, |
482 | - (float) local::arrow_rtl->GetWidth(), |
483 | - (float) local::arrow_rtl->GetHeight(), |
484 | - local::arrow_rtl->GetDeviceTexture(), |
485 | + GfxContext.QRP_1Tex((geo.x + geo.width) - textures_->arrow_rtl->GetWidth(), |
486 | + markerCenter - std::round(textures_->arrow_rtl->GetHeight() / 2.0f), |
487 | + textures_->arrow_rtl->GetWidth(), |
488 | + textures_->arrow_rtl->GetHeight(), |
489 | + textures_->arrow_rtl->GetDeviceTexture(), |
490 | texxform, |
491 | color); |
492 | } |
493 | @@ -1007,10 +1030,10 @@ |
494 | int height = texture->GetHeight(); |
495 | |
496 | int progress_width = icon_size; |
497 | - int progress_height = local::progress_bar_trough->GetHeight(); |
498 | + int progress_height = textures_->progress_bar_trough->GetHeight(); |
499 | |
500 | int fill_width = image_size - (icon_size - image_size); |
501 | - int fill_height = local::progress_bar_fill->GetHeight(); |
502 | + int fill_height = textures_->progress_bar_fill->GetHeight(); |
503 | |
504 | int fill_offset = (progress_width - fill_width) / 2; |
505 | |
506 | @@ -1045,10 +1068,10 @@ |
507 | // left door |
508 | GfxContext.PushClippingRectangle(nux::Geometry(left_edge, 0, half_size, height)); |
509 | GfxContext.QRP_1Tex(left_edge, progress_y, progress_width, progress_height, |
510 | - local::progress_bar_trough->GetDeviceTexture(), texxform, |
511 | + textures_->progress_bar_trough->GetDeviceTexture(), texxform, |
512 | nux::color::White); |
513 | GfxContext.QRP_1Tex(left_edge + fill_offset, fill_y, fill_width, fill_height, |
514 | - local::progress_bar_fill->GetDeviceTexture(), texxform, |
515 | + textures_->progress_bar_fill->GetDeviceTexture(), texxform, |
516 | nux::color::White); |
517 | GfxContext.PopClippingRectangle(); |
518 | |
519 | @@ -1056,11 +1079,11 @@ |
520 | GfxContext.PushClippingRectangle(nux::Geometry(left_edge + half_size, 0, half_size, height)); |
521 | GfxContext.QRP_1Tex(right_edge - progress_width, progress_y, |
522 | progress_width, progress_height, |
523 | - local::progress_bar_trough->GetDeviceTexture(), texxform, |
524 | + textures_->progress_bar_trough->GetDeviceTexture(), texxform, |
525 | nux::color::White); |
526 | GfxContext.QRP_1Tex(right_edge - progress_width + fill_offset, fill_y, |
527 | fill_width, fill_height, |
528 | - local::progress_bar_fill->GetDeviceTexture(), texxform, |
529 | + textures_->progress_bar_fill->GetDeviceTexture(), texxform, |
530 | nux::color::White); |
531 | |
532 | GfxContext.PopClippingRectangle(); |
533 | @@ -1068,16 +1091,9 @@ |
534 | unity::graphics::PopOffscreenRenderTarget(); |
535 | } |
536 | |
537 | -void IconRenderer::DestroyTextures() |
538 | -{ |
539 | - local::destroy_textures(); |
540 | -} |
541 | - |
542 | void IconRenderer::DestroyShortcutTextures() |
543 | { |
544 | - for (auto texture : local::label_map) |
545 | - texture.second->UnReference(); |
546 | - local::label_map.clear(); |
547 | + TexturesPool::Get()->labels.clear(); |
548 | } |
549 | |
550 | void IconRenderer::GetInverseScreenPerspectiveMatrix(nux::Matrix4& ViewMatrix, nux::Matrix4& PerspectiveMatrix, |
551 | @@ -1165,12 +1181,57 @@ |
552 | PerspectiveMatrix.Perspective(Fovy, AspectRatio, NearClipPlane, FarClipPlane); |
553 | } |
554 | |
555 | -// The local namespace is purely for namespacing the file local variables below. |
556 | -namespace local |
557 | -{ |
558 | -namespace |
559 | -{ |
560 | -void setup_shaders() |
561 | +IconRenderer::TexturesPool::TexturesPool() |
562 | + : offscreen_progress_texture(nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(2, 2, 1, nux::BITFMT_R8G8B8A8)) |
563 | +{ |
564 | + LoadTexture(progress_bar_trough, PKGDATADIR"/progress_bar_trough.png"); |
565 | + LoadTexture(progress_bar_fill, PKGDATADIR"/progress_bar_fill.png"); |
566 | + LoadTexture(pip_ltr, PKGDATADIR"/launcher_pip_ltr.png"); |
567 | + LoadTexture(large_pip_ltr, PKGDATADIR"/launcher_pip_large_ltr.png"); |
568 | + // LoadTexture(pip_rtl, PKGDATADIR"/launcher_pip_rtl.png"); |
569 | + // LoadTexture(large_pip_rtl, PKGDATADIR"/launcher_pip_large_rtl.png"); |
570 | + LoadTexture(arrow_ltr, PKGDATADIR"/launcher_arrow_ltr.png"); |
571 | + LoadTexture(arrow_rtl, PKGDATADIR"/launcher_arrow_rtl.png"); |
572 | + LoadTexture(arrow_empty_ltr, PKGDATADIR"/launcher_arrow_outline_ltr.png"); |
573 | + // LoadTexture(arrow_empty_rtl, PKGDATADIR"/launcher_arrow_outline_rtl.png"); |
574 | + |
575 | + // LoadTexture(squircle_base, PKGDATADIR"/squircle_base_54.png"); |
576 | + // LoadTexture(squircle_base_selected, PKGDATADIR"/squircle_base_selected_54.png"); |
577 | + // LoadTexture(squircle_edge, PKGDATADIR"/squircle_edge_54.png"); |
578 | + // LoadTexture(squircle_glow, PKGDATADIR"/squircle_glow_62.png"); |
579 | + // LoadTexture(squircle_shadow, PKGDATADIR"/squircle_shadow_62.png"); |
580 | + // LoadTexture(squircle_shine, PKGDATADIR"/squircle_shine_54.png"); |
581 | + |
582 | + // BaseTexturePtr icon_background[local::IconSize::SIZE]; |
583 | + // BaseTexturePtr icon_selected_background[local::IconSize::SIZE]; |
584 | + // BaseTexturePtr icon_edge[local::IconSize::SIZE]; |
585 | + // BaseTexturePtr icon_glow[local::IconSize::SIZE]; |
586 | + // BaseTexturePtr icon_shadow[local::IconSize::SIZE]; |
587 | + // BaseTexturePtr icon_shine[local::IconSize::SIZE]; |
588 | + |
589 | + GenerateTextures(icon_background, |
590 | + PKGDATADIR"/launcher_icon_back_150.png", |
591 | + PKGDATADIR"/launcher_icon_back_54.png"); |
592 | + GenerateTextures(icon_selected_background, |
593 | + PKGDATADIR"/launcher_icon_selected_back_150.png", |
594 | + PKGDATADIR"/launcher_icon_back_54.png"); |
595 | + GenerateTextures(icon_edge, |
596 | + PKGDATADIR"/launcher_icon_edge_150.png", |
597 | + PKGDATADIR"/launcher_icon_edge_54.png"); |
598 | + GenerateTextures(icon_glow, |
599 | + PKGDATADIR"/launcher_icon_glow_200.png", |
600 | + PKGDATADIR"/launcher_icon_glow_62.png"); |
601 | + GenerateTextures(icon_shadow, |
602 | + PKGDATADIR"/launcher_icon_shadow_200.png", |
603 | + PKGDATADIR"/launcher_icon_shadow_62.png"); |
604 | + GenerateTextures(icon_shine, |
605 | + PKGDATADIR"/launcher_icon_shine_150.png", |
606 | + PKGDATADIR"/launcher_icon_shine_54.png"); |
607 | + |
608 | + SetupShaders(); |
609 | +} |
610 | + |
611 | +void IconRenderer::TexturesPool::SetupShaders() |
612 | { |
613 | if (nux::GetWindowThread()->GetGraphicsEngine().UsingGLSLCodePath()) |
614 | { |
615 | @@ -1201,111 +1262,5 @@ |
616 | } |
617 | } |
618 | |
619 | - |
620 | -inline nux::BaseTexture* load_texture(const char* filename) |
621 | -{ |
622 | - return nux::CreateTexture2DFromFile(filename, -1, true); |
623 | -} |
624 | - |
625 | -void generate_textures(std::vector<nux::BaseTexture*>& icons, const char* big_file, const char* small_file) |
626 | -{ |
627 | - icons.resize(IconSize::LAST); |
628 | - icons[IconSize::BIG] = load_texture(big_file); |
629 | - icons[IconSize::SMALL] = load_texture(small_file); |
630 | -} |
631 | - |
632 | -void generate_textures() |
633 | -{ |
634 | - progress_bar_trough = load_texture(PKGDATADIR"/progress_bar_trough.png"); |
635 | - progress_bar_fill = load_texture(PKGDATADIR"/progress_bar_fill.png"); |
636 | - |
637 | - generate_textures(icon_background, |
638 | - PKGDATADIR"/launcher_icon_back_150.png", |
639 | - PKGDATADIR"/launcher_icon_back_54.png"); |
640 | - generate_textures(icon_selected_background, |
641 | - PKGDATADIR"/launcher_icon_selected_back_150.png", |
642 | - PKGDATADIR"/launcher_icon_back_54.png"); |
643 | - generate_textures(icon_edge, |
644 | - PKGDATADIR"/launcher_icon_edge_150.png", |
645 | - PKGDATADIR"/launcher_icon_edge_54.png"); |
646 | - generate_textures(icon_glow, |
647 | - PKGDATADIR"/launcher_icon_glow_200.png", |
648 | - PKGDATADIR"/launcher_icon_glow_62.png"); |
649 | - generate_textures(icon_shadow, |
650 | - PKGDATADIR"/launcher_icon_shadow_200.png", |
651 | - PKGDATADIR"/launcher_icon_shadow_62.png"); |
652 | - generate_textures(icon_shine, |
653 | - PKGDATADIR"/launcher_icon_shine_150.png", |
654 | - PKGDATADIR"/launcher_icon_shine_54.png"); |
655 | - |
656 | - // squircle_base = load_texture(PKGDATADIR"/squircle_base_54.png"); |
657 | - // squircle_base_selected = load_texture(PKGDATADIR"/squircle_base_selected_54.png"); |
658 | - // squircle_edge = load_texture(PKGDATADIR"/squircle_edge_54.png"); |
659 | - // squircle_glow = load_texture(PKGDATADIR"/squircle_glow_62.png"); |
660 | - // squircle_shadow = load_texture(PKGDATADIR"/squircle_shadow_62.png"); |
661 | - // squircle_shine = load_texture(PKGDATADIR"/squircle_shine_54.png"); |
662 | - |
663 | - pip_ltr = load_texture(PKGDATADIR"/launcher_pip_ltr.png"); |
664 | - large_pip_ltr = load_texture(PKGDATADIR"/launcher_pip_large_ltr.png"); |
665 | - arrow_ltr = load_texture(PKGDATADIR"/launcher_arrow_ltr.png"); |
666 | - arrow_empty_ltr = load_texture(PKGDATADIR"/launcher_arrow_outline_ltr.png"); |
667 | - |
668 | - pip_rtl = load_texture(PKGDATADIR"/launcher_pip_rtl.png"); |
669 | - large_pip_rtl = load_texture(PKGDATADIR"/launcher_pip_large_rt.png"); |
670 | - arrow_rtl = load_texture(PKGDATADIR"/launcher_arrow_rtl.png"); |
671 | - arrow_empty_rtl = load_texture(PKGDATADIR"/launcher_arrow_outline_rtl.png"); |
672 | - |
673 | - offscreen_progress_texture = nux::GetGraphicsDisplay()->GetGpuDevice() |
674 | - ->CreateSystemCapableDeviceTexture(2, 2, 1, nux::BITFMT_R8G8B8A8); |
675 | - |
676 | - setup_shaders(); |
677 | - textures_created = true; |
678 | -} |
679 | - |
680 | -void destroy_textures(std::vector<nux::BaseTexture*>& icons) |
681 | -{ |
682 | - icons[SMALL]->UnReference(); |
683 | - icons[BIG]->UnReference(); |
684 | - icons.clear(); |
685 | -} |
686 | - |
687 | -void destroy_textures() |
688 | -{ |
689 | - if (!textures_created) |
690 | - return; |
691 | - |
692 | - progress_bar_trough->UnReference(); |
693 | - progress_bar_fill->UnReference(); |
694 | - pip_ltr->UnReference(); |
695 | - pip_rtl->UnReference(); |
696 | - large_pip_ltr->UnReference(); |
697 | - large_pip_rtl->UnReference(); |
698 | - arrow_ltr->UnReference(); |
699 | - arrow_rtl->UnReference(); |
700 | - arrow_empty_ltr->UnReference(); |
701 | - arrow_empty_rtl->UnReference(); |
702 | - |
703 | - destroy_textures(icon_background); |
704 | - destroy_textures(icon_selected_background); |
705 | - destroy_textures(icon_edge); |
706 | - destroy_textures(icon_glow); |
707 | - destroy_textures(icon_shadow); |
708 | - destroy_textures(icon_shine); |
709 | - |
710 | - // squircle_base->UnReference(); |
711 | - // squircle_base_selected->UnReference(); |
712 | - // squircle_edge->UnReference(); |
713 | - // squircle_glow->UnReference(); |
714 | - // squircle_shadow->UnReference(); |
715 | - // squircle_shine->UnReference(); |
716 | - |
717 | - IconRenderer::DestroyShortcutTextures(); |
718 | - |
719 | - textures_created = false; |
720 | -} |
721 | - |
722 | -} // anon namespace |
723 | -} // namespace local |
724 | - |
725 | } // namespace ui |
726 | } // namespace unity |
727 | |
728 | === modified file 'unity-shared/IconRenderer.h' |
729 | --- unity-shared/IconRenderer.h 2012-11-05 17:56:56 +0000 |
730 | +++ unity-shared/IconRenderer.h 2013-03-19 13:21:04 +0000 |
731 | @@ -45,12 +45,9 @@ |
732 | |
733 | void SetTargetSize(int tile_size, int image_size, int spacing); |
734 | |
735 | - static void DestroyTextures(); |
736 | static void DestroyShortcutTextures(); |
737 | |
738 | protected: |
739 | - nux::BaseTexture* RenderCharToTexture(char label, int width, int height, nux::Color const& bg_color); |
740 | - |
741 | void RenderElement(nux::GraphicsEngine& GfxContext, |
742 | RenderArg const& arg, |
743 | nux::ObjectPtr<nux::IOpenGLBaseTexture> const& icon, |
744 | @@ -90,6 +87,8 @@ |
745 | int image_size; |
746 | int spacing; |
747 | |
748 | + struct TexturesPool; |
749 | + std::shared_ptr<TexturesPool> textures_; |
750 | nux::Matrix4 _stored_projection_matrix; |
751 | }; |
752 |