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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 cc::SurfaceDrawStatus drawn) { | 248 cc::SurfaceDrawStatus drawn) { |
| 248 cc::CompositorFrameAck ack; | 249 cc::CompositorFrameAck ack; |
| 249 DCHECK_GT(ack_pending_count_, 0U); | 250 DCHECK_GT(ack_pending_count_, 0U); |
| 250 if (!surface_returned_resources_.empty()) | 251 if (!surface_returned_resources_.empty()) |
| 251 ack.resources.swap(surface_returned_resources_); | 252 ack.resources.swap(surface_returned_resources_); |
| 252 if (host_) { | 253 if (host_) { |
| 253 host_->Send(new ViewMsg_SwapCompositorFrameAck(host_->GetRoutingID(), | 254 host_->Send(new ViewMsg_SwapCompositorFrameAck(host_->GetRoutingID(), |
| 254 output_surface_id, ack)); | 255 output_surface_id, ack)); |
| 255 } | 256 } |
| 256 ack_pending_count_--; | 257 ack_pending_count_--; |
| 258 | |
| 259 // We only use callbacks once, therefore we make a new list for registration | |
| 260 // before we start, and discard the old list entries when we are done. | |
| 261 FrameDrawnCallbackList process_callbacks; | |
| 262 process_callbacks.swap(frame_drawn_callbacks_); | |
| 263 for (scoped_ptr<base::Closure>& callback : process_callbacks) | |
| 264 callback->Run(); | |
| 257 } | 265 } |
| 258 | 266 |
| 259 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame( | 267 void RenderWidgetHostViewChildFrame::OnSwapCompositorFrame( |
| 260 uint32_t output_surface_id, | 268 uint32_t output_surface_id, |
| 261 scoped_ptr<cc::CompositorFrame> frame) { | 269 scoped_ptr<cc::CompositorFrame> frame) { |
| 262 last_scroll_offset_ = frame->metadata.root_scroll_offset; | 270 last_scroll_offset_ = frame->metadata.root_scroll_offset; |
| 263 | 271 |
| 264 if (!frame_connector_) | 272 if (!frame_connector_) |
| 265 return; | 273 return; |
| 266 | 274 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 | 426 |
| 419 void RenderWidgetHostViewChildFrame::StopSpeaking() { | 427 void RenderWidgetHostViewChildFrame::StopSpeaking() { |
| 420 } | 428 } |
| 421 | 429 |
| 422 bool RenderWidgetHostViewChildFrame::PostProcessEventForPluginIme( | 430 bool RenderWidgetHostViewChildFrame::PostProcessEventForPluginIme( |
| 423 const NativeWebKeyboardEvent& event) { | 431 const NativeWebKeyboardEvent& event) { |
| 424 return false; | 432 return false; |
| 425 } | 433 } |
| 426 #endif // defined(OS_MACOSX) | 434 #endif // defined(OS_MACOSX) |
| 427 | 435 |
| 436 void RenderWidgetHostViewChildFrame::RegisterFrameDrawnCallback( | |
| 437 scoped_ptr<base::Closure> callback) { | |
| 438 frame_drawn_callbacks_.push_back(std::move(callback)); | |
| 439 } | |
| 440 | |
| 428 void RenderWidgetHostViewChildFrame::CopyFromCompositingSurface( | 441 void RenderWidgetHostViewChildFrame::CopyFromCompositingSurface( |
| 429 const gfx::Rect& /* src_subrect */, | 442 const gfx::Rect& src_subrect, |
| 430 const gfx::Size& /* dst_size */, | 443 const gfx::Size& output_size, |
| 431 const ReadbackRequestCallback& callback, | 444 const ReadbackRequestCallback& callback, |
| 432 const SkColorType /* preferred_color_type */) { | 445 const SkColorType preferred_color_type) { |
| 433 callback.Run(SkBitmap(), READBACK_FAILED); | 446 if (!IsSurfaceAvailableForCopy()) { |
|
ncarter (slow)
2016/01/27 21:08:24
This behavior goes somewhat against the intended c
wjmaclean
2016/01/27 21:28:01
I guess having a surface ID may not be enough, but
| |
| 447 // Defer submitting the copy request until after a frame is drawn, at which | |
| 448 // point we should be guaranteed that the surface is available. | |
| 449 RegisterFrameDrawnCallback(make_scoped_ptr(new base::Closure(base::Bind( | |
|
piman
2016/01/29 04:29:46
Why waiting for the frame to be *drawn* (SurfaceDr
wjmaclean
2016/01/29 21:01:57
I didn't realize that would happen, thanks for poi
| |
| 450 &RenderWidgetHostViewChildFrame::SubmitSurfaceCopyRequest, AsWeakPtr(), | |
| 451 src_subrect, output_size, callback, preferred_color_type)))); | |
| 452 return; | |
| 453 } | |
| 454 | |
| 455 SubmitSurfaceCopyRequest(src_subrect, output_size, callback, | |
| 456 preferred_color_type); | |
| 457 } | |
| 458 | |
| 459 void RenderWidgetHostViewChildFrame::SubmitSurfaceCopyRequest( | |
| 460 const gfx::Rect& src_subrect, | |
| 461 const gfx::Size& output_size, | |
| 462 const ReadbackRequestCallback& callback, | |
| 463 const SkColorType preferred_color_type) { | |
| 464 DCHECK(IsSurfaceAvailableForCopy()); | |
| 465 | |
| 466 scoped_ptr<cc::CopyOutputRequest> request = | |
| 467 cc::CopyOutputRequest::CreateRequest( | |
| 468 base::Bind(&CopyFromCompositingSurfaceHasResult, output_size, | |
| 469 preferred_color_type, callback)); | |
| 470 if (!src_subrect.IsEmpty()) | |
| 471 request->set_area(src_subrect); | |
| 472 | |
| 473 surface_factory_->RequestCopyOfSurface(surface_id_, std::move(request)); | |
| 434 } | 474 } |
| 435 | 475 |
| 436 void RenderWidgetHostViewChildFrame::CopyFromCompositingSurfaceToVideoFrame( | 476 void RenderWidgetHostViewChildFrame::CopyFromCompositingSurfaceToVideoFrame( |
| 437 const gfx::Rect& src_subrect, | 477 const gfx::Rect& src_subrect, |
| 438 const scoped_refptr<media::VideoFrame>& target, | 478 const scoped_refptr<media::VideoFrame>& target, |
| 439 const base::Callback<void(const gfx::Rect&, bool)>& callback) { | 479 const base::Callback<void(const gfx::Rect&, bool)>& callback) { |
| 440 NOTIMPLEMENTED(); | 480 NOTIMPLEMENTED(); |
| 441 callback.Run(gfx::Rect(), false); | 481 callback.Run(gfx::Rect(), false); |
| 442 } | 482 } |
| 443 | 483 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 497 #endif | 537 #endif |
| 498 } | 538 } |
| 499 | 539 |
| 500 void RenderWidgetHostViewChildFrame::ClearCompositorSurfaceIfNecessary() { | 540 void RenderWidgetHostViewChildFrame::ClearCompositorSurfaceIfNecessary() { |
| 501 if (surface_factory_ && !surface_id_.is_null()) | 541 if (surface_factory_ && !surface_id_.is_null()) |
| 502 surface_factory_->Destroy(surface_id_); | 542 surface_factory_->Destroy(surface_id_); |
| 503 surface_id_ = cc::SurfaceId(); | 543 surface_id_ = cc::SurfaceId(); |
| 504 } | 544 } |
| 505 | 545 |
| 506 } // namespace content | 546 } // namespace content |
| OLD | NEW |