[dali_2.1.18] Merge branch 'devel/master' 48/273848/1
authorRichard Huang <r.huang@samsung.com>
Thu, 14 Apr 2022 10:36:15 +0000 (11:36 +0100)
committerRichard Huang <r.huang@samsung.com>
Thu, 14 Apr 2022 10:36:15 +0000 (11:36 +0100)
Change-Id: Id3aecc66081d0ba2413534d44c0d88edfc23078f

53 files changed:
automated-tests/src/dali-toolkit-internal/utc-Dali-TextureManager.cpp
automated-tests/src/dali-toolkit/CMakeLists.txt
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.h
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-reflection.cpp
automated-tests/src/dali-toolkit/utc-Dali-AnimatedImageVisual.cpp
automated-tests/src/dali-toolkit/utc-Dali-GlViewDirectRendering.cpp [new file with mode: 0644]
automated-tests/src/dali-toolkit/utc-Dali-ImageView.cpp
automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp
automated-tests/src/dali-toolkit/utc-Dali-TextSelectionPopup.cpp
automated-tests/src/dali-toolkit/utc-Dali-VisualFactory.cpp
dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h
dali-toolkit/internal/controls/gl-view/drawable-view-impl.cpp [new file with mode: 0644]
dali-toolkit/internal/controls/gl-view/drawable-view-impl.h [new file with mode: 0644]
dali-toolkit/internal/controls/gl-view/gl-view-impl.cpp
dali-toolkit/internal/controls/gl-view/gl-view-impl.h
dali-toolkit/internal/controls/gl-view/gl-view-interface-impl.h [new file with mode: 0644]
dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp
dali-toolkit/internal/controls/text-controls/text-editor-property-handler.cpp
dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.cpp
dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h
dali-toolkit/internal/controls/text-controls/text-selection-popup-property-handler.cpp [new file with mode: 0644]
dali-toolkit/internal/controls/text-controls/text-selection-popup-property-handler.h [new file with mode: 0644]
dali-toolkit/internal/file.list
dali-toolkit/internal/text/text-controller-impl.cpp
dali-toolkit/internal/text/text-controller-relayouter.cpp
dali-toolkit/internal/text/text-controller-relayouter.h
dali-toolkit/internal/texture-manager/texture-cache-manager.cpp
dali-toolkit/internal/texture-manager/texture-cache-manager.h
dali-toolkit/internal/texture-manager/texture-manager-impl.cpp
dali-toolkit/internal/texture-manager/texture-manager-impl.h
dali-toolkit/internal/texture-manager/texture-manager-type.h
dali-toolkit/internal/texture-manager/texture-upload-observer.cpp
dali-toolkit/internal/texture-manager/texture-upload-observer.h
dali-toolkit/internal/visuals/animated-image/animated-image-visual.cpp
dali-toolkit/internal/visuals/animated-image/animated-image-visual.h
dali-toolkit/internal/visuals/animated-image/fixed-image-cache.cpp
dali-toolkit/internal/visuals/animated-image/fixed-image-cache.h
dali-toolkit/internal/visuals/animated-image/image-cache.cpp
dali-toolkit/internal/visuals/animated-image/image-cache.h
dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.cpp
dali-toolkit/internal/visuals/animated-image/rolling-animated-image-cache.h
dali-toolkit/internal/visuals/animated-image/rolling-image-cache.cpp
dali-toolkit/internal/visuals/animated-image/rolling-image-cache.h
dali-toolkit/internal/visuals/npatch-data.cpp
dali-toolkit/internal/visuals/npatch-data.h
dali-toolkit/internal/visuals/npatch-loader.cpp
dali-toolkit/internal/visuals/npatch-loader.h
dali-toolkit/internal/visuals/npatch/npatch-visual.cpp
dali-toolkit/internal/visuals/visual-factory-cache.cpp
dali-toolkit/public-api/controls/gl-view/gl-view.cpp
dali-toolkit/public-api/controls/gl-view/gl-view.h
dali-toolkit/public-api/dali-toolkit-version.cpp
packaging/dali-toolkit.spec

index 6ec8617..e8088a3 100644 (file)
@@ -591,6 +591,158 @@ int UtcTextureManagerUseInvalidMask(void)
   END_TEST;
 }
 
+int UtcTextureManagerUseInvalidMaskAndMaskLoadedFirst(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded first");
+  tet_infoline("Try to check PostLoad works well");
+
+  TextureManager textureManager; // Create new texture manager
+
+  TestObserver                       observer;
+  std::string                        filename(TEST_IMAGE_FILE_NAME);
+  std::string                        maskname("invalid.png");
+  TextureManager::MaskingDataPointer maskInfo = nullptr;
+  maskInfo.reset(new TextureManager::MaskingData());
+  maskInfo->mAlphaMaskUrl       = maskname;
+  maskInfo->mAlphaMaskId        = TextureManager::INVALID_TEXTURE_ID;
+  maskInfo->mCropToMask         = true;
+  maskInfo->mContentScaleFactor = 1.0f;
+
+  auto                          textureId(TextureManager::INVALID_TEXTURE_ID);
+  Vector4                       atlasRect(0.f, 0.f, 1.f, 1.f);
+  Dali::ImageDimensions         atlasRectSize(0, 0);
+  bool                          synchronousLoading(false);
+  bool                          atlasingStatus(false);
+  bool                          loadingStatus(false);
+  auto                          preMultiply         = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
+  ImageAtlasManagerPtr          atlasManager        = nullptr;
+  Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
+
+  textureManager.LoadTexture(
+    filename,
+    ImageDimensions(),
+    FittingMode::SCALE_TO_FILL,
+    SamplingMode::BOX_THEN_LINEAR,
+    maskInfo,
+    synchronousLoading,
+    textureId,
+    atlasRect,
+    atlasRectSize,
+    atlasingStatus,
+    loadingStatus,
+    WrapMode::DEFAULT,
+    WrapMode::DEFAULT,
+    &observer,
+    atlasUploadObserver,
+    atlasManager,
+    true,
+    TextureManager::ReloadPolicy::CACHED,
+    preMultiply);
+
+  DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
+  DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
+  DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
+  DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcTextureManagerUseInvalidMaskAndMaskLoadedLater(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcTextureManagerUseInvalidMask when normal image loaded first, and mask image loaded later");
+  tet_infoline("Try to check CheckForWaitingTexture called");
+
+  TextureManager textureManager; // Create new texture manager
+
+  TestObserver                       observer;
+  std::string                        filename(TEST_IMAGE_FILE_NAME);
+  std::string                        maskname("invalid.png");
+  TextureManager::MaskingDataPointer maskInfo = nullptr;
+  maskInfo.reset(new TextureManager::MaskingData());
+  maskInfo->mAlphaMaskUrl       = maskname;
+  maskInfo->mAlphaMaskId        = TextureManager::INVALID_TEXTURE_ID;
+  maskInfo->mCropToMask         = true;
+  maskInfo->mContentScaleFactor = 1.0f;
+
+  auto                          textureId(TextureManager::INVALID_TEXTURE_ID);
+  Vector4                       atlasRect(0.f, 0.f, 1.f, 1.f);
+  Dali::ImageDimensions         atlasRectSize(0, 0);
+  bool                          synchronousLoading(false);
+  bool                          atlasingStatus(false);
+  bool                          loadingStatus(false);
+  auto                          preMultiply         = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
+  ImageAtlasManagerPtr          atlasManager        = nullptr;
+  Toolkit::AtlasUploadObserver* atlasUploadObserver = nullptr;
+
+  textureManager.LoadTexture(
+    filename,
+    ImageDimensions(),
+    FittingMode::SCALE_TO_FILL,
+    SamplingMode::BOX_THEN_LINEAR,
+    maskInfo,
+    synchronousLoading,
+    textureId,
+    atlasRect,
+    atlasRectSize,
+    atlasingStatus,
+    loadingStatus,
+    WrapMode::DEFAULT,
+    WrapMode::DEFAULT,
+    &observer,
+    atlasUploadObserver,
+    atlasManager,
+    true,
+    TextureManager::ReloadPolicy::CACHED,
+    preMultiply);
+
+  DALI_TEST_EQUALS(observer.mLoaded, false, TEST_LOCATION);
+  DALI_TEST_EQUALS(observer.mObserverCalled, false, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  // CAPTION : HARD-CODING for coverage. If you are a good boy, Do not follow this code.
+  {
+    Dali::Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(
+      filename,
+      ImageDimensions(),
+      FittingMode::SCALE_TO_FILL,
+      SamplingMode::BOX_THEN_LINEAR,
+      true, ///< synchronousLoading
+      nullptr,
+      true, ///< orientationCorrection
+      preMultiply);
+
+    textureManager.AsyncLoadComplete(textureId, pixelBuffer);
+    textureManager.AsyncLoadComplete(maskInfo->mAlphaMaskId, Dali::Devel::PixelBuffer());
+    textureManager.Remove(maskInfo->mAlphaMaskId, nullptr);
+    textureManager.Remove(textureId, &observer);
+  }
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(observer.mLoaded, true, TEST_LOCATION);
+  DALI_TEST_EQUALS(observer.mObserverCalled, true, TEST_LOCATION);
+  DALI_TEST_EQUALS(observer.mCompleteType, TestObserver::CompleteType::UPLOAD_COMPLETE, TEST_LOCATION);
+
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcTextureManagerSynchronousLoadingFail(void)
 {
   ToolkitTestApplication application;
index 641a9df..1dbbf90 100755 (executable)
@@ -79,6 +79,7 @@ SET(TC_SOURCES
   utc-Dali-DragAndDropDetector.cpp
   utc-Dali-NPatchUtilities.cpp
   utc-Dali-GlView.cpp
+  utc-Dali-GlViewDirectRendering.cpp
 )
 
 # List of test harness files (Won't get parsed for test cases)
index cc7fac4..a1f8405 100644 (file)
@@ -997,10 +997,17 @@ public:
       {
         name            = uniform.name.substr(0, iter);
         auto arrayCount = std::stoi(uniform.name.substr(iter + 1));
+        iter            = uniform.name.find("]");
+        std::string suffix;
+        if(iter != std::string::npos && iter + 1 != uniform.name.length())
+        {
+          suffix = uniform.name.substr(iter + 1); // If there is a suffix, it means its an element of an array of struct
+        }
+
         for(int i = 0; i < arrayCount; ++i)
         {
           std::stringstream nss;
-          nss << name << "[" << i << "]";
+          nss << name << "[" << i << "]" << suffix;
           GetUniformLocation(program, nss.str().c_str()); // Generate a GL loc per element
         }
       }
index 5b3da8c..6cb90ba 100644 (file)
@@ -147,8 +147,6 @@ TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, uint32_t p
   for(const auto& data : mCustomUniforms)
   {
     fprintf(stderr, "\ncustom uniforms: %s\n", data.name.c_str());
-    mDefaultUniformBlock.members.emplace_back();
-    auto& item = mDefaultUniformBlock.members.back();
 
     auto iter        = data.name.find("[", 0);
     int  numElements = 1;
@@ -161,26 +159,60 @@ TestGraphicsReflection::TestGraphicsReflection(TestGlAbstraction& gl, uint32_t p
       {
         numElements = 1;
       }
-
-      item.name         = baseName;
-      item.binding      = 0;
-      item.bufferIndex  = 0;
-      item.uniformClass = Graphics::UniformClass::UNIFORM;
-      item.type         = data.type;
-      item.numElements  = numElements;
-
-      for(int i = 0; i < numElements; ++i)
+      iter = data.name.find("]");
+      std::string suffix;
+      if(iter != std::string::npos && iter + 1 != data.name.length())
       {
-        std::stringstream elementNameStream;
-        elementNameStream << baseName << "[" << i << "]";
+        suffix = data.name.substr(iter + 1); // If there is a suffix, it means it is an element of an array of struct
+      }
 
-        item.locations.push_back(gl.GetUniformLocation(programId, elementNameStream.str().c_str()));
-        item.offsets.push_back(offset);
-        offset += GetSizeForType(data.type);
+      if(!suffix.empty())
+      {
+        // Write multiple items
+        for(int i = 0; i < numElements; ++i)
+        {
+          std::stringstream elementNameStream;
+          elementNameStream << baseName << "[" << i << "]" << suffix;
+          mDefaultUniformBlock.members.emplace_back();
+          auto& item   = mDefaultUniformBlock.members.back();
+          item.name    = elementNameStream.str();
+          item.binding = 0;
+          item.offsets.push_back(offset);
+          item.locations.push_back(gl.GetUniformLocation(programId, elementNameStream.str().c_str()));
+          item.bufferIndex  = 0;
+          item.uniformClass = Graphics::UniformClass::UNIFORM;
+          item.type         = data.type;
+          offset += GetSizeForType(data.type);
+        }
+      }
+      else
+      {
+        // Write 1 item with multiple elements
+        mDefaultUniformBlock.members.emplace_back();
+        auto& item = mDefaultUniformBlock.members.back();
+
+        item.name         = baseName;
+        item.binding      = 0;
+        item.bufferIndex  = 0;
+        item.uniformClass = Graphics::UniformClass::UNIFORM;
+        item.type         = data.type;
+        item.numElements  = numElements;
+
+        for(int i = 0; i < numElements; ++i)
+        {
+          std::stringstream elementNameStream;
+          elementNameStream << baseName << "[" << i << "]";
+          item.locations.push_back(gl.GetUniformLocation(programId, elementNameStream.str().c_str()));
+          item.offsets.push_back(offset);
+          offset += GetSizeForType(data.type);
+        }
       }
     }
     else
     {
+      // Write 1 item with 1 element
+      mDefaultUniformBlock.members.emplace_back();
+      auto& item   = mDefaultUniformBlock.members.back();
       item.name    = data.name;
       item.binding = 0;
       item.offsets.push_back(offset);
index 0d2efcc..1fffc97 100644 (file)
@@ -306,7 +306,9 @@ int UtcDaliAnimatedImageVisualGetPropertyMap04(void)
       .Add(ImageVisual::Property::URL, TEST_GIF_FILE_NAME)
       .Add(ImageVisual::Property::BATCH_SIZE, 1)
       .Add(ImageVisual::Property::CACHE_SIZE, 1)
-      .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, false)
+      .Add(ImageVisual::Property::SYNCHRONOUS_LOADING, true)
+      .Add(ImageVisual::Property::RELEASE_POLICY, ImageVisual::ReleasePolicy::DETACHED)
+      .Add(ImageVisual::Property::LOAD_POLICY, ImageVisual::LoadPolicy::ATTACHED)
       .Add(DevelVisual::Property::BORDERLINE_WIDTH, 0.4f));
 
   Property::Map resultMap;
@@ -329,6 +331,18 @@ int UtcDaliAnimatedImageVisualGetPropertyMap04(void)
   DALI_TEST_CHECK(value);
   DALI_TEST_CHECK(value->Get<int>() == 2);
 
+  value = resultMap.Find(ImageVisual::Property::SYNCHRONOUS_LOADING, Property::BOOLEAN);
+  DALI_TEST_CHECK(value);
+  DALI_TEST_CHECK(value->Get<bool>() == true);
+
+  value = resultMap.Find(ImageVisual::Property::RELEASE_POLICY, Property::INTEGER);
+  DALI_TEST_CHECK(value);
+  DALI_TEST_CHECK(value->Get<int>() == ImageVisual::ReleasePolicy::DETACHED);
+
+  value = resultMap.Find(ImageVisual::Property::LOAD_POLICY, Property::INTEGER);
+  DALI_TEST_CHECK(value);
+  DALI_TEST_CHECK(value->Get<int>() == ImageVisual::LoadPolicy::ATTACHED);
+
   value = resultMap.Find(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, "totalFrameNumber");
   DALI_TEST_CHECK(value);
   DALI_TEST_EQUALS(value->Get<int>(), 4, TEST_LOCATION);
@@ -427,7 +441,8 @@ int UtcDaliAnimatedImageVisualSynchronousLoading(void)
     application.SendNotification();
     application.Render(20);
 
-    DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
+    // The first frame is loaded synchronously and load next batch.
+    DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
 
     application.SendNotification();
     application.Render();
@@ -440,12 +455,12 @@ int UtcDaliAnimatedImageVisualSynchronousLoading(void)
     application.SendNotification();
     application.Render(20);
 
-    DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
+    DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
 
     application.SendNotification();
     application.Render();
 
-    DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 3, TEST_LOCATION);
+    DALI_TEST_EQUALS(gl.GetNumGeneratedTextures(), 2, TEST_LOCATION);
 
     dummyControl.Unparent();
   }
diff --git a/automated-tests/src/dali-toolkit/utc-Dali-GlViewDirectRendering.cpp b/automated-tests/src/dali-toolkit/utc-Dali-GlViewDirectRendering.cpp
new file mode 100644 (file)
index 0000000..82e3be9
--- /dev/null
@@ -0,0 +1,388 @@
+/*
+ * Copyright (c) 2022 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <unistd.h>
+#include <thread>
+
+#include <dali-toolkit-test-suite-utils.h>
+
+#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/public-api/controls/gl-view/gl-view.h>
+#include <dali/devel-api/adaptor-framework/window-devel.h>
+
+using namespace Dali;
+using namespace Dali::Toolkit;
+
+// Positive test case for a method
+int UtcDaliGlViewDirectRenderingNew(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliGlViewDirectRenderingNew");
+  GlView view = GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGBA8888);
+  DALI_TEST_CHECK(view);
+
+  auto mode1 = view.GetBackendMode();
+
+  DALI_TEST_EQUALS(mode1, GlView::BackendMode::DIRECT_RENDERING, TEST_LOCATION);
+
+  GlView view2 = GlView::New(GlView::BackendMode::EGL_IMAGE_OFFSCREEN_RENDERING, GlView::ColorFormat::RGBA8888);
+  DALI_TEST_CHECK(view2);
+
+  auto mode2 = view2.GetBackendMode();
+  DALI_TEST_EQUALS(mode2, GlView::BackendMode::EGL_IMAGE_OFFSCREEN_RENDERING, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliGlViewDirectRenderingNewN(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliGlViewDirectRenderingNewN");
+  // Invalid backend mode
+  GlView view = GlView::New(GlView::BackendMode(11111), GlView::ColorFormat::RGBA8888);
+  DALI_TEST_CHECK(!view);
+
+  END_TEST;
+}
+
+// Positive test case for a method
+int UtcDaliGlViewDirectRenderingDownCast(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliGlViewDirectRenderingDownCast");
+
+  GlView     view = GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
+  BaseHandle handle(view);
+
+  Toolkit::GlView view2 = Toolkit::GlView::DownCast(handle);
+  DALI_TEST_CHECK(view);
+  DALI_TEST_CHECK(view2);
+  DALI_TEST_CHECK(view == view2);
+  END_TEST;
+}
+
+int UtcDaliGlViewDirectRenderingCopyAndAssignment(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliGlViewDirectRenderingCopyAndAssignment");
+
+  GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
+  DALI_TEST_CHECK(view);
+
+  GlView copy(view);
+  DALI_TEST_CHECK(view == copy);
+
+  GlView assign;
+  DALI_TEST_CHECK(!assign);
+
+  assign = copy;
+  DALI_TEST_CHECK(assign == view);
+
+  END_TEST;
+}
+
+int UtcDaliGlViewDirectRenderingMoveAssignment(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliGlViewDirectRenderingMoveAssignment");
+
+  GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
+  DALI_TEST_EQUALS(1, view.GetBaseObject().ReferenceCount(), TEST_LOCATION);
+
+  GlView moved;
+  moved = std::move(view);
+  DALI_TEST_CHECK(moved);
+  DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
+  DALI_TEST_CHECK(!view);
+
+  END_TEST;
+}
+
+int UtcDaliGlViewDirectRenderingSetGraphicsConfigGles20N(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliGlViewDirectRenderingSetGraphicsConfigGles20");
+  GlView view;
+  try
+  {
+    view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
+    DALI_TEST_CHECK(false);
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(true);
+  }
+  END_TEST;
+}
+
+int UtcDaliGlViewDirectRenderingSetGraphicsConfigGles30(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliGlViewDirectRenderingSetGraphicsConfigGles30");
+  GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
+
+  try
+  {
+    view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_3_0);
+    DALI_TEST_CHECK(true);
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(false);
+  }
+  END_TEST;
+}
+
+int UtcDaliGlViewDirectRenderingRenderingMode(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliGlViewDirectRenderingRenderingMode");
+  GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
+
+  view.SetRenderingMode(GlView::RenderingMode::ON_DEMAND);
+
+  GlView::RenderingMode mode = view.GetRenderingMode();
+
+  DALI_TEST_EQUALS(GlView::RenderingMode::ON_DEMAND, mode, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliGlViewDirectRenderingOnSizeSet(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliGlViewDirectRenderingOnSizeSet");
+  GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
+
+  application.GetScene().Add(view);
+
+  application.SendNotification();
+  application.Render();
+
+  Vector3 size(200.0f, 300.0f, 0.0f);
+  view.SetProperty(Actor::Property::SIZE, size);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(view.GetCurrentProperty<Vector3>(Actor::Property::SIZE), size, TEST_LOCATION);
+
+  END_TEST;
+}
+
+namespace DirectRenderingCode
+{
+
+// Internal callback function
+void glInit(void)
+{
+}
+
+int glRenderFrame(void)
+{
+  static unsigned int retFlag = 0;
+  return retFlag++;
+}
+
+void glTerminate(void)
+{
+}
+
+void resizeCB(Vector2 size)
+{
+}
+
+}
+
+int UtcDaliGlViewDirectRenderingRegisterGlCallbacksN(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliGlViewDirectRenderingRegisterGlCallbacksN");
+  GlView view;
+
+  try
+  {
+    view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrame), Dali::MakeCallback(DirectRenderingCode::glTerminate));
+    DALI_TEST_CHECK(false);
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(true);
+  }
+  END_TEST;
+}
+
+int UtcDaliGlViewDirectRenderingSetResizeCallbackN(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliGlViewDirectRenderingSetResizeCallback");
+  GlView view;
+
+  try
+  {
+    view.SetResizeCallback(Dali::MakeCallback(DirectRenderingCode::resizeCB));
+    DALI_TEST_CHECK(false);
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(true);
+  }
+  END_TEST;
+}
+
+int UtcDaliGlViewDirectRenderingRenderOnce(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliGlViewDirectRenderingRenderOnce");
+  GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
+
+  try
+  {
+    view.RenderOnce();
+    DALI_TEST_CHECK(true);
+  }
+  catch(...)
+  {
+    DALI_TEST_CHECK(false);
+  }
+  END_TEST;
+}
+
+int UtcDaliGlViewDirectRenderingWindowVisibilityChanged(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliGlViewDirectRenderingWindowVisibilityChanged");
+  GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
+  application.GetScene().Add(view);
+  view.SetRenderingMode(GlView::RenderingMode::CONTINUOUS);
+  view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
+  view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrame), Dali::MakeCallback(DirectRenderingCode::glTerminate));
+  view.SetResizeCallback(Dali::MakeCallback(DirectRenderingCode::resizeCB));
+
+  application.SendNotification();
+  application.Render();
+
+  Window window = DevelWindow::Get(view);
+  window.Hide();
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_CHECK(true);
+  END_TEST;
+}
+
+int UtcDaliGlViewDirectRenderingOnScene(void)
+{
+  ToolkitTestApplication application;
+
+  GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
+
+  //Onscene
+  application.GetScene().Add(view);
+  view.SetRenderingMode(GlView::RenderingMode::CONTINUOUS);
+  view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
+  view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrame), Dali::MakeCallback(DirectRenderingCode::glTerminate));
+
+  application.SendNotification();
+  application.Render();
+
+  //Offscene
+  application.GetScene().Remove(view);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_CHECK(true);
+  END_TEST;
+}
+
+int UtcDaliGlViewDirectRenderingControlVisibilityChanged(void)
+{
+  ToolkitTestApplication application;
+
+  GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
+  application.GetScene().Add(view);
+
+  application.SendNotification();
+  application.Render();
+
+  view.SetProperty(Actor::Property::VISIBLE, false);
+  application.SendNotification();
+  application.Render();
+  DALI_TEST_CHECK(view.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == false);
+
+  view.SetProperty(Actor::Property::VISIBLE, true);
+  application.SendNotification();
+  application.Render();
+  DALI_TEST_CHECK(view.GetCurrentProperty<bool>(Actor::Property::VISIBLE) == true);
+
+  END_TEST;
+}
+
+int UtcDaliGlViewDirectRenderingResize(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliGlViewDirectRenderingResize");
+  GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
+
+  application.GetScene().Add(view);
+  view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
+  view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrame), Dali::MakeCallback(DirectRenderingCode::glTerminate));
+  view.SetResizeCallback(Dali::MakeCallback(DirectRenderingCode::resizeCB));
+  view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  view.SetProperty(Actor::Property::SIZE, Vector2(360.0f, 360.0f));
+
+  application.SendNotification();
+  application.Render();
+
+  //To GlViewRenderThread can recognize Resize signal the main thread have to sleep.
+  std::this_thread::sleep_for(std::chrono::milliseconds(100));
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_CHECK(true);
+  END_TEST;
+}
+
+int UtcDaliGlViewDirectRenderingTerminateCallback(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliGlViewDirectRenderingTerminateCallback");
+  GlView view = Toolkit::GlView::New(GlView::BackendMode::DIRECT_RENDERING, GlView::ColorFormat::RGB888);
+
+  application.GetScene().Add(view);
+  view.SetGraphicsConfig(true, true, 0, GlView::GraphicsApiVersion::GLES_VERSION_2_0);
+  view.RegisterGlCallbacks(Dali::MakeCallback(DirectRenderingCode::glInit), Dali::MakeCallback(DirectRenderingCode::glRenderFrame), Dali::MakeCallback(DirectRenderingCode::glTerminate));
+  view.SetResizeCallback(Dali::MakeCallback(DirectRenderingCode::resizeCB));
+  view.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  view.SetProperty(Actor::Property::SIZE, Vector2(360.0f, 360.0f));
+
+  application.SendNotification();
+  application.Render();
+
+
+
+  //To GlViewRenderThread can recognize Resize signal the main thread have to sleep.
+  std::this_thread::sleep_for(std::chrono::milliseconds(100));
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_CHECK(true);
+  END_TEST;
+}
\ No newline at end of file
index 823c2c2..ddd45ba 100644 (file)
@@ -3128,6 +3128,12 @@ void OnResourceReadySignal03(Control control)
   gResourceReadySignalCounter++;
 }
 
+void OnSimpleResourceReadySignal(Control control)
+{
+  // simply increate counter
+  gResourceReadySignalCounter++;
+}
+
 } // namespace
 
 int UtcDaliImageViewSetImageOnResourceReadySignal01(void)
@@ -3228,3 +3234,105 @@ int UtcDaliImageViewSetImageOnResourceReadySignal03(void)
 
   END_TEST;
 }
+
+int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask01(void)
+{
+  tet_infoline("Test signal handler when image / mask image is broken.");
+
+  ToolkitTestApplication application;
+
+  auto TestResourceReadyUrl = [&application](int eventTriggerCount, bool isSynchronous, const std::string& url, const std::string& mask, const char* location) {
+    gResourceReadySignalCounter = 0;
+
+    Property::Map map;
+    map[Toolkit::ImageVisual::Property::URL] = url;
+    if(!mask.empty())
+    {
+      map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = mask;
+    }
+    map[Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING] = isSynchronous;
+
+    ImageView imageView                            = ImageView::New();
+    imageView[Toolkit::ImageView::Property::IMAGE] = map;
+    imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
+    imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
+
+    application.GetScene().Add(imageView);
+    application.SendNotification();
+    application.Render();
+
+    if(!isSynchronous)
+    {
+      // Wait for loading
+      DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(eventTriggerCount), true, location);
+    }
+    tet_printf("test %s [sync:%d] signal fired\n", url.c_str(), isSynchronous ? 1 : 0);
+    DALI_TEST_EQUALS(gResourceReadySignalCounter, 1, location);
+
+    imageView.Unparent();
+  };
+
+  for(int synchronous = 0; synchronous <= 1; synchronous++)
+  {
+    tet_printf("Test normal case (sync:%d)\n", synchronous);
+    TestResourceReadyUrl(1, synchronous, gImage_600_RGB, "", TEST_LOCATION);
+    TestResourceReadyUrl(3, synchronous, gImage_600_RGB, gImage_34_RGBA, TEST_LOCATION); // 3 event trigger required : 2 image load + 1 apply mask
+
+    tet_printf("Test broken image case (sync:%d)\n", synchronous);
+    TestResourceReadyUrl(1, synchronous, "invalid.jpg", "", TEST_LOCATION);
+    TestResourceReadyUrl(2, synchronous, "invalid.jpg", gImage_34_RGBA, TEST_LOCATION);
+
+    tet_printf("Test broken mask image case (sync:%d)\n", synchronous);
+    TestResourceReadyUrl(2, synchronous, gImage_600_RGB, "invalid.png", TEST_LOCATION);
+
+    tet_printf("Test broken both image, mask image case (sync:%d)\n", synchronous);
+    TestResourceReadyUrl(2, synchronous, "invalid.jpg", "invalid.png", TEST_LOCATION);
+  }
+
+  END_TEST;
+}
+
+int UtcDaliImageViewOnResourceReadySignalWithBrokenAlphaMask02(void)
+{
+  tet_infoline("Test signal handler when image try to use cached-and-broken mask image.");
+
+  ToolkitTestApplication application;
+
+  gResourceReadySignalCounter = 0;
+
+  auto TestBrokenMaskResourceReadyUrl = [&application](const std::string& url, const char* location) {
+    Property::Map map;
+    map[Toolkit::ImageVisual::Property::URL] = url;
+    // Use invalid mask url
+    map[Toolkit::ImageVisual::Property::ALPHA_MASK_URL] = "invalid.png";
+
+    ImageView imageView                            = ImageView::New();
+    imageView[Toolkit::ImageView::Property::IMAGE] = map;
+    imageView[Actor::Property::SIZE]               = Vector2(100.0f, 200.0f);
+    imageView.ResourceReadySignal().Connect(&OnSimpleResourceReadySignal);
+
+    application.GetScene().Add(imageView);
+    application.SendNotification();
+    application.Render();
+
+    // Don't unparent imageView, for keep the cache.
+  };
+
+  // Use more than 4 images (The number of LocalImageLoadThread)
+  const std::vector<std::string> testUrlList = {gImage_34_RGBA, gImage_600_RGB, "invalid.jpg" /* invalid url */, TEST_IMAGE_1, TEST_IMAGE_2, TEST_BROKEN_IMAGE_DEFAULT};
+
+  int expectResourceReadySignalCounter = 0;
+
+  for(auto& url : testUrlList)
+  {
+    TestBrokenMaskResourceReadyUrl(url, TEST_LOCATION);
+    expectResourceReadySignalCounter++;
+  }
+
+  // Remain 1 signal due to we use #URL + 1 mask image.
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(expectResourceReadySignalCounter + 1), true, TEST_LOCATION);
+
+  DALI_TEST_EQUALS(gResourceReadySignalCounter, expectResourceReadySignalCounter, TEST_LOCATION);
+
+  END_TEST;
+}
\ No newline at end of file
index 9db4289..476da78 100644 (file)
@@ -691,6 +691,14 @@ int UtcDaliTextEditorSetPropertyP(void)
   editor.SetProperty(TextEditor::Property::HORIZONTAL_ALIGNMENT, "END");
   DALI_TEST_EQUALS(editor.GetProperty<std::string>(TextEditor::Property::HORIZONTAL_ALIGNMENT), "END", TEST_LOCATION);
 
