OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/debug/trace_event_synthetic_delay.h" | 10 #include "base/debug/trace_event_synthetic_delay.h" |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 closing_(false), | 379 closing_(false), |
380 is_swapped_out_(swapped_out), | 380 is_swapped_out_(swapped_out), |
381 input_method_is_active_(false), | 381 input_method_is_active_(false), |
382 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 382 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
383 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | 383 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
384 can_compose_inline_(true), | 384 can_compose_inline_(true), |
385 popup_type_(popup_type), | 385 popup_type_(popup_type), |
386 pending_window_rect_count_(0), | 386 pending_window_rect_count_(0), |
387 suppress_next_char_events_(false), | 387 suppress_next_char_events_(false), |
388 is_accelerated_compositing_active_(false), | 388 is_accelerated_compositing_active_(false), |
389 invalidation_task_posted_(false), | |
390 screen_info_(screen_info), | 389 screen_info_(screen_info), |
391 device_scale_factor_(screen_info_.deviceScaleFactor), | 390 device_scale_factor_(screen_info_.deviceScaleFactor), |
392 is_threaded_compositing_enabled_(false), | 391 is_threaded_compositing_enabled_(false), |
393 next_output_surface_id_(0), | 392 next_output_surface_id_(0), |
394 #if defined(OS_ANDROID) | 393 #if defined(OS_ANDROID) |
395 text_field_is_dirty_(false), | 394 text_field_is_dirty_(false), |
396 outstanding_ime_acks_(0), | 395 outstanding_ime_acks_(0), |
397 body_background_color_(SK_ColorWHITE), | 396 body_background_color_(SK_ColorWHITE), |
398 #endif | 397 #endif |
399 #if defined(OS_MACOSX) | 398 #if defined(OS_MACOSX) |
400 cached_has_main_frame_horizontal_scrollbar_(false), | 399 cached_has_main_frame_horizontal_scrollbar_(false), |
401 cached_has_main_frame_vertical_scrollbar_(false), | 400 cached_has_main_frame_vertical_scrollbar_(false), |
402 #endif | 401 #endif |
403 popup_origin_scale_for_emulation_(0.f), | 402 popup_origin_scale_for_emulation_(0.f), |
404 resizing_mode_selector_(new ResizingModeSelector()), | 403 resizing_mode_selector_(new ResizingModeSelector()), |
405 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { | 404 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { |
406 if (!swapped_out) | 405 if (!swapped_out) |
407 RenderProcess::current()->AddRefProcess(); | 406 RenderProcess::current()->AddRefProcess(); |
408 DCHECK(RenderThread::Get()); | 407 DCHECK(RenderThread::Get()); |
409 is_threaded_compositing_enabled_ = | 408 is_threaded_compositing_enabled_ = |
410 CommandLine::ForCurrentProcess()->HasSwitch( | 409 CommandLine::ForCurrentProcess()->HasSwitch( |
411 switches::kEnableThreadedCompositing); | 410 switches::kEnableThreadedCompositing); |
412 | |
413 legacy_software_mode_stats_ = cc::RenderingStatsInstrumentation::Create(); | |
414 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
415 cc::switches::kEnableGpuBenchmarking)) | |
416 legacy_software_mode_stats_->set_record_rendering_stats(true); | |
417 } | 411 } |
418 | 412 |
419 RenderWidget::~RenderWidget() { | 413 RenderWidget::~RenderWidget() { |
420 DCHECK(!webwidget_) << "Leaking our WebWidget!"; | 414 DCHECK(!webwidget_) << "Leaking our WebWidget!"; |
421 | 415 |
422 // If we are swapped out, we have released already. | 416 // If we are swapped out, we have released already. |
423 if (!is_swapped_out_ && RenderProcess::current()) | 417 if (!is_swapped_out_ && RenderProcess::current()) |
424 RenderProcess::current()->ReleaseProcess(); | 418 RenderProcess::current()->ReleaseProcess(); |
425 } | 419 } |
426 | 420 |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1136 webwidget_->setFocus(enable); | 1130 webwidget_->setFocus(enable); |
1137 } | 1131 } |
1138 | 1132 |
1139 void RenderWidget::ClearFocus() { | 1133 void RenderWidget::ClearFocus() { |
1140 // We may have got the focus from the browser before this gets processed, in | 1134 // We may have got the focus from the browser before this gets processed, in |
1141 // which case we do not want to unfocus ourself. | 1135 // which case we do not want to unfocus ourself. |
1142 if (!has_focus_ && webwidget_) | 1136 if (!has_focus_ && webwidget_) |
1143 webwidget_->setFocus(false); | 1137 webwidget_->setFocus(false); |
1144 } | 1138 } |
1145 | 1139 |
1146 void RenderWidget::InvalidationCallback() { | |
1147 TRACE_EVENT0("renderer", "RenderWidget::InvalidationCallback"); | |
1148 invalidation_task_posted_ = false; | |
1149 FlushPendingInputEventAck(); | |
1150 } | |
1151 | |
1152 void RenderWidget::FlushPendingInputEventAck() { | 1140 void RenderWidget::FlushPendingInputEventAck() { |
1153 if (pending_input_event_ack_) | 1141 if (pending_input_event_ack_) |
1154 Send(pending_input_event_ack_.release()); | 1142 Send(pending_input_event_ack_.release()); |
1155 total_input_handling_time_this_frame_ = base::TimeDelta(); | 1143 total_input_handling_time_this_frame_ = base::TimeDelta(); |
1156 } | 1144 } |
1157 | 1145 |
1158 /////////////////////////////////////////////////////////////////////////////// | 1146 /////////////////////////////////////////////////////////////////////////////// |
1159 // WebWidgetClient | 1147 // WebWidgetClient |
1160 | 1148 |
1161 void RenderWidget::didInvalidateRect(const WebRect& rect) { | |
piman
2014/05/12 23:55:21
There are still paths in WebKit that call didInval
| |
1162 // The invalidated rect might be outside the bounds of the view. | |
1163 gfx::Rect view_rect(size_); | |
1164 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, rect); | |
1165 if (damaged_rect.IsEmpty()) | |
1166 return; | |
1167 | |
1168 // We may not need to schedule another call to DoDeferredUpdate. | |
1169 if (invalidation_task_posted_) | |
1170 return; | |
1171 | |
1172 // Perform updating asynchronously. This serves two purposes: | |
1173 // 1) Ensures that we call WebView::Paint without a bunch of other junk | |
1174 // on the call stack. | |
1175 // 2) Allows us to collect more damage rects before painting to help coalesce | |
1176 // the work that we will need to do. | |
1177 invalidation_task_posted_ = true; | |
1178 base::MessageLoop::current()->PostTask( | |
1179 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this)); | |
1180 } | |
1181 | |
1182 void RenderWidget::didScrollRect(int dx, int dy, | |
1183 const WebRect& clip_rect) { | |
1184 // Drop scrolls on the floor when we are in compositing mode. | |
1185 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place. | |
1186 if (is_accelerated_compositing_active_) | |
1187 return; | |
1188 | |
1189 // The scrolled rect might be outside the bounds of the view. | |
1190 gfx::Rect view_rect(size_); | |
1191 gfx::Rect damaged_rect = gfx::IntersectRects(view_rect, clip_rect); | |
1192 if (damaged_rect.IsEmpty()) | |
1193 return; | |
1194 | |
1195 // We may not need to schedule another call to DoDeferredUpdate. | |
1196 if (invalidation_task_posted_) | |
1197 return; | |
1198 | |
1199 // Perform updating asynchronously. This serves two purposes: | |
1200 // 1) Ensures that we call WebView::Paint without a bunch of other junk | |
1201 // on the call stack. | |
1202 // 2) Allows us to collect more damage rects before painting to help coalesce | |
1203 // the work that we will need to do. | |
1204 invalidation_task_posted_ = true; | |
1205 base::MessageLoop::current()->PostTask( | |
1206 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this)); | |
1207 } | |
1208 | |
1209 void RenderWidget::didAutoResize(const WebSize& new_size) { | 1149 void RenderWidget::didAutoResize(const WebSize& new_size) { |
1210 if (size_.width() != new_size.width || size_.height() != new_size.height) { | 1150 if (size_.width() != new_size.width || size_.height() != new_size.height) { |
1211 size_ = new_size; | 1151 size_ = new_size; |
1212 | 1152 |
1213 if (resizing_mode_selector_->is_synchronous_mode()) { | 1153 if (resizing_mode_selector_->is_synchronous_mode()) { |
1214 WebRect new_pos(rootWindowRect().x, | 1154 WebRect new_pos(rootWindowRect().x, |
1215 rootWindowRect().y, | 1155 rootWindowRect().y, |
1216 new_size.width, | 1156 new_size.width, |
1217 new_size.height); | 1157 new_size.height); |
1218 view_screen_rect_ = new_pos; | 1158 view_screen_rect_ = new_pos; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1326 Send(new ViewHostMsg_UpdateRect(routing_id_, params)); | 1266 Send(new ViewHostMsg_UpdateRect(routing_id_, params)); |
1327 next_paint_flags_ = 0; | 1267 next_paint_flags_ = 0; |
1328 need_update_rect_for_auto_resize_ = false; | 1268 need_update_rect_for_auto_resize_ = false; |
1329 } | 1269 } |
1330 | 1270 |
1331 void RenderWidget::scheduleComposite() { | 1271 void RenderWidget::scheduleComposite() { |
1332 RenderThreadImpl* render_thread = RenderThreadImpl::current(); | 1272 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
1333 // render_thread may be NULL in tests. | 1273 // render_thread may be NULL in tests. |
1334 if (render_thread && render_thread->compositor_message_loop_proxy().get() && | 1274 if (render_thread && render_thread->compositor_message_loop_proxy().get() && |
1335 compositor_) { | 1275 compositor_) { |
1336 compositor_->setNeedsAnimate(); | 1276 compositor_->setNeedsAnimate(); |
1337 } else { | |
1338 // TODO(nduca): replace with something a little less hacky. The reason this | |
1339 // hack is still used is because the Invalidate-DoDeferredUpdate loop | |
1340 // contains a lot of host-renderer synchronization logic that is still | |
1341 // important for the accelerated compositing case. The option of simply | |
1342 // duplicating all that code is less desirable than "faking out" the | |
1343 // invalidation path using a magical damage rect. | |
1344 didInvalidateRect(WebRect(0, 0, 1, 1)); | |
1345 } | 1277 } |
1346 } | 1278 } |
1347 | 1279 |
1348 void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { | 1280 void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { |
1349 // TODO(darin): Eliminate this temporary. | 1281 // TODO(darin): Eliminate this temporary. |
1350 WebCursor cursor; | 1282 WebCursor cursor; |
1351 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info); | 1283 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info); |
1352 // Only send a SetCursor message if we need to make a change. | 1284 // Only send a SetCursor message if we need to make a change. |
1353 if (!current_cursor_.IsEqual(cursor)) { | 1285 if (!current_cursor_.IsEqual(cursor)) { |
1354 current_cursor_ = cursor; | 1286 current_cursor_ = cursor; |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2183 | 2115 |
2184 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) { | 2116 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) { |
2185 swapped_out_frames_.AddObserver(frame); | 2117 swapped_out_frames_.AddObserver(frame); |
2186 } | 2118 } |
2187 | 2119 |
2188 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) { | 2120 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) { |
2189 swapped_out_frames_.RemoveObserver(frame); | 2121 swapped_out_frames_.RemoveObserver(frame); |
2190 } | 2122 } |
2191 | 2123 |
2192 } // namespace content | 2124 } // namespace content |
OLD | NEW |