OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2007 The Android Open Source Project | 3 * Copyright 2007 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkPictureFlat.h" | 10 #include "SkPictureFlat.h" |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 int32_t id = sk_atomic_inc(&gNextID); | 305 int32_t id = sk_atomic_inc(&gNextID); |
306 if (id >= 1 << (8 * sizeof(Domain))) { | 306 if (id >= 1 << (8 * sizeof(Domain))) { |
307 SK_CRASH(); | 307 SK_CRASH(); |
308 } | 308 } |
309 | 309 |
310 return static_cast<Domain>(id); | 310 return static_cast<Domain>(id); |
311 } | 311 } |
312 | 312 |
313 /////////////////////////////////////////////////////////////////////////////// | 313 /////////////////////////////////////////////////////////////////////////////// |
314 | 314 |
315 #ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES | |
316 | |
317 SkCanvas* SkPicture::beginRecording(int width, int height, | |
318 uint32_t recordingFlags) { | |
319 if (fPlayback) { | |
320 SkDELETE(fPlayback); | |
321 fPlayback = NULL; | |
322 } | |
323 SkSafeUnref(fAccelData); | |
324 SkSafeSetNull(fRecord); | |
325 fContentInfo.reset(); | |
326 | |
327 this->needsNewGenID(); | |
328 | |
329 // Must be set before calling createBBoxHierarchy | |
330 fWidth = width; | |
331 fHeight = height; | |
332 | |
333 const SkISize size = SkISize::Make(width, height); | |
334 | |
335 if (recordingFlags & kOptimizeForClippedPlayback_RecordingFlag) { | |
336 SkBBoxHierarchy* tree = this->createBBoxHierarchy(); | |
337 SkASSERT(NULL != tree); | |
338 fRecord = SkNEW_ARGS(SkBBoxHierarchyRecord, (this, size, recordingFlags,
tree)); | |
339 tree->unref(); | |
340 } else { | |
341 fRecord = SkNEW_ARGS(SkPictureRecord, (this, size, recordingFlags)); | |
342 } | |
343 fRecord->beginRecording(); | |
344 | |
345 return fRecord; | |
346 } | |
347 | |
348 #endif | |
349 | |
350 SkCanvas* SkPicture::beginRecording(int width, int height, | 315 SkCanvas* SkPicture::beginRecording(int width, int height, |
351 SkBBHFactory* bbhFactory, | 316 SkBBHFactory* bbhFactory, |
352 uint32_t recordingFlags) { | 317 uint32_t recordingFlags) { |
353 if (fPlayback) { | 318 if (fPlayback) { |
354 SkDELETE(fPlayback); | 319 SkDELETE(fPlayback); |
355 fPlayback = NULL; | 320 fPlayback = NULL; |
356 } | 321 } |
357 SkSafeUnref(fAccelData); | 322 SkSafeUnref(fAccelData); |
358 SkSafeSetNull(fRecord); | 323 SkSafeSetNull(fRecord); |
359 SkASSERT(NULL == fPathHeap); | 324 SkASSERT(NULL == fPathHeap); |
360 fContentInfo.reset(); | 325 fContentInfo.reset(); |
361 | 326 |
362 this->needsNewGenID(); | 327 this->needsNewGenID(); |
363 | 328 |
364 fWidth = width; | 329 fWidth = width; |
365 fHeight = height; | 330 fHeight = height; |
366 | 331 |
367 const SkISize size = SkISize::Make(width, height); | 332 const SkISize size = SkISize::Make(width, height); |
368 | 333 |
369 if (NULL != bbhFactory) { | 334 if (NULL != bbhFactory) { |
370 SkAutoTUnref<SkBBoxHierarchy> tree((*bbhFactory)(width, height)); | 335 SkAutoTUnref<SkBBoxHierarchy> tree((*bbhFactory)(width, height)); |
371 SkASSERT(NULL != tree); | 336 SkASSERT(NULL != tree); |
372 fRecord = SkNEW_ARGS(SkBBoxHierarchyRecord, (this, size, | 337 fRecord = SkNEW_ARGS(SkBBoxHierarchyRecord, (this, size, recordingFlags,
tree.get())); |
373 recordingFlags| | |
374 kOptimizeForClippedPlayback
_RecordingFlag, | |
375 tree.get())); | |
376 } else { | 338 } else { |
377 fRecord = SkNEW_ARGS(SkPictureRecord, (this, size, recordingFlags)); | 339 fRecord = SkNEW_ARGS(SkPictureRecord, (this, size, recordingFlags)); |
378 } | 340 } |
379 fRecord->beginRecording(); | 341 fRecord->beginRecording(); |
380 | 342 |
381 return fRecord; | 343 return fRecord; |
382 } | 344 } |
383 | 345 |
384 | |
385 #ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES | |
386 | |
387 SkBBoxHierarchy* SkPicture::createBBoxHierarchy() const { | |
388 // TODO: this code is now replicated in SkRTreePicture. Once all external | |
389 // clients have been weaned off of kOptimizeForClippedPlayback_RecordingFlag
, | |
390 // this code can be removed. | |
391 | |
392 // These values were empirically determined to produce reasonable | |
393 // performance in most cases. | |
394 static const int kRTreeMinChildren = 6; | |
395 static const int kRTreeMaxChildren = 11; | |
396 | |
397 SkScalar aspectRatio = SkScalarDiv(SkIntToScalar(fWidth), | |
398 SkIntToScalar(fHeight)); | |
399 bool sortDraws = false; // Do not sort draw calls when bulk loading. | |
400 | |
401 return SkRTree::Create(kRTreeMinChildren, kRTreeMaxChildren, | |
402 aspectRatio, sortDraws); | |
403 } | |
404 | |
405 #endif | |
406 | |
407 SkCanvas* SkPicture::getRecordingCanvas() const { | 346 SkCanvas* SkPicture::getRecordingCanvas() const { |
408 // will be null if we are not recording | 347 // will be null if we are not recording |
409 return fRecord; | 348 return fRecord; |
410 } | 349 } |
411 | 350 |
412 void SkPicture::endRecording() { | 351 void SkPicture::endRecording() { |
413 if (NULL == fPlayback) { | 352 if (NULL == fPlayback) { |
414 if (NULL != fRecord) { | 353 if (NULL != fRecord) { |
415 fRecord->endRecording(); | 354 fRecord->endRecording(); |
416 SkPictInfo info; | 355 SkPictInfo info; |
417 this->createHeader(&info); | 356 this->createHeader(&info); |
418 fPlayback = SkNEW_ARGS(SkPicturePlayback, (this, *fRecord, info)); | 357 fPlayback = SkNEW_ARGS(SkPicturePlayback, (this, *fRecord, info)); |
419 SkSafeSetNull(fRecord); | 358 SkSafeSetNull(fRecord); |
420 } | 359 } |
421 } | 360 } |
422 SkASSERT(NULL == fRecord); | 361 SkASSERT(NULL == fRecord); |
423 } | 362 } |
424 | 363 |
425 const SkPicture::OperationList& SkPicture::OperationList::InvalidList() { | 364 const SkPicture::OperationList& SkPicture::OperationList::InvalidList() { |
426 static OperationList gInvalid; | 365 static OperationList gInvalid; |
427 return gInvalid; | 366 return gInvalid; |
428 } | 367 } |
429 | 368 |
430 const SkPicture::OperationList& SkPicture::EXPERIMENTAL_getActiveOps(const SkIRe
ct& queryRect) { | 369 const SkPicture::OperationList& SkPicture::EXPERIMENTAL_getActiveOps(const SkIRe
ct& queryRect) { |
431 this->endRecording(); // TODO: remove eventually | 370 SkASSERT(NULL != fPlayback && NULL == fRecord); |
432 if (NULL != fPlayback) { | 371 if (NULL != fPlayback) { |
433 return fPlayback->getActiveOps(queryRect); | 372 return fPlayback->getActiveOps(queryRect); |
434 } | 373 } |
435 return OperationList::InvalidList(); | 374 return OperationList::InvalidList(); |
436 } | 375 } |
437 | 376 |
438 size_t SkPicture::EXPERIMENTAL_curOpID() const { | 377 size_t SkPicture::EXPERIMENTAL_curOpID() const { |
439 if (NULL != fPlayback) { | 378 if (NULL != fPlayback) { |
440 return fPlayback->curOpID(); | 379 return fPlayback->curOpID(); |
441 } | 380 } |
442 return 0; | 381 return 0; |
443 } | 382 } |
444 | 383 |
445 void SkPicture::draw(SkCanvas* surface, SkDrawPictureCallback* callback) { | 384 void SkPicture::draw(SkCanvas* surface, SkDrawPictureCallback* callback) { |
446 this->endRecording(); // TODO: remove eventually | 385 SkASSERT(NULL != fPlayback && NULL == fRecord); |
447 if (NULL != fPlayback) { | 386 if (NULL != fPlayback) { |
448 fPlayback->draw(*surface, callback); | 387 fPlayback->draw(*surface, callback); |
449 } | 388 } |
450 } | 389 } |
451 | 390 |
452 /////////////////////////////////////////////////////////////////////////////// | 391 /////////////////////////////////////////////////////////////////////////////// |
453 | 392 |
454 #include "SkStream.h" | 393 #include "SkStream.h" |
455 | 394 |
456 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' }; | 395 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' }; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 if (NULL != fRecord) { | 645 if (NULL != fRecord) { |
707 SkASSERT(NULL == fPlayback); | 646 SkASSERT(NULL == fPlayback); |
708 return SK_InvalidGenID; | 647 return SK_InvalidGenID; |
709 } | 648 } |
710 | 649 |
711 if (SK_InvalidGenID == fUniqueID) { | 650 if (SK_InvalidGenID == fUniqueID) { |
712 fUniqueID = next_picture_generation_id(); | 651 fUniqueID = next_picture_generation_id(); |
713 } | 652 } |
714 return fUniqueID; | 653 return fUniqueID; |
715 } | 654 } |
OLD | NEW |