X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fbenchmark%2Fbenchmark.cpp;h=c4d4cf2cdd6d308d3889331bcff42b4fbb98c87b;hb=2e182925204bf3ef9f2a36cbfbf998e79fbafaf5;hp=3824de81bd57f2c7724adca5b3f86031c1ba0980;hpb=03d39591118c47c450740aad8a7186f7e65f05da;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/benchmark/benchmark.cpp b/examples/benchmark/benchmark.cpp index 3824de8..c4d4cf2 100644 --- a/examples/benchmark/benchmark.cpp +++ b/examples/benchmark/benchmark.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,12 +15,11 @@ * */ +// EXTERNAL INCLUDES #include -#include -#include -#include -#include -#include + +// INTERNAL INCLUDES +#include "shared/utility.h" using namespace Dali; using namespace Dali::Toolkit; @@ -183,72 +182,30 @@ const char* FRAGMENT_SHADER_TEXTURE = DALI_COMPOSE_SHADER( }\n ); - -Geometry& QuadMesh() -{ - static Geometry mesh; - if( !mesh ) - { - PropertyBuffer vertexBuffer; - Property::Map vertexFormat; - vertexFormat["aPosition"] = Property::VECTOR2; - vertexFormat["aTexCoord"] = Property::VECTOR2; - - //Create a vertex buffer for vertex positions and texture coordinates - vertexBuffer = PropertyBuffer::New( vertexFormat ); - vertexBuffer.SetData( gQuadWithTexture, 4u ); - - //Create the geometry - mesh = Geometry::New(); - mesh.AddVertexBuffer( vertexBuffer ); - mesh.SetGeometryType(Geometry::TRIANGLE_STRIP ); - } - return mesh; -} - bool gUseMesh(false); -bool gUseImageActor(false); bool gNinePatch(false); unsigned int gRowsPerPage(25); unsigned int gColumnsPerPage( 25 ); unsigned int gPageCount(13); -Renderer CreateRenderer( unsigned int index ) +Renderer CreateRenderer( unsigned int index, Geometry geometry, Shader shader ) { - - int numImages = !gNinePatch ? NUM_IMAGES : NUM_NINEPATCH_IMAGES; - static Renderer* renderers = new Renderer[numImages]; - if( !renderers[index] ) - { - //Create the renderer - Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE ); - - const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index]; - Image image = ResourceImage::New(imagePath); - TextureSet textureSet = TextureSet::New(); - textureSet.SetImage( 0u, image ); - renderers[index] = Renderer::New( QuadMesh(), shader ); - renderers[index].SetTextures( textureSet ); - renderers[index].SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF ); - } - return renderers[index]; + Renderer renderer = Renderer::New( geometry, shader ); + const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index]; + Texture texture = DemoHelper::LoadTexture( imagePath ); + TextureSet textureSet = TextureSet::New(); + textureSet.SetTexture( 0u, texture ); + renderer.SetTextures( textureSet ); + renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::OFF ); + return renderer; } -Actor CreateMeshActor( unsigned int index) -{ - Renderer renderer = CreateRenderer(index); - Actor meshActor = Actor::New(); - meshActor.AddRenderer( renderer ); - return meshActor; } - -} -// Test application to compare performance between ImageActor and ImageView +// Test application to compare performance between using a mesh and ImageView // By default, the application consist of 10 pages of 25x25 Image views, this can be modified using the following command line arguments: // -r NumberOfRows (Modifies the number of rows per page) // -c NumberOfColumns (Modifies the number of columns per page) // -p NumberOfPages (Modifies the nimber of pages ) -// --use-image-actor ( Use ImageActor instead of ImageView ) // --use-mesh ( Use new renderer API (as ImageView) but shares renderers between actors when possible ) // --nine-patch ( Use nine patch images ) @@ -285,16 +242,15 @@ public: mSize = Vector3( stageSize.x / mColumnsPerPage, stageSize.y / mRowsPerPage, 0.0f ); // Respond to a click anywhere on the stage - stage.GetRootLayer().TouchedSignal().Connect( this, &Benchmark::OnTouch ); + stage.GetRootLayer().TouchSignal().Connect( this, &Benchmark::OnTouch ); + + // Respond to key events + stage.KeyEventSignal().Connect( this, &Benchmark::OnKeyEvent ); if( gUseMesh ) { CreateMeshActors(); } - else if( gUseImageActor ) - { - CreateImageActors(); - } else { CreateImageViews(); @@ -303,7 +259,7 @@ public: ShowAnimation(); } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch( Actor actor, const TouchData& touch ) { // quit the application mApplication.Quit(); @@ -315,22 +271,6 @@ public: return !gNinePatch ? IMAGE_PATH[i % NUM_IMAGES] : NINEPATCH_IMAGE_PATH[i % NUM_NINEPATCH_IMAGES]; } - void CreateImageActors() - { - Stage stage = Stage::GetCurrent(); - unsigned int actorCount(mRowsPerPage*mColumnsPerPage * mPageCount); - mActor.resize(actorCount); - - for( size_t i(0); i renderers( numImages ); + Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE ); + Geometry geometry = DemoHelper::CreateTexturedQuad(); + for( unsigned int i(0); i( mRowsPerPage ) * mColumnsPerPage ) ) { duration = durationPerActor; delay = delayBetweenActors * count; } - if( gUseImageActor || gUseMesh ) + if( gUseMesh ) { - mActor[count].SetPosition( initialPosition ); - mActor[count].SetSize( Vector3(0.0f,0.0f,0.0f) ); - mActor[count].SetOrientation( Quaternion( Radian(0.0f),Vector3::XAXIS)); + mActor[count].SetProperty( Actor::Property::POSITION, initialPosition ); + mActor[count].SetProperty( Actor::Property::SIZE, Vector3(0.0f,0.0f,0.0f) ); + mActor[count].SetProperty( Actor::Property::ORIENTATION, Quaternion( Radian(0.0f),Vector3::XAXIS) ); mShow.AnimateTo( Property( mActor[count], Actor::Property::POSITION), Vector3(xpos+mSize.x*0.5f, ypos+mSize.y*0.5f, 0.0f), AlphaFunction::EASE_OUT_BACK, TimePeriod( delay, duration )); mShow.AnimateTo( Property( mActor[count], Actor::Property::SIZE), mSize, AlphaFunction::EASE_OUT_BACK, TimePeriod( delay, duration )); } else { - mImageView[count].SetPosition( initialPosition ); - mImageView[count].SetSize( Vector3(0.0f,0.0f,0.0f) ); - mImageView[count].SetOrientation( Quaternion( Radian(0.0f),Vector3::XAXIS)); + mImageView[count].SetProperty( Actor::Property::POSITION, initialPosition ); + mImageView[count].SetProperty( Actor::Property::SIZE, Vector3(0.0f,0.0f,0.0f) ); + mImageView[count].SetProperty( Actor::Property::ORIENTATION, Quaternion( Radian(0.0f),Vector3::XAXIS) ); mShow.AnimateTo( Property( mImageView[count], Actor::Property::POSITION), Vector3(xpos+mSize.x*0.5f, ypos+mSize.y*0.5f, 0.0f), AlphaFunction::EASE_OUT_BACK, TimePeriod( delay, duration )); mShow.AnimateTo( Property( mImageView[count], Actor::Property::SIZE), mSize, AlphaFunction::EASE_OUT_BACK, TimePeriod( delay, duration )); } @@ -436,10 +387,10 @@ public: Vector3 stageSize( stage.GetSize() ); mScroll = Animation::New(10.0f); - size_t actorCount( mRowsPerPage*mColumnsPerPage*mPageCount); + size_t actorCount( static_cast< size_t >( mRowsPerPage ) * mColumnsPerPage * mPageCount ); for( size_t i(0); i( Actor::Property::WORLD_POSITION ).z; float totalDuration( 5.0f); float durationPerActor( 0.5f ); float delayBetweenActors = ( totalDuration - durationPerActor) / (mRowsPerPage*mColumnsPerPage); @@ -482,7 +433,7 @@ public: delay = delayBetweenActors * count; } - if( gUseImageActor || gUseMesh ) + if( gUseMesh ) { mHide.AnimateTo( Property( mActor[count], Actor::Property::ORIENTATION), Quaternion( Radian( Degree( 70.0f ) ), Vector3::XAXIS ), AlphaFunction::EASE_OUT, TimePeriod( delay, duration )); mHide.AnimateBy( Property( mActor[count], Actor::Property::POSITION_Z), finalZ, AlphaFunction::EASE_OUT_BACK, TimePeriod( delay +delayBetweenActors*actorsPerPage + duration, duration )); @@ -500,6 +451,17 @@ public: mHide.FinishedSignal().Connect( this, &Benchmark::OnAnimationEnd ); } + void OnKeyEvent( const KeyEvent& event ) + { + if( event.state == KeyEvent::Down ) + { + if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + { + mApplication.Quit(); + } + } + } + private: Application& mApplication; @@ -516,15 +478,6 @@ private: Animation mHide; }; -void RunTest( Application& application ) -{ - Benchmark test( application ); - - application.MainLoop(); -} - -// Entry point for Linux & Tizen applications -// int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv ); @@ -536,10 +489,6 @@ int DALI_EXPORT_API main( int argc, char **argv ) { gUseMesh = true; } - else if( arg.compare("--use-image-actor") == 0) - { - gUseImageActor = true; - } else if( arg.compare("--nine-patch" ) == 0) { gNinePatch = true; @@ -558,7 +507,8 @@ int DALI_EXPORT_API main( int argc, char **argv ) } } - RunTest( application ); + Benchmark test( application ); + application.MainLoop(); return 0; }