1 /*
2  * Copyright (C) 2011 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_PROGRAM_FRAGMENT_STORE_H
18 #define ANDROID_RS_PROGRAM_FRAGMENT_STORE_H
19 
20 #include "rsProgramBase.h"
21 #include "rsStream.h"
22 
23 #include <vector>
24 
25 // ---------------------------------------------------------------------------
26 namespace android {
27 namespace renderscript {
28 
29 class ProgramStoreState;
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 ProgramStore : public ProgramBase {
39 public:
40     struct Hal {
41         mutable void *drv;
42 
43         struct State {
44             bool ditherEnable;
45 
46             //bool blendEnable;
47             bool colorRWriteEnable;
48             bool colorGWriteEnable;
49             bool colorBWriteEnable;
50             bool colorAWriteEnable;
51             RsBlendSrcFunc blendSrc;
52             RsBlendDstFunc blendDst;
53 
54             //bool depthTestEnable;
55             bool depthWriteEnable;
56             RsDepthFunc depthFunc;
57         };
58         State state;
59     };
60     Hal mHal;
61 
62     virtual void setup(const Context *, ProgramStoreState *);
63 
64     virtual void serialize(Context *rsc, OStream *stream) const;
getClassId()65     virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_PROGRAM_STORE; }
66     static ProgramStore *createFromStream(Context *rsc, IStream *stream);
67     static ObjectBaseRef<ProgramStore> getProgramStore(Context *,
68                                                        bool colorMaskR, bool colorMaskG,
69                                                        bool colorMaskB, bool colorMaskA,
70                                                        bool depthMask, bool ditherEnable,
71                                                        RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc,
72                                                        RsDepthFunc depthFunc);
73     void init();
74 protected:
75     virtual void preDestroy() const;
76     virtual ~ProgramStore();
77 
78 private:
79     ProgramStore(Context *,
80                  bool colorMaskR, bool colorMaskG, bool colorMaskB, bool colorMaskA,
81                  bool depthMask, bool ditherEnable,
82                  RsBlendSrcFunc srcFunc, RsBlendDstFunc destFunc,
83                  RsDepthFunc depthFunc);
84 };
85 
86 class ProgramStoreState {
87 public:
88     ProgramStoreState();
89     ~ProgramStoreState();
90     void init(Context *rsc);
91     void deinit(Context *rsc);
92 
93     ObjectBaseRef<ProgramStore> mDefault;
94     ObjectBaseRef<ProgramStore> mLast;
95 
96     // Cache of all existing store programs.
97     std::vector<ProgramStore *> mStorePrograms;
98 };
99 
100 } // namespace renderscript
101 } // namespace android
102 #endif
103 
104 
105 
106