blob: 5d86a8483db580e87d20400f991b6a1f41f7547c [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/gpu/GrRenderTarget.h"
12#include "include/gpu/GrTexture.h"
13#include "include/private/SkTHash.h"
14#include "src/gpu/GrGpu.h"
15#include "src/gpu/GrSemaphore.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; }
Greg Daniel858e12c2018-12-06 11:11:37 -050044 void insertSemaphore(sk_sp<GrSemaphore> semaphore) override {}
Greg Daniel48661b82018-01-22 16:11:35 -050045 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 Salomonb0d8b762019-05-06 16:58:22 -040050 void checkFinishProcs() override {}
51
Brian Salomon91a3e522017-06-23 10:58:19 -040052private:
Brian Salomoncfe910d2017-07-06 16:40:18 -040053 GrMockGpu(GrContext* context, const GrMockOptions&, const GrContextOptions&);
Brian Salomon91a3e522017-06-23 10:58:19 -040054
Robert Phillips5b5d84c2018-08-09 15:12:18 -040055 void submitCommandBuffer(const GrMockGpuRTCommandBuffer*);
56
Brian Salomon91a3e522017-06-23 10:58:19 -040057 void onResetContext(uint32_t resetBits) override {}
58
Chris Daltonc3318f02019-07-19 14:20:53 -060059 void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>* sampleLocations) override;
Chris Daltond7291ba2019-03-07 14:17:03 -070060
Brian Salomon91a3e522017-06-23 10:58:19 -040061 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
62
Brian Salomon27b4d8d2019-07-22 14:23:45 -040063 sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc&, GrRenderable, int renderTargetSampleCnt,
64 SkBudgeted, GrProtected, const GrMipLevel[],
65 int mipLevelCount) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040066
Brian Salomonbb8dde82019-06-27 10:52:13 -040067 sk_sp<GrTexture> onCreateCompressedTexture(int width, int height, SkImage::CompressionType,
68 SkBudgeted, const void* data) override;
69
Robert Phillipsc80b0e92019-07-23 10:27:09 -040070 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrColorType, GrWrapOwnership,
71 GrWrapCacheable, GrIOType) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040072
Brian Salomond17f6582017-07-19 18:28:58 -040073 sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
Brian Salomond17f6582017-07-19 18:28:58 -040074 int sampleCnt,
Robert Phillips0902c982019-07-16 07:47:56 -040075 GrColorType,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050076 GrWrapOwnership,
77 GrWrapCacheable) override;
Brian Salomond17f6582017-07-19 18:28:58 -040078
Robert Phillipsc80b0e92019-07-23 10:27:09 -040079 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
80 GrColorType) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040081
82 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
Robert Phillipsc80b0e92019-07-23 10:27:09 -040083 int sampleCnt, GrColorType) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040084
Brian Salomondbf70722019-02-07 11:31:24 -050085 sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes, GrGpuBufferType, GrAccessPattern,
86 const void*) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040087
Brian Salomonf77c1462019-08-01 15:19:29 -040088 bool onReadPixels(GrSurface* surface, int left, int top, int width, int height,
89 GrColorType surfaceColorType, GrColorType dstColorType, void* buffer,
90 size_t rowBytes) override {
Brian Salomoncfe910d2017-07-06 16:40:18 -040091 return true;
Brian Salomon91a3e522017-06-23 10:58:19 -040092 }
93
Brian Salomonf77c1462019-08-01 15:19:29 -040094 bool onWritePixels(GrSurface* surface, int left, int top, int width, int height,
95 GrColorType surfaceColorType, GrColorType srcColorType,
Brian Salomona9b04b92018-06-01 15:04:28 -040096 const GrMipLevel texels[], int mipLevelCount) override {
Brian Salomoncfe910d2017-07-06 16:40:18 -040097 return true;
Brian Salomon91a3e522017-06-23 10:58:19 -040098 }
99
Brian Salomone05ba5a2019-04-08 11:59:07 -0400100 bool onTransferPixelsTo(GrTexture* texture, int left, int top, int width, int height,
Brian Salomonf77c1462019-08-01 15:19:29 -0400101 GrColorType surfaceColorType, GrColorType bufferColorType,
102 GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override {
Brian Salomoncfe910d2017-07-06 16:40:18 -0400103 return true;
Brian Salomon91a3e522017-06-23 10:58:19 -0400104 }
Brian Salomon26de56e2019-04-10 12:14:26 -0400105 bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
Brian Salomonf77c1462019-08-01 15:19:29 -0400106 GrColorType surfaceColorType, GrColorType bufferColorType,
107 GrGpuBuffer* transferBuffer, size_t offset) override {
Brian Salomone05ba5a2019-04-08 11:59:07 -0400108 return true;
109 }
Greg Daniel46cfbc62019-06-07 11:43:30 -0400110 bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
Greg Daniel55fa6472018-03-16 16:13:10 -0400111 const SkIPoint& dstPoint, bool canDiscardOutsideDstRect) override {
Brian Salomon9b009bb2018-02-14 13:53:55 -0500112 return true;
113 }
114
Brian Salomon930f9392018-06-20 16:25:26 -0400115 bool onRegenerateMipMapLevels(GrTexture*) override { return true; }
116
Brian Salomon1fabd512018-02-09 09:54:25 -0500117 void onResolveRenderTarget(GrRenderTarget* target) override { return; }
Brian Salomon91a3e522017-06-23 10:58:19 -0400118
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400119 void onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfaceAccess access,
Greg Daniel797efca2019-05-09 14:04:20 -0400120 const GrFlushInfo& info, const GrPrepareForExternalIORequests&) override {
Greg Daniele6bfb7d2019-04-17 15:26:11 -0400121 if (info.fFinishedProc) {
122 info.fFinishedProc(info.fFinishedContext);
Greg Daniela3aa75a2019-04-12 14:24:55 -0400123 }
124 }
Greg Daniel51316782017-08-02 15:10:09 +0000125
Chris Daltoneffee202019-07-01 22:28:03 -0600126 GrStencilAttachment* createStencilAttachmentForRenderTarget(
127 const GrRenderTarget*, int width, int height, int numStencilSamples) override;
Robert Phillipsf0313ee2019-05-21 13:51:11 -0400128 GrBackendTexture createBackendTexture(int w, int h, const GrBackendFormat&,
129 GrMipMapped, GrRenderable,
Robert Phillips459b2952019-05-23 09:38:27 -0400130 const void* pixels, size_t rowBytes,
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400131 const SkColor4f* color, GrProtected isProtected) override;
Robert Phillipsf0313ee2019-05-21 13:51:11 -0400132 void deleteBackendTexture(const GrBackendTexture&) override;
Robert Phillips50a4e6e2019-05-15 12:31:15 -0400133
Robert Phillipsf0ced622019-05-16 09:06:25 -0400134#if GR_TEST_UTILS
135 bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
136
Brian Osman2d010b62018-08-09 10:55:09 -0400137 GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override;
Brian Salomonf865b052018-03-09 09:01:53 -0500138 void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
139
Greg Daniel26b50a42018-03-08 09:49:58 -0500140 void testingOnly_flushGpuAndSync() override {}
Brian Salomonf865b052018-03-09 09:01:53 -0500141#endif
Greg Daniel26b50a42018-03-08 09:49:58 -0500142
Chris Dalton91ab1552018-04-18 13:24:25 -0600143 const GrMockOptions fMockOptions;
144
Brian Salomon8fe24272017-07-07 12:56:11 -0400145 static int NextInternalTextureID();
146 static int NextExternalTextureID();
Brian Salomon0c51eea2018-03-09 17:02:09 -0500147 static int NextInternalRenderTargetID();
148 static int NextExternalRenderTargetID();
Brian Salomon8fe24272017-07-07 12:56:11 -0400149
150 SkTHashSet<int> fOutstandingTestingOnlyTextureIDs;
Brian Salomon91a3e522017-06-23 10:58:19 -0400151
152 typedef GrGpu INHERITED;
153};
Brian Salomoncfe910d2017-07-06 16:40:18 -0400154
155#endif