Flutter Engine
The Flutter Engine
MtlBlitCommandEncoder.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef skgpu_graphite_MtlBlitCommandEncoder_DEFINED
9#define skgpu_graphite_MtlBlitCommandEncoder_DEFINED
10
11#include "include/core/SkRect.h"
15
16#import <Metal/Metal.h>
17
18namespace skgpu::graphite {
19
20/**
21 * Wraps a MTLMtlBlitCommandEncoder object
22 */
24public:
26 id<MTLCommandBuffer> commandBuffer) {
27 @autoreleasepool {
28 // Adding a retain here to keep our own ref separate from the autorelease pool
29 sk_cfp<id<MTLBlitCommandEncoder>> encoder =
30 sk_ret_cfp<id<MTLBlitCommandEncoder>>([commandBuffer blitCommandEncoder]);
32 std::move(encoder)));
33 }
34 }
35
36 const char* getResourceType() const override { return "Metal Blit Command Encoder"; }
37
38 void pushDebugGroup(NSString* string) {
39 [(*fCommandEncoder) pushDebugGroup:string];
40 }
42 [(*fCommandEncoder) popDebugGroup];
43 }
44#ifdef SK_BUILD_FOR_MAC
45 void synchronizeResource(id<MTLBuffer> buffer) {
46 [(*fCommandEncoder) synchronizeResource: buffer];
47 }
48#endif
49
50 void fillBuffer(id<MTLBuffer> buffer, size_t bufferOffset, size_t bytes, uint8_t value) {
51 [(*fCommandEncoder) fillBuffer:buffer
52 range:NSMakeRange(bufferOffset, bytes)
53 value:value];
54 }
55
56 void copyFromTexture(id<MTLTexture> texture,
57 SkIRect srcRect,
58 id<MTLBuffer> buffer,
59 size_t bufferOffset,
60 size_t bufferRowBytes) {
61 [(*fCommandEncoder) copyFromTexture: texture
62 sourceSlice: 0
63 sourceLevel: 0
64 sourceOrigin: MTLOriginMake(srcRect.left(), srcRect.top(), 0)
65 sourceSize: MTLSizeMake(srcRect.width(), srcRect.height(), 1)
66 toBuffer: buffer
67 destinationOffset: bufferOffset
68 destinationBytesPerRow: bufferRowBytes
69 destinationBytesPerImage: bufferRowBytes * srcRect.height()];
70 }
71
72 void copyFromBuffer(id<MTLBuffer> buffer,
73 size_t bufferOffset,
74 size_t bufferRowBytes,
75 id<MTLTexture> texture,
76 SkIRect dstRect,
77 unsigned int dstLevel) {
78 [(*fCommandEncoder) copyFromBuffer: buffer
79 sourceOffset: bufferOffset
80 sourceBytesPerRow: bufferRowBytes
81 sourceBytesPerImage: bufferRowBytes * dstRect.height()
82 sourceSize: MTLSizeMake(dstRect.width(), dstRect.height(), 1)
83 toTexture: texture
84 destinationSlice: 0
85 destinationLevel: dstLevel
86 destinationOrigin: MTLOriginMake(dstRect.left(), dstRect.top(), 0)];
87 }
88
89 void copyTextureToTexture(id<MTLTexture> srcTexture,
90 SkIRect srcRect,
91 id<MTLTexture> dstTexture,
92 SkIPoint dstPoint,
93 int mipLevel) {
94 [(*fCommandEncoder) copyFromTexture: srcTexture
95 sourceSlice: 0
96 sourceLevel: 0
97 sourceOrigin: MTLOriginMake(srcRect.x(), srcRect.y(), 0)
98 sourceSize: MTLSizeMake(srcRect.width(), srcRect.height(), 1)
99 toTexture: dstTexture
100 destinationSlice: 0
101 destinationLevel: mipLevel
102 destinationOrigin: MTLOriginMake(dstPoint.fX, dstPoint.fY, 0)];
103 }
104
105 void copyBufferToBuffer(id<MTLBuffer> srcBuffer,
106 size_t srcOffset,
107 id<MTLBuffer> dstBuffer,
108 size_t dstOffset,
109 size_t size) {
110 [(*fCommandEncoder) copyFromBuffer: srcBuffer
111 sourceOffset: srcOffset
112 toBuffer: dstBuffer
113 destinationOffset: dstOffset
114 size: size];
115 }
116
117 void endEncoding() {
118 [(*fCommandEncoder) endEncoding];
119 }
120
121private:
123 sk_cfp<id<MTLBlitCommandEncoder>> encoder)
127 /*gpuMemorySize=*/0)
128 , fCommandEncoder(std::move(encoder)) {}
129
130 void freeGpuData() override {
131 fCommandEncoder.reset();
132 }
133
134 sk_cfp<id<MTLBlitCommandEncoder>> fCommandEncoder;
135};
136
137} // namespace skgpu::graphite
138
139#endif // skgpu_graphite_MtlBlitCommandEncoder_DEFINED
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
void fillBuffer(id< MTLBuffer > buffer, size_t bufferOffset, size_t bytes, uint8_t value)
static sk_sp< MtlBlitCommandEncoder > Make(const SharedContext *sharedContext, id< MTLCommandBuffer > commandBuffer)
void copyFromTexture(id< MTLTexture > texture, SkIRect srcRect, id< MTLBuffer > buffer, size_t bufferOffset, size_t bufferRowBytes)
void copyTextureToTexture(id< MTLTexture > srcTexture, SkIRect srcRect, id< MTLTexture > dstTexture, SkIPoint dstPoint, int mipLevel)
const char * getResourceType() const override
void copyBufferToBuffer(id< MTLBuffer > srcBuffer, size_t srcOffset, id< MTLBuffer > dstBuffer, size_t dstOffset, size_t size)
void copyFromBuffer(id< MTLBuffer > buffer, size_t bufferOffset, size_t bufferRowBytes, id< MTLTexture > texture, SkIRect dstRect, unsigned int dstLevel)
const SharedContext * sharedContext() const
Definition: Resource.h:189
uint8_t value
FlTexture * texture
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
Definition: switches.h:126
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Definition: GpuTools.h:21
Budgeted
Definition: GpuTypes.h:35
Definition: ref_ptr.h:256
int32_t fX
x-axis value
Definition: SkPoint_impl.h:29
int32_t fY
y-axis value
Definition: SkPoint_impl.h:30
Definition: SkRect.h:32
constexpr int32_t x() const
Definition: SkRect.h:141
constexpr int32_t y() const
Definition: SkRect.h:148
constexpr int32_t top() const
Definition: SkRect.h:120
constexpr int32_t height() const
Definition: SkRect.h:165
constexpr int32_t width() const
Definition: SkRect.h:158
constexpr int32_t left() const
Definition: SkRect.h:113