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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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) { |
| 573 if (view_ && is_accelerated_compositing_active_) { | 574 if (view_ && is_accelerated_compositing_active_) { |
| 574 TRACE_EVENT0("browser", | 575 TRACE_EVENT0("browser", |
| 575 "RenderWidgetHostImpl::CopyFromBackingStore::FromCompositingSurface"); | 576 "RenderWidgetHostImpl::CopyFromBackingStore::FromCompositingSurface"); |
| 576 gfx::Rect copy_rect = src_subrect.IsEmpty() ? | 577 gfx::Rect accelerated_copy_rect = src_subrect.IsEmpty() ? |
| 577 gfx::Rect(view_->GetViewBounds().size()) : src_subrect; | 578 gfx::Rect(view_->GetViewBounds().size()) : src_subrect; |
| 578 view_->CopyFromCompositingSurface(copy_rect, | 579 view_->CopyFromCompositingSurface(accelerated_copy_rect, |
| 579 accelerated_dst_size, | 580 accelerated_dst_size, |
| 580 callback); | 581 callback); |
| 581 return; | 582 return; |
| 582 } | 583 } |
| 583 | 584 |
| 584 BackingStore* backing_store = GetBackingStore(false); | 585 BackingStore* backing_store = GetBackingStore(false); |
| 585 if (!backing_store) { | 586 if (!backing_store) { |
| 586 callback.Run(false, SkBitmap()); | 587 callback.Run(false, SkBitmap()); |
| 587 return; | 588 return; |
| 588 } | 589 } |
| 589 | 590 |
| 590 TRACE_EVENT0("browser", | 591 TRACE_EVENT0("browser", |
| 591 "RenderWidgetHostImpl::CopyFromBackingStore::FromBackingStore"); | 592 "RenderWidgetHostImpl::CopyFromBackingStore::FromBackingStore"); |
| 592 gfx::Rect copy_rect = src_subrect.IsEmpty() ? | 593 gfx::Rect copy_rect = src_subrect.IsEmpty() ? |
| 593 gfx::Rect(backing_store->size()) : src_subrect; | 594 gfx::Rect(backing_store->size()) : src_subrect; |
| 594 // When the result size is equal to the backing store size, copy from the | 595 // When the result size is equal to the backing store size, copy from the |
| 595 // backing store directly to the output canvas. | 596 // backing store directly to the output canvas. |
| 596 skia::PlatformBitmap output; | 597 skia::PlatformBitmap output; |
| 597 bool result = backing_store->CopyFromBackingStore(copy_rect, &output); | 598 bool result = backing_store->CopyFromBackingStore(copy_rect, &output); |
| 598 callback.Run(result, output.GetBitmap()); | 599 callback.Run(result, output.GetBitmap()); |
| 599 } | 600 } |
| 600 | 601 |
| 602 void RenderWidgetHostImpl::GetSnapshotFromRenderer( | |
| 603 const gfx::Rect& src_subrect, | |
| 604 const gfx::Size& dst_size, | |
| 605 const base::Callback<void(bool, const SkBitmap&)>& callback) { | |
| 606 TRACE_EVENT0("browser", "RenderWidgetHostImpl::GetSnapshotFromRenderer"); | |
| 607 pending_snapshots_.push(std::make_pair(dst_size, callback)); | |
| 608 | |
| 609 gfx::Rect copy_rect = src_subrect.IsEmpty() ? | |
| 610 gfx::Rect(view_->GetViewBounds().size()) : src_subrect; | |
| 611 Send(new ViewMsg_Snapshot(routing_id_, copy_rect)); | |
| 612 } | |
| 613 | |
| 614 void RenderWidgetHostImpl::OnSnapshot(bool success, | |
| 615 const SkBitmap& bitmap) { | |
| 616 if (pending_snapshots_.size() == 0) { | |
| 617 LOG(ERROR) << "RenderWidgetHostImpl::OnSnapshot: " | |
| 618 "Received a snapshot that was not requested."; | |
| 619 return; | |
| 620 } | |
| 621 | |
| 622 PendingSnapshotInfo snapshot_info = pending_snapshots_.front(); | |
| 623 pending_snapshots_.pop(); | |
| 624 | |
| 625 const gfx::Size& dst_size = snapshot_info.first; | |
| 626 const base::Callback<void(bool, const SkBitmap&)>& callback = | |
| 627 snapshot_info.second; | |
| 628 | |
| 629 if (!success) { | |
| 630 callback.Run(success, SkBitmap()); | |
| 631 return; | |
| 632 } | |
| 633 | |
| 634 SkBitmap resized = skia::ImageOperations::Resize( | |
| 635 bitmap, skia::ImageOperations::RESIZE_GOOD, dst_size.width(), | |
|
jamesr
2013/03/18 22:41:18
why RESIZE_GOOD? what did the old code use?
justinlin
2013/03/18 23:27:52
The old code didn't really do the resize (CopyFrom
| |
| 636 dst_size.height()); | |
| 637 | |
| 638 callback.Run(success, resized); | |
| 639 } | |
| 640 | |
| 601 #if defined(TOOLKIT_GTK) | 641 #if defined(TOOLKIT_GTK) |
| 602 bool RenderWidgetHostImpl::CopyFromBackingStoreToGtkWindow( | 642 bool RenderWidgetHostImpl::CopyFromBackingStoreToGtkWindow( |
| 603 const gfx::Rect& dest_rect, GdkWindow* target) { | 643 const gfx::Rect& dest_rect, GdkWindow* target) { |
| 604 BackingStore* backing_store = GetBackingStore(false); | 644 BackingStore* backing_store = GetBackingStore(false); |
| 605 if (!backing_store) | 645 if (!backing_store) |
| 606 return false; | 646 return false; |
| 607 (static_cast<BackingStoreGtk*>(backing_store))->PaintToRect( | 647 (static_cast<BackingStoreGtk*>(backing_store))->PaintToRect( |
| 608 dest_rect, target); | 648 dest_rect, target); |
| 609 return true; | 649 return true; |
| 610 } | 650 } |
| (...skipping 1799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2410 return; | 2450 return; |
| 2411 | 2451 |
| 2412 OnRenderAutoResized(new_size); | 2452 OnRenderAutoResized(new_size); |
| 2413 } | 2453 } |
| 2414 | 2454 |
| 2415 void RenderWidgetHostImpl::DetachDelegate() { | 2455 void RenderWidgetHostImpl::DetachDelegate() { |
| 2416 delegate_ = NULL; | 2456 delegate_ = NULL; |
| 2417 } | 2457 } |
| 2418 | 2458 |
| 2419 } // namespace content | 2459 } // namespace content |
| OLD | NEW |