aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-07 17:23:00 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-07 17:23:00 +0000
commit21cbec4870660f776f470e3a5e327599b6433dd2 (patch)
treea1aebe391dedc2d9e78912f63b5b57ed979bbb8f
parent674a3a2ffd568e6e0d27fba0da596034276bbb65 (diff)
Remove GrTDArray.
Two dynamic array classes is enough. R=reed@google.com Review URL: https://codereview.appspot.com/7069047 git-svn-id: http://skia.googlecode.com/svn/trunk@7053 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--gyp/gpu.gypi1
-rw-r--r--include/core/SkTDArray.h9
-rw-r--r--src/gpu/GrAtlas.h1
-rw-r--r--src/gpu/GrBufferAllocPool.h4
-rw-r--r--src/gpu/GrGpu.cpp6
-rw-r--r--src/gpu/GrRectanizer.h1
-rw-r--r--src/gpu/GrTDArray.h216
-rw-r--r--src/gpu/GrTHashCache.h7
-rw-r--r--src/gpu/GrTextStrike.cpp2
-rw-r--r--src/gpu/gl/GrGLCreateNullInterface.cpp4
-rw-r--r--src/gpu/gr_unittests.cpp35
11 files changed, 18 insertions, 268 deletions
diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi
index 17708b1f91..3248f03d83 100644
--- a/gyp/gpu.gypi
+++ b/gyp/gpu.gypi
@@ -105,7 +105,6 @@
'<(skia_src_path)/gpu/GrStencilBuffer.cpp',
'<(skia_src_path)/gpu/GrStencilBuffer.h',
'<(skia_src_path)/gpu/GrTBSearch.h',
- '<(skia_src_path)/gpu/GrTDArray.h',
'<(skia_src_path)/gpu/GrSWMaskHelper.cpp',
'<(skia_src_path)/gpu/GrSWMaskHelper.h',
'<(skia_src_path)/gpu/GrSoftwarePathRenderer.cpp',
diff --git a/include/core/SkTDArray.h b/include/core/SkTDArray.h
index 997a07022b..eaf25c67ae 100644
--- a/include/core/SkTDArray.h
+++ b/include/core/SkTDArray.h
@@ -302,6 +302,15 @@ public:
this->reset();
}
+ void visitAll(void visitor(T&)) const {
+ T* stop = this->end();
+ for (T* curr = this->begin(); curr < stop; curr++) {
+ if (*curr) {
+ visitor(*curr);
+ }
+ }
+ }
+
#ifdef SK_DEBUG
void validate() const {
SkASSERT((fReserve == 0 && fArray == NULL) ||
diff --git a/src/gpu/GrAtlas.h b/src/gpu/GrAtlas.h
index f0114e399d..005598e28d 100644
--- a/src/gpu/GrAtlas.h
+++ b/src/gpu/GrAtlas.h
@@ -13,7 +13,6 @@
#include "GrPoint.h"
#include "GrTexture.h"
-#include "GrTDArray.h"
class GrGpu;
class GrRectanizer;
diff --git a/src/gpu/GrBufferAllocPool.h b/src/gpu/GrBufferAllocPool.h
index 7ed4b0c07e..654ba744f9 100644
--- a/src/gpu/GrBufferAllocPool.h
+++ b/src/gpu/GrBufferAllocPool.h
@@ -12,9 +12,9 @@
#define GrBufferAllocPool_DEFINED
#include "GrNoncopyable.h"
-#include "GrTDArray.h"
#include "SkTArray.h"
+#include "SkTDArray.h"
class GrGeometryBuffer;
class GrGpu;
@@ -170,7 +170,7 @@ private:
GrGpu* fGpu;
bool fGpuIsReffed;
bool fFrequentResetHint;
- GrTDArray<GrGeometryBuffer*> fPreallocBuffers;
+ SkTDArray<GrGeometryBuffer*> fPreallocBuffers;
size_t fMinBlockSize;
BufferType fBufferType;
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index b84b0f11c7..b8f43d81c5 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -23,8 +23,6 @@ static const int INDEX_POOL_IB_COUNT = 4;
////////////////////////////////////////////////////////////////////////////////
-extern void gr_run_unittests();
-
#define DEBUG_INVAL_BUFFER 0xdeadcafe
#define DEBUG_INVAL_START_IDX -1
@@ -41,10 +39,6 @@ GrGpu::GrGpu()
fClipMaskManager.setGpu(this);
-#if GR_DEBUG
- //gr_run_unittests();
-#endif
-
fGeomPoolStateStack.push_back();
#if GR_DEBUG
GeometryPoolState& poolState = fGeomPoolStateStack.back();
diff --git a/src/gpu/GrRectanizer.h b/src/gpu/GrRectanizer.h
index d1f5033259..0be83249b3 100644
--- a/src/gpu/GrRectanizer.h
+++ b/src/gpu/GrRectanizer.h
@@ -12,7 +12,6 @@
#define GrRectanizer_DEFINED
#include "GrRect.h"
-#include "GrTDArray.h"
class GrRectanizerPurgeListener {
public:
diff --git a/src/gpu/GrTDArray.h b/src/gpu/GrTDArray.h
deleted file mode 100644
index 33b7a632ed..0000000000
--- a/src/gpu/GrTDArray.h
+++ /dev/null
@@ -1,216 +0,0 @@
-
-/*
- * Copyright 2010 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-
-
-#ifndef GrTDArray_DEFINED
-#define GrTDArray_DEFINED
-
-#include "GrTypes.h"
-#include "GrRefCnt.h"
-
-static inline int GrInitialArrayAllocationCount() {
- return 4;
-}
-
-static inline int GrNextArrayAllocationCount(int count) {
- return count + ((count + 1) >> 1);
-}
-
-template <typename T> class GrTDArray {
-public:
- GrTDArray() : fArray(NULL), fAllocated(0), fCount(0) {}
- GrTDArray(const GrTDArray& src) {
- fCount = fAllocated = src.fCount;
- fArray = (T*)GrMalloc(fAllocated * sizeof(T));
- memcpy(fArray, src.fArray, fCount * sizeof(T));
- }
- ~GrTDArray() {
- if (fArray) {
- GrFree(fArray);
- }
- }
-
- bool isEmpty() const { return 0 == fCount; }
- int count() const { return fCount; }
-
- const T& at(int index) const {
- GrAssert((unsigned)index < (unsigned)fCount);
- return fArray[index];
- }
- T& at(int index) {
- GrAssert((unsigned)index < (unsigned)fCount);
- return fArray[index];
- }
-
- const T& operator[](int index) const { return this->at(index); }
- T& operator[](int index) { return this->at(index); }
-
- GrTDArray& operator=(const GrTDArray& src) {
- if (fAllocated < src.fCount) {
- fAllocated = src.fCount;
- GrFree(fArray);
- fArray = (T*)GrMalloc(fAllocated * sizeof(T));
- }
- fCount = src.fCount;
- memcpy(fArray, src.fArray, fCount * sizeof(T));
- return *this;
- }
-
- void reset() {
- if (fArray) {
- GrFree(fArray);
- fArray = NULL;
- }
- fAllocated = fCount = 0;
- }
-
- T* begin() const { return fArray; }
- T* end() const { return fArray + fCount; }
- T* back() const { GrAssert(fCount); return fArray + (fCount - 1); }
-
- T* prepend() {
- this->growAt(0);
- return fArray;
- }
-
- T* append() {
- this->growAt(fCount);
- return fArray + fCount - 1;
- }
-
- /**
- * index may be [0..count], so that you can insert at the end (like append)
- */
- T* insert(int index) {
- GrAssert((unsigned)index <= (unsigned)fCount);
- this->growAt(index);
- return fArray + index;
- }
-
- void remove(int index) {
- GrAssert((unsigned)index < (unsigned)fCount);
- fCount -= 1;
- if (index < fCount) {
- int remaining = fCount - index;
- memmove(fArray + index, fArray + index + 1, remaining * sizeof(T));
- }
- }
-
- void removeShuffle(int index) {
- GrAssert((unsigned)index < (unsigned)fCount);
- fCount -= 1;
- if (index < fCount) {
- memmove(fArray + index, fArray + fCount, sizeof(T));
- }
- }
-
- // Utility iterators
-
- /**
- * Calls GrFree() on each element. Assumes each is NULL or was allocated
- * with GrMalloc().
- */
- void freeAll() {
- T* stop = this->end();
- for (T* curr = this->begin(); curr < stop; curr++) {
- GrFree(*curr);
- }
- this->reset();
- }
-
- /**
- * Calls delete on each element. Assumes each is NULL or was allocated
- * with new.
- */
- void deleteAll() {
- T* stop = this->end();
- for (T* curr = this->begin(); curr < stop; curr++) {
- delete *curr;
- }
- this->reset();
- }
-
- /**
- * Calls GrSafeUnref() on each element. Assumes each is NULL or is a
- * subclass of GrRefCnt.
- */
- void unrefAll() {
- T* stop = this->end();
- for (T* curr = this->begin(); curr < stop; curr++) {
- GrSafeUnref(*curr);
- }
- this->reset();
- }
-
- void visit(void visitor(T&)) const {
- T* stop = this->end();
- for (T* curr = this->begin(); curr < stop; curr++) {
- if (*curr) {
- visitor(*curr);
- }
- }
- }
-
- int find(const T& elem) const {
- int count = this->count();
- T* curr = this->begin();
- for (int i = 0; i < count; i++) {
- if (elem == curr[i]) {
- return i;
- }
- }
- return -1;
- }
-
- friend bool operator==(const GrTDArray<T>& a, const GrTDArray<T>& b) {
- return a.count() == b.count() &&
- (0 == a.count() ||
- 0 == memcmp(a.begin(), b.begin(), a.count() * sizeof(T)));
- }
- friend bool operator!=(const GrTDArray<T>& a, const GrTDArray<T>& b) {
- return !(a == b);
- }
-
-private:
- T* fArray;
- int fAllocated, fCount;
-
- // growAt will increment fCount, reallocate fArray (as needed), and slide
- // the contents of fArray to make a hole for new data at index.
- void growAt(int index) {
- GrAssert(fCount <= fAllocated);
- if (0 == fAllocated) {
- fAllocated = GrInitialArrayAllocationCount();
- fArray = (T*)GrMalloc(fAllocated * sizeof(T));
- } else if (fCount == fAllocated) {
- fAllocated = GrNextArrayAllocationCount(fAllocated);
- T* newArray = (T*)GrMalloc(fAllocated * sizeof(T));
- memcpy(newArray, fArray, index * sizeof(T));
- memcpy(newArray + index + 1, fArray + index,
- (fCount - index) * sizeof(T));
- GrFree(fArray);
- fArray = newArray;
- } else {
- // check that we're not just appending
- if (index < fCount) {
- memmove(fArray + index + 1, fArray + index,
- (fCount - index) * sizeof(T));
- }
- }
- GrAssert(fCount < fAllocated);
- fCount += 1;
- }
-};
-
-extern void* GrTDArray_growAt(void*, int* allocated, int& count, int index,
- size_t);
-
-
-#endif
-
diff --git a/src/gpu/GrTHashCache.h b/src/gpu/GrTHashCache.h
index 854723715d..c75a5a79ce 100644
--- a/src/gpu/GrTHashCache.h
+++ b/src/gpu/GrTHashCache.h
@@ -11,7 +11,8 @@
#ifndef GrTHashCache_DEFINED
#define GrTHashCache_DEFINED
-#include "GrTDArray.h"
+#include "GrTypes.h"
+#include "SkTDArray.h"
// GrTDefaultFindFunctor implements the default find behavior for
// GrTHashTable (i.e., return the first resource that matches the
@@ -58,7 +59,7 @@ public:
#endif
// testing
- const GrTDArray<T*>& getArray() const { return fSorted; }
+ const SkTDArray<T*>& getArray() const { return fSorted; }
private:
enum {
kHashCount = 1 << kHashBits,
@@ -73,7 +74,7 @@ private:
}
mutable T* fHash[kHashCount];
- GrTDArray<T*> fSorted;
+ SkTDArray<T*> fSorted;
// search fSorted, and return the found index, or ~index of where it
// should be inserted
diff --git a/src/gpu/GrTextStrike.cpp b/src/gpu/GrTextStrike.cpp
index aebaaf81b7..4b55810660 100644
--- a/src/gpu/GrTextStrike.cpp
+++ b/src/gpu/GrTextStrike.cpp
@@ -149,7 +149,7 @@ static void FreeGlyph(GrGlyph*& glyph) { glyph->free(); }
GrTextStrike::~GrTextStrike() {
GrAtlas::FreeLList(fAtlas);
fFontScalerKey->unref();
- fCache.getArray().visit(FreeGlyph);
+ fCache.getArray().visitAll(FreeGlyph);
#if GR_DEBUG
gCounter -= 1;
diff --git a/src/gpu/gl/GrGLCreateNullInterface.cpp b/src/gpu/gl/GrGLCreateNullInterface.cpp
index 6cca6c89f6..f450cc8dd3 100644
--- a/src/gpu/gl/GrGLCreateNullInterface.cpp
+++ b/src/gpu/gl/GrGLCreateNullInterface.cpp
@@ -7,8 +7,8 @@
#include "gl/GrGLInterface.h"
-#include "GrTDArray.h"
#include "GrGLDefines.h"
+#include "SkTDArray.h"
namespace { // added to suppress 'no previous prototype' warning
@@ -132,7 +132,7 @@ GrGLvoid GR_GL_FUNCTION_TYPE nullGLDeleteIds(GrGLsizei n, const GrGLuint* ids) {
// In debug builds we do asserts that ensure we agree with GL about when a buffer
// is mapped.
-static GrTDArray<GrGLuint> gMappedBuffers;
+static SkTDArray<GrGLuint> gMappedBuffers;
static GrGLuint gCurrArrayBuffer;
static GrGLuint gCurrElementArrayBuffer;
diff --git a/src/gpu/gr_unittests.cpp b/src/gpu/gr_unittests.cpp
index 1d7653b71a..7a3a25115c 100644
--- a/src/gpu/gr_unittests.cpp
+++ b/src/gpu/gr_unittests.cpp
@@ -6,13 +6,10 @@
* found in the LICENSE file.
*/
-
-
#include "GrBinHashKey.h"
#include "GrDrawTarget.h"
#include "SkMatrix.h"
#include "GrRedBlackTree.h"
-#include "GrTDArray.h"
// FIXME: needs to be in a header
void gr_run_unittests();
@@ -28,37 +25,6 @@ static bool EQ(const int& elem, int value) {
}
#include "GrTBSearch.h"
-static void dump(const GrTDArray<int>& array) {
-#if 0
- for (int i = 0; i < array.count(); i++) {
- printf(" %d", array[i]);
- }
- printf("\n");
-#endif
-}
-
-static void test_tdarray() {
- GrTDArray<int> array;
-
- *array.append() = 0; dump(array);
- *array.append() = 2; dump(array);
- *array.append() = 4; dump(array);
- *array.append() = 6; dump(array);
- GrAssert(array.count() == 4);
-
- *array.insert(0) = -1; dump(array);
- *array.insert(2) = 1; dump(array);
- *array.insert(4) = 3; dump(array);
- *array.insert(7) = 7; dump(array);
- GrAssert(array.count() == 8);
- array.remove(3); dump(array);
- array.remove(0); dump(array);
- array.removeShuffle(4); dump(array);
- array.removeShuffle(1); dump(array);
- GrAssert(array.count() == 4);
-}
-
-
static void test_bsearch() {
const int array[] = {
1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99
@@ -106,7 +72,6 @@ static void test_binHashKey()
void gr_run_unittests() {
- test_tdarray();
test_bsearch();
test_binHashKey();
GrRedBlackTree<int>::UnitTest();