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