diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2014-08-27 14:25:40 +0200 |
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2014-08-27 14:25:40 +0200 |
| commit | 4e764f30ef47f7c59c7699c6b4414e47aafd5e13 (patch) | |
| tree | 91962655a5648233c40040b0756ff858898f5951 | |
| parent | 787d8f0693125ddae93baf6738416963429a1da1 (diff) | |
IconRenderer: share the icon labels only if they've the same size in multiple instances
Otherwise generate each one for the provided size. (bzr r3860.2.2)
| -rw-r--r-- | launcher/Launcher.cpp | 2 | ||||
| -rw-r--r-- | unity-shared/IconRenderer.cpp | 60 | ||||
| -rw-r--r-- | unity-shared/IconRenderer.h | 2 |
3 files changed, 29 insertions, 35 deletions
diff --git a/launcher/Launcher.cpp b/launcher/Launcher.cpp index 088df4d75..524074527 100644 --- a/launcher/Launcher.cpp +++ b/launcher/Launcher.cpp @@ -1516,8 +1516,6 @@ void Launcher::SetLauncherMinimizeWindow(bool click_to_minimize) void Launcher::SetIconSize(int tile_size, int icon_size) { - ui::IconRenderer::DestroyShortcutTextures(); - icon_size_ = tile_size; icon_renderer_->scale = cv_->DPIScale(); icon_renderer_->SetTargetSize(icon_size_.CP(cv_), RawPixel(icon_size).CP(cv_), SPACE_BETWEEN_ICONS.CP(cv_)); diff --git a/unity-shared/IconRenderer.cpp b/unity-shared/IconRenderer.cpp index 9b38fa6c5..4e90a3615 100644 --- a/unity-shared/IconRenderer.cpp +++ b/unity-shared/IconRenderer.cpp @@ -32,6 +32,7 @@ #include "unity-shared/DecorationStyle.h" #include "unity-shared/TextureCache.h" #include "unity-shared/UnitySettings.h" +#include "unity-shared/WindowManager.h" #include "GraphicsUtils.h" #include <gtk/gtk.h> @@ -211,7 +212,6 @@ struct IconRenderer::TexturesPool return instance; } - nux::ObjectPtr<nux::BaseTexture> RenderLabelTexture(char label, int icon_size, nux::Color const& bg_color); nux::ObjectPtr<nux::IOpenGLBaseTexture> offscreen_progress_texture; nux::ObjectPtr<nux::IOpenGLShaderProgram> shader_program_uv_persp_correction; #ifndef USE_GLES @@ -225,8 +225,6 @@ struct IconRenderer::TexturesPool int ColorifyColor; int DesatFactor; - std::map<char, BaseTexturePtr> labels; - private: TexturesPool(); @@ -250,18 +248,18 @@ struct IconRenderer::LocalTextures LocalTextures(IconRenderer* parent) : parent_(parent) { - theme_conn_ = decoration::Style::Get()->theme.changed.connect([this] (std::string const&) { + connections_.Add(decoration::Style::Get()->theme.changed.connect([this] (std::string const&) { auto& cache = TextureCache::GetDefault(); for (auto const& tex_data : texture_files_) cache.Invalidate(tex_data.name, tex_data.size, tex_data.size); ReloadIconSizedTextures(parent_->icon_size, parent_->image_size); - }); + })); - font_scaling_conn_ = Settings::Instance().font_scaling.changed.connect([] (double) { - ui::IconRenderer::DestroyShortcutTextures(); - }); + auto clear_labels = sigc::hide(sigc::mem_fun(this, &LocalTextures::ClearLabels)); + connections_.Add(Settings::Instance().font_scaling.changed.connect(clear_labels)); + connections_.Add(WindowManager::Default().average_color.changed.connect(clear_labels)); } void ReloadIconSizedTextures(int icon_size, int image_size) @@ -303,6 +301,22 @@ struct IconRenderer::LocalTextures *tex_data.tex_ptr = cache.FindTexture(tex_data.name, tex_data.size, tex_data.size, texture_loader); } + nux::BaseTexture* RenderLabelTexture(char label, int icon_size, nux::Color const&); + + BaseTexturePtr const& GetLabelTexture(char label, int icon_size, nux::Color const& color) + { + labels_.push_back(TextureCache::GetDefault().FindTexture(std::string(1, label), icon_size, icon_size, [this, &color] (std::string const& label, int size, int) { + return RenderLabelTexture(label[0], size, color); + })); + + return labels_.back(); + } + + void ClearLabels() + { + labels_.clear(); + } + BaseTexturePtr icon_background; BaseTexturePtr icon_selected_background; BaseTexturePtr icon_edge; @@ -320,8 +334,8 @@ private: IconRenderer* parent_; struct TextureData { BaseTexturePtr* tex_ptr; std::string name; int size; }; std::vector<TextureData> texture_files_; - connection::Wrapper theme_conn_; - connection::Wrapper font_scaling_conn_; + std::vector<BaseTexturePtr> labels_; + connection::Manager connections_; }; IconRenderer::IconRenderer() @@ -341,6 +355,7 @@ void IconRenderer::SetTargetSize(int tile_size, int image_size_, int spacing_) icon_size = tile_size; image_size = image_size_; local_textures_->ReloadIconSizedTextures(icon_size, image_size); + local_textures_->ClearLabels(); } spacing = spacing_; @@ -747,20 +762,8 @@ void IconRenderer::RenderIcon(nux::GraphicsEngine& GfxContext, RenderArg const& // draw superkey-shortcut label if (arg.draw_shortcut && arg.shortcut_label) { - char shortcut = (char) arg.shortcut_label; - - BaseTexturePtr label; - auto label_it = textures_->labels.find(shortcut); - - if (label_it != textures_->labels.end()) - { - label = label_it->second; - } - else - { - label = textures_->RenderLabelTexture(shortcut, icon_size, shortcut_color); - textures_->labels[shortcut] = label; - } + char shortcut = static_cast<char>(arg.shortcut_label); + auto const& label = local_textures_->GetLabelTexture(shortcut, icon_size, shortcut_color); RenderElement(GfxContext, arg, @@ -773,7 +776,7 @@ void IconRenderer::RenderIcon(nux::GraphicsEngine& GfxContext, RenderArg const& } } -nux::ObjectPtr<nux::BaseTexture> IconRenderer::TexturesPool::RenderLabelTexture(char label, int icon_size, nux::Color const& bg_color) +nux::BaseTexture* IconRenderer::LocalTextures::RenderLabelTexture(char label, int icon_size, nux::Color const& bg_color) { nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, icon_size, icon_size); cairo_t* cr = cg.GetInternalContext(); @@ -817,7 +820,7 @@ nux::ObjectPtr<nux::BaseTexture> IconRenderer::TexturesPool::RenderLabelTexture( cairo_move_to(cr, x, y); pango_cairo_show_layout(cr, layout); - return texture_ptr_from_cairo_graphics(cg); + return texture_from_cairo_graphics(cg); } void IconRenderer::RenderElement(nux::GraphicsEngine& GfxContext, @@ -1159,11 +1162,6 @@ void IconRenderer::RenderProgressToTexture(nux::GraphicsEngine& GfxContext, unity::graphics::PopOffscreenRenderTarget(); } -void IconRenderer::DestroyShortcutTextures() -{ - TexturesPool::Get()->labels.clear(); -} - void IconRenderer::GetInverseScreenPerspectiveMatrix(nux::Matrix4& ViewMatrix, nux::Matrix4& PerspectiveMatrix, int ViewportWidth, int ViewportHeight, diff --git a/unity-shared/IconRenderer.h b/unity-shared/IconRenderer.h index 733f9a1cf..50ab20e29 100644 --- a/unity-shared/IconRenderer.h +++ b/unity-shared/IconRenderer.h @@ -44,8 +44,6 @@ public: void SetTargetSize(int tile_size, int image_size, int spacing); - static void DestroyShortcutTextures(); - protected: void RenderElement(nux::GraphicsEngine& GfxContext, RenderArg const& arg, |
