blob: 64b267b7539b4b5c83b2a59e8dbce4181ff4c1ed [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
Robert Phillips5b5d84c2018-08-09 15:12:18 -040027 GrGpuRTCommandBuffer* getCommandBuffer(
Ethan Nicholas56d19a52018-10-15 11:26:20 -040028 GrRenderTarget*, GrSurfaceOrigin, const SkRect&,
Greg Daniel500d58b2017-08-24 15:59:33 -040029 const GrGpuRTCommandBuffer::LoadAndStoreInfo&,
30 const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) override;
31
Robert Phillips5b5d84c2018-08-09 15:12:18 -040032 GrGpuTextureCommandBuffer* getCommandBuffer(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
Robert Phillips5b5d84c2018-08-09 15:12:18 -040048 void submit(GrGpuCommandBuffer* buffer) override;
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
Robert Phillips5b5d84c2018-08-09 15:12:18 -040053 void submitCommandBuffer(const GrMockGpuRTCommandBuffer*);
54
Brian Salomon91a3e522017-06-23 10:58:19 -040055 void onResetContext(uint32_t resetBits) override {}
56
57 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
58
Brian Salomon58389b92018-03-07 13:01:25 -050059 sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc&, SkBudgeted, const GrMipLevel[],
60 int mipLevelCount) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040061
Greg Daniel4684f822018-03-08 15:27:36 -050062 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040063
Brian Salomond17f6582017-07-19 18:28:58 -040064 sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
Brian Salomond17f6582017-07-19 18:28:58 -040065 int sampleCnt,
Brian Salomon0c51eea2018-03-09 17:02:09 -050066 GrWrapOwnership) override;
Brian Salomond17f6582017-07-19 18:28:58 -040067
Brian Salomon0c51eea2018-03-09 17:02:09 -050068 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040069
70 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
Brian Salomon0c51eea2018-03-09 17:02:09 -050071 int sampleCnt) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040072
Brian Salomoncfe910d2017-07-06 16:40:18 -040073 GrBuffer* onCreateBuffer(size_t sizeInBytes, GrBufferType, GrAccessPattern,
74 const void*) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040075
Brian Salomona6948702018-06-01 15:33:20 -040076 bool onReadPixels(GrSurface* surface, int left, int top, int width, int height, GrColorType,
77 void* buffer, size_t rowBytes) override {
Brian Salomoncfe910d2017-07-06 16:40:18 -040078 return true;
Brian Salomon91a3e522017-06-23 10:58:19 -040079 }
80
Brian Salomona9b04b92018-06-01 15:04:28 -040081 bool onWritePixels(GrSurface* surface, int left, int top, int width, int height, GrColorType,
82 const GrMipLevel texels[], int mipLevelCount) override {
Brian Salomoncfe910d2017-07-06 16:40:18 -040083 return true;
Brian Salomon91a3e522017-06-23 10:58:19 -040084 }
85
Brian Salomonc320b152018-02-20 14:05:36 -050086 bool onTransferPixels(GrTexture* texture, int left, int top, int width, int height, GrColorType,
87 GrBuffer* transferBuffer, size_t offset, size_t rowBytes) override {
Brian Salomoncfe910d2017-07-06 16:40:18 -040088 return true;
Brian Salomon91a3e522017-06-23 10:58:19 -040089 }
90
Brian Salomon9b009bb2018-02-14 13:53:55 -050091 bool onCopySurface(GrSurface* dst, GrSurfaceOrigin dstOrigin, GrSurface* src,
92 GrSurfaceOrigin srcOrigin, const SkIRect& srcRect,
Greg Daniel55fa6472018-03-16 16:13:10 -040093 const SkIPoint& dstPoint, bool canDiscardOutsideDstRect) override {
Brian Salomon9b009bb2018-02-14 13:53:55 -050094 return true;
95 }
96
Brian Salomon930f9392018-06-20 16:25:26 -040097 bool onRegenerateMipMapLevels(GrTexture*) override { return true; }
98
Brian Salomon1fabd512018-02-09 09:54:25 -050099 void onResolveRenderTarget(GrRenderTarget* target) override { return; }
Brian Salomon91a3e522017-06-23 10:58:19 -0400100
Greg Daniel51316782017-08-02 15:10:09 +0000101 void onFinishFlush(bool insertedSemaphores) override {}
102
Brian Salomon91a3e522017-06-23 10:58:19 -0400103 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
104 int width,
Brian Salomoncfe910d2017-07-06 16:40:18 -0400105 int height) override;
Brian Salomonf865b052018-03-09 09:01:53 -0500106#if GR_TEST_UTILS
Brian Salomon52e943a2018-03-13 09:32:39 -0400107 GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h,
Robert Phillips646f6372018-09-25 09:31:10 -0400108 GrColorType, bool isRT,
109 GrMipMapped, size_t rowBytes = 0) override;
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500110 bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
Brian Salomon26102cb2018-03-09 09:33:19 -0500111 void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override;
Brian Salomon8fe24272017-07-07 12:56:11 -0400112
Brian Osman2d010b62018-08-09 10:55:09 -0400113 GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override;
Brian Salomonf865b052018-03-09 09:01:53 -0500114 void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
115
Greg Daniel26b50a42018-03-08 09:49:58 -0500116 void testingOnly_flushGpuAndSync() override {}
Brian Salomonf865b052018-03-09 09:01:53 -0500117#endif
Greg Daniel26b50a42018-03-08 09:49:58 -0500118
Chris Dalton91ab1552018-04-18 13:24:25 -0600119 const GrMockOptions fMockOptions;
120
Brian Salomon8fe24272017-07-07 12:56:11 -0400121 static int NextInternalTextureID();
122 static int NextExternalTextureID();
Brian Salomon0c51eea2018-03-09 17:02:09 -0500123 static int NextInternalRenderTargetID();
124 static int NextExternalRenderTargetID();
Brian Salomon8fe24272017-07-07 12:56:11 -0400125
126 SkTHashSet<int> fOutstandingTestingOnlyTextureIDs;
Brian Salomon91a3e522017-06-23 10:58:19 -0400127
128 typedef GrGpu INHERITED;
129};
Brian Salomoncfe910d2017-07-06 16:40:18 -0400130
131#endif