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