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 | */ |
7 | |
8 | #ifndef GrMockGpu_DEFINED |
9 | #define GrMockGpu_DEFINED |
10 | |
11 | #include "include/private/SkTHash.h" |
12 | #include "src/gpu/GrGpu.h" |
13 | #include "src/gpu/GrRenderTarget.h" |
14 | #include "src/gpu/GrSemaphore.h" |
15 | #include "src/gpu/GrTexture.h" |
16 | |
17 | class GrMockOpsRenderPass; |
18 | struct GrMockOptions; |
19 | class GrPipeline; |
20 | |
21 | class GrMockGpu : public GrGpu { |
22 | public: |
23 | static sk_sp<GrGpu> Make(const GrMockOptions*, const GrContextOptions&, GrContext*); |
24 | |
25 | ~GrMockGpu() override {} |
26 | |
27 | GrOpsRenderPass* getOpsRenderPass( |
28 | GrRenderTarget*, GrSurfaceOrigin, const SkIRect&, |
29 | const GrOpsRenderPass::LoadAndStoreInfo&, |
30 | const GrOpsRenderPass::StencilLoadAndStoreInfo&, |
31 | const SkTArray<GrSurfaceProxy*, true>& sampledProxies) override; |
32 | |
33 | GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; } |
34 | bool waitFence(GrFence, uint64_t) override { return true; } |
35 | void deleteFence(GrFence) const override {} |
36 | |
37 | std::unique_ptr<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override { |
38 | return nullptr; |
39 | } |
40 | std::unique_ptr<GrSemaphore> wrapBackendSemaphore( |
41 | const GrBackendSemaphore& semaphore, |
42 | GrResourceProvider::SemaphoreWrapType wrapType, |
43 | GrWrapOwnership ownership) override { |
44 | return nullptr; |
45 | } |
46 | void insertSemaphore(GrSemaphore* semaphore) override {} |
47 | void waitSemaphore(GrSemaphore* semaphore) override {} |
48 | std::unique_ptr<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override { |
49 | return nullptr; |
50 | } |
51 | |
52 | void submit(GrOpsRenderPass* renderPass) override; |
53 | |
54 | void checkFinishProcs() override {} |
55 | |
56 | private: |
57 | GrMockGpu(GrContext* context, const GrMockOptions&, const GrContextOptions&); |
58 | |
59 | void onResetContext(uint32_t resetBits) override {} |
60 | |
61 | void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>* sampleLocations) override; |
62 | |
63 | void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {} |
64 | |
65 | sk_sp<GrTexture> onCreateTexture(SkISize, |
66 | const GrBackendFormat&, |
67 | GrRenderable, |
68 | int renderTargetSampleCnt, |
69 | SkBudgeted, |
70 | GrProtected, |
71 | int mipLevelCount, |
72 | uint32_t levelClearMask) override; |
73 | |
74 | sk_sp<GrTexture> onCreateCompressedTexture(SkISize dimensions, |
75 | const GrBackendFormat&, |
76 | SkBudgeted, |
77 | GrMipMapped, |
78 | GrProtected, |
79 | const void* data, size_t dataSize) override; |
80 | |
81 | sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, |
82 | GrWrapOwnership, |
83 | GrWrapCacheable, |
84 | GrIOType) override; |
85 | sk_sp<GrTexture> onWrapCompressedBackendTexture(const GrBackendTexture&, |
86 | GrWrapOwnership, |
87 | GrWrapCacheable) override; |
88 | |
89 | sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, |
90 | int sampleCnt, |
91 | GrWrapOwnership, |
92 | GrWrapCacheable) override; |
93 | |
94 | sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override; |
95 | |
96 | sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, |
97 | int sampleCnt) override; |
98 | |
99 | sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes, GrGpuBufferType, GrAccessPattern, |
100 | const void*) override; |
101 | |
102 | bool onReadPixels(GrSurface* surface, int left, int top, int width, int height, |
103 | GrColorType surfaceColorType, GrColorType dstColorType, void* buffer, |
104 | size_t rowBytes) override { |
105 | return true; |
106 | } |
107 | |
108 | bool onWritePixels(GrSurface* surface, int left, int top, int width, int height, |
109 | GrColorType surfaceColorType, GrColorType srcColorType, |
110 | const GrMipLevel texels[], int mipLevelCount, |
111 | bool prepForTexSampling) override { |
112 | return true; |
113 | } |
114 | |
115 | bool onTransferPixelsTo(GrTexture* texture, int left, int top, int width, int height, |
116 | GrColorType surfaceColorType, GrColorType bufferColorType, |
117 | GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override { |
118 | return true; |
119 | } |
120 | bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height, |
121 | GrColorType surfaceColorType, GrColorType bufferColorType, |
122 | GrGpuBuffer* transferBuffer, size_t offset) override { |
123 | return true; |
124 | } |
125 | bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
126 | const SkIPoint& dstPoint) override { |
127 | return true; |
128 | } |
129 | |
130 | bool onRegenerateMipMapLevels(GrTexture*) override { return true; } |
131 | |
132 | void onResolveRenderTarget(GrRenderTarget* target, const SkIRect&, ForExternalIO) override {} |
133 | |
134 | void addFinishedProc(GrGpuFinishedProc finishedProc, |
135 | GrGpuFinishedContext finishedContext) override { |
136 | SkASSERT(finishedProc); |
137 | finishedProc(finishedContext); |
138 | } |
139 | |
140 | bool onSubmitToGpu(bool syncCpu) override { |
141 | return true; |
142 | } |
143 | |
144 | GrStencilAttachment* createStencilAttachmentForRenderTarget( |
145 | const GrRenderTarget*, int width, int height, int numStencilSamples) override; |
146 | GrBackendTexture onCreateBackendTexture(SkISize dimensions, |
147 | const GrBackendFormat&, |
148 | GrRenderable, |
149 | GrMipMapped, |
150 | GrProtected, |
151 | const BackendTextureData*) override; |
152 | GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions, |
153 | const GrBackendFormat&, |
154 | GrMipMapped, |
155 | GrProtected, |
156 | const BackendTextureData*) override; |
157 | void deleteBackendTexture(const GrBackendTexture&) override; |
158 | |
159 | bool compile(const GrProgramDesc&, const GrProgramInfo&) override { return false; } |
160 | |
161 | #if GR_TEST_UTILS |
162 | bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; |
163 | |
164 | GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override; |
165 | void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override; |
166 | |
167 | void testingOnly_flushGpuAndSync() override {} |
168 | #endif |
169 | |
170 | const GrMockOptions fMockOptions; |
171 | |
172 | static int NextInternalTextureID(); |
173 | static int NextExternalTextureID(); |
174 | static int NextInternalRenderTargetID(); |
175 | static int NextExternalRenderTargetID(); |
176 | |
177 | SkTHashSet<int> fOutstandingTestingOnlyTextureIDs; |
178 | |
179 | typedef GrGpu INHERITED; |
180 | }; |
181 | |
182 | #endif |
183 | |