Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
GrTTopoSort.h File Reference
#include "include/core/SkRefCnt.h"
#include "include/core/SkSpan.h"

Go to the source code of this file.

Functions

template<typename T , typename Traits = T>
bool GrTTopoSort_Visit (T *node, uint32_t *counter)
 
template<typename T , typename Traits = T>
bool GrTTopoSort (SkSpan< sk_sp< T > > graph, uint32_t offset=0)
 

Function Documentation

◆ GrTTopoSort()

template<typename T , typename Traits = T>
bool GrTTopoSort ( SkSpan< sk_sp< T > >  graph,
uint32_t  offset = 0 
)

Definition at line 92 of file GrTTopoSort.h.

92 {
93 uint32_t counter = offset;
94
95#ifdef SK_DEBUG
96 GrTTopoSort_CheckAllUnmarked<T, Traits>(graph);
97#endif
98
99 bool succeeded = true;
100
101 for (size_t i = 0; i < graph.size(); ++i) {
102 if (Traits::WasOutput(graph[i].get())) {
103 // This node was depended on by some earlier node and has already
104 // been output
105 continue;
106 }
107
108 // Output this node after all the nodes it depends on have been output.
109 if (!GrTTopoSort_Visit<T, Traits>(graph[i].get(), &counter)) {
110 succeeded = false;
111 }
112 }
113
114 SkASSERT(counter - offset == (uint32_t) graph.size());
115
116 // Reorder the array given the output order
117 for (uint32_t i = 0; i < (uint32_t) graph.size(); ++i) {
118 for (uint32_t correctIndex = Traits::GetIndex(graph[i].get()) - offset;
119 correctIndex != i;
120 correctIndex = Traits::GetIndex(graph[i].get()) - offset) {
121 graph[i].swap(graph[correctIndex]);
122 }
123 }
124
125#ifdef SK_DEBUG
126 GrTTopoSort_CleanExit<T, Traits>(graph, offset);
127#endif
128 return succeeded;
129}
#define SkASSERT(cond)
Definition SkAssert.h:116
constexpr size_t size() const
Definition SkSpan_impl.h:95
const myers::Point & get(const myers::Segment &)
Point offset

◆ GrTTopoSort_Visit()

template<typename T , typename Traits = T>
bool GrTTopoSort_Visit ( T node,
uint32_t *  counter 
)

Definition at line 36 of file GrTTopoSort.h.

36 {
37 if (Traits::IsTempMarked(node)) {
38 // There is a loop.
39 return false;
40 }
41
42 // If the node under consideration has been already been output it means it
43 // (and all the nodes it depends on) are already in 'result'.
44 if (Traits::WasOutput(node)) {
45 return true;
46 }
47
48 bool succeeded = true;
49 // This node hasn't been output yet. Recursively assess all the
50 // nodes it depends on outputing them first.
51 Traits::SetTempMark(node);
52 for (int i = 0; i < Traits::NumDependencies(node); ++i) {
53 if (!GrTTopoSort_Visit<T, Traits>(Traits::Dependency(node, i), counter)) {
54 succeeded = false;
55 }
56 }
57
58 Traits::Output(node, *counter); // mark this node as output
59 ++(*counter);
60 Traits::ResetTempMark(node);
61
62 return succeeded;
63}