| 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/bind_helpers.h" |
| 8 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 9 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 14 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 15 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 17 #include "cc/base/switches.h" | 18 #include "cc/base/switches.h" |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) | 315 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint) |
| 315 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, OnSmoothScrollCompleted) | 316 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, OnSmoothScrollCompleted) |
| 316 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) | 317 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) |
| 317 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) | 318 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) |
| 318 IPC_MESSAGE_HANDLER(ViewMsg_ScreenInfoChanged, OnScreenInfoChanged) | 319 IPC_MESSAGE_HANDLER(ViewMsg_ScreenInfoChanged, OnScreenInfoChanged) |
| 319 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) | 320 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) |
| 320 #if defined(OS_ANDROID) | 321 #if defined(OS_ANDROID) |
| 321 IPC_MESSAGE_HANDLER(ViewMsg_ImeBatchStateChanged, OnImeBatchStateChanged) | 322 IPC_MESSAGE_HANDLER(ViewMsg_ImeBatchStateChanged, OnImeBatchStateChanged) |
| 322 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) | 323 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded) |
| 323 #endif | 324 #endif |
| 325 IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot) |
| 324 IPC_MESSAGE_UNHANDLED(handled = false) | 326 IPC_MESSAGE_UNHANDLED(handled = false) |
| 325 IPC_END_MESSAGE_MAP() | 327 IPC_END_MESSAGE_MAP() |
| 326 return handled; | 328 return handled; |
| 327 } | 329 } |
| 328 | 330 |
| 329 bool RenderWidget::Send(IPC::Message* message) { | 331 bool RenderWidget::Send(IPC::Message* message) { |
| 330 // Don't send any messages after the browser has told us to close, and filter | 332 // Don't send any messages after the browser has told us to close, and filter |
| 331 // most outgoing messages while swapped out. | 333 // most outgoing messages while swapped out. |
| 332 if ((is_swapped_out_ && | 334 if ((is_swapped_out_ && |
| 333 !SwappedOutMessages::CanSendWhileSwappedOut(message)) || | 335 !SwappedOutMessages::CanSendWhileSwappedOut(message)) || |
| (...skipping 1479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1813 // Paint the entire thing (using original bounds, not scaled bounds). | 1815 // Paint the entire thing (using original bounds, not scaled bounds). |
| 1814 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get()); | 1816 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get()); |
| 1815 canvas->restore(); | 1817 canvas->restore(); |
| 1816 | 1818 |
| 1817 // Return the widget to its previous size. | 1819 // Return the widget to its previous size. |
| 1818 webwidget_->resize(old_size); | 1820 webwidget_->resize(old_size); |
| 1819 | 1821 |
| 1820 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size())); | 1822 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size())); |
| 1821 } | 1823 } |
| 1822 | 1824 |
| 1825 void RenderWidget::OnSnapshot(const gfx::Rect& src_subrect) { |
| 1826 SkBitmap snapshot; |
| 1827 |
| 1828 if (OnSnapshotHelper(src_subrect, &snapshot)) { |
| 1829 Send(new ViewHostMsg_Snapshot(routing_id(), true, snapshot)); |
| 1830 } else { |
| 1831 Send(new ViewHostMsg_Snapshot(routing_id(), false, SkBitmap())); |
| 1832 } |
| 1833 } |
| 1834 |
| 1835 bool RenderWidget::OnSnapshotHelper(const gfx::Rect& src_subrect, |
| 1836 SkBitmap* snapshot) { |
| 1837 base::TimeTicks beginning_time = base::TimeTicks::Now(); |
| 1838 |
| 1839 if (!webwidget_ || src_subrect.IsEmpty()) |
| 1840 return false; |
| 1841 |
| 1842 gfx::Rect viewport_size = gfx::IntersectRects( |
| 1843 src_subrect, gfx::Rect(physical_backing_size_)); |
| 1844 |
| 1845 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef( |
| 1846 skia::CreatePlatformCanvas(viewport_size.width(), |
| 1847 viewport_size.height(), |
| 1848 true, |
| 1849 NULL, |
| 1850 skia::RETURN_NULL_ON_FAILURE)); |
| 1851 if (!canvas.get()) |
| 1852 return false; |
| 1853 |
| 1854 canvas->save(); |
| 1855 webwidget_->layout(); |
| 1856 |
| 1857 PaintRect(viewport_size, viewport_size.origin(), canvas.get()); |
| 1858 canvas->restore(); |
| 1859 |
| 1860 const SkBitmap& bitmap = skia::GetTopDevice(*canvas)->accessBitmap(false); |
| 1861 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config)) |
| 1862 return false; |
| 1863 |
| 1864 UMA_HISTOGRAM_TIMES("Renderer4.Snapshot", |
| 1865 base::TimeTicks::Now() - beginning_time); |
| 1866 return true; |
| 1867 } |
| 1868 |
| 1823 void RenderWidget::OnRepaint(const gfx::Size& size_to_paint) { | 1869 void RenderWidget::OnRepaint(const gfx::Size& size_to_paint) { |
| 1824 // During shutdown we can just ignore this message. | 1870 // During shutdown we can just ignore this message. |
| 1825 if (!webwidget_) | 1871 if (!webwidget_) |
| 1826 return; | 1872 return; |
| 1827 | 1873 |
| 1828 set_next_paint_is_repaint_ack(); | 1874 set_next_paint_is_repaint_ack(); |
| 1829 if (is_accelerated_compositing_active_) { | 1875 if (is_accelerated_compositing_active_) { |
| 1830 if (compositor_) | 1876 if (compositor_) |
| 1831 compositor_->setNeedsRedraw(); | 1877 compositor_->setNeedsRedraw(); |
| 1832 scheduleComposite(); | 1878 scheduleComposite(); |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2256 | 2302 |
| 2257 if (!context->Initialize( | 2303 if (!context->Initialize( |
| 2258 attributes, | 2304 attributes, |
| 2259 false /* bind generates resources */, | 2305 false /* bind generates resources */, |
| 2260 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)
) | 2306 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE)
) |
| 2261 return NULL; | 2307 return NULL; |
| 2262 return context.release(); | 2308 return context.release(); |
| 2263 } | 2309 } |
| 2264 | 2310 |
| 2265 } // namespace content | 2311 } // namespace content |
| OLD | NEW |