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 
5 #include "cc/paint/draw_image.h"
6 
7 #include <utility>
8 
9 namespace cc {
10 namespace {
11 
12 // Helper funciton to extract a scale from the matrix. Returns true on success
13 // and false on failure.
ExtractScale(const SkMatrix & matrix,SkSize * scale)14 bool ExtractScale(const SkMatrix& matrix, SkSize* scale) {
15   *scale = SkSize::Make(matrix.getScaleX(), matrix.getScaleY());
16   if (matrix.getType() & SkMatrix::kAffine_Mask) {
17     if (!matrix.decomposeScale(scale)) {
18       scale->set(1, 1);
19       return false;
20     }
21   }
22   return true;
23 }
24 
25 }  // namespace
26 
DrawImage()27 DrawImage::DrawImage()
28     : use_dark_mode_(false),
29       src_rect_(SkIRect::MakeXYWH(0, 0, 0, 0)),
30       filter_quality_(kNone_SkFilterQuality),
31       scale_(SkSize::Make(1.f, 1.f)),
32       matrix_is_decomposable_(true) {}
33 
DrawImage(PaintImage image)34 DrawImage::DrawImage(PaintImage image)
35     : paint_image_(std::move(image)),
36       use_dark_mode_(false),
37       src_rect_(
38           SkIRect::MakeXYWH(0, 0, paint_image_.width(), paint_image_.height())),
39       filter_quality_(kNone_SkFilterQuality),
40       scale_(SkSize::Make(1.f, 1.f)),
41       matrix_is_decomposable_(true) {}
42 
DrawImage(PaintImage image,bool use_dark_mode,const SkIRect & src_rect,SkFilterQuality filter_quality,const SkMatrix & matrix,base::Optional<size_t> frame_index,const base::Optional<gfx::ColorSpace> & color_space,float sdr_white_level)43 DrawImage::DrawImage(PaintImage image,
44                      bool use_dark_mode,
45                      const SkIRect& src_rect,
46                      SkFilterQuality filter_quality,
47                      const SkMatrix& matrix,
48                      base::Optional<size_t> frame_index,
49                      const base::Optional<gfx::ColorSpace>& color_space,
50                      float sdr_white_level)
51     : paint_image_(std::move(image)),
52       use_dark_mode_(use_dark_mode),
53       src_rect_(src_rect),
54       filter_quality_(filter_quality),
55       frame_index_(frame_index),
56       target_color_space_(color_space),
57       sdr_white_level_(sdr_white_level) {
58   matrix_is_decomposable_ = ExtractScale(matrix, &scale_);
59 }
60 
DrawImage(const DrawImage & other,float scale_adjustment,size_t frame_index,const gfx::ColorSpace & color_space,float sdr_white_level)61 DrawImage::DrawImage(const DrawImage& other,
62                      float scale_adjustment,
63                      size_t frame_index,
64                      const gfx::ColorSpace& color_space,
65                      float sdr_white_level)
66     : paint_image_(other.paint_image_),
67       use_dark_mode_(other.use_dark_mode_),
68       src_rect_(other.src_rect_),
69       filter_quality_(other.filter_quality_),
70       scale_(SkSize::Make(other.scale_.width() * scale_adjustment,
71                           other.scale_.height() * scale_adjustment)),
72       matrix_is_decomposable_(other.matrix_is_decomposable_),
73       frame_index_(frame_index),
74       target_color_space_(color_space),
75       sdr_white_level_(sdr_white_level) {
76   if (sdr_white_level_ == gfx::ColorSpace::kDefaultSDRWhiteLevel)
77     sdr_white_level_ = other.sdr_white_level_;
78 }
79 
80 DrawImage::DrawImage(const DrawImage& other) = default;
81 DrawImage::DrawImage(DrawImage&& other) = default;
82 DrawImage::~DrawImage() = default;
83 
84 DrawImage& DrawImage::operator=(DrawImage&& other) = default;
85 DrawImage& DrawImage::operator=(const DrawImage& other) = default;
86 
operator ==(const DrawImage & other) const87 bool DrawImage::operator==(const DrawImage& other) const {
88   return paint_image_ == other.paint_image_ &&
89          use_dark_mode_ == other.use_dark_mode_ &&
90          src_rect_ == other.src_rect_ &&
91          filter_quality_ == other.filter_quality_ && scale_ == other.scale_ &&
92          matrix_is_decomposable_ == other.matrix_is_decomposable_ &&
93          target_color_space_ == other.target_color_space_ &&
94          sdr_white_level_ == other.sdr_white_level_;
95 }
96 
97 }  // namespace cc
98