blob: dae84cec72cbe3712c0e6a9ff06052477ba3b640 [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>
26
Tim Murray96267c22013-02-12 11:25:12 -080027// Every row in an RS allocation is guaranteed to be aligned by this amount
28// Every row in a user-backed allocation must be aligned by this amount
29#define RS_CPU_ALLOCATION_ALIGNMENT 16
30
Tim Murray84bf2b82012-10-31 16:03:16 -070031namespace android {
Tim Murray9eb7f4b2012-11-16 14:02:18 -080032namespace RSC {
Tim Murray84bf2b82012-10-31 16:03:16 -070033
34typedef void (*ErrorHandlerFunc_t)(uint32_t errorNum, const char *errorText);
35typedef void (*MessageHandlerFunc_t)(uint32_t msgNum, const void *msgData, size_t msgLen);
36
37class RS;
38class BaseObj;
39class Element;
40class Type;
41class Allocation;
42class Script;
43class ScriptC;
Tim Murray729b6fe2013-07-23 16:20:42 -070044class Sampler;
Tim Murray84bf2b82012-10-31 16:03:16 -070045
Tim Murray89daad62013-07-29 14:30:02 -070046 class RS : public android::RSC::LightRefBase<RS> {
Tim Murray84bf2b82012-10-31 16:03:16 -070047
48 public:
49 RS();
50 virtual ~RS();
51
Tim Murray4d252d62012-11-29 14:37:59 -080052 bool init(bool forceCpu = false, bool synchronous = false);
Tim Murray84bf2b82012-10-31 16:03:16 -070053
54 void setErrorHandler(ErrorHandlerFunc_t func);
55 ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; }
56
57 void setMessageHandler(MessageHandlerFunc_t func);
58 MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; }
59
60 void throwError(const char *err) const;
61
62 RsContext getContext() { return mContext; }
63
Tim Murraybaca6c32012-11-14 16:51:46 -080064 void finish();
65
Tim Murraya4230962013-07-17 16:50:10 -070066 static dispatchTable* dispatch;
67
Tim Murray84bf2b82012-10-31 16:03:16 -070068 private:
Tim Murray4a92d122013-07-22 10:56:18 -070069 static bool usingNative;
Tim Murraya4230962013-07-17 16:50:10 -070070 static bool initDispatch(int targetApi);
71
Tim Murray4d252d62012-11-29 14:37:59 -080072 bool init(int targetApi, bool forceCpu, bool synchronous);
Tim Murray84bf2b82012-10-31 16:03:16 -070073 static void * threadProc(void *);
74
75 static bool gInitialized;
76 static pthread_mutex_t gInitMutex;
77
78 pthread_t mMessageThreadId;
79 pid_t mNativeMessageThreadId;
80 bool mMessageRun;
81
82 RsDevice mDev;
83 RsContext mContext;
84
85 ErrorHandlerFunc_t mErrorFunc;
86 MessageHandlerFunc_t mMessageFunc;
Tim Murraya4230962013-07-17 16:50:10 -070087 bool mInit;
Tim Murray84bf2b82012-10-31 16:03:16 -070088
89 struct {
Tim Murray89daad62013-07-29 14:30:02 -070090 sp<const Element> U8;
91 sp<const Element> I8;
92 sp<const Element> U16;
93 sp<const Element> I16;
94 sp<const Element> U32;
95 sp<const Element> I32;
96 sp<const Element> U64;
97 sp<const Element> I64;
98 sp<const Element> F32;
99 sp<const Element> F64;
100 sp<const Element> BOOLEAN;
Tim Murray84bf2b82012-10-31 16:03:16 -0700101
Tim Murray89daad62013-07-29 14:30:02 -0700102 sp<const Element> ELEMENT;
103 sp<const Element> TYPE;
104 sp<const Element> ALLOCATION;
105 sp<const Element> SAMPLER;
106 sp<const Element> SCRIPT;
107 sp<const Element> MESH;
108 sp<const Element> PROGRAM_FRAGMENT;
109 sp<const Element> PROGRAM_VERTEX;
110 sp<const Element> PROGRAM_RASTER;
111 sp<const Element> PROGRAM_STORE;
Tim Murray84bf2b82012-10-31 16:03:16 -0700112
Tim Murray89daad62013-07-29 14:30:02 -0700113 sp<const Element> A_8;
114 sp<const Element> RGB_565;
115 sp<const Element> RGB_888;
116 sp<const Element> RGBA_5551;
117 sp<const Element> RGBA_4444;
118 sp<const Element> RGBA_8888;
Tim Murray84bf2b82012-10-31 16:03:16 -0700119
Tim Murray89daad62013-07-29 14:30:02 -0700120 sp<const Element> FLOAT_2;
121 sp<const Element> FLOAT_3;
122 sp<const Element> FLOAT_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700123
Tim Murray89daad62013-07-29 14:30:02 -0700124 sp<const Element> DOUBLE_2;
125 sp<const Element> DOUBLE_3;
126 sp<const Element> DOUBLE_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700127
Tim Murray89daad62013-07-29 14:30:02 -0700128 sp<const Element> UCHAR_2;
129 sp<const Element> UCHAR_3;
130 sp<const Element> UCHAR_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700131
Tim Murray89daad62013-07-29 14:30:02 -0700132 sp<const Element> CHAR_2;
133 sp<const Element> CHAR_3;
134 sp<const Element> CHAR_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700135
Tim Murray89daad62013-07-29 14:30:02 -0700136 sp<const Element> USHORT_2;
137 sp<const Element> USHORT_3;
138 sp<const Element> USHORT_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700139
Tim Murray89daad62013-07-29 14:30:02 -0700140 sp<const Element> SHORT_2;
141 sp<const Element> SHORT_3;
142 sp<const Element> SHORT_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700143
Tim Murray89daad62013-07-29 14:30:02 -0700144 sp<const Element> UINT_2;
145 sp<const Element> UINT_3;
146 sp<const Element> UINT_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700147
Tim Murray89daad62013-07-29 14:30:02 -0700148 sp<const Element> INT_2;
149 sp<const Element> INT_3;
150 sp<const Element> INT_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700151
Tim Murray89daad62013-07-29 14:30:02 -0700152 sp<const Element> ULONG_2;
153 sp<const Element> ULONG_3;
154 sp<const Element> ULONG_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700155
Tim Murray89daad62013-07-29 14:30:02 -0700156 sp<const Element> LONG_2;
157 sp<const Element> LONG_3;
158 sp<const Element> LONG_4;
Tim Murray84bf2b82012-10-31 16:03:16 -0700159
Tim Murray89daad62013-07-29 14:30:02 -0700160 sp<const Element> MATRIX_4X4;
161 sp<const Element> MATRIX_3X3;
162 sp<const Element> MATRIX_2X2;
Tim Murray84bf2b82012-10-31 16:03:16 -0700163 } mElements;
164
Tim Murray729b6fe2013-07-23 16:20:42 -0700165 struct {
Tim Murray89daad62013-07-29 14:30:02 -0700166 sp<const Sampler> CLAMP_NEAREST;
167 sp<const Sampler> CLAMP_LINEAR;
168 sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR;
169 sp<const Sampler> WRAP_NEAREST;
170 sp<const Sampler> WRAP_LINEAR;
171 sp<const Sampler> WRAP_LINEAR_MIP_LINEAR;
172 sp<const Sampler> MIRRORED_REPEAT_NEAREST;
173 sp<const Sampler> MIRRORED_REPEAT_LINEAR;
174 sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
Tim Murray729b6fe2013-07-23 16:20:42 -0700175 } mSamplers;
176 friend class Sampler;
177 friend class Element;
Tim Murray84bf2b82012-10-31 16:03:16 -0700178};
179
Tim Murray89daad62013-07-29 14:30:02 -0700180class BaseObj : public android::RSC::LightRefBase<BaseObj> {
181public:
182 void * getID() const;
183 virtual ~BaseObj();
184 virtual void updateFromNative();
185 virtual bool equals(sp<const BaseObj> obj);
186
Tim Murray84bf2b82012-10-31 16:03:16 -0700187protected:
188 void *mID;
189 sp<RS> mRS;
190 String8 mName;
191
192 BaseObj(void *id, sp<RS> rs);
193 void checkValid();
194
195 static void * getObjID(sp<const BaseObj> o);
196
Tim Murray84bf2b82012-10-31 16:03:16 -0700197};
198
199
200class Allocation : public BaseObj {
201protected:
Tim Murray89daad62013-07-29 14:30:02 -0700202 sp<const Type> mType;
Tim Murray84bf2b82012-10-31 16:03:16 -0700203 uint32_t mUsage;
Tim Murray89daad62013-07-29 14:30:02 -0700204 sp<Allocation> mAdaptedAllocation;
Tim Murray84bf2b82012-10-31 16:03:16 -0700205
206 bool mConstrainedLOD;
207 bool mConstrainedFace;
208 bool mConstrainedY;
209 bool mConstrainedZ;
210 bool mReadAllowed;
211 bool mWriteAllowed;
212 uint32_t mSelectedY;
213 uint32_t mSelectedZ;
214 uint32_t mSelectedLOD;
215 RsAllocationCubemapFace mSelectedFace;
216
217 uint32_t mCurrentDimX;
218 uint32_t mCurrentDimY;
219 uint32_t mCurrentDimZ;
220 uint32_t mCurrentCount;
221
222 void * getIDSafe() const;
223 void updateCacheInfo(sp<const Type> t);
224
225 Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage);
226
227 void validateIsInt32();
228 void validateIsInt16();
229 void validateIsInt8();
230 void validateIsFloat32();
231 void validateIsObject();
232
233 virtual void updateFromNative();
234
235 void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h);
236
237public:
Tim Murray89daad62013-07-29 14:30:02 -0700238 sp<const Type> getType() {
Tim Murray84bf2b82012-10-31 16:03:16 -0700239 return mType;
240 }
241
242 void syncAll(RsAllocationUsageType srcLocation);
243 void ioSendOutput();
244 void ioGetInput();
245
246 void generateMipmaps();
Tim Murray509ea5c2012-11-13 11:56:40 -0800247
Tim Murray0b93e302012-11-15 14:56:54 -0800248 void copy1DRangeFrom(uint32_t off, size_t count, const void *data);
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800249 void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700250
Tim Murray0b93e302012-11-15 14:56:54 -0800251 void copy1DRangeTo(uint32_t off, size_t count, void *data);
252
253 void copy1DFrom(const void* data);
254 void copy1DTo(void* data);
Tim Murraya4cbc2b2012-11-14 17:18:08 -0800255
Tim Murray84bf2b82012-10-31 16:03:16 -0700256 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
Tim Murray0b93e302012-11-15 14:56:54 -0800257 const void *data);
Tim Murray7b3e3092012-11-16 13:32:24 -0800258
259 void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
260 void *data);
261
Tim Murray0b93e302012-11-15 14:56:54 -0800262 void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
263 sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff);
Tim Murray84bf2b82012-10-31 16:03:16 -0700264
Tim Murray358747a2012-11-26 13:52:04 -0800265 void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
266 const void *data, size_t stride);
267 void copy2DStridedFrom(const void *data, size_t stride);
268
269 void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
270 void *data, size_t stride);
271 void copy2DStridedTo(void *data, size_t stride);
272
Tim Murray84bf2b82012-10-31 16:03:16 -0700273 void resize(int dimX);
274 void resize(int dimX, int dimY);
275
276 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
277 RsAllocationMipmapControl mips, uint32_t usage);
278 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
279 RsAllocationMipmapControl mips, uint32_t usage, void * pointer);
280
281 static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
282 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
283 static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count,
284 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
Tim Murray684726c2012-11-14 11:57:42 -0800285 static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e,
286 size_t x, size_t y,
287 uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
288
Tim Murray84bf2b82012-10-31 16:03:16 -0700289
290};
291
292class Element : public BaseObj {
293public:
294 bool isComplex();
295 size_t getSubElementCount() {
296 return mVisibleElementMap.size();
297 }
298
299 sp<const Element> getSubElement(uint32_t index);
300 const char * getSubElementName(uint32_t index);
301 size_t getSubElementArraySize(uint32_t index);
302 uint32_t getSubElementOffsetBytes(uint32_t index);
303 RsDataType getDataType() const {
304 return mType;
305 }
306
307 RsDataKind getDataKind() const {
308 return mKind;
309 }
310
311 size_t getSizeBytes() const {
312 return mSizeBytes;
313 }
314
315 static sp<const Element> BOOLEAN(sp<RS> rs);
316 static sp<const Element> U8(sp<RS> rs);
317 static sp<const Element> I8(sp<RS> rs);
318 static sp<const Element> U16(sp<RS> rs);
319 static sp<const Element> I16(sp<RS> rs);
320 static sp<const Element> U32(sp<RS> rs);
321 static sp<const Element> I32(sp<RS> rs);
322 static sp<const Element> U64(sp<RS> rs);
323 static sp<const Element> I64(sp<RS> rs);
324 static sp<const Element> F32(sp<RS> rs);
325 static sp<const Element> F64(sp<RS> rs);
326 static sp<const Element> ELEMENT(sp<RS> rs);
327 static sp<const Element> TYPE(sp<RS> rs);
328 static sp<const Element> ALLOCATION(sp<RS> rs);
329 static sp<const Element> SAMPLER(sp<RS> rs);
330 static sp<const Element> SCRIPT(sp<RS> rs);
331 static sp<const Element> MESH(sp<RS> rs);
332 static sp<const Element> PROGRAM_FRAGMENT(sp<RS> rs);
333 static sp<const Element> PROGRAM_VERTEX(sp<RS> rs);
334 static sp<const Element> PROGRAM_RASTER(sp<RS> rs);
335 static sp<const Element> PROGRAM_STORE(sp<RS> rs);
336
337 static sp<const Element> A_8(sp<RS> rs);
338 static sp<const Element> RGB_565(sp<RS> rs);
339 static sp<const Element> RGB_888(sp<RS> rs);
340 static sp<const Element> RGBA_5551(sp<RS> rs);
341 static sp<const Element> RGBA_4444(sp<RS> rs);
342 static sp<const Element> RGBA_8888(sp<RS> rs);
343
344 static sp<const Element> F32_2(sp<RS> rs);
345 static sp<const Element> F32_3(sp<RS> rs);
346 static sp<const Element> F32_4(sp<RS> rs);
347 static sp<const Element> F64_2(sp<RS> rs);
348 static sp<const Element> F64_3(sp<RS> rs);
349 static sp<const Element> F64_4(sp<RS> rs);
350 static sp<const Element> U8_2(sp<RS> rs);
351 static sp<const Element> U8_3(sp<RS> rs);
352 static sp<const Element> U8_4(sp<RS> rs);
353 static sp<const Element> I8_2(sp<RS> rs);
354 static sp<const Element> I8_3(sp<RS> rs);
355 static sp<const Element> I8_4(sp<RS> rs);
356 static sp<const Element> U16_2(sp<RS> rs);
357 static sp<const Element> U16_3(sp<RS> rs);
358 static sp<const Element> U16_4(sp<RS> rs);
359 static sp<const Element> I16_2(sp<RS> rs);
360 static sp<const Element> I16_3(sp<RS> rs);
361 static sp<const Element> I16_4(sp<RS> rs);
362 static sp<const Element> U32_2(sp<RS> rs);
363 static sp<const Element> U32_3(sp<RS> rs);
364 static sp<const Element> U32_4(sp<RS> rs);
365 static sp<const Element> I32_2(sp<RS> rs);
366 static sp<const Element> I32_3(sp<RS> rs);
367 static sp<const Element> I32_4(sp<RS> rs);
368 static sp<const Element> U64_2(sp<RS> rs);
369 static sp<const Element> U64_3(sp<RS> rs);
370 static sp<const Element> U64_4(sp<RS> rs);
371 static sp<const Element> I64_2(sp<RS> rs);
372 static sp<const Element> I64_3(sp<RS> rs);
373 static sp<const Element> I64_4(sp<RS> rs);
374 static sp<const Element> MATRIX_4X4(sp<RS> rs);
375 static sp<const Element> MATRIX_3X3(sp<RS> rs);
376 static sp<const Element> MATRIX_2X2(sp<RS> rs);
377
Tim Murray84bf2b82012-10-31 16:03:16 -0700378 void updateFromNative();
379 static sp<const Element> createUser(sp<RS> rs, RsDataType dt);
380 static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size);
381 static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk);
382 bool isCompatible(sp<const Element>e);
383
Tim Murray89daad62013-07-29 14:30:02 -0700384 Element(void *id, sp<RS> rs,
385 std::vector<sp<Element> > &elements,
386 std::vector<android::String8> &elementNames,
387 std::vector<uint32_t> &arraySizes);
388 Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size);
389 Element(sp<RS> rs);
390 virtual ~Element();
391
392 protected:
Tim Murray84bf2b82012-10-31 16:03:16 -0700393 class Builder {
394 private:
395 sp<RS> mRS;
Tim Murray89daad62013-07-29 14:30:02 -0700396 std::vector<sp<Element> > mElements;
397 std::vector<android::String8> mElementNames;
398 std::vector<uint32_t> mArraySizes;
Tim Murray84bf2b82012-10-31 16:03:16 -0700399 bool mSkipPadding;
400
401 public:
402 Builder(sp<RS> rs);
403 ~Builder();
Tim Murray89daad62013-07-29 14:30:02 -0700404 void add(sp<Element> e, android::String8 &name, uint32_t arraySize = 1);
Tim Murray84bf2b82012-10-31 16:03:16 -0700405 sp<const Element> create();
406 };
407
408private:
409 void updateVisibleSubElements();
410
Tim Murray89daad62013-07-29 14:30:02 -0700411 std::vector<sp<Element> > mElements;
412 std::vector<android::String8> mElementNames;
413 std::vector<uint32_t> mArraySizes;
414 std::vector<uint32_t> mVisibleElementMap;
415 std::vector<uint32_t> mOffsetInBytes;
Tim Murray84bf2b82012-10-31 16:03:16 -0700416
417 RsDataType mType;
418 RsDataKind mKind;
419 bool mNormalized;
420 size_t mSizeBytes;
421 size_t mVectorSize;
422};
423
Stephen Hines2c7206e2012-11-14 19:47:01 -0800424class FieldPacker {
425protected:
426 unsigned char* mData;
427 size_t mPos;
428 size_t mLen;
429
430public:
431 FieldPacker(size_t len)
Tim Murray89daad62013-07-29 14:30:02 -0700432 : mPos(0), mLen(len) {
433 mData = new unsigned char[len];
434 }
Stephen Hines2c7206e2012-11-14 19:47:01 -0800435
436 virtual ~FieldPacker() {
437 delete [] mData;
438 }
439
440 void align(size_t v) {
441 if ((v & (v - 1)) != 0) {
442 ALOGE("Non-power-of-two alignment: %zu", v);
443 return;
444 }
445
446 while ((mPos & (v - 1)) != 0) {
447 mData[mPos++] = 0;
448 }
449 }
450
451 void reset() {
452 mPos = 0;
453 }
454
455 void reset(size_t i) {
456 if (i >= mLen) {
457 ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen);
458 return;
459 }
460 mPos = i;
461 }
462
463 void skip(size_t i) {
464 size_t res = mPos + i;
465 if (res > mLen) {
466 ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen);
467 return;
468 }
469 mPos = res;
470 }
471
472 void* getData() const {
473 return mData;
474 }
475
476 size_t getLength() const {
477 return mLen;
478 }
479
480 template <typename T>
Tim Murray89daad62013-07-29 14:30:02 -0700481 void add(T t) {
Stephen Hines2c7206e2012-11-14 19:47:01 -0800482 align(sizeof(t));
483 if (mPos + sizeof(t) <= mLen) {
484 memcpy(&mData[mPos], &t, sizeof(t));
485 mPos += sizeof(t);
486 }
487 }
Stephen Hines43514cd2012-11-16 14:33:47 -0800488
489 /*
Tim Murray89daad62013-07-29 14:30:02 -0700490 void add(rs_matrix4x4 m) {
491 for (size_t i = 0; i < 16; i++) {
492 add(m.m[i]);
493 }
494 }
Stephen Hines43514cd2012-11-16 14:33:47 -0800495
Tim Murray89daad62013-07-29 14:30:02 -0700496 void add(rs_matrix3x3 m) {
497 for (size_t i = 0; i < 9; i++) {
498 add(m.m[i]);
499 }
500 }
Stephen Hines43514cd2012-11-16 14:33:47 -0800501
Tim Murray89daad62013-07-29 14:30:02 -0700502 void add(rs_matrix2x2 m) {
503 for (size_t i = 0; i < 4; i++) {
504 add(m.m[i]);
505 }
506 }
Stephen Hines43514cd2012-11-16 14:33:47 -0800507 */
508
Tim Murray89daad62013-07-29 14:30:02 -0700509 void add(sp<BaseObj> obj) {
Stephen Hines43514cd2012-11-16 14:33:47 -0800510 if (obj != NULL) {
511 add((uint32_t) (uintptr_t) obj->getID());
512 } else {
513 add((uint32_t) 0);
514 }
515 }
Stephen Hines2c7206e2012-11-14 19:47:01 -0800516};
517
Tim Murray89daad62013-07-29 14:30:02 -0700518
Tim Murray84bf2b82012-10-31 16:03:16 -0700519class Type : public BaseObj {
520protected:
521 friend class Allocation;
522
523 uint32_t mDimX;
524 uint32_t mDimY;
525 uint32_t mDimZ;
526 bool mDimMipmaps;
527 bool mDimFaces;
528 size_t mElementCount;
529 sp<const Element> mElement;
530
531 void calcElementCount();
532 virtual void updateFromNative();
533
534public:
535
536 sp<const Element> getElement() const {
537 return mElement;
538 }
539
540 uint32_t getX() const {
541 return mDimX;
542 }
543
544 uint32_t getY() const {
545 return mDimY;
546 }
547
548 uint32_t getZ() const {
549 return mDimZ;
550 }
551
552 bool hasMipmaps() const {
553 return mDimMipmaps;
554 }
555
556 bool hasFaces() const {
557 return mDimFaces;
558 }
559
560 size_t getCount() const {
561 return mElementCount;
562 }
563
564 size_t getSizeBytes() const {
565 return mElementCount * mElement->getSizeBytes();
566 }
567
568 Type(void *id, sp<RS> rs);
569
Tim Murray96267c22013-02-12 11:25:12 -0800570 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 -0700571
572 class Builder {
573 protected:
574 sp<RS> mRS;
575 uint32_t mDimX;
576 uint32_t mDimY;
577 uint32_t mDimZ;
578 bool mDimMipmaps;
579 bool mDimFaces;
580 sp<const Element> mElement;
581
582 public:
583 Builder(sp<RS> rs, sp<const Element> e);
584
585 void setX(uint32_t value);
586 void setY(int value);
587 void setMipmaps(bool value);
588 void setFaces(bool value);
589 sp<const Type> create();
590 };
591
592};
593
594class Script : public BaseObj {
595private:
596
597protected:
598 Script(void *id, sp<RS> rs);
599 void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out,
600 const void *v, size_t) const;
601 void bindAllocation(sp<Allocation> va, uint32_t slot) const;
602 void setVar(uint32_t index, const void *, size_t len) const;
603 void setVar(uint32_t index, sp<const BaseObj> o) const;
604 void invoke(uint32_t slot, const void *v, size_t len) const;
605
606
607 void invoke(uint32_t slot) const {
608 invoke(slot, NULL, 0);
609 }
610 void setVar(uint32_t index, float v) const {
611 setVar(index, &v, sizeof(v));
612 }
613 void setVar(uint32_t index, double v) const {
614 setVar(index, &v, sizeof(v));
615 }
616 void setVar(uint32_t index, int32_t v) const {
617 setVar(index, &v, sizeof(v));
618 }
619 void setVar(uint32_t index, int64_t v) const {
620 setVar(index, &v, sizeof(v));
621 }
622 void setVar(uint32_t index, bool v) const {
623 setVar(index, &v, sizeof(v));
624 }
625
626public:
627 class FieldBase {
628 protected:
629 sp<const Element> mElement;
630 sp<Allocation> mAllocation;
631
632 void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0);
633
634 public:
635 sp<const Element> getElement() {
636 return mElement;
637 }
638
639 sp<const Type> getType() {
640 return mAllocation->getType();
641 }
642
643 sp<const Allocation> getAllocation() {
644 return mAllocation;
645 }
646
647 //void updateAllocation();
648 };
649};
650
651class ScriptC : public Script {
652protected:
653 ScriptC(sp<RS> rs,
654 const void *codeTxt, size_t codeLength,
655 const char *cachedName, size_t cachedNameLength,
656 const char *cacheDir, size_t cacheDirLength);
657
658};
659
Tim Murray7f0d5682012-11-08 16:35:24 -0800660class ScriptIntrinsic : public Script {
661 protected:
Tim Murray3cd44af2012-11-14 11:25:27 -0800662 ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e);
Tim Murrayb27b1812013-08-05 14:00:40 -0700663 virtual ~ScriptIntrinsic();
Tim Murray7f0d5682012-11-08 16:35:24 -0800664};
665
Tim Murray89daad62013-07-29 14:30:02 -0700666class ScriptIntrinsic3DLUT : public ScriptIntrinsic {
667 public:
668 ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e);
669 void forEach(sp<Allocation> ain, sp<Allocation> aout);
670 void setLUT(sp<Allocation> lut);
671};
672
Tim Murray7f0d5682012-11-08 16:35:24 -0800673class ScriptIntrinsicBlend : public ScriptIntrinsic {
674 public:
Tim Murray89daad62013-07-29 14:30:02 -0700675 ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e);
Tim Murray7f0d5682012-11-08 16:35:24 -0800676 void blendClear(sp<Allocation> in, sp<Allocation> out);
677 void blendSrc(sp<Allocation> in, sp<Allocation> out);
678 void blendDst(sp<Allocation> in, sp<Allocation> out);
679 void blendSrcOver(sp<Allocation> in, sp<Allocation> out);
680 void blendDstOver(sp<Allocation> in, sp<Allocation> out);
681 void blendSrcIn(sp<Allocation> in, sp<Allocation> out);
682 void blendDstIn(sp<Allocation> in, sp<Allocation> out);
683 void blendSrcOut(sp<Allocation> in, sp<Allocation> out);
684 void blendDstOut(sp<Allocation> in, sp<Allocation> out);
685 void blendSrcAtop(sp<Allocation> in, sp<Allocation> out);
686 void blendDstAtop(sp<Allocation> in, sp<Allocation> out);
687 void blendXor(sp<Allocation> in, sp<Allocation> out);
688 void blendMultiply(sp<Allocation> in, sp<Allocation> out);
689 void blendAdd(sp<Allocation> in, sp<Allocation> out);
690 void blendSubtract(sp<Allocation> in, sp<Allocation> out);
691};
Tim Murray84bf2b82012-10-31 16:03:16 -0700692
Tim Murray8f1e60c2012-11-13 12:25:11 -0800693class ScriptIntrinsicBlur : public ScriptIntrinsic {
694 public:
Tim Murray89daad62013-07-29 14:30:02 -0700695 ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e);
Tim Murray8f1e60c2012-11-13 12:25:11 -0800696 void blur(sp<Allocation> in, sp<Allocation> out);
697 void setRadius(float radius);
698};
699
Tim Murray89daad62013-07-29 14:30:02 -0700700class ScriptIntrinsicColorMatrix : public ScriptIntrinsic {
701 public:
702 ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e);
703 void forEach(sp<Allocation> in, sp<Allocation> out);
704 void setColorMatrix3(float* m);
705 void setColorMatrix4(float* m);
706 void setGreyscale();
707 void setRGBtoYUV();
708 void setYUVtoRGB();
709};
710
711class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic {
712 public:
713 ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e);
714 void setInput(sp<Allocation> in);
715 void forEach(sp<Allocation> out);
716 void setCoefficients(float* v);
717};
718
719class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic {
720 public:
721 ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e);
722 void setInput(sp<Allocation> in);
723 void forEach(sp<Allocation> out);
724 void setCoefficients(float* v);
725};
726
Tim Murrayb27b1812013-08-05 14:00:40 -0700727class ScriptIntrinsicHistogram : public ScriptIntrinsic {
728 public:
729 ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e);
730 void setOutput(sp<Allocation> aout);
731 void setDotCoefficients(float r, float g, float b, float a);
732 void forEach(sp<Allocation> ain);
733 void forEach_dot(sp<Allocation> ain);
734};
735
736class ScriptIntrinsicLUT : public ScriptIntrinsic {
737 private:
738 sp<Allocation> LUT;
739 bool mDirty;
740 unsigned char mCache[1024];
741 void setTable(unsigned int offset, unsigned char base, unsigned char length, unsigned char* lutValues);
742
Tim Murray89daad62013-07-29 14:30:02 -0700743 public:
744 ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e);
745 void forEach(sp<Allocation> ain, sp<Allocation> aout);
Tim Murrayb27b1812013-08-05 14:00:40 -0700746 void setRed(unsigned char base, unsigned char length, unsigned char* lutValues);
747 void setGreen(unsigned char base, unsigned char length, unsigned char* lutValues);
748 void setBlue(unsigned char base, unsigned char length, unsigned char* lutValues);
749 void setAlpha(unsigned char base, unsigned char length, unsigned char* lutValues);
750 virtual ~ScriptIntrinsicLUT();
751};
752
Tim Murray89daad62013-07-29 14:30:02 -0700753class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic {
Tim Murrayb27b1812013-08-05 14:00:40 -0700754 public:
755 ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e);
756 void setInput(sp<Allocation> in);
757 void forEach(sp<Allocation> out);
Tim Murray89daad62013-07-29 14:30:02 -0700758
759};
Tim Murrayb27b1812013-08-05 14:00:40 -0700760
Tim Murray89daad62013-07-29 14:30:02 -0700761
Tim Murray729b6fe2013-07-23 16:20:42 -0700762 class Sampler : public BaseObj {
763 private:
764 Sampler(sp<RS> rs, void* id);
765 RsSamplerValue mMin;
766 RsSamplerValue mMag;
767 RsSamplerValue mWrapS;
768 RsSamplerValue mWrapT;
769 RsSamplerValue mWrapR;
770 float mAniso;
771
772 public:
773 static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
774
775 RsSamplerValue getMinification();
776 RsSamplerValue getMagnification();
777 RsSamplerValue getWrapS();
778 RsSamplerValue getWrapT();
779 float getAnisotropy();
780
781 sp<const Sampler> CLAMP_NEAREST(sp<RS> rs);
782 sp<const Sampler> CLAMP_LINEAR(sp<RS> rs);
783 sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs);
784 sp<const Sampler> WRAP_NEAREST(sp<RS> rs);
785 sp<const Sampler> WRAP_LINEAR(sp<RS> rs);
786 sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs);
787 sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs);
788 sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs);
789 sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs);
790
791};
792
Tim Murray84bf2b82012-10-31 16:03:16 -0700793}
Tim Murray7f0d5682012-11-08 16:35:24 -0800794
Tim Murray84bf2b82012-10-31 16:03:16 -0700795}
796
797#endif