summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/canvas/canvas2d/clip_list.cc
blob: 23178b411ea43d9d2409113fdb65d623d8dc1e94 (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
// Copyright 2014 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/modules/canvas/canvas2d/clip_list.h"

#include "third_party/blink/renderer/platform/graphics/paint/paint_canvas.h"
#include "third_party/blink/renderer/platform/transforms/affine_transform.h"
#include "third_party/skia/include/pathops/SkPathOps.h"

namespace blink {

ClipList::ClipList(const ClipList& other) : clip_list_(other.clip_list_) {}

void ClipList::ClipPath(const SkPath& path,
                        AntiAliasingMode anti_aliasing_mode,
                        const SkMatrix& ctm) {
  ClipOp new_clip;
  new_clip.anti_aliasing_mode_ = anti_aliasing_mode;
  new_clip.path_ = path;
  new_clip.path_.transform(ctm);
  if (clip_list_.IsEmpty()) {
    current_clip_path_ = path;
  } else {
    Op(current_clip_path_, path, SkPathOp::kIntersect_SkPathOp,
       &current_clip_path_);
  }
  clip_list_.push_back(new_clip);
}

void ClipList::Playback(PaintCanvas* canvas) const {
  for (const ClipOp* it = clip_list_.begin(); it < clip_list_.end(); it++) {
    canvas->clipPath(it->path_, SkClipOp::kIntersect,
                     it->anti_aliasing_mode_ == kAntiAliased);
  }
}

const SkPath& ClipList::GetCurrentClipPath() const {
  return current_clip_path_;
}

ClipList::ClipOp::ClipOp() : anti_aliasing_mode_(kAntiAliased) {}

ClipList::ClipOp::ClipOp(const ClipOp& other) = default;

}  // namespace blink