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

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: initialize 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
« no previous file with comments | « cc/layers/surface_layer.h ('k') | cc/layers/surface_layer_impl.cc » ('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"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 return make_scoped_refptr(new SurfaceLayer(std::move(ref_factory))); 56 return make_scoped_refptr(new SurfaceLayer(std::move(ref_factory)));
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::AddReferencedSurfaceId(const SurfaceInfo& surface_info) {
67 DCHECK(layer_tree_host());
68 if (surface_info.is_valid())
69 layer_tree_host()->AddSurfaceLayerId(surface_info.id());
70 }
71
72 void SurfaceLayer::RemoveReferencedSurfaceId(const SurfaceInfo& surface_info) {
73 DCHECK(layer_tree_host());
74 if (surface_info.is_valid())
75 layer_tree_host()->RemoveSurfaceLayerId(surface_info.id());
76 }
77
66 void SurfaceLayer::SetPrimarySurfaceInfo(const SurfaceInfo& surface_info) { 78 void SurfaceLayer::SetPrimarySurfaceInfo(const SurfaceInfo& surface_info) {
67 RemoveReference(std::move(primary_reference_returner_)); 79 RemoveReference(std::move(primary_reference_returner_));
80 bool update_referenced_surface_id = false;
81 if (layer_tree_host())
82 update_referenced_surface_id =
83 !layer_tree_host()->GetSettings().enable_surface_synchronization;
84 if (update_referenced_surface_id)
85 RemoveReferencedSurfaceId(primary_surface_info_);
68 primary_surface_info_ = surface_info; 86 primary_surface_info_ = surface_info;
69 if (layer_tree_host()) { 87 if (layer_tree_host()) {
70 primary_reference_returner_ = ref_factory_->CreateReference( 88 primary_reference_returner_ = ref_factory_->CreateReference(
71 layer_tree_host(), primary_surface_info_.id()); 89 layer_tree_host(), primary_surface_info_.id());
90 if (update_referenced_surface_id)
91 AddReferencedSurfaceId(primary_surface_info_);
72 } 92 }
73 UpdateDrawsContent(HasDrawableContent()); 93 UpdateDrawsContent(HasDrawableContent());
74 SetNeedsCommit(); 94 SetNeedsCommit();
75 } 95 }
76 96
77 void SurfaceLayer::SetFallbackSurfaceInfo(const SurfaceInfo& surface_info) { 97 void SurfaceLayer::SetFallbackSurfaceInfo(const SurfaceInfo& surface_info) {
78 RemoveReference(std::move(fallback_reference_returner_)); 98 RemoveReference(std::move(fallback_reference_returner_));
99 bool update_referenced_surface_id = false;
100 if (layer_tree_host())
101 update_referenced_surface_id =
102 layer_tree_host()->GetSettings().enable_surface_synchronization;
103 if (update_referenced_surface_id)
104 RemoveReferencedSurfaceId(fallback_surface_info_);
79 fallback_surface_info_ = surface_info; 105 fallback_surface_info_ = surface_info;
80 if (layer_tree_host()) { 106 if (layer_tree_host()) {
81 fallback_reference_returner_ = ref_factory_->CreateReference( 107 fallback_reference_returner_ = ref_factory_->CreateReference(
82 layer_tree_host(), fallback_surface_info_.id()); 108 layer_tree_host(), fallback_surface_info_.id());
109 if (update_referenced_surface_id)
110 AddReferencedSurfaceId(fallback_surface_info_);
83 } 111 }
84 SetNeedsCommit(); 112 SetNeedsCommit();
85 } 113 }
86 114
87 void SurfaceLayer::SetStretchContentToFillBounds( 115 void SurfaceLayer::SetStretchContentToFillBounds(
88 bool stretch_content_to_fill_bounds) { 116 bool stretch_content_to_fill_bounds) {
89 stretch_content_to_fill_bounds_ = stretch_content_to_fill_bounds; 117 stretch_content_to_fill_bounds_ = stretch_content_to_fill_bounds;
90 SetNeedsPushProperties(); 118 SetNeedsPushProperties();
91 } 119 }
92 120
93 std::unique_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl( 121 std::unique_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl(
94 LayerTreeImpl* tree_impl) { 122 LayerTreeImpl* tree_impl) {
95 return SurfaceLayerImpl::Create(tree_impl, id()); 123 return SurfaceLayerImpl::Create(tree_impl, id());
96 } 124 }
97 125
98 bool SurfaceLayer::HasDrawableContent() const { 126 bool SurfaceLayer::HasDrawableContent() const {
99 return primary_surface_info_.is_valid() && Layer::HasDrawableContent(); 127 return primary_surface_info_.is_valid() && Layer::HasDrawableContent();
100 } 128 }
101 129
102 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) { 130 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) {
103 if (layer_tree_host() == host) { 131 if (layer_tree_host() == host) {
104 Layer::SetLayerTreeHost(host);
105 return; 132 return;
106 } 133 }
134
135 bool use_primary_info_for_referenced_surface_id = false;
136 if (layer_tree_host()) {
137 use_primary_info_for_referenced_surface_id =
138 !layer_tree_host()->GetSettings().enable_surface_synchronization;
139 } else if (host) {
140 use_primary_info_for_referenced_surface_id =
141 !host->GetSettings().enable_surface_synchronization;
142 }
143
144 if (layer_tree_host()) {
145 if (use_primary_info_for_referenced_surface_id)
146 RemoveReferencedSurfaceId(primary_surface_info_);
147 else
148 RemoveReferencedSurfaceId(fallback_surface_info_);
149 }
150
107 RemoveReference(std::move(primary_reference_returner_)); 151 RemoveReference(std::move(primary_reference_returner_));
108 RemoveReference(std::move(fallback_reference_returner_)); 152 RemoveReference(std::move(fallback_reference_returner_));
109 Layer::SetLayerTreeHost(host); 153 Layer::SetLayerTreeHost(host);
154
110 if (layer_tree_host()) { 155 if (layer_tree_host()) {
111 if (primary_surface_info_.is_valid()) { 156 if (primary_surface_info_.is_valid()) {
112 primary_reference_returner_ = ref_factory_->CreateReference( 157 primary_reference_returner_ = ref_factory_->CreateReference(
113 layer_tree_host(), primary_surface_info_.id()); 158 layer_tree_host(), primary_surface_info_.id());
114 } 159 }
115 if (fallback_surface_info_.is_valid()) { 160 if (fallback_surface_info_.is_valid()) {
116 fallback_reference_returner_ = ref_factory_->CreateReference( 161 fallback_reference_returner_ = ref_factory_->CreateReference(
117 layer_tree_host(), fallback_surface_info_.id()); 162 layer_tree_host(), fallback_surface_info_.id());
118 } 163 }
164 if (use_primary_info_for_referenced_surface_id)
165 AddReferencedSurfaceId(primary_surface_info_);
166 else
167 AddReferencedSurfaceId(fallback_surface_info_);
119 } 168 }
120 } 169 }
121 170
122 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) { 171 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) {
123 Layer::PushPropertiesTo(layer); 172 Layer::PushPropertiesTo(layer);
124 TRACE_EVENT0("cc", "SurfaceLayer::PushPropertiesTo"); 173 TRACE_EVENT0("cc", "SurfaceLayer::PushPropertiesTo");
125 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); 174 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer);
126 layer_impl->SetPrimarySurfaceInfo(primary_surface_info_); 175 layer_impl->SetPrimarySurfaceInfo(primary_surface_info_);
127 layer_impl->SetFallbackSurfaceInfo(fallback_surface_info_); 176 layer_impl->SetFallbackSurfaceInfo(fallback_surface_info_);
128 layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_); 177 layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_);
129 } 178 }
130 179
131 void SurfaceLayer::RemoveReference(base::Closure reference_returner) { 180 void SurfaceLayer::RemoveReference(base::Closure reference_returner) {
132 if (!reference_returner) 181 if (!reference_returner)
133 return; 182 return;
134 auto swap_promise = base::MakeUnique<SatisfySwapPromise>( 183 auto swap_promise = base::MakeUnique<SatisfySwapPromise>(
135 std::move(reference_returner), 184 std::move(reference_returner),
136 layer_tree_host()->GetTaskRunnerProvider()->MainThreadTaskRunner()); 185 layer_tree_host()->GetTaskRunnerProvider()->MainThreadTaskRunner());
137 layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise( 186 layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise(
138 std::move(swap_promise)); 187 std::move(swap_promise));
139 } 188 }
140 189
141 } // namespace cc 190 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/surface_layer.h ('k') | cc/layers/surface_layer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698