rsCppStructs.h revision 84e3dea053bea25c1cec44ffb298f8b5b9b9141a
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 "util/RefBase.h"
22#include "rsDispatch.h"
23
24#include <vector>
25#include <string>
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 enum RSError {
47     RS_SUCCESS = 0,
48     RS_ERROR_INVALID_PARAMETER = 1,
49     RS_ERROR_RUNTIME_ERROR = 2,
50     RS_ERROR_INVALID_ELEMENT = 3,
51     RS_ERROR_MAX = 9999
52
53 };
54
55 enum RSYuvFormat {
56     RS_YUV_NONE = 0,
57     RS_YUV_YV12 = 1,
58     RS_YUV_NV21 = 2,
59     RS_YUV_MAX = 3
60 };
61
62 enum RSInitFlags {
63     RS_INIT_SYNCHRONOUS = 1,
64     RS_INIT_LOW_LATENCY = 2,
65     RS_INIT_MAX = 4
66 };
67
68
69 class RS : public android::RSC::LightRefBase<RS> {
70
71 public:
72    RS();
73    virtual ~RS();
74
75    bool init(uint32_t flags);
76
77    void setErrorHandler(ErrorHandlerFunc_t func);
78    ErrorHandlerFunc_t getErrorHandler() { return mErrorFunc; }
79
80    void setMessageHandler(MessageHandlerFunc_t func);
81    MessageHandlerFunc_t getMessageHandler() { return mMessageFunc; }
82
83    void throwError(RSError error, const char *errMsg);
84    RSError getError();
85
86    RsContext getContext() { return mContext; }
87
88    void finish();
89
90    static dispatchTable* dispatch;
91
92 private:
93    static bool usingNative;
94    static bool initDispatch(int targetApi);
95
96    bool init(int targetApi, uint32_t flags);
97    static void * threadProc(void *);
98
99    static bool gInitialized;
100    static pthread_mutex_t gInitMutex;
101
102    pthread_t mMessageThreadId;
103    pid_t mNativeMessageThreadId;
104    bool mMessageRun;
105
106    RsDevice mDev;
107    RsContext mContext;
108    RSError mCurrentError;
109
110    ErrorHandlerFunc_t mErrorFunc;
111    MessageHandlerFunc_t mMessageFunc;
112    bool mInit;
113
114    struct {
115        sp<const Element> U8;
116        sp<const Element> U8_2;
117        sp<const Element> U8_3;
118        sp<const Element> U8_4;
119        sp<const Element> I8;
120        sp<const Element> I8_2;
121        sp<const Element> I8_3;
122        sp<const Element> I8_4;
123        sp<const Element> U16;
124        sp<const Element> U16_2;
125        sp<const Element> U16_3;
126        sp<const Element> U16_4;
127        sp<const Element> I16;
128        sp<const Element> I16_2;
129        sp<const Element> I16_3;
130        sp<const Element> I16_4;
131        sp<const Element> U32;
132        sp<const Element> U32_2;
133        sp<const Element> U32_3;
134        sp<const Element> U32_4;
135        sp<const Element> I32;
136        sp<const Element> I32_2;
137        sp<const Element> I32_3;
138        sp<const Element> I32_4;
139        sp<const Element> U64;
140        sp<const Element> U64_2;
141        sp<const Element> U64_3;
142        sp<const Element> U64_4;
143        sp<const Element> I64;
144        sp<const Element> I64_2;
145        sp<const Element> I64_3;
146        sp<const Element> I64_4;
147        sp<const Element> F32;
148        sp<const Element> F32_2;
149        sp<const Element> F32_3;
150        sp<const Element> F32_4;
151        sp<const Element> F64;
152        sp<const Element> F64_2;
153        sp<const Element> F64_3;
154        sp<const Element> F64_4;
155        sp<const Element> BOOLEAN;
156
157        sp<const Element> ELEMENT;
158        sp<const Element> TYPE;
159        sp<const Element> ALLOCATION;
160        sp<const Element> SAMPLER;
161        sp<const Element> SCRIPT;
162        sp<const Element> MESH;
163        sp<const Element> PROGRAM_FRAGMENT;
164        sp<const Element> PROGRAM_VERTEX;
165        sp<const Element> PROGRAM_RASTER;
166        sp<const Element> PROGRAM_STORE;
167
168        sp<const Element> A_8;
169        sp<const Element> RGB_565;
170        sp<const Element> RGB_888;
171        sp<const Element> RGBA_5551;
172        sp<const Element> RGBA_4444;
173        sp<const Element> RGBA_8888;
174
175        sp<const Element> YUV;
176
177        sp<const Element> MATRIX_4X4;
178        sp<const Element> MATRIX_3X3;
179        sp<const Element> MATRIX_2X2;
180    } mElements;
181
182    struct {
183        sp<const Sampler> CLAMP_NEAREST;
184        sp<const Sampler> CLAMP_LINEAR;
185        sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR;
186        sp<const Sampler> WRAP_NEAREST;
187        sp<const Sampler> WRAP_LINEAR;
188        sp<const Sampler> WRAP_LINEAR_MIP_LINEAR;
189        sp<const Sampler> MIRRORED_REPEAT_NEAREST;
190        sp<const Sampler> MIRRORED_REPEAT_LINEAR;
191        sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR;
192    } mSamplers;
193    friend class Sampler;
194    friend class Element;
195};
196
197class BaseObj : public android::RSC::LightRefBase<BaseObj> {
198public:
199    void * getID() const;
200    virtual ~BaseObj();
201    virtual void updateFromNative();
202    virtual bool equals(sp<const BaseObj> obj);
203
204protected:
205    void *mID;
206    sp<RS> mRS;
207    std::string mName;
208
209    BaseObj(void *id, sp<RS> rs);
210    void checkValid();
211
212    static void * getObjID(sp<const BaseObj> o);
213
214};
215
216
217class Allocation : public BaseObj {
218protected:
219    sp<const Type> mType;
220    uint32_t mUsage;
221    sp<Allocation> mAdaptedAllocation;
222
223    bool mConstrainedLOD;
224    bool mConstrainedFace;
225    bool mConstrainedY;
226    bool mConstrainedZ;
227    bool mReadAllowed;
228    bool mWriteAllowed;
229    uint32_t mSelectedY;
230    uint32_t mSelectedZ;
231    uint32_t mSelectedLOD;
232    RsAllocationCubemapFace mSelectedFace;
233
234    uint32_t mCurrentDimX;
235    uint32_t mCurrentDimY;
236    uint32_t mCurrentDimZ;
237    uint32_t mCurrentCount;
238
239    void * getIDSafe() const;
240    void updateCacheInfo(sp<const Type> t);
241
242    Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage);
243
244    void validateIsInt32();
245    void validateIsInt16();
246    void validateIsInt8();
247    void validateIsFloat32();
248    void validateIsObject();
249
250    virtual void updateFromNative();
251
252    void validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h);
253    void validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff,
254                         uint32_t w, uint32_t h, uint32_t d);
255
256public:
257    sp<const Type> getType() const {
258        return mType;
259    }
260
261    void syncAll(RsAllocationUsageType srcLocation);
262    void ioSendOutput();
263    void ioGetInput();
264
265    void generateMipmaps();
266
267    void copy1DRangeFrom(uint32_t off, size_t count, const void *data);
268    void copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, uint32_t dataOff);
269
270    void copy1DRangeTo(uint32_t off, size_t count, void *data);
271
272    void copy1DFrom(const void* data);
273    void copy1DTo(void* data);
274
275    void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
276                         const void *data);
277
278    void copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
279                       void *data);
280
281    void copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
282                         sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff);
283
284    void copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
285                           const void *data, size_t stride);
286    void copy2DStridedFrom(const void *data, size_t stride);
287
288    void copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h,
289                         void *data, size_t stride);
290    void copy2DStridedTo(void *data, size_t stride);
291
292    void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w,
293                         uint32_t h, uint32_t d, const void* data);
294
295    void copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff,
296                         uint32_t w, uint32_t h, uint32_t d,
297                         sp<const Allocation> data,
298                         uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff);
299
300    static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
301                                   RsAllocationMipmapControl mips, uint32_t usage);
302    static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
303                                   RsAllocationMipmapControl mips, uint32_t usage, void * pointer);
304
305    static sp<Allocation> createTyped(sp<RS> rs, sp<const Type> type,
306                                   uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
307    static sp<Allocation> createSized(sp<RS> rs, sp<const Element> e, size_t count,
308                                   uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
309    static sp<Allocation> createSized2D(sp<RS> rs, sp<const Element> e,
310                                        size_t x, size_t y,
311                                        uint32_t usage = RS_ALLOCATION_USAGE_SCRIPT);
312
313
314};
315
316class Element : public BaseObj {
317public:
318    bool isComplex();
319    size_t getSubElementCount() {
320        return mVisibleElementMap.size();
321    }
322
323    sp<const Element> getSubElement(uint32_t index);
324    const char * getSubElementName(uint32_t index);
325    size_t getSubElementArraySize(uint32_t index);
326    uint32_t getSubElementOffsetBytes(uint32_t index);
327    RsDataType getDataType() const {
328        return mType;
329    }
330
331    RsDataKind getDataKind() const {
332        return mKind;
333    }
334
335    size_t getSizeBytes() const {
336        return mSizeBytes;
337    }
338
339    uint32_t getVectorSize() const {
340        return mVectorSize;
341    }
342
343    static sp<const Element> BOOLEAN(sp<RS> rs);
344    static sp<const Element> U8(sp<RS> rs);
345    static sp<const Element> I8(sp<RS> rs);
346    static sp<const Element> U16(sp<RS> rs);
347    static sp<const Element> I16(sp<RS> rs);
348    static sp<const Element> U32(sp<RS> rs);
349    static sp<const Element> I32(sp<RS> rs);
350    static sp<const Element> U64(sp<RS> rs);
351    static sp<const Element> I64(sp<RS> rs);
352    static sp<const Element> F32(sp<RS> rs);
353    static sp<const Element> F64(sp<RS> rs);
354    static sp<const Element> ELEMENT(sp<RS> rs);
355    static sp<const Element> TYPE(sp<RS> rs);
356    static sp<const Element> ALLOCATION(sp<RS> rs);
357    static sp<const Element> SAMPLER(sp<RS> rs);
358    static sp<const Element> SCRIPT(sp<RS> rs);
359    static sp<const Element> MESH(sp<RS> rs);
360    static sp<const Element> PROGRAM_FRAGMENT(sp<RS> rs);
361    static sp<const Element> PROGRAM_VERTEX(sp<RS> rs);
362    static sp<const Element> PROGRAM_RASTER(sp<RS> rs);
363    static sp<const Element> PROGRAM_STORE(sp<RS> rs);
364
365    static sp<const Element> A_8(sp<RS> rs);
366    static sp<const Element> RGB_565(sp<RS> rs);
367    static sp<const Element> RGB_888(sp<RS> rs);
368    static sp<const Element> RGBA_5551(sp<RS> rs);
369    static sp<const Element> RGBA_4444(sp<RS> rs);
370    static sp<const Element> RGBA_8888(sp<RS> rs);
371
372    static sp<const Element> F32_2(sp<RS> rs);
373    static sp<const Element> F32_3(sp<RS> rs);
374    static sp<const Element> F32_4(sp<RS> rs);
375    static sp<const Element> F64_2(sp<RS> rs);
376    static sp<const Element> F64_3(sp<RS> rs);
377    static sp<const Element> F64_4(sp<RS> rs);
378    static sp<const Element> U8_2(sp<RS> rs);
379    static sp<const Element> U8_3(sp<RS> rs);
380    static sp<const Element> U8_4(sp<RS> rs);
381    static sp<const Element> I8_2(sp<RS> rs);
382    static sp<const Element> I8_3(sp<RS> rs);
383    static sp<const Element> I8_4(sp<RS> rs);
384    static sp<const Element> U16_2(sp<RS> rs);
385    static sp<const Element> U16_3(sp<RS> rs);
386    static sp<const Element> U16_4(sp<RS> rs);
387    static sp<const Element> I16_2(sp<RS> rs);
388    static sp<const Element> I16_3(sp<RS> rs);
389    static sp<const Element> I16_4(sp<RS> rs);
390    static sp<const Element> U32_2(sp<RS> rs);
391    static sp<const Element> U32_3(sp<RS> rs);
392    static sp<const Element> U32_4(sp<RS> rs);
393    static sp<const Element> I32_2(sp<RS> rs);
394    static sp<const Element> I32_3(sp<RS> rs);
395    static sp<const Element> I32_4(sp<RS> rs);
396    static sp<const Element> U64_2(sp<RS> rs);
397    static sp<const Element> U64_3(sp<RS> rs);
398    static sp<const Element> U64_4(sp<RS> rs);
399    static sp<const Element> I64_2(sp<RS> rs);
400    static sp<const Element> I64_3(sp<RS> rs);
401    static sp<const Element> I64_4(sp<RS> rs);
402    static sp<const Element> YUV(sp<RS> rs);
403    static sp<const Element> MATRIX_4X4(sp<RS> rs);
404    static sp<const Element> MATRIX_3X3(sp<RS> rs);
405    static sp<const Element> MATRIX_2X2(sp<RS> rs);
406
407    void updateFromNative();
408    static sp<const Element> createUser(sp<RS> rs, RsDataType dt);
409    static sp<const Element> createVector(sp<RS> rs, RsDataType dt, uint32_t size);
410    static sp<const Element> createPixel(sp<RS> rs, RsDataType dt, RsDataKind dk);
411    bool isCompatible(sp<const Element>e) const;
412
413    class Builder {
414    private:
415        sp<RS> mRS;
416        std::vector<sp<Element> > mElements;
417        std::vector<std::string> mElementNames;
418        std::vector<uint32_t> mArraySizes;
419        bool mSkipPadding;
420
421    public:
422        Builder(sp<RS> rs);
423        ~Builder();
424        void add(sp<Element> e, std::string &name, uint32_t arraySize = 1);
425        sp<const Element> create();
426    };
427
428protected:
429    Element(void *id, sp<RS> rs,
430            std::vector<sp<Element> > &elements,
431            std::vector<std::string> &elementNames,
432            std::vector<uint32_t> &arraySizes);
433    Element(void *id, sp<RS> rs, RsDataType dt, RsDataKind dk, bool norm, uint32_t size);
434    Element(sp<RS> rs);
435    virtual ~Element();
436
437private:
438    void updateVisibleSubElements();
439
440    std::vector<sp<Element> > mElements;
441    std::vector<std::string> mElementNames;
442    std::vector<uint32_t> mArraySizes;
443    std::vector<uint32_t> mVisibleElementMap;
444    std::vector<uint32_t> mOffsetInBytes;
445
446    RsDataType mType;
447    RsDataKind mKind;
448    bool mNormalized;
449    size_t mSizeBytes;
450    size_t mVectorSize;
451};
452
453class FieldPacker {
454protected:
455    unsigned char* mData;
456    size_t mPos;
457    size_t mLen;
458
459public:
460    FieldPacker(size_t len)
461        : mPos(0), mLen(len) {
462            mData = new unsigned char[len];
463        }
464
465    virtual ~FieldPacker() {
466        delete [] mData;
467    }
468
469    void align(size_t v) {
470        if ((v & (v - 1)) != 0) {
471            //            ALOGE("Non-power-of-two alignment: %zu", v);
472            return;
473        }
474
475        while ((mPos & (v - 1)) != 0) {
476            mData[mPos++] = 0;
477        }
478    }
479
480    void reset() {
481        mPos = 0;
482    }
483
484    void reset(size_t i) {
485        if (i >= mLen) {
486            //            ALOGE("Out of bounds: i (%zu) >= len (%zu)", i, mLen);
487            return;
488        }
489        mPos = i;
490    }
491
492    void skip(size_t i) {
493        size_t res = mPos + i;
494        if (res > mLen) {
495            //            ALOGE("Exceeded buffer length: i (%zu) > len (%zu)", i, mLen);
496            return;
497        }
498        mPos = res;
499    }
500
501    void* getData() const {
502        return mData;
503    }
504
505    size_t getLength() const {
506        return mLen;
507    }
508
509    template <typename T>
510        void add(T t) {
511        align(sizeof(t));
512        if (mPos + sizeof(t) <= mLen) {
513            memcpy(&mData[mPos], &t, sizeof(t));
514            mPos += sizeof(t);
515        }
516    }
517
518    /*
519      void add(rs_matrix4x4 m) {
520      for (size_t i = 0; i < 16; i++) {
521      add(m.m[i]);
522      }
523      }
524
525      void add(rs_matrix3x3 m) {
526      for (size_t i = 0; i < 9; i++) {
527      add(m.m[i]);
528      }
529      }
530
531      void add(rs_matrix2x2 m) {
532      for (size_t i = 0; i < 4; i++) {
533      add(m.m[i]);
534      }
535      }
536    */
537
538    void add(sp<BaseObj> obj) {
539        if (obj != NULL) {
540            add((uint32_t) (uintptr_t) obj->getID());
541        } else {
542            add((uint32_t) 0);
543        }
544    }
545};
546
547
548class Type : public BaseObj {
549protected:
550    friend class Allocation;
551
552    uint32_t mDimX;
553    uint32_t mDimY;
554    uint32_t mDimZ;
555    RSYuvFormat mYuvFormat;
556    bool mDimMipmaps;
557    bool mDimFaces;
558    size_t mElementCount;
559    sp<const Element> mElement;
560
561    Type(void *id, sp<RS> rs);
562
563    void calcElementCount();
564    virtual void updateFromNative();
565
566public:
567
568    RSYuvFormat getYuvFormat() const {
569        return mYuvFormat;
570    }
571
572    sp<const Element> getElement() const {
573        return mElement;
574    }
575
576    uint32_t getX() const {
577        return mDimX;
578    }
579
580    uint32_t getY() const {
581        return mDimY;
582    }
583
584    uint32_t getZ() const {
585        return mDimZ;
586    }
587
588    bool hasMipmaps() const {
589        return mDimMipmaps;
590    }
591
592    bool hasFaces() const {
593        return mDimFaces;
594    }
595
596    size_t getCount() const {
597        return mElementCount;
598    }
599
600    size_t getSizeBytes() const {
601        return mElementCount * mElement->getSizeBytes();
602    }
603
604    static sp<const Type> create(sp<RS> rs, sp<const Element> e, uint32_t dimX, uint32_t dimY, uint32_t dimZ);
605
606    class Builder {
607    protected:
608        sp<RS> mRS;
609        uint32_t mDimX;
610        uint32_t mDimY;
611        uint32_t mDimZ;
612        RSYuvFormat mYuvFormat;
613        bool mDimMipmaps;
614        bool mDimFaces;
615        sp<const Element> mElement;
616
617    public:
618        Builder(sp<RS> rs, sp<const Element> e);
619
620        void setX(uint32_t value);
621        void setY(uint32_t value);
622        void setZ(uint32_t value);
623        void setYuvFormat(RSYuvFormat format);
624        void setMipmaps(bool value);
625        void setFaces(bool value);
626        sp<const Type> create();
627    };
628
629};
630
631class Script : public BaseObj {
632private:
633
634protected:
635    Script(void *id, sp<RS> rs);
636    void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out,
637            const void *v, size_t) const;
638    void bindAllocation(sp<Allocation> va, uint32_t slot) const;
639    void setVar(uint32_t index, const void *, size_t len) const;
640    void setVar(uint32_t index, sp<const BaseObj> o) const;
641    void invoke(uint32_t slot, const void *v, size_t len) const;
642
643
644    void invoke(uint32_t slot) const {
645        invoke(slot, NULL, 0);
646    }
647    void setVar(uint32_t index, float v) const {
648        setVar(index, &v, sizeof(v));
649    }
650    void setVar(uint32_t index, double v) const {
651        setVar(index, &v, sizeof(v));
652    }
653    void setVar(uint32_t index, int32_t v) const {
654        setVar(index, &v, sizeof(v));
655    }
656    void setVar(uint32_t index, int64_t v) const {
657        setVar(index, &v, sizeof(v));
658    }
659    void setVar(uint32_t index, bool v) const {
660        setVar(index, &v, sizeof(v));
661    }
662
663public:
664    class FieldBase {
665    protected:
666        sp<const Element> mElement;
667        sp<Allocation> mAllocation;
668
669        void init(sp<RS> rs, uint32_t dimx, uint32_t usages = 0);
670
671    public:
672        sp<const Element> getElement() {
673            return mElement;
674        }
675
676        sp<const Type> getType() {
677            return mAllocation->getType();
678        }
679
680        sp<const Allocation> getAllocation() {
681            return mAllocation;
682        }
683
684        //void updateAllocation();
685    };
686};
687
688class ScriptC : public Script {
689protected:
690    ScriptC(sp<RS> rs,
691            const void *codeTxt, size_t codeLength,
692            const char *cachedName, size_t cachedNameLength,
693            const char *cacheDir, size_t cacheDirLength);
694
695};
696
697class ScriptIntrinsic : public Script {
698 protected:
699    sp<const Element> mElement;
700    ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e);
701    virtual ~ScriptIntrinsic();
702};
703
704class ScriptIntrinsic3DLUT : public ScriptIntrinsic {
705 private:
706    ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e);
707 public:
708    static sp<ScriptIntrinsic3DLUT> create(sp<RS> rs, sp<const Element> e);
709    void forEach(sp<Allocation> ain, sp<Allocation> aout);
710    void setLUT(sp<Allocation> lut);
711};
712
713class ScriptIntrinsicBlend : public ScriptIntrinsic {
714 private:
715    ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e);
716 public:
717    static sp<ScriptIntrinsicBlend> create(sp<RS> rs, sp<const Element> e);
718    void blendClear(sp<Allocation> in, sp<Allocation> out);
719    void blendSrc(sp<Allocation> in, sp<Allocation> out);
720    void blendDst(sp<Allocation> in, sp<Allocation> out);
721    void blendSrcOver(sp<Allocation> in, sp<Allocation> out);
722    void blendDstOver(sp<Allocation> in, sp<Allocation> out);
723    void blendSrcIn(sp<Allocation> in, sp<Allocation> out);
724    void blendDstIn(sp<Allocation> in, sp<Allocation> out);
725    void blendSrcOut(sp<Allocation> in, sp<Allocation> out);
726    void blendDstOut(sp<Allocation> in, sp<Allocation> out);
727    void blendSrcAtop(sp<Allocation> in, sp<Allocation> out);
728    void blendDstAtop(sp<Allocation> in, sp<Allocation> out);
729    void blendXor(sp<Allocation> in, sp<Allocation> out);
730    void blendMultiply(sp<Allocation> in, sp<Allocation> out);
731    void blendAdd(sp<Allocation> in, sp<Allocation> out);
732    void blendSubtract(sp<Allocation> in, sp<Allocation> out);
733};
734
735class ScriptIntrinsicBlur : public ScriptIntrinsic {
736 private:
737    ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e);
738 public:
739    static sp<ScriptIntrinsicBlur> create(sp<RS> rs, sp<const Element> e);
740    void setInput(sp<Allocation> in);
741    void forEach(sp<Allocation> out);
742    void setRadius(float radius);
743};
744
745class ScriptIntrinsicColorMatrix : public ScriptIntrinsic {
746 private:
747    ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e);
748 public:
749    static sp<ScriptIntrinsicColorMatrix> create(sp<RS> rs);
750    void forEach(sp<Allocation> in, sp<Allocation> out);
751    void setAdd(float* add);
752    void setColorMatrix3(float* m);
753    void setColorMatrix4(float* m);
754    void setGreyscale();
755    void setRGBtoYUV();
756    void setYUVtoRGB();
757};
758
759class ScriptIntrinsicConvolve3x3 : public ScriptIntrinsic {
760 private:
761    ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e);
762 public:
763    static sp<ScriptIntrinsicConvolve3x3> create(sp<RS> rs, sp<const Element> e);
764    void setInput(sp<Allocation> in);
765    void forEach(sp<Allocation> out);
766    void setCoefficients(float* v);
767};
768
769class ScriptIntrinsicConvolve5x5 : public ScriptIntrinsic {
770 private:
771    ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e);
772 public:
773    static sp<ScriptIntrinsicConvolve5x5> create(sp<RS> rs, sp<const Element> e);
774    void setInput(sp<Allocation> in);
775    void forEach(sp<Allocation> out);
776    void setCoefficients(float* v);
777};
778
779class ScriptIntrinsicHistogram : public ScriptIntrinsic {
780 private:
781    ScriptIntrinsicHistogram(sp<RS> rs, sp<const Element> e);
782    sp<Allocation> mOut;
783 public:
784    static sp<ScriptIntrinsicHistogram> create(sp<RS> rs);
785    void setOutput(sp<Allocation> aout);
786    void setDotCoefficients(float r, float g, float b, float a);
787    void forEach(sp<Allocation> ain);
788    void forEach_dot(sp<Allocation> ain);
789};
790
791class ScriptIntrinsicLUT : public ScriptIntrinsic {
792 private:
793    sp<Allocation> LUT;
794    bool mDirty;
795    unsigned char mCache[1024];
796    void setTable(unsigned int offset, unsigned char base, unsigned int length, unsigned char* lutValues);
797    ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e);
798
799 public:
800    static sp<ScriptIntrinsicLUT> create(sp<RS> rs, sp<const Element> e);
801    void forEach(sp<Allocation> ain, sp<Allocation> aout);
802    void setRed(unsigned char base, unsigned int length, unsigned char* lutValues);
803    void setGreen(unsigned char base, unsigned int length, unsigned char* lutValues);
804    void setBlue(unsigned char base, unsigned int length, unsigned char* lutValues);
805    void setAlpha(unsigned char base, unsigned int length, unsigned char* lutValues);
806    virtual ~ScriptIntrinsicLUT();
807};
808
809class ScriptIntrinsicYuvToRGB : public ScriptIntrinsic {
810 private:
811    ScriptIntrinsicYuvToRGB(sp<RS> rs, sp<const Element> e);
812 public:
813    static sp<ScriptIntrinsicYuvToRGB> create(sp<RS> rs, sp<const Element> e);
814    void setInput(sp<Allocation> in);
815    void forEach(sp<Allocation> out);
816
817};
818
819
820 class Sampler : public BaseObj {
821 private:
822    Sampler(sp<RS> rs, void* id);
823    RsSamplerValue mMin;
824    RsSamplerValue mMag;
825    RsSamplerValue mWrapS;
826    RsSamplerValue mWrapT;
827    RsSamplerValue mWrapR;
828    float mAniso;
829
830 public:
831    static sp<Sampler> create(sp<RS> rs, RsSamplerValue min, RsSamplerValue mag, RsSamplerValue wrapS, RsSamplerValue wrapT, float anisotropy);
832
833    RsSamplerValue getMinification();
834    RsSamplerValue getMagnification();
835    RsSamplerValue getWrapS();
836    RsSamplerValue getWrapT();
837    float getAnisotropy();
838
839    sp<const Sampler> CLAMP_NEAREST(sp<RS> rs);
840    sp<const Sampler> CLAMP_LINEAR(sp<RS> rs);
841    sp<const Sampler> CLAMP_LINEAR_MIP_LINEAR(sp<RS> rs);
842    sp<const Sampler> WRAP_NEAREST(sp<RS> rs);
843    sp<const Sampler> WRAP_LINEAR(sp<RS> rs);
844    sp<const Sampler> WRAP_LINEAR_MIP_LINEAR(sp<RS> rs);
845    sp<const Sampler> MIRRORED_REPEAT_NEAREST(sp<RS> rs);
846    sp<const Sampler> MIRRORED_REPEAT_LINEAR(sp<RS> rs);
847    sp<const Sampler> MIRRORED_REPEAT_LINEAR_MIP_LINEAR(sp<RS> rs);
848
849};
850
851class Byte2 {
852 public:
853  int8_t x, y;
854
855  Byte2(int8_t initX, int8_t initY)
856    : x(initX), y(initY) {}
857  Byte2() : x(0), y(0) {}
858};
859
860class Byte3 {
861 public:
862  int8_t x, y, z;
863
864  Byte3(int8_t initX, int8_t initY, int8_t initZ)
865    : x(initX), y(initY), z(initZ) {}
866  Byte3() : x(0), y(0), z(0) {}
867};
868
869class Byte4 {
870 public:
871  int8_t x, y, z, w;
872
873  Byte4(int8_t initX, int8_t initY, int8_t initZ, int8_t initW)
874    : x(initX), y(initY), z(initZ), w(initW) {}
875  Byte4() : x(0), y(0), z(0), w(0) {}
876};
877
878class UByte2 {
879 public:
880  uint8_t x, y;
881
882  UByte2(uint8_t initX, uint8_t initY)
883    : x(initX), y(initY) {}
884  UByte2() : x(0), y(0) {}
885};
886
887class UByte3 {
888 public:
889  uint8_t x, y, z;
890
891  UByte3(uint8_t initX, uint8_t initY, uint8_t initZ)
892    : x(initX), y(initY), z(initZ) {}
893  UByte3() : x(0), y(0), z(0) {}
894};
895
896class UByte4 {
897 public:
898  uint8_t x, y, z, w;
899
900  UByte4(uint8_t initX, uint8_t initY, uint8_t initZ, uint8_t initW)
901    : x(initX), y(initY), z(initZ), w(initW) {}
902  UByte4() : x(0), y(0), z(0), w(0) {}
903};
904
905class Short2 {
906 public:
907  short x, y;
908
909  Short2(short initX, short initY)
910    : x(initX), y(initY) {}
911  Short2() : x(0), y(0) {}
912};
913
914class Short3 {
915 public:
916  short x, y, z;
917
918  Short3(short initX, short initY, short initZ)
919    : x(initX), y(initY), z(initZ) {}
920  Short3() : x(0), y(0), z(0) {}
921};
922
923class Short4 {
924 public:
925  short x, y, z, w;
926
927  Short4(short initX, short initY, short initZ, short initW)
928    : x(initX), y(initY), z(initZ), w(initW) {}
929  Short4() : x(0), y(0), z(0), w(0) {}
930};
931
932class UShort2 {
933 public:
934  uint16_t x, y;
935
936  UShort2(uint16_t initX, uint16_t initY)
937    : x(initX), y(initY) {}
938  UShort2() : x(0), y(0) {}
939};
940
941class UShort3 {
942 public:
943  uint16_t x, y, z;
944
945  UShort3(uint16_t initX, uint16_t initY, uint16_t initZ)
946    : x(initX), y(initY), z(initZ) {}
947  UShort3() : x(0), y(0), z(0) {}
948};
949
950class UShort4 {
951 public:
952  uint16_t x, y, z, w;
953
954  UShort4(uint16_t initX, uint16_t initY, uint16_t initZ, uint16_t initW)
955    : x(initX), y(initY), z(initZ), w(initW) {}
956  UShort4() : x(0), y(0), z(0), w(0) {}
957};
958
959class Int2 {
960 public:
961  int x, y;
962
963  Int2(int initX, int initY)
964    : x(initX), y(initY) {}
965  Int2() : x(0), y(0) {}
966};
967
968class Int3 {
969 public:
970  int x, y, z;
971
972  Int3(int initX, int initY, int initZ)
973    : x(initX), y(initY), z(initZ) {}
974  Int3() : x(0), y(0), z(0) {}
975};
976
977class Int4 {
978 public:
979  int x, y, z, w;
980
981  Int4(int initX, int initY, int initZ, int initW)
982    : x(initX), y(initY), z(initZ), w(initW) {}
983  Int4() : x(0), y(0), z(0), w(0) {}
984};
985
986class UInt2 {
987 public:
988  uint32_t x, y;
989
990  UInt2(uint32_t initX, uint32_t initY)
991    : x(initX), y(initY) {}
992  UInt2() : x(0), y(0) {}
993};
994
995class UInt3 {
996 public:
997  uint32_t x, y, z;
998
999  UInt3(uint32_t initX, uint32_t initY, uint32_t initZ)
1000    : x(initX), y(initY), z(initZ) {}
1001  UInt3() : x(0), y(0), z(0) {}
1002};
1003
1004class UInt4 {
1005 public:
1006  uint32_t x, y, z, w;
1007
1008  UInt4(uint32_t initX, uint32_t initY, uint32_t initZ, uint32_t initW)
1009    : x(initX), y(initY), z(initZ), w(initW) {}
1010  UInt4() : x(0), y(0), z(0), w(0) {}
1011};
1012
1013class Long2 {
1014 public:
1015  int64_t x, y;
1016
1017  Long2(int64_t initX, int64_t initY)
1018    : x(initX), y(initY) {}
1019  Long2() : x(0), y(0) {}
1020};
1021
1022class Long3 {
1023 public:
1024  int64_t x, y, z;
1025
1026  Long3(int64_t initX, int64_t initY, int64_t initZ)
1027    : x(initX), y(initY), z(initZ) {}
1028  Long3() : x(0), y(0), z(0) {}
1029};
1030
1031class Long4 {
1032 public:
1033  int64_t x, y, z, w;
1034
1035  Long4(int64_t initX, int64_t initY, int64_t initZ, int64_t initW)
1036    : x(initX), y(initY), z(initZ), w(initW) {}
1037  Long4() : x(0), y(0), z(0), w(0) {}
1038};
1039
1040class ULong2 {
1041 public:
1042  uint64_t x, y;
1043
1044  ULong2(uint64_t initX, uint64_t initY)
1045    : x(initX), y(initY) {}
1046  ULong2() : x(0), y(0) {}
1047};
1048
1049class ULong3 {
1050 public:
1051  uint64_t x, y, z;
1052
1053  ULong3(uint64_t initX, uint64_t initY, uint64_t initZ)
1054    : x(initX), y(initY), z(initZ) {}
1055  ULong3() : x(0), y(0), z(0) {}
1056};
1057
1058class ULong4 {
1059 public:
1060  uint64_t x, y, z, w;
1061
1062  ULong4(uint64_t initX, uint64_t initY, uint64_t initZ, uint64_t initW)
1063    : x(initX), y(initY), z(initZ), w(initW) {}
1064  ULong4() : x(0), y(0), z(0), w(0) {}
1065};
1066
1067class Float2 {
1068 public:
1069  float x, y;
1070
1071  Float2(float initX, float initY)
1072    : x(initX), y(initY) {}
1073  Float2() : x(0), y(0) {}
1074};
1075
1076class Float3 {
1077 public:
1078  float x, y, z;
1079
1080  Float3(float initX, float initY, float initZ)
1081    : x(initX), y(initY), z(initZ) {}
1082  Float3() : x(0.f), y(0.f), z(0.f) {}
1083};
1084
1085class Float4 {
1086 public:
1087  float x, y, z, w;
1088
1089  Float4(float initX, float initY, float initZ, float initW)
1090    : x(initX), y(initY), z(initZ), w(initW) {}
1091  Float4() : x(0.f), y(0.f), z(0.f), w(0.f) {}
1092};
1093
1094class Double2 {
1095 public:
1096  double x, y;
1097
1098  Double2(double initX, double initY)
1099    : x(initX), y(initY) {}
1100  Double2() : x(0), y(0) {}
1101};
1102
1103class Double3 {
1104 public:
1105  double x, y, z;
1106
1107  Double3(double initX, double initY, double initZ)
1108    : x(initX), y(initY), z(initZ) {}
1109  Double3() : x(0), y(0), z(0) {}
1110};
1111
1112class Double4 {
1113 public:
1114  double x, y, z, w;
1115
1116  Double4(double initX, double initY, double initZ, double initW)
1117    : x(initX), y(initY), z(initZ), w(initW) {}
1118  Double4() : x(0), y(0), z(0), w(0) {}
1119};
1120
1121}
1122
1123}
1124
1125#endif
1126