Chromium Code Reviews| 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 27 matching lines...) Expand all Loading... | |
| 38 if (!surface) { | 38 if (!surface) { |
| 39 LOG(ERROR) << "Attempting to require callback on nonexistent surface"; | 39 LOG(ERROR) << "Attempting to require callback on nonexistent surface"; |
| 40 return; | 40 return; |
| 41 } | 41 } |
| 42 surface->AddDestructionDependency(sequence); | 42 surface->AddDestructionDependency(sequence); |
| 43 } | 43 } |
| 44 | 44 |
| 45 scoped_refptr<cc::SurfaceLayer> CreateSurfaceLayer( | 45 scoped_refptr<cc::SurfaceLayer> CreateSurfaceLayer( |
| 46 cc::SurfaceManager* surface_manager, | 46 cc::SurfaceManager* surface_manager, |
| 47 cc::SurfaceId surface_id, | 47 cc::SurfaceId surface_id, |
| 48 const gfx::Size surface_size) { | 48 const gfx::Size surface_size, |
| 49 bool surface_opaque) { | |
| 49 // manager must outlive compositors using it. | 50 // manager must outlive compositors using it. |
| 50 scoped_refptr<cc::SurfaceLayer> layer = cc::SurfaceLayer::Create( | 51 scoped_refptr<cc::SurfaceLayer> layer = cc::SurfaceLayer::Create( |
| 51 base::Bind(&SatisfyCallback, base::Unretained(surface_manager)), | 52 base::Bind(&SatisfyCallback, base::Unretained(surface_manager)), |
| 52 base::Bind(&RequireCallback, base::Unretained(surface_manager))); | 53 base::Bind(&RequireCallback, base::Unretained(surface_manager))); |
| 53 layer->SetSurfaceId(surface_id, 1.f, surface_size); | 54 layer->SetSurfaceId(surface_id, 1.f, surface_size); |
| 54 layer->SetBounds(surface_size); | 55 layer->SetBounds(surface_size); |
| 55 layer->SetIsDrawable(true); | 56 layer->SetIsDrawable(true); |
| 56 layer->SetContentsOpaque(true); | 57 layer->SetContentsOpaque(surface_opaque); |
| 57 | 58 |
| 58 return layer; | 59 return layer; |
| 59 } | 60 } |
| 60 | 61 |
| 61 void CopyOutputRequestCallback( | 62 void CopyOutputRequestCallback( |
| 62 scoped_refptr<cc::Layer> readback_layer, | 63 scoped_refptr<cc::Layer> readback_layer, |
| 63 cc::CopyOutputRequest::CopyOutputRequestCallback result_callback, | 64 cc::CopyOutputRequest::CopyOutputRequestCallback result_callback, |
| 64 std::unique_ptr<cc::CopyOutputResult> copy_output_result) { | 65 std::unique_ptr<cc::CopyOutputResult> copy_output_result) { |
| 65 readback_layer->RemoveFromParent(); | 66 readback_layer->RemoveFromParent(); |
| 66 result_callback.Run(std::move(copy_output_result)); | 67 result_callback.Run(std::move(copy_output_result)); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 | 116 |
| 116 if (!current_frame_ || surface_size != current_frame_->surface_size || | 117 if (!current_frame_ || surface_size != current_frame_->surface_size || |
| 117 current_frame_->top_controls_height != | 118 current_frame_->top_controls_height != |
| 118 frame.metadata.top_controls_height || | 119 frame.metadata.top_controls_height || |
| 119 current_frame_->top_controls_shown_ratio != | 120 current_frame_->top_controls_shown_ratio != |
| 120 frame.metadata.top_controls_shown_ratio || | 121 frame.metadata.top_controls_shown_ratio || |
| 121 current_frame_->bottom_controls_height != | 122 current_frame_->bottom_controls_height != |
| 122 frame.metadata.bottom_controls_height || | 123 frame.metadata.bottom_controls_height || |
| 123 current_frame_->bottom_controls_shown_ratio != | 124 current_frame_->bottom_controls_shown_ratio != |
| 124 frame.metadata.bottom_controls_shown_ratio || | 125 frame.metadata.bottom_controls_shown_ratio || |
| 125 current_frame_->viewport_selection != frame.metadata.selection) { | 126 current_frame_->viewport_selection != frame.metadata.selection || |
| 127 current_frame_->has_transparent_background != | |
| 128 root_pass->has_transparent_background) { | |
| 126 DestroyDelegatedContent(); | 129 DestroyDelegatedContent(); |
| 127 DCHECK(!content_layer_); | 130 DCHECK(!content_layer_); |
| 128 DCHECK(!current_frame_); | 131 DCHECK(!current_frame_); |
| 129 | 132 |
| 130 current_frame_ = base::MakeUnique<FrameData>(); | 133 current_frame_ = base::MakeUnique<FrameData>(); |
| 131 current_frame_->surface_id = surface_id_allocator_->GenerateId(); | 134 current_frame_->surface_id = surface_id_allocator_->GenerateId(); |
| 132 surface_factory_->Create(current_frame_->surface_id); | 135 surface_factory_->Create(current_frame_->surface_id); |
| 133 | 136 |
| 134 current_frame_->surface_size = surface_size; | 137 current_frame_->surface_size = surface_size; |
| 135 current_frame_->top_controls_height = frame.metadata.top_controls_height; | 138 current_frame_->top_controls_height = frame.metadata.top_controls_height; |
| 136 current_frame_->top_controls_shown_ratio = | 139 current_frame_->top_controls_shown_ratio = |
| 137 frame.metadata.top_controls_shown_ratio; | 140 frame.metadata.top_controls_shown_ratio; |
| 138 current_frame_->bottom_controls_height = | 141 current_frame_->bottom_controls_height = |
| 139 frame.metadata.bottom_controls_height; | 142 frame.metadata.bottom_controls_height; |
| 140 current_frame_->bottom_controls_shown_ratio = | 143 current_frame_->bottom_controls_shown_ratio = |
| 141 frame.metadata.bottom_controls_shown_ratio; | 144 frame.metadata.bottom_controls_shown_ratio; |
| 145 current_frame_->has_transparent_background = | |
| 146 root_pass->has_transparent_background; | |
| 142 | 147 |
| 143 current_frame_->viewport_selection = frame.metadata.selection; | 148 current_frame_->viewport_selection = frame.metadata.selection; |
| 144 content_layer_ = | 149 content_layer_ = |
| 145 CreateSurfaceLayer(surface_manager_, current_frame_->surface_id, | 150 CreateSurfaceLayer(surface_manager_, current_frame_->surface_id, |
| 146 current_frame_->surface_size); | 151 current_frame_->surface_size, |
| 152 !current_frame_->has_transparent_background); | |
| 147 view_->GetLayer()->AddChild(content_layer_); | 153 view_->GetLayer()->AddChild(content_layer_); |
| 148 UpdateBackgroundLayer(); | 154 UpdateBackgroundLayer(); |
| 149 } | 155 } |
| 150 | 156 |
| 151 surface_factory_->SubmitCompositorFrame(current_frame_->surface_id, | 157 surface_factory_->SubmitCompositorFrame(current_frame_->surface_id, |
| 152 std::move(frame), draw_callback); | 158 std::move(frame), draw_callback); |
| 153 } | 159 } |
| 154 | 160 |
| 155 uint32_t DelegatedFrameHostAndroid::GetSurfaceClientId() const { | 161 uint32_t DelegatedFrameHostAndroid::GetSurfaceClientId() const { |
| 156 return surface_id_allocator_->client_id(); | 162 return surface_id_allocator_->client_id(); |
| 157 } | 163 } |
| 158 | 164 |
| 159 void DelegatedFrameHostAndroid::RequestCopyOfSurface( | 165 void DelegatedFrameHostAndroid::RequestCopyOfSurface( |
| 160 WindowAndroidCompositor* compositor, | 166 WindowAndroidCompositor* compositor, |
| 161 const gfx::Rect& src_subrect_in_pixel, | 167 const gfx::Rect& src_subrect_in_pixel, |
| 162 cc::CopyOutputRequest::CopyOutputRequestCallback result_callback) { | 168 cc::CopyOutputRequest::CopyOutputRequestCallback result_callback) { |
| 163 DCHECK(current_frame_); | 169 DCHECK(current_frame_); |
| 164 DCHECK(!result_callback.is_null()); | 170 DCHECK(!result_callback.is_null()); |
| 165 | 171 |
| 166 scoped_refptr<cc::Layer> readback_layer = | 172 scoped_refptr<cc::Layer> readback_layer = |
| 167 CreateSurfaceLayer(surface_manager_, current_frame_->surface_id, | 173 CreateSurfaceLayer(surface_manager_, current_frame_->surface_id, |
| 168 current_frame_->surface_size); | 174 current_frame_->surface_size, |
| 175 !current_frame_->has_transparent_background); | |
|
no sievers
2016/09/02 22:06:52
nit: maybe just make the readback layer always opa
| |
| 169 readback_layer->SetHideLayerAndSubtree(true); | 176 readback_layer->SetHideLayerAndSubtree(true); |
| 170 compositor->AttachLayerForReadback(readback_layer); | 177 compositor->AttachLayerForReadback(readback_layer); |
| 171 std::unique_ptr<cc::CopyOutputRequest> copy_output_request = | 178 std::unique_ptr<cc::CopyOutputRequest> copy_output_request = |
| 172 cc::CopyOutputRequest::CreateRequest(base::Bind( | 179 cc::CopyOutputRequest::CreateRequest(base::Bind( |
| 173 &CopyOutputRequestCallback, readback_layer, result_callback)); | 180 &CopyOutputRequestCallback, readback_layer, result_callback)); |
| 174 | 181 |
| 175 if (!src_subrect_in_pixel.IsEmpty()) | 182 if (!src_subrect_in_pixel.IsEmpty()) |
| 176 copy_output_request->set_area(src_subrect_in_pixel); | 183 copy_output_request->set_area(src_subrect_in_pixel); |
| 177 | 184 |
| 178 readback_layer->RequestCopyOfOutput(std::move(copy_output_request)); | 185 readback_layer->RequestCopyOfOutput(std::move(copy_output_request)); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 199 | 206 |
| 200 void DelegatedFrameHostAndroid::OutputSurfaceChanged() { | 207 void DelegatedFrameHostAndroid::OutputSurfaceChanged() { |
| 201 DestroyDelegatedContent(); | 208 DestroyDelegatedContent(); |
| 202 surface_factory_.reset(); | 209 surface_factory_.reset(); |
| 203 } | 210 } |
| 204 | 211 |
| 205 void DelegatedFrameHostAndroid::UpdateBackgroundColor(SkColor color) { | 212 void DelegatedFrameHostAndroid::UpdateBackgroundColor(SkColor color) { |
| 206 background_layer_->SetBackgroundColor(color); | 213 background_layer_->SetBackgroundColor(color); |
| 207 } | 214 } |
| 208 | 215 |
| 209 void DelegatedFrameHostAndroid::SetContentsOpaque(bool opaque) { | |
| 210 if (!content_layer_) | |
| 211 return; | |
| 212 content_layer_->SetContentsOpaque(opaque); | |
| 213 } | |
| 214 | |
| 215 void DelegatedFrameHostAndroid::UpdateContainerSizeinDIP( | 216 void DelegatedFrameHostAndroid::UpdateContainerSizeinDIP( |
| 216 const gfx::Size& size_in_dip) { | 217 const gfx::Size& size_in_dip) { |
| 217 container_size_in_dip_ = size_in_dip; | 218 container_size_in_dip_ = size_in_dip; |
| 218 background_layer_->SetBounds(gfx::ConvertSizeToPixel( | 219 background_layer_->SetBounds(gfx::ConvertSizeToPixel( |
| 219 gfx::DeviceDisplayInfo().GetDIPScale(), container_size_in_dip_)); | 220 gfx::DeviceDisplayInfo().GetDIPScale(), container_size_in_dip_)); |
| 220 UpdateBackgroundLayer(); | 221 UpdateBackgroundLayer(); |
| 221 } | 222 } |
| 222 | 223 |
| 223 void DelegatedFrameHostAndroid::ReturnResources( | 224 void DelegatedFrameHostAndroid::ReturnResources( |
| 224 const cc::ReturnedResourceArray& resources) { | 225 const cc::ReturnedResourceArray& resources) { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 245 content_size_in_dip.width() < container_size_in_dip_.width() || | 246 content_size_in_dip.width() < container_size_in_dip_.width() || |
| 246 content_size_in_dip.height() < container_size_in_dip_.height(); | 247 content_size_in_dip.height() < container_size_in_dip_.height(); |
| 247 } else { | 248 } else { |
| 248 background_is_drawable = true; | 249 background_is_drawable = true; |
| 249 } | 250 } |
| 250 | 251 |
| 251 background_layer_->SetIsDrawable(background_is_drawable); | 252 background_layer_->SetIsDrawable(background_is_drawable); |
| 252 } | 253 } |
| 253 | 254 |
| 254 } // namespace ui | 255 } // namespace ui |
| OLD | NEW |