GrMockGpu.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. #ifndef GrMockGpu_DEFINED
  8. #define GrMockGpu_DEFINED
  9. #include "include/gpu/GrRenderTarget.h"
  10. #include "include/gpu/GrTexture.h"
  11. #include "include/private/SkTHash.h"
  12. #include "src/gpu/GrGpu.h"
  13. #include "src/gpu/GrSemaphore.h"
  14. class GrMockGpuRTCommandBuffer;
  15. struct GrMockOptions;
  16. class GrPipeline;
  17. class GrMockGpu : public GrGpu {
  18. public:
  19. static sk_sp<GrGpu> Make(const GrMockOptions*, const GrContextOptions&, GrContext*);
  20. ~GrMockGpu() override {}
  21. GrGpuRTCommandBuffer* getCommandBuffer(
  22. GrRenderTarget*, GrSurfaceOrigin, const SkRect&,
  23. const GrGpuRTCommandBuffer::LoadAndStoreInfo&,
  24. const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&) override;
  25. GrGpuTextureCommandBuffer* getCommandBuffer(GrTexture*, GrSurfaceOrigin) override;
  26. GrFence SK_WARN_UNUSED_RESULT insertFence() override { return 0; }
  27. bool waitFence(GrFence, uint64_t) override { return true; }
  28. void deleteFence(GrFence) const override {}
  29. sk_sp<GrSemaphore> SK_WARN_UNUSED_RESULT makeSemaphore(bool isOwned) override {
  30. return nullptr;
  31. }
  32. sk_sp<GrSemaphore> wrapBackendSemaphore(const GrBackendSemaphore& semaphore,
  33. GrResourceProvider::SemaphoreWrapType wrapType,
  34. GrWrapOwnership ownership) override { return nullptr; }
  35. void insertSemaphore(sk_sp<GrSemaphore> semaphore) override {}
  36. void waitSemaphore(sk_sp<GrSemaphore> semaphore) override {}
  37. sk_sp<GrSemaphore> prepareTextureForCrossContextUsage(GrTexture*) override { return nullptr; }
  38. void submit(GrGpuCommandBuffer* buffer) override;
  39. void checkFinishProcs() override {}
  40. private:
  41. GrMockGpu(GrContext* context, const GrMockOptions&, const GrContextOptions&);
  42. void submitCommandBuffer(const GrMockGpuRTCommandBuffer*);
  43. void onResetContext(uint32_t resetBits) override {}
  44. void querySampleLocations(GrRenderTarget*, SkTArray<SkPoint>* sampleLocations) override;
  45. void xferBarrier(GrRenderTarget*, GrXferBarrierType) override {}
  46. sk_sp<GrTexture> onCreateTexture(const GrSurfaceDesc&, GrRenderable, int renderTargetSampleCnt,
  47. SkBudgeted, GrProtected, const GrMipLevel[],
  48. int mipLevelCount) override;
  49. sk_sp<GrTexture> onCreateCompressedTexture(int width, int height, SkImage::CompressionType,
  50. SkBudgeted, const void* data) override;
  51. sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrColorType, GrWrapOwnership,
  52. GrWrapCacheable, GrIOType) override;
  53. sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
  54. int sampleCnt,
  55. GrColorType,
  56. GrWrapOwnership,
  57. GrWrapCacheable) override;
  58. sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&,
  59. GrColorType) override;
  60. sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
  61. int sampleCnt, GrColorType) override;
  62. sk_sp<GrGpuBuffer> onCreateBuffer(size_t sizeInBytes, GrGpuBufferType, GrAccessPattern,
  63. const void*) override;
  64. bool onReadPixels(GrSurface* surface, int left, int top, int width, int height, GrColorType,
  65. void* buffer, size_t rowBytes) override {
  66. return true;
  67. }
  68. bool onWritePixels(GrSurface* surface, int left, int top, int width, int height, GrColorType,
  69. const GrMipLevel texels[], int mipLevelCount) override {
  70. return true;
  71. }
  72. bool onTransferPixelsTo(GrTexture* texture, int left, int top, int width, int height,
  73. GrColorType, GrGpuBuffer* transferBuffer, size_t offset,
  74. size_t rowBytes) override {
  75. return true;
  76. }
  77. bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
  78. GrColorType, GrGpuBuffer* transferBuffer, size_t offset) override {
  79. return true;
  80. }
  81. bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
  82. const SkIPoint& dstPoint, bool canDiscardOutsideDstRect) override {
  83. return true;
  84. }
  85. bool onRegenerateMipMapLevels(GrTexture*) override { return true; }
  86. void onResolveRenderTarget(GrRenderTarget* target) override { return; }
  87. void onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfaceAccess access,
  88. const GrFlushInfo& info, const GrPrepareForExternalIORequests&) override {
  89. if (info.fFinishedProc) {
  90. info.fFinishedProc(info.fFinishedContext);
  91. }
  92. }
  93. GrStencilAttachment* createStencilAttachmentForRenderTarget(
  94. const GrRenderTarget*, int width, int height, int numStencilSamples) override;
  95. GrBackendTexture createBackendTexture(int w, int h, const GrBackendFormat&,
  96. GrMipMapped, GrRenderable,
  97. const void* pixels, size_t rowBytes,
  98. const SkColor4f* color, GrProtected isProtected) override;
  99. void deleteBackendTexture(const GrBackendTexture&) override;
  100. #if GR_TEST_UTILS
  101. bool isTestingOnlyBackendTexture(const GrBackendTexture&) const override;
  102. GrBackendRenderTarget createTestingOnlyBackendRenderTarget(int w, int h, GrColorType) override;
  103. void deleteTestingOnlyBackendRenderTarget(const GrBackendRenderTarget&) override;
  104. void testingOnly_flushGpuAndSync() override {}
  105. #endif
  106. const GrMockOptions fMockOptions;
  107. static int NextInternalTextureID();
  108. static int NextExternalTextureID();
  109. static int NextInternalRenderTargetID();
  110. static int NextExternalRenderTargetID();
  111. SkTHashSet<int> fOutstandingTestingOnlyTextureIDs;
  112. typedef GrGpu INHERITED;
  113. };
  114. #endif