X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=examples%2Fperf-scroll%2Fperf-scroll.cpp;h=8a7d2a08ec533a54af058c104aa5bba0d99b0496;hb=c70446e9b125ae8bb236b4cbc3fd3f8b548459cd;hp=2835f7941921e79b7cd418d3ab5a8dcf8eb78529;hpb=6f3c3a4423261bb61dd01f2b8858ffa93ab2a2f9;p=platform%2Fcore%2Fuifw%2Fdali-demo.git diff --git a/examples/perf-scroll/perf-scroll.cpp b/examples/perf-scroll/perf-scroll.cpp index 2835f79..8a7d2a0 100644 --- a/examples/perf-scroll/perf-scroll.cpp +++ b/examples/perf-scroll/perf-scroll.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 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. @@ -16,12 +16,8 @@ */ #include -#include -#include -#include -#include -#include -#include +#include +#include "shared/utility.h" using namespace Dali; using namespace Dali::Toolkit; @@ -152,13 +148,6 @@ struct VertexWithTexture Vector2 texCoord; }; -VertexWithTexture gQuadWithTexture[] = { - { Vector2( -0.5f, -0.5f ), Vector2( 0.0f, 0.0f ) }, - { Vector2( 0.5f, -0.5f ), Vector2( 1.0f, 0.0f ) }, - { Vector2( -0.5f, 0.5f ), Vector2( 0.0f, 1.0f ) }, - { Vector2( 0.5f, 0.5f ), Vector2( 1.0f, 1.0f ) } -}; - const char* VERTEX_SHADER_TEXTURE = DALI_COMPOSE_SHADER( attribute mediump vec2 aPosition;\n attribute mediump vec2 aTexCoord;\n @@ -184,29 +173,6 @@ 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 gNinePatch(false); unsigned int gRowsPerPage(15); @@ -214,36 +180,18 @@ unsigned int gColumnsPerPage(15); unsigned int gPageCount(10); float gDuration(10.0f); -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::BLENDING_MODE, BlendingMode::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 @@ -275,21 +223,24 @@ public: // The Init signal is received once (only) during the Application lifetime void Create( Application& application ) { - // Get a handle to the stage - Stage stage = Stage::GetCurrent(); - stage.SetBackgroundColor( Color::WHITE ); - Vector2 stageSize = stage.GetSize(); + // Get a handle to the window + Window window = application.GetWindow(); + window.SetBackgroundColor( Color::WHITE ); + Vector2 windowSize = window.GetSize(); - stage.GetRootLayer().SetDepthTestDisabled(true); + window.GetRootLayer().SetProperty( Layer::Property::DEPTH_TEST, false ); - mSize = Vector3( stageSize.x / mColumnsPerPage, stageSize.y / mRowsPerPage, 0.0f ); + mSize = Vector3( windowSize.x / mColumnsPerPage, windowSize.y / mRowsPerPage, 0.0f ); - // Respond to a click anywhere on the stage - stage.GetRootLayer().TouchedSignal().Connect( this, &PerfScroll::OnTouch ); + // Respond to a click anywhere on the window + window.GetRootLayer().TouchSignal().Connect( this, &PerfScroll::OnTouch ); + + // Respond to key events + window.KeyEventSignal().Connect( this, &PerfScroll::OnKeyEvent ); mParent = Actor::New(); - mParent.SetAnchorPoint( AnchorPoint::TOP_LEFT ); - stage.Add(mParent); + mParent.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + window.Add(mParent); if( gUseMesh ) { @@ -317,14 +268,20 @@ public: void CreateImageViews() { - Stage stage = Stage::GetCurrent(); + Window window = mApplication.GetWindow(); unsigned int actorCount( mRowsPerPage*mColumnsPerPage * mPageCount ); mImageView.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( 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( 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( 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 ) ); } @@ -419,12 +385,12 @@ public: void ScrollAnimation() { - Stage stage = Stage::GetCurrent(); - Vector3 stageSize( stage.GetSize() ); + Window window = mApplication.GetWindow(); + Vector3 windowSize( window.GetSize() ); mScroll = Animation::New( gDuration ); - mScroll.AnimateBy( Property( mParent, Actor::Property::POSITION ), Vector3( -(gPageCount-1.)*stageSize.x,0.0f, 0.0f) ); + mScroll.AnimateBy( Property( mParent, Actor::Property::POSITION ), Vector3( -(gPageCount-1.)*windowSize.x,0.0f, 0.0f) ); mScroll.Play(); mScroll.FinishedSignal().Connect( this, &PerfScroll::OnAnimationEnd ); } @@ -470,6 +436,17 @@ public: mHide.FinishedSignal().Connect( this, &PerfScroll::OnAnimationEnd ); } + void OnKeyEvent( const KeyEvent& event ) + { + if( event.GetState() == KeyEvent::DOWN ) + { + if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) ) + { + mApplication.Quit(); + } + } + } + private: Application& mApplication; @@ -487,16 +464,7 @@ private: Animation mHide; }; -void RunTest( Application& application ) -{ - PerfScroll 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 ); @@ -517,7 +485,8 @@ int main( int argc, char **argv ) } } - RunTest( application ); + PerfScroll test( application ); + application.MainLoop(); return 0; }