1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2011 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci#ifndef SkPictureFlat_DEFINED 8cb93a386Sopenharmony_ci#define SkPictureFlat_DEFINED 9cb93a386Sopenharmony_ci 10cb93a386Sopenharmony_ci#include "include/core/SkCanvas.h" 11cb93a386Sopenharmony_ci#include "include/core/SkPaint.h" 12cb93a386Sopenharmony_ci#include "include/core/SkPicture.h" 13cb93a386Sopenharmony_ci#include "include/private/SkChecksum.h" 14cb93a386Sopenharmony_ci#include "src/core/SkPtrRecorder.h" 15cb93a386Sopenharmony_ci#include "src/core/SkReadBuffer.h" 16cb93a386Sopenharmony_ci#include "src/core/SkTDynamicHash.h" 17cb93a386Sopenharmony_ci#include "src/core/SkWriteBuffer.h" 18cb93a386Sopenharmony_ci 19cb93a386Sopenharmony_ci/* 20cb93a386Sopenharmony_ci * Note: While adding new DrawTypes, it is necessary to add to the end of this list 21cb93a386Sopenharmony_ci * and update LAST_DRAWTYPE_ENUM to avoid having the code read older skps wrong. 22cb93a386Sopenharmony_ci * (which can cause segfaults) 23cb93a386Sopenharmony_ci * 24cb93a386Sopenharmony_ci * Reordering can be done during version updates. 25cb93a386Sopenharmony_ci */ 26cb93a386Sopenharmony_cienum DrawType { 27cb93a386Sopenharmony_ci UNUSED, 28cb93a386Sopenharmony_ci CLIP_PATH, 29cb93a386Sopenharmony_ci CLIP_REGION, 30cb93a386Sopenharmony_ci CLIP_RECT, 31cb93a386Sopenharmony_ci CLIP_RRECT, 32cb93a386Sopenharmony_ci CONCAT, 33cb93a386Sopenharmony_ci DRAW_BITMAP_RETIRED_2016_REMOVED_2018, 34cb93a386Sopenharmony_ci DRAW_BITMAP_MATRIX_RETIRED_2016_REMOVED_2018, 35cb93a386Sopenharmony_ci DRAW_BITMAP_NINE_RETIRED_2016_REMOVED_2018, 36cb93a386Sopenharmony_ci DRAW_BITMAP_RECT_RETIRED_2016_REMOVED_2018, 37cb93a386Sopenharmony_ci DRAW_CLEAR, 38cb93a386Sopenharmony_ci DRAW_DATA, 39cb93a386Sopenharmony_ci DRAW_OVAL, 40cb93a386Sopenharmony_ci DRAW_PAINT, 41cb93a386Sopenharmony_ci DRAW_PATH, 42cb93a386Sopenharmony_ci DRAW_PICTURE, 43cb93a386Sopenharmony_ci DRAW_POINTS, 44cb93a386Sopenharmony_ci DRAW_POS_TEXT_REMOVED_1_2019, 45cb93a386Sopenharmony_ci DRAW_POS_TEXT_TOP_BOTTOM_REMOVED_1_2019, 46cb93a386Sopenharmony_ci DRAW_POS_TEXT_H_REMOVED_1_2019, 47cb93a386Sopenharmony_ci DRAW_POS_TEXT_H_TOP_BOTTOM_REMOVED_1_2019, 48cb93a386Sopenharmony_ci DRAW_RECT, 49cb93a386Sopenharmony_ci DRAW_RRECT, 50cb93a386Sopenharmony_ci DRAW_SPRITE_RETIRED_2015_REMOVED_2018, 51cb93a386Sopenharmony_ci DRAW_TEXT_REMOVED_1_2019, 52cb93a386Sopenharmony_ci DRAW_TEXT_ON_PATH_RETIRED_08_2018_REMOVED_10_2018, 53cb93a386Sopenharmony_ci DRAW_TEXT_TOP_BOTTOM_REMOVED_1_2019, 54cb93a386Sopenharmony_ci DRAW_VERTICES_RETIRED_03_2017_REMOVED_01_2018, 55cb93a386Sopenharmony_ci RESTORE, 56cb93a386Sopenharmony_ci ROTATE, 57cb93a386Sopenharmony_ci SAVE, 58cb93a386Sopenharmony_ci SAVE_LAYER_SAVEFLAGS_DEPRECATED_2015_REMOVED_12_2020, 59cb93a386Sopenharmony_ci SCALE, 60cb93a386Sopenharmony_ci SET_MATRIX, 61cb93a386Sopenharmony_ci SKEW, 62cb93a386Sopenharmony_ci TRANSLATE, 63cb93a386Sopenharmony_ci NOOP, 64cb93a386Sopenharmony_ci BEGIN_COMMENT_GROUP_obsolete, 65cb93a386Sopenharmony_ci COMMENT_obsolete, 66cb93a386Sopenharmony_ci END_COMMENT_GROUP_obsolete, 67cb93a386Sopenharmony_ci 68cb93a386Sopenharmony_ci // new ops -- feel free to re-alphabetize on next version bump 69cb93a386Sopenharmony_ci DRAW_DRRECT, 70cb93a386Sopenharmony_ci PUSH_CULL, // deprecated, M41 was last Chromium version to write this to an .skp 71cb93a386Sopenharmony_ci POP_CULL, // deprecated, M41 was last Chromium version to write this to an .skp 72cb93a386Sopenharmony_ci 73cb93a386Sopenharmony_ci DRAW_PATCH, // could not add in aphabetical order 74cb93a386Sopenharmony_ci DRAW_PICTURE_MATRIX_PAINT, 75cb93a386Sopenharmony_ci DRAW_TEXT_BLOB, 76cb93a386Sopenharmony_ci DRAW_IMAGE, 77cb93a386Sopenharmony_ci DRAW_IMAGE_RECT_STRICT_obsolete, 78cb93a386Sopenharmony_ci DRAW_ATLAS, 79cb93a386Sopenharmony_ci DRAW_IMAGE_NINE, 80cb93a386Sopenharmony_ci DRAW_IMAGE_RECT, 81cb93a386Sopenharmony_ci 82cb93a386Sopenharmony_ci SAVE_LAYER_SAVELAYERFLAGS_DEPRECATED_JAN_2016_REMOVED_01_2018, 83cb93a386Sopenharmony_ci SAVE_LAYER_SAVELAYERREC, 84cb93a386Sopenharmony_ci 85cb93a386Sopenharmony_ci DRAW_ANNOTATION, 86cb93a386Sopenharmony_ci DRAW_DRAWABLE, 87cb93a386Sopenharmony_ci DRAW_DRAWABLE_MATRIX, 88cb93a386Sopenharmony_ci DRAW_TEXT_RSXFORM_DEPRECATED_DEC_2018, 89cb93a386Sopenharmony_ci 90cb93a386Sopenharmony_ci TRANSLATE_Z, // deprecated (M60) 91cb93a386Sopenharmony_ci 92cb93a386Sopenharmony_ci DRAW_SHADOW_REC, 93cb93a386Sopenharmony_ci DRAW_IMAGE_LATTICE, 94cb93a386Sopenharmony_ci DRAW_ARC, 95cb93a386Sopenharmony_ci DRAW_REGION, 96cb93a386Sopenharmony_ci DRAW_VERTICES_OBJECT, 97cb93a386Sopenharmony_ci 98cb93a386Sopenharmony_ci FLUSH, 99cb93a386Sopenharmony_ci 100cb93a386Sopenharmony_ci DRAW_EDGEAA_IMAGE_SET, 101cb93a386Sopenharmony_ci 102cb93a386Sopenharmony_ci SAVE_BEHIND, 103cb93a386Sopenharmony_ci 104cb93a386Sopenharmony_ci DRAW_EDGEAA_QUAD, 105cb93a386Sopenharmony_ci 106cb93a386Sopenharmony_ci DRAW_BEHIND_PAINT, 107cb93a386Sopenharmony_ci CONCAT44, 108cb93a386Sopenharmony_ci CLIP_SHADER_IN_PAINT, 109cb93a386Sopenharmony_ci MARK_CTM, 110cb93a386Sopenharmony_ci SET_M44, 111cb93a386Sopenharmony_ci 112cb93a386Sopenharmony_ci DRAW_IMAGE2, 113cb93a386Sopenharmony_ci DRAW_IMAGE_RECT2, 114cb93a386Sopenharmony_ci DRAW_IMAGE_LATTICE2, 115cb93a386Sopenharmony_ci DRAW_EDGEAA_IMAGE_SET2, 116cb93a386Sopenharmony_ci 117cb93a386Sopenharmony_ci RESET_CLIP, 118cb93a386Sopenharmony_ci 119cb93a386Sopenharmony_ci LAST_DRAWTYPE_ENUM = RESET_CLIP, 120cb93a386Sopenharmony_ci}; 121cb93a386Sopenharmony_ci 122cb93a386Sopenharmony_cienum DrawVertexFlags { 123cb93a386Sopenharmony_ci DRAW_VERTICES_HAS_TEXS = 0x01, 124cb93a386Sopenharmony_ci DRAW_VERTICES_HAS_COLORS = 0x02, 125cb93a386Sopenharmony_ci DRAW_VERTICES_HAS_INDICES = 0x04, 126cb93a386Sopenharmony_ci DRAW_VERTICES_HAS_XFER = 0x08, 127cb93a386Sopenharmony_ci}; 128cb93a386Sopenharmony_ci 129cb93a386Sopenharmony_cienum DrawAtlasFlags { 130cb93a386Sopenharmony_ci DRAW_ATLAS_HAS_COLORS = 1 << 0, 131cb93a386Sopenharmony_ci DRAW_ATLAS_HAS_CULL = 1 << 1, 132cb93a386Sopenharmony_ci DRAW_ATLAS_HAS_SAMPLING = 1 << 2, 133cb93a386Sopenharmony_ci}; 134cb93a386Sopenharmony_ci 135cb93a386Sopenharmony_cienum DrawTextRSXformFlags { 136cb93a386Sopenharmony_ci DRAW_TEXT_RSXFORM_HAS_CULL = 1 << 0, 137cb93a386Sopenharmony_ci}; 138cb93a386Sopenharmony_ci 139cb93a386Sopenharmony_cienum SaveLayerRecFlatFlags { 140cb93a386Sopenharmony_ci SAVELAYERREC_HAS_BOUNDS = 1 << 0, 141cb93a386Sopenharmony_ci SAVELAYERREC_HAS_PAINT = 1 << 1, 142cb93a386Sopenharmony_ci SAVELAYERREC_HAS_BACKDROP = 1 << 2, 143cb93a386Sopenharmony_ci SAVELAYERREC_HAS_FLAGS = 1 << 3, 144cb93a386Sopenharmony_ci SAVELAYERREC_HAS_CLIPMASK_OBSOLETE = 1 << 4, // 6/13/2020 145cb93a386Sopenharmony_ci SAVELAYERREC_HAS_CLIPMATRIX_OBSOLETE = 1 << 5, // 6/13/2020 146cb93a386Sopenharmony_ci SAVELAYERREC_HAS_BACKDROP_SCALE = 1 << 6 147cb93a386Sopenharmony_ci}; 148cb93a386Sopenharmony_ci 149cb93a386Sopenharmony_cienum SaveBehindFlatFlags { 150cb93a386Sopenharmony_ci SAVEBEHIND_HAS_SUBSET = 1 << 0, 151cb93a386Sopenharmony_ci}; 152cb93a386Sopenharmony_ci 153cb93a386Sopenharmony_ci/////////////////////////////////////////////////////////////////////////////// 154cb93a386Sopenharmony_ci// clipparams are packed in 5 bits 155cb93a386Sopenharmony_ci// doAA:1 | clipOp:4 156cb93a386Sopenharmony_ci 157cb93a386Sopenharmony_ci// Newly serialized pictures will only write kIntersect or kDifference. 158cb93a386Sopenharmony_cistatic inline uint32_t ClipParams_pack(SkClipOp op, bool doAA) { 159cb93a386Sopenharmony_ci unsigned doAABit = doAA ? 1 : 0; 160cb93a386Sopenharmony_ci return (doAABit << 4) | static_cast<int>(op); 161cb93a386Sopenharmony_ci} 162cb93a386Sopenharmony_ci 163cb93a386Sopenharmony_ci// But old SKPs may have been serialized with the SK_SUPPORT_DEPRECATED_CLIPOP flag, so might 164cb93a386Sopenharmony_ci// encounter expanding clip ops. Thus, this returns the clip op as the more general Region::Op. 165cb93a386Sopenharmony_cistatic inline SkRegion::Op ClipParams_unpackRegionOp(SkReadBuffer* buffer, uint32_t packed) { 166cb93a386Sopenharmony_ci uint32_t unpacked = packed & 0xF; 167cb93a386Sopenharmony_ci if (buffer->validate(unpacked <= SkRegion::kIntersect_Op || 168cb93a386Sopenharmony_ci (unpacked <= SkRegion::kReplace_Op && 169cb93a386Sopenharmony_ci buffer->isVersionLT(SkPicturePriv::kNoExpandingClipOps)))) { 170cb93a386Sopenharmony_ci return static_cast<SkRegion::Op>(unpacked); 171cb93a386Sopenharmony_ci } 172cb93a386Sopenharmony_ci return SkRegion::kIntersect_Op; 173cb93a386Sopenharmony_ci} 174cb93a386Sopenharmony_ci 175cb93a386Sopenharmony_cistatic inline bool ClipParams_unpackDoAA(uint32_t packed) { 176cb93a386Sopenharmony_ci return SkToBool((packed >> 4) & 1); 177cb93a386Sopenharmony_ci} 178cb93a386Sopenharmony_ci 179cb93a386Sopenharmony_ci/////////////////////////////////////////////////////////////////////////////// 180cb93a386Sopenharmony_ci 181cb93a386Sopenharmony_ciclass SkTypefacePlayback { 182cb93a386Sopenharmony_cipublic: 183cb93a386Sopenharmony_ci SkTypefacePlayback() : fCount(0), fArray(nullptr) {} 184cb93a386Sopenharmony_ci ~SkTypefacePlayback() = default; 185cb93a386Sopenharmony_ci 186cb93a386Sopenharmony_ci void setCount(size_t count); 187cb93a386Sopenharmony_ci 188cb93a386Sopenharmony_ci size_t count() const { return fCount; } 189cb93a386Sopenharmony_ci 190cb93a386Sopenharmony_ci sk_sp<SkTypeface>& operator[](size_t index) { 191cb93a386Sopenharmony_ci SkASSERT(index < fCount); 192cb93a386Sopenharmony_ci return fArray[index]; 193cb93a386Sopenharmony_ci } 194cb93a386Sopenharmony_ci 195cb93a386Sopenharmony_ci void setupBuffer(SkReadBuffer& buffer) const { 196cb93a386Sopenharmony_ci buffer.setTypefaceArray(fArray.get(), fCount); 197cb93a386Sopenharmony_ci } 198cb93a386Sopenharmony_ci 199cb93a386Sopenharmony_ciprotected: 200cb93a386Sopenharmony_ci size_t fCount; 201cb93a386Sopenharmony_ci std::unique_ptr<sk_sp<SkTypeface>[]> fArray; 202cb93a386Sopenharmony_ci}; 203cb93a386Sopenharmony_ci 204cb93a386Sopenharmony_ciclass SkFactoryPlayback { 205cb93a386Sopenharmony_cipublic: 206cb93a386Sopenharmony_ci SkFactoryPlayback(int count) : fCount(count) { fArray = new SkFlattenable::Factory[count]; } 207cb93a386Sopenharmony_ci 208cb93a386Sopenharmony_ci ~SkFactoryPlayback() { delete[] fArray; } 209cb93a386Sopenharmony_ci 210cb93a386Sopenharmony_ci SkFlattenable::Factory* base() const { return fArray; } 211cb93a386Sopenharmony_ci 212cb93a386Sopenharmony_ci void setupBuffer(SkReadBuffer& buffer) const { 213cb93a386Sopenharmony_ci buffer.setFactoryPlayback(fArray, fCount); 214cb93a386Sopenharmony_ci } 215cb93a386Sopenharmony_ci 216cb93a386Sopenharmony_ciprivate: 217cb93a386Sopenharmony_ci int fCount; 218cb93a386Sopenharmony_ci SkFlattenable::Factory* fArray; 219cb93a386Sopenharmony_ci}; 220cb93a386Sopenharmony_ci 221cb93a386Sopenharmony_ci#endif 222