| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
| 6 #include "skia/ext/analysis_canvas.h" | 6 #include "skia/ext/analysis_canvas.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "third_party/skia/include/core/SkShader.h" | 8 #include "third_party/skia/include/core/SkShader.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| 11 | 11 |
| 12 void SolidColorFill(skia::AnalysisCanvas& canvas) { | 12 void SolidColorFill(skia::AnalysisCanvas& canvas) { |
| 13 canvas.clear(SkColorSetARGB(255, 255, 255, 255)); | 13 canvas.clear(SkColorSetARGB(255, 255, 255, 255)); |
| 14 } | 14 } |
| 15 | 15 |
| 16 void TransparentFill(skia::AnalysisCanvas& canvas) { | 16 void TransparentFill(skia::AnalysisCanvas& canvas) { |
| 17 canvas.clear(SkColorSetARGB(0, 0, 0, 0)); | 17 canvas.clear(SkColorSetARGB(0, 0, 0, 0)); |
| 18 } | 18 } |
| 19 | 19 |
| 20 } // namespace | 20 } // namespace |
| 21 |
| 21 namespace skia { | 22 namespace skia { |
| 22 | 23 |
| 23 TEST(AnalysisCanvasTest, EmptyCanvas) { | 24 TEST(AnalysisCanvasTest, EmptyCanvas) { |
| 24 SkBitmap emptyBitmap; | 25 SkBitmap emptyBitmap; |
| 25 emptyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255); | 26 emptyBitmap.setConfig(SkBitmap::kNo_Config, 255, 255); |
| 26 skia::AnalysisDevice device(emptyBitmap); | 27 skia::AnalysisDevice device(emptyBitmap); |
| 27 skia::AnalysisCanvas canvas(&device); | 28 skia::AnalysisCanvas canvas(&device); |
| 28 | 29 |
| 29 SkColor color; | 30 SkColor color; |
| 30 EXPECT_TRUE(canvas.GetColorIfSolid(&color)); | 31 EXPECT_TRUE(canvas.GetColorIfSolid(&color)); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 EXPECT_TRUE(canvas.HasText()); | 336 EXPECT_TRUE(canvas.HasText()); |
| 336 } | 337 } |
| 337 { | 338 { |
| 338 // Test SkCanvas::drawTextOnPath. | 339 // Test SkCanvas::drawTextOnPath. |
| 339 skia::AnalysisDevice device(bitmap); | 340 skia::AnalysisDevice device(bitmap); |
| 340 skia::AnalysisCanvas canvas(&device); | 341 skia::AnalysisCanvas canvas(&device); |
| 341 canvas.drawTextOnPath(text, byteLength, path, NULL, paint); | 342 canvas.drawTextOnPath(text, byteLength, path, NULL, paint); |
| 342 EXPECT_TRUE(canvas.HasText()); | 343 EXPECT_TRUE(canvas.HasText()); |
| 343 } | 344 } |
| 344 { | 345 { |
| 345 // Text under opaque rect. | |
| 346 skia::AnalysisDevice device(bitmap); | |
| 347 skia::AnalysisCanvas canvas(&device); | |
| 348 canvas.drawText(text, byteLength, point.fX, point.fY, paint); | |
| 349 EXPECT_TRUE(canvas.HasText()); | |
| 350 canvas.drawRect(SkRect::MakeWH(width, height), paint); | |
| 351 EXPECT_FALSE(canvas.HasText()); | |
| 352 } | |
| 353 { | |
| 354 // Text under translucent rect. | 346 // Text under translucent rect. |
| 355 skia::AnalysisDevice device(bitmap); | 347 skia::AnalysisDevice device(bitmap); |
| 356 skia::AnalysisCanvas canvas(&device); | 348 skia::AnalysisCanvas canvas(&device); |
| 357 canvas.drawText(text, byteLength, point.fX, point.fY, paint); | 349 canvas.drawText(text, byteLength, point.fX, point.fY, paint); |
| 358 EXPECT_TRUE(canvas.HasText()); | 350 EXPECT_TRUE(canvas.HasText()); |
| 359 SkPaint translucentPaint; | 351 SkPaint translucentPaint; |
| 360 translucentPaint.setColor(0x88FFFFFF); | 352 translucentPaint.setColor(0x88FFFFFF); |
| 361 canvas.drawRect(SkRect::MakeWH(width, height), translucentPaint); | 353 canvas.drawRect(SkRect::MakeWH(width, height), translucentPaint); |
| 362 EXPECT_TRUE(canvas.HasText()); | 354 EXPECT_TRUE(canvas.HasText()); |
| 363 } | 355 } |
| 364 { | 356 { |
| 365 // Text under rect in clear mode. | |
| 366 skia::AnalysisDevice device(bitmap); | |
| 367 skia::AnalysisCanvas canvas(&device); | |
| 368 canvas.drawText(text, byteLength, point.fX, point.fY, paint); | |
| 369 EXPECT_TRUE(canvas.HasText()); | |
| 370 SkPaint clearModePaint; | |
| 371 clearModePaint.setXfermodeMode(SkXfermode::kClear_Mode); | |
| 372 canvas.drawRect(SkRect::MakeWH(width, height), clearModePaint); | |
| 373 EXPECT_FALSE(canvas.HasText()); | |
| 374 } | |
| 375 { | |
| 376 // Clear. | 357 // Clear. |
| 377 skia::AnalysisDevice device(bitmap); | 358 skia::AnalysisDevice device(bitmap); |
| 378 skia::AnalysisCanvas canvas(&device); | 359 skia::AnalysisCanvas canvas(&device); |
| 379 canvas.drawText(text, byteLength, point.fX, point.fY, paint); | 360 canvas.drawText(text, byteLength, point.fX, point.fY, paint); |
| 380 EXPECT_TRUE(canvas.HasText()); | 361 EXPECT_TRUE(canvas.HasText()); |
| 381 canvas.clear(SK_ColorGRAY); | 362 canvas.clear(SK_ColorGRAY); |
| 382 EXPECT_FALSE(canvas.HasText()); | 363 EXPECT_FALSE(canvas.HasText()); |
| 383 } | 364 } |
| 384 { | 365 { |
| 385 // Text inside clip region. | 366 // Text inside clip region. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 397 canvas.drawText(text, byteLength, point.fX, point.fY, paint); | 378 canvas.drawText(text, byteLength, point.fX, point.fY, paint); |
| 398 // Analysis device does not do any clipping. | 379 // Analysis device does not do any clipping. |
| 399 // So even when text is outside the clip region, | 380 // So even when text is outside the clip region, |
| 400 // it is marked as having the text. | 381 // it is marked as having the text. |
| 401 // TODO(alokp): We may be able to do some trivial rejection. | 382 // TODO(alokp): We may be able to do some trivial rejection. |
| 402 EXPECT_TRUE(canvas.HasText()); | 383 EXPECT_TRUE(canvas.HasText()); |
| 403 } | 384 } |
| 404 } | 385 } |
| 405 | 386 |
| 406 } // namespace skia | 387 } // namespace skia |
| OLD | NEW |