| OLD | NEW |
| 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 "content/renderer/child_frame_compositing_helper.h" | 5 #include "content/renderer/child_frame_compositing_helper.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "cc/blink/web_layer_impl.h" | 9 #include "cc/blink/web_layer_impl.h" |
| 10 #include "cc/layers/picture_image_layer.h" | 10 #include "cc/layers/picture_image_layer.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 class IframeSurfaceReferenceFactory | 45 class IframeSurfaceReferenceFactory |
| 46 : public cc::SequenceSurfaceReferenceFactory { | 46 : public cc::SequenceSurfaceReferenceFactory { |
| 47 public: | 47 public: |
| 48 IframeSurfaceReferenceFactory(scoped_refptr<ThreadSafeSender> sender, | 48 IframeSurfaceReferenceFactory(scoped_refptr<ThreadSafeSender> sender, |
| 49 int routing_id) | 49 int routing_id) |
| 50 : sender_(std::move(sender)), routing_id_(routing_id) {} | 50 : sender_(std::move(sender)), routing_id_(routing_id) {} |
| 51 | 51 |
| 52 void AddPendingSequence(const cc::SurfaceSequence& sequence) { |
| 53 ReleasePendingSequenceIfNecessary(); |
| 54 pending_sequence_ = sequence; |
| 55 } |
| 56 |
| 52 private: | 57 private: |
| 53 ~IframeSurfaceReferenceFactory() override = default; | 58 ~IframeSurfaceReferenceFactory() override { |
| 59 ReleasePendingSequenceIfNecessary(); |
| 60 } |
| 61 |
| 62 void ReleasePendingSequenceIfNecessary() const { |
| 63 if (pending_sequence_.is_valid()) { |
| 64 sender_->Send( |
| 65 new FrameHostMsg_SatisfySequence(routing_id_, pending_sequence_)); |
| 66 pending_sequence_ = cc::SurfaceSequence(); |
| 67 } |
| 68 } |
| 54 | 69 |
| 55 // cc::SequenceSurfaceReferenceFactory implementation: | 70 // cc::SequenceSurfaceReferenceFactory implementation: |
| 56 void RequireSequence(const cc::SurfaceId& surface_id, | 71 void RequireSequence(const cc::SurfaceId& surface_id, |
| 57 const cc::SurfaceSequence& sequence) const override { | 72 const cc::SurfaceSequence& sequence) const override { |
| 58 sender_->Send( | 73 sender_->Send( |
| 59 new FrameHostMsg_RequireSequence(routing_id_, surface_id, sequence)); | 74 new FrameHostMsg_RequireSequence(routing_id_, surface_id, sequence)); |
| 75 // If there is a temporary reference that was waiting on a new one to be |
| 76 // created, it is now safe to release it. |
| 77 ReleasePendingSequenceIfNecessary(); |
| 60 } | 78 } |
| 61 | 79 |
| 62 void SatisfySequence(const cc::SurfaceSequence& sequence) const override { | 80 void SatisfySequence(const cc::SurfaceSequence& sequence) const override { |
| 63 sender_->Send(new FrameHostMsg_SatisfySequence(routing_id_, sequence)); | 81 sender_->Send(new FrameHostMsg_SatisfySequence(routing_id_, sequence)); |
| 64 } | 82 } |
| 65 | 83 |
| 66 const scoped_refptr<ThreadSafeSender> sender_; | 84 const scoped_refptr<ThreadSafeSender> sender_; |
| 85 mutable cc::SurfaceSequence pending_sequence_; |
| 67 const int routing_id_; | 86 const int routing_id_; |
| 68 | 87 |
| 69 DISALLOW_COPY_AND_ASSIGN(IframeSurfaceReferenceFactory); | 88 DISALLOW_COPY_AND_ASSIGN(IframeSurfaceReferenceFactory); |
| 70 }; | 89 }; |
| 71 | 90 |
| 72 class BrowserPluginSurfaceReferenceFactory | 91 class BrowserPluginSurfaceReferenceFactory |
| 73 : public cc::SequenceSurfaceReferenceFactory { | 92 : public cc::SequenceSurfaceReferenceFactory { |
| 74 public: | 93 public: |
| 75 BrowserPluginSurfaceReferenceFactory(scoped_refptr<ThreadSafeSender> sender, | 94 BrowserPluginSurfaceReferenceFactory(scoped_refptr<ThreadSafeSender> sender, |
| 76 int routing_id, | 95 int routing_id, |
| 77 int browser_plugin_instance_id) | 96 int browser_plugin_instance_id) |
| 78 : sender_(std::move(sender)), | 97 : sender_(std::move(sender)), |
| 79 routing_id_(routing_id), | 98 routing_id_(routing_id), |
| 80 browser_plugin_instance_id_(browser_plugin_instance_id) {} | 99 browser_plugin_instance_id_(browser_plugin_instance_id) {} |
| 81 | 100 |
| 101 void AddPendingSequence(const cc::SurfaceSequence& sequence) { |
| 102 ReleasePendingSequenceIfNecessary(); |
| 103 pending_sequence_ = sequence; |
| 104 } |
| 105 |
| 82 private: | 106 private: |
| 83 ~BrowserPluginSurfaceReferenceFactory() override = default; | 107 ~BrowserPluginSurfaceReferenceFactory() override { |
| 108 ReleasePendingSequenceIfNecessary(); |
| 109 } |
| 110 |
| 111 void ReleasePendingSequenceIfNecessary() const { |
| 112 if (pending_sequence_.is_valid()) { |
| 113 sender_->Send(new BrowserPluginHostMsg_SatisfySequence( |
| 114 routing_id_, browser_plugin_instance_id_, pending_sequence_)); |
| 115 pending_sequence_ = cc::SurfaceSequence(); |
| 116 } |
| 117 } |
| 84 | 118 |
| 85 // cc::SequenceSurfaceRefrenceFactory implementation: | 119 // cc::SequenceSurfaceRefrenceFactory implementation: |
| 86 void SatisfySequence(const cc::SurfaceSequence& seq) const override { | 120 void SatisfySequence(const cc::SurfaceSequence& seq) const override { |
| 87 sender_->Send(new BrowserPluginHostMsg_SatisfySequence( | 121 sender_->Send(new BrowserPluginHostMsg_SatisfySequence( |
| 88 routing_id_, browser_plugin_instance_id_, seq)); | 122 routing_id_, browser_plugin_instance_id_, seq)); |
| 89 } | 123 } |
| 90 | 124 |
| 91 void RequireSequence(const cc::SurfaceId& surface_id, | 125 void RequireSequence(const cc::SurfaceId& surface_id, |
| 92 const cc::SurfaceSequence& sequence) const override { | 126 const cc::SurfaceSequence& sequence) const override { |
| 93 sender_->Send(new BrowserPluginHostMsg_RequireSequence( | 127 sender_->Send(new BrowserPluginHostMsg_RequireSequence( |
| 94 routing_id_, browser_plugin_instance_id_, surface_id, sequence)); | 128 routing_id_, browser_plugin_instance_id_, surface_id, sequence)); |
| 129 // If there is a temporary reference that was waiting on a new one to be |
| 130 // created, it is now safe to release it. |
| 131 ReleasePendingSequenceIfNecessary(); |
| 95 } | 132 } |
| 96 | 133 |
| 97 const scoped_refptr<ThreadSafeSender> sender_; | 134 const scoped_refptr<ThreadSafeSender> sender_; |
| 135 mutable cc::SurfaceSequence pending_sequence_; |
| 98 const int routing_id_; | 136 const int routing_id_; |
| 99 const int browser_plugin_instance_id_; | 137 const int browser_plugin_instance_id_; |
| 100 | 138 |
| 101 DISALLOW_COPY_AND_ASSIGN(BrowserPluginSurfaceReferenceFactory); | 139 DISALLOW_COPY_AND_ASSIGN(BrowserPluginSurfaceReferenceFactory); |
| 102 }; | 140 }; |
| 103 | 141 |
| 104 } // namespace | 142 } // namespace |
| 105 | 143 |
| 106 ChildFrameCompositingHelper* | 144 ChildFrameCompositingHelper* |
| 107 ChildFrameCompositingHelper::CreateForBrowserPlugin( | 145 ChildFrameCompositingHelper::CreateForBrowserPlugin( |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 float scale_factor = surface_info.device_scale_factor(); | 254 float scale_factor = surface_info.device_scale_factor(); |
| 217 surface_id_ = surface_info.id(); | 255 surface_id_ = surface_info.id(); |
| 218 scoped_refptr<cc::SurfaceLayer> surface_layer = | 256 scoped_refptr<cc::SurfaceLayer> surface_layer = |
| 219 cc::SurfaceLayer::Create(surface_reference_factory_); | 257 cc::SurfaceLayer::Create(surface_reference_factory_); |
| 220 // TODO(oshima): This is a stopgap fix so that the compositor does not | 258 // TODO(oshima): This is a stopgap fix so that the compositor does not |
| 221 // scaledown the content when 2x frame data is added to 1x parent frame data. | 259 // scaledown the content when 2x frame data is added to 1x parent frame data. |
| 222 // Fix this in cc/. | 260 // Fix this in cc/. |
| 223 if (IsUseZoomForDSFEnabled()) | 261 if (IsUseZoomForDSFEnabled()) |
| 224 scale_factor = 1.0f; | 262 scale_factor = 1.0f; |
| 225 | 263 |
| 264 // The RWHV creates a destruction dependency on the surface that needs to be |
| 265 // satisfied. The reference factory will satisfy it when a new reference has |
| 266 // been created. |
| 267 if (render_frame_proxy_) { |
| 268 static_cast<IframeSurfaceReferenceFactory*>( |
| 269 surface_reference_factory_.get()) |
| 270 ->AddPendingSequence(sequence); |
| 271 } else { |
| 272 static_cast<BrowserPluginSurfaceReferenceFactory*>( |
| 273 surface_reference_factory_.get()) |
| 274 ->AddPendingSequence(sequence); |
| 275 } |
| 276 |
| 226 cc::SurfaceInfo modified_surface_info(surface_info.id(), scale_factor, | 277 cc::SurfaceInfo modified_surface_info(surface_info.id(), scale_factor, |
| 227 surface_info.size_in_pixels()); | 278 surface_info.size_in_pixels()); |
| 228 surface_layer->SetPrimarySurfaceInfo(modified_surface_info); | 279 surface_layer->SetPrimarySurfaceInfo(modified_surface_info); |
| 229 surface_layer->SetFallbackSurfaceInfo(modified_surface_info); | 280 surface_layer->SetFallbackSurfaceInfo(modified_surface_info); |
| 230 surface_layer->SetMasksToBounds(true); | 281 surface_layer->SetMasksToBounds(true); |
| 231 std::unique_ptr<cc_blink::WebLayerImpl> layer( | 282 std::unique_ptr<cc_blink::WebLayerImpl> layer( |
| 232 new cc_blink::WebLayerImpl(surface_layer)); | 283 new cc_blink::WebLayerImpl(surface_layer)); |
| 233 // TODO(lfg): Investigate if it's possible to propagate the information about | 284 // TODO(lfg): Investigate if it's possible to propagate the information about |
| 234 // the child surface's opacity. https://crbug.com/629851. | 285 // the child surface's opacity. https://crbug.com/629851. |
| 235 layer->SetOpaque(false); | 286 layer->SetOpaque(false); |
| 236 layer->SetContentsOpaqueIsFixed(true); | 287 layer->SetContentsOpaqueIsFixed(true); |
| 237 UpdateWebLayer(std::move(layer)); | 288 UpdateWebLayer(std::move(layer)); |
| 238 | 289 |
| 239 UpdateVisibility(true); | 290 UpdateVisibility(true); |
| 240 | 291 |
| 241 // The RWHV creates a destruction dependency on the surface that needs to be | |
| 242 // satisfied. Note: render_frame_proxy_ is null in the case our client is a | |
| 243 // BrowserPlugin; in this case the BrowserPlugin sends its own SatisfySequence | |
| 244 // message. | |
| 245 if (render_frame_proxy_) { | |
| 246 render_frame_proxy_->Send( | |
| 247 new FrameHostMsg_SatisfySequence(host_routing_id_, sequence)); | |
| 248 } else if (browser_plugin_.get()) { | |
| 249 browser_plugin_->SendSatisfySequence(sequence); | |
| 250 } | |
| 251 | |
| 252 CheckSizeAndAdjustLayerProperties( | 292 CheckSizeAndAdjustLayerProperties( |
| 253 surface_info.size_in_pixels(), surface_info.device_scale_factor(), | 293 surface_info.size_in_pixels(), surface_info.device_scale_factor(), |
| 254 static_cast<cc_blink::WebLayerImpl*>(web_layer_.get())->layer()); | 294 static_cast<cc_blink::WebLayerImpl*>(web_layer_.get())->layer()); |
| 255 } | 295 } |
| 256 | 296 |
| 257 void ChildFrameCompositingHelper::UpdateVisibility(bool visible) { | 297 void ChildFrameCompositingHelper::UpdateVisibility(bool visible) { |
| 258 if (web_layer_) | 298 if (web_layer_) |
| 259 web_layer_->SetDrawsContent(visible); | 299 web_layer_->SetDrawsContent(visible); |
| 260 } | 300 } |
| 261 | 301 |
| 262 } // namespace content | 302 } // namespace content |
| OLD | NEW |