+  // Check that the Alignment properties can be correctly set
+  editor.SetProperty(DevelTextEditor::Property::VERTICAL_ALIGNMENT, "BOTTOM");
+  DALI_TEST_EQUALS(editor.GetProperty<std::string>(DevelTextEditor::Property::VERTICAL_ALIGNMENT), "BOTTOM", TEST_LOCATION);
+  editor.SetProperty(DevelTextEditor::Property::VERTICAL_ALIGNMENT, "CENTER");
+  DALI_TEST_EQUALS(editor.GetProperty<std::string>(DevelTextEditor::Property::VERTICAL_ALIGNMENT), "CENTER", TEST_LOCATION);
+  editor.SetProperty(DevelTextEditor::Property::VERTICAL_ALIGNMENT, "TOP");
+  DALI_TEST_EQUALS(editor.GetProperty<std::string>(DevelTextEditor::Property::VERTICAL_ALIGNMENT), "TOP", TEST_LOCATION);
+
   // Check scroll properties.
   editor.SetProperty(TextEditor::Property::SCROLL_THRESHOLD, 1.f);
   DALI_TEST_EQUALS(editor.GetProperty<float>(TextEditor::Property::SCROLL_THRESHOLD), 1.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION);
index f8ee78d..c256b7a 100644 (file)
@@ -238,6 +238,7 @@ int UtcDaliToolkitTextSelectionPopupIconProperties(void)
   popup.SetProperty(TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE, "POPUP_PASTE_BUTTON_ICON_IMAGE");
   popup.SetProperty(TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE, "POPUP_SELECT_BUTTON_ICON_IMAGE");
   popup.SetProperty(TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE, "POPUP_SELECT_ALL_BUTTON_ICON_IMAGE");
+  popup.SetProperty(TextSelectionPopup::Property::POPUP_PRESSED_IMAGE, "POPUP_PRESSED_IMAGE");
 
   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_CLIPBOARD_BUTTON_ICON_IMAGE", TEST_LOCATION);
   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_CUT_BUTTON_ICON_IMAGE", TEST_LOCATION);
@@ -245,6 +246,7 @@ int UtcDaliToolkitTextSelectionPopupIconProperties(void)
   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_PASTE_BUTTON_ICON_IMAGE", TEST_LOCATION);
   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_SELECT_BUTTON_ICON_IMAGE", TEST_LOCATION);
   DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE).Get<std::string>(), "POPUP_SELECT_ALL_BUTTON_ICON_IMAGE", TEST_LOCATION);
+  DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_PRESSED_IMAGE).Get<std::string>(), "POPUP_PRESSED_IMAGE", TEST_LOCATION);
 
   END_TEST;
 }
@@ -273,3 +275,35 @@ int UtcDaliToolkitTextSelectionPopupSizeProperties(void)
 
   END_TEST;
 }
+
+int UtcDaliToolkitTextSelectionPopupDurationProperties(void)
+{
+  ToolkitTestApplication application;
+  TextSelectionPopup     popup = TextSelectionPopup::New(nullptr);
+
+  const float popupFadeInDuration = 5.0f;
+  const float popupFadeOutDuration = 10.0f;
+  popup.SetProperty(TextSelectionPopup::Property::POPUP_FADE_IN_DURATION, popupFadeInDuration);
+  popup.SetProperty(TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION, popupFadeOutDuration);
+
+  DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_FADE_IN_DURATION).Get<float>(), popupFadeInDuration, TEST_LOCATION);
+  DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION).Get<float>(), popupFadeOutDuration, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliToolkitTextSelectionPopupColorProperties(void)
+{
+  ToolkitTestApplication application;
+  TextSelectionPopup     popup = TextSelectionPopup::New(nullptr);
+
+  popup.SetProperty(TextSelectionPopup::Property::POPUP_DIVIDER_COLOR, Color::RED);
+  popup.SetProperty(TextSelectionPopup::Property::POPUP_ICON_COLOR, Color::BLUE);
+  popup.SetProperty(TextSelectionPopup::Property::POPUP_PRESSED_COLOR, Color::BLACK);
+
+  DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_DIVIDER_COLOR).Get<Vector4>(), Color::RED, TEST_LOCATION);
+  DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_ICON_COLOR).Get<Vector4>(), Color::BLUE, TEST_LOCATION);
+  DALI_TEST_EQUALS(popup.GetProperty(TextSelectionPopup::Property::POPUP_PRESSED_COLOR).Get<Vector4>(), Color::BLACK, TEST_LOCATION);
+
+  END_TEST;
+}
\ No newline at end of file
index 8b0adff..6291e50 100644 (file)
@@ -110,6 +110,13 @@ void TestVisualAsynchronousRender(ToolkitTestApplication& application,
   DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION);
 }
 
+int gResourceReadySignalCounter;
+
+void OnResourceReadySignal(Control control)
+{
+  gResourceReadySignalCounter++;
+}
+
 } // namespace
 
 void dali_visual_factory_startup(void)
@@ -729,7 +736,7 @@ int UtcDaliVisualFactoryGetNPatchVisual2(void)
   propertyMap.Insert(ImageVisual::Property::URL, gImage_34_RGBA);
   propertyMap.Insert(ImageVisual::Property::BORDER, Rect<int>(2, 2, 2, 2));
   {
-    tet_infoline("whole grid");
+    tet_infoline("whole grid (2,2,2,2) async");
     Visual::Base visual = factory.CreateVisual(propertyMap);
     DALI_TEST_CHECK(visual);
 
@@ -770,9 +777,80 @@ int UtcDaliVisualFactoryGetNPatchVisual2(void)
   propertyMap.Clear();
   propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::N_PATCH);
   propertyMap.Insert(ImageVisual::Property::URL, gImage_34_RGBA);
+  propertyMap.Insert(ImageVisual::Property::BORDER, Rect<int>(2, 2, 2, 2));
+  propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
+  {
+    tet_infoline("whole grid (2,2,2,2) sync");
+    Visual::Base visual = factory.CreateVisual(propertyMap);
+    DALI_TEST_CHECK(visual);
+
+    TestGlAbstraction& gl           = application.GetGlAbstraction();
+    TraceCallStack&    textureTrace = gl.GetTextureTrace();
+    textureTrace.Enable(true);
+
+    DummyControl actor = DummyControl::New(true);
+    TestVisualRender(application, actor, visual);
+
+    DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
+
+    Vector2 naturalSize(0.0f, 0.0f);
+    visual.GetNaturalSize(naturalSize);
+    DALI_TEST_EQUALS(naturalSize, Vector2(imageSize.GetWidth(), imageSize.GetHeight()), TEST_LOCATION);
+  }
+
+  propertyMap.Clear();
+  propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::N_PATCH);
+  propertyMap.Insert(ImageVisual::Property::URL, gImage_34_RGBA);
   propertyMap.Insert(ImageVisual::Property::BORDER, Rect<int>(1, 1, 1, 1));
+  propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
   {
-    tet_infoline("whole grid");
+    tet_infoline("whole grid (1,1,1,1) sync : for testing same image, different border");
+    Visual::Base visual = factory.CreateVisual(propertyMap);
+    DALI_TEST_CHECK(visual);
+
+    TestGlAbstraction& gl           = application.GetGlAbstraction();
+    TraceCallStack&    textureTrace = gl.GetTextureTrace();
+    textureTrace.Enable(true);
+
+    DummyControl actor = DummyControl::New(true);
+    TestVisualRender(application, actor, visual);
+
+    DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
+
+    Vector2 naturalSize(0.0f, 0.0f);
+    visual.GetNaturalSize(naturalSize);
+    DALI_TEST_EQUALS(naturalSize, Vector2(imageSize.GetWidth(), imageSize.GetHeight()), TEST_LOCATION);
+  }
+
+  propertyMap.Clear();
+  propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::N_PATCH);
+  propertyMap.Insert(ImageVisual::Property::URL, gImage_34_RGBA);
+  propertyMap.Insert(ImageVisual::Property::BORDER, Rect<int>(1, 1, 1, 1));
+  {
+    tet_infoline("whole grid (1,1,1,1) async");
+    Visual::Base visual = factory.CreateVisual(propertyMap);
+    DALI_TEST_CHECK(visual);
+
+    TestGlAbstraction& gl           = application.GetGlAbstraction();
+    TraceCallStack&    textureTrace = gl.GetTextureTrace();
+    textureTrace.Enable(true);
+
+    DummyControl actor = DummyControl::New(true);
+    TestVisualRender(application, actor, visual);
+
+    DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
+
+    Vector2 naturalSize(0.0f, 0.0f);
+    visual.GetNaturalSize(naturalSize);
+    DALI_TEST_EQUALS(naturalSize, Vector2(imageSize.GetWidth(), imageSize.GetHeight()), TEST_LOCATION);
+  }
+
+  propertyMap.Clear();
+  propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::N_PATCH);
+  propertyMap.Insert(ImageVisual::Property::URL, gImage_34_RGBA);
+  propertyMap.Insert(ImageVisual::Property::BORDER, Rect<int>(3, 3, 3, 3));
+  {
+    tet_infoline("whole grid (3,3,3,3) async");
     Visual::Base visual = factory.CreateVisual(propertyMap);
     DALI_TEST_CHECK(visual);
 
@@ -1103,6 +1181,169 @@ int UtcDaliVisualFactoryGetNPatchVisual8(void)
   END_TEST;
 }
 
+int UtcDaliVisualFactoryGetNPatchVisual9(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliVisualFactoryGetNPatchVisual9: Request n-patch visual sync during another n-patch visual load image asynchronously");
+
+  VisualFactory factory = VisualFactory::Get();
+  DALI_TEST_CHECK(factory);
+
+  Property::Map propertyMap;
+  propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::N_PATCH);
+  propertyMap.Insert(ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME);
+  propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, false);
+  Visual::Base visual = factory.CreateVisual(propertyMap);
+  DALI_TEST_CHECK(visual);
+
+  TestGlAbstraction& gl           = application.GetGlAbstraction();
+  TraceCallStack&    textureTrace = gl.GetTextureTrace();
+  textureTrace.Enable(true);
+
+  DummyControl actor = DummyControl::New(true);
+
+  DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
+  dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
+
+  actor.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
+  DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
+
+  application.GetScene().Add(actor);
+
+  propertyMap.Clear();
+  propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::N_PATCH);
+  propertyMap.Insert(ImageVisual::Property::URL, TEST_NPATCH_FILE_NAME);
+  propertyMap.Insert(ImageVisual::Property::SYNCHRONOUS_LOADING, true);
+  Visual::Base visual2 = factory.CreateVisual(propertyMap);
+  DALI_TEST_CHECK(visual2);
+
+  DummyControl actor2 = DummyControl::New(true);
+
+  DummyControlImpl& dummyImpl2 = static_cast<DummyControlImpl&>(actor2.GetImplementation());
+  dummyImpl2.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual2);
+
+  actor2.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f));
+  DALI_TEST_EQUALS(actor2.GetRendererCount(), 0u, TEST_LOCATION);
+
+  application.GetScene().Add(actor2);
+
+  application.SendNotification();
+  application.Render();
+
+  application.SendNotification();
+  application.Render();
+
+  // Async loading is not finished yet.
+  {
+    DALI_TEST_EQUALS(actor.GetRendererCount(), 0u, TEST_LOCATION);
+  }
+  // Sync loading is finished.
+  {
+    Renderer renderer = actor2.GetRendererAt(0);
+    auto     textures = renderer.GetTextures();
+
+    DALI_TEST_EQUALS(textures.GetTextureCount(), 1, TEST_LOCATION);
+  }
+  DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+  // Async loading is finished.
+  {
+    Renderer renderer = actor.GetRendererAt(0);
+    auto     textures = renderer.GetTextures();
+
+    DALI_TEST_EQUALS(textures.GetTextureCount(), 1, TEST_LOCATION);
+  }
+
+  END_TEST;
+}
+
+int UtcDaliVisualFactoryGetNPatchVisual10(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline("UtcDaliVisualFactoryGetNPatchVisual10: Request same 9-patch visual with a different border");
+
+  VisualFactory factory = VisualFactory::Get();
+  DALI_TEST_CHECK(factory);
+
+  // Get actual size of test image
+  ImageDimensions imageSize = Dali::GetClosestImageSize(gImage_34_RGBA);
+
+  Property::Map propertyMap;
+  propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::N_PATCH);
+  propertyMap.Insert(ImageVisual::Property::URL, gImage_34_RGBA);
+  propertyMap.Insert(ImageVisual::Property::BORDER, Rect<int>(2, 2, 2, 2));
+  {
+    tet_infoline("whole grid (2,2,2,2) async");
+    Visual::Base visual = factory.CreateVisual(propertyMap);
+    DALI_TEST_CHECK(visual);
+
+    TestGlAbstraction& gl           = application.GetGlAbstraction();
+    TraceCallStack&    textureTrace = gl.GetTextureTrace();
+    textureTrace.Enable(true);
+
+    DummyControl actor = DummyControl::New(true);
+    TestVisualAsynchronousRender(application, actor, visual);
+
+    DALI_TEST_EQUALS(textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION);
+
+    Vector2 naturalSize(0.0f, 0.0f);
+    visual.GetNaturalSize(naturalSize);
+    DALI_TEST_EQUALS(naturalSize, Vector2(imageSize.GetWidth(), imageSize.GetHeight()), TEST_LOCATION);
+  }
+
+  propertyMap.Clear();
+  propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::N_PATCH);
+  propertyMap.Insert(ImageVisual::Property::URL, gImage_34_RGBA);
+  propertyMap.Insert(ImageVisual::Property::BORDER, Rect<int>(1, 1, 1, 1));
+  {
+    tet_infoline("whole grid (1,1,1,1) async. Check whether we use cached texture");
+    // We don't use dummyControl here
+
+    const int expectResourceReadySignalCounter = 10;
+    gResourceReadySignalCounter                = 0;
+
+    for(int i = 0; i < expectResourceReadySignalCounter; i++)
+    {
+      ImageView imageView                            = ImageView::New();
+      imageView[Toolkit::ImageView::Property::IMAGE] = propertyMap;
+      imageView.ResourceReadySignal().Connect(&OnResourceReadySignal);
+      application.GetScene().Add(imageView);
+    }
+
+    // Dont wait for loading. All border use cached texture.
+
+    DALI_TEST_EQUALS(gResourceReadySignalCounter, expectResourceReadySignalCounter, TEST_LOCATION);
+  }
+
+  propertyMap.Clear();
+  propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::N_PATCH);
+  propertyMap.Insert(ImageVisual::Property::URL, gImage_34_RGBA);
+  propertyMap.Insert(ImageVisual::Property::BORDER, Rect<int>(1, 2, 1, 2));
+  {
+    tet_infoline("whole grid (1,2,1,2) async. Check whether we use cached texture");
+    // We don't use dummyControl here
+
+    const int expectResourceReadySignalCounter = 10;
+    gResourceReadySignalCounter                = 0;
+
+    for(int i = 0; i < expectResourceReadySignalCounter; i++)
+    {
+      ImageView imageView                            = ImageView::New();
+      imageView[Toolkit::ImageView::Property::IMAGE] = propertyMap;
+      imageView.ResourceReadySignal().Connect(&OnResourceReadySignal);
+      application.GetScene().Add(imageView);
+    }
+
+    // Dont wait for loading. All border use cached texture.
+
+    DALI_TEST_EQUALS(gResourceReadySignalCounter, expectResourceReadySignalCounter, TEST_LOCATION);
+  }
+
+  END_TEST;
+}
+
 int UtcDaliNPatchVisualAuxiliaryImage01(void)
 {
   ToolkitTestApplication application;
index b990dc7..4645576 100644 (file)
@@ -310,6 +310,14 @@ enum Type
    * @note If the value is less than 1, the lines could to be overlapped.
    */
   RELATIVE_LINE_SIZE,
+
+  /**
+   * @brief The line vertical alignment.
+   * @details Name "verticalAlignment", type Property::STRING or type VerticalAlignment::Type (Property::INTEGER).
+   *          Values "TOP", "CENTER", "BOTTOM", default TOP.
+   * @note Return type is Property::STRING
+   */
+  VERTICAL_ALIGNMENT,
 };
 
 } // namespace Property
diff --git a/dali-toolkit/internal/controls/gl-view/drawable-view-impl.cpp b/dali-toolkit/internal/controls/gl-view/drawable-view-impl.cpp
new file mode 100644 (file)
index 0000000..9b94546
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2021 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/internal/controls/gl-view/drawable-view-impl.h>
+
+// EXTERNAL INCLUDES
+#include <dali/devel-api/adaptor-framework/lifecycle-controller.h>
+#include <dali/devel-api/adaptor-framework/window-devel.h>
+#include <dali/devel-api/rendering/renderer-devel.h>
+#include <dali/integration-api/debug.h>
+#include <dali/public-api/rendering/renderer.h>
+
+namespace Dali::Toolkit::Internal
+{
+Dali::Toolkit::GlView DrawableView::New()
+{
+  auto* impl   = new DrawableView();
+  Dali::Toolkit::GlView handle = Dali::Toolkit::GlView(*impl);
+  impl->Initialize();
+  return handle;
+}
+
+DrawableView::DrawableView()
+: Dali::Toolkit::Internal::GlViewImpl( GlView::BackendMode::DIRECT_RENDERING ),
+  mRenderingMode(Toolkit::GlView::RenderingMode::CONTINUOUS),
+  mDepth(false),
+  mStencil(false),
+  mMSAA(0)
+{
+  mRenderCallback = RenderCallback::New( this, &DrawableView::OnRenderCallback);
+}
+
+DrawableView::~DrawableView() = default;
+
+void DrawableView::RegisterGlCallbacks(CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback)
+{
+  mOnInitCallback.reset( initCallback );
+  mOnRenderCallback.reset(renderFrameCallback );
+  mOnTerminateCallback. reset( terminateCallback );
+}
+
+void DrawableView::SetResizeCallback(CallbackBase* resizeCallback)
+{
+  mOnResizeCallback.reset( resizeCallback );
+}
+
+bool DrawableView::SetGraphicsConfig(bool depth, bool stencil, int msaa, Dali::Toolkit::GlView::GraphicsApiVersion version)
+{
+  DALI_LOG_ERROR( "DrawableView::SetGraphicsConfig() is currently not implemented");
+
+  return true;
+}
+
+void DrawableView::SetRenderingMode(Dali::Toolkit::GlView::RenderingMode mode)
+{
+  mRenderingMode    = mode;
+  Renderer renderer = Self().GetRendererAt(0);
+
+  if(mRenderingMode == Dali::Toolkit::GlView::RenderingMode::ON_DEMAND)
+  {
+    renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::IF_REQUIRED);
+  }
+  else
+  {
+    renderer.SetProperty(DevelRenderer::Property::RENDERING_BEHAVIOR, DevelRenderer::Rendering::CONTINUOUSLY);
+  }
+}
+
+Dali::Toolkit::GlView::RenderingMode DrawableView::GetRenderingMode() const
+{
+  return mRenderingMode;
+}
+
+void DrawableView::RenderOnce()
+{
+  // Ignored.
+  // TODO: without rendering on the separate thread the RenderOnce won't
+  // work as expected. Potential implementation of threading may enable that
+  // feature.
+}
+
+void DrawableView::OnInitialize()
+{
+  AddRenderer();
+
+  // Adding VisibilityChange Signal.
+  Actor self = Self();
+  Dali::DevelActor::VisibilityChangedSignal(self).Connect(this, &DrawableView::OnControlVisibilityChanged);
+}
+
+void DrawableView::OnSizeSet(const Vector3& targetSize)
+{
+  Control::OnSizeSet(targetSize);
+
+  mSurfaceSize = targetSize;
+
+  // If the callbacks are set then schedule execution of resize callback
+  if(mRenderCallback && mOnResizeCallback)
+  {
+    mSurfaceResized = true;
+  }
+}
+
+void DrawableView::OnControlVisibilityChanged(Dali::Actor actor, bool visible, Dali::DevelActor::VisibilityChange::Type type)
+{
+  // Ignored due to lack dedicated rendering thread
+}
+
+void DrawableView::OnWindowVisibilityChanged(Window window, bool visible)
+{
+  // Ignored due to lack dedicated rendering thread
+}
+
+void DrawableView::OnSceneConnection(int depth)
+{
+  Control::OnSceneConnection(depth);
+
+  Actor  self   = Self();
+  Window window = DevelWindow::Get(self);
+
+  // Despite OnWindowVisibilityChanged() is ignored it still should follow
+  // the designed behaviour of GlView so signal is connected regardless
+  if(window)
+  {
+    DevelWindow::VisibilityChangedSignal(window).Connect(this, &DrawableView::OnWindowVisibilityChanged);
+  }
+}
+
+void DrawableView::OnSceneDisconnection()
+{
+  Control::OnSceneDisconnection();
+}
+
+void DrawableView::AddRenderer()
+{
+  Actor    self     = Self();
+  Renderer renderer = Renderer::New( *mRenderCallback );
+  self.AddRenderer(renderer);
+}
+
+bool DrawableView::OnRenderCallback( const RenderCallbackInput& renderCallbackInput )
+{
+  // Init state
+  if( mCurrentViewState == ViewState::INIT )
+  {
+    if(mOnInitCallback)
+    {
+      CallbackBase::Execute(*mOnInitCallback);
+    }
+    mCurrentViewState = ViewState::RENDER;
+  }
+
+  int renderFrameResult = 0;
+  if( mCurrentViewState == ViewState::RENDER )
+  {
+    // The mSurfaceResized is set by another thread so atomic check must be provided
+    bool expected{ true };
+    if(mSurfaceResized.compare_exchange_weak( expected, false,
+                                             std::memory_order_release,
+                                             std::memory_order_relaxed
+                                             ) && mOnResizeCallback)
+    {
+      CallbackBase::Execute(*mOnResizeCallback, static_cast<int>(mSurfaceSize.x), static_cast<int>(mSurfaceSize.y));
+    }
+
+    if(mOnRenderCallback)
+    {
+      renderFrameResult = CallbackBase::ExecuteReturn<int>(*mOnRenderCallback);
+      if(renderFrameResult)
+      {
+        // TODO: may be utilized for RenderOnce feature
+      }
+    }
+  }
+
+  // The terminate callback isn't easy to implement for DR. The NativeImage backend
+  // calls it when the GlView is being destroyed. For DrawableView it means that
+  // the RenderCallback won't be executed (as it is a part of graphics pipeline).
+  // We don't have currenty no way to know whether the View will be destroyed and
+  // to execute last native draw command in the pipeline.
+  //
+  // else if( mCurrentViewState == ViewState::TERMINATE )
+  // {
+  //    CallbackBase::Execute(*mOnTerminateCallback);
+  // }
+
+  return true;
+}
+
+} // namespace Dali
diff --git a/dali-toolkit/internal/controls/gl-view/drawable-view-impl.h b/dali-toolkit/internal/controls/gl-view/drawable-view-impl.h
new file mode 100644 (file)
index 0000000..c61832a
--- /dev/null
@@ -0,0 +1,168 @@
+#ifndef DALI_TOOLKIT_INTERNAL_DRAWABLE_VIEW_H
+#define DALI_TOOLKIT_INTERNAL_DRAWABLE_VIEW_H
+
+/*
+ * Copyright (c) 2021 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/devel-api/actors/actor-devel.h>
+#include <dali/devel-api/adaptor-framework/native-image-source-queue.h>
+#include <dali/public-api/adaptor-framework/window.h>
+#include <dali/public-api/rendering/geometry.h>
+#include <dali/public-api/rendering/shader.h>
+#include <dali/public-api/signals/render-callback.h>
+#include "gl-view-interface-impl.h"
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/controls/gl-view/gl-view-interface-impl.h>
+#include <dali-toolkit/public-api/controls/control-impl.h>
+#include <dali-toolkit/public-api/controls/gl-view/gl-view.h>
+
+namespace Dali::Toolkit
+{
+class GlView;
+
+namespace Internal
+{
+class DrawableView : public Dali::Toolkit::Internal::GlViewImpl
+{
+protected:
+  virtual ~DrawableView();
+
+public:
+  /**
+   * @copydoc Dali::Toolkit::GlView::New()
+   */
+  static Dali::Toolkit::GlView New();
+
+  /**
+   * Construct a new GlView.
+   */
+  DrawableView();
+
+  /**
+   * @copydoc Dali::Toolkit::GlView::RegisterGlCallbacks()
+   */
+  void RegisterGlCallbacks(CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback) override;
+
+  /**
+   * @copydoc Dali::Toolkit::GlView::SetResizeCallback()
+   */
+  void SetResizeCallback(CallbackBase* resizeCallback) override;
+
+  /**
+   * @copydoc Dali::Toolkit::GlView::SetGraphicsConfig()
+   */
+  bool SetGraphicsConfig(bool depth, bool stencil, int msaa, Dali::Toolkit::GlView::GraphicsApiVersion version) override;
+
+  /**
+   * @copydoc Dali::Toolkit::GlView::SetRenderingMode()
+   */
+  void SetRenderingMode(Dali::Toolkit::GlView::RenderingMode mode) override;
+
+  /**
+   * @copydoc Dali::Toolkit::GlView::GetRenderingMode()
+   */
+  Dali::Toolkit::GlView::RenderingMode GetRenderingMode() const override;
+
+  /**
+   * @copydoc Dali::Toolkit::GlView::RenderOnce()
+   */
+  void RenderOnce();
+
+private: // From Control
+  /**
+   * @copydoc Toolkit::Control::OnInitialize()
+   */
+  virtual void OnInitialize() override;
+
+  /**
+   * @copydoc Toolkit::Control::OnSceneConnection()
+   */
+  void OnSceneConnection(int depth) override;
+
+  /**
+   * @copydoc Toolkit::Control::OnSceneDisconnection()
+   */
+  void OnSceneDisconnection() override;
+
+  /**
+   * @copydoc Toolkit::Control::OnSizeSet()
+   */
+  void OnSizeSet(const Vector3& targetSize) override;
+
+private:
+  // Undefined copy constructor and assignment operators
+  DrawableView(const DrawableView& GlView);
+  DrawableView& operator=(const DrawableView& GlView);
+
+  /**
+   * Callback when the visibility of the GlView is changed
+   */
+  void OnControlVisibilityChanged(Dali::Actor actor, bool visible, Dali::DevelActor::VisibilityChange::Type type);
+
+  /**
+   * Callback when the visibility of the window is changed
+   */
+  void OnWindowVisibilityChanged(Dali::Window window, bool visible);
+
+  /**
+   * Adds renderer to Actor.
+   */
+  void AddRenderer();
+
+private:
+
+  bool OnRenderCallback( const RenderCallbackInput& renderCallbackInput );
+
+private:
+  Dali::Toolkit::GlView::RenderingMode mRenderingMode;
+
+  bool mDepth;
+  bool mStencil;
+  int  mMSAA;
+
+  std::unique_ptr<RenderCallback> mRenderCallback;
+
+  /*
+   * Used within RenderCallback to handle the current render state
+   */
+  enum class ViewState
+  {
+    INIT,
+    RENDER,
+    TERMINATE
+  };
+
+  ViewState mCurrentViewState{ViewState::INIT}; ///< state within RenderCallback
+
+  // These callbacks are stored for GLView API compatibility
+  std::unique_ptr<CallbackBase> mOnInitCallback;
+  std::unique_ptr<CallbackBase> mOnRenderCallback;
+  std::unique_ptr<CallbackBase> mOnTerminateCallback;
+  std::unique_ptr<CallbackBase> mOnResizeCallback;
+
+  std::atomic_bool mSurfaceResized{false}; ///< Flag to invoke surface resize callback
+
+  Size mSurfaceSize{}; ///< Surface size
+};
+
+} // namespace Internal
+
+} // namespace Dali
+
+#endif // DALI_TOOLKIT_INTERNAL_DRAWABLE_VIEW_H
index b37189a..2eaf78c 100644 (file)
@@ -40,14 +40,14 @@ namespace Internal
 {
 Dali::Toolkit::GlView GlView::New(Dali::Toolkit::GlView::ColorFormat colorFormat)
 {
-  GlView*               impl   = new GlView(colorFormat);
+  auto* impl   = new Dali::Toolkit::Internal::GlView(colorFormat);
   Dali::Toolkit::GlView handle = Dali::Toolkit::GlView(*impl);
   impl->Initialize();
   return handle;
 }
 
 GlView::GlView(Dali::Toolkit::GlView::ColorFormat colorFormat)
-: Control(ControlBehaviour(ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
+: Dali::Toolkit::Internal::GlViewImpl( Toolkit::GlView::BackendMode::EGL_IMAGE_OFFSCREEN_RENDERING ),
   mRenderThread(nullptr),
   mNativeImageQueue(nullptr),
   mRenderingMode(Toolkit::GlView::RenderingMode::CONTINUOUS),
index 2dcb0b1..306a53b 100644 (file)
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/internal/controls/gl-view/gl-view-render-thread.h>
+#include <dali-toolkit/internal/controls/gl-view/gl-view-interface-impl.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
 #include <dali-toolkit/public-api/controls/gl-view/gl-view.h>
 
-namespace Dali
-{
-namespace Toolkit
+
+namespace Dali::Toolkit
 {
 class GlView;
 
 namespace Internal
 {
-class GlView : public Dali::Toolkit::Internal::Control
+class GlView : public Dali::Toolkit::Internal::GlViewImpl
 {
 protected:
   virtual ~GlView();
@@ -57,32 +57,32 @@ public:
   /**
    * @copydoc Dali::Toolkit::GlView::RegisterGlCallbacks()
    */
-  void RegisterGlCallbacks(CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback);
+  void RegisterGlCallbacks(CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback) override;
 
   /**
    * @copydoc Dali::Toolkit::GlView::SetResizeCallback()
    */
-  void SetResizeCallback(CallbackBase* resizeCallback);
+  void SetResizeCallback(CallbackBase* resizeCallback) override;
 
   /**
-   * @copydoc Dali::Toolkit::GlView::SetGraphisConfig()
+   * @copydoc Dali::Toolkit::GlView::SetGraphicsConfig()
    */
-  bool SetGraphicsConfig(bool depth, bool stencil, int msaa, Dali::Toolkit::GlView::GraphicsApiVersion version);
+  bool SetGraphicsConfig(bool depth, bool stencil, int msaa, Dali::Toolkit::GlView::GraphicsApiVersion version) override;
 
   /**
    * @copydoc Dali::Toolkit::GlView::SetRenderingMode()
    */
-  void SetRenderingMode(Dali::Toolkit::GlView::RenderingMode mode);
+  void SetRenderingMode(Dali::Toolkit::GlView::RenderingMode mode) override;
 
   /**
    * @copydoc Dali::Toolkit::GlView::GetRenderingMode()
    */
-  Dali::Toolkit::GlView::RenderingMode GetRenderingMode() const;
+  Dali::Toolkit::GlView::RenderingMode GetRenderingMode() const override;
 
   /**
    * @copydoc Dali::Toolkit::GlView::RenderOnce()
    */
-  void RenderOnce();
+  void RenderOnce() override;
 
 private: // From Control
   /**
@@ -155,22 +155,6 @@ private:
 
 } // namespace Internal
 
-inline Dali::Toolkit::Internal::GlView& GetImpl(Dali::Toolkit::GlView& handle)
-{
-  DALI_ASSERT_ALWAYS(handle);
-  Dali::RefObject& impl = handle.GetImplementation();
-  return static_cast<Dali::Toolkit::Internal::GlView&>(impl);
-}
-
-inline const Dali::Toolkit::Internal::GlView& GetImpl(const Dali::Toolkit::GlView& handle)
-{
-  DALI_ASSERT_ALWAYS(handle);
-  const Dali::RefObject& impl = handle.GetImplementation();
-  return static_cast<const Dali::Toolkit::Internal::GlView&>(impl);
-}
-
-} // namespace Toolkit
-
 } // namespace Dali
 
 #endif // DALI_TOOLKIT_INTERNAL_GL_VIEW_H
diff --git a/dali-toolkit/internal/controls/gl-view/gl-view-interface-impl.h b/dali-toolkit/internal/controls/gl-view/gl-view-interface-impl.h
new file mode 100644 (file)
index 0000000..5547789
--- /dev/null
@@ -0,0 +1,133 @@
+#ifndef DALI_TOOLKIT_INTERNAL_GL_VIEW_IMPL_H
+#define DALI_TOOLKIT_INTERNAL_GL_VIEW_IMPL_H
+
+/*
+ * Copyright (c) 2022 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/devel-api/actors/actor-devel.h>
+#include <dali/devel-api/adaptor-framework/native-image-source-queue.h>
+#include <dali/public-api/adaptor-framework/window.h>
+#include <dali/public-api/rendering/geometry.h>
+#include <dali/public-api/rendering/shader.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/controls/gl-view/gl-view-render-thread.h>
+#include <dali-toolkit/public-api/controls/control-impl.h>
+#include <dali-toolkit/public-api/controls/gl-view/gl-view.h>
+
+namespace Dali::Toolkit
+{
+class GlView;
+
+namespace Internal
+{
+class GlViewImpl : public Dali::Toolkit::Internal::Control
+{
+protected:
+
+  virtual ~GlViewImpl() = default;
+
+public:
+
+  /**
+   * Construct a new GlView.
+   */
+  explicit GlViewImpl( GlView::BackendMode backendMode ) :
+    Control(ControlBehaviour(0u | ACTOR_BEHAVIOUR_DEFAULT | DISABLE_STYLE_CHANGE_SIGNALS)),
+    mBackendMode(backendMode)
+  {
+  }
+
+  /**
+   * @copydoc Dali::Toolkit::GlView::RegisterGlCallbacks()
+   */
+  virtual void RegisterGlCallbacks(CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback) = 0;
+
+  /**
+   * @copydoc Dali::Toolkit::GlView::SetResizeCallback()
+   */
+  virtual void SetResizeCallback(CallbackBase* resizeCallback) = 0;
+
+  /**
+   * @copydoc Dali::Toolkit::GlView::SetGraphisConfig()
+   */
+  virtual bool SetGraphicsConfig(bool depth, bool stencil, int msaa, Dali::Toolkit::GlView::GraphicsApiVersion version) = 0;
+
+  /**
+   * @copydoc Dali::Toolkit::GlView::SetRenderingMode()
+   */
+  virtual void SetRenderingMode(Dali::Toolkit::GlView::RenderingMode mode) = 0;
+
+  /**
+   * @copydoc Dali::Toolkit::GlView::GetRenderingMode()
+   */
+  virtual Dali::Toolkit::GlView::RenderingMode GetRenderingMode() const = 0;
+
+  /**
+   * @copydoc Dali::Toolkit::GlView::GetBackendMode()
+   */
+  [[nodiscard]] Dali::Toolkit::GlView::BackendMode GetBackendMode() const
+  {
+    return mBackendMode;
+  }
+
+  /**
+   * @copydoc Dali::Toolkit::GlView::RenderOnce()
+   */
+  virtual void RenderOnce() = 0;
+
+private: // From Control
+  /**
+   * @copydoc Toolkit::Control::OnInitialize()
+   */
+  virtual void OnInitialize() override = 0;
+
+  /**
+   * @copydoc Toolkit::Control::OnSceneConnection()
+   */
+  virtual void OnSceneConnection(int depth) override = 0;
+
+  /**
+   * @copydoc Toolkit::Control::OnSceneDisconnection()
+   */
+  virtual void OnSceneDisconnection() override = 0;
+
+protected:
+
+  GlView::BackendMode mBackendMode { GlView::BackendMode::DEFAULT }; ///< Implementation backend mode (DirectRendering, EGL image)
+};
+
+} // namespace Internal
+
+inline Dali::Toolkit::Internal::GlViewImpl& GetImpl(Dali::Toolkit::GlView& handle)
+{
+  DALI_ASSERT_ALWAYS(handle);
+  Dali::RefObject& impl = handle.GetImplementation();
+  return static_cast<Dali::Toolkit::Internal::GlViewImpl&>(impl);
+}
+
+inline const Dali::Toolkit::Internal::GlViewImpl& GetImpl(const Dali::Toolkit::GlView& handle)
+{
+  DALI_ASSERT_ALWAYS(handle);
+  const Dali::RefObject& impl = handle.GetImplementation();
+  return static_cast<const Dali::Toolkit::Internal::GlViewImpl&>(impl);
+}
+
+} // namespace Dali
+
+#endif // DALI_TOOLKIT_INTERNAL_GL_VIEW_IMPL_H
index 42153dc..b44029c 100644 (file)
@@ -159,6 +159,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "strikethrough",
 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "inputStrikethrough",                   MAP,       INPUT_STRIKETHROUGH                 )
 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "characterSpacing",                     FLOAT,     CHARACTER_SPACING                   )
 DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "relativeLineSize",                     FLOAT,     RELATIVE_LINE_SIZE                  )
+DALI_DEVEL_PROPERTY_REGISTRATION(Toolkit,           TextEditor, "verticalAlignment",                    STRING,    VERTICAL_ALIGNMENT                  )
 
 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "textChanged",           SIGNAL_TEXT_CHANGED           )
 DALI_SIGNAL_REGISTRATION(Toolkit, TextEditor, "inputStyleChanged",     SIGNAL_INPUT_STYLE_CHANGED    )
