OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/renderer_host/render_widget_host.h" | 5 #include "chrome/browser/renderer_host/render_widget_host.h" |
6 | 6 |
7 #include "app/keyboard_codes.h" | 7 #include "app/keyboard_codes.h" |
8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 } | 756 } |
757 | 757 |
758 void RenderWidgetHost::OnMsgPaintAtSizeAck(int tag, const gfx::Size& size) { | 758 void RenderWidgetHost::OnMsgPaintAtSizeAck(int tag, const gfx::Size& size) { |
759 if (painting_observer_) { | 759 if (painting_observer_) { |
760 painting_observer_->WidgetDidReceivePaintAtSizeAck(this, tag, size); | 760 painting_observer_->WidgetDidReceivePaintAtSizeAck(this, tag, size); |
761 } | 761 } |
762 } | 762 } |
763 | 763 |
764 void RenderWidgetHost::OnMsgUpdateRect( | 764 void RenderWidgetHost::OnMsgUpdateRect( |
765 const ViewHostMsg_UpdateRect_Params& params) { | 765 const ViewHostMsg_UpdateRect_Params& params) { |
| 766 TransportDIB::ScopedHandle dib_handle(params.dib_handle); |
766 TimeTicks paint_start = TimeTicks::Now(); | 767 TimeTicks paint_start = TimeTicks::Now(); |
767 | 768 |
768 if (paint_observer_.get()) | 769 if (paint_observer_.get()) |
769 paint_observer_->RenderWidgetHostWillPaint(this); | 770 paint_observer_->RenderWidgetHostWillPaint(this); |
770 | 771 |
771 // Update our knowledge of the RenderWidget's size. | 772 // Update our knowledge of the RenderWidget's size. |
772 current_size_ = params.view_size; | 773 current_size_ = params.view_size; |
773 | 774 |
774 bool is_resize_ack = | 775 bool is_resize_ack = |
775 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); | 776 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); |
(...skipping 14 matching lines...) Expand all Loading... |
790 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta); | 791 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta); |
791 } | 792 } |
792 | 793 |
793 DCHECK(!params.bitmap_rect.IsEmpty()); | 794 DCHECK(!params.bitmap_rect.IsEmpty()); |
794 DCHECK(!params.view_size.IsEmpty()); | 795 DCHECK(!params.view_size.IsEmpty()); |
795 | 796 |
796 bool painted_synchronously = true; // Default to sending a paint ACK below. | 797 bool painted_synchronously = true; // Default to sending a paint ACK below. |
797 if (!is_gpu_rendering_active_) { | 798 if (!is_gpu_rendering_active_) { |
798 const size_t size = params.bitmap_rect.height() * | 799 const size_t size = params.bitmap_rect.height() * |
799 params.bitmap_rect.width() * 4; | 800 params.bitmap_rect.width() * 4; |
800 TransportDIB* dib = process_->GetTransportDIB(params.bitmap); | 801 TransportDIB* dib = process_->GetTransportDIB(params.dib_id, |
| 802 dib_handle.release()); |
801 | 803 |
802 // If gpu process does painting, scroll_rect and copy_rects are always empty | 804 // If gpu process does painting, scroll_rect and copy_rects are always empty |
803 // and backing store is never used. | 805 // and backing store is never used. |
804 if (dib) { | 806 if (dib) { |
805 if (dib->size() < size) { | 807 if (dib->size() < size) { |
806 DLOG(WARNING) << "Transport DIB too small for given rectangle"; | 808 DLOG(WARNING) << "Transport DIB too small for given rectangle"; |
807 process()->ReceivedBadMessage(ViewHostMsg_UpdateRect__ID); | 809 process()->ReceivedBadMessage(ViewHostMsg_UpdateRect__ID); |
808 } else { | 810 } else { |
809 // Scroll the backing store. | 811 // Scroll the backing store. |
810 if (!params.scroll_rect.IsEmpty()) { | 812 if (!params.scroll_rect.IsEmpty()) { |
811 ScrollBackingStoreRect(params.dx, params.dy, | 813 ScrollBackingStoreRect(params.dx, params.dy, |
812 params.scroll_rect, | 814 params.scroll_rect, |
813 params.view_size); | 815 params.view_size); |
814 } | 816 } |
815 | 817 |
816 // Paint the backing store. This will update it with the | 818 // Paint the backing store. This will update it with the |
817 // renderer-supplied bits. The view will read out of the backing store | 819 // renderer-supplied bits. The view will read out of the backing store |
818 // later to actually draw to the screen. | 820 // later to actually draw to the screen. |
819 PaintBackingStoreRect(params.bitmap, params.bitmap_rect, | 821 PaintBackingStoreRect(params.dib_id, |
820 params.copy_rects, params.view_size, | 822 params.dib_handle, |
| 823 params.bitmap_rect, |
| 824 params.copy_rects, |
| 825 params.view_size, |
821 &painted_synchronously); | 826 &painted_synchronously); |
822 } | 827 } |
823 } | 828 } |
824 } | 829 } |
825 | 830 |
826 // ACK early so we can prefetch the next PaintRect if there is a next one. | 831 // ACK early so we can prefetch the next PaintRect if there is a next one. |
827 // This must be done AFTER we're done painting with the bitmap supplied by the | 832 // This must be done AFTER we're done painting with the bitmap supplied by the |
828 // renderer. This ACK is a signal to the renderer that the backing store can | 833 // renderer. This ACK is a signal to the renderer that the backing store can |
829 // be re-used, so the bitmap may be invalid after this call. If the backing | 834 // be re-used, so the bitmap may be invalid after this call. If the backing |
830 // store is painting asynchronously, it will manage issuing this IPC. | 835 // store is painting asynchronously, it will manage issuing this IPC. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 | 879 |
875 void RenderWidgetHost::OnMsgCreateVideo(const gfx::Size& size) { | 880 void RenderWidgetHost::OnMsgCreateVideo(const gfx::Size& size) { |
876 DCHECK(!video_layer_.get()); | 881 DCHECK(!video_layer_.get()); |
877 | 882 |
878 video_layer_.reset(view_->AllocVideoLayer(size)); | 883 video_layer_.reset(view_->AllocVideoLayer(size)); |
879 | 884 |
880 // TODO(scherkus): support actual video ids! | 885 // TODO(scherkus): support actual video ids! |
881 Send(new ViewMsg_CreateVideo_ACK(routing_id_, -1)); | 886 Send(new ViewMsg_CreateVideo_ACK(routing_id_, -1)); |
882 } | 887 } |
883 | 888 |
884 void RenderWidgetHost::OnMsgUpdateVideo(TransportDIB::Id bitmap, | 889 void RenderWidgetHost::OnMsgUpdateVideo(TransportDIB::Id dib_id, |
| 890 TransportDIB::Handle dib_handle, |
885 const gfx::Rect& bitmap_rect) { | 891 const gfx::Rect& bitmap_rect) { |
886 PaintVideoLayer(bitmap, bitmap_rect); | 892 PaintVideoLayer(dib_id, dib_handle, bitmap_rect); |
887 | 893 |
888 // TODO(scherkus): support actual video ids! | 894 // TODO(scherkus): support actual video ids! |
889 Send(new ViewMsg_UpdateVideo_ACK(routing_id_, -1)); | 895 Send(new ViewMsg_UpdateVideo_ACK(routing_id_, -1)); |
890 } | 896 } |
891 | 897 |
892 void RenderWidgetHost::OnMsgDestroyVideo() { | 898 void RenderWidgetHost::OnMsgDestroyVideo() { |
893 video_layer_.reset(); | 899 video_layer_.reset(); |
894 } | 900 } |
895 | 901 |
896 void RenderWidgetHost::OnMsgInputEventAck(const IPC::Message& message) { | 902 void RenderWidgetHost::OnMsgInputEventAck(const IPC::Message& message) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 if (view_) { | 1048 if (view_) { |
1043 view_->AcceleratedSurfaceSetIOSurface(window, width, height, mach_port); | 1049 view_->AcceleratedSurfaceSetIOSurface(window, width, height, mach_port); |
1044 } | 1050 } |
1045 } | 1051 } |
1046 | 1052 |
1047 void RenderWidgetHost::OnAcceleratedSurfaceSetTransportDIB( | 1053 void RenderWidgetHost::OnAcceleratedSurfaceSetTransportDIB( |
1048 gfx::PluginWindowHandle window, | 1054 gfx::PluginWindowHandle window, |
1049 int32 width, | 1055 int32 width, |
1050 int32 height, | 1056 int32 height, |
1051 TransportDIB::Handle transport_dib) { | 1057 TransportDIB::Handle transport_dib) { |
| 1058 TransportDIB::ScopedHandle scoped_dib_handle(transport_dib); |
1052 if (view_) { | 1059 if (view_) { |
1053 view_->AcceleratedSurfaceSetTransportDIB(window, width, height, | 1060 view_->AcceleratedSurfaceSetTransportDIB(window, width, height, |
1054 transport_dib); | 1061 scoped_dib_handle.release()); |
1055 } | 1062 } |
1056 } | 1063 } |
1057 | 1064 |
1058 void RenderWidgetHost::OnAcceleratedSurfaceBuffersSwapped( | 1065 void RenderWidgetHost::OnAcceleratedSurfaceBuffersSwapped( |
1059 gfx::PluginWindowHandle window) { | 1066 gfx::PluginWindowHandle window) { |
1060 if (view_) { | 1067 if (view_) { |
1061 view_->AcceleratedSurfaceBuffersSwapped(window); | 1068 view_->AcceleratedSurfaceBuffersSwapped(window); |
1062 } | 1069 } |
1063 } | 1070 } |
1064 #elif defined(OS_POSIX) | 1071 #elif defined(OS_POSIX) |
(...skipping 13 matching lines...) Expand all Loading... |
1078 if (view_) { | 1085 if (view_) { |
1079 view_->DestroyPluginContainer(id); | 1086 view_->DestroyPluginContainer(id); |
1080 } else { | 1087 } else { |
1081 NOTIMPLEMENTED(); | 1088 NOTIMPLEMENTED(); |
1082 } | 1089 } |
1083 } | 1090 } |
1084 | 1091 |
1085 #endif | 1092 #endif |
1086 | 1093 |
1087 void RenderWidgetHost::PaintBackingStoreRect( | 1094 void RenderWidgetHost::PaintBackingStoreRect( |
1088 TransportDIB::Id bitmap, | 1095 TransportDIB::Id dib_id, |
| 1096 TransportDIB::Handle dib_handle, |
1089 const gfx::Rect& bitmap_rect, | 1097 const gfx::Rect& bitmap_rect, |
1090 const std::vector<gfx::Rect>& copy_rects, | 1098 const std::vector<gfx::Rect>& copy_rects, |
1091 const gfx::Size& view_size, | 1099 const gfx::Size& view_size, |
1092 bool* painted_synchronously) { | 1100 bool* painted_synchronously) { |
1093 // On failure, we need to be sure our caller knows we're done with the | 1101 // On failure, we need to be sure our caller knows we're done with the |
1094 // backing store. | 1102 // backing store. |
1095 *painted_synchronously = true; | 1103 *painted_synchronously = true; |
1096 | 1104 |
1097 // The view may be destroyed already. | 1105 // The view may be destroyed already. |
1098 if (!view_) | 1106 if (!view_) |
1099 return; | 1107 return; |
1100 | 1108 |
1101 if (is_hidden_) { | 1109 if (is_hidden_) { |
1102 // Don't bother updating the backing store when we're hidden. Just mark it | 1110 // Don't bother updating the backing store when we're hidden. Just mark it |
1103 // as being totally invalid. This will cause a complete repaint when the | 1111 // as being totally invalid. This will cause a complete repaint when the |
1104 // view is restored. | 1112 // view is restored. |
1105 needs_repainting_on_restore_ = true; | 1113 needs_repainting_on_restore_ = true; |
1106 return; | 1114 return; |
1107 } | 1115 } |
1108 | 1116 |
1109 bool needs_full_paint = false; | 1117 bool needs_full_paint = false; |
1110 BackingStoreManager::PrepareBackingStore(this, view_size, bitmap, bitmap_rect, | 1118 BackingStoreManager::PrepareBackingStore(this, |
1111 copy_rects, &needs_full_paint, | 1119 view_size, |
| 1120 dib_id, |
| 1121 dib_handle, |
| 1122 bitmap_rect, |
| 1123 copy_rects, |
| 1124 &needs_full_paint, |
1112 painted_synchronously); | 1125 painted_synchronously); |
1113 if (needs_full_paint) { | 1126 if (needs_full_paint) { |
1114 repaint_start_time_ = TimeTicks::Now(); | 1127 repaint_start_time_ = TimeTicks::Now(); |
1115 repaint_ack_pending_ = true; | 1128 repaint_ack_pending_ = true; |
1116 Send(new ViewMsg_Repaint(routing_id_, view_size)); | 1129 Send(new ViewMsg_Repaint(routing_id_, view_size)); |
1117 } | 1130 } |
1118 } | 1131 } |
1119 | 1132 |
1120 void RenderWidgetHost::ScrollBackingStoreRect(int dx, int dy, | 1133 void RenderWidgetHost::ScrollBackingStoreRect(int dx, int dy, |
1121 const gfx::Rect& clip_rect, | 1134 const gfx::Rect& clip_rect, |
1122 const gfx::Size& view_size) { | 1135 const gfx::Size& view_size) { |
1123 if (is_hidden_) { | 1136 if (is_hidden_) { |
1124 // Don't bother updating the backing store when we're hidden. Just mark it | 1137 // Don't bother updating the backing store when we're hidden. Just mark it |
1125 // as being totally invalid. This will cause a complete repaint when the | 1138 // as being totally invalid. This will cause a complete repaint when the |
1126 // view is restored. | 1139 // view is restored. |
1127 needs_repainting_on_restore_ = true; | 1140 needs_repainting_on_restore_ = true; |
1128 return; | 1141 return; |
1129 } | 1142 } |
1130 | 1143 |
1131 // TODO(darin): do we need to do something else if our backing store is not | 1144 // TODO(darin): do we need to do something else if our backing store is not |
1132 // the same size as the advertised view? maybe we just assume there is a | 1145 // the same size as the advertised view? maybe we just assume there is a |
1133 // full paint on its way? | 1146 // full paint on its way? |
1134 BackingStore* backing_store = BackingStoreManager::Lookup(this); | 1147 BackingStore* backing_store = BackingStoreManager::Lookup(this); |
1135 if (!backing_store || (backing_store->size() != view_size)) | 1148 if (!backing_store || (backing_store->size() != view_size)) |
1136 return; | 1149 return; |
1137 backing_store->ScrollBackingStore(dx, dy, clip_rect, view_size); | 1150 backing_store->ScrollBackingStore(dx, dy, clip_rect, view_size); |
1138 } | 1151 } |
1139 | 1152 |
1140 void RenderWidgetHost::PaintVideoLayer(TransportDIB::Id bitmap, | 1153 void RenderWidgetHost::PaintVideoLayer(TransportDIB::Id dib_id, |
| 1154 TransportDIB::Handle dib_handle, |
1141 const gfx::Rect& bitmap_rect) { | 1155 const gfx::Rect& bitmap_rect) { |
1142 if (is_hidden_ || !video_layer_.get()) | 1156 if (is_hidden_ || !video_layer_.get()) |
1143 return; | 1157 return; |
1144 | 1158 |
1145 video_layer_->CopyTransportDIB(process(), bitmap, bitmap_rect); | 1159 video_layer_->CopyTransportDIB(process(), dib_id, dib_handle, bitmap_rect); |
1146 | 1160 |
1147 // Don't update the view if we're hidden or if the view has been destroyed. | 1161 // Don't update the view if we're hidden or if the view has been destroyed. |
1148 if (is_hidden_ || !view_) | 1162 if (is_hidden_ || !view_) |
1149 return; | 1163 return; |
1150 | 1164 |
1151 // Trigger a paint for the updated video layer bitmap. | 1165 // Trigger a paint for the updated video layer bitmap. |
1152 std::vector<gfx::Rect> copy_rects; | 1166 std::vector<gfx::Rect> copy_rects; |
1153 copy_rects.push_back(bitmap_rect); | 1167 copy_rects.push_back(bitmap_rect); |
1154 | 1168 |
1155 view_being_painted_ = true; | 1169 view_being_painted_ = true; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 // of this key event. | 1239 // of this key event. |
1226 if (!processed && !is_hidden_ && !front_item.skip_in_browser) { | 1240 if (!processed && !is_hidden_ && !front_item.skip_in_browser) { |
1227 UnhandledKeyboardEvent(front_item); | 1241 UnhandledKeyboardEvent(front_item); |
1228 | 1242 |
1229 // WARNING: This RenderWidgetHost can be deallocated at this point | 1243 // WARNING: This RenderWidgetHost can be deallocated at this point |
1230 // (i.e. in the case of Ctrl+W, where the call to | 1244 // (i.e. in the case of Ctrl+W, where the call to |
1231 // UnhandledKeyboardEvent destroys this RenderWidgetHost). | 1245 // UnhandledKeyboardEvent destroys this RenderWidgetHost). |
1232 } | 1246 } |
1233 } | 1247 } |
1234 } | 1248 } |
OLD | NEW |