blob: 44d0a2dae54cfac1a6db2ccd0a8dad02d3696ad3 [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]74ebfb12013-06-07 20:48:0015#include "base/strings/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]66fca5bc2013-05-23 06:58:2932#include "content/renderer/ime_event_guard.h"
[email protected]8704f89b2011-04-15 00:30:0533#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4434#include "content/renderer/render_thread_impl.h"
[email protected]8d6cba42011-09-02 10:05:1935#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]484955942010-08-19 16:13:1836#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4837#include "skia/ext/platform_canvas.h"
[email protected]5c30b5e02013-05-30 03:46:0838#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
39#include "third_party/WebKit/public/platform/WebPoint.h"
40#include "third_party/WebKit/public/platform/WebRect.h"
41#include "third_party/WebKit/public/platform/WebSize.h"
42#include "third_party/WebKit/public/platform/WebString.h"
[email protected]8bd0fe62011-01-17 06:44:3743#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
[email protected]4b1146bc2012-07-10 18:46:0344#include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h"
[email protected]a7547fb2012-03-08 04:43:4445#include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h"
[email protected]8bd0fe62011-01-17 06:44:3746#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
47#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
[email protected]d4cff272011-05-02 15:46:0148#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:3749#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
[email protected]d353541f2012-05-03 22:45:4150#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1351#include "ui/base/ui_base_switches.h"
[email protected]9b003482013-05-21 14:00:1752#include "ui/gfx/point.h"
[email protected]a25e25b2012-09-28 14:32:3753#include "ui/gfx/rect_conversions.h"
[email protected]4b01b962012-10-09 23:17:3554#include "ui/gfx/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4855#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2756#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4157#include "ui/surface/transport_dib.h"
[email protected]9ec87712013-05-24 23:23:5258#include "webkit/glue/cursor_utils.h"
[email protected]8c89e7792009-08-19 21:18:3459#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5060#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4661#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
[email protected]799fd732013-05-15 21:18:5262#include "webkit/renderer/compositor_bindings/web_rendering_stats_impl.h"
[email protected]661eb9d2009-02-03 02:11:4863
[email protected]eeb93112013-05-01 19:41:1064#if defined(OS_ANDROID)
[email protected]913d99a2013-05-31 07:16:0765#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]eeb93112013-05-01 19:41:1066#endif
67
[email protected]661eb9d2009-02-03 02:11:4868#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4969#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5270#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4171#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4872#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4473
[email protected]8bd0fe62011-01-17 06:44:3774#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2975
[email protected]fa7b1dc2010-06-23 17:53:0476using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3077using WebKit::WebCursorInfo;
[email protected]41d86852012-11-07 12:23:2478using WebKit::WebGestureEvent;
[email protected]62cb33cae2009-03-27 23:30:2279using WebKit::WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0680using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2881using WebKit::WebNavigationPolicy;
[email protected]a7547fb2012-03-08 04:43:4482using WebKit::WebPagePopup;
[email protected]e99ef6f2011-10-16 01:13:0083using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2884using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5985using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1886using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0187using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5288using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1989using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5290using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2891using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2492using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0493using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1894using WebKit::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:2695
[email protected]6a4d7f62013-01-07 21:32:1396namespace {
97const char* GetEventName(WebInputEvent::Type type) {
98#define CASE_TYPE(t) case WebInputEvent::t: return #t
99 switch(type) {
100 CASE_TYPE(Undefined);
101 CASE_TYPE(MouseDown);
102 CASE_TYPE(MouseUp);
103 CASE_TYPE(MouseMove);
104 CASE_TYPE(MouseEnter);
105 CASE_TYPE(MouseLeave);
106 CASE_TYPE(ContextMenu);
107 CASE_TYPE(MouseWheel);
108 CASE_TYPE(RawKeyDown);
109 CASE_TYPE(KeyDown);
110 CASE_TYPE(KeyUp);
111 CASE_TYPE(Char);
112 CASE_TYPE(GestureScrollBegin);
113 CASE_TYPE(GestureScrollEnd);
114 CASE_TYPE(GestureScrollUpdate);
115 CASE_TYPE(GestureFlingStart);
116 CASE_TYPE(GestureFlingCancel);
117 CASE_TYPE(GestureTap);
[email protected]1c43b0a2013-05-10 07:43:23118 CASE_TYPE(GestureTapUnconfirmed);
[email protected]6a4d7f62013-01-07 21:32:13119 CASE_TYPE(GestureTapDown);
120 CASE_TYPE(GestureTapCancel);
121 CASE_TYPE(GestureDoubleTap);
122 CASE_TYPE(GestureTwoFingerTap);
123 CASE_TYPE(GestureLongPress);
124 CASE_TYPE(GestureLongTap);
125 CASE_TYPE(GesturePinchBegin);
126 CASE_TYPE(GesturePinchEnd);
127 CASE_TYPE(GesturePinchUpdate);
128 CASE_TYPE(TouchStart);
129 CASE_TYPE(TouchMove);
130 CASE_TYPE(TouchEnd);
131 CASE_TYPE(TouchCancel);
[email protected]3ec08ed2013-01-11 15:59:57132 default:
133 // Must include default to let WebKit::WebInputEvent add new event types
134 // before they're added here.
135 DLOG(WARNING) << "Unhandled WebInputEvent type in GetEventName.\n";
136 break;
[email protected]6a4d7f62013-01-07 21:32:13137 }
138#undef CASE_TYPE
[email protected]3ec08ed2013-01-11 15:59:57139 return "";
[email protected]6a4d7f62013-01-07 21:32:13140}
141}
[email protected]e9ff79c2012-10-19 21:31:26142namespace content {
[email protected]62cb33cae2009-03-27 23:30:22143
[email protected]6fd35b72012-03-01 19:46:41144RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]842f10652012-06-06 01:54:04145 const WebKit::WebScreenInfo& screen_info,
[email protected]14392a52012-05-02 20:28:44146 bool swapped_out)
initial.commit09911bf2008-07-26 23:55:29147 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56148 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:11149 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:29150 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30151 init_complete_(false),
[email protected]b4d08452010-10-05 17:34:35152 current_paint_buf_(NULL),
[email protected]d9083762013-03-24 01:36:40153 overdraw_bottom_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29154 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:06155 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:05156 update_reply_pending_(false),
[email protected]847a2582013-03-09 02:29:51157 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09158 need_update_rect_for_auto_resize_(false),
[email protected]65225772011-05-12 21:10:24159 using_asynchronous_swapbuffers_(false),
160 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:29161 did_show_(false),
initial.commit09911bf2008-07-26 23:55:29162 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:09163 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:29164 needs_repainting_on_restore_(false),
165 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49166 handling_input_event_(false),
[email protected]e8f775f2013-02-14 21:00:50167 handling_ime_event_(false),
[email protected]661eb9d2009-02-03 02:11:48168 closing_(false),
[email protected]14392a52012-05-02 20:28:44169 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04170 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45171 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
172 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12173 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48174 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12175 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50176 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21177 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07178 invalidation_task_posted_(false),
[email protected]842f10652012-06-06 01:54:04179 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52180 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]0e241b4b2012-08-18 09:06:27181 throttle_input_events_(true),
[email protected]ed7defa2013-03-12 21:29:59182 is_threaded_compositing_enabled_(false),
[email protected]a2b5ded2013-05-20 21:32:53183 overscroll_notifications_enabled_(false),
[email protected]69e797f2013-04-30 01:10:22184 weak_ptr_factory_(this) {
[email protected]8b3f0eb2012-05-03 19:15:05185 if (!swapped_out)
186 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27187 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18188 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
189 switches::kDisableGpuVsync);
[email protected]cb6430932012-10-31 00:53:36190 is_threaded_compositing_enabled_ =
191 CommandLine::ForCurrentProcess()->HasSwitch(
192 switches::kEnableThreadedCompositing);
[email protected]a2b5ded2013-05-20 21:32:53193 overscroll_notifications_enabled_ =
194 CommandLine::ForCurrentProcess()->HasSwitch(
195 switches::kEnableOverscrollNotifications);
initial.commit09911bf2008-07-26 23:55:29196}
197
198RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11199 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21200 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35201 if (current_paint_buf_) {
202 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
203 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29204 }
[email protected]992db4c2011-05-12 15:37:15205 // If we are swapped out, we have released already.
206 if (!is_swapped_out_)
207 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29208}
209
[email protected]484955942010-08-19 16:13:18210// static
[email protected]8085dbc82008-09-26 22:53:44211RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:04212 WebKit::WebPopupType popup_type,
213 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29214 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41215 scoped_refptr<RenderWidget> widget(
[email protected]842f10652012-06-06 01:54:04216 new RenderWidget(popup_type, screen_info, false));
[email protected]a635f942012-12-07 10:34:29217 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46218 return widget.get();
[email protected]a635f942012-12-07 10:34:29219 }
220 return NULL;
initial.commit09911bf2008-07-26 23:55:29221}
222
[email protected]484955942010-08-19 16:13:18223// static
224WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
225 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03226 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18227 break;
228 case WebKit::WebPopupTypeSelect:
229 case WebKit::WebPopupTypeSuggestion:
230 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44231 case WebKit::WebPopupTypePage:
232 return WebPagePopup::create(render_widget);
[email protected]4b1146bc2012-07-10 18:46:03233 case WebKit::WebPopupTypeHelperPlugin:
234 return WebKit::WebHelperPlugin::create(render_widget);
[email protected]484955942010-08-19 16:13:18235 default:
236 NOTREACHED();
237 }
238 return NULL;
239}
240
[email protected]a635f942012-12-07 10:34:29241bool RenderWidget::Init(int32 opener_id) {
242 return DoInit(opener_id,
243 RenderWidget::CreateWebWidget(this),
244 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
245 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18246}
247
[email protected]a635f942012-12-07 10:34:29248bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06249 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18250 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29251 DCHECK(!webwidget_);
252
253 if (opener_id != MSG_ROUTING_NONE)
254 opener_id_ = opener_id;
255
[email protected]484955942010-08-19 16:13:18256 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29257
[email protected]380244092011-10-07 17:26:27258 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29259 if (result) {
[email protected]380244092011-10-07 17:26:27260 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29261 // Take a reference on behalf of the RenderThread. This will be balanced
262 // when we receive ViewMsg_Close.
263 AddRef();
[email protected]a635f942012-12-07 10:34:29264 return true;
initial.commit09911bf2008-07-26 23:55:29265 } else {
[email protected]a635f942012-12-07 10:34:29266 // The above Send can fail when the tab is closing.
267 return false;
initial.commit09911bf2008-07-26 23:55:29268 }
269}
270
[email protected]fc4404d2012-11-07 19:53:30271// This is used to complete pending inits and non-pending inits.
272void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29273 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29274
[email protected]fc4404d2012-11-07 19:53:30275 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42276
[email protected]8926c602013-01-23 05:32:06277 if (webwidget_ && is_threaded_compositing_enabled_) {
278 webwidget_->enterForceCompositingMode(true);
279 }
[email protected]ba91a792013-02-06 09:48:28280 if (compositor_) {
281 compositor_->setSurfaceReady();
[email protected]479b0172012-10-29 19:27:09282 }
[email protected]05a980d7a2012-02-07 22:16:42283 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29284
[email protected]6de74452009-02-25 18:04:59285 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29286}
287
[email protected]992db4c2011-05-12 15:37:15288void RenderWidget::SetSwappedOut(bool is_swapped_out) {
289 // We should only toggle between states.
290 DCHECK(is_swapped_out_ != is_swapped_out);
291 is_swapped_out_ = is_swapped_out;
292
293 // If we are swapping out, we will call ReleaseProcess, allowing the process
294 // to exit if all of its RenderViews are swapped out. We wait until the
295 // WasSwappedOut call to do this, to avoid showing the sad tab.
296 // If we are swapping in, we call AddRefProcess to prevent the process from
297 // exiting.
298 if (!is_swapped_out)
299 RenderProcess::current()->AddRefProcess();
300}
301
[email protected]34bb3ac2013-03-08 02:41:28302bool RenderWidget::AllowPartialSwap() const {
303 return true;
304}
305
[email protected]c8cbae72013-05-23 10:45:03306bool RenderWidget::UsingSynchronousRendererCompositor() const {
[email protected]ccc1722e2013-05-06 19:43:07307#if defined(OS_ANDROID)
[email protected]913d99a2013-05-31 07:16:07308 return SynchronousCompositorFactory::GetInstance() != NULL;
309#else
[email protected]ccc1722e2013-05-06 19:43:07310 return false;
[email protected]913d99a2013-05-31 07:16:07311#endif
[email protected]ccc1722e2013-05-06 19:43:07312}
313
[email protected]a95986a82010-12-24 06:19:28314bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
315 bool handled = true;
316 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15317 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22318 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
319 OnCursorVisibilityChange)
[email protected]c084330e02013-04-27 01:08:15320 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
321 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]a95986a82010-12-24 06:19:28322 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
323 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
324 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54325 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28326 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41327 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]992db4c2011-05-12 15:37:15328 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28329 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]ed7defa2013-03-12 21:29:59330 IPC_MESSAGE_HANDLER(ViewMsg_SwapBuffers_ACK,
331 OnViewContextSwapBuffersComplete)
[email protected]a95986a82010-12-24 06:19:28332 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
333 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
334 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]3d9ec5052013-01-02 22:05:25335 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnPaintAtSize)
336 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
337 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, OnSmoothScrollCompleted)
[email protected]a95986a82010-12-24 06:19:28338 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
339 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03340 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]105dffb42013-02-20 03:46:21341#if defined(OS_ANDROID)
342 IPC_MESSAGE_HANDLER(ViewMsg_ImeBatchStateChanged, OnImeBatchStateChanged)
[email protected]2384b6c2013-02-28 23:58:51343 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21344#endif
[email protected]51a49502013-03-23 01:50:19345 IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot)
[email protected]3639aa82013-06-04 11:00:04346 IPC_MESSAGE_HANDLER(ViewMsg_SetBrowserRenderingStats,
347 OnSetBrowserRenderingStats)
[email protected]a95986a82010-12-24 06:19:28348 IPC_MESSAGE_UNHANDLED(handled = false)
349 IPC_END_MESSAGE_MAP()
350 return handled;
351}
initial.commit09911bf2008-07-26 23:55:29352
353bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15354 // Don't send any messages after the browser has told us to close, and filter
355 // most outgoing messages while swapped out.
356 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26357 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11358 closing_) {
initial.commit09911bf2008-07-26 23:55:29359 delete message;
360 return false;
361 }
362
363 // If given a messsage without a routing ID, then assign our routing ID.
364 if (message->routing_id() == MSG_ROUTING_NONE)
365 message->set_routing_id(routing_id_);
366
[email protected]380244092011-10-07 17:26:27367 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44368}
369
[email protected]61e2b3cc2012-03-02 16:13:34370void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44371 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40372 float overdraw_bottom_height,
[email protected]61e2b3cc2012-03-02 16:13:34373 const gfx::Rect& resizer_rect,
374 bool is_fullscreen,
375 ResizeAck resize_ack) {
[email protected]1c0008842013-06-06 08:35:48376 if (!RenderThreadImpl::current() || // Will be NULL during unit tests.
377 !RenderThreadImpl::current()->layout_test_mode()) {
378 // A resize ack shouldn't be requested if we have not ACK'd the previous
379 // one.
380 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
381 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
382 }
initial.commit09911bf2008-07-26 23:55:29383
[email protected]61e2b3cc2012-03-02 16:13:34384 // Ignore this during shutdown.
385 if (!webwidget_)
386 return;
387
[email protected]d9083762013-03-24 01:36:40388 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44389 compositor_->setViewportSize(new_size, physical_backing_size);
[email protected]d9083762013-03-24 01:36:40390 compositor_->SetOverdrawBottomHeight(overdraw_bottom_height);
391 }
[email protected]60d47ac2013-03-01 23:42:44392
[email protected]dade8992013-03-04 07:34:34393 physical_backing_size_ = physical_backing_size;
[email protected]d9083762013-03-24 01:36:40394 overdraw_bottom_height_ = overdraw_bottom_height;
[email protected]61e2b3cc2012-03-02 16:13:34395 resizer_rect_ = resizer_rect;
396
397 // NOTE: We may have entered fullscreen mode without changing our size.
398 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
399 if (fullscreen_change)
400 WillToggleFullscreen();
401 is_fullscreen_ = is_fullscreen;
402
403 if (size_ != new_size) {
404 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34405 needs_repainting_on_restore_ = false;
406
407 size_ = new_size;
408
409 paint_aggregator_.ClearPendingUpdate();
410
411 // When resizing, we want to wait to paint before ACK'ing the resize. This
412 // ensures that we only resize as fast as we can paint. We only need to
413 // send an ACK if we are resized to a non-empty rect.
414 webwidget_->resize(new_size);
[email protected]0b70dbe2013-05-10 19:06:32415
416 // Resize should have caused an invalidation of the entire view.
417 DCHECK(new_size.IsEmpty() || is_accelerated_compositing_active_ ||
418 paint_aggregator_.HasPendingUpdate());
[email protected]1c0008842013-06-06 08:35:48419 } else if (!RenderThreadImpl::current() || // Will be NULL during unit tests.
420 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]632c4382013-05-15 08:58:45421 resize_ack = NO_RESIZE_ACK;
422 }
423
424 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
425 // For empty size or empty physical_backing_size, there is no next paint
426 // (along with which to send the ack) until they are set to non-empty.
[email protected]ff475a322012-03-14 00:05:35427 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34428 }
429
[email protected]20fbfc22013-05-08 20:50:58430 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45431 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58432 set_next_paint_is_resize_ack();
433
[email protected]61e2b3cc2012-03-02 16:13:34434 if (fullscreen_change)
435 DidToggleFullscreen();
436
437 // If a resize ack is requested and it isn't set-up, then no more resizes will
438 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45439 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29440}
441
442void RenderWidget::OnClose() {
443 if (closing_)
444 return;
445 closing_ = true;
446
447 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03448 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27449 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03450 SetHidden(false);
451 }
initial.commit09911bf2008-07-26 23:55:29452
initial.commit09911bf2008-07-26 23:55:29453 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25454 // now. Post a task that only gets invoked when there are no nested message
455 // loops.
[email protected]dd32b1272013-05-04 14:17:11456 base::MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29457 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25458
459 // Balances the AddRef taken when we called AddRoute.
460 Release();
initial.commit09911bf2008-07-26 23:55:29461}
462
[email protected]61e2b3cc2012-03-02 16:13:34463// Got a response from the browser after the renderer decided to create a new
464// view.
[email protected]fc4404d2012-11-07 19:53:30465void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34466 DCHECK(routing_id_ != MSG_ROUTING_NONE);
467
[email protected]fc4404d2012-11-07 19:53:30468 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34469}
470
[email protected]0fdd5012013-05-29 08:05:56471void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
472 screen_info_ = params.screen_info;
473 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
474 Resize(params.new_size, params.physical_backing_size,
475 params.overdraw_bottom_height, params.resizer_rect,
476 params.is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29477}
478
[email protected]b5913d72012-02-07 22:26:54479void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
480 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59481 gfx::Rect view_rect(size_);
482
[email protected]ce112fe2012-10-29 22:52:18483 gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_);
[email protected]b9769d82012-02-10 00:23:59484 if (!old_damage_rect.IsEmpty())
485 paint_aggregator_.InvalidateRect(old_damage_rect);
486
[email protected]ce112fe2012-10-29 22:52:18487 gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect);
[email protected]b9769d82012-02-10 00:23:59488 if (!new_damage_rect.IsEmpty())
489 paint_aggregator_.InvalidateRect(new_damage_rect);
490
[email protected]b5913d72012-02-07 22:26:54491 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59492
[email protected]b5913d72012-02-07 22:26:54493 if (webwidget_)
494 webwidget_->didChangeWindowResizerRect();
495 }
496}
497
initial.commit09911bf2008-07-26 23:55:29498void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31499 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29500 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03501 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29502}
503
[email protected]9e2e4632012-07-27 16:38:41504void RenderWidget::OnWasShown(bool needs_repainting) {
505 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29506 // During shutdown we can just ignore this message.
507 if (!webwidget_)
508 return;
509
510 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03511 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29512
513 if (!needs_repainting && !needs_repainting_on_restore_)
514 return;
515 needs_repainting_on_restore_ = false;
516
[email protected]d65adb12010-04-28 17:26:49517 // Tag the next paint as a restore ack, which is picked up by
518 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29519 set_next_paint_is_restore_ack();
520
521 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56522 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46523 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
524 } else {
525 scheduleComposite();
526 }
initial.commit09911bf2008-07-26 23:55:29527}
528
[email protected]992db4c2011-05-12 15:37:15529void RenderWidget::OnWasSwappedOut() {
530 // If we have been swapped out and no one else is using this process,
531 // it's safe to exit now. If we get swapped back in, we will call
532 // AddRefProcess in SetSwappedOut.
533 if (is_swapped_out_)
534 RenderProcess::current()->ReleaseProcess();
535}
536
[email protected]53d3f302009-12-21 04:42:05537void RenderWidget::OnRequestMoveAck() {
538 DCHECK(pending_window_rect_count_);
539 pending_window_rect_count_--;
540}
541
542void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58543 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21544 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05545 update_reply_pending_ = false;
546
[email protected]b4d08452010-10-05 17:34:35547 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
548 // have no current paint buffer.
549 if (current_paint_buf_) {
550 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
551 current_paint_buf_ = NULL;
552 }
553
[email protected]65225772011-05-12 21:10:24554 // If swapbuffers is still pending, then defer the update until the
555 // swapbuffers occurs.
556 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
557 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
558 return;
559 }
560
[email protected]29ed96a2012-02-04 18:12:16561 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18562 if (!is_accelerated_compositing_active_) {
563 DidFlushPaint();
564 }
[email protected]a2f6bc112009-06-27 16:27:25565
initial.commit09911bf2008-07-26 23:55:29566 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24567 DoDeferredUpdateAndSendInputAck();
568}
569
[email protected]d0be63772011-12-20 23:18:04570bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]ed7defa2013-03-12 21:29:59571 // Contexts using the command buffer support asynchronous swapbuffers.
572 // See RenderWidget::CreateOutputSurface().
[email protected]8f746982013-03-21 06:28:03573 if (RenderThreadImpl::current()->compositor_message_loop_proxy())
[email protected]ed7defa2013-03-12 21:29:59574 return false;
575
576 return true;
577}
578
579GURL RenderWidget::GetURLForGraphicsContext3D() {
580 return GURL();
[email protected]65225772011-05-12 21:10:24581}
582
[email protected]479b0172012-10-29 19:27:09583bool RenderWidget::ForceCompositingModeEnabled() {
584 return false;
585}
586
[email protected]ba91a792013-02-06 09:48:28587scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface() {
[email protected]c3e32ed42013-05-02 05:07:13588 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]a1811b8912013-05-09 15:35:19589
590#if defined(OS_ANDROID)
[email protected]913d99a2013-05-31 07:16:07591 if (SynchronousCompositorFactory* factory =
592 SynchronousCompositorFactory::GetInstance()) {
593 return factory->CreateOutputSurface(routing_id());
[email protected]a1811b8912013-05-09 15:35:19594 }
595#endif
596
[email protected]8bbe3a92013-05-12 00:58:35597 if (command_line.HasSwitch(switches::kEnableSoftwareCompositingGLAdapter)) {
598 return scoped_ptr<cc::OutputSurface>(
599 new CompositorOutputSurface(routing_id(), NULL,
600 new CompositorSoftwareOutputDevice()));
601 }
602
[email protected]ed7defa2013-03-12 21:29:59603 // Explicitly disable antialiasing for the compositor. As of the time of
604 // this writing, the only platform that supported antialiasing for the
605 // compositor was Mac OS X, because the on-screen OpenGL context creation
606 // code paths on Windows and Linux didn't yet have multisampling support.
607 // Mac OS X essentially always behaves as though it's rendering offscreen.
608 // Multisampling has a heavy cost especially on devices with relatively low
609 // fill rate like most notebooks, and the Mac implementation would need to
610 // be optimized to resolve directly into the IOSurface shared between the
611 // GPU and browser processes. For these reasons and to avoid platform
612 // disparities we explicitly disable antialiasing.
613 WebKit::WebGraphicsContext3D::Attributes attributes;
614 attributes.antialias = false;
615 attributes.shareResources = true;
616 attributes.noAutomaticFlushes = true;
[email protected]a6886502013-05-16 20:59:18617 attributes.depth = false;
618 attributes.stencil = false;
[email protected]bec084292013-05-21 21:31:44619 if (command_line.HasSwitch(cc::switches::kForceDirectLayerDrawing))
620 attributes.stencil = true;
[email protected]3ae68c52013-04-12 06:10:05621 WebGraphicsContext3DCommandBufferImpl* context =
622 CreateGraphicsContext3D(attributes);
[email protected]8bbe3a92013-05-12 00:58:35623 if (!context)
624 return scoped_ptr<cc::OutputSurface>();
[email protected]ed7defa2013-03-12 21:29:59625
[email protected]2847b222013-04-06 00:59:24626 bool composite_to_mailbox =
[email protected]7b45b5762013-05-08 14:36:56627 command_line.HasSwitch(cc::switches::kCompositeToMailbox) &&
628 !command_line.HasSwitch(switches::kEnableDelegatedRenderer);
[email protected]2847b222013-04-06 00:59:24629 // No swap throttling yet when compositing on the main thread.
630 DCHECK(!composite_to_mailbox || is_threaded_compositing_enabled_);
631 return scoped_ptr<cc::OutputSurface>(composite_to_mailbox ?
632 new MailboxOutputSurface(routing_id(), context, NULL) :
633 new CompositorOutputSurface(routing_id(), context, NULL));
[email protected]ba91a792013-02-06 09:48:28634}
635
[email protected]ed7defa2013-03-12 21:29:59636void RenderWidget::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24637 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21638 while (!updates_pending_swap_.empty()) {
639 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
640 updates_pending_swap_.pop_front();
641 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
642 // compositing pass, hence doesn't require an UpdateRect message.
643 if (msg)
644 Send(msg);
645 }
[email protected]65225772011-05-12 21:10:24646 num_swapbuffers_complete_pending_ = 0;
647 using_asynchronous_swapbuffers_ = false;
648 // Schedule another frame so the compositor learns about it.
649 scheduleComposite();
650}
651
[email protected]ed7defa2013-03-12 21:29:59652void RenderWidget::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:08653 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21654
655 if (using_asynchronous_swapbuffers_) {
656 ViewHostMsg_UpdateRect* msg = NULL;
657 // pending_update_params_ can be NULL if the swap doesn't correspond to an
658 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
659 // message.
[email protected]59383c782013-04-17 16:43:27660 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:21661 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
662 pending_update_params_.reset();
663 }
664 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08665 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21666 }
[email protected]37a6f302011-07-11 23:43:08667}
668
[email protected]ed7defa2013-03-12 21:29:59669void RenderWidget::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24670 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16671
[email protected]404939f2012-06-01 04:06:18672 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16673 DidFlushPaint();
674
[email protected]65225772011-05-12 21:10:24675 // When compositing deactivates, we reset the swapbuffers pending count. The
676 // swapbuffers acks may still arrive, however.
677 if (num_swapbuffers_complete_pending_ == 0) {
678 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
679 return;
680 }
[email protected]aa4117f2011-12-09 22:19:21681 DCHECK(!updates_pending_swap_.empty());
682 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
683 updates_pending_swap_.pop_front();
684 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
685 // compositing pass, hence doesn't require an UpdateRect message.
686 if (msg)
687 Send(msg);
[email protected]65225772011-05-12 21:10:24688 num_swapbuffers_complete_pending_--;
689
690 // If update reply is still pending, then defer the update until that reply
691 // occurs.
[email protected]d0be63772011-12-20 23:18:04692 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24693 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
694 return;
695 }
696
697 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06698 // when we were previously rendering. However, if an invalidation task is not
699 // posted, there may be software rendering work pending. In that case, don't
700 // early out.
701 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24702 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
703 return;
704 }
705
[email protected]cc66e682012-10-02 06:48:18706 // Do not call DoDeferredUpdate unless there's animation work to be done or
707 // a real invalidation. This prevents rendering in response to a swapbuffers
708 // callback coming back after we've navigated away from the page that
709 // generated it.
710 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
711 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
712 return;
713 }
714
[email protected]65225772011-05-12 21:10:24715 // Continue painting if necessary...
716 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29717}
718
[email protected]0dea1652012-12-14 00:09:09719void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
[email protected]4b157662013-05-29 04:05:05720 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:09721 bool is_keyboard_shortcut) {
[email protected]5dd768212009-08-13 23:34:49722 handling_input_event_ = true;
[email protected]0dea1652012-12-14 00:09:09723 if (!input_event) {
[email protected]5dd768212009-08-13 23:34:49724 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29725 return;
[email protected]5dd768212009-08-13 23:34:49726 }
initial.commit09911bf2008-07-26 23:55:29727
[email protected]b4841e1c2013-05-16 22:30:10728 const char* const event_name = GetEventName(input_event->type);
729 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent",
730 "event", event_name);
731
[email protected]c2eaa8f2013-05-10 02:41:55732 if (compositor_)
733 compositor_->SetLatencyInfo(latency_info);
[email protected]256737c2013-06-08 04:39:10734 else
735 latency_info_.MergeWith(latency_info);
[email protected]c2eaa8f2013-05-10 02:41:55736
[email protected]6a4d7f62013-01-07 21:32:13737 base::TimeDelta now = base::TimeDelta::FromInternalValue(
738 base::TimeTicks::Now().ToInternalValue());
739
740 int64 delta = static_cast<int64>(
741 (now.InSecondsF() - input_event->timeStampSeconds) *
742 base::Time::kMicrosecondsPerSecond);
743 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer", delta, 0, 1000000, 100);
[email protected]de415552013-01-23 04:12:17744 base::HistogramBase* counter_for_type =
[email protected]bafdc5d52013-02-27 18:18:48745 base::Histogram::FactoryGet(
[email protected]b4841e1c2013-05-16 22:30:10746 base::StringPrintf("Event.Latency.Renderer.%s", event_name),
[email protected]bafdc5d52013-02-27 18:18:48747 0,
748 1000000,
[email protected]6a4d7f62013-01-07 21:32:13749 100,
[email protected]de415552013-01-23 04:12:17750 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]bafdc5d52013-02-27 18:18:48751 counter_for_type->Add(delta);
[email protected]6a4d7f62013-01-07 21:32:13752
[email protected]67bfb83f2011-09-22 03:36:37753 bool prevent_default = false;
754 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26755 const WebMouseEvent& mouse_event =
756 *static_cast<const WebMouseEvent*>(input_event);
757 TRACE_EVENT2("renderer", "HandleMouseMove",
758 "x", mouse_event.x, "y", mouse_event.y);
759 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37760 }
761
[email protected]41d86852012-11-07 12:23:24762 if (WebInputEvent::isGestureEventType(input_event->type)) {
763 const WebGestureEvent& gesture_event =
764 *static_cast<const WebGestureEvent*>(input_event);
765 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
766 }
767
[email protected]3ebcc7c2013-01-09 05:34:46768 if (input_event->type == WebInputEvent::GestureTap ||
769 input_event->type == WebInputEvent::GestureLongPress)
770 resetInputMethod();
771
[email protected]67bfb83f2011-09-22 03:36:37772 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12773 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
774 suppress_next_char_events_ = false;
775 if (!processed && webwidget_)
776 processed = webwidget_->handleInputEvent(*input_event);
777 }
778
779 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
780 // it's not processed by webkit, then we need to suppress the upcoming Char
781 // events.
782 if (!processed && is_keyboard_shortcut)
783 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29784
[email protected]3d5c243b2012-11-30 00:26:01785 InputEventAckState ack_result = processed ?
786 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
787 if (!processed && input_event->type == WebInputEvent::TouchStart) {
788 const WebTouchEvent& touch_event =
789 *static_cast<const WebTouchEvent*>(input_event);
790 ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ?
791 INPUT_EVENT_ACK_STATE_NOT_CONSUMED :
792 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
793 }
794
[email protected]a9fb30aa2011-10-06 06:58:46795 IPC::Message* response =
[email protected]c084330e02013-04-27 01:08:15796 new InputHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
797 ack_result);
[email protected]3391a0772012-03-28 00:32:07798 bool event_type_gets_rate_limited =
799 input_event->type == WebInputEvent::MouseMove ||
800 input_event->type == WebInputEvent::MouseWheel ||
801 WebInputEvent::isTouchEventType(input_event->type);
[email protected]8926c602013-01-23 05:32:06802
803 bool frame_pending = paint_aggregator_.HasPendingUpdate();
804 if (is_accelerated_compositing_active_) {
[email protected]ba91a792013-02-06 09:48:28805 frame_pending = compositor_ &&
806 compositor_->commitRequested();
[email protected]8926c602013-01-23 05:32:06807 }
808
[email protected]3391a0772012-03-28 00:32:07809 bool is_input_throttled =
[email protected]ce2b28e2012-08-09 15:53:57810 throttle_input_events_ &&
[email protected]8926c602013-01-23 05:32:06811 frame_pending;
[email protected]e2824412009-02-27 01:57:05812
[email protected]f8868d72012-04-27 19:13:03813 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24814 // We want to rate limit the input events in this case, so we'll wait for
815 // painting to finish before ACKing this message.
[email protected]59383c782013-04-17 16:43:27816 if (pending_input_event_ack_) {
[email protected]353a34c2010-05-28 23:35:17817 // As two different kinds of events could cause us to postpone an ack
818 // we send it now, if we have one pending. The Browser should never
819 // send us the same kind of event we are delaying the ack for.
820 Send(pending_input_event_ack_.release());
821 }
[email protected]12fbad812009-09-01 18:21:24822 pending_input_event_ack_.reset(response);
823 } else {
824 Send(response);
825 }
826
[email protected]3306f262012-09-21 19:20:42827#if defined(OS_ANDROID)
828 // Allow the IME to be shown when the focus changes as a consequence
829 // of a processed touch end event.
830 if (input_event->type == WebInputEvent::TouchEnd && processed)
831 UpdateTextInputState(SHOW_IME_IF_NEEDED);
832#endif
833
[email protected]5dd768212009-08-13 23:34:49834 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48835
[email protected]67bfb83f2011-09-22 03:36:37836 if (!prevent_default) {
837 if (WebInputEvent::isKeyboardEventType(input_event->type))
838 DidHandleKeyEvent();
839 if (WebInputEvent::isMouseEventType(input_event->type))
840 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24841 if (WebInputEvent::isTouchEventType(input_event->type))
842 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37843 }
initial.commit09911bf2008-07-26 23:55:29844}
845
[email protected]34202de2013-05-06 23:36:22846void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
847 if (webwidget_)
848 webwidget_->setCursorVisibilityState(is_visible);
849}
850
initial.commit09911bf2008-07-26 23:55:29851void RenderWidget::OnMouseCaptureLost() {
852 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28853 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29854}
855
856void RenderWidget::OnSetFocus(bool enable) {
857 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33858 if (webwidget_)
859 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29860}
861
862void RenderWidget::ClearFocus() {
863 // We may have got the focus from the browser before this gets processed, in
864 // which case we do not want to unfocus ourself.
865 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28866 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29867}
868
[email protected]2d5d09d52009-06-15 14:29:21869void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00870 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21871 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06872 TRACE_EVENT2("renderer", "PaintRect",
873 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:45874
875 const bool kEnableGpuBenchmarking =
876 CommandLine::ForCurrentProcess()->HasSwitch(
877 switches::kEnableGpuBenchmarking);
[email protected]4fb66842009-12-04 21:41:00878 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21879
880 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00881 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
882 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03883
[email protected]699ab0d2009-04-23 23:19:14884 // If there is a custom background, tile it.
885 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14886 SkPaint paint;
[email protected]4e29afd2012-12-04 04:07:11887 skia::RefPtr<SkShader> shader = skia::AdoptRef(
888 SkShader::CreateBitmapShader(background_,
889 SkShader::kRepeat_TileMode,
890 SkShader::kRepeat_TileMode));
891 paint.setShader(shader.get());
[email protected]fb10ec5b2011-10-24 17:54:20892
893 // Use kSrc_Mode to handle background_ transparency properly.
894 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
895
896 // Canvas could contain multiple update rects. Clip to given rect so that
897 // we don't accidentally clear other update rects.
898 canvas->save();
[email protected]aa7e7a12013-02-22 13:37:44899 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]1835b9e2012-02-28 13:12:48900 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14901 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20902 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14903 }
904
[email protected]719b36f2010-12-22 20:36:46905 // First see if this rect is a plugin that can paint itself faster.
906 TransportDIB* optimized_dib = NULL;
907 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:20908 float dib_scale_factor;
[email protected]719b36f2010-12-22 20:36:46909 webkit::ppapi::PluginInstance* optimized_instance =
910 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
911 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:20912 &optimized_copy_rect,
913 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:46914 if (optimized_instance) {
915 // This plugin can be optimize-painted and we can just ask it to paint
916 // itself. We don't actually need the TransportDIB in this case.
917 //
918 // This is an optimization for PPAPI plugins that know they're on top of
919 // the page content. If this rect is inside such a plugin, we can save some
920 // time and avoid re-rendering the page content which we know will be
921 // covered by the plugin later (this time can be significant, especially
922 // for a playing movie that is invalidating a lot).
923 //
924 // In the plugin movie case, hopefully the similar call to
925 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
926 // painting, because that avoids copying the plugin image to a different
927 // paint rect. Unfortunately, if anything on the page is animating other
928 // than the movie, it break this optimization since the union of the
929 // invalid regions will be larger than the plugin.
930 //
931 // This code optimizes that case, where we can still avoid painting in
932 // WebKit and filling the background (which can be slow) and just painting
933 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
934 // required.
[email protected]63ab54262012-11-09 15:58:45935 base::TimeTicks paint_begin_ticks;
936 if (kEnableGpuBenchmarking)
937 paint_begin_ticks = base::TimeTicks::HighResNow();
938
[email protected]df59dd42012-09-14 22:56:30939 SkAutoCanvasRestore auto_restore(canvas, true);
940 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]719b36f2010-12-22 20:36:46941 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27942 optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:21943 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45944 if (kEnableGpuBenchmarking) {
945 base::TimeDelta paint_time =
946 base::TimeTicks::HighResNow() - paint_begin_ticks;
947 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01948 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45949 }
[email protected]719b36f2010-12-22 20:36:46950 } else {
951 // Normal painting case.
[email protected]63ab54262012-11-09 15:58:45952 base::TimeTicks paint_begin_ticks;
953 if (kEnableGpuBenchmarking)
954 paint_begin_ticks = base::TimeTicks::HighResNow();
955
[email protected]719b36f2010-12-22 20:36:46956 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
[email protected]63ab54262012-11-09 15:58:45957
958 if (kEnableGpuBenchmarking) {
959 base::TimeDelta paint_time =
960 base::TimeTicks::HighResNow() - paint_begin_ticks;
961 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01962 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45963 }
[email protected]719b36f2010-12-22 20:36:46964
965 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35966 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46967 }
initial.commit09911bf2008-07-26 23:55:29968
[email protected]4fb66842009-12-04 21:41:00969 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00970 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45971
972 if (kEnableGpuBenchmarking) {
[email protected]63ab54262012-11-09 15:58:45973 int64 num_pixels_processed = rect.width() * rect.height();
[email protected]62049562013-03-24 00:39:01974 software_stats_.total_pixels_painted += num_pixels_processed;
[email protected]63ab54262012-11-09 15:58:45975 }
[email protected]4fb66842009-12-04 21:41:00976}
977
978void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
979 skia::PlatformCanvas* canvas) {
980 static bool kPaintBorder =
981 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
982 if (!kPaintBorder)
983 return;
984
[email protected]53d3f302009-12-21 04:42:05985 // Cycle through these colors to help distinguish new paint rects.
986 const SkColor colors[] = {
987 SkColorSetARGB(0x3F, 0xFF, 0, 0),
988 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
989 SkColorSetARGB(0x3F, 0, 0, 0xFF),
990 };
991 static int color_selector = 0;
992
[email protected]4fb66842009-12-04 21:41:00993 SkPaint paint;
994 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05995 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00996 paint.setStrokeWidth(1);
997
998 SkIRect irect;
999 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
1000 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:291001}
1002
[email protected]52ccd0ea2011-02-16 01:09:051003void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:301004 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:301005 if (!animation_update_pending_) {
1006 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:591007 return;
[email protected]921244e42011-07-20 16:36:301008 }
[email protected]bd37ae252011-06-03 01:28:181009 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:591010 // Record when we fired (according to base::Time::Now()) relative to when
1011 // we posted the task to quantify how much the base::Time/base::TimeTicks
1012 // skew is affecting animations.
1013 base::TimeDelta animation_callback_delay = base::Time::Now() -
1014 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
1015 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
1016 animation_callback_delay,
1017 base::TimeDelta::FromMilliseconds(0),
1018 base::TimeDelta::FromMilliseconds(30),
1019 25);
1020 }
[email protected]65225772011-05-12 21:10:241021 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:241022}
1023
[email protected]52ccd0ea2011-02-16 01:09:051024void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:591025 if (!animation_update_pending_)
1026 return;
[email protected]bd37ae252011-06-03 01:28:181027
1028 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:331029 base::TimeDelta animationInterval = IsRenderingVSynced() ?
1030 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:181031
[email protected]7c4329e2011-02-18 22:02:591032 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:451033
1034 // animation_floor_time_ is the earliest time that we should animate when
1035 // using the dead reckoning software scheduler. If we're using swapbuffers
1036 // complete callbacks to rate limit, we can ignore this floor.
1037 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:301038 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:331039 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:181040 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:591041 // running animation callbacks so that if a callback requests another
1042 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:381043 animation_timer_.Stop();
1044 animation_timer_.Start(FROM_HERE, animationInterval, this,
1045 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:591046 animation_update_pending_ = false;
[email protected]ba91a792013-02-06 09:48:281047 if (is_accelerated_compositing_active_ && compositor_) {
[email protected]635353c2013-03-06 09:11:201048 compositor_->Animate(base::TimeTicks::Now());
[email protected]8926c602013-01-23 05:32:061049 } else {
[email protected]635353c2013-03-06 09:11:201050 double frame_begin_time =
1051 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
1052 webwidget_->animate(frame_begin_time);
[email protected]8926c602013-01-23 05:32:061053 }
[email protected]7c4329e2011-02-18 22:02:591054 return;
[email protected]5f8b1022011-01-21 23:34:501055 }
[email protected]bd37ae252011-06-03 01:28:181056 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:381057 if (!animation_timer_.IsRunning()) {
1058 // This code uses base::Time::Now() to calculate the floor and next fire
1059 // time because javascript's Date object uses base::Time::Now(). The
1060 // message loop uses base::TimeTicks, which on windows can have a
1061 // different granularity than base::Time.
1062 // The upshot of all this is that this function might be called before
1063 // base::Time::Now() has advanced past the animation_floor_time_. To
1064 // avoid exposing this delay to javascript, we keep posting delayed
1065 // tasks until base::Time::Now() has advanced far enough.
1066 base::TimeDelta delay = animation_floor_time_ - now;
1067 animation_timer_.Start(FROM_HERE, delay, this,
1068 &RenderWidget::AnimationCallback);
1069 }
[email protected]5f8b1022011-01-21 23:34:501070}
1071
[email protected]bd37ae252011-06-03 01:28:181072bool RenderWidget::IsRenderingVSynced() {
1073 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
1074 // not caught by this check. This will lead to artificially low frame rates
1075 // for people who force vsync off at a driver level and expect Chrome to speed
1076 // up.
1077 return !has_disable_gpu_vsync_switch_;
1078}
1079
[email protected]65225772011-05-12 21:10:241080void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:061081 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:241082 invalidation_task_posted_ = false;
1083 DoDeferredUpdateAndSendInputAck();
1084}
1085
1086void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:051087 DoDeferredUpdate();
1088
[email protected]59383c782013-04-17 16:43:271089 if (pending_input_event_ack_)
[email protected]52ccd0ea2011-02-16 01:09:051090 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:211091}
1092
[email protected]552e6002009-11-19 05:24:571093void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:581094 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:081095
[email protected]65225772011-05-12 21:10:241096 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:291097 return;
[email protected]05a980d7a2012-02-07 22:16:421098
[email protected]fc4404d2012-11-07 19:53:301099 if (!init_complete_) {
1100 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:421101 return;
1102 }
[email protected]aa4117f2011-12-09 22:19:211103 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:241104 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
1105 return;
1106 }
[email protected]9ca84622011-06-02 23:46:391107 if (is_accelerated_compositing_active_ &&
1108 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:241109 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
1110 return;
1111 }
initial.commit09911bf2008-07-26 23:55:291112
[email protected]552e6002009-11-19 05:24:571113 // Suppress updating when we are hidden.
[email protected]e3d92a7f2013-01-10 02:35:051114 if (is_hidden_ || size_.IsEmpty() || is_swapped_out_) {
[email protected]552e6002009-11-19 05:24:571115 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:291116 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:241117 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:291118 return;
1119 }
1120
[email protected]05a980d7a2012-02-07 22:16:421121 if (is_accelerated_compositing_active_)
1122 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
1123
[email protected]0fb93f52011-05-18 23:13:561124 // Tracking of frame rate jitter
1125 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]38ce4e7b2013-02-23 06:17:371126 InstrumentWillBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:051127 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:501128
[email protected]f98d7e3c2010-09-13 22:30:461129 // Layout may generate more invalidation. It may also enable the
1130 // GPU acceleration, so make sure to run layout before we send the
1131 // GpuRenderingActivated message.
1132 webwidget_->layout();
1133
[email protected]dcca3aa92012-02-17 23:03:371134 // The following two can result in further layout and possibly
1135 // enable GPU acceleration so they need to be called before any painting
1136 // is done.
[email protected]3306f262012-09-21 19:20:421137 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]dcca3aa92012-02-17 23:03:371138 UpdateSelectionBounds();
1139
[email protected]5f8b1022011-01-21 23:34:501140 // Suppress painting if nothing is dirty. This has to be done after updating
1141 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:241142 if (!paint_aggregator_.HasPendingUpdate()) {
1143 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]38ce4e7b2013-02-23 06:17:371144 InstrumentDidCancelFrame();
[email protected]5f8b1022011-01-21 23:34:501145 return;
[email protected]65225772011-05-12 21:10:241146 }
[email protected]5f8b1022011-01-21 23:34:501147
[email protected]479b0172012-10-29 19:27:091148 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:361149 !is_threaded_compositing_enabled_ &&
[email protected]479b0172012-10-29 19:27:091150 ForceCompositingModeEnabled()) {
1151 webwidget_->enterForceCompositingMode(true);
1152 }
1153
[email protected]872ae5b2011-05-26 20:20:501154 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:561155 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:041156 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:561157 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
1158 delay,
1159 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411160 base::TimeDelta::FromMilliseconds(120),
1161 60);
[email protected]d0be63772011-12-20 23:18:041162 } else {
[email protected]0fb93f52011-05-18 23:13:561163 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
1164 delay,
1165 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411166 base::TimeDelta::FromMilliseconds(120),
1167 60);
[email protected]d0be63772011-12-20 23:18:041168 }
[email protected]872ae5b2011-05-26 20:20:501169
1170 // Calculate filtered time per frame:
1171 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
1172 filtered_time_per_frame_ =
1173 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:561174 }
1175 last_do_deferred_update_time_ = frame_begin_ticks;
1176
[email protected]fef5e3972012-08-07 03:59:471177 if (!is_accelerated_compositing_active_) {
[email protected]62049562013-03-24 00:39:011178 software_stats_.animation_frame_count++;
1179 software_stats_.screen_frame_count++;
[email protected]fef5e3972012-08-07 03:59:471180 }
1181
[email protected]552e6002009-11-19 05:24:571182 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:291183 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:301184 PaintAggregator::PendingUpdate update;
1185 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:291186
[email protected]53d3f302009-12-21 04:42:051187 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:181188 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:291189
[email protected]29ed96a2012-02-04 18:12:161190 // Notify derived classes that we're about to initiate a paint.
1191 WillInitiatePaint();
1192
[email protected]ca4847f2010-09-24 05:39:151193 // A plugin may be able to do an optimized paint. First check this, in which
1194 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:461195 // This optimization allows PPAPI plugins that declare themselves on top of
1196 // the page (like a traditional windowed plugin) to be able to animate (think
1197 // movie playing) without repeatedly re-painting the page underneath, or
1198 // copying the plugin backing store (since we can send the plugin's backing
1199 // store directly to the browser).
1200 //
1201 // This optimization only works when the entire invalid region is contained
1202 // within the plugin. There is a related optimization in PaintRect for the
1203 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:151204 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:151205 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201206 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:211207 DCHECK(!pending_update_params_.get());
1208 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551209 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211210 pending_update_params_->scroll_rect = update.scroll_rect;
1211 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211212 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1213 pending_update_params_->flags = next_paint_flags_;
1214 pending_update_params_->scroll_offset = GetScrollOffset();
1215 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091216 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211217 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091218 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211219
[email protected]256737c2013-06-08 04:39:101220 if (!is_accelerated_compositing_active_)
1221 pending_update_params_->latency_info = latency_info_;
1222
1223 latency_info_.Clear();
1224
[email protected]ca4847f2010-09-24 05:39:151225 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561226 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151227 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201228 &optimized_copy_rect,
1229 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271230 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471231 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211232 pending_update_params_->bitmap = dib->id();
1233 pending_update_params_->bitmap_rect = optimized_copy_location;
1234 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201235 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561236 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461237 // Compute a buffer for painting and cache it.
[email protected]4889bd212013-02-11 22:23:101238
1239 bool fractional_scale = device_scale_factor_ -
1240 static_cast<int>(device_scale_factor_) != 0;
1241 if (fractional_scale) {
1242 // Damage might not be DIP aligned. Inflate damage to compensate.
1243 bounds.Inset(-1, -1);
1244 bounds.Intersect(gfx::Rect(size_));
1245 }
1246
1247 gfx::Rect pixel_bounds = gfx::ToEnclosingRect(
[email protected]ce112fe2012-10-29 22:52:181248 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]4889bd212013-02-11 22:23:101249
[email protected]ca4847f2010-09-24 05:39:151250 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351251 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591252 pixel_bounds));
[email protected]59383c782013-04-17 16:43:271253 if (!canvas) {
[email protected]f98d7e3c2010-09-13 22:30:461254 NOTREACHED();
1255 return;
1256 }
[email protected]cef3362f2009-12-21 17:48:451257
[email protected]f98d7e3c2010-09-13 22:30:461258 // We may get back a smaller canvas than we asked for.
1259 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591260 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1261 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1262 pixel_bounds.set_width(canvas->getDevice()->width());
1263 pixel_bounds.set_height(canvas->getDevice()->height());
1264 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1265 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051266
[email protected]f98d7e3c2010-09-13 22:30:461267 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1268
[email protected]aa4117f2011-12-09 22:19:211269 pending_update_params_->bitmap = current_paint_buf_->id();
1270 pending_update_params_->bitmap_rect = bounds;
1271
1272 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461273 // The scroll damage is just another rectangle to paint and copy.
1274 copy_rects.swap(update.paint_rects);
1275 if (!scroll_damage.IsEmpty())
1276 copy_rects.push_back(scroll_damage);
1277
[email protected]4889bd212013-02-11 22:23:101278 for (size_t i = 0; i < copy_rects.size(); ++i) {
1279 gfx::Rect rect = copy_rects[i];
1280 if (fractional_scale) {
1281 // Damage might not be DPI aligned. Inflate rect to compensate.
1282 rect.Inset(-1, -1);
1283 }
1284 PaintRect(rect, pixel_bounds.origin(), canvas.get());
1285 }
[email protected]60a50072012-01-11 02:05:351286
1287 // Software FPS tick for performance tests. The accelerated path traces the
1288 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1289 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421290 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW",
1291 TRACE_EVENT_SCOPE_THREAD);
[email protected]f98d7e3c2010-09-13 22:30:461292 } else { // Accelerated compositing path
1293 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211294 // If painting is done via the gpu process then we don't set any damage
1295 // rects to save the browser process from doing unecessary work.
1296 pending_update_params_->bitmap_rect = bounds;
1297 pending_update_params_->scroll_rect = gfx::Rect();
1298 // We don't need an ack, because we're not sharing a DIB with the browser.
1299 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1300 // with the browser for the GPU surface.
1301 pending_update_params_->needs_ack = false;
[email protected]f0c2a242013-03-15 19:34:521302 Composite(frame_begin_ticks);
[email protected]f98d7e3c2010-09-13 22:30:461303 }
1304
[email protected]936c6f52011-12-13 01:35:261305 // If we're holding a pending input event ACK, send the ACK before sending the
1306 // UpdateReply message so we can receive another input event before the
1307 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1308 // the UpdateRect IPC message handler.
[email protected]59383c782013-04-17 16:43:271309 if (pending_input_event_ack_)
[email protected]936c6f52011-12-13 01:35:261310 Send(pending_input_event_ack_.release());
1311
[email protected]ab543072013-01-25 04:38:151312 // If Composite() called SwapBuffers, pending_update_params_ will be reset (in
[email protected]aa4117f2011-12-09 22:19:211313 // OnSwapBuffersPosted), meaning a message has been added to the
1314 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1315 // the message now.
[email protected]59383c782013-04-17 16:43:271316 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:211317 // sending an ack to browser process that the paint is complete...
1318 update_reply_pending_ = pending_update_params_->needs_ack;
1319 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1320 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341321 }
[email protected]53d3f302009-12-21 04:42:051322
[email protected]29ed96a2012-02-04 18:12:161323 // If we're software rendering then we're done initiating the paint.
1324 if (!is_accelerated_compositing_active_)
1325 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291326}
1327
[email protected]f0c2a242013-03-15 19:34:521328void RenderWidget::Composite(base::TimeTicks frame_begin_time) {
[email protected]ab543072013-01-25 04:38:151329 DCHECK(is_accelerated_compositing_active_);
[email protected]ba91a792013-02-06 09:48:281330 if (compositor_) // TODO(jamesr): Figure out how this can be null.
[email protected]f0c2a242013-03-15 19:34:521331 compositor_->Composite(frame_begin_time);
[email protected]ab543072013-01-25 04:38:151332}
1333
initial.commit09911bf2008-07-26 23:55:291334///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461335// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291336
[email protected]4873c7d2009-07-16 06:36:281337void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]479b0172012-10-29 19:27:091338 TRACE_EVENT2("renderer", "RenderWidget::didInvalidateRect",
1339 "width", rect.width, "height", rect.height);
[email protected]552e6002009-11-19 05:24:571340 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481341 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181342 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571343 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291344 return;
1345
[email protected]552e6002009-11-19 05:24:571346 paint_aggregator_.InvalidateRect(damaged_rect);
1347
1348 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241349 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571350 return;
1351 if (!paint_aggregator_.HasPendingUpdate())
1352 return;
[email protected]aa4117f2011-12-09 22:19:211353 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241354 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1355 return;
1356
1357 // When GPU rendering, combine pending animations and invalidations into
1358 // a single update.
[email protected]816edc62012-03-17 01:27:221359 if (is_accelerated_compositing_active_ &&
1360 animation_update_pending_ &&
1361 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571362 return;
1363
1364 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291365 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1366 // on the call stack.
1367 // 2) Allows us to collect more damage rects before painting to help coalesce
1368 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241369 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111370 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211371 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291372}
1373
[email protected]990278ff2012-11-13 02:12:551374void RenderWidget::didScrollRect(int dx, int dy,
1375 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461376 // Drop scrolls on the floor when we are in compositing mode.
1377 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561378 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461379 return;
1380
[email protected]552e6002009-11-19 05:24:571381 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481382 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181383 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571384 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291385 return;
1386
[email protected]990278ff2012-11-13 02:12:551387 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571388
1389 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241390 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571391 return;
1392 if (!paint_aggregator_.HasPendingUpdate())
1393 return;
[email protected]aa4117f2011-12-09 22:19:211394 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241395 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1396 return;
1397
1398 // When GPU rendering, combine pending animations and invalidations into
1399 // a single update.
[email protected]816edc62012-03-17 01:27:221400 if (is_accelerated_compositing_active_ &&
1401 animation_update_pending_ &&
1402 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571403 return;
1404
1405 // Perform updating asynchronously. This serves two purposes:
1406 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1407 // on the call stack.
1408 // 2) Allows us to collect more damage rects before painting to help coalesce
1409 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241410 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111411 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211412 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291413}
1414
[email protected]244ac1892011-12-02 17:04:471415void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091416 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451417 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581418
[email protected]eac2b362013-05-22 07:01:451419 // If we don't clear PaintAggregator after changing autoResize state, then
1420 // we might end up in a situation where bitmap_rect is larger than the
1421 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1422 // with invalid damage rects.
1423 paint_aggregator_.ClearPendingUpdate();
1424
[email protected]70dee7e2013-05-29 18:28:301425 if (RenderThreadImpl::current()->layout_test_mode()) {
[email protected]eac2b362013-05-22 07:01:451426 WebRect new_pos(rootWindowRect().x,
1427 rootWindowRect().y,
1428 new_size.width,
1429 new_size.height);
1430 view_screen_rect_ = new_pos;
1431 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031432 }
[email protected]20fbfc22013-05-08 20:50:581433
[email protected]eac2b362013-05-22 07:01:451434 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581435
[email protected]70dee7e2013-05-29 18:28:301436 if (!RenderThreadImpl::current()->layout_test_mode())
[email protected]20fbfc22013-05-08 20:50:581437 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091438 }
[email protected]244ac1892011-12-02 17:04:471439}
1440
[email protected]3a1c8a8032013-03-18 22:35:321441void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051442 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1443 device_scale_factor_));
1444 if (compositor_)
1445 compositor_->setViewportSize(size_, physical_backing_size_);
1446}
1447
[email protected]91acd1c2012-03-14 08:32:391448void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221449 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1450
[email protected]c63b4d42012-04-26 01:01:071451#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211452 if (!is_accelerated_compositing_active_) {
1453 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1454 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1455 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1456 // going to switch to accelerated compositing, the GPU process may need
1457 // round-trips to the browser's UI thread before finishing the frame,
1458 // causing deadlocks if we delay the UpdateRect until we receive the
1459 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071460 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1461 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211462 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1463 }
[email protected]c63b4d42012-04-26 01:01:071464#endif
[email protected]aa4117f2011-12-09 22:19:211465
[email protected]ea162f92011-10-04 23:08:221466 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421467 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241468 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221469}
1470
1471void RenderWidget::didDeactivateCompositor() {
1472 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1473
1474 is_accelerated_compositing_active_ = false;
1475 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1476 routing_id_, is_accelerated_compositing_active_));
1477
[email protected]ea162f92011-10-04 23:08:221478 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241479 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091480
1481 // In single-threaded mode, we exit force compositing mode and re-enter in
1482 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1483 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1484 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361485 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091486 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561487}
1488
[email protected]e195e582013-03-08 01:32:591489void RenderWidget::initializeLayerTreeView() {
1490 compositor_ = RenderWidgetCompositor::Create(this);
1491 if (!compositor_)
1492 return;
1493
1494 compositor_->setViewportSize(size_, physical_backing_size_);
1495 if (init_complete_)
1496 compositor_->setSurfaceReady();
1497}
1498
[email protected]8926c602013-01-23 05:32:061499WebKit::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281500 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061501}
1502
[email protected]9ed83fe2013-02-27 01:52:281503void RenderWidget::suppressCompositorScheduling(bool enable) {
1504 if (compositor_)
1505 compositor_->SetSuppressScheduleComposite(enable);
1506}
1507
[email protected]9cd43a62012-03-26 08:03:561508void RenderWidget::willBeginCompositorFrame() {
1509 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371510
[email protected]ea5f70a2013-03-07 12:30:361511 DCHECK(RenderThreadImpl::current()->compositor_message_loop_proxy());
[email protected]abe8b3a2012-03-28 21:19:371512
1513 // The following two can result in further layout and possibly
1514 // enable GPU acceleration so they need to be called before any painting
1515 // is done.
[email protected]2d354272013-01-14 00:59:061516 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]abe8b3a2012-03-28 21:19:371517 UpdateSelectionBounds();
1518
[email protected]9cd43a62012-03-26 08:03:561519 WillInitiatePaint();
1520}
1521
[email protected]3391a0772012-03-28 00:32:071522void RenderWidget::didBecomeReadyForAdditionalInput() {
1523 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]59383c782013-04-17 16:43:271524 if (pending_input_event_ack_)
[email protected]3391a0772012-03-28 00:32:071525 Send(pending_input_event_ack_.release());
1526}
1527
[email protected]6fceb912013-02-15 06:24:151528void RenderWidget::DidCommitCompositorFrame() {
1529}
1530
[email protected]58264a32011-11-17 23:36:151531void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501532 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351533 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1534 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421535 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU",
1536 TRACE_EVENT_SCOPE_THREAD);
[email protected]29ed96a2012-02-04 18:12:161537 // Notify subclasses that we initiated the paint operation.
1538 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151539}
1540
1541void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181542 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1543
1544 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561545 DidFlushPaint();
1546
[email protected]aa4117f2011-12-09 22:19:211547 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151548 return;
1549
[email protected]ea3ee0a2012-05-15 03:43:091550 if (!next_paint_flags_ &&
1551 !need_update_rect_for_auto_resize_ &&
1552 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151553 return;
[email protected]ea3ee0a2012-05-15 03:43:091554 }
[email protected]58264a32011-11-17 23:36:151555
1556 ViewHostMsg_UpdateRect_Params params;
1557 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151558 params.plugin_window_moves.swap(plugin_window_moves_);
1559 params.flags = next_paint_flags_;
1560 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121561 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091562 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151563
1564 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1565 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091566 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151567}
1568
[email protected]f98d7e3c2010-09-13 22:30:461569void RenderWidget::scheduleComposite() {
[email protected]479b0172012-10-29 19:27:091570 TRACE_EVENT0("gpu", "RenderWidget::scheduleComposite");
[email protected]ea5f70a2013-03-07 12:30:361571 if (RenderThreadImpl::current()->compositor_message_loop_proxy() &&
[email protected]ba91a792013-02-06 09:48:281572 compositor_) {
1573 compositor_->setNeedsRedraw();
[email protected]d0be63772011-12-20 23:18:041574 } else {
[email protected]c3d45532011-10-07 19:20:401575 // TODO(nduca): replace with something a little less hacky. The reason this
1576 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1577 // contains a lot of host-renderer synchronization logic that is still
1578 // important for the accelerated compositing case. The option of simply
1579 // duplicating all that code is less desirable than "faking out" the
1580 // invalidation path using a magical damage rect.
1581 didInvalidateRect(WebRect(0, 0, 1, 1));
1582 }
[email protected]f98d7e3c2010-09-13 22:30:461583}
1584
[email protected]5f8b1022011-01-21 23:34:501585void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201586 if (animation_update_pending_)
1587 return;
1588
[email protected]921244e42011-07-20 16:36:301589 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201590 animation_update_pending_ = true;
1591 if (!animation_timer_.IsRunning()) {
1592 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1593 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211594 }
[email protected]5f8b1022011-01-21 23:34:501595}
1596
[email protected]4873c7d2009-07-16 06:36:281597void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301598 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521599 WebCursor cursor;
1600 webkit_glue::InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291601 // Only send a SetCursor message if we need to make a change.
1602 if (!current_cursor_.IsEqual(cursor)) {
1603 current_cursor_ = cursor;
1604 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1605 }
1606}
1607
1608// We are supposed to get a single call to Show for a newly created RenderWidget
1609// that was created via RenderWidget::CreateWebView. So, we wait until this
1610// point to dispatch the ShowWidget message.
1611//
1612// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281613// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291614//
[email protected]4873c7d2009-07-16 06:36:281615void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291616 DCHECK(!did_show_) << "received extraneous Show call";
1617 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1618 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1619
[email protected]8de12d942010-11-17 20:42:441620 if (did_show_)
1621 return;
1622
1623 did_show_ = true;
1624 // NOTE: initial_pos_ may still have its default values at this point, but
1625 // that's okay. It'll be ignored if as_popup is false, or the browser
1626 // process will impose a default position otherwise.
1627 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1628 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291629}
1630
[email protected]9b003482013-05-21 14:00:171631void RenderWidget::didProgrammaticallyScroll(
1632 const WebKit::WebPoint& scroll_point) {
1633 if (!compositor_)
1634 return;
1635 Send(new ViewHostMsg_DidProgrammaticallyScroll(
1636 routing_id_, gfx::Vector2d(scroll_point.x, scroll_point.y)));
1637}
1638
[email protected]4873c7d2009-07-16 06:36:281639void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291640}
1641
[email protected]4873c7d2009-07-16 06:36:281642void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291643}
1644
[email protected]2533ce12009-05-09 00:02:241645void RenderWidget::DoDeferredClose() {
1646 Send(new ViewHostMsg_Close(routing_id_));
1647}
1648
[email protected]4873c7d2009-07-16 06:36:281649void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321650 if (is_swapped_out_) {
1651 // This widget is currently swapped out, and the active widget is in a
1652 // different process. Have the browser route the close request to the
1653 // active widget instead, so that the correct unload handlers are run.
1654 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1655 return;
1656 }
1657
initial.commit09911bf2008-07-26 23:55:291658 // If a page calls window.close() twice, we'll end up here twice, but that's
1659 // OK. It is safe to send multiple Close messages.
1660
[email protected]2533ce12009-05-09 00:02:241661 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1662 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1663 // could be closed before the JS finishes executing. So instead, post a
1664 // message back to the message loop, which won't run until the JS is
1665 // complete, and then the Close message can be sent.
[email protected]dd32b1272013-05-04 14:17:111666 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211667 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291668}
1669
1670void RenderWidget::Close() {
1671 if (webwidget_) {
[email protected]8926c602013-01-23 05:32:061672 webwidget_->willCloseLayerTreeView();
[email protected]ba91a792013-02-06 09:48:281673 compositor_.reset();
[email protected]4873c7d2009-07-16 06:36:281674 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291675 webwidget_ = NULL;
1676 }
1677}
1678
[email protected]4873c7d2009-07-16 06:36:281679WebRect RenderWidget::windowRect() {
1680 if (pending_window_rect_count_)
1681 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241682
[email protected]80ad8622012-11-07 16:33:031683 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291684}
1685
[email protected]8a9d6ca32011-06-06 20:11:301686void RenderWidget::setToolTipText(const WebKit::WebString& text,
1687 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541688 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301689}
1690
[email protected]4873c7d2009-07-16 06:36:281691void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291692 if (did_show_) {
[email protected]70dee7e2013-05-29 18:28:301693 if (!RenderThreadImpl::current()->layout_test_mode()) {
[email protected]8be1c582013-03-06 00:55:031694 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1695 SetPendingWindowRect(pos);
1696 } else {
1697 WebSize new_size(pos.width, pos.height);
[email protected]d9083762013-03-24 01:36:401698 Resize(new_size, new_size, overdraw_bottom_height_,
1699 WebRect(), is_fullscreen_, NO_RESIZE_ACK);
[email protected]8be1c582013-03-06 00:55:031700 view_screen_rect_ = pos;
1701 window_screen_rect_ = pos;
1702 }
initial.commit09911bf2008-07-26 23:55:291703 } else {
1704 initial_pos_ = pos;
1705 }
1706}
1707
[email protected]2533ce12009-05-09 00:02:241708void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1709 pending_window_rect_ = rect;
1710 pending_window_rect_count_++;
1711}
1712
[email protected]4873c7d2009-07-16 06:36:281713WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241714 if (pending_window_rect_count_) {
1715 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1716 // the RootWindowRect is probably going to return wrong results since the
1717 // browser may not have processed the Move yet. There isn't really anything
1718 // good to do in this case, and it shouldn't happen - since this size is
1719 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281720 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241721 }
1722
[email protected]80ad8622012-11-07 16:33:031723 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371724}
1725
[email protected]4873c7d2009-07-16 06:36:281726WebRect RenderWidget::windowResizerRect() {
1727 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191728}
1729
[email protected]fa7b1dc2010-06-23 17:53:041730void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031731 // To prevent this renderer process from sending unnecessary IPC messages to
1732 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041733 // only during the input method attached to the browser process is active.
1734 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291735}
1736
[email protected]58b48a0d2012-06-13 07:01:351737void RenderWidget::UpdateCompositionInfo(
1738 const ui::Range& range,
1739 const std::vector<gfx::Rect>& character_bounds) {
1740 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1741 return;
1742 composition_character_bounds_ = character_bounds;
1743 composition_range_ = range;
1744 Send(new ViewHostMsg_ImeCompositionRangeChanged(
1745 routing_id(), composition_range_, composition_character_bounds_));
1746}
1747
[email protected]fa7b1dc2010-06-23 17:53:041748void RenderWidget::OnImeSetComposition(
1749 const string16& text,
1750 const std::vector<WebCompositionUnderline>& underlines,
1751 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281752 if (!webwidget_)
1753 return;
[email protected]66fca5bc2013-05-23 06:58:291754 ImeEventGuard guard(this);
[email protected]d4cff272011-05-02 15:46:011755 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041756 text, WebVector<WebCompositionUnderline>(underlines),
1757 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011758 // Setting the IME composition was successful. Send the new composition
1759 // range to the browser.
1760 ui::Range range(ui::Range::InvalidRange());
1761 size_t location, length;
1762 if (webwidget_->compositionRange(&location, &length)) {
1763 range.set_start(location);
1764 range.set_end(location + length);
1765 }
1766 // The IME was cancelled via the Esc key, so just send back the caret.
1767 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1768 range.set_start(location);
1769 range.set_end(location + length);
1770 }
[email protected]58b48a0d2012-06-13 07:01:351771 std::vector<gfx::Rect> character_bounds;
1772 GetCompositionCharacterBounds(&character_bounds);
1773 UpdateCompositionInfo(range, character_bounds);
[email protected]d4cff272011-05-02 15:46:011774 } else {
[email protected]fa7b1dc2010-06-23 17:53:041775 // If we failed to set the composition text, then we need to let the browser
1776 // process to cancel the input method's ongoing composition session, to make
1777 // sure we are in a consistent state.
1778 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011779
1780 // Send an updated IME range with just the caret range.
1781 ui::Range range(ui::Range::InvalidRange());
1782 size_t location, length;
1783 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1784 range.set_start(location);
1785 range.set_end(location + length);
1786 }
[email protected]58b48a0d2012-06-13 07:01:351787 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]7f00efa2010-04-15 05:01:261788 }
[email protected]fa7b1dc2010-06-23 17:53:041789}
1790
[email protected]4de6d1692011-10-12 08:45:441791void RenderWidget::OnImeConfirmComposition(
1792 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041793 if (!webwidget_)
1794 return;
[email protected]66fca5bc2013-05-23 06:58:291795 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041796 handling_input_event_ = true;
1797 webwidget_->confirmComposition(text);
1798 handling_input_event_ = false;
1799
[email protected]d4cff272011-05-02 15:46:011800 // Send an updated IME range with just the caret range.
1801 ui::Range range(ui::Range::InvalidRange());
1802 size_t location, length;
1803 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1804 range.set_start(location);
1805 range.set_end(location + length);
1806 }
[email protected]58b48a0d2012-06-13 07:01:351807 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
initial.commit09911bf2008-07-26 23:55:291808}
1809
[email protected]948f7ab72010-05-28 23:48:081810// This message causes the renderer to render an image of the
1811// desired_size, regardless of whether the tab is hidden or not.
[email protected]3d9ec5052013-01-02 22:05:251812void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle,
1813 int tag,
1814 const gfx::Size& page_size,
1815 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001816 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1817 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251818 // Close our unused handle.
1819#if defined(OS_WIN)
1820 ::CloseHandle(dib_handle);
1821#elif defined(OS_MACOSX)
1822 base::SharedMemory::CloseHandle(dib_handle);
1823#endif
1824 }
[email protected]d65adb12010-04-28 17:26:491825 return;
[email protected]45c6aad32010-11-11 04:46:251826 }
[email protected]d65adb12010-04-28 17:26:491827
[email protected]948f7ab72010-05-28 23:48:081828 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491829 // If one of these is empty, then we just return the dib we were
1830 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091831 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491832 return;
1833 }
1834
1835 // Map the given DIB ID into this process, and unmap it at the end
1836 // of this function.
[email protected]45c6aad32010-11-11 04:46:251837 scoped_ptr<TransportDIB> paint_at_size_buffer(
1838 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301839
[email protected]4b01b962012-10-09 23:17:351840 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281841 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:351842 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281843 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:511844 gfx::Size canvas_size = page_size_in_pixel;
1845 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:491846 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:511847 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:491848 static_cast<float>(canvas_size.height());
1849
[email protected]ee8d6fd2010-05-26 17:05:481850 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491851 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1852 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481853 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491854
[email protected]36808ad2010-10-20 19:18:301855 scoped_ptr<skia::PlatformCanvas> canvas(
1856 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1857 canvas_size.height()));
[email protected]59383c782013-04-17 16:43:271858 if (!canvas) {
[email protected]36808ad2010-10-20 19:18:301859 NOTREACHED();
1860 return;
1861 }
1862
[email protected]d65adb12010-04-28 17:26:491863 // Reset bounds to what we actually received, but they should be the
1864 // same.
1865 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1866 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1867 bounds.set_width(canvas->getDevice()->width());
1868 bounds.set_height(canvas->getDevice()->height());
1869
1870 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081871 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491872 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1873
[email protected]948f7ab72010-05-28 23:48:081874 // Have to make sure we're laid out at the right size before
1875 // rendering.
1876 gfx::Size old_size = webwidget_->size();
1877 webwidget_->resize(page_size);
1878 webwidget_->layout();
1879
[email protected]d65adb12010-04-28 17:26:491880 // Paint the entire thing (using original bounds, not scaled bounds).
1881 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1882 canvas->restore();
1883
[email protected]948f7ab72010-05-28 23:48:081884 // Return the widget to its previous size.
1885 webwidget_->resize(old_size);
1886
[email protected]c88c9442010-07-19 18:55:091887 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491888}
1889
[email protected]51a49502013-03-23 01:50:191890void RenderWidget::OnSnapshot(const gfx::Rect& src_subrect) {
1891 SkBitmap snapshot;
1892
1893 if (OnSnapshotHelper(src_subrect, &snapshot)) {
1894 Send(new ViewHostMsg_Snapshot(routing_id(), true, snapshot));
1895 } else {
1896 Send(new ViewHostMsg_Snapshot(routing_id(), false, SkBitmap()));
1897 }
1898}
1899
1900bool RenderWidget::OnSnapshotHelper(const gfx::Rect& src_subrect,
1901 SkBitmap* snapshot) {
1902 base::TimeTicks beginning_time = base::TimeTicks::Now();
1903
1904 if (!webwidget_ || src_subrect.IsEmpty())
1905 return false;
1906
1907 gfx::Rect viewport_size = gfx::IntersectRects(
1908 src_subrect, gfx::Rect(physical_backing_size_));
1909
1910 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(
1911 skia::CreatePlatformCanvas(viewport_size.width(),
1912 viewport_size.height(),
1913 true,
1914 NULL,
1915 skia::RETURN_NULL_ON_FAILURE));
[email protected]59383c782013-04-17 16:43:271916 if (!canvas)
[email protected]51a49502013-03-23 01:50:191917 return false;
1918
1919 canvas->save();
1920 webwidget_->layout();
1921
1922 PaintRect(viewport_size, viewport_size.origin(), canvas.get());
1923 canvas->restore();
1924
1925 const SkBitmap& bitmap = skia::GetTopDevice(*canvas)->accessBitmap(false);
1926 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1927 return false;
1928
1929 UMA_HISTOGRAM_TIMES("Renderer4.Snapshot",
1930 base::TimeTicks::Now() - beginning_time);
1931 return true;
1932}
1933
[email protected]0bc1f572013-04-17 01:46:311934void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121935 // During shutdown we can just ignore this message.
1936 if (!webwidget_)
1937 return;
1938
[email protected]0bc1f572013-04-17 01:46:311939 // Even if the browser provides an empty damage rect, it's still expecting to
1940 // receive a repaint ack so just damage the entire widget bounds.
1941 if (size_to_paint.IsEmpty()) {
1942 size_to_paint = size_;
1943 }
1944
[email protected]ec7dc112008-08-06 05:30:121945 set_next_paint_is_repaint_ack();
[email protected]0bc1f572013-04-17 01:46:311946 if (is_accelerated_compositing_active_ && compositor_) {
1947 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]f98d7e3c2010-09-13 22:30:461948 } else {
1949 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1950 didInvalidateRect(repaint_rect);
1951 }
[email protected]ec7dc112008-08-06 05:30:121952}
1953
[email protected]4a9dba42013-04-29 18:24:221954void RenderWidget::OnSmoothScrollCompleted() {
1955 pending_smooth_scroll_gesture_.Run();
[email protected]0e241b4b2012-08-18 09:06:271956}
1957
[email protected]4873c7d2009-07-16 06:36:281958void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111959 if (!webwidget_)
1960 return;
[email protected]4873c7d2009-07-16 06:36:281961 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111962}
1963
[email protected]80ad8622012-11-07 16:33:031964void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1965 const gfx::Rect& window_screen_rect) {
1966 view_screen_rect_ = view_screen_rect;
1967 window_screen_rect_ = window_screen_rect;
1968 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1969}
1970
[email protected]105dffb42013-02-20 03:46:211971#if defined(OS_ANDROID)
1972void RenderWidget::OnImeBatchStateChanged(bool is_begin) {
1973 Send(new ViewHostMsg_ImeBatchStateChanged_ACK(routing_id(), is_begin));
1974}
[email protected]2384b6c2013-02-28 23:58:511975
1976void RenderWidget::OnShowImeIfNeeded() {
1977 UpdateTextInputState(SHOW_IME_IF_NEEDED);
1978}
[email protected]105dffb42013-02-20 03:46:211979#endif
1980
[email protected]468ac582012-11-20 00:53:191981void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1982 if (device_scale_factor_ == device_scale_factor)
1983 return;
1984
1985 device_scale_factor_ = device_scale_factor;
1986
1987 if (!is_accelerated_compositing_active_) {
1988 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
1989 } else {
1990 scheduleComposite();
1991 }
1992}
1993
[email protected]719b36f2010-12-22 20:36:461994webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151995 const gfx::Rect& paint_bounds,
1996 TransportDIB** dib,
1997 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:201998 gfx::Rect* clip,
1999 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:462000 // Bare RenderWidgets don't support optimized plugin painting.
2001 return NULL;
[email protected]ca4847f2010-09-24 05:39:152002}
2003
[email protected]ceb36f7d2012-10-31 18:33:242004gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:522005 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:242006 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:522007}
2008
[email protected]bee16aab2009-08-26 15:55:032009void RenderWidget::SetHidden(bool hidden) {
2010 if (is_hidden_ == hidden)
2011 return;
2012
2013 // The status has changed. Tell the RenderThread about it.
2014 is_hidden_ = hidden;
2015 if (is_hidden_)
[email protected]380244092011-10-07 17:26:272016 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:032017 else
[email protected]380244092011-10-07 17:26:272018 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:032019}
2020
[email protected]2b624c562011-10-27 22:58:262021void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262022 if (!webwidget_)
2023 return;
2024
2025 if (is_fullscreen_) {
2026 webwidget_->willExitFullScreen();
2027 } else {
2028 webwidget_->willEnterFullScreen();
2029 }
[email protected]2b624c562011-10-27 22:58:262030}
2031
2032void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262033 if (!webwidget_)
2034 return;
2035
2036 if (is_fullscreen_) {
2037 webwidget_->didEnterFullScreen();
2038 } else {
2039 webwidget_->didExitFullScreen();
2040 }
[email protected]2b624c562011-10-27 22:58:262041}
2042
[email protected]699ab0d2009-04-23 23:19:142043void RenderWidget::SetBackground(const SkBitmap& background) {
2044 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:462045
[email protected]699ab0d2009-04-23 23:19:142046 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:282047 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:142048}
2049
[email protected]674741932009-02-04 23:44:462050bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:052051 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462052}
2053
2054bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:052055 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462056}
2057
2058void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:052059 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462060}
2061
2062void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:052063 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:462064}
2065
2066void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:052067 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462068}
2069
[email protected]b18583c2012-12-18 06:55:272070static bool IsDateTimeInput(ui::TextInputType type) {
2071 return type == ui::TEXT_INPUT_TYPE_DATE ||
2072 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
2073 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
2074 type == ui::TEXT_INPUT_TYPE_MONTH ||
2075 type == ui::TEXT_INPUT_TYPE_TIME ||
2076 type == ui::TEXT_INPUT_TYPE_WEEK;
2077}
2078
[email protected]66fca5bc2013-05-23 06:58:292079
2080void RenderWidget::StartHandlingImeEvent() {
2081 DCHECK(!handling_ime_event_);
2082 handling_ime_event_ = true;
2083}
2084
2085void RenderWidget::FinishHandlingImeEvent() {
2086 DCHECK(handling_ime_event_);
2087 handling_ime_event_ = false;
2088 // While handling an ime event, text input state and selection bounds updates
2089 // are ignored. These must explicitly be updated once finished handling the
2090 // ime event.
2091 UpdateSelectionBounds();
2092 UpdateTextInputState(DO_NOT_SHOW_IME);
2093}
2094
[email protected]3306f262012-09-21 19:20:422095void RenderWidget::UpdateTextInputState(ShowIme show_ime) {
[email protected]e8f775f2013-02-14 21:00:502096 if (handling_ime_event_)
2097 return;
[email protected]3306f262012-09-21 19:20:422098 bool show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
2099 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:292100 return;
[email protected]ad26ef42011-06-17 07:59:452101 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:272102 if (IsDateTimeInput(new_type))
2103 return; // Not considered as a text input field in WebKit/Chromium.
2104
[email protected]5b739cb2012-08-21 20:35:212105 WebKit::WebTextInputInfo new_info;
2106 if (webwidget_)
2107 new_info = webwidget_->textInputInfo();
2108
[email protected]ad26ef42011-06-17 07:59:452109 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:212110
[email protected]3306f262012-09-21 19:20:422111 // Only sends text input params if they are changed or if the ime should be
2112 // shown.
2113 if (show_ime_if_needed || (text_input_type_ != new_type
2114 || text_input_info_ != new_info
2115 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:212116 ViewHostMsg_TextInputState_Params p;
2117 p.type = new_type;
2118 p.value = new_info.value.utf8();
2119 p.selection_start = new_info.selectionStart;
2120 p.selection_end = new_info.selectionEnd;
2121 p.composition_start = new_info.compositionStart;
2122 p.composition_end = new_info.compositionEnd;
2123 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:422124 p.show_ime_if_needed = show_ime_if_needed;
[email protected]5b739cb2012-08-21 20:35:212125 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
2126
2127 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:042128 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:452129 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:292130 }
initial.commit09911bf2008-07-26 23:55:292131}
2132
[email protected]7c8873e2013-02-05 08:03:012133void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2134 WebRect focus_webrect;
2135 WebRect anchor_webrect;
2136 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
2137 *focus = focus_webrect;
2138 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322139}
2140
[email protected]e99ef6f2011-10-16 01:13:002141void RenderWidget::UpdateSelectionBounds() {
2142 if (!webwidget_)
2143 return;
[email protected]66fca5bc2013-05-23 06:58:292144 if (handling_ime_event_)
2145 return;
[email protected]e99ef6f2011-10-16 01:13:002146
[email protected]7c8873e2013-02-05 08:03:012147 ViewHostMsg_SelectionBounds_Params params;
2148 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2149 if (selection_anchor_rect_ != params.anchor_rect ||
2150 selection_focus_rect_ != params.focus_rect) {
2151 selection_anchor_rect_ = params.anchor_rect;
2152 selection_focus_rect_ = params.focus_rect;
2153 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
[email protected]129b7382013-02-12 02:14:292154 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
[email protected]7c8873e2013-02-05 08:03:012155 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
[email protected]58b48a0d2012-06-13 07:01:352156 }
[email protected]e99ef6f2011-10-16 01:13:002157
[email protected]58b48a0d2012-06-13 07:01:352158 std::vector<gfx::Rect> character_bounds;
2159 GetCompositionCharacterBounds(&character_bounds);
2160 UpdateCompositionInfo(composition_range_, character_bounds);
2161}
2162
2163bool RenderWidget::ShouldUpdateCompositionInfo(
2164 const ui::Range& range,
2165 const std::vector<gfx::Rect>& bounds) {
2166 if (composition_range_ != range)
2167 return true;
2168 if (bounds.size() != composition_character_bounds_.size())
2169 return true;
2170 for (size_t i = 0; i < bounds.size(); ++i) {
2171 if (bounds[i] != composition_character_bounds_[i])
2172 return true;
2173 }
2174 return false;
[email protected]e99ef6f2011-10-16 01:13:002175}
2176
[email protected]73bf95812011-10-12 11:38:322177// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:452178COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
2179 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
2180COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
2181 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
2182COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
2183 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:182184COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
2185 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
2186COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
2187 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
2188COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
2189 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
2190COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
2191 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
2192COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
2193 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:002194COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
2195 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
2196COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
2197 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
2198COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
2199 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
2200COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
2201 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
2202COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
2203 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
2204COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
2205 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:012206COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
2207 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
2208COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
2209 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]8b4992e2013-03-01 15:42:152210COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeField) == \
2211 int(ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:452212
[email protected]5b739cb2012-08-21 20:35:212213ui::TextInputType RenderWidget::WebKitToUiTextInputType(
2214 WebKit::WebTextInputType type) {
2215 // Check the type is in the range representable by ui::TextInputType.
2216 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
2217 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
2218 return static_cast<ui::TextInputType>(type);
2219}
2220
[email protected]ad26ef42011-06-17 07:59:452221ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272222 if (webwidget_)
2223 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452224 return ui::TEXT_INPUT_TYPE_NONE;
2225}
2226
[email protected]58b48a0d2012-06-13 07:01:352227void RenderWidget::GetCompositionCharacterBounds(
2228 std::vector<gfx::Rect>* bounds) {
2229 DCHECK(bounds);
2230 bounds->clear();
2231}
2232
[email protected]ad26ef42011-06-17 07:59:452233bool RenderWidget::CanComposeInline() {
2234 return true;
[email protected]56ea1a62011-05-30 07:05:572235}
2236
[email protected]4873c7d2009-07-16 06:36:282237WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042238 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282239}
2240
[email protected]f660d9c2012-06-06 18:31:212241float RenderWidget::deviceScaleFactor() {
2242 return device_scale_factor_;
2243}
2244
[email protected]fa7b1dc2010-06-23 17:53:042245void RenderWidget::resetInputMethod() {
2246 if (!input_method_is_active_)
2247 return;
2248
2249 // If the last text input type is not None, then we should finish any
2250 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452251 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042252 // If a composition text exists, then we need to let the browser process
2253 // to cancel the input method's ongoing composition session.
2254 if (webwidget_->confirmComposition())
2255 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
2256 }
[email protected]d4cff272011-05-02 15:46:012257
2258 // Send an updated IME range with the current caret rect.
2259 ui::Range range(ui::Range::InvalidRange());
2260 size_t location, length;
2261 if (webwidget_->caretOrSelectionRange(&location, &length)) {
2262 range.set_start(location);
2263 range.set_end(location + length);
2264 }
[email protected]58b48a0d2012-06-13 07:01:352265
2266 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]fa7b1dc2010-06-23 17:53:042267}
2268
[email protected]c68c3e4e2013-01-24 00:36:562269void RenderWidget::didHandleGestureEvent(
2270 const WebGestureEvent& event,
2271 bool event_cancelled) {
2272#if defined(OS_ANDROID)
2273 if (event_cancelled)
2274 return;
2275 if (event.type == WebInputEvent::GestureTap ||
2276 event.type == WebInputEvent::GestureLongPress) {
2277 UpdateTextInputState(SHOW_IME_IF_NEEDED);
2278 }
2279#endif
2280}
2281
[email protected]f103ab72009-09-02 17:10:592282void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:502283 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292284 size_t i = 0;
2285 for (; i < plugin_window_moves_.size(); ++i) {
2286 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582287 if (move.rects_valid) {
2288 plugin_window_moves_[i] = move;
2289 } else {
2290 plugin_window_moves_[i].visible = move.visible;
2291 }
initial.commit09911bf2008-07-26 23:55:292292 break;
2293 }
2294 }
2295
2296 if (i == plugin_window_moves_.size())
2297 plugin_window_moves_.push_back(move);
2298}
[email protected]268654772009-08-06 23:02:042299
2300void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2301 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2302 i != plugin_window_moves_.end(); ++i) {
2303 if (i->window == window) {
2304 plugin_window_moves_.erase(i);
2305 break;
2306 }
2307 }
2308}
[email protected]67bfb83f2011-09-22 03:36:372309
[email protected]b63d58d2012-11-26 22:37:442310void RenderWidget::GetRenderingStats(
2311 WebKit::WebRenderingStatsImpl& stats) const {
[email protected]ba91a792013-02-06 09:48:282312 if (compositor_)
[email protected]635353c2013-03-06 09:11:202313 compositor_->GetRenderingStats(&stats.rendering_stats);
[email protected]b63d58d2012-11-26 22:37:442314
[email protected]62049562013-03-24 00:39:012315 stats.rendering_stats.animation_frame_count +=
2316 software_stats_.animation_frame_count;
2317 stats.rendering_stats.screen_frame_count +=
2318 software_stats_.screen_frame_count;
2319 stats.rendering_stats.total_paint_time +=
2320 software_stats_.total_paint_time;
2321 stats.rendering_stats.total_pixels_painted +=
2322 software_stats_.total_pixels_painted;
[email protected]fef5e3972012-08-07 03:59:472323}
2324
[email protected]e9ff79c2012-10-19 21:31:262325bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:522326 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
2327 if (!gpu_channel)
2328 return false;
2329
2330 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
2331}
2332
[email protected]24ed0432013-04-24 07:50:312333RenderWidgetCompositor* RenderWidget::compositor() const {
2334 return compositor_.get();
2335}
2336
[email protected]3639aa82013-06-04 11:00:042337void RenderWidget::OnSetBrowserRenderingStats(
2338 const BrowserRenderingStats& stats) {
2339 browser_rendering_stats_ = stats;
2340}
2341
2342void RenderWidget::GetBrowserRenderingStats(BrowserRenderingStats* stats) {
2343 *stats = browser_rendering_stats_;
2344}
2345
[email protected]0c2ebef2013-04-03 12:14:102346void RenderWidget::BeginSmoothScroll(
[email protected]0e241b4b2012-08-18 09:06:272347 bool down,
[email protected]ebd8b562012-10-09 14:44:292348 const SmoothScrollCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:192349 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:292350 int mouse_event_x,
2351 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:272352 DCHECK(!callback.is_null());
[email protected]267909d2012-10-20 04:36:192353
2354 ViewHostMsg_BeginSmoothScroll_Params params;
2355 params.scroll_down = down;
2356 params.pixels_to_scroll = pixels_to_scroll;
2357 params.mouse_event_x = mouse_event_x;
2358 params.mouse_event_y = mouse_event_y;
2359
[email protected]4a9dba42013-04-29 18:24:222360 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, params));
2361 pending_smooth_scroll_gesture_ = callback;
[email protected]a39ca1652012-07-13 21:30:582362}
2363
[email protected]a2b5ded2013-05-20 21:32:532364void RenderWidget::DidOverscroll(gfx::Vector2dF accumulated_overscroll,
2365 gfx::Vector2dF current_fling_velocity) {
2366 if (overscroll_notifications_enabled_) {
2367 Send(new ViewHostMsg_DidOverscroll(routing_id_,
2368 accumulated_overscroll,
2369 current_fling_velocity));
2370 }
2371}
2372
[email protected]67bfb83f2011-09-22 03:36:372373bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
2374 return false;
2375}
[email protected]c3d45532011-10-07 19:20:402376
[email protected]41d86852012-11-07 12:23:242377bool RenderWidget::WillHandleGestureEvent(
2378 const WebKit::WebGestureEvent& event) {
2379 return false;
2380}
2381
[email protected]ce6689f2013-03-29 12:52:552382void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2383 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2384}
2385
[email protected]3d5c243b2012-11-30 00:26:012386bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2387 return true;
2388}
2389
[email protected]3ae68c52013-04-12 06:10:052390WebGraphicsContext3DCommandBufferImpl* RenderWidget::CreateGraphicsContext3D(
[email protected]92fd8c02013-03-29 08:54:152391 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
[email protected]ed7defa2013-03-12 21:29:592392 if (!webwidget_)
2393 return NULL;
[email protected]8f746982013-03-21 06:28:032394 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
2395 new WebGraphicsContext3DCommandBufferImpl(
2396 surface_id(),
2397 GetURLForGraphicsContext3D(),
2398 RenderThreadImpl::current(),
2399 weak_ptr_factory_.GetWeakPtr()));
[email protected]ed7defa2013-03-12 21:29:592400
[email protected]8f746982013-03-21 06:28:032401 if (!context->Initialize(
2402 attributes,
2403 false /* bind generates resources */,
2404 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
2405 return NULL;
2406 return context.release();
[email protected]ed7defa2013-03-12 21:29:592407}
2408
[email protected]e9ff79c2012-10-19 21:31:262409} // namespace content