Flutter Engine
The Flutter Engine
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
6
7#include <memory>
8
9#include "flutter/fml/trace_event.h"
10#include "fml/closure.h"
14
15namespace impeller {
16
17BlitPassGLES::BlitPassGLES(ReactorGLES::Ref reactor)
18 : reactor_(std::move(reactor)),
19 is_valid_(reactor_ && reactor_->IsValid()) {}
20
21// |BlitPass|
22BlitPassGLES::~BlitPassGLES() = default;
23
24// |BlitPass|
25bool BlitPassGLES::IsValid() const {
26 return is_valid_;
27}
28
29// |BlitPass|
30void BlitPassGLES::OnSetLabel(std::string label) {
31 label_ = std::move(label);
32}
33
34[[nodiscard]] bool EncodeCommandsInReactor(
35 const std::shared_ptr<Allocator>& transients_allocator,
36 const ReactorGLES& reactor,
37 const std::vector<std::unique_ptr<BlitEncodeGLES>>& commands,
38 const std::string& label) {
39 TRACE_EVENT0("impeller", "BlitPassGLES::EncodeCommandsInReactor");
40
41 if (commands.empty()) {
42 return true;
43 }
44
45 const auto& gl = reactor.GetProcTable();
46
47 fml::ScopedCleanupClosure pop_pass_debug_marker(
48 [&gl]() { gl.PopDebugGroup(); });
49 if (!label.empty()) {
50 gl.PushDebugGroup(label);
51 } else {
52 pop_pass_debug_marker.Release();
53 }
54
55 for (const auto& command : commands) {
56 fml::ScopedCleanupClosure pop_cmd_debug_marker(
57 [&gl]() { gl.PopDebugGroup(); });
58 auto label = command->GetLabel();
59 if (!label.empty()) {
60 gl.PushDebugGroup(label);
61 } else {
62 pop_cmd_debug_marker.Release();
63 }
64
65 if (!command->Encode(reactor)) {
66 return false;
67 }
68 }
69
70 return true;
71}
72
73// |BlitPass|
74bool BlitPassGLES::EncodeCommands(
75 const std::shared_ptr<Allocator>& transients_allocator) const {
76 if (!IsValid()) {
77 return false;
78 }
79 if (commands_.empty()) {
80 return true;
81 }
82
83 std::shared_ptr<const BlitPassGLES> shared_this = shared_from_this();
84 return reactor_->AddOperation([transients_allocator,
85 blit_pass = std::move(shared_this),
86 label = label_](const auto& reactor) {
87 auto result = EncodeCommandsInReactor(transients_allocator, reactor,
88 blit_pass->commands_, label);
89 FML_CHECK(result) << "Must be able to encode GL commands without error.";
90 });
91}
92
93// |BlitPass|
94bool BlitPassGLES::OnCopyTextureToTextureCommand(
95 std::shared_ptr<Texture> source,
96 std::shared_ptr<Texture> destination,
97 IRect source_region,
98 IPoint destination_origin,
99 std::string label) {
100 auto command = std::make_unique<BlitCopyTextureToTextureCommandGLES>();
101 command->label = label;
102 command->source = std::move(source);
103 command->destination = std::move(destination);
104 command->source_region = source_region;
105 command->destination_origin = destination_origin;
106
107 commands_.push_back(std::move(command));
108 return true;
109}
110
111// |BlitPass|
112bool BlitPassGLES::OnCopyTextureToBufferCommand(
113 std::shared_ptr<Texture> source,
114 std::shared_ptr<DeviceBuffer> destination,
115 IRect source_region,
116 size_t destination_offset,
117 std::string label) {
118 auto command = std::make_unique<BlitCopyTextureToBufferCommandGLES>();
119 command->label = label;
120 command->source = std::move(source);
121 command->destination = std::move(destination);
122 command->source_region = source_region;
123 command->destination_offset = destination_offset;
124
125 commands_.push_back(std::move(command));
126 return true;
127}
128
129// |BlitPass|
130bool BlitPassGLES::OnCopyBufferToTextureCommand(
131 BufferView source,
132 std::shared_ptr<Texture> destination,
133 IRect destination_region,
134 std::string label,
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->slice = slice;
144
145 commands_.push_back(std::move(command));
146 return true;
147}
148
149// |BlitPass|
150bool BlitPassGLES::OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
151 std::string label) {
152 auto command = std::make_unique<BlitGenerateMipmapCommandGLES>();
153 command->label = label;
154 command->texture = std::move(texture);
155
156 commands_.push_back(std::move(command));
157 return true;
158}
159
160} // namespace impeller
Wraps a closure that is invoked in the destructor unless released by the caller.
Definition: closure.h:32
The reactor attempts to make thread-safe usage of OpenGL ES easier to reason about.
Definition: reactor_gles.h:55
const ProcTableGLES & GetProcTable() const
Get the OpenGL proc. table the reactor uses to manage handles.
Definition: reactor_gles.cc:48
std::shared_ptr< ReactorGLES > Ref
Definition: reactor_gles.h:86
SkBitmap source
Definition: examples.cpp:28
GAsyncResult * result
#define FML_CHECK(condition)
Definition: logging.h:85
FlTexture * texture
dictionary commands
Definition: dom.py:171
bool EncodeCommandsInReactor(const std::shared_ptr< Allocator > &transients_allocator, const ReactorGLES &reactor, const std::vector< std::unique_ptr< BlitEncodeGLES > > &commands, const std::string &label)
IRect64 IRect
Definition: rect.h:772
TPoint< int64_t > IPoint
Definition: point.h:323
gl
Definition: malisc.py:41
Definition: ref_ptr.h:256
list command
Definition: valgrind.py:24
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131