Revert "[Tizen] Add codes for Dali Windows Backend"
[platform/core/uifw/dali-core.git] / dali / internal / render / shaders / program-controller.h
1 #ifndef __DALI_INTERNAL_PROGRAM_CONTROLLER_H__
2 #define __DALI_INTERNAL_PROGRAM_CONTROLLER_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/devel-api/common/owner-container.h>
23 #include <dali/internal/common/shader-data.h>
24 #include <dali/internal/render/shaders/program.h>
25 #include <dali/internal/render/shaders/program-cache.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 class ShaderSaver;
34
35 /**
36  * This class is the owner of GL shader programs
37  */
38 class ProgramController : public ProgramCache
39 {
40 public:
41
42   /**
43    * Wrapper for a program and its hash code
44    */
45   class ProgramPair
46   {
47   public: // API
48
49     /**
50      * Constructor
51      * @param program
52      * @param shaderHash
53      */
54     ProgramPair( Program* program, size_t shaderHash )
55     : mProgram( program ), mShaderHash( shaderHash )
56     { }
57
58     /**
59      * Destructor, non-virtual as not a base
60      */
61     ~ProgramPair()
62     {
63       delete mProgram;
64     }
65
66     /**
67      * Inline getter for the program
68      * @return the program
69      */
70     inline Program* GetProgram()
71     {
72       return mProgram;
73     }
74
75     /**
76      * Inline getter for the hash
77      * @return the hash
78      */
79     inline size_t GetHash()
80     {
81       return mShaderHash;
82     }
83
84   private: // Not implemented
85     ProgramPair( const ProgramPair& );
86     ProgramPair& operator=( const ProgramPair& );
87
88   private: // Data
89     Program* mProgram;
90     size_t mShaderHash;
91   };
92
93   /**
94    * Constructor
95    * @param postProcessDispatcher to send save binary message back to update
96    */
97   ProgramController( Integration::GlAbstraction& glAbstraction );
98
99   /**
100    * Destructor, non virtual as not a base class
101    */
102   ~ProgramController();
103
104 public: // API
105
106   /**
107    * Resets the program matrices. Must be called at the beginning of every frame
108    */
109   void ResetProgramMatrices();
110
111   /**
112    * Notifies the cache that context is (re)created
113    */
114   void GlContextCreated();
115
116   /**
117    * Notifies cache that context is lost
118    */
119   void GlContextDestroyed();
120
121   /**
122    * Set the destination for compiler shader binaries so they can be saved.
123    * @note Must be called during initialisation.
124    */
125   void SetShaderSaver( ShaderSaver& shaderSaver );
126
127 private: // From ProgramCache
128
129   /**
130    * @copydoc ProgramCache::GetGlAbstraction
131    */
132   virtual Integration::GlAbstraction& GetGlAbstraction();
133
134   /**
135    * @copydoc ProgramCache::GetProgram
136    */
137   virtual Program* GetProgram( size_t shaderHash );
138
139   /**
140    * @copydoc ProgramCache::AddProgram
141    */
142   virtual void AddProgram( size_t shaderHash, Program* program );
143
144   /**
145    * @copydoc ProgramCache::GetCurrentProgram
146    */
147   virtual Program* GetCurrentProgram();
148
149   /**
150    * @copydoc ProgramCache::SetCurrentProgram
151    */
152   virtual void SetCurrentProgram( Program* program );
153
154   /**
155    * @copydoc ProgramCache::IsBinarySupported
156    */
157   virtual bool IsBinarySupported();
158
159   /**
160    * @copydoc ProgramCache::ProgramBinaryFormat
161    */
162   virtual GLenum ProgramBinaryFormat();
163
164   /**
165    * @copydoc ProgramCache::StoreBinary
166    */
167   virtual void StoreBinary( Internal::ShaderDataPtr programData );
168
169 private: // not implemented as non-copyable
170
171   ProgramController( const ProgramController& rhs );
172   ProgramController& operator=( const ProgramController& rhs );
173
174 private: // Data
175
176   ShaderSaver* mShaderSaver;
177   Integration::GlAbstraction& mGlAbstraction;
178   Program* mCurrentProgram;
179
180   typedef OwnerContainer< ProgramPair* > ProgramContainer;
181   typedef ProgramContainer::Iterator ProgramIterator;
182   ProgramContainer mProgramCache;
183
184   GLint mProgramBinaryFormat;
185   GLint mNumberOfProgramBinaryFormats;
186
187 };
188
189 } // namespace Internal
190
191 } // namespace Dali
192
193 #endif // __DALI_INTERNAL_PROGRAM_CONTROLLER_H__
194