[email protected] | 60a5007 | 2012-01-11 02:05:35 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 2cff005 | 2011-03-18 16:51:44 | [diff] [blame] | 5 | #include "content/renderer/render_widget.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | 32876ae | 2011-11-15 22:25:21 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 8 | #include "base/command_line.h" |
[email protected] | 366ae24 | 2011-05-10 02:23:58 | [diff] [blame] | 9 | #include "base/debug/trace_event.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 10 | #include "base/logging.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 11 | #include "base/memory/scoped_ptr.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 12 | #include "base/message_loop.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 13 | #include "base/metrics/histogram.h" |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 14 | #include "base/stl_util.h" |
[email protected] | 8a9d6ca3 | 2011-06-06 20:11:30 | [diff] [blame] | 15 | #include "base/utf_string_conversions.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 16 | #include "build/build_config.h" |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 17 | #include "content/common/swapped_out_messages.h" |
[email protected] | 778574e | 2011-03-21 22:03:50 | [diff] [blame] | 18 | #include "content/common/view_messages.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 19 | #include "content/public/common/content_switches.h" |
[email protected] | 8704f89b | 2011-04-15 00:30:05 | [diff] [blame] | 20 | #include "content/renderer/render_process.h" |
[email protected] | f1a29a0 | 2011-10-06 23:08:44 | [diff] [blame] | 21 | #include "content/renderer/render_thread_impl.h" |
[email protected] | 8d6cba4 | 2011-09-02 10:05:19 | [diff] [blame] | 22 | #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 23 | #include "ipc/ipc_sync_message.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 24 | #include "skia/ext/platform_canvas.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 25 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
[email protected] | 4b1146bc | 2012-07-10 18:46:03 | [diff] [blame] | 26 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h" |
[email protected] | a7547fb | 2012-03-08 04:43:44 | [diff] [blame] | 27 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 28 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" |
| 29 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h" |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 30 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 31 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 32 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h" |
| 33 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
[email protected] | e6e90dc | 2011-12-03 00:01:37 | [diff] [blame] | 34 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
| 35 | #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 36 | #include "third_party/skia/include/core/SkShader.h" |
[email protected] | faec7b1 | 2012-06-19 14:42:13 | [diff] [blame] | 37 | #include "ui/base/ui_base_switches.h" |
[email protected] | a25e25b | 2012-09-28 14:32:37 | [diff] [blame] | 38 | #include "ui/gfx/rect_conversions.h" |
[email protected] | 4b01b96 | 2012-10-09 23:17:35 | [diff] [blame] | 39 | #include "ui/gfx/size_conversions.h" |
[email protected] | 1835b9e | 2012-02-28 13:12:48 | [diff] [blame] | 40 | #include "ui/gfx/skia_util.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 41 | #include "ui/gl/gl_switches.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 42 | #include "ui/surface/transport_dib.h" |
[email protected] | b63d58d | 2012-11-26 22:37:44 | [diff] [blame] | 43 | #include "webkit/compositor_bindings/web_rendering_stats_impl.h" |
[email protected] | 8c89e779 | 2009-08-19 21:18:34 | [diff] [blame] | 44 | #include "webkit/glue/webkit_glue.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 45 | #include "webkit/plugins/npapi/webplugin.h" |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 46 | #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 47 | |
| 48 | #if defined(OS_POSIX) |
[email protected] | 6b889fb | 2010-03-23 20:09:49 | [diff] [blame] | 49 | #include "ipc/ipc_channel_posix.h" |
[email protected] | d5282e7 | 2009-05-13 13:16:52 | [diff] [blame] | 50 | #include "third_party/skia/include/core/SkMallocPixelRef.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 51 | #include "third_party/skia/include/core/SkPixelRef.h" |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 52 | #endif // defined(OS_POSIX) |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 53 | |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 54 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 55 | |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 56 | using WebKit::WebCompositionUnderline; |
[email protected] | 7c51b0ee | 2009-07-08 21:49:30 | [diff] [blame] | 57 | using WebKit::WebCursorInfo; |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 58 | using WebKit::WebGestureEvent; |
[email protected] | 62cb33cae | 2009-03-27 23:30:22 | [diff] [blame] | 59 | using WebKit::WebInputEvent; |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 60 | using WebKit::WebMouseEvent; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 61 | using WebKit::WebNavigationPolicy; |
[email protected] | a7547fb | 2012-03-08 04:43:44 | [diff] [blame] | 62 | using WebKit::WebPagePopup; |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 63 | using WebKit::WebPoint; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 64 | using WebKit::WebPopupMenu; |
[email protected] | 88efb7ec | 2009-07-14 16:32:59 | [diff] [blame] | 65 | using WebKit::WebPopupMenuInfo; |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 66 | using WebKit::WebPopupType; |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 67 | using WebKit::WebRange; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 68 | using WebKit::WebRect; |
[email protected] | 12456fa | 2009-04-01 23:07:19 | [diff] [blame] | 69 | using WebKit::WebScreenInfo; |
[email protected] | b3f2b91 | 2009-04-09 16:18:52 | [diff] [blame] | 70 | using WebKit::WebSize; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 71 | using WebKit::WebTextDirection; |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 72 | using WebKit::WebTouchEvent; |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 73 | using WebKit::WebVector; |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 74 | using WebKit::WebWidget; |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 75 | |
| 76 | namespace content { |
[email protected] | 62cb33cae | 2009-03-27 23:30:22 | [diff] [blame] | 77 | |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 78 | RenderWidget::RenderWidget(WebKit::WebPopupType popup_type, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 79 | const WebKit::WebScreenInfo& screen_info, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 80 | bool swapped_out) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 81 | : routing_id_(MSG_ROUTING_NONE), |
[email protected] | 9f4f332 | 2012-01-18 22:29:56 | [diff] [blame] | 82 | surface_id_(0), |
[email protected] | c5b3b5e | 2009-02-13 06:41:11 | [diff] [blame] | 83 | webwidget_(NULL), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 84 | opener_id_(MSG_ROUTING_NONE), |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 85 | init_complete_(false), |
[email protected] | b4d0845 | 2010-10-05 17:34:35 | [diff] [blame] | 86 | current_paint_buf_(NULL), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 87 | next_paint_flags_(0), |
[email protected] | 0cff69e | 2011-11-22 22:26:06 | [diff] [blame] | 88 | filtered_time_per_frame_(0.0f), |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 89 | update_reply_pending_(false), |
[email protected] | ea3ee0a | 2012-05-15 03:43:09 | [diff] [blame] | 90 | need_update_rect_for_auto_resize_(false), |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 91 | using_asynchronous_swapbuffers_(false), |
| 92 | num_swapbuffers_complete_pending_(0), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 93 | did_show_(false), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 94 | is_hidden_(false), |
[email protected] | ee41e7d2 | 2011-10-14 19:34:09 | [diff] [blame] | 95 | is_fullscreen_(false), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 96 | needs_repainting_on_restore_(false), |
| 97 | has_focus_(false), |
[email protected] | 5dd76821 | 2009-08-13 23:34:49 | [diff] [blame] | 98 | handling_input_event_(false), |
[email protected] | 661eb9d | 2009-02-03 02:11:48 | [diff] [blame] | 99 | closing_(false), |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 100 | is_swapped_out_(swapped_out), |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 101 | input_method_is_active_(false), |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 102 | text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
| 103 | can_compose_inline_(true), |
[email protected] | 3e2b375b | 2010-04-07 17:03:12 | [diff] [blame] | 104 | popup_type_(popup_type), |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 105 | pending_window_rect_count_(0), |
[email protected] | b68a0e5 | 2011-12-08 15:11:12 | [diff] [blame] | 106 | suppress_next_char_events_(false), |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 107 | is_accelerated_compositing_active_(false), |
[email protected] | ee3d3ad | 2011-02-04 00:42:21 | [diff] [blame] | 108 | animation_update_pending_(false), |
[email protected] | 4b03e29 | 2012-02-13 18:40:07 | [diff] [blame] | 109 | invalidation_task_posted_(false), |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 110 | screen_info_(screen_info), |
[email protected] | 3d77947 | 2012-11-15 20:49:52 | [diff] [blame] | 111 | device_scale_factor_(screen_info_.deviceScaleFactor), |
[email protected] | 0e241b4b | 2012-08-18 09:06:27 | [diff] [blame] | 112 | throttle_input_events_(true), |
[email protected] | cb643093 | 2012-10-31 00:53:36 | [diff] [blame] | 113 | next_smooth_scroll_gesture_id_(0), |
| 114 | is_threaded_compositing_enabled_(false) { |
[email protected] | 8b3f0eb | 2012-05-03 19:15:05 | [diff] [blame] | 115 | if (!swapped_out) |
| 116 | RenderProcess::current()->AddRefProcess(); |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 117 | DCHECK(RenderThread::Get()); |
[email protected] | bd37ae25 | 2011-06-03 01:28:18 | [diff] [blame] | 118 | has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch( |
| 119 | switches::kDisableGpuVsync); |
[email protected] | cb643093 | 2012-10-31 00:53:36 | [diff] [blame] | 120 | is_threaded_compositing_enabled_ = |
| 121 | CommandLine::ForCurrentProcess()->HasSwitch( |
| 122 | switches::kEnableThreadedCompositing); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | RenderWidget::~RenderWidget() { |
[email protected] | c5b3b5e | 2009-02-13 06:41:11 | [diff] [blame] | 126 | DCHECK(!webwidget_) << "Leaking our WebWidget!"; |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 127 | STLDeleteElements(&updates_pending_swap_); |
[email protected] | b4d0845 | 2010-10-05 17:34:35 | [diff] [blame] | 128 | if (current_paint_buf_) { |
| 129 | RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); |
| 130 | current_paint_buf_ = NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 131 | } |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 132 | // If we are swapped out, we have released already. |
| 133 | if (!is_swapped_out_) |
| 134 | RenderProcess::current()->ReleaseProcess(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 135 | } |
| 136 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 137 | // static |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 138 | RenderWidget* RenderWidget::Create(int32 opener_id, |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 139 | WebKit::WebPopupType popup_type, |
| 140 | const WebKit::WebScreenInfo& screen_info) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 141 | DCHECK(opener_id != MSG_ROUTING_NONE); |
[email protected] | 6fd35b7 | 2012-03-01 19:46:41 | [diff] [blame] | 142 | scoped_refptr<RenderWidget> widget( |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 143 | new RenderWidget(popup_type, screen_info, false)); |
[email protected] | a635f94 | 2012-12-07 10:34:29 | [diff] [blame] | 144 | if (widget->Init(opener_id)) { // adds reference on success. |
| 145 | return widget; |
| 146 | } |
| 147 | return NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 148 | } |
| 149 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 150 | // static |
| 151 | WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) { |
| 152 | switch (render_widget->popup_type_) { |
[email protected] | e235624 | 2010-11-16 22:33:03 | [diff] [blame] | 153 | case WebKit::WebPopupTypeNone: // Nothing to create. |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 154 | break; |
| 155 | case WebKit::WebPopupTypeSelect: |
| 156 | case WebKit::WebPopupTypeSuggestion: |
| 157 | return WebPopupMenu::create(render_widget); |
[email protected] | a7547fb | 2012-03-08 04:43:44 | [diff] [blame] | 158 | case WebKit::WebPopupTypePage: |
| 159 | return WebPagePopup::create(render_widget); |
[email protected] | 4b1146bc | 2012-07-10 18:46:03 | [diff] [blame] | 160 | case WebKit::WebPopupTypeHelperPlugin: |
| 161 | return WebKit::WebHelperPlugin::create(render_widget); |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 162 | default: |
| 163 | NOTREACHED(); |
| 164 | } |
| 165 | return NULL; |
| 166 | } |
| 167 | |
[email protected] | a635f94 | 2012-12-07 10:34:29 | [diff] [blame] | 168 | bool RenderWidget::Init(int32 opener_id) { |
| 169 | return DoInit(opener_id, |
| 170 | RenderWidget::CreateWebWidget(this), |
| 171 | new ViewHostMsg_CreateWidget(opener_id, popup_type_, |
| 172 | &routing_id_, &surface_id_)); |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 173 | } |
| 174 | |
[email protected] | a635f94 | 2012-12-07 10:34:29 | [diff] [blame] | 175 | bool RenderWidget::DoInit(int32 opener_id, |
[email protected] | 6a8ddba5 | 2010-09-05 04:38:06 | [diff] [blame] | 176 | WebWidget* web_widget, |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 177 | IPC::SyncMessage* create_widget_message) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 178 | DCHECK(!webwidget_); |
| 179 | |
| 180 | if (opener_id != MSG_ROUTING_NONE) |
| 181 | opener_id_ = opener_id; |
| 182 | |
[email protected] | 48495594 | 2010-08-19 16:13:18 | [diff] [blame] | 183 | webwidget_ = web_widget; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 184 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 185 | bool result = RenderThread::Get()->Send(create_widget_message); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 186 | if (result) { |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 187 | RenderThread::Get()->AddRoute(routing_id_, this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 188 | // Take a reference on behalf of the RenderThread. This will be balanced |
| 189 | // when we receive ViewMsg_Close. |
| 190 | AddRef(); |
[email protected] | a635f94 | 2012-12-07 10:34:29 | [diff] [blame] | 191 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 192 | } else { |
[email protected] | a635f94 | 2012-12-07 10:34:29 | [diff] [blame] | 193 | // The above Send can fail when the tab is closing. |
| 194 | return false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 198 | // This is used to complete pending inits and non-pending inits. |
| 199 | void RenderWidget::CompleteInit() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 200 | DCHECK(routing_id_ != MSG_ROUTING_NONE); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 201 | |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 202 | init_complete_ = true; |
[email protected] | 05a980d7a | 2012-02-07 22:16:42 | [diff] [blame] | 203 | |
[email protected] | 479b017 | 2012-10-29 19:27:09 | [diff] [blame] | 204 | if (webwidget_) { |
| 205 | webwidget_->setCompositorSurfaceReady(); |
[email protected] | cb643093 | 2012-10-31 00:53:36 | [diff] [blame] | 206 | if (is_threaded_compositing_enabled_) |
[email protected] | 479b017 | 2012-10-29 19:27:09 | [diff] [blame] | 207 | webwidget_->enterForceCompositingMode(true); |
| 208 | } |
[email protected] | 05a980d7a | 2012-02-07 22:16:42 | [diff] [blame] | 209 | DoDeferredUpdate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 210 | |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 211 | Send(new ViewHostMsg_RenderViewReady(routing_id_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 212 | } |
| 213 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 214 | void RenderWidget::SetSwappedOut(bool is_swapped_out) { |
| 215 | // We should only toggle between states. |
| 216 | DCHECK(is_swapped_out_ != is_swapped_out); |
| 217 | is_swapped_out_ = is_swapped_out; |
| 218 | |
| 219 | // If we are swapping out, we will call ReleaseProcess, allowing the process |
| 220 | // to exit if all of its RenderViews are swapped out. We wait until the |
| 221 | // WasSwappedOut call to do this, to avoid showing the sad tab. |
| 222 | // If we are swapping in, we call AddRefProcess to prevent the process from |
| 223 | // exiting. |
| 224 | if (!is_swapped_out) |
| 225 | RenderProcess::current()->AddRefProcess(); |
| 226 | } |
| 227 | |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 228 | bool RenderWidget::OnMessageReceived(const IPC::Message& message) { |
| 229 | bool handled = true; |
| 230 | IPC_BEGIN_MESSAGE_MAP(RenderWidget, message) |
| 231 | IPC_MESSAGE_HANDLER(ViewMsg_Close, OnClose) |
| 232 | IPC_MESSAGE_HANDLER(ViewMsg_CreatingNew_ACK, OnCreatingNewAck) |
| 233 | IPC_MESSAGE_HANDLER(ViewMsg_Resize, OnResize) |
[email protected] | b5913d7 | 2012-02-07 22:26:54 | [diff] [blame] | 234 | IPC_MESSAGE_HANDLER(ViewMsg_ChangeResizeRect, OnChangeResizeRect) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 235 | IPC_MESSAGE_HANDLER(ViewMsg_WasHidden, OnWasHidden) |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 236 | IPC_MESSAGE_HANDLER(ViewMsg_WasShown, OnWasShown) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 237 | IPC_MESSAGE_HANDLER(ViewMsg_WasSwappedOut, OnWasSwappedOut) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 238 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateRect_ACK, OnUpdateRectAck) |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 239 | IPC_MESSAGE_HANDLER(ViewMsg_SwapBuffers_ACK, OnSwapBuffersComplete) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 240 | IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent) |
| 241 | IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost) |
| 242 | IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus) |
| 243 | IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive) |
| 244 | IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition) |
| 245 | IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition) |
| 246 | IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize) |
| 247 | IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint) |
[email protected] | 0e241b4b | 2012-08-18 09:06:27 | [diff] [blame] | 248 | IPC_MESSAGE_HANDLER(ViewMsg_SmoothScrollCompleted, |
| 249 | OnMsgSmoothScrollCompleted) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 250 | IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) |
| 251 | IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) |
[email protected] | 6131a64 | 2012-06-15 23:26:53 | [diff] [blame] | 252 | IPC_MESSAGE_HANDLER(ViewMsg_ScreenInfoChanged, OnScreenInfoChanged) |
[email protected] | 80ad862 | 2012-11-07 16:33:03 | [diff] [blame] | 253 | IPC_MESSAGE_HANDLER(ViewMsg_UpdateScreenRects, OnUpdateScreenRects) |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 254 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 255 | IPC_END_MESSAGE_MAP() |
| 256 | return handled; |
| 257 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 258 | |
| 259 | bool RenderWidget::Send(IPC::Message* message) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 260 | // Don't send any messages after the browser has told us to close, and filter |
| 261 | // most outgoing messages while swapped out. |
| 262 | if ((is_swapped_out_ && |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 263 | !SwappedOutMessages::CanSendWhileSwappedOut(message)) || |
[email protected] | c6c921e9 | 2012-05-10 23:31:11 | [diff] [blame] | 264 | closing_) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 265 | delete message; |
| 266 | return false; |
| 267 | } |
| 268 | |
| 269 | // If given a messsage without a routing ID, then assign our routing ID. |
| 270 | if (message->routing_id() == MSG_ROUTING_NONE) |
| 271 | message->set_routing_id(routing_id_); |
| 272 | |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 273 | return RenderThread::Get()->Send(message); |
[email protected] | 8085dbc8 | 2008-09-26 22:53:44 | [diff] [blame] | 274 | } |
| 275 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 276 | void RenderWidget::Resize(const gfx::Size& new_size, |
| 277 | const gfx::Rect& resizer_rect, |
| 278 | bool is_fullscreen, |
| 279 | ResizeAck resize_ack) { |
| 280 | // A resize ack shouldn't be requested if we have not ACK'd the previous one. |
| 281 | DCHECK(resize_ack != SEND_RESIZE_ACK || !next_paint_is_resize_ack()); |
| 282 | DCHECK(resize_ack == SEND_RESIZE_ACK || resize_ack == NO_RESIZE_ACK); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 283 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 284 | // Ignore this during shutdown. |
| 285 | if (!webwidget_) |
| 286 | return; |
| 287 | |
| 288 | // Remember the rect where the resize corner will be drawn. |
| 289 | resizer_rect_ = resizer_rect; |
| 290 | |
| 291 | // NOTE: We may have entered fullscreen mode without changing our size. |
| 292 | bool fullscreen_change = is_fullscreen_ != is_fullscreen; |
| 293 | if (fullscreen_change) |
| 294 | WillToggleFullscreen(); |
| 295 | is_fullscreen_ = is_fullscreen; |
| 296 | |
| 297 | if (size_ != new_size) { |
| 298 | // TODO(darin): We should not need to reset this here. |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 299 | needs_repainting_on_restore_ = false; |
| 300 | |
| 301 | size_ = new_size; |
| 302 | |
| 303 | paint_aggregator_.ClearPendingUpdate(); |
| 304 | |
| 305 | // When resizing, we want to wait to paint before ACK'ing the resize. This |
| 306 | // ensures that we only resize as fast as we can paint. We only need to |
| 307 | // send an ACK if we are resized to a non-empty rect. |
| 308 | webwidget_->resize(new_size); |
| 309 | if (!new_size.IsEmpty()) { |
| 310 | if (!is_accelerated_compositing_active_) { |
| 311 | // Resize should have caused an invalidation of the entire view. |
| 312 | DCHECK(paint_aggregator_.HasPendingUpdate()); |
| 313 | } |
| 314 | |
| 315 | // Send the Resize_ACK flag once we paint again if requested. |
| 316 | if (resize_ack == SEND_RESIZE_ACK) |
| 317 | set_next_paint_is_resize_ack(); |
| 318 | } |
[email protected] | ff475a32 | 2012-03-14 00:05:35 | [diff] [blame] | 319 | } else { |
| 320 | resize_ack = NO_RESIZE_ACK; |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | if (fullscreen_change) |
| 324 | DidToggleFullscreen(); |
| 325 | |
| 326 | // If a resize ack is requested and it isn't set-up, then no more resizes will |
| 327 | // come in and in general things will go wrong. |
| 328 | DCHECK(resize_ack != SEND_RESIZE_ACK || new_size.IsEmpty() || |
| 329 | next_paint_is_resize_ack()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | void RenderWidget::OnClose() { |
| 333 | if (closing_) |
| 334 | return; |
| 335 | closing_ = true; |
| 336 | |
| 337 | // Browser correspondence is no longer needed at this point. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 338 | if (routing_id_ != MSG_ROUTING_NONE) { |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 339 | RenderThread::Get()->RemoveRoute(routing_id_); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 340 | SetHidden(false); |
| 341 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 342 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 343 | // If there is a Send call on the stack, then it could be dangerous to close |
[email protected] | d3fc2565 | 2009-02-24 22:31:25 | [diff] [blame] | 344 | // now. Post a task that only gets invoked when there are no nested message |
| 345 | // loops. |
[email protected] | 32876ae | 2011-11-15 22:25:21 | [diff] [blame] | 346 | MessageLoop::current()->PostNonNestableTask( |
[email protected] | 3a5a782 | 2011-12-23 18:27:29 | [diff] [blame] | 347 | FROM_HERE, base::Bind(&RenderWidget::Close, this)); |
[email protected] | d3fc2565 | 2009-02-24 22:31:25 | [diff] [blame] | 348 | |
| 349 | // Balances the AddRef taken when we called AddRoute. |
| 350 | Release(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 351 | } |
| 352 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 353 | // Got a response from the browser after the renderer decided to create a new |
| 354 | // view. |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 355 | void RenderWidget::OnCreatingNewAck() { |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 356 | DCHECK(routing_id_ != MSG_ROUTING_NONE); |
| 357 | |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 358 | CompleteInit(); |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 359 | } |
| 360 | |
[email protected] | f21c613a | 2009-02-12 14:46:17 | [diff] [blame] | 361 | void RenderWidget::OnResize(const gfx::Size& new_size, |
[email protected] | ee41e7d2 | 2011-10-14 19:34:09 | [diff] [blame] | 362 | const gfx::Rect& resizer_rect, |
| 363 | bool is_fullscreen) { |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 364 | Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 365 | } |
| 366 | |
[email protected] | b5913d7 | 2012-02-07 22:26:54 | [diff] [blame] | 367 | void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) { |
| 368 | if (resizer_rect_ != resizer_rect) { |
[email protected] | b9769d8 | 2012-02-10 00:23:59 | [diff] [blame] | 369 | gfx::Rect view_rect(size_); |
| 370 | |
[email protected] | ce112fe | 2012-10-29 22:52:18 | [diff] [blame] | 371 | gfx::Rect old_damage_rect = gfx::IntersectRects(view_rect, resizer_rect_); |
[email protected] | b9769d8 | 2012-02-10 00:23:59 | [diff] [blame] | 372 | if (!old_damage_rect.IsEmpty()) |
| 373 | paint_aggregator_.InvalidateRect(old_damage_rect); |
| 374 | |
[email protected] | ce112fe | 2012-10-29 22:52:18 | [diff] [blame] | 375 | gfx::Rect new_damage_rect = gfx::IntersectRects(view_rect, resizer_rect); |
[email protected] | b9769d8 | 2012-02-10 00:23:59 | [diff] [blame] | 376 | if (!new_damage_rect.IsEmpty()) |
| 377 | paint_aggregator_.InvalidateRect(new_damage_rect); |
| 378 | |
[email protected] | b5913d7 | 2012-02-07 22:26:54 | [diff] [blame] | 379 | resizer_rect_ = resizer_rect; |
[email protected] | b9769d8 | 2012-02-10 00:23:59 | [diff] [blame] | 380 | |
[email protected] | b5913d7 | 2012-02-07 22:26:54 | [diff] [blame] | 381 | if (webwidget_) |
| 382 | webwidget_->didChangeWindowResizerRect(); |
| 383 | } |
| 384 | } |
| 385 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 386 | void RenderWidget::OnWasHidden() { |
[email protected] | 9c3085f | 2011-06-09 02:10:31 | [diff] [blame] | 387 | TRACE_EVENT0("renderer", "RenderWidget::OnWasHidden"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 388 | // Go into a mode where we stop generating paint and scrolling events. |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 389 | SetHidden(true); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 390 | } |
| 391 | |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 392 | void RenderWidget::OnWasShown(bool needs_repainting) { |
| 393 | TRACE_EVENT0("renderer", "RenderWidget::OnWasShown"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 394 | // During shutdown we can just ignore this message. |
| 395 | if (!webwidget_) |
| 396 | return; |
| 397 | |
| 398 | // See OnWasHidden |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 399 | SetHidden(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 400 | |
| 401 | if (!needs_repainting && !needs_repainting_on_restore_) |
| 402 | return; |
| 403 | needs_repainting_on_restore_ = false; |
| 404 | |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 405 | // Tag the next paint as a restore ack, which is picked up by |
| 406 | // DoDeferredUpdate when it sends out the next PaintRect message. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 407 | set_next_paint_is_restore_ack(); |
| 408 | |
| 409 | // Generate a full repaint. |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 410 | if (!is_accelerated_compositing_active_) { |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 411 | didInvalidateRect(gfx::Rect(size_.width(), size_.height())); |
| 412 | } else { |
| 413 | scheduleComposite(); |
| 414 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 415 | } |
| 416 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 417 | void RenderWidget::OnWasSwappedOut() { |
| 418 | // If we have been swapped out and no one else is using this process, |
| 419 | // it's safe to exit now. If we get swapped back in, we will call |
| 420 | // AddRefProcess in SetSwappedOut. |
| 421 | if (is_swapped_out_) |
| 422 | RenderProcess::current()->ReleaseProcess(); |
| 423 | } |
| 424 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 425 | void RenderWidget::OnRequestMoveAck() { |
| 426 | DCHECK(pending_window_rect_count_); |
| 427 | pending_window_rect_count_--; |
| 428 | } |
| 429 | |
| 430 | void RenderWidget::OnUpdateRectAck() { |
[email protected] | 366ae24 | 2011-05-10 02:23:58 | [diff] [blame] | 431 | TRACE_EVENT0("renderer", "RenderWidget::OnUpdateRectAck"); |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 432 | DCHECK(update_reply_pending_); |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 433 | update_reply_pending_ = false; |
| 434 | |
[email protected] | b4d0845 | 2010-10-05 17:34:35 | [diff] [blame] | 435 | // If we sent an UpdateRect message with a zero-sized bitmap, then we should |
| 436 | // have no current paint buffer. |
| 437 | if (current_paint_buf_) { |
| 438 | RenderProcess::current()->ReleaseTransportDIB(current_paint_buf_); |
| 439 | current_paint_buf_ = NULL; |
| 440 | } |
| 441 | |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 442 | // If swapbuffers is still pending, then defer the update until the |
| 443 | // swapbuffers occurs. |
| 444 | if (num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) { |
| 445 | TRACE_EVENT0("renderer", "EarlyOut_SwapStillPending"); |
| 446 | return; |
| 447 | } |
| 448 | |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 449 | // Notify subclasses that software rendering was flushed to the screen. |
[email protected] | 404939f | 2012-06-01 04:06:18 | [diff] [blame] | 450 | if (!is_accelerated_compositing_active_) { |
| 451 | DidFlushPaint(); |
| 452 | } |
[email protected] | a2f6bc11 | 2009-06-27 16:27:25 | [diff] [blame] | 453 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 454 | // Continue painting if necessary... |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 455 | DoDeferredUpdateAndSendInputAck(); |
| 456 | } |
| 457 | |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 458 | bool RenderWidget::SupportsAsynchronousSwapBuffers() { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 459 | return false; |
| 460 | } |
| 461 | |
[email protected] | 479b017 | 2012-10-29 19:27:09 | [diff] [blame] | 462 | bool RenderWidget::ForceCompositingModeEnabled() { |
| 463 | return false; |
| 464 | } |
| 465 | |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 466 | void RenderWidget::OnSwapBuffersAborted() { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 467 | TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 468 | while (!updates_pending_swap_.empty()) { |
| 469 | ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front(); |
| 470 | updates_pending_swap_.pop_front(); |
| 471 | // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate |
| 472 | // compositing pass, hence doesn't require an UpdateRect message. |
| 473 | if (msg) |
| 474 | Send(msg); |
| 475 | } |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 476 | num_swapbuffers_complete_pending_ = 0; |
| 477 | using_asynchronous_swapbuffers_ = false; |
| 478 | // Schedule another frame so the compositor learns about it. |
| 479 | scheduleComposite(); |
| 480 | } |
| 481 | |
[email protected] | 37a6f30 | 2011-07-11 23:43:08 | [diff] [blame] | 482 | void RenderWidget::OnSwapBuffersPosted() { |
| 483 | TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted"); |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 484 | |
| 485 | if (using_asynchronous_swapbuffers_) { |
| 486 | ViewHostMsg_UpdateRect* msg = NULL; |
| 487 | // pending_update_params_ can be NULL if the swap doesn't correspond to an |
| 488 | // DoDeferredUpdate compositing pass, hence doesn't require an UpdateRect |
| 489 | // message. |
| 490 | if (pending_update_params_.get()) { |
| 491 | msg = new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_); |
| 492 | pending_update_params_.reset(); |
| 493 | } |
| 494 | updates_pending_swap_.push_back(msg); |
[email protected] | 37a6f30 | 2011-07-11 23:43:08 | [diff] [blame] | 495 | num_swapbuffers_complete_pending_++; |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 496 | } |
[email protected] | 37a6f30 | 2011-07-11 23:43:08 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | void RenderWidget::OnSwapBuffersComplete() { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 500 | TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete"); |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 501 | |
[email protected] | 404939f | 2012-06-01 04:06:18 | [diff] [blame] | 502 | // Notify subclasses that composited rendering was flushed to the screen. |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 503 | DidFlushPaint(); |
| 504 | |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 505 | // When compositing deactivates, we reset the swapbuffers pending count. The |
| 506 | // swapbuffers acks may still arrive, however. |
| 507 | if (num_swapbuffers_complete_pending_ == 0) { |
| 508 | TRACE_EVENT0("renderer", "EarlyOut_ZeroSwapbuffersPending"); |
| 509 | return; |
| 510 | } |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 511 | DCHECK(!updates_pending_swap_.empty()); |
| 512 | ViewHostMsg_UpdateRect* msg = updates_pending_swap_.front(); |
| 513 | updates_pending_swap_.pop_front(); |
| 514 | // msg can be NULL if the swap doesn't correspond to an DoDeferredUpdate |
| 515 | // compositing pass, hence doesn't require an UpdateRect message. |
| 516 | if (msg) |
| 517 | Send(msg); |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 518 | num_swapbuffers_complete_pending_--; |
| 519 | |
| 520 | // If update reply is still pending, then defer the update until that reply |
| 521 | // occurs. |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 522 | if (update_reply_pending_) { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 523 | TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending"); |
| 524 | return; |
| 525 | } |
| 526 | |
| 527 | // If we are not accelerated rendering, then this is a stale swapbuffers from |
[email protected] | 50312bf | 2011-06-22 23:30:06 | [diff] [blame] | 528 | // when we were previously rendering. However, if an invalidation task is not |
| 529 | // posted, there may be software rendering work pending. In that case, don't |
| 530 | // early out. |
| 531 | if (!is_accelerated_compositing_active_ && invalidation_task_posted_) { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 532 | TRACE_EVENT0("renderer", "EarlyOut_AcceleratedCompositingOff"); |
| 533 | return; |
| 534 | } |
| 535 | |
[email protected] | cc66e68 | 2012-10-02 06:48:18 | [diff] [blame] | 536 | // Do not call DoDeferredUpdate unless there's animation work to be done or |
| 537 | // a real invalidation. This prevents rendering in response to a swapbuffers |
| 538 | // callback coming back after we've navigated away from the page that |
| 539 | // generated it. |
| 540 | if (!animation_update_pending_ && !paint_aggregator_.HasPendingUpdate()) { |
| 541 | TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate"); |
| 542 | return; |
| 543 | } |
| 544 | |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 545 | // Continue painting if necessary... |
| 546 | DoDeferredUpdateAndSendInputAck(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 547 | } |
| 548 | |
[email protected] | 0dea165 | 2012-12-14 00:09:09 | [diff] [blame^] | 549 | void RenderWidget::OnHandleInputEvent(const WebKit::WebInputEvent* input_event, |
| 550 | bool is_keyboard_shortcut) { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 551 | TRACE_EVENT0("renderer", "RenderWidget::OnHandleInputEvent"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 552 | |
[email protected] | 5dd76821 | 2009-08-13 23:34:49 | [diff] [blame] | 553 | handling_input_event_ = true; |
[email protected] | 0dea165 | 2012-12-14 00:09:09 | [diff] [blame^] | 554 | if (!input_event) { |
[email protected] | 5dd76821 | 2009-08-13 23:34:49 | [diff] [blame] | 555 | handling_input_event_ = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 556 | return; |
[email protected] | 5dd76821 | 2009-08-13 23:34:49 | [diff] [blame] | 557 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 558 | |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 559 | bool prevent_default = false; |
| 560 | if (WebInputEvent::isMouseEventType(input_event->type)) { |
[email protected] | 936c6f5 | 2011-12-13 01:35:26 | [diff] [blame] | 561 | const WebMouseEvent& mouse_event = |
| 562 | *static_cast<const WebMouseEvent*>(input_event); |
| 563 | TRACE_EVENT2("renderer", "HandleMouseMove", |
| 564 | "x", mouse_event.x, "y", mouse_event.y); |
| 565 | prevent_default = WillHandleMouseEvent(mouse_event); |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 566 | } |
| 567 | |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 568 | if (WebInputEvent::isGestureEventType(input_event->type)) { |
| 569 | const WebGestureEvent& gesture_event = |
| 570 | *static_cast<const WebGestureEvent*>(input_event); |
| 571 | prevent_default = prevent_default || WillHandleGestureEvent(gesture_event); |
| 572 | } |
| 573 | |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 574 | bool processed = prevent_default; |
[email protected] | b68a0e5 | 2011-12-08 15:11:12 | [diff] [blame] | 575 | if (input_event->type != WebInputEvent::Char || !suppress_next_char_events_) { |
| 576 | suppress_next_char_events_ = false; |
| 577 | if (!processed && webwidget_) |
| 578 | processed = webwidget_->handleInputEvent(*input_event); |
| 579 | } |
| 580 | |
| 581 | // If this RawKeyDown event corresponds to a browser keyboard shortcut and |
| 582 | // it's not processed by webkit, then we need to suppress the upcoming Char |
| 583 | // events. |
| 584 | if (!processed && is_keyboard_shortcut) |
| 585 | suppress_next_char_events_ = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 586 | |
[email protected] | 3d5c243b | 2012-11-30 00:26:01 | [diff] [blame] | 587 | InputEventAckState ack_result = processed ? |
| 588 | INPUT_EVENT_ACK_STATE_CONSUMED : INPUT_EVENT_ACK_STATE_NOT_CONSUMED; |
| 589 | if (!processed && input_event->type == WebInputEvent::TouchStart) { |
| 590 | const WebTouchEvent& touch_event = |
| 591 | *static_cast<const WebTouchEvent*>(input_event); |
| 592 | ack_result = HasTouchEventHandlersAt(touch_event.touches[0].position) ? |
| 593 | INPUT_EVENT_ACK_STATE_NOT_CONSUMED : |
| 594 | INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; |
| 595 | } |
| 596 | |
[email protected] | a9fb30aa | 2011-10-06 06:58:46 | [diff] [blame] | 597 | IPC::Message* response = |
| 598 | new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type, |
[email protected] | 3d5c243b | 2012-11-30 00:26:01 | [diff] [blame] | 599 | ack_result); |
[email protected] | 3391a077 | 2012-03-28 00:32:07 | [diff] [blame] | 600 | bool event_type_gets_rate_limited = |
| 601 | input_event->type == WebInputEvent::MouseMove || |
| 602 | input_event->type == WebInputEvent::MouseWheel || |
| 603 | WebInputEvent::isTouchEventType(input_event->type); |
| 604 | bool is_input_throttled = |
[email protected] | ce2b28e | 2012-08-09 15:53:57 | [diff] [blame] | 605 | throttle_input_events_ && |
| 606 | ((webwidget_ ? webwidget_->isInputThrottled() : false) || |
| 607 | paint_aggregator_.HasPendingUpdate()); |
[email protected] | e282441 | 2009-02-27 01:57:05 | [diff] [blame] | 608 | |
[email protected] | f8868d7 | 2012-04-27 19:13:03 | [diff] [blame] | 609 | if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) { |
[email protected] | 12fbad81 | 2009-09-01 18:21:24 | [diff] [blame] | 610 | // We want to rate limit the input events in this case, so we'll wait for |
| 611 | // painting to finish before ACKing this message. |
[email protected] | 353a34c | 2010-05-28 23:35:17 | [diff] [blame] | 612 | if (pending_input_event_ack_.get()) { |
| 613 | // As two different kinds of events could cause us to postpone an ack |
| 614 | // we send it now, if we have one pending. The Browser should never |
| 615 | // send us the same kind of event we are delaying the ack for. |
| 616 | Send(pending_input_event_ack_.release()); |
| 617 | } |
[email protected] | 12fbad81 | 2009-09-01 18:21:24 | [diff] [blame] | 618 | pending_input_event_ack_.reset(response); |
| 619 | } else { |
| 620 | Send(response); |
| 621 | } |
| 622 | |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 623 | #if defined(OS_ANDROID) |
| 624 | // Allow the IME to be shown when the focus changes as a consequence |
| 625 | // of a processed touch end event. |
| 626 | if (input_event->type == WebInputEvent::TouchEnd && processed) |
| 627 | UpdateTextInputState(SHOW_IME_IF_NEEDED); |
| 628 | #endif |
| 629 | |
[email protected] | 5dd76821 | 2009-08-13 23:34:49 | [diff] [blame] | 630 | handling_input_event_ = false; |
[email protected] | 44670587 | 2009-09-10 07:22:48 | [diff] [blame] | 631 | |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 632 | if (!prevent_default) { |
| 633 | if (WebInputEvent::isKeyboardEventType(input_event->type)) |
| 634 | DidHandleKeyEvent(); |
| 635 | if (WebInputEvent::isMouseEventType(input_event->type)) |
| 636 | DidHandleMouseEvent(*(static_cast<const WebMouseEvent*>(input_event))); |
[email protected] | 2d0f2e9 | 2011-10-03 09:02:24 | [diff] [blame] | 637 | if (WebInputEvent::isTouchEventType(input_event->type)) |
| 638 | DidHandleTouchEvent(*(static_cast<const WebTouchEvent*>(input_event))); |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 639 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | void RenderWidget::OnMouseCaptureLost() { |
| 643 | if (webwidget_) |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 644 | webwidget_->mouseCaptureLost(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | void RenderWidget::OnSetFocus(bool enable) { |
| 648 | has_focus_ = enable; |
[email protected] | 9d166af | 2010-03-02 22:04:33 | [diff] [blame] | 649 | if (webwidget_) |
| 650 | webwidget_->setFocus(enable); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | void RenderWidget::ClearFocus() { |
| 654 | // We may have got the focus from the browser before this gets processed, in |
| 655 | // which case we do not want to unfocus ourself. |
| 656 | if (!has_focus_ && webwidget_) |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 657 | webwidget_->setFocus(false); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 658 | } |
| 659 | |
[email protected] | 2d5d09d5 | 2009-06-15 14:29:21 | [diff] [blame] | 660 | void RenderWidget::PaintRect(const gfx::Rect& rect, |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 661 | const gfx::Point& canvas_origin, |
[email protected] | 2d5d09d5 | 2009-06-15 14:29:21 | [diff] [blame] | 662 | skia::PlatformCanvas* canvas) { |
[email protected] | 50312bf | 2011-06-22 23:30:06 | [diff] [blame] | 663 | TRACE_EVENT2("renderer", "PaintRect", |
| 664 | "width", rect.width(), "height", rect.height()); |
[email protected] | 63ab5426 | 2012-11-09 15:58:45 | [diff] [blame] | 665 | |
| 666 | const bool kEnableGpuBenchmarking = |
| 667 | CommandLine::ForCurrentProcess()->HasSwitch( |
| 668 | switches::kEnableGpuBenchmarking); |
| 669 | base::TimeTicks rasterize_begin_ticks; |
| 670 | if (kEnableGpuBenchmarking) |
| 671 | rasterize_begin_ticks = base::TimeTicks::HighResNow(); |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 672 | canvas->save(); |
[email protected] | 2d5d09d5 | 2009-06-15 14:29:21 | [diff] [blame] | 673 | |
| 674 | // Bring the canvas into the coordinate system of the paint rect. |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 675 | canvas->translate(static_cast<SkScalar>(-canvas_origin.x()), |
| 676 | static_cast<SkScalar>(-canvas_origin.y())); |
[email protected] | 96c3499a | 2009-05-02 18:31:03 | [diff] [blame] | 677 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 678 | // If there is a custom background, tile it. |
| 679 | if (!background_.empty()) { |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 680 | SkPaint paint; |
[email protected] | 4e29afd | 2012-12-04 04:07:11 | [diff] [blame] | 681 | skia::RefPtr<SkShader> shader = skia::AdoptRef( |
| 682 | SkShader::CreateBitmapShader(background_, |
| 683 | SkShader::kRepeat_TileMode, |
| 684 | SkShader::kRepeat_TileMode)); |
| 685 | paint.setShader(shader.get()); |
[email protected] | fb10ec5b | 2011-10-24 17:54:20 | [diff] [blame] | 686 | |
| 687 | // Use kSrc_Mode to handle background_ transparency properly. |
| 688 | paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
| 689 | |
| 690 | // Canvas could contain multiple update rects. Clip to given rect so that |
| 691 | // we don't accidentally clear other update rects. |
| 692 | canvas->save(); |
[email protected] | 1835b9e | 2012-02-28 13:12:48 | [diff] [blame] | 693 | canvas->clipRect(gfx::RectToSkRect(rect)); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 694 | canvas->drawPaint(paint); |
[email protected] | fb10ec5b | 2011-10-24 17:54:20 | [diff] [blame] | 695 | canvas->restore(); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 696 | } |
| 697 | |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 698 | // First see if this rect is a plugin that can paint itself faster. |
| 699 | TransportDIB* optimized_dib = NULL; |
| 700 | gfx::Rect optimized_copy_rect, optimized_copy_location; |
[email protected] | 0f3a2d1 | 2012-09-01 03:37:20 | [diff] [blame] | 701 | float dib_scale_factor; |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 702 | webkit::ppapi::PluginInstance* optimized_instance = |
| 703 | GetBitmapForOptimizedPluginPaint(rect, &optimized_dib, |
| 704 | &optimized_copy_location, |
[email protected] | 0f3a2d1 | 2012-09-01 03:37:20 | [diff] [blame] | 705 | &optimized_copy_rect, |
| 706 | &dib_scale_factor); |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 707 | if (optimized_instance) { |
| 708 | // This plugin can be optimize-painted and we can just ask it to paint |
| 709 | // itself. We don't actually need the TransportDIB in this case. |
| 710 | // |
| 711 | // This is an optimization for PPAPI plugins that know they're on top of |
| 712 | // the page content. If this rect is inside such a plugin, we can save some |
| 713 | // time and avoid re-rendering the page content which we know will be |
| 714 | // covered by the plugin later (this time can be significant, especially |
| 715 | // for a playing movie that is invalidating a lot). |
| 716 | // |
| 717 | // In the plugin movie case, hopefully the similar call to |
| 718 | // GetBitmapForOptimizedPluginPaint in DoDeferredUpdate handles the |
| 719 | // painting, because that avoids copying the plugin image to a different |
| 720 | // paint rect. Unfortunately, if anything on the page is animating other |
| 721 | // than the movie, it break this optimization since the union of the |
| 722 | // invalid regions will be larger than the plugin. |
| 723 | // |
| 724 | // This code optimizes that case, where we can still avoid painting in |
| 725 | // WebKit and filling the background (which can be slow) and just painting |
| 726 | // the plugin. Unlike the DoDeferredUpdate case, an extra copy is still |
| 727 | // required. |
[email protected] | 63ab5426 | 2012-11-09 15:58:45 | [diff] [blame] | 728 | base::TimeTicks paint_begin_ticks; |
| 729 | if (kEnableGpuBenchmarking) |
| 730 | paint_begin_ticks = base::TimeTicks::HighResNow(); |
| 731 | |
[email protected] | df59dd4 | 2012-09-14 22:56:30 | [diff] [blame] | 732 | SkAutoCanvasRestore auto_restore(canvas, true); |
| 733 | canvas->scale(device_scale_factor_, device_scale_factor_); |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 734 | optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas), |
[email protected] | 2df1b36 | 2011-01-21 21:22:27 | [diff] [blame] | 735 | optimized_copy_location, rect); |
[email protected] | ea43e75 | 2012-09-06 22:39:21 | [diff] [blame] | 736 | canvas->restore(); |
[email protected] | 63ab5426 | 2012-11-09 15:58:45 | [diff] [blame] | 737 | if (kEnableGpuBenchmarking) { |
| 738 | base::TimeDelta paint_time = |
| 739 | base::TimeTicks::HighResNow() - paint_begin_ticks; |
| 740 | if (!is_accelerated_compositing_active_) |
| 741 | software_stats_.totalPaintTimeInSeconds += paint_time.InSecondsF(); |
| 742 | } |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 743 | } else { |
| 744 | // Normal painting case. |
[email protected] | 63ab5426 | 2012-11-09 15:58:45 | [diff] [blame] | 745 | base::TimeTicks paint_begin_ticks; |
| 746 | if (kEnableGpuBenchmarking) |
| 747 | paint_begin_ticks = base::TimeTicks::HighResNow(); |
| 748 | |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 749 | webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect); |
[email protected] | 63ab5426 | 2012-11-09 15:58:45 | [diff] [blame] | 750 | |
| 751 | if (kEnableGpuBenchmarking) { |
| 752 | base::TimeDelta paint_time = |
| 753 | base::TimeTicks::HighResNow() - paint_begin_ticks; |
| 754 | if (!is_accelerated_compositing_active_) |
| 755 | software_stats_.totalPaintTimeInSeconds += paint_time.InSecondsF(); |
| 756 | } |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 757 | |
| 758 | // Flush to underlying bitmap. TODO(darin): is this needed? |
[email protected] | 62f2e80 | 2011-05-26 14:28:35 | [diff] [blame] | 759 | skia::GetTopDevice(*canvas)->accessBitmap(false); |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 760 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 761 | |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 762 | PaintDebugBorder(rect, canvas); |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 763 | canvas->restore(); |
[email protected] | 63ab5426 | 2012-11-09 15:58:45 | [diff] [blame] | 764 | |
| 765 | if (kEnableGpuBenchmarking) { |
| 766 | base::TimeDelta rasterize_time = |
| 767 | base::TimeTicks::HighResNow() - rasterize_begin_ticks; |
| 768 | software_stats_.totalRasterizeTimeInSeconds += rasterize_time.InSecondsF(); |
| 769 | |
| 770 | int64 num_pixels_processed = rect.width() * rect.height(); |
| 771 | software_stats_.totalPixelsPainted += num_pixels_processed; |
| 772 | software_stats_.totalPixelsRasterized += num_pixels_processed; |
| 773 | } |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | void RenderWidget::PaintDebugBorder(const gfx::Rect& rect, |
| 777 | skia::PlatformCanvas* canvas) { |
| 778 | static bool kPaintBorder = |
| 779 | CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects); |
| 780 | if (!kPaintBorder) |
| 781 | return; |
| 782 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 783 | // Cycle through these colors to help distinguish new paint rects. |
| 784 | const SkColor colors[] = { |
| 785 | SkColorSetARGB(0x3F, 0xFF, 0, 0), |
| 786 | SkColorSetARGB(0x3F, 0xFF, 0, 0xFF), |
| 787 | SkColorSetARGB(0x3F, 0, 0, 0xFF), |
| 788 | }; |
| 789 | static int color_selector = 0; |
| 790 | |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 791 | SkPaint paint; |
| 792 | paint.setStyle(SkPaint::kStroke_Style); |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 793 | paint.setColor(colors[color_selector++ % arraysize(colors)]); |
[email protected] | 4fb6684 | 2009-12-04 21:41:00 | [diff] [blame] | 794 | paint.setStrokeWidth(1); |
| 795 | |
| 796 | SkIRect irect; |
| 797 | irect.set(rect.x(), rect.y(), rect.right() - 1, rect.bottom() - 1); |
| 798 | canvas->drawIRect(irect, paint); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 799 | } |
| 800 | |
[email protected] | 52ccd0ea | 2011-02-16 01:09:05 | [diff] [blame] | 801 | void RenderWidget::AnimationCallback() { |
[email protected] | 921244e4 | 2011-07-20 16:36:30 | [diff] [blame] | 802 | TRACE_EVENT0("renderer", "RenderWidget::AnimationCallback"); |
[email protected] | 921244e4 | 2011-07-20 16:36:30 | [diff] [blame] | 803 | if (!animation_update_pending_) { |
| 804 | TRACE_EVENT0("renderer", "EarlyOut_NoAnimationUpdatePending"); |
[email protected] | 7c4329e | 2011-02-18 22:02:59 | [diff] [blame] | 805 | return; |
[email protected] | 921244e4 | 2011-07-20 16:36:30 | [diff] [blame] | 806 | } |
[email protected] | bd37ae25 | 2011-06-03 01:28:18 | [diff] [blame] | 807 | if (!animation_floor_time_.is_null() && IsRenderingVSynced()) { |
[email protected] | 7c4329e | 2011-02-18 22:02:59 | [diff] [blame] | 808 | // Record when we fired (according to base::Time::Now()) relative to when |
| 809 | // we posted the task to quantify how much the base::Time/base::TimeTicks |
| 810 | // skew is affecting animations. |
| 811 | base::TimeDelta animation_callback_delay = base::Time::Now() - |
| 812 | (animation_floor_time_ - base::TimeDelta::FromMilliseconds(16)); |
| 813 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AnimationCallbackDelayTime", |
| 814 | animation_callback_delay, |
| 815 | base::TimeDelta::FromMilliseconds(0), |
| 816 | base::TimeDelta::FromMilliseconds(30), |
| 817 | 25); |
| 818 | } |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 819 | DoDeferredUpdateAndSendInputAck(); |
[email protected] | 12fbad81 | 2009-09-01 18:21:24 | [diff] [blame] | 820 | } |
| 821 | |
[email protected] | 52ccd0ea | 2011-02-16 01:09:05 | [diff] [blame] | 822 | void RenderWidget::AnimateIfNeeded() { |
[email protected] | 7c4329e | 2011-02-18 22:02:59 | [diff] [blame] | 823 | if (!animation_update_pending_) |
| 824 | return; |
[email protected] | bd37ae25 | 2011-06-03 01:28:18 | [diff] [blame] | 825 | |
| 826 | // Target 60FPS if vsync is on. Go as fast as we can if vsync is off. |
[email protected] | 02798a98 | 2012-01-27 00:45:33 | [diff] [blame] | 827 | base::TimeDelta animationInterval = IsRenderingVSynced() ? |
| 828 | base::TimeDelta::FromMilliseconds(16) : base::TimeDelta(); |
[email protected] | bd37ae25 | 2011-06-03 01:28:18 | [diff] [blame] | 829 | |
[email protected] | 7c4329e | 2011-02-18 22:02:59 | [diff] [blame] | 830 | base::Time now = base::Time::Now(); |
[email protected] | 51e403bb | 2012-03-02 21:09:45 | [diff] [blame] | 831 | |
| 832 | // animation_floor_time_ is the earliest time that we should animate when |
| 833 | // using the dead reckoning software scheduler. If we're using swapbuffers |
| 834 | // complete callbacks to rate limit, we can ignore this floor. |
| 835 | if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) { |
[email protected] | 921244e4 | 2011-07-20 16:36:30 | [diff] [blame] | 836 | TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded") |
[email protected] | 02798a98 | 2012-01-27 00:45:33 | [diff] [blame] | 837 | animation_floor_time_ = now + animationInterval; |
[email protected] | bd37ae25 | 2011-06-03 01:28:18 | [diff] [blame] | 838 | // Set a timer to call us back after animationInterval before |
[email protected] | 7c4329e | 2011-02-18 22:02:59 | [diff] [blame] | 839 | // running animation callbacks so that if a callback requests another |
| 840 | // we'll be sure to run it at the proper time. |
[email protected] | 350ce870 | 2012-03-09 04:23:38 | [diff] [blame] | 841 | animation_timer_.Stop(); |
| 842 | animation_timer_.Start(FROM_HERE, animationInterval, this, |
| 843 | &RenderWidget::AnimationCallback); |
[email protected] | 7c4329e | 2011-02-18 22:02:59 | [diff] [blame] | 844 | animation_update_pending_ = false; |
[email protected] | a5922cc | 2011-05-24 23:06:30 | [diff] [blame] | 845 | webwidget_->animate(0.0); |
[email protected] | 7c4329e | 2011-02-18 22:02:59 | [diff] [blame] | 846 | return; |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 847 | } |
[email protected] | bd37ae25 | 2011-06-03 01:28:18 | [diff] [blame] | 848 | TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently"); |
[email protected] | 350ce870 | 2012-03-09 04:23:38 | [diff] [blame] | 849 | if (!animation_timer_.IsRunning()) { |
| 850 | // This code uses base::Time::Now() to calculate the floor and next fire |
| 851 | // time because javascript's Date object uses base::Time::Now(). The |
| 852 | // message loop uses base::TimeTicks, which on windows can have a |
| 853 | // different granularity than base::Time. |
| 854 | // The upshot of all this is that this function might be called before |
| 855 | // base::Time::Now() has advanced past the animation_floor_time_. To |
| 856 | // avoid exposing this delay to javascript, we keep posting delayed |
| 857 | // tasks until base::Time::Now() has advanced far enough. |
| 858 | base::TimeDelta delay = animation_floor_time_ - now; |
| 859 | animation_timer_.Start(FROM_HERE, delay, this, |
| 860 | &RenderWidget::AnimationCallback); |
| 861 | } |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 862 | } |
| 863 | |
[email protected] | bd37ae25 | 2011-06-03 01:28:18 | [diff] [blame] | 864 | bool RenderWidget::IsRenderingVSynced() { |
| 865 | // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is |
| 866 | // not caught by this check. This will lead to artificially low frame rates |
| 867 | // for people who force vsync off at a driver level and expect Chrome to speed |
| 868 | // up. |
| 869 | return !has_disable_gpu_vsync_switch_; |
| 870 | } |
| 871 | |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 872 | void RenderWidget::InvalidationCallback() { |
[email protected] | 50312bf | 2011-06-22 23:30:06 | [diff] [blame] | 873 | TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback"); |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 874 | invalidation_task_posted_ = false; |
| 875 | DoDeferredUpdateAndSendInputAck(); |
| 876 | } |
| 877 | |
| 878 | void RenderWidget::DoDeferredUpdateAndSendInputAck() { |
[email protected] | 52ccd0ea | 2011-02-16 01:09:05 | [diff] [blame] | 879 | DoDeferredUpdate(); |
| 880 | |
| 881 | if (pending_input_event_ack_.get()) |
| 882 | Send(pending_input_event_ack_.release()); |
[email protected] | ee3d3ad | 2011-02-04 00:42:21 | [diff] [blame] | 883 | } |
| 884 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 885 | void RenderWidget::DoDeferredUpdate() { |
[email protected] | 366ae24 | 2011-05-10 02:23:58 | [diff] [blame] | 886 | TRACE_EVENT0("renderer", "RenderWidget::DoDeferredUpdate"); |
[email protected] | 71e2f0a | 2011-03-15 22:25:08 | [diff] [blame] | 887 | |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 888 | if (!webwidget_) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 889 | return; |
[email protected] | 05a980d7a | 2012-02-07 22:16:42 | [diff] [blame] | 890 | |
[email protected] | fc4404d | 2012-11-07 19:53:30 | [diff] [blame] | 891 | if (!init_complete_) { |
| 892 | TRACE_EVENT0("renderer", "EarlyOut_InitNotComplete"); |
[email protected] | 05a980d7a | 2012-02-07 22:16:42 | [diff] [blame] | 893 | return; |
| 894 | } |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 895 | if (update_reply_pending_) { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 896 | TRACE_EVENT0("renderer", "EarlyOut_UpdateReplyPending"); |
| 897 | return; |
| 898 | } |
[email protected] | 9ca8462 | 2011-06-02 23:46:39 | [diff] [blame] | 899 | if (is_accelerated_compositing_active_ && |
| 900 | num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) { |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 901 | TRACE_EVENT0("renderer", "EarlyOut_MaxSwapBuffersPending"); |
| 902 | return; |
| 903 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 904 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 905 | // Suppress updating when we are hidden. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 906 | if (is_hidden_ || size_.IsEmpty()) { |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 907 | paint_aggregator_.ClearPendingUpdate(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 908 | needs_repainting_on_restore_ = true; |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 909 | TRACE_EVENT0("renderer", "EarlyOut_NotVisible"); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 910 | return; |
| 911 | } |
| 912 | |
[email protected] | 05a980d7a | 2012-02-07 22:16:42 | [diff] [blame] | 913 | if (is_accelerated_compositing_active_) |
| 914 | using_asynchronous_swapbuffers_ = SupportsAsynchronousSwapBuffers(); |
| 915 | |
[email protected] | 0fb93f5 | 2011-05-18 23:13:56 | [diff] [blame] | 916 | // Tracking of frame rate jitter |
| 917 | base::TimeTicks frame_begin_ticks = base::TimeTicks::Now(); |
[email protected] | 541dcd5 | 2012-03-15 15:57:51 | [diff] [blame] | 918 | webwidget_->instrumentBeginFrame(); |
[email protected] | 52ccd0ea | 2011-02-16 01:09:05 | [diff] [blame] | 919 | AnimateIfNeeded(); |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 920 | |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 921 | // Layout may generate more invalidation. It may also enable the |
| 922 | // GPU acceleration, so make sure to run layout before we send the |
| 923 | // GpuRenderingActivated message. |
| 924 | webwidget_->layout(); |
| 925 | |
[email protected] | dcca3aa9 | 2012-02-17 23:03:37 | [diff] [blame] | 926 | // The following two can result in further layout and possibly |
| 927 | // enable GPU acceleration so they need to be called before any painting |
| 928 | // is done. |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 929 | UpdateTextInputState(DO_NOT_SHOW_IME); |
[email protected] | dcca3aa9 | 2012-02-17 23:03:37 | [diff] [blame] | 930 | UpdateSelectionBounds(); |
| 931 | |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 932 | // Suppress painting if nothing is dirty. This has to be done after updating |
| 933 | // animations running layout as these may generate further invalidations. |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 934 | if (!paint_aggregator_.HasPendingUpdate()) { |
| 935 | TRACE_EVENT0("renderer", "EarlyOut_NoPendingUpdate"); |
[email protected] | 541dcd5 | 2012-03-15 15:57:51 | [diff] [blame] | 936 | webwidget_->instrumentCancelFrame(); |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 937 | return; |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 938 | } |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 939 | |
[email protected] | 479b017 | 2012-10-29 19:27:09 | [diff] [blame] | 940 | if (!is_accelerated_compositing_active_ && |
[email protected] | cb643093 | 2012-10-31 00:53:36 | [diff] [blame] | 941 | !is_threaded_compositing_enabled_ && |
[email protected] | 479b017 | 2012-10-29 19:27:09 | [diff] [blame] | 942 | ForceCompositingModeEnabled()) { |
| 943 | webwidget_->enterForceCompositingMode(true); |
| 944 | } |
| 945 | |
[email protected] | 872ae5b | 2011-05-26 20:20:50 | [diff] [blame] | 946 | if (!last_do_deferred_update_time_.is_null()) { |
[email protected] | 0fb93f5 | 2011-05-18 23:13:56 | [diff] [blame] | 947 | base::TimeDelta delay = frame_begin_ticks - last_do_deferred_update_time_; |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 948 | if (is_accelerated_compositing_active_) { |
[email protected] | 0fb93f5 | 2011-05-18 23:13:56 | [diff] [blame] | 949 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.AccelDoDeferredUpdateDelay", |
| 950 | delay, |
| 951 | base::TimeDelta::FromMilliseconds(1), |
[email protected] | b604cf8 | 2012-07-19 05:31:41 | [diff] [blame] | 952 | base::TimeDelta::FromMilliseconds(120), |
| 953 | 60); |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 954 | } else { |
[email protected] | 0fb93f5 | 2011-05-18 23:13:56 | [diff] [blame] | 955 | UMA_HISTOGRAM_CUSTOM_TIMES("Renderer4.SoftwareDoDeferredUpdateDelay", |
| 956 | delay, |
| 957 | base::TimeDelta::FromMilliseconds(1), |
[email protected] | b604cf8 | 2012-07-19 05:31:41 | [diff] [blame] | 958 | base::TimeDelta::FromMilliseconds(120), |
| 959 | 60); |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 960 | } |
[email protected] | 872ae5b | 2011-05-26 20:20:50 | [diff] [blame] | 961 | |
| 962 | // Calculate filtered time per frame: |
| 963 | float frame_time_elapsed = static_cast<float>(delay.InSecondsF()); |
| 964 | filtered_time_per_frame_ = |
| 965 | 0.9f * filtered_time_per_frame_ + 0.1f * frame_time_elapsed; |
[email protected] | 0fb93f5 | 2011-05-18 23:13:56 | [diff] [blame] | 966 | } |
| 967 | last_do_deferred_update_time_ = frame_begin_ticks; |
| 968 | |
[email protected] | fef5e397 | 2012-08-07 03:59:47 | [diff] [blame] | 969 | if (!is_accelerated_compositing_active_) { |
| 970 | software_stats_.numAnimationFrames++; |
| 971 | software_stats_.numFramesSentToScreen++; |
| 972 | } |
| 973 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 974 | // OK, save the pending update to a local since painting may cause more |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 975 | // invalidation. Some WebCore rendering objects only layout when painted. |
[email protected] | dd01581 | 2010-12-06 23:39:30 | [diff] [blame] | 976 | PaintAggregator::PendingUpdate update; |
| 977 | paint_aggregator_.PopPendingUpdate(&update); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 978 | |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 979 | gfx::Rect scroll_damage = update.GetScrollDamage(); |
[email protected] | ce112fe | 2012-10-29 22:52:18 | [diff] [blame] | 980 | gfx::Rect bounds = gfx::UnionRects(update.GetPaintBounds(), scroll_damage); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 981 | |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 982 | // Notify derived classes that we're about to initiate a paint. |
| 983 | WillInitiatePaint(); |
| 984 | |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 985 | // A plugin may be able to do an optimized paint. First check this, in which |
| 986 | // case we can skip all of the bitmap generation and regular paint code. |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 987 | // This optimization allows PPAPI plugins that declare themselves on top of |
| 988 | // the page (like a traditional windowed plugin) to be able to animate (think |
| 989 | // movie playing) without repeatedly re-painting the page underneath, or |
| 990 | // copying the plugin backing store (since we can send the plugin's backing |
| 991 | // store directly to the browser). |
| 992 | // |
| 993 | // This optimization only works when the entire invalid region is contained |
| 994 | // within the plugin. There is a related optimization in PaintRect for the |
| 995 | // case where there may be multiple invalid regions. |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 996 | TransportDIB* dib = NULL; |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 997 | gfx::Rect optimized_copy_rect, optimized_copy_location; |
[email protected] | 0f3a2d1 | 2012-09-01 03:37:20 | [diff] [blame] | 998 | float dib_scale_factor = 1; |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 999 | DCHECK(!pending_update_params_.get()); |
| 1000 | pending_update_params_.reset(new ViewHostMsg_UpdateRect_Params); |
[email protected] | 990278ff | 2012-11-13 02:12:55 | [diff] [blame] | 1001 | pending_update_params_->scroll_delta = update.scroll_delta; |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 1002 | pending_update_params_->scroll_rect = update.scroll_rect; |
| 1003 | pending_update_params_->view_size = size_; |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 1004 | pending_update_params_->plugin_window_moves.swap(plugin_window_moves_); |
| 1005 | pending_update_params_->flags = next_paint_flags_; |
| 1006 | pending_update_params_->scroll_offset = GetScrollOffset(); |
| 1007 | pending_update_params_->needs_ack = true; |
[email protected] | 7ded9f1 | 2012-06-13 20:47:09 | [diff] [blame] | 1008 | pending_update_params_->scale_factor = device_scale_factor_; |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 1009 | next_paint_flags_ = 0; |
[email protected] | ea3ee0a | 2012-05-15 03:43:09 | [diff] [blame] | 1010 | need_update_rect_for_auto_resize_ = false; |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 1011 | |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 1012 | if (update.scroll_rect.IsEmpty() && |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 1013 | !is_accelerated_compositing_active_ && |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 1014 | GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location, |
[email protected] | 0f3a2d1 | 2012-09-01 03:37:20 | [diff] [blame] | 1015 | &optimized_copy_rect, |
| 1016 | &dib_scale_factor)) { |
[email protected] | 2df1b36 | 2011-01-21 21:22:27 | [diff] [blame] | 1017 | // Only update the part of the plugin that actually changed. |
[email protected] | d403050 | 2012-10-23 16:51:47 | [diff] [blame] | 1018 | optimized_copy_rect.Intersect(bounds); |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 1019 | pending_update_params_->bitmap = dib->id(); |
| 1020 | pending_update_params_->bitmap_rect = optimized_copy_location; |
| 1021 | pending_update_params_->copy_rects.push_back(optimized_copy_rect); |
[email protected] | 0f3a2d1 | 2012-09-01 03:37:20 | [diff] [blame] | 1022 | pending_update_params_->scale_factor = dib_scale_factor; |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 1023 | } else if (!is_accelerated_compositing_active_) { |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1024 | // Compute a buffer for painting and cache it. |
[email protected] | ce112fe | 2012-10-29 22:52:18 | [diff] [blame] | 1025 | gfx::Rect pixel_bounds = gfx::ToFlooredRectDeprecated( |
| 1026 | gfx::ScaleRect(bounds, device_scale_factor_)); |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 1027 | scoped_ptr<skia::PlatformCanvas> canvas( |
[email protected] | b4d0845 | 2010-10-05 17:34:35 | [diff] [blame] | 1028 | RenderProcess::current()->GetDrawingCanvas(¤t_paint_buf_, |
[email protected] | f1cccb3 | 2012-06-06 18:29:59 | [diff] [blame] | 1029 | pixel_bounds)); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1030 | if (!canvas.get()) { |
| 1031 | NOTREACHED(); |
| 1032 | return; |
| 1033 | } |
[email protected] | cef3362f | 2009-12-21 17:48:45 | [diff] [blame] | 1034 | |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1035 | // We may get back a smaller canvas than we asked for. |
| 1036 | // TODO(darin): This seems like it could cause painting problems! |
[email protected] | f1cccb3 | 2012-06-06 18:29:59 | [diff] [blame] | 1037 | DCHECK_EQ(pixel_bounds.width(), canvas->getDevice()->width()); |
| 1038 | DCHECK_EQ(pixel_bounds.height(), canvas->getDevice()->height()); |
| 1039 | pixel_bounds.set_width(canvas->getDevice()->width()); |
| 1040 | pixel_bounds.set_height(canvas->getDevice()->height()); |
| 1041 | bounds.set_width(pixel_bounds.width() / device_scale_factor_); |
| 1042 | bounds.set_height(pixel_bounds.height() / device_scale_factor_); |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1043 | |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1044 | HISTOGRAM_COUNTS_100("MPArch.RW_PaintRectCount", update.paint_rects.size()); |
| 1045 | |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 1046 | pending_update_params_->bitmap = current_paint_buf_->id(); |
| 1047 | pending_update_params_->bitmap_rect = bounds; |
| 1048 | |
| 1049 | std::vector<gfx::Rect>& copy_rects = pending_update_params_->copy_rects; |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1050 | // The scroll damage is just another rectangle to paint and copy. |
| 1051 | copy_rects.swap(update.paint_rects); |
| 1052 | if (!scroll_damage.IsEmpty()) |
| 1053 | copy_rects.push_back(scroll_damage); |
| 1054 | |
| 1055 | for (size_t i = 0; i < copy_rects.size(); ++i) |
[email protected] | f1cccb3 | 2012-06-06 18:29:59 | [diff] [blame] | 1056 | PaintRect(copy_rects[i], pixel_bounds.origin(), canvas.get()); |
[email protected] | 60a5007 | 2012-01-11 02:05:35 | [diff] [blame] | 1057 | |
| 1058 | // Software FPS tick for performance tests. The accelerated path traces the |
| 1059 | // frame events in didCommitAndDrawCompositorFrame. See throughput_tests.cc. |
| 1060 | // NOTE: Tests may break if this event is renamed or moved. |
| 1061 | UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickSW"); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1062 | } else { // Accelerated compositing path |
| 1063 | // Begin painting. |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 1064 | // If painting is done via the gpu process then we don't set any damage |
| 1065 | // rects to save the browser process from doing unecessary work. |
| 1066 | pending_update_params_->bitmap_rect = bounds; |
| 1067 | pending_update_params_->scroll_rect = gfx::Rect(); |
| 1068 | // We don't need an ack, because we're not sharing a DIB with the browser. |
| 1069 | // If it needs to (e.g. composited UI), the GPU process does its own ACK |
| 1070 | // with the browser for the GPU surface. |
| 1071 | pending_update_params_->needs_ack = false; |
[email protected] | 50bd645 | 2010-11-27 19:39:42 | [diff] [blame] | 1072 | webwidget_->composite(false); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1073 | } |
| 1074 | |
[email protected] | 936c6f5 | 2011-12-13 01:35:26 | [diff] [blame] | 1075 | // If we're holding a pending input event ACK, send the ACK before sending the |
| 1076 | // UpdateReply message so we can receive another input event before the |
| 1077 | // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within |
| 1078 | // the UpdateRect IPC message handler. |
| 1079 | if (pending_input_event_ack_.get()) |
| 1080 | Send(pending_input_event_ack_.release()); |
| 1081 | |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 1082 | // If composite() called SwapBuffers, pending_update_params_ will be reset (in |
| 1083 | // OnSwapBuffersPosted), meaning a message has been added to the |
| 1084 | // updates_pending_swap_ queue, that will be sent later. Otherwise, we send |
| 1085 | // the message now. |
| 1086 | if (pending_update_params_.get()) { |
| 1087 | // sending an ack to browser process that the paint is complete... |
| 1088 | update_reply_pending_ = pending_update_params_->needs_ack; |
| 1089 | Send(new ViewHostMsg_UpdateRect(routing_id_, *pending_update_params_)); |
| 1090 | pending_update_params_.reset(); |
[email protected] | b167ca66 | 2010-05-14 00:05:34 | [diff] [blame] | 1091 | } |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1092 | |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 1093 | // If we're software rendering then we're done initiating the paint. |
| 1094 | if (!is_accelerated_compositing_active_) |
| 1095 | DidInitiatePaint(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | /////////////////////////////////////////////////////////////////////////////// |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1099 | // WebWidgetClient |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1100 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1101 | void RenderWidget::didInvalidateRect(const WebRect& rect) { |
[email protected] | 479b017 | 2012-10-29 19:27:09 | [diff] [blame] | 1102 | TRACE_EVENT2("renderer", "RenderWidget::didInvalidateRect", |
| 1103 | "width", rect.width, "height", rect.height); |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 1104 | // The invalidated rect might be outside the bounds of the view. |
[email protected] | ee8d6fd | 2010-05-26 17:05:48 | [diff] [blame] | 1105 | gfx::Rect view_rect(size_); |
[email protected] | ce112fe | 2012-10-29 22:52:18 | [diff] [blame] | 1106 | gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect); |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 1107 | if (damaged_rect.IsEmpty()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1108 | return; |
| 1109 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 1110 | paint_aggregator_.InvalidateRect(damaged_rect); |
| 1111 | |
| 1112 | // We may not need to schedule another call to DoDeferredUpdate. |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1113 | if (invalidation_task_posted_) |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 1114 | return; |
| 1115 | if (!paint_aggregator_.HasPendingUpdate()) |
| 1116 | return; |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 1117 | if (update_reply_pending_ || |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1118 | num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) |
| 1119 | return; |
| 1120 | |
| 1121 | // When GPU rendering, combine pending animations and invalidations into |
| 1122 | // a single update. |
[email protected] | 816edc6 | 2012-03-17 01:27:22 | [diff] [blame] | 1123 | if (is_accelerated_compositing_active_ && |
| 1124 | animation_update_pending_ && |
| 1125 | animation_timer_.IsRunning()) |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 1126 | return; |
| 1127 | |
| 1128 | // Perform updating asynchronously. This serves two purposes: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1129 | // 1) Ensures that we call WebView::Paint without a bunch of other junk |
| 1130 | // on the call stack. |
| 1131 | // 2) Allows us to collect more damage rects before painting to help coalesce |
| 1132 | // the work that we will need to do. |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1133 | invalidation_task_posted_ = true; |
[email protected] | 32876ae | 2011-11-15 22:25:21 | [diff] [blame] | 1134 | MessageLoop::current()->PostTask( |
| 1135 | FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1136 | } |
| 1137 | |
[email protected] | 990278ff | 2012-11-13 02:12:55 | [diff] [blame] | 1138 | void RenderWidget::didScrollRect(int dx, int dy, |
| 1139 | const WebRect& clip_rect) { |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1140 | // Drop scrolls on the floor when we are in compositing mode. |
| 1141 | // TODO(nduca): stop WebViewImpl from sending scrolls in the first place. |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 1142 | if (is_accelerated_compositing_active_) |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1143 | return; |
| 1144 | |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 1145 | // The scrolled rect might be outside the bounds of the view. |
[email protected] | ee8d6fd | 2010-05-26 17:05:48 | [diff] [blame] | 1146 | gfx::Rect view_rect(size_); |
[email protected] | ce112fe | 2012-10-29 22:52:18 | [diff] [blame] | 1147 | gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect); |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 1148 | if (damaged_rect.IsEmpty()) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1149 | return; |
| 1150 | |
[email protected] | 990278ff | 2012-11-13 02:12:55 | [diff] [blame] | 1151 | paint_aggregator_.ScrollRect(gfx::Vector2d(dx, dy), damaged_rect); |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 1152 | |
| 1153 | // We may not need to schedule another call to DoDeferredUpdate. |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1154 | if (invalidation_task_posted_) |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 1155 | return; |
| 1156 | if (!paint_aggregator_.HasPendingUpdate()) |
| 1157 | return; |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 1158 | if (update_reply_pending_ || |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1159 | num_swapbuffers_complete_pending_ >= kMaxSwapBuffersPending) |
| 1160 | return; |
| 1161 | |
| 1162 | // When GPU rendering, combine pending animations and invalidations into |
| 1163 | // a single update. |
[email protected] | 816edc6 | 2012-03-17 01:27:22 | [diff] [blame] | 1164 | if (is_accelerated_compositing_active_ && |
| 1165 | animation_update_pending_ && |
| 1166 | animation_timer_.IsRunning()) |
[email protected] | 552e600 | 2009-11-19 05:24:57 | [diff] [blame] | 1167 | return; |
| 1168 | |
| 1169 | // Perform updating asynchronously. This serves two purposes: |
| 1170 | // 1) Ensures that we call WebView::Paint without a bunch of other junk |
| 1171 | // on the call stack. |
| 1172 | // 2) Allows us to collect more damage rects before painting to help coalesce |
| 1173 | // the work that we will need to do. |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1174 | invalidation_task_posted_ = true; |
[email protected] | 32876ae | 2011-11-15 22:25:21 | [diff] [blame] | 1175 | MessageLoop::current()->PostTask( |
| 1176 | FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1177 | } |
| 1178 | |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 1179 | void RenderWidget::didAutoResize(const WebSize& new_size) { |
[email protected] | ea3ee0a | 2012-05-15 03:43:09 | [diff] [blame] | 1180 | if (size_.width() != new_size.width || size_.height() != new_size.height) { |
| 1181 | size_ = new_size; |
| 1182 | need_update_rect_for_auto_resize_ = true; |
[email protected] | 240b5c3 | 2012-11-09 19:17:18 | [diff] [blame] | 1183 | // If we don't clear PaintAggregator after changing autoResize state, then |
| 1184 | // we might end up in a situation where bitmap_rect is larger than the |
| 1185 | // view_size. By clearing PaintAggregator, we ensure that we don't end up |
| 1186 | // with invalid damage rects. |
| 1187 | paint_aggregator_.ClearPendingUpdate(); |
[email protected] | ea3ee0a | 2012-05-15 03:43:09 | [diff] [blame] | 1188 | } |
[email protected] | 244ac189 | 2011-12-02 17:04:47 | [diff] [blame] | 1189 | } |
| 1190 | |
[email protected] | 91acd1c | 2012-03-14 08:32:39 | [diff] [blame] | 1191 | void RenderWidget::didActivateCompositor(int input_handler_identifier) { |
[email protected] | ea162f9 | 2011-10-04 23:08:22 | [diff] [blame] | 1192 | TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor"); |
| 1193 | |
[email protected] | c63b4d4 | 2012-04-26 01:01:07 | [diff] [blame] | 1194 | #if !defined(OS_MACOSX) |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 1195 | if (!is_accelerated_compositing_active_) { |
| 1196 | // When not in accelerated compositing mode, in certain cases (e.g. waiting |
| 1197 | // for a resize or if no backing store) the RenderWidgetHost is blocking the |
| 1198 | // browser's UI thread for some time, waiting for an UpdateRect. If we are |
| 1199 | // going to switch to accelerated compositing, the GPU process may need |
| 1200 | // round-trips to the browser's UI thread before finishing the frame, |
| 1201 | // causing deadlocks if we delay the UpdateRect until we receive the |
| 1202 | // OnSwapBuffersComplete. So send a dummy message that will unblock the |
[email protected] | c63b4d4 | 2012-04-26 01:01:07 | [diff] [blame] | 1203 | // browser's UI thread. This is not necessary on Mac, because SwapBuffers |
| 1204 | // now unblocks GetBackingStore on Mac. |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 1205 | Send(new ViewHostMsg_UpdateIsDelayed(routing_id_)); |
| 1206 | } |
[email protected] | c63b4d4 | 2012-04-26 01:01:07 | [diff] [blame] | 1207 | #endif |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 1208 | |
[email protected] | ea162f9 | 2011-10-04 23:08:22 | [diff] [blame] | 1209 | is_accelerated_compositing_active_ = true; |
[email protected] | 50bd645 | 2010-11-27 19:39:42 | [diff] [blame] | 1210 | Send(new ViewHostMsg_DidActivateAcceleratedCompositing( |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1211 | routing_id_, is_accelerated_compositing_active_)); |
[email protected] | ea162f9 | 2011-10-04 23:08:22 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | void RenderWidget::didDeactivateCompositor() { |
| 1215 | TRACE_EVENT0("gpu", "RenderWidget::didDeactivateCompositor"); |
| 1216 | |
| 1217 | is_accelerated_compositing_active_ = false; |
| 1218 | Send(new ViewHostMsg_DidActivateAcceleratedCompositing( |
| 1219 | routing_id_, is_accelerated_compositing_active_)); |
| 1220 | |
[email protected] | ea162f9 | 2011-10-04 23:08:22 | [diff] [blame] | 1221 | if (using_asynchronous_swapbuffers_) |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1222 | using_asynchronous_swapbuffers_ = false; |
[email protected] | 479b017 | 2012-10-29 19:27:09 | [diff] [blame] | 1223 | |
| 1224 | // In single-threaded mode, we exit force compositing mode and re-enter in |
| 1225 | // DoDeferredUpdate() if appropriate. In threaded compositing mode, |
| 1226 | // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and |
| 1227 | // entering force compositing mode at the appropriate times. |
[email protected] | cb643093 | 2012-10-31 00:53:36 | [diff] [blame] | 1228 | if (!is_threaded_compositing_enabled_) |
[email protected] | 479b017 | 2012-10-29 19:27:09 | [diff] [blame] | 1229 | webwidget_->enterForceCompositingMode(false); |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 1230 | } |
| 1231 | |
[email protected] | 9cd43a6 | 2012-03-26 08:03:56 | [diff] [blame] | 1232 | void RenderWidget::willBeginCompositorFrame() { |
| 1233 | TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame"); |
[email protected] | abe8b3a | 2012-03-28 21:19:37 | [diff] [blame] | 1234 | |
| 1235 | DCHECK(RenderThreadImpl::current()->compositor_thread()); |
| 1236 | |
| 1237 | // The following two can result in further layout and possibly |
| 1238 | // enable GPU acceleration so they need to be called before any painting |
| 1239 | // is done. |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 1240 | UpdateTextInputState(DO_NOT_SHOW_IME); |
[email protected] | abe8b3a | 2012-03-28 21:19:37 | [diff] [blame] | 1241 | UpdateSelectionBounds(); |
| 1242 | |
[email protected] | 9cd43a6 | 2012-03-26 08:03:56 | [diff] [blame] | 1243 | WillInitiatePaint(); |
| 1244 | } |
| 1245 | |
[email protected] | 3391a077 | 2012-03-28 00:32:07 | [diff] [blame] | 1246 | void RenderWidget::didBecomeReadyForAdditionalInput() { |
| 1247 | TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput"); |
| 1248 | if (pending_input_event_ack_.get()) |
| 1249 | Send(pending_input_event_ack_.release()); |
| 1250 | } |
| 1251 | |
[email protected] | 58264a3 | 2011-11-17 23:36:15 | [diff] [blame] | 1252 | void RenderWidget::didCommitAndDrawCompositorFrame() { |
[email protected] | b5db7eb | 2011-11-29 09:11:50 | [diff] [blame] | 1253 | TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame"); |
[email protected] | 60a5007 | 2012-01-11 02:05:35 | [diff] [blame] | 1254 | // Accelerated FPS tick for performance tests. See throughput_tests.cc. |
| 1255 | // NOTE: Tests may break if this event is renamed or moved. |
| 1256 | UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU"); |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 1257 | // Notify subclasses that we initiated the paint operation. |
| 1258 | DidInitiatePaint(); |
[email protected] | 58264a3 | 2011-11-17 23:36:15 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | void RenderWidget::didCompleteSwapBuffers() { |
[email protected] | 404939f | 2012-06-01 04:06:18 | [diff] [blame] | 1262 | TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers"); |
| 1263 | |
| 1264 | // Notify subclasses threaded composited rendering was flushed to the screen. |
[email protected] | 9cd43a6 | 2012-03-26 08:03:56 | [diff] [blame] | 1265 | DidFlushPaint(); |
| 1266 | |
[email protected] | aa4117f | 2011-12-09 22:19:21 | [diff] [blame] | 1267 | if (update_reply_pending_) |
[email protected] | 58264a3 | 2011-11-17 23:36:15 | [diff] [blame] | 1268 | return; |
| 1269 | |
[email protected] | ea3ee0a | 2012-05-15 03:43:09 | [diff] [blame] | 1270 | if (!next_paint_flags_ && |
| 1271 | !need_update_rect_for_auto_resize_ && |
| 1272 | !plugin_window_moves_.size()) { |
[email protected] | 58264a3 | 2011-11-17 23:36:15 | [diff] [blame] | 1273 | return; |
[email protected] | ea3ee0a | 2012-05-15 03:43:09 | [diff] [blame] | 1274 | } |
[email protected] | 58264a3 | 2011-11-17 23:36:15 | [diff] [blame] | 1275 | |
| 1276 | ViewHostMsg_UpdateRect_Params params; |
| 1277 | params.view_size = size_; |
[email protected] | 58264a3 | 2011-11-17 23:36:15 | [diff] [blame] | 1278 | params.plugin_window_moves.swap(plugin_window_moves_); |
| 1279 | params.flags = next_paint_flags_; |
| 1280 | params.scroll_offset = GetScrollOffset(); |
[email protected] | b0dda9e2 | 2011-12-13 20:30:12 | [diff] [blame] | 1281 | params.needs_ack = false; |
[email protected] | 7ded9f1 | 2012-06-13 20:47:09 | [diff] [blame] | 1282 | params.scale_factor = device_scale_factor_; |
[email protected] | 58264a3 | 2011-11-17 23:36:15 | [diff] [blame] | 1283 | |
| 1284 | Send(new ViewHostMsg_UpdateRect(routing_id_, params)); |
| 1285 | next_paint_flags_ = 0; |
[email protected] | ea3ee0a | 2012-05-15 03:43:09 | [diff] [blame] | 1286 | need_update_rect_for_auto_resize_ = false; |
[email protected] | 58264a3 | 2011-11-17 23:36:15 | [diff] [blame] | 1287 | } |
| 1288 | |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1289 | void RenderWidget::scheduleComposite() { |
[email protected] | 479b017 | 2012-10-29 19:27:09 | [diff] [blame] | 1290 | TRACE_EVENT0("gpu", "RenderWidget::scheduleComposite"); |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 1291 | if (WebWidgetHandlesCompositorScheduling()) { |
[email protected] | c3d4553 | 2011-10-07 19:20:40 | [diff] [blame] | 1292 | webwidget_->composite(false); |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 1293 | } else { |
[email protected] | c3d4553 | 2011-10-07 19:20:40 | [diff] [blame] | 1294 | // TODO(nduca): replace with something a little less hacky. The reason this |
| 1295 | // hack is still used is because the Invalidate-DoDeferredUpdate loop |
| 1296 | // contains a lot of host-renderer synchronization logic that is still |
| 1297 | // important for the accelerated compositing case. The option of simply |
| 1298 | // duplicating all that code is less desirable than "faking out" the |
| 1299 | // invalidation path using a magical damage rect. |
| 1300 | didInvalidateRect(WebRect(0, 0, 1, 1)); |
| 1301 | } |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1302 | } |
| 1303 | |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 1304 | void RenderWidget::scheduleAnimation() { |
[email protected] | ce65fb78 | 2012-04-19 05:01:20 | [diff] [blame] | 1305 | if (animation_update_pending_) |
| 1306 | return; |
| 1307 | |
[email protected] | 921244e4 | 2011-07-20 16:36:30 | [diff] [blame] | 1308 | TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation"); |
[email protected] | ce65fb78 | 2012-04-19 05:01:20 | [diff] [blame] | 1309 | animation_update_pending_ = true; |
| 1310 | if (!animation_timer_.IsRunning()) { |
| 1311 | animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(0), this, |
| 1312 | &RenderWidget::AnimationCallback); |
[email protected] | ee3d3ad | 2011-02-04 00:42:21 | [diff] [blame] | 1313 | } |
[email protected] | 5f8b102 | 2011-01-21 23:34:50 | [diff] [blame] | 1314 | } |
| 1315 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1316 | void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { |
[email protected] | 7c51b0ee | 2009-07-08 21:49:30 | [diff] [blame] | 1317 | // TODO(darin): Eliminate this temporary. |
| 1318 | WebCursor cursor(cursor_info); |
| 1319 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1320 | // Only send a SetCursor message if we need to make a change. |
| 1321 | if (!current_cursor_.IsEqual(cursor)) { |
| 1322 | current_cursor_ = cursor; |
| 1323 | Send(new ViewHostMsg_SetCursor(routing_id_, cursor)); |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | // We are supposed to get a single call to Show for a newly created RenderWidget |
| 1328 | // that was created via RenderWidget::CreateWebView. So, we wait until this |
| 1329 | // point to dispatch the ShowWidget message. |
| 1330 | // |
| 1331 | // This method provides us with the information about how to display the newly |
[email protected] | 5f9de588 | 2011-09-30 23:36:28 | [diff] [blame] | 1332 | // created RenderWidget (i.e., as a blocked popup or as a new tab). |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1333 | // |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1334 | void RenderWidget::show(WebNavigationPolicy) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1335 | DCHECK(!did_show_) << "received extraneous Show call"; |
| 1336 | DCHECK(routing_id_ != MSG_ROUTING_NONE); |
| 1337 | DCHECK(opener_id_ != MSG_ROUTING_NONE); |
| 1338 | |
[email protected] | 8de12d94 | 2010-11-17 20:42:44 | [diff] [blame] | 1339 | if (did_show_) |
| 1340 | return; |
| 1341 | |
| 1342 | did_show_ = true; |
| 1343 | // NOTE: initial_pos_ may still have its default values at this point, but |
| 1344 | // that's okay. It'll be ignored if as_popup is false, or the browser |
| 1345 | // process will impose a default position otherwise. |
| 1346 | Send(new ViewHostMsg_ShowWidget(opener_id_, routing_id_, initial_pos_)); |
| 1347 | SetPendingWindowRect(initial_pos_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1348 | } |
| 1349 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1350 | void RenderWidget::didFocus() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1351 | } |
| 1352 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1353 | void RenderWidget::didBlur() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1354 | } |
| 1355 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1356 | void RenderWidget::DoDeferredClose() { |
| 1357 | Send(new ViewHostMsg_Close(routing_id_)); |
| 1358 | } |
| 1359 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1360 | void RenderWidget::closeWidgetSoon() { |
[email protected] | e1c3a55 | 2012-05-04 20:51:32 | [diff] [blame] | 1361 | if (is_swapped_out_) { |
| 1362 | // This widget is currently swapped out, and the active widget is in a |
| 1363 | // different process. Have the browser route the close request to the |
| 1364 | // active widget instead, so that the correct unload handlers are run. |
| 1365 | Send(new ViewHostMsg_RouteCloseEvent(routing_id_)); |
| 1366 | return; |
| 1367 | } |
| 1368 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1369 | // If a page calls window.close() twice, we'll end up here twice, but that's |
| 1370 | // OK. It is safe to send multiple Close messages. |
| 1371 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1372 | // Ask the RenderWidgetHost to initiate close. We could be called from deep |
| 1373 | // in Javascript. If we ask the RendwerWidgetHost to close now, the window |
| 1374 | // could be closed before the JS finishes executing. So instead, post a |
| 1375 | // message back to the message loop, which won't run until the JS is |
| 1376 | // complete, and then the Close message can be sent. |
[email protected] | 32876ae | 2011-11-15 22:25:21 | [diff] [blame] | 1377 | MessageLoop::current()->PostTask( |
| 1378 | FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | void RenderWidget::Close() { |
| 1382 | if (webwidget_) { |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1383 | webwidget_->close(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1384 | webwidget_ = NULL; |
| 1385 | } |
| 1386 | } |
| 1387 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1388 | WebRect RenderWidget::windowRect() { |
| 1389 | if (pending_window_rect_count_) |
| 1390 | return pending_window_rect_; |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1391 | |
[email protected] | 80ad862 | 2012-11-07 16:33:03 | [diff] [blame] | 1392 | return view_screen_rect_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1393 | } |
| 1394 | |
[email protected] | 8a9d6ca3 | 2011-06-06 20:11:30 | [diff] [blame] | 1395 | void RenderWidget::setToolTipText(const WebKit::WebString& text, |
| 1396 | WebTextDirection hint) { |
[email protected] | 5a395b7 | 2011-08-08 19:13:54 | [diff] [blame] | 1397 | Send(new ViewHostMsg_SetTooltipText(routing_id_, text, hint)); |
[email protected] | 8a9d6ca3 | 2011-06-06 20:11:30 | [diff] [blame] | 1398 | } |
| 1399 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1400 | void RenderWidget::setWindowRect(const WebRect& pos) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1401 | if (did_show_) { |
| 1402 | Send(new ViewHostMsg_RequestMove(routing_id_, pos)); |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1403 | SetPendingWindowRect(pos); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1404 | } else { |
| 1405 | initial_pos_ = pos; |
| 1406 | } |
| 1407 | } |
| 1408 | |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1409 | void RenderWidget::SetPendingWindowRect(const WebRect& rect) { |
| 1410 | pending_window_rect_ = rect; |
| 1411 | pending_window_rect_count_++; |
| 1412 | } |
| 1413 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1414 | WebRect RenderWidget::rootWindowRect() { |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1415 | if (pending_window_rect_count_) { |
| 1416 | // NOTE(mbelshe): If there is a pending_window_rect_, then getting |
| 1417 | // the RootWindowRect is probably going to return wrong results since the |
| 1418 | // browser may not have processed the Move yet. There isn't really anything |
| 1419 | // good to do in this case, and it shouldn't happen - since this size is |
| 1420 | // only really needed for windowToScreen, which is only used for Popups. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1421 | return pending_window_rect_; |
[email protected] | 2533ce1 | 2009-05-09 00:02:24 | [diff] [blame] | 1422 | } |
| 1423 | |
[email protected] | 80ad862 | 2012-11-07 16:33:03 | [diff] [blame] | 1424 | return window_screen_rect_; |
[email protected] | d454745 | 2008-08-28 18:36:37 | [diff] [blame] | 1425 | } |
| 1426 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1427 | WebRect RenderWidget::windowResizerRect() { |
| 1428 | return resizer_rect_; |
[email protected] | c04b636 | 2008-11-21 18:54:19 | [diff] [blame] | 1429 | } |
| 1430 | |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1431 | void RenderWidget::OnSetInputMethodActive(bool is_active) { |
[email protected] | c4bb35a | 2008-10-31 17:54:03 | [diff] [blame] | 1432 | // To prevent this renderer process from sending unnecessary IPC messages to |
| 1433 | // a browser process, we permit the renderer process to send IPC messages |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1434 | // only during the input method attached to the browser process is active. |
| 1435 | input_method_is_active_ = is_active; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1436 | } |
| 1437 | |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 1438 | void RenderWidget::UpdateCompositionInfo( |
| 1439 | const ui::Range& range, |
| 1440 | const std::vector<gfx::Rect>& character_bounds) { |
| 1441 | if (!ShouldUpdateCompositionInfo(range, character_bounds)) |
| 1442 | return; |
| 1443 | composition_character_bounds_ = character_bounds; |
| 1444 | composition_range_ = range; |
| 1445 | Send(new ViewHostMsg_ImeCompositionRangeChanged( |
| 1446 | routing_id(), composition_range_, composition_character_bounds_)); |
| 1447 | } |
| 1448 | |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1449 | void RenderWidget::OnImeSetComposition( |
| 1450 | const string16& text, |
| 1451 | const std::vector<WebCompositionUnderline>& underlines, |
| 1452 | int selection_start, int selection_end) { |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1453 | if (!webwidget_) |
| 1454 | return; |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 1455 | if (webwidget_->setComposition( |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1456 | text, WebVector<WebCompositionUnderline>(underlines), |
| 1457 | selection_start, selection_end)) { |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 1458 | // Setting the IME composition was successful. Send the new composition |
| 1459 | // range to the browser. |
| 1460 | ui::Range range(ui::Range::InvalidRange()); |
| 1461 | size_t location, length; |
| 1462 | if (webwidget_->compositionRange(&location, &length)) { |
| 1463 | range.set_start(location); |
| 1464 | range.set_end(location + length); |
| 1465 | } |
| 1466 | // The IME was cancelled via the Esc key, so just send back the caret. |
| 1467 | else if (webwidget_->caretOrSelectionRange(&location, &length)) { |
| 1468 | range.set_start(location); |
| 1469 | range.set_end(location + length); |
| 1470 | } |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 1471 | std::vector<gfx::Rect> character_bounds; |
| 1472 | GetCompositionCharacterBounds(&character_bounds); |
| 1473 | UpdateCompositionInfo(range, character_bounds); |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 1474 | } else { |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1475 | // If we failed to set the composition text, then we need to let the browser |
| 1476 | // process to cancel the input method's ongoing composition session, to make |
| 1477 | // sure we are in a consistent state. |
| 1478 | Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 1479 | |
| 1480 | // Send an updated IME range with just the caret range. |
| 1481 | ui::Range range(ui::Range::InvalidRange()); |
| 1482 | size_t location, length; |
| 1483 | if (webwidget_->caretOrSelectionRange(&location, &length)) { |
| 1484 | range.set_start(location); |
| 1485 | range.set_end(location + length); |
| 1486 | } |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 1487 | UpdateCompositionInfo(range, std::vector<gfx::Rect>()); |
[email protected] | 7f00efa | 2010-04-15 05:01:26 | [diff] [blame] | 1488 | } |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1489 | } |
| 1490 | |
[email protected] | 4de6d169 | 2011-10-12 08:45:44 | [diff] [blame] | 1491 | void RenderWidget::OnImeConfirmComposition( |
| 1492 | const string16& text, const ui::Range& replacement_range) { |
[email protected] | d0be6377 | 2011-12-20 23:18:04 | [diff] [blame] | 1493 | if (!webwidget_) |
| 1494 | return; |
| 1495 | |
| 1496 | handling_input_event_ = true; |
| 1497 | webwidget_->confirmComposition(text); |
| 1498 | handling_input_event_ = false; |
| 1499 | |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 1500 | // Send an updated IME range with just the caret range. |
| 1501 | ui::Range range(ui::Range::InvalidRange()); |
| 1502 | size_t location, length; |
| 1503 | if (webwidget_->caretOrSelectionRange(&location, &length)) { |
| 1504 | range.set_start(location); |
| 1505 | range.set_end(location + length); |
| 1506 | } |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 1507 | UpdateCompositionInfo(range, std::vector<gfx::Rect>()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1508 | } |
| 1509 | |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 1510 | // This message causes the renderer to render an image of the |
| 1511 | // desired_size, regardless of whether the tab is hidden or not. |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1512 | void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle, |
[email protected] | c88c944 | 2010-07-19 18:55:09 | [diff] [blame] | 1513 | int tag, |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 1514 | const gfx::Size& page_size, |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1515 | const gfx::Size& desired_size) { |
[email protected] | 2754345 | 2011-03-25 00:14:00 | [diff] [blame] | 1516 | if (!webwidget_ || !TransportDIB::is_valid_handle(dib_handle)) { |
| 1517 | if (TransportDIB::is_valid_handle(dib_handle)) { |
[email protected] | 45c6aad3 | 2010-11-11 04:46:25 | [diff] [blame] | 1518 | // Close our unused handle. |
| 1519 | #if defined(OS_WIN) |
| 1520 | ::CloseHandle(dib_handle); |
| 1521 | #elif defined(OS_MACOSX) |
| 1522 | base::SharedMemory::CloseHandle(dib_handle); |
| 1523 | #endif |
| 1524 | } |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1525 | return; |
[email protected] | 45c6aad3 | 2010-11-11 04:46:25 | [diff] [blame] | 1526 | } |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1527 | |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 1528 | if (page_size.IsEmpty() || desired_size.IsEmpty()) { |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1529 | // If one of these is empty, then we just return the dib we were |
| 1530 | // given, to avoid leaking it. |
[email protected] | c88c944 | 2010-07-19 18:55:09 | [diff] [blame] | 1531 | Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size)); |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1532 | return; |
| 1533 | } |
| 1534 | |
| 1535 | // Map the given DIB ID into this process, and unmap it at the end |
| 1536 | // of this function. |
[email protected] | 45c6aad3 | 2010-11-11 04:46:25 | [diff] [blame] | 1537 | scoped_ptr<TransportDIB> paint_at_size_buffer( |
| 1538 | TransportDIB::CreateWithHandle(dib_handle)); |
[email protected] | 36808ad | 2010-10-20 19:18:30 | [diff] [blame] | 1539 | |
[email protected] | 4b01b96 | 2012-10-09 23:17:35 | [diff] [blame] | 1540 | gfx::Size page_size_in_pixel = gfx::ToFlooredSize( |
[email protected] | 01a15a7 | 2012-11-10 09:34:28 | [diff] [blame] | 1541 | gfx::ScaleSize(page_size, device_scale_factor_)); |
[email protected] | 4b01b96 | 2012-10-09 23:17:35 | [diff] [blame] | 1542 | gfx::Size desired_size_in_pixel = gfx::ToFlooredSize( |
[email protected] | 01a15a7 | 2012-11-10 09:34:28 | [diff] [blame] | 1543 | gfx::ScaleSize(desired_size, device_scale_factor_)); |
[email protected] | 8f64051 | 2012-08-07 23:52:51 | [diff] [blame] | 1544 | gfx::Size canvas_size = page_size_in_pixel; |
| 1545 | float x_scale = static_cast<float>(desired_size_in_pixel.width()) / |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1546 | static_cast<float>(canvas_size.width()); |
[email protected] | 8f64051 | 2012-08-07 23:52:51 | [diff] [blame] | 1547 | float y_scale = static_cast<float>(desired_size_in_pixel.height()) / |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1548 | static_cast<float>(canvas_size.height()); |
| 1549 | |
[email protected] | ee8d6fd | 2010-05-26 17:05:48 | [diff] [blame] | 1550 | gfx::Rect orig_bounds(canvas_size); |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1551 | canvas_size.set_width(static_cast<int>(canvas_size.width() * x_scale)); |
| 1552 | canvas_size.set_height(static_cast<int>(canvas_size.height() * y_scale)); |
[email protected] | ee8d6fd | 2010-05-26 17:05:48 | [diff] [blame] | 1553 | gfx::Rect bounds(canvas_size); |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1554 | |
[email protected] | 36808ad | 2010-10-20 19:18:30 | [diff] [blame] | 1555 | scoped_ptr<skia::PlatformCanvas> canvas( |
| 1556 | paint_at_size_buffer->GetPlatformCanvas(canvas_size.width(), |
| 1557 | canvas_size.height())); |
| 1558 | if (!canvas.get()) { |
| 1559 | NOTREACHED(); |
| 1560 | return; |
| 1561 | } |
| 1562 | |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1563 | // Reset bounds to what we actually received, but they should be the |
| 1564 | // same. |
| 1565 | DCHECK_EQ(bounds.width(), canvas->getDevice()->width()); |
| 1566 | DCHECK_EQ(bounds.height(), canvas->getDevice()->height()); |
| 1567 | bounds.set_width(canvas->getDevice()->width()); |
| 1568 | bounds.set_height(canvas->getDevice()->height()); |
| 1569 | |
| 1570 | canvas->save(); |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 1571 | // Add the scale factor to the canvas, so that we'll get the desired size. |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1572 | canvas->scale(SkFloatToScalar(x_scale), SkFloatToScalar(y_scale)); |
| 1573 | |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 1574 | // Have to make sure we're laid out at the right size before |
| 1575 | // rendering. |
| 1576 | gfx::Size old_size = webwidget_->size(); |
| 1577 | webwidget_->resize(page_size); |
| 1578 | webwidget_->layout(); |
| 1579 | |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1580 | // Paint the entire thing (using original bounds, not scaled bounds). |
| 1581 | PaintRect(orig_bounds, orig_bounds.origin(), canvas.get()); |
| 1582 | canvas->restore(); |
| 1583 | |
[email protected] | 948f7ab7 | 2010-05-28 23:48:08 | [diff] [blame] | 1584 | // Return the widget to its previous size. |
| 1585 | webwidget_->resize(old_size); |
| 1586 | |
[email protected] | c88c944 | 2010-07-19 18:55:09 | [diff] [blame] | 1587 | Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size())); |
[email protected] | d65adb1 | 2010-04-28 17:26:49 | [diff] [blame] | 1588 | } |
| 1589 | |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 1590 | void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) { |
| 1591 | // During shutdown we can just ignore this message. |
| 1592 | if (!webwidget_) |
| 1593 | return; |
| 1594 | |
| 1595 | set_next_paint_is_repaint_ack(); |
[email protected] | a79d8a63 | 2010-11-18 22:35:56 | [diff] [blame] | 1596 | if (is_accelerated_compositing_active_) { |
[email protected] | 8c49fa98 | 2012-02-10 14:37:04 | [diff] [blame] | 1597 | webwidget_->setNeedsRedraw(); |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1598 | scheduleComposite(); |
| 1599 | } else { |
| 1600 | gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); |
| 1601 | didInvalidateRect(repaint_rect); |
| 1602 | } |
[email protected] | ec7dc11 | 2008-08-06 05:30:12 | [diff] [blame] | 1603 | } |
| 1604 | |
[email protected] | 0e241b4b | 2012-08-18 09:06:27 | [diff] [blame] | 1605 | void RenderWidget::OnMsgSmoothScrollCompleted(int gesture_id) { |
| 1606 | PendingSmoothScrollGestureMap::iterator it = |
| 1607 | pending_smooth_scroll_gestures_.find(gesture_id); |
| 1608 | DCHECK(it != pending_smooth_scroll_gestures_.end()); |
| 1609 | it->second.Run(); |
| 1610 | pending_smooth_scroll_gestures_.erase(it); |
| 1611 | } |
| 1612 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1613 | void RenderWidget::OnSetTextDirection(WebTextDirection direction) { |
[email protected] | 07f95333 | 2009-03-25 04:31:11 | [diff] [blame] | 1614 | if (!webwidget_) |
| 1615 | return; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1616 | webwidget_->setTextDirection(direction); |
[email protected] | 07f95333 | 2009-03-25 04:31:11 | [diff] [blame] | 1617 | } |
| 1618 | |
[email protected] | 6131a64 | 2012-06-15 23:26:53 | [diff] [blame] | 1619 | void RenderWidget::OnScreenInfoChanged( |
| 1620 | const WebKit::WebScreenInfo& screen_info) { |
| 1621 | screen_info_ = screen_info; |
[email protected] | 468ac58 | 2012-11-20 00:53:19 | [diff] [blame] | 1622 | SetDeviceScaleFactor(screen_info.deviceScaleFactor); |
[email protected] | 6131a64 | 2012-06-15 23:26:53 | [diff] [blame] | 1623 | } |
| 1624 | |
[email protected] | 80ad862 | 2012-11-07 16:33:03 | [diff] [blame] | 1625 | void RenderWidget::OnUpdateScreenRects(const gfx::Rect& view_screen_rect, |
| 1626 | const gfx::Rect& window_screen_rect) { |
| 1627 | view_screen_rect_ = view_screen_rect; |
| 1628 | window_screen_rect_ = window_screen_rect; |
| 1629 | Send(new ViewHostMsg_UpdateScreenRects_ACK(routing_id())); |
| 1630 | } |
| 1631 | |
[email protected] | 468ac58 | 2012-11-20 00:53:19 | [diff] [blame] | 1632 | void RenderWidget::SetDeviceScaleFactor(float device_scale_factor) { |
| 1633 | if (device_scale_factor_ == device_scale_factor) |
| 1634 | return; |
| 1635 | |
| 1636 | device_scale_factor_ = device_scale_factor; |
| 1637 | |
| 1638 | if (!is_accelerated_compositing_active_) { |
| 1639 | didInvalidateRect(gfx::Rect(size_.width(), size_.height())); |
| 1640 | } else { |
| 1641 | scheduleComposite(); |
| 1642 | } |
| 1643 | } |
| 1644 | |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 1645 | webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint( |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 1646 | const gfx::Rect& paint_bounds, |
| 1647 | TransportDIB** dib, |
| 1648 | gfx::Rect* location, |
[email protected] | 0f3a2d1 | 2012-09-01 03:37:20 | [diff] [blame] | 1649 | gfx::Rect* clip, |
| 1650 | float* scale_factor) { |
[email protected] | 719b36f | 2010-12-22 20:36:46 | [diff] [blame] | 1651 | // Bare RenderWidgets don't support optimized plugin painting. |
| 1652 | return NULL; |
[email protected] | ca4847f | 2010-09-24 05:39:15 | [diff] [blame] | 1653 | } |
| 1654 | |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 1655 | gfx::Vector2d RenderWidget::GetScrollOffset() { |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 1656 | // Bare RenderWidgets don't support scroll offset. |
[email protected] | ceb36f7d | 2012-10-31 18:33:24 | [diff] [blame] | 1657 | return gfx::Vector2d(); |
[email protected] | d54169e9 | 2011-01-21 09:19:52 | [diff] [blame] | 1658 | } |
| 1659 | |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 1660 | void RenderWidget::SetHidden(bool hidden) { |
| 1661 | if (is_hidden_ == hidden) |
| 1662 | return; |
| 1663 | |
| 1664 | // The status has changed. Tell the RenderThread about it. |
| 1665 | is_hidden_ = hidden; |
| 1666 | if (is_hidden_) |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 1667 | RenderThread::Get()->WidgetHidden(); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 1668 | else |
[email protected] | 38024409 | 2011-10-07 17:26:27 | [diff] [blame] | 1669 | RenderThread::Get()->WidgetRestored(); |
[email protected] | bee16aab | 2009-08-26 15:55:03 | [diff] [blame] | 1670 | } |
| 1671 | |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 1672 | void RenderWidget::WillToggleFullscreen() { |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 1673 | if (!webwidget_) |
| 1674 | return; |
| 1675 | |
| 1676 | if (is_fullscreen_) { |
| 1677 | webwidget_->willExitFullScreen(); |
| 1678 | } else { |
| 1679 | webwidget_->willEnterFullScreen(); |
| 1680 | } |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 1681 | } |
| 1682 | |
| 1683 | void RenderWidget::DidToggleFullscreen() { |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 1684 | if (!webwidget_) |
| 1685 | return; |
| 1686 | |
| 1687 | if (is_fullscreen_) { |
| 1688 | webwidget_->didEnterFullScreen(); |
| 1689 | } else { |
| 1690 | webwidget_->didExitFullScreen(); |
| 1691 | } |
[email protected] | 2b624c56 | 2011-10-27 22:58:26 | [diff] [blame] | 1692 | } |
| 1693 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 1694 | void RenderWidget::SetBackground(const SkBitmap& background) { |
| 1695 | background_ = background; |
[email protected] | f98d7e3c | 2010-09-13 22:30:46 | [diff] [blame] | 1696 | |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 1697 | // Generate a full repaint. |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1698 | didInvalidateRect(gfx::Rect(size_.width(), size_.height())); |
[email protected] | 699ab0d | 2009-04-23 23:19:14 | [diff] [blame] | 1699 | } |
| 1700 | |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1701 | bool RenderWidget::next_paint_is_resize_ack() const { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1702 | return ViewHostMsg_UpdateRect_Flags::is_resize_ack(next_paint_flags_); |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | bool RenderWidget::next_paint_is_restore_ack() const { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1706 | return ViewHostMsg_UpdateRect_Flags::is_restore_ack(next_paint_flags_); |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | void RenderWidget::set_next_paint_is_resize_ack() { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1710 | next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESIZE_ACK; |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1711 | } |
| 1712 | |
| 1713 | void RenderWidget::set_next_paint_is_restore_ack() { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1714 | next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_RESTORE_ACK; |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | void RenderWidget::set_next_paint_is_repaint_ack() { |
[email protected] | 53d3f30 | 2009-12-21 04:42:05 | [diff] [blame] | 1718 | next_paint_flags_ |= ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK; |
[email protected] | 67474193 | 2009-02-04 23:44:46 | [diff] [blame] | 1719 | } |
| 1720 | |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 1721 | void RenderWidget::UpdateTextInputState(ShowIme show_ime) { |
| 1722 | bool show_ime_if_needed = (show_ime == SHOW_IME_IF_NEEDED); |
| 1723 | if (!show_ime_if_needed && !input_method_is_active_) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1724 | return; |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1725 | ui::TextInputType new_type = GetTextInputType(); |
[email protected] | 5b739cb | 2012-08-21 20:35:21 | [diff] [blame] | 1726 | WebKit::WebTextInputInfo new_info; |
| 1727 | if (webwidget_) |
| 1728 | new_info = webwidget_->textInputInfo(); |
| 1729 | |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1730 | bool new_can_compose_inline = CanComposeInline(); |
[email protected] | 5b739cb | 2012-08-21 20:35:21 | [diff] [blame] | 1731 | |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 1732 | // Only sends text input params if they are changed or if the ime should be |
| 1733 | // shown. |
| 1734 | if (show_ime_if_needed || (text_input_type_ != new_type |
| 1735 | || text_input_info_ != new_info |
| 1736 | || can_compose_inline_ != new_can_compose_inline)) { |
[email protected] | 5b739cb | 2012-08-21 20:35:21 | [diff] [blame] | 1737 | ViewHostMsg_TextInputState_Params p; |
| 1738 | p.type = new_type; |
| 1739 | p.value = new_info.value.utf8(); |
| 1740 | p.selection_start = new_info.selectionStart; |
| 1741 | p.selection_end = new_info.selectionEnd; |
| 1742 | p.composition_start = new_info.compositionStart; |
| 1743 | p.composition_end = new_info.compositionEnd; |
| 1744 | p.can_compose_inline = new_can_compose_inline; |
[email protected] | 3306f26 | 2012-09-21 19:20:42 | [diff] [blame] | 1745 | p.show_ime_if_needed = show_ime_if_needed; |
[email protected] | 5b739cb | 2012-08-21 20:35:21 | [diff] [blame] | 1746 | Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p)); |
| 1747 | |
| 1748 | text_input_info_ = new_info; |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1749 | text_input_type_ = new_type; |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1750 | can_compose_inline_ = new_can_compose_inline; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1751 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1752 | } |
| 1753 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 1754 | void RenderWidget::GetSelectionBounds(gfx::Rect* start, gfx::Rect* end) { |
| 1755 | WebRect start_webrect; |
| 1756 | WebRect end_webrect; |
| 1757 | webwidget_->selectionBounds(start_webrect, end_webrect); |
| 1758 | *start = start_webrect; |
| 1759 | *end = end_webrect; |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 1760 | } |
| 1761 | |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 1762 | void RenderWidget::UpdateSelectionBounds() { |
| 1763 | if (!webwidget_) |
| 1764 | return; |
| 1765 | |
[email protected] | 3f78336 | 2011-10-21 22:40:50 | [diff] [blame] | 1766 | gfx::Rect start_rect; |
| 1767 | gfx::Rect end_rect; |
| 1768 | GetSelectionBounds(&start_rect, &end_rect); |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 1769 | if (selection_start_rect_ != start_rect || selection_end_rect_ != end_rect) { |
| 1770 | selection_start_rect_ = start_rect; |
| 1771 | selection_end_rect_ = end_rect; |
[email protected] | b556c2e | 2012-08-10 22:18:27 | [diff] [blame] | 1772 | WebTextDirection start_dir = WebKit::WebTextDirectionLeftToRight; |
| 1773 | WebTextDirection end_dir = WebKit::WebTextDirectionLeftToRight; |
| 1774 | webwidget_->selectionTextDirection(start_dir, end_dir); |
| 1775 | Send(new ViewHostMsg_SelectionBoundsChanged(routing_id_, |
| 1776 | selection_start_rect_, start_dir, selection_end_rect_, end_dir)); |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 1777 | } |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 1778 | |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 1779 | std::vector<gfx::Rect> character_bounds; |
| 1780 | GetCompositionCharacterBounds(&character_bounds); |
| 1781 | UpdateCompositionInfo(composition_range_, character_bounds); |
| 1782 | } |
| 1783 | |
| 1784 | bool RenderWidget::ShouldUpdateCompositionInfo( |
| 1785 | const ui::Range& range, |
| 1786 | const std::vector<gfx::Rect>& bounds) { |
| 1787 | if (composition_range_ != range) |
| 1788 | return true; |
| 1789 | if (bounds.size() != composition_character_bounds_.size()) |
| 1790 | return true; |
| 1791 | for (size_t i = 0; i < bounds.size(); ++i) { |
| 1792 | if (bounds[i] != composition_character_bounds_[i]) |
| 1793 | return true; |
| 1794 | } |
| 1795 | return false; |
[email protected] | e99ef6f | 2011-10-16 01:13:00 | [diff] [blame] | 1796 | } |
| 1797 | |
[email protected] | 73bf9581 | 2011-10-12 11:38:32 | [diff] [blame] | 1798 | // Check WebKit::WebTextInputType and ui::TextInputType is kept in sync. |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1799 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeNone) == \ |
| 1800 | int(ui::TEXT_INPUT_TYPE_NONE), mismatching_enums); |
| 1801 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeText) == \ |
| 1802 | int(ui::TEXT_INPUT_TYPE_TEXT), mismatching_enums); |
| 1803 | COMPILE_ASSERT(int(WebKit::WebTextInputTypePassword) == \ |
| 1804 | int(ui::TEXT_INPUT_TYPE_PASSWORD), mismatching_enums); |
[email protected] | caf38ed | 2011-07-28 13:15:18 | [diff] [blame] | 1805 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeSearch) == \ |
| 1806 | int(ui::TEXT_INPUT_TYPE_SEARCH), mismatching_enums); |
| 1807 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeEmail) == \ |
| 1808 | int(ui::TEXT_INPUT_TYPE_EMAIL), mismatching_enums); |
| 1809 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeNumber) == \ |
| 1810 | int(ui::TEXT_INPUT_TYPE_NUMBER), mismatching_enums); |
| 1811 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeTelephone) == \ |
| 1812 | int(ui::TEXT_INPUT_TYPE_TELEPHONE), mismatching_enums); |
| 1813 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeURL) == \ |
| 1814 | int(ui::TEXT_INPUT_TYPE_URL), mismatching_enums); |
[email protected] | feb8cf75 | 2012-06-08 04:48:00 | [diff] [blame] | 1815 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeDate) == \ |
| 1816 | int(ui::TEXT_INPUT_TYPE_DATE), mismatching_enum); |
| 1817 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTime) == \ |
| 1818 | int(ui::TEXT_INPUT_TYPE_DATE_TIME), mismatching_enum); |
| 1819 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeDateTimeLocal) == \ |
| 1820 | int(ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL), mismatching_enum); |
| 1821 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeMonth) == \ |
| 1822 | int(ui::TEXT_INPUT_TYPE_MONTH), mismatching_enum); |
| 1823 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeTime) == \ |
| 1824 | int(ui::TEXT_INPUT_TYPE_TIME), mismatching_enum); |
| 1825 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeWeek) == \ |
| 1826 | int(ui::TEXT_INPUT_TYPE_WEEK), mismatching_enum); |
[email protected] | 2a989367 | 2012-11-09 20:33:01 | [diff] [blame] | 1827 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeTextArea) == \ |
| 1828 | int(ui::TEXT_INPUT_TYPE_TEXT_AREA), mismatching_enums); |
| 1829 | COMPILE_ASSERT(int(WebKit::WebTextInputTypeContentEditable) == \ |
| 1830 | int(ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE), mismatching_enums); |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1831 | |
[email protected] | 5b739cb | 2012-08-21 20:35:21 | [diff] [blame] | 1832 | ui::TextInputType RenderWidget::WebKitToUiTextInputType( |
| 1833 | WebKit::WebTextInputType type) { |
| 1834 | // Check the type is in the range representable by ui::TextInputType. |
| 1835 | DCHECK_LE(type, static_cast<int>(ui::TEXT_INPUT_TYPE_MAX)) << |
| 1836 | "WebKit::WebTextInputType and ui::TextInputType not synchronized"; |
| 1837 | return static_cast<ui::TextInputType>(type); |
| 1838 | } |
| 1839 | |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1840 | ui::TextInputType RenderWidget::GetTextInputType() { |
[email protected] | 8969bb3f | 2012-11-30 21:49:27 | [diff] [blame] | 1841 | if (webwidget_) |
| 1842 | return WebKitToUiTextInputType(webwidget_->textInputInfo().type); |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1843 | return ui::TEXT_INPUT_TYPE_NONE; |
| 1844 | } |
| 1845 | |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 1846 | void RenderWidget::GetCompositionCharacterBounds( |
| 1847 | std::vector<gfx::Rect>* bounds) { |
| 1848 | DCHECK(bounds); |
| 1849 | bounds->clear(); |
| 1850 | } |
| 1851 | |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1852 | bool RenderWidget::CanComposeInline() { |
| 1853 | return true; |
[email protected] | 56ea1a6 | 2011-05-30 07:05:57 | [diff] [blame] | 1854 | } |
| 1855 | |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1856 | WebScreenInfo RenderWidget::screenInfo() { |
[email protected] | 842f1065 | 2012-06-06 01:54:04 | [diff] [blame] | 1857 | return screen_info_; |
[email protected] | 4873c7d | 2009-07-16 06:36:28 | [diff] [blame] | 1858 | } |
| 1859 | |
[email protected] | f660d9c | 2012-06-06 18:31:21 | [diff] [blame] | 1860 | float RenderWidget::deviceScaleFactor() { |
| 1861 | return device_scale_factor_; |
| 1862 | } |
| 1863 | |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1864 | void RenderWidget::resetInputMethod() { |
| 1865 | if (!input_method_is_active_) |
| 1866 | return; |
| 1867 | |
| 1868 | // If the last text input type is not None, then we should finish any |
| 1869 | // ongoing composition regardless of the new text input type. |
[email protected] | ad26ef4 | 2011-06-17 07:59:45 | [diff] [blame] | 1870 | if (text_input_type_ != ui::TEXT_INPUT_TYPE_NONE) { |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1871 | // If a composition text exists, then we need to let the browser process |
| 1872 | // to cancel the input method's ongoing composition session. |
| 1873 | if (webwidget_->confirmComposition()) |
| 1874 | Send(new ViewHostMsg_ImeCancelComposition(routing_id())); |
| 1875 | } |
[email protected] | d4cff27 | 2011-05-02 15:46:01 | [diff] [blame] | 1876 | |
| 1877 | // Send an updated IME range with the current caret rect. |
| 1878 | ui::Range range(ui::Range::InvalidRange()); |
| 1879 | size_t location, length; |
| 1880 | if (webwidget_->caretOrSelectionRange(&location, &length)) { |
| 1881 | range.set_start(location); |
| 1882 | range.set_end(location + length); |
| 1883 | } |
[email protected] | 58b48a0d | 2012-06-13 07:01:35 | [diff] [blame] | 1884 | |
| 1885 | UpdateCompositionInfo(range, std::vector<gfx::Rect>()); |
[email protected] | fa7b1dc | 2010-06-23 17:53:04 | [diff] [blame] | 1886 | } |
| 1887 | |
[email protected] | f103ab7 | 2009-09-02 17:10:59 | [diff] [blame] | 1888 | void RenderWidget::SchedulePluginMove( |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 1889 | const webkit::npapi::WebPluginGeometry& move) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1890 | size_t i = 0; |
| 1891 | for (; i < plugin_window_moves_.size(); ++i) { |
| 1892 | if (plugin_window_moves_[i].window == move.window) { |
[email protected] | 16f89d0 | 2009-08-26 17:17:58 | [diff] [blame] | 1893 | if (move.rects_valid) { |
| 1894 | plugin_window_moves_[i] = move; |
| 1895 | } else { |
| 1896 | plugin_window_moves_[i].visible = move.visible; |
| 1897 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1898 | break; |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | if (i == plugin_window_moves_.size()) |
| 1903 | plugin_window_moves_.push_back(move); |
| 1904 | } |
[email protected] | 26865477 | 2009-08-06 23:02:04 | [diff] [blame] | 1905 | |
| 1906 | void RenderWidget::CleanupWindowInPluginMoves(gfx::PluginWindowHandle window) { |
| 1907 | for (WebPluginGeometryVector::iterator i = plugin_window_moves_.begin(); |
| 1908 | i != plugin_window_moves_.end(); ++i) { |
| 1909 | if (i->window == window) { |
| 1910 | plugin_window_moves_.erase(i); |
| 1911 | break; |
| 1912 | } |
| 1913 | } |
| 1914 | } |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 1915 | |
[email protected] | b63d58d | 2012-11-26 22:37:44 | [diff] [blame] | 1916 | void RenderWidget::GetRenderingStats( |
| 1917 | WebKit::WebRenderingStatsImpl& stats) const { |
[email protected] | fef5e397 | 2012-08-07 03:59:47 | [diff] [blame] | 1918 | webwidget()->renderingStats(stats); |
[email protected] | b63d58d | 2012-11-26 22:37:44 | [diff] [blame] | 1919 | |
| 1920 | stats.rendering_stats.numAnimationFrames += |
| 1921 | software_stats_.numAnimationFrames; |
| 1922 | stats.rendering_stats.numFramesSentToScreen += |
| 1923 | software_stats_.numFramesSentToScreen; |
| 1924 | stats.rendering_stats.totalPaintTimeInSeconds += |
| 1925 | software_stats_.totalPaintTimeInSeconds; |
| 1926 | stats.rendering_stats.totalPixelsPainted += |
| 1927 | software_stats_.totalPixelsPainted; |
| 1928 | stats.rendering_stats.totalRasterizeTimeInSeconds += |
[email protected] | 63ab5426 | 2012-11-09 15:58:45 | [diff] [blame] | 1929 | software_stats_.totalRasterizeTimeInSeconds; |
[email protected] | b63d58d | 2012-11-26 22:37:44 | [diff] [blame] | 1930 | stats.rendering_stats.totalPixelsRasterized += |
| 1931 | software_stats_.totalPixelsRasterized; |
[email protected] | fef5e397 | 2012-08-07 03:59:47 | [diff] [blame] | 1932 | } |
| 1933 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1934 | bool RenderWidget::GetGpuRenderingStats(GpuRenderingStats* stats) const { |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 1935 | GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel(); |
| 1936 | if (!gpu_channel) |
| 1937 | return false; |
| 1938 | |
| 1939 | return gpu_channel->CollectRenderingStatsForSurface(surface_id(), stats); |
| 1940 | } |
| 1941 | |
[email protected] | 0e241b4b | 2012-08-18 09:06:27 | [diff] [blame] | 1942 | void RenderWidget::BeginSmoothScroll( |
| 1943 | bool down, |
[email protected] | ebd8b56 | 2012-10-09 14:44:29 | [diff] [blame] | 1944 | const SmoothScrollCompletionCallback& callback, |
[email protected] | 267909d | 2012-10-20 04:36:19 | [diff] [blame] | 1945 | int pixels_to_scroll, |
[email protected] | ebd8b56 | 2012-10-09 14:44:29 | [diff] [blame] | 1946 | int mouse_event_x, |
| 1947 | int mouse_event_y) { |
[email protected] | 0e241b4b | 2012-08-18 09:06:27 | [diff] [blame] | 1948 | DCHECK(!callback.is_null()); |
| 1949 | int id = next_smooth_scroll_gesture_id_++; |
[email protected] | 267909d | 2012-10-20 04:36:19 | [diff] [blame] | 1950 | |
| 1951 | ViewHostMsg_BeginSmoothScroll_Params params; |
| 1952 | params.scroll_down = down; |
| 1953 | params.pixels_to_scroll = pixels_to_scroll; |
| 1954 | params.mouse_event_x = mouse_event_x; |
| 1955 | params.mouse_event_y = mouse_event_y; |
| 1956 | |
| 1957 | Send(new ViewHostMsg_BeginSmoothScroll(routing_id_, id, params)); |
[email protected] | 0e241b4b | 2012-08-18 09:06:27 | [diff] [blame] | 1958 | pending_smooth_scroll_gestures_.insert(std::make_pair(id, callback)); |
[email protected] | a39ca165 | 2012-07-13 21:30:58 | [diff] [blame] | 1959 | } |
| 1960 | |
[email protected] | 67bfb83f | 2011-09-22 03:36:37 | [diff] [blame] | 1961 | bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
| 1962 | return false; |
| 1963 | } |
[email protected] | c3d4553 | 2011-10-07 19:20:40 | [diff] [blame] | 1964 | |
[email protected] | 41d8685 | 2012-11-07 12:23:24 | [diff] [blame] | 1965 | bool RenderWidget::WillHandleGestureEvent( |
| 1966 | const WebKit::WebGestureEvent& event) { |
| 1967 | return false; |
| 1968 | } |
| 1969 | |
[email protected] | c3d4553 | 2011-10-07 19:20:40 | [diff] [blame] | 1970 | bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { |
| 1971 | return false; |
| 1972 | } |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1973 | |
[email protected] | 3d5c243b | 2012-11-30 00:26:01 | [diff] [blame] | 1974 | bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const { |
| 1975 | return true; |
| 1976 | } |
| 1977 | |
[email protected] | e9ff79c | 2012-10-19 21:31:26 | [diff] [blame] | 1978 | } // namespace content |