Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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_.emplace_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_.emplace_back(std::move(command));
126 return true;
127}
128
129// |BlitPass|
130bool BlitPassGLES::OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
131 std::string label) {
132 auto command = std::make_unique<BlitGenerateMipmapCommandGLES>();
133 command->label = label;
134 command->texture = std::move(texture);
135
136 commands_.emplace_back(std::move(command));
137 return true;
138}
139
140} // 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.
const ProcTableGLES & GetProcTable() const
Get the OpenGL proc. table the reactor uses to manage handles.
std::shared_ptr< ReactorGLES > Ref
SkBitmap source
Definition examples.cpp:28
GAsyncResult * result
#define FML_CHECK(condition)
Definition logging.h:85
FlTexture * texture
bool EncodeCommandsInReactor(const std::shared_ptr< Allocator > &transients_allocator, const ReactorGLES &reactor, const std::vector< std::unique_ptr< BlitEncodeGLES > > &commands, const std::string &label)
Definition ref_ptr.h:256
#define TRACE_EVENT0(category_group, name)