blob: afbff913ae9e484d0b852eb3f03b43ad7e87d7d2 [file] [log] [blame]
Tim Murray84bf2b82012-10-31 16:03:16 -07001/*
Tim Murray89daad62013-07-29 14:30:02 -07002 * Copyright (C) 2013 The Android Open Source Project
Tim Murray84bf2b82012-10-31 16:03:16 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_RSCPPSTRUCTS_H
18#define ANDROID_RSCPPSTRUCTS_H
19
Tim Murray89daad62013-07-29 14:30:02 -070020#include "rsDefines.h"
Jason Samsf9e077a2013-03-20 19:04:19 -070021#include "rsCppUtils.h"
Tim Murray89daad62013-07-29 14:30:02 -070022#include "util/RefBase.h"
Tim Murraya4230962013-07-17 16:50:10 -070023#include "rsDispatch.h"
24
Tim Murray89daad62013-07-29 14:30:02 -070025#include <vector>
Tim Murrayab716362013-08-12 12:37:18 -070026#include <string>
Tim Murray89daad62013-07-29 14:30:02 -070027
Tim Murray96267c22013-02-12 11:25:12 -080028// Every row in an RS allocation is guaranteed to be aligned by this amount
29// Every row in a user-backed allocation must be aligned by this amount
30#define RS_CPU_ALLOCATION_ALIGNMENT 16
31
Tim Murray84bf2b82012-10-31 16:03:16 -070032namespace android {
Tim Murray9eb7f4b2012-11-16 14:02:18 -080033namespace RSC {
Tim Murray84bf2b82012-10-31 16:03:16 -070034
35typedef void (*ErrorHandlerFunc_t)(uint32_t errorNum, const char *errorText);
36typedef void (*MessageHandlerFunc_t)(uint32_t msgNum, const void *msgData, size_t msgLen);
37
38class RS;
39class BaseObj;
40class Element;
41class Type;
42class Allocation;
43class Script;
44class ScriptC;
Tim Murray729b6fe2013-07-23 16:20:42 -070045class Sampler;
Tim Murray84bf2b82012-10-31 16:03:16 -070046
Tim Murray89daad62013-07-29 14:30:02 -070047 class RS : public android::RSC::LightRefBase<RS> {
Tim Murray84bf2b82012-10-31 16:03:16 -070048
49 public:
50 RS();
51 virtual ~RS();
52
Tim Murray4d252d62012-11-29 14:37:59 -080053 bool init(bool forceCpu = false, bool synchronous = false);
Tim Murray84bf2b82012-10-31 16:03:16 -070054
55 void setErrorHandler(ErrorHandlerFunc_t func);
56 ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; }
57
58 void setMessageHandler(MessageHandlerFunc_t func);
59 MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; }
60
61 void throwError(const char *err) const;
62
63 RsContext getContext() { return mContext; }
64
Tim Murraybaca6c32012-11-14 16:51:46 -080065 void finish();
66
Tim Murraya4230962013-07-17 16:50:10 -070067 static dispatchTable* dispatch;
68
Tim Murray84bf2b82012-10-31 16:03:16 -070069 private:
Tim Murray4a92d122013-07-22 10:56:18 -070070 static bool usingNative;
Tim Murraya4230962013-07-17 16:50:10 -070071 static bool initDispatch(int targetApi);
72
Tim Murray4d252d62012-11-29 14:37:59 -080073 bool init(int targetApi, bool forceCpu, bool synchronous);
Tim Murray84bf2b82012-10-31 16:03:16 -070074 static void * threadProc(void *);
75
76 static bool gInitialized;
77 static pthread_mutex_t gInitMutex;
78
79 pthread_t mMessageThreadId;
80 pid_t mNativeMessageThreadId;
81 bool mMessageRun;
82
83 RsDevice mDev;
84 RsContext mContext;
85
86 ErrorHandlerFunc_t mErrorFunc;
87 MessageHandlerFunc_t mMessageFunc;
Tim Murraya4230962013-07-17 16:50:10 -070088 bool mInit;
Tim Murray84bf2b82012-10-31 16:03:16 -070089
90 struct {
Tim Murray89daad62013-07-29 14:30:02 -070091 sp<const Element> U8;
92 sp<const Element> I8;
93 sp<const Element> U16;
94 sp<const Element> I16;
95 sp<const Element> U32;
96 sp<const Element> I32;
97 sp<const Element> U64;
98 sp<const Element> I64;
99 sp<const Element> F32;
100 sp<const Element> F64;
101 sp<const Element> BOOLEAN;
Tim Murray84bf2b82012-10-31 16:03:16 -0700102
Tim Murray89daad62013-07-29 14:30:02 -0700103 sp<const Element> ELEMENT;
104 sp<const Element> TYPE;
105 sp<const Element> ALLOCATION;
106 sp<const Element> SAMPLER;
107 sp<const Element> SCRIPT;
108 sp<const Element> MESH;
109 sp<const Element> PROGRAM_FRAGMENT;
110 sp<const Element> PROGRAM_VERTEX;
111 sp<const Element> PROGRAM_RASTER;
112 sp<const Element> PROGRAM_STORE;
Tim Murray84bf2b82012-10-31 16:03:16 -0700113
Tim Murray89daad62013-07-29 14:30:02 -0700114 sp<const Element> A_8;
115 sp<const Element> RGB_565;
116 sp<const Element> RGB_888;
117 sp<const Element> RGBA_5551;
118 sp<const Element> RGBA_4444;
119 sp<const Element> RGBA_8888;
Tim Murray84bf2b82012-10-31 16:03:16 -0700120
Tim Murray89daad62013-07-29 14:30:02 -0700121 sp<const Element> FLOAT_2;
122 sp<const Element> FLOAT_3;
123 sp<const Element> FLOAT_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700124
Tim Murray89daad62013-07-29 14:30:02 -0700125 sp<const Element> DOUBLE_2;
126 sp<const Element> DOUBLE_3;
127 sp<const Element> DOUBLE_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700128
Tim Murray89daad62013-07-29 14:30:02 -0700129 sp<const Element> UCHAR_2;
130 sp<const Element> UCHAR_3;
131 sp<const Element> UCHAR_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700132
Tim Murray89daad62013-07-29 14:30:02 -0700133 sp<const Element> CHAR_2;
134 sp<const Element> CHAR_3;
135 sp<const Element> CHAR_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700136
Tim Murray89daad62013-07-29 14:30:02 -0700137 sp<const Element> USHORT_2;
138 sp<const Element> USHORT_3;
139 sp<const Element> USHORT_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700140
Tim Murray89daad62013-07-29 14:30:02 -0700141 sp<const Element> SHORT_2;
142 sp<const Element> SHORT_3;
143 sp<const Element> SHORT_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700144
Tim Murray89daad62013-07-29 14:30:02 -0700145 sp<const Element> UINT_2;
146 sp<const Element> UINT_3;
147 sp<const Element> UINT_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700148
Tim Murray89daad62013-07-29 14:30:02 -0700149 sp<const Element> INT_2;
150 sp<const Element> INT_3;
151 sp<const Element> INT_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700152
Tim Murray89daad62013-07-29 14:30:02 -0700153 sp<const Element> ULONG_2;
154 sp<const Element> ULONG_3;
155 sp<const Element> ULONG_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700156
Tim Murray89daad62013-07-29 14:30:02 -0700157 sp<const Element> LONG_2;
158 sp<const Element> LONG_3;
159 sp<const Element> LONG_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700160
Tim Murray89daad62013-07-29 14:30:02 -0700161 sp<const Element> MATRIX_4X4;
162 sp<const Element> MATRIX_3X3;
163 sp<const Element> MATRIX_2X2;
Tim Murray84bf2b82012-10-31 16:03:16 -0700164 } mElements;
165
Tim Murray729b6fe2013-07-23 16:20:42 -0700166 struct {
Tim Murray89daad62013-07-29 14:30:02 -0700167 sp<const Sampler> CLAMP_NEAREST;
168 sp<const Sampler> CLAMP_LINEAR;
169 sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR;
170 sp<const Sampler> WRAP_NEAREST;
171 sp<const Sampler> WRAP_LINEAR;
172 sp<const Sampler> WRAP_LINEAR_MIP_LINEAR;
173 sp<const Sampler> MIRRORED_REPEAT_NEAREST;
174 sp<const Sampler> MIRRORED_REPEAT_LINEAR;
175 sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
Tim Murray729b6fe2013-07-23 16:20:42 -0700176 } mSamplers;
177 friend class Sampler;
178 friend class Element;
Tim Murray84bf2b82012-10-31 16:03:16 -0700179};
180
Tim Murray89daad62013-07-29 14:30:02 -0700181class BaseObj : public android::RSC::LightRefBase<BaseObj> {
182public:
183 void * getID() const;
184 virtual ~BaseObj();
185 virtual void updateFromNative();
186 virtual bool equals(sp<const BaseObj> obj);
187
Tim Murray84bf2b82012-10-31 16:03:16 -0700188protected:
189 void *mID;
190 sp<RS> mRS;
Tim Murrayab716362013-08-12 12:37:18 -0700191 std::string mName;
Tim Murray84bf2b82012-10-31 16:03:16 -0700192
193 BaseObj(void *id, sp<RS> rs);
194 void checkValid();
195
196 static void * getObjID(sp<const BaseObj> o);
197
Tim Murray84bf2b82012-10-31 16:03:16 -0700198};
199
200
201class Allocation : public BaseObj {
202protected:
Tim Murray89daad62013-07-29 14:30:02 -0700203 sp<const Type> mType;
Tim Murray84bf2b82012-10-31 16:03:16 -0700204 uint32_t mUsage;
Tim Murray89daad62013-07-29 14:30:02 -0700205 sp<Allocation> mAdaptedAllocation;
Tim Murray84bf2b82012-10-31 16:03:16 -0700206
207 bool mConstrainedLOD;
208 bool mConstrainedFace;
209 bool mConstrainedY;
210 bool mConstrainedZ;
211 bool mReadAllowed;
212 bool mWriteAllowed;
213 uint32_t mSelectedY;
214 uint32_t mSelectedZ;
215 uint32_t mSelectedLOD;
216 RsAllocationCubemapFace mSelectedFace;
217
218 uint32_t mCurrentDimX;
219 uint32_t mCurrentDimY;
220 uint32_t mCurrentDimZ;
221 uint32_t mCurrentCount;
222
223 void * getIDSafe() const;
224 void updateCacheInfo(sp<const Type> t);
225
226 Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage);
227
228 void validateIsInt32();
229 void validateIsInt16();
230 void validateIsInt8();
231 void validateIsFloat32();
232 void validateIsObject();
233
234 virtual void updateFromNative();
235
236 void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h);
237
238public:
Tim Murray89daad62013-07-29 14:30:02 -0700239 sp<const Type> getType() {
Tim Murray84bf2b82012-10-31 16:03:16 -0700240 return mType;
241 }
242
243 void syncAll(RsAllocationUsageType srcLocation);
244 void ioSendOutput();
245 void ioGetInput();
246
247 void generateMipmaps();
Tim Murray509ea5c2012-11-13 11:56:40 -0800248
Tim Murray0b93e302012-11-15 14:56:54 -0800249 void copy1DRangeFrom(uint32_t off, size_t count, const void *data);
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800250 void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700251
Tim Murray0b93e302012-11-15 14:56:54 -0800252 void copy1DRangeTo(uint32_t off, size_t count, void *data);
253
254 void copy1DFrom(const void* data);
255 void copy1DTo(void* data);
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800256
Tim Murray84bf2b82012-10-31 16:03:16 -0700257 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
Tim Murray0b93e302012-11-15 14:56:54 -0800258 const void *data);
Tim Murray7b3e3092012-11-16 13:32:24 -0800259
260 void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
261 void *data);
262
Tim Murray0b93e302012-11-15 14:56:54 -0800263 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
264 sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700265
Tim Murray358747a2012-11-26 13:52:04 -0800266 void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
267 const void *data, size_t stride);
268 void copy2DStridedFrom(const void *data, size_t stride);
269
270 void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
271 void *data, size_t stride);
272 void copy2DStridedTo(void *data, size_t stride);
273
Tim Murray84bf2b82012-10-31 16:03:16 -0700274 void resize(int dimX);
275 void resize(int dimX, int dimY);
276
277 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
278 RsAllocationMipmapControl mips, uint32_t usage);
279 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
280 RsAllocationMipmapControl mips, uint32_t usage, void * pointer);
281
282 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
283 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
284 static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count,
285 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
Tim Murray684726c2012-11-14 11:57:42 -0800286 static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e,
287 size_t x, size_t y,
288 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
289
Tim Murray84bf2b82012-10-31 16:03:16 -0700290
291};
292
293class Element : public BaseObj {
294public:
295 bool isComplex();
296 size_t getSubElementCount() {
297 return mVisibleElementMap.size();
298 }
299
300 sp<const Element> getSubElement(uint32_t index);
301 const char * getSubElementName(uint32_t index);
302 size_t getSubElementArraySize(uint32_t index);
303 uint32_t getSubElementOffsetBytes(uint32_t index);
304 RsDataType getDataType() const {
305 return mType;
306 }
307
308 RsDataKind getDataKind() const {
309 return mKind;
310 }
311
312 size_t getSizeBytes() const {
313 return mSizeBytes;
314 }
315
316 static sp<const Element> BOOLEAN(sp<RS> rs);
317 static sp<const Element> U8(sp<RS> rs);
318 static sp<const Element> I8(sp<RS> rs);
319 static sp<const Element> U16(sp<RS> rs);
320 static sp<const Element> I16(sp<RS> rs);
321 static sp<const Element> U32(sp<RS> rs);
322 static sp<const Element> I32(sp<RS> rs);
323 static sp<const Element> U64(sp<RS> rs);
324 static sp<const Element> I64(sp<RS> rs);
325 static sp<const Element> F32(sp<RS> rs);
326 static sp<const Element> F64(sp<RS> rs);
327 static sp<const Element> ELEMENT(sp<RS> rs);
328 static sp<const Element> TYPE(sp<RS> rs);
329 static sp<const Element> ALLOCATION(sp<RS> rs);
330 static sp<const Element> SAMPLER(sp<RS> rs);
331 static sp<const Element> SCRIPT(sp<RS> rs);
332 static sp<const Element> MESH(sp<RS> rs);
333 static sp<const Element> PROGRAM_FRAGMENT(sp<RS> rs);
334 static sp<const Element> PROGRAM_VERTEX(sp<RS> rs);
335 static sp<const Element> PROGRAM_RASTER(sp<RS> rs);
336 static sp<const Element> PROGRAM_STORE(sp<RS> rs);
337
338 static sp<const Element> A_8(sp<RS> rs);
339 static sp<const Element> RGB_565(sp<RS> rs);
340 static sp<const Element> RGB_888(sp<RS> rs);
341 static sp<const Element> RGBA_5551(sp<RS> rs);
342 static sp<const Element> RGBA_4444(sp<RS> rs);
343 static sp<const Element> RGBA_8888(sp<RS> rs);
344
345 static sp<const Element> F32_2(sp<RS> rs);
346 static sp<const Element> F32_3(sp<RS> rs);
347 static sp<const Element> F32_4(sp<RS> rs);
348 static sp<const Element> F64_2(sp<RS> rs);
349 static sp<const Element> F64_3(sp<RS> rs);
350 static sp<const Element> F64_4(sp<RS> rs);
351 static sp<const Element> U8_2(sp<RS> rs);
352 static sp<const Element> U8_3(sp<RS> rs);
353 static sp<const Element> U8_4(sp<RS> rs);
354 static sp<const Element> I8_2(sp<RS> rs);
355 static sp<const Element> I8_3(sp<RS> rs);
356 static sp<const Element> I8_4(sp<RS> rs);
357 static sp<const Element> U16_2(sp<RS> rs);
358 static sp<const Element> U16_3(sp<RS> rs);
359 static sp<const Element> U16_4(sp<RS> rs);
360 static sp<const Element> I16_2(sp<RS> rs);
361 static sp<const Element> I16_3(sp<RS> rs);
362 static sp<const Element> I16_4(sp<RS> rs);
363 static sp<const Element> U32_2(sp<RS> rs);
364 static sp<const Element> U32_3(sp<RS> rs);
365 static sp<const Element> U32_4(sp<RS> rs);
366 static sp<const Element> I32_2(sp<RS> rs);
367 static sp<const Element> I32_3(sp<RS> rs);
368 static sp<const Element> I32_4(sp<RS> rs);
369 static sp<const Element> U64_2(sp<RS> rs);
370 static sp<const Element> U64_3(sp<RS> rs);
371 static sp<const Element> U64_4(sp<RS> rs);
372 static sp<const Element> I64_2(sp<RS> rs);
373 static sp<const Element> I64_3(sp<RS> rs);
374 static sp<const Element> I64_4(sp<RS> rs);
375 static sp<const Element> MATRIX_4X4(sp<RS> rs);
376 static sp<const Element> MATRIX_3X3(sp<RS> rs);
377 static sp<const Element> MATRIX_2X2(sp<RS> rs);
378
Tim Murray84bf2b82012-10-31 16:03:16 -0700379 void updateFromNative();
380 static sp<const Element> createUser(sp<RS> rs, RsDataType dt);
381 static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size);
382 static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk);
383 bool isCompatible(sp<const Element>e);
384
Tim Murray89daad62013-07-29 14:30:02 -0700385 Element(void *id, sp<RS> rs,
386 std::vector<sp<Element> > &elements,
Tim Murrayab716362013-08-12 12:37:18 -0700387 std::vector<std::string> &elementNames,
Tim Murray89daad62013-07-29 14:30:02 -0700388 std::vector<uint32_t> &arraySizes);
389 Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size);
390 Element(sp<RS> rs);
391 virtual ~Element();
392
393 protected:
Tim Murray84bf2b82012-10-31 16:03:16 -0700394 class Builder {
395 private:
396 sp<RS> mRS;
Tim Murray89daad62013-07-29 14:30:02 -0700397 std::vector<sp<Element> > mElements;
Tim Murrayab716362013-08-12 12:37:18 -0700398 std::vector<std::string> mElementNames;
Tim Murray89daad62013-07-29 14:30:02 -0700399 std::vector<uint32_t> mArraySizes;
Tim Murray84bf2b82012-10-31 16:03:16 -0700400 bool mSkipPadding;
401
402 public:
403 Builder(sp<RS> rs);
404 ~Builder();
Tim Murrayab716362013-08-12 12:37:18 -0700405 void add(sp<Element> e, std::string &name, uint32_t arraySize = 1);
Tim Murray84bf2b82012-10-31 16:03:16 -0700406 sp<const Element> create();
407 };
408
409private:
410 void updateVisibleSubElements();
411
Tim Murray89daad62013-07-29 14:30:02 -0700412 std::vector<sp<Element> > mElements;
Tim Murrayab716362013-08-12 12:37:18 -0700413 std::vector<std::string> mElementNames;
Tim Murray89daad62013-07-29 14:30:02 -0700414 std::vector<uint32_t> mArraySizes;
415 std::vector<uint32_t> mVisibleElementMap;
416 std::vector<uint32_t> mOffsetInBytes;
Tim Murray84bf2b82012-10-31 16:03:16 -0700417
418 RsDataType mType;
419 RsDataKind mKind;
420 bool mNormalized;
421 size_t mSizeBytes;
422 size_t mVectorSize;
423};
424
Stephen Hines2c7206e2012-11-14 19:47:01 -0800425class FieldPacker {
426protected:
427 unsigned char* mData;
428 size_t mPos;
429 size_t mLen;
430
431public:
432 FieldPacker(size_t len)
Tim Murray89daad62013-07-29 14:30:02 -0700433 : mPos(0), mLen(len) {
434 mData = new unsigned char[len];
435 }
Stephen Hines2c7206e2012-11-14 19:47:01 -0800436
437 virtual ~FieldPacker() {
438 delete [] mData;
439 }
440
441 void align(size_t v) {
442 if ((v & (v - 1)) != 0) {
Tim Murrayab716362013-08-12 12:37:18 -0700443 // ALOGE("Non-power-of-two alignment: %zu", v);
Stephen Hines2c7206e2012-11-14 19:47:01 -0800444 return;
445 }
446
447 while ((mPos & (v - 1)) != 0) {
448 mData[mPos++] = 0;
449 }
450 }
451
452 void reset() {
453 mPos = 0;
454 }
455
456 void reset(size_t i) {
457 if (i >= mLen) {
Tim Murrayab716362013-08-12 12:37:18 -0700458 // ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen);
Stephen Hines2c7206e2012-11-14 19:47:01 -0800459 return;
460 }
461 mPos = i;
462 }
463
464 void skip(size_t i) {
465 size_t res = mPos + i;
466 if (res > mLen) {
Tim Murrayab716362013-08-12 12:37:18 -0700467 // ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen);
Stephen Hines2c7206e2012-11-14 19:47:01 -0800468 return;
469 }
470 mPos = res;
471 }
472
473 void* getData() const {
474 return mData;
475 }
476
477 size_t getLength() const {
478 return mLen;
479 }
480
481 template <typename T>
Tim Murray89daad62013-07-29 14:30:02 -0700482 void add(T t) {
Stephen Hines2c7206e2012-11-14 19:47:01 -0800483 align(sizeof(t));
484 if (mPos + sizeof(t) <= mLen) {
485 memcpy(&mData[mPos], &t, sizeof(t));
486 mPos += sizeof(t);
487 }
488 }
Stephen Hines43514cd2012-11-16 14:33:47 -0800489
490 /*
Tim Murray89daad62013-07-29 14:30:02 -0700491 void add(rs_matrix4x4 m) {
492 for (size_t i = 0; i < 16; i++) {
493 add(m.m[i]);
494 }
495 }
Stephen Hines43514cd2012-11-16 14:33:47 -0800496
Tim Murray89daad62013-07-29 14:30:02 -0700497 void add(rs_matrix3x3 m) {
498 for (size_t i = 0; i < 9; i++) {
499 add(m.m[i]);
500 }
501 }
Stephen Hines43514cd2012-11-16 14:33:47 -0800502
Tim Murray89daad62013-07-29 14:30:02 -0700503 void add(rs_matrix2x2 m) {
504 for (size_t i = 0; i < 4; i++) {
505 add(m.m[i]);
506 }
507 }
Stephen Hines43514cd2012-11-16 14:33:47 -0800508 */
509
Tim Murray89daad62013-07-29 14:30:02 -0700510 void add(sp<BaseObj> obj) {
Stephen Hines43514cd2012-11-16 14:33:47 -0800511 if (obj != NULL) {
512 add((uint32_t) (uintptr_t) obj->getID());
513 } else {
514 add((uint32_t) 0);
515 }
516 }
Stephen Hines2c7206e2012-11-14 19:47:01 -0800517};
518
Tim Murray89daad62013-07-29 14:30:02 -0700519
Tim Murray84bf2b82012-10-31 16:03:16 -0700520class Type : public BaseObj {
521protected:
522 friend class Allocation;
523
524 uint32_t mDimX;
525 uint32_t mDimY;
526 uint32_t mDimZ;
527 bool mDimMipmaps;
528 bool mDimFaces;
529 size_t mElementCount;
530 sp<const Element> mElement;
531
532 void calcElementCount();
533 virtual void updateFromNative();
534
535public:
536
537 sp<const Element> getElement() const {
538 return mElement;
539 }
540
541 uint32_t getX() const {
542 return mDimX;
543 }
544
545 uint32_t getY() const {
546 return mDimY;
547 }
548
549 uint32_t getZ() const {
550 return mDimZ;
551 }
552
553 bool hasMipmaps() const {
554 return mDimMipmaps;
555 }
556
557 bool hasFaces() const {
558 return mDimFaces;
559 }
560
561 size_t getCount() const {
562 return mElementCount;
563 }
564
565 size_t getSizeBytes() const {
566 return mElementCount * mElement->getSizeBytes();
567 }
568
569 Type(void *id, sp<RS> rs);
570
Tim Murray96267c22013-02-12 11:25:12 -0800571 static sp<const Type> create(sp<RS> rs, sp<const Element> e, uint32_t dimX, uint32_t dimY, uint32_t dimZ);
Tim Murray84bf2b82012-10-31 16:03:16 -0700572
573 class Builder {
574 protected:
575 sp<RS> mRS;
576 uint32_t mDimX;
577 uint32_t mDimY;
578 uint32_t mDimZ;
579 bool mDimMipmaps;
580 bool mDimFaces;
581 sp<const Element> mElement;
582
583 public:
584 Builder(sp<RS> rs, sp<const Element> e);
585
586 void setX(uint32_t value);
587 void setY(int value);
588 void setMipmaps(bool value);
589 void setFaces(bool value);
590 sp<const Type> create();
591 };
592
593};
594
595class Script : public BaseObj {
596private:
597
598protected:
599 Script(void *id, sp<RS> rs);
600 void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out,
601 const void *v, size_t) const;
602 void bindAllocation(sp<Allocation> va, uint32_t slot) const;
603 void setVar(uint32_t index, const void *, size_t len) const;
604 void setVar(uint32_t index, sp<const BaseObj> o) const;
605 void invoke(uint32_t slot, const void *v, size_t len) const;
606
607
608 void invoke(uint32_t slot) const {
609 invoke(slot, NULL, 0);
610 }
611 void setVar(uint32_t index, float v) const {
612 setVar(index, &v, sizeof(v));
613 }
614 void setVar(uint32_t index, double v) const {
615 setVar(index, &v, sizeof(v));
616 }
617 void setVar(uint32_t index, int32_t v) const {
618 setVar(index, &v, sizeof(v));
619 }
620 void setVar(uint32_t index, int64_t v) const {
621 setVar(index, &v, sizeof(v));
622 }
623 void setVar(uint32_t index, bool v) const {
624 setVar(index, &v, sizeof(v));
625 }
626
627public:
628 class FieldBase {
629 protected:
630 sp<const Element> mElement;
631 sp<Allocation> mAllocation;
632
633 void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0);
634
635 public:
636 sp<const Element> getElement() {
637 return mElement;
638 }
639
640 sp<const Type> getType() {
641 return mAllocation->getType();
642 }
643
644 sp<const Allocation> getAllocation() {
645 return mAllocation;
646 }
647
648 //void updateAllocation();
649 };
650};
651
652class ScriptC : public Script {
653protected:
654 ScriptC(sp<RS> rs,
655 const void *codeTxt, size_t codeLength,
656 const char *cachedName, size_t cachedNameLength,
657 const char *cacheDir, size_t cacheDirLength);
658
659};
660
Tim Murray7f0d5682012-11-08 16:35:24 -0800661class ScriptIntrinsic : public Script {
662 protected:
Tim Murray3cd44af2012-11-14 11:25:27 -0800663 ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -0700664 virtual ~ScriptIntrinsic();
Tim Murray7f0d5682012-11-08 16:35:24 -0800665};
666
Tim Murray89daad62013-07-29 14:30:02 -0700667class ScriptIntrinsic3DLUT : public ScriptIntrinsic {
668 public:
669 ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e);
670 void forEach(sp<Allocation> ain, sp<Allocation> aout);
671 void setLUT(sp<Allocation> lut);
672};
673
Tim Murray7f0d5682012-11-08 16:35:24 -0800674class ScriptIntrinsicBlend : public ScriptIntrinsic {
675 public:
Tim Murray89daad62013-07-29 14:30:02 -0700676 ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e);
Tim Murray7f0d5682012-11-08 16:35:24 -0800677 void blendClear(sp<Allocation> in, sp<Allocation> out);
678 void blendSrc(sp<Allocation> in, sp<Allocation> out);
679 void blendDst(sp<Allocation> in, sp<Allocation> out);
680 void blendSrcOver(sp<Allocation> in, sp<Allocation> out);
681 void blendDstOver(sp<Allocation> in, sp<Allocation> out);
682 void blendSrcIn(sp<Allocation> in, sp<Allocation> out);
683 void blendDstIn(sp<Allocation> in, sp<Allocation> out);
684 void blendSrcOut(sp<Allocation> in, sp<Allocation> out);
685 void blendDstOut(sp<Allocation> in, sp<Allocation> out);
686 void blendSrcAtop(sp<Allocation> in, sp<Allocation> out);
687 void blendDstAtop(sp<Allocation> in, sp<Allocation> out);
688 void blendXor(sp<Allocation> in, sp<Allocation> out);
689 void blendMultiply(sp<Allocation> in, sp<Allocation> out);
690 void blendAdd(sp<Allocation> in, sp<Allocation> out);
691 void blendSubtract(sp<Allocation> in, sp<Allocation> out);
692};
Tim Murray84bf2b82012-10-31 16:03:16 -0700693
Tim Murray8f1e60c2012-11-13 12:25:11 -0800694class ScriptIntrinsicBlur : public ScriptIntrinsic {
695 public:
Tim Murray89daad62013-07-29 14:30:02 -0700696 ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e);
Tim Murray8f1e60c2012-11-13 12:25:11 -0800697 void blur(sp<Allocation> in, sp<Allocation> out);
698 void setRadius(float radius);
699};
700
Tim Murray89daad62013-07-29 14:30:02 -0700701class ScriptIntrinsicColorMatrix : public ScriptIntrinsic {
702 public:
703 ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e);
704 void forEach(sp<Allocation> in, sp<Allocation> out);
705 void setColorMatrix3(float* m);
706 void setColorMatrix4(float* m);
707 void setGreyscale();
708 void setRGBtoYUV();
709 void setYUVtoRGB();
710};
711
712class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic {
713 public:
714 ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e);
715 void setInput(sp<Allocation> in);
716 void forEach(sp<Allocation> out);
717 void setCoefficients(float* v);
718};
719
720class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic {
721 public:
722 ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e);
723 void setInput(sp<Allocation> in);
724 void forEach(sp<Allocation> out);
725 void setCoefficients(float* v);
726};
727
Tim Murrayb27b1812013-08-05 14:00:40 -0700728class ScriptIntrinsicHistogram : public ScriptIntrinsic {
729 public:
730 ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e);
731 void setOutput(sp<Allocation> aout);
732 void setDotCoefficients(float r, float g, float b, float a);
733 void forEach(sp<Allocation> ain);
734 void forEach_dot(sp<Allocation> ain);
735};
736
737class ScriptIntrinsicLUT : public ScriptIntrinsic {
738 private:
739 sp<Allocation> LUT;
740 bool mDirty;
741 unsigned char mCache[1024];
742 void setTable(unsigned int offset, unsigned char base, unsigned char length, unsigned char* lutValues);
743
Tim Murray89daad62013-07-29 14:30:02 -0700744 public:
745 ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e);
746 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murrayb27b1812013-08-05 14:00:40 -0700747 void setRed(unsigned char base, unsigned char length, unsigned char* lutValues);
748 void setGreen(unsigned char base, unsigned char length, unsigned char* lutValues);
749 void setBlue(unsigned char base, unsigned char length, unsigned char* lutValues);
750 void setAlpha(unsigned char base, unsigned char length, unsigned char* lutValues);
751 virtual ~ScriptIntrinsicLUT();
752};
753
Tim Murray89daad62013-07-29 14:30:02 -0700754class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic {
Tim Murrayb27b1812013-08-05 14:00:40 -0700755 public:
756 ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e);
757 void setInput(sp<Allocation> in);
758 void forEach(sp<Allocation> out);
Tim Murray89daad62013-07-29 14:30:02 -0700759
760};
Tim Murrayb27b1812013-08-05 14:00:40 -0700761
Tim Murray89daad62013-07-29 14:30:02 -0700762
Tim Murray729b6fe2013-07-23 16:20:42 -0700763 class Sampler : public BaseObj {
764 private:
765 Sampler(sp<RS> rs, void* id);
766 RsSamplerValue mMin;
767 RsSamplerValue mMag;
768 RsSamplerValue mWrapS;
769 RsSamplerValue mWrapT;
770 RsSamplerValue mWrapR;
771 float mAniso;
772
773 public:
774 static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
775
776 RsSamplerValue getMinification();
777 RsSamplerValue getMagnification();
778 RsSamplerValue getWrapS();
779 RsSamplerValue getWrapT();
780 float getAnisotropy();
781
782 sp<const Sampler> CLAMP_NEAREST(sp<RS> rs);
783 sp<const Sampler> CLAMP_LINEAR(sp<RS> rs);
784 sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs);
785 sp<const Sampler> WRAP_NEAREST(sp<RS> rs);
786 sp<const Sampler> WRAP_LINEAR(sp<RS> rs);
787 sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs);
788 sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs);
789 sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs);
790 sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs);
791
792};
793
Tim Murray84bf2b82012-10-31 16:03:16 -0700794}
Tim Murray7f0d5682012-11-08 16:35:24 -0800795
Tim Murray84bf2b82012-10-31 16:03:16 -0700796}
797
798#endif