rsCppStructs.h revision 21fa7a0a23eddab88ff261017f6d7a2548b4d89a
1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
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
20#include "rsDefines.h"
21#include "rsCppUtils.h"
22#include "util/RefBase.h"
23#include "rsDispatch.h"
24
25#include <vector>
26#include <string>
27
28// 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
32namespace android {
33namespace RSC {
34
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;
45class Sampler;
46
47 enum RSError {
48     RS_SUCCESS = 0,
49     RS_ERROR_INVALID_PARAMETER = 1,
50     RS_ERROR_RUNTIME_ERROR = 2,
51     RS_ERROR_MAX = 9999
52
53 };
54
55 class RS : public android::RSC::LightRefBase<RS> {
56
57 public:
58    RS();
59    virtual ~RS();
60
61    bool init(bool forceCpu = false, bool synchronous = false);
62
63    void setErrorHandler(ErrorHandlerFunc_t func);
64    ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; }
65
66    void setMessageHandler(MessageHandlerFunc_t func);
67    MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; }
68
69    void throwError(RSError error, const char *errMsg);
70
71    RsContext getContext() { return mContext; }
72
73    void finish();
74
75    static dispatchTable* dispatch;
76
77 private:
78    static bool usingNative;
79    static bool initDispatch(int targetApi);
80
81    bool init(int targetApi, bool forceCpu, bool synchronous);
82    static void * threadProc(void *);
83
84    static bool gInitialized;
85    static pthread_mutex_t gInitMutex;
86
87    pthread_t mMessageThreadId;
88    pid_t mNativeMessageThreadId;
89    bool mMessageRun;
90
91    RsDevice mDev;
92    RsContext mContext;
93    RSError mCurrentError;
94
95    ErrorHandlerFunc_t mErrorFunc;
96    MessageHandlerFunc_t mMessageFunc;
97    bool mInit;
98
99    struct {
100        sp<const Element> U8;
101        sp<const Element> I8;
102        sp<const Element> U16;
103        sp<const Element> I16;
104        sp<const Element> U32;
105        sp<const Element> I32;
106        sp<const Element> U64;
107        sp<const Element> I64;
108        sp<const Element> F32;
109        sp<const Element> F64;
110        sp<const Element> BOOLEAN;
111
112        sp<const Element> ELEMENT;
113        sp<const Element> TYPE;
114        sp<const Element> ALLOCATION;
115        sp<const Element> SAMPLER;
116        sp<const Element> SCRIPT;
117        sp<const Element> MESH;
118        sp<const Element> PROGRAM_FRAGMENT;
119        sp<const Element> PROGRAM_VERTEX;
120        sp<const Element> PROGRAM_RASTER;
121        sp<const Element> PROGRAM_STORE;
122
123        sp<const Element> A_8;
124        sp<const Element> RGB_565;
125        sp<const Element> RGB_888;
126        sp<const Element> RGBA_5551;
127        sp<const Element> RGBA_4444;
128        sp<const Element> RGBA_8888;
129
130        sp<const Element> FLOAT_2;
131        sp<const Element> FLOAT_3;
132        sp<const Element> FLOAT_4;
133
134        sp<const Element> DOUBLE_2;
135        sp<const Element> DOUBLE_3;
136        sp<const Element> DOUBLE_4;
137
138        sp<const Element> UCHAR_2;
139        sp<const Element> UCHAR_3;
140        sp<const Element> UCHAR_4;
141
142        sp<const Element> CHAR_2;
143        sp<const Element> CHAR_3;
144        sp<const Element> CHAR_4;
145
146        sp<const Element> USHORT_2;
147        sp<const Element> USHORT_3;
148        sp<const Element> USHORT_4;
149
150        sp<const Element> SHORT_2;
151        sp<const Element> SHORT_3;
152        sp<const Element> SHORT_4;
153
154        sp<const Element> UINT_2;
155        sp<const Element> UINT_3;
156        sp<const Element> UINT_4;
157
158        sp<const Element> INT_2;
159        sp<const Element> INT_3;
160        sp<const Element> INT_4;
161
162        sp<const Element> ULONG_2;
163        sp<const Element> ULONG_3;
164        sp<const Element> ULONG_4;
165
166        sp<const Element> LONG_2;
167        sp<const Element> LONG_3;
168        sp<const Element> LONG_4;
169
170        sp<const Element> MATRIX_4X4;
171        sp<const Element> MATRIX_3X3;
172        sp<const Element> MATRIX_2X2;
173    } mElements;
174
175    struct {
176        sp<const Sampler> CLAMP_NEAREST;
177        sp<const Sampler> CLAMP_LINEAR;
178        sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR;
179        sp<const Sampler> WRAP_NEAREST;
180        sp<const Sampler> WRAP_LINEAR;
181        sp<const Sampler> WRAP_LINEAR_MIP_LINEAR;
182        sp<const Sampler> MIRRORED_REPEAT_NEAREST;
183        sp<const Sampler> MIRRORED_REPEAT_LINEAR;
184        sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
185    } mSamplers;
186    friend class Sampler;
187    friend class Element;
188};
189
190class BaseObj : public android::RSC::LightRefBase<BaseObj> {
191public:
192    void * getID() const;
193    virtual ~BaseObj();
194    virtual void updateFromNative();
195    virtual bool equals(sp<const BaseObj> obj);
196
197protected:
198    void *mID;
199    sp<RS> mRS;
200    std::string mName;
201
202    BaseObj(void *id, sp<RS> rs);
203    void checkValid();
204
205    static void * getObjID(sp<const BaseObj> o);
206
207};
208
209
210class Allocation : public BaseObj {
211protected:
212    sp<const Type> mType;
213    uint32_t mUsage;
214    sp<Allocation> mAdaptedAllocation;
215
216    bool mConstrainedLOD;
217    bool mConstrainedFace;
218    bool mConstrainedY;
219    bool mConstrainedZ;
220    bool mReadAllowed;
221    bool mWriteAllowed;
222    uint32_t mSelectedY;
223    uint32_t mSelectedZ;
224    uint32_t mSelectedLOD;
225    RsAllocationCubemapFace mSelectedFace;
226
227    uint32_t mCurrentDimX;
228    uint32_t mCurrentDimY;
229    uint32_t mCurrentDimZ;
230    uint32_t mCurrentCount;
231
232    void * getIDSafe() const;
233    void updateCacheInfo(sp<const Type> t);
234
235    Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage);
236
237    void validateIsInt32();
238    void validateIsInt16();
239    void validateIsInt8();
240    void validateIsFloat32();
241    void validateIsObject();
242
243    virtual void updateFromNative();
244
245    void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h);
246
247public:
248    sp<const Type> getType() {
249        return mType;
250    }
251
252    void syncAll(RsAllocationUsageType srcLocation);
253    void ioSendOutput();
254    void ioGetInput();
255
256    void generateMipmaps();
257
258    void copy1DRangeFrom(uint32_t off, size_t count, const void *data);
259    void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff);
260
261    void copy1DRangeTo(uint32_t off, size_t count, void *data);
262
263    void copy1DFrom(const void* data);
264    void copy1DTo(void* data);
265
266    void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
267                         const void *data);
268
269    void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
270                       void *data);
271
272    void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
273                         sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff);
274
275    void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
276                           const void *data, size_t stride);
277    void copy2DStridedFrom(const void *data, size_t stride);
278
279    void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
280                         void *data, size_t stride);
281    void copy2DStridedTo(void *data, size_t stride);
282
283    void resize(int dimX);
284    void resize(int dimX, int dimY);
285
286    static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
287                                   RsAllocationMipmapControl mips, uint32_t usage);
288    static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
289                                   RsAllocationMipmapControl mips, uint32_t usage, void * pointer);
290
291    static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
292                                   uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
293    static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count,
294                                   uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
295    static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e,
296                                        size_t x, size_t y,
297                                        uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
298
299
300};
301
302class Element : public BaseObj {
303public:
304    bool isComplex();
305    size_t getSubElementCount() {
306        return mVisibleElementMap.size();
307    }
308
309    sp<const Element> getSubElement(uint32_t index);
310    const char * getSubElementName(uint32_t index);
311    size_t getSubElementArraySize(uint32_t index);
312    uint32_t getSubElementOffsetBytes(uint32_t index);
313    RsDataType getDataType() const {
314        return mType;
315    }
316
317    RsDataKind getDataKind() const {
318        return mKind;
319    }
320
321    size_t getSizeBytes() const {
322        return mSizeBytes;
323    }
324
325    static sp<const Element> BOOLEAN(sp<RS> rs);
326    static sp<const Element> U8(sp<RS> rs);
327    static sp<const Element> I8(sp<RS> rs);
328    static sp<const Element> U16(sp<RS> rs);
329    static sp<const Element> I16(sp<RS> rs);
330    static sp<const Element> U32(sp<RS> rs);
331    static sp<const Element> I32(sp<RS> rs);
332    static sp<const Element> U64(sp<RS> rs);
333    static sp<const Element> I64(sp<RS> rs);
334    static sp<const Element> F32(sp<RS> rs);
335    static sp<const Element> F64(sp<RS> rs);
336    static sp<const Element> ELEMENT(sp<RS> rs);
337    static sp<const Element> TYPE(sp<RS> rs);
338    static sp<const Element> ALLOCATION(sp<RS> rs);
339    static sp<const Element> SAMPLER(sp<RS> rs);
340    static sp<const Element> SCRIPT(sp<RS> rs);
341    static sp<const Element> MESH(sp<RS> rs);
342    static sp<const Element> PROGRAM_FRAGMENT(sp<RS> rs);
343    static sp<const Element> PROGRAM_VERTEX(sp<RS> rs);
344    static sp<const Element> PROGRAM_RASTER(sp<RS> rs);
345    static sp<const Element> PROGRAM_STORE(sp<RS> rs);
346
347    static sp<const Element> A_8(sp<RS> rs);
348    static sp<const Element> RGB_565(sp<RS> rs);
349    static sp<const Element> RGB_888(sp<RS> rs);
350    static sp<const Element> RGBA_5551(sp<RS> rs);
351    static sp<const Element> RGBA_4444(sp<RS> rs);
352    static sp<const Element> RGBA_8888(sp<RS> rs);
353
354    static sp<const Element> F32_2(sp<RS> rs);
355    static sp<const Element> F32_3(sp<RS> rs);
356    static sp<const Element> F32_4(sp<RS> rs);
357    static sp<const Element> F64_2(sp<RS> rs);
358    static sp<const Element> F64_3(sp<RS> rs);
359    static sp<const Element> F64_4(sp<RS> rs);
360    static sp<const Element> U8_2(sp<RS> rs);
361    static sp<const Element> U8_3(sp<RS> rs);
362    static sp<const Element> U8_4(sp<RS> rs);
363    static sp<const Element> I8_2(sp<RS> rs);
364    static sp<const Element> I8_3(sp<RS> rs);
365    static sp<const Element> I8_4(sp<RS> rs);
366    static sp<const Element> U16_2(sp<RS> rs);
367    static sp<const Element> U16_3(sp<RS> rs);
368    static sp<const Element> U16_4(sp<RS> rs);
369    static sp<const Element> I16_2(sp<RS> rs);
370    static sp<const Element> I16_3(sp<RS> rs);
371    static sp<const Element> I16_4(sp<RS> rs);
372    static sp<const Element> U32_2(sp<RS> rs);
373    static sp<const Element> U32_3(sp<RS> rs);
374    static sp<const Element> U32_4(sp<RS> rs);
375    static sp<const Element> I32_2(sp<RS> rs);
376    static sp<const Element> I32_3(sp<RS> rs);
377    static sp<const Element> I32_4(sp<RS> rs);
378    static sp<const Element> U64_2(sp<RS> rs);
379    static sp<const Element> U64_3(sp<RS> rs);
380    static sp<const Element> U64_4(sp<RS> rs);
381    static sp<const Element> I64_2(sp<RS> rs);
382    static sp<const Element> I64_3(sp<RS> rs);
383    static sp<const Element> I64_4(sp<RS> rs);
384    static sp<const Element> MATRIX_4X4(sp<RS> rs);
385    static sp<const Element> MATRIX_3X3(sp<RS> rs);
386    static sp<const Element> MATRIX_2X2(sp<RS> rs);
387
388    void updateFromNative();
389    static sp<const Element> createUser(sp<RS> rs, RsDataType dt);
390    static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size);
391    static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk);
392    bool isCompatible(sp<const Element>e);
393
394    Element(void *id, sp<RS> rs,
395            std::vector<sp<Element> > &elements,
396            std::vector<std::string> &elementNames,
397            std::vector<uint32_t> &arraySizes);
398    Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size);
399    Element(sp<RS> rs);
400    virtual ~Element();
401
402 protected:
403    class Builder {
404    private:
405        sp<RS> mRS;
406        std::vector<sp<Element> > mElements;
407        std::vector<std::string> mElementNames;
408        std::vector<uint32_t> mArraySizes;
409        bool mSkipPadding;
410
411    public:
412        Builder(sp<RS> rs);
413        ~Builder();
414        void add(sp<Element> e, std::string &name, uint32_t arraySize = 1);
415        sp<const Element> create();
416    };
417
418private:
419    void updateVisibleSubElements();
420
421    std::vector<sp<Element> > mElements;
422    std::vector<std::string> mElementNames;
423    std::vector<uint32_t> mArraySizes;
424    std::vector<uint32_t> mVisibleElementMap;
425    std::vector<uint32_t> mOffsetInBytes;
426
427    RsDataType mType;
428    RsDataKind mKind;
429    bool mNormalized;
430    size_t mSizeBytes;
431    size_t mVectorSize;
432};
433
434class FieldPacker {
435protected:
436    unsigned char* mData;
437    size_t mPos;
438    size_t mLen;
439
440public:
441    FieldPacker(size_t len)
442        : mPos(0), mLen(len) {
443            mData = new unsigned char[len];
444        }
445
446    virtual ~FieldPacker() {
447        delete [] mData;
448    }
449
450    void align(size_t v) {
451        if ((v & (v - 1)) != 0) {
452            //            ALOGE("Non-power-of-two alignment: %zu", v);
453            return;
454        }
455
456        while ((mPos & (v - 1)) != 0) {
457            mData[mPos++] = 0;
458        }
459    }
460
461    void reset() {
462        mPos = 0;
463    }
464
465    void reset(size_t i) {
466        if (i >= mLen) {
467            //            ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen);
468            return;
469        }
470        mPos = i;
471    }
472
473    void skip(size_t i) {
474        size_t res = mPos + i;
475        if (res > mLen) {
476            //            ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen);
477            return;
478        }
479        mPos = res;
480    }
481
482    void* getData() const {
483        return mData;
484    }
485
486    size_t getLength() const {
487        return mLen;
488    }
489
490    template <typename T>
491        void add(T t) {
492        align(sizeof(t));
493        if (mPos + sizeof(t) <= mLen) {
494            memcpy(&mData[mPos], &t, sizeof(t));
495            mPos += sizeof(t);
496        }
497    }
498
499    /*
500      void add(rs_matrix4x4 m) {
501      for (size_t i = 0; i < 16; i++) {
502      add(m.m[i]);
503      }
504      }
505
506      void add(rs_matrix3x3 m) {
507      for (size_t i = 0; i < 9; i++) {
508      add(m.m[i]);
509      }
510      }
511
512      void add(rs_matrix2x2 m) {
513      for (size_t i = 0; i < 4; i++) {
514      add(m.m[i]);
515      }
516      }
517    */
518
519    void add(sp<BaseObj> obj) {
520        if (obj != NULL) {
521            add((uint32_t) (uintptr_t) obj->getID());
522        } else {
523            add((uint32_t) 0);
524        }
525    }
526};
527
528
529class Type : public BaseObj {
530protected:
531    friend class Allocation;
532
533    uint32_t mDimX;
534    uint32_t mDimY;
535    uint32_t mDimZ;
536    bool mDimMipmaps;
537    bool mDimFaces;
538    size_t mElementCount;
539    sp<const Element> mElement;
540
541    void calcElementCount();
542    virtual void updateFromNative();
543
544public:
545
546    sp<const Element> getElement() const {
547        return mElement;
548    }
549
550    uint32_t getX() const {
551        return mDimX;
552    }
553
554    uint32_t getY() const {
555        return mDimY;
556    }
557
558    uint32_t getZ() const {
559        return mDimZ;
560    }
561
562    bool hasMipmaps() const {
563        return mDimMipmaps;
564    }
565
566    bool hasFaces() const {
567        return mDimFaces;
568    }
569
570    size_t getCount() const {
571        return mElementCount;
572    }
573
574    size_t getSizeBytes() const {
575        return mElementCount * mElement->getSizeBytes();
576    }
577
578    Type(void *id, sp<RS> rs);
579
580    static sp<const Type> create(sp<RS> rs, sp<const Element> e, uint32_t dimX, uint32_t dimY, uint32_t dimZ);
581
582    class Builder {
583    protected:
584        sp<RS> mRS;
585        uint32_t mDimX;
586        uint32_t mDimY;
587        uint32_t mDimZ;
588        bool mDimMipmaps;
589        bool mDimFaces;
590        sp<const Element> mElement;
591
592    public:
593        Builder(sp<RS> rs, sp<const Element> e);
594
595        void setX(uint32_t value);
596        void setY(int value);
597        void setMipmaps(bool value);
598        void setFaces(bool value);
599        sp<const Type> create();
600    };
601
602};
603
604class Script : public BaseObj {
605private:
606
607protected:
608    Script(void *id, sp<RS> rs);
609    void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out,
610            const void *v, size_t) const;
611    void bindAllocation(sp<Allocation> va, uint32_t slot) const;
612    void setVar(uint32_t index, const void *, size_t len) const;
613    void setVar(uint32_t index, sp<const BaseObj> o) const;
614    void invoke(uint32_t slot, const void *v, size_t len) const;
615
616
617    void invoke(uint32_t slot) const {
618        invoke(slot, NULL, 0);
619    }
620    void setVar(uint32_t index, float v) const {
621        setVar(index, &v, sizeof(v));
622    }
623    void setVar(uint32_t index, double v) const {
624        setVar(index, &v, sizeof(v));
625    }
626    void setVar(uint32_t index, int32_t v) const {
627        setVar(index, &v, sizeof(v));
628    }
629    void setVar(uint32_t index, int64_t v) const {
630        setVar(index, &v, sizeof(v));
631    }
632    void setVar(uint32_t index, bool v) const {
633        setVar(index, &v, sizeof(v));
634    }
635
636public:
637    class FieldBase {
638    protected:
639        sp<const Element> mElement;
640        sp<Allocation> mAllocation;
641
642        void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0);
643
644    public:
645        sp<const Element> getElement() {
646            return mElement;
647        }
648
649        sp<const Type> getType() {
650            return mAllocation->getType();
651        }
652
653        sp<const Allocation> getAllocation() {
654            return mAllocation;
655        }
656
657        //void updateAllocation();
658    };
659};
660
661class ScriptC : public Script {
662protected:
663    ScriptC(sp<RS> rs,
664            const void *codeTxt, size_t codeLength,
665            const char *cachedName, size_t cachedNameLength,
666            const char *cacheDir, size_t cacheDirLength);
667
668};
669
670class ScriptIntrinsic : public Script {
671 protected:
672    ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e);
673    virtual ~ScriptIntrinsic();
674};
675
676class ScriptIntrinsic3DLUT : public ScriptIntrinsic {
677 private:
678    ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e);
679 public:
680    static sp<ScriptIntrinsic3DLUT> create(sp<RS> rs, sp<const Element> e);
681    void forEach(sp<Allocation> ain, sp<Allocation> aout);
682    void setLUT(sp<Allocation> lut);
683};
684
685class ScriptIntrinsicBlend : public ScriptIntrinsic {
686 private:
687    ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e);
688 public:
689    static sp<ScriptIntrinsicBlend> create(sp<RS> rs, sp<const Element> e);
690    void blendClear(sp<Allocation> in, sp<Allocation> out);
691    void blendSrc(sp<Allocation> in, sp<Allocation> out);
692    void blendDst(sp<Allocation> in, sp<Allocation> out);
693    void blendSrcOver(sp<Allocation> in, sp<Allocation> out);
694    void blendDstOver(sp<Allocation> in, sp<Allocation> out);
695    void blendSrcIn(sp<Allocation> in, sp<Allocation> out);
696    void blendDstIn(sp<Allocation> in, sp<Allocation> out);
697    void blendSrcOut(sp<Allocation> in, sp<Allocation> out);
698    void blendDstOut(sp<Allocation> in, sp<Allocation> out);
699    void blendSrcAtop(sp<Allocation> in, sp<Allocation> out);
700    void blendDstAtop(sp<Allocation> in, sp<Allocation> out);
701    void blendXor(sp<Allocation> in, sp<Allocation> out);
702    void blendMultiply(sp<Allocation> in, sp<Allocation> out);
703    void blendAdd(sp<Allocation> in, sp<Allocation> out);
704    void blendSubtract(sp<Allocation> in, sp<Allocation> out);
705};
706
707class ScriptIntrinsicBlur : public ScriptIntrinsic {
708 private:
709    ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e);
710 public:
711    static sp<ScriptIntrinsicBlur> create(sp<RS> rs, sp<const Element> e);
712    void setInput(sp<Allocation> in);
713    void forEach(sp<Allocation> out);
714    void setRadius(float radius);
715};
716
717class ScriptIntrinsicColorMatrix : public ScriptIntrinsic {
718 private:
719    ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e);
720 public:
721    static sp<ScriptIntrinsicColorMatrix> create(sp<RS> rs, sp<const Element> e);
722    void forEach(sp<Allocation> in, sp<Allocation> out);
723    void setColorMatrix3(float* m);
724    void setColorMatrix4(float* m);
725    void setGreyscale();
726    void setRGBtoYUV();
727    void setYUVtoRGB();
728};
729
730class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic {
731 private:
732    ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e);
733 public:
734    static sp<ScriptIntrinsicConvolve3x3> create(sp<RS> rs, sp<const Element> e);
735    void setInput(sp<Allocation> in);
736    void forEach(sp<Allocation> out);
737    void setCoefficients(float* v);
738};
739
740class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic {
741 private:
742    ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e);
743 public:
744    static sp<ScriptIntrinsicConvolve5x5> create(sp<RS> rs, sp<const Element> e);
745    void setInput(sp<Allocation> in);
746    void forEach(sp<Allocation> out);
747    void setCoefficients(float* v);
748};
749
750class ScriptIntrinsicHistogram : public ScriptIntrinsic {
751 private:
752    ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e);
753 public:
754    static sp<ScriptIntrinsicHistogram> create(sp<RS> rs, sp<const Element> e);
755    void setOutput(sp<Allocation> aout);
756    void setDotCoefficients(float r, float g, float b, float a);
757    void forEach(sp<Allocation> ain);
758    void forEach_dot(sp<Allocation> ain);
759};
760
761class ScriptIntrinsicLUT : public ScriptIntrinsic {
762 private:
763    sp<Allocation> LUT;
764    bool mDirty;
765    unsigned char mCache[1024];
766    void setTable(unsigned int offset, unsigned char base, unsigned char length, unsigned char* lutValues);
767    ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e);
768
769 public:
770    static sp<ScriptIntrinsicLUT> create(sp<RS> rs, sp<const Element> e);
771    void forEach(sp<Allocation> ain, sp<Allocation> aout);
772    void setRed(unsigned char base, unsigned char length, unsigned char* lutValues);
773    void setGreen(unsigned char base, unsigned char length, unsigned char* lutValues);
774    void setBlue(unsigned char base, unsigned char length, unsigned char* lutValues);
775    void setAlpha(unsigned char base, unsigned char length, unsigned char* lutValues);
776    virtual ~ScriptIntrinsicLUT();
777};
778
779class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic {
780 private:
781    ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e);
782 public:
783    static sp<ScriptIntrinsicYuvToRGB> create(sp<RS> rs, sp<const Element> e);
784    void setInput(sp<Allocation> in);
785    void forEach(sp<Allocation> out);
786
787};
788
789
790 class Sampler : public BaseObj {
791 private:
792    Sampler(sp<RS> rs, void* id);
793    RsSamplerValue mMin;
794    RsSamplerValue mMag;
795    RsSamplerValue mWrapS;
796    RsSamplerValue mWrapT;
797    RsSamplerValue mWrapR;
798    float mAniso;
799
800 public:
801    static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
802
803    RsSamplerValue getMinification();
804    RsSamplerValue getMagnification();
805    RsSamplerValue getWrapS();
806    RsSamplerValue getWrapT();
807    float getAnisotropy();
808
809    sp<const Sampler> CLAMP_NEAREST(sp<RS> rs);
810    sp<const Sampler> CLAMP_LINEAR(sp<RS> rs);
811    sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs);
812    sp<const Sampler> WRAP_NEAREST(sp<RS> rs);
813    sp<const Sampler> WRAP_LINEAR(sp<RS> rs);
814    sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs);
815    sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs);
816    sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs);
817    sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs);
818
819};
820
821}
822
823}
824
825#endif
826