Home | History | Annotate | Download | only in mtl
      1 /*
      2  * Copyright 2017 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 GrMtlGpu_DEFINED
      9 #define GrMtlGpu_DEFINED
     10 
     11 #include "GrGpu.h"
     12 #include "GrRenderTarget.h"
     13 #include "GrSemaphore.h"
     14 #include "GrTexture.h"
     15 
     16 #import <Metal/Metal.h>
     17 
     18 class GrSemaphore;
     19 struct GrMtlBackendContext;
     20 
     21 class GrMtlGpu : public GrGpu {
     22 public:
     23     static GrGpu* Create(GrContext* context, const GrContextOptions& options,
     24                          id<MTLDevice> device, id<MTLCommandQueue> queue);
     25 
     26     ~GrMtlGpu() override {}
     27 
     28     bool onGetReadPixelsInfo(GrSurface* srcSurface, int readWidth, int readHeight, size_t rowBytes,
     29                              GrPixelConfig readConfig, DrawPreference*,
     30                              ReadPixelTempDrawInfo*) override { return false; }
     31 
     32     bool onGetWritePixelsInfo(GrSurface* dstSurface, int width, int height,
     33                               GrPixelConfig srcConfig, DrawPreference*,
     34                               WritePixelTempDrawInfo*) override { return false; }
     35 
     36     bool onCopySurface(GrSurface* dst,
     37                        GrSurface* src,
     38                        const SkIRect& srcRect,
     39                        const SkIPoint& dstPoint) override { return false; }
     40 
     41     void onQueryMultisampleSpecs(GrRenderTarget* rt, const GrStencilSettings&,
     42                                  int* effectiveSampleCnt, SamplePattern*) override {}
     43 
     44     GrGpuCommandBuffer* createCommandBuffer(const GrGpuCommandBuffer::LoadAndStoreInfo&,
     45                                             const GrGpuCommandBuffer::LoadAndStoreInfo&) override {
     46         return nullptr;
     47     }
     48 
     49     GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; }
     50     bool waitFence(GrFence, uint64_t) override { return true; }
     51     void deleteFence(GrFence) const override {}
     52 
     53     sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override {
     54         return nullptr;
     55     }
     56     sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore,
     57                                             GrWrapOwnership ownership) override { return nullptr; }
     58     void insertSemaphore(sk_sp<GrSemaphore> semaphore, bool flush) override {}
     59     void waitSemaphore(sk_sp<GrSemaphore> semaphore) override {}
     60     sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override { return nullptr; }
     61 
     62 private:
     63     GrMtlGpu(GrContext* context, const GrContextOptions& options,
     64              id<MTLDevice> device, id<MTLCommandQueue> queue);
     65 
     66     void onResetContext(uint32_t resetBits) override {}
     67 
     68     void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
     69 
     70     sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
     71                                      const GrMipLevel texels[], int mipLevelCount) override {
     72         return nullptr;
     73     }
     74 
     75     sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&,
     76                                           GrSurfaceOrigin,
     77                                           GrBackendTextureFlags,
     78                                           int sampleCnt,
     79                                           GrWrapOwnership) override {
     80         return nullptr;
     81     }
     82 
     83     sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
     84                                                     GrSurfaceOrigin) override {
     85         return nullptr;
     86     }
     87 
     88     sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
     89                                                              GrSurfaceOrigin,
     90                                                              int sampleCnt) override {
     91         return nullptr;
     92     }
     93 
     94     GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override {
     95         return nullptr;
     96     }
     97 
     98     gr_instanced::InstancedRendering* onCreateInstancedRendering() override { return nullptr; }
     99 
    100     bool onReadPixels(GrSurface* surface,
    101                       int left, int top, int width, int height,
    102                       GrPixelConfig,
    103                       void* buffer,
    104                       size_t rowBytes) override {
    105         return false;
    106     }
    107 
    108     bool onWritePixels(GrSurface* surface,
    109                        int left, int top, int width, int height,
    110                        GrPixelConfig config,
    111                        const GrMipLevel texels[], int mipLevelCount) override {
    112         return false;
    113     }
    114 
    115     bool onTransferPixels(GrTexture* texture,
    116                           int left, int top, int width, int height,
    117                           GrPixelConfig config, GrBuffer* transferBuffer,
    118                           size_t offset, size_t rowBytes) override {
    119         return false;
    120     }
    121 
    122     void onResolveRenderTarget(GrRenderTarget* target) override { return; }
    123 
    124     GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
    125                                                                 int width,
    126                                                                 int height) override {
    127         return nullptr;
    128     }
    129 
    130     void clearStencil(GrRenderTarget* target) override  {}
    131 
    132     GrBackendObject createTestingOnlyBackendTexture(void* pixels, int w, int h,
    133                                                     GrPixelConfig config, bool isRT) override {
    134         return 0;
    135     }
    136     bool isTestingOnlyBackendTexture(GrBackendObject ) const override { return false; }
    137     void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) override {}
    138 
    139     id<MTLDevice> fDevice;
    140     id<MTLCommandQueue> fQueue;
    141 
    142 
    143     typedef GrGpu INHERITED;
    144 };
    145 
    146 #endif
    147 
    148