OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/common/wallpaper/wallpaper_controller.h" | 5 #include "ash/common/wallpaper/wallpaper_controller.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <cstdlib> | 8 #include <cstdlib> |
9 | 9 |
10 #include "ash/common/ash_switches.h" | 10 #include "ash/common/ash_switches.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 // display resolution when the layout is WALLPAPER_LAYOUT_CENTER. | 158 // display resolution when the layout is WALLPAPER_LAYOUT_CENTER. |
159 void WallpaperFitToNativeResolution(WallpaperView* view, | 159 void WallpaperFitToNativeResolution(WallpaperView* view, |
160 float device_scale_factor, | 160 float device_scale_factor, |
161 int image_width, | 161 int image_width, |
162 int image_height, | 162 int image_height, |
163 SkColor color) { | 163 SkColor color) { |
164 gfx::Size size = view->bounds().size(); | 164 gfx::Size size = view->bounds().size(); |
165 gfx::Canvas canvas(size, device_scale_factor, true); | 165 gfx::Canvas canvas(size, device_scale_factor, true); |
166 view->OnPaint(&canvas); | 166 view->OnPaint(&canvas); |
167 | 167 |
168 int canvas_width = canvas.sk_canvas()->imageInfo().width(); | 168 SkBitmap bitmap = canvas.GetBitmap(); |
169 int canvas_height = canvas.sk_canvas()->imageInfo().height(); | 169 int bitmap_width = bitmap.width(); |
170 SkBitmap bitmap; | 170 int bitmap_height = bitmap.height(); |
171 bitmap.allocN32Pixels(canvas_width, canvas_height); | 171 for (int i = 0; i < bitmap_width; i++) { |
172 canvas.sk_canvas()->readPixels(&bitmap, 0, 0); | 172 for (int j = 0; j < bitmap_height; j++) { |
173 | 173 if (i >= (bitmap_width - image_width) / 2 && |
174 for (int i = 0; i < canvas_width; i++) { | 174 i < (bitmap_width + image_width) / 2 && |
175 for (int j = 0; j < canvas_height; j++) { | 175 j >= (bitmap_height - image_height) / 2 && |
176 if (i >= (canvas_width - image_width) / 2 && | 176 j < (bitmap_height + image_height) / 2) { |
177 i < (canvas_width + image_width) / 2 && | |
178 j >= (canvas_height - image_height) / 2 && | |
179 j < (canvas_height + image_height) / 2) { | |
180 EXPECT_EQ(color, bitmap.getColor(i, j)); | 177 EXPECT_EQ(color, bitmap.getColor(i, j)); |
181 } else { | 178 } else { |
182 EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(i, j)); | 179 EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(i, j)); |
183 } | 180 } |
184 } | 181 } |
185 } | 182 } |
186 } | 183 } |
187 | 184 |
188 // Runs AnimatingWallpaperWidgetController's animation to completion. | 185 // Runs AnimatingWallpaperWidgetController's animation to completion. |
189 // TODO(bshe): Don't require tests to run animations; it's slow. | 186 // TODO(bshe): Don't require tests to run animations; it's slow. |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 EXPECT_TRUE(ShouldCalculateColors()); | 529 EXPECT_TRUE(ShouldCalculateColors()); |
533 | 530 |
534 SetSessionState(SessionState::LOCKED); | 531 SetSessionState(SessionState::LOCKED); |
535 EXPECT_FALSE(ShouldCalculateColors()); | 532 EXPECT_FALSE(ShouldCalculateColors()); |
536 | 533 |
537 SetSessionState(SessionState::LOGIN_SECONDARY); | 534 SetSessionState(SessionState::LOGIN_SECONDARY); |
538 EXPECT_FALSE(ShouldCalculateColors()); | 535 EXPECT_FALSE(ShouldCalculateColors()); |
539 } | 536 } |
540 | 537 |
541 } // namespace ash | 538 } // namespace ash |
OLD | NEW |