Expose API for whether an SkPicture contains text
authorajuma <ajuma@chromium.org>
Mon, 18 Aug 2014 19:59:55 +0000 (12:59 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 18 Aug 2014 19:59:55 +0000 (12:59 -0700)
BUG=chromium:399728
R=reed@google.com, nduca@chromium.org

Author: ajuma@chromium.org

Review URL: https://codereview.chromium.org/478673002

include/core/SkPicture.h
src/core/SkPicture.cpp
src/core/SkPictureData.h
tests/PictureTest.cpp

index 2a89277..004f130 100644 (file)
@@ -204,6 +204,10 @@ public:
      */
     int approximateOpCount() const;
 
+    /** Return true if this picture contains text.
+     */
+    bool hasText() const;
+
 private:
     // V2 : adds SkPixelRef's generation ID.
     // V3 : PictInfo tag at beginning, and EOF tag at the end
index ab00000..7af955a 100644 (file)
@@ -393,6 +393,11 @@ bool SkPicture::suitableForGpuRasterization(GrContext* context, const char **rea
 }
 #endif
 
+// fRecord TODO
+bool SkPicture::hasText() const {
+    return fData.get() && fData->hasText();
+}
+
 // fRecord OK
 bool SkPicture::willPlayBackBitmaps() const {
     if (fRecord.get()) {
index df898cf..a6c840a 100644 (file)
@@ -89,6 +89,8 @@ public:
 
     bool containsBitmaps() const;
 
+    bool hasText() const { return fContentInfo.hasText(); }
+
     int opCount() const { return fContentInfo.numOperations(); }
 
     const SkData* opData() const { return fOpData; }
index b3f13f0..b7e4bb6 100644 (file)
@@ -919,6 +919,63 @@ static void test_gpu_picture_optimization(skiatest::Reporter* reporter,
 
 #endif
 
+static void test_has_text(skiatest::Reporter* reporter) {
+    SkPictureRecorder recorder;
+    SkPaint paint;
+    paint.setColor(SK_ColorBLUE);
+    SkPoint point = SkPoint::Make(10, 10);
+
+    SkCanvas* canvas = recorder.beginRecording(100, 100);
+    {
+        canvas->drawRect(SkRect::MakeWH(20, 20), paint);
+    }
+    SkAutoTUnref<SkPicture> picture(recorder.endRecording());
+    REPORTER_ASSERT(reporter, !picture->hasText());
+
+    canvas = recorder.beginRecording(100, 100);
+    {
+        canvas->drawText("Q", 1, point.fX, point.fY, paint);
+    }
+    picture.reset(recorder.endRecording());
+    REPORTER_ASSERT(reporter, picture->hasText());
+
+    canvas = recorder.beginRecording(100, 100);
+    {
+        canvas->drawPosText("Q", 1, &point, paint);
+    }
+    picture.reset(recorder.endRecording());
+    REPORTER_ASSERT(reporter, picture->hasText());
+
+    canvas = recorder.beginRecording(100, 100);
+    {
+        canvas->drawPosTextH("Q", 1, &point.fX, point.fY, paint);
+    }
+    picture.reset(recorder.endRecording());
+    REPORTER_ASSERT(reporter, picture->hasText());
+
+    canvas = recorder.beginRecording(100, 100);
+    {
+        SkPath path;
+        path.moveTo(0, 0);
+        path.lineTo(50, 50);
+
+        canvas->drawTextOnPathHV("Q", 1, path, point.fX, point.fY, paint);
+    }
+    picture.reset(recorder.endRecording());
+    REPORTER_ASSERT(reporter, picture->hasText());
+
+    canvas = recorder.beginRecording(100, 100);
+    {
+        SkPath path;
+        path.moveTo(0, 0);
+        path.lineTo(50, 50);
+
+        canvas->drawTextOnPath("Q", 1, path, NULL, paint);
+    }
+    picture.reset(recorder.endRecording());
+    REPORTER_ASSERT(reporter, picture->hasText());
+}
+
 static void set_canvas_to_save_count_4(SkCanvas* canvas) {
     canvas->restoreToCount(1);
     canvas->save();
@@ -1561,6 +1618,7 @@ DEF_TEST(Picture, reporter) {
 #if SK_SUPPORT_GPU
     test_gpu_veto(reporter);
 #endif
+    test_has_text(reporter);
     test_gatherpixelrefs(reporter);
     test_gatherpixelrefsandrects(reporter);
     test_bitmap_with_encoded_data(reporter);