diff options
author | mtklein <mtklein@chromium.org> | 2014-11-12 11:08:20 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-12 11:08:20 -0800 |
commit | 703d3c7093f1fb8a40a46d465d9dd5ae60a456d5 (patch) | |
tree | 7992eb6cf73e09f09ee6e36041cc66e653739035 /src | |
parent | 4bf406a478148117df59d91d76843ea0def3fdd8 (diff) |
Followup: remove unnecessary SkTRefArray
BUG=skia:
Review URL: https://codereview.chromium.org/719113004
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkBitmapHeap.cpp | 13 | ||||
-rw-r--r-- | src/core/SkBitmapHeap.h | 9 | ||||
-rw-r--r-- | src/core/SkPictureData.cpp | 43 | ||||
-rw-r--r-- | src/core/SkPictureData.h | 12 | ||||
-rw-r--r-- | src/core/SkPictureFlat.h | 17 | ||||
-rw-r--r-- | src/core/SkTRefArray.h | 112 |
6 files changed, 24 insertions, 182 deletions
diff --git a/src/core/SkBitmapHeap.cpp b/src/core/SkBitmapHeap.cpp index efaa23fc64..07e65fb3e2 100644 --- a/src/core/SkBitmapHeap.cpp +++ b/src/core/SkBitmapHeap.cpp @@ -111,19 +111,6 @@ SkBitmapHeap::~SkBitmapHeap() { fLookupTable.deleteAll(); } -SkTRefArray<SkBitmap>* SkBitmapHeap::extractBitmaps() const { - const int size = fStorage.count(); - SkTRefArray<SkBitmap>* array = NULL; - if (size > 0) { - array = SkTRefArray<SkBitmap>::Create(size); - for (int i = 0; i < size; i++) { - // make a shallow copy of the bitmap - array->writableAt(i) = fStorage[i]->fBitmap; - } - } - return array; -} - void SkBitmapHeap::removeFromLRU(SkBitmapHeap::LookupEntry* entry) { if (fMostRecentlyUsed == entry) { fMostRecentlyUsed = entry->fLessRecentlyUsed; diff --git a/src/core/SkBitmapHeap.h b/src/core/SkBitmapHeap.h index 56ed3584e8..148ae132a4 100644 --- a/src/core/SkBitmapHeap.h +++ b/src/core/SkBitmapHeap.h @@ -13,7 +13,6 @@ #include "SkRefCnt.h" #include "SkTDArray.h" #include "SkThread.h" -#include "SkTRefArray.h" /** * SkBitmapHeapEntry provides users of SkBitmapHeap (using internal storage) with a means to... @@ -114,14 +113,6 @@ public: virtual ~SkBitmapHeap(); /** - * Makes a shallow copy of all bitmaps currently in the heap and returns them as an array. The - * array indices match their position in the heap. - * - * @return a ptr to an array of bitmaps or NULL if external storage is being used. - */ - SkTRefArray<SkBitmap>* extractBitmaps() const; - - /** * Retrieves the bitmap from the specified slot in the heap * * @return The bitmap located at that slot or NULL if external storage is being used. diff --git a/src/core/SkPictureData.cpp b/src/core/SkPictureData.cpp index 29e4415cfa..2dff8eb1d7 100644 --- a/src/core/SkPictureData.cpp +++ b/src/core/SkPictureData.cpp @@ -30,8 +30,8 @@ SkPictureData::SkPictureData(const SkPictInfo& info) void SkPictureData::initForPlayback() const { // ensure that the paths bounds are pre-computed - for (int i = 0; i < fPaths->count(); i++) { - (*fPaths)[i].updateBoundsCache(); + for (int i = 0; i < fPaths.count(); i++) { + fPaths[i].updateBoundsCache(); } } @@ -46,9 +46,9 @@ SkPictureData::SkPictureData(const SkPictureRecord& record, fContentInfo.set(record.fContentInfo); - fBitmaps = SkTRefArray<SkBitmap>::Create(record.fBitmaps.begin(), record.fBitmaps.count()); - fPaints = SkTRefArray<SkPaint> ::Create(record.fPaints .begin(), record.fPaints .count()); - fPaths = SkTRefArray<SkPath> ::Create(record.fPaths .begin(), record.fPaths .count()); + fBitmaps = record.fBitmaps; + fPaints = record.fPaints; + fPaths = record.fPaths; this->initForPlayback(); @@ -74,9 +74,6 @@ SkPictureData::SkPictureData(const SkPictureRecord& record, } void SkPictureData::init() { - fBitmaps = NULL; - fPaints = NULL; - fPaths = NULL; fPictureRefs = NULL; fPictureCount = 0; fTextBlobRefs = NULL; @@ -88,10 +85,6 @@ void SkPictureData::init() { SkPictureData::~SkPictureData() { SkSafeUnref(fOpData); - SkSafeUnref(fBitmaps); - SkSafeUnref(fPaints); - SkSafeUnref(fPaths); - for (int i = 0; i < fPictureCount; i++) { fPictureRefs[i]->unref(); } @@ -106,7 +99,7 @@ SkPictureData::~SkPictureData() { } bool SkPictureData::containsBitmaps() const { - if (fBitmaps && fBitmaps->count() > 0) { + if (fBitmaps.count() > 0) { return true; } for (int i = 0; i < fPictureCount; ++i) { @@ -194,25 +187,25 @@ void SkPictureData::WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec) { void SkPictureData::flattenToBuffer(SkWriteBuffer& buffer) const { int i, n; - if ((n = SafeCount(fBitmaps)) > 0) { + if ((n = fBitmaps.count()) > 0) { write_tag_size(buffer, SK_PICT_BITMAP_BUFFER_TAG, n); for (i = 0; i < n; i++) { - buffer.writeBitmap((*fBitmaps)[i]); + buffer.writeBitmap(fBitmaps[i]); } } - if ((n = SafeCount(fPaints)) > 0) { + if ((n = fPaints.count()) > 0) { write_tag_size(buffer, SK_PICT_PAINT_BUFFER_TAG, n); for (i = 0; i < n; i++) { - buffer.writePaint((*fPaints)[i]); + buffer.writePaint(fPaints[i]); } } - if ((n = SafeCount(fPaths)) > 0) { + if ((n = fPaths.count()) > 0) { write_tag_size(buffer, SK_PICT_PATH_BUFFER_TAG, n); buffer.writeInt(n); for (int i = 0; i < n; i++) { - buffer.writePath((*fPaths)[i]); + buffer.writePath(fPaths[i]); } } @@ -423,9 +416,9 @@ bool SkPictureData::parseBufferTag(SkReadBuffer& buffer, switch (tag) { case SK_PICT_BITMAP_BUFFER_TAG: { const int count = SkToInt(size); - fBitmaps = SkTRefArray<SkBitmap>::Create(size); + fBitmaps.reset(count); for (int i = 0; i < count; ++i) { - SkBitmap* bm = &fBitmaps->writableAt(i); + SkBitmap* bm = &fBitmaps[i]; if (buffer.readBitmap(bm)) { bm->setImmutable(); } else { @@ -435,17 +428,17 @@ bool SkPictureData::parseBufferTag(SkReadBuffer& buffer, } break; case SK_PICT_PAINT_BUFFER_TAG: { const int count = SkToInt(size); - fPaints = SkTRefArray<SkPaint>::Create(size); + fPaints.reset(count); for (int i = 0; i < count; ++i) { - buffer.readPaint(&fPaints->writableAt(i)); + buffer.readPaint(&fPaints[i]); } } break; case SK_PICT_PATH_BUFFER_TAG: if (size > 0) { const int count = buffer.readInt(); - fPaths = SkTRefArray<SkPath>::Create(count); + fPaths.reset(count); for (int i = 0; i < count; i++) { - buffer.readPath(&fPaths->writableAt(i)); + buffer.readPath(&fPaths[i]); } } break; case SK_PICT_TEXTBLOB_BUFFER_TAG: { diff --git a/src/core/SkPictureData.h b/src/core/SkPictureData.h index 9a5a4ca0c1..667880675b 100644 --- a/src/core/SkPictureData.h +++ b/src/core/SkPictureData.h @@ -84,12 +84,12 @@ protected: public: const SkBitmap& getBitmap(SkReader32* reader) const { const int index = reader->readInt(); - return (*fBitmaps)[index]; + return fBitmaps[index]; } const SkPath& getPath(SkReader32* reader) const { int index = reader->readInt() - 1; - return (*fPaths)[index]; + return fPaths[index]; } const SkPicture* getPicture(SkReader32* reader) const { @@ -103,7 +103,7 @@ public: if (index == 0) { return NULL; } - return &(*fPaints)[index - 1]; + return &fPaints[index - 1]; } const SkTextBlob* getTextBlob(SkReader32* reader) const { @@ -142,9 +142,9 @@ private: // bitmap allows playback to draw nothing and move on. SkBitmap fBadBitmap; - SkTRefArray<SkBitmap>* fBitmaps; - SkTRefArray<SkPaint>* fPaints; - SkTRefArray<SkPath>* fPaths; + SkTArray<SkBitmap> fBitmaps; + SkTArray<SkPaint> fPaints; + SkTArray<SkPath> fPaths; SkData* fOpData; // opcodes and parameters diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h index 40f6a0a803..61c4813597 100644 --- a/src/core/SkPictureFlat.h +++ b/src/core/SkPictureFlat.h @@ -18,7 +18,6 @@ #include "SkPicture.h" #include "SkPtrRecorder.h" #include "SkTDynamicHash.h" -#include "SkTRefArray.h" enum DrawType { UNUSED, @@ -449,22 +448,6 @@ public: } /** - * Unflatten the objects and return them in SkTRefArray, or return NULL - * if there no objects. Caller takes ownership of result. - */ - SkTRefArray<T>* unflattenToArray() const { - const int count = this->count(); - if (count == 0) { - return NULL; - } - SkTRefArray<T>* array = SkTRefArray<T>::Create(count); - for (int i = 0; i < count; i++) { - this->unflatten(&array->writableAt(i), fIndexedData[i]); - } - return array; - } - - /** * Unflatten the specific object at the given index. * Caller takes ownership of the result. */ diff --git a/src/core/SkTRefArray.h b/src/core/SkTRefArray.h deleted file mode 100644 index c4bca241d7..0000000000 --- a/src/core/SkTRefArray.h +++ /dev/null @@ -1,112 +0,0 @@ -// -// SkTRefArray.h -// core -// -// Created by Mike Reed on 7/17/12. -// Copyright (c) 2012 __MyCompanyName__. All rights reserved. -// - -#ifndef SkTRefArray_DEFINED -#define SkTRefArray_DEFINED - -#include "SkRefCnt.h" -#include <new> - -/** - * Wrapper to manage thread-safe sharing of an array of T objects. The array - * cannot be grown or shrunk. - */ -template <typename T> class SkTRefArray : public SkRefCnt { - /* - * Shared factory to allocate the space needed for our instance plus N - * T entries at the end. We call our constructor, but not the constructors - * for the elements. Those are called by the proper Create method. - */ - static SkTRefArray<T>* Alloc(int count) { - // space for us, and our [count] elements - size_t size = sizeof(SkTRefArray<T>) + count * sizeof(T); - SkTRefArray<T>* obj = (SkTRefArray<T>*)sk_malloc_throw(size); - - SkNEW_PLACEMENT(obj, SkTRefArray<T>); - obj->fCount = count; - return obj; - } - -public: - /** - * Return a new array with 'count' elements, initialized to their default - * value. To change them to some other value, use writableBegin/End or - * writableAt(), but do that before this array is given to another thread. - */ - static SkTRefArray<T>* Create(int count) { - SkTRefArray<T>* obj = Alloc(count); - T* array = const_cast<T*>(obj->begin()); - for (int i = 0; i < count; ++i) { - SkNEW_PLACEMENT(&array[i], T); - } - return obj; - } - - /** - * Return a new array with 'count' elements, initialized from the provided - * src array. To change them to some other value, use writableBegin/End or - * writableAt(), but do that before this array is given to another thread. - */ - static SkTRefArray<T>* Create(const T src[], int count) { - SkTRefArray<T>* obj = Alloc(count); - T* array = const_cast<T*>(obj->begin()); - for (int i = 0; i < count; ++i) { - SkNEW_PLACEMENT_ARGS(&array[i], T, (src[i])); - } - return obj; - } - - int count() const { return fCount; } - const T* begin() const { return (const T*)(this + 1); } - const T* end() const { return this->begin() + fCount; } - const T& at(int index) const { - SkASSERT((unsigned)index < (unsigned)fCount); - return this->begin()[index]; - } - const T& operator[](int index) const { return this->at(index); } - - // For the writable methods, we assert that we are the only owner if we - // call these, since other owners are not informed if we change an element. - - T* writableBegin() { - SkASSERT(this->unique()); - return (T*)(this + 1); - } - T* writableEnd() { - return this->writableBegin() + fCount; - } - T& writableAt(int index) { - SkASSERT((unsigned)index < (unsigned)fCount); - return this->writableBegin()[index]; - } - -protected: - virtual void internal_dispose() const SK_OVERRIDE { - T* array = const_cast<T*>(this->begin()); - int n = fCount; - - for (int i = 0; i < n; ++i) { - array->~T(); - array += 1; - } - - this->internal_dispose_restore_refcnt_to_1(); - this->~SkTRefArray<T>(); - sk_free((void*)this); - } - -private: - int fCount; - - // hide this - virtual ~SkTRefArray() {} - - typedef SkRefCnt INHERITED; -}; - -#endif |