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