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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 >= kNumAAConcavePathsTol) | 250 >= kNumAAConcavePathsTol) |
251 *reason = "Too many anti-aliased concave paths."; | 251 *reason = "Too many anti-aliased concave paths."; |
252 else | 252 else |
253 *reason = "Unknown reason for GPU unsuitability."; | 253 *reason = "Unknown reason for GPU unsuitability."; |
254 } | 254 } |
255 return ret; | 255 return ret; |
256 } | 256 } |
257 | 257 |
258 /////////////////////////////////////////////////////////////////////////////// | 258 /////////////////////////////////////////////////////////////////////////////// |
259 | 259 |
| 260 int SkPicture::drawableCount() const { |
| 261 if (fDrawablePicts.get()) { |
| 262 return SkToInt(fDrawablePicts->size() / sizeof(SkPicture*)); |
| 263 } else { |
| 264 return 0; |
| 265 } |
| 266 } |
| 267 |
| 268 SkPicture* const* SkPicture::drawablePicts() const { |
| 269 if (fDrawablePicts) { |
| 270 return reinterpret_cast<SkPicture* const*>(fDrawablePicts->data()); |
| 271 } |
| 272 return NULL; |
| 273 } |
| 274 |
260 SkPicture::~SkPicture() { | 275 SkPicture::~SkPicture() { |
261 this->callDeletionListeners(); | 276 this->callDeletionListeners(); |
| 277 |
| 278 const int count = this->drawableCount(); |
| 279 SkPicture* const* pics = this->drawablePicts(); |
| 280 for (int i = 0; i < count; ++i) { |
| 281 pics[i]->unref(); |
| 282 } |
262 } | 283 } |
263 | 284 |
264 void SkPicture::EXPERIMENTAL_addAccelData(const SkPicture::AccelData* data) cons
t { | 285 void SkPicture::EXPERIMENTAL_addAccelData(const SkPicture::AccelData* data) cons
t { |
265 fAccelData.reset(SkRef(data)); | 286 fAccelData.reset(SkRef(data)); |
266 } | 287 } |
267 | 288 |
268 const SkPicture::AccelData* SkPicture::EXPERIMENTAL_getAccelData( | 289 const SkPicture::AccelData* SkPicture::EXPERIMENTAL_getAccelData( |
269 SkPicture::AccelData::Key key) const { | 290 SkPicture::AccelData::Key key) const { |
270 if (fAccelData.get() && fAccelData->getKey() == key) { | 291 if (fAccelData.get() && fAccelData->getKey() == key) { |
271 return fAccelData.get(); | 292 return fAccelData.get(); |
(...skipping 15 matching lines...) Expand all Loading... |
287 /////////////////////////////////////////////////////////////////////////////// | 308 /////////////////////////////////////////////////////////////////////////////// |
288 | 309 |
289 void SkPicture::playback(SkCanvas* canvas, SkDrawPictureCallback* callback) cons
t { | 310 void SkPicture::playback(SkCanvas* canvas, SkDrawPictureCallback* callback) cons
t { |
290 SkASSERT(canvas); | 311 SkASSERT(canvas); |
291 | 312 |
292 // If the query contains the whole picture, don't bother with the BBH. | 313 // If the query contains the whole picture, don't bother with the BBH. |
293 SkRect clipBounds = { 0, 0, 0, 0 }; | 314 SkRect clipBounds = { 0, 0, 0, 0 }; |
294 (void)canvas->getClipBounds(&clipBounds); | 315 (void)canvas->getClipBounds(&clipBounds); |
295 const bool useBBH = !clipBounds.contains(this->cullRect()); | 316 const bool useBBH = !clipBounds.contains(this->cullRect()); |
296 | 317 |
297 SkRecordDraw(*fRecord, canvas, useBBH ? fBBH.get() : NULL, callback); | 318 SkRecordDraw(*fRecord, canvas, this->drawablePicts(), this->drawableCount(), |
| 319 useBBH ? fBBH.get() : NULL, callback); |
298 } | 320 } |
299 | 321 |
300 /////////////////////////////////////////////////////////////////////////////// | 322 /////////////////////////////////////////////////////////////////////////////// |
301 | 323 |
302 #include "SkStream.h" | 324 #include "SkStream.h" |
303 | 325 |
304 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' }; | 326 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' }; |
305 | 327 |
306 bool SkPicture::IsValidPictInfo(const SkPictInfo& info) { | 328 bool SkPicture::IsValidPictInfo(const SkPictInfo& info) { |
307 if (0 != memcmp(info.fMagic, kMagic, sizeof(kMagic))) { | 329 if (0 != memcmp(info.fMagic, kMagic, sizeof(kMagic))) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 info->fFlags = SkPictInfo::kCrossProcess_Flag; | 459 info->fFlags = SkPictInfo::kCrossProcess_Flag; |
438 // TODO: remove this flag, since we're always float (now) | 460 // TODO: remove this flag, since we're always float (now) |
439 info->fFlags |= SkPictInfo::kScalarIsFloat_Flag; | 461 info->fFlags |= SkPictInfo::kScalarIsFloat_Flag; |
440 | 462 |
441 if (8 == sizeof(void*)) { | 463 if (8 == sizeof(void*)) { |
442 info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag; | 464 info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag; |
443 } | 465 } |
444 } | 466 } |
445 | 467 |
446 // This for compatibility with serialization code only. This is not cheap. | 468 // This for compatibility with serialization code only. This is not cheap. |
447 SkPictureData* SkPicture::Backport(const SkRecord& src, const SkPictInfo& info)
{ | 469 SkPictureData* SkPicture::Backport(const SkRecord& src, const SkPictInfo& info, |
| 470 SkPicture* const drawablePicts[], int drawabl
eCount) { |
448 SkPictureRecord rec(SkISize::Make(info.fCullRect.width(), info.fCullRect.hei
ght()), 0/*flags*/); | 471 SkPictureRecord rec(SkISize::Make(info.fCullRect.width(), info.fCullRect.hei
ght()), 0/*flags*/); |
449 rec.beginRecording(); | 472 rec.beginRecording(); |
450 SkRecordDraw(src, &rec, NULL/*bbh*/, NULL/*callback*/); | 473 SkRecordDraw(src, &rec, drawablePicts, drawableCount, NULL/*bbh*/, NULL/
*callback*/); |
451 rec.endRecording(); | 474 rec.endRecording(); |
452 return SkNEW_ARGS(SkPictureData, (rec, info, false/*deep copy ops?*/)); | 475 return SkNEW_ARGS(SkPictureData, (rec, info, false/*deep copy ops?*/)); |
453 } | 476 } |
454 | 477 |
455 | |
456 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { | 478 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { |
457 SkPictInfo info; | 479 SkPictInfo info; |
458 this->createHeader(&info); | 480 this->createHeader(&info); |
459 SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info)); | 481 SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info, this->drawablePic
ts(), |
| 482 this->drawableCount())); |
460 | 483 |
461 stream->write(&info, sizeof(info)); | 484 stream->write(&info, sizeof(info)); |
462 if (data) { | 485 if (data) { |
463 stream->writeBool(true); | 486 stream->writeBool(true); |
464 data->serialize(stream, encoder); | 487 data->serialize(stream, encoder); |
465 } else { | 488 } else { |
466 stream->writeBool(false); | 489 stream->writeBool(false); |
467 } | 490 } |
468 } | 491 } |
469 | 492 |
470 void SkPicture::flatten(SkWriteBuffer& buffer) const { | 493 void SkPicture::flatten(SkWriteBuffer& buffer) const { |
471 SkPictInfo info; | 494 SkPictInfo info; |
472 this->createHeader(&info); | 495 this->createHeader(&info); |
473 SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info)); | 496 SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info, this->drawablePic
ts(), |
| 497 this->drawableCount())); |
474 | 498 |
475 buffer.writeByteArray(&info.fMagic, sizeof(info.fMagic)); | 499 buffer.writeByteArray(&info.fMagic, sizeof(info.fMagic)); |
476 buffer.writeUInt(info.fVersion); | 500 buffer.writeUInt(info.fVersion); |
477 buffer.writeRect(info.fCullRect); | 501 buffer.writeRect(info.fCullRect); |
478 buffer.writeUInt(info.fFlags); | 502 buffer.writeUInt(info.fFlags); |
479 if (data) { | 503 if (data) { |
480 buffer.writeBool(true); | 504 buffer.writeBool(true); |
481 data->flatten(buffer); | 505 data->flatten(buffer); |
482 } else { | 506 } else { |
483 buffer.writeBool(false); | 507 buffer.writeBool(false); |
(...skipping 21 matching lines...) Expand all Loading... |
505 return genID; | 529 return genID; |
506 } | 530 } |
507 | 531 |
508 uint32_t SkPicture::uniqueID() const { | 532 uint32_t SkPicture::uniqueID() const { |
509 if (SK_InvalidGenID == fUniqueID) { | 533 if (SK_InvalidGenID == fUniqueID) { |
510 fUniqueID = next_picture_generation_id(); | 534 fUniqueID = next_picture_generation_id(); |
511 } | 535 } |
512 return fUniqueID; | 536 return fUniqueID; |
513 } | 537 } |
514 | 538 |
515 SkPicture::SkPicture(SkScalar width, SkScalar height, SkRecord* record, SkBBoxHi
erarchy* bbh) | 539 SkPicture::SkPicture(SkScalar width, SkScalar height, SkRecord* record, SkData*
drawablePicts, |
| 540 SkBBoxHierarchy* bbh) |
516 : fCullWidth(width) | 541 : fCullWidth(width) |
517 , fCullHeight(height) | 542 , fCullHeight(height) |
518 , fRecord(record) | 543 , fRecord(record) |
519 , fBBH(SkSafeRef(bbh)) | 544 , fBBH(SkSafeRef(bbh)) |
| 545 , fDrawablePicts(SkSafeRef(drawablePicts)) |
520 , fAnalysis(*fRecord) { | 546 , fAnalysis(*fRecord) { |
521 this->needsNewGenID(); | 547 this->needsNewGenID(); |
522 } | 548 } |
523 | 549 |
524 // Note that we are assuming that this entry point will only be called from | 550 // Note that we are assuming that this entry point will only be called from |
525 // one thread. Currently the only client of this method is | 551 // one thread. Currently the only client of this method is |
526 // SkGpuDevice::EXPERIMENTAL_optimize which should be only called from a single | 552 // SkGpuDevice::EXPERIMENTAL_optimize which should be only called from a single |
527 // thread. | 553 // thread. |
528 void SkPicture::addDeletionListener(DeletionListener* listener) const { | 554 void SkPicture::addDeletionListener(DeletionListener* listener) const { |
529 SkASSERT(listener); | 555 SkASSERT(listener); |
530 | 556 |
531 *fDeletionListeners.append() = SkRef(listener); | 557 *fDeletionListeners.append() = SkRef(listener); |
532 } | 558 } |
533 | 559 |
534 void SkPicture::callDeletionListeners() { | 560 void SkPicture::callDeletionListeners() { |
535 for (int i = 0; i < fDeletionListeners.count(); ++i) { | 561 for (int i = 0; i < fDeletionListeners.count(); ++i) { |
536 fDeletionListeners[i]->onDeletion(this->uniqueID()); | 562 fDeletionListeners[i]->onDeletion(this->uniqueID()); |
537 } | 563 } |
538 | 564 |
539 fDeletionListeners.unrefAll(); | 565 fDeletionListeners.unrefAll(); |
540 } | 566 } |
OLD | NEW |