diff options
author | reed <reed@google.com> | 2016-03-03 08:13:54 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-03 08:13:54 -0800 |
commit | 0eda2587cc9233066cb3f3fec08f35c061780f8e (patch) | |
tree | d48efc9eaa40406d0dc8e8b7931629b049ad1909 /include | |
parent | c6663dc36b157e40c8225130f5970a346f9ba7c3 (diff) |
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
Review URL: https://codereview.chromium.org/1744103002
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkAnnotation.h | 76 | ||||
-rw-r--r-- | include/core/SkCanvas.h | 14 | ||||
-rw-r--r-- | include/core/SkDevice.h | 2 | ||||
-rw-r--r-- | include/core/SkPaint.h | 5 | ||||
-rw-r--r-- | include/core/SkPicture.h | 5 | ||||
-rw-r--r-- | include/core/SkWriter32.h | 12 | ||||
-rw-r--r-- | include/private/SkRecords.h | 10 | ||||
-rw-r--r-- | include/utils/SkDumpCanvas.h | 2 | ||||
-rw-r--r-- | include/utils/SkNWayCanvas.h | 1 |
9 files changed, 45 insertions, 82 deletions
diff --git a/include/core/SkAnnotation.h b/include/core/SkAnnotation.h index 80503c78d2..35cc2b5d04 100644 --- a/include/core/SkAnnotation.h +++ b/include/core/SkAnnotation.h @@ -8,83 +8,18 @@ #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; /** - * Experimental! - * * 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 + * 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. @@ -92,8 +27,6 @@ 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 @@ -104,8 +37,6 @@ 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. * @@ -116,5 +47,4 @@ 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 c23d748e78..1b4571a09c 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -22,6 +22,7 @@ class GrRenderTarget; class SkBaseDevice; class SkCanvasClipVisitor; class SkClipStack; +class SkData; class SkDraw; class SkDrawable; class SkDrawFilter; @@ -1072,6 +1073,18 @@ 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 @@ -1221,6 +1234,7 @@ 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 65ec56f902..cd13d5482e 100644 --- a/include/core/SkDevice.h +++ b/include/core/SkDevice.h @@ -252,6 +252,8 @@ 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 b58a3f3d4f..7090f3e249 100644 --- a/include/core/SkPaint.h +++ b/include/core/SkPaint.h @@ -13,7 +13,6 @@ #include "SkMatrix.h" #include "SkXfermode.h" -class SkAnnotation; class SkAutoDescriptor; class SkAutoGlyphCache; class SkColorFilter; @@ -625,9 +624,6 @@ 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. @@ -1039,7 +1035,6 @@ 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 7c8c187fd8..36f5310230 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -192,10 +192,11 @@ 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 = 43; + static const uint32_t CURRENT_PICTURE_VERSION = 44; static_assert(MIN_PICTURE_VERSION <= 41, "Remove kFontFileName and related code from SkFontDescriptor.cpp."); @@ -205,7 +206,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 1e7ec6d348..a2c6f5d472 100644 --- a/include/core/SkWriter32.h +++ b/include/core/SkWriter32.h @@ -206,6 +206,18 @@ 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 ecd73a12d9..1e274e9f46 100644 --- a/include/private/SkRecords.h +++ b/include/private/SkRecords.h @@ -8,6 +8,7 @@ #ifndef SkRecords_DEFINED #define SkRecords_DEFINED +#include "SkData.h" #include "SkCanvas.h" #include "SkDrawable.h" #include "SkImageFilter.h" @@ -17,6 +18,7 @@ #include "SkRect.h" #include "SkRRect.h" #include "SkRSXform.h" +#include "SkString.h" #include "SkTextBlob.h" namespace SkRecords { @@ -66,7 +68,8 @@ namespace SkRecords { M(DrawRect) \ M(DrawTextBlob) \ M(DrawAtlas) \ - M(DrawVertices) + M(DrawVertices) \ + M(DrawAnnotation) // Defines SkRecords::Type, an enum of all record types. #define ENUM(T) T##_Type, @@ -358,7 +361,10 @@ 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 d4c6dbf81b..1c16bf3f03 100644 --- a/include/utils/SkDumpCanvas.h +++ b/include/utils/SkDumpCanvas.h @@ -48,6 +48,7 @@ public: kDrawVertices_Verb, kDrawPatch_Verb, kDrawData_Verb, // obsolete + kDrawAnnotation_Verb, kCull_Verb }; @@ -120,6 +121,7 @@ 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 175701edbe..f2a99db802 100644 --- a/include/utils/SkNWayCanvas.h +++ b/include/utils/SkNWayCanvas.h @@ -79,6 +79,7 @@ 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; |