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

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

Issue 271099: Re-try r29078: Remove some deprecated file_util wstring functions. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « net/tools/crash_cache/crash_cache.cc ('k') | tools/memory_watcher/memory_watcher.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 (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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 void* data_; 77 void* data_;
78 78
79 DISALLOW_COPY_AND_ASSIGN(Bitmap); 79 DISALLOW_COPY_AND_ASSIGN(Bitmap);
80 }; 80 };
81 81
82 // Lightweight raw-bitmap management. The image, once initialized, is immuable. 82 // Lightweight raw-bitmap management. The image, once initialized, is immuable.
83 // It is mainly used for comparison. 83 // It is mainly used for comparison.
84 class Image { 84 class Image {
85 public: 85 public:
86 // Creates the image from the given filename on disk. 86 // Creates the image from the given filename on disk.
87 Image(const std::wstring& filename) : ignore_alpha_(true) { 87 explicit Image(const FilePath& filename) : ignore_alpha_(true) {
88 Vector<char> compressed; 88 Vector<char> compressed;
89 ReadFileToVector(filename, &compressed); 89 ReadFileToVector(filename, &compressed);
90 EXPECT_TRUE(compressed.size()); 90 EXPECT_TRUE(compressed.size());
91 WebCore::PNGImageDecoder decoder; 91 WebCore::PNGImageDecoder decoder;
92 decoder.setData(WebCore::SharedBuffer::adoptVector(compressed).get(), true); 92 decoder.setData(WebCore::SharedBuffer::adoptVector(compressed).get(), true);
93 scoped_ptr<NativeImageSkia> image_data( 93 scoped_ptr<NativeImageSkia> image_data(
94 decoder.frameBufferAtIndex(0)->asNewNativeImage()); 94 decoder.frameBufferAtIndex(0)->asNewNativeImage());
95 SetSkBitmap(*image_data); 95 SetSkBitmap(*image_data);
96 } 96 }
97 97
(...skipping 18 matching lines...) Expand all
116 // Loads the image from a canvas. 116 // Loads the image from a canvas.
117 Image(const SkBitmap& bitmap) : ignore_alpha_(true) { 117 Image(const SkBitmap& bitmap) : ignore_alpha_(true) {
118 SetSkBitmap(bitmap); 118 SetSkBitmap(bitmap);
119 } 119 }
120 120
121 int width() const { return width_; } 121 int width() const { return width_; }
122 int height() const { return height_; } 122 int height() const { return height_; }
123 int row_length() const { return row_length_; } 123 int row_length() const { return row_length_; }
124 124
125 // Save the image to a png file. Used to create the initial test files. 125 // Save the image to a png file. Used to create the initial test files.
126 void SaveToFile(const std::wstring& filename) { 126 void SaveToFile(const FilePath& filename) {
127 std::vector<unsigned char> compressed; 127 std::vector<unsigned char> compressed;
128 ASSERT_TRUE(gfx::PNGCodec::Encode(&*data_.begin(), 128 ASSERT_TRUE(gfx::PNGCodec::Encode(&*data_.begin(),
129 gfx::PNGCodec::FORMAT_BGRA, 129 gfx::PNGCodec::FORMAT_BGRA,
130 width_, 130 width_,
131 height_, 131 height_,
132 row_length_, 132 row_length_,
133 true, 133 true,
134 &compressed)); 134 &compressed));
135 ASSERT_TRUE(compressed.size()); 135 ASSERT_TRUE(compressed.size());
136 FILE* f = file_util::OpenFile(filename, "wb"); 136 FILE* f = file_util::OpenFile(filename, "wb");
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 222
223 ImageTest(ProcessAction default_action) 223 ImageTest(ProcessAction default_action)
224 : action_(default_action) { 224 : action_(default_action) {
225 } 225 }
226 226
227 protected: 227 protected:
228 virtual void SetUp() { 228 virtual void SetUp() {
229 const testing::TestInfo& test_info = 229 const testing::TestInfo& test_info =
230 *testing::UnitTest::GetInstance()->current_test_info(); 230 *testing::UnitTest::GetInstance()->current_test_info();
231 PathService::Get(base::DIR_SOURCE_ROOT, &test_dir_); 231 PathService::Get(base::DIR_SOURCE_ROOT, &test_dir_);
232 file_util::AppendToPath(&test_dir_, L"skia"); 232 test_dir_ = test_dir_.AppendASCII("skia").
233 file_util::AppendToPath(&test_dir_, L"ext"); 233 AppendASCII("ext").
234 file_util::AppendToPath(&test_dir_, L"data"); 234 AppendASCII("data").
235 file_util::AppendToPath(&test_dir_, 235 AppendASCII(test_info.test_case_name()).
236 ASCIIToWide(test_info.test_case_name())); 236 AppendASCII(test_info.name());
237 file_util::AppendToPath(&test_dir_, ASCIIToWide(test_info.name()));
238 237
239 // Hack for a quick lowercase. We assume all the tests names are ASCII. 238 // Hack for a quick lowercase. We assume all the tests names are ASCII.
240 std::string tmp(WideToASCII(test_dir_)); 239 std::string tmp(WideToASCII(test_dir_.ToWStringHack()));
241 for (size_t i = 0; i < tmp.size(); ++i) 240 for (size_t i = 0; i < tmp.size(); ++i)
242 tmp[i] = ToLowerASCII(tmp[i]); 241 tmp[i] = ToLowerASCII(tmp[i]);
243 test_dir_ = ASCIIToWide(tmp); 242 test_dir_ = FilePath::FromWStringHack(ASCIIToWide(tmp));
244 243
245 if (action_ == GENERATE) { 244 if (action_ == GENERATE) {
246 // Make sure the directory exist. 245 // Make sure the directory exist.
247 file_util::CreateDirectory(test_dir_); 246 file_util::CreateDirectory(test_dir_);
248 } 247 }
249 } 248 }
250 249
251 // Returns the fully qualified path of a data file. 250 // Returns the fully qualified path of a data file.
252 std::wstring test_file(const std::wstring& filename) const { 251 FilePath test_file(const FilePath::StringType& filename) const {
253 // Hack for a quick lowercase. We assume all the test data file names are 252 // Hack for a quick lowercase. We assume all the test data file names are
254 // ASCII. 253 // ASCII.
255 std::string tmp(WideToASCII(filename)); 254 #if defined(OS_WIN)
255 std::string tmp = WideToASCII(filename);
256 #else
257 std::string tmp(filename);
258 #endif
256 for (size_t i = 0; i < tmp.size(); ++i) 259 for (size_t i = 0; i < tmp.size(); ++i)
257 tmp[i] = ToLowerASCII(tmp[i]); 260 tmp[i] = ToLowerASCII(tmp[i]);
258 261
259 std::wstring path(test_dir_); 262 return test_dir_.AppendASCII(tmp);
260 file_util::AppendToPath(&path, ASCIIToWide(tmp));
261 return path;
262 } 263 }
263 264
264 // Compares or saves the bitmap currently loaded in the context, depending on 265 // Compares or saves the bitmap currently loaded in the context, depending on
265 // kGenerating value. Returns 0 on success or any positive value between ]0, 266 // kGenerating value. Returns 0 on success or any positive value between ]0,
266 // 100] on failure. The return value is the percentage of difference between 267 // 100] on failure. The return value is the percentage of difference between
267 // the image in the file and the image in the canvas. 268 // the image in the file and the image in the canvas.
268 double ProcessCanvas(const skia::PlatformCanvas& canvas, 269 double ProcessCanvas(const skia::PlatformCanvas& canvas,
269 std::wstring filename) const { 270 FilePath::StringType filename) const {
270 filename += L".png"; 271 filename = filename + FILE_PATH_LITERAL(".png");
271 switch (action_) { 272 switch (action_) {
272 case GENERATE: 273 case GENERATE:
273 SaveImage(canvas, filename); 274 SaveImage(canvas, filename);
274 return 0.; 275 return 0.;
275 case COMPARE: 276 case COMPARE:
276 return CompareImage(canvas, filename); 277 return CompareImage(canvas, filename);
277 case NOOP: 278 case NOOP:
278 return 0; 279 return 0;
279 default: 280 default:
280 // Invalid state, returns that the image is 100 different. 281 // Invalid state, returns that the image is 100 different.
281 return 100.; 282 return 100.;
282 } 283 }
283 } 284 }
284 285
285 // Compares the bitmap currently loaded in the context with the file. Returns 286 // Compares the bitmap currently loaded in the context with the file. Returns
286 // the percentage of pixel difference between both images, between 0 and 100. 287 // the percentage of pixel difference between both images, between 0 and 100.
287 double CompareImage(const skia::PlatformCanvas& canvas, 288 double CompareImage(const skia::PlatformCanvas& canvas,
288 const std::wstring& filename) const { 289 const FilePath::StringType& filename) const {
289 Image image1(canvas); 290 Image image1(canvas);
290 Image image2(test_file(filename)); 291 Image image2(test_file(filename));
291 double diff = image1.PercentageDifferent(image2); 292 double diff = image1.PercentageDifferent(image2);
292 return diff; 293 return diff;
293 } 294 }
294 295
295 // Saves the bitmap currently loaded in the context into the file. 296 // Saves the bitmap currently loaded in the context into the file.
296 void SaveImage(const skia::PlatformCanvas& canvas, 297 void SaveImage(const skia::PlatformCanvas& canvas,
297 const std::wstring& filename) const { 298 const FilePath::StringType& filename) const {
298 Image(canvas).SaveToFile(test_file(filename)); 299 Image(canvas).SaveToFile(test_file(filename));
299 } 300 }
300 301
301 ProcessAction action_; 302 ProcessAction action_;
302 303
303 // Path to directory used to contain the test data. 304 // Path to directory used to contain the test data.
304 std::wstring test_dir_; 305 FilePath test_dir_;
305 306
306 DISALLOW_COPY_AND_ASSIGN(ImageTest); 307 DISALLOW_COPY_AND_ASSIGN(ImageTest);
307 }; 308 };
308 309
309 // Premultiply the Alpha channel on the R, B and G channels. 310 // Premultiply the Alpha channel on the R, B and G channels.
310 void Premultiply(SkBitmap bitmap) { 311 void Premultiply(SkBitmap bitmap) {
311 SkAutoLockPixels lock(bitmap); 312 SkAutoLockPixels lock(bitmap);
312 for (int x = 0; x < bitmap.width(); ++x) { 313 for (int x = 0; x < bitmap.width(); ++x) {
313 for (int y = 0; y < bitmap.height(); ++y) { 314 for (int y = 0; y < bitmap.height(); ++y) {
314 uint32_t* pixel_addr = bitmap.getAddr32(x, y); 315 uint32_t* pixel_addr = bitmap.getAddr32(x, y);
315 uint32_t color = *pixel_addr; 316 uint32_t color = *pixel_addr;
316 BYTE alpha = SkColorGetA(color); 317 BYTE alpha = SkColorGetA(color);
317 if (!alpha) { 318 if (!alpha) {
318 *pixel_addr = 0; 319 *pixel_addr = 0;
319 } else { 320 } else {
320 BYTE alpha_offset = alpha / 2; 321 BYTE alpha_offset = alpha / 2;
321 *pixel_addr = SkColorSetARGB( 322 *pixel_addr = SkColorSetARGB(
322 SkColorGetA(color), 323 SkColorGetA(color),
323 (SkColorGetR(color) * 255 + alpha_offset) / alpha, 324 (SkColorGetR(color) * 255 + alpha_offset) / alpha,
324 (SkColorGetG(color) * 255 + alpha_offset) / alpha, 325 (SkColorGetG(color) * 255 + alpha_offset) / alpha,
325 (SkColorGetB(color) * 255 + alpha_offset) / alpha); 326 (SkColorGetB(color) * 255 + alpha_offset) / alpha);
326 } 327 }
327 } 328 }
328 } 329 }
329 } 330 }
330 331
331 void LoadPngFileToSkBitmap(const std::wstring& filename, 332 void LoadPngFileToSkBitmap(const FilePath& filename,
332 SkBitmap* bitmap, 333 SkBitmap* bitmap,
333 bool is_opaque) { 334 bool is_opaque) {
334 Vector<char> compressed; 335 Vector<char> compressed;
335 ReadFileToVector(filename, &compressed); 336 ReadFileToVector(filename, &compressed);
336 EXPECT_TRUE(compressed.size()); 337 EXPECT_TRUE(compressed.size());
337 WebCore::PNGImageDecoder decoder; 338 WebCore::PNGImageDecoder decoder;
338 decoder.setData(WebCore::SharedBuffer::adoptVector(compressed).get(), true); 339 decoder.setData(WebCore::SharedBuffer::adoptVector(compressed).get(), true);
339 scoped_ptr<NativeImageSkia> image_data( 340 scoped_ptr<NativeImageSkia> image_data(
340 decoder.frameBufferAtIndex(0)->asNewNativeImage()); 341 decoder.frameBufferAtIndex(0)->asNewNativeImage());
341 *bitmap = *image_data; 342 *bitmap = *image_data;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 vcanvas_ = new VectorCanvas(context_->context(), size_, size_); 391 vcanvas_ = new VectorCanvas(context_->context(), size_, size_);
391 pcanvas_ = new PlatformCanvas(size_, size_, false); 392 pcanvas_ = new PlatformCanvas(size_, size_, false);
392 393
393 // Clear white. 394 // Clear white.
394 vcanvas_->drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode); 395 vcanvas_->drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode);
395 pcanvas_->drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode); 396 pcanvas_->drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode);
396 } 397 }
397 398
398 // Compares both canvas and returns the pixel difference in percentage between 399 // Compares both canvas and returns the pixel difference in percentage between
399 // both images. 0 on success and ]0, 100] on failure. 400 // both images. 0 on success and ]0, 100] on failure.
400 double ProcessImage(const std::wstring& filename) { 401 double ProcessImage(const FilePath::StringType& filename) {
401 std::wstring number(StringPrintf(L"%02d_", number_++)); 402 std::wstring number(StringPrintf(L"%02d_", number_++));
402 double diff1 = parent::ProcessCanvas(*vcanvas_, number + L"vc_" + filename); 403 double diff1 = parent::ProcessCanvas(*vcanvas_, number + L"vc_" + filename);
403 double diff2 = parent::ProcessCanvas(*pcanvas_, number + L"pc_" + filename); 404 double diff2 = parent::ProcessCanvas(*pcanvas_, number + L"pc_" + filename);
404 if (!compare_canvas_) 405 if (!compare_canvas_)
405 return std::max(diff1, diff2); 406 return std::max(diff1, diff2);
406 407
407 Image image1(*vcanvas_); 408 Image image1(*vcanvas_);
408 Image image2(*pcanvas_); 409 Image image2(*pcanvas_);
409 double diff = image1.PercentageDifferent(image2); 410 double diff = image1.PercentageDifferent(image2);
410 return std::max(std::max(diff1, diff2), diff); 411 return std::max(std::max(diff1, diff2), diff);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 454
454 context_ = new Context(); 455 context_ = new Context();
455 bitmap_ = new Bitmap(*context_, size_, size_); 456 bitmap_ = new Bitmap(*context_, size_, size_);
456 vcanvas_ = new VectorCanvas(context_->context(), size_, size_); 457 vcanvas_ = new VectorCanvas(context_->context(), size_, size_);
457 pcanvas_ = new PlatformCanvas(size_, size_, false); 458 pcanvas_ = new PlatformCanvas(size_, size_, false);
458 459
459 // VectorCanvas default initialization is black. 460 // VectorCanvas default initialization is black.
460 // PlatformCanvas default initialization is almost white 0x01FFFEFD (invalid 461 // PlatformCanvas default initialization is almost white 0x01FFFEFD (invalid
461 // Skia color) in both Debug and Release. See magicTransparencyColor in 462 // Skia color) in both Debug and Release. See magicTransparencyColor in
462 // platform_device.cc 463 // platform_device.cc
463 EXPECT_EQ(0., ProcessImage(L"empty")); 464 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("empty")));
464 } 465 }
465 466
466 TEST_F(VectorCanvasTest, BasicDrawing) { 467 TEST_F(VectorCanvasTest, BasicDrawing) {
467 EXPECT_EQ(Image(*vcanvas_).PercentageDifferent(Image(*pcanvas_)), 0.) 468 EXPECT_EQ(Image(*vcanvas_).PercentageDifferent(Image(*pcanvas_)), 0.)
468 << L"clean"; 469 << L"clean";
469 EXPECT_EQ(0., ProcessImage(L"clean")); 470 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("clean")));
470 471
471 // Clear white. 472 // Clear white.
472 { 473 {
473 vcanvas_->drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode); 474 vcanvas_->drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode);
474 pcanvas_->drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode); 475 pcanvas_->drawARGB(255, 255, 255, 255, SkXfermode::kSrc_Mode);
475 } 476 }
476 EXPECT_EQ(0., ProcessImage(L"drawARGB")); 477 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("drawARGB")));
477 478
478 // Diagonal line top-left to bottom-right. 479 // Diagonal line top-left to bottom-right.
479 { 480 {
480 SkPaint paint; 481 SkPaint paint;
481 // Default color is black. 482 // Default color is black.
482 vcanvas_->drawLine(10, 10, 90, 90, paint); 483 vcanvas_->drawLine(10, 10, 90, 90, paint);
483 pcanvas_->drawLine(10, 10, 90, 90, paint); 484 pcanvas_->drawLine(10, 10, 90, 90, paint);
484 } 485 }
485 EXPECT_EQ(0., ProcessImage(L"drawLine_black")); 486 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("drawLine_black")));
486 487
487 // Rect. 488 // Rect.
488 { 489 {
489 SkPaint paint; 490 SkPaint paint;
490 paint.setColor(SK_ColorGREEN); 491 paint.setColor(SK_ColorGREEN);
491 vcanvas_->drawRectCoords(25, 25, 75, 75, paint); 492 vcanvas_->drawRectCoords(25, 25, 75, 75, paint);
492 pcanvas_->drawRectCoords(25, 25, 75, 75, paint); 493 pcanvas_->drawRectCoords(25, 25, 75, 75, paint);
493 } 494 }
494 EXPECT_EQ(0., ProcessImage(L"drawRect_green")); 495 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("drawRect_green")));
495 496
496 // A single-point rect doesn't leave any mark. 497 // A single-point rect doesn't leave any mark.
497 { 498 {
498 SkPaint paint; 499 SkPaint paint;
499 paint.setColor(SK_ColorBLUE); 500 paint.setColor(SK_ColorBLUE);
500 vcanvas_->drawRectCoords(5, 5, 5, 5, paint); 501 vcanvas_->drawRectCoords(5, 5, 5, 5, paint);
501 pcanvas_->drawRectCoords(5, 5, 5, 5, paint); 502 pcanvas_->drawRectCoords(5, 5, 5, 5, paint);
502 } 503 }
503 EXPECT_EQ(0., ProcessImage(L"drawRect_noop")); 504 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("drawRect_noop")));
504 505
505 // Rect. 506 // Rect.
506 { 507 {
507 SkPaint paint; 508 SkPaint paint;
508 paint.setColor(SK_ColorBLUE); 509 paint.setColor(SK_ColorBLUE);
509 vcanvas_->drawRectCoords(75, 50, 80, 55, paint); 510 vcanvas_->drawRectCoords(75, 50, 80, 55, paint);
510 pcanvas_->drawRectCoords(75, 50, 80, 55, paint); 511 pcanvas_->drawRectCoords(75, 50, 80, 55, paint);
511 } 512 }
512 EXPECT_EQ(0., ProcessImage(L"drawRect_noop")); 513 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("drawRect_noop")));
513 514
514 // Empty again 515 // Empty again
515 { 516 {
516 vcanvas_->drawPaint(SkPaint()); 517 vcanvas_->drawPaint(SkPaint());
517 pcanvas_->drawPaint(SkPaint()); 518 pcanvas_->drawPaint(SkPaint());
518 } 519 }
519 EXPECT_EQ(0., ProcessImage(L"drawPaint_black")); 520 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("drawPaint_black")));
520 521
521 // Horizontal line left to right. 522 // Horizontal line left to right.
522 { 523 {
523 SkPaint paint; 524 SkPaint paint;
524 paint.setColor(SK_ColorRED); 525 paint.setColor(SK_ColorRED);
525 vcanvas_->drawLine(10, 20, 90, 20, paint); 526 vcanvas_->drawLine(10, 20, 90, 20, paint);
526 pcanvas_->drawLine(10, 20, 90, 20, paint); 527 pcanvas_->drawLine(10, 20, 90, 20, paint);
527 } 528 }
528 EXPECT_EQ(0., ProcessImage(L"drawLine_left_to_right")); 529 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("drawLine_left_to_right")));
529 530
530 // Vertical line downward. 531 // Vertical line downward.
531 { 532 {
532 SkPaint paint; 533 SkPaint paint;
533 paint.setColor(SK_ColorRED); 534 paint.setColor(SK_ColorRED);
534 vcanvas_->drawLine(30, 10, 30, 90, paint); 535 vcanvas_->drawLine(30, 10, 30, 90, paint);
535 pcanvas_->drawLine(30, 10, 30, 90, paint); 536 pcanvas_->drawLine(30, 10, 30, 90, paint);
536 } 537 }
537 EXPECT_EQ(0., ProcessImage(L"drawLine_red")); 538 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("drawLine_red")));
538 } 539 }
539 540
540 TEST_F(VectorCanvasTest, Circles) { 541 TEST_F(VectorCanvasTest, Circles) {
541 // There is NO WAY to make them agree. At least verify that the output doesn't 542 // There is NO WAY to make them agree. At least verify that the output doesn't
542 // change across versions. This test is disabled. See bug 1060231. 543 // change across versions. This test is disabled. See bug 1060231.
543 compare_canvas_ = false; 544 compare_canvas_ = false;
544 545
545 // Stroked Circle. 546 // Stroked Circle.
546 { 547 {
547 SkPaint paint; 548 SkPaint paint;
548 SkPath path; 549 SkPath path;
549 path.addCircle(50, 75, 10); 550 path.addCircle(50, 75, 10);
550 paint.setStyle(SkPaint::kStroke_Style); 551 paint.setStyle(SkPaint::kStroke_Style);
551 paint.setColor(SK_ColorMAGENTA); 552 paint.setColor(SK_ColorMAGENTA);
552 vcanvas_->drawPath(path, paint); 553 vcanvas_->drawPath(path, paint);
553 pcanvas_->drawPath(path, paint); 554 pcanvas_->drawPath(path, paint);
554 } 555 }
555 EXPECT_EQ(0., ProcessImage(L"circle_stroke")); 556 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("circle_stroke")));
556 557
557 // Filled Circle. 558 // Filled Circle.
558 { 559 {
559 SkPaint paint; 560 SkPaint paint;
560 SkPath path; 561 SkPath path;
561 path.addCircle(50, 25, 10); 562 path.addCircle(50, 25, 10);
562 paint.setStyle(SkPaint::kFill_Style); 563 paint.setStyle(SkPaint::kFill_Style);
563 vcanvas_->drawPath(path, paint); 564 vcanvas_->drawPath(path, paint);
564 pcanvas_->drawPath(path, paint); 565 pcanvas_->drawPath(path, paint);
565 } 566 }
566 EXPECT_EQ(0., ProcessImage(L"circle_fill")); 567 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("circle_fill")));
567 568
568 // Stroked Circle over. 569 // Stroked Circle over.
569 { 570 {
570 SkPaint paint; 571 SkPaint paint;
571 SkPath path; 572 SkPath path;
572 path.addCircle(50, 25, 10); 573 path.addCircle(50, 25, 10);
573 paint.setStyle(SkPaint::kStroke_Style); 574 paint.setStyle(SkPaint::kStroke_Style);
574 paint.setColor(SK_ColorBLUE); 575 paint.setColor(SK_ColorBLUE);
575 vcanvas_->drawPath(path, paint); 576 vcanvas_->drawPath(path, paint);
576 pcanvas_->drawPath(path, paint); 577 pcanvas_->drawPath(path, paint);
577 } 578 }
578 EXPECT_EQ(0., ProcessImage(L"circle_over_strike")); 579 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("circle_over_strike")));
579 580
580 // Stroke and Fill Circle. 581 // Stroke and Fill Circle.
581 { 582 {
582 SkPaint paint; 583 SkPaint paint;
583 SkPath path; 584 SkPath path;
584 path.addCircle(12, 50, 10); 585 path.addCircle(12, 50, 10);
585 paint.setStyle(SkPaint::kStrokeAndFill_Style); 586 paint.setStyle(SkPaint::kStrokeAndFill_Style);
586 paint.setColor(SK_ColorRED); 587 paint.setColor(SK_ColorRED);
587 vcanvas_->drawPath(path, paint); 588 vcanvas_->drawPath(path, paint);
588 pcanvas_->drawPath(path, paint); 589 pcanvas_->drawPath(path, paint);
589 } 590 }
590 EXPECT_EQ(0., ProcessImage(L"circle_stroke_and_fill")); 591 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("circle_stroke_and_fill")));
591 592
592 // Line + Quad + Cubic. 593 // Line + Quad + Cubic.
593 { 594 {
594 SkPaint paint; 595 SkPaint paint;
595 SkPath path; 596 SkPath path;
596 paint.setStyle(SkPaint::kStroke_Style); 597 paint.setStyle(SkPaint::kStroke_Style);
597 paint.setColor(SK_ColorGREEN); 598 paint.setColor(SK_ColorGREEN);
598 path.moveTo(1, 1); 599 path.moveTo(1, 1);
599 path.lineTo(60, 40); 600 path.lineTo(60, 40);
600 path.lineTo(80, 80); 601 path.lineTo(80, 80);
601 path.quadTo(20, 50, 10, 90); 602 path.quadTo(20, 50, 10, 90);
602 path.quadTo(50, 20, 90, 10); 603 path.quadTo(50, 20, 90, 10);
603 path.cubicTo(20, 40, 50, 50, 10, 10); 604 path.cubicTo(20, 40, 50, 50, 10, 10);
604 path.cubicTo(30, 20, 50, 50, 90, 10); 605 path.cubicTo(30, 20, 50, 50, 90, 10);
605 path.addRect(90, 90, 95, 96); 606 path.addRect(90, 90, 95, 96);
606 vcanvas_->drawPath(path, paint); 607 vcanvas_->drawPath(path, paint);
607 pcanvas_->drawPath(path, paint); 608 pcanvas_->drawPath(path, paint);
608 } 609 }
609 EXPECT_EQ(0., ProcessImage(L"mixed_stroke")); 610 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("mixed_stroke")));
610 } 611 }
611 612
612 TEST_F(VectorCanvasTest, LineOrientation) { 613 TEST_F(VectorCanvasTest, LineOrientation) {
613 // There is NO WAY to make them agree. At least verify that the output doesn't 614 // There is NO WAY to make them agree. At least verify that the output doesn't
614 // change across versions. This test is disabled. See bug 1060231. 615 // change across versions. This test is disabled. See bug 1060231.
615 compare_canvas_ = false; 616 compare_canvas_ = false;
616 617
617 // Horizontal lines. 618 // Horizontal lines.
618 { 619 {
619 SkPaint paint; 620 SkPaint paint;
620 paint.setColor(SK_ColorRED); 621 paint.setColor(SK_ColorRED);
621 // Left to right. 622 // Left to right.
622 vcanvas_->drawLine(10, 20, 90, 20, paint); 623 vcanvas_->drawLine(10, 20, 90, 20, paint);
623 pcanvas_->drawLine(10, 20, 90, 20, paint); 624 pcanvas_->drawLine(10, 20, 90, 20, paint);
624 // Right to left. 625 // Right to left.
625 vcanvas_->drawLine(90, 30, 10, 30, paint); 626 vcanvas_->drawLine(90, 30, 10, 30, paint);
626 pcanvas_->drawLine(90, 30, 10, 30, paint); 627 pcanvas_->drawLine(90, 30, 10, 30, paint);
627 } 628 }
628 EXPECT_EQ(0., ProcessImage(L"horizontal")); 629 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("horizontal")));
629 630
630 // Vertical lines. 631 // Vertical lines.
631 { 632 {
632 SkPaint paint; 633 SkPaint paint;
633 paint.setColor(SK_ColorRED); 634 paint.setColor(SK_ColorRED);
634 // Top down. 635 // Top down.
635 vcanvas_->drawLine(20, 10, 20, 90, paint); 636 vcanvas_->drawLine(20, 10, 20, 90, paint);
636 pcanvas_->drawLine(20, 10, 20, 90, paint); 637 pcanvas_->drawLine(20, 10, 20, 90, paint);
637 // Bottom up. 638 // Bottom up.
638 vcanvas_->drawLine(30, 90, 30, 10, paint); 639 vcanvas_->drawLine(30, 90, 30, 10, paint);
639 pcanvas_->drawLine(30, 90, 30, 10, paint); 640 pcanvas_->drawLine(30, 90, 30, 10, paint);
640 } 641 }
641 EXPECT_EQ(0., ProcessImage(L"vertical")); 642 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("vertical")));
642 643
643 // Try again with a 180 degres rotation. 644 // Try again with a 180 degres rotation.
644 vcanvas_->rotate(180); 645 vcanvas_->rotate(180);
645 pcanvas_->rotate(180); 646 pcanvas_->rotate(180);
646 647
647 // Horizontal lines (rotated). 648 // Horizontal lines (rotated).
648 { 649 {
649 SkPaint paint; 650 SkPaint paint;
650 paint.setColor(SK_ColorRED); 651 paint.setColor(SK_ColorRED);
651 vcanvas_->drawLine(-10, -25, -90, -25, paint); 652 vcanvas_->drawLine(-10, -25, -90, -25, paint);
652 pcanvas_->drawLine(-10, -25, -90, -25, paint); 653 pcanvas_->drawLine(-10, -25, -90, -25, paint);
653 vcanvas_->drawLine(-90, -35, -10, -35, paint); 654 vcanvas_->drawLine(-90, -35, -10, -35, paint);
654 pcanvas_->drawLine(-90, -35, -10, -35, paint); 655 pcanvas_->drawLine(-90, -35, -10, -35, paint);
655 } 656 }
656 EXPECT_EQ(0., ProcessImage(L"horizontal_180")); 657 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("horizontal_180")));
657 658
658 // Vertical lines (rotated). 659 // Vertical lines (rotated).
659 { 660 {
660 SkPaint paint; 661 SkPaint paint;
661 paint.setColor(SK_ColorRED); 662 paint.setColor(SK_ColorRED);
662 vcanvas_->drawLine(-25, -10, -25, -90, paint); 663 vcanvas_->drawLine(-25, -10, -25, -90, paint);
663 pcanvas_->drawLine(-25, -10, -25, -90, paint); 664 pcanvas_->drawLine(-25, -10, -25, -90, paint);
664 vcanvas_->drawLine(-35, -90, -35, -10, paint); 665 vcanvas_->drawLine(-35, -90, -35, -10, paint);
665 pcanvas_->drawLine(-35, -90, -35, -10, paint); 666 pcanvas_->drawLine(-35, -90, -35, -10, paint);
666 } 667 }
667 EXPECT_EQ(0., ProcessImage(L"vertical_180")); 668 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("vertical_180")));
668 } 669 }
669 670
670 TEST_F(VectorCanvasTest, PathOrientation) { 671 TEST_F(VectorCanvasTest, PathOrientation) {
671 // There is NO WAY to make them agree. At least verify that the output doesn't 672 // There is NO WAY to make them agree. At least verify that the output doesn't
672 // change across versions. This test is disabled. See bug 1060231. 673 // change across versions. This test is disabled. See bug 1060231.
673 compare_canvas_ = false; 674 compare_canvas_ = false;
674 675
675 // Horizontal lines. 676 // Horizontal lines.
676 { 677 {
677 SkPaint paint; 678 SkPaint paint;
678 paint.setStyle(SkPaint::kStroke_Style); 679 paint.setStyle(SkPaint::kStroke_Style);
679 paint.setColor(SK_ColorRED); 680 paint.setColor(SK_ColorRED);
680 SkPath path; 681 SkPath path;
681 SkPoint start; 682 SkPoint start;
682 start.set(10, 20); 683 start.set(10, 20);
683 SkPoint end; 684 SkPoint end;
684 end.set(90, 20); 685 end.set(90, 20);
685 path.moveTo(start); 686 path.moveTo(start);
686 path.lineTo(end); 687 path.lineTo(end);
687 vcanvas_->drawPath(path, paint); 688 vcanvas_->drawPath(path, paint);
688 pcanvas_->drawPath(path, paint); 689 pcanvas_->drawPath(path, paint);
689 } 690 }
690 EXPECT_EQ(0., ProcessImage(L"drawPath_ltr")); 691 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("drawPath_ltr")));
691 692
692 // Horizontal lines. 693 // Horizontal lines.
693 { 694 {
694 SkPaint paint; 695 SkPaint paint;
695 paint.setStyle(SkPaint::kStroke_Style); 696 paint.setStyle(SkPaint::kStroke_Style);
696 paint.setColor(SK_ColorRED); 697 paint.setColor(SK_ColorRED);
697 SkPath path; 698 SkPath path;
698 SkPoint start; 699 SkPoint start;
699 start.set(90, 30); 700 start.set(90, 30);
700 SkPoint end; 701 SkPoint end;
701 end.set(10, 30); 702 end.set(10, 30);
702 path.moveTo(start); 703 path.moveTo(start);
703 path.lineTo(end); 704 path.lineTo(end);
704 vcanvas_->drawPath(path, paint); 705 vcanvas_->drawPath(path, paint);
705 pcanvas_->drawPath(path, paint); 706 pcanvas_->drawPath(path, paint);
706 } 707 }
707 EXPECT_EQ(0., ProcessImage(L"drawPath_rtl")); 708 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("drawPath_rtl")));
708 } 709 }
709 710
710 TEST_F(VectorCanvasTest, DiagonalLines) { 711 TEST_F(VectorCanvasTest, DiagonalLines) {
711 SkPaint paint; 712 SkPaint paint;
712 paint.setColor(SK_ColorRED); 713 paint.setColor(SK_ColorRED);
713 714
714 vcanvas_->drawLine(10, 10, 90, 90, paint); 715 vcanvas_->drawLine(10, 10, 90, 90, paint);
715 pcanvas_->drawLine(10, 10, 90, 90, paint); 716 pcanvas_->drawLine(10, 10, 90, 90, paint);
716 EXPECT_EQ(0., ProcessImage(L"nw-se")); 717 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("nw-se")));
717 718
718 // Starting here, there is NO WAY to make them agree. At least verify that the 719 // Starting here, there is NO WAY to make them agree. At least verify that the
719 // output doesn't change across versions. This test is disabled. See bug 720 // output doesn't change across versions. This test is disabled. See bug
720 // 1060231. 721 // 1060231.
721 compare_canvas_ = false; 722 compare_canvas_ = false;
722 723
723 vcanvas_->drawLine(10, 95, 90, 15, paint); 724 vcanvas_->drawLine(10, 95, 90, 15, paint);
724 pcanvas_->drawLine(10, 95, 90, 15, paint); 725 pcanvas_->drawLine(10, 95, 90, 15, paint);
725 EXPECT_EQ(0., ProcessImage(L"sw-ne")); 726 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("sw-ne")));
726 727
727 vcanvas_->drawLine(90, 10, 10, 90, paint); 728 vcanvas_->drawLine(90, 10, 10, 90, paint);
728 pcanvas_->drawLine(90, 10, 10, 90, paint); 729 pcanvas_->drawLine(90, 10, 10, 90, paint);
729 EXPECT_EQ(0., ProcessImage(L"ne-sw")); 730 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("ne-sw")));
730 731
731 vcanvas_->drawLine(95, 90, 15, 10, paint); 732 vcanvas_->drawLine(95, 90, 15, 10, paint);
732 pcanvas_->drawLine(95, 90, 15, 10, paint); 733 pcanvas_->drawLine(95, 90, 15, 10, paint);
733 EXPECT_EQ(0., ProcessImage(L"se-nw")); 734 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("se-nw")));
734 } 735 }
735 736
736 TEST_F(VectorCanvasTest, PathEffects) { 737 TEST_F(VectorCanvasTest, PathEffects) {
737 { 738 {
738 SkPaint paint; 739 SkPaint paint;
739 SkScalar intervals[] = { 1, 1 }; 740 SkScalar intervals[] = { 1, 1 };
740 SkPathEffect* effect = new SkDashPathEffect(intervals, arraysize(intervals), 741 SkPathEffect* effect = new SkDashPathEffect(intervals, arraysize(intervals),
741 0); 742 0);
742 paint.setPathEffect(effect)->unref(); 743 paint.setPathEffect(effect)->unref();
743 paint.setColor(SK_ColorMAGENTA); 744 paint.setColor(SK_ColorMAGENTA);
744 paint.setStyle(SkPaint::kStroke_Style); 745 paint.setStyle(SkPaint::kStroke_Style);
745 746
746 vcanvas_->drawLine(10, 10, 90, 10, paint); 747 vcanvas_->drawLine(10, 10, 90, 10, paint);
747 pcanvas_->drawLine(10, 10, 90, 10, paint); 748 pcanvas_->drawLine(10, 10, 90, 10, paint);
748 } 749 }
749 EXPECT_EQ(0., ProcessImage(L"dash_line")); 750 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("dash_line")));
750 751
751 752
752 // Starting here, there is NO WAY to make them agree. At least verify that the 753 // Starting here, there is NO WAY to make them agree. At least verify that the
753 // output doesn't change across versions. This test is disabled. See bug 754 // output doesn't change across versions. This test is disabled. See bug
754 // 1060231. 755 // 1060231.
755 compare_canvas_ = false; 756 compare_canvas_ = false;
756 757
757 { 758 {
758 SkPaint paint; 759 SkPaint paint;
759 SkScalar intervals[] = { 3, 5 }; 760 SkScalar intervals[] = { 3, 5 };
760 SkPathEffect* effect = new SkDashPathEffect(intervals, arraysize(intervals), 761 SkPathEffect* effect = new SkDashPathEffect(intervals, arraysize(intervals),
761 0); 762 0);
762 paint.setPathEffect(effect)->unref(); 763 paint.setPathEffect(effect)->unref();
763 paint.setColor(SK_ColorMAGENTA); 764 paint.setColor(SK_ColorMAGENTA);
764 paint.setStyle(SkPaint::kStroke_Style); 765 paint.setStyle(SkPaint::kStroke_Style);
765 766
766 SkPath path; 767 SkPath path;
767 path.moveTo(10, 15); 768 path.moveTo(10, 15);
768 path.lineTo(90, 15); 769 path.lineTo(90, 15);
769 path.lineTo(90, 90); 770 path.lineTo(90, 90);
770 vcanvas_->drawPath(path, paint); 771 vcanvas_->drawPath(path, paint);
771 pcanvas_->drawPath(path, paint); 772 pcanvas_->drawPath(path, paint);
772 } 773 }
773 EXPECT_EQ(0., ProcessImage(L"dash_path")); 774 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("dash_path")));
774 775
775 { 776 {
776 SkPaint paint; 777 SkPaint paint;
777 SkScalar intervals[] = { 2, 1 }; 778 SkScalar intervals[] = { 2, 1 };
778 SkPathEffect* effect = new SkDashPathEffect(intervals, arraysize(intervals), 779 SkPathEffect* effect = new SkDashPathEffect(intervals, arraysize(intervals),
779 0); 780 0);
780 paint.setPathEffect(effect)->unref(); 781 paint.setPathEffect(effect)->unref();
781 paint.setColor(SK_ColorMAGENTA); 782 paint.setColor(SK_ColorMAGENTA);
782 paint.setStyle(SkPaint::kStroke_Style); 783 paint.setStyle(SkPaint::kStroke_Style);
783 784
784 vcanvas_->drawRectCoords(20, 20, 30, 30, paint); 785 vcanvas_->drawRectCoords(20, 20, 30, 30, paint);
785 pcanvas_->drawRectCoords(20, 20, 30, 30, paint); 786 pcanvas_->drawRectCoords(20, 20, 30, 30, paint);
786 } 787 }
787 EXPECT_EQ(0., ProcessImage(L"dash_rect")); 788 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("dash_rect")));
788 789
789 // This thing looks like it has been drawn by a 3 years old kid. I haven't 790 // This thing looks like it has been drawn by a 3 years old kid. I haven't
790 // filed a bug on this since I guess nobody is expecting this to look nice. 791 // filed a bug on this since I guess nobody is expecting this to look nice.
791 { 792 {
792 SkPaint paint; 793 SkPaint paint;
793 SkScalar intervals[] = { 1, 1 }; 794 SkScalar intervals[] = { 1, 1 };
794 SkPathEffect* effect = new SkDashPathEffect(intervals, arraysize(intervals), 795 SkPathEffect* effect = new SkDashPathEffect(intervals, arraysize(intervals),
795 0); 796 0);
796 paint.setPathEffect(effect)->unref(); 797 paint.setPathEffect(effect)->unref();
797 paint.setColor(SK_ColorMAGENTA); 798 paint.setColor(SK_ColorMAGENTA);
798 paint.setStyle(SkPaint::kStroke_Style); 799 paint.setStyle(SkPaint::kStroke_Style);
799 800
800 SkPath path; 801 SkPath path;
801 path.addCircle(50, 75, 10); 802 path.addCircle(50, 75, 10);
802 vcanvas_->drawPath(path, paint); 803 vcanvas_->drawPath(path, paint);
803 pcanvas_->drawPath(path, paint); 804 pcanvas_->drawPath(path, paint);
804 EXPECT_EQ(0., ProcessImage(L"circle")); 805 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("circle")));
805 } 806 }
806 } 807 }
807 808
808 TEST_F(VectorCanvasTest, Bitmaps) { 809 TEST_F(VectorCanvasTest, Bitmaps) {
809 { 810 {
810 SkBitmap bitmap; 811 SkBitmap bitmap;
811 LoadPngFileToSkBitmap(test_file(L"bitmap_opaque.png"), &bitmap, true); 812 LoadPngFileToSkBitmap(test_file(L"bitmap_opaque.png"), &bitmap, true);
812 vcanvas_->drawBitmap(bitmap, 13, 3, NULL); 813 vcanvas_->drawBitmap(bitmap, 13, 3, NULL);
813 pcanvas_->drawBitmap(bitmap, 13, 3, NULL); 814 pcanvas_->drawBitmap(bitmap, 13, 3, NULL);
814 EXPECT_EQ(0., ProcessImage(L"opaque")); 815 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("opaque")));
815 } 816 }
816 817
817 { 818 {
818 SkBitmap bitmap; 819 SkBitmap bitmap;
819 LoadPngFileToSkBitmap(test_file(L"bitmap_alpha.png"), &bitmap, false); 820 LoadPngFileToSkBitmap(test_file(L"bitmap_alpha.png"), &bitmap, false);
820 vcanvas_->drawBitmap(bitmap, 5, 15, NULL); 821 vcanvas_->drawBitmap(bitmap, 5, 15, NULL);
821 pcanvas_->drawBitmap(bitmap, 5, 15, NULL); 822 pcanvas_->drawBitmap(bitmap, 5, 15, NULL);
822 EXPECT_EQ(0., ProcessImage(L"alpha")); 823 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("alpha")));
823 } 824 }
824 } 825 }
825 826
826 TEST_F(VectorCanvasTest, ClippingRect) { 827 TEST_F(VectorCanvasTest, ClippingRect) {
827 SkBitmap bitmap; 828 SkBitmap bitmap;
828 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap, 829 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap,
829 true); 830 true);
830 SkRect rect; 831 SkRect rect;
831 rect.fLeft = 2; 832 rect.fLeft = 2;
832 rect.fTop = 2; 833 rect.fTop = 2;
833 rect.fRight = 30.5f; 834 rect.fRight = 30.5f;
834 rect.fBottom = 30.5f; 835 rect.fBottom = 30.5f;
835 vcanvas_->clipRect(rect); 836 vcanvas_->clipRect(rect);
836 pcanvas_->clipRect(rect); 837 pcanvas_->clipRect(rect);
837 838
838 vcanvas_->drawBitmap(bitmap, 13, 3, NULL); 839 vcanvas_->drawBitmap(bitmap, 13, 3, NULL);
839 pcanvas_->drawBitmap(bitmap, 13, 3, NULL); 840 pcanvas_->drawBitmap(bitmap, 13, 3, NULL);
840 EXPECT_EQ(0., ProcessImage(L"rect")); 841 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("rect")));
841 } 842 }
842 843
843 TEST_F(VectorCanvasTest, ClippingPath) { 844 TEST_F(VectorCanvasTest, ClippingPath) {
844 SkBitmap bitmap; 845 SkBitmap bitmap;
845 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap, 846 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap,
846 true); 847 true);
847 SkPath path; 848 SkPath path;
848 path.addCircle(20, 20, 10); 849 path.addCircle(20, 20, 10);
849 vcanvas_->clipPath(path); 850 vcanvas_->clipPath(path);
850 pcanvas_->clipPath(path); 851 pcanvas_->clipPath(path);
851 852
852 vcanvas_->drawBitmap(bitmap, 14, 3, NULL); 853 vcanvas_->drawBitmap(bitmap, 14, 3, NULL);
853 pcanvas_->drawBitmap(bitmap, 14, 3, NULL); 854 pcanvas_->drawBitmap(bitmap, 14, 3, NULL);
854 EXPECT_EQ(0., ProcessImage(L"path")); 855 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("path")));
855 } 856 }
856 857
857 TEST_F(VectorCanvasTest, ClippingCombined) { 858 TEST_F(VectorCanvasTest, ClippingCombined) {
858 SkBitmap bitmap; 859 SkBitmap bitmap;
859 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap, 860 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap,
860 true); 861 true);
861 862
862 SkRect rect; 863 SkRect rect;
863 rect.fLeft = 2; 864 rect.fLeft = 2;
864 rect.fTop = 2; 865 rect.fTop = 2;
865 rect.fRight = 30.5f; 866 rect.fRight = 30.5f;
866 rect.fBottom = 30.5f; 867 rect.fBottom = 30.5f;
867 vcanvas_->clipRect(rect); 868 vcanvas_->clipRect(rect);
868 pcanvas_->clipRect(rect); 869 pcanvas_->clipRect(rect);
869 SkPath path; 870 SkPath path;
870 path.addCircle(20, 20, 10); 871 path.addCircle(20, 20, 10);
871 vcanvas_->clipPath(path, SkRegion::kUnion_Op); 872 vcanvas_->clipPath(path, SkRegion::kUnion_Op);
872 pcanvas_->clipPath(path, SkRegion::kUnion_Op); 873 pcanvas_->clipPath(path, SkRegion::kUnion_Op);
873 874
874 vcanvas_->drawBitmap(bitmap, 15, 3, NULL); 875 vcanvas_->drawBitmap(bitmap, 15, 3, NULL);
875 pcanvas_->drawBitmap(bitmap, 15, 3, NULL); 876 pcanvas_->drawBitmap(bitmap, 15, 3, NULL);
876 EXPECT_EQ(0., ProcessImage(L"combined")); 877 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("combined")));
877 } 878 }
878 879
879 TEST_F(VectorCanvasTest, ClippingIntersect) { 880 TEST_F(VectorCanvasTest, ClippingIntersect) {
880 SkBitmap bitmap; 881 SkBitmap bitmap;
881 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap, 882 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap,
882 true); 883 true);
883 884
884 SkRect rect; 885 SkRect rect;
885 rect.fLeft = 2; 886 rect.fLeft = 2;
886 rect.fTop = 2; 887 rect.fTop = 2;
887 rect.fRight = 30.5f; 888 rect.fRight = 30.5f;
888 rect.fBottom = 30.5f; 889 rect.fBottom = 30.5f;
889 vcanvas_->clipRect(rect); 890 vcanvas_->clipRect(rect);
890 pcanvas_->clipRect(rect); 891 pcanvas_->clipRect(rect);
891 SkPath path; 892 SkPath path;
892 path.addCircle(23, 23, 15); 893 path.addCircle(23, 23, 15);
893 vcanvas_->clipPath(path); 894 vcanvas_->clipPath(path);
894 pcanvas_->clipPath(path); 895 pcanvas_->clipPath(path);
895 896
896 vcanvas_->drawBitmap(bitmap, 15, 3, NULL); 897 vcanvas_->drawBitmap(bitmap, 15, 3, NULL);
897 pcanvas_->drawBitmap(bitmap, 15, 3, NULL); 898 pcanvas_->drawBitmap(bitmap, 15, 3, NULL);
898 EXPECT_EQ(0., ProcessImage(L"intersect")); 899 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("intersect")));
899 } 900 }
900 901
901 TEST_F(VectorCanvasTest, ClippingClean) { 902 TEST_F(VectorCanvasTest, ClippingClean) {
902 SkBitmap bitmap; 903 SkBitmap bitmap;
903 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap, 904 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap,
904 true); 905 true);
905 { 906 {
906 SkRegion old_region(pcanvas_->getTotalClip()); 907 SkRegion old_region(pcanvas_->getTotalClip());
907 SkRect rect; 908 SkRect rect;
908 rect.fLeft = 2; 909 rect.fLeft = 2;
909 rect.fTop = 2; 910 rect.fTop = 2;
910 rect.fRight = 30.5f; 911 rect.fRight = 30.5f;
911 rect.fBottom = 30.5f; 912 rect.fBottom = 30.5f;
912 vcanvas_->clipRect(rect); 913 vcanvas_->clipRect(rect);
913 pcanvas_->clipRect(rect); 914 pcanvas_->clipRect(rect);
914 915
915 vcanvas_->drawBitmap(bitmap, 15, 3, NULL); 916 vcanvas_->drawBitmap(bitmap, 15, 3, NULL);
916 pcanvas_->drawBitmap(bitmap, 15, 3, NULL); 917 pcanvas_->drawBitmap(bitmap, 15, 3, NULL);
917 EXPECT_EQ(0., ProcessImage(L"clipped")); 918 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("clipped")));
918 vcanvas_->clipRegion(old_region, SkRegion::kReplace_Op); 919 vcanvas_->clipRegion(old_region, SkRegion::kReplace_Op);
919 pcanvas_->clipRegion(old_region, SkRegion::kReplace_Op); 920 pcanvas_->clipRegion(old_region, SkRegion::kReplace_Op);
920 } 921 }
921 { 922 {
922 // Verify that the clipping region has been fixed back. 923 // Verify that the clipping region has been fixed back.
923 vcanvas_->drawBitmap(bitmap, 55, 3, NULL); 924 vcanvas_->drawBitmap(bitmap, 55, 3, NULL);
924 pcanvas_->drawBitmap(bitmap, 55, 3, NULL); 925 pcanvas_->drawBitmap(bitmap, 55, 3, NULL);
925 EXPECT_EQ(0., ProcessImage(L"unclipped")); 926 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("unclipped")));
926 } 927 }
927 } 928 }
928 929
929 TEST_F(VectorCanvasTest, DISABLED_Matrix) { 930 TEST_F(VectorCanvasTest, DISABLED_Matrix) {
930 SkBitmap bitmap; 931 SkBitmap bitmap;
931 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap, 932 LoadPngFileToSkBitmap(test_file(L"..\\bitmaps\\bitmap_opaque.png"), &bitmap,
932 true); 933 true);
933 { 934 {
934 vcanvas_->translate(15, 3); 935 vcanvas_->translate(15, 3);
935 pcanvas_->translate(15, 3); 936 pcanvas_->translate(15, 3);
936 vcanvas_->drawBitmap(bitmap, 0, 0, NULL); 937 vcanvas_->drawBitmap(bitmap, 0, 0, NULL);
937 pcanvas_->drawBitmap(bitmap, 0, 0, NULL); 938 pcanvas_->drawBitmap(bitmap, 0, 0, NULL);
938 EXPECT_EQ(0., ProcessImage(L"translate1")); 939 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("translate1")));
939 } 940 }
940 { 941 {
941 vcanvas_->translate(-30, -23); 942 vcanvas_->translate(-30, -23);
942 pcanvas_->translate(-30, -23); 943 pcanvas_->translate(-30, -23);
943 vcanvas_->drawBitmap(bitmap, 0, 0, NULL); 944 vcanvas_->drawBitmap(bitmap, 0, 0, NULL);
944 pcanvas_->drawBitmap(bitmap, 0, 0, NULL); 945 pcanvas_->drawBitmap(bitmap, 0, 0, NULL);
945 EXPECT_EQ(0., ProcessImage(L"translate2")); 946 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("translate2")));
946 } 947 }
947 vcanvas_->resetMatrix(); 948 vcanvas_->resetMatrix();
948 pcanvas_->resetMatrix(); 949 pcanvas_->resetMatrix();
949 950
950 // For scaling and rotation, they use a different algorithm (nearest 951 // For scaling and rotation, they use a different algorithm (nearest
951 // neighborhood vs smoothing). At least verify that the output doesn't change 952 // neighborhood vs smoothing). At least verify that the output doesn't change
952 // across versions. 953 // across versions.
953 compare_canvas_ = false; 954 compare_canvas_ = false;
954 955
955 { 956 {
956 vcanvas_->scale(SkDoubleToScalar(1.9), SkDoubleToScalar(1.5)); 957 vcanvas_->scale(SkDoubleToScalar(1.9), SkDoubleToScalar(1.5));
957 pcanvas_->scale(SkDoubleToScalar(1.9), SkDoubleToScalar(1.5)); 958 pcanvas_->scale(SkDoubleToScalar(1.9), SkDoubleToScalar(1.5));
958 vcanvas_->drawBitmap(bitmap, 1, 1, NULL); 959 vcanvas_->drawBitmap(bitmap, 1, 1, NULL);
959 pcanvas_->drawBitmap(bitmap, 1, 1, NULL); 960 pcanvas_->drawBitmap(bitmap, 1, 1, NULL);
960 EXPECT_EQ(0., ProcessImage(L"scale")); 961 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("scale")));
961 } 962 }
962 vcanvas_->resetMatrix(); 963 vcanvas_->resetMatrix();
963 pcanvas_->resetMatrix(); 964 pcanvas_->resetMatrix();
964 965
965 { 966 {
966 vcanvas_->rotate(67); 967 vcanvas_->rotate(67);
967 pcanvas_->rotate(67); 968 pcanvas_->rotate(67);
968 vcanvas_->drawBitmap(bitmap, 20, -50, NULL); 969 vcanvas_->drawBitmap(bitmap, 20, -50, NULL);
969 pcanvas_->drawBitmap(bitmap, 20, -50, NULL); 970 pcanvas_->drawBitmap(bitmap, 20, -50, NULL);
970 EXPECT_EQ(0., ProcessImage(L"rotate")); 971 EXPECT_EQ(0., ProcessImage(FILE_PATH_LITERAL("rotate")));
971 } 972 }
972 } 973 }
973 974
974 } // namespace skia 975 } // namespace skia
OLDNEW
« no previous file with comments | « net/tools/crash_cache/crash_cache.cc ('k') | tools/memory_watcher/memory_watcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698