blob: 724b36760d4876ae532ab689a5e9c71e76d04722 [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
[email protected]92201e32013-06-08 06:14:52416 if (!RenderThreadImpl::current() || // Will be NULL during unit tests.
417 !RenderThreadImpl::current()->layout_test_mode()) {
418 // Resize should have caused an invalidation of the entire view.
419 DCHECK(new_size.IsEmpty() || is_accelerated_compositing_active_ ||
420 paint_aggregator_.HasPendingUpdate());
421 }
[email protected]1c0008842013-06-06 08:35:48422 } else if (!RenderThreadImpl::current() || // Will be NULL during unit tests.
423 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]632c4382013-05-15 08:58:45424 resize_ack = NO_RESIZE_ACK;
425 }
426
427 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
428 // For empty size or empty physical_backing_size, there is no next paint
429 // (along with which to send the ack) until they are set to non-empty.
[email protected]ff475a322012-03-14 00:05:35430 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34431 }
432
[email protected]20fbfc22013-05-08 20:50:58433 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45434 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58435 set_next_paint_is_resize_ack();
436
[email protected]61e2b3cc2012-03-02 16:13:34437 if (fullscreen_change)
438 DidToggleFullscreen();
439
440 // If a resize ack is requested and it isn't set-up, then no more resizes will
441 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45442 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29443}
444
445void RenderWidget::OnClose() {
446 if (closing_)
447 return;
448 closing_ = true;
449
450 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03451 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27452 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03453 SetHidden(false);
454 }
initial.commit09911bf2008-07-26 23:55:29455
initial.commit09911bf2008-07-26 23:55:29456 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25457 // now. Post a task that only gets invoked when there are no nested message
458 // loops.
[email protected]dd32b1272013-05-04 14:17:11459 base::MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29460 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25461
462 // Balances the AddRef taken when we called AddRoute.
463 Release();
initial.commit09911bf2008-07-26 23:55:29464}
465
[email protected]61e2b3cc2012-03-02 16:13:34466// Got a response from the browser after the renderer decided to create a new
467// view.
[email protected]fc4404d2012-11-07 19:53:30468void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34469 DCHECK(routing_id_ != MSG_ROUTING_NONE);
470
[email protected]fc4404d2012-11-07 19:53:30471 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34472}
473
[email protected]0fdd5012013-05-29 08:05:56474void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
475 screen_info_ = params.screen_info;
476 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
477 Resize(params.new_size, params.physical_backing_size,
478 params.overdraw_bottom_height, params.resizer_rect,
479 params.is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29480}
481
[email protected]b5913d72012-02-07 22:26:54482void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
483 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59484 gfx::Rect view_rect(size_);
485
[email protected]ce112fe2012-10-29 22:52:18486 gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_);
[email protected]b9769d82012-02-10 00:23:59487 if (!old_damage_rect.IsEmpty())
488 paint_aggregator_.InvalidateRect(old_damage_rect);
489
[email protected]ce112fe2012-10-29 22:52:18490 gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect);
[email protected]b9769d82012-02-10 00:23:59491 if (!new_damage_rect.IsEmpty())
492 paint_aggregator_.InvalidateRect(new_damage_rect);
493
[email protected]b5913d72012-02-07 22:26:54494 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59495
[email protected]b5913d72012-02-07 22:26:54496 if (webwidget_)
497 webwidget_->didChangeWindowResizerRect();
498 }
499}
500
initial.commit09911bf2008-07-26 23:55:29501void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31502 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29503 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03504 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29505}
506
[email protected]9e2e4632012-07-27 16:38:41507void RenderWidget::OnWasShown(bool needs_repainting) {
508 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29509 // During shutdown we can just ignore this message.
510 if (!webwidget_)
511 return;
512
513 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03514 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29515
516 if (!needs_repainting && !needs_repainting_on_restore_)
517 return;
518 needs_repainting_on_restore_ = false;
519
[email protected]d65adb12010-04-28 17:26:49520 // Tag the next paint as a restore ack, which is picked up by
521 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29522 set_next_paint_is_restore_ack();
523
524 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56525 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46526 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
527 } else {
528 scheduleComposite();
529 }
initial.commit09911bf2008-07-26 23:55:29530}
531
[email protected]992db4c2011-05-12 15:37:15532void RenderWidget::OnWasSwappedOut() {
533 // If we have been swapped out and no one else is using this process,
534 // it's safe to exit now. If we get swapped back in, we will call
535 // AddRefProcess in SetSwappedOut.
536 if (is_swapped_out_)
537 RenderProcess::current()->ReleaseProcess();
538}
539
[email protected]53d3f302009-12-21 04:42:05540void RenderWidget::OnRequestMoveAck() {
541 DCHECK(pending_window_rect_count_);
542 pending_window_rect_count_--;
543}
544
545void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58546 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21547 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05548 update_reply_pending_ = false;
549
[email protected]b4d08452010-10-05 17:34:35550 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
551 // have no current paint buffer.
552 if (current_paint_buf_) {
553 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
554 current_paint_buf_ = NULL;
555 }
556
[email protected]65225772011-05-12 21:10:24557 // If swapbuffers is still pending, then defer the update until the
558 // swapbuffers occurs.
559 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
560 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
561 return;
562 }
563
[email protected]29ed96a2012-02-04 18:12:16564 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18565 if (!is_accelerated_compositing_active_) {
566 DidFlushPaint();
567 }
[email protected]a2f6bc112009-06-27 16:27:25568
initial.commit09911bf2008-07-26 23:55:29569 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24570 DoDeferredUpdateAndSendInputAck();
571}
572
[email protected]d0be63772011-12-20 23:18:04573bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]ed7defa2013-03-12 21:29:59574 // Contexts using the command buffer support asynchronous swapbuffers.
575 // See RenderWidget::CreateOutputSurface().
[email protected]8f746982013-03-21 06:28:03576 if (RenderThreadImpl::current()->compositor_message_loop_proxy())
[email protected]ed7defa2013-03-12 21:29:59577 return false;
578
579 return true;
580}
581
582GURL RenderWidget::GetURLForGraphicsContext3D() {
583 return GURL();
[email protected]65225772011-05-12 21:10:24584}
585
[email protected]479b0172012-10-29 19:27:09586bool RenderWidget::ForceCompositingModeEnabled() {
587 return false;
588}
589
[email protected]ba91a792013-02-06 09:48:28590scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface() {
[email protected]c3e32ed42013-05-02 05:07:13591 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]a1811b8912013-05-09 15:35:19592
593#if defined(OS_ANDROID)
[email protected]913d99a2013-05-31 07:16:07594 if (SynchronousCompositorFactory* factory =
595 SynchronousCompositorFactory::GetInstance()) {
596 return factory->CreateOutputSurface(routing_id());
[email protected]a1811b8912013-05-09 15:35:19597 }
598#endif
599
[email protected]8bbe3a92013-05-12 00:58:35600 if (command_line.HasSwitch(switches::kEnableSoftwareCompositingGLAdapter)) {
601 return scoped_ptr<cc::OutputSurface>(
602 new CompositorOutputSurface(routing_id(), NULL,
603 new CompositorSoftwareOutputDevice()));
604 }
605
[email protected]ed7defa2013-03-12 21:29:59606 // Explicitly disable antialiasing for the compositor. As of the time of
607 // this writing, the only platform that supported antialiasing for the
608 // compositor was Mac OS X, because the on-screen OpenGL context creation
609 // code paths on Windows and Linux didn't yet have multisampling support.
610 // Mac OS X essentially always behaves as though it's rendering offscreen.
611 // Multisampling has a heavy cost especially on devices with relatively low
612 // fill rate like most notebooks, and the Mac implementation would need to
613 // be optimized to resolve directly into the IOSurface shared between the
614 // GPU and browser processes. For these reasons and to avoid platform
615 // disparities we explicitly disable antialiasing.
616 WebKit::WebGraphicsContext3D::Attributes attributes;
617 attributes.antialias = false;
618 attributes.shareResources = true;
619 attributes.noAutomaticFlushes = true;
[email protected]a6886502013-05-16 20:59:18620 attributes.depth = false;
621 attributes.stencil = false;
[email protected]bec084292013-05-21 21:31:44622 if (command_line.HasSwitch(cc::switches::kForceDirectLayerDrawing))
623 attributes.stencil = true;
[email protected]3ae68c52013-04-12 06:10:05624 WebGraphicsContext3DCommandBufferImpl* context =
625 CreateGraphicsContext3D(attributes);
[email protected]8bbe3a92013-05-12 00:58:35626 if (!context)
627 return scoped_ptr<cc::OutputSurface>();
[email protected]ed7defa2013-03-12 21:29:59628
[email protected]2847b222013-04-06 00:59:24629 bool composite_to_mailbox =
[email protected]7b45b5762013-05-08 14:36:56630 command_line.HasSwitch(cc::switches::kCompositeToMailbox) &&
631 !command_line.HasSwitch(switches::kEnableDelegatedRenderer);
[email protected]2847b222013-04-06 00:59:24632 // No swap throttling yet when compositing on the main thread.
633 DCHECK(!composite_to_mailbox || is_threaded_compositing_enabled_);
634 return scoped_ptr<cc::OutputSurface>(composite_to_mailbox ?
635 new MailboxOutputSurface(routing_id(), context, NULL) :
636 new CompositorOutputSurface(routing_id(), context, NULL));
[email protected]ba91a792013-02-06 09:48:28637}
638
[email protected]ed7defa2013-03-12 21:29:59639void RenderWidget::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24640 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21641 while (!updates_pending_swap_.empty()) {
642 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
643 updates_pending_swap_.pop_front();
644 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
645 // compositing pass, hence doesn't require an UpdateRect message.
646 if (msg)
647 Send(msg);
648 }
[email protected]65225772011-05-12 21:10:24649 num_swapbuffers_complete_pending_ = 0;
650 using_asynchronous_swapbuffers_ = false;
651 // Schedule another frame so the compositor learns about it.
652 scheduleComposite();
653}
654
[email protected]ed7defa2013-03-12 21:29:59655void RenderWidget::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:08656 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21657
658 if (using_asynchronous_swapbuffers_) {
659 ViewHostMsg_UpdateRect* msg = NULL;
660 // pending_update_params_ can be NULL if the swap doesn't correspond to an
661 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
662 // message.
[email protected]59383c782013-04-17 16:43:27663 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:21664 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
665 pending_update_params_.reset();
666 }
667 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08668 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21669 }
[email protected]37a6f302011-07-11 23:43:08670}
671
[email protected]ed7defa2013-03-12 21:29:59672void RenderWidget::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24673 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16674
[email protected]404939f2012-06-01 04:06:18675 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16676 DidFlushPaint();
677
[email protected]65225772011-05-12 21:10:24678 // When compositing deactivates, we reset the swapbuffers pending count. The
679 // swapbuffers acks may still arrive, however.
680 if (num_swapbuffers_complete_pending_ == 0) {
681 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
682 return;
683 }
[email protected]aa4117f2011-12-09 22:19:21684 DCHECK(!updates_pending_swap_.empty());
685 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
686 updates_pending_swap_.pop_front();
687 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
688 // compositing pass, hence doesn't require an UpdateRect message.
689 if (msg)
690 Send(msg);
[email protected]65225772011-05-12 21:10:24691 num_swapbuffers_complete_pending_--;
692
693 // If update reply is still pending, then defer the update until that reply
694 // occurs.
[email protected]d0be63772011-12-20 23:18:04695 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24696 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
697 return;
698 }
699
700 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06701 // when we were previously rendering. However, if an invalidation task is not
702 // posted, there may be software rendering work pending. In that case, don't
703 // early out.
704 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24705 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
706 return;
707 }
708
[email protected]cc66e682012-10-02 06:48:18709 // Do not call DoDeferredUpdate unless there's animation work to be done or
710 // a real invalidation. This prevents rendering in response to a swapbuffers
711 // callback coming back after we've navigated away from the page that
712 // generated it.
713 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
714 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
715 return;
716 }
717
[email protected]65225772011-05-12 21:10:24718 // Continue painting if necessary...
719 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29720}
721
[email protected]0dea1652012-12-14 00:09:09722void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
[email protected]4b157662013-05-29 04:05:05723 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:09724 bool is_keyboard_shortcut) {
[email protected]5dd768212009-08-13 23:34:49725 handling_input_event_ = true;
[email protected]0dea1652012-12-14 00:09:09726 if (!input_event) {
[email protected]5dd768212009-08-13 23:34:49727 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29728 return;
[email protected]5dd768212009-08-13 23:34:49729 }
initial.commit09911bf2008-07-26 23:55:29730
[email protected]b4841e1c2013-05-16 22:30:10731 const char* const event_name = GetEventName(input_event->type);
732 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent",
733 "event", event_name);
734
[email protected]c2eaa8f2013-05-10 02:41:55735 if (compositor_)
736 compositor_->SetLatencyInfo(latency_info);
[email protected]256737c2013-06-08 04:39:10737 else
738 latency_info_.MergeWith(latency_info);
[email protected]c2eaa8f2013-05-10 02:41:55739
[email protected]6a4d7f62013-01-07 21:32:13740 base::TimeDelta now = base::TimeDelta::FromInternalValue(
741 base::TimeTicks::Now().ToInternalValue());
742
743 int64 delta = static_cast<int64>(
744 (now.InSecondsF() - input_event->timeStampSeconds) *
745 base::Time::kMicrosecondsPerSecond);
746 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer", delta, 0, 1000000, 100);
[email protected]de415552013-01-23 04:12:17747 base::HistogramBase* counter_for_type =
[email protected]bafdc5d52013-02-27 18:18:48748 base::Histogram::FactoryGet(
[email protected]b4841e1c2013-05-16 22:30:10749 base::StringPrintf("Event.Latency.Renderer.%s", event_name),
[email protected]bafdc5d52013-02-27 18:18:48750 0,
751 1000000,
[email protected]6a4d7f62013-01-07 21:32:13752 100,
[email protected]de415552013-01-23 04:12:17753 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]bafdc5d52013-02-27 18:18:48754 counter_for_type->Add(delta);
[email protected]6a4d7f62013-01-07 21:32:13755
[email protected]67bfb83f2011-09-22 03:36:37756 bool prevent_default = false;
757 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26758 const WebMouseEvent& mouse_event =
759 *static_cast<const WebMouseEvent*>(input_event);
760 TRACE_EVENT2("renderer", "HandleMouseMove",
761 "x", mouse_event.x, "y", mouse_event.y);
762 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37763 }
764
[email protected]41d86852012-11-07 12:23:24765 if (WebInputEvent::isGestureEventType(input_event->type)) {
766 const WebGestureEvent& gesture_event =
767 *static_cast<const WebGestureEvent*>(input_event);
768 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
769 }
770
[email protected]3ebcc7c2013-01-09 05:34:46771 if (input_event->type == WebInputEvent::GestureTap ||
772 input_event->type == WebInputEvent::GestureLongPress)
773 resetInputMethod();
774
[email protected]67bfb83f2011-09-22 03:36:37775 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12776 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
777 suppress_next_char_events_ = false;
778 if (!processed && webwidget_)
779 processed = webwidget_->handleInputEvent(*input_event);
780 }
781
782 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
783 // it's not processed by webkit, then we need to suppress the upcoming Char
784 // events.
785 if (!processed && is_keyboard_shortcut)
786 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29787
[email protected]3d5c243b2012-11-30 00:26:01788 InputEventAckState ack_result = processed ?
789 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
790 if (!processed && input_event->type == WebInputEvent::TouchStart) {
791 const WebTouchEvent& touch_event =
792 *static_cast<const WebTouchEvent*>(input_event);
793 ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ?
794 INPUT_EVENT_ACK_STATE_NOT_CONSUMED :
795 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
796 }
797
[email protected]a9fb30aa2011-10-06 06:58:46798 IPC::Message* response =
[email protected]c084330e02013-04-27 01:08:15799 new InputHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
800 ack_result);
[email protected]3391a0772012-03-28 00:32:07801 bool event_type_gets_rate_limited =
802 input_event->type == WebInputEvent::MouseMove ||
803 input_event->type == WebInputEvent::MouseWheel ||
804 WebInputEvent::isTouchEventType(input_event->type);
[email protected]8926c602013-01-23 05:32:06805
806 bool frame_pending = paint_aggregator_.HasPendingUpdate();
807 if (is_accelerated_compositing_active_) {
[email protected]ba91a792013-02-06 09:48:28808 frame_pending = compositor_ &&
809 compositor_->commitRequested();
[email protected]8926c602013-01-23 05:32:06810 }
811
[email protected]3391a0772012-03-28 00:32:07812 bool is_input_throttled =
[email protected]ce2b28e2012-08-09 15:53:57813 throttle_input_events_ &&
[email protected]8926c602013-01-23 05:32:06814 frame_pending;
[email protected]e2824412009-02-27 01:57:05815
[email protected]f8868d72012-04-27 19:13:03816 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24817 // We want to rate limit the input events in this case, so we'll wait for
818 // painting to finish before ACKing this message.
[email protected]59383c782013-04-17 16:43:27819 if (pending_input_event_ack_) {
[email protected]353a34c2010-05-28 23:35:17820 // As two different kinds of events could cause us to postpone an ack
821 // we send it now, if we have one pending. The Browser should never
822 // send us the same kind of event we are delaying the ack for.
823 Send(pending_input_event_ack_.release());
824 }
[email protected]12fbad812009-09-01 18:21:24825 pending_input_event_ack_.reset(response);
826 } else {
827 Send(response);
828 }
829
[email protected]3306f262012-09-21 19:20:42830#if defined(OS_ANDROID)
831 // Allow the IME to be shown when the focus changes as a consequence
832 // of a processed touch end event.
833 if (input_event->type == WebInputEvent::TouchEnd && processed)
834 UpdateTextInputState(SHOW_IME_IF_NEEDED);
835#endif
836
[email protected]5dd768212009-08-13 23:34:49837 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48838
[email protected]67bfb83f2011-09-22 03:36:37839 if (!prevent_default) {
840 if (WebInputEvent::isKeyboardEventType(input_event->type))
841 DidHandleKeyEvent();
842 if (WebInputEvent::isMouseEventType(input_event->type))
843 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24844 if (WebInputEvent::isTouchEventType(input_event->type))
845 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37846 }
initial.commit09911bf2008-07-26 23:55:29847}
848
[email protected]34202de2013-05-06 23:36:22849void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
850 if (webwidget_)
851 webwidget_->setCursorVisibilityState(is_visible);
852}
853
initial.commit09911bf2008-07-26 23:55:29854void RenderWidget::OnMouseCaptureLost() {
855 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28856 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29857}
858
859void RenderWidget::OnSetFocus(bool enable) {
860 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33861 if (webwidget_)
862 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29863}
864
865void RenderWidget::ClearFocus() {
866 // We may have got the focus from the browser before this gets processed, in
867 // which case we do not want to unfocus ourself.
868 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28869 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29870}
871
[email protected]2d5d09d52009-06-15 14:29:21872void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00873 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21874 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06875 TRACE_EVENT2("renderer", "PaintRect",
876 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:45877
878 const bool kEnableGpuBenchmarking =
879 CommandLine::ForCurrentProcess()->HasSwitch(
880 switches::kEnableGpuBenchmarking);
[email protected]4fb66842009-12-04 21:41:00881 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21882
883 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00884 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
885 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03886
[email protected]699ab0d2009-04-23 23:19:14887 // If there is a custom background, tile it.
888 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14889 SkPaint paint;
[email protected]4e29afd2012-12-04 04:07:11890 skia::RefPtr<SkShader> shader = skia::AdoptRef(
891 SkShader::CreateBitmapShader(background_,
892 SkShader::kRepeat_TileMode,
893 SkShader::kRepeat_TileMode));
894 paint.setShader(shader.get());
[email protected]fb10ec5b2011-10-24 17:54:20895
896 // Use kSrc_Mode to handle background_ transparency properly.
897 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
898
899 // Canvas could contain multiple update rects. Clip to given rect so that
900 // we don't accidentally clear other update rects.
901 canvas->save();
[email protected]aa7e7a12013-02-22 13:37:44902 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]1835b9e2012-02-28 13:12:48903 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14904 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20905 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14906 }
907
[email protected]719b36f2010-12-22 20:36:46908 // First see if this rect is a plugin that can paint itself faster.
909 TransportDIB* optimized_dib = NULL;
910 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:20911 float dib_scale_factor;
[email protected]719b36f2010-12-22 20:36:46912 webkit::ppapi::PluginInstance* optimized_instance =
913 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
914 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:20915 &optimized_copy_rect,
916 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:46917 if (optimized_instance) {
918 // This plugin can be optimize-painted and we can just ask it to paint
919 // itself. We don't actually need the TransportDIB in this case.
920 //
921 // This is an optimization for PPAPI plugins that know they're on top of
922 // the page content. If this rect is inside such a plugin, we can save some
923 // time and avoid re-rendering the page content which we know will be
924 // covered by the plugin later (this time can be significant, especially
925 // for a playing movie that is invalidating a lot).
926 //
927 // In the plugin movie case, hopefully the similar call to
928 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
929 // painting, because that avoids copying the plugin image to a different
930 // paint rect. Unfortunately, if anything on the page is animating other
931 // than the movie, it break this optimization since the union of the
932 // invalid regions will be larger than the plugin.
933 //
934 // This code optimizes that case, where we can still avoid painting in
935 // WebKit and filling the background (which can be slow) and just painting
936 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
937 // required.
[email protected]63ab54262012-11-09 15:58:45938 base::TimeTicks paint_begin_ticks;
939 if (kEnableGpuBenchmarking)
940 paint_begin_ticks = base::TimeTicks::HighResNow();
941
[email protected]df59dd42012-09-14 22:56:30942 SkAutoCanvasRestore auto_restore(canvas, true);
943 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]719b36f2010-12-22 20:36:46944 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27945 optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:21946 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45947 if (kEnableGpuBenchmarking) {
948 base::TimeDelta paint_time =
949 base::TimeTicks::HighResNow() - paint_begin_ticks;
950 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01951 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45952 }
[email protected]719b36f2010-12-22 20:36:46953 } else {
954 // Normal painting case.
[email protected]63ab54262012-11-09 15:58:45955 base::TimeTicks paint_begin_ticks;
956 if (kEnableGpuBenchmarking)
957 paint_begin_ticks = base::TimeTicks::HighResNow();
958
[email protected]719b36f2010-12-22 20:36:46959 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
[email protected]63ab54262012-11-09 15:58:45960
961 if (kEnableGpuBenchmarking) {
962 base::TimeDelta paint_time =
963 base::TimeTicks::HighResNow() - paint_begin_ticks;
964 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01965 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45966 }
[email protected]719b36f2010-12-22 20:36:46967
968 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35969 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46970 }
initial.commit09911bf2008-07-26 23:55:29971
[email protected]4fb66842009-12-04 21:41:00972 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00973 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45974
975 if (kEnableGpuBenchmarking) {
[email protected]63ab54262012-11-09 15:58:45976 int64 num_pixels_processed = rect.width() * rect.height();
[email protected]62049562013-03-24 00:39:01977 software_stats_.total_pixels_painted += num_pixels_processed;
[email protected]63ab54262012-11-09 15:58:45978 }
[email protected]4fb66842009-12-04 21:41:00979}
980
981void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
982 skia::PlatformCanvas* canvas) {
983 static bool kPaintBorder =
984 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
985 if (!kPaintBorder)
986 return;
987
[email protected]53d3f302009-12-21 04:42:05988 // Cycle through these colors to help distinguish new paint rects.
989 const SkColor colors[] = {
990 SkColorSetARGB(0x3F, 0xFF, 0, 0),
991 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
992 SkColorSetARGB(0x3F, 0, 0, 0xFF),
993 };
994 static int color_selector = 0;
995
[email protected]4fb66842009-12-04 21:41:00996 SkPaint paint;
997 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05998 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00999 paint.setStrokeWidth(1);
1000
1001 SkIRect irect;
1002 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
1003 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:291004}
1005
[email protected]52ccd0ea2011-02-16 01:09:051006void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:301007 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:301008 if (!animation_update_pending_) {
1009 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:591010 return;
[email protected]921244e42011-07-20 16:36:301011 }
[email protected]bd37ae252011-06-03 01:28:181012 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:591013 // Record when we fired (according to base::Time::Now()) relative to when
1014 // we posted the task to quantify how much the base::Time/base::TimeTicks
1015 // skew is affecting animations.
1016 base::TimeDelta animation_callback_delay = base::Time::Now() -
1017 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
1018 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
1019 animation_callback_delay,
1020 base::TimeDelta::FromMilliseconds(0),
1021 base::TimeDelta::FromMilliseconds(30),
1022 25);
1023 }
[email protected]65225772011-05-12 21:10:241024 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:241025}
1026
[email protected]52ccd0ea2011-02-16 01:09:051027void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:591028 if (!animation_update_pending_)
1029 return;
[email protected]bd37ae252011-06-03 01:28:181030
1031 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:331032 base::TimeDelta animationInterval = IsRenderingVSynced() ?
1033 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:181034
[email protected]7c4329e2011-02-18 22:02:591035 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:451036
1037 // animation_floor_time_ is the earliest time that we should animate when
1038 // using the dead reckoning software scheduler. If we're using swapbuffers
1039 // complete callbacks to rate limit, we can ignore this floor.
1040 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:301041 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:331042 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:181043 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:591044 // running animation callbacks so that if a callback requests another
1045 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:381046 animation_timer_.Stop();
1047 animation_timer_.Start(FROM_HERE, animationInterval, this,
1048 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:591049 animation_update_pending_ = false;
[email protected]ba91a792013-02-06 09:48:281050 if (is_accelerated_compositing_active_ && compositor_) {
[email protected]635353c2013-03-06 09:11:201051 compositor_->Animate(base::TimeTicks::Now());
[email protected]8926c602013-01-23 05:32:061052 } else {
[email protected]635353c2013-03-06 09:11:201053 double frame_begin_time =
1054 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
1055 webwidget_->animate(frame_begin_time);
[email protected]8926c602013-01-23 05:32:061056 }
[email protected]7c4329e2011-02-18 22:02:591057 return;
[email protected]5f8b1022011-01-21 23:34:501058 }
[email protected]bd37ae252011-06-03 01:28:181059 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:381060 if (!animation_timer_.IsRunning()) {
1061 // This code uses base::Time::Now() to calculate the floor and next fire
1062 // time because javascript's Date object uses base::Time::Now(). The
1063 // message loop uses base::TimeTicks, which on windows can have a
1064 // different granularity than base::Time.
1065 // The upshot of all this is that this function might be called before
1066 // base::Time::Now() has advanced past the animation_floor_time_. To
1067 // avoid exposing this delay to javascript, we keep posting delayed
1068 // tasks until base::Time::Now() has advanced far enough.
1069 base::TimeDelta delay = animation_floor_time_ - now;
1070 animation_timer_.Start(FROM_HERE, delay, this,
1071 &RenderWidget::AnimationCallback);
1072 }
[email protected]5f8b1022011-01-21 23:34:501073}
1074
[email protected]bd37ae252011-06-03 01:28:181075bool RenderWidget::IsRenderingVSynced() {
1076 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
1077 // not caught by this check. This will lead to artificially low frame rates
1078 // for people who force vsync off at a driver level and expect Chrome to speed
1079 // up.
1080 return !has_disable_gpu_vsync_switch_;
1081}
1082
[email protected]65225772011-05-12 21:10:241083void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:061084 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:241085 invalidation_task_posted_ = false;
1086 DoDeferredUpdateAndSendInputAck();
1087}
1088
1089void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:051090 DoDeferredUpdate();
1091
[email protected]59383c782013-04-17 16:43:271092 if (pending_input_event_ack_)
[email protected]52ccd0ea2011-02-16 01:09:051093 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:211094}
1095
[email protected]552e6002009-11-19 05:24:571096void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:581097 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:081098
[email protected]65225772011-05-12 21:10:241099 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:291100 return;
[email protected]05a980d7a2012-02-07 22:16:421101
[email protected]fc4404d2012-11-07 19:53:301102 if (!init_complete_) {
1103 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:421104 return;
1105 }
[email protected]aa4117f2011-12-09 22:19:211106 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:241107 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
1108 return;
1109 }
[email protected]9ca84622011-06-02 23:46:391110 if (is_accelerated_compositing_active_ &&
1111 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:241112 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
1113 return;
1114 }
initial.commit09911bf2008-07-26 23:55:291115
[email protected]552e6002009-11-19 05:24:571116 // Suppress updating when we are hidden.
[email protected]e3d92a7f2013-01-10 02:35:051117 if (is_hidden_ || size_.IsEmpty() || is_swapped_out_) {
[email protected]552e6002009-11-19 05:24:571118 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:291119 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:241120 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:291121 return;
1122 }
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]793b2d62013-06-11 00:43:251134 // Check for whether we need to track swap buffers. We need to do that after
1135 // layout() because it may have switched us to accelerated compositing.
1136 if (is_accelerated_compositing_active_)
1137 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
1138
[email protected]dcca3aa92012-02-17 23:03:371139 // The following two can result in further layout and possibly
1140 // enable GPU acceleration so they need to be called before any painting
1141 // is done.
[email protected]3306f262012-09-21 19:20:421142 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]dcca3aa92012-02-17 23:03:371143 UpdateSelectionBounds();
1144
[email protected]5f8b1022011-01-21 23:34:501145 // Suppress painting if nothing is dirty. This has to be done after updating
1146 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:241147 if (!paint_aggregator_.HasPendingUpdate()) {
1148 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]38ce4e7b2013-02-23 06:17:371149 InstrumentDidCancelFrame();
[email protected]5f8b1022011-01-21 23:34:501150 return;
[email protected]65225772011-05-12 21:10:241151 }
[email protected]5f8b1022011-01-21 23:34:501152
[email protected]479b0172012-10-29 19:27:091153 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:361154 !is_threaded_compositing_enabled_ &&
[email protected]479b0172012-10-29 19:27:091155 ForceCompositingModeEnabled()) {
1156 webwidget_->enterForceCompositingMode(true);
1157 }
1158
[email protected]872ae5b2011-05-26 20:20:501159 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:561160 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:041161 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:561162 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
1163 delay,
1164 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411165 base::TimeDelta::FromMilliseconds(120),
1166 60);
[email protected]d0be63772011-12-20 23:18:041167 } else {
[email protected]0fb93f52011-05-18 23:13:561168 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
1169 delay,
1170 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411171 base::TimeDelta::FromMilliseconds(120),
1172 60);
[email protected]d0be63772011-12-20 23:18:041173 }
[email protected]872ae5b2011-05-26 20:20:501174
1175 // Calculate filtered time per frame:
1176 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
1177 filtered_time_per_frame_ =
1178 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:561179 }
1180 last_do_deferred_update_time_ = frame_begin_ticks;
1181
[email protected]fef5e3972012-08-07 03:59:471182 if (!is_accelerated_compositing_active_) {
[email protected]62049562013-03-24 00:39:011183 software_stats_.animation_frame_count++;
1184 software_stats_.screen_frame_count++;
[email protected]fef5e3972012-08-07 03:59:471185 }
1186
[email protected]552e6002009-11-19 05:24:571187 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:291188 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:301189 PaintAggregator::PendingUpdate update;
1190 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:291191
[email protected]53d3f302009-12-21 04:42:051192 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:181193 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:291194
[email protected]29ed96a2012-02-04 18:12:161195 // Notify derived classes that we're about to initiate a paint.
1196 WillInitiatePaint();
1197
[email protected]ca4847f2010-09-24 05:39:151198 // A plugin may be able to do an optimized paint. First check this, in which
1199 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:461200 // This optimization allows PPAPI plugins that declare themselves on top of
1201 // the page (like a traditional windowed plugin) to be able to animate (think
1202 // movie playing) without repeatedly re-painting the page underneath, or
1203 // copying the plugin backing store (since we can send the plugin's backing
1204 // store directly to the browser).
1205 //
1206 // This optimization only works when the entire invalid region is contained
1207 // within the plugin. There is a related optimization in PaintRect for the
1208 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:151209 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:151210 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201211 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:211212 DCHECK(!pending_update_params_.get());
1213 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551214 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211215 pending_update_params_->scroll_rect = update.scroll_rect;
1216 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211217 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1218 pending_update_params_->flags = next_paint_flags_;
1219 pending_update_params_->scroll_offset = GetScrollOffset();
1220 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091221 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211222 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091223 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211224
[email protected]256737c2013-06-08 04:39:101225 if (!is_accelerated_compositing_active_)
1226 pending_update_params_->latency_info = latency_info_;
1227
1228 latency_info_.Clear();
1229
[email protected]ca4847f2010-09-24 05:39:151230 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561231 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151232 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201233 &optimized_copy_rect,
1234 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271235 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471236 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211237 pending_update_params_->bitmap = dib->id();
1238 pending_update_params_->bitmap_rect = optimized_copy_location;
1239 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201240 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561241 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461242 // Compute a buffer for painting and cache it.
[email protected]4889bd212013-02-11 22:23:101243
1244 bool fractional_scale = device_scale_factor_ -
1245 static_cast<int>(device_scale_factor_) != 0;
1246 if (fractional_scale) {
1247 // Damage might not be DIP aligned. Inflate damage to compensate.
1248 bounds.Inset(-1, -1);
1249 bounds.Intersect(gfx::Rect(size_));
1250 }
1251
1252 gfx::Rect pixel_bounds = gfx::ToEnclosingRect(
[email protected]ce112fe2012-10-29 22:52:181253 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]4889bd212013-02-11 22:23:101254
[email protected]ca4847f2010-09-24 05:39:151255 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351256 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591257 pixel_bounds));
[email protected]59383c782013-04-17 16:43:271258 if (!canvas) {
[email protected]f98d7e3c2010-09-13 22:30:461259 NOTREACHED();
1260 return;
1261 }
[email protected]cef3362f2009-12-21 17:48:451262
[email protected]f98d7e3c2010-09-13 22:30:461263 // We may get back a smaller canvas than we asked for.
1264 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591265 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1266 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1267 pixel_bounds.set_width(canvas->getDevice()->width());
1268 pixel_bounds.set_height(canvas->getDevice()->height());
1269 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1270 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051271
[email protected]f98d7e3c2010-09-13 22:30:461272 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1273
[email protected]aa4117f2011-12-09 22:19:211274 pending_update_params_->bitmap = current_paint_buf_->id();
1275 pending_update_params_->bitmap_rect = bounds;
1276
1277 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461278 // The scroll damage is just another rectangle to paint and copy.
1279 copy_rects.swap(update.paint_rects);
1280 if (!scroll_damage.IsEmpty())
1281 copy_rects.push_back(scroll_damage);
1282
[email protected]4889bd212013-02-11 22:23:101283 for (size_t i = 0; i < copy_rects.size(); ++i) {
1284 gfx::Rect rect = copy_rects[i];
1285 if (fractional_scale) {
1286 // Damage might not be DPI aligned. Inflate rect to compensate.
1287 rect.Inset(-1, -1);
1288 }
1289 PaintRect(rect, pixel_bounds.origin(), canvas.get());
1290 }
[email protected]60a50072012-01-11 02:05:351291
1292 // Software FPS tick for performance tests. The accelerated path traces the
1293 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1294 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421295 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW",
1296 TRACE_EVENT_SCOPE_THREAD);
[email protected]f98d7e3c2010-09-13 22:30:461297 } else { // Accelerated compositing path
1298 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211299 // If painting is done via the gpu process then we don't set any damage
1300 // rects to save the browser process from doing unecessary work.
1301 pending_update_params_->bitmap_rect = bounds;
1302 pending_update_params_->scroll_rect = gfx::Rect();
1303 // We don't need an ack, because we're not sharing a DIB with the browser.
1304 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1305 // with the browser for the GPU surface.
1306 pending_update_params_->needs_ack = false;
[email protected]f0c2a242013-03-15 19:34:521307 Composite(frame_begin_ticks);
[email protected]f98d7e3c2010-09-13 22:30:461308 }
1309
[email protected]936c6f52011-12-13 01:35:261310 // If we're holding a pending input event ACK, send the ACK before sending the
1311 // UpdateReply message so we can receive another input event before the
1312 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1313 // the UpdateRect IPC message handler.
[email protected]59383c782013-04-17 16:43:271314 if (pending_input_event_ack_)
[email protected]936c6f52011-12-13 01:35:261315 Send(pending_input_event_ack_.release());
1316
[email protected]ab543072013-01-25 04:38:151317 // If Composite() called SwapBuffers, pending_update_params_ will be reset (in
[email protected]aa4117f2011-12-09 22:19:211318 // OnSwapBuffersPosted), meaning a message has been added to the
1319 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1320 // the message now.
[email protected]59383c782013-04-17 16:43:271321 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:211322 // sending an ack to browser process that the paint is complete...
1323 update_reply_pending_ = pending_update_params_->needs_ack;
1324 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1325 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341326 }
[email protected]53d3f302009-12-21 04:42:051327
[email protected]29ed96a2012-02-04 18:12:161328 // If we're software rendering then we're done initiating the paint.
1329 if (!is_accelerated_compositing_active_)
1330 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291331}
1332
[email protected]f0c2a242013-03-15 19:34:521333void RenderWidget::Composite(base::TimeTicks frame_begin_time) {
[email protected]ab543072013-01-25 04:38:151334 DCHECK(is_accelerated_compositing_active_);
[email protected]ba91a792013-02-06 09:48:281335 if (compositor_) // TODO(jamesr): Figure out how this can be null.
[email protected]f0c2a242013-03-15 19:34:521336 compositor_->Composite(frame_begin_time);
[email protected]ab543072013-01-25 04:38:151337}
1338
initial.commit09911bf2008-07-26 23:55:291339///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461340// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291341
[email protected]4873c7d2009-07-16 06:36:281342void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]479b0172012-10-29 19:27:091343 TRACE_EVENT2("renderer", "RenderWidget::didInvalidateRect",
1344 "width", rect.width, "height", rect.height);
[email protected]552e6002009-11-19 05:24:571345 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481346 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181347 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571348 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291349 return;
1350
[email protected]552e6002009-11-19 05:24:571351 paint_aggregator_.InvalidateRect(damaged_rect);
1352
1353 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241354 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571355 return;
1356 if (!paint_aggregator_.HasPendingUpdate())
1357 return;
[email protected]aa4117f2011-12-09 22:19:211358 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241359 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1360 return;
1361
1362 // When GPU rendering, combine pending animations and invalidations into
1363 // a single update.
[email protected]816edc62012-03-17 01:27:221364 if (is_accelerated_compositing_active_ &&
1365 animation_update_pending_ &&
1366 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571367 return;
1368
1369 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291370 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1371 // on the call stack.
1372 // 2) Allows us to collect more damage rects before painting to help coalesce
1373 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241374 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111375 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211376 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291377}
1378
[email protected]990278ff2012-11-13 02:12:551379void RenderWidget::didScrollRect(int dx, int dy,
1380 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461381 // Drop scrolls on the floor when we are in compositing mode.
1382 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561383 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461384 return;
1385
[email protected]552e6002009-11-19 05:24:571386 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481387 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181388 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571389 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291390 return;
1391
[email protected]990278ff2012-11-13 02:12:551392 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571393
1394 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241395 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571396 return;
1397 if (!paint_aggregator_.HasPendingUpdate())
1398 return;
[email protected]aa4117f2011-12-09 22:19:211399 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241400 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1401 return;
1402
1403 // When GPU rendering, combine pending animations and invalidations into
1404 // a single update.
[email protected]816edc62012-03-17 01:27:221405 if (is_accelerated_compositing_active_ &&
1406 animation_update_pending_ &&
1407 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571408 return;
1409
1410 // Perform updating asynchronously. This serves two purposes:
1411 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1412 // on the call stack.
1413 // 2) Allows us to collect more damage rects before painting to help coalesce
1414 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241415 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111416 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211417 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291418}
1419
[email protected]244ac1892011-12-02 17:04:471420void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091421 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451422 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581423
[email protected]eac2b362013-05-22 07:01:451424 // If we don't clear PaintAggregator after changing autoResize state, then
1425 // we might end up in a situation where bitmap_rect is larger than the
1426 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1427 // with invalid damage rects.
1428 paint_aggregator_.ClearPendingUpdate();
1429
[email protected]70dee7e2013-05-29 18:28:301430 if (RenderThreadImpl::current()->layout_test_mode()) {
[email protected]eac2b362013-05-22 07:01:451431 WebRect new_pos(rootWindowRect().x,
1432 rootWindowRect().y,
1433 new_size.width,
1434 new_size.height);
1435 view_screen_rect_ = new_pos;
1436 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031437 }
[email protected]20fbfc22013-05-08 20:50:581438
[email protected]eac2b362013-05-22 07:01:451439 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581440
[email protected]70dee7e2013-05-29 18:28:301441 if (!RenderThreadImpl::current()->layout_test_mode())
[email protected]20fbfc22013-05-08 20:50:581442 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091443 }
[email protected]244ac1892011-12-02 17:04:471444}
1445
[email protected]3a1c8a8032013-03-18 22:35:321446void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051447 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1448 device_scale_factor_));
1449 if (compositor_)
1450 compositor_->setViewportSize(size_, physical_backing_size_);
1451}
1452
[email protected]91acd1c2012-03-14 08:32:391453void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221454 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1455
[email protected]c63b4d42012-04-26 01:01:071456#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211457 if (!is_accelerated_compositing_active_) {
1458 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1459 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1460 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1461 // going to switch to accelerated compositing, the GPU process may need
1462 // round-trips to the browser's UI thread before finishing the frame,
1463 // causing deadlocks if we delay the UpdateRect until we receive the
1464 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071465 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1466 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211467 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1468 }
[email protected]c63b4d42012-04-26 01:01:071469#endif
[email protected]aa4117f2011-12-09 22:19:211470
[email protected]ea162f92011-10-04 23:08:221471 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421472 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241473 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221474}
1475
1476void RenderWidget::didDeactivateCompositor() {
1477 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1478
1479 is_accelerated_compositing_active_ = false;
1480 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1481 routing_id_, is_accelerated_compositing_active_));
1482
[email protected]ea162f92011-10-04 23:08:221483 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241484 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091485
1486 // In single-threaded mode, we exit force compositing mode and re-enter in
1487 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1488 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1489 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361490 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091491 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561492}
1493
[email protected]e195e582013-03-08 01:32:591494void RenderWidget::initializeLayerTreeView() {
1495 compositor_ = RenderWidgetCompositor::Create(this);
1496 if (!compositor_)
1497 return;
1498
1499 compositor_->setViewportSize(size_, physical_backing_size_);
1500 if (init_complete_)
1501 compositor_->setSurfaceReady();
1502}
1503
[email protected]8926c602013-01-23 05:32:061504WebKit::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281505 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061506}
1507
[email protected]9ed83fe2013-02-27 01:52:281508void RenderWidget::suppressCompositorScheduling(bool enable) {
1509 if (compositor_)
1510 compositor_->SetSuppressScheduleComposite(enable);
1511}
1512
[email protected]9cd43a62012-03-26 08:03:561513void RenderWidget::willBeginCompositorFrame() {
1514 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371515
[email protected]ea5f70a2013-03-07 12:30:361516 DCHECK(RenderThreadImpl::current()->compositor_message_loop_proxy());
[email protected]abe8b3a2012-03-28 21:19:371517
1518 // The following two can result in further layout and possibly
1519 // enable GPU acceleration so they need to be called before any painting
1520 // is done.
[email protected]2d354272013-01-14 00:59:061521 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]abe8b3a2012-03-28 21:19:371522 UpdateSelectionBounds();
1523
[email protected]9cd43a62012-03-26 08:03:561524 WillInitiatePaint();
1525}
1526
[email protected]3391a0772012-03-28 00:32:071527void RenderWidget::didBecomeReadyForAdditionalInput() {
1528 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]59383c782013-04-17 16:43:271529 if (pending_input_event_ack_)
[email protected]3391a0772012-03-28 00:32:071530 Send(pending_input_event_ack_.release());
1531}
1532
[email protected]6fceb912013-02-15 06:24:151533void RenderWidget::DidCommitCompositorFrame() {
1534}
1535
[email protected]58264a32011-11-17 23:36:151536void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501537 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351538 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1539 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421540 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU",
1541 TRACE_EVENT_SCOPE_THREAD);
[email protected]29ed96a2012-02-04 18:12:161542 // Notify subclasses that we initiated the paint operation.
1543 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151544}
1545
1546void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181547 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1548
1549 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561550 DidFlushPaint();
1551
[email protected]aa4117f2011-12-09 22:19:211552 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151553 return;
1554
[email protected]ea3ee0a2012-05-15 03:43:091555 if (!next_paint_flags_ &&
1556 !need_update_rect_for_auto_resize_ &&
1557 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151558 return;
[email protected]ea3ee0a2012-05-15 03:43:091559 }
[email protected]58264a32011-11-17 23:36:151560
1561 ViewHostMsg_UpdateRect_Params params;
1562 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151563 params.plugin_window_moves.swap(plugin_window_moves_);
1564 params.flags = next_paint_flags_;
1565 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121566 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091567 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151568
1569 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1570 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091571 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151572}
1573
[email protected]f98d7e3c2010-09-13 22:30:461574void RenderWidget::scheduleComposite() {
[email protected]479b0172012-10-29 19:27:091575 TRACE_EVENT0("gpu", "RenderWidget::scheduleComposite");
[email protected]ea5f70a2013-03-07 12:30:361576 if (RenderThreadImpl::current()->compositor_message_loop_proxy() &&
[email protected]ba91a792013-02-06 09:48:281577 compositor_) {
1578 compositor_->setNeedsRedraw();
[email protected]d0be63772011-12-20 23:18:041579 } else {
[email protected]c3d45532011-10-07 19:20:401580 // TODO(nduca): replace with something a little less hacky. The reason this
1581 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1582 // contains a lot of host-renderer synchronization logic that is still
1583 // important for the accelerated compositing case. The option of simply
1584 // duplicating all that code is less desirable than "faking out" the
1585 // invalidation path using a magical damage rect.
1586 didInvalidateRect(WebRect(0, 0, 1, 1));
1587 }
[email protected]f98d7e3c2010-09-13 22:30:461588}
1589
[email protected]5f8b1022011-01-21 23:34:501590void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201591 if (animation_update_pending_)
1592 return;
1593
[email protected]921244e42011-07-20 16:36:301594 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201595 animation_update_pending_ = true;
1596 if (!animation_timer_.IsRunning()) {
1597 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1598 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211599 }
[email protected]5f8b1022011-01-21 23:34:501600}
1601
[email protected]4873c7d2009-07-16 06:36:281602void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301603 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521604 WebCursor cursor;
1605 webkit_glue::InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291606 // Only send a SetCursor message if we need to make a change.
1607 if (!current_cursor_.IsEqual(cursor)) {
1608 current_cursor_ = cursor;
1609 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1610 }
1611}
1612
1613// We are supposed to get a single call to Show for a newly created RenderWidget
1614// that was created via RenderWidget::CreateWebView. So, we wait until this
1615// point to dispatch the ShowWidget message.
1616//
1617// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281618// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291619//
[email protected]4873c7d2009-07-16 06:36:281620void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291621 DCHECK(!did_show_) << "received extraneous Show call";
1622 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1623 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1624
[email protected]8de12d942010-11-17 20:42:441625 if (did_show_)
1626 return;
1627
1628 did_show_ = true;
1629 // NOTE: initial_pos_ may still have its default values at this point, but
1630 // that's okay. It'll be ignored if as_popup is false, or the browser
1631 // process will impose a default position otherwise.
1632 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1633 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291634}
1635
[email protected]9b003482013-05-21 14:00:171636void RenderWidget::didProgrammaticallyScroll(
1637 const WebKit::WebPoint& scroll_point) {
1638 if (!compositor_)
1639 return;
1640 Send(new ViewHostMsg_DidProgrammaticallyScroll(
1641 routing_id_, gfx::Vector2d(scroll_point.x, scroll_point.y)));
1642}
1643
[email protected]4873c7d2009-07-16 06:36:281644void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291645}
1646
[email protected]4873c7d2009-07-16 06:36:281647void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291648}
1649
[email protected]2533ce12009-05-09 00:02:241650void RenderWidget::DoDeferredClose() {
1651 Send(new ViewHostMsg_Close(routing_id_));
1652}
1653
[email protected]4873c7d2009-07-16 06:36:281654void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321655 if (is_swapped_out_) {
1656 // This widget is currently swapped out, and the active widget is in a
1657 // different process. Have the browser route the close request to the
1658 // active widget instead, so that the correct unload handlers are run.
1659 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1660 return;
1661 }
1662
initial.commit09911bf2008-07-26 23:55:291663 // If a page calls window.close() twice, we'll end up here twice, but that's
1664 // OK. It is safe to send multiple Close messages.
1665
[email protected]2533ce12009-05-09 00:02:241666 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1667 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1668 // could be closed before the JS finishes executing. So instead, post a
1669 // message back to the message loop, which won't run until the JS is
1670 // complete, and then the Close message can be sent.
[email protected]dd32b1272013-05-04 14:17:111671 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211672 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291673}
1674
1675void RenderWidget::Close() {
1676 if (webwidget_) {
[email protected]8926c602013-01-23 05:32:061677 webwidget_->willCloseLayerTreeView();
[email protected]ba91a792013-02-06 09:48:281678 compositor_.reset();
[email protected]4873c7d2009-07-16 06:36:281679 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291680 webwidget_ = NULL;
1681 }
1682}
1683
[email protected]4873c7d2009-07-16 06:36:281684WebRect RenderWidget::windowRect() {
1685 if (pending_window_rect_count_)
1686 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241687
[email protected]80ad8622012-11-07 16:33:031688 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291689}
1690
[email protected]8a9d6ca32011-06-06 20:11:301691void RenderWidget::setToolTipText(const WebKit::WebString& text,
1692 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541693 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301694}
1695
[email protected]4873c7d2009-07-16 06:36:281696void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291697 if (did_show_) {
[email protected]70dee7e2013-05-29 18:28:301698 if (!RenderThreadImpl::current()->layout_test_mode()) {
[email protected]8be1c582013-03-06 00:55:031699 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1700 SetPendingWindowRect(pos);
1701 } else {
1702 WebSize new_size(pos.width, pos.height);
[email protected]d9083762013-03-24 01:36:401703 Resize(new_size, new_size, overdraw_bottom_height_,
1704 WebRect(), is_fullscreen_, NO_RESIZE_ACK);
[email protected]8be1c582013-03-06 00:55:031705 view_screen_rect_ = pos;
1706 window_screen_rect_ = pos;
1707 }
initial.commit09911bf2008-07-26 23:55:291708 } else {
1709 initial_pos_ = pos;
1710 }
1711}
1712
[email protected]2533ce12009-05-09 00:02:241713void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1714 pending_window_rect_ = rect;
1715 pending_window_rect_count_++;
1716}
1717
[email protected]4873c7d2009-07-16 06:36:281718WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241719 if (pending_window_rect_count_) {
1720 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1721 // the RootWindowRect is probably going to return wrong results since the
1722 // browser may not have processed the Move yet. There isn't really anything
1723 // good to do in this case, and it shouldn't happen - since this size is
1724 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281725 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241726 }
1727
[email protected]80ad8622012-11-07 16:33:031728 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371729}
1730
[email protected]4873c7d2009-07-16 06:36:281731WebRect RenderWidget::windowResizerRect() {
1732 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191733}
1734
[email protected]fa7b1dc2010-06-23 17:53:041735void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031736 // To prevent this renderer process from sending unnecessary IPC messages to
1737 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041738 // only during the input method attached to the browser process is active.
1739 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291740}
1741
[email protected]58b48a0d2012-06-13 07:01:351742void RenderWidget::UpdateCompositionInfo(
1743 const ui::Range& range,
1744 const std::vector<gfx::Rect>& character_bounds) {
1745 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1746 return;
1747 composition_character_bounds_ = character_bounds;
1748 composition_range_ = range;
1749 Send(new ViewHostMsg_ImeCompositionRangeChanged(
1750 routing_id(), composition_range_, composition_character_bounds_));
1751}
1752
[email protected]fa7b1dc2010-06-23 17:53:041753void RenderWidget::OnImeSetComposition(
1754 const string16& text,
1755 const std::vector<WebCompositionUnderline>& underlines,
1756 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281757 if (!webwidget_)
1758 return;
[email protected]66fca5bc2013-05-23 06:58:291759 ImeEventGuard guard(this);
[email protected]d4cff272011-05-02 15:46:011760 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041761 text, WebVector<WebCompositionUnderline>(underlines),
1762 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011763 // Setting the IME composition was successful. Send the new composition
1764 // range to the browser.
1765 ui::Range range(ui::Range::InvalidRange());
1766 size_t location, length;
1767 if (webwidget_->compositionRange(&location, &length)) {
1768 range.set_start(location);
1769 range.set_end(location + length);
1770 }
1771 // The IME was cancelled via the Esc key, so just send back the caret.
1772 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1773 range.set_start(location);
1774 range.set_end(location + length);
1775 }
[email protected]58b48a0d2012-06-13 07:01:351776 std::vector<gfx::Rect> character_bounds;
1777 GetCompositionCharacterBounds(&character_bounds);
1778 UpdateCompositionInfo(range, character_bounds);
[email protected]d4cff272011-05-02 15:46:011779 } else {
[email protected]fa7b1dc2010-06-23 17:53:041780 // If we failed to set the composition text, then we need to let the browser
1781 // process to cancel the input method's ongoing composition session, to make
1782 // sure we are in a consistent state.
1783 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011784
1785 // Send an updated IME range with just the caret range.
1786 ui::Range range(ui::Range::InvalidRange());
1787 size_t location, length;
1788 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1789 range.set_start(location);
1790 range.set_end(location + length);
1791 }
[email protected]58b48a0d2012-06-13 07:01:351792 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]7f00efa2010-04-15 05:01:261793 }
[email protected]fa7b1dc2010-06-23 17:53:041794}
1795
[email protected]4de6d1692011-10-12 08:45:441796void RenderWidget::OnImeConfirmComposition(
1797 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041798 if (!webwidget_)
1799 return;
[email protected]66fca5bc2013-05-23 06:58:291800 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041801 handling_input_event_ = true;
1802 webwidget_->confirmComposition(text);
1803 handling_input_event_ = false;
1804
[email protected]d4cff272011-05-02 15:46:011805 // Send an updated IME range with just the caret range.
1806 ui::Range range(ui::Range::InvalidRange());
1807 size_t location, length;
1808 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1809 range.set_start(location);
1810 range.set_end(location + length);
1811 }
[email protected]58b48a0d2012-06-13 07:01:351812 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
initial.commit09911bf2008-07-26 23:55:291813}
1814
[email protected]948f7ab72010-05-28 23:48:081815// This message causes the renderer to render an image of the
1816// desired_size, regardless of whether the tab is hidden or not.
[email protected]3d9ec5052013-01-02 22:05:251817void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle,
1818 int tag,
1819 const gfx::Size& page_size,
1820 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001821 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1822 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251823 // Close our unused handle.
1824#if defined(OS_WIN)
1825 ::CloseHandle(dib_handle);
1826#elif defined(OS_MACOSX)
1827 base::SharedMemory::CloseHandle(dib_handle);
1828#endif
1829 }
[email protected]d65adb12010-04-28 17:26:491830 return;
[email protected]45c6aad32010-11-11 04:46:251831 }
[email protected]d65adb12010-04-28 17:26:491832
[email protected]948f7ab72010-05-28 23:48:081833 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491834 // If one of these is empty, then we just return the dib we were
1835 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091836 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491837 return;
1838 }
1839
1840 // Map the given DIB ID into this process, and unmap it at the end
1841 // of this function.
[email protected]45c6aad32010-11-11 04:46:251842 scoped_ptr<TransportDIB> paint_at_size_buffer(
1843 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301844
[email protected]4b01b962012-10-09 23:17:351845 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281846 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:351847 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281848 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:511849 gfx::Size canvas_size = page_size_in_pixel;
1850 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:491851 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:511852 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:491853 static_cast<float>(canvas_size.height());
1854
[email protected]ee8d6fd2010-05-26 17:05:481855 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491856 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1857 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481858 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491859
[email protected]36808ad2010-10-20 19:18:301860 scoped_ptr<skia::PlatformCanvas> canvas(
1861 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1862 canvas_size.height()));
[email protected]59383c782013-04-17 16:43:271863 if (!canvas) {
[email protected]36808ad2010-10-20 19:18:301864 NOTREACHED();
1865 return;
1866 }
1867
[email protected]d65adb12010-04-28 17:26:491868 // Reset bounds to what we actually received, but they should be the
1869 // same.
1870 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1871 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1872 bounds.set_width(canvas->getDevice()->width());
1873 bounds.set_height(canvas->getDevice()->height());
1874
1875 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081876 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491877 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1878
[email protected]948f7ab72010-05-28 23:48:081879 // Have to make sure we're laid out at the right size before
1880 // rendering.
1881 gfx::Size old_size = webwidget_->size();
1882 webwidget_->resize(page_size);
1883 webwidget_->layout();
1884
[email protected]d65adb12010-04-28 17:26:491885 // Paint the entire thing (using original bounds, not scaled bounds).
1886 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1887 canvas->restore();
1888
[email protected]948f7ab72010-05-28 23:48:081889 // Return the widget to its previous size.
1890 webwidget_->resize(old_size);
1891
[email protected]c88c9442010-07-19 18:55:091892 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491893}
1894
[email protected]51a49502013-03-23 01:50:191895void RenderWidget::OnSnapshot(const gfx::Rect& src_subrect) {
1896 SkBitmap snapshot;
1897
1898 if (OnSnapshotHelper(src_subrect, &snapshot)) {
1899 Send(new ViewHostMsg_Snapshot(routing_id(), true, snapshot));
1900 } else {
1901 Send(new ViewHostMsg_Snapshot(routing_id(), false, SkBitmap()));
1902 }
1903}
1904
1905bool RenderWidget::OnSnapshotHelper(const gfx::Rect& src_subrect,
1906 SkBitmap* snapshot) {
1907 base::TimeTicks beginning_time = base::TimeTicks::Now();
1908
1909 if (!webwidget_ || src_subrect.IsEmpty())
1910 return false;
1911
1912 gfx::Rect viewport_size = gfx::IntersectRects(
1913 src_subrect, gfx::Rect(physical_backing_size_));
1914
1915 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(
1916 skia::CreatePlatformCanvas(viewport_size.width(),
1917 viewport_size.height(),
1918 true,
1919 NULL,
1920 skia::RETURN_NULL_ON_FAILURE));
[email protected]59383c782013-04-17 16:43:271921 if (!canvas)
[email protected]51a49502013-03-23 01:50:191922 return false;
1923
1924 canvas->save();
1925 webwidget_->layout();
1926
1927 PaintRect(viewport_size, viewport_size.origin(), canvas.get());
1928 canvas->restore();
1929
1930 const SkBitmap& bitmap = skia::GetTopDevice(*canvas)->accessBitmap(false);
1931 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1932 return false;
1933
1934 UMA_HISTOGRAM_TIMES("Renderer4.Snapshot",
1935 base::TimeTicks::Now() - beginning_time);
1936 return true;
1937}
1938
[email protected]0bc1f572013-04-17 01:46:311939void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121940 // During shutdown we can just ignore this message.
1941 if (!webwidget_)
1942 return;
1943
[email protected]0bc1f572013-04-17 01:46:311944 // Even if the browser provides an empty damage rect, it's still expecting to
1945 // receive a repaint ack so just damage the entire widget bounds.
1946 if (size_to_paint.IsEmpty()) {
1947 size_to_paint = size_;
1948 }
1949
[email protected]ec7dc112008-08-06 05:30:121950 set_next_paint_is_repaint_ack();
[email protected]0bc1f572013-04-17 01:46:311951 if (is_accelerated_compositing_active_ && compositor_) {
1952 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]f98d7e3c2010-09-13 22:30:461953 } else {
1954 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1955 didInvalidateRect(repaint_rect);
1956 }
[email protected]ec7dc112008-08-06 05:30:121957}
1958
[email protected]4a9dba42013-04-29 18:24:221959void RenderWidget::OnSmoothScrollCompleted() {
1960 pending_smooth_scroll_gesture_.Run();
[email protected]0e241b4b2012-08-18 09:06:271961}
1962
[email protected]4873c7d2009-07-16 06:36:281963void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111964 if (!webwidget_)
1965 return;
[email protected]4873c7d2009-07-16 06:36:281966 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111967}
1968
[email protected]80ad8622012-11-07 16:33:031969void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1970 const gfx::Rect& window_screen_rect) {
1971 view_screen_rect_ = view_screen_rect;
1972 window_screen_rect_ = window_screen_rect;
1973 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1974}
1975
[email protected]105dffb42013-02-20 03:46:211976#if defined(OS_ANDROID)
1977void RenderWidget::OnImeBatchStateChanged(bool is_begin) {
1978 Send(new ViewHostMsg_ImeBatchStateChanged_ACK(routing_id(), is_begin));
1979}
[email protected]2384b6c2013-02-28 23:58:511980
1981void RenderWidget::OnShowImeIfNeeded() {
1982 UpdateTextInputState(SHOW_IME_IF_NEEDED);
1983}
[email protected]105dffb42013-02-20 03:46:211984#endif
1985
[email protected]468ac582012-11-20 00:53:191986void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1987 if (device_scale_factor_ == device_scale_factor)
1988 return;
1989
1990 device_scale_factor_ = device_scale_factor;
1991
1992 if (!is_accelerated_compositing_active_) {
1993 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
1994 } else {
1995 scheduleComposite();
1996 }
1997}
1998
[email protected]719b36f2010-12-22 20:36:461999webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:152000 const gfx::Rect& paint_bounds,
2001 TransportDIB** dib,
2002 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:202003 gfx::Rect* clip,
2004 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:462005 // Bare RenderWidgets don't support optimized plugin painting.
2006 return NULL;
[email protected]ca4847f2010-09-24 05:39:152007}
2008
[email protected]ceb36f7d2012-10-31 18:33:242009gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:522010 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:242011 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:522012}
2013
[email protected]bee16aab2009-08-26 15:55:032014void RenderWidget::SetHidden(bool hidden) {
2015 if (is_hidden_ == hidden)
2016 return;
2017
2018 // The status has changed. Tell the RenderThread about it.
2019 is_hidden_ = hidden;
2020 if (is_hidden_)
[email protected]380244092011-10-07 17:26:272021 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:032022 else
[email protected]380244092011-10-07 17:26:272023 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:032024}
2025
[email protected]2b624c562011-10-27 22:58:262026void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262027 if (!webwidget_)
2028 return;
2029
2030 if (is_fullscreen_) {
2031 webwidget_->willExitFullScreen();
2032 } else {
2033 webwidget_->willEnterFullScreen();
2034 }
[email protected]2b624c562011-10-27 22:58:262035}
2036
2037void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262038 if (!webwidget_)
2039 return;
2040
2041 if (is_fullscreen_) {
2042 webwidget_->didEnterFullScreen();
2043 } else {
2044 webwidget_->didExitFullScreen();
2045 }
[email protected]2b624c562011-10-27 22:58:262046}
2047
[email protected]699ab0d2009-04-23 23:19:142048void RenderWidget::SetBackground(const SkBitmap& background) {
2049 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:462050
[email protected]699ab0d2009-04-23 23:19:142051 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:282052 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:142053}
2054
[email protected]674741932009-02-04 23:44:462055bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:052056 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462057}
2058
2059bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:052060 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462061}
2062
2063void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:052064 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462065}
2066
2067void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:052068 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:462069}
2070
2071void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:052072 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462073}
2074
[email protected]b18583c2012-12-18 06:55:272075static bool IsDateTimeInput(ui::TextInputType type) {
2076 return type == ui::TEXT_INPUT_TYPE_DATE ||
2077 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
2078 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
2079 type == ui::TEXT_INPUT_TYPE_MONTH ||
2080 type == ui::TEXT_INPUT_TYPE_TIME ||
2081 type == ui::TEXT_INPUT_TYPE_WEEK;
2082}
2083
[email protected]66fca5bc2013-05-23 06:58:292084
2085void RenderWidget::StartHandlingImeEvent() {
2086 DCHECK(!handling_ime_event_);
2087 handling_ime_event_ = true;
2088}
2089
2090void RenderWidget::FinishHandlingImeEvent() {
2091 DCHECK(handling_ime_event_);
2092 handling_ime_event_ = false;
2093 // While handling an ime event, text input state and selection bounds updates
2094 // are ignored. These must explicitly be updated once finished handling the
2095 // ime event.
2096 UpdateSelectionBounds();
2097 UpdateTextInputState(DO_NOT_SHOW_IME);
2098}
2099
[email protected]3306f262012-09-21 19:20:422100void RenderWidget::UpdateTextInputState(ShowIme show_ime) {
[email protected]e8f775f2013-02-14 21:00:502101 if (handling_ime_event_)
2102 return;
[email protected]3306f262012-09-21 19:20:422103 bool show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
2104 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:292105 return;
[email protected]ad26ef42011-06-17 07:59:452106 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:272107 if (IsDateTimeInput(new_type))
2108 return; // Not considered as a text input field in WebKit/Chromium.
2109
[email protected]5b739cb2012-08-21 20:35:212110 WebKit::WebTextInputInfo new_info;
2111 if (webwidget_)
2112 new_info = webwidget_->textInputInfo();
2113
[email protected]ad26ef42011-06-17 07:59:452114 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:212115
[email protected]3306f262012-09-21 19:20:422116 // Only sends text input params if they are changed or if the ime should be
2117 // shown.
2118 if (show_ime_if_needed || (text_input_type_ != new_type
2119 || text_input_info_ != new_info
2120 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:212121 ViewHostMsg_TextInputState_Params p;
2122 p.type = new_type;
2123 p.value = new_info.value.utf8();
2124 p.selection_start = new_info.selectionStart;
2125 p.selection_end = new_info.selectionEnd;
2126 p.composition_start = new_info.compositionStart;
2127 p.composition_end = new_info.compositionEnd;
2128 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:422129 p.show_ime_if_needed = show_ime_if_needed;
[email protected]5b739cb2012-08-21 20:35:212130 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
2131
2132 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:042133 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:452134 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:292135 }
initial.commit09911bf2008-07-26 23:55:292136}
2137
[email protected]7c8873e2013-02-05 08:03:012138void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2139 WebRect focus_webrect;
2140 WebRect anchor_webrect;
2141 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
2142 *focus = focus_webrect;
2143 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322144}
2145
[email protected]e99ef6f2011-10-16 01:13:002146void RenderWidget::UpdateSelectionBounds() {
2147 if (!webwidget_)
2148 return;
[email protected]66fca5bc2013-05-23 06:58:292149 if (handling_ime_event_)
2150 return;
[email protected]e99ef6f2011-10-16 01:13:002151
[email protected]7c8873e2013-02-05 08:03:012152 ViewHostMsg_SelectionBounds_Params params;
2153 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2154 if (selection_anchor_rect_ != params.anchor_rect ||
2155 selection_focus_rect_ != params.focus_rect) {
2156 selection_anchor_rect_ = params.anchor_rect;
2157 selection_focus_rect_ = params.focus_rect;
2158 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
[email protected]129b7382013-02-12 02:14:292159 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
[email protected]7c8873e2013-02-05 08:03:012160 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
[email protected]58b48a0d2012-06-13 07:01:352161 }
[email protected]e99ef6f2011-10-16 01:13:002162
[email protected]58b48a0d2012-06-13 07:01:352163 std::vector<gfx::Rect> character_bounds;
2164 GetCompositionCharacterBounds(&character_bounds);
2165 UpdateCompositionInfo(composition_range_, character_bounds);
2166}
2167
2168bool RenderWidget::ShouldUpdateCompositionInfo(
2169 const ui::Range& range,
2170 const std::vector<gfx::Rect>& bounds) {
2171 if (composition_range_ != range)
2172 return true;
2173 if (bounds.size() != composition_character_bounds_.size())
2174 return true;
2175 for (size_t i = 0; i < bounds.size(); ++i) {
2176 if (bounds[i] != composition_character_bounds_[i])
2177 return true;
2178 }
2179 return false;
[email protected]e99ef6f2011-10-16 01:13:002180}
2181
[email protected]73bf95812011-10-12 11:38:322182// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:452183COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
2184 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
2185COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
2186 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
2187COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
2188 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:182189COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
2190 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
2191COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
2192 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
2193COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
2194 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
2195COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
2196 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
2197COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
2198 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:002199COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
2200 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
2201COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
2202 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
2203COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
2204 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
2205COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
2206 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
2207COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
2208 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
2209COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
2210 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:012211COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
2212 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
2213COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
2214 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]8b4992e2013-03-01 15:42:152215COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeField) == \
2216 int(ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:452217
[email protected]5b739cb2012-08-21 20:35:212218ui::TextInputType RenderWidget::WebKitToUiTextInputType(
2219 WebKit::WebTextInputType type) {
2220 // Check the type is in the range representable by ui::TextInputType.
2221 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
2222 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
2223 return static_cast<ui::TextInputType>(type);
2224}
2225
[email protected]ad26ef42011-06-17 07:59:452226ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272227 if (webwidget_)
2228 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452229 return ui::TEXT_INPUT_TYPE_NONE;
2230}
2231
[email protected]58b48a0d2012-06-13 07:01:352232void RenderWidget::GetCompositionCharacterBounds(
2233 std::vector<gfx::Rect>* bounds) {
2234 DCHECK(bounds);
2235 bounds->clear();
2236}
2237
[email protected]ad26ef42011-06-17 07:59:452238bool RenderWidget::CanComposeInline() {
2239 return true;
[email protected]56ea1a62011-05-30 07:05:572240}
2241
[email protected]4873c7d2009-07-16 06:36:282242WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042243 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282244}
2245
[email protected]f660d9c2012-06-06 18:31:212246float RenderWidget::deviceScaleFactor() {
2247 return device_scale_factor_;
2248}
2249
[email protected]fa7b1dc2010-06-23 17:53:042250void RenderWidget::resetInputMethod() {
2251 if (!input_method_is_active_)
2252 return;
2253
2254 // If the last text input type is not None, then we should finish any
2255 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452256 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042257 // If a composition text exists, then we need to let the browser process
2258 // to cancel the input method's ongoing composition session.
2259 if (webwidget_->confirmComposition())
2260 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
2261 }
[email protected]d4cff272011-05-02 15:46:012262
2263 // Send an updated IME range with the current caret rect.
2264 ui::Range range(ui::Range::InvalidRange());
2265 size_t location, length;
2266 if (webwidget_->caretOrSelectionRange(&location, &length)) {
2267 range.set_start(location);
2268 range.set_end(location + length);
2269 }
[email protected]58b48a0d2012-06-13 07:01:352270
2271 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]fa7b1dc2010-06-23 17:53:042272}
2273
[email protected]c68c3e4e2013-01-24 00:36:562274void RenderWidget::didHandleGestureEvent(
2275 const WebGestureEvent& event,
2276 bool event_cancelled) {
2277#if defined(OS_ANDROID)
2278 if (event_cancelled)
2279 return;
2280 if (event.type == WebInputEvent::GestureTap ||
2281 event.type == WebInputEvent::GestureLongPress) {
2282 UpdateTextInputState(SHOW_IME_IF_NEEDED);
2283 }
2284#endif
2285}
2286
[email protected]f103ab72009-09-02 17:10:592287void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:502288 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292289 size_t i = 0;
2290 for (; i < plugin_window_moves_.size(); ++i) {
2291 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582292 if (move.rects_valid) {
2293 plugin_window_moves_[i] = move;
2294 } else {
2295 plugin_window_moves_[i].visible = move.visible;
2296 }
initial.commit09911bf2008-07-26 23:55:292297 break;
2298 }
2299 }
2300
2301 if (i == plugin_window_moves_.size())
2302 plugin_window_moves_.push_back(move);
2303}
[email protected]268654772009-08-06 23:02:042304
2305void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2306 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2307 i != plugin_window_moves_.end(); ++i) {
2308 if (i->window == window) {
2309 plugin_window_moves_.erase(i);
2310 break;
2311 }
2312 }
2313}
[email protected]67bfb83f2011-09-22 03:36:372314
[email protected]b63d58d2012-11-26 22:37:442315void RenderWidget::GetRenderingStats(
2316 WebKit::WebRenderingStatsImpl& stats) const {
[email protected]ba91a792013-02-06 09:48:282317 if (compositor_)
[email protected]635353c2013-03-06 09:11:202318 compositor_->GetRenderingStats(&stats.rendering_stats);
[email protected]b63d58d2012-11-26 22:37:442319
[email protected]62049562013-03-24 00:39:012320 stats.rendering_stats.animation_frame_count +=
2321 software_stats_.animation_frame_count;
2322 stats.rendering_stats.screen_frame_count +=
2323 software_stats_.screen_frame_count;
2324 stats.rendering_stats.total_paint_time +=
2325 software_stats_.total_paint_time;
2326 stats.rendering_stats.total_pixels_painted +=
2327 software_stats_.total_pixels_painted;
[email protected]fef5e3972012-08-07 03:59:472328}
2329
[email protected]e9ff79c2012-10-19 21:31:262330bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:522331 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
2332 if (!gpu_channel)
2333 return false;
2334
2335 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
2336}
2337
[email protected]24ed0432013-04-24 07:50:312338RenderWidgetCompositor* RenderWidget::compositor() const {
2339 return compositor_.get();
2340}
2341
[email protected]3639aa82013-06-04 11:00:042342void RenderWidget::OnSetBrowserRenderingStats(
2343 const BrowserRenderingStats& stats) {
2344 browser_rendering_stats_ = stats;
2345}
2346
2347void RenderWidget::GetBrowserRenderingStats(BrowserRenderingStats* stats) {
2348 *stats = browser_rendering_stats_;
2349}
2350
[email protected]0c2ebef2013-04-03 12:14:102351void RenderWidget::BeginSmoothScroll(
[email protected]0e241b4b2012-08-18 09:06:272352 bool down,
[email protected]ebd8b562012-10-09 14:44:292353 const SmoothScrollCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:192354 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:292355 int mouse_event_x,
2356 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:272357 DCHECK(!callback.is_null());
[email protected]267909d2012-10-20 04:36:192358
2359 ViewHostMsg_BeginSmoothScroll_Params params;
2360 params.scroll_down = down;
2361 params.pixels_to_scroll = pixels_to_scroll;
2362 params.mouse_event_x = mouse_event_x;
2363 params.mouse_event_y = mouse_event_y;
2364
[email protected]4a9dba42013-04-29 18:24:222365 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, params));
2366 pending_smooth_scroll_gesture_ = callback;
[email protected]a39ca1652012-07-13 21:30:582367}
2368
[email protected]a2b5ded2013-05-20 21:32:532369void RenderWidget::DidOverscroll(gfx::Vector2dF accumulated_overscroll,
2370 gfx::Vector2dF current_fling_velocity) {
2371 if (overscroll_notifications_enabled_) {
2372 Send(new ViewHostMsg_DidOverscroll(routing_id_,
2373 accumulated_overscroll,
2374 current_fling_velocity));
2375 }
2376}
2377
[email protected]67bfb83f2011-09-22 03:36:372378bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
2379 return false;
2380}
[email protected]c3d45532011-10-07 19:20:402381
[email protected]41d86852012-11-07 12:23:242382bool RenderWidget::WillHandleGestureEvent(
2383 const WebKit::WebGestureEvent& event) {
2384 return false;
2385}
2386
[email protected]ce6689f2013-03-29 12:52:552387void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2388 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2389}
2390
[email protected]3d5c243b2012-11-30 00:26:012391bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2392 return true;
2393}
2394
[email protected]3ae68c52013-04-12 06:10:052395WebGraphicsContext3DCommandBufferImpl* RenderWidget::CreateGraphicsContext3D(
[email protected]92fd8c02013-03-29 08:54:152396 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
[email protected]ed7defa2013-03-12 21:29:592397 if (!webwidget_)
2398 return NULL;
[email protected]8f746982013-03-21 06:28:032399 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
2400 new WebGraphicsContext3DCommandBufferImpl(
2401 surface_id(),
2402 GetURLForGraphicsContext3D(),
2403 RenderThreadImpl::current(),
2404 weak_ptr_factory_.GetWeakPtr()));
[email protected]ed7defa2013-03-12 21:29:592405
[email protected]990e4c212013-06-08 05:03:332406 if (!context->InitializeWithDefaultBufferSizes(
[email protected]8f746982013-03-21 06:28:032407 attributes,
2408 false /* bind generates resources */,
2409 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
2410 return NULL;
2411 return context.release();
[email protected]ed7defa2013-03-12 21:29:592412}
2413
[email protected]e9ff79c2012-10-19 21:31:262414} // namespace content