blob: 39b7b3f98a9e60d56e5cebd3b12c99c6d5287d27 [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]32876ae2011-11-15 22:25:217#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:008#include "base/command_line.h"
[email protected]366ae242011-05-10 02:23:589#include "base/debug/trace_event.h"
initial.commit09911bf2008-07-26 23:55:2910#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/scoped_ptr.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2114#include "base/stl_util.h"
[email protected]8a9d6ca32011-06-06 20:11:3015#include "base/utf_string_conversions.h"
[email protected]661eb9d2009-02-03 02:11:4816#include "build/build_config.h"
[email protected]681ccff2013-03-18 06:13:5217#include "cc/base/switches.h"
18#include "cc/base/thread.h"
19#include "cc/base/thread_impl.h"
[email protected]7f0d825f2013-03-18 07:24:3020#include "cc/output/output_surface.h"
[email protected]556fd292013-03-18 08:03:0421#include "cc/trees/layer_tree_host.h"
[email protected]ed7defa2013-03-12 21:29:5922#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]c084330e02013-04-27 01:08:1523#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1524#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5025#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2926#include "content/public/common/content_switches.h"
[email protected]ed7defa2013-03-12 21:29:5927#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]2847b222013-04-06 00:59:2428#include "content/renderer/gpu/compositor_software_output_device.h"
[email protected]ea5f70a2013-03-07 12:30:3629#include "content/renderer/gpu/input_handler_manager.h"
[email protected]ed7defa2013-03-12 21:29:5930#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]ba91a792013-02-06 09:48:2831#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]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]ed7defa2013-03-12 21:29:5938#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
[email protected]debc8e52013-01-15 03:43:1239#include "third_party/WebKit/Source/Platform/chromium/public/WebPoint.h"
40#include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
41#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
42#include "third_party/WebKit/Source/Platform/chromium/public/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)
65#include "content/renderer/android/synchronous_compositor_output_surface.h"
66#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.
218 return widget;
219 }
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)
308 if (CommandLine::ForCurrentProcess()->HasSwitch(
309 switches::kEnableSynchronousRendererCompositor)) {
310 return true;
311 }
312#endif
313 return false;
314}
315
[email protected]a95986a82010-12-24 06:19:28316bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
317 bool handled = true;
318 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15319 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22320 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
321 OnCursorVisibilityChange)
[email protected]c084330e02013-04-27 01:08:15322 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
323 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]a95986a82010-12-24 06:19:28324 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
325 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
326 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54327 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28328 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41329 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]992db4c2011-05-12 15:37:15330 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28331 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]ed7defa2013-03-12 21:29:59332 IPC_MESSAGE_HANDLER(ViewMsg_SwapBuffers_ACK,
333 OnViewContextSwapBuffersComplete)
[email protected]a95986a82010-12-24 06:19:28334 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
335 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
336 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]3d9ec5052013-01-02 22:05:25337 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnPaintAtSize)
338 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
339 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, OnSmoothScrollCompleted)
[email protected]a95986a82010-12-24 06:19:28340 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
341 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]6131a642012-06-15 23:26:53342 IPC_MESSAGE_HANDLER(ViewMsg_ScreenInfoChanged, OnScreenInfoChanged)
[email protected]80ad8622012-11-07 16:33:03343 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]105dffb42013-02-20 03:46:21344#if defined(OS_ANDROID)
345 IPC_MESSAGE_HANDLER(ViewMsg_ImeBatchStateChanged, OnImeBatchStateChanged)
[email protected]2384b6c2013-02-28 23:58:51346 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21347#endif
[email protected]51a49502013-03-23 01:50:19348 IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot)
[email protected]a95986a82010-12-24 06:19:28349 IPC_MESSAGE_UNHANDLED(handled = false)
350 IPC_END_MESSAGE_MAP()
351 return handled;
352}
initial.commit09911bf2008-07-26 23:55:29353
354bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15355 // Don't send any messages after the browser has told us to close, and filter
356 // most outgoing messages while swapped out.
357 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26358 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11359 closing_) {
initial.commit09911bf2008-07-26 23:55:29360 delete message;
361 return false;
362 }
363
364 // If given a messsage without a routing ID, then assign our routing ID.
365 if (message->routing_id() == MSG_ROUTING_NONE)
366 message->set_routing_id(routing_id_);
367
[email protected]380244092011-10-07 17:26:27368 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44369}
370
[email protected]61e2b3cc2012-03-02 16:13:34371void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44372 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40373 float overdraw_bottom_height,
[email protected]61e2b3cc2012-03-02 16:13:34374 const gfx::Rect& resizer_rect,
375 bool is_fullscreen,
376 ResizeAck resize_ack) {
377 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
378 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
379 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29380
[email protected]61e2b3cc2012-03-02 16:13:34381 // Ignore this during shutdown.
382 if (!webwidget_)
383 return;
384
[email protected]d9083762013-03-24 01:36:40385 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44386 compositor_->setViewportSize(new_size, physical_backing_size);
[email protected]d9083762013-03-24 01:36:40387 compositor_->SetOverdrawBottomHeight(overdraw_bottom_height);
388 }
[email protected]60d47ac2013-03-01 23:42:44389
[email protected]dade8992013-03-04 07:34:34390 physical_backing_size_ = physical_backing_size;
[email protected]d9083762013-03-24 01:36:40391 overdraw_bottom_height_ = overdraw_bottom_height;
[email protected]61e2b3cc2012-03-02 16:13:34392 resizer_rect_ = resizer_rect;
393
394 // NOTE: We may have entered fullscreen mode without changing our size.
395 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
396 if (fullscreen_change)
397 WillToggleFullscreen();
398 is_fullscreen_ = is_fullscreen;
399
400 if (size_ != new_size) {
401 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34402 needs_repainting_on_restore_ = false;
403
404 size_ = new_size;
405
406 paint_aggregator_.ClearPendingUpdate();
407
408 // When resizing, we want to wait to paint before ACK'ing the resize. This
409 // ensures that we only resize as fast as we can paint. We only need to
410 // send an ACK if we are resized to a non-empty rect.
411 webwidget_->resize(new_size);
[email protected]0b70dbe2013-05-10 19:06:32412
413 // Resize should have caused an invalidation of the entire view.
414 DCHECK(new_size.IsEmpty() || is_accelerated_compositing_active_ ||
415 paint_aggregator_.HasPendingUpdate());
[email protected]1f792d52013-05-22 06:52:45416 } else if (size_browser_expects_ == new_size) {
[email protected]632c4382013-05-15 08:58:45417 resize_ack = NO_RESIZE_ACK;
418 }
419
420 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
421 // For empty size or empty physical_backing_size, there is no next paint
422 // (along with which to send the ack) until they are set to non-empty.
[email protected]ff475a322012-03-14 00:05:35423 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34424 }
425
[email protected]20fbfc22013-05-08 20:50:58426 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45427 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58428 set_next_paint_is_resize_ack();
429
[email protected]61e2b3cc2012-03-02 16:13:34430 if (fullscreen_change)
431 DidToggleFullscreen();
432
433 // If a resize ack is requested and it isn't set-up, then no more resizes will
434 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45435 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29436}
437
438void RenderWidget::OnClose() {
439 if (closing_)
440 return;
441 closing_ = true;
442
443 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03444 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27445 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03446 SetHidden(false);
447 }
initial.commit09911bf2008-07-26 23:55:29448
initial.commit09911bf2008-07-26 23:55:29449 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25450 // now. Post a task that only gets invoked when there are no nested message
451 // loops.
[email protected]dd32b1272013-05-04 14:17:11452 base::MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29453 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25454
455 // Balances the AddRef taken when we called AddRoute.
456 Release();
initial.commit09911bf2008-07-26 23:55:29457}
458
[email protected]61e2b3cc2012-03-02 16:13:34459// Got a response from the browser after the renderer decided to create a new
460// view.
[email protected]fc4404d2012-11-07 19:53:30461void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34462 DCHECK(routing_id_ != MSG_ROUTING_NONE);
463
[email protected]fc4404d2012-11-07 19:53:30464 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34465}
466
[email protected]f21c613a2009-02-12 14:46:17467void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44468 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40469 float overdraw_bottom_height,
[email protected]ee41e7d22011-10-14 19:34:09470 const gfx::Rect& resizer_rect,
471 bool is_fullscreen) {
[email protected]d9083762013-03-24 01:36:40472 Resize(new_size, physical_backing_size, overdraw_bottom_height, resizer_rect,
473 is_fullscreen, SEND_RESIZE_ACK);
[email protected]1f792d52013-05-22 06:52:45474 size_browser_expects_ = new_size;
initial.commit09911bf2008-07-26 23:55:29475}
476
[email protected]b5913d72012-02-07 22:26:54477void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
478 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59479 gfx::Rect view_rect(size_);
480
[email protected]ce112fe2012-10-29 22:52:18481 gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_);
[email protected]b9769d82012-02-10 00:23:59482 if (!old_damage_rect.IsEmpty())
483 paint_aggregator_.InvalidateRect(old_damage_rect);
484
[email protected]ce112fe2012-10-29 22:52:18485 gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect);
[email protected]b9769d82012-02-10 00:23:59486 if (!new_damage_rect.IsEmpty())
487 paint_aggregator_.InvalidateRect(new_damage_rect);
488
[email protected]b5913d72012-02-07 22:26:54489 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59490
[email protected]b5913d72012-02-07 22:26:54491 if (webwidget_)
492 webwidget_->didChangeWindowResizerRect();
493 }
494}
495
initial.commit09911bf2008-07-26 23:55:29496void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31497 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29498 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03499 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29500}
501
[email protected]9e2e4632012-07-27 16:38:41502void RenderWidget::OnWasShown(bool needs_repainting) {
503 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29504 // During shutdown we can just ignore this message.
505 if (!webwidget_)
506 return;
507
508 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03509 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29510
511 if (!needs_repainting && !needs_repainting_on_restore_)
512 return;
513 needs_repainting_on_restore_ = false;
514
[email protected]d65adb12010-04-28 17:26:49515 // Tag the next paint as a restore ack, which is picked up by
516 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29517 set_next_paint_is_restore_ack();
518
519 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56520 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46521 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
522 } else {
523 scheduleComposite();
524 }
initial.commit09911bf2008-07-26 23:55:29525}
526
[email protected]992db4c2011-05-12 15:37:15527void RenderWidget::OnWasSwappedOut() {
528 // If we have been swapped out and no one else is using this process,
529 // it's safe to exit now. If we get swapped back in, we will call
530 // AddRefProcess in SetSwappedOut.
531 if (is_swapped_out_)
532 RenderProcess::current()->ReleaseProcess();
533}
534
[email protected]53d3f302009-12-21 04:42:05535void RenderWidget::OnRequestMoveAck() {
536 DCHECK(pending_window_rect_count_);
537 pending_window_rect_count_--;
538}
539
540void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58541 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21542 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05543 update_reply_pending_ = false;
[email protected]1f792d52013-05-22 06:52:45544 size_browser_expects_ = size_;
[email protected]53d3f302009-12-21 04:42:05545
[email protected]b4d08452010-10-05 17:34:35546 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
547 // have no current paint buffer.
548 if (current_paint_buf_) {
549 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
550 current_paint_buf_ = NULL;
551 }
552
[email protected]65225772011-05-12 21:10:24553 // If swapbuffers is still pending, then defer the update until the
554 // swapbuffers occurs.
555 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
556 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
557 return;
558 }
559
[email protected]29ed96a2012-02-04 18:12:16560 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18561 if (!is_accelerated_compositing_active_) {
562 DidFlushPaint();
563 }
[email protected]a2f6bc112009-06-27 16:27:25564
initial.commit09911bf2008-07-26 23:55:29565 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24566 DoDeferredUpdateAndSendInputAck();
567}
568
[email protected]d0be63772011-12-20 23:18:04569bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]ed7defa2013-03-12 21:29:59570 // Contexts using the command buffer support asynchronous swapbuffers.
571 // See RenderWidget::CreateOutputSurface().
[email protected]8f746982013-03-21 06:28:03572 if (RenderThreadImpl::current()->compositor_message_loop_proxy())
[email protected]ed7defa2013-03-12 21:29:59573 return false;
574
575 return true;
576}
577
578GURL RenderWidget::GetURLForGraphicsContext3D() {
579 return GURL();
[email protected]65225772011-05-12 21:10:24580}
581
[email protected]479b0172012-10-29 19:27:09582bool RenderWidget::ForceCompositingModeEnabled() {
583 return false;
584}
585
[email protected]ba91a792013-02-06 09:48:28586scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface() {
[email protected]c3e32ed42013-05-02 05:07:13587 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]a1811b8912013-05-09 15:35:19588
589#if defined(OS_ANDROID)
590 if (command_line.HasSwitch(switches::kEnableSynchronousRendererCompositor)) {
591 return scoped_ptr<cc::OutputSurface>(
592 new SynchronousCompositorOutputSurface(routing_id()));
593 }
594#endif
595
[email protected]8bbe3a92013-05-12 00:58:35596 if (command_line.HasSwitch(switches::kEnableSoftwareCompositingGLAdapter)) {
597 return scoped_ptr<cc::OutputSurface>(
598 new CompositorOutputSurface(routing_id(), NULL,
599 new CompositorSoftwareOutputDevice()));
600 }
601
[email protected]ed7defa2013-03-12 21:29:59602 // Explicitly disable antialiasing for the compositor. As of the time of
603 // this writing, the only platform that supported antialiasing for the
604 // compositor was Mac OS X, because the on-screen OpenGL context creation
605 // code paths on Windows and Linux didn't yet have multisampling support.
606 // Mac OS X essentially always behaves as though it's rendering offscreen.
607 // Multisampling has a heavy cost especially on devices with relatively low
608 // fill rate like most notebooks, and the Mac implementation would need to
609 // be optimized to resolve directly into the IOSurface shared between the
610 // GPU and browser processes. For these reasons and to avoid platform
611 // disparities we explicitly disable antialiasing.
612 WebKit::WebGraphicsContext3D::Attributes attributes;
613 attributes.antialias = false;
614 attributes.shareResources = true;
615 attributes.noAutomaticFlushes = true;
[email protected]a6886502013-05-16 20:59:18616 attributes.depth = false;
617 attributes.stencil = false;
[email protected]bec084292013-05-21 21:31:44618 if (command_line.HasSwitch(cc::switches::kForceDirectLayerDrawing))
619 attributes.stencil = true;
[email protected]3ae68c52013-04-12 06:10:05620 WebGraphicsContext3DCommandBufferImpl* context =
621 CreateGraphicsContext3D(attributes);
[email protected]8bbe3a92013-05-12 00:58:35622 if (!context)
623 return scoped_ptr<cc::OutputSurface>();
[email protected]ed7defa2013-03-12 21:29:59624
[email protected]2847b222013-04-06 00:59:24625 bool composite_to_mailbox =
[email protected]7b45b5762013-05-08 14:36:56626 command_line.HasSwitch(cc::switches::kCompositeToMailbox) &&
627 !command_line.HasSwitch(switches::kEnableDelegatedRenderer);
[email protected]2847b222013-04-06 00:59:24628 // No swap throttling yet when compositing on the main thread.
629 DCHECK(!composite_to_mailbox || is_threaded_compositing_enabled_);
630 return scoped_ptr<cc::OutputSurface>(composite_to_mailbox ?
631 new MailboxOutputSurface(routing_id(), context, NULL) :
632 new CompositorOutputSurface(routing_id(), context, NULL));
[email protected]ba91a792013-02-06 09:48:28633}
634
[email protected]ed7defa2013-03-12 21:29:59635void RenderWidget::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24636 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21637 while (!updates_pending_swap_.empty()) {
638 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
639 updates_pending_swap_.pop_front();
640 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
641 // compositing pass, hence doesn't require an UpdateRect message.
642 if (msg)
643 Send(msg);
644 }
[email protected]65225772011-05-12 21:10:24645 num_swapbuffers_complete_pending_ = 0;
646 using_asynchronous_swapbuffers_ = false;
647 // Schedule another frame so the compositor learns about it.
648 scheduleComposite();
649}
650
[email protected]ed7defa2013-03-12 21:29:59651void RenderWidget::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:08652 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21653
654 if (using_asynchronous_swapbuffers_) {
655 ViewHostMsg_UpdateRect* msg = NULL;
656 // pending_update_params_ can be NULL if the swap doesn't correspond to an
657 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
658 // message.
[email protected]59383c782013-04-17 16:43:27659 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:21660 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
661 pending_update_params_.reset();
662 }
663 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08664 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21665 }
[email protected]37a6f302011-07-11 23:43:08666}
667
[email protected]ed7defa2013-03-12 21:29:59668void RenderWidget::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24669 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16670
[email protected]404939f2012-06-01 04:06:18671 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16672 DidFlushPaint();
673
[email protected]65225772011-05-12 21:10:24674 // When compositing deactivates, we reset the swapbuffers pending count. The
675 // swapbuffers acks may still arrive, however.
676 if (num_swapbuffers_complete_pending_ == 0) {
677 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
678 return;
679 }
[email protected]aa4117f2011-12-09 22:19:21680 DCHECK(!updates_pending_swap_.empty());
681 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
682 updates_pending_swap_.pop_front();
683 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
684 // compositing pass, hence doesn't require an UpdateRect message.
685 if (msg)
686 Send(msg);
[email protected]65225772011-05-12 21:10:24687 num_swapbuffers_complete_pending_--;
688
689 // If update reply is still pending, then defer the update until that reply
690 // occurs.
[email protected]d0be63772011-12-20 23:18:04691 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24692 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
693 return;
694 }
695
696 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06697 // when we were previously rendering. However, if an invalidation task is not
698 // posted, there may be software rendering work pending. In that case, don't
699 // early out.
700 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24701 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
702 return;
703 }
704
[email protected]cc66e682012-10-02 06:48:18705 // Do not call DoDeferredUpdate unless there's animation work to be done or
706 // a real invalidation. This prevents rendering in response to a swapbuffers
707 // callback coming back after we've navigated away from the page that
708 // generated it.
709 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
710 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
711 return;
712 }
713
[email protected]65225772011-05-12 21:10:24714 // Continue painting if necessary...
715 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29716}
717
[email protected]0dea1652012-12-14 00:09:09718void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
[email protected]c2eaa8f2013-05-10 02:41:55719 const cc::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:09720 bool is_keyboard_shortcut) {
[email protected]5dd768212009-08-13 23:34:49721 handling_input_event_ = true;
[email protected]0dea1652012-12-14 00:09:09722 if (!input_event) {
[email protected]5dd768212009-08-13 23:34:49723 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29724 return;
[email protected]5dd768212009-08-13 23:34:49725 }
initial.commit09911bf2008-07-26 23:55:29726
[email protected]b4841e1c2013-05-16 22:30:10727 const char* const event_name = GetEventName(input_event->type);
728 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent",
729 "event", event_name);
730
[email protected]c2eaa8f2013-05-10 02:41:55731 if (compositor_)
732 compositor_->SetLatencyInfo(latency_info);
733
[email protected]6a4d7f62013-01-07 21:32:13734 base::TimeDelta now = base::TimeDelta::FromInternalValue(
735 base::TimeTicks::Now().ToInternalValue());
736
737 int64 delta = static_cast<int64>(
738 (now.InSecondsF() - input_event->timeStampSeconds) *
739 base::Time::kMicrosecondsPerSecond);
740 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer", delta, 0, 1000000, 100);
[email protected]de415552013-01-23 04:12:17741 base::HistogramBase* counter_for_type =
[email protected]bafdc5d52013-02-27 18:18:48742 base::Histogram::FactoryGet(
[email protected]b4841e1c2013-05-16 22:30:10743 base::StringPrintf("Event.Latency.Renderer.%s", event_name),
[email protected]bafdc5d52013-02-27 18:18:48744 0,
745 1000000,
[email protected]6a4d7f62013-01-07 21:32:13746 100,
[email protected]de415552013-01-23 04:12:17747 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]bafdc5d52013-02-27 18:18:48748 counter_for_type->Add(delta);
[email protected]6a4d7f62013-01-07 21:32:13749
[email protected]67bfb83f2011-09-22 03:36:37750 bool prevent_default = false;
751 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26752 const WebMouseEvent& mouse_event =
753 *static_cast<const WebMouseEvent*>(input_event);
754 TRACE_EVENT2("renderer", "HandleMouseMove",
755 "x", mouse_event.x, "y", mouse_event.y);
756 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37757 }
758
[email protected]41d86852012-11-07 12:23:24759 if (WebInputEvent::isGestureEventType(input_event->type)) {
760 const WebGestureEvent& gesture_event =
761 *static_cast<const WebGestureEvent*>(input_event);
762 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
763 }
764
[email protected]3ebcc7c2013-01-09 05:34:46765 if (input_event->type == WebInputEvent::GestureTap ||
766 input_event->type == WebInputEvent::GestureLongPress)
767 resetInputMethod();
768
[email protected]67bfb83f2011-09-22 03:36:37769 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12770 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
771 suppress_next_char_events_ = false;
772 if (!processed && webwidget_)
773 processed = webwidget_->handleInputEvent(*input_event);
774 }
775
776 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
777 // it's not processed by webkit, then we need to suppress the upcoming Char
778 // events.
779 if (!processed && is_keyboard_shortcut)
780 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29781
[email protected]3d5c243b2012-11-30 00:26:01782 InputEventAckState ack_result = processed ?
783 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
784 if (!processed && input_event->type == WebInputEvent::TouchStart) {
785 const WebTouchEvent& touch_event =
786 *static_cast<const WebTouchEvent*>(input_event);
787 ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ?
788 INPUT_EVENT_ACK_STATE_NOT_CONSUMED :
789 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
790 }
791
[email protected]a9fb30aa2011-10-06 06:58:46792 IPC::Message* response =
[email protected]c084330e02013-04-27 01:08:15793 new InputHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
794 ack_result);
[email protected]3391a0772012-03-28 00:32:07795 bool event_type_gets_rate_limited =
796 input_event->type == WebInputEvent::MouseMove ||
797 input_event->type == WebInputEvent::MouseWheel ||
798 WebInputEvent::isTouchEventType(input_event->type);
[email protected]8926c602013-01-23 05:32:06799
800 bool frame_pending = paint_aggregator_.HasPendingUpdate();
801 if (is_accelerated_compositing_active_) {
[email protected]ba91a792013-02-06 09:48:28802 frame_pending = compositor_ &&
803 compositor_->commitRequested();
[email protected]8926c602013-01-23 05:32:06804 }
805
[email protected]3391a0772012-03-28 00:32:07806 bool is_input_throttled =
[email protected]ce2b28e2012-08-09 15:53:57807 throttle_input_events_ &&
[email protected]8926c602013-01-23 05:32:06808 frame_pending;
[email protected]e2824412009-02-27 01:57:05809
[email protected]f8868d72012-04-27 19:13:03810 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24811 // We want to rate limit the input events in this case, so we'll wait for
812 // painting to finish before ACKing this message.
[email protected]59383c782013-04-17 16:43:27813 if (pending_input_event_ack_) {
[email protected]353a34c2010-05-28 23:35:17814 // As two different kinds of events could cause us to postpone an ack
815 // we send it now, if we have one pending. The Browser should never
816 // send us the same kind of event we are delaying the ack for.
817 Send(pending_input_event_ack_.release());
818 }
[email protected]12fbad812009-09-01 18:21:24819 pending_input_event_ack_.reset(response);
820 } else {
821 Send(response);
822 }
823
[email protected]3306f262012-09-21 19:20:42824#if defined(OS_ANDROID)
825 // Allow the IME to be shown when the focus changes as a consequence
826 // of a processed touch end event.
827 if (input_event->type == WebInputEvent::TouchEnd && processed)
828 UpdateTextInputState(SHOW_IME_IF_NEEDED);
829#endif
830
[email protected]5dd768212009-08-13 23:34:49831 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48832
[email protected]67bfb83f2011-09-22 03:36:37833 if (!prevent_default) {
834 if (WebInputEvent::isKeyboardEventType(input_event->type))
835 DidHandleKeyEvent();
836 if (WebInputEvent::isMouseEventType(input_event->type))
837 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24838 if (WebInputEvent::isTouchEventType(input_event->type))
839 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37840 }
initial.commit09911bf2008-07-26 23:55:29841}
842
[email protected]34202de2013-05-06 23:36:22843void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
844 if (webwidget_)
845 webwidget_->setCursorVisibilityState(is_visible);
846}
847
initial.commit09911bf2008-07-26 23:55:29848void RenderWidget::OnMouseCaptureLost() {
849 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28850 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29851}
852
853void RenderWidget::OnSetFocus(bool enable) {
854 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33855 if (webwidget_)
856 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29857}
858
859void RenderWidget::ClearFocus() {
860 // We may have got the focus from the browser before this gets processed, in
861 // which case we do not want to unfocus ourself.
862 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28863 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29864}
865
[email protected]2d5d09d52009-06-15 14:29:21866void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00867 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21868 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06869 TRACE_EVENT2("renderer", "PaintRect",
870 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:45871
872 const bool kEnableGpuBenchmarking =
873 CommandLine::ForCurrentProcess()->HasSwitch(
874 switches::kEnableGpuBenchmarking);
[email protected]4fb66842009-12-04 21:41:00875 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21876
877 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00878 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
879 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03880
[email protected]699ab0d2009-04-23 23:19:14881 // If there is a custom background, tile it.
882 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14883 SkPaint paint;
[email protected]4e29afd2012-12-04 04:07:11884 skia::RefPtr<SkShader> shader = skia::AdoptRef(
885 SkShader::CreateBitmapShader(background_,
886 SkShader::kRepeat_TileMode,
887 SkShader::kRepeat_TileMode));
888 paint.setShader(shader.get());
[email protected]fb10ec5b2011-10-24 17:54:20889
890 // Use kSrc_Mode to handle background_ transparency properly.
891 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
892
893 // Canvas could contain multiple update rects. Clip to given rect so that
894 // we don't accidentally clear other update rects.
895 canvas->save();
[email protected]aa7e7a12013-02-22 13:37:44896 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]1835b9e2012-02-28 13:12:48897 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14898 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20899 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14900 }
901
[email protected]719b36f2010-12-22 20:36:46902 // First see if this rect is a plugin that can paint itself faster.
903 TransportDIB* optimized_dib = NULL;
904 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:20905 float dib_scale_factor;
[email protected]719b36f2010-12-22 20:36:46906 webkit::ppapi::PluginInstance* optimized_instance =
907 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
908 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:20909 &optimized_copy_rect,
910 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:46911 if (optimized_instance) {
912 // This plugin can be optimize-painted and we can just ask it to paint
913 // itself. We don't actually need the TransportDIB in this case.
914 //
915 // This is an optimization for PPAPI plugins that know they're on top of
916 // the page content. If this rect is inside such a plugin, we can save some
917 // time and avoid re-rendering the page content which we know will be
918 // covered by the plugin later (this time can be significant, especially
919 // for a playing movie that is invalidating a lot).
920 //
921 // In the plugin movie case, hopefully the similar call to
922 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
923 // painting, because that avoids copying the plugin image to a different
924 // paint rect. Unfortunately, if anything on the page is animating other
925 // than the movie, it break this optimization since the union of the
926 // invalid regions will be larger than the plugin.
927 //
928 // This code optimizes that case, where we can still avoid painting in
929 // WebKit and filling the background (which can be slow) and just painting
930 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
931 // required.
[email protected]63ab54262012-11-09 15:58:45932 base::TimeTicks paint_begin_ticks;
933 if (kEnableGpuBenchmarking)
934 paint_begin_ticks = base::TimeTicks::HighResNow();
935
[email protected]df59dd42012-09-14 22:56:30936 SkAutoCanvasRestore auto_restore(canvas, true);
937 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]719b36f2010-12-22 20:36:46938 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27939 optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:21940 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45941 if (kEnableGpuBenchmarking) {
942 base::TimeDelta paint_time =
943 base::TimeTicks::HighResNow() - paint_begin_ticks;
944 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01945 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45946 }
[email protected]719b36f2010-12-22 20:36:46947 } else {
948 // Normal painting case.
[email protected]63ab54262012-11-09 15:58:45949 base::TimeTicks paint_begin_ticks;
950 if (kEnableGpuBenchmarking)
951 paint_begin_ticks = base::TimeTicks::HighResNow();
952
[email protected]719b36f2010-12-22 20:36:46953 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
[email protected]63ab54262012-11-09 15:58:45954
955 if (kEnableGpuBenchmarking) {
956 base::TimeDelta paint_time =
957 base::TimeTicks::HighResNow() - paint_begin_ticks;
958 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01959 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45960 }
[email protected]719b36f2010-12-22 20:36:46961
962 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35963 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46964 }
initial.commit09911bf2008-07-26 23:55:29965
[email protected]4fb66842009-12-04 21:41:00966 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00967 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45968
969 if (kEnableGpuBenchmarking) {
[email protected]63ab54262012-11-09 15:58:45970 int64 num_pixels_processed = rect.width() * rect.height();
[email protected]62049562013-03-24 00:39:01971 software_stats_.total_pixels_painted += num_pixels_processed;
[email protected]63ab54262012-11-09 15:58:45972 }
[email protected]4fb66842009-12-04 21:41:00973}
974
975void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
976 skia::PlatformCanvas* canvas) {
977 static bool kPaintBorder =
978 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
979 if (!kPaintBorder)
980 return;
981
[email protected]53d3f302009-12-21 04:42:05982 // Cycle through these colors to help distinguish new paint rects.
983 const SkColor colors[] = {
984 SkColorSetARGB(0x3F, 0xFF, 0, 0),
985 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
986 SkColorSetARGB(0x3F, 0, 0, 0xFF),
987 };
988 static int color_selector = 0;
989
[email protected]4fb66842009-12-04 21:41:00990 SkPaint paint;
991 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05992 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00993 paint.setStrokeWidth(1);
994
995 SkIRect irect;
996 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
997 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29998}
999
[email protected]52ccd0ea2011-02-16 01:09:051000void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:301001 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:301002 if (!animation_update_pending_) {
1003 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:591004 return;
[email protected]921244e42011-07-20 16:36:301005 }
[email protected]bd37ae252011-06-03 01:28:181006 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:591007 // Record when we fired (according to base::Time::Now()) relative to when
1008 // we posted the task to quantify how much the base::Time/base::TimeTicks
1009 // skew is affecting animations.
1010 base::TimeDelta animation_callback_delay = base::Time::Now() -
1011 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
1012 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
1013 animation_callback_delay,
1014 base::TimeDelta::FromMilliseconds(0),
1015 base::TimeDelta::FromMilliseconds(30),
1016 25);
1017 }
[email protected]65225772011-05-12 21:10:241018 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:241019}
1020
[email protected]52ccd0ea2011-02-16 01:09:051021void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:591022 if (!animation_update_pending_)
1023 return;
[email protected]bd37ae252011-06-03 01:28:181024
1025 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:331026 base::TimeDelta animationInterval = IsRenderingVSynced() ?
1027 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:181028
[email protected]7c4329e2011-02-18 22:02:591029 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:451030
1031 // animation_floor_time_ is the earliest time that we should animate when
1032 // using the dead reckoning software scheduler. If we're using swapbuffers
1033 // complete callbacks to rate limit, we can ignore this floor.
1034 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:301035 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:331036 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:181037 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:591038 // running animation callbacks so that if a callback requests another
1039 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:381040 animation_timer_.Stop();
1041 animation_timer_.Start(FROM_HERE, animationInterval, this,
1042 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:591043 animation_update_pending_ = false;
[email protected]ba91a792013-02-06 09:48:281044 if (is_accelerated_compositing_active_ && compositor_) {
[email protected]635353c2013-03-06 09:11:201045 compositor_->Animate(base::TimeTicks::Now());
[email protected]8926c602013-01-23 05:32:061046 } else {
[email protected]635353c2013-03-06 09:11:201047 double frame_begin_time =
1048 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
1049 webwidget_->animate(frame_begin_time);
[email protected]8926c602013-01-23 05:32:061050 }
[email protected]7c4329e2011-02-18 22:02:591051 return;
[email protected]5f8b1022011-01-21 23:34:501052 }
[email protected]bd37ae252011-06-03 01:28:181053 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:381054 if (!animation_timer_.IsRunning()) {
1055 // This code uses base::Time::Now() to calculate the floor and next fire
1056 // time because javascript's Date object uses base::Time::Now(). The
1057 // message loop uses base::TimeTicks, which on windows can have a
1058 // different granularity than base::Time.
1059 // The upshot of all this is that this function might be called before
1060 // base::Time::Now() has advanced past the animation_floor_time_. To
1061 // avoid exposing this delay to javascript, we keep posting delayed
1062 // tasks until base::Time::Now() has advanced far enough.
1063 base::TimeDelta delay = animation_floor_time_ - now;
1064 animation_timer_.Start(FROM_HERE, delay, this,
1065 &RenderWidget::AnimationCallback);
1066 }
[email protected]5f8b1022011-01-21 23:34:501067}
1068
[email protected]bd37ae252011-06-03 01:28:181069bool RenderWidget::IsRenderingVSynced() {
1070 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
1071 // not caught by this check. This will lead to artificially low frame rates
1072 // for people who force vsync off at a driver level and expect Chrome to speed
1073 // up.
1074 return !has_disable_gpu_vsync_switch_;
1075}
1076
[email protected]65225772011-05-12 21:10:241077void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:061078 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:241079 invalidation_task_posted_ = false;
1080 DoDeferredUpdateAndSendInputAck();
1081}
1082
1083void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:051084 DoDeferredUpdate();
1085
[email protected]59383c782013-04-17 16:43:271086 if (pending_input_event_ack_)
[email protected]52ccd0ea2011-02-16 01:09:051087 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:211088}
1089
[email protected]552e6002009-11-19 05:24:571090void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:581091 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:081092
[email protected]65225772011-05-12 21:10:241093 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:291094 return;
[email protected]05a980d7a2012-02-07 22:16:421095
[email protected]fc4404d2012-11-07 19:53:301096 if (!init_complete_) {
1097 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:421098 return;
1099 }
[email protected]aa4117f2011-12-09 22:19:211100 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:241101 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
1102 return;
1103 }
[email protected]9ca84622011-06-02 23:46:391104 if (is_accelerated_compositing_active_ &&
1105 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:241106 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
1107 return;
1108 }
initial.commit09911bf2008-07-26 23:55:291109
[email protected]552e6002009-11-19 05:24:571110 // Suppress updating when we are hidden.
[email protected]e3d92a7f2013-01-10 02:35:051111 if (is_hidden_ || size_.IsEmpty() || is_swapped_out_) {
[email protected]552e6002009-11-19 05:24:571112 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:291113 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:241114 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:291115 return;
1116 }
1117
[email protected]05a980d7a2012-02-07 22:16:421118 if (is_accelerated_compositing_active_)
1119 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
1120
[email protected]0fb93f52011-05-18 23:13:561121 // Tracking of frame rate jitter
1122 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]38ce4e7b2013-02-23 06:17:371123 InstrumentWillBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:051124 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:501125
[email protected]f98d7e3c2010-09-13 22:30:461126 // Layout may generate more invalidation. It may also enable the
1127 // GPU acceleration, so make sure to run layout before we send the
1128 // GpuRenderingActivated message.
1129 webwidget_->layout();
1130
[email protected]dcca3aa92012-02-17 23:03:371131 // The following two can result in further layout and possibly
1132 // enable GPU acceleration so they need to be called before any painting
1133 // is done.
[email protected]3306f262012-09-21 19:20:421134 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]dcca3aa92012-02-17 23:03:371135 UpdateSelectionBounds();
1136
[email protected]5f8b1022011-01-21 23:34:501137 // Suppress painting if nothing is dirty. This has to be done after updating
1138 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:241139 if (!paint_aggregator_.HasPendingUpdate()) {
1140 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]38ce4e7b2013-02-23 06:17:371141 InstrumentDidCancelFrame();
[email protected]5f8b1022011-01-21 23:34:501142 return;
[email protected]65225772011-05-12 21:10:241143 }
[email protected]5f8b1022011-01-21 23:34:501144
[email protected]479b0172012-10-29 19:27:091145 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:361146 !is_threaded_compositing_enabled_ &&
[email protected]479b0172012-10-29 19:27:091147 ForceCompositingModeEnabled()) {
1148 webwidget_->enterForceCompositingMode(true);
1149 }
1150
[email protected]872ae5b2011-05-26 20:20:501151 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:561152 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:041153 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:561154 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
1155 delay,
1156 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411157 base::TimeDelta::FromMilliseconds(120),
1158 60);
[email protected]d0be63772011-12-20 23:18:041159 } else {
[email protected]0fb93f52011-05-18 23:13:561160 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
1161 delay,
1162 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411163 base::TimeDelta::FromMilliseconds(120),
1164 60);
[email protected]d0be63772011-12-20 23:18:041165 }
[email protected]872ae5b2011-05-26 20:20:501166
1167 // Calculate filtered time per frame:
1168 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
1169 filtered_time_per_frame_ =
1170 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:561171 }
1172 last_do_deferred_update_time_ = frame_begin_ticks;
1173
[email protected]fef5e3972012-08-07 03:59:471174 if (!is_accelerated_compositing_active_) {
[email protected]62049562013-03-24 00:39:011175 software_stats_.animation_frame_count++;
1176 software_stats_.screen_frame_count++;
[email protected]fef5e3972012-08-07 03:59:471177 }
1178
[email protected]552e6002009-11-19 05:24:571179 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:291180 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:301181 PaintAggregator::PendingUpdate update;
1182 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:291183
[email protected]53d3f302009-12-21 04:42:051184 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:181185 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:291186
[email protected]29ed96a2012-02-04 18:12:161187 // Notify derived classes that we're about to initiate a paint.
1188 WillInitiatePaint();
1189
[email protected]ca4847f2010-09-24 05:39:151190 // A plugin may be able to do an optimized paint. First check this, in which
1191 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:461192 // This optimization allows PPAPI plugins that declare themselves on top of
1193 // the page (like a traditional windowed plugin) to be able to animate (think
1194 // movie playing) without repeatedly re-painting the page underneath, or
1195 // copying the plugin backing store (since we can send the plugin's backing
1196 // store directly to the browser).
1197 //
1198 // This optimization only works when the entire invalid region is contained
1199 // within the plugin. There is a related optimization in PaintRect for the
1200 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:151201 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:151202 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201203 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:211204 DCHECK(!pending_update_params_.get());
1205 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551206 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211207 pending_update_params_->scroll_rect = update.scroll_rect;
1208 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211209 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1210 pending_update_params_->flags = next_paint_flags_;
1211 pending_update_params_->scroll_offset = GetScrollOffset();
1212 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091213 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211214 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091215 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211216
[email protected]ca4847f2010-09-24 05:39:151217 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561218 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151219 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201220 &optimized_copy_rect,
1221 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271222 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471223 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211224 pending_update_params_->bitmap = dib->id();
1225 pending_update_params_->bitmap_rect = optimized_copy_location;
1226 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201227 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561228 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461229 // Compute a buffer for painting and cache it.
[email protected]4889bd212013-02-11 22:23:101230
1231 bool fractional_scale = device_scale_factor_ -
1232 static_cast<int>(device_scale_factor_) != 0;
1233 if (fractional_scale) {
1234 // Damage might not be DIP aligned. Inflate damage to compensate.
1235 bounds.Inset(-1, -1);
1236 bounds.Intersect(gfx::Rect(size_));
1237 }
1238
1239 gfx::Rect pixel_bounds = gfx::ToEnclosingRect(
[email protected]ce112fe2012-10-29 22:52:181240 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]4889bd212013-02-11 22:23:101241
[email protected]ca4847f2010-09-24 05:39:151242 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351243 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591244 pixel_bounds));
[email protected]59383c782013-04-17 16:43:271245 if (!canvas) {
[email protected]f98d7e3c2010-09-13 22:30:461246 NOTREACHED();
1247 return;
1248 }
[email protected]cef3362f2009-12-21 17:48:451249
[email protected]f98d7e3c2010-09-13 22:30:461250 // We may get back a smaller canvas than we asked for.
1251 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591252 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1253 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1254 pixel_bounds.set_width(canvas->getDevice()->width());
1255 pixel_bounds.set_height(canvas->getDevice()->height());
1256 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1257 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051258
[email protected]f98d7e3c2010-09-13 22:30:461259 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1260
[email protected]aa4117f2011-12-09 22:19:211261 pending_update_params_->bitmap = current_paint_buf_->id();
1262 pending_update_params_->bitmap_rect = bounds;
1263
1264 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461265 // The scroll damage is just another rectangle to paint and copy.
1266 copy_rects.swap(update.paint_rects);
1267 if (!scroll_damage.IsEmpty())
1268 copy_rects.push_back(scroll_damage);
1269
[email protected]4889bd212013-02-11 22:23:101270 for (size_t i = 0; i < copy_rects.size(); ++i) {
1271 gfx::Rect rect = copy_rects[i];
1272 if (fractional_scale) {
1273 // Damage might not be DPI aligned. Inflate rect to compensate.
1274 rect.Inset(-1, -1);
1275 }
1276 PaintRect(rect, pixel_bounds.origin(), canvas.get());
1277 }
[email protected]60a50072012-01-11 02:05:351278
1279 // Software FPS tick for performance tests. The accelerated path traces the
1280 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1281 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421282 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW",
1283 TRACE_EVENT_SCOPE_THREAD);
[email protected]f98d7e3c2010-09-13 22:30:461284 } else { // Accelerated compositing path
1285 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211286 // If painting is done via the gpu process then we don't set any damage
1287 // rects to save the browser process from doing unecessary work.
1288 pending_update_params_->bitmap_rect = bounds;
1289 pending_update_params_->scroll_rect = gfx::Rect();
1290 // We don't need an ack, because we're not sharing a DIB with the browser.
1291 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1292 // with the browser for the GPU surface.
1293 pending_update_params_->needs_ack = false;
[email protected]f0c2a242013-03-15 19:34:521294 Composite(frame_begin_ticks);
[email protected]f98d7e3c2010-09-13 22:30:461295 }
1296
[email protected]936c6f52011-12-13 01:35:261297 // If we're holding a pending input event ACK, send the ACK before sending the
1298 // UpdateReply message so we can receive another input event before the
1299 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1300 // the UpdateRect IPC message handler.
[email protected]59383c782013-04-17 16:43:271301 if (pending_input_event_ack_)
[email protected]936c6f52011-12-13 01:35:261302 Send(pending_input_event_ack_.release());
1303
[email protected]ab543072013-01-25 04:38:151304 // If Composite() called SwapBuffers, pending_update_params_ will be reset (in
[email protected]aa4117f2011-12-09 22:19:211305 // OnSwapBuffersPosted), meaning a message has been added to the
1306 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1307 // the message now.
[email protected]59383c782013-04-17 16:43:271308 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:211309 // sending an ack to browser process that the paint is complete...
1310 update_reply_pending_ = pending_update_params_->needs_ack;
1311 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1312 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341313 }
[email protected]53d3f302009-12-21 04:42:051314
[email protected]29ed96a2012-02-04 18:12:161315 // If we're software rendering then we're done initiating the paint.
1316 if (!is_accelerated_compositing_active_)
1317 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291318}
1319
[email protected]f0c2a242013-03-15 19:34:521320void RenderWidget::Composite(base::TimeTicks frame_begin_time) {
[email protected]ab543072013-01-25 04:38:151321 DCHECK(is_accelerated_compositing_active_);
[email protected]ba91a792013-02-06 09:48:281322 if (compositor_) // TODO(jamesr): Figure out how this can be null.
[email protected]f0c2a242013-03-15 19:34:521323 compositor_->Composite(frame_begin_time);
[email protected]ab543072013-01-25 04:38:151324}
1325
initial.commit09911bf2008-07-26 23:55:291326///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461327// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291328
[email protected]4873c7d2009-07-16 06:36:281329void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]479b0172012-10-29 19:27:091330 TRACE_EVENT2("renderer", "RenderWidget::didInvalidateRect",
1331 "width", rect.width, "height", rect.height);
[email protected]552e6002009-11-19 05:24:571332 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481333 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181334 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571335 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291336 return;
1337
[email protected]552e6002009-11-19 05:24:571338 paint_aggregator_.InvalidateRect(damaged_rect);
1339
1340 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241341 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571342 return;
1343 if (!paint_aggregator_.HasPendingUpdate())
1344 return;
[email protected]aa4117f2011-12-09 22:19:211345 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241346 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1347 return;
1348
1349 // When GPU rendering, combine pending animations and invalidations into
1350 // a single update.
[email protected]816edc62012-03-17 01:27:221351 if (is_accelerated_compositing_active_ &&
1352 animation_update_pending_ &&
1353 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571354 return;
1355
1356 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291357 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1358 // on the call stack.
1359 // 2) Allows us to collect more damage rects before painting to help coalesce
1360 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241361 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111362 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211363 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291364}
1365
[email protected]990278ff2012-11-13 02:12:551366void RenderWidget::didScrollRect(int dx, int dy,
1367 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461368 // Drop scrolls on the floor when we are in compositing mode.
1369 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561370 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461371 return;
1372
[email protected]552e6002009-11-19 05:24:571373 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481374 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181375 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571376 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291377 return;
1378
[email protected]990278ff2012-11-13 02:12:551379 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571380
1381 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241382 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571383 return;
1384 if (!paint_aggregator_.HasPendingUpdate())
1385 return;
[email protected]aa4117f2011-12-09 22:19:211386 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241387 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1388 return;
1389
1390 // When GPU rendering, combine pending animations and invalidations into
1391 // a single update.
[email protected]816edc62012-03-17 01:27:221392 if (is_accelerated_compositing_active_ &&
1393 animation_update_pending_ &&
1394 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571395 return;
1396
1397 // Perform updating asynchronously. This serves two purposes:
1398 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1399 // on the call stack.
1400 // 2) Allows us to collect more damage rects before painting to help coalesce
1401 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241402 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111403 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211404 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291405}
1406
[email protected]244ac1892011-12-02 17:04:471407void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091408 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451409 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581410
[email protected]eac2b362013-05-22 07:01:451411 // If we don't clear PaintAggregator after changing autoResize state, then
1412 // we might end up in a situation where bitmap_rect is larger than the
1413 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1414 // with invalid damage rects.
1415 paint_aggregator_.ClearPendingUpdate();
1416
1417 if (RenderThreadImpl::current()->short_circuit_size_updates()) {
1418 WebRect new_pos(rootWindowRect().x,
1419 rootWindowRect().y,
1420 new_size.width,
1421 new_size.height);
1422 view_screen_rect_ = new_pos;
1423 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031424 }
[email protected]20fbfc22013-05-08 20:50:581425
[email protected]eac2b362013-05-22 07:01:451426 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581427
1428 if (!RenderThreadImpl::current()->short_circuit_size_updates())
1429 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091430 }
[email protected]244ac1892011-12-02 17:04:471431}
1432
[email protected]3a1c8a8032013-03-18 22:35:321433void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051434 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1435 device_scale_factor_));
1436 if (compositor_)
1437 compositor_->setViewportSize(size_, physical_backing_size_);
1438}
1439
[email protected]91acd1c2012-03-14 08:32:391440void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221441 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1442
[email protected]c63b4d42012-04-26 01:01:071443#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211444 if (!is_accelerated_compositing_active_) {
1445 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1446 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1447 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1448 // going to switch to accelerated compositing, the GPU process may need
1449 // round-trips to the browser's UI thread before finishing the frame,
1450 // causing deadlocks if we delay the UpdateRect until we receive the
1451 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071452 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1453 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211454 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1455 }
[email protected]c63b4d42012-04-26 01:01:071456#endif
[email protected]aa4117f2011-12-09 22:19:211457
[email protected]ea162f92011-10-04 23:08:221458 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421459 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241460 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221461}
1462
1463void RenderWidget::didDeactivateCompositor() {
1464 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1465
1466 is_accelerated_compositing_active_ = false;
1467 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1468 routing_id_, is_accelerated_compositing_active_));
1469
[email protected]ea162f92011-10-04 23:08:221470 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241471 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091472
1473 // In single-threaded mode, we exit force compositing mode and re-enter in
1474 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1475 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1476 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361477 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091478 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561479}
1480
[email protected]e195e582013-03-08 01:32:591481void RenderWidget::initializeLayerTreeView() {
1482 compositor_ = RenderWidgetCompositor::Create(this);
1483 if (!compositor_)
1484 return;
1485
1486 compositor_->setViewportSize(size_, physical_backing_size_);
1487 if (init_complete_)
1488 compositor_->setSurfaceReady();
1489}
1490
[email protected]8926c602013-01-23 05:32:061491WebKit::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281492 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061493}
1494
[email protected]9ed83fe2013-02-27 01:52:281495void RenderWidget::suppressCompositorScheduling(bool enable) {
1496 if (compositor_)
1497 compositor_->SetSuppressScheduleComposite(enable);
1498}
1499
[email protected]9cd43a62012-03-26 08:03:561500void RenderWidget::willBeginCompositorFrame() {
1501 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371502
[email protected]ea5f70a2013-03-07 12:30:361503 DCHECK(RenderThreadImpl::current()->compositor_message_loop_proxy());
[email protected]abe8b3a2012-03-28 21:19:371504
1505 // The following two can result in further layout and possibly
1506 // enable GPU acceleration so they need to be called before any painting
1507 // is done.
[email protected]2d354272013-01-14 00:59:061508 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]abe8b3a2012-03-28 21:19:371509 UpdateSelectionBounds();
1510
[email protected]9cd43a62012-03-26 08:03:561511 WillInitiatePaint();
1512}
1513
[email protected]3391a0772012-03-28 00:32:071514void RenderWidget::didBecomeReadyForAdditionalInput() {
1515 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]59383c782013-04-17 16:43:271516 if (pending_input_event_ack_)
[email protected]3391a0772012-03-28 00:32:071517 Send(pending_input_event_ack_.release());
1518}
1519
[email protected]6fceb912013-02-15 06:24:151520void RenderWidget::DidCommitCompositorFrame() {
1521}
1522
[email protected]58264a32011-11-17 23:36:151523void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501524 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351525 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1526 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421527 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU",
1528 TRACE_EVENT_SCOPE_THREAD);
[email protected]29ed96a2012-02-04 18:12:161529 // Notify subclasses that we initiated the paint operation.
1530 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151531}
1532
1533void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181534 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1535
1536 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561537 DidFlushPaint();
1538
[email protected]aa4117f2011-12-09 22:19:211539 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151540 return;
1541
[email protected]ea3ee0a2012-05-15 03:43:091542 if (!next_paint_flags_ &&
1543 !need_update_rect_for_auto_resize_ &&
1544 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151545 return;
[email protected]ea3ee0a2012-05-15 03:43:091546 }
[email protected]58264a32011-11-17 23:36:151547
1548 ViewHostMsg_UpdateRect_Params params;
1549 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151550 params.plugin_window_moves.swap(plugin_window_moves_);
1551 params.flags = next_paint_flags_;
1552 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121553 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091554 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151555
1556 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1557 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091558 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151559}
1560
[email protected]f98d7e3c2010-09-13 22:30:461561void RenderWidget::scheduleComposite() {
[email protected]479b0172012-10-29 19:27:091562 TRACE_EVENT0("gpu", "RenderWidget::scheduleComposite");
[email protected]ea5f70a2013-03-07 12:30:361563 if (RenderThreadImpl::current()->compositor_message_loop_proxy() &&
[email protected]ba91a792013-02-06 09:48:281564 compositor_) {
1565 compositor_->setNeedsRedraw();
[email protected]d0be63772011-12-20 23:18:041566 } else {
[email protected]c3d45532011-10-07 19:20:401567 // TODO(nduca): replace with something a little less hacky. The reason this
1568 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1569 // contains a lot of host-renderer synchronization logic that is still
1570 // important for the accelerated compositing case. The option of simply
1571 // duplicating all that code is less desirable than "faking out" the
1572 // invalidation path using a magical damage rect.
1573 didInvalidateRect(WebRect(0, 0, 1, 1));
1574 }
[email protected]f98d7e3c2010-09-13 22:30:461575}
1576
[email protected]5f8b1022011-01-21 23:34:501577void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201578 if (animation_update_pending_)
1579 return;
1580
[email protected]921244e42011-07-20 16:36:301581 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201582 animation_update_pending_ = true;
1583 if (!animation_timer_.IsRunning()) {
1584 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1585 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211586 }
[email protected]5f8b1022011-01-21 23:34:501587}
1588
[email protected]4873c7d2009-07-16 06:36:281589void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301590 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521591 WebCursor cursor;
1592 webkit_glue::InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291593 // Only send a SetCursor message if we need to make a change.
1594 if (!current_cursor_.IsEqual(cursor)) {
1595 current_cursor_ = cursor;
1596 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1597 }
1598}
1599
1600// We are supposed to get a single call to Show for a newly created RenderWidget
1601// that was created via RenderWidget::CreateWebView. So, we wait until this
1602// point to dispatch the ShowWidget message.
1603//
1604// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281605// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291606//
[email protected]4873c7d2009-07-16 06:36:281607void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291608 DCHECK(!did_show_) << "received extraneous Show call";
1609 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1610 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1611
[email protected]8de12d942010-11-17 20:42:441612 if (did_show_)
1613 return;
1614
1615 did_show_ = true;
1616 // NOTE: initial_pos_ may still have its default values at this point, but
1617 // that's okay. It'll be ignored if as_popup is false, or the browser
1618 // process will impose a default position otherwise.
1619 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1620 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291621}
1622
[email protected]9b003482013-05-21 14:00:171623void RenderWidget::didProgrammaticallyScroll(
1624 const WebKit::WebPoint& scroll_point) {
1625 if (!compositor_)
1626 return;
1627 Send(new ViewHostMsg_DidProgrammaticallyScroll(
1628 routing_id_, gfx::Vector2d(scroll_point.x, scroll_point.y)));
1629}
1630
[email protected]4873c7d2009-07-16 06:36:281631void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291632}
1633
[email protected]4873c7d2009-07-16 06:36:281634void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291635}
1636
[email protected]2533ce12009-05-09 00:02:241637void RenderWidget::DoDeferredClose() {
1638 Send(new ViewHostMsg_Close(routing_id_));
1639}
1640
[email protected]4873c7d2009-07-16 06:36:281641void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321642 if (is_swapped_out_) {
1643 // This widget is currently swapped out, and the active widget is in a
1644 // different process. Have the browser route the close request to the
1645 // active widget instead, so that the correct unload handlers are run.
1646 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1647 return;
1648 }
1649
initial.commit09911bf2008-07-26 23:55:291650 // If a page calls window.close() twice, we'll end up here twice, but that's
1651 // OK. It is safe to send multiple Close messages.
1652
[email protected]2533ce12009-05-09 00:02:241653 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1654 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1655 // could be closed before the JS finishes executing. So instead, post a
1656 // message back to the message loop, which won't run until the JS is
1657 // complete, and then the Close message can be sent.
[email protected]dd32b1272013-05-04 14:17:111658 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211659 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291660}
1661
1662void RenderWidget::Close() {
1663 if (webwidget_) {
[email protected]8926c602013-01-23 05:32:061664 webwidget_->willCloseLayerTreeView();
[email protected]ba91a792013-02-06 09:48:281665 compositor_.reset();
[email protected]4873c7d2009-07-16 06:36:281666 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291667 webwidget_ = NULL;
1668 }
1669}
1670
[email protected]4873c7d2009-07-16 06:36:281671WebRect RenderWidget::windowRect() {
1672 if (pending_window_rect_count_)
1673 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241674
[email protected]80ad8622012-11-07 16:33:031675 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291676}
1677
[email protected]8a9d6ca32011-06-06 20:11:301678void RenderWidget::setToolTipText(const WebKit::WebString& text,
1679 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541680 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301681}
1682
[email protected]4873c7d2009-07-16 06:36:281683void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291684 if (did_show_) {
[email protected]8be1c582013-03-06 00:55:031685 if (!RenderThreadImpl::current()->short_circuit_size_updates()) {
1686 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1687 SetPendingWindowRect(pos);
1688 } else {
1689 WebSize new_size(pos.width, pos.height);
[email protected]d9083762013-03-24 01:36:401690 Resize(new_size, new_size, overdraw_bottom_height_,
1691 WebRect(), is_fullscreen_, NO_RESIZE_ACK);
[email protected]8be1c582013-03-06 00:55:031692 view_screen_rect_ = pos;
1693 window_screen_rect_ = pos;
1694 }
initial.commit09911bf2008-07-26 23:55:291695 } else {
1696 initial_pos_ = pos;
1697 }
1698}
1699
[email protected]2533ce12009-05-09 00:02:241700void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1701 pending_window_rect_ = rect;
1702 pending_window_rect_count_++;
1703}
1704
[email protected]4873c7d2009-07-16 06:36:281705WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241706 if (pending_window_rect_count_) {
1707 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1708 // the RootWindowRect is probably going to return wrong results since the
1709 // browser may not have processed the Move yet. There isn't really anything
1710 // good to do in this case, and it shouldn't happen - since this size is
1711 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281712 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241713 }
1714
[email protected]80ad8622012-11-07 16:33:031715 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371716}
1717
[email protected]4873c7d2009-07-16 06:36:281718WebRect RenderWidget::windowResizerRect() {
1719 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191720}
1721
[email protected]fa7b1dc2010-06-23 17:53:041722void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031723 // To prevent this renderer process from sending unnecessary IPC messages to
1724 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041725 // only during the input method attached to the browser process is active.
1726 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291727}
1728
[email protected]58b48a0d2012-06-13 07:01:351729void RenderWidget::UpdateCompositionInfo(
1730 const ui::Range& range,
1731 const std::vector<gfx::Rect>& character_bounds) {
1732 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1733 return;
1734 composition_character_bounds_ = character_bounds;
1735 composition_range_ = range;
1736 Send(new ViewHostMsg_ImeCompositionRangeChanged(
1737 routing_id(), composition_range_, composition_character_bounds_));
1738}
1739
[email protected]fa7b1dc2010-06-23 17:53:041740void RenderWidget::OnImeSetComposition(
1741 const string16& text,
1742 const std::vector<WebCompositionUnderline>& underlines,
1743 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281744 if (!webwidget_)
1745 return;
[email protected]66fca5bc2013-05-23 06:58:291746 ImeEventGuard guard(this);
[email protected]d4cff272011-05-02 15:46:011747 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041748 text, WebVector<WebCompositionUnderline>(underlines),
1749 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011750 // Setting the IME composition was successful. Send the new composition
1751 // range to the browser.
1752 ui::Range range(ui::Range::InvalidRange());
1753 size_t location, length;
1754 if (webwidget_->compositionRange(&location, &length)) {
1755 range.set_start(location);
1756 range.set_end(location + length);
1757 }
1758 // The IME was cancelled via the Esc key, so just send back the caret.
1759 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1760 range.set_start(location);
1761 range.set_end(location + length);
1762 }
[email protected]58b48a0d2012-06-13 07:01:351763 std::vector<gfx::Rect> character_bounds;
1764 GetCompositionCharacterBounds(&character_bounds);
1765 UpdateCompositionInfo(range, character_bounds);
[email protected]d4cff272011-05-02 15:46:011766 } else {
[email protected]fa7b1dc2010-06-23 17:53:041767 // If we failed to set the composition text, then we need to let the browser
1768 // process to cancel the input method's ongoing composition session, to make
1769 // sure we are in a consistent state.
1770 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011771
1772 // Send an updated IME range with just the caret range.
1773 ui::Range range(ui::Range::InvalidRange());
1774 size_t location, length;
1775 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1776 range.set_start(location);
1777 range.set_end(location + length);
1778 }
[email protected]58b48a0d2012-06-13 07:01:351779 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]7f00efa2010-04-15 05:01:261780 }
[email protected]fa7b1dc2010-06-23 17:53:041781}
1782
[email protected]4de6d1692011-10-12 08:45:441783void RenderWidget::OnImeConfirmComposition(
1784 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041785 if (!webwidget_)
1786 return;
[email protected]66fca5bc2013-05-23 06:58:291787 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041788 handling_input_event_ = true;
1789 webwidget_->confirmComposition(text);
1790 handling_input_event_ = false;
1791
[email protected]d4cff272011-05-02 15:46:011792 // Send an updated IME range with just the caret range.
1793 ui::Range range(ui::Range::InvalidRange());
1794 size_t location, length;
1795 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1796 range.set_start(location);
1797 range.set_end(location + length);
1798 }
[email protected]58b48a0d2012-06-13 07:01:351799 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
initial.commit09911bf2008-07-26 23:55:291800}
1801
[email protected]948f7ab72010-05-28 23:48:081802// This message causes the renderer to render an image of the
1803// desired_size, regardless of whether the tab is hidden or not.
[email protected]3d9ec5052013-01-02 22:05:251804void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle,
1805 int tag,
1806 const gfx::Size& page_size,
1807 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001808 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1809 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251810 // Close our unused handle.
1811#if defined(OS_WIN)
1812 ::CloseHandle(dib_handle);
1813#elif defined(OS_MACOSX)
1814 base::SharedMemory::CloseHandle(dib_handle);
1815#endif
1816 }
[email protected]d65adb12010-04-28 17:26:491817 return;
[email protected]45c6aad32010-11-11 04:46:251818 }
[email protected]d65adb12010-04-28 17:26:491819
[email protected]948f7ab72010-05-28 23:48:081820 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491821 // If one of these is empty, then we just return the dib we were
1822 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091823 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491824 return;
1825 }
1826
1827 // Map the given DIB ID into this process, and unmap it at the end
1828 // of this function.
[email protected]45c6aad32010-11-11 04:46:251829 scoped_ptr<TransportDIB> paint_at_size_buffer(
1830 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301831
[email protected]4b01b962012-10-09 23:17:351832 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281833 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:351834 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281835 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:511836 gfx::Size canvas_size = page_size_in_pixel;
1837 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:491838 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:511839 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:491840 static_cast<float>(canvas_size.height());
1841
[email protected]ee8d6fd2010-05-26 17:05:481842 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491843 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1844 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481845 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491846
[email protected]36808ad2010-10-20 19:18:301847 scoped_ptr<skia::PlatformCanvas> canvas(
1848 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1849 canvas_size.height()));
[email protected]59383c782013-04-17 16:43:271850 if (!canvas) {
[email protected]36808ad2010-10-20 19:18:301851 NOTREACHED();
1852 return;
1853 }
1854
[email protected]d65adb12010-04-28 17:26:491855 // Reset bounds to what we actually received, but they should be the
1856 // same.
1857 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1858 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1859 bounds.set_width(canvas->getDevice()->width());
1860 bounds.set_height(canvas->getDevice()->height());
1861
1862 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081863 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491864 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1865
[email protected]948f7ab72010-05-28 23:48:081866 // Have to make sure we're laid out at the right size before
1867 // rendering.
1868 gfx::Size old_size = webwidget_->size();
1869 webwidget_->resize(page_size);
1870 webwidget_->layout();
1871
[email protected]d65adb12010-04-28 17:26:491872 // Paint the entire thing (using original bounds, not scaled bounds).
1873 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1874 canvas->restore();
1875
[email protected]948f7ab72010-05-28 23:48:081876 // Return the widget to its previous size.
1877 webwidget_->resize(old_size);
1878
[email protected]c88c9442010-07-19 18:55:091879 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491880}
1881
[email protected]51a49502013-03-23 01:50:191882void RenderWidget::OnSnapshot(const gfx::Rect& src_subrect) {
1883 SkBitmap snapshot;
1884
1885 if (OnSnapshotHelper(src_subrect, &snapshot)) {
1886 Send(new ViewHostMsg_Snapshot(routing_id(), true, snapshot));
1887 } else {
1888 Send(new ViewHostMsg_Snapshot(routing_id(), false, SkBitmap()));
1889 }
1890}
1891
1892bool RenderWidget::OnSnapshotHelper(const gfx::Rect& src_subrect,
1893 SkBitmap* snapshot) {
1894 base::TimeTicks beginning_time = base::TimeTicks::Now();
1895
1896 if (!webwidget_ || src_subrect.IsEmpty())
1897 return false;
1898
1899 gfx::Rect viewport_size = gfx::IntersectRects(
1900 src_subrect, gfx::Rect(physical_backing_size_));
1901
1902 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(
1903 skia::CreatePlatformCanvas(viewport_size.width(),
1904 viewport_size.height(),
1905 true,
1906 NULL,
1907 skia::RETURN_NULL_ON_FAILURE));
[email protected]59383c782013-04-17 16:43:271908 if (!canvas)
[email protected]51a49502013-03-23 01:50:191909 return false;
1910
1911 canvas->save();
1912 webwidget_->layout();
1913
1914 PaintRect(viewport_size, viewport_size.origin(), canvas.get());
1915 canvas->restore();
1916
1917 const SkBitmap& bitmap = skia::GetTopDevice(*canvas)->accessBitmap(false);
1918 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1919 return false;
1920
1921 UMA_HISTOGRAM_TIMES("Renderer4.Snapshot",
1922 base::TimeTicks::Now() - beginning_time);
1923 return true;
1924}
1925
[email protected]0bc1f572013-04-17 01:46:311926void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121927 // During shutdown we can just ignore this message.
1928 if (!webwidget_)
1929 return;
1930
[email protected]0bc1f572013-04-17 01:46:311931 // Even if the browser provides an empty damage rect, it's still expecting to
1932 // receive a repaint ack so just damage the entire widget bounds.
1933 if (size_to_paint.IsEmpty()) {
1934 size_to_paint = size_;
1935 }
1936
[email protected]ec7dc112008-08-06 05:30:121937 set_next_paint_is_repaint_ack();
[email protected]0bc1f572013-04-17 01:46:311938 if (is_accelerated_compositing_active_ && compositor_) {
1939 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]f98d7e3c2010-09-13 22:30:461940 } else {
1941 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1942 didInvalidateRect(repaint_rect);
1943 }
[email protected]ec7dc112008-08-06 05:30:121944}
1945
[email protected]4a9dba42013-04-29 18:24:221946void RenderWidget::OnSmoothScrollCompleted() {
1947 pending_smooth_scroll_gesture_.Run();
[email protected]0e241b4b2012-08-18 09:06:271948}
1949
[email protected]4873c7d2009-07-16 06:36:281950void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111951 if (!webwidget_)
1952 return;
[email protected]4873c7d2009-07-16 06:36:281953 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111954}
1955
[email protected]6131a642012-06-15 23:26:531956void RenderWidget::OnScreenInfoChanged(
1957 const WebKit::WebScreenInfo& screen_info) {
1958 screen_info_ = screen_info;
[email protected]468ac582012-11-20 00:53:191959 SetDeviceScaleFactor(screen_info.deviceScaleFactor);
[email protected]6131a642012-06-15 23:26:531960}
1961
[email protected]80ad8622012-11-07 16:33:031962void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1963 const gfx::Rect& window_screen_rect) {
1964 view_screen_rect_ = view_screen_rect;
1965 window_screen_rect_ = window_screen_rect;
1966 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1967}
1968
[email protected]105dffb42013-02-20 03:46:211969#if defined(OS_ANDROID)
1970void RenderWidget::OnImeBatchStateChanged(bool is_begin) {
1971 Send(new ViewHostMsg_ImeBatchStateChanged_ACK(routing_id(), is_begin));
1972}
[email protected]2384b6c2013-02-28 23:58:511973
1974void RenderWidget::OnShowImeIfNeeded() {
1975 UpdateTextInputState(SHOW_IME_IF_NEEDED);
1976}
[email protected]105dffb42013-02-20 03:46:211977#endif
1978
[email protected]468ac582012-11-20 00:53:191979void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1980 if (device_scale_factor_ == device_scale_factor)
1981 return;
1982
1983 device_scale_factor_ = device_scale_factor;
1984
1985 if (!is_accelerated_compositing_active_) {
1986 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
1987 } else {
1988 scheduleComposite();
1989 }
1990}
1991
[email protected]719b36f2010-12-22 20:36:461992webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151993 const gfx::Rect& paint_bounds,
1994 TransportDIB** dib,
1995 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:201996 gfx::Rect* clip,
1997 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:461998 // Bare RenderWidgets don't support optimized plugin painting.
1999 return NULL;
[email protected]ca4847f2010-09-24 05:39:152000}
2001
[email protected]ceb36f7d2012-10-31 18:33:242002gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:522003 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:242004 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:522005}
2006
[email protected]bee16aab2009-08-26 15:55:032007void RenderWidget::SetHidden(bool hidden) {
2008 if (is_hidden_ == hidden)
2009 return;
2010
2011 // The status has changed. Tell the RenderThread about it.
2012 is_hidden_ = hidden;
2013 if (is_hidden_)
[email protected]380244092011-10-07 17:26:272014 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:032015 else
[email protected]380244092011-10-07 17:26:272016 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:032017}
2018
[email protected]2b624c562011-10-27 22:58:262019void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262020 if (!webwidget_)
2021 return;
2022
2023 if (is_fullscreen_) {
2024 webwidget_->willExitFullScreen();
2025 } else {
2026 webwidget_->willEnterFullScreen();
2027 }
[email protected]2b624c562011-10-27 22:58:262028}
2029
2030void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262031 if (!webwidget_)
2032 return;
2033
2034 if (is_fullscreen_) {
2035 webwidget_->didEnterFullScreen();
2036 } else {
2037 webwidget_->didExitFullScreen();
2038 }
[email protected]2b624c562011-10-27 22:58:262039}
2040
[email protected]699ab0d2009-04-23 23:19:142041void RenderWidget::SetBackground(const SkBitmap& background) {
2042 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:462043
[email protected]699ab0d2009-04-23 23:19:142044 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:282045 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:142046}
2047
[email protected]674741932009-02-04 23:44:462048bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:052049 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462050}
2051
2052bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:052053 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462054}
2055
2056void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:052057 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462058}
2059
2060void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:052061 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:462062}
2063
2064void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:052065 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462066}
2067
[email protected]b18583c2012-12-18 06:55:272068static bool IsDateTimeInput(ui::TextInputType type) {
2069 return type == ui::TEXT_INPUT_TYPE_DATE ||
2070 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
2071 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
2072 type == ui::TEXT_INPUT_TYPE_MONTH ||
2073 type == ui::TEXT_INPUT_TYPE_TIME ||
2074 type == ui::TEXT_INPUT_TYPE_WEEK;
2075}
2076
[email protected]66fca5bc2013-05-23 06:58:292077
2078void RenderWidget::StartHandlingImeEvent() {
2079 DCHECK(!handling_ime_event_);
2080 handling_ime_event_ = true;
2081}
2082
2083void RenderWidget::FinishHandlingImeEvent() {
2084 DCHECK(handling_ime_event_);
2085 handling_ime_event_ = false;
2086 // While handling an ime event, text input state and selection bounds updates
2087 // are ignored. These must explicitly be updated once finished handling the
2088 // ime event.
2089 UpdateSelectionBounds();
2090 UpdateTextInputState(DO_NOT_SHOW_IME);
2091}
2092
[email protected]3306f262012-09-21 19:20:422093void RenderWidget::UpdateTextInputState(ShowIme show_ime) {
[email protected]e8f775f2013-02-14 21:00:502094 if (handling_ime_event_)
2095 return;
[email protected]3306f262012-09-21 19:20:422096 bool show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
2097 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:292098 return;
[email protected]ad26ef42011-06-17 07:59:452099 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:272100 if (IsDateTimeInput(new_type))
2101 return; // Not considered as a text input field in WebKit/Chromium.
2102
[email protected]5b739cb2012-08-21 20:35:212103 WebKit::WebTextInputInfo new_info;
2104 if (webwidget_)
2105 new_info = webwidget_->textInputInfo();
2106
[email protected]ad26ef42011-06-17 07:59:452107 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:212108
[email protected]3306f262012-09-21 19:20:422109 // Only sends text input params if they are changed or if the ime should be
2110 // shown.
2111 if (show_ime_if_needed || (text_input_type_ != new_type
2112 || text_input_info_ != new_info
2113 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:212114 ViewHostMsg_TextInputState_Params p;
2115 p.type = new_type;
2116 p.value = new_info.value.utf8();
2117 p.selection_start = new_info.selectionStart;
2118 p.selection_end = new_info.selectionEnd;
2119 p.composition_start = new_info.compositionStart;
2120 p.composition_end = new_info.compositionEnd;
2121 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:422122 p.show_ime_if_needed = show_ime_if_needed;
[email protected]5b739cb2012-08-21 20:35:212123 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
2124
2125 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:042126 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:452127 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:292128 }
initial.commit09911bf2008-07-26 23:55:292129}
2130
[email protected]7c8873e2013-02-05 08:03:012131void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2132 WebRect focus_webrect;
2133 WebRect anchor_webrect;
2134 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
2135 *focus = focus_webrect;
2136 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322137}
2138
[email protected]e99ef6f2011-10-16 01:13:002139void RenderWidget::UpdateSelectionBounds() {
2140 if (!webwidget_)
2141 return;
[email protected]66fca5bc2013-05-23 06:58:292142 if (handling_ime_event_)
2143 return;
[email protected]e99ef6f2011-10-16 01:13:002144
[email protected]7c8873e2013-02-05 08:03:012145 ViewHostMsg_SelectionBounds_Params params;
2146 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2147 if (selection_anchor_rect_ != params.anchor_rect ||
2148 selection_focus_rect_ != params.focus_rect) {
2149 selection_anchor_rect_ = params.anchor_rect;
2150 selection_focus_rect_ = params.focus_rect;
2151 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
[email protected]129b7382013-02-12 02:14:292152 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
[email protected]7c8873e2013-02-05 08:03:012153 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
[email protected]58b48a0d2012-06-13 07:01:352154 }
[email protected]e99ef6f2011-10-16 01:13:002155
[email protected]58b48a0d2012-06-13 07:01:352156 std::vector<gfx::Rect> character_bounds;
2157 GetCompositionCharacterBounds(&character_bounds);
2158 UpdateCompositionInfo(composition_range_, character_bounds);
2159}
2160
2161bool RenderWidget::ShouldUpdateCompositionInfo(
2162 const ui::Range& range,
2163 const std::vector<gfx::Rect>& bounds) {
2164 if (composition_range_ != range)
2165 return true;
2166 if (bounds.size() != composition_character_bounds_.size())
2167 return true;
2168 for (size_t i = 0; i < bounds.size(); ++i) {
2169 if (bounds[i] != composition_character_bounds_[i])
2170 return true;
2171 }
2172 return false;
[email protected]e99ef6f2011-10-16 01:13:002173}
2174
[email protected]73bf95812011-10-12 11:38:322175// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:452176COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
2177 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
2178COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
2179 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
2180COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
2181 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:182182COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
2183 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
2184COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
2185 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
2186COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
2187 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
2188COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
2189 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
2190COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
2191 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:002192COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
2193 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
2194COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
2195 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
2196COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
2197 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
2198COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
2199 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
2200COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
2201 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
2202COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
2203 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:012204COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
2205 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
2206COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
2207 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]8b4992e2013-03-01 15:42:152208COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeField) == \
2209 int(ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:452210
[email protected]5b739cb2012-08-21 20:35:212211ui::TextInputType RenderWidget::WebKitToUiTextInputType(
2212 WebKit::WebTextInputType type) {
2213 // Check the type is in the range representable by ui::TextInputType.
2214 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
2215 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
2216 return static_cast<ui::TextInputType>(type);
2217}
2218
[email protected]ad26ef42011-06-17 07:59:452219ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272220 if (webwidget_)
2221 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452222 return ui::TEXT_INPUT_TYPE_NONE;
2223}
2224
[email protected]58b48a0d2012-06-13 07:01:352225void RenderWidget::GetCompositionCharacterBounds(
2226 std::vector<gfx::Rect>* bounds) {
2227 DCHECK(bounds);
2228 bounds->clear();
2229}
2230
[email protected]ad26ef42011-06-17 07:59:452231bool RenderWidget::CanComposeInline() {
2232 return true;
[email protected]56ea1a62011-05-30 07:05:572233}
2234
[email protected]4873c7d2009-07-16 06:36:282235WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042236 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282237}
2238
[email protected]f660d9c2012-06-06 18:31:212239float RenderWidget::deviceScaleFactor() {
2240 return device_scale_factor_;
2241}
2242
[email protected]fa7b1dc2010-06-23 17:53:042243void RenderWidget::resetInputMethod() {
2244 if (!input_method_is_active_)
2245 return;
2246
2247 // If the last text input type is not None, then we should finish any
2248 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452249 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042250 // If a composition text exists, then we need to let the browser process
2251 // to cancel the input method's ongoing composition session.
2252 if (webwidget_->confirmComposition())
2253 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
2254 }
[email protected]d4cff272011-05-02 15:46:012255
2256 // Send an updated IME range with the current caret rect.
2257 ui::Range range(ui::Range::InvalidRange());
2258 size_t location, length;
2259 if (webwidget_->caretOrSelectionRange(&location, &length)) {
2260 range.set_start(location);
2261 range.set_end(location + length);
2262 }
[email protected]58b48a0d2012-06-13 07:01:352263
2264 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]fa7b1dc2010-06-23 17:53:042265}
2266
[email protected]c68c3e4e2013-01-24 00:36:562267void RenderWidget::didHandleGestureEvent(
2268 const WebGestureEvent& event,
2269 bool event_cancelled) {
2270#if defined(OS_ANDROID)
2271 if (event_cancelled)
2272 return;
2273 if (event.type == WebInputEvent::GestureTap ||
2274 event.type == WebInputEvent::GestureLongPress) {
2275 UpdateTextInputState(SHOW_IME_IF_NEEDED);
2276 }
2277#endif
2278}
2279
[email protected]f103ab72009-09-02 17:10:592280void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:502281 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292282 size_t i = 0;
2283 for (; i < plugin_window_moves_.size(); ++i) {
2284 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582285 if (move.rects_valid) {
2286 plugin_window_moves_[i] = move;
2287 } else {
2288 plugin_window_moves_[i].visible = move.visible;
2289 }
initial.commit09911bf2008-07-26 23:55:292290 break;
2291 }
2292 }
2293
2294 if (i == plugin_window_moves_.size())
2295 plugin_window_moves_.push_back(move);
2296}
[email protected]268654772009-08-06 23:02:042297
2298void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2299 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2300 i != plugin_window_moves_.end(); ++i) {
2301 if (i->window == window) {
2302 plugin_window_moves_.erase(i);
2303 break;
2304 }
2305 }
2306}
[email protected]67bfb83f2011-09-22 03:36:372307
[email protected]b63d58d2012-11-26 22:37:442308void RenderWidget::GetRenderingStats(
2309 WebKit::WebRenderingStatsImpl& stats) const {
[email protected]ba91a792013-02-06 09:48:282310 if (compositor_)
[email protected]635353c2013-03-06 09:11:202311 compositor_->GetRenderingStats(&stats.rendering_stats);
[email protected]b63d58d2012-11-26 22:37:442312
[email protected]62049562013-03-24 00:39:012313 stats.rendering_stats.animation_frame_count +=
2314 software_stats_.animation_frame_count;
2315 stats.rendering_stats.screen_frame_count +=
2316 software_stats_.screen_frame_count;
2317 stats.rendering_stats.total_paint_time +=
2318 software_stats_.total_paint_time;
2319 stats.rendering_stats.total_pixels_painted +=
2320 software_stats_.total_pixels_painted;
[email protected]fef5e3972012-08-07 03:59:472321}
2322
[email protected]e9ff79c2012-10-19 21:31:262323bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:522324 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
2325 if (!gpu_channel)
2326 return false;
2327
2328 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
2329}
2330
[email protected]24ed0432013-04-24 07:50:312331RenderWidgetCompositor* RenderWidget::compositor() const {
2332 return compositor_.get();
2333}
2334
[email protected]0c2ebef2013-04-03 12:14:102335void RenderWidget::BeginSmoothScroll(
[email protected]0e241b4b2012-08-18 09:06:272336 bool down,
[email protected]ebd8b562012-10-09 14:44:292337 const SmoothScrollCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:192338 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:292339 int mouse_event_x,
2340 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:272341 DCHECK(!callback.is_null());
[email protected]267909d2012-10-20 04:36:192342
2343 ViewHostMsg_BeginSmoothScroll_Params params;
2344 params.scroll_down = down;
2345 params.pixels_to_scroll = pixels_to_scroll;
2346 params.mouse_event_x = mouse_event_x;
2347 params.mouse_event_y = mouse_event_y;
2348
[email protected]4a9dba42013-04-29 18:24:222349 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, params));
2350 pending_smooth_scroll_gesture_ = callback;
[email protected]a39ca1652012-07-13 21:30:582351}
2352
[email protected]a2b5ded2013-05-20 21:32:532353void RenderWidget::DidOverscroll(gfx::Vector2dF accumulated_overscroll,
2354 gfx::Vector2dF current_fling_velocity) {
2355 if (overscroll_notifications_enabled_) {
2356 Send(new ViewHostMsg_DidOverscroll(routing_id_,
2357 accumulated_overscroll,
2358 current_fling_velocity));
2359 }
2360}
2361
[email protected]67bfb83f2011-09-22 03:36:372362bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
2363 return false;
2364}
[email protected]c3d45532011-10-07 19:20:402365
[email protected]41d86852012-11-07 12:23:242366bool RenderWidget::WillHandleGestureEvent(
2367 const WebKit::WebGestureEvent& event) {
2368 return false;
2369}
2370
[email protected]ce6689f2013-03-29 12:52:552371void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2372 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2373}
2374
[email protected]3d5c243b2012-11-30 00:26:012375bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2376 return true;
2377}
2378
[email protected]3ae68c52013-04-12 06:10:052379WebGraphicsContext3DCommandBufferImpl* RenderWidget::CreateGraphicsContext3D(
[email protected]92fd8c02013-03-29 08:54:152380 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
[email protected]ed7defa2013-03-12 21:29:592381 if (!webwidget_)
2382 return NULL;
[email protected]8f746982013-03-21 06:28:032383 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
2384 new WebGraphicsContext3DCommandBufferImpl(
2385 surface_id(),
2386 GetURLForGraphicsContext3D(),
2387 RenderThreadImpl::current(),
2388 weak_ptr_factory_.GetWeakPtr()));
[email protected]ed7defa2013-03-12 21:29:592389
[email protected]8f746982013-03-21 06:28:032390 if (!context->Initialize(
2391 attributes,
2392 false /* bind generates resources */,
2393 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
2394 return NULL;
2395 return context.release();
[email protected]ed7defa2013-03-12 21:29:592396}
2397
[email protected]e9ff79c2012-10-19 21:31:262398} // namespace content