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 class SkStream; 16 struct SkPictInfo; 17 18 class SkPicturePriv { 19 public: 20 /** 21 * Recreate a picture that was serialized into a buffer. If the creation requires bitmap 22 * decoding, the decoder must be set on the SkReadBuffer parameter by calling 23 * SkReadBuffer::setBitmapDecoder() before calling SkPicture::MakeFromBuffer(). 24 * @param buffer Serialized picture data. 25 * @return A new SkPicture representing the serialized data, or NULL if the buffer is 26 * invalid. 27 */ 28 static sk_sp<SkPicture> MakeFromBuffer(SkReadBuffer& buffer); 29 30 /** 31 * Serialize to a buffer. 32 */ 33 static void Flatten(const sk_sp<const SkPicture> , SkWriteBuffer& buffer); 34 35 // Returns NULL if this is not an SkBigPicture. AsSkBigPicture(const sk_sp<const SkPicture> picture)36 static const SkBigPicture* AsSkBigPicture(const sk_sp<const SkPicture> picture) { 37 return picture->asSkBigPicture(); 38 } 39 MakeSharedID(uint32_t pictureID)40 static uint64_t MakeSharedID(uint32_t pictureID) { 41 uint64_t sharedID = SkSetFourByteTag('p', 'i', 'c', 't'); 42 return (sharedID << 32) | pictureID; 43 } 44 AddedToCache(const SkPicture * pic)45 static void AddedToCache(const SkPicture* pic) { 46 pic->fAddedToCache.store(true); 47 } 48 49 // V35: Store SkRect (rather then width & height) in header 50 // V36: Remove (obsolete) alphatype from SkColorTable 51 // V37: Added shadow only option to SkDropShadowImageFilter (last version to record CLEAR) 52 // V38: Added PictureResolution option to SkPictureImageFilter 53 // V39: Added FilterLevel option to SkPictureImageFilter 54 // V40: Remove UniqueID serialization from SkImageFilter. 55 // V41: Added serialization of SkBitmapSource's filterQuality parameter 56 // V42: Added a bool to SkPictureShader serialization to indicate did-we-serialize-a-picture? 57 // V43: Added DRAW_IMAGE and DRAW_IMAGE_RECT opt codes to serialized data 58 // V44: Move annotations from paint to drawAnnotation 59 // V45: Add invNormRotation to SkLightingShader. 60 // V46: Add drawTextRSXform 61 // V47: Add occluder rect to SkBlurMaskFilter 62 // V48: Read and write extended SkTextBlobs. 63 // V49: Gradients serialized as SkColor4f + SkColorSpace 64 // V50: SkXfermode -> SkBlendMode 65 // V51: more SkXfermode -> SkBlendMode 66 // V52: Remove SkTextBlob::fRunCount 67 // V53: SaveLayerRec clip mask 68 // V54: ComposeShader can use a Mode or a Lerp 69 // V55: Drop blendmode[] from MergeImageFilter 70 // V56: Add TileMode in SkBlurImageFilter. 71 // V57: Sweep tiling info. 72 // V58: No more 2pt conical flipping. 73 // V59: No more LocalSpace option on PictureImageFilter 74 // V60: Remove flags in picture header 75 // V61: Change SkDrawPictureRec to take two colors rather than two alphas 76 // V62: Don't negate size of custom encoded images (don't write origin x,y either) 77 // V63: Store image bounds (including origin) instead of just width/height to support subsets 78 // V64: Remove occluder feature from blur maskFilter 79 // V65: Float4 paint color 80 // V66: Add saveBehind 81 // V67: Blobs serialize fonts instead of paints 82 // V68: Paint doesn't serialize font-related stuff 83 // V69: Clean up duplicated and redundant SkImageFilter related enums 84 // V70: Image filters definitions hidden, registered names updated to include "Impl" 85 // V71: Unify erode and dilate image filters 86 // V72: SkColorFilter_Matrix domain (rgba vs. hsla) 87 // V73: Use SkColor4f in per-edge AA quad API 88 // V74: MorphologyImageFilter internal radius is SkScaler 89 // V75: SkVertices switched from unsafe use of SkReader32 to SkReadBuffer (like everything else) 90 // V76: Add filtering enum to ImageShader 91 // V77: Explicit filtering options on imageshaders 92 // V78: Serialize skmipmap data for images that have it 93 // V79: Cubic Resampler option on imageshader 94 // V80: Smapling options on imageshader 95 // V81: sampling parameters on drawImage/drawImageRect/etc. 96 // V82: Add filter param to picture-shader 97 // V83: SkMatrixImageFilter now takes SkSamplingOptions instead of SkFilterQuality 98 // V84: SkImageFilters::Image now takes SkSamplingOptions instead of SkFilterQuality 99 // V85: Remove legacy support for inheriting sampling from the paint. 100 // V86: Remove support for custom data inside SkVertices 101 // V87: SkPaint now holds a user-defined blend function (SkBlender), no longer has DrawLooper 102 // V88: Add blender to ComposeShader and BlendImageFilter 103 // V89: Deprecated SkClipOps are no longer supported 104 // V90: Private API for backdrop scale factor in SaveLayerRec 105 // V91: Added raw image shaders 106 // V92: Added anisotropic filtering to SkSamplingOptions 107 // V94: Removed local matrices from SkShaderBase. Local matrices always use SkLocalMatrixShader. 108 // V95: SkImageFilters::Shader only saves SkShader, not a full SkPaint 109 110 enum Version { 111 kPictureShaderFilterParam_Version = 82, 112 kMatrixImageFilterSampling_Version = 83, 113 kImageFilterImageSampling_Version = 84, 114 kNoFilterQualityShaders_Version = 85, 115 kVerticesRemoveCustomData_Version = 86, 116 kSkBlenderInSkPaint = 87, 117 kBlenderInEffects = 88, 118 kNoExpandingClipOps = 89, 119 kBackdropScaleFactor = 90, 120 kRawImageShaders = 91, 121 kAnisotropicFilter = 92, 122 kBlend4fColorFilter = 93, 123 kNoShaderLocalMatrix = 94, 124 kShaderImageFilterSerializeShader = 95, 125 126 // Only SKPs within the min/current picture version range (inclusive) can be read. 127 // 128 // When updating kMin_Version also update oldestSupportedSkpVersion in 129 // infra/bots/gen_tasks_logic/gen_tasks_logic.go 130 // 131 // Steps on how to find which oldestSupportedSkpVersion to use: 132 // 1) Find the git hash when the desired kMin_Version was the kCurrent_Version from the 133 // git logs: https://skia.googlesource.com/skia/+log/main/src/core/SkPicturePriv.h 134 // Eg: https://skia.googlesource.com/skia/+/bfd330d081952424a93d51715653e4d1314d4822%5E%21/#F1 135 // 136 // 2) Use that git hash to find the SKP asset version number at that time here: 137 // https://skia.googlesource.com/skia/+/bfd330d081952424a93d51715653e4d1314d4822/infra/bots/assets/skp/VERSION 138 // 139 // 3) [Optional] Increment the SKP asset version number from step 3 and verify that it has 140 // the expected version number by downloading the asset and running skpinfo on it. 141 // 142 // 4) Use the incremented SKP asset version number as the oldestSupportedSkpVersion in 143 // infra/bots/gen_tasks_logic/gen_tasks_logic.go 144 // 145 // 5) Run `make -C infra/bots train` 146 // 147 // Contact the Infra Gardener (or directly ping rmistry@) if the above steps do not work 148 // for you. 149 kMin_Version = kPictureShaderFilterParam_Version, 150 kCurrent_Version = kShaderImageFilterSerializeShader 151 }; 152 }; 153 154 bool SkPicture_StreamIsSKP(SkStream*, SkPictInfo*); 155 156 #endif 157