78c6fbbe2307743f44371a2957a57ba5b4f8bf77
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-graphics-command-buffer.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "test-graphics-command-buffer.h"
18
19 namespace Dali
20 {
21 TestGraphicsCommandBuffer::TestGraphicsCommandBuffer(TraceCallStack& callstack, TestGlAbstraction& glAbstraction)
22 : mCallStack(callstack),
23   mGlAbstraction(glAbstraction)
24 {
25 }
26
27 int TestGraphicsCommandBuffer::GetDrawCallsCount()
28 {
29   int count = 0;
30   for(auto& cmd : mCommands)
31   {
32     if(cmd.type == CommandType::DRAW ||
33        cmd.type == CommandType::DRAW_INDEXED ||
34        cmd.type == CommandType::DRAW_INDEXED_INDIRECT)
35     {
36       ++count;
37     }
38   }
39   return count;
40 }
41
42 void TestGraphicsCommandBuffer::GetStateForDrawCall(int drawCallIndex)
43 {
44   int                  index = 0;
45   std::vector<Command> mCommandStack{};
46   for(auto& cmd : mCommands)
47   {
48     mCommandStack.push_back(cmd);
49     if(cmd.type == CommandType::DRAW ||
50        cmd.type == CommandType::DRAW_INDEXED ||
51        cmd.type == CommandType::DRAW_INDEXED_INDIRECT)
52     {
53       if(index == drawCallIndex)
54       {
55         break;
56       }
57       mCommandStack.clear();
58       ++index;
59     }
60   }
61 }
62
63 std::vector<Command*> TestGraphicsCommandBuffer::GetCommandsByType(CommandTypeMask mask)
64 {
65   std::vector<Command*> mCommandStack{};
66   for(auto& cmd : mCommands)
67   {
68     if(uint32_t(cmd.type) == (mask & uint32_t(cmd.type)))
69     {
70       mCommandStack.emplace_back(&cmd);
71     }
72   }
73   return mCommandStack;
74 }
75
76 std::vector<Command*> TestGraphicsCommandBuffer::GetChildCommandsByType(CommandTypeMask mask)
77 {
78   std::vector<Command*> mCommandStack{};
79   for(auto& cmd : mCommands)
80   {
81     if(uint32_t(cmd.type) == (mask & uint32_t(cmd.type)))
82     {
83       mCommandStack.emplace_back(&cmd);
84     }
85     if(cmd.type == CommandType::EXECUTE_COMMAND_BUFFERS)
86     {
87       for(auto secondaryCB : cmd.data.executeCommandBuffers.buffers)
88       {
89         for(auto command : secondaryCB->GetChildCommandsByType(mask))
90         {
91           mCommandStack.push_back(command);
92         }
93       }
94     }
95   }
96   return mCommandStack;
97 }
98
99 } // namespace Dali