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