Fixed SVACE errors in Test Graphics
[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 std::ostream& operator<<(std::ostream& os, Graphics::StencilOp op)
22 {
23   switch(op)
24   {
25     case Graphics::StencilOp::KEEP:
26       os << "KEEP";
27       return os;
28     case Graphics::StencilOp::ZERO:
29       os << "ZERO";
30       return os;
31     case Graphics::StencilOp::REPLACE:
32       os << "REPLACE";
33       return os;
34     case Graphics::StencilOp::INCREMENT_AND_CLAMP:
35       os << "INCREMENT_AND_CLAMP";
36       return os;
37     case Graphics::StencilOp::DECREMENT_AND_CLAMP:
38       os << "DECREMENT_AND_CLAMP";
39       return os;
40     case Graphics::StencilOp::INVERT:
41       os << "INVERT";
42       return os;
43     case Graphics::StencilOp::INCREMENT_AND_WRAP:
44       os << "INCREMENT_AND_WRAP";
45       return os;
46     case Graphics::StencilOp::DECREMENT_AND_WRAP:
47       os << "DECREMENT_AND_WRAP";
48       return os;
49   }
50   return os;
51 };
52
53 std::ostream& operator<<(std::ostream& os, Graphics::CompareOp op)
54 {
55   switch(op)
56   {
57     case Graphics::CompareOp::NEVER:
58       os << "NEVER";
59       return os;
60     case Graphics::CompareOp::LESS:
61       os << "LESS";
62       return os;
63     case Graphics::CompareOp::EQUAL:
64       os << "EQUAL";
65       return os;
66     case Graphics::CompareOp::LESS_OR_EQUAL:
67       os << "LESS_OR_EQUAL";
68       return os;
69     case Graphics::CompareOp::GREATER:
70       os << "GREATER";
71       return os;
72     case Graphics::CompareOp::NOT_EQUAL:
73       os << "NOT_EQUAL";
74       return os;
75     case Graphics::CompareOp::GREATER_OR_EQUAL:
76       os << "GREATER_OR_EQUAL";
77       return os;
78     case Graphics::CompareOp::ALWAYS:
79       os << "ALWAYS";
80       return os;
81   }
82   return os;
83 };
84
85 TestGraphicsCommandBuffer::TestGraphicsCommandBuffer(TraceCallStack& callstack, TestGlAbstraction& glAbstraction)
86 : mCallStack(callstack),
87   mGlAbstraction(glAbstraction)
88 {
89 }
90
91 int TestGraphicsCommandBuffer::GetDrawCallsCount()
92 {
93   int count = 0;
94   for(auto& cmd : mCommands)
95   {
96     if(cmd.type == CommandType::DRAW ||
97        cmd.type == CommandType::DRAW_INDEXED ||
98        cmd.type == CommandType::DRAW_INDEXED_INDIRECT)
99     {
100       ++count;
101     }
102   }
103   return count;
104 }
105
106 void TestGraphicsCommandBuffer::GetStateForDrawCall(int drawCallIndex)
107 {
108   int                  index = 0;
109   std::vector<Command> mCommandStack{};
110   for(auto& cmd : mCommands)
111   {
112     mCommandStack.push_back(cmd);
113     if(cmd.type == CommandType::DRAW ||
114        cmd.type == CommandType::DRAW_INDEXED ||
115        cmd.type == CommandType::DRAW_INDEXED_INDIRECT)
116     {
117       if(index == drawCallIndex)
118       {
119         break;
120       }
121       mCommandStack.clear();
122       ++index;
123     }
124   }
125 }
126
127 std::vector<const Command*> TestGraphicsCommandBuffer::GetCommandsByType(CommandTypeMask mask) const
128 {
129   std::vector<const Command*> mCommandStack{};
130   for(auto& cmd : mCommands)
131   {
132     if(uint32_t(cmd.type) == (mask & uint32_t(cmd.type)))
133     {
134       mCommandStack.emplace_back(&cmd);
135     }
136   }
137   return mCommandStack;
138 }
139
140 std::vector<const Command*> TestGraphicsCommandBuffer::GetChildCommandsByType(CommandTypeMask mask) const
141 {
142   std::vector<const Command*> mCommandStack{};
143   for(auto& cmd : mCommands)
144   {
145     if(uint32_t(cmd.type) == (mask & uint32_t(cmd.type)))
146     {
147       mCommandStack.emplace_back(&cmd);
148     }
149     if(cmd.type == CommandType::EXECUTE_COMMAND_BUFFERS)
150     {
151       for(auto secondaryCB : cmd.data.executeCommandBuffers.buffers)
152       {
153         for(auto command : secondaryCB->GetChildCommandsByType(mask))
154         {
155           mCommandStack.push_back(command);
156         }
157       }
158     }
159   }
160   return mCommandStack;
161 }
162
163 } // namespace Dali