OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/compositor/clip_transform_recorder.h" | 5 #include "ui/compositor/clip_transform_recorder.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "cc/playback/clip_display_item.h" | 8 #include "cc/playback/clip_display_item.h" |
9 #include "cc/playback/clip_path_display_item.h" | 9 #include "cc/playback/clip_path_display_item.h" |
10 #include "cc/playback/display_item_list.h" | 10 #include "cc/playback/display_item_list.h" |
11 #include "cc/playback/transform_display_item.h" | 11 #include "cc/playback/transform_display_item.h" |
12 #include "ui/compositor/paint_context.h" | 12 #include "ui/compositor/paint_context.h" |
13 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
14 #include "ui/gfx/geometry/rect.h" | |
14 #include "ui/gfx/path.h" | 15 #include "ui/gfx/path.h" |
15 | 16 |
16 namespace ui { | 17 namespace ui { |
17 | 18 |
18 ClipTransformRecorder::ClipTransformRecorder(const PaintContext& context) | 19 ClipTransformRecorder::ClipTransformRecorder(const PaintContext& context, |
19 : context_(context), num_closers_(0) { | 20 const gfx::Size& layer_size) |
danakj
2015/11/17 22:14:33
IIRC when we'd talked about this, we discussed "la
wkorman
2015/11/17 23:43:04
Done.
| |
20 } | 21 : context_(context), |
22 layer_bounds_(context.ToLayerSpaceBounds(layer_size)), | |
23 num_closers_(0) {} | |
21 | 24 |
22 ClipTransformRecorder::~ClipTransformRecorder() { | 25 ClipTransformRecorder::~ClipTransformRecorder() { |
23 for (size_t i = 0; i < num_closers_; ++i) { | 26 for (size_t i = 0; i < num_closers_; ++i) { |
24 switch (closers_[i]) { | 27 switch (closers_[i]) { |
25 case CLIP_RECT: | 28 case CLIP_RECT: |
26 context_.list_->CreateAndAppendItem<cc::EndClipDisplayItem>(); | 29 context_.list_->CreateAndAppendItem<cc::EndClipDisplayItem>( |
30 layer_bounds_); | |
27 break; | 31 break; |
28 case CLIP_PATH: | 32 case CLIP_PATH: |
29 context_.list_->CreateAndAppendItem<cc::EndClipPathDisplayItem>(); | 33 context_.list_->CreateAndAppendItem<cc::EndClipPathDisplayItem>( |
34 layer_bounds_); | |
30 break; | 35 break; |
31 case TRANSFORM: | 36 case TRANSFORM: |
32 context_.list_->CreateAndAppendItem<cc::EndTransformDisplayItem>(); | 37 context_.list_->CreateAndAppendItem<cc::EndTransformDisplayItem>( |
38 layer_bounds_); | |
33 break; | 39 break; |
34 } | 40 } |
35 } | 41 } |
36 } | 42 } |
37 | 43 |
38 void ClipTransformRecorder::ClipRect(const gfx::Rect& clip_rect) { | 44 void ClipTransformRecorder::ClipRect(const gfx::Rect& clip_rect) { |
39 auto* item = context_.list_->CreateAndAppendItem<cc::ClipDisplayItem>(); | 45 gfx::Rect clip_in_layer_space = clip_rect + context_.offset_; |
danakj
2015/11/17 22:14:33
also i'd prefer adding a PaintContext method to co
danakj
2015/11/17 22:14:33
similar to this (with or without _space, but maybe
wkorman
2015/11/17 23:43:05
Added and made use of PaintContext::ToLayerSpaceRe
| |
46 auto* item = context_.list_->CreateAndAppendItem<cc::ClipDisplayItem>( | |
47 clip_in_layer_space); | |
40 item->SetNew(clip_rect, std::vector<SkRRect>()); | 48 item->SetNew(clip_rect, std::vector<SkRRect>()); |
41 DCHECK_LT(num_closers_, arraysize(closers_)); | 49 DCHECK_LT(num_closers_, arraysize(closers_)); |
42 closers_[num_closers_++] = CLIP_RECT; | 50 closers_[num_closers_++] = CLIP_RECT; |
43 } | 51 } |
44 | 52 |
45 void ClipTransformRecorder::ClipPath(const gfx::Path& clip_path) { | 53 void ClipTransformRecorder::ClipPath(const gfx::Path& clip_path) { |
46 bool anti_alias = false; | 54 bool anti_alias = false; |
47 auto* item = context_.list_->CreateAndAppendItem<cc::ClipPathDisplayItem>(); | 55 // As a further optimization, consider passing a more granular visual rect. |
56 auto* item = context_.list_->CreateAndAppendItem<cc::ClipPathDisplayItem>( | |
57 layer_bounds_); | |
48 item->SetNew(clip_path, SkRegion::kIntersect_Op, anti_alias); | 58 item->SetNew(clip_path, SkRegion::kIntersect_Op, anti_alias); |
49 DCHECK_LT(num_closers_, arraysize(closers_)); | 59 DCHECK_LT(num_closers_, arraysize(closers_)); |
50 closers_[num_closers_++] = CLIP_PATH; | 60 closers_[num_closers_++] = CLIP_PATH; |
51 } | 61 } |
52 | 62 |
53 void ClipTransformRecorder::ClipPathWithAntiAliasing( | 63 void ClipTransformRecorder::ClipPathWithAntiAliasing( |
54 const gfx::Path& clip_path) { | 64 const gfx::Path& clip_path) { |
55 bool anti_alias = true; | 65 bool anti_alias = true; |
56 auto* item = context_.list_->CreateAndAppendItem<cc::ClipPathDisplayItem>(); | 66 // As a further optimization, consider passing a more granular visual rect. |
67 auto* item = context_.list_->CreateAndAppendItem<cc::ClipPathDisplayItem>( | |
68 layer_bounds_); | |
57 item->SetNew(clip_path, SkRegion::kIntersect_Op, anti_alias); | 69 item->SetNew(clip_path, SkRegion::kIntersect_Op, anti_alias); |
58 DCHECK_LT(num_closers_, arraysize(closers_)); | 70 DCHECK_LT(num_closers_, arraysize(closers_)); |
59 closers_[num_closers_++] = CLIP_PATH; | 71 closers_[num_closers_++] = CLIP_PATH; |
60 } | 72 } |
61 | 73 |
62 void ClipTransformRecorder::Transform(const gfx::Transform& transform) { | 74 void ClipTransformRecorder::Transform(const gfx::Transform& transform) { |
63 auto* item = context_.list_->CreateAndAppendItem<cc::TransformDisplayItem>(); | 75 auto* item = context_.list_->CreateAndAppendItem<cc::TransformDisplayItem>( |
76 layer_bounds_); | |
64 item->SetNew(transform); | 77 item->SetNew(transform); |
65 DCHECK_LT(num_closers_, arraysize(closers_)); | 78 DCHECK_LT(num_closers_, arraysize(closers_)); |
66 closers_[num_closers_++] = TRANSFORM; | 79 closers_[num_closers_++] = TRANSFORM; |
67 } | 80 } |
68 | 81 |
69 } // namespace ui | 82 } // namespace ui |
OLD | NEW |