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/layers/surface_layer.h" | 5 #include "cc/layers/surface_layer.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
13 #include "cc/layers/surface_layer_impl.h" | 13 #include "cc/layers/surface_layer_impl.h" |
14 #include "cc/output/swap_promise.h" | 14 #include "cc/output/swap_promise.h" |
15 #include "cc/surfaces/surface_sequence_generator.h" | 15 #include "cc/surfaces/surface_sequence_generator.h" |
16 #include "cc/trees/layer_tree_host.h" | 16 #include "cc/trees/layer_tree_host.h" |
17 #include "cc/trees/swap_promise_manager.h" | 17 #include "cc/trees/swap_promise_manager.h" |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 | 20 |
21 class SatisfySwapPromise : public SwapPromise { | 21 class SatisfySwapPromise : public SwapPromise { |
22 public: | 22 public: |
23 SatisfySwapPromise( | 23 SatisfySwapPromise( |
24 std::unique_ptr<SurfaceReferenceBase> surface_ref, | 24 base::Closure reference_returner, |
25 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) | 25 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner) |
26 : surface_ref_(std::move(surface_ref)), | 26 : reference_returner_(reference_returner), |
27 main_task_runner_(std::move(main_task_runner)) {} | 27 main_task_runner_(std::move(main_task_runner)) {} |
28 | 28 |
29 ~SatisfySwapPromise() override {} | 29 ~SatisfySwapPromise() override {} |
30 | 30 |
31 private: | 31 private: |
32 void DidActivate() override {} | 32 void DidActivate() override {} |
33 | 33 |
34 void WillSwap(CompositorFrameMetadata* metadata) override {} | 34 void WillSwap(CompositorFrameMetadata* metadata) override {} |
35 | 35 |
36 void DidSwap() override { | 36 void DidSwap() override { |
37 main_task_runner_->DeleteSoon(FROM_HERE, surface_ref_.release()); | 37 main_task_runner_->PostTask(FROM_HERE, reference_returner_); |
38 } | 38 } |
39 | 39 |
40 DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override { | 40 DidNotSwapAction DidNotSwap(DidNotSwapReason reason) override { |
41 main_task_runner_->DeleteSoon(FROM_HERE, surface_ref_.release()); | 41 main_task_runner_->PostTask(FROM_HERE, reference_returner_); |
42 return DidNotSwapAction::BREAK_PROMISE; | 42 return DidNotSwapAction::BREAK_PROMISE; |
43 } | 43 } |
44 | 44 |
45 int64_t TraceId() const override { return 0; } | 45 int64_t TraceId() const override { return 0; } |
46 | 46 |
47 std::unique_ptr<SurfaceReferenceBase> surface_ref_; | 47 base::Closure reference_returner_; |
48 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 48 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
49 | 49 |
50 DISALLOW_COPY_AND_ASSIGN(SatisfySwapPromise); | 50 DISALLOW_COPY_AND_ASSIGN(SatisfySwapPromise); |
51 }; | 51 }; |
52 | 52 |
53 scoped_refptr<SurfaceLayer> SurfaceLayer::Create( | 53 scoped_refptr<SurfaceLayer> SurfaceLayer::Create( |
54 scoped_refptr<SurfaceReferenceFactory> ref_factory) { | 54 scoped_refptr<SurfaceReferenceFactory> ref_factory) { |
55 return make_scoped_refptr(new SurfaceLayer(std::move(ref_factory))); | 55 return make_scoped_refptr(new SurfaceLayer(std::move(ref_factory))); |
56 } | 56 } |
57 | 57 |
58 SurfaceLayer::SurfaceLayer(scoped_refptr<SurfaceReferenceFactory> ref_factory) | 58 SurfaceLayer::SurfaceLayer(scoped_refptr<SurfaceReferenceFactory> ref_factory) |
59 : ref_factory_(std::move(ref_factory)) {} | 59 : ref_factory_(std::move(ref_factory)) {} |
60 | 60 |
61 SurfaceLayer::~SurfaceLayer() { | 61 SurfaceLayer::~SurfaceLayer() { |
62 DCHECK(!layer_tree_host()); | 62 DCHECK(!layer_tree_host()); |
63 } | 63 } |
64 | 64 |
65 void SurfaceLayer::SetSurfaceInfo(const SurfaceInfo& surface_info, | 65 void SurfaceLayer::SetSurfaceInfo(const SurfaceInfo& surface_info, |
66 bool stretch_content_to_fill_bounds) { | 66 bool stretch_content_to_fill_bounds) { |
67 RemoveCurrentReference(); | 67 RemoveCurrentReference(); |
68 surface_info_ = surface_info; | 68 surface_info_ = surface_info; |
69 if (layer_tree_host()) { | 69 if (layer_tree_host()) { |
70 current_ref_ = | 70 reference_returner_ = |
71 ref_factory_->CreateReference(layer_tree_host(), surface_info_.id()); | 71 ref_factory_->CreateReference(layer_tree_host(), surface_info_.id()); |
72 } | 72 } |
73 stretch_content_to_fill_bounds_ = stretch_content_to_fill_bounds; | 73 stretch_content_to_fill_bounds_ = stretch_content_to_fill_bounds; |
74 UpdateDrawsContent(HasDrawableContent()); | 74 UpdateDrawsContent(HasDrawableContent()); |
75 SetNeedsPushProperties(); | 75 SetNeedsPushProperties(); |
76 } | 76 } |
77 | 77 |
78 std::unique_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl( | 78 std::unique_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl( |
79 LayerTreeImpl* tree_impl) { | 79 LayerTreeImpl* tree_impl) { |
80 return SurfaceLayerImpl::Create(tree_impl, id()); | 80 return SurfaceLayerImpl::Create(tree_impl, id()); |
81 } | 81 } |
82 | 82 |
83 bool SurfaceLayer::HasDrawableContent() const { | 83 bool SurfaceLayer::HasDrawableContent() const { |
84 return surface_info_.id().is_valid() && Layer::HasDrawableContent(); | 84 return surface_info_.id().is_valid() && Layer::HasDrawableContent(); |
85 } | 85 } |
86 | 86 |
87 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) { | 87 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) { |
88 if (layer_tree_host() == host) { | 88 if (layer_tree_host() == host) { |
89 Layer::SetLayerTreeHost(host); | 89 Layer::SetLayerTreeHost(host); |
90 return; | 90 return; |
91 } | 91 } |
92 RemoveCurrentReference(); | 92 RemoveCurrentReference(); |
93 Layer::SetLayerTreeHost(host); | 93 Layer::SetLayerTreeHost(host); |
94 if (layer_tree_host()) { | 94 if (layer_tree_host()) { |
95 current_ref_ = | 95 reference_returner_ = |
96 ref_factory_->CreateReference(layer_tree_host(), surface_info_.id()); | 96 ref_factory_->CreateReference(layer_tree_host(), surface_info_.id()); |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) { | 100 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) { |
101 Layer::PushPropertiesTo(layer); | 101 Layer::PushPropertiesTo(layer); |
102 TRACE_EVENT0("cc", "SurfaceLayer::PushPropertiesTo"); | 102 TRACE_EVENT0("cc", "SurfaceLayer::PushPropertiesTo"); |
103 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); | 103 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); |
104 layer_impl->SetSurfaceInfo(surface_info_); | 104 layer_impl->SetSurfaceInfo(surface_info_); |
105 layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_); | 105 layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_); |
106 } | 106 } |
107 | 107 |
108 void SurfaceLayer::RemoveCurrentReference() { | 108 void SurfaceLayer::RemoveCurrentReference() { |
109 if (!current_ref_) | 109 if (!reference_returner_) |
110 return; | 110 return; |
111 auto swap_promise = base::MakeUnique<SatisfySwapPromise>( | 111 auto swap_promise = base::MakeUnique<SatisfySwapPromise>( |
112 std::move(current_ref_), base::ThreadTaskRunnerHandle::Get()); | 112 std::move(reference_returner_), base::ThreadTaskRunnerHandle::Get()); |
danakj
2017/01/10 21:12:06
Just noticed, but this code should not use ThreadT
Fady Samuel
2017/01/10 21:33:07
LayerTreeHostImpl::task_runner_provider()->MainThr
Saman Sami
2017/01/10 21:56:14
Done.
| |
113 layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise( | 113 layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise( |
114 std::move(swap_promise)); | 114 std::move(swap_promise)); |
115 } | 115 } |
116 | 116 |
117 } // namespace cc | 117 } // namespace cc |
OLD | NEW |