Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008-2012 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_SCRIPT_H__ |
| 18 | #define __ANDROID_SCRIPT_H__ |
| 19 | |
| 20 | #include <pthread.h> |
| 21 | #include <rs.h> |
| 22 | |
| 23 | #include "RenderScript.h" |
| 24 | #include "Allocation.h" |
| 25 | |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 26 | namespace android { |
| 27 | namespace renderscriptCpp { |
| 28 | |
| 29 | |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 30 | class Type; |
| 31 | class Element; |
| 32 | class Allocation; |
| 33 | |
| 34 | class Script : public BaseObj { |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 35 | private: |
| 36 | |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 37 | protected: |
| 38 | Script(void *id, RenderScript *rs); |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 39 | void forEach(uint32_t slot, sp<const Allocation> in, sp<const Allocation> out, |
| 40 | const void *v, size_t) const; |
| 41 | void bindAllocation(sp<Allocation> va, uint32_t slot) const; |
Jason Sams | 1fc0201 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 42 | void setVar(uint32_t index, const void *, size_t len) const; |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 43 | void setVar(uint32_t index, sp<const BaseObj> o) const; |
Jason Sams | 1fc0201 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 44 | void invoke(uint32_t slot, const void *v, size_t len) const; |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 45 | |
| 46 | |
Jason Sams | 1fc0201 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 47 | void invoke(uint32_t slot) const { |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 48 | invoke(slot, NULL, 0); |
| 49 | } |
Jason Sams | 1fc0201 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 50 | void setVar(uint32_t index, float v) const { |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 51 | setVar(index, &v, sizeof(v)); |
| 52 | } |
Jason Sams | 1fc0201 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 53 | void setVar(uint32_t index, double v) const { |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 54 | setVar(index, &v, sizeof(v)); |
| 55 | } |
Jason Sams | 1fc0201 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 56 | void setVar(uint32_t index, int32_t v) const { |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 57 | setVar(index, &v, sizeof(v)); |
| 58 | } |
Jason Sams | 1fc0201 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 59 | void setVar(uint32_t index, int64_t v) const { |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 60 | setVar(index, &v, sizeof(v)); |
| 61 | } |
Jason Sams | 1fc0201 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 62 | void setVar(uint32_t index, bool v) const { |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 63 | setVar(index, &v, sizeof(v)); |
| 64 | } |
| 65 | |
| 66 | public: |
| 67 | class FieldBase { |
| 68 | protected: |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 69 | sp<const Element> mElement; |
| 70 | sp<Allocation> mAllocation; |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 71 | |
| 72 | void init(RenderScript *rs, uint32_t dimx, uint32_t usages = 0); |
| 73 | |
| 74 | public: |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 75 | sp<const Element> getElement() { |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 76 | return mElement; |
| 77 | } |
| 78 | |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 79 | sp<const Type> getType() { |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 80 | return mAllocation->getType(); |
| 81 | } |
| 82 | |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 83 | sp<const Allocation> getAllocation() { |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 84 | return mAllocation; |
| 85 | } |
| 86 | |
| 87 | //void updateAllocation(); |
| 88 | }; |
| 89 | }; |
| 90 | |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame^] | 91 | } |
| 92 | } |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 93 | #endif |