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

Side by Side Diff: skia/ext/vector_canvas_unittest.cc

Issue 125109: Refactor the PlatformContext layer to have only one class. (Closed)
Patch Set: Created 11 years, 6 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
« no previous file with comments | « skia/ext/vector_canvas.cc ('k') | skia/ext/vector_device.h » ('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 (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 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "webkit/tools/test_shell/image_decoder_unittest.h" 7 #include "webkit/tools/test_shell/image_decoder_unittest.h"
8 8
9 #if !defined(OS_WIN) 9 #if !defined(OS_WIN)
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 ReadFileToVector(filename, &compressed); 80 ReadFileToVector(filename, &compressed);
81 EXPECT_TRUE(compressed.size()); 81 EXPECT_TRUE(compressed.size());
82 WebCore::PNGImageDecoder decoder; 82 WebCore::PNGImageDecoder decoder;
83 decoder.setData(WebCore::SharedBuffer::adoptVector(compressed).get(), true); 83 decoder.setData(WebCore::SharedBuffer::adoptVector(compressed).get(), true);
84 scoped_ptr<NativeImageSkia> image_data( 84 scoped_ptr<NativeImageSkia> image_data(
85 decoder.frameBufferAtIndex(0)->asNewNativeImage()); 85 decoder.frameBufferAtIndex(0)->asNewNativeImage());
86 SetSkBitmap(*image_data); 86 SetSkBitmap(*image_data);
87 } 87 }
88 88
89 // Loads the image from a canvas. 89 // Loads the image from a canvas.
90 Image(const skia::PlatformCanvasWin& canvas) : ignore_alpha_(true) { 90 Image(const skia::PlatformCanvas& canvas) : ignore_alpha_(true) {
91 // Use a different way to access the bitmap. The normal way would be to 91 // Use a different way to access the bitmap. The normal way would be to
92 // query the SkBitmap. 92 // query the SkBitmap.
93 HDC context = canvas.getTopPlatformDevice().getBitmapDC(); 93 HDC context = canvas.getTopPlatformDevice().getBitmapDC();
94 HGDIOBJ bitmap = GetCurrentObject(context, OBJ_BITMAP); 94 HGDIOBJ bitmap = GetCurrentObject(context, OBJ_BITMAP);
95 EXPECT_TRUE(bitmap != NULL); 95 EXPECT_TRUE(bitmap != NULL);
96 // Initialize the clip region to the entire bitmap. 96 // Initialize the clip region to the entire bitmap.
97 BITMAP bitmap_data; 97 BITMAP bitmap_data;
98 EXPECT_EQ(GetObject(bitmap, sizeof(BITMAP), &bitmap_data), sizeof(BITMAP)); 98 EXPECT_EQ(GetObject(bitmap, sizeof(BITMAP), &bitmap_data), sizeof(BITMAP));
99 width_ = bitmap_data.bmWidth; 99 width_ = bitmap_data.bmWidth;
100 height_ = bitmap_data.bmHeight; 100 height_ = bitmap_data.bmHeight;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 249
250 std::wstring path(test_dir_); 250 std::wstring path(test_dir_);
251 file_util::AppendToPath(&path, ASCIIToWide(tmp)); 251 file_util::AppendToPath(&path, ASCIIToWide(tmp));
252 return path; 252 return path;
253 } 253 }
254 254
255 // Compares or saves the bitmap currently loaded in the context, depending on 255 // Compares or saves the bitmap currently loaded in the context, depending on
256 // kGenerating value. Returns 0 on success or any positive value between ]0, 256 // kGenerating value. Returns 0 on success or any positive value between ]0,
257 // 100] on failure. The return value is the percentage of difference between 257 // 100] on failure. The return value is the percentage of difference between
258 // the image in the file and the image in the canvas. 258 // the image in the file and the image in the canvas.
259 double ProcessCanvas(const skia::PlatformCanvasWin& canvas, 259 double ProcessCanvas(const skia::PlatformCanvas& canvas,
260 std::wstring filename) const { 260 std::wstring filename) const {
261 filename += L".png"; 261 filename += L".png";
262 switch (action_) { 262 switch (action_) {
263 case GENERATE: 263 case GENERATE:
264 SaveImage(canvas, filename); 264 SaveImage(canvas, filename);
265 return 0.; 265 return 0.;
266 case COMPARE: 266 case COMPARE:
267 return CompareImage(canvas, filename); 267 return CompareImage(canvas, filename);
268 case NOOP: 268 case NOOP:
269 return 0; 269 return 0;
270 default: 270 default:
271 // Invalid state, returns that the image is 100 different. 271 // Invalid state, returns that the image is 100 different.
272 return 100.; 272 return 100.;
273 } 273 }
274 } 274 }
275 275
276 // Compares the bitmap currently loaded in the context with the file. Returns 276 // Compares the bitmap currently loaded in the context with the file. Returns
277 // the percentage of pixel difference between both images, between 0 and 100. 277 // the percentage of pixel difference between both images, between 0 and 100.
278 double CompareImage(const skia::PlatformCanvasWin& canvas, 278 double CompareImage(const skia::PlatformCanvas& canvas,
279 const std::wstring& filename) const { 279 const std::wstring& filename) const {
280 Image image1(canvas); 280 Image image1(canvas);
281 Image image2(test_file(filename)); 281 Image image2(test_file(filename));
282 double diff = image1.PercentageDifferent(image2); 282 double diff = image1.PercentageDifferent(image2);
283 return diff; 283 return diff;
284 } 284 }
285 285
286 // Saves the bitmap currently loaded in the context into the file. 286 // Saves the bitmap currently loaded in the context into the file.
287 void SaveImage(const skia::PlatformCanvasWin& canvas, 287 void SaveImage(const skia::PlatformCanvas& canvas,
288 const std::wstring& filename) const { 288 const std::wstring& filename) const {
289 Image(canvas).SaveToFile(test_file(filename)); 289 Image(canvas).SaveToFile(test_file(filename));
290 } 290 }
291 291
292 ProcessAction action_; 292 ProcessAction action_;
293 293
294 // Path to directory used to contain the test data. 294 // Path to directory used to contain the test data.
295 std::wstring test_dir_; 295 std::wstring test_dir_;
296 296
297 DISALLOW_EVIL_CONSTRUCTORS(ImageTest); 297 DISALLOW_EVIL_CONSTRUCTORS(ImageTest);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 context_ = NULL; 372 context_ = NULL;
373 373
374 parent::TearDown(); 374 parent::TearDown();
375 } 375 }
376 376
377 void Init(int size) { 377 void Init(int size) {
378 size_ = size; 378 size_ = size;
379 context_ = new Context(); 379 context_ = new Context();
380 bitmap_ = new Bitmap(*context_, size_, size_); 380 bitmap_ = new Bitmap(*context_, size_, size_);
381 vcanvas_ = new VectorCanvas(context_->context(), size_, size_); 381 vcanvas_ = new VectorCanvas(context_->context(), size_, size_);
382 pcanvas_ = new PlatformCanvasWin(size_, size_, false); 382 pcanvas_ = new PlatformCanvas(size_, size_, false);
383 383
384 // Clear white. 384 // Clear white.
385 vcanvas_->drawARGB(255, 255, 255, 255, SkPorterDuff::kSrc_Mode); 385 vcanvas_->drawARGB(255, 255, 255, 255, SkPorterDuff::kSrc_Mode);
386 pcanvas_->drawARGB(255, 255, 255, 255, SkPorterDuff::kSrc_Mode); 386 pcanvas_->drawARGB(255, 255, 255, 255, SkPorterDuff::kSrc_Mode);
387 } 387 }
388 388
389 // Compares both canvas and returns the pixel difference in percentage between 389 // Compares both canvas and returns the pixel difference in percentage between
390 // both images. 0 on success and ]0, 100] on failure. 390 // both images. 0 on success and ]0, 100] on failure.
391 double ProcessImage(const std::wstring& filename) { 391 double ProcessImage(const std::wstring& filename) {
392 std::wstring number(StringPrintf(L"%02d_", number_++)); 392 std::wstring number(StringPrintf(L"%02d_", number_++));
(...skipping 24 matching lines...) Expand all
417 // A temporary HDC to draw into. 417 // A temporary HDC to draw into.
418 Context* context_; 418 Context* context_;
419 419
420 // Bitmap created inside context_. 420 // Bitmap created inside context_.
421 Bitmap* bitmap_; 421 Bitmap* bitmap_;
422 422
423 // Vector based canvas. 423 // Vector based canvas.
424 VectorCanvas* vcanvas_; 424 VectorCanvas* vcanvas_;
425 425
426 // Pixel based canvas. 426 // Pixel based canvas.
427 PlatformCanvasWin* pcanvas_; 427 PlatformCanvas* pcanvas_;
428 428
429 // When true (default), vcanvas_ and pcanvas_ contents are compared and 429 // When true (default), vcanvas_ and pcanvas_ contents are compared and
430 // verified to be identical. 430 // verified to be identical.
431 bool compare_canvas_; 431 bool compare_canvas_;
432 }; 432 };
433 433
434 434
435 //////////////////////////////////////////////////////////////////////////////// 435 ////////////////////////////////////////////////////////////////////////////////
436 // Actual tests 436 // Actual tests
437 437
438 TEST_F(VectorCanvasTest, Uninitialized) { 438 TEST_F(VectorCanvasTest, Uninitialized) {
439 // Do a little mubadumba do get uninitialized stuff. 439 // Do a little mubadumba do get uninitialized stuff.
440 VectorCanvasTest::TearDown(); 440 VectorCanvasTest::TearDown();
441 441
442 // The goal is not to verify that have the same uninitialized data. 442 // The goal is not to verify that have the same uninitialized data.
443 compare_canvas_ = false; 443 compare_canvas_ = false;
444 444
445 context_ = new Context(); 445 context_ = new Context();
446 bitmap_ = new Bitmap(*context_, size_, size_); 446 bitmap_ = new Bitmap(*context_, size_, size_);
447 vcanvas_ = new VectorCanvas(context_->context(), size_, size_); 447 vcanvas_ = new VectorCanvas(context_->context(), size_, size_);
448 pcanvas_ = new PlatformCanvasWin(size_, size_, false); 448 pcanvas_ = new PlatformCanvas(size_, size_, false);
449 449
450 // VectorCanvas default initialization is black. 450 // VectorCanvas default initialization is black.
451 // PlatformCanvas default initialization is almost white 0x01FFFEFD (invalid 451 // PlatformCanvas default initialization is almost white 0x01FFFEFD (invalid
452 // Skia color) in both Debug and Release. See magicTransparencyColor in 452 // Skia color) in both Debug and Release. See magicTransparencyColor in
453 // platform_device.cc 453 // platform_device.cc
454 EXPECT_EQ(0., ProcessImage(L"empty")); 454 EXPECT_EQ(0., ProcessImage(L"empty"));
455 } 455 }
456 456
457 TEST_F(VectorCanvasTest, BasicDrawing) { 457 TEST_F(VectorCanvasTest, BasicDrawing) {
458 EXPECT_EQ(Image(*vcanvas_).PercentageDifferent(Image(*pcanvas_)), 0.) 458 EXPECT_EQ(Image(*vcanvas_).PercentageDifferent(Image(*pcanvas_)), 0.)
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 { 956 {
957 vcanvas_->rotate(67); 957 vcanvas_->rotate(67);
958 pcanvas_->rotate(67); 958 pcanvas_->rotate(67);
959 vcanvas_->drawBitmap(bitmap, 20, -50, NULL); 959 vcanvas_->drawBitmap(bitmap, 20, -50, NULL);
960 pcanvas_->drawBitmap(bitmap, 20, -50, NULL); 960 pcanvas_->drawBitmap(bitmap, 20, -50, NULL);
961 EXPECT_EQ(0., ProcessImage(L"rotate")); 961 EXPECT_EQ(0., ProcessImage(L"rotate"));
962 } 962 }
963 } 963 }
964 964
965 } // namespace skia 965 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/vector_canvas.cc ('k') | skia/ext/vector_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698