Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: cc/layers/surface_layer.cc

Issue 2616403003: Replacing SurfaceReferenceBase and SequenceSurfaceReference with Closures (Closed)
Patch Set: c Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/surface_layer.h ('k') | cc/surfaces/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
12 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
13 #include "cc/layers/surface_layer_impl.h" 12 #include "cc/layers/surface_layer_impl.h"
14 #include "cc/output/swap_promise.h" 13 #include "cc/output/swap_promise.h"
15 #include "cc/surfaces/surface_sequence_generator.h" 14 #include "cc/surfaces/surface_sequence_generator.h"
16 #include "cc/trees/layer_tree_host.h" 15 #include "cc/trees/layer_tree_host.h"
17 #include "cc/trees/swap_promise_manager.h" 16 #include "cc/trees/swap_promise_manager.h"
17 #include "cc/trees/task_runner_provider.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 RemoveCurrentReference(); 66 RemoveCurrentReference();
67 surface_info_ = surface_info; 67 surface_info_ = surface_info;
68 if (layer_tree_host()) { 68 if (layer_tree_host()) {
69 current_ref_ = 69 reference_returner_ =
70 ref_factory_->CreateReference(layer_tree_host(), surface_info_.id()); 70 ref_factory_->CreateReference(layer_tree_host(), surface_info_.id());
71 } 71 }
72 UpdateDrawsContent(HasDrawableContent()); 72 UpdateDrawsContent(HasDrawableContent());
73 SetNeedsPushProperties(); 73 SetNeedsPushProperties();
74 } 74 }
75 75
76 void SurfaceLayer::SetStretchContentToFillBounds( 76 void SurfaceLayer::SetStretchContentToFillBounds(
77 bool stretch_content_to_fill_bounds) { 77 bool stretch_content_to_fill_bounds) {
78 stretch_content_to_fill_bounds_ = stretch_content_to_fill_bounds; 78 stretch_content_to_fill_bounds_ = stretch_content_to_fill_bounds;
79 SetNeedsPushProperties(); 79 SetNeedsPushProperties();
80 } 80 }
81 81
82 std::unique_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl( 82 std::unique_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl(
83 LayerTreeImpl* tree_impl) { 83 LayerTreeImpl* tree_impl) {
84 return SurfaceLayerImpl::Create(tree_impl, id()); 84 return SurfaceLayerImpl::Create(tree_impl, id());
85 } 85 }
86 86
87 bool SurfaceLayer::HasDrawableContent() const { 87 bool SurfaceLayer::HasDrawableContent() const {
88 return surface_info_.id().is_valid() && Layer::HasDrawableContent(); 88 return surface_info_.id().is_valid() && Layer::HasDrawableContent();
89 } 89 }
90 90
91 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) { 91 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) {
92 if (layer_tree_host() == host) { 92 if (layer_tree_host() == host) {
93 Layer::SetLayerTreeHost(host); 93 Layer::SetLayerTreeHost(host);
94 return; 94 return;
95 } 95 }
96 RemoveCurrentReference(); 96 RemoveCurrentReference();
97 Layer::SetLayerTreeHost(host); 97 Layer::SetLayerTreeHost(host);
98 if (layer_tree_host()) { 98 if (layer_tree_host()) {
99 current_ref_ = 99 reference_returner_ =
100 ref_factory_->CreateReference(layer_tree_host(), surface_info_.id()); 100 ref_factory_->CreateReference(layer_tree_host(), surface_info_.id());
101 } 101 }
102 } 102 }
103 103
104 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) { 104 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) {
105 Layer::PushPropertiesTo(layer); 105 Layer::PushPropertiesTo(layer);
106 TRACE_EVENT0("cc", "SurfaceLayer::PushPropertiesTo"); 106 TRACE_EVENT0("cc", "SurfaceLayer::PushPropertiesTo");
107 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); 107 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer);
108 layer_impl->SetSurfaceInfo(surface_info_); 108 layer_impl->SetSurfaceInfo(surface_info_);
109 layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_); 109 layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_);
110 } 110 }
111 111
112 void SurfaceLayer::RemoveCurrentReference() { 112 void SurfaceLayer::RemoveCurrentReference() {
113 if (!current_ref_) 113 if (!reference_returner_)
114 return; 114 return;
115 auto swap_promise = base::MakeUnique<SatisfySwapPromise>( 115 auto swap_promise = base::MakeUnique<SatisfySwapPromise>(
116 std::move(current_ref_), base::ThreadTaskRunnerHandle::Get()); 116 std::move(reference_returner_),
117 layer_tree_host()->GetTaskRunnerProvider()->MainThreadTaskRunner());
117 layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise( 118 layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise(
118 std::move(swap_promise)); 119 std::move(swap_promise));
119 } 120 }
120 121
121 } // namespace cc 122 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/surface_layer.h ('k') | cc/surfaces/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698