Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer_host/render_widget_host_impl.h" | 5 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) | 384 IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnLockMouse) |
| 385 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) | 385 IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnUnlockMouse) |
| 386 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowDisambiguationPopup, | 386 IPC_MESSAGE_HANDLER(ViewHostMsg_ShowDisambiguationPopup, |
| 387 OnShowDisambiguationPopup) | 387 OnShowDisambiguationPopup) |
| 388 #if defined(OS_WIN) | 388 #if defined(OS_WIN) |
| 389 IPC_MESSAGE_HANDLER(ViewHostMsg_WindowlessPluginDummyWindowCreated, | 389 IPC_MESSAGE_HANDLER(ViewHostMsg_WindowlessPluginDummyWindowCreated, |
| 390 OnWindowlessPluginDummyWindowCreated) | 390 OnWindowlessPluginDummyWindowCreated) |
| 391 IPC_MESSAGE_HANDLER(ViewHostMsg_WindowlessPluginDummyWindowDestroyed, | 391 IPC_MESSAGE_HANDLER(ViewHostMsg_WindowlessPluginDummyWindowDestroyed, |
| 392 OnWindowlessPluginDummyWindowDestroyed) | 392 OnWindowlessPluginDummyWindowDestroyed) |
| 393 #endif | 393 #endif |
| 394 IPC_MESSAGE_HANDLER(ViewHostMsg_Snapshot, OnSnapshot) | |
| 394 IPC_MESSAGE_UNHANDLED(handled = false) | 395 IPC_MESSAGE_UNHANDLED(handled = false) |
| 395 IPC_END_MESSAGE_MAP_EX() | 396 IPC_END_MESSAGE_MAP_EX() |
| 396 | 397 |
| 397 if (!handled && view_ && view_->OnMessageReceived(msg)) | 398 if (!handled && view_ && view_->OnMessageReceived(msg)) |
| 398 return true; | 399 return true; |
| 399 | 400 |
| 400 if (!msg_is_ok) { | 401 if (!msg_is_ok) { |
| 401 // The message de-serialization failed. Kill the renderer process. | 402 // The message de-serialization failed. Kill the renderer process. |
| 402 RecordAction(UserMetricsAction("BadMessageTerminate_RWH")); | 403 RecordAction(UserMetricsAction("BadMessageTerminate_RWH")); |
| 403 GetProcess()->ReceivedBadMessage(); | 404 GetProcess()->ReceivedBadMessage(); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 is_loading_ = is_loading; | 564 is_loading_ = is_loading; |
| 564 if (!view_) | 565 if (!view_) |
| 565 return; | 566 return; |
| 566 view_->SetIsLoading(is_loading); | 567 view_->SetIsLoading(is_loading); |
| 567 } | 568 } |
| 568 | 569 |
| 569 void RenderWidgetHostImpl::CopyFromBackingStore( | 570 void RenderWidgetHostImpl::CopyFromBackingStore( |
| 570 const gfx::Rect& src_subrect, | 571 const gfx::Rect& src_subrect, |
| 571 const gfx::Size& accelerated_dst_size, | 572 const gfx::Size& accelerated_dst_size, |
| 572 const base::Callback<void(bool, const SkBitmap&)>& callback) { | 573 const base::Callback<void(bool, const SkBitmap&)>& callback) { |
| 574 gfx::Rect accelerated_copy_rect = src_subrect.IsEmpty() ? | |
| 575 gfx::Rect(view_->GetViewBounds().size()) : src_subrect; | |
| 576 | |
| 573 if (view_ && is_accelerated_compositing_active_) { | 577 if (view_ && is_accelerated_compositing_active_) { |
| 574 TRACE_EVENT0("browser", | 578 TRACE_EVENT0("browser", |
| 575 "RenderWidgetHostImpl::CopyFromBackingStore::FromCompositingSurface"); | 579 "RenderWidgetHostImpl::CopyFromBackingStore::FromCompositingSurface"); |
| 576 gfx::Rect copy_rect = src_subrect.IsEmpty() ? | 580 |
| 577 gfx::Rect(view_->GetViewBounds().size()) : src_subrect; | 581 view_->CopyFromCompositingSurface(accelerated_copy_rect, |
| 578 view_->CopyFromCompositingSurface(copy_rect, | |
| 579 accelerated_dst_size, | 582 accelerated_dst_size, |
| 580 callback); | 583 callback); |
| 581 return; | 584 return; |
| 582 } | 585 } |
| 583 | 586 |
| 584 BackingStore* backing_store = GetBackingStore(false); | 587 BackingStore* backing_store = GetBackingStore(false); |
| 585 if (!backing_store) { | 588 if (!backing_store) { |
| 586 callback.Run(false, SkBitmap()); | 589 GetSnapshotFromRenderer(accelerated_copy_rect, |
|
Sam Kerner (Chrome)
2013/03/18 19:30:52
You are changing the semantics of this method from
| |
| 590 accelerated_dst_size, | |
| 591 callback); | |
| 587 return; | 592 return; |
| 588 } | 593 } |
| 589 | 594 |
| 590 TRACE_EVENT0("browser", | 595 TRACE_EVENT0("browser", |
| 591 "RenderWidgetHostImpl::CopyFromBackingStore::FromBackingStore"); | 596 "RenderWidgetHostImpl::CopyFromBackingStore::FromBackingStore"); |
| 592 gfx::Rect copy_rect = src_subrect.IsEmpty() ? | 597 gfx::Rect copy_rect = src_subrect.IsEmpty() ? |
| 593 gfx::Rect(backing_store->size()) : src_subrect; | 598 gfx::Rect(backing_store->size()) : src_subrect; |
| 594 // When the result size is equal to the backing store size, copy from the | 599 // When the result size is equal to the backing store size, copy from the |
| 595 // backing store directly to the output canvas. | 600 // backing store directly to the output canvas. |
| 596 skia::PlatformBitmap output; | 601 skia::PlatformBitmap output; |
| 597 bool result = backing_store->CopyFromBackingStore(copy_rect, &output); | 602 bool result = backing_store->CopyFromBackingStore(copy_rect, &output); |
| 598 callback.Run(result, output.GetBitmap()); | 603 callback.Run(result, output.GetBitmap()); |
| 599 } | 604 } |
| 600 | 605 |
| 606 void RenderWidgetHostImpl::GetSnapshotFromRenderer( | |
| 607 const gfx::Rect& src_subrect, | |
| 608 const gfx::Size& dst_size, | |
| 609 const base::Callback<void(bool, const SkBitmap&)>& callback) { | |
| 610 TRACE_EVENT0("browser", "RenderWidgetHostImpl::GetSnapshotFromRenderer"); | |
| 611 pending_snapshots_.push(std::make_pair(dst_size, callback)); | |
| 612 Send(new ViewMsg_Snapshot(routing_id_, src_subrect)); | |
| 613 } | |
| 614 | |
| 615 void RenderWidgetHostImpl::OnSnapshot(bool success, | |
| 616 const SkBitmap& bitmap) { | |
| 617 if (pending_snapshots_.size() == 0) { | |
| 618 LOG(ERROR) << "RenderWidgetHostImpl::OnSnapshot: " | |
| 619 "Received a snapshot that was not requested."; | |
| 620 return; | |
| 621 } | |
| 622 | |
| 623 PendingSnapshotInfo snapshot_info = pending_snapshots_.front(); | |
| 624 pending_snapshots_.pop(); | |
| 625 | |
| 626 const gfx::Size& dst_size = snapshot_info.first; | |
| 627 const base::Callback<void(bool, const SkBitmap&)>& callback = | |
| 628 snapshot_info.second; | |
| 629 | |
| 630 if (!success) { | |
| 631 callback.Run(success, SkBitmap()); | |
| 632 return; | |
| 633 } | |
| 634 | |
| 635 SkBitmap resized = skia::ImageOperations::Resize( | |
| 636 bitmap, skia::ImageOperations::RESIZE_GOOD, dst_size.width(), | |
| 637 dst_size.height()); | |
| 638 | |
| 639 callback.Run(success, resized); | |
| 640 } | |
| 641 | |
| 601 #if defined(TOOLKIT_GTK) | 642 #if defined(TOOLKIT_GTK) |
| 602 bool RenderWidgetHostImpl::CopyFromBackingStoreToGtkWindow( | 643 bool RenderWidgetHostImpl::CopyFromBackingStoreToGtkWindow( |
| 603 const gfx::Rect& dest_rect, GdkWindow* target) { | 644 const gfx::Rect& dest_rect, GdkWindow* target) { |
| 604 BackingStore* backing_store = GetBackingStore(false); | 645 BackingStore* backing_store = GetBackingStore(false); |
| 605 if (!backing_store) | 646 if (!backing_store) |
| 606 return false; | 647 return false; |
| 607 (static_cast<BackingStoreGtk*>(backing_store))->PaintToRect( | 648 (static_cast<BackingStoreGtk*>(backing_store))->PaintToRect( |
| 608 dest_rect, target); | 649 dest_rect, target); |
| 609 return true; | 650 return true; |
| 610 } | 651 } |
| (...skipping 1799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2410 return; | 2451 return; |
| 2411 | 2452 |
| 2412 OnRenderAutoResized(new_size); | 2453 OnRenderAutoResized(new_size); |
| 2413 } | 2454 } |
| 2414 | 2455 |
| 2415 void RenderWidgetHostImpl::DetachDelegate() { | 2456 void RenderWidgetHostImpl::DetachDelegate() { |
| 2416 delegate_ = NULL; | 2457 delegate_ = NULL; |
| 2417 } | 2458 } |
| 2418 | 2459 |
| 2419 } // namespace content | 2460 } // namespace content |
| OLD | NEW |