SkImage_GpuBase.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright 2018 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 SkImage_GpuBase_DEFINED
  8. #define SkImage_GpuBase_DEFINED
  9. #include "include/core/SkDeferredDisplayListRecorder.h"
  10. #include "include/core/SkYUVAIndex.h"
  11. #include "include/gpu/GrBackendSurface.h"
  12. #include "include/gpu/GrContext.h"
  13. #include "include/private/GrTypesPriv.h"
  14. #include "src/image/SkImage_Base.h"
  15. class GrColorSpaceXform;
  16. class SkColorSpace;
  17. class SkImage_GpuBase : public SkImage_Base {
  18. public:
  19. SkImage_GpuBase(sk_sp<GrContext>, int width, int height, uint32_t uniqueID, SkColorType,
  20. SkAlphaType, sk_sp<SkColorSpace>);
  21. ~SkImage_GpuBase() override;
  22. GrContext* context() const final { return fContext.get(); }
  23. bool getROPixels(SkBitmap*, CachingHint) const final;
  24. sk_sp<SkImage> onMakeSubset(GrRecordingContext*, const SkIRect& subset) const final;
  25. bool onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dstRB,
  26. int srcX, int srcY, CachingHint) const override;
  27. sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext* context) const override {
  28. // we shouldn't end up calling this
  29. SkASSERT(false);
  30. return this->INHERITED::asTextureProxyRef(context);
  31. }
  32. sk_sp<GrTextureProxy> asTextureProxyRef(GrRecordingContext*, const GrSamplerState&,
  33. SkScalar scaleAdjust[2]) const final;
  34. sk_sp<GrTextureProxy> refPinnedTextureProxy(GrRecordingContext* context,
  35. uint32_t* uniqueID) const final {
  36. *uniqueID = this->uniqueID();
  37. return this->asTextureProxyRef(context);
  38. }
  39. GrBackendTexture onGetBackendTexture(bool flushPendingGrContextIO,
  40. GrSurfaceOrigin* origin) const final;
  41. GrTexture* onGetTexture() const final;
  42. bool onIsValid(GrContext*) const final;
  43. #if GR_TEST_UTILS
  44. void resetContext(sk_sp<GrContext> newContext);
  45. #endif
  46. static bool ValidateBackendTexture(GrContext* ctx, const GrBackendTexture& tex,
  47. GrPixelConfig* config, GrColorType grCT,
  48. SkColorType ct, SkAlphaType at,
  49. sk_sp<SkColorSpace> cs);
  50. static bool MakeTempTextureProxies(GrContext* ctx, const GrBackendTexture yuvaTextures[],
  51. int numTextures, const SkYUVAIndex [4],
  52. GrSurfaceOrigin imageOrigin,
  53. sk_sp<GrTextureProxy> tempTextureProxies[4]);
  54. static SkAlphaType GetAlphaTypeFromYUVAIndices(const SkYUVAIndex yuvaIndices[4]) {
  55. return -1 != yuvaIndices[SkYUVAIndex::kA_Index].fIndex ? kPremul_SkAlphaType
  56. : kOpaque_SkAlphaType;
  57. }
  58. using PromiseImageTextureContext = SkDeferredDisplayListRecorder::PromiseImageTextureContext;
  59. using PromiseImageTextureFulfillProc =
  60. SkDeferredDisplayListRecorder::PromiseImageTextureFulfillProc;
  61. using PromiseImageTextureReleaseProc =
  62. SkDeferredDisplayListRecorder::PromiseImageTextureReleaseProc;
  63. using PromiseImageTextureDoneProc = SkDeferredDisplayListRecorder::PromiseImageTextureDoneProc;
  64. protected:
  65. using PromiseImageApiVersion = SkDeferredDisplayListRecorder::PromiseImageApiVersion;
  66. // Helper for making a lazy proxy for a promise image. The PromiseDoneProc we be called,
  67. // if not null, immediately if this function fails. Othwerwise, it is installed in the
  68. // proxy along with the TextureFulfillProc and TextureReleaseProc. PromiseDoneProc must not
  69. // be null.
  70. static sk_sp<GrTextureProxy> MakePromiseImageLazyProxy(
  71. GrContext*, int width, int height, GrSurfaceOrigin, GrColorType, GrBackendFormat,
  72. GrMipMapped, PromiseImageTextureFulfillProc, PromiseImageTextureReleaseProc,
  73. PromiseImageTextureDoneProc, PromiseImageTextureContext, PromiseImageApiVersion);
  74. static bool RenderYUVAToRGBA(GrContext* ctx, GrRenderTargetContext* renderTargetContext,
  75. const SkRect& rect, SkYUVColorSpace yuvColorSpace,
  76. sk_sp<GrColorSpaceXform> colorSpaceXform,
  77. const sk_sp<GrTextureProxy> proxies[4],
  78. const SkYUVAIndex yuvaIndices[4]);
  79. sk_sp<GrContext> fContext;
  80. private:
  81. typedef SkImage_Base INHERITED;
  82. };
  83. #endif