summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/css/cssom/paint_worklet_deferred_image.cc
blob: 35a58b2dcd2af4bf9036031030a2716b0a3feec1 (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
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/core/css/cssom/paint_worklet_deferred_image.h"

#include <utility>

#include "third_party/blink/renderer/platform/geometry/float_rect.h"
#include "third_party/blink/renderer/platform/graphics/graphics_context.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_canvas.h"
#include "third_party/blink/renderer/platform/graphics/paint/paint_record.h"
#include "third_party/blink/renderer/platform/graphics/skia/skia_utils.h"

namespace blink {

namespace {
void DrawInternal(cc::PaintCanvas* canvas,
                  const FloatRect& dest_rect,
                  const FloatRect& src_rect,
                  const PaintFlags& flags,
                  Image::ImageClampingMode clamping_mode,
                  const PaintImage& image) {
  canvas->drawImageRect(image, src_rect, dest_rect, &flags,
                        WebCoreClampingModeToSkiaRectConstraint(clamping_mode));
}
}  // namespace

void PaintWorkletDeferredImage::Draw(cc::PaintCanvas* canvas,
                                     const PaintFlags& flags,
                                     const FloatRect& dest_rect,
                                     const FloatRect& src_rect,
                                     RespectImageOrientationEnum,
                                     ImageClampingMode clamping_mode,
                                     ImageDecodingMode) {
  DrawInternal(canvas, dest_rect, src_rect, flags, clamping_mode, image_);
}

void PaintWorkletDeferredImage::DrawTile(GraphicsContext& context,
                                         const FloatRect& src_rect,
                                         RespectImageOrientationEnum) {
  DrawInternal(context.Canvas(), FloatRect(), src_rect, context.FillFlags(),
               kClampImageToSourceRect, image_);
}

sk_sp<PaintShader> PaintWorkletDeferredImage::CreateShader(
    const FloatRect& tile_rect,
    const SkMatrix* pattern_matrix,
    const FloatRect& src_rect,
    RespectImageOrientationEnum) {
  SkRect tile = SkRect::MakeXYWH(tile_rect.X(), tile_rect.Y(),
                                 tile_rect.Width(), tile_rect.Height());
  sk_sp<PaintShader> shader = PaintShader::MakeImage(
      image_, SkTileMode::kRepeat, SkTileMode::kRepeat, pattern_matrix, &tile);

  return shader;
}

}  // namespace blink