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/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/debug/trace_event_synthetic_delay.h" | 10 #include "base/debug/trace_event_synthetic_delay.h" |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition) | 598 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition) |
599 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition) | 599 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition) |
600 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) | 600 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) |
601 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) | 601 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) |
602 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) | 602 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) |
603 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) | 603 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) |
604 #if defined(OS_ANDROID) | 604 #if defined(OS_ANDROID) |
605 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) | 605 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) |
606 IPC_MESSAGE_HANDLER(ViewMsg_ImeEventAck, OnImeEventAck) | 606 IPC_MESSAGE_HANDLER(ViewMsg_ImeEventAck, OnImeEventAck) |
607 #endif | 607 #endif |
608 IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot) | |
609 IPC_MESSAGE_UNHANDLED(handled = false) | 608 IPC_MESSAGE_UNHANDLED(handled = false) |
610 IPC_END_MESSAGE_MAP() | 609 IPC_END_MESSAGE_MAP() |
611 return handled; | 610 return handled; |
612 } | 611 } |
613 | 612 |
614 bool RenderWidget::Send(IPC::Message* message) { | 613 bool RenderWidget::Send(IPC::Message* message) { |
615 // Don't send any messages after the browser has told us to close, and filter | 614 // Don't send any messages after the browser has told us to close, and filter |
616 // most outgoing messages while swapped out. | 615 // most outgoing messages while swapped out. |
617 if ((is_swapped_out_ && | 616 if ((is_swapped_out_ && |
618 !SwappedOutMessages::CanSendWhileSwappedOut(message)) || | 617 !SwappedOutMessages::CanSendWhileSwappedOut(message)) || |
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 else if (keep_selection) | 1705 else if (keep_selection) |
1707 webwidget_->confirmComposition(WebWidget::KeepSelection); | 1706 webwidget_->confirmComposition(WebWidget::KeepSelection); |
1708 else | 1707 else |
1709 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); | 1708 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection); |
1710 handling_input_event_ = false; | 1709 handling_input_event_ = false; |
1711 #if defined(OS_MACOSX) || defined(USE_AURA) | 1710 #if defined(OS_MACOSX) || defined(USE_AURA) |
1712 UpdateCompositionInfo(true); | 1711 UpdateCompositionInfo(true); |
1713 #endif | 1712 #endif |
1714 } | 1713 } |
1715 | 1714 |
1716 void RenderWidget::OnSnapshot(const gfx::Rect& src_subrect) { | |
1717 SkBitmap snapshot; | |
1718 | |
1719 if (OnSnapshotHelper(src_subrect, &snapshot)) { | |
1720 Send(new ViewHostMsg_Snapshot(routing_id(), true, snapshot)); | |
1721 } else { | |
1722 Send(new ViewHostMsg_Snapshot(routing_id(), false, SkBitmap())); | |
1723 } | |
1724 } | |
1725 | |
1726 bool RenderWidget::OnSnapshotHelper(const gfx::Rect& src_subrect, | |
1727 SkBitmap* snapshot) { | |
1728 base::TimeTicks beginning_time = base::TimeTicks::Now(); | |
1729 | |
1730 if (!webwidget_ || src_subrect.IsEmpty()) | |
1731 return false; | |
1732 | |
1733 gfx::Rect viewport_size = gfx::IntersectRects( | |
1734 src_subrect, gfx::Rect(physical_backing_size_)); | |
1735 | |
1736 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef( | |
1737 skia::CreatePlatformCanvas(viewport_size.width(), | |
1738 viewport_size.height(), | |
1739 true, | |
1740 NULL, | |
1741 skia::RETURN_NULL_ON_FAILURE)); | |
1742 if (!canvas) | |
1743 return false; | |
1744 | |
1745 canvas->save(); | |
1746 webwidget_->layout(); | |
1747 | |
1748 PaintRect(viewport_size, viewport_size.origin(), canvas.get()); | |
1749 canvas->restore(); | |
1750 | |
1751 const SkBitmap& bitmap = skia::GetTopDevice(*canvas)->accessBitmap(false); | |
1752 if (!bitmap.copyTo(snapshot, kPMColor_SkColorType)) | |
1753 return false; | |
1754 | |
1755 UMA_HISTOGRAM_TIMES("Renderer4.Snapshot", | |
1756 base::TimeTicks::Now() - beginning_time); | |
1757 return true; | |
1758 } | |
1759 | |
1760 void RenderWidget::OnRepaint(gfx::Size size_to_paint) { | 1715 void RenderWidget::OnRepaint(gfx::Size size_to_paint) { |
1761 // During shutdown we can just ignore this message. | 1716 // During shutdown we can just ignore this message. |
1762 if (!webwidget_) | 1717 if (!webwidget_) |
1763 return; | 1718 return; |
1764 | 1719 |
1765 // Even if the browser provides an empty damage rect, it's still expecting to | 1720 // Even if the browser provides an empty damage rect, it's still expecting to |
1766 // receive a repaint ack so just damage the entire widget bounds. | 1721 // receive a repaint ack so just damage the entire widget bounds. |
1767 if (size_to_paint.IsEmpty()) { | 1722 if (size_to_paint.IsEmpty()) { |
1768 size_to_paint = size_; | 1723 size_to_paint = size_; |
1769 } | 1724 } |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2370 | 2325 |
2371 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) { | 2326 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) { |
2372 swapped_out_frames_.AddObserver(frame); | 2327 swapped_out_frames_.AddObserver(frame); |
2373 } | 2328 } |
2374 | 2329 |
2375 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) { | 2330 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) { |
2376 swapped_out_frames_.RemoveObserver(frame); | 2331 swapped_out_frames_.RemoveObserver(frame); |
2377 } | 2332 } |
2378 | 2333 |
2379 } // namespace content | 2334 } // namespace content |
OLD | NEW |