From: sunghyun kim Date: Fri, 29 Apr 2022 06:58:41 +0000 (+0000) Subject: Merge "Fix webp&gif issue" into devel/master X-Git-Tag: dali_2.1.21~8 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=38f0ea9fcdf1dc5037144fa19c8a52316c8af763;hp=8031d58099c45584640676693f4b904e81008081 Merge "Fix webp&gif issue" into devel/master --- diff --git a/automated-tests/resources/coverageTest.bin b/automated-tests/resources/coverageTest.bin new file mode 100644 index 0000000..1d0e3d6 Binary files /dev/null and b/automated-tests/resources/coverageTest.bin differ diff --git a/automated-tests/resources/coverageTest.dli b/automated-tests/resources/coverageTest.dli new file mode 100644 index 0000000..a380378 --- /dev/null +++ b/automated-tests/resources/coverageTest.dli @@ -0,0 +1,82 @@ +{ + "asset": { "version": "1.0" }, + "scene": 0, + "scenes": [ { "nodes": [ 0 ] } ], + "nodes": [ + { + "name": "root", + "matrix": [ 0.2, 0, 0, 0, 0, -0, 0.2, 0, 0, -0.2, -0, 0, 0, 0, 0, 1 ], + "model": { + "mesh": 0, + "material": 0 + } + } + ], + "meshes": [ + { + "uri": "coverageTest.bin", + "attributes": 31, + "primitive": "TRIANGLES", + "indices": { "byteOffset": 0, "byteLength": 600 }, + "positions": { "byteOffset": 600, "byteLength": 2364 }, + "normals": { "byteOffset": 2964, "byteLength": 2364 }, + "textures": { "byteOffset": 5328, "byteLength": 1576 }, + "tangents": { "byteOffset": 6904, "byteLength": 2364 } + } + ], + "skeletons": [ + ], + "cameras": [ + { + "fov": 60, + "near": 0.1, + "far": 100, + "matrix": [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 3.5, 1 ] + } + ], + "materials": [ + { + "name": "material1", + "color": [ 1, 1, 0, 1 ], + "roughness": 0.4, + "metallic": 0, + "occlusionMap": "exercise/Icons/Icon_Idle.png", + "mipmap": true, + "environment" : 1 + }, + { + "name": "", + "color": [ 1, 1, 1, 1 ], + "roughness": 1, + "metallic": 1, + "mipmap": true + } + ], + "lights" : [ { + "matrix" : [ 0.8950600624084473, 0.0914330929517746, 0.4364715814590454, 0.0, 0.3676385283470154, 0.4026888310909271, -0.8382623195648193, 0.0, -0.25240713357925415, 0.9107588529586792, 0.3268163800239563, 0.0, 0.0, 0.0, -1.0, 1.0 ], + "color" : [ 0.8, 0.8, 0.8 ], + "intensity" : 1.0, + "shadowMapSize" : 256, + "orthographicSize" : 4.2760005, + "shadowIntensity" : 1.0 + } ], + "environment" : [ { + "cubeInitialOrientation" : [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ], + "iblIntensity" : 1.0 + }, { + "cubeSpecular" : "Studio/Radiance.ktx", + "cubeDiffuse" : "Studio/Irradiance.ktx", + "cubeInitialOrientation" : [ 0.6716271638870239, 0.07979151606559753, -0.7365801334381104, 0.0, 0.07979151606559753, 0.9806114435195923, 0.17898204922676086, 0.0, 0.7365801334381104, -0.17898204922676086, 0.6522386074066162, 0.0, 0.0, 0.0, 0.0, 1.0 ], + "iblIntensity" : 0.75 + } ], + "shaders": [ + { + "vertex": "dli_pbr.vsh", + "fragment": "dli_pbr.fsh", + "defines" : [ "OCCLUSION", "DISPLACEMENT" ], + "rendererState": "DEPTH_TEST|DEPTH_WRITE|CULL_BACK|DEPTH_FUNC:LESS_EQUAL", + "uCubeMatrix": [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ], + "uMaxLOD": 6 + } + ] +} diff --git a/automated-tests/resources/dli_pbr.fsh b/automated-tests/resources/dli_pbr.fsh index 72a0d31..6a961d2 100644 --- a/automated-tests/resources/dli_pbr.fsh +++ b/automated-tests/resources/dli_pbr.fsh @@ -31,6 +31,10 @@ uniform sampler2D sNormalRoughness; #endif +#ifdef OCCLUSION + uniform sampler2D sAmbientOcclusion; +#endif //OCCLUSION + uniform samplerCube sDiffuse; uniform samplerCube sSpecular; @@ -152,6 +156,11 @@ void main() vec3 finalColor = diffuseColor + specColor; finalColor = sqrt( finalColor ) * uIblIntensity; + +#ifdef OCCLUSION + finalColor *= texture(sAmbientOcclusion, vUV.st).r; +#endif //OCCLUSION + #ifdef THREE_TEX FragColor = vec4( finalColor, alpha ); #else //THREE_TEX diff --git a/automated-tests/src/dali-scene-loader/utc-Dali-DliLoader.cpp b/automated-tests/src/dali-scene-loader/utc-Dali-DliLoader.cpp index d09d2da..b63df36 100644 --- a/automated-tests/src/dali-scene-loader/utc-Dali-DliLoader.cpp +++ b/automated-tests/src/dali-scene-loader/utc-Dali-DliLoader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 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. @@ -18,32 +18,30 @@ // Enable debug log for test coverage #define DEBUG_ENABLED 1 +#include +#include +#include "dali-scene-loader/internal/json-util.h" #include "dali-scene-loader/public-api/dli-loader.h" +#include "dali-scene-loader/public-api/load-result.h" #include "dali-scene-loader/public-api/resource-bundle.h" #include "dali-scene-loader/public-api/scene-definition.h" -#include "dali-scene-loader/public-api/load-result.h" -#include "dali-scene-loader/internal/json-util.h" -#include -#include using namespace Dali; using namespace Dali::SceneLoader; namespace { - -void ConfigureBlendShapeShaders(ResourceBundle& resources, const SceneDefinition& scene, Actor root, - std::vector&& requests) +void ConfigureBlendShapeShaders(ResourceBundle& resources, const SceneDefinition& scene, Actor root, std::vector&& requests) { std::vector errors; - auto onError = [&errors](const std::string& msg) { + auto onError = [&errors](const std::string& msg) { errors.push_back(msg); }; - if (!scene.ConfigureBlendshapeShaders(resources, root, std::move(requests), onError)) + if(!scene.ConfigureBlendshapeShaders(resources, root, std::move(requests), onError)) { ExceptionFlinger flinger(ASSERT_LOCATION); - for (auto& msg : errors) + for(auto& msg : errors) { flinger << msg << '\n'; } @@ -56,33 +54,32 @@ struct Context return TEST_RESOURCE_DIR "/"; }; - ResourceBundle resources; - SceneDefinition scene; - std::vector cameraParameters; - std::vector lights; - std::vector animations; + ResourceBundle resources; + SceneDefinition scene; + std::vector cameraParameters; + std::vector lights; + std::vector animations; std::vector animGroups; - LoadResult output { + LoadResult output{ resources, scene, animations, animGroups, cameraParameters, - lights - }; + lights}; - DliLoader::InputParams input { + DliLoader::InputParams input{ pathProvider(ResourceType::Mesh), nullptr, {}, {}, nullptr, }; - DliLoader::LoadParams loadParams{ input, output }; + DliLoader::LoadParams loadParams{input, output}; std::vector errors; - DliLoader loader; + DliLoader loader; StringCallback onError = [this](const std::string& error) { errors.push_back(error); @@ -97,7 +94,7 @@ struct Context bool StringHasTokens(const char* string, const std::vector& tokens) { - for (auto& token: tokens) + for(auto& token : tokens) { auto result = strstr(string, token); if(nullptr == result) @@ -109,7 +106,7 @@ bool StringHasTokens(const char* string, const std::vector& tokens) return true; } -} +} // namespace int UtcDaliDliLoaderLoadSceneNotFound(void) { @@ -118,7 +115,7 @@ int UtcDaliDliLoaderLoadSceneNotFound(void) DALI_TEST_EQUAL(ctx.loader.LoadScene("does_not_exist.dli", ctx.loadParams), false); auto error = ctx.loader.GetParseError(); - DALI_TEST_CHECK(StringHasTokens(error.c_str(), { "Empty source buffer to parse." })); + DALI_TEST_CHECK(StringHasTokens(error.c_str(), {"Empty source buffer to parse."})); END_TEST; } @@ -131,49 +128,48 @@ int UtcDaliDliLoaderLoadSceneFailParse(void) DALI_TEST_EQUAL(ctx.loader.LoadScene(path, ctx.loadParams), false); auto error = ctx.loader.GetParseError(); - DALI_TEST_CHECK(StringHasTokens(error.c_str(), { "Unexpected character." })); + DALI_TEST_CHECK(StringHasTokens(error.c_str(), {"Unexpected character."})); END_TEST; } int UtcDaliDliLoaderLoadSceneAssertions(void) { - const std::pair pathExceptionPairs[] { - // from RequireChild() - { "scenes-nodes-missing", "Failed to find child node" }, - { "scenes-missing", "Failed to find child node" }, - { "nodes-missing", "Failed to find child node" }, + const std::pair pathExceptionPairs[]{ + // from RequireChild() + {"scenes-nodes-missing", "Failed to find child node"}, + {"scenes-missing", "Failed to find child node"}, + {"nodes-missing", "Failed to find child node"}, // from ParseSceneInternal() - { "scene-out-of-bounds", "out of bounds" }, - { "nodes-invalid-type", "invalid type; array required" }, - { "nodes-array-empty", "must define a node id" }, - { "root-id-invalid", "invalid value for root node index" }, - { "root-id-out-of-bounds", "out of bounds" }, - { "root-node-invalid-type", "invalid JSON type; object required" }, + {"scene-out-of-bounds", "out of bounds"}, + {"nodes-invalid-type", "invalid type; array required"}, + {"nodes-array-empty", "must define a node id"}, + {"root-id-invalid", "invalid value for root node index"}, + {"root-id-out-of-bounds", "out of bounds"}, + {"root-node-invalid-type", "invalid JSON type; object required"}, // from ParseSkeletons() - { "skeleton-node-missing", "Missing required attribute" }, - { "skeleton-root-not-found", "not defined" }, + {"skeleton-node-missing", "Missing required attribute"}, + {"skeleton-root-not-found", "not defined"}, // from ParseShaders() - { "shader-vertex-missing", "Missing vertex / fragment shader" }, - { "shader-fragment-missing", "Missing vertex / fragment shader" }, + {"shader-vertex-missing", "Missing vertex / fragment shader"}, + {"shader-fragment-missing", "Missing vertex / fragment shader"}, // from ParseMeshes() - { "mesh-uri-missing", "Missing required attribute" }, - { "mesh-indices-read-fail", "Failed to read indices" }, - { "mesh-positions-read-fail", "Failed to read positions" }, + {"mesh-uri-missing", "Missing required attribute"}, + {"mesh-indices-read-fail", "Failed to read indices"}, + {"mesh-positions-read-fail", "Failed to read positions"}, // from ParseMaterials() - { "material-environment-out-of-bounds", "out of bounds" }, + {"material-environment-out-of-bounds", "out of bounds"}, // from ParseNodes() - { "node-model-mesh-missing", "Missing mesh" }, - { "node-arc-mesh-missing", "Missing mesh" }, - { "node-animated-image-mesh-missing", "Missing mesh" }, - { "node-renderable-mesh-invalid-type", "Invalid Mesh index type" }, - { "node-renderable-mesh-out-of-bounds", "out of bounds" }, - { "node-child-invalid-type", "invalid index type" }, - { "node-name-already-used", "name already used" }, + {"node-model-mesh-missing", "Missing mesh"}, + {"node-arc-mesh-missing", "Missing mesh"}, + {"node-animated-image-mesh-missing", "Missing mesh"}, + {"node-renderable-mesh-invalid-type", "Invalid Mesh index type"}, + {"node-renderable-mesh-out-of-bounds", "out of bounds"}, + {"node-child-invalid-type", "invalid index type"}, + {"node-name-already-used", "name already used"}, // from ParseAnimations() - { "animation-failed-to-open", "Failed to open animation data" } - }; - for (auto& i: pathExceptionPairs) + {"animation-failed-to-open", "Failed to open animation data"}}; + for(auto& i : pathExceptionPairs) { Context ctx; @@ -214,10 +210,9 @@ int UtcDaliDliLoaderLoadSceneExercise(void) DALI_TEST_EQUAL(ctx.animGroups.size(), 16u); ViewProjection viewProjection; - Transforms xforms { + Transforms xforms{ MatrixStack{}, - viewProjection - }; + viewProjection}; NodeDefinition::CreateParams nodeParams{ resources, xforms, @@ -229,13 +224,13 @@ int UtcDaliDliLoaderLoadSceneExercise(void) Actor root = Actor::New(); SetActorCentered(root); - for (auto iRoot : scene.GetRoots()) + for(auto iRoot : scene.GetRoots()) { auto resourceRefs = resources.CreateRefCounter(); scene.CountResourceRefs(iRoot, choices, resourceRefs); resources.CountEnvironmentReferences(resourceRefs); resources.LoadResources(resourceRefs, ctx.pathProvider); - if (auto actor = scene.CreateNodes(iRoot, choices, nodeParams)) + if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams)) { scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor); scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables)); @@ -257,49 +252,47 @@ int UtcDaliDliLoaderLoadSceneMorph(void) Context ctx; std::vector metadata; - uint32_t metadataCount = 0; - ctx.input.mPreNodeCategoryProcessors.push_back({ "metadata", - [&](const Property::Array& array, StringCallback) { - std::string key, value; - for (uint32_t i0 = 0, i1 = array.Count(); i0 < i1; ++i0) - { - auto& data = array.GetElementAt(i0); - DALI_TEST_EQUAL(data.GetType(), Property::MAP); - - auto map = data.GetMap(); - auto key = map->Find("key"); - auto value = map->Find("value"); - DALI_TEST_EQUAL(key->GetType(), Property::STRING); - DALI_TEST_EQUAL(value->GetType(), Property::STRING); - metadata.push_back(key->Get() + ":" + value->Get()); - - ++metadataCount; - } - } - }); + uint32_t metadataCount = 0; + ctx.input.mPreNodeCategoryProcessors.push_back({"metadata", + [&](const Property::Array& array, StringCallback) { + std::string key, value; + for(uint32_t i0 = 0, i1 = array.Count(); i0 < i1; ++i0) + { + auto& data = array.GetElementAt(i0); + DALI_TEST_EQUAL(data.GetType(), Property::MAP); + + auto map = data.GetMap(); + auto key = map->Find("key"); + auto value = map->Find("value"); + DALI_TEST_EQUAL(key->GetType(), Property::STRING); + DALI_TEST_EQUAL(value->GetType(), Property::STRING); + metadata.push_back(key->Get() + ":" + value->Get()); + + ++metadataCount; + } + }}); std::vector behaviors; - uint32_t behaviorCount = 0; - ctx.input.mPostNodeCategoryProcessors.push_back({ "behaviors", - [&](const Property::Array& array, StringCallback) { - for (uint32_t i0 = 0, i1 = array.Count(); i0 < i1; ++i0) - { - auto& data = array.GetElementAt(i0); - DALI_TEST_EQUAL(data.GetType(), Property::MAP); - - auto map = data.GetMap(); - auto event = map->Find("event"); - auto url = map->Find("url"); - DALI_TEST_EQUAL(event->GetType(), Property::STRING); - DALI_TEST_EQUAL(url->GetType(), Property::STRING); - behaviors.push_back(event->Get() + ":" + url->Get()); - - ++behaviorCount; - } - } - }); - - size_t numNodes = 0; + uint32_t behaviorCount = 0; + ctx.input.mPostNodeCategoryProcessors.push_back({"behaviors", + [&](const Property::Array& array, StringCallback) { + for(uint32_t i0 = 0, i1 = array.Count(); i0 < i1; ++i0) + { + auto& data = array.GetElementAt(i0); + DALI_TEST_EQUAL(data.GetType(), Property::MAP); + + auto map = data.GetMap(); + auto event = map->Find("event"); + auto url = map->Find("url"); + DALI_TEST_EQUAL(event->GetType(), Property::STRING); + DALI_TEST_EQUAL(url->GetType(), Property::STRING); + behaviors.push_back(event->Get() + ":" + url->Get()); + + ++behaviorCount; + } + }}); + + size_t numNodes = 0; ctx.input.mNodePropertyProcessor = [&](const NodeDefinition&, const Property::Map&, StringCallback) { ++numNodes; }; @@ -332,10 +325,9 @@ int UtcDaliDliLoaderLoadSceneMorph(void) DALI_TEST_EQUAL(behaviors.size(), 1u); ViewProjection viewProjection; - Transforms xforms { + Transforms xforms{ MatrixStack{}, - viewProjection - }; + viewProjection}; NodeDefinition::CreateParams nodeParams{ resources, xforms, @@ -347,13 +339,13 @@ int UtcDaliDliLoaderLoadSceneMorph(void) Actor root = Actor::New(); SetActorCentered(root); - for (auto iRoot : scene.GetRoots()) + for(auto iRoot : scene.GetRoots()) { auto resourceRefs = resources.CreateRefCounter(); scene.CountResourceRefs(iRoot, choices, resourceRefs); resources.CountEnvironmentReferences(resourceRefs); resources.LoadResources(resourceRefs, ctx.pathProvider); - if (auto actor = scene.CreateNodes(iRoot, choices, nodeParams)) + if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams)) { scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor); scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables)); @@ -397,10 +389,9 @@ int UtcDaliDliLoaderLoadSceneArc(void) DALI_TEST_EQUAL(ctx.animGroups.size(), 0u); ViewProjection viewProjection; - Transforms xforms { + Transforms xforms{ MatrixStack{}, - viewProjection - }; + viewProjection}; NodeDefinition::CreateParams nodeParams{ resources, xforms, @@ -412,13 +403,13 @@ int UtcDaliDliLoaderLoadSceneArc(void) Actor root = Actor::New(); SetActorCentered(root); - for (auto iRoot : scene.GetRoots()) + for(auto iRoot : scene.GetRoots()) { auto resourceRefs = resources.CreateRefCounter(); scene.CountResourceRefs(iRoot, choices, resourceRefs); resources.CountEnvironmentReferences(resourceRefs); resources.LoadResources(resourceRefs, ctx.pathProvider); - if (auto actor = scene.CreateNodes(iRoot, choices, nodeParams)) + if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams)) { scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor); scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables)); @@ -496,11 +487,10 @@ int UtcDaliDliLoaderLoadSceneExtras(void) DALI_TEST_EQUAL(scene.GetNodeCount(), 1u); ViewProjection viewProjection; - Transforms xforms { + Transforms xforms{ MatrixStack{}, - viewProjection - }; - auto& resources = ctx.resources; + viewProjection}; + auto& resources = ctx.resources; NodeDefinition::CreateParams nodeParams{ resources, xforms, @@ -509,7 +499,7 @@ int UtcDaliDliLoaderLoadSceneExtras(void) Customization::Choices choices; TestApplication app; - Actor actor = scene.CreateNodes(0, choices, nodeParams); + Actor actor = scene.CreateNodes(0, choices, nodeParams); DALI_TEST_EQUAL(actor.GetProperty(actor.GetPropertyIndex("fudgeFactor")).Get(), 9000.1f); DALI_TEST_EQUAL(actor.GetProperty(actor.GetPropertyIndex("fudgeVector")).Get(), Vector2(-.25f, 17.f)); @@ -541,11 +531,10 @@ int UtcDaliDliLoaderLoadSceneConstraints(void) DALI_TEST_EQUAL(scene.GetNodeCount(), 4u); ViewProjection viewProjection; - Transforms xforms { + Transforms xforms{ MatrixStack{}, - viewProjection - }; - auto& resources = ctx.resources; + viewProjection}; + auto& resources = ctx.resources; NodeDefinition::CreateParams nodeParams{ resources, xforms, @@ -555,9 +544,9 @@ int UtcDaliDliLoaderLoadSceneConstraints(void) TestApplication app; - Actor root = scene.CreateNodes(0, choices, nodeParams); - Actor alice = root.FindChildByName("Alice"); - Actor bob = root.FindChildByName("Bob"); + Actor root = scene.CreateNodes(0, choices, nodeParams); + Actor alice = root.FindChildByName("Alice"); + Actor bob = root.FindChildByName("Bob"); Actor charlie = root.FindChildByName("Charlie"); DALI_TEST_EQUAL(nodeParams.mConstrainables.size(), 3u); @@ -639,3 +628,78 @@ int UtcDaliDliLoaderNodeProcessor(void) END_TEST; } + +int UtcDaliDliLoaderLoadCoverageTest(void) +{ + Context ctx; + + auto path = ctx.pathProvider(ResourceType::Mesh) + "coverageTest.dli"; + DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams)); + DALI_TEST_CHECK(ctx.errors.empty()); + + auto& scene = ctx.scene; + auto& roots = scene.GetRoots(); + DALI_TEST_EQUAL(roots.size(), 1u); + DALI_TEST_EQUAL(scene.GetNode(roots[0])->mName, "root"); + + DALI_TEST_EQUAL(scene.GetNodeCount(), 1u); + + auto& resources = ctx.resources; + DALI_TEST_EQUAL(resources.mMeshes.size(), 1u); + DALI_TEST_EQUAL(resources.mShaders.size(), 1u); + DALI_TEST_EQUAL(resources.mEnvironmentMaps.size(), 2u); + DALI_TEST_EQUAL(resources.mSkeletons.size(), 0u); + + auto& materials = ctx.resources.mMaterials; + DALI_TEST_EQUAL(2u, materials.size()); + + auto iMaterial = materials.begin(); + auto& md = iMaterial->first; + DALI_TEST_EQUAL(md.mTextureStages.size(), 1u); + + auto iTexture = md.mTextureStages.begin(); + DALI_TEST_CHECK(MaskMatch(iTexture->mSemantic, MaterialDefinition::OCCLUSION)); + DALI_TEST_EQUAL(iTexture->mTexture.mImageUri, "exercise/Icons/Icon_Idle.png"); + ++iTexture; + + DALI_TEST_EQUAL(ctx.cameraParameters.size(), 1u); + DALI_TEST_EQUAL(ctx.lights.size(), 1u); + DALI_TEST_EQUAL(ctx.animations.size(), 0u); + DALI_TEST_EQUAL(ctx.animGroups.size(), 0u); + + ViewProjection viewProjection; + Transforms xforms{ + MatrixStack{}, + viewProjection}; + NodeDefinition::CreateParams nodeParams{ + resources, + xforms, + }; + + Customization::Choices choices; + + TestApplication app; + + Actor root = Actor::New(); + SetActorCentered(root); + for(auto iRoot : scene.GetRoots()) + { + auto resourceRefs = resources.CreateRefCounter(); + scene.CountResourceRefs(iRoot, choices, resourceRefs); + resources.CountEnvironmentReferences(resourceRefs); + resources.LoadResources(resourceRefs, ctx.pathProvider); + if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams)) + { + scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor); + scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables)); + ConfigureBlendShapeShaders(resources, scene, actor, std::move(nodeParams.mBlendshapeRequests)); + scene.ApplyConstraints(actor, std::move(nodeParams.mConstrainables)); + root.Add(actor); + } + } + + DALI_TEST_EQUAL(root.GetChildCount(), 1u); + DALI_TEST_EQUAL(root.GetChildAt(0).GetProperty(Actor::Property::NAME).Get(), "root"); + + END_TEST; +} diff --git a/automated-tests/src/dali-scene-loader/utc-Dali-Gltf2Loader.cpp b/automated-tests/src/dali-scene-loader/utc-Dali-Gltf2Loader.cpp index 47515b3..b4dceb9 100644 --- a/automated-tests/src/dali-scene-loader/utc-Dali-Gltf2Loader.cpp +++ b/automated-tests/src/dali-scene-loader/utc-Dali-Gltf2Loader.cpp @@ -167,12 +167,15 @@ int UtcDaliGltfLoaderSuccess1(void) DALI_TEST_EQUAL(2u, materials.size()); const MaterialDefinition materialGroundTruth[]{ {MaterialDefinition::ALBEDO | MaterialDefinition::METALLIC | MaterialDefinition::ROUGHNESS | + MaterialDefinition::EMISSIVE | MaterialDefinition::OCCLUSION | MaterialDefinition::NORMAL | MaterialDefinition::TRANSPARENCY | MaterialDefinition::GLTF_CHANNELS | (0x80 << MaterialDefinition::ALPHA_CUTOFF_SHIFT), 0, Vector4(1.f, .766f, .336f, 1.f), + Vector3(0.2, 0.1, 0.0), 1.f, 0.f, + 1.f, { {MaterialDefinition::ALBEDO, {"AnimatedCube_BaseColor.png", @@ -183,13 +186,22 @@ int UtcDaliGltfLoaderSuccess1(void) {MaterialDefinition::NORMAL, {"AnimatedCube_BaseColor.png", SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT)}}, + {MaterialDefinition::OCCLUSION, + {"AnimatedCube_BaseColor.png", + SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT)}}, + {MaterialDefinition::EMISSIVE, + {"AnimatedCube_BaseColor.png", + SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT)}}, }}, {MaterialDefinition::ALBEDO | MaterialDefinition::METALLIC | MaterialDefinition::ROUGHNESS | + MaterialDefinition::EMISSIVE | MaterialDefinition::OCCLUSION | MaterialDefinition::NORMAL | MaterialDefinition::GLTF_CHANNELS, 0, Vector4(1.f, .766f, .336f, 1.f), + Vector3(0.2, 0.1, 0.0), 1.f, 0.f, + 1.f, { {MaterialDefinition::ALBEDO, {"AnimatedCube_BaseColor.png", @@ -200,6 +212,12 @@ int UtcDaliGltfLoaderSuccess1(void) {MaterialDefinition::NORMAL, {"AnimatedCube_BaseColor.png", SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT)}}, + {MaterialDefinition::OCCLUSION, + {"AnimatedCube_BaseColor.png", + SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT)}}, + {MaterialDefinition::EMISSIVE, + {"AnimatedCube_BaseColor.png", + SamplerFlags::Encode(FilterMode::LINEAR_MIPMAP_LINEAR, FilterMode::LINEAR, WrapMode::CLAMP_TO_EDGE, WrapMode::REPEAT)}}, }}, }; diff --git a/automated-tests/src/dali-scene-loader/utc-Dali-ShaderDefinitionFactory.cpp b/automated-tests/src/dali-scene-loader/utc-Dali-ShaderDefinitionFactory.cpp index c1b5481..3fd8fbb 100644 --- a/automated-tests/src/dali-scene-loader/utc-Dali-ShaderDefinitionFactory.cpp +++ b/automated-tests/src/dali-scene-loader/utc-Dali-ShaderDefinitionFactory.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 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. @@ -18,25 +18,19 @@ // Enable debug log for test coverage #define DEBUG_ENABLED 1 +#include +#include +#include #include "dali-scene-loader/public-api/gltf2-loader.h" -#include "dali-scene-loader/public-api/shader-definition-factory.h" #include "dali-scene-loader/public-api/node-definition.h" #include "dali-scene-loader/public-api/resource-bundle.h" -#include -#include -#include +#include "dali-scene-loader/public-api/shader-definition-factory.h" using namespace Dali; using namespace Dali::SceneLoader; namespace { - -bool EndsWith(const std::string& str, const std::string& suffix) // ends_width() is C++20 -{ - return str.size() >= suffix.size() && str.substr(str.size() - suffix.size()).compare(suffix) == 0; -} - MaterialDefinition& NewMaterialDefinition(ResourceBundle& resources) { resources.mMaterials.push_back({}); @@ -57,7 +51,7 @@ void ClearMeshesAndMaterials(ResourceBundle& resources) struct Context { - ResourceBundle resources; + ResourceBundle resources; ShaderDefinitionFactory factory; Context() @@ -68,29 +62,29 @@ struct Context struct ShaderParameters { - MeshDefinition& meshDef; + MeshDefinition& meshDef; MaterialDefinition& materialDef; - NodeDefinition& nodeDef; + NodeDefinition& nodeDef; }; struct Permutation { - using ConfigureFn = void(*)(ShaderParameters&); + using ConfigureFn = void (*)(ShaderParameters&); ConfigureFn configureFn; std::set defines; - RendererState::Type rendererStateSet = 0; - RendererState::Type rendererStateClear = 0; + RendererState::Type rendererStateSet = 0; + RendererState::Type rendererStateClear = 0; }; struct PermutationSet { std::vector permutations; - Index shaderIdx; + Index shaderIdx; }; -} +} // namespace int UtcDaliShaderDefinitionFactoryProduceShaderInvalid(void) { @@ -121,173 +115,157 @@ int UtcDaliShaderDefinitionFactoryProduceShader(void) [](ShaderParameters& p) { p.materialDef.mFlags |= MaterialDefinition::TRANSPARENCY; }, - { "THREE_TEX" }, + {"THREE_TEX"}, RendererState::ALPHA_BLEND, RendererState::DEPTH_WRITE, }, - { - [](ShaderParameters& p) { - p.materialDef.mTextureStages.push_back({ MaterialDefinition::ALBEDO, {} }); - }, - { "THREE_TEX" } - }, - { - [](ShaderParameters& p) { - p.materialDef.mTextureStages.push_back({ MaterialDefinition::METALLIC | MaterialDefinition::ROUGHNESS, {} }); - }, - { "THREE_TEX" } - }, - { - [](ShaderParameters& p) { - p.materialDef.mTextureStages.push_back({ MaterialDefinition::NORMAL, {} }); - }, - { "THREE_TEX" } - }, - { - [](ShaderParameters& p) { - p.materialDef.mFlags |= MaterialDefinition::SUBSURFACE; - }, - { "SSS" } - }, - { - [](ShaderParameters& p) { - p.materialDef.SetAlphaCutoff(.5f); - }, - { "ALPHA_TEST" } - }, - { - [](ShaderParameters& p) { - p.materialDef.SetAlphaCutoff(1.f); - }, - { "ALPHA_TEST" } - }, - { - [](ShaderParameters& p) { - p.materialDef.mFlags |= MaterialDefinition::GLTF_CHANNELS; - }, - { "GLTF_CHANNELS" } - }, - { - [](ShaderParameters& p) { - p.meshDef.mJoints0.mBlob.mOffset = 0; - p.meshDef.mWeights0.mBlob.mOffset = 0; - }, - { "SKINNING" } - }, - { - [](ShaderParameters& p) { - p.meshDef.mFlags |= MeshDefinition::FLIP_UVS_VERTICAL; - }, - { "FLIP_V" } - }, + {[](ShaderParameters& p) { + p.materialDef.mTextureStages.push_back({MaterialDefinition::ALBEDO, {}}); + }, + {"THREE_TEX"}}, + {[](ShaderParameters& p) { + p.materialDef.mTextureStages.push_back({MaterialDefinition::METALLIC | MaterialDefinition::ROUGHNESS, {}}); + }, + {"THREE_TEX"}}, + {[](ShaderParameters& p) { + p.materialDef.mTextureStages.push_back({MaterialDefinition::NORMAL, {}}); + }, + {"THREE_TEX"}}, + {[](ShaderParameters& p) { + p.materialDef.mFlags |= MaterialDefinition::SUBSURFACE; + }, + {"SSS"}}, + {[](ShaderParameters& p) { + p.materialDef.SetAlphaCutoff(.5f); + }, + {"ALPHA_TEST"}}, + {[](ShaderParameters& p) { + p.materialDef.SetAlphaCutoff(1.f); + }, + {"ALPHA_TEST"}}, + {[](ShaderParameters& p) { + p.materialDef.mFlags |= MaterialDefinition::GLTF_CHANNELS; + }, + {"GLTF_CHANNELS"}}, + {[](ShaderParameters& p) { + p.meshDef.mJoints0.mBlob.mOffset = 0; + p.meshDef.mWeights0.mBlob.mOffset = 0; + }, + {"SKINNING"}}, + {[](ShaderParameters& p) { + p.meshDef.mFlags |= MeshDefinition::FLIP_UVS_VERTICAL; + }, + {"FLIP_V"}}, { [](ShaderParameters& p) { p.meshDef.mBlendShapes.push_back({}); }, }, - { - [](ShaderParameters& p) { - p.meshDef.mBlendShapes.back().deltas.mBlob.mOffset = 0; - }, - { "MORPH_POSITION", "MORPH" } - }, - { - [](ShaderParameters& p) { - p.meshDef.mBlendShapes.back().normals.mBlob.mOffset = 0; - }, - { "MORPH_NORMAL", "MORPH" } - }, - { - [](ShaderParameters& p) { - p.meshDef.mBlendShapes.back().tangents.mBlob.mOffset = 0; - }, - { "MORPH_TANGENT", "MORPH" } - }, - { - [](ShaderParameters& p) { - auto& blendShapes = p.meshDef.mBlendShapes; - DALI_ASSERT_ALWAYS(!blendShapes.empty() && - (blendShapes.back().deltas.mBlob.mOffset != MeshDefinition::INVALID || - blendShapes.back().normals.mBlob.mOffset != MeshDefinition::INVALID || - blendShapes.back().tangents.mBlob.mOffset != MeshDefinition::INVALID)); - p.meshDef.mBlendShapeVersion = BlendShapes::Version::VERSION_2_0; - }, - { "MORPH_VERSION_2_0" } - }, + {[](ShaderParameters& p) { + p.meshDef.mBlendShapes.back().deltas.mBlob.mOffset = 0; + }, + {"MORPH_POSITION", "MORPH"}}, + {[](ShaderParameters& p) { + p.meshDef.mBlendShapes.back().normals.mBlob.mOffset = 0; + }, + {"MORPH_NORMAL", "MORPH"}}, + {[](ShaderParameters& p) { + p.meshDef.mBlendShapes.back().tangents.mBlob.mOffset = 0; + }, + {"MORPH_TANGENT", "MORPH"}}, + {[](ShaderParameters& p) { + auto& blendShapes = p.meshDef.mBlendShapes; + DALI_ASSERT_ALWAYS(!blendShapes.empty() && + (blendShapes.back().deltas.mBlob.mOffset != MeshDefinition::INVALID || + blendShapes.back().normals.mBlob.mOffset != MeshDefinition::INVALID || + blendShapes.back().tangents.mBlob.mOffset != MeshDefinition::INVALID)); + p.meshDef.mBlendShapeVersion = BlendShapes::Version::VERSION_2_0; + }, + {"MORPH_VERSION_2_0"}}, + + {[](ShaderParameters& p) { + p.materialDef.mFlags |= MaterialDefinition::OCCLUSION; + }, + + {"OCCLUSION"}}, }; - PermutationSet permSets[] { + PermutationSet permSets[]{ // default - { { &permutations[0] }, 0 }, + {{&permutations[0]}, 0}, // alpha - { { &permutations[0], &permutations[1] }, 1 }, + {{&permutations[0], &permutations[1]}, 1}, // three-texture setups - { { &permutations[0], &permutations[2] }, 2 }, - { { &permutations[0], &permutations[3] }, 2 }, - { { &permutations[0], &permutations[4] }, 2 }, - { { &permutations[0], &permutations[2], &permutations[3] }, 2 }, - { { &permutations[0], &permutations[3], &permutations[4] }, 2 }, - { { &permutations[0], &permutations[4], &permutations[2] }, 2 }, - { { &permutations[0], &permutations[2], &permutations[3], &permutations[4] }, 2 }, + {{&permutations[0], &permutations[2]}, 2}, + {{&permutations[0], &permutations[3]}, 2}, + {{&permutations[0], &permutations[4]}, 2}, + {{&permutations[0], &permutations[2], &permutations[3]}, 2}, + {{&permutations[0], &permutations[3], &permutations[4]}, 2}, + {{&permutations[0], &permutations[4], &permutations[2]}, 2}, + {{&permutations[0], &permutations[2], &permutations[3], &permutations[4]}, 2}, // subsurface scattering - { { &permutations[0], &permutations[5] }, 3 }, + {{&permutations[0], &permutations[5]}, 3}, // alpha test - { { &permutations[0], &permutations[6] }, 4 }, - { { &permutations[0], &permutations[7] }, 4 }, + {{&permutations[0], &permutations[6]}, 4}, + {{&permutations[0], &permutations[7]}, 4}, // glTF channels - { { &permutations[0], &permutations[8] }, 5 }, + {{&permutations[0], &permutations[8]}, 5}, // skinning - { { &permutations[0], &permutations[9] }, 6 }, + {{&permutations[0], &permutations[9]}, 6}, // flip uvs - { { &permutations[0], &permutations[10] }, 7 }, + {{&permutations[0], &permutations[10]}, 7}, // morphing - { { &permutations[0], &permutations[11], &permutations[12] }, 8 }, - { { &permutations[0], &permutations[11], &permutations[13] }, 9 }, - { { &permutations[0], &permutations[11], &permutations[14] }, 10 }, - { { &permutations[0], &permutations[11], &permutations[12], &permutations[13] }, 11 }, - { { &permutations[0], &permutations[11], &permutations[13], &permutations[14] }, 12 }, - { { &permutations[0], &permutations[11], &permutations[14], &permutations[12] }, 13 }, - { { &permutations[0], &permutations[11], &permutations[12], &permutations[13], &permutations[14] }, 14 }, - - { { &permutations[0], &permutations[11], &permutations[12], &permutations[15] }, 15 }, - { { &permutations[0], &permutations[11], &permutations[13], &permutations[15] }, 16 }, - { { &permutations[0], &permutations[11], &permutations[14], &permutations[15] }, 17 }, - { { &permutations[0], &permutations[11], &permutations[12], &permutations[13], &permutations[15] }, 18 }, - { { &permutations[0], &permutations[11], &permutations[13], &permutations[14], &permutations[15] }, 19 }, - { { &permutations[0], &permutations[11], &permutations[14], &permutations[12], &permutations[15] }, 20 }, - { { &permutations[0], &permutations[11], &permutations[12], &permutations[13], &permutations[14], &permutations[15] }, 21 }, + {{&permutations[0], &permutations[11], &permutations[12]}, 8}, + {{&permutations[0], &permutations[11], &permutations[13]}, 9}, + {{&permutations[0], &permutations[11], &permutations[14]}, 10}, + {{&permutations[0], &permutations[11], &permutations[12], &permutations[13]}, 11}, + {{&permutations[0], &permutations[11], &permutations[13], &permutations[14]}, 12}, + {{&permutations[0], &permutations[11], &permutations[14], &permutations[12]}, 13}, + {{&permutations[0], &permutations[11], &permutations[12], &permutations[13], &permutations[14]}, 14}, + + {{&permutations[0], &permutations[11], &permutations[12], &permutations[15]}, 15}, + {{&permutations[0], &permutations[11], &permutations[13], &permutations[15]}, 16}, + {{&permutations[0], &permutations[11], &permutations[14], &permutations[15]}, 17}, + {{&permutations[0], &permutations[11], &permutations[12], &permutations[13], &permutations[15]}, 18}, + {{&permutations[0], &permutations[11], &permutations[13], &permutations[14], &permutations[15]}, 19}, + {{&permutations[0], &permutations[11], &permutations[14], &permutations[12], &permutations[15]}, 20}, + {{&permutations[0], &permutations[11], &permutations[12], &permutations[13], &permutations[14], &permutations[15]}, 21}, // etc. - { { &permutations[0], &permutations[1], &permutations[2] }, 1 }, - { { &permutations[0], &permutations[1], &permutations[3] }, 1 }, - { { &permutations[0], &permutations[1], &permutations[2], &permutations[3] }, 1 }, + {{&permutations[0], &permutations[1], &permutations[2]}, 1}, + {{&permutations[0], &permutations[1], &permutations[3]}, 1}, + {{&permutations[0], &permutations[1], &permutations[2], &permutations[3]}, 1}, + + // occlusion + {{&permutations[0], &permutations[16]}, 22}, }; - for(auto& ps: permSets) + + for(auto& ps : permSets) { printf("%ld\n", &ps - permSets); - auto modelNode = new ModelNode(); - modelNode->mMeshIdx = 0; + auto modelNode = new ModelNode(); + modelNode->mMeshIdx = 0; modelNode->mMaterialIdx = 0; NodeDefinition nodeDef; nodeDef.mRenderable.reset(modelNode); - auto& meshDef = NewMeshDefinition(ctx.resources); - auto& materialDef = NewMaterialDefinition(ctx.resources); - ShaderParameters sp{ meshDef, materialDef, nodeDef }; + auto& meshDef = NewMeshDefinition(ctx.resources); + auto& materialDef = NewMaterialDefinition(ctx.resources); + ShaderParameters sp{meshDef, materialDef, nodeDef}; std::set defines; - RendererState::Type rendererState = 0; - for (auto p : ps.permutations) + RendererState::Type rendererState = 0; + for(auto p : ps.permutations) { p->configureFn(sp); defines.insert(p->defines.begin(), p->defines.end()); @@ -298,15 +276,13 @@ int UtcDaliShaderDefinitionFactoryProduceShader(void) DALI_TEST_EQUAL(ps.shaderIdx, shaderIdx); auto& shaderDef = ctx.resources.mShaders[shaderIdx].first; - DALI_TEST_CHECK(EndsWith(shaderDef.mVertexShaderPath, ".vsh")); - DALI_TEST_CHECK(EndsWith(shaderDef.mFragmentShaderPath, ".fsh")); DALI_TEST_EQUAL(shaderDef.mRendererState, rendererState); uint32_t definesUnmatched = shaderDef.mDefines.size(); - for (auto& d: shaderDef.mDefines) + for(auto& d : shaderDef.mDefines) { auto iFind = defines.find(d); - if (iFind != defines.end()) + if(iFind != defines.end()) { defines.erase(iFind); --definesUnmatched; diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-Accessibility-Controls-BridgeUp.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-Accessibility-Controls-BridgeUp.cpp index 9a3ef2b..8364147 100644 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-Accessibility-Controls-BridgeUp.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-Accessibility-Controls-BridgeUp.cpp @@ -1320,7 +1320,13 @@ int UtcDaliWebViewAccessible(void) DALI_TEST_EQUALS(children.size(), 1u, TEST_LOCATION); - auto address = children[0]->GetAddress(); + auto* child = children[0]; + + DALI_TEST_CHECK(child); + DALI_TEST_CHECK(child->IsProxy()); + DALI_TEST_EQUALS(child->GetParent(), webViewAccessible, TEST_LOCATION); + + auto address = child->GetAddress(); DALI_TEST_CHECK(address); DALI_TEST_NOT_EQUALS(address.GetBus(), webViewAccessible->GetAddress().GetBus(), 0.0f, TEST_LOCATION); diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-application.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-application.cpp index 2862284..873b7b3 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-application.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-application.cpp @@ -179,7 +179,7 @@ void TestApplication::SendNotification() mCore->ProcessEvents(); } -void TestApplication::DoUpdate(uint32_t intervalMilliseconds, const char* location) +void TestApplication::DoUpdate(uint32_t intervalMilliseconds, const char* location, bool uploadOnly) { if(GetUpdateStatus() == 0 && mRenderStatus.NeedsUpdate() == false && @@ -191,25 +191,28 @@ void TestApplication::DoUpdate(uint32_t intervalMilliseconds, const char* locati uint32_t nextVSyncTime = mLastVSyncTime + intervalMilliseconds; float elapsedSeconds = static_cast(intervalMilliseconds) * 0.001f; - mCore->Update(elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false); + mCore->Update(elapsedSeconds, mLastVSyncTime, nextVSyncTime, mStatus, false, false, uploadOnly); GetRenderController().Initialize(); mLastVSyncTime = nextVSyncTime; } -bool TestApplication::Render(uint32_t intervalMilliseconds, const char* location) +bool TestApplication::Render(uint32_t intervalMilliseconds, const char* location, bool uploadOnly) { - DoUpdate(intervalMilliseconds, location); + DoUpdate(intervalMilliseconds, location, uploadOnly); // Reset the status mRenderStatus.SetNeedsUpdate(false); mRenderStatus.SetNeedsPostRender(false); - mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/); - mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/); - mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/); - mCore->PostRender(false /*do not skip rendering*/); + mCore->PreRender(mRenderStatus, false /*do not force clear*/); + if(!uploadOnly) + { + mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/); + mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/); + } + mCore->PostRender(); mFrame++; @@ -220,7 +223,7 @@ bool TestApplication::PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, { DoUpdate(intervalMilliseconds, location); - mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/); + mCore->PreRender(mRenderStatus, false /*do not force clear*/); mCore->PreRender(mScene, damagedRects); return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate(); @@ -230,7 +233,7 @@ bool TestApplication::RenderWithPartialUpdate(std::vector>& damagedRec { mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/); mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/, clippingRect); - mCore->PostRender(false /*do not skip rendering*/); + mCore->PostRender(); mFrame++; @@ -261,10 +264,10 @@ bool TestApplication::GetRenderNeedsPostRender() bool TestApplication::RenderOnly() { // Update Time values - mCore->PreRender(mRenderStatus, false /*do not force clear*/, false /*do not skip rendering*/); + mCore->PreRender(mRenderStatus, false /*do not force clear*/); mCore->RenderScene(mRenderStatus, mScene, true /*render the off-screen buffers*/); mCore->RenderScene(mRenderStatus, mScene, false /*render the surface*/); - mCore->PostRender(false /*do not skip rendering*/); + mCore->PostRender(); mFrame++; diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-application.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-application.h index 02143a7..1b101c5 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-application.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-application.h @@ -72,7 +72,7 @@ public: void ProcessEvent(const Integration::Event& event); void SendNotification(); - bool Render(uint32_t intervalMilliseconds = DEFAULT_RENDER_INTERVAL, const char* location = NULL); + bool Render(uint32_t intervalMilliseconds = DEFAULT_RENDER_INTERVAL, const char* location = NULL, bool uploadOnly = false); bool PreRenderWithPartialUpdate(uint32_t intervalMilliseconds, const char* location, std::vector>& damagedRects); bool RenderWithPartialUpdate(std::vector>& damagedRects, Rect& clippingRect); uint32_t GetUpdateStatus(); @@ -93,7 +93,7 @@ public: } private: - void DoUpdate(uint32_t intervalMilliseconds, const char* location = NULL); + void DoUpdate(uint32_t intervalMilliseconds, const char* location = NULL, bool uploadOnly = false); protected: TestPlatformAbstraction mPlatformAbstraction; diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-input-method-context.h b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-input-method-context.h index d53e02a..deb9a2d 100755 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-input-method-context.h +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-input-method-context.h @@ -60,12 +60,13 @@ public: */ enum EventType { - VOID, ///< No event - PRE_EDIT, ///< Pre-Edit changed - COMMIT, ///< Commit recieved - DELETE_SURROUNDING, ///< Event to delete a range of characters from the string - GET_SURROUNDING, ///< Event to query string and cursor position - PRIVATE_COMMAND ///< Private command sent from the input panel + VOID, ///< No event + PRE_EDIT, ///< Pre-Edit changed + COMMIT, ///< Commit recieved + DELETE_SURROUNDING, ///< Event to delete a range of characters from the string + GET_SURROUNDING, ///< Event to query string and cursor position + PRIVATE_COMMAND, ///< Private command sent from the input panel + SELECTION_SET ///< input method needs to set the selection }; /** @@ -141,7 +142,9 @@ public: : predictiveString(), eventName( VOID ), cursorOffset( 0 ), - numberOfChars ( 0 ) + numberOfChars ( 0 ), + startIndex ( 0 ), + endIndex ( 0 ) { }; @@ -157,15 +160,36 @@ public: : predictiveString( aPredictiveString ), eventName( aEventName ), cursorOffset( aCursorOffset ), - numberOfChars( aNumberOfChars ) + numberOfChars( aNumberOfChars ), + startIndex ( 0 ), + endIndex ( 0 ) + { + } + + /** + * @brief Constructor + * + * @param[in] aEventName The name of the event from the InputMethodContext. + * @param[in] aStartIndex The start index of selection. + * @param[in] aEndIndex The end index of selection. + */ + EventData(EventType aEventName, int aStartIndex, int aEndIndex) + : predictiveString(), + eventName(aEventName), + cursorOffset(0), + numberOfChars(0), + startIndex(aStartIndex), + endIndex(aEndIndex) { } // Data std::string predictiveString; ///< The pre-edit or commit string. - EventType eventName; ///< The name of the event from the input method context. + EventType eventName; ///< The name of the event from the input method context. int cursorOffset; ///< Start position from the current cursor position to start deleting characters. int numberOfChars; ///< number of characters to delete from the cursorOffset. + int startIndex; ///< The start index of selection. + int endIndex; ///< The end index of selection. }; /** diff --git a/automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp b/automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp index 1ca7bd4..05ae1c4 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-KeyboardFocusManager.cpp @@ -2220,13 +2220,13 @@ int UtcDaliKeyboardFocusManagerWithUserInteractionEnabled(void) KeyboardFocusManager manager = KeyboardFocusManager::Get(); DALI_TEST_CHECK(manager); - // Create the first actor and add it to the stage - Actor first = Actor::New(); + // Create the first control and add it to the stage + Control first = Control::New(); first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); application.GetScene().Add(first); - // Create the second actor and add it to the first actor. - Actor second = Actor::New(); + // Create the second control and add it to the first control. + Control second = Control::New(); second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); first.Add(second); @@ -2251,5 +2251,103 @@ int UtcDaliKeyboardFocusManagerWithUserInteractionEnabled(void) DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true); DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second); + // If the currently focused actor becomes USER_INTERACTION_ENABLED false, it loses focus. + second.SetProperty(DevelActor::Property::USER_INTERACTION_ENABLED, false); + + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor()); + + + END_TEST; +} + + +int UtcDaliKeyboardFocusManagerWithHide(void) +{ + ToolkitTestApplication application; + + tet_infoline(" UtcDaliKeyboardFocusManagerWithHide"); + + KeyboardFocusManager manager = KeyboardFocusManager::Get(); + DALI_TEST_CHECK(manager); + + // Create the first control and add it to the stage + Control first = Control::New(); + first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); + application.GetScene().Add(first); + + // Create the second control and add it to the first control. + Control second = Control::New(); + second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); + first.Add(second); + + + // flush the queue and render once + application.SendNotification(); + application.Render(); + + // Check that no actor is being focused yet. + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor()); + + // Check that the focus is set on the actor + DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true); + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first); + + // If the currently focused actor becomes VISIBLE false, it loses focus. + first.SetProperty(Actor::Property::VISIBLE, false); + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor()); + + first.SetProperty(Actor::Property::VISIBLE, true); + // Check that the focus is set on the actor + DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true); + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second); + + // If the currently focused actor becomes VISIBLE false, When the parent is hidden, the child also loses focus. + first.SetProperty(Actor::Property::VISIBLE, false); + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor()); + + + END_TEST; +} + +int UtcDaliKeyboardFocusManagerWithVisible(void) +{ + ToolkitTestApplication application; + + tet_infoline(" UtcDaliKeyboardFocusManagerWithVisible"); + + KeyboardFocusManager manager = KeyboardFocusManager::Get(); + DALI_TEST_CHECK(manager); + + // Create the first actor and add it to the stage + Actor first = Actor::New(); + first.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); + application.GetScene().Add(first); + + // Create the second actor and add it to the first actor. + Actor second = Actor::New(); + second.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true); + first.Add(second); + + // Check that no actor is being focused yet. + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == Actor()); + + // Check that the focus is set on the first actor + DALI_TEST_CHECK(manager.SetCurrentFocusActor(first) == true); + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first); + + // Set visible false. + first.SetProperty(Actor::Property::VISIBLE, false); + + // Check that it will fail to set focus on the second actor as it's not focusable + DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == false); + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == first); + + // Set visible true. + first.SetProperty(Actor::Property::VISIBLE, true); + + // Check that the focus is set on the second actor + DALI_TEST_CHECK(manager.SetCurrentFocusActor(second) == true); + DALI_TEST_CHECK(manager.GetCurrentFocusActor() == second); + END_TEST; } \ No newline at end of file diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 476da78..c3a08ed 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -4860,7 +4860,7 @@ int utcDaliTextEditorGeometryEllipsisEnd(void) expectedSizes.PushBack(Vector2(59, 25)); expectedPositions.PushBack(Vector2(-1, 25)); - expectedSizes.PushBack(Vector2(25, 25)); + expectedSizes.PushBack(Vector2(38, 25)); TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes); @@ -4966,6 +4966,51 @@ int utcDaliTextEditorGeometryGlyphMiddle(void) END_TEST; } +int utcDaliTextEditorGeometryOneGlyph(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextEditorGeometryOneGlyph "); + + TextEditor label = TextEditor::New(); + DALI_TEST_CHECK(label); + + application.GetScene().Add(label); + + label.SetProperty(TextEditor::Property::POINT_SIZE, 7.f); + label.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); + label.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + label.SetProperty(TextEditor::Property::ENABLE_MARKUP, true); + label.SetProperty(TextEditor::Property::TEXT, "H"); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE); + + // Render and notify + application.SendNotification(); + application.Render(); + + unsigned int expectedCount = 1; + unsigned int startIndex = 0; + unsigned int endIndex = 0; + + Vector positionsList = DevelTextEditor::GetTextPosition(label, startIndex, endIndex); + Vector sizeList = DevelTextEditor::GetTextSize(label, startIndex, endIndex); + + DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION); + DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION); + + Vector expectedSizes; + Vector expectedPositions; + + expectedPositions.PushBack(Vector2(-2, 0)); + expectedSizes.PushBack(Vector2(16, 25)); + + TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes); + + END_TEST; +} + int utcDaliTextEditorSelectionClearedSignal(void) { ToolkitTestApplication application; @@ -5840,7 +5885,7 @@ int UtcDaliToolkitTextEditorMarkupRelativeLineHeight(void) //no effect of relative line size for paragraph with single line DALI_TEST_EQUALS(naturalSize.y, relativeSingleNaturalSize.y, Math::MACHINE_EPSILON_1000, TEST_LOCATION); - DALI_TEST_EQUALS(lineSize*8.5f, relativeMultiNaturalSize.y, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + DALI_TEST_EQUALS(lineSize * 8.5f, relativeMultiNaturalSize.y, Math::MACHINE_EPSILON_1000, TEST_LOCATION); END_TEST; } diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index b86f96b..3e8b0de 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -1599,6 +1599,83 @@ int utcDaliTextFieldTextChangedWithInputMethodContext(void) END_TEST; } +int utcDaliTextFieldSelectionWithInputMethodContext(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldSelectionWithInputMethodContext"); + TextField field = TextField::New(); + DALI_TEST_CHECK(field); + + field.SetProperty(TextField::Property::TEXT, "Hello world"); + + application.GetScene().Add(field); + + // connect to the selection changed signal. + ConnectionTracker* testTracker = new ConnectionTracker(); + DevelTextField::SelectionChangedSignal(field).Connect(&TestSelectionChangedCallback); + bool selectionChangedSignal = false; + field.ConnectSignal(testTracker, "selectionChanged", CallbackFunctor(&selectionChangedSignal)); + + // get InputMethodContext + std::string text; + InputMethodContext::EventData imfEvent; + InputMethodContext inputMethodContext = DevelTextField::GetInputMethodContext(field); + + field.SetKeyInputFocus(); + field.SetProperty(DevelTextField::Property::ENABLE_EDITING, true); + + // input text + gSelectionChangedCallbackCalled = false; + imfEvent = InputMethodContext::EventData(InputMethodContext::SELECTION_SET, 1, 4); + inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent); + application.SendNotification(); + application.Render(); + DALI_TEST_CHECK(gSelectionChangedCallbackCalled); + + DALI_TEST_EQUALS(field.GetProperty(DevelTextField::Property::SELECTED_TEXT_START).Get(), 1, TEST_LOCATION); + DALI_TEST_EQUALS(field.GetProperty(DevelTextField::Property::SELECTED_TEXT_END).Get(), 4, TEST_LOCATION); + + END_TEST; +} + +int utcDaliTextFieldPositionWithInputMethodContext(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextFieldPositionWithInputMethodContext"); + TextField field = TextField::New(); + DALI_TEST_CHECK(field); + + field.SetProperty(TextField::Property::TEXT, "Hello world"); + + application.GetScene().Add(field); + + // connect to the selection changed signal. + ConnectionTracker* testTracker = new ConnectionTracker(); + DevelTextField::CursorPositionChangedSignal(field).Connect(&TestCursorPositionChangedCallback); + bool cursorPositionChangedSignal = false; + field.ConnectSignal(testTracker, "cursorPositionChanged", CallbackFunctor(&cursorPositionChangedSignal)); + + // get InputMethodContext + std::string text; + InputMethodContext::EventData imfEvent; + InputMethodContext inputMethodContext = DevelTextField::GetInputMethodContext(field); + + field.SetKeyInputFocus(); + field.SetProperty(DevelTextField::Property::ENABLE_EDITING, true); + + // input text + gCursorPositionChangedCallbackCalled = false; + imfEvent = InputMethodContext::EventData(InputMethodContext::SELECTION_SET, 2, 2); + inputMethodContext.EventReceivedSignal().Emit(inputMethodContext, imfEvent); + application.SendNotification(); + application.Render(); + DALI_TEST_CHECK(gCursorPositionChangedCallbackCalled); + + DALI_TEST_EQUALS(field.GetProperty(DevelTextField::Property::PRIMARY_CURSOR_POSITION).Get(), 2, TEST_LOCATION); + + END_TEST; +} + // Negative test for the textChanged signal. int utcDaliTextFieldTextChangedN(void) { diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp index 30aaade..c810939 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextLabel.cpp @@ -2525,8 +2525,53 @@ int utcDaliTextLabelGeometryGlyphMiddle(void) Vector expectedSizes; Vector expectedPositions; - expectedPositions.PushBack(Vector2(12, 0)); - expectedSizes.PushBack(Vector2(118, 25)); + expectedPositions.PushBack(Vector2(6, 0)); + expectedSizes.PushBack(Vector2(124, 25)); + + TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes); + + END_TEST; +} + +int utcDaliTextLabelGeometryOneGlyph(void) +{ + ToolkitTestApplication application; + tet_infoline(" utcDaliTextLabelGeometryOneGlyph "); + + TextLabel label = TextLabel::New(); + DALI_TEST_CHECK(label); + + application.GetScene().Add(label); + + label.SetProperty(TextLabel::Property::POINT_SIZE, 7.f); + label.SetProperty(Actor::Property::SIZE, Vector2(200.f, 200.f)); + label.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT); + label.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT); + label.SetProperty(TextLabel::Property::ENABLE_MARKUP, true); + label.SetProperty(TextLabel::Property::TEXT, "H"); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult(GL_FRAMEBUFFER_COMPLETE); + + // Render and notify + application.SendNotification(); + application.Render(); + + unsigned int expectedCount = 1; + unsigned int startIndex = 0; + unsigned int endIndex = 0; + + Vector positionsList = DevelTextLabel::GetTextPosition(label, startIndex, endIndex); + Vector sizeList = DevelTextLabel::GetTextSize(label, startIndex, endIndex); + + DALI_TEST_EQUALS(positionsList.Size(), expectedCount, TEST_LOCATION); + DALI_TEST_EQUALS(sizeList.Size(), expectedCount, TEST_LOCATION); + + Vector expectedSizes; + Vector expectedPositions; + + expectedPositions.PushBack(Vector2(-2, 0)); + expectedSizes.PushBack(Vector2(16, 25)); TestTextGeometryUtils::CheckGeometryResult(positionsList, sizeList, expectedPositions, expectedSizes); @@ -2679,7 +2724,7 @@ int UtcDaliToolkitTextLabelMarkupRelativeLineHeight(void) //no effect of relative line size for paragraph with single line DALI_TEST_EQUALS(naturalSize.y, relativeSingleNaturalSize.y, Math::MACHINE_EPSILON_1000, TEST_LOCATION); - DALI_TEST_EQUALS(lineSize*8.5f, relativeMultiNaturalSize.y, Math::MACHINE_EPSILON_1000, TEST_LOCATION); + DALI_TEST_EQUALS(lineSize * 8.5f, relativeMultiNaturalSize.y, Math::MACHINE_EPSILON_1000, TEST_LOCATION); END_TEST; } diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp index 79b42f6..c17567a 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp @@ -615,20 +615,6 @@ int UtcDaliVisualGetPropertyMap2(void) DALI_TEST_CHECK(sizeValue); DALI_TEST_CHECK(sizeValue->Get() == 10.f); - // Get default value of borderline values here - - sizeValue = resultMap.Find(DevelVisual::Property::BORDERLINE_WIDTH, Property::FLOAT); - DALI_TEST_CHECK(sizeValue); - DALI_TEST_CHECK(sizeValue->Get() == 0.0f); - - colorValue = resultMap.Find(DevelVisual::Property::BORDERLINE_COLOR, Property::VECTOR4); - DALI_TEST_CHECK(colorValue); - DALI_TEST_CHECK(colorValue->Get() == Color::BLACK); - - sizeValue = resultMap.Find(DevelVisual::Property::BORDERLINE_OFFSET, Property::FLOAT); - DALI_TEST_CHECK(sizeValue); - DALI_TEST_CHECK(sizeValue->Get() == 0.0f); - END_TEST; } @@ -2051,7 +2037,7 @@ int UtcDaliVisualAnimatePrimitiveVisual(void) DALI_TEST_EQUALS(actor.GetRendererCount(), 1u, TEST_LOCATION); - Renderer renderer = actor.GetRendererAt(0); + Renderer renderer = actor.GetRendererAt(0); const Vector4 INITIAL_MIX_COLOR(1.0f, 0.0f, 1.0f, 0.5f); // Magenta with half alpha const Vector4 TARGET_MIX_COLOR(Color::RED); @@ -3470,7 +3456,7 @@ int UtcDaliVisualPremultipliedAlpha(void) DALI_TEST_EQUALS(value->Get(), false, TEST_LOCATION); } - // svg visual ( premultiplied alpha by default is true ) + // svg visual ( premultiplied alpha by default is true, and cannot change value ) { Visual::Base imageVisual = factory.CreateVisual( Property::Map() @@ -3485,6 +3471,149 @@ int UtcDaliVisualPremultipliedAlpha(void) DALI_TEST_CHECK(value); DALI_TEST_EQUALS(value->Get(), true, TEST_LOCATION); } + { + Visual::Base imageVisual = factory.CreateVisual( + Property::Map() + .Add(Toolkit::Visual::Property::TYPE, Visual::IMAGE) + .Add(ImageVisual::Property::URL, TEST_SVG_FILE_NAME) + .Add(Visual::Property::PREMULTIPLIED_ALPHA, false)); + + Dali::Property::Map visualMap; + imageVisual.CreatePropertyMap(visualMap); + Property::Value* value = visualMap.Find(Visual::Property::PREMULTIPLIED_ALPHA); + + // test values + DALI_TEST_CHECK(value); + DALI_TEST_EQUALS(value->Get(), true, TEST_LOCATION); + } + + // animated vector visual ( premultiplied alpha by default is true, and cannot change value ) + { + Visual::Base imageVisual = factory.CreateVisual( + Property::Map() + .Add(Toolkit::Visual::Property::TYPE, Visual::IMAGE) + .Add(ImageVisual::Property::URL, "something.json")); + + Dali::Property::Map visualMap; + imageVisual.CreatePropertyMap(visualMap); + Property::Value* value = visualMap.Find(Visual::Property::PREMULTIPLIED_ALPHA); + + // test values + DALI_TEST_CHECK(value); + DALI_TEST_EQUALS(value->Get(), true, TEST_LOCATION); + } + { + Visual::Base imageVisual = factory.CreateVisual( + Property::Map() + .Add(Toolkit::Visual::Property::TYPE, Visual::IMAGE) + .Add(ImageVisual::Property::URL, "something.json") + .Add(Visual::Property::PREMULTIPLIED_ALPHA, false)); + + Dali::Property::Map visualMap; + imageVisual.CreatePropertyMap(visualMap); + Property::Value* value = visualMap.Find(Visual::Property::PREMULTIPLIED_ALPHA); + + // test values + DALI_TEST_CHECK(value); + DALI_TEST_EQUALS(value->Get(), true, TEST_LOCATION); + } + + // text visual ( premultiplied alpha by default is true, and cannot change value ) + { + Visual::Base textVisual = factory.CreateVisual( + Property::Map() + .Add(Toolkit::Visual::Property::TYPE, Visual::TEXT) + .Add(TextVisual::Property::TEXT, "Text")); + + Dali::Property::Map visualMap; + textVisual.CreatePropertyMap(visualMap); + Property::Value* value = visualMap.Find(Visual::Property::PREMULTIPLIED_ALPHA); + + // test values + DALI_TEST_CHECK(value); + DALI_TEST_EQUALS(value->Get(), true, TEST_LOCATION); + } + { + Visual::Base textVisual = factory.CreateVisual( + Property::Map() + .Add(Toolkit::Visual::Property::TYPE, Visual::TEXT) + .Add(TextVisual::Property::TEXT, "Text") + .Add(Visual::Property::PREMULTIPLIED_ALPHA, false)); + + Dali::Property::Map visualMap; + textVisual.CreatePropertyMap(visualMap); + Property::Value* value = visualMap.Find(Visual::Property::PREMULTIPLIED_ALPHA); + + // test values + DALI_TEST_CHECK(value); + DALI_TEST_EQUALS(value->Get(), true, TEST_LOCATION); + } + + // gradient visual ( premultiplied alpha by default is true, and cannot change value ) + { + Visual::Base gradientVisual = factory.CreateVisual( + Property::Map() + .Add(Toolkit::Visual::Property::TYPE, Visual::GRADIENT) + .Add(GradientVisual::Property::START_POSITION, Vector2(-0.5f, -0.5f)) + .Add(GradientVisual::Property::END_POSITION, Vector2(0.5f, 0.5f)) + .Add(GradientVisual::Property::STOP_COLOR, Property::Array().Add(Color::RED).Add(Vector4(1.0f, 1.0f, 1.0f, 0.5f)))); + + Dali::Property::Map visualMap; + gradientVisual.CreatePropertyMap(visualMap); + Property::Value* value = visualMap.Find(Visual::Property::PREMULTIPLIED_ALPHA); + + // test values + DALI_TEST_CHECK(value); + DALI_TEST_EQUALS(value->Get(), true, TEST_LOCATION); + } + { + Visual::Base gradientVisual = factory.CreateVisual( + Property::Map() + .Add(Toolkit::Visual::Property::TYPE, Visual::GRADIENT) + .Add(GradientVisual::Property::START_POSITION, Vector2(-0.5f, -0.5f)) + .Add(GradientVisual::Property::END_POSITION, Vector2(0.5f, 0.5f)) + .Add(GradientVisual::Property::STOP_COLOR, Property::Array().Add(Color::RED).Add(Vector4(1.0f, 1.0f, 1.0f, 0.5f))) + .Add(Visual::Property::PREMULTIPLIED_ALPHA, false)); + + Dali::Property::Map visualMap; + gradientVisual.CreatePropertyMap(visualMap); + Property::Value* value = visualMap.Find(Visual::Property::PREMULTIPLIED_ALPHA); + + // test values + DALI_TEST_CHECK(value); + DALI_TEST_EQUALS(value->Get(), true, TEST_LOCATION); + } + + // color visual ( premultiplied alpha by default is false, and cannot change value ) + { + Visual::Base colorVisual = factory.CreateVisual( + Property::Map() + .Add(Toolkit::Visual::Property::TYPE, Visual::COLOR) + .Add(ColorVisual::Property::MIX_COLOR, Color::AQUA)); + + Dali::Property::Map visualMap; + colorVisual.CreatePropertyMap(visualMap); + Property::Value* value = visualMap.Find(Visual::Property::PREMULTIPLIED_ALPHA); + + // test values + DALI_TEST_CHECK(value); + DALI_TEST_EQUALS(value->Get(), false, TEST_LOCATION); + } + { + Visual::Base colorVisual = factory.CreateVisual( + Property::Map() + .Add(Toolkit::Visual::Property::TYPE, Visual::COLOR) + .Add(ColorVisual::Property::MIX_COLOR, Color::AQUA) + .Add(Visual::Property::PREMULTIPLIED_ALPHA, true)); + + Dali::Property::Map visualMap; + colorVisual.CreatePropertyMap(visualMap); + Property::Value* value = visualMap.Find(Visual::Property::PREMULTIPLIED_ALPHA); + + // test values + DALI_TEST_CHECK(value); + DALI_TEST_EQUALS(value->Get(), false, TEST_LOCATION); + } END_TEST; } @@ -4749,8 +4878,7 @@ int UtcDaliVisualGetVisualProperty01(void) UniformData("blurRadius", Property::Type::FLOAT), UniformData("borderlineWidth", Property::Type::FLOAT), UniformData("borderlineColor", Property::Type::VECTOR4), - UniformData("borderlineOffset", Property::Type::FLOAT), - UniformData("preMultipliedAlpha", Property::Type::FLOAT)}; + UniformData("borderlineOffset", Property::Type::FLOAT)}; TestGraphicsController& graphics = application.GetGraphicsController(); graphics.AddCustomUniforms(customUniforms); @@ -4765,7 +4893,6 @@ int UtcDaliVisualGetVisualProperty01(void) propertyMap.Insert(DevelVisual::Property::BORDERLINE_WIDTH, 20.0f); propertyMap.Insert(DevelVisual::Property::BORDERLINE_COLOR, Color::RED); propertyMap.Insert(DevelVisual::Property::BORDERLINE_OFFSET, 1.0f); - propertyMap.Insert(Visual::Property::PREMULTIPLIED_ALPHA, true); Visual::Base colorVisual = factory.CreateVisual(propertyMap); DummyControl dummyControl = DummyControl::New(true); @@ -4785,8 +4912,7 @@ int UtcDaliVisualGetVisualProperty01(void) float targetBlurRadius = 10.0f; float targetBorderlineWidth = 25.0f; Vector4 targetBorderlineColor(1.0f, 1.0f, 1.0f, 1.0f); - float targetBorderlineOffset = -1.0f; - float targetPreMultipliedAlpha = 1.0f; + float targetBorderlineOffset = -1.0f; Animation animation = Animation::New(1.0f); animation.AnimateTo(DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL, Visual::Property::MIX_COLOR), targetColor); @@ -4844,10 +4970,6 @@ int UtcDaliVisualGetVisualProperty01(void) DALI_TEST_CHECK(borderlineOffsetValue); DALI_TEST_EQUALS(borderlineOffsetValue->Get(), targetBorderlineOffset, TEST_LOCATION); - Property::Value* preMultAlphaValue = resultMap.Find(Visual::Property::PREMULTIPLIED_ALPHA, Property::BOOLEAN); - DALI_TEST_CHECK(preMultAlphaValue); - DALI_TEST_EQUALS(preMultAlphaValue->Get(), bool(targetPreMultipliedAlpha), TEST_LOCATION); - // Test uniform values DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue("mixColor", targetColor), true, TEST_LOCATION); DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue("offset", targetOffset), true, TEST_LOCATION); @@ -4857,7 +4979,6 @@ int UtcDaliVisualGetVisualProperty01(void) DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue("borderlineWidth", targetBorderlineWidth), true, TEST_LOCATION); DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue("borderlineColor", targetBorderlineColor), true, TEST_LOCATION); DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue("borderlineOffset", targetBorderlineOffset), true, TEST_LOCATION); - DALI_TEST_EQUALS(application.GetGlAbstraction().CheckUniformValue("preMultipliedAlpha", targetPreMultipliedAlpha), true, TEST_LOCATION); // Test unregistered visual Property property3 = DevelControl::GetVisualProperty(dummyControl, DummyControl::Property::TEST_VISUAL2, Visual::Property::MIX_COLOR); diff --git a/dali-scene-loader/internal/gltf2-asset.h b/dali-scene-loader/internal/gltf2-asset.h index f5bd6b9..e074c28 100644 --- a/dali-scene-loader/internal/gltf2-asset.h +++ b/dali-scene-loader/internal/gltf2-asset.h @@ -317,6 +317,7 @@ struct TextureInfo Ref mTexture; uint32_t mTexCoord = 0; float mScale = 1.f; + float mStrength = 1.f; operator bool() const { diff --git a/dali-scene-loader/internal/graphics/shaders/default-physically-based-shader.frag b/dali-scene-loader/internal/graphics/shaders/default-physically-based-shader.frag new file mode 100644 index 0000000..2581ad6 --- /dev/null +++ b/dali-scene-loader/internal/graphics/shaders/default-physically-based-shader.frag @@ -0,0 +1,183 @@ +#version 300 es + +#ifdef HIGHP + precision highp float; +#else + precision mediump float; +#endif + +#ifdef THREE_TEX +#ifdef GLTF_CHANNELS +// https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#pbrmetallicroughnessmetallicroughnesstexture +#define METALLIC b +#define ROUGHNESS g +#else //GLTF_CHANNELS +#define METALLIC r +#define ROUGHNESS a +#endif //GLTF_CHANNELS +#endif //THREE_TEX + +#ifdef THREE_TEX + uniform sampler2D sAlbedoAlpha; + uniform sampler2D sMetalRoughness; + uniform sampler2D sNormal; + +#ifdef ALPHA_TEST + uniform float uAlphaThreshold; +#endif //ALPHA_TEST + +#else + uniform sampler2D sAlbedoMetal; + uniform sampler2D sNormalRoughness; +#endif + +#ifdef OCCLUSION + uniform sampler2D sOcclusion; + uniform float uOcclusionStrength; +#endif + +#ifdef EMISSIVE + uniform sampler2D sEmissive; + uniform vec3 uEmissiveFactor; +#endif + +uniform samplerCube sDiffuse; +uniform samplerCube sSpecular; + +// Number of mip map levels in the texture +uniform float uMaxLOD; + +// Transformation matrix of the cubemap texture +uniform mat4 uCubeMatrix; + +uniform vec4 uColor; +uniform float uMetallicFactor; +uniform float uRoughnessFactor; + +//IBL Light intensity +uniform float uIblIntensity; + +// TODO: Multiple texture coordinate will be supported. +in vec2 vUV; +in vec3 vNormal; +in vec3 vTangent; +in vec3 vViewVec; + +out vec4 FragColor; + +// Functions for BRDF calculation come from +// https://www.unrealengine.com/blog/physically-based-shading-on-mobile +// Based on the paper by Dimitar Lazarov +// http://blog.selfshadow.com/publications/s2013-shading-course/lazarov/s2013_pbs_black_ops_2_notes.pdf +vec3 EnvBRDFApprox( vec3 SpecularColor, float Roughness, float NoV ) +{ + const vec4 c0 = vec4( -1.0, -0.0275, -0.572, 0.022 ); + const vec4 c1 = vec4( 1.0, 0.0425, 1.04, -0.04 ); + vec4 r = Roughness * c0 + c1; + float a004 = min( r.x * r.x, exp2( -9.28 * NoV ) ) * r.x + r.y; + vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw; + + return SpecularColor * AB.x + AB.y; +} + +void main() +{ + // We get information from the maps (albedo, normal map, roughness, metalness + // I access the maps in the order they will be used +#ifdef THREE_TEX + vec4 albedoAlpha = texture(sAlbedoAlpha, vUV.st); + float alpha = albedoAlpha.a; +#ifdef ALPHA_TEST + if (alpha <= uAlphaThreshold) + { + discard; + } +#endif //ALPHA_TEST + vec3 albedoColor = albedoAlpha.rgb * uColor.rgb; + + vec4 metalRoughness = texture(sMetalRoughness, vUV.st); + float metallic = metalRoughness.METALLIC * uMetallicFactor; + float roughness = metalRoughness.ROUGHNESS * uRoughnessFactor; + + vec3 normalMap = texture(sNormal, vUV.st).rgb; +#else //THREE_TEX + vec4 albedoMetal = texture(sAlbedoMetal, vUV.st); + vec3 albedoColor = albedoMetal.rgb * uColor.rgb; + float metallic = albedoMetal.a * uMetallicFactor; + + vec4 normalRoughness = texture(sNormalRoughness, vUV.st); + vec3 normalMap = normalRoughness.rgb; + float roughness = normalRoughness.a * uRoughnessFactor; +#endif + //Normalize vectors + vec3 normal = normalize(vNormal); + vec3 tangent = normalize(vTangent); + + // NOTE: normal and tangent have to be orthogonal for the result of the cross() + // product to be a unit vector. We might find that we need to normalize(). + vec3 bitangent = cross(normal, tangent); + + vec3 viewVec = normalize(vViewVec); + + // Create Inverse Local to world matrix + mat3 vInvTBN = mat3(tangent, bitangent, normal); + + // Get normal map info in world space + normalMap = normalize(normalMap - 0.5); + vec3 newNormal = vInvTBN * normalMap.rgb; + + // Calculate normal dot view vector + float NoV = max(dot(newNormal, -viewVec), 0.0); + + // Reflect vector + vec3 reflectionVec = reflect(viewVec, newNormal); + + //transform it now to environment coordinates (used when the environment rotates) + vec3 reflecCube = (uCubeMatrix * vec4( reflectionVec, 0.0 ) ).xyz; + reflecCube = normalize( reflecCube ); + + //transform it now to environment coordinates + vec3 normalCube = ( uCubeMatrix * vec4( newNormal, 0.0 ) ).xyz; + normalCube = normalize( normalCube ); + + // Get irradiance from diffuse cubemap + vec3 irradiance = texture( sDiffuse, normalCube ).rgb; + + // Access reflection color using roughness value + float finalLod = mix( 0.0, uMaxLOD - 2.0, roughness); + vec3 reflectionColor = textureLod(sSpecular, reflecCube, finalLod).rgb; + + // We are supposed to be using DielectricColor (0.04) of a plastic (almost everything) + // http://blog.selfshadow.com/publications/s2014-shading-course/hoffman/s2014_pbs_physics_math_slides.pdf + // however that seems to prevent achieving very dark tones (i.e. get dark gray blacks). + vec3 DiffuseColor = albedoColor - albedoColor * metallic; // 1 mad + vec3 SpecularColor = mix( vec3(0.04), albedoColor, metallic); // 2 mad + + // Calculate specular color using Magic Function (takes original roughness and normal dot view). + vec3 specColor = reflectionColor.rgb * EnvBRDFApprox(SpecularColor, roughness, NoV ); + + // Multiply the result by albedo texture and do energy conservation + vec3 diffuseColor = irradiance * DiffuseColor; + + // Final color is the sum of the diffuse and specular term + vec3 finalColor = diffuseColor + specColor; + + finalColor = sqrt( finalColor ) * uIblIntensity; + + +#ifdef OCCLUSION + float ao = texture(sOcclusion, vUV.st).r; + finalColor = mix( finalColor, finalColor * ao, uOcclusionStrength ); +#endif + +#ifdef EMISSIVE + vec3 emissive = texture( sEmissive, vUV.st ).rgb * uEmissiveFactor; + finalColor += emissive; +#endif + +#ifdef THREE_TEX + FragColor = vec4( finalColor, alpha ); +#else //THREE_TEX + FragColor = vec4( finalColor, 1.0 ); +#endif //THREE_TEX +} diff --git a/dali-scene-loader/internal/graphics/shaders/default-physically-based-shader.vert b/dali-scene-loader/internal/graphics/shaders/default-physically-based-shader.vert new file mode 100644 index 0000000..e9381c5 --- /dev/null +++ b/dali-scene-loader/internal/graphics/shaders/default-physically-based-shader.vert @@ -0,0 +1,149 @@ +#version 300 es + +#ifdef HIGHP + precision highp float; +#else + precision mediump float; +#endif + +in vec3 aPosition; +in vec2 aTexCoord; +in vec3 aNormal; +in vec3 aTangent; + +#ifdef MORPH + uniform sampler2D sBlendShapeGeometry; +#endif + +out vec2 vUV; +out vec3 vNormal; +out vec3 vTangent; +out vec3 vViewVec; + +uniform highp mat4 uMvpMatrix; +uniform highp mat4 uViewMatrix; +uniform mat3 uNormalMatrix; +uniform mat4 uModelMatrix; +uniform mat4 uModelView; +uniform mat4 uProjection; + +#ifdef SKINNING + in vec4 aJoints; + in vec4 aWeights; + #define MAX_BONES 64 + uniform mat4 uBone[MAX_BONES]; +#endif + +#ifdef MORPH +#define MAX_BLEND_SHAPE_NUMBER 128 +uniform int uNumberOfBlendShapes; ///< Total number of blend shapes loaded. +uniform float uBlendShapeWeight[MAX_BLEND_SHAPE_NUMBER]; ///< The weight of each blend shape. +#ifdef MORPH_VERSION_2_0 +uniform float uBlendShapeUnnormalizeFactor; ///< Factor used to unnormalize the geometry of the blend shape. +#else +uniform float uBlendShapeUnnormalizeFactor[MAX_BLEND_SHAPE_NUMBER]; ///< Factor used to unnormalize the geometry of the blend shape. +#endif +uniform int uBlendShapeComponentSize; ///< The size in the texture of either the vertices, normals or tangents. Used to calculate the offset to address them. +#endif + +void main() +{ + vec4 position = vec4(aPosition, 1.0); + vec3 normal = aNormal; + vec3 tangent = aTangent; + +#ifdef MORPH + int width = textureSize( sBlendShapeGeometry, 0 ).x; + + int blendShapeBufferOffset = 0; + for( int index = 0; index < uNumberOfBlendShapes; ++index ) + { +#ifdef MORPH_POSITION + // Calculate the index to retrieve the geometry from the texture. + int vertexId = gl_VertexID + blendShapeBufferOffset; + int x = vertexId % width; + int y = vertexId / width; + + vec3 diff = vec3(0.0); + // Retrieves the blend shape geometry from the texture, unnormalizes it and multiply by the weight. + if( 0.0 != uBlendShapeWeight[index] ) + { +#ifdef MORPH_VERSION_2_0 + float unnormalizeFactor = uBlendShapeUnnormalizeFactor; +#else + float unnormalizeFactor = uBlendShapeUnnormalizeFactor[index]; +#endif + + diff = uBlendShapeWeight[index] * unnormalizeFactor * ( texelFetch( sBlendShapeGeometry, ivec2(x, y), 0 ).xyz - 0.5 ); + } + + position.xyz += diff; + + blendShapeBufferOffset += uBlendShapeComponentSize; +#endif + +#ifdef MORPH_NORMAL + // Calculate the index to retrieve the normal from the texture. + vertexId = gl_VertexID + blendShapeBufferOffset; + x = vertexId % width; + y = vertexId / width; + + // Retrieves the blend shape normal from the texture, unnormalizes it and multiply by the weight. + if( 0.0 != uBlendShapeWeight[index] ) + { + diff = uBlendShapeWeight[index] * 2.0 * ( texelFetch( sBlendShapeGeometry, ivec2(x, y), 0 ).xyz - 0.5 ); + } + + normal += diff.xyz; + + blendShapeBufferOffset += uBlendShapeComponentSize; +#endif + +#ifdef MORPH_TANGENT + // Calculate the index to retrieve the tangent from the texture. + vertexId = gl_VertexID + blendShapeBufferOffset; + x = vertexId % width; + y = vertexId / width; + + // Retrieves the blend shape tangent from the texture, unnormalizes it and multiply by the weight. + if( 0.0 != uBlendShapeWeight[index] ) + { + diff = uBlendShapeWeight[index] * 2.0 * ( texelFetch( sBlendShapeGeometry, ivec2(x, y), 0 ).xyz - 0.5 ); + } + + tangent += diff.xyz; + + blendShapeBufferOffset += uBlendShapeComponentSize; +#endif + } + +#endif + +#ifdef SKINNING + mat4 bone = uBone[int(aJoints.x)] * aWeights.x + + uBone[int(aJoints.y)] * aWeights.y + + uBone[int(aJoints.z)] * aWeights.z + + uBone[int(aJoints.w)] * aWeights.w; + position = bone * position; + normal = (bone * vec4(normal, 0.0)).xyz; + tangent = (bone * vec4(tangent, 0.0)).xyz; +#endif + + vec4 vPosition = uModelMatrix * position; + + vNormal = normalize(uNormalMatrix * normal); + + vTangent = normalize(uNormalMatrix * tangent); + + + vec4 viewPosition = uViewMatrix * vPosition; + gl_Position = uProjection * viewPosition; + +#ifdef FLIP_V + vUV = vec2(aTexCoord.x, 1.0 - aTexCoord.y); +#else + vUV = aTexCoord; +#endif + + vViewVec = viewPosition.xyz; +} diff --git a/dali-scene-loader/public-api/dli-loader.cpp b/dali-scene-loader/public-api/dli-loader.cpp index 48a82c3..3031c5e 100644 --- a/dali-scene-loader/public-api/dli-loader.cpp +++ b/dali-scene-loader/public-api/dli-loader.cpp @@ -1014,6 +1014,14 @@ void DliLoader::Impl::ParseMaterials(const TreeNode* materials, ConvertColorCode materialDef.mFlags |= semantic; } + if(ReadString(node.GetChild("occlusionMap"), texturePath)) + { + ToUnixFileSeparators(texturePath); + const auto semantic = MaterialDefinition::OCCLUSION; + materialDef.mTextureStages.push_back({semantic, TextureDefinition{std::move(texturePath)}}); + materialDef.mFlags |= semantic; + } + if(ReadColorCodeOrColor(&node, materialDef.mColor, convertColorCode) && materialDef.mColor.a < 1.0f) { diff --git a/dali-scene-loader/public-api/gltf2-loader.cpp b/dali-scene-loader/public-api/gltf2-loader.cpp index 923d0e4..be7e538 100644 --- a/dali-scene-loader/public-api/gltf2-loader.cpp +++ b/dali-scene-loader/public-api/gltf2-loader.cpp @@ -157,7 +157,8 @@ const auto TEXURE_READER = std::move(js::Reader() const auto TEXURE_INFO_READER = std::move(js::Reader() .Register(*js::MakeProperty("index", gt::RefReader::Read, >::TextureInfo::mTexture)) .Register(*js::MakeProperty("texCoord", js::Read::Number, >::TextureInfo::mTexCoord)) - .Register(*js::MakeProperty("scale", js::Read::Number, >::TextureInfo::mScale))); + .Register(*js::MakeProperty("scale", js::Read::Number, >::TextureInfo::mScale)) + .Register(*js::MakeProperty("strength", js::Read::Number, >::TextureInfo::mStrength))); const auto MATERIAL_PBR_READER = std::move(js::Reader() .Register(*js::MakeProperty("baseColorFactor", gt::ReadDaliVector, >::Material::Pbr::mBaseColorFactor)) @@ -440,7 +441,7 @@ void ConvertMaterial(const gt::Material& m, decltype(ResourceBundle::mMaterials) matDef.mColor = pbr.mBaseColorFactor; - matDef.mTextureStages.reserve(!!pbr.mBaseColorTexture + !!pbr.mMetallicRoughnessTexture + !!m.mNormalTexture); + matDef.mTextureStages.reserve(!!pbr.mBaseColorTexture + !!pbr.mMetallicRoughnessTexture + !!m.mNormalTexture + !!m.mOcclusionTexture + !!m.mEmissiveTexture); if(pbr.mBaseColorTexture) { const auto semantic = MaterialDefinition::ALBEDO; @@ -470,6 +471,23 @@ void ConvertMaterial(const gt::Material& m, decltype(ResourceBundle::mMaterials) } // TODO: handle doubleSided + if(m.mOcclusionTexture) + { + const auto semantic = MaterialDefinition::OCCLUSION; + matDef.mTextureStages.push_back({semantic, ConvertTextureInfo(m.mOcclusionTexture)}); + // TODO: and there had better be one + matDef.mFlags |= semantic; + matDef.mOcclusionStrength = m.mOcclusionTexture.mStrength; + } + + if(m.mEmissiveTexture) + { + const auto semantic = MaterialDefinition::EMISSIVE; + matDef.mTextureStages.push_back({semantic, ConvertTextureInfo(m.mEmissiveTexture)}); + // TODO: and there had better be one + matDef.mFlags |= semantic; + matDef.mEmissiveFactor = m.mEmissiveFactor; + } outMaterials.emplace_back(std::move(matDef), TextureSet()); } diff --git a/dali-scene-loader/public-api/material-definition.cpp b/dali-scene-loader/public-api/material-definition.cpp index c0e816c..1342ced 100644 --- a/dali-scene-loader/public-api/material-definition.cpp +++ b/dali-scene-loader/public-api/material-definition.cpp @@ -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. @@ -110,7 +110,9 @@ MaterialDefinition::LoadRaw(const std::string& imagesPath) const RawData raw; const bool hasTransparency = MaskMatch(mFlags, TRANSPARENCY); - uint32_t numBuffers = mTextureStages.size() + (hasTransparency ? !CheckTextures(ALBEDO) + !CheckTextures(METALLIC | ROUGHNESS) + !CheckTextures(NORMAL) : !CheckTextures(ALBEDO | METALLIC) + !CheckTextures(NORMAL | ROUGHNESS)); + // Why we add additional count here? + uint32_t numBuffers = mTextureStages.size() + (hasTransparency ? !CheckTextures(ALBEDO) + !CheckTextures(METALLIC | ROUGHNESS) + !CheckTextures(NORMAL) + : !CheckTextures(ALBEDO | METALLIC) + !CheckTextures(NORMAL | ROUGHNESS)); if(numBuffers == 0) { return raw; @@ -210,13 +212,25 @@ MaterialDefinition::LoadRaw(const std::string& imagesPath) const } } - // Extra textures. TODO: emissive, occlusion etc. + // Extra textures. if(checkStage(SUBSURFACE)) { raw.mTextures.push_back({SyncImageLoader::Load(imagesPath + iTexture->mTexture.mImageUri), iTexture->mTexture.mSamplerFlags}); ++iTexture; } + if(checkStage(OCCLUSION)) + { + raw.mTextures.push_back({SyncImageLoader::Load(imagesPath + iTexture->mTexture.mImageUri), iTexture->mTexture.mSamplerFlags}); + ++iTexture; + } + + if(checkStage(EMISSIVE)) + { + raw.mTextures.push_back({SyncImageLoader::Load(imagesPath + iTexture->mTexture.mImageUri), iTexture->mTexture.mSamplerFlags}); + ++iTexture; + } + return raw; } diff --git a/dali-scene-loader/public-api/material-definition.h b/dali-scene-loader/public-api/material-definition.h index 80e93e7..e36f74b 100644 --- a/dali-scene-loader/public-api/material-definition.h +++ b/dali-scene-loader/public-api/material-definition.h @@ -219,10 +219,12 @@ struct DALI_SCENE_LOADER_API MaterialDefinition public: // DATA uint32_t mFlags = 0x0; - Index mEnvironmentIdx = 0; - Vector4 mColor = Color::WHITE; - float mMetallic = 1.f; - float mRoughness = 1.f; + Index mEnvironmentIdx = 0; + Vector4 mColor = Color::WHITE; + Vector3 mEmissiveFactor = Vector3::ZERO; + float mMetallic = 1.f; + float mRoughness = 1.f; + float mOcclusionStrength = 1.f; std::vector mTextureStages; }; diff --git a/dali-scene-loader/public-api/node-definition.cpp b/dali-scene-loader/public-api/node-definition.cpp index 45e0b23..e8f6b82 100644 --- a/dali-scene-loader/public-api/node-definition.cpp +++ b/dali-scene-loader/public-api/node-definition.cpp @@ -153,6 +153,14 @@ void ModelNode::OnCreate(const NodeDefinition& node, NodeDefinition::CreateParam auto& matDef = resources.mMaterials[mMaterialIdx].first; actor.RegisterProperty("uMetallicFactor", matDef.mMetallic); actor.RegisterProperty("uRoughnessFactor", matDef.mRoughness); + if(matDef.mFlags & MaterialDefinition::OCCLUSION) + { + actor.RegisterProperty("uOcclusionStrength", matDef.mOcclusionStrength); + } + if(matDef.mFlags & MaterialDefinition::EMISSIVE) + { + actor.RegisterProperty("uEmissiveFactor", matDef.mEmissiveFactor); + } Index envIdx = matDef.mEnvironmentIdx; actor.RegisterProperty("uIblIntensity", resources.mEnvironmentMaps[envIdx].first.mIblIntensity); diff --git a/dali-scene-loader/public-api/shader-definition-factory.cpp b/dali-scene-loader/public-api/shader-definition-factory.cpp index 843fbcf..6f9ab4e 100644 --- a/dali-scene-loader/public-api/shader-definition-factory.cpp +++ b/dali-scene-loader/public-api/shader-definition-factory.cpp @@ -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. @@ -56,8 +56,6 @@ struct ResourceReceiver : IResourceReceiver } }; -const std::string PBR_SHADER_NAME = "dli_pbr"; - void RetrieveBlendShapeComponents(const std::vector& blendShapes, bool& hasPositions, bool& hasNormals, bool& hasTangents) { for(const auto& blendShape : blendShapes) @@ -72,9 +70,6 @@ uint64_t HashNode(const NodeDefinition& nodeDef, const MaterialDefinition& mater { Hash hash; - // note: could be per vertex / fragment component - in WatchViewer, these have the same name. - hash.Add(PBR_SHADER_NAME); - const bool hasTransparency = MaskMatch(materialDef.mFlags, MaterialDefinition::TRANSPARENCY); hash.Add(hasTransparency); @@ -96,6 +91,16 @@ uint64_t HashNode(const NodeDefinition& nodeDef, const MaterialDefinition& mater hash.Add("SSS"); } + if(MaskMatch(materialDef.mFlags, MaterialDefinition::OCCLUSION)) + { + hash.Add("OCCL" /*USION*/); + } + + if(MaskMatch(materialDef.mFlags, MaterialDefinition::EMISSIVE)) + { + hash.Add("EMIS" /*SIVE*/); + } + if(MaskMatch(materialDef.mFlags, MaterialDefinition::GLTF_CHANNELS)) { hash.Add("GLTF" /*_CHANNELS*/); @@ -187,8 +192,7 @@ Index ShaderDefinitionFactory::ProduceShader(const NodeDefinition& nodeDef) } ShaderDefinition shaderDef; - shaderDef.mVertexShaderPath = PBR_SHADER_NAME + ".vsh"; - shaderDef.mFragmentShaderPath = PBR_SHADER_NAME + ".fsh"; + shaderDef.mUseBuiltInShader = true; shaderDef.mRendererState = RendererState::DEPTH_TEST | RendererState::DEPTH_WRITE | RendererState::CULL_BACK; auto& materialDef = *receiver.mMaterialDef; @@ -217,7 +221,17 @@ Index ShaderDefinitionFactory::ProduceShader(const NodeDefinition& nodeDef) shaderDef.mDefines.push_back("SSS"); } - if(MaskMatch(receiver.mMaterialDef->mFlags, MaterialDefinition::GLTF_CHANNELS)) + if(MaskMatch(materialDef.mFlags, MaterialDefinition::OCCLUSION)) + { + shaderDef.mDefines.push_back("OCCLUSION"); + } + + if(MaskMatch(materialDef.mFlags, MaterialDefinition::EMISSIVE)) + { + shaderDef.mDefines.push_back("EMISSIVE"); + } + + if(MaskMatch(materialDef.mFlags, MaterialDefinition::GLTF_CHANNELS)) { shaderDef.mDefines.push_back("GLTF_CHANNELS"); } diff --git a/dali-scene-loader/public-api/shader-definition.cpp b/dali-scene-loader/public-api/shader-definition.cpp index 73c18ba..71024f3 100644 --- a/dali-scene-loader/public-api/shader-definition.cpp +++ b/dali-scene-loader/public-api/shader-definition.cpp @@ -18,6 +18,7 @@ // INTERNAL INCLUDES #include "dali-scene-loader/public-api/shader-definition.h" #include "dali-scene-loader/public-api/utils.h" +#include namespace Dali { @@ -36,7 +37,8 @@ ShaderDefinition::ShaderDefinition(const ShaderDefinition& other) mFragmentShaderPath(other.mFragmentShaderPath), mDefines(other.mDefines), mHints(other.mHints), - mUniforms(other.mUniforms) + mUniforms(other.mUniforms), + mUseBuiltInShader(false) { } @@ -80,28 +82,38 @@ ShaderDefinition::LoadRaw(const std::string& shadersPath) const { RawData raw; - bool fail = false; - raw.mVertexShaderSource = LoadTextFile((shadersPath + mVertexShaderPath).c_str(), &fail); - if(!fail) + bool fail = false; + if(!mUseBuiltInShader) { - raw.mFragmentShaderSource = LoadTextFile((shadersPath + mFragmentShaderPath).c_str(), &fail); + raw.mVertexShaderSource = LoadTextFile((shadersPath + mVertexShaderPath).c_str(), &fail); if(!fail) { - for(auto definevar : mDefines) + raw.mFragmentShaderSource = LoadTextFile((shadersPath + mFragmentShaderPath).c_str(), &fail); + if(fail) { - ApplyDefine(raw.mVertexShaderSource, definevar); - ApplyDefine(raw.mFragmentShaderSource, definevar); + ExceptionFlinger(ASSERT_LOCATION) << "Failed to load shader source from '" << shadersPath + mFragmentShaderPath << "'."; } } else { - ExceptionFlinger(ASSERT_LOCATION) << "Failed to load shader source from '" << shadersPath + mFragmentShaderPath << "'."; + ExceptionFlinger(ASSERT_LOCATION) << "Failed to load shader source from '" << shadersPath + mVertexShaderPath << "'."; } } else { - ExceptionFlinger(ASSERT_LOCATION) << "Failed to load shader source from '" << shadersPath + mVertexShaderPath << "'."; + raw.mVertexShaderSource = SHADER_DEFAULT_PHYSICALLY_BASED_SHADER_VERT.data(); + raw.mFragmentShaderSource = SHADER_DEFAULT_PHYSICALLY_BASED_SHADER_FRAG.data(); + } + + if(!fail) + { + for(auto definevar : mDefines) + { + ApplyDefine(raw.mVertexShaderSource, definevar); + ApplyDefine(raw.mFragmentShaderSource, definevar); + } } + return raw; } diff --git a/dali-scene-loader/public-api/shader-definition.h b/dali-scene-loader/public-api/shader-definition.h index d7f390b..5d0a49e 100644 --- a/dali-scene-loader/public-api/shader-definition.h +++ b/dali-scene-loader/public-api/shader-definition.h @@ -79,8 +79,8 @@ public: // DATA std::string mFragmentShaderPath; std::vector mDefines; std::vector mHints; - - Property::Map mUniforms; + Property::Map mUniforms; + bool mUseBuiltInShader; }; } // namespace SceneLoader diff --git a/dali-toolkit/devel-api/controls/scene3d-view/scene3d-view.h b/dali-toolkit/devel-api/controls/scene3d-view/scene3d-view.h index 1f0effb..756a7a5 100644 --- a/dali-toolkit/devel-api/controls/scene3d-view/scene3d-view.h +++ b/dali-toolkit/devel-api/controls/scene3d-view/scene3d-view.h @@ -80,15 +80,9 @@ public: // Scene doesn't use both of point and directional light NONE = 0, // Scene use point light - POINT_LIGHT, + POINT_LIGHT = 1, // Scene use directional light - DIRECTIONAL_LIGHT, - // Scene use Image Based Lighting - IMAGE_BASED_LIGHT, - // Scene use Image Based Lighting and point light - IMAGE_BASED_LIGHT_AND_POINT_LIGHT, - // Scene use Image Based Lighting and directional light - IMAGE_BASED_LIGHT_AND_DIRECTIONAL_LIGHT + DIRECTIONAL_LIGHT = 2 }; /** diff --git a/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp b/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp index 2c8de12..55dfd8d 100644 --- a/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp +++ b/dali-toolkit/internal/controls/scene3d-view/gltf-loader.cpp @@ -1509,7 +1509,7 @@ Actor Loader::AddNode(Scene3dView& scene3dView, uint32_t index) VERTEX_SHADER += SHADER_GLTF_PHYSICALLY_BASED_SHADER_VERT.data(); FRAGMENT_SHADER = SHADER_GLTF_GLES_VERSION_300_DEF.data(); - bool useIBL = (scene3dView.GetLightType() >= Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT); + bool useIBL = scene3dView.HasImageBasedLighting(); if(isMaterial) { MaterialInfo materialInfo = mMaterialArray[meshInfo.materialsIdx]; @@ -1592,11 +1592,14 @@ Actor Loader::AddNode(Scene3dView& scene3dView, uint32_t index) actor.RotateBy(orientation); actor.SetProperty(Actor::Property::POSITION, translation); - shader.RegisterProperty("uLightType", (scene3dView.GetLightType() & ~Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT)); + float hasLightSource = static_cast(!!(scene3dView.GetLightType() & (Toolkit::Scene3dView::LightType::POINT_LIGHT | Toolkit::Scene3dView::LightType::DIRECTIONAL_LIGHT))); + float isPointLight = static_cast(!!(scene3dView.GetLightType() & Toolkit::Scene3dView::LightType::POINT_LIGHT)); + shader.RegisterProperty("uHasLightSource", hasLightSource); + shader.RegisterProperty("uIsPointLight", isPointLight); shader.RegisterProperty("uLightVector", scene3dView.GetLightVector()); shader.RegisterProperty("uLightColor", scene3dView.GetLightColor()); - actor.RegisterProperty("uIsColor", meshInfo.attribute.COLOR.size() > 0); + actor.RegisterProperty("uHasVertexColor", meshInfo.attribute.COLOR.size() > 0 ? 1.0f : 0.0f); if(isMaterial) { MaterialInfo materialInfo = mMaterialArray[meshInfo.materialsIdx]; @@ -1605,15 +1608,15 @@ Actor Loader::AddNode(Scene3dView& scene3dView, uint32_t index) if(materialInfo.alphaMode == "OPAQUE") { - actor.RegisterProperty("alphaMode", 0); + actor.RegisterProperty("uAlphaMode", 0.0f); } else if(materialInfo.alphaMode == "MASK") { - actor.RegisterProperty("alphaMode", 1); + actor.RegisterProperty("uAlphaMode", 1.0f); } else { - actor.RegisterProperty("alphaMode", 2); + actor.RegisterProperty("uAlphaMode", 2.0f); } actor.RegisterProperty("alphaCutoff", materialInfo.alphaCutoff); diff --git a/dali-toolkit/internal/controls/scene3d-view/scene3d-view-impl.cpp b/dali-toolkit/internal/controls/scene3d-view/scene3d-view-impl.cpp index aa8438a..6231b64 100644 --- a/dali-toolkit/internal/controls/scene3d-view/scene3d-view-impl.cpp +++ b/dali-toolkit/internal/controls/scene3d-view/scene3d-view-impl.cpp @@ -54,7 +54,8 @@ Scene3dView::Scene3dView() mAnimationArray(), mLightType(Toolkit::Scene3dView::LightType::NONE), mLightVector(Vector3::ONE), - mLightColor(Vector3::ONE) + mLightColor(Vector3::ONE), + mUseIBL(false) { } @@ -130,20 +131,16 @@ bool Scene3dView::PlayAnimations() bool Scene3dView::SetLight(Toolkit::Scene3dView::LightType type, Vector3 lightVector, Vector3 lightColor) { - if(type > Toolkit::Scene3dView::LightType::DIRECTIONAL_LIGHT) - { - return false; - } - - mLightType = static_cast( - (mLightType >= Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT) ? Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT + type : type); - + mLightType = type; mLightVector = lightVector; mLightColor = lightColor; for(auto&& shader : mShaderArray) { - shader.RegisterProperty("uLightType", (GetLightType() & ~Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT)); + float hasLightSource = static_cast(!!(GetLightType() & (Toolkit::Scene3dView::LightType::POINT_LIGHT | Toolkit::Scene3dView::LightType::DIRECTIONAL_LIGHT))); + float isPointLight = static_cast(!!(GetLightType() & Toolkit::Scene3dView::LightType::POINT_LIGHT)); + shader.RegisterProperty("uHasLightSource", hasLightSource); + shader.RegisterProperty("uIsPointLight", isPointLight); shader.RegisterProperty("uLightVector", lightVector); shader.RegisterProperty("uLightColor", lightColor); } @@ -203,8 +200,6 @@ void Scene3dView::UploadTextureFace(Texture& texture, Devel::PixelBuffer pixelBu void Scene3dView::SetCubeMap(const std::string& diffuseTexturePath, const std::string& specularTexturePath, Vector4 scaleFactor) { - mLightType = Toolkit::Scene3dView::LightType::IMAGE_BASED_LIGHT; - // BRDF texture const std::string imageDirPath = AssetManager::GetDaliImagePath(); const std::string imageBrdfUrl = imageDirPath + IMAGE_BRDF_FILE_NAME; @@ -235,6 +230,7 @@ void Scene3dView::SetCubeMap(const std::string& diffuseTexturePath, const std::s mSpecularTexture.GenerateMipmaps(); mIBLScaleFactor = scaleFactor; + mUseIBL = true; } bool Scene3dView::SetDefaultCamera(const Dali::Camera::Type type, const float nearPlane, const Vector3 cameraPosition) @@ -318,6 +314,11 @@ Texture Scene3dView::GetSpecularTexture() return mSpecularTexture; } +bool Scene3dView::HasImageBasedLighting() +{ + return mUseIBL; +} + Texture Scene3dView::GetDiffuseTexture() { return mDiffuseTexture; diff --git a/dali-toolkit/internal/controls/scene3d-view/scene3d-view-impl.h b/dali-toolkit/internal/controls/scene3d-view/scene3d-view-impl.h index 6dbe859..bc731d3 100644 --- a/dali-toolkit/internal/controls/scene3d-view/scene3d-view-impl.h +++ b/dali-toolkit/internal/controls/scene3d-view/scene3d-view-impl.h @@ -185,6 +185,11 @@ public: */ Texture GetSpecularTexture(); + /** + * @brief Get whether the scene has image based rendering or not. + */ + bool HasImageBasedLighting(); + private: /** * @brief Get Cropped image buffer. @@ -232,6 +237,7 @@ private: Texture mBRDFTexture; // BRDF texture for the PBR rendering Texture mSpecularTexture; // Specular cube map texture Texture mDiffuseTexture; // Diffuse cube map texture + bool mUseIBL; private: // Undefined copy constructor. diff --git a/dali-toolkit/internal/controls/web-view/web-view-impl.cpp b/dali-toolkit/internal/controls/web-view/web-view-impl.cpp index 7fc2117..e3f2406 100755 --- a/dali-toolkit/internal/controls/web-view/web-view-impl.cpp +++ b/dali-toolkit/internal/controls/web-view/web-view-impl.cpp @@ -1246,6 +1246,8 @@ bool WebView::SetVisibility(bool visible) WebView::WebViewAccessible::WebViewAccessible(Dali::Actor self, Dali::WebEngine& webEngine) : ControlAccessible(self), mRemoteChild{}, mWebEngine{webEngine} { + mRemoteChild.SetParent(this); + Dali::Accessibility::Bridge::EnabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityEnabled); Dali::Accessibility::Bridge::DisabledSignal().Connect(this, &WebViewAccessible::OnAccessibilityDisabled); diff --git a/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp b/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp index a64690e..d0daa9f 100644 --- a/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp +++ b/dali-toolkit/internal/focus-manager/keyboard-focus-manager-impl.cpp @@ -205,53 +205,44 @@ bool KeyboardFocusManager::DoSetCurrentFocusActor(Actor actor) { bool success = false; - // If the parent's KEYBOARD_FOCUSABLE_CHILDREN is false, it cannot have focus. - if(actor) + // Check whether the actor is in the stage and is keyboard focusable. + if(actor && + actor.GetProperty(Actor::Property::KEYBOARD_FOCUSABLE) && + actor.GetProperty(DevelActor::Property::USER_INTERACTION_ENABLED) && + actor.GetProperty(Actor::Property::CONNECTED_TO_SCENE) && + actor.GetProperty(Actor::Property::VISIBLE)) { + // If the parent's KEYBOARD_FOCUSABLE_CHILDREN is false or VISIBLE is false, it cannot have focus. Actor parent = actor.GetParent(); while(parent) { - if(!parent.GetProperty(DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN)) + if(!parent.GetProperty(DevelActor::Property::KEYBOARD_FOCUSABLE_CHILDREN) || !parent.GetProperty(Actor::Property::VISIBLE)) { - DALI_LOG_INFO(gLogFilter, Debug::General, "[%s:%d] Parent Actor has KEYBOARD_FOCUSABLE_CHILDREN false,\n", __FUNCTION__, __LINE__); + DALI_LOG_INFO(gLogFilter, Debug::General, "[%s:%d] Parent Actor has KEYBOARD_FOCUSABLE_CHILDREN false or VISIBLE false,\n", __FUNCTION__, __LINE__); return false; } parent = parent.GetParent(); } - } - if(actor && actor.GetProperty(Actor::Property::KEYBOARD_FOCUSABLE) && actor.GetProperty(DevelActor::Property::USER_INTERACTION_ENABLED) && actor.GetProperty(Actor::Property::CONNECTED_TO_SCENE)) - { - Integration::SceneHolder currentWindow = Integration::SceneHolder::Get(actor); + // If developer set focus on same actor, doing nothing + Actor currentFocusedActor = GetCurrentFocusActor(); + if(actor == currentFocusedActor) + { + return true; + } + Integration::SceneHolder currentWindow = Integration::SceneHolder::Get(actor); if(currentWindow.GetRootLayer() != mCurrentFocusedWindow.GetHandle()) { Layer rootLayer = currentWindow.GetRootLayer(); mCurrentFocusedWindow = rootLayer; } - } - - Actor currentFocusedActor = GetCurrentFocusActor(); - - // If developer set focus on same actor, doing nothing - if(actor == currentFocusedActor) - { - if(!actor) - { - return false; - } - return true; - } - // Check whether the actor is in the stage and is keyboard focusable. - if(actor && actor.GetProperty(Actor::Property::KEYBOARD_FOCUSABLE) && actor.GetProperty(DevelActor::Property::USER_INTERACTION_ENABLED) && actor.GetProperty(Actor::Property::CONNECTED_TO_SCENE)) - { if((mIsFocusIndicatorShown == SHOW) && (mEnableFocusIndicator == ENABLE)) { actor.Add(GetFocusIndicatorActor()); } - Toolkit::Control currentlyFocusedControl = Toolkit::Control::DownCast(currentFocusedActor); if(currentlyFocusedControl) { diff --git a/dali-toolkit/internal/graphics/shaders/gltf-physically-based-shader.frag b/dali-toolkit/internal/graphics/shaders/gltf-physically-based-shader.frag index cefd19e..9477e40 100644 --- a/dali-toolkit/internal/graphics/shaders/gltf-physically-based-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/gltf-physically-based-shader.frag @@ -1,13 +1,13 @@ uniform lowp vec3 uLightColor; uniform lowp vec4 uBaseColorFactor; uniform lowp vec2 uMetallicRoughnessFactors; -uniform lowp int alphaMode; uniform lowp float alphaCutoff; +uniform lowp float uAlphaMode; +uniform lowp float uHasLightSource; in lowp vec2 vUV[2]; in lowp mat3 vTBN; in lowp vec4 vColor; -flat in int visLight; in highp vec3 vLightDirection; in highp vec3 vPositionToCamera; @@ -30,20 +30,20 @@ const float c_MinRoughness = 0.04; vec3 getNormal() { #ifdef TEXTURE_NORMAL - lowp vec3 n = texture( uNormalSampler, vUV[uNormalTexCoordIndex] ).rgb; - n = normalize( vTBN * ( ( 2.0 * n - 1.0 ) * vec3( uNormalScale, uNormalScale, 1.0 ) ) ); + lowp vec3 n = texture(uNormalSampler, vUV[uNormalTexCoordIndex]).rgb; + n = normalize(vTBN * ((2.0 * n - 1.0) * vec3(uNormalScale, uNormalScale, 1.0))); #else lowp vec3 n = normalize( vTBN[2].xyz ); #endif return n; } -vec3 specularReflection( PBRInfo pbrInputs ) +vec3 specularReflection(PBRInfo pbrInputs) { - return pbrInputs.reflectance0 + ( pbrInputs.reflectance90 - pbrInputs.reflectance0 ) * pow( clamp( 1.0 - pbrInputs.VdotH, 0.0, 1.0 ), 5.0 ); + return pbrInputs.reflectance0 + (pbrInputs.reflectance90 - pbrInputs.reflectance0) * pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0); } -float geometricOcclusion( PBRInfo pbrInputs ) +float geometricOcclusion(PBRInfo pbrInputs) { mediump float NdotL = pbrInputs.NdotL; mediump float NdotV = pbrInputs.NdotV; @@ -61,7 +61,7 @@ float microfacetDistribution(PBRInfo pbrInputs) return roughnessSq / (M_PI * f * f); } -vec3 linear( vec3 color ) +vec3 linear(vec3 color) { return pow(color,vec3(2.2)); } @@ -96,13 +96,13 @@ void main() lowp vec4 baseColor = vColor * uBaseColorFactor; #endif - if( alphaMode == 0 ) + if(uAlphaMode < 0.5f) { baseColor.w = 1.0; } - else if( alphaMode == 1 ) + else if(uAlphaMode < 1.5f) { - if( baseColor.w >= alphaCutoff ) + if(baseColor.w >= alphaCutoff) { baseColor.w = 1.0; } @@ -150,7 +150,7 @@ void main() // Calculate the shading terms for the microfacet specular shading model lowp vec3 color = vec3(0.0); - if( visLight == 1 ) + if( uHasLightSource > 0.5f ) { lowp vec3 F = specularReflection( pbrInputs ); lowp float G = geometricOcclusion( pbrInputs ); diff --git a/dali-toolkit/internal/graphics/shaders/gltf-physically-based-shader.vert b/dali-toolkit/internal/graphics/shaders/gltf-physically-based-shader.vert index 6628865..095e839 100644 --- a/dali-toolkit/internal/graphics/shaders/gltf-physically-based-shader.vert +++ b/dali-toolkit/internal/graphics/shaders/gltf-physically-based-shader.vert @@ -9,51 +9,34 @@ uniform mediump vec3 uSize; uniform mediump mat4 uModelMatrix; uniform mediump mat4 uViewMatrix; uniform mediump mat4 uProjection; -uniform lowp int uLightType; uniform mediump vec3 uLightVector; -uniform lowp int uIsColor; +uniform lowp float uIsPointLight; +uniform lowp float uHasVertexColor; out lowp vec2 vUV[2]; out lowp mat3 vTBN; out lowp vec4 vColor; -flat out int visLight; out highp vec3 vLightDirection; out highp vec3 vPositionToCamera; void main() { highp vec4 invY = vec4(1.0, -1.0, 1.0, 1.0); - highp vec4 positionW = uModelMatrix * vec4( aPosition * uSize, 1.0 ); - highp vec4 positionV = uViewMatrix * ( invY * positionW ); + highp vec4 positionW = uModelMatrix * vec4(aPosition * uSize, 1.0); + highp vec4 positionV = uViewMatrix * (invY * positionW); - vPositionToCamera = transpose( mat3( uViewMatrix ) ) * ( -vec3( positionV.xyz / positionV.w ) ); + vPositionToCamera = transpose(mat3(uViewMatrix)) * (-vec3(positionV.xyz / positionV.w)); vPositionToCamera *= invY.xyz; lowp vec3 bitangent = cross(aNormal, aTangent.xyz) * aTangent.w; - vTBN = mat3( uModelMatrix ) * mat3(aTangent.xyz, bitangent, aNormal); + vTBN = mat3(uModelMatrix) * mat3(aTangent.xyz, bitangent, aNormal); vUV[0] = aTexCoord0; vUV[1] = aTexCoord1; - visLight = 1; - if( uLightType == 1 ) - { - vLightDirection = ( invY.xyz * uLightVector ) - ( positionW.xyz / positionW.w ); - } - else if( uLightType == 2 ) - { - vLightDirection = -( invY.xyz * uLightVector ); - } - else - { - visLight = 0; - } - - vColor = vec4( 1.0 ); - if( uIsColor == 1 ) - { - vColor = aVertexColor; - } + vLightDirection = mix(-(invY.xyz * uLightVector), (invY.xyz * uLightVector) - (positionW.xyz / positionW.w), uIsPointLight); + + vColor = mix(vec4(1.0f), aVertexColor, uHasVertexColor); gl_Position = uProjection * positionV; // needs w for proper perspective correction gl_Position = gl_Position/gl_Position.w; diff --git a/dali-toolkit/internal/text/text-controller-background-actor.cpp b/dali-toolkit/internal/text/text-controller-background-actor.cpp index 7def7e8..bc7c79b 100644 --- a/dali-toolkit/internal/text/text-controller-background-actor.cpp +++ b/dali-toolkit/internal/text/text-controller-background-actor.cpp @@ -112,7 +112,6 @@ Actor CreateControllerBackgroundActor(const View& textView, const VisualModelPtr Length yLineOffset = 0; Length prevLineIndex = 0; LineIndex lineIndex; - Length numberOfLines; for(uint32_t i = 0, glyphSize = glyphs.Size(); i < glyphSize; ++i) { @@ -125,7 +124,7 @@ Actor CreateControllerBackgroundActor(const View& textView, const VisualModelPtr const bool isDefaultBackgroundColor = (0u == backgroundColorIndex); const Vector4& backgroundColor = isDefaultBackgroundColor ? defaultBackgroundColor : *(backgroundColorsBuffer + backgroundColorIndex - 1u); - textVisualModel->GetNumberOfLines(i, 1, lineIndex, numberOfLines); + lineIndex = textVisualModel->GetLineOfGlyph(i); Length lineHeight = CalculateBackgroundLineHeight(lineRun[lineIndex]); if(lineIndex != prevLineIndex) diff --git a/dali-toolkit/internal/text/text-controller-event-handler.cpp b/dali-toolkit/internal/text/text-controller-event-handler.cpp index d5c41a1..1d4be23 100644 --- a/dali-toolkit/internal/text/text-controller-event-handler.cpp +++ b/dali-toolkit/internal/text/text-controller-event-handler.cpp @@ -809,6 +809,21 @@ InputMethodContext::CallbackData Controller::EventHandler::OnInputMethodContextE retrieveCursor = true; break; } + case InputMethodContext::SELECTION_SET: + { + uint32_t start = static_cast(inputMethodContextEvent.startIndex); + uint32_t end = static_cast(inputMethodContextEvent.endIndex); + if(start == end) + { + controller.SetPrimaryCursorPosition(start, true); + } + else + { + controller.SelectText(start, end); + } + + break; + } case InputMethodContext::VOID: { // do nothing diff --git a/dali-toolkit/internal/text/text-geometry.cpp b/dali-toolkit/internal/text/text-geometry.cpp index bde5517..6c90665 100644 --- a/dali-toolkit/internal/text/text-geometry.cpp +++ b/dali-toolkit/internal/text/text-geometry.cpp @@ -160,7 +160,7 @@ void GetTextGeometry(ModelPtr textModel, CharacterIndex startIndex, CharacterInd } else { - if((ellipsisPosition == DevelText::EllipsisPosition::END) && (index >= endIndexOfGlyphs)) + if((ellipsisPosition == DevelText::EllipsisPosition::END) && (index > endIndexOfGlyphs)) { //skip remaining elided glyphs break; diff --git a/dali-toolkit/internal/text/text-selection-handle-controller.cpp b/dali-toolkit/internal/text/text-selection-handle-controller.cpp index 05d8ad5..e4bf91c 100644 --- a/dali-toolkit/internal/text/text-selection-handle-controller.cpp +++ b/dali-toolkit/internal/text/text-selection-handle-controller.cpp @@ -286,12 +286,7 @@ void SelectionHandleController::Reposition(Controller::Impl& impl) selectionBoxInfo->maxX = MIN_FLOAT; // Update the line's vertical offset. - selectionBoxInfo->lineOffset = currentLineOffset + currentLineHeight; - - if(currentLineSpacing < 0) - { - selectionBoxInfo->lineOffset += currentLineSpacing; - } + selectionBoxInfo->lineOffset = currentLineOffset + currentLineHeight + currentLineSpacing; // The line height is the addition of the line ascender and the line descender. // However, the line descender has a negative value, hence the subtraction also line spacing should not be included in selection height. diff --git a/dali-toolkit/internal/text/text-view.cpp b/dali-toolkit/internal/text/text-view.cpp index 697dc04..9c067de 100644 --- a/dali-toolkit/internal/text/text-view.cpp +++ b/dali-toolkit/internal/text/text-view.cpp @@ -114,7 +114,6 @@ Length View::GetGlyphs(GlyphInfo* glyphs, float calculatedAdvance = 0.f; const Character* textBuffer = mImpl->mLogicalModel->mText.Begin(); - if(mImpl->mVisualModel) { // Get the character-spacing runs. @@ -125,7 +124,7 @@ Length View::GetGlyphs(GlyphInfo* glyphs, //Reset indices of ElidedGlyphs mImpl->mVisualModel->SetStartIndexOfElidedGlyphs(0u); - mImpl->mVisualModel->SetEndIndexOfElidedGlyphs(numberOfGlyphs); + mImpl->mVisualModel->SetEndIndexOfElidedGlyphs(numberOfGlyphs - 1u); // Initialization is the last index of Glyphs mImpl->mVisualModel->SetFirstMiddleIndexOfElidedGlyphs(0u); mImpl->mVisualModel->SetSecondMiddleIndexOfElidedGlyphs(0u); diff --git a/dali-toolkit/internal/text/visual-model-impl.cpp b/dali-toolkit/internal/text/visual-model-impl.cpp index 5ef2b50..490bae3 100644 --- a/dali-toolkit/internal/text/visual-model-impl.cpp +++ b/dali-toolkit/internal/text/visual-model-impl.cpp @@ -254,6 +254,12 @@ void VisualModel::GetNumberOfLines(GlyphIndex glyphIndex, } } +LineIndex VisualModel::GetLineOfGlyph( GlyphIndex glyphIndex ) +{ + const CharacterIndex characterIndex = *(mGlyphsToCharacters.Begin() + glyphIndex); + return GetLineOfCharacter(characterIndex); +} + void VisualModel::GetLinesOfGlyphRange(LineRun* lines, GlyphIndex glyphIndex, Length numberOfGlyphs) const diff --git a/dali-toolkit/internal/text/visual-model-impl.h b/dali-toolkit/internal/text/visual-model-impl.h index 9c0af3a..eebbe18 100644 --- a/dali-toolkit/internal/text/visual-model-impl.h +++ b/dali-toolkit/internal/text/visual-model-impl.h @@ -144,6 +144,15 @@ public: Length& numberOfLines) const; /** + * @brief Retrieves the line index where the glyph is laid-out. + * + * @param[in] glyphIndex The glyph's index. + * + * @return The line index. + */ + LineIndex GetLineOfGlyph(GlyphIndex glyphIndex); + + /** * @brief Retrieves the lines where the given range of glyphs is laid out. * * The size of the @p lines buffer needs to be big enough to copy the @p numberOfLines. diff --git a/dali-toolkit/internal/texture-manager/texture-cache-manager.cpp b/dali-toolkit/internal/texture-manager/texture-cache-manager.cpp index 9524c44..cc90fd8 100644 --- a/dali-toolkit/internal/texture-manager/texture-cache-manager.cpp +++ b/dali-toolkit/internal/texture-manager/texture-cache-manager.cpp @@ -326,7 +326,8 @@ TextureCacheManager::TextureHash TextureCacheManager::GenerateHash( const Dali::FittingMode::Type& fittingMode, const Dali::SamplingMode::Type& samplingMode, const TextureCacheManager::UseAtlas& useAtlas, - const TextureCacheManager::TextureId& maskTextureId) + const TextureCacheManager::TextureId& maskTextureId, + const bool& cropToMask) { std::vector hashTarget(url.begin(), url.end()); const size_t urlLength = url.length(); @@ -374,7 +375,7 @@ TextureCacheManager::TextureHash TextureCacheManager::GenerateHash( if(maskTextureId != INVALID_TEXTURE_ID) { auto textureIdIndex = hashTarget.size(); - hashTarget.resize(hashTarget.size() + sizeof(TextureId)); + hashTarget.resize(hashTarget.size() + sizeof(TextureId) + 1u); std::uint8_t* hashTargetPtr = reinterpret_cast(&(hashTarget[textureIdIndex])); // Append the texture id to the end of the URL byte by byte: @@ -385,6 +386,7 @@ TextureCacheManager::TextureHash TextureCacheManager::GenerateHash( *hashTargetPtr++ = saltedMaskTextureId & 0xff; saltedMaskTextureId >>= 8u; } + *hashTargetPtr++ = (cropToMask ? 'C' : 'M'); } return Dali::CalculateHash(hashTarget); @@ -399,7 +401,8 @@ TextureCacheManager::TextureCacheIndex TextureCacheManager::FindCachedTexture( const TextureCacheManager::UseAtlas& useAtlas, const TextureCacheManager::TextureId& maskTextureId, const TextureCacheManager::MultiplyOnLoad& preMultiplyOnLoad, - bool isAnimatedImage) + bool isAnimatedImage, + const bool& cropToMask) { // Default to an invalid ID, in case we do not find a match. TextureCacheIndex cacheIndex = INVALID_CACHE_INDEX; @@ -416,6 +419,7 @@ TextureCacheManager::TextureCacheIndex TextureCacheManager::FindCachedTexture( if((url == textureInfo.url.GetUrl()) && (useAtlas == textureInfo.useAtlas) && (maskTextureId == textureInfo.maskTextureId) && + (cropToMask == textureInfo.cropToMask) && (size == textureInfo.desiredSize) && (isAnimatedImage == textureInfo.isAnimatedImageFormat) && ((size.GetWidth() == 0 && size.GetHeight() == 0) || diff --git a/dali-toolkit/internal/texture-manager/texture-cache-manager.h b/dali-toolkit/internal/texture-manager/texture-cache-manager.h index 7d941d1..3196e24 100644 --- a/dali-toolkit/internal/texture-manager/texture-cache-manager.h +++ b/dali-toolkit/internal/texture-manager/texture-cache-manager.h @@ -184,6 +184,7 @@ public: * @param[in] samplingMode The SamplingMode to use * @param[in] useAtlas True if atlased * @param[in] maskTextureId The masking texture id (or INVALID_TEXTURE_ID) + * @param[in] cropToMask True if crop to mask * @return A hash of the provided data for caching. */ TextureCacheManager::TextureHash GenerateHash( @@ -192,7 +193,8 @@ public: const Dali::FittingMode::Type& fittingMode, const Dali::SamplingMode::Type& samplingMode, const TextureCacheManager::UseAtlas& useAtlas, - const TextureCacheManager::TextureId& maskTextureId); + const TextureCacheManager::TextureId& maskTextureId, + const bool& cropToMask); /** * @brief Looks up a cached texture by its hash. @@ -206,6 +208,7 @@ public: * @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] isAnimatedImage True if the texture is from animated image. + * @param[in] cropToMask True if crop to mask * @return A TextureCacheId of a cached Texture if found. Or INVALID_CACHE_INDEX if not found. */ TextureCacheManager::TextureCacheIndex FindCachedTexture( @@ -217,7 +220,8 @@ public: const TextureCacheManager::UseAtlas& useAtlas, const TextureCacheManager::TextureId& maskTextureId, const TextureCacheManager::MultiplyOnLoad& preMultiplyOnLoad, - bool isAnimatedImage); + bool isAnimatedImage, + const bool& cropToMask); /** * @brief Append a Texture to the TextureCacheManager. diff --git a/dali-toolkit/internal/texture-manager/texture-manager-impl.cpp b/dali-toolkit/internal/texture-manager/texture-manager-impl.cpp index ff81b22..a3cb054 100644 --- a/dali-toolkit/internal/texture-manager/texture-manager-impl.cpp +++ b/dali-toolkit/internal/texture-manager/texture-manager-impl.cpp @@ -468,10 +468,10 @@ TextureManager::TextureId TextureManager::RequestLoadInternal( TextureCacheIndex cacheIndex = INVALID_CACHE_INDEX; if(storageType != StorageType::RETURN_PIXEL_BUFFER && useCache) { - textureHash = mTextureCacheManager.GenerateHash(url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId); + textureHash = mTextureCacheManager.GenerateHash(url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, cropToMask); // 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, (animatedImageLoading) ? true : false); + cacheIndex = mTextureCacheManager.FindCachedTexture(textureHash, url.GetUrl(), desiredSize, fittingMode, samplingMode, useAtlas, maskTextureId, preMultiplyOnLoad, (animatedImageLoading) ? true : false, cropToMask); } TextureManager::TextureId textureId = INVALID_TEXTURE_ID; diff --git a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp index 440dbd4..a7d1f76 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp +++ b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.cpp @@ -190,6 +190,15 @@ void AnimatedVectorImageVisual::DoCreateInstancePropertyMap(Property::Map& map) // Do nothing } +void AnimatedVectorImageVisual::EnablePreMultipliedAlpha(bool preMultiplied) +{ + // Make always enable pre multiplied alpha whether preMultiplied value is false. + if(!preMultiplied) + { + DALI_LOG_WARNING("Note : AnimatedVectorVisual cannot disable PreMultipliedAlpha\n"); + } +} + void AnimatedVectorImageVisual::DoSetProperties(const Property::Map& propertyMap) { // url already passed in from constructor diff --git a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h index 4f1a859..4b14fc3 100644 --- a/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h +++ b/dali-toolkit/internal/visuals/animated-vector-image/animated-vector-image-visual.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_INTERNAL_ANIMATED_VECTOR_IMAGE_VISUAL_H /* - * 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. @@ -93,6 +93,11 @@ public: // from Visual */ void DoCreateInstancePropertyMap(Property::Map& map) const override; + /** + * @copydoc Visual::Base::EnablePreMultipliedAlpha + */ + void EnablePreMultipliedAlpha(bool preMultiplied) override; + protected: // From VectorAnimationManager::LifecycleObserver: /** * @copydoc VectorAnimationManager::LifecycleObserver::VectorAnimationManagerDestroyed() diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index 60899bd..8dfc168 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.cpp +++ b/dali-toolkit/internal/visuals/color/color-visual.cpp @@ -176,6 +176,15 @@ void ColorVisual::DoCreateInstancePropertyMap(Property::Map& map) const // Do nothing } +void ColorVisual::EnablePreMultipliedAlpha(bool preMultiplied) +{ + // Make always disable pre multiplied alpha whether preMultiplied value is true. + if(preMultiplied) + { + DALI_LOG_WARNING("Note : ColorVisual cannot enable PreMultipliedAlpha\n"); + } +} + void ColorVisual::OnSetTransform() { if(mImpl->mRenderer) diff --git a/dali-toolkit/internal/visuals/color/color-visual.h b/dali-toolkit/internal/visuals/color/color-visual.h index 5edf2ba..bb8bc95 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.h +++ b/dali-toolkit/internal/visuals/color/color-visual.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_INTERNAL_COLOR_VISUAL_H /* - * 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. @@ -65,6 +65,11 @@ public: // from Visual */ void DoCreateInstancePropertyMap(Property::Map& map) const override; + /** + * @copydoc Visual::Base::EnablePreMultipliedAlpha + */ + void EnablePreMultipliedAlpha(bool preMultiplied) override; + protected: /** * @brief Constructor. diff --git a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp index 648ffcc..cef1ef4 100644 --- a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp +++ b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp @@ -238,6 +238,15 @@ void GradientVisual::DoCreateInstancePropertyMap(Property::Map& map) const // Do nothing } +void GradientVisual::EnablePreMultipliedAlpha(bool preMultiplied) +{ + // Make always enable pre multiplied alpha whether preMultiplied value is false. + if(!preMultiplied) + { + DALI_LOG_WARNING("Note : GradientVisual cannot disable PreMultipliedAlpha\n"); + } +} + void GradientVisual::OnInitialize() { Geometry geometry = mFactoryCache.GetGeometry(VisualFactoryCache::QUAD_GEOMETRY); diff --git a/dali-toolkit/internal/visuals/gradient/gradient-visual.h b/dali-toolkit/internal/visuals/gradient/gradient-visual.h index 40223b8..9a471d4 100644 --- a/dali-toolkit/internal/visuals/gradient/gradient-visual.h +++ b/dali-toolkit/internal/visuals/gradient/gradient-visual.h @@ -2,7 +2,7 @@ #define DALI_TOOLKIT_INTERNAL_GRADIENT_VISUAL_H /* - * 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. @@ -101,6 +101,11 @@ public: // from Visual */ void DoCreateInstancePropertyMap(Property::Map& map) const override; + /** + * @copydoc Visual::Base::EnablePreMultipliedAlpha + */ + void EnablePreMultipliedAlpha(bool preMultiplied) override; + protected: /** * @brief Constructor. diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.cpp b/dali-toolkit/internal/visuals/svg/svg-visual.cpp index 80c6958..9a47462 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.cpp +++ b/dali-toolkit/internal/visuals/svg/svg-visual.cpp @@ -208,6 +208,15 @@ void SvgVisual::DoCreateInstancePropertyMap(Property::Map& map) const // Do nothing } +void SvgVisual::EnablePreMultipliedAlpha(bool preMultiplied) +{ + // Make always enable pre multiplied alpha whether preMultiplied value is false. + if(!preMultiplied) + { + DALI_LOG_WARNING("Note : SvgVisual cannot disable PreMultipliedAlpha\n"); + } +} + void SvgVisual::Load() { // load remote resource on svg rasterize thread. diff --git a/dali-toolkit/internal/visuals/svg/svg-visual.h b/dali-toolkit/internal/visuals/svg/svg-visual.h index 2f49e16..c005691 100644 --- a/dali-toolkit/internal/visuals/svg/svg-visual.h +++ b/dali-toolkit/internal/visuals/svg/svg-visual.h @@ -92,6 +92,11 @@ public: // from Visual */ void DoCreateInstancePropertyMap(Property::Map& map) const override; + /** + * @copydoc Visual::Base::EnablePreMultipliedAlpha + */ + void EnablePreMultipliedAlpha(bool preMultiplied) override; + protected: /** * @brief Constructor. diff --git a/dali-toolkit/internal/visuals/text/text-visual.cpp b/dali-toolkit/internal/visuals/text/text-visual.cpp index a7d6ae7..9b0e811 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.cpp +++ b/dali-toolkit/internal/visuals/text/text-visual.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include // INTERNAL HEADER @@ -239,6 +240,15 @@ void TextVisual::DoCreateInstancePropertyMap(Property::Map& map) const map.Insert(Toolkit::TextVisual::Property::TEXT, text); } +void TextVisual::EnablePreMultipliedAlpha(bool preMultiplied) +{ + // Make always enable pre multiplied alpha whether preMultiplied value is false. + if(!preMultiplied) + { + DALI_LOG_WARNING("Note : TextVisual cannot disable PreMultipliedAlpha\n"); + } +} + TextVisual::TextVisual(VisualFactoryCache& factoryCache) : Visual::Base(factoryCache, Visual::FittingMode::FIT_KEEP_ASPECT_RATIO, Toolkit::Visual::TEXT), mController(Text::Controller::New()), @@ -247,6 +257,8 @@ TextVisual::TextVisual(VisualFactoryCache& factoryCache) mTextColorAnimatableIndex(Property::INVALID_INDEX), mRendererUpdateNeeded(false) { + // Enable the pre-multiplied alpha to improve the text quality + mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA; } TextVisual::~TextVisual() @@ -294,9 +306,6 @@ void TextVisual::DoSetOnScene(Actor& actor) mImpl->mRenderer.SetProperty(Dali::Renderer::Property::DEPTH_INDEX, Toolkit::DepthIndex::CONTENT); - // Enable the pre-multiplied alpha to improve the text quality - EnablePreMultipliedAlpha(true); - const Vector4& defaultColor = mController->GetTextModel()->GetDefaultColor(); if(mTextColorAnimatableIndex == Property::INVALID_INDEX) { diff --git a/dali-toolkit/internal/visuals/text/text-visual.h b/dali-toolkit/internal/visuals/text/text-visual.h index 8474441..fa7ca4e 100644 --- a/dali-toolkit/internal/visuals/text/text-visual.h +++ b/dali-toolkit/internal/visuals/text/text-visual.h @@ -143,6 +143,11 @@ public: // from Visual::Base */ void DoCreateInstancePropertyMap(Property::Map& map) const override; + /** + * @copydoc Visual::Base::EnablePreMultipliedAlpha + */ + void EnablePreMultipliedAlpha(bool preMultiplied) override; + protected: /** * @brief Constructor. diff --git a/dali-toolkit/internal/visuals/visual-base-impl.cpp b/dali-toolkit/internal/visuals/visual-base-impl.cpp index 953e23e..960a9fd 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.cpp +++ b/dali-toolkit/internal/visuals/visual-base-impl.cpp @@ -613,12 +613,18 @@ void Visual::Base::CreatePropertyMap(Property::Map& map) const mImpl->mFittingMode, VISUAL_FITTING_MODE_TABLE, VISUAL_FITTING_MODE_TABLE_COUNT); map.Insert(Toolkit::DevelVisual::Property::VISUAL_FITTING_MODE, fittingModeString); - map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, mImpl->mBorderlineWidth); - map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, mImpl->mBorderlineColor); - map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, mImpl->mBorderlineOffset); + if(IsTypeAvailableForBorderline(mImpl->mType)) + { + map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_WIDTH, mImpl->mBorderlineWidth); + map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_COLOR, mImpl->mBorderlineColor); + map.Insert(Toolkit::DevelVisual::Property::BORDERLINE_OFFSET, mImpl->mBorderlineOffset); + } - map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS, mImpl->mCornerRadius); - map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, static_cast(mImpl->mCornerRadiusPolicy)); + if(IsTypeAvailableForCornerRadius(mImpl->mType)) + { + map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS, mImpl->mCornerRadius); + map.Insert(Toolkit::DevelVisual::Property::CORNER_RADIUS_POLICY, static_cast(mImpl->mCornerRadiusPolicy)); + } } void Visual::Base::CreateInstancePropertyMap(Property::Map& map) const diff --git a/dali-toolkit/internal/visuals/visual-base-impl.h b/dali-toolkit/internal/visuals/visual-base-impl.h index 336a62d..20b0bd9 100644 --- a/dali-toolkit/internal/visuals/visual-base-impl.h +++ b/dali-toolkit/internal/visuals/visual-base-impl.h @@ -155,7 +155,7 @@ public: * * @param[in] preMultiplied whether alpha is pre-multiplied. */ - void EnablePreMultipliedAlpha(bool preMultiplied); + virtual void EnablePreMultipliedAlpha(bool preMultiplied); /** * @brief Query whether alpha is pre-multiplied. diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp index 271b826..9b10ffd 100644 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -581,7 +581,31 @@ void Control::OnPropertySet(Property::Index index, const Property::Value& proper } case Actor::Property::VISIBLE: { - GetAccessibleObject()->EmitVisible(Self().GetProperty(Actor::Property::VISIBLE)); + const bool visible = propertyValue.Get(); + GetAccessibleObject()->EmitVisible(visible); + if(!visible) + { + Dali::Actor self = Self(); + Dali::Actor actor = Dali::Toolkit::KeyboardFocusManager::Get().GetCurrentFocusActor(); + while(actor) + { + if(self == actor) + { + Dali::Toolkit::KeyboardFocusManager::Get().ClearFocus(); + break; + } + actor = actor.GetParent(); + } + } + break; + } + case DevelActor::Property::USER_INTERACTION_ENABLED: + { + const bool enabled = propertyValue.Get(); + if (!enabled && Self() == Dali::Toolkit::KeyboardFocusManager::Get().GetCurrentFocusActor()) + { + Dali::Toolkit::KeyboardFocusManager::Get().ClearFocus(); + } break; } } diff --git a/dali-toolkit/public-api/dali-toolkit-version.cpp b/dali-toolkit/public-api/dali-toolkit-version.cpp index 9630b37..e704530 100644 --- a/dali-toolkit/public-api/dali-toolkit-version.cpp +++ b/dali-toolkit/public-api/dali-toolkit-version.cpp @@ -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 = 18; +const unsigned int TOOLKIT_MICRO_VERSION = 19; const char* const TOOLKIT_BUILD_DATE = __DATE__ " " __TIME__; #ifdef DEBUG_ENABLED diff --git a/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json b/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json index 3b5d1ce..62b232d 100644 --- a/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json +++ b/dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json @@ -98,36 +98,35 @@ }, "TextSelectionPopup": { - "popupMaxSize":[656,36], - "optionDividerSize":[1,0], - "optionDividerPadding":[0.0,0.0,6.0,6.0], - "popupDividerColor":[1.0,1.0,1.0,1.0], + "popupMaxSize":[656,40], + "optionDividerSize":[0,0], + "optionDividerPadding":[0.0,0.0,0.0,0.0], + "popupDividerColor":[0.0,0.0,0.0,1.0], "popupIconColor":[1.0,1.0,1.0,1.0], "popupPressedColor":[0.24,0.72,0.8,0.11], "background": { "visualType": "IMAGE", - "url": "{DALI_IMAGE_DIR}IoT-selection-popup-background.9.png", - "mixColor":[0.0,0.05,0.17,0.9] + "url": "{DALI_IMAGE_DIR}IoT-selection-popup-background.9.png" }, "backgroundBorder": { "visualType": "IMAGE", - "url": "{DALI_IMAGE_DIR}selection-popup-border.9.png", - "mixColor":[0.0,0.0,0.0,0.0] + "url": "{DALI_IMAGE_DIR}IoT-selection-popup-border.9.png", + "mixColor":[1.0,1.0,1.0,1.0] }, "popupFadeInDuration":0.25, "popupFadeOutDuration":0.25 }, "TextSelectionPopupButton": { - "minimumSize":[0,36], - "labelPadding":[0.0,0.0,0.0,0.0], + "minimumSize":[0,40], + "labelPadding":[-4.0,-4.0,0.0,0.0], "label": { "visualType":"TEXT", - "pointSize":18, - "textColor":[1.0,1.0,1.0,1.0], - "fontFamily":"BreezeSans", - "fontStyle" : {"weight":"light"} + "pointSize":6.0, + "textColor":[0.04,0.06,0.13,1.0], + "fontFamily":"SamsungOneUI", + "fontStyle" : {"weight":"regular"} }, "unselectedBackgroundVisual": { diff --git a/dali-toolkit/styles/images-common/IoT-selection-popup-background.9.png b/dali-toolkit/styles/images-common/IoT-selection-popup-background.9.png index 7903ae2..b27254b 100644 Binary files a/dali-toolkit/styles/images-common/IoT-selection-popup-background.9.png and b/dali-toolkit/styles/images-common/IoT-selection-popup-background.9.png differ diff --git a/dali-toolkit/styles/images-common/IoT-selection-popup-border.9.png b/dali-toolkit/styles/images-common/IoT-selection-popup-border.9.png new file mode 100644 index 0000000..553056e Binary files /dev/null and b/dali-toolkit/styles/images-common/IoT-selection-popup-border.9.png differ diff --git a/packaging/dali-toolkit.spec b/packaging/dali-toolkit.spec index c115b60..c2a9846 100644 --- a/packaging/dali-toolkit.spec +++ b/packaging/dali-toolkit.spec @@ -1,6 +1,6 @@ Name: dali2-toolkit Summary: Dali 3D engine Toolkit -Version: 2.1.18 +Version: 2.1.19 Release: 1 Group: System/Libraries License: Apache-2.0 and BSD-3-Clause and MIT