blob: 25f334096832c41cf9c405abc0cace0876a7d438 [file] [log] [blame]
Jason Sams326e0dd2009-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
24Adapter1D::Adapter1D()
25{
26 reset();
27}
28
29Adapter1D::Adapter1D(Allocation *a)
30{
31 reset();
32 setAllocation(a);
33}
34
35void Adapter1D::reset()
36{
37 mY = 0;
38 mZ = 0;
39 mLOD = 0;
40 mFace = 0;
41}
42
43void * Adapter1D::getElement(uint32_t x)
44{
45 rsAssert(mAllocation.get());
46 rsAssert(mAllocation->getPtr());
47 rsAssert(mAllocation->getType());
48 uint8_t * ptr = static_cast<uint8_t *>(mAllocation->getPtr());
49 ptr += mAllocation->getType()->getLODOffset(mLOD, x, mY);
50 return ptr;
51}
52
53void Adapter1D::subData(uint32_t xoff, uint32_t count, const void *data)
54{
55 if (mAllocation.get() && mAllocation.get()->getType()) {
56 void *ptr = getElement(xoff);
57 count *= mAllocation.get()->getType()->getElementSizeBytes();
58 memcpy(ptr, data, count);
59 }
60}
61
62void Adapter1D::data(const void *data)
63{
Jason Samsd3c8de22009-08-03 16:03:08 -070064 memcpy(getElement(0),
65 data,
Jason Sams326e0dd2009-05-22 14:03:28 -070066 mAllocation.get()->getType()->getSizeBytes());
67}
68
69namespace android {
70namespace renderscript {
71
72RsAdapter1D rsi_Adapter1DCreate(Context *rsc)
73{
Jason Samsd3c8de22009-08-03 16:03:08 -070074 Adapter1D *a = new Adapter1D();
75 a->incRef();
76 return a;
Jason Sams326e0dd2009-05-22 14:03:28 -070077}
78
79void rsi_Adapter1DDestroy(Context *rsc, RsAdapter1D va)
80{
81 Adapter1D * a = static_cast<Adapter1D *>(va);
82 a->decRef();
83}
84
85void rsi_Adapter1DBindAllocation(Context *rsc, RsAdapter1D va, RsAllocation valloc)
86{
87 Adapter1D * a = static_cast<Adapter1D *>(va);
88 Allocation * alloc = static_cast<Allocation *>(valloc);
89 a->setAllocation(alloc);
90}
91
92void rsi_Adapter1DSetConstraint(Context *rsc, RsAdapter1D va, RsDimension dim, uint32_t value)
93{
94 Adapter1D * a = static_cast<Adapter1D *>(va);
95 switch(dim) {
96 case RS_DIMENSION_X:
97 rsAssert(!"Cannot contrain X in an 1D adapter");
98 return;
99 case RS_DIMENSION_Y:
100 a->setY(value);
101 break;
102 case RS_DIMENSION_Z:
103 a->setZ(value);
104 break;
105 case RS_DIMENSION_LOD:
106 a->setLOD(value);
107 break;
108 case RS_DIMENSION_FACE:
109 a->setFace(value);
110 break;
111 default:
112 rsAssert(!"Unimplemented constraint");
113 return;
114 }
115}
116
117void rsi_Adapter1DSubData(Context *rsc, RsAdapter1D va, uint32_t xoff, uint32_t count, const void *data)
118{
119 Adapter1D * a = static_cast<Adapter1D *>(va);
120 a->subData(xoff, count, data);
121}
122
123void rsi_Adapter1DData(Context *rsc, RsAdapter1D va, const void *data)
124{
125 Adapter1D * a = static_cast<Adapter1D *>(va);
126 a->data(data);
127}
128
129}
130}
131
132//////////////////////////
133
134Adapter2D::Adapter2D()
135{
136 reset();
137}
138
139Adapter2D::Adapter2D(Allocation *a)
140{
141 reset();
142 setAllocation(a);
143}
144
145void Adapter2D::reset()
146{
147 mZ = 0;
148 mLOD = 0;
149 mFace = 0;
150}
151
152void * Adapter2D::getElement(uint32_t x, uint32_t y) const
153{
154 rsAssert(mAllocation.get());
155 rsAssert(mAllocation->getPtr());
156 rsAssert(mAllocation->getType());
157 uint8_t * ptr = static_cast<uint8_t *>(mAllocation->getPtr());
158 ptr += mAllocation->getType()->getLODOffset(mLOD, x, y);
159 return ptr;
160}
161
162void Adapter2D::subData(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data)
163{
164 rsAssert(mAllocation.get());
165 rsAssert(mAllocation->getPtr());
166 rsAssert(mAllocation->getType());
167
168 uint32_t eSize = mAllocation.get()->getType()->getElementSizeBytes();
169 uint32_t lineSize = eSize * w;
170 uint32_t destW = getDimX();
171
172 const uint8_t *src = static_cast<const uint8_t *>(data);
173 for (uint32_t line=yoff; line < (yoff+h); line++) {
174 memcpy(getElement(xoff, line), src, lineSize);
175 src += lineSize;
176 }
177}
178
179void Adapter2D::data(const void *data)
180{
Jason Samsd3c8de22009-08-03 16:03:08 -0700181 memcpy(getElement(0,0),
182 data,
Jason Sams326e0dd2009-05-22 14:03:28 -0700183 mAllocation.get()->getType()->getSizeBytes());
184}
185
186
187
188namespace android {
189namespace renderscript {
190
191RsAdapter2D rsi_Adapter2DCreate(Context *rsc)
192{
Jason Samsd3c8de22009-08-03 16:03:08 -0700193 Adapter2D *a = new Adapter2D();
194 a->incRef();
195 return a;
Jason Sams326e0dd2009-05-22 14:03:28 -0700196}
197
198void rsi_Adapter2DDestroy(Context *rsc, RsAdapter2D va)
199{
200 Adapter2D * a = static_cast<Adapter2D *>(va);
201 a->decRef();
202}
203
204void rsi_Adapter2DBindAllocation(Context *rsc, RsAdapter2D va, RsAllocation valloc)
205{
206 Adapter2D * a = static_cast<Adapter2D *>(va);
207 Allocation * alloc = static_cast<Allocation *>(valloc);
208 a->setAllocation(alloc);
209}
210
211void rsi_Adapter2DSetConstraint(Context *rsc, RsAdapter2D va, RsDimension dim, uint32_t value)
212{
213 Adapter2D * a = static_cast<Adapter2D *>(va);
214 switch(dim) {
215 case RS_DIMENSION_X:
216 rsAssert(!"Cannot contrain X in an 2D adapter");
217 return;
218 case RS_DIMENSION_Y:
219 rsAssert(!"Cannot contrain Y in an 2D adapter");
220 break;
221 case RS_DIMENSION_Z:
222 a->setZ(value);
223 break;
224 case RS_DIMENSION_LOD:
225 a->setLOD(value);
226 break;
227 case RS_DIMENSION_FACE:
228 a->setFace(value);
229 break;
230 default:
231 rsAssert(!"Unimplemented constraint");
232 return;
233 }
234}
235
236void rsi_Adapter2DData(Context *rsc, RsAdapter2D va, const void *data)
237{
238 Adapter2D * a = static_cast<Adapter2D *>(va);
239 a->data(data);
240}
241
242void rsi_Adapter2DSubData(Context *rsc, RsAdapter2D va, uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data)
243{
244 Adapter2D * a = static_cast<Adapter2D *>(va);
245 a->subData(xoff, yoff, w, h, data);
246}
247
248}
249}