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

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

Issue 2905533002: cc : Store surface layer ids on LayerTreeHost and push them at commit (Closed)
Patch Set: comments Created 3 years, 7 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
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"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 } 57 }
58 58
59 SurfaceLayer::SurfaceLayer(scoped_refptr<SurfaceReferenceFactory> ref_factory) 59 SurfaceLayer::SurfaceLayer(scoped_refptr<SurfaceReferenceFactory> ref_factory)
60 : ref_factory_(std::move(ref_factory)) {} 60 : ref_factory_(std::move(ref_factory)) {}
61 61
62 SurfaceLayer::~SurfaceLayer() { 62 SurfaceLayer::~SurfaceLayer() {
63 DCHECK(!layer_tree_host()); 63 DCHECK(!layer_tree_host());
64 } 64 }
65 65
66 void SurfaceLayer::SetPrimarySurfaceInfo(const SurfaceInfo& surface_info) { 66 void SurfaceLayer::SetPrimarySurfaceInfo(const SurfaceInfo& surface_info) {
67 const SurfaceId* old_surface_id = GetReferencedSurfaceId();
67 RemoveReference(std::move(primary_reference_returner_)); 68 RemoveReference(std::move(primary_reference_returner_));
68 primary_surface_info_ = surface_info; 69 primary_surface_info_ = surface_info;
69 if (layer_tree_host()) { 70 if (layer_tree_host()) {
70 primary_reference_returner_ = ref_factory_->CreateReference( 71 primary_reference_returner_ = ref_factory_->CreateReference(
71 layer_tree_host(), primary_surface_info_.id()); 72 layer_tree_host(), primary_surface_info_.id());
73 const SurfaceId* new_surface_id = GetReferencedSurfaceId();
74 if (old_surface_id != new_surface_id) {
75 if (old_surface_id)
76 layer_tree_host()->RemoveSurfaceLayerId(*old_surface_id);
77 if (new_surface_id)
78 layer_tree_host()->AddSurfaceLayerId(*new_surface_id);
79 }
72 } 80 }
73 UpdateDrawsContent(HasDrawableContent()); 81 UpdateDrawsContent(HasDrawableContent());
74 SetNeedsCommit(); 82 SetNeedsCommit();
75 } 83 }
76 84
77 void SurfaceLayer::SetFallbackSurfaceInfo(const SurfaceInfo& surface_info) { 85 void SurfaceLayer::SetFallbackSurfaceInfo(const SurfaceInfo& surface_info) {
86 const SurfaceId* old_surface_id = GetReferencedSurfaceId();
78 RemoveReference(std::move(fallback_reference_returner_)); 87 RemoveReference(std::move(fallback_reference_returner_));
79 fallback_surface_info_ = surface_info; 88 fallback_surface_info_ = surface_info;
80 if (layer_tree_host()) { 89 if (layer_tree_host()) {
81 fallback_reference_returner_ = ref_factory_->CreateReference( 90 fallback_reference_returner_ = ref_factory_->CreateReference(
82 layer_tree_host(), fallback_surface_info_.id()); 91 layer_tree_host(), fallback_surface_info_.id());
92 const SurfaceId* new_surface_id = GetReferencedSurfaceId();
93 if (old_surface_id != new_surface_id) {
94 if (old_surface_id)
95 layer_tree_host()->RemoveSurfaceLayerId(*old_surface_id);
96 if (new_surface_id)
97 layer_tree_host()->AddSurfaceLayerId(*new_surface_id);
98 }
83 } 99 }
84 SetNeedsCommit(); 100 SetNeedsCommit();
85 } 101 }
86 102
87 void SurfaceLayer::SetStretchContentToFillBounds( 103 void SurfaceLayer::SetStretchContentToFillBounds(
88 bool stretch_content_to_fill_bounds) { 104 bool stretch_content_to_fill_bounds) {
89 stretch_content_to_fill_bounds_ = stretch_content_to_fill_bounds; 105 stretch_content_to_fill_bounds_ = stretch_content_to_fill_bounds;
90 SetNeedsPushProperties(); 106 SetNeedsPushProperties();
91 } 107 }
92 108
93 std::unique_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl( 109 std::unique_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl(
94 LayerTreeImpl* tree_impl) { 110 LayerTreeImpl* tree_impl) {
95 return SurfaceLayerImpl::Create(tree_impl, id()); 111 return SurfaceLayerImpl::Create(tree_impl, id());
96 } 112 }
97 113
98 bool SurfaceLayer::HasDrawableContent() const { 114 bool SurfaceLayer::HasDrawableContent() const {
99 return primary_surface_info_.is_valid() && Layer::HasDrawableContent(); 115 return primary_surface_info_.is_valid() && Layer::HasDrawableContent();
100 } 116 }
101 117
118 const SurfaceId* SurfaceLayer::GetReferencedSurfaceId(LayerTreeHost* new_host) {
enne (OOO) 2017/05/24 18:44:54 This is a lot of logic in SurfaceLayer to try to a
jaydasika 2017/05/24 21:39:54 Done (sending all primary and fallback surface ids
Fady Samuel 2017/05/24 22:46:24 I meant to reply here:
jaydasika 2017/05/25 18:00:28 Ok. I have changed the CL again to record only one
119 LayerTreeHost* old_host = layer_tree_host();
120 if (!old_host && !new_host)
121 return nullptr;
122 DCHECK(!old_host || !new_host ||
123 old_host->GetSettings().enable_surface_synchronization ==
124 old_host->GetSettings().enable_surface_synchronization);
125
126 bool enable_surface_synchronization;
127 if (old_host) {
128 enable_surface_synchronization =
129 old_host->GetSettings().enable_surface_synchronization;
130 } else {
131 enable_surface_synchronization =
132 new_host->GetSettings().enable_surface_synchronization;
133 }
134
135 if (enable_surface_synchronization) {
136 if (fallback_surface_info_.is_valid())
137 return &fallback_surface_info_.id();
138 } else if (primary_surface_info_.is_valid()) {
139 return &primary_surface_info_.id();
140 }
141 return nullptr;
142 }
143
102 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) { 144 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) {
103 if (layer_tree_host() == host) { 145 if (layer_tree_host() == host) {
104 Layer::SetLayerTreeHost(host); 146 Layer::SetLayerTreeHost(host);
105 return; 147 return;
106 } 148 }
149 const SurfaceId* surface_id = GetReferencedSurfaceId(host);
150
151 if (layer_tree_host() && surface_id)
152 layer_tree_host()->RemoveSurfaceLayerId(*surface_id);
107 RemoveReference(std::move(primary_reference_returner_)); 153 RemoveReference(std::move(primary_reference_returner_));
108 RemoveReference(std::move(fallback_reference_returner_)); 154 RemoveReference(std::move(fallback_reference_returner_));
109 Layer::SetLayerTreeHost(host); 155 Layer::SetLayerTreeHost(host);
110 if (layer_tree_host()) { 156 if (layer_tree_host()) {
111 if (primary_surface_info_.is_valid()) { 157 if (primary_surface_info_.is_valid()) {
112 primary_reference_returner_ = ref_factory_->CreateReference( 158 primary_reference_returner_ = ref_factory_->CreateReference(
113 layer_tree_host(), primary_surface_info_.id()); 159 layer_tree_host(), primary_surface_info_.id());
114 } 160 }
115 if (fallback_surface_info_.is_valid()) { 161 if (fallback_surface_info_.is_valid()) {
116 fallback_reference_returner_ = ref_factory_->CreateReference( 162 fallback_reference_returner_ = ref_factory_->CreateReference(
117 layer_tree_host(), fallback_surface_info_.id()); 163 layer_tree_host(), fallback_surface_info_.id());
118 } 164 }
165 if (surface_id)
166 layer_tree_host()->AddSurfaceLayerId(*surface_id);
119 } 167 }
120 } 168 }
121 169
122 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) { 170 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) {
123 Layer::PushPropertiesTo(layer); 171 Layer::PushPropertiesTo(layer);
124 TRACE_EVENT0("cc", "SurfaceLayer::PushPropertiesTo"); 172 TRACE_EVENT0("cc", "SurfaceLayer::PushPropertiesTo");
125 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); 173 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer);
126 layer_impl->SetPrimarySurfaceInfo(primary_surface_info_); 174 layer_impl->SetPrimarySurfaceInfo(primary_surface_info_);
127 layer_impl->SetFallbackSurfaceInfo(fallback_surface_info_); 175 layer_impl->SetFallbackSurfaceInfo(fallback_surface_info_);
128 layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_); 176 layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_);
129 } 177 }
130 178
131 void SurfaceLayer::RemoveReference(base::Closure reference_returner) { 179 void SurfaceLayer::RemoveReference(base::Closure reference_returner) {
132 if (!reference_returner) 180 if (!reference_returner)
133 return; 181 return;
134 auto swap_promise = base::MakeUnique<SatisfySwapPromise>( 182 auto swap_promise = base::MakeUnique<SatisfySwapPromise>(
135 std::move(reference_returner), 183 std::move(reference_returner),
136 layer_tree_host()->GetTaskRunnerProvider()->MainThreadTaskRunner()); 184 layer_tree_host()->GetTaskRunnerProvider()->MainThreadTaskRunner());
137 layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise( 185 layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise(
138 std::move(swap_promise)); 186 std::move(swap_promise));
139 } 187 }
140 188
141 } // namespace cc 189 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698