blob: b4ec2501408494f60ea3f7d5b608f4a2b4151ba5 [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
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070018#ifndef ANDROID_RS_BUILD_FOR_HOST
Jason Samsd19f10d2009-05-22 14:03:28 -070019#include "rsContext.h"
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070020#else
21#include "rsContextHostStub.h"
22#endif
Jason Samsd19f10d2009-05-22 14:03:28 -070023
24using namespace android;
25using namespace android::renderscript;
26
27
Jason Samsa9e7a052009-09-25 14:51:22 -070028Adapter1D::Adapter1D(Context *rsc) : ObjectBase(rsc)
Jason Samsd19f10d2009-05-22 14:03:28 -070029{
Jason Sams61f08d62009-09-25 16:37:33 -070030 mAllocFile = __FILE__;
31 mAllocLine = __LINE__;
Jason Samsd19f10d2009-05-22 14:03:28 -070032 reset();
33}
34
Jason Samsa9e7a052009-09-25 14:51:22 -070035Adapter1D::Adapter1D(Context *rsc, Allocation *a) : ObjectBase(rsc)
Jason Samsd19f10d2009-05-22 14:03:28 -070036{
Jason Sams61f08d62009-09-25 16:37:33 -070037 mAllocFile = __FILE__;
38 mAllocLine = __LINE__;
Jason Samsd19f10d2009-05-22 14:03:28 -070039 reset();
40 setAllocation(a);
41}
42
43void Adapter1D::reset()
44{
45 mY = 0;
46 mZ = 0;
47 mLOD = 0;
48 mFace = 0;
49}
50
51void * Adapter1D::getElement(uint32_t x)
52{
53 rsAssert(mAllocation.get());
54 rsAssert(mAllocation->getPtr());
55 rsAssert(mAllocation->getType());
56 uint8_t * ptr = static_cast<uint8_t *>(mAllocation->getPtr());
57 ptr += mAllocation->getType()->getLODOffset(mLOD, x, mY);
58 return ptr;
59}
60
61void Adapter1D::subData(uint32_t xoff, uint32_t count, const void *data)
62{
63 if (mAllocation.get() && mAllocation.get()->getType()) {
64 void *ptr = getElement(xoff);
65 count *= mAllocation.get()->getType()->getElementSizeBytes();
66 memcpy(ptr, data, count);
67 }
68}
69
70void Adapter1D::data(const void *data)
71{
Jason Samsbd1c3ad2009-08-03 16:03:08 -070072 memcpy(getElement(0),
73 data,
Jason Samsd19f10d2009-05-22 14:03:28 -070074 mAllocation.get()->getType()->getSizeBytes());
75}
76
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070077void Adapter1D::serialize(OStream *stream) const
78{
79
80}
81
82Adapter1D *Adapter1D::createFromStream(Context *rsc, IStream *stream)
83{
84 return NULL;
85}
86
Jason Samsd19f10d2009-05-22 14:03:28 -070087namespace android {
88namespace renderscript {
89
90RsAdapter1D rsi_Adapter1DCreate(Context *rsc)
91{
Jason Samsa9e7a052009-09-25 14:51:22 -070092 Adapter1D *a = new Adapter1D(rsc);
Jason Sams07ae4062009-08-27 20:23:34 -070093 a->incUserRef();
Jason Samsbd1c3ad2009-08-03 16:03:08 -070094 return a;
Jason Samsd19f10d2009-05-22 14:03:28 -070095}
96
Jason Samsd19f10d2009-05-22 14:03:28 -070097void rsi_Adapter1DBindAllocation(Context *rsc, RsAdapter1D va, RsAllocation valloc)
98{
99 Adapter1D * a = static_cast<Adapter1D *>(va);
100 Allocation * alloc = static_cast<Allocation *>(valloc);
101 a->setAllocation(alloc);
102}
103
104void rsi_Adapter1DSetConstraint(Context *rsc, RsAdapter1D va, RsDimension dim, uint32_t value)
105{
106 Adapter1D * a = static_cast<Adapter1D *>(va);
107 switch(dim) {
108 case RS_DIMENSION_X:
109 rsAssert(!"Cannot contrain X in an 1D adapter");
110 return;
111 case RS_DIMENSION_Y:
112 a->setY(value);
113 break;
114 case RS_DIMENSION_Z:
115 a->setZ(value);
116 break;
117 case RS_DIMENSION_LOD:
118 a->setLOD(value);
119 break;
120 case RS_DIMENSION_FACE:
121 a->setFace(value);
122 break;
123 default:
124 rsAssert(!"Unimplemented constraint");
125 return;
126 }
127}
128
129void rsi_Adapter1DSubData(Context *rsc, RsAdapter1D va, uint32_t xoff, uint32_t count, const void *data)
130{
131 Adapter1D * a = static_cast<Adapter1D *>(va);
132 a->subData(xoff, count, data);
133}
134
135void rsi_Adapter1DData(Context *rsc, RsAdapter1D va, const void *data)
136{
137 Adapter1D * a = static_cast<Adapter1D *>(va);
138 a->data(data);
139}
140
141}
142}
143
144//////////////////////////
145
Jason Samsa9e7a052009-09-25 14:51:22 -0700146Adapter2D::Adapter2D(Context *rsc) : ObjectBase(rsc)
Jason Samsd19f10d2009-05-22 14:03:28 -0700147{
Jason Sams61f08d62009-09-25 16:37:33 -0700148 mAllocFile = __FILE__;
149 mAllocLine = __LINE__;
Jason Samsd19f10d2009-05-22 14:03:28 -0700150 reset();
151}
152
Jason Samsa9e7a052009-09-25 14:51:22 -0700153Adapter2D::Adapter2D(Context *rsc, Allocation *a) : ObjectBase(rsc)
Jason Samsd19f10d2009-05-22 14:03:28 -0700154{
Jason Sams61f08d62009-09-25 16:37:33 -0700155 mAllocFile = __FILE__;
156 mAllocLine = __LINE__;
Jason Samsd19f10d2009-05-22 14:03:28 -0700157 reset();
158 setAllocation(a);
159}
160
161void Adapter2D::reset()
162{
163 mZ = 0;
164 mLOD = 0;
165 mFace = 0;
166}
167
168void * Adapter2D::getElement(uint32_t x, uint32_t y) const
169{
170 rsAssert(mAllocation.get());
171 rsAssert(mAllocation->getPtr());
172 rsAssert(mAllocation->getType());
173 uint8_t * ptr = static_cast<uint8_t *>(mAllocation->getPtr());
174 ptr += mAllocation->getType()->getLODOffset(mLOD, x, y);
175 return ptr;
176}
177
178void Adapter2D::subData(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data)
179{
180 rsAssert(mAllocation.get());
181 rsAssert(mAllocation->getPtr());
182 rsAssert(mAllocation->getType());
183
184 uint32_t eSize = mAllocation.get()->getType()->getElementSizeBytes();
185 uint32_t lineSize = eSize * w;
186 uint32_t destW = getDimX();
187
188 const uint8_t *src = static_cast<const uint8_t *>(data);
189 for (uint32_t line=yoff; line < (yoff+h); line++) {
190 memcpy(getElement(xoff, line), src, lineSize);
191 src += lineSize;
192 }
193}
194
195void Adapter2D::data(const void *data)
196{
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700197 memcpy(getElement(0,0),
198 data,
Jason Samsd19f10d2009-05-22 14:03:28 -0700199 mAllocation.get()->getType()->getSizeBytes());
200}
201
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -0700202void Adapter2D::serialize(OStream *stream) const
203{
204
205}
206
207Adapter2D *Adapter2D::createFromStream(Context *rsc, IStream *stream)
208{
209 return NULL;
210}
Jason Samsd19f10d2009-05-22 14:03:28 -0700211
212
213namespace android {
214namespace renderscript {
215
216RsAdapter2D rsi_Adapter2DCreate(Context *rsc)
217{
Jason Samsa9e7a052009-09-25 14:51:22 -0700218 Adapter2D *a = new Adapter2D(rsc);
Jason Sams07ae4062009-08-27 20:23:34 -0700219 a->incUserRef();
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700220 return a;
Jason Samsd19f10d2009-05-22 14:03:28 -0700221}
222
Jason Samsd19f10d2009-05-22 14:03:28 -0700223void rsi_Adapter2DBindAllocation(Context *rsc, RsAdapter2D va, RsAllocation valloc)
224{
225 Adapter2D * a = static_cast<Adapter2D *>(va);
226 Allocation * alloc = static_cast<Allocation *>(valloc);
227 a->setAllocation(alloc);
228}
229
230void rsi_Adapter2DSetConstraint(Context *rsc, RsAdapter2D va, RsDimension dim, uint32_t value)
231{
232 Adapter2D * a = static_cast<Adapter2D *>(va);
233 switch(dim) {
234 case RS_DIMENSION_X:
235 rsAssert(!"Cannot contrain X in an 2D adapter");
236 return;
237 case RS_DIMENSION_Y:
238 rsAssert(!"Cannot contrain Y in an 2D adapter");
239 break;
240 case RS_DIMENSION_Z:
241 a->setZ(value);
242 break;
243 case RS_DIMENSION_LOD:
244 a->setLOD(value);
245 break;
246 case RS_DIMENSION_FACE:
247 a->setFace(value);
248 break;
249 default:
250 rsAssert(!"Unimplemented constraint");
251 return;
252 }
253}
254
255void rsi_Adapter2DData(Context *rsc, RsAdapter2D va, const void *data)
256{
257 Adapter2D * a = static_cast<Adapter2D *>(va);
258 a->data(data);
259}
260
261void rsi_Adapter2DSubData(Context *rsc, RsAdapter2D va, uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data)
262{
263 Adapter2D * a = static_cast<Adapter2D *>(va);
264 a->subData(xoff, yoff, w, h, data);
265}
266
267}
268}