| 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_recorder.h" | 5 #include "ui/compositor/clip_recorder.h" |
| 6 | 6 |
| 7 #include "cc/playback/clip_display_item.h" | 7 #include "cc/playback/clip_display_item.h" |
| 8 #include "cc/playback/clip_path_display_item.h" | 8 #include "cc/playback/clip_path_display_item.h" |
| 9 #include "cc/playback/display_item_list.h" | 9 #include "cc/playback/display_item_list.h" |
| 10 #include "ui/compositor/paint_context.h" | 10 #include "ui/compositor/paint_context.h" |
| 11 #include "ui/gfx/canvas.h" | 11 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/geometry/rect.h" |
| 12 #include "ui/gfx/path.h" | 13 #include "ui/gfx/path.h" |
| 13 | 14 |
| 14 namespace ui { | 15 namespace ui { |
| 15 | 16 |
| 16 ClipRecorder::ClipRecorder(const PaintContext& context) | 17 ClipRecorder::ClipRecorder(const PaintContext& context, |
| 17 : context_(context), num_closers_(0) { | 18 const gfx::Size& size_in_layer) |
| 18 } | 19 : context_(context), |
| 20 bounds_in_layer_(context.ToLayerSpaceBounds(size_in_layer)), |
| 21 num_closers_(0) {} |
| 19 | 22 |
| 20 ClipRecorder::~ClipRecorder() { | 23 ClipRecorder::~ClipRecorder() { |
| 21 for (size_t i = num_closers_; i > 0; --i) { | 24 for (size_t i = num_closers_; i > 0; --i) { |
| 22 switch (closers_[i - 1]) { | 25 switch (closers_[i - 1]) { |
| 23 case CLIP_RECT: | 26 case CLIP_RECT: |
| 24 context_.list_->CreateAndAppendItem<cc::EndClipDisplayItem>(); | 27 context_.list_->CreateAndAppendItem<cc::EndClipDisplayItem>( |
| 28 bounds_in_layer_); |
| 25 break; | 29 break; |
| 26 case CLIP_PATH: | 30 case CLIP_PATH: |
| 27 context_.list_->CreateAndAppendItem<cc::EndClipPathDisplayItem>(); | 31 context_.list_->CreateAndAppendItem<cc::EndClipPathDisplayItem>( |
| 32 bounds_in_layer_); |
| 28 break; | 33 break; |
| 29 } | 34 } |
| 30 } | 35 } |
| 31 } | 36 } |
| 32 | 37 |
| 33 void ClipRecorder::ClipRect(const gfx::Rect& clip_rect) { | 38 void ClipRecorder::ClipRect(const gfx::Rect& clip_rect) { |
| 34 auto* item = context_.list_->CreateAndAppendItem<cc::ClipDisplayItem>(); | 39 gfx::Rect clip_in_layer_space = context_.ToLayerSpaceRect(clip_rect); |
| 40 auto* item = context_.list_->CreateAndAppendItem<cc::ClipDisplayItem>( |
| 41 clip_in_layer_space); |
| 35 item->SetNew(clip_rect, std::vector<SkRRect>()); | 42 item->SetNew(clip_rect, std::vector<SkRRect>()); |
| 36 DCHECK_LT(num_closers_, arraysize(closers_)); | 43 DCHECK_LT(num_closers_, arraysize(closers_)); |
| 37 closers_[num_closers_++] = CLIP_RECT; | 44 closers_[num_closers_++] = CLIP_RECT; |
| 38 } | 45 } |
| 39 | 46 |
| 40 void ClipRecorder::ClipPath(const gfx::Path& clip_path) { | 47 void ClipRecorder::ClipPath(const gfx::Path& clip_path) { |
| 41 bool anti_alias = false; | 48 bool anti_alias = false; |
| 42 auto* item = context_.list_->CreateAndAppendItem<cc::ClipPathDisplayItem>(); | 49 // As a further optimization, consider passing a more granular visual rect. |
| 50 auto* item = context_.list_->CreateAndAppendItem<cc::ClipPathDisplayItem>( |
| 51 bounds_in_layer_); |
| 43 item->SetNew(clip_path, SkRegion::kIntersect_Op, anti_alias); | 52 item->SetNew(clip_path, SkRegion::kIntersect_Op, anti_alias); |
| 44 DCHECK_LT(num_closers_, arraysize(closers_)); | 53 DCHECK_LT(num_closers_, arraysize(closers_)); |
| 45 closers_[num_closers_++] = CLIP_PATH; | 54 closers_[num_closers_++] = CLIP_PATH; |
| 46 } | 55 } |
| 47 | 56 |
| 48 void ClipRecorder::ClipPathWithAntiAliasing( | 57 void ClipRecorder::ClipPathWithAntiAliasing( |
| 49 const gfx::Path& clip_path) { | 58 const gfx::Path& clip_path) { |
| 50 bool anti_alias = true; | 59 bool anti_alias = true; |
| 51 auto* item = context_.list_->CreateAndAppendItem<cc::ClipPathDisplayItem>(); | 60 // As a further optimization, consider passing a more granular visual rect. |
| 61 auto* item = context_.list_->CreateAndAppendItem<cc::ClipPathDisplayItem>( |
| 62 bounds_in_layer_); |
| 52 item->SetNew(clip_path, SkRegion::kIntersect_Op, anti_alias); | 63 item->SetNew(clip_path, SkRegion::kIntersect_Op, anti_alias); |
| 53 DCHECK_LT(num_closers_, arraysize(closers_)); | 64 DCHECK_LT(num_closers_, arraysize(closers_)); |
| 54 closers_[num_closers_++] = CLIP_PATH; | 65 closers_[num_closers_++] = CLIP_PATH; |
| 55 } | 66 } |
| 56 | 67 |
| 57 } // namespace ui | 68 } // namespace ui |
| OLD | NEW |