blob: 1fe6bba8ecf138b1deb93365f8ac7b68d3b97b0d [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]32876ae2011-11-15 22:25:217#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:008#include "base/command_line.h"
[email protected]366ae242011-05-10 02:23:589#include "base/debug/trace_event.h"
initial.commit09911bf2008-07-26 23:55:2910#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/scoped_ptr.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2114#include "base/stl_util.h"
[email protected]8a9d6ca32011-06-06 20:11:3015#include "base/utf_string_conversions.h"
[email protected]661eb9d2009-02-03 02:11:4816#include "build/build_config.h"
[email protected]681ccff2013-03-18 06:13:5217#include "cc/base/switches.h"
18#include "cc/base/thread.h"
19#include "cc/base/thread_impl.h"
[email protected]7f0d825f2013-03-18 07:24:3020#include "cc/output/output_surface.h"
[email protected]556fd292013-03-18 08:03:0421#include "cc/trees/layer_tree_host.h"
[email protected]ed7defa2013-03-12 21:29:5922#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]c084330e02013-04-27 01:08:1523#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1524#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5025#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2926#include "content/public/common/content_switches.h"
[email protected]ed7defa2013-03-12 21:29:5927#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]2847b222013-04-06 00:59:2428#include "content/renderer/gpu/compositor_software_output_device.h"
[email protected]ea5f70a2013-03-07 12:30:3629#include "content/renderer/gpu/input_handler_manager.h"
[email protected]ed7defa2013-03-12 21:29:5930#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]ba91a792013-02-06 09:48:2831#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]8704f89b2011-04-15 00:30:0532#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4433#include "content/renderer/render_thread_impl.h"
[email protected]8d6cba42011-09-02 10:05:1934#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]484955942010-08-19 16:13:1835#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4836#include "skia/ext/platform_canvas.h"
[email protected]ed7defa2013-03-12 21:29:5937#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
[email protected]debc8e52013-01-15 03:43:1238#include "third_party/WebKit/Source/Platform/chromium/public/WebPoint.h"
39#include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
40#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
41#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
[email protected]8bd0fe62011-01-17 06:44:3742#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
[email protected]4b1146bc2012-07-10 18:46:0343#include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h"
[email protected]a7547fb2012-03-08 04:43:4444#include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h"
[email protected]8bd0fe62011-01-17 06:44:3745#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
46#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
[email protected]d4cff272011-05-02 15:46:0147#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:3748#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
[email protected]d353541f2012-05-03 22:45:4149#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1350#include "ui/base/ui_base_switches.h"
[email protected]a25e25b2012-09-28 14:32:3751#include "ui/gfx/rect_conversions.h"
[email protected]4b01b962012-10-09 23:17:3552#include "ui/gfx/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4853#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2754#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4155#include "ui/surface/transport_dib.h"
[email protected]8c89e7792009-08-19 21:18:3456#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5057#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4658#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
[email protected]799fd732013-05-15 21:18:5259#include "webkit/renderer/compositor_bindings/web_rendering_stats_impl.h"
[email protected]661eb9d2009-02-03 02:11:4860
[email protected]eeb93112013-05-01 19:41:1061#if defined(OS_ANDROID)
62#include "content/renderer/android/synchronous_compositor_output_surface.h"
63#endif
64
[email protected]661eb9d2009-02-03 02:11:4865#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4966#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5267#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4168#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4869#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4470
[email protected]8bd0fe62011-01-17 06:44:3771#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2972
[email protected]fa7b1dc2010-06-23 17:53:0473using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3074using WebKit::WebCursorInfo;
[email protected]41d86852012-11-07 12:23:2475using WebKit::WebGestureEvent;
[email protected]62cb33cae2009-03-27 23:30:2276using WebKit::WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0677using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2878using WebKit::WebNavigationPolicy;
[email protected]a7547fb2012-03-08 04:43:4479using WebKit::WebPagePopup;
[email protected]e99ef6f2011-10-16 01:13:0080using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2881using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5982using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1883using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0184using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5285using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1986using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5287using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2888using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2489using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0490using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1891using WebKit::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:2692
[email protected]6a4d7f62013-01-07 21:32:1393namespace {
94const char* GetEventName(WebInputEvent::Type type) {
95#define CASE_TYPE(t) case WebInputEvent::t: return #t
96 switch(type) {
97 CASE_TYPE(Undefined);
98 CASE_TYPE(MouseDown);
99 CASE_TYPE(MouseUp);
100 CASE_TYPE(MouseMove);
101 CASE_TYPE(MouseEnter);
102 CASE_TYPE(MouseLeave);
103 CASE_TYPE(ContextMenu);
104 CASE_TYPE(MouseWheel);
105 CASE_TYPE(RawKeyDown);
106 CASE_TYPE(KeyDown);
107 CASE_TYPE(KeyUp);
108 CASE_TYPE(Char);
109 CASE_TYPE(GestureScrollBegin);
110 CASE_TYPE(GestureScrollEnd);
111 CASE_TYPE(GestureScrollUpdate);
112 CASE_TYPE(GestureFlingStart);
113 CASE_TYPE(GestureFlingCancel);
114 CASE_TYPE(GestureTap);
[email protected]1c43b0a2013-05-10 07:43:23115 CASE_TYPE(GestureTapUnconfirmed);
[email protected]6a4d7f62013-01-07 21:32:13116 CASE_TYPE(GestureTapDown);
117 CASE_TYPE(GestureTapCancel);
118 CASE_TYPE(GestureDoubleTap);
119 CASE_TYPE(GestureTwoFingerTap);
120 CASE_TYPE(GestureLongPress);
121 CASE_TYPE(GestureLongTap);
122 CASE_TYPE(GesturePinchBegin);
123 CASE_TYPE(GesturePinchEnd);
124 CASE_TYPE(GesturePinchUpdate);
125 CASE_TYPE(TouchStart);
126 CASE_TYPE(TouchMove);
127 CASE_TYPE(TouchEnd);
128 CASE_TYPE(TouchCancel);
[email protected]3ec08ed2013-01-11 15:59:57129 default:
130 // Must include default to let WebKit::WebInputEvent add new event types
131 // before they're added here.
132 DLOG(WARNING) << "Unhandled WebInputEvent type in GetEventName.\n";
133 break;
[email protected]6a4d7f62013-01-07 21:32:13134 }
135#undef CASE_TYPE
[email protected]3ec08ed2013-01-11 15:59:57136 return "";
[email protected]6a4d7f62013-01-07 21:32:13137}
138}
[email protected]e9ff79c2012-10-19 21:31:26139namespace content {
[email protected]62cb33cae2009-03-27 23:30:22140
[email protected]6fd35b72012-03-01 19:46:41141RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]842f10652012-06-06 01:54:04142 const WebKit::WebScreenInfo& screen_info,
[email protected]14392a52012-05-02 20:28:44143 bool swapped_out)
initial.commit09911bf2008-07-26 23:55:29144 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56145 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:11146 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:29147 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30148 init_complete_(false),
[email protected]b4d08452010-10-05 17:34:35149 current_paint_buf_(NULL),
[email protected]d9083762013-03-24 01:36:40150 overdraw_bottom_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29151 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:06152 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:05153 update_reply_pending_(false),
[email protected]847a2582013-03-09 02:29:51154 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09155 need_update_rect_for_auto_resize_(false),
[email protected]65225772011-05-12 21:10:24156 using_asynchronous_swapbuffers_(false),
157 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:29158 did_show_(false),
initial.commit09911bf2008-07-26 23:55:29159 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:09160 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:29161 needs_repainting_on_restore_(false),
162 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49163 handling_input_event_(false),
[email protected]e8f775f2013-02-14 21:00:50164 handling_ime_event_(false),
[email protected]661eb9d2009-02-03 02:11:48165 closing_(false),
[email protected]14392a52012-05-02 20:28:44166 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04167 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45168 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
169 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12170 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48171 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12172 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50173 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21174 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07175 invalidation_task_posted_(false),
[email protected]842f10652012-06-06 01:54:04176 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52177 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]0e241b4b2012-08-18 09:06:27178 throttle_input_events_(true),
[email protected]ed7defa2013-03-12 21:29:59179 is_threaded_compositing_enabled_(false),
[email protected]69e797f2013-04-30 01:10:22180 weak_ptr_factory_(this) {
[email protected]8b3f0eb2012-05-03 19:15:05181 if (!swapped_out)
182 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27183 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18184 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
185 switches::kDisableGpuVsync);
[email protected]cb6430932012-10-31 00:53:36186 is_threaded_compositing_enabled_ =
187 CommandLine::ForCurrentProcess()->HasSwitch(
188 switches::kEnableThreadedCompositing);
initial.commit09911bf2008-07-26 23:55:29189}
190
191RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11192 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21193 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35194 if (current_paint_buf_) {
195 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
196 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29197 }
[email protected]992db4c2011-05-12 15:37:15198 // If we are swapped out, we have released already.
199 if (!is_swapped_out_)
200 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29201}
202
[email protected]484955942010-08-19 16:13:18203// static
[email protected]8085dbc82008-09-26 22:53:44204RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:04205 WebKit::WebPopupType popup_type,
206 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29207 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41208 scoped_refptr<RenderWidget> widget(
[email protected]842f10652012-06-06 01:54:04209 new RenderWidget(popup_type, screen_info, false));
[email protected]a635f942012-12-07 10:34:29210 if (widget->Init(opener_id)) { // adds reference on success.
211 return widget;
212 }
213 return NULL;
initial.commit09911bf2008-07-26 23:55:29214}
215
[email protected]484955942010-08-19 16:13:18216// static
217WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
218 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03219 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18220 break;
221 case WebKit::WebPopupTypeSelect:
222 case WebKit::WebPopupTypeSuggestion:
223 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44224 case WebKit::WebPopupTypePage:
225 return WebPagePopup::create(render_widget);
[email protected]4b1146bc2012-07-10 18:46:03226 case WebKit::WebPopupTypeHelperPlugin:
227 return WebKit::WebHelperPlugin::create(render_widget);
[email protected]484955942010-08-19 16:13:18228 default:
229 NOTREACHED();
230 }
231 return NULL;
232}
233
[email protected]a635f942012-12-07 10:34:29234bool RenderWidget::Init(int32 opener_id) {
235 return DoInit(opener_id,
236 RenderWidget::CreateWebWidget(this),
237 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
238 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18239}
240
[email protected]a635f942012-12-07 10:34:29241bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06242 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18243 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29244 DCHECK(!webwidget_);
245
246 if (opener_id != MSG_ROUTING_NONE)
247 opener_id_ = opener_id;
248
[email protected]484955942010-08-19 16:13:18249 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29250
[email protected]380244092011-10-07 17:26:27251 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29252 if (result) {
[email protected]380244092011-10-07 17:26:27253 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29254 // Take a reference on behalf of the RenderThread. This will be balanced
255 // when we receive ViewMsg_Close.
256 AddRef();
[email protected]a635f942012-12-07 10:34:29257 return true;
initial.commit09911bf2008-07-26 23:55:29258 } else {
[email protected]a635f942012-12-07 10:34:29259 // The above Send can fail when the tab is closing.
260 return false;
initial.commit09911bf2008-07-26 23:55:29261 }
262}
263
[email protected]fc4404d2012-11-07 19:53:30264// This is used to complete pending inits and non-pending inits.
265void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29266 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29267
[email protected]fc4404d2012-11-07 19:53:30268 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42269
[email protected]8926c602013-01-23 05:32:06270 if (webwidget_ && is_threaded_compositing_enabled_) {
271 webwidget_->enterForceCompositingMode(true);
272 }
[email protected]ba91a792013-02-06 09:48:28273 if (compositor_) {
274 compositor_->setSurfaceReady();
[email protected]479b0172012-10-29 19:27:09275 }
[email protected]05a980d7a2012-02-07 22:16:42276 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29277
[email protected]6de74452009-02-25 18:04:59278 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29279}
280
[email protected]992db4c2011-05-12 15:37:15281void RenderWidget::SetSwappedOut(bool is_swapped_out) {
282 // We should only toggle between states.
283 DCHECK(is_swapped_out_ != is_swapped_out);
284 is_swapped_out_ = is_swapped_out;
285
286 // If we are swapping out, we will call ReleaseProcess, allowing the process
287 // to exit if all of its RenderViews are swapped out. We wait until the
288 // WasSwappedOut call to do this, to avoid showing the sad tab.
289 // If we are swapping in, we call AddRefProcess to prevent the process from
290 // exiting.
291 if (!is_swapped_out)
292 RenderProcess::current()->AddRefProcess();
293}
294
[email protected]34bb3ac2013-03-08 02:41:28295bool RenderWidget::AllowPartialSwap() const {
296 return true;
297}
298
[email protected]ccc1722e2013-05-06 19:43:07299bool RenderWidget::SynchronouslyDisableVSync() const {
300#if defined(OS_ANDROID)
301 if (CommandLine::ForCurrentProcess()->HasSwitch(
302 switches::kEnableSynchronousRendererCompositor)) {
303 return true;
304 }
305#endif
306 return false;
307}
308
[email protected]a95986a82010-12-24 06:19:28309bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
310 bool handled = true;
311 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15312 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22313 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
314 OnCursorVisibilityChange)
[email protected]c084330e02013-04-27 01:08:15315 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
316 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]a95986a82010-12-24 06:19:28317 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
318 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
319 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54320 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28321 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41322 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]992db4c2011-05-12 15:37:15323 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28324 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]ed7defa2013-03-12 21:29:59325 IPC_MESSAGE_HANDLER(ViewMsg_SwapBuffers_ACK,
326 OnViewContextSwapBuffersComplete)
[email protected]a95986a82010-12-24 06:19:28327 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
328 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
329 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]3d9ec5052013-01-02 22:05:25330 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnPaintAtSize)
331 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
332 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, OnSmoothScrollCompleted)
[email protected]a95986a82010-12-24 06:19:28333 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
334 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]6131a642012-06-15 23:26:53335 IPC_MESSAGE_HANDLER(ViewMsg_ScreenInfoChanged, OnScreenInfoChanged)
[email protected]80ad8622012-11-07 16:33:03336 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]105dffb42013-02-20 03:46:21337#if defined(OS_ANDROID)
338 IPC_MESSAGE_HANDLER(ViewMsg_ImeBatchStateChanged, OnImeBatchStateChanged)
[email protected]2384b6c2013-02-28 23:58:51339 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21340#endif
[email protected]51a49502013-03-23 01:50:19341 IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot)
[email protected]a95986a82010-12-24 06:19:28342 IPC_MESSAGE_UNHANDLED(handled = false)
343 IPC_END_MESSAGE_MAP()
344 return handled;
345}
initial.commit09911bf2008-07-26 23:55:29346
347bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15348 // Don't send any messages after the browser has told us to close, and filter
349 // most outgoing messages while swapped out.
350 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26351 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11352 closing_) {
initial.commit09911bf2008-07-26 23:55:29353 delete message;
354 return false;
355 }
356
357 // If given a messsage without a routing ID, then assign our routing ID.
358 if (message->routing_id() == MSG_ROUTING_NONE)
359 message->set_routing_id(routing_id_);
360
[email protected]380244092011-10-07 17:26:27361 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44362}
363
[email protected]61e2b3cc2012-03-02 16:13:34364void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44365 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40366 float overdraw_bottom_height,
[email protected]61e2b3cc2012-03-02 16:13:34367 const gfx::Rect& resizer_rect,
368 bool is_fullscreen,
369 ResizeAck resize_ack) {
370 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
371 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
372 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29373
[email protected]61e2b3cc2012-03-02 16:13:34374 // Ignore this during shutdown.
375 if (!webwidget_)
376 return;
377
[email protected]d9083762013-03-24 01:36:40378 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44379 compositor_->setViewportSize(new_size, physical_backing_size);
[email protected]d9083762013-03-24 01:36:40380 compositor_->SetOverdrawBottomHeight(overdraw_bottom_height);
381 }
[email protected]60d47ac2013-03-01 23:42:44382
[email protected]dade8992013-03-04 07:34:34383 physical_backing_size_ = physical_backing_size;
[email protected]d9083762013-03-24 01:36:40384 overdraw_bottom_height_ = overdraw_bottom_height;
[email protected]61e2b3cc2012-03-02 16:13:34385 resizer_rect_ = resizer_rect;
386
387 // NOTE: We may have entered fullscreen mode without changing our size.
388 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
389 if (fullscreen_change)
390 WillToggleFullscreen();
391 is_fullscreen_ = is_fullscreen;
392
393 if (size_ != new_size) {
394 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34395 needs_repainting_on_restore_ = false;
396
397 size_ = new_size;
398
399 paint_aggregator_.ClearPendingUpdate();
400
401 // When resizing, we want to wait to paint before ACK'ing the resize. This
402 // ensures that we only resize as fast as we can paint. We only need to
403 // send an ACK if we are resized to a non-empty rect.
404 webwidget_->resize(new_size);
[email protected]0b70dbe2013-05-10 19:06:32405
406 // Resize should have caused an invalidation of the entire view.
407 DCHECK(new_size.IsEmpty() || is_accelerated_compositing_active_ ||
408 paint_aggregator_.HasPendingUpdate());
[email protected]632c4382013-05-15 08:58:45409 } else if (!RenderThreadImpl::current() || // Will be NULL during unit tests.
410 !RenderThreadImpl::current()->short_circuit_size_updates()) {
411 resize_ack = NO_RESIZE_ACK;
412 }
413
414 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
415 // For empty size or empty physical_backing_size, there is no next paint
416 // (along with which to send the ack) until they are set to non-empty.
[email protected]ff475a322012-03-14 00:05:35417 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34418 }
419
[email protected]20fbfc22013-05-08 20:50:58420 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45421 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58422 set_next_paint_is_resize_ack();
423
[email protected]61e2b3cc2012-03-02 16:13:34424 if (fullscreen_change)
425 DidToggleFullscreen();
426
427 // If a resize ack is requested and it isn't set-up, then no more resizes will
428 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45429 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29430}
431
432void RenderWidget::OnClose() {
433 if (closing_)
434 return;
435 closing_ = true;
436
437 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03438 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27439 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03440 SetHidden(false);
441 }
initial.commit09911bf2008-07-26 23:55:29442
initial.commit09911bf2008-07-26 23:55:29443 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25444 // now. Post a task that only gets invoked when there are no nested message
445 // loops.
[email protected]dd32b1272013-05-04 14:17:11446 base::MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29447 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25448
449 // Balances the AddRef taken when we called AddRoute.
450 Release();
initial.commit09911bf2008-07-26 23:55:29451}
452
[email protected]61e2b3cc2012-03-02 16:13:34453// Got a response from the browser after the renderer decided to create a new
454// view.
[email protected]fc4404d2012-11-07 19:53:30455void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34456 DCHECK(routing_id_ != MSG_ROUTING_NONE);
457
[email protected]fc4404d2012-11-07 19:53:30458 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34459}
460
[email protected]f21c613a2009-02-12 14:46:17461void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44462 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40463 float overdraw_bottom_height,
[email protected]ee41e7d22011-10-14 19:34:09464 const gfx::Rect& resizer_rect,
465 bool is_fullscreen) {
[email protected]d9083762013-03-24 01:36:40466 Resize(new_size, physical_backing_size, overdraw_bottom_height, resizer_rect,
467 is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29468}
469
[email protected]b5913d72012-02-07 22:26:54470void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
471 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59472 gfx::Rect view_rect(size_);
473
[email protected]ce112fe2012-10-29 22:52:18474 gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_);
[email protected]b9769d82012-02-10 00:23:59475 if (!old_damage_rect.IsEmpty())
476 paint_aggregator_.InvalidateRect(old_damage_rect);
477
[email protected]ce112fe2012-10-29 22:52:18478 gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect);
[email protected]b9769d82012-02-10 00:23:59479 if (!new_damage_rect.IsEmpty())
480 paint_aggregator_.InvalidateRect(new_damage_rect);
481
[email protected]b5913d72012-02-07 22:26:54482 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59483
[email protected]b5913d72012-02-07 22:26:54484 if (webwidget_)
485 webwidget_->didChangeWindowResizerRect();
486 }
487}
488
initial.commit09911bf2008-07-26 23:55:29489void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31490 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29491 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03492 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29493}
494
[email protected]9e2e4632012-07-27 16:38:41495void RenderWidget::OnWasShown(bool needs_repainting) {
496 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29497 // During shutdown we can just ignore this message.
498 if (!webwidget_)
499 return;
500
501 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03502 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29503
504 if (!needs_repainting && !needs_repainting_on_restore_)
505 return;
506 needs_repainting_on_restore_ = false;
507
[email protected]d65adb12010-04-28 17:26:49508 // Tag the next paint as a restore ack, which is picked up by
509 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29510 set_next_paint_is_restore_ack();
511
512 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56513 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46514 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
515 } else {
516 scheduleComposite();
517 }
initial.commit09911bf2008-07-26 23:55:29518}
519
[email protected]992db4c2011-05-12 15:37:15520void RenderWidget::OnWasSwappedOut() {
521 // If we have been swapped out and no one else is using this process,
522 // it's safe to exit now. If we get swapped back in, we will call
523 // AddRefProcess in SetSwappedOut.
524 if (is_swapped_out_)
525 RenderProcess::current()->ReleaseProcess();
526}
527
[email protected]53d3f302009-12-21 04:42:05528void RenderWidget::OnRequestMoveAck() {
529 DCHECK(pending_window_rect_count_);
530 pending_window_rect_count_--;
531}
532
533void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58534 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21535 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05536 update_reply_pending_ = false;
537
[email protected]b4d08452010-10-05 17:34:35538 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
539 // have no current paint buffer.
540 if (current_paint_buf_) {
541 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
542 current_paint_buf_ = NULL;
543 }
544
[email protected]65225772011-05-12 21:10:24545 // If swapbuffers is still pending, then defer the update until the
546 // swapbuffers occurs.
547 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
548 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
549 return;
550 }
551
[email protected]29ed96a2012-02-04 18:12:16552 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18553 if (!is_accelerated_compositing_active_) {
554 DidFlushPaint();
555 }
[email protected]a2f6bc112009-06-27 16:27:25556
initial.commit09911bf2008-07-26 23:55:29557 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24558 DoDeferredUpdateAndSendInputAck();
559}
560
[email protected]d0be63772011-12-20 23:18:04561bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]ed7defa2013-03-12 21:29:59562 // Contexts using the command buffer support asynchronous swapbuffers.
563 // See RenderWidget::CreateOutputSurface().
[email protected]8f746982013-03-21 06:28:03564 if (RenderThreadImpl::current()->compositor_message_loop_proxy())
[email protected]ed7defa2013-03-12 21:29:59565 return false;
566
567 return true;
568}
569
570GURL RenderWidget::GetURLForGraphicsContext3D() {
571 return GURL();
[email protected]65225772011-05-12 21:10:24572}
573
[email protected]479b0172012-10-29 19:27:09574bool RenderWidget::ForceCompositingModeEnabled() {
575 return false;
576}
577
[email protected]ba91a792013-02-06 09:48:28578scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface() {
[email protected]c3e32ed42013-05-02 05:07:13579 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]a1811b8912013-05-09 15:35:19580
581#if defined(OS_ANDROID)
582 if (command_line.HasSwitch(switches::kEnableSynchronousRendererCompositor)) {
583 return scoped_ptr<cc::OutputSurface>(
584 new SynchronousCompositorOutputSurface(routing_id()));
585 }
586#endif
587
[email protected]8bbe3a92013-05-12 00:58:35588 if (command_line.HasSwitch(switches::kEnableSoftwareCompositingGLAdapter)) {
589 return scoped_ptr<cc::OutputSurface>(
590 new CompositorOutputSurface(routing_id(), NULL,
591 new CompositorSoftwareOutputDevice()));
592 }
593
[email protected]ed7defa2013-03-12 21:29:59594 // Explicitly disable antialiasing for the compositor. As of the time of
595 // this writing, the only platform that supported antialiasing for the
596 // compositor was Mac OS X, because the on-screen OpenGL context creation
597 // code paths on Windows and Linux didn't yet have multisampling support.
598 // Mac OS X essentially always behaves as though it's rendering offscreen.
599 // Multisampling has a heavy cost especially on devices with relatively low
600 // fill rate like most notebooks, and the Mac implementation would need to
601 // be optimized to resolve directly into the IOSurface shared between the
602 // GPU and browser processes. For these reasons and to avoid platform
603 // disparities we explicitly disable antialiasing.
604 WebKit::WebGraphicsContext3D::Attributes attributes;
605 attributes.antialias = false;
606 attributes.shareResources = true;
607 attributes.noAutomaticFlushes = true;
[email protected]a6886502013-05-16 20:59:18608 attributes.depth = false;
609 attributes.stencil = false;
[email protected]3ae68c52013-04-12 06:10:05610 WebGraphicsContext3DCommandBufferImpl* context =
611 CreateGraphicsContext3D(attributes);
[email protected]8bbe3a92013-05-12 00:58:35612 if (!context)
613 return scoped_ptr<cc::OutputSurface>();
[email protected]ed7defa2013-03-12 21:29:59614
[email protected]2847b222013-04-06 00:59:24615 bool composite_to_mailbox =
[email protected]7b45b5762013-05-08 14:36:56616 command_line.HasSwitch(cc::switches::kCompositeToMailbox) &&
617 !command_line.HasSwitch(switches::kEnableDelegatedRenderer);
[email protected]2847b222013-04-06 00:59:24618 // No swap throttling yet when compositing on the main thread.
619 DCHECK(!composite_to_mailbox || is_threaded_compositing_enabled_);
620 return scoped_ptr<cc::OutputSurface>(composite_to_mailbox ?
621 new MailboxOutputSurface(routing_id(), context, NULL) :
622 new CompositorOutputSurface(routing_id(), context, NULL));
[email protected]ba91a792013-02-06 09:48:28623}
624
[email protected]ed7defa2013-03-12 21:29:59625void RenderWidget::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24626 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21627 while (!updates_pending_swap_.empty()) {
628 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
629 updates_pending_swap_.pop_front();
630 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
631 // compositing pass, hence doesn't require an UpdateRect message.
632 if (msg)
633 Send(msg);
634 }
[email protected]65225772011-05-12 21:10:24635 num_swapbuffers_complete_pending_ = 0;
636 using_asynchronous_swapbuffers_ = false;
637 // Schedule another frame so the compositor learns about it.
638 scheduleComposite();
639}
640
[email protected]ed7defa2013-03-12 21:29:59641void RenderWidget::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:08642 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21643
644 if (using_asynchronous_swapbuffers_) {
645 ViewHostMsg_UpdateRect* msg = NULL;
646 // pending_update_params_ can be NULL if the swap doesn't correspond to an
647 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
648 // message.
[email protected]59383c782013-04-17 16:43:27649 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:21650 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
651 pending_update_params_.reset();
652 }
653 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08654 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21655 }
[email protected]37a6f302011-07-11 23:43:08656}
657
[email protected]ed7defa2013-03-12 21:29:59658void RenderWidget::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24659 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16660
[email protected]404939f2012-06-01 04:06:18661 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16662 DidFlushPaint();
663
[email protected]65225772011-05-12 21:10:24664 // When compositing deactivates, we reset the swapbuffers pending count. The
665 // swapbuffers acks may still arrive, however.
666 if (num_swapbuffers_complete_pending_ == 0) {
667 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
668 return;
669 }
[email protected]aa4117f2011-12-09 22:19:21670 DCHECK(!updates_pending_swap_.empty());
671 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
672 updates_pending_swap_.pop_front();
673 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
674 // compositing pass, hence doesn't require an UpdateRect message.
675 if (msg)
676 Send(msg);
[email protected]65225772011-05-12 21:10:24677 num_swapbuffers_complete_pending_--;
678
679 // If update reply is still pending, then defer the update until that reply
680 // occurs.
[email protected]d0be63772011-12-20 23:18:04681 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24682 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
683 return;
684 }
685
686 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06687 // when we were previously rendering. However, if an invalidation task is not
688 // posted, there may be software rendering work pending. In that case, don't
689 // early out.
690 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24691 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
692 return;
693 }
694
[email protected]cc66e682012-10-02 06:48:18695 // Do not call DoDeferredUpdate unless there's animation work to be done or
696 // a real invalidation. This prevents rendering in response to a swapbuffers
697 // callback coming back after we've navigated away from the page that
698 // generated it.
699 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
700 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
701 return;
702 }
703
[email protected]65225772011-05-12 21:10:24704 // Continue painting if necessary...
705 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29706}
707
[email protected]0dea1652012-12-14 00:09:09708void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
[email protected]c2eaa8f2013-05-10 02:41:55709 const cc::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:09710 bool is_keyboard_shortcut) {
[email protected]65225772011-05-12 21:10:24711 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
initial.commit09911bf2008-07-26 23:55:29712
[email protected]5dd768212009-08-13 23:34:49713 handling_input_event_ = true;
[email protected]0dea1652012-12-14 00:09:09714 if (!input_event) {
[email protected]5dd768212009-08-13 23:34:49715 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29716 return;
[email protected]5dd768212009-08-13 23:34:49717 }
initial.commit09911bf2008-07-26 23:55:29718
[email protected]c2eaa8f2013-05-10 02:41:55719 if (compositor_)
720 compositor_->SetLatencyInfo(latency_info);
721
[email protected]6a4d7f62013-01-07 21:32:13722 base::TimeDelta now = base::TimeDelta::FromInternalValue(
723 base::TimeTicks::Now().ToInternalValue());
724
725 int64 delta = static_cast<int64>(
726 (now.InSecondsF() - input_event->timeStampSeconds) *
727 base::Time::kMicrosecondsPerSecond);
728 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer", delta, 0, 1000000, 100);
729 std::string name_for_event =
730 base::StringPrintf("Event.Latency.Renderer.%s",
731 GetEventName(input_event->type));
[email protected]de415552013-01-23 04:12:17732 base::HistogramBase* counter_for_type =
[email protected]bafdc5d52013-02-27 18:18:48733 base::Histogram::FactoryGet(
[email protected]6a4d7f62013-01-07 21:32:13734 name_for_event,
[email protected]bafdc5d52013-02-27 18:18:48735 0,
736 1000000,
[email protected]6a4d7f62013-01-07 21:32:13737 100,
[email protected]de415552013-01-23 04:12:17738 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]bafdc5d52013-02-27 18:18:48739 counter_for_type->Add(delta);
[email protected]6a4d7f62013-01-07 21:32:13740
[email protected]67bfb83f2011-09-22 03:36:37741 bool prevent_default = false;
742 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26743 const WebMouseEvent& mouse_event =
744 *static_cast<const WebMouseEvent*>(input_event);
745 TRACE_EVENT2("renderer", "HandleMouseMove",
746 "x", mouse_event.x, "y", mouse_event.y);
747 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37748 }
749
[email protected]41d86852012-11-07 12:23:24750 if (WebInputEvent::isGestureEventType(input_event->type)) {
751 const WebGestureEvent& gesture_event =
752 *static_cast<const WebGestureEvent*>(input_event);
753 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
754 }
755
[email protected]3ebcc7c2013-01-09 05:34:46756 if (input_event->type == WebInputEvent::GestureTap ||
757 input_event->type == WebInputEvent::GestureLongPress)
758 resetInputMethod();
759
[email protected]67bfb83f2011-09-22 03:36:37760 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12761 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
762 suppress_next_char_events_ = false;
763 if (!processed && webwidget_)
764 processed = webwidget_->handleInputEvent(*input_event);
765 }
766
767 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
768 // it's not processed by webkit, then we need to suppress the upcoming Char
769 // events.
770 if (!processed && is_keyboard_shortcut)
771 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29772
[email protected]3d5c243b2012-11-30 00:26:01773 InputEventAckState ack_result = processed ?
774 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
775 if (!processed && input_event->type == WebInputEvent::TouchStart) {
776 const WebTouchEvent& touch_event =
777 *static_cast<const WebTouchEvent*>(input_event);
778 ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ?
779 INPUT_EVENT_ACK_STATE_NOT_CONSUMED :
780 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
781 }
782
[email protected]a9fb30aa2011-10-06 06:58:46783 IPC::Message* response =
[email protected]c084330e02013-04-27 01:08:15784 new InputHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
785 ack_result);
[email protected]3391a0772012-03-28 00:32:07786 bool event_type_gets_rate_limited =
787 input_event->type == WebInputEvent::MouseMove ||
788 input_event->type == WebInputEvent::MouseWheel ||
789 WebInputEvent::isTouchEventType(input_event->type);
[email protected]8926c602013-01-23 05:32:06790
791 bool frame_pending = paint_aggregator_.HasPendingUpdate();
792 if (is_accelerated_compositing_active_) {
[email protected]ba91a792013-02-06 09:48:28793 frame_pending = compositor_ &&
794 compositor_->commitRequested();
[email protected]8926c602013-01-23 05:32:06795 }
796
[email protected]3391a0772012-03-28 00:32:07797 bool is_input_throttled =
[email protected]ce2b28e2012-08-09 15:53:57798 throttle_input_events_ &&
[email protected]8926c602013-01-23 05:32:06799 frame_pending;
[email protected]e2824412009-02-27 01:57:05800
[email protected]f8868d72012-04-27 19:13:03801 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24802 // We want to rate limit the input events in this case, so we'll wait for
803 // painting to finish before ACKing this message.
[email protected]59383c782013-04-17 16:43:27804 if (pending_input_event_ack_) {
[email protected]353a34c2010-05-28 23:35:17805 // As two different kinds of events could cause us to postpone an ack
806 // we send it now, if we have one pending. The Browser should never
807 // send us the same kind of event we are delaying the ack for.
808 Send(pending_input_event_ack_.release());
809 }
[email protected]12fbad812009-09-01 18:21:24810 pending_input_event_ack_.reset(response);
811 } else {
812 Send(response);
813 }
814
[email protected]3306f262012-09-21 19:20:42815#if defined(OS_ANDROID)
816 // Allow the IME to be shown when the focus changes as a consequence
817 // of a processed touch end event.
818 if (input_event->type == WebInputEvent::TouchEnd && processed)
819 UpdateTextInputState(SHOW_IME_IF_NEEDED);
820#endif
821
[email protected]5dd768212009-08-13 23:34:49822 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48823
[email protected]67bfb83f2011-09-22 03:36:37824 if (!prevent_default) {
825 if (WebInputEvent::isKeyboardEventType(input_event->type))
826 DidHandleKeyEvent();
827 if (WebInputEvent::isMouseEventType(input_event->type))
828 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24829 if (WebInputEvent::isTouchEventType(input_event->type))
830 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37831 }
initial.commit09911bf2008-07-26 23:55:29832}
833
[email protected]34202de2013-05-06 23:36:22834void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
835 if (webwidget_)
836 webwidget_->setCursorVisibilityState(is_visible);
837}
838
initial.commit09911bf2008-07-26 23:55:29839void RenderWidget::OnMouseCaptureLost() {
840 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28841 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29842}
843
844void RenderWidget::OnSetFocus(bool enable) {
845 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33846 if (webwidget_)
847 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29848}
849
850void RenderWidget::ClearFocus() {
851 // We may have got the focus from the browser before this gets processed, in
852 // which case we do not want to unfocus ourself.
853 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28854 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29855}
856
[email protected]2d5d09d52009-06-15 14:29:21857void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00858 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21859 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06860 TRACE_EVENT2("renderer", "PaintRect",
861 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:45862
863 const bool kEnableGpuBenchmarking =
864 CommandLine::ForCurrentProcess()->HasSwitch(
865 switches::kEnableGpuBenchmarking);
[email protected]4fb66842009-12-04 21:41:00866 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21867
868 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00869 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
870 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03871
[email protected]699ab0d2009-04-23 23:19:14872 // If there is a custom background, tile it.
873 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14874 SkPaint paint;
[email protected]4e29afd2012-12-04 04:07:11875 skia::RefPtr<SkShader> shader = skia::AdoptRef(
876 SkShader::CreateBitmapShader(background_,
877 SkShader::kRepeat_TileMode,
878 SkShader::kRepeat_TileMode));
879 paint.setShader(shader.get());
[email protected]fb10ec5b2011-10-24 17:54:20880
881 // Use kSrc_Mode to handle background_ transparency properly.
882 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
883
884 // Canvas could contain multiple update rects. Clip to given rect so that
885 // we don't accidentally clear other update rects.
886 canvas->save();
[email protected]aa7e7a12013-02-22 13:37:44887 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]1835b9e2012-02-28 13:12:48888 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14889 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20890 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14891 }
892
[email protected]719b36f2010-12-22 20:36:46893 // First see if this rect is a plugin that can paint itself faster.
894 TransportDIB* optimized_dib = NULL;
895 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:20896 float dib_scale_factor;
[email protected]719b36f2010-12-22 20:36:46897 webkit::ppapi::PluginInstance* optimized_instance =
898 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
899 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:20900 &optimized_copy_rect,
901 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:46902 if (optimized_instance) {
903 // This plugin can be optimize-painted and we can just ask it to paint
904 // itself. We don't actually need the TransportDIB in this case.
905 //
906 // This is an optimization for PPAPI plugins that know they're on top of
907 // the page content. If this rect is inside such a plugin, we can save some
908 // time and avoid re-rendering the page content which we know will be
909 // covered by the plugin later (this time can be significant, especially
910 // for a playing movie that is invalidating a lot).
911 //
912 // In the plugin movie case, hopefully the similar call to
913 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
914 // painting, because that avoids copying the plugin image to a different
915 // paint rect. Unfortunately, if anything on the page is animating other
916 // than the movie, it break this optimization since the union of the
917 // invalid regions will be larger than the plugin.
918 //
919 // This code optimizes that case, where we can still avoid painting in
920 // WebKit and filling the background (which can be slow) and just painting
921 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
922 // required.
[email protected]63ab54262012-11-09 15:58:45923 base::TimeTicks paint_begin_ticks;
924 if (kEnableGpuBenchmarking)
925 paint_begin_ticks = base::TimeTicks::HighResNow();
926
[email protected]df59dd42012-09-14 22:56:30927 SkAutoCanvasRestore auto_restore(canvas, true);
928 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]719b36f2010-12-22 20:36:46929 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27930 optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:21931 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45932 if (kEnableGpuBenchmarking) {
933 base::TimeDelta paint_time =
934 base::TimeTicks::HighResNow() - paint_begin_ticks;
935 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01936 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45937 }
[email protected]719b36f2010-12-22 20:36:46938 } else {
939 // Normal painting case.
[email protected]63ab54262012-11-09 15:58:45940 base::TimeTicks paint_begin_ticks;
941 if (kEnableGpuBenchmarking)
942 paint_begin_ticks = base::TimeTicks::HighResNow();
943
[email protected]719b36f2010-12-22 20:36:46944 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
[email protected]63ab54262012-11-09 15:58:45945
946 if (kEnableGpuBenchmarking) {
947 base::TimeDelta paint_time =
948 base::TimeTicks::HighResNow() - paint_begin_ticks;
949 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01950 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45951 }
[email protected]719b36f2010-12-22 20:36:46952
953 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35954 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46955 }
initial.commit09911bf2008-07-26 23:55:29956
[email protected]4fb66842009-12-04 21:41:00957 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00958 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45959
960 if (kEnableGpuBenchmarking) {
[email protected]63ab54262012-11-09 15:58:45961 int64 num_pixels_processed = rect.width() * rect.height();
[email protected]62049562013-03-24 00:39:01962 software_stats_.total_pixels_painted += num_pixels_processed;
[email protected]63ab54262012-11-09 15:58:45963 }
[email protected]4fb66842009-12-04 21:41:00964}
965
966void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
967 skia::PlatformCanvas* canvas) {
968 static bool kPaintBorder =
969 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
970 if (!kPaintBorder)
971 return;
972
[email protected]53d3f302009-12-21 04:42:05973 // Cycle through these colors to help distinguish new paint rects.
974 const SkColor colors[] = {
975 SkColorSetARGB(0x3F, 0xFF, 0, 0),
976 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
977 SkColorSetARGB(0x3F, 0, 0, 0xFF),
978 };
979 static int color_selector = 0;
980
[email protected]4fb66842009-12-04 21:41:00981 SkPaint paint;
982 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05983 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00984 paint.setStrokeWidth(1);
985
986 SkIRect irect;
987 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
988 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29989}
990
[email protected]52ccd0ea2011-02-16 01:09:05991void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30992 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30993 if (!animation_update_pending_) {
994 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59995 return;
[email protected]921244e42011-07-20 16:36:30996 }
[email protected]bd37ae252011-06-03 01:28:18997 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59998 // Record when we fired (according to base::Time::Now()) relative to when
999 // we posted the task to quantify how much the base::Time/base::TimeTicks
1000 // skew is affecting animations.
1001 base::TimeDelta animation_callback_delay = base::Time::Now() -
1002 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
1003 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
1004 animation_callback_delay,
1005 base::TimeDelta::FromMilliseconds(0),
1006 base::TimeDelta::FromMilliseconds(30),
1007 25);
1008 }
[email protected]65225772011-05-12 21:10:241009 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:241010}
1011
[email protected]52ccd0ea2011-02-16 01:09:051012void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:591013 if (!animation_update_pending_)
1014 return;
[email protected]bd37ae252011-06-03 01:28:181015
1016 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:331017 base::TimeDelta animationInterval = IsRenderingVSynced() ?
1018 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:181019
[email protected]7c4329e2011-02-18 22:02:591020 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:451021
1022 // animation_floor_time_ is the earliest time that we should animate when
1023 // using the dead reckoning software scheduler. If we're using swapbuffers
1024 // complete callbacks to rate limit, we can ignore this floor.
1025 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:301026 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:331027 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:181028 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:591029 // running animation callbacks so that if a callback requests another
1030 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:381031 animation_timer_.Stop();
1032 animation_timer_.Start(FROM_HERE, animationInterval, this,
1033 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:591034 animation_update_pending_ = false;
[email protected]ba91a792013-02-06 09:48:281035 if (is_accelerated_compositing_active_ && compositor_) {
[email protected]635353c2013-03-06 09:11:201036 compositor_->Animate(base::TimeTicks::Now());
[email protected]8926c602013-01-23 05:32:061037 } else {
[email protected]635353c2013-03-06 09:11:201038 double frame_begin_time =
1039 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
1040 webwidget_->animate(frame_begin_time);
[email protected]8926c602013-01-23 05:32:061041 }
[email protected]7c4329e2011-02-18 22:02:591042 return;
[email protected]5f8b1022011-01-21 23:34:501043 }
[email protected]bd37ae252011-06-03 01:28:181044 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:381045 if (!animation_timer_.IsRunning()) {
1046 // This code uses base::Time::Now() to calculate the floor and next fire
1047 // time because javascript's Date object uses base::Time::Now(). The
1048 // message loop uses base::TimeTicks, which on windows can have a
1049 // different granularity than base::Time.
1050 // The upshot of all this is that this function might be called before
1051 // base::Time::Now() has advanced past the animation_floor_time_. To
1052 // avoid exposing this delay to javascript, we keep posting delayed
1053 // tasks until base::Time::Now() has advanced far enough.
1054 base::TimeDelta delay = animation_floor_time_ - now;
1055 animation_timer_.Start(FROM_HERE, delay, this,
1056 &RenderWidget::AnimationCallback);
1057 }
[email protected]5f8b1022011-01-21 23:34:501058}
1059
[email protected]bd37ae252011-06-03 01:28:181060bool RenderWidget::IsRenderingVSynced() {
1061 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
1062 // not caught by this check. This will lead to artificially low frame rates
1063 // for people who force vsync off at a driver level and expect Chrome to speed
1064 // up.
1065 return !has_disable_gpu_vsync_switch_;
1066}
1067
[email protected]65225772011-05-12 21:10:241068void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:061069 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:241070 invalidation_task_posted_ = false;
1071 DoDeferredUpdateAndSendInputAck();
1072}
1073
1074void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:051075 DoDeferredUpdate();
1076
[email protected]59383c782013-04-17 16:43:271077 if (pending_input_event_ack_)
[email protected]52ccd0ea2011-02-16 01:09:051078 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:211079}
1080
[email protected]552e6002009-11-19 05:24:571081void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:581082 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:081083
[email protected]65225772011-05-12 21:10:241084 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:291085 return;
[email protected]05a980d7a2012-02-07 22:16:421086
[email protected]fc4404d2012-11-07 19:53:301087 if (!init_complete_) {
1088 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:421089 return;
1090 }
[email protected]aa4117f2011-12-09 22:19:211091 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:241092 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
1093 return;
1094 }
[email protected]9ca84622011-06-02 23:46:391095 if (is_accelerated_compositing_active_ &&
1096 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:241097 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
1098 return;
1099 }
initial.commit09911bf2008-07-26 23:55:291100
[email protected]552e6002009-11-19 05:24:571101 // Suppress updating when we are hidden.
[email protected]e3d92a7f2013-01-10 02:35:051102 if (is_hidden_ || size_.IsEmpty() || is_swapped_out_) {
[email protected]552e6002009-11-19 05:24:571103 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:291104 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:241105 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:291106 return;
1107 }
1108
[email protected]05a980d7a2012-02-07 22:16:421109 if (is_accelerated_compositing_active_)
1110 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
1111
[email protected]0fb93f52011-05-18 23:13:561112 // Tracking of frame rate jitter
1113 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]38ce4e7b2013-02-23 06:17:371114 InstrumentWillBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:051115 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:501116
[email protected]f98d7e3c2010-09-13 22:30:461117 // Layout may generate more invalidation. It may also enable the
1118 // GPU acceleration, so make sure to run layout before we send the
1119 // GpuRenderingActivated message.
1120 webwidget_->layout();
1121
[email protected]dcca3aa92012-02-17 23:03:371122 // The following two can result in further layout and possibly
1123 // enable GPU acceleration so they need to be called before any painting
1124 // is done.
[email protected]3306f262012-09-21 19:20:421125 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]dcca3aa92012-02-17 23:03:371126 UpdateSelectionBounds();
1127
[email protected]5f8b1022011-01-21 23:34:501128 // Suppress painting if nothing is dirty. This has to be done after updating
1129 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:241130 if (!paint_aggregator_.HasPendingUpdate()) {
1131 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]38ce4e7b2013-02-23 06:17:371132 InstrumentDidCancelFrame();
[email protected]5f8b1022011-01-21 23:34:501133 return;
[email protected]65225772011-05-12 21:10:241134 }
[email protected]5f8b1022011-01-21 23:34:501135
[email protected]479b0172012-10-29 19:27:091136 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:361137 !is_threaded_compositing_enabled_ &&
[email protected]479b0172012-10-29 19:27:091138 ForceCompositingModeEnabled()) {
1139 webwidget_->enterForceCompositingMode(true);
1140 }
1141
[email protected]872ae5b2011-05-26 20:20:501142 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:561143 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:041144 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:561145 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
1146 delay,
1147 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411148 base::TimeDelta::FromMilliseconds(120),
1149 60);
[email protected]d0be63772011-12-20 23:18:041150 } else {
[email protected]0fb93f52011-05-18 23:13:561151 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
1152 delay,
1153 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411154 base::TimeDelta::FromMilliseconds(120),
1155 60);
[email protected]d0be63772011-12-20 23:18:041156 }
[email protected]872ae5b2011-05-26 20:20:501157
1158 // Calculate filtered time per frame:
1159 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
1160 filtered_time_per_frame_ =
1161 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:561162 }
1163 last_do_deferred_update_time_ = frame_begin_ticks;
1164
[email protected]fef5e3972012-08-07 03:59:471165 if (!is_accelerated_compositing_active_) {
[email protected]62049562013-03-24 00:39:011166 software_stats_.animation_frame_count++;
1167 software_stats_.screen_frame_count++;
[email protected]fef5e3972012-08-07 03:59:471168 }
1169
[email protected]552e6002009-11-19 05:24:571170 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:291171 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:301172 PaintAggregator::PendingUpdate update;
1173 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:291174
[email protected]53d3f302009-12-21 04:42:051175 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:181176 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:291177
[email protected]29ed96a2012-02-04 18:12:161178 // Notify derived classes that we're about to initiate a paint.
1179 WillInitiatePaint();
1180
[email protected]ca4847f2010-09-24 05:39:151181 // A plugin may be able to do an optimized paint. First check this, in which
1182 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:461183 // This optimization allows PPAPI plugins that declare themselves on top of
1184 // the page (like a traditional windowed plugin) to be able to animate (think
1185 // movie playing) without repeatedly re-painting the page underneath, or
1186 // copying the plugin backing store (since we can send the plugin's backing
1187 // store directly to the browser).
1188 //
1189 // This optimization only works when the entire invalid region is contained
1190 // within the plugin. There is a related optimization in PaintRect for the
1191 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:151192 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:151193 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201194 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:211195 DCHECK(!pending_update_params_.get());
1196 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551197 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211198 pending_update_params_->scroll_rect = update.scroll_rect;
1199 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211200 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1201 pending_update_params_->flags = next_paint_flags_;
1202 pending_update_params_->scroll_offset = GetScrollOffset();
1203 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091204 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211205 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091206 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211207
[email protected]ca4847f2010-09-24 05:39:151208 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561209 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151210 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201211 &optimized_copy_rect,
1212 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271213 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471214 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211215 pending_update_params_->bitmap = dib->id();
1216 pending_update_params_->bitmap_rect = optimized_copy_location;
1217 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201218 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561219 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461220 // Compute a buffer for painting and cache it.
[email protected]4889bd212013-02-11 22:23:101221
1222 bool fractional_scale = device_scale_factor_ -
1223 static_cast<int>(device_scale_factor_) != 0;
1224 if (fractional_scale) {
1225 // Damage might not be DIP aligned. Inflate damage to compensate.
1226 bounds.Inset(-1, -1);
1227 bounds.Intersect(gfx::Rect(size_));
1228 }
1229
1230 gfx::Rect pixel_bounds = gfx::ToEnclosingRect(
[email protected]ce112fe2012-10-29 22:52:181231 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]4889bd212013-02-11 22:23:101232
[email protected]ca4847f2010-09-24 05:39:151233 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351234 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591235 pixel_bounds));
[email protected]59383c782013-04-17 16:43:271236 if (!canvas) {
[email protected]f98d7e3c2010-09-13 22:30:461237 NOTREACHED();
1238 return;
1239 }
[email protected]cef3362f2009-12-21 17:48:451240
[email protected]f98d7e3c2010-09-13 22:30:461241 // We may get back a smaller canvas than we asked for.
1242 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591243 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1244 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1245 pixel_bounds.set_width(canvas->getDevice()->width());
1246 pixel_bounds.set_height(canvas->getDevice()->height());
1247 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1248 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051249
[email protected]f98d7e3c2010-09-13 22:30:461250 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1251
[email protected]aa4117f2011-12-09 22:19:211252 pending_update_params_->bitmap = current_paint_buf_->id();
1253 pending_update_params_->bitmap_rect = bounds;
1254
1255 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461256 // The scroll damage is just another rectangle to paint and copy.
1257 copy_rects.swap(update.paint_rects);
1258 if (!scroll_damage.IsEmpty())
1259 copy_rects.push_back(scroll_damage);
1260
[email protected]4889bd212013-02-11 22:23:101261 for (size_t i = 0; i < copy_rects.size(); ++i) {
1262 gfx::Rect rect = copy_rects[i];
1263 if (fractional_scale) {
1264 // Damage might not be DPI aligned. Inflate rect to compensate.
1265 rect.Inset(-1, -1);
1266 }
1267 PaintRect(rect, pixel_bounds.origin(), canvas.get());
1268 }
[email protected]60a50072012-01-11 02:05:351269
1270 // Software FPS tick for performance tests. The accelerated path traces the
1271 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1272 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421273 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW",
1274 TRACE_EVENT_SCOPE_THREAD);
[email protected]f98d7e3c2010-09-13 22:30:461275 } else { // Accelerated compositing path
1276 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211277 // If painting is done via the gpu process then we don't set any damage
1278 // rects to save the browser process from doing unecessary work.
1279 pending_update_params_->bitmap_rect = bounds;
1280 pending_update_params_->scroll_rect = gfx::Rect();
1281 // We don't need an ack, because we're not sharing a DIB with the browser.
1282 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1283 // with the browser for the GPU surface.
1284 pending_update_params_->needs_ack = false;
[email protected]f0c2a242013-03-15 19:34:521285 Composite(frame_begin_ticks);
[email protected]f98d7e3c2010-09-13 22:30:461286 }
1287
[email protected]936c6f52011-12-13 01:35:261288 // If we're holding a pending input event ACK, send the ACK before sending the
1289 // UpdateReply message so we can receive another input event before the
1290 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1291 // the UpdateRect IPC message handler.
[email protected]59383c782013-04-17 16:43:271292 if (pending_input_event_ack_)
[email protected]936c6f52011-12-13 01:35:261293 Send(pending_input_event_ack_.release());
1294
[email protected]ab543072013-01-25 04:38:151295 // If Composite() called SwapBuffers, pending_update_params_ will be reset (in
[email protected]aa4117f2011-12-09 22:19:211296 // OnSwapBuffersPosted), meaning a message has been added to the
1297 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1298 // the message now.
[email protected]59383c782013-04-17 16:43:271299 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:211300 // sending an ack to browser process that the paint is complete...
1301 update_reply_pending_ = pending_update_params_->needs_ack;
1302 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1303 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341304 }
[email protected]53d3f302009-12-21 04:42:051305
[email protected]29ed96a2012-02-04 18:12:161306 // If we're software rendering then we're done initiating the paint.
1307 if (!is_accelerated_compositing_active_)
1308 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291309}
1310
[email protected]f0c2a242013-03-15 19:34:521311void RenderWidget::Composite(base::TimeTicks frame_begin_time) {
[email protected]ab543072013-01-25 04:38:151312 DCHECK(is_accelerated_compositing_active_);
[email protected]ba91a792013-02-06 09:48:281313 if (compositor_) // TODO(jamesr): Figure out how this can be null.
[email protected]f0c2a242013-03-15 19:34:521314 compositor_->Composite(frame_begin_time);
[email protected]ab543072013-01-25 04:38:151315}
1316
initial.commit09911bf2008-07-26 23:55:291317///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461318// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291319
[email protected]4873c7d2009-07-16 06:36:281320void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]479b0172012-10-29 19:27:091321 TRACE_EVENT2("renderer", "RenderWidget::didInvalidateRect",
1322 "width", rect.width, "height", rect.height);
[email protected]552e6002009-11-19 05:24:571323 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481324 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181325 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571326 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291327 return;
1328
[email protected]552e6002009-11-19 05:24:571329 paint_aggregator_.InvalidateRect(damaged_rect);
1330
1331 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241332 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571333 return;
1334 if (!paint_aggregator_.HasPendingUpdate())
1335 return;
[email protected]aa4117f2011-12-09 22:19:211336 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241337 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1338 return;
1339
1340 // When GPU rendering, combine pending animations and invalidations into
1341 // a single update.
[email protected]816edc62012-03-17 01:27:221342 if (is_accelerated_compositing_active_ &&
1343 animation_update_pending_ &&
1344 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571345 return;
1346
1347 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291348 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1349 // on the call stack.
1350 // 2) Allows us to collect more damage rects before painting to help coalesce
1351 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241352 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111353 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211354 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291355}
1356
[email protected]990278ff2012-11-13 02:12:551357void RenderWidget::didScrollRect(int dx, int dy,
1358 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461359 // Drop scrolls on the floor when we are in compositing mode.
1360 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561361 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461362 return;
1363
[email protected]552e6002009-11-19 05:24:571364 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481365 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181366 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571367 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291368 return;
1369
[email protected]990278ff2012-11-13 02:12:551370 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571371
1372 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241373 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571374 return;
1375 if (!paint_aggregator_.HasPendingUpdate())
1376 return;
[email protected]aa4117f2011-12-09 22:19:211377 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241378 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1379 return;
1380
1381 // When GPU rendering, combine pending animations and invalidations into
1382 // a single update.
[email protected]816edc62012-03-17 01:27:221383 if (is_accelerated_compositing_active_ &&
1384 animation_update_pending_ &&
1385 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571386 return;
1387
1388 // Perform updating asynchronously. This serves two purposes:
1389 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1390 // on the call stack.
1391 // 2) Allows us to collect more damage rects before painting to help coalesce
1392 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241393 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111394 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211395 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291396}
1397
[email protected]244ac1892011-12-02 17:04:471398void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091399 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]8be1c582013-03-06 00:55:031400 if (RenderThreadImpl::current()->short_circuit_size_updates()) {
1401 setWindowRect(WebRect(rootWindowRect().x,
1402 rootWindowRect().y,
1403 new_size.width,
1404 new_size.height));
1405 } else {
[email protected]20fbfc22013-05-08 20:50:581406 size_ = new_size;
1407
1408 // If we don't clear PaintAggregator after changing autoResize state, then
1409 // we might end up in a situation where bitmap_rect is larger than the
1410 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1411 // with invalid damage rects.
1412 paint_aggregator_.ClearPendingUpdate();
[email protected]8be1c582013-03-06 00:55:031413 }
[email protected]20fbfc22013-05-08 20:50:581414
1415 if (auto_resize_mode_)
1416 AutoResizeCompositor();
1417
1418 if (!RenderThreadImpl::current()->short_circuit_size_updates())
1419 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091420 }
[email protected]244ac1892011-12-02 17:04:471421}
1422
[email protected]3a1c8a8032013-03-18 22:35:321423void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051424 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1425 device_scale_factor_));
1426 if (compositor_)
1427 compositor_->setViewportSize(size_, physical_backing_size_);
1428}
1429
[email protected]91acd1c2012-03-14 08:32:391430void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221431 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1432
[email protected]c63b4d42012-04-26 01:01:071433#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211434 if (!is_accelerated_compositing_active_) {
1435 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1436 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1437 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1438 // going to switch to accelerated compositing, the GPU process may need
1439 // round-trips to the browser's UI thread before finishing the frame,
1440 // causing deadlocks if we delay the UpdateRect until we receive the
1441 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071442 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1443 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211444 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1445 }
[email protected]c63b4d42012-04-26 01:01:071446#endif
[email protected]aa4117f2011-12-09 22:19:211447
[email protected]ea162f92011-10-04 23:08:221448 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421449 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241450 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221451}
1452
1453void RenderWidget::didDeactivateCompositor() {
1454 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1455
1456 is_accelerated_compositing_active_ = false;
1457 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1458 routing_id_, is_accelerated_compositing_active_));
1459
[email protected]ea162f92011-10-04 23:08:221460 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241461 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091462
1463 // In single-threaded mode, we exit force compositing mode and re-enter in
1464 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1465 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1466 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361467 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091468 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561469}
1470
[email protected]e195e582013-03-08 01:32:591471void RenderWidget::initializeLayerTreeView() {
1472 compositor_ = RenderWidgetCompositor::Create(this);
1473 if (!compositor_)
1474 return;
1475
1476 compositor_->setViewportSize(size_, physical_backing_size_);
1477 if (init_complete_)
1478 compositor_->setSurfaceReady();
1479}
1480
[email protected]8926c602013-01-23 05:32:061481WebKit::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281482 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061483}
1484
[email protected]9ed83fe2013-02-27 01:52:281485void RenderWidget::suppressCompositorScheduling(bool enable) {
1486 if (compositor_)
1487 compositor_->SetSuppressScheduleComposite(enable);
1488}
1489
[email protected]9cd43a62012-03-26 08:03:561490void RenderWidget::willBeginCompositorFrame() {
1491 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371492
[email protected]ea5f70a2013-03-07 12:30:361493 DCHECK(RenderThreadImpl::current()->compositor_message_loop_proxy());
[email protected]abe8b3a2012-03-28 21:19:371494
1495 // The following two can result in further layout and possibly
1496 // enable GPU acceleration so they need to be called before any painting
1497 // is done.
[email protected]2d354272013-01-14 00:59:061498 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]abe8b3a2012-03-28 21:19:371499 UpdateSelectionBounds();
1500
[email protected]9cd43a62012-03-26 08:03:561501 WillInitiatePaint();
1502}
1503
[email protected]3391a0772012-03-28 00:32:071504void RenderWidget::didBecomeReadyForAdditionalInput() {
1505 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]59383c782013-04-17 16:43:271506 if (pending_input_event_ack_)
[email protected]3391a0772012-03-28 00:32:071507 Send(pending_input_event_ack_.release());
1508}
1509
[email protected]6fceb912013-02-15 06:24:151510void RenderWidget::DidCommitCompositorFrame() {
1511}
1512
[email protected]58264a32011-11-17 23:36:151513void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501514 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351515 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1516 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421517 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU",
1518 TRACE_EVENT_SCOPE_THREAD);
[email protected]29ed96a2012-02-04 18:12:161519 // Notify subclasses that we initiated the paint operation.
1520 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151521}
1522
1523void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181524 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1525
1526 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561527 DidFlushPaint();
1528
[email protected]aa4117f2011-12-09 22:19:211529 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151530 return;
1531
[email protected]ea3ee0a2012-05-15 03:43:091532 if (!next_paint_flags_ &&
1533 !need_update_rect_for_auto_resize_ &&
1534 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151535 return;
[email protected]ea3ee0a2012-05-15 03:43:091536 }
[email protected]58264a32011-11-17 23:36:151537
1538 ViewHostMsg_UpdateRect_Params params;
1539 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151540 params.plugin_window_moves.swap(plugin_window_moves_);
1541 params.flags = next_paint_flags_;
1542 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121543 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091544 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151545
1546 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1547 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091548 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151549}
1550
[email protected]f98d7e3c2010-09-13 22:30:461551void RenderWidget::scheduleComposite() {
[email protected]479b0172012-10-29 19:27:091552 TRACE_EVENT0("gpu", "RenderWidget::scheduleComposite");
[email protected]ea5f70a2013-03-07 12:30:361553 if (RenderThreadImpl::current()->compositor_message_loop_proxy() &&
[email protected]ba91a792013-02-06 09:48:281554 compositor_) {
1555 compositor_->setNeedsRedraw();
[email protected]d0be63772011-12-20 23:18:041556 } else {
[email protected]c3d45532011-10-07 19:20:401557 // TODO(nduca): replace with something a little less hacky. The reason this
1558 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1559 // contains a lot of host-renderer synchronization logic that is still
1560 // important for the accelerated compositing case. The option of simply
1561 // duplicating all that code is less desirable than "faking out" the
1562 // invalidation path using a magical damage rect.
1563 didInvalidateRect(WebRect(0, 0, 1, 1));
1564 }
[email protected]f98d7e3c2010-09-13 22:30:461565}
1566
[email protected]5f8b1022011-01-21 23:34:501567void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201568 if (animation_update_pending_)
1569 return;
1570
[email protected]921244e42011-07-20 16:36:301571 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201572 animation_update_pending_ = true;
1573 if (!animation_timer_.IsRunning()) {
1574 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1575 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211576 }
[email protected]5f8b1022011-01-21 23:34:501577}
1578
[email protected]4873c7d2009-07-16 06:36:281579void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301580 // TODO(darin): Eliminate this temporary.
1581 WebCursor cursor(cursor_info);
1582
initial.commit09911bf2008-07-26 23:55:291583 // Only send a SetCursor message if we need to make a change.
1584 if (!current_cursor_.IsEqual(cursor)) {
1585 current_cursor_ = cursor;
1586 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1587 }
1588}
1589
1590// We are supposed to get a single call to Show for a newly created RenderWidget
1591// that was created via RenderWidget::CreateWebView. So, we wait until this
1592// point to dispatch the ShowWidget message.
1593//
1594// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281595// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291596//
[email protected]4873c7d2009-07-16 06:36:281597void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291598 DCHECK(!did_show_) << "received extraneous Show call";
1599 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1600 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1601
[email protected]8de12d942010-11-17 20:42:441602 if (did_show_)
1603 return;
1604
1605 did_show_ = true;
1606 // NOTE: initial_pos_ may still have its default values at this point, but
1607 // that's okay. It'll be ignored if as_popup is false, or the browser
1608 // process will impose a default position otherwise.
1609 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1610 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291611}
1612
[email protected]4873c7d2009-07-16 06:36:281613void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291614}
1615
[email protected]4873c7d2009-07-16 06:36:281616void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291617}
1618
[email protected]2533ce12009-05-09 00:02:241619void RenderWidget::DoDeferredClose() {
1620 Send(new ViewHostMsg_Close(routing_id_));
1621}
1622
[email protected]4873c7d2009-07-16 06:36:281623void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321624 if (is_swapped_out_) {
1625 // This widget is currently swapped out, and the active widget is in a
1626 // different process. Have the browser route the close request to the
1627 // active widget instead, so that the correct unload handlers are run.
1628 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1629 return;
1630 }
1631
initial.commit09911bf2008-07-26 23:55:291632 // If a page calls window.close() twice, we'll end up here twice, but that's
1633 // OK. It is safe to send multiple Close messages.
1634
[email protected]2533ce12009-05-09 00:02:241635 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1636 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1637 // could be closed before the JS finishes executing. So instead, post a
1638 // message back to the message loop, which won't run until the JS is
1639 // complete, and then the Close message can be sent.
[email protected]dd32b1272013-05-04 14:17:111640 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211641 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291642}
1643
1644void RenderWidget::Close() {
1645 if (webwidget_) {
[email protected]8926c602013-01-23 05:32:061646 webwidget_->willCloseLayerTreeView();
[email protected]ba91a792013-02-06 09:48:281647 compositor_.reset();
[email protected]4873c7d2009-07-16 06:36:281648 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291649 webwidget_ = NULL;
1650 }
1651}
1652
[email protected]4873c7d2009-07-16 06:36:281653WebRect RenderWidget::windowRect() {
1654 if (pending_window_rect_count_)
1655 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241656
[email protected]80ad8622012-11-07 16:33:031657 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291658}
1659
[email protected]8a9d6ca32011-06-06 20:11:301660void RenderWidget::setToolTipText(const WebKit::WebString& text,
1661 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541662 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301663}
1664
[email protected]4873c7d2009-07-16 06:36:281665void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291666 if (did_show_) {
[email protected]8be1c582013-03-06 00:55:031667 if (!RenderThreadImpl::current()->short_circuit_size_updates()) {
1668 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1669 SetPendingWindowRect(pos);
1670 } else {
1671 WebSize new_size(pos.width, pos.height);
[email protected]d9083762013-03-24 01:36:401672 Resize(new_size, new_size, overdraw_bottom_height_,
1673 WebRect(), is_fullscreen_, NO_RESIZE_ACK);
[email protected]8be1c582013-03-06 00:55:031674 view_screen_rect_ = pos;
1675 window_screen_rect_ = pos;
1676 }
initial.commit09911bf2008-07-26 23:55:291677 } else {
1678 initial_pos_ = pos;
1679 }
1680}
1681
[email protected]2533ce12009-05-09 00:02:241682void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1683 pending_window_rect_ = rect;
1684 pending_window_rect_count_++;
1685}
1686
[email protected]4873c7d2009-07-16 06:36:281687WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241688 if (pending_window_rect_count_) {
1689 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1690 // the RootWindowRect is probably going to return wrong results since the
1691 // browser may not have processed the Move yet. There isn't really anything
1692 // good to do in this case, and it shouldn't happen - since this size is
1693 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281694 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241695 }
1696
[email protected]80ad8622012-11-07 16:33:031697 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371698}
1699
[email protected]4873c7d2009-07-16 06:36:281700WebRect RenderWidget::windowResizerRect() {
1701 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191702}
1703
[email protected]fa7b1dc2010-06-23 17:53:041704void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031705 // To prevent this renderer process from sending unnecessary IPC messages to
1706 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041707 // only during the input method attached to the browser process is active.
1708 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291709}
1710
[email protected]58b48a0d2012-06-13 07:01:351711void RenderWidget::UpdateCompositionInfo(
1712 const ui::Range& range,
1713 const std::vector<gfx::Rect>& character_bounds) {
1714 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1715 return;
1716 composition_character_bounds_ = character_bounds;
1717 composition_range_ = range;
1718 Send(new ViewHostMsg_ImeCompositionRangeChanged(
1719 routing_id(), composition_range_, composition_character_bounds_));
1720}
1721
[email protected]fa7b1dc2010-06-23 17:53:041722void RenderWidget::OnImeSetComposition(
1723 const string16& text,
1724 const std::vector<WebCompositionUnderline>& underlines,
1725 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281726 if (!webwidget_)
1727 return;
[email protected]e8f775f2013-02-14 21:00:501728 DCHECK(!handling_ime_event_);
1729 handling_ime_event_ = true;
[email protected]d4cff272011-05-02 15:46:011730 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041731 text, WebVector<WebCompositionUnderline>(underlines),
1732 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011733 // Setting the IME composition was successful. Send the new composition
1734 // range to the browser.
1735 ui::Range range(ui::Range::InvalidRange());
1736 size_t location, length;
1737 if (webwidget_->compositionRange(&location, &length)) {
1738 range.set_start(location);
1739 range.set_end(location + length);
1740 }
1741 // The IME was cancelled via the Esc key, so just send back the caret.
1742 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1743 range.set_start(location);
1744 range.set_end(location + length);
1745 }
[email protected]58b48a0d2012-06-13 07:01:351746 std::vector<gfx::Rect> character_bounds;
1747 GetCompositionCharacterBounds(&character_bounds);
1748 UpdateCompositionInfo(range, character_bounds);
[email protected]d4cff272011-05-02 15:46:011749 } else {
[email protected]fa7b1dc2010-06-23 17:53:041750 // If we failed to set the composition text, then we need to let the browser
1751 // process to cancel the input method's ongoing composition session, to make
1752 // sure we are in a consistent state.
1753 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011754
1755 // Send an updated IME range with just the caret range.
1756 ui::Range range(ui::Range::InvalidRange());
1757 size_t location, length;
1758 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1759 range.set_start(location);
1760 range.set_end(location + length);
1761 }
[email protected]58b48a0d2012-06-13 07:01:351762 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]7f00efa2010-04-15 05:01:261763 }
[email protected]e8f775f2013-02-14 21:00:501764 handling_ime_event_ = false;
1765 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]fa7b1dc2010-06-23 17:53:041766}
1767
[email protected]4de6d1692011-10-12 08:45:441768void RenderWidget::OnImeConfirmComposition(
1769 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041770 if (!webwidget_)
1771 return;
[email protected]e8f775f2013-02-14 21:00:501772 DCHECK(!handling_ime_event_);
1773 handling_ime_event_ = true;
[email protected]d0be63772011-12-20 23:18:041774 handling_input_event_ = true;
1775 webwidget_->confirmComposition(text);
1776 handling_input_event_ = false;
1777
[email protected]d4cff272011-05-02 15:46:011778 // Send an updated IME range with just the caret range.
1779 ui::Range range(ui::Range::InvalidRange());
1780 size_t location, length;
1781 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1782 range.set_start(location);
1783 range.set_end(location + length);
1784 }
[email protected]58b48a0d2012-06-13 07:01:351785 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]e8f775f2013-02-14 21:00:501786 handling_ime_event_ = false;
1787 UpdateTextInputState(DO_NOT_SHOW_IME);
initial.commit09911bf2008-07-26 23:55:291788}
1789
[email protected]948f7ab72010-05-28 23:48:081790// This message causes the renderer to render an image of the
1791// desired_size, regardless of whether the tab is hidden or not.
[email protected]3d9ec5052013-01-02 22:05:251792void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle,
1793 int tag,
1794 const gfx::Size& page_size,
1795 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001796 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1797 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251798 // Close our unused handle.
1799#if defined(OS_WIN)
1800 ::CloseHandle(dib_handle);
1801#elif defined(OS_MACOSX)
1802 base::SharedMemory::CloseHandle(dib_handle);
1803#endif
1804 }
[email protected]d65adb12010-04-28 17:26:491805 return;
[email protected]45c6aad32010-11-11 04:46:251806 }
[email protected]d65adb12010-04-28 17:26:491807
[email protected]948f7ab72010-05-28 23:48:081808 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491809 // If one of these is empty, then we just return the dib we were
1810 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091811 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491812 return;
1813 }
1814
1815 // Map the given DIB ID into this process, and unmap it at the end
1816 // of this function.
[email protected]45c6aad32010-11-11 04:46:251817 scoped_ptr<TransportDIB> paint_at_size_buffer(
1818 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301819
[email protected]4b01b962012-10-09 23:17:351820 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281821 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:351822 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281823 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:511824 gfx::Size canvas_size = page_size_in_pixel;
1825 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:491826 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:511827 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:491828 static_cast<float>(canvas_size.height());
1829
[email protected]ee8d6fd2010-05-26 17:05:481830 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491831 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1832 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481833 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491834
[email protected]36808ad2010-10-20 19:18:301835 scoped_ptr<skia::PlatformCanvas> canvas(
1836 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1837 canvas_size.height()));
[email protected]59383c782013-04-17 16:43:271838 if (!canvas) {
[email protected]36808ad2010-10-20 19:18:301839 NOTREACHED();
1840 return;
1841 }
1842
[email protected]d65adb12010-04-28 17:26:491843 // Reset bounds to what we actually received, but they should be the
1844 // same.
1845 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1846 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1847 bounds.set_width(canvas->getDevice()->width());
1848 bounds.set_height(canvas->getDevice()->height());
1849
1850 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081851 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491852 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1853
[email protected]948f7ab72010-05-28 23:48:081854 // Have to make sure we're laid out at the right size before
1855 // rendering.
1856 gfx::Size old_size = webwidget_->size();
1857 webwidget_->resize(page_size);
1858 webwidget_->layout();
1859
[email protected]d65adb12010-04-28 17:26:491860 // Paint the entire thing (using original bounds, not scaled bounds).
1861 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1862 canvas->restore();
1863
[email protected]948f7ab72010-05-28 23:48:081864 // Return the widget to its previous size.
1865 webwidget_->resize(old_size);
1866
[email protected]c88c9442010-07-19 18:55:091867 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491868}
1869
[email protected]51a49502013-03-23 01:50:191870void RenderWidget::OnSnapshot(const gfx::Rect& src_subrect) {
1871 SkBitmap snapshot;
1872
1873 if (OnSnapshotHelper(src_subrect, &snapshot)) {
1874 Send(new ViewHostMsg_Snapshot(routing_id(), true, snapshot));
1875 } else {
1876 Send(new ViewHostMsg_Snapshot(routing_id(), false, SkBitmap()));
1877 }
1878}
1879
1880bool RenderWidget::OnSnapshotHelper(const gfx::Rect& src_subrect,
1881 SkBitmap* snapshot) {
1882 base::TimeTicks beginning_time = base::TimeTicks::Now();
1883
1884 if (!webwidget_ || src_subrect.IsEmpty())
1885 return false;
1886
1887 gfx::Rect viewport_size = gfx::IntersectRects(
1888 src_subrect, gfx::Rect(physical_backing_size_));
1889
1890 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(
1891 skia::CreatePlatformCanvas(viewport_size.width(),
1892 viewport_size.height(),
1893 true,
1894 NULL,
1895 skia::RETURN_NULL_ON_FAILURE));
[email protected]59383c782013-04-17 16:43:271896 if (!canvas)
[email protected]51a49502013-03-23 01:50:191897 return false;
1898
1899 canvas->save();
1900 webwidget_->layout();
1901
1902 PaintRect(viewport_size, viewport_size.origin(), canvas.get());
1903 canvas->restore();
1904
1905 const SkBitmap& bitmap = skia::GetTopDevice(*canvas)->accessBitmap(false);
1906 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1907 return false;
1908
1909 UMA_HISTOGRAM_TIMES("Renderer4.Snapshot",
1910 base::TimeTicks::Now() - beginning_time);
1911 return true;
1912}
1913
[email protected]0bc1f572013-04-17 01:46:311914void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121915 // During shutdown we can just ignore this message.
1916 if (!webwidget_)
1917 return;
1918
[email protected]0bc1f572013-04-17 01:46:311919 // Even if the browser provides an empty damage rect, it's still expecting to
1920 // receive a repaint ack so just damage the entire widget bounds.
1921 if (size_to_paint.IsEmpty()) {
1922 size_to_paint = size_;
1923 }
1924
[email protected]ec7dc112008-08-06 05:30:121925 set_next_paint_is_repaint_ack();
[email protected]0bc1f572013-04-17 01:46:311926 if (is_accelerated_compositing_active_ && compositor_) {
1927 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]f98d7e3c2010-09-13 22:30:461928 } else {
1929 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1930 didInvalidateRect(repaint_rect);
1931 }
[email protected]ec7dc112008-08-06 05:30:121932}
1933
[email protected]4a9dba42013-04-29 18:24:221934void RenderWidget::OnSmoothScrollCompleted() {
1935 pending_smooth_scroll_gesture_.Run();
[email protected]0e241b4b2012-08-18 09:06:271936}
1937
[email protected]4873c7d2009-07-16 06:36:281938void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111939 if (!webwidget_)
1940 return;
[email protected]4873c7d2009-07-16 06:36:281941 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111942}
1943
[email protected]6131a642012-06-15 23:26:531944void RenderWidget::OnScreenInfoChanged(
1945 const WebKit::WebScreenInfo& screen_info) {
1946 screen_info_ = screen_info;
[email protected]468ac582012-11-20 00:53:191947 SetDeviceScaleFactor(screen_info.deviceScaleFactor);
[email protected]6131a642012-06-15 23:26:531948}
1949
[email protected]80ad8622012-11-07 16:33:031950void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1951 const gfx::Rect& window_screen_rect) {
1952 view_screen_rect_ = view_screen_rect;
1953 window_screen_rect_ = window_screen_rect;
1954 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1955}
1956
[email protected]105dffb42013-02-20 03:46:211957#if defined(OS_ANDROID)
1958void RenderWidget::OnImeBatchStateChanged(bool is_begin) {
1959 Send(new ViewHostMsg_ImeBatchStateChanged_ACK(routing_id(), is_begin));
1960}
[email protected]2384b6c2013-02-28 23:58:511961
1962void RenderWidget::OnShowImeIfNeeded() {
1963 UpdateTextInputState(SHOW_IME_IF_NEEDED);
1964}
[email protected]105dffb42013-02-20 03:46:211965#endif
1966
[email protected]468ac582012-11-20 00:53:191967void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1968 if (device_scale_factor_ == device_scale_factor)
1969 return;
1970
1971 device_scale_factor_ = device_scale_factor;
1972
1973 if (!is_accelerated_compositing_active_) {
1974 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
1975 } else {
1976 scheduleComposite();
1977 }
1978}
1979
[email protected]719b36f2010-12-22 20:36:461980webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151981 const gfx::Rect& paint_bounds,
1982 TransportDIB** dib,
1983 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:201984 gfx::Rect* clip,
1985 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:461986 // Bare RenderWidgets don't support optimized plugin painting.
1987 return NULL;
[email protected]ca4847f2010-09-24 05:39:151988}
1989
[email protected]ceb36f7d2012-10-31 18:33:241990gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521991 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241992 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521993}
1994
[email protected]bee16aab2009-08-26 15:55:031995void RenderWidget::SetHidden(bool hidden) {
1996 if (is_hidden_ == hidden)
1997 return;
1998
1999 // The status has changed. Tell the RenderThread about it.
2000 is_hidden_ = hidden;
2001 if (is_hidden_)
[email protected]380244092011-10-07 17:26:272002 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:032003 else
[email protected]380244092011-10-07 17:26:272004 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:032005}
2006
[email protected]2b624c562011-10-27 22:58:262007void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262008 if (!webwidget_)
2009 return;
2010
2011 if (is_fullscreen_) {
2012 webwidget_->willExitFullScreen();
2013 } else {
2014 webwidget_->willEnterFullScreen();
2015 }
[email protected]2b624c562011-10-27 22:58:262016}
2017
2018void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262019 if (!webwidget_)
2020 return;
2021
2022 if (is_fullscreen_) {
2023 webwidget_->didEnterFullScreen();
2024 } else {
2025 webwidget_->didExitFullScreen();
2026 }
[email protected]2b624c562011-10-27 22:58:262027}
2028
[email protected]699ab0d2009-04-23 23:19:142029void RenderWidget::SetBackground(const SkBitmap& background) {
2030 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:462031
[email protected]699ab0d2009-04-23 23:19:142032 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:282033 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:142034}
2035
[email protected]674741932009-02-04 23:44:462036bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:052037 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462038}
2039
2040bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:052041 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462042}
2043
2044void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:052045 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462046}
2047
2048void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:052049 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:462050}
2051
2052void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:052053 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462054}
2055
[email protected]b18583c2012-12-18 06:55:272056static bool IsDateTimeInput(ui::TextInputType type) {
2057 return type == ui::TEXT_INPUT_TYPE_DATE ||
2058 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
2059 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
2060 type == ui::TEXT_INPUT_TYPE_MONTH ||
2061 type == ui::TEXT_INPUT_TYPE_TIME ||
2062 type == ui::TEXT_INPUT_TYPE_WEEK;
2063}
2064
[email protected]3306f262012-09-21 19:20:422065void RenderWidget::UpdateTextInputState(ShowIme show_ime) {
[email protected]e8f775f2013-02-14 21:00:502066 if (handling_ime_event_)
2067 return;
[email protected]3306f262012-09-21 19:20:422068 bool show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
2069 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:292070 return;
[email protected]ad26ef42011-06-17 07:59:452071 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:272072 if (IsDateTimeInput(new_type))
2073 return; // Not considered as a text input field in WebKit/Chromium.
2074
[email protected]5b739cb2012-08-21 20:35:212075 WebKit::WebTextInputInfo new_info;
2076 if (webwidget_)
2077 new_info = webwidget_->textInputInfo();
2078
[email protected]ad26ef42011-06-17 07:59:452079 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:212080
[email protected]3306f262012-09-21 19:20:422081 // Only sends text input params if they are changed or if the ime should be
2082 // shown.
2083 if (show_ime_if_needed || (text_input_type_ != new_type
2084 || text_input_info_ != new_info
2085 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:212086 ViewHostMsg_TextInputState_Params p;
2087 p.type = new_type;
2088 p.value = new_info.value.utf8();
2089 p.selection_start = new_info.selectionStart;
2090 p.selection_end = new_info.selectionEnd;
2091 p.composition_start = new_info.compositionStart;
2092 p.composition_end = new_info.compositionEnd;
2093 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:422094 p.show_ime_if_needed = show_ime_if_needed;
[email protected]5b739cb2012-08-21 20:35:212095 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
2096
2097 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:042098 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:452099 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:292100 }
initial.commit09911bf2008-07-26 23:55:292101}
2102
[email protected]7c8873e2013-02-05 08:03:012103void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2104 WebRect focus_webrect;
2105 WebRect anchor_webrect;
2106 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
2107 *focus = focus_webrect;
2108 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322109}
2110
[email protected]e99ef6f2011-10-16 01:13:002111void RenderWidget::UpdateSelectionBounds() {
2112 if (!webwidget_)
2113 return;
2114
[email protected]7c8873e2013-02-05 08:03:012115 ViewHostMsg_SelectionBounds_Params params;
2116 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2117 if (selection_anchor_rect_ != params.anchor_rect ||
2118 selection_focus_rect_ != params.focus_rect) {
2119 selection_anchor_rect_ = params.anchor_rect;
2120 selection_focus_rect_ = params.focus_rect;
2121 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
[email protected]129b7382013-02-12 02:14:292122 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
[email protected]7c8873e2013-02-05 08:03:012123 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
[email protected]58b48a0d2012-06-13 07:01:352124 }
[email protected]e99ef6f2011-10-16 01:13:002125
[email protected]58b48a0d2012-06-13 07:01:352126 std::vector<gfx::Rect> character_bounds;
2127 GetCompositionCharacterBounds(&character_bounds);
2128 UpdateCompositionInfo(composition_range_, character_bounds);
2129}
2130
2131bool RenderWidget::ShouldUpdateCompositionInfo(
2132 const ui::Range& range,
2133 const std::vector<gfx::Rect>& bounds) {
2134 if (composition_range_ != range)
2135 return true;
2136 if (bounds.size() != composition_character_bounds_.size())
2137 return true;
2138 for (size_t i = 0; i < bounds.size(); ++i) {
2139 if (bounds[i] != composition_character_bounds_[i])
2140 return true;
2141 }
2142 return false;
[email protected]e99ef6f2011-10-16 01:13:002143}
2144
[email protected]73bf95812011-10-12 11:38:322145// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:452146COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
2147 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
2148COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
2149 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
2150COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
2151 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:182152COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
2153 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
2154COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
2155 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
2156COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
2157 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
2158COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
2159 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
2160COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
2161 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:002162COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
2163 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
2164COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
2165 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
2166COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
2167 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
2168COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
2169 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
2170COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
2171 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
2172COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
2173 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:012174COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
2175 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
2176COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
2177 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]8b4992e2013-03-01 15:42:152178COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeField) == \
2179 int(ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:452180
[email protected]5b739cb2012-08-21 20:35:212181ui::TextInputType RenderWidget::WebKitToUiTextInputType(
2182 WebKit::WebTextInputType type) {
2183 // Check the type is in the range representable by ui::TextInputType.
2184 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
2185 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
2186 return static_cast<ui::TextInputType>(type);
2187}
2188
[email protected]ad26ef42011-06-17 07:59:452189ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272190 if (webwidget_)
2191 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452192 return ui::TEXT_INPUT_TYPE_NONE;
2193}
2194
[email protected]58b48a0d2012-06-13 07:01:352195void RenderWidget::GetCompositionCharacterBounds(
2196 std::vector<gfx::Rect>* bounds) {
2197 DCHECK(bounds);
2198 bounds->clear();
2199}
2200
[email protected]ad26ef42011-06-17 07:59:452201bool RenderWidget::CanComposeInline() {
2202 return true;
[email protected]56ea1a62011-05-30 07:05:572203}
2204
[email protected]4873c7d2009-07-16 06:36:282205WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042206 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282207}
2208
[email protected]f660d9c2012-06-06 18:31:212209float RenderWidget::deviceScaleFactor() {
2210 return device_scale_factor_;
2211}
2212
[email protected]fa7b1dc2010-06-23 17:53:042213void RenderWidget::resetInputMethod() {
2214 if (!input_method_is_active_)
2215 return;
2216
2217 // If the last text input type is not None, then we should finish any
2218 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452219 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042220 // If a composition text exists, then we need to let the browser process
2221 // to cancel the input method's ongoing composition session.
[email protected]fa7b1dc2010-06-23 17:53:042222 if (webwidget_->confirmComposition())
2223 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]fa7b1dc2010-06-23 17:53:042224 }
[email protected]d4cff272011-05-02 15:46:012225
2226 // Send an updated IME range with the current caret rect.
2227 ui::Range range(ui::Range::InvalidRange());
2228 size_t location, length;
2229 if (webwidget_->caretOrSelectionRange(&location, &length)) {
2230 range.set_start(location);
2231 range.set_end(location + length);
2232 }
[email protected]58b48a0d2012-06-13 07:01:352233
2234 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]fa7b1dc2010-06-23 17:53:042235}
2236
[email protected]c68c3e4e2013-01-24 00:36:562237void RenderWidget::didHandleGestureEvent(
2238 const WebGestureEvent& event,
2239 bool event_cancelled) {
2240#if defined(OS_ANDROID)
2241 if (event_cancelled)
2242 return;
2243 if (event.type == WebInputEvent::GestureTap ||
2244 event.type == WebInputEvent::GestureLongPress) {
2245 UpdateTextInputState(SHOW_IME_IF_NEEDED);
2246 }
2247#endif
2248}
2249
[email protected]f103ab72009-09-02 17:10:592250void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:502251 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292252 size_t i = 0;
2253 for (; i < plugin_window_moves_.size(); ++i) {
2254 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582255 if (move.rects_valid) {
2256 plugin_window_moves_[i] = move;
2257 } else {
2258 plugin_window_moves_[i].visible = move.visible;
2259 }
initial.commit09911bf2008-07-26 23:55:292260 break;
2261 }
2262 }
2263
2264 if (i == plugin_window_moves_.size())
2265 plugin_window_moves_.push_back(move);
2266}
[email protected]268654772009-08-06 23:02:042267
2268void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2269 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2270 i != plugin_window_moves_.end(); ++i) {
2271 if (i->window == window) {
2272 plugin_window_moves_.erase(i);
2273 break;
2274 }
2275 }
2276}
[email protected]67bfb83f2011-09-22 03:36:372277
[email protected]b63d58d2012-11-26 22:37:442278void RenderWidget::GetRenderingStats(
2279 WebKit::WebRenderingStatsImpl& stats) const {
[email protected]ba91a792013-02-06 09:48:282280 if (compositor_)
[email protected]635353c2013-03-06 09:11:202281 compositor_->GetRenderingStats(&stats.rendering_stats);
[email protected]b63d58d2012-11-26 22:37:442282
[email protected]62049562013-03-24 00:39:012283 stats.rendering_stats.animation_frame_count +=
2284 software_stats_.animation_frame_count;
2285 stats.rendering_stats.screen_frame_count +=
2286 software_stats_.screen_frame_count;
2287 stats.rendering_stats.total_paint_time +=
2288 software_stats_.total_paint_time;
2289 stats.rendering_stats.total_pixels_painted +=
2290 software_stats_.total_pixels_painted;
[email protected]fef5e3972012-08-07 03:59:472291}
2292
[email protected]e9ff79c2012-10-19 21:31:262293bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:522294 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
2295 if (!gpu_channel)
2296 return false;
2297
2298 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
2299}
2300
[email protected]24ed0432013-04-24 07:50:312301RenderWidgetCompositor* RenderWidget::compositor() const {
2302 return compositor_.get();
2303}
2304
[email protected]0c2ebef2013-04-03 12:14:102305void RenderWidget::BeginSmoothScroll(
[email protected]0e241b4b2012-08-18 09:06:272306 bool down,
[email protected]ebd8b562012-10-09 14:44:292307 const SmoothScrollCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:192308 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:292309 int mouse_event_x,
2310 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:272311 DCHECK(!callback.is_null());
[email protected]267909d2012-10-20 04:36:192312
2313 ViewHostMsg_BeginSmoothScroll_Params params;
2314 params.scroll_down = down;
2315 params.pixels_to_scroll = pixels_to_scroll;
2316 params.mouse_event_x = mouse_event_x;
2317 params.mouse_event_y = mouse_event_y;
2318
[email protected]4a9dba42013-04-29 18:24:222319 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, params));
2320 pending_smooth_scroll_gesture_ = callback;
[email protected]a39ca1652012-07-13 21:30:582321}
2322
[email protected]67bfb83f2011-09-22 03:36:372323bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
2324 return false;
2325}
[email protected]c3d45532011-10-07 19:20:402326
[email protected]41d86852012-11-07 12:23:242327bool RenderWidget::WillHandleGestureEvent(
2328 const WebKit::WebGestureEvent& event) {
2329 return false;
2330}
2331
[email protected]ce6689f2013-03-29 12:52:552332void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2333 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2334}
2335
[email protected]3d5c243b2012-11-30 00:26:012336bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2337 return true;
2338}
2339
[email protected]3ae68c52013-04-12 06:10:052340WebGraphicsContext3DCommandBufferImpl* RenderWidget::CreateGraphicsContext3D(
[email protected]92fd8c02013-03-29 08:54:152341 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
[email protected]ed7defa2013-03-12 21:29:592342 if (!webwidget_)
2343 return NULL;
[email protected]8f746982013-03-21 06:28:032344 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
2345 new WebGraphicsContext3DCommandBufferImpl(
2346 surface_id(),
2347 GetURLForGraphicsContext3D(),
2348 RenderThreadImpl::current(),
2349 weak_ptr_factory_.GetWeakPtr()));
[email protected]ed7defa2013-03-12 21:29:592350
[email protected]8f746982013-03-21 06:28:032351 if (!context->Initialize(
2352 attributes,
2353 false /* bind generates resources */,
2354 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
2355 return NULL;
2356 return context.release();
[email protected]ed7defa2013-03-12 21:29:592357}
2358
[email protected]e9ff79c2012-10-19 21:31:262359} // namespace content