Add methods to get current size and orientation to Scene 10/257610/4
authorHeeyong Song <heeyong.song@samsung.com>
Wed, 28 Apr 2021 07:09:53 +0000 (16:09 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Fri, 14 May 2021 05:05:14 +0000 (05:05 +0000)
Change-Id: I91922312b720d31c1cb05650c094534ded2470ac

automated-tests/src/dali/utc-Dali-Scene.cpp
dali/integration-api/scene.cpp
dali/integration-api/scene.h
dali/internal/event/common/scene-impl.cpp
dali/internal/event/common/scene-impl.h

index 290d896..96302a2 100644 (file)
@@ -928,6 +928,8 @@ int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
   auto stage = Stage::GetCurrent();
   DALI_TEST_EQUALS(stage.GetSize(), defaultScene.GetSize(), TEST_LOCATION);
 
+  Rect<int32_t> surfaceRect = defaultScene.GetCurrentSurfaceRect();
+
   bool surfaceResized;
   // check resized flag before surface is resized.
   surfaceResized = defaultScene.IsSurfaceRectChanged();
@@ -942,6 +944,12 @@ int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
   DALI_TEST_EQUALS(stage.GetSize(), newSize, TEST_LOCATION);
   DALI_TEST_EQUALS(defaultScene.GetSize(), newSize, TEST_LOCATION);
 
+  // Check current surface rect
+  Rect<int32_t> newSurfaceRect = defaultScene.GetCurrentSurfaceRect();
+
+  // It should not be changed yet.
+  DALI_TEST_CHECK(surfaceRect == newSurfaceRect);
+
   // Render after resizing surface
   application.SendNotification();
   application.Render(0);
@@ -952,6 +960,15 @@ int UtcDaliSceneSurfaceResizedDefaultSceneViewport(void)
   // Check that the viewport is handled properly
   DALI_TEST_CHECK(callStack.FindMethodAndGetParameters("Viewport", viewportParams));
 
+  // Check current surface rect
+  newSurfaceRect = defaultScene.GetCurrentSurfaceRect();
+
+  // It should be changed
+  DALI_TEST_EQUALS(newSurfaceRect.x, 0, TEST_LOCATION);
+  DALI_TEST_EQUALS(newSurfaceRect.y, 0, TEST_LOCATION);
+  DALI_TEST_EQUALS(newSurfaceRect.width, 1000, TEST_LOCATION);
+  DALI_TEST_EQUALS(newSurfaceRect.height, 2000, TEST_LOCATION);
+
   END_TEST;
 }
 
@@ -1101,6 +1118,13 @@ int UtcDaliSceneSurfaceRotatedWithAngle0(void)
   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
                                         0);
+
+  // Check current surface orientation
+  int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
+
+  // It should not be changed yet.
+  DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
+
   application.SendNotification();
   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
@@ -1114,6 +1138,12 @@ int UtcDaliSceneSurfaceRotatedWithAngle0(void)
   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
 
+  // Check current surface orientation
+  orientation = application.GetScene().GetCurrentSurfaceOrientation();
+
+  // It should be changed.
+  DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
+
   END_TEST;
 }
 
@@ -1152,6 +1182,13 @@ int UtcDaliSceneSurfaceRotatedWithAngle90(void)
   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
                                         90);
+
+  // Check current surface orientation
+  int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
+
+  // It should not be changed yet.
+  DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
+
   application.SendNotification();
   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
@@ -1172,6 +1209,12 @@ int UtcDaliSceneSurfaceRotatedWithAngle90(void)
   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
 
+  // Check current surface orientation
+  orientation = application.GetScene().GetCurrentSurfaceOrientation();
+
+  // It should be changed.
+  DALI_TEST_EQUALS(orientation, 90, TEST_LOCATION);
+
   END_TEST;
 }
 
@@ -1210,6 +1253,13 @@ int UtcDaliSceneSurfaceRotatedWithAngle180(void)
   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
                                         180);
+
+  // Check current surface orientation
+  int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
+
+  // It should not be changed yet.
+  DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
+
   application.SendNotification();
   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
@@ -1230,6 +1280,12 @@ int UtcDaliSceneSurfaceRotatedWithAngle180(void)
   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
 
+  // Check current surface orientation
+  orientation = application.GetScene().GetCurrentSurfaceOrientation();
+
+  // It should be changed.
+  DALI_TEST_EQUALS(orientation, 180, TEST_LOCATION);
+
   END_TEST;
 }
 
