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 | |
| 11 | #include "GrGpu.h" |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 12 | #include "GrRenderTarget.h" |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 13 | #include "GrSemaphore.h" |
Hal Canary | 466c7d6 | 2017-07-03 15:11:49 -0400 | [diff] [blame] | 14 | #include "GrTexture.h" |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 15 | #include "SkTHash.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 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 27 | GrGpuRTCommandBuffer* createCommandBuffer( |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 28 | GrRenderTarget*, GrSurfaceOrigin, |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 29 | const GrGpuRTCommandBuffer::LoadAndStoreInfo&, |
| 30 | const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) override; |
| 31 | |
| 32 | GrGpuTextureCommandBuffer* createCommandBuffer(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; } |
| 44 | void insertSemaphore(sk_sp<GrSemaphore> semaphore, bool flush) override {} |
| 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 | |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 48 | void submitCommandBuffer(const GrMockGpuRTCommandBuffer*); |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 49 | |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 50 | private: |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 51 | GrMockGpu(GrContext* context, const GrMockOptions&, const GrContextOptions&); |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 52 | |
| 53 | void onResetContext(uint32_t resetBits) override {} |
| 54 | |
| 55 | void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {} |
| 56 | |
Brian Salomon | 58389b9 | 2018-03-07 13:01:25 -0500 | [diff] [blame] | 57 | sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc&, SkBudgeted, const GrMipLevel[], |
| 58 | int mipLevelCount) override; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 59 | |
Greg Daniel | 4684f82 | 2018-03-08 15:27:36 -0500 | [diff] [blame] | 60 | sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership) override; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 61 | |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 62 | sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 63 | int sampleCnt, |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 64 | GrWrapOwnership) override; |
Brian Salomon | d17f658 | 2017-07-19 18:28:58 -0400 | [diff] [blame] | 65 | |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 66 | sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 67 | |
| 68 | sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 69 | int sampleCnt) override; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 70 | |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 71 | GrBuffer* onCreateBuffer(size_t sizeInBytes, GrBufferType, GrAccessPattern, |
| 72 | const void*) override; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 73 | |
Brian Salomon | c320b15 | 2018-02-20 14:05:36 -0500 | [diff] [blame] | 74 | bool onReadPixels(GrSurface* surface, GrSurfaceOrigin, int left, int top, int width, int height, |
| 75 | GrColorType, void* buffer, size_t rowBytes) override { |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 76 | return true; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 77 | } |
| 78 | |
Brian Salomon | a9b04b9 | 2018-06-01 15:04:28 -0400 | [diff] [blame^] | 79 | bool onWritePixels(GrSurface* surface, int left, int top, int width, int height, GrColorType, |
| 80 | const GrMipLevel texels[], int mipLevelCount) override { |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 81 | return true; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 82 | } |
| 83 | |
Brian Salomon | c320b15 | 2018-02-20 14:05:36 -0500 | [diff] [blame] | 84 | bool onTransferPixels(GrTexture* texture, int left, int top, int width, int height, GrColorType, |
| 85 | GrBuffer* transferBuffer, size_t offset, size_t rowBytes) override { |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 86 | return true; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 87 | } |
| 88 | |
Brian Salomon | 9b009bb | 2018-02-14 13:53:55 -0500 | [diff] [blame] | 89 | bool onCopySurface(GrSurface* dst, GrSurfaceOrigin dstOrigin, GrSurface* src, |
| 90 | GrSurfaceOrigin srcOrigin, const SkIRect& srcRect, |
Greg Daniel | 55fa647 | 2018-03-16 16:13:10 -0400 | [diff] [blame] | 91 | const SkIPoint& dstPoint, bool canDiscardOutsideDstRect) override { |
Brian Salomon | 9b009bb | 2018-02-14 13:53:55 -0500 | [diff] [blame] | 92 | return true; |
| 93 | } |
| 94 | |
Brian Salomon | 1fabd51 | 2018-02-09 09:54:25 -0500 | [diff] [blame] | 95 | void onResolveRenderTarget(GrRenderTarget* target) override { return; } |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 96 | |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 97 | void onFinishFlush(bool insertedSemaphores) override {} |
| 98 | |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 99 | GrStencilAttachment* createStencilAttachmentForRenderTarget(const GrRenderTarget*, |
| 100 | int width, |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 101 | int height) override; |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 102 | void clearStencil(GrRenderTarget*, int clearValue) override {} |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 103 | |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 104 | #if GR_TEST_UTILS |
Brian Salomon | 52e943a | 2018-03-13 09:32:39 -0400 | [diff] [blame] | 105 | GrBackendTexture createTestingOnlyBackendTexture(const void* pixels, int w, int h, |
| 106 | GrPixelConfig, bool isRT, |
| 107 | GrMipMapped) override; |
Robert Phillips | d21b2a5 | 2017-12-12 13:01:25 -0500 | [diff] [blame] | 108 | bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; |
Brian Salomon | 26102cb | 2018-03-09 09:33:19 -0500 | [diff] [blame] | 109 | void deleteTestingOnlyBackendTexture(const GrBackendTexture&) override; |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 110 | |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 111 | GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType, |
| 112 | GrSRGBEncoded) override; |
| 113 | void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override; |
| 114 | |
Greg Daniel | 26b50a4 | 2018-03-08 09:49:58 -0500 | [diff] [blame] | 115 | void testingOnly_flushGpuAndSync() override {} |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 116 | #endif |
Greg Daniel | 26b50a4 | 2018-03-08 09:49:58 -0500 | [diff] [blame] | 117 | |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 118 | const GrMockOptions fMockOptions; |
| 119 | |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 120 | static int NextInternalTextureID(); |
| 121 | static int NextExternalTextureID(); |
Brian Salomon | 0c51eea | 2018-03-09 17:02:09 -0500 | [diff] [blame] | 122 | static int NextInternalRenderTargetID(); |
| 123 | static int NextExternalRenderTargetID(); |
Brian Salomon | 8fe2427 | 2017-07-07 12:56:11 -0400 | [diff] [blame] | 124 | |
| 125 | SkTHashSet<int> fOutstandingTestingOnlyTextureIDs; |
Brian Salomon | 91a3e52 | 2017-06-23 10:58:19 -0400 | [diff] [blame] | 126 | |
| 127 | typedef GrGpu INHERITED; |
| 128 | }; |
Brian Salomon | cfe910d | 2017-07-06 16:40:18 -0400 | [diff] [blame] | 129 | |
| 130 | #endif |