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

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

Issue 2582823002: WIP: Surface Synchronization System
Patch Set: Only create ClientSurfaceEmbedder if window is visible. Trash it otherwise. 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
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 } 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 RemoveReference(std::move(primary_reference_returner_));
67 surface_info_ = surface_info; 67 primary_surface_info_ = surface_info;
68 if (layer_tree_host()) { 68 if (layer_tree_host()) {
69 reference_returner_ = 69 primary_reference_returner_ = ref_factory_->CreateReference(
70 ref_factory_->CreateReference(layer_tree_host(), surface_info_.id()); 70 layer_tree_host(), primary_surface_info_.id());
71 } 71 }
72 UpdateDrawsContent(HasDrawableContent()); 72 UpdateDrawsContent(HasDrawableContent());
73 SetNeedsPushProperties(); 73 SetNeedsPushProperties();
74 }
75
76 void SurfaceLayer::SwapSurfaceInfo(const SurfaceInfo& surface_info) {
77 if (surface_info.id() == primary_surface_info_.id()) {
78 // Remove the existing fallback reference.
79 primary_surface_info_ = surface_info;
80 RemoveReference(std::move(fallback_reference_returner_));
81 fallback_surface_info_ = SurfaceInfo();
82 UpdateDrawsContent(HasDrawableContent());
83 SetNeedsPushProperties();
84 return;
85 }
86 // Remove the existing fallback reference.
87 RemoveReference(std::move(fallback_reference_returner_));
88
89 // The primary SurfaceInfo becomes the fallback.
90 fallback_surface_info_ = primary_surface_info_;
91 fallback_reference_returner_ = std::move(primary_reference_returner_);
92
93 // The new |surface_info| becomes the primary SurfaceInfo.
94 primary_surface_info_ = surface_info;
95 if (layer_tree_host()) {
96 primary_reference_returner_ = ref_factory_->CreateReference(
97 layer_tree_host(), primary_surface_info_.id());
98 }
99 UpdateDrawsContent(HasDrawableContent());
100 SetNeedsPushProperties();
74 } 101 }
75 102
76 void SurfaceLayer::SetStretchContentToFillBounds( 103 void SurfaceLayer::SetStretchContentToFillBounds(
77 bool stretch_content_to_fill_bounds) { 104 bool stretch_content_to_fill_bounds) {
78 stretch_content_to_fill_bounds_ = stretch_content_to_fill_bounds; 105 stretch_content_to_fill_bounds_ = stretch_content_to_fill_bounds;
79 SetNeedsPushProperties(); 106 SetNeedsPushProperties();
80 } 107 }
81 108
82 std::unique_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl( 109 std::unique_ptr<LayerImpl> SurfaceLayer::CreateLayerImpl(
83 LayerTreeImpl* tree_impl) { 110 LayerTreeImpl* tree_impl) {
84 return SurfaceLayerImpl::Create(tree_impl, id()); 111 return SurfaceLayerImpl::Create(tree_impl, id());
85 } 112 }
86 113
87 bool SurfaceLayer::HasDrawableContent() const { 114 bool SurfaceLayer::HasDrawableContent() const {
88 return surface_info_.id().is_valid() && Layer::HasDrawableContent(); 115 return primary_surface_info_.id().is_valid() && Layer::HasDrawableContent();
89 } 116 }
90 117
91 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) { 118 void SurfaceLayer::SetLayerTreeHost(LayerTreeHost* host) {
92 if (layer_tree_host() == host) { 119 if (layer_tree_host() == host) {
93 Layer::SetLayerTreeHost(host); 120 Layer::SetLayerTreeHost(host);
94 return; 121 return;
95 } 122 }
96 RemoveCurrentReference(); 123 RemoveReference(std::move(primary_reference_returner_));
124 RemoveReference(std::move(fallback_reference_returner_));
97 Layer::SetLayerTreeHost(host); 125 Layer::SetLayerTreeHost(host);
98 if (layer_tree_host()) { 126 if (layer_tree_host()) {
99 reference_returner_ = 127 if (primary_surface_info_.id().is_valid()) {
100 ref_factory_->CreateReference(layer_tree_host(), surface_info_.id()); 128 primary_reference_returner_ = ref_factory_->CreateReference(
129 layer_tree_host(), primary_surface_info_.id());
130 }
131 if (fallback_surface_info_.id().is_valid()) {
132 fallback_reference_returner_ = ref_factory_->CreateReference(
133 layer_tree_host(), fallback_surface_info_.id());
134 }
101 } 135 }
102 } 136 }
103 137
104 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) { 138 void SurfaceLayer::PushPropertiesTo(LayerImpl* layer) {
105 Layer::PushPropertiesTo(layer); 139 Layer::PushPropertiesTo(layer);
106 TRACE_EVENT0("cc", "SurfaceLayer::PushPropertiesTo"); 140 TRACE_EVENT0("cc", "SurfaceLayer::PushPropertiesTo");
107 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer); 141 SurfaceLayerImpl* layer_impl = static_cast<SurfaceLayerImpl*>(layer);
108 layer_impl->SetSurfaceInfo(surface_info_); 142 layer_impl->SetPrimarySurfaceInfo(primary_surface_info_);
143 layer_impl->SetFallbackSurfaceInfo(fallback_surface_info_);
109 layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_); 144 layer_impl->SetStretchContentToFillBounds(stretch_content_to_fill_bounds_);
110 } 145 }
111 146
112 void SurfaceLayer::RemoveCurrentReference() { 147 void SurfaceLayer::RemoveReference(base::Closure reference_returner) {
113 if (!reference_returner_) 148 if (!reference_returner)
114 return; 149 return;
115 auto swap_promise = base::MakeUnique<SatisfySwapPromise>( 150 auto swap_promise = base::MakeUnique<SatisfySwapPromise>(
116 std::move(reference_returner_), 151 std::move(reference_returner),
117 layer_tree_host()->GetTaskRunnerProvider()->MainThreadTaskRunner()); 152 layer_tree_host()->GetTaskRunnerProvider()->MainThreadTaskRunner());
118 layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise( 153 layer_tree_host()->GetSwapPromiseManager()->QueueSwapPromise(
119 std::move(swap_promise)); 154 std::move(swap_promise));
120 } 155 }
121 156
122 } // namespace cc 157 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698