blob: 2692a93b71a98aacc3c80cbb020a1e307677fb6f [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]2255a9332013-06-17 05:12:3137#include "third_party/WebKit/public/web/WebCursorInfo.h"
38#include "third_party/WebKit/public/web/WebHelperPlugin.h"
39#include "third_party/WebKit/public/web/WebPagePopup.h"
40#include "third_party/WebKit/public/web/WebPopupMenu.h"
41#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
42#include "third_party/WebKit/public/web/WebRange.h"
43#include "third_party/WebKit/public/web/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]2255a9332013-06-17 05:12:3173#include "third_party/WebKit/public/web/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]f56c7872013-06-18 12:31:5779using WebKit::WebKeyboardEvent;
[email protected]6a8ddba52010-09-05 04:38:0680using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2881using WebKit::WebNavigationPolicy;
[email protected]a7547fb2012-03-08 04:43:4482using WebKit::WebPagePopup;
[email protected]e99ef6f2011-10-16 01:13:0083using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2884using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5985using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1886using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0187using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5288using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1989using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5290using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2891using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2492using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0493using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1894using WebKit::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:2695
[email protected]6a4d7f62013-01-07 21:32:1396namespace {
97const char* GetEventName(WebInputEvent::Type type) {
98#define CASE_TYPE(t) case WebInputEvent::t: return #t
99 switch(type) {
100 CASE_TYPE(Undefined);
101 CASE_TYPE(MouseDown);
102 CASE_TYPE(MouseUp);
103 CASE_TYPE(MouseMove);
104 CASE_TYPE(MouseEnter);
105 CASE_TYPE(MouseLeave);
106 CASE_TYPE(ContextMenu);
107 CASE_TYPE(MouseWheel);
108 CASE_TYPE(RawKeyDown);
109 CASE_TYPE(KeyDown);
110 CASE_TYPE(KeyUp);
111 CASE_TYPE(Char);
112 CASE_TYPE(GestureScrollBegin);
113 CASE_TYPE(GestureScrollEnd);
114 CASE_TYPE(GestureScrollUpdate);
115 CASE_TYPE(GestureFlingStart);
116 CASE_TYPE(GestureFlingCancel);
117 CASE_TYPE(GestureTap);
[email protected]1c43b0a2013-05-10 07:43:23118 CASE_TYPE(GestureTapUnconfirmed);
[email protected]6a4d7f62013-01-07 21:32:13119 CASE_TYPE(GestureTapDown);
120 CASE_TYPE(GestureTapCancel);
121 CASE_TYPE(GestureDoubleTap);
122 CASE_TYPE(GestureTwoFingerTap);
123 CASE_TYPE(GestureLongPress);
124 CASE_TYPE(GestureLongTap);
125 CASE_TYPE(GesturePinchBegin);
126 CASE_TYPE(GesturePinchEnd);
127 CASE_TYPE(GesturePinchUpdate);
128 CASE_TYPE(TouchStart);
129 CASE_TYPE(TouchMove);
130 CASE_TYPE(TouchEnd);
131 CASE_TYPE(TouchCancel);
[email protected]3ec08ed2013-01-11 15:59:57132 default:
133 // Must include default to let WebKit::WebInputEvent add new event types
134 // before they're added here.
135 DLOG(WARNING) << "Unhandled WebInputEvent type in GetEventName.\n";
136 break;
[email protected]6a4d7f62013-01-07 21:32:13137 }
138#undef CASE_TYPE
[email protected]3ec08ed2013-01-11 15:59:57139 return "";
[email protected]6a4d7f62013-01-07 21:32:13140}
141}
[email protected]e9ff79c2012-10-19 21:31:26142namespace content {
[email protected]62cb33cae2009-03-27 23:30:22143
[email protected]6fd35b72012-03-01 19:46:41144RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]842f10652012-06-06 01:54:04145 const WebKit::WebScreenInfo& screen_info,
[email protected]14392a52012-05-02 20:28:44146 bool swapped_out)
initial.commit09911bf2008-07-26 23:55:29147 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56148 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:11149 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:29150 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30151 init_complete_(false),
[email protected]b4d08452010-10-05 17:34:35152 current_paint_buf_(NULL),
[email protected]d9083762013-03-24 01:36:40153 overdraw_bottom_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29154 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:06155 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:05156 update_reply_pending_(false),
[email protected]847a2582013-03-09 02:29:51157 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09158 need_update_rect_for_auto_resize_(false),
[email protected]65225772011-05-12 21:10:24159 using_asynchronous_swapbuffers_(false),
160 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:29161 did_show_(false),
initial.commit09911bf2008-07-26 23:55:29162 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:09163 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:29164 needs_repainting_on_restore_(false),
165 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49166 handling_input_event_(false),
[email protected]e8f775f2013-02-14 21:00:50167 handling_ime_event_(false),
[email protected]661eb9d2009-02-03 02:11:48168 closing_(false),
[email protected]14392a52012-05-02 20:28:44169 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04170 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45171 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
172 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12173 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48174 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12175 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50176 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21177 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07178 invalidation_task_posted_(false),
[email protected]842f10652012-06-06 01:54:04179 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52180 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]ed7defa2013-03-12 21:29:59181 is_threaded_compositing_enabled_(false),
[email protected]69e797f2013-04-30 01:10:22182 weak_ptr_factory_(this) {
[email protected]8b3f0eb2012-05-03 19:15:05183 if (!swapped_out)
184 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27185 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18186 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
187 switches::kDisableGpuVsync);
[email protected]cb6430932012-10-31 00:53:36188 is_threaded_compositing_enabled_ =
189 CommandLine::ForCurrentProcess()->HasSwitch(
190 switches::kEnableThreadedCompositing);
initial.commit09911bf2008-07-26 23:55:29191}
192
193RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11194 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21195 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35196 if (current_paint_buf_) {
197 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
198 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29199 }
[email protected]992db4c2011-05-12 15:37:15200 // If we are swapped out, we have released already.
201 if (!is_swapped_out_)
202 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29203}
204
[email protected]484955942010-08-19 16:13:18205// static
[email protected]8085dbc82008-09-26 22:53:44206RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:04207 WebKit::WebPopupType popup_type,
208 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29209 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41210 scoped_refptr<RenderWidget> widget(
[email protected]842f10652012-06-06 01:54:04211 new RenderWidget(popup_type, screen_info, false));
[email protected]a635f942012-12-07 10:34:29212 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46213 return widget.get();
[email protected]a635f942012-12-07 10:34:29214 }
215 return NULL;
initial.commit09911bf2008-07-26 23:55:29216}
217
[email protected]484955942010-08-19 16:13:18218// static
219WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
220 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03221 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18222 break;
223 case WebKit::WebPopupTypeSelect:
224 case WebKit::WebPopupTypeSuggestion:
225 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44226 case WebKit::WebPopupTypePage:
227 return WebPagePopup::create(render_widget);
[email protected]4b1146bc2012-07-10 18:46:03228 case WebKit::WebPopupTypeHelperPlugin:
229 return WebKit::WebHelperPlugin::create(render_widget);
[email protected]484955942010-08-19 16:13:18230 default:
231 NOTREACHED();
232 }
233 return NULL;
234}
235
[email protected]a635f942012-12-07 10:34:29236bool RenderWidget::Init(int32 opener_id) {
237 return DoInit(opener_id,
238 RenderWidget::CreateWebWidget(this),
239 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
240 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18241}
242
[email protected]a635f942012-12-07 10:34:29243bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06244 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18245 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29246 DCHECK(!webwidget_);
247
248 if (opener_id != MSG_ROUTING_NONE)
249 opener_id_ = opener_id;
250
[email protected]484955942010-08-19 16:13:18251 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29252
[email protected]380244092011-10-07 17:26:27253 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29254 if (result) {
[email protected]380244092011-10-07 17:26:27255 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29256 // Take a reference on behalf of the RenderThread. This will be balanced
257 // when we receive ViewMsg_Close.
258 AddRef();
[email protected]a635f942012-12-07 10:34:29259 return true;
initial.commit09911bf2008-07-26 23:55:29260 } else {
[email protected]a635f942012-12-07 10:34:29261 // The above Send can fail when the tab is closing.
262 return false;
initial.commit09911bf2008-07-26 23:55:29263 }
264}
265
[email protected]fc4404d2012-11-07 19:53:30266// This is used to complete pending inits and non-pending inits.
267void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29268 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29269
[email protected]fc4404d2012-11-07 19:53:30270 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42271
[email protected]8926c602013-01-23 05:32:06272 if (webwidget_ && is_threaded_compositing_enabled_) {
273 webwidget_->enterForceCompositingMode(true);
274 }
[email protected]ba91a792013-02-06 09:48:28275 if (compositor_) {
276 compositor_->setSurfaceReady();
[email protected]479b0172012-10-29 19:27:09277 }
[email protected]05a980d7a2012-02-07 22:16:42278 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29279
[email protected]6de74452009-02-25 18:04:59280 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29281}
282
[email protected]992db4c2011-05-12 15:37:15283void RenderWidget::SetSwappedOut(bool is_swapped_out) {
284 // We should only toggle between states.
285 DCHECK(is_swapped_out_ != is_swapped_out);
286 is_swapped_out_ = is_swapped_out;
287
288 // If we are swapping out, we will call ReleaseProcess, allowing the process
289 // to exit if all of its RenderViews are swapped out. We wait until the
290 // WasSwappedOut call to do this, to avoid showing the sad tab.
291 // If we are swapping in, we call AddRefProcess to prevent the process from
292 // exiting.
293 if (!is_swapped_out)
294 RenderProcess::current()->AddRefProcess();
295}
296
[email protected]34bb3ac2013-03-08 02:41:28297bool RenderWidget::AllowPartialSwap() const {
298 return true;
299}
300
[email protected]c8cbae72013-05-23 10:45:03301bool RenderWidget::UsingSynchronousRendererCompositor() const {
[email protected]ccc1722e2013-05-06 19:43:07302#if defined(OS_ANDROID)
[email protected]913d99a2013-05-31 07:16:07303 return SynchronousCompositorFactory::GetInstance() != NULL;
304#else
[email protected]ccc1722e2013-05-06 19:43:07305 return false;
[email protected]913d99a2013-05-31 07:16:07306#endif
[email protected]ccc1722e2013-05-06 19:43:07307}
308
[email protected]a95986a82010-12-24 06:19:28309bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
310 bool handled = true;
311 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15312 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22313 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
314 OnCursorVisibilityChange)
[email protected]c084330e02013-04-27 01:08:15315 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
316 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]a95986a82010-12-24 06:19:28317 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
318 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
319 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54320 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28321 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41322 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]992db4c2011-05-12 15:37:15323 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28324 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]ed7defa2013-03-12 21:29:59325 IPC_MESSAGE_HANDLER(ViewMsg_SwapBuffers_ACK,
326 OnViewContextSwapBuffersComplete)
[email protected]a95986a82010-12-24 06:19:28327 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
328 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
329 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]3d9ec5052013-01-02 22:05:25330 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnPaintAtSize)
331 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
332 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, OnSmoothScrollCompleted)
[email protected]a95986a82010-12-24 06:19:28333 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
334 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03335 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]105dffb42013-02-20 03:46:21336#if defined(OS_ANDROID)
337 IPC_MESSAGE_HANDLER(ViewMsg_ImeBatchStateChanged, OnImeBatchStateChanged)
[email protected]2384b6c2013-02-28 23:58:51338 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21339#endif
[email protected]51a49502013-03-23 01:50:19340 IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot)
[email protected]3639aa82013-06-04 11:00:04341 IPC_MESSAGE_HANDLER(ViewMsg_SetBrowserRenderingStats,
342 OnSetBrowserRenderingStats)
[email protected]a95986a82010-12-24 06:19:28343 IPC_MESSAGE_UNHANDLED(handled = false)
344 IPC_END_MESSAGE_MAP()
345 return handled;
346}
initial.commit09911bf2008-07-26 23:55:29347
348bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15349 // Don't send any messages after the browser has told us to close, and filter
350 // most outgoing messages while swapped out.
351 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26352 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11353 closing_) {
initial.commit09911bf2008-07-26 23:55:29354 delete message;
355 return false;
356 }
357
358 // If given a messsage without a routing ID, then assign our routing ID.
359 if (message->routing_id() == MSG_ROUTING_NONE)
360 message->set_routing_id(routing_id_);
361
[email protected]380244092011-10-07 17:26:27362 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44363}
364
[email protected]61e2b3cc2012-03-02 16:13:34365void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44366 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40367 float overdraw_bottom_height,
[email protected]61e2b3cc2012-03-02 16:13:34368 const gfx::Rect& resizer_rect,
369 bool is_fullscreen,
370 ResizeAck resize_ack) {
[email protected]1c0008842013-06-06 08:35:48371 if (!RenderThreadImpl::current() || // Will be NULL during unit tests.
372 !RenderThreadImpl::current()->layout_test_mode()) {
373 // A resize ack shouldn't be requested if we have not ACK'd the previous
374 // one.
375 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
376 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
377 }
initial.commit09911bf2008-07-26 23:55:29378
[email protected]61e2b3cc2012-03-02 16:13:34379 // Ignore this during shutdown.
380 if (!webwidget_)
381 return;
382
[email protected]d9083762013-03-24 01:36:40383 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44384 compositor_->setViewportSize(new_size, physical_backing_size);
[email protected]d9083762013-03-24 01:36:40385 compositor_->SetOverdrawBottomHeight(overdraw_bottom_height);
386 }
[email protected]60d47ac2013-03-01 23:42:44387
[email protected]dade8992013-03-04 07:34:34388 physical_backing_size_ = physical_backing_size;
[email protected]d9083762013-03-24 01:36:40389 overdraw_bottom_height_ = overdraw_bottom_height;
[email protected]61e2b3cc2012-03-02 16:13:34390 resizer_rect_ = resizer_rect;
391
392 // NOTE: We may have entered fullscreen mode without changing our size.
393 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
394 if (fullscreen_change)
395 WillToggleFullscreen();
396 is_fullscreen_ = is_fullscreen;
397
398 if (size_ != new_size) {
399 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34400 needs_repainting_on_restore_ = false;
401
402 size_ = new_size;
403
404 paint_aggregator_.ClearPendingUpdate();
405
406 // When resizing, we want to wait to paint before ACK'ing the resize. This
407 // ensures that we only resize as fast as we can paint. We only need to
408 // send an ACK if we are resized to a non-empty rect.
409 webwidget_->resize(new_size);
[email protected]0b70dbe2013-05-10 19:06:32410
[email protected]92201e32013-06-08 06:14:52411 if (!RenderThreadImpl::current() || // Will be NULL during unit tests.
412 !RenderThreadImpl::current()->layout_test_mode()) {
413 // Resize should have caused an invalidation of the entire view.
414 DCHECK(new_size.IsEmpty() || is_accelerated_compositing_active_ ||
415 paint_aggregator_.HasPendingUpdate());
416 }
[email protected]1c0008842013-06-06 08:35:48417 } else if (!RenderThreadImpl::current() || // Will be NULL during unit tests.
418 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]632c4382013-05-15 08:58:45419 resize_ack = NO_RESIZE_ACK;
420 }
421
422 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
423 // For empty size or empty physical_backing_size, there is no next paint
424 // (along with which to send the ack) until they are set to non-empty.
[email protected]ff475a322012-03-14 00:05:35425 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34426 }
427
[email protected]20fbfc22013-05-08 20:50:58428 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45429 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58430 set_next_paint_is_resize_ack();
431
[email protected]61e2b3cc2012-03-02 16:13:34432 if (fullscreen_change)
433 DidToggleFullscreen();
434
435 // If a resize ack is requested and it isn't set-up, then no more resizes will
436 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45437 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29438}
439
440void RenderWidget::OnClose() {
441 if (closing_)
442 return;
443 closing_ = true;
444
445 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03446 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27447 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03448 SetHidden(false);
449 }
initial.commit09911bf2008-07-26 23:55:29450
initial.commit09911bf2008-07-26 23:55:29451 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25452 // now. Post a task that only gets invoked when there are no nested message
453 // loops.
[email protected]dd32b1272013-05-04 14:17:11454 base::MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29455 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25456
457 // Balances the AddRef taken when we called AddRoute.
458 Release();
initial.commit09911bf2008-07-26 23:55:29459}
460
[email protected]61e2b3cc2012-03-02 16:13:34461// Got a response from the browser after the renderer decided to create a new
462// view.
[email protected]fc4404d2012-11-07 19:53:30463void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34464 DCHECK(routing_id_ != MSG_ROUTING_NONE);
465
[email protected]fc4404d2012-11-07 19:53:30466 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34467}
468
[email protected]0fdd5012013-05-29 08:05:56469void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
470 screen_info_ = params.screen_info;
471 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
472 Resize(params.new_size, params.physical_backing_size,
473 params.overdraw_bottom_height, params.resizer_rect,
474 params.is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29475}
476
[email protected]b5913d72012-02-07 22:26:54477void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
478 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59479 gfx::Rect view_rect(size_);
480
[email protected]ce112fe2012-10-29 22:52:18481 gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_);
[email protected]b9769d82012-02-10 00:23:59482 if (!old_damage_rect.IsEmpty())
483 paint_aggregator_.InvalidateRect(old_damage_rect);
484
[email protected]ce112fe2012-10-29 22:52:18485 gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect);
[email protected]b9769d82012-02-10 00:23:59486 if (!new_damage_rect.IsEmpty())
487 paint_aggregator_.InvalidateRect(new_damage_rect);
488
[email protected]b5913d72012-02-07 22:26:54489 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59490
[email protected]b5913d72012-02-07 22:26:54491 if (webwidget_)
492 webwidget_->didChangeWindowResizerRect();
493 }
494}
495
initial.commit09911bf2008-07-26 23:55:29496void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31497 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29498 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03499 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29500}
501
[email protected]9e2e4632012-07-27 16:38:41502void RenderWidget::OnWasShown(bool needs_repainting) {
503 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29504 // During shutdown we can just ignore this message.
505 if (!webwidget_)
506 return;
507
508 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03509 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29510
511 if (!needs_repainting && !needs_repainting_on_restore_)
512 return;
513 needs_repainting_on_restore_ = false;
514
[email protected]d65adb12010-04-28 17:26:49515 // Tag the next paint as a restore ack, which is picked up by
516 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29517 set_next_paint_is_restore_ack();
518
519 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56520 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46521 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
522 } else {
523 scheduleComposite();
524 }
initial.commit09911bf2008-07-26 23:55:29525}
526
[email protected]992db4c2011-05-12 15:37:15527void RenderWidget::OnWasSwappedOut() {
528 // If we have been swapped out and no one else is using this process,
529 // it's safe to exit now. If we get swapped back in, we will call
530 // AddRefProcess in SetSwappedOut.
531 if (is_swapped_out_)
532 RenderProcess::current()->ReleaseProcess();
533}
534
[email protected]53d3f302009-12-21 04:42:05535void RenderWidget::OnRequestMoveAck() {
536 DCHECK(pending_window_rect_count_);
537 pending_window_rect_count_--;
538}
539
540void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58541 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21542 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05543 update_reply_pending_ = false;
544
[email protected]b4d08452010-10-05 17:34:35545 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
546 // have no current paint buffer.
547 if (current_paint_buf_) {
548 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
549 current_paint_buf_ = NULL;
550 }
551
[email protected]65225772011-05-12 21:10:24552 // If swapbuffers is still pending, then defer the update until the
553 // swapbuffers occurs.
554 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
555 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
556 return;
557 }
558
[email protected]29ed96a2012-02-04 18:12:16559 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18560 if (!is_accelerated_compositing_active_) {
561 DidFlushPaint();
562 }
[email protected]a2f6bc112009-06-27 16:27:25563
initial.commit09911bf2008-07-26 23:55:29564 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24565 DoDeferredUpdateAndSendInputAck();
566}
567
[email protected]d0be63772011-12-20 23:18:04568bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]ed7defa2013-03-12 21:29:59569 // Contexts using the command buffer support asynchronous swapbuffers.
570 // See RenderWidget::CreateOutputSurface().
[email protected]cadac622013-06-11 16:46:36571 if (RenderThreadImpl::current()->compositor_message_loop_proxy().get())
[email protected]ed7defa2013-03-12 21:29:59572 return false;
573
574 return true;
575}
576
577GURL RenderWidget::GetURLForGraphicsContext3D() {
578 return GURL();
[email protected]65225772011-05-12 21:10:24579}
580
[email protected]479b0172012-10-29 19:27:09581bool RenderWidget::ForceCompositingModeEnabled() {
582 return false;
583}
584
[email protected]ba91a792013-02-06 09:48:28585scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface() {
[email protected]c3e32ed42013-05-02 05:07:13586 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]a1811b8912013-05-09 15:35:19587
588#if defined(OS_ANDROID)
[email protected]913d99a2013-05-31 07:16:07589 if (SynchronousCompositorFactory* factory =
590 SynchronousCompositorFactory::GetInstance()) {
591 return factory->CreateOutputSurface(routing_id());
[email protected]a1811b8912013-05-09 15:35:19592 }
593#endif
594
[email protected]8bbe3a92013-05-12 00:58:35595 if (command_line.HasSwitch(switches::kEnableSoftwareCompositingGLAdapter)) {
596 return scoped_ptr<cc::OutputSurface>(
597 new CompositorOutputSurface(routing_id(), NULL,
[email protected]36e5ff12013-06-11 12:19:29598 new CompositorSoftwareOutputDevice(), true));
[email protected]8bbe3a92013-05-12 00:58:35599 }
600
[email protected]ed7defa2013-03-12 21:29:59601 // Explicitly disable antialiasing for the compositor. As of the time of
602 // this writing, the only platform that supported antialiasing for the
603 // compositor was Mac OS X, because the on-screen OpenGL context creation
604 // code paths on Windows and Linux didn't yet have multisampling support.
605 // Mac OS X essentially always behaves as though it's rendering offscreen.
606 // Multisampling has a heavy cost especially on devices with relatively low
607 // fill rate like most notebooks, and the Mac implementation would need to
608 // be optimized to resolve directly into the IOSurface shared between the
609 // GPU and browser processes. For these reasons and to avoid platform
610 // disparities we explicitly disable antialiasing.
611 WebKit::WebGraphicsContext3D::Attributes attributes;
612 attributes.antialias = false;
613 attributes.shareResources = true;
614 attributes.noAutomaticFlushes = true;
[email protected]a6886502013-05-16 20:59:18615 attributes.depth = false;
616 attributes.stencil = false;
[email protected]bec084292013-05-21 21:31:44617 if (command_line.HasSwitch(cc::switches::kForceDirectLayerDrawing))
618 attributes.stencil = true;
[email protected]3ae68c52013-04-12 06:10:05619 WebGraphicsContext3DCommandBufferImpl* context =
620 CreateGraphicsContext3D(attributes);
[email protected]8bbe3a92013-05-12 00:58:35621 if (!context)
622 return scoped_ptr<cc::OutputSurface>();
[email protected]ed7defa2013-03-12 21:29:59623
[email protected]36e5ff12013-06-11 12:19:29624 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) {
625 DCHECK(is_threaded_compositing_enabled_);
626 return scoped_ptr<cc::OutputSurface>(
627 new DelegatedCompositorOutputSurface(routing_id(), context, NULL));
628 }
629 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) {
630 DCHECK(is_threaded_compositing_enabled_);
631 return scoped_ptr<cc::OutputSurface>(
632 new MailboxOutputSurface(routing_id(), context, NULL));
633 }
634 return scoped_ptr<cc::OutputSurface>(
635 new CompositorOutputSurface(routing_id(), context, NULL, false));
[email protected]ba91a792013-02-06 09:48:28636}
637
[email protected]ed7defa2013-03-12 21:29:59638void RenderWidget::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24639 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21640 while (!updates_pending_swap_.empty()) {
641 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
642 updates_pending_swap_.pop_front();
643 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
644 // compositing pass, hence doesn't require an UpdateRect message.
645 if (msg)
646 Send(msg);
647 }
[email protected]65225772011-05-12 21:10:24648 num_swapbuffers_complete_pending_ = 0;
649 using_asynchronous_swapbuffers_ = false;
650 // Schedule another frame so the compositor learns about it.
651 scheduleComposite();
652}
653
[email protected]ed7defa2013-03-12 21:29:59654void RenderWidget::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:08655 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21656
657 if (using_asynchronous_swapbuffers_) {
658 ViewHostMsg_UpdateRect* msg = NULL;
659 // pending_update_params_ can be NULL if the swap doesn't correspond to an
660 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
661 // message.
[email protected]59383c782013-04-17 16:43:27662 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:21663 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
664 pending_update_params_.reset();
665 }
666 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08667 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21668 }
[email protected]37a6f302011-07-11 23:43:08669}
670
[email protected]ed7defa2013-03-12 21:29:59671void RenderWidget::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24672 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16673
[email protected]404939f2012-06-01 04:06:18674 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16675 DidFlushPaint();
676
[email protected]65225772011-05-12 21:10:24677 // When compositing deactivates, we reset the swapbuffers pending count. The
678 // swapbuffers acks may still arrive, however.
679 if (num_swapbuffers_complete_pending_ == 0) {
680 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
681 return;
682 }
[email protected]aa4117f2011-12-09 22:19:21683 DCHECK(!updates_pending_swap_.empty());
684 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
685 updates_pending_swap_.pop_front();
686 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
687 // compositing pass, hence doesn't require an UpdateRect message.
688 if (msg)
689 Send(msg);
[email protected]65225772011-05-12 21:10:24690 num_swapbuffers_complete_pending_--;
691
692 // If update reply is still pending, then defer the update until that reply
693 // occurs.
[email protected]d0be63772011-12-20 23:18:04694 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24695 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
696 return;
697 }
698
699 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06700 // when we were previously rendering. However, if an invalidation task is not
701 // posted, there may be software rendering work pending. In that case, don't
702 // early out.
703 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24704 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
705 return;
706 }
707
[email protected]cc66e682012-10-02 06:48:18708 // Do not call DoDeferredUpdate unless there's animation work to be done or
709 // a real invalidation. This prevents rendering in response to a swapbuffers
710 // callback coming back after we've navigated away from the page that
711 // generated it.
712 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
713 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
714 return;
715 }
716
[email protected]65225772011-05-12 21:10:24717 // Continue painting if necessary...
718 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29719}
720
[email protected]0dea1652012-12-14 00:09:09721void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
[email protected]4b157662013-05-29 04:05:05722 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:09723 bool is_keyboard_shortcut) {
[email protected]5dd768212009-08-13 23:34:49724 handling_input_event_ = true;
[email protected]0dea1652012-12-14 00:09:09725 if (!input_event) {
[email protected]5dd768212009-08-13 23:34:49726 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29727 return;
[email protected]5dd768212009-08-13 23:34:49728 }
initial.commit09911bf2008-07-26 23:55:29729
[email protected]b4841e1c2013-05-16 22:30:10730 const char* const event_name = GetEventName(input_event->type);
731 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent",
732 "event", event_name);
733
[email protected]c2eaa8f2013-05-10 02:41:55734 if (compositor_)
735 compositor_->SetLatencyInfo(latency_info);
[email protected]256737c2013-06-08 04:39:10736 else
737 latency_info_.MergeWith(latency_info);
[email protected]c2eaa8f2013-05-10 02:41:55738
[email protected]6a4d7f62013-01-07 21:32:13739 base::TimeDelta now = base::TimeDelta::FromInternalValue(
740 base::TimeTicks::Now().ToInternalValue());
741
742 int64 delta = static_cast<int64>(
743 (now.InSecondsF() - input_event->timeStampSeconds) *
744 base::Time::kMicrosecondsPerSecond);
745 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer", delta, 0, 1000000, 100);
[email protected]de415552013-01-23 04:12:17746 base::HistogramBase* counter_for_type =
[email protected]bafdc5d52013-02-27 18:18:48747 base::Histogram::FactoryGet(
[email protected]b4841e1c2013-05-16 22:30:10748 base::StringPrintf("Event.Latency.Renderer.%s", event_name),
[email protected]bafdc5d52013-02-27 18:18:48749 0,
750 1000000,
[email protected]6a4d7f62013-01-07 21:32:13751 100,
[email protected]de415552013-01-23 04:12:17752 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]bafdc5d52013-02-27 18:18:48753 counter_for_type->Add(delta);
[email protected]6a4d7f62013-01-07 21:32:13754
[email protected]67bfb83f2011-09-22 03:36:37755 bool prevent_default = false;
756 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26757 const WebMouseEvent& mouse_event =
758 *static_cast<const WebMouseEvent*>(input_event);
759 TRACE_EVENT2("renderer", "HandleMouseMove",
760 "x", mouse_event.x, "y", mouse_event.y);
761 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37762 }
763
[email protected]f56c7872013-06-18 12:31:57764 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
765 const WebKeyboardEvent& key_event =
766 *static_cast<const WebKeyboardEvent*>(input_event);
767 prevent_default = WillHandleKeyEvent(key_event);
768 }
769
[email protected]41d86852012-11-07 12:23:24770 if (WebInputEvent::isGestureEventType(input_event->type)) {
771 const WebGestureEvent& gesture_event =
772 *static_cast<const WebGestureEvent*>(input_event);
773 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
774 }
775
[email protected]3ebcc7c2013-01-09 05:34:46776 if (input_event->type == WebInputEvent::GestureTap ||
777 input_event->type == WebInputEvent::GestureLongPress)
778 resetInputMethod();
779
[email protected]67bfb83f2011-09-22 03:36:37780 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12781 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
782 suppress_next_char_events_ = false;
783 if (!processed && webwidget_)
784 processed = webwidget_->handleInputEvent(*input_event);
785 }
786
787 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
788 // it's not processed by webkit, then we need to suppress the upcoming Char
789 // events.
790 if (!processed && is_keyboard_shortcut)
791 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29792
[email protected]3d5c243b2012-11-30 00:26:01793 InputEventAckState ack_result = processed ?
794 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
795 if (!processed && input_event->type == WebInputEvent::TouchStart) {
796 const WebTouchEvent& touch_event =
797 *static_cast<const WebTouchEvent*>(input_event);
798 ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ?
799 INPUT_EVENT_ACK_STATE_NOT_CONSUMED :
800 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
801 }
802
[email protected]a9fb30aa2011-10-06 06:58:46803 IPC::Message* response =
[email protected]c084330e02013-04-27 01:08:15804 new InputHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
805 ack_result);
[email protected]3391a0772012-03-28 00:32:07806 bool event_type_gets_rate_limited =
807 input_event->type == WebInputEvent::MouseMove ||
808 input_event->type == WebInputEvent::MouseWheel ||
809 WebInputEvent::isTouchEventType(input_event->type);
[email protected]8926c602013-01-23 05:32:06810
811 bool frame_pending = paint_aggregator_.HasPendingUpdate();
812 if (is_accelerated_compositing_active_) {
[email protected]ba91a792013-02-06 09:48:28813 frame_pending = compositor_ &&
814 compositor_->commitRequested();
[email protected]8926c602013-01-23 05:32:06815 }
816
[email protected]9a8ce7f92013-06-11 12:39:49817 if (event_type_gets_rate_limited && frame_pending && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24818 // We want to rate limit the input events in this case, so we'll wait for
819 // painting to finish before ACKing this message.
[email protected]59383c782013-04-17 16:43:27820 if (pending_input_event_ack_) {
[email protected]353a34c2010-05-28 23:35:17821 // As two different kinds of events could cause us to postpone an ack
822 // we send it now, if we have one pending. The Browser should never
823 // send us the same kind of event we are delaying the ack for.
824 Send(pending_input_event_ack_.release());
825 }
[email protected]12fbad812009-09-01 18:21:24826 pending_input_event_ack_.reset(response);
827 } else {
828 Send(response);
829 }
830
[email protected]3306f262012-09-21 19:20:42831#if defined(OS_ANDROID)
832 // Allow the IME to be shown when the focus changes as a consequence
833 // of a processed touch end event.
834 if (input_event->type == WebInputEvent::TouchEnd && processed)
835 UpdateTextInputState(SHOW_IME_IF_NEEDED);
836#endif
837
[email protected]5dd768212009-08-13 23:34:49838 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48839
[email protected]67bfb83f2011-09-22 03:36:37840 if (!prevent_default) {
841 if (WebInputEvent::isKeyboardEventType(input_event->type))
842 DidHandleKeyEvent();
843 if (WebInputEvent::isMouseEventType(input_event->type))
844 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24845 if (WebInputEvent::isTouchEventType(input_event->type))
846 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37847 }
initial.commit09911bf2008-07-26 23:55:29848}
849
[email protected]34202de2013-05-06 23:36:22850void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
851 if (webwidget_)
852 webwidget_->setCursorVisibilityState(is_visible);
853}
854
initial.commit09911bf2008-07-26 23:55:29855void RenderWidget::OnMouseCaptureLost() {
856 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28857 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29858}
859
860void RenderWidget::OnSetFocus(bool enable) {
861 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33862 if (webwidget_)
863 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29864}
865
866void RenderWidget::ClearFocus() {
867 // We may have got the focus from the browser before this gets processed, in
868 // which case we do not want to unfocus ourself.
869 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28870 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29871}
872
[email protected]2d5d09d52009-06-15 14:29:21873void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00874 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21875 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06876 TRACE_EVENT2("renderer", "PaintRect",
877 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:45878
879 const bool kEnableGpuBenchmarking =
880 CommandLine::ForCurrentProcess()->HasSwitch(
881 switches::kEnableGpuBenchmarking);
[email protected]4fb66842009-12-04 21:41:00882 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21883
884 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00885 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
886 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03887
[email protected]699ab0d2009-04-23 23:19:14888 // If there is a custom background, tile it.
889 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14890 SkPaint paint;
[email protected]4e29afd2012-12-04 04:07:11891 skia::RefPtr<SkShader> shader = skia::AdoptRef(
892 SkShader::CreateBitmapShader(background_,
893 SkShader::kRepeat_TileMode,
894 SkShader::kRepeat_TileMode));
895 paint.setShader(shader.get());
[email protected]fb10ec5b2011-10-24 17:54:20896
897 // Use kSrc_Mode to handle background_ transparency properly.
898 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
899
900 // Canvas could contain multiple update rects. Clip to given rect so that
901 // we don't accidentally clear other update rects.
902 canvas->save();
[email protected]aa7e7a12013-02-22 13:37:44903 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]1835b9e2012-02-28 13:12:48904 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14905 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20906 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14907 }
908
[email protected]719b36f2010-12-22 20:36:46909 // First see if this rect is a plugin that can paint itself faster.
910 TransportDIB* optimized_dib = NULL;
911 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:20912 float dib_scale_factor;
[email protected]719b36f2010-12-22 20:36:46913 webkit::ppapi::PluginInstance* optimized_instance =
914 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
915 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:20916 &optimized_copy_rect,
917 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:46918 if (optimized_instance) {
919 // This plugin can be optimize-painted and we can just ask it to paint
920 // itself. We don't actually need the TransportDIB in this case.
921 //
922 // This is an optimization for PPAPI plugins that know they're on top of
923 // the page content. If this rect is inside such a plugin, we can save some
924 // time and avoid re-rendering the page content which we know will be
925 // covered by the plugin later (this time can be significant, especially
926 // for a playing movie that is invalidating a lot).
927 //
928 // In the plugin movie case, hopefully the similar call to
929 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
930 // painting, because that avoids copying the plugin image to a different
931 // paint rect. Unfortunately, if anything on the page is animating other
932 // than the movie, it break this optimization since the union of the
933 // invalid regions will be larger than the plugin.
934 //
935 // This code optimizes that case, where we can still avoid painting in
936 // WebKit and filling the background (which can be slow) and just painting
937 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
938 // required.
[email protected]63ab54262012-11-09 15:58:45939 base::TimeTicks paint_begin_ticks;
940 if (kEnableGpuBenchmarking)
941 paint_begin_ticks = base::TimeTicks::HighResNow();
942
[email protected]df59dd42012-09-14 22:56:30943 SkAutoCanvasRestore auto_restore(canvas, true);
944 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]719b36f2010-12-22 20:36:46945 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27946 optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:21947 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45948 if (kEnableGpuBenchmarking) {
949 base::TimeDelta paint_time =
950 base::TimeTicks::HighResNow() - paint_begin_ticks;
951 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01952 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45953 }
[email protected]719b36f2010-12-22 20:36:46954 } else {
955 // Normal painting case.
[email protected]63ab54262012-11-09 15:58:45956 base::TimeTicks paint_begin_ticks;
957 if (kEnableGpuBenchmarking)
958 paint_begin_ticks = base::TimeTicks::HighResNow();
959
[email protected]719b36f2010-12-22 20:36:46960 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
[email protected]63ab54262012-11-09 15:58:45961
962 if (kEnableGpuBenchmarking) {
963 base::TimeDelta paint_time =
964 base::TimeTicks::HighResNow() - paint_begin_ticks;
965 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01966 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45967 }
[email protected]719b36f2010-12-22 20:36:46968
969 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35970 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46971 }
initial.commit09911bf2008-07-26 23:55:29972
[email protected]4fb66842009-12-04 21:41:00973 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00974 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45975
976 if (kEnableGpuBenchmarking) {
[email protected]63ab54262012-11-09 15:58:45977 int64 num_pixels_processed = rect.width() * rect.height();
[email protected]62049562013-03-24 00:39:01978 software_stats_.total_pixels_painted += num_pixels_processed;
[email protected]63ab54262012-11-09 15:58:45979 }
[email protected]4fb66842009-12-04 21:41:00980}
981
982void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
983 skia::PlatformCanvas* canvas) {
984 static bool kPaintBorder =
985 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
986 if (!kPaintBorder)
987 return;
988
[email protected]53d3f302009-12-21 04:42:05989 // Cycle through these colors to help distinguish new paint rects.
990 const SkColor colors[] = {
991 SkColorSetARGB(0x3F, 0xFF, 0, 0),
992 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
993 SkColorSetARGB(0x3F, 0, 0, 0xFF),
994 };
995 static int color_selector = 0;
996
[email protected]4fb66842009-12-04 21:41:00997 SkPaint paint;
998 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05999 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:001000 paint.setStrokeWidth(1);
1001
1002 SkIRect irect;
1003 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
1004 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:291005}
1006
[email protected]52ccd0ea2011-02-16 01:09:051007void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:301008 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:301009 if (!animation_update_pending_) {
1010 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:591011 return;
[email protected]921244e42011-07-20 16:36:301012 }
[email protected]bd37ae252011-06-03 01:28:181013 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:591014 // Record when we fired (according to base::Time::Now()) relative to when
1015 // we posted the task to quantify how much the base::Time/base::TimeTicks
1016 // skew is affecting animations.
1017 base::TimeDelta animation_callback_delay = base::Time::Now() -
1018 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
1019 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
1020 animation_callback_delay,
1021 base::TimeDelta::FromMilliseconds(0),
1022 base::TimeDelta::FromMilliseconds(30),
1023 25);
1024 }
[email protected]65225772011-05-12 21:10:241025 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:241026}
1027
[email protected]52ccd0ea2011-02-16 01:09:051028void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:591029 if (!animation_update_pending_)
1030 return;
[email protected]bd37ae252011-06-03 01:28:181031
1032 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:331033 base::TimeDelta animationInterval = IsRenderingVSynced() ?
1034 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:181035
[email protected]7c4329e2011-02-18 22:02:591036 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:451037
1038 // animation_floor_time_ is the earliest time that we should animate when
1039 // using the dead reckoning software scheduler. If we're using swapbuffers
1040 // complete callbacks to rate limit, we can ignore this floor.
1041 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:301042 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:331043 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:181044 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:591045 // running animation callbacks so that if a callback requests another
1046 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:381047 animation_timer_.Stop();
1048 animation_timer_.Start(FROM_HERE, animationInterval, this,
1049 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:591050 animation_update_pending_ = false;
[email protected]ba91a792013-02-06 09:48:281051 if (is_accelerated_compositing_active_ && compositor_) {
[email protected]635353c2013-03-06 09:11:201052 compositor_->Animate(base::TimeTicks::Now());
[email protected]8926c602013-01-23 05:32:061053 } else {
[email protected]635353c2013-03-06 09:11:201054 double frame_begin_time =
1055 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
1056 webwidget_->animate(frame_begin_time);
[email protected]8926c602013-01-23 05:32:061057 }
[email protected]7c4329e2011-02-18 22:02:591058 return;
[email protected]5f8b1022011-01-21 23:34:501059 }
[email protected]bd37ae252011-06-03 01:28:181060 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:381061 if (!animation_timer_.IsRunning()) {
1062 // This code uses base::Time::Now() to calculate the floor and next fire
1063 // time because javascript's Date object uses base::Time::Now(). The
1064 // message loop uses base::TimeTicks, which on windows can have a
1065 // different granularity than base::Time.
1066 // The upshot of all this is that this function might be called before
1067 // base::Time::Now() has advanced past the animation_floor_time_. To
1068 // avoid exposing this delay to javascript, we keep posting delayed
1069 // tasks until base::Time::Now() has advanced far enough.
1070 base::TimeDelta delay = animation_floor_time_ - now;
1071 animation_timer_.Start(FROM_HERE, delay, this,
1072 &RenderWidget::AnimationCallback);
1073 }
[email protected]5f8b1022011-01-21 23:34:501074}
1075
[email protected]bd37ae252011-06-03 01:28:181076bool RenderWidget::IsRenderingVSynced() {
1077 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
1078 // not caught by this check. This will lead to artificially low frame rates
1079 // for people who force vsync off at a driver level and expect Chrome to speed
1080 // up.
1081 return !has_disable_gpu_vsync_switch_;
1082}
1083
[email protected]65225772011-05-12 21:10:241084void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:061085 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:241086 invalidation_task_posted_ = false;
1087 DoDeferredUpdateAndSendInputAck();
1088}
1089
1090void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:051091 DoDeferredUpdate();
1092
[email protected]59383c782013-04-17 16:43:271093 if (pending_input_event_ack_)
[email protected]52ccd0ea2011-02-16 01:09:051094 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:211095}
1096
[email protected]552e6002009-11-19 05:24:571097void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:581098 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:081099
[email protected]65225772011-05-12 21:10:241100 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:291101 return;
[email protected]05a980d7a2012-02-07 22:16:421102
[email protected]fc4404d2012-11-07 19:53:301103 if (!init_complete_) {
1104 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:421105 return;
1106 }
[email protected]aa4117f2011-12-09 22:19:211107 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:241108 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
1109 return;
1110 }
[email protected]9ca84622011-06-02 23:46:391111 if (is_accelerated_compositing_active_ &&
1112 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:241113 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
1114 return;
1115 }
initial.commit09911bf2008-07-26 23:55:291116
[email protected]552e6002009-11-19 05:24:571117 // Suppress updating when we are hidden.
[email protected]e3d92a7f2013-01-10 02:35:051118 if (is_hidden_ || size_.IsEmpty() || is_swapped_out_) {
[email protected]552e6002009-11-19 05:24:571119 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:291120 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:241121 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:291122 return;
1123 }
1124
[email protected]0fb93f52011-05-18 23:13:561125 // Tracking of frame rate jitter
1126 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]38ce4e7b2013-02-23 06:17:371127 InstrumentWillBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:051128 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:501129
[email protected]f98d7e3c2010-09-13 22:30:461130 // Layout may generate more invalidation. It may also enable the
1131 // GPU acceleration, so make sure to run layout before we send the
1132 // GpuRenderingActivated message.
1133 webwidget_->layout();
1134
[email protected]793b2d62013-06-11 00:43:251135 // Check for whether we need to track swap buffers. We need to do that after
1136 // layout() because it may have switched us to accelerated compositing.
1137 if (is_accelerated_compositing_active_)
1138 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
1139
[email protected]dcca3aa92012-02-17 23:03:371140 // The following two can result in further layout and possibly
1141 // enable GPU acceleration so they need to be called before any painting
1142 // is done.
[email protected]cb9e2632013-06-18 11:26:471143 UpdateTextInputType();
[email protected]dcca3aa92012-02-17 23:03:371144 UpdateSelectionBounds();
1145
[email protected]5f8b1022011-01-21 23:34:501146 // Suppress painting if nothing is dirty. This has to be done after updating
1147 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:241148 if (!paint_aggregator_.HasPendingUpdate()) {
1149 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]38ce4e7b2013-02-23 06:17:371150 InstrumentDidCancelFrame();
[email protected]5f8b1022011-01-21 23:34:501151 return;
[email protected]65225772011-05-12 21:10:241152 }
[email protected]5f8b1022011-01-21 23:34:501153
[email protected]479b0172012-10-29 19:27:091154 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:361155 !is_threaded_compositing_enabled_ &&
[email protected]479b0172012-10-29 19:27:091156 ForceCompositingModeEnabled()) {
1157 webwidget_->enterForceCompositingMode(true);
1158 }
1159
[email protected]872ae5b2011-05-26 20:20:501160 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:561161 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:041162 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:561163 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
1164 delay,
1165 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411166 base::TimeDelta::FromMilliseconds(120),
1167 60);
[email protected]d0be63772011-12-20 23:18:041168 } else {
[email protected]0fb93f52011-05-18 23:13:561169 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
1170 delay,
1171 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411172 base::TimeDelta::FromMilliseconds(120),
1173 60);
[email protected]d0be63772011-12-20 23:18:041174 }
[email protected]872ae5b2011-05-26 20:20:501175
1176 // Calculate filtered time per frame:
1177 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
1178 filtered_time_per_frame_ =
1179 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:561180 }
1181 last_do_deferred_update_time_ = frame_begin_ticks;
1182
[email protected]fef5e3972012-08-07 03:59:471183 if (!is_accelerated_compositing_active_) {
[email protected]62049562013-03-24 00:39:011184 software_stats_.animation_frame_count++;
1185 software_stats_.screen_frame_count++;
[email protected]fef5e3972012-08-07 03:59:471186 }
1187
[email protected]552e6002009-11-19 05:24:571188 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:291189 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:301190 PaintAggregator::PendingUpdate update;
1191 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:291192
[email protected]53d3f302009-12-21 04:42:051193 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:181194 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:291195
[email protected]29ed96a2012-02-04 18:12:161196 // Notify derived classes that we're about to initiate a paint.
1197 WillInitiatePaint();
1198
[email protected]ca4847f2010-09-24 05:39:151199 // A plugin may be able to do an optimized paint. First check this, in which
1200 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:461201 // This optimization allows PPAPI plugins that declare themselves on top of
1202 // the page (like a traditional windowed plugin) to be able to animate (think
1203 // movie playing) without repeatedly re-painting the page underneath, or
1204 // copying the plugin backing store (since we can send the plugin's backing
1205 // store directly to the browser).
1206 //
1207 // This optimization only works when the entire invalid region is contained
1208 // within the plugin. There is a related optimization in PaintRect for the
1209 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:151210 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:151211 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201212 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:211213 DCHECK(!pending_update_params_.get());
1214 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551215 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211216 pending_update_params_->scroll_rect = update.scroll_rect;
1217 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211218 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1219 pending_update_params_->flags = next_paint_flags_;
1220 pending_update_params_->scroll_offset = GetScrollOffset();
1221 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091222 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211223 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091224 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211225
[email protected]256737c2013-06-08 04:39:101226 if (!is_accelerated_compositing_active_)
1227 pending_update_params_->latency_info = latency_info_;
1228
1229 latency_info_.Clear();
1230
[email protected]ca4847f2010-09-24 05:39:151231 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561232 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151233 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201234 &optimized_copy_rect,
1235 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271236 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471237 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211238 pending_update_params_->bitmap = dib->id();
1239 pending_update_params_->bitmap_rect = optimized_copy_location;
1240 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201241 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561242 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461243 // Compute a buffer for painting and cache it.
[email protected]4889bd212013-02-11 22:23:101244
1245 bool fractional_scale = device_scale_factor_ -
1246 static_cast<int>(device_scale_factor_) != 0;
1247 if (fractional_scale) {
1248 // Damage might not be DIP aligned. Inflate damage to compensate.
1249 bounds.Inset(-1, -1);
1250 bounds.Intersect(gfx::Rect(size_));
1251 }
1252
1253 gfx::Rect pixel_bounds = gfx::ToEnclosingRect(
[email protected]ce112fe2012-10-29 22:52:181254 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]4889bd212013-02-11 22:23:101255
[email protected]ca4847f2010-09-24 05:39:151256 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351257 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591258 pixel_bounds));
[email protected]59383c782013-04-17 16:43:271259 if (!canvas) {
[email protected]f98d7e3c2010-09-13 22:30:461260 NOTREACHED();
1261 return;
1262 }
[email protected]cef3362f2009-12-21 17:48:451263
[email protected]f98d7e3c2010-09-13 22:30:461264 // We may get back a smaller canvas than we asked for.
1265 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591266 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1267 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1268 pixel_bounds.set_width(canvas->getDevice()->width());
1269 pixel_bounds.set_height(canvas->getDevice()->height());
1270 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1271 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051272
[email protected]f98d7e3c2010-09-13 22:30:461273 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1274
[email protected]aa4117f2011-12-09 22:19:211275 pending_update_params_->bitmap = current_paint_buf_->id();
1276 pending_update_params_->bitmap_rect = bounds;
1277
1278 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461279 // The scroll damage is just another rectangle to paint and copy.
1280 copy_rects.swap(update.paint_rects);
1281 if (!scroll_damage.IsEmpty())
1282 copy_rects.push_back(scroll_damage);
1283
[email protected]4889bd212013-02-11 22:23:101284 for (size_t i = 0; i < copy_rects.size(); ++i) {
1285 gfx::Rect rect = copy_rects[i];
1286 if (fractional_scale) {
1287 // Damage might not be DPI aligned. Inflate rect to compensate.
1288 rect.Inset(-1, -1);
1289 }
1290 PaintRect(rect, pixel_bounds.origin(), canvas.get());
1291 }
[email protected]60a50072012-01-11 02:05:351292
1293 // Software FPS tick for performance tests. The accelerated path traces the
1294 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1295 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421296 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW",
1297 TRACE_EVENT_SCOPE_THREAD);
[email protected]f98d7e3c2010-09-13 22:30:461298 } else { // Accelerated compositing path
1299 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211300 // If painting is done via the gpu process then we don't set any damage
1301 // rects to save the browser process from doing unecessary work.
1302 pending_update_params_->bitmap_rect = bounds;
1303 pending_update_params_->scroll_rect = gfx::Rect();
1304 // We don't need an ack, because we're not sharing a DIB with the browser.
1305 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1306 // with the browser for the GPU surface.
1307 pending_update_params_->needs_ack = false;
[email protected]f0c2a242013-03-15 19:34:521308 Composite(frame_begin_ticks);
[email protected]f98d7e3c2010-09-13 22:30:461309 }
1310
[email protected]936c6f52011-12-13 01:35:261311 // If we're holding a pending input event ACK, send the ACK before sending the
1312 // UpdateReply message so we can receive another input event before the
1313 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1314 // the UpdateRect IPC message handler.
[email protected]59383c782013-04-17 16:43:271315 if (pending_input_event_ack_)
[email protected]936c6f52011-12-13 01:35:261316 Send(pending_input_event_ack_.release());
1317
[email protected]ab543072013-01-25 04:38:151318 // If Composite() called SwapBuffers, pending_update_params_ will be reset (in
[email protected]aa4117f2011-12-09 22:19:211319 // OnSwapBuffersPosted), meaning a message has been added to the
1320 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1321 // the message now.
[email protected]59383c782013-04-17 16:43:271322 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:211323 // sending an ack to browser process that the paint is complete...
1324 update_reply_pending_ = pending_update_params_->needs_ack;
1325 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1326 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341327 }
[email protected]53d3f302009-12-21 04:42:051328
[email protected]29ed96a2012-02-04 18:12:161329 // If we're software rendering then we're done initiating the paint.
1330 if (!is_accelerated_compositing_active_)
1331 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291332}
1333
[email protected]f0c2a242013-03-15 19:34:521334void RenderWidget::Composite(base::TimeTicks frame_begin_time) {
[email protected]ab543072013-01-25 04:38:151335 DCHECK(is_accelerated_compositing_active_);
[email protected]ba91a792013-02-06 09:48:281336 if (compositor_) // TODO(jamesr): Figure out how this can be null.
[email protected]f0c2a242013-03-15 19:34:521337 compositor_->Composite(frame_begin_time);
[email protected]ab543072013-01-25 04:38:151338}
1339
initial.commit09911bf2008-07-26 23:55:291340///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461341// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291342
[email protected]4873c7d2009-07-16 06:36:281343void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]479b0172012-10-29 19:27:091344 TRACE_EVENT2("renderer", "RenderWidget::didInvalidateRect",
1345 "width", rect.width, "height", rect.height);
[email protected]552e6002009-11-19 05:24:571346 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481347 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181348 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571349 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291350 return;
1351
[email protected]552e6002009-11-19 05:24:571352 paint_aggregator_.InvalidateRect(damaged_rect);
1353
1354 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241355 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571356 return;
1357 if (!paint_aggregator_.HasPendingUpdate())
1358 return;
[email protected]aa4117f2011-12-09 22:19:211359 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241360 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1361 return;
1362
1363 // When GPU rendering, combine pending animations and invalidations into
1364 // a single update.
[email protected]816edc62012-03-17 01:27:221365 if (is_accelerated_compositing_active_ &&
1366 animation_update_pending_ &&
1367 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571368 return;
1369
1370 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291371 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1372 // on the call stack.
1373 // 2) Allows us to collect more damage rects before painting to help coalesce
1374 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241375 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111376 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211377 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291378}
1379
[email protected]990278ff2012-11-13 02:12:551380void RenderWidget::didScrollRect(int dx, int dy,
1381 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461382 // Drop scrolls on the floor when we are in compositing mode.
1383 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561384 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461385 return;
1386
[email protected]552e6002009-11-19 05:24:571387 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481388 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181389 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571390 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291391 return;
1392
[email protected]990278ff2012-11-13 02:12:551393 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571394
1395 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241396 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571397 return;
1398 if (!paint_aggregator_.HasPendingUpdate())
1399 return;
[email protected]aa4117f2011-12-09 22:19:211400 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241401 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1402 return;
1403
1404 // When GPU rendering, combine pending animations and invalidations into
1405 // a single update.
[email protected]816edc62012-03-17 01:27:221406 if (is_accelerated_compositing_active_ &&
1407 animation_update_pending_ &&
1408 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571409 return;
1410
1411 // Perform updating asynchronously. This serves two purposes:
1412 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1413 // on the call stack.
1414 // 2) Allows us to collect more damage rects before painting to help coalesce
1415 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241416 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111417 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211418 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291419}
1420
[email protected]244ac1892011-12-02 17:04:471421void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091422 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451423 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581424
[email protected]eac2b362013-05-22 07:01:451425 // If we don't clear PaintAggregator after changing autoResize state, then
1426 // we might end up in a situation where bitmap_rect is larger than the
1427 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1428 // with invalid damage rects.
1429 paint_aggregator_.ClearPendingUpdate();
1430
[email protected]70dee7e2013-05-29 18:28:301431 if (RenderThreadImpl::current()->layout_test_mode()) {
[email protected]eac2b362013-05-22 07:01:451432 WebRect new_pos(rootWindowRect().x,
1433 rootWindowRect().y,
1434 new_size.width,
1435 new_size.height);
1436 view_screen_rect_ = new_pos;
1437 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031438 }
[email protected]20fbfc22013-05-08 20:50:581439
[email protected]eac2b362013-05-22 07:01:451440 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581441
[email protected]70dee7e2013-05-29 18:28:301442 if (!RenderThreadImpl::current()->layout_test_mode())
[email protected]20fbfc22013-05-08 20:50:581443 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091444 }
[email protected]244ac1892011-12-02 17:04:471445}
1446
[email protected]3a1c8a8032013-03-18 22:35:321447void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051448 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1449 device_scale_factor_));
1450 if (compositor_)
1451 compositor_->setViewportSize(size_, physical_backing_size_);
1452}
1453
[email protected]91acd1c2012-03-14 08:32:391454void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221455 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1456
[email protected]c63b4d42012-04-26 01:01:071457#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211458 if (!is_accelerated_compositing_active_) {
1459 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1460 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1461 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1462 // going to switch to accelerated compositing, the GPU process may need
1463 // round-trips to the browser's UI thread before finishing the frame,
1464 // causing deadlocks if we delay the UpdateRect until we receive the
1465 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071466 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1467 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211468 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1469 }
[email protected]c63b4d42012-04-26 01:01:071470#endif
[email protected]aa4117f2011-12-09 22:19:211471
[email protected]ea162f92011-10-04 23:08:221472 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421473 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241474 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221475}
1476
1477void RenderWidget::didDeactivateCompositor() {
1478 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1479
1480 is_accelerated_compositing_active_ = false;
1481 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1482 routing_id_, is_accelerated_compositing_active_));
1483
[email protected]ea162f92011-10-04 23:08:221484 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241485 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091486
1487 // In single-threaded mode, we exit force compositing mode and re-enter in
1488 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1489 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1490 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361491 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091492 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561493}
1494
[email protected]e195e582013-03-08 01:32:591495void RenderWidget::initializeLayerTreeView() {
1496 compositor_ = RenderWidgetCompositor::Create(this);
1497 if (!compositor_)
1498 return;
1499
1500 compositor_->setViewportSize(size_, physical_backing_size_);
1501 if (init_complete_)
1502 compositor_->setSurfaceReady();
1503}
1504
[email protected]8926c602013-01-23 05:32:061505WebKit::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281506 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061507}
1508
[email protected]9ed83fe2013-02-27 01:52:281509void RenderWidget::suppressCompositorScheduling(bool enable) {
1510 if (compositor_)
1511 compositor_->SetSuppressScheduleComposite(enable);
1512}
1513
[email protected]9cd43a62012-03-26 08:03:561514void RenderWidget::willBeginCompositorFrame() {
1515 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371516
[email protected]cadac622013-06-11 16:46:361517 DCHECK(RenderThreadImpl::current()->compositor_message_loop_proxy().get());
[email protected]abe8b3a2012-03-28 21:19:371518
1519 // The following two can result in further layout and possibly
1520 // enable GPU acceleration so they need to be called before any painting
1521 // is done.
[email protected]cb9e2632013-06-18 11:26:471522 UpdateTextInputType();
1523#if defined(OS_ANDROID)
[email protected]2d354272013-01-14 00:59:061524 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]cb9e2632013-06-18 11:26:471525#endif
[email protected]abe8b3a2012-03-28 21:19:371526 UpdateSelectionBounds();
1527
[email protected]9cd43a62012-03-26 08:03:561528 WillInitiatePaint();
1529}
1530
[email protected]3391a0772012-03-28 00:32:071531void RenderWidget::didBecomeReadyForAdditionalInput() {
1532 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]59383c782013-04-17 16:43:271533 if (pending_input_event_ack_)
[email protected]3391a0772012-03-28 00:32:071534 Send(pending_input_event_ack_.release());
1535}
1536
[email protected]6fceb912013-02-15 06:24:151537void RenderWidget::DidCommitCompositorFrame() {
1538}
1539
[email protected]58264a32011-11-17 23:36:151540void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501541 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351542 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1543 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421544 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU",
1545 TRACE_EVENT_SCOPE_THREAD);
[email protected]29ed96a2012-02-04 18:12:161546 // Notify subclasses that we initiated the paint operation.
1547 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151548}
1549
1550void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181551 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1552
1553 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561554 DidFlushPaint();
1555
[email protected]aa4117f2011-12-09 22:19:211556 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151557 return;
1558
[email protected]ea3ee0a2012-05-15 03:43:091559 if (!next_paint_flags_ &&
1560 !need_update_rect_for_auto_resize_ &&
1561 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151562 return;
[email protected]ea3ee0a2012-05-15 03:43:091563 }
[email protected]58264a32011-11-17 23:36:151564
1565 ViewHostMsg_UpdateRect_Params params;
1566 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151567 params.plugin_window_moves.swap(plugin_window_moves_);
1568 params.flags = next_paint_flags_;
1569 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121570 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091571 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151572
1573 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1574 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091575 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151576}
1577
[email protected]f98d7e3c2010-09-13 22:30:461578void RenderWidget::scheduleComposite() {
[email protected]479b0172012-10-29 19:27:091579 TRACE_EVENT0("gpu", "RenderWidget::scheduleComposite");
[email protected]cadac622013-06-11 16:46:361580 if (RenderThreadImpl::current()->compositor_message_loop_proxy().get() &&
[email protected]ba91a792013-02-06 09:48:281581 compositor_) {
1582 compositor_->setNeedsRedraw();
[email protected]d0be63772011-12-20 23:18:041583 } else {
[email protected]c3d45532011-10-07 19:20:401584 // TODO(nduca): replace with something a little less hacky. The reason this
1585 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1586 // contains a lot of host-renderer synchronization logic that is still
1587 // important for the accelerated compositing case. The option of simply
1588 // duplicating all that code is less desirable than "faking out" the
1589 // invalidation path using a magical damage rect.
1590 didInvalidateRect(WebRect(0, 0, 1, 1));
1591 }
[email protected]f98d7e3c2010-09-13 22:30:461592}
1593
[email protected]5f8b1022011-01-21 23:34:501594void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201595 if (animation_update_pending_)
1596 return;
1597
[email protected]921244e42011-07-20 16:36:301598 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201599 animation_update_pending_ = true;
1600 if (!animation_timer_.IsRunning()) {
1601 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1602 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211603 }
[email protected]5f8b1022011-01-21 23:34:501604}
1605
[email protected]4873c7d2009-07-16 06:36:281606void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301607 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521608 WebCursor cursor;
1609 webkit_glue::InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291610 // Only send a SetCursor message if we need to make a change.
1611 if (!current_cursor_.IsEqual(cursor)) {
1612 current_cursor_ = cursor;
1613 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1614 }
1615}
1616
1617// We are supposed to get a single call to Show for a newly created RenderWidget
1618// that was created via RenderWidget::CreateWebView. So, we wait until this
1619// point to dispatch the ShowWidget message.
1620//
1621// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281622// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291623//
[email protected]4873c7d2009-07-16 06:36:281624void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291625 DCHECK(!did_show_) << "received extraneous Show call";
1626 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1627 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1628
[email protected]8de12d942010-11-17 20:42:441629 if (did_show_)
1630 return;
1631
1632 did_show_ = true;
1633 // NOTE: initial_pos_ may still have its default values at this point, but
1634 // that's okay. It'll be ignored if as_popup is false, or the browser
1635 // process will impose a default position otherwise.
1636 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1637 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291638}
1639
[email protected]9b003482013-05-21 14:00:171640void RenderWidget::didProgrammaticallyScroll(
1641 const WebKit::WebPoint& scroll_point) {
1642 if (!compositor_)
1643 return;
1644 Send(new ViewHostMsg_DidProgrammaticallyScroll(
1645 routing_id_, gfx::Vector2d(scroll_point.x, scroll_point.y)));
1646}
1647
[email protected]4873c7d2009-07-16 06:36:281648void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291649}
1650
[email protected]4873c7d2009-07-16 06:36:281651void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291652}
1653
[email protected]2533ce12009-05-09 00:02:241654void RenderWidget::DoDeferredClose() {
1655 Send(new ViewHostMsg_Close(routing_id_));
1656}
1657
[email protected]4873c7d2009-07-16 06:36:281658void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321659 if (is_swapped_out_) {
1660 // This widget is currently swapped out, and the active widget is in a
1661 // different process. Have the browser route the close request to the
1662 // active widget instead, so that the correct unload handlers are run.
1663 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1664 return;
1665 }
1666
initial.commit09911bf2008-07-26 23:55:291667 // If a page calls window.close() twice, we'll end up here twice, but that's
1668 // OK. It is safe to send multiple Close messages.
1669
[email protected]2533ce12009-05-09 00:02:241670 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1671 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1672 // could be closed before the JS finishes executing. So instead, post a
1673 // message back to the message loop, which won't run until the JS is
1674 // complete, and then the Close message can be sent.
[email protected]dd32b1272013-05-04 14:17:111675 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211676 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291677}
1678
1679void RenderWidget::Close() {
1680 if (webwidget_) {
[email protected]8926c602013-01-23 05:32:061681 webwidget_->willCloseLayerTreeView();
[email protected]ba91a792013-02-06 09:48:281682 compositor_.reset();
[email protected]4873c7d2009-07-16 06:36:281683 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291684 webwidget_ = NULL;
1685 }
1686}
1687
[email protected]4873c7d2009-07-16 06:36:281688WebRect RenderWidget::windowRect() {
1689 if (pending_window_rect_count_)
1690 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241691
[email protected]80ad8622012-11-07 16:33:031692 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291693}
1694
[email protected]8a9d6ca32011-06-06 20:11:301695void RenderWidget::setToolTipText(const WebKit::WebString& text,
1696 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541697 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301698}
1699
[email protected]4873c7d2009-07-16 06:36:281700void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291701 if (did_show_) {
[email protected]70dee7e2013-05-29 18:28:301702 if (!RenderThreadImpl::current()->layout_test_mode()) {
[email protected]8be1c582013-03-06 00:55:031703 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1704 SetPendingWindowRect(pos);
1705 } else {
1706 WebSize new_size(pos.width, pos.height);
[email protected]d9083762013-03-24 01:36:401707 Resize(new_size, new_size, overdraw_bottom_height_,
1708 WebRect(), is_fullscreen_, NO_RESIZE_ACK);
[email protected]8be1c582013-03-06 00:55:031709 view_screen_rect_ = pos;
1710 window_screen_rect_ = pos;
1711 }
initial.commit09911bf2008-07-26 23:55:291712 } else {
1713 initial_pos_ = pos;
1714 }
1715}
1716
[email protected]2533ce12009-05-09 00:02:241717void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1718 pending_window_rect_ = rect;
1719 pending_window_rect_count_++;
1720}
1721
[email protected]4873c7d2009-07-16 06:36:281722WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241723 if (pending_window_rect_count_) {
1724 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1725 // the RootWindowRect is probably going to return wrong results since the
1726 // browser may not have processed the Move yet. There isn't really anything
1727 // good to do in this case, and it shouldn't happen - since this size is
1728 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281729 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241730 }
1731
[email protected]80ad8622012-11-07 16:33:031732 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371733}
1734
[email protected]4873c7d2009-07-16 06:36:281735WebRect RenderWidget::windowResizerRect() {
1736 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191737}
1738
[email protected]fa7b1dc2010-06-23 17:53:041739void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031740 // To prevent this renderer process from sending unnecessary IPC messages to
1741 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041742 // only during the input method attached to the browser process is active.
1743 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291744}
1745
[email protected]88dbe32f2013-06-20 23:31:361746void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
1747 ui::Range range = ui::Range();
1748 if (should_update_range) {
1749 GetCompositionRange(&range);
1750 } else {
1751 range = composition_range_;
1752 }
1753 std::vector<gfx::Rect> character_bounds;
1754 GetCompositionCharacterBounds(&character_bounds);
1755
[email protected]58b48a0d2012-06-13 07:01:351756 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1757 return;
1758 composition_character_bounds_ = character_bounds;
1759 composition_range_ = range;
1760 Send(new ViewHostMsg_ImeCompositionRangeChanged(
1761 routing_id(), composition_range_, composition_character_bounds_));
1762}
1763
[email protected]fa7b1dc2010-06-23 17:53:041764void RenderWidget::OnImeSetComposition(
1765 const string16& text,
1766 const std::vector<WebCompositionUnderline>& underlines,
1767 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281768 if (!webwidget_)
1769 return;
[email protected]66fca5bc2013-05-23 06:58:291770 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:361771 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041772 text, WebVector<WebCompositionUnderline>(underlines),
1773 selection_start, selection_end)) {
1774 // 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]7f00efa2010-04-15 05:01:261778 }
[email protected]88dbe32f2013-06-20 23:31:361779 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:041780}
1781
[email protected]4de6d1692011-10-12 08:45:441782void RenderWidget::OnImeConfirmComposition(
1783 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041784 if (!webwidget_)
1785 return;
[email protected]66fca5bc2013-05-23 06:58:291786 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:041787 handling_input_event_ = true;
1788 webwidget_->confirmComposition(text);
1789 handling_input_event_ = false;
[email protected]88dbe32f2013-06-20 23:31:361790 UpdateCompositionInfo(true);
initial.commit09911bf2008-07-26 23:55:291791}
1792
[email protected]948f7ab72010-05-28 23:48:081793// This message causes the renderer to render an image of the
1794// desired_size, regardless of whether the tab is hidden or not.
[email protected]3d9ec5052013-01-02 22:05:251795void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle,
1796 int tag,
1797 const gfx::Size& page_size,
1798 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001799 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1800 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251801 // Close our unused handle.
1802#if defined(OS_WIN)
1803 ::CloseHandle(dib_handle);
1804#elif defined(OS_MACOSX)
1805 base::SharedMemory::CloseHandle(dib_handle);
1806#endif
1807 }
[email protected]d65adb12010-04-28 17:26:491808 return;
[email protected]45c6aad32010-11-11 04:46:251809 }
[email protected]d65adb12010-04-28 17:26:491810
[email protected]948f7ab72010-05-28 23:48:081811 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491812 // If one of these is empty, then we just return the dib we were
1813 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091814 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491815 return;
1816 }
1817
1818 // Map the given DIB ID into this process, and unmap it at the end
1819 // of this function.
[email protected]45c6aad32010-11-11 04:46:251820 scoped_ptr<TransportDIB> paint_at_size_buffer(
1821 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301822
[email protected]4b01b962012-10-09 23:17:351823 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281824 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:351825 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281826 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:511827 gfx::Size canvas_size = page_size_in_pixel;
1828 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:491829 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:511830 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:491831 static_cast<float>(canvas_size.height());
1832
[email protected]ee8d6fd2010-05-26 17:05:481833 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491834 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1835 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481836 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491837
[email protected]36808ad2010-10-20 19:18:301838 scoped_ptr<skia::PlatformCanvas> canvas(
1839 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1840 canvas_size.height()));
[email protected]59383c782013-04-17 16:43:271841 if (!canvas) {
[email protected]36808ad2010-10-20 19:18:301842 NOTREACHED();
1843 return;
1844 }
1845
[email protected]d65adb12010-04-28 17:26:491846 // Reset bounds to what we actually received, but they should be the
1847 // same.
1848 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1849 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1850 bounds.set_width(canvas->getDevice()->width());
1851 bounds.set_height(canvas->getDevice()->height());
1852
1853 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081854 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491855 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1856
[email protected]948f7ab72010-05-28 23:48:081857 // Have to make sure we're laid out at the right size before
1858 // rendering.
1859 gfx::Size old_size = webwidget_->size();
1860 webwidget_->resize(page_size);
1861 webwidget_->layout();
1862
[email protected]d65adb12010-04-28 17:26:491863 // Paint the entire thing (using original bounds, not scaled bounds).
1864 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1865 canvas->restore();
1866
[email protected]948f7ab72010-05-28 23:48:081867 // Return the widget to its previous size.
1868 webwidget_->resize(old_size);
1869
[email protected]c88c9442010-07-19 18:55:091870 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491871}
1872
[email protected]51a49502013-03-23 01:50:191873void RenderWidget::OnSnapshot(const gfx::Rect& src_subrect) {
1874 SkBitmap snapshot;
1875
1876 if (OnSnapshotHelper(src_subrect, &snapshot)) {
1877 Send(new ViewHostMsg_Snapshot(routing_id(), true, snapshot));
1878 } else {
1879 Send(new ViewHostMsg_Snapshot(routing_id(), false, SkBitmap()));
1880 }
1881}
1882
1883bool RenderWidget::OnSnapshotHelper(const gfx::Rect& src_subrect,
1884 SkBitmap* snapshot) {
1885 base::TimeTicks beginning_time = base::TimeTicks::Now();
1886
1887 if (!webwidget_ || src_subrect.IsEmpty())
1888 return false;
1889
1890 gfx::Rect viewport_size = gfx::IntersectRects(
1891 src_subrect, gfx::Rect(physical_backing_size_));
1892
1893 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(
1894 skia::CreatePlatformCanvas(viewport_size.width(),
1895 viewport_size.height(),
1896 true,
1897 NULL,
1898 skia::RETURN_NULL_ON_FAILURE));
[email protected]59383c782013-04-17 16:43:271899 if (!canvas)
[email protected]51a49502013-03-23 01:50:191900 return false;
1901
1902 canvas->save();
1903 webwidget_->layout();
1904
1905 PaintRect(viewport_size, viewport_size.origin(), canvas.get());
1906 canvas->restore();
1907
1908 const SkBitmap& bitmap = skia::GetTopDevice(*canvas)->accessBitmap(false);
1909 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1910 return false;
1911
1912 UMA_HISTOGRAM_TIMES("Renderer4.Snapshot",
1913 base::TimeTicks::Now() - beginning_time);
1914 return true;
1915}
1916
[email protected]0bc1f572013-04-17 01:46:311917void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121918 // During shutdown we can just ignore this message.
1919 if (!webwidget_)
1920 return;
1921
[email protected]0bc1f572013-04-17 01:46:311922 // Even if the browser provides an empty damage rect, it's still expecting to
1923 // receive a repaint ack so just damage the entire widget bounds.
1924 if (size_to_paint.IsEmpty()) {
1925 size_to_paint = size_;
1926 }
1927
[email protected]ec7dc112008-08-06 05:30:121928 set_next_paint_is_repaint_ack();
[email protected]0bc1f572013-04-17 01:46:311929 if (is_accelerated_compositing_active_ && compositor_) {
1930 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]f98d7e3c2010-09-13 22:30:461931 } else {
1932 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1933 didInvalidateRect(repaint_rect);
1934 }
[email protected]ec7dc112008-08-06 05:30:121935}
1936
[email protected]4a9dba42013-04-29 18:24:221937void RenderWidget::OnSmoothScrollCompleted() {
1938 pending_smooth_scroll_gesture_.Run();
[email protected]0e241b4b2012-08-18 09:06:271939}
1940
[email protected]4873c7d2009-07-16 06:36:281941void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111942 if (!webwidget_)
1943 return;
[email protected]4873c7d2009-07-16 06:36:281944 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111945}
1946
[email protected]80ad8622012-11-07 16:33:031947void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1948 const gfx::Rect& window_screen_rect) {
1949 view_screen_rect_ = view_screen_rect;
1950 window_screen_rect_ = window_screen_rect;
1951 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1952}
1953
[email protected]105dffb42013-02-20 03:46:211954#if defined(OS_ANDROID)
1955void RenderWidget::OnImeBatchStateChanged(bool is_begin) {
1956 Send(new ViewHostMsg_ImeBatchStateChanged_ACK(routing_id(), is_begin));
1957}
[email protected]2384b6c2013-02-28 23:58:511958
1959void RenderWidget::OnShowImeIfNeeded() {
1960 UpdateTextInputState(SHOW_IME_IF_NEEDED);
1961}
[email protected]105dffb42013-02-20 03:46:211962#endif
1963
[email protected]468ac582012-11-20 00:53:191964void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1965 if (device_scale_factor_ == device_scale_factor)
1966 return;
1967
1968 device_scale_factor_ = device_scale_factor;
1969
1970 if (!is_accelerated_compositing_active_) {
1971 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
1972 } else {
1973 scheduleComposite();
1974 }
1975}
1976
[email protected]719b36f2010-12-22 20:36:461977webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151978 const gfx::Rect& paint_bounds,
1979 TransportDIB** dib,
1980 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:201981 gfx::Rect* clip,
1982 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:461983 // Bare RenderWidgets don't support optimized plugin painting.
1984 return NULL;
[email protected]ca4847f2010-09-24 05:39:151985}
1986
[email protected]ceb36f7d2012-10-31 18:33:241987gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521988 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241989 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521990}
1991
[email protected]bee16aab2009-08-26 15:55:031992void RenderWidget::SetHidden(bool hidden) {
1993 if (is_hidden_ == hidden)
1994 return;
1995
1996 // The status has changed. Tell the RenderThread about it.
1997 is_hidden_ = hidden;
1998 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271999 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:032000 else
[email protected]380244092011-10-07 17:26:272001 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:032002}
2003
[email protected]2b624c562011-10-27 22:58:262004void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262005 if (!webwidget_)
2006 return;
2007
2008 if (is_fullscreen_) {
2009 webwidget_->willExitFullScreen();
2010 } else {
2011 webwidget_->willEnterFullScreen();
2012 }
[email protected]2b624c562011-10-27 22:58:262013}
2014
2015void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262016 if (!webwidget_)
2017 return;
2018
2019 if (is_fullscreen_) {
2020 webwidget_->didEnterFullScreen();
2021 } else {
2022 webwidget_->didExitFullScreen();
2023 }
[email protected]2b624c562011-10-27 22:58:262024}
2025
[email protected]699ab0d2009-04-23 23:19:142026void RenderWidget::SetBackground(const SkBitmap& background) {
2027 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:462028
[email protected]699ab0d2009-04-23 23:19:142029 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:282030 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:142031}
2032
[email protected]674741932009-02-04 23:44:462033bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:052034 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462035}
2036
2037bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:052038 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462039}
2040
2041void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:052042 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462043}
2044
2045void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:052046 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:462047}
2048
2049void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:052050 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462051}
2052
[email protected]b18583c2012-12-18 06:55:272053static bool IsDateTimeInput(ui::TextInputType type) {
2054 return type == ui::TEXT_INPUT_TYPE_DATE ||
2055 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
2056 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
2057 type == ui::TEXT_INPUT_TYPE_MONTH ||
2058 type == ui::TEXT_INPUT_TYPE_TIME ||
2059 type == ui::TEXT_INPUT_TYPE_WEEK;
2060}
2061
[email protected]66fca5bc2013-05-23 06:58:292062
2063void RenderWidget::StartHandlingImeEvent() {
2064 DCHECK(!handling_ime_event_);
2065 handling_ime_event_ = true;
2066}
2067
2068void RenderWidget::FinishHandlingImeEvent() {
2069 DCHECK(handling_ime_event_);
2070 handling_ime_event_ = false;
2071 // While handling an ime event, text input state and selection bounds updates
2072 // are ignored. These must explicitly be updated once finished handling the
2073 // ime event.
2074 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:472075#if defined(OS_ANDROID)
[email protected]66fca5bc2013-05-23 06:58:292076 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]cb9e2632013-06-18 11:26:472077#endif
[email protected]66fca5bc2013-05-23 06:58:292078}
2079
[email protected]cb9e2632013-06-18 11:26:472080void RenderWidget::UpdateTextInputType() {
2081 if (!input_method_is_active_)
2082 return;
2083
2084 ui::TextInputType new_type = GetTextInputType();
2085 if (IsDateTimeInput(new_type))
2086 return; // Not considered as a text input field in WebKit/Chromium.
2087
2088 bool new_can_compose_inline = CanComposeInline();
2089
2090 if (text_input_type_ != new_type
2091 || can_compose_inline_ != new_can_compose_inline) {
2092 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
2093 new_type,
2094 new_can_compose_inline));
2095 text_input_type_ = new_type;
2096 can_compose_inline_ = new_can_compose_inline;
2097 }
2098}
2099
2100#if defined(OS_ANDROID)
[email protected]3306f262012-09-21 19:20:422101void RenderWidget::UpdateTextInputState(ShowIme show_ime) {
[email protected]e8f775f2013-02-14 21:00:502102 if (handling_ime_event_)
2103 return;
[email protected]3306f262012-09-21 19:20:422104 bool show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
2105 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:292106 return;
[email protected]ad26ef42011-06-17 07:59:452107 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:272108 if (IsDateTimeInput(new_type))
2109 return; // Not considered as a text input field in WebKit/Chromium.
2110
[email protected]5b739cb2012-08-21 20:35:212111 WebKit::WebTextInputInfo new_info;
2112 if (webwidget_)
2113 new_info = webwidget_->textInputInfo();
2114
[email protected]ad26ef42011-06-17 07:59:452115 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:212116
[email protected]3306f262012-09-21 19:20:422117 // Only sends text input params if they are changed or if the ime should be
2118 // shown.
2119 if (show_ime_if_needed || (text_input_type_ != new_type
2120 || text_input_info_ != new_info
2121 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:212122 ViewHostMsg_TextInputState_Params p;
2123 p.type = new_type;
2124 p.value = new_info.value.utf8();
2125 p.selection_start = new_info.selectionStart;
2126 p.selection_end = new_info.selectionEnd;
2127 p.composition_start = new_info.compositionStart;
2128 p.composition_end = new_info.compositionEnd;
2129 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:422130 p.show_ime_if_needed = show_ime_if_needed;
[email protected]5b739cb2012-08-21 20:35:212131 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
2132
2133 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:042134 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:452135 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:292136 }
initial.commit09911bf2008-07-26 23:55:292137}
[email protected]cb9e2632013-06-18 11:26:472138#endif
initial.commit09911bf2008-07-26 23:55:292139
[email protected]7c8873e2013-02-05 08:03:012140void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2141 WebRect focus_webrect;
2142 WebRect anchor_webrect;
2143 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
2144 *focus = focus_webrect;
2145 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322146}
2147
[email protected]e99ef6f2011-10-16 01:13:002148void RenderWidget::UpdateSelectionBounds() {
2149 if (!webwidget_)
2150 return;
[email protected]66fca5bc2013-05-23 06:58:292151 if (handling_ime_event_)
2152 return;
[email protected]e99ef6f2011-10-16 01:13:002153
[email protected]7c8873e2013-02-05 08:03:012154 ViewHostMsg_SelectionBounds_Params params;
2155 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2156 if (selection_anchor_rect_ != params.anchor_rect ||
2157 selection_focus_rect_ != params.focus_rect) {
2158 selection_anchor_rect_ = params.anchor_rect;
2159 selection_focus_rect_ = params.focus_rect;
2160 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
[email protected]129b7382013-02-12 02:14:292161 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
[email protected]7c8873e2013-02-05 08:03:012162 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
[email protected]58b48a0d2012-06-13 07:01:352163 }
[email protected]e99ef6f2011-10-16 01:13:002164
[email protected]88dbe32f2013-06-20 23:31:362165 UpdateCompositionInfo(false);
[email protected]58b48a0d2012-06-13 07:01:352166}
2167
2168bool RenderWidget::ShouldUpdateCompositionInfo(
2169 const ui::Range& range,
2170 const std::vector<gfx::Rect>& bounds) {
2171 if (composition_range_ != range)
2172 return true;
2173 if (bounds.size() != composition_character_bounds_.size())
2174 return true;
2175 for (size_t i = 0; i < bounds.size(); ++i) {
2176 if (bounds[i] != composition_character_bounds_[i])
2177 return true;
2178 }
2179 return false;
[email protected]e99ef6f2011-10-16 01:13:002180}
2181
[email protected]73bf95812011-10-12 11:38:322182// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:452183COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
2184 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
2185COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
2186 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
2187COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
2188 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:182189COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
2190 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
2191COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
2192 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
2193COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
2194 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
2195COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
2196 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
2197COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
2198 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:002199COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
2200 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
2201COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
2202 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
2203COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
2204 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
2205COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
2206 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
2207COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
2208 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
2209COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
2210 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:012211COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
2212 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
2213COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
2214 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]8b4992e2013-03-01 15:42:152215COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeField) == \
2216 int(ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:452217
[email protected]5b739cb2012-08-21 20:35:212218ui::TextInputType RenderWidget::WebKitToUiTextInputType(
2219 WebKit::WebTextInputType type) {
2220 // Check the type is in the range representable by ui::TextInputType.
2221 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
2222 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
2223 return static_cast<ui::TextInputType>(type);
2224}
2225
[email protected]ad26ef42011-06-17 07:59:452226ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272227 if (webwidget_)
2228 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452229 return ui::TEXT_INPUT_TYPE_NONE;
2230}
2231
[email protected]58b48a0d2012-06-13 07:01:352232void RenderWidget::GetCompositionCharacterBounds(
2233 std::vector<gfx::Rect>* bounds) {
2234 DCHECK(bounds);
2235 bounds->clear();
2236}
2237
[email protected]88dbe32f2013-06-20 23:31:362238void RenderWidget::GetCompositionRange(ui::Range* range) {
2239 size_t location, length;
2240 if (webwidget_->compositionRange(&location, &length)) {
2241 range->set_start(location);
2242 range->set_end(location + length);
2243 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2244 range->set_start(location);
2245 range->set_end(location + length);
2246 } else {
2247 *range = ui::Range::InvalidRange();
2248 }
2249}
2250
[email protected]ad26ef42011-06-17 07:59:452251bool RenderWidget::CanComposeInline() {
2252 return true;
[email protected]56ea1a62011-05-30 07:05:572253}
2254
[email protected]4873c7d2009-07-16 06:36:282255WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042256 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282257}
2258
[email protected]f660d9c2012-06-06 18:31:212259float RenderWidget::deviceScaleFactor() {
2260 return device_scale_factor_;
2261}
2262
[email protected]fa7b1dc2010-06-23 17:53:042263void RenderWidget::resetInputMethod() {
2264 if (!input_method_is_active_)
2265 return;
2266
2267 // If the last text input type is not None, then we should finish any
2268 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452269 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042270 // If a composition text exists, then we need to let the browser process
2271 // to cancel the input method's ongoing composition session.
2272 if (webwidget_->confirmComposition())
2273 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
2274 }
[email protected]d4cff272011-05-02 15:46:012275
[email protected]88dbe32f2013-06-20 23:31:362276 UpdateCompositionInfo(true);
[email protected]fa7b1dc2010-06-23 17:53:042277}
2278
[email protected]c68c3e4e2013-01-24 00:36:562279void RenderWidget::didHandleGestureEvent(
2280 const WebGestureEvent& event,
2281 bool event_cancelled) {
2282#if defined(OS_ANDROID)
2283 if (event_cancelled)
2284 return;
2285 if (event.type == WebInputEvent::GestureTap ||
2286 event.type == WebInputEvent::GestureLongPress) {
2287 UpdateTextInputState(SHOW_IME_IF_NEEDED);
2288 }
2289#endif
2290}
2291
[email protected]f103ab72009-09-02 17:10:592292void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:502293 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292294 size_t i = 0;
2295 for (; i < plugin_window_moves_.size(); ++i) {
2296 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582297 if (move.rects_valid) {
2298 plugin_window_moves_[i] = move;
2299 } else {
2300 plugin_window_moves_[i].visible = move.visible;
2301 }
initial.commit09911bf2008-07-26 23:55:292302 break;
2303 }
2304 }
2305
2306 if (i == plugin_window_moves_.size())
2307 plugin_window_moves_.push_back(move);
2308}
[email protected]268654772009-08-06 23:02:042309
2310void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2311 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2312 i != plugin_window_moves_.end(); ++i) {
2313 if (i->window == window) {
2314 plugin_window_moves_.erase(i);
2315 break;
2316 }
2317 }
2318}
[email protected]67bfb83f2011-09-22 03:36:372319
[email protected]b63d58d2012-11-26 22:37:442320void RenderWidget::GetRenderingStats(
2321 WebKit::WebRenderingStatsImpl& stats) const {
[email protected]ba91a792013-02-06 09:48:282322 if (compositor_)
[email protected]635353c2013-03-06 09:11:202323 compositor_->GetRenderingStats(&stats.rendering_stats);
[email protected]b63d58d2012-11-26 22:37:442324
[email protected]62049562013-03-24 00:39:012325 stats.rendering_stats.animation_frame_count +=
2326 software_stats_.animation_frame_count;
2327 stats.rendering_stats.screen_frame_count +=
2328 software_stats_.screen_frame_count;
2329 stats.rendering_stats.total_paint_time +=
2330 software_stats_.total_paint_time;
2331 stats.rendering_stats.total_pixels_painted +=
2332 software_stats_.total_pixels_painted;
[email protected]fef5e3972012-08-07 03:59:472333}
2334
[email protected]e9ff79c2012-10-19 21:31:262335bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:522336 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
2337 if (!gpu_channel)
2338 return false;
2339
2340 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
2341}
2342
[email protected]24ed0432013-04-24 07:50:312343RenderWidgetCompositor* RenderWidget::compositor() const {
2344 return compositor_.get();
2345}
2346
[email protected]3639aa82013-06-04 11:00:042347void RenderWidget::OnSetBrowserRenderingStats(
2348 const BrowserRenderingStats& stats) {
2349 browser_rendering_stats_ = stats;
2350}
2351
2352void RenderWidget::GetBrowserRenderingStats(BrowserRenderingStats* stats) {
2353 *stats = browser_rendering_stats_;
2354}
2355
[email protected]0c2ebef2013-04-03 12:14:102356void RenderWidget::BeginSmoothScroll(
[email protected]0e241b4b2012-08-18 09:06:272357 bool down,
[email protected]ebd8b562012-10-09 14:44:292358 const SmoothScrollCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:192359 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:292360 int mouse_event_x,
2361 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:272362 DCHECK(!callback.is_null());
[email protected]267909d2012-10-20 04:36:192363
2364 ViewHostMsg_BeginSmoothScroll_Params params;
2365 params.scroll_down = down;
2366 params.pixels_to_scroll = pixels_to_scroll;
2367 params.mouse_event_x = mouse_event_x;
2368 params.mouse_event_y = mouse_event_y;
2369
[email protected]4a9dba42013-04-29 18:24:222370 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, params));
2371 pending_smooth_scroll_gesture_ = callback;
[email protected]a39ca1652012-07-13 21:30:582372}
2373
[email protected]67bfb83f2011-09-22 03:36:372374bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
2375 return false;
2376}
[email protected]c3d45532011-10-07 19:20:402377
[email protected]f56c7872013-06-18 12:31:572378bool RenderWidget::WillHandleKeyEvent(const WebKit::WebKeyboardEvent& event) {
2379 return false;
2380}
2381
[email protected]41d86852012-11-07 12:23:242382bool RenderWidget::WillHandleGestureEvent(
2383 const WebKit::WebGestureEvent& event) {
2384 return false;
2385}
2386
[email protected]ce6689f2013-03-29 12:52:552387void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2388 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2389}
2390
[email protected]3d5c243b2012-11-30 00:26:012391bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2392 return true;
2393}
2394
[email protected]3ae68c52013-04-12 06:10:052395WebGraphicsContext3DCommandBufferImpl* RenderWidget::CreateGraphicsContext3D(
[email protected]92fd8c02013-03-29 08:54:152396 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
[email protected]ed7defa2013-03-12 21:29:592397 if (!webwidget_)
2398 return NULL;
[email protected]8f746982013-03-21 06:28:032399 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
2400 new WebGraphicsContext3DCommandBufferImpl(
2401 surface_id(),
2402 GetURLForGraphicsContext3D(),
2403 RenderThreadImpl::current(),
2404 weak_ptr_factory_.GetWeakPtr()));
[email protected]ed7defa2013-03-12 21:29:592405
[email protected]990e4c212013-06-08 05:03:332406 if (!context->InitializeWithDefaultBufferSizes(
[email protected]8f746982013-03-21 06:28:032407 attributes,
2408 false /* bind generates resources */,
2409 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
2410 return NULL;
2411 return context.release();
[email protected]ed7defa2013-03-12 21:29:592412}
2413
[email protected]e9ff79c2012-10-19 21:31:262414} // namespace content