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

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

Issue 2633303003: Clean up RenderWidgetHostView(ChildFrame and Guest) compositing code (Closed)
Patch Set: c Created 3 years, 11 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 <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "cc/output/copy_output_request.h" 16 #include "cc/output/copy_output_request.h"
17 #include "cc/output/copy_output_result.h" 17 #include "cc/output/copy_output_result.h"
18 #include "cc/surfaces/surface.h" 18 #include "cc/surfaces/surface.h"
19 #include "cc/surfaces/surface_factory.h" 19 #include "cc/surfaces/surface_factory.h"
20 #include "cc/surfaces/surface_manager.h" 20 #include "cc/surfaces/surface_manager.h"
21 #include "cc/surfaces/surface_sequence.h"
22 #include "content/browser/accessibility/browser_accessibility_manager.h" 21 #include "content/browser/accessibility/browser_accessibility_manager.h"
23 #include "content/browser/browser_plugin/browser_plugin_guest.h" 22 #include "content/browser/browser_plugin/browser_plugin_guest.h"
24 #include "content/browser/compositor/surface_utils.h" 23 #include "content/browser/compositor/surface_utils.h"
25 #include "content/browser/frame_host/cross_process_frame_connector.h" 24 #include "content/browser/frame_host/cross_process_frame_connector.h"
26 #include "content/browser/gpu/compositor_util.h" 25 #include "content/browser/gpu/compositor_util.h"
27 #include "content/browser/renderer_host/render_view_host_impl.h" 26 #include "content/browser/renderer_host/render_view_host_impl.h"
28 #include "content/browser/renderer_host/render_widget_host_delegate.h" 27 #include "content/browser/renderer_host/render_widget_host_delegate.h"
29 #include "content/browser/renderer_host/render_widget_host_impl.h" 28 #include "content/browser/renderer_host/render_widget_host_impl.h"
30 #include "content/browser/renderer_host/render_widget_host_input_event_router.h" 29 #include "content/browser/renderer_host/render_widget_host_input_event_router.h"
31 #include "content/common/text_input_state.h" 30 #include "content/common/text_input_state.h"
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 DCHECK_GT(ack_pending_count_, 0U); 366 DCHECK_GT(ack_pending_count_, 0U);
368 if (host_) { 367 if (host_) {
369 host_->Send(new ViewMsg_ReclaimCompositorResources( 368 host_->Send(new ViewMsg_ReclaimCompositorResources(
370 host_->GetRoutingID(), compositor_frame_sink_id, true /* is_swap_ack */, 369 host_->GetRoutingID(), compositor_frame_sink_id, true /* is_swap_ack */,
371 surface_returned_resources_)); 370 surface_returned_resources_));
372 surface_returned_resources_.clear(); 371 surface_returned_resources_.clear();
373 } 372 }
374 ack_pending_count_--; 373 ack_pending_count_--;
375 } 374 }
376 375
377 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame( 376 bool RenderWidgetHostViewChildFrame::ShouldRecreateSurface(
Fady Samuel 2017/01/18 01:03:43 I think ShouldCreateNewSurfaceId better captures w
Saman Sami 2017/01/18 18:15:53 Done.
377 uint32_t compositor_frame_sink_id,
378 const cc::CompositorFrame& frame) {
379 gfx::Size new_frame_size = frame.render_pass_list.back()->output_rect.size();
380 float new_scale_factor = frame.metadata.device_scale_factor;
381
382 return compositor_frame_sink_id != last_compositor_frame_sink_id_ ||
383 new_frame_size != current_surface_size_ ||
384 new_scale_factor != current_surface_scale_factor_;
385 }
386
387 void RenderWidgetHostViewChildFrame::ProcessCompositorFrame(
378 uint32_t compositor_frame_sink_id, 388 uint32_t compositor_frame_sink_id,
379 cc::CompositorFrame frame) { 389 cc::CompositorFrame frame) {
380 TRACE_EVENT0("content", 390 if (ShouldRecreateSurface(compositor_frame_sink_id, frame)) {
381 "RenderWidgetHostViewChildFrame::OnSwapCompositorFrame");
382
383 last_scroll_offset_ = frame.metadata.root_scroll_offset;
384
385 if (!frame_connector_)
386 return;
387
388 cc::RenderPass* root_pass = frame.render_pass_list.back().get();
389
390 gfx::Size frame_size = root_pass->output_rect.size();
391 float scale_factor = frame.metadata.device_scale_factor;
392
393 // Check whether we need to recreate the cc::Surface, which means the child
394 // frame renderer has changed its frame sink, or size, or scale factor.
395 if (compositor_frame_sink_id != last_compositor_frame_sink_id_ ||
396 frame_size != current_surface_size_ ||
397 scale_factor != current_surface_scale_factor_) {
398 ClearCompositorSurfaceIfNecessary(); 391 ClearCompositorSurfaceIfNecessary();
399 // If the renderer changed its frame sink, reset the surface factory to 392 // If the renderer changed its frame sink, reset the surface factory to
400 // avoid returning stale resources. 393 // avoid returning stale resources.
401 if (compositor_frame_sink_id != last_compositor_frame_sink_id_) 394 if (compositor_frame_sink_id != last_compositor_frame_sink_id_)
402 surface_factory_->Reset(); 395 surface_factory_->Reset();
403 last_compositor_frame_sink_id_ = compositor_frame_sink_id; 396 last_compositor_frame_sink_id_ = compositor_frame_sink_id;
404 current_surface_size_ = frame_size; 397 current_surface_size_ = frame.render_pass_list.back()->output_rect.size();
405 current_surface_scale_factor_ = scale_factor; 398 current_surface_scale_factor_ = frame.metadata.device_scale_factor;
406 } 399 }
407 400
408 bool allocated_new_local_frame_id = false; 401 bool allocated_new_local_frame_id = false;
409 if (!local_frame_id_.is_valid()) { 402 if (!local_frame_id_.is_valid()) {
410 local_frame_id_ = id_allocator_->GenerateId(); 403 local_frame_id_ = id_allocator_->GenerateId();
411 allocated_new_local_frame_id = true; 404 allocated_new_local_frame_id = true;
412 } 405 }
413 406
414 cc::SurfaceFactory::DrawCallback ack_callback = 407 cc::SurfaceFactory::DrawCallback ack_callback =
415 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(), 408 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(),
416 compositor_frame_sink_id); 409 compositor_frame_sink_id);
417 ack_pending_count_++; 410 ack_pending_count_++;
418 // If this value grows very large, something is going wrong. 411 // If this value grows very large, something is going wrong.
419 DCHECK_LT(ack_pending_count_, 1000U); 412 DCHECK_LT(ack_pending_count_, 1000U);
420 surface_factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame), 413 surface_factory_->SubmitCompositorFrame(local_frame_id_, std::move(frame),
421 ack_callback); 414 ack_callback);
415 if (allocated_new_local_frame_id)
416 SendSurfaceInfoToChild();
417 ProcessFrameSwappedCallbacks();
418 }
422 419
423 if (allocated_new_local_frame_id) { 420 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToChild() {
Fady Samuel 2017/01/18 01:03:43 This should be called SendSurfaceInfoToEmbedder
Saman Sami 2017/01/18 18:15:53 Done.
424 cc::SurfaceSequence sequence = 421 cc::SurfaceSequence sequence =
425 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++); 422 cc::SurfaceSequence(frame_sink_id_, next_surface_sequence_++);
426 // The renderer process will satisfy this dependency when it creates a 423 cc::SurfaceManager* manager = GetSurfaceManager();
427 // SurfaceLayer. 424 cc::SurfaceId surface_id(frame_sink_id_, local_frame_id_);
428 cc::SurfaceManager* manager = GetSurfaceManager(); 425 // The renderer process will satisfy this dependency when it creates a
429 manager->GetSurfaceForId(cc::SurfaceId(frame_sink_id_, local_frame_id_)) 426 // SurfaceLayer.
430 ->AddDestructionDependency(sequence); 427 manager->GetSurfaceForId(surface_id)->AddDestructionDependency(sequence);
431 frame_connector_->SetChildFrameSurface( 428 cc::SurfaceInfo surface_info(surface_id, current_surface_scale_factor_,
432 cc::SurfaceId(frame_sink_id_, local_frame_id_), frame_size, 429 current_surface_size_);
433 scale_factor, sequence); 430 SendSurfaceInfoToChild(surface_info, sequence);
434 } 431 }
435 ProcessFrameSwappedCallbacks(); 432
433 void RenderWidgetHostViewChildFrame::SendSurfaceInfoToChild(
Fady Samuel 2017/01/18 01:03:43 SendSurfaceInfoToEmbedder
Saman Sami 2017/01/18 18:15:53 Done.
434 const cc::SurfaceInfo& surface_info,
435 const cc::SurfaceSequence& sequence) {
436 frame_connector_->SetChildFrameSurface(surface_info, sequence);
437 }
438
439 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame(
440 uint32_t compositor_frame_sink_id,
441 cc::CompositorFrame frame) {
442 TRACE_EVENT0("content",
443 "RenderWidgetHostViewChildFrame::OnSwapCompositorFrame");
444 last_scroll_offset_ = frame.metadata.root_scroll_offset;
445 if (!frame_connector_)
446 return;
447 ProcessCompositorFrame(compositor_frame_sink_id, std::move(frame));
436 } 448 }
437 449
438 void RenderWidgetHostViewChildFrame::ProcessFrameSwappedCallbacks() { 450 void RenderWidgetHostViewChildFrame::ProcessFrameSwappedCallbacks() {
439 // We only use callbacks once, therefore we make a new list for registration 451 // We only use callbacks once, therefore we make a new list for registration
440 // before we start, and discard the old list entries when we are done. 452 // before we start, and discard the old list entries when we are done.
441 FrameSwappedCallbackList process_callbacks; 453 FrameSwappedCallbackList process_callbacks;
442 process_callbacks.swap(frame_swapped_callbacks_); 454 process_callbacks.swap(frame_swapped_callbacks_);
443 for (std::unique_ptr<base::Closure>& callback : process_callbacks) 455 for (std::unique_ptr<base::Closure>& callback : process_callbacks)
444 callback->Run(); 456 callback->Run();
445 } 457 }
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 756
745 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const { 757 bool RenderWidgetHostViewChildFrame::IsChildFrameForTesting() const {
746 return true; 758 return true;
747 } 759 }
748 760
749 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const { 761 cc::SurfaceId RenderWidgetHostViewChildFrame::SurfaceIdForTesting() const {
750 return cc::SurfaceId(frame_sink_id_, local_frame_id_); 762 return cc::SurfaceId(frame_sink_id_, local_frame_id_);
751 }; 763 };
752 764
753 } // namespace content 765 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698