Chromium Code Reviews| 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/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 "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "cc/output/copy_output_request.h" | |
| 13 #include "cc/output/copy_output_result.h" | |
| 12 #include "cc/surfaces/surface.h" | 14 #include "cc/surfaces/surface.h" |
| 13 #include "cc/surfaces/surface_factory.h" | 15 #include "cc/surfaces/surface_factory.h" |
| 14 #include "cc/surfaces/surface_manager.h" | 16 #include "cc/surfaces/surface_manager.h" |
| 15 #include "cc/surfaces/surface_sequence.h" | 17 #include "cc/surfaces/surface_sequence.h" |
| 16 #include "content/browser/accessibility/browser_accessibility_manager.h" | 18 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 17 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 19 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 18 #include "content/browser/compositor/surface_utils.h" | 20 #include "content/browser/compositor/surface_utils.h" |
| 19 #include "content/browser/frame_host/cross_process_frame_connector.h" | 21 #include "content/browser/frame_host/cross_process_frame_connector.h" |
| 20 #include "content/browser/gpu/compositor_util.h" | 22 #include "content/browser/gpu/compositor_util.h" |
| 21 #include "content/browser/renderer_host/render_view_host_impl.h" | 23 #include "content/browser/renderer_host/render_view_host_impl.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 void RenderWidgetHostViewChildFrame::Focus() { | 79 void RenderWidgetHostViewChildFrame::Focus() { |
| 78 } | 80 } |
| 79 | 81 |
| 80 bool RenderWidgetHostViewChildFrame::HasFocus() const { | 82 bool RenderWidgetHostViewChildFrame::HasFocus() const { |
| 81 if (frame_connector_) | 83 if (frame_connector_) |
| 82 return frame_connector_->HasFocus(); | 84 return frame_connector_->HasFocus(); |
| 83 return false; | 85 return false; |
| 84 } | 86 } |
| 85 | 87 |
| 86 bool RenderWidgetHostViewChildFrame::IsSurfaceAvailableForCopy() const { | 88 bool RenderWidgetHostViewChildFrame::IsSurfaceAvailableForCopy() const { |
| 87 NOTIMPLEMENTED(); | 89 return surface_factory_ && !surface_id_.is_null(); |
| 88 return false; | |
| 89 } | 90 } |
| 90 | 91 |
| 91 void RenderWidgetHostViewChildFrame::Show() { | 92 void RenderWidgetHostViewChildFrame::Show() { |
| 92 if (!host_->is_hidden()) | 93 if (!host_->is_hidden()) |
| 93 return; | 94 return; |
| 94 host_->WasShown(ui::LatencyInfo()); | 95 host_->WasShown(ui::LatencyInfo()); |
| 95 } | 96 } |
| 96 | 97 |
| 97 void RenderWidgetHostViewChildFrame::Hide() { | 98 void RenderWidgetHostViewChildFrame::Hide() { |
| 98 if (host_->is_hidden()) | 99 if (host_->is_hidden()) |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 } | 315 } |
| 315 | 316 |
| 316 cc::SurfaceFactory::DrawCallback ack_callback = | 317 cc::SurfaceFactory::DrawCallback ack_callback = |
| 317 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(), | 318 base::Bind(&RenderWidgetHostViewChildFrame::SurfaceDrawn, AsWeakPtr(), |
| 318 output_surface_id); | 319 output_surface_id); |
| 319 ack_pending_count_++; | 320 ack_pending_count_++; |
| 320 // If this value grows very large, something is going wrong. | 321 // If this value grows very large, something is going wrong. |
| 321 DCHECK_LT(ack_pending_count_, 1000U); | 322 DCHECK_LT(ack_pending_count_, 1000U); |
| 322 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), | 323 surface_factory_->SubmitCompositorFrame(surface_id_, std::move(frame), |
| 323 ack_callback); | 324 ack_callback); |
| 325 | |
| 326 ProcessFrameSwappedCallbacks(); | |
| 327 } | |
| 328 | |
| 329 void RenderWidgetHostViewChildFrame::ProcessFrameSwappedCallbacks() { | |
| 330 // We only use callbacks once, therefore we make a new list for registration | |
| 331 // before we start, and discard the old list entries when we are done. | |
| 332 FrameSwappedCallbackList process_callbacks; | |
| 333 process_callbacks.swap(frame_swapped_callbacks_); | |
| 334 for (scoped_ptr<base::Closure>& callback : process_callbacks) | |
| 335 callback->Run(); | |
| 324 } | 336 } |
| 325 | 337 |
| 326 void RenderWidgetHostViewChildFrame::GetScreenInfo( | 338 void RenderWidgetHostViewChildFrame::GetScreenInfo( |
| 327 blink::WebScreenInfo* results) { | 339 blink::WebScreenInfo* results) { |
| 328 if (!frame_connector_) | 340 if (!frame_connector_) |
| 329 return; | 341 return; |
| 330 frame_connector_->GetScreenInfo(results); | 342 frame_connector_->GetScreenInfo(results); |
| 331 } | 343 } |
| 332 | 344 |
| 333 bool RenderWidgetHostViewChildFrame::GetScreenColorProfile( | 345 bool RenderWidgetHostViewChildFrame::GetScreenColorProfile( |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 | 427 |
| 416 void RenderWidgetHostViewChildFrame::StopSpeaking() { | 428 void RenderWidgetHostViewChildFrame::StopSpeaking() { |
| 417 } | 429 } |
| 418 | 430 |
| 419 bool RenderWidgetHostViewChildFrame::PostProcessEventForPluginIme( | 431 bool RenderWidgetHostViewChildFrame::PostProcessEventForPluginIme( |
| 420 const NativeWebKeyboardEvent& event) { | 432 const NativeWebKeyboardEvent& event) { |
| 421 return false; | 433 return false; |
| 422 } | 434 } |
| 423 #endif // defined(OS_MACOSX) | 435 #endif // defined(OS_MACOSX) |
| 424 | 436 |
| 437 void RenderWidgetHostViewChildFrame::RegisterFrameSwappedCallback( | |
| 438 scoped_ptr<base::Closure> callback) { | |
| 439 frame_swapped_callbacks_.push_back(std::move(callback)); | |
| 440 } | |
| 441 | |
| 425 void RenderWidgetHostViewChildFrame::CopyFromCompositingSurface( | 442 void RenderWidgetHostViewChildFrame::CopyFromCompositingSurface( |
| 426 const gfx::Rect& /* src_subrect */, | 443 const gfx::Rect& src_subrect, |
| 427 const gfx::Size& /* dst_size */, | 444 const gfx::Size& output_size, |
| 428 const ReadbackRequestCallback& callback, | 445 const ReadbackRequestCallback& callback, |
| 429 const SkColorType /* preferred_color_type */) { | 446 const SkColorType preferred_color_type) { |
| 430 callback.Run(SkBitmap(), READBACK_FAILED); | 447 if (!IsSurfaceAvailableForCopy()) { |
| 448 // Defer submitting the copy request until after a frame is drawn, at which | |
| 449 // point we should be guaranteed that the surface is available. | |
| 450 RegisterFrameSwappedCallback(make_scoped_ptr(new base::Closure(base::Bind( | |
| 451 &RenderWidgetHostViewChildFrame::SubmitSurfaceCopyRequest, AsWeakPtr(), | |
| 452 src_subrect, output_size, callback, preferred_color_type)))); | |
| 453 // If a composite is already scheduled, the following call will do nothing. | |
| 454 // If no composite is scheduled, and there is no current surface, this will | |
| 455 // initiate a composite. | |
| 456 // TODO(piman): Is this reasoning correct? | |
| 457 host_->ScheduleComposite(); | |
|
piman
2016/01/29 22:28:54
Is there a reason why the renderer would not gener
wjmaclean
2016/02/01 15:36:04
Ok, I've removed this. There was some discussion a
| |
| 458 return; | |
| 459 } | |
| 460 | |
| 461 SubmitSurfaceCopyRequest(src_subrect, output_size, callback, | |
| 462 preferred_color_type); | |
| 463 } | |
| 464 | |
| 465 void RenderWidgetHostViewChildFrame::SubmitSurfaceCopyRequest( | |
| 466 const gfx::Rect& src_subrect, | |
| 467 const gfx::Size& output_size, | |
| 468 const ReadbackRequestCallback& callback, | |
| 469 const SkColorType preferred_color_type) { | |
| 470 DCHECK(IsSurfaceAvailableForCopy()); | |
| 471 | |
| 472 scoped_ptr<cc::CopyOutputRequest> request = | |
| 473 cc::CopyOutputRequest::CreateRequest( | |
| 474 base::Bind(&CopyFromCompositingSurfaceHasResult, output_size, | |
| 475 preferred_color_type, callback)); | |
| 476 if (!src_subrect.IsEmpty()) | |
| 477 request->set_area(src_subrect); | |
| 478 | |
| 479 surface_factory_->RequestCopyOfSurface(surface_id_, std::move(request)); | |
| 431 } | 480 } |
| 432 | 481 |
| 433 void RenderWidgetHostViewChildFrame::CopyFromCompositingSurfaceToVideoFrame( | 482 void RenderWidgetHostViewChildFrame::CopyFromCompositingSurfaceToVideoFrame( |
| 434 const gfx::Rect& src_subrect, | 483 const gfx::Rect& src_subrect, |
| 435 const scoped_refptr<media::VideoFrame>& target, | 484 const scoped_refptr<media::VideoFrame>& target, |
| 436 const base::Callback<void(const gfx::Rect&, bool)>& callback) { | 485 const base::Callback<void(const gfx::Rect&, bool)>& callback) { |
| 437 NOTIMPLEMENTED(); | 486 NOTIMPLEMENTED(); |
| 438 callback.Run(gfx::Rect(), false); | 487 callback.Run(gfx::Rect(), false); |
| 439 } | 488 } |
| 440 | 489 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 #endif | 543 #endif |
| 495 } | 544 } |
| 496 | 545 |
| 497 void RenderWidgetHostViewChildFrame::ClearCompositorSurfaceIfNecessary() { | 546 void RenderWidgetHostViewChildFrame::ClearCompositorSurfaceIfNecessary() { |
| 498 if (surface_factory_ && !surface_id_.is_null()) | 547 if (surface_factory_ && !surface_id_.is_null()) |
| 499 surface_factory_->Destroy(surface_id_); | 548 surface_factory_->Destroy(surface_id_); |
| 500 surface_id_ = cc::SurfaceId(); | 549 surface_id_ = cc::SurfaceId(); |
| 501 } | 550 } |
| 502 | 551 |
| 503 } // namespace content | 552 } // namespace content |
| OLD | NEW |