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