X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fbenchmark%2Fbenchmark.cpp;h=c4d4cf2cdd6d308d3889331bcff42b4fbb98c87b;hb=2e182925204bf3ef9f2a36cbfbf998e79fbafaf5;hp=9e4a22dc39cdd53c9d06bd3ec07c6e4590d70f05;hpb=283d29060f730b0e4f4fec64f3d54caa75472426;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/benchmark/benchmark.cpp b/examples/benchmark/benchmark.cpp index 9e4a22d..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; @@ -29,62 +28,119 @@ using namespace Dali::Toolkit; namespace { const char* IMAGE_PATH[] = { - DALI_IMAGE_DIR "gallery-medium-1.jpg", - DALI_IMAGE_DIR "gallery-medium-2.jpg", - DALI_IMAGE_DIR "gallery-medium-3.jpg", - DALI_IMAGE_DIR "gallery-medium-4.jpg", - DALI_IMAGE_DIR "gallery-medium-5.jpg", - DALI_IMAGE_DIR "gallery-medium-6.jpg", - DALI_IMAGE_DIR "gallery-medium-7.jpg", - DALI_IMAGE_DIR "gallery-medium-8.jpg", - DALI_IMAGE_DIR "gallery-medium-9.jpg", - DALI_IMAGE_DIR "gallery-medium-10.jpg", - DALI_IMAGE_DIR "gallery-medium-11.jpg", - DALI_IMAGE_DIR "gallery-medium-12.jpg", - DALI_IMAGE_DIR "gallery-medium-13.jpg", - DALI_IMAGE_DIR "gallery-medium-14.jpg", - DALI_IMAGE_DIR "gallery-medium-15.jpg", - DALI_IMAGE_DIR "gallery-medium-16.jpg", - DALI_IMAGE_DIR "gallery-medium-17.jpg", - DALI_IMAGE_DIR "gallery-medium-18.jpg", - DALI_IMAGE_DIR "gallery-medium-19.jpg", - DALI_IMAGE_DIR "gallery-medium-20.jpg", - DALI_IMAGE_DIR "gallery-medium-21.jpg", - DALI_IMAGE_DIR "gallery-medium-22.jpg", - DALI_IMAGE_DIR "gallery-medium-23.jpg", - DALI_IMAGE_DIR "gallery-medium-24.jpg", - DALI_IMAGE_DIR "gallery-medium-25.jpg", - DALI_IMAGE_DIR "gallery-medium-26.jpg", - DALI_IMAGE_DIR "gallery-medium-27.jpg", - DALI_IMAGE_DIR "gallery-medium-28.jpg", - DALI_IMAGE_DIR "gallery-medium-29.jpg", - DALI_IMAGE_DIR "gallery-medium-30.jpg", - DALI_IMAGE_DIR "gallery-medium-31.jpg", - DALI_IMAGE_DIR "gallery-medium-32.jpg", - DALI_IMAGE_DIR "gallery-medium-33.jpg", - DALI_IMAGE_DIR "gallery-medium-34.jpg", - DALI_IMAGE_DIR "gallery-medium-35.jpg", - DALI_IMAGE_DIR "gallery-medium-36.jpg", - DALI_IMAGE_DIR "gallery-medium-37.jpg", - DALI_IMAGE_DIR "gallery-medium-38.jpg", - DALI_IMAGE_DIR "gallery-medium-39.jpg", - DALI_IMAGE_DIR "gallery-medium-40.jpg", - DALI_IMAGE_DIR "gallery-medium-41.jpg", - DALI_IMAGE_DIR "gallery-medium-42.jpg", - DALI_IMAGE_DIR "gallery-medium-43.jpg", - DALI_IMAGE_DIR "gallery-medium-44.jpg", - DALI_IMAGE_DIR "gallery-medium-45.jpg", - DALI_IMAGE_DIR "gallery-medium-46.jpg", - DALI_IMAGE_DIR "gallery-medium-47.jpg", - DALI_IMAGE_DIR "gallery-medium-48.jpg", - DALI_IMAGE_DIR "gallery-medium-49.jpg", - DALI_IMAGE_DIR "gallery-medium-50.jpg", - DALI_IMAGE_DIR "gallery-medium-51.jpg", - DALI_IMAGE_DIR "gallery-medium-52.jpg", - DALI_IMAGE_DIR "gallery-medium-53.jpg", + DEMO_IMAGE_DIR "gallery-medium-1.jpg", + DEMO_IMAGE_DIR "gallery-medium-2.jpg", + DEMO_IMAGE_DIR "gallery-medium-3.jpg", + DEMO_IMAGE_DIR "gallery-medium-4.jpg", + DEMO_IMAGE_DIR "gallery-medium-5.jpg", + DEMO_IMAGE_DIR "gallery-medium-6.jpg", + DEMO_IMAGE_DIR "gallery-medium-7.jpg", + DEMO_IMAGE_DIR "gallery-medium-8.jpg", + DEMO_IMAGE_DIR "gallery-medium-9.jpg", + DEMO_IMAGE_DIR "gallery-medium-10.jpg", + DEMO_IMAGE_DIR "gallery-medium-11.jpg", + DEMO_IMAGE_DIR "gallery-medium-12.jpg", + DEMO_IMAGE_DIR "gallery-medium-13.jpg", + DEMO_IMAGE_DIR "gallery-medium-14.jpg", + DEMO_IMAGE_DIR "gallery-medium-15.jpg", + DEMO_IMAGE_DIR "gallery-medium-16.jpg", + DEMO_IMAGE_DIR "gallery-medium-17.jpg", + DEMO_IMAGE_DIR "gallery-medium-18.jpg", + DEMO_IMAGE_DIR "gallery-medium-19.jpg", + DEMO_IMAGE_DIR "gallery-medium-20.jpg", + DEMO_IMAGE_DIR "gallery-medium-21.jpg", + DEMO_IMAGE_DIR "gallery-medium-22.jpg", + DEMO_IMAGE_DIR "gallery-medium-23.jpg", + DEMO_IMAGE_DIR "gallery-medium-24.jpg", + DEMO_IMAGE_DIR "gallery-medium-25.jpg", + DEMO_IMAGE_DIR "gallery-medium-26.jpg", + DEMO_IMAGE_DIR "gallery-medium-27.jpg", + DEMO_IMAGE_DIR "gallery-medium-28.jpg", + DEMO_IMAGE_DIR "gallery-medium-29.jpg", + DEMO_IMAGE_DIR "gallery-medium-30.jpg", + DEMO_IMAGE_DIR "gallery-medium-31.jpg", + DEMO_IMAGE_DIR "gallery-medium-32.jpg", + DEMO_IMAGE_DIR "gallery-medium-33.jpg", + DEMO_IMAGE_DIR "gallery-medium-34.jpg", + DEMO_IMAGE_DIR "gallery-medium-35.jpg", + DEMO_IMAGE_DIR "gallery-medium-36.jpg", + DEMO_IMAGE_DIR "gallery-medium-37.jpg", + DEMO_IMAGE_DIR "gallery-medium-38.jpg", + DEMO_IMAGE_DIR "gallery-medium-39.jpg", + DEMO_IMAGE_DIR "gallery-medium-40.jpg", + DEMO_IMAGE_DIR "gallery-medium-41.jpg", + DEMO_IMAGE_DIR "gallery-medium-42.jpg", + DEMO_IMAGE_DIR "gallery-medium-43.jpg", + DEMO_IMAGE_DIR "gallery-medium-44.jpg", + DEMO_IMAGE_DIR "gallery-medium-45.jpg", + DEMO_IMAGE_DIR "gallery-medium-46.jpg", + DEMO_IMAGE_DIR "gallery-medium-47.jpg", + DEMO_IMAGE_DIR "gallery-medium-48.jpg", + DEMO_IMAGE_DIR "gallery-medium-49.jpg", + DEMO_IMAGE_DIR "gallery-medium-50.jpg", + DEMO_IMAGE_DIR "gallery-medium-51.jpg", + DEMO_IMAGE_DIR "gallery-medium-52.jpg", + DEMO_IMAGE_DIR "gallery-medium-53.jpg", +}; + +const char* NINEPATCH_IMAGE_PATH[] = { + DEMO_IMAGE_DIR "selection-popup-bg.1.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.2.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.3.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.4.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.5.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.6.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.7.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.8.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.9.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.10.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.11.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.12.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.13.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.14.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.15.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.16.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.17.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.18.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.19.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.20.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.21.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.22.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.23.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.24.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.25.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.26.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.27.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.28.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.29.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.30.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.31.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.32.9.png", + DEMO_IMAGE_DIR "selection-popup-bg.33.9.png", + DEMO_IMAGE_DIR "button-disabled.9.png", + DEMO_IMAGE_DIR "button-down.9.png", + DEMO_IMAGE_DIR "button-down-disabled.9.png", + DEMO_IMAGE_DIR "button-up-1.9.png", + DEMO_IMAGE_DIR "button-up-2.9.png", + DEMO_IMAGE_DIR "button-up-3.9.png", + DEMO_IMAGE_DIR "button-up-4.9.png", + DEMO_IMAGE_DIR "button-up-5.9.png", + DEMO_IMAGE_DIR "button-up-6.9.png", + DEMO_IMAGE_DIR "button-up-7.9.png", + DEMO_IMAGE_DIR "button-up-8.9.png", + DEMO_IMAGE_DIR "button-up-9.9.png", + DEMO_IMAGE_DIR "button-up-10.9.png", + DEMO_IMAGE_DIR "button-up-11.9.png", + DEMO_IMAGE_DIR "button-up-12.9.png", + DEMO_IMAGE_DIR "button-up-13.9.png", + DEMO_IMAGE_DIR "button-up-14.9.png", + DEMO_IMAGE_DIR "button-up-15.9.png", + DEMO_IMAGE_DIR "button-up-16.9.png", + DEMO_IMAGE_DIR "button-up-17.9.png", }; const unsigned int NUM_IMAGES = sizeof(IMAGE_PATH) / sizeof(char*); +const unsigned int NUM_NINEPATCH_IMAGES = sizeof(NINEPATCH_IMAGE_PATH) / sizeof(char*); const float ANIMATION_TIME ( 5.0f ); // animation length in seconds @@ -126,69 +182,32 @@ 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, 4u ); - vertexBuffer.SetData( gQuadWithTexture ); - - //Create the geometry - mesh = Geometry::New(); - mesh.AddVertexBuffer( vertexBuffer ); - mesh.SetGeometryType(Geometry::TRIANGLE_STRIP ); - } - return mesh; -} - -Renderer CreateRenderer( unsigned int index ) -{ - static Renderer renderers[NUM_IMAGES]; - if( !renderers[index] ) - { - //Create the renderer - Shader shader = Shader::New( VERTEX_SHADER_TEXTURE, FRAGMENT_SHADER_TEXTURE ); - Image image = ResourceImage::New(IMAGE_PATH[index]); - Sampler textureSampler = Sampler::New( image, "sTexture" ); - Material material = Material::New( shader ); - material.AddSampler(textureSampler); - material.SetBlendMode( BlendingMode::OFF ); - renderers[index] = Renderer::New( QuadMesh(), material ); - } - return renderers[index]; -} - -Actor CreateMeshActor( unsigned int index) -{ - Renderer renderer = CreateRenderer(index); - Actor meshActor = Actor::New(); - meshActor.AddRenderer( renderer ); - return meshActor; -} - bool gUseMesh(false); -bool gUseImageView(false); +bool gNinePatch(false); unsigned int gRowsPerPage(25); unsigned int gColumnsPerPage( 25 ); unsigned int gPageCount(13); +Renderer CreateRenderer( unsigned int index, Geometry geometry, Shader shader ) +{ + 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; +} } -// Test application to compare performance between ImageActor and ImageView -// By default, the application consist of 10 pages of 25x25 ImageActors, this can be modified using the following command line arguments: +// 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-imageview ( Use ImageView instead of ImageActor ) // --use-mesh ( Use new renderer API (as ImageView) but shares renderers between actors when possible ) +// --nine-patch ( Use nine patch images ) // class Benchmark : public ConnectionTracker @@ -223,45 +242,33 @@ 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( gUseImageView ) - { - CreateImageViews(); - } else { - CreateImageActors(); + CreateImageViews(); } ShowAnimation(); } - bool OnTouch( Actor actor, const TouchEvent& touch ) + bool OnTouch( Actor actor, const TouchData& touch ) { // quit the application mApplication.Quit(); return true; } - void CreateImageActors() + const char* ImagePath( int i ) { - 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( gUseImageView ) + if( gUseMesh ) { - mImageView[count].SetPosition( initialPosition ); - mImageView[count].SetSize( Vector3(0.0f,0.0f,0.0f) ); - mImageView[count].SetOrientation( 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 )); + 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 { - mActor[count].SetPosition( initialPosition ); - mActor[count].SetSize( Vector3(0.0f,0.0f,0.0f) ); - mActor[count].SetOrientation( 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 )); + 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 )); } ++count; } @@ -369,23 +387,23 @@ 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); @@ -414,15 +433,15 @@ public: delay = delayBetweenActors * count; } - if( gUseImageView ) + if( gUseMesh ) { - mHide.AnimateTo( Property( mImageView[count], Actor::Property::ORIENTATION), Quaternion( Radian( Degree( 70.0f ) ), Vector3::XAXIS ), AlphaFunction::EASE_OUT, TimePeriod( delay, duration )); - mHide.AnimateBy( Property( mImageView[count], Actor::Property::POSITION_Z), 1000.0f, AlphaFunction::EASE_OUT_BACK, TimePeriod( delay +delayBetweenActors*actorsPerPage + duration, duration )); + 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 )); } else { - 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), 1000.0f, AlphaFunction::EASE_OUT_BACK, TimePeriod( delay +delayBetweenActors*actorsPerPage + duration, duration )); + mHide.AnimateTo( Property( mImageView[count], Actor::Property::ORIENTATION), Quaternion( Radian( Degree( 70.0f ) ), Vector3::XAXIS ), AlphaFunction::EASE_OUT, TimePeriod( delay, duration )); + mHide.AnimateBy( Property( mImageView[count], Actor::Property::POSITION_Z), finalZ, AlphaFunction::EASE_OUT_BACK, TimePeriod( delay +delayBetweenActors*actorsPerPage + duration, duration )); } ++count; } @@ -432,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; @@ -448,16 +478,7 @@ private: Animation mHide; }; -void RunTest( Application& application ) -{ - Benchmark test( application ); - - application.MainLoop(); -} - -// Entry point for Linux & Tizen applications -// -int main( int argc, char **argv ) +int DALI_EXPORT_API main( int argc, char **argv ) { Application application = Application::New( &argc, &argv ); @@ -468,9 +489,9 @@ int main( int argc, char **argv ) { gUseMesh = true; } - else if( arg.compare("--use-imageview") == 0) + else if( arg.compare("--nine-patch" ) == 0) { - gUseImageView = true; + gNinePatch = true; } else if( arg.compare(0, 2, "-r" ) == 0) { @@ -484,11 +505,10 @@ int main( int argc, char **argv ) { gPageCount = atoi( arg.substr( 2, arg.size()).c_str()); } - - } - RunTest( application ); + Benchmark test( application ); + application.MainLoop(); return 0; }