Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 1 | /* |
| 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 Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 7 | |
Hal Canary | 466c7d6 | 2017-07-03 15:11:49 -0400 | [diff] [blame] | 8 | #ifndef GrMockGpu_DEFINED |
| 9 | #define GrMockGpu_DEFINED |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/private/SkTHash.h" |
| 12 | #include "src/gpu/GrGpu.h" |
Brian Salomon | 201cdbb | 2019-08-14 17:00:30 -0400 | [diff] [blame] | 13 | #include "src/gpu/GrRenderTarget.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "src/gpu/GrSemaphore.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 15 | #include "src/gpu/GrTexture.h" |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 16 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 17 | class GrMockOpsRenderPass; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 18 | struct GrMockOptions; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 19 | class GrPipeline; |
| 20 | |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 21 | class GrMockGpu : public GrGpu { |
| 22 | public: |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 23 | static sk_sp<GrGpu> Make(const GrMockOptions*, const GrContextOptions&, GrDirectContext*); |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 24 | |
| 25 | ~GrMockGpu() override {} |
| 26 | |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 27 | GrOpsRenderPass* getOpsRenderPass( |
Robert Phillips | 96f2237 | 2020-05-20 12:31:18 -0400 | [diff] [blame] | 28 | GrRenderTarget*, |
| 29 | GrStencilAttachment*, |
| 30 | GrSurfaceOrigin, |
| 31 | const SkIRect&, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 32 | const GrOpsRenderPass::LoadAndStoreInfo&, |
| 33 | const GrOpsRenderPass::StencilLoadAndStoreInfo&, |
Greg Daniel | 9a18b08 | 2020-08-14 14:03:50 -0400 | [diff] [blame] | 34 | const SkTArray<GrSurfaceProxy*, true>& sampledProxies, |
| 35 | bool usesXferBarriers) override; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 36 | |
| 37 | GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; } |
Stephen White | b353c9b | 2020-04-16 14:14:13 -0400 | [diff] [blame] | 38 | bool waitFence(GrFence) override { return true; } |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 39 | void deleteFence(GrFence) const override {} |
| 40 | |
Greg Daniel | 301015c | 2019-11-18 14:06:46 -0500 | [diff] [blame] | 41 | std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override { |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 42 | return nullptr; |
| 43 | } |
Greg Daniel | 301015c | 2019-11-18 14:06:46 -0500 | [diff] [blame] | 44 | 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 Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 55 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 56 | void submit(GrOpsRenderPass* renderPass) override; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 57 | |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 58 | void checkFinishProcs() override {} |
| 59 | |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 60 | private: |
Adlai Holler | 3d0359a | 2020-07-09 15:35:55 -0400 | [diff] [blame] | 61 | GrMockGpu(GrDirectContext*, const GrMockOptions&, const GrContextOptions&); |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 62 | |
| 63 | void onResetContext(uint32_t resetBits) override {} |
| 64 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 65 | void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>* sampleLocations) override; |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 66 | |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 67 | void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {} |
| 68 | |
Brian Salomon | a56a746 | 2020-02-07 14:17:25 -0500 | [diff] [blame] | 69 | sk_sp<GrTexture> onCreateTexture(SkISize, |
Brian Salomon | 81536f2 | 2019-08-08 16:30:49 -0400 | [diff] [blame] | 70 | const GrBackendFormat&, |
| 71 | GrRenderable, |
| 72 | int renderTargetSampleCnt, |
| 73 | SkBudgeted, |
| 74 | GrProtected, |
Brian Salomon | d2a8ae2 | 2019-09-10 16:03:59 -0400 | [diff] [blame] | 75 | int mipLevelCount, |
| 76 | uint32_t levelClearMask) override; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 77 | |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 78 | sk_sp<GrTexture> onCreateCompressedTexture(SkISize dimensions, |
| 79 | const GrBackendFormat&, |
| 80 | SkBudgeted, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 81 | GrMipmapped, |
Robert Phillips | 3a83392 | 2020-01-21 15:25:58 -0500 | [diff] [blame] | 82 | GrProtected, |
| 83 | const void* data, size_t dataSize) override; |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 84 | |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 85 | sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, |
| 86 | GrWrapOwnership, |
| 87 | GrWrapCacheable, |
| 88 | GrIOType) override; |
| 89 | sk_sp<GrTexture> onWrapCompressedBackendTexture(const GrBackendTexture&, |
| 90 | GrWrapOwnership, |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 91 | GrWrapCacheable) override; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 92 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 93 | sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 94 | int sampleCnt, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 95 | GrWrapOwnership, |
| 96 | GrWrapCacheable) override; |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 97 | |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 98 | sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 99 | |
| 100 | sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, |
Brian Salomon | 8a78e9c | 2020-03-27 10:42:15 -0400 | [diff] [blame] | 101 | int sampleCnt) override; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 102 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 103 | sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes, GrGpuBufferType, GrAccessPattern, |
| 104 | const void*) override; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 105 | |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 106 | 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 Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 109 | return true; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 110 | } |
| 111 | |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 112 | bool onWritePixels(GrSurface* surface, int left, int top, int width, int height, |
| 113 | GrColorType surfaceColorType, GrColorType srcColorType, |
Greg Daniel | b20d7e5 | 2019-09-03 13:54:39 -0400 | [diff] [blame] | 114 | const GrMipLevel texels[], int mipLevelCount, |
| 115 | bool prepForTexSampling) override { |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 116 | return true; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 119 | bool onTransferPixelsTo(GrTexture* texture, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 120 | GrColorType surfaceColorType, GrColorType bufferColorType, |
| 121 | GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override { |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 122 | return true; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 123 | } |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 124 | bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame] | 125 | GrColorType surfaceColorType, GrColorType bufferColorType, |
| 126 | GrGpuBuffer* transferBuffer, size_t offset) override { |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 127 | return true; |
| 128 | } |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 129 | bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 130 | const SkIPoint& dstPoint) override { |
Brian Salomon | 9b009bb | 2018-02-14 13:53:55 -0500 | [diff] [blame] | 131 | return true; |
| 132 | } |
| 133 | |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 134 | bool onRegenerateMipMapLevels(GrTexture*) override { return true; } |
| 135 | |
Jim Van Verth | bb61fe3 | 2020-07-07 16:39:04 -0400 | [diff] [blame] | 136 | void onResolveRenderTarget(GrRenderTarget* target, const SkIRect&) override {} |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 137 | |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 138 | void addFinishedProc(GrGpuFinishedProc finishedProc, |
| 139 | GrGpuFinishedContext finishedContext) override { |
| 140 | SkASSERT(finishedProc); |
| 141 | finishedProc(finishedContext); |
| 142 | } |
| 143 | |
| 144 | bool onSubmitToGpu(bool syncCpu) override { |
Greg Daniel | 30a35e8 | 2019-11-19 14:12:25 -0500 | [diff] [blame] | 145 | return true; |
Greg Daniel | a3aa75a | 2019-04-12 14:24:55 -0400 | [diff] [blame] | 146 | } |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 147 | |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 148 | GrStencilAttachment* createStencilAttachmentForRenderTarget( |
| 149 | const GrRenderTarget*, int width, int height, int numStencilSamples) override; |
Robert Phillips | 4277f01 | 2020-01-21 14:28:34 -0500 | [diff] [blame] | 150 | GrBackendTexture onCreateBackendTexture(SkISize dimensions, |
Brian Salomon | 85c3d68 | 2019-11-04 15:04:54 -0500 | [diff] [blame] | 151 | const GrBackendFormat&, |
| 152 | GrRenderable, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 153 | GrMipmapped, |
Greg Daniel | 16032b3 | 2020-05-06 15:31:10 -0400 | [diff] [blame] | 154 | GrProtected) override; |
| 155 | |
| 156 | bool onUpdateBackendTexture(const GrBackendTexture&, |
| 157 | sk_sp<GrRefCntedCallback> finishedCallback, |
| 158 | const BackendTextureData*) override { |
| 159 | return true; |
| 160 | } |
| 161 | |
Robert Phillips | b915c94 | 2019-12-17 14:44:37 -0500 | [diff] [blame] | 162 | GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions, |
| 163 | const GrBackendFormat&, |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 164 | GrMipmapped, |
Greg Daniel | aaf738c | 2020-07-10 09:30:33 -0400 | [diff] [blame] | 165 | GrProtected) override; |
| 166 | |
| 167 | bool onUpdateCompressedBackendTexture(const GrBackendTexture&, |
| 168 | sk_sp<GrRefCntedCallback> finishedCallback, |
| 169 | const BackendTextureData*) override { |
| 170 | return true; |
| 171 | } |
| 172 | |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 173 | void deleteBackendTexture(const GrBackendTexture&) override; |
Robert Phillips | 50a4e6e | 2019-05-15 12:31:15 -0400 | [diff] [blame] | 174 | |
Robert Phillips | 979b223 | 2020-02-20 10:47:29 -0500 | [diff] [blame] | 175 | bool compile(const GrProgramDesc&, const GrProgramInfo&) override { return false; } |
| 176 | |
Robert Phillips | f0ced62 | 2019-05-16 09:06:25 -0400 | [diff] [blame] | 177 | #if GR_TEST_UTILS |
| 178 | bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; |
| 179 | |
Brian Osman | 2d010b6 | 2018-08-09 10:55:09 -0400 | [diff] [blame] | 180 | GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override; |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 181 | void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override; |
| 182 | |
Greg Daniel | 26b50a4 | 2018-03-08 09:49:58 -0500 | [diff] [blame] | 183 | void testingOnly_flushGpuAndSync() override {} |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 184 | #endif |
Greg Daniel | 26b50a4 | 2018-03-08 09:49:58 -0500 | [diff] [blame] | 185 | |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 186 | const GrMockOptions fMockOptions; |
| 187 | |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 188 | static int NextInternalTextureID(); |
| 189 | static int NextExternalTextureID(); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 190 | static int NextInternalRenderTargetID(); |
| 191 | static int NextExternalRenderTargetID(); |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 192 | |
| 193 | SkTHashSet<int> fOutstandingTestingOnlyTextureIDs; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 194 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame^] | 195 | using INHERITED = GrGpu; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 196 | }; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 197 | |
| 198 | #endif |