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