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