diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-25 01:08:39 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-25 01:08:39 +0000 |
commit | e607e65e5b0502ff0dd86d15c7cd173aaddbe129 (patch) | |
tree | 21c8cf71e9ef8c59dd3ec3eb165f13f8c1f29ec8 /ash/desktop_background/desktop_background_view.cc | |
parent | 332b4d309224fddf3abd89a7c8e2197bf950139f (diff) | |
download | chromium_src-e607e65e5b0502ff0dd86d15c7cd173aaddbe129.zip chromium_src-e607e65e5b0502ff0dd86d15c7cd173aaddbe129.tar.gz chromium_src-e607e65e5b0502ff0dd86d15c7cd173aaddbe129.tar.bz2 |
* Use correct bounds to pick and resize wallpaper image
* Use separate layer to draw wallpaper and scale it,
rather than scaling at drawing time, which uses more CPU and memory.
* Changed ctrl-alt-b behavior so that it uses fixed image with different layouts.
BUG=294479
TEST=manual + unittests.
R=derat@chromium.org
Review URL: https://codereview.chromium.org/24269015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@225116 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/desktop_background/desktop_background_view.cc')
-rw-r--r-- | ash/desktop_background/desktop_background_view.cc | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/ash/desktop_background/desktop_background_view.cc b/ash/desktop_background/desktop_background_view.cc index b46109f..db1b27d 100644 --- a/ash/desktop_background/desktop_background_view.cc +++ b/ash/desktop_background/desktop_background_view.cc @@ -23,6 +23,8 @@ #include "ui/compositor/layer.h" #include "ui/gfx/canvas.h" #include "ui/gfx/image/image.h" +#include "ui/gfx/size_conversions.h" +#include "ui/gfx/transform.h" #include "ui/views/widget/widget.h" namespace ash { @@ -34,6 +36,41 @@ int RoundPositive(double x) { return static_cast<int>(floor(x + 0.5)); } +// A view that controls the child view's layer so that the layer +// always has the same size as the display's original, un-scaled size +// in DIP. The layer then transformed to fit to the virtual screen +// size when laid-out. +// This is to avoid scaling the image at painting time, then scaling +// it back to the screen size in the compositor. +class LayerControlView : public views::View { + public: + explicit LayerControlView(views::View* view) { + AddChildView(view); + view->SetPaintToLayer(true); + } + + // Overrides views::View. + virtual void Layout() OVERRIDE { + gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( + GetWidget()->GetNativeView()); + DisplayManager* display_manager = Shell::GetInstance()->display_manager(); + DisplayInfo info = display_manager->GetDisplayInfo(display.id()); + + gfx::SizeF pixel_size = display.size(); + pixel_size.Scale(1.0f / info.ui_scale()); + gfx::Size rounded_size = gfx::ToCeiledSize(pixel_size); + DCHECK_EQ(1, child_count()); + views::View* child = child_at(0); + child->SetBounds(0, 0, rounded_size.width(), rounded_size.height()); + gfx::Transform transform; + transform.Scale(info.ui_scale(), info.ui_scale()); + child->SetTransform(transform); + } + + private: + DISALLOW_COPY_AND_ASSIGN(LayerControlView); +}; + } // namespace //////////////////////////////////////////////////////////////////////////////// @@ -151,7 +188,8 @@ views::Widget* CreateDesktopBackground(aura::RootWindow* root_window, params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; params.parent = root_window->GetChildById(container_id); desktop_widget->Init(params); - desktop_widget->SetContentsView(new DesktopBackgroundView()); + desktop_widget->SetContentsView( + new LayerControlView(new DesktopBackgroundView())); int animation_type = wallpaper_delegate->GetAnimationType(); views::corewm::SetWindowVisibilityAnimationType( desktop_widget->GetNativeView(), animation_type); |