paint_image_generator.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef CC_PAINT_PAINT_IMAGE_GENERATOR_H_
  5. #define CC_PAINT_PAINT_IMAGE_GENERATOR_H_
  6. #include <vector>
  7. #include "cc/paint/frame_metadata.h"
  8. #include "cc/paint/paint_export.h"
  9. #include "cc/paint/paint_image.h"
  10. #include "third_party/skia/include/core/SkData.h"
  11. #include "third_party/skia/include/core/SkImageInfo.h"
  12. #include "third_party/skia/include/core/SkSize.h"
  13. #include "third_party/skia/include/core/SkYUVAPixmaps.h"
  14. namespace cc {
  15. // PaintImage Generator is a wrapper to provide a lazily decoded PaintImage to
  16. // the compositor.
  17. // Note that the implementation of this class must ensure thread safety, it can
  18. // be called from any thread.
  19. class CC_PAINT_EXPORT PaintImageGenerator : public SkRefCnt {
  20. public:
  21. PaintImageGenerator(const PaintImageGenerator&) = delete;
  22. ~PaintImageGenerator() override;
  23. PaintImageGenerator& operator=(const PaintImageGenerator&) = delete;
  24. // Returns a reference to the encoded content of this image.
  25. virtual sk_sp<SkData> GetEncodedData() const = 0;
  26. // Decode into the given pixels, a block of memory of size at least
  27. // (info.fHeight - 1) * rowBytes + (info.fWidth * bytesPerPixel). |info|
  28. // represents the desired output format. Returns true on success.
  29. //
  30. // TODO(khushalsagar): |lazy_pixel_ref| is only present for
  31. // DecodingImageGenerator tracing needs. Remove it.
  32. virtual bool GetPixels(const SkImageInfo& info,
  33. void* pixels,
  34. size_t row_bytes,
  35. size_t frame_index,
  36. PaintImage::GeneratorClientId client_id,
  37. uint32_t lazy_pixel_ref) = 0;
  38. // Returns true if the generator supports YUV decoding, providing the details
  39. // about planar configuration and conversion to RGB in |info|.
  40. // |supported_data_types| indicates the allowed bit depth and types allowed
  41. // for Y, U, V, and A values.
  42. virtual bool QueryYUVA(
  43. const SkYUVAPixmapInfo::SupportedDataTypes& supported_data_types,
  44. SkYUVAPixmapInfo* info) const = 0;
  45. // Decodes to YUV, storing planar data in the SkPixmaps in the provided
  46. // |pixmaps|. The method should only be used if QueryYUVA returns true.
  47. // SkPixmaps owned by |pixmaps| have been configured as indicated by
  48. // QueryYUVA.
  49. //
  50. // TODO(khushalsagar): |lazy_pixel_ref| is only present for
  51. // DecodingImageGenerator tracing needs. Remove it.
  52. virtual bool GetYUVAPlanes(const SkYUVAPixmaps& pixmaps,
  53. size_t frame_index,
  54. uint32_t lazy_pixel_ref,
  55. PaintImage::GeneratorClientId client_id) = 0;
  56. // Returns the smallest size that is at least as big as the requested size,
  57. // such that we can decode to exactly that scale.
  58. virtual SkISize GetSupportedDecodeSize(const SkISize& requested_size) const;
  59. // Returns the content id to key the decoded output produced by this
  60. // generator for a frame at |frame_index|. The generator promises that
  61. // the output for repeated calls to decode a frame will be consistent across
  62. // all generators for a PaintImage, if this function returns the same id.
  63. virtual PaintImage::ContentId GetContentIdForFrame(size_t frame_index) const;
  64. const SkImageInfo& GetSkImageInfo() const { return info_; }
  65. const std::vector<FrameMetadata>& GetFrameMetadata() const { return frames_; }
  66. // Returns the information required to decide whether or not hardware
  67. // acceleration can be used to decode this image.
  68. virtual const ImageHeaderMetadata* GetMetadataForDecodeAcceleration() const;
  69. protected:
  70. // |info| is the info for this paint image generator.
  71. PaintImageGenerator(const SkImageInfo& info,
  72. std::vector<FrameMetadata> frames = {FrameMetadata()});
  73. private:
  74. const SkImageInfo info_;
  75. const PaintImage::ContentId generator_content_id_;
  76. const std::vector<FrameMetadata> frames_;
  77. };
  78. } // namespace cc
  79. #endif // CC_PAINT_PAINT_IMAGE_GENERATOR_H_