/* * Copyright 2017 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef GrMtlGpu_DEFINED #define GrMtlGpu_DEFINED #include "GrGpu.h" #include "GrRenderTarget.h" #include "GrSemaphore.h" #include "GrTexture.h" #include "GrMtlCaps.h" #include "GrMtlCopyManager.h" #include "GrMtlResourceProvider.h" #import class GrMtlTexture; class GrSemaphore; struct GrMtlBackendContext; namespace SkSL { class Compiler; } class GrMtlGpu : public GrGpu { public: static sk_sp Make(GrContext* context, const GrContextOptions& options, id device, id queue); ~GrMtlGpu() override = default; const GrMtlCaps& mtlCaps() const { return *fMtlCaps.get(); } id device() const { return fDevice; } id commandBuffer() const { return fCmdBuffer; } GrMtlResourceProvider& resourceProvider() { return fResourceProvider; } enum SyncQueue { kForce_SyncQueue, kSkip_SyncQueue }; #ifdef GR_TEST_UTILS GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h, GrPixelConfig config, bool isRT, GrMipMapped) override; bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override; GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType, GrSRGBEncoded) override; void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override; void testingOnly_flushGpuAndSync() override; #endif bool copySurfaceAsBlit(GrSurface* dst, GrSurfaceOrigin dstOrigin, GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect, const SkIPoint& dstPoint); bool onCopySurface(GrSurface* dst, GrSurfaceOrigin dstOrigin, GrSurface* src, GrSurfaceOrigin srcOrigin, const SkIRect& srcRect, const SkIPoint& dstPoint, bool canDiscardOutsideDstRect) override; GrGpuRTCommandBuffer* createCommandBuffer( GrRenderTarget*, GrSurfaceOrigin, const GrGpuRTCommandBuffer::LoadAndStoreInfo&, const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) override; GrGpuTextureCommandBuffer* createCommandBuffer(GrTexture*, GrSurfaceOrigin) override; SkSL::Compiler* shaderCompiler() const { return fCompiler.get(); } GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; } bool waitFence(GrFence, uint64_t) override { return true; } void deleteFence(GrFence) const override {} sk_sp SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override { return nullptr; } sk_sp wrapBackendSemaphore(const GrBackendSemaphore& semaphore, GrResourceProvider::SemaphoreWrapType wrapType, GrWrapOwnership ownership) override { return nullptr; } void insertSemaphore(sk_sp semaphore, bool flush) override {} void waitSemaphore(sk_sp semaphore) override {} sk_sp prepareTextureForCrossContextUsage(GrTexture*) override { return nullptr; } private: GrMtlGpu(GrContext* context, const GrContextOptions& options, id device, id queue, MTLFeatureSet featureSet); void onResetContext(uint32_t resetBits) override {} void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {} sk_sp onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, const GrMipLevel texels[], int mipLevelCount) override; sk_sp onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership) override; sk_sp onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt, GrWrapOwnership) override; sk_sp onWrapBackendRenderTarget(const GrBackendRenderTarget&) override; sk_sp onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, int sampleCnt) override; GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override { return nullptr; } bool onReadPixels(GrSurface* surface, int left, int top, int width, int height, GrColorType, void* buffer, size_t rowBytes) override; bool onWritePixels(GrSurface*, int left, int top, int width, int height, GrColorType, const GrMipLevel[], int mipLevelCount) override; bool onTransferPixels(GrTexture*, int left, int top, int width, int height, GrColorType, GrBuffer*, size_t offset, size_t rowBytes) override { return false; } bool onRegenerateMipMapLevels(GrTexture*) override { return false; } void onResolveRenderTarget(GrRenderTarget* target) override { return; } void onFinishFlush(bool insertedSemaphores) override {} // Commits the current command buffer to the queue and then creates a new command buffer. If // sync is set to kForce_SyncQueue, the function will wait for all work in the committed // command buffer to finish before creating a new buffer and returning. void submitCommandBuffer(SyncQueue sync); // Function that uploads data onto textures with private storage mode (GPU access only). bool uploadToTexture(GrMtlTexture* tex, int left, int top, int width, int height, GrColorType dataColorType, const GrMipLevel texels[], int mipLevels); GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*, int width, int height) override { return nullptr; } void clearStencil(GrRenderTarget* target, int clearValue) override {} #if GR_TEST_UTILS bool createTestingOnlyMtlTextureInfo(GrPixelConfig config, int w, int h, bool texturable, bool renderable, GrMipMapped mipMapped, const void* srcData, GrMtlTextureInfo* info); #endif sk_sp fMtlCaps; id fDevice; id fQueue; id fCmdBuffer; std::unique_ptr fCompiler; GrMtlCopyManager fCopyManager; GrMtlResourceProvider fResourceProvider; typedef GrGpu INHERITED; }; #endif