rsCppStructs.h revision 21deee08b729f701d6193e93e56bd442b04c4a3d
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 class RS : public android::RSC::LightRefBase<RS> {
48
49 public:
50    RS();
51    virtual ~RS();
52
53    bool init(bool forceCpu = false, bool synchronous = false);
54
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
65    void finish();
66
67    static dispatchTable* dispatch;
68
69 private:
70    static bool usingNative;
71    static bool initDispatch(int targetApi);
72
73    bool init(int targetApi, bool forceCpu, bool synchronous);
74    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;
88    bool mInit;
89
90    struct {
91        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;
102
103        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;
113
114        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;
120
121        sp<const Element> FLOAT_2;
122        sp<const Element> FLOAT_3;
123        sp<const Element> FLOAT_4;
124
125        sp<const Element> DOUBLE_2;
126        sp<const Element> DOUBLE_3;
127        sp<const Element> DOUBLE_4;
128
129        sp<const Element> UCHAR_2;
130        sp<const Element> UCHAR_3;
131        sp<const Element> UCHAR_4;
132
133        sp<const Element> CHAR_2;
134        sp<const Element> CHAR_3;
135        sp<const Element> CHAR_4;
136
137        sp<const Element> USHORT_2;
138        sp<const Element> USHORT_3;
139        sp<const Element> USHORT_4;
140
141        sp<const Element> SHORT_2;
142        sp<const Element> SHORT_3;
143        sp<const Element> SHORT_4;
144
145        sp<const Element> UINT_2;
146        sp<const Element> UINT_3;
147        sp<const Element> UINT_4;
148
149        sp<const Element> INT_2;
150        sp<const Element> INT_3;
151        sp<const Element> INT_4;
152
153        sp<const Element> ULONG_2;
154        sp<const Element> ULONG_3;
155        sp<const Element> ULONG_4;
156
157        sp<const Element> LONG_2;
158        sp<const Element> LONG_3;
159        sp<const Element> LONG_4;
160
161        sp<const Element> MATRIX_4X4;
162        sp<const Element> MATRIX_3X3;
163        sp<const Element> MATRIX_2X2;
164    } mElements;
165
166    struct {
167        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;
176    } mSamplers;
177    friend class Sampler;
178    friend class Element;
179};
180
181class 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
188protected:
189    void *mID;
190    sp<RS> mRS;
191    std::string mName;
192
193    BaseObj(void *id, sp<RS> rs);
194    void checkValid();
195
196    static void * getObjID(sp<const BaseObj> o);
197
198};
199
200
201class Allocation : public BaseObj {
202protected:
203    sp<const Type> mType;
204    uint32_t mUsage;
205    sp<Allocation> mAdaptedAllocation;
206
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:
239    sp<const Type> getType() {
240        return mType;
241    }
242
243    void syncAll(RsAllocationUsageType srcLocation);
244    void ioSendOutput();
245    void ioGetInput();
246
247    void generateMipmaps();
248
249    void copy1DRangeFrom(uint32_t off, size_t count, const void *data);
250    void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff);
251
252    void copy1DRangeTo(uint32_t off, size_t count, void *data);
253
254    void copy1DFrom(const void* data);
255    void copy1DTo(void* data);
256
257    void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
258                         const void *data);
259
260    void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
261                       void *data);
262
263    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);
265
266    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
274    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);
286    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
290
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
379    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
385    Element(void *id, sp<RS> rs,
386            std::vector<sp<Element> > &elements,
387            std::vector<std::string> &elementNames,
388            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:
394    class Builder {
395    private:
396        sp<RS> mRS;
397        std::vector<sp<Element> > mElements;
398        std::vector<std::string> mElementNames;
399        std::vector<uint32_t> mArraySizes;
400        bool mSkipPadding;
401
402    public:
403        Builder(sp<RS> rs);
404        ~Builder();
405        void add(sp<Element> e, std::string &name, uint32_t arraySize = 1);
406        sp<const Element> create();
407    };
408
409private:
410    void updateVisibleSubElements();
411
412    std::vector<sp<Element> > mElements;
413    std::vector<std::string> mElementNames;
414    std::vector<uint32_t> mArraySizes;
415    std::vector<uint32_t> mVisibleElementMap;
416    std::vector<uint32_t> mOffsetInBytes;
417
418    RsDataType mType;
419    RsDataKind mKind;
420    bool mNormalized;
421    size_t mSizeBytes;
422    size_t mVectorSize;
423};
424
425class FieldPacker {
426protected:
427    unsigned char* mData;
428    size_t mPos;
429    size_t mLen;
430
431public:
432    FieldPacker(size_t len)
433        : mPos(0), mLen(len) {
434            mData = new unsigned char[len];
435        }
436
437    virtual ~FieldPacker() {
438        delete [] mData;
439    }
440
441    void align(size_t v) {
442        if ((v & (v - 1)) != 0) {
443            //            ALOGE("Non-power-of-two alignment: %zu", v);
444            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) {
458            //            ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen);
459            return;
460        }
461        mPos = i;
462    }
463
464    void skip(size_t i) {
465        size_t res = mPos + i;
466        if (res > mLen) {
467            //            ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen);
468            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>
482        void add(T t) {
483        align(sizeof(t));
484        if (mPos + sizeof(t) <= mLen) {
485            memcpy(&mData[mPos], &t, sizeof(t));
486            mPos += sizeof(t);
487        }
488    }
489
490    /*
491      void add(rs_matrix4x4 m) {
492      for (size_t i = 0; i < 16; i++) {
493      add(m.m[i]);
494      }
495      }
496
497      void add(rs_matrix3x3 m) {
498      for (size_t i = 0; i < 9; i++) {
499      add(m.m[i]);
500      }
501      }
502
503      void add(rs_matrix2x2 m) {
504      for (size_t i = 0; i < 4; i++) {
505      add(m.m[i]);
506      }
507      }
508    */
509
510    void add(sp<BaseObj> obj) {
511        if (obj != NULL) {
512            add((uint32_t) (uintptr_t) obj->getID());
513        } else {
514            add((uint32_t) 0);
515        }
516    }
517};
518
519
520class 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
571    static sp<const Type> create(sp<RS> rs, sp<const Element> e, uint32_t dimX, uint32_t dimY, uint32_t dimZ);
572
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
661class ScriptIntrinsic : public Script {
662 protected:
663    ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e);
664    virtual ~ScriptIntrinsic();
665};
666
667class 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
674class ScriptIntrinsicBlend : public ScriptIntrinsic {
675 public:
676    ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e);
677    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};
693
694class ScriptIntrinsicBlur : public ScriptIntrinsic {
695 public:
696    ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e);
697    void blur(sp<Allocation> in, sp<Allocation> out);
698    void setRadius(float radius);
699};
700
701class 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
728class 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
744 public:
745    ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e);
746    void forEach(sp<Allocation> ain, sp<Allocation> aout);
747    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
754class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic {
755 public:
756    ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e);
757    void setInput(sp<Allocation> in);
758    void forEach(sp<Allocation> out);
759
760};
761
762
763 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
794}
795
796}
797
798#endif
799