@@ -1268,6 +1324,13 @@ int UtcDaliSceneSurfaceRotatedWithAngle270(void)
   application.GetScene().SurfaceRotated(TestApplication::DEFAULT_SURFACE_WIDTH,
                                         TestApplication::DEFAULT_SURFACE_HEIGHT,
                                         270);
+
+  // Check current surface orientation
+  int32_t orientation = application.GetScene().GetCurrentSurfaceOrientation();
+
+  // It should not be changed yet.
+  DALI_TEST_EQUALS(orientation, 0, TEST_LOCATION);
+
   application.SendNotification();
   application.PreRenderWithPartialUpdate(TestApplication::RENDER_FRAME_INTERVAL, nullptr, damagedRects);
   DALI_TEST_EQUALS(damagedRects.size(), 1, TEST_LOCATION);
@@ -1288,6 +1351,12 @@ int UtcDaliSceneSurfaceRotatedWithAngle270(void)
   DALI_TEST_EQUALS(clippingRect.width, glScissorParams.width, TEST_LOCATION);
   DALI_TEST_EQUALS(clippingRect.height, glScissorParams.height, TEST_LOCATION);
 
+  // Check current surface orientation
+  orientation = application.GetScene().GetCurrentSurfaceOrientation();
+
+  // It should be changed.
+  DALI_TEST_EQUALS(orientation, 270, TEST_LOCATION);
+
   END_TEST;
 }
 
