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

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

Issue 13726013: Smart layer invalidation for LCD text. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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
« skia/ext/analysis_canvas.cc ('K') | « skia/ext/analysis_canvas.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 std::list<skia::LazyPixelRef*> pixelRefs; 447 std::list<skia::LazyPixelRef*> pixelRefs;
448 canvas.consumeLazyPixelRefs(&pixelRefs); 448 canvas.consumeLazyPixelRefs(&pixelRefs);
449 449
450 // We expect to get only lazy pixel refs and only unique results. 450 // We expect to get only lazy pixel refs and only unique results.
451 EXPECT_EQ(pixelRefs.size(), 1u); 451 EXPECT_EQ(pixelRefs.size(), 1u);
452 if (!pixelRefs.empty()) { 452 if (!pixelRefs.empty()) {
453 EXPECT_EQ(pixelRefs.front(), static_cast<LazyPixelRef*>(&lazyPixelRef)); 453 EXPECT_EQ(pixelRefs.front(), static_cast<LazyPixelRef*>(&lazyPixelRef));
454 } 454 }
455 } 455 }
456 456
457 TEST(AnalysisCanvasTest, HasText) {
458 SkBitmap bitmap;
459 bitmap.setConfig(SkBitmap::kNo_Config, 200, 100);
460
461 const char* text = "A";
462 size_t byteLength = 1;
463 SkPoint point = SkPoint::Make(SkIntToScalar(25), SkIntToScalar(25));
464 SkPath path;
465 path.moveTo(point);
466 path.lineTo(SkIntToScalar(75), SkIntToScalar(75));
467 SkPaint paint;
468 paint.setTextSize(SkIntToScalar(10));
469
470 {
471 skia::AnalysisDevice device(bitmap);
472 skia::AnalysisCanvas canvas(&device);
473 // Test after initialization.
474 EXPECT_FALSE(canvas.hasText());
475 // Test drawing anything other than text.
476 canvas.drawRect(SkRect::MakeWH(100, 100), paint);
477 EXPECT_FALSE(canvas.hasText());
478 }
479 {
480 // Test SkCanvas::drawText.
481 skia::AnalysisDevice device(bitmap);
482 skia::AnalysisCanvas canvas(&device);
483 canvas.drawText(text, byteLength, point.fX, point.fY, paint);
484 EXPECT_TRUE(canvas.hasText());
485 }
486 {
487 // Test SkCanvas::drawPosText.
488 skia::AnalysisDevice device(bitmap);
489 skia::AnalysisCanvas canvas(&device);
490 canvas.drawPosText(text, byteLength, &point, paint);
491 EXPECT_TRUE(canvas.hasText());
492 }
493 {
494 // Test SkCanvas::drawPosTextH.
495 skia::AnalysisDevice device(bitmap);
496 skia::AnalysisCanvas canvas(&device);
497 canvas.drawPosTextH(text, byteLength, &point.fX, point.fY, paint);
498 EXPECT_TRUE(canvas.hasText());
499 }
500 {
501 // Test SkCanvas::drawTextOnPathHV.
502 skia::AnalysisDevice device(bitmap);
503 skia::AnalysisCanvas canvas(&device);
504 canvas.drawTextOnPathHV(text, byteLength, path, point.fX, point.fY, paint);
505 EXPECT_TRUE(canvas.hasText());
506 }
507 {
508 // Test SkCanvas::drawTextOnPath.
509 skia::AnalysisDevice device(bitmap);
510 skia::AnalysisCanvas canvas(&device);
511 canvas.drawTextOnPath(text, byteLength, path, NULL, paint);
512 EXPECT_TRUE(canvas.hasText());
513 }
514 {
515 // Text inside clip region.
516 skia::AnalysisDevice device(bitmap);
517 skia::AnalysisCanvas canvas(&device);
518 canvas.clipRect(SkRect::MakeWH(100, 100));
519 canvas.drawText(text, byteLength, point.fX, point.fY, paint);
520 EXPECT_TRUE(canvas.hasText());
521 }
522 {
523 // Text outside clip region.
524 skia::AnalysisDevice device(bitmap);
525 skia::AnalysisCanvas canvas(&device);
526 canvas.clipRect(SkRect::MakeXYWH(100, 0, 100, 100));
527 canvas.drawText(text, byteLength, point.fX, point.fY, paint);
528 // Analysis device does not do any clipping.
529 // So even when text is outside the clip region,
530 // it is marked as having the text.
531 // TODO(alokp): We may be able to do some trivial rejection.
532 EXPECT_TRUE(canvas.hasText());
533 }
534 }
535
457 } // namespace skia 536 } // namespace skia
OLDNEW
« skia/ext/analysis_canvas.cc ('K') | « skia/ext/analysis_canvas.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698