Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: content/renderer/child_frame_compositing_helper.cc

Issue 2514033002: Introducing SurfaceReferenceFactory (Closed)
Patch Set: up Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_(sender), routing_id_(routing_id) {}
50
51 protected:
Fady Samuel 2016/12/13 22:55:06 Can you mark this as private?
Saman Sami 2016/12/14 17:50:02 Done.
52 ~IframeSurfaceReferenceFactory() override = default;
53
54 private:
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 }
Fady Samuel 2016/12/13 22:55:05 nit: leave blank line.
Saman Sami 2016/12/14 17:50:02 Done.
60 void SatisfySequence(const cc::SurfaceSequence& sequence) const override {
61 sender_->Send(new FrameHostMsg_SatisfySequence(routing_id_, sequence));
62 }
63
64 const scoped_refptr<ThreadSafeSender> sender_;
65 const int routing_id_;
66
67 DISALLOW_COPY_AND_ASSIGN(IframeSurfaceReferenceFactory);
68 };
69
70 class BrowserPluginSurfaceReferenceFactory
71 : public cc::SequenceSurfaceReferenceFactory {
72 public:
73 BrowserPluginSurfaceReferenceFactory(scoped_refptr<ThreadSafeSender> sender,
74 int routing_id,
75 int browser_plugin_instance_id)
76 : sender_(sender),
77 routing_id_(routing_id),
78 browser_plugin_instance_id_(browser_plugin_instance_id) {}
79
80 protected:
Fady Samuel 2016/12/13 22:55:05 Mark it as private?
Saman Sami 2016/12/14 17:50:02 Done.
81 ~BrowserPluginSurfaceReferenceFactory() override = default;
82
83 private:
84 void SatisfySequence(const cc::SurfaceSequence& seq) const override {
85 sender_->Send(new BrowserPluginHostMsg_SatisfySequence(
86 routing_id_, browser_plugin_instance_id_, seq));
87 }
Fady Samuel 2016/12/13 22:55:05 nit: leave blank line.
Saman Sami 2016/12/14 17:50:02 Done.
88 void RequireSequence(const cc::SurfaceId& surface_id,
89 const cc::SurfaceSequence& sequence) const override {
90 sender_->Send(new BrowserPluginHostMsg_RequireSequence(
91 routing_id_, browser_plugin_instance_id_, surface_id, sequence));
92 }
93
94 const scoped_refptr<ThreadSafeSender> sender_;
Fady Samuel 2016/12/13 22:55:06 Weird to make a scoped_refptr const.
Saman Sami 2016/12/14 17:50:02 Done.
95 const int routing_id_;
96 const int browser_plugin_instance_id_;
97
98 DISALLOW_COPY_AND_ASSIGN(BrowserPluginSurfaceReferenceFactory);
99 };
100
101 } // namespace
102
41 ChildFrameCompositingHelper* 103 ChildFrameCompositingHelper*
42 ChildFrameCompositingHelper::CreateForBrowserPlugin( 104 ChildFrameCompositingHelper::CreateForBrowserPlugin(
43 const base::WeakPtr<BrowserPlugin>& browser_plugin) { 105 const base::WeakPtr<BrowserPlugin>& browser_plugin) {
44 return new ChildFrameCompositingHelper( 106 return new ChildFrameCompositingHelper(
45 browser_plugin, nullptr, nullptr, 107 browser_plugin, nullptr, nullptr,
46 browser_plugin->render_frame_routing_id()); 108 browser_plugin->render_frame_routing_id());
47 } 109 }
48 110
49 ChildFrameCompositingHelper* 111 ChildFrameCompositingHelper*
50 ChildFrameCompositingHelper::CreateForRenderFrameProxy( 112 ChildFrameCompositingHelper::CreateForRenderFrameProxy(
51 RenderFrameProxy* render_frame_proxy) { 113 RenderFrameProxy* render_frame_proxy) {
52 return new ChildFrameCompositingHelper( 114 return new ChildFrameCompositingHelper(
53 base::WeakPtr<BrowserPlugin>(), render_frame_proxy->web_frame(), 115 base::WeakPtr<BrowserPlugin>(), render_frame_proxy->web_frame(),
54 render_frame_proxy, render_frame_proxy->routing_id()); 116 render_frame_proxy, render_frame_proxy->routing_id());
55 } 117 }
56 118
57 ChildFrameCompositingHelper::ChildFrameCompositingHelper( 119 ChildFrameCompositingHelper::ChildFrameCompositingHelper(
58 const base::WeakPtr<BrowserPlugin>& browser_plugin, 120 const base::WeakPtr<BrowserPlugin>& browser_plugin,
59 blink::WebRemoteFrame* frame, 121 blink::WebRemoteFrame* frame,
60 RenderFrameProxy* render_frame_proxy, 122 RenderFrameProxy* render_frame_proxy,
61 int host_routing_id) 123 int host_routing_id)
62 : host_routing_id_(host_routing_id), 124 : host_routing_id_(host_routing_id),
63 browser_plugin_(browser_plugin), 125 browser_plugin_(browser_plugin),
64 render_frame_proxy_(render_frame_proxy), 126 render_frame_proxy_(render_frame_proxy),
65 frame_(frame) {} 127 frame_(frame) {
128 scoped_refptr<ThreadSafeSender> sender(
129 RenderThreadImpl::current()->thread_safe_sender());
130 if (render_frame_proxy_) {
131 surface_reference_factory_ =
132 new IframeSurfaceReferenceFactory(sender, host_routing_id_);
133 } else {
134 surface_reference_factory_ = new BrowserPluginSurfaceReferenceFactory(
135 sender, host_routing_id_,
136 browser_plugin_->browser_plugin_instance_id());
137 }
138 }
66 139
67 ChildFrameCompositingHelper::~ChildFrameCompositingHelper() { 140 ChildFrameCompositingHelper::~ChildFrameCompositingHelper() {
68 } 141 }
69 142
70 blink::WebPluginContainer* ChildFrameCompositingHelper::GetContainer() { 143 blink::WebPluginContainer* ChildFrameCompositingHelper::GetContainer() {
71 if (!browser_plugin_) 144 if (!browser_plugin_)
72 return nullptr; 145 return nullptr;
73 146
74 return browser_plugin_->container(); 147 return browser_plugin_->container();
75 } 148 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 199
127 crashed_layer->AddChild(sad_layer); 200 crashed_layer->AddChild(sad_layer);
128 } 201 }
129 } 202 }
130 203
131 std::unique_ptr<blink::WebLayer> layer( 204 std::unique_ptr<blink::WebLayer> layer(
132 new cc_blink::WebLayerImpl(crashed_layer)); 205 new cc_blink::WebLayerImpl(crashed_layer));
133 UpdateWebLayer(std::move(layer)); 206 UpdateWebLayer(std::move(layer));
134 } 207 }
135 208
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( 209 void ChildFrameCompositingHelper::OnSetSurface(
177 const cc::SurfaceId& surface_id, 210 const cc::SurfaceId& surface_id,
178 const gfx::Size& frame_size, 211 const gfx::Size& frame_size,
179 float scale_factor, 212 float scale_factor,
180 const cc::SurfaceSequence& sequence) { 213 const cc::SurfaceSequence& sequence) {
181 surface_id_ = surface_id; 214 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 = 215 scoped_refptr<cc::SurfaceLayer> surface_layer =
201 cc::SurfaceLayer::Create(satisfy_callback, require_callback); 216 cc::SurfaceLayer::Create(surface_reference_factory_);
202 // TODO(oshima): This is a stopgap fix so that the compositor does not 217 // 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. 218 // scaledown the content when 2x frame data is added to 1x parent frame data.
204 // Fix this in cc/. 219 // Fix this in cc/.
205 if (IsUseZoomForDSFEnabled()) 220 if (IsUseZoomForDSFEnabled())
206 scale_factor = 1.0f; 221 scale_factor = 1.0f;
207 222 cc::SurfaceInfo info(surface_id, scale_factor, frame_size);
208 surface_layer->SetSurfaceId(surface_id, scale_factor, frame_size); 223 surface_layer->SetSurfaceInfo(info);
209 surface_layer->SetMasksToBounds(true); 224 surface_layer->SetMasksToBounds(true);
210 std::unique_ptr<cc_blink::WebLayerImpl> layer( 225 std::unique_ptr<cc_blink::WebLayerImpl> layer(
211 new cc_blink::WebLayerImpl(surface_layer)); 226 new cc_blink::WebLayerImpl(surface_layer));
212 // TODO(lfg): Investigate if it's possible to propagate the information about 227 // TODO(lfg): Investigate if it's possible to propagate the information about
213 // the child surface's opacity. https://crbug.com/629851. 228 // the child surface's opacity. https://crbug.com/629851.
214 layer->setOpaque(false); 229 layer->setOpaque(false);
215 layer->SetContentsOpaqueIsFixed(true); 230 layer->SetContentsOpaqueIsFixed(true);
216 UpdateWebLayer(std::move(layer)); 231 UpdateWebLayer(std::move(layer));
217 232
218 UpdateVisibility(true); 233 UpdateVisibility(true);
(...skipping 13 matching lines...) Expand all
232 frame_size, scale_factor, 247 frame_size, scale_factor,
233 static_cast<cc_blink::WebLayerImpl*>(web_layer_.get())->layer()); 248 static_cast<cc_blink::WebLayerImpl*>(web_layer_.get())->layer());
234 } 249 }
235 250
236 void ChildFrameCompositingHelper::UpdateVisibility(bool visible) { 251 void ChildFrameCompositingHelper::UpdateVisibility(bool visible) {
237 if (web_layer_) 252 if (web_layer_)
238 web_layer_->setDrawsContent(visible); 253 web_layer_->setDrawsContent(visible);
239 } 254 }
240 255
241 } // namespace content 256 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698