blob: 52522aef136b98d6947c0c38b8c82d006c1937af [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]8e299aa2013-10-16 18:17:4425#include "content/common/input/web_input_event_traits.h"
[email protected]c084330e02013-04-27 01:08:1526#include "content/common/input_messages.h"
[email protected]992db4c2011-05-12 15:37:1527#include "content/common/swapped_out_messages.h"
[email protected]778574e2011-03-21 22:03:5028#include "content/common/view_messages.h"
[email protected]c08950d22011-10-13 22:20:2929#include "content/public/common/content_switches.h"
[email protected]953bd0062013-08-01 00:58:4030#include "content/renderer/cursor_utils.h"
[email protected]b2e4c70132013-10-03 02:07:5131#include "content/renderer/external_popup_menu.h"
[email protected]ed7defa2013-03-12 21:29:5932#include "content/renderer/gpu/compositor_output_surface.h"
[email protected]2847b222013-04-06 00:59:2433#include "content/renderer/gpu/compositor_software_output_device.h"
[email protected]36e5ff12013-06-11 12:19:2934#include "content/renderer/gpu/delegated_compositor_output_surface.h"
[email protected]ea5f70a2013-03-07 12:30:3635#include "content/renderer/gpu/input_handler_manager.h"
[email protected]ed7defa2013-03-12 21:29:5936#include "content/renderer/gpu/mailbox_output_surface.h"
[email protected]ba91a792013-02-06 09:48:2837#include "content/renderer/gpu/render_widget_compositor.h"
[email protected]66fca5bc2013-05-23 06:58:2938#include "content/renderer/ime_event_guard.h"
[email protected]adab2332013-07-25 18:04:3239#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
[email protected]8704f89b2011-04-15 00:30:0540#include "content/renderer/render_process.h"
[email protected]f1a29a02011-10-06 23:08:4441#include "content/renderer/render_thread_impl.h"
[email protected]8d6cba42011-09-02 10:05:1942#include "content/renderer/renderer_webkitplatformsupport_impl.h"
[email protected]484955942010-08-19 16:13:1843#include "ipc/ipc_sync_message.h"
[email protected]661eb9d2009-02-03 02:11:4844#include "skia/ext/platform_canvas.h"
[email protected]aaf68892013-07-18 00:11:3045#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
46#include "third_party/WebKit/public/platform/WebPoint.h"
47#include "third_party/WebKit/public/platform/WebRect.h"
48#include "third_party/WebKit/public/platform/WebSize.h"
49#include "third_party/WebKit/public/platform/WebString.h"
[email protected]2255a9332013-06-17 05:12:3150#include "third_party/WebKit/public/web/WebCursorInfo.h"
51#include "third_party/WebKit/public/web/WebHelperPlugin.h"
52#include "third_party/WebKit/public/web/WebPagePopup.h"
53#include "third_party/WebKit/public/web/WebPopupMenu.h"
54#include "third_party/WebKit/public/web/WebPopupMenuInfo.h"
55#include "third_party/WebKit/public/web/WebRange.h"
56#include "third_party/WebKit/public/web/WebScreenInfo.h"
[email protected]d353541f2012-05-03 22:45:4157#include "third_party/skia/include/core/SkShader.h"
[email protected]faec7b12012-06-19 14:42:1358#include "ui/base/ui_base_switches.h"
[email protected]b2e4c70132013-10-03 02:07:5159#include "ui/gfx/point_conversions.h"
[email protected]a25e25b2012-09-28 14:32:3760#include "ui/gfx/rect_conversions.h"
[email protected]4b01b962012-10-09 23:17:3561#include "ui/gfx/size_conversions.h"
[email protected]1835b9e2012-02-28 13:12:4862#include "ui/gfx/skia_util.h"
[email protected]c9e2cbbb2012-05-12 21:17:2763#include "ui/gl/gl_switches.h"
[email protected]d353541f2012-05-03 22:45:4164#include "ui/surface/transport_dib.h"
[email protected]799fd732013-05-15 21:18:5265#include "webkit/renderer/compositor_bindings/web_rendering_stats_impl.h"
[email protected]661eb9d2009-02-03 02:11:4866
[email protected]eeb93112013-05-01 19:41:1067#if defined(OS_ANDROID)
[email protected]b6eb8e332013-09-10 00:51:0168#include "base/android/sys_utils.h"
[email protected]913d99a2013-05-31 07:16:0769#include "content/renderer/android/synchronous_compositor_factory.h"
[email protected]eeb93112013-05-01 19:41:1070#endif
71
[email protected]661eb9d2009-02-03 02:11:4872#if defined(OS_POSIX)
[email protected]6b889fb2010-03-23 20:09:4973#include "ipc/ipc_channel_posix.h"
[email protected]d5282e72009-05-13 13:16:5274#include "third_party/skia/include/core/SkMallocPixelRef.h"
[email protected]d353541f2012-05-03 22:45:4175#include "third_party/skia/include/core/SkPixelRef.h"
[email protected]661eb9d2009-02-03 02:11:4876#endif // defined(OS_POSIX)
[email protected]8085dbc82008-09-26 22:53:4477
[email protected]2255a9332013-06-17 05:12:3178#include "third_party/WebKit/public/web/WebWidget.h"
initial.commit09911bf2008-07-26 23:55:2979
[email protected]fa7b1dc2010-06-23 17:53:0480using WebKit::WebCompositionUnderline;
[email protected]7c51b0ee2009-07-08 21:49:3081using WebKit::WebCursorInfo;
[email protected]41d86852012-11-07 12:23:2482using WebKit::WebGestureEvent;
[email protected]62cb33cae2009-03-27 23:30:2283using WebKit::WebInputEvent;
[email protected]f56c7872013-06-18 12:31:5784using WebKit::WebKeyboardEvent;
[email protected]6a8ddba52010-09-05 04:38:0685using WebKit::WebMouseEvent;
[email protected]b2e4c70132013-10-03 02:07:5186using WebKit::WebMouseWheelEvent;
[email protected]4873c7d2009-07-16 06:36:2887using WebKit::WebNavigationPolicy;
[email protected]a7547fb2012-03-08 04:43:4488using WebKit::WebPagePopup;
[email protected]e99ef6f2011-10-16 01:13:0089using WebKit::WebPoint;
[email protected]4873c7d2009-07-16 06:36:2890using WebKit::WebPopupMenu;
[email protected]88efb7ec2009-07-14 16:32:5991using WebKit::WebPopupMenuInfo;
[email protected]484955942010-08-19 16:13:1892using WebKit::WebPopupType;
[email protected]d4cff272011-05-02 15:46:0193using WebKit::WebRange;
[email protected]b3f2b912009-04-09 16:18:5294using WebKit::WebRect;
[email protected]12456fa2009-04-01 23:07:1995using WebKit::WebScreenInfo;
[email protected]b3f2b912009-04-09 16:18:5296using WebKit::WebSize;
[email protected]4873c7d2009-07-16 06:36:2897using WebKit::WebTextDirection;
[email protected]2d0f2e92011-10-03 09:02:2498using WebKit::WebTouchEvent;
[email protected]fa7b1dc2010-06-23 17:53:0499using WebKit::WebVector;
[email protected]484955942010-08-19 16:13:18100using WebKit::WebWidget;
[email protected]e9ff79c2012-10-19 21:31:26101
[email protected]6a4d7f62013-01-07 21:32:13102namespace {
[email protected]b256eca2013-07-11 10:57:40103
104typedef std::map<std::string, ui::TextInputMode> TextInputModeMap;
105
106class TextInputModeMapSingleton {
107 public:
108 static TextInputModeMapSingleton* GetInstance() {
109 return Singleton<TextInputModeMapSingleton>::get();
110 }
111 TextInputModeMapSingleton()
112 : map() {
113 map["verbatim"] = ui::TEXT_INPUT_MODE_VERBATIM;
114 map["latin"] = ui::TEXT_INPUT_MODE_LATIN;
115 map["latin-name"] = ui::TEXT_INPUT_MODE_LATIN_NAME;
116 map["latin-prose"] = ui::TEXT_INPUT_MODE_LATIN_PROSE;
117 map["full-width-latin"] = ui::TEXT_INPUT_MODE_FULL_WIDTH_LATIN;
118 map["kana"] = ui::TEXT_INPUT_MODE_KANA;
119 map["katakana"] = ui::TEXT_INPUT_MODE_KATAKANA;
120 map["numeric"] = ui::TEXT_INPUT_MODE_NUMERIC;
121 map["tel"] = ui::TEXT_INPUT_MODE_TEL;
122 map["email"] = ui::TEXT_INPUT_MODE_EMAIL;
123 map["url"] = ui::TEXT_INPUT_MODE_URL;
124 }
125 TextInputModeMap& Map() {
126 return map;
127 }
128 private:
129 TextInputModeMap map;
130
131 friend struct DefaultSingletonTraits<TextInputModeMapSingleton>;
132
133 DISALLOW_COPY_AND_ASSIGN(TextInputModeMapSingleton);
134};
135
136ui::TextInputMode ConvertInputMode(
137 const WebKit::WebString& input_mode) {
138 static TextInputModeMapSingleton* singleton =
139 TextInputModeMapSingleton::GetInstance();
140 TextInputModeMap::iterator it = singleton->Map().find(input_mode.utf8());
141 if (it == singleton->Map().end())
142 return ui::TEXT_INPUT_MODE_DEFAULT;
143 return it->second;
[email protected]6a4d7f62013-01-07 21:32:13144}
[email protected]b256eca2013-07-11 10:57:40145
146} // namespace
147
[email protected]e9ff79c2012-10-19 21:31:26148namespace content {
[email protected]62cb33cae2009-03-27 23:30:22149
[email protected]b2e4c70132013-10-03 02:07:51150// RenderWidget::ScreenMetricsEmulator ----------------------------------------
151
152class RenderWidget::ScreenMetricsEmulator {
153 public:
154 ScreenMetricsEmulator(
155 RenderWidget* widget,
156 const gfx::Size& device_size,
157 const gfx::Rect& widget_rect,
158 float device_scale_factor,
159 bool fit_to_view);
160 virtual ~ScreenMetricsEmulator();
161
162 float scale() { return scale_; }
163 gfx::Rect widget_rect() const { return widget_rect_; }
164 gfx::Rect original_screen_rect() const { return original_view_screen_rect_; }
165
166 void ChangeEmulationParams(
167 const gfx::Size& device_size,
168 const gfx::Rect& widget_rect,
169 float device_scale_factor,
170 bool fit_to_view);
171
172 // The following methods alter handlers' behavior for messages related to
173 // widget size and position.
174 void OnResizeMessage(const ViewMsg_Resize_Params& params);
175 void OnUpdateScreenRectsMessage(const gfx::Rect& view_screen_rect,
176 const gfx::Rect& window_screen_rect);
177 void OnShowContextMenu(ContextMenuParams* params);
178
179 private:
180 void Apply(float overdraw_bottom_height,
181 gfx::Rect resizer_rect, bool is_fullscreen);
182
183 RenderWidget* widget_;
184
185 // Parameters as passed by RenderWidget::EmulateScreenMetrics.
186 gfx::Size device_size_;
187 gfx::Rect widget_rect_;
188 float device_scale_factor_;
189 bool fit_to_view_;
190
191 // The computed scaled used to fit widget into browser window.
192 float scale_;
193
194 // Original values to restore back after emulation ends.
195 gfx::Size original_size_;
196 gfx::Size original_physical_backing_size_;
197 WebKit::WebScreenInfo original_screen_info_;
198 gfx::Rect original_view_screen_rect_;
199 gfx::Rect original_window_screen_rect_;
200};
201
202RenderWidget::ScreenMetricsEmulator::ScreenMetricsEmulator(
203 RenderWidget* widget,
204 const gfx::Size& device_size,
205 const gfx::Rect& widget_rect,
206 float device_scale_factor,
207 bool fit_to_view)
208 : widget_(widget),
209 device_size_(device_size),
210 widget_rect_(widget_rect),
211 device_scale_factor_(device_scale_factor),
212 fit_to_view_(fit_to_view),
213 scale_(1.f) {
214 original_size_ = widget_->size_;
215 original_physical_backing_size_ = widget_->physical_backing_size_;
216 original_screen_info_ = widget_->screen_info_;
217 original_view_screen_rect_ = widget_->view_screen_rect_;
218 original_window_screen_rect_ = widget_->window_screen_rect_;
219 Apply(widget_->overdraw_bottom_height_,
220 widget_->resizer_rect_, widget_->is_fullscreen_);
221}
222
223RenderWidget::ScreenMetricsEmulator::~ScreenMetricsEmulator() {
224 widget_->screen_info_ = original_screen_info_;
225
226 widget_->SetDeviceScaleFactor(original_screen_info_.deviceScaleFactor);
227 widget_->SetScreenMetricsEmulationParameters(0.f, 1.f);
228 widget_->view_screen_rect_ = original_view_screen_rect_;
229 widget_->window_screen_rect_ = original_window_screen_rect_;
230 widget_->Resize(original_size_, original_physical_backing_size_,
231 widget_->overdraw_bottom_height_, widget_->resizer_rect_,
232 widget_->is_fullscreen_, NO_RESIZE_ACK);
233}
234
235void RenderWidget::ScreenMetricsEmulator::ChangeEmulationParams(
236 const gfx::Size& device_size,
237 const gfx::Rect& widget_rect,
238 float device_scale_factor,
239 bool fit_to_view) {
240 device_size_ = device_size;
241 widget_rect_ = widget_rect;
242 device_scale_factor_ = device_scale_factor;
243 fit_to_view_ = fit_to_view;
244 Apply(widget_->overdraw_bottom_height_,
245 widget_->resizer_rect_, widget_->is_fullscreen_);
246}
247
248void RenderWidget::ScreenMetricsEmulator::Apply(
249 float overdraw_bottom_height, gfx::Rect resizer_rect, bool is_fullscreen) {
250 if (fit_to_view_) {
251 DCHECK(!original_size_.IsEmpty());
252 float width_ratio =
253 static_cast<float>(widget_rect_.width()) / original_size_.width();
254 float height_ratio =
255 static_cast<float>(widget_rect_.height()) / original_size_.height();
256 float ratio = std::max(1.0f, std::max(width_ratio, height_ratio));
257 scale_ = 1.f / ratio;
258 } else {
259 scale_ = 1.f;
260 }
261
262 widget_->screen_info_.rect = gfx::Rect(device_size_);
263 widget_->screen_info_.availableRect = gfx::Rect(device_size_);
264 widget_->screen_info_.deviceScaleFactor = device_scale_factor_;
265
266 // Pass two emulation parameters to the blink side:
267 // - we keep the real device scale factor in compositor to produce sharp image
268 // even when emulating different scale factor;
269 // - in order to fit into view, WebView applies scaling transform to the
270 // root layer.
271 widget_->SetScreenMetricsEmulationParameters(
272 original_screen_info_.deviceScaleFactor, scale_);
273
274 widget_->SetDeviceScaleFactor(device_scale_factor_);
275 widget_->view_screen_rect_ = widget_rect_;
276 widget_->window_screen_rect_ = widget_->screen_info_.availableRect;
277
278 gfx::Size physical_backing_size = gfx::ToCeiledSize(gfx::ScaleSize(
279 original_size_, original_screen_info_.deviceScaleFactor));
280 widget_->Resize(widget_rect_.size(), physical_backing_size,
281 overdraw_bottom_height, resizer_rect, is_fullscreen, NO_RESIZE_ACK);
282}
283
284void RenderWidget::ScreenMetricsEmulator::OnResizeMessage(
285 const ViewMsg_Resize_Params& params) {
286 bool need_ack = params.new_size != original_size_ &&
287 !params.new_size.IsEmpty() && !params.physical_backing_size.IsEmpty();
288 original_size_ = params.new_size;
289 original_physical_backing_size_ = params.physical_backing_size;
290 original_screen_info_ = params.screen_info;
291 Apply(params.overdraw_bottom_height, params.resizer_rect,
292 params.is_fullscreen);
293
294 if (need_ack) {
295 widget_->set_next_paint_is_resize_ack();
296 if (widget_->compositor_)
297 widget_->compositor_->SetNeedsRedrawRect(gfx::Rect(widget_->size_));
298 }
299}
300
301void RenderWidget::ScreenMetricsEmulator::OnUpdateScreenRectsMessage(
302 const gfx::Rect& view_screen_rect,
303 const gfx::Rect& window_screen_rect) {
304 original_view_screen_rect_ = view_screen_rect;
305 original_window_screen_rect_ = window_screen_rect;
306}
307
308void RenderWidget::ScreenMetricsEmulator::OnShowContextMenu(
309 ContextMenuParams* params) {
310 params->x *= scale_;
311 params->y *= scale_;
312}
313
314// RenderWidget ---------------------------------------------------------------
315
[email protected]6fd35b72012-03-01 19:46:41316RenderWidget::RenderWidget(WebKit::WebPopupType popup_type,
[email protected]842f10652012-06-06 01:54:04317 const WebKit::WebScreenInfo& screen_info,
[email protected]1ac10dca2013-08-20 20:47:04318 bool swapped_out,
319 bool hidden)
initial.commit09911bf2008-07-26 23:55:29320 : routing_id_(MSG_ROUTING_NONE),
[email protected]9f4f3322012-01-18 22:29:56321 surface_id_(0),
[email protected]c5b3b5e2009-02-13 06:41:11322 webwidget_(NULL),
initial.commit09911bf2008-07-26 23:55:29323 opener_id_(MSG_ROUTING_NONE),
[email protected]fc4404d2012-11-07 19:53:30324 init_complete_(false),
[email protected]b4d08452010-10-05 17:34:35325 current_paint_buf_(NULL),
[email protected]d9083762013-03-24 01:36:40326 overdraw_bottom_height_(0.f),
initial.commit09911bf2008-07-26 23:55:29327 next_paint_flags_(0),
[email protected]0cff69e2011-11-22 22:26:06328 filtered_time_per_frame_(0.0f),
[email protected]53d3f302009-12-21 04:42:05329 update_reply_pending_(false),
[email protected]847a2582013-03-09 02:29:51330 auto_resize_mode_(false),
[email protected]ea3ee0a2012-05-15 03:43:09331 need_update_rect_for_auto_resize_(false),
[email protected]65225772011-05-12 21:10:24332 using_asynchronous_swapbuffers_(false),
333 num_swapbuffers_complete_pending_(0),
initial.commit09911bf2008-07-26 23:55:29334 did_show_(false),
[email protected]1ac10dca2013-08-20 20:47:04335 is_hidden_(hidden),
[email protected]ee41e7d22011-10-14 19:34:09336 is_fullscreen_(false),
initial.commit09911bf2008-07-26 23:55:29337 needs_repainting_on_restore_(false),
338 has_focus_(false),
[email protected]5dd768212009-08-13 23:34:49339 handling_input_event_(false),
[email protected]e8f775f2013-02-14 21:00:50340 handling_ime_event_(false),
[email protected]661eb9d2009-02-03 02:11:48341 closing_(false),
[email protected]14392a52012-05-02 20:28:44342 is_swapped_out_(swapped_out),
[email protected]fa7b1dc2010-06-23 17:53:04343 input_method_is_active_(false),
[email protected]ad26ef42011-06-17 07:59:45344 text_input_type_(ui::TEXT_INPUT_TYPE_NONE),
[email protected]b256eca2013-07-11 10:57:40345 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT),
[email protected]86ba5fcb2013-09-04 00:36:53346 can_compose_inline_(true),
[email protected]3e2b375b2010-04-07 17:03:12347 popup_type_(popup_type),
[email protected]867125a02009-12-10 06:01:48348 pending_window_rect_count_(0),
[email protected]b68a0e52011-12-08 15:11:12349 suppress_next_char_events_(false),
[email protected]5f8b1022011-01-21 23:34:50350 is_accelerated_compositing_active_(false),
[email protected]d8a6c5d12013-09-23 04:37:10351 was_accelerated_compositing_ever_active_(false),
[email protected]ee3d3ad2011-02-04 00:42:21352 animation_update_pending_(false),
[email protected]4b03e292012-02-13 18:40:07353 invalidation_task_posted_(false),
[email protected]842f10652012-06-06 01:54:04354 screen_info_(screen_info),
[email protected]3d779472012-11-15 20:49:52355 device_scale_factor_(screen_info_.deviceScaleFactor),
[email protected]ed7defa2013-03-12 21:29:59356 is_threaded_compositing_enabled_(false),
[email protected]53b4cc12013-07-18 23:02:30357 next_output_surface_id_(0),
[email protected]0d1ebed12013-08-05 22:01:13358#if defined(OS_ANDROID)
359 outstanding_ime_acks_(0),
360#endif
[email protected]b2e4c70132013-10-03 02:07:51361 popup_origin_scale_for_emulation_(0.f),
[email protected]69e797f2013-04-30 01:10:22362 weak_ptr_factory_(this) {
[email protected]8b3f0eb2012-05-03 19:15:05363 if (!swapped_out)
364 RenderProcess::current()->AddRefProcess();
[email protected]380244092011-10-07 17:26:27365 DCHECK(RenderThread::Get());
[email protected]bd37ae252011-06-03 01:28:18366 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch(
367 switches::kDisableGpuVsync);
[email protected]cb6430932012-10-31 00:53:36368 is_threaded_compositing_enabled_ =
369 CommandLine::ForCurrentProcess()->HasSwitch(
370 switches::kEnableThreadedCompositing);
[email protected]c1e6cc062013-08-24 03:35:35371
372 legacy_software_mode_stats_ = cc::RenderingStatsInstrumentation::Create();
373 if (CommandLine::ForCurrentProcess()->HasSwitch(
374 switches::kEnableGpuBenchmarking))
375 legacy_software_mode_stats_->set_record_rendering_stats(true);
initial.commit09911bf2008-07-26 23:55:29376}
377
378RenderWidget::~RenderWidget() {
[email protected]c5b3b5e2009-02-13 06:41:11379 DCHECK(!webwidget_) << "Leaking our WebWidget!";
[email protected]aa4117f2011-12-09 22:19:21380 STLDeleteElements(&updates_pending_swap_);
[email protected]b4d08452010-10-05 17:34:35381 if (current_paint_buf_) {
[email protected]467414eb2013-07-30 20:32:29382 if (RenderProcess::current()) {
383 // If the RenderProcess is already gone, it will have released all DIBs
384 // in its destructor anyway.
385 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
386 }
[email protected]b4d08452010-10-05 17:34:35387 current_paint_buf_ = NULL;
initial.commit09911bf2008-07-26 23:55:29388 }
[email protected]992db4c2011-05-12 15:37:15389 // If we are swapped out, we have released already.
[email protected]d2e2f9ee2013-08-21 11:02:02390 if (!is_swapped_out_ && RenderProcess::current())
[email protected]992db4c2011-05-12 15:37:15391 RenderProcess::current()->ReleaseProcess();
initial.commit09911bf2008-07-26 23:55:29392}
393
[email protected]484955942010-08-19 16:13:18394// static
[email protected]8085dbc82008-09-26 22:53:44395RenderWidget* RenderWidget::Create(int32 opener_id,
[email protected]842f10652012-06-06 01:54:04396 WebKit::WebPopupType popup_type,
397 const WebKit::WebScreenInfo& screen_info) {
initial.commit09911bf2008-07-26 23:55:29398 DCHECK(opener_id != MSG_ROUTING_NONE);
[email protected]6fd35b72012-03-01 19:46:41399 scoped_refptr<RenderWidget> widget(
[email protected]1ac10dca2013-08-20 20:47:04400 new RenderWidget(popup_type, screen_info, false, false));
[email protected]a635f942012-12-07 10:34:29401 if (widget->Init(opener_id)) { // adds reference on success.
[email protected]fc72bb12013-06-02 21:13:46402 return widget.get();
[email protected]a635f942012-12-07 10:34:29403 }
404 return NULL;
initial.commit09911bf2008-07-26 23:55:29405}
406
[email protected]484955942010-08-19 16:13:18407// static
408WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) {
409 switch (render_widget->popup_type_) {
[email protected]e2356242010-11-16 22:33:03410 case WebKit::WebPopupTypeNone: // Nothing to create.
[email protected]484955942010-08-19 16:13:18411 break;
412 case WebKit::WebPopupTypeSelect:
413 case WebKit::WebPopupTypeSuggestion:
414 return WebPopupMenu::create(render_widget);
[email protected]a7547fb2012-03-08 04:43:44415 case WebKit::WebPopupTypePage:
416 return WebPagePopup::create(render_widget);
[email protected]4b1146bc2012-07-10 18:46:03417 case WebKit::WebPopupTypeHelperPlugin:
418 return WebKit::WebHelperPlugin::create(render_widget);
[email protected]484955942010-08-19 16:13:18419 default:
420 NOTREACHED();
421 }
422 return NULL;
423}
424
[email protected]a635f942012-12-07 10:34:29425bool RenderWidget::Init(int32 opener_id) {
426 return DoInit(opener_id,
427 RenderWidget::CreateWebWidget(this),
428 new ViewHostMsg_CreateWidget(opener_id, popup_type_,
429 &routing_id_, &surface_id_));
[email protected]484955942010-08-19 16:13:18430}
431
[email protected]a635f942012-12-07 10:34:29432bool RenderWidget::DoInit(int32 opener_id,
[email protected]6a8ddba52010-09-05 04:38:06433 WebWidget* web_widget,
[email protected]484955942010-08-19 16:13:18434 IPC::SyncMessage* create_widget_message) {
initial.commit09911bf2008-07-26 23:55:29435 DCHECK(!webwidget_);
436
437 if (opener_id != MSG_ROUTING_NONE)
438 opener_id_ = opener_id;
439
[email protected]484955942010-08-19 16:13:18440 webwidget_ = web_widget;
initial.commit09911bf2008-07-26 23:55:29441
[email protected]380244092011-10-07 17:26:27442 bool result = RenderThread::Get()->Send(create_widget_message);
initial.commit09911bf2008-07-26 23:55:29443 if (result) {
[email protected]380244092011-10-07 17:26:27444 RenderThread::Get()->AddRoute(routing_id_, this);
initial.commit09911bf2008-07-26 23:55:29445 // Take a reference on behalf of the RenderThread. This will be balanced
446 // when we receive ViewMsg_Close.
447 AddRef();
[email protected]1ac10dca2013-08-20 20:47:04448 if (is_hidden_)
449 RenderThread::Get()->WidgetHidden();
[email protected]a635f942012-12-07 10:34:29450 return true;
initial.commit09911bf2008-07-26 23:55:29451 } else {
[email protected]a635f942012-12-07 10:34:29452 // The above Send can fail when the tab is closing.
453 return false;
initial.commit09911bf2008-07-26 23:55:29454 }
455}
456
[email protected]fc4404d2012-11-07 19:53:30457// This is used to complete pending inits and non-pending inits.
458void RenderWidget::CompleteInit() {
initial.commit09911bf2008-07-26 23:55:29459 DCHECK(routing_id_ != MSG_ROUTING_NONE);
initial.commit09911bf2008-07-26 23:55:29460
[email protected]fc4404d2012-11-07 19:53:30461 init_complete_ = true;
[email protected]05a980d7a2012-02-07 22:16:42462
[email protected]8926c602013-01-23 05:32:06463 if (webwidget_ && is_threaded_compositing_enabled_) {
464 webwidget_->enterForceCompositingMode(true);
465 }
[email protected]ba91a792013-02-06 09:48:28466 if (compositor_) {
467 compositor_->setSurfaceReady();
[email protected]479b0172012-10-29 19:27:09468 }
[email protected]05a980d7a2012-02-07 22:16:42469 DoDeferredUpdate();
initial.commit09911bf2008-07-26 23:55:29470
[email protected]6de74452009-02-25 18:04:59471 Send(new ViewHostMsg_RenderViewReady(routing_id_));
initial.commit09911bf2008-07-26 23:55:29472}
473
[email protected]992db4c2011-05-12 15:37:15474void RenderWidget::SetSwappedOut(bool is_swapped_out) {
475 // We should only toggle between states.
476 DCHECK(is_swapped_out_ != is_swapped_out);
477 is_swapped_out_ = is_swapped_out;
478
479 // If we are swapping out, we will call ReleaseProcess, allowing the process
480 // to exit if all of its RenderViews are swapped out. We wait until the
481 // WasSwappedOut call to do this, to avoid showing the sad tab.
482 // If we are swapping in, we call AddRefProcess to prevent the process from
483 // exiting.
484 if (!is_swapped_out)
485 RenderProcess::current()->AddRefProcess();
486}
487
[email protected]34bb3ac2013-03-08 02:41:28488bool RenderWidget::AllowPartialSwap() const {
489 return true;
490}
491
[email protected]c8cbae72013-05-23 10:45:03492bool RenderWidget::UsingSynchronousRendererCompositor() const {
[email protected]ccc1722e2013-05-06 19:43:07493#if defined(OS_ANDROID)
[email protected]913d99a2013-05-31 07:16:07494 return SynchronousCompositorFactory::GetInstance() != NULL;
495#else
[email protected]ccc1722e2013-05-06 19:43:07496 return false;
[email protected]913d99a2013-05-31 07:16:07497#endif
[email protected]ccc1722e2013-05-06 19:43:07498}
499
[email protected]b2e4c70132013-10-03 02:07:51500void RenderWidget::EnableScreenMetricsEmulation(
501 const gfx::Size& device_size,
502 const gfx::Rect& widget_rect,
503 float device_scale_factor,
504 bool fit_to_view) {
505 if (!screen_metrics_emulator_) {
506 screen_metrics_emulator_.reset(new ScreenMetricsEmulator(this,
507 device_size, widget_rect, device_scale_factor, fit_to_view));
508 } else {
509 screen_metrics_emulator_->ChangeEmulationParams(device_size,
510 widget_rect, device_scale_factor, fit_to_view);
511 }
512}
513
514void RenderWidget::DisableScreenMetricsEmulation() {
515 screen_metrics_emulator_.reset();
516}
517
518void RenderWidget::SetPopupOriginAdjustmentsForEmulation(
519 ScreenMetricsEmulator* emulator) {
520 popup_origin_scale_for_emulation_ = emulator->scale();
521 popup_view_origin_for_emulation_ = emulator->widget_rect().origin();
522 popup_screen_origin_for_emulation_ =
523 emulator->original_screen_rect().origin();
524}
525
526void RenderWidget::SetScreenMetricsEmulationParameters(
527 float device_scale_factor, float root_layer_scale) {
528 // This is only supported in RenderView.
529 NOTREACHED();
530}
531
532void RenderWidget::SetExternalPopupOriginAdjustmentsForEmulation(
533 ExternalPopupMenu* popup, ScreenMetricsEmulator* emulator) {
534 popup->SetOriginScaleForEmulation(emulator->scale());
535}
536
537void RenderWidget::OnShowHostContextMenu(ContextMenuParams* params) {
538 if (screen_metrics_emulator_)
539 screen_metrics_emulator_->OnShowContextMenu(params);
540}
541
[email protected]7d08a9352013-10-15 08:24:56542void RenderWidget::ScheduleCompositeWithForcedRedraw() {
543 if (compositor_) {
544 // Regardless of whether threaded compositing is enabled, always
545 // use this mechanism to force the compositor to redraw. However,
546 // the invalidation code path below is still needed for the
547 // non-threaded case.
548 compositor_->SetNeedsForcedRedraw();
549 }
550 ScheduleCompositeImpl(true);
551}
552
553void RenderWidget::ScheduleCompositeImpl(bool force_redraw) {
554 if (RenderThreadImpl::current()->compositor_message_loop_proxy().get() &&
555 compositor_) {
556 if (!force_redraw) {
557 compositor_->setNeedsRedraw();
558 }
559 } else {
560 // TODO(nduca): replace with something a little less hacky. The reason this
561 // hack is still used is because the Invalidate-DoDeferredUpdate loop
562 // contains a lot of host-renderer synchronization logic that is still
563 // important for the accelerated compositing case. The option of simply
564 // duplicating all that code is less desirable than "faking out" the
565 // invalidation path using a magical damage rect.
566 didInvalidateRect(WebRect(0, 0, 1, 1));
567 }
568}
569
[email protected]a95986a82010-12-24 06:19:28570bool RenderWidget::OnMessageReceived(const IPC::Message& message) {
571 bool handled = true;
572 IPC_BEGIN_MESSAGE_MAP(RenderWidget, message)
[email protected]c084330e02013-04-27 01:08:15573 IPC_MESSAGE_HANDLER(InputMsg_HandleInputEvent, OnHandleInputEvent)
[email protected]34202de2013-05-06 23:36:22574 IPC_MESSAGE_HANDLER(InputMsg_CursorVisibilityChange,
575 OnCursorVisibilityChange)
[email protected]c084330e02013-04-27 01:08:15576 IPC_MESSAGE_HANDLER(InputMsg_MouseCaptureLost, OnMouseCaptureLost)
577 IPC_MESSAGE_HANDLER(InputMsg_SetFocus, OnSetFocus)
[email protected]a95986a82010-12-24 06:19:28578 IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose)
579 IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck)
580 IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize)
[email protected]b5913d72012-02-07 22:26:54581 IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect)
[email protected]a95986a82010-12-24 06:19:28582 IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden)
[email protected]9e2e4632012-07-27 16:38:41583 IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown)
[email protected]992db4c2011-05-12 15:37:15584 IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut)
[email protected]a95986a82010-12-24 06:19:28585 IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck)
[email protected]ed7defa2013-03-12 21:29:59586 IPC_MESSAGE_HANDLER(ViewMsg_SwapBuffers_ACK,
587 OnViewContextSwapBuffersComplete)
[email protected]a95986a82010-12-24 06:19:28588 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive)
589 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition)
590 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition)
[email protected]3d9ec5052013-01-02 22:05:25591 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnPaintAtSize)
592 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnRepaint)
[email protected]79fa22e2013-08-23 15:18:12593 IPC_MESSAGE_HANDLER(ViewMsg_SyntheticGestureCompleted,
594 OnSyntheticGestureCompleted)
[email protected]a95986a82010-12-24 06:19:28595 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection)
596 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck)
[email protected]80ad8622012-11-07 16:33:03597 IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects)
[email protected]105dffb42013-02-20 03:46:21598#if defined(OS_ANDROID)
[email protected]2384b6c2013-02-28 23:58:51599 IPC_MESSAGE_HANDLER(ViewMsg_ShowImeIfNeeded, OnShowImeIfNeeded)
[email protected]0d1ebed12013-08-05 22:01:13600 IPC_MESSAGE_HANDLER(ViewMsg_ImeEventAck, OnImeEventAck)
[email protected]105dffb42013-02-20 03:46:21601#endif
[email protected]51a49502013-03-23 01:50:19602 IPC_MESSAGE_HANDLER(ViewMsg_Snapshot, OnSnapshot)
[email protected]3639aa82013-06-04 11:00:04603 IPC_MESSAGE_HANDLER(ViewMsg_SetBrowserRenderingStats,
604 OnSetBrowserRenderingStats)
[email protected]a95986a82010-12-24 06:19:28605 IPC_MESSAGE_UNHANDLED(handled = false)
606 IPC_END_MESSAGE_MAP()
607 return handled;
608}
initial.commit09911bf2008-07-26 23:55:29609
610bool RenderWidget::Send(IPC::Message* message) {
[email protected]992db4c2011-05-12 15:37:15611 // Don't send any messages after the browser has told us to close, and filter
612 // most outgoing messages while swapped out.
613 if ((is_swapped_out_ &&
[email protected]e9ff79c2012-10-19 21:31:26614 !SwappedOutMessages::CanSendWhileSwappedOut(message)) ||
[email protected]c6c921e92012-05-10 23:31:11615 closing_) {
initial.commit09911bf2008-07-26 23:55:29616 delete message;
617 return false;
618 }
619
620 // If given a messsage without a routing ID, then assign our routing ID.
621 if (message->routing_id() == MSG_ROUTING_NONE)
622 message->set_routing_id(routing_id_);
623
[email protected]380244092011-10-07 17:26:27624 return RenderThread::Get()->Send(message);
[email protected]8085dbc82008-09-26 22:53:44625}
626
[email protected]61e2b3cc2012-03-02 16:13:34627void RenderWidget::Resize(const gfx::Size& new_size,
[email protected]60d47ac2013-03-01 23:42:44628 const gfx::Size& physical_backing_size,
[email protected]d9083762013-03-24 01:36:40629 float overdraw_bottom_height,
[email protected]61e2b3cc2012-03-02 16:13:34630 const gfx::Rect& resizer_rect,
631 bool is_fullscreen,
632 ResizeAck resize_ack) {
[email protected]1c0008842013-06-06 08:35:48633 if (!RenderThreadImpl::current() || // Will be NULL during unit tests.
634 !RenderThreadImpl::current()->layout_test_mode()) {
635 // A resize ack shouldn't be requested if we have not ACK'd the previous
636 // one.
637 DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack());
638 DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK);
639 }
initial.commit09911bf2008-07-26 23:55:29640
[email protected]61e2b3cc2012-03-02 16:13:34641 // Ignore this during shutdown.
642 if (!webwidget_)
643 return;
644
[email protected]d9083762013-03-24 01:36:40645 if (compositor_) {
[email protected]60d47ac2013-03-01 23:42:44646 compositor_->setViewportSize(new_size, physical_backing_size);
[email protected]d9083762013-03-24 01:36:40647 compositor_->SetOverdrawBottomHeight(overdraw_bottom_height);
648 }
[email protected]60d47ac2013-03-01 23:42:44649
[email protected]dade8992013-03-04 07:34:34650 physical_backing_size_ = physical_backing_size;
[email protected]d9083762013-03-24 01:36:40651 overdraw_bottom_height_ = overdraw_bottom_height;
[email protected]61e2b3cc2012-03-02 16:13:34652 resizer_rect_ = resizer_rect;
653
654 // NOTE: We may have entered fullscreen mode without changing our size.
655 bool fullscreen_change = is_fullscreen_ != is_fullscreen;
656 if (fullscreen_change)
657 WillToggleFullscreen();
658 is_fullscreen_ = is_fullscreen;
659
660 if (size_ != new_size) {
661 // TODO(darin): We should not need to reset this here.
[email protected]61e2b3cc2012-03-02 16:13:34662 needs_repainting_on_restore_ = false;
663
664 size_ = new_size;
665
666 paint_aggregator_.ClearPendingUpdate();
667
668 // When resizing, we want to wait to paint before ACK'ing the resize. This
669 // ensures that we only resize as fast as we can paint. We only need to
670 // send an ACK if we are resized to a non-empty rect.
671 webwidget_->resize(new_size);
[email protected]0b70dbe2013-05-10 19:06:32672
[email protected]92201e32013-06-08 06:14:52673 if (!RenderThreadImpl::current() || // Will be NULL during unit tests.
674 !RenderThreadImpl::current()->layout_test_mode()) {
675 // Resize should have caused an invalidation of the entire view.
676 DCHECK(new_size.IsEmpty() || is_accelerated_compositing_active_ ||
677 paint_aggregator_.HasPendingUpdate());
678 }
[email protected]1c0008842013-06-06 08:35:48679 } else if (!RenderThreadImpl::current() || // Will be NULL during unit tests.
680 !RenderThreadImpl::current()->layout_test_mode()) {
[email protected]632c4382013-05-15 08:58:45681 resize_ack = NO_RESIZE_ACK;
682 }
683
684 if (new_size.IsEmpty() || physical_backing_size.IsEmpty()) {
685 // For empty size or empty physical_backing_size, there is no next paint
686 // (along with which to send the ack) until they are set to non-empty.
[email protected]ff475a322012-03-14 00:05:35687 resize_ack = NO_RESIZE_ACK;
[email protected]61e2b3cc2012-03-02 16:13:34688 }
689
[email protected]20fbfc22013-05-08 20:50:58690 // Send the Resize_ACK flag once we paint again if requested.
[email protected]632c4382013-05-15 08:58:45691 if (resize_ack == SEND_RESIZE_ACK)
[email protected]20fbfc22013-05-08 20:50:58692 set_next_paint_is_resize_ack();
693
[email protected]61e2b3cc2012-03-02 16:13:34694 if (fullscreen_change)
695 DidToggleFullscreen();
696
697 // If a resize ack is requested and it isn't set-up, then no more resizes will
698 // come in and in general things will go wrong.
[email protected]632c4382013-05-15 08:58:45699 DCHECK(resize_ack != SEND_RESIZE_ACK || next_paint_is_resize_ack());
initial.commit09911bf2008-07-26 23:55:29700}
701
702void RenderWidget::OnClose() {
703 if (closing_)
704 return;
705 closing_ = true;
706
707 // Browser correspondence is no longer needed at this point.
[email protected]bee16aab2009-08-26 15:55:03708 if (routing_id_ != MSG_ROUTING_NONE) {
[email protected]380244092011-10-07 17:26:27709 RenderThread::Get()->RemoveRoute(routing_id_);
[email protected]bee16aab2009-08-26 15:55:03710 SetHidden(false);
711 }
initial.commit09911bf2008-07-26 23:55:29712
initial.commit09911bf2008-07-26 23:55:29713 // If there is a Send call on the stack, then it could be dangerous to close
[email protected]d3fc25652009-02-24 22:31:25714 // now. Post a task that only gets invoked when there are no nested message
715 // loops.
[email protected]dd32b1272013-05-04 14:17:11716 base::MessageLoop::current()->PostNonNestableTask(
[email protected]3a5a7822011-12-23 18:27:29717 FROM_HERE, base::Bind(&RenderWidget::Close, this));
[email protected]d3fc25652009-02-24 22:31:25718
719 // Balances the AddRef taken when we called AddRoute.
720 Release();
initial.commit09911bf2008-07-26 23:55:29721}
722
[email protected]61e2b3cc2012-03-02 16:13:34723// Got a response from the browser after the renderer decided to create a new
724// view.
[email protected]fc4404d2012-11-07 19:53:30725void RenderWidget::OnCreatingNewAck() {
[email protected]61e2b3cc2012-03-02 16:13:34726 DCHECK(routing_id_ != MSG_ROUTING_NONE);
727
[email protected]fc4404d2012-11-07 19:53:30728 CompleteInit();
[email protected]61e2b3cc2012-03-02 16:13:34729}
730
[email protected]0fdd5012013-05-29 08:05:56731void RenderWidget::OnResize(const ViewMsg_Resize_Params& params) {
[email protected]b2e4c70132013-10-03 02:07:51732 if (screen_metrics_emulator_) {
733 screen_metrics_emulator_->OnResizeMessage(params);
734 return;
735 }
736
[email protected]0fdd5012013-05-29 08:05:56737 screen_info_ = params.screen_info;
738 SetDeviceScaleFactor(screen_info_.deviceScaleFactor);
739 Resize(params.new_size, params.physical_backing_size,
740 params.overdraw_bottom_height, params.resizer_rect,
741 params.is_fullscreen, SEND_RESIZE_ACK);
initial.commit09911bf2008-07-26 23:55:29742}
743
[email protected]b5913d72012-02-07 22:26:54744void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) {
745 if (resizer_rect_ != resizer_rect) {
[email protected]b9769d82012-02-10 00:23:59746 gfx::Rect view_rect(size_);
747
[email protected]ce112fe2012-10-29 22:52:18748 gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_);
[email protected]b9769d82012-02-10 00:23:59749 if (!old_damage_rect.IsEmpty())
750 paint_aggregator_.InvalidateRect(old_damage_rect);
751
[email protected]ce112fe2012-10-29 22:52:18752 gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect);
[email protected]b9769d82012-02-10 00:23:59753 if (!new_damage_rect.IsEmpty())
754 paint_aggregator_.InvalidateRect(new_damage_rect);
755
[email protected]b5913d72012-02-07 22:26:54756 resizer_rect_ = resizer_rect;
[email protected]b9769d82012-02-10 00:23:59757
[email protected]b5913d72012-02-07 22:26:54758 if (webwidget_)
759 webwidget_->didChangeWindowResizerRect();
760 }
761}
762
initial.commit09911bf2008-07-26 23:55:29763void RenderWidget::OnWasHidden() {
[email protected]9c3085f2011-06-09 02:10:31764 TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden");
initial.commit09911bf2008-07-26 23:55:29765 // Go into a mode where we stop generating paint and scrolling events.
[email protected]bee16aab2009-08-26 15:55:03766 SetHidden(true);
initial.commit09911bf2008-07-26 23:55:29767}
768
[email protected]9e2e4632012-07-27 16:38:41769void RenderWidget::OnWasShown(bool needs_repainting) {
770 TRACE_EVENT0("renderer", "RenderWidget::OnWasShown");
initial.commit09911bf2008-07-26 23:55:29771 // During shutdown we can just ignore this message.
772 if (!webwidget_)
773 return;
774
775 // See OnWasHidden
[email protected]bee16aab2009-08-26 15:55:03776 SetHidden(false);
initial.commit09911bf2008-07-26 23:55:29777
778 if (!needs_repainting && !needs_repainting_on_restore_)
779 return;
780 needs_repainting_on_restore_ = false;
781
[email protected]d65adb12010-04-28 17:26:49782 // Tag the next paint as a restore ack, which is picked up by
783 // DoDeferredUpdate when it sends out the next PaintRect message.
initial.commit09911bf2008-07-26 23:55:29784 set_next_paint_is_restore_ack();
785
786 // Generate a full repaint.
[email protected]a79d8a632010-11-18 22:35:56787 if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:46788 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
789 } else {
790 scheduleComposite();
791 }
initial.commit09911bf2008-07-26 23:55:29792}
793
[email protected]992db4c2011-05-12 15:37:15794void RenderWidget::OnWasSwappedOut() {
795 // If we have been swapped out and no one else is using this process,
796 // it's safe to exit now. If we get swapped back in, we will call
797 // AddRefProcess in SetSwappedOut.
798 if (is_swapped_out_)
799 RenderProcess::current()->ReleaseProcess();
800}
801
[email protected]53d3f302009-12-21 04:42:05802void RenderWidget::OnRequestMoveAck() {
803 DCHECK(pending_window_rect_count_);
804 pending_window_rect_count_--;
805}
806
807void RenderWidget::OnUpdateRectAck() {
[email protected]366ae242011-05-10 02:23:58808 TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck");
[email protected]aa4117f2011-12-09 22:19:21809 DCHECK(update_reply_pending_);
[email protected]53d3f302009-12-21 04:42:05810 update_reply_pending_ = false;
811
[email protected]b4d08452010-10-05 17:34:35812 // If we sent an UpdateRect message with a zero-sized bitmap, then we should
813 // have no current paint buffer.
814 if (current_paint_buf_) {
815 RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_);
816 current_paint_buf_ = NULL;
817 }
818
[email protected]65225772011-05-12 21:10:24819 // If swapbuffers is still pending, then defer the update until the
820 // swapbuffers occurs.
821 if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
822 TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending");
823 return;
824 }
825
[email protected]29ed96a2012-02-04 18:12:16826 // Notify subclasses that software rendering was flushed to the screen.
[email protected]404939f2012-06-01 04:06:18827 if (!is_accelerated_compositing_active_) {
828 DidFlushPaint();
829 }
[email protected]a2f6bc112009-06-27 16:27:25830
initial.commit09911bf2008-07-26 23:55:29831 // Continue painting if necessary...
[email protected]65225772011-05-12 21:10:24832 DoDeferredUpdateAndSendInputAck();
833}
834
[email protected]d0be63772011-12-20 23:18:04835bool RenderWidget::SupportsAsynchronousSwapBuffers() {
[email protected]ed7defa2013-03-12 21:29:59836 // Contexts using the command buffer support asynchronous swapbuffers.
837 // See RenderWidget::CreateOutputSurface().
[email protected]cadac622013-06-11 16:46:36838 if (RenderThreadImpl::current()->compositor_message_loop_proxy().get())
[email protected]ed7defa2013-03-12 21:29:59839 return false;
840
841 return true;
842}
843
844GURL RenderWidget::GetURLForGraphicsContext3D() {
845 return GURL();
[email protected]65225772011-05-12 21:10:24846}
847
[email protected]479b0172012-10-29 19:27:09848bool RenderWidget::ForceCompositingModeEnabled() {
849 return false;
850}
851
[email protected]ebc0e1df2013-08-01 02:46:22852scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
[email protected]a1811b8912013-05-09 15:35:19853
854#if defined(OS_ANDROID)
[email protected]b6eb8e332013-09-10 00:51:01855 if (SynchronousCompositorFactory* factory =
856 SynchronousCompositorFactory::GetInstance()) {
[email protected]913d99a2013-05-31 07:16:07857 return factory->CreateOutputSurface(routing_id());
[email protected]a1811b8912013-05-09 15:35:19858 }
859#endif
860
[email protected]ed7defa2013-03-12 21:29:59861 // Explicitly disable antialiasing for the compositor. As of the time of
862 // this writing, the only platform that supported antialiasing for the
863 // compositor was Mac OS X, because the on-screen OpenGL context creation
864 // code paths on Windows and Linux didn't yet have multisampling support.
865 // Mac OS X essentially always behaves as though it's rendering offscreen.
866 // Multisampling has a heavy cost especially on devices with relatively low
867 // fill rate like most notebooks, and the Mac implementation would need to
868 // be optimized to resolve directly into the IOSurface shared between the
869 // GPU and browser processes. For these reasons and to avoid platform
870 // disparities we explicitly disable antialiasing.
871 WebKit::WebGraphicsContext3D::Attributes attributes;
872 attributes.antialias = false;
873 attributes.shareResources = true;
874 attributes.noAutomaticFlushes = true;
[email protected]a6886502013-05-16 20:59:18875 attributes.depth = false;
876 attributes.stencil = false;
[email protected]b6eb8e332013-09-10 00:51:01877
878 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
[email protected]bec084292013-05-21 21:31:44879 if (command_line.HasSwitch(cc::switches::kForceDirectLayerDrawing))
880 attributes.stencil = true;
[email protected]b6eb8e332013-09-10 00:51:01881
[email protected]0634cdd42013-08-16 00:46:09882 scoped_refptr<ContextProviderCommandBuffer> context_provider;
883 if (!fallback) {
884 context_provider = ContextProviderCommandBuffer::Create(
[email protected]af13d832013-09-13 06:56:27885 CreateGraphicsContext3D(attributes),
886 "RenderCompositor");
[email protected]0634cdd42013-08-16 00:46:09887 }
[email protected]ebc0e1df2013-08-01 02:46:22888
[email protected]b6eb8e332013-09-10 00:51:01889 uint32 output_surface_id = next_output_surface_id_++;
[email protected]0634cdd42013-08-16 00:46:09890 if (!context_provider.get()) {
[email protected]ebc0e1df2013-08-01 02:46:22891 if (!command_line.HasSwitch(switches::kEnableSoftwareCompositing))
892 return scoped_ptr<cc::OutputSurface>();
[email protected]0634cdd42013-08-16 00:46:09893
894 scoped_ptr<cc::SoftwareOutputDevice> software_device(
895 new CompositorSoftwareOutputDevice());
896
897 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface(
898 routing_id(),
899 output_surface_id,
900 NULL,
901 software_device.Pass(),
902 true));
[email protected]ebc0e1df2013-08-01 02:46:22903 }
[email protected]ed7defa2013-03-12 21:29:59904
[email protected]0c04d1c2013-07-10 00:02:32905 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer) &&
906 !command_line.HasSwitch(switches::kDisableDelegatedRenderer)) {
[email protected]36e5ff12013-06-11 12:19:29907 DCHECK(is_threaded_compositing_enabled_);
908 return scoped_ptr<cc::OutputSurface>(
[email protected]0634cdd42013-08-16 00:46:09909 new DelegatedCompositorOutputSurface(
910 routing_id(),
911 output_surface_id,
912 context_provider,
913 scoped_ptr<cc::SoftwareOutputDevice>()));
[email protected]36e5ff12013-06-11 12:19:29914 }
915 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) {
916 DCHECK(is_threaded_compositing_enabled_);
[email protected]186f09602013-09-24 07:13:16917 cc::ResourceFormat format = cc::RGBA_8888;
918#if defined(OS_ANDROID)
919 if (base::android::SysUtils::IsLowEndDevice())
920 format = cc::RGB_565;
921#endif
[email protected]36e5ff12013-06-11 12:19:29922 return scoped_ptr<cc::OutputSurface>(
[email protected]0634cdd42013-08-16 00:46:09923 new MailboxOutputSurface(
924 routing_id(),
925 output_surface_id,
926 context_provider,
[email protected]186f09602013-09-24 07:13:16927 scoped_ptr<cc::SoftwareOutputDevice>(),
928 format));
[email protected]36e5ff12013-06-11 12:19:29929 }
[email protected]0634cdd42013-08-16 00:46:09930 bool use_swap_compositor_frame_message = false;
[email protected]36e5ff12013-06-11 12:19:29931 return scoped_ptr<cc::OutputSurface>(
[email protected]0634cdd42013-08-16 00:46:09932 new CompositorOutputSurface(
933 routing_id(),
934 output_surface_id,
935 context_provider,
936 scoped_ptr<cc::SoftwareOutputDevice>(),
937 use_swap_compositor_frame_message));
[email protected]ba91a792013-02-06 09:48:28938}
939
[email protected]ed7defa2013-03-12 21:29:59940void RenderWidget::OnViewContextSwapBuffersAborted() {
[email protected]65225772011-05-12 21:10:24941 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
[email protected]aa4117f2011-12-09 22:19:21942 while (!updates_pending_swap_.empty()) {
943 ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front();
944 updates_pending_swap_.pop_front();
945 // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate
946 // compositing pass, hence doesn't require an UpdateRect message.
947 if (msg)
948 Send(msg);
949 }
[email protected]65225772011-05-12 21:10:24950 num_swapbuffers_complete_pending_ = 0;
951 using_asynchronous_swapbuffers_ = false;
952 // Schedule another frame so the compositor learns about it.
953 scheduleComposite();
954}
955
[email protected]ed7defa2013-03-12 21:29:59956void RenderWidget::OnViewContextSwapBuffersPosted() {
[email protected]37a6f302011-07-11 23:43:08957 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
[email protected]aa4117f2011-12-09 22:19:21958
959 if (using_asynchronous_swapbuffers_) {
960 ViewHostMsg_UpdateRect* msg = NULL;
961 // pending_update_params_ can be NULL if the swap doesn't correspond to an
962 // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect
963 // message.
[email protected]59383c782013-04-17 16:43:27964 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:21965 msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_);
966 pending_update_params_.reset();
967 }
968 updates_pending_swap_.push_back(msg);
[email protected]37a6f302011-07-11 23:43:08969 num_swapbuffers_complete_pending_++;
[email protected]aa4117f2011-12-09 22:19:21970 }
[email protected]37a6f302011-07-11 23:43:08971}
972
[email protected]ed7defa2013-03-12 21:29:59973void RenderWidget::OnViewContextSwapBuffersComplete() {
[email protected]65225772011-05-12 21:10:24974 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete");
[email protected]29ed96a2012-02-04 18:12:16975
[email protected]404939f2012-06-01 04:06:18976 // Notify subclasses that composited rendering was flushed to the screen.
[email protected]29ed96a2012-02-04 18:12:16977 DidFlushPaint();
978
[email protected]65225772011-05-12 21:10:24979 // When compositing deactivates, we reset the swapbuffers pending count. The
980 // swapbuffers acks may still arrive, however.
981 if (num_swapbuffers_complete_pending_ == 0) {
982 TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending");
983 return;
984 }
[email protected]aa4117f2011-12-09 22:19:21985 DCHECK(!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);
[email protected]65225772011-05-12 21:10:24992 num_swapbuffers_complete_pending_--;
993
994 // If update reply is still pending, then defer the update until that reply
995 // occurs.
[email protected]d0be63772011-12-20 23:18:04996 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:24997 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
998 return;
999 }
1000
1001 // If we are not accelerated rendering, then this is a stale swapbuffers from
[email protected]50312bf2011-06-22 23:30:061002 // when we were previously rendering. However, if an invalidation task is not
1003 // posted, there may be software rendering work pending. In that case, don't
1004 // early out.
1005 if (!is_accelerated_compositing_active_ && invalidation_task_posted_) {
[email protected]65225772011-05-12 21:10:241006 TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff");
1007 return;
1008 }
1009
[email protected]cc66e682012-10-02 06:48:181010 // Do not call DoDeferredUpdate unless there's animation work to be done or
1011 // a real invalidation. This prevents rendering in response to a swapbuffers
1012 // callback coming back after we've navigated away from the page that
1013 // generated it.
1014 if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) {
1015 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
1016 return;
1017 }
1018
[email protected]65225772011-05-12 21:10:241019 // Continue painting if necessary...
1020 DoDeferredUpdateAndSendInputAck();
initial.commit09911bf2008-07-26 23:55:291021}
1022
[email protected]0dea1652012-12-14 00:09:091023void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event,
[email protected]4b157662013-05-29 04:05:051024 const ui::LatencyInfo& latency_info,
[email protected]0dea1652012-12-14 00:09:091025 bool is_keyboard_shortcut) {
[email protected]5dd768212009-08-13 23:34:491026 handling_input_event_ = true;
[email protected]0dea1652012-12-14 00:09:091027 if (!input_event) {
[email protected]5dd768212009-08-13 23:34:491028 handling_input_event_ = false;
initial.commit09911bf2008-07-26 23:55:291029 return;
[email protected]5dd768212009-08-13 23:34:491030 }
initial.commit09911bf2008-07-26 23:55:291031
[email protected]8e299aa2013-10-16 18:17:441032 const char* const event_name =
1033 WebInputEventTraits::GetName(input_event->type);
[email protected]b4841e1c2013-05-16 22:30:101034 TRACE_EVENT1("renderer", "RenderWidget::OnHandleInputEvent",
1035 "event", event_name);
1036
[email protected]c2eaa8f2013-05-10 02:41:551037 if (compositor_)
1038 compositor_->SetLatencyInfo(latency_info);
[email protected]256737c2013-06-08 04:39:101039 else
1040 latency_info_.MergeWith(latency_info);
[email protected]c2eaa8f2013-05-10 02:41:551041
[email protected]6a4d7f62013-01-07 21:32:131042 base::TimeDelta now = base::TimeDelta::FromInternalValue(
1043 base::TimeTicks::Now().ToInternalValue());
1044
1045 int64 delta = static_cast<int64>(
1046 (now.InSecondsF() - input_event->timeStampSeconds) *
1047 base::Time::kMicrosecondsPerSecond);
1048 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.Renderer", delta, 0, 1000000, 100);
[email protected]de415552013-01-23 04:12:171049 base::HistogramBase* counter_for_type =
[email protected]bafdc5d52013-02-27 18:18:481050 base::Histogram::FactoryGet(
[email protected]b4841e1c2013-05-16 22:30:101051 base::StringPrintf("Event.Latency.Renderer.%s", event_name),
[email protected]bafdc5d52013-02-27 18:18:481052 0,
1053 1000000,
[email protected]6a4d7f62013-01-07 21:32:131054 100,
[email protected]de415552013-01-23 04:12:171055 base::HistogramBase::kUmaTargetedHistogramFlag);
[email protected]bafdc5d52013-02-27 18:18:481056 counter_for_type->Add(delta);
[email protected]6a4d7f62013-01-07 21:32:131057
[email protected]67bfb83f2011-09-22 03:36:371058 bool prevent_default = false;
1059 if (WebInputEvent::isMouseEventType(input_event->type)) {
[email protected]936c6f52011-12-13 01:35:261060 const WebMouseEvent& mouse_event =
1061 *static_cast<const WebMouseEvent*>(input_event);
1062 TRACE_EVENT2("renderer", "HandleMouseMove",
1063 "x", mouse_event.x, "y", mouse_event.y);
1064 prevent_default = WillHandleMouseEvent(mouse_event);
[email protected]67bfb83f2011-09-22 03:36:371065 }
1066
[email protected]f56c7872013-06-18 12:31:571067 if (WebInputEvent::isKeyboardEventType(input_event->type)) {
1068 const WebKeyboardEvent& key_event =
1069 *static_cast<const WebKeyboardEvent*>(input_event);
1070 prevent_default = WillHandleKeyEvent(key_event);
1071 }
1072
[email protected]41d86852012-11-07 12:23:241073 if (WebInputEvent::isGestureEventType(input_event->type)) {
1074 const WebGestureEvent& gesture_event =
1075 *static_cast<const WebGestureEvent*>(input_event);
1076 prevent_default = prevent_default || WillHandleGestureEvent(gesture_event);
1077 }
1078
[email protected]3ebcc7c2013-01-09 05:34:461079 if (input_event->type == WebInputEvent::GestureTap ||
1080 input_event->type == WebInputEvent::GestureLongPress)
1081 resetInputMethod();
1082
[email protected]67bfb83f2011-09-22 03:36:371083 bool processed = prevent_default;
[email protected]b68a0e52011-12-08 15:11:121084 if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) {
1085 suppress_next_char_events_ = false;
1086 if (!processed && webwidget_)
1087 processed = webwidget_->handleInputEvent(*input_event);
1088 }
1089
1090 // If this RawKeyDown event corresponds to a browser keyboard shortcut and
1091 // it's not processed by webkit, then we need to suppress the upcoming Char
1092 // events.
1093 if (!processed && is_keyboard_shortcut)
1094 suppress_next_char_events_ = true;
initial.commit09911bf2008-07-26 23:55:291095
[email protected]3d5c243b2012-11-30 00:26:011096 InputEventAckState ack_result = processed ?
1097 INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED;
1098 if (!processed && input_event->type == WebInputEvent::TouchStart) {
1099 const WebTouchEvent& touch_event =
1100 *static_cast<const WebTouchEvent*>(input_event);
1101 ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ?
1102 INPUT_EVENT_ACK_STATE_NOT_CONSUMED :
1103 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
1104 }
1105
[email protected]a9fb30aa2011-10-06 06:58:461106 IPC::Message* response =
[email protected]f6df0edf2013-08-07 00:27:021107 new InputHostMsg_HandleInputEvent_ACK(routing_id_,
1108 input_event->type,
1109 ack_result,
1110 latency_info);
[email protected]3391a0772012-03-28 00:32:071111 bool event_type_gets_rate_limited =
1112 input_event->type == WebInputEvent::MouseMove ||
1113 input_event->type == WebInputEvent::MouseWheel ||
[email protected]3475bb52013-10-03 08:25:161114 input_event->type == WebInputEvent::TouchMove;
[email protected]8926c602013-01-23 05:32:061115
1116 bool frame_pending = paint_aggregator_.HasPendingUpdate();
1117 if (is_accelerated_compositing_active_) {
[email protected]ba91a792013-02-06 09:48:281118 frame_pending = compositor_ &&
1119 compositor_->commitRequested();
[email protected]8926c602013-01-23 05:32:061120 }
1121
[email protected]9a8ce7f92013-06-11 12:39:491122 if (event_type_gets_rate_limited && frame_pending && !is_hidden_) {
[email protected]12fbad812009-09-01 18:21:241123 // We want to rate limit the input events in this case, so we'll wait for
1124 // painting to finish before ACKing this message.
[email protected]59383c782013-04-17 16:43:271125 if (pending_input_event_ack_) {
[email protected]353a34c2010-05-28 23:35:171126 // As two different kinds of events could cause us to postpone an ack
1127 // we send it now, if we have one pending. The Browser should never
1128 // send us the same kind of event we are delaying the ack for.
1129 Send(pending_input_event_ack_.release());
1130 }
[email protected]12fbad812009-09-01 18:21:241131 pending_input_event_ack_.reset(response);
[email protected]df09e052013-07-31 18:59:501132 if (compositor_)
1133 compositor_->NotifyInputThrottledUntilCommit();
[email protected]12fbad812009-09-01 18:21:241134 } else {
1135 Send(response);
1136 }
1137
[email protected]3306f262012-09-21 19:20:421138#if defined(OS_ANDROID)
1139 // Allow the IME to be shown when the focus changes as a consequence
1140 // of a processed touch end event.
1141 if (input_event->type == WebInputEvent::TouchEnd && processed)
[email protected]0d1ebed12013-08-05 22:01:131142 UpdateTextInputState(true, true);
[email protected]3306f262012-09-21 19:20:421143#endif
1144
[email protected]5dd768212009-08-13 23:34:491145 handling_input_event_ = false;
[email protected]446705872009-09-10 07:22:481146
[email protected]67bfb83f2011-09-22 03:36:371147 if (!prevent_default) {
1148 if (WebInputEvent::isKeyboardEventType(input_event->type))
1149 DidHandleKeyEvent();
1150 if (WebInputEvent::isMouseEventType(input_event->type))
1151 DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event)));
[email protected]2d0f2e92011-10-03 09:02:241152 if (WebInputEvent::isTouchEventType(input_event->type))
1153 DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event)));
[email protected]67bfb83f2011-09-22 03:36:371154 }
initial.commit09911bf2008-07-26 23:55:291155}
1156
[email protected]34202de2013-05-06 23:36:221157void RenderWidget::OnCursorVisibilityChange(bool is_visible) {
1158 if (webwidget_)
1159 webwidget_->setCursorVisibilityState(is_visible);
1160}
1161
initial.commit09911bf2008-07-26 23:55:291162void RenderWidget::OnMouseCaptureLost() {
1163 if (webwidget_)
[email protected]4873c7d2009-07-16 06:36:281164 webwidget_->mouseCaptureLost();
initial.commit09911bf2008-07-26 23:55:291165}
1166
1167void RenderWidget::OnSetFocus(bool enable) {
1168 has_focus_ = enable;
[email protected]9d166af2010-03-02 22:04:331169 if (webwidget_)
1170 webwidget_->setFocus(enable);
initial.commit09911bf2008-07-26 23:55:291171}
1172
1173void RenderWidget::ClearFocus() {
1174 // We may have got the focus from the browser before this gets processed, in
1175 // which case we do not want to unfocus ourself.
1176 if (!has_focus_ && webwidget_)
[email protected]4873c7d2009-07-16 06:36:281177 webwidget_->setFocus(false);
initial.commit09911bf2008-07-26 23:55:291178}
1179
[email protected]2d5d09d52009-06-15 14:29:211180void RenderWidget::PaintRect(const gfx::Rect& rect,
[email protected]4fb66842009-12-04 21:41:001181 const gfx::Point& canvas_origin,
[email protected]2d5d09d52009-06-15 14:29:211182 skia::PlatformCanvas* canvas) {
[email protected]50312bf2011-06-22 23:30:061183 TRACE_EVENT2("renderer", "PaintRect",
1184 "width", rect.width(), "height", rect.height());
[email protected]63ab54262012-11-09 15:58:451185
[email protected]4fb66842009-12-04 21:41:001186 canvas->save();
[email protected]2d5d09d52009-06-15 14:29:211187
1188 // Bring the canvas into the coordinate system of the paint rect.
[email protected]4fb66842009-12-04 21:41:001189 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()),
1190 static_cast<SkScalar>(-canvas_origin.y()));
[email protected]96c3499a2009-05-02 18:31:031191
[email protected]699ab0d2009-04-23 23:19:141192 // If there is a custom background, tile it.
1193 if (!background_.empty()) {
[email protected]699ab0d2009-04-23 23:19:141194 SkPaint paint;
[email protected]4e29afd2012-12-04 04:07:111195 skia::RefPtr<SkShader> shader = skia::AdoptRef(
1196 SkShader::CreateBitmapShader(background_,
1197 SkShader::kRepeat_TileMode,
1198 SkShader::kRepeat_TileMode));
1199 paint.setShader(shader.get());
[email protected]fb10ec5b2011-10-24 17:54:201200
1201 // Use kSrc_Mode to handle background_ transparency properly.
1202 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
1203
1204 // Canvas could contain multiple update rects. Clip to given rect so that
1205 // we don't accidentally clear other update rects.
1206 canvas->save();
[email protected]aa7e7a12013-02-22 13:37:441207 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]1835b9e2012-02-28 13:12:481208 canvas->clipRect(gfx::RectToSkRect(rect));
[email protected]699ab0d2009-04-23 23:19:141209 canvas->drawPaint(paint);
[email protected]fb10ec5b2011-10-24 17:54:201210 canvas->restore();
[email protected]699ab0d2009-04-23 23:19:141211 }
1212
[email protected]719b36f2010-12-22 20:36:461213 // First see if this rect is a plugin that can paint itself faster.
1214 TransportDIB* optimized_dib = NULL;
1215 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201216 float dib_scale_factor;
[email protected]adab2332013-07-25 18:04:321217 PepperPluginInstanceImpl* optimized_instance =
[email protected]719b36f2010-12-22 20:36:461218 GetBitmapForOptimizedPluginPaint(rect, &optimized_dib,
1219 &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201220 &optimized_copy_rect,
1221 &dib_scale_factor);
[email protected]719b36f2010-12-22 20:36:461222 if (optimized_instance) {
[email protected]20790a222013-07-25 02:23:051223#if defined(ENABLE_PLUGINS)
[email protected]719b36f2010-12-22 20:36:461224 // This plugin can be optimize-painted and we can just ask it to paint
1225 // itself. We don't actually need the TransportDIB in this case.
1226 //
1227 // This is an optimization for PPAPI plugins that know they're on top of
1228 // the page content. If this rect is inside such a plugin, we can save some
1229 // time and avoid re-rendering the page content which we know will be
1230 // covered by the plugin later (this time can be significant, especially
1231 // for a playing movie that is invalidating a lot).
1232 //
1233 // In the plugin movie case, hopefully the similar call to
1234 // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the
1235 // painting, because that avoids copying the plugin image to a different
1236 // paint rect. Unfortunately, if anything on the page is animating other
1237 // than the movie, it break this optimization since the union of the
1238 // invalid regions will be larger than the plugin.
1239 //
1240 // This code optimizes that case, where we can still avoid painting in
1241 // WebKit and filling the background (which can be slow) and just painting
1242 // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still
1243 // required.
[email protected]df59dd42012-09-14 22:56:301244 SkAutoCanvasRestore auto_restore(canvas, true);
1245 canvas->scale(device_scale_factor_, device_scale_factor_);
[email protected]6bd867b2013-07-24 22:10:201246 optimized_instance->Paint(canvas, optimized_copy_location, rect);
[email protected]ea43e752012-09-06 22:39:211247 canvas->restore();
[email protected]20790a222013-07-25 02:23:051248#endif
[email protected]719b36f2010-12-22 20:36:461249 } else {
1250 // Normal painting case.
[email protected]c1e6cc062013-08-24 03:35:351251 base::TimeTicks start_time;
1252 if (!is_accelerated_compositing_active_)
1253 start_time = legacy_software_mode_stats_->StartRecording();
[email protected]63ab54262012-11-09 15:58:451254
[email protected]6bd867b2013-07-24 22:10:201255 webwidget_->paint(canvas, rect);
[email protected]63ab54262012-11-09 15:58:451256
[email protected]c1e6cc062013-08-24 03:35:351257 if (!is_accelerated_compositing_active_) {
[email protected]63ab54262012-11-09 15:58:451258 base::TimeDelta paint_time =
[email protected]c1e6cc062013-08-24 03:35:351259 legacy_software_mode_stats_->EndRecording(start_time);
1260 int64 painted_pixel_count = rect.width() * rect.height();
1261 legacy_software_mode_stats_->AddPaint(paint_time, painted_pixel_count);
[email protected]63ab54262012-11-09 15:58:451262 }
[email protected]719b36f2010-12-22 20:36:461263
1264 // Flush to underlying bitmap. TODO(darin): is this needed?
[email protected]62f2e802011-05-26 14:28:351265 skia::GetTopDevice(*canvas)->accessBitmap(false);
[email protected]719b36f2010-12-22 20:36:461266 }
initial.commit09911bf2008-07-26 23:55:291267
[email protected]4fb66842009-12-04 21:41:001268 PaintDebugBorder(rect, canvas);
[email protected]4fb66842009-12-04 21:41:001269 canvas->restore();
1270}
1271
1272void RenderWidget::PaintDebugBorder(const gfx::Rect& rect,
1273 skia::PlatformCanvas* canvas) {
1274 static bool kPaintBorder =
1275 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects);
1276 if (!kPaintBorder)
1277 return;
1278
[email protected]53d3f302009-12-21 04:42:051279 // Cycle through these colors to help distinguish new paint rects.
1280 const SkColor colors[] = {
1281 SkColorSetARGB(0x3F, 0xFF, 0, 0),
1282 SkColorSetARGB(0x3F, 0xFF, 0, 0xFF),
1283 SkColorSetARGB(0x3F, 0, 0, 0xFF),
1284 };
1285 static int color_selector = 0;
1286
[email protected]4fb66842009-12-04 21:41:001287 SkPaint paint;
1288 paint.setStyle(SkPaint::kStroke_Style);
[email protected]53d3f302009-12-21 04:42:051289 paint.setColor(colors[color_selector++ % arraysize(colors)]);
[email protected]4fb66842009-12-04 21:41:001290 paint.setStrokeWidth(1);
1291
1292 SkIRect irect;
1293 irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1);
1294 canvas->drawIRect(irect, paint);
initial.commit09911bf2008-07-26 23:55:291295}
1296
[email protected]52ccd0ea2011-02-16 01:09:051297void RenderWidget::AnimationCallback() {
[email protected]921244e42011-07-20 16:36:301298 TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback");
[email protected]921244e42011-07-20 16:36:301299 if (!animation_update_pending_) {
1300 TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending");
[email protected]7c4329e2011-02-18 22:02:591301 return;
[email protected]921244e42011-07-20 16:36:301302 }
[email protected]bd37ae252011-06-03 01:28:181303 if (!animation_floor_time_.is_null() && IsRenderingVSynced()) {
[email protected]7c4329e2011-02-18 22:02:591304 // Record when we fired (according to base::Time::Now()) relative to when
1305 // we posted the task to quantify how much the base::Time/base::TimeTicks
1306 // skew is affecting animations.
1307 base::TimeDelta animation_callback_delay = base::Time::Now() -
1308 (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16));
1309 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime",
1310 animation_callback_delay,
1311 base::TimeDelta::FromMilliseconds(0),
1312 base::TimeDelta::FromMilliseconds(30),
1313 25);
1314 }
[email protected]65225772011-05-12 21:10:241315 DoDeferredUpdateAndSendInputAck();
[email protected]12fbad812009-09-01 18:21:241316}
1317
[email protected]52ccd0ea2011-02-16 01:09:051318void RenderWidget::AnimateIfNeeded() {
[email protected]7c4329e2011-02-18 22:02:591319 if (!animation_update_pending_)
1320 return;
[email protected]bd37ae252011-06-03 01:28:181321
1322 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off.
[email protected]02798a982012-01-27 00:45:331323 base::TimeDelta animationInterval = IsRenderingVSynced() ?
1324 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta();
[email protected]bd37ae252011-06-03 01:28:181325
[email protected]7c4329e2011-02-18 22:02:591326 base::Time now = base::Time::Now();
[email protected]51e403bb2012-03-02 21:09:451327
1328 // animation_floor_time_ is the earliest time that we should animate when
1329 // using the dead reckoning software scheduler. If we're using swapbuffers
1330 // complete callbacks to rate limit, we can ignore this floor.
1331 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
[email protected]921244e42011-07-20 16:36:301332 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
[email protected]02798a982012-01-27 00:45:331333 animation_floor_time_ = now + animationInterval;
[email protected]bd37ae252011-06-03 01:28:181334 // Set a timer to call us back after animationInterval before
[email protected]7c4329e2011-02-18 22:02:591335 // running animation callbacks so that if a callback requests another
1336 // we'll be sure to run it at the proper time.
[email protected]350ce8702012-03-09 04:23:381337 animation_timer_.Stop();
1338 animation_timer_.Start(FROM_HERE, animationInterval, this,
1339 &RenderWidget::AnimationCallback);
[email protected]7c4329e2011-02-18 22:02:591340 animation_update_pending_ = false;
[email protected]ba91a792013-02-06 09:48:281341 if (is_accelerated_compositing_active_ && compositor_) {
[email protected]635353c2013-03-06 09:11:201342 compositor_->Animate(base::TimeTicks::Now());
[email protected]8926c602013-01-23 05:32:061343 } else {
[email protected]635353c2013-03-06 09:11:201344 double frame_begin_time =
1345 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
1346 webwidget_->animate(frame_begin_time);
[email protected]8926c602013-01-23 05:32:061347 }
[email protected]7c4329e2011-02-18 22:02:591348 return;
[email protected]5f8b1022011-01-21 23:34:501349 }
[email protected]bd37ae252011-06-03 01:28:181350 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
[email protected]350ce8702012-03-09 04:23:381351 if (!animation_timer_.IsRunning()) {
1352 // This code uses base::Time::Now() to calculate the floor and next fire
1353 // time because javascript's Date object uses base::Time::Now(). The
1354 // message loop uses base::TimeTicks, which on windows can have a
1355 // different granularity than base::Time.
1356 // The upshot of all this is that this function might be called before
1357 // base::Time::Now() has advanced past the animation_floor_time_. To
1358 // avoid exposing this delay to javascript, we keep posting delayed
1359 // tasks until base::Time::Now() has advanced far enough.
1360 base::TimeDelta delay = animation_floor_time_ - now;
1361 animation_timer_.Start(FROM_HERE, delay, this,
1362 &RenderWidget::AnimationCallback);
1363 }
[email protected]5f8b1022011-01-21 23:34:501364}
1365
[email protected]bd37ae252011-06-03 01:28:181366bool RenderWidget::IsRenderingVSynced() {
1367 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is
1368 // not caught by this check. This will lead to artificially low frame rates
1369 // for people who force vsync off at a driver level and expect Chrome to speed
1370 // up.
1371 return !has_disable_gpu_vsync_switch_;
1372}
1373
[email protected]65225772011-05-12 21:10:241374void RenderWidget::InvalidationCallback() {
[email protected]50312bf2011-06-22 23:30:061375 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback");
[email protected]65225772011-05-12 21:10:241376 invalidation_task_posted_ = false;
1377 DoDeferredUpdateAndSendInputAck();
1378}
1379
1380void RenderWidget::DoDeferredUpdateAndSendInputAck() {
[email protected]52ccd0ea2011-02-16 01:09:051381 DoDeferredUpdate();
1382
[email protected]59383c782013-04-17 16:43:271383 if (pending_input_event_ack_)
[email protected]52ccd0ea2011-02-16 01:09:051384 Send(pending_input_event_ack_.release());
[email protected]ee3d3ad2011-02-04 00:42:211385}
1386
[email protected]552e6002009-11-19 05:24:571387void RenderWidget::DoDeferredUpdate() {
[email protected]366ae242011-05-10 02:23:581388 TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate");
[email protected]fc8bde1a2013-07-04 08:54:071389 TRACE_EVENT_SCOPED_SAMPLING_STATE("Chrome", "Paint");
[email protected]71e2f0a2011-03-15 22:25:081390
[email protected]65225772011-05-12 21:10:241391 if (!webwidget_)
initial.commit09911bf2008-07-26 23:55:291392 return;
[email protected]05a980d7a2012-02-07 22:16:421393
[email protected]fc4404d2012-11-07 19:53:301394 if (!init_complete_) {
1395 TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete");
[email protected]05a980d7a2012-02-07 22:16:421396 return;
1397 }
[email protected]aa4117f2011-12-09 22:19:211398 if (update_reply_pending_) {
[email protected]65225772011-05-12 21:10:241399 TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending");
1400 return;
1401 }
[email protected]9ca84622011-06-02 23:46:391402 if (is_accelerated_compositing_active_ &&
1403 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) {
[email protected]65225772011-05-12 21:10:241404 TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending");
1405 return;
1406 }
initial.commit09911bf2008-07-26 23:55:291407
[email protected]552e6002009-11-19 05:24:571408 // Suppress updating when we are hidden.
[email protected]e3d92a7f2013-01-10 02:35:051409 if (is_hidden_ || size_.IsEmpty() || is_swapped_out_) {
[email protected]552e6002009-11-19 05:24:571410 paint_aggregator_.ClearPendingUpdate();
initial.commit09911bf2008-07-26 23:55:291411 needs_repainting_on_restore_ = true;
[email protected]65225772011-05-12 21:10:241412 TRACE_EVENT0("renderer", "EarlyOut_NotVisible");
initial.commit09911bf2008-07-26 23:55:291413 return;
1414 }
1415
[email protected]0fb93f52011-05-18 23:13:561416 // Tracking of frame rate jitter
1417 base::TimeTicks frame_begin_ticks = base::TimeTicks::Now();
[email protected]38ce4e7b2013-02-23 06:17:371418 InstrumentWillBeginFrame();
[email protected]52ccd0ea2011-02-16 01:09:051419 AnimateIfNeeded();
[email protected]5f8b1022011-01-21 23:34:501420
[email protected]f98d7e3c2010-09-13 22:30:461421 // Layout may generate more invalidation. It may also enable the
1422 // GPU acceleration, so make sure to run layout before we send the
1423 // GpuRenderingActivated message.
1424 webwidget_->layout();
1425
[email protected]793b2d62013-06-11 00:43:251426 // Check for whether we need to track swap buffers. We need to do that after
1427 // layout() because it may have switched us to accelerated compositing.
1428 if (is_accelerated_compositing_active_)
1429 using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers();
1430
[email protected]dcca3aa92012-02-17 23:03:371431 // The following two can result in further layout and possibly
1432 // enable GPU acceleration so they need to be called before any painting
1433 // is done.
[email protected]cb9e2632013-06-18 11:26:471434 UpdateTextInputType();
[email protected]dcca3aa92012-02-17 23:03:371435 UpdateSelectionBounds();
1436
[email protected]5f8b1022011-01-21 23:34:501437 // Suppress painting if nothing is dirty. This has to be done after updating
1438 // animations running layout as these may generate further invalidations.
[email protected]65225772011-05-12 21:10:241439 if (!paint_aggregator_.HasPendingUpdate()) {
1440 TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate");
[email protected]38ce4e7b2013-02-23 06:17:371441 InstrumentDidCancelFrame();
[email protected]5f8b1022011-01-21 23:34:501442 return;
[email protected]65225772011-05-12 21:10:241443 }
[email protected]5f8b1022011-01-21 23:34:501444
[email protected]479b0172012-10-29 19:27:091445 if (!is_accelerated_compositing_active_ &&
[email protected]cb6430932012-10-31 00:53:361446 !is_threaded_compositing_enabled_ &&
[email protected]d8a6c5d12013-09-23 04:37:101447 (ForceCompositingModeEnabled() ||
1448 was_accelerated_compositing_ever_active_)) {
[email protected]479b0172012-10-29 19:27:091449 webwidget_->enterForceCompositingMode(true);
1450 }
1451
[email protected]872ae5b2011-05-26 20:20:501452 if (!last_do_deferred_update_time_.is_null()) {
[email protected]0fb93f52011-05-18 23:13:561453 base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_;
[email protected]d0be63772011-12-20 23:18:041454 if (is_accelerated_compositing_active_) {
[email protected]0fb93f52011-05-18 23:13:561455 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay",
1456 delay,
1457 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411458 base::TimeDelta::FromMilliseconds(120),
1459 60);
[email protected]d0be63772011-12-20 23:18:041460 } else {
[email protected]0fb93f52011-05-18 23:13:561461 UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay",
1462 delay,
1463 base::TimeDelta::FromMilliseconds(1),
[email protected]b604cf82012-07-19 05:31:411464 base::TimeDelta::FromMilliseconds(120),
1465 60);
[email protected]d0be63772011-12-20 23:18:041466 }
[email protected]872ae5b2011-05-26 20:20:501467
1468 // Calculate filtered time per frame:
1469 float frame_time_elapsed = static_cast<float>(delay.InSecondsF());
1470 filtered_time_per_frame_ =
1471 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed;
[email protected]0fb93f52011-05-18 23:13:561472 }
1473 last_do_deferred_update_time_ = frame_begin_ticks;
1474
[email protected]fef5e3972012-08-07 03:59:471475 if (!is_accelerated_compositing_active_) {
[email protected]922c6e1f2013-10-09 04:04:091476 legacy_software_mode_stats_->IncrementFrameCount(1, true);
[email protected]adbe30f2013-10-11 21:12:331477 cc::BenchmarkInstrumentation::IssueMainThreadRenderingStatsEvent(
1478 legacy_software_mode_stats_->main_thread_rendering_stats());
[email protected]c1e6cc062013-08-24 03:35:351479 legacy_software_mode_stats_->AccumulateAndClearMainThreadStats();
[email protected]fef5e3972012-08-07 03:59:471480 }
1481
[email protected]552e6002009-11-19 05:24:571482 // OK, save the pending update to a local since painting may cause more
initial.commit09911bf2008-07-26 23:55:291483 // invalidation. Some WebCore rendering objects only layout when painted.
[email protected]dd015812010-12-06 23:39:301484 PaintAggregator::PendingUpdate update;
1485 paint_aggregator_.PopPendingUpdate(&update);
initial.commit09911bf2008-07-26 23:55:291486
[email protected]53d3f302009-12-21 04:42:051487 gfx::Rect scroll_damage = update.GetScrollDamage();
[email protected]ce112fe2012-10-29 22:52:181488 gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage);
initial.commit09911bf2008-07-26 23:55:291489
[email protected]ca4847f2010-09-24 05:39:151490 // A plugin may be able to do an optimized paint. First check this, in which
1491 // case we can skip all of the bitmap generation and regular paint code.
[email protected]719b36f2010-12-22 20:36:461492 // This optimization allows PPAPI plugins that declare themselves on top of
1493 // the page (like a traditional windowed plugin) to be able to animate (think
1494 // movie playing) without repeatedly re-painting the page underneath, or
1495 // copying the plugin backing store (since we can send the plugin's backing
1496 // store directly to the browser).
1497 //
1498 // This optimization only works when the entire invalid region is contained
1499 // within the plugin. There is a related optimization in PaintRect for the
1500 // case where there may be multiple invalid regions.
[email protected]ca4847f2010-09-24 05:39:151501 TransportDIB* dib = NULL;
[email protected]ca4847f2010-09-24 05:39:151502 gfx::Rect optimized_copy_rect, optimized_copy_location;
[email protected]0f3a2d12012-09-01 03:37:201503 float dib_scale_factor = 1;
[email protected]aa4117f2011-12-09 22:19:211504 DCHECK(!pending_update_params_.get());
1505 pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params);
[email protected]990278ff2012-11-13 02:12:551506 pending_update_params_->scroll_delta = update.scroll_delta;
[email protected]aa4117f2011-12-09 22:19:211507 pending_update_params_->scroll_rect = update.scroll_rect;
1508 pending_update_params_->view_size = size_;
[email protected]aa4117f2011-12-09 22:19:211509 pending_update_params_->plugin_window_moves.swap(plugin_window_moves_);
1510 pending_update_params_->flags = next_paint_flags_;
1511 pending_update_params_->scroll_offset = GetScrollOffset();
1512 pending_update_params_->needs_ack = true;
[email protected]7ded9f12012-06-13 20:47:091513 pending_update_params_->scale_factor = device_scale_factor_;
[email protected]aa4117f2011-12-09 22:19:211514 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091515 need_update_rect_for_auto_resize_ = false;
[email protected]aa4117f2011-12-09 22:19:211516
[email protected]256737c2013-06-08 04:39:101517 if (!is_accelerated_compositing_active_)
1518 pending_update_params_->latency_info = latency_info_;
1519
1520 latency_info_.Clear();
1521
[email protected]ca4847f2010-09-24 05:39:151522 if (update.scroll_rect.IsEmpty() &&
[email protected]a79d8a632010-11-18 22:35:561523 !is_accelerated_compositing_active_ &&
[email protected]ca4847f2010-09-24 05:39:151524 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
[email protected]0f3a2d12012-09-01 03:37:201525 &optimized_copy_rect,
1526 &dib_scale_factor)) {
[email protected]2df1b362011-01-21 21:22:271527 // Only update the part of the plugin that actually changed.
[email protected]d4030502012-10-23 16:51:471528 optimized_copy_rect.Intersect(bounds);
[email protected]aa4117f2011-12-09 22:19:211529 pending_update_params_->bitmap = dib->id();
1530 pending_update_params_->bitmap_rect = optimized_copy_location;
1531 pending_update_params_->copy_rects.push_back(optimized_copy_rect);
[email protected]0f3a2d12012-09-01 03:37:201532 pending_update_params_->scale_factor = dib_scale_factor;
[email protected]a79d8a632010-11-18 22:35:561533 } else if (!is_accelerated_compositing_active_) {
[email protected]f98d7e3c2010-09-13 22:30:461534 // Compute a buffer for painting and cache it.
[email protected]4889bd212013-02-11 22:23:101535
1536 bool fractional_scale = device_scale_factor_ -
1537 static_cast<int>(device_scale_factor_) != 0;
1538 if (fractional_scale) {
1539 // Damage might not be DIP aligned. Inflate damage to compensate.
1540 bounds.Inset(-1, -1);
1541 bounds.Intersect(gfx::Rect(size_));
1542 }
1543
1544 gfx::Rect pixel_bounds = gfx::ToEnclosingRect(
[email protected]ce112fe2012-10-29 22:52:181545 gfx::ScaleRect(bounds, device_scale_factor_));
[email protected]4889bd212013-02-11 22:23:101546
[email protected]ca4847f2010-09-24 05:39:151547 scoped_ptr<skia::PlatformCanvas> canvas(
[email protected]b4d08452010-10-05 17:34:351548 RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
[email protected]f1cccb32012-06-06 18:29:591549 pixel_bounds));
[email protected]59383c782013-04-17 16:43:271550 if (!canvas) {
[email protected]f98d7e3c2010-09-13 22:30:461551 NOTREACHED();
1552 return;
1553 }
[email protected]cef3362f2009-12-21 17:48:451554
[email protected]f98d7e3c2010-09-13 22:30:461555 // We may get back a smaller canvas than we asked for.
1556 // TODO(darin): This seems like it could cause painting problems!
[email protected]f1cccb32012-06-06 18:29:591557 DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width());
1558 DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height());
1559 pixel_bounds.set_width(canvas->getDevice()->width());
1560 pixel_bounds.set_height(canvas->getDevice()->height());
1561 bounds.set_width(pixel_bounds.width() / device_scale_factor_);
1562 bounds.set_height(pixel_bounds.height() / device_scale_factor_);
[email protected]53d3f302009-12-21 04:42:051563
[email protected]f98d7e3c2010-09-13 22:30:461564 HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size());
1565
[email protected]aa4117f2011-12-09 22:19:211566 pending_update_params_->bitmap = current_paint_buf_->id();
1567 pending_update_params_->bitmap_rect = bounds;
1568
1569 std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects;
[email protected]f98d7e3c2010-09-13 22:30:461570 // The scroll damage is just another rectangle to paint and copy.
1571 copy_rects.swap(update.paint_rects);
1572 if (!scroll_damage.IsEmpty())
1573 copy_rects.push_back(scroll_damage);
1574
[email protected]4889bd212013-02-11 22:23:101575 for (size_t i = 0; i < copy_rects.size(); ++i) {
1576 gfx::Rect rect = copy_rects[i];
1577 if (fractional_scale) {
1578 // Damage might not be DPI aligned. Inflate rect to compensate.
1579 rect.Inset(-1, -1);
1580 }
1581 PaintRect(rect, pixel_bounds.origin(), canvas.get());
1582 }
[email protected]60a50072012-01-11 02:05:351583
1584 // Software FPS tick for performance tests. The accelerated path traces the
1585 // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc.
1586 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421587 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW",
1588 TRACE_EVENT_SCOPE_THREAD);
[email protected]f98d7e3c2010-09-13 22:30:461589 } else { // Accelerated compositing path
1590 // Begin painting.
[email protected]aa4117f2011-12-09 22:19:211591 // If painting is done via the gpu process then we don't set any damage
1592 // rects to save the browser process from doing unecessary work.
1593 pending_update_params_->bitmap_rect = bounds;
1594 pending_update_params_->scroll_rect = gfx::Rect();
1595 // We don't need an ack, because we're not sharing a DIB with the browser.
1596 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1597 // with the browser for the GPU surface.
1598 pending_update_params_->needs_ack = false;
[email protected]f0c2a242013-03-15 19:34:521599 Composite(frame_begin_ticks);
[email protected]f98d7e3c2010-09-13 22:30:461600 }
1601
[email protected]936c6f52011-12-13 01:35:261602 // If we're holding a pending input event ACK, send the ACK before sending the
1603 // UpdateReply message so we can receive another input event before the
1604 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1605 // the UpdateRect IPC message handler.
[email protected]59383c782013-04-17 16:43:271606 if (pending_input_event_ack_)
[email protected]936c6f52011-12-13 01:35:261607 Send(pending_input_event_ack_.release());
1608
[email protected]ab543072013-01-25 04:38:151609 // If Composite() called SwapBuffers, pending_update_params_ will be reset (in
[email protected]aa4117f2011-12-09 22:19:211610 // OnSwapBuffersPosted), meaning a message has been added to the
1611 // updates_pending_swap_ queue, that will be sent later. Otherwise, we send
1612 // the message now.
[email protected]59383c782013-04-17 16:43:271613 if (pending_update_params_) {
[email protected]aa4117f2011-12-09 22:19:211614 // sending an ack to browser process that the paint is complete...
1615 update_reply_pending_ = pending_update_params_->needs_ack;
1616 Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_));
1617 pending_update_params_.reset();
[email protected]b167ca662010-05-14 00:05:341618 }
[email protected]53d3f302009-12-21 04:42:051619
[email protected]29ed96a2012-02-04 18:12:161620 // If we're software rendering then we're done initiating the paint.
1621 if (!is_accelerated_compositing_active_)
1622 DidInitiatePaint();
initial.commit09911bf2008-07-26 23:55:291623}
1624
[email protected]f0c2a242013-03-15 19:34:521625void RenderWidget::Composite(base::TimeTicks frame_begin_time) {
[email protected]ab543072013-01-25 04:38:151626 DCHECK(is_accelerated_compositing_active_);
[email protected]ba91a792013-02-06 09:48:281627 if (compositor_) // TODO(jamesr): Figure out how this can be null.
[email protected]f0c2a242013-03-15 19:34:521628 compositor_->Composite(frame_begin_time);
[email protected]ab543072013-01-25 04:38:151629}
1630
initial.commit09911bf2008-07-26 23:55:291631///////////////////////////////////////////////////////////////////////////////
[email protected]f98d7e3c2010-09-13 22:30:461632// WebWidgetClient
initial.commit09911bf2008-07-26 23:55:291633
[email protected]4873c7d2009-07-16 06:36:281634void RenderWidget::didInvalidateRect(const WebRect& rect) {
[email protected]552e6002009-11-19 05:24:571635 // The invalidated rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481636 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181637 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect);
[email protected]552e6002009-11-19 05:24:571638 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291639 return;
1640
[email protected]552e6002009-11-19 05:24:571641 paint_aggregator_.InvalidateRect(damaged_rect);
1642
1643 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241644 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571645 return;
1646 if (!paint_aggregator_.HasPendingUpdate())
1647 return;
[email protected]aa4117f2011-12-09 22:19:211648 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241649 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1650 return;
1651
1652 // When GPU rendering, combine pending animations and invalidations into
1653 // a single update.
[email protected]816edc62012-03-17 01:27:221654 if (is_accelerated_compositing_active_ &&
1655 animation_update_pending_ &&
1656 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571657 return;
1658
1659 // Perform updating asynchronously. This serves two purposes:
initial.commit09911bf2008-07-26 23:55:291660 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1661 // on the call stack.
1662 // 2) Allows us to collect more damage rects before painting to help coalesce
1663 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241664 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111665 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211666 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291667}
1668
[email protected]990278ff2012-11-13 02:12:551669void RenderWidget::didScrollRect(int dx, int dy,
1670 const WebRect& clip_rect) {
[email protected]f98d7e3c2010-09-13 22:30:461671 // Drop scrolls on the floor when we are in compositing mode.
1672 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
[email protected]a79d8a632010-11-18 22:35:561673 if (is_accelerated_compositing_active_)
[email protected]f98d7e3c2010-09-13 22:30:461674 return;
1675
[email protected]552e6002009-11-19 05:24:571676 // The scrolled rect might be outside the bounds of the view.
[email protected]ee8d6fd2010-05-26 17:05:481677 gfx::Rect view_rect(size_);
[email protected]ce112fe2012-10-29 22:52:181678 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect);
[email protected]552e6002009-11-19 05:24:571679 if (damaged_rect.IsEmpty())
initial.commit09911bf2008-07-26 23:55:291680 return;
1681
[email protected]990278ff2012-11-13 02:12:551682 paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect);
[email protected]552e6002009-11-19 05:24:571683
1684 // We may not need to schedule another call to DoDeferredUpdate.
[email protected]65225772011-05-12 21:10:241685 if (invalidation_task_posted_)
[email protected]552e6002009-11-19 05:24:571686 return;
1687 if (!paint_aggregator_.HasPendingUpdate())
1688 return;
[email protected]aa4117f2011-12-09 22:19:211689 if (update_reply_pending_ ||
[email protected]65225772011-05-12 21:10:241690 num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending)
1691 return;
1692
1693 // When GPU rendering, combine pending animations and invalidations into
1694 // a single update.
[email protected]816edc62012-03-17 01:27:221695 if (is_accelerated_compositing_active_ &&
1696 animation_update_pending_ &&
1697 animation_timer_.IsRunning())
[email protected]552e6002009-11-19 05:24:571698 return;
1699
1700 // Perform updating asynchronously. This serves two purposes:
1701 // 1) Ensures that we call WebView::Paint without a bunch of other junk
1702 // on the call stack.
1703 // 2) Allows us to collect more damage rects before painting to help coalesce
1704 // the work that we will need to do.
[email protected]65225772011-05-12 21:10:241705 invalidation_task_posted_ = true;
[email protected]dd32b1272013-05-04 14:17:111706 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211707 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this));
initial.commit09911bf2008-07-26 23:55:291708}
1709
[email protected]244ac1892011-12-02 17:04:471710void RenderWidget::didAutoResize(const WebSize& new_size) {
[email protected]ea3ee0a2012-05-15 03:43:091711 if (size_.width() != new_size.width || size_.height() != new_size.height) {
[email protected]eac2b362013-05-22 07:01:451712 size_ = new_size;
[email protected]20fbfc22013-05-08 20:50:581713
[email protected]eac2b362013-05-22 07:01:451714 // If we don't clear PaintAggregator after changing autoResize state, then
1715 // we might end up in a situation where bitmap_rect is larger than the
1716 // view_size. By clearing PaintAggregator, we ensure that we don't end up
1717 // with invalid damage rects.
1718 paint_aggregator_.ClearPendingUpdate();
1719
[email protected]70dee7e2013-05-29 18:28:301720 if (RenderThreadImpl::current()->layout_test_mode()) {
[email protected]eac2b362013-05-22 07:01:451721 WebRect new_pos(rootWindowRect().x,
1722 rootWindowRect().y,
1723 new_size.width,
1724 new_size.height);
1725 view_screen_rect_ = new_pos;
1726 window_screen_rect_ = new_pos;
[email protected]8be1c582013-03-06 00:55:031727 }
[email protected]20fbfc22013-05-08 20:50:581728
[email protected]eac2b362013-05-22 07:01:451729 AutoResizeCompositor();
[email protected]20fbfc22013-05-08 20:50:581730
[email protected]70dee7e2013-05-29 18:28:301731 if (!RenderThreadImpl::current()->layout_test_mode())
[email protected]20fbfc22013-05-08 20:50:581732 need_update_rect_for_auto_resize_ = true;
[email protected]ea3ee0a2012-05-15 03:43:091733 }
[email protected]244ac1892011-12-02 17:04:471734}
1735
[email protected]3a1c8a8032013-03-18 22:35:321736void RenderWidget::AutoResizeCompositor() {
[email protected]97e1bf72013-03-06 14:06:051737 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_,
1738 device_scale_factor_));
1739 if (compositor_)
1740 compositor_->setViewportSize(size_, physical_backing_size_);
1741}
1742
[email protected]91acd1c2012-03-14 08:32:391743void RenderWidget::didActivateCompositor(int input_handler_identifier) {
[email protected]ea162f92011-10-04 23:08:221744 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor");
1745
[email protected]c63b4d42012-04-26 01:01:071746#if !defined(OS_MACOSX)
[email protected]aa4117f2011-12-09 22:19:211747 if (!is_accelerated_compositing_active_) {
1748 // When not in accelerated compositing mode, in certain cases (e.g. waiting
1749 // for a resize or if no backing store) the RenderWidgetHost is blocking the
1750 // browser's UI thread for some time, waiting for an UpdateRect. If we are
1751 // going to switch to accelerated compositing, the GPU process may need
1752 // round-trips to the browser's UI thread before finishing the frame,
1753 // causing deadlocks if we delay the UpdateRect until we receive the
1754 // OnSwapBuffersComplete. So send a dummy message that will unblock the
[email protected]c63b4d42012-04-26 01:01:071755 // browser's UI thread. This is not necessary on Mac, because SwapBuffers
1756 // now unblocks GetBackingStore on Mac.
[email protected]aa4117f2011-12-09 22:19:211757 Send(new ViewHostMsg_UpdateIsDelayed(routing_id_));
1758 }
[email protected]c63b4d42012-04-26 01:01:071759#endif
[email protected]aa4117f2011-12-09 22:19:211760
[email protected]ea162f92011-10-04 23:08:221761 is_accelerated_compositing_active_ = true;
[email protected]50bd6452010-11-27 19:39:421762 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
[email protected]65225772011-05-12 21:10:241763 routing_id_, is_accelerated_compositing_active_));
[email protected]d8a6c5d12013-09-23 04:37:101764
1765 if (!was_accelerated_compositing_ever_active_) {
1766 was_accelerated_compositing_ever_active_ = true;
1767 webwidget_->enterForceCompositingMode(true);
1768 }
[email protected]ea162f92011-10-04 23:08:221769}
1770
1771void RenderWidget::didDeactivateCompositor() {
1772 TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor");
1773
1774 is_accelerated_compositing_active_ = false;
1775 Send(new ViewHostMsg_DidActivateAcceleratedCompositing(
1776 routing_id_, is_accelerated_compositing_active_));
1777
[email protected]ea162f92011-10-04 23:08:221778 if (using_asynchronous_swapbuffers_)
[email protected]65225772011-05-12 21:10:241779 using_asynchronous_swapbuffers_ = false;
[email protected]479b0172012-10-29 19:27:091780
1781 // In single-threaded mode, we exit force compositing mode and re-enter in
1782 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1783 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1784 // entering force compositing mode at the appropriate times.
[email protected]cb6430932012-10-31 00:53:361785 if (!is_threaded_compositing_enabled_)
[email protected]479b0172012-10-29 19:27:091786 webwidget_->enterForceCompositingMode(false);
[email protected]a79d8a632010-11-18 22:35:561787}
1788
[email protected]e195e582013-03-08 01:32:591789void RenderWidget::initializeLayerTreeView() {
[email protected]c5fa4c42013-07-20 05:47:371790 compositor_ = RenderWidgetCompositor::Create(
1791 this, is_threaded_compositing_enabled_);
[email protected]e195e582013-03-08 01:32:591792 if (!compositor_)
1793 return;
1794
1795 compositor_->setViewportSize(size_, physical_backing_size_);
1796 if (init_complete_)
1797 compositor_->setSurfaceReady();
1798}
1799
[email protected]8926c602013-01-23 05:32:061800WebKit::WebLayerTreeView* RenderWidget::layerTreeView() {
[email protected]ba91a792013-02-06 09:48:281801 return compositor_.get();
[email protected]8926c602013-01-23 05:32:061802}
1803
[email protected]9ed83fe2013-02-27 01:52:281804void RenderWidget::suppressCompositorScheduling(bool enable) {
1805 if (compositor_)
1806 compositor_->SetSuppressScheduleComposite(enable);
1807}
1808
[email protected]9cd43a62012-03-26 08:03:561809void RenderWidget::willBeginCompositorFrame() {
1810 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
[email protected]abe8b3a2012-03-28 21:19:371811
[email protected]cadac622013-06-11 16:46:361812 DCHECK(RenderThreadImpl::current()->compositor_message_loop_proxy().get());
[email protected]abe8b3a2012-03-28 21:19:371813
1814 // The following two can result in further layout and possibly
1815 // enable GPU acceleration so they need to be called before any painting
1816 // is done.
[email protected]cb9e2632013-06-18 11:26:471817 UpdateTextInputType();
1818#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:131819 UpdateTextInputState(false, true);
[email protected]cb9e2632013-06-18 11:26:471820#endif
[email protected]abe8b3a2012-03-28 21:19:371821 UpdateSelectionBounds();
[email protected]9cd43a62012-03-26 08:03:561822}
1823
[email protected]3391a0772012-03-28 00:32:071824void RenderWidget::didBecomeReadyForAdditionalInput() {
1825 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
[email protected]59383c782013-04-17 16:43:271826 if (pending_input_event_ack_)
[email protected]3391a0772012-03-28 00:32:071827 Send(pending_input_event_ack_.release());
1828}
1829
[email protected]6fceb912013-02-15 06:24:151830void RenderWidget::DidCommitCompositorFrame() {
1831}
1832
[email protected]58264a32011-11-17 23:36:151833void RenderWidget::didCommitAndDrawCompositorFrame() {
[email protected]b5db7eb2011-11-29 09:11:501834 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
[email protected]60a50072012-01-11 02:05:351835 // Accelerated FPS tick for performance tests. See throughput_tests.cc.
1836 // NOTE: Tests may break if this event is renamed or moved.
[email protected]c76faea2013-03-26 07:42:421837 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU",
1838 TRACE_EVENT_SCOPE_THREAD);
[email protected]29ed96a2012-02-04 18:12:161839 // Notify subclasses that we initiated the paint operation.
1840 DidInitiatePaint();
[email protected]58264a32011-11-17 23:36:151841}
1842
1843void RenderWidget::didCompleteSwapBuffers() {
[email protected]404939f2012-06-01 04:06:181844 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
1845
1846 // Notify subclasses threaded composited rendering was flushed to the screen.
[email protected]9cd43a62012-03-26 08:03:561847 DidFlushPaint();
1848
[email protected]aa4117f2011-12-09 22:19:211849 if (update_reply_pending_)
[email protected]58264a32011-11-17 23:36:151850 return;
1851
[email protected]ea3ee0a2012-05-15 03:43:091852 if (!next_paint_flags_ &&
1853 !need_update_rect_for_auto_resize_ &&
1854 !plugin_window_moves_.size()) {
[email protected]58264a32011-11-17 23:36:151855 return;
[email protected]ea3ee0a2012-05-15 03:43:091856 }
[email protected]58264a32011-11-17 23:36:151857
1858 ViewHostMsg_UpdateRect_Params params;
1859 params.view_size = size_;
[email protected]58264a32011-11-17 23:36:151860 params.plugin_window_moves.swap(plugin_window_moves_);
1861 params.flags = next_paint_flags_;
1862 params.scroll_offset = GetScrollOffset();
[email protected]b0dda9e22011-12-13 20:30:121863 params.needs_ack = false;
[email protected]7ded9f12012-06-13 20:47:091864 params.scale_factor = device_scale_factor_;
[email protected]58264a32011-11-17 23:36:151865
1866 Send(new ViewHostMsg_UpdateRect(routing_id_, params));
1867 next_paint_flags_ = 0;
[email protected]ea3ee0a2012-05-15 03:43:091868 need_update_rect_for_auto_resize_ = false;
[email protected]58264a32011-11-17 23:36:151869}
1870
[email protected]f98d7e3c2010-09-13 22:30:461871void RenderWidget::scheduleComposite() {
[email protected]7d08a9352013-10-15 08:24:561872 ScheduleCompositeImpl(false);
[email protected]f98d7e3c2010-09-13 22:30:461873}
1874
[email protected]5f8b1022011-01-21 23:34:501875void RenderWidget::scheduleAnimation() {
[email protected]ce65fb782012-04-19 05:01:201876 if (animation_update_pending_)
1877 return;
1878
[email protected]921244e42011-07-20 16:36:301879 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation");
[email protected]ce65fb782012-04-19 05:01:201880 animation_update_pending_ = true;
1881 if (!animation_timer_.IsRunning()) {
1882 animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this,
1883 &RenderWidget::AnimationCallback);
[email protected]ee3d3ad2011-02-04 00:42:211884 }
[email protected]5f8b1022011-01-21 23:34:501885}
1886
[email protected]4873c7d2009-07-16 06:36:281887void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) {
[email protected]7c51b0ee2009-07-08 21:49:301888 // TODO(darin): Eliminate this temporary.
[email protected]9ec87712013-05-24 23:23:521889 WebCursor cursor;
[email protected]953bd0062013-08-01 00:58:401890 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info);
initial.commit09911bf2008-07-26 23:55:291891 // Only send a SetCursor message if we need to make a change.
1892 if (!current_cursor_.IsEqual(cursor)) {
1893 current_cursor_ = cursor;
1894 Send(new ViewHostMsg_SetCursor(routing_id_, cursor));
1895 }
1896}
1897
1898// We are supposed to get a single call to Show for a newly created RenderWidget
1899// that was created via RenderWidget::CreateWebView. So, we wait until this
1900// point to dispatch the ShowWidget message.
1901//
1902// This method provides us with the information about how to display the newly
[email protected]5f9de5882011-09-30 23:36:281903// created RenderWidget (i.e., as a blocked popup or as a new tab).
initial.commit09911bf2008-07-26 23:55:291904//
[email protected]4873c7d2009-07-16 06:36:281905void RenderWidget::show(WebNavigationPolicy) {
initial.commit09911bf2008-07-26 23:55:291906 DCHECK(!did_show_) << "received extraneous Show call";
1907 DCHECK(routing_id_ != MSG_ROUTING_NONE);
1908 DCHECK(opener_id_ != MSG_ROUTING_NONE);
1909
[email protected]8de12d942010-11-17 20:42:441910 if (did_show_)
1911 return;
1912
1913 did_show_ = true;
1914 // NOTE: initial_pos_ may still have its default values at this point, but
1915 // that's okay. It'll be ignored if as_popup is false, or the browser
1916 // process will impose a default position otherwise.
1917 Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_));
1918 SetPendingWindowRect(initial_pos_);
initial.commit09911bf2008-07-26 23:55:291919}
1920
[email protected]9b003482013-05-21 14:00:171921void RenderWidget::didProgrammaticallyScroll(
1922 const WebKit::WebPoint& scroll_point) {
1923 if (!compositor_)
1924 return;
1925 Send(new ViewHostMsg_DidProgrammaticallyScroll(
1926 routing_id_, gfx::Vector2d(scroll_point.x, scroll_point.y)));
1927}
1928
[email protected]4873c7d2009-07-16 06:36:281929void RenderWidget::didFocus() {
initial.commit09911bf2008-07-26 23:55:291930}
1931
[email protected]4873c7d2009-07-16 06:36:281932void RenderWidget::didBlur() {
initial.commit09911bf2008-07-26 23:55:291933}
1934
[email protected]2533ce12009-05-09 00:02:241935void RenderWidget::DoDeferredClose() {
1936 Send(new ViewHostMsg_Close(routing_id_));
1937}
1938
[email protected]4873c7d2009-07-16 06:36:281939void RenderWidget::closeWidgetSoon() {
[email protected]e1c3a552012-05-04 20:51:321940 if (is_swapped_out_) {
1941 // This widget is currently swapped out, and the active widget is in a
1942 // different process. Have the browser route the close request to the
1943 // active widget instead, so that the correct unload handlers are run.
1944 Send(new ViewHostMsg_RouteCloseEvent(routing_id_));
1945 return;
1946 }
1947
initial.commit09911bf2008-07-26 23:55:291948 // If a page calls window.close() twice, we'll end up here twice, but that's
1949 // OK. It is safe to send multiple Close messages.
1950
[email protected]2533ce12009-05-09 00:02:241951 // Ask the RenderWidgetHost to initiate close. We could be called from deep
1952 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1953 // could be closed before the JS finishes executing. So instead, post a
1954 // message back to the message loop, which won't run until the JS is
1955 // complete, and then the Close message can be sent.
[email protected]dd32b1272013-05-04 14:17:111956 base::MessageLoop::current()->PostTask(
[email protected]32876ae2011-11-15 22:25:211957 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
initial.commit09911bf2008-07-26 23:55:291958}
1959
1960void RenderWidget::Close() {
1961 if (webwidget_) {
[email protected]8926c602013-01-23 05:32:061962 webwidget_->willCloseLayerTreeView();
[email protected]ba91a792013-02-06 09:48:281963 compositor_.reset();
[email protected]4873c7d2009-07-16 06:36:281964 webwidget_->close();
initial.commit09911bf2008-07-26 23:55:291965 webwidget_ = NULL;
1966 }
1967}
1968
[email protected]4873c7d2009-07-16 06:36:281969WebRect RenderWidget::windowRect() {
1970 if (pending_window_rect_count_)
1971 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:241972
[email protected]80ad8622012-11-07 16:33:031973 return view_screen_rect_;
initial.commit09911bf2008-07-26 23:55:291974}
1975
[email protected]8a9d6ca32011-06-06 20:11:301976void RenderWidget::setToolTipText(const WebKit::WebString& text,
1977 WebTextDirection hint) {
[email protected]5a395b72011-08-08 19:13:541978 Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint));
[email protected]8a9d6ca32011-06-06 20:11:301979}
1980
[email protected]b2e4c70132013-10-03 02:07:511981void RenderWidget::setWindowRect(const WebRect& rect) {
1982 WebRect pos = rect;
1983 if (popup_origin_scale_for_emulation_) {
1984 float scale = popup_origin_scale_for_emulation_;
1985 pos.x = popup_screen_origin_for_emulation_.x() +
1986 (pos.x - popup_view_origin_for_emulation_.x()) * scale;
1987 pos.y = popup_screen_origin_for_emulation_.y() +
1988 (pos.y - popup_view_origin_for_emulation_.y()) * scale;
1989 }
1990
[email protected]ec951b9d2013-10-20 06:21:201991 if (!RenderThreadImpl::current()->layout_test_mode()) {
1992 if (did_show_) {
[email protected]8be1c582013-03-06 00:55:031993 Send(new ViewHostMsg_RequestMove(routing_id_, pos));
1994 SetPendingWindowRect(pos);
1995 } else {
[email protected]ec951b9d2013-10-20 06:21:201996 initial_pos_ = pos;
[email protected]8be1c582013-03-06 00:55:031997 }
initial.commit09911bf2008-07-26 23:55:291998 } else {
[email protected]ec951b9d2013-10-20 06:21:201999 WebSize new_size(pos.width, pos.height);
2000 Resize(new_size, new_size, overdraw_bottom_height_,
2001 WebRect(), is_fullscreen_, NO_RESIZE_ACK);
2002 view_screen_rect_ = pos;
2003 window_screen_rect_ = pos;
2004 if (!did_show_)
2005 initial_pos_ = pos;
initial.commit09911bf2008-07-26 23:55:292006 }
2007}
2008
[email protected]2533ce12009-05-09 00:02:242009void RenderWidget::SetPendingWindowRect(const WebRect& rect) {
2010 pending_window_rect_ = rect;
2011 pending_window_rect_count_++;
2012}
2013
[email protected]4873c7d2009-07-16 06:36:282014WebRect RenderWidget::rootWindowRect() {
[email protected]2533ce12009-05-09 00:02:242015 if (pending_window_rect_count_) {
2016 // NOTE(mbelshe): If there is a pending_window_rect_, then getting
2017 // the RootWindowRect is probably going to return wrong results since the
2018 // browser may not have processed the Move yet. There isn't really anything
2019 // good to do in this case, and it shouldn't happen - since this size is
2020 // only really needed for windowToScreen, which is only used for Popups.
[email protected]4873c7d2009-07-16 06:36:282021 return pending_window_rect_;
[email protected]2533ce12009-05-09 00:02:242022 }
2023
[email protected]80ad8622012-11-07 16:33:032024 return window_screen_rect_;
[email protected]d4547452008-08-28 18:36:372025}
2026
[email protected]4873c7d2009-07-16 06:36:282027WebRect RenderWidget::windowResizerRect() {
2028 return resizer_rect_;
[email protected]c04b6362008-11-21 18:54:192029}
2030
[email protected]fa7b1dc2010-06-23 17:53:042031void RenderWidget::OnSetInputMethodActive(bool is_active) {
[email protected]c4bb35a2008-10-31 17:54:032032 // To prevent this renderer process from sending unnecessary IPC messages to
2033 // a browser process, we permit the renderer process to send IPC messages
[email protected]fa7b1dc2010-06-23 17:53:042034 // only during the input method attached to the browser process is active.
2035 input_method_is_active_ = is_active;
initial.commit09911bf2008-07-26 23:55:292036}
2037
[email protected]fa7b1dc2010-06-23 17:53:042038void RenderWidget::OnImeSetComposition(
2039 const string16& text,
2040 const std::vector<WebCompositionUnderline>& underlines,
2041 int selection_start, int selection_end) {
[email protected]0d1ebed12013-08-05 22:01:132042 if (!ShouldHandleImeEvent())
[email protected]4873c7d2009-07-16 06:36:282043 return;
[email protected]66fca5bc2013-05-23 06:58:292044 ImeEventGuard guard(this);
[email protected]88dbe32f2013-06-20 23:31:362045 if (!webwidget_->setComposition(
[email protected]fa7b1dc2010-06-23 17:53:042046 text, WebVector<WebCompositionUnderline>(underlines),
2047 selection_start, selection_end)) {
2048 // If we failed to set the composition text, then we need to let the browser
2049 // process to cancel the input method's ongoing composition session, to make
2050 // sure we are in a consistent state.
2051 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
[email protected]7f00efa2010-04-15 05:01:262052 }
[email protected]501ea13d2013-07-09 17:03:292053#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
[email protected]88dbe32f2013-06-20 23:31:362054 UpdateCompositionInfo(true);
[email protected]501ea13d2013-07-09 17:03:292055#endif
[email protected]fa7b1dc2010-06-23 17:53:042056}
2057
[email protected]0e45bd02013-07-12 20:20:022058void RenderWidget::OnImeConfirmComposition(const string16& text,
[email protected]db4fc1e2013-09-06 20:01:512059 const gfx::Range& replacement_range,
[email protected]0e45bd02013-07-12 20:20:022060 bool keep_selection) {
[email protected]0d1ebed12013-08-05 22:01:132061 if (!ShouldHandleImeEvent())
[email protected]d0be63772011-12-20 23:18:042062 return;
[email protected]66fca5bc2013-05-23 06:58:292063 ImeEventGuard guard(this);
[email protected]d0be63772011-12-20 23:18:042064 handling_input_event_ = true;
[email protected]0e45bd02013-07-12 20:20:022065 if (text.length())
2066 webwidget_->confirmComposition(text);
2067 else if (keep_selection)
2068 webwidget_->confirmComposition(WebWidget::KeepSelection);
2069 else
2070 webwidget_->confirmComposition(WebWidget::DoNotKeepSelection);
[email protected]d0be63772011-12-20 23:18:042071 handling_input_event_ = false;
[email protected]501ea13d2013-07-09 17:03:292072#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
[email protected]88dbe32f2013-06-20 23:31:362073 UpdateCompositionInfo(true);
[email protected]501ea13d2013-07-09 17:03:292074#endif
initial.commit09911bf2008-07-26 23:55:292075}
2076
[email protected]948f7ab72010-05-28 23:48:082077// This message causes the renderer to render an image of the
2078// desired_size, regardless of whether the tab is hidden or not.
[email protected]3d9ec5052013-01-02 22:05:252079void RenderWidget::OnPaintAtSize(const TransportDIB::Handle& dib_handle,
2080 int tag,
2081 const gfx::Size& page_size,
2082 const gfx::Size& desired_size) {
[email protected]27543452011-03-25 00:14:002083 if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) {
2084 if (TransportDIB::is_valid_handle(dib_handle)) {
[email protected]45c6aad32010-11-11 04:46:252085 // Close our unused handle.
2086#if defined(OS_WIN)
2087 ::CloseHandle(dib_handle);
2088#elif defined(OS_MACOSX)
2089 base::SharedMemory::CloseHandle(dib_handle);
2090#endif
2091 }
[email protected]d65adb12010-04-28 17:26:492092 return;
[email protected]45c6aad32010-11-11 04:46:252093 }
[email protected]d65adb12010-04-28 17:26:492094
[email protected]948f7ab72010-05-28 23:48:082095 if (page_size.IsEmpty() || desired_size.IsEmpty()) {
[email protected]d65adb12010-04-28 17:26:492096 // If one of these is empty, then we just return the dib we were
2097 // given, to avoid leaking it.
[email protected]c88c9442010-07-19 18:55:092098 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
[email protected]d65adb12010-04-28 17:26:492099 return;
2100 }
2101
2102 // Map the given DIB ID into this process, and unmap it at the end
2103 // of this function.
[email protected]45c6aad32010-11-11 04:46:252104 scoped_ptr<TransportDIB> paint_at_size_buffer(
2105 TransportDIB::CreateWithHandle(dib_handle));
[email protected]36808ad2010-10-20 19:18:302106
[email protected]4b01b962012-10-09 23:17:352107 gfx::Size page_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:282108 gfx::ScaleSize(page_size, device_scale_factor_));
[email protected]4b01b962012-10-09 23:17:352109 gfx::Size desired_size_in_pixel = gfx::ToFlooredSize(
[email protected]01a15a72012-11-10 09:34:282110 gfx::ScaleSize(desired_size, device_scale_factor_));
[email protected]8f640512012-08-07 23:52:512111 gfx::Size canvas_size = page_size_in_pixel;
2112 float x_scale = static_cast<float>(desired_size_in_pixel.width()) /
[email protected]d65adb12010-04-28 17:26:492113 static_cast<float>(canvas_size.width());
[email protected]8f640512012-08-07 23:52:512114 float y_scale = static_cast<float>(desired_size_in_pixel.height()) /
[email protected]d65adb12010-04-28 17:26:492115 static_cast<float>(canvas_size.height());
2116
[email protected]ee8d6fd2010-05-26 17:05:482117 gfx::Rect orig_bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:492118 canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale));
2119 canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale));
[email protected]ee8d6fd2010-05-26 17:05:482120 gfx::Rect bounds(canvas_size);
[email protected]d65adb12010-04-28 17:26:492121
[email protected]36808ad2010-10-20 19:18:302122 scoped_ptr<skia::PlatformCanvas> canvas(
2123 paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(),
2124 canvas_size.height()));
[email protected]59383c782013-04-17 16:43:272125 if (!canvas) {
[email protected]36808ad2010-10-20 19:18:302126 NOTREACHED();
2127 return;
2128 }
2129
[email protected]d65adb12010-04-28 17:26:492130 // Reset bounds to what we actually received, but they should be the
2131 // same.
2132 DCHECK_EQ(bounds.width(), canvas->getDevice()->width());
2133 DCHECK_EQ(bounds.height(), canvas->getDevice()->height());
2134 bounds.set_width(canvas->getDevice()->width());
2135 bounds.set_height(canvas->getDevice()->height());
2136
2137 canvas->save();
[email protected]948f7ab72010-05-28 23:48:082138 // Add the scale factor to the canvas, so that we'll get the desired size.
[email protected]d65adb12010-04-28 17:26:492139 canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale));
2140
[email protected]948f7ab72010-05-28 23:48:082141 // Have to make sure we're laid out at the right size before
2142 // rendering.
2143 gfx::Size old_size = webwidget_->size();
2144 webwidget_->resize(page_size);
2145 webwidget_->layout();
2146
[email protected]d65adb12010-04-28 17:26:492147 // Paint the entire thing (using original bounds, not scaled bounds).
2148 PaintRect(orig_bounds, orig_bounds.origin(), canvas.get());
2149 canvas->restore();
2150
[email protected]948f7ab72010-05-28 23:48:082151 // Return the widget to its previous size.
2152 webwidget_->resize(old_size);
2153
[email protected]c88c9442010-07-19 18:55:092154 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
[email protected]d65adb12010-04-28 17:26:492155}
2156
[email protected]51a49502013-03-23 01:50:192157void RenderWidget::OnSnapshot(const gfx::Rect& src_subrect) {
2158 SkBitmap snapshot;
2159
2160 if (OnSnapshotHelper(src_subrect, &snapshot)) {
2161 Send(new ViewHostMsg_Snapshot(routing_id(), true, snapshot));
2162 } else {
2163 Send(new ViewHostMsg_Snapshot(routing_id(), false, SkBitmap()));
2164 }
2165}
2166
2167bool RenderWidget::OnSnapshotHelper(const gfx::Rect& src_subrect,
2168 SkBitmap* snapshot) {
2169 base::TimeTicks beginning_time = base::TimeTicks::Now();
2170
2171 if (!webwidget_ || src_subrect.IsEmpty())
2172 return false;
2173
2174 gfx::Rect viewport_size = gfx::IntersectRects(
2175 src_subrect, gfx::Rect(physical_backing_size_));
2176
2177 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(
2178 skia::CreatePlatformCanvas(viewport_size.width(),
2179 viewport_size.height(),
2180 true,
2181 NULL,
2182 skia::RETURN_NULL_ON_FAILURE));
[email protected]59383c782013-04-17 16:43:272183 if (!canvas)
[email protected]51a49502013-03-23 01:50:192184 return false;
2185
2186 canvas->save();
2187 webwidget_->layout();
2188
2189 PaintRect(viewport_size, viewport_size.origin(), canvas.get());
2190 canvas->restore();
2191
2192 const SkBitmap& bitmap = skia::GetTopDevice(*canvas)->accessBitmap(false);
2193 if (!bitmap.copyTo(snapshot, SkBitmap::kARGB_8888_Config))
2194 return false;
2195
2196 UMA_HISTOGRAM_TIMES("Renderer4.Snapshot",
2197 base::TimeTicks::Now() - beginning_time);
2198 return true;
2199}
2200
[email protected]0bc1f572013-04-17 01:46:312201void RenderWidget::OnRepaint(gfx::Size size_to_paint) {
[email protected]ec7dc112008-08-06 05:30:122202 // During shutdown we can just ignore this message.
2203 if (!webwidget_)
2204 return;
2205
[email protected]0bc1f572013-04-17 01:46:312206 // Even if the browser provides an empty damage rect, it's still expecting to
2207 // receive a repaint ack so just damage the entire widget bounds.
2208 if (size_to_paint.IsEmpty()) {
2209 size_to_paint = size_;
2210 }
2211
[email protected]ec7dc112008-08-06 05:30:122212 set_next_paint_is_repaint_ack();
[email protected]0bc1f572013-04-17 01:46:312213 if (is_accelerated_compositing_active_ && compositor_) {
2214 compositor_->SetNeedsRedrawRect(gfx::Rect(size_to_paint));
[email protected]f98d7e3c2010-09-13 22:30:462215 } else {
2216 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
2217 didInvalidateRect(repaint_rect);
2218 }
[email protected]ec7dc112008-08-06 05:30:122219}
2220
[email protected]79fa22e2013-08-23 15:18:122221void RenderWidget::OnSyntheticGestureCompleted() {
2222 pending_synthetic_gesture_.Run();
[email protected]0e241b4b2012-08-18 09:06:272223}
2224
[email protected]4873c7d2009-07-16 06:36:282225void RenderWidget::OnSetTextDirection(WebTextDirection direction) {
[email protected]07f953332009-03-25 04:31:112226 if (!webwidget_)
2227 return;
[email protected]4873c7d2009-07-16 06:36:282228 webwidget_->setTextDirection(direction);
[email protected]07f953332009-03-25 04:31:112229}
2230
[email protected]80ad8622012-11-07 16:33:032231void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect,
2232 const gfx::Rect& window_screen_rect) {
[email protected]b2e4c70132013-10-03 02:07:512233 if (screen_metrics_emulator_) {
2234 screen_metrics_emulator_->OnUpdateScreenRectsMessage(
2235 view_screen_rect, window_screen_rect);
2236 } else {
2237 view_screen_rect_ = view_screen_rect;
2238 window_screen_rect_ = window_screen_rect;
2239 }
[email protected]80ad8622012-11-07 16:33:032240 Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id()));
2241}
2242
[email protected]105dffb42013-02-20 03:46:212243#if defined(OS_ANDROID)
[email protected]2384b6c2013-02-28 23:58:512244void RenderWidget::OnShowImeIfNeeded() {
[email protected]0d1ebed12013-08-05 22:01:132245 UpdateTextInputState(true, true);
2246}
2247
2248void RenderWidget::IncrementOutstandingImeEventAcks() {
2249 ++outstanding_ime_acks_;
2250}
2251
2252void RenderWidget::OnImeEventAck() {
2253 --outstanding_ime_acks_;
2254 DCHECK(outstanding_ime_acks_ >= 0);
[email protected]2384b6c2013-02-28 23:58:512255}
[email protected]105dffb42013-02-20 03:46:212256#endif
2257
[email protected]0d1ebed12013-08-05 22:01:132258bool RenderWidget::ShouldHandleImeEvent() {
2259#if defined(OS_ANDROID)
2260 return !!webwidget_ && outstanding_ime_acks_ == 0;
2261#else
2262 return !!webwidget_;
2263#endif
2264}
2265
[email protected]468ac582012-11-20 00:53:192266void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) {
2267 if (device_scale_factor_ == device_scale_factor)
2268 return;
2269
2270 device_scale_factor_ = device_scale_factor;
2271
2272 if (!is_accelerated_compositing_active_) {
2273 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
2274 } else {
2275 scheduleComposite();
2276 }
2277}
2278
[email protected]adab2332013-07-25 18:04:322279PepperPluginInstanceImpl* RenderWidget::GetBitmapForOptimizedPluginPaint(
2280 const gfx::Rect& paint_bounds,
2281 TransportDIB** dib,
2282 gfx::Rect* location,
2283 gfx::Rect* clip,
2284 float* scale_factor) {
[email protected]719b36f2010-12-22 20:36:462285 // Bare RenderWidgets don't support optimized plugin painting.
2286 return NULL;
[email protected]ca4847f2010-09-24 05:39:152287}
2288
[email protected]ceb36f7d2012-10-31 18:33:242289gfx::Vector2d RenderWidget::GetScrollOffset() {
[email protected]d54169e92011-01-21 09:19:522290 // Bare RenderWidgets don't support scroll offset.
[email protected]ceb36f7d2012-10-31 18:33:242291 return gfx::Vector2d();
[email protected]d54169e92011-01-21 09:19:522292}
2293
[email protected]bee16aab2009-08-26 15:55:032294void RenderWidget::SetHidden(bool hidden) {
2295 if (is_hidden_ == hidden)
2296 return;
2297
2298 // The status has changed. Tell the RenderThread about it.
2299 is_hidden_ = hidden;
2300 if (is_hidden_)
[email protected]380244092011-10-07 17:26:272301 RenderThread::Get()->WidgetHidden();
[email protected]bee16aab2009-08-26 15:55:032302 else
[email protected]380244092011-10-07 17:26:272303 RenderThread::Get()->WidgetRestored();
[email protected]bee16aab2009-08-26 15:55:032304}
2305
[email protected]2b624c562011-10-27 22:58:262306void RenderWidget::WillToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262307 if (!webwidget_)
2308 return;
2309
2310 if (is_fullscreen_) {
2311 webwidget_->willExitFullScreen();
2312 } else {
2313 webwidget_->willEnterFullScreen();
2314 }
[email protected]2b624c562011-10-27 22:58:262315}
2316
2317void RenderWidget::DidToggleFullscreen() {
[email protected]2b624c562011-10-27 22:58:262318 if (!webwidget_)
2319 return;
2320
2321 if (is_fullscreen_) {
2322 webwidget_->didEnterFullScreen();
2323 } else {
2324 webwidget_->didExitFullScreen();
2325 }
[email protected]2b624c562011-10-27 22:58:262326}
2327
[email protected]699ab0d2009-04-23 23:19:142328void RenderWidget::SetBackground(const SkBitmap& background) {
2329 background_ = background;
[email protected]f98d7e3c2010-09-13 22:30:462330
[email protected]699ab0d2009-04-23 23:19:142331 // Generate a full repaint.
[email protected]4873c7d2009-07-16 06:36:282332 didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
[email protected]699ab0d2009-04-23 23:19:142333}
2334
[email protected]674741932009-02-04 23:44:462335bool RenderWidget::next_paint_is_resize_ack() const {
[email protected]53d3f302009-12-21 04:42:052336 return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462337}
2338
2339bool RenderWidget::next_paint_is_restore_ack() const {
[email protected]53d3f302009-12-21 04:42:052340 return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_);
[email protected]674741932009-02-04 23:44:462341}
2342
2343void RenderWidget::set_next_paint_is_resize_ack() {
[email protected]53d3f302009-12-21 04:42:052344 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK;
[email protected]674741932009-02-04 23:44:462345}
2346
2347void RenderWidget::set_next_paint_is_restore_ack() {
[email protected]53d3f302009-12-21 04:42:052348 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK;
[email protected]674741932009-02-04 23:44:462349}
2350
2351void RenderWidget::set_next_paint_is_repaint_ack() {
[email protected]53d3f302009-12-21 04:42:052352 next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK;
[email protected]674741932009-02-04 23:44:462353}
2354
[email protected]b18583c2012-12-18 06:55:272355static bool IsDateTimeInput(ui::TextInputType type) {
2356 return type == ui::TEXT_INPUT_TYPE_DATE ||
2357 type == ui::TEXT_INPUT_TYPE_DATE_TIME ||
2358 type == ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL ||
2359 type == ui::TEXT_INPUT_TYPE_MONTH ||
2360 type == ui::TEXT_INPUT_TYPE_TIME ||
2361 type == ui::TEXT_INPUT_TYPE_WEEK;
2362}
2363
[email protected]66fca5bc2013-05-23 06:58:292364
2365void RenderWidget::StartHandlingImeEvent() {
2366 DCHECK(!handling_ime_event_);
2367 handling_ime_event_ = true;
2368}
2369
2370void RenderWidget::FinishHandlingImeEvent() {
2371 DCHECK(handling_ime_event_);
2372 handling_ime_event_ = false;
2373 // While handling an ime event, text input state and selection bounds updates
2374 // are ignored. These must explicitly be updated once finished handling the
2375 // ime event.
2376 UpdateSelectionBounds();
[email protected]cb9e2632013-06-18 11:26:472377#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:132378 UpdateTextInputState(false, false);
[email protected]cb9e2632013-06-18 11:26:472379#endif
[email protected]66fca5bc2013-05-23 06:58:292380}
2381
[email protected]cb9e2632013-06-18 11:26:472382void RenderWidget::UpdateTextInputType() {
[email protected]11f22bb62013-09-24 04:59:062383 // On Windows, not only an IME but also an on-screen keyboard relies on the
2384 // latest TextInputType to optimize its layout and functionality. Thus
2385 // |input_method_is_active_| is no longer an appropriate condition to suppress
2386 // TextInputTypeChanged IPC on Windows.
2387 // TODO(yukawa, yoichio): Consider to stop checking |input_method_is_active_|
2388 // on other platforms as well as Windows if the overhead is acceptable.
2389#if !defined(OS_WIN)
[email protected]cb9e2632013-06-18 11:26:472390 if (!input_method_is_active_)
2391 return;
[email protected]11f22bb62013-09-24 04:59:062392#endif
[email protected]cb9e2632013-06-18 11:26:472393
[email protected]e7c569d2013-07-17 16:00:362394 ui::TextInputType new_type = GetTextInputType();
[email protected]cb9e2632013-06-18 11:26:472395 if (IsDateTimeInput(new_type))
2396 return; // Not considered as a text input field in WebKit/Chromium.
2397
2398 bool new_can_compose_inline = CanComposeInline();
2399
[email protected]e7c569d2013-07-17 16:00:362400 WebKit::WebTextInputInfo new_info;
2401 if (webwidget_)
2402 new_info = webwidget_->textInputInfo();
[email protected]b256eca2013-07-11 10:57:402403 const ui::TextInputMode new_mode = ConvertInputMode(new_info.inputMode);
2404
[email protected]cb9e2632013-06-18 11:26:472405 if (text_input_type_ != new_type
[email protected]b256eca2013-07-11 10:57:402406 || can_compose_inline_ != new_can_compose_inline
2407 || text_input_mode_ != new_mode) {
[email protected]cb9e2632013-06-18 11:26:472408 Send(new ViewHostMsg_TextInputTypeChanged(routing_id(),
2409 new_type,
[email protected]86ba5fcb2013-09-04 00:36:532410 new_mode,
2411 new_can_compose_inline));
[email protected]cb9e2632013-06-18 11:26:472412 text_input_type_ = new_type;
2413 can_compose_inline_ = new_can_compose_inline;
[email protected]b256eca2013-07-11 10:57:402414 text_input_mode_ = new_mode;
[email protected]cb9e2632013-06-18 11:26:472415 }
2416}
2417
2418#if defined(OS_ANDROID)
[email protected]0d1ebed12013-08-05 22:01:132419void RenderWidget::UpdateTextInputState(bool show_ime_if_needed,
2420 bool send_ime_ack) {
[email protected]e8f775f2013-02-14 21:00:502421 if (handling_ime_event_)
2422 return;
[email protected]3306f262012-09-21 19:20:422423 if (!show_ime_if_needed && !input_method_is_active_)
initial.commit09911bf2008-07-26 23:55:292424 return;
[email protected]ad26ef42011-06-17 07:59:452425 ui::TextInputType new_type = GetTextInputType();
[email protected]b18583c2012-12-18 06:55:272426 if (IsDateTimeInput(new_type))
2427 return; // Not considered as a text input field in WebKit/Chromium.
2428
[email protected]5b739cb2012-08-21 20:35:212429 WebKit::WebTextInputInfo new_info;
2430 if (webwidget_)
2431 new_info = webwidget_->textInputInfo();
2432
[email protected]ad26ef42011-06-17 07:59:452433 bool new_can_compose_inline = CanComposeInline();
[email protected]5b739cb2012-08-21 20:35:212434
[email protected]3306f262012-09-21 19:20:422435 // Only sends text input params if they are changed or if the ime should be
2436 // shown.
2437 if (show_ime_if_needed || (text_input_type_ != new_type
2438 || text_input_info_ != new_info
2439 || can_compose_inline_ != new_can_compose_inline)) {
[email protected]5b739cb2012-08-21 20:35:212440 ViewHostMsg_TextInputState_Params p;
2441 p.type = new_type;
2442 p.value = new_info.value.utf8();
2443 p.selection_start = new_info.selectionStart;
2444 p.selection_end = new_info.selectionEnd;
2445 p.composition_start = new_info.compositionStart;
2446 p.composition_end = new_info.compositionEnd;
2447 p.can_compose_inline = new_can_compose_inline;
[email protected]3306f262012-09-21 19:20:422448 p.show_ime_if_needed = show_ime_if_needed;
[email protected]0d1ebed12013-08-05 22:01:132449 p.require_ack = send_ime_ack;
2450 if (p.require_ack)
2451 IncrementOutstandingImeEventAcks();
[email protected]5b739cb2012-08-21 20:35:212452 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p));
2453
2454 text_input_info_ = new_info;
[email protected]fa7b1dc2010-06-23 17:53:042455 text_input_type_ = new_type;
[email protected]ad26ef42011-06-17 07:59:452456 can_compose_inline_ = new_can_compose_inline;
initial.commit09911bf2008-07-26 23:55:292457 }
initial.commit09911bf2008-07-26 23:55:292458}
[email protected]cb9e2632013-06-18 11:26:472459#endif
initial.commit09911bf2008-07-26 23:55:292460
[email protected]7c8873e2013-02-05 08:03:012461void RenderWidget::GetSelectionBounds(gfx::Rect* focus, gfx::Rect* anchor) {
2462 WebRect focus_webrect;
2463 WebRect anchor_webrect;
2464 webwidget_->selectionBounds(focus_webrect, anchor_webrect);
2465 *focus = focus_webrect;
2466 *anchor = anchor_webrect;
[email protected]73bf95812011-10-12 11:38:322467}
2468
[email protected]e99ef6f2011-10-16 01:13:002469void RenderWidget::UpdateSelectionBounds() {
2470 if (!webwidget_)
2471 return;
[email protected]66fca5bc2013-05-23 06:58:292472 if (handling_ime_event_)
2473 return;
[email protected]e99ef6f2011-10-16 01:13:002474
[email protected]7c8873e2013-02-05 08:03:012475 ViewHostMsg_SelectionBounds_Params params;
2476 GetSelectionBounds(&params.anchor_rect, &params.focus_rect);
2477 if (selection_anchor_rect_ != params.anchor_rect ||
2478 selection_focus_rect_ != params.focus_rect) {
2479 selection_anchor_rect_ = params.anchor_rect;
2480 selection_focus_rect_ = params.focus_rect;
2481 webwidget_->selectionTextDirection(params.focus_dir, params.anchor_dir);
[email protected]129b7382013-02-12 02:14:292482 params.is_anchor_first = webwidget_->isSelectionAnchorFirst();
[email protected]7c8873e2013-02-05 08:03:012483 Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, params));
[email protected]58b48a0d2012-06-13 07:01:352484 }
[email protected]501ea13d2013-07-09 17:03:292485#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
[email protected]88dbe32f2013-06-20 23:31:362486 UpdateCompositionInfo(false);
[email protected]501ea13d2013-07-09 17:03:292487#endif
[email protected]e99ef6f2011-10-16 01:13:002488}
2489
[email protected]73bf95812011-10-12 11:38:322490// Check WebKit::WebTextInputType and ui::TextInputType is kept in sync.
[email protected]ad26ef42011-06-17 07:59:452491COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \
2492 int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums);
2493COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \
2494 int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums);
2495COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \
2496 int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums);
[email protected]caf38ed2011-07-28 13:15:182497COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \
2498 int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums);
2499COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \
2500 int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums);
2501COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \
2502 int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums);
2503COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \
2504 int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums);
2505COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \
2506 int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums);
[email protected]feb8cf752012-06-08 04:48:002507COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \
2508 int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum);
2509COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \
2510 int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum);
2511COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \
2512 int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum);
2513COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \
2514 int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum);
2515COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \
2516 int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum);
2517COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \
2518 int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum);
[email protected]2a9893672012-11-09 20:33:012519COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \
2520 int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums);
2521COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \
2522 int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums);
[email protected]8b4992e2013-03-01 15:42:152523COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeField) == \
2524 int(ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD), mismatching_enums);
[email protected]ad26ef42011-06-17 07:59:452525
[email protected]5b739cb2012-08-21 20:35:212526ui::TextInputType RenderWidget::WebKitToUiTextInputType(
2527 WebKit::WebTextInputType type) {
2528 // Check the type is in the range representable by ui::TextInputType.
2529 DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) <<
2530 "WebKit::WebTextInputType and ui::TextInputType not synchronized";
2531 return static_cast<ui::TextInputType>(type);
2532}
2533
[email protected]ad26ef42011-06-17 07:59:452534ui::TextInputType RenderWidget::GetTextInputType() {
[email protected]8969bb3f2012-11-30 21:49:272535 if (webwidget_)
2536 return WebKitToUiTextInputType(webwidget_->textInputInfo().type);
[email protected]ad26ef42011-06-17 07:59:452537 return ui::TEXT_INPUT_TYPE_NONE;
2538}
2539
[email protected]501ea13d2013-07-09 17:03:292540#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
2541void RenderWidget::UpdateCompositionInfo(bool should_update_range) {
[email protected]db4fc1e2013-09-06 20:01:512542 gfx::Range range = gfx::Range();
[email protected]501ea13d2013-07-09 17:03:292543 if (should_update_range) {
2544 GetCompositionRange(&range);
2545 } else {
2546 range = composition_range_;
2547 }
2548 std::vector<gfx::Rect> character_bounds;
2549 GetCompositionCharacterBounds(&character_bounds);
2550
2551 if (!ShouldUpdateCompositionInfo(range, character_bounds))
2552 return;
2553 composition_character_bounds_ = character_bounds;
2554 composition_range_ = range;
2555 Send(new ViewHostMsg_ImeCompositionRangeChanged(
2556 routing_id(), composition_range_, composition_character_bounds_));
2557}
2558
[email protected]58b48a0d2012-06-13 07:01:352559void RenderWidget::GetCompositionCharacterBounds(
2560 std::vector<gfx::Rect>* bounds) {
2561 DCHECK(bounds);
2562 bounds->clear();
2563}
2564
[email protected]db4fc1e2013-09-06 20:01:512565void RenderWidget::GetCompositionRange(gfx::Range* range) {
[email protected]88dbe32f2013-06-20 23:31:362566 size_t location, length;
2567 if (webwidget_->compositionRange(&location, &length)) {
2568 range->set_start(location);
2569 range->set_end(location + length);
2570 } else if (webwidget_->caretOrSelectionRange(&location, &length)) {
2571 range->set_start(location);
2572 range->set_end(location + length);
2573 } else {
[email protected]db4fc1e2013-09-06 20:01:512574 *range = gfx::Range::InvalidRange();
[email protected]88dbe32f2013-06-20 23:31:362575 }
2576}
2577
[email protected]501ea13d2013-07-09 17:03:292578bool RenderWidget::ShouldUpdateCompositionInfo(
[email protected]db4fc1e2013-09-06 20:01:512579 const gfx::Range& range,
[email protected]501ea13d2013-07-09 17:03:292580 const std::vector<gfx::Rect>& bounds) {
2581 if (composition_range_ != range)
2582 return true;
2583 if (bounds.size() != composition_character_bounds_.size())
2584 return true;
2585 for (size_t i = 0; i < bounds.size(); ++i) {
2586 if (bounds[i] != composition_character_bounds_[i])
2587 return true;
2588 }
2589 return false;
2590}
2591#endif
2592
[email protected]ad26ef42011-06-17 07:59:452593bool RenderWidget::CanComposeInline() {
2594 return true;
[email protected]56ea1a62011-05-30 07:05:572595}
2596
[email protected]4873c7d2009-07-16 06:36:282597WebScreenInfo RenderWidget::screenInfo() {
[email protected]842f10652012-06-06 01:54:042598 return screen_info_;
[email protected]4873c7d2009-07-16 06:36:282599}
2600
[email protected]f660d9c2012-06-06 18:31:212601float RenderWidget::deviceScaleFactor() {
2602 return device_scale_factor_;
2603}
2604
[email protected]fa7b1dc2010-06-23 17:53:042605void RenderWidget::resetInputMethod() {
2606 if (!input_method_is_active_)
2607 return;
2608
[email protected]0e45bd02013-07-12 20:20:022609 ImeEventGuard guard(this);
[email protected]fa7b1dc2010-06-23 17:53:042610 // If the last text input type is not None, then we should finish any
2611 // ongoing composition regardless of the new text input type.
[email protected]ad26ef42011-06-17 07:59:452612 if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) {
[email protected]fa7b1dc2010-06-23 17:53:042613 // If a composition text exists, then we need to let the browser process
2614 // to cancel the input method's ongoing composition session.
2615 if (webwidget_->confirmComposition())
2616 Send(new ViewHostMsg_ImeCancelComposition(routing_id()));
2617 }
[email protected]d4cff272011-05-02 15:46:012618
[email protected]501ea13d2013-07-09 17:03:292619#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
[email protected]88dbe32f2013-06-20 23:31:362620 UpdateCompositionInfo(true);
[email protected]501ea13d2013-07-09 17:03:292621#endif
[email protected]fa7b1dc2010-06-23 17:53:042622}
2623
[email protected]c68c3e4e2013-01-24 00:36:562624void RenderWidget::didHandleGestureEvent(
2625 const WebGestureEvent& event,
2626 bool event_cancelled) {
2627#if defined(OS_ANDROID)
2628 if (event_cancelled)
2629 return;
2630 if (event.type == WebInputEvent::GestureTap ||
2631 event.type == WebInputEvent::GestureLongPress) {
[email protected]0d1ebed12013-08-05 22:01:132632 UpdateTextInputState(true, true);
[email protected]c68c3e4e2013-01-24 00:36:562633 }
2634#endif
2635}
2636
[email protected]29e2fb42013-07-19 01:13:472637void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) {
initial.commit09911bf2008-07-26 23:55:292638 size_t i = 0;
2639 for (; i < plugin_window_moves_.size(); ++i) {
2640 if (plugin_window_moves_[i].window == move.window) {
[email protected]16f89d02009-08-26 17:17:582641 if (move.rects_valid) {
2642 plugin_window_moves_[i] = move;
2643 } else {
2644 plugin_window_moves_[i].visible = move.visible;
2645 }
initial.commit09911bf2008-07-26 23:55:292646 break;
2647 }
2648 }
2649
2650 if (i == plugin_window_moves_.size())
2651 plugin_window_moves_.push_back(move);
2652}
[email protected]268654772009-08-06 23:02:042653
2654void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) {
2655 for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin();
2656 i != plugin_window_moves_.end(); ++i) {
2657 if (i->window == window) {
2658 plugin_window_moves_.erase(i);
2659 break;
2660 }
2661 }
2662}
[email protected]67bfb83f2011-09-22 03:36:372663
[email protected]b63d58d2012-11-26 22:37:442664void RenderWidget::GetRenderingStats(
2665 WebKit::WebRenderingStatsImpl& stats) const {
[email protected]ba91a792013-02-06 09:48:282666 if (compositor_)
[email protected]635353c2013-03-06 09:11:202667 compositor_->GetRenderingStats(&stats.rendering_stats);
[email protected]b63d58d2012-11-26 22:37:442668
[email protected]c1e6cc062013-08-24 03:35:352669 stats.rendering_stats.Add(
2670 legacy_software_mode_stats_->GetRenderingStats());
[email protected]fef5e3972012-08-07 03:59:472671}
2672
[email protected]e9ff79c2012-10-19 21:31:262673bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const {
[email protected]63b465922012-09-06 02:04:522674 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel();
2675 if (!gpu_channel)
2676 return false;
2677
2678 return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats);
2679}
2680
[email protected]24ed0432013-04-24 07:50:312681RenderWidgetCompositor* RenderWidget::compositor() const {
2682 return compositor_.get();
2683}
2684
[email protected]3639aa82013-06-04 11:00:042685void RenderWidget::OnSetBrowserRenderingStats(
2686 const BrowserRenderingStats& stats) {
2687 browser_rendering_stats_ = stats;
2688}
2689
2690void RenderWidget::GetBrowserRenderingStats(BrowserRenderingStats* stats) {
2691 *stats = browser_rendering_stats_;
2692}
2693
[email protected]0c2ebef2013-04-03 12:14:102694void RenderWidget::BeginSmoothScroll(
[email protected]0e241b4b2012-08-18 09:06:272695 bool down,
[email protected]79fa22e2013-08-23 15:18:122696 const SyntheticGestureCompletionCallback& callback,
[email protected]267909d2012-10-20 04:36:192697 int pixels_to_scroll,
[email protected]ebd8b562012-10-09 14:44:292698 int mouse_event_x,
2699 int mouse_event_y) {
[email protected]0e241b4b2012-08-18 09:06:272700 DCHECK(!callback.is_null());
[email protected]267909d2012-10-20 04:36:192701
2702 ViewHostMsg_BeginSmoothScroll_Params params;
2703 params.scroll_down = down;
2704 params.pixels_to_scroll = pixels_to_scroll;
2705 params.mouse_event_x = mouse_event_x;
2706 params.mouse_event_y = mouse_event_y;
2707
[email protected]4a9dba42013-04-29 18:24:222708 Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, params));
[email protected]79fa22e2013-08-23 15:18:122709 pending_synthetic_gesture_ = callback;
[email protected]a39ca1652012-07-13 21:30:582710}
2711
[email protected]1e1dd182013-09-12 01:51:152712void RenderWidget::BeginPinch(
2713 bool zoom_in,
2714 int pixels_to_move,
2715 int anchor_x,
2716 int anchor_y,
2717 const SyntheticGestureCompletionCallback& callback) {
2718 DCHECK(!callback.is_null());
2719
2720 ViewHostMsg_BeginPinch_Params params;
2721 params.zoom_in = zoom_in;
2722 params.pixels_to_move = pixels_to_move;
2723 params.anchor_x = anchor_x;
2724 params.anchor_y = anchor_y;
2725
2726 Send(new ViewHostMsg_BeginPinch(routing_id_, params));
2727 pending_synthetic_gesture_ = callback;
2728}
2729
[email protected]67bfb83f2011-09-22 03:36:372730bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) {
2731 return false;
2732}
[email protected]c3d45532011-10-07 19:20:402733
[email protected]f56c7872013-06-18 12:31:572734bool RenderWidget::WillHandleKeyEvent(const WebKit::WebKeyboardEvent& event) {
2735 return false;
2736}
2737
[email protected]41d86852012-11-07 12:23:242738bool RenderWidget::WillHandleGestureEvent(
2739 const WebKit::WebGestureEvent& event) {
2740 return false;
2741}
2742
[email protected]ce6689f2013-03-29 12:52:552743void RenderWidget::hasTouchEventHandlers(bool has_handlers) {
2744 Send(new ViewHostMsg_HasTouchEventHandlers(routing_id_, has_handlers));
2745}
2746
[email protected]3d5c243b2012-11-30 00:26:012747bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2748 return true;
2749}
2750
[email protected]0634cdd42013-08-16 00:46:092751scoped_ptr<WebGraphicsContext3DCommandBufferImpl>
2752RenderWidget::CreateGraphicsContext3D(
[email protected]92fd8c02013-03-29 08:54:152753 const WebKit::WebGraphicsContext3D::Attributes& attributes) {
[email protected]ed7defa2013-03-12 21:29:592754 if (!webwidget_)
[email protected]0634cdd42013-08-16 00:46:092755 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]ebc0e1df2013-08-01 02:46:222756 if (CommandLine::ForCurrentProcess()->HasSwitch(
2757 switches::kDisableGpuCompositing))
[email protected]0634cdd42013-08-16 00:46:092758 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]bf676c192013-10-15 23:59:252759 scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context(
2760 new WebGraphicsContext3DCommandBufferImpl(
2761 surface_id(),
2762 GetURLForGraphicsContext3D(),
2763 RenderThreadImpl::current(),
2764 weak_ptr_factory_.GetWeakPtr()));
[email protected]ed7defa2013-03-12 21:29:592765
[email protected]b6eb8e332013-09-10 00:51:012766#if defined(OS_ANDROID)
2767 // If we raster too fast we become upload bound, and pending
2768 // uploads consume memory. For maximum upload throughput, we would
2769 // want to allow for upload_throughput * pipeline_time of pending
2770 // uploads, after which we are just wasting memory. Since we don't
2771 // know our upload throughput yet, this just caps our memory usage.
2772 size_t divider = 1;
2773 if (base::android::SysUtils::IsLowEndDevice())
[email protected]657be322013-09-20 08:50:032774 divider = 6;
[email protected]b6eb8e332013-09-10 00:51:012775 // For reference Nexus10 can upload 1MB in about 2.5ms.
[email protected]657be322013-09-20 08:50:032776 const double max_mb_uploaded_per_ms = 2.0 / (5 * divider);
[email protected]b6eb8e332013-09-10 00:51:012777 // Deadline to draw a frame to achieve 60 frames per second.
2778 const size_t kMillisecondsPerFrame = 16;
2779 // Assuming a two frame deep pipeline between the CPU and the GPU.
[email protected]657be322013-09-20 08:50:032780 size_t max_transfer_buffer_usage_mb =
2781 static_cast<size_t>(2 * kMillisecondsPerFrame * max_mb_uploaded_per_ms);
2782 static const size_t kBytesPerMegabyte = 1024 * 1024;
[email protected]b6eb8e332013-09-10 00:51:012783 // We keep the MappedMemoryReclaimLimit the same as the upload limit
2784 // to avoid unnecessarily stalling the compositor thread.
[email protected]bf676c192013-10-15 23:59:252785 const size_t mapped_memory_reclaim_limit =
[email protected]657be322013-09-20 08:50:032786 max_transfer_buffer_usage_mb * kBytesPerMegabyte;
[email protected]bf676c192013-10-15 23:59:252787#else
2788 const size_t mapped_memory_reclaim_limit =
2789 WebGraphicsContext3DCommandBufferImpl::kNoLimit;
[email protected]b6eb8e332013-09-10 00:51:012790#endif
[email protected]bf676c192013-10-15 23:59:252791 if (!context->Initialize(
[email protected]8f746982013-03-21 06:28:032792 attributes,
2793 false /* bind generates resources */,
[email protected]bf676c192013-10-15 23:59:252794 CAUSE_FOR_GPU_LAUNCH_WEBGRAPHICSCONTEXT3DCOMMANDBUFFERIMPL_INITIALIZE,
2795 kDefaultCommandBufferSize,
2796 kDefaultStartTransferBufferSize,
2797 kDefaultMinTransferBufferSize,
2798 kDefaultMaxTransferBufferSize,
2799 mapped_memory_reclaim_limit))
2800 return scoped_ptr<WebGraphicsContext3DCommandBufferImpl>();
[email protected]0634cdd42013-08-16 00:46:092801 return context.Pass();
[email protected]ed7defa2013-03-12 21:29:592802}
2803
[email protected]e9ff79c2012-10-19 21:31:262804} // namespace content