Chromium Code Reviews| 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 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE | 13 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 14 #include "SkMatrixClipStateMgr.h" | 14 #include "SkMatrixClipStateMgr.h" |
| 15 #endif | 15 #endif |
| 16 #include "SkPathHeap.h" | 16 #include "SkPathHeap.h" |
| 17 #include "SkPicture.h" | 17 #include "SkPicture.h" |
| 18 #include "SkPictureFlat.h" | 18 #include "SkPictureFlat.h" |
| 19 #include "SkTemplates.h" | 19 #include "SkTemplates.h" |
| 20 #include "SkWriter32.h" | 20 #include "SkWriter32.h" |
| 21 | 21 |
| 22 class SkPictureStateTree; | 22 class SkPictureStateTree; |
| 23 class SkBBoxHierarchy; | 23 class SkBBoxHierarchy; |
| 24 | 24 |
| 25 // A 2D table of skp offsets. Each row is indexed by an int. This is used | |
| 26 // to store the command offsets that reference a particular bitmap using | |
| 27 // the bitmap's index in the bitmap heap as the 'id' here. It has to be | |
| 28 // ref-countable so SkPicturePlayback can take ownership of it. | |
| 29 class SkOffsetTable : public SkRefCnt { | |
|
mtklein
2014/03/06 16:20:38
Give this class its own .h/.cpp pair?
robertphillips
2014/03/06 20:18:26
Will do. I will leave that as a final refactoring
| |
| 30 public: | |
| 31 SkOffsetTable() {} | |
| 32 ~SkOffsetTable() { | |
| 33 for (int i = 0; i < fOffsetArrays.count(); ++i) { | |
|
mtklein
2014/03/06 16:20:38
fOffsetArrays.deleteAll(); ?
robertphillips
2014/03/06 20:18:26
Done.
| |
| 34 SkDELETE(fOffsetArrays[i]); | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 void add(int id, size_t offset) { | |
|
mtklein
2014/03/06 16:20:38
// Record that this ID is used by the command star
robertphillips
2014/03/06 20:18:26
Done.
| |
| 39 if (id >= fOffsetArrays.count()) { | |
|
mtklein
2014/03/06 16:20:38
Can you note somewhere, maybe at the top of the cl
robertphillips
2014/03/06 20:18:26
Done.
| |
| 40 int oldCount = fOffsetArrays.count(); | |
| 41 fOffsetArrays.setCount(id+1); | |
| 42 for (int i = oldCount; i <= id; ++i) { | |
| 43 fOffsetArrays[i] = NULL; | |
| 44 } | |
| 45 } | |
|
mtklein
2014/03/06 16:20:38
Are we assuming |IDs| << |offsets|? If there are
robertphillips
2014/03/06 20:18:26
|IDs| is < |offsets| but it varies widely between
| |
| 46 | |
| 47 if (NULL == fOffsetArrays[id]) { | |
| 48 fOffsetArrays[id] = SkNEW(OffsetArray); | |
| 49 } | |
| 50 fOffsetArrays[id]->add(offset); | |
| 51 } | |
| 52 | |
| 53 int numIDs() const { | |
| 54 return fOffsetArrays.count(); | |
| 55 } | |
| 56 | |
| 57 bool overlap(int id, size_t min, size_t max) { | |
|
mtklein
2014/03/06 16:20:38
// Do the offsets of any commands referencing this
robertphillips
2014/03/06 20:18:26
Done.
| |
| 58 SkASSERT(id < fOffsetArrays.count()); | |
| 59 | |
| 60 if (NULL == fOffsetArrays[id]) { | |
| 61 return false; | |
| 62 } | |
| 63 | |
| 64 SkASSERT(fOffsetArrays[id]->count() > 0); | |
|
mtklein
2014/03/06 16:20:38
->front() and ->back() are about to check this any
robertphillips
2014/03/06 20:18:26
I've added a comment. The assert here was basicall
| |
| 65 if (max < fOffsetArrays[id]->front() || min > fOffsetArrays[id]->back()) { | |
|
mtklein
2014/03/06 16:20:38
Might help readability here to rename front to low
robertphillips
2014/03/06 20:18:26
Done.
| |
| 66 return false; | |
| 67 } | |
| 68 | |
| 69 return true; | |
| 70 } | |
| 71 | |
| 72 bool includes(int id, size_t offset) { | |
|
mtklein
2014/03/06 16:20:38
Note that this is linear in the number of commands
robertphillips
2014/03/06 20:18:26
Yep - right now I'm just trying to get it working.
| |
| 73 SkASSERT(id < fOffsetArrays.count()); | |
| 74 | |
| 75 OffsetArray* array = fOffsetArrays[id]; | |
| 76 | |
| 77 for (int i = 0; i < array->fOffsets.count(); ++i) { | |
| 78 if (array->fOffsets[i] == offset) { | |
| 79 return true; | |
| 80 } else if (array->fOffsets[i] > offset) { | |
| 81 return false; | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 SkASSERT(0); | |
|
mtklein
2014/03/06 16:20:38
Why this assert? I guess we don't expect people t
robertphillips
2014/03/06 20:18:26
Given that this should always be guarded by a 'ove
mtklein
2014/03/07 13:04:08
Ah, can you add // We're guarded by an overlap() c
robertphillips
2014/03/07 13:23:00
Done.
| |
| 86 return false; | |
| 87 } | |
| 88 | |
| 89 protected: | |
| 90 class OffsetArray { | |
| 91 public: | |
| 92 void add(size_t offset) { *fOffsets.append() = offset; } | |
|
mtklein
2014/03/06 16:20:38
Seems like we'd want to add
SkASSERT(fOffsets.co
robertphillips
2014/03/06 20:18:26
Done.
| |
| 93 size_t front() const { | |
| 94 SkASSERT(fOffsets.count() > 0); | |
| 95 return fOffsets[0]; | |
| 96 } | |
| 97 size_t back() const { | |
| 98 SkASSERT(fOffsets.count() > 0); | |
| 99 return fOffsets[fOffsets.count()-1]; | |
| 100 } | |
| 101 int count() const { | |
| 102 return fOffsets.count(); | |
| 103 } | |
| 104 | |
| 105 SkTDArray<size_t> fOffsets; | |
| 106 }; | |
| 107 | |
| 108 SkTDArray<OffsetArray*> fOffsetArrays; | |
| 109 | |
| 110 private: | |
| 111 typedef SkRefCnt INHERITED; | |
| 112 }; | |
| 113 | |
| 25 // These macros help with packing and unpacking a single byte value and | 114 // These macros help with packing and unpacking a single byte value and |
| 26 // a 3 byte value into/out of a uint32_t | 115 // a 3 byte value into/out of a uint32_t |
| 27 #define MASK_24 0x00FFFFFF | 116 #define MASK_24 0x00FFFFFF |
| 28 #define UNPACK_8_24(combined, small, large) \ | 117 #define UNPACK_8_24(combined, small, large) \ |
| 29 small = (combined >> 24) & 0xFF; \ | 118 small = (combined >> 24) & 0xFF; \ |
| 30 large = combined & MASK_24; | 119 large = combined & MASK_24; |
| 31 #define PACK_8_24(small, large) ((small << 24) | large) | 120 #define PACK_8_24(small, large) ((small << 24) | large) |
| 32 | 121 |
| 33 | 122 |
| 34 class SkPictureRecord : public SkCanvas { | 123 class SkPictureRecord : public SkCanvas { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 return offset; | 246 return offset; |
| 158 } | 247 } |
| 159 | 248 |
| 160 void addInt(int value) { | 249 void addInt(int value) { |
| 161 fWriter.writeInt(value); | 250 fWriter.writeInt(value); |
| 162 } | 251 } |
| 163 void addScalar(SkScalar scalar) { | 252 void addScalar(SkScalar scalar) { |
| 164 fWriter.writeScalar(scalar); | 253 fWriter.writeScalar(scalar); |
| 165 } | 254 } |
| 166 | 255 |
| 167 void addBitmap(const SkBitmap& bitmap); | 256 // The command at 'offset' in the skp uses the specified bitmap |
| 257 void trackBitmapUse(int bitmapID, size_t offset); | |
| 258 int addBitmap(const SkBitmap& bitmap); | |
| 168 void addMatrix(const SkMatrix& matrix); | 259 void addMatrix(const SkMatrix& matrix); |
| 169 const SkFlatData* addPaint(const SkPaint& paint) { return this->addPaintPtr( &paint); } | 260 const SkFlatData* addPaint(const SkPaint& paint) { return this->addPaintPtr( &paint); } |
| 170 const SkFlatData* addPaintPtr(const SkPaint* paint); | 261 const SkFlatData* addPaintPtr(const SkPaint* paint); |
| 171 void addFlatPaint(const SkFlatData* flatPaint); | 262 void addFlatPaint(const SkFlatData* flatPaint); |
| 172 void addPath(const SkPath& path); | 263 void addPath(const SkPath& path); |
| 173 void addPicture(SkPicture& picture); | 264 void addPicture(SkPicture& picture); |
| 174 void addPoint(const SkPoint& point); | 265 void addPoint(const SkPoint& point); |
| 175 void addPoints(const SkPoint pts[], int count); | 266 void addPoints(const SkPoint pts[], int count); |
| 176 void addRect(const SkRect& rect); | 267 void addRect(const SkRect& rect); |
| 177 void addRectPtr(const SkRect* rect); | 268 void addRectPtr(const SkRect* rect); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 SkPathHeap* fPathHeap; // reference counted | 378 SkPathHeap* fPathHeap; // reference counted |
| 288 SkWriter32 fWriter; | 379 SkWriter32 fWriter; |
| 289 | 380 |
| 290 // we ref each item in these arrays | 381 // we ref each item in these arrays |
| 291 SkTDArray<SkPicture*> fPictureRefs; | 382 SkTDArray<SkPicture*> fPictureRefs; |
| 292 | 383 |
| 293 uint32_t fRecordFlags; | 384 uint32_t fRecordFlags; |
| 294 bool fOptsEnabled; | 385 bool fOptsEnabled; |
| 295 int fInitialSaveCount; | 386 int fInitialSaveCount; |
| 296 | 387 |
| 388 SkOffsetTable* fBitmapUseOffsets; | |
|
mtklein
2014/03/06 16:20:38
SkAutoTUnref<SkOffsetTable> ?
robertphillips
2014/03/06 20:18:26
Done.
| |
| 389 | |
| 297 friend class SkPicturePlayback; | 390 friend class SkPicturePlayback; |
| 298 friend class SkPictureTester; // for unit testing | 391 friend class SkPictureTester; // for unit testing |
| 299 | 392 |
| 300 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE | 393 #ifdef SK_COLLAPSE_MATRIX_CLIP_STATE |
| 301 SkMatrixClipStateMgr fMCMgr; | 394 SkMatrixClipStateMgr fMCMgr; |
| 302 #endif | 395 #endif |
| 303 | 396 |
| 304 typedef SkCanvas INHERITED; | 397 typedef SkCanvas INHERITED; |
| 305 }; | 398 }; |
| 306 | 399 |
| 307 #endif | 400 #endif |
| OLD | NEW |