Add precompile-shader example 37/322837/4
authorsunghyun kim <scholb.kim@samsung.com>
Wed, 16 Apr 2025 08:17:25 +0000 (17:17 +0900)
committersunghyun kim <scholb.kim@samsung.com>
Tue, 22 Apr 2025 06:27:39 +0000 (15:27 +0900)
Change-Id: I816b78750343f06680277e91e513babc1bb5c79c

com.samsung.dali-demo.xml
examples/precompile-shader/README.md [new file with mode: 0644]
examples/precompile-shader/precompile-shader-example.cpp [new file with mode: 0644]
examples/precompile-shader/precompile-shader.png [new file with mode: 0755]
resources/po/en_GB.po
resources/po/en_US.po
shared/dali-demo-strings.h
tests-reel/dali-tests-reel.cpp

index f684d2e7d20c58a09ee38ce4ef20a59c9791e3b3..5a1f35e4e9a5c34d39831fac035b1f3fcb362e50 100644 (file)
        <ui-application appid="popup.example" exec="/usr/apps/com.samsung.dali-demo/bin/popup.example" nodisplay="true" multiple="false" taskmanage="true" type="c++app">
                <label>Popup</label>
        </ui-application>
+       <ui-application appid="precompile-shader.example" exec="/usr/apps/com.samsung.dali-demo/bin/precompile-shader.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
+               <label>Precompile Shader</label>
+       </ui-application>
        <ui-application appid="pre-render-callback.example" exec="/usr/apps/com.samsung.dali-demo/bin/pre-render-callback.example" nodisplay="true" multiple="false" type="c++app" taskmanage="true">
                <label>Frame Callback</label>
        </ui-application>
diff --git a/examples/precompile-shader/README.md b/examples/precompile-shader/README.md
new file mode 100644 (file)
index 0000000..7e2e849
--- /dev/null
@@ -0,0 +1,10 @@
+# Precompile Shader
+
+This is a test example for testing shader precompilation/file caching.
+file caching can be enabled/disabled through environment variables, and precompiling refers to the code in the example.
+
+- Test precompile shader
+- Test Shader File Caching
+
+Please update this note if you add some more test cases.
+![](./precompile-shader.png)
diff --git a/examples/precompile-shader/precompile-shader-example.cpp b/examples/precompile-shader/precompile-shader-example.cpp
new file mode 100644 (file)
index 0000000..c3ec33d
--- /dev/null
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2025 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/dali-toolkit.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+
+// For Wait
+#include <iostream>
+#include <chrono>
+#include <thread>
+
+using namespace Dali;
+using Dali::Toolkit::TextLabel;
+
+const std::string_view SHADER_CUSTOM_VERT
+{
+R"(attribute mediump vec2 aPosition;
+uniform mediump mat4 uMvpMatrix;
+uniform vec3 uSize;
+
+void main()
+{
+  gl_Position = uMvpMatrix * vec4(aPosition*uSize.xy, 0.0, 1.0);
+}
+)"
+};
+
+const std::string_view SHADER_CUSTOM_FRAG
+{
+R"(uniform lowp vec4 uColor;
+
+void main()
+{
+  gl_FragColor = vec4(0.0,0.0,0.0,1.0);
+}
+)"
+};
+
+using namespace Dali;
+using namespace Dali::Toolkit;
+
+// This example shows how to create and display Hello World! using a simple TextActor
+//
+class PrecompileShaderController : public ConnectionTracker
+{
+public:
+  PrecompileShaderController(Application& application)
+  : mApplication(application)
+  {
+    setenv("DALI_SHADER_USE_PROGRAM_BINARY", "1", 1); // Enable program binary
+    // Connect to the Application's Init signal
+    mApplication.InitSignal().Connect(this, &PrecompileShaderController::Create);
+  }
+
+  ~PrecompileShaderController() = default; // Nothing to do in destructor
+
+  // The Init signal is received once (only) during the Application lifetime
+  void Create(Application& application)
+  {
+    Property::Map imageShader;
+    imageShader["shaderType"]   = "image";
+    imageShader["shaderOption"] = Property::Map().Add("YUV_AND_RGB", true);
+    imageShader["shaderName"]   = "IMAGE_SHADER_YUV_AND_RGB";
+
+    Property::Map imageShader2;
+    imageShader2["shaderType"]   = "image";
+    imageShader2["shaderOption"] = Property::Map()
+                                     .Add("ROUNDED_CORNER", true)
+                                     .Add("MASKING", true);
+    imageShader2["shaderName"]   = "";
+
+    Property::Map textShader;
+    textShader["shaderType"]   = "text";
+    textShader["shaderOption"] = Property::Map()
+                                     .Add("MULTI_COLOR", true)
+                                     .Add("STYLES", true);
+    textShader["shaderName"]   = "";
+
+    Property::Map colorShader;
+    colorShader["shaderType"]   = "color";
+    colorShader["shaderOption"] = Property::Map()
+                                     .Add("CUTOUT", true)
+                                     .Add("BORDERLINE", true);
+    colorShader["shaderName"]   = "ColorBorderlineCutout";
+
+
+    Property::Map customSHader;
+    customSHader["shaderType"]   = "custom";
+    customSHader["shaderName"]   = "myShader";
+    customSHader["vertexShader"] = SHADER_CUSTOM_VERT.data();
+    customSHader["fragmentShader"] = SHADER_CUSTOM_FRAG.data();
+
+    Property::Map npatchShader;
+    npatchShader["shaderType"]   = "npatch";
+    npatchShader["xStretchCount"] = 4;
+    npatchShader["yStretchCount"] = 3;
+
+    VisualFactory::Get().AddPrecompileShader(imageShader);
+    VisualFactory::Get().AddPrecompileShader(imageShader2);
+    VisualFactory::Get().AddPrecompileShader(textShader);
+    VisualFactory::Get().AddPrecompileShader(colorShader);
+    VisualFactory::Get().AddPrecompileShader(customSHader);
+    VisualFactory::Get().AddPrecompileShader(npatchShader);
+    VisualFactory::Get().UsePreCompiledShader();
+
+    // Get a handle to the window
+    Window window = application.GetWindow();
+    window.SetBackgroundColor(Color::WHITE);
+
+    TextLabel textLabel = TextLabel::New("Precomile Shader");
+    textLabel.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+    textLabel.SetProperty(Dali::Actor::Property::NAME, "Precompile Shader");
+    window.Add(textLabel);
+
+    // Need to wait forcelly for precompiling shaders
+    std::this_thread::sleep_for(std::chrono::seconds(3));
+  }
+
+private:
+  Application& mApplication;
+};
+
+int DALI_EXPORT_API main(int argc, char** argv)
+{
+  Application          application = Application::New(&argc, &argv);
+  PrecompileShaderController test(application);
+  application.MainLoop();
+  return 0;
+}
diff --git a/examples/precompile-shader/precompile-shader.png b/examples/precompile-shader/precompile-shader.png
new file mode 100755 (executable)
index 0000000..06ecc6e
Binary files /dev/null and b/examples/precompile-shader/precompile-shader.png differ
index 75db038f1be9e2c73f5d64fe54fcf72e7bef0450..17f3043507194827aacb6feda2deaefa3a742e33 100755 (executable)
@@ -214,6 +214,9 @@ msgstr "Pivot"
 msgid "DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK"
 msgstr "Pre Render Callback"
 
