| Flutter Impeller |

draw_order_resolver.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_ENTITY_DRAW_ORDER_RESOLVER_H_
6 #define FLUTTER_IMPELLER_ENTITY_DRAW_ORDER_RESOLVER_H_
7
8 #include <optional>
9 #include <vector>
10
11 namespace impeller {
12
13 /// Helper that records draw indices in painter's order and sorts the draws into
14 /// an optimized order based on translucency and clips.
15 class DrawOrderResolver {
16 public:
17 using ElementRefs = std::vector<size_t>;
18
19 DrawOrderResolver();
20
21 void AddElement(size_t element_index, bool is_opaque);
22
23 void PushClip(size_t element_index);
24
25 void PopClip();
26
27 void Flush();
28
29 //-------------------------------------------------------------------------
30 /// @brief Returns the sorted draws for the current draw order layer.
31 /// This should only be called after all recording has finished.
32 ///
33 /// @param[in] opaque_skip_count The number of opaque elements to skip
34 /// when appending the combined elements.
35 /// This is used for the "clear color"
36 /// optimization.
37 /// @param[in] translucent_skip_count The number of translucent elements to
38 /// skip when appending the combined
39 /// elements. This is used for the
40 /// "clear color" optimization.
41 ///
42 ElementRefs GetSortedDraws(size_t opaque_skip_count,
43 size_t translucent_skip_count) const;
44
45 private:
46 /// A data structure for collecting sorted draws for a given "draw order
47 /// layer". Currently these layers just correspond to the local clip stack.
48 struct DrawOrderLayer {
49 /// The list of backdrop-independent elements (always just opaque). These
50 /// are order independent, and so we render these elements in reverse
51 /// painter's order so that they cull one another.
52 ElementRefs opaque_elements;
53
54 /// The list of backdrop-dependent elements with respect to this draw
55 /// order layer. These elements are drawn after all of the independent
56 /// elements.
57 ElementRefs dependent_elements;
58
59 //-----------------------------------------------------------------------
60 /// @brief Appends the combined opaque and transparent elements into
61 /// a final destination buffer.
62 ///
63 /// @param[in] destination The buffer to append the combined
64 /// elements to.
65 /// @param[in] opaque_skip_count The number of opaque elements to
66 /// skip when appending the combined
67 /// elements. This is used for the
68 /// "clear color" optimization.
69 /// @param[in] translucent_skip_count The number of translucent elements
70 /// to skip when appending the combined
71 /// elements. This is used for the
72 /// "clear color" optimization.
73 ///
74 void WriteCombinedDraws(ElementRefs& destination,
75 size_t opaque_skip_count,
76 size_t translucent_skip_count) const;
77 };
78 std::vector<DrawOrderLayer> draw_order_layers_;
79
80 // The first time the root layer is flushed, the layer contents are stored
81 // here. This is done to enable element skipping for the clear color
82 // optimization.
83 std::optional<DrawOrderLayer> first_root_flush_;
84 // All subsequent root flushes are stored here.
85 ElementRefs sorted_elements_;
86
87 DrawOrderResolver(const DrawOrderResolver&) = delete;
88
89 DrawOrderResolver& operator=(const DrawOrderResolver&) = delete;
90 };
91
92 } // namespace impeller
93
94 #endif // FLUTTER_IMPELLER_ENTITY_DRAW_ORDER_RESOLVER_H_
impeller::DrawOrderResolver
Definition: draw_order_resolver.h:15
impeller::DrawOrderResolver::Flush
void Flush()
Definition: draw_order_resolver.cc:44
impeller::DrawOrderResolver::PushClip
void PushClip(size_t element_index)
Definition: draw_order_resolver.cc:22
impeller::DrawOrderResolver::GetSortedDraws
ElementRefs GetSortedDraws(size_t opaque_skip_count, size_t translucent_skip_count) const
Returns the sorted draws for the current draw order layer. This should only be called after all recor...
Definition: draw_order_resolver.cc:71
impeller::DrawOrderResolver::ElementRefs
std::vector< size_t > ElementRefs
Definition: draw_order_resolver.h:17
impeller::DrawOrderResolver::AddElement
void AddElement(size_t element_index, bool is_opaque)
Definition: draw_order_resolver.cc:14
impeller::DrawOrderResolver::DrawOrderResolver
DrawOrderResolver()
Definition: draw_order_resolver.cc:12
impeller::DrawOrderResolver::PopClip
void PopClip()
Definition: draw_order_resolver.cc:27
impeller
Definition: allocation.cc:12