Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: ui/snapshot/snapshot_aura_unittest.cc

Issue 137143005: Removes the rotation and scaling in SnapshotAura. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/snapshot/snapshot_aura.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "ui/snapshot/snapshot.h" 5 #include "ui/snapshot/snapshot.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/test/test_simple_task_runner.h" 8 #include "base/test/test_simple_task_runner.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/aura/root_window.h" 10 #include "ui/aura/root_window.h"
11 #include "ui/aura/test/aura_test_helper.h" 11 #include "ui/aura/test/aura_test_helper.h"
12 #include "ui/aura/test/test_screen.h" 12 #include "ui/aura/test/test_screen.h"
13 #include "ui/aura/test/test_window_delegate.h" 13 #include "ui/aura/test/test_window_delegate.h"
14 #include "ui/aura/test/test_windows.h" 14 #include "ui/aura/test/test_windows.h"
15 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
16 #include "ui/compositor/layer.h" 16 #include "ui/compositor/layer.h"
17 #include "ui/gfx/canvas.h" 17 #include "ui/gfx/canvas.h"
18 #include "ui/gfx/gfx_paths.h" 18 #include "ui/gfx/gfx_paths.h"
19 #include "ui/gfx/image/image.h" 19 #include "ui/gfx/image/image.h"
20 #include "ui/gfx/rect.h" 20 #include "ui/gfx/rect.h"
21 #include "ui/gfx/size_conversions.h" 21 #include "ui/gfx/size_conversions.h"
22 #include "ui/gfx/transform.h" 22 #include "ui/gfx/transform.h"
23 #include "ui/gl/gl_implementation.h" 23 #include "ui/gl/gl_implementation.h"
24 24
25 namespace ui { 25 namespace ui {
26 namespace { 26 namespace {
27 const SkColor kPaintColor = SK_ColorRED; 27
28 SkColor GetExpectedColorForPoint(int x, int y) {
29 return SkColorSetRGB(std::min(x, 255), std::min(y, 255), 0);
30 }
28 31
29 // Paint simple rectangle on the specified aura window. 32 // Paint simple rectangle on the specified aura window.
30 class TestPaintingWindowDelegate : public aura::test::TestWindowDelegate { 33 class TestPaintingWindowDelegate : public aura::test::TestWindowDelegate {
31 public: 34 public:
32 explicit TestPaintingWindowDelegate(const gfx::Size& window_size) 35 explicit TestPaintingWindowDelegate(const gfx::Size& window_size)
33 : window_size_(window_size) { 36 : window_size_(window_size) {
34 } 37 }
35 38
36 virtual ~TestPaintingWindowDelegate() { 39 virtual ~TestPaintingWindowDelegate() {
37 } 40 }
38 41
39 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { 42 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
40 canvas->FillRect(gfx::Rect(window_size_), kPaintColor); 43 for (int y = 0; y < window_size_.height(); ++y) {
44 for (int x = 0; x < window_size_.width(); ++x)
45 canvas->FillRect(gfx::Rect(x, y, 1, 1), GetExpectedColorForPoint(x, y));
46 }
41 } 47 }
42 48
43 private: 49 private:
44 gfx::Size window_size_; 50 gfx::Size window_size_;
45 51
46 DISALLOW_COPY_AND_ASSIGN(TestPaintingWindowDelegate); 52 DISALLOW_COPY_AND_ASSIGN(TestPaintingWindowDelegate);
47 }; 53 };
48 54
49 size_t GetFailedPixelsCount(const gfx::Image& image) { 55 size_t GetFailedPixelsCountWithScaleFactor(const gfx::Image& image,
56 int scale_factor) {
50 const SkBitmap* bitmap = image.ToSkBitmap(); 57 const SkBitmap* bitmap = image.ToSkBitmap();
51 uint32* bitmap_data = reinterpret_cast<uint32*>( 58 uint32* bitmap_data = reinterpret_cast<uint32*>(
52 bitmap->pixelRef()->pixels()); 59 bitmap->pixelRef()->pixels());
53 size_t result = 0; 60 size_t result = 0;
54 for (int i = 0; i < bitmap->width() * bitmap->height(); ++i) { 61 for (int y = 0; y < bitmap->height(); y += scale_factor) {
55 if (static_cast<SkColor>(bitmap_data[i]) != kPaintColor) 62 for (int x = 0; x < bitmap->width(); x += scale_factor) {
56 ++result; 63 if (static_cast<SkColor>(bitmap_data[x + y * bitmap->width()]) !=
64 GetExpectedColorForPoint(x / scale_factor, y / scale_factor)) {
65 ++result;
66 }
67 }
57 } 68 }
58 return result; 69 return result;
59 } 70 }
60 71
72 size_t GetFailedPixelsCount(const gfx::Image& image) {
73 return GetFailedPixelsCountWithScaleFactor(image, 1);
74 }
75
61 } // namespace 76 } // namespace
62 77
63 class SnapshotAuraTest : public testing::Test { 78 class SnapshotAuraTest : public testing::Test {
64 public: 79 public:
65 SnapshotAuraTest() {} 80 SnapshotAuraTest() {}
66 virtual ~SnapshotAuraTest() {} 81 virtual ~SnapshotAuraTest() {}
67 82
68 virtual void SetUp() OVERRIDE { 83 virtual void SetUp() OVERRIDE {
69 testing::Test::SetUp(); 84 testing::Test::SetUp();
70 helper_.reset( 85 helper_.reset(
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 snapshot.Size().ToString()); 183 snapshot.Size().ToString());
169 EXPECT_EQ(0u, GetFailedPixelsCount(snapshot)); 184 EXPECT_EQ(0u, GetFailedPixelsCount(snapshot));
170 } 185 }
171 186
172 TEST_F(SnapshotAuraTest, PartialBounds) { 187 TEST_F(SnapshotAuraTest, PartialBounds) {
173 gfx::Rect test_bounds(100, 100, 300, 200); 188 gfx::Rect test_bounds(100, 100, 300, 200);
174 SetupTestWindow(test_bounds); 189 SetupTestWindow(test_bounds);
175 WaitForDraw(); 190 WaitForDraw();
176 191
177 gfx::Image snapshot = GrabSnapshotForTestWindow(); 192 gfx::Image snapshot = GrabSnapshotForTestWindow();
178 EXPECT_EQ(test_bounds.size().ToString(), 193 EXPECT_EQ(test_bounds.size().ToString(), snapshot.Size().ToString());
179 snapshot.Size().ToString());
180 EXPECT_EQ(0u, GetFailedPixelsCount(snapshot)); 194 EXPECT_EQ(0u, GetFailedPixelsCount(snapshot));
181 } 195 }
182 196
183 TEST_F(SnapshotAuraTest, Rotated) { 197 TEST_F(SnapshotAuraTest, Rotated) {
184 test_screen()->SetDisplayRotation(gfx::Display::ROTATE_90); 198 test_screen()->SetDisplayRotation(gfx::Display::ROTATE_90);
185 199
186 gfx::Rect test_bounds(100, 100, 300, 200); 200 gfx::Rect test_bounds(100, 100, 300, 200);
187 SetupTestWindow(test_bounds); 201 SetupTestWindow(test_bounds);
188 WaitForDraw(); 202 WaitForDraw();
189 203
190 gfx::Image snapshot = GrabSnapshotForTestWindow(); 204 gfx::Image snapshot = GrabSnapshotForTestWindow();
191 EXPECT_EQ(test_bounds.size().ToString(), 205 EXPECT_EQ(test_bounds.size().ToString(), snapshot.Size().ToString());
192 snapshot.Size().ToString());
193 EXPECT_EQ(0u, GetFailedPixelsCount(snapshot)); 206 EXPECT_EQ(0u, GetFailedPixelsCount(snapshot));
194 } 207 }
195 208
196 TEST_F(SnapshotAuraTest, UIScale) { 209 TEST_F(SnapshotAuraTest, UIScale) {
197 const float kUIScale = 1.25f; 210 const float kUIScale = 1.25f;
198 test_screen()->SetUIScale(kUIScale); 211 test_screen()->SetUIScale(kUIScale);
199 212
200 gfx::Rect test_bounds(100, 100, 300, 200); 213 gfx::Rect test_bounds(100, 100, 300, 200);
201 SetupTestWindow(test_bounds); 214 SetupTestWindow(test_bounds);
202 WaitForDraw(); 215 WaitForDraw();
203 216
204 // Snapshot always captures the physical pixels. 217 // Snapshot always captures the physical pixels.
205 gfx::SizeF snapshot_size(test_bounds.size()); 218 gfx::SizeF snapshot_size(test_bounds.size());
206 snapshot_size.Scale(1.0f / kUIScale);
207 219
208 gfx::Image snapshot = GrabSnapshotForTestWindow(); 220 gfx::Image snapshot = GrabSnapshotForTestWindow();
209 EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(), 221 EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(),
210 snapshot.Size().ToString()); 222 snapshot.Size().ToString());
211 EXPECT_EQ(0u, GetFailedPixelsCount(snapshot)); 223 EXPECT_EQ(0u, GetFailedPixelsCount(snapshot));
212 } 224 }
213 225
214 TEST_F(SnapshotAuraTest, DeviceScaleFactor) { 226 TEST_F(SnapshotAuraTest, DeviceScaleFactor) {
215 test_screen()->SetDeviceScaleFactor(2.0f); 227 test_screen()->SetDeviceScaleFactor(2.0f);
216 228
217 gfx::Rect test_bounds(100, 100, 150, 100); 229 gfx::Rect test_bounds(100, 100, 150, 100);
218 SetupTestWindow(test_bounds); 230 SetupTestWindow(test_bounds);
219 WaitForDraw(); 231 WaitForDraw();
220 232
221 // Snapshot always captures the physical pixels. 233 // Snapshot always captures the physical pixels.
222 gfx::SizeF snapshot_size(test_bounds.size()); 234 gfx::SizeF snapshot_size(test_bounds.size());
223 snapshot_size.Scale(2.0f); 235 snapshot_size.Scale(2.0f);
224 236
225 gfx::Image snapshot = GrabSnapshotForTestWindow(); 237 gfx::Image snapshot = GrabSnapshotForTestWindow();
226 EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(), 238 EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(),
227 snapshot.Size().ToString()); 239 snapshot.Size().ToString());
228 EXPECT_EQ(0u, GetFailedPixelsCount(snapshot)); 240 EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 2));
229 } 241 }
230 242
231 TEST_F(SnapshotAuraTest, RotateAndUIScale) { 243 TEST_F(SnapshotAuraTest, RotateAndUIScale) {
232 const float kUIScale = 1.25f; 244 const float kUIScale = 1.25f;
233 test_screen()->SetUIScale(kUIScale); 245 test_screen()->SetUIScale(kUIScale);
234 test_screen()->SetDisplayRotation(gfx::Display::ROTATE_90); 246 test_screen()->SetDisplayRotation(gfx::Display::ROTATE_90);
235 247
236 gfx::Rect test_bounds(100, 100, 300, 200); 248 gfx::Rect test_bounds(100, 100, 300, 200);
237 SetupTestWindow(test_bounds); 249 SetupTestWindow(test_bounds);
238 WaitForDraw(); 250 WaitForDraw();
239 251
240 // Snapshot always captures the physical pixels. 252 // Snapshot always captures the physical pixels.
241 gfx::SizeF snapshot_size(test_bounds.size()); 253 gfx::SizeF snapshot_size(test_bounds.size());
242 snapshot_size.Scale(1.0f / kUIScale);
243 254
244 gfx::Image snapshot = GrabSnapshotForTestWindow(); 255 gfx::Image snapshot = GrabSnapshotForTestWindow();
245 EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(), 256 EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(),
246 snapshot.Size().ToString()); 257 snapshot.Size().ToString());
247 EXPECT_EQ(0u, GetFailedPixelsCount(snapshot)); 258 EXPECT_EQ(0u, GetFailedPixelsCount(snapshot));
248 } 259 }
249 260
250 TEST_F(SnapshotAuraTest, RotateAndUIScaleAndScaleFactor) { 261 TEST_F(SnapshotAuraTest, RotateAndUIScaleAndScaleFactor) {
251 test_screen()->SetDeviceScaleFactor(2.0f); 262 test_screen()->SetDeviceScaleFactor(2.0f);
252 const float kUIScale = 1.25f; 263 const float kUIScale = 1.25f;
253 test_screen()->SetUIScale(kUIScale); 264 test_screen()->SetUIScale(kUIScale);
254 test_screen()->SetDisplayRotation(gfx::Display::ROTATE_90); 265 test_screen()->SetDisplayRotation(gfx::Display::ROTATE_90);
255 266
256 gfx::Rect test_bounds(20, 30, 150, 100); 267 gfx::Rect test_bounds(20, 30, 150, 100);
257 SetupTestWindow(test_bounds); 268 SetupTestWindow(test_bounds);
258 WaitForDraw(); 269 WaitForDraw();
259 270
260 // Snapshot always captures the physical pixels. 271 // Snapshot always captures the physical pixels.
261 gfx::SizeF snapshot_size(test_bounds.size()); 272 gfx::SizeF snapshot_size(test_bounds.size());
262 snapshot_size.Scale(2.0f / kUIScale); 273 snapshot_size.Scale(2.0f);
263 274
264 gfx::Image snapshot = GrabSnapshotForTestWindow(); 275 gfx::Image snapshot = GrabSnapshotForTestWindow();
265 EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(), 276 EXPECT_EQ(gfx::ToRoundedSize(snapshot_size).ToString(),
266 snapshot.Size().ToString()); 277 snapshot.Size().ToString());
267 EXPECT_EQ(0u, GetFailedPixelsCount(snapshot)); 278 EXPECT_EQ(0u, GetFailedPixelsCountWithScaleFactor(snapshot, 2));
268 } 279 }
269 280
270 } // namespace ui 281 } // namespace ui
OLDNEW
« no previous file with comments | « ui/snapshot/snapshot_aura.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698