Commit 6dd654db6579d7e4feb3f4c4ade3139123edd227
1 parent
9c0861bc
(perf-scroll) Fix demo so that the animations are not zeroed out
Change-Id: I150ea98a31135243a824556dcfb934f295bf219e
Showing
1 changed file
with
68 additions
and
145 deletions
examples/perf-scroll/perf-scroll.cpp
| ... | ... | @@ -15,14 +15,18 @@ |
| 15 | 15 | * |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | +// EXTERNAL INCLUDES | |
| 18 | 19 | #include <dali-toolkit/dali-toolkit.h> |
| 19 | -#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h> | |
| 20 | +#include <iostream> | |
| 21 | + | |
| 22 | +// INTERNAL INCLUDES | |
| 20 | 23 | #include "generated/perf-scroll-frag.h" |
| 21 | 24 | #include "generated/perf-scroll-vert.h" |
| 22 | 25 | #include "shared/utility.h" |
| 23 | 26 | |
| 24 | 27 | using namespace Dali; |
| 25 | 28 | using namespace Dali::Toolkit; |
| 29 | +using namespace std; | |
| 26 | 30 | |
| 27 | 31 | namespace |
| 28 | 32 | { |
| ... | ... | @@ -138,10 +142,8 @@ const char* NINEPATCH_IMAGE_PATH[] = { |
| 138 | 142 | DEMO_IMAGE_DIR "button-up-17.9.png", |
| 139 | 143 | }; |
| 140 | 144 | |
| 141 | -const unsigned int NUM_IMAGES = sizeof(IMAGE_PATH) / sizeof(char*); | |
| 142 | -const unsigned int NUM_NINEPATCH_IMAGES = sizeof(NINEPATCH_IMAGE_PATH) / sizeof(char*); | |
| 143 | - | |
| 144 | -const float ANIMATION_TIME(5.0f); // animation length in seconds | |
| 145 | +constexpr unsigned int NUM_IMAGES = sizeof(IMAGE_PATH) / sizeof(char*); | |
| 146 | +constexpr unsigned int NUM_NINEPATCH_IMAGES = sizeof(NINEPATCH_IMAGE_PATH) / sizeof(char*); | |
| 145 | 147 | |
| 146 | 148 | struct VertexWithTexture |
| 147 | 149 | { |
| ... | ... | @@ -149,17 +151,19 @@ struct VertexWithTexture |
| 149 | 151 | Vector2 texCoord; |
| 150 | 152 | }; |
| 151 | 153 | |
| 152 | -bool gUseMesh(false); | |
| 153 | -bool gNinePatch(false); | |
| 154 | -unsigned int gRowsPerPage(15); | |
| 155 | -unsigned int gColumnsPerPage(15); | |
| 156 | -unsigned int gPageCount(10); | |
| 157 | -float gDuration(10.0f); | |
| 154 | +bool gUseMesh(false); | |
| 155 | +bool gUseNinePatch(false); | |
| 156 | + | |
| 157 | +constexpr unsigned int ROWS_PER_PAGE(15); | |
| 158 | +constexpr unsigned int COLUMNS_PER_PAGE(15); | |
| 159 | +constexpr unsigned int PAGE_COUNT(10); | |
| 160 | + | |
| 161 | +float gScrollDuration(10.0f); ///< Default animation duration for the scroll, is modifiable with the -t option | |
| 158 | 162 | |
| 159 | 163 | Renderer CreateRenderer(unsigned int index, Geometry geometry, Shader shader) |
| 160 | 164 | { |
| 161 | 165 | Renderer renderer = Renderer::New(geometry, shader); |
| 162 | - const char* imagePath = !gNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index]; | |
| 166 | + const char* imagePath = !gUseNinePatch ? IMAGE_PATH[index] : NINEPATCH_IMAGE_PATH[index]; | |
| 163 | 167 | Texture texture = DemoHelper::LoadTexture(imagePath); |
| 164 | 168 | TextureSet textureSet = TextureSet::New(); |
| 165 | 169 | textureSet.SetTexture(0u, texture); |
| ... | ... | @@ -169,30 +173,28 @@ Renderer CreateRenderer(unsigned int index, Geometry geometry, Shader shader) |
| 169 | 173 | } |
| 170 | 174 | |
| 171 | 175 | } // namespace |
| 172 | -// Test application to compare performance between ImageActor and ImageView | |
| 173 | -// By default, the application consist of 10 pages of 25x25 ImageActors, this can be modified using the following command line arguments: | |
| 174 | -// -t duration (sec ) | |
| 175 | -// --use-imageview ( Use ImageView instead of ImageActor ) | |
| 176 | -// --use-mesh ( Use new renderer API (as ImageView) but shares renderers between actors when possible ) | |
| 177 | 176 | |
| 178 | -// | |
| 177 | +/** | |
| 178 | + * Test application to compare performance between ImageView & manually created Renderers | |
| 179 | + * By default, the application consist of 10 pages of 15x15 Images, this can be modified using the following command line arguments: | |
| 180 | + * -t[duration] (seconds) | |
| 181 | + * --use-mesh (Use Renderer API) | |
| 182 | + * --nine-patch (Use nine-patch images in ImageView) | |
| 183 | + */ | |
| 179 | 184 | class PerfScroll : public ConnectionTracker |
| 180 | 185 | { |
| 181 | 186 | public: |
| 182 | 187 | PerfScroll(Application& application) |
| 183 | 188 | : mApplication(application), |
| 184 | - mRowsPerPage(gRowsPerPage), | |
| 185 | - mColumnsPerPage(gColumnsPerPage), | |
| 186 | - mPageCount(gPageCount) | |
| 189 | + mRowsPerPage(ROWS_PER_PAGE), | |
| 190 | + mColumnsPerPage(COLUMNS_PER_PAGE), | |
| 191 | + mPageCount(PAGE_COUNT) | |
| 187 | 192 | { |
| 188 | 193 | // Connect to the Application's Init signal |
| 189 | 194 | mApplication.InitSignal().Connect(this, &PerfScroll::Create); |
| 190 | 195 | } |
| 191 | 196 | |
| 192 | - ~PerfScroll() | |
| 193 | - { | |
| 194 | - // Nothing to do here; | |
| 195 | - } | |
| 197 | + ~PerfScroll() = default; | |
| 196 | 198 | |
| 197 | 199 | // The Init signal is received once (only) during the Application lifetime |
| 198 | 200 | void Create(Application& application) |
| ... | ... | @@ -225,7 +227,8 @@ public: |
| 225 | 227 | CreateImageViews(); |
| 226 | 228 | } |
| 227 | 229 | |
| 228 | - ShowAnimation(); | |
| 230 | + PositionActors(); | |
| 231 | + ScrollAnimation(); | |
| 229 | 232 | } |
| 230 | 233 | |
| 231 | 234 | bool OnTouch(Actor actor, const TouchEvent& touch) |
| ... | ... | @@ -237,33 +240,30 @@ public: |
| 237 | 240 | |
| 238 | 241 | const char* ImagePath(int i) |
| 239 | 242 | { |
| 240 | - return !gNinePatch ? IMAGE_PATH[i % NUM_IMAGES] : NINEPATCH_IMAGE_PATH[i % NUM_NINEPATCH_IMAGES]; | |
| 243 | + return !gUseNinePatch ? IMAGE_PATH[i % NUM_IMAGES] : NINEPATCH_IMAGE_PATH[i % NUM_NINEPATCH_IMAGES]; | |
| 241 | 244 | } |
| 242 | 245 | |
| 243 | 246 | void CreateImageViews() |
| 244 | 247 | { |
| 245 | 248 | Window window = mApplication.GetWindow(); |
| 246 | 249 | unsigned int actorCount(mRowsPerPage * mColumnsPerPage * mPageCount); |
| 247 | - mImageView.resize(actorCount); | |
| 250 | + mActor.resize(actorCount); | |
| 248 | 251 | |
| 249 | 252 | for(size_t i(0); i < actorCount; ++i) |
| 250 | 253 | { |
| 251 | - mImageView[i] = ImageView::New(); | |
| 254 | + mActor[i] = ImageView::New(); | |
| 252 | 255 | Property::Map propertyMap; |
| 253 | 256 | propertyMap.Insert(Toolkit::ImageVisual::Property::URL, ImagePath(i)); |
| 254 | 257 | propertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE); |
| 255 | - propertyMap.Insert(Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE, Toolkit::DevelVisual::FILL); | |
| 256 | - mImageView[i].SetProperty(Toolkit::ImageView::Property::IMAGE, propertyMap); | |
| 257 | - | |
| 258 | - mImageView[i].SetProperty(Actor::Property::SIZE, Vector3(0.0f, 0.0f, 0.0f)); | |
| 259 | - mImageView[i].SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); | |
| 260 | - mParent.Add(mImageView[i]); | |
| 258 | + mActor[i].SetProperty(Toolkit::ImageView::Property::IMAGE, propertyMap); | |
| 259 | + mActor[i].SetResizePolicy(ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS); | |
| 260 | + mParent.Add(mActor[i]); | |
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | void CreateMeshActors() |
| 265 | 265 | { |
| 266 | - unsigned int numImages = !gNinePatch ? NUM_IMAGES : NUM_NINEPATCH_IMAGES; | |
| 266 | + unsigned int numImages = !gUseNinePatch ? NUM_IMAGES : NUM_NINEPATCH_IMAGES; | |
| 267 | 267 | |
| 268 | 268 | //Create all the renderers |
| 269 | 269 | std::vector<Renderer> renderers(numImages); |
| ... | ... | @@ -282,28 +282,11 @@ public: |
| 282 | 282 | { |
| 283 | 283 | mActor[i] = Actor::New(); |
| 284 | 284 | mActor[i].AddRenderer(renderers[i % numImages]); |
| 285 | - mActor[i].SetProperty(Actor::Property::SIZE, Vector3(0.0f, 0.0f, 0.0f)); | |
| 286 | 285 | mParent.Add(mActor[i]); |
| 287 | 286 | } |
| 288 | 287 | } |
| 289 | 288 | |
| 290 | - void OnAnimationEnd(Animation& source) | |
| 291 | - { | |
| 292 | - if(source == mShow) | |
| 293 | - { | |
| 294 | - ScrollAnimation(); | |
| 295 | - } | |
| 296 | - else if(source == mScroll) | |
| 297 | - { | |
| 298 | - HideAnimation(); | |
| 299 | - } | |
| 300 | - else | |
| 301 | - { | |
| 302 | - mApplication.Quit(); | |
| 303 | - } | |
| 304 | - } | |
| 305 | - | |
| 306 | - void ShowAnimation() | |
| 289 | + void PositionActors() | |
| 307 | 290 | { |
| 308 | 291 | Window window = mApplication.GetWindow(); |
| 309 | 292 | Vector3 initialPosition(window.GetSize().GetWidth() * 0.5f, window.GetSize().GetHeight() * 0.5f, 1000.0f); |
| ... | ... | @@ -312,11 +295,6 @@ public: |
| 312 | 295 | |
| 313 | 296 | size_t count(0); |
| 314 | 297 | float xpos, ypos; |
| 315 | - mShow = Animation::New(0.0f); | |
| 316 | - | |
| 317 | - float totalDuration(0.0f); | |
| 318 | - float durationPerActor(0.0f); | |
| 319 | - float delayBetweenActors = (totalDuration - durationPerActor) / (mRowsPerPage * mColumnsPerPage); | |
| 320 | 298 | |
| 321 | 299 | for(size_t i(0); i < totalColumns; ++i) |
| 322 | 300 | { |
| ... | ... | @@ -325,35 +303,12 @@ public: |
| 325 | 303 | for(size_t j(0); j < mRowsPerPage; ++j) |
| 326 | 304 | { |
| 327 | 305 | ypos = mSize.y * j; |
| 328 | - | |
| 329 | - float delay = 0.0f; | |
| 330 | - float duration = 0.0f; | |
| 331 | - if(count < (static_cast<size_t>(mRowsPerPage) * mColumnsPerPage)) | |
| 332 | - { | |
| 333 | - duration = durationPerActor; | |
| 334 | - delay = delayBetweenActors * count; | |
| 335 | - } | |
| 336 | - if(gUseMesh) | |
| 337 | - { | |
| 338 | - mActor[count].SetProperty(Actor::Property::POSITION, initialPosition); | |
| 339 | - mActor[count].SetProperty(Actor::Property::SIZE, Vector3(0.0f, 0.0f, 0.0f)); | |
| 340 | - mActor[count].SetProperty(Actor::Property::ORIENTATION, Quaternion(Quaternion(Radian(0.0f), Vector3::XAXIS))); | |
| 341 | - 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)); | |
| 342 | - mShow.AnimateTo(Property(mActor[count], Actor::Property::SIZE), mSize, AlphaFunction::EASE_OUT_BACK, TimePeriod(delay, duration)); | |
| 343 | - } | |
| 344 | - else | |
| 345 | - { | |
| 346 | - mImageView[count].SetProperty(Actor::Property::POSITION, initialPosition); | |
| 347 | - mImageView[count].SetProperty(Actor::Property::SIZE, Vector3(0.0f, 0.0f, 0.0f)); | |
| 348 | - mImageView[count].SetProperty(Actor::Property::ORIENTATION, Quaternion(Quaternion(Radian(0.0f), Vector3::XAXIS))); | |
| 349 | - 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)); | |
| 350 | - mShow.AnimateTo(Property(mImageView[count], Actor::Property::SIZE), mSize, AlphaFunction::EASE_OUT_BACK, TimePeriod(delay, duration)); | |
| 351 | - } | |
| 306 | + mActor[count].SetProperty(Actor::Property::POSITION, Vector3(xpos + mSize.x * 0.5f, ypos + mSize.y * 0.5f, 0.0f)); | |
| 307 | + mActor[count].SetProperty(Actor::Property::SIZE, mSize); | |
| 308 | + mActor[count].SetProperty(Actor::Property::ORIENTATION, Quaternion(Radian(0.0f), Vector3::XAXIS)); | |
| 352 | 309 | ++count; |
| 353 | 310 | } |
| 354 | 311 | } |
| 355 | - mShow.Play(); | |
| 356 | - mShow.FinishedSignal().Connect(this, &PerfScroll::OnAnimationEnd); | |
| 357 | 312 | } |
| 358 | 313 | |
| 359 | 314 | void ScrollAnimation() |
| ... | ... | @@ -361,52 +316,10 @@ public: |
| 361 | 316 | Window window = mApplication.GetWindow(); |
| 362 | 317 | Vector3 windowSize(window.GetSize()); |
| 363 | 318 | |
| 364 | - mScroll = Animation::New(gDuration); | |
| 365 | - | |
| 366 | - mScroll.AnimateBy(Property(mParent, Actor::Property::POSITION), Vector3(-(gPageCount - 1.) * windowSize.x, 0.0f, 0.0f)); | |
| 367 | - mScroll.Play(); | |
| 368 | - mScroll.FinishedSignal().Connect(this, &PerfScroll::OnAnimationEnd); | |
| 369 | - } | |
| 370 | - | |
| 371 | - void HideAnimation() | |
| 372 | - { | |
| 373 | - size_t count(0); | |
| 374 | - unsigned int actorsPerPage(mRowsPerPage * mColumnsPerPage); | |
| 375 | - mHide = Animation::New(0.0f); | |
| 376 | - | |
| 377 | - unsigned int totalColumns = mColumnsPerPage * mPageCount; | |
| 378 | - | |
| 379 | - float totalDuration(0.0f); | |
| 380 | - float durationPerActor(0.0f); | |
| 381 | - float delayBetweenActors = (totalDuration - durationPerActor) / (mRowsPerPage * mColumnsPerPage); | |
| 382 | - for(size_t i(0); i < mRowsPerPage; ++i) | |
| 383 | - { | |
| 384 | - for(size_t j(0); j < totalColumns; ++j) | |
| 385 | - { | |
| 386 | - float delay = 0.0f; | |
| 387 | - float duration = 0.0f; | |
| 388 | - if(count < actorsPerPage) | |
| 389 | - { | |
| 390 | - duration = durationPerActor; | |
| 391 | - delay = delayBetweenActors * count; | |
| 392 | - } | |
| 393 | - | |
| 394 | - if(gUseMesh) | |
| 395 | - { | |
| 396 | - mHide.AnimateTo(Property(mActor[count], Actor::Property::ORIENTATION), Quaternion(Radian(Degree(70.0f)), Vector3::XAXIS), AlphaFunction::EASE_OUT, TimePeriod(delay, duration)); | |
| 397 | - mHide.AnimateBy(Property(mActor[count], Actor::Property::POSITION_Z), 1000.0f, AlphaFunction::EASE_OUT_BACK, TimePeriod(delay + delayBetweenActors * actorsPerPage + duration, duration)); | |
| 398 | - } | |
| 399 | - else | |
| 400 | - { | |
| 401 | - mHide.AnimateTo(Property(mImageView[count], Actor::Property::ORIENTATION), Quaternion(Radian(Degree(70.0f)), Vector3::XAXIS), AlphaFunction::EASE_OUT, TimePeriod(delay, duration)); | |
| 402 | - mHide.AnimateBy(Property(mImageView[count], Actor::Property::POSITION_Z), 1000.0f, AlphaFunction::EASE_OUT_BACK, TimePeriod(delay + delayBetweenActors * actorsPerPage + duration, duration)); | |
| 403 | - } | |
| 404 | - ++count; | |
| 405 | - } | |
| 406 | - } | |
| 407 | - | |
| 408 | - mHide.Play(); | |
| 409 | - mHide.FinishedSignal().Connect(this, &PerfScroll::OnAnimationEnd); | |
| 319 | + Animation scrollAnimation = Animation::New(gScrollDuration); | |
| 320 | + scrollAnimation.AnimateBy(Property(mParent, Actor::Property::POSITION), Vector3(-(PAGE_COUNT - 1.) * windowSize.x, 0.0f, 0.0f)); | |
| 321 | + scrollAnimation.Play(); | |
| 322 | + scrollAnimation.FinishedSignal().Connect(this, [&](Animation&) { mApplication.Quit(); }); | |
| 410 | 323 | } |
| 411 | 324 | |
| 412 | 325 | void OnKeyEvent(const KeyEvent& event) |
| ... | ... | @@ -423,24 +336,18 @@ public: |
| 423 | 336 | private: |
| 424 | 337 | Application& mApplication; |
| 425 | 338 | |
| 426 | - std::vector<Actor> mActor; | |
| 427 | - std::vector<ImageView> mImageView; | |
| 428 | - Actor mParent; | |
| 339 | + std::vector<Actor> mActor; | |
| 340 | + Actor mParent; | |
| 429 | 341 | |
| 430 | - Vector3 mSize; | |
| 431 | - unsigned int mRowsPerPage; | |
| 432 | - unsigned int mColumnsPerPage; | |
| 433 | - unsigned int mPageCount; | |
| 342 | + Vector3 mSize; | |
| 434 | 343 | |
| 435 | - Animation mShow; | |
| 436 | - Animation mScroll; | |
| 437 | - Animation mHide; | |
| 344 | + const unsigned int mRowsPerPage; | |
| 345 | + const unsigned int mColumnsPerPage; | |
| 346 | + const unsigned int mPageCount; | |
| 438 | 347 | }; |
| 439 | 348 | |
| 440 | 349 | int DALI_EXPORT_API main(int argc, char** argv) |
| 441 | 350 | { |
| 442 | - Application application = Application::New(&argc, &argv); | |
| 443 | - | |
| 444 | 351 | for(int i(1); i < argc; ++i) |
| 445 | 352 | { |
| 446 | 353 | std::string arg(argv[i]); |
| ... | ... | @@ -450,14 +357,30 @@ int DALI_EXPORT_API main(int argc, char** argv) |
| 450 | 357 | } |
| 451 | 358 | else if(arg.compare("--nine-patch") == 0) |
| 452 | 359 | { |
| 453 | - gNinePatch = true; | |
| 360 | + gUseNinePatch = true; | |
| 454 | 361 | } |
| 455 | 362 | else if(arg.compare(0, 2, "-t") == 0) |
| 456 | 363 | { |
| 457 | - gDuration = atof(arg.substr(2, arg.size()).c_str()); | |
| 364 | + auto newDuration = atof(arg.substr(2, arg.size()).c_str()); | |
| 365 | + if(newDuration > 0.0f) | |
| 366 | + { | |
| 367 | + gScrollDuration = newDuration; | |
| 368 | + } | |
| 369 | + } | |
| 370 | + else if((arg.compare("--help") == 0) || (arg.compare("-h") == 0)) | |
| 371 | + { | |
| 372 | + cout << "perf-scroll.example [OPTIONS]" << endl; | |
| 373 | + cout << " Options:" << endl; | |
| 374 | + cout << " --use-mesh Uses the Rendering API directly to create actors" << endl; | |
| 375 | + cout << " --nine-patch Uses n-patch images instead" << endl; | |
| 376 | + cout << " -t[seconds] Replace [seconds] with the animation time required, i.e. -t4. Default is 10s." << endl; | |
| 377 | + cout << " -h|--help Help" << endl; | |
| 378 | + return 0; | |
| 458 | 379 | } |
| 459 | 380 | } |
| 460 | 381 | |
| 382 | + Application application = Application::New(&argc, &argv); | |
| 383 | + | |
| 461 | 384 | PerfScroll test(application); |
| 462 | 385 | application.MainLoop(); |
| 463 | 386 | ... | ... |