blob: 177fb6028009eaffb125383ff953f10bde2a5b7a [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
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080023Adapter1D::Adapter1D(Context *rsc) : ObjectBase(rsc) {
Jason Samsd19f10d2009-05-22 14:03:28 -070024 reset();
25}
26
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080027Adapter1D::Adapter1D(Context *rsc, Allocation *a) : ObjectBase(rsc) {
Jason Samsd19f10d2009-05-22 14:03:28 -070028 reset();
29 setAllocation(a);
30}
31
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080032void Adapter1D::reset() {
Jason Samsd19f10d2009-05-22 14:03:28 -070033 mY = 0;
34 mZ = 0;
35 mLOD = 0;
36 mFace = 0;
37}
38
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080039void * Adapter1D::getElement(uint32_t x) {
Jason Samsd19f10d2009-05-22 14:03:28 -070040 rsAssert(mAllocation.get());
41 rsAssert(mAllocation->getPtr());
42 rsAssert(mAllocation->getType());
43 uint8_t * ptr = static_cast<uint8_t *>(mAllocation->getPtr());
44 ptr += mAllocation->getType()->getLODOffset(mLOD, x, mY);
45 return ptr;
46}
47
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080048void Adapter1D::subData(uint32_t xoff, uint32_t count, const void *data) {
Jason Samsd19f10d2009-05-22 14:03:28 -070049 if (mAllocation.get() && mAllocation.get()->getType()) {
50 void *ptr = getElement(xoff);
51 count *= mAllocation.get()->getType()->getElementSizeBytes();
52 memcpy(ptr, data, count);
53 }
54}
55
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080056void Adapter1D::data(const void *data) {
Jason Samsbd1c3ad2009-08-03 16:03:08 -070057 memcpy(getElement(0),
58 data,
Jason Samsd19f10d2009-05-22 14:03:28 -070059 mAllocation.get()->getType()->getSizeBytes());
60}
61
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080062void Adapter1D::serialize(OStream *stream) const {
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070063}
64
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080065Adapter1D *Adapter1D::createFromStream(Context *rsc, IStream *stream) {
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -070066 return NULL;
67}
68
Jason Samsd19f10d2009-05-22 14:03:28 -070069namespace android {
70namespace renderscript {
71
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080072RsAdapter1D rsi_Adapter1DCreate(Context *rsc) {
Jason Samsa9e7a052009-09-25 14:51:22 -070073 Adapter1D *a = new Adapter1D(rsc);
Jason Sams07ae4062009-08-27 20:23:34 -070074 a->incUserRef();
Jason Samsbd1c3ad2009-08-03 16:03:08 -070075 return a;
Jason Samsd19f10d2009-05-22 14:03:28 -070076}
77
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080078void rsi_Adapter1DBindAllocation(Context *rsc, RsAdapter1D va, RsAllocation valloc) {
Jason Samsd19f10d2009-05-22 14:03:28 -070079 Adapter1D * a = static_cast<Adapter1D *>(va);
80 Allocation * alloc = static_cast<Allocation *>(valloc);
81 a->setAllocation(alloc);
82}
83
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080084void rsi_Adapter1DSetConstraint(Context *rsc, RsAdapter1D va, RsDimension dim, uint32_t value) {
Jason Samsd19f10d2009-05-22 14:03:28 -070085 Adapter1D * a = static_cast<Adapter1D *>(va);
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080086 switch (dim) {
Jason Samsd19f10d2009-05-22 14:03:28 -070087 case RS_DIMENSION_X:
88 rsAssert(!"Cannot contrain X in an 1D adapter");
89 return;
90 case RS_DIMENSION_Y:
91 a->setY(value);
92 break;
93 case RS_DIMENSION_Z:
94 a->setZ(value);
95 break;
96 case RS_DIMENSION_LOD:
97 a->setLOD(value);
98 break;
99 case RS_DIMENSION_FACE:
100 a->setFace(value);
101 break;
102 default:
103 rsAssert(!"Unimplemented constraint");
104 return;
105 }
106}
107
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800108void rsi_Adapter1DSubData(Context *rsc, RsAdapter1D va, uint32_t xoff, uint32_t count, const void *data) {
Jason Samsd19f10d2009-05-22 14:03:28 -0700109 Adapter1D * a = static_cast<Adapter1D *>(va);
110 a->subData(xoff, count, data);
111}
112
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800113void rsi_Adapter1DData(Context *rsc, RsAdapter1D va, const void *data) {
Jason Samsd19f10d2009-05-22 14:03:28 -0700114 Adapter1D * a = static_cast<Adapter1D *>(va);
115 a->data(data);
116}
117
118}
119}
120
121//////////////////////////
122
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800123Adapter2D::Adapter2D(Context *rsc) : ObjectBase(rsc) {
Jason Samsd19f10d2009-05-22 14:03:28 -0700124 reset();
125}
126
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800127Adapter2D::Adapter2D(Context *rsc, Allocation *a) : ObjectBase(rsc) {
Jason Samsd19f10d2009-05-22 14:03:28 -0700128 reset();
129 setAllocation(a);
130}
131
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800132void Adapter2D::reset() {
Jason Samsd19f10d2009-05-22 14:03:28 -0700133 mZ = 0;
134 mLOD = 0;
135 mFace = 0;
136}
137
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800138void * Adapter2D::getElement(uint32_t x, uint32_t y) const {
Jason Samsd19f10d2009-05-22 14:03:28 -0700139 rsAssert(mAllocation.get());
140 rsAssert(mAllocation->getPtr());
141 rsAssert(mAllocation->getType());
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800142 if (mFace != 0 && !mAllocation->getType()->getDimFaces()) {
Steve Block3762c312012-01-06 19:20:56 +0000143 ALOGE("Adapter wants cubemap face, but allocation has none");
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800144 return NULL;
145 }
146
Jason Samsd19f10d2009-05-22 14:03:28 -0700147 uint8_t * ptr = static_cast<uint8_t *>(mAllocation->getPtr());
148 ptr += mAllocation->getType()->getLODOffset(mLOD, x, y);
Alex Sakhartchouk67f2e442010-11-18 15:22:43 -0800149
150 if (mFace != 0) {
151 uint32_t totalSizeBytes = mAllocation->getType()->getSizeBytes();
152 uint32_t faceOffset = totalSizeBytes / 6;
153 ptr += faceOffset * mFace;
154 }
Jason Samsd19f10d2009-05-22 14:03:28 -0700155 return ptr;
156}
157
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800158void Adapter2D::subData(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data) {
Jason Samsd19f10d2009-05-22 14:03:28 -0700159 rsAssert(mAllocation.get());
160 rsAssert(mAllocation->getPtr());
161 rsAssert(mAllocation->getType());
162
163 uint32_t eSize = mAllocation.get()->getType()->getElementSizeBytes();
164 uint32_t lineSize = eSize * w;
Jason Samsd19f10d2009-05-22 14:03:28 -0700165
166 const uint8_t *src = static_cast<const uint8_t *>(data);
167 for (uint32_t line=yoff; line < (yoff+h); line++) {
168 memcpy(getElement(xoff, line), src, lineSize);
169 src += lineSize;
170 }
171}
172
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800173void Adapter2D::data(const void *data) {
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700174 memcpy(getElement(0,0),
175 data,
Jason Samsd19f10d2009-05-22 14:03:28 -0700176 mAllocation.get()->getType()->getSizeBytes());
177}
178
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800179void Adapter2D::serialize(OStream *stream) const {
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -0700180}
181
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800182Adapter2D *Adapter2D::createFromStream(Context *rsc, IStream *stream) {
Alex Sakhartchoukaa7d2882010-05-21 12:53:13 -0700183 return NULL;
184}
Jason Samsd19f10d2009-05-22 14:03:28 -0700185
186
187namespace android {
188namespace renderscript {
189
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800190RsAdapter2D rsi_Adapter2DCreate(Context *rsc) {
Jason Samsa9e7a052009-09-25 14:51:22 -0700191 Adapter2D *a = new Adapter2D(rsc);
Jason Sams07ae4062009-08-27 20:23:34 -0700192 a->incUserRef();
Jason Samsbd1c3ad2009-08-03 16:03:08 -0700193 return a;
Jason Samsd19f10d2009-05-22 14:03:28 -0700194}
195
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800196void rsi_Adapter2DBindAllocation(Context *rsc, RsAdapter2D va, RsAllocation valloc) {
Jason Samsd19f10d2009-05-22 14:03:28 -0700197 Adapter2D * a = static_cast<Adapter2D *>(va);
198 Allocation * alloc = static_cast<Allocation *>(valloc);
199 a->setAllocation(alloc);
200}
201
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800202void rsi_Adapter2DSetConstraint(Context *rsc, RsAdapter2D va, RsDimension dim, uint32_t value) {
Jason Samsd19f10d2009-05-22 14:03:28 -0700203 Adapter2D * a = static_cast<Adapter2D *>(va);
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800204 switch (dim) {
Jason Samsd19f10d2009-05-22 14:03:28 -0700205 case RS_DIMENSION_X:
206 rsAssert(!"Cannot contrain X in an 2D adapter");
207 return;
208 case RS_DIMENSION_Y:
209 rsAssert(!"Cannot contrain Y in an 2D adapter");
210 break;
211 case RS_DIMENSION_Z:
212 a->setZ(value);
213 break;
214 case RS_DIMENSION_LOD:
215 a->setLOD(value);
216 break;
217 case RS_DIMENSION_FACE:
218 a->setFace(value);
219 break;
220 default:
221 rsAssert(!"Unimplemented constraint");
222 return;
223 }
224}
225
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800226void rsi_Adapter2DData(Context *rsc, RsAdapter2D va, const void *data) {
Jason Samsd19f10d2009-05-22 14:03:28 -0700227 Adapter2D * a = static_cast<Adapter2D *>(va);
228 a->data(data);
229}
230
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800231void rsi_Adapter2DSubData(Context *rsc, RsAdapter2D va, uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, const void *data) {
Jason Samsd19f10d2009-05-22 14:03:28 -0700232 Adapter2D * a = static_cast<Adapter2D *>(va);
233 a->subData(xoff, yoff, w, h, data);
234}
235
236}
237}