summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorxdai <xdai@chromium.org>2015-09-01 08:11:07 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-01 15:11:44 +0000
commitad3ad5a38f5eba345eb36066a549bf22e19a3471 (patch)
tree429f65b0766811d2b0c109f816c93cfe2782931f /ash
parent623b5c6a0bd065b2442dc1ea17ba6b3b05fbf042 (diff)
downloadchromium_src-ad3ad5a38f5eba345eb36066a549bf22e19a3471.zip
chromium_src-ad3ad5a38f5eba345eb36066a549bf22e19a3471.tar.gz
chromium_src-ad3ad5a38f5eba345eb36066a549bf22e19a3471.tar.bz2
Always fit the wallpaper to the native display resolution when the layout is WALLPAPER_LAYOUT_CENTER to prevent blurry image.
BUG=515660 Review URL: https://codereview.chromium.org/1268853006 Cr-Commit-Position: refs/heads/master@{#346657}
Diffstat (limited to 'ash')
-rw-r--r--ash/desktop_background/desktop_background_controller_unittest.cc110
-rw-r--r--ash/desktop_background/desktop_background_view.cc18
-rw-r--r--ash/desktop_background/desktop_background_view.h2
3 files changed, 115 insertions, 15 deletions
diff --git a/ash/desktop_background/desktop_background_controller_unittest.cc b/ash/desktop_background/desktop_background_controller_unittest.cc
index b51fca1..b1df3ec 100644
--- a/ash/desktop_background/desktop_background_controller_unittest.cc
+++ b/ash/desktop_background/desktop_background_controller_unittest.cc
@@ -8,6 +8,7 @@
#include <cstdlib>
#include "ash/ash_switches.h"
+#include "ash/desktop_background/desktop_background_view.h"
#include "ash/desktop_background/desktop_background_widget_controller.h"
#include "ash/root_window_controller.h"
#include "ash/shell.h"
@@ -15,13 +16,16 @@
#include "ash/test/ash_test_base.h"
#include "ash/test/test_user_wallpaper_delegate.h"
#include "base/message_loop/message_loop.h"
+#include "base/strings/stringprintf.h"
#include "base/threading/sequenced_worker_pool.h"
#include "content/public/test/test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/compositor/test/layer_animator_test_controller.h"
+#include "ui/gfx/canvas.h"
using aura::RootWindow;
using aura::Window;
@@ -89,6 +93,16 @@ class DesktopBackgroundControllerTest : public test::AshTestBase {
controller_->set_wallpaper_reload_delay_for_test(0);
}
+ DesktopBackgroundView* desktop_background_view() {
+ DesktopBackgroundWidgetController* controller =
+ Shell::GetPrimaryRootWindowController()
+ ->animating_wallpaper_controller()
+ ->GetController(false);
+ EXPECT_TRUE(controller);
+ return static_cast<DesktopBackgroundView*>(
+ controller->widget()->GetContentsView()->child_at(0));
+ }
+
protected:
// A color that can be passed to CreateImage(). Specifically chosen to not
// conflict with any of the default wallpaper colors.
@@ -103,6 +117,37 @@ class DesktopBackgroundControllerTest : public test::AshTestBase {
return image;
}
+ // Helper function that tests the wallpaper is always fitted to the native
+ // display resolution when the layout is WALLPAPER_LAYOUT_CENTER.
+ void WallpaperFitToNativeResolution(DesktopBackgroundView* view,
+ float device_scale_factor,
+ int image_width,
+ int image_height,
+ SkColor color) {
+ gfx::Size size = view->bounds().size();
+ gfx::Canvas canvas(size, device_scale_factor, true);
+ view->OnPaint(&canvas);
+
+ int canvas_width = canvas.sk_canvas()->imageInfo().width();
+ int canvas_height = canvas.sk_canvas()->imageInfo().height();
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(canvas_width, canvas_height);
+ canvas.sk_canvas()->readPixels(&bitmap, 0, 0);
+
+ for (int i = 0; i < canvas_width; i++) {
+ for (int j = 0; j < canvas_height; j++) {
+ if (i >= (canvas_width - image_width) / 2 &&
+ i < (canvas_width + image_width) / 2 &&
+ j >= (canvas_height - image_height) / 2 &&
+ j < (canvas_height + image_height) / 2) {
+ EXPECT_EQ(color, bitmap.getColor(i, j));
+ } else {
+ EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(i, j));
+ }
+ }
+ }
+ }
+
// Runs kAnimatingDesktopController's animation to completion.
// TODO(bshe): Don't require tests to run animations; it's slow.
void RunDesktopControllerAnimation() {
@@ -345,5 +390,70 @@ TEST_F(DesktopBackgroundControllerTest, GetMaxDisplaySize) {
DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString());
}
+// Test that the wallpaper is always fitted to the native display resolution
+// when the layout is WALLPAPER_LAYOUT_CENTER to prevent blurry images.
+TEST_F(DesktopBackgroundControllerTest, DontSacleWallpaperWithCenterLayout) {
+ // We cannot short-circuit animations for this test.
+ ui::ScopedAnimationDurationScaleMode test_duration_mode(
+ ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
+
+ const gfx::Size high_resolution(3600, 2400);
+ const gfx::Size low_resolution(360, 240);
+ const float high_dsf = 2.0f;
+ const float low_dsf = 1.0f;
+
+ gfx::ImageSkia image_high_res = CreateImage(
+ high_resolution.width(), high_resolution.height(), kCustomWallpaperColor);
+ gfx::ImageSkia image_low_res = CreateImage(
+ low_resolution.width(), low_resolution.height(), kCustomWallpaperColor);
+
+ UpdateDisplay("1200x600*2");
+ {
+ SCOPED_TRACE(base::StringPrintf("1200x600*2 high resolution"));
+ controller_->SetWallpaperImage(image_high_res, WALLPAPER_LAYOUT_CENTER);
+ WallpaperFitToNativeResolution(
+ desktop_background_view(), high_dsf, high_resolution.width(),
+ high_resolution.height(), kCustomWallpaperColor);
+ }
+ {
+ SCOPED_TRACE(base::StringPrintf("1200x600*2 low resolution"));
+ controller_->SetWallpaperImage(image_low_res, WALLPAPER_LAYOUT_CENTER);
+ WallpaperFitToNativeResolution(
+ desktop_background_view(), high_dsf, low_resolution.width(),
+ low_resolution.height(), kCustomWallpaperColor);
+ }
+
+ UpdateDisplay("1200x600");
+ {
+ SCOPED_TRACE(base::StringPrintf("1200x600 high resolution"));
+ controller_->SetWallpaperImage(image_high_res, WALLPAPER_LAYOUT_CENTER);
+ WallpaperFitToNativeResolution(
+ desktop_background_view(), low_dsf, high_resolution.width(),
+ high_resolution.height(), kCustomWallpaperColor);
+ }
+ {
+ SCOPED_TRACE(base::StringPrintf("1200x600 low resolution"));
+ controller_->SetWallpaperImage(image_low_res, WALLPAPER_LAYOUT_CENTER);
+ WallpaperFitToNativeResolution(
+ desktop_background_view(), low_dsf, low_resolution.width(),
+ low_resolution.height(), kCustomWallpaperColor);
+ }
+
+ UpdateDisplay("1200x600/u@1.5"); // 1.5 ui scale
+ {
+ SCOPED_TRACE(base::StringPrintf("1200x600/u@1.5 high resolution"));
+ controller_->SetWallpaperImage(image_high_res, WALLPAPER_LAYOUT_CENTER);
+ WallpaperFitToNativeResolution(
+ desktop_background_view(), low_dsf, high_resolution.width(),
+ high_resolution.height(), kCustomWallpaperColor);
+ }
+ {
+ SCOPED_TRACE(base::StringPrintf("1200x600/u@1.5 low resolution"));
+ controller_->SetWallpaperImage(image_low_res, WALLPAPER_LAYOUT_CENTER);
+ WallpaperFitToNativeResolution(
+ desktop_background_view(), low_dsf, low_resolution.width(),
+ low_resolution.height(), kCustomWallpaperColor);
+ }
+}
} // namespace ash
diff --git a/ash/desktop_background/desktop_background_view.cc b/ash/desktop_background/desktop_background_view.cc
index 7107898..6975c11 100644
--- a/ash/desktop_background/desktop_background_view.cc
+++ b/ash/desktop_background/desktop_background_view.cc
@@ -142,21 +142,6 @@ void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) {
return;
}
- gfx::NativeView native_view = GetWidget()->GetNativeView();
- gfx::Display display = gfx::Screen::GetScreenFor(native_view)->
- GetDisplayNearestWindow(native_view);
-
- DisplayManager* display_manager = Shell::GetInstance()->display_manager();
- DisplayInfo display_info = display_manager->GetDisplayInfo(display.id());
- float scaling = display_info.GetEffectiveUIScale();
- if (scaling <= 1.0f)
- scaling = 1.0f;
- // Allow scaling up to the UI scaling.
- // TODO(oshima): Create separate layer that fits to the image and then
- // scale to avoid artifacts and be more efficient when clipped.
- gfx::Rect wallpaper_rect(
- 0, 0, wallpaper.width() * scaling, wallpaper.height() * scaling);
-
if (wallpaper_layout == WALLPAPER_LAYOUT_CENTER_CROPPED) {
// The dimension with the smallest ratio must be cropped, the other one
// is preserved. Both are set in gfx::Size cropped_size.
@@ -193,6 +178,9 @@ void DesktopBackgroundView::OnPaint(gfx::Canvas* canvas) {
} else {
// Fill with black to make sure that the entire area is opaque.
canvas->FillRect(GetLocalBounds(), SK_ColorBLACK);
+ float image_scale = canvas->image_scale();
+ gfx::Rect wallpaper_rect(0, 0, wallpaper.width() / image_scale,
+ wallpaper.height() / image_scale);
// All other are simply centered, and not scaled (but may be clipped).
canvas->DrawImageInt(
wallpaper,
diff --git a/ash/desktop_background/desktop_background_view.h b/ash/desktop_background/desktop_background_view.h
index 17814d0..1c76351 100644
--- a/ash/desktop_background/desktop_background_view.h
+++ b/ash/desktop_background/desktop_background_view.h
@@ -21,6 +21,8 @@ class DesktopBackgroundView : public views::View,
~DesktopBackgroundView() override;
private:
+ friend class DesktopBackgroundControllerTest;
+
// Overridden from views::View:
void OnPaint(gfx::Canvas* canvas) override;
bool OnMousePressed(const ui::MouseEvent& event) override;