Merge branch 'devel/master' into sandbox/dkdk/tizen
[platform/core/uifw/dali-adaptor.git] / dali / internal / graphics / gles / gl-proxy-implementation.h
1 #ifndef DALI_INTERNAL_GL_PROXY_IMPLEMENTATION_H
2 #define DALI_INTERNAL_GL_PROXY_IMPLEMENTATION_H
3
4 /*
5  * Copyright (c) 2019 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/internal/graphics/gles/gl-implementation.h>
23
24 namespace Dali
25 {
26 namespace Internal
27 {
28 namespace Adaptor
29 {
30 class EnvironmentOptions;
31
32 /**
33  * Helper class to calculate the statistics for Open GLES calls
34  */
35 class Sampler
36 {
37 public:
38
39   /**
40    * Constructor
41    * @param description to write to the log
42    */
43   Sampler( const char* description );
44
45   /**
46    * Increment the counter for this frame
47    */
48   void Increment();
49
50   /**
51    * Reset the counter
52    */
53   void Reset();
54
55   /**
56    * Accumulate the count onto statistics
57    */
58   void Accumulate();
59
60   /**
61    * @return the description of the sampler
62    */
63   const char* GetDescription() const;
64
65   /**
66    * @return the mean value
67    */
68   float GetMeanValue() const;
69
70   /**
71    * @return the standard deviation
72    */
73   float GetStandardDeviation() const;
74
75   /**
76    * @return the minimum value
77    */
78   float GetMin() const;
79
80   /**
81    * @return the maximum value
82    */
83   float GetMax() const;
84
85   /**
86    * @return the current count
87    */
88   uint64_t GetCount() const;
89
90 private: // Data
91
92   const char* mDescription;
93
94   uint64_t mAccumulatedSquare;
95   uint64_t mAccumulated;
96   uint64_t mNumSamples;
97   float mMin;
98   float mMax;
99   unsigned int mCurrentFrameCount;
100 };
101
102 /**
103  * Helper class to calculate number of OpenGL objects
104  */
105 class ObjectCounter
106 {
107 public:
108   ObjectCounter( const char* description );
109
110   /**
111    * Increment the counter
112    */
113   void Increment();
114
115   /**
116    * Decrement the counter
117    */
118   void Decrement();
119
120   /**
121    * @return The current number of objects
122    */
123   unsigned int GetCount() const;
124
125   /**
126    * @return The maximum number of objects created
127    */
128   unsigned int GetPeak() const;
129
130   /**
131    * @return the description of the sampler
132    */
133   const char* GetDescription() const;
134
135 private:
136   const char* mDescription;
137   unsigned int mCount;
138   unsigned int mPeak;
139 };
140
141 /**
142  * GlProxyImplementation is a wrapper for the concrete implementation
143  * of GlAbstraction that also gathers statistical information.
144  */
145 class GlProxyImplementation : public GlImplementation
146 {
147 public:
148
149   /**
150    * Constructor
151    * @param environmentOptions to check how often to log results
152    */
153   GlProxyImplementation( EnvironmentOptions& environmentOptions );
154
155   /**
156    * Virtual destructor
157    */
158   virtual ~GlProxyImplementation();
159
160   /**
161    * @copydoc GlAbstraction::PreRender();
162    */
163   void PreRender() override;
164
165   /**
166    * @copydoc GlAbstraction::PostRender();
167    */
168   void PostRender() override;
169
170   /* OpenGL ES 2.0 API */
171   void Clear( GLbitfield mask ) override;
172
173   void GenBuffers( GLsizei n, GLuint* buffers ) override;
174   void DeleteBuffers( GLsizei n, const GLuint* buffers ) override;
175   void BindBuffer( GLenum target, GLuint buffer ) override;
176
177   void GenTextures( GLsizei n, GLuint* textures ) override;
178   void DeleteTextures( GLsizei n, const GLuint* textures ) override;
179   void ActiveTexture( GLenum texture ) override;
180   void BindTexture( GLenum target, GLuint texture ) override;
181
182   void DrawArrays( GLenum mode, GLint first, GLsizei count ) override;
183   void DrawElements( GLenum mode, GLsizei count, GLenum type, const void* indices ) override;
184
185   void Uniform1f ( GLint location, GLfloat x ) override;
186   void Uniform1fv( GLint location, GLsizei count, const GLfloat* v ) override;
187   void Uniform1i ( GLint location, GLint x ) override;
188   void Uniform1iv( GLint location, GLsizei count, const GLint* v ) override;
189   void Uniform2f ( GLint location, GLfloat x, GLfloat y ) override;
190   void Uniform2fv( GLint location, GLsizei count, const GLfloat* v ) override;
191   void Uniform2i ( GLint location, GLint x, GLint y ) override;
192   void Uniform2iv( GLint location, GLsizei count, const GLint* v ) override;
193   void Uniform3f ( GLint location, GLfloat x, GLfloat y, GLfloat z ) override;
194   void Uniform3fv( GLint location, GLsizei count, const GLfloat* v ) override;
195   void Uniform3i ( GLint location, GLint x, GLint y, GLint z ) override;
196   void Uniform3iv( GLint location, GLsizei count, const GLint* v ) override;
197   void Uniform4f ( GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w ) override;
198   void Uniform4fv( GLint location, GLsizei count, const GLfloat* v ) override;
199   void Uniform4i ( GLint location, GLint x, GLint y, GLint z, GLint w ) override;
200   void Uniform4iv( GLint location, GLsizei count, const GLint* v ) override;
201   void UniformMatrix2fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ) override;
202   void UniformMatrix3fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ) override;
203   void UniformMatrix4fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value ) override;
204
205   GLuint CreateProgram( void ) override;
206   void DeleteProgram( GLuint program ) override;
207   void UseProgram( GLuint program ) override;
208
209 private: // Helpers
210
211   void AccumulateSamples();
212   void LogResults();
213   void LogCalls( const Sampler& sampler );
214   void LogObjectCounter( const ObjectCounter& sampler );
215   void ResetSamplers();
216
217 private: // Data
218
219   EnvironmentOptions& mEnvironmentOptions;
220   Sampler mActiveTextureSampler;
221   Sampler mClearSampler;
222   Sampler mBindBufferSampler;
223   Sampler mBindTextureSampler;
224   Sampler mDrawSampler;
225   Sampler mUniformSampler;
226   Sampler mUseProgramSampler;
227   ObjectCounter mBufferCount;
228   ObjectCounter mTextureCount;
229   ObjectCounter mProgramCount;
230
231   int mCurrentFrameCount;
232   int mTotalFrameCount;
233 };
234
235 } // namespace Adaptor
236
237 } // namespace Internal
238
239 } // namespace Dali
240
241 #endif // DALI_INTERNAL_GL_PROXY_IMPLEMENTATION_H