Home | History | Annotate | Download | only in rs
      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 
     20 #include "rsAllocation.h"
     21 #include "RenderScript.h"
     22 
     23 // ---------------------------------------------------------------------------
     24 namespace android {
     25 namespace renderscript {
     26 
     27 const static uint32_t RS_MAX_SAMPLER_SLOT = 16;
     28 
     29 class SamplerState;
     30 /*****************************************************************************
     31  * CAUTION
     32  *
     33  * Any layout changes for this class may require a corresponding change to be
     34  * made to frameworks/compile/libbcc/lib/ScriptCRT/rs_core.c, which contains
     35  * a partial copy of the information below.
     36  *
     37  *****************************************************************************/
     38 class Sampler : public ObjectBase {
     39 public:
     40     struct Hal {
     41         mutable void *drv;
     42 
     43         struct State {
     44             RsSamplerValue magFilter;
     45             RsSamplerValue minFilter;
     46             RsSamplerValue wrapS;
     47             RsSamplerValue wrapT;
     48             RsSamplerValue wrapR;
     49             float aniso;
     50         };
     51         State state;
     52     };
     53     Hal mHal;
     54 
     55     static ObjectBaseRef<Sampler> getSampler(Context *,
     56                                              RsSamplerValue magFilter,
     57                                              RsSamplerValue minFilter,
     58                                              RsSamplerValue wrapS,
     59                                              RsSamplerValue wrapT,
     60                                              RsSamplerValue wrapR,
     61                                              float aniso = 1.0f);
     62     void bindToContext(SamplerState *, uint32_t slot);
     63     void unbindFromContext(SamplerState *);
     64 
     65     virtual void serialize(OStream *stream) const;
     66     virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SAMPLER; }
     67     static Sampler *createFromStream(Context *rsc, IStream *stream);
     68 
     69 protected:
     70     int32_t mBoundSlot;
     71 
     72     virtual void preDestroy() const;
     73     virtual ~Sampler();
     74 
     75 private:
     76     Sampler(Context *);
     77     Sampler(Context *,
     78             RsSamplerValue magFilter,
     79             RsSamplerValue minFilter,
     80             RsSamplerValue wrapS,
     81             RsSamplerValue wrapT,
     82             RsSamplerValue wrapR,
     83             float aniso = 1.0f);
     84 };
     85 
     86 
     87 class SamplerState {
     88 public:
     89     ObjectBaseRef<Sampler> mSamplers[RS_MAX_SAMPLER_SLOT];
     90     void init(Context *rsc) {
     91     }
     92     void deinit(Context *rsc) {
     93         for (uint32_t i = 0; i < RS_MAX_SAMPLER_SLOT; i ++) {
     94             mSamplers[i].clear();
     95         }
     96     }
     97     // Cache of all existing raster programs.
     98     Vector<Sampler *> mAllSamplers;
     99 };
    100 
    101 }
    102 }
    103 #endif //ANDROID_RS_SAMPLER_H
    104 
    105 
    106 
    107