blob: 1cb162a4843b4c8b660873e3c838448ebe051633 [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"
[email protected]b256eca2013-07-11 10:57:4012#include "base/memory/singleton.h"
[email protected]aaf68892013-07-18 00:11:3013#include "base/message_loop/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3814#include "base/metrics/histogram.h"
[email protected]aa4117f2011-12-09 22:19:2115#include "base/stl_util.h"
[email protected]74ebfb12013-06-07 20:48:0016#include "base/strings/utf_string_conversions.h"
[email protected]661eb9d2009-02-03 02:11:4817#include "build/build_config.h"
[email protected]681ccff2013-03-18 06:13:5218#include "cc/base/switches.h"
[email protected]adbe30f2013-10-11 21:12:3319#include "cc/debug/benchmark_instrumentation.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]29e2fb42013-07-19 01:13:4722#include "content/child/npapi/webplugin.h"
[email protected]0634cdd42013-08-16 00:46:0923#include "content/common/gpu/client/context_provider_command_buffer.h"
[email protected]ed7defa2013-03-12 21:29:5924#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
[email protected]c084330e02013-04-27 01:08:1525#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1526#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5027#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2928#include "content/public/common/content_switches.h"
[email protected]953bd0062013-08-01 00:58:4029#include "content/renderer/cursor_utils.h"
[email protected]b2e4c70132013-10-03 02:07:5130#include "content/renderer/external_popup_menu.h"
[email protected]ed7defa2013-03-12 21:29:5931#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]2847b222013-04-06 00:59:2432#include "content/renderer/gpu/compositor_software_output_device.h"
[email protected]36e5ff12013-06-11 12:19:2933#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]ea5f70a2013-03-07 12:30:3634#include "content/renderer/gpu/input_handler_manager.h"
[email protected]ed7defa2013-03-12 21:29:5935#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]ba91a792013-02-06 09:48:2836#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2937#include "content/renderer/ime_event_guard.h"
[email protected]adab2332013-07-25 18:04:3238#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]8704f89b2011-04-15 00:30:0539#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4440#include "content/renderer/render_thread_impl.h"
[email protected]8d6cba42011-09-02 10:05:1941#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]484955942010-08-19 16:13:1842#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4843#include "skia/ext/platform_canvas.h"
[email protected]aaf68892013-07-18 00:11:3044#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
45#include "third_party/WebKit/public/platform/WebPoint.h"
46#include "third_party/WebKit/public/platform/WebRect.h"
47#include "third_party/WebKit/public/platform/WebSize.h"
48#include "third_party/WebKit/public/platform/WebString.h"
[email protected]2255a9332013-06-17 05:12:3149#include "third_party/WebKit/public/web/WebCursorInfo.h"
50#include "third_party/WebKit/public/web/WebHelperPlugin.h"
51#include "third_party/WebKit/public/web/WebPagePopup.h"
52#include "third_party/WebKit/public/web/WebPopupMenu.h"
53#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
54#include "third_party/WebKit/public/web/WebRange.h"
55#include "third_party/WebKit/public/web/WebScreenInfo.h"
[email protected]d353541f2012-05-03 22:45:4156#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1357#include "ui/base/ui_base_switches.h"
[email protected]b2e4c70132013-10-03 02:07:5158#include "ui/gfx/point_conversions.h"
[email protected]a25e25b2012-09-28 14:32:3759#include "ui/gfx/rect_conversions.h"
[email protected]4b01b962012-10-09 23:17:3560#include "ui/gfx/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4861#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2762#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4163#include "ui/surface/transport_dib.h"
[email protected]799fd732013-05-15 21:18:5264#include "webkit/renderer/compositor_bindings/web_rendering_stats_impl.h"
[email protected]661eb9d2009-02-03 02:11:4865
[email protected]eeb93112013-05-01 19:41:1066#if defined(OS_ANDROID)
[email protected]b6eb8e332013-09-10 00:51:0167#include "base/android/sys_utils.h"
[email protected]913d99a2013-05-31 07:16:0768#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]eeb93112013-05-01 19:41:1069#endif
70
[email protected]661eb9d2009-02-03 02:11:4871#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4972#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5273#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4174#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4875#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4476
[email protected]2255a9332013-06-17 05:12:3177#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2978
[email protected]fa7b1dc2010-06-23 17:53:0479using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3080using WebKit::WebCursorInfo;
[email protected]41d86852012-11-07 12:23:2481using WebKit::WebGestureEvent;
[email protected]62cb33cae2009-03-27 23:30:2282using WebKit::WebInputEvent;
[email protected]f56c7872013-06-18 12:31:5783using WebKit::WebKeyboardEvent;
[email protected]6a8ddba52010-09-05 04:38:0684using WebKit::WebMouseEvent;
[email protected]b2e4c70132013-10-03 02:07:5185using WebKit::WebMouseWheelEvent;
[email protected]4873c7d2009-07-16 06:36:2886using WebKit::WebNavigationPolicy;
[email protected]a7547fb2012-03-08 04:43:4487using WebKit::WebPagePopup;
[email protected]e99ef6f2011-10-16 01:13:0088using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2889using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5990using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1891using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0192using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5293using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1994using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5295using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2896using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2497using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0498using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:1899using WebKit::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26100
[email protected]6a4d7f62013-01-07 21:32:13101namespace {
102const char* GetEventName(WebInputEvent::Type type) {
103#define CASE_TYPE(t) case WebInputEvent::t: return #t
104 switch(type) {
105 CASE_TYPE(Undefined);
106 CASE_TYPE(MouseDown);
107 CASE_TYPE(MouseUp);
108 CASE_TYPE(MouseMove);
109 CASE_TYPE(MouseEnter);
110 CASE_TYPE(MouseLeave);
111 CASE_TYPE(ContextMenu);
112 CASE_TYPE(MouseWheel);
113 CASE_TYPE(RawKeyDown);
114 CASE_TYPE(KeyDown);
115 CASE_TYPE(KeyUp);
116 CASE_TYPE(Char);
117 CASE_TYPE(GestureScrollBegin);
118 CASE_TYPE(GestureScrollEnd);
119 CASE_TYPE(GestureScrollUpdate);
120 CASE_TYPE(GestureFlingStart);
121 CASE_TYPE(GestureFlingCancel);
122 CASE_TYPE(GestureTap);
[email protected]1c43b0a2013-05-10 07:43:23123 CASE_TYPE(GestureTapUnconfirmed);
[email protected]6a4d7f62013-01-07 21:32:13124 CASE_TYPE(GestureTapDown);
125 CASE_TYPE(GestureTapCancel);
126 CASE_TYPE(GestureDoubleTap);
127 CASE_TYPE(GestureTwoFingerTap);
128 CASE_TYPE(GestureLongPress);
129 CASE_TYPE(GestureLongTap);
130 CASE_TYPE(GesturePinchBegin);
131 CASE_TYPE(GesturePinchEnd);
132 CASE_TYPE(GesturePinchUpdate);
133 CASE_TYPE(TouchStart);
134 CASE_TYPE(TouchMove);
135 CASE_TYPE(TouchEnd);
136 CASE_TYPE(TouchCancel);
[email protected]3ec08ed2013-01-11 15:59:57137 default:
138 // Must include default to let WebKit::WebInputEvent add new event types
139 // before they're added here.
140 DLOG(WARNING) << "Unhandled WebInputEvent type in GetEventName.\n";
141 break;
[email protected]6a4d7f62013-01-07 21:32:13142 }
143#undef CASE_TYPE
[email protected]3ec08ed2013-01-11 15:59:57144 return "";
[email protected]6a4d7f62013-01-07 21:32:13145}
[email protected]b256eca2013-07-11 10:57:40146
147typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
148
149class TextInputModeMapSingleton {
150 public:
151 static TextInputModeMapSingleton* GetInstance() {
152 return Singleton<TextInputModeMapSingleton>::get();
153 }
154 TextInputModeMapSingleton()
155 : map() {
156 map["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
157 map["latin"] = ui::TEXT_INPUT_MODE_LATIN;
158 map["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
159 map["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
160 map["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
161 map["kana"] = ui::TEXT_INPUT_MODE_KANA;
162 map["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
163 map["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
164 map["tel"] = ui::TEXT_INPUT_MODE_TEL;
165 map["email"] = ui::TEXT_INPUT_MODE_EMAIL;
166 map["url"] = ui::TEXT_INPUT_MODE_URL;
167 }
168 TextInputModeMap& Map() {
169 return map;
170 }
171 private:
172 TextInputModeMap map;
173
174 friend struct DefaultSingletonTraits<TextInputModeMapSingleton>;
175
176 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
177};
178
179ui::TextInputMode ConvertInputMode(
180 const WebKit::WebString& input_mode) {
181 static TextInputModeMapSingleton* singleton =
182 TextInputModeMapSingleton::GetInstance();
183 TextInputModeMap::iterator it = singleton->Map().find(input_mode.utf8());
184 if (it == singleton->Map().end())
185 return ui::TEXT_INPUT_MODE_DEFAULT;
186 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13187}
[email protected]b256eca2013-07-11 10:57:40188
189} // namespace
190
[email protected]e9ff79c2012-10-19 21:31:26191namespace content {
[email protected]62cb33cae2009-03-27 23:30:22192
[email protected]b2e4c70132013-10-03 02:07:51193// RenderWidget::ScreenMetricsEmulator ----------------------------------------
194
195class RenderWidget::ScreenMetricsEmulator {
196 public:
197 ScreenMetricsEmulator(
198 RenderWidget* widget,
199 const gfx::Size& device_size,
200 const gfx::Rect& widget_rect,
201 float device_scale_factor,
202 bool fit_to_view);
203 virtual ~ScreenMetricsEmulator();
204
205 float scale() { return scale_; }
206 gfx::Rect widget_rect() const { return widget_rect_; }
207 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
208
209 void ChangeEmulationParams(
210 const gfx::Size& device_size,
211 const gfx::Rect& widget_rect,
212 float device_scale_factor,
213 bool fit_to_view);
214
215 // The following methods alter handlers' behavior for messages related to
216 // widget size and position.
217 void OnResizeMessage(const ViewMsg_Resize_Params& params);
218 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
219 const gfx::Rect& window_screen_rect);
220 void OnShowContextMenu(ContextMenuParams* params);
221
222 private:
223 void Apply(float overdraw_bottom_height,
224 gfx::Rect resizer_rect, bool is_fullscreen);
225
226 RenderWidget* widget_;
227
228 // Parameters as passed by RenderWidget::EmulateScreenMetrics.
229 gfx::Size device_size_;
230 gfx::Rect widget_rect_;
231 float device_scale_factor_;
232 bool fit_to_view_;
233
234 // The computed scaled used to fit widget into browser window.
235 float scale_;
236
237 // Original values to restore back after emulation ends.
238 gfx::Size original_size_;
239 gfx::Size original_physical_backing_size_;
240 WebKit::WebScreenInfo original_screen_info_;
241 gfx::Rect original_view_screen_rect_;
242 gfx::Rect original_window_screen_rect_;
243};
244
245RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator(
246 RenderWidget* widget,
247 const gfx::Size& device_size,
248 const gfx::Rect& widget_rect,
249 float device_scale_factor,
250 bool fit_to_view)
251 : widget_(widget),
252 device_size_(device_size),
253 widget_rect_(widget_rect),
254 device_scale_factor_(device_scale_factor),
255 fit_to_view_(fit_to_view),
256 scale_(1.f) {
257 original_size_ = widget_->size_;
258 original_physical_backing_size_ = widget_->physical_backing_size_;
259 original_screen_info_ = widget_->screen_info_;
260 original_view_screen_rect_ = widget_->view_screen_rect_;
261 original_window_screen_rect_ = widget_->window_screen_rect_;
262 Apply(widget_->overdraw_bottom_height_,
263 widget_->resizer_rect_, widget_->is_fullscreen_);
264}
265
266RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
267 widget_->screen_info_ = original_screen_info_;
268
269 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
270 widget_->SetScreenMetricsEmulationParameters(0.f, 1.f);
271 widget_->view_screen_rect_ = original_view_screen_rect_;
272 widget_->window_screen_rect_ = original_window_screen_rect_;
273 widget_->Resize(original_size_, original_physical_backing_size_,
274 widget_->overdraw_bottom_height_, widget_->resizer_rect_,
275 widget_->is_fullscreen_, NO_RESIZE_ACK);
276}
277
278void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
279 const gfx::Size& device_size,
280 const gfx::Rect& widget_rect,
281 float device_scale_factor,
282 bool fit_to_view) {
283 device_size_ = device_size;
284 widget_rect_ = widget_rect;
285 device_scale_factor_ = device_scale_factor;
286 fit_to_view_ = fit_to_view;
287 Apply(widget_->overdraw_bottom_height_,
288 widget_->resizer_rect_, widget_->is_fullscreen_);
289}
290
291void RenderWidget::ScreenMetricsEmulator::Apply(
292 float overdraw_bottom_height, gfx::Rect resizer_rect, bool is_fullscreen) {
293 if (fit_to_view_) {
294 DCHECK(!original_size_.IsEmpty());
295 float width_ratio =
296 static_cast<float>(widget_rect_.width()) / original_size_.width();
297 float height_ratio =
298 static_cast<float>(widget_rect_.height()) / original_size_.height();
299 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
300 scale_ = 1.f / ratio;
301 } else {
302 scale_ = 1.f;
303 }
304
305 widget_->screen_info_.rect = gfx::Rect(device_size_);
306 widget_->screen_info_.availableRect = gfx::Rect(device_size_);
307 widget_->screen_info_.deviceScaleFactor = device_scale_factor_;
308
309 // Pass two emulation parameters to the blink side:
310 // - we keep the real device scale factor in compositor to produce sharp image
311 // even when emulating different scale factor;
312 // - in order to fit into view, WebView applies scaling transform to the
313 // root layer.
314 widget_->SetScreenMetricsEmulationParameters(
315 original_screen_info_.deviceScaleFactor, scale_);
316
317 widget_->SetDeviceScaleFactor(device_scale_factor_);
318 widget_->view_screen_rect_ = widget_rect_;
319 widget_->window_screen_rect_ = widget_->screen_info_.availableRect;
320
321 gfx::Size physical_backing_size = gfx::ToCeiledSize(gfx::ScaleSize(
322 original_size_, original_screen_info_.deviceScaleFactor));
323 widget_->Resize(widget_rect_.size(), physical_backing_size,
324 overdraw_bottom_height, resizer_rect, is_fullscreen, NO_RESIZE_ACK);
325}
326
327void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
328 const ViewMsg_Resize_Params& params) {
329 bool need_ack = params.new_size != original_size_ &&
330 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
331 original_size_ = params.new_size;
332 original_physical_backing_size_ = params.physical_backing_size;
333 original_screen_info_ = params.screen_info;
334 Apply(params.overdraw_bottom_height, params.resizer_rect,
335 params.is_fullscreen);
336
337 if (need_ack) {
338 widget_->set_next_paint_is_resize_ack();
339 if (widget_->compositor_)
340 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
341 }
342}
343
344void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
345 const gfx::Rect& view_screen_rect,
346 const gfx::Rect& window_screen_rect) {
347 original_view_screen_rect_ = view_screen_rect;
348 original_window_screen_rect_ = window_screen_rect;
349}
350
351void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
352 ContextMenuParams* params) {
353 params->x *= scale_;
354 params->y *= scale_;
355}
356
357// RenderWidget ---------------------------------------------------------------
358
[email protected]6fd35b72012-03-01 19:46:41359RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]842f10652012-06-06 01:54:04360 const WebKit::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04361 bool swapped_out,
362 bool hidden)
initial.commit09911bf2008-07-26 23:55:29363 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56364 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:11365 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:29366 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30367 init_complete_(false),
[email protected]b4d08452010-10-05 17:34:35368 current_paint_buf_(NULL),
[email protected]d9083762013-03-24 01:36:40369 overdraw_bottom_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29370 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:06371 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:05372 update_reply_pending_(false),
[email protected]847a2582013-03-09 02:29:51373 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09374 need_update_rect_for_auto_resize_(false),
[email protected]65225772011-05-12 21:10:24375 using_asynchronous_swapbuffers_(false),
376 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:29377 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04378 is_hidden_(hidden),
[email protected]ee41e7d22011-10-14 19:34:09379 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:29380 needs_repainting_on_restore_(false),
381 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49382 handling_input_event_(false),
[email protected]e8f775f2013-02-14 21:00:50383 handling_ime_event_(false),
[email protected]661eb9d2009-02-03 02:11:48384 closing_(false),
[email protected]14392a52012-05-02 20:28:44385 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04386 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45387 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40388 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
[email protected]86ba5fcb2013-09-04 00:36:53389 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12390 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48391 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12392 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50393 is_accelerated_compositing_active_(false),
[email protected]d8a6c5d12013-09-23 04:37:10394 was_accelerated_compositing_ever_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21395 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07396 invalidation_task_posted_(false),
[email protected]842f10652012-06-06 01:54:04397 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52398 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]ed7defa2013-03-12 21:29:59399 is_threaded_compositing_enabled_(false),
[email protected]53b4cc12013-07-18 23:02:30400 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13401#if defined(OS_ANDROID)
402 outstanding_ime_acks_(0),
403#endif
[email protected]b2e4c70132013-10-03 02:07:51404 popup_origin_scale_for_emulation_(0.f),
[email protected]69e797f2013-04-30 01:10:22405 weak_ptr_factory_(this) {
[email protected]8b3f0eb2012-05-03 19:15:05406 if (!swapped_out)
407 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27408 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18409 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
410 switches::kDisableGpuVsync);
[email protected]cb6430932012-10-31 00:53:36411 is_threaded_compositing_enabled_ =
412 CommandLine::ForCurrentProcess()->HasSwitch(
413 switches::kEnableThreadedCompositing);
[email protected]c1e6cc062013-08-24 03:35:35414
415 legacy_software_mode_stats_ = cc::RenderingStatsInstrumentation::Create();
416 if (CommandLine::ForCurrentProcess()->HasSwitch(
417 switches::kEnableGpuBenchmarking))
418 legacy_software_mode_stats_->set_record_rendering_stats(true);
initial.commit09911bf2008-07-26 23:55:29419}
420
421RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11422 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21423 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35424 if (current_paint_buf_) {
[email protected]467414eb2013-07-30 20:32:29425 if (RenderProcess::current()) {
426 // If the RenderProcess is already gone, it will have released all DIBs
427 // in its destructor anyway.
428 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
429 }
[email protected]b4d08452010-10-05 17:34:35430 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29431 }
[email protected]992db4c2011-05-12 15:37:15432 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02433 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15434 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29435}
436
[email protected]484955942010-08-19 16:13:18437// static
[email protected]8085dbc82008-09-26 22:53:44438RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:04439 WebKit::WebPopupType popup_type,
440 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29441 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41442 scoped_refptr<RenderWidget> widget(
[email protected]1ac10dca2013-08-20 20:47:04443 new RenderWidget(popup_type, screen_info, false, false));
[email protected]a635f942012-12-07 10:34:29444 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46445 return widget.get();
[email protected]a635f942012-12-07 10:34:29446 }
447 return NULL;
initial.commit09911bf2008-07-26 23:55:29448}
449
[email protected]484955942010-08-19 16:13:18450// static
451WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
452 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03453 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18454 break;
455 case WebKit::WebPopupTypeSelect:
456 case WebKit::WebPopupTypeSuggestion:
457 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44458 case WebKit::WebPopupTypePage:
459 return WebPagePopup::create(render_widget);
[email protected]4b1146bc2012-07-10 18:46:03460 case WebKit::WebPopupTypeHelperPlugin:
461 return WebKit::WebHelperPlugin::create(render_widget);
[email protected]484955942010-08-19 16:13:18462 default:
463 NOTREACHED();
464 }
465 return NULL;
466}
467
[email protected]a635f942012-12-07 10:34:29468bool RenderWidget::Init(int32 opener_id) {
469 return DoInit(opener_id,
470 RenderWidget::CreateWebWidget(this),
471 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
472 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18473}
474
[email protected]a635f942012-12-07 10:34:29475bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06476 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18477 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29478 DCHECK(!webwidget_);
479
480 if (opener_id != MSG_ROUTING_NONE)
481 opener_id_ = opener_id;
482
[email protected]484955942010-08-19 16:13:18483 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29484
[email protected]380244092011-10-07 17:26:27485 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29486 if (result) {
[email protected]380244092011-10-07 17:26:27487 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29488 // Take a reference on behalf of the RenderThread. This will be balanced
489 // when we receive ViewMsg_Close.
490 AddRef();
[email protected]1ac10dca2013-08-20 20:47:04491 if (is_hidden_)
492 RenderThread::Get()->WidgetHidden();
[email protected]a635f942012-12-07 10:34:29493 return true;
initial.commit09911bf2008-07-26 23:55:29494 } else {
[email protected]a635f942012-12-07 10:34:29495 // The above Send can fail when the tab is closing.
496 return false;
initial.commit09911bf2008-07-26 23:55:29497 }
498}
499
[email protected]fc4404d2012-11-07 19:53:30500// This is used to complete pending inits and non-pending inits.
501void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29502 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29503
[email protected]fc4404d2012-11-07 19:53:30504 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42505
[email protected]8926c602013-01-23 05:32:06506 if (webwidget_ && is_threaded_compositing_enabled_) {
507 webwidget_->enterForceCompositingMode(true);
508 }
[email protected]ba91a792013-02-06 09:48:28509 if (compositor_) {
510 compositor_->setSurfaceReady();
[email protected]479b0172012-10-29 19:27:09511 }
[email protected]05a980d7a2012-02-07 22:16:42512 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29513
[email protected]6de74452009-02-25 18:04:59514 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29515}
516
[email protected]992db4c2011-05-12 15:37:15517void RenderWidget::SetSwappedOut(bool is_swapped_out) {
518 // We should only toggle between states.
519 DCHECK(is_swapped_out_ != is_swapped_out);
520 is_swapped_out_ = is_swapped_out;
521
522 // If we are swapping out, we will call ReleaseProcess, allowing the process
523 // to exit if all of its RenderViews are swapped out. We wait until the
524 // WasSwappedOut call to do this, to avoid showing the sad tab.
525 // If we are swapping in, we call AddRefProcess to prevent the process from
526 // exiting.
527 if (!is_swapped_out)
528 RenderProcess::current()->AddRefProcess();
529}
530
[email protected]34bb3ac2013-03-08 02:41:28531bool RenderWidget::AllowPartialSwap() const {
532 return true;
533}
534
[email protected]c8cbae72013-05-23 10:45:03535bool RenderWidget::UsingSynchronousRendererCompositor() const {
[email protected]ccc1722e2013-05-06 19:43:07536#if defined(OS_ANDROID)
[email protected]913d99a2013-05-31 07:16:07537 return SynchronousCompositorFactory::GetInstance() != NULL;
538#else
[email protected]ccc1722e2013-05-06 19:43:07539 return false;
[email protected]913d99a2013-05-31 07:16:07540#endif
[email protected]ccc1722e2013-05-06 19:43:07541}
542
[email protected]b2e4c70132013-10-03 02:07:51543void RenderWidget::EnableScreenMetricsEmulation(
544 const gfx::Size& device_size,
545 const gfx::Rect& widget_rect,
546 float device_scale_factor,
547 bool fit_to_view) {
548 if (!screen_metrics_emulator_) {
549 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this,
550 device_size, widget_rect, device_scale_factor, fit_to_view));
551 } else {
552 screen_metrics_emulator_->ChangeEmulationParams(device_size,
553 widget_rect, device_scale_factor, fit_to_view);
554 }
555}
556
557void RenderWidget::DisableScreenMetricsEmulation() {
558 screen_metrics_emulator_.reset();
559}
560
561void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
562 ScreenMetricsEmulator* emulator) {
563 popup_origin_scale_for_emulation_ = emulator->scale();
564 popup_view_origin_for_emulation_ = emulator->widget_rect().origin();
565 popup_screen_origin_for_emulation_ =
566 emulator->original_screen_rect().origin();
567}
568
569void RenderWidget::SetScreenMetricsEmulationParameters(
570 float device_scale_factor, float root_layer_scale) {
571 // This is only supported in RenderView.
572 NOTREACHED();
573}
574
575void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
576 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
577 popup->SetOriginScaleForEmulation(emulator->scale());
578}
579
580void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
581 if (screen_metrics_emulator_)
582 screen_metrics_emulator_->OnShowContextMenu(params);
583}
584
[email protected]7d08a9352013-10-15 08:24:56585void RenderWidget::ScheduleCompositeWithForcedRedraw() {
586 if (compositor_) {
587 // Regardless of whether threaded compositing is enabled, always
588 // use this mechanism to force the compositor to redraw. However,
589 // the invalidation code path below is still needed for the
590 // non-threaded case.
591 compositor_->SetNeedsForcedRedraw();
592 }
593 ScheduleCompositeImpl(true);
594}
595
596void RenderWidget::ScheduleCompositeImpl(bool force_redraw) {
597 if (RenderThreadImpl::current()->compositor_message_loop_proxy().get() &&
598 compositor_) {
599 if (!force_redraw) {
600 compositor_->setNeedsRedraw();
601 }
602 } else {
603 // TODO(nduca): replace with something a little less hacky. The reason this
604 // hack is still used is because the Invalidate-DoDeferredUpdate loop
605 // contains a lot of host-renderer synchronization logic that is still
606 // important for the accelerated compositing case. The option of simply
607 // duplicating all that code is less desirable than "faking out" the
608 // invalidation path using a magical damage rect.
609 didInvalidateRect(WebRect(0, 0, 1, 1));
610 }
611}
612
[email protected]a95986a82010-12-24 06:19:28613bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
614 bool handled = true;
615 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15616 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22617 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
618 OnCursorVisibilityChange)
[email protected]c084330e02013-04-27 01:08:15619 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
620 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]a95986a82010-12-24 06:19:28621 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
622 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
623 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54624 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28625 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41626 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]992db4c2011-05-12 15:37:15627 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28628 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]ed7defa2013-03-12 21:29:59629 IPC_MESSAGE_HANDLER(ViewMsg_SwapBuffers_ACK,
630 OnViewContextSwapBuffersComplete)
[email protected]a95986a82010-12-24 06:19:28631 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
632 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
633 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]3d9ec5052013-01-02 22:05:25634 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnPaintAtSize)
635 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]79fa22e2013-08-23 15:18:12636 IPC_MESSAGE_HANDLER(ViewMsg_SyntheticGestureCompleted,
637 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28638 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
639 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03640 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]105dffb42013-02-20 03:46:21641#if defined(OS_ANDROID)
[email protected]2384b6c2013-02-28 23:58:51642 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]0d1ebed12013-08-05 22:01:13643 IPC_MESSAGE_HANDLER(ViewMsg_ImeEventAck, OnImeEventAck)
[email protected]105dffb42013-02-20 03:46:21644#endif
[email protected]51a49502013-03-23 01:50:19645 IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot)
[email protected]3639aa82013-06-04 11:00:04646 IPC_MESSAGE_HANDLER(ViewMsg_SetBrowserRenderingStats,
647 OnSetBrowserRenderingStats)
[email protected]a95986a82010-12-24 06:19:28648 IPC_MESSAGE_UNHANDLED(handled = false)
649 IPC_END_MESSAGE_MAP()
650 return handled;
651}
initial.commit09911bf2008-07-26 23:55:29652
653bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15654 // Don't send any messages after the browser has told us to close, and filter
655 // most outgoing messages while swapped out.
656 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26657 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11658 closing_) {
initial.commit09911bf2008-07-26 23:55:29659 delete message;
660 return false;
661 }
662
663 // If given a messsage without a routing ID, then assign our routing ID.
664 if (message->routing_id() == MSG_ROUTING_NONE)
665 message->set_routing_id(routing_id_);
666
[email protected]380244092011-10-07 17:26:27667 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44668}
669
[email protected]61e2b3cc2012-03-02 16:13:34670void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44671 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40672 float overdraw_bottom_height,
[email protected]61e2b3cc2012-03-02 16:13:34673 const gfx::Rect& resizer_rect,
674 bool is_fullscreen,
675 ResizeAck resize_ack) {
[email protected]1c0008842013-06-06 08:35:48676 if (!RenderThreadImpl::current() || // Will be NULL during unit tests.
677 !RenderThreadImpl::current()->layout_test_mode()) {
678 // A resize ack shouldn't be requested if we have not ACK'd the previous
679 // one.
680 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
681 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
682 }
initial.commit09911bf2008-07-26 23:55:29683
[email protected]61e2b3cc2012-03-02 16:13:34684 // Ignore this during shutdown.
685 if (!webwidget_)
686 return;
687
[email protected]d9083762013-03-24 01:36:40688 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44689 compositor_->setViewportSize(new_size, physical_backing_size);
[email protected]d9083762013-03-24 01:36:40690 compositor_->SetOverdrawBottomHeight(overdraw_bottom_height);
691 }
[email protected]60d47ac2013-03-01 23:42:44692
[email protected]dade8992013-03-04 07:34:34693 physical_backing_size_ = physical_backing_size;
[email protected]d9083762013-03-24 01:36:40694 overdraw_bottom_height_ = overdraw_bottom_height;
[email protected]61e2b3cc2012-03-02 16:13:34695 resizer_rect_ = resizer_rect;
696
697 // NOTE: We may have entered fullscreen mode without changing our size.
698 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
699 if (fullscreen_change)
700 WillToggleFullscreen();
701 is_fullscreen_ = is_fullscreen;
702
703 if (size_ != new_size) {
704 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34705 needs_repainting_on_restore_ = false;
706
707 size_ = new_size;
708
709 paint_aggregator_.ClearPendingUpdate();
710
711 // When resizing, we want to wait to paint before ACK'ing the resize. This
712 // ensures that we only resize as fast as we can paint. We only need to
713 // send an ACK if we are resized to a non-empty rect.
714 webwidget_->resize(new_size);
[email protected]0b70dbe2013-05-10 19:06:32715
[email protected]92201e32013-06-08 06:14:52716 if (!RenderThreadImpl::current() || // Will be NULL during unit tests.
717 !RenderThreadImpl::current()->layout_test_mode()) {
718 // Resize should have caused an invalidation of the entire view.
719 DCHECK(new_size.IsEmpty() || is_accelerated_compositing_active_ ||
720 paint_aggregator_.HasPendingUpdate());
721 }
[email protected]1c0008842013-06-06 08:35:48722 } else if (!RenderThreadImpl::current() || // Will be NULL during unit tests.
723 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]632c4382013-05-15 08:58:45724 resize_ack = NO_RESIZE_ACK;
725 }
726
727 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
728 // For empty size or empty physical_backing_size, there is no next paint
729 // (along with which to send the ack) until they are set to non-empty.
[email protected]ff475a322012-03-14 00:05:35730 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34731 }
732
[email protected]20fbfc22013-05-08 20:50:58733 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45734 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58735 set_next_paint_is_resize_ack();
736
[email protected]61e2b3cc2012-03-02 16:13:34737 if (fullscreen_change)
738 DidToggleFullscreen();
739
740 // If a resize ack is requested and it isn't set-up, then no more resizes will
741 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45742 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29743}
744
745void RenderWidget::OnClose() {
746 if (closing_)
747 return;
748 closing_ = true;
749
750 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03751 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27752 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03753 SetHidden(false);
754 }
initial.commit09911bf2008-07-26 23:55:29755
initial.commit09911bf2008-07-26 23:55:29756 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25757 // now. Post a task that only gets invoked when there are no nested message
758 // loops.
[email protected]dd32b1272013-05-04 14:17:11759 base::MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29760 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25761
762 // Balances the AddRef taken when we called AddRoute.
763 Release();
initial.commit09911bf2008-07-26 23:55:29764}
765
[email protected]61e2b3cc2012-03-02 16:13:34766// Got a response from the browser after the renderer decided to create a new
767// view.
[email protected]fc4404d2012-11-07 19:53:30768void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34769 DCHECK(routing_id_ != MSG_ROUTING_NONE);
770
[email protected]fc4404d2012-11-07 19:53:30771 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34772}
773
[email protected]0fdd5012013-05-29 08:05:56774void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]b2e4c70132013-10-03 02:07:51775 if (screen_metrics_emulator_) {
776 screen_metrics_emulator_->OnResizeMessage(params);
777 return;
778 }
779
[email protected]0fdd5012013-05-29 08:05:56780 screen_info_ = params.screen_info;
781 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
782 Resize(params.new_size, params.physical_backing_size,
783 params.overdraw_bottom_height, params.resizer_rect,
784 params.is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29785}
786
[email protected]b5913d72012-02-07 22:26:54787void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
788 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59789 gfx::Rect view_rect(size_);
790
[email protected]ce112fe2012-10-29 22:52:18791 gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_);
[email protected]b9769d82012-02-10 00:23:59792 if (!old_damage_rect.IsEmpty())
793 paint_aggregator_.InvalidateRect(old_damage_rect);
794
[email protected]ce112fe2012-10-29 22:52:18795 gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect);
[email protected]b9769d82012-02-10 00:23:59796 if (!new_damage_rect.IsEmpty())
797 paint_aggregator_.InvalidateRect(new_damage_rect);
798
[email protected]b5913d72012-02-07 22:26:54799 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59800
[email protected]b5913d72012-02-07 22:26:54801 if (webwidget_)
802 webwidget_->didChangeWindowResizerRect();
803 }
804}
805
initial.commit09911bf2008-07-26 23:55:29806void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31807 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29808 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03809 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29810}
811
[email protected]9e2e4632012-07-27 16:38:41812void RenderWidget::OnWasShown(bool needs_repainting) {
813 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29814 // During shutdown we can just ignore this message.
815 if (!webwidget_)
816 return;
817
818 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03819 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29820
821 if (!needs_repainting && !needs_repainting_on_restore_)
822 return;
823 needs_repainting_on_restore_ = false;
824
[email protected]d65adb12010-04-28 17:26:49825 // Tag the next paint as a restore ack, which is picked up by
826 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29827 set_next_paint_is_restore_ack();
828
829 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56830 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46831 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
832 } else {
833 scheduleComposite();
834 }
initial.commit09911bf2008-07-26 23:55:29835}
836
[email protected]992db4c2011-05-12 15:37:15837void RenderWidget::OnWasSwappedOut() {
838 // If we have been swapped out and no one else is using this process,
839 // it's safe to exit now. If we get swapped back in, we will call
840 // AddRefProcess in SetSwappedOut.
841 if (is_swapped_out_)
842 RenderProcess::current()->ReleaseProcess();
843}
844
[email protected]53d3f302009-12-21 04:42:05845void RenderWidget::OnRequestMoveAck() {
846 DCHECK(pending_window_rect_count_);
847 pending_window_rect_count_--;
848}
849
850void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58851 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21852 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05853 update_reply_pending_ = false;
854
[email protected]b4d08452010-10-05 17:34:35855 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
856 // have no current paint buffer.
857 if (current_paint_buf_) {
858 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
859 current_paint_buf_ = NULL;
860 }
861
[email protected]65225772011-05-12 21:10:24862 // If swapbuffers is still pending, then defer the update until the
863 // swapbuffers occurs.
864 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
865 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
866 return;
867 }
868
[email protected]29ed96a2012-02-04 18:12:16869 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18870 if (!is_accelerated_compositing_active_) {
871 DidFlushPaint();
872 }
[email protected]a2f6bc112009-06-27 16:27:25873
initial.commit09911bf2008-07-26 23:55:29874 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24875 DoDeferredUpdateAndSendInputAck();
876}
877
[email protected]d0be63772011-12-20 23:18:04878bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]ed7defa2013-03-12 21:29:59879 // Contexts using the command buffer support asynchronous swapbuffers.
880 // See RenderWidget::CreateOutputSurface().
[email protected]cadac622013-06-11 16:46:36881 if (RenderThreadImpl::current()->compositor_message_loop_proxy().get())
[email protected]ed7defa2013-03-12 21:29:59882 return false;
883
884 return true;
885}
886
887GURL RenderWidget::GetURLForGraphicsContext3D() {
888 return GURL();
[email protected]65225772011-05-12 21:10:24889}
890
[email protected]479b0172012-10-29 19:27:09891bool RenderWidget::ForceCompositingModeEnabled() {
892 return false;
893}
894
[email protected]ebc0e1df2013-08-01 02:46:22895scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]a1811b8912013-05-09 15:35:19896
897#if defined(OS_ANDROID)
[email protected]b6eb8e332013-09-10 00:51:01898 if (SynchronousCompositorFactory* factory =
899 SynchronousCompositorFactory::GetInstance()) {
[email protected]913d99a2013-05-31 07:16:07900 return factory->CreateOutputSurface(routing_id());
[email protected]a1811b8912013-05-09 15:35:19901 }
902#endif
903
[email protected]ed7defa2013-03-12 21:29:59904 // Explicitly disable antialiasing for the compositor. As of the time of
905 // this writing, the only platform that supported antialiasing for the
906 // compositor was Mac OS X, because the on-screen OpenGL context creation
907 // code paths on Windows and Linux didn't yet have multisampling support.
908 // Mac OS X essentially always behaves as though it's rendering offscreen.
909 // Multisampling has a heavy cost especially on devices with relatively low
910 // fill rate like most notebooks, and the Mac implementation would need to
911 // be optimized to resolve directly into the IOSurface shared between the
912 // GPU and browser processes. For these reasons and to avoid platform
913 // disparities we explicitly disable antialiasing.
914 WebKit::WebGraphicsContext3D::Attributes attributes;
915 attributes.antialias = false;
916 attributes.shareResources = true;
917 attributes.noAutomaticFlushes = true;
[email protected]a6886502013-05-16 20:59:18918 attributes.depth = false;
919 attributes.stencil = false;
[email protected]b6eb8e332013-09-10 00:51:01920
921 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]bec084292013-05-21 21:31:44922 if (command_line.HasSwitch(cc::switches::kForceDirectLayerDrawing))
923 attributes.stencil = true;
[email protected]b6eb8e332013-09-10 00:51:01924
[email protected]0634cdd42013-08-16 00:46:09925 scoped_refptr<ContextProviderCommandBuffer> context_provider;
926 if (!fallback) {
927 context_provider = ContextProviderCommandBuffer::Create(
[email protected]af13d832013-09-13 06:56:27928 CreateGraphicsContext3D(attributes),
929 "RenderCompositor");
[email protected]0634cdd42013-08-16 00:46:09930 }
[email protected]ebc0e1df2013-08-01 02:46:22931
[email protected]b6eb8e332013-09-10 00:51:01932 uint32 output_surface_id = next_output_surface_id_++;
[email protected]0634cdd42013-08-16 00:46:09933 if (!context_provider.get()) {
[email protected]ebc0e1df2013-08-01 02:46:22934 if (!command_line.HasSwitch(switches::kEnableSoftwareCompositing))
935 return scoped_ptr<cc::OutputSurface>();
[email protected]0634cdd42013-08-16 00:46:09936
937 scoped_ptr<cc::SoftwareOutputDevice> software_device(
938 new CompositorSoftwareOutputDevice());
939
940 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface(
941 routing_id(),
942 output_surface_id,
943 NULL,
944 software_device.Pass(),
945 true));
[email protected]ebc0e1df2013-08-01 02:46:22946 }
[email protected]ed7defa2013-03-12 21:29:59947
[email protected]0c04d1c2013-07-10 00:02:32948 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer) &&
949 !command_line.HasSwitch(switches::kDisableDelegatedRenderer)) {
[email protected]36e5ff12013-06-11 12:19:29950 DCHECK(is_threaded_compositing_enabled_);
951 return scoped_ptr<cc::OutputSurface>(
[email protected]0634cdd42013-08-16 00:46:09952 new DelegatedCompositorOutputSurface(
953 routing_id(),
954 output_surface_id,
955 context_provider,
956 scoped_ptr<cc::SoftwareOutputDevice>()));
[email protected]36e5ff12013-06-11 12:19:29957 }
958 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) {
959 DCHECK(is_threaded_compositing_enabled_);
[email protected]186f09602013-09-24 07:13:16960 cc::ResourceFormat format = cc::RGBA_8888;
961#if defined(OS_ANDROID)
962 if (base::android::SysUtils::IsLowEndDevice())
963 format = cc::RGB_565;
964#endif
[email protected]36e5ff12013-06-11 12:19:29965 return scoped_ptr<cc::OutputSurface>(
[email protected]0634cdd42013-08-16 00:46:09966 new MailboxOutputSurface(
967 routing_id(),
968 output_surface_id,
969 context_provider,
[email protected]186f09602013-09-24 07:13:16970 scoped_ptr<cc::SoftwareOutputDevice>(),
971 format));
[email protected]36e5ff12013-06-11 12:19:29972 }
[email protected]0634cdd42013-08-16 00:46:09973 bool use_swap_compositor_frame_message = false;
[email protected]36e5ff12013-06-11 12:19:29974 return scoped_ptr<cc::OutputSurface>(
[email protected]0634cdd42013-08-16 00:46:09975 new CompositorOutputSurface(
976 routing_id(),
977 output_surface_id,
978 context_provider,
979 scoped_ptr<cc::SoftwareOutputDevice>(),
980 use_swap_compositor_frame_message));
[email protected]ba91a792013-02-06 09:48:28981}
982
[email protected]ed7defa2013-03-12 21:29:59983void RenderWidget::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24984 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21985 while (!updates_pending_swap_.empty()) {
986 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
987 updates_pending_swap_.pop_front();
988 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
989 // compositing pass, hence doesn't require an UpdateRect message.
990 if (msg)
991 Send(msg);
992 }
[email protected]65225772011-05-12 21:10:24993 num_swapbuffers_complete_pending_ = 0;
994 using_asynchronous_swapbuffers_ = false;
995 // Schedule another frame so the compositor learns about it.
996 scheduleComposite();
997}
998
[email protected]ed7defa2013-03-12 21:29:59999void RenderWidget::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:081000 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:211001
1002 if (using_asynchronous_swapbuffers_) {
1003 ViewHostMsg_UpdateRect* msg = NULL;
1004 // pending_update_params_ can be NULL if the swap doesn't correspond to an
1005 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
1006 // message.
[email protected]59383c782013-04-17 16:43:271007 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:211008 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
1009 pending_update_params_.reset();
1010 }
1011 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:081012 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:211013 }
[email protected]37a6f302011-07-11 23:43:081014}
1015
[email protected]ed7defa2013-03-12 21:29:591016void RenderWidget::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:241017 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:161018
[email protected]404939f2012-06-01 04:06:181019 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:161020 DidFlushPaint();
1021
[email protected]65225772011-05-12 21:10:241022 // When compositing deactivates, we reset the swapbuffers pending count. The
1023 // swapbuffers acks may still arrive, however.
1024 if (num_swapbuffers_complete_pending_ == 0) {
1025 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
1026 return;
1027 }
[email protected]aa4117f2011-12-09 22:19:211028 DCHECK(!updates_pending_swap_.empty());
1029 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
1030 updates_pending_swap_.pop_front();
1031 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
1032 // compositing pass, hence doesn't require an UpdateRect message.
1033 if (msg)
1034 Send(msg);
[email protected]65225772011-05-12 21:10:241035 num_swapbuffers_complete_pending_--;
1036
1037 // If update reply is still pending, then defer the update until that reply
1038 // occurs.
[email protected]d0be63772011-12-20 23:18:041039 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:241040 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
1041 return;
1042 }
1043
1044 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:061045 // when we were previously rendering. However, if an invalidation task is not
1046 // posted, there may be software rendering work pending. In that case, don't
1047 // early out.
1048 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:241049 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
1050 return;
1051 }
1052
[email protected]cc66e682012-10-02 06:48:181053 // Do not call DoDeferredUpdate unless there's animation work to be done or
1054 // a real invalidation. This prevents rendering in response to a swapbuffers
1055 // callback coming back after we've navigated away from the page that
1056 // generated it.
1057 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
1058 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
1059 return;
1060 }
1061
[email protected]65225772011-05-12 21:10:241062 // Continue painting if necessary...
1063 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:291064}
1065
[email protected]0dea1652012-12-14 00:09:091066void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
[email protected]4b157662013-05-29 04:05:051067 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:091068 bool is_keyboard_shortcut) {
[email protected]5dd768212009-08-13 23:34:491069 handling_input_event_ = true;
[email protected]0dea1652012-12-14 00:09:091070 if (!input_event) {
[email protected]5dd768212009-08-13 23:34:491071 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:291072 return;
[email protected]5dd768212009-08-13 23:34:491073 }
initial.commit09911bf2008-07-26 23:55:291074
[email protected]b4841e1c2013-05-16 22:30:101075 const char* const event_name = GetEventName(input_event->type);
1076 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent",
1077 "event", event_name);
1078
[email protected]c2eaa8f2013-05-10 02:41:551079 if (compositor_)
1080 compositor_->SetLatencyInfo(latency_info);
[email protected]256737c2013-06-08 04:39:101081 else
1082 latency_info_.MergeWith(latency_info);
[email protected]c2eaa8f2013-05-10 02:41:551083
[email protected]6a4d7f62013-01-07 21:32:131084 base::TimeDelta now = base::TimeDelta::FromInternalValue(
1085 base::TimeTicks::Now().ToInternalValue());
1086
1087 int64 delta = static_cast<int64>(
1088 (now.InSecondsF() - input_event->timeStampSeconds) *
1089 base::Time::kMicrosecondsPerSecond);
1090 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer", delta, 0, 1000000, 100);
[email protected]de415552013-01-23 04:12:171091 base::HistogramBase* counter_for_type =
[email protected]bafdc5d52013-02-27 18:18:481092 base::Histogram::FactoryGet(
[email protected]b4841e1c2013-05-16 22:30:101093 base::StringPrintf("Event.Latency.Renderer.%s", event_name),
[email protected]bafdc5d52013-02-27 18:18:481094 0,
1095 1000000,
[email protected]6a4d7f62013-01-07 21:32:131096 100,
[email protected]de415552013-01-23 04:12:171097 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]bafdc5d52013-02-27 18:18:481098 counter_for_type->Add(delta);
[email protected]6a4d7f62013-01-07 21:32:131099
[email protected]67bfb83f2011-09-22 03:36:371100 bool prevent_default = false;
1101 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:261102 const WebMouseEvent& mouse_event =
1103 *static_cast<const WebMouseEvent*>(input_event);
1104 TRACE_EVENT2("renderer", "HandleMouseMove",
1105 "x", mouse_event.x, "y", mouse_event.y);
1106 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:371107 }
1108
[email protected]f56c7872013-06-18 12:31:571109 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
1110 const WebKeyboardEvent& key_event =
1111 *static_cast<const WebKeyboardEvent*>(input_event);
1112 prevent_default = WillHandleKeyEvent(key_event);
1113 }
1114
[email protected]41d86852012-11-07 12:23:241115 if (WebInputEvent::isGestureEventType(input_event->type)) {
1116 const WebGestureEvent& gesture_event =
1117 *static_cast<const WebGestureEvent*>(input_event);
1118 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
1119 }
1120
[email protected]3ebcc7c2013-01-09 05:34:461121 if (input_event->type == WebInputEvent::GestureTap ||
1122 input_event->type == WebInputEvent::GestureLongPress)
1123 resetInputMethod();
1124
[email protected]67bfb83f2011-09-22 03:36:371125 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:121126 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
1127 suppress_next_char_events_ = false;
1128 if (!processed && webwidget_)
1129 processed = webwidget_->handleInputEvent(*input_event);
1130 }
1131
1132 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
1133 // it's not processed by webkit, then we need to suppress the upcoming Char
1134 // events.
1135 if (!processed && is_keyboard_shortcut)
1136 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:291137
[email protected]3d5c243b2012-11-30 00:26:011138 InputEventAckState ack_result = processed ?
1139 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1140 if (!processed && input_event->type == WebInputEvent::TouchStart) {
1141 const WebTouchEvent& touch_event =
1142 *static_cast<const WebTouchEvent*>(input_event);
1143 ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ?
1144 INPUT_EVENT_ACK_STATE_NOT_CONSUMED :
1145 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1146 }
1147
[email protected]a9fb30aa2011-10-06 06:58:461148 IPC::Message* response =
[email protected]f6df0edf2013-08-07 00:27:021149 new InputHostMsg_HandleInputEvent_ACK(routing_id_,
1150 input_event->type,
1151 ack_result,
1152 latency_info);
[email protected]3391a0772012-03-28 00:32:071153 bool event_type_gets_rate_limited =
1154 input_event->type == WebInputEvent::MouseMove ||
1155 input_event->type == WebInputEvent::MouseWheel ||
[email protected]3475bb52013-10-03 08:25:161156 input_event->type == WebInputEvent::TouchMove;
[email protected]8926c602013-01-23 05:32:061157
1158 bool frame_pending = paint_aggregator_.HasPendingUpdate();
1159 if (is_accelerated_compositing_active_) {
[email protected]ba91a792013-02-06 09:48:281160 frame_pending = compositor_ &&
1161 compositor_->commitRequested();
[email protected]8926c602013-01-23 05:32:061162 }
1163
[email protected]9a8ce7f92013-06-11 12:39:491164 if (event_type_gets_rate_limited && frame_pending && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:241165 // We want to rate limit the input events in this case, so we'll wait for
1166 // painting to finish before ACKing this message.
[email protected]59383c782013-04-17 16:43:271167 if (pending_input_event_ack_) {
[email protected]353a34c2010-05-28 23:35:171168 // As two different kinds of events could cause us to postpone an ack
1169 // we send it now, if we have one pending. The Browser should never
1170 // send us the same kind of event we are delaying the ack for.
1171 Send(pending_input_event_ack_.release());
1172 }
[email protected]12fbad812009-09-01 18:21:241173 pending_input_event_ack_.reset(response);
[email protected]df09e052013-07-31 18:59:501174 if (compositor_)
1175 compositor_->NotifyInputThrottledUntilCommit();
[email protected]12fbad812009-09-01 18:21:241176 } else {
1177 Send(response);
1178 }
1179
[email protected]3306f262012-09-21 19:20:421180#if defined(OS_ANDROID)
1181 // Allow the IME to be shown when the focus changes as a consequence
1182 // of a processed touch end event.
1183 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]0d1ebed12013-08-05 22:01:131184 UpdateTextInputState(true, true);
[email protected]3306f262012-09-21 19:20:421185#endif
1186
[email protected]5dd768212009-08-13 23:34:491187 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:481188
[email protected]67bfb83f2011-09-22 03:36:371189 if (!prevent_default) {
1190 if (WebInputEvent::isKeyboardEventType(input_event->type))
1191 DidHandleKeyEvent();
1192 if (WebInputEvent::isMouseEventType(input_event->type))
1193 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:241194 if (WebInputEvent::isTouchEventType(input_event->type))
1195 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:371196 }
initial.commit09911bf2008-07-26 23:55:291197}
1198
[email protected]34202de2013-05-06 23:36:221199void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1200 if (webwidget_)
1201 webwidget_->setCursorVisibilityState(is_visible);
1202}
1203
initial.commit09911bf2008-07-26 23:55:291204void RenderWidget::OnMouseCaptureLost() {
1205 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281206 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291207}
1208
1209void RenderWidget::OnSetFocus(bool enable) {
1210 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:331211 if (webwidget_)
1212 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291213}
1214
1215void RenderWidget::ClearFocus() {
1216 // We may have got the focus from the browser before this gets processed, in
1217 // which case we do not want to unfocus ourself.
1218 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:281219 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:291220}
1221
[email protected]2d5d09d52009-06-15 14:29:211222void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:001223 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:211224 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:061225 TRACE_EVENT2("renderer", "PaintRect",
1226 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:451227
[email protected]4fb66842009-12-04 21:41:001228 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:211229
1230 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:001231 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
1232 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:031233
[email protected]699ab0d2009-04-23 23:19:141234 // If there is a custom background, tile it.
1235 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:141236 SkPaint paint;
[email protected]4e29afd2012-12-04 04:07:111237 skia::RefPtr<SkShader> shader = skia::AdoptRef(
1238 SkShader::CreateBitmapShader(background_,
1239 SkShader::kRepeat_TileMode,
1240 SkShader::kRepeat_TileMode));
1241 paint.setShader(shader.get());
[email protected]fb10ec5b2011-10-24 17:54:201242
1243 // Use kSrc_Mode to handle background_ transparency properly.
1244 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
1245
1246 // Canvas could contain multiple update rects. Clip to given rect so that
1247 // we don't accidentally clear other update rects.
1248 canvas->save();
[email protected]aa7e7a12013-02-22 13:37:441249 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]1835b9e2012-02-28 13:12:481250 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:141251 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:201252 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:141253 }
1254
[email protected]719b36f2010-12-22 20:36:461255 // First see if this rect is a plugin that can paint itself faster.
1256 TransportDIB* optimized_dib = NULL;
1257 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201258 float dib_scale_factor;
[email protected]adab2332013-07-25 18:04:321259 PepperPluginInstanceImpl* optimized_instance =
[email protected]719b36f2010-12-22 20:36:461260 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
1261 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201262 &optimized_copy_rect,
1263 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:461264 if (optimized_instance) {
[email protected]20790a222013-07-25 02:23:051265#if defined(ENABLE_PLUGINS)
[email protected]719b36f2010-12-22 20:36:461266 // This plugin can be optimize-painted and we can just ask it to paint
1267 // itself. We don't actually need the TransportDIB in this case.
1268 //
1269 // This is an optimization for PPAPI plugins that know they're on top of
1270 // the page content. If this rect is inside such a plugin, we can save some
1271 // time and avoid re-rendering the page content which we know will be
1272 // covered by the plugin later (this time can be significant, especially
1273 // for a playing movie that is invalidating a lot).
1274 //
1275 // In the plugin movie case, hopefully the similar call to
1276 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
1277 // painting, because that avoids copying the plugin image to a different
1278 // paint rect. Unfortunately, if anything on the page is animating other
1279 // than the movie, it break this optimization since the union of the
1280 // invalid regions will be larger than the plugin.
1281 //
1282 // This code optimizes that case, where we can still avoid painting in
1283 // WebKit and filling the background (which can be slow) and just painting
1284 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
1285 // required.
[email protected]df59dd42012-09-14 22:56:301286 SkAutoCanvasRestore auto_restore(canvas, true);
1287 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]6bd867b2013-07-24 22:10:201288 optimized_instance->Paint(canvas, optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:211289 canvas->restore();
[email protected]20790a222013-07-25 02:23:051290#endif
[email protected]719b36f2010-12-22 20:36:461291 } else {
1292 // Normal painting case.
[email protected]c1e6cc062013-08-24 03:35:351293 base::TimeTicks start_time;
1294 if (!is_accelerated_compositing_active_)
1295 start_time = legacy_software_mode_stats_->StartRecording();
[email protected]63ab54262012-11-09 15:58:451296
[email protected]6bd867b2013-07-24 22:10:201297 webwidget_->paint(canvas, rect);
[email protected]63ab54262012-11-09 15:58:451298
[email protected]c1e6cc062013-08-24 03:35:351299 if (!is_accelerated_compositing_active_) {
[email protected]63ab54262012-11-09 15:58:451300 base::TimeDelta paint_time =
[email protected]c1e6cc062013-08-24 03:35:351301 legacy_software_mode_stats_->EndRecording(start_time);
1302 int64 painted_pixel_count = rect.width() * rect.height();
1303 legacy_software_mode_stats_->AddPaint(paint_time, painted_pixel_count);
[email protected]63ab54262012-11-09 15:58:451304 }
[email protected]719b36f2010-12-22 20:36:461305
1306 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:351307 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:461308 }
initial.commit09911bf2008-07-26 23:55:291309
[email protected]4fb66842009-12-04 21:41:001310 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:001311 canvas->restore();
1312}
1313
1314void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
1315 skia::PlatformCanvas* canvas) {
1316 static bool kPaintBorder =
1317 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
1318 if (!kPaintBorder)
1319 return;
1320
[email protected]53d3f302009-12-21 04:42:051321 // Cycle through these colors to help distinguish new paint rects.
1322 const SkColor colors[] = {
1323 SkColorSetARGB(0x3F, 0xFF, 0, 0),
1324 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
1325 SkColorSetARGB(0x3F, 0, 0, 0xFF),
1326 };
1327 static int color_selector = 0;
1328
[email protected]4fb66842009-12-04 21:41:001329 SkPaint paint;
1330 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:051331 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:001332 paint.setStrokeWidth(1);
1333
1334 SkIRect irect;
1335 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
1336 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:291337}
1338
[email protected]52ccd0ea2011-02-16 01:09:051339void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:301340 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:301341 if (!animation_update_pending_) {
1342 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:591343 return;
[email protected]921244e42011-07-20 16:36:301344 }
[email protected]bd37ae252011-06-03 01:28:181345 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:591346 // Record when we fired (according to base::Time::Now()) relative to when
1347 // we posted the task to quantify how much the base::Time/base::TimeTicks
1348 // skew is affecting animations.
1349 base::TimeDelta animation_callback_delay = base::Time::Now() -
1350 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
1351 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
1352 animation_callback_delay,
1353 base::TimeDelta::FromMilliseconds(0),
1354 base::TimeDelta::FromMilliseconds(30),
1355 25);
1356 }
[email protected]65225772011-05-12 21:10:241357 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:241358}
1359
[email protected]52ccd0ea2011-02-16 01:09:051360void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:591361 if (!animation_update_pending_)
1362 return;
[email protected]bd37ae252011-06-03 01:28:181363
1364 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:331365 base::TimeDelta animationInterval = IsRenderingVSynced() ?
1366 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:181367
[email protected]7c4329e2011-02-18 22:02:591368 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:451369
1370 // animation_floor_time_ is the earliest time that we should animate when
1371 // using the dead reckoning software scheduler. If we're using swapbuffers
1372 // complete callbacks to rate limit, we can ignore this floor.
1373 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:301374 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:331375 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:181376 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:591377 // running animation callbacks so that if a callback requests another
1378 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:381379 animation_timer_.Stop();
1380 animation_timer_.Start(FROM_HERE, animationInterval, this,
1381 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:591382 animation_update_pending_ = false;
[email protected]ba91a792013-02-06 09:48:281383 if (is_accelerated_compositing_active_ && compositor_) {
[email protected]635353c2013-03-06 09:11:201384 compositor_->Animate(base::TimeTicks::Now());
[email protected]8926c602013-01-23 05:32:061385 } else {
[email protected]635353c2013-03-06 09:11:201386 double frame_begin_time =
1387 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
1388 webwidget_->animate(frame_begin_time);
[email protected]8926c602013-01-23 05:32:061389 }
[email protected]7c4329e2011-02-18 22:02:591390 return;
[email protected]5f8b1022011-01-21 23:34:501391 }
[email protected]bd37ae252011-06-03 01:28:181392 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:381393 if (!animation_timer_.IsRunning()) {
1394 // This code uses base::Time::Now() to calculate the floor and next fire
1395 // time because javascript's Date object uses base::Time::Now(). The
1396 // message loop uses base::TimeTicks, which on windows can have a
1397 // different granularity than base::Time.
1398 // The upshot of all this is that this function might be called before
1399 // base::Time::Now() has advanced past the animation_floor_time_. To
1400 // avoid exposing this delay to javascript, we keep posting delayed
1401 // tasks until base::Time::Now() has advanced far enough.
1402 base::TimeDelta delay = animation_floor_time_ - now;
1403 animation_timer_.Start(FROM_HERE, delay, this,
1404 &RenderWidget::AnimationCallback);
1405 }
[email protected]5f8b1022011-01-21 23:34:501406}
1407
[email protected]bd37ae252011-06-03 01:28:181408bool RenderWidget::IsRenderingVSynced() {
1409 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
1410 // not caught by this check. This will lead to artificially low frame rates
1411 // for people who force vsync off at a driver level and expect Chrome to speed
1412 // up.
1413 return !has_disable_gpu_vsync_switch_;
1414}
1415
[email protected]65225772011-05-12 21:10:241416void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:061417 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:241418 invalidation_task_posted_ = false;
1419 DoDeferredUpdateAndSendInputAck();
1420}
1421
1422void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:051423 DoDeferredUpdate();
1424
[email protected]59383c782013-04-17 16:43:271425 if (pending_input_event_ack_)
[email protected]52ccd0ea2011-02-16 01:09:051426 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:211427}
1428
[email protected]552e6002009-11-19 05:24:571429void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:581430 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]fc8bde1a2013-07-04 08:54:071431 TRACE_EVENT_SCOPED_SAMPLING_STATE("Chrome", "Paint");
[email protected]71e2f0a2011-03-15 22:25:081432
[email protected]65225772011-05-12 21:10:241433 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:291434 return;
[email protected]05a980d7a2012-02-07 22:16:421435
[email protected]fc4404d2012-11-07 19:53:301436 if (!init_complete_) {
1437 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:421438 return;
1439 }
[email protected]aa4117f2011-12-09 22:19:211440 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:241441 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
1442 return;
1443 }
[email protected]9ca84622011-06-02 23:46:391444 if (is_accelerated_compositing_active_ &&
1445 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:241446 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
1447 return;
1448 }
initial.commit09911bf2008-07-26 23:55:291449
[email protected]552e6002009-11-19 05:24:571450 // Suppress updating when we are hidden.
[email protected]e3d92a7f2013-01-10 02:35:051451 if (is_hidden_ || size_.IsEmpty() || is_swapped_out_) {
[email protected]552e6002009-11-19 05:24:571452 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:291453 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:241454 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:291455 return;
1456 }
1457
[email protected]0fb93f52011-05-18 23:13:561458 // Tracking of frame rate jitter
1459 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]38ce4e7b2013-02-23 06:17:371460 InstrumentWillBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:051461 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:501462
[email protected]f98d7e3c2010-09-13 22:30:461463 // Layout may generate more invalidation. It may also enable the
1464 // GPU acceleration, so make sure to run layout before we send the
1465 // GpuRenderingActivated message.
1466 webwidget_->layout();
1467
[email protected]793b2d62013-06-11 00:43:251468 // Check for whether we need to track swap buffers. We need to do that after
1469 // layout() because it may have switched us to accelerated compositing.
1470 if (is_accelerated_compositing_active_)
1471 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
1472
[email protected]dcca3aa92012-02-17 23:03:371473 // The following two can result in further layout and possibly
1474 // enable GPU acceleration so they need to be called before any painting
1475 // is done.
[email protected]cb9e2632013-06-18 11:26:471476 UpdateTextInputType();
[email protected]dcca3aa92012-02-17 23:03:371477 UpdateSelectionBounds();
1478
[email protected]5f8b1022011-01-21 23:34:501479 // Suppress painting if nothing is dirty. This has to be done after updating
1480 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:241481 if (!paint_aggregator_.HasPendingUpdate()) {
1482 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]38ce4e7b2013-02-23 06:17:371483 InstrumentDidCancelFrame();
[email protected]5f8b1022011-01-21 23:34:501484 return;
[email protected]65225772011-05-12 21:10:241485 }
[email protected]5f8b1022011-01-21 23:34:501486
[email protected]479b0172012-10-29 19:27:091487 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:361488 !is_threaded_compositing_enabled_ &&
[email protected]d8a6c5d12013-09-23 04:37:101489 (ForceCompositingModeEnabled() ||
1490 was_accelerated_compositing_ever_active_)) {
[email protected]479b0172012-10-29 19:27:091491 webwidget_->enterForceCompositingMode(true);
1492 }
1493
[email protected]872ae5b2011-05-26 20:20:501494 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:561495 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:041496 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:561497 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
1498 delay,
1499 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411500 base::TimeDelta::FromMilliseconds(120),
1501 60);
[email protected]d0be63772011-12-20 23:18:041502 } else {
[email protected]0fb93f52011-05-18 23:13:561503 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
1504 delay,
1505 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411506 base::TimeDelta::FromMilliseconds(120),
1507 60);
[email protected]d0be63772011-12-20 23:18:041508 }
[email protected]872ae5b2011-05-26 20:20:501509
1510 // Calculate filtered time per frame:
1511 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
1512 filtered_time_per_frame_ =
1513 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:561514 }
1515 last_do_deferred_update_time_ = frame_begin_ticks;
1516
[email protected]fef5e3972012-08-07 03:59:471517 if (!is_accelerated_compositing_active_) {
[email protected]922c6e1f2013-10-09 04:04:091518 legacy_software_mode_stats_->IncrementFrameCount(1, true);
[email protected]adbe30f2013-10-11 21:12:331519 cc::BenchmarkInstrumentation::IssueMainThreadRenderingStatsEvent(
1520 legacy_software_mode_stats_->main_thread_rendering_stats());
[email protected]c1e6cc062013-08-24 03:35:351521 legacy_software_mode_stats_->AccumulateAndClearMainThreadStats();
[email protected]fef5e3972012-08-07 03:59:471522 }
1523
[email protected]552e6002009-11-19 05:24:571524 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:291525 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:301526 PaintAggregator::PendingUpdate update;
1527 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:291528
[email protected]53d3f302009-12-21 04:42:051529 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:181530 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:291531
[email protected]ca4847f2010-09-24 05:39:151532 // A plugin may be able to do an optimized paint. First check this, in which
1533 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:461534 // This optimization allows PPAPI plugins that declare themselves on top of
1535 // the page (like a traditional windowed plugin) to be able to animate (think
1536 // movie playing) without repeatedly re-painting the page underneath, or
1537 // copying the plugin backing store (since we can send the plugin's backing
1538 // store directly to the browser).
1539 //
1540 // This optimization only works when the entire invalid region is contained
1541 // within the plugin. There is a related optimization in PaintRect for the
1542 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:151543 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:151544 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201545 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:211546 DCHECK(!pending_update_params_.get());
1547 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551548 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211549 pending_update_params_->scroll_rect = update.scroll_rect;
1550 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211551 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1552 pending_update_params_->flags = next_paint_flags_;
1553 pending_update_params_->scroll_offset = GetScrollOffset();
1554 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091555 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211556 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091557 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211558
[email protected]256737c2013-06-08 04:39:101559 if (!is_accelerated_compositing_active_)
1560 pending_update_params_->latency_info = latency_info_;
1561
1562 latency_info_.Clear();
1563
[email protected]ca4847f2010-09-24 05:39:151564 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561565 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151566 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201567 &optimized_copy_rect,
1568 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271569 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471570 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211571 pending_update_params_->bitmap = dib->id();
1572 pending_update_params_->bitmap_rect = optimized_copy_location;
1573 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201574 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561575 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461576 // Compute a buffer for painting and cache it.
[email protected]4889bd212013-02-11 22:23:101577
1578 bool fractional_scale = device_scale_factor_ -
1579 static_cast<int>(device_scale_factor_) != 0;
1580 if (fractional_scale) {
1581 // Damage might not be DIP aligned. Inflate damage to compensate.
1582 bounds.Inset(-1, -1);
1583 bounds.Intersect(gfx::Rect(size_));
1584 }
1585
1586 gfx::Rect pixel_bounds = gfx::ToEnclosingRect(
[email protected]ce112fe2012-10-29 22:52:181587 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]4889bd212013-02-11 22:23:101588
[email protected]ca4847f2010-09-24 05:39:151589 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351590 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591591 pixel_bounds));
[email protected]59383c782013-04-17 16:43:271592 if (!canvas) {
[email protected]f98d7e3c2010-09-13 22:30:461593 NOTREACHED();
1594 return;
1595 }
[email protected]cef3362f2009-12-21 17:48:451596
[email protected]f98d7e3c2010-09-13 22:30:461597 // We may get back a smaller canvas than we asked for.
1598 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591599 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1600 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1601 pixel_bounds.set_width(canvas->getDevice()->width());
1602 pixel_bounds.set_height(canvas->getDevice()->height());
1603 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1604 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051605
[email protected]f98d7e3c2010-09-13 22:30:461606 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1607
[email protected]aa4117f2011-12-09 22:19:211608 pending_update_params_->bitmap = current_paint_buf_->id();
1609 pending_update_params_->bitmap_rect = bounds;
1610
1611 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461612 // The scroll damage is just another rectangle to paint and copy.
1613 copy_rects.swap(update.paint_rects);
1614 if (!scroll_damage.IsEmpty())
1615 copy_rects.push_back(scroll_damage);
1616
[email protected]4889bd212013-02-11 22:23:101617 for (size_t i = 0; i < copy_rects.size(); ++i) {
1618 gfx::Rect rect = copy_rects[i];
1619 if (fractional_scale) {
1620 // Damage might not be DPI aligned. Inflate rect to compensate.
1621 rect.Inset(-1, -1);
1622 }
1623 PaintRect(rect, pixel_bounds.origin(), canvas.get());
1624 }
[email protected]60a50072012-01-11 02:05:351625
1626 // Software FPS tick for performance tests. The accelerated path traces the
1627 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1628 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421629 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW",
1630 TRACE_EVENT_SCOPE_THREAD);
[email protected]f98d7e3c2010-09-13 22:30:461631 } else { // Accelerated compositing path
1632 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211633 // If painting is done via the gpu process then we don't set any damage
1634 // rects to save the browser process from doing unecessary work.
1635 pending_update_params_->bitmap_rect = bounds;
1636 pending_update_params_->scroll_rect = gfx::Rect();
1637 // We don't need an ack, because we're not sharing a DIB with the browser.
1638 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1639 // with the browser for the GPU surface.
1640 pending_update_params_->needs_ack = false;
[email protected]f0c2a242013-03-15 19:34:521641 Composite(frame_begin_ticks);
[email protected]f98d7e3c2010-09-13 22:30:461642 }
1643
[email protected]936c6f52011-12-13 01:35:261644 // If we're holding a pending input event ACK, send the ACK before sending the
1645 // UpdateReply message so we can receive another input event before the
1646 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1647 // the UpdateRect IPC message handler.
[email protected]59383c782013-04-17 16:43:271648 if (pending_input_event_ack_)
[email protected]936c6f52011-12-13 01:35:261649 Send(pending_input_event_ack_.release());
1650
[email protected]ab543072013-01-25 04:38:151651 // If Composite() called SwapBuffers, pending_update_params_ will be reset (in
[email protected]aa4117f2011-12-09 22:19:211652 // OnSwapBuffersPosted), meaning a message has been added to the
1653 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1654 // the message now.
[email protected]59383c782013-04-17 16:43:271655 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:211656 // sending an ack to browser process that the paint is complete...
1657 update_reply_pending_ = pending_update_params_->needs_ack;
1658 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1659 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341660 }
[email protected]53d3f302009-12-21 04:42:051661
[email protected]29ed96a2012-02-04 18:12:161662 // If we're software rendering then we're done initiating the paint.
1663 if (!is_accelerated_compositing_active_)
1664 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291665}
1666
[email protected]f0c2a242013-03-15 19:34:521667void RenderWidget::Composite(base::TimeTicks frame_begin_time) {
[email protected]ab543072013-01-25 04:38:151668 DCHECK(is_accelerated_compositing_active_);
[email protected]ba91a792013-02-06 09:48:281669 if (compositor_) // TODO(jamesr): Figure out how this can be null.
[email protected]f0c2a242013-03-15 19:34:521670 compositor_->Composite(frame_begin_time);
[email protected]ab543072013-01-25 04:38:151671}
1672
initial.commit09911bf2008-07-26 23:55:291673///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461674// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291675
[email protected]4873c7d2009-07-16 06:36:281676void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]552e6002009-11-19 05:24:571677 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481678 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181679 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571680 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291681 return;
1682
[email protected]552e6002009-11-19 05:24:571683 paint_aggregator_.InvalidateRect(damaged_rect);
1684
1685 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241686 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571687 return;
1688 if (!paint_aggregator_.HasPendingUpdate())
1689 return;
[email protected]aa4117f2011-12-09 22:19:211690 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241691 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1692 return;
1693
1694 // When GPU rendering, combine pending animations and invalidations into
1695 // a single update.
[email protected]816edc62012-03-17 01:27:221696 if (is_accelerated_compositing_active_ &&
1697 animation_update_pending_ &&
1698 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571699 return;
1700
1701 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291702 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1703 // on the call stack.
1704 // 2) Allows us to collect more damage rects before painting to help coalesce
1705 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241706 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111707 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211708 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291709}
1710
[email protected]990278ff2012-11-13 02:12:551711void RenderWidget::didScrollRect(int dx, int dy,
1712 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461713 // Drop scrolls on the floor when we are in compositing mode.
1714 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561715 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461716 return;
1717
[email protected]552e6002009-11-19 05:24:571718 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481719 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181720 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571721 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291722 return;
1723
[email protected]990278ff2012-11-13 02:12:551724 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571725
1726 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241727 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571728 return;
1729 if (!paint_aggregator_.HasPendingUpdate())
1730 return;
[email protected]aa4117f2011-12-09 22:19:211731 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241732 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1733 return;
1734
1735 // When GPU rendering, combine pending animations and invalidations into
1736 // a single update.
[email protected]816edc62012-03-17 01:27:221737 if (is_accelerated_compositing_active_ &&
1738 animation_update_pending_ &&
1739 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571740 return;
1741
1742 // Perform updating asynchronously. This serves two purposes:
1743 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1744 // on the call stack.
1745 // 2) Allows us to collect more damage rects before painting to help coalesce
1746 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241747 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111748 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211749 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291750}
1751
[email protected]244ac1892011-12-02 17:04:471752void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091753 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451754 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581755
[email protected]eac2b362013-05-22 07:01:451756 // If we don't clear PaintAggregator after changing autoResize state, then
1757 // we might end up in a situation where bitmap_rect is larger than the
1758 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1759 // with invalid damage rects.
1760 paint_aggregator_.ClearPendingUpdate();
1761
[email protected]70dee7e2013-05-29 18:28:301762 if (RenderThreadImpl::current()->layout_test_mode()) {
[email protected]eac2b362013-05-22 07:01:451763 WebRect new_pos(rootWindowRect().x,
1764 rootWindowRect().y,
1765 new_size.width,
1766 new_size.height);
1767 view_screen_rect_ = new_pos;
1768 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031769 }
[email protected]20fbfc22013-05-08 20:50:581770
[email protected]eac2b362013-05-22 07:01:451771 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581772
[email protected]70dee7e2013-05-29 18:28:301773 if (!RenderThreadImpl::current()->layout_test_mode())
[email protected]20fbfc22013-05-08 20:50:581774 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091775 }
[email protected]244ac1892011-12-02 17:04:471776}
1777
[email protected]3a1c8a8032013-03-18 22:35:321778void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051779 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1780 device_scale_factor_));
1781 if (compositor_)
1782 compositor_->setViewportSize(size_, physical_backing_size_);
1783}
1784
[email protected]91acd1c2012-03-14 08:32:391785void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221786 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1787
[email protected]c63b4d42012-04-26 01:01:071788#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211789 if (!is_accelerated_compositing_active_) {
1790 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1791 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1792 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1793 // going to switch to accelerated compositing, the GPU process may need
1794 // round-trips to the browser's UI thread before finishing the frame,
1795 // causing deadlocks if we delay the UpdateRect until we receive the
1796 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071797 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1798 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211799 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1800 }
[email protected]c63b4d42012-04-26 01:01:071801#endif
[email protected]aa4117f2011-12-09 22:19:211802
[email protected]ea162f92011-10-04 23:08:221803 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421804 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241805 routing_id_, is_accelerated_compositing_active_));
[email protected]d8a6c5d12013-09-23 04:37:101806
1807 if (!was_accelerated_compositing_ever_active_) {
1808 was_accelerated_compositing_ever_active_ = true;
1809 webwidget_->enterForceCompositingMode(true);
1810 }
[email protected]ea162f92011-10-04 23:08:221811}
1812
1813void RenderWidget::didDeactivateCompositor() {
1814 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1815
1816 is_accelerated_compositing_active_ = false;
1817 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1818 routing_id_, is_accelerated_compositing_active_));
1819
[email protected]ea162f92011-10-04 23:08:221820 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241821 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091822
1823 // In single-threaded mode, we exit force compositing mode and re-enter in
1824 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1825 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1826 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361827 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091828 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561829}
1830
[email protected]e195e582013-03-08 01:32:591831void RenderWidget::initializeLayerTreeView() {
[email protected]c5fa4c42013-07-20 05:47:371832 compositor_ = RenderWidgetCompositor::Create(
1833 this, is_threaded_compositing_enabled_);
[email protected]e195e582013-03-08 01:32:591834 if (!compositor_)
1835 return;
1836
1837 compositor_->setViewportSize(size_, physical_backing_size_);
1838 if (init_complete_)
1839 compositor_->setSurfaceReady();
1840}
1841
[email protected]8926c602013-01-23 05:32:061842WebKit::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281843 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061844}
1845
[email protected]9ed83fe2013-02-27 01:52:281846void RenderWidget::suppressCompositorScheduling(bool enable) {
1847 if (compositor_)
1848 compositor_->SetSuppressScheduleComposite(enable);
1849}
1850
[email protected]9cd43a62012-03-26 08:03:561851void RenderWidget::willBeginCompositorFrame() {
1852 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371853
[email protected]cadac622013-06-11 16:46:361854 DCHECK(RenderThreadImpl::current()->compositor_message_loop_proxy().get());
[email protected]abe8b3a2012-03-28 21:19:371855
1856 // The following two can result in further layout and possibly
1857 // enable GPU acceleration so they need to be called before any painting
1858 // is done.
[email protected]cb9e2632013-06-18 11:26:471859 UpdateTextInputType();
1860#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:131861 UpdateTextInputState(false, true);
[email protected]cb9e2632013-06-18 11:26:471862#endif
[email protected]abe8b3a2012-03-28 21:19:371863 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561864}
1865
[email protected]3391a0772012-03-28 00:32:071866void RenderWidget::didBecomeReadyForAdditionalInput() {
1867 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]59383c782013-04-17 16:43:271868 if (pending_input_event_ack_)
[email protected]3391a0772012-03-28 00:32:071869 Send(pending_input_event_ack_.release());
1870}
1871
[email protected]6fceb912013-02-15 06:24:151872void RenderWidget::DidCommitCompositorFrame() {
1873}
1874
[email protected]58264a32011-11-17 23:36:151875void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501876 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351877 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1878 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421879 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU",
1880 TRACE_EVENT_SCOPE_THREAD);
[email protected]29ed96a2012-02-04 18:12:161881 // Notify subclasses that we initiated the paint operation.
1882 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151883}
1884
1885void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181886 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1887
1888 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561889 DidFlushPaint();
1890
[email protected]aa4117f2011-12-09 22:19:211891 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151892 return;
1893
[email protected]ea3ee0a2012-05-15 03:43:091894 if (!next_paint_flags_ &&
1895 !need_update_rect_for_auto_resize_ &&
1896 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151897 return;
[email protected]ea3ee0a2012-05-15 03:43:091898 }
[email protected]58264a32011-11-17 23:36:151899
1900 ViewHostMsg_UpdateRect_Params params;
1901 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151902 params.plugin_window_moves.swap(plugin_window_moves_);
1903 params.flags = next_paint_flags_;
1904 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121905 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091906 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151907
1908 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1909 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091910 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151911}
1912
[email protected]f98d7e3c2010-09-13 22:30:461913void RenderWidget::scheduleComposite() {
[email protected]7d08a9352013-10-15 08:24:561914 ScheduleCompositeImpl(false);
[email protected]f98d7e3c2010-09-13 22:30:461915}
1916
[email protected]5f8b1022011-01-21 23:34:501917void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201918 if (animation_update_pending_)
1919 return;
1920
[email protected]921244e42011-07-20 16:36:301921 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201922 animation_update_pending_ = true;
1923 if (!animation_timer_.IsRunning()) {
1924 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1925 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211926 }
[email protected]5f8b1022011-01-21 23:34:501927}
1928
[email protected]4873c7d2009-07-16 06:36:281929void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301930 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521931 WebCursor cursor;
[email protected]953bd0062013-08-01 00:58:401932 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291933 // Only send a SetCursor message if we need to make a change.
1934 if (!current_cursor_.IsEqual(cursor)) {
1935 current_cursor_ = cursor;
1936 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1937 }
1938}
1939
1940// We are supposed to get a single call to Show for a newly created RenderWidget
1941// that was created via RenderWidget::CreateWebView. So, we wait until this
1942// point to dispatch the ShowWidget message.
1943//
1944// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281945// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291946//
[email protected]4873c7d2009-07-16 06:36:281947void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291948 DCHECK(!did_show_) << "received extraneous Show call";
1949 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1950 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1951
[email protected]8de12d942010-11-17 20:42:441952 if (did_show_)
1953 return;
1954
1955 did_show_ = true;
1956 // NOTE: initial_pos_ may still have its default values at this point, but
1957 // that's okay. It'll be ignored if as_popup is false, or the browser
1958 // process will impose a default position otherwise.
1959 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1960 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291961}
1962
[email protected]9b003482013-05-21 14:00:171963void RenderWidget::didProgrammaticallyScroll(
1964 const WebKit::WebPoint& scroll_point) {
1965 if (!compositor_)
1966 return;
1967 Send(new ViewHostMsg_DidProgrammaticallyScroll(
1968 routing_id_, gfx::Vector2d(scroll_point.x, scroll_point.y)));
1969}
1970
[email protected]4873c7d2009-07-16 06:36:281971void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291972}
1973
[email protected]4873c7d2009-07-16 06:36:281974void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291975}
1976
[email protected]2533ce12009-05-09 00:02:241977void RenderWidget::DoDeferredClose() {
1978 Send(new ViewHostMsg_Close(routing_id_));
1979}
1980
[email protected]4873c7d2009-07-16 06:36:281981void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321982 if (is_swapped_out_) {
1983 // This widget is currently swapped out, and the active widget is in a
1984 // different process. Have the browser route the close request to the
1985 // active widget instead, so that the correct unload handlers are run.
1986 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1987 return;
1988 }
1989
initial.commit09911bf2008-07-26 23:55:291990 // If a page calls window.close() twice, we'll end up here twice, but that's
1991 // OK. It is safe to send multiple Close messages.
1992
[email protected]2533ce12009-05-09 00:02:241993 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1994 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1995 // could be closed before the JS finishes executing. So instead, post a
1996 // message back to the message loop, which won't run until the JS is
1997 // complete, and then the Close message can be sent.
[email protected]dd32b1272013-05-04 14:17:111998 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211999 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:292000}
2001
2002void RenderWidget::Close() {
2003 if (webwidget_) {
[email protected]8926c602013-01-23 05:32:062004 webwidget_->willCloseLayerTreeView();
[email protected]ba91a792013-02-06 09:48:282005 compositor_.reset();
[email protected]4873c7d2009-07-16 06:36:282006 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:292007 webwidget_ = NULL;
2008 }
2009}
2010
[email protected]4873c7d2009-07-16 06:36:282011WebRect RenderWidget::windowRect() {
2012 if (pending_window_rect_count_)
2013 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:242014
[email protected]80ad8622012-11-07 16:33:032015 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:292016}
2017
[email protected]8a9d6ca32011-06-06 20:11:302018void RenderWidget::setToolTipText(const WebKit::WebString& text,
2019 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:542020 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:302021}
2022
[email protected]b2e4c70132013-10-03 02:07:512023void RenderWidget::setWindowRect(const WebRect& rect) {
2024 WebRect pos = rect;
2025 if (popup_origin_scale_for_emulation_) {
2026 float scale = popup_origin_scale_for_emulation_;
2027 pos.x = popup_screen_origin_for_emulation_.x() +
2028 (pos.x - popup_view_origin_for_emulation_.x()) * scale;
2029 pos.y = popup_screen_origin_for_emulation_.y() +
2030 (pos.y - popup_view_origin_for_emulation_.y()) * scale;
2031 }
2032
initial.commit09911bf2008-07-26 23:55:292033 if (did_show_) {
[email protected]70dee7e2013-05-29 18:28:302034 if (!RenderThreadImpl::current()->layout_test_mode()) {
[email protected]8be1c582013-03-06 00:55:032035 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
2036 SetPendingWindowRect(pos);
2037 } else {
2038 WebSize new_size(pos.width, pos.height);
[email protected]d9083762013-03-24 01:36:402039 Resize(new_size, new_size, overdraw_bottom_height_,
2040 WebRect(), is_fullscreen_, NO_RESIZE_ACK);
[email protected]8be1c582013-03-06 00:55:032041 view_screen_rect_ = pos;
2042 window_screen_rect_ = pos;
2043 }
initial.commit09911bf2008-07-26 23:55:292044 } else {
2045 initial_pos_ = pos;
2046 }
2047}
2048
[email protected]2533ce12009-05-09 00:02:242049void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
2050 pending_window_rect_ = rect;
2051 pending_window_rect_count_++;
2052}
2053
[email protected]4873c7d2009-07-16 06:36:282054WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:242055 if (pending_window_rect_count_) {
2056 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
2057 // the RootWindowRect is probably going to return wrong results since the
2058 // browser may not have processed the Move yet. There isn't really anything
2059 // good to do in this case, and it shouldn't happen - since this size is
2060 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:282061 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:242062 }
2063
[email protected]80ad8622012-11-07 16:33:032064 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:372065}
2066
[email protected]4873c7d2009-07-16 06:36:282067WebRect RenderWidget::windowResizerRect() {
2068 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:192069}
2070
[email protected]fa7b1dc2010-06-23 17:53:042071void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:032072 // To prevent this renderer process from sending unnecessary IPC messages to
2073 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:042074 // only during the input method attached to the browser process is active.
2075 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:292076}
2077
[email protected]fa7b1dc2010-06-23 17:53:042078void RenderWidget::OnImeSetComposition(
2079 const string16& text,
2080 const std::vector<WebCompositionUnderline>& underlines,
2081 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:132082 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:282083 return;
[email protected]66fca5bc2013-05-23 06:58:292084 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:362085 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:042086 text, WebVector<WebCompositionUnderline>(underlines),
2087 selection_start, selection_end)) {
2088 // If we failed to set the composition text, then we need to let the browser
2089 // process to cancel the input method's ongoing composition session, to make
2090 // sure we are in a consistent state.
2091 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:262092 }
[email protected]501ea13d2013-07-09 17:03:292093#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
[email protected]88dbe32f2013-06-20 23:31:362094 UpdateCompositionInfo(true);
[email protected]501ea13d2013-07-09 17:03:292095#endif
[email protected]fa7b1dc2010-06-23 17:53:042096}
2097
[email protected]0e45bd02013-07-12 20:20:022098void RenderWidget::OnImeConfirmComposition(const string16& text,
[email protected]db4fc1e2013-09-06 20:01:512099 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:022100 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:132101 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:042102 return;
[email protected]66fca5bc2013-05-23 06:58:292103 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:042104 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:022105 if (text.length())
2106 webwidget_->confirmComposition(text);
2107 else if (keep_selection)
2108 webwidget_->confirmComposition(WebWidget::KeepSelection);
2109 else
2110 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:042111 handling_input_event_ = false;
[email protected]501ea13d2013-07-09 17:03:292112#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
[email protected]88dbe32f2013-06-20 23:31:362113 UpdateCompositionInfo(true);
[email protected]501ea13d2013-07-09 17:03:292114#endif
initial.commit09911bf2008-07-26 23:55:292115}
2116
[email protected]948f7ab72010-05-28 23:48:082117// This message causes the renderer to render an image of the
2118// desired_size, regardless of whether the tab is hidden or not.
[email protected]3d9ec5052013-01-02 22:05:252119void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle,
2120 int tag,
2121 const gfx::Size& page_size,
2122 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:002123 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
2124 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:252125 // Close our unused handle.
2126#if defined(OS_WIN)
2127 ::CloseHandle(dib_handle);
2128#elif defined(OS_MACOSX)
2129 base::SharedMemory::CloseHandle(dib_handle);
2130#endif
2131 }
[email protected]d65adb12010-04-28 17:26:492132 return;
[email protected]45c6aad32010-11-11 04:46:252133 }
[email protected]d65adb12010-04-28 17:26:492134
[email protected]948f7ab72010-05-28 23:48:082135 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:492136 // If one of these is empty, then we just return the dib we were
2137 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:092138 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:492139 return;
2140 }
2141
2142 // Map the given DIB ID into this process, and unmap it at the end
2143 // of this function.
[email protected]45c6aad32010-11-11 04:46:252144 scoped_ptr<TransportDIB> paint_at_size_buffer(
2145 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:302146
[email protected]4b01b962012-10-09 23:17:352147 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:282148 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:352149 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:282150 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:512151 gfx::Size canvas_size = page_size_in_pixel;
2152 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:492153 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:512154 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:492155 static_cast<float>(canvas_size.height());
2156
[email protected]ee8d6fd2010-05-26 17:05:482157 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:492158 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
2159 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:482160 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:492161
[email protected]36808ad2010-10-20 19:18:302162 scoped_ptr<skia::PlatformCanvas> canvas(
2163 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
2164 canvas_size.height()));
[email protected]59383c782013-04-17 16:43:272165 if (!canvas) {
[email protected]36808ad2010-10-20 19:18:302166 NOTREACHED();
2167 return;
2168 }
2169
[email protected]d65adb12010-04-28 17:26:492170 // Reset bounds to what we actually received, but they should be the
2171 // same.
2172 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
2173 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
2174 bounds.set_width(canvas->getDevice()->width());
2175 bounds.set_height(canvas->getDevice()->height());
2176
2177 canvas->save();
[email protected]948f7ab72010-05-28 23:48:082178 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:492179 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
2180
[email protected]948f7ab72010-05-28 23:48:082181 // Have to make sure we're laid out at the right size before
2182 // rendering.
2183 gfx::Size old_size = webwidget_->size();
2184 webwidget_->resize(page_size);
2185 webwidget_->layout();
2186
[email protected]d65adb12010-04-28 17:26:492187 // Paint the entire thing (using original bounds, not scaled bounds).
2188 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
2189 canvas->restore();
2190
[email protected]948f7ab72010-05-28 23:48:082191 // Return the widget to its previous size.
2192 webwidget_->resize(old_size);
2193
[email protected]c88c9442010-07-19 18:55:092194 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:492195}
2196
[email protected]51a49502013-03-23 01:50:192197void RenderWidget::OnSnapshot(const gfx::Rect& src_subrect) {
2198 SkBitmap snapshot;
2199
2200 if (OnSnapshotHelper(src_subrect, &snapshot)) {
2201 Send(new ViewHostMsg_Snapshot(routing_id(), true, snapshot));
2202 } else {
2203 Send(new ViewHostMsg_Snapshot(routing_id(), false, SkBitmap()));
2204 }
2205}
2206
2207bool RenderWidget::OnSnapshotHelper(const gfx::Rect& src_subrect,
2208 SkBitmap* snapshot) {
2209 base::TimeTicks beginning_time = base::TimeTicks::Now();
2210
2211 if (!webwidget_ || src_subrect.IsEmpty())
2212 return false;
2213
2214 gfx::Rect viewport_size = gfx::IntersectRects(
2215 src_subrect, gfx::Rect(physical_backing_size_));
2216
2217 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(
2218 skia::CreatePlatformCanvas(viewport_size.width(),
2219 viewport_size.height(),
2220 true,
2221 NULL,
2222 skia::RETURN_NULL_ON_FAILURE));
[email protected]59383c782013-04-17 16:43:272223 if (!canvas)
[email protected]51a49502013-03-23 01:50:192224 return false;
2225
2226 canvas->save();
2227 webwidget_->layout();
2228
2229 PaintRect(viewport_size, viewport_size.origin(), canvas.get());
2230 canvas->restore();
2231
2232 const SkBitmap& bitmap = skia::GetTopDevice(*canvas)->accessBitmap(false);
2233 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
2234 return false;
2235
2236 UMA_HISTOGRAM_TIMES("Renderer4.Snapshot",
2237 base::TimeTicks::Now() - beginning_time);
2238 return true;
2239}
2240
[email protected]0bc1f572013-04-17 01:46:312241void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:122242 // During shutdown we can just ignore this message.
2243 if (!webwidget_)
2244 return;
2245
[email protected]0bc1f572013-04-17 01:46:312246 // Even if the browser provides an empty damage rect, it's still expecting to
2247 // receive a repaint ack so just damage the entire widget bounds.
2248 if (size_to_paint.IsEmpty()) {
2249 size_to_paint = size_;
2250 }
2251
[email protected]ec7dc112008-08-06 05:30:122252 set_next_paint_is_repaint_ack();
[email protected]0bc1f572013-04-17 01:46:312253 if (is_accelerated_compositing_active_ && compositor_) {
2254 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]f98d7e3c2010-09-13 22:30:462255 } else {
2256 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
2257 didInvalidateRect(repaint_rect);
2258 }
[email protected]ec7dc112008-08-06 05:30:122259}
2260
[email protected]79fa22e2013-08-23 15:18:122261void RenderWidget::OnSyntheticGestureCompleted() {
2262 pending_synthetic_gesture_.Run();
[email protected]0e241b4b2012-08-18 09:06:272263}
2264
[email protected]4873c7d2009-07-16 06:36:282265void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:112266 if (!webwidget_)
2267 return;
[email protected]4873c7d2009-07-16 06:36:282268 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:112269}
2270
[email protected]80ad8622012-11-07 16:33:032271void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
2272 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:512273 if (screen_metrics_emulator_) {
2274 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
2275 view_screen_rect, window_screen_rect);
2276 } else {
2277 view_screen_rect_ = view_screen_rect;
2278 window_screen_rect_ = window_screen_rect;
2279 }
[email protected]80ad8622012-11-07 16:33:032280 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
2281}
2282
[email protected]105dffb42013-02-20 03:46:212283#if defined(OS_ANDROID)
[email protected]2384b6c2013-02-28 23:58:512284void RenderWidget::OnShowImeIfNeeded() {
[email protected]0d1ebed12013-08-05 22:01:132285 UpdateTextInputState(true, true);
2286}
2287
2288void RenderWidget::IncrementOutstandingImeEventAcks() {
2289 ++outstanding_ime_acks_;
2290}
2291
2292void RenderWidget::OnImeEventAck() {
2293 --outstanding_ime_acks_;
2294 DCHECK(outstanding_ime_acks_ >= 0);
[email protected]2384b6c2013-02-28 23:58:512295}
[email protected]105dffb42013-02-20 03:46:212296#endif
2297
[email protected]0d1ebed12013-08-05 22:01:132298bool RenderWidget::ShouldHandleImeEvent() {
2299#if defined(OS_ANDROID)
2300 return !!webwidget_ && outstanding_ime_acks_ == 0;
2301#else
2302 return !!webwidget_;
2303#endif
2304}
2305
[email protected]468ac582012-11-20 00:53:192306void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
2307 if (device_scale_factor_ == device_scale_factor)
2308 return;
2309
2310 device_scale_factor_ = device_scale_factor;
2311
2312 if (!is_accelerated_compositing_active_) {
2313 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
2314 } else {
2315 scheduleComposite();
2316 }
2317}
2318
[email protected]adab2332013-07-25 18:04:322319PepperPluginInstanceImpl* RenderWidget::GetBitmapForOptimizedPluginPaint(
2320 const gfx::Rect& paint_bounds,
2321 TransportDIB** dib,
2322 gfx::Rect* location,
2323 gfx::Rect* clip,
2324 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:462325 // Bare RenderWidgets don't support optimized plugin painting.
2326 return NULL;
[email protected]ca4847f2010-09-24 05:39:152327}
2328
[email protected]ceb36f7d2012-10-31 18:33:242329gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:522330 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:242331 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:522332}
2333
[email protected]bee16aab2009-08-26 15:55:032334void RenderWidget::SetHidden(bool hidden) {
2335 if (is_hidden_ == hidden)
2336 return;
2337
2338 // The status has changed. Tell the RenderThread about it.
2339 is_hidden_ = hidden;
2340 if (is_hidden_)
[email protected]380244092011-10-07 17:26:272341 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:032342 else
[email protected]380244092011-10-07 17:26:272343 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:032344}
2345
[email protected]2b624c562011-10-27 22:58:262346void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262347 if (!webwidget_)
2348 return;
2349
2350 if (is_fullscreen_) {
2351 webwidget_->willExitFullScreen();
2352 } else {
2353 webwidget_->willEnterFullScreen();
2354 }
[email protected]2b624c562011-10-27 22:58:262355}
2356
2357void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262358 if (!webwidget_)
2359 return;
2360
2361 if (is_fullscreen_) {
2362 webwidget_->didEnterFullScreen();
2363 } else {
2364 webwidget_->didExitFullScreen();
2365 }
[email protected]2b624c562011-10-27 22:58:262366}
2367
[email protected]699ab0d2009-04-23 23:19:142368void RenderWidget::SetBackground(const SkBitmap& background) {
2369 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:462370
[email protected]699ab0d2009-04-23 23:19:142371 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:282372 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:142373}
2374
[email protected]674741932009-02-04 23:44:462375bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:052376 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462377}
2378
2379bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:052380 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462381}
2382
2383void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:052384 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462385}
2386
2387void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:052388 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:462389}
2390
2391void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:052392 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462393}
2394
[email protected]b18583c2012-12-18 06:55:272395static bool IsDateTimeInput(ui::TextInputType type) {
2396 return type == ui::TEXT_INPUT_TYPE_DATE ||
2397 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
2398 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
2399 type == ui::TEXT_INPUT_TYPE_MONTH ||
2400 type == ui::TEXT_INPUT_TYPE_TIME ||
2401 type == ui::TEXT_INPUT_TYPE_WEEK;
2402}
2403
[email protected]66fca5bc2013-05-23 06:58:292404
2405void RenderWidget::StartHandlingImeEvent() {
2406 DCHECK(!handling_ime_event_);
2407 handling_ime_event_ = true;
2408}
2409
2410void RenderWidget::FinishHandlingImeEvent() {
2411 DCHECK(handling_ime_event_);
2412 handling_ime_event_ = false;
2413 // While handling an ime event, text input state and selection bounds updates
2414 // are ignored. These must explicitly be updated once finished handling the
2415 // ime event.
2416 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:472417#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:132418 UpdateTextInputState(false, false);
[email protected]cb9e2632013-06-18 11:26:472419#endif
[email protected]66fca5bc2013-05-23 06:58:292420}
2421
[email protected]cb9e2632013-06-18 11:26:472422void RenderWidget::UpdateTextInputType() {
[email protected]11f22bb62013-09-24 04:59:062423 // On Windows, not only an IME but also an on-screen keyboard relies on the
2424 // latest TextInputType to optimize its layout and functionality. Thus
2425 // |input_method_is_active_| is no longer an appropriate condition to suppress
2426 // TextInputTypeChanged IPC on Windows.
2427 // TODO(yukawa, yoichio): Consider to stop checking |input_method_is_active_|
2428 // on other platforms as well as Windows if the overhead is acceptable.
2429#if !defined(OS_WIN)
[email protected]cb9e2632013-06-18 11:26:472430 if (!input_method_is_active_)
2431 return;
[email protected]11f22bb62013-09-24 04:59:062432#endif
[email protected]cb9e2632013-06-18 11:26:472433
[email protected]e7c569d2013-07-17 16:00:362434 ui::TextInputType new_type = GetTextInputType();
[email protected]cb9e2632013-06-18 11:26:472435 if (IsDateTimeInput(new_type))
2436 return; // Not considered as a text input field in WebKit/Chromium.
2437
2438 bool new_can_compose_inline = CanComposeInline();
2439
[email protected]e7c569d2013-07-17 16:00:362440 WebKit::WebTextInputInfo new_info;
2441 if (webwidget_)
2442 new_info = webwidget_->textInputInfo();
[email protected]b256eca2013-07-11 10:57:402443 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
2444
[email protected]cb9e2632013-06-18 11:26:472445 if (text_input_type_ != new_type
[email protected]b256eca2013-07-11 10:57:402446 || can_compose_inline_ != new_can_compose_inline
2447 || text_input_mode_ != new_mode) {
[email protected]cb9e2632013-06-18 11:26:472448 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
2449 new_type,
[email protected]86ba5fcb2013-09-04 00:36:532450 new_mode,
2451 new_can_compose_inline));
[email protected]cb9e2632013-06-18 11:26:472452 text_input_type_ = new_type;
2453 can_compose_inline_ = new_can_compose_inline;
[email protected]b256eca2013-07-11 10:57:402454 text_input_mode_ = new_mode;
[email protected]cb9e2632013-06-18 11:26:472455 }
2456}
2457
2458#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:132459void RenderWidget::UpdateTextInputState(bool show_ime_if_needed,
2460 bool send_ime_ack) {
[email protected]e8f775f2013-02-14 21:00:502461 if (handling_ime_event_)
2462 return;
[email protected]3306f262012-09-21 19:20:422463 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:292464 return;
[email protected]ad26ef42011-06-17 07:59:452465 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:272466 if (IsDateTimeInput(new_type))
2467 return; // Not considered as a text input field in WebKit/Chromium.
2468
[email protected]5b739cb2012-08-21 20:35:212469 WebKit::WebTextInputInfo new_info;
2470 if (webwidget_)
2471 new_info = webwidget_->textInputInfo();
2472
[email protected]ad26ef42011-06-17 07:59:452473 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:212474
[email protected]3306f262012-09-21 19:20:422475 // Only sends text input params if they are changed or if the ime should be
2476 // shown.
2477 if (show_ime_if_needed || (text_input_type_ != new_type
2478 || text_input_info_ != new_info
2479 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:212480 ViewHostMsg_TextInputState_Params p;
2481 p.type = new_type;
2482 p.value = new_info.value.utf8();
2483 p.selection_start = new_info.selectionStart;
2484 p.selection_end = new_info.selectionEnd;
2485 p.composition_start = new_info.compositionStart;
2486 p.composition_end = new_info.compositionEnd;
2487 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:422488 p.show_ime_if_needed = show_ime_if_needed;
[email protected]0d1ebed12013-08-05 22:01:132489 p.require_ack = send_ime_ack;
2490 if (p.require_ack)
2491 IncrementOutstandingImeEventAcks();
[email protected]5b739cb2012-08-21 20:35:212492 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
2493
2494 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:042495 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:452496 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:292497 }
initial.commit09911bf2008-07-26 23:55:292498}
[email protected]cb9e2632013-06-18 11:26:472499#endif
initial.commit09911bf2008-07-26 23:55:292500
[email protected]7c8873e2013-02-05 08:03:012501void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2502 WebRect focus_webrect;
2503 WebRect anchor_webrect;
2504 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
2505 *focus = focus_webrect;
2506 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322507}
2508
[email protected]e99ef6f2011-10-16 01:13:002509void RenderWidget::UpdateSelectionBounds() {
2510 if (!webwidget_)
2511 return;
[email protected]66fca5bc2013-05-23 06:58:292512 if (handling_ime_event_)
2513 return;
[email protected]e99ef6f2011-10-16 01:13:002514
[email protected]7c8873e2013-02-05 08:03:012515 ViewHostMsg_SelectionBounds_Params params;
2516 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2517 if (selection_anchor_rect_ != params.anchor_rect ||
2518 selection_focus_rect_ != params.focus_rect) {
2519 selection_anchor_rect_ = params.anchor_rect;
2520 selection_focus_rect_ = params.focus_rect;
2521 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
[email protected]129b7382013-02-12 02:14:292522 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
[email protected]7c8873e2013-02-05 08:03:012523 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
[email protected]58b48a0d2012-06-13 07:01:352524 }
[email protected]501ea13d2013-07-09 17:03:292525#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
[email protected]88dbe32f2013-06-20 23:31:362526 UpdateCompositionInfo(false);
[email protected]501ea13d2013-07-09 17:03:292527#endif
[email protected]e99ef6f2011-10-16 01:13:002528}
2529
[email protected]73bf95812011-10-12 11:38:322530// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:452531COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
2532 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
2533COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
2534 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
2535COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
2536 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:182537COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
2538 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
2539COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
2540 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
2541COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
2542 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
2543COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
2544 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
2545COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
2546 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:002547COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
2548 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
2549COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
2550 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
2551COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
2552 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
2553COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
2554 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
2555COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
2556 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
2557COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
2558 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:012559COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
2560 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
2561COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
2562 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]8b4992e2013-03-01 15:42:152563COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeField) == \
2564 int(ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:452565
[email protected]5b739cb2012-08-21 20:35:212566ui::TextInputType RenderWidget::WebKitToUiTextInputType(
2567 WebKit::WebTextInputType type) {
2568 // Check the type is in the range representable by ui::TextInputType.
2569 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
2570 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
2571 return static_cast<ui::TextInputType>(type);
2572}
2573
[email protected]ad26ef42011-06-17 07:59:452574ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272575 if (webwidget_)
2576 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452577 return ui::TEXT_INPUT_TYPE_NONE;
2578}
2579
[email protected]501ea13d2013-07-09 17:03:292580#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
2581void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
[email protected]db4fc1e2013-09-06 20:01:512582 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292583 if (should_update_range) {
2584 GetCompositionRange(&range);
2585 } else {
2586 range = composition_range_;
2587 }
2588 std::vector<gfx::Rect> character_bounds;
2589 GetCompositionCharacterBounds(&character_bounds);
2590
2591 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2592 return;
2593 composition_character_bounds_ = character_bounds;
2594 composition_range_ = range;
2595 Send(new ViewHostMsg_ImeCompositionRangeChanged(
2596 routing_id(), composition_range_, composition_character_bounds_));
2597}
2598
[email protected]58b48a0d2012-06-13 07:01:352599void RenderWidget::GetCompositionCharacterBounds(
2600 std::vector<gfx::Rect>* bounds) {
2601 DCHECK(bounds);
2602 bounds->clear();
2603}
2604
[email protected]db4fc1e2013-09-06 20:01:512605void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362606 size_t location, length;
2607 if (webwidget_->compositionRange(&location, &length)) {
2608 range->set_start(location);
2609 range->set_end(location + length);
2610 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2611 range->set_start(location);
2612 range->set_end(location + length);
2613 } else {
[email protected]db4fc1e2013-09-06 20:01:512614 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362615 }
2616}
2617
[email protected]501ea13d2013-07-09 17:03:292618bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512619 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292620 const std::vector<gfx::Rect>& bounds) {
2621 if (composition_range_ != range)
2622 return true;
2623 if (bounds.size() != composition_character_bounds_.size())
2624 return true;
2625 for (size_t i = 0; i < bounds.size(); ++i) {
2626 if (bounds[i] != composition_character_bounds_[i])
2627 return true;
2628 }
2629 return false;
2630}
2631#endif
2632
[email protected]ad26ef42011-06-17 07:59:452633bool RenderWidget::CanComposeInline() {
2634 return true;
[email protected]56ea1a62011-05-30 07:05:572635}
2636
[email protected]4873c7d2009-07-16 06:36:282637WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042638 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282639}
2640
[email protected]f660d9c2012-06-06 18:31:212641float RenderWidget::deviceScaleFactor() {
2642 return device_scale_factor_;
2643}
2644
[email protected]fa7b1dc2010-06-23 17:53:042645void RenderWidget::resetInputMethod() {
2646 if (!input_method_is_active_)
2647 return;
2648
[email protected]0e45bd02013-07-12 20:20:022649 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042650 // If the last text input type is not None, then we should finish any
2651 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452652 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042653 // If a composition text exists, then we need to let the browser process
2654 // to cancel the input method's ongoing composition session.
2655 if (webwidget_->confirmComposition())
2656 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
2657 }
[email protected]d4cff272011-05-02 15:46:012658
[email protected]501ea13d2013-07-09 17:03:292659#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
[email protected]88dbe32f2013-06-20 23:31:362660 UpdateCompositionInfo(true);
[email protected]501ea13d2013-07-09 17:03:292661#endif
[email protected]fa7b1dc2010-06-23 17:53:042662}
2663
[email protected]c68c3e4e2013-01-24 00:36:562664void RenderWidget::didHandleGestureEvent(
2665 const WebGestureEvent& event,
2666 bool event_cancelled) {
2667#if defined(OS_ANDROID)
2668 if (event_cancelled)
2669 return;
2670 if (event.type == WebInputEvent::GestureTap ||
2671 event.type == WebInputEvent::GestureLongPress) {
[email protected]0d1ebed12013-08-05 22:01:132672 UpdateTextInputState(true, true);
[email protected]c68c3e4e2013-01-24 00:36:562673 }
2674#endif
2675}
2676
[email protected]29e2fb42013-07-19 01:13:472677void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292678 size_t i = 0;
2679 for (; i < plugin_window_moves_.size(); ++i) {
2680 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582681 if (move.rects_valid) {
2682 plugin_window_moves_[i] = move;
2683 } else {
2684 plugin_window_moves_[i].visible = move.visible;
2685 }
initial.commit09911bf2008-07-26 23:55:292686 break;
2687 }
2688 }
2689
2690 if (i == plugin_window_moves_.size())
2691 plugin_window_moves_.push_back(move);
2692}
[email protected]268654772009-08-06 23:02:042693
2694void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2695 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2696 i != plugin_window_moves_.end(); ++i) {
2697 if (i->window == window) {
2698 plugin_window_moves_.erase(i);
2699 break;
2700 }
2701 }
2702}
[email protected]67bfb83f2011-09-22 03:36:372703
[email protected]b63d58d2012-11-26 22:37:442704void RenderWidget::GetRenderingStats(
2705 WebKit::WebRenderingStatsImpl& stats) const {
[email protected]ba91a792013-02-06 09:48:282706 if (compositor_)
[email protected]635353c2013-03-06 09:11:202707 compositor_->GetRenderingStats(&stats.rendering_stats);
[email protected]b63d58d2012-11-26 22:37:442708
[email protected]c1e6cc062013-08-24 03:35:352709 stats.rendering_stats.Add(
2710 legacy_software_mode_stats_->GetRenderingStats());
[email protected]fef5e3972012-08-07 03:59:472711}
2712
[email protected]e9ff79c2012-10-19 21:31:262713bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:522714 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
2715 if (!gpu_channel)
2716 return false;
2717
2718 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
2719}
2720
[email protected]24ed0432013-04-24 07:50:312721RenderWidgetCompositor* RenderWidget::compositor() const {
2722 return compositor_.get();
2723}
2724
[email protected]3639aa82013-06-04 11:00:042725void RenderWidget::OnSetBrowserRenderingStats(
2726 const BrowserRenderingStats& stats) {
2727 browser_rendering_stats_ = stats;
2728}
2729
2730void RenderWidget::GetBrowserRenderingStats(BrowserRenderingStats* stats) {
2731 *stats = browser_rendering_stats_;
2732}
2733
[email protected]0c2ebef2013-04-03 12:14:102734void RenderWidget::BeginSmoothScroll(
[email protected]0e241b4b2012-08-18 09:06:272735 bool down,
[email protected]79fa22e2013-08-23 15:18:122736 const SyntheticGestureCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:192737 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:292738 int mouse_event_x,
2739 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:272740 DCHECK(!callback.is_null());
[email protected]267909d2012-10-20 04:36:192741
2742 ViewHostMsg_BeginSmoothScroll_Params params;
2743 params.scroll_down = down;
2744 params.pixels_to_scroll = pixels_to_scroll;
2745 params.mouse_event_x = mouse_event_x;
2746 params.mouse_event_y = mouse_event_y;
2747
[email protected]4a9dba42013-04-29 18:24:222748 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, params));
[email protected]79fa22e2013-08-23 15:18:122749 pending_synthetic_gesture_ = callback;
[email protected]a39ca1652012-07-13 21:30:582750}
2751
[email protected]1e1dd182013-09-12 01:51:152752void RenderWidget::BeginPinch(
2753 bool zoom_in,
2754 int pixels_to_move,
2755 int anchor_x,
2756 int anchor_y,
2757 const SyntheticGestureCompletionCallback& callback) {
2758 DCHECK(!callback.is_null());
2759
2760 ViewHostMsg_BeginPinch_Params params;
2761 params.zoom_in = zoom_in;
2762 params.pixels_to_move = pixels_to_move;
2763 params.anchor_x = anchor_x;
2764 params.anchor_y = anchor_y;
2765
2766 Send(new ViewHostMsg_BeginPinch(routing_id_, params));
2767 pending_synthetic_gesture_ = callback;
2768}
2769
[email protected]67bfb83f2011-09-22 03:36:372770bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
2771 return false;
2772}
[email protected]c3d45532011-10-07 19:20:402773
[email protected]f56c7872013-06-18 12:31:572774bool RenderWidget::WillHandleKeyEvent(const WebKit::WebKeyboardEvent& event) {
2775 return false;
2776}
2777
[email protected]41d86852012-11-07 12:23:242778bool RenderWidget::WillHandleGestureEvent(
2779 const WebKit::WebGestureEvent& event) {
2780 return false;
2781}
2782
[email protected]ce6689f2013-03-29 12:52:552783void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2784 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2785}
2786
[email protected]3d5c243b2012-11-30 00:26:012787bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2788 return true;
2789}
2790
[email protected]0634cdd42013-08-16 00:46:092791scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
2792RenderWidget::CreateGraphicsContext3D(
[email protected]92fd8c02013-03-29 08:54:152793 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
[email protected]ed7defa2013-03-12 21:29:592794 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092795 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ebc0e1df2013-08-01 02:46:222796 if (CommandLine::ForCurrentProcess()->HasSwitch(
2797 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092798 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]8f746982013-03-21 06:28:032799 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
2800 new WebGraphicsContext3DCommandBufferImpl(
2801 surface_id(),
2802 GetURLForGraphicsContext3D(),
2803 RenderThreadImpl::current(),
2804 weak_ptr_factory_.GetWeakPtr()));
[email protected]ed7defa2013-03-12 21:29:592805
[email protected]b6eb8e332013-09-10 00:51:012806#if defined(OS_ANDROID)
2807 // If we raster too fast we become upload bound, and pending
2808 // uploads consume memory. For maximum upload throughput, we would
2809 // want to allow for upload_throughput * pipeline_time of pending
2810 // uploads, after which we are just wasting memory. Since we don't
2811 // know our upload throughput yet, this just caps our memory usage.
2812 size_t divider = 1;
2813 if (base::android::SysUtils::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032814 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012815 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032816 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012817 // Deadline to draw a frame to achieve 60 frames per second.
2818 const size_t kMillisecondsPerFrame = 16;
2819 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032820 size_t max_transfer_buffer_usage_mb =
2821 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2822 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012823 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2824 // to avoid unnecessarily stalling the compositor thread.
[email protected]657be322013-09-20 08:50:032825 const size_t mapped_memory_reclaim_limit =
2826 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]b6eb8e332013-09-10 00:51:012827#else
2828 const size_t mapped_memory_reclaim_limit =
2829 WebGraphicsContext3DCommandBufferImpl::kNoLimit;
2830#endif
2831 if (!context->Initialize(
[email protected]8f746982013-03-21 06:28:032832 attributes,
2833 false /* bind generates resources */,
[email protected]b6eb8e332013-09-10 00:51:012834 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE,
2835 kDefaultCommandBufferSize,
2836 kDefaultStartTransferBufferSize,
2837 kDefaultMinTransferBufferSize,
2838 kDefaultMaxTransferBufferSize,
2839 mapped_memory_reclaim_limit))
[email protected]0634cdd42013-08-16 00:46:092840 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
2841 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592842}
2843
[email protected]e9ff79c2012-10-19 21:31:262844} // namespace content