| 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 return; |
| 454 } |
| 455 |
| 456 SubmitSurfaceCopyRequest(src_subrect, output_size, callback, |
| 457 preferred_color_type); |
| 458 } |
| 459 |
| 460 void RenderWidgetHostViewChildFrame::SubmitSurfaceCopyRequest( |
| 461 const gfx::Rect& src_subrect, |
| 462 const gfx::Size& output_size, |
| 463 const ReadbackRequestCallback& callback, |
| 464 const SkColorType preferred_color_type) { |
| 465 DCHECK(IsSurfaceAvailableForCopy()); |
| 466 |
| 467 scoped_ptr<cc::CopyOutputRequest> request = |
| 468 cc::CopyOutputRequest::CreateRequest( |
| 469 base::Bind(&CopyFromCompositingSurfaceHasResult, output_size, |
| 470 preferred_color_type, callback)); |
| 471 if (!src_subrect.IsEmpty()) |
| 472 request->set_area(src_subrect); |
| 473 |
| 474 surface_factory_->RequestCopyOfSurface(surface_id_, std::move(request)); |
| 431 } | 475 } |
| 432 | 476 |
| 433 void RenderWidgetHostViewChildFrame::CopyFromCompositingSurfaceToVideoFrame( | 477 void RenderWidgetHostViewChildFrame::CopyFromCompositingSurfaceToVideoFrame( |
| 434 const gfx::Rect& src_subrect, | 478 const gfx::Rect& src_subrect, |
| 435 const scoped_refptr<media::VideoFrame>& target, | 479 const scoped_refptr<media::VideoFrame>& target, |
| 436 const base::Callback<void(const gfx::Rect&, bool)>& callback) { | 480 const base::Callback<void(const gfx::Rect&, bool)>& callback) { |
| 437 NOTIMPLEMENTED(); | 481 NOTIMPLEMENTED(); |
| 438 callback.Run(gfx::Rect(), false); | 482 callback.Run(gfx::Rect(), false); |
| 439 } | 483 } |
| 440 | 484 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 #endif | 538 #endif |
| 495 } | 539 } |
| 496 | 540 |
| 497 void RenderWidgetHostViewChildFrame::ClearCompositorSurfaceIfNecessary() { | 541 void RenderWidgetHostViewChildFrame::ClearCompositorSurfaceIfNecessary() { |
| 498 if (surface_factory_ && !surface_id_.is_null()) | 542 if (surface_factory_ && !surface_id_.is_null()) |
| 499 surface_factory_->Destroy(surface_id_); | 543 surface_factory_->Destroy(surface_id_); |
| 500 surface_id_ = cc::SurfaceId(); | 544 surface_id_ = cc::SurfaceId(); |
| 501 } | 545 } |
| 502 | 546 |
| 503 } // namespace content | 547 } // namespace content |
| OLD | NEW |