| Flutter Impeller |

blit_pass_gles.cc
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 #include "impeller/renderer/backend/gles/blit_pass_gles.h"
6
7 #include <memory>
8
9 #include "flutter/fml/trace_event.h"
10 #include "fml/closure.h"
11 #include "impeller/core/formats.h"
12 #include "impeller/renderer/backend/gles/blit_command_gles.h"
13 #include "impeller/renderer/backend/gles/proc_table_gles.h"
14
15 namespace impeller {
16
17 BlitPassGLES::BlitPassGLES(std::shared_ptr<ReactorGLES> reactor)
18 : reactor_(std::move(reactor)),
19 is_valid_(reactor_ && reactor_->IsValid()) {}
20
21 // |BlitPass|
22 BlitPassGLES::~BlitPassGLES() = default;
23
24 // |BlitPass|
25 bool BlitPassGLES::IsValid() const {
26 return is_valid_;
27 }
28
29 // |BlitPass|
30 void BlitPassGLES::OnSetLabel(std::string_view label) {
31 label_ = std::string(label);
32 }
33
34 [[nodiscard]] bool EncodeCommandsInReactor(
35 const ReactorGLES& reactor,
36 const std::vector<std::unique_ptr<BlitEncodeGLES>>& commands,
37 const std::string& label) {
38 TRACE_EVENT0("impeller", "BlitPassGLES::EncodeCommandsInReactor");
39
40 if (commands.empty()) {
41 return true;
42 }
43
44 #ifdef IMPELLER_DEBUG
45 const auto& gl = reactor.GetProcTable();
46 fml::ScopedCleanupClosure pop_pass_debug_marker(
47 [&gl]() { gl.PopDebugGroup(); });
48 if (!label.empty()) {
49 gl.PushDebugGroup(label);
50 } else {
51 pop_pass_debug_marker.Release();
52 }
53 #endif // IMPELLER_DEBUG
54
55 for (const auto& command : commands) {
56 #ifdef IMPELLER_DEBUG
57 fml::ScopedCleanupClosure pop_cmd_debug_marker(
58 [&gl]() { gl.PopDebugGroup(); });
59 auto label = command->GetLabel();
60 if (!label.empty()) {
61 gl.PushDebugGroup(label);
62 } else {
63 pop_cmd_debug_marker.Release();
64 }
65 #endif // IMPELLER_DEBUG
66
67 if (!command->Encode(reactor)) {
68 return false;
69 }
70 }
71
72 return true;
73 }
74
75 // |BlitPass|
76 bool BlitPassGLES::EncodeCommands() const {
77 if (!IsValid()) {
78 return false;
79 }
80 if (commands_.empty()) {
81 return true;
82 }
83
84 std::shared_ptr<const BlitPassGLES> shared_this = shared_from_this();
85 return reactor_->AddOperation([blit_pass = std::move(shared_this),
86 label = label_](const auto& reactor) {
87 auto result = EncodeCommandsInReactor(reactor, blit_pass->commands_, label);
88 FML_CHECK(result) << "Must be able to encode GL commands without error.";
89 });
90 }
91
92 // |BlitPass|
93 bool BlitPassGLES::OnCopyTextureToTextureCommand(
94 std::shared_ptr<Texture> source,
95 std::shared_ptr<Texture> destination,
96 IRect source_region,
97 IPoint destination_origin,
98 std::string_view label) {
99 auto command = std::make_unique<BlitCopyTextureToTextureCommandGLES>();
100 command->label = label;
101 command->source = std::move(source);
102 command->destination = std::move(destination);
103 command->source_region = source_region;
104 command->destination_origin = destination_origin;
105
106 commands_.push_back(std::move(command));
107 return true;
108 }
109
110 // |BlitPass|
111 bool BlitPassGLES::OnCopyTextureToBufferCommand(
112 std::shared_ptr<Texture> source,
113 std::shared_ptr<DeviceBuffer> destination,
114 IRect source_region,
115 size_t destination_offset,
116 std::string_view label) {
117 auto command = std::make_unique<BlitCopyTextureToBufferCommandGLES>();
118 command->label = label;
119 command->source = std::move(source);
120 command->destination = std::move(destination);
121 command->source_region = source_region;
122 command->destination_offset = destination_offset;
123
124 commands_.push_back(std::move(command));
125 return true;
126 }
127
128 // |BlitPass|
129 bool BlitPassGLES::OnCopyBufferToTextureCommand(
130 BufferView source,
131 std::shared_ptr<Texture> destination,
132 IRect destination_region,
133 std::string_view label,
134 uint32_t mip_level,
135 uint32_t slice,
136 bool convert_to_read) {
137 auto command = std::make_unique<BlitCopyBufferToTextureCommandGLES>();
138 command->label = label;
139 command->source = std::move(source);
140 command->destination = std::move(destination);
141 command->destination_region = destination_region;
142 command->label = label;
143 command->mip_level = mip_level;
144 command->slice = slice;
145
146 commands_.push_back(std::move(command));
147 return true;
148 }
149
150 // |BlitPass|
151 bool BlitPassGLES::OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
152 std::string_view label) {
153 auto command = std::make_unique<BlitGenerateMipmapCommandGLES>();
154 command->label = label;
155 command->texture = std::move(texture);
156
157 commands_.push_back(std::move(command));
158 return true;
159 }
160
161 // |BlitPass|
162 bool BlitPassGLES::ResizeTexture(const std::shared_ptr<Texture>& source,
163 const std::shared_ptr<Texture>& destination) {
164 auto command = std::make_unique<BlitResizeTextureCommandGLES>();
165 command->source = source;
166 command->destination = destination;
167
168 commands_.push_back(std::move(command));
169 return true;
170 }
171
172 } // namespace impeller
blit_command_gles.h
blit_pass_gles.h
impeller::ProcTableGLES::PushDebugGroup
void PushDebugGroup(const std::string &string) const
Definition: proc_table_gles.cc:393
impeller::ReactorGLES
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
Definition: reactor_gles.h:57
impeller::ReactorGLES::GetProcTable
const ProcTableGLES & GetProcTable() const
Get the OpenGL proc. table the reactor uses to manage handles.
Definition: reactor_gles.cc:122
formats.h
impeller
Definition: allocation.cc:12
impeller::EncodeCommandsInReactor
bool EncodeCommandsInReactor(const ReactorGLES &reactor, const std::vector< std::unique_ptr< BlitEncodeGLES >> &commands, const std::string &label)
Definition: blit_pass_gles.cc:34
impeller::IRect
IRect64 IRect
Definition: rect.h:795
impeller::IPoint
TPoint< int64_t > IPoint
Definition: point.h:328
std
Definition: comparable.h:95
proc_table_gles.h