| Flutter Impeller |

blit_command_mtl.mm
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/metal/blit_command_mtl.h"
6
7 #include "impeller/renderer/backend/metal/device_buffer_mtl.h"
8 #include "impeller/renderer/backend/metal/texture_mtl.h"
9
10 namespace impeller {
11
12 BlitEncodeMTL::~BlitEncodeMTL() = default;
13
14 BlitCopyTextureToTextureCommandMTL::~BlitCopyTextureToTextureCommandMTL() =
15 default;
16
17 std::string BlitCopyTextureToTextureCommandMTL::GetLabel() const {
18 return label;
19 }
20
21 bool BlitCopyTextureToTextureCommandMTL::Encode(
22 id<MTLBlitCommandEncoder> encoder) const {
23 auto source_mtl = TextureMTL::Cast(*source).GetMTLTexture();
24 if (!source_mtl) {
25 return false;
26 }
27
28 auto destination_mtl = TextureMTL::Cast(*destination).GetMTLTexture();
29 if (!destination_mtl) {
30 return false;
31 }
32
33 auto source_origin_mtl =
34 MTLOriginMake(source_region.origin.x, source_region.origin.y, 0);
35 auto source_size_mtl =
36 MTLSizeMake(source_region.size.width, source_region.size.height, 1);
37 auto destination_origin_mtl =
38 MTLOriginMake(destination_origin.x, destination_origin.y, 0);
39
40 [encoder copyFromTexture:source_mtl
41 sourceSlice:0
42 sourceLevel:0
43 sourceOrigin:source_origin_mtl
44 sourceSize:source_size_mtl
45 toTexture:destination_mtl
46 destinationSlice:0
47 destinationLevel:0
48 destinationOrigin:destination_origin_mtl];
49
50 return true;
51 };
52
53 BlitCopyTextureToBufferCommandMTL::~BlitCopyTextureToBufferCommandMTL() =
54 default;
55
56 std::string BlitCopyTextureToBufferCommandMTL::GetLabel() const {
57 return label;
58 }
59
60 bool BlitCopyTextureToBufferCommandMTL::Encode(
61 id<MTLBlitCommandEncoder> encoder) const {
62 auto source_mtl = TextureMTL::Cast(*source).GetMTLTexture();
63 if (!source_mtl) {
64 return false;
65 }
66
67 auto destination_mtl = DeviceBufferMTL::Cast(*destination).GetMTLBuffer();
68 if (!destination_mtl) {
69 return false;
70 }
71
72 auto source_origin_mtl =
73 MTLOriginMake(source_region.origin.x, source_region.origin.y, 0);
74 auto source_size_mtl =
75 MTLSizeMake(source_region.size.width, source_region.size.height, 1);
76
77 auto destination_bytes_per_pixel =
78 BytesPerPixelForPixelFormat(source->GetTextureDescriptor().format);
79 auto destination_bytes_per_row =
80 source_size_mtl.width * destination_bytes_per_pixel;
81 auto destination_bytes_per_image =
82 source_size_mtl.height * destination_bytes_per_row;
83
84 [encoder copyFromTexture:source_mtl
85 sourceSlice:0
86 sourceLevel:0
87 sourceOrigin:source_origin_mtl
88 sourceSize:source_size_mtl
89 toBuffer:destination_mtl
90 destinationOffset:destination_offset
91 destinationBytesPerRow:destination_bytes_per_row
92 destinationBytesPerImage:destination_bytes_per_image];
93
94 return true;
95 };
96
97 BlitCopyBufferToTextureCommandMTL::~BlitCopyBufferToTextureCommandMTL() =
98 default;
99
100 std::string BlitCopyBufferToTextureCommandMTL::GetLabel() const {
101 return label;
102 }
103
104 bool BlitCopyBufferToTextureCommandMTL::Encode(
105 id<MTLBlitCommandEncoder> encoder) const {
106 auto source_mtl = DeviceBufferMTL::Cast(*source.buffer).GetMTLBuffer();
107 if (!source_mtl) {
108 return false;
109 }
110
111 auto destination_mtl = TextureMTL::Cast(*destination).GetMTLTexture();
112 if (!destination_mtl) {
113 return false;
114 }
115
116 auto destination_origin_mtl =
117 MTLOriginMake(destination_origin.x, destination_origin.y, 0);
118
119 auto image_size = destination->GetTextureDescriptor().size;
120 auto source_size_mtl = MTLSizeMake(image_size.width, image_size.height, 1);
121
122 auto destination_bytes_per_pixel =
123 BytesPerPixelForPixelFormat(destination->GetTextureDescriptor().format);
124 auto destination_bytes_per_row =
125 source_size_mtl.width * destination_bytes_per_pixel;
126 auto destination_bytes_per_image =
127 source_size_mtl.height * destination_bytes_per_row;
128
129 [encoder copyFromBuffer:source_mtl
130 sourceOffset:source.range.offset
131 sourceBytesPerRow:destination_bytes_per_row
132 sourceBytesPerImage:destination_bytes_per_image
133 sourceSize:source_size_mtl
134 toTexture:destination_mtl
135 destinationSlice:0
136 destinationLevel:0
137 destinationOrigin:destination_origin_mtl];
138
139 return true;
140 };
141
142 BlitGenerateMipmapCommandMTL::~BlitGenerateMipmapCommandMTL() = default;
143
144 std::string BlitGenerateMipmapCommandMTL::GetLabel() const {
145 return label;
146 }
147
148 bool BlitGenerateMipmapCommandMTL::Encode(
149 id<MTLBlitCommandEncoder> encoder) const {
150 return TextureMTL::Cast(*texture).GenerateMipmap(encoder);
151 };
152
153 } // namespace impeller
impeller::BlitGenerateMipmapCommandMTL::GetLabel
std::string GetLabel() const override
Definition: blit_command_mtl.mm:144
impeller::TRect::size
TSize< Type > size
Definition: rect.h:24
impeller::TPoint::y
Type y
Definition: point.h:24
impeller::TextureMTL::GenerateMipmap
bool GenerateMipmap(id< MTLBlitCommandEncoder > encoder)
Definition: texture_mtl.mm:112
impeller::BlitCopyTextureToBufferCommandMTL::Encode
bool Encode(id< MTLBlitCommandEncoder > encoder) const override
Definition: blit_command_mtl.mm:60
impeller::Range::offset
size_t offset
Definition: range.h:14
impeller::TextureMTL::GetMTLTexture
id< MTLTexture > GetMTLTexture() const
Definition: texture_mtl.mm:100
impeller::BufferView::range
Range range
Definition: buffer_view.h:16
blit_command_mtl.h
impeller::BlitCopyTextureToTextureCommand::destination_origin
IPoint destination_origin
Definition: blit_command.h:21
impeller::BlitCopyTextureToBufferCommandMTL::~BlitCopyTextureToBufferCommandMTL
~BlitCopyTextureToBufferCommandMTL() override
impeller::BlitCommand::label
std::string label
Definition: blit_command.h:14
impeller::BlitEncodeMTL::~BlitEncodeMTL
virtual ~BlitEncodeMTL()
impeller::BlitCopyBufferToTextureCommand::source
BufferView source
Definition: blit_command.h:32
impeller::BytesPerPixelForPixelFormat
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition: formats.h:399
impeller::BlitCopyTextureToTextureCommandMTL::~BlitCopyTextureToTextureCommandMTL
~BlitCopyTextureToTextureCommandMTL() override
impeller::BlitCopyTextureToTextureCommandMTL::Encode
bool Encode(id< MTLBlitCommandEncoder > encoder) const override
Definition: blit_command_mtl.mm:21
impeller::BufferView::buffer
std::shared_ptr< const Buffer > buffer
Definition: buffer_view.h:14
impeller::BlitGenerateMipmapCommandMTL::Encode
bool Encode(id< MTLBlitCommandEncoder > encoder) const override
Definition: blit_command_mtl.mm:148
impeller::BlitCopyTextureToBufferCommand::destination_offset
size_t destination_offset
Definition: blit_command.h:28
impeller::BlitCopyBufferToTextureCommandMTL::~BlitCopyBufferToTextureCommandMTL
~BlitCopyBufferToTextureCommandMTL() override
impeller::TRect::origin
TPoint< Type > origin
Definition: rect.h:23
impeller::BlitCopyBufferToTextureCommandMTL::GetLabel
std::string GetLabel() const override
Definition: blit_command_mtl.mm:100
impeller::TSize::width
Type width
Definition: size.h:21
impeller::TPoint::x
Type x
Definition: point.h:23
impeller::DeviceBufferMTL::GetMTLBuffer
id< MTLBuffer > GetMTLBuffer() const
Definition: device_buffer_mtl.mm:21
impeller::BlitGenerateMipmapCommandMTL::~BlitGenerateMipmapCommandMTL
~BlitGenerateMipmapCommandMTL() override
impeller::BlitCopyTextureToTextureCommandMTL::GetLabel
std::string GetLabel() const override
Definition: blit_command_mtl.mm:17
texture_mtl.h
impeller::BackendCast< TextureMTL, Texture >::Cast
static TextureMTL & Cast(Texture &base)
Definition: backend_cast.h:14
impeller::BlitCopyTextureToBufferCommand::source
std::shared_ptr< Texture > source
Definition: blit_command.h:25
impeller::BlitCopyTextureToBufferCommandMTL::GetLabel
std::string GetLabel() const override
Definition: blit_command_mtl.mm:56
impeller::BlitCopyTextureToTextureCommand::source_region
IRect source_region
Definition: blit_command.h:20
impeller::TSize::height
Type height
Definition: size.h:22
impeller::BlitCopyBufferToTextureCommand::destination_origin
IPoint destination_origin
Definition: blit_command.h:34
impeller
Definition: aiks_context.cc:10
impeller::BlitCopyTextureToBufferCommand::source_region
IRect source_region
Definition: blit_command.h:27
impeller::BlitCopyBufferToTextureCommandMTL::Encode
bool Encode(id< MTLBlitCommandEncoder > encoder) const override
Definition: blit_command_mtl.mm:104
device_buffer_mtl.h
impeller::BlitCopyBufferToTextureCommand::destination
std::shared_ptr< Texture > destination
Definition: blit_command.h:33