Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: src/core/SkPicture.cpp

Issue 727363003: wip for drawables (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make the pictures in the array also const (the array already was const) Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkCanvasDrawable.cpp ('k') | src/core/SkPictureRecorder.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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* 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();
262 } 277 }
263 278
264 void SkPicture::EXPERIMENTAL_addAccelData(const SkPicture::AccelData* data) cons t { 279 void SkPicture::EXPERIMENTAL_addAccelData(const SkPicture::AccelData* data) cons t {
265 fAccelData.reset(SkRef(data)); 280 fAccelData.reset(SkRef(data));
266 } 281 }
267 282
268 const SkPicture::AccelData* SkPicture::EXPERIMENTAL_getAccelData( 283 const SkPicture::AccelData* SkPicture::EXPERIMENTAL_getAccelData(
269 SkPicture::AccelData::Key key) const { 284 SkPicture::AccelData::Key key) const {
(...skipping 17 matching lines...) Expand all
287 /////////////////////////////////////////////////////////////////////////////// 302 ///////////////////////////////////////////////////////////////////////////////
288 303
289 void SkPicture::playback(SkCanvas* canvas, SkDrawPictureCallback* callback) cons t { 304 void SkPicture::playback(SkCanvas* canvas, SkDrawPictureCallback* callback) cons t {
290 SkASSERT(canvas); 305 SkASSERT(canvas);
291 306
292 // If the query contains the whole picture, don't bother with the BBH. 307 // If the query contains the whole picture, don't bother with the BBH.
293 SkRect clipBounds = { 0, 0, 0, 0 }; 308 SkRect clipBounds = { 0, 0, 0, 0 };
294 (void)canvas->getClipBounds(&clipBounds); 309 (void)canvas->getClipBounds(&clipBounds);
295 const bool useBBH = !clipBounds.contains(this->cullRect()); 310 const bool useBBH = !clipBounds.contains(this->cullRect());
296 311
297 SkRecordDraw(*fRecord, canvas, useBBH ? fBBH.get() : NULL, callback); 312 SkRecordDraw(*fRecord, canvas, this->drawablePicts(), this->drawableCount(),
313 useBBH ? fBBH.get() : NULL, callback);
298 } 314 }
299 315
300 /////////////////////////////////////////////////////////////////////////////// 316 ///////////////////////////////////////////////////////////////////////////////
301 317
302 #include "SkStream.h" 318 #include "SkStream.h"
303 319
304 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' }; 320 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' };
305 321
306 bool SkPicture::IsValidPictInfo(const SkPictInfo& info) { 322 bool SkPicture::IsValidPictInfo(const SkPictInfo& info) {
307 if (0 != memcmp(info.fMagic, kMagic, sizeof(kMagic))) { 323 if (0 != memcmp(info.fMagic, kMagic, sizeof(kMagic))) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 info->fFlags = SkPictInfo::kCrossProcess_Flag; 453 info->fFlags = SkPictInfo::kCrossProcess_Flag;
438 // TODO: remove this flag, since we're always float (now) 454 // TODO: remove this flag, since we're always float (now)
439 info->fFlags |= SkPictInfo::kScalarIsFloat_Flag; 455 info->fFlags |= SkPictInfo::kScalarIsFloat_Flag;
440 456
441 if (8 == sizeof(void*)) { 457 if (8 == sizeof(void*)) {
442 info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag; 458 info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag;
443 } 459 }
444 } 460 }
445 461
446 // This for compatibility with serialization code only. This is not cheap. 462 // This for compatibility with serialization code only. This is not cheap.
447 SkPictureData* SkPicture::Backport(const SkRecord& src, const SkPictInfo& info) { 463 SkPictureData* SkPicture::Backport(const SkRecord& src, const SkPictInfo& info,
464 SkPicture const* const drawablePicts[], int d rawableCount) {
448 SkPictureRecord rec(SkISize::Make(info.fCullRect.width(), info.fCullRect.hei ght()), 0/*flags*/); 465 SkPictureRecord rec(SkISize::Make(info.fCullRect.width(), info.fCullRect.hei ght()), 0/*flags*/);
449 rec.beginRecording(); 466 rec.beginRecording();
450 SkRecordDraw(src, &rec, NULL/*bbh*/, NULL/*callback*/); 467 SkRecordDraw(src, &rec, drawablePicts, drawableCount, NULL/*bbh*/, NULL/ *callback*/);
451 rec.endRecording(); 468 rec.endRecording();
452 return SkNEW_ARGS(SkPictureData, (rec, info, false/*deep copy ops?*/)); 469 return SkNEW_ARGS(SkPictureData, (rec, info, false/*deep copy ops?*/));
453 } 470 }
454 471
455
456 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { 472 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const {
457 SkPictInfo info; 473 SkPictInfo info;
458 this->createHeader(&info); 474 this->createHeader(&info);
459 SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info)); 475 SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info, this->drawablePic ts(),
476 this->drawableCount()));
460 477
461 stream->write(&info, sizeof(info)); 478 stream->write(&info, sizeof(info));
462 if (data) { 479 if (data) {
463 stream->writeBool(true); 480 stream->writeBool(true);
464 data->serialize(stream, encoder); 481 data->serialize(stream, encoder);
465 } else { 482 } else {
466 stream->writeBool(false); 483 stream->writeBool(false);
467 } 484 }
468 } 485 }
469 486
470 void SkPicture::flatten(SkWriteBuffer& buffer) const { 487 void SkPicture::flatten(SkWriteBuffer& buffer) const {
471 SkPictInfo info; 488 SkPictInfo info;
472 this->createHeader(&info); 489 this->createHeader(&info);
473 SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info)); 490 SkAutoTDelete<SkPictureData> data(Backport(*fRecord, info, this->drawablePic ts(),
491 this->drawableCount()));
474 492
475 buffer.writeByteArray(&info.fMagic, sizeof(info.fMagic)); 493 buffer.writeByteArray(&info.fMagic, sizeof(info.fMagic));
476 buffer.writeUInt(info.fVersion); 494 buffer.writeUInt(info.fVersion);
477 buffer.writeRect(info.fCullRect); 495 buffer.writeRect(info.fCullRect);
478 buffer.writeUInt(info.fFlags); 496 buffer.writeUInt(info.fFlags);
479 if (data) { 497 if (data) {
480 buffer.writeBool(true); 498 buffer.writeBool(true);
481 data->flatten(buffer); 499 data->flatten(buffer);
482 } else { 500 } else {
483 buffer.writeBool(false); 501 buffer.writeBool(false);
(...skipping 21 matching lines...) Expand all
505 return genID; 523 return genID;
506 } 524 }
507 525
508 uint32_t SkPicture::uniqueID() const { 526 uint32_t SkPicture::uniqueID() const {
509 if (SK_InvalidGenID == fUniqueID) { 527 if (SK_InvalidGenID == fUniqueID) {
510 fUniqueID = next_picture_generation_id(); 528 fUniqueID = next_picture_generation_id();
511 } 529 }
512 return fUniqueID; 530 return fUniqueID;
513 } 531 }
514 532
515 SkPicture::SkPicture(SkScalar width, SkScalar height, SkRecord* record, SkBBoxHi erarchy* bbh) 533 SkPicture::SkPicture(SkScalar width, SkScalar height, SkRecord* record, SkData* drawablePicts,
534 SkBBoxHierarchy* bbh)
516 : fCullWidth(width) 535 : fCullWidth(width)
517 , fCullHeight(height) 536 , fCullHeight(height)
518 , fRecord(record) 537 , fRecord(record)
519 , fBBH(SkSafeRef(bbh)) 538 , fBBH(SkSafeRef(bbh))
539 , fDrawablePicts(SkSafeRef(drawablePicts))
520 , fAnalysis(*fRecord) { 540 , fAnalysis(*fRecord) {
521 this->needsNewGenID(); 541 this->needsNewGenID();
522 } 542 }
523 543
524 // Note that we are assuming that this entry point will only be called from 544 // 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 545 // one thread. Currently the only client of this method is
526 // SkGpuDevice::EXPERIMENTAL_optimize which should be only called from a single 546 // SkGpuDevice::EXPERIMENTAL_optimize which should be only called from a single
527 // thread. 547 // thread.
528 void SkPicture::addDeletionListener(DeletionListener* listener) const { 548 void SkPicture::addDeletionListener(DeletionListener* listener) const {
529 SkASSERT(listener); 549 SkASSERT(listener);
530 550
531 *fDeletionListeners.append() = SkRef(listener); 551 *fDeletionListeners.append() = SkRef(listener);
532 } 552 }
533 553
534 void SkPicture::callDeletionListeners() { 554 void SkPicture::callDeletionListeners() {
535 for (int i = 0; i < fDeletionListeners.count(); ++i) { 555 for (int i = 0; i < fDeletionListeners.count(); ++i) {
536 fDeletionListeners[i]->onDeletion(this->uniqueID()); 556 fDeletionListeners[i]->onDeletion(this->uniqueID());
537 } 557 }
538 558
539 fDeletionListeners.unrefAll(); 559 fDeletionListeners.unrefAll();
540 } 560 }
OLDNEW
« no previous file with comments | « src/core/SkCanvasDrawable.cpp ('k') | src/core/SkPictureRecorder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698