summaryrefslogtreecommitdiffstats
path: root/cc/resources/clip_display_item.cc
blob: 731c6059122df0930ce340ad894ad464a5242175 (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
70
71
72
73
74
// 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 "cc/resources/clip_display_item.h"

#include "third_party/skia/include/core/SkCanvas.h"

namespace cc {

ClipDisplayItem::ClipDisplayItem(gfx::Rect clip_rect,
                                 const std::vector<SkRRect>& rounded_clip_rects)
    : clip_rect_(clip_rect), rounded_clip_rects_(rounded_clip_rects) {
}

ClipDisplayItem::~ClipDisplayItem() {
}

void ClipDisplayItem::Raster(SkCanvas* canvas,
                             SkDrawPictureCallback* callback) const {
  canvas->save();
  canvas->clipRect(SkRect::MakeXYWH(clip_rect_.x(), clip_rect_.y(),
                                    clip_rect_.width(), clip_rect_.height()));
  for (size_t i = 0; i < rounded_clip_rects_.size(); ++i) {
    if (rounded_clip_rects_[i].isRect()) {
      canvas->clipRect(rounded_clip_rects_[i].rect());
    } else {
      bool antialiased = true;
      canvas->clipRRect(rounded_clip_rects_[i], SkRegion::kIntersect_Op,
                        antialiased);
    }
  }
}

bool ClipDisplayItem::IsSuitableForGpuRasterization() const {
  return true;
}

int ClipDisplayItem::ApproximateOpCount() const {
  return 1;
}

size_t ClipDisplayItem::PictureMemoryUsage() const {
  size_t total_size = sizeof(gfx::Rect);
  for (size_t i = 0; i < rounded_clip_rects_.size(); ++i) {
    total_size += sizeof(rounded_clip_rects_[i]);
  }
  return total_size;
}

EndClipDisplayItem::EndClipDisplayItem() {
}

EndClipDisplayItem::~EndClipDisplayItem() {
}

void EndClipDisplayItem::Raster(SkCanvas* canvas,
                                SkDrawPictureCallback* callback) const {
  canvas->restore();
}

bool EndClipDisplayItem::IsSuitableForGpuRasterization() const {
  return true;
}

int EndClipDisplayItem::ApproximateOpCount() const {
  return 0;
}

size_t EndClipDisplayItem::PictureMemoryUsage() const {
  return 0;
}

}  // namespace cc