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 #include <new> | 7 #include <new> |
8 #include "SkBBoxHierarchy.h" | 8 #include "SkBBoxHierarchy.h" |
9 #include "SkDrawPictureCallback.h" | 9 #include "SkDrawPictureCallback.h" |
10 #include "SkPicturePlayback.h" | 10 #include "SkPictureData.h" |
11 #include "SkPictureRecord.h" | 11 #include "SkPictureRecord.h" |
12 #include "SkPictureStateTree.h" | 12 #include "SkPictureStateTree.h" |
13 #include "SkReadBuffer.h" | 13 #include "SkReadBuffer.h" |
14 #include "SkTypeface.h" | 14 #include "SkTypeface.h" |
15 #include "SkTSort.h" | 15 #include "SkTSort.h" |
16 #include "SkWriteBuffer.h" | 16 #include "SkWriteBuffer.h" |
17 | 17 |
18 #if SK_SUPPORT_GPU | 18 #if SK_SUPPORT_GPU |
19 #include "GrContext.h" | 19 #include "GrContext.h" |
20 #endif | 20 #endif |
21 | 21 |
22 template <typename T> int SafeCount(const T* obj) { | 22 template <typename T> int SafeCount(const T* obj) { |
23 return obj ? obj->count() : 0; | 23 return obj ? obj->count() : 0; |
24 } | 24 } |
25 | 25 |
26 /* Define this to spew out a debug statement whenever we skip the remainder of | 26 /* Define this to spew out a debug statement whenever we skip the remainder of |
27 a save/restore block because a clip... command returned false (empty). | 27 a save/restore block because a clip... command returned false (empty). |
28 */ | 28 */ |
29 #define SPEW_CLIP_SKIPPINGx | 29 #define SPEW_CLIP_SKIPPINGx |
30 | 30 |
31 SkPicturePlayback::PlaybackReplacements::ReplacementInfo* | 31 SkPictureData::PlaybackReplacements::ReplacementInfo* |
32 SkPicturePlayback::PlaybackReplacements::push() { | 32 SkPictureData::PlaybackReplacements::push() { |
33 SkDEBUGCODE(this->validate()); | 33 SkDEBUGCODE(this->validate()); |
34 return fReplacements.push(); | 34 return fReplacements.push(); |
35 } | 35 } |
36 | 36 |
37 void SkPicturePlayback::PlaybackReplacements::freeAll() { | 37 void SkPictureData::PlaybackReplacements::freeAll() { |
38 for (int i = 0; i < fReplacements.count(); ++i) { | 38 for (int i = 0; i < fReplacements.count(); ++i) { |
39 SkDELETE(fReplacements[i].fBM); | 39 SkDELETE(fReplacements[i].fBM); |
40 } | 40 } |
41 fReplacements.reset(); | 41 fReplacements.reset(); |
42 } | 42 } |
43 | 43 |
44 #ifdef SK_DEBUG | 44 #ifdef SK_DEBUG |
45 void SkPicturePlayback::PlaybackReplacements::validate() const { | 45 void SkPictureData::PlaybackReplacements::validate() const { |
46 // Check that the ranges are monotonically increasing and non-overlapping | 46 // Check that the ranges are monotonically increasing and non-overlapping |
47 if (fReplacements.count() > 0) { | 47 if (fReplacements.count() > 0) { |
48 SkASSERT(fReplacements[0].fStart < fReplacements[0].fStop); | 48 SkASSERT(fReplacements[0].fStart < fReplacements[0].fStop); |
49 | 49 |
50 for (int i = 1; i < fReplacements.count(); ++i) { | 50 for (int i = 1; i < fReplacements.count(); ++i) { |
51 SkASSERT(fReplacements[i].fStart < fReplacements[i].fStop); | 51 SkASSERT(fReplacements[i].fStart < fReplacements[i].fStop); |
52 SkASSERT(fReplacements[i-1].fStop < fReplacements[i].fStart); | 52 SkASSERT(fReplacements[i-1].fStop < fReplacements[i].fStart); |
53 } | 53 } |
54 } | 54 } |
55 } | 55 } |
56 #endif | 56 #endif |
57 | 57 |
58 SkPicturePlayback::SkPicturePlayback(const SkPictInfo& info) | 58 SkPictureData::SkPictureData(const SkPictInfo& info) |
59 : fInfo(info) { | 59 : fInfo(info) { |
60 this->init(); | 60 this->init(); |
61 } | 61 } |
62 | 62 |
63 void SkPicturePlayback::initForPlayback() const { | 63 void SkPictureData::initForPlayback() const { |
64 // ensure that the paths bounds are pre-computed | 64 // ensure that the paths bounds are pre-computed |
65 if (NULL != fPathHeap.get()) { | 65 if (NULL != fPathHeap.get()) { |
66 for (int i = 0; i < fPathHeap->count(); i++) { | 66 for (int i = 0; i < fPathHeap->count(); i++) { |
67 (*fPathHeap.get())[i].updateBoundsCache(); | 67 (*fPathHeap.get())[i].updateBoundsCache(); |
68 } | 68 } |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 SkPicturePlayback::SkPicturePlayback(const SkPictureRecord& record, | 72 SkPictureData::SkPictureData(const SkPictureRecord& record, |
73 const SkPictInfo& info, | 73 const SkPictInfo& info, |
74 bool deepCopyOps) | 74 bool deepCopyOps) |
75 : fInfo(info) { | 75 : fInfo(info) { |
76 #ifdef SK_DEBUG_SIZE | 76 #ifdef SK_DEBUG_SIZE |
77 size_t overallBytes, bitmapBytes, matricesBytes, | 77 size_t overallBytes, bitmapBytes, matricesBytes, |
78 paintBytes, pathBytes, pictureBytes, regionBytes; | 78 paintBytes, pathBytes, pictureBytes, regionBytes; |
79 int bitmaps = record.bitmaps(&bitmapBytes); | 79 int bitmaps = record.bitmaps(&bitmapBytes); |
80 int matrices = record.matrices(&matricesBytes); | 80 int matrices = record.matrices(&matricesBytes); |
81 int paints = record.paints(&paintBytes); | 81 int paints = record.paints(&paintBytes); |
82 int paths = record.paths(&pathBytes); | 82 int paths = record.paths(&pathBytes); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 SkDebugf("paths size %zd (paths:%d) ", pathBytes, paths); | 162 SkDebugf("paths size %zd (paths:%d) ", pathBytes, paths); |
163 if (pictures != 0) | 163 if (pictures != 0) |
164 SkDebugf("pictures size %zd (pictures:%d) ", pictureBytes, pictures); | 164 SkDebugf("pictures size %zd (pictures:%d) ", pictureBytes, pictures); |
165 if (regions != 0) | 165 if (regions != 0) |
166 SkDebugf("regions size %zd (regions:%d) ", regionBytes, regions); | 166 SkDebugf("regions size %zd (regions:%d) ", regionBytes, regions); |
167 SkDebugf("\n"); | 167 SkDebugf("\n"); |
168 #endif | 168 #endif |
169 } | 169 } |
170 | 170 |
171 #ifdef SK_SUPPORT_LEGACY_PICTURE_CLONE | 171 #ifdef SK_SUPPORT_LEGACY_PICTURE_CLONE |
172 SkPicturePlayback::SkPicturePlayback(const SkPicturePlayback& src, SkPictCopyInf
o* deepCopyInfo) | 172 SkPictureData::SkPictureData(const SkPictureData& src, SkPictCopyInfo* deepCopyI
nfo) |
173 : fInfo(src.fInfo) { | 173 : fInfo(src.fInfo) { |
174 this->init(); | 174 this->init(); |
175 | 175 |
176 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get())); | 176 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get())); |
177 fPathHeap.reset(SkSafeRef(src.fPathHeap.get())); | 177 fPathHeap.reset(SkSafeRef(src.fPathHeap.get())); |
178 | 178 |
179 fOpData = SkSafeRef(src.fOpData); | 179 fOpData = SkSafeRef(src.fOpData); |
180 | 180 |
181 fBoundingHierarchy = src.fBoundingHierarchy; | 181 fBoundingHierarchy = src.fBoundingHierarchy; |
182 fStateTree = src.fStateTree; | 182 fStateTree = src.fStateTree; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 for (int i = 0; i < fPictureCount; i++) { | 218 for (int i = 0; i < fPictureCount; i++) { |
219 if (deepCopyInfo) { | 219 if (deepCopyInfo) { |
220 fPictureRefs[i] = src.fPictureRefs[i]->clone(); | 220 fPictureRefs[i] = src.fPictureRefs[i]->clone(); |
221 } else { | 221 } else { |
222 fPictureRefs[i] = src.fPictureRefs[i]; | 222 fPictureRefs[i] = src.fPictureRefs[i]; |
223 fPictureRefs[i]->ref(); | 223 fPictureRefs[i]->ref(); |
224 } | 224 } |
225 } | 225 } |
226 } | 226 } |
227 #else | 227 #else |
228 SkPicturePlayback::SkPicturePlayback(const SkPicturePlayback& src) : fInfo(src.f
Info) { | 228 SkPictureData::SkPictureData(const SkPictureData& src) : fInfo(src.fInfo) { |
229 this->init(); | 229 this->init(); |
230 | 230 |
231 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get())); | 231 fBitmapHeap.reset(SkSafeRef(src.fBitmapHeap.get())); |
232 fPathHeap.reset(SkSafeRef(src.fPathHeap.get())); | 232 fPathHeap.reset(SkSafeRef(src.fPathHeap.get())); |
233 | 233 |
234 fOpData = SkSafeRef(src.fOpData); | 234 fOpData = SkSafeRef(src.fOpData); |
235 | 235 |
236 fBoundingHierarchy = src.fBoundingHierarchy; | 236 fBoundingHierarchy = src.fBoundingHierarchy; |
237 fStateTree = src.fStateTree; | 237 fStateTree = src.fStateTree; |
238 fContentInfo.set(src.fContentInfo); | 238 fContentInfo.set(src.fContentInfo); |
239 | 239 |
240 SkSafeRef(fBoundingHierarchy); | 240 SkSafeRef(fBoundingHierarchy); |
241 SkSafeRef(fStateTree); | 241 SkSafeRef(fStateTree); |
242 | 242 |
243 fBitmaps = SkSafeRef(src.fBitmaps); | 243 fBitmaps = SkSafeRef(src.fBitmaps); |
244 fPaints = SkSafeRef(src.fPaints); | 244 fPaints = SkSafeRef(src.fPaints); |
245 | 245 |
246 fPictureCount = src.fPictureCount; | 246 fPictureCount = src.fPictureCount; |
247 fPictureRefs = SkNEW_ARRAY(const SkPicture*, fPictureCount); | 247 fPictureRefs = SkNEW_ARRAY(const SkPicture*, fPictureCount); |
248 for (int i = 0; i < fPictureCount; i++) { | 248 for (int i = 0; i < fPictureCount; i++) { |
249 fPictureRefs[i] = SkRef(src.fPictureRefs[i]); | 249 fPictureRefs[i] = SkRef(src.fPictureRefs[i]); |
250 } | 250 } |
251 } | 251 } |
252 #endif//SK_SUPPORT_LEGACY_PICTURE_CLONE | 252 #endif//SK_SUPPORT_LEGACY_PICTURE_CLONE |
253 | 253 |
254 void SkPicturePlayback::init() { | 254 void SkPictureData::init() { |
255 fBitmaps = NULL; | 255 fBitmaps = NULL; |
256 fPaints = NULL; | 256 fPaints = NULL; |
257 fPictureRefs = NULL; | 257 fPictureRefs = NULL; |
258 fPictureCount = 0; | 258 fPictureCount = 0; |
259 fOpData = NULL; | 259 fOpData = NULL; |
260 fFactoryPlayback = NULL; | 260 fFactoryPlayback = NULL; |
261 fBoundingHierarchy = NULL; | 261 fBoundingHierarchy = NULL; |
262 fStateTree = NULL; | 262 fStateTree = NULL; |
263 fCachedActiveOps = NULL; | 263 fCachedActiveOps = NULL; |
264 fCurOffset = 0; | 264 fCurOffset = 0; |
265 fUseBBH = true; | 265 fUseBBH = true; |
266 fStart = 0; | 266 fStart = 0; |
267 fStop = 0; | 267 fStop = 0; |
268 fReplacements = NULL; | 268 fReplacements = NULL; |
269 } | 269 } |
270 | 270 |
271 SkPicturePlayback::~SkPicturePlayback() { | 271 SkPictureData::~SkPictureData() { |
272 SkSafeUnref(fOpData); | 272 SkSafeUnref(fOpData); |
273 | 273 |
274 SkSafeUnref(fBitmaps); | 274 SkSafeUnref(fBitmaps); |
275 SkSafeUnref(fPaints); | 275 SkSafeUnref(fPaints); |
276 SkSafeUnref(fBoundingHierarchy); | 276 SkSafeUnref(fBoundingHierarchy); |
277 SkSafeUnref(fStateTree); | 277 SkSafeUnref(fStateTree); |
278 | 278 |
279 SkDELETE(fCachedActiveOps); | 279 SkDELETE(fCachedActiveOps); |
280 | 280 |
281 for (int i = 0; i < fPictureCount; i++) { | 281 for (int i = 0; i < fPictureCount; i++) { |
282 fPictureRefs[i]->unref(); | 282 fPictureRefs[i]->unref(); |
283 } | 283 } |
284 SkDELETE_ARRAY(fPictureRefs); | 284 SkDELETE_ARRAY(fPictureRefs); |
285 | 285 |
286 SkDELETE(fFactoryPlayback); | 286 SkDELETE(fFactoryPlayback); |
287 } | 287 } |
288 | 288 |
289 void SkPicturePlayback::dumpSize() const { | 289 void SkPictureData::dumpSize() const { |
290 SkDebugf("--- picture size: ops=%d bitmaps=%d [%d] paints=%d [%d]\n", | 290 SkDebugf("--- picture size: ops=%d bitmaps=%d [%d] paints=%d [%d]\n", |
291 fOpData->size(), | 291 fOpData->size(), |
292 SafeCount(fBitmaps), SafeCount(fBitmaps) * sizeof(SkBitmap), | 292 SafeCount(fBitmaps), SafeCount(fBitmaps) * sizeof(SkBitmap), |
293 SafeCount(fPaints), SafeCount(fPaints) * sizeof(SkPaint)); | 293 SafeCount(fPaints), SafeCount(fPaints) * sizeof(SkPaint)); |
294 SkDebugf("--- picture size: paths=%d\n", | 294 SkDebugf("--- picture size: paths=%d\n", |
295 SafeCount(fPathHeap.get())); | 295 SafeCount(fPathHeap.get())); |
296 } | 296 } |
297 | 297 |
298 bool SkPicturePlayback::containsBitmaps() const { | 298 bool SkPictureData::containsBitmaps() const { |
299 if (fBitmaps && fBitmaps->count() > 0) { | 299 if (fBitmaps && fBitmaps->count() > 0) { |
300 return true; | 300 return true; |
301 } | 301 } |
302 for (int i = 0; i < fPictureCount; ++i) { | 302 for (int i = 0; i < fPictureCount; ++i) { |
303 if (fPictureRefs[i]->willPlayBackBitmaps()) { | 303 if (fPictureRefs[i]->willPlayBackBitmaps()) { |
304 return true; | 304 return true; |
305 } | 305 } |
306 } | 306 } |
307 return false; | 307 return false; |
308 } | 308 } |
(...skipping 13 matching lines...) Expand all Loading... |
322 } else { | 322 } else { |
323 size_t len = strlen(name); | 323 size_t len = strlen(name); |
324 size += SkWStream::SizeOfPackedUInt(len); | 324 size += SkWStream::SizeOfPackedUInt(len); |
325 size += len; | 325 size += len; |
326 } | 326 } |
327 } | 327 } |
328 | 328 |
329 return size; | 329 return size; |
330 } | 330 } |
331 | 331 |
332 void SkPicturePlayback::WriteFactories(SkWStream* stream, const SkFactorySet& re
c) { | 332 void SkPictureData::WriteFactories(SkWStream* stream, const SkFactorySet& rec) { |
333 int count = rec.count(); | 333 int count = rec.count(); |
334 | 334 |
335 SkAutoSTMalloc<16, SkFlattenable::Factory> storage(count); | 335 SkAutoSTMalloc<16, SkFlattenable::Factory> storage(count); |
336 SkFlattenable::Factory* array = (SkFlattenable::Factory*)storage.get(); | 336 SkFlattenable::Factory* array = (SkFlattenable::Factory*)storage.get(); |
337 rec.copyToArray(array); | 337 rec.copyToArray(array); |
338 | 338 |
339 size_t size = compute_chunk_size(array, count); | 339 size_t size = compute_chunk_size(array, count); |
340 | 340 |
341 // TODO: write_tag_size should really take a size_t | 341 // TODO: write_tag_size should really take a size_t |
342 SkPicture::WriteTagSize(stream, SK_PICT_FACTORY_TAG, (uint32_t) size); | 342 SkPicture::WriteTagSize(stream, SK_PICT_FACTORY_TAG, (uint32_t) size); |
343 SkDEBUGCODE(size_t start = stream->bytesWritten()); | 343 SkDEBUGCODE(size_t start = stream->bytesWritten()); |
344 stream->write32(count); | 344 stream->write32(count); |
345 | 345 |
346 for (int i = 0; i < count; i++) { | 346 for (int i = 0; i < count; i++) { |
347 const char* name = SkFlattenable::FactoryToName(array[i]); | 347 const char* name = SkFlattenable::FactoryToName(array[i]); |
348 // SkDebugf("---- write factories [%d] %p <%s>\n", i, array[i], name); | 348 // SkDebugf("---- write factories [%d] %p <%s>\n", i, array[i], name); |
349 if (NULL == name || 0 == *name) { | 349 if (NULL == name || 0 == *name) { |
350 stream->writePackedUInt(0); | 350 stream->writePackedUInt(0); |
351 } else { | 351 } else { |
352 size_t len = strlen(name); | 352 size_t len = strlen(name); |
353 stream->writePackedUInt(len); | 353 stream->writePackedUInt(len); |
354 stream->write(name, len); | 354 stream->write(name, len); |
355 } | 355 } |
356 } | 356 } |
357 | 357 |
358 SkASSERT(size == (stream->bytesWritten() - start)); | 358 SkASSERT(size == (stream->bytesWritten() - start)); |
359 } | 359 } |
360 | 360 |
361 void SkPicturePlayback::WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec
) { | 361 void SkPictureData::WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec) { |
362 int count = rec.count(); | 362 int count = rec.count(); |
363 | 363 |
364 SkPicture::WriteTagSize(stream, SK_PICT_TYPEFACE_TAG, count); | 364 SkPicture::WriteTagSize(stream, SK_PICT_TYPEFACE_TAG, count); |
365 | 365 |
366 SkAutoSTMalloc<16, SkTypeface*> storage(count); | 366 SkAutoSTMalloc<16, SkTypeface*> storage(count); |
367 SkTypeface** array = (SkTypeface**)storage.get(); | 367 SkTypeface** array = (SkTypeface**)storage.get(); |
368 rec.copyToArray((SkRefCnt**)array); | 368 rec.copyToArray((SkRefCnt**)array); |
369 | 369 |
370 for (int i = 0; i < count; i++) { | 370 for (int i = 0; i < count; i++) { |
371 array[i]->serialize(stream); | 371 array[i]->serialize(stream); |
372 } | 372 } |
373 } | 373 } |
374 | 374 |
375 void SkPicturePlayback::flattenToBuffer(SkWriteBuffer& buffer) const { | 375 void SkPictureData::flattenToBuffer(SkWriteBuffer& buffer) const { |
376 int i, n; | 376 int i, n; |
377 | 377 |
378 if ((n = SafeCount(fBitmaps)) > 0) { | 378 if ((n = SafeCount(fBitmaps)) > 0) { |
379 SkPicture::WriteTagSize(buffer, SK_PICT_BITMAP_BUFFER_TAG, n); | 379 SkPicture::WriteTagSize(buffer, SK_PICT_BITMAP_BUFFER_TAG, n); |
380 for (i = 0; i < n; i++) { | 380 for (i = 0; i < n; i++) { |
381 buffer.writeBitmap((*fBitmaps)[i]); | 381 buffer.writeBitmap((*fBitmaps)[i]); |
382 } | 382 } |
383 } | 383 } |
384 | 384 |
385 if ((n = SafeCount(fPaints)) > 0) { | 385 if ((n = SafeCount(fPaints)) > 0) { |
386 SkPicture::WriteTagSize(buffer, SK_PICT_PAINT_BUFFER_TAG, n); | 386 SkPicture::WriteTagSize(buffer, SK_PICT_PAINT_BUFFER_TAG, n); |
387 for (i = 0; i < n; i++) { | 387 for (i = 0; i < n; i++) { |
388 buffer.writePaint((*fPaints)[i]); | 388 buffer.writePaint((*fPaints)[i]); |
389 } | 389 } |
390 } | 390 } |
391 | 391 |
392 if ((n = SafeCount(fPathHeap.get())) > 0) { | 392 if ((n = SafeCount(fPathHeap.get())) > 0) { |
393 SkPicture::WriteTagSize(buffer, SK_PICT_PATH_BUFFER_TAG, n); | 393 SkPicture::WriteTagSize(buffer, SK_PICT_PATH_BUFFER_TAG, n); |
394 fPathHeap->flatten(buffer); | 394 fPathHeap->flatten(buffer); |
395 } | 395 } |
396 } | 396 } |
397 | 397 |
398 void SkPicturePlayback::serialize(SkWStream* stream, | 398 void SkPictureData::serialize(SkWStream* stream, |
399 SkPicture::EncodeBitmap encoder) const { | 399 SkPicture::EncodeBitmap encoder) const { |
400 SkPicture::WriteTagSize(stream, SK_PICT_READER_TAG, fOpData->size()); | 400 SkPicture::WriteTagSize(stream, SK_PICT_READER_TAG, fOpData->size()); |
401 stream->write(fOpData->bytes(), fOpData->size()); | 401 stream->write(fOpData->bytes(), fOpData->size()); |
402 | 402 |
403 if (fPictureCount > 0) { | 403 if (fPictureCount > 0) { |
404 SkPicture::WriteTagSize(stream, SK_PICT_PICTURE_TAG, fPictureCount); | 404 SkPicture::WriteTagSize(stream, SK_PICT_PICTURE_TAG, fPictureCount); |
405 for (int i = 0; i < fPictureCount; i++) { | 405 for (int i = 0; i < fPictureCount; i++) { |
406 fPictureRefs[i]->serialize(stream, encoder); | 406 fPictureRefs[i]->serialize(stream, encoder); |
407 } | 407 } |
408 } | 408 } |
(...skipping 17 matching lines...) Expand all Loading... |
426 WriteFactories(stream, factSet); | 426 WriteFactories(stream, factSet); |
427 WriteTypefaces(stream, typefaceSet); | 427 WriteTypefaces(stream, typefaceSet); |
428 | 428 |
429 SkPicture::WriteTagSize(stream, SK_PICT_BUFFER_SIZE_TAG, buffer.bytesWri
tten()); | 429 SkPicture::WriteTagSize(stream, SK_PICT_BUFFER_SIZE_TAG, buffer.bytesWri
tten()); |
430 buffer.writeToStream(stream); | 430 buffer.writeToStream(stream); |
431 } | 431 } |
432 | 432 |
433 stream->write32(SK_PICT_EOF_TAG); | 433 stream->write32(SK_PICT_EOF_TAG); |
434 } | 434 } |
435 | 435 |
436 void SkPicturePlayback::flatten(SkWriteBuffer& buffer) const { | 436 void SkPictureData::flatten(SkWriteBuffer& buffer) const { |
437 SkPicture::WriteTagSize(buffer, SK_PICT_READER_TAG, fOpData->size()); | 437 SkPicture::WriteTagSize(buffer, SK_PICT_READER_TAG, fOpData->size()); |
438 buffer.writeByteArray(fOpData->bytes(), fOpData->size()); | 438 buffer.writeByteArray(fOpData->bytes(), fOpData->size()); |
439 | 439 |
440 if (fPictureCount > 0) { | 440 if (fPictureCount > 0) { |
441 SkPicture::WriteTagSize(buffer, SK_PICT_PICTURE_TAG, fPictureCount); | 441 SkPicture::WriteTagSize(buffer, SK_PICT_PICTURE_TAG, fPictureCount); |
442 for (int i = 0; i < fPictureCount; i++) { | 442 for (int i = 0; i < fPictureCount; i++) { |
443 fPictureRefs[i]->flatten(buffer); | 443 fPictureRefs[i]->flatten(buffer); |
444 } | 444 } |
445 } | 445 } |
446 | 446 |
(...skipping 20 matching lines...) Expand all Loading... |
467 | 467 |
468 uint32_t rbMask = 0; | 468 uint32_t rbMask = 0; |
469 for (size_t i = 0; i < SK_ARRAY_COUNT(gSD); ++i) { | 469 for (size_t i = 0; i < SK_ARRAY_COUNT(gSD); ++i) { |
470 if (pictInfoFlags & gSD[i].fSrc) { | 470 if (pictInfoFlags & gSD[i].fSrc) { |
471 rbMask |= gSD[i].fDst; | 471 rbMask |= gSD[i].fDst; |
472 } | 472 } |
473 } | 473 } |
474 return rbMask; | 474 return rbMask; |
475 } | 475 } |
476 | 476 |
477 bool SkPicturePlayback::parseStreamTag(SkStream* stream, | 477 bool SkPictureData::parseStreamTag(SkStream* stream, |
478 uint32_t tag, | 478 uint32_t tag, |
479 uint32_t size, | 479 uint32_t size, |
480 SkPicture::InstallPixelRefProc proc) { | 480 SkPicture::InstallPixelRefProc proc) { |
481 /* | 481 /* |
482 * By the time we encounter BUFFER_SIZE_TAG, we need to have already seen | 482 * By the time we encounter BUFFER_SIZE_TAG, we need to have already seen |
483 * its dependents: FACTORY_TAG and TYPEFACE_TAG. These two are not required | 483 * its dependents: FACTORY_TAG and TYPEFACE_TAG. These two are not required |
484 * but if they are present, they need to have been seen before the buffer. | 484 * but if they are present, they need to have been seen before the buffer. |
485 * | 485 * |
486 * We assert that if/when we see either of these, that we have not yet seen | 486 * We assert that if/when we see either of these, that we have not yet seen |
487 * the buffer tag, because if we have, then its too-late to deal with the | 487 * the buffer tag, because if we have, then its too-late to deal with the |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 if (!this->parseBufferTag(buffer, tag, size)) { | 579 if (!this->parseBufferTag(buffer, tag, size)) { |
580 return false; | 580 return false; |
581 } | 581 } |
582 } | 582 } |
583 SkDEBUGCODE(haveBuffer = true;) | 583 SkDEBUGCODE(haveBuffer = true;) |
584 } break; | 584 } break; |
585 } | 585 } |
586 return true; // success | 586 return true; // success |
587 } | 587 } |
588 | 588 |
589 bool SkPicturePlayback::parseBufferTag(SkReadBuffer& buffer, | 589 bool SkPictureData::parseBufferTag(SkReadBuffer& buffer, |
590 uint32_t tag, uint32_t size) { | 590 uint32_t tag, uint32_t size) { |
591 switch (tag) { | 591 switch (tag) { |
592 case SK_PICT_BITMAP_BUFFER_TAG: { | 592 case SK_PICT_BITMAP_BUFFER_TAG: { |
593 const int count = SkToInt(size); | 593 const int count = SkToInt(size); |
594 fBitmaps = SkTRefArray<SkBitmap>::Create(size); | 594 fBitmaps = SkTRefArray<SkBitmap>::Create(size); |
595 for (int i = 0; i < count; ++i) { | 595 for (int i = 0; i < count; ++i) { |
596 SkBitmap* bm = &fBitmaps->writableAt(i); | 596 SkBitmap* bm = &fBitmaps->writableAt(i); |
597 buffer.readBitmap(bm); | 597 buffer.readBitmap(bm); |
598 bm->setImmutable(); | 598 bm->setImmutable(); |
599 } | 599 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 return false; | 645 return false; |
646 } | 646 } |
647 } break; | 647 } break; |
648 default: | 648 default: |
649 // The tag was invalid. | 649 // The tag was invalid. |
650 return false; | 650 return false; |
651 } | 651 } |
652 return true; // success | 652 return true; // success |
653 } | 653 } |
654 | 654 |
655 SkPicturePlayback* SkPicturePlayback::CreateFromStream(SkStream* stream, | 655 SkPictureData* SkPictureData::CreateFromStream(SkStream* stream, |
656 const SkPictInfo& info, | 656 const SkPictInfo& info, |
657 SkPicture::InstallPixelRe
fProc proc) { | 657 SkPicture::InstallPixelRefProc pr
oc) { |
658 SkAutoTDelete<SkPicturePlayback> playback(SkNEW_ARGS(SkPicturePlayback, (inf
o))); | 658 SkAutoTDelete<SkPictureData> data(SkNEW_ARGS(SkPictureData, (info))); |
659 | 659 |
660 if (!playback->parseStream(stream, proc)) { | 660 if (!data->parseStream(stream, proc)) { |
661 return NULL; | 661 return NULL; |
662 } | 662 } |
663 return playback.detach(); | 663 return data.detach(); |
664 } | 664 } |
665 | 665 |
666 SkPicturePlayback* SkPicturePlayback::CreateFromBuffer(SkReadBuffer& buffer, | 666 SkPictureData* SkPictureData::CreateFromBuffer(SkReadBuffer& buffer, |
667 const SkPictInfo& info) { | 667 const SkPictInfo& info) { |
668 SkAutoTDelete<SkPicturePlayback> playback(SkNEW_ARGS(SkPicturePlayback, (inf
o))); | 668 SkAutoTDelete<SkPictureData> data(SkNEW_ARGS(SkPictureData, (info))); |
669 buffer.setVersion(info.fVersion); | 669 buffer.setVersion(info.fVersion); |
670 | 670 |
671 if (!playback->parseBuffer(buffer)) { | 671 if (!data->parseBuffer(buffer)) { |
672 return NULL; | 672 return NULL; |
673 } | 673 } |
674 return playback.detach(); | 674 return data.detach(); |
675 } | 675 } |
676 | 676 |
677 bool SkPicturePlayback::parseStream(SkStream* stream, | 677 bool SkPictureData::parseStream(SkStream* stream, |
678 SkPicture::InstallPixelRefProc proc) { | 678 SkPicture::InstallPixelRefProc proc) { |
679 for (;;) { | 679 for (;;) { |
680 uint32_t tag = stream->readU32(); | 680 uint32_t tag = stream->readU32(); |
681 if (SK_PICT_EOF_TAG == tag) { | 681 if (SK_PICT_EOF_TAG == tag) { |
682 break; | 682 break; |
683 } | 683 } |
684 | 684 |
685 uint32_t size = stream->readU32(); | 685 uint32_t size = stream->readU32(); |
686 if (!this->parseStreamTag(stream, tag, size, proc)) { | 686 if (!this->parseStreamTag(stream, tag, size, proc)) { |
687 return false; // we're invalid | 687 return false; // we're invalid |
688 } | 688 } |
689 } | 689 } |
690 return true; | 690 return true; |
691 } | 691 } |
692 | 692 |
693 bool SkPicturePlayback::parseBuffer(SkReadBuffer& buffer) { | 693 bool SkPictureData::parseBuffer(SkReadBuffer& buffer) { |
694 for (;;) { | 694 for (;;) { |
695 uint32_t tag = buffer.readUInt(); | 695 uint32_t tag = buffer.readUInt(); |
696 if (SK_PICT_EOF_TAG == tag) { | 696 if (SK_PICT_EOF_TAG == tag) { |
697 break; | 697 break; |
698 } | 698 } |
699 | 699 |
700 uint32_t size = buffer.readUInt(); | 700 uint32_t size = buffer.readUInt(); |
701 if (!this->parseBufferTag(buffer, tag, size)) { | 701 if (!this->parseBufferTag(buffer, tag, size)) { |
702 return false; // we're invalid | 702 return false; // we're invalid |
703 } | 703 } |
(...skipping 15 matching lines...) Expand all Loading... |
719 } | 719 } |
720 | 720 |
721 void recordSkip(size_t bytes) { | 721 void recordSkip(size_t bytes) { |
722 fCount += 1; | 722 fCount += 1; |
723 fSize += bytes; | 723 fSize += bytes; |
724 } | 724 } |
725 }; | 725 }; |
726 #endif | 726 #endif |
727 | 727 |
728 #ifdef SK_DEVELOPER | 728 #ifdef SK_DEVELOPER |
729 bool SkPicturePlayback::preDraw(int opIndex, int type) { | 729 bool SkPictureData::preDraw(int opIndex, int type) { |
730 return false; | 730 return false; |
731 } | 731 } |
732 | 732 |
733 void SkPicturePlayback::postDraw(int opIndex) { | 733 void SkPictureData::postDraw(int opIndex) { |
734 } | 734 } |
735 #endif | 735 #endif |
736 | 736 |
737 /* | 737 /* |
738 * Read the next op code and chunk size from 'reader'. The returned size | 738 * Read the next op code and chunk size from 'reader'. The returned size |
739 * is the entire size of the chunk (including the opcode). Thus, the | 739 * is the entire size of the chunk (including the opcode). Thus, the |
740 * offset just prior to calling read_op_and_size + 'size' is the offset | 740 * offset just prior to calling read_op_and_size + 'size' is the offset |
741 * to the next chunk's op code. This also means that the size of a chunk | 741 * to the next chunk's op code. This also means that the size of a chunk |
742 * with no arguments (just an opcode) will be 4. | 742 * with no arguments (just an opcode) will be 4. |
743 */ | 743 */ |
744 static DrawType read_op_and_size(SkReader32* reader, uint32_t* size) { | 744 static DrawType read_op_and_size(SkReader32* reader, uint32_t* size) { |
745 uint32_t temp = reader->readInt(); | 745 uint32_t temp = reader->readInt(); |
746 uint32_t op; | 746 uint32_t op; |
747 if (((uint8_t) temp) == temp) { | 747 if (((uint8_t) temp) == temp) { |
748 // old skp file - no size information | 748 // old skp file - no size information |
749 op = temp; | 749 op = temp; |
750 *size = 0; | 750 *size = 0; |
751 } else { | 751 } else { |
752 UNPACK_8_24(temp, op, *size); | 752 UNPACK_8_24(temp, op, *size); |
753 if (MASK_24 == *size) { | 753 if (MASK_24 == *size) { |
754 *size = reader->readInt(); | 754 *size = reader->readInt(); |
755 } | 755 } |
756 } | 756 } |
757 return (DrawType) op; | 757 return (DrawType) op; |
758 } | 758 } |
759 | 759 |
760 uint32_t SkPicturePlayback::CachedOperationList::offset(int index) const { | 760 uint32_t SkPictureData::CachedOperationList::offset(int index) const { |
761 SkASSERT(index < fOps.count()); | 761 SkASSERT(index < fOps.count()); |
762 return ((SkPictureStateTree::Draw*)fOps[index])->fOffset; | 762 return ((SkPictureStateTree::Draw*)fOps[index])->fOffset; |
763 } | 763 } |
764 | 764 |
765 const SkMatrix& SkPicturePlayback::CachedOperationList::matrix(int index) const
{ | 765 const SkMatrix& SkPictureData::CachedOperationList::matrix(int index) const { |
766 SkASSERT(index < fOps.count()); | 766 SkASSERT(index < fOps.count()); |
767 return *((SkPictureStateTree::Draw*)fOps[index])->fMatrix; | 767 return *((SkPictureStateTree::Draw*)fOps[index])->fMatrix; |
768 } | 768 } |
769 | 769 |
770 const SkPicture::OperationList& SkPicturePlayback::getActiveOps(const SkIRect& q
uery) { | 770 const SkPicture::OperationList& SkPictureData::getActiveOps(const SkIRect& query
) { |
771 if (NULL == fStateTree || NULL == fBoundingHierarchy) { | 771 if (NULL == fStateTree || NULL == fBoundingHierarchy) { |
772 return SkPicture::OperationList::InvalidList(); | 772 return SkPicture::OperationList::InvalidList(); |
773 } | 773 } |
774 | 774 |
775 if (NULL == fCachedActiveOps) { | 775 if (NULL == fCachedActiveOps) { |
776 fCachedActiveOps = SkNEW(CachedOperationList); | 776 fCachedActiveOps = SkNEW(CachedOperationList); |
777 } | 777 } |
778 | 778 |
779 if (query == fCachedActiveOps->fCacheQueryRect) { | 779 if (query == fCachedActiveOps->fCacheQueryRect) { |
780 return *fCachedActiveOps; | 780 return *fCachedActiveOps; |
781 } | 781 } |
782 | 782 |
783 fCachedActiveOps->fOps.rewind(); | 783 fCachedActiveOps->fOps.rewind(); |
784 | 784 |
785 fBoundingHierarchy->search(query, &(fCachedActiveOps->fOps)); | 785 fBoundingHierarchy->search(query, &(fCachedActiveOps->fOps)); |
786 if (0 != fCachedActiveOps->fOps.count()) { | 786 if (0 != fCachedActiveOps->fOps.count()) { |
787 SkTQSort<SkPictureStateTree::Draw>( | 787 SkTQSort<SkPictureStateTree::Draw>( |
788 reinterpret_cast<SkPictureStateTree::Draw**>(fCachedActiveOps->fOps.
begin()), | 788 reinterpret_cast<SkPictureStateTree::Draw**>(fCachedActiveOps->fOps.
begin()), |
789 reinterpret_cast<SkPictureStateTree::Draw**>(fCachedActiveOps->fOps.
end()-1)); | 789 reinterpret_cast<SkPictureStateTree::Draw**>(fCachedActiveOps->fOps.
end()-1)); |
790 } | 790 } |
791 | 791 |
792 fCachedActiveOps->fCacheQueryRect = query; | 792 fCachedActiveOps->fCacheQueryRect = query; |
793 return *fCachedActiveOps; | 793 return *fCachedActiveOps; |
794 } | 794 } |
795 | 795 |
796 class SkAutoResetOpID { | 796 class SkAutoResetOpID { |
797 public: | 797 public: |
798 SkAutoResetOpID(SkPicturePlayback* playback) : fPlayback(playback) { } | 798 SkAutoResetOpID(SkPictureData* data) : fData(data) { } |
799 ~SkAutoResetOpID() { | 799 ~SkAutoResetOpID() { |
800 if (NULL != fPlayback) { | 800 if (NULL != fData) { |
801 fPlayback->resetOpID(); | 801 fData->resetOpID(); |
802 } | 802 } |
803 } | 803 } |
804 | 804 |
805 private: | 805 private: |
806 SkPicturePlayback* fPlayback; | 806 SkPictureData* fData; |
807 }; | 807 }; |
808 | 808 |
809 // TODO: Replace with hash or pass in "lastLookedUp" hint | 809 // TODO: Replace with hash or pass in "lastLookedUp" hint |
810 SkPicturePlayback::PlaybackReplacements::ReplacementInfo* | 810 SkPictureData::PlaybackReplacements::ReplacementInfo* |
811 SkPicturePlayback::PlaybackReplacements::lookupByStart(size_t start) { | 811 SkPictureData::PlaybackReplacements::lookupByStart(size_t start) { |
812 SkDEBUGCODE(this->validate()); | 812 SkDEBUGCODE(this->validate()); |
813 for (int i = 0; i < fReplacements.count(); ++i) { | 813 for (int i = 0; i < fReplacements.count(); ++i) { |
814 if (start == fReplacements[i].fStart) { | 814 if (start == fReplacements[i].fStart) { |
815 return &fReplacements[i]; | 815 return &fReplacements[i]; |
816 } else if (start < fReplacements[i].fStart) { | 816 } else if (start < fReplacements[i].fStart) { |
817 return NULL; // the ranges are monotonically increasing and non-ove
rlapping | 817 return NULL; // the ranges are monotonically increasing and non-ove
rlapping |
818 } | 818 } |
819 } | 819 } |
820 | 820 |
821 return NULL; | 821 return NULL; |
822 } | 822 } |
823 | 823 |
824 void SkPicturePlayback::draw(SkCanvas& canvas, SkDrawPictureCallback* callback)
{ | 824 void SkPictureData::draw(SkCanvas& canvas, SkDrawPictureCallback* callback) { |
825 SkAutoResetOpID aroi(this); | 825 SkAutoResetOpID aroi(this); |
826 SkASSERT(0 == fCurOffset); | 826 SkASSERT(0 == fCurOffset); |
827 | 827 |
828 #ifdef ENABLE_TIME_DRAW | 828 #ifdef ENABLE_TIME_DRAW |
829 SkAutoTime at("SkPicture::draw", 50); | 829 SkAutoTime at("SkPicture::draw", 50); |
830 #endif | 830 #endif |
831 | 831 |
832 #ifdef SPEW_CLIP_SKIPPING | 832 #ifdef SPEW_CLIP_SKIPPING |
833 SkipClipRec skipRect, skipRRect, skipRegion, skipPath, skipCull; | 833 SkipClipRec skipRect, skipRRect, skipRegion, skipPath, skipCull; |
834 int opCount = 0; | 834 int opCount = 0; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 if (offset >= fStop) { | 915 if (offset >= fStop) { |
916 uint32_t size; | 916 uint32_t size; |
917 SkDEBUGCODE(DrawType op =) read_op_and_size(&reader, &size); | 917 SkDEBUGCODE(DrawType op =) read_op_and_size(&reader, &size); |
918 SkASSERT(RESTORE == op); | 918 SkASSERT(RESTORE == op); |
919 return; | 919 return; |
920 } | 920 } |
921 } | 921 } |
922 | 922 |
923 if (NULL != fReplacements) { | 923 if (NULL != fReplacements) { |
924 // Potentially replace a block of operations with a single drawBitma
p call | 924 // Potentially replace a block of operations with a single drawBitma
p call |
925 SkPicturePlayback::PlaybackReplacements::ReplacementInfo* temp = | 925 SkPictureData::PlaybackReplacements::ReplacementInfo* temp = |
926 fReplacements->lookupByStart(reader.
offset()); | 926 fReplacements->lookupByStart(reader.
offset()); |
927 if (NULL != temp) { | 927 if (NULL != temp) { |
928 SkASSERT(NULL != temp->fBM); | 928 SkASSERT(NULL != temp->fBM); |
929 SkASSERT(NULL != temp->fPaint); | 929 SkASSERT(NULL != temp->fPaint); |
930 canvas.save(); | 930 canvas.save(); |
931 canvas.setMatrix(initialMatrix); | 931 canvas.setMatrix(initialMatrix); |
932 SkRect src = SkRect::Make(temp->fSrcRect); | 932 SkRect src = SkRect::Make(temp->fSrcRect); |
933 SkRect dst = SkRect::MakeXYWH(temp->fPos.fX, temp->fPos.fY, | 933 SkRect dst = SkRect::MakeXYWH(temp->fPos.fX, temp->fPos.fY, |
934 temp->fSrcRect.width(), | 934 temp->fSrcRect.width(), |
935 temp->fSrcRect.height()); | 935 temp->fSrcRect.height()); |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 size * 100 / reader.offset(), skipRect.fCount, skipRRect.fCount, | 1369 size * 100 / reader.offset(), skipRect.fCount, skipRRect.fCount, |
1370 skipPath.fCount, skipRegion.fCount, skipCull.fCount); | 1370 skipPath.fCount, skipRegion.fCount, skipCull.fCount); |
1371 SkDebugf("--- Total ops: %d\n", opCount); | 1371 SkDebugf("--- Total ops: %d\n", opCount); |
1372 } | 1372 } |
1373 #endif | 1373 #endif |
1374 // this->dumpSize(); | 1374 // this->dumpSize(); |
1375 } | 1375 } |
1376 | 1376 |
1377 | 1377 |
1378 #if SK_SUPPORT_GPU | 1378 #if SK_SUPPORT_GPU |
1379 bool SkPicturePlayback::suitableForGpuRasterization(GrContext* context, const ch
ar **reason, | 1379 bool SkPictureData::suitableForGpuRasterization(GrContext* context, const char *
*reason, |
1380 int sampleCount) const { | 1380 int sampleCount) const { |
1381 // TODO: the heuristic used here needs to be refined | 1381 // TODO: the heuristic used here needs to be refined |
1382 static const int kNumPaintWithPathEffectUsesTol = 1; | 1382 static const int kNumPaintWithPathEffectUsesTol = 1; |
1383 static const int kNumAAConcavePaths = 5; | 1383 static const int kNumAAConcavePaths = 5; |
1384 | 1384 |
1385 SkASSERT(fContentInfo.numAAHairlineConcavePaths() <= fContentInfo.numAAConca
vePaths()); | 1385 SkASSERT(fContentInfo.numAAHairlineConcavePaths() <= fContentInfo.numAAConca
vePaths()); |
1386 | 1386 |
1387 int numNonDashedPathEffects = fContentInfo.numPaintWithPathEffectUses() - | 1387 int numNonDashedPathEffects = fContentInfo.numPaintWithPathEffectUses() - |
1388 fContentInfo.numFastPathDashEffects(); | 1388 fContentInfo.numFastPathDashEffects(); |
1389 | 1389 |
(...skipping 13 matching lines...) Expand all Loading... |
1403 } | 1403 } |
1404 } else if ((fContentInfo.numAAConcavePaths() - fContentInfo.numAAHairlin
eConcavePaths()) | 1404 } else if ((fContentInfo.numAAConcavePaths() - fContentInfo.numAAHairlin
eConcavePaths()) |
1405 >= kNumAAConcavePaths) | 1405 >= kNumAAConcavePaths) |
1406 *reason = "Too many anti-aliased concave paths."; | 1406 *reason = "Too many anti-aliased concave paths."; |
1407 else | 1407 else |
1408 *reason = "Unknown reason for GPU unsuitability."; | 1408 *reason = "Unknown reason for GPU unsuitability."; |
1409 } | 1409 } |
1410 return ret; | 1410 return ret; |
1411 } | 1411 } |
1412 | 1412 |
1413 bool SkPicturePlayback::suitableForGpuRasterization(GrContext* context, const ch
ar **reason, | 1413 bool SkPictureData::suitableForGpuRasterization(GrContext* context, const char *
*reason, |
1414 GrPixelConfig config, SkScal
ar dpi) const { | 1414 GrPixelConfig config, SkScalar d
pi) const { |
1415 | 1415 |
1416 if (context != NULL) { | 1416 if (context != NULL) { |
1417 return this->suitableForGpuRasterization(context, reason, | 1417 return this->suitableForGpuRasterization(context, reason, |
1418 context->getRecommendedSampleCo
unt(config, dpi)); | 1418 context->getRecommendedSampleCo
unt(config, dpi)); |
1419 } else { | 1419 } else { |
1420 return this->suitableForGpuRasterization(NULL, reason); | 1420 return this->suitableForGpuRasterization(NULL, reason); |
1421 } | 1421 } |
1422 } | 1422 } |
1423 | 1423 |
1424 #endif | 1424 #endif |
1425 /////////////////////////////////////////////////////////////////////////////// | 1425 /////////////////////////////////////////////////////////////////////////////// |
1426 | 1426 |
1427 #ifdef SK_DEBUG_SIZE | 1427 #ifdef SK_DEBUG_SIZE |
1428 int SkPicturePlayback::size(size_t* sizePtr) { | 1428 int SkPictureData::size(size_t* sizePtr) { |
1429 int objects = bitmaps(sizePtr); | 1429 int objects = bitmaps(sizePtr); |
1430 objects += paints(sizePtr); | 1430 objects += paints(sizePtr); |
1431 objects += paths(sizePtr); | 1431 objects += paths(sizePtr); |
1432 objects += pictures(sizePtr); | 1432 objects += pictures(sizePtr); |
1433 objects += regions(sizePtr); | 1433 objects += regions(sizePtr); |
1434 *sizePtr = fOpData.size(); | 1434 *sizePtr = fOpData.size(); |
1435 return objects; | 1435 return objects; |
1436 } | 1436 } |
1437 | 1437 |
1438 int SkPicturePlayback::bitmaps(size_t* size) { | 1438 int SkPictureData::bitmaps(size_t* size) { |
1439 size_t result = 0; | 1439 size_t result = 0; |
1440 for (int index = 0; index < fBitmapCount; index++) { | 1440 for (int index = 0; index < fBitmapCount; index++) { |
1441 // const SkBitmap& bitmap = fBitmaps[index]; | 1441 // const SkBitmap& bitmap = fBitmaps[index]; |
1442 result += sizeof(SkBitmap); // bitmap->size(); | 1442 result += sizeof(SkBitmap); // bitmap->size(); |
1443 } | 1443 } |
1444 *size = result; | 1444 *size = result; |
1445 return fBitmapCount; | 1445 return fBitmapCount; |
1446 } | 1446 } |
1447 | 1447 |
1448 int SkPicturePlayback::paints(size_t* size) { | 1448 int SkPictureData::paints(size_t* size) { |
1449 size_t result = 0; | 1449 size_t result = 0; |
1450 for (int index = 0; index < fPaintCount; index++) { | 1450 for (int index = 0; index < fPaintCount; index++) { |
1451 // const SkPaint& paint = fPaints[index]; | 1451 // const SkPaint& paint = fPaints[index]; |
1452 result += sizeof(SkPaint); // paint->size(); | 1452 result += sizeof(SkPaint); // paint->size(); |
1453 } | 1453 } |
1454 *size = result; | 1454 *size = result; |
1455 return fPaintCount; | 1455 return fPaintCount; |
1456 } | 1456 } |
1457 | 1457 |
1458 int SkPicturePlayback::paths(size_t* size) { | 1458 int SkPictureData::paths(size_t* size) { |
1459 size_t result = 0; | 1459 size_t result = 0; |
1460 for (int index = 0; index < fPathCount; index++) { | 1460 for (int index = 0; index < fPathCount; index++) { |
1461 const SkPath& path = fPaths[index]; | 1461 const SkPath& path = fPaths[index]; |
1462 result += path.flatten(NULL); | 1462 result += path.flatten(NULL); |
1463 } | 1463 } |
1464 *size = result; | 1464 *size = result; |
1465 return fPathCount; | 1465 return fPathCount; |
1466 } | 1466 } |
1467 #endif | 1467 #endif |
1468 | 1468 |
1469 #ifdef SK_DEBUG_DUMP | 1469 #ifdef SK_DEBUG_DUMP |
1470 void SkPicturePlayback::dumpBitmap(const SkBitmap& bitmap) const { | 1470 void SkPictureData::dumpBitmap(const SkBitmap& bitmap) const { |
1471 char pBuffer[DUMP_BUFFER_SIZE]; | 1471 char pBuffer[DUMP_BUFFER_SIZE]; |
1472 char* bufferPtr = pBuffer; | 1472 char* bufferPtr = pBuffer; |
1473 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer), | 1473 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer), |
1474 "BitmapData bitmap%p = {", &bitmap); | 1474 "BitmapData bitmap%p = {", &bitmap); |
1475 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer), | 1475 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer), |
1476 "{kWidth, %d}, ", bitmap.width()); | 1476 "{kWidth, %d}, ", bitmap.width()); |
1477 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer), | 1477 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer), |
1478 "{kHeight, %d}, ", bitmap.height()); | 1478 "{kHeight, %d}, ", bitmap.height()); |
1479 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer), | 1479 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer), |
1480 "{kRowBytes, %d}, ", bitmap.rowBytes()); | 1480 "{kRowBytes, %d}, ", bitmap.rowBytes()); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1617 int textEncoding = paint.getTextEncoding(); | 1617 int textEncoding = paint.getTextEncoding(); |
1618 if (textEncoding != defaultPaint.getTextEncoding()) | 1618 if (textEncoding != defaultPaint.getTextEncoding()) |
1619 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), | 1619 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), |
1620 "{kTextEncoding, 0x%x}, ", textEncoding); | 1620 "{kTextEncoding, 0x%x}, ", textEncoding); |
1621 SkDebugf("%s{0}};\n", pBuffer); | 1621 SkDebugf("%s{0}};\n", pBuffer); |
1622 | 1622 |
1623 SkDebugf("PaintData paint%p = {paintPtrs%p, paintScalars%p, paintInts%p};\n"
, | 1623 SkDebugf("PaintData paint%p = {paintPtrs%p, paintScalars%p, paintInts%p};\n"
, |
1624 &paint, &paint, &paint, &paint); | 1624 &paint, &paint, &paint, &paint); |
1625 } | 1625 } |
1626 | 1626 |
1627 void SkPicturePlayback::dumpPath(const SkPath& path) const { | 1627 void SkPictureData::dumpPath(const SkPath& path) const { |
1628 SkDebugf("path dump unimplemented\n"); | 1628 SkDebugf("path dump unimplemented\n"); |
1629 } | 1629 } |
1630 | 1630 |
1631 void SkPicturePlayback::dumpPicture(const SkPicture& picture) const { | 1631 void SkPictureData::dumpPicture(const SkPicture& picture) const { |
1632 SkDebugf("picture dump unimplemented\n"); | 1632 SkDebugf("picture dump unimplemented\n"); |
1633 } | 1633 } |
1634 | 1634 |
1635 void SkPicturePlayback::dumpRegion(const SkRegion& region) const { | 1635 void SkPictureData::dumpRegion(const SkRegion& region) const { |
1636 SkDebugf("region dump unimplemented\n"); | 1636 SkDebugf("region dump unimplemented\n"); |
1637 } | 1637 } |
1638 | 1638 |
1639 int SkPicturePlayback::dumpDrawType(char* bufferPtr, char* buffer, DrawType draw
Type) { | 1639 int SkPictureData::dumpDrawType(char* bufferPtr, char* buffer, DrawType drawType
) { |
1640 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), | 1640 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), |
1641 "k%s, ", DrawTypeToString(drawType)); | 1641 "k%s, ", DrawTypeToString(drawType)); |
1642 } | 1642 } |
1643 | 1643 |
1644 int SkPicturePlayback::dumpInt(char* bufferPtr, char* buffer, char* name) { | 1644 int SkPictureData::dumpInt(char* bufferPtr, char* buffer, char* name) { |
1645 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), | 1645 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), |
1646 "%s:%d, ", name, getInt()); | 1646 "%s:%d, ", name, getInt()); |
1647 } | 1647 } |
1648 | 1648 |
1649 int SkPicturePlayback::dumpRect(char* bufferPtr, char* buffer, char* name) { | 1649 int SkPictureData::dumpRect(char* bufferPtr, char* buffer, char* name) { |
1650 const SkRect* rect = fReader.skipRect(); | 1650 const SkRect* rect = fReader.skipRect(); |
1651 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), | 1651 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), |
1652 "%s:{l:%g t:%g r:%g b:%g}, ", name, SkScalarToFloat(rect.fLeft), | 1652 "%s:{l:%g t:%g r:%g b:%g}, ", name, SkScalarToFloat(rect.fLeft), |
1653 SkScalarToFloat(rect.fTop), | 1653 SkScalarToFloat(rect.fTop), |
1654 SkScalarToFloat(rect.fRight), SkScalarToFloat(rect.fBottom)); | 1654 SkScalarToFloat(rect.fRight), SkScalarToFloat(rect.fBottom)); |
1655 } | 1655 } |
1656 | 1656 |
1657 int SkPicturePlayback::dumpPoint(char* bufferPtr, char* buffer, char* name) { | 1657 int SkPictureData::dumpPoint(char* bufferPtr, char* buffer, char* name) { |
1658 SkPoint pt; | 1658 SkPoint pt; |
1659 getPoint(&pt); | 1659 getPoint(&pt); |
1660 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), | 1660 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), |
1661 "%s:{x:%g y:%g}, ", name, SkScalarToFloat(pt.fX), | 1661 "%s:{x:%g y:%g}, ", name, SkScalarToFloat(pt.fX), |
1662 SkScalarToFloat(pt.fY)); | 1662 SkScalarToFloat(pt.fY)); |
1663 } | 1663 } |
1664 | 1664 |
1665 void SkPicturePlayback::dumpPointArray(char** bufferPtrPtr, char* buffer, int co
unt) { | 1665 void SkPictureData::dumpPointArray(char** bufferPtrPtr, char* buffer, int count)
{ |
1666 char* bufferPtr = *bufferPtrPtr; | 1666 char* bufferPtr = *bufferPtrPtr; |
1667 const SkPoint* pts = (const SkPoint*)fReadStream.getAtPos(); | 1667 const SkPoint* pts = (const SkPoint*)fReadStream.getAtPos(); |
1668 fReadStream.skip(sizeof(SkPoint) * count); | 1668 fReadStream.skip(sizeof(SkPoint) * count); |
1669 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), | 1669 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), |
1670 "count:%d {", count); | 1670 "count:%d {", count); |
1671 for (int index = 0; index < count; index++) | 1671 for (int index = 0; index < count; index++) |
1672 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer)
, | 1672 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer)
, |
1673 "{x:%g y:%g}, ", SkScalarToFloat(pts[index].fX), | 1673 "{x:%g y:%g}, ", SkScalarToFloat(pts[index].fX), |
1674 SkScalarToFloat(pts[index].fY)); | 1674 SkScalarToFloat(pts[index].fY)); |
1675 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), | 1675 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), |
1676 "} "); | 1676 "} "); |
1677 *bufferPtrPtr = bufferPtr; | 1677 *bufferPtrPtr = bufferPtr; |
1678 } | 1678 } |
1679 | 1679 |
1680 int SkPicturePlayback::dumpPtr(char* bufferPtr, char* buffer, char* name, void*
ptr) { | 1680 int SkPictureData::dumpPtr(char* bufferPtr, char* buffer, char* name, void* ptr)
{ |
1681 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), | 1681 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), |
1682 "%s:%p, ", name, ptr); | 1682 "%s:%p, ", name, ptr); |
1683 } | 1683 } |
1684 | 1684 |
1685 int SkPicturePlayback::dumpRectPtr(char* bufferPtr, char* buffer, char* name) { | 1685 int SkPictureData::dumpRectPtr(char* bufferPtr, char* buffer, char* name) { |
1686 char result; | 1686 char result; |
1687 fReadStream.read(&result, sizeof(result)); | 1687 fReadStream.read(&result, sizeof(result)); |
1688 if (result) | 1688 if (result) |
1689 return dumpRect(bufferPtr, buffer, name); | 1689 return dumpRect(bufferPtr, buffer, name); |
1690 else | 1690 else |
1691 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), | 1691 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), |
1692 "%s:NULL, ", name); | 1692 "%s:NULL, ", name); |
1693 } | 1693 } |
1694 | 1694 |
1695 int SkPicturePlayback::dumpScalar(char* bufferPtr, char* buffer, char* name) { | 1695 int SkPictureData::dumpScalar(char* bufferPtr, char* buffer, char* name) { |
1696 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), | 1696 return snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - buffer), |
1697 "%s:%d, ", name, getScalar()); | 1697 "%s:%d, ", name, getScalar()); |
1698 } | 1698 } |
1699 | 1699 |
1700 void SkPicturePlayback::dumpText(char** bufferPtrPtr, char* buffer) { | 1700 void SkPictureData::dumpText(char** bufferPtrPtr, char* buffer) { |
1701 char* bufferPtr = *bufferPtrPtr; | 1701 char* bufferPtr = *bufferPtrPtr; |
1702 int length = getInt(); | 1702 int length = getInt(); |
1703 bufferPtr += dumpDrawType(bufferPtr, buffer); | 1703 bufferPtr += dumpDrawType(bufferPtr, buffer); |
1704 fReadStream.skipToAlign4(); | 1704 fReadStream.skipToAlign4(); |
1705 char* text = (char*) fReadStream.getAtPos(); | 1705 char* text = (char*) fReadStream.getAtPos(); |
1706 fReadStream.skip(length); | 1706 fReadStream.skip(length); |
1707 bufferPtr += dumpInt(bufferPtr, buffer, "length"); | 1707 bufferPtr += dumpInt(bufferPtr, buffer, "length"); |
1708 int limit = DUMP_BUFFER_SIZE - (bufferPtr - buffer) - 2; | 1708 int limit = DUMP_BUFFER_SIZE - (bufferPtr - buffer) - 2; |
1709 length >>= 1; | 1709 length >>= 1; |
1710 if (limit > length) | 1710 if (limit > length) |
(...skipping 29 matching lines...) Expand all Loading... |
1740 | 1740 |
1741 #define DUMP_PTR(name, ptr) \ | 1741 #define DUMP_PTR(name, ptr) \ |
1742 bufferPtr += dumpPtr(bufferPtr, buffer, #name, (void*) ptr) | 1742 bufferPtr += dumpPtr(bufferPtr, buffer, #name, (void*) ptr) |
1743 | 1743 |
1744 #define DUMP_SCALAR(name) \ | 1744 #define DUMP_SCALAR(name) \ |
1745 bufferPtr += dumpScalar(bufferPtr, buffer, #name) | 1745 bufferPtr += dumpScalar(bufferPtr, buffer, #name) |
1746 | 1746 |
1747 #define DUMP_TEXT() \ | 1747 #define DUMP_TEXT() \ |
1748 dumpText(&bufferPtr, buffer) | 1748 dumpText(&bufferPtr, buffer) |
1749 | 1749 |
1750 void SkPicturePlayback::dumpStream() { | 1750 void SkPictureData::dumpStream() { |
1751 SkDebugf("RecordStream stream = {\n"); | 1751 SkDebugf("RecordStream stream = {\n"); |
1752 DrawType drawType; | 1752 DrawType drawType; |
1753 TextContainer text; | 1753 TextContainer text; |
1754 fReadStream.rewind(); | 1754 fReadStream.rewind(); |
1755 char buffer[DUMP_BUFFER_SIZE], * bufferPtr; | 1755 char buffer[DUMP_BUFFER_SIZE], * bufferPtr; |
1756 while (fReadStream.read(&drawType, sizeof(drawType))) { | 1756 while (fReadStream.read(&drawType, sizeof(drawType))) { |
1757 bufferPtr = buffer; | 1757 bufferPtr = buffer; |
1758 DUMP_DRAWTYPE(drawType); | 1758 DUMP_DRAWTYPE(drawType); |
1759 switch (drawType) { | 1759 switch (drawType) { |
1760 case CLIP_PATH: { | 1760 case CLIP_PATH: { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1859 DUMP_SCALAR(dx); | 1859 DUMP_SCALAR(dx); |
1860 DUMP_SCALAR(dy); | 1860 DUMP_SCALAR(dy); |
1861 } break; | 1861 } break; |
1862 default: | 1862 default: |
1863 SkASSERT(0); | 1863 SkASSERT(0); |
1864 } | 1864 } |
1865 SkDebugf("%s\n", buffer); | 1865 SkDebugf("%s\n", buffer); |
1866 } | 1866 } |
1867 } | 1867 } |
1868 | 1868 |
1869 void SkPicturePlayback::dump() const { | 1869 void SkPictureData::dump() const { |
1870 char pBuffer[DUMP_BUFFER_SIZE]; | 1870 char pBuffer[DUMP_BUFFER_SIZE]; |
1871 char* bufferPtr = pBuffer; | 1871 char* bufferPtr = pBuffer; |
1872 int index; | 1872 int index; |
1873 if (fBitmapCount > 0) | 1873 if (fBitmapCount > 0) |
1874 SkDebugf("// bitmaps (%d)\n", fBitmapCount); | 1874 SkDebugf("// bitmaps (%d)\n", fBitmapCount); |
1875 for (index = 0; index < fBitmapCount; index++) { | 1875 for (index = 0; index < fBitmapCount; index++) { |
1876 const SkBitmap& bitmap = fBitmaps[index]; | 1876 const SkBitmap& bitmap = fBitmaps[index]; |
1877 dumpBitmap(bitmap); | 1877 dumpBitmap(bitmap); |
1878 } | 1878 } |
1879 if (fBitmapCount > 0) | 1879 if (fBitmapCount > 0) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1922 bufferPtr = pBuffer; | 1922 bufferPtr = pBuffer; |
1923 if (fPictureCount > 0) | 1923 if (fPictureCount > 0) |
1924 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), | 1924 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), |
1925 "Pictures pictures = {"); | 1925 "Pictures pictures = {"); |
1926 for (index = 0; index < fPictureCount; index++) | 1926 for (index = 0; index < fPictureCount; index++) |
1927 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), | 1927 bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer
), |
1928 "picture%p, ", fPictureRefs[index]); | 1928 "picture%p, ", fPictureRefs[index]); |
1929 if (fPictureCount > 0) | 1929 if (fPictureCount > 0) |
1930 SkDebugf("%s0};\n", pBuffer); | 1930 SkDebugf("%s0};\n", pBuffer); |
1931 | 1931 |
1932 const_cast<SkPicturePlayback*>(this)->dumpStream(); | 1932 const_cast<SkPictureData*>(this)->dumpStream(); |
1933 } | 1933 } |
1934 | 1934 |
1935 #endif | 1935 #endif |
OLD | NEW |