diff options
| author | Gord Allott <gord.allott@canonical.com> | 2012-08-10 16:13:35 +0100 |
|---|---|---|
| committer | Gord Allott <gord.allott@canonical.com> | 2012-08-10 16:13:35 +0100 |
| commit | 19a9ad3b86b55fbe09dd8003a21ee61c260c5c20 (patch) | |
| tree | e73bebe4dba1cbae73eddc9a153040365e296678 /unity-shared | |
| parent | c3f1515c91ccbd3b1d6e6ea8cc9f695e8320beac (diff) | |
| parent | 4af96d27e4489a8c61dbf26db116cca66b3a8f0d (diff) | |
latest preview ui code
(bzr r2419.6.21)
Diffstat (limited to 'unity-shared')
| -rw-r--r-- | unity-shared/CoverArt.cpp | 86 | ||||
| -rw-r--r-- | unity-shared/CoverArt.h | 1 | ||||
| -rw-r--r-- | unity-shared/IconLoader.cpp | 21 | ||||
| -rw-r--r-- | unity-shared/PreviewStyle.cpp | 106 | ||||
| -rw-r--r-- | unity-shared/PreviewStyle.h | 7 | ||||
| -rw-r--r-- | unity-shared/ThumbnailGenerator.cpp | 21 |
6 files changed, 120 insertions, 122 deletions
diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index 5854fdbfe..c6949d499 100644 --- a/unity-shared/CoverArt.cpp +++ b/unity-shared/CoverArt.cpp @@ -86,49 +86,20 @@ void CoverArt::SetImage(std::string const& image_hint) GIcon* icon = g_icon_new_for_string(image_hint.c_str(), NULL); - glib::Object<GFile> image_file; - if (g_strrstr(image_hint.c_str(), "://")) + bool bLoadTexture = false; + bLoadTexture |= g_strrstr(image_hint.c_str(), "://") != NULL; + if (!bLoadTexture && !image_hint.empty()) { - /* try to open the source file for reading */ - image_file = g_file_new_for_uri (image_hint.c_str()); + bLoadTexture |= image_hint[0] == '/' && image_hint.size() > 1; } - else - { - image_file = g_file_new_for_path (image_hint.c_str()); - } - - if (g_file_query_exists(image_file, NULL)) - { - // for files on disk, we stretch to maximum aspect ratio. - stretch_image_ = true; - GFileInputStream *stream; - GError *error = NULL; - - stream = g_file_read (image_file, NULL, &error); - - if (error != NULL) - { - g_error_free (error); - - if (icon != NULL) - g_object_unref(icon); - return; - } - - /* stream image into pixel-buffer. */ - glib::Object<GdkPixbuf> pixbuf(gdk_pixbuf_new_from_stream (G_INPUT_STREAM (stream), NULL, &error)); - g_object_unref (stream); - - texture_screenshot_.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true)); - - if (!texture_screenshot_) - { - SetNoImageAvailable(); - } - QueueDraw(); + // texture from file. + if (bLoadTexture) + { + StartWaiting(); + slot_handle_ = IconLoader::GetDefault().LoadFromGIconString(image_hint, ~0, sigc::mem_fun(this, &CoverArt::TextureLoaded)); } - else + else if (!image_hint.empty()) { if (GetLayout()) GetLayout()->RemoveChildObject(overlay_text_); @@ -144,6 +115,10 @@ void CoverArt::SetImage(std::string const& image_hint) slot_handle_ = IconLoader::GetDefault().LoadFromIconName(image_hint, icon_width, sigc::mem_fun(this, &CoverArt::IconLoaded)); } } + else + { + SetNoImageAvailable(); + } if (icon != NULL) g_object_unref(icon); @@ -262,11 +237,6 @@ void CoverArt::IconLoaded(std::string const& texid, unsigned size, glib::Object< cairo_paint(cr); float scale = float(pixbuf_height) / gdk_pixbuf_get_height(pixbuf); - - //cairo_translate(cr, - // static_cast<int>((width - (pixbuf_width * scale)) * 0.5), - // static_cast<int>((height - (pixbuf_height * scale)) * 0.5)); - cairo_scale(cr, scale, scale); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); @@ -278,6 +248,22 @@ void CoverArt::IconLoaded(std::string const& texid, unsigned size, glib::Object< } } +void CoverArt::TextureLoaded(std::string const& texid, unsigned size, glib::Object<GdkPixbuf> const& pixbuf) +{ + // Finished waiting + spinner_timeout_.reset(); + frame_timeout_.reset(); + waiting_ = false; + stretch_image_ = true; + + if (!pixbuf) + { + SetNoImageAvailable(); + return; + } + texture_screenshot_.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true)); +} + void CoverArt::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) { nux::Geometry const& base = GetGeometry(); @@ -287,13 +273,13 @@ void CoverArt::Draw(nux::GraphicsEngine& gfx_engine, bool force_draw) unsigned int alpha, src, dest = 0; gfx_engine.GetRenderStates().GetBlend(alpha, src, dest); - gfx_engine.GetRenderStates().SetBlend(true); + gfx_engine.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - gfx_engine.QRP_Color(base.x, - base.y, - base.GetWidth(), - base.GetHeight(), - nux::Color(0.03f, 0.03f, 0.03f, 0.0f)); + gfx_engine.QRP_Color(base.x, + base.y, + base.GetWidth(), + base.GetHeight(), + nux::Color(0.03f, 0.03f, 0.03f, 0.0f)); if (texture_screenshot_) { diff --git a/unity-shared/CoverArt.h b/unity-shared/CoverArt.h index 13b33cb25..dd5a666fe 100644 --- a/unity-shared/CoverArt.h +++ b/unity-shared/CoverArt.h @@ -69,6 +69,7 @@ protected: bool OnFrameTimeout(); void IconLoaded(std::string const& texid, unsigned size, glib::Object<GdkPixbuf> const& pixbuf); + void TextureLoaded(std::string const& texid, unsigned size, glib::Object<GdkPixbuf> const& pixbuf); void StartWaiting(); void SetNoImageAvailable(); diff --git a/unity-shared/IconLoader.cpp b/unity-shared/IconLoader.cpp index 2627d914c..78c9e9ea9 100644 --- a/unity-shared/IconLoader.cpp +++ b/unity-shared/IconLoader.cpp @@ -268,12 +268,21 @@ private: glib::Object<GInputStream> stream( ::g_memory_input_stream_new_from_data(contents.Value(), length, nullptr)); - task->result = ::gdk_pixbuf_new_from_stream_at_scale(stream, - -1, - task->size, - TRUE, - canc, - &task->error); + if (task->size != static_cast<unsigned int>(~0)) + { + task->result = ::gdk_pixbuf_new_from_stream_at_scale(stream, + -1, + task->size, + TRUE, + canc, + &task->error); + } + else + { + task->result = ::gdk_pixbuf_new_from_stream(stream, + canc, + &task->error); + } ::g_input_stream_close(stream, canc, nullptr); } } diff --git a/unity-shared/PreviewStyle.cpp b/unity-shared/PreviewStyle.cpp index 8dd27c8df..56e55bb4a 100644 --- a/unity-shared/PreviewStyle.cpp +++ b/unity-shared/PreviewStyle.cpp @@ -41,17 +41,45 @@ nux::logging::Logger logger("unity.dash.previews.style"); typedef nux::ObjectPtr<nux::BaseTexture> BaseTexturePtr; +template <int default_size = 1> class LazyLoadTexture { public: - LazyLoadTexture(std::string const& filename, int size = -1); - nux::BaseTexture* texture(); + LazyLoadTexture(std::string const& filename) + : filename_(filename) {} + + nux::BaseTexture* texture(int size = default_size) + { + auto tex_iter = textures_.find(size); + if (tex_iter != textures_.end()) + return tex_iter->second.GetPointer(); + + return LoadTexture(size).GetPointer(); + } + private: - void LoadTexture(); + BaseTexturePtr LoadTexture(int size) + { + BaseTexturePtr texture; + std::string full_path = PKGDATADIR + filename_; + glib::Object<GdkPixbuf> pixbuf; + glib::Error error; + + pixbuf = ::gdk_pixbuf_new_from_file_at_size(full_path.c_str(), size, size, &error); + if (error) + { + LOG_WARN(logger) << "Unable to texture " << full_path << " at size '" << size << "' : " << error; + } + else + { + texture.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true)); + } + textures_[size] = texture; + return texture; + } private: std::string filename_; - int size_; - BaseTexturePtr texture_; + std::map<int, BaseTexturePtr> textures_; }; } // namespace @@ -62,20 +90,22 @@ class Style::Impl public: Impl(Style* owner) : owner_(owner) - , preview_nav_left_texture_("/preview_previous.svg", 32) - , preview_nav_right_texture_("/preview_next.svg", 32) - , preview_play_texture_("/preview_play.svg", 32) - , preview_pause_texture_("/preview_pause.svg", 32) + , preview_nav_left_texture_("/preview_previous.svg") + , preview_nav_right_texture_("/preview_next.svg") + , preview_play_texture_("/preview_play.svg") + , preview_pause_texture_("/preview_pause.svg") + , preview_spin_texture_("/search_spin.svg") { } ~Impl() {} Style* owner_; - LazyLoadTexture preview_nav_left_texture_; - LazyLoadTexture preview_nav_right_texture_; - LazyLoadTexture preview_play_texture_; - LazyLoadTexture preview_pause_texture_; + LazyLoadTexture<32> preview_nav_left_texture_; + LazyLoadTexture<32> preview_nav_right_texture_; + LazyLoadTexture<32> preview_play_texture_; + LazyLoadTexture<32> preview_pause_texture_; + LazyLoadTexture<32> preview_spin_texture_; }; @@ -118,14 +148,9 @@ int Style::GetNavigatorIconSize() const return 24; } -int Style::GetPreviewPreferredHeight() const +float Style::GetPreviewAspectRatio() const { - return 390; -} - -int Style::GetPreviewPreferredWidth() const -{ - return 796; + return static_cast<float>(796)/390; } int Style::GetDetailsTopMargin() const @@ -213,11 +238,16 @@ int Style::GetInfoHintIconSizeWidth() const return 24; } -int Style::GetInfoHintNameWidth() const +int Style::GetInfoHintNameMinimumWidth() const { return 100; } +int Style::GetInfoHintNameMaximumWidth() const +{ + return 160; +} + float Style::GetDescriptionLineSpacing() const { return 2.0; @@ -320,41 +350,11 @@ nux::BaseTexture* Style::GetPauseIcon() return pimpl->preview_pause_texture_.texture(); } - - -namespace -{ -LazyLoadTexture::LazyLoadTexture(std::string const& filename, int size) - : filename_(filename) - , size_(size) -{ -} - -nux::BaseTexture* LazyLoadTexture::texture() -{ - if (!texture_) - LoadTexture(); - return texture_.GetPointer(); -} - -void LazyLoadTexture::LoadTexture() +nux::BaseTexture* Style::GetSearchSpinIcon(int size) { - std::string full_path = PKGDATADIR + filename_; - glib::Object<GdkPixbuf> pixbuf; - glib::Error error; - - pixbuf = ::gdk_pixbuf_new_from_file_at_size(full_path.c_str(), size_, size_, &error); - if (error) - { - LOG_WARN(logger) << "Unable to texture " << full_path << ": " << error; - } - else - { - texture_.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true)); - } + return pimpl->preview_spin_texture_.texture(size); } -} // namesspace } // namespace previews } // namespace dash diff --git a/unity-shared/PreviewStyle.h b/unity-shared/PreviewStyle.h index a63a5b3de..23c9ba2f8 100644 --- a/unity-shared/PreviewStyle.h +++ b/unity-shared/PreviewStyle.h @@ -59,8 +59,7 @@ public: int GetNavigatorWidth() const; int GetNavigatorIconSize() const; - int GetPreviewPreferredHeight() const; - int GetPreviewPreferredWidth() const; + float GetPreviewAspectRatio() const; int GetDetailsTopMargin() const; int GetDetailsBottomMargin() const; @@ -77,7 +76,8 @@ public: int GetDetailsPanelMinimumWidth() const; int GetInfoHintIconSizeWidth() const; - int GetInfoHintNameWidth() const; + int GetInfoHintNameMinimumWidth() const; + int GetInfoHintNameMaximumWidth() const; float GetDescriptionLineSpacing() const; int GetDescriptionLineCount() const; @@ -124,6 +124,7 @@ public: nux::BaseTexture* GetNavRightIcon(); nux::BaseTexture* GetPlayIcon(); nux::BaseTexture* GetPauseIcon(); + nux::BaseTexture* GetSearchSpinIcon(int size = -1); protected: class Impl; diff --git a/unity-shared/ThumbnailGenerator.cpp b/unity-shared/ThumbnailGenerator.cpp index e94d0d5af..0245f5f03 100644 --- a/unity-shared/ThumbnailGenerator.cpp +++ b/unity-shared/ThumbnailGenerator.cpp @@ -119,8 +119,8 @@ private: private: ThumbnailGenerator* parent_; - glib::Source::UniquePtr idle_; - glib::Source::UniquePtr idle_return_; + glib::Source::UniquePtr thread_create_timer_; + glib::Source::UniquePtr thread_return_timer_; /* Our mutex used when accessing data shared between the main thread and the thumbnail thread, i.e. the thumbnail_thread_is_running flag and the @@ -179,9 +179,9 @@ ThumbnailNotifier::Ptr ThumbnailGeneratorImpl::GetThumbnail(std::string const& u complete_thumbnails_.push_back(complete_thumb); // Delay the thumbnail update until after this method has returned with the notifier - if (!idle_return_) + if (!thread_return_timer_) { - idle_return_.reset(new glib::Idle(sigc::mem_fun(this, &ThumbnailGeneratorImpl::OnThumbnailComplete), glib::Source::Priority::LOW)); + thread_return_timer_.reset(new glib::Timeout(0, sigc::mem_fun(this, &ThumbnailGeneratorImpl::OnThumbnailComplete), glib::Source::Priority::LOW)); } pthread_mutex_unlock (&thumbnails_mutex_); @@ -196,13 +196,14 @@ ThumbnailNotifier::Ptr ThumbnailGeneratorImpl::GetThumbnail(std::string const& u * MUTEX LOCKED *********************************/ - if (!idle_ && thumbnail_thread_is_running_ == false) + if (!thread_create_timer_ && thumbnail_thread_is_running_ == false) { - idle_.reset(new glib::Idle([&]() + + thread_create_timer_.reset(new glib::Timeout(0, [&]() { thumbnail_thread_is_running_ = true; pthread_create (&thumbnail_thread_, NULL, thumbnail_thread_start, this); - idle_.reset(); + thread_create_timer_.reset(); return false; }, glib::Source::Priority::LOW)); } @@ -271,9 +272,9 @@ void ThumbnailGeneratorImpl::RunGenerate() complete_thumbnails_.push_back(complete_thumb); - if (!idle_return_) + if (!thread_return_timer_) { - idle_return_.reset(new glib::Idle(sigc::mem_fun(this, &ThumbnailGeneratorImpl::OnThumbnailComplete), glib::Source::Priority::LOW)); + thread_return_timer_.reset(new glib::Timeout(0, sigc::mem_fun(this, &ThumbnailGeneratorImpl::OnThumbnailComplete), glib::Source::Priority::LOW)); } pthread_mutex_unlock (&thumbnails_mutex_); @@ -291,7 +292,7 @@ bool ThumbnailGeneratorImpl::OnThumbnailComplete() if (complete_thumbnails_.size() == 0) { - idle_return_.reset(); + thread_return_timer_.reset(); pthread_mutex_unlock (&thumbnails_mutex_); return false; } |
