From d73ee69e784206f6ad976ffce664e424da68ba8f Mon Sep 17 00:00:00 2001 From: Kimmo Hoikka Date: Wed, 26 Oct 2016 17:54:39 +0100 Subject: [PATCH] Fix PageFactory to take in Texture rather than Image Change-Id: Ie052ab83ec8be585c2e6caad1e2b4345a1321be3 --- .../src/dali-toolkit/utc-Dali-PageTurnView.cpp | 51 ++++++++++++++++++---- .../controls/page-turn-view/page-factory.h | 17 +++----- .../page-turn-view/page-turn-view-impl.cpp | 26 ++++------- .../controls/page-turn-view/page-turn-view-impl.h | 6 +-- 4 files changed, 60 insertions(+), 40 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-PageTurnView.cpp b/automated-tests/src/dali-toolkit/utc-Dali-PageTurnView.cpp index ab4551f..85ba766 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-PageTurnView.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-PageTurnView.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -35,9 +34,6 @@ namespace const int RENDER_FRAME_INTERVAL = 16; ///< Duration of each frame in ms. (at approx 60FPS) const unsigned int TOTAL_PAGE_NUMBER = 20; const Vector2 PAGE_SIZE( 300.f,400.f ); -const unsigned int IMAGE_WIDTH = 30; -const unsigned int IMAGE_HEIGHT = 30; -const Vector2 IMAGE_SIZE( static_cast( IMAGE_WIDTH ), static_cast(IMAGE_HEIGHT) ); const Vector2 SPINE_SHADOW_PARAMETER( 60.0f, 30.0f ); static bool gObjectCreatedCallBackCalled; @@ -189,8 +185,9 @@ class TestPageFactory : public PageFactory { public: - TestPageFactory(ToolkitTestApplication& application) - : mApplication( application ) + TestPageFactory(ToolkitTestApplication& application, bool returnValidTexture = true ) + : mApplication( application ), + mValidTexture( returnValidTexture ) { mTotalPageNumber = TOTAL_PAGE_NUMBER; } @@ -205,18 +202,23 @@ public: } /** - * Create an image to represent a page content. + * Create an texture to represent a page content. * @param[in] pageId The ID of the page to create. * @return An image, or an empty handle if the ID is out of range. */ - virtual Image NewPage( unsigned int pageId ) + virtual Texture NewPage( unsigned int pageId ) { - return BufferImage::WHITE(); + if( mValidTexture ) + { + return Texture::New( Dali::TextureType::TEXTURE_2D, Pixel::RGB888, 100, 100 ); + } + return Texture(); // empty handle } private: ToolkitTestApplication& mApplication; unsigned int mTotalPageNumber; + bool mValidTexture; }; }// namespace @@ -689,3 +691,34 @@ int UtcDaliPageImageFactoryGetExtention(void) DALI_TEST_CHECK( factory.GetExtension() == NULL ); END_TEST; } + +int UtcDaliPageTurnEmptyTextureHandle(void) +{ + ToolkitTestApplication application; + + tet_infoline(" UtcDaliPageTurnEmptyTextureHandle "); + + application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE ); + + TestPageFactory factory(application, false); // returns empty handles + Vector2 size = Stage::GetCurrent().GetSize(); + try + { + PageTurnView portraitView = PageTurnPortraitView::New( factory, size ); + portraitView.SetParentOrigin( ParentOrigin::CENTER ); + Stage::GetCurrent().Add( portraitView ); + + tet_result(TET_FAIL); + } + catch (DaliException& e) + { + DALI_TEST_ASSERT(e, "must pass in valid texture", TEST_LOCATION ); + } + catch (...) + { + tet_result(TET_FAIL); + } + + END_TEST; +} + diff --git a/dali-toolkit/devel-api/controls/page-turn-view/page-factory.h b/dali-toolkit/devel-api/controls/page-turn-view/page-factory.h index cc12134..64432b4 100644 --- a/dali-toolkit/devel-api/controls/page-turn-view/page-factory.h +++ b/dali-toolkit/devel-api/controls/page-turn-view/page-factory.h @@ -19,7 +19,7 @@ */ // EXTERNAL INCLUDES -#include +#include namespace Dali { @@ -28,7 +28,7 @@ namespace Toolkit { /** - * @brief PageFactory is an abstract interface for providing images to PageTurnView + * @brief PageFactory is an abstract interface for providing textures to PageTurnView * Each page is identified by a unique ID, and has a linear order from 0 to GetNumberOfPages()-1 * * @SINCE_1_1.4 @@ -41,7 +41,6 @@ public: /** * @brief Virtual destructor - * @SINCE_1_1.4 */ virtual ~PageFactory(){}; @@ -49,26 +48,24 @@ public: * @brief Query the number of pages available from the factory. * * The maximum available page has an ID of GetNumberOfPages()-1. - * @SINCE_1_1.4 * @return The page count. */ virtual unsigned int GetNumberOfPages() = 0; /** - * @brief Create an actor to represent the page content. - * @SINCE_1_1.30 + * @brief Return the texture for the page * - * If no valid image provided, a broken image is displayed. - * For double-sided page( PageTurnLandscapeView ), the left half of image is used as page front side, and the right half as page back side. + * For double-sided page( PageTurnLandscapeView ), the left half of texture is used as page front side, and the right half as page back side. + * + * @note Must return a valid texture handle! * * @param[in] pageId The ID of the page to create. * @return An actor, or an uninitialized pointer if the ID is out of range. */ - virtual Image NewPage( unsigned int pageId ) = 0; + virtual Texture NewPage( unsigned int pageId ) = 0; /** * @brief Retrieve the extension for this factory - * @SINCE_1_1.30 * * @return The extension if available, NULL otherwise. */ diff --git a/dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.cpp b/dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.cpp index f6d5e7a..8c2cc41 100644 --- a/dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.cpp +++ b/dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.cpp @@ -22,10 +22,8 @@ #include // for strcmp #include #include -#include #include #include -#include #include // INTERNAL INCLUDES @@ -39,9 +37,6 @@ using namespace Dali; namespace //Unnamed namespace { -// broken image is loaded if there is no valid image provided for the page -const char * const BROKEN_IMAGE_URL( DALI_IMAGE_DIR "broken.png"); - // properties set on shader, these properties have the constant value in regardless of the page status const char * const PROPERTY_SPINE_SHADOW ( "uSpineShadowParameter" ); // uniform for both spine and turn effect @@ -282,14 +277,13 @@ PageTurnView::Page::Page() propertyTurnDirection = actor.RegisterProperty(PROPERTY_TURN_DIRECTION, -1.f); } -void PageTurnView::Page::SetImage( Image image ) +void PageTurnView::Page::SetTexture( Texture texture ) { if( !textureSet ) { textureSet = TextureSet::New(); } - - TextureSetImage( textureSet, 0u, image ); + textureSet.SetTexture( 0u, texture ); } void PageTurnView::Page::UseEffect(Shader newShader) @@ -398,7 +392,7 @@ void PageTurnView::OnInitialize() Self().Add( mPages[i].actor ); } - // create the layer for turning images + // create the layer for turning pages mTurningPageLayer = Layer::New(); mTurningPageLayer.SetAnchorPoint( AnchorPoint::CENTER_LEFT ); mTurningPageLayer.SetBehavior(Layer::LAYER_3D); @@ -584,13 +578,9 @@ void PageTurnView::AddPage( int pageIndex ) { int index = pageIndex % NUMBER_OF_CACHED_PAGES; - Image newPageImage; - newPageImage = mPageFactory->NewPage( pageIndex ); - - if( !newPageImage ) // load the broken image - { - newPageImage = ResourceImage::New( BROKEN_IMAGE_URL ); - } + Texture newPage; + newPage = mPageFactory->NewPage( pageIndex ); + DALI_ASSERT_ALWAYS( newPage && "must pass in valid texture" ); bool isLeftSide = ( pageIndex < mCurrentPageIndex ); if( mPages[index].isTurnBack != isLeftSide ) @@ -602,11 +592,11 @@ void PageTurnView::AddPage( int pageIndex ) mPages[index].actor.SetOrientation( Degree( degree ), Vector3::YAXIS ); mPages[index].actor.SetVisible( false ); mPages[index].UseEffect( mSpineEffectShader, mGeometry ); - mPages[index].SetImage( newPageImage ); + mPages[index].SetTexture( newPage ); // For Portrait, nothing to do // For Landscape, set the parent origin to CENTER - OnAddPage( mPages[index].actor, isLeftSide ); + OnAddPage( mPages[index].actor, isLeftSide ); } } diff --git a/dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.h b/dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.h index 2d40717..73aff02 100644 --- a/dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.h +++ b/dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.h @@ -57,10 +57,10 @@ protected: ~Page(){}; /** - * Set the page image content - * @param[in] image The content of the page. + * Set the page texture content + * @param[in] texture The content of the page. */ - void SetImage( Image image ); + void SetTexture( Texture texture ); /** * Apply an effect onto the page actor. -- 2.7.4