paint_image_builder.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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_BUILDER_H_
  5. #define CC_PAINT_PAINT_IMAGE_BUILDER_H_
  6. #include <utility>
  7. #include "cc/paint/paint_export.h"
  8. #include "cc/paint/paint_image.h"
  9. #include "cc/paint/paint_image_generator.h"
  10. #include "cc/paint/paint_op_buffer.h"
  11. #include "cc/paint/paint_worklet_input.h"
  12. #include "cc/paint/skia_paint_image_generator.h"
  13. #include "cc/paint/texture_backing.h"
  14. #include "third_party/skia/include/core/SkImage.h"
  15. namespace cc {
  16. // Class used to construct a paint image.
  17. class CC_PAINT_EXPORT PaintImageBuilder {
  18. public:
  19. static PaintImageBuilder WithDefault();
  20. // Starts with the given images. Everything, including the "contents" of the
  21. // image are copied.
  22. static PaintImageBuilder WithCopy(PaintImage image);
  23. // Starts with the given image's flags. Note that this does _not_ keep the
  24. // "contents" of the image. That is, it clears the cached SkImage, the set
  25. // SkImage, the set PaintRecord, and any other content type variables.
  26. static PaintImageBuilder WithProperties(PaintImage image);
  27. PaintImageBuilder(PaintImageBuilder&& other);
  28. ~PaintImageBuilder();
  29. PaintImageBuilder&& set_id(PaintImage::Id id) {
  30. paint_image_.id_ = id;
  31. #if DCHECK_IS_ON()
  32. id_set_ = true;
  33. #endif
  34. return std::move(*this);
  35. }
  36. PaintImageBuilder&& set_image(sk_sp<SkImage> sk_image,
  37. PaintImage::ContentId content_id) {
  38. DCHECK(!sk_image->isTextureBacked());
  39. paint_image_.sk_image_ = std::move(sk_image);
  40. paint_image_.content_id_ = content_id;
  41. return std::move(*this);
  42. }
  43. PaintImageBuilder&& set_texture_backing(sk_sp<TextureBacking> texture_backing,
  44. PaintImage::ContentId content_id) {
  45. paint_image_.texture_backing_ = std::move(texture_backing);
  46. paint_image_.content_id_ = content_id;
  47. return std::move(*this);
  48. }
  49. PaintImageBuilder&& set_paint_record(sk_sp<PaintRecord> paint_record,
  50. const gfx::Rect& rect,
  51. PaintImage::ContentId content_id) {
  52. DCHECK_NE(content_id, PaintImage::kInvalidContentId);
  53. paint_image_.paint_record_ = std::move(paint_record);
  54. paint_image_.paint_record_rect_ = rect;
  55. paint_image_.content_id_ = content_id;
  56. return std::move(*this);
  57. }
  58. PaintImageBuilder&& set_paint_image_generator(
  59. sk_sp<PaintImageGenerator> generator) {
  60. paint_image_.paint_image_generator_ = std::move(generator);
  61. return std::move(*this);
  62. }
  63. PaintImageBuilder&& set_animation_type(PaintImage::AnimationType type) {
  64. paint_image_.animation_type_ = type;
  65. return std::move(*this);
  66. }
  67. PaintImageBuilder&& set_completion_state(PaintImage::CompletionState state) {
  68. paint_image_.completion_state_ = state;
  69. return std::move(*this);
  70. }
  71. PaintImageBuilder&& set_is_multipart(bool is_multipart) {
  72. paint_image_.is_multipart_ = is_multipart;
  73. return std::move(*this);
  74. }
  75. PaintImageBuilder&& set_is_high_bit_depth(bool is_high_bit_depth) {
  76. paint_image_.is_high_bit_depth_ = is_high_bit_depth;
  77. return std::move(*this);
  78. }
  79. PaintImageBuilder&& set_may_be_lcp_candidate(bool may_be_lcp_candidate) {
  80. paint_image_.may_be_lcp_candidate_ = may_be_lcp_candidate;
  81. return std::move(*this);
  82. }
  83. PaintImageBuilder&& set_repetition_count(int count) {
  84. paint_image_.repetition_count_ = count;
  85. return std::move(*this);
  86. }
  87. PaintImageBuilder&& set_reset_animation_sequence_id(
  88. PaintImage::AnimationSequenceId id) {
  89. paint_image_.reset_animation_sequence_id_ = id;
  90. return std::move(*this);
  91. }
  92. PaintImageBuilder&& set_decoding_mode(
  93. PaintImage::DecodingMode decoding_mode) {
  94. paint_image_.decoding_mode_ = decoding_mode;
  95. return std::move(*this);
  96. }
  97. PaintImageBuilder&& set_paint_worklet_input(
  98. scoped_refptr<PaintWorkletInput> input) {
  99. paint_image_.paint_worklet_input_ = std::move(input);
  100. return std::move(*this);
  101. }
  102. PaintImage TakePaintImage();
  103. private:
  104. friend class PaintOpReader;
  105. friend class PaintShader;
  106. friend class ImagePaintFilter;
  107. friend PaintImage CreateNonDiscardablePaintImage(const gfx::Size& size);
  108. PaintImageBuilder();
  109. PaintImageBuilder(PaintImage starting_image, bool clear_contents);
  110. // For GPU process callers using a texture backed SkImage.
  111. PaintImageBuilder&& set_texture_image(sk_sp<SkImage> sk_image,
  112. PaintImage::ContentId content_id) {
  113. paint_image_.sk_image_ = std::move(sk_image);
  114. paint_image_.content_id_ = content_id;
  115. return std::move(*this);
  116. }
  117. PaintImage paint_image_;
  118. #if DCHECK_IS_ON()
  119. bool id_set_ = false;
  120. #endif
  121. };
  122. } // namespace cc
  123. #endif // CC_PAINT_PAINT_IMAGE_BUILDER_H_