RenderScript.h revision 221a4b17cda03916a0599628fcbb5f48605a0e5a
1221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams/*
2221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * Copyright (C) 2008-2012 The Android Open Source Project
3221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams *
4221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * Licensed under the Apache License, Version 2.0 (the "License");
5221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * you may not use this file except in compliance with the License.
6221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * You may obtain a copy of the License at
7221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams *
8221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams *      http://www.apache.org/licenses/LICENSE-2.0
9221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams *
10221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * Unless required by applicable law or agreed to in writing, software
11221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * distributed under the License is distributed on an "AS IS" BASIS,
12221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * See the License for the specific language governing permissions and
14221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams * limitations under the License.
15221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams */
16221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
17221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams#ifndef ANDROID_RENDERSCRIPT_H
18221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams#define ANDROID_RENDERSCRIPT_H
19221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
20221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
21221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams#include <pthread.h>
22221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams#include <utils/String8.h>
23221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams#include <utils/Vector.h>
24221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
25221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams#include "rs.h"
26221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
27221a4b17cda03916a0599628fcbb5f48605a0e5aJason Samsclass Element;
28221a4b17cda03916a0599628fcbb5f48605a0e5aJason Samsclass Type;
29221a4b17cda03916a0599628fcbb5f48605a0e5aJason Samsclass Allocation;
30221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
31221a4b17cda03916a0599628fcbb5f48605a0e5aJason Samsclass RenderScript {
32221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    friend class BaseObj;
33221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    friend class Allocation;
34221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    friend class Element;
35221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    friend class Type;
36221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
37221a4b17cda03916a0599628fcbb5f48605a0e5aJason Samspublic:
38221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    RenderScript();
39221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    virtual ~RenderScript();
40221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
41221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    typedef void (*ErrorHandlerFunc_t)(uint32_t errorNum, const char *errorText);
42221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    typedef void (*MessageHandlerFunc_t)(uint32_t msgNum, const void *msgData, size_t msgLen);
43221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
44221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
45221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    void setErrorHandler(ErrorHandlerFunc_t func);
46221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    ErrorHandlerFunc_t getErrorHandler() {return mErrorFunc;}
47221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
48221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    void setMessageHandler(MessageHandlerFunc_t func);
49221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    MessageHandlerFunc_t getMessageHandler() {return mMessageFunc;}
50221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
51221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    bool init(int targetApi);
52221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    void contextDump();
53221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    void finish();
54221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
55221a4b17cda03916a0599628fcbb5f48605a0e5aJason Samsprivate:
56221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    static bool gInitialized;
57221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    static pthread_mutex_t gInitMutex;
58221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
59221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    pthread_t mMessageThreadId;
60221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    pid_t mNativeMessageThreadId;
61221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    bool mMessageRun;
62221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
63221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    RsDevice mDev;
64221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    RsContext mContext;
65221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
66221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    ErrorHandlerFunc_t mErrorFunc;
67221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    MessageHandlerFunc_t mMessageFunc;
68221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
69221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    struct {
70221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *U8;
71221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *I8;
72221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *U16;
73221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *I16;
74221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *U32;
75221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *I32;
76221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *U64;
77221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *I64;
78221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *F32;
79221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *F64;
80221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *BOOLEAN;
81221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
82221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *ELEMENT;
83221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *TYPE;
84221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *ALLOCATION;
85221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *SAMPLER;
86221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *SCRIPT;
87221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *MESH;
88221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *PROGRAM_FRAGMENT;
89221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *PROGRAM_VERTEX;
90221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *PROGRAM_RASTER;
91221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *PROGRAM_STORE;
92221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
93221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *A_8;
94221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *RGB_565;
95221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *RGB_888;
96221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *RGBA_5551;
97221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *RGBA_4444;
98221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *RGBA_8888;
99221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
100221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *FLOAT_2;
101221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *FLOAT_3;
102221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *FLOAT_4;
103221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
104221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *DOUBLE_2;
105221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *DOUBLE_3;
106221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *DOUBLE_4;
107221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
108221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *UCHAR_2;
109221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *UCHAR_3;
110221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *UCHAR_4;
111221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
112221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *CHAR_2;
113221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *CHAR_3;
114221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *CHAR_4;
115221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
116221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *USHORT_2;
117221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *USHORT_3;
118221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *USHORT_4;
119221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
120221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *SHORT_2;
121221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *SHORT_3;
122221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *SHORT_4;
123221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
124221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *UINT_2;
125221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *UINT_3;
126221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *UINT_4;
127221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
128221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *INT_2;
129221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *INT_3;
130221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *INT_4;
131221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
132221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *ULONG_2;
133221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *ULONG_3;
134221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *ULONG_4;
135221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
136221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *LONG_2;
137221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *LONG_3;
138221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *LONG_4;
139221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
140221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *MATRIX_4X4;
141221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *MATRIX_3X3;
142221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams        Element *MATRIX_2X2;
143221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    } mElements;
144221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
145221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
146221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
147221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
148221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams    static void * threadProc(void *);
149221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
150221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams};
151221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
152221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams#endif
153221a4b17cda03916a0599628fcbb5f48605a0e5aJason Sams
154