blob: 46cc828f73b7dfae34e7d17ba31a5505ae113ecf [file] [log] [blame]
[email protected]60a50072012-01-11 02:05:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]2cff0052011-03-18 16:51:445#include "content/renderer/render_widget.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]32876ae2011-11-15 22:25:217#include "base/bind.h"
[email protected]4fb66842009-12-04 21:41:008#include "base/command_line.h"
[email protected]366ae242011-05-10 02:23:589#include "base/debug/trace_event.h"
initial.commit09911bf2008-07-26 23:55:2910#include "base/logging.h"
[email protected]3b63f8f42011-03-28 01:54:1511#include "base/memory/scoped_ptr.h"
initial.commit09911bf2008-07-26 23:55:2912#include "base/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3813#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2114#include "base/stl_util.h"
[email protected]8a9d6ca32011-06-06 20:11:3015#include "base/utf_string_conversions.h"
[email protected]661eb9d2009-02-03 02:11:4816#include "build/build_config.h"
[email protected]681ccff2013-03-18 06:13:5217#include "cc/base/switches.h"
18#include "cc/base/thread.h"
19#include "cc/base/thread_impl.h"
[email protected]7f0d825f2013-03-18 07:24:3020#include "cc/output/output_surface.h"
[email protected]556fd292013-03-18 08:03:0421#include "cc/trees/layer_tree_host.h"
[email protected]ed7defa2013-03-12 21:29:5922#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]c084330e02013-04-27 01:08:1523#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1524#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5025#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2926#include "content/public/common/content_switches.h"
[email protected]ed7defa2013-03-12 21:29:5927#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]2847b222013-04-06 00:59:2428#include "content/renderer/gpu/compositor_software_output_device.h"
[email protected]ea5f70a2013-03-07 12:30:3629#include "content/renderer/gpu/input_handler_manager.h"
[email protected]ed7defa2013-03-12 21:29:5930#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]ba91a792013-02-06 09:48:2831#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]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]ed7defa2013-03-12 21:29:5937#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
[email protected]debc8e52013-01-15 03:43:1238#include "third_party/WebKit/Source/Platform/chromium/public/WebPoint.h"
39#include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
40#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
41#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
[email protected]8bd0fe62011-01-17 06:44:3742#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
[email protected]4b1146bc2012-07-10 18:46:0343#include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h"
[email protected]a7547fb2012-03-08 04:43:4444#include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h"
[email protected]8bd0fe62011-01-17 06:44:3745#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
46#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
[email protected]d4cff272011-05-02 15:46:0147#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:3748#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.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]661eb9d2009-02-03 02:11:4861
[email protected]eeb93112013-05-01 19:41:1062#if defined(OS_ANDROID)
63#include "content/renderer/android/synchronous_compositor_output_surface.h"
64#endif
65
[email protected]661eb9d2009-02-03 02:11:4866#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4967#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5268#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4169#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4870#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4471
[email protected]8bd0fe62011-01-17 06:44:3772#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2973
[email protected]fa7b1dc2010-06-23 17:53:0474using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3075using WebKit::WebCursorInfo;
[email protected]41d86852012-11-07 12:23:2476using WebKit::WebGestureEvent;
[email protected]62cb33cae2009-03-27 23:30:2277using WebKit::WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0678using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2879using WebKit::WebNavigationPolicy;
[email protected]a7547fb2012-03-08 04:43:4480using WebKit::WebPagePopup;
[email protected]e99ef6f2011-10-16 01:13:0081using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2882using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5983using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1884using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0185using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5286using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1987using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5288using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2889using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2490using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0491using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1892using WebKit::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:2693
[email protected]6a4d7f62013-01-07 21:32:1394namespace {
95const char* GetEventName(WebInputEvent::Type type) {
96#define CASE_TYPE(t) case WebInputEvent::t: return #t
97 switch(type) {
98 CASE_TYPE(Undefined);
99 CASE_TYPE(MouseDown);
100 CASE_TYPE(MouseUp);
101 CASE_TYPE(MouseMove);
102 CASE_TYPE(MouseEnter);
103 CASE_TYPE(MouseLeave);
104 CASE_TYPE(ContextMenu);
105 CASE_TYPE(MouseWheel);
106 CASE_TYPE(RawKeyDown);
107 CASE_TYPE(KeyDown);
108 CASE_TYPE(KeyUp);
109 CASE_TYPE(Char);
110 CASE_TYPE(GestureScrollBegin);
111 CASE_TYPE(GestureScrollEnd);
112 CASE_TYPE(GestureScrollUpdate);
113 CASE_TYPE(GestureFlingStart);
114 CASE_TYPE(GestureFlingCancel);
115 CASE_TYPE(GestureTap);
[email protected]1c43b0a2013-05-10 07:43:23116 CASE_TYPE(GestureTapUnconfirmed);
[email protected]6a4d7f62013-01-07 21:32:13117 CASE_TYPE(GestureTapDown);
118 CASE_TYPE(GestureTapCancel);
119 CASE_TYPE(GestureDoubleTap);
120 CASE_TYPE(GestureTwoFingerTap);
121 CASE_TYPE(GestureLongPress);
122 CASE_TYPE(GestureLongTap);
123 CASE_TYPE(GesturePinchBegin);
124 CASE_TYPE(GesturePinchEnd);
125 CASE_TYPE(GesturePinchUpdate);
126 CASE_TYPE(TouchStart);
127 CASE_TYPE(TouchMove);
128 CASE_TYPE(TouchEnd);
129 CASE_TYPE(TouchCancel);
[email protected]3ec08ed2013-01-11 15:59:57130 default:
131 // Must include default to let WebKit::WebInputEvent add new event types
132 // before they're added here.
133 DLOG(WARNING) << "Unhandled WebInputEvent type in GetEventName.\n";
134 break;
[email protected]6a4d7f62013-01-07 21:32:13135 }
136#undef CASE_TYPE
[email protected]3ec08ed2013-01-11 15:59:57137 return "";
[email protected]6a4d7f62013-01-07 21:32:13138}
139}
[email protected]e9ff79c2012-10-19 21:31:26140namespace content {
[email protected]62cb33cae2009-03-27 23:30:22141
[email protected]6fd35b72012-03-01 19:46:41142RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]842f10652012-06-06 01:54:04143 const WebKit::WebScreenInfo& screen_info,
[email protected]14392a52012-05-02 20:28:44144 bool swapped_out)
initial.commit09911bf2008-07-26 23:55:29145 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56146 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:11147 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:29148 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30149 init_complete_(false),
[email protected]b4d08452010-10-05 17:34:35150 current_paint_buf_(NULL),
[email protected]d9083762013-03-24 01:36:40151 overdraw_bottom_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29152 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:06153 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:05154 update_reply_pending_(false),
[email protected]847a2582013-03-09 02:29:51155 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09156 need_update_rect_for_auto_resize_(false),
[email protected]65225772011-05-12 21:10:24157 using_asynchronous_swapbuffers_(false),
158 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:29159 did_show_(false),
initial.commit09911bf2008-07-26 23:55:29160 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:09161 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:29162 needs_repainting_on_restore_(false),
163 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49164 handling_input_event_(false),
[email protected]e8f775f2013-02-14 21:00:50165 handling_ime_event_(false),
[email protected]661eb9d2009-02-03 02:11:48166 closing_(false),
[email protected]14392a52012-05-02 20:28:44167 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04168 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45169 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
170 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12171 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48172 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12173 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50174 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21175 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07176 invalidation_task_posted_(false),
[email protected]842f10652012-06-06 01:54:04177 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52178 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]0e241b4b2012-08-18 09:06:27179 throttle_input_events_(true),
[email protected]ed7defa2013-03-12 21:29:59180 is_threaded_compositing_enabled_(false),
[email protected]a2b5ded2013-05-20 21:32:53181 overscroll_notifications_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);
[email protected]a2b5ded2013-05-20 21:32:53191 overscroll_notifications_enabled_ =
192 CommandLine::ForCurrentProcess()->HasSwitch(
193 switches::kEnableOverscrollNotifications);
initial.commit09911bf2008-07-26 23:55:29194}
195
196RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11197 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21198 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35199 if (current_paint_buf_) {
200 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
201 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29202 }
[email protected]992db4c2011-05-12 15:37:15203 // If we are swapped out, we have released already.
204 if (!is_swapped_out_)
205 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29206}
207
[email protected]484955942010-08-19 16:13:18208// static
[email protected]8085dbc82008-09-26 22:53:44209RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:04210 WebKit::WebPopupType popup_type,
211 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29212 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41213 scoped_refptr<RenderWidget> widget(
[email protected]842f10652012-06-06 01:54:04214 new RenderWidget(popup_type, screen_info, false));
[email protected]a635f942012-12-07 10:34:29215 if (widget->Init(opener_id)) { // adds reference on success.
216 return widget;
217 }
218 return NULL;
initial.commit09911bf2008-07-26 23:55:29219}
220
[email protected]484955942010-08-19 16:13:18221// static
222WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
223 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03224 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18225 break;
226 case WebKit::WebPopupTypeSelect:
227 case WebKit::WebPopupTypeSuggestion:
228 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44229 case WebKit::WebPopupTypePage:
230 return WebPagePopup::create(render_widget);
[email protected]4b1146bc2012-07-10 18:46:03231 case WebKit::WebPopupTypeHelperPlugin:
232 return WebKit::WebHelperPlugin::create(render_widget);
[email protected]484955942010-08-19 16:13:18233 default:
234 NOTREACHED();
235 }
236 return NULL;
237}
238
[email protected]a635f942012-12-07 10:34:29239bool RenderWidget::Init(int32 opener_id) {
240 return DoInit(opener_id,
241 RenderWidget::CreateWebWidget(this),
242 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
243 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18244}
245
[email protected]a635f942012-12-07 10:34:29246bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06247 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18248 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29249 DCHECK(!webwidget_);
250
251 if (opener_id != MSG_ROUTING_NONE)
252 opener_id_ = opener_id;
253
[email protected]484955942010-08-19 16:13:18254 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29255
[email protected]380244092011-10-07 17:26:27256 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29257 if (result) {
[email protected]380244092011-10-07 17:26:27258 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29259 // Take a reference on behalf of the RenderThread. This will be balanced
260 // when we receive ViewMsg_Close.
261 AddRef();
[email protected]a635f942012-12-07 10:34:29262 return true;
initial.commit09911bf2008-07-26 23:55:29263 } else {
[email protected]a635f942012-12-07 10:34:29264 // The above Send can fail when the tab is closing.
265 return false;
initial.commit09911bf2008-07-26 23:55:29266 }
267}
268
[email protected]fc4404d2012-11-07 19:53:30269// This is used to complete pending inits and non-pending inits.
270void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29271 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29272
[email protected]fc4404d2012-11-07 19:53:30273 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42274
[email protected]8926c602013-01-23 05:32:06275 if (webwidget_ && is_threaded_compositing_enabled_) {
276 webwidget_->enterForceCompositingMode(true);
277 }
[email protected]ba91a792013-02-06 09:48:28278 if (compositor_) {
279 compositor_->setSurfaceReady();
[email protected]479b0172012-10-29 19:27:09280 }
[email protected]05a980d7a2012-02-07 22:16:42281 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29282
[email protected]6de74452009-02-25 18:04:59283 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29284}
285
[email protected]992db4c2011-05-12 15:37:15286void RenderWidget::SetSwappedOut(bool is_swapped_out) {
287 // We should only toggle between states.
288 DCHECK(is_swapped_out_ != is_swapped_out);
289 is_swapped_out_ = is_swapped_out;
290
291 // If we are swapping out, we will call ReleaseProcess, allowing the process
292 // to exit if all of its RenderViews are swapped out. We wait until the
293 // WasSwappedOut call to do this, to avoid showing the sad tab.
294 // If we are swapping in, we call AddRefProcess to prevent the process from
295 // exiting.
296 if (!is_swapped_out)
297 RenderProcess::current()->AddRefProcess();
298}
299
[email protected]34bb3ac2013-03-08 02:41:28300bool RenderWidget::AllowPartialSwap() const {
301 return true;
302}
303
[email protected]ccc1722e2013-05-06 19:43:07304bool RenderWidget::SynchronouslyDisableVSync() const {
305#if defined(OS_ANDROID)
306 if (CommandLine::ForCurrentProcess()->HasSwitch(
307 switches::kEnableSynchronousRendererCompositor)) {
308 return true;
309 }
310#endif
311 return false;
312}
313
[email protected]a95986a82010-12-24 06:19:28314bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
315 bool handled = true;
316 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15317 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22318 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
319 OnCursorVisibilityChange)
[email protected]c084330e02013-04-27 01:08:15320 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
321 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]a95986a82010-12-24 06:19:28322 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
323 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
324 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54325 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28326 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41327 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]992db4c2011-05-12 15:37:15328 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28329 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]ed7defa2013-03-12 21:29:59330 IPC_MESSAGE_HANDLER(ViewMsg_SwapBuffers_ACK,
331 OnViewContextSwapBuffersComplete)
[email protected]a95986a82010-12-24 06:19:28332 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
333 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
334 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]3d9ec5052013-01-02 22:05:25335 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnPaintAtSize)
336 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
337 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, OnSmoothScrollCompleted)
[email protected]a95986a82010-12-24 06:19:28338 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
339 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]6131a642012-06-15 23:26:53340 IPC_MESSAGE_HANDLER(ViewMsg_ScreenInfoChanged, OnScreenInfoChanged)
[email protected]80ad8622012-11-07 16:33:03341 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]105dffb42013-02-20 03:46:21342#if defined(OS_ANDROID)
343 IPC_MESSAGE_HANDLER(ViewMsg_ImeBatchStateChanged, OnImeBatchStateChanged)
[email protected]2384b6c2013-02-28 23:58:51344 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21345#endif
[email protected]51a49502013-03-23 01:50:19346 IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot)
[email protected]a95986a82010-12-24 06:19:28347 IPC_MESSAGE_UNHANDLED(handled = false)
348 IPC_END_MESSAGE_MAP()
349 return handled;
350}
initial.commit09911bf2008-07-26 23:55:29351
352bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15353 // Don't send any messages after the browser has told us to close, and filter
354 // most outgoing messages while swapped out.
355 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26356 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11357 closing_) {
initial.commit09911bf2008-07-26 23:55:29358 delete message;
359 return false;
360 }
361
362 // If given a messsage without a routing ID, then assign our routing ID.
363 if (message->routing_id() == MSG_ROUTING_NONE)
364 message->set_routing_id(routing_id_);
365
[email protected]380244092011-10-07 17:26:27366 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44367}
368
[email protected]61e2b3cc2012-03-02 16:13:34369void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44370 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40371 float overdraw_bottom_height,
[email protected]61e2b3cc2012-03-02 16:13:34372 const gfx::Rect& resizer_rect,
373 bool is_fullscreen,
374 ResizeAck resize_ack) {
375 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
376 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
377 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
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
411 // Resize should have caused an invalidation of the entire view.
412 DCHECK(new_size.IsEmpty() || is_accelerated_compositing_active_ ||
413 paint_aggregator_.HasPendingUpdate());
[email protected]1f792d52013-05-22 06:52:45414 } else if (size_browser_expects_ == new_size) {
[email protected]632c4382013-05-15 08:58:45415 resize_ack = NO_RESIZE_ACK;
416 }
417
418 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
419 // For empty size or empty physical_backing_size, there is no next paint
420 // (along with which to send the ack) until they are set to non-empty.
[email protected]ff475a322012-03-14 00:05:35421 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34422 }
423
[email protected]20fbfc22013-05-08 20:50:58424 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45425 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58426 set_next_paint_is_resize_ack();
427
[email protected]61e2b3cc2012-03-02 16:13:34428 if (fullscreen_change)
429 DidToggleFullscreen();
430
431 // If a resize ack is requested and it isn't set-up, then no more resizes will
432 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45433 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29434}
435
436void RenderWidget::OnClose() {
437 if (closing_)
438 return;
439 closing_ = true;
440
441 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03442 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27443 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03444 SetHidden(false);
445 }
initial.commit09911bf2008-07-26 23:55:29446
initial.commit09911bf2008-07-26 23:55:29447 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25448 // now. Post a task that only gets invoked when there are no nested message
449 // loops.
[email protected]dd32b1272013-05-04 14:17:11450 base::MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29451 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25452
453 // Balances the AddRef taken when we called AddRoute.
454 Release();
initial.commit09911bf2008-07-26 23:55:29455}
456
[email protected]61e2b3cc2012-03-02 16:13:34457// Got a response from the browser after the renderer decided to create a new
458// view.
[email protected]fc4404d2012-11-07 19:53:30459void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34460 DCHECK(routing_id_ != MSG_ROUTING_NONE);
461
[email protected]fc4404d2012-11-07 19:53:30462 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34463}
464
[email protected]f21c613a2009-02-12 14:46:17465void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44466 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40467 float overdraw_bottom_height,
[email protected]ee41e7d22011-10-14 19:34:09468 const gfx::Rect& resizer_rect,
469 bool is_fullscreen) {
[email protected]d9083762013-03-24 01:36:40470 Resize(new_size, physical_backing_size, overdraw_bottom_height, resizer_rect,
471 is_fullscreen, SEND_RESIZE_ACK);
[email protected]1f792d52013-05-22 06:52:45472 size_browser_expects_ = new_size;
initial.commit09911bf2008-07-26 23:55:29473}
474
[email protected]b5913d72012-02-07 22:26:54475void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
476 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59477 gfx::Rect view_rect(size_);
478
[email protected]ce112fe2012-10-29 22:52:18479 gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_);
[email protected]b9769d82012-02-10 00:23:59480 if (!old_damage_rect.IsEmpty())
481 paint_aggregator_.InvalidateRect(old_damage_rect);
482
[email protected]ce112fe2012-10-29 22:52:18483 gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect);
[email protected]b9769d82012-02-10 00:23:59484 if (!new_damage_rect.IsEmpty())
485 paint_aggregator_.InvalidateRect(new_damage_rect);
486
[email protected]b5913d72012-02-07 22:26:54487 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59488
[email protected]b5913d72012-02-07 22:26:54489 if (webwidget_)
490 webwidget_->didChangeWindowResizerRect();
491 }
492}
493
initial.commit09911bf2008-07-26 23:55:29494void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31495 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29496 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03497 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29498}
499
[email protected]9e2e4632012-07-27 16:38:41500void RenderWidget::OnWasShown(bool needs_repainting) {
501 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29502 // During shutdown we can just ignore this message.
503 if (!webwidget_)
504 return;
505
506 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03507 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29508
509 if (!needs_repainting && !needs_repainting_on_restore_)
510 return;
511 needs_repainting_on_restore_ = false;
512
[email protected]d65adb12010-04-28 17:26:49513 // Tag the next paint as a restore ack, which is picked up by
514 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29515 set_next_paint_is_restore_ack();
516
517 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56518 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46519 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
520 } else {
521 scheduleComposite();
522 }
initial.commit09911bf2008-07-26 23:55:29523}
524
[email protected]992db4c2011-05-12 15:37:15525void RenderWidget::OnWasSwappedOut() {
526 // If we have been swapped out and no one else is using this process,
527 // it's safe to exit now. If we get swapped back in, we will call
528 // AddRefProcess in SetSwappedOut.
529 if (is_swapped_out_)
530 RenderProcess::current()->ReleaseProcess();
531}
532
[email protected]53d3f302009-12-21 04:42:05533void RenderWidget::OnRequestMoveAck() {
534 DCHECK(pending_window_rect_count_);
535 pending_window_rect_count_--;
536}
537
538void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58539 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21540 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05541 update_reply_pending_ = false;
[email protected]1f792d52013-05-22 06:52:45542 size_browser_expects_ = size_;
[email protected]53d3f302009-12-21 04:42:05543
[email protected]b4d08452010-10-05 17:34:35544 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
545 // have no current paint buffer.
546 if (current_paint_buf_) {
547 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
548 current_paint_buf_ = NULL;
549 }
550
[email protected]65225772011-05-12 21:10:24551 // If swapbuffers is still pending, then defer the update until the
552 // swapbuffers occurs.
553 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
554 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
555 return;
556 }
557
[email protected]29ed96a2012-02-04 18:12:16558 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18559 if (!is_accelerated_compositing_active_) {
560 DidFlushPaint();
561 }
[email protected]a2f6bc112009-06-27 16:27:25562
initial.commit09911bf2008-07-26 23:55:29563 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24564 DoDeferredUpdateAndSendInputAck();
565}
566
[email protected]d0be63772011-12-20 23:18:04567bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]ed7defa2013-03-12 21:29:59568 // Contexts using the command buffer support asynchronous swapbuffers.
569 // See RenderWidget::CreateOutputSurface().
[email protected]8f746982013-03-21 06:28:03570 if (RenderThreadImpl::current()->compositor_message_loop_proxy())
[email protected]ed7defa2013-03-12 21:29:59571 return false;
572
573 return true;
574}
575
576GURL RenderWidget::GetURLForGraphicsContext3D() {
577 return GURL();
[email protected]65225772011-05-12 21:10:24578}
579
[email protected]479b0172012-10-29 19:27:09580bool RenderWidget::ForceCompositingModeEnabled() {
581 return false;
582}
583
[email protected]ba91a792013-02-06 09:48:28584scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface() {
[email protected]c3e32ed42013-05-02 05:07:13585 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]a1811b8912013-05-09 15:35:19586
587#if defined(OS_ANDROID)
588 if (command_line.HasSwitch(switches::kEnableSynchronousRendererCompositor)) {
589 return scoped_ptr<cc::OutputSurface>(
590 new SynchronousCompositorOutputSurface(routing_id()));
591 }
592#endif
593
[email protected]8bbe3a92013-05-12 00:58:35594 if (command_line.HasSwitch(switches::kEnableSoftwareCompositingGLAdapter)) {
595 return scoped_ptr<cc::OutputSurface>(
596 new CompositorOutputSurface(routing_id(), NULL,
597 new CompositorSoftwareOutputDevice()));
598 }
599
[email protected]ed7defa2013-03-12 21:29:59600 // Explicitly disable antialiasing for the compositor. As of the time of
601 // this writing, the only platform that supported antialiasing for the
602 // compositor was Mac OS X, because the on-screen OpenGL context creation
603 // code paths on Windows and Linux didn't yet have multisampling support.
604 // Mac OS X essentially always behaves as though it's rendering offscreen.
605 // Multisampling has a heavy cost especially on devices with relatively low
606 // fill rate like most notebooks, and the Mac implementation would need to
607 // be optimized to resolve directly into the IOSurface shared between the
608 // GPU and browser processes. For these reasons and to avoid platform
609 // disparities we explicitly disable antialiasing.
610 WebKit::WebGraphicsContext3D::Attributes attributes;
611 attributes.antialias = false;
612 attributes.shareResources = true;
613 attributes.noAutomaticFlushes = true;
[email protected]a6886502013-05-16 20:59:18614 attributes.depth = false;
615 attributes.stencil = false;
[email protected]bec084292013-05-21 21:31:44616 if (command_line.HasSwitch(cc::switches::kForceDirectLayerDrawing))
617 attributes.stencil = true;
[email protected]3ae68c52013-04-12 06:10:05618 WebGraphicsContext3DCommandBufferImpl* context =
619 CreateGraphicsContext3D(attributes);
[email protected]8bbe3a92013-05-12 00:58:35620 if (!context)
621 return scoped_ptr<cc::OutputSurface>();
[email protected]ed7defa2013-03-12 21:29:59622
[email protected]2847b222013-04-06 00:59:24623 bool composite_to_mailbox =
[email protected]7b45b5762013-05-08 14:36:56624 command_line.HasSwitch(cc::switches::kCompositeToMailbox) &&
625 !command_line.HasSwitch(switches::kEnableDelegatedRenderer);
[email protected]2847b222013-04-06 00:59:24626 // No swap throttling yet when compositing on the main thread.
627 DCHECK(!composite_to_mailbox || is_threaded_compositing_enabled_);
628 return scoped_ptr<cc::OutputSurface>(composite_to_mailbox ?
629 new MailboxOutputSurface(routing_id(), context, NULL) :
630 new CompositorOutputSurface(routing_id(), context, NULL));
[email protected]ba91a792013-02-06 09:48:28631}
632
[email protected]ed7defa2013-03-12 21:29:59633void RenderWidget::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24634 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21635 while (!updates_pending_swap_.empty()) {
636 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
637 updates_pending_swap_.pop_front();
638 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
639 // compositing pass, hence doesn't require an UpdateRect message.
640 if (msg)
641 Send(msg);
642 }
[email protected]65225772011-05-12 21:10:24643 num_swapbuffers_complete_pending_ = 0;
644 using_asynchronous_swapbuffers_ = false;
645 // Schedule another frame so the compositor learns about it.
646 scheduleComposite();
647}
648
[email protected]ed7defa2013-03-12 21:29:59649void RenderWidget::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:08650 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21651
652 if (using_asynchronous_swapbuffers_) {
653 ViewHostMsg_UpdateRect* msg = NULL;
654 // pending_update_params_ can be NULL if the swap doesn't correspond to an
655 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
656 // message.
[email protected]59383c782013-04-17 16:43:27657 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:21658 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
659 pending_update_params_.reset();
660 }
661 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08662 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21663 }
[email protected]37a6f302011-07-11 23:43:08664}
665
[email protected]ed7defa2013-03-12 21:29:59666void RenderWidget::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24667 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16668
[email protected]404939f2012-06-01 04:06:18669 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16670 DidFlushPaint();
671
[email protected]65225772011-05-12 21:10:24672 // When compositing deactivates, we reset the swapbuffers pending count. The
673 // swapbuffers acks may still arrive, however.
674 if (num_swapbuffers_complete_pending_ == 0) {
675 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
676 return;
677 }
[email protected]aa4117f2011-12-09 22:19:21678 DCHECK(!updates_pending_swap_.empty());
679 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
680 updates_pending_swap_.pop_front();
681 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
682 // compositing pass, hence doesn't require an UpdateRect message.
683 if (msg)
684 Send(msg);
[email protected]65225772011-05-12 21:10:24685 num_swapbuffers_complete_pending_--;
686
687 // If update reply is still pending, then defer the update until that reply
688 // occurs.
[email protected]d0be63772011-12-20 23:18:04689 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24690 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
691 return;
692 }
693
694 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06695 // when we were previously rendering. However, if an invalidation task is not
696 // posted, there may be software rendering work pending. In that case, don't
697 // early out.
698 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24699 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
700 return;
701 }
702
[email protected]cc66e682012-10-02 06:48:18703 // Do not call DoDeferredUpdate unless there's animation work to be done or
704 // a real invalidation. This prevents rendering in response to a swapbuffers
705 // callback coming back after we've navigated away from the page that
706 // generated it.
707 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
708 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
709 return;
710 }
711
[email protected]65225772011-05-12 21:10:24712 // Continue painting if necessary...
713 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29714}
715
[email protected]0dea1652012-12-14 00:09:09716void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
[email protected]c2eaa8f2013-05-10 02:41:55717 const cc::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:09718 bool is_keyboard_shortcut) {
[email protected]5dd768212009-08-13 23:34:49719 handling_input_event_ = true;
[email protected]0dea1652012-12-14 00:09:09720 if (!input_event) {
[email protected]5dd768212009-08-13 23:34:49721 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29722 return;
[email protected]5dd768212009-08-13 23:34:49723 }
initial.commit09911bf2008-07-26 23:55:29724
[email protected]b4841e1c2013-05-16 22:30:10725 const char* const event_name = GetEventName(input_event->type);
726 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent",
727 "event", event_name);
728
[email protected]c2eaa8f2013-05-10 02:41:55729 if (compositor_)
730 compositor_->SetLatencyInfo(latency_info);
731
[email protected]6a4d7f62013-01-07 21:32:13732 base::TimeDelta now = base::TimeDelta::FromInternalValue(
733 base::TimeTicks::Now().ToInternalValue());
734
735 int64 delta = static_cast<int64>(
736 (now.InSecondsF() - input_event->timeStampSeconds) *
737 base::Time::kMicrosecondsPerSecond);
738 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer", delta, 0, 1000000, 100);
[email protected]de415552013-01-23 04:12:17739 base::HistogramBase* counter_for_type =
[email protected]bafdc5d52013-02-27 18:18:48740 base::Histogram::FactoryGet(
[email protected]b4841e1c2013-05-16 22:30:10741 base::StringPrintf("Event.Latency.Renderer.%s", event_name),
[email protected]bafdc5d52013-02-27 18:18:48742 0,
743 1000000,
[email protected]6a4d7f62013-01-07 21:32:13744 100,
[email protected]de415552013-01-23 04:12:17745 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]bafdc5d52013-02-27 18:18:48746 counter_for_type->Add(delta);
[email protected]6a4d7f62013-01-07 21:32:13747
[email protected]67bfb83f2011-09-22 03:36:37748 bool prevent_default = false;
749 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26750 const WebMouseEvent& mouse_event =
751 *static_cast<const WebMouseEvent*>(input_event);
752 TRACE_EVENT2("renderer", "HandleMouseMove",
753 "x", mouse_event.x, "y", mouse_event.y);
754 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37755 }
756
[email protected]41d86852012-11-07 12:23:24757 if (WebInputEvent::isGestureEventType(input_event->type)) {
758 const WebGestureEvent& gesture_event =
759 *static_cast<const WebGestureEvent*>(input_event);
760 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
761 }
762
[email protected]3ebcc7c2013-01-09 05:34:46763 if (input_event->type == WebInputEvent::GestureTap ||
764 input_event->type == WebInputEvent::GestureLongPress)
765 resetInputMethod();
766
[email protected]67bfb83f2011-09-22 03:36:37767 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12768 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
769 suppress_next_char_events_ = false;
770 if (!processed && webwidget_)
771 processed = webwidget_->handleInputEvent(*input_event);
772 }
773
774 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
775 // it's not processed by webkit, then we need to suppress the upcoming Char
776 // events.
777 if (!processed && is_keyboard_shortcut)
778 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29779
[email protected]3d5c243b2012-11-30 00:26:01780 InputEventAckState ack_result = processed ?
781 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
782 if (!processed && input_event->type == WebInputEvent::TouchStart) {
783 const WebTouchEvent& touch_event =
784 *static_cast<const WebTouchEvent*>(input_event);
785 ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ?
786 INPUT_EVENT_ACK_STATE_NOT_CONSUMED :
787 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
788 }
789
[email protected]a9fb30aa2011-10-06 06:58:46790 IPC::Message* response =
[email protected]c084330e02013-04-27 01:08:15791 new InputHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
792 ack_result);
[email protected]3391a0772012-03-28 00:32:07793 bool event_type_gets_rate_limited =
794 input_event->type == WebInputEvent::MouseMove ||
795 input_event->type == WebInputEvent::MouseWheel ||
796 WebInputEvent::isTouchEventType(input_event->type);
[email protected]8926c602013-01-23 05:32:06797
798 bool frame_pending = paint_aggregator_.HasPendingUpdate();
799 if (is_accelerated_compositing_active_) {
[email protected]ba91a792013-02-06 09:48:28800 frame_pending = compositor_ &&
801 compositor_->commitRequested();
[email protected]8926c602013-01-23 05:32:06802 }
803
[email protected]3391a0772012-03-28 00:32:07804 bool is_input_throttled =
[email protected]ce2b28e2012-08-09 15:53:57805 throttle_input_events_ &&
[email protected]8926c602013-01-23 05:32:06806 frame_pending;
[email protected]e2824412009-02-27 01:57:05807
[email protected]f8868d72012-04-27 19:13:03808 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24809 // We want to rate limit the input events in this case, so we'll wait for
810 // painting to finish before ACKing this message.
[email protected]59383c782013-04-17 16:43:27811 if (pending_input_event_ack_) {
[email protected]353a34c2010-05-28 23:35:17812 // As two different kinds of events could cause us to postpone an ack
813 // we send it now, if we have one pending. The Browser should never
814 // send us the same kind of event we are delaying the ack for.
815 Send(pending_input_event_ack_.release());
816 }
[email protected]12fbad812009-09-01 18:21:24817 pending_input_event_ack_.reset(response);
818 } else {
819 Send(response);
820 }
821
[email protected]3306f262012-09-21 19:20:42822#if defined(OS_ANDROID)
823 // Allow the IME to be shown when the focus changes as a consequence
824 // of a processed touch end event.
825 if (input_event->type == WebInputEvent::TouchEnd && processed)
826 UpdateTextInputState(SHOW_IME_IF_NEEDED);
827#endif
828
[email protected]5dd768212009-08-13 23:34:49829 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48830
[email protected]67bfb83f2011-09-22 03:36:37831 if (!prevent_default) {
832 if (WebInputEvent::isKeyboardEventType(input_event->type))
833 DidHandleKeyEvent();
834 if (WebInputEvent::isMouseEventType(input_event->type))
835 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24836 if (WebInputEvent::isTouchEventType(input_event->type))
837 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37838 }
initial.commit09911bf2008-07-26 23:55:29839}
840
[email protected]34202de2013-05-06 23:36:22841void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
842 if (webwidget_)
843 webwidget_->setCursorVisibilityState(is_visible);
844}
845
initial.commit09911bf2008-07-26 23:55:29846void RenderWidget::OnMouseCaptureLost() {
847 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28848 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29849}
850
851void RenderWidget::OnSetFocus(bool enable) {
852 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33853 if (webwidget_)
854 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29855}
856
857void RenderWidget::ClearFocus() {
858 // We may have got the focus from the browser before this gets processed, in
859 // which case we do not want to unfocus ourself.
860 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28861 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29862}
863
[email protected]2d5d09d52009-06-15 14:29:21864void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00865 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21866 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06867 TRACE_EVENT2("renderer", "PaintRect",
868 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:45869
870 const bool kEnableGpuBenchmarking =
871 CommandLine::ForCurrentProcess()->HasSwitch(
872 switches::kEnableGpuBenchmarking);
[email protected]4fb66842009-12-04 21:41:00873 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21874
875 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00876 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
877 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03878
[email protected]699ab0d2009-04-23 23:19:14879 // If there is a custom background, tile it.
880 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14881 SkPaint paint;
[email protected]4e29afd2012-12-04 04:07:11882 skia::RefPtr<SkShader> shader = skia::AdoptRef(
883 SkShader::CreateBitmapShader(background_,
884 SkShader::kRepeat_TileMode,
885 SkShader::kRepeat_TileMode));
886 paint.setShader(shader.get());
[email protected]fb10ec5b2011-10-24 17:54:20887
888 // Use kSrc_Mode to handle background_ transparency properly.
889 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
890
891 // Canvas could contain multiple update rects. Clip to given rect so that
892 // we don't accidentally clear other update rects.
893 canvas->save();
[email protected]aa7e7a12013-02-22 13:37:44894 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]1835b9e2012-02-28 13:12:48895 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14896 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20897 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14898 }
899
[email protected]719b36f2010-12-22 20:36:46900 // First see if this rect is a plugin that can paint itself faster.
901 TransportDIB* optimized_dib = NULL;
902 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:20903 float dib_scale_factor;
[email protected]719b36f2010-12-22 20:36:46904 webkit::ppapi::PluginInstance* optimized_instance =
905 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
906 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:20907 &optimized_copy_rect,
908 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:46909 if (optimized_instance) {
910 // This plugin can be optimize-painted and we can just ask it to paint
911 // itself. We don't actually need the TransportDIB in this case.
912 //
913 // This is an optimization for PPAPI plugins that know they're on top of
914 // the page content. If this rect is inside such a plugin, we can save some
915 // time and avoid re-rendering the page content which we know will be
916 // covered by the plugin later (this time can be significant, especially
917 // for a playing movie that is invalidating a lot).
918 //
919 // In the plugin movie case, hopefully the similar call to
920 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
921 // painting, because that avoids copying the plugin image to a different
922 // paint rect. Unfortunately, if anything on the page is animating other
923 // than the movie, it break this optimization since the union of the
924 // invalid regions will be larger than the plugin.
925 //
926 // This code optimizes that case, where we can still avoid painting in
927 // WebKit and filling the background (which can be slow) and just painting
928 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
929 // required.
[email protected]63ab54262012-11-09 15:58:45930 base::TimeTicks paint_begin_ticks;
931 if (kEnableGpuBenchmarking)
932 paint_begin_ticks = base::TimeTicks::HighResNow();
933
[email protected]df59dd42012-09-14 22:56:30934 SkAutoCanvasRestore auto_restore(canvas, true);
935 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]719b36f2010-12-22 20:36:46936 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27937 optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:21938 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45939 if (kEnableGpuBenchmarking) {
940 base::TimeDelta paint_time =
941 base::TimeTicks::HighResNow() - paint_begin_ticks;
942 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01943 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45944 }
[email protected]719b36f2010-12-22 20:36:46945 } else {
946 // Normal painting case.
[email protected]63ab54262012-11-09 15:58:45947 base::TimeTicks paint_begin_ticks;
948 if (kEnableGpuBenchmarking)
949 paint_begin_ticks = base::TimeTicks::HighResNow();
950
[email protected]719b36f2010-12-22 20:36:46951 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
[email protected]63ab54262012-11-09 15:58:45952
953 if (kEnableGpuBenchmarking) {
954 base::TimeDelta paint_time =
955 base::TimeTicks::HighResNow() - paint_begin_ticks;
956 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01957 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45958 }
[email protected]719b36f2010-12-22 20:36:46959
960 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35961 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46962 }
initial.commit09911bf2008-07-26 23:55:29963
[email protected]4fb66842009-12-04 21:41:00964 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00965 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45966
967 if (kEnableGpuBenchmarking) {
[email protected]63ab54262012-11-09 15:58:45968 int64 num_pixels_processed = rect.width() * rect.height();
[email protected]62049562013-03-24 00:39:01969 software_stats_.total_pixels_painted += num_pixels_processed;
[email protected]63ab54262012-11-09 15:58:45970 }
[email protected]4fb66842009-12-04 21:41:00971}
972
973void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
974 skia::PlatformCanvas* canvas) {
975 static bool kPaintBorder =
976 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
977 if (!kPaintBorder)
978 return;
979
[email protected]53d3f302009-12-21 04:42:05980 // Cycle through these colors to help distinguish new paint rects.
981 const SkColor colors[] = {
982 SkColorSetARGB(0x3F, 0xFF, 0, 0),
983 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
984 SkColorSetARGB(0x3F, 0, 0, 0xFF),
985 };
986 static int color_selector = 0;
987
[email protected]4fb66842009-12-04 21:41:00988 SkPaint paint;
989 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05990 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00991 paint.setStrokeWidth(1);
992
993 SkIRect irect;
994 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
995 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29996}
997
[email protected]52ccd0ea2011-02-16 01:09:05998void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30999 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:301000 if (!animation_update_pending_) {
1001 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:591002 return;
[email protected]921244e42011-07-20 16:36:301003 }
[email protected]bd37ae252011-06-03 01:28:181004 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:591005 // Record when we fired (according to base::Time::Now()) relative to when
1006 // we posted the task to quantify how much the base::Time/base::TimeTicks
1007 // skew is affecting animations.
1008 base::TimeDelta animation_callback_delay = base::Time::Now() -
1009 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
1010 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
1011 animation_callback_delay,
1012 base::TimeDelta::FromMilliseconds(0),
1013 base::TimeDelta::FromMilliseconds(30),
1014 25);
1015 }
[email protected]65225772011-05-12 21:10:241016 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:241017}
1018
[email protected]52ccd0ea2011-02-16 01:09:051019void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:591020 if (!animation_update_pending_)
1021 return;
[email protected]bd37ae252011-06-03 01:28:181022
1023 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:331024 base::TimeDelta animationInterval = IsRenderingVSynced() ?
1025 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:181026
[email protected]7c4329e2011-02-18 22:02:591027 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:451028
1029 // animation_floor_time_ is the earliest time that we should animate when
1030 // using the dead reckoning software scheduler. If we're using swapbuffers
1031 // complete callbacks to rate limit, we can ignore this floor.
1032 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:301033 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:331034 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:181035 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:591036 // running animation callbacks so that if a callback requests another
1037 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:381038 animation_timer_.Stop();
1039 animation_timer_.Start(FROM_HERE, animationInterval, this,
1040 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:591041 animation_update_pending_ = false;
[email protected]ba91a792013-02-06 09:48:281042 if (is_accelerated_compositing_active_ && compositor_) {
[email protected]635353c2013-03-06 09:11:201043 compositor_->Animate(base::TimeTicks::Now());
[email protected]8926c602013-01-23 05:32:061044 } else {
[email protected]635353c2013-03-06 09:11:201045 double frame_begin_time =
1046 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
1047 webwidget_->animate(frame_begin_time);
[email protected]8926c602013-01-23 05:32:061048 }
[email protected]7c4329e2011-02-18 22:02:591049 return;
[email protected]5f8b1022011-01-21 23:34:501050 }
[email protected]bd37ae252011-06-03 01:28:181051 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:381052 if (!animation_timer_.IsRunning()) {
1053 // This code uses base::Time::Now() to calculate the floor and next fire
1054 // time because javascript's Date object uses base::Time::Now(). The
1055 // message loop uses base::TimeTicks, which on windows can have a
1056 // different granularity than base::Time.
1057 // The upshot of all this is that this function might be called before
1058 // base::Time::Now() has advanced past the animation_floor_time_. To
1059 // avoid exposing this delay to javascript, we keep posting delayed
1060 // tasks until base::Time::Now() has advanced far enough.
1061 base::TimeDelta delay = animation_floor_time_ - now;
1062 animation_timer_.Start(FROM_HERE, delay, this,
1063 &RenderWidget::AnimationCallback);
1064 }
[email protected]5f8b1022011-01-21 23:34:501065}
1066
[email protected]bd37ae252011-06-03 01:28:181067bool RenderWidget::IsRenderingVSynced() {
1068 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
1069 // not caught by this check. This will lead to artificially low frame rates
1070 // for people who force vsync off at a driver level and expect Chrome to speed
1071 // up.
1072 return !has_disable_gpu_vsync_switch_;
1073}
1074
[email protected]65225772011-05-12 21:10:241075void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:061076 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:241077 invalidation_task_posted_ = false;
1078 DoDeferredUpdateAndSendInputAck();
1079}
1080
1081void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:051082 DoDeferredUpdate();
1083
[email protected]59383c782013-04-17 16:43:271084 if (pending_input_event_ack_)
[email protected]52ccd0ea2011-02-16 01:09:051085 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:211086}
1087
[email protected]552e6002009-11-19 05:24:571088void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:581089 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:081090
[email protected]65225772011-05-12 21:10:241091 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:291092 return;
[email protected]05a980d7a2012-02-07 22:16:421093
[email protected]fc4404d2012-11-07 19:53:301094 if (!init_complete_) {
1095 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:421096 return;
1097 }
[email protected]aa4117f2011-12-09 22:19:211098 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:241099 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
1100 return;
1101 }
[email protected]9ca84622011-06-02 23:46:391102 if (is_accelerated_compositing_active_ &&
1103 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:241104 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
1105 return;
1106 }
initial.commit09911bf2008-07-26 23:55:291107
[email protected]552e6002009-11-19 05:24:571108 // Suppress updating when we are hidden.
[email protected]e3d92a7f2013-01-10 02:35:051109 if (is_hidden_ || size_.IsEmpty() || is_swapped_out_) {
[email protected]552e6002009-11-19 05:24:571110 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:291111 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:241112 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:291113 return;
1114 }
1115
[email protected]05a980d7a2012-02-07 22:16:421116 if (is_accelerated_compositing_active_)
1117 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
1118
[email protected]0fb93f52011-05-18 23:13:561119 // Tracking of frame rate jitter
1120 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]38ce4e7b2013-02-23 06:17:371121 InstrumentWillBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:051122 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:501123
[email protected]f98d7e3c2010-09-13 22:30:461124 // Layout may generate more invalidation. It may also enable the
1125 // GPU acceleration, so make sure to run layout before we send the
1126 // GpuRenderingActivated message.
1127 webwidget_->layout();
1128
[email protected]dcca3aa92012-02-17 23:03:371129 // The following two can result in further layout and possibly
1130 // enable GPU acceleration so they need to be called before any painting
1131 // is done.
[email protected]3306f262012-09-21 19:20:421132 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]dcca3aa92012-02-17 23:03:371133 UpdateSelectionBounds();
1134
[email protected]5f8b1022011-01-21 23:34:501135 // Suppress painting if nothing is dirty. This has to be done after updating
1136 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:241137 if (!paint_aggregator_.HasPendingUpdate()) {
1138 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]38ce4e7b2013-02-23 06:17:371139 InstrumentDidCancelFrame();
[email protected]5f8b1022011-01-21 23:34:501140 return;
[email protected]65225772011-05-12 21:10:241141 }
[email protected]5f8b1022011-01-21 23:34:501142
[email protected]479b0172012-10-29 19:27:091143 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:361144 !is_threaded_compositing_enabled_ &&
[email protected]479b0172012-10-29 19:27:091145 ForceCompositingModeEnabled()) {
1146 webwidget_->enterForceCompositingMode(true);
1147 }
1148
[email protected]872ae5b2011-05-26 20:20:501149 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:561150 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:041151 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:561152 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
1153 delay,
1154 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411155 base::TimeDelta::FromMilliseconds(120),
1156 60);
[email protected]d0be63772011-12-20 23:18:041157 } else {
[email protected]0fb93f52011-05-18 23:13:561158 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
1159 delay,
1160 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411161 base::TimeDelta::FromMilliseconds(120),
1162 60);
[email protected]d0be63772011-12-20 23:18:041163 }
[email protected]872ae5b2011-05-26 20:20:501164
1165 // Calculate filtered time per frame:
1166 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
1167 filtered_time_per_frame_ =
1168 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:561169 }
1170 last_do_deferred_update_time_ = frame_begin_ticks;
1171
[email protected]fef5e3972012-08-07 03:59:471172 if (!is_accelerated_compositing_active_) {
[email protected]62049562013-03-24 00:39:011173 software_stats_.animation_frame_count++;
1174 software_stats_.screen_frame_count++;
[email protected]fef5e3972012-08-07 03:59:471175 }
1176
[email protected]552e6002009-11-19 05:24:571177 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:291178 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:301179 PaintAggregator::PendingUpdate update;
1180 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:291181
[email protected]53d3f302009-12-21 04:42:051182 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:181183 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:291184
[email protected]29ed96a2012-02-04 18:12:161185 // Notify derived classes that we're about to initiate a paint.
1186 WillInitiatePaint();
1187
[email protected]ca4847f2010-09-24 05:39:151188 // A plugin may be able to do an optimized paint. First check this, in which
1189 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:461190 // This optimization allows PPAPI plugins that declare themselves on top of
1191 // the page (like a traditional windowed plugin) to be able to animate (think
1192 // movie playing) without repeatedly re-painting the page underneath, or
1193 // copying the plugin backing store (since we can send the plugin's backing
1194 // store directly to the browser).
1195 //
1196 // This optimization only works when the entire invalid region is contained
1197 // within the plugin. There is a related optimization in PaintRect for the
1198 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:151199 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:151200 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201201 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:211202 DCHECK(!pending_update_params_.get());
1203 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551204 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211205 pending_update_params_->scroll_rect = update.scroll_rect;
1206 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211207 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1208 pending_update_params_->flags = next_paint_flags_;
1209 pending_update_params_->scroll_offset = GetScrollOffset();
1210 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091211 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211212 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091213 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211214
[email protected]ca4847f2010-09-24 05:39:151215 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561216 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151217 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201218 &optimized_copy_rect,
1219 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271220 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471221 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211222 pending_update_params_->bitmap = dib->id();
1223 pending_update_params_->bitmap_rect = optimized_copy_location;
1224 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201225 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561226 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461227 // Compute a buffer for painting and cache it.
[email protected]4889bd212013-02-11 22:23:101228
1229 bool fractional_scale = device_scale_factor_ -
1230 static_cast<int>(device_scale_factor_) != 0;
1231 if (fractional_scale) {
1232 // Damage might not be DIP aligned. Inflate damage to compensate.
1233 bounds.Inset(-1, -1);
1234 bounds.Intersect(gfx::Rect(size_));
1235 }
1236
1237 gfx::Rect pixel_bounds = gfx::ToEnclosingRect(
[email protected]ce112fe2012-10-29 22:52:181238 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]4889bd212013-02-11 22:23:101239
[email protected]ca4847f2010-09-24 05:39:151240 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351241 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591242 pixel_bounds));
[email protected]59383c782013-04-17 16:43:271243 if (!canvas) {
[email protected]f98d7e3c2010-09-13 22:30:461244 NOTREACHED();
1245 return;
1246 }
[email protected]cef3362f2009-12-21 17:48:451247
[email protected]f98d7e3c2010-09-13 22:30:461248 // We may get back a smaller canvas than we asked for.
1249 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591250 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1251 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1252 pixel_bounds.set_width(canvas->getDevice()->width());
1253 pixel_bounds.set_height(canvas->getDevice()->height());
1254 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1255 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051256
[email protected]f98d7e3c2010-09-13 22:30:461257 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1258
[email protected]aa4117f2011-12-09 22:19:211259 pending_update_params_->bitmap = current_paint_buf_->id();
1260 pending_update_params_->bitmap_rect = bounds;
1261
1262 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461263 // The scroll damage is just another rectangle to paint and copy.
1264 copy_rects.swap(update.paint_rects);
1265 if (!scroll_damage.IsEmpty())
1266 copy_rects.push_back(scroll_damage);
1267
[email protected]4889bd212013-02-11 22:23:101268 for (size_t i = 0; i < copy_rects.size(); ++i) {
1269 gfx::Rect rect = copy_rects[i];
1270 if (fractional_scale) {
1271 // Damage might not be DPI aligned. Inflate rect to compensate.
1272 rect.Inset(-1, -1);
1273 }
1274 PaintRect(rect, pixel_bounds.origin(), canvas.get());
1275 }
[email protected]60a50072012-01-11 02:05:351276
1277 // Software FPS tick for performance tests. The accelerated path traces the
1278 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1279 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421280 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW",
1281 TRACE_EVENT_SCOPE_THREAD);
[email protected]f98d7e3c2010-09-13 22:30:461282 } else { // Accelerated compositing path
1283 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211284 // If painting is done via the gpu process then we don't set any damage
1285 // rects to save the browser process from doing unecessary work.
1286 pending_update_params_->bitmap_rect = bounds;
1287 pending_update_params_->scroll_rect = gfx::Rect();
1288 // We don't need an ack, because we're not sharing a DIB with the browser.
1289 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1290 // with the browser for the GPU surface.
1291 pending_update_params_->needs_ack = false;
[email protected]f0c2a242013-03-15 19:34:521292 Composite(frame_begin_ticks);
[email protected]f98d7e3c2010-09-13 22:30:461293 }
1294
[email protected]936c6f52011-12-13 01:35:261295 // If we're holding a pending input event ACK, send the ACK before sending the
1296 // UpdateReply message so we can receive another input event before the
1297 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1298 // the UpdateRect IPC message handler.
[email protected]59383c782013-04-17 16:43:271299 if (pending_input_event_ack_)
[email protected]936c6f52011-12-13 01:35:261300 Send(pending_input_event_ack_.release());
1301
[email protected]ab543072013-01-25 04:38:151302 // If Composite() called SwapBuffers, pending_update_params_ will be reset (in
[email protected]aa4117f2011-12-09 22:19:211303 // OnSwapBuffersPosted), meaning a message has been added to the
1304 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1305 // the message now.
[email protected]59383c782013-04-17 16:43:271306 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:211307 // sending an ack to browser process that the paint is complete...
1308 update_reply_pending_ = pending_update_params_->needs_ack;
1309 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1310 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341311 }
[email protected]53d3f302009-12-21 04:42:051312
[email protected]29ed96a2012-02-04 18:12:161313 // If we're software rendering then we're done initiating the paint.
1314 if (!is_accelerated_compositing_active_)
1315 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291316}
1317
[email protected]f0c2a242013-03-15 19:34:521318void RenderWidget::Composite(base::TimeTicks frame_begin_time) {
[email protected]ab543072013-01-25 04:38:151319 DCHECK(is_accelerated_compositing_active_);
[email protected]ba91a792013-02-06 09:48:281320 if (compositor_) // TODO(jamesr): Figure out how this can be null.
[email protected]f0c2a242013-03-15 19:34:521321 compositor_->Composite(frame_begin_time);
[email protected]ab543072013-01-25 04:38:151322}
1323
initial.commit09911bf2008-07-26 23:55:291324///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461325// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291326
[email protected]4873c7d2009-07-16 06:36:281327void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]479b0172012-10-29 19:27:091328 TRACE_EVENT2("renderer", "RenderWidget::didInvalidateRect",
1329 "width", rect.width, "height", rect.height);
[email protected]552e6002009-11-19 05:24:571330 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481331 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181332 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571333 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291334 return;
1335
[email protected]552e6002009-11-19 05:24:571336 paint_aggregator_.InvalidateRect(damaged_rect);
1337
1338 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241339 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571340 return;
1341 if (!paint_aggregator_.HasPendingUpdate())
1342 return;
[email protected]aa4117f2011-12-09 22:19:211343 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241344 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1345 return;
1346
1347 // When GPU rendering, combine pending animations and invalidations into
1348 // a single update.
[email protected]816edc62012-03-17 01:27:221349 if (is_accelerated_compositing_active_ &&
1350 animation_update_pending_ &&
1351 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571352 return;
1353
1354 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291355 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1356 // on the call stack.
1357 // 2) Allows us to collect more damage rects before painting to help coalesce
1358 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241359 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111360 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211361 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291362}
1363
[email protected]990278ff2012-11-13 02:12:551364void RenderWidget::didScrollRect(int dx, int dy,
1365 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461366 // Drop scrolls on the floor when we are in compositing mode.
1367 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561368 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461369 return;
1370
[email protected]552e6002009-11-19 05:24:571371 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481372 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181373 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571374 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291375 return;
1376
[email protected]990278ff2012-11-13 02:12:551377 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571378
1379 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241380 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571381 return;
1382 if (!paint_aggregator_.HasPendingUpdate())
1383 return;
[email protected]aa4117f2011-12-09 22:19:211384 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241385 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1386 return;
1387
1388 // When GPU rendering, combine pending animations and invalidations into
1389 // a single update.
[email protected]816edc62012-03-17 01:27:221390 if (is_accelerated_compositing_active_ &&
1391 animation_update_pending_ &&
1392 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571393 return;
1394
1395 // Perform updating asynchronously. This serves two purposes:
1396 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1397 // on the call stack.
1398 // 2) Allows us to collect more damage rects before painting to help coalesce
1399 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241400 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111401 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211402 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291403}
1404
[email protected]244ac1892011-12-02 17:04:471405void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091406 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]8be1c582013-03-06 00:55:031407 if (RenderThreadImpl::current()->short_circuit_size_updates()) {
1408 setWindowRect(WebRect(rootWindowRect().x,
1409 rootWindowRect().y,
1410 new_size.width,
1411 new_size.height));
1412 } else {
[email protected]20fbfc22013-05-08 20:50:581413 size_ = new_size;
1414
1415 // If we don't clear PaintAggregator after changing autoResize state, then
1416 // we might end up in a situation where bitmap_rect is larger than the
1417 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1418 // with invalid damage rects.
1419 paint_aggregator_.ClearPendingUpdate();
[email protected]8be1c582013-03-06 00:55:031420 }
[email protected]20fbfc22013-05-08 20:50:581421
1422 if (auto_resize_mode_)
1423 AutoResizeCompositor();
1424
1425 if (!RenderThreadImpl::current()->short_circuit_size_updates())
1426 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091427 }
[email protected]244ac1892011-12-02 17:04:471428}
1429
[email protected]3a1c8a8032013-03-18 22:35:321430void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051431 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1432 device_scale_factor_));
1433 if (compositor_)
1434 compositor_->setViewportSize(size_, physical_backing_size_);
1435}
1436
[email protected]91acd1c2012-03-14 08:32:391437void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221438 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1439
[email protected]c63b4d42012-04-26 01:01:071440#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211441 if (!is_accelerated_compositing_active_) {
1442 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1443 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1444 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1445 // going to switch to accelerated compositing, the GPU process may need
1446 // round-trips to the browser's UI thread before finishing the frame,
1447 // causing deadlocks if we delay the UpdateRect until we receive the
1448 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071449 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1450 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211451 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1452 }
[email protected]c63b4d42012-04-26 01:01:071453#endif
[email protected]aa4117f2011-12-09 22:19:211454
[email protected]ea162f92011-10-04 23:08:221455 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421456 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241457 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221458}
1459
1460void RenderWidget::didDeactivateCompositor() {
1461 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1462
1463 is_accelerated_compositing_active_ = false;
1464 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1465 routing_id_, is_accelerated_compositing_active_));
1466
[email protected]ea162f92011-10-04 23:08:221467 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241468 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091469
1470 // In single-threaded mode, we exit force compositing mode and re-enter in
1471 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1472 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1473 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361474 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091475 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561476}
1477
[email protected]e195e582013-03-08 01:32:591478void RenderWidget::initializeLayerTreeView() {
1479 compositor_ = RenderWidgetCompositor::Create(this);
1480 if (!compositor_)
1481 return;
1482
1483 compositor_->setViewportSize(size_, physical_backing_size_);
1484 if (init_complete_)
1485 compositor_->setSurfaceReady();
1486}
1487
[email protected]8926c602013-01-23 05:32:061488WebKit::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281489 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061490}
1491
[email protected]9ed83fe2013-02-27 01:52:281492void RenderWidget::suppressCompositorScheduling(bool enable) {
1493 if (compositor_)
1494 compositor_->SetSuppressScheduleComposite(enable);
1495}
1496
[email protected]9cd43a62012-03-26 08:03:561497void RenderWidget::willBeginCompositorFrame() {
1498 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371499
[email protected]ea5f70a2013-03-07 12:30:361500 DCHECK(RenderThreadImpl::current()->compositor_message_loop_proxy());
[email protected]abe8b3a2012-03-28 21:19:371501
1502 // The following two can result in further layout and possibly
1503 // enable GPU acceleration so they need to be called before any painting
1504 // is done.
[email protected]2d354272013-01-14 00:59:061505 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]abe8b3a2012-03-28 21:19:371506 UpdateSelectionBounds();
1507
[email protected]9cd43a62012-03-26 08:03:561508 WillInitiatePaint();
1509}
1510
[email protected]3391a0772012-03-28 00:32:071511void RenderWidget::didBecomeReadyForAdditionalInput() {
1512 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]59383c782013-04-17 16:43:271513 if (pending_input_event_ack_)
[email protected]3391a0772012-03-28 00:32:071514 Send(pending_input_event_ack_.release());
1515}
1516
[email protected]6fceb912013-02-15 06:24:151517void RenderWidget::DidCommitCompositorFrame() {
1518}
1519
[email protected]58264a32011-11-17 23:36:151520void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501521 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351522 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1523 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421524 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU",
1525 TRACE_EVENT_SCOPE_THREAD);
[email protected]29ed96a2012-02-04 18:12:161526 // Notify subclasses that we initiated the paint operation.
1527 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151528}
1529
1530void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181531 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1532
1533 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561534 DidFlushPaint();
1535
[email protected]aa4117f2011-12-09 22:19:211536 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151537 return;
1538
[email protected]ea3ee0a2012-05-15 03:43:091539 if (!next_paint_flags_ &&
1540 !need_update_rect_for_auto_resize_ &&
1541 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151542 return;
[email protected]ea3ee0a2012-05-15 03:43:091543 }
[email protected]58264a32011-11-17 23:36:151544
1545 ViewHostMsg_UpdateRect_Params params;
1546 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151547 params.plugin_window_moves.swap(plugin_window_moves_);
1548 params.flags = next_paint_flags_;
1549 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121550 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091551 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151552
1553 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1554 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091555 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151556}
1557
[email protected]f98d7e3c2010-09-13 22:30:461558void RenderWidget::scheduleComposite() {
[email protected]479b0172012-10-29 19:27:091559 TRACE_EVENT0("gpu", "RenderWidget::scheduleComposite");
[email protected]ea5f70a2013-03-07 12:30:361560 if (RenderThreadImpl::current()->compositor_message_loop_proxy() &&
[email protected]ba91a792013-02-06 09:48:281561 compositor_) {
1562 compositor_->setNeedsRedraw();
[email protected]d0be63772011-12-20 23:18:041563 } else {
[email protected]c3d45532011-10-07 19:20:401564 // TODO(nduca): replace with something a little less hacky. The reason this
1565 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1566 // contains a lot of host-renderer synchronization logic that is still
1567 // important for the accelerated compositing case. The option of simply
1568 // duplicating all that code is less desirable than "faking out" the
1569 // invalidation path using a magical damage rect.
1570 didInvalidateRect(WebRect(0, 0, 1, 1));
1571 }
[email protected]f98d7e3c2010-09-13 22:30:461572}
1573
[email protected]5f8b1022011-01-21 23:34:501574void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201575 if (animation_update_pending_)
1576 return;
1577
[email protected]921244e42011-07-20 16:36:301578 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201579 animation_update_pending_ = true;
1580 if (!animation_timer_.IsRunning()) {
1581 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1582 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211583 }
[email protected]5f8b1022011-01-21 23:34:501584}
1585
[email protected]4873c7d2009-07-16 06:36:281586void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301587 // TODO(darin): Eliminate this temporary.
1588 WebCursor cursor(cursor_info);
1589
initial.commit09911bf2008-07-26 23:55:291590 // Only send a SetCursor message if we need to make a change.
1591 if (!current_cursor_.IsEqual(cursor)) {
1592 current_cursor_ = cursor;
1593 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1594 }
1595}
1596
1597// We are supposed to get a single call to Show for a newly created RenderWidget
1598// that was created via RenderWidget::CreateWebView. So, we wait until this
1599// point to dispatch the ShowWidget message.
1600//
1601// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281602// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291603//
[email protected]4873c7d2009-07-16 06:36:281604void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291605 DCHECK(!did_show_) << "received extraneous Show call";
1606 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1607 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1608
[email protected]8de12d942010-11-17 20:42:441609 if (did_show_)
1610 return;
1611
1612 did_show_ = true;
1613 // NOTE: initial_pos_ may still have its default values at this point, but
1614 // that's okay. It'll be ignored if as_popup is false, or the browser
1615 // process will impose a default position otherwise.
1616 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1617 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291618}
1619
[email protected]9b003482013-05-21 14:00:171620void RenderWidget::didProgrammaticallyScroll(
1621 const WebKit::WebPoint& scroll_point) {
1622 if (!compositor_)
1623 return;
1624 Send(new ViewHostMsg_DidProgrammaticallyScroll(
1625 routing_id_, gfx::Vector2d(scroll_point.x, scroll_point.y)));
1626}
1627
[email protected]4873c7d2009-07-16 06:36:281628void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291629}
1630
[email protected]4873c7d2009-07-16 06:36:281631void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291632}
1633
[email protected]2533ce12009-05-09 00:02:241634void RenderWidget::DoDeferredClose() {
1635 Send(new ViewHostMsg_Close(routing_id_));
1636}
1637
[email protected]4873c7d2009-07-16 06:36:281638void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321639 if (is_swapped_out_) {
1640 // This widget is currently swapped out, and the active widget is in a
1641 // different process. Have the browser route the close request to the
1642 // active widget instead, so that the correct unload handlers are run.
1643 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1644 return;
1645 }
1646
initial.commit09911bf2008-07-26 23:55:291647 // If a page calls window.close() twice, we'll end up here twice, but that's
1648 // OK. It is safe to send multiple Close messages.
1649
[email protected]2533ce12009-05-09 00:02:241650 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1651 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1652 // could be closed before the JS finishes executing. So instead, post a
1653 // message back to the message loop, which won't run until the JS is
1654 // complete, and then the Close message can be sent.
[email protected]dd32b1272013-05-04 14:17:111655 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211656 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291657}
1658
1659void RenderWidget::Close() {
1660 if (webwidget_) {
[email protected]8926c602013-01-23 05:32:061661 webwidget_->willCloseLayerTreeView();
[email protected]ba91a792013-02-06 09:48:281662 compositor_.reset();
[email protected]4873c7d2009-07-16 06:36:281663 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291664 webwidget_ = NULL;
1665 }
1666}
1667
[email protected]4873c7d2009-07-16 06:36:281668WebRect RenderWidget::windowRect() {
1669 if (pending_window_rect_count_)
1670 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241671
[email protected]80ad8622012-11-07 16:33:031672 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291673}
1674
[email protected]8a9d6ca32011-06-06 20:11:301675void RenderWidget::setToolTipText(const WebKit::WebString& text,
1676 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541677 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301678}
1679
[email protected]4873c7d2009-07-16 06:36:281680void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291681 if (did_show_) {
[email protected]8be1c582013-03-06 00:55:031682 if (!RenderThreadImpl::current()->short_circuit_size_updates()) {
1683 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1684 SetPendingWindowRect(pos);
1685 } else {
1686 WebSize new_size(pos.width, pos.height);
[email protected]d9083762013-03-24 01:36:401687 Resize(new_size, new_size, overdraw_bottom_height_,
1688 WebRect(), is_fullscreen_, NO_RESIZE_ACK);
[email protected]8be1c582013-03-06 00:55:031689 view_screen_rect_ = pos;
1690 window_screen_rect_ = pos;
1691 }
initial.commit09911bf2008-07-26 23:55:291692 } else {
1693 initial_pos_ = pos;
1694 }
1695}
1696
[email protected]2533ce12009-05-09 00:02:241697void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1698 pending_window_rect_ = rect;
1699 pending_window_rect_count_++;
1700}
1701
[email protected]4873c7d2009-07-16 06:36:281702WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241703 if (pending_window_rect_count_) {
1704 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1705 // the RootWindowRect is probably going to return wrong results since the
1706 // browser may not have processed the Move yet. There isn't really anything
1707 // good to do in this case, and it shouldn't happen - since this size is
1708 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281709 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241710 }
1711
[email protected]80ad8622012-11-07 16:33:031712 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371713}
1714
[email protected]4873c7d2009-07-16 06:36:281715WebRect RenderWidget::windowResizerRect() {
1716 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191717}
1718
[email protected]fa7b1dc2010-06-23 17:53:041719void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031720 // To prevent this renderer process from sending unnecessary IPC messages to
1721 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041722 // only during the input method attached to the browser process is active.
1723 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291724}
1725
[email protected]58b48a0d2012-06-13 07:01:351726void RenderWidget::UpdateCompositionInfo(
1727 const ui::Range& range,
1728 const std::vector<gfx::Rect>& character_bounds) {
1729 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1730 return;
1731 composition_character_bounds_ = character_bounds;
1732 composition_range_ = range;
1733 Send(new ViewHostMsg_ImeCompositionRangeChanged(
1734 routing_id(), composition_range_, composition_character_bounds_));
1735}
1736
[email protected]fa7b1dc2010-06-23 17:53:041737void RenderWidget::OnImeSetComposition(
1738 const string16& text,
1739 const std::vector<WebCompositionUnderline>& underlines,
1740 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281741 if (!webwidget_)
1742 return;
[email protected]e8f775f2013-02-14 21:00:501743 DCHECK(!handling_ime_event_);
1744 handling_ime_event_ = true;
[email protected]d4cff272011-05-02 15:46:011745 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041746 text, WebVector<WebCompositionUnderline>(underlines),
1747 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011748 // Setting the IME composition was successful. Send the new composition
1749 // range to the browser.
1750 ui::Range range(ui::Range::InvalidRange());
1751 size_t location, length;
1752 if (webwidget_->compositionRange(&location, &length)) {
1753 range.set_start(location);
1754 range.set_end(location + length);
1755 }
1756 // The IME was cancelled via the Esc key, so just send back the caret.
1757 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1758 range.set_start(location);
1759 range.set_end(location + length);
1760 }
[email protected]58b48a0d2012-06-13 07:01:351761 std::vector<gfx::Rect> character_bounds;
1762 GetCompositionCharacterBounds(&character_bounds);
1763 UpdateCompositionInfo(range, character_bounds);
[email protected]d4cff272011-05-02 15:46:011764 } else {
[email protected]fa7b1dc2010-06-23 17:53:041765 // If we failed to set the composition text, then we need to let the browser
1766 // process to cancel the input method's ongoing composition session, to make
1767 // sure we are in a consistent state.
1768 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011769
1770 // Send an updated IME range with just the caret range.
1771 ui::Range range(ui::Range::InvalidRange());
1772 size_t location, length;
1773 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1774 range.set_start(location);
1775 range.set_end(location + length);
1776 }
[email protected]58b48a0d2012-06-13 07:01:351777 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]7f00efa2010-04-15 05:01:261778 }
[email protected]e8f775f2013-02-14 21:00:501779 handling_ime_event_ = false;
1780 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]fa7b1dc2010-06-23 17:53:041781}
1782
[email protected]4de6d1692011-10-12 08:45:441783void RenderWidget::OnImeConfirmComposition(
1784 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041785 if (!webwidget_)
1786 return;
[email protected]e8f775f2013-02-14 21:00:501787 DCHECK(!handling_ime_event_);
1788 handling_ime_event_ = true;
[email protected]d0be63772011-12-20 23:18:041789 handling_input_event_ = true;
1790 webwidget_->confirmComposition(text);
1791 handling_input_event_ = false;
1792
[email protected]d4cff272011-05-02 15:46:011793 // Send an updated IME range with just the caret range.
1794 ui::Range range(ui::Range::InvalidRange());
1795 size_t location, length;
1796 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1797 range.set_start(location);
1798 range.set_end(location + length);
1799 }
[email protected]58b48a0d2012-06-13 07:01:351800 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]e8f775f2013-02-14 21:00:501801 handling_ime_event_ = false;
1802 UpdateTextInputState(DO_NOT_SHOW_IME);
initial.commit09911bf2008-07-26 23:55:291803}
1804
[email protected]948f7ab72010-05-28 23:48:081805// This message causes the renderer to render an image of the
1806// desired_size, regardless of whether the tab is hidden or not.
[email protected]3d9ec5052013-01-02 22:05:251807void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle,
1808 int tag,
1809 const gfx::Size& page_size,
1810 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001811 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1812 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251813 // Close our unused handle.
1814#if defined(OS_WIN)
1815 ::CloseHandle(dib_handle);
1816#elif defined(OS_MACOSX)
1817 base::SharedMemory::CloseHandle(dib_handle);
1818#endif
1819 }
[email protected]d65adb12010-04-28 17:26:491820 return;
[email protected]45c6aad32010-11-11 04:46:251821 }
[email protected]d65adb12010-04-28 17:26:491822
[email protected]948f7ab72010-05-28 23:48:081823 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491824 // If one of these is empty, then we just return the dib we were
1825 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091826 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491827 return;
1828 }
1829
1830 // Map the given DIB ID into this process, and unmap it at the end
1831 // of this function.
[email protected]45c6aad32010-11-11 04:46:251832 scoped_ptr<TransportDIB> paint_at_size_buffer(
1833 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301834
[email protected]4b01b962012-10-09 23:17:351835 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281836 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:351837 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281838 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:511839 gfx::Size canvas_size = page_size_in_pixel;
1840 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:491841 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:511842 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:491843 static_cast<float>(canvas_size.height());
1844
[email protected]ee8d6fd2010-05-26 17:05:481845 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491846 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1847 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481848 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491849
[email protected]36808ad2010-10-20 19:18:301850 scoped_ptr<skia::PlatformCanvas> canvas(
1851 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1852 canvas_size.height()));
[email protected]59383c782013-04-17 16:43:271853 if (!canvas) {
[email protected]36808ad2010-10-20 19:18:301854 NOTREACHED();
1855 return;
1856 }
1857
[email protected]d65adb12010-04-28 17:26:491858 // Reset bounds to what we actually received, but they should be the
1859 // same.
1860 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1861 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1862 bounds.set_width(canvas->getDevice()->width());
1863 bounds.set_height(canvas->getDevice()->height());
1864
1865 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081866 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491867 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1868
[email protected]948f7ab72010-05-28 23:48:081869 // Have to make sure we're laid out at the right size before
1870 // rendering.
1871 gfx::Size old_size = webwidget_->size();
1872 webwidget_->resize(page_size);
1873 webwidget_->layout();
1874
[email protected]d65adb12010-04-28 17:26:491875 // Paint the entire thing (using original bounds, not scaled bounds).
1876 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1877 canvas->restore();
1878
[email protected]948f7ab72010-05-28 23:48:081879 // Return the widget to its previous size.
1880 webwidget_->resize(old_size);
1881
[email protected]c88c9442010-07-19 18:55:091882 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491883}
1884
[email protected]51a49502013-03-23 01:50:191885void RenderWidget::OnSnapshot(const gfx::Rect& src_subrect) {
1886 SkBitmap snapshot;
1887
1888 if (OnSnapshotHelper(src_subrect, &snapshot)) {
1889 Send(new ViewHostMsg_Snapshot(routing_id(), true, snapshot));
1890 } else {
1891 Send(new ViewHostMsg_Snapshot(routing_id(), false, SkBitmap()));
1892 }
1893}
1894
1895bool RenderWidget::OnSnapshotHelper(const gfx::Rect& src_subrect,
1896 SkBitmap* snapshot) {
1897 base::TimeTicks beginning_time = base::TimeTicks::Now();
1898
1899 if (!webwidget_ || src_subrect.IsEmpty())
1900 return false;
1901
1902 gfx::Rect viewport_size = gfx::IntersectRects(
1903 src_subrect, gfx::Rect(physical_backing_size_));
1904
1905 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(
1906 skia::CreatePlatformCanvas(viewport_size.width(),
1907 viewport_size.height(),
1908 true,
1909 NULL,
1910 skia::RETURN_NULL_ON_FAILURE));
[email protected]59383c782013-04-17 16:43:271911 if (!canvas)
[email protected]51a49502013-03-23 01:50:191912 return false;
1913
1914 canvas->save();
1915 webwidget_->layout();
1916
1917 PaintRect(viewport_size, viewport_size.origin(), canvas.get());
1918 canvas->restore();
1919
1920 const SkBitmap& bitmap = skia::GetTopDevice(*canvas)->accessBitmap(false);
1921 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1922 return false;
1923
1924 UMA_HISTOGRAM_TIMES("Renderer4.Snapshot",
1925 base::TimeTicks::Now() - beginning_time);
1926 return true;
1927}
1928
[email protected]0bc1f572013-04-17 01:46:311929void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121930 // During shutdown we can just ignore this message.
1931 if (!webwidget_)
1932 return;
1933
[email protected]0bc1f572013-04-17 01:46:311934 // Even if the browser provides an empty damage rect, it's still expecting to
1935 // receive a repaint ack so just damage the entire widget bounds.
1936 if (size_to_paint.IsEmpty()) {
1937 size_to_paint = size_;
1938 }
1939
[email protected]ec7dc112008-08-06 05:30:121940 set_next_paint_is_repaint_ack();
[email protected]0bc1f572013-04-17 01:46:311941 if (is_accelerated_compositing_active_ && compositor_) {
1942 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]f98d7e3c2010-09-13 22:30:461943 } else {
1944 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1945 didInvalidateRect(repaint_rect);
1946 }
[email protected]ec7dc112008-08-06 05:30:121947}
1948
[email protected]4a9dba42013-04-29 18:24:221949void RenderWidget::OnSmoothScrollCompleted() {
1950 pending_smooth_scroll_gesture_.Run();
[email protected]0e241b4b2012-08-18 09:06:271951}
1952
[email protected]4873c7d2009-07-16 06:36:281953void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111954 if (!webwidget_)
1955 return;
[email protected]4873c7d2009-07-16 06:36:281956 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111957}
1958
[email protected]6131a642012-06-15 23:26:531959void RenderWidget::OnScreenInfoChanged(
1960 const WebKit::WebScreenInfo& screen_info) {
1961 screen_info_ = screen_info;
[email protected]468ac582012-11-20 00:53:191962 SetDeviceScaleFactor(screen_info.deviceScaleFactor);
[email protected]6131a642012-06-15 23:26:531963}
1964
[email protected]80ad8622012-11-07 16:33:031965void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1966 const gfx::Rect& window_screen_rect) {
1967 view_screen_rect_ = view_screen_rect;
1968 window_screen_rect_ = window_screen_rect;
1969 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1970}
1971
[email protected]105dffb42013-02-20 03:46:211972#if defined(OS_ANDROID)
1973void RenderWidget::OnImeBatchStateChanged(bool is_begin) {
1974 Send(new ViewHostMsg_ImeBatchStateChanged_ACK(routing_id(), is_begin));
1975}
[email protected]2384b6c2013-02-28 23:58:511976
1977void RenderWidget::OnShowImeIfNeeded() {
1978 UpdateTextInputState(SHOW_IME_IF_NEEDED);
1979}
[email protected]105dffb42013-02-20 03:46:211980#endif
1981
[email protected]468ac582012-11-20 00:53:191982void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1983 if (device_scale_factor_ == device_scale_factor)
1984 return;
1985
1986 device_scale_factor_ = device_scale_factor;
1987
1988 if (!is_accelerated_compositing_active_) {
1989 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
1990 } else {
1991 scheduleComposite();
1992 }
1993}
1994
[email protected]719b36f2010-12-22 20:36:461995webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151996 const gfx::Rect& paint_bounds,
1997 TransportDIB** dib,
1998 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:201999 gfx::Rect* clip,
2000 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:462001 // Bare RenderWidgets don't support optimized plugin painting.
2002 return NULL;
[email protected]ca4847f2010-09-24 05:39:152003}
2004
[email protected]ceb36f7d2012-10-31 18:33:242005gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:522006 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:242007 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:522008}
2009
[email protected]bee16aab2009-08-26 15:55:032010void RenderWidget::SetHidden(bool hidden) {
2011 if (is_hidden_ == hidden)
2012 return;
2013
2014 // The status has changed. Tell the RenderThread about it.
2015 is_hidden_ = hidden;
2016 if (is_hidden_)
[email protected]380244092011-10-07 17:26:272017 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:032018 else
[email protected]380244092011-10-07 17:26:272019 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:032020}
2021
[email protected]2b624c562011-10-27 22:58:262022void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262023 if (!webwidget_)
2024 return;
2025
2026 if (is_fullscreen_) {
2027 webwidget_->willExitFullScreen();
2028 } else {
2029 webwidget_->willEnterFullScreen();
2030 }
[email protected]2b624c562011-10-27 22:58:262031}
2032
2033void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262034 if (!webwidget_)
2035 return;
2036
2037 if (is_fullscreen_) {
2038 webwidget_->didEnterFullScreen();
2039 } else {
2040 webwidget_->didExitFullScreen();
2041 }
[email protected]2b624c562011-10-27 22:58:262042}
2043
[email protected]699ab0d2009-04-23 23:19:142044void RenderWidget::SetBackground(const SkBitmap& background) {
2045 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:462046
[email protected]699ab0d2009-04-23 23:19:142047 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:282048 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:142049}
2050
[email protected]674741932009-02-04 23:44:462051bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:052052 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462053}
2054
2055bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:052056 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462057}
2058
2059void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:052060 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462061}
2062
2063void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:052064 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:462065}
2066
2067void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:052068 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462069}
2070
[email protected]b18583c2012-12-18 06:55:272071static bool IsDateTimeInput(ui::TextInputType type) {
2072 return type == ui::TEXT_INPUT_TYPE_DATE ||
2073 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
2074 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
2075 type == ui::TEXT_INPUT_TYPE_MONTH ||
2076 type == ui::TEXT_INPUT_TYPE_TIME ||
2077 type == ui::TEXT_INPUT_TYPE_WEEK;
2078}
2079
[email protected]3306f262012-09-21 19:20:422080void RenderWidget::UpdateTextInputState(ShowIme show_ime) {
[email protected]e8f775f2013-02-14 21:00:502081 if (handling_ime_event_)
2082 return;
[email protected]3306f262012-09-21 19:20:422083 bool show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
2084 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:292085 return;
[email protected]ad26ef42011-06-17 07:59:452086 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:272087 if (IsDateTimeInput(new_type))
2088 return; // Not considered as a text input field in WebKit/Chromium.
2089
[email protected]5b739cb2012-08-21 20:35:212090 WebKit::WebTextInputInfo new_info;
2091 if (webwidget_)
2092 new_info = webwidget_->textInputInfo();
2093
[email protected]ad26ef42011-06-17 07:59:452094 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:212095
[email protected]3306f262012-09-21 19:20:422096 // Only sends text input params if they are changed or if the ime should be
2097 // shown.
2098 if (show_ime_if_needed || (text_input_type_ != new_type
2099 || text_input_info_ != new_info
2100 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:212101 ViewHostMsg_TextInputState_Params p;
2102 p.type = new_type;
2103 p.value = new_info.value.utf8();
2104 p.selection_start = new_info.selectionStart;
2105 p.selection_end = new_info.selectionEnd;
2106 p.composition_start = new_info.compositionStart;
2107 p.composition_end = new_info.compositionEnd;
2108 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:422109 p.show_ime_if_needed = show_ime_if_needed;
[email protected]5b739cb2012-08-21 20:35:212110 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
2111
2112 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:042113 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:452114 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:292115 }
initial.commit09911bf2008-07-26 23:55:292116}
2117
[email protected]7c8873e2013-02-05 08:03:012118void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2119 WebRect focus_webrect;
2120 WebRect anchor_webrect;
2121 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
2122 *focus = focus_webrect;
2123 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322124}
2125
[email protected]e99ef6f2011-10-16 01:13:002126void RenderWidget::UpdateSelectionBounds() {
2127 if (!webwidget_)
2128 return;
2129
[email protected]7c8873e2013-02-05 08:03:012130 ViewHostMsg_SelectionBounds_Params params;
2131 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2132 if (selection_anchor_rect_ != params.anchor_rect ||
2133 selection_focus_rect_ != params.focus_rect) {
2134 selection_anchor_rect_ = params.anchor_rect;
2135 selection_focus_rect_ = params.focus_rect;
2136 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
[email protected]129b7382013-02-12 02:14:292137 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
[email protected]7c8873e2013-02-05 08:03:012138 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
[email protected]58b48a0d2012-06-13 07:01:352139 }
[email protected]e99ef6f2011-10-16 01:13:002140
[email protected]58b48a0d2012-06-13 07:01:352141 std::vector<gfx::Rect> character_bounds;
2142 GetCompositionCharacterBounds(&character_bounds);
2143 UpdateCompositionInfo(composition_range_, character_bounds);
2144}
2145
2146bool RenderWidget::ShouldUpdateCompositionInfo(
2147 const ui::Range& range,
2148 const std::vector<gfx::Rect>& bounds) {
2149 if (composition_range_ != range)
2150 return true;
2151 if (bounds.size() != composition_character_bounds_.size())
2152 return true;
2153 for (size_t i = 0; i < bounds.size(); ++i) {
2154 if (bounds[i] != composition_character_bounds_[i])
2155 return true;
2156 }
2157 return false;
[email protected]e99ef6f2011-10-16 01:13:002158}
2159
[email protected]73bf95812011-10-12 11:38:322160// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:452161COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
2162 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
2163COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
2164 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
2165COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
2166 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:182167COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
2168 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
2169COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
2170 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
2171COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
2172 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
2173COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
2174 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
2175COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
2176 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:002177COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
2178 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
2179COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
2180 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
2181COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
2182 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
2183COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
2184 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
2185COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
2186 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
2187COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
2188 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:012189COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
2190 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
2191COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
2192 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]8b4992e2013-03-01 15:42:152193COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeField) == \
2194 int(ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:452195
[email protected]5b739cb2012-08-21 20:35:212196ui::TextInputType RenderWidget::WebKitToUiTextInputType(
2197 WebKit::WebTextInputType type) {
2198 // Check the type is in the range representable by ui::TextInputType.
2199 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
2200 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
2201 return static_cast<ui::TextInputType>(type);
2202}
2203
[email protected]ad26ef42011-06-17 07:59:452204ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272205 if (webwidget_)
2206 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452207 return ui::TEXT_INPUT_TYPE_NONE;
2208}
2209
[email protected]58b48a0d2012-06-13 07:01:352210void RenderWidget::GetCompositionCharacterBounds(
2211 std::vector<gfx::Rect>* bounds) {
2212 DCHECK(bounds);
2213 bounds->clear();
2214}
2215
[email protected]ad26ef42011-06-17 07:59:452216bool RenderWidget::CanComposeInline() {
2217 return true;
[email protected]56ea1a62011-05-30 07:05:572218}
2219
[email protected]4873c7d2009-07-16 06:36:282220WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042221 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282222}
2223
[email protected]f660d9c2012-06-06 18:31:212224float RenderWidget::deviceScaleFactor() {
2225 return device_scale_factor_;
2226}
2227
[email protected]fa7b1dc2010-06-23 17:53:042228void RenderWidget::resetInputMethod() {
2229 if (!input_method_is_active_)
2230 return;
2231
2232 // If the last text input type is not None, then we should finish any
2233 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452234 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042235 // If a composition text exists, then we need to let the browser process
2236 // to cancel the input method's ongoing composition session.
2237 if (webwidget_->confirmComposition())
2238 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
2239 }
[email protected]d4cff272011-05-02 15:46:012240
2241 // Send an updated IME range with the current caret rect.
2242 ui::Range range(ui::Range::InvalidRange());
2243 size_t location, length;
2244 if (webwidget_->caretOrSelectionRange(&location, &length)) {
2245 range.set_start(location);
2246 range.set_end(location + length);
2247 }
[email protected]58b48a0d2012-06-13 07:01:352248
2249 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]fa7b1dc2010-06-23 17:53:042250}
2251
[email protected]c68c3e4e2013-01-24 00:36:562252void RenderWidget::didHandleGestureEvent(
2253 const WebGestureEvent& event,
2254 bool event_cancelled) {
2255#if defined(OS_ANDROID)
2256 if (event_cancelled)
2257 return;
2258 if (event.type == WebInputEvent::GestureTap ||
2259 event.type == WebInputEvent::GestureLongPress) {
2260 UpdateTextInputState(SHOW_IME_IF_NEEDED);
2261 }
2262#endif
2263}
2264
[email protected]f103ab72009-09-02 17:10:592265void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:502266 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292267 size_t i = 0;
2268 for (; i < plugin_window_moves_.size(); ++i) {
2269 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582270 if (move.rects_valid) {
2271 plugin_window_moves_[i] = move;
2272 } else {
2273 plugin_window_moves_[i].visible = move.visible;
2274 }
initial.commit09911bf2008-07-26 23:55:292275 break;
2276 }
2277 }
2278
2279 if (i == plugin_window_moves_.size())
2280 plugin_window_moves_.push_back(move);
2281}
[email protected]268654772009-08-06 23:02:042282
2283void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2284 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2285 i != plugin_window_moves_.end(); ++i) {
2286 if (i->window == window) {
2287 plugin_window_moves_.erase(i);
2288 break;
2289 }
2290 }
2291}
[email protected]67bfb83f2011-09-22 03:36:372292
[email protected]b63d58d2012-11-26 22:37:442293void RenderWidget::GetRenderingStats(
2294 WebKit::WebRenderingStatsImpl& stats) const {
[email protected]ba91a792013-02-06 09:48:282295 if (compositor_)
[email protected]635353c2013-03-06 09:11:202296 compositor_->GetRenderingStats(&stats.rendering_stats);
[email protected]b63d58d2012-11-26 22:37:442297
[email protected]62049562013-03-24 00:39:012298 stats.rendering_stats.animation_frame_count +=
2299 software_stats_.animation_frame_count;
2300 stats.rendering_stats.screen_frame_count +=
2301 software_stats_.screen_frame_count;
2302 stats.rendering_stats.total_paint_time +=
2303 software_stats_.total_paint_time;
2304 stats.rendering_stats.total_pixels_painted +=
2305 software_stats_.total_pixels_painted;
[email protected]fef5e3972012-08-07 03:59:472306}
2307
[email protected]e9ff79c2012-10-19 21:31:262308bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:522309 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
2310 if (!gpu_channel)
2311 return false;
2312
2313 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
2314}
2315
[email protected]24ed0432013-04-24 07:50:312316RenderWidgetCompositor* RenderWidget::compositor() const {
2317 return compositor_.get();
2318}
2319
[email protected]0c2ebef2013-04-03 12:14:102320void RenderWidget::BeginSmoothScroll(
[email protected]0e241b4b2012-08-18 09:06:272321 bool down,
[email protected]ebd8b562012-10-09 14:44:292322 const SmoothScrollCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:192323 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:292324 int mouse_event_x,
2325 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:272326 DCHECK(!callback.is_null());
[email protected]267909d2012-10-20 04:36:192327
2328 ViewHostMsg_BeginSmoothScroll_Params params;
2329 params.scroll_down = down;
2330 params.pixels_to_scroll = pixels_to_scroll;
2331 params.mouse_event_x = mouse_event_x;
2332 params.mouse_event_y = mouse_event_y;
2333
[email protected]4a9dba42013-04-29 18:24:222334 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, params));
2335 pending_smooth_scroll_gesture_ = callback;
[email protected]a39ca1652012-07-13 21:30:582336}
2337
[email protected]a2b5ded2013-05-20 21:32:532338void RenderWidget::DidOverscroll(gfx::Vector2dF accumulated_overscroll,
2339 gfx::Vector2dF current_fling_velocity) {
2340 if (overscroll_notifications_enabled_) {
2341 Send(new ViewHostMsg_DidOverscroll(routing_id_,
2342 accumulated_overscroll,
2343 current_fling_velocity));
2344 }
2345}
2346
[email protected]67bfb83f2011-09-22 03:36:372347bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
2348 return false;
2349}
[email protected]c3d45532011-10-07 19:20:402350
[email protected]41d86852012-11-07 12:23:242351bool RenderWidget::WillHandleGestureEvent(
2352 const WebKit::WebGestureEvent& event) {
2353 return false;
2354}
2355
[email protected]ce6689f2013-03-29 12:52:552356void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2357 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2358}
2359
[email protected]3d5c243b2012-11-30 00:26:012360bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2361 return true;
2362}
2363
[email protected]3ae68c52013-04-12 06:10:052364WebGraphicsContext3DCommandBufferImpl* RenderWidget::CreateGraphicsContext3D(
[email protected]92fd8c02013-03-29 08:54:152365 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
[email protected]ed7defa2013-03-12 21:29:592366 if (!webwidget_)
2367 return NULL;
[email protected]8f746982013-03-21 06:28:032368 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
2369 new WebGraphicsContext3DCommandBufferImpl(
2370 surface_id(),
2371 GetURLForGraphicsContext3D(),
2372 RenderThreadImpl::current(),
2373 weak_ptr_factory_.GetWeakPtr()));
[email protected]ed7defa2013-03-12 21:29:592374
[email protected]8f746982013-03-21 06:28:032375 if (!context->Initialize(
2376 attributes,
2377 false /* bind generates resources */,
2378 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
2379 return NULL;
2380 return context.release();
[email protected]ed7defa2013-03-12 21:29:592381}
2382
[email protected]e9ff79c2012-10-19 21:31:262383} // namespace content