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

Side by Side Diff: ui/gfx/blit_unittest.cc

Issue 11138024: Simplify platform_canvas.h by recognizing that PlatformCanvas does not actually extend (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/shared_memory.h" 6 #include "base/shared_memory.h"
7 #include "skia/ext/platform_canvas.h" 7 #include "skia/ext/platform_canvas.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/blit.h" 9 #include "ui/gfx/blit.h"
10 #include "ui/gfx/point.h" 10 #include "ui/gfx/point.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 ASSERT_EQ(expected, *bitmap.getAddr32(x, y)); 54 ASSERT_EQ(expected, *bitmap.getAddr32(x, y));
55 } 55 }
56 } 56 }
57 } 57 }
58 58
59 } // namespace 59 } // namespace
60 60
61 TEST(Blit, ScrollCanvas) { 61 TEST(Blit, ScrollCanvas) {
62 static const int kCanvasWidth = 5; 62 static const int kCanvasWidth = 5;
63 static const int kCanvasHeight = 5; 63 static const int kCanvasHeight = 5;
64 skia::PlatformCanvas canvas(kCanvasWidth, kCanvasHeight, true); 64 SkAutoTUnref<SkCanvas> canvas(skia::CreatePlatformCanvas(kCanvasWidth,
65 kCanvasHeight, true));
65 uint8 initial_values[kCanvasHeight][kCanvasWidth] = { 66 uint8 initial_values[kCanvasHeight][kCanvasWidth] = {
66 { 0x00, 0x01, 0x02, 0x03, 0x04 }, 67 { 0x00, 0x01, 0x02, 0x03, 0x04 },
67 { 0x10, 0x11, 0x12, 0x13, 0x14 }, 68 { 0x10, 0x11, 0x12, 0x13, 0x14 },
68 { 0x20, 0x21, 0x22, 0x23, 0x24 }, 69 { 0x20, 0x21, 0x22, 0x23, 0x24 },
69 { 0x30, 0x31, 0x32, 0x33, 0x34 }, 70 { 0x30, 0x31, 0x32, 0x33, 0x34 },
70 { 0x40, 0x41, 0x42, 0x43, 0x44 }}; 71 { 0x40, 0x41, 0x42, 0x43, 0x44 }};
71 SetToCanvas<5, 5>(&canvas, initial_values); 72 SetToCanvas<5, 5>(canvas, initial_values);
72 73
73 // Sanity check on input. 74 // Sanity check on input.
74 VerifyCanvasValues<5, 5>(&canvas, initial_values); 75 VerifyCanvasValues<5, 5>(canvas, initial_values);
75 76
76 // Scroll none and make sure it's a NOP. 77 // Scroll none and make sure it's a NOP.
77 gfx::ScrollCanvas(&canvas, 78 gfx::ScrollCanvas(canvas,
78 gfx::Rect(0, 0, kCanvasWidth, kCanvasHeight), 79 gfx::Rect(0, 0, kCanvasWidth, kCanvasHeight),
79 gfx::Vector2d(0, 0)); 80 gfx::Vector2d(0, 0));
80 VerifyCanvasValues<5, 5>(&canvas, initial_values); 81 VerifyCanvasValues<5, 5>(canvas, initial_values);
81 82
82 // Scroll the center 3 pixels up one. 83 // Scroll the center 3 pixels up one.
83 gfx::Rect center_three(1, 1, 3, 3); 84 gfx::Rect center_three(1, 1, 3, 3);
84 gfx::ScrollCanvas(&canvas, center_three, gfx::Vector2d(0, -1)); 85 gfx::ScrollCanvas(canvas, center_three, gfx::Vector2d(0, -1));
85 uint8 scroll_up_expected[kCanvasHeight][kCanvasWidth] = { 86 uint8 scroll_up_expected[kCanvasHeight][kCanvasWidth] = {
86 { 0x00, 0x01, 0x02, 0x03, 0x04 }, 87 { 0x00, 0x01, 0x02, 0x03, 0x04 },
87 { 0x10, 0x21, 0x22, 0x23, 0x14 }, 88 { 0x10, 0x21, 0x22, 0x23, 0x14 },
88 { 0x20, 0x31, 0x32, 0x33, 0x24 }, 89 { 0x20, 0x31, 0x32, 0x33, 0x24 },
89 { 0x30, 0x31, 0x32, 0x33, 0x34 }, 90 { 0x30, 0x31, 0x32, 0x33, 0x34 },
90 { 0x40, 0x41, 0x42, 0x43, 0x44 }}; 91 { 0x40, 0x41, 0x42, 0x43, 0x44 }};
91 VerifyCanvasValues<5, 5>(&canvas, scroll_up_expected); 92 VerifyCanvasValues<5, 5>(canvas, scroll_up_expected);
92 93
93 // Reset and scroll the center 3 pixels down one. 94 // Reset and scroll the center 3 pixels down one.
94 SetToCanvas<5, 5>(&canvas, initial_values); 95 SetToCanvas<5, 5>(canvas, initial_values);
95 gfx::ScrollCanvas(&canvas, center_three, gfx::Vector2d(0, 1)); 96 gfx::ScrollCanvas(canvas, center_three, gfx::Vector2d(0, 1));
96 uint8 scroll_down_expected[kCanvasHeight][kCanvasWidth] = { 97 uint8 scroll_down_expected[kCanvasHeight][kCanvasWidth] = {
97 { 0x00, 0x01, 0x02, 0x03, 0x04 }, 98 { 0x00, 0x01, 0x02, 0x03, 0x04 },
98 { 0x10, 0x11, 0x12, 0x13, 0x14 }, 99 { 0x10, 0x11, 0x12, 0x13, 0x14 },
99 { 0x20, 0x11, 0x12, 0x13, 0x24 }, 100 { 0x20, 0x11, 0x12, 0x13, 0x24 },
100 { 0x30, 0x21, 0x22, 0x23, 0x34 }, 101 { 0x30, 0x21, 0x22, 0x23, 0x34 },
101 { 0x40, 0x41, 0x42, 0x43, 0x44 }}; 102 { 0x40, 0x41, 0x42, 0x43, 0x44 }};
102 VerifyCanvasValues<5, 5>(&canvas, scroll_down_expected); 103 VerifyCanvasValues<5, 5>(canvas, scroll_down_expected);
103 104
104 // Reset and scroll the center 3 pixels right one. 105 // Reset and scroll the center 3 pixels right one.
105 SetToCanvas<5, 5>(&canvas, initial_values); 106 SetToCanvas<5, 5>(canvas, initial_values);
106 gfx::ScrollCanvas(&canvas, center_three, gfx::Vector2d(1, 0)); 107 gfx::ScrollCanvas(canvas, center_three, gfx::Vector2d(1, 0));
107 uint8 scroll_right_expected[kCanvasHeight][kCanvasWidth] = { 108 uint8 scroll_right_expected[kCanvasHeight][kCanvasWidth] = {
108 { 0x00, 0x01, 0x02, 0x03, 0x04 }, 109 { 0x00, 0x01, 0x02, 0x03, 0x04 },
109 { 0x10, 0x11, 0x11, 0x12, 0x14 }, 110 { 0x10, 0x11, 0x11, 0x12, 0x14 },
110 { 0x20, 0x21, 0x21, 0x22, 0x24 }, 111 { 0x20, 0x21, 0x21, 0x22, 0x24 },
111 { 0x30, 0x31, 0x31, 0x32, 0x34 }, 112 { 0x30, 0x31, 0x31, 0x32, 0x34 },
112 { 0x40, 0x41, 0x42, 0x43, 0x44 }}; 113 { 0x40, 0x41, 0x42, 0x43, 0x44 }};
113 VerifyCanvasValues<5, 5>(&canvas, scroll_right_expected); 114 VerifyCanvasValues<5, 5>(canvas, scroll_right_expected);
114 115
115 // Reset and scroll the center 3 pixels left one. 116 // Reset and scroll the center 3 pixels left one.
116 SetToCanvas<5, 5>(&canvas, initial_values); 117 SetToCanvas<5, 5>(canvas, initial_values);
117 gfx::ScrollCanvas(&canvas, center_three, gfx::Vector2d(-1, 0)); 118 gfx::ScrollCanvas(canvas, center_three, gfx::Vector2d(-1, 0));
118 uint8 scroll_left_expected[kCanvasHeight][kCanvasWidth] = { 119 uint8 scroll_left_expected[kCanvasHeight][kCanvasWidth] = {
119 { 0x00, 0x01, 0x02, 0x03, 0x04 }, 120 { 0x00, 0x01, 0x02, 0x03, 0x04 },
120 { 0x10, 0x12, 0x13, 0x13, 0x14 }, 121 { 0x10, 0x12, 0x13, 0x13, 0x14 },
121 { 0x20, 0x22, 0x23, 0x23, 0x24 }, 122 { 0x20, 0x22, 0x23, 0x23, 0x24 },
122 { 0x30, 0x32, 0x33, 0x33, 0x34 }, 123 { 0x30, 0x32, 0x33, 0x33, 0x34 },
123 { 0x40, 0x41, 0x42, 0x43, 0x44 }}; 124 { 0x40, 0x41, 0x42, 0x43, 0x44 }};
124 VerifyCanvasValues<5, 5>(&canvas, scroll_left_expected); 125 VerifyCanvasValues<5, 5>(canvas, scroll_left_expected);
125 126
126 // Diagonal scroll. 127 // Diagonal scroll.
127 SetToCanvas<5, 5>(&canvas, initial_values); 128 SetToCanvas<5, 5>(canvas, initial_values);
128 gfx::ScrollCanvas(&canvas, center_three, gfx::Vector2d(2, 2)); 129 gfx::ScrollCanvas(canvas, center_three, gfx::Vector2d(2, 2));
129 uint8 scroll_diagonal_expected[kCanvasHeight][kCanvasWidth] = { 130 uint8 scroll_diagonal_expected[kCanvasHeight][kCanvasWidth] = {
130 { 0x00, 0x01, 0x02, 0x03, 0x04 }, 131 { 0x00, 0x01, 0x02, 0x03, 0x04 },
131 { 0x10, 0x11, 0x12, 0x13, 0x14 }, 132 { 0x10, 0x11, 0x12, 0x13, 0x14 },
132 { 0x20, 0x21, 0x22, 0x23, 0x24 }, 133 { 0x20, 0x21, 0x22, 0x23, 0x24 },
133 { 0x30, 0x31, 0x32, 0x11, 0x34 }, 134 { 0x30, 0x31, 0x32, 0x11, 0x34 },
134 { 0x40, 0x41, 0x42, 0x43, 0x44 }}; 135 { 0x40, 0x41, 0x42, 0x43, 0x44 }};
135 VerifyCanvasValues<5, 5>(&canvas, scroll_diagonal_expected); 136 VerifyCanvasValues<5, 5>(canvas, scroll_diagonal_expected);
136 } 137 }
137 138
138 #if defined(OS_WIN) 139 #if defined(OS_WIN)
139 140
140 TEST(Blit, WithSharedMemory) { 141 TEST(Blit, WithSharedMemory) {
141 const int kCanvasWidth = 5; 142 const int kCanvasWidth = 5;
142 const int kCanvasHeight = 5; 143 const int kCanvasHeight = 5;
143 skia::PlatformCanvas canvas;
144 base::SharedMemory shared_mem; 144 base::SharedMemory shared_mem;
145 ASSERT_TRUE(shared_mem.CreateAnonymous(kCanvasWidth * kCanvasHeight)); 145 ASSERT_TRUE(shared_mem.CreateAnonymous(kCanvasWidth * kCanvasHeight));
146 base::SharedMemoryHandle section = shared_mem.handle(); 146 base::SharedMemoryHandle section = shared_mem.handle();
147 ASSERT_TRUE(canvas.initialize(kCanvasWidth, kCanvasHeight, true, section)); 147 SkCanvas* canvas = skia::CreatePlatformCanvas(kCanvasWidth, kCanvasHeight,
148 true, section, skia::RETURN_NULL_ON_FAILURE);
149 ASSERT_TRUE(NULL != canvas);
150 SkAutoUnref aur(canvas);
148 shared_mem.Close(); 151 shared_mem.Close();
149 152
150 uint8 initial_values[kCanvasHeight][kCanvasWidth] = { 153 uint8 initial_values[kCanvasHeight][kCanvasWidth] = {
151 { 0x00, 0x01, 0x02, 0x03, 0x04 }, 154 { 0x00, 0x01, 0x02, 0x03, 0x04 },
152 { 0x10, 0x11, 0x12, 0x13, 0x14 }, 155 { 0x10, 0x11, 0x12, 0x13, 0x14 },
153 { 0x20, 0x21, 0x22, 0x23, 0x24 }, 156 { 0x20, 0x21, 0x22, 0x23, 0x24 },
154 { 0x30, 0x31, 0x32, 0x33, 0x34 }, 157 { 0x30, 0x31, 0x32, 0x33, 0x34 },
155 { 0x40, 0x41, 0x42, 0x43, 0x44 }}; 158 { 0x40, 0x41, 0x42, 0x43, 0x44 }};
156 SetToCanvas<5, 5>(&canvas, initial_values); 159 SetToCanvas<5, 5>(canvas, initial_values);
157 160
158 // Sanity check on input. 161 // Sanity check on input.
159 VerifyCanvasValues<5, 5>(&canvas, initial_values); 162 VerifyCanvasValues<5, 5>(canvas, initial_values);
160 } 163 }
161 164
162 #endif 165 #endif
163 166
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698