OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "cc/blink/web_layer_impl.h" | 5 #include "cc/blink/web_layer_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
14 #include "base/trace_event/trace_event_impl.h" | 14 #include "base/trace_event/trace_event_impl.h" |
15 #include "cc/animation/animation.h" | 15 #include "cc/animation/animation.h" |
16 #include "cc/base/region.h" | 16 #include "cc/base/region.h" |
17 #include "cc/base/switches.h" | 17 #include "cc/base/switches.h" |
18 #include "cc/blink/web_animation_impl.h" | 18 #include "cc/blink/web_animation_impl.h" |
19 #include "cc/blink/web_blend_mode.h" | 19 #include "cc/blink/web_blend_mode.h" |
20 #include "cc/blink/web_filter_operations_impl.h" | 20 #include "cc/blink/web_filter_operations_impl.h" |
21 #include "cc/blink/web_to_cc_animation_delegate_adapter.h" | 21 #include "cc/blink/web_to_cc_animation_delegate_adapter.h" |
22 #include "cc/layers/layer.h" | 22 #include "cc/layers/layer.h" |
23 #include "cc/layers/layer_position_constraint.h" | 23 #include "cc/layers/layer_position_constraint.h" |
24 #include "cc/layers/layer_settings.h" | 24 #include "cc/layers/layer_settings.h" |
25 #include "cc/trees/layer_tree_host.h" | 25 #include "cc/trees/layer_tree_host.h" |
26 #include "third_party/WebKit/public/platform/WebFloatPoint.h" | 26 #include "third_party/WebKit/public/platform/WebFloatPoint.h" |
27 #include "third_party/WebKit/public/platform/WebFloatRect.h" | 27 #include "third_party/WebKit/public/platform/WebFloatRect.h" |
| 28 #include "third_party/WebKit/public/platform/WebGraphicsLayerDebugInfo.h" |
| 29 #include "third_party/WebKit/public/platform/WebLayerClient.h" |
28 #include "third_party/WebKit/public/platform/WebLayerPositionConstraint.h" | 30 #include "third_party/WebKit/public/platform/WebLayerPositionConstraint.h" |
29 #include "third_party/WebKit/public/platform/WebLayerScrollClient.h" | 31 #include "third_party/WebKit/public/platform/WebLayerScrollClient.h" |
30 #include "third_party/WebKit/public/platform/WebSize.h" | 32 #include "third_party/WebKit/public/platform/WebSize.h" |
31 #include "third_party/skia/include/utils/SkMatrix44.h" | 33 #include "third_party/skia/include/utils/SkMatrix44.h" |
32 #include "ui/gfx/geometry/rect_conversions.h" | 34 #include "ui/gfx/geometry/rect_conversions.h" |
33 #include "ui/gfx/geometry/vector2d_conversions.h" | 35 #include "ui/gfx/geometry/vector2d_conversions.h" |
34 | 36 |
35 using cc::Animation; | 37 using cc::Animation; |
36 using cc::Layer; | 38 using cc::Layer; |
37 using blink::WebLayer; | 39 using blink::WebLayer; |
38 using blink::WebFloatPoint; | 40 using blink::WebFloatPoint; |
39 using blink::WebVector; | 41 using blink::WebVector; |
40 using blink::WebRect; | 42 using blink::WebRect; |
41 using blink::WebSize; | 43 using blink::WebSize; |
42 using blink::WebColor; | 44 using blink::WebColor; |
43 using blink::WebFilterOperations; | 45 using blink::WebFilterOperations; |
44 | 46 |
45 namespace cc_blink { | 47 namespace cc_blink { |
46 namespace { | 48 namespace { |
47 | 49 |
48 base::LazyInstance<cc::LayerSettings> g_layer_settings = | 50 base::LazyInstance<cc::LayerSettings> g_layer_settings = |
49 LAZY_INSTANCE_INITIALIZER; | 51 LAZY_INSTANCE_INITIALIZER; |
50 | 52 |
51 } // namespace | 53 } // namespace |
52 | 54 |
53 WebLayerImpl::WebLayerImpl() | 55 WebLayerImpl::WebLayerImpl() |
54 : layer_(Layer::Create(LayerSettings())), contents_opaque_is_fixed_(false) { | 56 : layer_(Layer::Create(LayerSettings())), contents_opaque_is_fixed_(false) { |
| 57 web_layer_client_ = nullptr; |
| 58 layer_->SetLayerClient(this); |
55 } | 59 } |
56 | 60 |
57 WebLayerImpl::WebLayerImpl(scoped_refptr<Layer> layer) | 61 WebLayerImpl::WebLayerImpl(scoped_refptr<Layer> layer) |
58 : layer_(layer), contents_opaque_is_fixed_(false) { | 62 : layer_(layer), contents_opaque_is_fixed_(false) { |
| 63 web_layer_client_ = nullptr; |
| 64 layer_->SetLayerClient(this); |
59 } | 65 } |
60 | 66 |
61 WebLayerImpl::~WebLayerImpl() { | 67 WebLayerImpl::~WebLayerImpl() { |
62 if (animation_delegate_adapter_.get()) | 68 if (animation_delegate_adapter_.get()) |
63 layer_->set_layer_animation_delegate(nullptr); | 69 layer_->set_layer_animation_delegate(nullptr); |
| 70 web_layer_client_ = nullptr; |
64 layer_->SetLayerClient(nullptr); | 71 layer_->SetLayerClient(nullptr); |
65 } | 72 } |
66 | 73 |
67 // static | 74 // static |
68 void WebLayerImpl::SetLayerSettings(const cc::LayerSettings& settings) { | 75 void WebLayerImpl::SetLayerSettings(const cc::LayerSettings& settings) { |
69 g_layer_settings.Get() = settings; | 76 g_layer_settings.Get() = settings; |
70 } | 77 } |
71 | 78 |
72 // static | 79 // static |
73 const cc::LayerSettings& WebLayerImpl::LayerSettings() { | 80 const cc::LayerSettings& WebLayerImpl::LayerSettings() { |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 base::Unretained(scroll_client))); | 486 base::Unretained(scroll_client))); |
480 } else { | 487 } else { |
481 layer_->set_did_scroll_callback(base::Closure()); | 488 layer_->set_did_scroll_callback(base::Closure()); |
482 } | 489 } |
483 } | 490 } |
484 | 491 |
485 bool WebLayerImpl::isOrphan() const { | 492 bool WebLayerImpl::isOrphan() const { |
486 return !layer_->layer_tree_host(); | 493 return !layer_->layer_tree_host(); |
487 } | 494 } |
488 | 495 |
489 void WebLayerImpl::setLayerClient(cc::LayerClient* client) { | 496 void WebLayerImpl::setWebLayerClient(blink::WebLayerClient* client) { |
490 layer_->SetLayerClient(client); | 497 web_layer_client_ = client; |
491 } | 498 } |
492 | 499 |
493 const cc::Layer* WebLayerImpl::ccLayer() const { | 500 class TracedDebugInfo : public base::trace_event::ConvertableToTraceFormat { |
494 return layer_.get(); | 501 public: |
| 502 // This object takes ownership of the debug_info object. |
| 503 explicit TracedDebugInfo(blink::WebGraphicsLayerDebugInfo* debug_info) |
| 504 : debug_info_(debug_info) {} |
| 505 void AppendAsTraceFormat(std::string* out) const override { |
| 506 DCHECK(thread_checker_.CalledOnValidThread()); |
| 507 blink::WebString web_string; |
| 508 debug_info_->appendAsTraceFormat(&web_string); |
| 509 out->append(web_string.utf8()); |
| 510 } |
| 511 |
| 512 private: |
| 513 ~TracedDebugInfo() override {} |
| 514 scoped_ptr<blink::WebGraphicsLayerDebugInfo> debug_info_; |
| 515 base::ThreadChecker thread_checker_; |
| 516 }; |
| 517 |
| 518 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
| 519 WebLayerImpl::TakeDebugInfo() { |
| 520 if (!web_layer_client_) |
| 521 return nullptr; |
| 522 blink::WebGraphicsLayerDebugInfo* debug_info = |
| 523 web_layer_client_->takeDebugInfoFor(this); |
| 524 |
| 525 if (debug_info) |
| 526 return new TracedDebugInfo(debug_info); |
| 527 else |
| 528 return nullptr; |
495 } | 529 } |
496 | 530 |
497 void WebLayerImpl::setScrollParent(blink::WebLayer* parent) { | 531 void WebLayerImpl::setScrollParent(blink::WebLayer* parent) { |
498 cc::Layer* scroll_parent = nullptr; | 532 cc::Layer* scroll_parent = nullptr; |
499 if (parent) | 533 if (parent) |
500 scroll_parent = static_cast<WebLayerImpl*>(parent)->layer(); | 534 scroll_parent = static_cast<WebLayerImpl*>(parent)->layer(); |
501 layer_->SetScrollParent(scroll_parent); | 535 layer_->SetScrollParent(scroll_parent); |
502 } | 536 } |
503 | 537 |
504 void WebLayerImpl::setClipParent(blink::WebLayer* parent) { | 538 void WebLayerImpl::setClipParent(blink::WebLayer* parent) { |
505 cc::Layer* clip_parent = nullptr; | 539 cc::Layer* clip_parent = nullptr; |
506 if (parent) | 540 if (parent) |
507 clip_parent = static_cast<WebLayerImpl*>(parent)->layer(); | 541 clip_parent = static_cast<WebLayerImpl*>(parent)->layer(); |
508 layer_->SetClipParent(clip_parent); | 542 layer_->SetClipParent(clip_parent); |
509 } | 543 } |
510 | 544 |
511 Layer* WebLayerImpl::layer() const { | 545 Layer* WebLayerImpl::layer() const { |
512 return layer_.get(); | 546 return layer_.get(); |
513 } | 547 } |
514 | 548 |
515 void WebLayerImpl::SetContentsOpaqueIsFixed(bool fixed) { | 549 void WebLayerImpl::SetContentsOpaqueIsFixed(bool fixed) { |
516 contents_opaque_is_fixed_ = fixed; | 550 contents_opaque_is_fixed_ = fixed; |
517 } | 551 } |
518 | 552 |
519 } // namespace cc_blink | 553 } // namespace cc_blink |
OLD | NEW |