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"
17 ClipTransformRecorder::ClipTransformRecorder(const PaintContext
& context
)
20 context_
.canvas_
->Save();
23 ClipTransformRecorder::~ClipTransformRecorder() {
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
) {
32 context_
.list_
->AppendItem(
33 cc::ClipDisplayItem::Create(clip_rect
, std::vector
<SkRRect
>()));
34 closers_
.push_back(cc::EndClipDisplayItem::Create().release());
36 context_
.canvas_
->ClipRect(clip_rect
);
40 void ClipTransformRecorder::ClipPath(const gfx::Path
& clip_path
) {
41 bool anti_alias
= false;
43 context_
.list_
->AppendItem(cc::ClipPathDisplayItem::Create(
44 clip_path
, SkRegion::kIntersect_Op
, anti_alias
));
45 closers_
.push_back(cc::EndClipPathDisplayItem::Create().release());
47 context_
.canvas_
->ClipPath(clip_path
, anti_alias
);
51 void ClipTransformRecorder::ClipPathWithAntiAliasing(
52 const gfx::Path
& clip_path
) {
53 bool anti_alias
= true;
55 context_
.list_
->AppendItem(cc::ClipPathDisplayItem::Create(
56 clip_path
, SkRegion::kIntersect_Op
, anti_alias
));
57 closers_
.push_back(cc::EndClipPathDisplayItem::Create().release());
59 context_
.canvas_
->ClipPath(clip_path
, anti_alias
);
63 void ClipTransformRecorder::Transform(const gfx::Transform
& transform
) {
65 context_
.list_
->AppendItem(cc::TransformDisplayItem::Create(transform
));
66 closers_
.push_back(cc::EndTransformDisplayItem::Create().release());
68 context_
.canvas_
->Transform(transform
);