blob: 8d363fde19e1476c122e6deddae2c5b761f26ef2 [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
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070018#ifndef ANDROID_RS_BUILD_FOR_HOST
Jason Sams326e0dd2009-05-22 14:03:28 -070019#include "rsContext.h"
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070020#else
21#include "rsContextHostStub.h"
22#endif
Jason Sams326e0dd2009-05-22 14:03:28 -070023
24using namespace android;
25using namespace android::renderscript;
26
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080027Adapter1D::Adapter1D(Context *rsc) : ObjectBase(rsc) {
Jason Sams326e0dd2009-05-22 14:03:28 -070028 reset();
29}
30
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080031Adapter1D::Adapter1D(Context *rsc, Allocation *a) : ObjectBase(rsc) {
Jason Sams326e0dd2009-05-22 14:03:28 -070032 reset();
33 setAllocation(a);
34}
35
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080036void Adapter1D::reset() {
Jason Sams326e0dd2009-05-22 14:03:28 -070037 mY = 0;
38 mZ = 0;
39 mLOD = 0;
40 mFace = 0;
41}
42
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080043void * Adapter1D::getElement(uint32_t x) {
Jason Sams326e0dd2009-05-22 14:03:28 -070044 rsAssert(mAllocation.get());
45 rsAssert(mAllocation->getPtr());
46 rsAssert(mAllocation->getType());
47 uint8_t * ptr = static_cast<uint8_t *>(mAllocation->getPtr());
48 ptr += mAllocation->getType()->getLODOffset(mLOD, x, mY);
49 return ptr;
50}
51
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080052void Adapter1D::subData(uint32_t xoff, uint32_t count, const void *data) {
Jason Sams326e0dd2009-05-22 14:03:28 -070053 if (mAllocation.get() && mAllocation.get()->getType()) {
54 void *ptr = getElement(xoff);
55 count *= mAllocation.get()->getType()->getElementSizeBytes();
56 memcpy(ptr, data, count);
57 }
58}
59
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080060void Adapter1D::data(const void *data) {
Jason Samsd3c8de22009-08-03 16:03:08 -070061 memcpy(getElement(0),
62 data,
Jason Sams326e0dd2009-05-22 14:03:28 -070063 mAllocation.get()->getType()->getSizeBytes());
64}
65
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080066void Adapter1D::serialize(OStream *stream) const {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070067}
68
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080069Adapter1D *Adapter1D::createFromStream(Context *rsc, IStream *stream) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070070 return NULL;
71}
72
Jason Sams326e0dd2009-05-22 14:03:28 -070073namespace android {
74namespace renderscript {
75
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080076RsAdapter1D rsi_Adapter1DCreate(Context *rsc) {
Jason Samse514b452009-09-25 14:51:22 -070077 Adapter1D *a = new Adapter1D(rsc);
Jason Sams9397e302009-08-27 20:23:34 -070078 a->incUserRef();
Jason Samsd3c8de22009-08-03 16:03:08 -070079 return a;
Jason Sams326e0dd2009-05-22 14:03:28 -070080}
81
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080082void rsi_Adapter1DBindAllocation(Context *rsc, RsAdapter1D va, RsAllocation valloc) {
Jason Sams326e0dd2009-05-22 14:03:28 -070083 Adapter1D * a = static_cast<Adapter1D *>(va);
84 Allocation * alloc = static_cast<Allocation *>(valloc);
85 a->setAllocation(alloc);
86}
87
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080088void rsi_Adapter1DSetConstraint(Context *rsc, RsAdapter1D va, RsDimension dim, uint32_t value) {
Jason Sams326e0dd2009-05-22 14:03:28 -070089 Adapter1D * a = static_cast<Adapter1D *>(va);
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080090 switch (dim) {
Jason Sams326e0dd2009-05-22 14:03:28 -070091 case RS_DIMENSION_X:
92 rsAssert(!"Cannot contrain X in an 1D adapter");
93 return;
94 case RS_DIMENSION_Y:
95 a->setY(value);
96 break;
97 case RS_DIMENSION_Z:
98 a->setZ(value);
99 break;
100 case RS_DIMENSION_LOD:
101 a->setLOD(value);
102 break;
103 case RS_DIMENSION_FACE:
104 a->setFace(value);
105 break;
106 default:
107 rsAssert(!"Unimplemented constraint");
108 return;
109 }
110}
111
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800112void rsi_Adapter1DSubData(Context *rsc, RsAdapter1D va, uint32_t xoff, uint32_t count, const void *data) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700113 Adapter1D * a = static_cast<Adapter1D *>(va);
114 a->subData(xoff, count, data);
115}
116
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800117void rsi_Adapter1DData(Context *rsc, RsAdapter1D va, const void *data) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700118 Adapter1D * a = static_cast<Adapter1D *>(va);
119 a->data(data);
120}
121
122}
123}
124
125//////////////////////////
126
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800127Adapter2D::Adapter2D(Context *rsc) : ObjectBase(rsc) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700128 reset();
129}
130
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800131Adapter2D::Adapter2D(Context *rsc, Allocation *a) : ObjectBase(rsc) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700132 reset();
133 setAllocation(a);
134}
135
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800136void Adapter2D::reset() {
Jason Sams326e0dd2009-05-22 14:03:28 -0700137 mZ = 0;
138 mLOD = 0;
139 mFace = 0;
140}
141
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800142void * Adapter2D::getElement(uint32_t x, uint32_t y) const {
Jason Sams326e0dd2009-05-22 14:03:28 -0700143 rsAssert(mAllocation.get());
144 rsAssert(mAllocation->getPtr());
145 rsAssert(mAllocation->getType());
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800146 if (mFace != 0 && !mAllocation->getType()->getDimFaces()) {
147 LOGE("Adapter wants cubemap face, but allocation has none");
148 return NULL;
149 }
150
Jason Sams326e0dd2009-05-22 14:03:28 -0700151 uint8_t * ptr = static_cast<uint8_t *>(mAllocation->getPtr());
152 ptr += mAllocation->getType()->getLODOffset(mLOD, x, y);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800153
154 if (mFace != 0) {
155 uint32_t totalSizeBytes = mAllocation->getType()->getSizeBytes();
156 uint32_t faceOffset = totalSizeBytes / 6;
157 ptr += faceOffset * mFace;
158 }
Jason Sams326e0dd2009-05-22 14:03:28 -0700159 return ptr;
160}
161
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800162void Adapter2D::subData(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700163 rsAssert(mAllocation.get());
164 rsAssert(mAllocation->getPtr());
165 rsAssert(mAllocation->getType());
166
167 uint32_t eSize = mAllocation.get()->getType()->getElementSizeBytes();
168 uint32_t lineSize = eSize * w;
Jason Sams326e0dd2009-05-22 14:03:28 -0700169
170 const uint8_t *src = static_cast<const uint8_t *>(data);
171 for (uint32_t line=yoff; line < (yoff+h); line++) {
172 memcpy(getElement(xoff, line), src, lineSize);
173 src += lineSize;
174 }
175}
176
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800177void Adapter2D::data(const void *data) {
Jason Samsd3c8de22009-08-03 16:03:08 -0700178 memcpy(getElement(0,0),
179 data,
Jason Sams326e0dd2009-05-22 14:03:28 -0700180 mAllocation.get()->getType()->getSizeBytes());
181}
182
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800183void Adapter2D::serialize(OStream *stream) const {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700184}
185
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800186Adapter2D *Adapter2D::createFromStream(Context *rsc, IStream *stream) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700187 return NULL;
188}
Jason Sams326e0dd2009-05-22 14:03:28 -0700189
190
191namespace android {
192namespace renderscript {
193
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800194RsAdapter2D rsi_Adapter2DCreate(Context *rsc) {
Jason Samse514b452009-09-25 14:51:22 -0700195 Adapter2D *a = new Adapter2D(rsc);
Jason Sams9397e302009-08-27 20:23:34 -0700196 a->incUserRef();
Jason Samsd3c8de22009-08-03 16:03:08 -0700197 return a;
Jason Sams326e0dd2009-05-22 14:03:28 -0700198}
199
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800200void rsi_Adapter2DBindAllocation(Context *rsc, RsAdapter2D va, RsAllocation valloc) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700201 Adapter2D * a = static_cast<Adapter2D *>(va);
202 Allocation * alloc = static_cast<Allocation *>(valloc);
203 a->setAllocation(alloc);
204}
205
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800206void rsi_Adapter2DSetConstraint(Context *rsc, RsAdapter2D va, RsDimension dim, uint32_t value) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700207 Adapter2D * a = static_cast<Adapter2D *>(va);
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800208 switch (dim) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700209 case RS_DIMENSION_X:
210 rsAssert(!"Cannot contrain X in an 2D adapter");
211 return;
212 case RS_DIMENSION_Y:
213 rsAssert(!"Cannot contrain Y in an 2D adapter");
214 break;
215 case RS_DIMENSION_Z:
216 a->setZ(value);
217 break;
218 case RS_DIMENSION_LOD:
219 a->setLOD(value);
220 break;
221 case RS_DIMENSION_FACE:
222 a->setFace(value);
223 break;
224 default:
225 rsAssert(!"Unimplemented constraint");
226 return;
227 }
228}
229
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800230void rsi_Adapter2DData(Context *rsc, RsAdapter2D va, const void *data) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700231 Adapter2D * a = static_cast<Adapter2D *>(va);
232 a->data(data);
233}
234
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800235void rsi_Adapter2DSubData(Context *rsc, RsAdapter2D va, uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700236 Adapter2D * a = static_cast<Adapter2D *>(va);
237 a->subData(xoff, yoff, w, h, data);
238}
239
240}
241}