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

Side by Side Diff: content/browser/frame_host/render_widget_host_view_child_frame.cc

Issue 1094113003: Allow out-of-process iframes to render to compositing surfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Destroy Surface when resetting id Created 5 years, 6 months 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/browser/frame_host/render_widget_host_view_child_frame.h" 5 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
6 6
7 #include "cc/surfaces/surface.h"
8 #include "cc/surfaces/surface_factory.h"
9 #include "cc/surfaces/surface_manager.h"
10 #include "cc/surfaces/surface_sequence.h"
7 #include "content/browser/accessibility/browser_accessibility_manager.h" 11 #include "content/browser/accessibility/browser_accessibility_manager.h"
8 #include "content/browser/frame_host/cross_process_frame_connector.h" 12 #include "content/browser/frame_host/cross_process_frame_connector.h"
13 #include "content/browser/gpu/compositor_util.h"
9 #include "content/browser/renderer_host/render_widget_host_impl.h" 14 #include "content/browser/renderer_host/render_widget_host_impl.h"
10 #include "content/common/gpu/gpu_messages.h" 15 #include "content/common/gpu/gpu_messages.h"
11 #include "content/common/view_messages.h" 16 #include "content/common/view_messages.h"
12 #include "content/public/browser/render_process_host.h" 17 #include "content/public/browser/render_process_host.h"
13 18
14 namespace content { 19 namespace content {
15 20
16 RenderWidgetHostViewChildFrame::RenderWidgetHostViewChildFrame( 21 RenderWidgetHostViewChildFrame::RenderWidgetHostViewChildFrame(
17 RenderWidgetHost* widget_host) 22 RenderWidgetHost* widget_host)
18 : host_(RenderWidgetHostImpl::From(widget_host)), 23 : host_(RenderWidgetHostImpl::From(widget_host)),
24 use_surfaces_(UseSurfacesEnabled()),
25 next_surface_sequence_(1u),
26 last_output_surface_id_(0),
27 current_surface_scale_factor_(1.f),
28 ack_pending_count_(0),
19 frame_connector_(NULL) { 29 frame_connector_(NULL) {
30 #if !defined(OS_ANDROID)
31 if (use_surfaces_) {
32 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
33 id_allocator_ = factory->GetContextFactory()->CreateSurfaceIdAllocator();
34 }
35 #endif // !defined(OS_ANDROID)
36
20 host_->SetView(this); 37 host_->SetView(this);
21 } 38 }
22 39
23 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() { 40 RenderWidgetHostViewChildFrame::~RenderWidgetHostViewChildFrame() {
ncarter (slow) 2015/05/28 22:32:52 If there are still entries in surface_returned_res
kenrb 2015/05/29 19:29:36 John answered this separately, but yes: RWHVCF bei
41 if (!surface_id_.is_null())
42 surface_factory_->Destroy(surface_id_);
24 } 43 }
25 44
26 void RenderWidgetHostViewChildFrame::InitAsChild( 45 void RenderWidgetHostViewChildFrame::InitAsChild(
27 gfx::NativeView parent_view) { 46 gfx::NativeView parent_view) {
28 NOTREACHED(); 47 NOTREACHED();
29 } 48 }
30 49
31 RenderWidgetHost* RenderWidgetHostViewChildFrame::GetRenderWidgetHost() const { 50 RenderWidgetHost* RenderWidgetHostViewChildFrame::GetRenderWidgetHost() const {
32 return host_; 51 return host_;
33 } 52 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 198 }
180 199
181 #if defined(OS_ANDROID) 200 #if defined(OS_ANDROID)
182 void RenderWidgetHostViewChildFrame::LockCompositingSurface() { 201 void RenderWidgetHostViewChildFrame::LockCompositingSurface() {
183 } 202 }
184 203
185 void RenderWidgetHostViewChildFrame::UnlockCompositingSurface() { 204 void RenderWidgetHostViewChildFrame::UnlockCompositingSurface() {
186 } 205 }
187 #endif 206 #endif
188 207
208 void RenderWidgetHostViewChildFrame::SurfaceDrawn(uint32 output_surface_id,
209 cc::SurfaceDrawStatus drawn) {
210 cc::CompositorFrameAck ack;
211 DCHECK(ack_pending_count_ > 0);
212 if (!surface_returned_resources_.empty())
213 ack.resources.swap(surface_returned_resources_);
214 if (host_)
nasko 2015/05/28 20:42:36 nit: Two line body requires {}.
kenrb 2015/05/29 19:29:36 Done.
215 host_->Send(new ViewMsg_SwapCompositorFrameAck(host_->GetRoutingID(),
216 output_surface_id, ack));
217 ack_pending_count_--;
218 }
219
189 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame( 220 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame(
190 uint32 output_surface_id, 221 uint32 output_surface_id,
191 scoped_ptr<cc::CompositorFrame> frame) { 222 scoped_ptr<cc::CompositorFrame> frame) {
192 last_scroll_offset_ = frame->metadata.root_scroll_offset; 223 last_scroll_offset_ = frame->metadata.root_scroll_offset;
193 if (frame_connector_) { 224
225 if (!frame_connector_)
226 return;
227
228 // When not using surfaces, the frame just gets proxied to
229 // the embedder's renderer to be composited.
230 if (!frame->delegated_frame_data || !use_surfaces_) {
194 frame_connector_->ChildFrameCompositorFrameSwapped( 231 frame_connector_->ChildFrameCompositorFrameSwapped(
195 output_surface_id, 232 output_surface_id,
196 host_->GetProcess()->GetID(), 233 host_->GetProcess()->GetID(),
197 host_->GetRoutingID(), 234 host_->GetRoutingID(),
198 frame.Pass()); 235 frame.Pass());
236 return;
199 } 237 }
238
239 #if !defined(OS_ANDROID)
240 cc::RenderPass* root_pass =
241 frame->delegated_frame_data->render_pass_list.back();
242
243 gfx::Size frame_size = root_pass->output_rect.size();
244 float scale_factor = frame->metadata.device_scale_factor;
245
246 // Check whether we need to recreate the cc::Surface, which means the child
247 // frame renderer has changed its output surface, or size, or scale factor.
248 if (output_surface_id != last_output_surface_id_ && surface_factory_) {
249 surface_factory_->Destroy(surface_id_);
250 surface_factory_.reset();
ncarter (slow) 2015/05/28 22:32:52 Why do we need a new SurfaceFactory each time the
kenrb 2015/05/29 19:29:36 Answered.
251 }
252 if (output_surface_id != last_output_surface_id_ ||
253 frame_size != current_surface_size_ ||
254 scale_factor != current_surface_scale_factor_) {
255 if (surface_factory_ && !surface_id_.is_null())
256 surface_factory_->Destroy(surface_id_);
257 surface_id_ = cc::SurfaceId();
258 last_output_surface_id_ = output_surface_id;
259 current_surface_size_ = frame_size;
260 current_surface_scale_factor_ = scale_factor;
261 }
262
263 if (!surface_factory_) {
264 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
265 cc::SurfaceManager* manager = factory->GetSurfaceManager();
266 surface_factory_ = make_scoped_ptr(new cc::SurfaceFactory(manager, this));
267 }
268
269 if (surface_id_.is_null()) {
270 surface_id_ = id_allocator_->GenerateId();
271 surface_factory_->Create(surface_id_);
272
273 ImageTransportFactory* factory = ImageTransportFactory::GetInstance();
274 cc::SurfaceSequence sequence = cc::SurfaceSequence(
275 id_allocator_->id_namespace(), next_surface_sequence_++);
276 // The renderer will satisfy this dependency when it creates a
nasko 2015/05/28 20:42:36 nit: s/renderer/renderer process/?
kenrb 2015/05/29 19:29:36 Done.
277 // SurfaceLayer.
278 factory->GetSurfaceManager()
279 ->GetSurfaceForId(surface_id_)
280 ->AddDestructionDependency(sequence);
281 frame_connector_->SetChildFrameSurface(surface_id_, frame_size,
282 scale_factor, sequence);
283 }
284
285 cc::SurfaceFactory::DrawCallback ack_callback =
286 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(),
287 output_surface_id);
288 ack_pending_count_++;
ncarter (slow) 2015/05/28 22:32:52 Could we dcheck some upper limit for ack_pending_c
kenrb 2015/05/29 19:29:36 That's a good idea. I don't really know what a saf
289 surface_factory_->SubmitFrame(surface_id_, frame.Pass(), ack_callback);
290 #endif // !defined(OS_ANDROID)
200 } 291 }
201 292
202 void RenderWidgetHostViewChildFrame::GetScreenInfo( 293 void RenderWidgetHostViewChildFrame::GetScreenInfo(
203 blink::WebScreenInfo* results) { 294 blink::WebScreenInfo* results) {
204 } 295 }
205 296
206 gfx::Rect RenderWidgetHostViewChildFrame::GetBoundsInRootWindow() { 297 gfx::Rect RenderWidgetHostViewChildFrame::GetBoundsInRootWindow() {
207 // We do not have any root window specific parts in this view. 298 // We do not have any root window specific parts in this view.
208 return GetViewBounds(); 299 return GetViewBounds();
209 } 300 }
210 301
211 #if defined(USE_AURA) 302 #if defined(USE_AURA)
212 void RenderWidgetHostViewChildFrame::ProcessAckedTouchEvent( 303 void RenderWidgetHostViewChildFrame::ProcessAckedTouchEvent(
213 const TouchEventWithLatencyInfo& touch, 304 const TouchEventWithLatencyInfo& touch,
214 InputEventAckState ack_result) { 305 InputEventAckState ack_result) {
215 } 306 }
216 #endif // defined(USE_AURA) 307 #endif // defined(USE_AURA)
217 308
218 bool RenderWidgetHostViewChildFrame::LockMouse() { 309 bool RenderWidgetHostViewChildFrame::LockMouse() {
219 return false; 310 return false;
220 } 311 }
221 312
222 void RenderWidgetHostViewChildFrame::UnlockMouse() { 313 void RenderWidgetHostViewChildFrame::UnlockMouse() {
223 } 314 }
224 315
225 uint32_t RenderWidgetHostViewChildFrame::GetSurfaceIdNamespace() { 316 uint32_t RenderWidgetHostViewChildFrame::GetSurfaceIdNamespace() {
226 // TODO(kenrb): Create SurfaceFactory here when RWHVChildFrame 317 if (!use_surfaces_)
227 // gets compositor surface support. 318 return 0;
228 return 0; 319
320 return id_allocator_->id_namespace();
229 } 321 }
230 322
231 #if defined(OS_MACOSX) 323 #if defined(OS_MACOSX)
232 void RenderWidgetHostViewChildFrame::SetActive(bool active) { 324 void RenderWidgetHostViewChildFrame::SetActive(bool active) {
233 } 325 }
234 326
235 void RenderWidgetHostViewChildFrame::SetWindowVisibility(bool visible) { 327 void RenderWidgetHostViewChildFrame::SetWindowVisibility(bool visible) {
236 } 328 }
237 329
238 void RenderWidgetHostViewChildFrame::WindowFrameChanged() { 330 void RenderWidgetHostViewChildFrame::WindowFrameChanged() {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 void RenderWidgetHostViewChildFrame::SetParentNativeViewAccessible( 386 void RenderWidgetHostViewChildFrame::SetParentNativeViewAccessible(
295 gfx::NativeViewAccessible accessible_parent) { 387 gfx::NativeViewAccessible accessible_parent) {
296 } 388 }
297 389
298 gfx::NativeViewId RenderWidgetHostViewChildFrame::GetParentForWindowlessPlugin() 390 gfx::NativeViewId RenderWidgetHostViewChildFrame::GetParentForWindowlessPlugin()
299 const { 391 const {
300 return NULL; 392 return NULL;
301 } 393 }
302 #endif // defined(OS_WIN) 394 #endif // defined(OS_WIN)
303 395
396 // cc::SurfaceFactoryClient implementation.
397 void RenderWidgetHostViewChildFrame::ReturnResources(
398 const cc::ReturnedResourceArray& resources) {
399 if (resources.empty())
400 return;
401
402 if (!ack_pending_count_ && host_) {
403 cc::CompositorFrameAck ack;
404 std::copy(resources.begin(), resources.end(),
405 std::back_inserter(ack.resources));
406 host_->Send(new ViewMsg_ReclaimCompositorResources(
407 host_->GetRoutingID(), last_output_surface_id_, ack));
408 return;
409 }
410
411 std::copy(resources.begin(), resources.end(),
412 std::back_inserter(surface_returned_resources_));
413 }
414
304 BrowserAccessibilityManager* 415 BrowserAccessibilityManager*
305 RenderWidgetHostViewChildFrame::CreateBrowserAccessibilityManager( 416 RenderWidgetHostViewChildFrame::CreateBrowserAccessibilityManager(
306 BrowserAccessibilityDelegate* delegate) { 417 BrowserAccessibilityDelegate* delegate) {
307 return BrowserAccessibilityManager::Create( 418 return BrowserAccessibilityManager::Create(
308 BrowserAccessibilityManager::GetEmptyDocument(), delegate); 419 BrowserAccessibilityManager::GetEmptyDocument(), delegate);
309 } 420 }
310 421
311 } // namespace content 422 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698