/* * Copyright 2019 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef GrMtlCommandBuffer_DEFINED #define GrMtlCommandBuffer_DEFINED #import #include "include/core/SkRefCnt.h" #include "include/gpu/GrTypes.h" #include "src/gpu/GrBuffer.h" #include "src/gpu/mtl/GrMtlUtil.h" class GrMtlGpu; class GrMtlPipelineState; class GrMtlOpsRenderPass; GR_NORETAIN_BEGIN class GrMtlCommandBuffer : public SkRefCnt { public: static sk_sp Make(id queue); ~GrMtlCommandBuffer() override; bool commit(bool waitUntilCompleted); bool hasWork() { return fHasWork; } void addFinishedCallback(sk_sp callback) { fFinishedCallbacks.push_back(std::move(callback)); } id getBlitCommandEncoder(); id getRenderCommandEncoder(MTLRenderPassDescriptor*, const GrMtlPipelineState*, GrMtlOpsRenderPass* opsRenderPass); void addCompletedHandler(MTLCommandBufferHandler block) { [fCmdBuffer addCompletedHandler:block]; } void addGrBuffer(sk_sp buffer) { fTrackedGrBuffers.push_back(std::move(buffer)); } void encodeSignalEvent(id, uint64_t value) SK_API_AVAILABLE(macos(10.14), ios(12.0)); void encodeWaitForEvent(id, uint64_t value) SK_API_AVAILABLE(macos(10.14), ios(12.0)); void waitUntilCompleted() { [fCmdBuffer waitUntilCompleted]; } bool isCompleted() { return fCmdBuffer.status == MTLCommandBufferStatusCompleted || fCmdBuffer.status == MTLCommandBufferStatusError; } void callFinishedCallbacks() { fFinishedCallbacks.reset(); } private: static const int kInitialTrackedResourcesCount = 32; GrMtlCommandBuffer(id cmdBuffer) : fCmdBuffer(cmdBuffer) , fActiveBlitCommandEncoder(nil) , fActiveRenderCommandEncoder(nil) , fPreviousRenderPassDescriptor(nil) , fHasWork(false) {} void endAllEncoding(); id fCmdBuffer; id fActiveBlitCommandEncoder; id fActiveRenderCommandEncoder; MTLRenderPassDescriptor* fPreviousRenderPassDescriptor; bool fHasWork; SkTArray> fFinishedCallbacks; SkSTArray> fTrackedGrBuffers; }; GR_NORETAIN_END #endif