aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed <reed@google.com>2016-03-03 09:14:36 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-03 09:14:36 -0800
commit1610835624a9658cc60940b80038b84f297e836f (patch)
treee41c91ac9efd2f31cadc89535d6f82e24bb7570c
parent464d210875ccf24687027fa1b401b9ba257e2a27 (diff)
Revert of move annotations to canvas virtual (patchset #8 id:140001 of https://codereview.chromium.org/1744103002/ )
Reason for revert: need to update unittest in blink: FAILED: /b/build/goma/gomacc ../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/third_party/WebKit/Source/core/page/webkit_unit_tests.PrintContextTest.o.d -DV8_DEPRECATION_WARNINGS -DCLD_VERSION=2 -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORE=0 -DCHROMIUM_BUILD -DCR_CLANG_REVISION=261368-1 -DCOMPONENT_BUILD -DUSE_LIBJPEG_TURBO=1 -DENABLE_WEBRTC=1 -DENABLE_MEDIA_ROUTER=1 -DENABLE_PEPPER_CDMS -DENABLE_CONFIGURATION_POLICY -DENABLE_NOTIFICATIONS -DENABLE_TOPCHROME_MD=1 -DDCHECK_ALWAYS_ON=1 -DFIELDTRIAL_TESTING_ENABLED -DENABLE_TASK_MANAGER=1 -DENABLE_EXTENSIONS=1 -DENABLE_PDF=1 -DENABLE_PLUGIN_INSTALLATION=1 -DENABLE_PLUGINS=1 -DENABLE_SESSION_SERVICE=1 -DENABLE_THEMES=1 -DENABLE_AUTOFILL_DIALOG=1 -DENABLE_PRINTING=1 -DENABLE_BASIC_PRINTING=1 -DENABLE_PRINT_PREVIEW=1 -DENABLE_SPELLCHECK=1 -DUSE_BROWSER_SPELLCHECKER=1 -DENABLE_CAPTIVE_PORTAL_DETECTION=1 -DENABLE_APP_LIST=1 -DENABLE_SETTINGS_APP=1 -DENABLE_SUPERVISED_USERS=1 -DENABLE_SERVICE_DISCOVERY=1 -DV8_USE_EXTERNAL_STARTUP_DATA -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL -DBLINK_IMPLEMENTATION=1 -DINSIDE_BLINK -DMOJO_USE_SYSTEM_IMPL -DGTEST_HAS_POSIX_RE=0 -DGTEST_LANG_CXX11=0 -DSKIA_DLL -DGR_GL_IGNORE_ES3_MSAA=0 -DSK_SUPPORT_GPU=1 -DSK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS -DU_USING_ICU_NAMESPACE=0 -DU_ENABLE_DYLOAD=0 -DCHROME_PNG_WRITE_SUPPORT -DPNG_USER_CONFIG -DENABLE_LAYOUT_UNIT_IN_INLINE_BOXES=0 -DWTF_USE_CONCATENATED_IMPULSE_RESPONSES=1 -DENABLE_INPUT_MULTIPLE_FIELDS_UI=1 -DWTF_USE_ICCJPEG=1 -DWTF_USE_QCMSLIB=1 -DENABLE_OILPAN=1 -DUNIT_TEST -DGTEST_HAS_RTTI=0 -DV8_SHARED -DUSING_V8_SHARED -DUSE_LIBPCI=1 -DUSE_OPENSSL=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DWTF_USE_DYNAMIC_ANNOTATIONS=1 -Igen -I../../third_party/WebKit/public/web -I../../third_party/WebKit/Source/web -I../../third_party/WebKit/Source/web/src -I../../third_party/WebKit/public/web/mac -I../.. -I../../skia/config -I../../third_party/WebKit/Source -I../../third_party/khronos -I../../gpu -Igen/angle -I../../third_party/WebKit -I../../skia/ext -I../../third_party/skia/include/core -I../../third_party/skia/include/effects -I../../third_party/skia/include/pdf -I../../third_party/skia/include/gpu -I../../third_party/skia/include/lazy -I../../third_party/skia/include/pathops -I../../third_party/skia/include/pipe -I../../third_party/skia/include/ports -I../../third_party/skia/include/utils -I../../third_party/skia/include/utils/mac -I../../third_party/icu/source/common -I../../third_party/npapi -I../../third_party/npapi/bindings -I../../third_party/libpng -I../../third_party/ots/include -I../../third_party/qcms/src -I../../third_party/iccjpeg -I../../third_party/libjpeg_turbo -I../../third_party/WebKit -I../../third_party/icu/source/i18n -I../../testing/gmock/include -I../../testing/gtest/include -I../../third_party/libwebp -I../../third_party/zlib -I../../v8/include -Igen/blink -isysroot /Applications/Xcode5.1.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -O0 -fvisibility=hidden -Werror -mmacosx-version-min=10.6 -arch x86_64 -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-selector-type-mismatch -Wpartial-availability -Wheader-hygiene -Wno-char-subscripts -Wno-unneeded-internal-declaration -Wno-covered-switch-default -Wstring-conversion -Wno-c++11-narrowing -Wno-deprecated-register -Wno-inconsistent-missing-override -Wno-shift-negative-value -Wexit-time-destructors -std=c++11 -stdlib=libc++ -fno-rtti -fno-exceptions -fvisibility-inlines-hidden -fno-threadsafe-statics -Xclang -load -Xclang /b/build/slave/mac/build/src/third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.dylib -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-templates -Xclang -plugin-arg-find-bad-constructs -Xclang follow-macro-expansion -fcolor-diagnostics -fno-strict-aliasing -Xclang -load -Xclang /b/build/slave/mac/build/src/third_party/llvm-build/Release+Asserts/lib/libBlinkGCPlugin.dylib -Xclang -add-plugin -Xclang blink-gc-plugin -Xclang -plugin-arg-blink-gc-plugin -Xclang enable-oilpan -Xclang -plugin-arg-blink-gc-plugin -Xclang warn-raw-ptr -fstack-protector-all -c ../../third_party/WebKit/Source/core/page/PrintContextTest.cpp -o obj/third_party/WebKit/Source/core/page/webkit_unit_tests.PrintContextTest.o ../../third_party/WebKit/Source/core/page/PrintContextTest.cpp:54:20: error: no member named 'getAnnotation' in 'SkPaint' if (!paint.getAnnotation()) ~~~~~ ^ Original issue's description: > move annotations to canvas virtual > > In an effort to do it all at once, this change assumes that its ok to ignore annotations that were previously stored on paints in old SKP files (since this feature is only interesting to PDF printing). > > BUG=skia: > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1744103002 > > Committed: https://skia.googlesource.com/skia/+/0eda2587cc9233066cb3f3fec08f35c061780f8e TBR=halcanary@google.com,fmalita@chromium.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review URL: https://codereview.chromium.org/1761793003
-rw-r--r--include/core/SkAnnotation.h76
-rw-r--r--include/core/SkCanvas.h14
-rw-r--r--include/core/SkDevice.h2
-rw-r--r--include/core/SkPaint.h5
-rw-r--r--include/core/SkPicture.h5
-rw-r--r--include/core/SkWriter32.h12
-rw-r--r--include/private/SkRecords.h10
-rw-r--r--include/utils/SkDumpCanvas.h2
-rw-r--r--include/utils/SkNWayCanvas.h1
-rw-r--r--samplecode/SampleFilterFuzz.cpp4
-rw-r--r--src/core/SkAnnotation.cpp55
-rw-r--r--src/core/SkAnnotationKeys.h33
-rw-r--r--src/core/SkBitmapDevice.cpp10
-rw-r--r--src/core/SkCanvas.cpp17
-rw-r--r--src/core/SkPaint.cpp39
-rw-r--r--src/core/SkPictureFlat.h4
-rw-r--r--src/core/SkPicturePlayback.cpp6
-rw-r--r--src/core/SkPictureRecord.cpp12
-rw-r--r--src/core/SkPictureRecord.h1
-rw-r--r--src/core/SkReadBuffer.h1
-rw-r--r--src/core/SkReader32.h10
-rw-r--r--src/core/SkRecordDraw.cpp5
-rw-r--r--src/core/SkRecorder.cpp4
-rw-r--r--src/core/SkRecorder.h1
-rw-r--r--src/core/SkRemote.cpp10
-rw-r--r--src/core/SkRemote.h3
-rw-r--r--src/core/SkRemote_protocol.h1
-rw-r--r--src/gpu/SkGpuDevice.cpp12
-rw-r--r--src/pdf/SkPDFDevice.cpp80
-rw-r--r--src/pdf/SkPDFDevice.h8
-rw-r--r--src/utils/SkDumpCanvas.cpp8
-rw-r--r--src/utils/SkNWayCanvas.cpp7
-rw-r--r--tests/SerializationTest.cpp83
-rw-r--r--tests/Writer32Test.cpp41
34 files changed, 253 insertions, 329 deletions
diff --git a/include/core/SkAnnotation.h b/include/core/SkAnnotation.h
index 35cc2b5d04..80503c78d2 100644
--- a/include/core/SkAnnotation.h
+++ b/include/core/SkAnnotation.h
@@ -8,18 +8,83 @@
#ifndef SkAnnotation_DEFINED
#define SkAnnotation_DEFINED
+#include "SkRefCnt.h"
+#include "SkString.h"
#include "SkTypes.h"
class SkData;
+class SkReadBuffer;
+class SkWriteBuffer;
struct SkPoint;
+
+/**
+ * Experimental class for annotating draws. Do not use directly yet.
+ * Use helper functions at the bottom of this file for now.
+ */
+class SkAnnotation : public SkRefCnt {
+public:
+ virtual ~SkAnnotation();
+
+ static SkAnnotation* Create(const char key[], SkData* value) {
+ return new SkAnnotation(key, value);
+ }
+
+ static SkAnnotation* Create(SkReadBuffer& buffer) { return new SkAnnotation(buffer); }
+
+ /**
+ * Return the data for the specified key, or NULL.
+ */
+ SkData* find(const char key[]) const;
+
+ void writeToBuffer(SkWriteBuffer&) const;
+
+private:
+ SkAnnotation(const char key[], SkData* value);
+ SkAnnotation(SkReadBuffer&);
+
+ SkString fKey;
+ SkData* fData;
+
+ typedef SkRefCnt INHERITED;
+};
+
+/**
+ * Experimental collection of predefined Keys into the Annotation dictionary
+ */
+class SkAnnotationKeys {
+public:
+ /**
+ * Returns the canonical key whose payload is a URL
+ */
+ static const char* URL_Key();
+
+ /**
+ * Returns the canonical key whose payload is the name of a destination to
+ * be defined.
+ */
+ static const char* Define_Named_Dest_Key();
+
+ /**
+ * Returns the canonical key whose payload is the name of a destination to
+ * be linked to.
+ */
+ static const char* Link_Named_Dest_Key();
+};
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Experimental helper functions to use Annotations
+//
+
struct SkRect;
class SkCanvas;
/**
- * Annotate the canvas by associating the specified URL with the
- * specified rectangle (in local coordinates, just like drawRect).
+ * Experimental!
*
- * If the backend of this canvas does not support annotations, this call is
+ * Annotate the canvas by associating the specified URL with the
+ * specified rectangle (in local coordinates, just like drawRect). If the
+ * backend of this canvas does not support annotations, this call is
* safely ignored.
*
* The caller is responsible for managing its ownership of the SkData.
@@ -27,6 +92,8 @@ class SkCanvas;
SK_API void SkAnnotateRectWithURL(SkCanvas*, const SkRect&, SkData*);
/**
+ * Experimental!
+ *
* Annotate the canvas by associating a name with the specified point.
*
* If the backend of this canvas does not support annotations, this call is
@@ -37,6 +104,8 @@ SK_API void SkAnnotateRectWithURL(SkCanvas*, const SkRect&, SkData*);
SK_API void SkAnnotateNamedDestination(SkCanvas*, const SkPoint&, SkData*);
/**
+ * Experimental!
+ *
* Annotate the canvas by making the specified rectangle link to a named
* destination.
*
@@ -47,4 +116,5 @@ SK_API void SkAnnotateNamedDestination(SkCanvas*, const SkPoint&, SkData*);
*/
SK_API void SkAnnotateLinkToDestination(SkCanvas*, const SkRect&, SkData*);
+
#endif
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h
index 1b4571a09c..c23d748e78 100644
--- a/include/core/SkCanvas.h
+++ b/include/core/SkCanvas.h
@@ -22,7 +22,6 @@ class GrRenderTarget;
class SkBaseDevice;
class SkCanvasClipVisitor;
class SkClipStack;
-class SkData;
class SkDraw;
class SkDrawable;
class SkDrawFilter;
@@ -1073,18 +1072,6 @@ public:
void drawDrawable(SkDrawable* drawable, const SkMatrix* = NULL);
void drawDrawable(SkDrawable*, SkScalar x, SkScalar y);
- /**
- * Send an "annotation" to the canvas. The annotation is a key/value pair, where the key is
- * a null-terminated utf8 string, and the value is a blob of data stored in an SkData
- * (which may be null). The annotation is associated with the specified rectangle.
- *
- * The caller still retains its ownership of the data (if any).
- *
- * Note: on may canvas types, this information is ignored, but some canvases (e.g. recording
- * a picture or drawing to a PDF document) will pass on this information.
- */
- void drawAnnotation(const SkRect&, const char key[], SkData* value);
-
//////////////////////////////////////////////////////////////////////////
#ifdef SK_INTERNAL
#ifndef SK_SUPPORT_LEGACY_DRAWFILTER
@@ -1234,7 +1221,6 @@ protected:
virtual void didConcat(const SkMatrix&) {}
virtual void didSetMatrix(const SkMatrix&) {}
- virtual void onDrawAnnotation(const SkRect&, const char key[], SkData* value);
virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&);
virtual void onDrawText(const void* text, size_t byteLength, SkScalar x,
diff --git a/include/core/SkDevice.h b/include/core/SkDevice.h
index cd13d5482e..65ec56f902 100644
--- a/include/core/SkDevice.h
+++ b/include/core/SkDevice.h
@@ -252,8 +252,6 @@ protected:
virtual void drawAtlas(const SkDraw&, const SkImage* atlas, const SkRSXform[], const SkRect[],
const SkColor[], int count, SkXfermode::Mode, const SkPaint&);
- virtual void drawAnnotation(const SkDraw&, const SkRect&, const char[], SkData*) {}
-
/** The SkDevice passed will be an SkDevice which was returned by a call to
onCreateDevice on this device with kNeverTile_TileExpectation.
*/
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h
index 7090f3e249..b58a3f3d4f 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -13,6 +13,7 @@
#include "SkMatrix.h"
#include "SkXfermode.h"
+class SkAnnotation;
class SkAutoDescriptor;
class SkAutoGlyphCache;
class SkColorFilter;
@@ -624,6 +625,9 @@ public:
SkImageFilter* getImageFilter() const { return fImageFilter; }
SkImageFilter* setImageFilter(SkImageFilter*);
+ SkAnnotation* getAnnotation() const { return fAnnotation; }
+ SkAnnotation* setAnnotation(SkAnnotation*);
+
/**
* Return the paint's SkDrawLooper (if any). Does not affect the looper's
* reference count.
@@ -1035,6 +1039,7 @@ private:
SkRasterizer* fRasterizer;
SkDrawLooper* fLooper;
SkImageFilter* fImageFilter;
+ SkAnnotation* fAnnotation;
SkScalar fTextSize;
SkScalar fTextScaleX;
diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h
index 36f5310230..7c8c187fd8 100644
--- a/include/core/SkPicture.h
+++ b/include/core/SkPicture.h
@@ -192,11 +192,10 @@ private:
// V41: Added serialization of SkBitmapSource's filterQuality parameter
// V42: Added a bool to SkPictureShader serialization to indicate did-we-serialize-a-picture?
// V43: Added DRAW_IMAGE and DRAW_IMAGE_RECT opt codes to serialized data
- // V44: Move annotations from paint to drawAnnotation
// Only SKPs within the min/current picture version range (inclusive) can be read.
static const uint32_t MIN_PICTURE_VERSION = 35; // Produced by Chrome M39.
- static const uint32_t CURRENT_PICTURE_VERSION = 44;
+ static const uint32_t CURRENT_PICTURE_VERSION = 43;
static_assert(MIN_PICTURE_VERSION <= 41,
"Remove kFontFileName and related code from SkFontDescriptor.cpp.");
@@ -206,7 +205,7 @@ private:
static_assert(MIN_PICTURE_VERSION <= 43,
"Remove SkBitmapSourceDeserializer.");
-
+
static bool IsValidPictInfo(const SkPictInfo& info);
static SkPicture* Forwardport(const SkPictInfo&, const SkPictureData*);
diff --git a/include/core/SkWriter32.h b/include/core/SkWriter32.h
index a2c6f5d472..1e7ec6d348 100644
--- a/include/core/SkWriter32.h
+++ b/include/core/SkWriter32.h
@@ -206,18 +206,6 @@ public:
*/
static size_t WriteStringSize(const char* str, size_t len = (size_t)-1);
- void writeData(const SkData* data) {
- uint32_t len = data ? SkToU32(data->size()) : 0;
- this->write32(len);
- if (data) {
- this->writePad(data->data(), len);
- }
- }
-
- static size_t WriteDataSize(const SkData* data) {
- return 4 + SkAlign4(data ? data->size() : 0);
- }
-
/**
* Move the cursor back to offset bytes from the beginning.
* offset must be a multiple of 4 no greater than size().
diff --git a/include/private/SkRecords.h b/include/private/SkRecords.h
index 1e274e9f46..ecd73a12d9 100644
--- a/include/private/SkRecords.h
+++ b/include/private/SkRecords.h
@@ -8,7 +8,6 @@
#ifndef SkRecords_DEFINED
#define SkRecords_DEFINED
-#include "SkData.h"
#include "SkCanvas.h"
#include "SkDrawable.h"
#include "SkImageFilter.h"
@@ -18,7 +17,6 @@
#include "SkRect.h"
#include "SkRRect.h"
#include "SkRSXform.h"
-#include "SkString.h"
#include "SkTextBlob.h"
namespace SkRecords {
@@ -68,8 +66,7 @@ namespace SkRecords {
M(DrawRect) \
M(DrawTextBlob) \
M(DrawAtlas) \
- M(DrawVertices) \
- M(DrawAnnotation)
+ M(DrawVertices)
// Defines SkRecords::Type, an enum of all record types.
#define ENUM(T) T##_Type,
@@ -361,10 +358,7 @@ RECORD(DrawVertices, kDraw_Tag,
RefBox<SkXfermode> xmode;
PODArray<uint16_t> indices;
int indexCount);
-RECORD(DrawAnnotation, 0,
- SkRect rect;
- SkString key;
- RefBox<SkData> value);
+
#undef RECORD
} // namespace SkRecords
diff --git a/include/utils/SkDumpCanvas.h b/include/utils/SkDumpCanvas.h
index 1c16bf3f03..d4c6dbf81b 100644
--- a/include/utils/SkDumpCanvas.h
+++ b/include/utils/SkDumpCanvas.h
@@ -48,7 +48,6 @@ public:
kDrawVertices_Verb,
kDrawPatch_Verb,
kDrawData_Verb, // obsolete
- kDrawAnnotation_Verb,
kCull_Verb
};
@@ -121,7 +120,6 @@ protected:
void onClipRegion(const SkRegion&, SkRegion::Op) override;
void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
- void onDrawAnnotation(const SkRect&, const char key[], SkData* value) override;
static const char* EdgeStyleToAAString(ClipEdgeStyle edgeStyle);
diff --git a/include/utils/SkNWayCanvas.h b/include/utils/SkNWayCanvas.h
index f2a99db802..175701edbe 100644
--- a/include/utils/SkNWayCanvas.h
+++ b/include/utils/SkNWayCanvas.h
@@ -79,7 +79,6 @@ protected:
void onClipRegion(const SkRegion&, SkRegion::Op) override;
void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
- void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
class Iter;
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp
index 28155f14fd..687921ae0b 100644
--- a/samplecode/SampleFilterFuzz.cpp
+++ b/samplecode/SampleFilterFuzz.cpp
@@ -9,6 +9,7 @@
#include "Sk2DPathEffect.h"
#include "SkAlphaThresholdFilter.h"
#include "SkArcToPathEffect.h"
+#include "SkAnnotation.h"
#include "SkBlurImageFilter.h"
#include "SkBlurMaskFilter.h"
#include "SkCanvas.h"
@@ -544,6 +545,9 @@ static SkPaint make_paint() {
paint.setRasterizer(rasterizer);
paint.setImageFilter(make_image_filter());
SkAutoDataUnref data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool()));
+ SkAutoTUnref<SkAnnotation> annotation(
+ SkAnnotation::Create(make_string().c_str(), data));
+ paint.setAnnotation(annotation);
paint.setTextAlign(make_paint_align());
paint.setTextSize(make_scalar());
paint.setTextScaleX(make_scalar());
diff --git a/src/core/SkAnnotation.cpp b/src/core/SkAnnotation.cpp
index 09a6296fba..84d41fc669 100644
--- a/src/core/SkAnnotation.cpp
+++ b/src/core/SkAnnotation.cpp
@@ -6,10 +6,38 @@
*/
#include "SkAnnotation.h"
-#include "SkAnnotationKeys.h"
-#include "SkCanvas.h"
+#include "SkData.h"
+#include "SkPaint.h"
#include "SkPoint.h"
-#include "SkRect.h"
+#include "SkReadBuffer.h"
+#include "SkWriteBuffer.h"
+
+SkAnnotation::SkAnnotation(const char key[], SkData* value) : fKey(key) {
+ if (nullptr == value) {
+ value = SkData::NewEmpty();
+ } else {
+ value->ref();
+ }
+ fData = value;
+}
+
+SkAnnotation::~SkAnnotation() {
+ fData->unref();
+}
+
+SkData* SkAnnotation::find(const char key[]) const {
+ return fKey.equals(key) ? fData : nullptr;
+}
+
+SkAnnotation::SkAnnotation(SkReadBuffer& buffer) {
+ buffer.readString(&fKey);
+ fData = buffer.readByteArrayAsData();
+}
+
+void SkAnnotation::writeToBuffer(SkWriteBuffer& buffer) const {
+ buffer.writeString(fKey.c_str());
+ buffer.writeDataAsByteArray(fData);
+}
const char* SkAnnotationKeys::URL_Key() {
return "SkAnnotationKey_URL";
@@ -23,26 +51,37 @@ const char* SkAnnotationKeys::Link_Named_Dest_Key() {
return "SkAnnotationKey_Link_Named_Dest";
};
-//////////////////////////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+
+#include "SkCanvas.h"
+
+static void annotate_paint(SkPaint& paint, const char* key, SkData* value) {
+ paint.setAnnotation(SkAnnotation::Create(key, value))->unref();
+}
void SkAnnotateRectWithURL(SkCanvas* canvas, const SkRect& rect, SkData* value) {
if (nullptr == value) {
return;
}
- canvas->drawAnnotation(rect, SkAnnotationKeys::URL_Key(), value);
+ SkPaint paint;
+ annotate_paint(paint, SkAnnotationKeys::URL_Key(), value);
+ canvas->drawRect(rect, paint);
}
void SkAnnotateNamedDestination(SkCanvas* canvas, const SkPoint& point, SkData* name) {
if (nullptr == name) {
return;
}
- const SkRect rect = SkRect::MakeXYWH(point.x(), point.y(), 0, 0);
- canvas->drawAnnotation(rect, SkAnnotationKeys::Define_Named_Dest_Key(), name);
+ SkPaint paint;
+ annotate_paint(paint, SkAnnotationKeys::Define_Named_Dest_Key(), name);
+ canvas->drawPoint(point.x(), point.y(), paint);
}
void SkAnnotateLinkToDestination(SkCanvas* canvas, const SkRect& rect, SkData* name) {
if (nullptr == name) {
return;
}
- canvas->drawAnnotation(rect, SkAnnotationKeys::Link_Named_Dest_Key(), name);
+ SkPaint paint;
+ annotate_paint(paint, SkAnnotationKeys::Link_Named_Dest_Key(), name);
+ canvas->drawRect(rect, paint);
}
diff --git a/src/core/SkAnnotationKeys.h b/src/core/SkAnnotationKeys.h
deleted file mode 100644
index dff9338807..0000000000
--- a/src/core/SkAnnotationKeys.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2016 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkAnnotationKeys_DEFINED
-#define SkAnnotationKeys_DEFINED
-
-#include "SkTypes.h"
-
-class SkAnnotationKeys {
-public:
- /**
- * Returns the canonical key whose payload is a URL
- */
- static const char* URL_Key();
-
- /**
- * Returns the canonical key whose payload is the name of a destination to
- * be defined.
- */
- static const char* Define_Named_Dest_Key();
-
- /**
- * Returns the canonical key whose payload is the name of a destination to
- * be linked to.
- */
- static const char* Link_Named_Dest_Key();
-};
-
-#endif
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index d5dfcc1733..8c3c562181 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -20,6 +20,9 @@
class SkColorTable;
+#define CHECK_FOR_ANNOTATION(paint) \
+ do { if (paint.getAnnotation()) { return; } } while (0)
+
static bool valid_for_bitmap_device(const SkImageInfo& info,
SkAlphaType* newAlphaType) {
if (info.width() < 0 || info.height() < 0) {
@@ -201,14 +204,18 @@ void SkBitmapDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
void SkBitmapDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, size_t count,
const SkPoint pts[], const SkPaint& paint) {
+ CHECK_FOR_ANNOTATION(paint);
draw.drawPoints(mode, count, pts, paint);
}
void SkBitmapDevice::drawRect(const SkDraw& draw, const SkRect& r, const SkPaint& paint) {
+ CHECK_FOR_ANNOTATION(paint);
draw.drawRect(r, paint);
}
void SkBitmapDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) {
+ CHECK_FOR_ANNOTATION(paint);
+
SkPath path;
path.addOval(oval);
// call the VIRTUAL version, so any subclasses who do handle drawPath aren't
@@ -217,6 +224,8 @@ void SkBitmapDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPa
}
void SkBitmapDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const SkPaint& paint) {
+ CHECK_FOR_ANNOTATION(paint);
+
#ifdef SK_IGNORE_BLURRED_RRECT_OPT
SkPath path;
@@ -232,6 +241,7 @@ void SkBitmapDevice::drawRRect(const SkDraw& draw, const SkRRect& rrect, const S
void SkBitmapDevice::drawPath(const SkDraw& draw, const SkPath& path,
const SkPaint& paint, const SkMatrix* prePathMatrix,
bool pathIsMutable) {
+ CHECK_FOR_ANNOTATION(paint);
draw.drawPath(path, paint, prePathMatrix, pathIsMutable);
}
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index f3f38386bd..a628105001 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -1973,12 +1973,6 @@ void SkCanvas::drawAtlas(const SkImage* atlas, const SkRSXform xform[], const Sk
this->onDrawAtlas(atlas, xform, tex, colors, count, mode, cull, paint);
}
-void SkCanvas::drawAnnotation(const SkRect& rect, const char key[], SkData* value) {
- if (key) {
- this->onDrawAnnotation(rect, key, value);
- }
-}
-
void SkCanvas::legacy_drawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst,
const SkPaint* paint, SrcRectConstraint constraint) {
if (src) {
@@ -2731,17 +2725,6 @@ void SkCanvas::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], const
LOOPER_END
}
-void SkCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) {
- SkASSERT(key);
-
- SkPaint paint;
- LOOPER_BEGIN(paint, SkDrawFilter::kRect_Type, nullptr)
- while (iter.next()) {
- iter.fDevice->drawAnnotation(iter, rect, key, value);
- }
- LOOPER_END
-}
-
//////////////////////////////////////////////////////////////////////////////
// These methods are NOT virtual, and therefore must call back into virtual
// methods, rather than actually drawing themselves.
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index cdfb110454..017662ff48 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -6,6 +6,7 @@
*/
#include "SkPaint.h"
+#include "SkAnnotation.h"
#include "SkAutoKern.h"
#include "SkChecksum.h"
#include "SkColorFilter.h"
@@ -53,6 +54,7 @@ SkPaint::SkPaint() {
fRasterizer = nullptr;
fLooper = nullptr;
fImageFilter = nullptr;
+ fAnnotation = nullptr;
fTextSize = SkPaintDefaults_TextSize;
fTextScaleX = SK_Scalar1;
@@ -85,6 +87,7 @@ SkPaint::SkPaint(const SkPaint& src) {
REF_COPY(fRasterizer);
REF_COPY(fLooper);
REF_COPY(fImageFilter);
+ REF_COPY(fAnnotation);
COPY(fTextSize);
COPY(fTextScaleX);
@@ -111,6 +114,7 @@ SkPaint::SkPaint(SkPaint&& src) {
REF_MOVE(fRasterizer);
REF_MOVE(fLooper);
REF_MOVE(fImageFilter);
+ REF_MOVE(fAnnotation);
MOVE(fTextSize);
MOVE(fTextScaleX);
@@ -134,6 +138,7 @@ SkPaint::~SkPaint() {
SkSafeUnref(fRasterizer);
SkSafeUnref(fLooper);
SkSafeUnref(fImageFilter);
+ SkSafeUnref(fAnnotation);
}
SkPaint& SkPaint::operator=(const SkPaint& src) {
@@ -153,6 +158,7 @@ SkPaint& SkPaint::operator=(const SkPaint& src) {
REF_COPY(fRasterizer);
REF_COPY(fLooper);
REF_COPY(fImageFilter);
+ REF_COPY(fAnnotation);
COPY(fTextSize);
COPY(fTextScaleX);
@@ -185,6 +191,7 @@ SkPaint& SkPaint::operator=(SkPaint&& src) {
REF_MOVE(fRasterizer);
REF_MOVE(fLooper);
REF_MOVE(fImageFilter);
+ REF_MOVE(fAnnotation);
MOVE(fTextSize);
MOVE(fTextScaleX);
@@ -211,6 +218,7 @@ bool operator==(const SkPaint& a, const SkPaint& b) {
&& EQUAL(fRasterizer)
&& EQUAL(fLooper)
&& EQUAL(fImageFilter)
+ && EQUAL(fAnnotation)
&& EQUAL(fTextSize)
&& EQUAL(fTextScaleX)
&& EQUAL(fTextSkewX)
@@ -412,6 +420,11 @@ SkImageFilter* SkPaint::setImageFilter(SkImageFilter* imageFilter) {
return imageFilter;
}
+SkAnnotation* SkPaint::setAnnotation(SkAnnotation* annotation) {
+ SkRefCnt_SafeAssign(fAnnotation, annotation);
+ return annotation;
+}
+
///////////////////////////////////////////////////////////////////////////////
static SkScalar mag2(SkScalar x, SkScalar y) {
@@ -1884,6 +1897,7 @@ void SkPaint::flatten(SkWriteBuffer& buffer) const {
asint(this->getColorFilter()) |
asint(this->getRasterizer()) |
asint(this->getLooper()) |
+ asint(this->getAnnotation()) |
asint(this->getImageFilter())) {
flatFlags |= kHasEffects_FlatFlag;
}
@@ -1917,6 +1931,13 @@ void SkPaint::flatten(SkWriteBuffer& buffer) const {
buffer.writeFlattenable(this->getRasterizer());
buffer.writeFlattenable(this->getLooper());
buffer.writeFlattenable(this->getImageFilter());
+
+ if (fAnnotation) {
+ buffer.writeBool(true);
+ fAnnotation->writeToBuffer(buffer);
+ } else {
+ buffer.writeBool(false);
+ }
}
}
@@ -1960,14 +1981,8 @@ void SkPaint::unflatten(SkReadBuffer& buffer) {
SkSafeUnref(this->setLooper(buffer.readDrawLooper()));
SkSafeUnref(this->setImageFilter(buffer.readImageFilter()));
- if (buffer.isVersionLT(SkReadBuffer::kAnnotationsMovedToCanvas_Version)) {
- // We used to store annotations here (string+skdata) if this bool was true
- if (buffer.readBool()) {
- // Annotations have moved to drawAnnotation, so we just drop this one on the floor.
- SkString key;
- buffer.readString(&key);
- SkSafeUnref(buffer.readByteArrayAsData());
- }
+ if (buffer.readBool()) {
+ this->setAnnotation(SkAnnotation::Create(buffer))->unref();
}
} else {
this->setPathEffect(nullptr);
@@ -2190,6 +2205,12 @@ void SkPaint::toString(SkString* str) const {
str->append("</dd>");
}
+ SkAnnotation* annotation = this->getAnnotation();
+ if (annotation) {
+ str->append("<dt>Annotation:</dt><dd>");
+ str->append("</dd>");
+ }
+
str->append("<dt>Color:</dt><dd>0x");
SkColor color = this->getColor();
str->appendHex(color);
@@ -2416,7 +2437,7 @@ bool SkPaint::nothingToDraw() const {
uint32_t SkPaint::getHash() const {
// We're going to hash 10 pointers and 7 32-bit values, finishing up with fBitfields,
// so fBitfields should be 10 pointers and 6 32-bit values from the start.
- static_assert(offsetof(SkPaint, fBitfields) == 9 * sizeof(void*) + 6 * sizeof(uint32_t),
+ static_assert(offsetof(SkPaint, fBitfields) == 10 * sizeof(void*) + 6 * sizeof(uint32_t),
"SkPaint_notPackedTightly");
return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this),
offsetof(SkPaint, fBitfields) + sizeof(fBitfields));
diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h
index 00b7c2bb41..4eee04fcda 100644
--- a/src/core/SkPictureFlat.h
+++ b/src/core/SkPictureFlat.h
@@ -78,9 +78,7 @@ enum DrawType {
SAVE_LAYER_SAVELAYERFLAGS_DEPRECATED_JAN_2016,
SAVE_LAYER_SAVELAYERREC,
- DRAW_ANNOTATION,
-
- LAST_DRAWTYPE_ENUM = DRAW_ANNOTATION,
+ LAST_DRAWTYPE_ENUM = SAVE_LAYER_SAVELAYERREC,
};
// In the 'match' method, this constant will match any flavor of DRAW_BITMAP*
diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp
index e8497daca1..a5dd814b82 100644
--- a/src/core/SkPicturePlayback.cpp
+++ b/src/core/SkPicturePlayback.cpp
@@ -175,12 +175,6 @@ void SkPicturePlayback::handleOp(SkReader32* reader,
canvas->concat(matrix);
break;
}
- case DRAW_ANNOTATION: {
- const SkRect& rect = reader->skipT<SkRect>();
- const char* key = reader->readString();
- SkAutoTUnref<SkData> value(reader->readData());
- canvas->drawAnnotation(rect, key, value);
- } break;
case DRAW_ATLAS: {
const SkPaint* paint = fPictureData->getPaint(reader);
const SkImage* atlas = fPictureData->getImage(reader);
diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp
index 2718ee999d..2822a1ac16 100644
--- a/src/core/SkPictureRecord.cpp
+++ b/src/core/SkPictureRecord.cpp
@@ -777,18 +777,6 @@ void SkPictureRecord::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[],
this->validate(initialOffset, size);
}
-void SkPictureRecord::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) {
- size_t keyLen = fWriter.WriteStringSize(key);
- size_t valueLen = fWriter.WriteDataSize(value);
- size_t size = 4 + sizeof(SkRect) + keyLen + valueLen;
-
- size_t initialOffset = this->addDraw(DRAW_ANNOTATION, &size);
- this->addRect(rect);
- fWriter.writeString(key);
- fWriter.writeData(value);
- this->validate(initialOffset, size);
-}
-
///////////////////////////////////////////////////////////////////////////////
SkSurface* SkPictureRecord::onNewSurface(const SkImageInfo& info, const SkSurfaceProps&) {
diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h
index 607f6f10f7..2e1e62a021 100644
--- a/src/core/SkPictureRecord.h
+++ b/src/core/SkPictureRecord.h
@@ -204,7 +204,6 @@ protected:
void onClipRegion(const SkRegion&, SkRegion::Op) override;
void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
- void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
int addPathToHeap(const SkPath& path); // does not write to ops stream
diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h
index b9b30944ff..3d6dd362ac 100644
--- a/src/core/SkReadBuffer.h
+++ b/src/core/SkReadBuffer.h
@@ -60,7 +60,6 @@ public:
kBitmapSourceFilterQuality_Version = 41,
kPictureShaderHasPictureBool_Version = 42,
kHasDrawImageOpCodes_Version = 43,
- kAnnotationsMovedToCanvas_Version = 44,
};
/**
diff --git a/src/core/SkReader32.h b/src/core/SkReader32.h
index 645d64cc24..68dda23c6e 100644
--- a/src/core/SkReader32.h
+++ b/src/core/SkReader32.h
@@ -1,3 +1,4 @@
+
/*
* Copyright 2008 The Android Open Source Project
*
@@ -9,7 +10,6 @@
#ifndef SkReader32_DEFINED
#define SkReader32_DEFINED
-#include "SkData.h"
#include "SkMatrix.h"
#include "SkPath.h"
#include "SkRegion.h"
@@ -135,14 +135,6 @@ public:
*/
size_t readIntoString(SkString* copy);
- SkData* readData() {
- uint32_t byteLength = this->readU32();
- if (0 == byteLength) {
- return SkData::NewEmpty();
- }
- return SkData::NewWithCopy(this->skip(byteLength), byteLength);
- }
-
private:
template <typename T> bool readObjectFromMemory(T* obj) {
size_t size = obj->readFromMemory(this->peek(), this->available());
diff --git a/src/core/SkRecordDraw.cpp b/src/core/SkRecordDraw.cpp
index 0e4b5af580..5ca9517d3f 100644
--- a/src/core/SkRecordDraw.cpp
+++ b/src/core/SkRecordDraw.cpp
@@ -117,7 +117,6 @@ DRAW(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, &r.matrix, r.p
DRAW(DrawAtlas, drawAtlas(r.atlas, r.xforms, r.texs, r.colors, r.count, r.mode, r.cull, r.paint));
DRAW(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.colors,
r.xmode, r.indices, r.indexCount, r.paint));
-DRAW(DrawAnnotation, drawAnnotation(r.rect, r.key.c_str(), r.value));
#undef DRAW
template <> void Draw::draw(const DrawDrawable& r) {
@@ -518,10 +517,6 @@ private:
return this->adjustAndMap(op.worstCaseBounds, nullptr);
}
- Bounds bounds(const DrawAnnotation& op) const {
- return this->adjustAndMap(op.rect, nullptr);
- }
-
static void AdjustTextForFontMetrics(SkRect* rect, const SkPaint& paint) {
#ifdef SK_DEBUG
SkRect correct = *rect;
diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp
index f9fd8bb374..01c28dfc2b 100644
--- a/src/core/SkRecorder.cpp
+++ b/src/core/SkRecorder.cpp
@@ -332,10 +332,6 @@ void SkRecorder::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], cons
this->copy(cull));
}
-void SkRecorder::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) {
- APPEND(DrawAnnotation, rect, SkString(key), value);
-}
-
void SkRecorder::willSave() {
APPEND(Save);
}
diff --git a/src/core/SkRecorder.h b/src/core/SkRecorder.h
index 7372e540e7..cd5bc8ad04 100644
--- a/src/core/SkRecorder.h
+++ b/src/core/SkRecorder.h
@@ -120,7 +120,6 @@ public:
void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) override;
void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
- void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override { return nullptr; }
diff --git a/src/core/SkRemote.cpp b/src/core/SkRemote.cpp
index 9b0383d406..22185cddb0 100644
--- a/src/core/SkRemote.cpp
+++ b/src/core/SkRemote.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkAnnotation.h"
#include "SkCanvas.h"
#include "SkColorFilter.h"
#include "SkDrawLooper.h"
@@ -126,6 +127,7 @@ namespace SkRemote {
fIDs.rasterizer = fEncoder->define(paint.getRasterizer());
fIDs.looper = fEncoder->define(paint.getLooper());
fIDs.imagefilter = fEncoder->define(paint.getImageFilter());
+ fIDs.annotation = fEncoder->define(paint.getAnnotation());
}
~AutoCommonIDs() {
if (fEncoder) {
@@ -138,6 +140,7 @@ namespace SkRemote {
fEncoder->undefine(fIDs.rasterizer);
fEncoder->undefine(fIDs.looper);
fEncoder->undefine(fIDs.imagefilter);
+ fEncoder->undefine(fIDs.annotation);
}
}
@@ -458,6 +461,7 @@ namespace SkRemote {
ID define(SkRasterizer* v)O{return this->define(Type::kRasterizer, &fRasterizer, v);}
ID define(SkDrawLooper* v)O{return this->define(Type::kDrawLooper, &fDrawLooper, v);}
ID define(SkImageFilter* v)O{return this->define(Type::kImageFilter, &fImageFilter, v);}
+ ID define(SkAnnotation* v)O{return this->define(Type::kAnnotation, &fAnnotation, v);}
#undef O
@@ -476,6 +480,7 @@ namespace SkRemote {
case Type::kRasterizer: return fRasterizer .remove(id);
case Type::kDrawLooper: return fDrawLooper .remove(id);
case Type::kImageFilter: return fImageFilter.remove(id);
+ case Type::kAnnotation: return fAnnotation .remove(id);
};
}
@@ -489,6 +494,7 @@ namespace SkRemote {
paint->setRasterizer (fRasterizer .find(common.rasterizer));
paint->setLooper (fDrawLooper .find(common.looper));
paint->setImageFilter(fImageFilter.find(common.imagefilter));
+ paint->setAnnotation (fAnnotation .find(common.annotation));
}
void save() override { fCanvas->save(); }
@@ -611,6 +617,7 @@ namespace SkRemote {
ReffedIDMap<SkRasterizer , Type::kRasterizer > fRasterizer;
ReffedIDMap<SkDrawLooper , Type::kDrawLooper > fDrawLooper;
ReffedIDMap<SkImageFilter , Type::kImageFilter> fImageFilter;
+ ReffedIDMap<SkAnnotation , Type::kAnnotation > fAnnotation;
SkCanvas* fCanvas;
uint64_t fNextID = 0;
@@ -646,6 +653,7 @@ namespace SkRemote {
fRasterizer .foreach(undef);
fDrawLooper .foreach(undef);
fImageFilter.foreach(undef);
+ fAnnotation .foreach(undef);
}
template <typename Map, typename T>
@@ -671,6 +679,7 @@ namespace SkRemote {
ID define(SkRasterizer* v) override { return this->define(&fRasterizer , v); }
ID define(SkDrawLooper* v) override { return this->define(&fDrawLooper , v); }
ID define(SkImageFilter* v) override { return this->define(&fImageFilter, v); }
+ ID define(SkAnnotation* v) override { return this->define(&fAnnotation , v); }
void undefine(ID) override {}
@@ -740,6 +749,7 @@ namespace SkRemote {
RefKeyMap<SkRasterizer , Type::kRasterizer > fRasterizer;
RefKeyMap<SkDrawLooper , Type::kDrawLooper > fDrawLooper;
RefKeyMap<SkImageFilter , Type::kImageFilter> fImageFilter;
+ RefKeyMap<SkAnnotation , Type::kAnnotation > fAnnotation;
Encoder* fWrapped;
};
diff --git a/src/core/SkRemote.h b/src/core/SkRemote.h
index a8126d6c9e..a1b1405b21 100644
--- a/src/core/SkRemote.h
+++ b/src/core/SkRemote.h
@@ -79,13 +79,14 @@ namespace SkRemote {
virtual ID define(SkRasterizer*) = 0;
virtual ID define(SkDrawLooper*) = 0;
virtual ID define(SkImageFilter*) = 0;
+ virtual ID define(SkAnnotation*) = 0;
virtual void undefine(ID) = 0;
// TODO: do these all belong here in CommonIDs?
struct CommonIDs {
ID misc, patheffect, shader, xfermode, maskfilter,
- colorfilter, rasterizer, looper, imagefilter;
+ colorfilter, rasterizer, looper, imagefilter, annotation;
};
virtual void save() = 0;
diff --git a/src/core/SkRemote_protocol.h b/src/core/SkRemote_protocol.h
index 825a1c2732..19bdc33fdd 100644
--- a/src/core/SkRemote_protocol.h
+++ b/src/core/SkRemote_protocol.h
@@ -28,6 +28,7 @@ namespace SkRemote {
kRasterizer,
kDrawLooper,
kImageFilter,
+ kAnnotation,
};
} // namespace SkRemote
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index a7bf82e6f0..04bc14e563 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -68,6 +68,11 @@ enum { kDefaultImageFilterCacheSize = 32 * 1024 * 1024 };
///////////////////////////////////////////////////////////////////////////////
+#define CHECK_FOR_ANNOTATION(paint) \
+ do { if (paint.getAnnotation()) { return; } } while (0)
+
+///////////////////////////////////////////////////////////////////////////////
+
// Helper for turning a bitmap into a texture. If the bitmap is GrTexture backed this
// just accesses the backing GrTexture. Otherwise, it creates a cached texture
// representation and releases it in the destructor.
@@ -396,6 +401,7 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
size_t count, const SkPoint pts[], const SkPaint& paint) {
ASSERT_SINGLE_OWNER
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPoints", fContext);
+ CHECK_FOR_ANNOTATION(paint);
CHECK_SHOULD_DRAW(draw);
SkScalar width = paint.getStrokeWidth();
@@ -447,6 +453,7 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint& paint) {
ASSERT_SINGLE_OWNER
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRect", fContext);
+ CHECK_FOR_ANNOTATION(paint);
CHECK_SHOULD_DRAW(draw);
bool doStroke = paint.getStyle() != SkPaint::kFill_Style;
@@ -493,6 +500,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
const SkPaint& paint) {
ASSERT_SINGLE_OWNER
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawRRect", fContext);
+ CHECK_FOR_ANNOTATION(paint);
CHECK_SHOULD_DRAW(draw);
GrPaint grPaint;
@@ -557,6 +565,7 @@ void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
const SkRRect& inner, const SkPaint& paint) {
ASSERT_SINGLE_OWNER
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawDRRect", fContext);
+ CHECK_FOR_ANNOTATION(paint);
CHECK_SHOULD_DRAW(draw);
if (outer.isEmpty()) {
@@ -597,6 +606,7 @@ void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint& paint) {
ASSERT_SINGLE_OWNER
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawOval", fContext);
+ CHECK_FOR_ANNOTATION(paint);
CHECK_SHOULD_DRAW(draw);
// Presumably the path effect warps this to something other than an oval
@@ -651,6 +661,7 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
}
}
+ CHECK_FOR_ANNOTATION(paint);
CHECK_SHOULD_DRAW(draw);
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPath", fContext);
@@ -1461,6 +1472,7 @@ void SkGpuDevice::drawProducerNine(const SkDraw& draw, GrTextureProducer* produc
const SkIRect& center, const SkRect& dst, const SkPaint& paint) {
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawProducerNine", fContext);
+ CHECK_FOR_ANNOTATION(paint);
CHECK_SHOULD_DRAW(draw);
bool useFallback = paint.getMaskFilter() || paint.isAntiAlias() ||
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index f473e0f981..315c84317d 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -7,7 +7,7 @@
#include "SkPDFDevice.h"
-#include "SkAnnotationKeys.h"
+#include "SkAnnotation.h"
#include "SkColor.h"
#include "SkColorFilter.h"
#include "SkClipStack.h"
@@ -757,17 +757,6 @@ void SkPDFDevice::cleanUp(bool clearFontUsage) {
}
}
-void SkPDFDevice::drawAnnotation(const SkDraw& d, const SkRect& rect, const char key[],
- SkData* value) {
- if (0 == rect.width() && 0 == rect.height()) {
- handlePointAnnotation({ rect.x(), rect.y() }, *d.fMatrix, key, value);
- } else {
- SkPath path;
- path.addRect(rect);
- handlePathAnnotation(path, d, key, value);
- }
-}
-
void SkPDFDevice::drawPaint(const SkDraw& d, const SkPaint& paint) {
SkPaint newPaint = paint;
replace_srcmode_on_opaque_paint(&newPaint);
@@ -807,6 +796,12 @@ void SkPDFDevice::drawPoints(const SkDraw& d,
return;
}
+ if (SkAnnotation* annotation = passedPaint.getAnnotation()) {
+ if (handlePointAnnotation(points, count, *d.fMatrix, annotation)) {
+ return;
+ }
+ }
+
// SkDraw::drawPoints converts to multiple calls to fDevice->drawPath.
// We only use this when there's a path effect because of the overhead
// of multiple calls to setUpContentEntry it causes.
@@ -944,6 +939,14 @@ void SkPDFDevice::drawRect(const SkDraw& d,
return;
}
+ if (SkAnnotation* annotation = paint.getAnnotation()) {
+ SkPath path;
+ path.addRect(rect);
+ if (handlePathAnnotation(path, d, annotation)) {
+ return;
+ }
+ }
+
ScopedContentEntry content(this, d, paint);
if (!content.entry()) {
return;
@@ -1022,6 +1025,12 @@ void SkPDFDevice::drawPath(const SkDraw& d,
return;
}
+ if (SkAnnotation* annotation = paint.getAnnotation()) {
+ if (handlePathAnnotation(*pathPtr, d, annotation)) {
+ return;
+ }
+ }
+
ScopedContentEntry content(this, d.fClipStack, *d.fClip, matrix, paint);
if (!content.entry()) {
return;
@@ -1675,26 +1684,26 @@ bool SkPDFDevice::handleInversePath(const SkDraw& d, const SkPath& origPath,
return true;
}
-void SkPDFDevice::handlePointAnnotation(const SkPoint& point,
+bool SkPDFDevice::handlePointAnnotation(const SkPoint* points, size_t count,
const SkMatrix& matrix,
- const char key[], SkData* value) {
- if (!value) {
- return;
- }
-
- if (!strcmp(SkAnnotationKeys::Define_Named_Dest_Key(), key)) {
- SkPoint transformedPoint;
- matrix.mapXY(point.x(), point.y(), &transformedPoint);
- fNamedDestinations.push(new NamedDestination(value, transformedPoint));
+ SkAnnotation* annotationInfo) {
+ SkData* nameData = annotationInfo->find(
+ SkAnnotationKeys::Define_Named_Dest_Key());
+ if (nameData) {
+ for (size_t i = 0; i < count; i++) {
+ SkPoint transformedPoint;
+ matrix.mapXY(points[i].x(), points[i].y(), &transformedPoint);
+ fNamedDestinations.push(new NamedDestination(nameData, transformedPoint));
+ }
+ return true;
}
+ return false;
}
-void SkPDFDevice::handlePathAnnotation(const SkPath& path,
+bool SkPDFDevice::handlePathAnnotation(const SkPath& path,
const SkDraw& d,
- const char key[], SkData* value) {
- if (!value) {
- return;
- }
+ SkAnnotation* annotation) {
+ SkASSERT(annotation);
SkPath transformedPath = path;
transformedPath.transform(*d.fMatrix);
@@ -1703,15 +1712,24 @@ void SkPDFDevice::handlePathAnnotation(const SkPath& path,
false);
SkRect transformedRect = SkRect::Make(clip.getBounds());
- if (!strcmp(SkAnnotationKeys::URL_Key(), key)) {
+ SkData* urlData = annotation->find(SkAnnotationKeys::URL_Key());
+ if (urlData) {
if (!transformedRect.isEmpty()) {
- fLinkToURLs.push(new RectWithData(transformedRect, value));
+ fLinkToURLs.push(new RectWithData(transformedRect, urlData));
}
- } else if (!strcmp(SkAnnotationKeys::Link_Named_Dest_Key(), key)) {
+ return true;
+ }
+
+ SkData* linkToDestination =
+ annotation->find(SkAnnotationKeys::Link_Named_Dest_Key());
+ if (linkToDestination) {
if (!transformedRect.isEmpty()) {
- fLinkToDestinations.push(new RectWithData(transformedRect, value));
+ fLinkToDestinations.push(new RectWithData(transformedRect, linkToDestination));
}
+ return true;
}
+
+ return false;
}
void SkPDFDevice::appendAnnotations(SkPDFArray* array) const {
diff --git a/src/pdf/SkPDFDevice.h b/src/pdf/SkPDFDevice.h
index bc71e46dbb..31f6de11ee 100644
--- a/src/pdf/SkPDFDevice.h
+++ b/src/pdf/SkPDFDevice.h
@@ -198,8 +198,6 @@ protected:
SkSurface* newSurface(const SkImageInfo&, const SkSurfaceProps&) override;
- void drawAnnotation(const SkDraw&, const SkRect&, const char key[], SkData* value) override;
-
private:
// TODO(vandebo): push most of SkPDFDevice's state into a core object in
// order to get the right access levels without using friend.
@@ -305,8 +303,10 @@ private:
bool handleInversePath(const SkDraw& d, const SkPath& origPath,
const SkPaint& paint, bool pathIsMutable,
const SkMatrix* prePathMatrix = nullptr);
- void handlePointAnnotation(const SkPoint&, const SkMatrix&, const char key[], SkData* value);
- void handlePathAnnotation(const SkPath&, const SkDraw& d, const char key[], SkData* value);
+ bool handlePointAnnotation(const SkPoint* points, size_t count,
+ const SkMatrix& matrix, SkAnnotation* annot);
+ bool handlePathAnnotation(const SkPath& path, const SkDraw& d,
+ SkAnnotation* annot);
typedef SkBaseDevice INHERITED;
diff --git a/src/utils/SkDumpCanvas.cpp b/src/utils/SkDumpCanvas.cpp
index 75fa836a6a..916c32a655 100644
--- a/src/utils/SkDumpCanvas.cpp
+++ b/src/utils/SkDumpCanvas.cpp
@@ -9,7 +9,6 @@
#include "SkDumpCanvas.h"
#ifdef SK_DEVELOPER
-#include "SkData.h"
#include "SkPatchUtils.h"
#include "SkPicture.h"
#include "SkPixelRef.h"
@@ -483,13 +482,6 @@ void SkDumpCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4]
texCoords[2].x(), texCoords[2].y(), texCoords[3].x(), texCoords[3].y());
}
-void SkDumpCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) {
- SkString str;
- toString(rect, &str);
- this->dump(kDrawAnnotation_Verb, nullptr, "drawAnnotation(%s \"%s\" (%zu))",
- str.c_str(), key, value ? value->size() : 0);
-}
-
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/utils/SkNWayCanvas.cpp b/src/utils/SkNWayCanvas.cpp
index fd5fa82aa5..e3b1e019b6 100644
--- a/src/utils/SkNWayCanvas.cpp
+++ b/src/utils/SkNWayCanvas.cpp
@@ -292,13 +292,6 @@ void SkNWayCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4]
}
}
-void SkNWayCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* data) {
- Iter iter(fList);
- while (iter.next()) {
- iter->drawAnnotation(rect, key, data);
- }
-}
-
#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
SkDrawFilter* SkNWayCanvas::setDrawFilter(SkDrawFilter* filter) {
Iter iter(fList);
diff --git a/tests/SerializationTest.cpp b/tests/SerializationTest.cpp
index eb84b3c957..a4e40c54ee 100644
--- a/tests/SerializationTest.cpp
+++ b/tests/SerializationTest.cpp
@@ -5,7 +5,6 @@
* found in the LICENSE file.
*/
-#include "SkAnnotationKeys.h"
#include "Resources.h"
#include "SkCanvas.h"
#include "SkFixed.h"
@@ -547,85 +546,3 @@ DEF_TEST(Serialization, reporter) {
TestPictureTypefaceSerialization(reporter);
}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-#include "SkAnnotation.h"
-
-static SkPicture* copy_picture_via_serialization(SkPicture* src) {
- SkDynamicMemoryWStream wstream;
- src->serialize(&wstream);
- SkAutoTDelete<SkStreamAsset> rstream(wstream.detachAsStream());
- return SkPicture::CreateFromStream(rstream);
-}
-
-struct AnnotationRec {
- const SkRect fRect;
- const char* fKey;
- SkData* fValue;
-};
-
-class TestAnnotationCanvas : public SkCanvas {
- skiatest::Reporter* fReporter;
- const AnnotationRec* fRec;
- int fCount;
- int fCurrIndex;
-
-public:
- TestAnnotationCanvas(skiatest::Reporter* reporter, const AnnotationRec rec[], int count)
- : SkCanvas(100, 100)
- , fReporter(reporter)
- , fRec(rec)
- , fCount(count)
- , fCurrIndex(0)
- {}
-
- ~TestAnnotationCanvas() {
- REPORTER_ASSERT(fReporter, fCount == fCurrIndex);
- }
-
-protected:
- void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) {
- REPORTER_ASSERT(fReporter, fCurrIndex < fCount);
- REPORTER_ASSERT(fReporter, rect == fRec[fCurrIndex].fRect);
- REPORTER_ASSERT(fReporter, !strcmp(key, fRec[fCurrIndex].fKey));
- REPORTER_ASSERT(fReporter, value->equals(fRec[fCurrIndex].fValue));
- fCurrIndex += 1;
- }
-};
-
-/*
- * Test the 3 annotation types by recording them into a picture, serializing, and then playing
- * them back into another canvas.
- */
-DEF_TEST(Annotations, reporter) {
- SkPictureRecorder recorder;
- SkCanvas* recordingCanvas = recorder.beginRecording(SkRect::MakeWH(100, 100));
-
- const char* str0 = "rect-with-url";
- const SkRect r0 = SkRect::MakeWH(10, 10);
- SkAutoTUnref<SkData> d0(SkData::NewWithCString(str0));
- SkAnnotateRectWithURL(recordingCanvas, r0, d0);
-
- const char* str1 = "named-destination";
- const SkRect r1 = SkRect::MakeXYWH(5, 5, 0, 0); // collapsed to a point
- SkAutoTUnref<SkData> d1(SkData::NewWithCString(str1));
- SkAnnotateNamedDestination(recordingCanvas, {r1.x(), r1.y()}, d1);
-
- const char* str2 = "link-to-destination";
- const SkRect r2 = SkRect::MakeXYWH(20, 20, 5, 6);
- SkAutoTUnref<SkData> d2(SkData::NewWithCString(str2));
- SkAnnotateLinkToDestination(recordingCanvas, r2, d2);
-
- const AnnotationRec recs[] = {
- { r0, SkAnnotationKeys::URL_Key(), d0 },
- { r1, SkAnnotationKeys::Define_Named_Dest_Key(), d1 },
- { r2, SkAnnotationKeys::Link_Named_Dest_Key(), d2 },
- };
-
- SkAutoTUnref<SkPicture> pict0(recorder.endRecording());
- SkAutoTUnref<SkPicture> pict1(copy_picture_via_serialization(pict0));
-
- TestAnnotationCanvas canvas(reporter, recs, SK_ARRAY_COUNT(recs));
- canvas.drawPicture(pict1);
-}
-
diff --git a/tests/Writer32Test.cpp b/tests/Writer32Test.cpp
index e03a9163aa..39ae79cff6 100644
--- a/tests/Writer32Test.cpp
+++ b/tests/Writer32Test.cpp
@@ -278,44 +278,3 @@ DEF_TEST(Writer32_misc, reporter) {
test_rewind(reporter);
}
-DEF_TEST(Writer32_data, reporter) {
- const char* str = "0123456789";
- SkAutoTUnref<SkData> data0(SkData::NewWithCString(str));
- SkAutoTUnref<SkData> data1(SkData::NewEmpty());
-
- const size_t sizes[] = {
- SkWriter32::WriteDataSize(nullptr),
- SkWriter32::WriteDataSize(data0),
- SkWriter32::WriteDataSize(data1),
- };
-
- SkSWriter32<1000> writer;
- size_t sizeWritten = 0;
-
- writer.writeData(nullptr);
- sizeWritten += sizes[0];
- REPORTER_ASSERT(reporter, sizeWritten == writer.bytesWritten());
-
- writer.writeData(data0);
- sizeWritten += sizes[1];
- REPORTER_ASSERT(reporter, sizeWritten == writer.bytesWritten());
-
- writer.writeData(data1);
- sizeWritten += sizes[2];
- REPORTER_ASSERT(reporter, sizeWritten == writer.bytesWritten());
-
- SkAutoTUnref<SkData> result(writer.snapshotAsData());
-
- SkReader32 reader(result->data(), result->size());
- SkAutoTUnref<SkData> d0(reader.readData()),
- d1(reader.readData()),
- d2(reader.readData());
-
- REPORTER_ASSERT(reporter, 0 == d0->size());
- REPORTER_ASSERT(reporter, strlen(str)+1 == d1->size());
- REPORTER_ASSERT(reporter, !memcmp(str, d1->data(), strlen(str)+1));
- REPORTER_ASSERT(reporter, 0 == d2->size());
-
- REPORTER_ASSERT(reporter, reader.offset() == sizeWritten);
- REPORTER_ASSERT(reporter, reader.eof());
-}