X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-scene3d%2Futc-Dali-SceneView.cpp;h=06ff71219979b6b1426ef859602d8d362cb1c091;hb=HEAD;hp=ed3af5864fa0e8c3462c785bacbcc6d4f61e29a0;hpb=9660fccbe1c9b4a902a236eeb5b2988b94c64c1d;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/automated-tests/src/dali-scene3d/utc-Dali-SceneView.cpp b/automated-tests/src/dali-scene3d/utc-Dali-SceneView.cpp index ed3af58..4541eee 100644 --- a/automated-tests/src/dali-scene3d/utc-Dali-SceneView.cpp +++ b/automated-tests/src/dali-scene3d/utc-Dali-SceneView.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 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. @@ -16,13 +16,16 @@ */ #include +#include +#include + #include #include #include #include #include -#include + using namespace Dali; using namespace Dali::Toolkit; @@ -51,7 +54,7 @@ const char* TEST_GLTF_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedCube.gltf"; * These textures are based off version of Wave engine sample * Take from https://github.com/WaveEngine/Samples * - * Copyright (c) 2022 Wave Coorporation + * Copyright (c) 2024 Wave Coorporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -88,9 +91,9 @@ Dali::Texture GetDiffuseTexture(Dali::Scene3D::Model model) if(renderer) { TextureSet textureSet = renderer.GetTextures(); - if(textureSet.GetTextureCount() == 9u) + if(textureSet.GetTextureCount() == 10u) { - texture = textureSet.GetTexture(7u); + texture = textureSet.GetTexture(8u); } } } @@ -109,9 +112,9 @@ Dali::Texture GetSpecularTexture(Dali::Scene3D::Model model) if(renderer) { TextureSet textureSet = renderer.GetTextures(); - if(textureSet.GetTextureCount() == 9u) + if(textureSet.GetTextureCount() == 10u) { - texture = textureSet.GetTexture(8u); + texture = textureSet.GetTexture(9u); } } } @@ -119,16 +122,15 @@ Dali::Texture GetSpecularTexture(Dali::Scene3D::Model model) return texture; } - // For ResourceReady static bool gOnRelayoutCallBackCalled = false; -void OnRelayoutCallback(Actor actor) +void OnRelayoutCallback(Actor actor) { gOnRelayoutCallBackCalled = true; } static bool gResourceReadyCalled = false; -void OnResourceReady(Control control) +void OnResourceReady(Control control) { gResourceReadyCalled = true; } @@ -314,24 +316,22 @@ int UtcDaliSceneViewOnScene02(void) { ToolkitTestApplication application; - uint32_t renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount(); - DALI_TEST_EQUALS(1u, renderTaskCount, TEST_LOCATION); + uint32_t baseRenderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount(); Scene3D::SceneView view = Scene3D::SceneView::New(); - renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount(); - DALI_TEST_EQUALS(1u, renderTaskCount, TEST_LOCATION); + uint32_t renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount(); + DALI_TEST_EQUALS(baseRenderTaskCount, renderTaskCount, TEST_LOCATION); application.GetScene().Add(view); application.SendNotification(); application.Render(); - renderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount(); - DALI_TEST_EQUALS(2u, renderTaskCount, TEST_LOCATION); + DALI_TEST_EQUALS(baseRenderTaskCount + 1u, renderTaskCount, TEST_LOCATION); - RenderTask renderTask = application.GetScene().GetRenderTaskList().GetTask(1u); + RenderTask renderTask = application.GetScene().GetRenderTaskList().GetTask(baseRenderTaskCount); CameraActor camera = renderTask.GetCameraActor(); CameraActor defaultCamera = renderTask.GetCameraActor(); @@ -460,8 +460,8 @@ int UtcDaliSceneViewImageBasedLight01(void) application.SendNotification(); application.Render(); - DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView2), 0.0f, TEST_LOCATION); - DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView2), 0.0f, TEST_LOCATION); + DALI_TEST_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView2), TEST_LOCATION); + DALI_TEST_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView2), TEST_LOCATION); DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), GetDiffuseTexture(modelView3), 0.0f, TEST_LOCATION); DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), GetSpecularTexture(modelView3), 0.0f, TEST_LOCATION); @@ -553,7 +553,7 @@ int UtcDaliSceneViewImageBasedLight02(void) DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION); - Dali::Texture diffuseTexture = GetDiffuseTexture(modelView1); + Dali::Texture diffuseTexture = GetDiffuseTexture(modelView1); Dali::Texture specularTexture = GetSpecularTexture(modelView1); gResourceReadyCalled = false; @@ -571,7 +571,7 @@ int UtcDaliSceneViewImageBasedLight02(void) DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), diffuseTexture, 0.0f, TEST_LOCATION); DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), specularTexture, 0.0f, TEST_LOCATION); - diffuseTexture = GetDiffuseTexture(modelView1); + diffuseTexture = GetDiffuseTexture(modelView1); specularTexture = GetSpecularTexture(modelView1); // reset SceneView IBL @@ -608,7 +608,7 @@ int UtcDaliSceneViewImageBasedLight03(void) application.SendNotification(); application.Render(); - Dali::Texture diffuseTexture = GetDiffuseTexture(modelView1); + Dali::Texture diffuseTexture = GetDiffuseTexture(modelView1); Dali::Texture specularTexture = GetSpecularTexture(modelView1); gResourceReadyCalled = false; @@ -629,7 +629,7 @@ int UtcDaliSceneViewImageBasedLight03(void) modelView1.SetImageBasedLightSource("", ""); DALI_TEST_NOT_EQUALS(GetDiffuseTexture(modelView1), diffuseTexture, 0.0f, TEST_LOCATION); DALI_TEST_NOT_EQUALS(GetSpecularTexture(modelView1), specularTexture, 0.0f, TEST_LOCATION); - diffuseTexture = GetDiffuseTexture(modelView1); + diffuseTexture = GetDiffuseTexture(modelView1); specularTexture = GetSpecularTexture(modelView1); // reset SceneView IBL @@ -687,6 +687,8 @@ int UtcDaliSceneViewUseFramebuffer02(void) { ToolkitTestApplication application; + uint32_t baseRenderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount(); + Scene3D::SceneView view = Scene3D::SceneView::New(); view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100)); @@ -695,7 +697,7 @@ int UtcDaliSceneViewUseFramebuffer02(void) application.SendNotification(); application.Render(); - RenderTask renderTask = application.GetScene().GetRenderTaskList().GetTask(1u); + RenderTask renderTask = application.GetScene().GetRenderTaskList().GetTask(baseRenderTaskCount); DALI_TEST_CHECK(!renderTask.GetFrameBuffer()); view.UseFramebuffer(true); @@ -710,13 +712,50 @@ int UtcDaliSceneViewUseFramebuffer02(void) END_TEST; } +int UtcDaliSceneViewFramebufferMultiSamplingLevel(void) +{ + ToolkitTestApplication application; + + Scene3D::SceneView view = Scene3D::SceneView::New(); + view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100)); + + application.GetScene().Add(view); + + application.SendNotification(); + application.Render(); + + uint8_t expectValue = 0u; // Default MultiSamplingLevel is 0. + uint8_t multiSamplingLevel = view.GetFramebufferMultiSamplingLevel(); + DALI_TEST_EQUALS(multiSamplingLevel, expectValue, TEST_LOCATION); + + expectValue = 4u; // Change value. + view.UseFramebuffer(true); + view.SetFramebufferMultiSamplingLevel(expectValue); + + multiSamplingLevel = view.GetFramebufferMultiSamplingLevel(); + DALI_TEST_EQUALS(multiSamplingLevel, expectValue, TEST_LOCATION); + + // Note : we don't check multi sampling level is applied to framebuffer, or not. + view.UseFramebuffer(false); + expectValue = 2u; // Change value. + view.SetFramebufferMultiSamplingLevel(expectValue); + + application.SendNotification(); + application.Render(); + + multiSamplingLevel = view.GetFramebufferMultiSamplingLevel(); + DALI_TEST_EQUALS(multiSamplingLevel, expectValue, TEST_LOCATION); + + END_TEST; +} + int UtcDaliSceneViewResourceReady(void) { ToolkitTestApplication application; gOnRelayoutCallBackCalled = false; - gResourceReadyCalled = false; - Scene3D::SceneView view = Scene3D::SceneView::New(); + gResourceReadyCalled = false; + Scene3D::SceneView view = Scene3D::SceneView::New(); view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f)); view.OnRelayoutSignal().Connect(OnRelayoutCallback); view.ResourceReadySignal().Connect(OnResourceReady); @@ -737,7 +776,7 @@ int UtcDaliSceneViewResourceReady(void) DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION); gOnRelayoutCallBackCalled = false; - gResourceReadyCalled = false; + gResourceReadyCalled = false; view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE); @@ -757,7 +796,7 @@ int UtcDaliSceneViewSetSkybox(void) { ToolkitTestApplication application; - gResourceReadyCalled = false; + gResourceReadyCalled = false; Scene3D::SceneView view = Scene3D::SceneView::New(); view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f)); view.ResourceReadySignal().Connect(OnResourceReady); @@ -792,7 +831,7 @@ int UtcDaliSceneViewSetSkyboxEquirectangular(void) { ToolkitTestApplication application; - gResourceReadyCalled = false; + gResourceReadyCalled = false; Scene3D::SceneView view = Scene3D::SceneView::New(); view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f)); view.ResourceReadySignal().Connect(OnResourceReady); @@ -802,7 +841,8 @@ int UtcDaliSceneViewSetSkyboxEquirectangular(void) application.Render(); uint32_t childCount = view.GetChildAt(0u).GetChildCount(); - view.SetSkybox(TEST_EQUIRECTANGULAR_TEXTURE, Scene3D::SceneView::SkyboxType::EQUIRECTANGULAR); + view.SetSkyboxEnvironmentMapType(Scene3D::EnvironmentMapType::EQUIRECTANGULAR); + view.SetSkybox(TEST_EQUIRECTANGULAR_TEXTURE); gResourceReadyCalled = false; DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION); @@ -827,7 +867,7 @@ int UtcDaliSceneViewSetSkyboxEmpty(void) { ToolkitTestApplication application; - gResourceReadyCalled = false; + gResourceReadyCalled = false; Scene3D::SceneView view = Scene3D::SceneView::New(); view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f)); view.ResourceReadySignal().Connect(OnResourceReady); @@ -846,11 +886,43 @@ int UtcDaliSceneViewSetSkyboxEmpty(void) END_TEST; } +int UtcDaliSceneViewSetSkyboxEmpty2(void) +{ + ToolkitTestApplication application; + + gResourceReadyCalled = false; + Scene3D::SceneView view = Scene3D::SceneView::New(); + view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f)); + view.ResourceReadySignal().Connect(OnResourceReady); + application.GetScene().Add(view); + + application.SendNotification(); + application.Render(); + + view.SetSkybox(TEST_EQUIRECTANGULAR_TEXTURE); + + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + application.SendNotification(); + application.Render(); + + uint32_t childCount = view.GetChildAt(0u).GetChildCount(); + + view.SetSkybox(""); + DALI_TEST_EQUALS(view.GetChildAt(0u).GetChildCount(), childCount - 1, TEST_LOCATION); + + view.Unparent(); + view.Reset(); + + END_TEST; +} + int UtcDaliSceneViewSetSkyboxEquirectangularEmpty(void) { ToolkitTestApplication application; - gResourceReadyCalled = false; + gResourceReadyCalled = false; Scene3D::SceneView view = Scene3D::SceneView::New(); view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f)); view.ResourceReadySignal().Connect(OnResourceReady); @@ -860,7 +932,7 @@ int UtcDaliSceneViewSetSkyboxEquirectangularEmpty(void) application.Render(); uint32_t childCount = view.GetChildAt(0u).GetChildCount(); - view.SetSkybox("", Scene3D::SceneView::SkyboxType::EQUIRECTANGULAR); + view.SetSkybox(""); DALI_TEST_EQUALS(view.GetChildAt(0u).GetChildCount(), childCount, TEST_LOCATION); view.Unparent(); @@ -926,22 +998,22 @@ int UtcDaliSceneViewSetImageBasedLightAndSkybox(void) int UtcDaliSceneViewCreateAndRemoveRenderTask(void) { ToolkitTestApplication application; - RenderTaskList taskList = application.GetScene().GetRenderTaskList(); + RenderTaskList taskList = application.GetScene().GetRenderTaskList(); - uint32_t renderTaskCount = taskList.GetTaskCount(); + uint32_t baseRenderTaskCount = taskList.GetTaskCount(); Scene3D::SceneView view = Scene3D::SceneView::New(); view.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f)); - DALI_TEST_EQUALS(renderTaskCount, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION); + DALI_TEST_EQUALS(baseRenderTaskCount, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION); application.GetScene().Add(view); - DALI_TEST_EQUALS(renderTaskCount + 1, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION); + DALI_TEST_EQUALS(baseRenderTaskCount + 1, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION); view.Unparent(); - DALI_TEST_EQUALS(renderTaskCount, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION); + DALI_TEST_EQUALS(baseRenderTaskCount, application.GetScene().GetRenderTaskList().GetTaskCount(), TEST_LOCATION); END_TEST; } @@ -965,3 +1037,457 @@ int UtcDaliSceneViewColorMode(void) END_TEST; } + +int UtcDaliSceneViewSetResolution(void) +{ + ToolkitTestApplication application; + + Scene3D::SceneView view = Scene3D::SceneView::New(); + application.GetScene().Add(view); + view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100)); + + DALI_TEST_EQUALS(view.GetResolutionWidth(), 100u, TEST_LOCATION); + DALI_TEST_EQUALS(view.GetResolutionHeight(), 100u, TEST_LOCATION); + + view.SetResolution(200u, 200u); + + DALI_TEST_EQUALS(view.GetResolutionWidth(), 100u, TEST_LOCATION); + DALI_TEST_EQUALS(view.GetResolutionHeight(), 100u, TEST_LOCATION); + + view.UseFramebuffer(true); + + DALI_TEST_EQUALS(view.GetResolutionWidth(), 200u, TEST_LOCATION); + DALI_TEST_EQUALS(view.GetResolutionHeight(), 200u, TEST_LOCATION); + + view.SetResolution(300u, 0u); + + DALI_TEST_EQUALS(view.GetResolutionWidth(), 100u, TEST_LOCATION); + DALI_TEST_EQUALS(view.GetResolutionHeight(), 100u, TEST_LOCATION); + + view.SetResolution(300u, 400u); + + DALI_TEST_EQUALS(view.GetResolutionWidth(), 300u, TEST_LOCATION); + DALI_TEST_EQUALS(view.GetResolutionHeight(), 400u, TEST_LOCATION); + + view.ResetResolution(); + + DALI_TEST_EQUALS(view.GetResolutionWidth(), 100u, TEST_LOCATION); + DALI_TEST_EQUALS(view.GetResolutionHeight(), 100u, TEST_LOCATION); + + view.SetProperty(Dali::Actor::Property::SIZE, Vector2(400, 400)); + + DALI_TEST_EQUALS(view.GetResolutionWidth(), 400u, TEST_LOCATION); + DALI_TEST_EQUALS(view.GetResolutionHeight(), 400u, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliSceneViewSetResolution02(void) +{ + tet_infoline("Test whether framebuffer created well base on inputed resolution"); + ToolkitTestApplication application; + RenderTaskList renderTaskList = application.GetScene().GetRenderTaskList(); + + uint32_t baseRenderTaskCount = renderTaskList.GetTaskCount(); + + Scene3D::SceneView view = Scene3D::SceneView::New(); + application.GetScene().Add(view); + view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100)); + + DALI_TEST_EQUALS(view.GetResolutionWidth(), 100u, TEST_LOCATION); + DALI_TEST_EQUALS(view.GetResolutionHeight(), 100u, TEST_LOCATION); + + uint32_t expectWidth = 83u; + uint32_t expectHeight = 207u; + + view.SetResolution(expectWidth, expectHeight); + + DALI_TEST_EQUALS(view.GetResolutionWidth(), 100u, TEST_LOCATION); + DALI_TEST_EQUALS(view.GetResolutionHeight(), 100u, TEST_LOCATION); + + tet_printf("Test Framebuffer result target created well\n"); + view.UseFramebuffer(true); + + RenderTask renderTask = renderTaskList.GetTask(baseRenderTaskCount); + DALI_TEST_CHECK(renderTask); + + FrameBuffer frameBuffer = renderTask.GetFrameBuffer(); + DALI_TEST_CHECK(frameBuffer); + + DALI_TEST_EQUALS(view.GetResolutionWidth(), expectWidth, TEST_LOCATION); + DALI_TEST_EQUALS(view.GetResolutionHeight(), expectHeight, TEST_LOCATION); + + Texture renderTargetTexture = frameBuffer.GetColorTexture(); + DALI_TEST_CHECK(renderTargetTexture); + DALI_TEST_EQUALS(renderTargetTexture.GetWidth(), expectWidth, TEST_LOCATION); + DALI_TEST_EQUALS(renderTargetTexture.GetHeight(), expectHeight, TEST_LOCATION); + + tet_printf("Test Framebuffer result target created well after create new FBO, by set multisampling level\n"); + view.SetFramebufferMultiSamplingLevel(2u); + + renderTask = renderTaskList.GetTask(baseRenderTaskCount); + DALI_TEST_CHECK(renderTask); + + frameBuffer = renderTask.GetFrameBuffer(); + DALI_TEST_CHECK(frameBuffer); + + DALI_TEST_EQUALS(view.GetResolutionWidth(), expectWidth, TEST_LOCATION); + DALI_TEST_EQUALS(view.GetResolutionHeight(), expectHeight, TEST_LOCATION); + + renderTargetTexture = frameBuffer.GetColorTexture(); + DALI_TEST_CHECK(renderTargetTexture); + + DALI_TEST_EQUALS(renderTargetTexture.GetWidth(), expectWidth, TEST_LOCATION); + DALI_TEST_EQUALS(renderTargetTexture.GetHeight(), expectHeight, TEST_LOCATION); + + tet_printf("Test Framebuffer result target created well after change resolution\n"); + expectWidth = 421u; + expectHeight = 103u; + view.SetResolution(expectWidth, expectHeight); + + renderTask = renderTaskList.GetTask(baseRenderTaskCount); + DALI_TEST_CHECK(renderTask); + + frameBuffer = renderTask.GetFrameBuffer(); + DALI_TEST_CHECK(frameBuffer); + + DALI_TEST_EQUALS(view.GetResolutionWidth(), expectWidth, TEST_LOCATION); + DALI_TEST_EQUALS(view.GetResolutionHeight(), expectHeight, TEST_LOCATION); + + renderTargetTexture = frameBuffer.GetColorTexture(); + DALI_TEST_CHECK(renderTargetTexture); + + DALI_TEST_EQUALS(renderTargetTexture.GetWidth(), expectWidth, TEST_LOCATION); + DALI_TEST_EQUALS(renderTargetTexture.GetHeight(), expectHeight, TEST_LOCATION); + + END_TEST; +} + +namespace +{ +const char* TEST_MASK_IMAGE_FILE_NAME = TEST_RESOURCE_DIR "/mask.png"; + +static constexpr std::string_view Y_FLIP_MASK_TEXTURE = "uYFlipMaskTexture"; +} // namespace + +int UtcDaliSceneViewMasking(void) +{ + ToolkitTestApplication application; + + Scene3D::SceneView view = Scene3D::SceneView::New(); + application.GetScene().Add(view); + + DALI_TEST_EQUALS(view.GetProperty(Dali::Scene3D::SceneView::Property::ALPHA_MASK_URL), "", TEST_LOCATION); + DALI_TEST_EQUALS(view.GetProperty(Dali::Scene3D::SceneView::Property::CROP_TO_MASK), true, TEST_LOCATION); + DALI_TEST_EQUALS(view.GetProperty(Dali::Scene3D::SceneView::Property::MASK_CONTENT_SCALE), 1.0f, TEST_LOCATION); + + auto yFlipMaskTextureIndex = view.GetPropertyIndex(Y_FLIP_MASK_TEXTURE.data()); + DALI_TEST_EQUALS(yFlipMaskTextureIndex, Property::INVALID_INDEX, TEST_LOCATION); + + view.UseFramebuffer(true); + view.SetProperty(Dali::Scene3D::SceneView::Property::ALPHA_MASK_URL, TEST_MASK_IMAGE_FILE_NAME); + view.SetProperty(Dali::Scene3D::SceneView::Property::CROP_TO_MASK, false); + view.SetProperty(Dali::Scene3D::SceneView::Property::MASK_CONTENT_SCALE, 0.5f); + + DALI_TEST_EQUALS(view.GetProperty(Dali::Scene3D::SceneView::Property::ALPHA_MASK_URL), TEST_MASK_IMAGE_FILE_NAME, TEST_LOCATION); + DALI_TEST_EQUALS(view.GetProperty(Dali::Scene3D::SceneView::Property::CROP_TO_MASK), false, TEST_LOCATION); + DALI_TEST_EQUALS(view.GetProperty(Dali::Scene3D::SceneView::Property::MASK_CONTENT_SCALE), 0.5f, TEST_LOCATION); + + yFlipMaskTextureIndex = view.GetPropertyIndex(std::string(Y_FLIP_MASK_TEXTURE)); + DALI_TEST_EQUALS(view.GetProperty(yFlipMaskTextureIndex), 1.0f, TEST_LOCATION); + + END_TEST; +} + +namespace +{ +static bool gCaptureFinishedCalled{false}; +static int32_t gCaptureId{-1}; +static Toolkit::ImageUrl gCapturedImageUrl; +static Scene3D::SceneView::CaptureFinishState gCaptureFinishState{Scene3D::SceneView::CaptureFinishState::FAILED}; + +void OnCaptureFinished(Scene3D::SceneView sceneView, Scene3D::SceneView::CaptureResult& captureResult) +{ + gCaptureFinishedCalled = true; + gCaptureId = captureResult.captureId; + gCapturedImageUrl = captureResult.imageUrl; + gCaptureFinishState = captureResult.state; +} + +static int32_t gCapturedCount{0}; +static std::vector gCaptureIds; +static std::vector gCapturedImageUrls; +static std::vector gCaptureFinishStates; + +void OnCaptureMultipleFinished(Scene3D::SceneView sceneView, Scene3D::SceneView::CaptureResult& captureResult) +{ + gCapturedCount++; + gCaptureIds.push_back(captureResult.captureId); + gCapturedImageUrls.push_back(captureResult.imageUrl); + gCaptureFinishStates.push_back(captureResult.state); +} +} // namespace + +int UtcDaliSceneViewCapture01(void) +{ + ToolkitTestApplication application; + + Scene3D::SceneView view = Scene3D::SceneView::New(); + view.CaptureFinishedSignal().Connect(OnCaptureFinished); + view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100)); + + application.GetScene().Add(view); + + application.SendNotification(); + application.Render(); + + Scene3D::Model modelView1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME); + view.Add(modelView1); + + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + application.SendNotification(); + application.Render(); + + CameraActor camera = Dali::CameraActor::New(); + camera.SetProperty(Dali::Actor::Property::NAME, "camera"); + camera.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + camera.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + camera.SetFieldOfView(0.5f); + camera.SetNearClippingPlane(1.0f); + camera.SetFarClippingPlane(5000.0f); + camera.SetProperty(Dali::Actor::Property::POSITION, Vector3(20, 30, 40)); + + view.Add(camera); + + gCaptureFinishedCalled = false; + gCaptureId = -1; + gCapturedImageUrl.Reset(); + gCaptureFinishState = Scene3D::SceneView::CaptureFinishState::FAILED; + int32_t captureId = view.Capture(camera, Vector2(300, 300)); + + application.SendNotification(); + application.Render(); + application.SendNotification(); + application.Render(); + application.SendNotification(); + + DALI_TEST_EQUALS(gCaptureFinishedCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(gCaptureId, captureId, TEST_LOCATION); + DALI_TEST_EQUALS(gCapturedImageUrl.GetUrl().empty(), false, TEST_LOCATION); + DALI_TEST_EQUALS(gCaptureFinishState, Scene3D::SceneView::CaptureFinishState::SUCCEEDED, TEST_LOCATION); + + Toolkit::ImageUrl tempImageUrl = gCapturedImageUrl; + + gCaptureFinishedCalled = false; + gCaptureId = -1; + gCapturedImageUrl.Reset(); + gCaptureFinishState = Scene3D::SceneView::CaptureFinishState::FAILED; + int32_t captureId2 = view.Capture(camera, Vector2(400, 400)); + + application.SendNotification(); + application.Render(); + application.SendNotification(); + application.Render(); + application.SendNotification(); + + DALI_TEST_EQUALS(gCaptureFinishedCalled, true, TEST_LOCATION); + DALI_TEST_NOT_EQUALS(captureId, captureId2, 0.1f, TEST_LOCATION); + DALI_TEST_EQUALS(gCaptureId, captureId2, TEST_LOCATION); + DALI_TEST_EQUALS(gCapturedImageUrl.GetUrl().empty(), false, TEST_LOCATION); + DALI_TEST_NOT_EQUALS(gCapturedImageUrl, tempImageUrl, 0.1f, TEST_LOCATION); + DALI_TEST_EQUALS(gCaptureFinishState, Scene3D::SceneView::CaptureFinishState::SUCCEEDED, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliSceneViewCaptureCancel(void) +{ + ToolkitTestApplication application; + + Scene3D::SceneView view = Scene3D::SceneView::New(); + view.CaptureFinishedSignal().Connect(OnCaptureFinished); + view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100)); + + application.GetScene().Add(view); + + application.SendNotification(); + application.Render(); + + Scene3D::Model modelView1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME); + view.Add(modelView1); + + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + application.SendNotification(); + application.Render(); + + CameraActor camera = Dali::CameraActor::New(); + camera.SetProperty(Dali::Actor::Property::NAME, "camera"); + camera.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + camera.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + camera.SetFieldOfView(0.5f); + camera.SetNearClippingPlane(1.0f); + camera.SetFarClippingPlane(5000.0f); + camera.SetProperty(Dali::Actor::Property::POSITION, Vector3(20, 30, 40)); + + view.Add(camera); + + gCaptureFinishedCalled = false; + gCaptureId = -1; + gCapturedImageUrl.Reset(); + gCaptureFinishState = Scene3D::SceneView::CaptureFinishState::FAILED; + int32_t captureId = view.Capture(camera, Vector2(300, 300)); + + view.Unparent(); + + DALI_TEST_EQUALS(gCaptureFinishedCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(gCaptureId, captureId, TEST_LOCATION); + DALI_TEST_EQUALS(!!gCapturedImageUrl, false, TEST_LOCATION); + DALI_TEST_EQUALS(gCaptureFinishState, Scene3D::SceneView::CaptureFinishState::FAILED, TEST_LOCATION); + + + gCaptureFinishedCalled = false; + gCaptureId = -1; + gCapturedImageUrl.Reset(); + gCaptureFinishState = Scene3D::SceneView::CaptureFinishState::FAILED; + + application.SendNotification(); + application.Render(); + application.SendNotification(); + application.Render(); + application.SendNotification(); + + DALI_TEST_EQUALS(gCaptureFinishedCalled, false, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliSceneViewCaptureFailed(void) +{ + ToolkitTestApplication application; + + Scene3D::SceneView view = Scene3D::SceneView::New(); + view.CaptureFinishedSignal().Connect(OnCaptureFinished); + view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100)); + + application.GetScene().Add(view); + + application.SendNotification(); + application.Render(); + + Scene3D::Model modelView1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME); + view.Add(modelView1); + + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + application.SendNotification(); + application.Render(); + + CameraActor camera = Dali::CameraActor::New(); + camera.SetProperty(Dali::Actor::Property::NAME, "camera"); + camera.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + camera.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + camera.SetFieldOfView(0.5f); + camera.SetNearClippingPlane(1.0f); + camera.SetFarClippingPlane(5000.0f); + camera.SetProperty(Dali::Actor::Property::POSITION, Vector3(20, 30, 40)); + + view.Add(camera); + + gCaptureFinishedCalled = false; + gCaptureId = -1; + gCapturedImageUrl.Reset(); + gCaptureFinishState = Scene3D::SceneView::CaptureFinishState::FAILED; + int32_t captureId = view.Capture(camera, Vector2(300, 300)); + + Test::EmitGlobalTimerSignal(); + Test::EmitGlobalTimerSignal(); + Test::EmitGlobalTimerSignal(); + + DALI_TEST_EQUALS(gCaptureFinishedCalled, true, TEST_LOCATION); + DALI_TEST_EQUALS(gCaptureId, captureId, TEST_LOCATION); + DALI_TEST_EQUALS(!!gCapturedImageUrl, false, TEST_LOCATION); + DALI_TEST_EQUALS(gCaptureFinishState, Scene3D::SceneView::CaptureFinishState::FAILED, TEST_LOCATION); + + gCaptureFinishedCalled = false; + gCaptureId = -1; + gCapturedImageUrl.Reset(); + gCaptureFinishState = Scene3D::SceneView::CaptureFinishState::FAILED; + + application.SendNotification(); + application.Render(); + application.SendNotification(); + application.Render(); + application.SendNotification(); + + DALI_TEST_EQUALS(gCaptureFinishedCalled, false, TEST_LOCATION); + + END_TEST; +} + +int UtcDaliSceneViewCapture02(void) +{ + ToolkitTestApplication application; + + Scene3D::SceneView view = Scene3D::SceneView::New(); + view.CaptureFinishedSignal().Connect(OnCaptureMultipleFinished); + view.SetProperty(Dali::Actor::Property::SIZE, Vector2(100, 100)); + + application.GetScene().Add(view); + + application.SendNotification(); + application.Render(); + + Scene3D::Model modelView1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME); + view.Add(modelView1); + + application.SendNotification(); + application.Render(); + DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION); + application.SendNotification(); + application.Render(); + + CameraActor camera = Dali::CameraActor::New(); + camera.SetProperty(Dali::Actor::Property::NAME, "camera"); + camera.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER); + camera.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER); + camera.SetFieldOfView(0.5f); + camera.SetNearClippingPlane(1.0f); + camera.SetFarClippingPlane(5000.0f); + camera.SetProperty(Dali::Actor::Property::POSITION, Vector3(20, 30, 40)); + + view.Add(camera); + + gCapturedCount = 0; + gCaptureIds.clear(); + gCapturedImageUrls.clear(); + gCaptureFinishStates.clear(); + int32_t captureId = view.Capture(camera, Vector2(300, 300)); + int32_t captureId2 = view.Capture(camera, Vector2(300, 300)); + + application.SendNotification(); + application.Render(); + application.SendNotification(); + application.Render(); + application.SendNotification(); + + DALI_TEST_EQUALS(gCapturedCount, 2, TEST_LOCATION); + DALI_TEST_EQUALS(gCaptureIds.size(), 2, TEST_LOCATION); + auto idIter1 = std::find(gCaptureIds.begin(), gCaptureIds.end(), captureId); + bool isIter1 = idIter1 != gCaptureIds.end(); + DALI_TEST_EQUALS(isIter1, true, TEST_LOCATION); + auto idIter2 = std::find(gCaptureIds.begin(), gCaptureIds.end(), captureId2); + bool isIter2 = idIter2 != gCaptureIds.end(); + DALI_TEST_EQUALS(isIter2, true, TEST_LOCATION); + + DALI_TEST_EQUALS(gCapturedImageUrls.size(), 2, TEST_LOCATION); + DALI_TEST_NOT_EQUALS(gCapturedImageUrls[0], gCapturedImageUrls[1], 0.1f, TEST_LOCATION); + DALI_TEST_EQUALS(gCaptureFinishStates[0], Scene3D::SceneView::CaptureFinishState::SUCCEEDED, TEST_LOCATION); + DALI_TEST_EQUALS(gCaptureFinishStates[1], Scene3D::SceneView::CaptureFinishState::SUCCEEDED, TEST_LOCATION); + + END_TEST; +} \ No newline at end of file