| 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 "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "cc/layers/solid_color_layer.h" | 10 #include "cc/layers/solid_color_layer.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 DelegatedFrameHostAndroid::DelegatedFrameHostAndroid( | 53 DelegatedFrameHostAndroid::DelegatedFrameHostAndroid( |
| 54 ui::ViewAndroid* view, | 54 ui::ViewAndroid* view, |
| 55 cc::SurfaceManager* surface_manager, | 55 cc::SurfaceManager* surface_manager, |
| 56 Client* client, | 56 Client* client, |
| 57 const cc::FrameSinkId& frame_sink_id) | 57 const cc::FrameSinkId& frame_sink_id) |
| 58 : frame_sink_id_(frame_sink_id), | 58 : frame_sink_id_(frame_sink_id), |
| 59 view_(view), | 59 view_(view), |
| 60 surface_manager_(surface_manager), | 60 surface_manager_(surface_manager), |
| 61 client_(client) { | 61 client_(client), |
| 62 begin_frame_source_(this) { |
| 62 DCHECK(view_); | 63 DCHECK(view_); |
| 63 DCHECK(client_); | 64 DCHECK(client_); |
| 64 | 65 |
| 65 local_surface_id_allocator_.reset(new cc::LocalSurfaceIdAllocator()); | 66 local_surface_id_allocator_.reset(new cc::LocalSurfaceIdAllocator()); |
| 66 surface_manager_->RegisterFrameSinkId(frame_sink_id_); | 67 surface_manager_->RegisterFrameSinkId(frame_sink_id_); |
| 67 surface_factory_ = base::WrapUnique( | 68 CreateNewCompositorFrameSinkSupport(); |
| 68 new cc::SurfaceFactory(frame_sink_id_, surface_manager_, this)); | |
| 69 } | 69 } |
| 70 | 70 |
| 71 DelegatedFrameHostAndroid::~DelegatedFrameHostAndroid() { | 71 DelegatedFrameHostAndroid::~DelegatedFrameHostAndroid() { |
| 72 DestroyDelegatedContent(); | 72 DestroyDelegatedContent(); |
| 73 surface_factory_.reset(); | |
| 74 DetachFromCompositor(); | 73 DetachFromCompositor(); |
| 74 support_.reset(); |
| 75 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); | 75 surface_manager_->InvalidateFrameSinkId(frame_sink_id_); |
| 76 } | 76 } |
| 77 | 77 |
| 78 DelegatedFrameHostAndroid::FrameData::FrameData() = default; | 78 DelegatedFrameHostAndroid::FrameData::FrameData() = default; |
| 79 | 79 |
| 80 DelegatedFrameHostAndroid::FrameData::~FrameData() = default; | 80 DelegatedFrameHostAndroid::FrameData::~FrameData() = default; |
| 81 | 81 |
| 82 void DelegatedFrameHostAndroid::SubmitCompositorFrame( | 82 void DelegatedFrameHostAndroid::SubmitCompositorFrame( |
| 83 cc::CompositorFrame frame, | 83 cc::CompositorFrame frame) { |
| 84 cc::SurfaceFactory::DrawCallback draw_callback) { | |
| 85 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); | 84 cc::RenderPass* root_pass = frame.render_pass_list.back().get(); |
| 86 gfx::Size surface_size = root_pass->output_rect.size(); | 85 gfx::Size surface_size = root_pass->output_rect.size(); |
| 87 | 86 |
| 88 if (!current_frame_ || surface_size != current_frame_->surface_size || | 87 if (!current_frame_ || surface_size != current_frame_->surface_size || |
| 89 current_frame_->top_controls_height != | 88 current_frame_->top_controls_height != |
| 90 frame.metadata.top_controls_height || | 89 frame.metadata.top_controls_height || |
| 91 current_frame_->top_controls_shown_ratio != | 90 current_frame_->top_controls_shown_ratio != |
| 92 frame.metadata.top_controls_shown_ratio || | 91 frame.metadata.top_controls_shown_ratio || |
| 93 current_frame_->bottom_controls_height != | 92 current_frame_->bottom_controls_height != |
| 94 frame.metadata.bottom_controls_height || | 93 frame.metadata.bottom_controls_height || |
| (...skipping 13 matching lines...) Expand all Loading... |
| 108 current_frame_->top_controls_height = frame.metadata.top_controls_height; | 107 current_frame_->top_controls_height = frame.metadata.top_controls_height; |
| 109 current_frame_->top_controls_shown_ratio = | 108 current_frame_->top_controls_shown_ratio = |
| 110 frame.metadata.top_controls_shown_ratio; | 109 frame.metadata.top_controls_shown_ratio; |
| 111 current_frame_->bottom_controls_height = | 110 current_frame_->bottom_controls_height = |
| 112 frame.metadata.bottom_controls_height; | 111 frame.metadata.bottom_controls_height; |
| 113 current_frame_->bottom_controls_shown_ratio = | 112 current_frame_->bottom_controls_shown_ratio = |
| 114 frame.metadata.bottom_controls_shown_ratio; | 113 frame.metadata.bottom_controls_shown_ratio; |
| 115 current_frame_->has_transparent_background = | 114 current_frame_->has_transparent_background = |
| 116 root_pass->has_transparent_background; | 115 root_pass->has_transparent_background; |
| 117 current_frame_->viewport_selection = frame.metadata.selection; | 116 current_frame_->viewport_selection = frame.metadata.selection; |
| 118 surface_factory_->SubmitCompositorFrame(current_frame_->local_surface_id, | 117 support_->SubmitCompositorFrame(current_frame_->local_surface_id, |
| 119 std::move(frame), draw_callback); | 118 std::move(frame)); |
| 120 | 119 |
| 121 content_layer_ = CreateSurfaceLayer( | 120 content_layer_ = CreateSurfaceLayer( |
| 122 surface_manager_, cc::SurfaceId(surface_factory_->frame_sink_id(), | 121 surface_manager_, |
| 123 current_frame_->local_surface_id), | 122 cc::SurfaceId(frame_sink_id_, current_frame_->local_surface_id), |
| 124 current_frame_->surface_size, | 123 current_frame_->surface_size, |
| 125 !current_frame_->has_transparent_background); | 124 !current_frame_->has_transparent_background); |
| 126 view_->GetLayer()->AddChild(content_layer_); | 125 view_->GetLayer()->AddChild(content_layer_); |
| 127 } else { | 126 } else { |
| 128 surface_factory_->SubmitCompositorFrame(current_frame_->local_surface_id, | 127 support_->SubmitCompositorFrame(current_frame_->local_surface_id, |
| 129 std::move(frame), draw_callback); | 128 std::move(frame)); |
| 130 } | 129 } |
| 131 } | 130 } |
| 132 | 131 |
| 133 cc::FrameSinkId DelegatedFrameHostAndroid::GetFrameSinkId() const { | 132 cc::FrameSinkId DelegatedFrameHostAndroid::GetFrameSinkId() const { |
| 134 return frame_sink_id_; | 133 return frame_sink_id_; |
| 135 } | 134 } |
| 136 | 135 |
| 137 void DelegatedFrameHostAndroid::RequestCopyOfSurface( | 136 void DelegatedFrameHostAndroid::RequestCopyOfSurface( |
| 138 WindowAndroidCompositor* compositor, | 137 WindowAndroidCompositor* compositor, |
| 139 const gfx::Rect& src_subrect_in_pixel, | 138 const gfx::Rect& src_subrect_in_pixel, |
| 140 cc::CopyOutputRequest::CopyOutputRequestCallback result_callback) { | 139 cc::CopyOutputRequest::CopyOutputRequestCallback result_callback) { |
| 141 DCHECK(current_frame_); | 140 DCHECK(current_frame_); |
| 142 DCHECK(!result_callback.is_null()); | 141 DCHECK(!result_callback.is_null()); |
| 143 | 142 |
| 144 scoped_refptr<cc::Layer> readback_layer = CreateSurfaceLayer( | 143 scoped_refptr<cc::Layer> readback_layer = CreateSurfaceLayer( |
| 145 surface_manager_, cc::SurfaceId(surface_factory_->frame_sink_id(), | 144 surface_manager_, |
| 146 current_frame_->local_surface_id), | 145 cc::SurfaceId(frame_sink_id_, current_frame_->local_surface_id), |
| 147 current_frame_->surface_size, | 146 current_frame_->surface_size, |
| 148 !current_frame_->has_transparent_background); | 147 !current_frame_->has_transparent_background); |
| 149 readback_layer->SetHideLayerAndSubtree(true); | 148 readback_layer->SetHideLayerAndSubtree(true); |
| 150 compositor->AttachLayerForReadback(readback_layer); | 149 compositor->AttachLayerForReadback(readback_layer); |
| 151 std::unique_ptr<cc::CopyOutputRequest> copy_output_request = | 150 std::unique_ptr<cc::CopyOutputRequest> copy_output_request = |
| 152 cc::CopyOutputRequest::CreateRequest(base::Bind( | 151 cc::CopyOutputRequest::CreateRequest(base::Bind( |
| 153 &CopyOutputRequestCallback, readback_layer, result_callback)); | 152 &CopyOutputRequestCallback, readback_layer, result_callback)); |
| 154 | 153 |
| 155 if (!src_subrect_in_pixel.IsEmpty()) | 154 if (!src_subrect_in_pixel.IsEmpty()) |
| 156 copy_output_request->set_area(src_subrect_in_pixel); | 155 copy_output_request->set_area(src_subrect_in_pixel); |
| 157 | 156 |
| 158 surface_factory_->RequestCopyOfSurface(std::move(copy_output_request)); | 157 support_->RequestCopyOfSurface(std::move(copy_output_request)); |
| 159 } | 158 } |
| 160 | 159 |
| 161 void DelegatedFrameHostAndroid::DestroyDelegatedContent() { | 160 void DelegatedFrameHostAndroid::DestroyDelegatedContent() { |
| 162 if (!current_frame_) | 161 if (!current_frame_) |
| 163 return; | 162 return; |
| 164 | 163 |
| 165 DCHECK(content_layer_); | 164 DCHECK(content_layer_); |
| 166 | 165 |
| 167 content_layer_->RemoveFromParent(); | 166 content_layer_->RemoveFromParent(); |
| 168 content_layer_ = nullptr; | 167 content_layer_ = nullptr; |
| 169 surface_factory_->EvictSurface(); | 168 support_->EvictFrame(); |
| 170 current_frame_.reset(); | 169 current_frame_.reset(); |
| 171 } | 170 } |
| 172 | 171 |
| 173 bool DelegatedFrameHostAndroid::HasDelegatedContent() const { | 172 bool DelegatedFrameHostAndroid::HasDelegatedContent() const { |
| 174 return current_frame_.get() != nullptr; | 173 return current_frame_.get() != nullptr; |
| 175 } | 174 } |
| 176 | 175 |
| 177 void DelegatedFrameHostAndroid::CompositorFrameSinkChanged() { | 176 void DelegatedFrameHostAndroid::CompositorFrameSinkChanged() { |
| 178 DestroyDelegatedContent(); | 177 DestroyDelegatedContent(); |
| 179 surface_factory_->Reset(); | 178 CreateNewCompositorFrameSinkSupport(); |
| 179 if (registered_parent_compositor_) |
| 180 AttachToCompositor(registered_parent_compositor_); |
| 180 } | 181 } |
| 181 | 182 |
| 182 void DelegatedFrameHostAndroid::AttachToCompositor( | 183 void DelegatedFrameHostAndroid::AttachToCompositor( |
| 183 WindowAndroidCompositor* compositor) { | 184 WindowAndroidCompositor* compositor) { |
| 184 if (registered_parent_compositor_) | 185 if (registered_parent_compositor_) |
| 185 DetachFromCompositor(); | 186 DetachFromCompositor(); |
| 186 surface_manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); | |
| 187 compositor->AddChildFrameSink(frame_sink_id_); | 187 compositor->AddChildFrameSink(frame_sink_id_); |
| 188 client_->SetBeginFrameSource(&begin_frame_source_); |
| 188 registered_parent_compositor_ = compositor; | 189 registered_parent_compositor_ = compositor; |
| 189 } | 190 } |
| 190 | 191 |
| 191 void DelegatedFrameHostAndroid::DetachFromCompositor() { | 192 void DelegatedFrameHostAndroid::DetachFromCompositor() { |
| 192 if (!registered_parent_compositor_) | 193 if (!registered_parent_compositor_) |
| 193 return; | 194 return; |
| 194 surface_manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); | 195 client_->SetBeginFrameSource(nullptr); |
| 196 support_->SetNeedsBeginFrame(false); |
| 195 registered_parent_compositor_->RemoveChildFrameSink(frame_sink_id_); | 197 registered_parent_compositor_->RemoveChildFrameSink(frame_sink_id_); |
| 196 registered_parent_compositor_ = nullptr; | 198 registered_parent_compositor_ = nullptr; |
| 197 } | 199 } |
| 198 | 200 |
| 199 void DelegatedFrameHostAndroid::ReturnResources( | 201 void DelegatedFrameHostAndroid::DidReceiveCompositorFrameAck() { |
| 200 const cc::ReturnedResourceArray& resources) { | 202 client_->DidReceiveCompositorFrameAck(); |
| 201 client_->ReturnResources(resources); | |
| 202 } | 203 } |
| 203 | 204 |
| 204 void DelegatedFrameHostAndroid::SetBeginFrameSource( | 205 void DelegatedFrameHostAndroid::OnBeginFrame(const cc::BeginFrameArgs& args) { |
| 205 cc::BeginFrameSource* begin_frame_source) { | 206 begin_frame_source_.OnBeginFrame(args); |
| 206 client_->SetBeginFrameSource(begin_frame_source); | 207 } |
| 208 |
| 209 void DelegatedFrameHostAndroid::ReclaimResources( |
| 210 const cc::ReturnedResourceArray& resources) { |
| 211 client_->ReclaimResources(resources); |
| 212 } |
| 213 |
| 214 void DelegatedFrameHostAndroid::WillDrawSurface( |
| 215 const cc::LocalSurfaceId& local_surface_id, |
| 216 const gfx::Rect& damage_rect) {} |
| 217 |
| 218 void DelegatedFrameHostAndroid::OnNeedsBeginFrames(bool needs_begin_frames) { |
| 219 support_->SetNeedsBeginFrame(needs_begin_frames); |
| 220 } |
| 221 |
| 222 void DelegatedFrameHostAndroid::OnDidFinishFrame(const cc::BeginFrameAck& ack) { |
| 223 } |
| 224 |
| 225 void DelegatedFrameHostAndroid::CreateNewCompositorFrameSinkSupport() { |
| 226 support_.reset(); |
| 227 support_ = base::MakeUnique<cc::CompositorFrameSinkSupport>( |
| 228 this, surface_manager_, frame_sink_id_, false /* is_root */, |
| 229 false /* handles_frame_sink_id_invalidation */, |
| 230 true /* needs_sync_points */); |
| 207 } | 231 } |
| 208 | 232 |
| 209 } // namespace ui | 233 } // namespace ui |
| OLD | NEW |