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