Fix PageFactory to take in Texture rather than Image 11/94011/3
authorKimmo Hoikka <kimmo.hoikka@samsung.com>
Wed, 26 Oct 2016 16:54:39 +0000 (17:54 +0100)
committerKimmo Hoikka <kimmo.hoikka@samsung.com>
Wed, 26 Oct 2016 18:06:10 +0000 (19:06 +0100)
Change-Id: Ie052ab83ec8be585c2e6caad1e2b4345a1321be3

automated-tests/src/dali-toolkit/utc-Dali-PageTurnView.cpp
dali-toolkit/devel-api/controls/page-turn-view/page-factory.h
dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.cpp
dali-toolkit/internal/controls/page-turn-view/page-turn-view-impl.h

index ab4551f..85ba766 100644 (file)
@@ -21,7 +21,6 @@
 #include <sstream>
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali/integration-api/events/pan-gesture-event.h>
-#include <dali/public-api/images/buffer-image.h>
 #include <dali-toolkit/devel-api/controls/page-turn-view/page-factory.h>
 #include <dali-toolkit/devel-api/controls/page-turn-view/page-turn-landscape-view.h>
 #include <dali-toolkit/devel-api/controls/page-turn-view/page-turn-portrait-view.h>
@@ -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<float>( IMAGE_WIDTH ), static_cast<float>(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;
+}
+
index cc12134..64432b4 100644 (file)
@@ -19,7 +19,7 @@
  */
 
 // EXTERNAL INCLUDES
-#include <dali/public-api/actors/actor.h>
+#include <dali/public-api/rendering/texture.h>
 
 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.
    */
index f6d5e7a..8c2cc41 100644 (file)
 #include <cstring> // for strcmp
 #include <dali/public-api/animation/animation.h>
 #include <dali/public-api/animation/constraint.h>
-#include <dali/public-api/images/resource-image.h>
 #include <dali/public-api/object/type-registry.h>
 #include <dali/public-api/object/type-registry-helper.h>
-#include <dali/devel-api/images/texture-set-image.h>
 #include <dali/integration-api/debug.h>
 
 // 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 );
   }
 }
 
index 2d40717..73aff02 100644 (file)
@@ -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.