Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / compositor / clip_transform_recorder.cc
blob6b8109d803a80a8fcff196948fc4286368fb765b
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.
5 #include "ui/compositor/clip_transform_recorder.h"
7 #include "cc/resources/clip_display_item.h"
8 #include "cc/resources/clip_path_display_item.h"
9 #include "cc/resources/display_item_list.h"
10 #include "cc/resources/transform_display_item.h"
11 #include "ui/compositor/paint_context.h"
12 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/path.h"
15 namespace ui {
17 ClipTransformRecorder::ClipTransformRecorder(const PaintContext& context)
18 : context_(context) {
19 if (context_.canvas_)
20 context_.canvas_->Save();
23 ClipTransformRecorder::~ClipTransformRecorder() {
24 if (context_.canvas_)
25 context_.canvas_->Restore();
26 for (auto it = closers_.rbegin(); it != closers_.rend(); ++it)
27 context_.list_->AppendItem(make_scoped_ptr(*it));
30 void ClipTransformRecorder::ClipRect(const gfx::Rect& clip_rect) {
31 if (context_.list_) {
32 context_.list_->AppendItem(
33 cc::ClipDisplayItem::Create(clip_rect, std::vector<SkRRect>()));
34 closers_.push_back(cc::EndClipDisplayItem::Create().release());
35 } else {
36 context_.canvas_->ClipRect(clip_rect);
40 void ClipTransformRecorder::ClipPath(const gfx::Path& clip_path) {
41 bool anti_alias = false;
42 if (context_.list_) {
43 context_.list_->AppendItem(cc::ClipPathDisplayItem::Create(
44 clip_path, SkRegion::kIntersect_Op, anti_alias));
45 closers_.push_back(cc::EndClipPathDisplayItem::Create().release());
46 } else {
47 context_.canvas_->ClipPath(clip_path, anti_alias);
51 void ClipTransformRecorder::ClipPathWithAntiAliasing(
52 const gfx::Path& clip_path) {
53 bool anti_alias = true;
54 if (context_.list_) {
55 context_.list_->AppendItem(cc::ClipPathDisplayItem::Create(
56 clip_path, SkRegion::kIntersect_Op, anti_alias));
57 closers_.push_back(cc::EndClipPathDisplayItem::Create().release());
58 } else {
59 context_.canvas_->ClipPath(clip_path, anti_alias);
63 void ClipTransformRecorder::Transform(const gfx::Transform& transform) {
64 if (context_.list_) {
65 context_.list_->AppendItem(cc::TransformDisplayItem::Create(transform));
66 closers_.push_back(cc::EndTransformDisplayItem::Create().release());
67 } else {
68 context_.canvas_->Transform(transform);
72 } // namespace ui