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/logging.h" | 10 #include "base/logging.h" |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 void RenderWidget::OnResize(const gfx::Size& new_size, | 367 void RenderWidget::OnResize(const gfx::Size& new_size, |
368 const gfx::Rect& resizer_rect, | 368 const gfx::Rect& resizer_rect, |
369 bool is_fullscreen) { | 369 bool is_fullscreen) { |
370 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK); | 370 Resize(new_size, resizer_rect, is_fullscreen, SEND_RESIZE_ACK); |
371 } | 371 } |
372 | 372 |
373 void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) { | 373 void RenderWidget::OnChangeResizeRect(const gfx::Rect& resizer_rect) { |
374 if (resizer_rect_ != resizer_rect) { | 374 if (resizer_rect_ != resizer_rect) { |
375 gfx::Rect view_rect(size_); | 375 gfx::Rect view_rect(size_); |
376 | 376 |
377 gfx::Rect old_damage_rect = view_rect.Intersect(resizer_rect_); | 377 gfx::Rect old_damage_rect = view_rect; |
| 378 old_damage_rect.Intersect(resizer_rect_); |
378 if (!old_damage_rect.IsEmpty()) | 379 if (!old_damage_rect.IsEmpty()) |
379 paint_aggregator_.InvalidateRect(old_damage_rect); | 380 paint_aggregator_.InvalidateRect(old_damage_rect); |
380 | 381 |
381 gfx::Rect new_damage_rect = view_rect.Intersect(resizer_rect); | 382 gfx::Rect new_damage_rect = view_rect; |
| 383 new_damage_rect.Intersect(resizer_rect); |
382 if (!new_damage_rect.IsEmpty()) | 384 if (!new_damage_rect.IsEmpty()) |
383 paint_aggregator_.InvalidateRect(new_damage_rect); | 385 paint_aggregator_.InvalidateRect(new_damage_rect); |
384 | 386 |
385 resizer_rect_ = resizer_rect; | 387 resizer_rect_ = resizer_rect; |
386 | 388 |
387 if (webwidget_) | 389 if (webwidget_) |
388 webwidget_->didChangeWindowResizerRect(); | 390 webwidget_->didChangeWindowResizerRect(); |
389 } | 391 } |
390 } | 392 } |
391 | 393 |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 software_stats_.numAnimationFrames++; | 931 software_stats_.numAnimationFrames++; |
930 software_stats_.numFramesSentToScreen++; | 932 software_stats_.numFramesSentToScreen++; |
931 } | 933 } |
932 | 934 |
933 // OK, save the pending update to a local since painting may cause more | 935 // OK, save the pending update to a local since painting may cause more |
934 // invalidation. Some WebCore rendering objects only layout when painted. | 936 // invalidation. Some WebCore rendering objects only layout when painted. |
935 PaintAggregator::PendingUpdate update; | 937 PaintAggregator::PendingUpdate update; |
936 paint_aggregator_.PopPendingUpdate(&update); | 938 paint_aggregator_.PopPendingUpdate(&update); |
937 | 939 |
938 gfx::Rect scroll_damage = update.GetScrollDamage(); | 940 gfx::Rect scroll_damage = update.GetScrollDamage(); |
939 gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage); | 941 gfx::Rect bounds = update.GetPaintBounds(); |
| 942 bounds.Union(scroll_damage); |
940 | 943 |
941 // Notify derived classes that we're about to initiate a paint. | 944 // Notify derived classes that we're about to initiate a paint. |
942 WillInitiatePaint(); | 945 WillInitiatePaint(); |
943 | 946 |
944 // A plugin may be able to do an optimized paint. First check this, in which | 947 // A plugin may be able to do an optimized paint. First check this, in which |
945 // case we can skip all of the bitmap generation and regular paint code. | 948 // case we can skip all of the bitmap generation and regular paint code. |
946 // This optimization allows PPAPI plugins that declare themselves on top of | 949 // This optimization allows PPAPI plugins that declare themselves on top of |
947 // the page (like a traditional windowed plugin) to be able to animate (think | 950 // the page (like a traditional windowed plugin) to be able to animate (think |
948 // movie playing) without repeatedly re-painting the page underneath, or | 951 // movie playing) without repeatedly re-painting the page underneath, or |
949 // copying the plugin backing store (since we can send the plugin's backing | 952 // copying the plugin backing store (since we can send the plugin's backing |
(...skipping 18 matching lines...) Expand all Loading... |
968 pending_update_params_->scale_factor = device_scale_factor_; | 971 pending_update_params_->scale_factor = device_scale_factor_; |
969 next_paint_flags_ = 0; | 972 next_paint_flags_ = 0; |
970 need_update_rect_for_auto_resize_ = false; | 973 need_update_rect_for_auto_resize_ = false; |
971 | 974 |
972 if (update.scroll_rect.IsEmpty() && | 975 if (update.scroll_rect.IsEmpty() && |
973 !is_accelerated_compositing_active_ && | 976 !is_accelerated_compositing_active_ && |
974 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location, | 977 GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location, |
975 &optimized_copy_rect, | 978 &optimized_copy_rect, |
976 &dib_scale_factor)) { | 979 &dib_scale_factor)) { |
977 // Only update the part of the plugin that actually changed. | 980 // Only update the part of the plugin that actually changed. |
978 optimized_copy_rect = optimized_copy_rect.Intersect(bounds); | 981 optimized_copy_rect.Intersect(bounds); |
979 pending_update_params_->bitmap = dib->id(); | 982 pending_update_params_->bitmap = dib->id(); |
980 pending_update_params_->bitmap_rect = optimized_copy_location; | 983 pending_update_params_->bitmap_rect = optimized_copy_location; |
981 pending_update_params_->copy_rects.push_back(optimized_copy_rect); | 984 pending_update_params_->copy_rects.push_back(optimized_copy_rect); |
982 pending_update_params_->scale_factor = dib_scale_factor; | 985 pending_update_params_->scale_factor = dib_scale_factor; |
983 } else if (!is_accelerated_compositing_active_) { | 986 } else if (!is_accelerated_compositing_active_) { |
984 // Compute a buffer for painting and cache it. | 987 // Compute a buffer for painting and cache it. |
985 gfx::Rect pixel_bounds = | 988 gfx::RectF scaled_bounds = bounds; |
986 gfx::ToEnclosingRect(bounds.Scale(device_scale_factor_)); | 989 scaled_bounds.Scale(device_scale_factor_); |
| 990 gfx::Rect pixel_bounds = gfx::ToEnclosingRect(scaled_bounds); |
987 scoped_ptr<skia::PlatformCanvas> canvas( | 991 scoped_ptr<skia::PlatformCanvas> canvas( |
988 RenderProcess::current()->GetDrawingCanvas(¤t_paint_buf_, | 992 RenderProcess::current()->GetDrawingCanvas(¤t_paint_buf_, |
989 pixel_bounds)); | 993 pixel_bounds)); |
990 if (!canvas.get()) { | 994 if (!canvas.get()) { |
991 NOTREACHED(); | 995 NOTREACHED(); |
992 return; | 996 return; |
993 } | 997 } |
994 | 998 |
995 // We may get back a smaller canvas than we asked for. | 999 // We may get back a smaller canvas than we asked for. |
996 // TODO(darin): This seems like it could cause painting problems! | 1000 // TODO(darin): This seems like it could cause painting problems! |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 if (!is_accelerated_compositing_active_) | 1058 if (!is_accelerated_compositing_active_) |
1055 DidInitiatePaint(); | 1059 DidInitiatePaint(); |
1056 } | 1060 } |
1057 | 1061 |
1058 /////////////////////////////////////////////////////////////////////////////// | 1062 /////////////////////////////////////////////////////////////////////////////// |
1059 // WebWidgetClient | 1063 // WebWidgetClient |
1060 | 1064 |
1061 void RenderWidget::didInvalidateRect(const WebRect& rect) { | 1065 void RenderWidget::didInvalidateRect(const WebRect& rect) { |
1062 // The invalidated rect might be outside the bounds of the view. | 1066 // The invalidated rect might be outside the bounds of the view. |
1063 gfx::Rect view_rect(size_); | 1067 gfx::Rect view_rect(size_); |
1064 gfx::Rect damaged_rect = view_rect.Intersect(rect); | 1068 gfx::Rect damaged_rect = view_rect; |
| 1069 damaged_rect.Intersect(rect); |
1065 if (damaged_rect.IsEmpty()) | 1070 if (damaged_rect.IsEmpty()) |
1066 return; | 1071 return; |
1067 | 1072 |
1068 paint_aggregator_.InvalidateRect(damaged_rect); | 1073 paint_aggregator_.InvalidateRect(damaged_rect); |
1069 | 1074 |
1070 // We may not need to schedule another call to DoDeferredUpdate. | 1075 // We may not need to schedule another call to DoDeferredUpdate. |
1071 if (invalidation_task_posted_) | 1076 if (invalidation_task_posted_) |
1072 return; | 1077 return; |
1073 if (!paint_aggregator_.HasPendingUpdate()) | 1078 if (!paint_aggregator_.HasPendingUpdate()) |
1074 return; | 1079 return; |
(...skipping 19 matching lines...) Expand all Loading... |
1094 } | 1099 } |
1095 | 1100 |
1096 void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) { | 1101 void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) { |
1097 // Drop scrolls on the floor when we are in compositing mode. | 1102 // Drop scrolls on the floor when we are in compositing mode. |
1098 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place. | 1103 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place. |
1099 if (is_accelerated_compositing_active_) | 1104 if (is_accelerated_compositing_active_) |
1100 return; | 1105 return; |
1101 | 1106 |
1102 // The scrolled rect might be outside the bounds of the view. | 1107 // The scrolled rect might be outside the bounds of the view. |
1103 gfx::Rect view_rect(size_); | 1108 gfx::Rect view_rect(size_); |
1104 gfx::Rect damaged_rect = view_rect.Intersect(clip_rect); | 1109 gfx::Rect damaged_rect = view_rect; |
| 1110 damaged_rect.Intersect(clip_rect); |
1105 if (damaged_rect.IsEmpty()) | 1111 if (damaged_rect.IsEmpty()) |
1106 return; | 1112 return; |
1107 | 1113 |
1108 paint_aggregator_.ScrollRect(dx, dy, damaged_rect); | 1114 paint_aggregator_.ScrollRect(dx, dy, damaged_rect); |
1109 | 1115 |
1110 // We may not need to schedule another call to DoDeferredUpdate. | 1116 // We may not need to schedule another call to DoDeferredUpdate. |
1111 if (invalidation_task_posted_) | 1117 if (invalidation_task_posted_) |
1112 return; | 1118 return; |
1113 if (!paint_aggregator_.HasPendingUpdate()) | 1119 if (!paint_aggregator_.HasPendingUpdate()) |
1114 return; | 1120 return; |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1890 pending_smooth_scroll_gestures_.insert(std::make_pair(id, callback)); | 1896 pending_smooth_scroll_gestures_.insert(std::make_pair(id, callback)); |
1891 } | 1897 } |
1892 | 1898 |
1893 bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { | 1899 bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
1894 return false; | 1900 return false; |
1895 } | 1901 } |
1896 | 1902 |
1897 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { | 1903 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { |
1898 return false; | 1904 return false; |
1899 } | 1905 } |
OLD | NEW |