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#include "GrMtlCaps.h"
17
18#import <Metal/Metal.h>
19
20class GrSemaphore;
21struct GrMtlBackendContext;
22
23class GrMtlGpu : public GrGpu {
24public:
25    static sk_sp<GrGpu> Make(GrContext* context, const GrContextOptions& options,
26                             id<MTLDevice> device, id<MTLCommandQueue> queue);
27
28    ~GrMtlGpu() override {}
29
30    const GrMtlCaps& mtlCaps() const { return *fMtlCaps.get(); }
31
32    id<MTLDevice> device() const { return fDevice; }
33
34    bool onGetReadPixelsInfo(GrSurface* srcSurface, GrSurfaceOrigin origin,
35                             int readWidth, int readHeight, size_t rowBytes,
36                             GrPixelConfig readConfig, DrawPreference*,
37                             ReadPixelTempDrawInfo*) override { return false; }
38
39    bool onGetWritePixelsInfo(GrSurface* dstSurface, GrSurfaceOrigin dstOrigin,
40                              int width, int height,
41                              GrPixelConfig srcConfig, DrawPreference*,
42                              WritePixelTempDrawInfo*) override { return false; }
43
44    bool onCopySurface(GrSurface* dst, GrSurfaceOrigin dstOrigin,
45                       GrSurface* src, GrSurfaceOrigin srcOrigin,
46                       const SkIRect& srcRect,
47                       const SkIPoint& dstPoint,
48                       bool canDiscardOutsideDstRect) override { return false; }
49
50    void onQueryMultisampleSpecs(GrRenderTarget*, GrSurfaceOrigin, const GrStencilSettings&,
51                                 int* effectiveSampleCnt, SamplePattern*) override {}
52
53    GrGpuRTCommandBuffer* createCommandBuffer(
54                                    GrRenderTarget*, GrSurfaceOrigin,
55                                    const GrGpuRTCommandBuffer::LoadAndStoreInfo&,
56                                    const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) override {
57        return nullptr;
58    }
59
60    GrGpuTextureCommandBuffer* createCommandBuffer(GrTexture*, GrSurfaceOrigin) override {
61        return nullptr;
62    }
63
64    GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; }
65    bool waitFence(GrFence, uint64_t) override { return true; }
66    void deleteFence(GrFence) const override {}
67
68    sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override {
69        return nullptr;
70    }
71    sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore,
72                                            GrResourceProvider::SemaphoreWrapType wrapType,
73                                            GrWrapOwnership ownership) override { return nullptr; }
74    void insertSemaphore(sk_sp<GrSemaphore> semaphore, bool flush) override {}
75    void waitSemaphore(sk_sp<GrSemaphore> semaphore) override {}
76    sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override { return nullptr; }
77
78private:
79    GrMtlGpu(GrContext* context, const GrContextOptions& options,
80             id<MTLDevice> device, id<MTLCommandQueue> queue, MTLFeatureSet featureSet);
81
82    void onResetContext(uint32_t resetBits) override {}
83
84    void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
85
86    sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted,
87                                     const GrMipLevel texels[], int mipLevelCount) override;
88
89    sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership) override {
90        return nullptr;
91    }
92
93    sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
94                                                    int sampleCnt,
95                                                    GrWrapOwnership) override {
96        return nullptr;
97    }
98
99    sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override {
100        return nullptr;
101    }
102
103    sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
104                                                             int sampleCnt) override {
105        return nullptr;
106    }
107
108    GrBuffer* onCreateBuffer(size_t, GrBufferType, GrAccessPattern, const void*) override {
109        return nullptr;
110    }
111
112    bool onReadPixels(GrSurface* surface, GrSurfaceOrigin,
113                      int left, int top, int width, int height,
114                      GrPixelConfig,
115                      void* buffer,
116                      size_t rowBytes) override {
117        return false;
118    }
119
120    bool onWritePixels(GrSurface* surface, GrSurfaceOrigin,
121                       int left, int top, int width, int height,
122                       GrPixelConfig config,
123                       const GrMipLevel texels[], int mipLevelCount) override {
124        return false;
125    }
126
127    bool onTransferPixels(GrTexture* texture,
128                          int left, int top, int width, int height,
129                          GrPixelConfig config, GrBuffer* transferBuffer,
130                          size_t offset, size_t rowBytes) override {
131        return false;
132    }
133
134    void onResolveRenderTarget(GrRenderTarget* target, GrSurfaceOrigin) override { return; }
135
136    void onFinishFlush(bool insertedSemaphores) override {}
137
138    GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
139                                                                int width,
140                                                                int height) override {
141        return nullptr;
142    }
143
144    void clearStencil(GrRenderTarget* target, int clearValue) override  {}
145
146    GrBackendTexture createTestingOnlyBackendTexture(void* pixels, int w, int h,
147                                                     GrPixelConfig config, bool isRT,
148                                                     GrMipMapped) override {
149        return GrBackendTexture();
150    }
151    bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override { return false; }
152    void deleteTestingOnlyBackendTexture(GrBackendTexture*, bool abandon = false) override {}
153
154    void testingOnly_flushGpuAndSync() override {}
155
156    sk_sp<GrMtlCaps> fMtlCaps;
157
158    id<MTLDevice> fDevice;
159    id<MTLCommandQueue> fQueue;
160
161
162    typedef GrGpu INHERITED;
163};
164
165#endif
166
167