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