| 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/core/SkRect.h" |
| 12 |
#include "include/core/SkRefCnt.h" |
| 13 |
#include "include/core/SkSize.h" |
| 14 |
#include "include/core/SkTextureCompressionType.h" |
| 15 |
#include "include/gpu/ganesh/GrBackendSurface.h" |
| 16 |
#include "include/gpu/ganesh/GrTypes.h" |
| 17 |
#include "include/gpu/ganesh/mock/GrMockTypes.h" |
| 18 |
#include "include/private/base/SkAssert.h" |
| 19 |
#include "include/private/base/SkTArray.h" |
| 20 |
#include "include/private/gpu/ganesh/GrTypesPriv.h" |
| 21 |
#include "src/core/SkTHash.h" |
| 22 |
#include "src/gpu/RefCntedCallback.h" |
| 23 |
#include "src/gpu/ganesh/GrAttachment.h" |
| 24 |
#include "src/gpu/ganesh/GrGpu.h" |
| 25 |
#include "src/gpu/ganesh/GrOpsRenderPass.h" |
| 26 |
#include "src/gpu/ganesh/GrSamplerState.h" |
| 27 |
#include "src/gpu/ganesh/GrSemaphore.h" // IWYU pragma: keep |
| 28 |
#include "src/gpu/ganesh/GrXferProcessor.h" |
| 29 |
|
| 30 |
#include <array> |
| 31 |
#include <cstddef> |
| 32 |
#include <cstdint> |
| 33 |
#include <memory> |
| 34 |
#include <optional> |
| 35 |
#include <string_view> |
| 36 |
|
| 37 |
class GrBackendSemaphore; |
| 38 |
class GrDirectContext; |
| 39 |
class GrGpuBuffer; |
| 40 |
class GrProgramDesc; |
| 41 |
class GrProgramInfo; |
| 42 |
class GrRenderTarget; |
| 43 |
class GrSurface; |
| 44 |
class GrSurfaceProxy; |
| 45 |
class GrTexture; |
| 46 |
class GrThreadSafePipelineBuilder; |
| 47 |
struct GrContextOptions; |
| 48 |
|
| 49 |
namespace skgpu { |
| 50 |
enum class Budgeted : bool; |
| 51 |
enum class Mipmapped : bool; |
| 52 |
} |
| 53 |
|
| 54 |
class GrMockGpu : public GrGpu { |
| 55 |
public: |
| 56 |
static std::unique_ptr<GrGpu> Make(const GrMockOptions*, |
| 57 |
const GrContextOptions&, |
| 58 |
GrDirectContext*); |
| 59 |
|
| 60 |
~GrMockGpu() override; |
| 61 |
|
| 62 |
GrThreadSafePipelineBuilder* pipelineBuilder() override; |
| 63 |
sk_sp<GrThreadSafePipelineBuilder> refPipelineBuilder() override; |
| 64 |
|
| 65 |
[[nodiscard]] std::unique_ptr<GrSemaphore> makeSemaphore(bool isOwned) override { |
| 66 |
return nullptr; |
| 67 |
} |
| 68 |
std::unique_ptr<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& /* semaphore */, |
| 69 |
GrSemaphoreWrapType /* wraptype */, |
| 70 |
GrWrapOwnership /* ownership */) override { |
| 71 |
return nullptr; |
| 72 |
} |
| 73 |
void insertSemaphore(GrSemaphore* semaphore) override {} |
| 74 |
void waitSemaphore(GrSemaphore* semaphore) override {} |
| 75 |
std::unique_ptr<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override { |
| 76 |
return nullptr; |
| 77 |
} |
| 78 |
|
| 79 |
void submit(GrOpsRenderPass* renderPass) override; |
| 80 |
|
| 81 |
void checkFinishedCallbacks() override {} |
| 82 |
void finishOutstandingGpuWork() override {} |
| 83 |
|
| 84 |
private: |
| 85 |
GrMockGpu(GrDirectContext*, const GrMockOptions&, const GrContextOptions&); |
| 86 |
|
| 87 |
void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {} |
| 88 |
|
| 89 |
sk_sp<GrTexture> onCreateTexture(SkISize, |
| 90 |
const GrBackendFormat&, |
| 91 |
GrRenderable, |
| 92 |
int renderTargetSampleCnt, |
| 93 |
skgpu::Budgeted, |
| 94 |
GrProtected, |
| 95 |
int mipLevelCount, |
| 96 |
uint32_t levelClearMask, |
| 97 |
std::string_view label) override; |
| 98 |
|
| 99 |
sk_sp<GrTexture> onCreateCompressedTexture(SkISize dimensions, |
| 100 |
const GrBackendFormat&, |
| 101 |
skgpu::Budgeted, |
| 102 |
skgpu::Mipmapped, |
| 103 |
GrProtected, |
| 104 |
const void* data, |
| 105 |
size_t dataSize) override; |
| 106 |
|
| 107 |
sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, |
| 108 |
GrWrapOwnership, |
| 109 |
GrWrapCacheable, |
| 110 |
GrIOType) override; |
| 111 |
sk_sp<GrTexture> onWrapCompressedBackendTexture(const GrBackendTexture&, |
| 112 |
GrWrapOwnership, |
| 113 |
GrWrapCacheable) override; |
| 114 |
|
| 115 |
sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, |
| 116 |
int sampleCnt, |
| 117 |
GrWrapOwnership, |
| 118 |
GrWrapCacheable) override; |
| 119 |
|
| 120 |
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override; |
| 121 |
|
| 122 |
sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes, |
| 123 |
GrGpuBufferType, |
| 124 |
GrAccessPattern) override; |
| 125 |
|
| 126 |
bool onReadPixels(GrSurface*, |
| 127 |
SkIRect, |
| 128 |
GrColorType surfaceColorType, |
| 129 |
GrColorType dstColorType, |
| 130 |
void*, |
| 131 |
size_t rowBytes) override { |
| 132 |
return true; |
| 133 |
} |
| 134 |
|
| 135 |
bool onWritePixels(GrSurface*, |
| 136 |
SkIRect, |
| 137 |
GrColorType surfaceColorType, |
| 138 |
GrColorType srcColorType, |
| 139 |
const GrMipLevel[], |
| 140 |
int mipLevelCount, |
| 141 |
bool prepForTexSampling) override { |
| 142 |
return true; |
| 143 |
} |
| 144 |
|
| 145 |
bool onTransferFromBufferToBuffer(sk_sp<GrGpuBuffer> src, |
| 146 |
size_t srcOffset, |
| 147 |
sk_sp<GrGpuBuffer> dst, |
| 148 |
size_t dstOffset, |
| 149 |
size_t size) override { |
| 150 |
return true; |
| 151 |
} |
| 152 |
|
| 153 |
bool onTransferPixelsTo(GrTexture*, |
| 154 |
SkIRect, |
| 155 |
GrColorType surfaceColorType, |
| 156 |
GrColorType bufferColorType, |
| 157 |
sk_sp<GrGpuBuffer>, |
| 158 |
size_t offset, |
| 159 |
size_t rowBytes) override { |
| 160 |
return true; |
| 161 |
} |
| 162 |
|
| 163 |
bool onTransferPixelsFrom(GrSurface*, |
| 164 |
SkIRect, |
| 165 |
GrColorType surfaceColorType, |
| 166 |
GrColorType bufferColorType, |
| 167 |
sk_sp<GrGpuBuffer>, |
| 168 |
size_t offset) override { |
| 169 |
return true; |
| 170 |
} |
| 171 |
|
| 172 |
bool onCopySurface(GrSurface* dst, const SkIRect& dstRect, |
| 173 |
GrSurface* src, const SkIRect& srcRect, |
| 174 |
GrSamplerState::Filter)override { |
| 175 |
return true; |
| 176 |
} |
| 177 |
|
| 178 |
bool onRegenerateMipMapLevels(GrTexture*) override { return true; } |
| 179 |
|
| 180 |
void onResolveRenderTarget(GrRenderTarget* target, const SkIRect&) override {} |
| 181 |
|
| 182 |
void addFinishedCallback(skgpu::AutoCallback callback, std::optional<GrTimerQuery>) override { |
| 183 |
SkASSERT(callback); |
| 184 |
} |
| 185 |
|
| 186 |
GrOpsRenderPass* onGetOpsRenderPass( |
| 187 |
GrRenderTarget*, |
| 188 |
bool useMSAASurface, |
| 189 |
GrAttachment*, |
| 190 |
GrSurfaceOrigin, |
| 191 |
const SkIRect&, |
| 192 |
const GrOpsRenderPass::LoadAndStoreInfo&, |
| 193 |
const GrOpsRenderPass::StencilLoadAndStoreInfo&, |
| 194 |
const skia_private::TArray<GrSurfaceProxy*, true>& sampledProxies, |
| 195 |
GrXferBarrierFlags renderPassXferBarriers) override; |
| 196 |
|
| 197 |
bool onSubmitToGpu(const GrSubmitInfo&) override { return true; } |
| 198 |
|
| 199 |
sk_sp<GrAttachment> makeStencilAttachment(const GrBackendFormat& /*colorFormat*/, |
| 200 |
SkISize dimensions, int numStencilSamples) override; |
| 201 |
|
| 202 |
GrBackendFormat getPreferredStencilFormat(const GrBackendFormat&) override { |
| 203 |
return GrBackendFormat::MakeMock(GrColorType::kUnknown, SkTextureCompressionType::kNone, |
| 204 |
true); |
| 205 |
} |
| 206 |
|
| 207 |
sk_sp<GrAttachment> makeMSAAAttachment(SkISize dimensions, |
| 208 |
const GrBackendFormat& format, |
| 209 |
int numSamples, |
| 210 |
GrProtected isProtected, |
| 211 |
GrMemoryless isMemoryless) override { |
| 212 |
return nullptr; |
| 213 |
} |
| 214 |
|
| 215 |
GrBackendTexture onCreateBackendTexture(SkISize dimensions, |
| 216 |
const GrBackendFormat&, |
| 217 |
GrRenderable, |
| 218 |
skgpu::Mipmapped, |
| 219 |
GrProtected, |
| 220 |
std::string_view label) override; |
| 221 |
|
| 222 |
bool onClearBackendTexture(const GrBackendTexture&, |
| 223 |
sk_sp<skgpu::RefCntedCallback> finishedCallback, |
| 224 |
std::array<float, 4> color) override { |
| 225 |
return true; |
| 226 |
} |
| 227 |
|
| 228 |
GrBackendTexture onCreateCompressedBackendTexture(SkISize dimensions, |
| 229 |
const GrBackendFormat&, |
| 230 |
skgpu::Mipmapped, |
| 231 |
GrProtected) override; |
| 232 |
|
| 233 |
bool onUpdateCompressedBackendTexture(const GrBackendTexture&, |
| 234 |
sk_sp<skgpu::RefCntedCallback> finishedCallback, |
| 235 |
const void*, |
| 236 |
size_t) override { |
| 237 |
return true; |
| 238 |
} |
| 239 |
|
| 240 |
void deleteBackendTexture(const GrBackendTexture&) override; |
| 241 |
|
| 242 |
bool compile(const GrProgramDesc&, const GrProgramInfo&) override { return false; } |
| 243 |
|
| 244 |
#if defined(GPU_TEST_UTILS) |
| 245 |
bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override; |
| 246 |
|
| 247 |
GrBackendRenderTarget createTestingOnlyBackendRenderTarget(SkISize dimensions, |
| 248 |
GrColorType, |
| 249 |
int sampleCnt, |
| 250 |
GrProtected) override; |
| 251 |
void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override; |
| 252 |
#endif |
| 253 |
|
| 254 |
const GrMockOptions fMockOptions; |
| 255 |
|
| 256 |
static int NextInternalTextureID(); |
| 257 |
static int NextExternalTextureID(); |
| 258 |
static int NextInternalRenderTargetID(); |
| 259 |
static int NextExternalRenderTargetID(); |
| 260 |
|
| 261 |
skia_private::THashSet<int> fOutstandingTestingOnlyTextureIDs; |
| 262 |
|
| 263 |
using INHERITED = GrGpu; |
| 264 |
}; |
| 265 |
|
| 266 |
#endif |