blob: 56c40ae3717aa94661aece15a80ec36053c0280e [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; }
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 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
Chris Daltond7291ba2019-03-07 14:17:03 -070057 void querySampleLocations(
58 GrRenderTarget*, const GrStencilSettings&, SkTArray<SkPoint>*) override {
59 SkASSERT(!this->caps()->sampleLocationsSupport());
60 SK_ABORT("Sample locations not implemented for mock GPU.");
61 }
62
Brian Salomon91a3e522017-06-23 10:58:19 -040063 void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
64
Brian Salomon58389b92018-03-07 13:01:25 -050065 sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc&, SkBudgeted, const GrMipLevel[],
66 int mipLevelCount) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040067
Brian Salomonfa2ebea2019-01-24 15:58:58 -050068 sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
69 GrIOType) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040070
Brian Salomond17f6582017-07-19 18:28:58 -040071 sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
Brian Salomond17f6582017-07-19 18:28:58 -040072 int sampleCnt,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050073 GrWrapOwnership,
74 GrWrapCacheable) override;
Brian Salomond17f6582017-07-19 18:28:58 -040075
Brian Salomon0c51eea2018-03-09 17:02:09 -050076 sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040077
78 sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
Brian Salomon0c51eea2018-03-09 17:02:09 -050079 int sampleCnt) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040080
Brian Salomondbf70722019-02-07 11:31:24 -050081 sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes, GrGpuBufferType, GrAccessPattern,
82 const void*) override;
Brian Salomon91a3e522017-06-23 10:58:19 -040083
Brian Salomona6948702018-06-01 15:33:20 -040084 bool onReadPixels(GrSurface* surface, int left, int top, int width, int height, GrColorType,
85 void* buffer, size_t rowBytes) override {
Brian Salomoncfe910d2017-07-06 16:40:18 -040086 return true;
Brian Salomon91a3e522017-06-23 10:58:19 -040087 }
88
Brian Salomona9b04b92018-06-01 15:04:28 -040089 bool onWritePixels(GrSurface* surface, int left, int top, int width, int height, GrColorType,
90 const GrMipLevel texels[], int mipLevelCount) override {
Brian Salomoncfe910d2017-07-06 16:40:18 -040091 return true;
Brian Salomon91a3e522017-06-23 10:58:19 -040092 }
93
Brian Salomone05ba5a2019-04-08 11:59:07 -040094 bool onTransferPixelsTo(GrTexture* texture, int left, int top, int width, int height,
95 GrColorType, GrGpuBuffer* transferBuffer, size_t offset,
96 size_t rowBytes) override {
Brian Salomoncfe910d2017-07-06 16:40:18 -040097 return true;
Brian Salomon91a3e522017-06-23 10:58:19 -040098 }
Brian Salomone05ba5a2019-04-08 11:59:07 -040099 size_t onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
100 GrColorType, GrGpuBuffer* transferBuffer, size_t offset) override {
101 return true;
102 }
Brian Salomon9b009bb2018-02-14 13:53:55 -0500103 bool onCopySurface(GrSurface* dst, GrSurfaceOrigin dstOrigin, GrSurface* src,
104 GrSurfaceOrigin srcOrigin, const SkIRect& srcRect,
Greg Daniel55fa6472018-03-16 16:13:10 -0400105 const SkIPoint& dstPoint, bool canDiscardOutsideDstRect) override {
Brian Salomon9b009bb2018-02-14 13:53:55 -0500106 return true;
107 }
108
Brian Salomon930f9392018-06-20 16:25:26 -0400109 bool onRegenerateMipMapLevels(GrTexture*) override { return true; }
110
Brian Salomon1fabd512018-02-09 09:54:25 -0500111 void onResolveRenderTarget(GrRenderTarget* target) override { return; }
Brian Salomon91a3e522017-06-23 10:58:19 -0400112
Greg Danielbae71212019-03-01 15:24:35 -0500113 void onFinishFlush(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess access,
Greg Danielb9990e42019-04-10 16:28:52 -0400114 GrFlushFlags flags, bool insertedSemaphores) override {}
Greg Daniel51316782017-08-02 15:10:09 +0000115
Brian Salomon91a3e522017-06-23 10:58:19 -0400116 GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*,
117 int width,
Brian Salomoncfe910d2017-07-06 16:40:18 -0400118 int height) override;
Brian Salomonf865b052018-03-09 09:01:53 -0500119#if GR_TEST_UTILS
Brian Salomon52e943a2018-03-13 09:32:39 -0400120 GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h,
Robert Phillips646f6372018-09-25 09:31:10 -0400121 GrColorType, bool isRT,
122 GrMipMapped, size_t rowBytes = 0) override;
Robert Phillipsd21b2a52017-12-12 13:01:25 -0500123 bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
Brian Salomon26102cb2018-03-09 09:33:19 -0500124 void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override;
Brian Salomon8fe24272017-07-07 12:56:11 -0400125
Brian Osman2d010b62018-08-09 10:55:09 -0400126 GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override;
Brian Salomonf865b052018-03-09 09:01:53 -0500127 void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
128
Greg Daniel26b50a42018-03-08 09:49:58 -0500129 void testingOnly_flushGpuAndSync() override {}
Brian Salomonf865b052018-03-09 09:01:53 -0500130#endif
Greg Daniel26b50a42018-03-08 09:49:58 -0500131
Chris Dalton91ab1552018-04-18 13:24:25 -0600132 const GrMockOptions fMockOptions;
133
Brian Salomon8fe24272017-07-07 12:56:11 -0400134 static int NextInternalTextureID();
135 static int NextExternalTextureID();
Brian Salomon0c51eea2018-03-09 17:02:09 -0500136 static int NextInternalRenderTargetID();
137 static int NextExternalRenderTargetID();
Brian Salomon8fe24272017-07-07 12:56:11 -0400138
139 SkTHashSet<int> fOutstandingTestingOnlyTextureIDs;
Brian Salomon91a3e522017-06-23 10:58:19 -0400140
141 typedef GrGpu INHERITED;
142};
Brian Salomoncfe910d2017-07-06 16:40:18 -0400143
144#endif