blob: 2f44c793daecbcc757058fa41a4798b9fc25898e [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]992db4c2011-05-12 15:37:1523#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5024#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2925#include "content/public/common/content_switches.h"
[email protected]ed7defa2013-03-12 21:29:5926#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]2847b222013-04-06 00:59:2427#include "content/renderer/gpu/compositor_software_output_device.h"
[email protected]ea5f70a2013-03-07 12:30:3628#include "content/renderer/gpu/input_handler_manager.h"
[email protected]ed7defa2013-03-12 21:29:5929#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]ba91a792013-02-06 09:48:2830#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]8704f89b2011-04-15 00:30:0531#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4432#include "content/renderer/render_thread_impl.h"
[email protected]8d6cba42011-09-02 10:05:1933#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]484955942010-08-19 16:13:1834#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4835#include "skia/ext/platform_canvas.h"
[email protected]ed7defa2013-03-12 21:29:5936#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
[email protected]debc8e52013-01-15 03:43:1237#include "third_party/WebKit/Source/Platform/chromium/public/WebPoint.h"
38#include "third_party/WebKit/Source/Platform/chromium/public/WebRect.h"
39#include "third_party/WebKit/Source/Platform/chromium/public/WebSize.h"
40#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
[email protected]8bd0fe62011-01-17 06:44:3741#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
[email protected]4b1146bc2012-07-10 18:46:0342#include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h"
[email protected]a7547fb2012-03-08 04:43:4443#include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h"
[email protected]8bd0fe62011-01-17 06:44:3744#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
45#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
[email protected]d4cff272011-05-02 15:46:0146#include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
[email protected]8bd0fe62011-01-17 06:44:3747#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
[email protected]d353541f2012-05-03 22:45:4148#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1349#include "ui/base/ui_base_switches.h"
[email protected]a25e25b2012-09-28 14:32:3750#include "ui/gfx/rect_conversions.h"
[email protected]4b01b962012-10-09 23:17:3551#include "ui/gfx/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4852#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2753#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4154#include "ui/surface/transport_dib.h"
[email protected]b63d58d2012-11-26 22:37:4455#include "webkit/compositor_bindings/web_rendering_stats_impl.h"
[email protected]8c89e7792009-08-19 21:18:3456#include "webkit/glue/webkit_glue.h"
[email protected]191eb3f72010-12-21 06:27:5057#include "webkit/plugins/npapi/webplugin.h"
[email protected]719b36f2010-12-22 20:36:4658#include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
[email protected]661eb9d2009-02-03 02:11:4859
60#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4961#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5262#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4163#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4864#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4465
[email protected]8bd0fe62011-01-17 06:44:3766#include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2967
[email protected]fa7b1dc2010-06-23 17:53:0468using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3069using WebKit::WebCursorInfo;
[email protected]41d86852012-11-07 12:23:2470using WebKit::WebGestureEvent;
[email protected]62cb33cae2009-03-27 23:30:2271using WebKit::WebInputEvent;
[email protected]6a8ddba52010-09-05 04:38:0672using WebKit::WebMouseEvent;
[email protected]4873c7d2009-07-16 06:36:2873using WebKit::WebNavigationPolicy;
[email protected]a7547fb2012-03-08 04:43:4474using WebKit::WebPagePopup;
[email protected]e99ef6f2011-10-16 01:13:0075using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2876using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5977using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1878using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0179using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5280using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1981using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5282using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2883using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2484using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0485using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1886using WebKit::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:2687
[email protected]6a4d7f62013-01-07 21:32:1388namespace {
89const char* GetEventName(WebInputEvent::Type type) {
90#define CASE_TYPE(t) case WebInputEvent::t: return #t
91 switch(type) {
92 CASE_TYPE(Undefined);
93 CASE_TYPE(MouseDown);
94 CASE_TYPE(MouseUp);
95 CASE_TYPE(MouseMove);
96 CASE_TYPE(MouseEnter);
97 CASE_TYPE(MouseLeave);
98 CASE_TYPE(ContextMenu);
99 CASE_TYPE(MouseWheel);
100 CASE_TYPE(RawKeyDown);
101 CASE_TYPE(KeyDown);
102 CASE_TYPE(KeyUp);
103 CASE_TYPE(Char);
104 CASE_TYPE(GestureScrollBegin);
105 CASE_TYPE(GestureScrollEnd);
106 CASE_TYPE(GestureScrollUpdate);
107 CASE_TYPE(GestureFlingStart);
108 CASE_TYPE(GestureFlingCancel);
109 CASE_TYPE(GestureTap);
110 CASE_TYPE(GestureTapDown);
111 CASE_TYPE(GestureTapCancel);
112 CASE_TYPE(GestureDoubleTap);
113 CASE_TYPE(GestureTwoFingerTap);
114 CASE_TYPE(GestureLongPress);
115 CASE_TYPE(GestureLongTap);
116 CASE_TYPE(GesturePinchBegin);
117 CASE_TYPE(GesturePinchEnd);
118 CASE_TYPE(GesturePinchUpdate);
119 CASE_TYPE(TouchStart);
120 CASE_TYPE(TouchMove);
121 CASE_TYPE(TouchEnd);
122 CASE_TYPE(TouchCancel);
[email protected]3ec08ed2013-01-11 15:59:57123 default:
124 // Must include default to let WebKit::WebInputEvent add new event types
125 // before they're added here.
126 DLOG(WARNING) << "Unhandled WebInputEvent type in GetEventName.\n";
127 break;
[email protected]6a4d7f62013-01-07 21:32:13128 }
129#undef CASE_TYPE
[email protected]3ec08ed2013-01-11 15:59:57130 return "";
[email protected]6a4d7f62013-01-07 21:32:13131}
132}
[email protected]e9ff79c2012-10-19 21:31:26133namespace content {
[email protected]62cb33cae2009-03-27 23:30:22134
[email protected]6fd35b72012-03-01 19:46:41135RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]842f10652012-06-06 01:54:04136 const WebKit::WebScreenInfo& screen_info,
[email protected]14392a52012-05-02 20:28:44137 bool swapped_out)
initial.commit09911bf2008-07-26 23:55:29138 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56139 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:11140 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:29141 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30142 init_complete_(false),
[email protected]b4d08452010-10-05 17:34:35143 current_paint_buf_(NULL),
[email protected]d9083762013-03-24 01:36:40144 overdraw_bottom_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29145 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:06146 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:05147 update_reply_pending_(false),
[email protected]847a2582013-03-09 02:29:51148 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09149 need_update_rect_for_auto_resize_(false),
[email protected]65225772011-05-12 21:10:24150 using_asynchronous_swapbuffers_(false),
151 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:29152 did_show_(false),
initial.commit09911bf2008-07-26 23:55:29153 is_hidden_(false),
[email protected]ee41e7d22011-10-14 19:34:09154 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:29155 needs_repainting_on_restore_(false),
156 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49157 handling_input_event_(false),
[email protected]e8f775f2013-02-14 21:00:50158 handling_ime_event_(false),
[email protected]661eb9d2009-02-03 02:11:48159 closing_(false),
[email protected]14392a52012-05-02 20:28:44160 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04161 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45162 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
163 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12164 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48165 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12166 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50167 is_accelerated_compositing_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21168 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07169 invalidation_task_posted_(false),
[email protected]842f10652012-06-06 01:54:04170 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52171 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]0e241b4b2012-08-18 09:06:27172 throttle_input_events_(true),
[email protected]0c2ebef2013-04-03 12:14:10173 next_smooth_scroll_gesture_id_(0),
[email protected]ed7defa2013-03-12 21:29:59174 is_threaded_compositing_enabled_(false),
175 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
[email protected]8b3f0eb2012-05-03 19:15:05176 if (!swapped_out)
177 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27178 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18179 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
180 switches::kDisableGpuVsync);
[email protected]cb6430932012-10-31 00:53:36181 is_threaded_compositing_enabled_ =
182 CommandLine::ForCurrentProcess()->HasSwitch(
183 switches::kEnableThreadedCompositing);
initial.commit09911bf2008-07-26 23:55:29184}
185
186RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11187 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21188 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35189 if (current_paint_buf_) {
190 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
191 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29192 }
[email protected]992db4c2011-05-12 15:37:15193 // If we are swapped out, we have released already.
194 if (!is_swapped_out_)
195 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29196}
197
[email protected]484955942010-08-19 16:13:18198// static
[email protected]8085dbc82008-09-26 22:53:44199RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:04200 WebKit::WebPopupType popup_type,
201 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29202 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41203 scoped_refptr<RenderWidget> widget(
[email protected]842f10652012-06-06 01:54:04204 new RenderWidget(popup_type, screen_info, false));
[email protected]a635f942012-12-07 10:34:29205 if (widget->Init(opener_id)) { // adds reference on success.
206 return widget;
207 }
208 return NULL;
initial.commit09911bf2008-07-26 23:55:29209}
210
[email protected]484955942010-08-19 16:13:18211// static
212WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
213 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03214 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18215 break;
216 case WebKit::WebPopupTypeSelect:
217 case WebKit::WebPopupTypeSuggestion:
218 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44219 case WebKit::WebPopupTypePage:
220 return WebPagePopup::create(render_widget);
[email protected]4b1146bc2012-07-10 18:46:03221 case WebKit::WebPopupTypeHelperPlugin:
222 return WebKit::WebHelperPlugin::create(render_widget);
[email protected]484955942010-08-19 16:13:18223 default:
224 NOTREACHED();
225 }
226 return NULL;
227}
228
[email protected]a635f942012-12-07 10:34:29229bool RenderWidget::Init(int32 opener_id) {
230 return DoInit(opener_id,
231 RenderWidget::CreateWebWidget(this),
232 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
233 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18234}
235
[email protected]a635f942012-12-07 10:34:29236bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06237 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18238 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29239 DCHECK(!webwidget_);
240
241 if (opener_id != MSG_ROUTING_NONE)
242 opener_id_ = opener_id;
243
[email protected]484955942010-08-19 16:13:18244 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29245
[email protected]380244092011-10-07 17:26:27246 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29247 if (result) {
[email protected]380244092011-10-07 17:26:27248 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29249 // Take a reference on behalf of the RenderThread. This will be balanced
250 // when we receive ViewMsg_Close.
251 AddRef();
[email protected]a635f942012-12-07 10:34:29252 return true;
initial.commit09911bf2008-07-26 23:55:29253 } else {
[email protected]a635f942012-12-07 10:34:29254 // The above Send can fail when the tab is closing.
255 return false;
initial.commit09911bf2008-07-26 23:55:29256 }
257}
258
[email protected]fc4404d2012-11-07 19:53:30259// This is used to complete pending inits and non-pending inits.
260void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29261 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29262
[email protected]fc4404d2012-11-07 19:53:30263 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42264
[email protected]8926c602013-01-23 05:32:06265 if (webwidget_ && is_threaded_compositing_enabled_) {
266 webwidget_->enterForceCompositingMode(true);
267 }
[email protected]ba91a792013-02-06 09:48:28268 if (compositor_) {
269 compositor_->setSurfaceReady();
[email protected]479b0172012-10-29 19:27:09270 }
[email protected]05a980d7a2012-02-07 22:16:42271 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29272
[email protected]6de74452009-02-25 18:04:59273 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29274}
275
[email protected]992db4c2011-05-12 15:37:15276void RenderWidget::SetSwappedOut(bool is_swapped_out) {
277 // We should only toggle between states.
278 DCHECK(is_swapped_out_ != is_swapped_out);
279 is_swapped_out_ = is_swapped_out;
280
281 // If we are swapping out, we will call ReleaseProcess, allowing the process
282 // to exit if all of its RenderViews are swapped out. We wait until the
283 // WasSwappedOut call to do this, to avoid showing the sad tab.
284 // If we are swapping in, we call AddRefProcess to prevent the process from
285 // exiting.
286 if (!is_swapped_out)
287 RenderProcess::current()->AddRefProcess();
288}
289
[email protected]34bb3ac2013-03-08 02:41:28290bool RenderWidget::AllowPartialSwap() const {
291 return true;
292}
293
[email protected]a95986a82010-12-24 06:19:28294bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
295 bool handled = true;
296 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
297 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
298 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
299 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54300 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28301 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41302 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]992db4c2011-05-12 15:37:15303 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28304 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]ed7defa2013-03-12 21:29:59305 IPC_MESSAGE_HANDLER(ViewMsg_SwapBuffers_ACK,
306 OnViewContextSwapBuffersComplete)
[email protected]a95986a82010-12-24 06:19:28307 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent)
308 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost)
309 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus)
310 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
311 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
312 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]3d9ec5052013-01-02 22:05:25313 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnPaintAtSize)
314 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
315 IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, OnSmoothScrollCompleted)
[email protected]a95986a82010-12-24 06:19:28316 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
317 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]6131a642012-06-15 23:26:53318 IPC_MESSAGE_HANDLER(ViewMsg_ScreenInfoChanged, OnScreenInfoChanged)
[email protected]80ad8622012-11-07 16:33:03319 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]105dffb42013-02-20 03:46:21320#if defined(OS_ANDROID)
321 IPC_MESSAGE_HANDLER(ViewMsg_ImeBatchStateChanged, OnImeBatchStateChanged)
[email protected]2384b6c2013-02-28 23:58:51322 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]105dffb42013-02-20 03:46:21323#endif
[email protected]51a49502013-03-23 01:50:19324 IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot)
[email protected]a95986a82010-12-24 06:19:28325 IPC_MESSAGE_UNHANDLED(handled = false)
326 IPC_END_MESSAGE_MAP()
327 return handled;
328}
initial.commit09911bf2008-07-26 23:55:29329
330bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15331 // Don't send any messages after the browser has told us to close, and filter
332 // most outgoing messages while swapped out.
333 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26334 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11335 closing_) {
initial.commit09911bf2008-07-26 23:55:29336 delete message;
337 return false;
338 }
339
340 // If given a messsage without a routing ID, then assign our routing ID.
341 if (message->routing_id() == MSG_ROUTING_NONE)
342 message->set_routing_id(routing_id_);
343
[email protected]380244092011-10-07 17:26:27344 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44345}
346
[email protected]61e2b3cc2012-03-02 16:13:34347void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44348 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40349 float overdraw_bottom_height,
[email protected]61e2b3cc2012-03-02 16:13:34350 const gfx::Rect& resizer_rect,
351 bool is_fullscreen,
352 ResizeAck resize_ack) {
353 // A resize ack shouldn't be requested if we have not ACK'd the previous one.
354 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
355 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29356
[email protected]61e2b3cc2012-03-02 16:13:34357 // Ignore this during shutdown.
358 if (!webwidget_)
359 return;
360
[email protected]d9083762013-03-24 01:36:40361 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44362 compositor_->setViewportSize(new_size, physical_backing_size);
[email protected]d9083762013-03-24 01:36:40363 compositor_->SetOverdrawBottomHeight(overdraw_bottom_height);
364 }
[email protected]60d47ac2013-03-01 23:42:44365
[email protected]dade8992013-03-04 07:34:34366 physical_backing_size_ = physical_backing_size;
[email protected]d9083762013-03-24 01:36:40367 overdraw_bottom_height_ = overdraw_bottom_height;
[email protected]61e2b3cc2012-03-02 16:13:34368 resizer_rect_ = resizer_rect;
369
370 // NOTE: We may have entered fullscreen mode without changing our size.
371 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
372 if (fullscreen_change)
373 WillToggleFullscreen();
374 is_fullscreen_ = is_fullscreen;
375
376 if (size_ != new_size) {
377 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34378 needs_repainting_on_restore_ = false;
379
380 size_ = new_size;
381
382 paint_aggregator_.ClearPendingUpdate();
383
384 // When resizing, we want to wait to paint before ACK'ing the resize. This
385 // ensures that we only resize as fast as we can paint. We only need to
386 // send an ACK if we are resized to a non-empty rect.
387 webwidget_->resize(new_size);
388 if (!new_size.IsEmpty()) {
389 if (!is_accelerated_compositing_active_) {
390 // Resize should have caused an invalidation of the entire view.
391 DCHECK(paint_aggregator_.HasPendingUpdate());
392 }
393
394 // Send the Resize_ACK flag once we paint again if requested.
395 if (resize_ack == SEND_RESIZE_ACK)
396 set_next_paint_is_resize_ack();
397 }
[email protected]ff475a322012-03-14 00:05:35398 } else {
399 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34400 }
401
402 if (fullscreen_change)
403 DidToggleFullscreen();
404
405 // If a resize ack is requested and it isn't set-up, then no more resizes will
406 // come in and in general things will go wrong.
407 DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() ||
408 next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29409}
410
411void RenderWidget::OnClose() {
412 if (closing_)
413 return;
414 closing_ = true;
415
416 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03417 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27418 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03419 SetHidden(false);
420 }
initial.commit09911bf2008-07-26 23:55:29421
initial.commit09911bf2008-07-26 23:55:29422 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25423 // now. Post a task that only gets invoked when there are no nested message
424 // loops.
[email protected]32876ae2011-11-15 22:25:21425 MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29426 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25427
428 // Balances the AddRef taken when we called AddRoute.
429 Release();
initial.commit09911bf2008-07-26 23:55:29430}
431
[email protected]61e2b3cc2012-03-02 16:13:34432// Got a response from the browser after the renderer decided to create a new
433// view.
[email protected]fc4404d2012-11-07 19:53:30434void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34435 DCHECK(routing_id_ != MSG_ROUTING_NONE);
436
[email protected]fc4404d2012-11-07 19:53:30437 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34438}
439
[email protected]f21c613a2009-02-12 14:46:17440void RenderWidget::OnResize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44441 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40442 float overdraw_bottom_height,
[email protected]ee41e7d22011-10-14 19:34:09443 const gfx::Rect& resizer_rect,
444 bool is_fullscreen) {
[email protected]d9083762013-03-24 01:36:40445 Resize(new_size, physical_backing_size, overdraw_bottom_height, resizer_rect,
446 is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29447}
448
[email protected]b5913d72012-02-07 22:26:54449void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
450 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59451 gfx::Rect view_rect(size_);
452
[email protected]ce112fe2012-10-29 22:52:18453 gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_);
[email protected]b9769d82012-02-10 00:23:59454 if (!old_damage_rect.IsEmpty())
455 paint_aggregator_.InvalidateRect(old_damage_rect);
456
[email protected]ce112fe2012-10-29 22:52:18457 gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect);
[email protected]b9769d82012-02-10 00:23:59458 if (!new_damage_rect.IsEmpty())
459 paint_aggregator_.InvalidateRect(new_damage_rect);
460
[email protected]b5913d72012-02-07 22:26:54461 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59462
[email protected]b5913d72012-02-07 22:26:54463 if (webwidget_)
464 webwidget_->didChangeWindowResizerRect();
465 }
466}
467
initial.commit09911bf2008-07-26 23:55:29468void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31469 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29470 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03471 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29472}
473
[email protected]9e2e4632012-07-27 16:38:41474void RenderWidget::OnWasShown(bool needs_repainting) {
475 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29476 // During shutdown we can just ignore this message.
477 if (!webwidget_)
478 return;
479
480 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03481 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29482
483 if (!needs_repainting && !needs_repainting_on_restore_)
484 return;
485 needs_repainting_on_restore_ = false;
486
[email protected]d65adb12010-04-28 17:26:49487 // Tag the next paint as a restore ack, which is picked up by
488 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29489 set_next_paint_is_restore_ack();
490
491 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56492 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46493 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
494 } else {
495 scheduleComposite();
496 }
initial.commit09911bf2008-07-26 23:55:29497}
498
[email protected]992db4c2011-05-12 15:37:15499void RenderWidget::OnWasSwappedOut() {
500 // If we have been swapped out and no one else is using this process,
501 // it's safe to exit now. If we get swapped back in, we will call
502 // AddRefProcess in SetSwappedOut.
503 if (is_swapped_out_)
504 RenderProcess::current()->ReleaseProcess();
505}
506
[email protected]53d3f302009-12-21 04:42:05507void RenderWidget::OnRequestMoveAck() {
508 DCHECK(pending_window_rect_count_);
509 pending_window_rect_count_--;
510}
511
512void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58513 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21514 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05515 update_reply_pending_ = false;
516
[email protected]b4d08452010-10-05 17:34:35517 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
518 // have no current paint buffer.
519 if (current_paint_buf_) {
520 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
521 current_paint_buf_ = NULL;
522 }
523
[email protected]65225772011-05-12 21:10:24524 // If swapbuffers is still pending, then defer the update until the
525 // swapbuffers occurs.
526 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
527 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
528 return;
529 }
530
[email protected]29ed96a2012-02-04 18:12:16531 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18532 if (!is_accelerated_compositing_active_) {
533 DidFlushPaint();
534 }
[email protected]a2f6bc112009-06-27 16:27:25535
initial.commit09911bf2008-07-26 23:55:29536 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24537 DoDeferredUpdateAndSendInputAck();
538}
539
[email protected]d0be63772011-12-20 23:18:04540bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]ed7defa2013-03-12 21:29:59541 // Contexts using the command buffer support asynchronous swapbuffers.
542 // See RenderWidget::CreateOutputSurface().
[email protected]8f746982013-03-21 06:28:03543 if (RenderThreadImpl::current()->compositor_message_loop_proxy())
[email protected]ed7defa2013-03-12 21:29:59544 return false;
545
546 return true;
547}
548
549GURL RenderWidget::GetURLForGraphicsContext3D() {
550 return GURL();
[email protected]65225772011-05-12 21:10:24551}
552
[email protected]479b0172012-10-29 19:27:09553bool RenderWidget::ForceCompositingModeEnabled() {
554 return false;
555}
556
[email protected]ba91a792013-02-06 09:48:28557scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface() {
[email protected]2847b222013-04-06 00:59:24558 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
559 if (command_line.HasSwitch(switches::kEnableSoftwareCompositingGLAdapter)) {
560 return scoped_ptr<cc::OutputSurface>(
561 new CompositorOutputSurface(routing_id(), NULL,
562 new CompositorSoftwareOutputDevice()));
563 }
564
[email protected]ed7defa2013-03-12 21:29:59565 // Explicitly disable antialiasing for the compositor. As of the time of
566 // this writing, the only platform that supported antialiasing for the
567 // compositor was Mac OS X, because the on-screen OpenGL context creation
568 // code paths on Windows and Linux didn't yet have multisampling support.
569 // Mac OS X essentially always behaves as though it's rendering offscreen.
570 // Multisampling has a heavy cost especially on devices with relatively low
571 // fill rate like most notebooks, and the Mac implementation would need to
572 // be optimized to resolve directly into the IOSurface shared between the
573 // GPU and browser processes. For these reasons and to avoid platform
574 // disparities we explicitly disable antialiasing.
575 WebKit::WebGraphicsContext3D::Attributes attributes;
576 attributes.antialias = false;
577 attributes.shareResources = true;
578 attributes.noAutomaticFlushes = true;
[email protected]3ae68c52013-04-12 06:10:05579 WebGraphicsContext3DCommandBufferImpl* context =
580 CreateGraphicsContext3D(attributes);
[email protected]ed7defa2013-03-12 21:29:59581 if (!context)
582 return scoped_ptr<cc::OutputSurface>();
583
[email protected]2847b222013-04-06 00:59:24584 bool composite_to_mailbox =
585 command_line.HasSwitch(cc::switches::kCompositeToMailbox);
586 DCHECK(!composite_to_mailbox || command_line.HasSwitch(
587 cc::switches::kEnableCompositorFrameMessage));
588 // No swap throttling yet when compositing on the main thread.
589 DCHECK(!composite_to_mailbox || is_threaded_compositing_enabled_);
590 return scoped_ptr<cc::OutputSurface>(composite_to_mailbox ?
591 new MailboxOutputSurface(routing_id(), context, NULL) :
592 new CompositorOutputSurface(routing_id(), context, NULL));
[email protected]ba91a792013-02-06 09:48:28593}
594
[email protected]ed7defa2013-03-12 21:29:59595void RenderWidget::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24596 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21597 while (!updates_pending_swap_.empty()) {
598 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
599 updates_pending_swap_.pop_front();
600 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
601 // compositing pass, hence doesn't require an UpdateRect message.
602 if (msg)
603 Send(msg);
604 }
[email protected]65225772011-05-12 21:10:24605 num_swapbuffers_complete_pending_ = 0;
606 using_asynchronous_swapbuffers_ = false;
607 // Schedule another frame so the compositor learns about it.
608 scheduleComposite();
609}
610
[email protected]ed7defa2013-03-12 21:29:59611void RenderWidget::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:08612 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21613
614 if (using_asynchronous_swapbuffers_) {
615 ViewHostMsg_UpdateRect* msg = NULL;
616 // pending_update_params_ can be NULL if the swap doesn't correspond to an
617 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
618 // message.
[email protected]59383c782013-04-17 16:43:27619 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:21620 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
621 pending_update_params_.reset();
622 }
623 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08624 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21625 }
[email protected]37a6f302011-07-11 23:43:08626}
627
[email protected]ed7defa2013-03-12 21:29:59628void RenderWidget::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24629 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16630
[email protected]404939f2012-06-01 04:06:18631 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16632 DidFlushPaint();
633
[email protected]65225772011-05-12 21:10:24634 // When compositing deactivates, we reset the swapbuffers pending count. The
635 // swapbuffers acks may still arrive, however.
636 if (num_swapbuffers_complete_pending_ == 0) {
637 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
638 return;
639 }
[email protected]aa4117f2011-12-09 22:19:21640 DCHECK(!updates_pending_swap_.empty());
641 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
642 updates_pending_swap_.pop_front();
643 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
644 // compositing pass, hence doesn't require an UpdateRect message.
645 if (msg)
646 Send(msg);
[email protected]65225772011-05-12 21:10:24647 num_swapbuffers_complete_pending_--;
648
649 // If update reply is still pending, then defer the update until that reply
650 // occurs.
[email protected]d0be63772011-12-20 23:18:04651 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24652 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
653 return;
654 }
655
656 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:06657 // when we were previously rendering. However, if an invalidation task is not
658 // posted, there may be software rendering work pending. In that case, don't
659 // early out.
660 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:24661 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
662 return;
663 }
664
[email protected]cc66e682012-10-02 06:48:18665 // Do not call DoDeferredUpdate unless there's animation work to be done or
666 // a real invalidation. This prevents rendering in response to a swapbuffers
667 // callback coming back after we've navigated away from the page that
668 // generated it.
669 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
670 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
671 return;
672 }
673
[email protected]65225772011-05-12 21:10:24674 // Continue painting if necessary...
675 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:29676}
677
[email protected]0dea1652012-12-14 00:09:09678void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
679 bool is_keyboard_shortcut) {
[email protected]65225772011-05-12 21:10:24680 TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent");
initial.commit09911bf2008-07-26 23:55:29681
[email protected]5dd768212009-08-13 23:34:49682 handling_input_event_ = true;
[email protected]0dea1652012-12-14 00:09:09683 if (!input_event) {
[email protected]5dd768212009-08-13 23:34:49684 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:29685 return;
[email protected]5dd768212009-08-13 23:34:49686 }
initial.commit09911bf2008-07-26 23:55:29687
[email protected]6a4d7f62013-01-07 21:32:13688 base::TimeDelta now = base::TimeDelta::FromInternalValue(
689 base::TimeTicks::Now().ToInternalValue());
690
691 int64 delta = static_cast<int64>(
692 (now.InSecondsF() - input_event->timeStampSeconds) *
693 base::Time::kMicrosecondsPerSecond);
694 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer", delta, 0, 1000000, 100);
695 std::string name_for_event =
696 base::StringPrintf("Event.Latency.Renderer.%s",
697 GetEventName(input_event->type));
[email protected]de415552013-01-23 04:12:17698 base::HistogramBase* counter_for_type =
[email protected]bafdc5d52013-02-27 18:18:48699 base::Histogram::FactoryGet(
[email protected]6a4d7f62013-01-07 21:32:13700 name_for_event,
[email protected]bafdc5d52013-02-27 18:18:48701 0,
702 1000000,
[email protected]6a4d7f62013-01-07 21:32:13703 100,
[email protected]de415552013-01-23 04:12:17704 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]bafdc5d52013-02-27 18:18:48705 counter_for_type->Add(delta);
[email protected]6a4d7f62013-01-07 21:32:13706
[email protected]67bfb83f2011-09-22 03:36:37707 bool prevent_default = false;
708 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:26709 const WebMouseEvent& mouse_event =
710 *static_cast<const WebMouseEvent*>(input_event);
711 TRACE_EVENT2("renderer", "HandleMouseMove",
712 "x", mouse_event.x, "y", mouse_event.y);
713 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:37714 }
715
[email protected]41d86852012-11-07 12:23:24716 if (WebInputEvent::isGestureEventType(input_event->type)) {
717 const WebGestureEvent& gesture_event =
718 *static_cast<const WebGestureEvent*>(input_event);
719 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
720 }
721
[email protected]3ebcc7c2013-01-09 05:34:46722 if (input_event->type == WebInputEvent::GestureTap ||
723 input_event->type == WebInputEvent::GestureLongPress)
724 resetInputMethod();
725
[email protected]67bfb83f2011-09-22 03:36:37726 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:12727 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
728 suppress_next_char_events_ = false;
729 if (!processed && webwidget_)
730 processed = webwidget_->handleInputEvent(*input_event);
731 }
732
733 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
734 // it's not processed by webkit, then we need to suppress the upcoming Char
735 // events.
736 if (!processed && is_keyboard_shortcut)
737 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:29738
[email protected]3d5c243b2012-11-30 00:26:01739 InputEventAckState ack_result = processed ?
740 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
741 if (!processed && input_event->type == WebInputEvent::TouchStart) {
742 const WebTouchEvent& touch_event =
743 *static_cast<const WebTouchEvent*>(input_event);
744 ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ?
745 INPUT_EVENT_ACK_STATE_NOT_CONSUMED :
746 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
747 }
748
[email protected]a9fb30aa2011-10-06 06:58:46749 IPC::Message* response =
750 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
[email protected]3d5c243b2012-11-30 00:26:01751 ack_result);
[email protected]3391a0772012-03-28 00:32:07752 bool event_type_gets_rate_limited =
753 input_event->type == WebInputEvent::MouseMove ||
754 input_event->type == WebInputEvent::MouseWheel ||
755 WebInputEvent::isTouchEventType(input_event->type);
[email protected]8926c602013-01-23 05:32:06756
757 bool frame_pending = paint_aggregator_.HasPendingUpdate();
758 if (is_accelerated_compositing_active_) {
[email protected]ba91a792013-02-06 09:48:28759 frame_pending = compositor_ &&
760 compositor_->commitRequested();
[email protected]8926c602013-01-23 05:32:06761 }
762
[email protected]3391a0772012-03-28 00:32:07763 bool is_input_throttled =
[email protected]ce2b28e2012-08-09 15:53:57764 throttle_input_events_ &&
[email protected]8926c602013-01-23 05:32:06765 frame_pending;
[email protected]e2824412009-02-27 01:57:05766
[email protected]f8868d72012-04-27 19:13:03767 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:24768 // We want to rate limit the input events in this case, so we'll wait for
769 // painting to finish before ACKing this message.
[email protected]59383c782013-04-17 16:43:27770 if (pending_input_event_ack_) {
[email protected]353a34c2010-05-28 23:35:17771 // As two different kinds of events could cause us to postpone an ack
772 // we send it now, if we have one pending. The Browser should never
773 // send us the same kind of event we are delaying the ack for.
774 Send(pending_input_event_ack_.release());
775 }
[email protected]12fbad812009-09-01 18:21:24776 pending_input_event_ack_.reset(response);
777 } else {
778 Send(response);
779 }
780
[email protected]3306f262012-09-21 19:20:42781#if defined(OS_ANDROID)
782 // Allow the IME to be shown when the focus changes as a consequence
783 // of a processed touch end event.
784 if (input_event->type == WebInputEvent::TouchEnd && processed)
785 UpdateTextInputState(SHOW_IME_IF_NEEDED);
786#endif
787
[email protected]5dd768212009-08-13 23:34:49788 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:48789
[email protected]67bfb83f2011-09-22 03:36:37790 if (!prevent_default) {
791 if (WebInputEvent::isKeyboardEventType(input_event->type))
792 DidHandleKeyEvent();
793 if (WebInputEvent::isMouseEventType(input_event->type))
794 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:24795 if (WebInputEvent::isTouchEventType(input_event->type))
796 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:37797 }
initial.commit09911bf2008-07-26 23:55:29798}
799
800void RenderWidget::OnMouseCaptureLost() {
801 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:28802 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:29803}
804
805void RenderWidget::OnSetFocus(bool enable) {
806 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:33807 if (webwidget_)
808 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:29809}
810
811void RenderWidget::ClearFocus() {
812 // We may have got the focus from the browser before this gets processed, in
813 // which case we do not want to unfocus ourself.
814 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:28815 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:29816}
817
[email protected]2d5d09d52009-06-15 14:29:21818void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:00819 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:21820 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:06821 TRACE_EVENT2("renderer", "PaintRect",
822 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:45823
824 const bool kEnableGpuBenchmarking =
825 CommandLine::ForCurrentProcess()->HasSwitch(
826 switches::kEnableGpuBenchmarking);
[email protected]4fb66842009-12-04 21:41:00827 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:21828
829 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:00830 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
831 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:03832
[email protected]699ab0d2009-04-23 23:19:14833 // If there is a custom background, tile it.
834 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:14835 SkPaint paint;
[email protected]4e29afd2012-12-04 04:07:11836 skia::RefPtr<SkShader> shader = skia::AdoptRef(
837 SkShader::CreateBitmapShader(background_,
838 SkShader::kRepeat_TileMode,
839 SkShader::kRepeat_TileMode));
840 paint.setShader(shader.get());
[email protected]fb10ec5b2011-10-24 17:54:20841
842 // Use kSrc_Mode to handle background_ transparency properly.
843 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
844
845 // Canvas could contain multiple update rects. Clip to given rect so that
846 // we don't accidentally clear other update rects.
847 canvas->save();
[email protected]aa7e7a12013-02-22 13:37:44848 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]1835b9e2012-02-28 13:12:48849 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:14850 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:20851 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:14852 }
853
[email protected]719b36f2010-12-22 20:36:46854 // First see if this rect is a plugin that can paint itself faster.
855 TransportDIB* optimized_dib = NULL;
856 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:20857 float dib_scale_factor;
[email protected]719b36f2010-12-22 20:36:46858 webkit::ppapi::PluginInstance* optimized_instance =
859 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
860 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:20861 &optimized_copy_rect,
862 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:46863 if (optimized_instance) {
864 // This plugin can be optimize-painted and we can just ask it to paint
865 // itself. We don't actually need the TransportDIB in this case.
866 //
867 // This is an optimization for PPAPI plugins that know they're on top of
868 // the page content. If this rect is inside such a plugin, we can save some
869 // time and avoid re-rendering the page content which we know will be
870 // covered by the plugin later (this time can be significant, especially
871 // for a playing movie that is invalidating a lot).
872 //
873 // In the plugin movie case, hopefully the similar call to
874 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
875 // painting, because that avoids copying the plugin image to a different
876 // paint rect. Unfortunately, if anything on the page is animating other
877 // than the movie, it break this optimization since the union of the
878 // invalid regions will be larger than the plugin.
879 //
880 // This code optimizes that case, where we can still avoid painting in
881 // WebKit and filling the background (which can be slow) and just painting
882 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
883 // required.
[email protected]63ab54262012-11-09 15:58:45884 base::TimeTicks paint_begin_ticks;
885 if (kEnableGpuBenchmarking)
886 paint_begin_ticks = base::TimeTicks::HighResNow();
887
[email protected]df59dd42012-09-14 22:56:30888 SkAutoCanvasRestore auto_restore(canvas, true);
889 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]719b36f2010-12-22 20:36:46890 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas),
[email protected]2df1b362011-01-21 21:22:27891 optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:21892 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45893 if (kEnableGpuBenchmarking) {
894 base::TimeDelta paint_time =
895 base::TimeTicks::HighResNow() - paint_begin_ticks;
896 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01897 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45898 }
[email protected]719b36f2010-12-22 20:36:46899 } else {
900 // Normal painting case.
[email protected]63ab54262012-11-09 15:58:45901 base::TimeTicks paint_begin_ticks;
902 if (kEnableGpuBenchmarking)
903 paint_begin_ticks = base::TimeTicks::HighResNow();
904
[email protected]719b36f2010-12-22 20:36:46905 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect);
[email protected]63ab54262012-11-09 15:58:45906
907 if (kEnableGpuBenchmarking) {
908 base::TimeDelta paint_time =
909 base::TimeTicks::HighResNow() - paint_begin_ticks;
910 if (!is_accelerated_compositing_active_)
[email protected]62049562013-03-24 00:39:01911 software_stats_.total_paint_time += paint_time;
[email protected]63ab54262012-11-09 15:58:45912 }
[email protected]719b36f2010-12-22 20:36:46913
914 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:35915 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:46916 }
initial.commit09911bf2008-07-26 23:55:29917
[email protected]4fb66842009-12-04 21:41:00918 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:00919 canvas->restore();
[email protected]63ab54262012-11-09 15:58:45920
921 if (kEnableGpuBenchmarking) {
[email protected]63ab54262012-11-09 15:58:45922 int64 num_pixels_processed = rect.width() * rect.height();
[email protected]62049562013-03-24 00:39:01923 software_stats_.total_pixels_painted += num_pixels_processed;
924 software_stats_.total_pixels_rasterized += num_pixels_processed;
[email protected]63ab54262012-11-09 15:58:45925 }
[email protected]4fb66842009-12-04 21:41:00926}
927
928void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
929 skia::PlatformCanvas* canvas) {
930 static bool kPaintBorder =
931 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
932 if (!kPaintBorder)
933 return;
934
[email protected]53d3f302009-12-21 04:42:05935 // Cycle through these colors to help distinguish new paint rects.
936 const SkColor colors[] = {
937 SkColorSetARGB(0x3F, 0xFF, 0, 0),
938 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
939 SkColorSetARGB(0x3F, 0, 0, 0xFF),
940 };
941 static int color_selector = 0;
942
[email protected]4fb66842009-12-04 21:41:00943 SkPaint paint;
944 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:05945 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:00946 paint.setStrokeWidth(1);
947
948 SkIRect irect;
949 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
950 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:29951}
952
[email protected]52ccd0ea2011-02-16 01:09:05953void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:30954 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:30955 if (!animation_update_pending_) {
956 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:59957 return;
[email protected]921244e42011-07-20 16:36:30958 }
[email protected]bd37ae252011-06-03 01:28:18959 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:59960 // Record when we fired (according to base::Time::Now()) relative to when
961 // we posted the task to quantify how much the base::Time/base::TimeTicks
962 // skew is affecting animations.
963 base::TimeDelta animation_callback_delay = base::Time::Now() -
964 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
965 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
966 animation_callback_delay,
967 base::TimeDelta::FromMilliseconds(0),
968 base::TimeDelta::FromMilliseconds(30),
969 25);
970 }
[email protected]65225772011-05-12 21:10:24971 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:24972}
973
[email protected]52ccd0ea2011-02-16 01:09:05974void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:59975 if (!animation_update_pending_)
976 return;
[email protected]bd37ae252011-06-03 01:28:18977
978 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:33979 base::TimeDelta animationInterval = IsRenderingVSynced() ?
980 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:18981
[email protected]7c4329e2011-02-18 22:02:59982 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:45983
984 // animation_floor_time_ is the earliest time that we should animate when
985 // using the dead reckoning software scheduler. If we're using swapbuffers
986 // complete callbacks to rate limit, we can ignore this floor.
987 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:30988 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:33989 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:18990 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:59991 // running animation callbacks so that if a callback requests another
992 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:38993 animation_timer_.Stop();
994 animation_timer_.Start(FROM_HERE, animationInterval, this,
995 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:59996 animation_update_pending_ = false;
[email protected]ba91a792013-02-06 09:48:28997 if (is_accelerated_compositing_active_ && compositor_) {
[email protected]635353c2013-03-06 09:11:20998 compositor_->Animate(base::TimeTicks::Now());
[email protected]8926c602013-01-23 05:32:06999 } else {
[email protected]635353c2013-03-06 09:11:201000 double frame_begin_time =
1001 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
1002 webwidget_->animate(frame_begin_time);
[email protected]8926c602013-01-23 05:32:061003 }
[email protected]7c4329e2011-02-18 22:02:591004 return;
[email protected]5f8b1022011-01-21 23:34:501005 }
[email protected]bd37ae252011-06-03 01:28:181006 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:381007 if (!animation_timer_.IsRunning()) {
1008 // This code uses base::Time::Now() to calculate the floor and next fire
1009 // time because javascript's Date object uses base::Time::Now(). The
1010 // message loop uses base::TimeTicks, which on windows can have a
1011 // different granularity than base::Time.
1012 // The upshot of all this is that this function might be called before
1013 // base::Time::Now() has advanced past the animation_floor_time_. To
1014 // avoid exposing this delay to javascript, we keep posting delayed
1015 // tasks until base::Time::Now() has advanced far enough.
1016 base::TimeDelta delay = animation_floor_time_ - now;
1017 animation_timer_.Start(FROM_HERE, delay, this,
1018 &RenderWidget::AnimationCallback);
1019 }
[email protected]5f8b1022011-01-21 23:34:501020}
1021
[email protected]bd37ae252011-06-03 01:28:181022bool RenderWidget::IsRenderingVSynced() {
1023 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
1024 // not caught by this check. This will lead to artificially low frame rates
1025 // for people who force vsync off at a driver level and expect Chrome to speed
1026 // up.
1027 return !has_disable_gpu_vsync_switch_;
1028}
1029
[email protected]65225772011-05-12 21:10:241030void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:061031 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:241032 invalidation_task_posted_ = false;
1033 DoDeferredUpdateAndSendInputAck();
1034}
1035
1036void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:051037 DoDeferredUpdate();
1038
[email protected]59383c782013-04-17 16:43:271039 if (pending_input_event_ack_)
[email protected]52ccd0ea2011-02-16 01:09:051040 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:211041}
1042
[email protected]552e6002009-11-19 05:24:571043void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:581044 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]71e2f0a2011-03-15 22:25:081045
[email protected]65225772011-05-12 21:10:241046 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:291047 return;
[email protected]05a980d7a2012-02-07 22:16:421048
[email protected]fc4404d2012-11-07 19:53:301049 if (!init_complete_) {
1050 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:421051 return;
1052 }
[email protected]aa4117f2011-12-09 22:19:211053 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:241054 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
1055 return;
1056 }
[email protected]9ca84622011-06-02 23:46:391057 if (is_accelerated_compositing_active_ &&
1058 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:241059 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
1060 return;
1061 }
initial.commit09911bf2008-07-26 23:55:291062
[email protected]552e6002009-11-19 05:24:571063 // Suppress updating when we are hidden.
[email protected]e3d92a7f2013-01-10 02:35:051064 if (is_hidden_ || size_.IsEmpty() || is_swapped_out_) {
[email protected]552e6002009-11-19 05:24:571065 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:291066 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:241067 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:291068 return;
1069 }
1070
[email protected]05a980d7a2012-02-07 22:16:421071 if (is_accelerated_compositing_active_)
1072 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
1073
[email protected]0fb93f52011-05-18 23:13:561074 // Tracking of frame rate jitter
1075 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]38ce4e7b2013-02-23 06:17:371076 InstrumentWillBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:051077 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:501078
[email protected]f98d7e3c2010-09-13 22:30:461079 // Layout may generate more invalidation. It may also enable the
1080 // GPU acceleration, so make sure to run layout before we send the
1081 // GpuRenderingActivated message.
1082 webwidget_->layout();
1083
[email protected]dcca3aa92012-02-17 23:03:371084 // The following two can result in further layout and possibly
1085 // enable GPU acceleration so they need to be called before any painting
1086 // is done.
[email protected]3306f262012-09-21 19:20:421087 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]dcca3aa92012-02-17 23:03:371088 UpdateSelectionBounds();
1089
[email protected]5f8b1022011-01-21 23:34:501090 // Suppress painting if nothing is dirty. This has to be done after updating
1091 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:241092 if (!paint_aggregator_.HasPendingUpdate()) {
1093 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]38ce4e7b2013-02-23 06:17:371094 InstrumentDidCancelFrame();
[email protected]5f8b1022011-01-21 23:34:501095 return;
[email protected]65225772011-05-12 21:10:241096 }
[email protected]5f8b1022011-01-21 23:34:501097
[email protected]479b0172012-10-29 19:27:091098 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:361099 !is_threaded_compositing_enabled_ &&
[email protected]479b0172012-10-29 19:27:091100 ForceCompositingModeEnabled()) {
1101 webwidget_->enterForceCompositingMode(true);
1102 }
1103
[email protected]872ae5b2011-05-26 20:20:501104 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:561105 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:041106 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:561107 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
1108 delay,
1109 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411110 base::TimeDelta::FromMilliseconds(120),
1111 60);
[email protected]d0be63772011-12-20 23:18:041112 } else {
[email protected]0fb93f52011-05-18 23:13:561113 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
1114 delay,
1115 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411116 base::TimeDelta::FromMilliseconds(120),
1117 60);
[email protected]d0be63772011-12-20 23:18:041118 }
[email protected]872ae5b2011-05-26 20:20:501119
1120 // Calculate filtered time per frame:
1121 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
1122 filtered_time_per_frame_ =
1123 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:561124 }
1125 last_do_deferred_update_time_ = frame_begin_ticks;
1126
[email protected]fef5e3972012-08-07 03:59:471127 if (!is_accelerated_compositing_active_) {
[email protected]62049562013-03-24 00:39:011128 software_stats_.animation_frame_count++;
1129 software_stats_.screen_frame_count++;
[email protected]fef5e3972012-08-07 03:59:471130 }
1131
[email protected]552e6002009-11-19 05:24:571132 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:291133 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:301134 PaintAggregator::PendingUpdate update;
1135 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:291136
[email protected]53d3f302009-12-21 04:42:051137 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:181138 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:291139
[email protected]29ed96a2012-02-04 18:12:161140 // Notify derived classes that we're about to initiate a paint.
1141 WillInitiatePaint();
1142
[email protected]ca4847f2010-09-24 05:39:151143 // A plugin may be able to do an optimized paint. First check this, in which
1144 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:461145 // This optimization allows PPAPI plugins that declare themselves on top of
1146 // the page (like a traditional windowed plugin) to be able to animate (think
1147 // movie playing) without repeatedly re-painting the page underneath, or
1148 // copying the plugin backing store (since we can send the plugin's backing
1149 // store directly to the browser).
1150 //
1151 // This optimization only works when the entire invalid region is contained
1152 // within the plugin. There is a related optimization in PaintRect for the
1153 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:151154 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:151155 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201156 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:211157 DCHECK(!pending_update_params_.get());
1158 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551159 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211160 pending_update_params_->scroll_rect = update.scroll_rect;
1161 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211162 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1163 pending_update_params_->flags = next_paint_flags_;
1164 pending_update_params_->scroll_offset = GetScrollOffset();
1165 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091166 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211167 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091168 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211169
[email protected]ca4847f2010-09-24 05:39:151170 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561171 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151172 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201173 &optimized_copy_rect,
1174 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271175 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471176 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211177 pending_update_params_->bitmap = dib->id();
1178 pending_update_params_->bitmap_rect = optimized_copy_location;
1179 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201180 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561181 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461182 // Compute a buffer for painting and cache it.
[email protected]4889bd212013-02-11 22:23:101183
1184 bool fractional_scale = device_scale_factor_ -
1185 static_cast<int>(device_scale_factor_) != 0;
1186 if (fractional_scale) {
1187 // Damage might not be DIP aligned. Inflate damage to compensate.
1188 bounds.Inset(-1, -1);
1189 bounds.Intersect(gfx::Rect(size_));
1190 }
1191
1192 gfx::Rect pixel_bounds = gfx::ToEnclosingRect(
[email protected]ce112fe2012-10-29 22:52:181193 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]4889bd212013-02-11 22:23:101194
[email protected]ca4847f2010-09-24 05:39:151195 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351196 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591197 pixel_bounds));
[email protected]59383c782013-04-17 16:43:271198 if (!canvas) {
[email protected]f98d7e3c2010-09-13 22:30:461199 NOTREACHED();
1200 return;
1201 }
[email protected]cef3362f2009-12-21 17:48:451202
[email protected]f98d7e3c2010-09-13 22:30:461203 // We may get back a smaller canvas than we asked for.
1204 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591205 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1206 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1207 pixel_bounds.set_width(canvas->getDevice()->width());
1208 pixel_bounds.set_height(canvas->getDevice()->height());
1209 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1210 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051211
[email protected]f98d7e3c2010-09-13 22:30:461212 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1213
[email protected]aa4117f2011-12-09 22:19:211214 pending_update_params_->bitmap = current_paint_buf_->id();
1215 pending_update_params_->bitmap_rect = bounds;
1216
1217 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461218 // The scroll damage is just another rectangle to paint and copy.
1219 copy_rects.swap(update.paint_rects);
1220 if (!scroll_damage.IsEmpty())
1221 copy_rects.push_back(scroll_damage);
1222
[email protected]4889bd212013-02-11 22:23:101223 for (size_t i = 0; i < copy_rects.size(); ++i) {
1224 gfx::Rect rect = copy_rects[i];
1225 if (fractional_scale) {
1226 // Damage might not be DPI aligned. Inflate rect to compensate.
1227 rect.Inset(-1, -1);
1228 }
1229 PaintRect(rect, pixel_bounds.origin(), canvas.get());
1230 }
[email protected]60a50072012-01-11 02:05:351231
1232 // Software FPS tick for performance tests. The accelerated path traces the
1233 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1234 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421235 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW",
1236 TRACE_EVENT_SCOPE_THREAD);
[email protected]f98d7e3c2010-09-13 22:30:461237 } else { // Accelerated compositing path
1238 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211239 // If painting is done via the gpu process then we don't set any damage
1240 // rects to save the browser process from doing unecessary work.
1241 pending_update_params_->bitmap_rect = bounds;
1242 pending_update_params_->scroll_rect = gfx::Rect();
1243 // We don't need an ack, because we're not sharing a DIB with the browser.
1244 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1245 // with the browser for the GPU surface.
1246 pending_update_params_->needs_ack = false;
[email protected]f0c2a242013-03-15 19:34:521247 Composite(frame_begin_ticks);
[email protected]f98d7e3c2010-09-13 22:30:461248 }
1249
[email protected]936c6f52011-12-13 01:35:261250 // If we're holding a pending input event ACK, send the ACK before sending the
1251 // UpdateReply message so we can receive another input event before the
1252 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1253 // the UpdateRect IPC message handler.
[email protected]59383c782013-04-17 16:43:271254 if (pending_input_event_ack_)
[email protected]936c6f52011-12-13 01:35:261255 Send(pending_input_event_ack_.release());
1256
[email protected]ab543072013-01-25 04:38:151257 // If Composite() called SwapBuffers, pending_update_params_ will be reset (in
[email protected]aa4117f2011-12-09 22:19:211258 // OnSwapBuffersPosted), meaning a message has been added to the
1259 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1260 // the message now.
[email protected]59383c782013-04-17 16:43:271261 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:211262 // sending an ack to browser process that the paint is complete...
1263 update_reply_pending_ = pending_update_params_->needs_ack;
1264 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1265 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341266 }
[email protected]53d3f302009-12-21 04:42:051267
[email protected]29ed96a2012-02-04 18:12:161268 // If we're software rendering then we're done initiating the paint.
1269 if (!is_accelerated_compositing_active_)
1270 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291271}
1272
[email protected]f0c2a242013-03-15 19:34:521273void RenderWidget::Composite(base::TimeTicks frame_begin_time) {
[email protected]ab543072013-01-25 04:38:151274 DCHECK(is_accelerated_compositing_active_);
[email protected]ba91a792013-02-06 09:48:281275 if (compositor_) // TODO(jamesr): Figure out how this can be null.
[email protected]f0c2a242013-03-15 19:34:521276 compositor_->Composite(frame_begin_time);
[email protected]ab543072013-01-25 04:38:151277}
1278
initial.commit09911bf2008-07-26 23:55:291279///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461280// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291281
[email protected]4873c7d2009-07-16 06:36:281282void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]479b0172012-10-29 19:27:091283 TRACE_EVENT2("renderer", "RenderWidget::didInvalidateRect",
1284 "width", rect.width, "height", rect.height);
[email protected]552e6002009-11-19 05:24:571285 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481286 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181287 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571288 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291289 return;
1290
[email protected]552e6002009-11-19 05:24:571291 paint_aggregator_.InvalidateRect(damaged_rect);
1292
1293 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241294 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571295 return;
1296 if (!paint_aggregator_.HasPendingUpdate())
1297 return;
[email protected]aa4117f2011-12-09 22:19:211298 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241299 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1300 return;
1301
1302 // When GPU rendering, combine pending animations and invalidations into
1303 // a single update.
[email protected]816edc62012-03-17 01:27:221304 if (is_accelerated_compositing_active_ &&
1305 animation_update_pending_ &&
1306 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571307 return;
1308
1309 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291310 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1311 // on the call stack.
1312 // 2) Allows us to collect more damage rects before painting to help coalesce
1313 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241314 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211315 MessageLoop::current()->PostTask(
1316 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291317}
1318
[email protected]990278ff2012-11-13 02:12:551319void RenderWidget::didScrollRect(int dx, int dy,
1320 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461321 // Drop scrolls on the floor when we are in compositing mode.
1322 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561323 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461324 return;
1325
[email protected]552e6002009-11-19 05:24:571326 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481327 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181328 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571329 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291330 return;
1331
[email protected]990278ff2012-11-13 02:12:551332 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571333
1334 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241335 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571336 return;
1337 if (!paint_aggregator_.HasPendingUpdate())
1338 return;
[email protected]aa4117f2011-12-09 22:19:211339 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241340 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1341 return;
1342
1343 // When GPU rendering, combine pending animations and invalidations into
1344 // a single update.
[email protected]816edc62012-03-17 01:27:221345 if (is_accelerated_compositing_active_ &&
1346 animation_update_pending_ &&
1347 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571348 return;
1349
1350 // Perform updating asynchronously. This serves two purposes:
1351 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1352 // on the call stack.
1353 // 2) Allows us to collect more damage rects before painting to help coalesce
1354 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241355 invalidation_task_posted_ = true;
[email protected]32876ae2011-11-15 22:25:211356 MessageLoop::current()->PostTask(
1357 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291358}
1359
[email protected]244ac1892011-12-02 17:04:471360void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091361 if (size_.width() != new_size.width || size_.height() != new_size.height) {
1362 size_ = new_size;
[email protected]240b5c32012-11-09 19:17:181363 // If we don't clear PaintAggregator after changing autoResize state, then
1364 // we might end up in a situation where bitmap_rect is larger than the
1365 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1366 // with invalid damage rects.
1367 paint_aggregator_.ClearPendingUpdate();
[email protected]8be1c582013-03-06 00:55:031368
[email protected]3a1c8a8032013-03-18 22:35:321369 if (auto_resize_mode_)
1370 AutoResizeCompositor();
[email protected]97e1bf72013-03-06 14:06:051371
[email protected]8be1c582013-03-06 00:55:031372 if (RenderThreadImpl::current()->short_circuit_size_updates()) {
1373 setWindowRect(WebRect(rootWindowRect().x,
1374 rootWindowRect().y,
1375 new_size.width,
1376 new_size.height));
1377 } else {
1378 need_update_rect_for_auto_resize_ = true;
1379 }
[email protected]ea3ee0a2012-05-15 03:43:091380 }
[email protected]244ac1892011-12-02 17:04:471381}
1382
[email protected]3a1c8a8032013-03-18 22:35:321383void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051384 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1385 device_scale_factor_));
1386 if (compositor_)
1387 compositor_->setViewportSize(size_, physical_backing_size_);
1388}
1389
[email protected]91acd1c2012-03-14 08:32:391390void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221391 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1392
[email protected]c63b4d42012-04-26 01:01:071393#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211394 if (!is_accelerated_compositing_active_) {
1395 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1396 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1397 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1398 // going to switch to accelerated compositing, the GPU process may need
1399 // round-trips to the browser's UI thread before finishing the frame,
1400 // causing deadlocks if we delay the UpdateRect until we receive the
1401 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071402 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1403 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211404 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1405 }
[email protected]c63b4d42012-04-26 01:01:071406#endif
[email protected]aa4117f2011-12-09 22:19:211407
[email protected]ea162f92011-10-04 23:08:221408 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421409 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241410 routing_id_, is_accelerated_compositing_active_));
[email protected]ea162f92011-10-04 23:08:221411}
1412
1413void RenderWidget::didDeactivateCompositor() {
1414 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1415
1416 is_accelerated_compositing_active_ = false;
1417 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1418 routing_id_, is_accelerated_compositing_active_));
1419
[email protected]ea162f92011-10-04 23:08:221420 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241421 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091422
1423 // In single-threaded mode, we exit force compositing mode and re-enter in
1424 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1425 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1426 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361427 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091428 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561429}
1430
[email protected]e195e582013-03-08 01:32:591431void RenderWidget::initializeLayerTreeView() {
1432 compositor_ = RenderWidgetCompositor::Create(this);
1433 if (!compositor_)
1434 return;
1435
1436 compositor_->setViewportSize(size_, physical_backing_size_);
1437 if (init_complete_)
1438 compositor_->setSurfaceReady();
1439}
1440
[email protected]8926c602013-01-23 05:32:061441WebKit::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281442 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061443}
1444
[email protected]9ed83fe2013-02-27 01:52:281445void RenderWidget::suppressCompositorScheduling(bool enable) {
1446 if (compositor_)
1447 compositor_->SetSuppressScheduleComposite(enable);
1448}
1449
[email protected]9cd43a62012-03-26 08:03:561450void RenderWidget::willBeginCompositorFrame() {
1451 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371452
[email protected]ea5f70a2013-03-07 12:30:361453 DCHECK(RenderThreadImpl::current()->compositor_message_loop_proxy());
[email protected]abe8b3a2012-03-28 21:19:371454
1455 // The following two can result in further layout and possibly
1456 // enable GPU acceleration so they need to be called before any painting
1457 // is done.
[email protected]2d354272013-01-14 00:59:061458 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]abe8b3a2012-03-28 21:19:371459 UpdateSelectionBounds();
1460
[email protected]9cd43a62012-03-26 08:03:561461 WillInitiatePaint();
1462}
1463
[email protected]3391a0772012-03-28 00:32:071464void RenderWidget::didBecomeReadyForAdditionalInput() {
1465 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]59383c782013-04-17 16:43:271466 if (pending_input_event_ack_)
[email protected]3391a0772012-03-28 00:32:071467 Send(pending_input_event_ack_.release());
1468}
1469
[email protected]6fceb912013-02-15 06:24:151470void RenderWidget::DidCommitCompositorFrame() {
1471}
1472
[email protected]58264a32011-11-17 23:36:151473void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501474 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351475 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1476 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421477 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU",
1478 TRACE_EVENT_SCOPE_THREAD);
[email protected]29ed96a2012-02-04 18:12:161479 // Notify subclasses that we initiated the paint operation.
1480 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151481}
1482
1483void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181484 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1485
1486 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561487 DidFlushPaint();
1488
[email protected]aa4117f2011-12-09 22:19:211489 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151490 return;
1491
[email protected]ea3ee0a2012-05-15 03:43:091492 if (!next_paint_flags_ &&
1493 !need_update_rect_for_auto_resize_ &&
1494 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151495 return;
[email protected]ea3ee0a2012-05-15 03:43:091496 }
[email protected]58264a32011-11-17 23:36:151497
1498 ViewHostMsg_UpdateRect_Params params;
1499 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151500 params.plugin_window_moves.swap(plugin_window_moves_);
1501 params.flags = next_paint_flags_;
1502 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121503 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091504 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151505
1506 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1507 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091508 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151509}
1510
[email protected]f98d7e3c2010-09-13 22:30:461511void RenderWidget::scheduleComposite() {
[email protected]479b0172012-10-29 19:27:091512 TRACE_EVENT0("gpu", "RenderWidget::scheduleComposite");
[email protected]ea5f70a2013-03-07 12:30:361513 if (RenderThreadImpl::current()->compositor_message_loop_proxy() &&
[email protected]ba91a792013-02-06 09:48:281514 compositor_) {
1515 compositor_->setNeedsRedraw();
[email protected]d0be63772011-12-20 23:18:041516 } else {
[email protected]c3d45532011-10-07 19:20:401517 // TODO(nduca): replace with something a little less hacky. The reason this
1518 // hack is still used is because the Invalidate-DoDeferredUpdate loop
1519 // contains a lot of host-renderer synchronization logic that is still
1520 // important for the accelerated compositing case. The option of simply
1521 // duplicating all that code is less desirable than "faking out" the
1522 // invalidation path using a magical damage rect.
1523 didInvalidateRect(WebRect(0, 0, 1, 1));
1524 }
[email protected]f98d7e3c2010-09-13 22:30:461525}
1526
[email protected]5f8b1022011-01-21 23:34:501527void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201528 if (animation_update_pending_)
1529 return;
1530
[email protected]921244e42011-07-20 16:36:301531 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201532 animation_update_pending_ = true;
1533 if (!animation_timer_.IsRunning()) {
1534 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1535 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211536 }
[email protected]5f8b1022011-01-21 23:34:501537}
1538
[email protected]4873c7d2009-07-16 06:36:281539void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301540 // TODO(darin): Eliminate this temporary.
1541 WebCursor cursor(cursor_info);
1542
initial.commit09911bf2008-07-26 23:55:291543 // Only send a SetCursor message if we need to make a change.
1544 if (!current_cursor_.IsEqual(cursor)) {
1545 current_cursor_ = cursor;
1546 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1547 }
1548}
1549
1550// We are supposed to get a single call to Show for a newly created RenderWidget
1551// that was created via RenderWidget::CreateWebView. So, we wait until this
1552// point to dispatch the ShowWidget message.
1553//
1554// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281555// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291556//
[email protected]4873c7d2009-07-16 06:36:281557void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291558 DCHECK(!did_show_) << "received extraneous Show call";
1559 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1560 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1561
[email protected]8de12d942010-11-17 20:42:441562 if (did_show_)
1563 return;
1564
1565 did_show_ = true;
1566 // NOTE: initial_pos_ may still have its default values at this point, but
1567 // that's okay. It'll be ignored if as_popup is false, or the browser
1568 // process will impose a default position otherwise.
1569 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1570 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291571}
1572
[email protected]4873c7d2009-07-16 06:36:281573void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291574}
1575
[email protected]4873c7d2009-07-16 06:36:281576void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291577}
1578
[email protected]2533ce12009-05-09 00:02:241579void RenderWidget::DoDeferredClose() {
1580 Send(new ViewHostMsg_Close(routing_id_));
1581}
1582
[email protected]4873c7d2009-07-16 06:36:281583void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321584 if (is_swapped_out_) {
1585 // This widget is currently swapped out, and the active widget is in a
1586 // different process. Have the browser route the close request to the
1587 // active widget instead, so that the correct unload handlers are run.
1588 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1589 return;
1590 }
1591
initial.commit09911bf2008-07-26 23:55:291592 // If a page calls window.close() twice, we'll end up here twice, but that's
1593 // OK. It is safe to send multiple Close messages.
1594
[email protected]2533ce12009-05-09 00:02:241595 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1596 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1597 // could be closed before the JS finishes executing. So instead, post a
1598 // message back to the message loop, which won't run until the JS is
1599 // complete, and then the Close message can be sent.
[email protected]32876ae2011-11-15 22:25:211600 MessageLoop::current()->PostTask(
1601 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291602}
1603
1604void RenderWidget::Close() {
1605 if (webwidget_) {
[email protected]8926c602013-01-23 05:32:061606 webwidget_->willCloseLayerTreeView();
[email protected]ba91a792013-02-06 09:48:281607 compositor_.reset();
[email protected]4873c7d2009-07-16 06:36:281608 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291609 webwidget_ = NULL;
1610 }
1611}
1612
[email protected]4873c7d2009-07-16 06:36:281613WebRect RenderWidget::windowRect() {
1614 if (pending_window_rect_count_)
1615 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241616
[email protected]80ad8622012-11-07 16:33:031617 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291618}
1619
[email protected]8a9d6ca32011-06-06 20:11:301620void RenderWidget::setToolTipText(const WebKit::WebString& text,
1621 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541622 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301623}
1624
[email protected]4873c7d2009-07-16 06:36:281625void RenderWidget::setWindowRect(const WebRect& pos) {
initial.commit09911bf2008-07-26 23:55:291626 if (did_show_) {
[email protected]8be1c582013-03-06 00:55:031627 if (!RenderThreadImpl::current()->short_circuit_size_updates()) {
1628 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1629 SetPendingWindowRect(pos);
1630 } else {
1631 WebSize new_size(pos.width, pos.height);
[email protected]d9083762013-03-24 01:36:401632 Resize(new_size, new_size, overdraw_bottom_height_,
1633 WebRect(), is_fullscreen_, NO_RESIZE_ACK);
[email protected]8be1c582013-03-06 00:55:031634 view_screen_rect_ = pos;
1635 window_screen_rect_ = pos;
1636 }
initial.commit09911bf2008-07-26 23:55:291637 } else {
1638 initial_pos_ = pos;
1639 }
1640}
1641
[email protected]2533ce12009-05-09 00:02:241642void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
1643 pending_window_rect_ = rect;
1644 pending_window_rect_count_++;
1645}
1646
[email protected]4873c7d2009-07-16 06:36:281647WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:241648 if (pending_window_rect_count_) {
1649 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
1650 // the RootWindowRect is probably going to return wrong results since the
1651 // browser may not have processed the Move yet. There isn't really anything
1652 // good to do in this case, and it shouldn't happen - since this size is
1653 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:281654 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241655 }
1656
[email protected]80ad8622012-11-07 16:33:031657 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:371658}
1659
[email protected]4873c7d2009-07-16 06:36:281660WebRect RenderWidget::windowResizerRect() {
1661 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:191662}
1663
[email protected]fa7b1dc2010-06-23 17:53:041664void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:031665 // To prevent this renderer process from sending unnecessary IPC messages to
1666 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:041667 // only during the input method attached to the browser process is active.
1668 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:291669}
1670
[email protected]58b48a0d2012-06-13 07:01:351671void RenderWidget::UpdateCompositionInfo(
1672 const ui::Range& range,
1673 const std::vector<gfx::Rect>& character_bounds) {
1674 if (!ShouldUpdateCompositionInfo(range, character_bounds))
1675 return;
1676 composition_character_bounds_ = character_bounds;
1677 composition_range_ = range;
1678 Send(new ViewHostMsg_ImeCompositionRangeChanged(
1679 routing_id(), composition_range_, composition_character_bounds_));
1680}
1681
[email protected]fa7b1dc2010-06-23 17:53:041682void RenderWidget::OnImeSetComposition(
1683 const string16& text,
1684 const std::vector<WebCompositionUnderline>& underlines,
1685 int selection_start, int selection_end) {
[email protected]4873c7d2009-07-16 06:36:281686 if (!webwidget_)
1687 return;
[email protected]e8f775f2013-02-14 21:00:501688 DCHECK(!handling_ime_event_);
1689 handling_ime_event_ = true;
[email protected]d4cff272011-05-02 15:46:011690 if (webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:041691 text, WebVector<WebCompositionUnderline>(underlines),
1692 selection_start, selection_end)) {
[email protected]d4cff272011-05-02 15:46:011693 // Setting the IME composition was successful. Send the new composition
1694 // range to the browser.
1695 ui::Range range(ui::Range::InvalidRange());
1696 size_t location, length;
1697 if (webwidget_->compositionRange(&location, &length)) {
1698 range.set_start(location);
1699 range.set_end(location + length);
1700 }
1701 // The IME was cancelled via the Esc key, so just send back the caret.
1702 else if (webwidget_->caretOrSelectionRange(&location, &length)) {
1703 range.set_start(location);
1704 range.set_end(location + length);
1705 }
[email protected]58b48a0d2012-06-13 07:01:351706 std::vector<gfx::Rect> character_bounds;
1707 GetCompositionCharacterBounds(&character_bounds);
1708 UpdateCompositionInfo(range, character_bounds);
[email protected]d4cff272011-05-02 15:46:011709 } else {
[email protected]fa7b1dc2010-06-23 17:53:041710 // If we failed to set the composition text, then we need to let the browser
1711 // process to cancel the input method's ongoing composition session, to make
1712 // sure we are in a consistent state.
1713 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]d4cff272011-05-02 15:46:011714
1715 // Send an updated IME range with just the caret range.
1716 ui::Range range(ui::Range::InvalidRange());
1717 size_t location, length;
1718 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1719 range.set_start(location);
1720 range.set_end(location + length);
1721 }
[email protected]58b48a0d2012-06-13 07:01:351722 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]7f00efa2010-04-15 05:01:261723 }
[email protected]e8f775f2013-02-14 21:00:501724 handling_ime_event_ = false;
1725 UpdateTextInputState(DO_NOT_SHOW_IME);
[email protected]fa7b1dc2010-06-23 17:53:041726}
1727
[email protected]4de6d1692011-10-12 08:45:441728void RenderWidget::OnImeConfirmComposition(
1729 const string16& text, const ui::Range& replacement_range) {
[email protected]d0be63772011-12-20 23:18:041730 if (!webwidget_)
1731 return;
[email protected]e8f775f2013-02-14 21:00:501732 DCHECK(!handling_ime_event_);
1733 handling_ime_event_ = true;
[email protected]d0be63772011-12-20 23:18:041734 handling_input_event_ = true;
1735 webwidget_->confirmComposition(text);
1736 handling_input_event_ = false;
1737
[email protected]d4cff272011-05-02 15:46:011738 // Send an updated IME range with just the caret range.
1739 ui::Range range(ui::Range::InvalidRange());
1740 size_t location, length;
1741 if (webwidget_->caretOrSelectionRange(&location, &length)) {
1742 range.set_start(location);
1743 range.set_end(location + length);
1744 }
[email protected]58b48a0d2012-06-13 07:01:351745 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]e8f775f2013-02-14 21:00:501746 handling_ime_event_ = false;
1747 UpdateTextInputState(DO_NOT_SHOW_IME);
initial.commit09911bf2008-07-26 23:55:291748}
1749
[email protected]948f7ab72010-05-28 23:48:081750// This message causes the renderer to render an image of the
1751// desired_size, regardless of whether the tab is hidden or not.
[email protected]3d9ec5052013-01-02 22:05:251752void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle,
1753 int tag,
1754 const gfx::Size& page_size,
1755 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:001756 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
1757 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:251758 // Close our unused handle.
1759#if defined(OS_WIN)
1760 ::CloseHandle(dib_handle);
1761#elif defined(OS_MACOSX)
1762 base::SharedMemory::CloseHandle(dib_handle);
1763#endif
1764 }
[email protected]d65adb12010-04-28 17:26:491765 return;
[email protected]45c6aad32010-11-11 04:46:251766 }
[email protected]d65adb12010-04-28 17:26:491767
[email protected]948f7ab72010-05-28 23:48:081768 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:491769 // If one of these is empty, then we just return the dib we were
1770 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:091771 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:491772 return;
1773 }
1774
1775 // Map the given DIB ID into this process, and unmap it at the end
1776 // of this function.
[email protected]45c6aad32010-11-11 04:46:251777 scoped_ptr<TransportDIB> paint_at_size_buffer(
1778 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:301779
[email protected]4b01b962012-10-09 23:17:351780 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281781 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:351782 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:281783 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:511784 gfx::Size canvas_size = page_size_in_pixel;
1785 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:491786 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:511787 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:491788 static_cast<float>(canvas_size.height());
1789
[email protected]ee8d6fd2010-05-26 17:05:481790 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491791 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
1792 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:481793 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:491794
[email protected]36808ad2010-10-20 19:18:301795 scoped_ptr<skia::PlatformCanvas> canvas(
1796 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
1797 canvas_size.height()));
[email protected]59383c782013-04-17 16:43:271798 if (!canvas) {
[email protected]36808ad2010-10-20 19:18:301799 NOTREACHED();
1800 return;
1801 }
1802
[email protected]d65adb12010-04-28 17:26:491803 // Reset bounds to what we actually received, but they should be the
1804 // same.
1805 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
1806 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
1807 bounds.set_width(canvas->getDevice()->width());
1808 bounds.set_height(canvas->getDevice()->height());
1809
1810 canvas->save();
[email protected]948f7ab72010-05-28 23:48:081811 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:491812 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
1813
[email protected]948f7ab72010-05-28 23:48:081814 // Have to make sure we're laid out at the right size before
1815 // rendering.
1816 gfx::Size old_size = webwidget_->size();
1817 webwidget_->resize(page_size);
1818 webwidget_->layout();
1819
[email protected]d65adb12010-04-28 17:26:491820 // Paint the entire thing (using original bounds, not scaled bounds).
1821 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
1822 canvas->restore();
1823
[email protected]948f7ab72010-05-28 23:48:081824 // Return the widget to its previous size.
1825 webwidget_->resize(old_size);
1826
[email protected]c88c9442010-07-19 18:55:091827 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:491828}
1829
[email protected]51a49502013-03-23 01:50:191830void RenderWidget::OnSnapshot(const gfx::Rect& src_subrect) {
1831 SkBitmap snapshot;
1832
1833 if (OnSnapshotHelper(src_subrect, &snapshot)) {
1834 Send(new ViewHostMsg_Snapshot(routing_id(), true, snapshot));
1835 } else {
1836 Send(new ViewHostMsg_Snapshot(routing_id(), false, SkBitmap()));
1837 }
1838}
1839
1840bool RenderWidget::OnSnapshotHelper(const gfx::Rect& src_subrect,
1841 SkBitmap* snapshot) {
1842 base::TimeTicks beginning_time = base::TimeTicks::Now();
1843
1844 if (!webwidget_ || src_subrect.IsEmpty())
1845 return false;
1846
1847 gfx::Rect viewport_size = gfx::IntersectRects(
1848 src_subrect, gfx::Rect(physical_backing_size_));
1849
1850 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(
1851 skia::CreatePlatformCanvas(viewport_size.width(),
1852 viewport_size.height(),
1853 true,
1854 NULL,
1855 skia::RETURN_NULL_ON_FAILURE));
[email protected]59383c782013-04-17 16:43:271856 if (!canvas)
[email protected]51a49502013-03-23 01:50:191857 return false;
1858
1859 canvas->save();
1860 webwidget_->layout();
1861
1862 PaintRect(viewport_size, viewport_size.origin(), canvas.get());
1863 canvas->restore();
1864
1865 const SkBitmap& bitmap = skia::GetTopDevice(*canvas)->accessBitmap(false);
1866 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
1867 return false;
1868
1869 UMA_HISTOGRAM_TIMES("Renderer4.Snapshot",
1870 base::TimeTicks::Now() - beginning_time);
1871 return true;
1872}
1873
[email protected]0bc1f572013-04-17 01:46:311874void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:121875 // During shutdown we can just ignore this message.
1876 if (!webwidget_)
1877 return;
1878
[email protected]0bc1f572013-04-17 01:46:311879 // Even if the browser provides an empty damage rect, it's still expecting to
1880 // receive a repaint ack so just damage the entire widget bounds.
1881 if (size_to_paint.IsEmpty()) {
1882 size_to_paint = size_;
1883 }
1884
[email protected]ec7dc112008-08-06 05:30:121885 set_next_paint_is_repaint_ack();
[email protected]0bc1f572013-04-17 01:46:311886 if (is_accelerated_compositing_active_ && compositor_) {
1887 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]f98d7e3c2010-09-13 22:30:461888 } else {
1889 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1890 didInvalidateRect(repaint_rect);
1891 }
[email protected]ec7dc112008-08-06 05:30:121892}
1893
[email protected]0c2ebef2013-04-03 12:14:101894void RenderWidget::OnSmoothScrollCompleted(int gesture_id) {
1895 PendingSmoothScrollGestureMap::iterator it =
1896 pending_smooth_scroll_gestures_.find(gesture_id);
1897 DCHECK(it != pending_smooth_scroll_gestures_.end());
1898 it->second.Run();
1899 pending_smooth_scroll_gestures_.erase(it);
[email protected]0e241b4b2012-08-18 09:06:271900}
1901
[email protected]4873c7d2009-07-16 06:36:281902void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:111903 if (!webwidget_)
1904 return;
[email protected]4873c7d2009-07-16 06:36:281905 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:111906}
1907
[email protected]6131a642012-06-15 23:26:531908void RenderWidget::OnScreenInfoChanged(
1909 const WebKit::WebScreenInfo& screen_info) {
1910 screen_info_ = screen_info;
[email protected]468ac582012-11-20 00:53:191911 SetDeviceScaleFactor(screen_info.deviceScaleFactor);
[email protected]6131a642012-06-15 23:26:531912}
1913
[email protected]80ad8622012-11-07 16:33:031914void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
1915 const gfx::Rect& window_screen_rect) {
1916 view_screen_rect_ = view_screen_rect;
1917 window_screen_rect_ = window_screen_rect;
1918 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
1919}
1920
[email protected]105dffb42013-02-20 03:46:211921#if defined(OS_ANDROID)
1922void RenderWidget::OnImeBatchStateChanged(bool is_begin) {
1923 Send(new ViewHostMsg_ImeBatchStateChanged_ACK(routing_id(), is_begin));
1924}
[email protected]2384b6c2013-02-28 23:58:511925
1926void RenderWidget::OnShowImeIfNeeded() {
1927 UpdateTextInputState(SHOW_IME_IF_NEEDED);
1928}
[email protected]105dffb42013-02-20 03:46:211929#endif
1930
[email protected]468ac582012-11-20 00:53:191931void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
1932 if (device_scale_factor_ == device_scale_factor)
1933 return;
1934
1935 device_scale_factor_ = device_scale_factor;
1936
1937 if (!is_accelerated_compositing_active_) {
1938 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
1939 } else {
1940 scheduleComposite();
1941 }
1942}
1943
[email protected]719b36f2010-12-22 20:36:461944webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint(
[email protected]ca4847f2010-09-24 05:39:151945 const gfx::Rect& paint_bounds,
1946 TransportDIB** dib,
1947 gfx::Rect* location,
[email protected]0f3a2d12012-09-01 03:37:201948 gfx::Rect* clip,
1949 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:461950 // Bare RenderWidgets don't support optimized plugin painting.
1951 return NULL;
[email protected]ca4847f2010-09-24 05:39:151952}
1953
[email protected]ceb36f7d2012-10-31 18:33:241954gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:521955 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:241956 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:521957}
1958
[email protected]bee16aab2009-08-26 15:55:031959void RenderWidget::SetHidden(bool hidden) {
1960 if (is_hidden_ == hidden)
1961 return;
1962
1963 // The status has changed. Tell the RenderThread about it.
1964 is_hidden_ = hidden;
1965 if (is_hidden_)
[email protected]380244092011-10-07 17:26:271966 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:031967 else
[email protected]380244092011-10-07 17:26:271968 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:031969}
1970
[email protected]2b624c562011-10-27 22:58:261971void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261972 if (!webwidget_)
1973 return;
1974
1975 if (is_fullscreen_) {
1976 webwidget_->willExitFullScreen();
1977 } else {
1978 webwidget_->willEnterFullScreen();
1979 }
[email protected]2b624c562011-10-27 22:58:261980}
1981
1982void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:261983 if (!webwidget_)
1984 return;
1985
1986 if (is_fullscreen_) {
1987 webwidget_->didEnterFullScreen();
1988 } else {
1989 webwidget_->didExitFullScreen();
1990 }
[email protected]2b624c562011-10-27 22:58:261991}
1992
[email protected]699ab0d2009-04-23 23:19:141993void RenderWidget::SetBackground(const SkBitmap& background) {
1994 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:461995
[email protected]699ab0d2009-04-23 23:19:141996 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:281997 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:141998}
1999
[email protected]674741932009-02-04 23:44:462000bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:052001 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462002}
2003
2004bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:052005 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462006}
2007
2008void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:052009 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462010}
2011
2012void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:052013 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:462014}
2015
2016void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:052017 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462018}
2019
[email protected]b18583c2012-12-18 06:55:272020static bool IsDateTimeInput(ui::TextInputType type) {
2021 return type == ui::TEXT_INPUT_TYPE_DATE ||
2022 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
2023 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
2024 type == ui::TEXT_INPUT_TYPE_MONTH ||
2025 type == ui::TEXT_INPUT_TYPE_TIME ||
2026 type == ui::TEXT_INPUT_TYPE_WEEK;
2027}
2028
[email protected]3306f262012-09-21 19:20:422029void RenderWidget::UpdateTextInputState(ShowIme show_ime) {
[email protected]e8f775f2013-02-14 21:00:502030 if (handling_ime_event_)
2031 return;
[email protected]3306f262012-09-21 19:20:422032 bool show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED);
2033 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:292034 return;
[email protected]ad26ef42011-06-17 07:59:452035 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:272036 if (IsDateTimeInput(new_type))
2037 return; // Not considered as a text input field in WebKit/Chromium.
2038
[email protected]5b739cb2012-08-21 20:35:212039 WebKit::WebTextInputInfo new_info;
2040 if (webwidget_)
2041 new_info = webwidget_->textInputInfo();
2042
[email protected]ad26ef42011-06-17 07:59:452043 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:212044
[email protected]3306f262012-09-21 19:20:422045 // Only sends text input params if they are changed or if the ime should be
2046 // shown.
2047 if (show_ime_if_needed || (text_input_type_ != new_type
2048 || text_input_info_ != new_info
2049 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:212050 ViewHostMsg_TextInputState_Params p;
2051 p.type = new_type;
2052 p.value = new_info.value.utf8();
2053 p.selection_start = new_info.selectionStart;
2054 p.selection_end = new_info.selectionEnd;
2055 p.composition_start = new_info.compositionStart;
2056 p.composition_end = new_info.compositionEnd;
2057 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:422058 p.show_ime_if_needed = show_ime_if_needed;
[email protected]5b739cb2012-08-21 20:35:212059 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
2060
2061 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:042062 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:452063 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:292064 }
initial.commit09911bf2008-07-26 23:55:292065}
2066
[email protected]7c8873e2013-02-05 08:03:012067void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2068 WebRect focus_webrect;
2069 WebRect anchor_webrect;
2070 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
2071 *focus = focus_webrect;
2072 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322073}
2074
[email protected]e99ef6f2011-10-16 01:13:002075void RenderWidget::UpdateSelectionBounds() {
2076 if (!webwidget_)
2077 return;
2078
[email protected]7c8873e2013-02-05 08:03:012079 ViewHostMsg_SelectionBounds_Params params;
2080 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2081 if (selection_anchor_rect_ != params.anchor_rect ||
2082 selection_focus_rect_ != params.focus_rect) {
2083 selection_anchor_rect_ = params.anchor_rect;
2084 selection_focus_rect_ = params.focus_rect;
2085 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
[email protected]129b7382013-02-12 02:14:292086 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
[email protected]7c8873e2013-02-05 08:03:012087 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
[email protected]58b48a0d2012-06-13 07:01:352088 }
[email protected]e99ef6f2011-10-16 01:13:002089
[email protected]58b48a0d2012-06-13 07:01:352090 std::vector<gfx::Rect> character_bounds;
2091 GetCompositionCharacterBounds(&character_bounds);
2092 UpdateCompositionInfo(composition_range_, character_bounds);
2093}
2094
2095bool RenderWidget::ShouldUpdateCompositionInfo(
2096 const ui::Range& range,
2097 const std::vector<gfx::Rect>& bounds) {
2098 if (composition_range_ != range)
2099 return true;
2100 if (bounds.size() != composition_character_bounds_.size())
2101 return true;
2102 for (size_t i = 0; i < bounds.size(); ++i) {
2103 if (bounds[i] != composition_character_bounds_[i])
2104 return true;
2105 }
2106 return false;
[email protected]e99ef6f2011-10-16 01:13:002107}
2108
[email protected]73bf95812011-10-12 11:38:322109// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:452110COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
2111 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
2112COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
2113 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
2114COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
2115 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:182116COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
2117 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
2118COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
2119 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
2120COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
2121 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
2122COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
2123 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
2124COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
2125 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:002126COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
2127 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
2128COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
2129 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
2130COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
2131 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
2132COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
2133 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
2134COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
2135 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
2136COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
2137 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:012138COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
2139 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
2140COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
2141 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]8b4992e2013-03-01 15:42:152142COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeField) == \
2143 int(ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:452144
[email protected]5b739cb2012-08-21 20:35:212145ui::TextInputType RenderWidget::WebKitToUiTextInputType(
2146 WebKit::WebTextInputType type) {
2147 // Check the type is in the range representable by ui::TextInputType.
2148 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
2149 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
2150 return static_cast<ui::TextInputType>(type);
2151}
2152
[email protected]ad26ef42011-06-17 07:59:452153ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272154 if (webwidget_)
2155 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452156 return ui::TEXT_INPUT_TYPE_NONE;
2157}
2158
[email protected]58b48a0d2012-06-13 07:01:352159void RenderWidget::GetCompositionCharacterBounds(
2160 std::vector<gfx::Rect>* bounds) {
2161 DCHECK(bounds);
2162 bounds->clear();
2163}
2164
[email protected]ad26ef42011-06-17 07:59:452165bool RenderWidget::CanComposeInline() {
2166 return true;
[email protected]56ea1a62011-05-30 07:05:572167}
2168
[email protected]4873c7d2009-07-16 06:36:282169WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042170 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282171}
2172
[email protected]f660d9c2012-06-06 18:31:212173float RenderWidget::deviceScaleFactor() {
2174 return device_scale_factor_;
2175}
2176
[email protected]fa7b1dc2010-06-23 17:53:042177void RenderWidget::resetInputMethod() {
2178 if (!input_method_is_active_)
2179 return;
2180
2181 // If the last text input type is not None, then we should finish any
2182 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452183 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042184 // If a composition text exists, then we need to let the browser process
2185 // to cancel the input method's ongoing composition session.
2186 if (webwidget_->confirmComposition())
2187 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
2188 }
[email protected]d4cff272011-05-02 15:46:012189
2190 // Send an updated IME range with the current caret rect.
2191 ui::Range range(ui::Range::InvalidRange());
2192 size_t location, length;
2193 if (webwidget_->caretOrSelectionRange(&location, &length)) {
2194 range.set_start(location);
2195 range.set_end(location + length);
2196 }
[email protected]58b48a0d2012-06-13 07:01:352197
2198 UpdateCompositionInfo(range, std::vector<gfx::Rect>());
[email protected]fa7b1dc2010-06-23 17:53:042199}
2200
[email protected]c68c3e4e2013-01-24 00:36:562201void RenderWidget::didHandleGestureEvent(
2202 const WebGestureEvent& event,
2203 bool event_cancelled) {
2204#if defined(OS_ANDROID)
2205 if (event_cancelled)
2206 return;
2207 if (event.type == WebInputEvent::GestureTap ||
2208 event.type == WebInputEvent::GestureLongPress) {
2209 UpdateTextInputState(SHOW_IME_IF_NEEDED);
2210 }
2211#endif
2212}
2213
[email protected]f103ab72009-09-02 17:10:592214void RenderWidget::SchedulePluginMove(
[email protected]191eb3f72010-12-21 06:27:502215 const webkit::npapi::WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292216 size_t i = 0;
2217 for (; i < plugin_window_moves_.size(); ++i) {
2218 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582219 if (move.rects_valid) {
2220 plugin_window_moves_[i] = move;
2221 } else {
2222 plugin_window_moves_[i].visible = move.visible;
2223 }
initial.commit09911bf2008-07-26 23:55:292224 break;
2225 }
2226 }
2227
2228 if (i == plugin_window_moves_.size())
2229 plugin_window_moves_.push_back(move);
2230}
[email protected]268654772009-08-06 23:02:042231
2232void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2233 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2234 i != plugin_window_moves_.end(); ++i) {
2235 if (i->window == window) {
2236 plugin_window_moves_.erase(i);
2237 break;
2238 }
2239 }
2240}
[email protected]67bfb83f2011-09-22 03:36:372241
[email protected]b63d58d2012-11-26 22:37:442242void RenderWidget::GetRenderingStats(
2243 WebKit::WebRenderingStatsImpl& stats) const {
[email protected]ba91a792013-02-06 09:48:282244 if (compositor_)
[email protected]635353c2013-03-06 09:11:202245 compositor_->GetRenderingStats(&stats.rendering_stats);
[email protected]b63d58d2012-11-26 22:37:442246
[email protected]62049562013-03-24 00:39:012247 stats.rendering_stats.animation_frame_count +=
2248 software_stats_.animation_frame_count;
2249 stats.rendering_stats.screen_frame_count +=
2250 software_stats_.screen_frame_count;
2251 stats.rendering_stats.total_paint_time +=
2252 software_stats_.total_paint_time;
2253 stats.rendering_stats.total_pixels_painted +=
2254 software_stats_.total_pixels_painted;
2255 stats.rendering_stats.total_rasterize_time +=
2256 software_stats_.total_rasterize_time;
2257 stats.rendering_stats.total_pixels_rasterized +=
2258 software_stats_.total_pixels_rasterized;
[email protected]fef5e3972012-08-07 03:59:472259}
2260
[email protected]e9ff79c2012-10-19 21:31:262261bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:522262 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
2263 if (!gpu_channel)
2264 return false;
2265
2266 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
2267}
2268
[email protected]0c2ebef2013-04-03 12:14:102269void RenderWidget::BeginSmoothScroll(
[email protected]0e241b4b2012-08-18 09:06:272270 bool down,
[email protected]ebd8b562012-10-09 14:44:292271 const SmoothScrollCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:192272 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:292273 int mouse_event_x,
2274 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:272275 DCHECK(!callback.is_null());
[email protected]0c2ebef2013-04-03 12:14:102276 int id = next_smooth_scroll_gesture_id_++;
[email protected]267909d2012-10-20 04:36:192277
2278 ViewHostMsg_BeginSmoothScroll_Params params;
2279 params.scroll_down = down;
2280 params.pixels_to_scroll = pixels_to_scroll;
2281 params.mouse_event_x = mouse_event_x;
2282 params.mouse_event_y = mouse_event_y;
2283
[email protected]0c2ebef2013-04-03 12:14:102284 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, id, params));
2285 pending_smooth_scroll_gestures_.insert(std::make_pair(id, callback));
[email protected]a39ca1652012-07-13 21:30:582286}
2287
[email protected]67bfb83f2011-09-22 03:36:372288bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
2289 return false;
2290}
[email protected]c3d45532011-10-07 19:20:402291
[email protected]41d86852012-11-07 12:23:242292bool RenderWidget::WillHandleGestureEvent(
2293 const WebKit::WebGestureEvent& event) {
2294 return false;
2295}
2296
[email protected]ce6689f2013-03-29 12:52:552297void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2298 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2299}
2300
[email protected]3d5c243b2012-11-30 00:26:012301bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2302 return true;
2303}
2304
[email protected]3ae68c52013-04-12 06:10:052305WebGraphicsContext3DCommandBufferImpl* RenderWidget::CreateGraphicsContext3D(
[email protected]92fd8c02013-03-29 08:54:152306 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
[email protected]ed7defa2013-03-12 21:29:592307 if (!webwidget_)
2308 return NULL;
[email protected]8f746982013-03-21 06:28:032309 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
2310 new WebGraphicsContext3DCommandBufferImpl(
2311 surface_id(),
2312 GetURLForGraphicsContext3D(),
2313 RenderThreadImpl::current(),
2314 weak_ptr_factory_.GetWeakPtr()));
[email protected]ed7defa2013-03-12 21:29:592315
[email protected]8f746982013-03-21 06:28:032316 if (!context->Initialize(
2317 attributes,
2318 false /* bind generates resources */,
2319 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE))
2320 return NULL;
2321 return context.release();
[email protected]ed7defa2013-03-12 21:29:592322}
2323
[email protected]e9ff79c2012-10-19 21:31:262324} // namespace content