| 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" |
| 11 #include "cc/layers/solid_color_layer.h" | 11 #include "cc/layers/solid_color_layer.h" |
| 12 #include "cc/layers/surface_layer.h" | 12 #include "cc/layers/surface_layer.h" |
| 13 #include "cc/output/context_provider.h" | 13 #include "cc/output/context_provider.h" |
| 14 #include "cc/output/copy_output_request.h" | 14 #include "cc/output/copy_output_request.h" |
| 15 #include "cc/output/copy_output_result.h" | 15 #include "cc/output/copy_output_result.h" |
| 16 #include "cc/resources/single_release_callback.h" | 16 #include "cc/resources/single_release_callback.h" |
| 17 #include "cc/surfaces/sequence_surface_reference_factory.h" |
| 17 #include "content/child/thread_safe_sender.h" | 18 #include "content/child/thread_safe_sender.h" |
| 18 #include "content/common/browser_plugin/browser_plugin_messages.h" | 19 #include "content/common/browser_plugin/browser_plugin_messages.h" |
| 19 #include "content/common/content_switches_internal.h" | 20 #include "content/common/content_switches_internal.h" |
| 20 #include "content/common/frame_messages.h" | 21 #include "content/common/frame_messages.h" |
| 21 #include "content/common/gpu/client/context_provider_command_buffer.h" | 22 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 22 #include "content/public/common/content_client.h" | 23 #include "content/public/common/content_client.h" |
| 23 #include "content/public/renderer/content_renderer_client.h" | 24 #include "content/public/renderer/content_renderer_client.h" |
| 24 #include "content/renderer/browser_plugin/browser_plugin.h" | 25 #include "content/renderer/browser_plugin/browser_plugin.h" |
| 25 #include "content/renderer/browser_plugin/browser_plugin_manager.h" | 26 #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
| 26 #include "content/renderer/render_frame_impl.h" | 27 #include "content/renderer/render_frame_impl.h" |
| 27 #include "content/renderer/render_frame_proxy.h" | 28 #include "content/renderer/render_frame_proxy.h" |
| 28 #include "content/renderer/render_thread_impl.h" | 29 #include "content/renderer/render_thread_impl.h" |
| 29 #include "skia/ext/image_operations.h" | 30 #include "skia/ext/image_operations.h" |
| 30 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 31 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 31 #include "third_party/WebKit/public/web/WebRemoteFrame.h" | 32 #include "third_party/WebKit/public/web/WebRemoteFrame.h" |
| 32 #include "third_party/khronos/GLES2/gl2.h" | 33 #include "third_party/khronos/GLES2/gl2.h" |
| 33 #include "third_party/skia/include/core/SkBitmap.h" | 34 #include "third_party/skia/include/core/SkBitmap.h" |
| 34 #include "third_party/skia/include/core/SkImage.h" | 35 #include "third_party/skia/include/core/SkImage.h" |
| 35 #include "ui/gfx/geometry/point_f.h" | 36 #include "ui/gfx/geometry/point_f.h" |
| 36 #include "ui/gfx/geometry/size_conversions.h" | 37 #include "ui/gfx/geometry/size_conversions.h" |
| 37 #include "ui/gfx/skia_util.h" | 38 #include "ui/gfx/skia_util.h" |
| 38 | 39 |
| 39 namespace content { | 40 namespace content { |
| 40 | 41 |
| 42 namespace { |
| 43 |
| 44 class IframeSurfaceReferenceFactory |
| 45 : public cc::SequenceSurfaceReferenceFactory { |
| 46 public: |
| 47 IframeSurfaceReferenceFactory(scoped_refptr<ThreadSafeSender> sender, |
| 48 int routing_id) |
| 49 : sender_(std::move(sender)), routing_id_(routing_id) {} |
| 50 |
| 51 private: |
| 52 ~IframeSurfaceReferenceFactory() override = default; |
| 53 |
| 54 // cc::SequenceSurfaceReferenceFactory implementation: |
| 55 void RequireSequence(const cc::SurfaceId& surface_id, |
| 56 const cc::SurfaceSequence& sequence) const override { |
| 57 sender_->Send( |
| 58 new FrameHostMsg_RequireSequence(routing_id_, surface_id, sequence)); |
| 59 } |
| 60 |
| 61 void SatisfySequence(const cc::SurfaceSequence& sequence) const override { |
| 62 sender_->Send(new FrameHostMsg_SatisfySequence(routing_id_, sequence)); |
| 63 } |
| 64 |
| 65 const scoped_refptr<ThreadSafeSender> sender_; |
| 66 const int routing_id_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(IframeSurfaceReferenceFactory); |
| 69 }; |
| 70 |
| 71 class BrowserPluginSurfaceReferenceFactory |
| 72 : public cc::SequenceSurfaceReferenceFactory { |
| 73 public: |
| 74 BrowserPluginSurfaceReferenceFactory(scoped_refptr<ThreadSafeSender> sender, |
| 75 int routing_id, |
| 76 int browser_plugin_instance_id) |
| 77 : sender_(std::move(sender)), |
| 78 routing_id_(routing_id), |
| 79 browser_plugin_instance_id_(browser_plugin_instance_id) {} |
| 80 |
| 81 private: |
| 82 ~BrowserPluginSurfaceReferenceFactory() override = default; |
| 83 |
| 84 // cc::SequenceSurfaceRefrenceFactory implementation: |
| 85 void SatisfySequence(const cc::SurfaceSequence& seq) const override { |
| 86 sender_->Send(new BrowserPluginHostMsg_SatisfySequence( |
| 87 routing_id_, browser_plugin_instance_id_, seq)); |
| 88 } |
| 89 |
| 90 void RequireSequence(const cc::SurfaceId& surface_id, |
| 91 const cc::SurfaceSequence& sequence) const override { |
| 92 sender_->Send(new BrowserPluginHostMsg_RequireSequence( |
| 93 routing_id_, browser_plugin_instance_id_, surface_id, sequence)); |
| 94 } |
| 95 |
| 96 const scoped_refptr<ThreadSafeSender> sender_; |
| 97 const int routing_id_; |
| 98 const int browser_plugin_instance_id_; |
| 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(BrowserPluginSurfaceReferenceFactory); |
| 101 }; |
| 102 |
| 103 } // namespace |
| 104 |
| 41 ChildFrameCompositingHelper* | 105 ChildFrameCompositingHelper* |
| 42 ChildFrameCompositingHelper::CreateForBrowserPlugin( | 106 ChildFrameCompositingHelper::CreateForBrowserPlugin( |
| 43 const base::WeakPtr<BrowserPlugin>& browser_plugin) { | 107 const base::WeakPtr<BrowserPlugin>& browser_plugin) { |
| 44 return new ChildFrameCompositingHelper( | 108 return new ChildFrameCompositingHelper( |
| 45 browser_plugin, nullptr, nullptr, | 109 browser_plugin, nullptr, nullptr, |
| 46 browser_plugin->render_frame_routing_id()); | 110 browser_plugin->render_frame_routing_id()); |
| 47 } | 111 } |
| 48 | 112 |
| 49 ChildFrameCompositingHelper* | 113 ChildFrameCompositingHelper* |
| 50 ChildFrameCompositingHelper::CreateForRenderFrameProxy( | 114 ChildFrameCompositingHelper::CreateForRenderFrameProxy( |
| 51 RenderFrameProxy* render_frame_proxy) { | 115 RenderFrameProxy* render_frame_proxy) { |
| 52 return new ChildFrameCompositingHelper( | 116 return new ChildFrameCompositingHelper( |
| 53 base::WeakPtr<BrowserPlugin>(), render_frame_proxy->web_frame(), | 117 base::WeakPtr<BrowserPlugin>(), render_frame_proxy->web_frame(), |
| 54 render_frame_proxy, render_frame_proxy->routing_id()); | 118 render_frame_proxy, render_frame_proxy->routing_id()); |
| 55 } | 119 } |
| 56 | 120 |
| 57 ChildFrameCompositingHelper::ChildFrameCompositingHelper( | 121 ChildFrameCompositingHelper::ChildFrameCompositingHelper( |
| 58 const base::WeakPtr<BrowserPlugin>& browser_plugin, | 122 const base::WeakPtr<BrowserPlugin>& browser_plugin, |
| 59 blink::WebRemoteFrame* frame, | 123 blink::WebRemoteFrame* frame, |
| 60 RenderFrameProxy* render_frame_proxy, | 124 RenderFrameProxy* render_frame_proxy, |
| 61 int host_routing_id) | 125 int host_routing_id) |
| 62 : host_routing_id_(host_routing_id), | 126 : host_routing_id_(host_routing_id), |
| 63 browser_plugin_(browser_plugin), | 127 browser_plugin_(browser_plugin), |
| 64 render_frame_proxy_(render_frame_proxy), | 128 render_frame_proxy_(render_frame_proxy), |
| 65 frame_(frame) {} | 129 frame_(frame) { |
| 130 scoped_refptr<ThreadSafeSender> sender( |
| 131 RenderThreadImpl::current()->thread_safe_sender()); |
| 132 if (render_frame_proxy_) { |
| 133 surface_reference_factory_ = |
| 134 new IframeSurfaceReferenceFactory(sender, host_routing_id_); |
| 135 } else { |
| 136 surface_reference_factory_ = new BrowserPluginSurfaceReferenceFactory( |
| 137 sender, host_routing_id_, |
| 138 browser_plugin_->browser_plugin_instance_id()); |
| 139 } |
| 140 } |
| 66 | 141 |
| 67 ChildFrameCompositingHelper::~ChildFrameCompositingHelper() { | 142 ChildFrameCompositingHelper::~ChildFrameCompositingHelper() { |
| 68 } | 143 } |
| 69 | 144 |
| 70 blink::WebPluginContainer* ChildFrameCompositingHelper::GetContainer() { | 145 blink::WebPluginContainer* ChildFrameCompositingHelper::GetContainer() { |
| 71 if (!browser_plugin_) | 146 if (!browser_plugin_) |
| 72 return nullptr; | 147 return nullptr; |
| 73 | 148 |
| 74 return browser_plugin_->container(); | 149 return browser_plugin_->container(); |
| 75 } | 150 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 201 |
| 127 crashed_layer->AddChild(sad_layer); | 202 crashed_layer->AddChild(sad_layer); |
| 128 } | 203 } |
| 129 } | 204 } |
| 130 | 205 |
| 131 std::unique_ptr<blink::WebLayer> layer( | 206 std::unique_ptr<blink::WebLayer> layer( |
| 132 new cc_blink::WebLayerImpl(crashed_layer)); | 207 new cc_blink::WebLayerImpl(crashed_layer)); |
| 133 UpdateWebLayer(std::move(layer)); | 208 UpdateWebLayer(std::move(layer)); |
| 134 } | 209 } |
| 135 | 210 |
| 136 // static | |
| 137 void ChildFrameCompositingHelper::SatisfyCallback( | |
| 138 scoped_refptr<ThreadSafeSender> sender, | |
| 139 int host_routing_id, | |
| 140 const cc::SurfaceSequence& sequence) { | |
| 141 // This may be called on either the main or impl thread. | |
| 142 sender->Send(new FrameHostMsg_SatisfySequence(host_routing_id, sequence)); | |
| 143 } | |
| 144 | |
| 145 // static | |
| 146 void ChildFrameCompositingHelper::SatisfyCallbackBrowserPlugin( | |
| 147 scoped_refptr<ThreadSafeSender> sender, | |
| 148 int host_routing_id, | |
| 149 int browser_plugin_instance_id, | |
| 150 const cc::SurfaceSequence& sequence) { | |
| 151 sender->Send(new BrowserPluginHostMsg_SatisfySequence( | |
| 152 host_routing_id, browser_plugin_instance_id, sequence)); | |
| 153 } | |
| 154 | |
| 155 // static | |
| 156 void ChildFrameCompositingHelper::RequireCallback( | |
| 157 scoped_refptr<ThreadSafeSender> sender, | |
| 158 int host_routing_id, | |
| 159 const cc::SurfaceId& id, | |
| 160 const cc::SurfaceSequence& sequence) { | |
| 161 // This may be called on either the main or impl thread. | |
| 162 sender->Send(new FrameHostMsg_RequireSequence(host_routing_id, id, sequence)); | |
| 163 } | |
| 164 | |
| 165 void ChildFrameCompositingHelper::RequireCallbackBrowserPlugin( | |
| 166 scoped_refptr<ThreadSafeSender> sender, | |
| 167 int host_routing_id, | |
| 168 int browser_plugin_instance_id, | |
| 169 const cc::SurfaceId& id, | |
| 170 const cc::SurfaceSequence& sequence) { | |
| 171 // This may be called on either the main or impl thread. | |
| 172 sender->Send(new BrowserPluginHostMsg_RequireSequence( | |
| 173 host_routing_id, browser_plugin_instance_id, id, sequence)); | |
| 174 } | |
| 175 | |
| 176 void ChildFrameCompositingHelper::OnSetSurface( | 211 void ChildFrameCompositingHelper::OnSetSurface( |
| 177 const cc::SurfaceId& surface_id, | 212 const cc::SurfaceId& surface_id, |
| 178 const gfx::Size& frame_size, | 213 const gfx::Size& frame_size, |
| 179 float scale_factor, | 214 float scale_factor, |
| 180 const cc::SurfaceSequence& sequence) { | 215 const cc::SurfaceSequence& sequence) { |
| 181 surface_id_ = surface_id; | 216 surface_id_ = surface_id; |
| 182 scoped_refptr<ThreadSafeSender> sender( | |
| 183 RenderThreadImpl::current()->thread_safe_sender()); | |
| 184 cc::SurfaceLayer::SatisfyCallback satisfy_callback = | |
| 185 render_frame_proxy_ | |
| 186 ? base::Bind(&ChildFrameCompositingHelper::SatisfyCallback, sender, | |
| 187 host_routing_id_) | |
| 188 : base::Bind( | |
| 189 &ChildFrameCompositingHelper::SatisfyCallbackBrowserPlugin, | |
| 190 sender, host_routing_id_, | |
| 191 browser_plugin_->browser_plugin_instance_id()); | |
| 192 cc::SurfaceLayer::RequireCallback require_callback = | |
| 193 render_frame_proxy_ | |
| 194 ? base::Bind(&ChildFrameCompositingHelper::RequireCallback, sender, | |
| 195 host_routing_id_) | |
| 196 : base::Bind( | |
| 197 &ChildFrameCompositingHelper::RequireCallbackBrowserPlugin, | |
| 198 sender, host_routing_id_, | |
| 199 browser_plugin_->browser_plugin_instance_id()); | |
| 200 scoped_refptr<cc::SurfaceLayer> surface_layer = | 217 scoped_refptr<cc::SurfaceLayer> surface_layer = |
| 201 cc::SurfaceLayer::Create(satisfy_callback, require_callback); | 218 cc::SurfaceLayer::Create(surface_reference_factory_); |
| 202 // TODO(oshima): This is a stopgap fix so that the compositor does not | 219 // TODO(oshima): This is a stopgap fix so that the compositor does not |
| 203 // scaledown the content when 2x frame data is added to 1x parent frame data. | 220 // scaledown the content when 2x frame data is added to 1x parent frame data. |
| 204 // Fix this in cc/. | 221 // Fix this in cc/. |
| 205 if (IsUseZoomForDSFEnabled()) | 222 if (IsUseZoomForDSFEnabled()) |
| 206 scale_factor = 1.0f; | 223 scale_factor = 1.0f; |
| 207 | 224 cc::SurfaceInfo info(surface_id, scale_factor, frame_size); |
| 208 surface_layer->SetSurfaceId(surface_id, scale_factor, frame_size); | 225 surface_layer->SetSurfaceInfo(info); |
| 209 surface_layer->SetMasksToBounds(true); | 226 surface_layer->SetMasksToBounds(true); |
| 210 std::unique_ptr<cc_blink::WebLayerImpl> layer( | 227 std::unique_ptr<cc_blink::WebLayerImpl> layer( |
| 211 new cc_blink::WebLayerImpl(surface_layer)); | 228 new cc_blink::WebLayerImpl(surface_layer)); |
| 212 // TODO(lfg): Investigate if it's possible to propagate the information about | 229 // TODO(lfg): Investigate if it's possible to propagate the information about |
| 213 // the child surface's opacity. https://crbug.com/629851. | 230 // the child surface's opacity. https://crbug.com/629851. |
| 214 layer->setOpaque(false); | 231 layer->setOpaque(false); |
| 215 layer->SetContentsOpaqueIsFixed(true); | 232 layer->SetContentsOpaqueIsFixed(true); |
| 216 UpdateWebLayer(std::move(layer)); | 233 UpdateWebLayer(std::move(layer)); |
| 217 | 234 |
| 218 UpdateVisibility(true); | 235 UpdateVisibility(true); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 232 frame_size, scale_factor, | 249 frame_size, scale_factor, |
| 233 static_cast<cc_blink::WebLayerImpl*>(web_layer_.get())->layer()); | 250 static_cast<cc_blink::WebLayerImpl*>(web_layer_.get())->layer()); |
| 234 } | 251 } |
| 235 | 252 |
| 236 void ChildFrameCompositingHelper::UpdateVisibility(bool visible) { | 253 void ChildFrameCompositingHelper::UpdateVisibility(bool visible) { |
| 237 if (web_layer_) | 254 if (web_layer_) |
| 238 web_layer_->setDrawsContent(visible); | 255 web_layer_->setDrawsContent(visible); |
| 239 } | 256 } |
| 240 | 257 |
| 241 } // namespace content | 258 } // namespace content |
| OLD | NEW |