gfx/skia/trunk/src/animator/SkTDArray_Experimental.h

Thu, 15 Jan 2015 15:55:04 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:55:04 +0100
branch
TOR_BUG_9701
changeset 9
a63d609f5ebe
permissions
-rw-r--r--

Back out 97036ab72558 which inappropriately compared turds to third parties.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2006 The Android Open Source Project
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8
michael@0 9
michael@0 10 #ifndef SkTDArray_Experimental_DEFINED
michael@0 11 #define SkTDArray_Experimental_DEFINED
michael@0 12
michael@0 13 #include "SkTypes.h"
michael@0 14
michael@0 15 #ifdef SK_BUILD_FOR_UNIX
michael@0 16 #define SK_BUILD_FOR_ADS_12
michael@0 17 #endif
michael@0 18
michael@0 19 #if !defined(SK_BUILD_FOR_ADS_12) && !defined(__x86_64__)
michael@0 20 #define SK_SMALLER_ARRAY_TEMPLATE_EXPERIMENT 1
michael@0 21 #else
michael@0 22 #define SK_SMALLER_ARRAY_TEMPLATE_EXPERIMENT 0
michael@0 23 #endif
michael@0 24
michael@0 25 #if SK_SMALLER_ARRAY_TEMPLATE_EXPERIMENT == 0
michael@0 26 #include "SkTDArray.h"
michael@0 27 #define SkIntArray(type) SkTDArray<type>
michael@0 28 #define SkLongArray(type) SkTDArray<type>
michael@0 29 #else
michael@0 30
michael@0 31 class SkDS32Array {
michael@0 32 protected:
michael@0 33 SkDS32Array();
michael@0 34 SkDS32Array(const SkDS32Array& src);
michael@0 35 SkDS32Array(const int32_t src[], U16CPU count);
michael@0 36 SkDS32Array& operator=(const SkDS32Array& src);
michael@0 37 friend int operator==(const SkDS32Array& a, const SkDS32Array& b);
michael@0 38 int32_t* append() { return this->append(1, NULL); }
michael@0 39 int32_t* append(U16CPU count, const int32_t* src = NULL);
michael@0 40
michael@0 41 int32_t* appendClear()
michael@0 42 {
michael@0 43 int32_t* result = this->append();
michael@0 44 *result = 0;
michael@0 45 return result;
michael@0 46 }
michael@0 47
michael@0 48 int find(const int32_t& elem) const;
michael@0 49 int32_t* insert(U16CPU index, U16CPU count, const int32_t* src);
michael@0 50 int rfind(const int32_t& elem) const;
michael@0 51 void swap(SkDS32Array& other);
michael@0 52 public:
michael@0 53 bool isEmpty() const { return fCount == 0; }
michael@0 54 int count() const { return fCount; }
michael@0 55
michael@0 56 void remove(U16CPU index, U16CPU count = 1)
michael@0 57 {
michael@0 58 SkASSERT(index + count <= fCount);
michael@0 59 fCount = SkToU16(fCount - count);
michael@0 60 memmove(fArray + index, fArray + index + count, sizeof(int32_t) * (fCount - index));
michael@0 61 }
michael@0 62
michael@0 63 void reset()
michael@0 64 {
michael@0 65 if (fArray)
michael@0 66 {
michael@0 67 sk_free(fArray);
michael@0 68 fArray = NULL;
michael@0 69 #ifdef SK_DEBUG
michael@0 70 fData = NULL;
michael@0 71 #endif
michael@0 72 fReserve = fCount = 0;
michael@0 73 }
michael@0 74 else
michael@0 75 {
michael@0 76 SkASSERT(fReserve == 0 && fCount == 0);
michael@0 77 }
michael@0 78 }
michael@0 79
michael@0 80 void setCount(U16CPU count)
michael@0 81 {
michael@0 82 if (count > fReserve)
michael@0 83 this->growBy(count - fCount);
michael@0 84 else
michael@0 85 fCount = SkToU16(count);
michael@0 86 }
michael@0 87 protected:
michael@0 88 #ifdef SK_DEBUG
michael@0 89 enum {
michael@0 90 kDebugArraySize = 24
michael@0 91 };
michael@0 92 int32_t(* fData)[kDebugArraySize];
michael@0 93 #endif
michael@0 94 int32_t* fArray;
michael@0 95 uint16_t fReserve, fCount;
michael@0 96 void growBy(U16CPU extra);
michael@0 97 };
michael@0 98
michael@0 99 #ifdef SK_DEBUG
michael@0 100 #define SYNC() fTData = (T (*)[kDebugArraySize]) fArray
michael@0 101 #else
michael@0 102 #define SYNC()
michael@0 103 #endif
michael@0 104
michael@0 105 template <typename T> class SkTDS32Array : public SkDS32Array {
michael@0 106 public:
michael@0 107 SkTDS32Array() { SkDEBUGCODE(fTData=NULL); SkASSERT(sizeof(T) == sizeof(int32_t)); }
michael@0 108 SkTDS32Array(const SkTDS32Array<T>& src) : SkDS32Array(src) {}
michael@0 109 ~SkTDS32Array() { sk_free(fArray); }
michael@0 110 T& operator[](int index) const { SYNC(); SkASSERT((unsigned)index < fCount); return ((T*) fArray)[index]; }
michael@0 111 SkTDS32Array<T>& operator=(const SkTDS32Array<T>& src) {
michael@0 112 return (SkTDS32Array<T>&) SkDS32Array::operator=(src); }
michael@0 113 friend int operator==(const SkTDS32Array<T>& a, const SkTDS32Array<T>& b) {
michael@0 114 return operator==((const SkDS32Array&) a, (const SkDS32Array&) b); }
michael@0 115 T* append() { return (T*) SkDS32Array::append(); }
michael@0 116 T* appendClear() { return (T*) SkDS32Array::appendClear(); }
michael@0 117 T* append(U16CPU count, const T* src = NULL) { return (T*) SkDS32Array::append(count, (const int32_t*) src); }
michael@0 118 T* begin() const { SYNC(); return (T*) fArray; }
michael@0 119 T* end() const { return (T*) (fArray ? fArray + fCount : NULL); }
michael@0 120 int find(const T& elem) const { return SkDS32Array::find((const int32_t&) elem); }
michael@0 121 T* insert(U16CPU index) { return this->insert(index, 1, NULL); }
michael@0 122 T* insert(U16CPU index, U16CPU count, const T* src = NULL) {
michael@0 123 return (T*) SkDS32Array::insert(index, count, (const int32_t*) src); }
michael@0 124 int rfind(const T& elem) const { return SkDS32Array::rfind((const int32_t&) elem); }
michael@0 125 T* push() { return this->append(); }
michael@0 126 void push(T& elem) { *this->append() = elem; }
michael@0 127 const T& top() const { return (*this)[fCount - 1]; }
michael@0 128 T& top() { return (*this)[fCount - 1]; }
michael@0 129 void pop(T* elem) { if (elem) *elem = (*this)[fCount - 1]; --fCount; }
michael@0 130 void pop() { --fCount; }
michael@0 131 private:
michael@0 132 #ifdef SK_DEBUG
michael@0 133 mutable T(* fTData)[kDebugArraySize];
michael@0 134 #endif
michael@0 135 };
michael@0 136
michael@0 137 #define SkIntArray(type) SkTDS32Array<type> // holds 32 bit data types
michael@0 138 #define SkLongArray(type) SkTDS32Array<type>
michael@0 139
michael@0 140 #endif // SK_SMALLER_ARRAY_TEMPLATE_EXPERIMENT
michael@0 141
michael@0 142 #endif // SkTDArray_Experimental_DEFINED

mercurial