2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <dali/internal/graphics/gles/gl-proxy-implementation.h>
24 #include <dali/integration-api/debug.h>
27 #include <dali/internal/system/common/environment-options.h>
31 const int NUM_FRAMES_PER_SECOND( 60 );
42 Sampler::Sampler( const char* description )
43 : mDescription( description ),
44 mAccumulatedSquare( 0 ),
49 mCurrentFrameCount( 0 )
53 void Sampler::Increment()
60 mAccumulatedSquare = 0;
65 mCurrentFrameCount = 0;
68 void Sampler::Accumulate()
70 if( mNumSamples == 0 )
72 mMin = mCurrentFrameCount;
73 mMax = mCurrentFrameCount;
77 if( mCurrentFrameCount < mMin )
79 mMin = mCurrentFrameCount;
81 if( mCurrentFrameCount > mMax )
83 mMax = mCurrentFrameCount;
89 mAccumulated += mCurrentFrameCount;
90 mAccumulatedSquare += ( mCurrentFrameCount * mCurrentFrameCount );
91 mCurrentFrameCount = 0;
93 const char* Sampler::GetDescription() const
98 float Sampler::GetMeanValue() const
101 if( mNumSamples > 0 )
103 meanValue = static_cast<double>( mAccumulated ) / static_cast<double>( mNumSamples );
108 float Sampler::GetStandardDeviation() const
110 float standardDeviation = 0.0f;
111 if( mNumSamples > 0 )
113 standardDeviation = sqrtf( mNumSamples * mAccumulatedSquare - ( mAccumulated * mAccumulated ) ) / mNumSamples;
115 return standardDeviation;
118 float Sampler::GetMin() const
123 float Sampler::GetMax() const
128 uint64_t Sampler::GetCount() const
133 ObjectCounter::ObjectCounter( const char* description )
134 : mDescription( description ),
139 void ObjectCounter::Increment()
148 void ObjectCounter::Decrement()
153 unsigned int ObjectCounter::GetCount() const
157 unsigned int ObjectCounter::GetPeak() const
162 const char* ObjectCounter::GetDescription() const
167 GlProxyImplementation::GlProxyImplementation( EnvironmentOptions& environmentOptions )
168 : mEnvironmentOptions( environmentOptions ),
169 mActiveTextureSampler( "ActiveTexture calls" ),
170 mClearSampler( "Clear calls" ),
171 mBindBufferSampler( "Bind buffers" ),
172 mBindTextureSampler( "Bind textures" ),
173 mDrawSampler( "Draw calls" ),
174 mUniformSampler( "Uniform sets" ),
175 mUseProgramSampler( "Used programs" ),
176 mBufferCount( "Buffer Count" ),
177 mTextureCount( "Texture Count" ),
178 mProgramCount( "Program Count" ),
179 mCurrentFrameCount( 0 ),
180 mTotalFrameCount( 0 )
184 GlProxyImplementation::~GlProxyImplementation()
188 void GlProxyImplementation::PreRender()
192 void GlProxyImplementation::PostRender()
194 // Accumulate counts in each sampler
197 // When we reach the desired frame count, output the averages from the samples
199 mCurrentFrameCount++;
201 if( mCurrentFrameCount >= mEnvironmentOptions.GetGlesCallTime() * NUM_FRAMES_PER_SECOND )
203 mCurrentFrameCount = 0;
206 if( !mEnvironmentOptions.GetGlesCallAccumulate() )
213 void GlProxyImplementation::Clear( GLbitfield mask )
215 mClearSampler.Increment();
216 GlImplementation::Clear(mask);
219 void GlProxyImplementation::GenBuffers(GLsizei n, GLuint* buffers)
221 mBufferCount.Increment();
222 GlImplementation::GenBuffers( n, buffers );
225 void GlProxyImplementation::DeleteBuffers( GLsizei n, const GLuint* buffers )
227 mBufferCount.Decrement();
228 GlImplementation::DeleteBuffers( n, buffers );
231 void GlProxyImplementation::BindBuffer( GLenum target, GLuint buffer )
233 mBindBufferSampler.Increment();
234 GlImplementation::BindBuffer( target, buffer );
237 void GlProxyImplementation::GenTextures( GLsizei n, GLuint* textures )
239 mTextureCount.Increment();
240 GlImplementation::GenTextures( n, textures );
243 void GlProxyImplementation::DeleteTextures( GLsizei n, const GLuint* textures )
245 mTextureCount.Decrement();
246 GlImplementation::DeleteTextures( n, textures );
249 void GlProxyImplementation::ActiveTexture( GLenum texture )
251 mActiveTextureSampler.Increment();
252 GlImplementation::ActiveTexture( texture );
255 void GlProxyImplementation::BindTexture( GLenum target, GLuint texture )
257 mBindTextureSampler.Increment();
258 GlImplementation::BindTexture(target,texture);
261 void GlProxyImplementation::DrawArrays( GLenum mode, GLint first, GLsizei count )
263 mDrawSampler.Increment();
264 GlImplementation::DrawArrays( mode, first, count );
267 void GlProxyImplementation::DrawElements( GLenum mode, GLsizei count, GLenum type, const void* indices )
269 mDrawSampler.Increment();
270 GlImplementation::DrawElements( mode, count, type, indices );
273 void GlProxyImplementation::Uniform1f( GLint location, GLfloat x )
275 mUniformSampler.Increment();
276 GlImplementation::Uniform1f( location, x );
279 void GlProxyImplementation::Uniform1fv( GLint location, GLsizei count, const GLfloat* v )
281 mUniformSampler.Increment();
282 GlImplementation::Uniform1fv( location, count, v );
285 void GlProxyImplementation::Uniform1i( GLint location, GLint x )
287 mUniformSampler.Increment();
288 GlImplementation::Uniform1i( location, x );
291 void GlProxyImplementation::Uniform1iv( GLint location, GLsizei count, const GLint* v )
293 mUniformSampler.Increment();
294 GlImplementation::Uniform1iv( location, count, v );
297 void GlProxyImplementation::Uniform2f( GLint location, GLfloat x, GLfloat y)
299 mUniformSampler.Increment();
300 GlImplementation::Uniform2f( location, x, y );
303 void GlProxyImplementation::Uniform2fv( GLint location, GLsizei count, const GLfloat* v )
305 mUniformSampler.Increment();
306 GlImplementation::Uniform2fv( location, count, v );
309 void GlProxyImplementation::Uniform2i( GLint location, GLint x, GLint y )
311 mUniformSampler.Increment();
312 GlImplementation::Uniform2i( location, x, y );
315 void GlProxyImplementation::Uniform2iv( GLint location, GLsizei count, const GLint* v )
317 mUniformSampler.Increment();
318 GlImplementation::Uniform2iv( location, count, v );
321 void GlProxyImplementation::Uniform3f( GLint location, GLfloat x, GLfloat y, GLfloat z )
323 mUniformSampler.Increment();
324 GlImplementation::Uniform3f( location, x, y, z );
327 void GlProxyImplementation::Uniform3fv( GLint location, GLsizei count, const GLfloat* v )
329 mUniformSampler.Increment();
330 GlImplementation::Uniform3fv( location, count, v );
333 void GlProxyImplementation::Uniform3i( GLint location, GLint x, GLint y, GLint z )
335 mUniformSampler.Increment();
336 GlImplementation::Uniform3i( location, x, y, z );
339 void GlProxyImplementation::Uniform3iv( GLint location, GLsizei count, const GLint* v )
341 mUniformSampler.Increment();
342 GlImplementation::Uniform3iv( location, count, v );
345 void GlProxyImplementation::Uniform4f( GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w )
347 mUniformSampler.Increment();
348 GlImplementation::Uniform4f( location, x, y, z, w );
351 void GlProxyImplementation::Uniform4fv( GLint location, GLsizei count, const GLfloat* v )
353 mUniformSampler.Increment();
354 GlImplementation::Uniform4fv( location, count, v );
357 void GlProxyImplementation::Uniform4i( GLint location, GLint x, GLint y, GLint z, GLint w )
359 mUniformSampler.Increment();
360 GlImplementation::Uniform4i( location, x, y, z, w );
363 void GlProxyImplementation::Uniform4iv( GLint location, GLsizei count, const GLint* v )
365 mUniformSampler.Increment();
366 GlImplementation::Uniform4iv( location, count, v );
369 void GlProxyImplementation::UniformMatrix2fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value )
371 mUniformSampler.Increment();
372 GlImplementation::UniformMatrix2fv( location, count, transpose, value );
375 void GlProxyImplementation::UniformMatrix3fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value )
377 mUniformSampler.Increment();
378 GlImplementation::UniformMatrix3fv( location, count, transpose, value );
381 void GlProxyImplementation::UniformMatrix4fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value )
383 mUniformSampler.Increment();
384 GlImplementation::UniformMatrix4fv( location, count, transpose, value);
387 GLuint GlProxyImplementation::CreateProgram( void )
389 mProgramCount.Increment();
390 return GlImplementation::CreateProgram();
393 void GlProxyImplementation::DeleteProgram( GLuint program )
395 mProgramCount.Decrement();
396 GlImplementation::DeleteProgram( program );
399 void GlProxyImplementation::UseProgram( GLuint program )
401 mUseProgramSampler.Increment();
402 GlImplementation::UseProgram( program );
405 void GlProxyImplementation::AccumulateSamples()
407 // Accumulate counts in each sampler
408 mActiveTextureSampler.Accumulate();
409 mClearSampler.Accumulate();
410 mBindBufferSampler.Accumulate();
411 mBindTextureSampler.Accumulate();
412 mDrawSampler.Accumulate();
413 mUniformSampler.Accumulate();
414 mUseProgramSampler.Accumulate();
417 void GlProxyImplementation::LogResults()
419 Debug::LogMessage( Debug::DebugInfo, "OpenGL ES statistics sampled over %d frames) operations per frame:\n", mTotalFrameCount );
420 LogCalls( mActiveTextureSampler );
421 LogCalls( mClearSampler );
422 LogCalls( mBindBufferSampler );
423 LogCalls( mBindTextureSampler );
424 LogCalls( mDrawSampler );
425 LogCalls( mUniformSampler );
426 LogCalls( mUseProgramSampler );
427 Debug::LogMessage( Debug::DebugInfo, "OpenGL ES Object Count:\n" );
428 LogObjectCounter( mBufferCount );
429 LogObjectCounter( mTextureCount );
430 LogObjectCounter( mProgramCount );
433 void GlProxyImplementation::LogCalls( const Sampler& sampler )
435 Debug::LogMessage( Debug::DebugInfo, " %s : Mean %5.2f (Min:%5.2f, Max:%5.2f, StdDev:%5.2f, Actual:%d)\n",
436 sampler.GetDescription(),
437 sampler.GetMeanValue(), sampler.GetMin(), sampler.GetMax(),
438 sampler.GetStandardDeviation(),
439 sampler.GetCount() );
442 void GlProxyImplementation::LogObjectCounter( const ObjectCounter& sampler )
444 Debug::LogMessage( Debug::DebugInfo, " %s : %u (Peak:%u)\n",
445 sampler.GetDescription(),
450 void GlProxyImplementation::ResetSamplers()
452 mActiveTextureSampler.Reset();
453 mClearSampler.Reset();
454 mBindBufferSampler.Reset();
455 mBindTextureSampler.Reset();
456 mDrawSampler.Reset();
457 mUniformSampler.Reset();
458 mUseProgramSampler.Reset();
459 mTotalFrameCount = 0;
462 } // namespace Adaptor
464 } // namespace Internal