Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 /*label=*/"MtlBlitCommandEncoder")
129 , fCommandEncoder(std::move(encoder)) {}
130
131 void freeGpuData() override {
132 fCommandEncoder.reset();
133 }
134
135 sk_cfp<id<MTLBlitCommandEncoder>> fCommandEncoder;
136};
137
138} // namespace skgpu::graphite
139
140#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:187
static const uint8_t buffer[]
uint8_t value
FlTexture * texture
Budgeted
Definition GpuTypes.h:35
Definition ref_ptr.h:256
int32_t fX
x-axis value
int32_t fY
y-axis value
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