rsCppStructs.h revision b27b18130d0772203799ba0f2d27783b640dc891
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
27// 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
31namespace android {
32namespace RSC {
33
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;
44class Sampler;
45
46 class RS : public android::RSC::LightRefBase<RS> {
47
48 public:
49    RS();
50    virtual ~RS();
51
52    bool init(bool forceCpu = false, bool synchronous = false);
53
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
64    void finish();
65
66    static dispatchTable* dispatch;
67
68 private:
69    static bool usingNative;
70    static bool initDispatch(int targetApi);
71
72    bool init(int targetApi, bool forceCpu, bool synchronous);
73    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;
87    bool mInit;
88
89    struct {
90        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;
101
102        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;
112
113        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;
119
120        sp<const Element> FLOAT_2;
121        sp<const Element> FLOAT_3;
122        sp<const Element> FLOAT_4;
123
124        sp<const Element> DOUBLE_2;
125        sp<const Element> DOUBLE_3;
126        sp<const Element> DOUBLE_4;
127
128        sp<const Element> UCHAR_2;
129        sp<const Element> UCHAR_3;
130        sp<const Element> UCHAR_4;
131
132        sp<const Element> CHAR_2;
133        sp<const Element> CHAR_3;
134        sp<const Element> CHAR_4;
135
136        sp<const Element> USHORT_2;
137        sp<const Element> USHORT_3;
138        sp<const Element> USHORT_4;
139
140        sp<const Element> SHORT_2;
141        sp<const Element> SHORT_3;
142        sp<const Element> SHORT_4;
143
144        sp<const Element> UINT_2;
145        sp<const Element> UINT_3;
146        sp<const Element> UINT_4;
147
148        sp<const Element> INT_2;
149        sp<const Element> INT_3;
150        sp<const Element> INT_4;
151
152        sp<const Element> ULONG_2;
153        sp<const Element> ULONG_3;
154        sp<const Element> ULONG_4;
155
156        sp<const Element> LONG_2;
157        sp<const Element> LONG_3;
158        sp<const Element> LONG_4;
159
160        sp<const Element> MATRIX_4X4;
161        sp<const Element> MATRIX_3X3;
162        sp<const Element> MATRIX_2X2;
163    } mElements;
164
165    struct {
166        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;
175    } mSamplers;
176    friend class Sampler;
177    friend class Element;
178};
179
180class 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
187protected:
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
197};
198
199
200class Allocation : public BaseObj {
201protected:
202    sp<const Type> mType;
203    uint32_t mUsage;
204    sp<Allocation> mAdaptedAllocation;
205
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:
238    sp<const Type> getType() {
239        return mType;
240    }
241
242    void syncAll(RsAllocationUsageType srcLocation);
243    void ioSendOutput();
244    void ioGetInput();
245
246    void generateMipmaps();
247
248    void copy1DRangeFrom(uint32_t off, size_t count, const void *data);
249    void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff);
250
251    void copy1DRangeTo(uint32_t off, size_t count, void *data);
252
253    void copy1DFrom(const void* data);
254    void copy1DTo(void* data);
255
256    void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
257                         const void *data);
258
259    void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
260                       void *data);
261
262    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);
264
265    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
273    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);
285    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
289
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
378    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
384    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:
393    class Builder {
394    private:
395        sp<RS> mRS;
396        std::vector<sp<Element> > mElements;
397        std::vector<android::String8> mElementNames;
398        std::vector<uint32_t> mArraySizes;
399        bool mSkipPadding;
400
401    public:
402        Builder(sp<RS> rs);
403        ~Builder();
404        void add(sp<Element> e, android::String8 &name, uint32_t arraySize = 1);
405        sp<const Element> create();
406    };
407
408private:
409    void updateVisibleSubElements();
410
411    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;
416
417    RsDataType mType;
418    RsDataKind mKind;
419    bool mNormalized;
420    size_t mSizeBytes;
421    size_t mVectorSize;
422};
423
424class FieldPacker {
425protected:
426    unsigned char* mData;
427    size_t mPos;
428    size_t mLen;
429
430public:
431    FieldPacker(size_t len)
432        : mPos(0), mLen(len) {
433            mData = new unsigned char[len];
434        }
435
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>
481        void add(T t) {
482        align(sizeof(t));
483        if (mPos + sizeof(t) <= mLen) {
484            memcpy(&mData[mPos], &t, sizeof(t));
485            mPos += sizeof(t);
486        }
487    }
488
489    /*
490      void add(rs_matrix4x4 m) {
491      for (size_t i = 0; i < 16; i++) {
492      add(m.m[i]);
493      }
494      }
495
496      void add(rs_matrix3x3 m) {
497      for (size_t i = 0; i < 9; i++) {
498      add(m.m[i]);
499      }
500      }
501
502      void add(rs_matrix2x2 m) {
503      for (size_t i = 0; i < 4; i++) {
504      add(m.m[i]);
505      }
506      }
507    */
508
509    void add(sp<BaseObj> obj) {
510        if (obj != NULL) {
511            add((uint32_t) (uintptr_t) obj->getID());
512        } else {
513            add((uint32_t) 0);
514        }
515    }
516};
517
518
519class 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
570    static sp<const Type> create(sp<RS> rs, sp<const Element> e, uint32_t dimX, uint32_t dimY, uint32_t dimZ);
571
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
660class ScriptIntrinsic : public Script {
661 protected:
662    ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e);
663    virtual ~ScriptIntrinsic();
664};
665
666class 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
673class ScriptIntrinsicBlend : public ScriptIntrinsic {
674 public:
675    ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e);
676    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};
692
693class ScriptIntrinsicBlur : public ScriptIntrinsic {
694 public:
695    ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e);
696    void blur(sp<Allocation> in, sp<Allocation> out);
697    void setRadius(float radius);
698};
699
700class 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
727class 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
743 public:
744    ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e);
745    void forEach(sp<Allocation> ain, sp<Allocation> aout);
746    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
753class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic {
754 public:
755    ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e);
756    void setInput(sp<Allocation> in);
757    void forEach(sp<Allocation> out);
758
759};
760
761
762 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
793}
794
795}
796
797#endif
798