index bbe1139..363b1b5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * 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.
@@ -27,7 +27,7 @@ namespace Dali
 {
 namespace Integration
 {
-Scene Scene::New(Size size, int orientation)
+Scene Scene::New(Size size, int32_t orientation)
 {
   Internal::ScenePtr internal = Internal::Scene::New(size, orientation);
   return Scene(internal.Get());
@@ -156,11 +156,21 @@ void Scene::GetFramePresentedCallback(FrameCallbackContainer& callbacks)
   GetImplementation(*this).GetFramePresentedCallback(callbacks);
 }
 
-void Scene::SurfaceRotated(float width, float height, int orientation)
+void Scene::SurfaceRotated(float width, float height, int32_t orientation)
 {
   GetImplementation(*this).SurfaceRotated(width, height, orientation);
 }
 
+int32_t Scene::GetCurrentSurfaceOrientation() const
+{
+  return GetImplementation(*this).GetCurrentSurfaceOrientation();
+}
+
+const Rect<int32_t>& Scene::GetCurrentSurfaceRect() const
+{
+  return GetImplementation(*this).GetCurrentSurfaceRect();
+}
+
 bool Scene::IsSurfaceRectChanged() const
 {
   return GetImplementation(*this).IsSurfaceRectChanged();
index eeb191f..0bfac7f 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_SCENE_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * 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.
@@ -70,7 +70,7 @@ public:
    *
    * @return a handle to a newly allocated Dali resource.
    */
-  static Scene New(Size size, int orientation = 0);
+  static Scene New(Size size, int32_t orientation = 0);
 
   /**
    * @brief Downcast an Object handle to Scene handle.
@@ -242,7 +242,7 @@ public:
    *
    * @note A callback of the following type may be used:
    * @code
-   *   void MyFunction( int frameId );
+   *   void MyFunction( int32_t frameId );
    * @endcode
    * This callback will be deleted once it is called.
    *
@@ -258,7 +258,7 @@ public:
    *
    * @note A callback of the following type may be used:
    * @code
-   *   void MyFunction( int frameId );
+   *   void MyFunction( int32_t frameId );
    * @endcode
    * This callback will be deleted once it is called.
    *
@@ -291,7 +291,21 @@ public:
    * @param[in] height The height of rotated surface
    * @param[in] orientation The orientation of rotated surface
    */
-  void SurfaceRotated(float width, float height, int orientation);
+  void SurfaceRotated(float width, float height, int32_t orientation);
+
+  /**
+   * @brief Gets the current surface orientation. It gets the value from the scene object.
+   *
+   * @return The current surface orientation.
+   */
+  int32_t GetCurrentSurfaceOrientation() const;
+
+  /**
+   * @brief Gets the current surface rectangle. It gets the value from the scene object.
+   *
+   * @return The current surface rectangle
+   */
+  const Rect<int32_t>& GetCurrentSurfaceRect() const;
 
   /**
    * Query wheter the surface rect is changed or not.
index 95104fb..4ac94c4 100644 (file)
@@ -41,7 +41,7 @@ namespace Dali
 {
 namespace Internal
 {
-ScenePtr Scene::New(Size size, int orientation)
+ScenePtr Scene::New(Size size, int32_t orientation)
 {
   ScenePtr scene = new Scene;
 
@@ -93,7 +93,7 @@ Scene::~Scene()
   // When this destructor is called, the scene has either already been removed from Core or Core has already been destroyed
 }
 
-void Scene::Initialize(Size size, int orientation)
+void Scene::Initialize(Size size, int32_t orientation)
 {
   ThreadLocalStorage* tls = ThreadLocalStorage::GetInternal();
 
@@ -277,18 +277,23 @@ void Scene::EmitKeyEventSignal(const Dali::KeyEvent& event)
   }
 }
 
-void Scene::SurfaceRotated(float width, float height, int orientation)
+void Scene::SurfaceRotated(float width, float height, int32_t orientation)
 {
   mSurfaceOrientation = orientation;
   ChangedSurface(width, height, orientation);
 }
 
-int Scene::GetSurfaceOrientation()
+int32_t Scene::GetCurrentSurfaceOrientation() const
 {
-  return mSurfaceOrientation;
+  return mSceneObject->GetSurfaceOrientation();
 }
 
-void Scene::ChangedSurface(float width, float height, int orientation)
+const Rect<int32_t>& Scene::GetCurrentSurfaceRect() const
+{
+  return mSceneObject->GetSurfaceRect();
+}
+
+void Scene::ChangedSurface(float width, float height, int32_t orientation)
 {
   Rect<int32_t> newSize(0, 0, static_cast<int32_t>(width), static_cast<int32_t>(height)); // truncated
   mSize.width  = width;
index 1346448..51550cf 100644 (file)
@@ -50,7 +50,7 @@ class Scene;
 
 struct DirtyRect
 {
-  DirtyRect(Node* node, Render::Renderer* renderer, int frame, Rect<int>& rect)
+  DirtyRect(Node* node, Render::Renderer* renderer, int32_t frame, Rect<int>& rect)
   : node(node),
     renderer(renderer),
     frame(frame),
@@ -89,10 +89,10 @@ struct DirtyRect
 
   Node*             node;
   Render::Renderer* renderer;
-  int               frame;
+  int32_t           frame;
 
-  Rect<int> rect;
-  bool      visited;
+  Rect<int32_t> rect;
+  bool          visited;
 };
 
 } // namespace SceneGraph
@@ -116,7 +116,7 @@ public:
   /**
    * @copydoc Dali::Integration::Scene::New
    */
-  static ScenePtr New(Size size, int orientation = 0);
+  static ScenePtr New(Size size, int32_t orientation = 0);
 
   /**
    * virtual destructor
@@ -242,14 +242,17 @@ public:
    * @param[in] height The height of rotated surface
    * @param[in] orientation The orientation of rotated surface
    */
-  void SurfaceRotated(float width, float height, int orientation);
+  void SurfaceRotated(float width, float height, int32_t orientation);
 
   /**
-   * @brief Get surface's current orientation
-   *
-   * @return surface orientation
+   * @copydoc Dali::Integration::Scene::GetCurrentSurfaceOrientation
+   */
+  int32_t GetCurrentSurfaceOrientation() const;
+
+  /**
+   * @copydoc Dali::Integration::Scene::GetCurrentSurfaceRect
    */
-  int GetSurfaceOrientation();
+  const Rect<int32_t>& GetCurrentSurfaceRect() const;
 
   /**
    * @copydoc Dali::Integration::Scene::IsSurfaceRectChanged
@@ -363,7 +366,7 @@ private:
    * @param[in] size The size of the set surface
    * @param[in] orientation The orientation of the set surface for this scene
    */
-  void Initialize(Size size, int orientation);
+  void Initialize(Size size, int32_t orientation);
 
   // Undefined
   Scene(const Scene&) = delete;
@@ -378,7 +381,7 @@ private:
    * @param[in] height The height of rotated surface
    * @param[in] orientation The orientation of rotated surface
    */
-  void ChangedSurface(float width, float height, int orientation);
+  void ChangedSurface(float width, float height, int32_t orientation);
 
 private:
   Internal::SceneGraph::Scene* mSceneObject;
@@ -404,7 +407,7 @@ private:
   EventProcessor mEventProcessor;
 
   // The Surface's orientation
-  int mSurfaceOrientation;
+  int32_t mSurfaceOrientation;
 
   // The key event signal
   Integration::Scene::KeyEventSignalType          mKeyEventSignal;