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 
6 
7 #include <algorithm>
8 #include <memory>
9 
10 #include "flutter/fml/trace_event.h"
11 #include "impeller/base/config.h"
13 #include "impeller/core/formats.h"
20 
21 namespace impeller {
22 
23 BlitPassGLES::BlitPassGLES(ReactorGLES::Ref reactor)
24  : reactor_(std::move(reactor)),
25  is_valid_(reactor_ && reactor_->IsValid()) {}
26 
27 // |BlitPass|
28 BlitPassGLES::~BlitPassGLES() = default;
29 
30 // |BlitPass|
31 bool BlitPassGLES::IsValid() const {
32  return is_valid_;
33 }
34 
35 // |BlitPass|
36 void BlitPassGLES::OnSetLabel(std::string label) {
37  label_ = std::move(label);
38 }
39 
40 [[nodiscard]] bool EncodeCommandsInReactor(
41  const std::shared_ptr<Allocator>& transients_allocator,
42  const ReactorGLES& reactor,
43  const std::vector<std::unique_ptr<BlitEncodeGLES>>& commands,
44  const std::string& label) {
45  TRACE_EVENT0("impeller", "BlitPassGLES::EncodeCommandsInReactor");
46 
47  if (commands.empty()) {
48  return true;
49  }
50 
51  const auto& gl = reactor.GetProcTable();
52 
53  fml::ScopedCleanupClosure pop_pass_debug_marker(
54  [&gl]() { gl.PopDebugGroup(); });
55  if (!label.empty()) {
56  gl.PushDebugGroup(label);
57  } else {
58  pop_pass_debug_marker.Release();
59  }
60 
61  for (const auto& command : commands) {
62  fml::ScopedCleanupClosure pop_cmd_debug_marker(
63  [&gl]() { gl.PopDebugGroup(); });
64  auto label = command->GetLabel();
65  if (!label.empty()) {
66  gl.PushDebugGroup(label);
67  } else {
68  pop_cmd_debug_marker.Release();
69  }
70 
71  if (!command->Encode(reactor)) {
72  return false;
73  }
74  }
75 
76  return true;
77 }
78 
79 // |BlitPass|
80 bool BlitPassGLES::EncodeCommands(
81  const std::shared_ptr<Allocator>& transients_allocator) const {
82  if (!IsValid()) {
83  return false;
84  }
85  if (commands_.empty()) {
86  return true;
87  }
88 
89  std::shared_ptr<const BlitPassGLES> shared_this = shared_from_this();
90  return reactor_->AddOperation([transients_allocator,
91  blit_pass = std::move(shared_this),
92  label = label_](const auto& reactor) {
93  auto result = EncodeCommandsInReactor(transients_allocator, reactor,
94  blit_pass->commands_, label);
95  FML_CHECK(result) << "Must be able to encode GL commands without error.";
96  });
97 }
98 
99 // |BlitPass|
100 bool BlitPassGLES::OnCopyTextureToTextureCommand(
101  std::shared_ptr<Texture> source,
102  std::shared_ptr<Texture> destination,
103  IRect source_region,
104  IPoint destination_origin,
105  std::string label) {
106  auto command = std::make_unique<BlitCopyTextureToTextureCommandGLES>();
107  command->label = label;
108  command->source = std::move(source);
109  command->destination = std::move(destination);
110  command->source_region = source_region;
111  command->destination_origin = destination_origin;
112 
113  commands_.emplace_back(std::move(command));
114  return true;
115 }
116 
117 // |BlitPass|
118 bool BlitPassGLES::OnCopyTextureToBufferCommand(
119  std::shared_ptr<Texture> source,
120  std::shared_ptr<DeviceBuffer> destination,
121  IRect source_region,
122  size_t destination_offset,
123  std::string label) {
124  auto command = std::make_unique<BlitCopyTextureToBufferCommandGLES>();
125  command->label = label;
126  command->source = std::move(source);
127  command->destination = std::move(destination);
128  command->source_region = source_region;
129  command->destination_offset = destination_offset;
130 
131  commands_.emplace_back(std::move(command));
132  return true;
133 }
134 
135 // |BlitPass|
136 bool BlitPassGLES::OnGenerateMipmapCommand(std::shared_ptr<Texture> texture,
137  std::string label) {
138  auto command = std::make_unique<BlitGenerateMipmapCommandGLES>();
139  command->label = label;
140  command->texture = std::move(texture);
141 
142  commands_.emplace_back(std::move(command));
143  return true;
144 }
145 
146 } // namespace impeller
impeller::ReactorGLES::GetProcTable
const ProcTableGLES & GetProcTable() const
Definition: reactor_gles.cc:47
impeller::ProcTableGLES::PushDebugGroup
void PushDebugGroup(const std::string &string) const
Definition: proc_table_gles.cc:307
impeller::ReactorGLES::Ref
std::shared_ptr< ReactorGLES > Ref
Definition: reactor_gles.h:31
formats.h
texture_gles.h
validation.h
device_buffer_gles.h
impeller::BlitPassGLES::~BlitPassGLES
~BlitPassGLES() override
proc_table_gles.h
impeller::IRect
TRect< int64_t > IRect
Definition: rect.h:307
blit_command_gles.h
formats_gles.h
blit_pass_gles.h
pipeline_gles.h
std
Definition: comparable.h:98
impeller::IPoint
TPoint< int64_t > IPoint
Definition: point.h:307
impeller::ReactorGLES
Definition: reactor_gles.h:19
config.h
impeller::EncodeCommandsInReactor
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: blit_pass_gles.cc:40
impeller
Definition: aiks_context.cc:10