epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 | */ |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 7 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #ifndef SkPictureRecord_DEFINED |
| 9 | #define SkPictureRecord_DEFINED |
| 10 | |
| 11 | #include "SkCanvas.h" |
| 12 | #include "SkFlattenable.h" |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 13 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 14 | #include "SkMatrixClipStateMgr.h" |
| 15 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 16 | #include "SkPathHeap.h" |
| 17 | #include "SkPicture.h" |
| 18 | #include "SkPictureFlat.h" |
| 19 | #include "SkTemplates.h" |
| 20 | #include "SkWriter32.h" |
| 21 | |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 22 | class SkBBoxHierarchy; |
commit-bot@chromium.org | 8016f79 | 2014-03-07 15:53:01 +0000 | [diff] [blame] | 23 | class SkOffsetTable; |
| 24 | class SkPictureStateTree; |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 25 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 26 | // These macros help with packing and unpacking a single byte value and |
| 27 | // a 3 byte value into/out of a uint32_t |
| 28 | #define MASK_24 0x00FFFFFF |
| 29 | #define UNPACK_8_24(combined, small, large) \ |
| 30 | small = (combined >> 24) & 0xFF; \ |
| 31 | large = combined & MASK_24; |
| 32 | #define PACK_8_24(small, large) ((small << 24) | large) |
| 33 | |
| 34 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 35 | class SkPictureRecord : public SkCanvas { |
| 36 | public: |
commit-bot@chromium.org | 19fafef | 2014-02-17 15:28:00 +0000 | [diff] [blame] | 37 | SkPictureRecord(const SkISize& dimensions, uint32_t recordFlags); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | virtual ~SkPictureRecord(); |
| 39 | |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 40 | virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE; |
| 41 | virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE; |
| 42 | virtual bool rotate(SkScalar degrees) SK_OVERRIDE; |
| 43 | virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE; |
| 44 | virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE; |
| 45 | virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE; |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 46 | virtual void clear(SkColor) SK_OVERRIDE; |
| 47 | virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 48 | virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 49 | const SkPaint&) SK_OVERRIDE; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 50 | virtual void drawOval(const SkRect&, const SkPaint&) SK_OVERRIDE; |
bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame] | 51 | virtual void drawRect(const SkRect&, const SkPaint&) SK_OVERRIDE; |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 52 | virtual void drawRRect(const SkRRect&, const SkPaint&) SK_OVERRIDE; |
bsalomon@google.com | 7ce564c | 2013-10-22 16:54:15 +0000 | [diff] [blame] | 53 | virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 54 | virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 55 | const SkPaint*) SK_OVERRIDE; |
reed@google.com | 7112173 | 2012-09-18 15:14:33 +0000 | [diff] [blame] | 56 | virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src, |
skia.committer@gmail.com | 7475811 | 2013-08-17 07:01:54 +0000 | [diff] [blame] | 57 | const SkRect& dst, const SkPaint* paint, |
commit-bot@chromium.org | eed779d | 2013-08-16 10:24:37 +0000 | [diff] [blame] | 58 | DrawBitmapRectFlags flags) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 59 | virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 60 | const SkPaint*) SK_OVERRIDE; |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 61 | virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 62 | const SkRect& dst, const SkPaint*) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 63 | virtual void drawSprite(const SkBitmap&, int left, int top, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 64 | const SkPaint*) SK_OVERRIDE; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 65 | virtual void drawText(const void* text, size_t byteLength, SkScalar x, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 66 | SkScalar y, const SkPaint&) SK_OVERRIDE; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 67 | virtual void drawPosText(const void* text, size_t byteLength, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 68 | const SkPoint pos[], const SkPaint&) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 69 | virtual void drawPosTextH(const void* text, size_t byteLength, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 70 | const SkScalar xpos[], SkScalar constY, const SkPaint&) SK_OVERRIDE; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 71 | virtual void drawTextOnPath(const void* text, size_t byteLength, |
| 72 | const SkPath& path, const SkMatrix* matrix, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 73 | const SkPaint&) SK_OVERRIDE; |
| 74 | virtual void drawPicture(SkPicture& picture) SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 75 | virtual void drawVertices(VertexMode, int vertexCount, |
| 76 | const SkPoint vertices[], const SkPoint texs[], |
| 77 | const SkColor colors[], SkXfermode*, |
| 78 | const uint16_t indices[], int indexCount, |
reed@google.com | 2d4297c | 2011-10-06 13:14:12 +0000 | [diff] [blame] | 79 | const SkPaint&) SK_OVERRIDE; |
| 80 | virtual void drawData(const void*, size_t) SK_OVERRIDE; |
robertphillips@google.com | 0a4805e | 2013-05-29 13:24:23 +0000 | [diff] [blame] | 81 | virtual void beginCommentGroup(const char* description) SK_OVERRIDE; |
| 82 | virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; |
| 83 | virtual void endCommentGroup() SK_OVERRIDE; |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 84 | virtual bool isDrawingToLayer() const SK_OVERRIDE; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 85 | |
junov@chromium.org | 3f5ecd6 | 2013-01-22 18:01:26 +0000 | [diff] [blame] | 86 | void addFontMetricsTopBottom(const SkPaint& paint, const SkFlatData&, |
reed@google.com | 4595426 | 2012-12-07 17:14:40 +0000 | [diff] [blame] | 87 | SkScalar minY, SkScalar maxY); |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 88 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 89 | const SkTDArray<SkPicture* >& getPictureRefs() const { |
| 90 | return fPictureRefs; |
| 91 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 92 | |
junov@chromium.org | 4866cc0 | 2012-06-01 21:23:07 +0000 | [diff] [blame] | 93 | void setFlags(uint32_t recordFlags) { |
| 94 | fRecordFlags = recordFlags; |
| 95 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 96 | |
| 97 | const SkWriter32& writeStream() const { |
| 98 | return fWriter; |
| 99 | } |
| 100 | |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 101 | void beginRecording(); |
junov@chromium.org | a6c9e0e | 2012-07-12 17:47:34 +0000 | [diff] [blame] | 102 | void endRecording(); |
reed@google.com | d86e7ab | 2012-09-27 20:31:31 +0000 | [diff] [blame] | 103 | |
commit-bot@chromium.org | e494dbd | 2014-03-04 19:08:57 +0000 | [diff] [blame] | 104 | void internalOnly_EnableOpts(bool optsEnabled) { |
| 105 | fOptsEnabled = optsEnabled; |
| 106 | } |
| 107 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 108 | private: |
commit-bot@chromium.org | 4b32bd5 | 2013-03-15 15:06:03 +0000 | [diff] [blame] | 109 | void handleOptimization(int opt); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 110 | int recordRestoreOffsetPlaceholder(SkRegion::Op); |
| 111 | void fillRestoreOffsetPlaceholdersForCurrentStackLevel(uint32_t restoreOffset); |
junov@chromium.org | e3dbedb | 2012-07-09 16:03:55 +0000 | [diff] [blame] | 112 | |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 113 | #ifndef SK_COLLAPSE_MATRIX_CLIP_STATE |
reed@google.com | ffacd3c | 2012-08-30 15:31:23 +0000 | [diff] [blame] | 114 | SkTDArray<int32_t> fRestoreOffsetStack; |
junov@chromium.org | 8f9ecbd | 2012-02-13 21:53:45 +0000 | [diff] [blame] | 115 | int fFirstSavedLayerIndex; |
| 116 | enum { |
| 117 | kNoSavedLayerIndex = -1 |
| 118 | }; |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 119 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 120 | |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 121 | SkTDArray<uint32_t> fCullOffsetStack; |
| 122 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 123 | /* |
| 124 | * Write the 'drawType' operation and chunk size to the skp. 'size' |
skia.committer@gmail.com | ce8343d | 2013-02-16 07:01:31 +0000 | [diff] [blame] | 125 | * can potentially be increased if the chunk size needs its own storage |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 126 | * location (i.e., it overflows 24 bits). |
| 127 | * Returns the start offset of the chunk. This is the location at which |
| 128 | * the opcode & size are stored. |
skia.committer@gmail.com | ce8343d | 2013-02-16 07:01:31 +0000 | [diff] [blame] | 129 | * TODO: since we are handing the size into here we could call reserve |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 130 | * and then return a pointer to the memory storage. This could decrease |
| 131 | * allocation overhead but could lead to more wasted space (the tail |
| 132 | * end of blocks could go unused). Possibly add a second addDraw that |
| 133 | * operates in this manner. |
| 134 | */ |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 135 | size_t addDraw(DrawType drawType, uint32_t* size) { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 136 | size_t offset = fWriter.bytesWritten(); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 137 | |
reed@google.com | 97af1a6 | 2012-08-28 12:19:02 +0000 | [diff] [blame] | 138 | this->predrawNotify(); |
| 139 | |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 140 | #ifdef SK_DEBUG_TRACE |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 141 | SkDebugf("add %s\n", DrawTypeToString(drawType)); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 142 | #endif |
| 143 | |
| 144 | SkASSERT(0 != *size); |
| 145 | SkASSERT(((uint8_t) drawType) == drawType); |
| 146 | |
| 147 | if (0 != (*size & ~MASK_24) || *size == MASK_24) { |
| 148 | fWriter.writeInt(PACK_8_24(drawType, MASK_24)); |
| 149 | *size += 1; |
| 150 | fWriter.writeInt(*size); |
| 151 | } else { |
| 152 | fWriter.writeInt(PACK_8_24(drawType, *size)); |
| 153 | } |
| 154 | |
| 155 | return offset; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 156 | } |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 157 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 158 | void addInt(int value) { |
| 159 | fWriter.writeInt(value); |
| 160 | } |
| 161 | void addScalar(SkScalar scalar) { |
| 162 | fWriter.writeScalar(scalar); |
| 163 | } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 164 | |
commit-bot@chromium.org | 8016f79 | 2014-03-07 15:53:01 +0000 | [diff] [blame] | 165 | // The command at 'offset' in the skp uses the specified bitmap |
| 166 | void trackBitmapUse(int bitmapID, size_t offset); |
| 167 | int addBitmap(const SkBitmap& bitmap); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 168 | void addMatrix(const SkMatrix& matrix); |
junov@chromium.org | f3b1223 | 2013-01-22 17:50:47 +0000 | [diff] [blame] | 169 | const SkFlatData* addPaint(const SkPaint& paint) { return this->addPaintPtr(&paint); } |
| 170 | const SkFlatData* addPaintPtr(const SkPaint* paint); |
commit-bot@chromium.org | cf7be95 | 2013-08-22 17:19:52 +0000 | [diff] [blame] | 171 | void addFlatPaint(const SkFlatData* flatPaint); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 172 | void addPath(const SkPath& path); |
| 173 | void addPicture(SkPicture& picture); |
| 174 | void addPoint(const SkPoint& point); |
| 175 | void addPoints(const SkPoint pts[], int count); |
| 176 | void addRect(const SkRect& rect); |
| 177 | void addRectPtr(const SkRect* rect); |
reed@google.com | f0b5e11 | 2011-09-07 11:57:34 +0000 | [diff] [blame] | 178 | void addIRect(const SkIRect& rect); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 179 | void addIRectPtr(const SkIRect* rect); |
reed@google.com | 4ed0fb7 | 2012-12-12 20:48:18 +0000 | [diff] [blame] | 180 | void addRRect(const SkRRect&); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 181 | void addRegion(const SkRegion& region); |
| 182 | void addText(const void* text, size_t byteLength); |
| 183 | |
junov@chromium.org | 4866cc0 | 2012-06-01 21:23:07 +0000 | [diff] [blame] | 184 | int find(const SkBitmap& bitmap); |
| 185 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 186 | #ifdef SK_DEBUG_DUMP |
| 187 | public: |
| 188 | void dumpMatrices(); |
| 189 | void dumpPaints(); |
| 190 | #endif |
| 191 | |
| 192 | #ifdef SK_DEBUG_SIZE |
| 193 | public: |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 194 | size_t size() const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 195 | int bitmaps(size_t* size) const; |
| 196 | int matrices(size_t* size) const; |
| 197 | int paints(size_t* size) const; |
| 198 | int paths(size_t* size) const; |
| 199 | int regions(size_t* size) const; |
| 200 | size_t streamlen() const; |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame] | 201 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 202 | size_t fPointBytes, fRectBytes, fTextBytes; |
| 203 | int fPointWrites, fRectWrites, fTextWrites; |
| 204 | #endif |
| 205 | |
| 206 | #ifdef SK_DEBUG_VALIDATE |
| 207 | public: |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 208 | void validate(size_t initialOffset, uint32_t size) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 209 | private: |
| 210 | void validateBitmaps() const; |
| 211 | void validateMatrices() const; |
| 212 | void validatePaints() const; |
| 213 | void validatePaths() const; |
| 214 | void validateRegions() const; |
| 215 | #else |
| 216 | public: |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 217 | void validate(size_t initialOffset, uint32_t size) const { |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 218 | SkASSERT(fWriter.bytesWritten() == initialOffset + size); |
robertphillips@google.com | 2ca1aaa | 2013-02-15 13:47:37 +0000 | [diff] [blame] | 219 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 220 | #endif |
| 221 | |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 222 | protected: |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 223 | virtual SkSurface* onNewSurface(const SkImageInfo&) SK_OVERRIDE; |
commit-bot@chromium.org | c3bd8af | 2014-02-13 17:14:46 +0000 | [diff] [blame] | 224 | const void* onPeekPixels(SkImageInfo*, size_t*) SK_OVERRIDE { |
| 225 | return NULL; |
| 226 | } |
commit-bot@chromium.org | e54a23f | 2014-03-12 20:21:48 +0000 | [diff] [blame^] | 227 | |
| 228 | virtual void willSave(SaveFlags) SK_OVERRIDE; |
| 229 | virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE; |
| 230 | virtual void willRestore() SK_OVERRIDE; |
| 231 | |
commit-bot@chromium.org | ed9806f | 2014-02-21 02:32:36 +0000 | [diff] [blame] | 232 | virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; |
commit-bot@chromium.org | 210ae2a | 2014-02-27 17:40:13 +0000 | [diff] [blame] | 233 | virtual void onPushCull(const SkRect&) SK_OVERRIDE; |
| 234 | virtual void onPopCull() SK_OVERRIDE; |
reed@google.com | 76f10a3 | 2014-02-05 15:32:21 +0000 | [diff] [blame] | 235 | |
robertphillips@google.com | 8f90a89 | 2014-02-28 18:19:39 +0000 | [diff] [blame] | 236 | virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
| 237 | virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
| 238 | virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; |
| 239 | virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE; |
| 240 | |
commit-bot@chromium.org | cf7be95 | 2013-08-22 17:19:52 +0000 | [diff] [blame] | 241 | // Return fontmetrics.fTop,fBottom in topbot[0,1], after they have been |
| 242 | // tweaked by paint.computeFastBounds(). |
| 243 | static void ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar topbot[2]); |
| 244 | |
| 245 | // Make sure that flat has fTopBot written. |
| 246 | static void WriteTopBot(const SkPaint& paint, const SkFlatData& flat) { |
| 247 | if (!flat.isTopBotWritten()) { |
| 248 | ComputeFontMetricsTopBottom(paint, flat.writableTopBot()); |
| 249 | SkASSERT(flat.isTopBotWritten()); |
| 250 | } |
| 251 | } |
| 252 | // Will return a cached version when possible. |
| 253 | const SkFlatData* getFlatPaintData(const SkPaint& paint); |
| 254 | /** |
| 255 | * SkBBoxRecord::drawPosTextH gets a flat paint and uses it, |
| 256 | * then it calls this, using the extra parameter, to avoid duplication. |
| 257 | */ |
| 258 | void drawPosTextHImpl(const void* text, size_t byteLength, |
| 259 | const SkScalar xpos[], SkScalar constY, |
| 260 | const SkPaint& paint, const SkFlatData* flatPaintData); |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 261 | |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 262 | int addPathToHeap(const SkPath& path); // does not write to ops stream |
| 263 | |
skia.committer@gmail.com | 1dab403 | 2014-02-05 03:01:48 +0000 | [diff] [blame] | 264 | // These entry points allow the writing of matrices, clips, saves & |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 265 | // restores to be deferred (e.g., if the MC state is being collapsed and |
| 266 | // only written out as needed). |
| 267 | void recordConcat(const SkMatrix& matrix); |
| 268 | int recordClipRect(const SkRect& rect, SkRegion::Op op, bool doAA); |
| 269 | int recordClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA); |
| 270 | int recordClipPath(int pathID, SkRegion::Op op, bool doAA); |
| 271 | int recordClipRegion(const SkRegion& region, SkRegion::Op op); |
| 272 | void recordSave(SaveFlags flags); |
| 273 | void recordSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags); |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 274 | void recordRestore(bool fillInSkips = true); |
robertphillips@google.com | 5a63f24 | 2014-02-04 20:07:50 +0000 | [diff] [blame] | 275 | |
rileya@google.com | 9f5898d | 2012-09-11 20:21:44 +0000 | [diff] [blame] | 276 | // These are set to NULL in our constructor, but may be changed by |
| 277 | // subclasses, in which case they will be SkSafeUnref'd in our destructor. |
| 278 | SkBBoxHierarchy* fBoundingHierarchy; |
| 279 | SkPictureStateTree* fStateTree; |
| 280 | |
robertphillips@google.com | 801cee1 | 2012-10-19 19:06:11 +0000 | [diff] [blame] | 281 | // Allocated in the constructor and managed by this class. |
djsollen@google.com | c9ab987 | 2012-08-29 18:52:07 +0000 | [diff] [blame] | 282 | SkBitmapHeap* fBitmapHeap; |
robertphillips@google.com | 801cee1 | 2012-10-19 19:06:11 +0000 | [diff] [blame] | 283 | |
| 284 | private: |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 285 | friend class MatrixClipState; // for access to *Impl methods |
| 286 | friend class SkMatrixClipStateMgr; // for access to *Impl methods |
| 287 | |
djsollen@google.com | 21830d9 | 2012-08-07 19:49:41 +0000 | [diff] [blame] | 288 | SkChunkFlatController fFlattenableHeap; |
junov@chromium.org | 4866cc0 | 2012-06-01 21:23:07 +0000 | [diff] [blame] | 289 | |
djsollen@google.com | d2700ee | 2012-05-30 16:54:13 +0000 | [diff] [blame] | 290 | SkPaintDictionary fPaints; |
djsollen@google.com | d2700ee | 2012-05-30 16:54:13 +0000 | [diff] [blame] | 291 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 292 | SkPathHeap* fPathHeap; // reference counted |
| 293 | SkWriter32 fWriter; |
| 294 | |
reed@android.com | 09b84a0 | 2009-06-26 20:22:26 +0000 | [diff] [blame] | 295 | // we ref each item in these arrays |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 296 | SkTDArray<SkPicture*> fPictureRefs; |
| 297 | |
reed@android.com | ae814c8 | 2009-02-13 14:56:09 +0000 | [diff] [blame] | 298 | uint32_t fRecordFlags; |
commit-bot@chromium.org | e494dbd | 2014-03-04 19:08:57 +0000 | [diff] [blame] | 299 | bool fOptsEnabled; |
| 300 | int fInitialSaveCount; |
reed@android.com | ae814c8 | 2009-02-13 14:56:09 +0000 | [diff] [blame] | 301 | |
commit-bot@chromium.org | 8016f79 | 2014-03-07 15:53:01 +0000 | [diff] [blame] | 302 | SkAutoTUnref<SkOffsetTable> fBitmapUseOffsets; |
| 303 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 304 | friend class SkPicturePlayback; |
junov@chromium.org | 1cc8f6f | 2012-02-22 21:00:42 +0000 | [diff] [blame] | 305 | friend class SkPictureTester; // for unit testing |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 306 | |
robertphillips@google.com | 105a4a5 | 2014-02-11 15:10:40 +0000 | [diff] [blame] | 307 | #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 308 | SkMatrixClipStateMgr fMCMgr; |
| 309 | #endif |
| 310 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 311 | typedef SkCanvas INHERITED; |
| 312 | }; |
| 313 | |
| 314 | #endif |