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

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

Issue 1432443004: Remove SkDevice and SkBaseDevice outside skia/ext/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pass SkPixmap by pointer to MakeBitmapOpaque Created 5 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
« no previous file with comments | « ui/gfx/canvas.cc ('k') | ui/ozone/platform/drm/gpu/drm_window.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/gfx/nine_image_painter.h" 5 #include "ui/gfx/nine_image_painter.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/codec/png_codec.h" 10 #include "ui/gfx/codec/png_codec.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 bool is_opaque = true; 79 bool is_opaque = true;
80 gfx::Canvas canvas(gfx::Size(100, 100), image_scale, is_opaque); 80 gfx::Canvas canvas(gfx::Size(100, 100), image_scale, is_opaque);
81 81
82 gfx::Vector2d offset(20, 10); 82 gfx::Vector2d offset(20, 10);
83 canvas.Translate(offset); 83 canvas.Translate(offset);
84 84
85 gfx::Rect bounds(0, 0, 50, 50); 85 gfx::Rect bounds(0, 0, 50, 50);
86 painter.Paint(&canvas, bounds); 86 painter.Paint(&canvas, bounds);
87 87
88 SkBitmap result; 88 SkBitmap result;
89 const SkISize size = canvas.sk_canvas()->getDeviceSize(); 89 const SkISize size = canvas.sk_canvas()->getBaseLayerSize();
90 result.allocN32Pixels(size.width(), size.height()); 90 result.allocN32Pixels(size.width(), size.height());
91 canvas.sk_canvas()->readPixels(&result, 0, 0); 91 canvas.sk_canvas()->readPixels(&result, 0, 0);
92 92
93 gfx::Vector2d paint_offset = 93 gfx::Vector2d paint_offset =
94 gfx::ToFlooredVector2d(gfx::ScaleVector2d(offset, image_scale)); 94 gfx::ToFlooredVector2d(gfx::ScaleVector2d(offset, image_scale));
95 gfx::Rect green_rect = gfx::Rect(10, 10, 80, 80) + paint_offset; 95 gfx::Rect green_rect = gfx::Rect(10, 10, 80, 80) + paint_offset;
96 gfx::Rect outer_rect = gfx::Rect(100, 100) + paint_offset; 96 gfx::Rect outer_rect = gfx::Rect(100, 100) + paint_offset;
97 ExpectRedWithGreenRect(result, outer_rect, green_rect); 97 ExpectRedWithGreenRect(result, outer_rect, green_rect);
98 } 98 }
99 99
(...skipping 13 matching lines...) Expand all
113 113
114 int image_scale = 1; 114 int image_scale = 1;
115 bool is_opaque = true; 115 bool is_opaque = true;
116 gfx::Canvas canvas(gfx::Size(3, 3), image_scale, is_opaque); 116 gfx::Canvas canvas(gfx::Size(3, 3), image_scale, is_opaque);
117 canvas.DrawColor(SK_ColorBLACK); 117 canvas.DrawColor(SK_ColorBLACK);
118 118
119 gfx::Rect bounds(1, 1, 1, 1); 119 gfx::Rect bounds(1, 1, 1, 1);
120 painter.Paint(&canvas, bounds); 120 painter.Paint(&canvas, bounds);
121 121
122 SkBitmap result; 122 SkBitmap result;
123 const SkISize size = canvas.sk_canvas()->getDeviceSize(); 123 const SkISize size = canvas.sk_canvas()->getBaseLayerSize();
124 result.allocN32Pixels(size.width(), size.height()); 124 result.allocN32Pixels(size.width(), size.height());
125 canvas.sk_canvas()->readPixels(&result, 0, 0); 125 canvas.sk_canvas()->readPixels(&result, 0, 0);
126 126
127 EXPECT_EQ(SK_ColorGREEN, result.getColor(1, 1)); 127 EXPECT_EQ(SK_ColorGREEN, result.getColor(1, 1));
128 128
129 EXPECT_EQ(SK_ColorBLACK, result.getColor(0, 0)); 129 EXPECT_EQ(SK_ColorBLACK, result.getColor(0, 0));
130 EXPECT_EQ(SK_ColorBLACK, result.getColor(0, 1)); 130 EXPECT_EQ(SK_ColorBLACK, result.getColor(0, 1));
131 EXPECT_EQ(SK_ColorBLACK, result.getColor(0, 2)); 131 EXPECT_EQ(SK_ColorBLACK, result.getColor(0, 2));
132 EXPECT_EQ(SK_ColorBLACK, result.getColor(1, 0)); 132 EXPECT_EQ(SK_ColorBLACK, result.getColor(1, 0));
133 EXPECT_EQ(SK_ColorBLACK, result.getColor(1, 2)); 133 EXPECT_EQ(SK_ColorBLACK, result.getColor(1, 2));
(...skipping 12 matching lines...) Expand all
146 gfx::Insets insets(1, 1, 1, 1); 146 gfx::Insets insets(1, 1, 1, 1);
147 gfx::NineImagePainter painter(image, insets); 147 gfx::NineImagePainter painter(image, insets);
148 148
149 bool is_opaque = true; 149 bool is_opaque = true;
150 gfx::Canvas canvas(gfx::Size(10, 10), 1, is_opaque); 150 gfx::Canvas canvas(gfx::Size(10, 10), 1, is_opaque);
151 151
152 gfx::Rect bounds(1, 1, 10, 10); 152 gfx::Rect bounds(1, 1, 10, 10);
153 painter.Paint(&canvas, bounds); 153 painter.Paint(&canvas, bounds);
154 154
155 SkBitmap result; 155 SkBitmap result;
156 const SkISize size = canvas.sk_canvas()->getDeviceSize(); 156 const SkISize size = canvas.sk_canvas()->getBaseLayerSize();
157 result.allocN32Pixels(size.width(), size.height()); 157 result.allocN32Pixels(size.width(), size.height());
158 canvas.sk_canvas()->readPixels(&result, 0, 0); 158 canvas.sk_canvas()->readPixels(&result, 0, 0);
159 159
160 SkIRect green_rect = SkIRect::MakeLTRB(2, 2, 10, 10); 160 SkIRect green_rect = SkIRect::MakeLTRB(2, 2, 10, 10);
161 for (int y = 1; y < 10; y++) { 161 for (int y = 1; y < 10; y++) {
162 for (int x = 1; x < 10; x++) { 162 for (int x = 1; x < 10; x++) {
163 if (green_rect.contains(x, y)) { 163 if (green_rect.contains(x, y)) {
164 ASSERT_EQ(SK_ColorGREEN, result.getColor(x, y)); 164 ASSERT_EQ(SK_ColorGREEN, result.getColor(x, y));
165 } else { 165 } else {
166 ASSERT_EQ(SK_ColorRED, result.getColor(x, y)); 166 ASSERT_EQ(SK_ColorRED, result.getColor(x, y));
(...skipping 18 matching lines...) Expand all
185 gfx::Canvas canvas(gfx::Size(400, 400), image_scale, is_opaque); 185 gfx::Canvas canvas(gfx::Size(400, 400), image_scale, is_opaque);
186 186
187 gfx::Vector2d offset(20, 10); 187 gfx::Vector2d offset(20, 10);
188 canvas.Translate(offset); 188 canvas.Translate(offset);
189 canvas.Scale(2, 1); 189 canvas.Scale(2, 1);
190 190
191 gfx::Rect bounds(0, 0, 50, 50); 191 gfx::Rect bounds(0, 0, 50, 50);
192 painter.Paint(&canvas, bounds); 192 painter.Paint(&canvas, bounds);
193 193
194 SkBitmap result; 194 SkBitmap result;
195 const SkISize size = canvas.sk_canvas()->getDeviceSize(); 195 const SkISize size = canvas.sk_canvas()->getBaseLayerSize();
196 result.allocN32Pixels(size.width(), size.height()); 196 result.allocN32Pixels(size.width(), size.height());
197 canvas.sk_canvas()->readPixels(&result, 0, 0); 197 canvas.sk_canvas()->readPixels(&result, 0, 0);
198 198
199 gfx::Vector2d paint_offset = 199 gfx::Vector2d paint_offset =
200 gfx::ToFlooredVector2d(gfx::ScaleVector2d(offset, image_scale)); 200 gfx::ToFlooredVector2d(gfx::ScaleVector2d(offset, image_scale));
201 gfx::Rect green_rect = gfx::Rect(20, 10, 160, 80) + paint_offset; 201 gfx::Rect green_rect = gfx::Rect(20, 10, 160, 80) + paint_offset;
202 gfx::Rect outer_rect = gfx::Rect(200, 100) + paint_offset; 202 gfx::Rect outer_rect = gfx::Rect(200, 100) + paint_offset;
203 ExpectRedWithGreenRect(result, outer_rect, green_rect); 203 ExpectRedWithGreenRect(result, outer_rect, green_rect);
204 } 204 }
205 205
(...skipping 11 matching lines...) Expand all
217 217
218 bool is_opaque = true; 218 bool is_opaque = true;
219 gfx::Canvas canvas(gfx::Size(400, 400), image_scale, is_opaque); 219 gfx::Canvas canvas(gfx::Size(400, 400), image_scale, is_opaque);
220 canvas.Translate(gfx::Vector2d(70, 60)); 220 canvas.Translate(gfx::Vector2d(70, 60));
221 canvas.Scale(-1, -1); 221 canvas.Scale(-1, -1);
222 222
223 gfx::Rect bounds(0, 0, 50, 50); 223 gfx::Rect bounds(0, 0, 50, 50);
224 painter.Paint(&canvas, bounds); 224 painter.Paint(&canvas, bounds);
225 225
226 SkBitmap result; 226 SkBitmap result;
227 const SkISize size = canvas.sk_canvas()->getDeviceSize(); 227 const SkISize size = canvas.sk_canvas()->getBaseLayerSize();
228 result.allocN32Pixels(size.width(), size.height()); 228 result.allocN32Pixels(size.width(), size.height());
229 canvas.sk_canvas()->readPixels(&result, 0, 0); 229 canvas.sk_canvas()->readPixels(&result, 0, 0);
230 230
231 // The painting space is 50x50 and the scale of -1,-1 means an offset of 50,50 231 // The painting space is 50x50 and the scale of -1,-1 means an offset of 50,50
232 // would put the output in the top left corner. Since the offset is 70,60 it 232 // would put the output in the top left corner. Since the offset is 70,60 it
233 // moves by 20,10. Since the output is 2x DPI it will become offset by 40,20. 233 // moves by 20,10. Since the output is 2x DPI it will become offset by 40,20.
234 gfx::Vector2d paint_offset(40, 20); 234 gfx::Vector2d paint_offset(40, 20);
235 gfx::Rect green_rect = gfx::Rect(10, 10, 80, 80) + paint_offset; 235 gfx::Rect green_rect = gfx::Rect(10, 10, 80, 80) + paint_offset;
236 gfx::Rect outer_rect = gfx::Rect(100, 100) + paint_offset; 236 gfx::Rect outer_rect = gfx::Rect(100, 100) + paint_offset;
237 ExpectRedWithGreenRect(result, outer_rect, green_rect); 237 ExpectRedWithGreenRect(result, outer_rect, green_rect);
238 } 238 }
239 239
240 } // namespace gfx 240 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas.cc ('k') | ui/ozone/platform/drm/gpu/drm_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698