+msgid "DALI_DEMO_STR_TITLE_PRECOMPILE_SHADER"
+msgstr "Precompile Shader"
+
 msgid "DALI_DEMO_STR_TITLE_PROGRESS_BAR"
 msgstr "Progress Bar"
 
index 9804df21abf899bdb405386af0b094fa9ab0fccc..56113ddb9cbf2619d2e5fd88d366a6a38a0104b3 100755 (executable)
@@ -223,6 +223,9 @@ msgstr "Pivot"
 msgid "DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK"
 msgstr "Pre Render Callback"
 
+msgid "DALI_DEMO_STR_TITLE_PRECOMPILE_SHADER"
+msgstr "Precompile Shader"
+
 msgid "DALI_DEMO_STR_TITLE_PROGRESS_BAR"
 msgstr "Progress Bar"
 
index c71151505b4aa6a20f0b16532ba02f032e558bd5..ada9d697d727a8c284aa6f1edd756346c0370ad8 100644 (file)
@@ -113,6 +113,7 @@ extern "C"
 #define DALI_DEMO_STR_TITLE_POPUP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_POPUP")
 #define DALI_DEMO_STR_TITLE_PIVOT dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PIVOT")
 #define DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK")
+#define DALI_DEMO_STR_TITLE_PRECOMPILE_SHADER dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PRECOMPILE_SHADER")
 #define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES")
 #define DALI_DEMO_STR_TITLE_PROGRESS_BAR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PROGRESS_BAR")
 #define DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION")
@@ -244,6 +245,7 @@ extern "C"
 #define DALI_DEMO_STR_TITLE_POPUP "Popup"
 #define DALI_DEMO_STR_TITLE_PIVOT "Pivot"
 #define DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK "Pre Render Callback"
+#define DALI_DEMO_STR_TITLE_PRECOMPILE_SHADER "Precompile Shader"
 #define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES "Primitive Shapes"
 #define DALI_DEMO_STR_TITLE_PROGRESS_BAR "Progress Bar"
 #define DALI_DEMO_STR_TITLE_PROPERTY_NOTIFICATION "Property Notification"
index 61f605c13662fe189f51e7242dfbcbca0e81f3e6..240cb8158e75c4430e4fd689916ddde7f3ac9563 100644 (file)
@@ -46,6 +46,7 @@ int DALI_EXPORT_API main(int argc, char** argv)
   demo.AddExample(Example("inherit-test.example", DALI_DEMO_STR_TITLE_INHERIT_TEST));
   demo.AddExample(Example("image-view-yuv.example", DALI_DEMO_STR_TITLE_IMAGE_VIEW_YUV));
   demo.AddExample(Example("pre-render-callback.example", DALI_DEMO_STR_TITLE_PRE_RENDER_CALLBACK));
+  demo.AddExample(Example("precompile-shader.example", DALI_DEMO_STR_TITLE_PRECOMPILE_SHADER));
   demo.AddExample(Example("perf-scroll.example", DALI_DEMO_STR_TITLE_PERF_SCROLL));
   demo.AddExample(Example("perf-view-creation.example", DALI_DEMO_STR_TITLE_PERF_VIEW_CREATION));
   demo.AddExample(Example("point-mesh.example", DALI_DEMO_STR_TITLE_POINT_MESH));