/* * Copyright 2021 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef skgpu_MtlBlitCommandEncoder_DEFINED #define skgpu_MtlBlitCommandEncoder_DEFINED #include "include/core/SkRect.h" #include "include/core/SkRefCnt.h" #include "include/ports/SkCFObject.h" #import namespace skgpu::mtl { /** * Wraps a MTLBlitCommandEncoder object */ class BlitCommandEncoder : public SkRefCnt { public: static sk_sp Make(id commandBuffer) { // Adding a retain here to keep our own ref separate from the autorelease pool sk_cfp> encoder = sk_ret_cfp>([commandBuffer blitCommandEncoder]); return sk_sp(new BlitCommandEncoder(std::move(encoder))); } void pushDebugGroup(NSString* string) { [(*fCommandEncoder) pushDebugGroup:string]; } void popDebugGroup() { [(*fCommandEncoder) popDebugGroup]; } #ifdef SK_BUILD_FOR_MAC void synchronizeResource(id buffer) { [(*fCommandEncoder) synchronizeResource: buffer]; } #endif void copyFromTexture(id texture, SkIRect srcRect, id buffer, size_t bufferOffset, size_t bufferRowBytes) { [(*fCommandEncoder) copyFromTexture: texture sourceSlice: 0 sourceLevel: 0 sourceOrigin: MTLOriginMake(srcRect.left(), srcRect.top(), 0) sourceSize: MTLSizeMake(srcRect.width(), srcRect.height(), 1) toBuffer: buffer destinationOffset: bufferOffset destinationBytesPerRow: bufferRowBytes destinationBytesPerImage: bufferRowBytes * srcRect.height()]; } void endEncoding() { [(*fCommandEncoder) endEncoding]; } private: BlitCommandEncoder(sk_cfp> encoder) : fCommandEncoder(std::move(encoder)) {} sk_cfp> fCommandEncoder; }; } // namespace skgpu::mtl #endif // skgpu_MtlBlitCommandEncoder_DEFINED