blob: 0b874bb7fa9cb4efe410ae87cf9308913a5d861a [file] [log] [blame]
Brian Salomon91a3e522017-06-23 10:58:19 -04001/*
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 */
Brian Salomoncfe910d2017-07-06 16:40:18 -04007
Hal Canary466c7d62017-07-03 15:11:49 -04008#ifndef GrMockGpu_DEFINED
9#define GrMockGpu_DEFINED
Brian Salomon91a3e522017-06-23 10:58:19 -040010
11#include "GrGpu.h"
Robert Phillips2890fbf2017-07-26 15:48:41 -040012#include "GrRenderTarget.h"
Brian Salomon91a3e522017-06-23 10:58:19 -040013#include "GrSemaphore.h"
Hal Canary466c7d62017-07-03 15:11:49 -040014#include "GrTexture.h"
Brian Salomon8fe24272017-07-07 12:56:11 -040015#include "SkTHash.h"
Brian Salomon91a3e522017-06-23 10:58:19 -040016
Greg Daniel500d58b2017-08-24 15:59:33 -040017class GrMockGpuRTCommandBuffer;
Brian Salomoncfe910d2017-07-06 16:40:18 -040018struct GrMockOptions;
Brian Salomon91a3e522017-06-23 10:58:19 -040019class GrPipeline;
20
Brian Salomon91a3e522017-06-23 10:58:19 -040021class GrMockGpu : public GrGpu {
22public:
Brian Salomon384fab42017-12-07 12:33:05 -050023 static sk_sp<GrGpu> Make(const GrMockOptions*, const GrContextOptions&, GrContext*);
Brian Salomon91a3e522017-06-23 10:58:19 -040024
25 ~GrMockGpu() override {}
26
Greg Daniel500d58b2017-08-24 15:59:33 -040027 GrGpuRTCommandBuffer* createCommandBuffer(
Robert Phillips95214472017-08-08 18:00:03 -040028 GrRenderTarget*, GrSurfaceOrigin,
Greg Daniel500d58b2017-08-24 15:59:33 -040029 const GrGpuRTCommandBuffer::LoadAndStoreInfo&,
30 const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) override;
31
32 GrGpuTextureCommandBuffer* createCommandBuffer(GrTexture*, GrSurfaceOrigin) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040033
34 GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; }
35 bool waitFence(GrFence, uint64_t) override { return true; }
36 void deleteFence(GrFence) const override {}
37
38 sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override {
39 return nullptr;
40 }
Greg Daniel48661b82018-01-22 16:11:35 -050041 sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore,
42 GrResourceProvider::SemaphoreWrapType wrapType,
43 GrWrapOwnership ownership) override { return nullptr; }
44 void insertSemaphore(sk_sp<GrSemaphore> semaphore, bool flush) override {}
45 void waitSemaphore(sk_sp<GrSemaphore> semaphore) override {}
Brian Salomon91a3e522017-06-23 10:58:19 -040046 sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override { return nullptr; }
47
Greg Daniel500d58b2017-08-24 15:59:33 -040048 void submitCommandBuffer(const GrMockGpuRTCommandBuffer*);
Brian Salomoncfe910d2017-07-06 16:40:18 -040049
Brian Salomon91a3e522017-06-23 10:58:19 -040050private:
Brian Salomoncfe910d2017-07-06 16:40:18 -040051 GrMockGpu(GrContext* context, const GrMockOptions&, const GrContextOptions&);
Brian Salomon91a3e522017-06-23 10:58:19 -040052
53 void onResetContext(uint32_t resetBits) override {}
54
55 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
56
Brian Salomon58389b92018-03-07 13:01:25 -050057 sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc&, SkBudgeted, const GrMipLevel[],
58 int mipLevelCount) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040059
Greg Daniel4684f822018-03-08 15:27:36 -050060 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040061
Brian Salomond17f6582017-07-19 18:28:58 -040062 sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
Brian Salomond17f6582017-07-19 18:28:58 -040063 int sampleCnt,
Brian Salomon0c51eea2018-03-09 17:02:09 -050064 GrWrapOwnership) override;
Brian Salomond17f6582017-07-19 18:28:58 -040065
Brian Salomon0c51eea2018-03-09 17:02:09 -050066 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040067
68 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
Brian Salomon0c51eea2018-03-09 17:02:09 -050069 int sampleCnt) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040070
Brian Salomoncfe910d2017-07-06 16:40:18 -040071 GrBuffer* onCreateBuffer(size_t sizeInBytes, GrBufferType, GrAccessPattern,
72 const void*) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040073
Brian Salomonc320b152018-02-20 14:05:36 -050074 bool onReadPixels(GrSurface* surface, GrSurfaceOrigin, int left, int top, int width, int height,
75 GrColorType, void* buffer, size_t rowBytes) override {
Brian Salomoncfe910d2017-07-06 16:40:18 -040076 return true;
Brian Salomon91a3e522017-06-23 10:58:19 -040077 }
78
Brian Salomona9b04b92018-06-01 15:04:28 -040079 bool onWritePixels(GrSurface* surface, int left, int top, int width, int height, GrColorType,
80 const GrMipLevel texels[], int mipLevelCount) override {
Brian Salomoncfe910d2017-07-06 16:40:18 -040081 return true;
Brian Salomon91a3e522017-06-23 10:58:19 -040082 }
83
Brian Salomonc320b152018-02-20 14:05:36 -050084 bool onTransferPixels(GrTexture* texture, int left, int top, int width, int height, GrColorType,
85 GrBuffer* transferBuffer, size_t offset, size_t rowBytes) override {
Brian Salomoncfe910d2017-07-06 16:40:18 -040086 return true;
Brian Salomon91a3e522017-06-23 10:58:19 -040087 }
88
Brian Salomon9b009bb2018-02-14 13:53:55 -050089 bool onCopySurface(GrSurface* dst, GrSurfaceOrigin dstOrigin, GrSurface* src,
90 GrSurfaceOrigin srcOrigin, const SkIRect& srcRect,
Greg Daniel55fa6472018-03-16 16:13:10 -040091 const SkIPoint& dstPoint, bool canDiscardOutsideDstRect) override {
Brian Salomon9b009bb2018-02-14 13:53:55 -050092 return true;
93 }
94
Brian Salomon1fabd512018-02-09 09:54:25 -050095 void onResolveRenderTarget(GrRenderTarget* target) override { return; }
Brian Salomon91a3e522017-06-23 10:58:19 -040096
Greg Daniel51316782017-08-02 15:10:09 +000097 void onFinishFlush(bool insertedSemaphores) override {}
98
Brian Salomon91a3e522017-06-23 10:58:19 -040099 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
100 int width,
Brian Salomoncfe910d2017-07-06 16:40:18 -0400101 int height) override;
Robert Phillips95214472017-08-08 18:00:03 -0400102 void clearStencil(GrRenderTarget*, int clearValue) override {}
Brian Salomon91a3e522017-06-23 10:58:19 -0400103
Brian Salomonf865b052018-03-09 09:01:53 -0500104#if GR_TEST_UTILS
Brian Salomon52e943a2018-03-13 09:32:39 -0400105 GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h,
106 GrPixelConfig, bool isRT,
107 GrMipMapped) override;
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500108 bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
Brian Salomon26102cb2018-03-09 09:33:19 -0500109 void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override;
Brian Salomon8fe24272017-07-07 12:56:11 -0400110
Brian Salomonf865b052018-03-09 09:01:53 -0500111 GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType,
112 GrSRGBEncoded) override;
113 void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
114
Greg Daniel26b50a42018-03-08 09:49:58 -0500115 void testingOnly_flushGpuAndSync() override {}
Brian Salomonf865b052018-03-09 09:01:53 -0500116#endif
Greg Daniel26b50a42018-03-08 09:49:58 -0500117
Chris Dalton91ab1552018-04-18 13:24:25 -0600118 const GrMockOptions fMockOptions;
119
Brian Salomon8fe24272017-07-07 12:56:11 -0400120 static int NextInternalTextureID();
121 static int NextExternalTextureID();
Brian Salomon0c51eea2018-03-09 17:02:09 -0500122 static int NextInternalRenderTargetID();
123 static int NextExternalRenderTargetID();
Brian Salomon8fe24272017-07-07 12:56:11 -0400124
125 SkTHashSet<int> fOutstandingTestingOnlyTextureIDs;
Brian Salomon91a3e522017-06-23 10:58:19 -0400126
127 typedef GrGpu INHERITED;
128};
Brian Salomoncfe910d2017-07-06 16:40:18 -0400129
130#endif