6#include <Metal/Metal.h>
11#include "flutter/fml/closure.h"
12#include "flutter/fml/logging.h"
13#include "flutter/fml/trace_event.h"
28BlitPassMTL::BlitPassMTL(id<MTLCommandBuffer>
buffer) : buffer_(
buffer) {
32 encoder_ = [buffer_ blitCommandEncoder];
34 is_metal_trace_active_ =
35 [[MTLCaptureManager sharedCaptureManager] isCapturing];
40BlitPassMTL::~BlitPassMTL() {
41 if (!did_finish_encoding_) {
42 [encoder_ endEncoding];
46bool BlitPassMTL::IsValid()
const {
50void BlitPassMTL::OnSetLabel(std::string label) {
54 [encoder_ setLabel:@(label.c_str())];
57bool BlitPassMTL::EncodeCommands(
58 const std::shared_ptr<Allocator>& transients_allocator)
const {
59 [encoder_ endEncoding];
60 did_finish_encoding_ =
true;
65bool BlitPassMTL::OnCopyTextureToTextureCommand(
66 std::shared_ptr<Texture>
source,
67 std::shared_ptr<Texture> destination,
71 auto source_mtl = TextureMTL::Cast(*source).GetMTLTexture();
76 auto destination_mtl = TextureMTL::Cast(*destination).GetMTLTexture();
77 if (!destination_mtl) {
81 auto source_origin_mtl =
82 MTLOriginMake(source_region.GetX(), source_region.GetY(), 0);
83 auto source_size_mtl =
84 MTLSizeMake(source_region.GetWidth(), source_region.GetHeight(), 1);
85 auto destination_origin_mtl =
86 MTLOriginMake(destination_origin.x, destination_origin.y, 0);
89 if (is_metal_trace_active_) {
90 [encoder_ pushDebugGroup:@(label.c_str())];
93 [encoder_ copyFromTexture:source_mtl
96 sourceOrigin:source_origin_mtl
97 sourceSize:source_size_mtl
98 toTexture:destination_mtl
101 destinationOrigin:destination_origin_mtl];
104 if (is_metal_trace_active_) {
105 [encoder_ popDebugGroup];
113bool BlitPassMTL::OnCopyTextureToBufferCommand(
114 std::shared_ptr<Texture>
source,
115 std::shared_ptr<DeviceBuffer> destination,
117 size_t destination_offset,
119 auto source_mtl = TextureMTL::Cast(*source).GetMTLTexture();
124 auto destination_mtl = DeviceBufferMTL::Cast(*destination).GetMTLBuffer();
125 if (!destination_mtl) {
129 auto source_origin_mtl =
130 MTLOriginMake(source_region.GetX(), source_region.GetY(), 0);
131 auto source_size_mtl =
132 MTLSizeMake(source_region.GetWidth(), source_region.GetHeight(), 1);
134 auto destination_bytes_per_pixel =
136 auto destination_bytes_per_row =
137 source_size_mtl.width * destination_bytes_per_pixel;
138 auto destination_bytes_per_image =
139 source_size_mtl.height * destination_bytes_per_row;
142 if (is_metal_trace_active_) {
143 [encoder_ pushDebugGroup:@(label.c_str())];
146 [encoder_ copyFromTexture:source_mtl
149 sourceOrigin:source_origin_mtl
150 sourceSize:source_size_mtl
151 toBuffer:destination_mtl
152 destinationOffset:destination_offset
153 destinationBytesPerRow:destination_bytes_per_row
154 destinationBytesPerImage:destination_bytes_per_image];
157 if (is_metal_trace_active_) {
158 [encoder_ popDebugGroup];
164bool BlitPassMTL::OnCopyBufferToTextureCommand(
166 std::shared_ptr<Texture> destination,
167 IRect destination_region,
170 bool convert_to_read) {
171 auto source_mtl = DeviceBufferMTL::Cast(*
source.buffer).GetMTLBuffer();
176 auto destination_mtl = TextureMTL::Cast(*destination).GetMTLTexture();
177 if (!destination_mtl) {
181 auto destination_origin_mtl =
182 MTLOriginMake(destination_region.GetX(), destination_region.GetY(), 0);
183 auto source_size_mtl = MTLSizeMake(destination_region.GetWidth(),
184 destination_region.GetHeight(), 1);
186 auto destination_bytes_per_pixel =
188 auto source_bytes_per_row =
189 destination_region.GetWidth() * destination_bytes_per_pixel;
192 if (is_metal_trace_active_) {
193 [encoder_ pushDebugGroup:@(label.c_str())];
197 copyFromBuffer:source_mtl
198 sourceOffset:
source.range.offset
199 sourceBytesPerRow:source_bytes_per_row
203 sourceSize:source_size_mtl
204 toTexture:destination_mtl
205 destinationSlice:slice
207 destinationOrigin:destination_origin_mtl];
210 if (is_metal_trace_active_) {
211 [encoder_ popDebugGroup];
218bool BlitPassMTL::OnGenerateMipmapCommand(std::shared_ptr<Texture>
texture,
221 if (is_metal_trace_active_) {
222 [encoder_ pushDebugGroup:@(label.c_str())];
225 auto result = TextureMTL::Cast(*texture).GenerateMipmap(encoder_);
227 if (is_metal_trace_active_) {
228 [encoder_ popDebugGroup];
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)