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 "base/logging.h"
8 #include "cc/playback/clip_display_item.h"
9 #include "cc/playback/clip_path_display_item.h"
10 #include "cc/playback/display_item_list.h"
11 #include "cc/playback/transform_display_item.h"
12 #include "ui/compositor/paint_context.h"
13 #include "ui/gfx/canvas.h"
14 #include "ui/gfx/path.h"
18 ClipTransformRecorder::ClipTransformRecorder(const PaintContext
& context
)
19 : context_(context
), num_closers_(0) {
22 ClipTransformRecorder::~ClipTransformRecorder() {
23 for (size_t i
= 0; i
< num_closers_
; ++i
) {
24 switch (closers_
[i
]) {
26 context_
.list_
->CreateAndAppendItem
<cc::EndClipDisplayItem
>();
29 context_
.list_
->CreateAndAppendItem
<cc::EndClipPathDisplayItem
>();
32 context_
.list_
->CreateAndAppendItem
<cc::EndTransformDisplayItem
>();
38 void ClipTransformRecorder::ClipRect(const gfx::Rect
& clip_rect
) {
39 auto* item
= context_
.list_
->CreateAndAppendItem
<cc::ClipDisplayItem
>();
40 item
->SetNew(clip_rect
, std::vector
<SkRRect
>());
41 DCHECK_LT(num_closers_
, arraysize(closers_
));
42 closers_
[num_closers_
++] = CLIP_RECT
;
45 void ClipTransformRecorder::ClipPath(const gfx::Path
& clip_path
) {
46 bool anti_alias
= false;
47 auto* item
= context_
.list_
->CreateAndAppendItem
<cc::ClipPathDisplayItem
>();
48 item
->SetNew(clip_path
, SkRegion::kIntersect_Op
, anti_alias
);
49 DCHECK_LT(num_closers_
, arraysize(closers_
));
50 closers_
[num_closers_
++] = CLIP_PATH
;
53 void ClipTransformRecorder::ClipPathWithAntiAliasing(
54 const gfx::Path
& clip_path
) {
55 bool anti_alias
= true;
56 auto* item
= context_
.list_
->CreateAndAppendItem
<cc::ClipPathDisplayItem
>();
57 item
->SetNew(clip_path
, SkRegion::kIntersect_Op
, anti_alias
);
58 DCHECK_LT(num_closers_
, arraysize(closers_
));
59 closers_
[num_closers_
++] = CLIP_PATH
;
62 void ClipTransformRecorder::Transform(const gfx::Transform
& transform
) {
63 auto* item
= context_
.list_
->CreateAndAppendItem
<cc::TransformDisplayItem
>();
64 item
->SetNew(transform
);
65 DCHECK_LT(num_closers_
, arraysize(closers_
));
66 closers_
[num_closers_
++] = TRANSFORM
;