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

Side by Side Diff: gfx/blit_unittest.cc

Issue 6246027: Move src/gfx/ to src/ui/gfx... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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 | « gfx/blit.cc ('k') | gfx/brush.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/basictypes.h"
6 #include "gfx/blit.h"
7 #include "gfx/point.h"
8 #include "gfx/rect.h"
9 #include "skia/ext/platform_canvas.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace {
13
14 // Fills the given canvas with the values by duplicating the values into each
15 // color channel for the corresponding pixel.
16 //
17 // Example values = {{0x0, 0x01}, {0x12, 0xFF}} would give a canvas with:
18 // 0x00000000 0x01010101
19 // 0x12121212 0xFFFFFFFF
20 template<int w, int h>
21 void SetToCanvas(skia::PlatformCanvas* canvas, uint8 values[h][w]) {
22 SkBitmap& bitmap = const_cast<SkBitmap&>(
23 canvas->getTopPlatformDevice().accessBitmap(true));
24 SkAutoLockPixels lock(bitmap);
25 ASSERT_EQ(w, bitmap.width());
26 ASSERT_EQ(h, bitmap.height());
27
28 for (int y = 0; y < h; y++) {
29 for (int x = 0; x < w; x++) {
30 uint8 value = values[y][x];
31 *bitmap.getAddr32(x, y) =
32 (value << 24) | (value << 16) | (value << 8) | value;
33 }
34 }
35 }
36
37 // Checks each pixel in the given canvas and see if it is made up of the given
38 // values, where each value has been duplicated into each channel of the given
39 // bitmap (see SetToCanvas above).
40 template<int w, int h>
41 void VerifyCanvasValues(skia::PlatformCanvas* canvas, uint8 values[h][w]) {
42 SkBitmap& bitmap = const_cast<SkBitmap&>(
43 canvas->getTopPlatformDevice().accessBitmap(true));
44 SkAutoLockPixels lock(bitmap);
45 ASSERT_EQ(w, bitmap.width());
46 ASSERT_EQ(h, bitmap.height());
47
48 for (int y = 0; y < h; y++) {
49 for (int x = 0; x < w; x++) {
50 uint8 value = values[y][x];
51 uint32 expected =
52 (value << 24) | (value << 16) | (value << 8) | value;
53 ASSERT_EQ(expected, *bitmap.getAddr32(x, y));
54 }
55 }
56 }
57
58 } // namespace
59
60 TEST(Blit, ScrollCanvas) {
61 static const int kCanvasWidth = 5;
62 static const int kCanvasHeight = 5;
63 skia::PlatformCanvas canvas(kCanvasWidth, kCanvasHeight, true);
64 uint8 initial_values[kCanvasHeight][kCanvasWidth] = {
65 { 0x00, 0x01, 0x02, 0x03, 0x04 },
66 { 0x10, 0x11, 0x12, 0x13, 0x14 },
67 { 0x20, 0x21, 0x22, 0x23, 0x24 },
68 { 0x30, 0x31, 0x32, 0x33, 0x34 },
69 { 0x40, 0x41, 0x42, 0x43, 0x44 }};
70 SetToCanvas<5, 5>(&canvas, initial_values);
71
72 // Sanity check on input.
73 VerifyCanvasValues<5, 5>(&canvas, initial_values);
74
75 // Scroll none and make sure it's a NOP.
76 gfx::ScrollCanvas(&canvas,
77 gfx::Rect(0, 0, kCanvasWidth, kCanvasHeight),
78 gfx::Point(0, 0));
79 VerifyCanvasValues<5, 5>(&canvas, initial_values);
80
81 // Scroll the center 3 pixels up one.
82 gfx::Rect center_three(1, 1, 3, 3);
83 gfx::ScrollCanvas(&canvas, center_three, gfx::Point(0, -1));
84 uint8 scroll_up_expected[kCanvasHeight][kCanvasWidth] = {
85 { 0x00, 0x01, 0x02, 0x03, 0x04 },
86 { 0x10, 0x21, 0x22, 0x23, 0x14 },
87 { 0x20, 0x31, 0x32, 0x33, 0x24 },
88 { 0x30, 0x31, 0x32, 0x33, 0x34 },
89 { 0x40, 0x41, 0x42, 0x43, 0x44 }};
90 VerifyCanvasValues<5, 5>(&canvas, scroll_up_expected);
91
92 // Reset and scroll the center 3 pixels down one.
93 SetToCanvas<5, 5>(&canvas, initial_values);
94 gfx::ScrollCanvas(&canvas, center_three, gfx::Point(0, 1));
95 uint8 scroll_down_expected[kCanvasHeight][kCanvasWidth] = {
96 { 0x00, 0x01, 0x02, 0x03, 0x04 },
97 { 0x10, 0x11, 0x12, 0x13, 0x14 },
98 { 0x20, 0x11, 0x12, 0x13, 0x24 },
99 { 0x30, 0x21, 0x22, 0x23, 0x34 },
100 { 0x40, 0x41, 0x42, 0x43, 0x44 }};
101 VerifyCanvasValues<5, 5>(&canvas, scroll_down_expected);
102
103 // Reset and scroll the center 3 pixels right one.
104 SetToCanvas<5, 5>(&canvas, initial_values);
105 gfx::ScrollCanvas(&canvas, center_three, gfx::Point(1, 0));
106 uint8 scroll_right_expected[kCanvasHeight][kCanvasWidth] = {
107 { 0x00, 0x01, 0x02, 0x03, 0x04 },
108 { 0x10, 0x11, 0x11, 0x12, 0x14 },
109 { 0x20, 0x21, 0x21, 0x22, 0x24 },
110 { 0x30, 0x31, 0x31, 0x32, 0x34 },
111 { 0x40, 0x41, 0x42, 0x43, 0x44 }};
112 VerifyCanvasValues<5, 5>(&canvas, scroll_right_expected);
113
114 // Reset and scroll the center 3 pixels left one.
115 SetToCanvas<5, 5>(&canvas, initial_values);
116 gfx::ScrollCanvas(&canvas, center_three, gfx::Point(-1, 0));
117 uint8 scroll_left_expected[kCanvasHeight][kCanvasWidth] = {
118 { 0x00, 0x01, 0x02, 0x03, 0x04 },
119 { 0x10, 0x12, 0x13, 0x13, 0x14 },
120 { 0x20, 0x22, 0x23, 0x23, 0x24 },
121 { 0x30, 0x32, 0x33, 0x33, 0x34 },
122 { 0x40, 0x41, 0x42, 0x43, 0x44 }};
123 VerifyCanvasValues<5, 5>(&canvas, scroll_left_expected);
124
125 // Diagonal scroll.
126 SetToCanvas<5, 5>(&canvas, initial_values);
127 gfx::ScrollCanvas(&canvas, center_three, gfx::Point(2, 2));
128 uint8 scroll_diagonal_expected[kCanvasHeight][kCanvasWidth] = {
129 { 0x00, 0x01, 0x02, 0x03, 0x04 },
130 { 0x10, 0x11, 0x12, 0x13, 0x14 },
131 { 0x20, 0x21, 0x22, 0x23, 0x24 },
132 { 0x30, 0x31, 0x32, 0x11, 0x34 },
133 { 0x40, 0x41, 0x42, 0x43, 0x44 }};
134 VerifyCanvasValues<5, 5>(&canvas, scroll_diagonal_expected);
135 }
OLDNEW
« no previous file with comments | « gfx/blit.cc ('k') | gfx/brush.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698