| 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 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if !defined(OS_WIN) | 7 #if !defined(OS_WIN) |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "skia/ext/vector_canvas.h" | 16 #include "skia/ext/vector_canvas.h" |
| 17 #include "skia/ext/vector_platform_device.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/skia/include/effects/SkDashPathEffect.h" | 19 #include "third_party/skia/include/effects/SkDashPathEffect.h" |
| 19 #include "ui/gfx/codec/png_codec.h" | 20 #include "ui/gfx/codec/png_codec.h" |
| 20 | 21 |
| 21 namespace skia { | 22 namespace skia { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 const char kGenerateSwitch[] = "vector-canvas-generate"; | 26 const char kGenerateSwitch[] = "vector-canvas-generate"; |
| 26 | 27 |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 delete context_; | 380 delete context_; |
| 380 context_ = NULL; | 381 context_ = NULL; |
| 381 | 382 |
| 382 parent::TearDown(); | 383 parent::TearDown(); |
| 383 } | 384 } |
| 384 | 385 |
| 385 void Init(int size) { | 386 void Init(int size) { |
| 386 size_ = size; | 387 size_ = size; |
| 387 context_ = new Context(); | 388 context_ = new Context(); |
| 388 bitmap_ = new Bitmap(*context_, size_, size_); | 389 bitmap_ = new Bitmap(*context_, size_, size_); |
| 389 vcanvas_ = new VectorCanvas(context_->context(), size_, size_); | 390 vcanvas_ = new VectorCanvas(VectorPlatformDeviceFactory::CreateDevice( |
| 391 size_, size_, true, context_->context())); |
| 390 pcanvas_ = new PlatformCanvas(size_, size_, false); | 392 pcanvas_ = new PlatformCanvas(size_, size_, false); |
| 391 | 393 |
| 392 // Clear white. | 394 // Clear white. |
| 393 vcanvas_->drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode); | 395 vcanvas_->drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode); |
| 394 pcanvas_->drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode); | 396 pcanvas_->drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode); |
| 395 } | 397 } |
| 396 | 398 |
| 397 // Compares both canvas and returns the pixel difference in percentage between | 399 // Compares both canvas and returns the pixel difference in percentage between |
| 398 // both images. 0 on success and ]0, 100] on failure. | 400 // both images. 0 on success and ]0, 100] on failure. |
| 399 double ProcessImage(const FilePath::StringType& filename) { | 401 double ProcessImage(const FilePath::StringType& filename) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 | 447 |
| 446 TEST_F(VectorCanvasTest, Uninitialized) { | 448 TEST_F(VectorCanvasTest, Uninitialized) { |
| 447 // Do a little mubadumba do get uninitialized stuff. | 449 // Do a little mubadumba do get uninitialized stuff. |
| 448 VectorCanvasTest::TearDown(); | 450 VectorCanvasTest::TearDown(); |
| 449 | 451 |
| 450 // The goal is not to verify that have the same uninitialized data. | 452 // The goal is not to verify that have the same uninitialized data. |
| 451 compare_canvas_ = false; | 453 compare_canvas_ = false; |
| 452 | 454 |
| 453 context_ = new Context(); | 455 context_ = new Context(); |
| 454 bitmap_ = new Bitmap(*context_, size_, size_); | 456 bitmap_ = new Bitmap(*context_, size_, size_); |
| 455 vcanvas_ = new VectorCanvas(context_->context(), size_, size_); | 457 vcanvas_ = new VectorCanvas(VectorPlatformDeviceFactory::CreateDevice( |
| 458 size_, size_, true, context_->context())); |
| 456 pcanvas_ = new PlatformCanvas(size_, size_, false); | 459 pcanvas_ = new PlatformCanvas(size_, size_, false); |
| 457 | 460 |
| 458 // VectorCanvas default initialization is black. | 461 // VectorCanvas default initialization is black. |
| 459 // PlatformCanvas default initialization is almost white 0x01FFFEFD (invalid | 462 // PlatformCanvas default initialization is almost white 0x01FFFEFD (invalid |
| 460 // Skia color) in both Debug and Release. See magicTransparencyColor in | 463 // Skia color) in both Debug and Release. See magicTransparencyColor in |
| 461 // platform_device.cc | 464 // platform_device.cc |
| 462 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("empty"))); | 465 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("empty"))); |
| 463 } | 466 } |
| 464 | 467 |
| 465 TEST_F(VectorCanvasTest, BasicDrawing) { | 468 TEST_F(VectorCanvasTest, BasicDrawing) { |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 965 { | 968 { |
| 966 vcanvas_->rotate(67); | 969 vcanvas_->rotate(67); |
| 967 pcanvas_->rotate(67); | 970 pcanvas_->rotate(67); |
| 968 vcanvas_->drawBitmap(bitmap, 20, -50, NULL); | 971 vcanvas_->drawBitmap(bitmap, 20, -50, NULL); |
| 969 pcanvas_->drawBitmap(bitmap, 20, -50, NULL); | 972 pcanvas_->drawBitmap(bitmap, 20, -50, NULL); |
| 970 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("rotate"))); | 973 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("rotate"))); |
| 971 } | 974 } |
| 972 } | 975 } |
| 973 | 976 |
| 974 } // namespace skia | 977 } // namespace skia |
| OLD | NEW |