2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
24 // Internal headers are allowed here
26 #include <dali/internal/event/common/thread-local-storage.h>
27 #include <dali/internal/update/resources/resource-manager.h>
28 #include <dali/internal/event/resources/resource-client.h>
29 #include <dali/internal/event/resources/resource-ticket.h>
30 #include <dali/internal/update/modeling/scene-graph-mesh.h>
33 #include "mesh-builder.h"
35 void utc_dali_mesh_startup(void)
37 test_return_value = TET_UNDEF;
40 void utc_dali_mesh_cleanup(void)
42 test_return_value = TET_PASS;
48 unsigned int GetNextResourceId(TestApplication& application)
50 // Attempt to determine what the next resource ID will be
51 Internal::ResourceClient& resourceClient = Internal::ThreadLocalStorage::Get().GetResourceClient();
52 Internal::ResourceTicketPtr resourceTicket = resourceClient.AllocateTexture( 80, 80, Pixel::RGBA8888 );
53 unsigned int nextResourceId = resourceTicket->GetId();
56 // Clear allocation request through the system
57 application.SendNotification();
59 application.SendNotification();
61 return nextResourceId;
64 Mesh CreateMesh( TestApplication& application )
66 Dali::MeshData publicMeshData;
68 MeshData::VertexContainer publicVertices;
69 MeshData::FaceIndices publicFaces;
71 ConstructVertices(publicVertices, 60);
72 ConstructFaces(publicVertices, publicFaces);
73 Dali::Material material = ConstructMaterial();
74 publicMeshData.SetData(publicVertices, publicFaces, bones, material);
76 Mesh publicMesh = Mesh::New(publicMeshData); // Will generate new request
78 application.SendNotification();
79 application.Render(); // Should allocate mesh, pass ownership to ResourceManager
80 application.SendNotification();
84 Internal::MeshData& GetStagedMeshData( unsigned int resourceId )
86 // ResourceManager::GetMesh() will give us the scene graph mesh from resource id
87 Internal::ResourceManager& resourceManager = Internal::ThreadLocalStorage::Get().GetResourceManager();
88 Internal::SceneGraph::Mesh* internalMesh = resourceManager.GetMesh(resourceId);
89 DALI_TEST_CHECK( internalMesh != NULL );
90 return internalMesh->GetMeshData(Internal::SceneGraph::Mesh::UPDATE_THREAD);
94 void TestMeshDiscard( ResourcePolicy::DataRetention policy, bool expectedDiscardResult )
96 TestApplication application( TestApplication::DEFAULT_SURFACE_WIDTH,
97 TestApplication::DEFAULT_SURFACE_HEIGHT,
98 TestApplication::DEFAULT_HORIZONTAL_DPI,
99 TestApplication::DEFAULT_VERTICAL_DPI,
102 // run through startup, clearing all requests/messages
103 application.SendNotification();
104 application.Render();
105 application.SendNotification();
107 unsigned int nextResourceId = GetNextResourceId(application);
108 Mesh publicMesh = CreateMesh(application);
109 Internal::MeshData& meshData = GetStagedMeshData(nextResourceId);
111 // Check that the vertex data is allocated
112 const Internal::MeshData::VertexContainer& internalVertices = meshData.GetVertices();
113 const Internal::MeshData::FaceIndices& internalFaces = meshData.GetFaces();
114 DALI_TEST_CHECK( meshData.GetVertexCount() > 0 );
115 DALI_TEST_CHECK( meshData.GetFaceCount() > 0 );
116 DALI_TEST_CHECK( internalVertices.size() > 0 );
117 DALI_TEST_CHECK( internalFaces.size() > 0 );
119 // Create an actor that will render the mesh
120 MeshActor actor = MeshActor::New( publicMesh );
121 std::string name = "AMeshActor";
123 Stage::GetCurrent().Add(actor);
126 application.SendNotification();
127 application.Render();
128 application.SendNotification();
130 // Check that the vertex data has been discarded
131 DALI_TEST_CHECK( meshData.GetVertexCount() > 0 );
132 DALI_TEST_CHECK( meshData.GetFaceCount() > 0 );
133 if( expectedDiscardResult == false )
135 DALI_TEST_CHECK( internalVertices.size() > 0 );
136 DALI_TEST_CHECK( internalFaces.size() > 0 );
140 DALI_TEST_CHECK( internalVertices.size() == 0 );
141 DALI_TEST_CHECK( internalFaces.size() == 0 );
148 int utcDaliInternalMeshDiscard01(void)
150 tet_infoline("Test that internal mesh data is discarded after rendering with policy=DISCARD_ALL");
151 TestMeshDiscard( ResourcePolicy::DALI_DISCARDS_ALL_DATA, true /* Not discarded */);
155 int utcDaliInternalMeshDiscard02(void)
157 tet_infoline("Test that internal mesh data is not discarded after rendering with policy=RETAIN_ALL");
158 TestMeshDiscard( ResourcePolicy::DALI_RETAINS_ALL_DATA, false /* Not discarded */);
162 int utcDaliInternalMeshDiscard03(void)
164 tet_infoline("Test that internal mesh data is not discarded after rendering with policy=RETAIN_MESH");
165 TestMeshDiscard( ResourcePolicy::DALI_RETAINS_MESH_DATA, false /* Not discarded */);