diff options
author | mtklein <mtklein@chromium.org> | 2014-11-21 11:06:04 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-21 11:06:04 -0800 |
commit | b7ee349f108040fbd5cb71d891d5b74a1843b0bc (patch) | |
tree | 4fc9e878e6aa5a7ef76b000cd226ff565b3e7014 /src/core | |
parent | 3f10b9dd2c9d256b77111e9669806785a54c7f54 (diff) |
SkData -> SkPicture::SnapshotArray
Restores type safety with all the same features.
(Also note, less code: 29 insertions, 50 deletions.)
BUG=skia:
Review URL: https://codereview.chromium.org/746553002
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkPicture.cpp | 13 | ||||
-rw-r--r-- | src/core/SkPictureRecorder.cpp | 5 | ||||
-rw-r--r-- | src/core/SkRecorder.cpp | 34 | ||||
-rw-r--r-- | src/core/SkRecorder.h | 5 |
4 files changed, 12 insertions, 45 deletions
diff --git a/src/core/SkPicture.cpp b/src/core/SkPicture.cpp index 4848345e51..a8e160f855 100644 --- a/src/core/SkPicture.cpp +++ b/src/core/SkPicture.cpp @@ -270,18 +270,11 @@ bool SkPicture::Analysis::suitableForGpuRasterization(const char** reason, /////////////////////////////////////////////////////////////////////////////// int SkPicture::drawableCount() const { - if (fDrawablePicts.get()) { - return SkToInt(fDrawablePicts->size() / sizeof(SkPicture*)); - } else { - return 0; - } + return fDrawablePicts.get() ? fDrawablePicts->count() : 0; } SkPicture const* const* SkPicture::drawablePicts() const { - if (fDrawablePicts) { - return reinterpret_cast<SkPicture* const*>(fDrawablePicts->data()); - } - return NULL; + return fDrawablePicts.get() ? fDrawablePicts->begin() : NULL; } SkPicture::~SkPicture() { @@ -524,7 +517,7 @@ bool SkPicture::hasText() const { return fAnalysis.fHasText; } bool SkPicture::willPlayBackBitmaps() const { return fAnalysis.fWillPlaybackBitmaps; } int SkPicture::approximateOpCount() const { return fRecord->count(); } -SkPicture::SkPicture(const SkRect& cullRect, SkRecord* record, SkData* drawablePicts, +SkPicture::SkPicture(const SkRect& cullRect, SkRecord* record, SnapshotArray* drawablePicts, SkBBoxHierarchy* bbh) : fUniqueID(next_picture_generation_id()) , fCullRect(cullRect) diff --git a/src/core/SkPictureRecorder.cpp b/src/core/SkPictureRecorder.cpp index aea9e389da..edee07b0e3 100644 --- a/src/core/SkPictureRecorder.cpp +++ b/src/core/SkPictureRecorder.cpp @@ -61,9 +61,10 @@ SkPicture* SkPictureRecorder::endRecording() { // TODO: we should remember these from our caller SkBBHFactory* factory = NULL; uint32_t recordFlags = 0; - SkAutoDataUnref drawablePicts(fRecorder->newDrawableSnapshot(factory, recordFlags)); + SkAutoTUnref<SkPicture::SnapshotArray> drawablePicts( + fRecorder->newDrawableSnapshot(factory, recordFlags)); SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullRect, fRecord.detach(), - drawablePicts, fBBH.get())); + drawablePicts.detach(), fBBH.get())); if (saveLayerData) { pict->EXPERIMENTAL_addAccelData(saveLayerData); diff --git a/src/core/SkRecorder.cpp b/src/core/SkRecorder.cpp index 3252e59f62..22d742f3e7 100644 --- a/src/core/SkRecorder.cpp +++ b/src/core/SkRecorder.cpp @@ -5,7 +5,6 @@ * found in the LICENSE file. */ -#include "SkData.h" #include "SkRecorder.h" #include "SkPatchUtils.h" #include "SkPicture.h" @@ -30,42 +29,17 @@ void SkRecorder::forgetRecord() { fRecord = NULL; } -// ReleaseProc for SkData, assuming the data was allocated via sk_malloc, and its contents are an -// array of SkPicture* which need to be unref'd. -// -static void unref_all_malloc_releaseProc(const void* ptr, size_t length, void* context) { - SkASSERT(ptr == context); // our context is our ptr, allocated via sk_malloc - int count = SkToInt(length / sizeof(SkPicture*)); - SkASSERT(count * sizeof(SkPicture*) == length); // our length is snug for the array - - SkPicture* const* array = reinterpret_cast<SkPicture* const*>(ptr); - for (int i = 0; i < count; ++i) { - SkSafeUnref(array[i]); - } - sk_free(context); -} - -// Return an uninitialized SkData sized for "count" SkPicture pointers. They will be unref'd when -// the SkData is destroyed. -// -static SkData* new_uninitialized_picture_ptrs(int count) { - size_t length = count * sizeof(SkPicture*); - void* array = sk_malloc_throw(length); - void* context = array; - return SkData::NewWithProc(array, length, unref_all_malloc_releaseProc, context); -} - -SkData* SkRecorder::newDrawableSnapshot(SkBBHFactory* factory, uint32_t recordFlags) { +SkPicture::SnapshotArray* SkRecorder::newDrawableSnapshot(SkBBHFactory* factory, + uint32_t recordFlags) { const int count = fDrawableList.count(); if (0 == count) { return NULL; } - SkData* data = new_uninitialized_picture_ptrs(count); - SkPicture** pics = reinterpret_cast<SkPicture**>(data->writable_data()); + SkAutoTMalloc<const SkPicture*> pics(count); for (int i = 0; i < count; ++i) { pics[i] = fDrawableList[i]->newPictureSnapshot(factory, recordFlags); } - return data; + return SkNEW_ARGS(SkPicture::SnapshotArray, (pics.detach(), count)); } // To make appending to fRecord a little less verbose. diff --git a/src/core/SkRecorder.h b/src/core/SkRecorder.h index 7b2cbfe3a0..b532c89060 100644 --- a/src/core/SkRecorder.h +++ b/src/core/SkRecorder.h @@ -22,9 +22,8 @@ public: SkRecorder(SkRecord*, const SkRect& bounds); virtual ~SkRecorder() SK_OVERRIDE; - // return a (new or ref'd) data containing the array of pictures that were - // snapped from our drawables. - SkData* newDrawableSnapshot(SkBBHFactory*, uint32_t recordFlags); + // Return a new or ref'd array of pictures that were snapped from our drawables. + SkPicture::SnapshotArray* newDrawableSnapshot(SkBBHFactory*, uint32_t recordFlags); // Make SkRecorder forget entirely about its SkRecord*; all calls to SkRecorder will fail. void forgetRecord(); |