blob: 593b43b3c114da7cc14be112db161e2b7d28bd26 [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]8c89e7792009-08-19 21:18:3458#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5059#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4660#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
[email protected]799fd732013-05-15 21:18:5261#include "webkit/renderer/compositor_bindings/web_rendering_stats_impl.h"
[email protected]661eb9d2009-02-03 02:11:4862
[email protected]eeb93112013-05-01 19:41:1063#if defined(OS_ANDROID)
64#include "content/renderer/android/synchronous_compositor_output_surface.h"
65#endif
66
[email protected]661eb9d2009-02-03 02:11:4867#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4968#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5269#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4170#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4871#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4472
[email protected]8bd0fe62011-01-17 06:44:3773#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2974
[email protected]fa7b1dc2010-06-23 17:53:0475using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3076using WebKit::WebCursorInfo;
[email protected]41d86852012-11-07 12:23:2477using WebKit::WebGestureEvent;
[email protected]62cb33cae2009-03-27 23:30:2278using WebKit::WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0679using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2880using WebKit::WebNavigationPolicy;
[email protected]a7547fb2012-03-08 04:43:4481using WebKit::WebPagePopup;
[email protected]e99ef6f2011-10-16 01:13:0082using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2883using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5984using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1885using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0186using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5287using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1988using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5289using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2890using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2491using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0492using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1893using WebKit::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:2694
[email protected]6a4d7f62013-01-07 21:32:1395namespace {
96const char* GetEventName(WebInputEvent::Type type) {
97#define CASE_TYPE(t) case WebInputEvent::t: return #t
98 switch(type) {
99 CASE_TYPE(Undefined);
100 CASE_TYPE(MouseDown);
101 CASE_TYPE(MouseUp);
102 CASE_TYPE(MouseMove);
103 CASE_TYPE(MouseEnter);
104 CASE_TYPE(MouseLeave);
105 CASE_TYPE(ContextMenu);
106 CASE_TYPE(MouseWheel);
107 CASE_TYPE(RawKeyDown);
108 CASE_TYPE(KeyDown);
109 CASE_TYPE(KeyUp);
110 CASE_TYPE(Char);
111 CASE_TYPE(GestureScrollBegin);
112 CASE_TYPE(GestureScrollEnd);
113 CASE_TYPE(GestureScrollUpdate);
114 CASE_TYPE(GestureFlingStart);
115 CASE_TYPE(GestureFlingCancel);
116 CASE_TYPE(GestureTap);
[email protected]1c43b0a2013-05-10 07:43:23117 CASE_TYPE(GestureTapUnconfirmed);
[email protected]6a4d7f62013-01-07 21:32:13118 CASE_TYPE(GestureTapDown);
119 CASE_TYPE(GestureTapCancel);
120 CASE_TYPE(GestureDoubleTap);
121 CASE_TYPE(GestureTwoFingerTap);
122 CASE_TYPE(GestureLongPress);
123 CASE_TYPE(GestureLongTap);
124 CASE_TYPE(GesturePinchBegin);
125 CASE_TYPE(GesturePinchEnd);
126 CASE_TYPE(GesturePinchUpdate);
127 CASE_TYPE(TouchStart);
128 CASE_TYPE(TouchMove);
129 CASE_TYPE(TouchEnd);
130 CASE_TYPE(TouchCancel);
[email protected]3ec08ed2013-01-11 15:59:57131 default:
132 // Must include default to let WebKit::WebInputEvent add new event types
133 // before they're added here.
134 DLOG(WARNING) << "Unhandled WebInputEvent type in GetEventName.\n";
135 break;
[email protected]6a4d7f62013-01-07 21:32:13136 }
137#undef CASE_TYPE
[email protected]3ec08ed2013-01-11 15:59:57138 return "";
[email protected]6a4d7f62013-01-07 21:32:13139}
140}
[email protected]e9ff79c2012-10-19 21:31:26141namespace content {
[email protected]62cb33cae2009-03-27 23:30:22142
[email protected]6fd35b72012-03-01 19:46:41143RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]842f10652012-06-06 01:54:04144 const WebKit::WebScreenInfo& screen_info,
[email protected]14392a52012-05-02 20:28:44145 bool swapped_out)
initial.commit09911bf2008-07-26 23:55:29146 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56147 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:11148 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:29149 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30150 init_complete_(false),
[email protected]b4d08452010-10-05 17:34:35151 current_paint_buf_(NULL),
[email protected]d9083762013-03-24 01:36:40152 overdraw_bottom_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29153 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:06154 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:05155 update_reply_pending_(false),
[email protected]847a2582013-03-09 02:29:51156 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09157 need_update_rect_for_auto_resize_(false),
[email protected]65225772011-05-12 21:10:24158 using_asynchronous_swapbuffers_(false),
159 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:29160 did_show_(false),
initial.commit09911bf2008-07-26 23:55:29161 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:09162 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:29163 needs_repainting_on_restore_(false),
164 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49165 handling_input_event_(false),
[email protected]e8f775f2013-02-14 21:00:50166 handling_ime_event_(false),
[email protected]661eb9d2009-02-03 02:11:48167 closing_(false),
[email protected]14392a52012-05-02 20:28:44168 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04169 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45170 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
171 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12172 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48173 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12174 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50175 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21176 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07177 invalidation_task_posted_(false),
[email protected]842f10652012-06-06 01:54:04178 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52179 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]0e241b4b2012-08-18 09:06:27180 throttle_input_events_(true),
[email protected]ed7defa2013-03-12 21:29:59181 is_threaded_compositing_enabled_(false),
[email protected]a2b5ded2013-05-20 21:32:53182 overscroll_notifications_enabled_(false),
[email protected]69e797f2013-04-30 01:10:22183 weak_ptr_factory_(this) {
[email protected]8b3f0eb2012-05-03 19:15:05184 if (!swapped_out)
185 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27186 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18187 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
188 switches::kDisableGpuVsync);
[email protected]cb6430932012-10-31 00:53:36189 is_threaded_compositing_enabled_ =
190 CommandLine::ForCurrentProcess()->HasSwitch(
191 switches::kEnableThreadedCompositing);
[email protected]a2b5ded2013-05-20 21:32:53192 overscroll_notifications_enabled_ =
193 CommandLine::ForCurrentProcess()->HasSwitch(
194 switches::kEnableOverscrollNotifications);
initial.commit09911bf2008-07-26 23:55:29195}
196
197RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11198 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21199 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35200 if (current_paint_buf_) {
201 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
202 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29203 }
[email protected]992db4c2011-05-12 15:37:15204 // If we are swapped out, we have released already.
205 if (!is_swapped_out_)
206 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29207}
208
[email protected]484955942010-08-19 16:13:18209// static
[email protected]8085dbc82008-09-26 22:53:44210RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:04211 WebKit::WebPopupType popup_type,
212 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29213 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41214 scoped_refptr<RenderWidget> widget(
[email protected]842f10652012-06-06 01:54:04215 new RenderWidget(popup_type, screen_info, false));
[email protected]a635f942012-12-07 10:34:29216 if (widget->Init(opener_id)) { // adds reference on success.
217 return widget;
218 }
219 return NULL;
initial.commit09911bf2008-07-26 23:55:29220}
221
[email protected]484955942010-08-19 16:13:18222// static
223WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
224 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03225 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18226 break;
227 case WebKit::WebPopupTypeSelect:
228 case WebKit::WebPopupTypeSuggestion:
229 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44230 case WebKit::WebPopupTypePage:
231 return WebPagePopup::create(render_widget);
[email protected]4b1146bc2012-07-10 18:46:03232 case WebKit::WebPopupTypeHelperPlugin:
233 return WebKit::WebHelperPlugin::create(render_widget);
[email protected]484955942010-08-19 16:13:18234 default:
235 NOTREACHED();
236 }
237 return NULL;
238}
239
[email protected]a635f942012-12-07 10:34:29240bool RenderWidget::Init(int32 opener_id) {
241 return DoInit(opener_id,
242 RenderWidget::CreateWebWidget(this),
243 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
244 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18245}
246
[email protected]a635f942012-12-07 10:34:29247bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06248 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18249 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29250 DCHECK(!webwidget_);
251
252 if (opener_id != MSG_ROUTING_NONE)
253 opener_id_ = opener_id;
254
[email protected]484955942010-08-19 16:13:18255 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29256
[email protected]380244092011-10-07 17:26:27257 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29258 if (result) {
[email protected]380244092011-10-07 17:26:27259 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29260 // Take a reference on behalf of the RenderThread. This will be balanced
261 // when we receive ViewMsg_Close.
262 AddRef();
[email protected]a635f942012-12-07 10:34:29263 return true;
initial.commit09911bf2008-07-26 23:55:29264 } else {
[email protected]a635f942012-12-07 10:34:29265 // The above Send can fail when the tab is closing.
266 return false;
initial.commit09911bf2008-07-26 23:55:29267 }
268}
269
[email protected]fc4404d2012-11-07 19:53:30270// This is used to complete pending inits and non-pending inits.
271void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29272 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29273
[email protected]fc4404d2012-11-07 19:53:30274 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42275
[email protected]8926c602013-01-23 05:32:06276 if (webwidget_ && is_threaded_compositing_enabled_) {
277 webwidget_->enterForceCompositingMode(true);
278 }
[email protected]ba91a792013-02-06 09:48:28279 if (compositor_) {
280 compositor_->setSurfaceReady();
[email protected]479b0172012-10-29 19:27:09281 }
[email protected]05a980d7a2012-02-07 22:16:42282 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29283
[email protected]6de74452009-02-25 18:04:59284 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29285}
286
[email protected]992db4c2011-05-12 15:37:15287void RenderWidget::SetSwappedOut(bool is_swapped_out) {
288 // We should only toggle between states.
289 DCHECK(is_swapped_out_ != is_swapped_out);
290 is_swapped_out_ = is_swapped_out;
291
292 // If we are swapping out, we will call ReleaseProcess, allowing the process
293 // to exit if all of its RenderViews are swapped out. We wait until the
294 // WasSwappedOut call to do this, to avoid showing the sad tab.
295 // If we are swapping in, we call AddRefProcess to prevent the process from
296 // exiting.
297 if (!is_swapped_out)
298 RenderProcess::current()->AddRefProcess();
299}
300
[email protected]34bb3ac2013-03-08 02:41:28301bool RenderWidget::AllowPartialSwap() const {
302 return true;
303}
304
[email protected]c8cbae72013-05-23 10:45:03305bool RenderWidget::UsingSynchronousRendererCompositor() const {
[email protected]ccc1722e2013-05-06 19:43:07306#if defined(OS_ANDROID)
307 if (CommandLine::ForCurrentProcess()->HasSwitch(
308 switches::kEnableSynchronousRendererCompositor)) {
309 return true;
310 }
311#endif
312 return false;
313}
314
[email protected]a95986a82010-12-24 06:19:28315bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
316 bool handled = true;
317 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15318 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22319 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
320 OnCursorVisibilityChange)
[email protected]c084330e02013-04-27 01:08:15321 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
322 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]a95986a82010-12-24 06:19:28323 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
324 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
325 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54326 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28327 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41328 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]992db4c2011-05-12 15:37:15329 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28330 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]ed7defa2013-03-12 21:29:59331 IPC_MESSAGE_HANDLER(ViewMsg_SwapBuffers_ACK,
332 OnViewContextSwapBuffersComplete)
[email protected]a95986a82010-12-24 06:19:28333 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
334 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
335 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]3d9ec5052013-01-02 22:05:25336 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnPaintAtSize)
337 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
338 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, OnSmoothScrollCompleted)
[email protected]a95986a82010-12-24 06:19:28339 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
340 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]6131a642012-06-15 23:26:53341 IPC_MESSAGE_HANDLER(ViewMsg_ScreenInfoChanged, OnScreenInfoChanged)
[email protected]80ad8622012-11-07 16:33:03342 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]105dffb42013-02-20 03:46:21343#if defined(OS_ANDROID)
344 IPC_MESSAGE_HANDLER(ViewMsg_ImeBatchStateChanged, OnImeBatchStateChanged)
[email protected]2384b6c2013-02-28 23:58:51345 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21346#endif
[email protected]51a49502013-03-23 01:50:19347 IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot)
[email protected]a95986a82010-12-24 06:19:28348 IPC_MESSAGE_UNHANDLED(handled = false)
349 IPC_END_MESSAGE_MAP()
350 return handled;
351}
initial.commit09911bf2008-07-26 23:55:29352
353bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15354 // Don't send any messages after the browser has told us to close, and filter
355 // most outgoing messages while swapped out.
356 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26357 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11358 closing_) {
initial.commit09911bf2008-07-26 23:55:29359 delete message;
360 return false;
361 }
362
363 // If given a messsage without a routing ID, then assign our routing ID.
364 if (message->routing_id() == MSG_ROUTING_NONE)
365 message->set_routing_id(routing_id_);
366
[email protected]380244092011-10-07 17:26:27367 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44368}
369
[email protected]61e2b3cc2012-03-02 16:13:34370void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44371 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40372 float overdraw_bottom_height,
[email protected]61e2b3cc2012-03-02 16:13:34373 const gfx::Rect& resizer_rect,
374 bool is_fullscreen,
375 ResizeAck resize_ack) {
376 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
377 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
378 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29379
[email protected]61e2b3cc2012-03-02 16:13:34380 // Ignore this during shutdown.
381 if (!webwidget_)
382 return;
383
[email protected]d9083762013-03-24 01:36:40384 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44385 compositor_->setViewportSize(new_size, physical_backing_size);
[email protected]d9083762013-03-24 01:36:40386 compositor_->SetOverdrawBottomHeight(overdraw_bottom_height);
387 }
[email protected]60d47ac2013-03-01 23:42:44388
[email protected]dade8992013-03-04 07:34:34389 physical_backing_size_ = physical_backing_size;
[email protected]d9083762013-03-24 01:36:40390 overdraw_bottom_height_ = overdraw_bottom_height;
[email protected]61e2b3cc2012-03-02 16:13:34391 resizer_rect_ = resizer_rect;
392
393 // NOTE: We may have entered fullscreen mode without changing our size.
394 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
395 if (fullscreen_change)
396 WillToggleFullscreen();
397 is_fullscreen_ = is_fullscreen;
398
399 if (size_ != new_size) {
400 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34401 needs_repainting_on_restore_ = false;
402
403 size_ = new_size;
404
405 paint_aggregator_.ClearPendingUpdate();
406
407 // When resizing, we want to wait to paint before ACK'ing the resize. This
408 // ensures that we only resize as fast as we can paint. We only need to
409 // send an ACK if we are resized to a non-empty rect.
410 webwidget_->resize(new_size);
[email protected]0b70dbe2013-05-10 19:06:32411
412 // Resize should have caused an invalidation of the entire view.
413 DCHECK(new_size.IsEmpty() || is_accelerated_compositing_active_ ||
414 paint_aggregator_.HasPendingUpdate());
[email protected]1f792d52013-05-22 06:52:45415 } else if (size_browser_expects_ == new_size) {
[email protected]632c4382013-05-15 08:58:45416 resize_ack = NO_RESIZE_ACK;
417 }
418
419 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
420 // For empty size or empty physical_backing_size, there is no next paint
421 // (along with which to send the ack) until they are set to non-empty.
[email protected]ff475a322012-03-14 00:05:35422 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34423 }
424
[email protected]20fbfc22013-05-08 20:50:58425 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45426 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58427 set_next_paint_is_resize_ack();
428
[email protected]61e2b3cc2012-03-02 16:13:34429 if (fullscreen_change)
430 DidToggleFullscreen();
431
432 // If a resize ack is requested and it isn't set-up, then no more resizes will
433 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45434 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29435}
436
437void RenderWidget::OnClose() {
438 if (closing_)
439 return;
440 closing_ = true;
441
442 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03443 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27444 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03445 SetHidden(false);
446 }
initial.commit09911bf2008-07-26 23:55:29447
initial.commit09911bf2008-07-26 23:55:29448 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25449 // now. Post a task that only gets invoked when there are no nested message
450 // loops.
[email protected]dd32b1272013-05-04 14:17:11451 base::MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29452 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25453
454 // Balances the AddRef taken when we called AddRoute.
455 Release();
initial.commit09911bf2008-07-26 23:55:29456}
457
[email protected]61e2b3cc2012-03-02 16:13:34458// Got a response from the browser after the renderer decided to create a new
459// view.
[email protected]fc4404d2012-11-07 19:53:30460void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34461 DCHECK(routing_id_ != MSG_ROUTING_NONE);
462
[email protected]fc4404d2012-11-07 19:53:30463 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34464}
465
[email protected]f21c613a2009-02-12 14:46:17466void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44467 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40468 float overdraw_bottom_height,
[email protected]ee41e7d22011-10-14 19:34:09469 const gfx::Rect& resizer_rect,
470 bool is_fullscreen) {
[email protected]d9083762013-03-24 01:36:40471 Resize(new_size, physical_backing_size, overdraw_bottom_height, resizer_rect,
472 is_fullscreen, SEND_RESIZE_ACK);
[email protected]1f792d52013-05-22 06:52:45473 size_browser_expects_ = new_size;
initial.commit09911bf2008-07-26 23:55:29474}
475
[email protected]b5913d72012-02-07 22:26:54476void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
477 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59478 gfx::Rect view_rect(size_);
479
[email protected]ce112fe2012-10-29 22:52:18480 gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_);
[email protected]b9769d82012-02-10 00:23:59481 if (!old_damage_rect.IsEmpty())
482 paint_aggregator_.InvalidateRect(old_damage_rect);
483
[email protected]ce112fe2012-10-29 22:52:18484 gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect);
[email protected]b9769d82012-02-10 00:23:59485 if (!new_damage_rect.IsEmpty())
486 paint_aggregator_.InvalidateRect(new_damage_rect);
487
[email protected]b5913d72012-02-07 22:26:54488 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59489
[email protected]b5913d72012-02-07 22:26:54490 if (webwidget_)
491 webwidget_->didChangeWindowResizerRect();
492 }
493}
494
initial.commit09911bf2008-07-26 23:55:29495void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31496 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29497 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03498 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29499}
500
[email protected]9e2e4632012-07-27 16:38:41501void RenderWidget::OnWasShown(bool needs_repainting) {
502 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29503 // During shutdown we can just ignore this message.
504 if (!webwidget_)
505 return;
506
507 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03508 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29509
510 if (!needs_repainting && !needs_repainting_on_restore_)
511 return;
512 needs_repainting_on_restore_ = false;
513
[email protected]d65adb12010-04-28 17:26:49514 // Tag the next paint as a restore ack, which is picked up by
515 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29516 set_next_paint_is_restore_ack();
517
518 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56519 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46520 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
521 } else {
522 scheduleComposite();
523 }
initial.commit09911bf2008-07-26 23:55:29524}
525
[email protected]992db4c2011-05-12 15:37:15526void RenderWidget::OnWasSwappedOut() {
527 // If we have been swapped out and no one else is using this process,
528 // it's safe to exit now. If we get swapped back in, we will call
529 // AddRefProcess in SetSwappedOut.
530 if (is_swapped_out_)
531 RenderProcess::current()->ReleaseProcess();
532}
533
[email protected]53d3f302009-12-21 04:42:05534void RenderWidget::OnRequestMoveAck() {
535 DCHECK(pending_window_rect_count_);
536 pending_window_rect_count_--;
537}
538
539void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58540 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21541 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05542 update_reply_pending_ = false;
[email protected]1f792d52013-05-22 06:52:45543 size_browser_expects_ = size_;
[email protected]53d3f302009-12-21 04:42:05544
[email protected]b4d08452010-10-05 17:34:35545 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
546 // have no current paint buffer.
547 if (current_paint_buf_) {
548 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
549 current_paint_buf_ = NULL;
550 }
551
[email protected]65225772011-05-12 21:10:24552 // If swapbuffers is still pending, then defer the update until the
553 // swapbuffers occurs.
554 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
555 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
556 return;
557 }
558
[email protected]29ed96a2012-02-04 18:12:16559 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18560 if (!is_accelerated_compositing_active_) {
561 DidFlushPaint();
562 }
[email protected]a2f6bc112009-06-27 16:27:25563
initial.commit09911bf2008-07-26 23:55:29564 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24565 DoDeferredUpdateAndSendInputAck();
566}
567
[email protected]d0be63772011-12-20 23:18:04568bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]ed7defa2013-03-12 21:29:59569 // Contexts using the command buffer support asynchronous swapbuffers.
570 // See RenderWidget::CreateOutputSurface().
[email protected]8f746982013-03-21 06:28:03571 if (RenderThreadImpl::current()->compositor_message_loop_proxy())
[email protected]ed7defa2013-03-12 21:29:59572 return false;
573
574 return true;
575}
576
577GURL RenderWidget::GetURLForGraphicsContext3D() {
578 return GURL();
[email protected]65225772011-05-12 21:10:24579}
580
[email protected]479b0172012-10-29 19:27:09581bool RenderWidget::ForceCompositingModeEnabled() {
582 return false;
583}
584
[email protected]ba91a792013-02-06 09:48:28585scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface() {
[email protected]c3e32ed42013-05-02 05:07:13586 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]a1811b8912013-05-09 15:35:19587
588#if defined(OS_ANDROID)
589 if (command_line.HasSwitch(switches::kEnableSynchronousRendererCompositor)) {
590 return scoped_ptr<cc::OutputSurface>(
591 new SynchronousCompositorOutputSurface(routing_id()));
592 }
593#endif
594
[email protected]8bbe3a92013-05-12 00:58:35595 if (command_line.HasSwitch(switches::kEnableSoftwareCompositingGLAdapter)) {
596 return scoped_ptr<cc::OutputSurface>(
597 new CompositorOutputSurface(routing_id(), NULL,
598 new CompositorSoftwareOutputDevice()));
599 }
600
[email protected]ed7defa2013-03-12 21:29:59601 // Explicitly disable antialiasing for the compositor. As of the time of
602 // this writing, the only platform that supported antialiasing for the
603 // compositor was Mac OS X, because the on-screen OpenGL context creation
604 // code paths on Windows and Linux didn't yet have multisampling support.
605 // Mac OS X essentially always behaves as though it's rendering offscreen.
606 // Multisampling has a heavy cost especially on devices with relatively low
607 // fill rate like most notebooks, and the Mac implementation would need to
608 // be optimized to resolve directly into the IOSurface shared between the
609 // GPU and browser processes. For these reasons and to avoid platform
610 // disparities we explicitly disable antialiasing.
611 WebKit::WebGraphicsContext3D::Attributes attributes;
612 attributes.antialias = false;
613 attributes.shareResources = true;
614 attributes.noAutomaticFlushes = true;
[email protected]a6886502013-05-16 20:59:18615 attributes.depth = false;
616 attributes.stencil = false;
[email protected]bec084292013-05-21 21:31:44617 if (command_line.HasSwitch(cc::switches::kForceDirectLayerDrawing))
618 attributes.stencil = true;
[email protected]3ae68c52013-04-12 06:10:05619 WebGraphicsContext3DCommandBufferImpl* context =
620 CreateGraphicsContext3D(attributes);
[email protected]8bbe3a92013-05-12 00:58:35621 if (!context)
622 return scoped_ptr<cc::OutputSurface>();
[email protected]ed7defa2013-03-12 21:29:59623
[email protected]2847b222013-04-06 00:59:24624 bool composite_to_mailbox =
[email protected]7b45b5762013-05-08 14:36:56625 command_line.HasSwitch(cc::switches::kCompositeToMailbox) &&
626 !command_line.HasSwitch(switches::kEnableDelegatedRenderer);
[email protected]2847b222013-04-06 00:59:24627 // No swap throttling yet when compositing on the main thread.
628 DCHECK(!composite_to_mailbox || is_threaded_compositing_enabled_);
629 return scoped_ptr<cc::OutputSurface>(composite_to_mailbox ?
630 new MailboxOutputSurface(routing_id(), context, NULL) :
631 new CompositorOutputSurface(routing_id(), context, NULL));
[email protected]ba91a792013-02-06 09:48:28632}
633
[email protected]ed7defa2013-03-12 21:29:59634void RenderWidget::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24635 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21636 while (!updates_pending_swap_.empty()) {
637 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
638 updates_pending_swap_.pop_front();
639 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
640 // compositing pass, hence doesn't require an UpdateRect message.
641 if (msg)
642 Send(msg);
643 }
[email protected]65225772011-05-12 21:10:24644 num_swapbuffers_complete_pending_ = 0;
645 using_asynchronous_swapbuffers_ = false;
646 // Schedule another frame so the compositor learns about it.
647 scheduleComposite();
648}
649
[email protected]ed7defa2013-03-12 21:29:59650void RenderWidget::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:08651 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21652
653 if (using_asynchronous_swapbuffers_) {
654 ViewHostMsg_UpdateRect* msg = NULL;
655 // pending_update_params_ can be NULL if the swap doesn't correspond to an
656 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
657 // message.
[email protected]59383c782013-04-17 16:43:27658 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:21659 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
660 pending_update_params_.reset();
661 }
662 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08663 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21664 }
[email protected]37a6f302011-07-11 23:43:08665}
666
[email protected]ed7defa2013-03-12 21:29:59667void RenderWidget::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24668 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16669
[email protected]404939f2012-06-01 04:06:18670 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16671 DidFlushPaint();
672
[email protected]65225772011-05-12 21:10:24673 // When compositing deactivates, we reset the swapbuffers pending count. The
674 // swapbuffers acks may still arrive, however.
675 if (num_swapbuffers_complete_pending_ == 0) {
676 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
677 return;
678 }
[email protected]aa4117f2011-12-09 22:19:21679 DCHECK(!updates_pending_swap_.empty());
680 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
681 updates_pending_swap_.pop_front();
682 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
683 // compositing pass, hence doesn't require an UpdateRect message.
684 if (msg)
685 Send(msg);
[email protected]65225772011-05-12 21:10:24686 num_swapbuffers_complete_pending_--;
687
688 // If update reply is still pending, then defer the update until that reply
689 // occurs.
[email protected]d0be63772011-12-20 23:18:04690 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24691 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
692 return;
693 }
694
695 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06696 // when we were previously rendering. However, if an invalidation task is not
697 // posted, there may be software rendering work pending. In that case, don't
698 // early out.
699 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24700 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
701 return;
702 }
703
[email protected]cc66e682012-10-02 06:48:18704 // Do not call DoDeferredUpdate unless there's animation work to be done or
705 // a real invalidation. This prevents rendering in response to a swapbuffers
706 // callback coming back after we've navigated away from the page that
707 // generated it.
708 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
709 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
710 return;
711 }
712
[email protected]65225772011-05-12 21:10:24713 // Continue painting if necessary...
714 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29715}
716
[email protected]0dea1652012-12-14 00:09:09717void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
[email protected]c2eaa8f2013-05-10 02:41:55718 const cc::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:09719 bool is_keyboard_shortcut) {
[email protected]5dd768212009-08-13 23:34:49720 handling_input_event_ = true;
[email protected]0dea1652012-12-14 00:09:09721 if (!input_event) {
[email protected]5dd768212009-08-13 23:34:49722 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29723 return;
[email protected]5dd768212009-08-13 23:34:49724 }
initial.commit09911bf2008-07-26 23:55:29725
[email protected]b4841e1c2013-05-16 22:30:10726 const char* const event_name = GetEventName(input_event->type);
727 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent",
728 "event", event_name);
729
[email protected]c2eaa8f2013-05-10 02:41:55730 if (compositor_)
731 compositor_->SetLatencyInfo(latency_info);
732
[email protected]6a4d7f62013-01-07 21:32:13733 base::TimeDelta now = base::TimeDelta::FromInternalValue(
734 base::TimeTicks::Now().ToInternalValue());
735
736 int64 delta = static_cast<int64>(
737 (now.InSecondsF() - input_event->timeStampSeconds) *
738 base::Time::kMicrosecondsPerSecond);
739 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer", delta, 0, 1000000, 100);
[email protected]de415552013-01-23 04:12:17740 base::HistogramBase* counter_for_type =
[email protected]bafdc5d52013-02-27 18:18:48741 base::Histogram::FactoryGet(
[email protected]b4841e1c2013-05-16 22:30:10742 base::StringPrintf("Event.Latency.Renderer.%s", event_name),
[email protected]bafdc5d52013-02-27 18:18:48743 0,
744 1000000,
[email protected]6a4d7f62013-01-07 21:32:13745 100,
[email protected]de415552013-01-23 04:12:17746 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]bafdc5d52013-02-27 18:18:48747 counter_for_type->Add(delta);
[email protected]6a4d7f62013-01-07 21:32:13748
[email protected]67bfb83f2011-09-22 03:36:37749 bool prevent_default = false;
750 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26751 const WebMouseEvent& mouse_event =
752 *static_cast<const WebMouseEvent*>(input_event);
753 TRACE_EVENT2("renderer", "HandleMouseMove",
754 "x", mouse_event.x, "y", mouse_event.y);
755 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37756 }
757
[email protected]41d86852012-11-07 12:23:24758 if (WebInputEvent::isGestureEventType(input_event->type)) {
759 const WebGestureEvent& gesture_event =
760 *static_cast<const WebGestureEvent*>(input_event);
761 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
762 }
763
[email protected]3ebcc7c2013-01-09 05:34:46764 if (input_event->type == WebInputEvent::GestureTap ||
765 input_event->type == WebInputEvent::GestureLongPress)
766 resetInputMethod();
767
[email protected]67bfb83f2011-09-22 03:36:37768 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12769 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
770 suppress_next_char_events_ = false;
771 if (!processed && webwidget_)
772 processed = webwidget_->handleInputEvent(*input_event);
773 }
774
775 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
776 // it's not processed by webkit, then we need to suppress the upcoming Char
777 // events.
778 if (!processed && is_keyboard_shortcut)
779 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29780
[email protected]3d5c243b2012-11-30 00:26:01781 InputEventAckState ack_result = processed ?
782 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
783 if (!processed && input_event->type == WebInputEvent::TouchStart) {
784 const WebTouchEvent& touch_event =
785 *static_cast<const WebTouchEvent*>(input_event);
786 ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ?
787 INPUT_EVENT_ACK_STATE_NOT_CONSUMED :
788 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
789 }
790
[email protected]a9fb30aa2011-10-06 06:58:46791 IPC::Message* response =
[email protected]c084330e02013-04-27 01:08:15792 new InputHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
793 ack_result);
[email protected]3391a0772012-03-28 00:32:07794 bool event_type_gets_rate_limited =
795 input_event->type == WebInputEvent::MouseMove ||
796 input_event->type == WebInputEvent::MouseWheel ||
797 WebInputEvent::isTouchEventType(input_event->type);
[email protected]8926c602013-01-23 05:32:06798
799 bool frame_pending = paint_aggregator_.HasPendingUpdate();
800 if (is_accelerated_compositing_active_) {
[email protected]ba91a792013-02-06 09:48:28801 frame_pending = compositor_ &&
802 compositor_->commitRequested();
[email protected]8926c602013-01-23 05:32:06803 }
804
[email protected]3391a0772012-03-28 00:32:07805 bool is_input_throttled =
[email protected]ce2b28e2012-08-09 15:53:57806 throttle_input_events_ &&
[email protected]8926c602013-01-23 05:32:06807 frame_pending;
[email protected]e2824412009-02-27 01:57:05808
[email protected]f8868d72012-04-27 19:13:03809 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24810 // We want to rate limit the input events in this case, so we'll wait for
811 // painting to finish before ACKing this message.
[email protected]59383c782013-04-17 16:43:27812 if (pending_input_event_ack_) {
[email protected]353a34c2010-05-28 23:35:17813 // As two different kinds of events could cause us to postpone an ack
814 // we send it now, if we have one pending. The Browser should never
815 // send us the same kind of event we are delaying the ack for.
816 Send(pending_input_event_ack_.release());
817 }
[email protected]12fbad812009-09-01 18:21:24818 pending_input_event_ack_.reset(response);
819 } else {
820 Send(response);
821 }
822
[email protected]3306f262012-09-21 19:20:42823#if defined(OS_ANDROID)
824 // Allow the IME to be shown when the focus changes as a consequence
825 // of a processed touch end event.
826 if (input_event->type == WebInputEvent::TouchEnd && processed)
827 UpdateTextInputState(SHOW_IME_IF_NEEDED);
828#endif
829
[email protected]5dd768212009-08-13 23:34:49830 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48831
[email protected]67bfb83f2011-09-22 03:36:37832 if (!prevent_default) {
833 if (WebInputEvent::isKeyboardEventType(input_event->type))
834 DidHandleKeyEvent();
835 if (WebInputEvent::isMouseEventType(input_event->type))
836 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24837 if (WebInputEvent::isTouchEventType(input_event->type))
838 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37839 }
initial.commit09911bf2008-07-26 23:55:29840}
841
[email protected]34202de2013-05-06 23:36:22842void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
843 if (webwidget_)
844 webwidget_->setCursorVisibilityState(is_visible);
845}
846
initial.commit09911bf2008-07-26 23:55:29847void RenderWidget::OnMouseCaptureLost() {
848 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28849 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29850}
851
852void RenderWidget::OnSetFocus(bool enable) {
853 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33854 if (webwidget_)
855 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29856}
857
858void RenderWidget::ClearFocus() {
859 // We may have got the focus from the browser before this gets processed, in
860 // which case we do not want to unfocus ourself.
861 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28862 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29863}
864
[email protected]2d5d09d52009-06-15 14:29:21865void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00866 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21867 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06868 TRACE_EVENT2("renderer", "PaintRect",
869 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:45870
871 const bool kEnableGpuBenchmarking =
872 CommandLine::ForCurrentProcess()->HasSwitch(
873 switches::kEnableGpuBenchmarking);
[email protected]4fb66842009-12-04 21:41:00874 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21875
876 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00877 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
878 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03879
[email protected]699ab0d2009-04-23 23:19:14880 // If there is a custom background, tile it.
881 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14882 SkPaint paint;
[email protected]4e29afd2012-12-04 04:07:11883 skia::RefPtr<SkShader> shader = skia::AdoptRef(
884 SkShader::CreateBitmapShader(background_,
885 SkShader::kRepeat_TileMode,
886 SkShader::kRepeat_TileMode));
887 paint.setShader(shader.get());
[email protected]fb10ec5b2011-10-24 17:54:20888
889 // Use kSrc_Mode to handle background_ transparency properly.
890 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
891
892 // Canvas could contain multiple update rects. Clip to given rect so that
893 // we don't accidentally clear other update rects.
894 canvas->save();
[email protected]aa7e7a12013-02-22 13:37:44895 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]1835b9e2012-02-28 13:12:48896 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14897 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20898 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14899 }
900
[email protected]719b36f2010-12-22 20:36:46901 // First see if this rect is a plugin that can paint itself faster.
902 TransportDIB* optimized_dib = NULL;
903 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:20904 float dib_scale_factor;
[email protected]719b36f2010-12-22 20:36:46905 webkit::ppapi::PluginInstance* optimized_instance =
906 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
907 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:20908 &optimized_copy_rect,
909 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:46910 if (optimized_instance) {
911 // This plugin can be optimize-painted and we can just ask it to paint
912 // itself. We don't actually need the TransportDIB in this case.
913 //
914 // This is an optimization for PPAPI plugins that know they're on top of
915 // the page content. If this rect is inside such a plugin, we can save some
916 // time and avoid re-rendering the page content which we know will be
917 // covered by the plugin later (this time can be significant, especially
918 // for a playing movie that is invalidating a lot).
919 //
920 // In the plugin movie case, hopefully the similar call to
921 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
922 // painting, because that avoids copying the plugin image to a different
923 // paint rect. Unfortunately, if anything on the page is animating other
924 // than the movie, it break this optimization since the union of the
925 // invalid regions will be larger than the plugin.
926 //
927 // This code optimizes that case, where we can still avoid painting in
928 // WebKit and filling the background (which can be slow) and just painting
929 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
930 // required.
[email protected]63ab54262012-11-09 15:58:45931 base::TimeTicks paint_begin_ticks;
932 if (kEnableGpuBenchmarking)
933 paint_begin_ticks = base::TimeTicks::HighResNow();
934
[email protected]df59dd42012-09-14 22:56:30935 SkAutoCanvasRestore auto_restore(canvas, true);
936 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]719b36f2010-12-22 20:36:46937 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27938 optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:21939 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45940 if (kEnableGpuBenchmarking) {
941 base::TimeDelta paint_time =
942 base::TimeTicks::HighResNow() - paint_begin_ticks;
943 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01944 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45945 }
[email protected]719b36f2010-12-22 20:36:46946 } else {
947 // Normal painting case.
[email protected]63ab54262012-11-09 15:58:45948 base::TimeTicks paint_begin_ticks;
949 if (kEnableGpuBenchmarking)
950 paint_begin_ticks = base::TimeTicks::HighResNow();
951
[email protected]719b36f2010-12-22 20:36:46952 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
[email protected]63ab54262012-11-09 15:58:45953
954 if (kEnableGpuBenchmarking) {
955 base::TimeDelta paint_time =
956 base::TimeTicks::HighResNow() - paint_begin_ticks;
957 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01958 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45959 }
[email protected]719b36f2010-12-22 20:36:46960
961 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35962 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46963 }
initial.commit09911bf2008-07-26 23:55:29964
[email protected]4fb66842009-12-04 21:41:00965 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00966 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45967
968 if (kEnableGpuBenchmarking) {
[email protected]63ab54262012-11-09 15:58:45969 int64 num_pixels_processed = rect.width() * rect.height();
[email protected]62049562013-03-24 00:39:01970 software_stats_.total_pixels_painted += num_pixels_processed;
[email protected]63ab54262012-11-09 15:58:45971 }
[email protected]4fb66842009-12-04 21:41:00972}
973
974void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
975 skia::PlatformCanvas* canvas) {
976 static bool kPaintBorder =
977 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
978 if (!kPaintBorder)
979 return;
980
[email protected]53d3f302009-12-21 04:42:05981 // Cycle through these colors to help distinguish new paint rects.
982 const SkColor colors[] = {
983 SkColorSetARGB(0x3F, 0xFF, 0, 0),
984 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
985 SkColorSetARGB(0x3F, 0, 0, 0xFF),
986 };
987 static int color_selector = 0;
988
[email protected]4fb66842009-12-04 21:41:00989 SkPaint paint;
990 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05991 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00992 paint.setStrokeWidth(1);
993
994 SkIRect irect;
995 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
996 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29997}
998
[email protected]52ccd0ea2011-02-16 01:09:05999void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:301000 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:301001 if (!animation_update_pending_) {
1002 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:591003 return;
[email protected]921244e42011-07-20 16:36:301004 }
[email protected]bd37ae252011-06-03 01:28:181005 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:591006 // Record when we fired (according to base::Time::Now()) relative to when
1007 // we posted the task to quantify how much the base::Time/base::TimeTicks
1008 // skew is affecting animations.
1009 base::TimeDelta animation_callback_delay = base::Time::Now() -
1010 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
1011 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
1012 animation_callback_delay,
1013 base::TimeDelta::FromMilliseconds(0),
1014 base::TimeDelta::FromMilliseconds(30),
1015 25);
1016 }
[email protected]65225772011-05-12 21:10:241017 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:241018}
1019
[email protected]52ccd0ea2011-02-16 01:09:051020void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:591021 if (!animation_update_pending_)
1022 return;
[email protected]bd37ae252011-06-03 01:28:181023
1024 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:331025 base::TimeDelta animationInterval = IsRenderingVSynced() ?
1026 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:181027
[email protected]7c4329e2011-02-18 22:02:591028 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:451029
1030 // animation_floor_time_ is the earliest time that we should animate when
1031 // using the dead reckoning software scheduler. If we're using swapbuffers
1032 // complete callbacks to rate limit, we can ignore this floor.
1033 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:301034 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:331035 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:181036 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:591037 // running animation callbacks so that if a callback requests another
1038 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:381039 animation_timer_.Stop();
1040 animation_timer_.Start(FROM_HERE, animationInterval, this,
1041 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:591042 animation_update_pending_ = false;
[email protected]ba91a792013-02-06 09:48:281043 if (is_accelerated_compositing_active_ && compositor_) {
[email protected]635353c2013-03-06 09:11:201044 compositor_->Animate(base::TimeTicks::Now());
[email protected]8926c602013-01-23 05:32:061045 } else {
[email protected]635353c2013-03-06 09:11:201046 double frame_begin_time =
1047 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
1048 webwidget_->animate(frame_begin_time);
[email protected]8926c602013-01-23 05:32:061049 }
[email protected]7c4329e2011-02-18 22:02:591050 return;
[email protected]5f8b1022011-01-21 23:34:501051 }
[email protected]bd37ae252011-06-03 01:28:181052 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:381053 if (!animation_timer_.IsRunning()) {
1054 // This code uses base::Time::Now() to calculate the floor and next fire
1055 // time because javascript's Date object uses base::Time::Now(). The
1056 // message loop uses base::TimeTicks, which on windows can have a
1057 // different granularity than base::Time.
1058 // The upshot of all this is that this function might be called before
1059 // base::Time::Now() has advanced past the animation_floor_time_. To
1060 // avoid exposing this delay to javascript, we keep posting delayed
1061 // tasks until base::Time::Now() has advanced far enough.
1062 base::TimeDelta delay = animation_floor_time_ - now;
1063 animation_timer_.Start(FROM_HERE, delay, this,
1064 &RenderWidget::AnimationCallback);
1065 }
[email protected]5f8b1022011-01-21 23:34:501066}
1067
[email protected]bd37ae252011-06-03 01:28:181068bool RenderWidget::IsRenderingVSynced() {
1069 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
1070 // not caught by this check. This will lead to artificially low frame rates
1071 // for people who force vsync off at a driver level and expect Chrome to speed
1072 // up.
1073 return !has_disable_gpu_vsync_switch_;
1074}
1075
[email protected]65225772011-05-12 21:10:241076void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:061077 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:241078 invalidation_task_posted_ = false;
1079 DoDeferredUpdateAndSendInputAck();
1080}
1081
1082void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:051083 DoDeferredUpdate();
1084
[email protected]59383c782013-04-17 16:43:271085 if (pending_input_event_ack_)
[email protected]52ccd0ea2011-02-16 01:09:051086 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:211087}
1088
[email protected]552e6002009-11-19 05:24:571089void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:581090 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:081091
[email protected]65225772011-05-12 21:10:241092 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:291093 return;
[email protected]05a980d7a2012-02-07 22:16:421094
[email protected]fc4404d2012-11-07 19:53:301095 if (!init_complete_) {
1096 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:421097 return;
1098 }
[email protected]aa4117f2011-12-09 22:19:211099 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:241100 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
1101 return;
1102 }
[email protected]9ca84622011-06-02 23:46:391103 if (is_accelerated_compositing_active_ &&
1104 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:241105 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
1106 return;
1107 }
initial.commit09911bf2008-07-26 23:55:291108
[email protected]552e6002009-11-19 05:24:571109 // Suppress updating when we are hidden.
[email protected]e3d92a7f2013-01-10 02:35:051110 if (is_hidden_ || size_.IsEmpty() || is_swapped_out_) {
[email protected]552e6002009-11-19 05:24:571111 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:291112 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:241113 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:291114 return;
1115 }
1116
[email protected]05a980d7a2012-02-07 22:16:421117 if (is_accelerated_compositing_active_)
1118 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
1119
[email protected]0fb93f52011-05-18 23:13:561120 // Tracking of frame rate jitter
1121 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]38ce4e7b2013-02-23 06:17:371122 InstrumentWillBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:051123 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:501124
[email protected]f98d7e3c2010-09-13 22:30:461125 // Layout may generate more invalidation. It may also enable the
1126 // GPU acceleration, so make sure to run layout before we send the
1127 // GpuRenderingActivated message.
1128 webwidget_->layout();
1129
[email protected]dcca3aa92012-02-17 23:03:371130 // The following two can result in further layout and possibly
1131 // enable GPU acceleration so they need to be called before any painting
1132 // is done.
[email protected]3306f262012-09-21 19:20:421133 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]dcca3aa92012-02-17 23:03:371134 UpdateSelectionBounds();
1135
[email protected]5f8b1022011-01-21 23:34:501136 // Suppress painting if nothing is dirty. This has to be done after updating
1137 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:241138 if (!paint_aggregator_.HasPendingUpdate()) {
1139 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]38ce4e7b2013-02-23 06:17:371140 InstrumentDidCancelFrame();
[email protected]5f8b1022011-01-21 23:34:501141 return;
[email protected]65225772011-05-12 21:10:241142 }
[email protected]5f8b1022011-01-21 23:34:501143
[email protected]479b0172012-10-29 19:27:091144 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:361145 !is_threaded_compositing_enabled_ &&
[email protected]479b0172012-10-29 19:27:091146 ForceCompositingModeEnabled()) {
1147 webwidget_->enterForceCompositingMode(true);
1148 }
1149
[email protected]872ae5b2011-05-26 20:20:501150 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:561151 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:041152 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:561153 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
1154 delay,
1155 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411156 base::TimeDelta::FromMilliseconds(120),
1157 60);
[email protected]d0be63772011-12-20 23:18:041158 } else {
[email protected]0fb93f52011-05-18 23:13:561159 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
1160 delay,
1161 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411162 base::TimeDelta::FromMilliseconds(120),
1163 60);
[email protected]d0be63772011-12-20 23:18:041164 }
[email protected]872ae5b2011-05-26 20:20:501165
1166 // Calculate filtered time per frame:
1167 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
1168 filtered_time_per_frame_ =
1169 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:561170 }
1171 last_do_deferred_update_time_ = frame_begin_ticks;
1172
[email protected]fef5e3972012-08-07 03:59:471173 if (!is_accelerated_compositing_active_) {
[email protected]62049562013-03-24 00:39:011174 software_stats_.animation_frame_count++;
1175 software_stats_.screen_frame_count++;
[email protected]fef5e3972012-08-07 03:59:471176 }
1177
[email protected]552e6002009-11-19 05:24:571178 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:291179 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:301180 PaintAggregator::PendingUpdate update;
1181 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:291182
[email protected]53d3f302009-12-21 04:42:051183 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:181184 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:291185
[email protected]29ed96a2012-02-04 18:12:161186 // Notify derived classes that we're about to initiate a paint.
1187 WillInitiatePaint();
1188
[email protected]ca4847f2010-09-24 05:39:151189 // A plugin may be able to do an optimized paint. First check this, in which
1190 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:461191 // This optimization allows PPAPI plugins that declare themselves on top of
1192 // the page (like a traditional windowed plugin) to be able to animate (think
1193 // movie playing) without repeatedly re-painting the page underneath, or
1194 // copying the plugin backing store (since we can send the plugin's backing
1195 // store directly to the browser).
1196 //
1197 // This optimization only works when the entire invalid region is contained
1198 // within the plugin. There is a related optimization in PaintRect for the
1199 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:151200 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:151201 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201202 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:211203 DCHECK(!pending_update_params_.get());
1204 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551205 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211206 pending_update_params_->scroll_rect = update.scroll_rect;
1207 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211208 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1209 pending_update_params_->flags = next_paint_flags_;
1210 pending_update_params_->scroll_offset = GetScrollOffset();
1211 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091212 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211213 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091214 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211215
[email protected]ca4847f2010-09-24 05:39:151216 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561217 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151218 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201219 &optimized_copy_rect,
1220 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271221 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471222 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211223 pending_update_params_->bitmap = dib->id();
1224 pending_update_params_->bitmap_rect = optimized_copy_location;
1225 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201226 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561227 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461228 // Compute a buffer for painting and cache it.
[email protected]4889bd212013-02-11 22:23:101229
1230 bool fractional_scale = device_scale_factor_ -
1231 static_cast<int>(device_scale_factor_) != 0;
1232 if (fractional_scale) {
1233 // Damage might not be DIP aligned. Inflate damage to compensate.
1234 bounds.Inset(-1, -1);
1235 bounds.Intersect(gfx::Rect(size_));
1236 }
1237
1238 gfx::Rect pixel_bounds = gfx::ToEnclosingRect(
[email protected]ce112fe2012-10-29 22:52:181239 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]4889bd212013-02-11 22:23:101240
[email protected]ca4847f2010-09-24 05:39:151241 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351242 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591243 pixel_bounds));
[email protected]59383c782013-04-17 16:43:271244 if (!canvas) {
[email protected]f98d7e3c2010-09-13 22:30:461245 NOTREACHED();
1246 return;
1247 }
[email protected]cef3362f2009-12-21 17:48:451248
[email protected]f98d7e3c2010-09-13 22:30:461249 // We may get back a smaller canvas than we asked for.
1250 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591251 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1252 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1253 pixel_bounds.set_width(canvas->getDevice()->width());
1254 pixel_bounds.set_height(canvas->getDevice()->height());
1255 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1256 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051257
[email protected]f98d7e3c2010-09-13 22:30:461258 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1259
[email protected]aa4117f2011-12-09 22:19:211260 pending_update_params_->bitmap = current_paint_buf_->id();
1261 pending_update_params_->bitmap_rect = bounds;
1262
1263 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461264 // The scroll damage is just another rectangle to paint and copy.
1265 copy_rects.swap(update.paint_rects);
1266 if (!scroll_damage.IsEmpty())
1267 copy_rects.push_back(scroll_damage);
1268
[email protected]4889bd212013-02-11 22:23:101269 for (size_t i = 0; i < copy_rects.size(); ++i) {
1270 gfx::Rect rect = copy_rects[i];
1271 if (fractional_scale) {
1272 // Damage might not be DPI aligned. Inflate rect to compensate.
1273 rect.Inset(-1, -1);
1274 }
1275 PaintRect(rect, pixel_bounds.origin(), canvas.get());
1276 }
[email protected]60a50072012-01-11 02:05:351277
1278 // Software FPS tick for performance tests. The accelerated path traces the
1279 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1280 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421281 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW",
1282 TRACE_EVENT_SCOPE_THREAD);
[email protected]f98d7e3c2010-09-13 22:30:461283 } else { // Accelerated compositing path
1284 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211285 // If painting is done via the gpu process then we don't set any damage
1286 // rects to save the browser process from doing unecessary work.
1287 pending_update_params_->bitmap_rect = bounds;
1288 pending_update_params_->scroll_rect = gfx::Rect();
1289 // We don't need an ack, because we're not sharing a DIB with the browser.
1290 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1291 // with the browser for the GPU surface.
1292 pending_update_params_->needs_ack = false;
[email protected]f0c2a242013-03-15 19:34:521293 Composite(frame_begin_ticks);
[email protected]f98d7e3c2010-09-13 22:30:461294 }
1295
[email protected]936c6f52011-12-13 01:35:261296 // If we're holding a pending input event ACK, send the ACK before sending the
1297 // UpdateReply message so we can receive another input event before the
1298 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1299 // the UpdateRect IPC message handler.
[email protected]59383c782013-04-17 16:43:271300 if (pending_input_event_ack_)
[email protected]936c6f52011-12-13 01:35:261301 Send(pending_input_event_ack_.release());
1302
[email protected]ab543072013-01-25 04:38:151303 // If Composite() called SwapBuffers, pending_update_params_ will be reset (in
[email protected]aa4117f2011-12-09 22:19:211304 // OnSwapBuffersPosted), meaning a message has been added to the
1305 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1306 // the message now.
[email protected]59383c782013-04-17 16:43:271307 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:211308 // sending an ack to browser process that the paint is complete...
1309 update_reply_pending_ = pending_update_params_->needs_ack;
1310 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1311 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341312 }
[email protected]53d3f302009-12-21 04:42:051313
[email protected]29ed96a2012-02-04 18:12:161314 // If we're software rendering then we're done initiating the paint.
1315 if (!is_accelerated_compositing_active_)
1316 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291317}
1318
[email protected]f0c2a242013-03-15 19:34:521319void RenderWidget::Composite(base::TimeTicks frame_begin_time) {
[email protected]ab543072013-01-25 04:38:151320 DCHECK(is_accelerated_compositing_active_);
[email protected]ba91a792013-02-06 09:48:281321 if (compositor_) // TODO(jamesr): Figure out how this can be null.
[email protected]f0c2a242013-03-15 19:34:521322 compositor_->Composite(frame_begin_time);
[email protected]ab543072013-01-25 04:38:151323}
1324
initial.commit09911bf2008-07-26 23:55:291325///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461326// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291327
[email protected]4873c7d2009-07-16 06:36:281328void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]479b0172012-10-29 19:27:091329 TRACE_EVENT2("renderer", "RenderWidget::didInvalidateRect",
1330 "width", rect.width, "height", rect.height);
[email protected]552e6002009-11-19 05:24:571331 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481332 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181333 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571334 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291335 return;
1336
[email protected]552e6002009-11-19 05:24:571337 paint_aggregator_.InvalidateRect(damaged_rect);
1338
1339 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241340 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571341 return;
1342 if (!paint_aggregator_.HasPendingUpdate())
1343 return;
[email protected]aa4117f2011-12-09 22:19:211344 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241345 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1346 return;
1347
1348 // When GPU rendering, combine pending animations and invalidations into
1349 // a single update.
[email protected]816edc62012-03-17 01:27:221350 if (is_accelerated_compositing_active_ &&
1351 animation_update_pending_ &&
1352 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571353 return;
1354
1355 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291356 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1357 // on the call stack.
1358 // 2) Allows us to collect more damage rects before painting to help coalesce
1359 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241360 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111361 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211362 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291363}
1364
[email protected]990278ff2012-11-13 02:12:551365void RenderWidget::didScrollRect(int dx, int dy,
1366 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461367 // Drop scrolls on the floor when we are in compositing mode.
1368 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561369 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461370 return;
1371
[email protected]552e6002009-11-19 05:24:571372 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481373 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181374 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571375 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291376 return;
1377
[email protected]990278ff2012-11-13 02:12:551378 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571379
1380 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241381 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571382 return;
1383 if (!paint_aggregator_.HasPendingUpdate())
1384 return;
[email protected]aa4117f2011-12-09 22:19:211385 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241386 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1387 return;
1388
1389 // When GPU rendering, combine pending animations and invalidations into
1390 // a single update.
[email protected]816edc62012-03-17 01:27:221391 if (is_accelerated_compositing_active_ &&
1392 animation_update_pending_ &&
1393 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571394 return;
1395
1396 // Perform updating asynchronously. This serves two purposes:
1397 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1398 // on the call stack.
1399 // 2) Allows us to collect more damage rects before painting to help coalesce
1400 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241401 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111402 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211403 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291404}
1405
[email protected]244ac1892011-12-02 17:04:471406void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091407 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451408 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581409
[email protected]eac2b362013-05-22 07:01:451410 // If we don't clear PaintAggregator after changing autoResize state, then
1411 // we might end up in a situation where bitmap_rect is larger than the
1412 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1413 // with invalid damage rects.
1414 paint_aggregator_.ClearPendingUpdate();
1415
1416 if (RenderThreadImpl::current()->short_circuit_size_updates()) {
1417 WebRect new_pos(rootWindowRect().x,
1418 rootWindowRect().y,
1419 new_size.width,
1420 new_size.height);
1421 view_screen_rect_ = new_pos;
1422 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031423 }
[email protected]20fbfc22013-05-08 20:50:581424
[email protected]eac2b362013-05-22 07:01:451425 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581426
1427 if (!RenderThreadImpl::current()->short_circuit_size_updates())
1428 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091429 }
[email protected]244ac1892011-12-02 17:04:471430}
1431
[email protected]3a1c8a8032013-03-18 22:35:321432void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051433 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1434 device_scale_factor_));
1435 if (compositor_)
1436 compositor_->setViewportSize(size_, physical_backing_size_);
1437}
1438
[email protected]91acd1c2012-03-14 08:32:391439void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221440 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1441
[email protected]c63b4d42012-04-26 01:01:071442#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211443 if (!is_accelerated_compositing_active_) {
1444 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1445 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1446 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1447 // going to switch to accelerated compositing, the GPU process may need
1448 // round-trips to the browser's UI thread before finishing the frame,
1449 // causing deadlocks if we delay the UpdateRect until we receive the
1450 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071451 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1452 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211453 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1454 }
[email protected]c63b4d42012-04-26 01:01:071455#endif
[email protected]aa4117f2011-12-09 22:19:211456
[email protected]ea162f92011-10-04 23:08:221457 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421458 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241459 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221460}
1461
1462void RenderWidget::didDeactivateCompositor() {
1463 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1464
1465 is_accelerated_compositing_active_ = false;
1466 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1467 routing_id_, is_accelerated_compositing_active_));
1468
[email protected]ea162f92011-10-04 23:08:221469 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241470 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091471
1472 // In single-threaded mode, we exit force compositing mode and re-enter in
1473 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1474 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1475 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361476 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091477 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561478}
1479
[email protected]e195e582013-03-08 01:32:591480void RenderWidget::initializeLayerTreeView() {
1481 compositor_ = RenderWidgetCompositor::Create(this);
1482 if (!compositor_)
1483 return;
1484
1485 compositor_->setViewportSize(size_, physical_backing_size_);
1486 if (init_complete_)
1487 compositor_->setSurfaceReady();
1488}
1489
[email protected]8926c602013-01-23 05:32:061490WebKit::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281491 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061492}
1493
[email protected]9ed83fe2013-02-27 01:52:281494void RenderWidget::suppressCompositorScheduling(bool enable) {
1495 if (compositor_)
1496 compositor_->SetSuppressScheduleComposite(enable);
1497}
1498
[email protected]9cd43a62012-03-26 08:03:561499void RenderWidget::willBeginCompositorFrame() {
1500 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371501
[email protected]ea5f70a2013-03-07 12:30:361502 DCHECK(RenderThreadImpl::current()->compositor_message_loop_proxy());
[email protected]abe8b3a2012-03-28 21:19:371503
1504 // The following two can result in further layout and possibly
1505 // enable GPU acceleration so they need to be called before any painting
1506 // is done.
[email protected]2d354272013-01-14 00:59:061507 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]abe8b3a2012-03-28 21:19:371508 UpdateSelectionBounds();
1509
[email protected]9cd43a62012-03-26 08:03:561510 WillInitiatePaint();
1511}
1512
[email protected]3391a0772012-03-28 00:32:071513void RenderWidget::didBecomeReadyForAdditionalInput() {
1514 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]59383c782013-04-17 16:43:271515 if (pending_input_event_ack_)
[email protected]3391a0772012-03-28 00:32:071516 Send(pending_input_event_ack_.release());
1517}
1518
[email protected]6fceb912013-02-15 06:24:151519void RenderWidget::DidCommitCompositorFrame() {
1520}
1521
[email protected]58264a32011-11-17 23:36:151522void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501523 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351524 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1525 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421526 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU",
1527 TRACE_EVENT_SCOPE_THREAD);
[email protected]29ed96a2012-02-04 18:12:161528 // Notify subclasses that we initiated the paint operation.
1529 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151530}
1531
1532void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181533 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1534
1535 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561536 DidFlushPaint();
1537
[email protected]aa4117f2011-12-09 22:19:211538 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151539 return;
1540
[email protected]ea3ee0a2012-05-15 03:43:091541 if (!next_paint_flags_ &&
1542 !need_update_rect_for_auto_resize_ &&
1543 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151544 return;
[email protected]ea3ee0a2012-05-15 03:43:091545 }
[email protected]58264a32011-11-17 23:36:151546
1547 ViewHostMsg_UpdateRect_Params params;
1548 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151549 params.plugin_window_moves.swap(plugin_window_moves_);
1550 params.flags = next_paint_flags_;
1551 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121552 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091553 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151554
1555 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1556 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091557 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151558}
1559
[email protected]f98d7e3c2010-09-13 22:30:461560void RenderWidget::scheduleComposite() {
[email protected]479b0172012-10-29 19:27:091561 TRACE_EVENT0("gpu", "RenderWidget::scheduleComposite");
[email protected]ea5f70a2013-03-07 12:30:361562 if (RenderThreadImpl::current()->compositor_message_loop_proxy() &&
[email protected]ba91a792013-02-06 09:48:281563 compositor_) {
1564 compositor_->setNeedsRedraw();
[email protected]d0be63772011-12-20 23:18:041565 } else {
[email protected]c3d45532011-10-07 19:20:401566 // TODO(nduca): replace with something a little less hacky. The reason this
1567 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1568 // contains a lot of host-renderer synchronization logic that is still
1569 // important for the accelerated compositing case. The option of simply
1570 // duplicating all that code is less desirable than "faking out" the
1571 // invalidation path using a magical damage rect.
1572 didInvalidateRect(WebRect(0, 0, 1, 1));
1573 }
[email protected]f98d7e3c2010-09-13 22:30:461574}
1575
[email protected]5f8b1022011-01-21 23:34:501576void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201577 if (animation_update_pending_)
1578 return;
1579
[email protected]921244e42011-07-20 16:36:301580 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201581 animation_update_pending_ = true;
1582 if (!animation_timer_.IsRunning()) {
1583 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1584 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211585 }
[email protected]5f8b1022011-01-21 23:34:501586}
1587
[email protected]4873c7d2009-07-16 06:36:281588void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301589 // TODO(darin): Eliminate this temporary.
1590 WebCursor cursor(cursor_info);
1591
initial.commit09911bf2008-07-26 23:55:291592 // Only send a SetCursor message if we need to make a change.
1593 if (!current_cursor_.IsEqual(cursor)) {
1594 current_cursor_ = cursor;
1595 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1596 }
1597}
1598
1599// We are supposed to get a single call to Show for a newly created RenderWidget
1600// that was created via RenderWidget::CreateWebView. So, we wait until this
1601// point to dispatch the ShowWidget message.
1602//
1603// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281604// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291605//
[email protected]4873c7d2009-07-16 06:36:281606void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291607 DCHECK(!did_show_) << "received extraneous Show call";
1608 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1609 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1610
[email protected]8de12d942010-11-17 20:42:441611 if (did_show_)
1612 return;
1613
1614 did_show_ = true;
1615 // NOTE: initial_pos_ may still have its default values at this point, but
1616 // that's okay. It'll be ignored if as_popup is false, or the browser
1617 // process will impose a default position otherwise.
1618 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1619 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291620}
1621
[email protected]9b003482013-05-21 14:00:171622void RenderWidget::didProgrammaticallyScroll(
1623 const WebKit::WebPoint& scroll_point) {
1624 if (!compositor_)
1625 return;
1626 Send(new ViewHostMsg_DidProgrammaticallyScroll(
1627 routing_id_, gfx::Vector2d(scroll_point.x, scroll_point.y)));
1628}
1629
[email protected]4873c7d2009-07-16 06:36:281630void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291631}
1632
[email protected]4873c7d2009-07-16 06:36:281633void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291634}
1635
[email protected]2533ce12009-05-09 00:02:241636void RenderWidget::DoDeferredClose() {
1637 Send(new ViewHostMsg_Close(routing_id_));
1638}
1639
[email protected]4873c7d2009-07-16 06:36:281640void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321641 if (is_swapped_out_) {
1642 // This widget is currently swapped out, and the active widget is in a
1643 // different process. Have the browser route the close request to the
1644 // active widget instead, so that the correct unload handlers are run.
1645 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1646 return;
1647 }
1648
initial.commit09911bf2008-07-26 23:55:291649 // If a page calls window.close() twice, we'll end up here twice, but that's
1650 // OK. It is safe to send multiple Close messages.
1651
[email protected]2533ce12009-05-09 00:02:241652 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1653 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1654 // could be closed before the JS finishes executing. So instead, post a
1655 // message back to the message loop, which won't run until the JS is
1656 // complete, and then the Close message can be sent.
[email protected]dd32b1272013-05-04 14:17:111657 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211658 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291659}
1660
1661void RenderWidget::Close() {
1662 if (webwidget_) {
[email protected]8926c602013-01-23 05:32:061663 webwidget_->willCloseLayerTreeView();
[email protected]ba91a792013-02-06 09:48:281664 compositor_.reset();
[email protected]4873c7d2009-07-16 06:36:281665 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291666 webwidget_ = NULL;
1667 }
1668}
1669
[email protected]4873c7d2009-07-16 06:36:281670WebRect RenderWidget::windowRect() {
1671 if (pending_window_rect_count_)
1672 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241673
[email protected]80ad8622012-11-07 16:33:031674 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291675}
1676
[email protected]8a9d6ca32011-06-06 20:11:301677void RenderWidget::setToolTipText(const WebKit::WebString& text,
1678 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541679 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301680}
1681
[email protected]4873c7d2009-07-16 06:36:281682void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291683 if (did_show_) {
[email protected]8be1c582013-03-06 00:55:031684 if (!RenderThreadImpl::current()->short_circuit_size_updates()) {
1685 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1686 SetPendingWindowRect(pos);
1687 } else {
1688 WebSize new_size(pos.width, pos.height);
[email protected]d9083762013-03-24 01:36:401689 Resize(new_size, new_size, overdraw_bottom_height_,
1690 WebRect(), is_fullscreen_, NO_RESIZE_ACK);
[email protected]8be1c582013-03-06 00:55:031691 view_screen_rect_ = pos;
1692 window_screen_rect_ = pos;
1693 }
initial.commit09911bf2008-07-26 23:55:291694 } else {
1695 initial_pos_ = pos;
1696 }
1697}
1698
[email protected]2533ce12009-05-09 00:02:241699void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1700 pending_window_rect_ = rect;
1701 pending_window_rect_count_++;
1702}
1703
[email protected]4873c7d2009-07-16 06:36:281704WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241705 if (pending_window_rect_count_) {
1706 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1707 // the RootWindowRect is probably going to return wrong results since the
1708 // browser may not have processed the Move yet. There isn't really anything
1709 // good to do in this case, and it shouldn't happen - since this size is
1710 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281711 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241712 }
1713
[email protected]80ad8622012-11-07 16:33:031714 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371715}
1716
[email protected]4873c7d2009-07-16 06:36:281717WebRect RenderWidget::windowResizerRect() {
1718 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191719}
1720
[email protected]fa7b1dc2010-06-23 17:53:041721void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031722 // To prevent this renderer process from sending unnecessary IPC messages to
1723 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041724 // only during the input method attached to the browser process is active.
1725 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291726}
1727
[email protected]58b48a0d2012-06-13 07:01:351728void RenderWidget::UpdateCompositionInfo(
1729 const ui::Range& range,
1730 const std::vector<gfx::Rect>& character_bounds) {
1731 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1732 return;
1733 composition_character_bounds_ = character_bounds;
1734 composition_range_ = range;
1735 Send(new ViewHostMsg_ImeCompositionRangeChanged(
1736 routing_id(), composition_range_, composition_character_bounds_));
1737}
1738
[email protected]fa7b1dc2010-06-23 17:53:041739void RenderWidget::OnImeSetComposition(
1740 const string16& text,
1741 const std::vector<WebCompositionUnderline>& underlines,
1742 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281743 if (!webwidget_)
1744 return;
[email protected]66fca5bc2013-05-23 06:58:291745 ImeEventGuard guard(this);
[email protected]d4cff272011-05-02 15:46:011746 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041747 text, WebVector<WebCompositionUnderline>(underlines),
1748 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011749 // Setting the IME composition was successful. Send the new composition
1750 // range to the browser.
1751 ui::Range range(ui::Range::InvalidRange());
1752 size_t location, length;
1753 if (webwidget_->compositionRange(&location, &length)) {
1754 range.set_start(location);
1755 range.set_end(location + length);
1756 }
1757 // The IME was cancelled via the Esc key, so just send back the caret.
1758 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1759 range.set_start(location);
1760 range.set_end(location + length);
1761 }
[email protected]58b48a0d2012-06-13 07:01:351762 std::vector<gfx::Rect> character_bounds;
1763 GetCompositionCharacterBounds(&character_bounds);
1764 UpdateCompositionInfo(range, character_bounds);
[email protected]d4cff272011-05-02 15:46:011765 } else {
[email protected]fa7b1dc2010-06-23 17:53:041766 // If we failed to set the composition text, then we need to let the browser
1767 // process to cancel the input method's ongoing composition session, to make
1768 // sure we are in a consistent state.
1769 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011770
1771 // Send an updated IME range with just the caret range.
1772 ui::Range range(ui::Range::InvalidRange());
1773 size_t location, length;
1774 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1775 range.set_start(location);
1776 range.set_end(location + length);
1777 }
[email protected]58b48a0d2012-06-13 07:01:351778 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]7f00efa2010-04-15 05:01:261779 }
[email protected]fa7b1dc2010-06-23 17:53:041780}
1781
[email protected]4de6d1692011-10-12 08:45:441782void RenderWidget::OnImeConfirmComposition(
1783 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041784 if (!webwidget_)
1785 return;
[email protected]66fca5bc2013-05-23 06:58:291786 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041787 handling_input_event_ = true;
1788 webwidget_->confirmComposition(text);
1789 handling_input_event_ = false;
1790
[email protected]d4cff272011-05-02 15:46:011791 // Send an updated IME range with just the caret range.
1792 ui::Range range(ui::Range::InvalidRange());
1793 size_t location, length;
1794 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1795 range.set_start(location);
1796 range.set_end(location + length);
1797 }
[email protected]58b48a0d2012-06-13 07:01:351798 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
initial.commit09911bf2008-07-26 23:55:291799}
1800
[email protected]948f7ab72010-05-28 23:48:081801// This message causes the renderer to render an image of the
1802// desired_size, regardless of whether the tab is hidden or not.
[email protected]3d9ec5052013-01-02 22:05:251803void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle,
1804 int tag,
1805 const gfx::Size& page_size,
1806 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001807 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1808 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251809 // Close our unused handle.
1810#if defined(OS_WIN)
1811 ::CloseHandle(dib_handle);
1812#elif defined(OS_MACOSX)
1813 base::SharedMemory::CloseHandle(dib_handle);
1814#endif
1815 }
[email protected]d65adb12010-04-28 17:26:491816 return;
[email protected]45c6aad32010-11-11 04:46:251817 }
[email protected]d65adb12010-04-28 17:26:491818
[email protected]948f7ab72010-05-28 23:48:081819 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491820 // If one of these is empty, then we just return the dib we were
1821 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091822 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491823 return;
1824 }
1825
1826 // Map the given DIB ID into this process, and unmap it at the end
1827 // of this function.
[email protected]45c6aad32010-11-11 04:46:251828 scoped_ptr<TransportDIB> paint_at_size_buffer(
1829 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301830
[email protected]4b01b962012-10-09 23:17:351831 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281832 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:351833 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281834 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:511835 gfx::Size canvas_size = page_size_in_pixel;
1836 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:491837 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:511838 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:491839 static_cast<float>(canvas_size.height());
1840
[email protected]ee8d6fd2010-05-26 17:05:481841 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491842 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1843 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481844 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491845
[email protected]36808ad2010-10-20 19:18:301846 scoped_ptr<skia::PlatformCanvas> canvas(
1847 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1848 canvas_size.height()));
[email protected]59383c782013-04-17 16:43:271849 if (!canvas) {
[email protected]36808ad2010-10-20 19:18:301850 NOTREACHED();
1851 return;
1852 }
1853
[email protected]d65adb12010-04-28 17:26:491854 // Reset bounds to what we actually received, but they should be the
1855 // same.
1856 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1857 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1858 bounds.set_width(canvas->getDevice()->width());
1859 bounds.set_height(canvas->getDevice()->height());
1860
1861 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081862 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491863 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1864
[email protected]948f7ab72010-05-28 23:48:081865 // Have to make sure we're laid out at the right size before
1866 // rendering.
1867 gfx::Size old_size = webwidget_->size();
1868 webwidget_->resize(page_size);
1869 webwidget_->layout();
1870
[email protected]d65adb12010-04-28 17:26:491871 // Paint the entire thing (using original bounds, not scaled bounds).
1872 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1873 canvas->restore();
1874
[email protected]948f7ab72010-05-28 23:48:081875 // Return the widget to its previous size.
1876 webwidget_->resize(old_size);
1877
[email protected]c88c9442010-07-19 18:55:091878 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491879}
1880
[email protected]51a49502013-03-23 01:50:191881void RenderWidget::OnSnapshot(const gfx::Rect& src_subrect) {
1882 SkBitmap snapshot;
1883
1884 if (OnSnapshotHelper(src_subrect, &snapshot)) {
1885 Send(new ViewHostMsg_Snapshot(routing_id(), true, snapshot));
1886 } else {
1887 Send(new ViewHostMsg_Snapshot(routing_id(), false, SkBitmap()));
1888 }
1889}
1890
1891bool RenderWidget::OnSnapshotHelper(const gfx::Rect& src_subrect,
1892 SkBitmap* snapshot) {
1893 base::TimeTicks beginning_time = base::TimeTicks::Now();
1894
1895 if (!webwidget_ || src_subrect.IsEmpty())
1896 return false;
1897
1898 gfx::Rect viewport_size = gfx::IntersectRects(
1899 src_subrect, gfx::Rect(physical_backing_size_));
1900
1901 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(
1902 skia::CreatePlatformCanvas(viewport_size.width(),
1903 viewport_size.height(),
1904 true,
1905 NULL,
1906 skia::RETURN_NULL_ON_FAILURE));
[email protected]59383c782013-04-17 16:43:271907 if (!canvas)
[email protected]51a49502013-03-23 01:50:191908 return false;
1909
1910 canvas->save();
1911 webwidget_->layout();
1912
1913 PaintRect(viewport_size, viewport_size.origin(), canvas.get());
1914 canvas->restore();
1915
1916 const SkBitmap& bitmap = skia::GetTopDevice(*canvas)->accessBitmap(false);
1917 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1918 return false;
1919
1920 UMA_HISTOGRAM_TIMES("Renderer4.Snapshot",
1921 base::TimeTicks::Now() - beginning_time);
1922 return true;
1923}
1924
[email protected]0bc1f572013-04-17 01:46:311925void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121926 // During shutdown we can just ignore this message.
1927 if (!webwidget_)
1928 return;
1929
[email protected]0bc1f572013-04-17 01:46:311930 // Even if the browser provides an empty damage rect, it's still expecting to
1931 // receive a repaint ack so just damage the entire widget bounds.
1932 if (size_to_paint.IsEmpty()) {
1933 size_to_paint = size_;
1934 }
1935
[email protected]ec7dc112008-08-06 05:30:121936 set_next_paint_is_repaint_ack();
[email protected]0bc1f572013-04-17 01:46:311937 if (is_accelerated_compositing_active_ && compositor_) {
1938 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]f98d7e3c2010-09-13 22:30:461939 } else {
1940 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1941 didInvalidateRect(repaint_rect);
1942 }
[email protected]ec7dc112008-08-06 05:30:121943}
1944
[email protected]4a9dba42013-04-29 18:24:221945void RenderWidget::OnSmoothScrollCompleted() {
1946 pending_smooth_scroll_gesture_.Run();
[email protected]0e241b4b2012-08-18 09:06:271947}
1948
[email protected]4873c7d2009-07-16 06:36:281949void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111950 if (!webwidget_)
1951 return;
[email protected]4873c7d2009-07-16 06:36:281952 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111953}
1954
[email protected]6131a642012-06-15 23:26:531955void RenderWidget::OnScreenInfoChanged(
1956 const WebKit::WebScreenInfo& screen_info) {
1957 screen_info_ = screen_info;
[email protected]468ac582012-11-20 00:53:191958 SetDeviceScaleFactor(screen_info.deviceScaleFactor);
[email protected]6131a642012-06-15 23:26:531959}
1960
[email protected]80ad8622012-11-07 16:33:031961void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1962 const gfx::Rect& window_screen_rect) {
1963 view_screen_rect_ = view_screen_rect;
1964 window_screen_rect_ = window_screen_rect;
1965 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1966}
1967
[email protected]105dffb42013-02-20 03:46:211968#if defined(OS_ANDROID)
1969void RenderWidget::OnImeBatchStateChanged(bool is_begin) {
1970 Send(new ViewHostMsg_ImeBatchStateChanged_ACK(routing_id(), is_begin));
1971}
[email protected]2384b6c2013-02-28 23:58:511972
1973void RenderWidget::OnShowImeIfNeeded() {
1974 UpdateTextInputState(SHOW_IME_IF_NEEDED);
1975}
[email protected]105dffb42013-02-20 03:46:211976#endif
1977
[email protected]468ac582012-11-20 00:53:191978void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1979 if (device_scale_factor_ == device_scale_factor)
1980 return;
1981
1982 device_scale_factor_ = device_scale_factor;
1983
1984 if (!is_accelerated_compositing_active_) {
1985 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
1986 } else {
1987 scheduleComposite();
1988 }
1989}
1990
[email protected]719b36f2010-12-22 20:36:461991webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151992 const gfx::Rect& paint_bounds,
1993 TransportDIB** dib,
1994 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:201995 gfx::Rect* clip,
1996 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:461997 // Bare RenderWidgets don't support optimized plugin painting.
1998 return NULL;
[email protected]ca4847f2010-09-24 05:39:151999}
2000
[email protected]ceb36f7d2012-10-31 18:33:242001gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:522002 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:242003 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:522004}
2005
[email protected]bee16aab2009-08-26 15:55:032006void RenderWidget::SetHidden(bool hidden) {
2007 if (is_hidden_ == hidden)
2008 return;
2009
2010 // The status has changed. Tell the RenderThread about it.
2011 is_hidden_ = hidden;
2012 if (is_hidden_)
[email protected]380244092011-10-07 17:26:272013 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:032014 else
[email protected]380244092011-10-07 17:26:272015 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:032016}
2017
[email protected]2b624c562011-10-27 22:58:262018void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262019 if (!webwidget_)
2020 return;
2021
2022 if (is_fullscreen_) {
2023 webwidget_->willExitFullScreen();
2024 } else {
2025 webwidget_->willEnterFullScreen();
2026 }
[email protected]2b624c562011-10-27 22:58:262027}
2028
2029void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262030 if (!webwidget_)
2031 return;
2032
2033 if (is_fullscreen_) {
2034 webwidget_->didEnterFullScreen();
2035 } else {
2036 webwidget_->didExitFullScreen();
2037 }
[email protected]2b624c562011-10-27 22:58:262038}
2039
[email protected]699ab0d2009-04-23 23:19:142040void RenderWidget::SetBackground(const SkBitmap& background) {
2041 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:462042
[email protected]699ab0d2009-04-23 23:19:142043 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:282044 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:142045}
2046
[email protected]674741932009-02-04 23:44:462047bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:052048 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462049}
2050
2051bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:052052 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462053}
2054
2055void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:052056 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462057}
2058
2059void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:052060 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:462061}
2062
2063void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:052064 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462065}
2066
[email protected]b18583c2012-12-18 06:55:272067static bool IsDateTimeInput(ui::TextInputType type) {
2068 return type == ui::TEXT_INPUT_TYPE_DATE ||
2069 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
2070 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
2071 type == ui::TEXT_INPUT_TYPE_MONTH ||
2072 type == ui::TEXT_INPUT_TYPE_TIME ||
2073 type == ui::TEXT_INPUT_TYPE_WEEK;
2074}
2075
[email protected]66fca5bc2013-05-23 06:58:292076
2077void RenderWidget::StartHandlingImeEvent() {
2078 DCHECK(!handling_ime_event_);
2079 handling_ime_event_ = true;
2080}
2081
2082void RenderWidget::FinishHandlingImeEvent() {
2083 DCHECK(handling_ime_event_);
2084 handling_ime_event_ = false;
2085 // While handling an ime event, text input state and selection bounds updates
2086 // are ignored. These must explicitly be updated once finished handling the
2087 // ime event.
2088 UpdateSelectionBounds();
2089 UpdateTextInputState(DO_NOT_SHOW_IME);
2090}
2091
[email protected]3306f262012-09-21 19:20:422092void RenderWidget::UpdateTextInputState(ShowIme show_ime) {
[email protected]e8f775f2013-02-14 21:00:502093 if (handling_ime_event_)
2094 return;
[email protected]3306f262012-09-21 19:20:422095 bool show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
2096 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:292097 return;
[email protected]ad26ef42011-06-17 07:59:452098 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:272099 if (IsDateTimeInput(new_type))
2100 return; // Not considered as a text input field in WebKit/Chromium.
2101
[email protected]5b739cb2012-08-21 20:35:212102 WebKit::WebTextInputInfo new_info;
2103 if (webwidget_)
2104 new_info = webwidget_->textInputInfo();
2105
[email protected]ad26ef42011-06-17 07:59:452106 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:212107
[email protected]3306f262012-09-21 19:20:422108 // Only sends text input params if they are changed or if the ime should be
2109 // shown.
2110 if (show_ime_if_needed || (text_input_type_ != new_type
2111 || text_input_info_ != new_info
2112 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:212113 ViewHostMsg_TextInputState_Params p;
2114 p.type = new_type;
2115 p.value = new_info.value.utf8();
2116 p.selection_start = new_info.selectionStart;
2117 p.selection_end = new_info.selectionEnd;
2118 p.composition_start = new_info.compositionStart;
2119 p.composition_end = new_info.compositionEnd;
2120 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:422121 p.show_ime_if_needed = show_ime_if_needed;
[email protected]5b739cb2012-08-21 20:35:212122 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
2123
2124 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:042125 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:452126 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:292127 }
initial.commit09911bf2008-07-26 23:55:292128}
2129
[email protected]7c8873e2013-02-05 08:03:012130void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2131 WebRect focus_webrect;
2132 WebRect anchor_webrect;
2133 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
2134 *focus = focus_webrect;
2135 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322136}
2137
[email protected]e99ef6f2011-10-16 01:13:002138void RenderWidget::UpdateSelectionBounds() {
2139 if (!webwidget_)
2140 return;
[email protected]66fca5bc2013-05-23 06:58:292141 if (handling_ime_event_)
2142 return;
[email protected]e99ef6f2011-10-16 01:13:002143
[email protected]7c8873e2013-02-05 08:03:012144 ViewHostMsg_SelectionBounds_Params params;
2145 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2146 if (selection_anchor_rect_ != params.anchor_rect ||
2147 selection_focus_rect_ != params.focus_rect) {
2148 selection_anchor_rect_ = params.anchor_rect;
2149 selection_focus_rect_ = params.focus_rect;
2150 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
[email protected]129b7382013-02-12 02:14:292151 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
[email protected]7c8873e2013-02-05 08:03:012152 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
[email protected]58b48a0d2012-06-13 07:01:352153 }
[email protected]e99ef6f2011-10-16 01:13:002154
[email protected]58b48a0d2012-06-13 07:01:352155 std::vector<gfx::Rect> character_bounds;
2156 GetCompositionCharacterBounds(&character_bounds);
2157 UpdateCompositionInfo(composition_range_, character_bounds);
2158}
2159
2160bool RenderWidget::ShouldUpdateCompositionInfo(
2161 const ui::Range& range,
2162 const std::vector<gfx::Rect>& bounds) {
2163 if (composition_range_ != range)
2164 return true;
2165 if (bounds.size() != composition_character_bounds_.size())
2166 return true;
2167 for (size_t i = 0; i < bounds.size(); ++i) {
2168 if (bounds[i] != composition_character_bounds_[i])
2169 return true;
2170 }
2171 return false;
[email protected]e99ef6f2011-10-16 01:13:002172}
2173
[email protected]73bf95812011-10-12 11:38:322174// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:452175COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
2176 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
2177COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
2178 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
2179COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
2180 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:182181COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
2182 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
2183COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
2184 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
2185COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
2186 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
2187COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
2188 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
2189COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
2190 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:002191COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
2192 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
2193COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
2194 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
2195COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
2196 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
2197COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
2198 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
2199COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
2200 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
2201COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
2202 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:012203COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
2204 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
2205COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
2206 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]8b4992e2013-03-01 15:42:152207COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeField) == \
2208 int(ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:452209
[email protected]5b739cb2012-08-21 20:35:212210ui::TextInputType RenderWidget::WebKitToUiTextInputType(
2211 WebKit::WebTextInputType type) {
2212 // Check the type is in the range representable by ui::TextInputType.
2213 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
2214 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
2215 return static_cast<ui::TextInputType>(type);
2216}
2217
[email protected]ad26ef42011-06-17 07:59:452218ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272219 if (webwidget_)
2220 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452221 return ui::TEXT_INPUT_TYPE_NONE;
2222}
2223
[email protected]58b48a0d2012-06-13 07:01:352224void RenderWidget::GetCompositionCharacterBounds(
2225 std::vector<gfx::Rect>* bounds) {
2226 DCHECK(bounds);
2227 bounds->clear();
2228}
2229
[email protected]ad26ef42011-06-17 07:59:452230bool RenderWidget::CanComposeInline() {
2231 return true;
[email protected]56ea1a62011-05-30 07:05:572232}
2233
[email protected]4873c7d2009-07-16 06:36:282234WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042235 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282236}
2237
[email protected]f660d9c2012-06-06 18:31:212238float RenderWidget::deviceScaleFactor() {
2239 return device_scale_factor_;
2240}
2241
[email protected]fa7b1dc2010-06-23 17:53:042242void RenderWidget::resetInputMethod() {
2243 if (!input_method_is_active_)
2244 return;
2245
2246 // If the last text input type is not None, then we should finish any
2247 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452248 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042249 // If a composition text exists, then we need to let the browser process
2250 // to cancel the input method's ongoing composition session.
2251 if (webwidget_->confirmComposition())
2252 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
2253 }
[email protected]d4cff272011-05-02 15:46:012254
2255 // Send an updated IME range with the current caret rect.
2256 ui::Range range(ui::Range::InvalidRange());
2257 size_t location, length;
2258 if (webwidget_->caretOrSelectionRange(&location, &length)) {
2259 range.set_start(location);
2260 range.set_end(location + length);
2261 }
[email protected]58b48a0d2012-06-13 07:01:352262
2263 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]fa7b1dc2010-06-23 17:53:042264}
2265
[email protected]c68c3e4e2013-01-24 00:36:562266void RenderWidget::didHandleGestureEvent(
2267 const WebGestureEvent& event,
2268 bool event_cancelled) {
2269#if defined(OS_ANDROID)
2270 if (event_cancelled)
2271 return;
2272 if (event.type == WebInputEvent::GestureTap ||
2273 event.type == WebInputEvent::GestureLongPress) {
2274 UpdateTextInputState(SHOW_IME_IF_NEEDED);
2275 }
2276#endif
2277}
2278
[email protected]f103ab72009-09-02 17:10:592279void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:502280 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292281 size_t i = 0;
2282 for (; i < plugin_window_moves_.size(); ++i) {
2283 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582284 if (move.rects_valid) {
2285 plugin_window_moves_[i] = move;
2286 } else {
2287 plugin_window_moves_[i].visible = move.visible;
2288 }
initial.commit09911bf2008-07-26 23:55:292289 break;
2290 }
2291 }
2292
2293 if (i == plugin_window_moves_.size())
2294 plugin_window_moves_.push_back(move);
2295}
[email protected]268654772009-08-06 23:02:042296
2297void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2298 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2299 i != plugin_window_moves_.end(); ++i) {
2300 if (i->window == window) {
2301 plugin_window_moves_.erase(i);
2302 break;
2303 }
2304 }
2305}
[email protected]67bfb83f2011-09-22 03:36:372306
[email protected]b63d58d2012-11-26 22:37:442307void RenderWidget::GetRenderingStats(
2308 WebKit::WebRenderingStatsImpl& stats) const {
[email protected]ba91a792013-02-06 09:48:282309 if (compositor_)
[email protected]635353c2013-03-06 09:11:202310 compositor_->GetRenderingStats(&stats.rendering_stats);
[email protected]b63d58d2012-11-26 22:37:442311
[email protected]62049562013-03-24 00:39:012312 stats.rendering_stats.animation_frame_count +=
2313 software_stats_.animation_frame_count;
2314 stats.rendering_stats.screen_frame_count +=
2315 software_stats_.screen_frame_count;
2316 stats.rendering_stats.total_paint_time +=
2317 software_stats_.total_paint_time;
2318 stats.rendering_stats.total_pixels_painted +=
2319 software_stats_.total_pixels_painted;
[email protected]fef5e3972012-08-07 03:59:472320}
2321
[email protected]e9ff79c2012-10-19 21:31:262322bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:522323 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
2324 if (!gpu_channel)
2325 return false;
2326
2327 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
2328}
2329
[email protected]24ed0432013-04-24 07:50:312330RenderWidgetCompositor* RenderWidget::compositor() const {
2331 return compositor_.get();
2332}
2333
[email protected]0c2ebef2013-04-03 12:14:102334void RenderWidget::BeginSmoothScroll(
[email protected]0e241b4b2012-08-18 09:06:272335 bool down,
[email protected]ebd8b562012-10-09 14:44:292336 const SmoothScrollCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:192337 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:292338 int mouse_event_x,
2339 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:272340 DCHECK(!callback.is_null());
[email protected]267909d2012-10-20 04:36:192341
2342 ViewHostMsg_BeginSmoothScroll_Params params;
2343 params.scroll_down = down;
2344 params.pixels_to_scroll = pixels_to_scroll;
2345 params.mouse_event_x = mouse_event_x;
2346 params.mouse_event_y = mouse_event_y;
2347
[email protected]4a9dba42013-04-29 18:24:222348 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, params));
2349 pending_smooth_scroll_gesture_ = callback;
[email protected]a39ca1652012-07-13 21:30:582350}
2351
[email protected]a2b5ded2013-05-20 21:32:532352void RenderWidget::DidOverscroll(gfx::Vector2dF accumulated_overscroll,
2353 gfx::Vector2dF current_fling_velocity) {
2354 if (overscroll_notifications_enabled_) {
2355 Send(new ViewHostMsg_DidOverscroll(routing_id_,
2356 accumulated_overscroll,
2357 current_fling_velocity));
2358 }
2359}
2360
[email protected]67bfb83f2011-09-22 03:36:372361bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
2362 return false;
2363}
[email protected]c3d45532011-10-07 19:20:402364
[email protected]41d86852012-11-07 12:23:242365bool RenderWidget::WillHandleGestureEvent(
2366 const WebKit::WebGestureEvent& event) {
2367 return false;
2368}
2369
[email protected]ce6689f2013-03-29 12:52:552370void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2371 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2372}
2373
[email protected]3d5c243b2012-11-30 00:26:012374bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2375 return true;
2376}
2377
[email protected]3ae68c52013-04-12 06:10:052378WebGraphicsContext3DCommandBufferImpl* RenderWidget::CreateGraphicsContext3D(
[email protected]92fd8c02013-03-29 08:54:152379 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
[email protected]ed7defa2013-03-12 21:29:592380 if (!webwidget_)
2381 return NULL;
[email protected]8f746982013-03-21 06:28:032382 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
2383 new WebGraphicsContext3DCommandBufferImpl(
2384 surface_id(),
2385 GetURLForGraphicsContext3D(),
2386 RenderThreadImpl::current(),
2387 weak_ptr_factory_.GetWeakPtr()));
[email protected]ed7defa2013-03-12 21:29:592388
[email protected]8f746982013-03-21 06:28:032389 if (!context->Initialize(
2390 attributes,
2391 false /* bind generates resources */,
2392 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
2393 return NULL;
2394 return context.release();
[email protected]ed7defa2013-03-12 21:29:592395}
2396
[email protected]e9ff79c2012-10-19 21:31:262397} // namespace content