Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
6
9
10namespace impeller {
11
13
15 default;
16
18 return label;
19}
20
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.GetX(), source_region.GetY(), 0);
35 auto source_size_mtl =
36 MTLSizeMake(source_region.GetWidth(), source_region.GetHeight(), 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
54 default;
55
57 return label;
58}
59
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.GetX(), source_region.GetY(), 0);
74 auto source_size_mtl =
75 MTLSizeMake(source_region.GetWidth(), source_region.GetHeight(), 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
98 default;
99
101 return label;
102}
103
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
143
145 return label;
146}
147
149 id<MTLBlitCommandEncoder> encoder) const {
150 return TextureMTL::Cast(*texture).GenerateMipmap(encoder);
151};
152
153} // namespace impeller
static TextureMTL & Cast(Texture &base)
id< MTLBuffer > GetMTLBuffer() const
id< MTLTexture > GetMTLTexture() const
bool GenerateMipmap(id< MTLBlitCommandEncoder > encoder)
constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format)
Definition formats.h:448
bool Encode(id< MTLBlitCommandEncoder > encoder) const override
std::shared_ptr< Texture > destination
bool Encode(id< MTLBlitCommandEncoder > encoder) const override
std::shared_ptr< Texture > source
bool Encode(id< MTLBlitCommandEncoder > encoder) const override
bool Encode(id< MTLBlitCommandEncoder > encoder) const override
std::string GetLabel() const override
std::shared_ptr< const DeviceBuffer > buffer
Definition buffer_view.h:16
size_t offset
Definition range.h:15
constexpr Type GetY() const
Returns the Y coordinate of the upper left corner, equivalent to |GetOrigin().y|.
Definition rect.h:304
constexpr Type GetHeight() const
Returns the height of the rectangle, equivalent to |GetSize().height|.
Definition rect.h:314
constexpr Type GetX() const
Returns the X coordinate of the upper left corner, equivalent to |GetOrigin().x|.
Definition rect.h:300
constexpr Type GetWidth() const
Returns the width of the rectangle, equivalent to |GetSize().width|.
Definition rect.h:308