blob: 48e9e3d1d74f1f8aeb97ea9e3759699a90d191bf [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/private/SkTHash.h"
12#include "src/gpu/GrGpu.h"
Brian Salomon201cdbb2019-08-14 17:00:30 -040013#include "src/gpu/GrRenderTarget.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/gpu/GrSemaphore.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000015#include "src/gpu/GrTexture.h"
Brian Salomon91a3e522017-06-23 10:58:19 -040016
Greg Daniel2d41d0d2019-08-26 11:08:51 -040017class GrMockOpsRenderPass;
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:
Adlai Holler3d0359a2020-07-09 15:35:55 -040023 static sk_sp<GrGpu> Make(const GrMockOptions*, const GrContextOptions&, GrDirectContext*);
Brian Salomon91a3e522017-06-23 10:58:19 -040024
25 ~GrMockGpu() override {}
26
Greg Danielb20d7e52019-09-03 13:54:39 -040027 GrOpsRenderPass* getOpsRenderPass(
Robert Phillips96f22372020-05-20 12:31:18 -040028 GrRenderTarget*,
29 GrStencilAttachment*,
30 GrSurfaceOrigin,
31 const SkIRect&,
Greg Danielb20d7e52019-09-03 13:54:39 -040032 const GrOpsRenderPass::LoadAndStoreInfo&,
33 const GrOpsRenderPass::StencilLoadAndStoreInfo&,
Greg Daniel9a18b082020-08-14 14:03:50 -040034 const SkTArray<GrSurfaceProxy*, true>& sampledProxies,
35 bool usesXferBarriers) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040036
37 GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; }
Stephen Whiteb353c9b2020-04-16 14:14:13 -040038 bool waitFence(GrFence) override { return true; }
Brian Salomon91a3e522017-06-23 10:58:19 -040039 void deleteFence(GrFence) const override {}
40
Greg Daniel301015c2019-11-18 14:06:46 -050041 std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override {
Brian Salomon91a3e522017-06-23 10:58:19 -040042 return nullptr;
43 }
Greg Daniel301015c2019-11-18 14:06:46 -050044 std::unique_ptr<GrSemaphore> wrapBackendSemaphore(
45 const GrBackendSemaphore& semaphore,
46 GrResourceProvider::SemaphoreWrapType wrapType,
47 GrWrapOwnership ownership) override {
48 return nullptr;
49 }
50 void insertSemaphore(GrSemaphore* semaphore) override {}
51 void waitSemaphore(GrSemaphore* semaphore) override {}
52 std::unique_ptr<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override {
53 return nullptr;
54 }
Brian Salomon91a3e522017-06-23 10:58:19 -040055
Greg Daniel2d41d0d2019-08-26 11:08:51 -040056 void submit(GrOpsRenderPass* renderPass) override;
Brian Salomoncfe910d2017-07-06 16:40:18 -040057
Brian Salomonb0d8b762019-05-06 16:58:22 -040058 void checkFinishProcs() override {}
59
Brian Salomon91a3e522017-06-23 10:58:19 -040060private:
Adlai Holler3d0359a2020-07-09 15:35:55 -040061 GrMockGpu(GrDirectContext*, const GrMockOptions&, const GrContextOptions&);
Brian Salomon91a3e522017-06-23 10:58:19 -040062
63 void onResetContext(uint32_t resetBits) override {}
64
Chris Daltonc3318f02019-07-19 14:20:53 -060065 void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>* sampleLocations) override;
Chris Daltond7291ba2019-03-07 14:17:03 -070066
Brian Salomon91a3e522017-06-23 10:58:19 -040067 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
68
Brian Salomona56a7462020-02-07 14:17:25 -050069 sk_sp<GrTexture> onCreateTexture(SkISize,
Brian Salomon81536f22019-08-08 16:30:49 -040070 const GrBackendFormat&,
71 GrRenderable,
72 int renderTargetSampleCnt,
73 SkBudgeted,
74 GrProtected,
Brian Salomond2a8ae22019-09-10 16:03:59 -040075 int mipLevelCount,
76 uint32_t levelClearMask) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040077
Robert Phillips3a833922020-01-21 15:25:58 -050078 sk_sp<GrTexture> onCreateCompressedTexture(SkISize dimensions,
79 const GrBackendFormat&,
80 SkBudgeted,
Brian Salomon7e67dca2020-07-21 09:27:25 -040081 GrMipmapped,
Robert Phillips3a833922020-01-21 15:25:58 -050082 GrProtected,
83 const void* data, size_t dataSize) override;
Brian Salomonbb8dde82019-06-27 10:52:13 -040084
Brian Salomon8a78e9c2020-03-27 10:42:15 -040085 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&,
86 GrWrapOwnership,
87 GrWrapCacheable,
88 GrIOType) override;
89 sk_sp<GrTexture> onWrapCompressedBackendTexture(const GrBackendTexture&,
90 GrWrapOwnership,
Robert Phillipsb915c942019-12-17 14:44:37 -050091 GrWrapCacheable) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040092
Brian Salomond17f6582017-07-19 18:28:58 -040093 sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
Brian Salomond17f6582017-07-19 18:28:58 -040094 int sampleCnt,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050095 GrWrapOwnership,
96 GrWrapCacheable) override;
Brian Salomond17f6582017-07-19 18:28:58 -040097
Brian Salomon8a78e9c2020-03-27 10:42:15 -040098 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040099
100 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
Brian Salomon8a78e9c2020-03-27 10:42:15 -0400101 int sampleCnt) override;
Brian Salomon91a3e522017-06-23 10:58:19 -0400102
Brian Salomondbf70722019-02-07 11:31:24 -0500103 sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes, GrGpuBufferType, GrAccessPattern,
104 const void*) override;
Brian Salomon91a3e522017-06-23 10:58:19 -0400105
Brian Salomonf77c1462019-08-01 15:19:29 -0400106 bool onReadPixels(GrSurface* surface, int left, int top, int width, int height,
107 GrColorType surfaceColorType, GrColorType dstColorType, void* buffer,
108 size_t rowBytes) override {
Brian Salomoncfe910d2017-07-06 16:40:18 -0400109 return true;
Brian Salomon91a3e522017-06-23 10:58:19 -0400110 }
111
Brian Salomonf77c1462019-08-01 15:19:29 -0400112 bool onWritePixels(GrSurface* surface, int left, int top, int width, int height,
113 GrColorType surfaceColorType, GrColorType srcColorType,
Greg Danielb20d7e52019-09-03 13:54:39 -0400114 const GrMipLevel texels[], int mipLevelCount,
115 bool prepForTexSampling) override {
Brian Salomoncfe910d2017-07-06 16:40:18 -0400116 return true;
Brian Salomon91a3e522017-06-23 10:58:19 -0400117 }
118
Brian Salomone05ba5a2019-04-08 11:59:07 -0400119 bool onTransferPixelsTo(GrTexture* texture, int left, int top, int width, int height,
Brian Salomonf77c1462019-08-01 15:19:29 -0400120 GrColorType surfaceColorType, GrColorType bufferColorType,
121 GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override {
Brian Salomoncfe910d2017-07-06 16:40:18 -0400122 return true;
Brian Salomon91a3e522017-06-23 10:58:19 -0400123 }
Brian Salomon26de56e2019-04-10 12:14:26 -0400124 bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
Brian Salomonf77c1462019-08-01 15:19:29 -0400125 GrColorType surfaceColorType, GrColorType bufferColorType,
126 GrGpuBuffer* transferBuffer, size_t offset) override {
Brian Salomone05ba5a2019-04-08 11:59:07 -0400127 return true;
128 }
Greg Daniel46cfbc62019-06-07 11:43:30 -0400129 bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
Greg Daniele227fe42019-08-21 13:52:24 -0400130 const SkIPoint& dstPoint) override {
Brian Salomon9b009bb2018-02-14 13:53:55 -0500131 return true;
132 }
133
Brian Salomon930f9392018-06-20 16:25:26 -0400134 bool onRegenerateMipMapLevels(GrTexture*) override { return true; }
135
Jim Van Verthbb61fe32020-07-07 16:39:04 -0400136 void onResolveRenderTarget(GrRenderTarget* target, const SkIRect&) override {}
Brian Salomon91a3e522017-06-23 10:58:19 -0400137
Greg Danielfe159622020-04-10 17:43:51 +0000138 void addFinishedProc(GrGpuFinishedProc finishedProc,
139 GrGpuFinishedContext finishedContext) override {
140 SkASSERT(finishedProc);
141 finishedProc(finishedContext);
142 }
143
144 bool onSubmitToGpu(bool syncCpu) override {
Greg Daniel30a35e82019-11-19 14:12:25 -0500145 return true;
Greg Daniela3aa75a2019-04-12 14:24:55 -0400146 }
Greg Daniel51316782017-08-02 15:10:09 +0000147
Chris Daltoneffee202019-07-01 22:28:03 -0600148 GrStencilAttachment* createStencilAttachmentForRenderTarget(
149 const GrRenderTarget*, int width, int height, int numStencilSamples) override;
Robert Phillips4277f012020-01-21 14:28:34 -0500150 GrBackendTexture onCreateBackendTexture(SkISize dimensions,
Brian Salomon85c3d682019-11-04 15:04:54 -0500151 const GrBackendFormat&,
152 GrRenderable,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400153 GrMipmapped,
Greg Daniel16032b32020-05-06 15:31:10 -0400154 GrProtected) override;
155
156 bool onUpdateBackendTexture(const GrBackendTexture&,
157 sk_sp<GrRefCntedCallback> finishedCallback,
158 const BackendTextureData*) override {
159 return true;
160 }
161
Robert Phillipsb915c942019-12-17 14:44:37 -0500162 GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions,
163 const GrBackendFormat&,
Brian Salomon7e67dca2020-07-21 09:27:25 -0400164 GrMipmapped,
Greg Danielaaf738c2020-07-10 09:30:33 -0400165 GrProtected) override;
166
167 bool onUpdateCompressedBackendTexture(const GrBackendTexture&,
168 sk_sp<GrRefCntedCallback> finishedCallback,
169 const BackendTextureData*) override {
170 return true;
171 }
172
Robert Phillipsf0313ee2019-05-21 13:51:11 -0400173 void deleteBackendTexture(const GrBackendTexture&) override;
Robert Phillips50a4e6e2019-05-15 12:31:15 -0400174
Robert Phillips979b2232020-02-20 10:47:29 -0500175 bool compile(const GrProgramDesc&, const GrProgramInfo&) override { return false; }
176
Robert Phillipsf0ced622019-05-16 09:06:25 -0400177#if GR_TEST_UTILS
178 bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
179
Brian Osman2d010b62018-08-09 10:55:09 -0400180 GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override;
Brian Salomonf865b052018-03-09 09:01:53 -0500181 void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
182
Greg Daniel26b50a42018-03-08 09:49:58 -0500183 void testingOnly_flushGpuAndSync() override {}
Brian Salomonf865b052018-03-09 09:01:53 -0500184#endif
Greg Daniel26b50a42018-03-08 09:49:58 -0500185
Chris Dalton91ab1552018-04-18 13:24:25 -0600186 const GrMockOptions fMockOptions;
187
Brian Salomon8fe24272017-07-07 12:56:11 -0400188 static int NextInternalTextureID();
189 static int NextExternalTextureID();
Brian Salomon0c51eea2018-03-09 17:02:09 -0500190 static int NextInternalRenderTargetID();
191 static int NextExternalRenderTargetID();
Brian Salomon8fe24272017-07-07 12:56:11 -0400192
193 SkTHashSet<int> fOutstandingTestingOnlyTextureIDs;
Brian Salomon91a3e522017-06-23 10:58:19 -0400194
John Stiles7571f9e2020-09-02 22:42:33 -0400195 using INHERITED = GrGpu;
Brian Salomon91a3e522017-06-23 10:58:19 -0400196};
Brian Salomoncfe910d2017-07-06 16:40:18 -0400197
198#endif