summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Kamath2015-09-08 07:59:49 -0500
committerNarayan Kamath2015-09-08 07:59:49 -0500
commit51e740f802083cc250a2f6228222bcbbcec79887 (patch)
tree783b5fc2e126ed2d914f26e579426ebeb398be39 /libpixelflinger
parentbeb81f48d8eacdb9e29e369a911c1195e5c7a76d (diff)
parent32d86587f32b5c35f9294ed1d9d27446d638de65 (diff)
downloadplatform-system-core-51e740f802083cc250a2f6228222bcbbcec79887.tar.gz
platform-system-core-51e740f802083cc250a2f6228222bcbbcec79887.tar.xz
platform-system-core-51e740f802083cc250a2f6228222bcbbcec79887.zip
resolved conflicts for 32d86587 to mnc-dr-dev-plus-aosp
Change-Id: I381133e7dd93f908bd3d2b42e8af83d954e428af
Diffstat (limited to 'libpixelflinger')
-rw-r--r--libpixelflinger/Android.mk7
-rw-r--r--libpixelflinger/codeflinger/ARMAssembler.h4
-rw-r--r--libpixelflinger/codeflinger/Arm64Assembler.h4
-rw-r--r--libpixelflinger/codeflinger/CodeCache.h2
-rw-r--r--libpixelflinger/codeflinger/MIPSAssembler.h4
-rw-r--r--libpixelflinger/codeflinger/tinyutils/Errors.h48
-rw-r--r--libpixelflinger/codeflinger/tinyutils/KeyedVector.h203
-rw-r--r--libpixelflinger/codeflinger/tinyutils/SharedBuffer.cpp115
-rw-r--r--libpixelflinger/codeflinger/tinyutils/SharedBuffer.h148
-rw-r--r--libpixelflinger/codeflinger/tinyutils/SortedVector.h284
-rw-r--r--libpixelflinger/codeflinger/tinyutils/TypeHelpers.h256
-rw-r--r--libpixelflinger/codeflinger/tinyutils/Vector.h353
-rw-r--r--libpixelflinger/codeflinger/tinyutils/VectorImpl.cpp555
-rw-r--r--libpixelflinger/codeflinger/tinyutils/VectorImpl.h195
14 files changed, 10 insertions, 2168 deletions
diff --git a/libpixelflinger/Android.mk b/libpixelflinger/Android.mk
index 11e7988b3..65a3fdfcf 100644
--- a/libpixelflinger/Android.mk
+++ b/libpixelflinger/Android.mk
@@ -14,8 +14,6 @@ PIXELFLINGER_SRC_FILES:= \
14 codeflinger/load_store.cpp \ 14 codeflinger/load_store.cpp \
15 codeflinger/blending.cpp \ 15 codeflinger/blending.cpp \
16 codeflinger/texturing.cpp \ 16 codeflinger/texturing.cpp \
17 codeflinger/tinyutils/SharedBuffer.cpp \
18 codeflinger/tinyutils/VectorImpl.cpp \
19 fixed.cpp.arm \ 17 fixed.cpp.arm \
20 picker.cpp.arm \ 18 picker.cpp.arm \
21 pixelflinger.cpp.arm \ 19 pixelflinger.cpp.arm \
@@ -63,8 +61,9 @@ LOCAL_SRC_FILES_arm64 := $(PIXELFLINGER_SRC_FILES_arm64)
63LOCAL_SRC_FILES_mips := $(PIXELFLINGER_SRC_FILES_mips) 61LOCAL_SRC_FILES_mips := $(PIXELFLINGER_SRC_FILES_mips)
64LOCAL_CFLAGS := $(PIXELFLINGER_CFLAGS) 62LOCAL_CFLAGS := $(PIXELFLINGER_CFLAGS)
65LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include 63LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
66LOCAL_C_INCLUDES += $(LOCAL_EXPORT_C_INCLUDE_DIRS) 64LOCAL_C_INCLUDES += $(LOCAL_EXPORT_C_INCLUDE_DIRS) \
67LOCAL_SHARED_LIBRARIES := libcutils liblog 65 external/safe-iop/include
66LOCAL_SHARED_LIBRARIES := libcutils liblog libutils
68 67
69# Really this should go away entirely or at least not depend on 68# Really this should go away entirely or at least not depend on
70# libhardware, but this at least gets us built. 69# libhardware, but this at least gets us built.
diff --git a/libpixelflinger/codeflinger/ARMAssembler.h b/libpixelflinger/codeflinger/ARMAssembler.h
index c03dd9a39..e0c7646cf 100644
--- a/libpixelflinger/codeflinger/ARMAssembler.h
+++ b/libpixelflinger/codeflinger/ARMAssembler.h
@@ -21,9 +21,9 @@
21#include <stdint.h> 21#include <stdint.h>
22#include <sys/types.h> 22#include <sys/types.h>
23 23
24#include "tinyutils/Vector.h"
25#include "tinyutils/KeyedVector.h"
26#include "tinyutils/smartpointer.h" 24#include "tinyutils/smartpointer.h"
25#include "utils/Vector.h"
26#include "utils/KeyedVector.h"
27 27
28#include "ARMAssemblerInterface.h" 28#include "ARMAssemblerInterface.h"
29#include "CodeCache.h" 29#include "CodeCache.h"
diff --git a/libpixelflinger/codeflinger/Arm64Assembler.h b/libpixelflinger/codeflinger/Arm64Assembler.h
index 847927009..c9be11614 100644
--- a/libpixelflinger/codeflinger/Arm64Assembler.h
+++ b/libpixelflinger/codeflinger/Arm64Assembler.h
@@ -32,9 +32,9 @@
32#include <stdint.h> 32#include <stdint.h>
33#include <sys/types.h> 33#include <sys/types.h>
34 34
35#include "tinyutils/Vector.h"
36#include "tinyutils/KeyedVector.h"
37#include "tinyutils/smartpointer.h" 35#include "tinyutils/smartpointer.h"
36#include "utils/Vector.h"
37#include "utils/KeyedVector.h"
38 38
39#include "tinyutils/smartpointer.h" 39#include "tinyutils/smartpointer.h"
40#include "codeflinger/ARMAssemblerInterface.h" 40#include "codeflinger/ARMAssemblerInterface.h"
diff --git a/libpixelflinger/codeflinger/CodeCache.h b/libpixelflinger/codeflinger/CodeCache.h
index fa67dd072..0fb6fd5fe 100644
--- a/libpixelflinger/codeflinger/CodeCache.h
+++ b/libpixelflinger/codeflinger/CodeCache.h
@@ -23,7 +23,7 @@
23#include <pthread.h> 23#include <pthread.h>
24#include <sys/types.h> 24#include <sys/types.h>
25 25
26#include "tinyutils/KeyedVector.h" 26#include "utils/KeyedVector.h"
27#include "tinyutils/smartpointer.h" 27#include "tinyutils/smartpointer.h"
28 28
29namespace android { 29namespace android {
diff --git a/libpixelflinger/codeflinger/MIPSAssembler.h b/libpixelflinger/codeflinger/MIPSAssembler.h
index 430ab064c..8fea8cb12 100644
--- a/libpixelflinger/codeflinger/MIPSAssembler.h
+++ b/libpixelflinger/codeflinger/MIPSAssembler.h
@@ -21,9 +21,9 @@
21#include <stdint.h> 21#include <stdint.h>
22#include <sys/types.h> 22#include <sys/types.h>
23 23
24#include "tinyutils/KeyedVector.h"
25#include "tinyutils/Vector.h"
26#include "tinyutils/smartpointer.h" 24#include "tinyutils/smartpointer.h"
25#include "utils/KeyedVector.h"
26#include "utils/Vector.h"
27 27
28#include "ARMAssemblerInterface.h" 28#include "ARMAssemblerInterface.h"
29#include "CodeCache.h" 29#include "CodeCache.h"
diff --git a/libpixelflinger/codeflinger/tinyutils/Errors.h b/libpixelflinger/codeflinger/tinyutils/Errors.h
deleted file mode 100644
index 47ae9d79e..000000000
--- a/libpixelflinger/codeflinger/tinyutils/Errors.h
+++ /dev/null
@@ -1,48 +0,0 @@
1/*
2 * Copyright 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_PIXELFLINGER_ERRORS_H
18#define ANDROID_PIXELFLINGER_ERRORS_H
19
20#include <sys/types.h>
21#include <errno.h>
22
23namespace android {
24namespace tinyutils {
25
26// use this type to return error codes
27typedef int32_t status_t;
28
29/*
30 * Error codes.
31 * All error codes are negative values.
32 */
33
34enum {
35 NO_ERROR = 0, // No errors.
36 NO_MEMORY = -ENOMEM,
37 BAD_VALUE = -EINVAL,
38 BAD_INDEX = -EOVERFLOW,
39 NAME_NOT_FOUND = -ENOENT,
40};
41
42
43} // namespace tinyutils
44} // namespace android
45
46// ---------------------------------------------------------------------------
47
48#endif // ANDROID_PIXELFLINGER_ERRORS_H
diff --git a/libpixelflinger/codeflinger/tinyutils/KeyedVector.h b/libpixelflinger/codeflinger/tinyutils/KeyedVector.h
deleted file mode 100644
index 9d8668b9c..000000000
--- a/libpixelflinger/codeflinger/tinyutils/KeyedVector.h
+++ /dev/null
@@ -1,203 +0,0 @@
1/*
2 * Copyright 2005 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_PIXELFLINGER_KEYED_VECTOR_H
18#define ANDROID_PIXELFLINGER_KEYED_VECTOR_H
19
20#include <assert.h>
21#include <stdint.h>
22#include <sys/types.h>
23
24#include "Errors.h"
25#include "SortedVector.h"
26#include "TypeHelpers.h"
27
28// ---------------------------------------------------------------------------
29
30namespace android {
31namespace tinyutils {
32
33template <typename KEY, typename VALUE>
34class KeyedVector
35{
36public:
37 typedef KEY key_type;
38 typedef VALUE value_type;
39
40 inline KeyedVector();
41
42 /*
43 * empty the vector
44 */
45
46 inline void clear() { mVector.clear(); }
47
48 /*!
49 * vector stats
50 */
51
52 //! returns number of items in the vector
53 inline size_t size() const { return mVector.size(); }
54 //! returns wether or not the vector is empty
55 inline bool isEmpty() const { return mVector.isEmpty(); }
56 //! returns how many items can be stored without reallocating the backing store
57 inline size_t capacity() const { return mVector.capacity(); }
58 //! setst the capacity. capacity can never be reduced less than size()
59 inline ssize_t setCapacity(size_t size) { return mVector.setCapacity(size); }
60
61 /*!
62 * accessors
63 */
64 const VALUE& valueFor(const KEY& key) const;
65 const VALUE& valueAt(size_t index) const;
66 const KEY& keyAt(size_t index) const;
67 ssize_t indexOfKey(const KEY& key) const;
68
69 /*!
70 * modifing the array
71 */
72
73 VALUE& editValueFor(const KEY& key);
74 VALUE& editValueAt(size_t index);
75
76 /*!
77 * add/insert/replace items
78 */
79
80 ssize_t add(const KEY& key, const VALUE& item);
81 ssize_t replaceValueFor(const KEY& key, const VALUE& item);
82 ssize_t replaceValueAt(size_t index, const VALUE& item);
83
84 /*!
85 * remove items
86 */
87
88 ssize_t removeItem(const KEY& key);
89 ssize_t removeItemsAt(size_t index, size_t count = 1);
90
91private:
92 SortedVector< key_value_pair_t<KEY, VALUE> > mVector;
93};
94
95// ---------------------------------------------------------------------------
96
97/**
98 * Variation of KeyedVector that holds a default value to return when
99 * valueFor() is called with a key that doesn't exist.
100 */
101template <typename KEY, typename VALUE>
102class DefaultKeyedVector : public KeyedVector<KEY, VALUE>
103{
104public:
105 inline DefaultKeyedVector(const VALUE& defValue = VALUE());
106 const VALUE& valueFor(const KEY& key) const;
107
108private:
109 VALUE mDefault;
110};
111
112// ---------------------------------------------------------------------------
113
114template<typename KEY, typename VALUE> inline
115KeyedVector<KEY,VALUE>::KeyedVector()
116{
117}
118
119template<typename KEY, typename VALUE> inline
120ssize_t KeyedVector<KEY,VALUE>::indexOfKey(const KEY& key) const {
121 return mVector.indexOf( key_value_pair_t<KEY,VALUE>(key) );
122}
123
124template<typename KEY, typename VALUE> inline
125const VALUE& KeyedVector<KEY,VALUE>::valueFor(const KEY& key) const {
126 ssize_t i = indexOfKey(key);
127 assert(i>=0);
128 return mVector.itemAt(i).value;
129}
130
131template<typename KEY, typename VALUE> inline
132const VALUE& KeyedVector<KEY,VALUE>::valueAt(size_t index) const {
133 return mVector.itemAt(index).value;
134}
135
136template<typename KEY, typename VALUE> inline
137const KEY& KeyedVector<KEY,VALUE>::keyAt(size_t index) const {
138 return mVector.itemAt(index).key;
139}
140
141template<typename KEY, typename VALUE> inline
142VALUE& KeyedVector<KEY,VALUE>::editValueFor(const KEY& key) {
143 ssize_t i = indexOfKey(key);
144 assert(i>=0);
145 return mVector.editItemAt(i).value;
146}
147
148template<typename KEY, typename VALUE> inline
149VALUE& KeyedVector<KEY,VALUE>::editValueAt(size_t index) {
150 return mVector.editItemAt(index).value;
151}
152
153template<typename KEY, typename VALUE> inline
154ssize_t KeyedVector<KEY,VALUE>::add(const KEY& key, const VALUE& value) {
155 return mVector.add( key_value_pair_t<KEY,VALUE>(key, value) );
156}
157
158template<typename KEY, typename VALUE> inline
159ssize_t KeyedVector<KEY,VALUE>::replaceValueFor(const KEY& key, const VALUE& value) {
160 key_value_pair_t<KEY,VALUE> pair(key, value);
161 mVector.remove(pair);
162 return mVector.add(pair);
163}
164
165template<typename KEY, typename VALUE> inline
166ssize_t KeyedVector<KEY,VALUE>::replaceValueAt(size_t index, const VALUE& item) {
167 if (index<size()) {
168 mVector.editValueAt(index).value = item;
169 return index;
170 }
171 return BAD_INDEX;
172}
173
174template<typename KEY, typename VALUE> inline
175ssize_t KeyedVector<KEY,VALUE>::removeItem(const KEY& key) {
176 return mVector.remove(key_value_pair_t<KEY,VALUE>(key));
177}
178
179template<typename KEY, typename VALUE> inline
180ssize_t KeyedVector<KEY, VALUE>::removeItemsAt(size_t index, size_t count) {
181 return mVector.removeItemsAt(index, count);
182}
183
184// ---------------------------------------------------------------------------
185
186template<typename KEY, typename VALUE> inline
187DefaultKeyedVector<KEY,VALUE>::DefaultKeyedVector(const VALUE& defValue)
188 : mDefault(defValue)
189{
190}
191
192template<typename KEY, typename VALUE> inline
193const VALUE& DefaultKeyedVector<KEY,VALUE>::valueFor(const KEY& key) const {
194 ssize_t i = indexOfKey(key);
195 return i >= 0 ? KeyedVector<KEY,VALUE>::valueAt(i) : mDefault;
196}
197
198} // namespace tinyutils
199} // namespace android
200
201// ---------------------------------------------------------------------------
202
203#endif // ANDROID_PIXELFLINGER_KEYED_VECTOR_H
diff --git a/libpixelflinger/codeflinger/tinyutils/SharedBuffer.cpp b/libpixelflinger/codeflinger/tinyutils/SharedBuffer.cpp
deleted file mode 100644
index ef453fa6c..000000000
--- a/libpixelflinger/codeflinger/tinyutils/SharedBuffer.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
1/*
2 * Copyright 2005 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdlib.h>
18#include <string.h>
19
20#include <cutils/atomic.h>
21
22#include "SharedBuffer.h"
23
24// ---------------------------------------------------------------------------
25
26namespace android {
27namespace tinyutils {
28
29SharedBuffer* SharedBuffer::alloc(size_t size)
30{
31 SharedBuffer* sb = static_cast<SharedBuffer *>(malloc(sizeof(SharedBuffer) + size));
32 if (sb) {
33 sb->mRefs = 1;
34 sb->mSize = size;
35 }
36 return sb;
37}
38
39
40ssize_t SharedBuffer::dealloc(const SharedBuffer* released)
41{
42 if (released->mRefs != 0) return -1; // XXX: invalid operation
43 free(const_cast<SharedBuffer*>(released));
44 return 0;
45}
46
47SharedBuffer* SharedBuffer::edit() const
48{
49 if (onlyOwner()) {
50 return const_cast<SharedBuffer*>(this);
51 }
52 SharedBuffer* sb = alloc(mSize);
53 if (sb) {
54 memcpy(sb->data(), data(), size());
55 release();
56 }
57 return sb;
58}
59
60SharedBuffer* SharedBuffer::editResize(size_t newSize) const
61{
62 if (onlyOwner()) {
63 SharedBuffer* buf = const_cast<SharedBuffer*>(this);
64 if (buf->mSize == newSize) return buf;
65 buf = (SharedBuffer*)realloc(buf, sizeof(SharedBuffer) + newSize);
66 if (buf != NULL) {
67 buf->mSize = newSize;
68 return buf;
69 }
70 }
71 SharedBuffer* sb = alloc(newSize);
72 if (sb) {
73 const size_t mySize = mSize;
74 memcpy(sb->data(), data(), newSize < mySize ? newSize : mySize);
75 release();
76 }
77 return sb;
78}
79
80SharedBuffer* SharedBuffer::attemptEdit() const
81{
82 if (onlyOwner()) {
83 return const_cast<SharedBuffer*>(this);
84 }
85 return 0;
86}
87
88SharedBuffer* SharedBuffer::reset(size_t new_size) const
89{
90 // cheap-o-reset.
91 SharedBuffer* sb = alloc(new_size);
92 if (sb) {
93 release();
94 }
95 return sb;
96}
97
98void SharedBuffer::acquire() const {
99 android_atomic_inc(&mRefs);
100}
101
102int32_t SharedBuffer::release(uint32_t flags) const
103{
104 int32_t prev = 1;
105 if (onlyOwner() || ((prev = android_atomic_dec(&mRefs)) == 1)) {
106 mRefs = 0;
107 if ((flags & eKeepStorage) == 0) {
108 free(const_cast<SharedBuffer*>(this));
109 }
110 }
111 return prev;
112}
113
114} // namespace tinyutils
115} // namespace android
diff --git a/libpixelflinger/codeflinger/tinyutils/SharedBuffer.h b/libpixelflinger/codeflinger/tinyutils/SharedBuffer.h
deleted file mode 100644
index d69b4179b..000000000
--- a/libpixelflinger/codeflinger/tinyutils/SharedBuffer.h
+++ /dev/null
@@ -1,148 +0,0 @@
1/*
2 * Copyright 2005 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_PIXELFLINGER_SHARED_BUFFER_H
18#define ANDROID_PIXELFLINGER_SHARED_BUFFER_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23// ---------------------------------------------------------------------------
24
25namespace android {
26namespace tinyutils {
27
28class SharedBuffer
29{
30public:
31
32 /* flags to use with release() */
33 enum {
34 eKeepStorage = 0x00000001
35 };
36
37 /*! allocate a buffer of size 'size' and acquire() it.
38 * call release() to free it.
39 */
40 static SharedBuffer* alloc(size_t size);
41
42 /*! free the memory associated with the SharedBuffer.
43 * Fails if there are any users associated with this SharedBuffer.
44 * In other words, the buffer must have been release by all its
45 * users.
46 */
47 static ssize_t dealloc(const SharedBuffer* released);
48
49 //! get the SharedBuffer from the data pointer
50 static inline const SharedBuffer* sharedBuffer(const void* data);
51
52 //! access the data for read
53 inline const void* data() const;
54
55 //! access the data for read/write
56 inline void* data();
57
58 //! get size of the buffer
59 inline size_t size() const;
60
61 //! get back a SharedBuffer object from its data
62 static inline SharedBuffer* bufferFromData(void* data);
63
64 //! get back a SharedBuffer object from its data
65 static inline const SharedBuffer* bufferFromData(const void* data);
66
67 //! get the size of a SharedBuffer object from its data
68 static inline size_t sizeFromData(const void* data);
69
70 //! edit the buffer (get a writtable, or non-const, version of it)
71 SharedBuffer* edit() const;
72
73 //! edit the buffer, resizing if needed
74 SharedBuffer* editResize(size_t size) const;
75
76 //! like edit() but fails if a copy is required
77 SharedBuffer* attemptEdit() const;
78
79 //! resize and edit the buffer, loose it's content.
80 SharedBuffer* reset(size_t size) const;
81
82 //! acquire/release a reference on this buffer
83 void acquire() const;
84
85 /*! release a reference on this buffer, with the option of not
86 * freeing the memory associated with it if it was the last reference
87 * returns the previous reference count
88 */
89 int32_t release(uint32_t flags = 0) const;
90
91 //! returns wether or not we're the only owner
92 inline bool onlyOwner() const;
93
94
95private:
96 inline SharedBuffer() { }
97 inline ~SharedBuffer() { }
98 inline SharedBuffer(const SharedBuffer&);
99
100 // 16 bytes. must be sized to preserve correct alingment.
101 mutable int32_t mRefs;
102 size_t mSize;
103 uint32_t mReserved[2];
104};
105
106// ---------------------------------------------------------------------------
107
108const SharedBuffer* SharedBuffer::sharedBuffer(const void* data) {
109 return data ? reinterpret_cast<const SharedBuffer *>(data)-1 : 0;
110}
111
112const void* SharedBuffer::data() const {
113 return this + 1;
114}
115
116void* SharedBuffer::data() {
117 return this + 1;
118}
119
120size_t SharedBuffer::size() const {
121 return mSize;
122}
123
124SharedBuffer* SharedBuffer::bufferFromData(void* data)
125{
126 return ((SharedBuffer*)data)-1;
127}
128
129const SharedBuffer* SharedBuffer::bufferFromData(const void* data)
130{
131 return ((const SharedBuffer*)data)-1;
132}
133
134size_t SharedBuffer::sizeFromData(const void* data)
135{
136 return (((const SharedBuffer*)data)-1)->mSize;
137}
138
139bool SharedBuffer::onlyOwner() const {
140 return (mRefs == 1);
141}
142
143} // namespace tinyutils
144} // namespace android
145
146// ---------------------------------------------------------------------------
147
148#endif // ANDROID_PIXELFLINGER_SHARED_BUFFER_H
diff --git a/libpixelflinger/codeflinger/tinyutils/SortedVector.h b/libpixelflinger/codeflinger/tinyutils/SortedVector.h
deleted file mode 100644
index a2b700542..000000000
--- a/libpixelflinger/codeflinger/tinyutils/SortedVector.h
+++ /dev/null
@@ -1,284 +0,0 @@
1/*
2 * Copyright 2005 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_PIXELFLINGER_SORTED_VECTOR_H
18#define ANDROID_PIXELFLINGER_SORTED_VECTOR_H
19
20#include <assert.h>
21#include <stdint.h>
22#include <sys/types.h>
23
24#include "Vector.h"
25#include "VectorImpl.h"
26#include "TypeHelpers.h"
27
28// ---------------------------------------------------------------------------
29
30namespace android {
31namespace tinyutils {
32
33template <class TYPE>
34class SortedVector : private SortedVectorImpl
35{
36public:
37 typedef TYPE value_type;
38
39 /*!
40 * Constructors and destructors
41 */
42
43 SortedVector();
44 SortedVector(const SortedVector<TYPE>& rhs);
45 virtual ~SortedVector();
46
47 /*! copy operator */
48 const SortedVector<TYPE>& operator = (const SortedVector<TYPE>& rhs) const;
49 SortedVector<TYPE>& operator = (const SortedVector<TYPE>& rhs);
50
51 /*
52 * empty the vector
53 */
54
55 inline void clear() { VectorImpl::clear(); }
56
57 /*!
58 * vector stats
59 */
60
61 //! returns number of items in the vector
62 inline size_t size() const { return VectorImpl::size(); }
63 //! returns wether or not the vector is empty
64 inline bool isEmpty() const { return VectorImpl::isEmpty(); }
65 //! returns how many items can be stored without reallocating the backing store
66 inline size_t capacity() const { return VectorImpl::capacity(); }
67 //! setst the capacity. capacity can never be reduced less than size()
68 inline ssize_t setCapacity(size_t size) { return VectorImpl::setCapacity(size); }
69
70 /*!
71 * C-style array access
72 */
73
74 //! read-only C-style access
75 inline const TYPE* array() const;
76
77 //! read-write C-style access. BE VERY CAREFUL when modifying the array
78 //! you ust keep it sorted! You usually don't use this function.
79 TYPE* editArray();
80
81 //! finds the index of an item
82 ssize_t indexOf(const TYPE& item) const;
83
84 //! finds where this item should be inserted
85 size_t orderOf(const TYPE& item) const;
86
87
88 /*!
89 * accessors
90 */
91
92 //! read-only access to an item at a given index
93 inline const TYPE& operator [] (size_t index) const;
94 //! alternate name for operator []
95 inline const TYPE& itemAt(size_t index) const;
96 //! stack-usage of the vector. returns the top of the stack (last element)
97 const TYPE& top() const;
98 //! same as operator [], but allows to access the vector backward (from the end) with a negative index
99 const TYPE& mirrorItemAt(ssize_t index) const;
100
101 /*!
102 * modifing the array
103 */
104
105 //! add an item in the right place (and replace the one that is there)
106 ssize_t add(const TYPE& item);
107
108 //! editItemAt() MUST NOT change the order of this item
109 TYPE& editItemAt(size_t index) {
110 return *( static_cast<TYPE *>(VectorImpl::editItemLocation(index)) );
111 }
112
113 //! merges a vector into this one
114 ssize_t merge(const Vector<TYPE>& vector);
115 ssize_t merge(const SortedVector<TYPE>& vector);
116
117 //! removes an item
118 ssize_t remove(const TYPE&);
119
120 //! remove several items
121 inline ssize_t removeItemsAt(size_t index, size_t count = 1);
122 //! remove one item
123 inline ssize_t removeAt(size_t index) { return removeItemsAt(index); }
124
125protected:
126 virtual void do_construct(void* storage, size_t num) const;
127 virtual void do_destroy(void* storage, size_t num) const;
128 virtual void do_copy(void* dest, const void* from, size_t num) const;
129 virtual void do_splat(void* dest, const void* item, size_t num) const;
130 virtual void do_move_forward(void* dest, const void* from, size_t num) const;
131 virtual void do_move_backward(void* dest, const void* from, size_t num) const;
132 virtual int do_compare(const void* lhs, const void* rhs) const;
133};
134
135
136// ---------------------------------------------------------------------------
137// No user serviceable parts from here...
138// ---------------------------------------------------------------------------
139
140template<class TYPE> inline
141SortedVector<TYPE>::SortedVector()
142 : SortedVectorImpl(sizeof(TYPE),
143 ((traits<TYPE>::has_trivial_ctor ? HAS_TRIVIAL_CTOR : 0)
144 |(traits<TYPE>::has_trivial_dtor ? HAS_TRIVIAL_DTOR : 0)
145 |(traits<TYPE>::has_trivial_copy ? HAS_TRIVIAL_COPY : 0)
146 |(traits<TYPE>::has_trivial_assign ? HAS_TRIVIAL_ASSIGN : 0))
147 )
148{
149}
150
151template<class TYPE> inline
152SortedVector<TYPE>::SortedVector(const SortedVector<TYPE>& rhs)
153 : SortedVectorImpl(rhs) {
154}
155
156template<class TYPE> inline
157SortedVector<TYPE>::~SortedVector() {
158 finish_vector();
159}
160
161template<class TYPE> inline
162SortedVector<TYPE>& SortedVector<TYPE>::operator = (const SortedVector<TYPE>& rhs) {
163 SortedVectorImpl::operator = (rhs);
164 return *this;
165}
166
167template<class TYPE> inline
168const SortedVector<TYPE>& SortedVector<TYPE>::operator = (const SortedVector<TYPE>& rhs) const {
169 SortedVectorImpl::operator = (rhs);
170 return *this;
171}
172
173template<class TYPE> inline
174const TYPE* SortedVector<TYPE>::array() const {
175 return static_cast<const TYPE *>(arrayImpl());
176}
177
178template<class TYPE> inline
179TYPE* SortedVector<TYPE>::editArray() {
180 return static_cast<TYPE *>(editArrayImpl());
181}
182
183
184template<class TYPE> inline
185const TYPE& SortedVector<TYPE>::operator[](size_t index) const {
186 assert( index<size() );
187 return *(array() + index);
188}
189
190template<class TYPE> inline
191const TYPE& SortedVector<TYPE>::itemAt(size_t index) const {
192 return operator[](index);
193}
194
195template<class TYPE> inline
196const TYPE& SortedVector<TYPE>::mirrorItemAt(ssize_t index) const {
197 assert( (index>0 ? index : -index)<size() );
198 return *(array() + ((index<0) ? (size()-index) : index));
199}
200
201template<class TYPE> inline
202const TYPE& SortedVector<TYPE>::top() const {
203 return *(array() + size() - 1);
204}
205
206template<class TYPE> inline
207ssize_t SortedVector<TYPE>::add(const TYPE& item) {
208 return SortedVectorImpl::add(&item);
209}
210
211template<class TYPE> inline
212ssize_t SortedVector<TYPE>::indexOf(const TYPE& item) const {
213 return SortedVectorImpl::indexOf(&item);
214}
215
216template<class TYPE> inline
217size_t SortedVector<TYPE>::orderOf(const TYPE& item) const {
218 return SortedVectorImpl::orderOf(&item);
219}
220
221template<class TYPE> inline
222ssize_t SortedVector<TYPE>::merge(const Vector<TYPE>& vector) {
223 return SortedVectorImpl::merge(reinterpret_cast<const VectorImpl&>(vector));
224}
225
226template<class TYPE> inline
227ssize_t SortedVector<TYPE>::merge(const SortedVector<TYPE>& vector) {
228 return SortedVectorImpl::merge(reinterpret_cast<const SortedVectorImpl&>(vector));
229}
230
231template<class TYPE> inline
232ssize_t SortedVector<TYPE>::remove(const TYPE& item) {
233 return SortedVectorImpl::remove(&item);
234}
235
236template<class TYPE> inline
237ssize_t SortedVector<TYPE>::removeItemsAt(size_t index, size_t count) {
238 return VectorImpl::removeItemsAt(index, count);
239}
240
241// ---------------------------------------------------------------------------
242
243template<class TYPE>
244void SortedVector<TYPE>::do_construct(void* storage, size_t num) const {
245 construct_type( reinterpret_cast<TYPE*>(storage), num );
246}
247
248template<class TYPE>
249void SortedVector<TYPE>::do_destroy(void* storage, size_t num) const {
250 destroy_type( reinterpret_cast<TYPE*>(storage), num );
251}
252
253template<class TYPE>
254void SortedVector<TYPE>::do_copy(void* dest, const void* from, size_t num) const {
255 copy_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
256}
257
258template<class TYPE>
259void SortedVector<TYPE>::do_splat(void* dest, const void* item, size_t num) const {
260 splat_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(item), num );
261}
262
263template<class TYPE>
264void SortedVector<TYPE>::do_move_forward(void* dest, const void* from, size_t num) const {
265 move_forward_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
266}
267
268template<class TYPE>
269void SortedVector<TYPE>::do_move_backward(void* dest, const void* from, size_t num) const {
270 move_backward_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
271}
272
273template<class TYPE>
274int SortedVector<TYPE>::do_compare(const void* lhs, const void* rhs) const {
275 return compare_type( *reinterpret_cast<const TYPE*>(lhs), *reinterpret_cast<const TYPE*>(rhs) );
276}
277
278} // namespace tinyutils
279} // namespace android
280
281
282// ---------------------------------------------------------------------------
283
284#endif // ANDROID_PIXELFLINGER_SORTED_VECTOR_H
diff --git a/libpixelflinger/codeflinger/tinyutils/TypeHelpers.h b/libpixelflinger/codeflinger/tinyutils/TypeHelpers.h
deleted file mode 100644
index 7abff072f..000000000
--- a/libpixelflinger/codeflinger/tinyutils/TypeHelpers.h
+++ /dev/null
@@ -1,256 +0,0 @@
1/*
2 * Copyright 2005 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_PIXELFLINGER_TYPE_HELPERS_H
18#define ANDROID_PIXELFLINGER_TYPE_HELPERS_H
19
20#include <new>
21#include <stdint.h>
22#include <string.h>
23#include <sys/types.h>
24
25// ---------------------------------------------------------------------------
26
27namespace android {
28namespace tinyutils {
29
30/*
31 * Types traits
32 */
33
34template <typename T> struct trait_trivial_ctor { enum { value = false }; };
35template <typename T> struct trait_trivial_dtor { enum { value = false }; };
36template <typename T> struct trait_trivial_copy { enum { value = false }; };
37template <typename T> struct trait_trivial_assign{ enum { value = false }; };
38
39template <typename T> struct trait_pointer { enum { value = false }; };
40template <typename T> struct trait_pointer<T*> { enum { value = true }; };
41
42#define ANDROID_BASIC_TYPES_TRAITS( T ) \
43 template<> struct trait_trivial_ctor< T > { enum { value = true }; }; \
44 template<> struct trait_trivial_dtor< T > { enum { value = true }; }; \
45 template<> struct trait_trivial_copy< T > { enum { value = true }; }; \
46 template<> struct trait_trivial_assign< T >{ enum { value = true }; };
47
48#define ANDROID_TYPE_TRAITS( T, ctor, dtor, copy, assign ) \
49 template<> struct trait_trivial_ctor< T > { enum { value = ctor }; }; \
50 template<> struct trait_trivial_dtor< T > { enum { value = dtor }; }; \
51 template<> struct trait_trivial_copy< T > { enum { value = copy }; }; \
52 template<> struct trait_trivial_assign< T >{ enum { value = assign }; };
53
54template <typename TYPE>
55struct traits {
56 enum {
57 is_pointer = trait_pointer<TYPE>::value,
58 has_trivial_ctor = is_pointer || trait_trivial_ctor<TYPE>::value,
59 has_trivial_dtor = is_pointer || trait_trivial_dtor<TYPE>::value,
60 has_trivial_copy = is_pointer || trait_trivial_copy<TYPE>::value,
61 has_trivial_assign = is_pointer || trait_trivial_assign<TYPE>::value
62 };
63};
64
65template <typename T, typename U>
66struct aggregate_traits {
67 enum {
68 is_pointer = false,
69 has_trivial_ctor = traits<T>::has_trivial_ctor && traits<U>::has_trivial_ctor,
70 has_trivial_dtor = traits<T>::has_trivial_dtor && traits<U>::has_trivial_dtor,
71 has_trivial_copy = traits<T>::has_trivial_copy && traits<U>::has_trivial_copy,
72 has_trivial_assign = traits<T>::has_trivial_assign && traits<U>::has_trivial_assign
73 };
74};
75
76// ---------------------------------------------------------------------------
77
78/*
79 * basic types traits
80 */
81
82ANDROID_BASIC_TYPES_TRAITS( void );
83ANDROID_BASIC_TYPES_TRAITS( bool );
84ANDROID_BASIC_TYPES_TRAITS( char );
85ANDROID_BASIC_TYPES_TRAITS( unsigned char );
86ANDROID_BASIC_TYPES_TRAITS( short );
87ANDROID_BASIC_TYPES_TRAITS( unsigned short );
88ANDROID_BASIC_TYPES_TRAITS( int );
89ANDROID_BASIC_TYPES_TRAITS( unsigned int );
90ANDROID_BASIC_TYPES_TRAITS( long );
91ANDROID_BASIC_TYPES_TRAITS( unsigned long );
92ANDROID_BASIC_TYPES_TRAITS( long long );
93ANDROID_BASIC_TYPES_TRAITS( unsigned long long );
94ANDROID_BASIC_TYPES_TRAITS( float );
95ANDROID_BASIC_TYPES_TRAITS( double );
96
97// ---------------------------------------------------------------------------
98
99
100/*
101 * compare and order types
102 */
103
104template<typename TYPE> inline
105int strictly_order_type(const TYPE& lhs, const TYPE& rhs) {
106 return (lhs < rhs) ? 1 : 0;
107}
108
109template<typename TYPE> inline
110int compare_type(const TYPE& lhs, const TYPE& rhs) {
111 return strictly_order_type(rhs, lhs) - strictly_order_type(lhs, rhs);
112}
113
114/*
115 * create, destroy, copy and assign types...
116 */
117
118template<typename TYPE> inline
119void construct_type(TYPE* p, size_t n) {
120 if (!traits<TYPE>::has_trivial_ctor) {
121 while (n--) {
122 new(p++) TYPE;
123 }
124 }
125}
126
127template<typename TYPE> inline
128void destroy_type(TYPE* p, size_t n) {
129 if (!traits<TYPE>::has_trivial_dtor) {
130 while (n--) {
131 p->~TYPE();
132 p++;
133 }
134 }
135}
136
137template<typename TYPE> inline
138void copy_type(TYPE* d, const TYPE* s, size_t n) {
139 if (!traits<TYPE>::has_trivial_copy) {
140 while (n--) {
141 new(d) TYPE(*s);
142 d++, s++;
143 }
144 } else {
145 memcpy(d,s,n*sizeof(TYPE));
146 }
147}
148
149template<typename TYPE> inline
150void assign_type(TYPE* d, const TYPE* s, size_t n) {
151 if (!traits<TYPE>::has_trivial_assign) {
152 while (n--) {
153 *d++ = *s++;
154 }
155 } else {
156 memcpy(d,s,n*sizeof(TYPE));
157 }
158}
159
160template<typename TYPE> inline
161void splat_type(TYPE* where, const TYPE* what, size_t n) {
162 if (!traits<TYPE>::has_trivial_copy) {
163 while (n--) {
164 new(where) TYPE(*what);
165 where++;
166 }
167 } else {
168 while (n--) {
169 *where++ = *what;
170 }
171 }
172}
173
174template<typename TYPE> inline
175void move_forward_type(TYPE* d, const TYPE* s, size_t n = 1) {
176 if (!traits<TYPE>::has_trivial_copy || !traits<TYPE>::has_trivial_dtor) {
177 d += n;
178 s += n;
179 while (n--) {
180 --d, --s;
181 if (!traits<TYPE>::has_trivial_copy) {
182 new(d) TYPE(*s);
183 } else {
184 *d = *s;
185 }
186 if (!traits<TYPE>::has_trivial_dtor) {
187 s->~TYPE();
188 }
189 }
190 } else {
191 memmove(d,s,n*sizeof(TYPE));
192 }
193}
194
195template<typename TYPE> inline
196void move_backward_type(TYPE* d, const TYPE* s, size_t n = 1) {
197 if (!traits<TYPE>::has_trivial_copy || !traits<TYPE>::has_trivial_dtor) {
198 while (n--) {
199 if (!traits<TYPE>::has_trivial_copy) {
200 new(d) TYPE(*s);
201 } else {
202 *d = *s;
203 }
204 if (!traits<TYPE>::has_trivial_dtor) {
205 s->~TYPE();
206 }
207 d++, s++;
208 }
209 } else {
210 memmove(d,s,n*sizeof(TYPE));
211 }
212}
213// ---------------------------------------------------------------------------
214
215/*
216 * a key/value pair
217 */
218
219template <typename KEY, typename VALUE>
220struct key_value_pair_t {
221 KEY key;
222 VALUE value;
223 key_value_pair_t() { }
224 key_value_pair_t(const key_value_pair_t& o) : key(o.key), value(o.value) { }
225 key_value_pair_t(const KEY& k, const VALUE& v) : key(k), value(v) { }
226 key_value_pair_t(const KEY& k) : key(k) { }
227 inline bool operator < (const key_value_pair_t& o) const {
228 return strictly_order_type(key, o.key);
229 }
230};
231
232template<>
233template <typename K, typename V>
234struct trait_trivial_ctor< key_value_pair_t<K, V> >
235{ enum { value = aggregate_traits<K,V>::has_trivial_ctor }; };
236template<>
237template <typename K, typename V>
238struct trait_trivial_dtor< key_value_pair_t<K, V> >
239{ enum { value = aggregate_traits<K,V>::has_trivial_dtor }; };
240template<>
241template <typename K, typename V>
242struct trait_trivial_copy< key_value_pair_t<K, V> >
243{ enum { value = aggregate_traits<K,V>::has_trivial_copy }; };
244template<>
245template <typename K, typename V>
246struct trait_trivial_assign< key_value_pair_t<K, V> >
247{ enum { value = aggregate_traits<K,V>::has_trivial_assign};};
248
249// ---------------------------------------------------------------------------
250
251} // namespace tinyutils
252} // namespace android
253
254// ---------------------------------------------------------------------------
255
256#endif // ANDROID_PIXELFLINGER_TYPE_HELPERS_H
diff --git a/libpixelflinger/codeflinger/tinyutils/Vector.h b/libpixelflinger/codeflinger/tinyutils/Vector.h
deleted file mode 100644
index c07a17aa5..000000000
--- a/libpixelflinger/codeflinger/tinyutils/Vector.h
+++ /dev/null
@@ -1,353 +0,0 @@
1/*
2 * Copyright 2005 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_PIXELFLINGER_VECTOR_H
18#define ANDROID_PIXELFLINGER_VECTOR_H
19
20#include <new>
21#include <stdint.h>
22#include <sys/types.h>
23
24#include <cutils/log.h>
25
26#include "Errors.h"
27#include "VectorImpl.h"
28#include "TypeHelpers.h"
29
30// ---------------------------------------------------------------------------
31
32namespace android {
33namespace tinyutils {
34
35/*!
36 * The main templated vector class ensuring type safety
37 * while making use of VectorImpl.
38 * This is the class users want to use.
39 */
40
41template <class TYPE>
42class Vector : private VectorImpl
43{
44public:
45 typedef TYPE value_type;
46
47 /*!
48 * Constructors and destructors
49 */
50
51 Vector();
52 Vector(const Vector<TYPE>& rhs);
53 virtual ~Vector();
54
55 /*! copy operator */
56 const Vector<TYPE>& operator = (const Vector<TYPE>& rhs) const;
57 Vector<TYPE>& operator = (const Vector<TYPE>& rhs);
58
59 /*
60 * empty the vector
61 */
62
63 inline void clear() { VectorImpl::clear(); }
64
65 /*!
66 * vector stats
67 */
68
69 //! returns number of items in the vector
70 inline size_t size() const { return VectorImpl::size(); }
71 //! returns wether or not the vector is empty
72 inline bool isEmpty() const { return VectorImpl::isEmpty(); }
73 //! returns how many items can be stored without reallocating the backing store
74 inline size_t capacity() const { return VectorImpl::capacity(); }
75 //! setst the capacity. capacity can never be reduced less than size()
76 inline ssize_t setCapacity(size_t size) { return VectorImpl::setCapacity(size); }
77
78 /*!
79 * C-style array access
80 */
81
82 //! read-only C-style access
83 inline const TYPE* array() const;
84 //! read-write C-style access
85 TYPE* editArray();
86
87 /*!
88 * accessors
89 */
90
91 //! read-only access to an item at a given index
92 inline const TYPE& operator [] (size_t index) const;
93 //! alternate name for operator []
94 inline const TYPE& itemAt(size_t index) const;
95 //! stack-usage of the vector. returns the top of the stack (last element)
96 const TYPE& top() const;
97 //! same as operator [], but allows to access the vector backward (from the end) with a negative index
98 const TYPE& mirrorItemAt(ssize_t index) const;
99
100 /*!
101 * modifing the array
102 */
103
104 //! copy-on write support, grants write access to an item
105 TYPE& editItemAt(size_t index);
106 //! grants right acces to the top of the stack (last element)
107 TYPE& editTop();
108
109 /*!
110 * append/insert another vector
111 */
112
113 //! insert another vector at a given index
114 ssize_t insertVectorAt(const Vector<TYPE>& vector, size_t index);
115
116 //! append another vector at the end of this one
117 ssize_t appendVector(const Vector<TYPE>& vector);
118
119
120 /*!
121 * add/insert/replace items
122 */
123
124 //! insert one or several items initialized with their default constructor
125 inline ssize_t insertAt(size_t index, size_t numItems = 1);
126 //! insert on onr several items initialized from a prototype item
127 ssize_t insertAt(const TYPE& prototype_item, size_t index, size_t numItems = 1);
128 //! pop the top of the stack (removes the last element). No-op if the stack's empty
129 inline void pop();
130 //! pushes an item initialized with its default constructor
131 inline void push();
132 //! pushes an item on the top of the stack
133 void push(const TYPE& item);
134 //! same as push() but returns the index the item was added at (or an error)
135 inline ssize_t add();
136 //! same as push() but returns the index the item was added at (or an error)
137 ssize_t add(const TYPE& item);
138 //! replace an item with a new one initialized with its default constructor
139 inline ssize_t replaceAt(size_t index);
140 //! replace an item with a new one
141 ssize_t replaceAt(const TYPE& item, size_t index);
142
143 /*!
144 * remove items
145 */
146
147 //! remove several items
148 inline ssize_t removeItemsAt(size_t index, size_t count = 1);
149 //! remove one item
150 inline ssize_t removeAt(size_t index) { return removeItemsAt(index); }
151
152 /*!
153 * sort (stable) the array
154 */
155
156 typedef int (*compar_t)(const TYPE* lhs, const TYPE* rhs);
157 typedef int (*compar_r_t)(const TYPE* lhs, const TYPE* rhs, void* state);
158
159 inline status_t sort(compar_t cmp);
160 inline status_t sort(compar_r_t cmp, void* state);
161
162protected:
163 virtual void do_construct(void* storage, size_t num) const;
164 virtual void do_destroy(void* storage, size_t num) const;
165 virtual void do_copy(void* dest, const void* from, size_t num) const;
166 virtual void do_splat(void* dest, const void* item, size_t num) const;
167 virtual void do_move_forward(void* dest, const void* from, size_t num) const;
168 virtual void do_move_backward(void* dest, const void* from, size_t num) const;
169};
170
171
172// ---------------------------------------------------------------------------
173// No user serviceable parts from here...
174// ---------------------------------------------------------------------------
175
176template<class TYPE> inline
177Vector<TYPE>::Vector()
178 : VectorImpl(sizeof(TYPE),
179 ((traits<TYPE>::has_trivial_ctor ? HAS_TRIVIAL_CTOR : 0)
180 |(traits<TYPE>::has_trivial_dtor ? HAS_TRIVIAL_DTOR : 0)
181 |(traits<TYPE>::has_trivial_copy ? HAS_TRIVIAL_COPY : 0)
182 |(traits<TYPE>::has_trivial_assign ? HAS_TRIVIAL_ASSIGN : 0))
183 )
184{
185}
186
187template<class TYPE> inline
188Vector<TYPE>::Vector(const Vector<TYPE>& rhs)
189 : VectorImpl(rhs) {
190}
191
192template<class TYPE> inline
193Vector<TYPE>::~Vector() {
194 finish_vector();
195}
196
197template<class TYPE> inline
198Vector<TYPE>& Vector<TYPE>::operator = (const Vector<TYPE>& rhs) {
199 VectorImpl::operator = (rhs);
200 return *this;
201}
202
203template<class TYPE> inline
204const Vector<TYPE>& Vector<TYPE>::operator = (const Vector<TYPE>& rhs) const {
205 VectorImpl::operator = (rhs);
206 return *this;
207}
208
209template<class TYPE> inline
210const TYPE* Vector<TYPE>::array() const {
211 return static_cast<const TYPE *>(arrayImpl());
212}
213
214template<class TYPE> inline
215TYPE* Vector<TYPE>::editArray() {
216 return static_cast<TYPE *>(editArrayImpl());
217}
218
219
220template<class TYPE> inline
221const TYPE& Vector<TYPE>::operator[](size_t index) const {
222 LOG_FATAL_IF( index>=size(),
223 "itemAt: index %d is past size %d", (int)index, (int)size() );
224 return *(array() + index);
225}
226
227template<class TYPE> inline
228const TYPE& Vector<TYPE>::itemAt(size_t index) const {
229 return operator[](index);
230}
231
232template<class TYPE> inline
233const TYPE& Vector<TYPE>::mirrorItemAt(ssize_t index) const {
234 LOG_FATAL_IF( (index>0 ? index : -index)>=size(),
235 "mirrorItemAt: index %d is past size %d",
236 (int)index, (int)size() );
237 return *(array() + ((index<0) ? (size()-index) : index));
238}
239
240template<class TYPE> inline
241const TYPE& Vector<TYPE>::top() const {
242 return *(array() + size() - 1);
243}
244
245template<class TYPE> inline
246TYPE& Vector<TYPE>::editItemAt(size_t index) {
247 return *( static_cast<TYPE *>(editItemLocation(index)) );
248}
249
250template<class TYPE> inline
251TYPE& Vector<TYPE>::editTop() {
252 return *( static_cast<TYPE *>(editItemLocation(size()-1)) );
253}
254
255template<class TYPE> inline
256ssize_t Vector<TYPE>::insertVectorAt(const Vector<TYPE>& vector, size_t index) {
257 return VectorImpl::insertVectorAt(reinterpret_cast<const VectorImpl&>(vector), index);
258}
259
260template<class TYPE> inline
261ssize_t Vector<TYPE>::appendVector(const Vector<TYPE>& vector) {
262 return VectorImpl::appendVector(reinterpret_cast<const VectorImpl&>(vector));
263}
264
265template<class TYPE> inline
266ssize_t Vector<TYPE>::insertAt(const TYPE& item, size_t index, size_t numItems) {
267 return VectorImpl::insertAt(&item, index, numItems);
268}
269
270template<class TYPE> inline
271void Vector<TYPE>::push(const TYPE& item) {
272 return VectorImpl::push(&item);
273}
274
275template<class TYPE> inline
276ssize_t Vector<TYPE>::add(const TYPE& item) {
277 return VectorImpl::add(&item);
278}
279
280template<class TYPE> inline
281ssize_t Vector<TYPE>::replaceAt(const TYPE& item, size_t index) {
282 return VectorImpl::replaceAt(&item, index);
283}
284
285template<class TYPE> inline
286ssize_t Vector<TYPE>::insertAt(size_t index, size_t numItems) {
287 return VectorImpl::insertAt(index, numItems);
288}
289
290template<class TYPE> inline
291void Vector<TYPE>::pop() {
292 VectorImpl::pop();
293}
294
295template<class TYPE> inline
296void Vector<TYPE>::push() {
297 VectorImpl::push();
298}
299
300template<class TYPE> inline
301ssize_t Vector<TYPE>::add() {
302 return VectorImpl::add();
303}
304
305template<class TYPE> inline
306ssize_t Vector<TYPE>::replaceAt(size_t index) {
307 return VectorImpl::replaceAt(index);
308}
309
310template<class TYPE> inline
311ssize_t Vector<TYPE>::removeItemsAt(size_t index, size_t count) {
312 return VectorImpl::removeItemsAt(index, count);
313}
314
315// ---------------------------------------------------------------------------
316
317template<class TYPE>
318void Vector<TYPE>::do_construct(void* storage, size_t num) const {
319 construct_type( reinterpret_cast<TYPE*>(storage), num );
320}
321
322template<class TYPE>
323void Vector<TYPE>::do_destroy(void* storage, size_t num) const {
324 destroy_type( reinterpret_cast<TYPE*>(storage), num );
325}
326
327template<class TYPE>
328void Vector<TYPE>::do_copy(void* dest, const void* from, size_t num) const {
329 copy_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
330}
331
332template<class TYPE>
333void Vector<TYPE>::do_splat(void* dest, const void* item, size_t num) const {
334 splat_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(item), num );
335}
336
337template<class TYPE>
338void Vector<TYPE>::do_move_forward(void* dest, const void* from, size_t num) const {
339 move_forward_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
340}
341
342template<class TYPE>
343void Vector<TYPE>::do_move_backward(void* dest, const void* from, size_t num) const {
344 move_backward_type( reinterpret_cast<TYPE*>(dest), reinterpret_cast<const TYPE*>(from), num );
345}
346
347} // namespace tinyutils
348} // namespace android
349
350
351// ---------------------------------------------------------------------------
352
353#endif // ANDROID_PIXELFLINGER_VECTOR_H
diff --git a/libpixelflinger/codeflinger/tinyutils/VectorImpl.cpp b/libpixelflinger/codeflinger/tinyutils/VectorImpl.cpp
deleted file mode 100644
index 689129a65..000000000
--- a/libpixelflinger/codeflinger/tinyutils/VectorImpl.cpp
+++ /dev/null
@@ -1,555 +0,0 @@
1/*
2 * Copyright 2005 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "Vector"
18
19#include <string.h>
20#include <stdlib.h>
21#include <stdio.h>
22#include <errno.h>
23
24#include <cutils/log.h>
25
26#include "Errors.h"
27#include "SharedBuffer.h"
28#include "VectorImpl.h"
29
30/*****************************************************************************/
31
32
33namespace android {
34namespace tinyutils {
35
36// ----------------------------------------------------------------------------
37
38const size_t kMinVectorCapacity = 4;
39
40static inline size_t max(size_t a, size_t b) {
41 return a>b ? a : b;
42}
43
44// ----------------------------------------------------------------------------
45
46VectorImpl::VectorImpl(size_t itemSize, uint32_t flags)
47 : mStorage(0), mCount(0), mFlags(flags), mItemSize(itemSize)
48{
49}
50
51VectorImpl::VectorImpl(const VectorImpl& rhs)
52 : mStorage(rhs.mStorage), mCount(rhs.mCount),
53 mFlags(rhs.mFlags), mItemSize(rhs.mItemSize)
54{
55 if (mStorage) {
56 SharedBuffer::sharedBuffer(mStorage)->acquire();
57 }
58}
59
60VectorImpl::~VectorImpl()
61{
62 ALOG_ASSERT(!mCount,
63 "[%p] "
64 "subclasses of VectorImpl must call finish_vector()"
65 " in their destructor. Leaking %d bytes.",
66 this, (int)(mCount*mItemSize));
67 // We can't call _do_destroy() here because the vtable is already gone.
68}
69
70VectorImpl& VectorImpl::operator = (const VectorImpl& rhs)
71{
72 ALOG_ASSERT(mItemSize == rhs.mItemSize,
73 "Vector<> have different types (this=%p, rhs=%p)", this, &rhs);
74 if (this != &rhs) {
75 release_storage();
76 if (rhs.mCount) {
77 mStorage = rhs.mStorage;
78 mCount = rhs.mCount;
79 SharedBuffer::sharedBuffer(mStorage)->acquire();
80 } else {
81 mStorage = 0;
82 mCount = 0;
83 }
84 }
85 return *this;
86}
87
88void* VectorImpl::editArrayImpl()
89{
90 if (mStorage) {
91 SharedBuffer* sb = SharedBuffer::sharedBuffer(mStorage)->attemptEdit();
92 if (sb == 0) {
93 sb = SharedBuffer::alloc(capacity() * mItemSize);
94 if (sb) {
95 _do_copy(sb->data(), mStorage, mCount);
96 release_storage();
97 mStorage = sb->data();
98 }
99 }
100 }
101 return mStorage;
102}
103
104size_t VectorImpl::capacity() const
105{
106 if (mStorage) {
107 return SharedBuffer::sharedBuffer(mStorage)->size() / mItemSize;
108 }
109 return 0;
110}
111
112ssize_t VectorImpl::insertVectorAt(const VectorImpl& vector, size_t index)
113{
114 if (index > size())
115 return BAD_INDEX;
116 void* where = _grow(index, vector.size());
117 if (where) {
118 _do_copy(where, vector.arrayImpl(), vector.size());
119 }
120 return where ? index : (ssize_t)NO_MEMORY;
121}
122
123ssize_t VectorImpl::appendVector(const VectorImpl& vector)
124{
125 return insertVectorAt(vector, size());
126}
127
128ssize_t VectorImpl::insertAt(size_t index, size_t numItems)
129{
130 return insertAt(0, index, numItems);
131}
132
133ssize_t VectorImpl::insertAt(const void* item, size_t index, size_t numItems)
134{
135 if (index > size())
136 return BAD_INDEX;
137 void* where = _grow(index, numItems);
138 if (where) {
139 if (item) {
140 _do_splat(where, item, numItems);
141 } else {
142 _do_construct(where, numItems);
143 }
144 }
145 return where ? index : (ssize_t)NO_MEMORY;
146}
147
148void VectorImpl::pop()
149{
150 if (size())
151 removeItemsAt(size()-1, 1);
152}
153
154void VectorImpl::push()
155{
156 push(0);
157}
158
159void VectorImpl::push(const void* item)
160{
161 insertAt(item, size());
162}
163
164ssize_t VectorImpl::add()
165{
166 return add(0);
167}
168
169ssize_t VectorImpl::add(const void* item)
170{
171 return insertAt(item, size());
172}
173
174ssize_t VectorImpl::replaceAt(size_t index)
175{
176 return replaceAt(0, index);
177}
178
179ssize_t VectorImpl::replaceAt(const void* prototype, size_t index)
180{
181 ALOG_ASSERT(index<size(),
182 "[%p] replace: index=%d, size=%d", this, (int)index, (int)size());
183
184 void* item = editItemLocation(index);
185 if (item == 0)
186 return NO_MEMORY;
187 _do_destroy(item, 1);
188 if (prototype == 0) {
189 _do_construct(item, 1);
190 } else {
191 _do_copy(item, prototype, 1);
192 }
193 return ssize_t(index);
194}
195
196ssize_t VectorImpl::removeItemsAt(size_t index, size_t count)
197{
198 ALOG_ASSERT((index+count)<=size(),
199 "[%p] remove: index=%d, count=%d, size=%d",
200 this, (int)index, (int)count, (int)size());
201
202 if ((index+count) > size())
203 return BAD_VALUE;
204 _shrink(index, count);
205 return index;
206}
207
208void VectorImpl::finish_vector()
209{
210 release_storage();
211 mStorage = 0;
212 mCount = 0;
213}
214
215void VectorImpl::clear()
216{
217 _shrink(0, mCount);
218}
219
220void* VectorImpl::editItemLocation(size_t index)
221{
222 ALOG_ASSERT(index<capacity(),
223 "[%p] itemLocation: index=%d, capacity=%d, count=%d",
224 this, (int)index, (int)capacity(), (int)mCount);
225
226 void* buffer = editArrayImpl();
227 if (buffer)
228 return reinterpret_cast<char*>(buffer) + index*mItemSize;
229 return 0;
230}
231
232const void* VectorImpl::itemLocation(size_t index) const
233{
234 ALOG_ASSERT(index<capacity(),
235 "[%p] editItemLocation: index=%d, capacity=%d, count=%d",
236 this, (int)index, (int)capacity(), (int)mCount);
237
238 const void* buffer = arrayImpl();
239 if (buffer)
240 return reinterpret_cast<const char*>(buffer) + index*mItemSize;
241 return 0;
242}
243
244ssize_t VectorImpl::setCapacity(size_t new_capacity)
245{
246 size_t current_capacity = capacity();
247 ssize_t amount = new_capacity - size();
248 if (amount <= 0) {
249 // we can't reduce the capacity
250 return current_capacity;
251 }
252 SharedBuffer* sb = SharedBuffer::alloc(new_capacity * mItemSize);
253 if (sb) {
254 void* array = sb->data();
255 _do_copy(array, mStorage, size());
256 release_storage();
257 mStorage = const_cast<void*>(array);
258 } else {
259 return NO_MEMORY;
260 }
261 return new_capacity;
262}
263
264void VectorImpl::release_storage()
265{
266 if (mStorage) {
267 const SharedBuffer* sb = SharedBuffer::sharedBuffer(mStorage);
268 if (sb->release(SharedBuffer::eKeepStorage) == 1) {
269 _do_destroy(mStorage, mCount);
270 SharedBuffer::dealloc(sb);
271 }
272 }
273}
274
275void* VectorImpl::_grow(size_t where, size_t amount)
276{
277// ALOGV("_grow(this=%p, where=%d, amount=%d) count=%d, capacity=%d",
278// this, (int)where, (int)amount, (int)mCount, (int)capacity());
279
280 if (where > mCount)
281 where = mCount;
282
283 const size_t new_size = mCount + amount;
284 if (capacity() < new_size) {
285 const size_t new_capacity = max(kMinVectorCapacity, ((new_size*3)+1)/2);
286// ALOGV("grow vector %p, new_capacity=%d", this, (int)new_capacity);
287 if ((mStorage) &&
288 (mCount==where) &&
289 (mFlags & HAS_TRIVIAL_COPY) &&
290 (mFlags & HAS_TRIVIAL_DTOR))
291 {
292 const SharedBuffer* cur_sb = SharedBuffer::sharedBuffer(mStorage);
293 SharedBuffer* sb = cur_sb->editResize(new_capacity * mItemSize);
294 mStorage = sb->data();
295 } else {
296 SharedBuffer* sb = SharedBuffer::alloc(new_capacity * mItemSize);
297 if (sb) {
298 void* array = sb->data();
299 if (where>0) {
300 _do_copy(array, mStorage, where);
301 }
302 if (mCount>where) {
303 const void* from = reinterpret_cast<const uint8_t *>(mStorage) + where*mItemSize;
304 void* dest = reinterpret_cast<uint8_t *>(array) + (where+amount)*mItemSize;
305 _do_copy(dest, from, mCount-where);
306 }
307 release_storage();
308 mStorage = const_cast<void*>(array);
309 }
310 }
311 } else {
312 ssize_t s = mCount-where;
313 if (s>0) {
314 void* array = editArrayImpl();
315 void* to = reinterpret_cast<uint8_t *>(array) + (where+amount)*mItemSize;
316 const void* from = reinterpret_cast<const uint8_t *>(array) + where*mItemSize;
317 _do_move_forward(to, from, s);
318 }
319 }
320 mCount += amount;
321 void* free_space = const_cast<void*>(itemLocation(where));
322 return free_space;
323}
324
325void VectorImpl::_shrink(size_t where, size_t amount)
326{
327 if (!mStorage)
328 return;
329
330// ALOGV("_shrink(this=%p, where=%d, amount=%d) count=%d, capacity=%d",
331// this, (int)where, (int)amount, (int)mCount, (int)capacity());
332
333 if (where >= mCount)
334 where = mCount - amount;
335
336 const size_t new_size = mCount - amount;
337 if (new_size*3 < capacity()) {
338 const size_t new_capacity = max(kMinVectorCapacity, new_size*2);
339// ALOGV("shrink vector %p, new_capacity=%d", this, (int)new_capacity);
340 if ((where == mCount-amount) &&
341 (mFlags & HAS_TRIVIAL_COPY) &&
342 (mFlags & HAS_TRIVIAL_DTOR))
343 {
344 const SharedBuffer* cur_sb = SharedBuffer::sharedBuffer(mStorage);
345 SharedBuffer* sb = cur_sb->editResize(new_capacity * mItemSize);
346 mStorage = sb->data();
347 } else {
348 SharedBuffer* sb = SharedBuffer::alloc(new_capacity * mItemSize);
349 if (sb) {
350 void* array = sb->data();
351 if (where>0) {
352 _do_copy(array, mStorage, where);
353 }
354 if (mCount > where+amount) {
355 const void* from = reinterpret_cast<const uint8_t *>(mStorage) + (where+amount)*mItemSize;
356 void* dest = reinterpret_cast<uint8_t *>(array) + where*mItemSize;
357 _do_copy(dest, from, mCount-(where+amount));
358 }
359 release_storage();
360 mStorage = const_cast<void*>(array);
361 }
362 }
363 } else {
364 void* array = editArrayImpl();
365 void* to = reinterpret_cast<uint8_t *>(array) + where*mItemSize;
366 _do_destroy(to, amount);
367 ssize_t s = mCount-(where+amount);
368 if (s>0) {
369 const void* from = reinterpret_cast<uint8_t *>(array) + (where+amount)*mItemSize;
370 _do_move_backward(to, from, s);
371 }
372 }
373
374 // adjust the number of items...
375 mCount -= amount;
376}
377
378size_t VectorImpl::itemSize() const {
379 return mItemSize;
380}
381
382void VectorImpl::_do_construct(void* storage, size_t num) const
383{
384 if (!(mFlags & HAS_TRIVIAL_CTOR)) {
385 do_construct(storage, num);
386 }
387}
388
389void VectorImpl::_do_destroy(void* storage, size_t num) const
390{
391 if (!(mFlags & HAS_TRIVIAL_DTOR)) {
392 do_destroy(storage, num);
393 }
394}
395
396void VectorImpl::_do_copy(void* dest, const void* from, size_t num) const
397{
398 if (!(mFlags & HAS_TRIVIAL_COPY)) {
399 do_copy(dest, from, num);
400 } else {
401 memcpy(dest, from, num*itemSize());
402 }
403}
404
405void VectorImpl::_do_splat(void* dest, const void* item, size_t num) const {
406 do_splat(dest, item, num);
407}
408
409void VectorImpl::_do_move_forward(void* dest, const void* from, size_t num) const {
410 do_move_forward(dest, from, num);
411}
412
413void VectorImpl::_do_move_backward(void* dest, const void* from, size_t num) const {
414 do_move_backward(dest, from, num);
415}
416
417void VectorImpl::reservedVectorImpl1() { }
418void VectorImpl::reservedVectorImpl2() { }
419void VectorImpl::reservedVectorImpl3() { }
420void VectorImpl::reservedVectorImpl4() { }
421void VectorImpl::reservedVectorImpl5() { }
422void VectorImpl::reservedVectorImpl6() { }
423void VectorImpl::reservedVectorImpl7() { }
424void VectorImpl::reservedVectorImpl8() { }
425
426/*****************************************************************************/
427
428SortedVectorImpl::SortedVectorImpl(size_t itemSize, uint32_t flags)
429 : VectorImpl(itemSize, flags)
430{
431}
432
433SortedVectorImpl::SortedVectorImpl(const VectorImpl& rhs)
434: VectorImpl(rhs)
435{
436}
437
438SortedVectorImpl::~SortedVectorImpl()
439{
440}
441
442SortedVectorImpl& SortedVectorImpl::operator = (const SortedVectorImpl& rhs)
443{
444 return static_cast<SortedVectorImpl&>( VectorImpl::operator = (static_cast<const VectorImpl&>(rhs)) );
445}
446
447ssize_t SortedVectorImpl::indexOf(const void* item) const
448{
449 return _indexOrderOf(item);
450}
451
452size_t SortedVectorImpl::orderOf(const void* item) const
453{
454 size_t o;
455 _indexOrderOf(item, &o);
456 return o;
457}
458
459ssize_t SortedVectorImpl::_indexOrderOf(const void* item, size_t* order) const
460{
461 // binary search
462 ssize_t err = NAME_NOT_FOUND;
463 ssize_t l = 0;
464 ssize_t h = size()-1;
465 ssize_t mid;
466 const void* a = arrayImpl();
467 const size_t s = itemSize();
468 while (l <= h) {
469 mid = l + (h - l)/2;
470 const void* const curr = reinterpret_cast<const char *>(a) + (mid*s);
471 const int c = do_compare(curr, item);
472 if (c == 0) {
473 err = l = mid;
474 break;
475 } else if (c < 0) {
476 l = mid + 1;
477 } else {
478 h = mid - 1;
479 }
480 }
481 if (order) *order = l;
482 return err;
483}
484
485ssize_t SortedVectorImpl::add(const void* item)
486{
487 size_t order;
488 ssize_t index = _indexOrderOf(item, &order);
489 if (index < 0) {
490 index = VectorImpl::insertAt(item, order, 1);
491 } else {
492 index = VectorImpl::replaceAt(item, index);
493 }
494 return index;
495}
496
497ssize_t SortedVectorImpl::merge(const VectorImpl& vector)
498{
499 // naive merge...
500 if (!vector.isEmpty()) {
501 const void* buffer = vector.arrayImpl();
502 const size_t is = itemSize();
503 size_t s = vector.size();
504 for (size_t i=0 ; i<s ; i++) {
505 ssize_t err = add( reinterpret_cast<const char*>(buffer) + i*is );
506 if (err<0) {
507 return err;
508 }
509 }
510 }
511 return NO_ERROR;
512}
513
514ssize_t SortedVectorImpl::merge(const SortedVectorImpl& vector)
515{
516 // we've merging a sorted vector... nice!
517 ssize_t err = NO_ERROR;
518 if (!vector.isEmpty()) {
519 // first take care of the case where the vectors are sorted together
520 if (do_compare(vector.itemLocation(vector.size()-1), arrayImpl()) <= 0) {
521 err = VectorImpl::insertVectorAt(static_cast<const VectorImpl&>(vector), 0);
522 } else if (do_compare(vector.arrayImpl(), itemLocation(size()-1)) >= 0) {
523 err = VectorImpl::appendVector(static_cast<const VectorImpl&>(vector));
524 } else {
525 // this could be made a little better
526 err = merge(static_cast<const VectorImpl&>(vector));
527 }
528 }
529 return err;
530}
531
532ssize_t SortedVectorImpl::remove(const void* item)
533{
534 ssize_t i = indexOf(item);
535 if (i>=0) {
536 VectorImpl::removeItemsAt(i, 1);
537 }
538 return i;
539}
540
541void SortedVectorImpl::reservedSortedVectorImpl1() { };
542void SortedVectorImpl::reservedSortedVectorImpl2() { };
543void SortedVectorImpl::reservedSortedVectorImpl3() { };
544void SortedVectorImpl::reservedSortedVectorImpl4() { };
545void SortedVectorImpl::reservedSortedVectorImpl5() { };
546void SortedVectorImpl::reservedSortedVectorImpl6() { };
547void SortedVectorImpl::reservedSortedVectorImpl7() { };
548void SortedVectorImpl::reservedSortedVectorImpl8() { };
549
550
551/*****************************************************************************/
552
553} // namespace tinyutils
554} // namespace android
555
diff --git a/libpixelflinger/codeflinger/tinyutils/VectorImpl.h b/libpixelflinger/codeflinger/tinyutils/VectorImpl.h
deleted file mode 100644
index 56089b325..000000000
--- a/libpixelflinger/codeflinger/tinyutils/VectorImpl.h
+++ /dev/null
@@ -1,195 +0,0 @@
1/*
2 * Copyright 2005 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_PIXELFLINGER_VECTOR_IMPL_H
18#define ANDROID_PIXELFLINGER_VECTOR_IMPL_H
19
20#include <assert.h>
21#include <stdint.h>
22#include <sys/types.h>
23
24// ---------------------------------------------------------------------------
25// No user serviceable parts in here...
26// ---------------------------------------------------------------------------
27
28namespace android {
29namespace tinyutils {
30
31/*!
32 * Implementation of the guts of the vector<> class
33 * this ensures backward binary compatibility and
34 * reduces code size.
35 * For performance reasons, we expose mStorage and mCount
36 * so these fields are set in stone.
37 *
38 */
39
40class VectorImpl
41{
42public:
43 enum { // flags passed to the ctor
44 HAS_TRIVIAL_CTOR = 0x00000001,
45 HAS_TRIVIAL_DTOR = 0x00000002,
46 HAS_TRIVIAL_COPY = 0x00000004,
47 HAS_TRIVIAL_ASSIGN = 0x00000008
48 };
49
50 VectorImpl(size_t itemSize, uint32_t flags);
51 VectorImpl(const VectorImpl& rhs);
52 virtual ~VectorImpl();
53
54 /*! must be called from subclasses destructor */
55 void finish_vector();
56
57 VectorImpl& operator = (const VectorImpl& rhs);
58
59 /*! C-style array access */
60 inline const void* arrayImpl() const { return mStorage; }
61 void* editArrayImpl();
62
63 /*! vector stats */
64 inline size_t size() const { return mCount; }
65 inline bool isEmpty() const { return mCount == 0; }
66 size_t capacity() const;
67 ssize_t setCapacity(size_t size);
68
69 /*! append/insert another vector */
70 ssize_t insertVectorAt(const VectorImpl& vector, size_t index);
71 ssize_t appendVector(const VectorImpl& vector);
72
73 /*! add/insert/replace items */
74 ssize_t insertAt(size_t where, size_t numItems = 1);
75 ssize_t insertAt(const void* item, size_t where, size_t numItems = 1);
76 void pop();
77 void push();
78 void push(const void* item);
79 ssize_t add();
80 ssize_t add(const void* item);
81 ssize_t replaceAt(size_t index);
82 ssize_t replaceAt(const void* item, size_t index);
83
84 /*! remove items */
85 ssize_t removeItemsAt(size_t index, size_t count = 1);
86 void clear();
87
88 const void* itemLocation(size_t index) const;
89 void* editItemLocation(size_t index);
90
91protected:
92 size_t itemSize() const;
93 void release_storage();
94
95 virtual void do_construct(void* storage, size_t num) const = 0;
96 virtual void do_destroy(void* storage, size_t num) const = 0;
97 virtual void do_copy(void* dest, const void* from, size_t num) const = 0;
98 virtual void do_splat(void* dest, const void* item, size_t num) const = 0;
99 virtual void do_move_forward(void* dest, const void* from, size_t num) const = 0;
100 virtual void do_move_backward(void* dest, const void* from, size_t num) const = 0;
101
102 // take care of FBC...
103 virtual void reservedVectorImpl1();
104 virtual void reservedVectorImpl2();
105 virtual void reservedVectorImpl3();
106 virtual void reservedVectorImpl4();
107 virtual void reservedVectorImpl5();
108 virtual void reservedVectorImpl6();
109 virtual void reservedVectorImpl7();
110 virtual void reservedVectorImpl8();
111
112private:
113 void* _grow(size_t where, size_t amount);
114 void _shrink(size_t where, size_t amount);
115
116 inline void _do_construct(void* storage, size_t num) const;
117 inline void _do_destroy(void* storage, size_t num) const;
118 inline void _do_copy(void* dest, const void* from, size_t num) const;
119 inline void _do_splat(void* dest, const void* item, size_t num) const;
120 inline void _do_move_forward(void* dest, const void* from, size_t num) const;
121 inline void _do_move_backward(void* dest, const void* from, size_t num) const;
122
123 // These 2 fields are exposed in the inlines below,
124 // so they're set in stone.
125 void * mStorage; // base address of the vector
126 size_t mCount; // number of items
127
128 const uint32_t mFlags;
129 const size_t mItemSize;
130};
131
132
133
134class SortedVectorImpl : public VectorImpl
135{
136public:
137 SortedVectorImpl(size_t itemSize, uint32_t flags);
138 SortedVectorImpl(const VectorImpl& rhs);
139 virtual ~SortedVectorImpl();
140
141 SortedVectorImpl& operator = (const SortedVectorImpl& rhs);
142
143 //! finds the index of an item
144 ssize_t indexOf(const void* item) const;
145
146 //! finds where this item should be inserted
147 size_t orderOf(const void* item) const;
148
149 //! add an item in the right place (or replaces it if there is one)
150 ssize_t add(const void* item);
151
152 //! merges a vector into this one
153 ssize_t merge(const VectorImpl& vector);
154 ssize_t merge(const SortedVectorImpl& vector);
155
156 //! removes an item
157 ssize_t remove(const void* item);
158
159protected:
160 virtual int do_compare(const void* lhs, const void* rhs) const = 0;
161
162 // take care of FBC...
163 virtual void reservedSortedVectorImpl1();
164 virtual void reservedSortedVectorImpl2();
165 virtual void reservedSortedVectorImpl3();
166 virtual void reservedSortedVectorImpl4();
167 virtual void reservedSortedVectorImpl5();
168 virtual void reservedSortedVectorImpl6();
169 virtual void reservedSortedVectorImpl7();
170 virtual void reservedSortedVectorImpl8();
171
172private:
173 ssize_t _indexOrderOf(const void* item, size_t* order = 0) const;
174
175 // these are made private, because they can't be used on a SortedVector
176 // (they don't have an implementation either)
177 ssize_t add();
178 void pop();
179 void push();
180 void push(const void* item);
181 ssize_t insertVectorAt(const VectorImpl& vector, size_t index);
182 ssize_t appendVector(const VectorImpl& vector);
183 ssize_t insertAt(size_t where, size_t numItems = 1);
184 ssize_t insertAt(const void* item, size_t where, size_t numItems = 1);
185 ssize_t replaceAt(size_t index);
186 ssize_t replaceAt(const void* item, size_t index);
187};
188
189} // namespace tinyutils
190} // namespace android
191
192
193// ---------------------------------------------------------------------------
194
195#endif // ANDROID_PIXELFLINGER_VECTOR_IMPL_H