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