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