[dali_2.3.22] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-actor-utils.cpp
index 38eb0b2..d628f0d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/dali-core.h>
-#include <dali/devel-api/images/texture-set-image.h>
 
 // INTERNAL INCLUDES
+#include <dali-test-suite-utils.h>
 #include "mesh-builder.h"
 
 namespace Dali
 {
-
 namespace
 {
-
 const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
-  attribute mediump vec2 aPosition;\n
-  uniform mediump mat4 uMvpMatrix;\n
-  uniform mediump vec3 uSize;\n
-  \n
-  void main()\n
-  {\n
-    mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n
-    vertexPosition.xyz *= uSize;\n
-    gl_Position = uMvpMatrix * vertexPosition;\n
-  }\n
-);
+  attribute mediump vec2   aPosition;\n
+    uniform mediump mat4   uMvpMatrix;\n
+      uniform mediump vec3 uSize;\n
+  \n void main()\n {
+        \n
+          mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);
+        \n
+          vertexPosition.xyz *= uSize;
+        \n
+          gl_Position = uMvpMatrix * vertexPosition;
+        \n
+      }\n);
 
 const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
   uniform lowp vec4 uColor;\n
-  \n
-  void main()\n
-  {\n
-    gl_FragColor = uColor;\n
-  }\n
-);
+  \n void main()\n {
+    \n
+      gl_FragColor = uColor;
+    \n
+  }\n);
 
 } // unnamed namespace
 
 Actor CreateRenderableActor()
 {
-  return CreateRenderableActor( Image(), VERTEX_SHADER, FRAGMENT_SHADER );
+  return CreateRenderableActor(Texture(), VERTEX_SHADER, FRAGMENT_SHADER);
 }
 
-Actor CreateRenderableActor( Image texture )
+Actor CreateRenderableActor(Texture texture)
 {
-  return CreateRenderableActor( texture, VERTEX_SHADER, FRAGMENT_SHADER );
+  return CreateRenderableActor(texture, VERTEX_SHADER, FRAGMENT_SHADER);
 }
 
-Actor CreateRenderableActor( Image texture, const std::string& vertexShader, const std::string& fragmentShader )
+Actor CreateRenderableActor(Texture texture, const std::string& vertexShader, const std::string& fragmentShader)
 {
   // Create the geometry
   Geometry geometry = CreateQuadGeometry();
 
   // Create Shader
-  Shader shader = Shader::New( vertexShader, fragmentShader );
+  Shader shader = Shader::New(vertexShader, fragmentShader);
 
   // Create renderer from geometry and material
-  Renderer renderer = Renderer::New( geometry, shader );
+  Renderer renderer = Renderer::New(geometry, shader);
 
   // Create actor and set renderer
   Actor actor = Actor::New();
-  actor.AddRenderer( renderer );
+  actor.AddRenderer(renderer);
 
   // If we a texture, then create a texture-set and add to renderer
-  if( texture )
+  if(texture)
   {
     TextureSet textureSet = TextureSet::New();
-    TextureSetImage( textureSet, 0u, texture );
-    renderer.SetTextures( textureSet );
+    textureSet.SetTexture(0u, texture);
+    renderer.SetTextures(textureSet);
 
     // Set actor to the size of the texture if set
-    actor.SetSize( texture.GetWidth(), texture.GetHeight() );
+    actor.SetProperty(Actor::Property::SIZE, Vector2(texture.GetWidth(), texture.GetHeight()));
   }
 
   return actor;
 }
 
+Actor CreateRenderableActor2(TextureSet textures, const std::string& vertexShader, const std::string& fragmentShader)
+{
+  // Create the geometry
+  Geometry geometry = CreateQuadGeometry();
+
+  // Create Shader
+  Shader shader = Shader::New(vertexShader, fragmentShader);
+
+  // Create renderer from geometry and material
+  Renderer renderer = Renderer::New(geometry, shader);
+
+  // Create actor and set renderer
+  Actor actor = Actor::New();
+  actor.AddRenderer(renderer);
+
+  // If we a texture, then create a texture-set and add to renderer
+  if(textures)
+  {
+    renderer.SetTextures(textures);
+
+    auto texture = textures.GetTexture(0);
+
+    // Set actor to the size of the texture if set
+    actor.SetProperty(Actor::Property::SIZE, Vector2(texture.GetWidth(), texture.GetHeight()));
+  }
+
+  return actor;
+}
+
+Texture CreateTexture(TextureType::Type type, Pixel::Format format, int width, int height)
+{
+  Texture texture = Texture::New(type, format, width, height);
+
+  int       bufferSize = width * height * GetBytesPerPixel(format);
+  uint8_t*  buffer     = reinterpret_cast<uint8_t*>(malloc(bufferSize));
+  PixelData pixelData  = PixelData::New(buffer, bufferSize, width, height, format, PixelData::FREE);
+  texture.Upload(pixelData, 0u, 0u, 0u, 0u, width, height);
+  return texture;
+}
+
+TextureSet CreateTextureSet(Pixel::Format format, int width, int height)
+{
+  TextureSet textureSet = TextureSet::New();
+  textureSet.SetTexture(0u, CreateTexture(TextureType::TEXTURE_2D, format, width, height));
+  return textureSet;
+}
+
+void DirtyRectChecker(const std::vector<Rect<int>>& damagedRects, std::multiset<Rect<int>, RectSorter> expectedRectList, bool checkRectsExact, const char* testLocation)
+{
+  // Just check damagedRect contain all expectRectList.
+  DALI_TEST_GREATER(damagedRects.size() + 1u, expectedRectList.size(), testLocation);
+
+  for(auto& rect : damagedRects)
+  {
+    auto iter = expectedRectList.find(rect);
+    if(iter != expectedRectList.end())
+    {
+      expectedRectList.erase(iter);
+    }
+    else if(checkRectsExact)
+    {
+      std::ostringstream o;
+      o << rect << " exist in expectRectList" << std::endl;
+      fprintf(stderr, "Test failed in %s, checking %s", testLocation, o.str().c_str());
+      tet_result(TET_FAIL);
+    }
+  }
+
+  // Check all rects are matched
+  DALI_TEST_EQUALS(expectedRectList.empty(), true, testLocation);
+}
+
 } // namespace Dali