GrYUVProvider.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright 2015 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 GrYUVProvider_DEFINED
  8. #define GrYUVProvider_DEFINED
  9. #include <include/private/GrTypesPriv.h>
  10. #include "include/core/SkImageInfo.h"
  11. #include "include/core/SkYUVAIndex.h"
  12. #include "include/core/SkYUVASizeInfo.h"
  13. #include "include/gpu/GrTypes.h"
  14. class GrBackendFormat;
  15. class GrRecordingContext;
  16. struct GrSurfaceDesc;
  17. class GrTexture;
  18. class GrTextureProxy;
  19. class SkCachedData;
  20. /**
  21. * There are at least 2 different ways to extract/retrieve YUV planar data...
  22. * - SkPixelRef
  23. * - SkImageGenerator
  24. *
  25. * To share common functionality around using the planar data, we use this abstract base-class
  26. * to represent accessing that data.
  27. */
  28. class GrYUVProvider {
  29. public:
  30. virtual ~GrYUVProvider() {}
  31. /**
  32. * On success, this returns a texture proxy that has converted the YUV data from the provider
  33. * into a form that is supported by the GPU (typically transformed into RGB). The texture will
  34. * automatically have a key added, so it can be retrieved from the cache (assuming it is
  35. * requested by a provider w/ the same genID). If srcColorSpace and dstColorSpace are
  36. * specified, then a color conversion from src to dst will be applied to the pixels.
  37. *
  38. * On failure (e.g. the provider had no data), this returns NULL.
  39. */
  40. sk_sp<GrTextureProxy> refAsTextureProxy(GrRecordingContext*,
  41. const GrSurfaceDesc&,
  42. GrColorType colorType,
  43. SkColorSpace* srcColorSpace,
  44. SkColorSpace* dstColorSpace);
  45. sk_sp<SkCachedData> getPlanes(SkYUVASizeInfo*, SkYUVAIndex[SkYUVAIndex::kIndexCount],
  46. SkYUVColorSpace*, const void* planes[SkYUVASizeInfo::kMaxCount]);
  47. private:
  48. virtual uint32_t onGetID() const = 0;
  49. // These are not meant to be called by a client, only by the implementation
  50. /**
  51. * If decoding to YUV is supported, this returns true. Otherwise, this
  52. * returns false and does not modify any of the parameters.
  53. *
  54. * @param sizeInfo Output parameter indicating the sizes and required
  55. * allocation widths of the Y, U, V, and A planes.
  56. * @param yuvaIndices How the YUVA planes are used/organized
  57. * @param colorSpace Output parameter.
  58. */
  59. virtual bool onQueryYUVA8(SkYUVASizeInfo* sizeInfo,
  60. SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
  61. SkYUVColorSpace* colorSpace) const = 0;
  62. /**
  63. * Returns true on success and false on failure.
  64. * This always attempts to perform a full decode. If the client only
  65. * wants size, it should call onQueryYUVA8().
  66. *
  67. * @param sizeInfo Needs to exactly match the values returned by the
  68. * query, except the WidthBytes may be larger than the
  69. * recommendation (but not smaller).
  70. * @param yuvaIndices How the YUVA planes are used/organized
  71. * @param planes Memory for each of the Y, U, V, and A planes.
  72. */
  73. virtual bool onGetYUVA8Planes(const SkYUVASizeInfo& sizeInfo,
  74. const SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
  75. void* planes[]) = 0;
  76. // This is used as release callback for the YUV data that we capture in an SkImage when
  77. // uploading to a gpu. When the upload is complete and we release the SkImage this callback will
  78. // release the underlying data.
  79. static void YUVGen_DataReleaseProc(const void*, void* data);
  80. };
  81. #endif