OLD | NEW |
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 : frame_sink_id_( | 76 : frame_sink_id_( |
77 ui::ContextProviderFactory::GetInstance()->AllocateFrameSinkId()), | 77 ui::ContextProviderFactory::GetInstance()->AllocateFrameSinkId()), |
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(frame_sink_id_)); | 86 surface_id_allocator_.reset(new cc::SurfaceIdAllocator()); |
87 surface_manager_->RegisterFrameSinkId(frame_sink_id_); | 87 surface_manager_->RegisterFrameSinkId(frame_sink_id_); |
88 | 88 |
89 background_layer_->SetBackgroundColor(background_color); | 89 background_layer_->SetBackgroundColor(background_color); |
90 view_->GetLayer()->AddChild(background_layer_); | 90 view_->GetLayer()->AddChild(background_layer_); |
91 UpdateBackgroundLayer(); | 91 UpdateBackgroundLayer(); |
92 } | 92 } |
93 | 93 |
94 DelegatedFrameHostAndroid::~DelegatedFrameHostAndroid() { | 94 DelegatedFrameHostAndroid::~DelegatedFrameHostAndroid() { |
95 DestroyDelegatedContent(); | 95 DestroyDelegatedContent(); |
96 surface_factory_.reset(); | 96 surface_factory_.reset(); |
(...skipping 28 matching lines...) Expand all Loading... |
125 current_frame_->bottom_controls_shown_ratio != | 125 current_frame_->bottom_controls_shown_ratio != |
126 frame.metadata.bottom_controls_shown_ratio || | 126 frame.metadata.bottom_controls_shown_ratio || |
127 current_frame_->viewport_selection != frame.metadata.selection || | 127 current_frame_->viewport_selection != frame.metadata.selection || |
128 current_frame_->has_transparent_background != | 128 current_frame_->has_transparent_background != |
129 root_pass->has_transparent_background) { | 129 root_pass->has_transparent_background) { |
130 DestroyDelegatedContent(); | 130 DestroyDelegatedContent(); |
131 DCHECK(!content_layer_); | 131 DCHECK(!content_layer_); |
132 DCHECK(!current_frame_); | 132 DCHECK(!current_frame_); |
133 | 133 |
134 current_frame_ = base::MakeUnique<FrameData>(); | 134 current_frame_ = base::MakeUnique<FrameData>(); |
135 current_frame_->surface_id = surface_id_allocator_->GenerateId(); | 135 current_frame_->local_frame_id = surface_id_allocator_->GenerateId(); |
136 surface_factory_->Create(current_frame_->surface_id); | 136 surface_factory_->Create(current_frame_->local_frame_id); |
137 | 137 |
138 current_frame_->surface_size = surface_size; | 138 current_frame_->surface_size = surface_size; |
139 current_frame_->top_controls_height = frame.metadata.top_controls_height; | 139 current_frame_->top_controls_height = frame.metadata.top_controls_height; |
140 current_frame_->top_controls_shown_ratio = | 140 current_frame_->top_controls_shown_ratio = |
141 frame.metadata.top_controls_shown_ratio; | 141 frame.metadata.top_controls_shown_ratio; |
142 current_frame_->bottom_controls_height = | 142 current_frame_->bottom_controls_height = |
143 frame.metadata.bottom_controls_height; | 143 frame.metadata.bottom_controls_height; |
144 current_frame_->bottom_controls_shown_ratio = | 144 current_frame_->bottom_controls_shown_ratio = |
145 frame.metadata.bottom_controls_shown_ratio; | 145 frame.metadata.bottom_controls_shown_ratio; |
146 current_frame_->has_transparent_background = | 146 current_frame_->has_transparent_background = |
147 root_pass->has_transparent_background; | 147 root_pass->has_transparent_background; |
148 | 148 |
149 current_frame_->viewport_selection = frame.metadata.selection; | 149 current_frame_->viewport_selection = frame.metadata.selection; |
150 content_layer_ = | 150 content_layer_ = CreateSurfaceLayer( |
151 CreateSurfaceLayer(surface_manager_, current_frame_->surface_id, | 151 surface_manager_, cc::SurfaceId(surface_factory_->frame_sink_id(), |
152 current_frame_->surface_size, | 152 current_frame_->local_frame_id), |
153 !current_frame_->has_transparent_background); | 153 current_frame_->surface_size, |
| 154 !current_frame_->has_transparent_background); |
154 view_->GetLayer()->AddChild(content_layer_); | 155 view_->GetLayer()->AddChild(content_layer_); |
155 UpdateBackgroundLayer(); | 156 UpdateBackgroundLayer(); |
156 } | 157 } |
157 | 158 |
158 surface_factory_->SubmitCompositorFrame(current_frame_->surface_id, | 159 surface_factory_->SubmitCompositorFrame(current_frame_->local_frame_id, |
159 std::move(frame), draw_callback); | 160 std::move(frame), draw_callback); |
160 } | 161 } |
161 | 162 |
162 cc::FrameSinkId DelegatedFrameHostAndroid::GetFrameSinkId() const { | 163 cc::FrameSinkId DelegatedFrameHostAndroid::GetFrameSinkId() const { |
163 return frame_sink_id_; | 164 return frame_sink_id_; |
164 } | 165 } |
165 | 166 |
166 void DelegatedFrameHostAndroid::RequestCopyOfSurface( | 167 void DelegatedFrameHostAndroid::RequestCopyOfSurface( |
167 WindowAndroidCompositor* compositor, | 168 WindowAndroidCompositor* compositor, |
168 const gfx::Rect& src_subrect_in_pixel, | 169 const gfx::Rect& src_subrect_in_pixel, |
169 cc::CopyOutputRequest::CopyOutputRequestCallback result_callback) { | 170 cc::CopyOutputRequest::CopyOutputRequestCallback result_callback) { |
170 DCHECK(current_frame_); | 171 DCHECK(current_frame_); |
171 DCHECK(!result_callback.is_null()); | 172 DCHECK(!result_callback.is_null()); |
172 | 173 |
173 scoped_refptr<cc::Layer> readback_layer = | 174 scoped_refptr<cc::Layer> readback_layer = CreateSurfaceLayer( |
174 CreateSurfaceLayer(surface_manager_, current_frame_->surface_id, | 175 surface_manager_, cc::SurfaceId(surface_factory_->frame_sink_id(), |
175 current_frame_->surface_size, | 176 current_frame_->local_frame_id), |
176 !current_frame_->has_transparent_background); | 177 current_frame_->surface_size, |
| 178 !current_frame_->has_transparent_background); |
177 readback_layer->SetHideLayerAndSubtree(true); | 179 readback_layer->SetHideLayerAndSubtree(true); |
178 compositor->AttachLayerForReadback(readback_layer); | 180 compositor->AttachLayerForReadback(readback_layer); |
179 std::unique_ptr<cc::CopyOutputRequest> copy_output_request = | 181 std::unique_ptr<cc::CopyOutputRequest> copy_output_request = |
180 cc::CopyOutputRequest::CreateRequest(base::Bind( | 182 cc::CopyOutputRequest::CreateRequest(base::Bind( |
181 &CopyOutputRequestCallback, readback_layer, result_callback)); | 183 &CopyOutputRequestCallback, readback_layer, result_callback)); |
182 | 184 |
183 if (!src_subrect_in_pixel.IsEmpty()) | 185 if (!src_subrect_in_pixel.IsEmpty()) |
184 copy_output_request->set_area(src_subrect_in_pixel); | 186 copy_output_request->set_area(src_subrect_in_pixel); |
185 | 187 |
186 readback_layer->RequestCopyOfOutput(std::move(copy_output_request)); | 188 readback_layer->RequestCopyOfOutput(std::move(copy_output_request)); |
187 } | 189 } |
188 | 190 |
189 void DelegatedFrameHostAndroid::DestroyDelegatedContent() { | 191 void DelegatedFrameHostAndroid::DestroyDelegatedContent() { |
190 if (!current_frame_) | 192 if (!current_frame_) |
191 return; | 193 return; |
192 | 194 |
193 DCHECK(surface_factory_.get()); | 195 DCHECK(surface_factory_.get()); |
194 DCHECK(content_layer_); | 196 DCHECK(content_layer_); |
195 | 197 |
196 content_layer_->RemoveFromParent(); | 198 content_layer_->RemoveFromParent(); |
197 content_layer_ = nullptr; | 199 content_layer_ = nullptr; |
198 surface_factory_->Destroy(current_frame_->surface_id); | 200 surface_factory_->Destroy(current_frame_->local_frame_id); |
199 current_frame_.reset(); | 201 current_frame_.reset(); |
200 | 202 |
201 UpdateBackgroundLayer(); | 203 UpdateBackgroundLayer(); |
202 } | 204 } |
203 | 205 |
204 bool DelegatedFrameHostAndroid::HasDelegatedContent() const { | 206 bool DelegatedFrameHostAndroid::HasDelegatedContent() const { |
205 return current_frame_.get() != nullptr; | 207 return current_frame_.get() != nullptr; |
206 } | 208 } |
207 | 209 |
208 void DelegatedFrameHostAndroid::CompositorFrameSinkChanged() { | 210 void DelegatedFrameHostAndroid::CompositorFrameSinkChanged() { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 content_size_in_dip.width() < container_size_in_dip_.width() || | 268 content_size_in_dip.width() < container_size_in_dip_.width() || |
267 content_size_in_dip.height() < container_size_in_dip_.height(); | 269 content_size_in_dip.height() < container_size_in_dip_.height(); |
268 } else { | 270 } else { |
269 background_is_drawable = true; | 271 background_is_drawable = true; |
270 } | 272 } |
271 | 273 |
272 background_layer_->SetIsDrawable(background_is_drawable); | 274 background_layer_->SetIsDrawable(background_is_drawable); |
273 } | 275 } |
274 | 276 |
275 } // namespace ui | 277 } // namespace ui |
OLD | NEW |