Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 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_SAMPLER_H |
| 18 | #define ANDROID_RS_SAMPLER_H |
| 19 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 20 | #include "rsAllocation.h" |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 21 | |
Miao Wang | 82e135c | 2017-02-27 23:35:35 -0800 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 24 | // --------------------------------------------------------------------------- |
| 25 | namespace android { |
| 26 | namespace renderscript { |
| 27 | |
| 28 | const static uint32_t RS_MAX_SAMPLER_SLOT = 16; |
| 29 | |
| 30 | class SamplerState; |
Alex Sakhartchouk | 407f8ca | 2011-09-23 17:05:04 -0700 | [diff] [blame] | 31 | /***************************************************************************** |
| 32 | * CAUTION |
| 33 | * |
| 34 | * Any layout changes for this class may require a corresponding change to be |
| 35 | * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains |
| 36 | * a partial copy of the information below. |
| 37 | * |
| 38 | *****************************************************************************/ |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 39 | class Sampler : public ObjectBase { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 40 | public: |
Alex Sakhartchouk | c2c02a8 | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 41 | struct Hal { |
| 42 | mutable void *drv; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 43 | |
Alex Sakhartchouk | c2c02a8 | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 44 | struct State { |
| 45 | RsSamplerValue magFilter; |
| 46 | RsSamplerValue minFilter; |
| 47 | RsSamplerValue wrapS; |
| 48 | RsSamplerValue wrapT; |
| 49 | RsSamplerValue wrapR; |
| 50 | float aniso; |
| 51 | }; |
| 52 | State state; |
| 53 | }; |
| 54 | Hal mHal; |
| 55 | |
Ling Wan | 3abc05b | 2013-03-15 16:21:50 -0700 | [diff] [blame] | 56 | void operator delete(void* ptr); |
| 57 | |
Alex Sakhartchouk | 407f8ca | 2011-09-23 17:05:04 -0700 | [diff] [blame] | 58 | static ObjectBaseRef<Sampler> getSampler(Context *, |
| 59 | RsSamplerValue magFilter, |
| 60 | RsSamplerValue minFilter, |
| 61 | RsSamplerValue wrapS, |
| 62 | RsSamplerValue wrapT, |
| 63 | RsSamplerValue wrapR, |
| 64 | float aniso = 1.0f); |
| 65 | void bindToContext(SamplerState *, uint32_t slot); |
| 66 | void unbindFromContext(SamplerState *); |
| 67 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 68 | virtual void serialize(Context *rsc, OStream *stream) const; |
Alex Sakhartchouk | 407f8ca | 2011-09-23 17:05:04 -0700 | [diff] [blame] | 69 | virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SAMPLER; } |
| 70 | static Sampler *createFromStream(Context *rsc, IStream *stream); |
| 71 | |
Alex Sakhartchouk | c2c02a8 | 2011-05-04 17:45:36 -0700 | [diff] [blame] | 72 | protected: |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 73 | int32_t mBoundSlot; |
| 74 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 75 | virtual void preDestroy() const; |
| 76 | virtual ~Sampler(); |
| 77 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 78 | private: |
Chih-Hung Hsieh | 10ab8bb | 2016-07-01 12:20:20 -0700 | [diff] [blame] | 79 | explicit Sampler(Context *); |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 80 | Sampler(Context *, |
| 81 | RsSamplerValue magFilter, |
| 82 | RsSamplerValue minFilter, |
| 83 | RsSamplerValue wrapS, |
| 84 | RsSamplerValue wrapT, |
| 85 | RsSamplerValue wrapR, |
| 86 | float aniso = 1.0f); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 90 | class SamplerState { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 91 | public: |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 92 | ObjectBaseRef<Sampler> mSamplers[RS_MAX_SAMPLER_SLOT]; |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 93 | void init(Context *rsc) { |
| 94 | } |
| 95 | void deinit(Context *rsc) { |
| 96 | for (uint32_t i = 0; i < RS_MAX_SAMPLER_SLOT; i ++) { |
| 97 | mSamplers[i].clear(); |
| 98 | } |
| 99 | } |
| 100 | // Cache of all existing raster programs. |
Miao Wang | 82e135c | 2017-02-27 23:35:35 -0800 | [diff] [blame] | 101 | std::vector<Sampler *> mAllSamplers; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
Rahul Chaudhry | 7974fc0 | 2017-02-09 12:33:28 -0800 | [diff] [blame] | 104 | } // namespace renderscript |
| 105 | } // namespace android |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 106 | #endif //ANDROID_RS_SAMPLER_H |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 107 | |
| 108 | |
| 109 | |