draw_image.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #include "cc/paint/draw_image.h"
  5. #include <utility>
  6. namespace cc {
  7. namespace {
  8. // Helper funciton to extract a scale from the matrix. Returns true on success
  9. // and false on failure.
  10. bool ExtractScale(const SkM44& matrix, SkSize* scale) {
  11. *scale = SkSize::Make(matrix.rc(0, 0), matrix.rc(1, 1));
  12. // TODO(crbug.com/1155544): Don't use SkMatrix here, add functionality to
  13. // MathUtil.
  14. SkMatrix mat33 = matrix.asM33();
  15. if (mat33.getType() & SkMatrix::kAffine_Mask) {
  16. if (!mat33.decomposeScale(scale)) {
  17. scale->set(1, 1);
  18. return false;
  19. }
  20. }
  21. return true;
  22. }
  23. } // namespace
  24. DrawImage::DrawImage()
  25. : use_dark_mode_(false),
  26. src_rect_(SkIRect::MakeXYWH(0, 0, 0, 0)),
  27. filter_quality_(PaintFlags::FilterQuality::kNone),
  28. scale_(SkSize::Make(1.f, 1.f)),
  29. matrix_is_decomposable_(true) {}
  30. DrawImage::DrawImage(PaintImage image)
  31. : paint_image_(std::move(image)),
  32. use_dark_mode_(false),
  33. src_rect_(
  34. SkIRect::MakeXYWH(0, 0, paint_image_.width(), paint_image_.height())),
  35. filter_quality_(PaintFlags::FilterQuality::kNone),
  36. scale_(SkSize::Make(1.f, 1.f)),
  37. matrix_is_decomposable_(true) {}
  38. DrawImage::DrawImage(PaintImage image,
  39. bool use_dark_mode,
  40. const SkIRect& src_rect,
  41. PaintFlags::FilterQuality filter_quality,
  42. const SkM44& matrix,
  43. absl::optional<size_t> frame_index)
  44. : paint_image_(std::move(image)),
  45. use_dark_mode_(use_dark_mode),
  46. src_rect_(src_rect),
  47. filter_quality_(filter_quality),
  48. frame_index_(frame_index) {
  49. matrix_is_decomposable_ = ExtractScale(matrix, &scale_);
  50. }
  51. DrawImage::DrawImage(PaintImage image,
  52. bool use_dark_mode,
  53. const SkIRect& src_rect,
  54. PaintFlags::FilterQuality filter_quality,
  55. const SkM44& matrix,
  56. absl::optional<size_t> frame_index,
  57. const TargetColorParams& target_color_params)
  58. : paint_image_(std::move(image)),
  59. use_dark_mode_(use_dark_mode),
  60. src_rect_(src_rect),
  61. filter_quality_(filter_quality),
  62. frame_index_(frame_index),
  63. target_color_params_(target_color_params) {
  64. matrix_is_decomposable_ = ExtractScale(matrix, &scale_);
  65. }
  66. DrawImage::DrawImage(const DrawImage& other,
  67. float scale_adjustment,
  68. size_t frame_index,
  69. const TargetColorParams& target_color_params)
  70. : paint_image_(other.paint_image_),
  71. use_dark_mode_(other.use_dark_mode_),
  72. src_rect_(other.src_rect_),
  73. filter_quality_(other.filter_quality_),
  74. scale_(SkSize::Make(other.scale_.width() * scale_adjustment,
  75. other.scale_.height() * scale_adjustment)),
  76. matrix_is_decomposable_(other.matrix_is_decomposable_),
  77. frame_index_(frame_index),
  78. target_color_params_(target_color_params) {}
  79. DrawImage::DrawImage(const DrawImage& other) = default;
  80. DrawImage::DrawImage(DrawImage&& other) = default;
  81. DrawImage::~DrawImage() = default;
  82. DrawImage& DrawImage::operator=(DrawImage&& other) = default;
  83. DrawImage& DrawImage::operator=(const DrawImage& other) = default;
  84. bool DrawImage::operator==(const DrawImage& other) const {
  85. return paint_image_ == other.paint_image_ &&
  86. use_dark_mode_ == other.use_dark_mode_ &&
  87. src_rect_ == other.src_rect_ &&
  88. filter_quality_ == other.filter_quality_ && scale_ == other.scale_ &&
  89. matrix_is_decomposable_ == other.matrix_is_decomposable_ &&
  90. target_color_params_ == other.target_color_params_;
  91. }
  92. } // namespace cc