blob: fd84bb6482e5c3ef0e59fd77eeeea5b1eff172cb [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]32876ae2011-11-15 22:25:217#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:008#include "base/command_line.h"
[email protected]366ae242011-05-10 02:23:589#include "base/debug/trace_event.h"
initial.commit09911bf2008-07-26 23:55:2910#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/scoped_ptr.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2114#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0015#include "base/strings/utf_string_conversions.h"
[email protected]661eb9d2009-02-03 02:11:4816#include "build/build_config.h"
[email protected]681ccff2013-03-18 06:13:5217#include "cc/base/switches.h"
[email protected]7f0d825f2013-03-18 07:24:3018#include "cc/output/output_surface.h"
[email protected]556fd292013-03-18 08:03:0419#include "cc/trees/layer_tree_host.h"
[email protected]ed7defa2013-03-12 21:29:5920#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]c084330e02013-04-27 01:08:1521#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1522#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5023#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2924#include "content/public/common/content_switches.h"
[email protected]ed7defa2013-03-12 21:29:5925#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]2847b222013-04-06 00:59:2426#include "content/renderer/gpu/compositor_software_output_device.h"
[email protected]36e5ff12013-06-11 12:19:2927#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]ea5f70a2013-03-07 12:30:3628#include "content/renderer/gpu/input_handler_manager.h"
[email protected]ed7defa2013-03-12 21:29:5929#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]ba91a792013-02-06 09:48:2830#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2931#include "content/renderer/ime_event_guard.h"
[email protected]8704f89b2011-04-15 00:30:0532#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4433#include "content/renderer/render_thread_impl.h"
[email protected]8d6cba42011-09-02 10:05:1934#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]484955942010-08-19 16:13:1835#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4836#include "skia/ext/platform_canvas.h"
[email protected]8bd0fe62011-01-17 06:44:3737#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
[email protected]4b1146bc2012-07-10 18:46:0338#include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h"
[email protected]a7547fb2012-03-08 04:43:4439#include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h"
[email protected]8bd0fe62011-01-17 06:44:3740#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
41#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
[email protected]d4cff272011-05-02 15:46:0142#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:3743#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
[email protected]152fd7f72013-06-15 17:18:4144#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
45#include "third_party/WebKit/public/platform/WebPoint.h"
46#include "third_party/WebKit/public/platform/WebRect.h"
47#include "third_party/WebKit/public/platform/WebSize.h"
48#include "third_party/WebKit/public/platform/WebString.h"
[email protected]d353541f2012-05-03 22:45:4149#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1350#include "ui/base/ui_base_switches.h"
[email protected]9b003482013-05-21 14:00:1751#include "ui/gfx/point.h"
[email protected]a25e25b2012-09-28 14:32:3752#include "ui/gfx/rect_conversions.h"
[email protected]4b01b962012-10-09 23:17:3553#include "ui/gfx/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4854#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2755#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4156#include "ui/surface/transport_dib.h"
[email protected]8c89e7792009-08-19 21:18:3457#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5058#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4659#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
[email protected]799fd732013-05-15 21:18:5260#include "webkit/renderer/compositor_bindings/web_rendering_stats_impl.h"
[email protected]152fd7f72013-06-15 17:18:4161#include "webkit/renderer/cursor_utils.h"
[email protected]661eb9d2009-02-03 02:11:4862
[email protected]eeb93112013-05-01 19:41:1063#if defined(OS_ANDROID)
[email protected]913d99a2013-05-31 07:16:0764#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]eeb93112013-05-01 19:41:1065#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]ed7defa2013-03-12 21:29:59180 is_threaded_compositing_enabled_(false),
[email protected]69e797f2013-04-30 01:10:22181 weak_ptr_factory_(this) {
[email protected]8b3f0eb2012-05-03 19:15:05182 if (!swapped_out)
183 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27184 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18185 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
186 switches::kDisableGpuVsync);
[email protected]cb6430932012-10-31 00:53:36187 is_threaded_compositing_enabled_ =
188 CommandLine::ForCurrentProcess()->HasSwitch(
189 switches::kEnableThreadedCompositing);
initial.commit09911bf2008-07-26 23:55:29190}
191
192RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11193 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21194 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35195 if (current_paint_buf_) {
196 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
197 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29198 }
[email protected]992db4c2011-05-12 15:37:15199 // If we are swapped out, we have released already.
200 if (!is_swapped_out_)
201 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29202}
203
[email protected]484955942010-08-19 16:13:18204// static
[email protected]8085dbc82008-09-26 22:53:44205RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:04206 WebKit::WebPopupType popup_type,
207 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29208 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41209 scoped_refptr<RenderWidget> widget(
[email protected]842f10652012-06-06 01:54:04210 new RenderWidget(popup_type, screen_info, false));
[email protected]a635f942012-12-07 10:34:29211 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46212 return widget.get();
[email protected]a635f942012-12-07 10:34:29213 }
214 return NULL;
initial.commit09911bf2008-07-26 23:55:29215}
216
[email protected]484955942010-08-19 16:13:18217// static
218WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
219 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03220 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18221 break;
222 case WebKit::WebPopupTypeSelect:
223 case WebKit::WebPopupTypeSuggestion:
224 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44225 case WebKit::WebPopupTypePage:
226 return WebPagePopup::create(render_widget);
[email protected]4b1146bc2012-07-10 18:46:03227 case WebKit::WebPopupTypeHelperPlugin:
228 return WebKit::WebHelperPlugin::create(render_widget);
[email protected]484955942010-08-19 16:13:18229 default:
230 NOTREACHED();
231 }
232 return NULL;
233}
234
[email protected]a635f942012-12-07 10:34:29235bool RenderWidget::Init(int32 opener_id) {
236 return DoInit(opener_id,
237 RenderWidget::CreateWebWidget(this),
238 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
239 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18240}
241
[email protected]a635f942012-12-07 10:34:29242bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06243 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18244 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29245 DCHECK(!webwidget_);
246
247 if (opener_id != MSG_ROUTING_NONE)
248 opener_id_ = opener_id;
249
[email protected]484955942010-08-19 16:13:18250 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29251
[email protected]380244092011-10-07 17:26:27252 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29253 if (result) {
[email protected]380244092011-10-07 17:26:27254 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29255 // Take a reference on behalf of the RenderThread. This will be balanced
256 // when we receive ViewMsg_Close.
257 AddRef();
[email protected]a635f942012-12-07 10:34:29258 return true;
initial.commit09911bf2008-07-26 23:55:29259 } else {
[email protected]a635f942012-12-07 10:34:29260 // The above Send can fail when the tab is closing.
261 return false;
initial.commit09911bf2008-07-26 23:55:29262 }
263}
264
[email protected]fc4404d2012-11-07 19:53:30265// This is used to complete pending inits and non-pending inits.
266void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29267 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29268
[email protected]fc4404d2012-11-07 19:53:30269 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42270
[email protected]8926c602013-01-23 05:32:06271 if (webwidget_ && is_threaded_compositing_enabled_) {
272 webwidget_->enterForceCompositingMode(true);
273 }
[email protected]ba91a792013-02-06 09:48:28274 if (compositor_) {
275 compositor_->setSurfaceReady();
[email protected]479b0172012-10-29 19:27:09276 }
[email protected]05a980d7a2012-02-07 22:16:42277 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29278
[email protected]6de74452009-02-25 18:04:59279 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29280}
281
[email protected]992db4c2011-05-12 15:37:15282void RenderWidget::SetSwappedOut(bool is_swapped_out) {
283 // We should only toggle between states.
284 DCHECK(is_swapped_out_ != is_swapped_out);
285 is_swapped_out_ = is_swapped_out;
286
287 // If we are swapping out, we will call ReleaseProcess, allowing the process
288 // to exit if all of its RenderViews are swapped out. We wait until the
289 // WasSwappedOut call to do this, to avoid showing the sad tab.
290 // If we are swapping in, we call AddRefProcess to prevent the process from
291 // exiting.
292 if (!is_swapped_out)
293 RenderProcess::current()->AddRefProcess();
294}
295
[email protected]34bb3ac2013-03-08 02:41:28296bool RenderWidget::AllowPartialSwap() const {
297 return true;
298}
299
[email protected]c8cbae72013-05-23 10:45:03300bool RenderWidget::UsingSynchronousRendererCompositor() const {
[email protected]ccc1722e2013-05-06 19:43:07301#if defined(OS_ANDROID)
[email protected]913d99a2013-05-31 07:16:07302 return SynchronousCompositorFactory::GetInstance() != NULL;
303#else
[email protected]ccc1722e2013-05-06 19:43:07304 return false;
[email protected]913d99a2013-05-31 07:16:07305#endif
[email protected]ccc1722e2013-05-06 19:43:07306}
307
[email protected]a95986a82010-12-24 06:19:28308bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
309 bool handled = true;
310 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15311 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22312 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
313 OnCursorVisibilityChange)
[email protected]c084330e02013-04-27 01:08:15314 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
315 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]a95986a82010-12-24 06:19:28316 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
317 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
318 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54319 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28320 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41321 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]992db4c2011-05-12 15:37:15322 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28323 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]ed7defa2013-03-12 21:29:59324 IPC_MESSAGE_HANDLER(ViewMsg_SwapBuffers_ACK,
325 OnViewContextSwapBuffersComplete)
[email protected]a95986a82010-12-24 06:19:28326 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
327 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
328 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]3d9ec5052013-01-02 22:05:25329 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnPaintAtSize)
330 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
331 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, OnSmoothScrollCompleted)
[email protected]a95986a82010-12-24 06:19:28332 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
333 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03334 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]105dffb42013-02-20 03:46:21335#if defined(OS_ANDROID)
336 IPC_MESSAGE_HANDLER(ViewMsg_ImeBatchStateChanged, OnImeBatchStateChanged)
[email protected]2384b6c2013-02-28 23:58:51337 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21338#endif
[email protected]51a49502013-03-23 01:50:19339 IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot)
[email protected]3639aa82013-06-04 11:00:04340 IPC_MESSAGE_HANDLER(ViewMsg_SetBrowserRenderingStats,
341 OnSetBrowserRenderingStats)
[email protected]a95986a82010-12-24 06:19:28342 IPC_MESSAGE_UNHANDLED(handled = false)
343 IPC_END_MESSAGE_MAP()
344 return handled;
345}
initial.commit09911bf2008-07-26 23:55:29346
347bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15348 // Don't send any messages after the browser has told us to close, and filter
349 // most outgoing messages while swapped out.
350 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26351 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11352 closing_) {
initial.commit09911bf2008-07-26 23:55:29353 delete message;
354 return false;
355 }
356
357 // If given a messsage without a routing ID, then assign our routing ID.
358 if (message->routing_id() == MSG_ROUTING_NONE)
359 message->set_routing_id(routing_id_);
360
[email protected]380244092011-10-07 17:26:27361 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44362}
363
[email protected]61e2b3cc2012-03-02 16:13:34364void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44365 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40366 float overdraw_bottom_height,
[email protected]61e2b3cc2012-03-02 16:13:34367 const gfx::Rect& resizer_rect,
368 bool is_fullscreen,
369 ResizeAck resize_ack) {
[email protected]1c0008842013-06-06 08:35:48370 if (!RenderThreadImpl::current() || // Will be NULL during unit tests.
371 !RenderThreadImpl::current()->layout_test_mode()) {
372 // A resize ack shouldn't be requested if we have not ACK'd the previous
373 // one.
374 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
375 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
376 }
initial.commit09911bf2008-07-26 23:55:29377
[email protected]61e2b3cc2012-03-02 16:13:34378 // Ignore this during shutdown.
379 if (!webwidget_)
380 return;
381
[email protected]d9083762013-03-24 01:36:40382 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44383 compositor_->setViewportSize(new_size, physical_backing_size);
[email protected]d9083762013-03-24 01:36:40384 compositor_->SetOverdrawBottomHeight(overdraw_bottom_height);
385 }
[email protected]60d47ac2013-03-01 23:42:44386
[email protected]dade8992013-03-04 07:34:34387 physical_backing_size_ = physical_backing_size;
[email protected]d9083762013-03-24 01:36:40388 overdraw_bottom_height_ = overdraw_bottom_height;
[email protected]61e2b3cc2012-03-02 16:13:34389 resizer_rect_ = resizer_rect;
390
391 // NOTE: We may have entered fullscreen mode without changing our size.
392 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
393 if (fullscreen_change)
394 WillToggleFullscreen();
395 is_fullscreen_ = is_fullscreen;
396
397 if (size_ != new_size) {
398 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34399 needs_repainting_on_restore_ = false;
400
401 size_ = new_size;
402
403 paint_aggregator_.ClearPendingUpdate();
404
405 // When resizing, we want to wait to paint before ACK'ing the resize. This
406 // ensures that we only resize as fast as we can paint. We only need to
407 // send an ACK if we are resized to a non-empty rect.
408 webwidget_->resize(new_size);
[email protected]0b70dbe2013-05-10 19:06:32409
[email protected]92201e32013-06-08 06:14:52410 if (!RenderThreadImpl::current() || // Will be NULL during unit tests.
411 !RenderThreadImpl::current()->layout_test_mode()) {
412 // Resize should have caused an invalidation of the entire view.
413 DCHECK(new_size.IsEmpty() || is_accelerated_compositing_active_ ||
414 paint_aggregator_.HasPendingUpdate());
415 }
[email protected]1c0008842013-06-06 08:35:48416 } else if (!RenderThreadImpl::current() || // Will be NULL during unit tests.
417 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]632c4382013-05-15 08:58:45418 resize_ack = NO_RESIZE_ACK;
419 }
420
421 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
422 // For empty size or empty physical_backing_size, there is no next paint
423 // (along with which to send the ack) until they are set to non-empty.
[email protected]ff475a322012-03-14 00:05:35424 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34425 }
426
[email protected]20fbfc22013-05-08 20:50:58427 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45428 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58429 set_next_paint_is_resize_ack();
430
[email protected]61e2b3cc2012-03-02 16:13:34431 if (fullscreen_change)
432 DidToggleFullscreen();
433
434 // If a resize ack is requested and it isn't set-up, then no more resizes will
435 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45436 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29437}
438
439void RenderWidget::OnClose() {
440 if (closing_)
441 return;
442 closing_ = true;
443
444 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03445 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27446 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03447 SetHidden(false);
448 }
initial.commit09911bf2008-07-26 23:55:29449
initial.commit09911bf2008-07-26 23:55:29450 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25451 // now. Post a task that only gets invoked when there are no nested message
452 // loops.
[email protected]dd32b1272013-05-04 14:17:11453 base::MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29454 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25455
456 // Balances the AddRef taken when we called AddRoute.
457 Release();
initial.commit09911bf2008-07-26 23:55:29458}
459
[email protected]61e2b3cc2012-03-02 16:13:34460// Got a response from the browser after the renderer decided to create a new
461// view.
[email protected]fc4404d2012-11-07 19:53:30462void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34463 DCHECK(routing_id_ != MSG_ROUTING_NONE);
464
[email protected]fc4404d2012-11-07 19:53:30465 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34466}
467
[email protected]0fdd5012013-05-29 08:05:56468void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
469 screen_info_ = params.screen_info;
470 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
471 Resize(params.new_size, params.physical_backing_size,
472 params.overdraw_bottom_height, params.resizer_rect,
473 params.is_fullscreen, SEND_RESIZE_ACK);
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;
543
[email protected]b4d08452010-10-05 17:34:35544 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
545 // have no current paint buffer.
546 if (current_paint_buf_) {
547 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
548 current_paint_buf_ = NULL;
549 }
550
[email protected]65225772011-05-12 21:10:24551 // If swapbuffers is still pending, then defer the update until the
552 // swapbuffers occurs.
553 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
554 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
555 return;
556 }
557
[email protected]29ed96a2012-02-04 18:12:16558 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18559 if (!is_accelerated_compositing_active_) {
560 DidFlushPaint();
561 }
[email protected]a2f6bc112009-06-27 16:27:25562
initial.commit09911bf2008-07-26 23:55:29563 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24564 DoDeferredUpdateAndSendInputAck();
565}
566
[email protected]d0be63772011-12-20 23:18:04567bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]ed7defa2013-03-12 21:29:59568 // Contexts using the command buffer support asynchronous swapbuffers.
569 // See RenderWidget::CreateOutputSurface().
[email protected]cadac622013-06-11 16:46:36570 if (RenderThreadImpl::current()->compositor_message_loop_proxy().get())
[email protected]ed7defa2013-03-12 21:29:59571 return false;
572
573 return true;
574}
575
576GURL RenderWidget::GetURLForGraphicsContext3D() {
577 return GURL();
[email protected]65225772011-05-12 21:10:24578}
579
[email protected]479b0172012-10-29 19:27:09580bool RenderWidget::ForceCompositingModeEnabled() {
581 return false;
582}
583
[email protected]ba91a792013-02-06 09:48:28584scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface() {
[email protected]c3e32ed42013-05-02 05:07:13585 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]a1811b8912013-05-09 15:35:19586
587#if defined(OS_ANDROID)
[email protected]913d99a2013-05-31 07:16:07588 if (SynchronousCompositorFactory* factory =
589 SynchronousCompositorFactory::GetInstance()) {
590 return factory->CreateOutputSurface(routing_id());
[email protected]a1811b8912013-05-09 15:35:19591 }
592#endif
593
[email protected]8bbe3a92013-05-12 00:58:35594 if (command_line.HasSwitch(switches::kEnableSoftwareCompositingGLAdapter)) {
595 return scoped_ptr<cc::OutputSurface>(
596 new CompositorOutputSurface(routing_id(), NULL,
[email protected]36e5ff12013-06-11 12:19:29597 new CompositorSoftwareOutputDevice(), true));
[email protected]8bbe3a92013-05-12 00:58:35598 }
599
[email protected]ed7defa2013-03-12 21:29:59600 // Explicitly disable antialiasing for the compositor. As of the time of
601 // this writing, the only platform that supported antialiasing for the
602 // compositor was Mac OS X, because the on-screen OpenGL context creation
603 // code paths on Windows and Linux didn't yet have multisampling support.
604 // Mac OS X essentially always behaves as though it's rendering offscreen.
605 // Multisampling has a heavy cost especially on devices with relatively low
606 // fill rate like most notebooks, and the Mac implementation would need to
607 // be optimized to resolve directly into the IOSurface shared between the
608 // GPU and browser processes. For these reasons and to avoid platform
609 // disparities we explicitly disable antialiasing.
610 WebKit::WebGraphicsContext3D::Attributes attributes;
611 attributes.antialias = false;
612 attributes.shareResources = true;
613 attributes.noAutomaticFlushes = true;
[email protected]a6886502013-05-16 20:59:18614 attributes.depth = false;
615 attributes.stencil = false;
[email protected]bec084292013-05-21 21:31:44616 if (command_line.HasSwitch(cc::switches::kForceDirectLayerDrawing))
617 attributes.stencil = true;
[email protected]3ae68c52013-04-12 06:10:05618 WebGraphicsContext3DCommandBufferImpl* context =
619 CreateGraphicsContext3D(attributes);
[email protected]8bbe3a92013-05-12 00:58:35620 if (!context)
621 return scoped_ptr<cc::OutputSurface>();
[email protected]ed7defa2013-03-12 21:29:59622
[email protected]36e5ff12013-06-11 12:19:29623 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) {
624 DCHECK(is_threaded_compositing_enabled_);
625 return scoped_ptr<cc::OutputSurface>(
626 new DelegatedCompositorOutputSurface(routing_id(), context, NULL));
627 }
628 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) {
629 DCHECK(is_threaded_compositing_enabled_);
630 return scoped_ptr<cc::OutputSurface>(
631 new MailboxOutputSurface(routing_id(), context, NULL));
632 }
633 return scoped_ptr<cc::OutputSurface>(
634 new CompositorOutputSurface(routing_id(), context, NULL, false));
[email protected]ba91a792013-02-06 09:48:28635}
636
[email protected]ed7defa2013-03-12 21:29:59637void RenderWidget::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24638 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21639 while (!updates_pending_swap_.empty()) {
640 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
641 updates_pending_swap_.pop_front();
642 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
643 // compositing pass, hence doesn't require an UpdateRect message.
644 if (msg)
645 Send(msg);
646 }
[email protected]65225772011-05-12 21:10:24647 num_swapbuffers_complete_pending_ = 0;
648 using_asynchronous_swapbuffers_ = false;
649 // Schedule another frame so the compositor learns about it.
650 scheduleComposite();
651}
652
[email protected]ed7defa2013-03-12 21:29:59653void RenderWidget::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:08654 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21655
656 if (using_asynchronous_swapbuffers_) {
657 ViewHostMsg_UpdateRect* msg = NULL;
658 // pending_update_params_ can be NULL if the swap doesn't correspond to an
659 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
660 // message.
[email protected]59383c782013-04-17 16:43:27661 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:21662 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
663 pending_update_params_.reset();
664 }
665 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08666 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21667 }
[email protected]37a6f302011-07-11 23:43:08668}
669
[email protected]ed7defa2013-03-12 21:29:59670void RenderWidget::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24671 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16672
[email protected]404939f2012-06-01 04:06:18673 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16674 DidFlushPaint();
675
[email protected]65225772011-05-12 21:10:24676 // When compositing deactivates, we reset the swapbuffers pending count. The
677 // swapbuffers acks may still arrive, however.
678 if (num_swapbuffers_complete_pending_ == 0) {
679 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
680 return;
681 }
[email protected]aa4117f2011-12-09 22:19:21682 DCHECK(!updates_pending_swap_.empty());
683 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
684 updates_pending_swap_.pop_front();
685 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
686 // compositing pass, hence doesn't require an UpdateRect message.
687 if (msg)
688 Send(msg);
[email protected]65225772011-05-12 21:10:24689 num_swapbuffers_complete_pending_--;
690
691 // If update reply is still pending, then defer the update until that reply
692 // occurs.
[email protected]d0be63772011-12-20 23:18:04693 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24694 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
695 return;
696 }
697
698 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06699 // when we were previously rendering. However, if an invalidation task is not
700 // posted, there may be software rendering work pending. In that case, don't
701 // early out.
702 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24703 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
704 return;
705 }
706
[email protected]cc66e682012-10-02 06:48:18707 // Do not call DoDeferredUpdate unless there's animation work to be done or
708 // a real invalidation. This prevents rendering in response to a swapbuffers
709 // callback coming back after we've navigated away from the page that
710 // generated it.
711 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
712 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
713 return;
714 }
715
[email protected]65225772011-05-12 21:10:24716 // Continue painting if necessary...
717 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29718}
719
[email protected]0dea1652012-12-14 00:09:09720void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
[email protected]4b157662013-05-29 04:05:05721 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:09722 bool is_keyboard_shortcut) {
[email protected]5dd768212009-08-13 23:34:49723 handling_input_event_ = true;
[email protected]0dea1652012-12-14 00:09:09724 if (!input_event) {
[email protected]5dd768212009-08-13 23:34:49725 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29726 return;
[email protected]5dd768212009-08-13 23:34:49727 }
initial.commit09911bf2008-07-26 23:55:29728
[email protected]b4841e1c2013-05-16 22:30:10729 const char* const event_name = GetEventName(input_event->type);
730 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent",
731 "event", event_name);
732
[email protected]c2eaa8f2013-05-10 02:41:55733 if (compositor_)
734 compositor_->SetLatencyInfo(latency_info);
[email protected]256737c2013-06-08 04:39:10735 else
736 latency_info_.MergeWith(latency_info);
[email protected]c2eaa8f2013-05-10 02:41:55737
[email protected]6a4d7f62013-01-07 21:32:13738 base::TimeDelta now = base::TimeDelta::FromInternalValue(
739 base::TimeTicks::Now().ToInternalValue());
740
741 int64 delta = static_cast<int64>(
742 (now.InSecondsF() - input_event->timeStampSeconds) *
743 base::Time::kMicrosecondsPerSecond);
744 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer", delta, 0, 1000000, 100);
[email protected]de415552013-01-23 04:12:17745 base::HistogramBase* counter_for_type =
[email protected]bafdc5d52013-02-27 18:18:48746 base::Histogram::FactoryGet(
[email protected]b4841e1c2013-05-16 22:30:10747 base::StringPrintf("Event.Latency.Renderer.%s", event_name),
[email protected]bafdc5d52013-02-27 18:18:48748 0,
749 1000000,
[email protected]6a4d7f62013-01-07 21:32:13750 100,
[email protected]de415552013-01-23 04:12:17751 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]bafdc5d52013-02-27 18:18:48752 counter_for_type->Add(delta);
[email protected]6a4d7f62013-01-07 21:32:13753
[email protected]67bfb83f2011-09-22 03:36:37754 bool prevent_default = false;
755 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26756 const WebMouseEvent& mouse_event =
757 *static_cast<const WebMouseEvent*>(input_event);
758 TRACE_EVENT2("renderer", "HandleMouseMove",
759 "x", mouse_event.x, "y", mouse_event.y);
760 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37761 }
762
[email protected]41d86852012-11-07 12:23:24763 if (WebInputEvent::isGestureEventType(input_event->type)) {
764 const WebGestureEvent& gesture_event =
765 *static_cast<const WebGestureEvent*>(input_event);
766 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
767 }
768
[email protected]3ebcc7c2013-01-09 05:34:46769 if (input_event->type == WebInputEvent::GestureTap ||
770 input_event->type == WebInputEvent::GestureLongPress)
771 resetInputMethod();
772
[email protected]67bfb83f2011-09-22 03:36:37773 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12774 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
775 suppress_next_char_events_ = false;
776 if (!processed && webwidget_)
777 processed = webwidget_->handleInputEvent(*input_event);
778 }
779
780 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
781 // it's not processed by webkit, then we need to suppress the upcoming Char
782 // events.
783 if (!processed && is_keyboard_shortcut)
784 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29785
[email protected]3d5c243b2012-11-30 00:26:01786 InputEventAckState ack_result = processed ?
787 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
788 if (!processed && input_event->type == WebInputEvent::TouchStart) {
789 const WebTouchEvent& touch_event =
790 *static_cast<const WebTouchEvent*>(input_event);
791 ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ?
792 INPUT_EVENT_ACK_STATE_NOT_CONSUMED :
793 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
794 }
795
[email protected]a9fb30aa2011-10-06 06:58:46796 IPC::Message* response =
[email protected]c084330e02013-04-27 01:08:15797 new InputHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
798 ack_result);
[email protected]3391a0772012-03-28 00:32:07799 bool event_type_gets_rate_limited =
800 input_event->type == WebInputEvent::MouseMove ||
801 input_event->type == WebInputEvent::MouseWheel ||
802 WebInputEvent::isTouchEventType(input_event->type);
[email protected]8926c602013-01-23 05:32:06803
804 bool frame_pending = paint_aggregator_.HasPendingUpdate();
805 if (is_accelerated_compositing_active_) {
[email protected]ba91a792013-02-06 09:48:28806 frame_pending = compositor_ &&
807 compositor_->commitRequested();
[email protected]8926c602013-01-23 05:32:06808 }
809
[email protected]9a8ce7f92013-06-11 12:39:49810 if (event_type_gets_rate_limited && frame_pending && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24811 // We want to rate limit the input events in this case, so we'll wait for
812 // painting to finish before ACKing this message.
[email protected]59383c782013-04-17 16:43:27813 if (pending_input_event_ack_) {
[email protected]353a34c2010-05-28 23:35:17814 // As two different kinds of events could cause us to postpone an ack
815 // we send it now, if we have one pending. The Browser should never
816 // send us the same kind of event we are delaying the ack for.
817 Send(pending_input_event_ack_.release());
818 }
[email protected]12fbad812009-09-01 18:21:24819 pending_input_event_ack_.reset(response);
820 } else {
821 Send(response);
822 }
823
[email protected]3306f262012-09-21 19:20:42824#if defined(OS_ANDROID)
825 // Allow the IME to be shown when the focus changes as a consequence
826 // of a processed touch end event.
827 if (input_event->type == WebInputEvent::TouchEnd && processed)
828 UpdateTextInputState(SHOW_IME_IF_NEEDED);
829#endif
830
[email protected]5dd768212009-08-13 23:34:49831 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48832
[email protected]67bfb83f2011-09-22 03:36:37833 if (!prevent_default) {
834 if (WebInputEvent::isKeyboardEventType(input_event->type))
835 DidHandleKeyEvent();
836 if (WebInputEvent::isMouseEventType(input_event->type))
837 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24838 if (WebInputEvent::isTouchEventType(input_event->type))
839 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37840 }
initial.commit09911bf2008-07-26 23:55:29841}
842
[email protected]34202de2013-05-06 23:36:22843void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
844 if (webwidget_)
845 webwidget_->setCursorVisibilityState(is_visible);
846}
847
initial.commit09911bf2008-07-26 23:55:29848void RenderWidget::OnMouseCaptureLost() {
849 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28850 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29851}
852
853void RenderWidget::OnSetFocus(bool enable) {
854 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33855 if (webwidget_)
856 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29857}
858
859void RenderWidget::ClearFocus() {
860 // We may have got the focus from the browser before this gets processed, in
861 // which case we do not want to unfocus ourself.
862 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28863 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29864}
865
[email protected]2d5d09d52009-06-15 14:29:21866void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00867 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21868 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06869 TRACE_EVENT2("renderer", "PaintRect",
870 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:45871
872 const bool kEnableGpuBenchmarking =
873 CommandLine::ForCurrentProcess()->HasSwitch(
874 switches::kEnableGpuBenchmarking);
[email protected]4fb66842009-12-04 21:41:00875 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21876
877 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00878 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
879 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03880
[email protected]699ab0d2009-04-23 23:19:14881 // If there is a custom background, tile it.
882 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14883 SkPaint paint;
[email protected]4e29afd2012-12-04 04:07:11884 skia::RefPtr<SkShader> shader = skia::AdoptRef(
885 SkShader::CreateBitmapShader(background_,
886 SkShader::kRepeat_TileMode,
887 SkShader::kRepeat_TileMode));
888 paint.setShader(shader.get());
[email protected]fb10ec5b2011-10-24 17:54:20889
890 // Use kSrc_Mode to handle background_ transparency properly.
891 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
892
893 // Canvas could contain multiple update rects. Clip to given rect so that
894 // we don't accidentally clear other update rects.
895 canvas->save();
[email protected]aa7e7a12013-02-22 13:37:44896 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]1835b9e2012-02-28 13:12:48897 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14898 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20899 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14900 }
901
[email protected]719b36f2010-12-22 20:36:46902 // First see if this rect is a plugin that can paint itself faster.
903 TransportDIB* optimized_dib = NULL;
904 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:20905 float dib_scale_factor;
[email protected]719b36f2010-12-22 20:36:46906 webkit::ppapi::PluginInstance* optimized_instance =
907 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
908 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:20909 &optimized_copy_rect,
910 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:46911 if (optimized_instance) {
912 // This plugin can be optimize-painted and we can just ask it to paint
913 // itself. We don't actually need the TransportDIB in this case.
914 //
915 // This is an optimization for PPAPI plugins that know they're on top of
916 // the page content. If this rect is inside such a plugin, we can save some
917 // time and avoid re-rendering the page content which we know will be
918 // covered by the plugin later (this time can be significant, especially
919 // for a playing movie that is invalidating a lot).
920 //
921 // In the plugin movie case, hopefully the similar call to
922 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
923 // painting, because that avoids copying the plugin image to a different
924 // paint rect. Unfortunately, if anything on the page is animating other
925 // than the movie, it break this optimization since the union of the
926 // invalid regions will be larger than the plugin.
927 //
928 // This code optimizes that case, where we can still avoid painting in
929 // WebKit and filling the background (which can be slow) and just painting
930 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
931 // required.
[email protected]63ab54262012-11-09 15:58:45932 base::TimeTicks paint_begin_ticks;
933 if (kEnableGpuBenchmarking)
934 paint_begin_ticks = base::TimeTicks::HighResNow();
935
[email protected]df59dd42012-09-14 22:56:30936 SkAutoCanvasRestore auto_restore(canvas, true);
937 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]719b36f2010-12-22 20:36:46938 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27939 optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:21940 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45941 if (kEnableGpuBenchmarking) {
942 base::TimeDelta paint_time =
943 base::TimeTicks::HighResNow() - paint_begin_ticks;
944 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01945 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45946 }
[email protected]719b36f2010-12-22 20:36:46947 } else {
948 // Normal painting case.
[email protected]63ab54262012-11-09 15:58:45949 base::TimeTicks paint_begin_ticks;
950 if (kEnableGpuBenchmarking)
951 paint_begin_ticks = base::TimeTicks::HighResNow();
952
[email protected]719b36f2010-12-22 20:36:46953 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
[email protected]63ab54262012-11-09 15:58:45954
955 if (kEnableGpuBenchmarking) {
956 base::TimeDelta paint_time =
957 base::TimeTicks::HighResNow() - paint_begin_ticks;
958 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01959 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45960 }
[email protected]719b36f2010-12-22 20:36:46961
962 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35963 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46964 }
initial.commit09911bf2008-07-26 23:55:29965
[email protected]4fb66842009-12-04 21:41:00966 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00967 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45968
969 if (kEnableGpuBenchmarking) {
[email protected]63ab54262012-11-09 15:58:45970 int64 num_pixels_processed = rect.width() * rect.height();
[email protected]62049562013-03-24 00:39:01971 software_stats_.total_pixels_painted += num_pixels_processed;
[email protected]63ab54262012-11-09 15:58:45972 }
[email protected]4fb66842009-12-04 21:41:00973}
974
975void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
976 skia::PlatformCanvas* canvas) {
977 static bool kPaintBorder =
978 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
979 if (!kPaintBorder)
980 return;
981
[email protected]53d3f302009-12-21 04:42:05982 // Cycle through these colors to help distinguish new paint rects.
983 const SkColor colors[] = {
984 SkColorSetARGB(0x3F, 0xFF, 0, 0),
985 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
986 SkColorSetARGB(0x3F, 0, 0, 0xFF),
987 };
988 static int color_selector = 0;
989
[email protected]4fb66842009-12-04 21:41:00990 SkPaint paint;
991 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05992 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00993 paint.setStrokeWidth(1);
994
995 SkIRect irect;
996 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
997 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29998}
999
[email protected]52ccd0ea2011-02-16 01:09:051000void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:301001 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:301002 if (!animation_update_pending_) {
1003 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:591004 return;
[email protected]921244e42011-07-20 16:36:301005 }
[email protected]bd37ae252011-06-03 01:28:181006 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:591007 // Record when we fired (according to base::Time::Now()) relative to when
1008 // we posted the task to quantify how much the base::Time/base::TimeTicks
1009 // skew is affecting animations.
1010 base::TimeDelta animation_callback_delay = base::Time::Now() -
1011 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
1012 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
1013 animation_callback_delay,
1014 base::TimeDelta::FromMilliseconds(0),
1015 base::TimeDelta::FromMilliseconds(30),
1016 25);
1017 }
[email protected]65225772011-05-12 21:10:241018 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:241019}
1020
[email protected]52ccd0ea2011-02-16 01:09:051021void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:591022 if (!animation_update_pending_)
1023 return;
[email protected]bd37ae252011-06-03 01:28:181024
1025 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:331026 base::TimeDelta animationInterval = IsRenderingVSynced() ?
1027 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:181028
[email protected]7c4329e2011-02-18 22:02:591029 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:451030
1031 // animation_floor_time_ is the earliest time that we should animate when
1032 // using the dead reckoning software scheduler. If we're using swapbuffers
1033 // complete callbacks to rate limit, we can ignore this floor.
1034 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:301035 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:331036 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:181037 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:591038 // running animation callbacks so that if a callback requests another
1039 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:381040 animation_timer_.Stop();
1041 animation_timer_.Start(FROM_HERE, animationInterval, this,
1042 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:591043 animation_update_pending_ = false;
[email protected]ba91a792013-02-06 09:48:281044 if (is_accelerated_compositing_active_ && compositor_) {
[email protected]635353c2013-03-06 09:11:201045 compositor_->Animate(base::TimeTicks::Now());
[email protected]8926c602013-01-23 05:32:061046 } else {
[email protected]635353c2013-03-06 09:11:201047 double frame_begin_time =
1048 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
1049 webwidget_->animate(frame_begin_time);
[email protected]8926c602013-01-23 05:32:061050 }
[email protected]7c4329e2011-02-18 22:02:591051 return;
[email protected]5f8b1022011-01-21 23:34:501052 }
[email protected]bd37ae252011-06-03 01:28:181053 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:381054 if (!animation_timer_.IsRunning()) {
1055 // This code uses base::Time::Now() to calculate the floor and next fire
1056 // time because javascript's Date object uses base::Time::Now(). The
1057 // message loop uses base::TimeTicks, which on windows can have a
1058 // different granularity than base::Time.
1059 // The upshot of all this is that this function might be called before
1060 // base::Time::Now() has advanced past the animation_floor_time_. To
1061 // avoid exposing this delay to javascript, we keep posting delayed
1062 // tasks until base::Time::Now() has advanced far enough.
1063 base::TimeDelta delay = animation_floor_time_ - now;
1064 animation_timer_.Start(FROM_HERE, delay, this,
1065 &RenderWidget::AnimationCallback);
1066 }
[email protected]5f8b1022011-01-21 23:34:501067}
1068
[email protected]bd37ae252011-06-03 01:28:181069bool RenderWidget::IsRenderingVSynced() {
1070 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
1071 // not caught by this check. This will lead to artificially low frame rates
1072 // for people who force vsync off at a driver level and expect Chrome to speed
1073 // up.
1074 return !has_disable_gpu_vsync_switch_;
1075}
1076
[email protected]65225772011-05-12 21:10:241077void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:061078 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:241079 invalidation_task_posted_ = false;
1080 DoDeferredUpdateAndSendInputAck();
1081}
1082
1083void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:051084 DoDeferredUpdate();
1085
[email protected]59383c782013-04-17 16:43:271086 if (pending_input_event_ack_)
[email protected]52ccd0ea2011-02-16 01:09:051087 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:211088}
1089
[email protected]552e6002009-11-19 05:24:571090void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:581091 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:081092
[email protected]65225772011-05-12 21:10:241093 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:291094 return;
[email protected]05a980d7a2012-02-07 22:16:421095
[email protected]fc4404d2012-11-07 19:53:301096 if (!init_complete_) {
1097 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:421098 return;
1099 }
[email protected]aa4117f2011-12-09 22:19:211100 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:241101 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
1102 return;
1103 }
[email protected]9ca84622011-06-02 23:46:391104 if (is_accelerated_compositing_active_ &&
1105 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:241106 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
1107 return;
1108 }
initial.commit09911bf2008-07-26 23:55:291109
[email protected]552e6002009-11-19 05:24:571110 // Suppress updating when we are hidden.
[email protected]e3d92a7f2013-01-10 02:35:051111 if (is_hidden_ || size_.IsEmpty() || is_swapped_out_) {
[email protected]552e6002009-11-19 05:24:571112 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:291113 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:241114 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:291115 return;
1116 }
1117
[email protected]0fb93f52011-05-18 23:13:561118 // Tracking of frame rate jitter
1119 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]38ce4e7b2013-02-23 06:17:371120 InstrumentWillBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:051121 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:501122
[email protected]f98d7e3c2010-09-13 22:30:461123 // Layout may generate more invalidation. It may also enable the
1124 // GPU acceleration, so make sure to run layout before we send the
1125 // GpuRenderingActivated message.
1126 webwidget_->layout();
1127
[email protected]793b2d62013-06-11 00:43:251128 // Check for whether we need to track swap buffers. We need to do that after
1129 // layout() because it may have switched us to accelerated compositing.
1130 if (is_accelerated_compositing_active_)
1131 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
1132
[email protected]dcca3aa92012-02-17 23:03:371133 // The following two can result in further layout and possibly
1134 // enable GPU acceleration so they need to be called before any painting
1135 // is done.
[email protected]3306f262012-09-21 19:20:421136 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]dcca3aa92012-02-17 23:03:371137 UpdateSelectionBounds();
1138
[email protected]5f8b1022011-01-21 23:34:501139 // Suppress painting if nothing is dirty. This has to be done after updating
1140 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:241141 if (!paint_aggregator_.HasPendingUpdate()) {
1142 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]38ce4e7b2013-02-23 06:17:371143 InstrumentDidCancelFrame();
[email protected]5f8b1022011-01-21 23:34:501144 return;
[email protected]65225772011-05-12 21:10:241145 }
[email protected]5f8b1022011-01-21 23:34:501146
[email protected]479b0172012-10-29 19:27:091147 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:361148 !is_threaded_compositing_enabled_ &&
[email protected]479b0172012-10-29 19:27:091149 ForceCompositingModeEnabled()) {
1150 webwidget_->enterForceCompositingMode(true);
1151 }
1152
[email protected]872ae5b2011-05-26 20:20:501153 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:561154 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:041155 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:561156 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
1157 delay,
1158 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411159 base::TimeDelta::FromMilliseconds(120),
1160 60);
[email protected]d0be63772011-12-20 23:18:041161 } else {
[email protected]0fb93f52011-05-18 23:13:561162 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
1163 delay,
1164 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411165 base::TimeDelta::FromMilliseconds(120),
1166 60);
[email protected]d0be63772011-12-20 23:18:041167 }
[email protected]872ae5b2011-05-26 20:20:501168
1169 // Calculate filtered time per frame:
1170 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
1171 filtered_time_per_frame_ =
1172 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:561173 }
1174 last_do_deferred_update_time_ = frame_begin_ticks;
1175
[email protected]fef5e3972012-08-07 03:59:471176 if (!is_accelerated_compositing_active_) {
[email protected]62049562013-03-24 00:39:011177 software_stats_.animation_frame_count++;
1178 software_stats_.screen_frame_count++;
[email protected]fef5e3972012-08-07 03:59:471179 }
1180
[email protected]552e6002009-11-19 05:24:571181 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:291182 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:301183 PaintAggregator::PendingUpdate update;
1184 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:291185
[email protected]53d3f302009-12-21 04:42:051186 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:181187 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:291188
[email protected]29ed96a2012-02-04 18:12:161189 // Notify derived classes that we're about to initiate a paint.
1190 WillInitiatePaint();
1191
[email protected]ca4847f2010-09-24 05:39:151192 // A plugin may be able to do an optimized paint. First check this, in which
1193 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:461194 // This optimization allows PPAPI plugins that declare themselves on top of
1195 // the page (like a traditional windowed plugin) to be able to animate (think
1196 // movie playing) without repeatedly re-painting the page underneath, or
1197 // copying the plugin backing store (since we can send the plugin's backing
1198 // store directly to the browser).
1199 //
1200 // This optimization only works when the entire invalid region is contained
1201 // within the plugin. There is a related optimization in PaintRect for the
1202 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:151203 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:151204 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201205 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:211206 DCHECK(!pending_update_params_.get());
1207 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551208 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211209 pending_update_params_->scroll_rect = update.scroll_rect;
1210 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211211 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1212 pending_update_params_->flags = next_paint_flags_;
1213 pending_update_params_->scroll_offset = GetScrollOffset();
1214 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091215 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211216 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091217 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211218
[email protected]256737c2013-06-08 04:39:101219 if (!is_accelerated_compositing_active_)
1220 pending_update_params_->latency_info = latency_info_;
1221
1222 latency_info_.Clear();
1223
[email protected]ca4847f2010-09-24 05:39:151224 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561225 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151226 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201227 &optimized_copy_rect,
1228 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271229 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471230 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211231 pending_update_params_->bitmap = dib->id();
1232 pending_update_params_->bitmap_rect = optimized_copy_location;
1233 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201234 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561235 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461236 // Compute a buffer for painting and cache it.
[email protected]4889bd212013-02-11 22:23:101237
1238 bool fractional_scale = device_scale_factor_ -
1239 static_cast<int>(device_scale_factor_) != 0;
1240 if (fractional_scale) {
1241 // Damage might not be DIP aligned. Inflate damage to compensate.
1242 bounds.Inset(-1, -1);
1243 bounds.Intersect(gfx::Rect(size_));
1244 }
1245
1246 gfx::Rect pixel_bounds = gfx::ToEnclosingRect(
[email protected]ce112fe2012-10-29 22:52:181247 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]4889bd212013-02-11 22:23:101248
[email protected]ca4847f2010-09-24 05:39:151249 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351250 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591251 pixel_bounds));
[email protected]59383c782013-04-17 16:43:271252 if (!canvas) {
[email protected]f98d7e3c2010-09-13 22:30:461253 NOTREACHED();
1254 return;
1255 }
[email protected]cef3362f2009-12-21 17:48:451256
[email protected]f98d7e3c2010-09-13 22:30:461257 // We may get back a smaller canvas than we asked for.
1258 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591259 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1260 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1261 pixel_bounds.set_width(canvas->getDevice()->width());
1262 pixel_bounds.set_height(canvas->getDevice()->height());
1263 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1264 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051265
[email protected]f98d7e3c2010-09-13 22:30:461266 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1267
[email protected]aa4117f2011-12-09 22:19:211268 pending_update_params_->bitmap = current_paint_buf_->id();
1269 pending_update_params_->bitmap_rect = bounds;
1270
1271 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461272 // The scroll damage is just another rectangle to paint and copy.
1273 copy_rects.swap(update.paint_rects);
1274 if (!scroll_damage.IsEmpty())
1275 copy_rects.push_back(scroll_damage);
1276
[email protected]4889bd212013-02-11 22:23:101277 for (size_t i = 0; i < copy_rects.size(); ++i) {
1278 gfx::Rect rect = copy_rects[i];
1279 if (fractional_scale) {
1280 // Damage might not be DPI aligned. Inflate rect to compensate.
1281 rect.Inset(-1, -1);
1282 }
1283 PaintRect(rect, pixel_bounds.origin(), canvas.get());
1284 }
[email protected]60a50072012-01-11 02:05:351285
1286 // Software FPS tick for performance tests. The accelerated path traces the
1287 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1288 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421289 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW",
1290 TRACE_EVENT_SCOPE_THREAD);
[email protected]f98d7e3c2010-09-13 22:30:461291 } else { // Accelerated compositing path
1292 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211293 // If painting is done via the gpu process then we don't set any damage
1294 // rects to save the browser process from doing unecessary work.
1295 pending_update_params_->bitmap_rect = bounds;
1296 pending_update_params_->scroll_rect = gfx::Rect();
1297 // We don't need an ack, because we're not sharing a DIB with the browser.
1298 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1299 // with the browser for the GPU surface.
1300 pending_update_params_->needs_ack = false;
[email protected]f0c2a242013-03-15 19:34:521301 Composite(frame_begin_ticks);
[email protected]f98d7e3c2010-09-13 22:30:461302 }
1303
[email protected]936c6f52011-12-13 01:35:261304 // If we're holding a pending input event ACK, send the ACK before sending the
1305 // UpdateReply message so we can receive another input event before the
1306 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1307 // the UpdateRect IPC message handler.
[email protected]59383c782013-04-17 16:43:271308 if (pending_input_event_ack_)
[email protected]936c6f52011-12-13 01:35:261309 Send(pending_input_event_ack_.release());
1310
[email protected]ab543072013-01-25 04:38:151311 // If Composite() called SwapBuffers, pending_update_params_ will be reset (in
[email protected]aa4117f2011-12-09 22:19:211312 // OnSwapBuffersPosted), meaning a message has been added to the
1313 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1314 // the message now.
[email protected]59383c782013-04-17 16:43:271315 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:211316 // sending an ack to browser process that the paint is complete...
1317 update_reply_pending_ = pending_update_params_->needs_ack;
1318 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1319 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341320 }
[email protected]53d3f302009-12-21 04:42:051321
[email protected]29ed96a2012-02-04 18:12:161322 // If we're software rendering then we're done initiating the paint.
1323 if (!is_accelerated_compositing_active_)
1324 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291325}
1326
[email protected]f0c2a242013-03-15 19:34:521327void RenderWidget::Composite(base::TimeTicks frame_begin_time) {
[email protected]ab543072013-01-25 04:38:151328 DCHECK(is_accelerated_compositing_active_);
[email protected]ba91a792013-02-06 09:48:281329 if (compositor_) // TODO(jamesr): Figure out how this can be null.
[email protected]f0c2a242013-03-15 19:34:521330 compositor_->Composite(frame_begin_time);
[email protected]ab543072013-01-25 04:38:151331}
1332
initial.commit09911bf2008-07-26 23:55:291333///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461334// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291335
[email protected]4873c7d2009-07-16 06:36:281336void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]479b0172012-10-29 19:27:091337 TRACE_EVENT2("renderer", "RenderWidget::didInvalidateRect",
1338 "width", rect.width, "height", rect.height);
[email protected]552e6002009-11-19 05:24:571339 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481340 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181341 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571342 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291343 return;
1344
[email protected]552e6002009-11-19 05:24:571345 paint_aggregator_.InvalidateRect(damaged_rect);
1346
1347 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241348 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571349 return;
1350 if (!paint_aggregator_.HasPendingUpdate())
1351 return;
[email protected]aa4117f2011-12-09 22:19:211352 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241353 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1354 return;
1355
1356 // When GPU rendering, combine pending animations and invalidations into
1357 // a single update.
[email protected]816edc62012-03-17 01:27:221358 if (is_accelerated_compositing_active_ &&
1359 animation_update_pending_ &&
1360 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571361 return;
1362
1363 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291364 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1365 // on the call stack.
1366 // 2) Allows us to collect more damage rects before painting to help coalesce
1367 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241368 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111369 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211370 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291371}
1372
[email protected]990278ff2012-11-13 02:12:551373void RenderWidget::didScrollRect(int dx, int dy,
1374 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461375 // Drop scrolls on the floor when we are in compositing mode.
1376 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561377 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461378 return;
1379
[email protected]552e6002009-11-19 05:24:571380 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481381 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181382 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571383 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291384 return;
1385
[email protected]990278ff2012-11-13 02:12:551386 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571387
1388 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241389 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571390 return;
1391 if (!paint_aggregator_.HasPendingUpdate())
1392 return;
[email protected]aa4117f2011-12-09 22:19:211393 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241394 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1395 return;
1396
1397 // When GPU rendering, combine pending animations and invalidations into
1398 // a single update.
[email protected]816edc62012-03-17 01:27:221399 if (is_accelerated_compositing_active_ &&
1400 animation_update_pending_ &&
1401 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571402 return;
1403
1404 // Perform updating asynchronously. This serves two purposes:
1405 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1406 // on the call stack.
1407 // 2) Allows us to collect more damage rects before painting to help coalesce
1408 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241409 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111410 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211411 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291412}
1413
[email protected]244ac1892011-12-02 17:04:471414void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091415 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451416 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581417
[email protected]eac2b362013-05-22 07:01:451418 // If we don't clear PaintAggregator after changing autoResize state, then
1419 // we might end up in a situation where bitmap_rect is larger than the
1420 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1421 // with invalid damage rects.
1422 paint_aggregator_.ClearPendingUpdate();
1423
[email protected]70dee7e2013-05-29 18:28:301424 if (RenderThreadImpl::current()->layout_test_mode()) {
[email protected]eac2b362013-05-22 07:01:451425 WebRect new_pos(rootWindowRect().x,
1426 rootWindowRect().y,
1427 new_size.width,
1428 new_size.height);
1429 view_screen_rect_ = new_pos;
1430 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031431 }
[email protected]20fbfc22013-05-08 20:50:581432
[email protected]eac2b362013-05-22 07:01:451433 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581434
[email protected]70dee7e2013-05-29 18:28:301435 if (!RenderThreadImpl::current()->layout_test_mode())
[email protected]20fbfc22013-05-08 20:50:581436 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091437 }
[email protected]244ac1892011-12-02 17:04:471438}
1439
[email protected]3a1c8a8032013-03-18 22:35:321440void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051441 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1442 device_scale_factor_));
1443 if (compositor_)
1444 compositor_->setViewportSize(size_, physical_backing_size_);
1445}
1446
[email protected]91acd1c2012-03-14 08:32:391447void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221448 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1449
[email protected]c63b4d42012-04-26 01:01:071450#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211451 if (!is_accelerated_compositing_active_) {
1452 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1453 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1454 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1455 // going to switch to accelerated compositing, the GPU process may need
1456 // round-trips to the browser's UI thread before finishing the frame,
1457 // causing deadlocks if we delay the UpdateRect until we receive the
1458 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071459 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1460 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211461 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1462 }
[email protected]c63b4d42012-04-26 01:01:071463#endif
[email protected]aa4117f2011-12-09 22:19:211464
[email protected]ea162f92011-10-04 23:08:221465 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421466 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241467 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221468}
1469
1470void RenderWidget::didDeactivateCompositor() {
1471 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1472
1473 is_accelerated_compositing_active_ = false;
1474 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1475 routing_id_, is_accelerated_compositing_active_));
1476
[email protected]ea162f92011-10-04 23:08:221477 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241478 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091479
1480 // In single-threaded mode, we exit force compositing mode and re-enter in
1481 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1482 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1483 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361484 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091485 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561486}
1487
[email protected]e195e582013-03-08 01:32:591488void RenderWidget::initializeLayerTreeView() {
1489 compositor_ = RenderWidgetCompositor::Create(this);
1490 if (!compositor_)
1491 return;
1492
1493 compositor_->setViewportSize(size_, physical_backing_size_);
1494 if (init_complete_)
1495 compositor_->setSurfaceReady();
1496}
1497
[email protected]8926c602013-01-23 05:32:061498WebKit::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281499 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061500}
1501
[email protected]9ed83fe2013-02-27 01:52:281502void RenderWidget::suppressCompositorScheduling(bool enable) {
1503 if (compositor_)
1504 compositor_->SetSuppressScheduleComposite(enable);
1505}
1506
[email protected]9cd43a62012-03-26 08:03:561507void RenderWidget::willBeginCompositorFrame() {
1508 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371509
[email protected]cadac622013-06-11 16:46:361510 DCHECK(RenderThreadImpl::current()->compositor_message_loop_proxy().get());
[email protected]abe8b3a2012-03-28 21:19:371511
1512 // The following two can result in further layout and possibly
1513 // enable GPU acceleration so they need to be called before any painting
1514 // is done.
[email protected]2d354272013-01-14 00:59:061515 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]abe8b3a2012-03-28 21:19:371516 UpdateSelectionBounds();
1517
[email protected]9cd43a62012-03-26 08:03:561518 WillInitiatePaint();
1519}
1520
[email protected]3391a0772012-03-28 00:32:071521void RenderWidget::didBecomeReadyForAdditionalInput() {
1522 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]59383c782013-04-17 16:43:271523 if (pending_input_event_ack_)
[email protected]3391a0772012-03-28 00:32:071524 Send(pending_input_event_ack_.release());
1525}
1526
[email protected]6fceb912013-02-15 06:24:151527void RenderWidget::DidCommitCompositorFrame() {
1528}
1529
[email protected]58264a32011-11-17 23:36:151530void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501531 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351532 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1533 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421534 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU",
1535 TRACE_EVENT_SCOPE_THREAD);
[email protected]29ed96a2012-02-04 18:12:161536 // Notify subclasses that we initiated the paint operation.
1537 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151538}
1539
1540void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181541 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1542
1543 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561544 DidFlushPaint();
1545
[email protected]aa4117f2011-12-09 22:19:211546 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151547 return;
1548
[email protected]ea3ee0a2012-05-15 03:43:091549 if (!next_paint_flags_ &&
1550 !need_update_rect_for_auto_resize_ &&
1551 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151552 return;
[email protected]ea3ee0a2012-05-15 03:43:091553 }
[email protected]58264a32011-11-17 23:36:151554
1555 ViewHostMsg_UpdateRect_Params params;
1556 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151557 params.plugin_window_moves.swap(plugin_window_moves_);
1558 params.flags = next_paint_flags_;
1559 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121560 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091561 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151562
1563 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1564 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091565 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151566}
1567
[email protected]f98d7e3c2010-09-13 22:30:461568void RenderWidget::scheduleComposite() {
[email protected]479b0172012-10-29 19:27:091569 TRACE_EVENT0("gpu", "RenderWidget::scheduleComposite");
[email protected]cadac622013-06-11 16:46:361570 if (RenderThreadImpl::current()->compositor_message_loop_proxy().get() &&
[email protected]ba91a792013-02-06 09:48:281571 compositor_) {
1572 compositor_->setNeedsRedraw();
[email protected]d0be63772011-12-20 23:18:041573 } else {
[email protected]c3d45532011-10-07 19:20:401574 // TODO(nduca): replace with something a little less hacky. The reason this
1575 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1576 // contains a lot of host-renderer synchronization logic that is still
1577 // important for the accelerated compositing case. The option of simply
1578 // duplicating all that code is less desirable than "faking out" the
1579 // invalidation path using a magical damage rect.
1580 didInvalidateRect(WebRect(0, 0, 1, 1));
1581 }
[email protected]f98d7e3c2010-09-13 22:30:461582}
1583
[email protected]5f8b1022011-01-21 23:34:501584void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201585 if (animation_update_pending_)
1586 return;
1587
[email protected]921244e42011-07-20 16:36:301588 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201589 animation_update_pending_ = true;
1590 if (!animation_timer_.IsRunning()) {
1591 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1592 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211593 }
[email protected]5f8b1022011-01-21 23:34:501594}
1595
[email protected]4873c7d2009-07-16 06:36:281596void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301597 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521598 WebCursor cursor;
1599 webkit_glue::InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291600 // Only send a SetCursor message if we need to make a change.
1601 if (!current_cursor_.IsEqual(cursor)) {
1602 current_cursor_ = cursor;
1603 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1604 }
1605}
1606
1607// We are supposed to get a single call to Show for a newly created RenderWidget
1608// that was created via RenderWidget::CreateWebView. So, we wait until this
1609// point to dispatch the ShowWidget message.
1610//
1611// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281612// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291613//
[email protected]4873c7d2009-07-16 06:36:281614void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291615 DCHECK(!did_show_) << "received extraneous Show call";
1616 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1617 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1618
[email protected]8de12d942010-11-17 20:42:441619 if (did_show_)
1620 return;
1621
1622 did_show_ = true;
1623 // NOTE: initial_pos_ may still have its default values at this point, but
1624 // that's okay. It'll be ignored if as_popup is false, or the browser
1625 // process will impose a default position otherwise.
1626 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1627 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291628}
1629
[email protected]9b003482013-05-21 14:00:171630void RenderWidget::didProgrammaticallyScroll(
1631 const WebKit::WebPoint& scroll_point) {
1632 if (!compositor_)
1633 return;
1634 Send(new ViewHostMsg_DidProgrammaticallyScroll(
1635 routing_id_, gfx::Vector2d(scroll_point.x, scroll_point.y)));
1636}
1637
[email protected]4873c7d2009-07-16 06:36:281638void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291639}
1640
[email protected]4873c7d2009-07-16 06:36:281641void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291642}
1643
[email protected]2533ce12009-05-09 00:02:241644void RenderWidget::DoDeferredClose() {
1645 Send(new ViewHostMsg_Close(routing_id_));
1646}
1647
[email protected]4873c7d2009-07-16 06:36:281648void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321649 if (is_swapped_out_) {
1650 // This widget is currently swapped out, and the active widget is in a
1651 // different process. Have the browser route the close request to the
1652 // active widget instead, so that the correct unload handlers are run.
1653 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1654 return;
1655 }
1656
initial.commit09911bf2008-07-26 23:55:291657 // If a page calls window.close() twice, we'll end up here twice, but that's
1658 // OK. It is safe to send multiple Close messages.
1659
[email protected]2533ce12009-05-09 00:02:241660 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1661 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1662 // could be closed before the JS finishes executing. So instead, post a
1663 // message back to the message loop, which won't run until the JS is
1664 // complete, and then the Close message can be sent.
[email protected]dd32b1272013-05-04 14:17:111665 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211666 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291667}
1668
1669void RenderWidget::Close() {
1670 if (webwidget_) {
[email protected]8926c602013-01-23 05:32:061671 webwidget_->willCloseLayerTreeView();
[email protected]ba91a792013-02-06 09:48:281672 compositor_.reset();
[email protected]4873c7d2009-07-16 06:36:281673 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291674 webwidget_ = NULL;
1675 }
1676}
1677
[email protected]4873c7d2009-07-16 06:36:281678WebRect RenderWidget::windowRect() {
1679 if (pending_window_rect_count_)
1680 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241681
[email protected]80ad8622012-11-07 16:33:031682 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291683}
1684
[email protected]8a9d6ca32011-06-06 20:11:301685void RenderWidget::setToolTipText(const WebKit::WebString& text,
1686 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541687 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301688}
1689
[email protected]4873c7d2009-07-16 06:36:281690void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291691 if (did_show_) {
[email protected]70dee7e2013-05-29 18:28:301692 if (!RenderThreadImpl::current()->layout_test_mode()) {
[email protected]8be1c582013-03-06 00:55:031693 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1694 SetPendingWindowRect(pos);
1695 } else {
1696 WebSize new_size(pos.width, pos.height);
[email protected]d9083762013-03-24 01:36:401697 Resize(new_size, new_size, overdraw_bottom_height_,
1698 WebRect(), is_fullscreen_, NO_RESIZE_ACK);
[email protected]8be1c582013-03-06 00:55:031699 view_screen_rect_ = pos;
1700 window_screen_rect_ = pos;
1701 }
initial.commit09911bf2008-07-26 23:55:291702 } else {
1703 initial_pos_ = pos;
1704 }
1705}
1706
[email protected]2533ce12009-05-09 00:02:241707void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1708 pending_window_rect_ = rect;
1709 pending_window_rect_count_++;
1710}
1711
[email protected]4873c7d2009-07-16 06:36:281712WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241713 if (pending_window_rect_count_) {
1714 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1715 // the RootWindowRect is probably going to return wrong results since the
1716 // browser may not have processed the Move yet. There isn't really anything
1717 // good to do in this case, and it shouldn't happen - since this size is
1718 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281719 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241720 }
1721
[email protected]80ad8622012-11-07 16:33:031722 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371723}
1724
[email protected]4873c7d2009-07-16 06:36:281725WebRect RenderWidget::windowResizerRect() {
1726 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191727}
1728
[email protected]fa7b1dc2010-06-23 17:53:041729void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031730 // To prevent this renderer process from sending unnecessary IPC messages to
1731 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041732 // only during the input method attached to the browser process is active.
1733 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291734}
1735
[email protected]58b48a0d2012-06-13 07:01:351736void RenderWidget::UpdateCompositionInfo(
1737 const ui::Range& range,
1738 const std::vector<gfx::Rect>& character_bounds) {
1739 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1740 return;
1741 composition_character_bounds_ = character_bounds;
1742 composition_range_ = range;
1743 Send(new ViewHostMsg_ImeCompositionRangeChanged(
1744 routing_id(), composition_range_, composition_character_bounds_));
1745}
1746
[email protected]fa7b1dc2010-06-23 17:53:041747void RenderWidget::OnImeSetComposition(
1748 const string16& text,
1749 const std::vector<WebCompositionUnderline>& underlines,
1750 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281751 if (!webwidget_)
1752 return;
[email protected]66fca5bc2013-05-23 06:58:291753 ImeEventGuard guard(this);
[email protected]d4cff272011-05-02 15:46:011754 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041755 text, WebVector<WebCompositionUnderline>(underlines),
1756 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011757 // Setting the IME composition was successful. Send the new composition
1758 // range to the browser.
1759 ui::Range range(ui::Range::InvalidRange());
1760 size_t location, length;
1761 if (webwidget_->compositionRange(&location, &length)) {
1762 range.set_start(location);
1763 range.set_end(location + length);
1764 }
1765 // The IME was cancelled via the Esc key, so just send back the caret.
1766 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1767 range.set_start(location);
1768 range.set_end(location + length);
1769 }
[email protected]58b48a0d2012-06-13 07:01:351770 std::vector<gfx::Rect> character_bounds;
1771 GetCompositionCharacterBounds(&character_bounds);
1772 UpdateCompositionInfo(range, character_bounds);
[email protected]d4cff272011-05-02 15:46:011773 } else {
[email protected]fa7b1dc2010-06-23 17:53:041774 // If we failed to set the composition text, then we need to let the browser
1775 // process to cancel the input method's ongoing composition session, to make
1776 // sure we are in a consistent state.
1777 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011778
1779 // Send an updated IME range with just the caret range.
1780 ui::Range range(ui::Range::InvalidRange());
1781 size_t location, length;
1782 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1783 range.set_start(location);
1784 range.set_end(location + length);
1785 }
[email protected]58b48a0d2012-06-13 07:01:351786 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]7f00efa2010-04-15 05:01:261787 }
[email protected]fa7b1dc2010-06-23 17:53:041788}
1789
[email protected]4de6d1692011-10-12 08:45:441790void RenderWidget::OnImeConfirmComposition(
1791 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041792 if (!webwidget_)
1793 return;
[email protected]66fca5bc2013-05-23 06:58:291794 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041795 handling_input_event_ = true;
1796 webwidget_->confirmComposition(text);
1797 handling_input_event_ = false;
1798
[email protected]d4cff272011-05-02 15:46:011799 // Send an updated IME range with just the caret range.
1800 ui::Range range(ui::Range::InvalidRange());
1801 size_t location, length;
1802 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1803 range.set_start(location);
1804 range.set_end(location + length);
1805 }
[email protected]58b48a0d2012-06-13 07:01:351806 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
initial.commit09911bf2008-07-26 23:55:291807}
1808
[email protected]948f7ab72010-05-28 23:48:081809// This message causes the renderer to render an image of the
1810// desired_size, regardless of whether the tab is hidden or not.
[email protected]3d9ec5052013-01-02 22:05:251811void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle,
1812 int tag,
1813 const gfx::Size& page_size,
1814 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001815 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1816 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251817 // Close our unused handle.
1818#if defined(OS_WIN)
1819 ::CloseHandle(dib_handle);
1820#elif defined(OS_MACOSX)
1821 base::SharedMemory::CloseHandle(dib_handle);
1822#endif
1823 }
[email protected]d65adb12010-04-28 17:26:491824 return;
[email protected]45c6aad32010-11-11 04:46:251825 }
[email protected]d65adb12010-04-28 17:26:491826
[email protected]948f7ab72010-05-28 23:48:081827 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491828 // If one of these is empty, then we just return the dib we were
1829 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091830 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491831 return;
1832 }
1833
1834 // Map the given DIB ID into this process, and unmap it at the end
1835 // of this function.
[email protected]45c6aad32010-11-11 04:46:251836 scoped_ptr<TransportDIB> paint_at_size_buffer(
1837 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301838
[email protected]4b01b962012-10-09 23:17:351839 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281840 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:351841 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281842 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:511843 gfx::Size canvas_size = page_size_in_pixel;
1844 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:491845 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:511846 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:491847 static_cast<float>(canvas_size.height());
1848
[email protected]ee8d6fd2010-05-26 17:05:481849 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491850 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1851 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481852 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491853
[email protected]36808ad2010-10-20 19:18:301854 scoped_ptr<skia::PlatformCanvas> canvas(
1855 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1856 canvas_size.height()));
[email protected]59383c782013-04-17 16:43:271857 if (!canvas) {
[email protected]36808ad2010-10-20 19:18:301858 NOTREACHED();
1859 return;
1860 }
1861
[email protected]d65adb12010-04-28 17:26:491862 // Reset bounds to what we actually received, but they should be the
1863 // same.
1864 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1865 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1866 bounds.set_width(canvas->getDevice()->width());
1867 bounds.set_height(canvas->getDevice()->height());
1868
1869 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081870 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491871 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1872
[email protected]948f7ab72010-05-28 23:48:081873 // Have to make sure we're laid out at the right size before
1874 // rendering.
1875 gfx::Size old_size = webwidget_->size();
1876 webwidget_->resize(page_size);
1877 webwidget_->layout();
1878
[email protected]d65adb12010-04-28 17:26:491879 // Paint the entire thing (using original bounds, not scaled bounds).
1880 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1881 canvas->restore();
1882
[email protected]948f7ab72010-05-28 23:48:081883 // Return the widget to its previous size.
1884 webwidget_->resize(old_size);
1885
[email protected]c88c9442010-07-19 18:55:091886 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491887}
1888
[email protected]51a49502013-03-23 01:50:191889void RenderWidget::OnSnapshot(const gfx::Rect& src_subrect) {
1890 SkBitmap snapshot;
1891
1892 if (OnSnapshotHelper(src_subrect, &snapshot)) {
1893 Send(new ViewHostMsg_Snapshot(routing_id(), true, snapshot));
1894 } else {
1895 Send(new ViewHostMsg_Snapshot(routing_id(), false, SkBitmap()));
1896 }
1897}
1898
1899bool RenderWidget::OnSnapshotHelper(const gfx::Rect& src_subrect,
1900 SkBitmap* snapshot) {
1901 base::TimeTicks beginning_time = base::TimeTicks::Now();
1902
1903 if (!webwidget_ || src_subrect.IsEmpty())
1904 return false;
1905
1906 gfx::Rect viewport_size = gfx::IntersectRects(
1907 src_subrect, gfx::Rect(physical_backing_size_));
1908
1909 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(
1910 skia::CreatePlatformCanvas(viewport_size.width(),
1911 viewport_size.height(),
1912 true,
1913 NULL,
1914 skia::RETURN_NULL_ON_FAILURE));
[email protected]59383c782013-04-17 16:43:271915 if (!canvas)
[email protected]51a49502013-03-23 01:50:191916 return false;
1917
1918 canvas->save();
1919 webwidget_->layout();
1920
1921 PaintRect(viewport_size, viewport_size.origin(), canvas.get());
1922 canvas->restore();
1923
1924 const SkBitmap& bitmap = skia::GetTopDevice(*canvas)->accessBitmap(false);
1925 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1926 return false;
1927
1928 UMA_HISTOGRAM_TIMES("Renderer4.Snapshot",
1929 base::TimeTicks::Now() - beginning_time);
1930 return true;
1931}
1932
[email protected]0bc1f572013-04-17 01:46:311933void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121934 // During shutdown we can just ignore this message.
1935 if (!webwidget_)
1936 return;
1937
[email protected]0bc1f572013-04-17 01:46:311938 // Even if the browser provides an empty damage rect, it's still expecting to
1939 // receive a repaint ack so just damage the entire widget bounds.
1940 if (size_to_paint.IsEmpty()) {
1941 size_to_paint = size_;
1942 }
1943
[email protected]ec7dc112008-08-06 05:30:121944 set_next_paint_is_repaint_ack();
[email protected]0bc1f572013-04-17 01:46:311945 if (is_accelerated_compositing_active_ && compositor_) {
1946 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]f98d7e3c2010-09-13 22:30:461947 } else {
1948 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1949 didInvalidateRect(repaint_rect);
1950 }
[email protected]ec7dc112008-08-06 05:30:121951}
1952
[email protected]4a9dba42013-04-29 18:24:221953void RenderWidget::OnSmoothScrollCompleted() {
1954 pending_smooth_scroll_gesture_.Run();
[email protected]0e241b4b2012-08-18 09:06:271955}
1956
[email protected]4873c7d2009-07-16 06:36:281957void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111958 if (!webwidget_)
1959 return;
[email protected]4873c7d2009-07-16 06:36:281960 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111961}
1962
[email protected]80ad8622012-11-07 16:33:031963void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1964 const gfx::Rect& window_screen_rect) {
1965 view_screen_rect_ = view_screen_rect;
1966 window_screen_rect_ = window_screen_rect;
1967 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1968}
1969
[email protected]105dffb42013-02-20 03:46:211970#if defined(OS_ANDROID)
1971void RenderWidget::OnImeBatchStateChanged(bool is_begin) {
1972 Send(new ViewHostMsg_ImeBatchStateChanged_ACK(routing_id(), is_begin));
1973}
[email protected]2384b6c2013-02-28 23:58:511974
1975void RenderWidget::OnShowImeIfNeeded() {
1976 UpdateTextInputState(SHOW_IME_IF_NEEDED);
1977}
[email protected]105dffb42013-02-20 03:46:211978#endif
1979
[email protected]468ac582012-11-20 00:53:191980void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1981 if (device_scale_factor_ == device_scale_factor)
1982 return;
1983
1984 device_scale_factor_ = device_scale_factor;
1985
1986 if (!is_accelerated_compositing_active_) {
1987 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
1988 } else {
1989 scheduleComposite();
1990 }
1991}
1992
[email protected]719b36f2010-12-22 20:36:461993webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151994 const gfx::Rect& paint_bounds,
1995 TransportDIB** dib,
1996 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:201997 gfx::Rect* clip,
1998 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:461999 // Bare RenderWidgets don't support optimized plugin painting.
2000 return NULL;
[email protected]ca4847f2010-09-24 05:39:152001}
2002
[email protected]ceb36f7d2012-10-31 18:33:242003gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:522004 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:242005 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:522006}
2007
[email protected]bee16aab2009-08-26 15:55:032008void RenderWidget::SetHidden(bool hidden) {
2009 if (is_hidden_ == hidden)
2010 return;
2011
2012 // The status has changed. Tell the RenderThread about it.
2013 is_hidden_ = hidden;
2014 if (is_hidden_)
[email protected]380244092011-10-07 17:26:272015 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:032016 else
[email protected]380244092011-10-07 17:26:272017 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:032018}
2019
[email protected]2b624c562011-10-27 22:58:262020void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262021 if (!webwidget_)
2022 return;
2023
2024 if (is_fullscreen_) {
2025 webwidget_->willExitFullScreen();
2026 } else {
2027 webwidget_->willEnterFullScreen();
2028 }
[email protected]2b624c562011-10-27 22:58:262029}
2030
2031void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262032 if (!webwidget_)
2033 return;
2034
2035 if (is_fullscreen_) {
2036 webwidget_->didEnterFullScreen();
2037 } else {
2038 webwidget_->didExitFullScreen();
2039 }
[email protected]2b624c562011-10-27 22:58:262040}
2041
[email protected]699ab0d2009-04-23 23:19:142042void RenderWidget::SetBackground(const SkBitmap& background) {
2043 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:462044
[email protected]699ab0d2009-04-23 23:19:142045 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:282046 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:142047}
2048
[email protected]674741932009-02-04 23:44:462049bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:052050 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462051}
2052
2053bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:052054 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462055}
2056
2057void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:052058 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462059}
2060
2061void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:052062 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:462063}
2064
2065void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:052066 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462067}
2068
[email protected]b18583c2012-12-18 06:55:272069static bool IsDateTimeInput(ui::TextInputType type) {
2070 return type == ui::TEXT_INPUT_TYPE_DATE ||
2071 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
2072 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
2073 type == ui::TEXT_INPUT_TYPE_MONTH ||
2074 type == ui::TEXT_INPUT_TYPE_TIME ||
2075 type == ui::TEXT_INPUT_TYPE_WEEK;
2076}
2077
[email protected]66fca5bc2013-05-23 06:58:292078
2079void RenderWidget::StartHandlingImeEvent() {
2080 DCHECK(!handling_ime_event_);
2081 handling_ime_event_ = true;
2082}
2083
2084void RenderWidget::FinishHandlingImeEvent() {
2085 DCHECK(handling_ime_event_);
2086 handling_ime_event_ = false;
2087 // While handling an ime event, text input state and selection bounds updates
2088 // are ignored. These must explicitly be updated once finished handling the
2089 // ime event.
2090 UpdateSelectionBounds();
2091 UpdateTextInputState(DO_NOT_SHOW_IME);
2092}
2093
[email protected]3306f262012-09-21 19:20:422094void RenderWidget::UpdateTextInputState(ShowIme show_ime) {
[email protected]e8f775f2013-02-14 21:00:502095 if (handling_ime_event_)
2096 return;
[email protected]3306f262012-09-21 19:20:422097 bool show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
2098 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:292099 return;
[email protected]ad26ef42011-06-17 07:59:452100 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:272101 if (IsDateTimeInput(new_type))
2102 return; // Not considered as a text input field in WebKit/Chromium.
2103
[email protected]5b739cb2012-08-21 20:35:212104 WebKit::WebTextInputInfo new_info;
2105 if (webwidget_)
2106 new_info = webwidget_->textInputInfo();
2107
[email protected]ad26ef42011-06-17 07:59:452108 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:212109
[email protected]3306f262012-09-21 19:20:422110 // Only sends text input params if they are changed or if the ime should be
2111 // shown.
2112 if (show_ime_if_needed || (text_input_type_ != new_type
2113 || text_input_info_ != new_info
2114 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:212115 ViewHostMsg_TextInputState_Params p;
2116 p.type = new_type;
2117 p.value = new_info.value.utf8();
2118 p.selection_start = new_info.selectionStart;
2119 p.selection_end = new_info.selectionEnd;
2120 p.composition_start = new_info.compositionStart;
2121 p.composition_end = new_info.compositionEnd;
2122 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:422123 p.show_ime_if_needed = show_ime_if_needed;
[email protected]5b739cb2012-08-21 20:35:212124 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
2125
2126 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:042127 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:452128 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:292129 }
initial.commit09911bf2008-07-26 23:55:292130}
2131
[email protected]7c8873e2013-02-05 08:03:012132void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2133 WebRect focus_webrect;
2134 WebRect anchor_webrect;
2135 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
2136 *focus = focus_webrect;
2137 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322138}
2139
[email protected]e99ef6f2011-10-16 01:13:002140void RenderWidget::UpdateSelectionBounds() {
2141 if (!webwidget_)
2142 return;
[email protected]66fca5bc2013-05-23 06:58:292143 if (handling_ime_event_)
2144 return;
[email protected]e99ef6f2011-10-16 01:13:002145
[email protected]7c8873e2013-02-05 08:03:012146 ViewHostMsg_SelectionBounds_Params params;
2147 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2148 if (selection_anchor_rect_ != params.anchor_rect ||
2149 selection_focus_rect_ != params.focus_rect) {
2150 selection_anchor_rect_ = params.anchor_rect;
2151 selection_focus_rect_ = params.focus_rect;
2152 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
[email protected]129b7382013-02-12 02:14:292153 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
[email protected]7c8873e2013-02-05 08:03:012154 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
[email protected]58b48a0d2012-06-13 07:01:352155 }
[email protected]e99ef6f2011-10-16 01:13:002156
[email protected]58b48a0d2012-06-13 07:01:352157 std::vector<gfx::Rect> character_bounds;
2158 GetCompositionCharacterBounds(&character_bounds);
2159 UpdateCompositionInfo(composition_range_, character_bounds);
2160}
2161
2162bool RenderWidget::ShouldUpdateCompositionInfo(
2163 const ui::Range& range,
2164 const std::vector<gfx::Rect>& bounds) {
2165 if (composition_range_ != range)
2166 return true;
2167 if (bounds.size() != composition_character_bounds_.size())
2168 return true;
2169 for (size_t i = 0; i < bounds.size(); ++i) {
2170 if (bounds[i] != composition_character_bounds_[i])
2171 return true;
2172 }
2173 return false;
[email protected]e99ef6f2011-10-16 01:13:002174}
2175
[email protected]73bf95812011-10-12 11:38:322176// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:452177COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
2178 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
2179COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
2180 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
2181COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
2182 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:182183COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
2184 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
2185COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
2186 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
2187COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
2188 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
2189COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
2190 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
2191COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
2192 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:002193COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
2194 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
2195COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
2196 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
2197COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
2198 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
2199COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
2200 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
2201COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
2202 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
2203COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
2204 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:012205COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
2206 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
2207COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
2208 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]8b4992e2013-03-01 15:42:152209COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeField) == \
2210 int(ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:452211
[email protected]5b739cb2012-08-21 20:35:212212ui::TextInputType RenderWidget::WebKitToUiTextInputType(
2213 WebKit::WebTextInputType type) {
2214 // Check the type is in the range representable by ui::TextInputType.
2215 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
2216 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
2217 return static_cast<ui::TextInputType>(type);
2218}
2219
[email protected]ad26ef42011-06-17 07:59:452220ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272221 if (webwidget_)
2222 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452223 return ui::TEXT_INPUT_TYPE_NONE;
2224}
2225
[email protected]58b48a0d2012-06-13 07:01:352226void RenderWidget::GetCompositionCharacterBounds(
2227 std::vector<gfx::Rect>* bounds) {
2228 DCHECK(bounds);
2229 bounds->clear();
2230}
2231
[email protected]ad26ef42011-06-17 07:59:452232bool RenderWidget::CanComposeInline() {
2233 return true;
[email protected]56ea1a62011-05-30 07:05:572234}
2235
[email protected]4873c7d2009-07-16 06:36:282236WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042237 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282238}
2239
[email protected]f660d9c2012-06-06 18:31:212240float RenderWidget::deviceScaleFactor() {
2241 return device_scale_factor_;
2242}
2243
[email protected]fa7b1dc2010-06-23 17:53:042244void RenderWidget::resetInputMethod() {
2245 if (!input_method_is_active_)
2246 return;
2247
2248 // If the last text input type is not None, then we should finish any
2249 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452250 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042251 // If a composition text exists, then we need to let the browser process
2252 // to cancel the input method's ongoing composition session.
2253 if (webwidget_->confirmComposition())
2254 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
2255 }
[email protected]d4cff272011-05-02 15:46:012256
2257 // Send an updated IME range with the current caret rect.
2258 ui::Range range(ui::Range::InvalidRange());
2259 size_t location, length;
2260 if (webwidget_->caretOrSelectionRange(&location, &length)) {
2261 range.set_start(location);
2262 range.set_end(location + length);
2263 }
[email protected]58b48a0d2012-06-13 07:01:352264
2265 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]fa7b1dc2010-06-23 17:53:042266}
2267
[email protected]c68c3e4e2013-01-24 00:36:562268void RenderWidget::didHandleGestureEvent(
2269 const WebGestureEvent& event,
2270 bool event_cancelled) {
2271#if defined(OS_ANDROID)
2272 if (event_cancelled)
2273 return;
2274 if (event.type == WebInputEvent::GestureTap ||
2275 event.type == WebInputEvent::GestureLongPress) {
2276 UpdateTextInputState(SHOW_IME_IF_NEEDED);
2277 }
2278#endif
2279}
2280
[email protected]f103ab72009-09-02 17:10:592281void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:502282 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292283 size_t i = 0;
2284 for (; i < plugin_window_moves_.size(); ++i) {
2285 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582286 if (move.rects_valid) {
2287 plugin_window_moves_[i] = move;
2288 } else {
2289 plugin_window_moves_[i].visible = move.visible;
2290 }
initial.commit09911bf2008-07-26 23:55:292291 break;
2292 }
2293 }
2294
2295 if (i == plugin_window_moves_.size())
2296 plugin_window_moves_.push_back(move);
2297}
[email protected]268654772009-08-06 23:02:042298
2299void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2300 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2301 i != plugin_window_moves_.end(); ++i) {
2302 if (i->window == window) {
2303 plugin_window_moves_.erase(i);
2304 break;
2305 }
2306 }
2307}
[email protected]67bfb83f2011-09-22 03:36:372308
[email protected]b63d58d2012-11-26 22:37:442309void RenderWidget::GetRenderingStats(
2310 WebKit::WebRenderingStatsImpl& stats) const {
[email protected]ba91a792013-02-06 09:48:282311 if (compositor_)
[email protected]635353c2013-03-06 09:11:202312 compositor_->GetRenderingStats(&stats.rendering_stats);
[email protected]b63d58d2012-11-26 22:37:442313
[email protected]62049562013-03-24 00:39:012314 stats.rendering_stats.animation_frame_count +=
2315 software_stats_.animation_frame_count;
2316 stats.rendering_stats.screen_frame_count +=
2317 software_stats_.screen_frame_count;
2318 stats.rendering_stats.total_paint_time +=
2319 software_stats_.total_paint_time;
2320 stats.rendering_stats.total_pixels_painted +=
2321 software_stats_.total_pixels_painted;
[email protected]fef5e3972012-08-07 03:59:472322}
2323
[email protected]e9ff79c2012-10-19 21:31:262324bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:522325 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
2326 if (!gpu_channel)
2327 return false;
2328
2329 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
2330}
2331
[email protected]24ed0432013-04-24 07:50:312332RenderWidgetCompositor* RenderWidget::compositor() const {
2333 return compositor_.get();
2334}
2335
[email protected]3639aa82013-06-04 11:00:042336void RenderWidget::OnSetBrowserRenderingStats(
2337 const BrowserRenderingStats& stats) {
2338 browser_rendering_stats_ = stats;
2339}
2340
2341void RenderWidget::GetBrowserRenderingStats(BrowserRenderingStats* stats) {
2342 *stats = browser_rendering_stats_;
2343}
2344
[email protected]0c2ebef2013-04-03 12:14:102345void RenderWidget::BeginSmoothScroll(
[email protected]0e241b4b2012-08-18 09:06:272346 bool down,
[email protected]ebd8b562012-10-09 14:44:292347 const SmoothScrollCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:192348 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:292349 int mouse_event_x,
2350 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:272351 DCHECK(!callback.is_null());
[email protected]267909d2012-10-20 04:36:192352
2353 ViewHostMsg_BeginSmoothScroll_Params params;
2354 params.scroll_down = down;
2355 params.pixels_to_scroll = pixels_to_scroll;
2356 params.mouse_event_x = mouse_event_x;
2357 params.mouse_event_y = mouse_event_y;
2358
[email protected]4a9dba42013-04-29 18:24:222359 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, params));
2360 pending_smooth_scroll_gesture_ = callback;
[email protected]a39ca1652012-07-13 21:30:582361}
2362
[email protected]67bfb83f2011-09-22 03:36:372363bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
2364 return false;
2365}
[email protected]c3d45532011-10-07 19:20:402366
[email protected]41d86852012-11-07 12:23:242367bool RenderWidget::WillHandleGestureEvent(
2368 const WebKit::WebGestureEvent& event) {
2369 return false;
2370}
2371
[email protected]ce6689f2013-03-29 12:52:552372void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2373 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2374}
2375
[email protected]3d5c243b2012-11-30 00:26:012376bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2377 return true;
2378}
2379
[email protected]3ae68c52013-04-12 06:10:052380WebGraphicsContext3DCommandBufferImpl* RenderWidget::CreateGraphicsContext3D(
[email protected]92fd8c02013-03-29 08:54:152381 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
[email protected]ed7defa2013-03-12 21:29:592382 if (!webwidget_)
2383 return NULL;
[email protected]8f746982013-03-21 06:28:032384 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
2385 new WebGraphicsContext3DCommandBufferImpl(
2386 surface_id(),
2387 GetURLForGraphicsContext3D(),
2388 RenderThreadImpl::current(),
2389 weak_ptr_factory_.GetWeakPtr()));
[email protected]ed7defa2013-03-12 21:29:592390
[email protected]990e4c212013-06-08 05:03:332391 if (!context->InitializeWithDefaultBufferSizes(
[email protected]8f746982013-03-21 06:28:032392 attributes,
2393 false /* bind generates resources */,
2394 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
2395 return NULL;
2396 return context.release();
[email protected]ed7defa2013-03-12 21:29:592397}
2398
[email protected]e9ff79c2012-10-19 21:31:262399} // namespace content