blob: 074870e483d68a12cb7a51db7942deda43556382 [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]b63d58d2012-11-26 22:37:4456#include "webkit/compositor_bindings/web_rendering_stats_impl.h"
[email protected]8c89e7792009-08-19 21:18:3457#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5058#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4659#include "webkit/plugins/ppapi/ppapi_plugin_instance.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);
115 CASE_TYPE(GestureTapDown);
116 CASE_TYPE(GestureTapCancel);
117 CASE_TYPE(GestureDoubleTap);
118 CASE_TYPE(GestureTwoFingerTap);
119 CASE_TYPE(GestureLongPress);
120 CASE_TYPE(GestureLongTap);
121 CASE_TYPE(GesturePinchBegin);
122 CASE_TYPE(GesturePinchEnd);
123 CASE_TYPE(GesturePinchUpdate);
124 CASE_TYPE(TouchStart);
125 CASE_TYPE(TouchMove);
126 CASE_TYPE(TouchEnd);
127 CASE_TYPE(TouchCancel);
[email protected]3ec08ed2013-01-11 15:59:57128 default:
129 // Must include default to let WebKit::WebInputEvent add new event types
130 // before they're added here.
131 DLOG(WARNING) << "Unhandled WebInputEvent type in GetEventName.\n";
132 break;
[email protected]6a4d7f62013-01-07 21:32:13133 }
134#undef CASE_TYPE
[email protected]3ec08ed2013-01-11 15:59:57135 return "";
[email protected]6a4d7f62013-01-07 21:32:13136}
137}
[email protected]e9ff79c2012-10-19 21:31:26138namespace content {
[email protected]62cb33cae2009-03-27 23:30:22139
[email protected]6fd35b72012-03-01 19:46:41140RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]842f10652012-06-06 01:54:04141 const WebKit::WebScreenInfo& screen_info,
[email protected]14392a52012-05-02 20:28:44142 bool swapped_out)
initial.commit09911bf2008-07-26 23:55:29143 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56144 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:11145 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:29146 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30147 init_complete_(false),
[email protected]b4d08452010-10-05 17:34:35148 current_paint_buf_(NULL),
[email protected]d9083762013-03-24 01:36:40149 overdraw_bottom_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29150 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:06151 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:05152 update_reply_pending_(false),
[email protected]847a2582013-03-09 02:29:51153 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09154 need_update_rect_for_auto_resize_(false),
[email protected]65225772011-05-12 21:10:24155 using_asynchronous_swapbuffers_(false),
156 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:29157 did_show_(false),
initial.commit09911bf2008-07-26 23:55:29158 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:09159 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:29160 needs_repainting_on_restore_(false),
161 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49162 handling_input_event_(false),
[email protected]e8f775f2013-02-14 21:00:50163 handling_ime_event_(false),
[email protected]661eb9d2009-02-03 02:11:48164 closing_(false),
[email protected]14392a52012-05-02 20:28:44165 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04166 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45167 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
168 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12169 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48170 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12171 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50172 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21173 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07174 invalidation_task_posted_(false),
[email protected]842f10652012-06-06 01:54:04175 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52176 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]0e241b4b2012-08-18 09:06:27177 throttle_input_events_(true),
[email protected]ed7defa2013-03-12 21:29:59178 is_threaded_compositing_enabled_(false),
[email protected]69e797f2013-04-30 01:10:22179 weak_ptr_factory_(this) {
[email protected]8b3f0eb2012-05-03 19:15:05180 if (!swapped_out)
181 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27182 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18183 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
184 switches::kDisableGpuVsync);
[email protected]cb6430932012-10-31 00:53:36185 is_threaded_compositing_enabled_ =
186 CommandLine::ForCurrentProcess()->HasSwitch(
187 switches::kEnableThreadedCompositing);
initial.commit09911bf2008-07-26 23:55:29188}
189
190RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11191 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21192 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35193 if (current_paint_buf_) {
194 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
195 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29196 }
[email protected]992db4c2011-05-12 15:37:15197 // If we are swapped out, we have released already.
198 if (!is_swapped_out_)
199 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29200}
201
[email protected]484955942010-08-19 16:13:18202// static
[email protected]8085dbc82008-09-26 22:53:44203RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:04204 WebKit::WebPopupType popup_type,
205 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29206 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41207 scoped_refptr<RenderWidget> widget(
[email protected]842f10652012-06-06 01:54:04208 new RenderWidget(popup_type, screen_info, false));
[email protected]a635f942012-12-07 10:34:29209 if (widget->Init(opener_id)) { // adds reference on success.
210 return widget;
211 }
212 return NULL;
initial.commit09911bf2008-07-26 23:55:29213}
214
[email protected]484955942010-08-19 16:13:18215// static
216WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
217 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03218 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18219 break;
220 case WebKit::WebPopupTypeSelect:
221 case WebKit::WebPopupTypeSuggestion:
222 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44223 case WebKit::WebPopupTypePage:
224 return WebPagePopup::create(render_widget);
[email protected]4b1146bc2012-07-10 18:46:03225 case WebKit::WebPopupTypeHelperPlugin:
226 return WebKit::WebHelperPlugin::create(render_widget);
[email protected]484955942010-08-19 16:13:18227 default:
228 NOTREACHED();
229 }
230 return NULL;
231}
232
[email protected]a635f942012-12-07 10:34:29233bool RenderWidget::Init(int32 opener_id) {
234 return DoInit(opener_id,
235 RenderWidget::CreateWebWidget(this),
236 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
237 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18238}
239
[email protected]a635f942012-12-07 10:34:29240bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06241 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18242 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29243 DCHECK(!webwidget_);
244
245 if (opener_id != MSG_ROUTING_NONE)
246 opener_id_ = opener_id;
247
[email protected]484955942010-08-19 16:13:18248 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29249
[email protected]380244092011-10-07 17:26:27250 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29251 if (result) {
[email protected]380244092011-10-07 17:26:27252 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29253 // Take a reference on behalf of the RenderThread. This will be balanced
254 // when we receive ViewMsg_Close.
255 AddRef();
[email protected]a635f942012-12-07 10:34:29256 return true;
initial.commit09911bf2008-07-26 23:55:29257 } else {
[email protected]a635f942012-12-07 10:34:29258 // The above Send can fail when the tab is closing.
259 return false;
initial.commit09911bf2008-07-26 23:55:29260 }
261}
262
[email protected]fc4404d2012-11-07 19:53:30263// This is used to complete pending inits and non-pending inits.
264void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29265 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29266
[email protected]fc4404d2012-11-07 19:53:30267 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42268
[email protected]8926c602013-01-23 05:32:06269 if (webwidget_ && is_threaded_compositing_enabled_) {
270 webwidget_->enterForceCompositingMode(true);
271 }
[email protected]ba91a792013-02-06 09:48:28272 if (compositor_) {
273 compositor_->setSurfaceReady();
[email protected]479b0172012-10-29 19:27:09274 }
[email protected]05a980d7a2012-02-07 22:16:42275 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29276
[email protected]6de74452009-02-25 18:04:59277 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29278}
279
[email protected]992db4c2011-05-12 15:37:15280void RenderWidget::SetSwappedOut(bool is_swapped_out) {
281 // We should only toggle between states.
282 DCHECK(is_swapped_out_ != is_swapped_out);
283 is_swapped_out_ = is_swapped_out;
284
285 // If we are swapping out, we will call ReleaseProcess, allowing the process
286 // to exit if all of its RenderViews are swapped out. We wait until the
287 // WasSwappedOut call to do this, to avoid showing the sad tab.
288 // If we are swapping in, we call AddRefProcess to prevent the process from
289 // exiting.
290 if (!is_swapped_out)
291 RenderProcess::current()->AddRefProcess();
292}
293
[email protected]34bb3ac2013-03-08 02:41:28294bool RenderWidget::AllowPartialSwap() const {
295 return true;
296}
297
[email protected]ccc1722e2013-05-06 19:43:07298bool RenderWidget::SynchronouslyDisableVSync() const {
299#if defined(OS_ANDROID)
300 if (CommandLine::ForCurrentProcess()->HasSwitch(
301 switches::kEnableSynchronousRendererCompositor)) {
302 return true;
303 }
304#endif
305 return false;
306}
307
[email protected]a95986a82010-12-24 06:19:28308bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
309 bool handled = true;
310 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15311 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22312 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
313 OnCursorVisibilityChange)
[email protected]c084330e02013-04-27 01:08:15314 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
315 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]a95986a82010-12-24 06:19:28316 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
317 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
318 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54319 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28320 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41321 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]992db4c2011-05-12 15:37:15322 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28323 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]ed7defa2013-03-12 21:29:59324 IPC_MESSAGE_HANDLER(ViewMsg_SwapBuffers_ACK,
325 OnViewContextSwapBuffersComplete)
[email protected]a95986a82010-12-24 06:19:28326 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
327 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
328 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]3d9ec5052013-01-02 22:05:25329 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnPaintAtSize)
330 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
331 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, OnSmoothScrollCompleted)
[email protected]a95986a82010-12-24 06:19:28332 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
333 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]6131a642012-06-15 23:26:53334 IPC_MESSAGE_HANDLER(ViewMsg_ScreenInfoChanged, OnScreenInfoChanged)
[email protected]80ad8622012-11-07 16:33:03335 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]105dffb42013-02-20 03:46:21336#if defined(OS_ANDROID)
337 IPC_MESSAGE_HANDLER(ViewMsg_ImeBatchStateChanged, OnImeBatchStateChanged)
[email protected]2384b6c2013-02-28 23:58:51338 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21339#endif
[email protected]51a49502013-03-23 01:50:19340 IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot)
[email protected]a95986a82010-12-24 06:19:28341 IPC_MESSAGE_UNHANDLED(handled = false)
342 IPC_END_MESSAGE_MAP()
343 return handled;
344}
initial.commit09911bf2008-07-26 23:55:29345
346bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15347 // Don't send any messages after the browser has told us to close, and filter
348 // most outgoing messages while swapped out.
349 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26350 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11351 closing_) {
initial.commit09911bf2008-07-26 23:55:29352 delete message;
353 return false;
354 }
355
356 // If given a messsage without a routing ID, then assign our routing ID.
357 if (message->routing_id() == MSG_ROUTING_NONE)
358 message->set_routing_id(routing_id_);
359
[email protected]380244092011-10-07 17:26:27360 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44361}
362
[email protected]61e2b3cc2012-03-02 16:13:34363void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44364 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40365 float overdraw_bottom_height,
[email protected]61e2b3cc2012-03-02 16:13:34366 const gfx::Rect& resizer_rect,
367 bool is_fullscreen,
368 ResizeAck resize_ack) {
369 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
370 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
371 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29372
[email protected]61e2b3cc2012-03-02 16:13:34373 // Ignore this during shutdown.
374 if (!webwidget_)
375 return;
376
[email protected]d9083762013-03-24 01:36:40377 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44378 compositor_->setViewportSize(new_size, physical_backing_size);
[email protected]d9083762013-03-24 01:36:40379 compositor_->SetOverdrawBottomHeight(overdraw_bottom_height);
380 }
[email protected]60d47ac2013-03-01 23:42:44381
[email protected]dade8992013-03-04 07:34:34382 physical_backing_size_ = physical_backing_size;
[email protected]d9083762013-03-24 01:36:40383 overdraw_bottom_height_ = overdraw_bottom_height;
[email protected]61e2b3cc2012-03-02 16:13:34384 resizer_rect_ = resizer_rect;
385
386 // NOTE: We may have entered fullscreen mode without changing our size.
387 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
388 if (fullscreen_change)
389 WillToggleFullscreen();
390 is_fullscreen_ = is_fullscreen;
391
392 if (size_ != new_size) {
393 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34394 needs_repainting_on_restore_ = false;
395
396 size_ = new_size;
397
398 paint_aggregator_.ClearPendingUpdate();
399
400 // When resizing, we want to wait to paint before ACK'ing the resize. This
401 // ensures that we only resize as fast as we can paint. We only need to
402 // send an ACK if we are resized to a non-empty rect.
403 webwidget_->resize(new_size);
404 if (!new_size.IsEmpty()) {
405 if (!is_accelerated_compositing_active_) {
406 // Resize should have caused an invalidation of the entire view.
407 DCHECK(paint_aggregator_.HasPendingUpdate());
408 }
[email protected]61e2b3cc2012-03-02 16:13:34409 }
[email protected]20fbfc22013-05-08 20:50:58410 } else if (!RenderThreadImpl::current()->short_circuit_size_updates()) {
[email protected]ff475a322012-03-14 00:05:35411 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34412 }
413
[email protected]20fbfc22013-05-08 20:50:58414 // Send the Resize_ACK flag once we paint again if requested.
415 if (resize_ack == SEND_RESIZE_ACK)
416 set_next_paint_is_resize_ack();
417
[email protected]61e2b3cc2012-03-02 16:13:34418 if (fullscreen_change)
419 DidToggleFullscreen();
420
421 // If a resize ack is requested and it isn't set-up, then no more resizes will
422 // come in and in general things will go wrong.
423 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
424 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29425}
426
427void RenderWidget::OnClose() {
428 if (closing_)
429 return;
430 closing_ = true;
431
432 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03433 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27434 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03435 SetHidden(false);
436 }
initial.commit09911bf2008-07-26 23:55:29437
initial.commit09911bf2008-07-26 23:55:29438 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25439 // now. Post a task that only gets invoked when there are no nested message
440 // loops.
[email protected]dd32b1272013-05-04 14:17:11441 base::MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29442 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25443
444 // Balances the AddRef taken when we called AddRoute.
445 Release();
initial.commit09911bf2008-07-26 23:55:29446}
447
[email protected]61e2b3cc2012-03-02 16:13:34448// Got a response from the browser after the renderer decided to create a new
449// view.
[email protected]fc4404d2012-11-07 19:53:30450void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34451 DCHECK(routing_id_ != MSG_ROUTING_NONE);
452
[email protected]fc4404d2012-11-07 19:53:30453 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34454}
455
[email protected]f21c613a2009-02-12 14:46:17456void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44457 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40458 float overdraw_bottom_height,
[email protected]ee41e7d22011-10-14 19:34:09459 const gfx::Rect& resizer_rect,
460 bool is_fullscreen) {
[email protected]d9083762013-03-24 01:36:40461 Resize(new_size, physical_backing_size, overdraw_bottom_height, resizer_rect,
462 is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29463}
464
[email protected]b5913d72012-02-07 22:26:54465void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
466 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59467 gfx::Rect view_rect(size_);
468
[email protected]ce112fe2012-10-29 22:52:18469 gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_);
[email protected]b9769d82012-02-10 00:23:59470 if (!old_damage_rect.IsEmpty())
471 paint_aggregator_.InvalidateRect(old_damage_rect);
472
[email protected]ce112fe2012-10-29 22:52:18473 gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect);
[email protected]b9769d82012-02-10 00:23:59474 if (!new_damage_rect.IsEmpty())
475 paint_aggregator_.InvalidateRect(new_damage_rect);
476
[email protected]b5913d72012-02-07 22:26:54477 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59478
[email protected]b5913d72012-02-07 22:26:54479 if (webwidget_)
480 webwidget_->didChangeWindowResizerRect();
481 }
482}
483
initial.commit09911bf2008-07-26 23:55:29484void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31485 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29486 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03487 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29488}
489
[email protected]9e2e4632012-07-27 16:38:41490void RenderWidget::OnWasShown(bool needs_repainting) {
491 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29492 // During shutdown we can just ignore this message.
493 if (!webwidget_)
494 return;
495
496 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03497 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29498
499 if (!needs_repainting && !needs_repainting_on_restore_)
500 return;
501 needs_repainting_on_restore_ = false;
502
[email protected]d65adb12010-04-28 17:26:49503 // Tag the next paint as a restore ack, which is picked up by
504 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29505 set_next_paint_is_restore_ack();
506
507 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56508 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46509 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
510 } else {
511 scheduleComposite();
512 }
initial.commit09911bf2008-07-26 23:55:29513}
514
[email protected]992db4c2011-05-12 15:37:15515void RenderWidget::OnWasSwappedOut() {
516 // If we have been swapped out and no one else is using this process,
517 // it's safe to exit now. If we get swapped back in, we will call
518 // AddRefProcess in SetSwappedOut.
519 if (is_swapped_out_)
520 RenderProcess::current()->ReleaseProcess();
521}
522
[email protected]53d3f302009-12-21 04:42:05523void RenderWidget::OnRequestMoveAck() {
524 DCHECK(pending_window_rect_count_);
525 pending_window_rect_count_--;
526}
527
528void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58529 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21530 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05531 update_reply_pending_ = false;
532
[email protected]b4d08452010-10-05 17:34:35533 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
534 // have no current paint buffer.
535 if (current_paint_buf_) {
536 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
537 current_paint_buf_ = NULL;
538 }
539
[email protected]65225772011-05-12 21:10:24540 // If swapbuffers is still pending, then defer the update until the
541 // swapbuffers occurs.
542 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
543 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
544 return;
545 }
546
[email protected]29ed96a2012-02-04 18:12:16547 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18548 if (!is_accelerated_compositing_active_) {
549 DidFlushPaint();
550 }
[email protected]a2f6bc112009-06-27 16:27:25551
initial.commit09911bf2008-07-26 23:55:29552 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24553 DoDeferredUpdateAndSendInputAck();
554}
555
[email protected]d0be63772011-12-20 23:18:04556bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]ed7defa2013-03-12 21:29:59557 // Contexts using the command buffer support asynchronous swapbuffers.
558 // See RenderWidget::CreateOutputSurface().
[email protected]8f746982013-03-21 06:28:03559 if (RenderThreadImpl::current()->compositor_message_loop_proxy())
[email protected]ed7defa2013-03-12 21:29:59560 return false;
561
562 return true;
563}
564
565GURL RenderWidget::GetURLForGraphicsContext3D() {
566 return GURL();
[email protected]65225772011-05-12 21:10:24567}
568
[email protected]479b0172012-10-29 19:27:09569bool RenderWidget::ForceCompositingModeEnabled() {
570 return false;
571}
572
[email protected]ba91a792013-02-06 09:48:28573scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface() {
[email protected]c3e32ed42013-05-02 05:07:13574 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
575 if (command_line.HasSwitch(switches::kEnableSoftwareCompositingGLAdapter)) {
576 return scoped_ptr<cc::OutputSurface>(
577 new CompositorOutputSurface(routing_id(), NULL,
578 new CompositorSoftwareOutputDevice()));
579 }
580
[email protected]ed7defa2013-03-12 21:29:59581 // Explicitly disable antialiasing for the compositor. As of the time of
582 // this writing, the only platform that supported antialiasing for the
583 // compositor was Mac OS X, because the on-screen OpenGL context creation
584 // code paths on Windows and Linux didn't yet have multisampling support.
585 // Mac OS X essentially always behaves as though it's rendering offscreen.
586 // Multisampling has a heavy cost especially on devices with relatively low
587 // fill rate like most notebooks, and the Mac implementation would need to
588 // be optimized to resolve directly into the IOSurface shared between the
589 // GPU and browser processes. For these reasons and to avoid platform
590 // disparities we explicitly disable antialiasing.
591 WebKit::WebGraphicsContext3D::Attributes attributes;
592 attributes.antialias = false;
593 attributes.shareResources = true;
594 attributes.noAutomaticFlushes = true;
[email protected]3ae68c52013-04-12 06:10:05595 WebGraphicsContext3DCommandBufferImpl* context =
596 CreateGraphicsContext3D(attributes);
[email protected]c3e32ed42013-05-02 05:07:13597 if (!context)
598 return scoped_ptr<cc::OutputSurface>();
[email protected]ed7defa2013-03-12 21:29:59599
[email protected]eeb93112013-05-01 19:41:10600#if defined(OS_ANDROID)
601 if (command_line.HasSwitch(switches::kEnableSynchronousRendererCompositor)) {
602 // TODO(joth): Move above the |context| creation step above when the
603 // SynchronousCompositor no longer depends on externally created context.
604 return scoped_ptr<cc::OutputSurface>(
605 new SynchronousCompositorOutputSurface(routing_id(),
606 context));
607 }
608#endif
609
[email protected]2847b222013-04-06 00:59:24610 bool composite_to_mailbox =
[email protected]7b45b5762013-05-08 14:36:56611 command_line.HasSwitch(cc::switches::kCompositeToMailbox) &&
612 !command_line.HasSwitch(switches::kEnableDelegatedRenderer);
[email protected]2847b222013-04-06 00:59:24613 DCHECK(!composite_to_mailbox || command_line.HasSwitch(
614 cc::switches::kEnableCompositorFrameMessage));
615 // No swap throttling yet when compositing on the main thread.
616 DCHECK(!composite_to_mailbox || is_threaded_compositing_enabled_);
617 return scoped_ptr<cc::OutputSurface>(composite_to_mailbox ?
618 new MailboxOutputSurface(routing_id(), context, NULL) :
619 new CompositorOutputSurface(routing_id(), context, NULL));
[email protected]ba91a792013-02-06 09:48:28620}
621
[email protected]ed7defa2013-03-12 21:29:59622void RenderWidget::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24623 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21624 while (!updates_pending_swap_.empty()) {
625 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
626 updates_pending_swap_.pop_front();
627 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
628 // compositing pass, hence doesn't require an UpdateRect message.
629 if (msg)
630 Send(msg);
631 }
[email protected]65225772011-05-12 21:10:24632 num_swapbuffers_complete_pending_ = 0;
633 using_asynchronous_swapbuffers_ = false;
634 // Schedule another frame so the compositor learns about it.
635 scheduleComposite();
636}
637
[email protected]ed7defa2013-03-12 21:29:59638void RenderWidget::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:08639 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21640
641 if (using_asynchronous_swapbuffers_) {
642 ViewHostMsg_UpdateRect* msg = NULL;
643 // pending_update_params_ can be NULL if the swap doesn't correspond to an
644 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
645 // message.
[email protected]59383c782013-04-17 16:43:27646 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:21647 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
648 pending_update_params_.reset();
649 }
650 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08651 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21652 }
[email protected]37a6f302011-07-11 23:43:08653}
654
[email protected]ed7defa2013-03-12 21:29:59655void RenderWidget::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24656 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16657
[email protected]404939f2012-06-01 04:06:18658 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16659 DidFlushPaint();
660
[email protected]65225772011-05-12 21:10:24661 // When compositing deactivates, we reset the swapbuffers pending count. The
662 // swapbuffers acks may still arrive, however.
663 if (num_swapbuffers_complete_pending_ == 0) {
664 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
665 return;
666 }
[email protected]aa4117f2011-12-09 22:19:21667 DCHECK(!updates_pending_swap_.empty());
668 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
669 updates_pending_swap_.pop_front();
670 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
671 // compositing pass, hence doesn't require an UpdateRect message.
672 if (msg)
673 Send(msg);
[email protected]65225772011-05-12 21:10:24674 num_swapbuffers_complete_pending_--;
675
676 // If update reply is still pending, then defer the update until that reply
677 // occurs.
[email protected]d0be63772011-12-20 23:18:04678 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24679 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
680 return;
681 }
682
683 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06684 // when we were previously rendering. However, if an invalidation task is not
685 // posted, there may be software rendering work pending. In that case, don't
686 // early out.
687 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24688 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
689 return;
690 }
691
[email protected]cc66e682012-10-02 06:48:18692 // Do not call DoDeferredUpdate unless there's animation work to be done or
693 // a real invalidation. This prevents rendering in response to a swapbuffers
694 // callback coming back after we've navigated away from the page that
695 // generated it.
696 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
697 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
698 return;
699 }
700
[email protected]65225772011-05-12 21:10:24701 // Continue painting if necessary...
702 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29703}
704
[email protected]0dea1652012-12-14 00:09:09705void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
706 bool is_keyboard_shortcut) {
[email protected]65225772011-05-12 21:10:24707 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
initial.commit09911bf2008-07-26 23:55:29708
[email protected]5dd768212009-08-13 23:34:49709 handling_input_event_ = true;
[email protected]0dea1652012-12-14 00:09:09710 if (!input_event) {
[email protected]5dd768212009-08-13 23:34:49711 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29712 return;
[email protected]5dd768212009-08-13 23:34:49713 }
initial.commit09911bf2008-07-26 23:55:29714
[email protected]6a4d7f62013-01-07 21:32:13715 base::TimeDelta now = base::TimeDelta::FromInternalValue(
716 base::TimeTicks::Now().ToInternalValue());
717
718 int64 delta = static_cast<int64>(
719 (now.InSecondsF() - input_event->timeStampSeconds) *
720 base::Time::kMicrosecondsPerSecond);
721 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer", delta, 0, 1000000, 100);
722 std::string name_for_event =
723 base::StringPrintf("Event.Latency.Renderer.%s",
724 GetEventName(input_event->type));
[email protected]de415552013-01-23 04:12:17725 base::HistogramBase* counter_for_type =
[email protected]bafdc5d52013-02-27 18:18:48726 base::Histogram::FactoryGet(
[email protected]6a4d7f62013-01-07 21:32:13727 name_for_event,
[email protected]bafdc5d52013-02-27 18:18:48728 0,
729 1000000,
[email protected]6a4d7f62013-01-07 21:32:13730 100,
[email protected]de415552013-01-23 04:12:17731 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]bafdc5d52013-02-27 18:18:48732 counter_for_type->Add(delta);
[email protected]6a4d7f62013-01-07 21:32:13733
[email protected]67bfb83f2011-09-22 03:36:37734 bool prevent_default = false;
735 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26736 const WebMouseEvent& mouse_event =
737 *static_cast<const WebMouseEvent*>(input_event);
738 TRACE_EVENT2("renderer", "HandleMouseMove",
739 "x", mouse_event.x, "y", mouse_event.y);
740 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37741 }
742
[email protected]41d86852012-11-07 12:23:24743 if (WebInputEvent::isGestureEventType(input_event->type)) {
744 const WebGestureEvent& gesture_event =
745 *static_cast<const WebGestureEvent*>(input_event);
746 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
747 }
748
[email protected]3ebcc7c2013-01-09 05:34:46749 if (input_event->type == WebInputEvent::GestureTap ||
750 input_event->type == WebInputEvent::GestureLongPress)
751 resetInputMethod();
752
[email protected]67bfb83f2011-09-22 03:36:37753 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12754 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
755 suppress_next_char_events_ = false;
756 if (!processed && webwidget_)
757 processed = webwidget_->handleInputEvent(*input_event);
758 }
759
760 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
761 // it's not processed by webkit, then we need to suppress the upcoming Char
762 // events.
763 if (!processed && is_keyboard_shortcut)
764 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29765
[email protected]3d5c243b2012-11-30 00:26:01766 InputEventAckState ack_result = processed ?
767 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
768 if (!processed && input_event->type == WebInputEvent::TouchStart) {
769 const WebTouchEvent& touch_event =
770 *static_cast<const WebTouchEvent*>(input_event);
771 ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ?
772 INPUT_EVENT_ACK_STATE_NOT_CONSUMED :
773 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
774 }
775
[email protected]a9fb30aa2011-10-06 06:58:46776 IPC::Message* response =
[email protected]c084330e02013-04-27 01:08:15777 new InputHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
778 ack_result);
[email protected]3391a0772012-03-28 00:32:07779 bool event_type_gets_rate_limited =
780 input_event->type == WebInputEvent::MouseMove ||
781 input_event->type == WebInputEvent::MouseWheel ||
782 WebInputEvent::isTouchEventType(input_event->type);
[email protected]8926c602013-01-23 05:32:06783
784 bool frame_pending = paint_aggregator_.HasPendingUpdate();
785 if (is_accelerated_compositing_active_) {
[email protected]ba91a792013-02-06 09:48:28786 frame_pending = compositor_ &&
787 compositor_->commitRequested();
[email protected]8926c602013-01-23 05:32:06788 }
789
[email protected]3391a0772012-03-28 00:32:07790 bool is_input_throttled =
[email protected]ce2b28e2012-08-09 15:53:57791 throttle_input_events_ &&
[email protected]8926c602013-01-23 05:32:06792 frame_pending;
[email protected]e2824412009-02-27 01:57:05793
[email protected]f8868d72012-04-27 19:13:03794 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24795 // We want to rate limit the input events in this case, so we'll wait for
796 // painting to finish before ACKing this message.
[email protected]59383c782013-04-17 16:43:27797 if (pending_input_event_ack_) {
[email protected]353a34c2010-05-28 23:35:17798 // As two different kinds of events could cause us to postpone an ack
799 // we send it now, if we have one pending. The Browser should never
800 // send us the same kind of event we are delaying the ack for.
801 Send(pending_input_event_ack_.release());
802 }
[email protected]12fbad812009-09-01 18:21:24803 pending_input_event_ack_.reset(response);
804 } else {
805 Send(response);
806 }
807
[email protected]3306f262012-09-21 19:20:42808#if defined(OS_ANDROID)
809 // Allow the IME to be shown when the focus changes as a consequence
810 // of a processed touch end event.
811 if (input_event->type == WebInputEvent::TouchEnd && processed)
812 UpdateTextInputState(SHOW_IME_IF_NEEDED);
813#endif
814
[email protected]5dd768212009-08-13 23:34:49815 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48816
[email protected]67bfb83f2011-09-22 03:36:37817 if (!prevent_default) {
818 if (WebInputEvent::isKeyboardEventType(input_event->type))
819 DidHandleKeyEvent();
820 if (WebInputEvent::isMouseEventType(input_event->type))
821 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24822 if (WebInputEvent::isTouchEventType(input_event->type))
823 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37824 }
initial.commit09911bf2008-07-26 23:55:29825}
826
[email protected]34202de2013-05-06 23:36:22827void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
828 if (webwidget_)
829 webwidget_->setCursorVisibilityState(is_visible);
830}
831
initial.commit09911bf2008-07-26 23:55:29832void RenderWidget::OnMouseCaptureLost() {
833 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28834 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29835}
836
837void RenderWidget::OnSetFocus(bool enable) {
838 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33839 if (webwidget_)
840 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29841}
842
843void RenderWidget::ClearFocus() {
844 // We may have got the focus from the browser before this gets processed, in
845 // which case we do not want to unfocus ourself.
846 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28847 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29848}
849
[email protected]2d5d09d52009-06-15 14:29:21850void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00851 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21852 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06853 TRACE_EVENT2("renderer", "PaintRect",
854 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:45855
856 const bool kEnableGpuBenchmarking =
857 CommandLine::ForCurrentProcess()->HasSwitch(
858 switches::kEnableGpuBenchmarking);
[email protected]4fb66842009-12-04 21:41:00859 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21860
861 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00862 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
863 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03864
[email protected]699ab0d2009-04-23 23:19:14865 // If there is a custom background, tile it.
866 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14867 SkPaint paint;
[email protected]4e29afd2012-12-04 04:07:11868 skia::RefPtr<SkShader> shader = skia::AdoptRef(
869 SkShader::CreateBitmapShader(background_,
870 SkShader::kRepeat_TileMode,
871 SkShader::kRepeat_TileMode));
872 paint.setShader(shader.get());
[email protected]fb10ec5b2011-10-24 17:54:20873
874 // Use kSrc_Mode to handle background_ transparency properly.
875 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
876
877 // Canvas could contain multiple update rects. Clip to given rect so that
878 // we don't accidentally clear other update rects.
879 canvas->save();
[email protected]aa7e7a12013-02-22 13:37:44880 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]1835b9e2012-02-28 13:12:48881 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14882 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20883 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14884 }
885
[email protected]719b36f2010-12-22 20:36:46886 // First see if this rect is a plugin that can paint itself faster.
887 TransportDIB* optimized_dib = NULL;
888 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:20889 float dib_scale_factor;
[email protected]719b36f2010-12-22 20:36:46890 webkit::ppapi::PluginInstance* optimized_instance =
891 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
892 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:20893 &optimized_copy_rect,
894 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:46895 if (optimized_instance) {
896 // This plugin can be optimize-painted and we can just ask it to paint
897 // itself. We don't actually need the TransportDIB in this case.
898 //
899 // This is an optimization for PPAPI plugins that know they're on top of
900 // the page content. If this rect is inside such a plugin, we can save some
901 // time and avoid re-rendering the page content which we know will be
902 // covered by the plugin later (this time can be significant, especially
903 // for a playing movie that is invalidating a lot).
904 //
905 // In the plugin movie case, hopefully the similar call to
906 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
907 // painting, because that avoids copying the plugin image to a different
908 // paint rect. Unfortunately, if anything on the page is animating other
909 // than the movie, it break this optimization since the union of the
910 // invalid regions will be larger than the plugin.
911 //
912 // This code optimizes that case, where we can still avoid painting in
913 // WebKit and filling the background (which can be slow) and just painting
914 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
915 // required.
[email protected]63ab54262012-11-09 15:58:45916 base::TimeTicks paint_begin_ticks;
917 if (kEnableGpuBenchmarking)
918 paint_begin_ticks = base::TimeTicks::HighResNow();
919
[email protected]df59dd42012-09-14 22:56:30920 SkAutoCanvasRestore auto_restore(canvas, true);
921 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]719b36f2010-12-22 20:36:46922 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27923 optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:21924 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45925 if (kEnableGpuBenchmarking) {
926 base::TimeDelta paint_time =
927 base::TimeTicks::HighResNow() - paint_begin_ticks;
928 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01929 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45930 }
[email protected]719b36f2010-12-22 20:36:46931 } else {
932 // Normal painting case.
[email protected]63ab54262012-11-09 15:58:45933 base::TimeTicks paint_begin_ticks;
934 if (kEnableGpuBenchmarking)
935 paint_begin_ticks = base::TimeTicks::HighResNow();
936
[email protected]719b36f2010-12-22 20:36:46937 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
[email protected]63ab54262012-11-09 15:58:45938
939 if (kEnableGpuBenchmarking) {
940 base::TimeDelta paint_time =
941 base::TimeTicks::HighResNow() - paint_begin_ticks;
942 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01943 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45944 }
[email protected]719b36f2010-12-22 20:36:46945
946 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35947 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46948 }
initial.commit09911bf2008-07-26 23:55:29949
[email protected]4fb66842009-12-04 21:41:00950 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00951 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45952
953 if (kEnableGpuBenchmarking) {
[email protected]63ab54262012-11-09 15:58:45954 int64 num_pixels_processed = rect.width() * rect.height();
[email protected]62049562013-03-24 00:39:01955 software_stats_.total_pixels_painted += num_pixels_processed;
[email protected]63ab54262012-11-09 15:58:45956 }
[email protected]4fb66842009-12-04 21:41:00957}
958
959void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
960 skia::PlatformCanvas* canvas) {
961 static bool kPaintBorder =
962 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
963 if (!kPaintBorder)
964 return;
965
[email protected]53d3f302009-12-21 04:42:05966 // Cycle through these colors to help distinguish new paint rects.
967 const SkColor colors[] = {
968 SkColorSetARGB(0x3F, 0xFF, 0, 0),
969 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
970 SkColorSetARGB(0x3F, 0, 0, 0xFF),
971 };
972 static int color_selector = 0;
973
[email protected]4fb66842009-12-04 21:41:00974 SkPaint paint;
975 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05976 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00977 paint.setStrokeWidth(1);
978
979 SkIRect irect;
980 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
981 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29982}
983
[email protected]52ccd0ea2011-02-16 01:09:05984void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30985 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30986 if (!animation_update_pending_) {
987 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59988 return;
[email protected]921244e42011-07-20 16:36:30989 }
[email protected]bd37ae252011-06-03 01:28:18990 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59991 // Record when we fired (according to base::Time::Now()) relative to when
992 // we posted the task to quantify how much the base::Time/base::TimeTicks
993 // skew is affecting animations.
994 base::TimeDelta animation_callback_delay = base::Time::Now() -
995 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
996 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
997 animation_callback_delay,
998 base::TimeDelta::FromMilliseconds(0),
999 base::TimeDelta::FromMilliseconds(30),
1000 25);
1001 }
[email protected]65225772011-05-12 21:10:241002 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:241003}
1004
[email protected]52ccd0ea2011-02-16 01:09:051005void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:591006 if (!animation_update_pending_)
1007 return;
[email protected]bd37ae252011-06-03 01:28:181008
1009 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:331010 base::TimeDelta animationInterval = IsRenderingVSynced() ?
1011 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:181012
[email protected]7c4329e2011-02-18 22:02:591013 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:451014
1015 // animation_floor_time_ is the earliest time that we should animate when
1016 // using the dead reckoning software scheduler. If we're using swapbuffers
1017 // complete callbacks to rate limit, we can ignore this floor.
1018 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:301019 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:331020 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:181021 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:591022 // running animation callbacks so that if a callback requests another
1023 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:381024 animation_timer_.Stop();
1025 animation_timer_.Start(FROM_HERE, animationInterval, this,
1026 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:591027 animation_update_pending_ = false;
[email protected]ba91a792013-02-06 09:48:281028 if (is_accelerated_compositing_active_ && compositor_) {
[email protected]635353c2013-03-06 09:11:201029 compositor_->Animate(base::TimeTicks::Now());
[email protected]8926c602013-01-23 05:32:061030 } else {
[email protected]635353c2013-03-06 09:11:201031 double frame_begin_time =
1032 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
1033 webwidget_->animate(frame_begin_time);
[email protected]8926c602013-01-23 05:32:061034 }
[email protected]7c4329e2011-02-18 22:02:591035 return;
[email protected]5f8b1022011-01-21 23:34:501036 }
[email protected]bd37ae252011-06-03 01:28:181037 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:381038 if (!animation_timer_.IsRunning()) {
1039 // This code uses base::Time::Now() to calculate the floor and next fire
1040 // time because javascript's Date object uses base::Time::Now(). The
1041 // message loop uses base::TimeTicks, which on windows can have a
1042 // different granularity than base::Time.
1043 // The upshot of all this is that this function might be called before
1044 // base::Time::Now() has advanced past the animation_floor_time_. To
1045 // avoid exposing this delay to javascript, we keep posting delayed
1046 // tasks until base::Time::Now() has advanced far enough.
1047 base::TimeDelta delay = animation_floor_time_ - now;
1048 animation_timer_.Start(FROM_HERE, delay, this,
1049 &RenderWidget::AnimationCallback);
1050 }
[email protected]5f8b1022011-01-21 23:34:501051}
1052
[email protected]bd37ae252011-06-03 01:28:181053bool RenderWidget::IsRenderingVSynced() {
1054 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
1055 // not caught by this check. This will lead to artificially low frame rates
1056 // for people who force vsync off at a driver level and expect Chrome to speed
1057 // up.
1058 return !has_disable_gpu_vsync_switch_;
1059}
1060
[email protected]65225772011-05-12 21:10:241061void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:061062 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:241063 invalidation_task_posted_ = false;
1064 DoDeferredUpdateAndSendInputAck();
1065}
1066
1067void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:051068 DoDeferredUpdate();
1069
[email protected]59383c782013-04-17 16:43:271070 if (pending_input_event_ack_)
[email protected]52ccd0ea2011-02-16 01:09:051071 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:211072}
1073
[email protected]552e6002009-11-19 05:24:571074void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:581075 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:081076
[email protected]65225772011-05-12 21:10:241077 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:291078 return;
[email protected]05a980d7a2012-02-07 22:16:421079
[email protected]fc4404d2012-11-07 19:53:301080 if (!init_complete_) {
1081 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:421082 return;
1083 }
[email protected]aa4117f2011-12-09 22:19:211084 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:241085 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
1086 return;
1087 }
[email protected]9ca84622011-06-02 23:46:391088 if (is_accelerated_compositing_active_ &&
1089 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:241090 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
1091 return;
1092 }
initial.commit09911bf2008-07-26 23:55:291093
[email protected]552e6002009-11-19 05:24:571094 // Suppress updating when we are hidden.
[email protected]e3d92a7f2013-01-10 02:35:051095 if (is_hidden_ || size_.IsEmpty() || is_swapped_out_) {
[email protected]552e6002009-11-19 05:24:571096 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:291097 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:241098 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:291099 return;
1100 }
1101
[email protected]05a980d7a2012-02-07 22:16:421102 if (is_accelerated_compositing_active_)
1103 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
1104
[email protected]0fb93f52011-05-18 23:13:561105 // Tracking of frame rate jitter
1106 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]38ce4e7b2013-02-23 06:17:371107 InstrumentWillBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:051108 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:501109
[email protected]f98d7e3c2010-09-13 22:30:461110 // Layout may generate more invalidation. It may also enable the
1111 // GPU acceleration, so make sure to run layout before we send the
1112 // GpuRenderingActivated message.
1113 webwidget_->layout();
1114
[email protected]dcca3aa92012-02-17 23:03:371115 // The following two can result in further layout and possibly
1116 // enable GPU acceleration so they need to be called before any painting
1117 // is done.
[email protected]3306f262012-09-21 19:20:421118 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]dcca3aa92012-02-17 23:03:371119 UpdateSelectionBounds();
1120
[email protected]5f8b1022011-01-21 23:34:501121 // Suppress painting if nothing is dirty. This has to be done after updating
1122 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:241123 if (!paint_aggregator_.HasPendingUpdate()) {
1124 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]38ce4e7b2013-02-23 06:17:371125 InstrumentDidCancelFrame();
[email protected]5f8b1022011-01-21 23:34:501126 return;
[email protected]65225772011-05-12 21:10:241127 }
[email protected]5f8b1022011-01-21 23:34:501128
[email protected]479b0172012-10-29 19:27:091129 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:361130 !is_threaded_compositing_enabled_ &&
[email protected]479b0172012-10-29 19:27:091131 ForceCompositingModeEnabled()) {
1132 webwidget_->enterForceCompositingMode(true);
1133 }
1134
[email protected]872ae5b2011-05-26 20:20:501135 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:561136 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:041137 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:561138 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
1139 delay,
1140 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411141 base::TimeDelta::FromMilliseconds(120),
1142 60);
[email protected]d0be63772011-12-20 23:18:041143 } else {
[email protected]0fb93f52011-05-18 23:13:561144 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
1145 delay,
1146 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411147 base::TimeDelta::FromMilliseconds(120),
1148 60);
[email protected]d0be63772011-12-20 23:18:041149 }
[email protected]872ae5b2011-05-26 20:20:501150
1151 // Calculate filtered time per frame:
1152 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
1153 filtered_time_per_frame_ =
1154 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:561155 }
1156 last_do_deferred_update_time_ = frame_begin_ticks;
1157
[email protected]fef5e3972012-08-07 03:59:471158 if (!is_accelerated_compositing_active_) {
[email protected]62049562013-03-24 00:39:011159 software_stats_.animation_frame_count++;
1160 software_stats_.screen_frame_count++;
[email protected]fef5e3972012-08-07 03:59:471161 }
1162
[email protected]552e6002009-11-19 05:24:571163 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:291164 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:301165 PaintAggregator::PendingUpdate update;
1166 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:291167
[email protected]53d3f302009-12-21 04:42:051168 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:181169 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:291170
[email protected]29ed96a2012-02-04 18:12:161171 // Notify derived classes that we're about to initiate a paint.
1172 WillInitiatePaint();
1173
[email protected]ca4847f2010-09-24 05:39:151174 // A plugin may be able to do an optimized paint. First check this, in which
1175 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:461176 // This optimization allows PPAPI plugins that declare themselves on top of
1177 // the page (like a traditional windowed plugin) to be able to animate (think
1178 // movie playing) without repeatedly re-painting the page underneath, or
1179 // copying the plugin backing store (since we can send the plugin's backing
1180 // store directly to the browser).
1181 //
1182 // This optimization only works when the entire invalid region is contained
1183 // within the plugin. There is a related optimization in PaintRect for the
1184 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:151185 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:151186 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201187 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:211188 DCHECK(!pending_update_params_.get());
1189 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551190 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211191 pending_update_params_->scroll_rect = update.scroll_rect;
1192 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211193 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1194 pending_update_params_->flags = next_paint_flags_;
1195 pending_update_params_->scroll_offset = GetScrollOffset();
1196 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091197 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211198 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091199 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211200
[email protected]ca4847f2010-09-24 05:39:151201 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561202 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151203 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201204 &optimized_copy_rect,
1205 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271206 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471207 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211208 pending_update_params_->bitmap = dib->id();
1209 pending_update_params_->bitmap_rect = optimized_copy_location;
1210 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201211 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561212 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461213 // Compute a buffer for painting and cache it.
[email protected]4889bd212013-02-11 22:23:101214
1215 bool fractional_scale = device_scale_factor_ -
1216 static_cast<int>(device_scale_factor_) != 0;
1217 if (fractional_scale) {
1218 // Damage might not be DIP aligned. Inflate damage to compensate.
1219 bounds.Inset(-1, -1);
1220 bounds.Intersect(gfx::Rect(size_));
1221 }
1222
1223 gfx::Rect pixel_bounds = gfx::ToEnclosingRect(
[email protected]ce112fe2012-10-29 22:52:181224 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]4889bd212013-02-11 22:23:101225
[email protected]ca4847f2010-09-24 05:39:151226 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351227 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591228 pixel_bounds));
[email protected]59383c782013-04-17 16:43:271229 if (!canvas) {
[email protected]f98d7e3c2010-09-13 22:30:461230 NOTREACHED();
1231 return;
1232 }
[email protected]cef3362f2009-12-21 17:48:451233
[email protected]f98d7e3c2010-09-13 22:30:461234 // We may get back a smaller canvas than we asked for.
1235 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591236 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1237 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1238 pixel_bounds.set_width(canvas->getDevice()->width());
1239 pixel_bounds.set_height(canvas->getDevice()->height());
1240 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1241 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051242
[email protected]f98d7e3c2010-09-13 22:30:461243 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1244
[email protected]aa4117f2011-12-09 22:19:211245 pending_update_params_->bitmap = current_paint_buf_->id();
1246 pending_update_params_->bitmap_rect = bounds;
1247
1248 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461249 // The scroll damage is just another rectangle to paint and copy.
1250 copy_rects.swap(update.paint_rects);
1251 if (!scroll_damage.IsEmpty())
1252 copy_rects.push_back(scroll_damage);
1253
[email protected]4889bd212013-02-11 22:23:101254 for (size_t i = 0; i < copy_rects.size(); ++i) {
1255 gfx::Rect rect = copy_rects[i];
1256 if (fractional_scale) {
1257 // Damage might not be DPI aligned. Inflate rect to compensate.
1258 rect.Inset(-1, -1);
1259 }
1260 PaintRect(rect, pixel_bounds.origin(), canvas.get());
1261 }
[email protected]60a50072012-01-11 02:05:351262
1263 // Software FPS tick for performance tests. The accelerated path traces the
1264 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1265 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421266 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW",
1267 TRACE_EVENT_SCOPE_THREAD);
[email protected]f98d7e3c2010-09-13 22:30:461268 } else { // Accelerated compositing path
1269 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211270 // If painting is done via the gpu process then we don't set any damage
1271 // rects to save the browser process from doing unecessary work.
1272 pending_update_params_->bitmap_rect = bounds;
1273 pending_update_params_->scroll_rect = gfx::Rect();
1274 // We don't need an ack, because we're not sharing a DIB with the browser.
1275 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1276 // with the browser for the GPU surface.
1277 pending_update_params_->needs_ack = false;
[email protected]f0c2a242013-03-15 19:34:521278 Composite(frame_begin_ticks);
[email protected]f98d7e3c2010-09-13 22:30:461279 }
1280
[email protected]936c6f52011-12-13 01:35:261281 // If we're holding a pending input event ACK, send the ACK before sending the
1282 // UpdateReply message so we can receive another input event before the
1283 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1284 // the UpdateRect IPC message handler.
[email protected]59383c782013-04-17 16:43:271285 if (pending_input_event_ack_)
[email protected]936c6f52011-12-13 01:35:261286 Send(pending_input_event_ack_.release());
1287
[email protected]ab543072013-01-25 04:38:151288 // If Composite() called SwapBuffers, pending_update_params_ will be reset (in
[email protected]aa4117f2011-12-09 22:19:211289 // OnSwapBuffersPosted), meaning a message has been added to the
1290 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1291 // the message now.
[email protected]59383c782013-04-17 16:43:271292 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:211293 // sending an ack to browser process that the paint is complete...
1294 update_reply_pending_ = pending_update_params_->needs_ack;
1295 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1296 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341297 }
[email protected]53d3f302009-12-21 04:42:051298
[email protected]29ed96a2012-02-04 18:12:161299 // If we're software rendering then we're done initiating the paint.
1300 if (!is_accelerated_compositing_active_)
1301 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291302}
1303
[email protected]f0c2a242013-03-15 19:34:521304void RenderWidget::Composite(base::TimeTicks frame_begin_time) {
[email protected]ab543072013-01-25 04:38:151305 DCHECK(is_accelerated_compositing_active_);
[email protected]ba91a792013-02-06 09:48:281306 if (compositor_) // TODO(jamesr): Figure out how this can be null.
[email protected]f0c2a242013-03-15 19:34:521307 compositor_->Composite(frame_begin_time);
[email protected]ab543072013-01-25 04:38:151308}
1309
initial.commit09911bf2008-07-26 23:55:291310///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461311// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291312
[email protected]4873c7d2009-07-16 06:36:281313void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]479b0172012-10-29 19:27:091314 TRACE_EVENT2("renderer", "RenderWidget::didInvalidateRect",
1315 "width", rect.width, "height", rect.height);
[email protected]552e6002009-11-19 05:24:571316 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481317 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181318 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571319 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291320 return;
1321
[email protected]552e6002009-11-19 05:24:571322 paint_aggregator_.InvalidateRect(damaged_rect);
1323
1324 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241325 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571326 return;
1327 if (!paint_aggregator_.HasPendingUpdate())
1328 return;
[email protected]aa4117f2011-12-09 22:19:211329 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241330 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1331 return;
1332
1333 // When GPU rendering, combine pending animations and invalidations into
1334 // a single update.
[email protected]816edc62012-03-17 01:27:221335 if (is_accelerated_compositing_active_ &&
1336 animation_update_pending_ &&
1337 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571338 return;
1339
1340 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291341 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1342 // on the call stack.
1343 // 2) Allows us to collect more damage rects before painting to help coalesce
1344 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241345 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111346 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211347 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291348}
1349
[email protected]990278ff2012-11-13 02:12:551350void RenderWidget::didScrollRect(int dx, int dy,
1351 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461352 // Drop scrolls on the floor when we are in compositing mode.
1353 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561354 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461355 return;
1356
[email protected]552e6002009-11-19 05:24:571357 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481358 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181359 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571360 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291361 return;
1362
[email protected]990278ff2012-11-13 02:12:551363 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571364
1365 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241366 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571367 return;
1368 if (!paint_aggregator_.HasPendingUpdate())
1369 return;
[email protected]aa4117f2011-12-09 22:19:211370 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241371 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1372 return;
1373
1374 // When GPU rendering, combine pending animations and invalidations into
1375 // a single update.
[email protected]816edc62012-03-17 01:27:221376 if (is_accelerated_compositing_active_ &&
1377 animation_update_pending_ &&
1378 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571379 return;
1380
1381 // Perform updating asynchronously. This serves two purposes:
1382 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1383 // on the call stack.
1384 // 2) Allows us to collect more damage rects before painting to help coalesce
1385 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241386 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111387 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211388 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291389}
1390
[email protected]244ac1892011-12-02 17:04:471391void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091392 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]8be1c582013-03-06 00:55:031393 if (RenderThreadImpl::current()->short_circuit_size_updates()) {
1394 setWindowRect(WebRect(rootWindowRect().x,
1395 rootWindowRect().y,
1396 new_size.width,
1397 new_size.height));
1398 } else {
[email protected]20fbfc22013-05-08 20:50:581399 size_ = new_size;
1400
1401 // If we don't clear PaintAggregator after changing autoResize state, then
1402 // we might end up in a situation where bitmap_rect is larger than the
1403 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1404 // with invalid damage rects.
1405 paint_aggregator_.ClearPendingUpdate();
[email protected]8be1c582013-03-06 00:55:031406 }
[email protected]20fbfc22013-05-08 20:50:581407
1408 if (auto_resize_mode_)
1409 AutoResizeCompositor();
1410
1411 if (!RenderThreadImpl::current()->short_circuit_size_updates())
1412 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091413 }
[email protected]244ac1892011-12-02 17:04:471414}
1415
[email protected]3a1c8a8032013-03-18 22:35:321416void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051417 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1418 device_scale_factor_));
1419 if (compositor_)
1420 compositor_->setViewportSize(size_, physical_backing_size_);
1421}
1422
[email protected]91acd1c2012-03-14 08:32:391423void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221424 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1425
[email protected]c63b4d42012-04-26 01:01:071426#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211427 if (!is_accelerated_compositing_active_) {
1428 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1429 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1430 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1431 // going to switch to accelerated compositing, the GPU process may need
1432 // round-trips to the browser's UI thread before finishing the frame,
1433 // causing deadlocks if we delay the UpdateRect until we receive the
1434 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071435 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1436 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211437 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1438 }
[email protected]c63b4d42012-04-26 01:01:071439#endif
[email protected]aa4117f2011-12-09 22:19:211440
[email protected]ea162f92011-10-04 23:08:221441 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421442 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241443 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221444}
1445
1446void RenderWidget::didDeactivateCompositor() {
1447 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1448
1449 is_accelerated_compositing_active_ = false;
1450 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1451 routing_id_, is_accelerated_compositing_active_));
1452
[email protected]ea162f92011-10-04 23:08:221453 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241454 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091455
1456 // In single-threaded mode, we exit force compositing mode and re-enter in
1457 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1458 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1459 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361460 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091461 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561462}
1463
[email protected]e195e582013-03-08 01:32:591464void RenderWidget::initializeLayerTreeView() {
1465 compositor_ = RenderWidgetCompositor::Create(this);
1466 if (!compositor_)
1467 return;
1468
1469 compositor_->setViewportSize(size_, physical_backing_size_);
1470 if (init_complete_)
1471 compositor_->setSurfaceReady();
1472}
1473
[email protected]8926c602013-01-23 05:32:061474WebKit::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281475 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061476}
1477
[email protected]9ed83fe2013-02-27 01:52:281478void RenderWidget::suppressCompositorScheduling(bool enable) {
1479 if (compositor_)
1480 compositor_->SetSuppressScheduleComposite(enable);
1481}
1482
[email protected]9cd43a62012-03-26 08:03:561483void RenderWidget::willBeginCompositorFrame() {
1484 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371485
[email protected]ea5f70a2013-03-07 12:30:361486 DCHECK(RenderThreadImpl::current()->compositor_message_loop_proxy());
[email protected]abe8b3a2012-03-28 21:19:371487
1488 // The following two can result in further layout and possibly
1489 // enable GPU acceleration so they need to be called before any painting
1490 // is done.
[email protected]2d354272013-01-14 00:59:061491 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]abe8b3a2012-03-28 21:19:371492 UpdateSelectionBounds();
1493
[email protected]9cd43a62012-03-26 08:03:561494 WillInitiatePaint();
1495}
1496
[email protected]3391a0772012-03-28 00:32:071497void RenderWidget::didBecomeReadyForAdditionalInput() {
1498 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]59383c782013-04-17 16:43:271499 if (pending_input_event_ack_)
[email protected]3391a0772012-03-28 00:32:071500 Send(pending_input_event_ack_.release());
1501}
1502
[email protected]6fceb912013-02-15 06:24:151503void RenderWidget::DidCommitCompositorFrame() {
1504}
1505
[email protected]58264a32011-11-17 23:36:151506void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501507 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351508 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1509 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421510 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU",
1511 TRACE_EVENT_SCOPE_THREAD);
[email protected]29ed96a2012-02-04 18:12:161512 // Notify subclasses that we initiated the paint operation.
1513 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151514}
1515
1516void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181517 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1518
1519 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561520 DidFlushPaint();
1521
[email protected]aa4117f2011-12-09 22:19:211522 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151523 return;
1524
[email protected]ea3ee0a2012-05-15 03:43:091525 if (!next_paint_flags_ &&
1526 !need_update_rect_for_auto_resize_ &&
1527 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151528 return;
[email protected]ea3ee0a2012-05-15 03:43:091529 }
[email protected]58264a32011-11-17 23:36:151530
1531 ViewHostMsg_UpdateRect_Params params;
1532 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151533 params.plugin_window_moves.swap(plugin_window_moves_);
1534 params.flags = next_paint_flags_;
1535 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121536 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091537 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151538
1539 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1540 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091541 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151542}
1543
[email protected]f98d7e3c2010-09-13 22:30:461544void RenderWidget::scheduleComposite() {
[email protected]479b0172012-10-29 19:27:091545 TRACE_EVENT0("gpu", "RenderWidget::scheduleComposite");
[email protected]ea5f70a2013-03-07 12:30:361546 if (RenderThreadImpl::current()->compositor_message_loop_proxy() &&
[email protected]ba91a792013-02-06 09:48:281547 compositor_) {
1548 compositor_->setNeedsRedraw();
[email protected]d0be63772011-12-20 23:18:041549 } else {
[email protected]c3d45532011-10-07 19:20:401550 // TODO(nduca): replace with something a little less hacky. The reason this
1551 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1552 // contains a lot of host-renderer synchronization logic that is still
1553 // important for the accelerated compositing case. The option of simply
1554 // duplicating all that code is less desirable than "faking out" the
1555 // invalidation path using a magical damage rect.
1556 didInvalidateRect(WebRect(0, 0, 1, 1));
1557 }
[email protected]f98d7e3c2010-09-13 22:30:461558}
1559
[email protected]5f8b1022011-01-21 23:34:501560void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201561 if (animation_update_pending_)
1562 return;
1563
[email protected]921244e42011-07-20 16:36:301564 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201565 animation_update_pending_ = true;
1566 if (!animation_timer_.IsRunning()) {
1567 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1568 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211569 }
[email protected]5f8b1022011-01-21 23:34:501570}
1571
[email protected]4873c7d2009-07-16 06:36:281572void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301573 // TODO(darin): Eliminate this temporary.
1574 WebCursor cursor(cursor_info);
1575
initial.commit09911bf2008-07-26 23:55:291576 // Only send a SetCursor message if we need to make a change.
1577 if (!current_cursor_.IsEqual(cursor)) {
1578 current_cursor_ = cursor;
1579 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1580 }
1581}
1582
1583// We are supposed to get a single call to Show for a newly created RenderWidget
1584// that was created via RenderWidget::CreateWebView. So, we wait until this
1585// point to dispatch the ShowWidget message.
1586//
1587// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281588// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291589//
[email protected]4873c7d2009-07-16 06:36:281590void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291591 DCHECK(!did_show_) << "received extraneous Show call";
1592 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1593 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1594
[email protected]8de12d942010-11-17 20:42:441595 if (did_show_)
1596 return;
1597
1598 did_show_ = true;
1599 // NOTE: initial_pos_ may still have its default values at this point, but
1600 // that's okay. It'll be ignored if as_popup is false, or the browser
1601 // process will impose a default position otherwise.
1602 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1603 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291604}
1605
[email protected]4873c7d2009-07-16 06:36:281606void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291607}
1608
[email protected]4873c7d2009-07-16 06:36:281609void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291610}
1611
[email protected]2533ce12009-05-09 00:02:241612void RenderWidget::DoDeferredClose() {
1613 Send(new ViewHostMsg_Close(routing_id_));
1614}
1615
[email protected]4873c7d2009-07-16 06:36:281616void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321617 if (is_swapped_out_) {
1618 // This widget is currently swapped out, and the active widget is in a
1619 // different process. Have the browser route the close request to the
1620 // active widget instead, so that the correct unload handlers are run.
1621 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1622 return;
1623 }
1624
initial.commit09911bf2008-07-26 23:55:291625 // If a page calls window.close() twice, we'll end up here twice, but that's
1626 // OK. It is safe to send multiple Close messages.
1627
[email protected]2533ce12009-05-09 00:02:241628 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1629 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1630 // could be closed before the JS finishes executing. So instead, post a
1631 // message back to the message loop, which won't run until the JS is
1632 // complete, and then the Close message can be sent.
[email protected]dd32b1272013-05-04 14:17:111633 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211634 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291635}
1636
1637void RenderWidget::Close() {
1638 if (webwidget_) {
[email protected]8926c602013-01-23 05:32:061639 webwidget_->willCloseLayerTreeView();
[email protected]ba91a792013-02-06 09:48:281640 compositor_.reset();
[email protected]4873c7d2009-07-16 06:36:281641 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291642 webwidget_ = NULL;
1643 }
1644}
1645
[email protected]4873c7d2009-07-16 06:36:281646WebRect RenderWidget::windowRect() {
1647 if (pending_window_rect_count_)
1648 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241649
[email protected]80ad8622012-11-07 16:33:031650 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291651}
1652
[email protected]8a9d6ca32011-06-06 20:11:301653void RenderWidget::setToolTipText(const WebKit::WebString& text,
1654 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541655 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301656}
1657
[email protected]4873c7d2009-07-16 06:36:281658void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291659 if (did_show_) {
[email protected]8be1c582013-03-06 00:55:031660 if (!RenderThreadImpl::current()->short_circuit_size_updates()) {
1661 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1662 SetPendingWindowRect(pos);
1663 } else {
1664 WebSize new_size(pos.width, pos.height);
[email protected]d9083762013-03-24 01:36:401665 Resize(new_size, new_size, overdraw_bottom_height_,
1666 WebRect(), is_fullscreen_, NO_RESIZE_ACK);
[email protected]8be1c582013-03-06 00:55:031667 view_screen_rect_ = pos;
1668 window_screen_rect_ = pos;
1669 }
initial.commit09911bf2008-07-26 23:55:291670 } else {
1671 initial_pos_ = pos;
1672 }
1673}
1674
[email protected]2533ce12009-05-09 00:02:241675void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1676 pending_window_rect_ = rect;
1677 pending_window_rect_count_++;
1678}
1679
[email protected]4873c7d2009-07-16 06:36:281680WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241681 if (pending_window_rect_count_) {
1682 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1683 // the RootWindowRect is probably going to return wrong results since the
1684 // browser may not have processed the Move yet. There isn't really anything
1685 // good to do in this case, and it shouldn't happen - since this size is
1686 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281687 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241688 }
1689
[email protected]80ad8622012-11-07 16:33:031690 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371691}
1692
[email protected]4873c7d2009-07-16 06:36:281693WebRect RenderWidget::windowResizerRect() {
1694 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191695}
1696
[email protected]fa7b1dc2010-06-23 17:53:041697void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031698 // To prevent this renderer process from sending unnecessary IPC messages to
1699 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041700 // only during the input method attached to the browser process is active.
1701 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291702}
1703
[email protected]58b48a0d2012-06-13 07:01:351704void RenderWidget::UpdateCompositionInfo(
1705 const ui::Range& range,
1706 const std::vector<gfx::Rect>& character_bounds) {
1707 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1708 return;
1709 composition_character_bounds_ = character_bounds;
1710 composition_range_ = range;
1711 Send(new ViewHostMsg_ImeCompositionRangeChanged(
1712 routing_id(), composition_range_, composition_character_bounds_));
1713}
1714
[email protected]fa7b1dc2010-06-23 17:53:041715void RenderWidget::OnImeSetComposition(
1716 const string16& text,
1717 const std::vector<WebCompositionUnderline>& underlines,
1718 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281719 if (!webwidget_)
1720 return;
[email protected]e8f775f2013-02-14 21:00:501721 DCHECK(!handling_ime_event_);
1722 handling_ime_event_ = true;
[email protected]d4cff272011-05-02 15:46:011723 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041724 text, WebVector<WebCompositionUnderline>(underlines),
1725 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011726 // Setting the IME composition was successful. Send the new composition
1727 // range to the browser.
1728 ui::Range range(ui::Range::InvalidRange());
1729 size_t location, length;
1730 if (webwidget_->compositionRange(&location, &length)) {
1731 range.set_start(location);
1732 range.set_end(location + length);
1733 }
1734 // The IME was cancelled via the Esc key, so just send back the caret.
1735 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1736 range.set_start(location);
1737 range.set_end(location + length);
1738 }
[email protected]58b48a0d2012-06-13 07:01:351739 std::vector<gfx::Rect> character_bounds;
1740 GetCompositionCharacterBounds(&character_bounds);
1741 UpdateCompositionInfo(range, character_bounds);
[email protected]d4cff272011-05-02 15:46:011742 } else {
[email protected]fa7b1dc2010-06-23 17:53:041743 // If we failed to set the composition text, then we need to let the browser
1744 // process to cancel the input method's ongoing composition session, to make
1745 // sure we are in a consistent state.
1746 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011747
1748 // Send an updated IME range with just the caret range.
1749 ui::Range range(ui::Range::InvalidRange());
1750 size_t location, length;
1751 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1752 range.set_start(location);
1753 range.set_end(location + length);
1754 }
[email protected]58b48a0d2012-06-13 07:01:351755 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]7f00efa2010-04-15 05:01:261756 }
[email protected]e8f775f2013-02-14 21:00:501757 handling_ime_event_ = false;
1758 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]fa7b1dc2010-06-23 17:53:041759}
1760
[email protected]4de6d1692011-10-12 08:45:441761void RenderWidget::OnImeConfirmComposition(
1762 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041763 if (!webwidget_)
1764 return;
[email protected]e8f775f2013-02-14 21:00:501765 DCHECK(!handling_ime_event_);
1766 handling_ime_event_ = true;
[email protected]d0be63772011-12-20 23:18:041767 handling_input_event_ = true;
1768 webwidget_->confirmComposition(text);
1769 handling_input_event_ = false;
1770
[email protected]d4cff272011-05-02 15:46:011771 // Send an updated IME range with just the caret range.
1772 ui::Range range(ui::Range::InvalidRange());
1773 size_t location, length;
1774 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1775 range.set_start(location);
1776 range.set_end(location + length);
1777 }
[email protected]58b48a0d2012-06-13 07:01:351778 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]e8f775f2013-02-14 21:00:501779 handling_ime_event_ = false;
1780 UpdateTextInputState(DO_NOT_SHOW_IME);
initial.commit09911bf2008-07-26 23:55:291781}
1782
[email protected]948f7ab72010-05-28 23:48:081783// This message causes the renderer to render an image of the
1784// desired_size, regardless of whether the tab is hidden or not.
[email protected]3d9ec5052013-01-02 22:05:251785void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle,
1786 int tag,
1787 const gfx::Size& page_size,
1788 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001789 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1790 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251791 // Close our unused handle.
1792#if defined(OS_WIN)
1793 ::CloseHandle(dib_handle);
1794#elif defined(OS_MACOSX)
1795 base::SharedMemory::CloseHandle(dib_handle);
1796#endif
1797 }
[email protected]d65adb12010-04-28 17:26:491798 return;
[email protected]45c6aad32010-11-11 04:46:251799 }
[email protected]d65adb12010-04-28 17:26:491800
[email protected]948f7ab72010-05-28 23:48:081801 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491802 // If one of these is empty, then we just return the dib we were
1803 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091804 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491805 return;
1806 }
1807
1808 // Map the given DIB ID into this process, and unmap it at the end
1809 // of this function.
[email protected]45c6aad32010-11-11 04:46:251810 scoped_ptr<TransportDIB> paint_at_size_buffer(
1811 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301812
[email protected]4b01b962012-10-09 23:17:351813 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281814 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:351815 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281816 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:511817 gfx::Size canvas_size = page_size_in_pixel;
1818 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:491819 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:511820 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:491821 static_cast<float>(canvas_size.height());
1822
[email protected]ee8d6fd2010-05-26 17:05:481823 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491824 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1825 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481826 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491827
[email protected]36808ad2010-10-20 19:18:301828 scoped_ptr<skia::PlatformCanvas> canvas(
1829 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1830 canvas_size.height()));
[email protected]59383c782013-04-17 16:43:271831 if (!canvas) {
[email protected]36808ad2010-10-20 19:18:301832 NOTREACHED();
1833 return;
1834 }
1835
[email protected]d65adb12010-04-28 17:26:491836 // Reset bounds to what we actually received, but they should be the
1837 // same.
1838 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1839 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1840 bounds.set_width(canvas->getDevice()->width());
1841 bounds.set_height(canvas->getDevice()->height());
1842
1843 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081844 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491845 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1846
[email protected]948f7ab72010-05-28 23:48:081847 // Have to make sure we're laid out at the right size before
1848 // rendering.
1849 gfx::Size old_size = webwidget_->size();
1850 webwidget_->resize(page_size);
1851 webwidget_->layout();
1852
[email protected]d65adb12010-04-28 17:26:491853 // Paint the entire thing (using original bounds, not scaled bounds).
1854 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1855 canvas->restore();
1856
[email protected]948f7ab72010-05-28 23:48:081857 // Return the widget to its previous size.
1858 webwidget_->resize(old_size);
1859
[email protected]c88c9442010-07-19 18:55:091860 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491861}
1862
[email protected]51a49502013-03-23 01:50:191863void RenderWidget::OnSnapshot(const gfx::Rect& src_subrect) {
1864 SkBitmap snapshot;
1865
1866 if (OnSnapshotHelper(src_subrect, &snapshot)) {
1867 Send(new ViewHostMsg_Snapshot(routing_id(), true, snapshot));
1868 } else {
1869 Send(new ViewHostMsg_Snapshot(routing_id(), false, SkBitmap()));
1870 }
1871}
1872
1873bool RenderWidget::OnSnapshotHelper(const gfx::Rect& src_subrect,
1874 SkBitmap* snapshot) {
1875 base::TimeTicks beginning_time = base::TimeTicks::Now();
1876
1877 if (!webwidget_ || src_subrect.IsEmpty())
1878 return false;
1879
1880 gfx::Rect viewport_size = gfx::IntersectRects(
1881 src_subrect, gfx::Rect(physical_backing_size_));
1882
1883 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(
1884 skia::CreatePlatformCanvas(viewport_size.width(),
1885 viewport_size.height(),
1886 true,
1887 NULL,
1888 skia::RETURN_NULL_ON_FAILURE));
[email protected]59383c782013-04-17 16:43:271889 if (!canvas)
[email protected]51a49502013-03-23 01:50:191890 return false;
1891
1892 canvas->save();
1893 webwidget_->layout();
1894
1895 PaintRect(viewport_size, viewport_size.origin(), canvas.get());
1896 canvas->restore();
1897
1898 const SkBitmap& bitmap = skia::GetTopDevice(*canvas)->accessBitmap(false);
1899 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1900 return false;
1901
1902 UMA_HISTOGRAM_TIMES("Renderer4.Snapshot",
1903 base::TimeTicks::Now() - beginning_time);
1904 return true;
1905}
1906
[email protected]0bc1f572013-04-17 01:46:311907void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121908 // During shutdown we can just ignore this message.
1909 if (!webwidget_)
1910 return;
1911
[email protected]0bc1f572013-04-17 01:46:311912 // Even if the browser provides an empty damage rect, it's still expecting to
1913 // receive a repaint ack so just damage the entire widget bounds.
1914 if (size_to_paint.IsEmpty()) {
1915 size_to_paint = size_;
1916 }
1917
[email protected]ec7dc112008-08-06 05:30:121918 set_next_paint_is_repaint_ack();
[email protected]0bc1f572013-04-17 01:46:311919 if (is_accelerated_compositing_active_ && compositor_) {
1920 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]f98d7e3c2010-09-13 22:30:461921 } else {
1922 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1923 didInvalidateRect(repaint_rect);
1924 }
[email protected]ec7dc112008-08-06 05:30:121925}
1926
[email protected]4a9dba42013-04-29 18:24:221927void RenderWidget::OnSmoothScrollCompleted() {
1928 pending_smooth_scroll_gesture_.Run();
[email protected]0e241b4b2012-08-18 09:06:271929}
1930
[email protected]4873c7d2009-07-16 06:36:281931void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111932 if (!webwidget_)
1933 return;
[email protected]4873c7d2009-07-16 06:36:281934 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111935}
1936
[email protected]6131a642012-06-15 23:26:531937void RenderWidget::OnScreenInfoChanged(
1938 const WebKit::WebScreenInfo& screen_info) {
1939 screen_info_ = screen_info;
[email protected]468ac582012-11-20 00:53:191940 SetDeviceScaleFactor(screen_info.deviceScaleFactor);
[email protected]6131a642012-06-15 23:26:531941}
1942
[email protected]80ad8622012-11-07 16:33:031943void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1944 const gfx::Rect& window_screen_rect) {
1945 view_screen_rect_ = view_screen_rect;
1946 window_screen_rect_ = window_screen_rect;
1947 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1948}
1949
[email protected]105dffb42013-02-20 03:46:211950#if defined(OS_ANDROID)
1951void RenderWidget::OnImeBatchStateChanged(bool is_begin) {
1952 Send(new ViewHostMsg_ImeBatchStateChanged_ACK(routing_id(), is_begin));
1953}
[email protected]2384b6c2013-02-28 23:58:511954
1955void RenderWidget::OnShowImeIfNeeded() {
1956 UpdateTextInputState(SHOW_IME_IF_NEEDED);
1957}
[email protected]105dffb42013-02-20 03:46:211958#endif
1959
[email protected]468ac582012-11-20 00:53:191960void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1961 if (device_scale_factor_ == device_scale_factor)
1962 return;
1963
1964 device_scale_factor_ = device_scale_factor;
1965
1966 if (!is_accelerated_compositing_active_) {
1967 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
1968 } else {
1969 scheduleComposite();
1970 }
1971}
1972
[email protected]719b36f2010-12-22 20:36:461973webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151974 const gfx::Rect& paint_bounds,
1975 TransportDIB** dib,
1976 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:201977 gfx::Rect* clip,
1978 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:461979 // Bare RenderWidgets don't support optimized plugin painting.
1980 return NULL;
[email protected]ca4847f2010-09-24 05:39:151981}
1982
[email protected]ceb36f7d2012-10-31 18:33:241983gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521984 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241985 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521986}
1987
[email protected]bee16aab2009-08-26 15:55:031988void RenderWidget::SetHidden(bool hidden) {
1989 if (is_hidden_ == hidden)
1990 return;
1991
1992 // The status has changed. Tell the RenderThread about it.
1993 is_hidden_ = hidden;
1994 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271995 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031996 else
[email protected]380244092011-10-07 17:26:271997 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031998}
1999
[email protected]2b624c562011-10-27 22:58:262000void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262001 if (!webwidget_)
2002 return;
2003
2004 if (is_fullscreen_) {
2005 webwidget_->willExitFullScreen();
2006 } else {
2007 webwidget_->willEnterFullScreen();
2008 }
[email protected]2b624c562011-10-27 22:58:262009}
2010
2011void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262012 if (!webwidget_)
2013 return;
2014
2015 if (is_fullscreen_) {
2016 webwidget_->didEnterFullScreen();
2017 } else {
2018 webwidget_->didExitFullScreen();
2019 }
[email protected]2b624c562011-10-27 22:58:262020}
2021
[email protected]699ab0d2009-04-23 23:19:142022void RenderWidget::SetBackground(const SkBitmap& background) {
2023 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:462024
[email protected]699ab0d2009-04-23 23:19:142025 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:282026 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:142027}
2028
[email protected]674741932009-02-04 23:44:462029bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:052030 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462031}
2032
2033bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:052034 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462035}
2036
2037void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:052038 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462039}
2040
2041void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:052042 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:462043}
2044
2045void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:052046 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462047}
2048
[email protected]b18583c2012-12-18 06:55:272049static bool IsDateTimeInput(ui::TextInputType type) {
2050 return type == ui::TEXT_INPUT_TYPE_DATE ||
2051 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
2052 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
2053 type == ui::TEXT_INPUT_TYPE_MONTH ||
2054 type == ui::TEXT_INPUT_TYPE_TIME ||
2055 type == ui::TEXT_INPUT_TYPE_WEEK;
2056}
2057
[email protected]3306f262012-09-21 19:20:422058void RenderWidget::UpdateTextInputState(ShowIme show_ime) {
[email protected]e8f775f2013-02-14 21:00:502059 if (handling_ime_event_)
2060 return;
[email protected]3306f262012-09-21 19:20:422061 bool show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
2062 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:292063 return;
[email protected]ad26ef42011-06-17 07:59:452064 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:272065 if (IsDateTimeInput(new_type))
2066 return; // Not considered as a text input field in WebKit/Chromium.
2067
[email protected]5b739cb2012-08-21 20:35:212068 WebKit::WebTextInputInfo new_info;
2069 if (webwidget_)
2070 new_info = webwidget_->textInputInfo();
2071
[email protected]ad26ef42011-06-17 07:59:452072 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:212073
[email protected]3306f262012-09-21 19:20:422074 // Only sends text input params if they are changed or if the ime should be
2075 // shown.
2076 if (show_ime_if_needed || (text_input_type_ != new_type
2077 || text_input_info_ != new_info
2078 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:212079 ViewHostMsg_TextInputState_Params p;
2080 p.type = new_type;
2081 p.value = new_info.value.utf8();
2082 p.selection_start = new_info.selectionStart;
2083 p.selection_end = new_info.selectionEnd;
2084 p.composition_start = new_info.compositionStart;
2085 p.composition_end = new_info.compositionEnd;
2086 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:422087 p.show_ime_if_needed = show_ime_if_needed;
[email protected]5b739cb2012-08-21 20:35:212088 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
2089
2090 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:042091 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:452092 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:292093 }
initial.commit09911bf2008-07-26 23:55:292094}
2095
[email protected]7c8873e2013-02-05 08:03:012096void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2097 WebRect focus_webrect;
2098 WebRect anchor_webrect;
2099 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
2100 *focus = focus_webrect;
2101 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322102}
2103
[email protected]e99ef6f2011-10-16 01:13:002104void RenderWidget::UpdateSelectionBounds() {
2105 if (!webwidget_)
2106 return;
2107
[email protected]7c8873e2013-02-05 08:03:012108 ViewHostMsg_SelectionBounds_Params params;
2109 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2110 if (selection_anchor_rect_ != params.anchor_rect ||
2111 selection_focus_rect_ != params.focus_rect) {
2112 selection_anchor_rect_ = params.anchor_rect;
2113 selection_focus_rect_ = params.focus_rect;
2114 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
[email protected]129b7382013-02-12 02:14:292115 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
[email protected]7c8873e2013-02-05 08:03:012116 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
[email protected]58b48a0d2012-06-13 07:01:352117 }
[email protected]e99ef6f2011-10-16 01:13:002118
[email protected]58b48a0d2012-06-13 07:01:352119 std::vector<gfx::Rect> character_bounds;
2120 GetCompositionCharacterBounds(&character_bounds);
2121 UpdateCompositionInfo(composition_range_, character_bounds);
2122}
2123
2124bool RenderWidget::ShouldUpdateCompositionInfo(
2125 const ui::Range& range,
2126 const std::vector<gfx::Rect>& bounds) {
2127 if (composition_range_ != range)
2128 return true;
2129 if (bounds.size() != composition_character_bounds_.size())
2130 return true;
2131 for (size_t i = 0; i < bounds.size(); ++i) {
2132 if (bounds[i] != composition_character_bounds_[i])
2133 return true;
2134 }
2135 return false;
[email protected]e99ef6f2011-10-16 01:13:002136}
2137
[email protected]73bf95812011-10-12 11:38:322138// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:452139COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
2140 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
2141COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
2142 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
2143COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
2144 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:182145COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
2146 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
2147COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
2148 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
2149COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
2150 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
2151COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
2152 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
2153COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
2154 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:002155COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
2156 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
2157COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
2158 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
2159COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
2160 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
2161COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
2162 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
2163COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
2164 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
2165COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
2166 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:012167COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
2168 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
2169COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
2170 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]8b4992e2013-03-01 15:42:152171COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeField) == \
2172 int(ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:452173
[email protected]5b739cb2012-08-21 20:35:212174ui::TextInputType RenderWidget::WebKitToUiTextInputType(
2175 WebKit::WebTextInputType type) {
2176 // Check the type is in the range representable by ui::TextInputType.
2177 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
2178 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
2179 return static_cast<ui::TextInputType>(type);
2180}
2181
[email protected]ad26ef42011-06-17 07:59:452182ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272183 if (webwidget_)
2184 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452185 return ui::TEXT_INPUT_TYPE_NONE;
2186}
2187
[email protected]58b48a0d2012-06-13 07:01:352188void RenderWidget::GetCompositionCharacterBounds(
2189 std::vector<gfx::Rect>* bounds) {
2190 DCHECK(bounds);
2191 bounds->clear();
2192}
2193
[email protected]ad26ef42011-06-17 07:59:452194bool RenderWidget::CanComposeInline() {
2195 return true;
[email protected]56ea1a62011-05-30 07:05:572196}
2197
[email protected]4873c7d2009-07-16 06:36:282198WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042199 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282200}
2201
[email protected]f660d9c2012-06-06 18:31:212202float RenderWidget::deviceScaleFactor() {
2203 return device_scale_factor_;
2204}
2205
[email protected]fa7b1dc2010-06-23 17:53:042206void RenderWidget::resetInputMethod() {
2207 if (!input_method_is_active_)
2208 return;
2209
2210 // If the last text input type is not None, then we should finish any
2211 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452212 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042213 // If a composition text exists, then we need to let the browser process
2214 // to cancel the input method's ongoing composition session.
2215 if (webwidget_->confirmComposition())
2216 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
2217 }
[email protected]d4cff272011-05-02 15:46:012218
2219 // Send an updated IME range with the current caret rect.
2220 ui::Range range(ui::Range::InvalidRange());
2221 size_t location, length;
2222 if (webwidget_->caretOrSelectionRange(&location, &length)) {
2223 range.set_start(location);
2224 range.set_end(location + length);
2225 }
[email protected]58b48a0d2012-06-13 07:01:352226
2227 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]fa7b1dc2010-06-23 17:53:042228}
2229
[email protected]c68c3e4e2013-01-24 00:36:562230void RenderWidget::didHandleGestureEvent(
2231 const WebGestureEvent& event,
2232 bool event_cancelled) {
2233#if defined(OS_ANDROID)
2234 if (event_cancelled)
2235 return;
2236 if (event.type == WebInputEvent::GestureTap ||
2237 event.type == WebInputEvent::GestureLongPress) {
2238 UpdateTextInputState(SHOW_IME_IF_NEEDED);
2239 }
2240#endif
2241}
2242
[email protected]f103ab72009-09-02 17:10:592243void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:502244 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292245 size_t i = 0;
2246 for (; i < plugin_window_moves_.size(); ++i) {
2247 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582248 if (move.rects_valid) {
2249 plugin_window_moves_[i] = move;
2250 } else {
2251 plugin_window_moves_[i].visible = move.visible;
2252 }
initial.commit09911bf2008-07-26 23:55:292253 break;
2254 }
2255 }
2256
2257 if (i == plugin_window_moves_.size())
2258 plugin_window_moves_.push_back(move);
2259}
[email protected]268654772009-08-06 23:02:042260
2261void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2262 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2263 i != plugin_window_moves_.end(); ++i) {
2264 if (i->window == window) {
2265 plugin_window_moves_.erase(i);
2266 break;
2267 }
2268 }
2269}
[email protected]67bfb83f2011-09-22 03:36:372270
[email protected]b63d58d2012-11-26 22:37:442271void RenderWidget::GetRenderingStats(
2272 WebKit::WebRenderingStatsImpl& stats) const {
[email protected]ba91a792013-02-06 09:48:282273 if (compositor_)
[email protected]635353c2013-03-06 09:11:202274 compositor_->GetRenderingStats(&stats.rendering_stats);
[email protected]b63d58d2012-11-26 22:37:442275
[email protected]62049562013-03-24 00:39:012276 stats.rendering_stats.animation_frame_count +=
2277 software_stats_.animation_frame_count;
2278 stats.rendering_stats.screen_frame_count +=
2279 software_stats_.screen_frame_count;
2280 stats.rendering_stats.total_paint_time +=
2281 software_stats_.total_paint_time;
2282 stats.rendering_stats.total_pixels_painted +=
2283 software_stats_.total_pixels_painted;
[email protected]fef5e3972012-08-07 03:59:472284}
2285
[email protected]e9ff79c2012-10-19 21:31:262286bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:522287 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
2288 if (!gpu_channel)
2289 return false;
2290
2291 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
2292}
2293
[email protected]24ed0432013-04-24 07:50:312294RenderWidgetCompositor* RenderWidget::compositor() const {
2295 return compositor_.get();
2296}
2297
[email protected]0c2ebef2013-04-03 12:14:102298void RenderWidget::BeginSmoothScroll(
[email protected]0e241b4b2012-08-18 09:06:272299 bool down,
[email protected]ebd8b562012-10-09 14:44:292300 const SmoothScrollCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:192301 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:292302 int mouse_event_x,
2303 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:272304 DCHECK(!callback.is_null());
[email protected]267909d2012-10-20 04:36:192305
2306 ViewHostMsg_BeginSmoothScroll_Params params;
2307 params.scroll_down = down;
2308 params.pixels_to_scroll = pixels_to_scroll;
2309 params.mouse_event_x = mouse_event_x;
2310 params.mouse_event_y = mouse_event_y;
2311
[email protected]4a9dba42013-04-29 18:24:222312 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, params));
2313 pending_smooth_scroll_gesture_ = callback;
[email protected]a39ca1652012-07-13 21:30:582314}
2315
[email protected]67bfb83f2011-09-22 03:36:372316bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
2317 return false;
2318}
[email protected]c3d45532011-10-07 19:20:402319
[email protected]41d86852012-11-07 12:23:242320bool RenderWidget::WillHandleGestureEvent(
2321 const WebKit::WebGestureEvent& event) {
2322 return false;
2323}
2324
[email protected]ce6689f2013-03-29 12:52:552325void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2326 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2327}
2328
[email protected]3d5c243b2012-11-30 00:26:012329bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2330 return true;
2331}
2332
[email protected]3ae68c52013-04-12 06:10:052333WebGraphicsContext3DCommandBufferImpl* RenderWidget::CreateGraphicsContext3D(
[email protected]92fd8c02013-03-29 08:54:152334 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
[email protected]ed7defa2013-03-12 21:29:592335 if (!webwidget_)
2336 return NULL;
[email protected]8f746982013-03-21 06:28:032337 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
2338 new WebGraphicsContext3DCommandBufferImpl(
2339 surface_id(),
2340 GetURLForGraphicsContext3D(),
2341 RenderThreadImpl::current(),
2342 weak_ptr_factory_.GetWeakPtr()));
[email protected]ed7defa2013-03-12 21:29:592343
[email protected]8f746982013-03-21 06:28:032344 if (!context->Initialize(
2345 attributes,
2346 false /* bind generates resources */,
2347 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
2348 return NULL;
2349 return context.release();
[email protected]ed7defa2013-03-12 21:29:592350}
2351
[email protected]e9ff79c2012-10-19 21:31:262352} // namespace content