| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkPictureRecord_DEFINED | 8 #ifndef SkPictureRecord_DEFINED |
| 9 #define SkPictureRecord_DEFINED | 9 #define SkPictureRecord_DEFINED |
| 10 | 10 |
| 11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
| 12 #include "SkFlattenable.h" | 12 #include "SkFlattenable.h" |
| 13 #include "SkPathHeap.h" | 13 #include "SkPathHeap.h" |
| 14 #include "SkPicture.h" | 14 #include "SkPicture.h" |
| 15 #include "SkPictureData.h" | 15 #include "SkPictureData.h" |
| 16 #include "SkPictureFlat.h" | 16 #include "SkPictureFlat.h" |
| 17 #include "SkTemplates.h" | 17 #include "SkTemplates.h" |
| 18 #include "SkWriter32.h" | 18 #include "SkWriter32.h" |
| 19 | 19 |
| 20 class SkBBoxHierarchy; | |
| 21 class SkPictureStateTree; | |
| 22 | |
| 23 // These macros help with packing and unpacking a single byte value and | 20 // These macros help with packing and unpacking a single byte value and |
| 24 // a 3 byte value into/out of a uint32_t | 21 // a 3 byte value into/out of a uint32_t |
| 25 #define MASK_24 0x00FFFFFF | 22 #define MASK_24 0x00FFFFFF |
| 26 #define UNPACK_8_24(combined, small, large) \ | 23 #define UNPACK_8_24(combined, small, large) \ |
| 27 small = (combined >> 24) & 0xFF; \ | 24 small = (combined >> 24) & 0xFF; \ |
| 28 large = combined & MASK_24; | 25 large = combined & MASK_24; |
| 29 #define PACK_8_24(small, large) ((small << 24) | large) | 26 #define PACK_8_24(small, large) ((small << 24) | large) |
| 30 | 27 |
| 31 | 28 |
| 32 class SkPictureRecord : public SkCanvas { | 29 class SkPictureRecord : public SkCanvas { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 57 const SkPoint vertices[], const SkPoint texs[], | 54 const SkPoint vertices[], const SkPoint texs[], |
| 58 const SkColor colors[], SkXfermode*, | 55 const SkColor colors[], SkXfermode*, |
| 59 const uint16_t indices[], int indexCount, | 56 const uint16_t indices[], int indexCount, |
| 60 const SkPaint&) SK_OVERRIDE; | 57 const SkPaint&) SK_OVERRIDE; |
| 61 virtual void drawData(const void*, size_t) SK_OVERRIDE; | 58 virtual void drawData(const void*, size_t) SK_OVERRIDE; |
| 62 virtual void beginCommentGroup(const char* description) SK_OVERRIDE; | 59 virtual void beginCommentGroup(const char* description) SK_OVERRIDE; |
| 63 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; | 60 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; |
| 64 virtual void endCommentGroup() SK_OVERRIDE; | 61 virtual void endCommentGroup() SK_OVERRIDE; |
| 65 virtual bool isDrawingToLayer() const SK_OVERRIDE; | 62 virtual bool isDrawingToLayer() const SK_OVERRIDE; |
| 66 | 63 |
| 67 void addFontMetricsTopBottom(const SkPaint& paint, const SkFlatData&, | |
| 68 SkScalar minY, SkScalar maxY); | |
| 69 | |
| 70 const SkTDArray<const SkPicture* >& getPictureRefs() const { | 64 const SkTDArray<const SkPicture* >& getPictureRefs() const { |
| 71 return fPictureRefs; | 65 return fPictureRefs; |
| 72 } | 66 } |
| 73 | 67 |
| 74 const SkTDArray<const SkTextBlob* >& getTextBlobRefs() const { | 68 const SkTDArray<const SkTextBlob* >& getTextBlobRefs() const { |
| 75 return fTextBlobRefs; | 69 return fTextBlobRefs; |
| 76 } | 70 } |
| 77 | 71 |
| 78 SkData* opData(bool deepCopy) const { | 72 SkData* opData(bool deepCopy) const { |
| 79 this->validate(fWriter.bytesWritten(), 0); | 73 this->validate(fWriter.bytesWritten(), 0); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 101 fRecordFlags = recordFlags; | 95 fRecordFlags = recordFlags; |
| 102 } | 96 } |
| 103 | 97 |
| 104 const SkWriter32& writeStream() const { | 98 const SkWriter32& writeStream() const { |
| 105 return fWriter; | 99 return fWriter; |
| 106 } | 100 } |
| 107 | 101 |
| 108 void beginRecording(); | 102 void beginRecording(); |
| 109 void endRecording(); | 103 void endRecording(); |
| 110 | 104 |
| 111 void internalOnly_EnableOpts(bool optsEnabled) { | |
| 112 fOptsEnabled = optsEnabled; | |
| 113 } | |
| 114 | |
| 115 protected: | 105 protected: |
| 116 void addNoOp(); | 106 void addNoOp(); |
| 117 | 107 |
| 118 private: | 108 private: |
| 119 void handleOptimization(int opt); | 109 void handleOptimization(int opt); |
| 120 size_t recordRestoreOffsetPlaceholder(SkRegion::Op); | 110 size_t recordRestoreOffsetPlaceholder(SkRegion::Op); |
| 121 void fillRestoreOffsetPlaceholdersForCurrentStackLevel(uint32_t restoreOffse
t); | 111 void fillRestoreOffsetPlaceholdersForCurrentStackLevel(uint32_t restoreOffse
t); |
| 122 | 112 |
| 123 SkTDArray<int32_t> fRestoreOffsetStack; | 113 SkTDArray<int32_t> fRestoreOffsetStack; |
| 124 int fFirstSavedLayerIndex; | 114 int fFirstSavedLayerIndex; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 void addInt(int value) { | 153 void addInt(int value) { |
| 164 fWriter.writeInt(value); | 154 fWriter.writeInt(value); |
| 165 } | 155 } |
| 166 void addScalar(SkScalar scalar) { | 156 void addScalar(SkScalar scalar) { |
| 167 fWriter.writeScalar(scalar); | 157 fWriter.writeScalar(scalar); |
| 168 } | 158 } |
| 169 | 159 |
| 170 // The command at 'offset' in the skp uses the specified bitmap | 160 // The command at 'offset' in the skp uses the specified bitmap |
| 171 int addBitmap(const SkBitmap& bitmap); | 161 int addBitmap(const SkBitmap& bitmap); |
| 172 void addMatrix(const SkMatrix& matrix); | 162 void addMatrix(const SkMatrix& matrix); |
| 173 const SkFlatData* addPaint(const SkPaint& paint) { return this->addPaintPtr(
&paint); } | 163 void addPaint(const SkPaint& paint) { this->addPaintPtr(&paint); } |
| 174 const SkFlatData* addPaintPtr(const SkPaint* paint); | 164 void addPaintPtr(const SkPaint* paint); |
| 175 void addFlatPaint(const SkFlatData* flatPaint); | |
| 176 void addPatch(const SkPoint cubics[12]); | 165 void addPatch(const SkPoint cubics[12]); |
| 177 void addPath(const SkPath& path); | 166 void addPath(const SkPath& path); |
| 178 void addPicture(const SkPicture* picture); | 167 void addPicture(const SkPicture* picture); |
| 179 void addPoint(const SkPoint& point); | 168 void addPoint(const SkPoint& point); |
| 180 void addPoints(const SkPoint pts[], int count); | 169 void addPoints(const SkPoint pts[], int count); |
| 181 void addRect(const SkRect& rect); | 170 void addRect(const SkRect& rect); |
| 182 void addRectPtr(const SkRect* rect); | 171 void addRectPtr(const SkRect* rect); |
| 183 void addIRect(const SkIRect& rect); | 172 void addIRect(const SkIRect& rect); |
| 184 void addIRectPtr(const SkIRect* rect); | 173 void addIRectPtr(const SkIRect* rect); |
| 185 void addRRect(const SkRRect&); | 174 void addRRect(const SkRRect&); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 213 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkS
calar y, | 202 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkS
calar y, |
| 214 const SkPaint&) SK_OVERRIDE; | 203 const SkPaint&) SK_OVERRIDE; |
| 215 virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoin
t pos[], | 204 virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoin
t pos[], |
| 216 const SkPaint&) SK_OVERRIDE; | 205 const SkPaint&) SK_OVERRIDE; |
| 217 virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkSca
lar xpos[], | 206 virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkSca
lar xpos[], |
| 218 SkScalar constY, const SkPaint&) SK_OVERRIDE; | 207 SkScalar constY, const SkPaint&) SK_OVERRIDE; |
| 219 virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkP
ath& path, | 208 virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkP
ath& path, |
| 220 const SkMatrix* matrix, const SkPaint&) SK_OVE
RRIDE; | 209 const SkMatrix* matrix, const SkPaint&) SK_OVE
RRIDE; |
| 221 virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, | 210 virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 222 const SkPaint& paint) SK_OVERRIDE; | 211 const SkPaint& paint) SK_OVERRIDE; |
| 223 | 212 |
| 224 virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], | 213 virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 225 const SkPoint texCoords[4], SkXfermode* xmode, | 214 const SkPoint texCoords[4], SkXfermode* xmode, |
| 226 const SkPaint& paint) SK_OVERRIDE; | 215 const SkPaint& paint) SK_OVERRIDE; |
| 227 | 216 |
| 228 virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERR
IDE; | 217 virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERR
IDE; |
| 229 virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVE
RRIDE; | 218 virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVE
RRIDE; |
| 230 virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERR
IDE; | 219 virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERR
IDE; |
| 231 virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE; | 220 virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE; |
| 232 | 221 |
| 233 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*
) SK_OVERRIDE; | 222 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*
) SK_OVERRIDE; |
| 234 | 223 |
| 235 // Return fontmetrics.fTop,fBottom in topbot[0,1], after they have been | |
| 236 // tweaked by paint.computeFastBounds(). | |
| 237 static void ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar topbo
t[2]); | |
| 238 | |
| 239 // Make sure that flat has fTopBot written. | |
| 240 static void WriteTopBot(const SkPaint& paint, const SkFlatData& flat) { | |
| 241 if (!flat.isTopBotWritten()) { | |
| 242 ComputeFontMetricsTopBottom(paint, flat.writableTopBot()); | |
| 243 SkASSERT(flat.isTopBotWritten()); | |
| 244 } | |
| 245 } | |
| 246 // Will return a cached version when possible. | |
| 247 const SkFlatData* getFlatPaintData(const SkPaint& paint); | |
| 248 /** | |
| 249 * SkBBoxRecord::drawPosTextH gets a flat paint and uses it, | |
| 250 * then it calls this, using the extra parameter, to avoid duplication. | |
| 251 */ | |
| 252 void drawPosTextHImpl(const void* text, size_t byteLength, | |
| 253 const SkScalar xpos[], SkScalar constY, | |
| 254 const SkPaint& paint, const SkFlatData* flatPaintData)
; | |
| 255 | |
| 256 int addPathToHeap(const SkPath& path); // does not write to ops stream | 224 int addPathToHeap(const SkPath& path); // does not write to ops stream |
| 257 | 225 |
| 258 // These entry points allow the writing of matrices, clips, saves & | 226 // These entry points allow the writing of matrices, clips, saves & |
| 259 // restores to be deferred (e.g., if the MC state is being collapsed and | 227 // restores to be deferred (e.g., if the MC state is being collapsed and |
| 260 // only written out as needed). | 228 // only written out as needed). |
| 261 void recordConcat(const SkMatrix& matrix); | 229 void recordConcat(const SkMatrix& matrix); |
| 262 void recordTranslate(const SkMatrix& matrix); | 230 void recordTranslate(const SkMatrix& matrix); |
| 263 void recordScale(const SkMatrix& matrix); | 231 void recordScale(const SkMatrix& matrix); |
| 264 size_t recordClipRect(const SkRect& rect, SkRegion::Op op, bool doAA); | 232 size_t recordClipRect(const SkRect& rect, SkRegion::Op op, bool doAA); |
| 265 size_t recordClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA); | 233 size_t recordClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA); |
| 266 size_t recordClipPath(int pathID, SkRegion::Op op, bool doAA); | 234 size_t recordClipPath(int pathID, SkRegion::Op op, bool doAA); |
| 267 size_t recordClipRegion(const SkRegion& region, SkRegion::Op op); | 235 size_t recordClipRegion(const SkRegion& region, SkRegion::Op op); |
| 268 void recordSave(); | 236 void recordSave(); |
| 269 void recordSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags f
lags); | 237 void recordSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags f
lags); |
| 270 void recordRestore(bool fillInSkips = true); | 238 void recordRestore(bool fillInSkips = true); |
| 271 | 239 |
| 272 // These are set to NULL in our constructor, but may be changed by | |
| 273 // subclasses, in which case they will be SkSafeUnref'd in our destructor. | |
| 274 SkBBoxHierarchy* fBoundingHierarchy; | |
| 275 SkPictureStateTree* fStateTree; | |
| 276 | |
| 277 // Allocated in the constructor and managed by this class. | 240 // Allocated in the constructor and managed by this class. |
| 278 SkBitmapHeap* fBitmapHeap; | 241 SkBitmapHeap* fBitmapHeap; |
| 279 | 242 |
| 280 private: | 243 private: |
| 281 SkPictureContentInfo fContentInfo; | 244 SkPictureContentInfo fContentInfo; |
| 282 SkAutoTUnref<SkPathHeap> fPathHeap; | 245 SkAutoTUnref<SkPathHeap> fPathHeap; |
| 283 | 246 |
| 284 SkChunkFlatController fFlattenableHeap; | 247 SkChunkFlatController fFlattenableHeap; |
| 285 | 248 |
| 286 SkPaintDictionary fPaints; | 249 SkPaintDictionary fPaints; |
| 287 | 250 |
| 288 SkWriter32 fWriter; | 251 SkWriter32 fWriter; |
| 289 | 252 |
| 290 // we ref each item in these arrays | 253 // we ref each item in these arrays |
| 291 SkTDArray<const SkPicture*> fPictureRefs; | 254 SkTDArray<const SkPicture*> fPictureRefs; |
| 292 SkTDArray<const SkTextBlob*> fTextBlobRefs; | 255 SkTDArray<const SkTextBlob*> fTextBlobRefs; |
| 293 | 256 |
| 294 uint32_t fRecordFlags; | 257 uint32_t fRecordFlags; |
| 295 bool fOptsEnabled; | |
| 296 int fInitialSaveCount; | 258 int fInitialSaveCount; |
| 297 | 259 |
| 298 friend class SkPictureData; // for SkPictureData's SkPictureRecord-based c
onstructor | 260 friend class SkPictureData; // for SkPictureData's SkPictureRecord-based c
onstructor |
| 299 friend class SkPictureTester; // for unit testing | 261 friend class SkPictureTester; // for unit testing |
| 300 | 262 |
| 301 typedef SkCanvas INHERITED; | 263 typedef SkCanvas INHERITED; |
| 302 }; | 264 }; |
| 303 | 265 |
| 304 #endif | 266 #endif |
| OLD | NEW |