draw_image.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright 2015 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_DRAW_IMAGE_H_
  5. #define CC_PAINT_DRAW_IMAGE_H_
  6. #include "cc/paint/paint_export.h"
  7. #include "cc/paint/paint_flags.h"
  8. #include "cc/paint/paint_image.h"
  9. #include "cc/paint/target_color_params.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. #include "third_party/skia/include/core/SkImage.h"
  12. #include "third_party/skia/include/core/SkM44.h"
  13. #include "third_party/skia/include/core/SkRect.h"
  14. #include "third_party/skia/include/core/SkRefCnt.h"
  15. #include "ui/gfx/color_space.h"
  16. #include "ui/gfx/geometry/size_f.h"
  17. namespace cc {
  18. // A DrawImage is a logical snapshot in time and space of a PaintImage. It
  19. // includes decisions about scaling, animation frame, final colorspace, etc.
  20. // It has not been decoded yet. DrawImage turns into DecodedDrawImage via
  21. // ImageDecodeCache::GetDecodedImageForDraw during playback.
  22. class CC_PAINT_EXPORT DrawImage {
  23. public:
  24. DrawImage();
  25. explicit DrawImage(PaintImage image);
  26. DrawImage(PaintImage image,
  27. bool use_dark_mode,
  28. const SkIRect& src_rect,
  29. PaintFlags::FilterQuality filter_quality,
  30. const SkM44& matrix,
  31. absl::optional<size_t> frame_index = absl::nullopt);
  32. DrawImage(PaintImage image,
  33. bool use_dark_mode,
  34. const SkIRect& src_rect,
  35. PaintFlags::FilterQuality filter_quality,
  36. const SkM44& matrix,
  37. absl::optional<size_t> frame_index,
  38. const TargetColorParams& target_color_params);
  39. // Constructs a DrawImage from |other| by adjusting its scale and setting new
  40. // color params.
  41. DrawImage(const DrawImage& other,
  42. float scale_adjustment,
  43. size_t frame_index,
  44. const TargetColorParams& target_color_params);
  45. DrawImage(const DrawImage& other);
  46. DrawImage(DrawImage&& other);
  47. ~DrawImage();
  48. DrawImage& operator=(DrawImage&& other);
  49. DrawImage& operator=(const DrawImage& other);
  50. bool operator==(const DrawImage& other) const;
  51. const PaintImage& paint_image() const { return paint_image_; }
  52. bool use_dark_mode() const { return use_dark_mode_; }
  53. const SkSize& scale() const { return scale_; }
  54. const SkIRect& src_rect() const { return src_rect_; }
  55. PaintFlags::FilterQuality filter_quality() const { return filter_quality_; }
  56. bool matrix_is_decomposable() const { return matrix_is_decomposable_; }
  57. PaintImage::FrameKey frame_key() const {
  58. return paint_image_.GetKeyForFrame(frame_index());
  59. }
  60. size_t frame_index() const {
  61. DCHECK(frame_index_.has_value());
  62. return frame_index_.value();
  63. }
  64. const TargetColorParams& target_color_params() const {
  65. DCHECK(target_color_params_.has_value());
  66. return *target_color_params_;
  67. }
  68. const gfx::ColorSpace& target_color_space() const {
  69. DCHECK(target_color_params_.has_value());
  70. return target_color_params_->color_space;
  71. }
  72. float sdr_white_level() const {
  73. DCHECK(target_color_params_.has_value());
  74. return target_color_params_->sdr_max_luminance_nits;
  75. }
  76. private:
  77. PaintImage paint_image_;
  78. bool use_dark_mode_;
  79. SkIRect src_rect_;
  80. PaintFlags::FilterQuality filter_quality_;
  81. SkSize scale_;
  82. bool matrix_is_decomposable_;
  83. absl::optional<size_t> frame_index_;
  84. absl::optional<TargetColorParams> target_color_params_;
  85. };
  86. } // namespace cc
  87. #endif // CC_PAINT_DRAW_IMAGE_H_