| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // TODO(awalker): clean up the const/non-const reference handling in this test | 5 // TODO(awalker): clean up the const/non-const reference handling in this test |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if !defined(OS_WIN) |
| 10 #include <windows.h> | |
| 11 #else | |
| 12 #include <unistd.h> | 10 #include <unistd.h> |
| 13 #endif | 11 #endif |
| 14 | 12 |
| 15 #include "skia/ext/platform_canvas.h" | 13 #include "skia/ext/platform_canvas.h" |
| 16 #include "skia/ext/platform_device.h" | 14 #include "skia/ext/platform_device.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 16 |
| 19 #include "SkColor.h" | 17 #include "SkColor.h" |
| 20 | 18 |
| 21 namespace skia { | 19 namespace skia { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 43 if (*bitmap.getAddr32(cur_x, cur_y) != canvas_color) | 41 if (*bitmap.getAddr32(cur_x, cur_y) != canvas_color) |
| 44 return false; | 42 return false; |
| 45 } | 43 } |
| 46 } | 44 } |
| 47 } | 45 } |
| 48 return true; | 46 return true; |
| 49 } | 47 } |
| 50 | 48 |
| 51 // Checks whether there is a white canvas with a black square at the given | 49 // Checks whether there is a white canvas with a black square at the given |
| 52 // location in pixels (not in the canvas coordinate system). | 50 // location in pixels (not in the canvas coordinate system). |
| 53 // TODO(ericroman): rename Square to Rect | 51 bool VerifyBlackRect(const PlatformCanvas& canvas, int x, int y, int w, int h) { |
| 54 bool VerifyBlackSquare(const PlatformCanvas& canvas, int x, int y, int w, int h)
{ | |
| 55 return VerifyRect(canvas, SK_ColorWHITE, SK_ColorBLACK, x, y, w, h); | 52 return VerifyRect(canvas, SK_ColorWHITE, SK_ColorBLACK, x, y, w, h); |
| 56 } | 53 } |
| 57 | 54 |
| 58 // Check that every pixel in the canvas is a single color. | 55 // Check that every pixel in the canvas is a single color. |
| 59 bool VerifyCanvasColor(const PlatformCanvas& canvas, uint32_t canvas_color) { | 56 bool VerifyCanvasColor(const PlatformCanvas& canvas, uint32_t canvas_color) { |
| 60 return VerifyRect(canvas, canvas_color, 0, 0, 0, 0, 0); | 57 return VerifyRect(canvas, canvas_color, 0, 0, 0, 0, 0); |
| 61 } | 58 } |
| 62 | 59 |
| 63 #if defined(OS_WIN) | 60 #if defined(OS_WIN) |
| 64 void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) { | 61 void DrawNativeRect(PlatformCanvas& canvas, int x, int y, int w, int h) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // Create the canvas initialized to opaque white. | 151 // Create the canvas initialized to opaque white. |
| 155 PlatformCanvas canvas(16, 16, true); | 152 PlatformCanvas canvas(16, 16, true); |
| 156 canvas.drawColor(SK_ColorWHITE); | 153 canvas.drawColor(SK_ColorWHITE); |
| 157 | 154 |
| 158 // Make a layer and fill it completely to make sure that the bounds are | 155 // Make a layer and fill it completely to make sure that the bounds are |
| 159 // correct. | 156 // correct. |
| 160 { | 157 { |
| 161 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); | 158 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); |
| 162 canvas.drawColor(SK_ColorBLACK); | 159 canvas.drawColor(SK_ColorBLACK); |
| 163 } | 160 } |
| 164 EXPECT_TRUE(VerifyBlackSquare(canvas, kLayerX, kLayerY, kLayerW, kLayerH)); | 161 EXPECT_TRUE(VerifyBlackRect(canvas, kLayerX, kLayerY, kLayerW, kLayerH)); |
| 165 } | 162 } |
| 166 | 163 |
| 167 // Test native clipping. | 164 // Test native clipping. |
| 168 TEST(PlatformCanvas, ClipRegion) { | 165 TEST(PlatformCanvas, ClipRegion) { |
| 169 // Initialize a white canvas | 166 // Initialize a white canvas |
| 170 PlatformCanvas canvas(16, 16, true); | 167 PlatformCanvas canvas(16, 16, true); |
| 171 canvas.drawColor(SK_ColorWHITE); | 168 canvas.drawColor(SK_ColorWHITE); |
| 172 EXPECT_TRUE(VerifyCanvasColor(canvas, SK_ColorWHITE)); | 169 EXPECT_TRUE(VerifyCanvasColor(canvas, SK_ColorWHITE)); |
| 173 | 170 |
| 174 // Test that initially the canvas has no clip region, by filling it | 171 // Test that initially the canvas has no clip region, by filling it |
| (...skipping 20 matching lines...) Expand all Loading... |
| 195 // Create the canvas initialized to opaque white. | 192 // Create the canvas initialized to opaque white. |
| 196 PlatformCanvas canvas(16, 16, true); | 193 PlatformCanvas canvas(16, 16, true); |
| 197 | 194 |
| 198 // Make a layer and fill it completely to make sure that the bounds are | 195 // Make a layer and fill it completely to make sure that the bounds are |
| 199 // correct. | 196 // correct. |
| 200 canvas.drawColor(SK_ColorWHITE); | 197 canvas.drawColor(SK_ColorWHITE); |
| 201 { | 198 { |
| 202 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); | 199 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); |
| 203 DrawNativeRect(canvas, 0, 0, 100, 100); | 200 DrawNativeRect(canvas, 0, 0, 100, 100); |
| 204 } | 201 } |
| 205 EXPECT_TRUE(VerifyBlackSquare(canvas, kLayerX, kLayerY, kLayerW, kLayerH)); | 202 EXPECT_TRUE(VerifyBlackRect(canvas, kLayerX, kLayerY, kLayerW, kLayerH)); |
| 206 | 203 |
| 207 // Make a layer and fill it partially to make sure the translation is correct. | 204 // Make a layer and fill it partially to make sure the translation is correct. |
| 208 canvas.drawColor(SK_ColorWHITE); | 205 canvas.drawColor(SK_ColorWHITE); |
| 209 { | 206 { |
| 210 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); | 207 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); |
| 211 DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH); | 208 DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH); |
| 212 } | 209 } |
| 213 EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX, kInnerY, kInnerW, kInnerH)); | 210 EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH)); |
| 214 | 211 |
| 215 // Add a clip on the layer and fill to make sure clip is correct. | 212 // Add a clip on the layer and fill to make sure clip is correct. |
| 216 canvas.drawColor(SK_ColorWHITE); | 213 canvas.drawColor(SK_ColorWHITE); |
| 217 { | 214 { |
| 218 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); | 215 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); |
| 219 canvas.save(); | 216 canvas.save(); |
| 220 AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH); | 217 AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH); |
| 221 DrawNativeRect(canvas, 0, 0, 100, 100); | 218 DrawNativeRect(canvas, 0, 0, 100, 100); |
| 222 canvas.restore(); | 219 canvas.restore(); |
| 223 } | 220 } |
| 224 EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX, kInnerY, kInnerW, kInnerH)); | 221 EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH)); |
| 225 | 222 |
| 226 // Add a clip and then make the layer to make sure the clip is correct. | 223 // Add a clip and then make the layer to make sure the clip is correct. |
| 227 canvas.drawColor(SK_ColorWHITE); | 224 canvas.drawColor(SK_ColorWHITE); |
| 228 canvas.save(); | 225 canvas.save(); |
| 229 AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH); | 226 AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH); |
| 230 { | 227 { |
| 231 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); | 228 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); |
| 232 DrawNativeRect(canvas, 0, 0, 100, 100); | 229 DrawNativeRect(canvas, 0, 0, 100, 100); |
| 233 } | 230 } |
| 234 canvas.restore(); | 231 canvas.restore(); |
| 235 EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX, kInnerY, kInnerW, kInnerH)); | 232 EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH)); |
| 236 } | 233 } |
| 237 | 234 |
| 238 // Test that translation + make layer works properly. | 235 // Test that translation + make layer works properly. |
| 239 TEST(PlatformCanvas, TranslateLayer) { | 236 TEST(PlatformCanvas, TranslateLayer) { |
| 240 // Create the canvas initialized to opaque white. | 237 // Create the canvas initialized to opaque white. |
| 241 PlatformCanvas canvas(16, 16, true); | 238 PlatformCanvas canvas(16, 16, true); |
| 242 | 239 |
| 243 // Make a layer and fill it completely to make sure that the bounds are | 240 // Make a layer and fill it completely to make sure that the bounds are |
| 244 // correct. | 241 // correct. |
| 245 canvas.drawColor(SK_ColorWHITE); | 242 canvas.drawColor(SK_ColorWHITE); |
| 246 canvas.save(); | 243 canvas.save(); |
| 247 canvas.translate(1, 1); | 244 canvas.translate(1, 1); |
| 248 { | 245 { |
| 249 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); | 246 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); |
| 250 DrawNativeRect(canvas, 0, 0, 100, 100); | 247 DrawNativeRect(canvas, 0, 0, 100, 100); |
| 251 } | 248 } |
| 252 canvas.restore(); | 249 canvas.restore(); |
| 253 EXPECT_TRUE(VerifyBlackSquare(canvas, kLayerX + 1, kLayerY + 1, | 250 EXPECT_TRUE(VerifyBlackRect(canvas, kLayerX + 1, kLayerY + 1, |
| 254 kLayerW, kLayerH)); | 251 kLayerW, kLayerH)); |
| 255 | 252 |
| 256 // Translate then make the layer. | 253 // Translate then make the layer. |
| 257 canvas.drawColor(SK_ColorWHITE); | 254 canvas.drawColor(SK_ColorWHITE); |
| 258 canvas.save(); | 255 canvas.save(); |
| 259 canvas.translate(1, 1); | 256 canvas.translate(1, 1); |
| 260 { | 257 { |
| 261 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); | 258 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); |
| 262 DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH); | 259 DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH); |
| 263 } | 260 } |
| 264 canvas.restore(); | 261 canvas.restore(); |
| 265 EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX + 1, kInnerY + 1, | 262 EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX + 1, kInnerY + 1, |
| 266 kInnerW, kInnerH)); | 263 kInnerW, kInnerH)); |
| 267 | 264 |
| 268 // Make the layer then translate. | 265 // Make the layer then translate. |
| 269 canvas.drawColor(SK_ColorWHITE); | 266 canvas.drawColor(SK_ColorWHITE); |
| 270 canvas.save(); | 267 canvas.save(); |
| 271 { | 268 { |
| 272 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); | 269 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); |
| 273 canvas.translate(1, 1); | 270 canvas.translate(1, 1); |
| 274 DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH); | 271 DrawNativeRect(canvas, kInnerX, kInnerY, kInnerW, kInnerH); |
| 275 } | 272 } |
| 276 canvas.restore(); | 273 canvas.restore(); |
| 277 EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX + 1, kInnerY + 1, | 274 EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX + 1, kInnerY + 1, |
| 278 kInnerW, kInnerH)); | 275 kInnerW, kInnerH)); |
| 279 | 276 |
| 280 // Translate both before and after, and have a clip. | 277 // Translate both before and after, and have a clip. |
| 281 canvas.drawColor(SK_ColorWHITE); | 278 canvas.drawColor(SK_ColorWHITE); |
| 282 canvas.save(); | 279 canvas.save(); |
| 283 canvas.translate(1, 1); | 280 canvas.translate(1, 1); |
| 284 { | 281 { |
| 285 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); | 282 LayerSaver layer(canvas, kLayerX, kLayerY, kLayerW, kLayerH); |
| 286 canvas.translate(1, 1); | 283 canvas.translate(1, 1); |
| 287 AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH); | 284 AddClip(canvas, kInnerX, kInnerY, kInnerW, kInnerH); |
| 288 DrawNativeRect(canvas, 0, 0, 100, 100); | 285 DrawNativeRect(canvas, 0, 0, 100, 100); |
| 289 } | 286 } |
| 290 canvas.restore(); | 287 canvas.restore(); |
| 291 EXPECT_TRUE(VerifyBlackSquare(canvas, kInnerX + 2, kInnerY + 2, | 288 EXPECT_TRUE(VerifyBlackRect(canvas, kInnerX + 2, kInnerY + 2, |
| 292 kInnerW, kInnerH)); | 289 kInnerW, kInnerH)); |
| 293 } | 290 } |
| 294 | 291 |
| 295 } // namespace skia | 292 } // namespace skia |
| 296 | |
| OLD | NEW |