blob: 0d31facba90207e691c0e967f2fe2f2f22b6a683 [file] [log] [blame]
Jason Samsd19f10d2009-05-22 14:03:28 -07001
2/*
3 * Copyright (C) 2009 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include "rsContext.h"
19
20using namespace android;
21using namespace android::renderscript;
22
23
Jason Samsa9e7a052009-09-25 14:51:22 -070024Adapter1D::Adapter1D(Context *rsc) : ObjectBase(rsc)
Jason Samsd19f10d2009-05-22 14:03:28 -070025{
Jason Sams61f08d62009-09-25 16:37:33 -070026 mAllocFile = __FILE__;
27 mAllocLine = __LINE__;
Jason Samsd19f10d2009-05-22 14:03:28 -070028 reset();
29}
30
Jason Samsa9e7a052009-09-25 14:51:22 -070031Adapter1D::Adapter1D(Context *rsc, Allocation *a) : ObjectBase(rsc)
Jason Samsd19f10d2009-05-22 14:03:28 -070032{
Jason Sams61f08d62009-09-25 16:37:33 -070033 mAllocFile = __FILE__;
34 mAllocLine = __LINE__;
Jason Samsd19f10d2009-05-22 14:03:28 -070035 reset();
36 setAllocation(a);
37}
38
39void Adapter1D::reset()
40{
41 mY = 0;
42 mZ = 0;
43 mLOD = 0;
44 mFace = 0;
45}
46
47void * Adapter1D::getElement(uint32_t x)
48{
49 rsAssert(mAllocation.get());
50 rsAssert(mAllocation->getPtr());
51 rsAssert(mAllocation->getType());
52 uint8_t * ptr = static_cast<uint8_t *>(mAllocation->getPtr());
53 ptr += mAllocation->getType()->getLODOffset(mLOD, x, mY);
54 return ptr;
55}
56
57void Adapter1D::subData(uint32_t xoff, uint32_t count, const void *data)
58{
59 if (mAllocation.get() && mAllocation.get()->getType()) {
60 void *ptr = getElement(xoff);
61 count *= mAllocation.get()->getType()->getElementSizeBytes();
62 memcpy(ptr, data, count);
63 }
64}
65
66void Adapter1D::data(const void *data)
67{
Jason Samsbd1c3ad2009-08-03 16:03:08 -070068 memcpy(getElement(0),
69 data,
Jason Samsd19f10d2009-05-22 14:03:28 -070070 mAllocation.get()->getType()->getSizeBytes());
71}
72
73namespace android {
74namespace renderscript {
75
76RsAdapter1D rsi_Adapter1DCreate(Context *rsc)
77{
Jason Samsa9e7a052009-09-25 14:51:22 -070078 Adapter1D *a = new Adapter1D(rsc);
Jason Sams07ae4062009-08-27 20:23:34 -070079 a->incUserRef();
Jason Samsbd1c3ad2009-08-03 16:03:08 -070080 return a;
Jason Samsd19f10d2009-05-22 14:03:28 -070081}
82
Jason Samsd19f10d2009-05-22 14:03:28 -070083void rsi_Adapter1DBindAllocation(Context *rsc, RsAdapter1D va, RsAllocation valloc)
84{
85 Adapter1D * a = static_cast<Adapter1D *>(va);
86 Allocation * alloc = static_cast<Allocation *>(valloc);
87 a->setAllocation(alloc);
88}
89
90void rsi_Adapter1DSetConstraint(Context *rsc, RsAdapter1D va, RsDimension dim, uint32_t value)
91{
92 Adapter1D * a = static_cast<Adapter1D *>(va);
93 switch(dim) {
94 case RS_DIMENSION_X:
95 rsAssert(!"Cannot contrain X in an 1D adapter");
96 return;
97 case RS_DIMENSION_Y:
98 a->setY(value);
99 break;
100 case RS_DIMENSION_Z:
101 a->setZ(value);
102 break;
103 case RS_DIMENSION_LOD:
104 a->setLOD(value);
105 break;
106 case RS_DIMENSION_FACE:
107 a->setFace(value);
108 break;
109 default:
110 rsAssert(!"Unimplemented constraint");
111 return;
112 }
113}
114
115void rsi_Adapter1DSubData(Context *rsc, RsAdapter1D va, uint32_t xoff, uint32_t count, const void *data)
116{
117 Adapter1D * a = static_cast<Adapter1D *>(va);
118 a->subData(xoff, count, data);
119}
120
121void rsi_Adapter1DData(Context *rsc, RsAdapter1D va, const void *data)
122{
123 Adapter1D * a = static_cast<Adapter1D *>(va);
124 a->data(data);
125}
126
127}
128}
129
130//////////////////////////
131
Jason Samsa9e7a052009-09-25 14:51:22 -0700132Adapter2D::Adapter2D(Context *rsc) : ObjectBase(rsc)
Jason Samsd19f10d2009-05-22 14:03:28 -0700133{
Jason Sams61f08d62009-09-25 16:37:33 -0700134 mAllocFile = __FILE__;
135 mAllocLine = __LINE__;
Jason Samsd19f10d2009-05-22 14:03:28 -0700136 reset();
137}
138
Jason Samsa9e7a052009-09-25 14:51:22 -0700139Adapter2D::Adapter2D(Context *rsc, Allocation *a) : ObjectBase(rsc)
Jason Samsd19f10d2009-05-22 14:03:28 -0700140{
Jason Sams61f08d62009-09-25 16:37:33 -0700141 mAllocFile = __FILE__;
142 mAllocLine = __LINE__;
Jason Samsd19f10d2009-05-22 14:03:28 -0700143 reset();
144 setAllocation(a);
145}
146
147void Adapter2D::reset()
148{
149 mZ = 0;
150 mLOD = 0;
151 mFace = 0;
152}
153
154void * Adapter2D::getElement(uint32_t x, uint32_t y) const
155{
156 rsAssert(mAllocation.get());
157 rsAssert(mAllocation->getPtr());
158 rsAssert(mAllocation->getType());
159 uint8_t * ptr = static_cast<uint8_t *>(mAllocation->getPtr());
160 ptr += mAllocation->getType()->getLODOffset(mLOD, x, y);
161 return ptr;
162}
163
164void Adapter2D::subData(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data)
165{
166 rsAssert(mAllocation.get());
167 rsAssert(mAllocation->getPtr());
168 rsAssert(mAllocation->getType());
169
170 uint32_t eSize = mAllocation.get()->getType()->getElementSizeBytes();
171 uint32_t lineSize = eSize * w;
172 uint32_t destW = getDimX();
173
174 const uint8_t *src = static_cast<const uint8_t *>(data);
175 for (uint32_t line=yoff; line < (yoff+h); line++) {
176 memcpy(getElement(xoff, line), src, lineSize);
177 src += lineSize;
178 }
179}
180
181void Adapter2D::data(const void *data)
182{
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700183 memcpy(getElement(0,0),
184 data,
Jason Samsd19f10d2009-05-22 14:03:28 -0700185 mAllocation.get()->getType()->getSizeBytes());
186}
187
188
189
190namespace android {
191namespace renderscript {
192
193RsAdapter2D rsi_Adapter2DCreate(Context *rsc)
194{
Jason Samsa9e7a052009-09-25 14:51:22 -0700195 Adapter2D *a = new Adapter2D(rsc);
Jason Sams07ae4062009-08-27 20:23:34 -0700196 a->incUserRef();
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700197 return a;
Jason Samsd19f10d2009-05-22 14:03:28 -0700198}
199
Jason Samsd19f10d2009-05-22 14:03:28 -0700200void rsi_Adapter2DBindAllocation(Context *rsc, RsAdapter2D va, RsAllocation valloc)
201{
202 Adapter2D * a = static_cast<Adapter2D *>(va);
203 Allocation * alloc = static_cast<Allocation *>(valloc);
204 a->setAllocation(alloc);
205}
206
207void rsi_Adapter2DSetConstraint(Context *rsc, RsAdapter2D va, RsDimension dim, uint32_t value)
208{
209 Adapter2D * a = static_cast<Adapter2D *>(va);
210 switch(dim) {
211 case RS_DIMENSION_X:
212 rsAssert(!"Cannot contrain X in an 2D adapter");
213 return;
214 case RS_DIMENSION_Y:
215 rsAssert(!"Cannot contrain Y in an 2D adapter");
216 break;
217 case RS_DIMENSION_Z:
218 a->setZ(value);
219 break;
220 case RS_DIMENSION_LOD:
221 a->setLOD(value);
222 break;
223 case RS_DIMENSION_FACE:
224 a->setFace(value);
225 break;
226 default:
227 rsAssert(!"Unimplemented constraint");
228 return;
229 }
230}
231
232void rsi_Adapter2DData(Context *rsc, RsAdapter2D va, const void *data)
233{
234 Adapter2D * a = static_cast<Adapter2D *>(va);
235 a->data(data);
236}
237
238void rsi_Adapter2DSubData(Context *rsc, RsAdapter2D va, uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data)
239{
240 Adapter2D * a = static_cast<Adapter2D *>(va);
241 a->subData(xoff, yoff, w, h, data);
242}
243
244}
245}