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

Side by Side Diff: ui/android/delegated_frame_host_android.cc

Issue 2476303004: Make SurfaceFactory lifetime match frame_sink_id_ registration in DelegatedFrameHostAndroid (Closed)
Patch Set: Created 4 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ui/android/delegated_frame_host_android.h" 5 #include "ui/android/delegated_frame_host_android.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "cc/layers/solid_color_layer.h" 9 #include "cc/layers/solid_color_layer.h"
10 #include "cc/layers/surface_layer.h" 10 #include "cc/layers/surface_layer.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 view_(view), 78 view_(view),
79 return_resources_callback_(return_resources_callback), 79 return_resources_callback_(return_resources_callback),
80 background_layer_(cc::SolidColorLayer::Create()) { 80 background_layer_(cc::SolidColorLayer::Create()) {
81 DCHECK(view_); 81 DCHECK(view_);
82 DCHECK(!return_resources_callback_.is_null()); 82 DCHECK(!return_resources_callback_.is_null());
83 83
84 surface_manager_ = 84 surface_manager_ =
85 ui::ContextProviderFactory::GetInstance()->GetSurfaceManager(); 85 ui::ContextProviderFactory::GetInstance()->GetSurfaceManager();
86 surface_id_allocator_.reset(new cc::SurfaceIdAllocator()); 86 surface_id_allocator_.reset(new cc::SurfaceIdAllocator());
87 surface_manager_->RegisterFrameSinkId(frame_sink_id_); 87 surface_manager_->RegisterFrameSinkId(frame_sink_id_);
88 surface_factory_ = base::WrapUnique(
89 new cc::SurfaceFactory(frame_sink_id_, surface_manager_, this));
88 90
89 background_layer_->SetBackgroundColor(background_color); 91 background_layer_->SetBackgroundColor(background_color);
90 view_->GetLayer()->AddChild(background_layer_); 92 view_->GetLayer()->AddChild(background_layer_);
91 UpdateBackgroundLayer(); 93 UpdateBackgroundLayer();
92 } 94 }
93 95
94 DelegatedFrameHostAndroid::~DelegatedFrameHostAndroid() { 96 DelegatedFrameHostAndroid::~DelegatedFrameHostAndroid() {
95 DestroyDelegatedContent(); 97 DestroyDelegatedContent();
96 surface_factory_.reset(); 98 surface_factory_.reset();
97 UnregisterFrameSinkHierarchy(); 99 UnregisterFrameSinkHierarchy();
98 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); 100 surface_manager_->InvalidateFrameSinkId(frame_sink_id_);
99 background_layer_->RemoveFromParent(); 101 background_layer_->RemoveFromParent();
100 } 102 }
101 103
102 DelegatedFrameHostAndroid::FrameData::FrameData() = default; 104 DelegatedFrameHostAndroid::FrameData::FrameData() = default;
103 105
104 DelegatedFrameHostAndroid::FrameData::~FrameData() = default; 106 DelegatedFrameHostAndroid::FrameData::~FrameData() = default;
105 107
106 void DelegatedFrameHostAndroid::SubmitCompositorFrame( 108 void DelegatedFrameHostAndroid::SubmitCompositorFrame(
107 cc::CompositorFrame frame, 109 cc::CompositorFrame frame,
108 cc::SurfaceFactory::DrawCallback draw_callback) { 110 cc::SurfaceFactory::DrawCallback draw_callback) {
109 if (!surface_factory_) {
110 surface_factory_ = base::WrapUnique(
111 new cc::SurfaceFactory(frame_sink_id_, surface_manager_, this));
112 }
113
114 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); 111 cc::RenderPass* root_pass = frame.render_pass_list.back().get();
115 gfx::Size surface_size = root_pass->output_rect.size(); 112 gfx::Size surface_size = root_pass->output_rect.size();
116 113
117 if (!current_frame_ || surface_size != current_frame_->surface_size || 114 if (!current_frame_ || surface_size != current_frame_->surface_size ||
118 current_frame_->top_controls_height != 115 current_frame_->top_controls_height !=
119 frame.metadata.top_controls_height || 116 frame.metadata.top_controls_height ||
120 current_frame_->top_controls_shown_ratio != 117 current_frame_->top_controls_shown_ratio !=
121 frame.metadata.top_controls_shown_ratio || 118 frame.metadata.top_controls_shown_ratio ||
122 current_frame_->bottom_controls_height != 119 current_frame_->bottom_controls_height !=
123 frame.metadata.bottom_controls_height || 120 frame.metadata.bottom_controls_height ||
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 if (!src_subrect_in_pixel.IsEmpty()) 181 if (!src_subrect_in_pixel.IsEmpty())
185 copy_output_request->set_area(src_subrect_in_pixel); 182 copy_output_request->set_area(src_subrect_in_pixel);
186 183
187 readback_layer->RequestCopyOfOutput(std::move(copy_output_request)); 184 readback_layer->RequestCopyOfOutput(std::move(copy_output_request));
188 } 185 }
189 186
190 void DelegatedFrameHostAndroid::DestroyDelegatedContent() { 187 void DelegatedFrameHostAndroid::DestroyDelegatedContent() {
191 if (!current_frame_) 188 if (!current_frame_)
192 return; 189 return;
193 190
194 DCHECK(surface_factory_.get());
195 DCHECK(content_layer_); 191 DCHECK(content_layer_);
196 192
197 content_layer_->RemoveFromParent(); 193 content_layer_->RemoveFromParent();
198 content_layer_ = nullptr; 194 content_layer_ = nullptr;
199 surface_factory_->Destroy(current_frame_->local_frame_id); 195 surface_factory_->Destroy(current_frame_->local_frame_id);
200 current_frame_.reset(); 196 current_frame_.reset();
201 197
202 UpdateBackgroundLayer(); 198 UpdateBackgroundLayer();
203 } 199 }
204 200
205 bool DelegatedFrameHostAndroid::HasDelegatedContent() const { 201 bool DelegatedFrameHostAndroid::HasDelegatedContent() const {
206 return current_frame_.get() != nullptr; 202 return current_frame_.get() != nullptr;
207 } 203 }
208 204
209 void DelegatedFrameHostAndroid::CompositorFrameSinkChanged() { 205 void DelegatedFrameHostAndroid::CompositorFrameSinkChanged() {
210 DestroyDelegatedContent(); 206 DestroyDelegatedContent();
211 surface_factory_.reset(); 207 surface_factory_->Reset();
212 } 208 }
213 209
214 void DelegatedFrameHostAndroid::UpdateBackgroundColor(SkColor color) { 210 void DelegatedFrameHostAndroid::UpdateBackgroundColor(SkColor color) {
215 background_layer_->SetBackgroundColor(color); 211 background_layer_->SetBackgroundColor(color);
216 } 212 }
217 213
218 void DelegatedFrameHostAndroid::UpdateContainerSizeinDIP( 214 void DelegatedFrameHostAndroid::UpdateContainerSizeinDIP(
219 const gfx::Size& size_in_dip) { 215 const gfx::Size& size_in_dip) {
220 container_size_in_dip_ = size_in_dip; 216 container_size_in_dip_ = size_in_dip;
221 background_layer_->SetBounds(gfx::ConvertSizeToPixel( 217 background_layer_->SetBounds(gfx::ConvertSizeToPixel(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 content_size_in_dip.width() < container_size_in_dip_.width() || 263 content_size_in_dip.width() < container_size_in_dip_.width() ||
268 content_size_in_dip.height() < container_size_in_dip_.height(); 264 content_size_in_dip.height() < container_size_in_dip_.height();
269 } else { 265 } else {
270 background_is_drawable = true; 266 background_is_drawable = true;
271 } 267 }
272 268
273 background_layer_->SetIsDrawable(background_is_drawable); 269 background_layer_->SetIsDrawable(background_is_drawable);
274 } 270 }
275 271
276 } // namespace ui 272 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698