blob: 671fbe6746f4d2c89efda6fbd78c76bd376339c8 [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
2 * Copyright (C) 2009 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_RS_SCRIPT_H
18#define ANDROID_RS_SCRIPT_H
19
20#include "rsAllocation.h"
21
Jason Samsa0a1b6f2009-06-10 15:04:38 -070022
Jason Sams326e0dd2009-05-22 14:03:28 -070023// ---------------------------------------------------------------------------
24namespace android {
25namespace renderscript {
26
Jason Samsa0a1b6f2009-06-10 15:04:38 -070027class ProgramVertex;
28class ProgramFragment;
29class ProgramRaster;
Jason Samsccc010b2010-05-13 18:30:11 -070030class ProgramStore;
Jason Sams326e0dd2009-05-22 14:03:28 -070031
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080032class Script : public ObjectBase {
Jason Sams326e0dd2009-05-22 14:03:28 -070033public:
Jason Samsbad80742011-03-16 16:29:28 -070034 struct Hal {
35 void * drv;
36
37 struct State {
38 ObjectBaseRef<const Type> type;
39 void * mallocPtr;
40
41 uint32_t usageFlags;
42 RsAllocationMipmapControl mipmapControl;
43
44 // Cached fields from the Type and Element
45 // to prevent pointer chasing in critical loops.
46 uint32_t dimensionX;
47 uint32_t dimensionY;
48 uint32_t dimensionZ;
49 uint32_t elementSizeBytes;
50 bool hasMipmaps;
51 bool hasFaces;
52 bool hasReferences;
53 };
54 State state;
55
56 struct DriverInfo {
57 int mVersionMajor;
58 int mVersionMinor;
59
60 size_t exportedVariableCount;
61 size_t exportedFunctionCount;
62 size_t exportedPragmaCount;
63 char const **exportedPragmaKeyList;
64 char const **exportedPragmaValueList;
65
66 int (* root)();
67 bool isThreadable;
68 };
69 DriverInfo info;
70 };
71 Hal mHal;
72
Jason Sams8c6bc692009-09-16 15:04:38 -070073 typedef void (* InvokeFunc_t)(void);
Jason Sams326e0dd2009-05-22 14:03:28 -070074
Jason Samse514b452009-09-25 14:51:22 -070075 Script(Context *);
Jason Sams326e0dd2009-05-22 14:03:28 -070076 virtual ~Script();
77
Jason Sams928b7342009-06-08 18:50:13 -070078 struct Enviroment_t {
Jason Samsef5867a2010-07-28 11:17:53 -070079 int64_t mStartTimeMillis;
80 int64_t mLastDtTime;
Romain Guy98e10fd2009-07-30 18:45:01 -070081 const char* mTimeZone;
82
Jason Samsa0a1b6f2009-06-10 15:04:38 -070083 ObjectBaseRef<ProgramVertex> mVertex;
84 ObjectBaseRef<ProgramFragment> mFragment;
Jason Samsb681c8a2009-09-28 18:12:56 -070085 ObjectBaseRef<ProgramRaster> mRaster;
Jason Samsccc010b2010-05-13 18:30:11 -070086 ObjectBaseRef<ProgramStore> mFragmentStore;
Jason Sams928b7342009-06-08 18:50:13 -070087 };
88 Enviroment_t mEnviroment;
Jason Sams326e0dd2009-05-22 14:03:28 -070089
Alex Sakhartchouk700ba382010-10-08 15:00:05 -070090 void initSlots();
91 void setSlot(uint32_t slot, Allocation *a);
Jason Samsbe36bf32010-05-11 14:03:58 -070092 void setVar(uint32_t slot, const void *val, uint32_t len);
Jason Samsa5eb6e12010-11-16 17:37:02 -080093 void setVarObj(uint32_t slot, ObjectBase *val);
Jason Sams8c6bc692009-09-16 15:04:38 -070094
Jason Samsace3e012010-07-15 17:11:13 -070095 virtual void runForEach(Context *rsc,
96 const Allocation * ain,
97 Allocation * aout,
98 const void * usr,
99 const RsScriptCall *sc = NULL) = 0;
Jason Samsc61346b2010-05-28 18:23:22 -0700100
Jason Sams22fa3712010-05-19 17:22:57 -0700101 virtual void Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len) = 0;
Jason Samsc61346b2010-05-28 18:23:22 -0700102 virtual void setupScript(Context *rsc) = 0;
103 virtual uint32_t run(Context *) = 0;
Alex Sakhartchouk700ba382010-10-08 15:00:05 -0700104protected:
105 ObjectBaseRef<Allocation> *mSlots;
106 ObjectBaseRef<const Type> *mTypes;
107
Jason Sams326e0dd2009-05-22 14:03:28 -0700108};
109
110
Jason Sams326e0dd2009-05-22 14:03:28 -0700111}
112}
113#endif
114