• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkPicturePriv_DEFINED
9 #define SkPicturePriv_DEFINED
10 
11 #include "include/core/SkPicture.h"
12 
13 class SkReadBuffer;
14 class SkWriteBuffer;
15 
16 class SkPicturePriv {
17 public:
18     /**
19      *  Recreate a picture that was serialized into a buffer. If the creation requires bitmap
20      *  decoding, the decoder must be set on the SkReadBuffer parameter by calling
21      *  SkReadBuffer::setBitmapDecoder() before calling SkPicture::MakeFromBuffer().
22      *  @param buffer Serialized picture data.
23      *  @return A new SkPicture representing the serialized data, or NULL if the buffer is
24      *          invalid.
25      */
26     static sk_sp<SkPicture> MakeFromBuffer(SkReadBuffer& buffer);
27 
28     /**
29      *  Serialize to a buffer.
30      */
31     static void Flatten(const sk_sp<const SkPicture> , SkWriteBuffer& buffer);
32 
33     // Returns NULL if this is not an SkBigPicture.
AsSkBigPicture(const sk_sp<const SkPicture> picture)34     static const SkBigPicture* AsSkBigPicture(const sk_sp<const SkPicture> picture) {
35         return picture->asSkBigPicture();
36     }
37 
MakeSharedID(uint32_t pictureID)38     static uint64_t MakeSharedID(uint32_t pictureID) {
39         uint64_t sharedID = SkSetFourByteTag('p', 'i', 'c', 't');
40         return (sharedID << 32) | pictureID;
41     }
42 
AddedToCache(const SkPicture * pic)43     static void AddedToCache(const SkPicture* pic) {
44         pic->fAddedToCache.store(true);
45     }
46 
47     // V35: Store SkRect (rather then width & height) in header
48     // V36: Remove (obsolete) alphatype from SkColorTable
49     // V37: Added shadow only option to SkDropShadowImageFilter (last version to record CLEAR)
50     // V38: Added PictureResolution option to SkPictureImageFilter
51     // V39: Added FilterLevel option to SkPictureImageFilter
52     // V40: Remove UniqueID serialization from SkImageFilter.
53     // V41: Added serialization of SkBitmapSource's filterQuality parameter
54     // V42: Added a bool to SkPictureShader serialization to indicate did-we-serialize-a-picture?
55     // V43: Added DRAW_IMAGE and DRAW_IMAGE_RECT opt codes to serialized data
56     // V44: Move annotations from paint to drawAnnotation
57     // V45: Add invNormRotation to SkLightingShader.
58     // V46: Add drawTextRSXform
59     // V47: Add occluder rect to SkBlurMaskFilter
60     // V48: Read and write extended SkTextBlobs.
61     // V49: Gradients serialized as SkColor4f + SkColorSpace
62     // V50: SkXfermode -> SkBlendMode
63     // V51: more SkXfermode -> SkBlendMode
64     // V52: Remove SkTextBlob::fRunCount
65     // V53: SaveLayerRec clip mask
66     // V54: ComposeShader can use a Mode or a Lerp
67     // V55: Drop blendmode[] from MergeImageFilter
68     // V56: Add TileMode in SkBlurImageFilter.
69     // V57: Sweep tiling info.
70     // V58: No more 2pt conical flipping.
71     // V59: No more LocalSpace option on PictureImageFilter
72     // V60: Remove flags in picture header
73     // V61: Change SkDrawPictureRec to take two colors rather than two alphas
74     // V62: Don't negate size of custom encoded images (don't write origin x,y either)
75     // V63: Store image bounds (including origin) instead of just width/height to support subsets
76     // V64: Remove occluder feature from blur maskFilter
77     // V65: Float4 paint color
78     // V66: Add saveBehind
79     // V67: Blobs serialize fonts instead of paints
80     // V68: Paint doesn't serialize font-related stuff
81     // V69: Clean up duplicated and redundant SkImageFilter related enums
82     // V70: Image filters definitions hidden, registered names updated to include "Impl"
83     // V71: Unify erode and dilate image filters
84     // V72: SkColorFilter_Matrix domain (rgba vs. hsla)
85     // V73: Use SkColor4f in per-edge AA quad API
86     // V74: MorphologyImageFilter internal radius is SkScaler
87     // V75: SkVertices switched from unsafe use of SkReader32 to SkReadBuffer (like everything else)
88     // V76: Add filtering enum to ImageShader
89     // V77: Explicit filtering options on imageshaders
90     // V78: Serialize skmipmap data for images that have it
91     // V79: Cubic Resampler option on imageshader
92     // V80: Smapling options on imageshader
93     // V81: sampling parameters on drawImage/drawImageRect/etc.
94 
95     enum Version {
96         kEdgeAAQuadColor4f_Version          = 73,
97         kMorphologyTakesScalar_Version      = 74,
98         kVerticesUseReadBuffer_Version      = 75,
99         kFilterEnumInImageShader_Version    = 76,
100         kFilterOptionsInImageShader_Version = 77,
101         kSerializeMipmaps_Version           = 78,
102         kCubicResamplerImageShader_Version  = 79,
103         kSamplingInImageShader_Version      = 80,
104         kSamplingInDrawImage_Version        = 81,
105         kPictureShaderFilterParam_Version   = 82,
106         kMatrixImageFilterSampling_Version  = 83,
107         kImageFilterImageSampling_Version   = 84,
108         kNoFilterQualityShaders_Version     = 85,
109         kVerticesRemoveCustomData_Version   = 86,
110 
111         // Only SKPs within the min/current picture version range (inclusive) can be read.
112         kMin_Version     = kEdgeAAQuadColor4f_Version,
113         kCurrent_Version = kVerticesRemoveCustomData_Version
114     };
115 
116     static_assert(SkPicturePriv::kMin_Version <= SkPicturePriv::kCubicResamplerImageShader_Version,
117         "Remove SkFontDescriptor::maybeAsSkFontData, SkFontMgr::makeFromFontData, kFontAxes");
118 };
119 
120 #endif
121