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/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 1480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1814 // Paint the entire thing (using original bounds, not scaled bounds). | 1816 // Paint the entire thing (using original bounds, not scaled bounds). |
| 1815 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get()); | 1817 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get()); |
| 1816 canvas->restore(); | 1818 canvas->restore(); |
| 1817 | 1819 |
| 1818 // Return the widget to its previous size. | 1820 // Return the widget to its previous size. |
| 1819 webwidget_->resize(old_size); | 1821 webwidget_->resize(old_size); |
| 1820 | 1822 |
| 1821 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size())); | 1823 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size())); |
| 1822 } | 1824 } |
| 1823 | 1825 |
| 1826 namespace { | |
| 1827 void OnSnapshotFailed(scoped_refptr<content::RenderWidget> render_widget, | |
| 1828 int routing_id) { | |
| 1829 render_widget->Send(new ViewHostMsg_Snapshot(routing_id, false, SkBitmap())); | |
| 1830 } | |
| 1831 } // namespace | |
| 1832 | |
| 1833 void RenderWidget::OnSnapshot(const gfx::Rect& src_subrect) { | |
| 1834 base::TimeTicks beginning_time = base::TimeTicks::Now(); | |
| 1835 | |
| 1836 base::ScopedClosureRunner scoped_callback_runner( | |
| 1837 base::Bind(OnSnapshotFailed, make_scoped_refptr(this), routing_id_)); | |
|
jamesr
2013/03/22 00:05:33
This functional style is highly uncommon in chromi
justinlin
2013/03/22 00:43:39
Done.
| |
| 1838 | |
| 1839 SkBitmap snapshot; | |
| 1840 if (!webwidget_ || src_subrect.IsEmpty()) | |
| 1841 return; | |
| 1842 | |
| 1843 gfx::Rect viewport_size = gfx::IntersectRects( | |
| 1844 src_subrect, gfx::Rect(physical_backing_size_)); | |
| 1845 | |
| 1846 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef( | |
| 1847 skia::CreatePlatformCanvas(viewport_size.width(), | |
| 1848 viewport_size.height(), | |
| 1849 true, | |
| 1850 NULL, | |
| 1851 skia::RETURN_NULL_ON_FAILURE)); | |
| 1852 if (!canvas.get()) | |
| 1853 return; | |
| 1854 | |
| 1855 canvas->save(); | |
| 1856 webwidget_->layout(); | |
| 1857 | |
| 1858 PaintRect(viewport_size, viewport_size.origin(), canvas.get()); | |
| 1859 canvas->restore(); | |
| 1860 | |
| 1861 const SkBitmap& bitmap = skia::GetTopDevice(*canvas)->accessBitmap(false); | |
| 1862 if (!bitmap.copyTo(&snapshot, SkBitmap::kARGB_8888_Config)) | |
| 1863 return; | |
| 1864 | |
| 1865 UMA_HISTOGRAM_TIMES("Renderer4.Snapshot", | |
| 1866 base::TimeTicks::Now() - beginning_time); | |
| 1867 | |
| 1868 scoped_callback_runner.Release(); | |
| 1869 | |
| 1870 Send(new ViewHostMsg_Snapshot(routing_id_, true, snapshot)); | |
| 1871 } | |
| 1872 | |
| 1824 void RenderWidget::OnRepaint(const gfx::Size& size_to_paint) { | 1873 void RenderWidget::OnRepaint(const gfx::Size& size_to_paint) { |
| 1825 // During shutdown we can just ignore this message. | 1874 // During shutdown we can just ignore this message. |
| 1826 if (!webwidget_) | 1875 if (!webwidget_) |
| 1827 return; | 1876 return; |
| 1828 | 1877 |
| 1829 set_next_paint_is_repaint_ack(); | 1878 set_next_paint_is_repaint_ack(); |
| 1830 if (is_accelerated_compositing_active_) { | 1879 if (is_accelerated_compositing_active_) { |
| 1831 if (compositor_) | 1880 if (compositor_) |
| 1832 compositor_->setNeedsRedraw(); | 1881 compositor_->setNeedsRedraw(); |
| 1833 scheduleComposite(); | 1882 scheduleComposite(); |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2265 if (!context->Initialize( | 2314 if (!context->Initialize( |
| 2266 attributes, | 2315 attributes, |
| 2267 false /* bind generates resources */, | 2316 false /* bind generates resources */, |
| 2268 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZ E)) | 2317 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZ E)) |
| 2269 return NULL; | 2318 return NULL; |
| 2270 return context.release(); | 2319 return context.release(); |
| 2271 } | 2320 } |
| 2272 } | 2321 } |
| 2273 | 2322 |
| 2274 } // namespace content | 2323 } // namespace content |
| OLD | NEW |