index 5ea2cf1..361607a 100644 (file)
@@ -126,6 +126,16 @@ void TextEditor::PropertyHandler::SetProperty(Toolkit::TextEditor textEditor, Pr
       }
       break;
     }
+    case Toolkit::DevelTextEditor::Property::VERTICAL_ALIGNMENT:
+    {
+      Toolkit::Text::VerticalAlignment::Type alignment(static_cast<Text::VerticalAlignment::Type>(-1)); // Set to invalid value to ensure a valid mode does get set
+      if(Text::GetVerticalAlignmentEnumeration(value, alignment))
+      {
+        impl.mController->SetVerticalAlignment(alignment);
+        DALI_LOG_INFO(gTextEditorLogFilter, Debug::General, "TextEditor %p VERTICAL_ALIGNMENT %d\n", impl.mController.Get(), alignment);
+      }
+      break;
+    }
     case Toolkit::TextEditor::Property::SCROLL_THRESHOLD:
     {
       const float threshold = value.Get<float>();
@@ -786,6 +796,16 @@ Property::Value TextEditor::PropertyHandler::GetProperty(Toolkit::TextEditor tex
       }
       break;
     }
+    case Toolkit::DevelTextEditor::Property::VERTICAL_ALIGNMENT:
+    {
+      const char* name = Text::GetVerticalAlignmentString(impl.mController->GetVerticalAlignment());
+
+      if(name)
+      {
+        value = std::string(name);
+      }
+      break;
+    }
     case Toolkit::TextEditor::Property::SCROLL_THRESHOLD:
     {
       value = impl.mDecorator->GetScrollThreshold();
index 5d41058..ffa258d 100644 (file)
@@ -38,6 +38,7 @@
 #include <dali-toolkit/devel-api/controls/text-controls/text-selection-popup-callback-interface.h>
 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
+#include <dali-toolkit/internal/controls/text-controls/text-selection-popup-property-handler.h>
 #include <dali-toolkit/internal/helpers/color-conversion.h>
 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
@@ -149,104 +150,8 @@ void TextSelectionPopup::SetProperty(BaseObject* object, Property::Index index,
 
   if(selectionPopup)
   {
-    TextSelectionPopup& impl(GetImpl(selectionPopup));
-
-    switch(index)
-    {
-      case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
-      {
-        impl.SetDimensionToCustomise(POPUP_MAXIMUM_SIZE, value.Get<Vector2>());
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
-      {
-        impl.SetDimensionToCustomise(OPTION_MAXIMUM_SIZE, value.Get<Vector2>());
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
-      {
-        impl.SetDimensionToCustomise(OPTION_MINIMUM_SIZE, value.Get<Vector2>());
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
-      {
-        impl.SetDimensionToCustomise(OPTION_DIVIDER_SIZE, value.Get<Vector2>());
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_PADDING:
-      {
-        Vector4 padding(value.Get<Vector4>());
-        impl.SetOptionDividerPadding(Padding(padding.x, padding.y, padding.z, padding.w));
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
-      {
-        impl.SetButtonImage(Toolkit::TextSelectionPopup::CLIPBOARD, value.Get<std::string>());
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
-      {
-        impl.SetButtonImage(Toolkit::TextSelectionPopup::CUT, value.Get<std::string>());
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
-      {
-        impl.SetButtonImage(Toolkit::TextSelectionPopup::COPY, value.Get<std::string>());
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
-      {
-        impl.SetButtonImage(Toolkit::TextSelectionPopup::PASTE, value.Get<std::string>());
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
-      {
-        impl.SetButtonImage(Toolkit::TextSelectionPopup::SELECT, value.Get<std::string>());
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
-      {
-        impl.SetButtonImage(Toolkit::TextSelectionPopup::SELECT_ALL, value.Get<std::string>());
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR:
-      {
-        impl.mDividerColor = value.Get<Vector4>();
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_ICON_COLOR:
-      {
-        impl.mIconColor = value.Get<Vector4>();
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR:
-      {
-        impl.mPressedColor = value.Get<Vector4>();
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
-      {
-        impl.SetPressedImage(value.Get<std::string>());
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
-      {
-        impl.mFadeInDuration = value.Get<float>();
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
-      {
-        impl.mFadeOutDuration = value.Get<float>();
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
-      {
-        Property::Map map = value.Get<Property::Map>();
-        impl.CreateBackgroundBorder(map);
-        break;
-      }
-    } // switch
-  }   // TextSelectionPopup
+    PropertyHandler::SetProperty(selectionPopup, index, value);
+  }
 }
 
 Property::Value TextSelectionPopup::GetProperty(BaseObject* object, Property::Index index)
@@ -257,93 +162,7 @@ Property::Value TextSelectionPopup::GetProperty(BaseObject* object, Property::In
 
   if(selectionPopup)
   {
-    TextSelectionPopup& impl(GetImpl(selectionPopup));
-
-    switch(index)
-    {
-      case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
-      {
-        value = impl.GetDimensionToCustomise(POPUP_MAXIMUM_SIZE);
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
-      {
-        value = impl.GetDimensionToCustomise(OPTION_MAXIMUM_SIZE);
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
-      {
-        value = impl.GetDimensionToCustomise(OPTION_MINIMUM_SIZE);
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
-      {
-        value = impl.GetDimensionToCustomise(OPTION_DIVIDER_SIZE);
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_PADDING:
-      {
-        Padding padding = impl.GetOptionDividerPadding();
-        value           = Vector4(padding.left, padding.right, padding.top, padding.bottom);
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
-      {
-        value = impl.GetButtonImage(Toolkit::TextSelectionPopup::CLIPBOARD);
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
-      {
-        value = impl.GetButtonImage(Toolkit::TextSelectionPopup::CUT);
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
-      {
-        value = impl.GetButtonImage(Toolkit::TextSelectionPopup::COPY);
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
-      {
-        value = impl.GetButtonImage(Toolkit::TextSelectionPopup::PASTE);
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
-      {
-        value = impl.GetButtonImage(Toolkit::TextSelectionPopup::SELECT);
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
-      {
-        value = impl.GetButtonImage(Toolkit::TextSelectionPopup::SELECT_ALL);
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
-      {
-        value = impl.GetPressedImage();
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
-      {
-        value = impl.mFadeInDuration;
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
-      {
-        value = impl.mFadeOutDuration;
-        break;
-      }
-      case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
-      {
-        Property::Map         map;
-        Toolkit::Visual::Base visual = DevelControl::GetVisual(impl, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER);
-        if(visual)
-        {
-          visual.CreatePropertyMap(map);
-        }
-        value = map;
-        break;
-      }
-    } // switch
+    value = PropertyHandler::GetProperty(selectionPopup, index);
   }
   return value;
 }
index 41686ee..db51100 100644 (file)
@@ -273,6 +273,8 @@ private: // Implementation
   virtual ~TextSelectionPopup();
 
 protected:
+  struct PropertyHandler;
+
   class TextSelectionPopupAccessible : public DevelControl::ControlAccessible
   {
   public:
diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-popup-property-handler.cpp b/dali-toolkit/internal/controls/text-controls/text-selection-popup-property-handler.cpp
new file mode 100644 (file)
index 0000000..fe6e93f
--- /dev/null
@@ -0,0 +1,236 @@
+/*
+ * Copyright (c) 2022 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dali-toolkit/internal/controls/text-controls/text-selection-popup-property-handler.h>
+#include <dali/integration-api/debug.h>
+
+#if defined(DEBUG_ENABLED)
+extern Debug::Filter* gLogFilter;
+#endif
+
+namespace Dali::Toolkit::Internal
+{
+void TextSelectionPopup::PropertyHandler::SetProperty(Toolkit::TextSelectionPopup selectionPopup, Property::Index index, const Property::Value& value)
+{
+  TextSelectionPopup& impl(GetImpl(selectionPopup));
+
+  switch(index)
+  {
+    case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
+    {
+      impl.SetDimensionToCustomise(POPUP_MAXIMUM_SIZE, value.Get<Vector2>());
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
+    {
+      impl.SetDimensionToCustomise(OPTION_MAXIMUM_SIZE, value.Get<Vector2>());
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
+    {
+      impl.SetDimensionToCustomise(OPTION_MINIMUM_SIZE, value.Get<Vector2>());
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
+    {
+      impl.SetDimensionToCustomise(OPTION_DIVIDER_SIZE, value.Get<Vector2>());
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_PADDING:
+    {
+      Vector4 padding(value.Get<Vector4>());
+      impl.SetOptionDividerPadding(Padding(padding.x, padding.y, padding.z, padding.w));
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
+    {
+      impl.SetButtonImage(Toolkit::TextSelectionPopup::CLIPBOARD, value.Get<std::string>());
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
+    {
+      impl.SetButtonImage(Toolkit::TextSelectionPopup::CUT, value.Get<std::string>());
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
+    {
+      impl.SetButtonImage(Toolkit::TextSelectionPopup::COPY, value.Get<std::string>());
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
+    {
+      impl.SetButtonImage(Toolkit::TextSelectionPopup::PASTE, value.Get<std::string>());
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
+    {
+      impl.SetButtonImage(Toolkit::TextSelectionPopup::SELECT, value.Get<std::string>());
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
+    {
+      impl.SetButtonImage(Toolkit::TextSelectionPopup::SELECT_ALL, value.Get<std::string>());
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR:
+    {
+      impl.mDividerColor = value.Get<Vector4>();
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_ICON_COLOR:
+    {
+      impl.mIconColor = value.Get<Vector4>();
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR:
+    {
+      impl.mPressedColor = value.Get<Vector4>();
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
+    {
+      impl.SetPressedImage(value.Get<std::string>());
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
+    {
+      impl.mFadeInDuration = value.Get<float>();
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
+    {
+      impl.mFadeOutDuration = value.Get<float>();
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
+    {
+      Property::Map map = value.Get<Property::Map>();
+      impl.CreateBackgroundBorder(map);
+      break;
+    }
+  }
+}
+
+Property::Value TextSelectionPopup::PropertyHandler::GetProperty(Toolkit::TextSelectionPopup selectionPopup, Property::Index index)
+{
+  Property::Value value;
+  TextSelectionPopup& impl(GetImpl(selectionPopup));
+
+  switch(index)
+  {
+    case Toolkit::TextSelectionPopup::Property::POPUP_MAX_SIZE:
+    {
+      value = impl.GetDimensionToCustomise(POPUP_MAXIMUM_SIZE);
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::OPTION_MAX_SIZE:
+    {
+      value = impl.GetDimensionToCustomise(OPTION_MAXIMUM_SIZE);
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::OPTION_MIN_SIZE:
+    {
+      value = impl.GetDimensionToCustomise(OPTION_MINIMUM_SIZE);
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_SIZE:
+    {
+      value = impl.GetDimensionToCustomise(OPTION_DIVIDER_SIZE);
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::OPTION_DIVIDER_PADDING:
+    {
+      Padding padding = impl.GetOptionDividerPadding();
+      value           = Vector4(padding.left, padding.right, padding.top, padding.bottom);
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_CLIPBOARD_BUTTON_ICON_IMAGE:
+    {
+      value = impl.GetButtonImage(Toolkit::TextSelectionPopup::CLIPBOARD);
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_CUT_BUTTON_ICON_IMAGE:
+    {
+      value = impl.GetButtonImage(Toolkit::TextSelectionPopup::CUT);
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_COPY_BUTTON_ICON_IMAGE:
+    {
+      value = impl.GetButtonImage(Toolkit::TextSelectionPopup::COPY);
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_PASTE_BUTTON_ICON_IMAGE:
+    {
+      value = impl.GetButtonImage(Toolkit::TextSelectionPopup::PASTE);
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_BUTTON_ICON_IMAGE:
+    {
+      value = impl.GetButtonImage(Toolkit::TextSelectionPopup::SELECT);
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_SELECT_ALL_BUTTON_ICON_IMAGE:
+    {
+      value = impl.GetButtonImage(Toolkit::TextSelectionPopup::SELECT_ALL);
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_DIVIDER_COLOR:
+    {
+      value = impl.mDividerColor;
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_ICON_COLOR:
+    {
+      value = impl.mIconColor;
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_COLOR:
+    {
+      value = impl.mPressedColor;
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_PRESSED_IMAGE:
+    {
+      value = impl.GetPressedImage();
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_FADE_IN_DURATION:
+    {
+      value = impl.mFadeInDuration;
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::POPUP_FADE_OUT_DURATION:
+    {
+      value = impl.mFadeOutDuration;
+      break;
+    }
+    case Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER:
+    {
+      Property::Map         map;
+      Toolkit::Visual::Base visual = DevelControl::GetVisual(impl, Toolkit::TextSelectionPopup::Property::BACKGROUND_BORDER);
+      if(visual)
+      {
+        visual.CreatePropertyMap(map);
+      }
+      value = map;
+      break;
+    }
+  }
+
+  return value;
+}
+
+} // namespace Dali::Toolkit::Internal
diff --git a/dali-toolkit/internal/controls/text-controls/text-selection-popup-property-handler.h b/dali-toolkit/internal/controls/text-controls/text-selection-popup-property-handler.h
new file mode 100644 (file)
index 0000000..805e3d8
--- /dev/null
@@ -0,0 +1,50 @@
+#ifndef DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_PROPERTY_HANDLER_H
+#define DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_PROPERTY_HANDLER_H
+
+/*
+ * Copyright (c) 2022 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dali-toolkit/internal/controls/text-controls/text-selection-popup-impl.h>
+
+namespace Dali::Toolkit::Internal
+{
+/**
+ * Class to manage properties for the TextSelectionPopup
+ */
+struct TextSelectionPopup::PropertyHandler
+{
+  /**
+   * Set properties on the text selection popup
+   *
+   * @param[in] selectionPopup The handle for the text selection popup
+   * @param[in] index The property index of the property to set
+   * @param[in] value The value to set
+   */
+  static void SetProperty(Toolkit::TextSelectionPopup selectionPopup, Property::Index index, const Property::Value& value);
+
+  /**
+   * Get properties from the text selection popup
+   *
+   * @param[in] selectionPopup The handle for the text selection popup
+   * @param[in] index The property index of the property to set
+   * @return the value
+   */
+  static Property::Value GetProperty(Toolkit::TextSelectionPopup selectionPopup, Property::Index index);
+};
+
+} // namespace Dali::Toolkit::Internal
+
+#endif //DALI_TOOLKIT_INTERNAL_TEXT_SELECTION_POPUP_PROPERTY_HANDLER_H
index 355667e..15640b7 100644 (file)
@@ -111,12 +111,14 @@ SET( toolkit_src_files
    ${toolkit_src_dir}/controls/text-controls/text-field-property-handler.cpp
    ${toolkit_src_dir}/controls/text-controls/text-label-impl.cpp
    ${toolkit_src_dir}/controls/text-controls/text-selection-popup-impl.cpp
+   ${toolkit_src_dir}/controls/text-controls/text-selection-popup-property-handler.cpp
    ${toolkit_src_dir}/controls/text-controls/text-selection-toolbar-impl.cpp
    ${toolkit_src_dir}/controls/tool-bar/tool-bar-impl.cpp
    ${toolkit_src_dir}/controls/tooltip/tooltip.cpp
    ${toolkit_src_dir}/controls/video-view/video-view-impl.cpp
    ${toolkit_src_dir}/controls/web-view/web-view-impl.cpp
    ${toolkit_src_dir}/controls/camera-view/camera-view-impl.cpp
+   ${toolkit_src_dir}/controls/gl-view/drawable-view-impl.cpp
    ${toolkit_src_dir}/controls/gl-view/gl-view-impl.cpp
    ${toolkit_src_dir}/controls/gl-view/gl-view-render-thread.cpp
    ${toolkit_src_dir}/accessibility-manager/accessibility-manager-impl.cpp
index c24a5cf..46d83dd 100644 (file)
@@ -362,6 +362,27 @@ void ChangeTextControllerState(Controller::Impl& impl, EventData::State newState
   }
 }
 
+void UpdateCursorPositionForAlignment(Controller::Impl& impl, bool needFullAlignment)
+{
+  EventData* eventData = impl.mEventData;
+
+  // Set the flag to redo the alignment operation
+  impl.mOperationsPending = static_cast<Controller::OperationsMask>(impl.mOperationsPending | Controller::OperationsMask::ALIGN);
+
+  if(eventData)
+  {
+    // Note: mUpdateAlignment is currently only needed for horizontal alignment
+    eventData->mUpdateAlignment = needFullAlignment;
+
+    // Update the cursor if it's in editing mode
+    if(EventData::IsEditingState(eventData->mState))
+    {
+      impl.ChangeState(EventData::EDITING);
+      eventData->mUpdateCursorPosition = true;
+    }
+  }
+}
+
 } // unnamed Namespace
 
 EventData::EventData(DecoratorPtr decorator, InputMethodContext& inputMethodContext)
@@ -1440,6 +1461,10 @@ void Controller::Impl::ScrollToMakePositionVisible(const Vector2& position, floa
     {
       mModel->mScrollPosition.y = mModel->mVisualModel->mControlSize.height - positionEndY;
     }
+    else if(mModel->mLogicalModel->mText.Count() == 0u)
+    {
+      Relayouter::CalculateVerticalOffset(*this, mModel->mVisualModel->mControlSize);
+    }
   }
 }
 
@@ -1802,22 +1827,7 @@ void Controller::Impl::SetHorizontalAlignment(Text::HorizontalAlignment::Type al
   {
     // Set the alignment.
     mModel->mHorizontalAlignment = alignment;
-
-    // Set the flag to redo the alignment operation.
-    mOperationsPending = static_cast<OperationsMask>(mOperationsPending | ALIGN);
-
-    if(mEventData)
-    {
-      mEventData->mUpdateAlignment = true;
-
-      // Update the cursor if it's in editing mode
-      if(EventData::IsEditingState(mEventData->mState))
-      {
-        ChangeState(EventData::EDITING);
-        mEventData->mUpdateCursorPosition = true;
-      }
-    }
-
+    UpdateCursorPositionForAlignment(*this, true);
     RequestRelayout();
   }
 }
@@ -1828,7 +1838,7 @@ void Controller::Impl::SetVerticalAlignment(VerticalAlignment::Type alignment)
   {
     // Set the alignment.
     mModel->mVerticalAlignment = alignment;
-    mOperationsPending         = static_cast<OperationsMask>(mOperationsPending | ALIGN);
+    UpdateCursorPositionForAlignment(*this, false);
     RequestRelayout();
   }
 }
index 6f4763e..ebab609 100644 (file)
@@ -447,7 +447,19 @@ Controller::UpdateTextType Controller::Relayouter::Relayout(Controller& controll
   if(!isEditable || !controller.IsMultiLineEnabled())
   {
     // After doing the text layout, the vertical offset to place the actor in the desired position can be calculated.
-    CalculateVerticalOffset(controller, size);
+    CalculateVerticalOffset(impl, size);
+  }
+  else // TextEditor
+  {
+    // If layoutSize is bigger than size, vertical align has no meaning.
+    if(layoutSize.y < size.y)
+    {
+      CalculateVerticalOffset(impl, size);
+      if(impl.mEventData)
+      {
+        impl.mEventData->mScrollAfterDelete = false;
+      }
+    }
   }
 
   if(isEditable)
@@ -769,9 +781,8 @@ void Controller::Relayouter::DoRelayoutHorizontalAlignment(Controller::Impl&
   }
 }
 
-void Controller::Relayouter::CalculateVerticalOffset(Controller& controller, const Size& controlSize)
+void Controller::Relayouter::CalculateVerticalOffset(Controller::Impl& impl, const Size& controlSize)
 {
-  Controller::Impl& impl                  = *controller.mImpl;
   ModelPtr&         model                 = impl.mModel;
   VisualModelPtr&   visualModel           = model->mVisualModel;
   Size              layoutSize            = model->mVisualModel->GetLayoutSize();
index c0ab806..a98ed53 100644 (file)
@@ -97,10 +97,10 @@ struct Controller::Relayouter
   /**
    * @brief Called by the Controller to calculate the veritcal offset give the control size.
    *
-   * @param[in] controller A reference to the controller class
+   * @param[in] impl A reference to the controller impl class
    * @param[in] controlSize The control size
    */
-  static void CalculateVerticalOffset(Controller& controller, const Size& controlSize);
+  static void CalculateVerticalOffset(Controller::Impl& impl, const Size& controlSize);
 
   /**
   * @brief Calculates the layout size of control according to @p requestedControllerSize and @p requestedOperationsMask
index bdc0b6a..9524c44 100644 (file)
@@ -398,7 +398,8 @@ TextureCacheManager::TextureCacheIndex TextureCacheManager::FindCachedTexture(
   const Dali::SamplingMode::Type&            samplingMode,
   const TextureCacheManager::UseAtlas&       useAtlas,
   const TextureCacheManager::TextureId&      maskTextureId,
-  const TextureCacheManager::MultiplyOnLoad& preMultiplyOnLoad)
+  const TextureCacheManager::MultiplyOnLoad& preMultiplyOnLoad,
+  bool                                       isAnimatedImage)
 {
   // Default to an invalid ID, in case we do not find a match.
   TextureCacheIndex cacheIndex = INVALID_CACHE_INDEX;
@@ -416,6 +417,7 @@ TextureCacheManager::TextureCacheIndex TextureCacheManager::FindCachedTexture(
          (useAtlas == textureInfo.useAtlas) &&
          (maskTextureId == textureInfo.maskTextureId) &&
          (size == textureInfo.desiredSize) &&
+         (isAnimatedImage == textureInfo.isAnimatedImageFormat) &&
          ((size.GetWidth() == 0 && size.GetHeight() == 0) ||
           (fittingMode == textureInfo.fittingMode &&
            samplingMode == textureInfo.samplingMode)))
@@ -449,7 +451,6 @@ void TextureCacheManager::RemoveCache(const TextureCacheManager::TextureId& text
   if(textureInfoIndex != INVALID_CACHE_INDEX)
   {
     TextureInfo& textureInfo(mTextureInfoContainer[textureInfoIndex]);
-
     DALI_LOG_INFO(gTextureManagerLogFilter, Debug::Concise, "TextureCacheManager::Remove(textureId:%d) url:%s\n  cacheIdx:%d loadState:%s reference count = %d\n", textureId, textureInfo.url.GetUrl().c_str(), textureInfoIndex, GET_LOAD_STATE_STRING(textureInfo.loadState), textureInfo.referenceCount);
 
     // Decrement the reference count and check if this is the last user of this Texture.
index 5e82d47..7d941d1 100644 (file)
@@ -204,7 +204,8 @@ public:
    * @param[in] samplingMode      The SamplingMode to use
    * @param[in] useAtlas          True if atlased
    * @param[in] maskTextureId     Optional texture ID to use to mask this image
-   * @param[in] preMultiplyOnLoad if the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha.
+   * @param[in] preMultiplyOnLoad If the image's color should be multiplied by it's alpha. Set to OFF if there is no alpha.
+   * @param[in] isAnimatedImage   True if the texture is from animated image.
    * @return                      A TextureCacheId of a cached Texture if found. Or INVALID_CACHE_INDEX if not found.
    */
   TextureCacheManager::TextureCacheIndex FindCachedTexture(
@@ -215,7 +216,8 @@ public:
     const Dali::SamplingMode::Type&            samplingMode,
     const TextureCacheManager::UseAtlas&       useAtlas,
     const TextureCacheManager::TextureId&      maskTextureId,
-    const TextureCacheManager::MultiplyOnLoad& preMultiplyOnLoad);
+    const TextureCacheManager::MultiplyOnLoad& preMultiplyOnLoad,
+    bool                                       isAnimatedImage);
 
   /**
    * @brief Append a Texture to the TextureCacheManager.
index 31c57c6..ff81b22 100644 (file)
@@ -137,15 +137,15 @@ TextureManager::~TextureManager()
   }
 }
 
-TextureSet TextureManager::LoadAnimatedImageTexture(
-  Dali::AnimatedImageLoading      animatedImageLoading,
-  const std::uint32_t&            frameIndex,
-  const Dali::SamplingMode::Type& samplingMode,
-  const bool&                     synchronousLoading,
-  TextureManager::TextureId&      textureId,
-  const Dali::WrapMode::Type&     wrapModeU,
-  const Dali::WrapMode::Type&     wrapModeV,
-  TextureUploadObserver*          textureObserver)
+TextureSet TextureManager::LoadAnimatedImageTexture(Dali::AnimatedImageLoading      animatedImageLoading,
+                                                    const uint32_t&                 frameIndex,
+                                                    TextureManager::TextureId&      textureId,
+                                                    const Dali::SamplingMode::Type& samplingMode,
+                                                    const Dali::WrapMode::Type&     wrapModeU,
+                                                    const Dali::WrapMode::Type&     wrapModeV,
+                                                    const bool&                     synchronousLoading,
+                                                    const bool&                     useCache,
+                                                    TextureUploadObserver*          textureObserver)
 {
   TextureSet textureSet;
 
@@ -175,7 +175,7 @@ TextureSet TextureManager::LoadAnimatedImageTexture(
   else
   {
     auto preMultiply                    = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
-    textureId                           = RequestLoadInternal(animatedImageLoading.GetUrl(), INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, UseAtlas::NO_ATLAS, false, StorageType::UPLOAD_TO_TEXTURE, textureObserver, true, TextureManager::ReloadPolicy::CACHED, preMultiply, animatedImageLoading, frameIndex, false);
+    textureId                           = RequestLoadInternal(animatedImageLoading.GetUrl(), INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, UseAtlas::NO_ATLAS, false, StorageType::UPLOAD_TO_TEXTURE, textureObserver, true, TextureManager::ReloadPolicy::CACHED, preMultiply, animatedImageLoading, frameIndex, false, useCache);
     TextureManager::LoadState loadState = mTextureCacheManager.GetTextureStateInternal(textureId);
     if(loadState == TextureManager::LoadState::UPLOADED)
     {
@@ -229,7 +229,7 @@ Devel::PixelBuffer TextureManager::LoadPixelBuffer(
   }
   else
   {
-    RequestLoadInternal(url, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, UseAtlas::NO_ATLAS, false, StorageType::RETURN_PIXEL_BUFFER, textureObserver, orientationCorrection, TextureManager::ReloadPolicy::FORCED, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, false);
+    RequestLoadInternal(url, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, UseAtlas::NO_ATLAS, false, StorageType::RETURN_PIXEL_BUFFER, textureObserver, orientationCorrection, TextureManager::ReloadPolicy::FORCED, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, false, false);
   }
 
   return pixelBuffer;
@@ -415,7 +415,7 @@ TextureManager::TextureId TextureManager::RequestLoad(
   TextureManager::MultiplyOnLoad&     preMultiplyOnLoad,
   const bool&                         synchronousLoading)
 {
-  return RequestLoadInternal(url, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, useAtlas, false, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
+  return RequestLoadInternal(url, INVALID_TEXTURE_ID, 1.0f, desiredSize, fittingMode, samplingMode, useAtlas, false, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading, true);
 }
 
 TextureManager::TextureId TextureManager::RequestLoad(
@@ -433,7 +433,7 @@ TextureManager::TextureId TextureManager::RequestLoad(
   TextureManager::MultiplyOnLoad&     preMultiplyOnLoad,
   const bool&                         synchronousLoading)
 {
-  return RequestLoadInternal(url, maskTextureId, contentScale, desiredSize, fittingMode, samplingMode, useAtlas, cropToMask, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
+  return RequestLoadInternal(url, maskTextureId, contentScale, desiredSize, fittingMode, samplingMode, useAtlas, cropToMask, StorageType::UPLOAD_TO_TEXTURE, observer, orientationCorrection, reloadPolicy, preMultiplyOnLoad, Dali::AnimatedImageLoading(), 0u, synchronousLoading, true);
 }
 
 TextureManager::TextureId TextureManager::RequestMaskLoad(
@@ -442,7 +442,7 @@ TextureManager::TextureId TextureManager::RequestMaskLoad(
 {
   // Use the normal load procedure to get the alpha mask.
   auto preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
-  return RequestLoadInternal(maskUrl, INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, UseAtlas::NO_ATLAS, false, StorageType::KEEP_PIXEL_BUFFER, NULL, true, TextureManager::ReloadPolicy::CACHED, preMultiply, Dali::AnimatedImageLoading(), 0u, synchronousLoading);
+  return RequestLoadInternal(maskUrl, INVALID_TEXTURE_ID, 1.0f, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::NO_FILTER, UseAtlas::NO_ATLAS, false, StorageType::KEEP_PIXEL_BUFFER, NULL, true, TextureManager::ReloadPolicy::CACHED, preMultiply, Dali::AnimatedImageLoading(), 0u, synchronousLoading, true);
 }
 
 TextureManager::TextureId TextureManager::RequestLoadInternal(
@@ -461,19 +461,17 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
   TextureManager::MultiplyOnLoad&     preMultiplyOnLoad,
   Dali::AnimatedImageLoading          animatedImageLoading,
   const std::uint32_t&                frameIndex,
-  const bool&                         synchronousLoading)
+  const bool&                         synchronousLoading,
+  const bool&                         useCache)
 {
-  // First check if the requested Texture is cached.
-  bool isAnimatedImage = (animatedImageLoading) ? true : false;
-
   TextureHash       textureHash = INITIAL_HASH_NUMBER;
   TextureCacheIndex cacheIndex  = INVALID_CACHE_INDEX;
-  if(storageType != StorageType::RETURN_PIXEL_BUFFER && !isAnimatedImage)
+  if(storageType != StorageType::RETURN_PIXEL_BUFFER && useCache)
   {
     textureHash = mTextureCacheManager.GenerateHash(url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId);
 
     // Look up the texture by hash. Note: The extra parameters are used in case of a hash collision.
-    cacheIndex = mTextureCacheManager.FindCachedTexture(textureHash, url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, preMultiplyOnLoad);
+    cacheIndex = mTextureCacheManager.FindCachedTexture(textureHash, url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, preMultiplyOnLoad, (animatedImageLoading) ? true : false);
   }
 
   TextureManager::TextureId textureId = INVALID_TEXTURE_ID;
@@ -602,12 +600,8 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
   {
     // If the image is already finished to load, use cached texture.
     // We don't need to consider Observer because this is synchronous loading.
-    if(textureInfo.loadState == TextureManager::LoadState::UPLOADED ||
-       textureInfo.loadState == TextureManager::LoadState::LOAD_FINISHED)
-    {
-      return textureId;
-    }
-    else
+    if(!(textureInfo.loadState == TextureManager::LoadState::UPLOADED ||
+         textureInfo.loadState == TextureManager::LoadState::LOAD_FINISHED))
     {
       Devel::PixelBuffer pixelBuffer = LoadImageSynchronously(url, desiredSize, fittingMode, samplingMode, orientationCorrection);
 
@@ -635,6 +629,10 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
             {
               pixelBuffer.ApplyMask(maskPixelBuffer, contentScale, cropToMask);
             }
+            else
+            {
+              DALI_LOG_ERROR("Mask image cached invalid pixel buffer!\n");
+            }
           }
           else
           {
@@ -648,8 +646,6 @@ TextureManager::TextureId TextureManager::RequestLoadInternal(
       }
     }
   }
-
-  // Return the TextureId for which this Texture can now be referenced by externally.
   return textureId;
 }
 
@@ -746,7 +742,7 @@ void TextureManager::LoadOrQueueTexture(TextureManager::TextureInfo& textureInfo
       {
         // The Texture has already loaded. The other observers have already been notified.
         // We need to send a "late" loaded notification for this observer.
-        observer->LoadComplete(true, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::TEXTURE, textureInfo.textureId, textureInfo.textureSet, (textureInfo.useAtlas == UseAtlas::USE_ATLAS) ? true : false, textureInfo.atlasRect, textureInfo.preMultiplied));
+        EmitLoadComplete(observer, textureInfo, true);
       }
       break;
     }
@@ -806,13 +802,9 @@ void TextureManager::ProcessQueuedTextures()
     if(cacheIndex != INVALID_CACHE_INDEX)
     {
       TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
-      if(textureInfo.loadState == LoadState::UPLOADED)
+      if((textureInfo.loadState == LoadState::UPLOADED) || (textureInfo.loadState == LoadState::LOAD_FINISHED && textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER))
       {
-        element.mObserver->LoadComplete(true, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::TEXTURE, textureInfo.textureId, textureInfo.textureSet, (textureInfo.useAtlas == UseAtlas::USE_ATLAS) ? true : false, textureInfo.atlasRect, textureInfo.preMultiplied));
-      }
-      else if(textureInfo.loadState == LoadState::LOAD_FINISHED && textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER)
-      {
-        element.mObserver->LoadComplete(true, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::PIXEL_BUFFER, textureInfo.pixelBuffer, textureInfo.url.GetUrl(), textureInfo.preMultiplied));
+        EmitLoadComplete(element.mObserver, textureInfo, true);
       }
       else
       {
@@ -895,6 +887,13 @@ void TextureManager::PostLoad(TextureManager::TextureInfo& textureInfo, Devel::P
             // Send New Task to Thread
             ApplyMask(textureInfo, textureInfo.maskTextureId);
           }
+          else // maskLoadState == LoadState::LOAD_FAILED
+          {
+            // Url texture load success, But alpha mask texture load failed. Run as normal image upload.
+            DALI_LOG_ERROR("Alpha mask image loading failed! Image will not be masked\n");
+            UploadTexture(pixelBuffer, textureInfo);
+            NotifyObservers(textureInfo, true);
+          }
         }
       }
       else
@@ -923,8 +922,16 @@ void TextureManager::PostLoad(TextureManager::TextureInfo& textureInfo, Devel::P
   else
   {
     textureInfo.loadState = LoadState::LOAD_FAILED;
-    CheckForWaitingTexture(textureInfo);
-    NotifyObservers(textureInfo, false);
+    if(textureInfo.storageType != StorageType::KEEP_PIXEL_BUFFER)
+    {
+      NotifyObservers(textureInfo, false);
+    }
+    else // if(textureInfo.storageType == StorageType::KEEP_PIXEL_BUFFER) // image mask case
+    {
+      // Check if there was another texture waiting for this load to complete
+      // (e.g. if this was an image mask, and its load is on a different thread)
+      CheckForWaitingTexture(textureInfo);
+    }
   }
 }
 
@@ -934,6 +941,8 @@ void TextureManager::CheckForWaitingTexture(TextureManager::TextureInfo& maskTex
   // maskTextureId:
   const TextureCacheIndex size = static_cast<TextureCacheIndex>(mTextureCacheManager.size());
 
+  const bool maskLoadSuccess = maskTextureInfo.loadState == LoadState::LOAD_FINISHED ? true : false;
+
   for(TextureCacheIndex cacheIndex = 0; cacheIndex < size; ++cacheIndex)
   {
     if(mTextureCacheManager[cacheIndex].maskTextureId == maskTextureInfo.textureId &&
@@ -941,16 +950,17 @@ void TextureManager::CheckForWaitingTexture(TextureManager::TextureInfo& maskTex
     {
       TextureInfo& textureInfo(mTextureCacheManager[cacheIndex]);
 
-      if(maskTextureInfo.loadState == LoadState::LOAD_FINISHED)
+      if(maskLoadSuccess)
       {
         // Send New Task to Thread
         ApplyMask(textureInfo, maskTextureInfo.textureId);
       }
       else
       {
-        textureInfo.pixelBuffer.Reset();
-        textureInfo.loadState = LoadState::LOAD_FAILED;
-        NotifyObservers(textureInfo, false);
+        // Url texture load success, But alpha mask texture load failed. Run as normal image upload.
+        DALI_LOG_ERROR("Alpha mask image loading failed! Image will not be masked\n");
+        UploadTexture(textureInfo.pixelBuffer, textureInfo);
+        NotifyObservers(textureInfo, true);
       }
     }
   }
@@ -1017,6 +1027,17 @@ void TextureManager::NotifyObservers(TextureManager::TextureInfo& textureInfo, c
   // and erase it from the list
   TextureInfo* info = &textureInfo;
 
+  if(info->animatedImageLoading)
+  {
+    // If loading failed, we don't need to get frameCount and frameInterval.
+    if(success)
+    {
+      info->frameCount    = info->animatedImageLoading.GetImageCount();
+      info->frameInterval = info->animatedImageLoading.GetFrameInterval(info->frameIndex);
+    }
+    info->animatedImageLoading.Reset();
+  }
+
   mQueueLoadFlag = true;
 
   while(info->observerList.Count())
@@ -1039,14 +1060,7 @@ void TextureManager::NotifyObservers(TextureManager::TextureInfo& textureInfo, c
 
     info->observerList.Erase(info->observerList.Begin());
 
-    if(info->storageType == StorageType::RETURN_PIXEL_BUFFER)
-    {
-      observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::PIXEL_BUFFER, info->pixelBuffer, info->url.GetUrl(), info->preMultiplied));
-    }
-    else
-    {
-      observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::TEXTURE, info->textureId, info->textureSet, (info->useAtlas == UseAtlas::USE_ATLAS) ? true : false, info->atlasRect, info->preMultiplied));
-    }
+    EmitLoadComplete(observer, *info, success);
 
     // Get the textureInfo from the container again as it may have been invalidated.
     TextureCacheIndex textureInfoIndex = mTextureCacheManager.GetCacheIndexFromId(textureId);
@@ -1101,6 +1115,22 @@ Dali::Geometry TextureManager::GetRenderGeometry(const TextureManager::TextureId
   return RenderingAddOn::Get().IsValid() ? RenderingAddOn::Get().GetGeometry(textureId, frontElements, backElements) : Geometry();
 }
 
+void TextureManager::EmitLoadComplete(TextureUploadObserver* observer, TextureManager::TextureInfo& textureInfo, const bool& success)
+{
+  if(textureInfo.storageType == StorageType::RETURN_PIXEL_BUFFER)
+  {
+    observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::PIXEL_BUFFER, textureInfo.pixelBuffer, textureInfo.url.GetUrl(), textureInfo.preMultiplied));
+  }
+  else if(textureInfo.isAnimatedImageFormat)
+  {
+    observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::ANIMATED_IMAGE_TEXTURE, textureInfo.textureId, textureInfo.frameCount, textureInfo.frameInterval));
+  }
+  else
+  {
+    observer->LoadComplete(success, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::TEXTURE, textureInfo.textureId, textureInfo.textureSet, (textureInfo.useAtlas == UseAtlas::USE_ATLAS) ? true : false, textureInfo.atlasRect, textureInfo.preMultiplied));
+  }
+}
+
 } // namespace Internal
 
 } // namespace Toolkit
index ee06c53..01f62ee 100644 (file)
@@ -112,27 +112,28 @@ public:
    * The parameters are used to specify how the animated image is loaded.
    * The observer has the LoadComplete method called when the load is ready.
    *
-   * @param[in] animatedImageLoading  The AnimatedImageLoading that contain the animated image information
-   * @param[in] frameIndex            The frame index to load.
-   * @param[in] samplingMode          The SamplingMode to use
-   * @param[in] synchronousLoading    true if the frame should be loaded synchronously
-   * @param[out] textureId            The textureId of the frame
-   * @param[in] wrapModeU             Horizontal Wrap mode
-   * @param[in] wrapModeV             Vertical Wrap mode
-   * @param[in] textureObserver       The client object should inherit from this and provide the "UploadCompleted" virtual.
-   *                                  This is called when an image load completes (or fails).
+   * @param[in]  animatedImageLoading  The AnimatedImageLoading that contain the animated image information
+   * @param[in]  frameIndex            The frame index to load.
+   * @param[out] textureId             The textureId of the frame
+   * @param[in]  samplingMode          The SamplingMode to use
+   * @param[in]  wrapModeU             Horizontal Wrap mode
+   * @param[in]  wrapModeV             Vertical Wrap mode
+   * @param[in]  synchronousLoading    true if the frame should be loaded synchronously
+   * @param[in]  useCache              true if this frame loading uses cache.
+   * @param[in]  textureObserver       The client object should inherit from this and provide the "LoadCompleted" virtual.
+   *                                   This is called when an image load completes (or fails).
    *
-   * @return                          The texture set containing the frame of animated image, or empty if still loading.
+   * @return                           The texture set containing the frame of animated image, or empty if still loading.
    */
-  TextureSet LoadAnimatedImageTexture(
-    Dali::AnimatedImageLoading      animatedImageLoading,
-    const std::uint32_t&            frameIndex,
-    const Dali::SamplingMode::Type& samplingMode,
-    const bool&                     synchronousLoading,
-    TextureManager::TextureId&      textureId,
-    const Dali::WrapMode::Type&     wrapModeU,
-    const Dali::WrapMode::Type&     wrapModeV,
-    TextureUploadObserver*          textureObserver);
+  TextureSet LoadAnimatedImageTexture(Dali::AnimatedImageLoading      animatedImageLoading,
+                                      const uint32_t&                 frameIndex,
+                                      TextureManager::TextureId&      textureId,
+                                      const Dali::SamplingMode::Type& samplingMode,
+                                      const Dali::WrapMode::Type&     wrapModeU,
+                                      const Dali::WrapMode::Type&     wrapModeV,
+                                      const bool&                     synchronousLoading,
+                                      const bool&                     useCache,
+                                      TextureUploadObserver*          textureObserver);
 
   /**
    * @brief Requests an image load of the given URL to get PixelBuffer.
@@ -145,7 +146,7 @@ public:
    * @param[in] fittingMode           The FittingMode to use
    * @param[in] samplingMode          The SamplingMode to use
    * @param[in] synchronousLoading    true if the URL should be loaded synchronously
-   * @param[in] textureObserver       The client object should inherit from this and provide the "UploadCompleted" virtual.
+   * @param[in] textureObserver       The client object should inherit from this and provide the "LoadCompleted" virtual.
    *                                  This is called when an image load completes (or fails).
    * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
    * @param[in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the
@@ -188,10 +189,10 @@ public:
    * @param[out] loadingStatus        The loading status of the texture
    * @param[in] wrapModeU             Horizontal Wrap mode
    * @param[in] wrapModeV             Vertical Wrap mode
-   * @param[in] textureObserver       The client object should inherit from this and provide the "UploadCompleted" virtual.
+   * @param[in] textureObserver       The client object should inherit from this and provide the "LoadCompleted" virtual.
    *                                  This is called when an image load completes (or fails).
    * @param[in] atlasObserver         This is used if the texture is atlased, and will be called instead of
-   *                                  textureObserver.UploadCompleted
+   *                                  textureObserver.LoadCompleted
    * @param[in] imageAtlasManager     The atlas manager to use for atlasing textures
    * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
    * @param[in] reloadPolicy          Forces a reload of the texture even if already cached
@@ -335,8 +336,8 @@ public: // Load Request API
    * @param[in] fittingMode           The FittingMode to use
    * @param[in] samplingMode          The SamplingMode to use
    * @param[in] useAtlasing           Set to USE_ATLAS to attempt atlasing. If atlasing fails, the image will still be loaded, and marked successful,
-   *                                  but "useAtlasing" will be set to false in the "UploadCompleted" callback from the TextureManagerUploadObserver.
-   * @param[in] observer              The client object should inherit from this and provide the "UploadCompleted" virtual.
+   *                                  but "useAtlasing" will be set to false in the "LoadCompleted" callback from the TextureManagerUploadObserver.
+   * @param[in] observer              The client object should inherit from this and provide the "LoadCompleted" virtual.
    *                                  This is called when an image load completes (or fails).
    * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
    * @param[in] reloadPolicy          Forces a reload of the texture even if already cached
@@ -345,7 +346,7 @@ public: // Load Request API
    *                                  default is false.
    * @return                          A TextureId to use as a handle to reference this Texture
    */
-  TextureManager::TextureId RequestLoad(
+  TextureId RequestLoad(
     const VisualUrl&                    url,
     const ImageDimensions&              desiredSize,
     const Dali::FittingMode::Type&      fittingMode,
@@ -376,11 +377,11 @@ public: // Load Request API
    * @param[in] samplingMode          The SamplingMode to use
    * @param[in] useAtlasing           Set to USE_ATLAS to attempt atlasing. If atlasing fails, the image will still
    *                                  be loaded, and marked successful,
-   *                                  but "useAtlasing" will be set to false in the "UploadCompleted" callback from
+   *                                  but "useAtlasing" will be set to false in the "LoadCompleted" callback from
    *                                  the TextureManagerUploadObserver.
    * @param[in] cropToMask            Only used with masking, this will crop the scaled image to the mask size.
    *                                  If false, then the mask will be scaled to fit the image before being applied.
-   * @param[in] observer              The client object should inherit from this and provide the "UploadCompleted"
+   * @param[in] observer              The client object should inherit from this and provide the "LoadCompleted"
    *                                  virtual.
    *                                  This is called when an image load completes (or fails).
    * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
@@ -391,7 +392,7 @@ public: // Load Request API
    *                                  default is false.
    * @return                          A TextureId to use as a handle to reference this Texture
    */
-  TextureManager::TextureId RequestLoad(
+  TextureId RequestLoad(
     const VisualUrl&                    url,
     const TextureManager::TextureId&    maskTextureId,
     const float&                        contentScale,
@@ -414,7 +415,7 @@ public: // Load Request API
    *                               default is false.
    * @return                       A TextureId to use as a handle to reference this mask Texture
    */
-  TextureManager::TextureId RequestMaskLoad(
+  TextureId RequestMaskLoad(
     const VisualUrl& maskUrl,
     const bool&      synchronousLoading = false);
 
@@ -438,11 +439,11 @@ private:
    * @param[in] samplingMode          The SamplingMode to use
    * @param[in] useAtlasing           Set to USE_ATLAS to attempt atlasing. If atlasing fails, the image will still be
    *                                  loaded, and marked successful, but "useAtlasing" will be set to false in the
-   *                                  "UploadCompleted" callback from the TextureManagerUploadObserver.
+   *                                  "LoadCompleted" callback from the TextureManagerUploadObserver.
    * @param[in] cropToMask            Whether to crop the target after masking, or scale the mask to the image before
    *                                  masking.
    * @param[in] storageType,          Whether the pixel data is stored in the cache or uploaded to the GPU
-   * @param[in] observer              The client object should inherit from this and provide the "UploadCompleted"
+   * @param[in] observer              The client object should inherit from this and provide the "LoadCompleted"
    *                                  virtual.
    *                                  This is called when an image load completes (or fails).
    * @param[in] orientationCorrection Whether to rotate image to match embedded orientation data
@@ -453,9 +454,10 @@ private:
    * @param[in] frameIndex            The frame index of a frame to be loaded frame
    * @param[in] synchronousLoading    True if the frame should be loaded synchronously. If you skip this parameter,
    *                                  default is false.
+   * @param[in] useCache              True if the texture will be cached.
    * @return                          A TextureId to use as a handle to reference this Texture
    */
-  TextureManager::TextureId RequestLoadInternal(
+  TextureId RequestLoadInternal(
     const VisualUrl&                    url,
     const TextureManager::TextureId&    maskTextureId,
     const float&                        contentScale,
@@ -471,7 +473,8 @@ private:
     TextureManager::MultiplyOnLoad&     preMultiplyOnLoad,
     Dali::AnimatedImageLoading          animatedImageLoading,
     const std::uint32_t&                frameIndex,
-    const bool&                         synchronousLoading);
+    const bool&                         synchronousLoading,
+    const bool&                         useCache);
 
   /**
    * @brief Load a new image synchronously.
@@ -580,6 +583,14 @@ private:
    */
   void NotifyObservers(TextureManager::TextureInfo& textureInfo, const bool& success);
 
+  /**
+   * Call LoadComplete to the observer.
+   * @param[in] observer    The client object should inherit from this and provide the "LoadCompleted"
+   * @param[in] textureInfo The struct associated with this Texture
+   * @param[in] success     If the pixel data was retrieved successfully and uploaded to GPU
+   */
+  void EmitLoadComplete(TextureUploadObserver* observer, TextureManager::TextureInfo& textureInfo, const bool& success);
+
 public:
   /**
    * @brief Common method to handle loading completion.
index 5f07c1f..514e544 100644 (file)
@@ -153,6 +153,8 @@ struct TextureInfo
     storageType(StorageType::UPLOAD_TO_TEXTURE),
     animatedImageLoading(animatedImageLoading),
     frameIndex(frameIndex),
+    frameCount(0u),
+    frameInterval(0u),
     useAtlas(useAtlas),
     loadSynchronously(loadSynchronously),
     cropToMask(cropToMask),
@@ -160,6 +162,7 @@ struct TextureInfo
     preMultiplyOnLoad(preMultiplyOnLoad),
     preMultiplied(false)
   {
+    isAnimatedImageFormat = (animatedImageLoading) ? true : false;
   }
 
   /**
@@ -185,7 +188,9 @@ struct TextureInfo
   Dali::SamplingMode::Type   samplingMode : 3;     ///< The requested SamplingMode
   StorageType                storageType;          ///< CPU storage / GPU upload;
   Dali::AnimatedImageLoading animatedImageLoading; ///< AnimatedImageLoading that contains animated image information.
-  std::uint32_t              frameIndex;           ///< frame index that be loaded, in case of animated image
+  uint32_t                   frameIndex;           ///< Frame index that be loaded, in case of animated image
+  uint32_t                   frameCount;           ///< Total frame count of input animated image. If this variable is not 0, this textureInfo is for animated image file format.
+  uint32_t                   frameInterval;        ///< Time interval between this frame and next frame of animated image.
   UseAtlas                   useAtlas;             ///< USE_ATLAS if an atlas was requested.
 
   bool loadSynchronously : 1;     ///< True if synchronous loading was requested
@@ -193,6 +198,7 @@ struct TextureInfo
   bool orientationCorrection : 1; ///< True if the image should be rotated to match exif orientation data
   bool preMultiplyOnLoad : 1;     ///< True if the image's color should be multiplied by it's alpha
   bool preMultiplied : 1;         ///< True if the image's color was multiplied by it's alpha
+  bool isAnimatedImageFormat : 1; ///< true if the image is requested from animated image visual.
 };
 
 } // namespace TextureManagerType
index 524ef67..a4cdc64 100644 (file)
@@ -49,6 +49,20 @@ TextureUploadObserver::TextureInformation::TextureInformation(ReturnType returnT
 {
 }
 
+TextureUploadObserver::TextureInformation::TextureInformation(ReturnType returnType, int32_t textureId, uint32_t frameCount, uint32_t interval)
+: returnType(returnType),
+  textureId(textureId),
+  textureSet(),
+  useAtlasing(false),
+  atlasRect(Vector4::ZERO),
+  preMultiplied(false),
+  pixelBuffer(),
+  url(),
+  frameCount(frameCount),
+  interval(interval)
+{
+}
+
 TextureUploadObserver::TextureUploadObserver()
 {
 }
index 211cad7..5848654 100644 (file)
@@ -44,14 +44,16 @@ public:
 
   enum class ReturnType
   {
-    TEXTURE = 0,
-    PIXEL_BUFFER
+    PIXEL_BUFFER = 0,
+    TEXTURE,
+    ANIMATED_IMAGE_TEXTURE
   };
 
   struct TextureInformation
   {
     TextureInformation(ReturnType returnType, int32_t textureId, TextureSet textureSet, bool useAtlasing, const Vector4& atlasRect, bool preMultiplied);
     TextureInformation(ReturnType returnType, Devel::PixelBuffer pixelBuffer, const std::string& url, bool preMultiplied);
+    TextureInformation(ReturnType returnType, int32_t textureId, uint32_t frameCount, uint32_t interval);
 
     TextureInformation();
 
@@ -63,6 +65,8 @@ public:
     bool               preMultiplied; ///< True if the image had pre-multiplied alpha applied
     Devel::PixelBuffer pixelBuffer;   ///< The PixelBuffer of the loaded image.
     std::string_view   url;           ///< The url address of the loaded image.
+    uint32_t           frameCount{0}; ///< The frameCount of the animated image
+    uint32_t           interval{0};   ///< Time interval between currently loaded frame and next frame.
   };
 
 public:
index b8eb497..d5dcdaa 100644 (file)
@@ -63,8 +63,25 @@ DALI_ENUM_TO_STRING_TABLE_BEGIN(WRAP_MODE)
   DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::WrapMode, MIRRORED_REPEAT)
 DALI_ENUM_TO_STRING_TABLE_END(WRAP_MODE)
 
-const Vector4  FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
-constexpr auto LOOP_FOREVER = -1;
+// load policies
+DALI_ENUM_TO_STRING_TABLE_BEGIN(LOAD_POLICY)
+  DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::ImageVisual::LoadPolicy, IMMEDIATE)
+  DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::ImageVisual::LoadPolicy, ATTACHED)
+DALI_ENUM_TO_STRING_TABLE_END(LOAD_POLICY)
+
+// release policies
+DALI_ENUM_TO_STRING_TABLE_BEGIN(RELEASE_POLICY)
+  DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::ImageVisual::ReleasePolicy, DETACHED)
+  DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::ImageVisual::ReleasePolicy, DESTROYED)
+  DALI_ENUM_TO_STRING_WITH_SCOPE(Dali::Toolkit::ImageVisual::ReleasePolicy, NEVER)
+DALI_ENUM_TO_STRING_TABLE_END(RELEASE_POLICY)
+
+static constexpr uint32_t SINGLE_IMAGE_COUNT = 1u;
+static constexpr uint32_t FIRST_FRAME_INDEX  = 0u;
+static constexpr uint16_t MINIMUM_CACHESIZE  = 1;
+static constexpr Vector4  FULL_TEXTURE_RECT(0.f, 0.f, 1.f, 1.f);
+static constexpr auto     LOOP_FOREVER = -1;
+static constexpr auto     FIRST_LOOP   = 0u;
 
 #if defined(DEBUG_ENABLED)
 Debug::Filter* gAnimImgLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_ANIMATED_IMAGE");
@@ -76,18 +93,15 @@ Debug::Filter* gAnimImgLogFilter = Debug::Filter::New(Debug::NoLogging, false, "
  *
  *   | New
  *   |   DoSetProperties()
- *   |   LoadFirstBatch()
- *   |     new cache
- *   |       cache->LoadBatch()
+ *   |   OnInitialize()
+ *   |     CreateImageCache()
  *   |
  *   | DoSetOnScene()
  *   |   PrepareTextureSet()
  *   |     cache->FirstFrame()
- *   |   CreateRenderer()    (Doesn't become ready until first frame loads)
- *   |   StartFirstFrame()
  *   |
  *   | FrameReady(textureSet)
- *   |   start first frame:
+ *   |   StartFirstFrame:
  *   |     actor.AddRenderer
  *   |     start timer
  *   |   mRenderer.SetTextures(textureSet)
@@ -97,8 +111,7 @@ Debug::Filter* gAnimImgLogFilter = Debug::Filter::New(Debug::NoLogging, false, "
  *   |     if front frame is ready,
  *   |       mRenderer.SetTextures( front frame's texture )
  *   |     else
- *   |       mWaitingForTexture=true
- *   |     cache->LoadBatch()
+ *   |       Waiting for frame ready.
  *   |
  *   | FrameReady(textureSet)
  *   |   mRenderer.SetTextures(textureSet)
@@ -112,11 +125,6 @@ AnimatedImageVisualPtr AnimatedImageVisual::New(VisualFactoryCache& factoryCache
   visual->InitializeAnimatedImage(imageUrl);
   visual->SetProperties(properties);
 
-  if(visual->mFrameCount > 0)
-  {
-    visual->LoadFirstBatch();
-  }
-
   visual->Initialize();
 
   return visual;
@@ -138,11 +146,6 @@ AnimatedImageVisualPtr AnimatedImageVisual::New(VisualFactoryCache& factoryCache
   visual->mFrameCount = imageUrls.Count();
   visual->SetProperties(properties);
 
-  if(visual->mFrameCount > 0)
-  {
-    visual->LoadFirstBatch();
-  }
-
   visual->Initialize();
 
   return visual;
@@ -153,11 +156,6 @@ AnimatedImageVisualPtr AnimatedImageVisual::New(VisualFactoryCache& factoryCache
   AnimatedImageVisualPtr visual(new AnimatedImageVisual(factoryCache, shaderFactory));
   visual->InitializeAnimatedImage(imageUrl);
 
-  if(visual->mFrameCount > 0)
-  {
-    visual->LoadFirstBatch();
-  }
-
   visual->Initialize();
 
   return visual;
@@ -165,9 +163,41 @@ AnimatedImageVisualPtr AnimatedImageVisual::New(VisualFactoryCache& factoryCache
 
 void AnimatedImageVisual::InitializeAnimatedImage(const VisualUrl& imageUrl)
 {
-  mImageUrl             = imageUrl;
+  mImageUrl = imageUrl;
   mAnimatedImageLoading = AnimatedImageLoading::New(imageUrl.GetUrl(), imageUrl.IsLocalResource());
-  mFrameCount           = mAnimatedImageLoading.GetImageCount();
+}
+
+void AnimatedImageVisual::CreateImageCache()
+{
+  DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "AnimatedImageVisual::CreateImageCache()  batchSize:%d  cacheSize:%d\n", mBatchSize, mCacheSize);
+
+  TextureManager& textureManager = mFactoryCache.GetTextureManager();
+
+  if(mAnimatedImageLoading)
+  {
+    mImageCache = new RollingAnimatedImageCache(textureManager, mAnimatedImageLoading, *this, mCacheSize, mBatchSize, IsSynchronousLoadingRequired());
+  }
+  else if(mImageUrls)
+  {
+    // Ensure the batch size and cache size are no bigger than the number of URLs,
+    // and that the cache is at least as big as the batch size.
+    uint16_t numUrls   = mImageUrls->size();
+    uint16_t batchSize = std::max(std::min(mBatchSize, numUrls), MINIMUM_CACHESIZE);
+    uint16_t cacheSize = std::max(std::min(std::max(batchSize, mCacheSize), numUrls), MINIMUM_CACHESIZE);
+    if(cacheSize < numUrls)
+    {
+      mImageCache = new RollingImageCache(textureManager, *mImageUrls, *this, cacheSize, batchSize, mFrameDelay);
+    }
+    else
+    {
+      mImageCache = new FixedImageCache(textureManager, *mImageUrls, *this, batchSize, mFrameDelay);
+    }
+  }
+
+  if(!mImageCache)
+  {
+    DALI_LOG_ERROR("mImageCache is null\n");
+  }
 }
 
 AnimatedImageVisual::AnimatedImageVisual(VisualFactoryCache& factoryCache, ImageVisualShaderFactory& shaderFactory)
@@ -179,14 +209,16 @@ AnimatedImageVisual::AnimatedImageVisual(VisualFactoryCache& factoryCache, Image
   mImageUrl(),
   mAnimatedImageLoading(),
   mFrameIndexForJumpTo(0),
+  mCurrentFrameIndex(FIRST_FRAME_INDEX),
   mImageUrls(NULL),
   mImageCache(NULL),
   mCacheSize(2),
   mBatchSize(2),
   mFrameDelay(100),
   mLoopCount(LOOP_FOREVER),
-  mCurrentLoopIndex(0),
-  mUrlIndex(0),
+  mCurrentLoopIndex(FIRST_LOOP),
+  mLoadPolicy(Toolkit::ImageVisual::LoadPolicy::ATTACHED),
+  mReleasePolicy(Toolkit::ImageVisual::ReleasePolicy::DETACHED),
   mFrameCount(0),
   mImageSize(),
   mActionStatus(DevelAnimatedImageVisual::Action::PLAY),
@@ -200,6 +232,12 @@ AnimatedImageVisual::AnimatedImageVisual(VisualFactoryCache& factoryCache, Image
 
 AnimatedImageVisual::~AnimatedImageVisual()
 {
+  // AnimatedImageVisual destroyed so remove texture unless ReleasePolicy is set to never release
+  // If this is animated image, clear cache. Else if this is single frame image, this is affected be release policy.
+  if(mFrameCount > SINGLE_IMAGE_COUNT || mReleasePolicy != Toolkit::ImageVisual::ReleasePolicy::NEVER)
+  {
+    mImageCache->ClearCache();
+  }
   delete mImageCache;
   delete mImageUrls;
 }
@@ -255,9 +293,13 @@ void AnimatedImageVisual::DoCreatePropertyMap(Property::Map& map) const
   map.Insert(Toolkit::ImageVisual::Property::FRAME_DELAY, static_cast<int>(mFrameDelay));
   map.Insert(Toolkit::DevelImageVisual::Property::LOOP_COUNT, static_cast<int>(mLoopCount));
   map.Insert(Toolkit::DevelImageVisual::Property::CURRENT_FRAME_NUMBER, (mImageCache) ? static_cast<int32_t>(mImageCache->GetCurrentFrameIndex()) : -1);
-  map.Insert(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, (mImageCache) ? static_cast<int32_t>(mImageCache->GetTotalFrameCount()) : -1);
+  map.Insert(Toolkit::DevelImageVisual::Property::TOTAL_FRAME_NUMBER, (mImageCache) ? static_cast<int32_t>((mAnimatedImageLoading) ? mAnimatedImageLoading.GetImageCount() : 
+                                                                                                                                     mImageCache->GetTotalFrameCount()) : -1);
 
   map.Insert(Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, mStopBehavior);
+
+  map.Insert(Toolkit::ImageVisual::Property::LOAD_POLICY, mLoadPolicy);
+  map.Insert(Toolkit::ImageVisual::Property::RELEASE_POLICY, mReleasePolicy);
 }
 
 void AnimatedImageVisual::DoCreateInstancePropertyMap(Property::Map& map) const
@@ -296,6 +338,7 @@ void AnimatedImageVisual::OnDoAction(const Dali::Property::Index actionId, const
       // STOP reset functionality will actually be done in a future change
       // Stop will be executed on next timer tick
       mActionStatus = DevelAnimatedImageVisual::Action::STOP;
+      mCurrentLoopIndex = FIRST_LOOP;
       if(IsOnScene())
       {
         DisplayNextFrame();
@@ -370,8 +413,25 @@ void AnimatedImageVisual::DoSetProperties(const Property::Map& propertyMap)
       {
         DoSetProperty(Toolkit::DevelImageVisual::Property::STOP_BEHAVIOR, keyValue.second);
       }
+      else if(keyValue.first == LOAD_POLICY_NAME)
+      {
+        DoSetProperty(Toolkit::ImageVisual::Property::LOAD_POLICY, keyValue.second);
+      }
+      else if(keyValue.first == RELEASE_POLICY_NAME)
+      {
+        DoSetProperty(Toolkit::ImageVisual::Property::RELEASE_POLICY, keyValue.second);
+      }
+      else if(keyValue.first == SYNCHRONOUS_LOADING)
+      {
+        DoSetProperty(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, keyValue.second);
+      }
     }
   }
+  // Load image immediately if LOAD_POLICY requires it
+  if(mLoadPolicy == Toolkit::ImageVisual::LoadPolicy::IMMEDIATE)
+  {
+    PrepareTextureSet();
+  }
 }
 
 void AnimatedImageVisual::DoSetProperty(Property::Index        index,
@@ -451,6 +511,10 @@ void AnimatedImageVisual::DoSetProperty(Property::Index        index,
       if(value.Get(frameDelay))
       {
         mFrameDelay = frameDelay;
+        if(mImageCache)
+        {
+          mImageCache->SetInterval(static_cast<uint32_t>(mFrameDelay));
+        }
       }
       break;
     }
@@ -489,29 +553,30 @@ void AnimatedImageVisual::DoSetProperty(Property::Index        index,
       }
       break;
     }
+
+    case Toolkit::ImageVisual::Property::RELEASE_POLICY:
+    {
+      int releasePolicy = 0;
+      Scripting::GetEnumerationProperty(value, RELEASE_POLICY_TABLE, RELEASE_POLICY_TABLE_COUNT, releasePolicy);
+      mReleasePolicy = Toolkit::ImageVisual::ReleasePolicy::Type(releasePolicy);
+      break;
+    }
+
+    case Toolkit::ImageVisual::Property::LOAD_POLICY:
+    {
+      int loadPolicy = 0;
+      Scripting::GetEnumerationProperty(value, LOAD_POLICY_TABLE, LOAD_POLICY_TABLE_COUNT, loadPolicy);
+      mLoadPolicy = Toolkit::ImageVisual::LoadPolicy::Type(loadPolicy);
+      break;
+    }
   }
 }
 
 void AnimatedImageVisual::DoSetOnScene(Actor& actor)
 {
+  mStartFirstFrame      = true;
   mPlacementActor       = actor;
-  TextureSet textureSet = PrepareTextureSet();
-
-  // Loading animated image file is failed.
-  if(!mImageCache ||
-     (mAnimatedImageLoading && !mAnimatedImageLoading.HasLoadingSucceeded()))
-  {
-    textureSet = SetLoadingFailed();
-  }
-
-  if(textureSet) // if the image loading is successful
-  {
-    StartFirstFrame(textureSet);
-  }
-  else
-  {
-    mStartFirstFrame = true;
-  }
+  PrepareTextureSet();
 }
 
 void AnimatedImageVisual::DoSetOffScene(Actor& actor)
@@ -525,8 +590,19 @@ void AnimatedImageVisual::DoSetOffScene(Actor& actor)
   }
 
   actor.RemoveRenderer(mImpl->mRenderer);
+  if(mReleasePolicy == Toolkit::ImageVisual::ReleasePolicy::DETACHED)
+  {
+    mImageCache->ClearCache(); // If INVALID_TEXTURE_ID then removal will be attempted on atlas
+    mImpl->mResourceStatus = Toolkit::Visual::ResourceStatus::PREPARING;
+
+    TextureSet textureSet = TextureSet::New();
+    mImpl->mRenderer.SetTextures(textureSet);
+  }
+
   mPlacementActor.Reset();
   mStartFirstFrame = false;
+  mCurrentFrameIndex = FIRST_FRAME_INDEX;
+  mCurrentLoopIndex = FIRST_LOOP;
 }
 
 void AnimatedImageVisual::OnSetTransform()
@@ -546,8 +622,23 @@ void AnimatedImageVisual::UpdateShader()
   }
 }
 
+Shader AnimatedImageVisual::GenerateShader() const
+{
+  bool   defaultWrapMode = mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE;
+  Shader shader;
+  shader = mImageVisualShaderFactory.GetShader(
+    mFactoryCache,
+    ImageVisualShaderFeature::FeatureBuilder()
+      .ApplyDefaultTextureWrapMode(defaultWrapMode)
+      .EnableRoundedCorner(IsRoundedCornerRequired())
+      .EnableBorderline(IsBorderlineRequired()));
+  return shader;
+}
+
 void AnimatedImageVisual::OnInitialize()
 {
+  CreateImageCache();
+
   bool   defaultWrapMode = mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE;
   Shader shader          = GenerateShader();
 
@@ -572,61 +663,7 @@ void AnimatedImageVisual::OnInitialize()
   }
 }
 
-void AnimatedImageVisual::LoadFirstBatch()
-{
-  // Ensure the batch size and cache size are no bigger than the number of URLs,
-  // and that the cache is at least as big as the batch size.
-  uint16_t numUrls   = 0;
-  uint16_t batchSize = 1;
-  uint16_t cacheSize = 1;
-
-  if(mImageUrls)
-  {
-    numUrls = mImageUrls->size();
-  }
-  else
-  {
-    numUrls = mFrameCount;
-  }
-
-  batchSize = std::min(mBatchSize, numUrls);
-  cacheSize = std::min(std::max(batchSize, mCacheSize), numUrls);
-
-  DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "AnimatedImageVisual::LoadFirstBatch()  batchSize:%d  cacheSize:%d\n", batchSize, cacheSize);
-
-  mUrlIndex                      = 0;
-  TextureManager& textureManager = mFactoryCache.GetTextureManager();
-
-  if(mAnimatedImageLoading)
-  {
-    mImageCache = new RollingAnimatedImageCache(textureManager, mAnimatedImageLoading, mFrameCount, *this, cacheSize, batchSize, IsSynchronousLoadingRequired());
-  }
-  else if(mImageUrls)
-  {
-    if(batchSize > 0 && cacheSize > 0)
-    {
-      if(cacheSize < numUrls)
-      {
-        mImageCache = new RollingImageCache(textureManager, *mImageUrls, *this, cacheSize, batchSize);
-      }
-      else
-      {
-        mImageCache = new FixedImageCache(textureManager, *mImageUrls, *this, batchSize);
-      }
-    }
-    else
-    {
-      mImageCache = new RollingImageCache(textureManager, *mImageUrls, *this, 1, 1);
-    }
-  }
-
-  if(!mImageCache)
-  {
-    DALI_LOG_ERROR("mImageCache is null\n");
-  }
-}
-
-void AnimatedImageVisual::StartFirstFrame(TextureSet& textureSet)
+void AnimatedImageVisual::StartFirstFrame(TextureSet& textureSet, uint32_t firstInterval)
 {
   DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "AnimatedImageVisual::StartFirstFrame()\n");
 
@@ -643,26 +680,23 @@ void AnimatedImageVisual::StartFirstFrame(TextureSet& textureSet)
     }
   }
 
-  if(mFrameCount > 1)
+  if(mImpl->mResourceStatus != Toolkit::Visual::ResourceStatus::FAILED)
   {
-    int frameDelay = mImageCache->GetFrameInterval(0);
-    if(frameDelay == 0u)
+    if(mFrameCount > SINGLE_IMAGE_COUNT)
     {
-      frameDelay = mFrameDelay; // from URL array
+      mFrameDelayTimer = Timer::New(firstInterval);
+      mFrameDelayTimer.TickSignal().Connect(this, &AnimatedImageVisual::DisplayNextFrame);
+      mFrameDelayTimer.Start();
     }
-    mFrameDelayTimer = Timer::New(frameDelay);
-    mFrameDelayTimer.TickSignal().Connect(this, &AnimatedImageVisual::DisplayNextFrame);
-    mFrameDelayTimer.Start();
-  }
 
-  if(mImpl->mResourceStatus != Toolkit::Visual::ResourceStatus::FAILED)
-  {
     DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "ResourceReady(ResourceStatus::READY)\n");
     ResourceReady(Toolkit::Visual::ResourceStatus::READY);
   }
+
+  mCurrentFrameIndex = FIRST_FRAME_INDEX;
 }
 
-TextureSet AnimatedImageVisual::PrepareTextureSet()
+void AnimatedImageVisual::PrepareTextureSet()
 {
   TextureSet textureSet;
   if(mImageCache)
@@ -670,12 +704,11 @@ TextureSet AnimatedImageVisual::PrepareTextureSet()
     textureSet = mImageCache->FirstFrame();
   }
 
+  // Check whether synchronous loading is true or false for the first frame.
   if(textureSet)
   {
     SetImageSize(textureSet);
   }
-
-  return textureSet;
 }
 
 void AnimatedImageVisual::SetImageSize(TextureSet& textureSet)
@@ -691,24 +724,28 @@ void AnimatedImageVisual::SetImageSize(TextureSet& textureSet)
   }
 }
 
-void AnimatedImageVisual::FrameReady(TextureSet textureSet)
+void AnimatedImageVisual::FrameReady(TextureSet textureSet, uint32_t interval)
 {
   // When image visual requested to load new frame to mImageCache and it is failed.
-  if(!textureSet)
+  if(!mImageCache || !textureSet)
   {
     textureSet = SetLoadingFailed();
   }
-
   SetImageSize(textureSet);
 
   if(mStartFirstFrame)
   {
-    StartFirstFrame(textureSet);
+    mFrameCount = mImageCache->GetTotalFrameCount();
+    StartFirstFrame(textureSet, interval);
   }
   else
   {
     if(mImpl->mRenderer)
     {
+      if(mFrameDelayTimer && interval > 0u)
+      {
+        mFrameDelayTimer.SetInterval(interval);
+      }
       mImpl->mRenderer.SetTextures(textureSet);
     }
   }
@@ -721,7 +758,6 @@ bool AnimatedImageVisual::DisplayNextFrame()
 
   if(mImageCache)
   {
-    bool     nextFrame  = false;
     uint32_t frameIndex = mImageCache->GetCurrentFrameIndex();
 
     if(mIsJumpTo)
@@ -735,10 +771,10 @@ bool AnimatedImageVisual::DisplayNextFrame()
     }
     else if(mActionStatus == DevelAnimatedImageVisual::Action::STOP)
     {
-      frameIndex = 0;
+      mCurrentLoopIndex = FIRST_LOOP;
       if(mStopBehavior == DevelImageVisual::StopBehavior::FIRST_FRAME)
       {
-        frameIndex = 0;
+        frameIndex = FIRST_FRAME_INDEX;
       }
       else if(mStopBehavior == DevelImageVisual::StopBehavior::LAST_FRAME)
       {
@@ -751,13 +787,12 @@ bool AnimatedImageVisual::DisplayNextFrame()
     }
     else
     {
-      if(mFrameCount > 1)
+      if(mFrameCount > SINGLE_IMAGE_COUNT)
       {
-        nextFrame = true;
         frameIndex++;
         if(frameIndex >= mFrameCount)
         {
-          frameIndex %= mFrameCount;
+          frameIndex = FIRST_FRAME_INDEX;
           ++mCurrentLoopIndex;
         }
 
@@ -768,38 +803,24 @@ bool AnimatedImageVisual::DisplayNextFrame()
           return DisplayNextFrame();
         }
       }
-
-      unsigned int delay = mImageCache->GetFrameInterval(frameIndex);
-      if(delay > 0u)
-      {
-        if(mFrameDelayTimer.GetInterval() != delay)
-        {
-          mFrameDelayTimer.SetInterval(delay);
-        }
-      }
     }
 
     DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "AnimatedImageVisual::DisplayNextFrame(this:%p) CurrentFrameIndex:%d\n", this, frameIndex);
 
-    if(nextFrame)
-    {
-      textureSet = mImageCache->NextFrame();
-    }
-    else
-    {
-      textureSet = mImageCache->Frame(frameIndex);
-    }
-
-    continueTimer = (mActionStatus == DevelAnimatedImageVisual::Action::PLAY) ? true : false;
-  }
+    textureSet = mImageCache->Frame(frameIndex);
 
-  if(textureSet)
-  {
-    SetImageSize(textureSet);
-    if(mImpl->mRenderer)
+    if(textureSet)
     {
-      mImpl->mRenderer.SetTextures(textureSet);
+      SetImageSize(textureSet);
+      if(mImpl->mRenderer)
+      {
+        mImpl->mRenderer.SetTextures(textureSet);
+      }
+      mFrameDelayTimer.SetInterval(mImageCache->GetFrameInterval(frameIndex));
     }
+
+    mCurrentFrameIndex = frameIndex;
+    continueTimer      = (mActionStatus == DevelAnimatedImageVisual::Action::PLAY && textureSet) ? true : false;
   }
 
   return continueTimer;
@@ -830,19 +851,6 @@ TextureSet AnimatedImageVisual::SetLoadingFailed()
   return textureSet;
 }
 
-Shader AnimatedImageVisual::GenerateShader() const
-{
-  bool   defaultWrapMode = mWrapModeU <= WrapMode::CLAMP_TO_EDGE && mWrapModeV <= WrapMode::CLAMP_TO_EDGE;
-  Shader shader;
-  shader = mImageVisualShaderFactory.GetShader(
-    mFactoryCache,
-    ImageVisualShaderFeature::FeatureBuilder()
-      .ApplyDefaultTextureWrapMode(defaultWrapMode)
-      .EnableRoundedCorner(IsRoundedCornerRequired())
-      .EnableBorderline(IsBorderlineRequired()));
-  return shader;
-}
-
 } // namespace Internal
 
 } // namespace Toolkit
index ad8b5ac..5e70964 100644 (file)
@@ -193,54 +193,51 @@ protected:
 
 private:
   /**
-   * Creates the renderer for the animated image
+   * @brief Initialize the animated image variables.
+   * @param[in] imageUrl The url of the animated image
    */
-  void CreateRenderer();
+  void InitializeAnimatedImage(const VisualUrl& imageUrl);
 
   /**
-   * Starts the Load of the first batch of URLs
+   * @brief Create image cache for animated image or image array.
    */
-  void LoadFirstBatch();
+  void CreateImageCache();
 
   /**
-   * Adds the texture set to the renderer, and the renderer to the
+   * @brief Adds the texture set to the renderer, and the renderer to the
    * placement actor, and starts the frame timer
-   * @param[in] textureSet The texture set to apply
+   * @param[in] textureSet    The texture set to apply
+   * @param[in] firstInterval frame interval(ms) for the first frame.
    */
-  void StartFirstFrame(TextureSet& textureSet);
+  void StartFirstFrame(TextureSet& textureSet, uint32_t firstInterval);
 
   /**
-   * Prepares the texture set for displaying
+   * @brief Prepares the texture set for displaying
    */
-  TextureSet PrepareTextureSet();
+  void PrepareTextureSet();
 
   /**
-   * Set the image size from the texture set
+   * @brief Set the image size from the texture set
    * @param[in] textureSet The texture set to get the size from
    */
   void SetImageSize(TextureSet& textureSet);
 
   /**
-   * Called when the next frame is ready.
+   * @brief Called when the next frame is ready.
    * @param[in] textureSet the texture set to apply
+   * @param[in] interval interval(ms) for the frame
    */
-  void FrameReady(TextureSet textureSet) override;
+  void FrameReady(TextureSet textureSet, uint32_t interval) override;
 
   /**
-   * Display the next frame. It is called when the mFrameDelayTimer ticks.
-   * Returns true to ensure the timer continues running.
+   * @brief Display the next frame. It is called when the mFrameDelayTimer ticks.
+   * @return true to ensure the timer continues running.
    */
   bool DisplayNextFrame();
 
   /**
-   * Initialize the animated image variables.
-   * @param[in] imageUrl The url of the animated image
-   */
-  void InitializeAnimatedImage(const VisualUrl& imageUrl);
-
-  /**
-   * Set the state of loading fail of an image or a frame.
-   * Returns TextureSet of broken image.
+   * @brief Set the state of loading fail of an image or a frame.
+   * @return TextureSet of broken image.
    */
   TextureSet SetLoadingFailed();
 
@@ -260,6 +257,7 @@ private:
   VisualUrl                  mImageUrl;
   Dali::AnimatedImageLoading mAnimatedImageLoading; // Only needed for animated image
   uint32_t                   mFrameIndexForJumpTo;  // Frame index into textureRects
+  uint32_t                   mCurrentFrameIndex;
 
   // Variables for Multi-Image player
   ImageCache::UrlList* mImageUrls;
@@ -269,7 +267,10 @@ private:
   uint16_t             mFrameDelay;
   int16_t              mLoopCount;
   int16_t              mCurrentLoopIndex;
-  uint16_t             mUrlIndex;
+
+  // Variables for image visual policy.
+  Dali::Toolkit::ImageVisual::LoadPolicy::Type    mLoadPolicy;
+  Dali::Toolkit::ImageVisual::ReleasePolicy::Type mReleasePolicy;
 
   // Shared variables
   uint32_t        mFrameCount; // Number of frames
index dcb6621..192a3c4 100644 (file)
@@ -20,6 +20,9 @@
 // INTERNAL HEADERS
 #include <dali-toolkit/internal/visuals/image-atlas-manager.h> // For ImageAtlasManagerPtr
 
+// EXTERNAL HEADERS
+#include <dali/integration-api/debug.h>
+
 namespace Dali
 {
 namespace Toolkit
@@ -28,79 +31,60 @@ namespace Internal
 {
 namespace
 {
-const bool ENABLE_ORIENTATION_CORRECTION(true);
+constexpr bool ENABLE_ORIENTATION_CORRECTION(true);
+constexpr uint32_t FIRST_FRAME_INDEX = 0u;
 } // namespace
 
 FixedImageCache::FixedImageCache(
-  TextureManager& textureManager, UrlList& urlList, ImageCache::FrameReadyObserver& observer, unsigned int batchSize)
-: ImageCache(textureManager, observer, batchSize),
+  TextureManager& textureManager, UrlList& urlList, ImageCache::FrameReadyObserver& observer, uint32_t batchSize, uint32_t interval)
+: ImageCache(textureManager, observer, batchSize, interval),
   mImageUrls(urlList),
-  mFront(0u)
+  mFront(FIRST_FRAME_INDEX)
 {
   mReadyFlags.reserve(mImageUrls.size());
-  LoadBatch();
 }
 
 FixedImageCache::~FixedImageCache()
 {
-  if(mTextureManagerAlive)
-  {
-    for(std::size_t i = 0; i < mImageUrls.size(); ++i)
-    {
-      mTextureManager.Remove(mImageUrls[i].mTextureId, this);
-    }
-  }
+  ClearCache();
 }
 
 TextureSet FixedImageCache::Frame(uint32_t frameIndex)
 {
-  while(frameIndex > mFront)
+  TextureSet textureSet;
+  if(frameIndex >= mImageUrls.size())
+  {
+    DALI_LOG_ERROR("Wrong frameIndex requested.\n");
+    return textureSet;
+  }
+
+  while(mReadyFlags.size() < mImageUrls.size() &&
+        (frameIndex > mFront || mReadyFlags.empty()))
   {
     ++mFront;
-    if(mFront >= mImageUrls.size())
-    {
-      mFront = 0;
-    }
     LoadBatch();
   }
 
   mFront = frameIndex;
 
-  TextureSet textureSet;
-  if(IsFrontReady() == true)
+  if(IsFrontReady() && mLoadState != TextureManager::LoadState::LOAD_FAILED)
   {
     textureSet = GetFrontTextureSet();
   }
-  else
-  {
-    mWaitingForReadyFrame = true;
-  }
 
   return textureSet;
 }
 
 TextureSet FixedImageCache::FirstFrame()
 {
-  TextureSet textureSet = GetFrontTextureSet();
-
-  if(!textureSet)
-  {
-    mWaitingForReadyFrame = true;
-  }
-
-  return textureSet;
-}
-
-TextureSet FixedImageCache::NextFrame()
-{
-  TextureSet textureSet = Frame((mFront + 1) % mImageUrls.size());
+  TextureSet textureSet = Frame(FIRST_FRAME_INDEX);
 
   return textureSet;
 }
 
 uint32_t FixedImageCache::GetFrameInterval(uint32_t frameIndex) const
 {
-  return 0u;
+  return mInterval;
 }
 
 int32_t FixedImageCache::GetCurrentFrameIndex() const
@@ -121,13 +105,11 @@ bool FixedImageCache::IsFrontReady() const
 void FixedImageCache::LoadBatch()
 {
   // Try and load up to mBatchSize images, until the cache is filled.
-  // Once the cache is filled, mUrlIndex exceeds mImageUrls size and
-  // no more images are loaded.
-  bool frontFrameReady = IsFrontReady();
-
-  for(unsigned int i = 0; i < mBatchSize && mUrlIndex < mImageUrls.size(); ++i)
+  // Once the cache is filled, no more images are loaded.
+  for(unsigned int i = 0; i < mBatchSize && mReadyFlags.size() < mImageUrls.size(); ++i)
   {
-    std::string& url = mImageUrls[mUrlIndex].mUrl;
+    uint32_t frameIndex = mReadyFlags.size();
+    std::string& url = mImageUrls[frameIndex].mUrl;
 
     mReadyFlags.push_back(false);
 
@@ -135,6 +117,7 @@ void FixedImageCache::LoadBatch()
     // from within this method. This means it won't yet have a texture id, so we
     // need to account for this inside the LoadComplete method using mRequestingLoad.
     mRequestingLoad = true;
+    mLoadState = TextureManager::LoadState::LOADING;
 
     bool                               synchronousLoading = false;
     bool                               atlasingStatus     = false;
@@ -147,28 +130,9 @@ void FixedImageCache::LoadBatch()
     auto                               preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
 
     mTextureManager.LoadTexture(
-      url, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, maskInfo, synchronousLoading, mImageUrls[mUrlIndex].mTextureId, textureRect, textureRectSize, atlasingStatus, loadingStatus, Dali::WrapMode::Type::DEFAULT, Dali::WrapMode::Type::DEFAULT, this, atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiply);
+      url, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, maskInfo, synchronousLoading, mImageUrls[frameIndex].mTextureId, textureRect, textureRectSize, atlasingStatus, loadingStatus, Dali::WrapMode::Type::DEFAULT, Dali::WrapMode::Type::DEFAULT, this, atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiply);
 
-    if(loadingStatus == false) // not loading, means it's already ready.
-    {
-      SetImageFrameReady(mImageUrls[mUrlIndex].mTextureId);
-    }
     mRequestingLoad = false;
-    ++mUrlIndex;
-  }
-
-  CheckFrontFrame(frontFrameReady);
-}
-
-void FixedImageCache::SetImageFrameReady(TextureManager::TextureId textureId)
-{
-  for(std::size_t i = 0; i < mImageUrls.size(); ++i)
-  {
-    if(mImageUrls[i].mTextureId == textureId)
-    {
-      mReadyFlags[i] = true;
-      break;
-    }
   }
 }
 
@@ -179,29 +143,53 @@ TextureSet FixedImageCache::GetFrontTextureSet() const
 
 void FixedImageCache::CheckFrontFrame(bool wasReady)
 {
-  if(mWaitingForReadyFrame && wasReady == false && IsFrontReady())
+  if(wasReady == false && IsFrontReady())
   {
-    mWaitingForReadyFrame = false;
-    mObserver.FrameReady(GetFrontTextureSet());
+    mObserver.FrameReady(GetFrontTextureSet(), mInterval);
   }
 }
 
-void FixedImageCache::LoadComplete(bool loadSuccess, TextureInformation textureInformation)
+void FixedImageCache::ClearCache()
 {
-  bool frontFrameReady = IsFrontReady();
-
-  if(!mRequestingLoad)
+  if(mTextureManagerAlive)
   {
-    SetImageFrameReady(textureInformation.textureId);
+    for(std::size_t i = 0; i < mImageUrls.size(); ++i)
+    {
+      mTextureManager.Remove(mImageUrls[i].mTextureId, this);
+      mImageUrls[i].mTextureId = TextureManager::INVALID_TEXTURE_ID;
+    }
+  }
+  mReadyFlags.clear();
+  mLoadState = TextureManager::LoadState::NOT_STARTED;
+}
 
+void FixedImageCache::LoadComplete(bool loadSuccess, TextureInformation textureInformation)
+{
+  if(loadSuccess)
+  {
+    mLoadState = TextureManager::LoadState::LOAD_FINISHED;
+    bool frontFrameReady = IsFrontReady();
+    if(!mRequestingLoad)
+    {
+      for(std::size_t i = 0; i < mImageUrls.size(); ++i)
+      {
+        if(mImageUrls[i].mTextureId == textureInformation.textureId)
+        {
+          mReadyFlags[i] = true;
+          break;
+        }
+      }
+    }
+    else
+    {
+      mReadyFlags.back() = true;
+    }
     CheckFrontFrame(frontFrameReady);
   }
   else
   {
-    // LoadComplete has been called from within RequestLoad. TextureManager must
-    // therefore already have the texture cached, so make the texture ready.
-    // (Use the last texture, as the texture id hasn't been assigned yet)
-    mReadyFlags.back() = true;
+    mLoadState = TextureManager::LoadState::LOAD_FAILED;
+    mObserver.FrameReady(TextureSet(), 0);
   }
 }
 
index 6a2394a..2d446f0 100644 (file)
@@ -36,6 +36,7 @@ public:
    * @param[in] urlList List of urls to cache
    * @param[in] observer FrameReady observer
    * @param[in] batchSize The size of a batch to load
+   * @param[in] interval Time interval between each frame
    *
    * This will start loading textures immediately, according to the
    * batch and cache sizes. The cache is as large as the number of urls.
@@ -43,79 +44,79 @@ public:
   FixedImageCache(TextureManager&                 textureManager,
                   UrlList&                        urlList,
                   ImageCache::FrameReadyObserver& observer,
-                  unsigned int                    batchSize);
+                  uint32_t                        batchSize,
+                  uint32_t                        interval);
 
   ~FixedImageCache() override;
 
   /**
-   * Get the Nth frame. If it's not ready, this will trigger the
-   * sending of FrameReady() when the image becomes ready.
+   * @copydoc Internal::ImageCache::Frame()
    */
   TextureSet Frame(uint32_t frameIndex) override;
 
   /**
-   * Get the first frame. If it's not ready, this will trigger the
-   * sending of FrameReady() when the image becomes ready.
+   * @copydoc Internal::ImageCache::FirstFrame()
    */
   TextureSet FirstFrame() override;
 
   /**
-   * Get the next frame. If it's not ready, this will trigger the
-   * sending of FrameReady() when the image becomes ready.
-   */
-  TextureSet NextFrame() override;
-
-  /**
-   * Get the interval of Nth frame.
+   * @copydoc Internal::ImageCache::GetFrameInterval()
    */
   uint32_t GetFrameInterval(uint32_t frameIndex) const override;
 
   /**
-   * Get the current rendered frame index.
-   * If there isn't any loaded frame, returns -1.
+   * @copydoc Internal::ImageCache::GetCurrentFrameIndex()
    */
   int32_t GetCurrentFrameIndex() const override;
 
   /**
-   * Get total frame count of the animated image file.
+   * @copydoc Internal::ImageCache::GetTotalFrameCount()
    */
   int32_t GetTotalFrameCount() const override;
 
+  /**
+   * @copydoc Internal::ImageCache::ClearCache()
+   */
+  void ClearCache() override;
+
 private:
   /**
+   * @brief Check whether the front frame is ready or not.
+   *
    * @return true if the front frame is ready
    */
   bool IsFrontReady() const;
 
   /**
-   * Load the next batch of images
+   * @brief Load the next batch of images
    */
   void LoadBatch();
 
   /**
-   * Find the matching image frame, and set it to ready
-   */
-  void SetImageFrameReady(TextureManager::TextureId textureId);
-
-  /**
-   * Get the texture set of the front frame.
-   * @return the texture set
+   * @brief Get the texture set of the front frame.
+   *
+   * @return the texture set of the front of Cache.
    */
   TextureSet GetFrontTextureSet() const;
 
   /**
-   * Check if the front frame has become ready - if so, inform observer
+   * @brief Check if the front frame has become ready - if so, inform observer
+   *
    * @param[in] wasReady Readiness before call.
    */
   void CheckFrontFrame(bool wasReady);
 
 protected:
+  /**
+   * @copydoc Toolkit::TextureUploadObserver::LoadComplete()
+   */
   void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override;
 
 private:
-  std::vector<UrlStore>& mImageUrls;
-  std::vector<bool>      mReadyFlags;
-  unsigned int           mFront;
+  std::vector<UrlStore>&                 mImageUrls;
+  std::vector<bool>                      mReadyFlags;
+  std::vector<TextureManager::LoadState> mLoadStates;
+  uint32_t                               mFront;
 };
 
 } //namespace Internal
index cccb085..27c3ef2 100644 (file)
@@ -24,12 +24,13 @@ namespace Internal
 {
 ImageCache::ImageCache(TextureManager&                 textureManager,
                        ImageCache::FrameReadyObserver& observer,
-                       unsigned int                    batchSize)
+                       uint32_t                        batchSize,
+                       uint32_t                        interval)
 : mTextureManager(textureManager),
   mObserver(observer),
   mBatchSize(batchSize),
-  mUrlIndex(0u),
-  mWaitingForReadyFrame(false),
+  mInterval(interval),
+  mLoadState(TextureManager::LoadState::NOT_STARTED),
   mRequestingLoad(false),
   mTextureManagerAlive(true)
 {
@@ -49,6 +50,11 @@ void ImageCache::TextureManagerDestroyed()
   mTextureManagerAlive = false;
 }
 
+void ImageCache::SetInterval(uint32_t interval)
+{
+  mInterval = interval;
+}
+
 } //namespace Internal
 } //namespace Toolkit
 } //namespace Dali
index 3200902..19a8f52 100644 (file)
@@ -37,10 +37,11 @@ public:
   {
   public:
     /**
-     * Informs observer when the next texture set is ready to display
+     * @brief Informs observer when the next texture set is ready to display
      * @param[in] textureSet The ready texture set
+     * @param[in] interval interval(ms) for the frame
      */
-    virtual void FrameReady(TextureSet textureSet) = 0;
+    virtual void FrameReady(TextureSet textureSet, uint32_t interval) = 0;
   };
 
   struct UrlStore
@@ -56,69 +57,89 @@ public:
 
 public:
   /**
-   * Constructor.
+   * @brief Constructor.
    * @param[in] textureManager The texture manager
    * @param[in] urlList List of urls to cache
    * @param[in] observer FrameReady observer
    * @param[in] batchSize The size of a batch to load
+   * @param[in] interval Time interval(ms) between each frame 
    *
    * This will start loading textures immediately, according to the
    * batch and cache sizes. The cache is as large as the number of urls.
    */
   ImageCache(TextureManager&                 textureManager,
              ImageCache::FrameReadyObserver& observer,
-             unsigned int                    batchSize);
+             uint32_t                        batchSize,
+             uint32_t                        interval);
 
   virtual ~ImageCache();
 
   /**
-   * Get the first frame. If it's not ready, this will trigger the
+   * @brief Get the first frame. If it's not ready, this will trigger the
    * sending of FrameReady() when the image becomes ready.
+   *
+   * @return TextureSet of the first frame.
    */
   virtual TextureSet FirstFrame() = 0;
 
   /**
-   * Get the next frame. If it's not ready, this will trigger the
-   * sending of FrameReady() when the image becomes ready.
-   */
-  virtual TextureSet NextFrame() = 0;
-
-  /**
-   * Get the Nth frame. If it's not ready, this will trigger the
+   * @brief Get the Nth frame. If it's not ready, this will trigger the
    * sending of FrameReady() when the image becomes ready.
+   *
+   * @param[in] frameIndex required frame index to be returned.
+   * @return TextureSet of the frame index.
    */
   virtual TextureSet Frame(uint32_t frameIndex) = 0;
 
   /**
-   * Get the interval of Nth frame.
+   * @brief Get the interval(ms) of Nth frame.
+   *
+   * @param[in] frameIndex frame index to get frame interval.
+   * @return Time interval in millisecond between frames of frameIndex and frameIndex + 1.
    */
   virtual uint32_t GetFrameInterval(uint32_t frameIndex) const = 0;
 
   /**
-   * Get the current rendered frame index.
+   * @brief Get the current rendered frame index.
    * If there isn't any loaded frame, returns -1.
+   *
+   * @return Frame index of currently showing frame.
    */
   virtual int32_t GetCurrentFrameIndex() const = 0;
 
   /**
-   * Get total frame count of the animated image file.
+   * @brief Get total frame count of the animated image file.
+   *
+   * @return Total frame count of the animated image file.
    */
   virtual int32_t GetTotalFrameCount() const = 0;
 
+  /**
+   * @brief Clears animated image cache and remove loaded textures.
+   */
+  virtual void ClearCache() = 0;
+
+  /**
+   * @brief Set default interval(ms) between each frame.
+   *
+   * @param[in] interval time interval in millisecond to be used as default interval.
+   */
+  virtual void SetInterval(uint32_t interval);
+
 private:
   /**
-   * Called before the texture manager is destroyed.
+   * @brief Called before the texture manager is destroyed.
    */
   void TextureManagerDestroyed() final;
 
 protected:
-  TextureManager&     mTextureManager;
-  FrameReadyObserver& mObserver;
-  unsigned int        mBatchSize;
-  unsigned int        mUrlIndex;
-  bool                mWaitingForReadyFrame : 1;
-  bool                mRequestingLoad : 1;
-  bool                mTextureManagerAlive : 1;
+  TextureManager&           mTextureManager;
+  FrameReadyObserver&       mObserver;
+  uint32_t                  mBatchSize;
+  uint32_t                  mInterval;
+  TextureManager::LoadState mLoadState;
+  bool                      mRequestingLoad : 1;
+  bool                      mTextureManagerAlive : 1;
 };
 
 } //namespace Internal
index 490c3be..473f276 100644 (file)
@@ -17,8 +17,6 @@
 // CLASS HEADER
 #include "rolling-animated-image-cache.h"
 
-// EXTERNAL HEADERS
-
 // INTERNAL HEADERS
 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
 #include <dali-toolkit/internal/visuals/image-atlas-manager.h> // For ImageAtlasManagerPtr
@@ -45,7 +43,7 @@ Debug::Filter* gAnimImgLogFilter = Debug::Filter::New(Debug::NoLogging, false, "
 #define LOG_CACHE
 #endif
 
-const bool ENABLE_ORIENTATION_CORRECTION(true);
+static constexpr bool ENABLE_ORIENTATION_CORRECTION(true);
 
 } // namespace
 
@@ -55,32 +53,30 @@ namespace Toolkit
 {
 namespace Internal
 {
+namespace
+{
+static constexpr uint32_t SINGLE_IMAGE_COUNT = 1u;
+static constexpr uint32_t FIRST_FRAME_INDEX  = 0u;
+} // namespace
+
 RollingAnimatedImageCache::RollingAnimatedImageCache(
-  TextureManager& textureManager, AnimatedImageLoading& animatedImageLoading, uint32_t frameCount, ImageCache::FrameReadyObserver& observer, uint16_t cacheSize, uint16_t batchSize, bool isSynchronousLoading)
-: ImageCache(textureManager, observer, batchSize),
+  TextureManager& textureManager, AnimatedImageLoading& animatedImageLoading, ImageCache::FrameReadyObserver& observer, uint16_t cacheSize, uint16_t batchSize, bool isSynchronousLoading)
+: ImageCache(textureManager, observer, batchSize, 0u),
   mAnimatedImageLoading(animatedImageLoading),
-  mFrameCount(frameCount),
-  mFrameIndex(0),
+  mFrameCount(SINGLE_IMAGE_COUNT),
+  mFrameIndex(FIRST_FRAME_INDEX),
   mCacheSize(cacheSize),
   mQueue(cacheSize),
-  mIsSynchronousLoading(isSynchronousLoading),
-  mOnLoading(false)
+  mIsSynchronousLoading(isSynchronousLoading)
 {
   mImageUrls.resize(mFrameCount);
   mIntervals.assign(mFrameCount, 0);
-  LoadBatch();
 }
 
 RollingAnimatedImageCache::~RollingAnimatedImageCache()
 {
-  if(mTextureManagerAlive)
-  {
-    while(!mQueue.IsEmpty())
-    {
-      ImageFrame imageFrame = mQueue.PopFront();
-      mTextureManager.Remove(mImageUrls[imageFrame.mFrameNumber].mTextureId, this);
-    }
-  }
+  ClearCache();
+  mAnimatedImageLoading.Reset();
 }
 
 TextureSet RollingAnimatedImageCache::Frame(uint32_t frameIndex)
@@ -95,53 +91,53 @@ TextureSet RollingAnimatedImageCache::Frame(uint32_t frameIndex)
   }
 
   TextureSet textureSet;
+  uint32_t   batchFrameIndex = frameIndex;
   // If we need to load new frame that are not stored in queue.
   // Load the frame synchronously.
+  bool synchronouslyLoaded = false;
   if(mIsSynchronousLoading && mQueue.IsEmpty())
   {
-    bool synchronousLoading = true;
-    textureSet              = mTextureManager.LoadAnimatedImageTexture(mAnimatedImageLoading, frameIndex, SamplingMode::BOX_THEN_LINEAR, synchronousLoading, mImageUrls[frameIndex].mTextureId, Dali::WrapMode::Type::DEFAULT, Dali::WrapMode::Type::DEFAULT, this);
-    mFrameIndex             = (frameIndex + 1) % mFrameCount;
+    textureSet          = RequestFrameLoading(frameIndex, frameIndex == FIRST_FRAME_INDEX, true);
+    batchFrameIndex     = (frameIndex + 1) % mFrameCount;
+    uint32_t interval = 0u;
+    if(textureSet)
+    {
+      synchronouslyLoaded = true;
+      interval = mAnimatedImageLoading.GetFrameInterval(mQueue.Back().mFrameNumber);
+    }
+    MakeFrameReady(synchronouslyLoaded, textureSet, interval);
   }
 
-  if(popExist || mQueue.IsEmpty())
+  if(popExist || mQueue.IsEmpty() || synchronouslyLoaded)
   {
     // If the frame of frameIndex was already loaded, load batch from the last frame of queue
     if(!mQueue.IsEmpty())
     {
       if(!mLoadWaitingQueue.empty())
       {
-        mFrameIndex = (mLoadWaitingQueue.back() + 1) % mFrameCount;
+        batchFrameIndex = (mLoadWaitingQueue.back() + 1) % mFrameCount;
       }
       else
       {
-        mFrameIndex = (mQueue.Back().mFrameNumber + 1) % mFrameCount;
+        batchFrameIndex = (mQueue.Back().mFrameNumber + 1) % mFrameCount;
       }
     }
     else
     {
-      mOnLoading = false;
       // If the request is for the first frame or a jumped frame(JUMP_TO) remove current waiting queue.
       mLoadWaitingQueue.clear();
       // If the queue is empty, and the frame of frameIndex is not loaded synchronously. load batch from the frame of frameIndex
       if(!textureSet)
       {
-        mFrameIndex = frameIndex;
+        batchFrameIndex = frameIndex;
       }
     }
-    LoadBatch();
+    LoadBatch(batchFrameIndex);
   }
 
-  if(!textureSet)
+  if(!textureSet && mLoadState != TextureManager::LoadState::LOAD_FAILED && IsFrontReady() == true)
   {
-    if(IsFrontReady() == true)
-    {
-      textureSet = GetFrontTextureSet();
-    }
-    else
-    {
-      mWaitingForReadyFrame = true;
-    }
+    textureSet = GetFrontTextureSet();
   }
 
   return textureSet;
@@ -149,32 +145,17 @@ TextureSet RollingAnimatedImageCache::Frame(uint32_t frameIndex)
 
 TextureSet RollingAnimatedImageCache::FirstFrame()
 {
-  return Frame(0u);
-}
-
-TextureSet RollingAnimatedImageCache::NextFrame()
-{
-  TextureSet textureSet;
-  if(!mQueue.IsEmpty())
-  {
-    uint32_t frameIndex = mQueue.Front().mFrameNumber;
-    if(IsFrontReady())
-    {
-      frameIndex = (frameIndex + 1) % mFrameCount;
-    }
-    textureSet = Frame(frameIndex);
-  }
-  else
-  {
-    DALI_LOG_ERROR("Cache is empty.");
-  }
-
+  TextureSet textureSet = Frame(FIRST_FRAME_INDEX);
   return textureSet;
 }
 
 uint32_t RollingAnimatedImageCache::GetFrameInterval(uint32_t frameIndex) const
 {
-  return mAnimatedImageLoading.GetFrameInterval(frameIndex);
+  if(frameIndex >= mIntervals.size())
+  {
+    return 0u;
+  }
+  return mIntervals[frameIndex];
 }
 
 int32_t RollingAnimatedImageCache::GetCurrentFrameIndex() const
@@ -196,7 +177,7 @@ bool RollingAnimatedImageCache::IsFrontReady() const
   return (!mQueue.IsEmpty() && mQueue.Front().mReady);
 }
 
-void RollingAnimatedImageCache::RequestFrameLoading(uint32_t frameIndex)
+TextureSet RollingAnimatedImageCache::RequestFrameLoading(uint32_t frameIndex, bool useCache, bool synchronousLoading)
 {
   ImageFrame imageFrame;
   imageFrame.mFrameNumber = frameIndex;
@@ -204,39 +185,45 @@ void RollingAnimatedImageCache::RequestFrameLoading(uint32_t frameIndex)
 
   mQueue.PushBack(imageFrame);
 
-  mRequestingLoad = true;
+  mLoadState = TextureManager::LoadState::LOADING;
+
+  TextureManager::TextureId loadTextureId = TextureManager::INVALID_TEXTURE_ID;
+  TextureSet                textureSet    = mTextureManager.LoadAnimatedImageTexture(mAnimatedImageLoading,
+                                                                   frameIndex,
+                                                                   loadTextureId,
+                                                                   SamplingMode::BOX_THEN_LINEAR,
+                                                                   Dali::WrapMode::Type::DEFAULT,
+                                                                   Dali::WrapMode::Type::DEFAULT,
+                                                                   synchronousLoading,
+                                                                   useCache,
+                                                                   this);
 
-  bool synchronousLoading = false;
-  mTextureManager.LoadAnimatedImageTexture(mAnimatedImageLoading, frameIndex, SamplingMode::BOX_THEN_LINEAR, synchronousLoading, mImageUrls[frameIndex].mTextureId, Dali::WrapMode::Type::DEFAULT, Dali::WrapMode::Type::DEFAULT, this);
+  mImageUrls[frameIndex].mTextureId = loadTextureId;
 
-  mRequestingLoad = false;
+  return textureSet;
 }
 
-void RollingAnimatedImageCache::LoadBatch()
+void RollingAnimatedImageCache::LoadBatch(uint32_t frameIndex)
 {
   // Try and load up to mBatchSize images, until the cache is filled.
   // Once the cache is filled, as frames progress, the old frame is
   // removed, and another frame is loaded
-
-  bool frontFrameReady = IsFrontReady();
-  for(unsigned int i = 0; i < mBatchSize && mQueue.Count() + mLoadWaitingQueue.size() < static_cast<uint32_t>(mCacheSize) && !mQueue.IsFull(); ++i)
+  uint32_t minimumSize = std::min(mCacheSize, mFrameCount);
+  for(uint32_t i = 0; i < mBatchSize && (mQueue.Count() + mLoadWaitingQueue.size()) < minimumSize; ++i)
   {
-    if(!mOnLoading)
+    if(mLoadState != TextureManager::LoadState::LOADING)
     {
-      mOnLoading = true;
-      RequestFrameLoading(mFrameIndex);
+      RequestFrameLoading(frameIndex, frameIndex == FIRST_FRAME_INDEX, false);
     }
     else
     {
-      mLoadWaitingQueue.push_back(mFrameIndex);
+      mLoadWaitingQueue.push_back(frameIndex);
     }
 
-    mFrameIndex++;
-    mFrameIndex %= mFrameCount;
+    frameIndex++;
+    frameIndex %= mFrameCount;
   }
 
-  CheckFrontFrame(frontFrameReady);
-
   LOG_CACHE;
 }
 
@@ -265,46 +252,84 @@ TextureManager::TextureId RollingAnimatedImageCache::GetCachedTextureId(int inde
   return mImageUrls[mQueue[index].mFrameNumber].mTextureId;
 }
 
-void RollingAnimatedImageCache::CheckFrontFrame(bool wasReady)
+void RollingAnimatedImageCache::ClearCache()
 {
-  if(mWaitingForReadyFrame && wasReady == false && IsFrontReady())
+  while(mTextureManagerAlive && !mQueue.IsEmpty())
   {
-    mWaitingForReadyFrame = false;
-    mObserver.FrameReady(GetFrontTextureSet());
+    ImageFrame imageFrame = mQueue.PopFront();
+    mTextureManager.Remove(mImageUrls[imageFrame.mFrameNumber].mTextureId, this);
+    mImageUrls[imageFrame.mFrameNumber].mTextureId = TextureManager::INVALID_TEXTURE_ID;
   }
+  mLoadWaitingQueue.clear();
+  mLoadState = TextureManager::LoadState::NOT_STARTED;
 }
 
-void RollingAnimatedImageCache::LoadComplete(bool loadSuccess, TextureInformation textureInformation)
+void RollingAnimatedImageCache::MakeFrameReady(bool loadSuccess, TextureSet textureSet, uint32_t interval)
 {
-  DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "AnimatedImageVisual::LoadComplete(textureId:%d) start\n", textureInformation.textureId);
-  LOG_CACHE;
-
-  bool frontFrameReady = IsFrontReady();
-
-  if(!mRequestingLoad)
+  if(!loadSuccess)
   {
-    SetImageFrameReady(textureInformation.textureId);
-
-    CheckFrontFrame(frontFrameReady);
+    mLoadState = TextureManager::LoadState::LOAD_FAILED;
+    mObserver.FrameReady(TextureSet(), 0);
   }
   else
   {
-    // LoadComplete has been called from within RequestLoad. TextureManager must
-    // therefore already have the texture cached, so make the texture ready.
-    // (Use the last texture, as the texture id hasn't been assigned yet)
-    mQueue.Back().mReady = true;
+    mLoadState = TextureManager::LoadState::LOAD_FINISHED;
+
+    // Reset size of Queue according to the real frame count.
+    if(mFrameCount != mAnimatedImageLoading.GetImageCount())
+    {
+      mFrameCount = mAnimatedImageLoading.GetImageCount();
+      mImageUrls.resize(mFrameCount);
+      mIntervals.assign(mFrameCount, 0u);
+    }
+
+    bool frontFrameReady = IsFrontReady();
+    // Because only one frame is on loading and the others are in mLoadWaitingQueue,
+    // mQueue.Back() is always the frame currently loaded.
+    mQueue.Back().mReady                   = true;
+    mIntervals[mQueue.Back().mFrameNumber] = interval;
+    // Check whether currently loaded frame is front of queue or not.
+    // If it is, notify frame ready to observer.
+    if(frontFrameReady == false && IsFrontReady())
+    {
+      mObserver.FrameReady(textureSet, interval);
+    }
   }
+}
 
-  mOnLoading = false;
-  // The frames of a single animated image can not be loaded parallelly.
-  // Therefore, a frame is now loading, other orders are waiting.
-  // And, after the frame is loaded, requests load of next order.
-  if(!mLoadWaitingQueue.empty())
+void RollingAnimatedImageCache::LoadComplete(bool loadSuccess, TextureInformation textureInformation)
+{
+  DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "AnimatedImageVisual::LoadComplete(textureId:%d) start\n", textureInformation.textureId);
+  LOG_CACHE;
+
+  MakeFrameReady(loadSuccess, mTextureManager.GetTextureSet(textureInformation.textureId), textureInformation.interval);
+
+  if(loadSuccess)
   {
-    uint32_t loadingIndex = mLoadWaitingQueue.front();
-    mLoadWaitingQueue.erase(mLoadWaitingQueue.begin());
-    mOnLoading = true;
-    RequestFrameLoading(loadingIndex);
+    // The frames of a single animated image can not be loaded parallelly.
+    // Therefore, a frame is now loading, other orders are waiting.
+    // And, after the frame is loaded, requests load of next order.
+    if(!mLoadWaitingQueue.empty())
+    {
+      uint32_t loadingIndex = mLoadWaitingQueue.front();
+      mLoadWaitingQueue.erase(mLoadWaitingQueue.begin());
+      RequestFrameLoading(loadingIndex, loadingIndex == FIRST_FRAME_INDEX, false);
+    }
+    else if(mQueue.Count() == 1u && textureInformation.frameCount > SINGLE_IMAGE_COUNT)
+    {
+      // There is only an image in queue and no waiting queue.
+      // Request to load batch once again.
+      uint32_t batchFrameIndex = 0u;
+      if(!mLoadWaitingQueue.empty())
+      {
+        batchFrameIndex = (mLoadWaitingQueue.back() + 1) % mFrameCount;
+      }
+      else
+      {
+        batchFrameIndex = (mQueue.Back().mFrameNumber + 1) % mFrameCount;
+      }
+      LoadBatch(batchFrameIndex);
+    }
   }
 
   LOG_CACHE;
index 08aec52..605fbb9 100644 (file)
@@ -40,10 +40,9 @@ class RollingAnimatedImageCache : public ImageCache, public TextureUploadObserve
 {
 public:
   /**
-   * Constructor.
+   * @brief Constructor.
    * @param[in] textureManager The texture manager
    * @param[in] animatedImageLoader The loaded animated image
-   * @param[in] frameCount The number of frames in the animated image
    * @param[in] observer FrameReady observer
    * @param[in] cacheSize The size of the cache
    * @param[in] batchSize The size of a batch to load
@@ -54,112 +53,128 @@ public:
    */
   RollingAnimatedImageCache(TextureManager&                 textureManager,
                             AnimatedImageLoading&           animatedImageLoader,
-                            uint32_t                        frameCount,
                             ImageCache::FrameReadyObserver& observer,
                             uint16_t                        cacheSize,
                             uint16_t                        batchSize,
                             bool                            isSynchronousLoading);
 
   /**
-   * Destructor
+   * @brief Destructor
    */
   ~RollingAnimatedImageCache() override;
 
   /**
-   * Get the Nth frame. If it's not ready, this will trigger the
-   * sending of FrameReady() when the image becomes ready.
+   * @copydoc Internal::ImageCache::Frame()
    */
   TextureSet Frame(uint32_t frameIndex) override;
 
   /**
-   * Get the first frame. If it's not ready, this will trigger the
-   * sending of FrameReady() when the image becomes ready.
+   * @copydoc Internal::ImageCache::FirstFrame()
    */
   TextureSet FirstFrame() override;
 
   /**
-   * Get the next frame. If it's not ready, this will trigger the
-   * sending of FrameReady() when the image becomes ready.
-   */
-  TextureSet NextFrame() override;
-
-  /**
-   * Get the interval of Nth frame.
+   * @copydoc Internal::ImageCache::GetFrameInterval()
    */
   uint32_t GetFrameInterval(uint32_t frameIndex) const override;
 
   /**
-   * Get the current rendered frame index.
-   * If there isn't any loaded frame, returns -1.
+   * @copydoc Internal::ImageCache::GetCurrentFrameIndex()
    */
   int32_t GetCurrentFrameIndex() const override;
 
   /**
-   * Get total frame count of the animated image file.
+   * @copydoc Internal::ImageCache::GetTotalFrameCount()
    */
   int32_t GetTotalFrameCount() const override;
 
+  /**
+   * @copydoc Internal::ImageCache::ClearCache()
+   */
+  void ClearCache() override;
+
 private:
   /**
+   * @brief Check whether the front frame is ready or not.
+   *
    * @return true if the front frame is ready
    */
   bool IsFrontReady() const;
 
   /**
-   * Request to Load a frame
+   * @brief Request to Load a frame
+   *
+   * @param[in] frameIndex          index of frame to be loaded.
+   * @param[in] useCache            true if this frame loading uses cache.
+   * @param[in] synchronousLoading  true if the frame should be loaded synchronously
+   *
+   * @return the texture set currently loaded.
    */
-  void RequestFrameLoading(uint32_t frameIndex);
+  TextureSet RequestFrameLoading(uint32_t frameIndex, bool useCache, bool synchronousLoading);
 
   /**
-   * Load the next batch of images
+   * @brief Load the next batch of images
+   *
+   * @param[in] frameIndex starting frame index of batch to be loaded.
    */
-  void LoadBatch();
+  void LoadBatch(uint32_t frameIndex);
 
   /**
-   * Find the matching image frame, and set it to ready
+   * @brief Find the matching image frame, and set it to ready
+   *
+   * @param[in] textureId texture id to be marked as ready.
    */
   void SetImageFrameReady(TextureManager::TextureId textureId);
 
   /**
-   * Get the texture set of the front frame.
-   * @return the texture set
+   * @brief Get the texture set of the front frame.
+   *
+   * @return the texture set of the front of Cache.
    */
   TextureSet GetFrontTextureSet() const;
 
   /**
-   * Get the texture id of the given index
+   * @brief Get the texture id of the given index
+   *
+   * @param[in] index index of the queue.
    */
   TextureManager::TextureId GetCachedTextureId(int index) const;
 
   /**
-   * Check if the front frame has become ready - if so, inform observer
-   * @param[in] wasReady Readiness before call.
+   * @brief Make the loaded frame ready and notify it to the texture upload observer
+   *
+   * @param[in] loadSuccess whether the loading is succeded or not.
+   * @param[in] textureSet textureSet for this frame.
+   * @param[in] interval interval between this frame and next frame.
    */
-  void CheckFrontFrame(bool wasReady);
+  void MakeFrameReady(bool loadSuccess, TextureSet textureSet, uint32_t interval);
 
 protected:
+  /**
+   * @copydoc Toolkit::TextureUploadObserver::LoadComplete()
+   */
   void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override;
 
 private:
+
   /**
    * Secondary class to hold readiness and index into url
    */
   struct ImageFrame
   {
-    unsigned int mFrameNumber = 0u;
-    bool         mReady       = false;
+    uint32_t mFrameNumber = 0u;
+    bool     mReady       = false;
   };
 
   Dali::AnimatedImageLoading mAnimatedImageLoading;
   uint32_t                   mFrameCount;
-  int                        mFrameIndex;
-  int                        mCacheSize;
+  uint32_t                   mFrameIndex;
+  uint32_t                   mCacheSize;
   std::vector<UrlStore>      mImageUrls;
   std::vector<int32_t>       mIntervals;
   std::vector<uint32_t>      mLoadWaitingQueue;
   CircularQueue<ImageFrame>  mQueue;
   bool                       mIsSynchronousLoading;
-  bool                       mOnLoading;
 };
 
 } // namespace Internal
index caecf39..08fe0d0 100644 (file)
@@ -44,7 +44,9 @@ Debug::Filter* gAnimImgLogFilter = Debug::Filter::New(Debug::NoLogging, false, "
 #define LOG_CACHE
 #endif
 
-const bool ENABLE_ORIENTATION_CORRECTION(true);
+static constexpr bool ENABLE_ORIENTATION_CORRECTION(true);
+
+static constexpr uint32_t FIRST_FRAME_INDEX = 0u;
 
 } // namespace
 
@@ -55,100 +57,60 @@ namespace Toolkit
 namespace Internal
 {
 RollingImageCache::RollingImageCache(
-  TextureManager& textureManager, UrlList& urlList, ImageCache::FrameReadyObserver& observer, uint16_t cacheSize, uint16_t batchSize)
-: ImageCache(textureManager, observer, batchSize),
+  TextureManager& textureManager, UrlList& urlList, ImageCache::FrameReadyObserver& observer, uint16_t cacheSize, uint16_t batchSize, uint32_t interval)
+: ImageCache(textureManager, observer, batchSize, interval),
   mImageUrls(urlList),
   mQueue(cacheSize)
 {
-  LoadBatch();
 }
 
 RollingImageCache::~RollingImageCache()
 {
-  if(mTextureManagerAlive)
-  {
-    while(!mQueue.IsEmpty())
-    {
-      ImageFrame imageFrame = mQueue.PopFront();
-      mTextureManager.Remove(mImageUrls[imageFrame.mUrlIndex].mTextureId, this);
-    }
-  }
+  ClearCache();
 }
 
 TextureSet RollingImageCache::Frame(uint32_t frameIndex)
 {
-  // If a frame of frameIndex is not loaded, clear the queue and remove all loaded textures.
-  if(mImageUrls[frameIndex].mTextureId == TextureManager::INVALID_TEXTURE_ID)
+  // Pop frames until the frame of frameIndex become front frame.
+  bool popExist = false;
+  while(!mQueue.IsEmpty() && mQueue.Front().mUrlIndex != frameIndex)
   {
-    mUrlIndex = frameIndex;
-    while(!mQueue.IsEmpty())
-    {
-      ImageFrame imageFrame = mQueue.PopFront();
-      mTextureManager.Remove(mImageUrls[imageFrame.mUrlIndex].mTextureId, this);
-      mImageUrls[imageFrame.mUrlIndex].mTextureId = TextureManager::INVALID_TEXTURE_ID;
-    }
-    LoadBatch();
+    ImageFrame imageFrame = mQueue.PopFront();
+    mTextureManager.Remove(mImageUrls[imageFrame.mUrlIndex].mTextureId, this);
+    mImageUrls[imageFrame.mUrlIndex].mTextureId = TextureManager::INVALID_TEXTURE_ID;
+    popExist                                    = true;
   }
-  // If the frame is already loaded, remove previous frames of the frame in the queue
-  // and load new frames amount of removed frames.
-  else
+
+  // TODO: synchronous loading of first frame.
+  if(popExist || mQueue.IsEmpty())
   {
-    bool popExist = false;
-    while(!mQueue.IsEmpty() && mQueue.Front().mUrlIndex != frameIndex)
-    {
-      ImageFrame imageFrame = mQueue.PopFront();
-      mTextureManager.Remove(mImageUrls[imageFrame.mUrlIndex].mTextureId, this);
-      mImageUrls[imageFrame.mUrlIndex].mTextureId = TextureManager::INVALID_TEXTURE_ID;
-      popExist                                    = true;
-    }
-    if(popExist)
+    uint32_t batchFrameIndex = frameIndex;
+    // If the frame of frameIndex was already loaded, load batch from the last frame of queue
+    if(!mQueue.IsEmpty())
     {
-      mUrlIndex = (mQueue.Back().mUrlIndex + 1) % mImageUrls.size();
-      LoadBatch();
+      batchFrameIndex = (mQueue.Back().mUrlIndex + 1) % mImageUrls.size();
     }
+    LoadBatch(batchFrameIndex);
   }
 
   TextureSet textureSet;
-  if(IsFrontReady() == true)
+  if(IsFrontReady() == true && mLoadState != TextureManager::LoadState::LOAD_FAILED)
   {
     textureSet = GetFrontTextureSet();
   }
-  else
-  {
-    mWaitingForReadyFrame = true;
-  }
 
   return textureSet;
 }
 
 TextureSet RollingImageCache::FirstFrame()
 {
-  return Frame(0u);
-}
-
-TextureSet RollingImageCache::NextFrame()
-{
-  TextureSet textureSet;
-  if(!mQueue.IsEmpty())
-  {
-    uint32_t frameIndex = mQueue.Front().mUrlIndex;
-    if(IsFrontReady())
-    {
-      frameIndex = (frameIndex + 1) % mImageUrls.size();
-    }
-    textureSet = Frame(frameIndex);
-  }
-  else
-  {
-    DALI_LOG_ERROR("Cache is empty.");
-  }
-
+  TextureSet textureSet = Frame(FIRST_FRAME_INDEX);
   return textureSet;
 }
 
 uint32_t RollingImageCache::GetFrameInterval(uint32_t frameIndex) const
 {
-  return 0u;
+  return mInterval;
 }
 
 int32_t RollingImageCache::GetCurrentFrameIndex() const
@@ -170,30 +132,26 @@ bool RollingImageCache::IsFrontReady() const
   return (!mQueue.IsEmpty() && mQueue.Front().mReady);
 }
 
-void RollingImageCache::LoadBatch()
+void RollingImageCache::LoadBatch(uint32_t frameIndex)
 {
   // Try and load up to mBatchSize images, until the cache is filled.
   // Once the cache is filled, as frames progress, the old frame is
   // cleared, but not erased, and another image is loaded
-  bool frontFrameReady = IsFrontReady();
-
   for(unsigned int i = 0; i < mBatchSize && !mQueue.IsFull(); ++i)
   {
     ImageFrame imageFrame;
 
-    std::string& url     = mImageUrls[mUrlIndex].mUrl;
-    imageFrame.mUrlIndex = mUrlIndex;
+    std::string& url     = mImageUrls[frameIndex].mUrl;
+    imageFrame.mUrlIndex = frameIndex;
     imageFrame.mReady    = false;
 
-    ++mUrlIndex;
-    mUrlIndex %= mImageUrls.size();
-
     mQueue.PushBack(imageFrame);
 
     // Note, if the image is already loaded, then LoadComplete will get called
     // from within this method. This means it won't yet have a texture id, so we
     // need to account for this inside the LoadComplete method using mRequestingLoad.
     mRequestingLoad = true;
+    mLoadState = TextureManager::LoadState::LOADING;
 
     bool                               synchronousLoading = false;
     bool                               atlasingStatus     = false;
@@ -205,24 +163,15 @@ void RollingImageCache::LoadBatch()
     Dali::ImageDimensions              textureRectSize;
     auto                               preMultiply = TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
 
-    mTextureManager.LoadTexture(
-      url, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, maskInfo, synchronousLoading, mImageUrls[imageFrame.mUrlIndex].mTextureId, textureRect, textureRectSize, atlasingStatus, loadingStatus, Dali::WrapMode::Type::DEFAULT, Dali::WrapMode::Type::DEFAULT, this, atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiply);
+    TextureManager::TextureId loadTextureId = TextureManager::INVALID_TEXTURE_ID;
+    TextureSet                textureSet    = mTextureManager.LoadTexture(
+      url, ImageDimensions(), FittingMode::SCALE_TO_FILL, SamplingMode::BOX_THEN_LINEAR, maskInfo, synchronousLoading, loadTextureId, textureRect, textureRectSize, atlasingStatus, loadingStatus, Dali::WrapMode::Type::DEFAULT, Dali::WrapMode::Type::DEFAULT, this, atlasObserver, imageAtlasManager, ENABLE_ORIENTATION_CORRECTION, TextureManager::ReloadPolicy::CACHED, preMultiply);
+    mImageUrls[imageFrame.mUrlIndex].mTextureId = loadTextureId;
 
     mRequestingLoad = false;
-  }
 
-  CheckFrontFrame(frontFrameReady);
-}
-
-void RollingImageCache::SetImageFrameReady(TextureManager::TextureId textureId)
-{
-  for(std::size_t i = 0; i < mQueue.Count(); ++i)
-  {
-    if(GetCachedTextureId(i) == textureId)
-    {
-      mQueue[i].mReady = true;
-      break;
-    }
+    ++frameIndex;
+    frameIndex %= mImageUrls.size();
   }
 }
 
@@ -237,13 +186,15 @@ TextureManager::TextureId RollingImageCache::GetCachedTextureId(int index) const
   return mImageUrls[mQueue[index].mUrlIndex].mTextureId;
 }
 
-void RollingImageCache::CheckFrontFrame(bool wasReady)
+void RollingImageCache::ClearCache()
 {
-  if(mWaitingForReadyFrame && wasReady == false && IsFrontReady())
+  while(mTextureManagerAlive && !mQueue.IsEmpty())
   {
-    mWaitingForReadyFrame = false;
-    mObserver.FrameReady(GetFrontTextureSet());
+    ImageFrame imageFrame = mQueue.PopFront();
+    mTextureManager.Remove(mImageUrls[imageFrame.mUrlIndex].mTextureId, this);
+    mImageUrls[imageFrame.mUrlIndex].mTextureId = TextureManager::INVALID_TEXTURE_ID;
   }
+  mLoadState = TextureManager::LoadState::NOT_STARTED;
 }
 
 void RollingImageCache::LoadComplete(bool loadSuccess, TextureInformation textureInformation)
@@ -251,20 +202,38 @@ void RollingImageCache::LoadComplete(bool loadSuccess, TextureInformation textur
   DALI_LOG_INFO(gAnimImgLogFilter, Debug::Concise, "AnimatedImageVisual::LoadComplete(textureId:%d) start\n", textureInformation.textureId);
   LOG_CACHE;
 
-  bool frontFrameReady = IsFrontReady();
-
-  if(!mRequestingLoad)
+  if(loadSuccess)
   {
-    SetImageFrameReady(textureInformation.textureId);
+    mLoadState = TextureManager::LoadState::LOAD_FINISHED;
+    bool frontFrameReady = IsFrontReady();
+    if(!mRequestingLoad)
+    {
+      for(std::size_t i = 0; i < mQueue.Count(); ++i)
+      {
+        if(GetCachedTextureId(i) == textureInformation.textureId)
+        {
+          mQueue[i].mReady = true;
+          break;
+        }
+      }
+    }
+    else
+    {
+      // LoadComplete has been called from within RequestLoad. TextureManager must
+      // therefore already have the texture cached, so make the texture ready.
+      // (Use the last texture, as the texture id hasn't been assigned yet)
+      mQueue.Back().mReady = true;
+    }
 
-    CheckFrontFrame(frontFrameReady);
+    if(!frontFrameReady && IsFrontReady())
+    {
+      mObserver.FrameReady(mTextureManager.GetTextureSet(textureInformation.textureId), mInterval);
+    }
   }
   else
   {
-    // LoadComplete has been called from within RequestLoad. TextureManager must
-    // therefore already have the texture cached, so make the texture ready.
-    // (Use the last texture, as the texture id hasn't been assigned yet)
-    mQueue.Back().mReady = true;
+    mLoadState = TextureManager::LoadState::LOAD_FAILED;
+    mObserver.FrameReady(TextureSet(), 0);
   }
 
   LOG_CACHE;
index 7647e31..98ba45c 100644 (file)
@@ -42,6 +42,7 @@ public:
    * @param[in] observer FrameReady observer
    * @param[in] cacheSize The size of the cache
    * @param[in] batchSize The size of a batch to load
+   * @param[in] interval Time interval between each frame
    *
    * This will start loading textures immediately, according to the
    * batch and cache sizes.
@@ -50,7 +51,8 @@ public:
                     UrlList&                        urlList,
                     ImageCache::FrameReadyObserver& observer,
                     uint16_t                        cacheSize,
-                    uint16_t                        batchSize);
+                    uint16_t                        batchSize,
+                    uint32_t                        interval);
 
   /**
    * Destructor
@@ -58,73 +60,75 @@ public:
   ~RollingImageCache() override;
 
   /**
-   * Get the Nth frame. If it's not ready, this will trigger the
-   * sending of FrameReady() when the image becomes ready.
+   * @copydoc Internal::ImageCache::Frame()
    */
   TextureSet Frame(uint32_t frameIndex) override;
 
   /**
-   * Get the first frame. If it's not ready, this will trigger the
-   * sending of FrameReady() when the image becomes ready.
+   * @copydoc Internal::ImageCache::FirstFrame()
    */
   TextureSet FirstFrame() override;
 
   /**
-   * Get the next frame. If it's not ready, this will trigger the
-   * sending of FrameReady() when the image becomes ready.
-   */
-  TextureSet NextFrame() override;
-
-  /**
-   * Get the interval of Nth frame.
+   * @copydoc Internal::ImageCache::GetFrameInterval()
    */
   uint32_t GetFrameInterval(uint32_t frameIndex) const override;
 
   /**
-   * Get the current rendered frame index.
-   * If there isn't any loaded frame, returns -1.
+   * @copydoc Internal::ImageCache::GetCurrentFrameIndex()
    */
   int32_t GetCurrentFrameIndex() const override;
 
   /**
-   * Get total frame count of the animated image file.
+   * @copydoc Internal::ImageCache::GetTotalFrameCount()
    */
   int32_t GetTotalFrameCount() const override;
 
-private:
   /**
-   * @return true if the front frame is ready
+   * @copydoc Internal::ImageCache::ClearCache()
    */
-  bool IsFrontReady() const;
+  void ClearCache() override;
 
+private:
   /**
-   * Load the next batch of images
+   * @brief Check whether the front frame is ready or not.
+   *
+   * @return true if the front frame is ready
    */
-  void LoadBatch();
+  bool IsFrontReady() const;
 
   /**
-   * Find the matching image frame, and set it to ready
+   * @brief Load the next batch of images
+   *
+   * @param[in] frameIndex starting frame index of batch to be loaded.
    */
-  void SetImageFrameReady(TextureManager::TextureId textureId);
+  void LoadBatch(uint32_t frameIndex);
 
   /**
-   * Get the texture set of the front frame.
-   * @return the texture set
+   * @brief Get the texture set of the front frame.
+   *
+   * @return the texture set of the front of Cache.
    */
   TextureSet GetFrontTextureSet() const;
 
   /**
-   * Get the texture id of the given index
+   * @brief Get the texture id of the given index
+   *
+   * @param[in] index index of the queue.
    */
   TextureManager::TextureId GetCachedTextureId(int index) const;
 
   /**
-   * Check if the front frame has become ready - if so, inform observer
+   * @brief Check if the front frame has become ready - if so, inform observer
+   *
    * @param[in] wasReady Readiness before call.
    */
   void CheckFrontFrame(bool wasReady);
 
 protected:
+  /**
+   * @copydoc Toolkit::TextureUploadObserver::LoadComplete()
+   */
   void LoadComplete(bool loadSuccess, TextureInformation textureInformation) override;
 
 private:
@@ -137,8 +141,8 @@ private:
     bool         mReady    = false;
   };
 
-  std::vector<UrlStore>&    mImageUrls;
-  CircularQueue<ImageFrame> mQueue;
+  std::vector<UrlStore>&                 mImageUrls;
+  CircularQueue<ImageFrame>              mQueue;
 };
 
 } // namespace Internal
index e8a6042..cbc038a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
@@ -38,7 +38,7 @@ NPatchData::NPatchData()
   mCroppedWidth(0),
   mCroppedHeight(0),
   mBorder(0, 0, 0, 0),
-  mLoadingState(LoadingState::LOADING),
+  mLoadingState(LoadingState::NOT_STARTED),
   mPreMultiplyOnLoad(false),
   mRenderingMap{nullptr}
 {
@@ -224,22 +224,49 @@ void NPatchData::SetLoadedNPatchData(Devel::PixelBuffer& pixelBuffer, bool preMu
   mLoadingState = LoadingState::LOAD_COMPLETE;
 }
 
+void NPatchData::NotifyObserver(TextureUploadObserver* observer, const bool& loadSuccess)
+{
+  observer->LoadComplete(
+    loadSuccess,
+    TextureUploadObserver::TextureInformation(
+      TextureUploadObserver::ReturnType::TEXTURE,
+      static_cast<TextureManager::TextureId>(mId), ///< Note : until end of NPatchLoader::Load, npatch-visual don't know the id of data.
+      mTextureSet,
+      false,     // UseAtlas
+      Vector4(), // AtlasRect
+      mPreMultiplyOnLoad));
+}
+
 void NPatchData::LoadComplete(bool loadSuccess, TextureInformation textureInformation)
 {
   if(loadSuccess)
   {
-    SetLoadedNPatchData(textureInformation.pixelBuffer, textureInformation.preMultiplied);
+    if(mLoadingState != LoadingState::LOAD_COMPLETE)
+    {
+      // If mLoadingState is LOAD_FAILED, just re-set (It can be happened when sync loading is failed, but async loading is succeeded).
+      SetLoadedNPatchData(textureInformation.pixelBuffer, textureInformation.preMultiplied);
+    }
   }
   else
   {
-    mLoadingState = LoadingState::LOAD_FAILED;
+    if(mLoadingState == LoadingState::LOADING)
+    {
+      mLoadingState = LoadingState::LOAD_FAILED;
+    }
+    // If mLoadingState is already LOAD_COMPLETE, we can use uploaded texture (It can be happened when sync loading is succeeded, but async loading is failed).
+    else if(mLoadingState == LoadingState::LOAD_COMPLETE)
+    {
+      loadSuccess = true;
+    }
   }
 
   for(uint32_t index = 0; index < mObserverList.Count(); ++index)
   {
     TextureUploadObserver* observer = mObserverList[index];
-    observer->LoadComplete(loadSuccess, TextureUploadObserver::TextureInformation(TextureUploadObserver::ReturnType::TEXTURE, TextureManager::INVALID_TEXTURE_ID, mTextureSet, false, Vector4(), textureInformation.preMultiplied));
+    NotifyObserver(observer, loadSuccess);
   }
+
+  mObserverList.Clear();
 }
 
 } // namespace Internal
index f67e599..cc520d8 100644 (file)
@@ -44,9 +44,10 @@ public:
    */
   enum class LoadingState
   {
-    LOADING = 0,   ///< NPatch is on loading.
-    LOAD_COMPLETE, ///< NPatch loading is completed successfully.
-    LOAD_FAILED    ///< NPatch loading is failed.
+    NOT_STARTED = 0, ///< NPatch loading is not started yet.
+    LOADING,         ///< NPatch is on loading.
+    LOAD_COMPLETE,   ///< NPatch loading is completed successfully.
+    LOAD_FAILED      ///< NPatch loading is failed.
   };
 
 public:
@@ -251,6 +252,14 @@ public:
    */
   void SetLoadedNPatchData(Devel::PixelBuffer& pixelBuffer, bool preMultiplied);
 
+  /**
+   * @brief Send LoadComplete notify with current setuped NPatchData
+   *
+   * @param [in] observer observer who will be got LoadComplete notify
+   * @param [in] loadSuccess whether the image load success or not.
+   */
+  void NotifyObserver(TextureUploadObserver* observer, const bool& loadSuccess);
+
 private:
   /**
    * @copydoc TextureUploadObserver::LoadComplete
index cb2850d..4c6471e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 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.
@@ -54,94 +54,59 @@ NPatchData::NPatchDataId NPatchLoader::GenerateUniqueNPatchDataId()
 
 std::size_t NPatchLoader::Load(TextureManager& textureManager, TextureUploadObserver* textureObserver, const VisualUrl& url, const Rect<int>& border, bool& preMultiplyOnLoad, bool synchronousLoading)
 {
-  std::size_t                                 hash  = CalculateHash(url.GetUrl());
-  OwnerContainer<NPatchData*>::SizeType       index = UNINITIALIZED_ID;
-  const OwnerContainer<NPatchData*>::SizeType count = mCache.Count();
+  NPatchData* data = GetNPatchData(url, border, preMultiplyOnLoad);
 
-  for(; index < count; ++index)
+  DALI_ASSERT_ALWAYS(data && "NPatchData creation failed!");
+
+  if(data->GetLoadingState() == NPatchData::LoadingState::LOAD_COMPLETE)
   {
-    if(mCache[index]->GetHash() == hash)
+    if(!synchronousLoading)
     {
-      // hash match, check url as well in case of hash collision
-      if(mCache[index]->GetUrl().GetUrl() == url.GetUrl())
+      // NotifyObserver already done, so
+      // data will not iterate observer list.
+      // We need to call LoadComplete directly.
+      data->NotifyObserver(textureObserver, true);
+    }
+  }
+  else // if NOT_STARTED or LOADING or LOAD_FAILED, try to reload.
+  {
+    if(!synchronousLoading)
+    {
+      data->AddObserver(textureObserver);
+      // If still LOADING and async, don't need to request reload. Fast return.
+      if(data->GetLoadingState() == NPatchData::LoadingState::LOADING)
       {
-        // Use cached data
-        if(mCache[index]->GetBorder() == border)
-        {
-          if(mCache[index]->GetLoadingState() == NPatchData::LoadingState::LOADING)
-          {
-            mCache[index]->AddObserver(textureObserver);
-          }
-          return mCache[index]->GetId(); // valid indices are from 1 onwards
-        }
-        else
-        {
-          if(mCache[index]->GetLoadingState() == NPatchData::LoadingState::LOAD_COMPLETE)
-          {
-            // Same url but border is different - use the existing texture
-            NPatchData* newData = new NPatchData();
-            newData->SetId(GenerateUniqueNPatchDataId());
-            newData->SetHash(hash);
-            newData->SetUrl(url);
-            newData->SetCroppedWidth(mCache[index]->GetCroppedWidth());
-            newData->SetCroppedHeight(mCache[index]->GetCroppedHeight());
-
-            newData->SetTextures(mCache[index]->GetTextures());
-
-            NPatchUtility::StretchRanges stretchRangesX;
-            stretchRangesX.PushBack(Uint16Pair(border.left, ((newData->GetCroppedWidth() >= static_cast<unsigned int>(border.right)) ? newData->GetCroppedHeight() - border.right : 0)));
-
-            NPatchUtility::StretchRanges stretchRangesY;
-            stretchRangesY.PushBack(Uint16Pair(border.top, ((newData->GetCroppedWidth() >= static_cast<unsigned int>(border.bottom)) ? newData->GetCroppedHeight() - border.bottom : 0)));
+        return data->GetId();
+      }
+    }
 
-            newData->SetStretchPixelsX(stretchRangesX);
-            newData->SetStretchPixelsY(stretchRangesY);
-            newData->SetBorder(border);
+    data->SetLoadingState(NPatchData::LoadingState::LOADING);
 
-            newData->SetPreMultiplyOnLoad(mCache[index]->IsPreMultiplied());
+    auto preMultiplyOnLoading = preMultiplyOnLoad ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD
+                                                  : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
 
-            newData->SetLoadingState(NPatchData::LoadingState::LOAD_COMPLETE);
-            newData->AddObserver(textureObserver);
+    Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(url, Dali::ImageDimensions(), FittingMode::DEFAULT, SamplingMode::BOX_THEN_LINEAR, synchronousLoading, data, true, preMultiplyOnLoading);
 
-            mCache.PushBack(newData);
-            return newData->GetId(); // valid ids start from 1u
-          }
-        }
-      }
+    if(pixelBuffer)
+    {
+      preMultiplyOnLoad = (preMultiplyOnLoading == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD) ? true : false;
+      data->SetLoadedNPatchData(pixelBuffer, preMultiplyOnLoad);
+    }
+    else if(synchronousLoading)
+    {
+      data->SetLoadingState(NPatchData::LoadingState::LOAD_FAILED);
     }
-  }
-
-  // If this is new image loading, make new cache data
-  NPatchData* data;
-  data = new NPatchData();
-  data->SetId(GenerateUniqueNPatchDataId());
-  data->SetHash(hash);
-  data->SetUrl(url);
-  data->SetBorder(border);
-  data->SetPreMultiplyOnLoad(preMultiplyOnLoad);
-  data->AddObserver(textureObserver);
-  mCache.PushBack(data);
-
-  auto preMultiplyOnLoading = preMultiplyOnLoad ? TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD
-                                                : TextureManager::MultiplyOnLoad::LOAD_WITHOUT_MULTIPLY;
-
-  Devel::PixelBuffer pixelBuffer = textureManager.LoadPixelBuffer(url, Dali::ImageDimensions(), FittingMode::DEFAULT, SamplingMode::BOX_THEN_LINEAR, synchronousLoading, data, true, preMultiplyOnLoading);
-
-  if(pixelBuffer)
-  {
-    preMultiplyOnLoad = (preMultiplyOnLoading == TextureManager::MultiplyOnLoad::MULTIPLY_ON_LOAD) ? true : false;
-    data->SetLoadedNPatchData(pixelBuffer, preMultiplyOnLoad);
   }
   return data->GetId();
 }
 
 int32_t NPatchLoader::GetCacheIndexFromId(const NPatchData::NPatchDataId id)
 {
-  const unsigned int size = mCache.Count();
+  const unsigned int size = mCache.size();
 
   for(unsigned int i = 0; i < size; ++i)
   {
-    if(mCache[i]->GetId() == id)
+    if(mCache[i].mData->GetId() == id)
     {
       return i;
     }
@@ -155,7 +120,7 @@ bool NPatchLoader::GetNPatchData(const NPatchData::NPatchDataId id, const NPatch
   int32_t cacheIndex = GetCacheIndexFromId(id);
   if(cacheIndex != INVALID_CACHE_INDEX)
   {
-    data = mCache[cacheIndex];
+    data = mCache[cacheIndex].mData;
     return true;
   }
   data = nullptr;
@@ -170,17 +135,119 @@ void NPatchLoader::Remove(std::size_t id, TextureUploadObserver* textureObserver
     return;
   }
 
-  NPatchData* data;
-  data = mCache[cacheIndex];
+  NPatchInfo& info(mCache[cacheIndex]);
 
-  data->RemoveObserver(textureObserver);
+  info.mData->RemoveObserver(textureObserver);
 
-  if(data->GetObserverCount() == 0)
+  if(--info.mReferenceCount <= 0)
   {
-    mCache.Erase(mCache.Begin() + cacheIndex);
+    mCache.erase(mCache.begin() + cacheIndex);
   }
 }
 
+NPatchData* NPatchLoader::GetNPatchData(const VisualUrl& url, const Rect<int>& border, bool& preMultiplyOnLoad)
+{
+  std::size_t                              hash  = CalculateHash(url.GetUrl());
+  std::vector<NPatchInfo>::size_type       index = UNINITIALIZED_ID;
+  const std::vector<NPatchInfo>::size_type count = mCache.size();
+
+  NPatchInfo* infoPtr = nullptr;
+
+  for(; index < count; ++index)
+  {
+    if(mCache[index].mData->GetHash() == hash)
+    {
+      // hash match, check url as well in case of hash collision
+      if(mCache[index].mData->GetUrl().GetUrl() == url.GetUrl())
+      {
+        // Use cached data. Need to fast-out return.
+        if(mCache[index].mData->GetBorder() == border)
+        {
+          mCache[index].mReferenceCount++;
+          return mCache[index].mData;
+        }
+        else
+        {
+          if(mCache[index].mData->GetLoadingState() == NPatchData::LoadingState::LOAD_COMPLETE)
+          {
+            // If we only found LOAD_FAILED case, replace current data. We can reuse texture
+            if(infoPtr == nullptr || infoPtr->mData->GetLoadingState() != NPatchData::LoadingState::LOAD_COMPLETE)
+            {
+              infoPtr = &mCache[index];
+            }
+          }
+          // Still loading pixel buffer. We cannot reuse cached texture yet. Skip checking
+          else if(mCache[index].mData->GetLoadingState() == NPatchData::LoadingState::LOADING)
+          {
+            continue;
+          }
+          // if LOAD_FAILED, reuse this cached NPatchData, and try to load again.
+          else
+          {
+            if(infoPtr == nullptr)
+            {
+              infoPtr = &mCache[index];
+            }
+          }
+        }
+      }
+    }
+  }
+
+  // If this is new image loading, make new cache data
+  if(infoPtr == nullptr)
+  {
+    NPatchInfo info(new NPatchData());
+    info.mData->SetId(GenerateUniqueNPatchDataId());
+    info.mData->SetHash(hash);
+    info.mData->SetUrl(url);
+    info.mData->SetBorder(border);
+    info.mData->SetPreMultiplyOnLoad(preMultiplyOnLoad);
+
+    mCache.emplace_back(std::move(info));
+    infoPtr = &mCache.back();
+  }
+  // Else if LOAD_COMPLETE, Same url but border is different - use the existing texture
+  else if(infoPtr->mData->GetLoadingState() == NPatchData::LoadingState::LOAD_COMPLETE)
+  {
+    NPatchInfo info(new NPatchData());
+
+    info.mData->SetId(GenerateUniqueNPatchDataId());
+    info.mData->SetHash(hash);
+    info.mData->SetUrl(url);
+    info.mData->SetCroppedWidth(infoPtr->mData->GetCroppedWidth());
+    info.mData->SetCroppedHeight(infoPtr->mData->GetCroppedHeight());
+
+    info.mData->SetTextures(infoPtr->mData->GetTextures());
+
+    NPatchUtility::StretchRanges stretchRangesX;
+    stretchRangesX.PushBack(Uint16Pair(border.left, ((info.mData->GetCroppedWidth() >= static_cast<unsigned int>(border.right)) ? info.mData->GetCroppedHeight() - border.right : 0)));
+
+    NPatchUtility::StretchRanges stretchRangesY;
+    stretchRangesY.PushBack(Uint16Pair(border.top, ((info.mData->GetCroppedWidth() >= static_cast<unsigned int>(border.bottom)) ? info.mData->GetCroppedHeight() - border.bottom : 0)));
+
+    info.mData->SetStretchPixelsX(stretchRangesX);
+    info.mData->SetStretchPixelsY(stretchRangesY);
+    info.mData->SetBorder(border);
+
+    info.mData->SetPreMultiplyOnLoad(infoPtr->mData->IsPreMultiplied());
+
+    info.mData->SetLoadingState(NPatchData::LoadingState::LOAD_COMPLETE);
+
+    mCache.emplace_back(std::move(info));
+    infoPtr = &mCache.back();
+  }
+  // Else, LOAD_FAILED. just increase reference so we can reuse it.
+  else
+  {
+    infoPtr->mReferenceCount++;
+  }
+
+  DALI_ASSERT_ALWAYS(infoPtr && "NPatchInfo creation failed!");
+
+  return infoPtr->mData;
+}
+
 } // namespace Internal
 
 } // namespace Toolkit
index 6475613..48301a6 100644 (file)
@@ -19,7 +19,6 @@
 
 // EXTERNAL INCLUDES
 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
-#include <dali/devel-api/common/owner-container.h>
 #include <dali/public-api/rendering/texture-set.h>
 #include <string>
 
@@ -90,8 +89,9 @@ public:
 
   /**
    * @brief Remove a texture matching id.
-   * Erase the observer from the observer list of cache.
-   * If the observer list is empty, the textureSet will be reset.
+   * Erase the observer from the observer list of cache if we need.
+   * This API decrease cached NPatchInfo reference.
+   * If the NPatchInfo reference become 0, the textureSet will be reset.
    *
    * @param [in] id cache data id
    * @param [in] textureObserver The NPatchVisual that requested loading.
@@ -103,6 +103,60 @@ private:
 
   int32_t GetCacheIndexFromId(const NPatchData::NPatchDataId id);
 
+private:
+  /**
+   * @brief Information of NPatchData
+   * It also hold ownership of NPatchData memory.
+   */
+  struct NPatchInfo
+  {
+    NPatchInfo(NPatchData* data)
+    : mData(data),
+      mReferenceCount(1u)
+    {
+    }
+    ~NPatchInfo()
+    {
+      if(mData)
+      {
+        delete mData;
+      }
+    }
+    NPatchInfo(NPatchInfo&& info) // move constructor
+    {
+      mData                = std::move(info.mData);
+      mReferenceCount      = info.mReferenceCount;
+      info.mData           = nullptr;
+      info.mReferenceCount = 0u;
+    }
+    NPatchInfo& operator=(NPatchInfo&& info) // move operator
+    {
+      mData                = std::move(info.mData);
+      mReferenceCount      = info.mReferenceCount;
+      info.mData           = nullptr;
+      info.mReferenceCount = 0u;
+      return *this;
+    }
+
+    NPatchInfo()                       = delete; // Do not use default constructor
+    NPatchInfo(const NPatchInfo& info) = delete; // Do not use copy constructor
+
+    NPatchData*  mData;
+    std::int16_t mReferenceCount; ///< The number of N-patch visuals that use this data.
+  };
+
+  /**
+   * @brief Get cached NPatchData by inputed url and border. If there is no cached data, create new one.
+   * @note This API increase cached NPatchInfo reference.
+   *
+   * @param [in] url to retrieve
+   * @param [in] border The border size of the image
+   * @param [in,out] preMultiplyOnLoad True if the image color should be multiplied by it's alpha. Set to false if the
+   *                                   image has no alpha channel
+   * @return NPatchData pointer that Load function will used.
+   */
+  NPatchData* GetNPatchData(const VisualUrl& url, const Rect<int>& border, bool& preMultiplyOnLoad);
+
 protected:
   /**
    * Undefined copy constructor.
@@ -115,8 +169,8 @@ protected:
   NPatchLoader& operator=(const NPatchLoader& rhs);
 
 private:
-  NPatchData::NPatchDataId    mCurrentNPatchDataId;
-  OwnerContainer<NPatchData*> mCache;
+  NPatchData::NPatchDataId mCurrentNPatchDataId;
+  std::vector<NPatchInfo>  mCache;
 };
 
 } // namespace Internal
index 831d4b4..5fc5dd0 100644 (file)
@@ -198,40 +198,17 @@ void NPatchVisual::DoSetOnScene(Actor& actor)
   // load when first go on stage
   LoadImages();
 
+  // Set mPlacementActor now, because some case, LoadImages can use this information in LoadComplete API.
+  // at this case, we try to SetResouce to mPlaceActor twice. so, we should avoid that case.
+  mPlacementActor = actor;
+
   const NPatchData* data;
-  if(mLoader.GetNPatchData(mId, data))
+  if(mImpl->mRenderer && mLoader.GetNPatchData(mId, data) && data->GetLoadingState() != NPatchData::LoadingState::LOADING)
   {
-    Geometry geometry = CreateGeometry();
-    Shader   shader   = CreateShader();
-
-    mImpl->mRenderer.SetGeometry(geometry);
-    mImpl->mRenderer.SetShader(shader);
-
-    mPlacementActor = actor;
-    // If all reasources are already loaded, apply textures and uniforms now
-    // else, will be completed uploaded at LoadComplete function asynchronously.
-    if(data->GetLoadingState() != NPatchData::LoadingState::LOADING &&
-       (!mAuxiliaryUrl.IsValid() || mAuxiliaryResourceStatus != Toolkit::Visual::ResourceStatus::PREPARING))
+    // If mAuxiliaryUrl need to be loaded, we should wait it until LoadComplete called.
+    if(!mAuxiliaryUrl.IsValid() || mAuxiliaryResourceStatus != Toolkit::Visual::ResourceStatus::PREPARING)
     {
-      if(RenderingAddOn::Get().IsValid())
-      {
-        RenderingAddOn::Get().SubmitRenderTask(mImpl->mRenderer, data->GetRenderingMap());
-      }
-
-      ApplyTextureAndUniforms();
-      actor.AddRenderer(mImpl->mRenderer);
-      mPlacementActor.Reset();
-
-      // npatch loaded and ready to display
-      if(data->GetLoadingState() != NPatchData::LoadingState::LOAD_COMPLETE ||
-         (mAuxiliaryUrl.IsValid() && mAuxiliaryResourceStatus != Toolkit::Visual::ResourceStatus::READY))
-      {
-        ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
-      }
-      else
-      {
-        ResourceReady(Toolkit::Visual::ResourceStatus::READY);
-      }
+      SetResource();
     }
   }
 }
@@ -513,8 +490,6 @@ void NPatchVisual::ApplyTextureAndUniforms()
   else
   {
     DALI_LOG_ERROR("The N patch image '%s' is not a valid N patch image\n", mImageUrl.GetUrl().c_str());
-    textureSet = TextureSet::New();
-
     Actor   actor     = mPlacementActor.GetHandle();
     Vector2 imageSize = Vector2::ZERO;
     if(actor)
@@ -548,18 +523,36 @@ Geometry NPatchVisual::GetNinePatchGeometry(VisualFactoryCache::GeometryType sub
 
 void NPatchVisual::SetResource()
 {
-  Geometry geometry = CreateGeometry();
-  Shader   shader   = CreateShader();
+  const NPatchData* data;
+  if(mImpl->mRenderer && mLoader.GetNPatchData(mId, data))
+  {
+    Geometry geometry = CreateGeometry();
+    Shader   shader   = CreateShader();
 
-  mImpl->mRenderer.SetGeometry(geometry);
-  mImpl->mRenderer.SetShader(shader);
+    mImpl->mRenderer.SetGeometry(geometry);
+    mImpl->mRenderer.SetShader(shader);
 
-  Actor actor = mPlacementActor.GetHandle();
-  if(actor)
-  {
-    ApplyTextureAndUniforms();
-    actor.AddRenderer(mImpl->mRenderer);
-    mPlacementActor.Reset();
+    if(RenderingAddOn::Get().IsValid())
+    {
+      RenderingAddOn::Get().SubmitRenderTask(mImpl->mRenderer, data->GetRenderingMap());
+    }
+    Actor actor = mPlacementActor.GetHandle();
+    if(actor)
+    {
+      ApplyTextureAndUniforms();
+      actor.AddRenderer(mImpl->mRenderer);
+      mPlacementActor.Reset();
+    }
+
+    // npatch loaded and ready to display
+    if(data->GetLoadingState() != NPatchData::LoadingState::LOAD_COMPLETE)
+    {
+      ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
+    }
+    else
+    {
+      ResourceReady(Toolkit::Visual::ResourceStatus::READY);
+    }
   }
 }
 
@@ -567,6 +560,15 @@ void NPatchVisual::LoadComplete(bool loadSuccess, TextureInformation textureInfo
 {
   if(textureInformation.returnType == TextureUploadObserver::ReturnType::TEXTURE) // For the Url.
   {
+    if(textureInformation.textureId != TextureManager::INVALID_TEXTURE_ID)
+    {
+      if(mId == NPatchData::INVALID_NPATCH_DATA_ID)
+      {
+        // Special case when mLoader.Load call LoadComplete function before mId setup.
+        // We can overwrite mId.
+        mId = static_cast<NPatchData::NPatchDataId>(textureInformation.textureId);
+      }
+    }
     if(loadSuccess)
     {
       EnablePreMultipliedAlpha(textureInformation.preMultiplied);
@@ -584,7 +586,7 @@ void NPatchVisual::LoadComplete(bool loadSuccess, TextureInformation textureInfo
       mAuxiliaryResourceStatus = Toolkit::Visual::ResourceStatus::FAILED;
     }
   }
-  // If auxiliaryUrl didn't set || auxiliaryUrl load done.
+  // If auxiliaryUrl didn't required OR auxiliaryUrl load done.
   if(!mAuxiliaryUrl.IsValid() || mAuxiliaryResourceStatus != Toolkit::Visual::ResourceStatus::PREPARING)
   {
     const NPatchData* data;
@@ -592,16 +594,6 @@ void NPatchVisual::LoadComplete(bool loadSuccess, TextureInformation textureInfo
     if(mImpl->mRenderer && mLoader.GetNPatchData(mId, data) && data->GetLoadingState() != NPatchData::LoadingState::LOADING)
     {
       SetResource();
-      // npatch loaded and ready to display
-      if(data->GetLoadingState() != NPatchData::LoadingState::LOAD_COMPLETE ||
-         (mAuxiliaryUrl.IsValid() && mAuxiliaryResourceStatus != Toolkit::Visual::ResourceStatus::READY))
-      {
-        ResourceReady(Toolkit::Visual::ResourceStatus::FAILED);
-      }
-      else
-      {
-        ResourceReady(Toolkit::Visual::ResourceStatus::READY);
-      }
     }
   }
 }
index d7932d2..2f5d123 100644 (file)
@@ -412,7 +412,6 @@ void VisualFactoryCache::UpdateBrokenImageRenderer(Renderer& renderer, const Vec
   int brokenIndex = GetProperBrokenImageIndex(size);
   if(GetBrokenImageVisualType(brokenIndex) == VisualUrl::N_PATCH)
   {
-    DALI_LOG_ERROR("Broken npatch?");
     // Set geometry and shader for npatch
     Geometry geometry = GetNPatchGeometry(brokenIndex);
     Shader   shader   = GetNPatchShader(brokenIndex);
@@ -422,7 +421,6 @@ void VisualFactoryCache::UpdateBrokenImageRenderer(Renderer& renderer, const Vec
   }
   else
   {
-    DALI_LOG_ERROR("Broken single image");
     // Create single image renderer only if rederer is not use normal ImageShader. i.e. npatch visual.
     if(!rendererIsImage)
     {
index 958d031..91939c0 100644 (file)
 #include <dali-toolkit/public-api/controls/gl-view/gl-view.h>
 
 // INTERNAL INCLUDES
+#include <dali-toolkit/internal/controls/gl-view/drawable-view-impl.h>
 #include <dali-toolkit/internal/controls/gl-view/gl-view-impl.h>
 
-namespace Dali
+namespace Dali::Toolkit
 {
-namespace Toolkit
-{
-GlView::GlView()
-{
-}
+
+GlView::GlView() = default;
 
 GlView::GlView(const GlView& GlView) = default;
 
@@ -37,18 +35,38 @@ GlView& GlView::operator=(const GlView& GlView) = default;
 
 GlView& GlView::operator=(GlView&& rhs) = default;
 
-GlView::~GlView()
+GlView::~GlView() = default;
+
+GlView GlView::New(ColorFormat colorFormat)
 {
+  // This function is backward compatible and always returns
+  // backend based on NativeImage.
+  return Internal::GlView::New( colorFormat );
 }
 
-GlView GlView::New(ColorFormat colorFormat)
+GlView GlView::New(BackendMode backendMode, ColorFormat colorFormat)
 {
-  return Internal::GlView::New(colorFormat);
+  switch(backendMode)
+  {
+    case BackendMode::DIRECT_RENDERING:
+    {
+      return Internal::DrawableView::New();
+    }
+    case BackendMode::EGL_IMAGE_OFFSCREEN_RENDERING:
+    {
+      return Internal::GlView::New(colorFormat);
+    }
+    default:
+    {
+      DALI_ASSERT_ALWAYS("Invalid BackendMode");
+    }
+  }
+  return {};
 }
 
 GlView GlView::DownCast(BaseHandle handle)
 {
-  return Control::DownCast<GlView, Internal::GlView>(handle);
+  return Control::DownCast<GlView, Internal::GlViewImpl>(handle);
 }
 
 void GlView::RegisterGlCallbacks(CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback)
@@ -76,12 +94,17 @@ Dali::Toolkit::GlView::RenderingMode GlView::GetRenderingMode() const
   return Dali::Toolkit::GetImpl(*this).GetRenderingMode();
 }
 
+Dali::Toolkit::GlView::BackendMode GlView::GetBackendMode() const
+{
+  return Dali::Toolkit::GetImpl(*this).GetBackendMode();
+}
+
 void GlView::RenderOnce()
 {
   Dali::Toolkit::GetImpl(*this).RenderOnce();
 }
 
-GlView::GlView(Internal::GlView& implementation)
+GlView::GlView(Internal::GlViewImpl& implementation)
 : Control(implementation)
 {
 }
@@ -89,9 +112,7 @@ GlView::GlView(Internal::GlView& implementation)
 GlView::GlView(Dali::Internal::CustomActor* internal)
 : Control(internal)
 {
-  VerifyCustomActorPointer<Internal::GlView>(internal);
+  VerifyCustomActorPointer<Internal::GlViewImpl>(internal);
 }
 
-} // namespace Toolkit
-
 } // namespace Dali
index 57c3201..099b00f 100644 (file)
@@ -26,7 +26,7 @@ namespace Toolkit
 {
 namespace Internal DALI_INTERNAL
 {
-class GlView;
+class GlViewImpl;
 }
 
 /**
@@ -36,10 +36,42 @@ class GlView;
  * GlView creates a GL context, a GL surface and a render thread.
  * The render thread invokes user's callbacks.
  *
+ * @SINCE_2_0.45
  */
 class DALI_TOOLKIT_API GlView : public Dali::Toolkit::Control
 {
 public:
+
+  /**
+   * @brief Implementation backend mode
+   *
+   * @SINCE_2_1.18
+   */
+  enum class BackendMode
+  {
+    /**
+     * DIRECT_RENDERING mode executes GL code within DALi graphics
+     * pipeline. When Renderer is about to be drawn, the callback
+     * will be executed and the custom code "injected" into the pipeline.
+     * This allows rendering directly to the surface rather than offscreen.
+     */
+    DIRECT_RENDERING = 0,
+
+    /**
+     * EGL_IMAGE_OFFSCREEN_RENDERING mode executes GL code in own thread
+     * and renders to the offscreen NativeImage (EGL) buffer. This backend
+     * will render in parallel but has higher memory footprint and may suffer
+     * performance issues due to using EGL image.
+     */
+    EGL_IMAGE_OFFSCREEN_RENDERING,
+
+    /**
+     * The default mode is set to EGL_IMAGE_OFFSCREEN_RENDERING for backwards
+     * compatibility.
+     */
+    DEFAULT = EGL_IMAGE_OFFSCREEN_RENDERING
+  };
+
   /**
    * @brief Enumeration for rendering mode
    *
@@ -47,6 +79,8 @@ public:
    * It has two options.
    * One of them is continuous mode. It is rendered continuously.
    * The other is on demand mode. It is rendered by application.
+   *
+   * @SINCE_2_0.45
    */
   enum class RenderingMode
   {
@@ -58,6 +92,8 @@ public:
    * @brief Enumeration for Graphics API version
    *
    * This Enumeration is used to set a GLES version for EGL configuration.
+   *
+   * @SINCE_2_0.45
    */
   enum class GraphicsApiVersion
   {
@@ -69,6 +105,8 @@ public:
    * @brief Enumeration for color buffer format
    *
    * This Enumeration is used to set a color buffer format of GlView
+   *
+   * @SINCE_2_0.45
    */
   enum class ColorFormat
   {
@@ -78,13 +116,34 @@ public:
 
   /**
    * @brief Creates a GlView control.
+   *
+   * @note This function always creates the GlView with NativeImage backend.
+   *
    * @param[in] colorFormat the format of the color buffer.
    * @return A handle to a GlView control
+   *
+   * @SINCE_2_0.45
    */
   static GlView New(ColorFormat colorFormat);
 
   /**
+   * @brief Creates a GlView control.
+   *
+   * The new GlView will be created with specified backend.
+   * The colorFormat is ignored for DIRECT_RENDERING backend.
+   *
+   * @param[in] colorFormat the format of the color buffer.
+   * @param[in] backendMode the backend used by the GlView
+   * @return A handle to a GlView control
+   *
+   * @SINCE_2_1.18
+   */
+  static GlView New(BackendMode backendMode, ColorFormat colorFormat);
+
+  /**
    * @brief Creates an uninitialized GlView.
+   *
+   * @SINCE_2_0.45
    */
   GlView();
 
@@ -92,6 +151,8 @@ public:
    * @brief Destructor.
    *
    * This is non-virtual since derived Handle types must not contain data or virtual methods.
+   *
+   * @SINCE_2_0.45
    */
   ~GlView();
 
@@ -99,6 +160,8 @@ public:
    * @brief Copy constructor.
    *
    * @param[in] GlView GlView to copy. The copied GlView will point at the same implementation
+   *
+   * @SINCE_2_0.45
    */
   GlView(const GlView& GlView);
 
@@ -106,6 +169,8 @@ public:
    * @brief Move constructor
    *
    * @param[in] rhs A reference to the moved handle
+   *
+   * @SINCE_2_0.45
    */
   GlView(GlView&& rhs);
 
@@ -114,6 +179,8 @@ public:
    *
    * @param[in] GlView The GlView to assign from
    * @return A reference to this
+   *
+   * @SINCE_2_0.45
    */
   GlView& operator=(const GlView& GlView);
 
@@ -122,6 +189,8 @@ public:
    *
    * @param[in] rhs A reference to the moved handle
    * @return A reference to this
+   *
+   * @SINCE_2_0.45
    */
   GlView& operator=(GlView&& rhs);
 
@@ -133,6 +202,8 @@ public:
    *
    * @param[in] handle Handle to an object
    * @return Handle to a GlView or an uninitialized handle
+   *
+   * @SINCE_2_0.45
    */
   static GlView DownCast(BaseHandle handle);
 
@@ -164,6 +235,8 @@ public:
    * @note Ownership of the callbacks is passed onto this class.
    * <b>You can't call Dali APIs in your callbacks because it is invoked in GlView's own render thread.</b>
    * And this must be called before adding GlView to the scene.
+   *
+   * @SINCE_2_0.45
    */
   void RegisterGlCallbacks(CallbackBase* initCallback, CallbackBase* renderFrameCallback, CallbackBase* terminateCallback);
 
@@ -182,6 +255,8 @@ public:
    * @note Ownership of the callback is passed onto this class.
    * <b>You can't call Dali APIs in your callback because it is invoked in GlView's own render thread.</b>
    * And this must be called before adding GlView to the scene.
+   *
+   * @SINCE_2_0.45
    */
   void SetResizeCallback(CallbackBase* resizeCallback);
 
@@ -192,13 +267,24 @@ public:
    *
    * @note The default Rendering mode is CONTINUOUS.
    * If ON_DEMAND mode is set, it is rendered by RenderOnce()
+   *
+   * @SINCE_2_0.45
    */
   void SetRenderingMode(RenderingMode mode);
 
   /**
    * @brief Gets the rendering mode.
+   *
+   * @SINCE_2_0.45
+   */
+  [[nodiscard]] RenderingMode GetRenderingMode() const;
+
+  /**
+   * @brief Gets the backend mode.
+   *
+   * @SINCE_2_1.18
    */
-  RenderingMode GetRenderingMode() const;
+  [[nodiscard]] BackendMode GetBackendMode() const;
 
   /**
    * @brief Sets egl configuration for GlView
@@ -208,12 +294,16 @@ public:
    * @param[in] msaa the expected sampling number per pixel.
    * @param[in] version the graphics API version
    * @return True if the config exists, false otherwise.
+   *
+   * @SINCE_2_0.45
    */
   bool SetGraphicsConfig(bool depth, bool stencil, int msaa, GraphicsApiVersion version);
 
   /**
    * @brief Renders once more even if GL render functions are not added to idler.
    * @note Will not work if the window is hidden or GL render functions are added to idler
+   *
+   * @SINCE_2_0.45
    */
   void RenderOnce();
 
@@ -222,12 +312,16 @@ public: // Not intended for application developers
   /**
    * @brief Creates a handle using the Toolkit::Internal implementation.
    * @param[in] implementation The GlView implementation
+   *
+   * @SINCE_2_0.45
    */
-  DALI_INTERNAL GlView(Internal::GlView& implementation);
+  DALI_INTERNAL GlView(Internal::GlViewImpl& implementation);
 
   /**
    * @brief Allows the creation of this GlView from an Internal::CustomActor pointer.
    * @param[in] internal A pointer to the internal CustomActor
+   *
+   * @SINCE_2_0.45
    */
   DALI_INTERNAL GlView(Dali::Internal::CustomActor* internal);
   /// @endcond
index 6f9e75d..9630b37 100644 (file)
@@ -29,7 +29,7 @@ namespace Toolkit
 {
 const unsigned int TOOLKIT_MAJOR_VERSION = 2;
 const unsigned int TOOLKIT_MINOR_VERSION = 1;
-const unsigned int TOOLKIT_MICRO_VERSION = 17;
+const unsigned int TOOLKIT_MICRO_VERSION = 18;
 const char* const  TOOLKIT_BUILD_DATE    = __DATE__ " " __TIME__;
 
 #ifdef DEBUG_ENABLED
index 01aa94e..c115b60 100644 (file)
@@ -1,6 +1,6 @@
 Name:       dali2-toolkit
 Summary:    Dali 3D engine Toolkit
-Version:    2.1.17
+Version:    2.1.18
 Release:    1
 Group:      System/Libraries
 License:    Apache-2.0 and BSD-3-Clause and MIT