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/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 Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 16 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 17 | class GrMockGpuRTCommandBuffer; |
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: |
Brian Salomon | 384fab4 | 2017-12-07 12:33:05 -0500 | [diff] [blame] | 23 | static sk_sp<GrGpu> Make(const GrMockOptions*, const GrContextOptions&, GrContext*); |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 24 | |
| 25 | ~GrMockGpu() override {} |
| 26 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 27 | GrGpuRTCommandBuffer* getCommandBuffer( |
Ethan Nicholas | 56d19a5 | 2018-10-15 11:26:20 -0400 | [diff] [blame] | 28 | GrRenderTarget*, GrSurfaceOrigin, const SkRect&, |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 29 | const GrGpuRTCommandBuffer::LoadAndStoreInfo&, |
| 30 | const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) override; |
| 31 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 32 | GrGpuTextureCommandBuffer* getCommandBuffer(GrTexture*, GrSurfaceOrigin) override; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 33 | |
| 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 Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 41 | sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore, |
| 42 | GrResourceProvider::SemaphoreWrapType wrapType, |
| 43 | GrWrapOwnership ownership) override { return nullptr; } |
Greg Daniel | 858e12c | 2018-12-06 11:11:37 -0500 | [diff] [blame] | 44 | void insertSemaphore(sk_sp<GrSemaphore> semaphore) override {} |
Greg Daniel | 48661b8 | 2018-01-22 16:11:35 -0500 | [diff] [blame] | 45 | void waitSemaphore(sk_sp<GrSemaphore> semaphore) override {} |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 46 | sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override { return nullptr; } |
| 47 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 48 | void submit(GrGpuCommandBuffer* buffer) override; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 49 | |
Brian Salomon | b0d8b76 | 2019-05-06 16:58:22 -0400 | [diff] [blame] | 50 | void checkFinishProcs() override {} |
| 51 | |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 52 | private: |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 53 | GrMockGpu(GrContext* context, const GrMockOptions&, const GrContextOptions&); |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 54 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 55 | void submitCommandBuffer(const GrMockGpuRTCommandBuffer*); |
| 56 | |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 57 | void onResetContext(uint32_t resetBits) override {} |
| 58 | |
Chris Dalton | c3318f0 | 2019-07-19 14:20:53 -0600 | [diff] [blame] | 59 | void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>* sampleLocations) override; |
Chris Dalton | d7291ba | 2019-03-07 14:17:03 -0700 | [diff] [blame] | 60 | |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 61 | void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {} |
| 62 | |
Brian Salomon | 27b4d8d | 2019-07-22 14:23:45 -0400 | [diff] [blame] | 63 | sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc&, GrRenderable, int renderTargetSampleCnt, |
| 64 | SkBudgeted, GrProtected, const GrMipLevel[], |
| 65 | int mipLevelCount) override; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 66 | |
Brian Salomon | bb8dde8 | 2019-06-27 10:52:13 -0400 | [diff] [blame] | 67 | sk_sp<GrTexture> onCreateCompressedTexture(int width, int height, SkImage::CompressionType, |
| 68 | SkBudgeted, const void* data) override; |
| 69 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 70 | sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrColorType, GrWrapOwnership, |
| 71 | GrWrapCacheable, GrIOType) override; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 72 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 73 | sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 74 | int sampleCnt, |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 75 | GrColorType, |
Brian Salomon | aa6ca0a | 2019-01-24 16:03:07 -0500 | [diff] [blame] | 76 | GrWrapOwnership, |
| 77 | GrWrapCacheable) override; |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 78 | |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 79 | sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&, |
| 80 | GrColorType) override; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 81 | |
| 82 | sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 83 | int sampleCnt, GrColorType) override; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 84 | |
Brian Salomon | dbf7072 | 2019-02-07 11:31:24 -0500 | [diff] [blame] | 85 | sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes, GrGpuBufferType, GrAccessPattern, |
| 86 | const void*) override; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 87 | |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame^] | 88 | 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 Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 91 | return true; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 92 | } |
| 93 | |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame^] | 94 | bool onWritePixels(GrSurface* surface, int left, int top, int width, int height, |
| 95 | GrColorType surfaceColorType, GrColorType srcColorType, |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame] | 96 | const GrMipLevel texels[], int mipLevelCount) override { |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 97 | return true; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 98 | } |
| 99 | |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 100 | bool onTransferPixelsTo(GrTexture* texture, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame^] | 101 | GrColorType surfaceColorType, GrColorType bufferColorType, |
| 102 | GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override { |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 103 | return true; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 104 | } |
Brian Salomon | 26de56e | 2019-04-10 12:14:26 -0400 | [diff] [blame] | 105 | bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height, |
Brian Salomon | f77c146 | 2019-08-01 15:19:29 -0400 | [diff] [blame^] | 106 | GrColorType surfaceColorType, GrColorType bufferColorType, |
| 107 | GrGpuBuffer* transferBuffer, size_t offset) override { |
Brian Salomon | e05ba5a | 2019-04-08 11:59:07 -0400 | [diff] [blame] | 108 | return true; |
| 109 | } |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 110 | bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
Greg Daniel | 55fa647 | 2018-03-16 16:13:10 -0400 | [diff] [blame] | 111 | const SkIPoint& dstPoint, bool canDiscardOutsideDstRect) override { |
Brian Salomon | 9b009bb | 2018-02-14 13:53:55 -0500 | [diff] [blame] | 112 | return true; |
| 113 | } |
| 114 | |
Brian Salomon | 930f939 | 2018-06-20 16:25:26 -0400 | [diff] [blame] | 115 | bool onRegenerateMipMapLevels(GrTexture*) override { return true; } |
| 116 | |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 117 | void onResolveRenderTarget(GrRenderTarget* target) override { return; } |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 118 | |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 119 | void onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfaceAccess access, |
Greg Daniel | 797efca | 2019-05-09 14:04:20 -0400 | [diff] [blame] | 120 | const GrFlushInfo& info, const GrPrepareForExternalIORequests&) override { |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 121 | if (info.fFinishedProc) { |
| 122 | info.fFinishedProc(info.fFinishedContext); |
Greg Daniel | a3aa75a | 2019-04-12 14:24:55 -0400 | [diff] [blame] | 123 | } |
| 124 | } |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 125 | |
Chris Dalton | effee20 | 2019-07-01 22:28:03 -0600 | [diff] [blame] | 126 | GrStencilAttachment* createStencilAttachmentForRenderTarget( |
| 127 | const GrRenderTarget*, int width, int height, int numStencilSamples) override; |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 128 | GrBackendTexture createBackendTexture(int w, int h, const GrBackendFormat&, |
| 129 | GrMipMapped, GrRenderable, |
Robert Phillips | 459b295 | 2019-05-23 09:38:27 -0400 | [diff] [blame] | 130 | const void* pixels, size_t rowBytes, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 131 | const SkColor4f* color, GrProtected isProtected) override; |
Robert Phillips | f0313ee | 2019-05-21 13:51:11 -0400 | [diff] [blame] | 132 | void deleteBackendTexture(const GrBackendTexture&) override; |
Robert Phillips | 50a4e6e | 2019-05-15 12:31:15 -0400 | [diff] [blame] | 133 | |
Robert Phillips | f0ced62 | 2019-05-16 09:06:25 -0400 | [diff] [blame] | 134 | #if GR_TEST_UTILS |
| 135 | bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; |
| 136 | |
Brian Osman | 2d010b6 | 2018-08-09 10:55:09 -0400 | [diff] [blame] | 137 | GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override; |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 138 | void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override; |
| 139 | |
Greg Daniel | 26b50a4 | 2018-03-08 09:49:58 -0500 | [diff] [blame] | 140 | void testingOnly_flushGpuAndSync() override {} |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 141 | #endif |
Greg Daniel | 26b50a4 | 2018-03-08 09:49:58 -0500 | [diff] [blame] | 142 | |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 143 | const GrMockOptions fMockOptions; |
| 144 | |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 145 | static int NextInternalTextureID(); |
| 146 | static int NextExternalTextureID(); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 147 | static int NextInternalRenderTargetID(); |
| 148 | static int NextExternalRenderTargetID(); |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 149 | |
| 150 | SkTHashSet<int> fOutstandingTestingOnlyTextureIDs; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 151 | |
| 152 | typedef GrGpu INHERITED; |
| 153 | }; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 154 | |
| 155 | #endif |