summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/svg/graphics/svg_image_for_container.cc
blob: 0567b0d5f6b7e214e3aba92cd11be4bdec5f31e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * Copyright (C) 2013 Google Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "third_party/blink/renderer/core/svg/graphics/svg_image_for_container.h"
#include "third_party/blink/renderer/platform/graphics/graphics_context.h"

namespace blink {

IntSize SVGImageForContainer::SizeWithConfig(SizeConfig config) const {
  return RoundedIntSize(SizeWithConfigAsFloat(config));
}

FloatSize SVGImageForContainer::SizeWithConfigAsFloat(SizeConfig) const {
  return container_size_.ScaledBy(zoom_);
}

void SVGImageForContainer::Draw(cc::PaintCanvas* canvas,
                                const cc::PaintFlags& flags,
                                const FloatRect& dst_rect,
                                const FloatRect& src_rect,
                                const ImageDrawOptions& draw_options,
                                ImageClampingMode,
                                ImageDecodingMode) {
  const SVGImage::DrawInfo draw_info(container_size_, zoom_, url_,
                                     draw_options.apply_dark_mode);
  image_->DrawForContainer(draw_info, canvas, flags, dst_rect, src_rect);
}

void SVGImageForContainer::DrawPattern(GraphicsContext& context,
                                       const cc::PaintFlags& flags,
                                       const FloatRect& dst_rect,
                                       const ImageTilingInfo& tiling_info,
                                       const ImageDrawOptions& draw_options) {
  const SVGImage::DrawInfo draw_info(container_size_, zoom_, url_,
                                     draw_options.apply_dark_mode);
  image_->DrawPatternForContainer(draw_info, context, flags, dst_rect,
                                  tiling_info);
}

bool SVGImageForContainer::ApplyShader(cc::PaintFlags& flags,
                                       const SkMatrix& local_matrix) {
  const SVGImage::DrawInfo draw_info(container_size_, zoom_, url_, false);
  return image_->ApplyShaderForContainer(draw_info, flags, local_matrix);
}

PaintImage SVGImageForContainer::PaintImageForCurrentFrame() {
  const SVGImage::DrawInfo draw_info(container_size_, zoom_, url_, false);
  auto builder = CreatePaintImageBuilder();
  image_->PopulatePaintRecordForCurrentFrameForContainer(draw_info, builder);
  return builder.TakePaintImage();
}

}  // namespace blink