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/webplugin_delegate_proxy.h" | 5 #include "content/renderer/webplugin_delegate_proxy.h" |
6 | 6 |
7 #if defined(TOOLKIT_GTK) | 7 #if defined(TOOLKIT_GTK) |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #elif defined(USE_X11) | 9 #elif defined(USE_X11) |
10 #include <cairo/cairo.h> | 10 #include <cairo/cairo.h> |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 // Intended for converting rects between flipped and non-flipped contexts. | 732 // Intended for converting rects between flipped and non-flipped contexts. |
733 static void FlipRectVerticallyWithHeight(gfx::Rect* rect, int height) { | 733 static void FlipRectVerticallyWithHeight(gfx::Rect* rect, int height) { |
734 rect->set_y(height - rect->bottom()); | 734 rect->set_y(height - rect->bottom()); |
735 } | 735 } |
736 #endif | 736 #endif |
737 | 737 |
738 void WebPluginDelegateProxy::Paint(WebKit::WebCanvas* canvas, | 738 void WebPluginDelegateProxy::Paint(WebKit::WebCanvas* canvas, |
739 const gfx::Rect& damaged_rect) { | 739 const gfx::Rect& damaged_rect) { |
740 // Limit the damaged rectangle to whatever is contained inside the plugin | 740 // Limit the damaged rectangle to whatever is contained inside the plugin |
741 // rectangle, as that's the rectangle that we'll actually draw. | 741 // rectangle, as that's the rectangle that we'll actually draw. |
742 gfx::Rect rect = damaged_rect; | 742 gfx::Rect rect = gfx::IntersectRects(damaged_rect, plugin_rect_); |
743 rect.Intersect(plugin_rect_); | |
744 | 743 |
745 // If the plugin is no longer connected (channel crashed) draw a crashed | 744 // If the plugin is no longer connected (channel crashed) draw a crashed |
746 // plugin bitmap | 745 // plugin bitmap |
747 if (!channel_host_ || !channel_host_->channel_valid()) { | 746 if (!channel_host_ || !channel_host_->channel_valid()) { |
748 PaintSadPlugin(canvas, rect); | 747 PaintSadPlugin(canvas, rect); |
749 return; | 748 return; |
750 } | 749 } |
751 | 750 |
752 if (!uses_shared_bitmaps_) | 751 if (!uses_shared_bitmaps_) |
753 return; | 752 return; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 XFORM xf; | 846 XFORM xf; |
848 if (!GetWorldTransform(context, &xf)) { | 847 if (!GetWorldTransform(context, &xf)) { |
849 NOTREACHED(); | 848 NOTREACHED(); |
850 return true; | 849 return true; |
851 } | 850 } |
852 | 851 |
853 // The damaged rect that we're given can be larger than the bitmap, so | 852 // The damaged rect that we're given can be larger than the bitmap, so |
854 // intersect their rects first. | 853 // intersect their rects first. |
855 gfx::Rect bitmap_rect(static_cast<int>(-xf.eDx), static_cast<int>(-xf.eDy), | 854 gfx::Rect bitmap_rect(static_cast<int>(-xf.eDx), static_cast<int>(-xf.eDy), |
856 bitmap.bmWidth, bitmap.bmHeight); | 855 bitmap.bmWidth, bitmap.bmHeight); |
857 gfx::Rect check_rect = rect; | 856 gfx::Rect check_rect = gfx::IntersectRects(rect, bitmap_rect); |
858 check_rect.Intersect(bitmap_rect); | |
859 int row_byte_size = check_rect.width() * (bitmap.bmBitsPixel / 8); | 857 int row_byte_size = check_rect.width() * (bitmap.bmBitsPixel / 8); |
860 for (int y = check_rect.y(); y < check_rect.bottom(); y++) { | 858 for (int y = check_rect.y(); y < check_rect.bottom(); y++) { |
861 char* hdc_row_start = static_cast<char*>(bitmap.bmBits) + | 859 char* hdc_row_start = static_cast<char*>(bitmap.bmBits) + |
862 (y + static_cast<int>(xf.eDy)) * bitmap.bmWidthBytes + | 860 (y + static_cast<int>(xf.eDy)) * bitmap.bmWidthBytes + |
863 (check_rect.x() + static_cast<int>(xf.eDx)) * (bitmap.bmBitsPixel / 8); | 861 (check_rect.x() + static_cast<int>(xf.eDx)) * (bitmap.bmBitsPixel / 8); |
864 | 862 |
865 // getAddr32 doesn't use the translation units, so we have to subtract | 863 // getAddr32 doesn't use the translation units, so we have to subtract |
866 // the plugin origin from the coordinates. | 864 // the plugin origin from the coordinates. |
867 uint32_t* canvas_row_start = | 865 uint32_t* canvas_row_start = |
868 background_store_.canvas->getDevice()->accessBitmap(true).getAddr32( | 866 background_store_.canvas->getDevice()->accessBitmap(true).getAddr32( |
(...skipping 24 matching lines...) Expand all Loading... |
893 double page_x_double = 0; | 891 double page_x_double = 0; |
894 double page_y_double = 0; | 892 double page_y_double = 0; |
895 cairo_device_to_user(context, &page_x_double, &page_y_double); | 893 cairo_device_to_user(context, &page_x_double, &page_y_double); |
896 gfx::Rect full_content_rect(static_cast<int>(page_x_double), | 894 gfx::Rect full_content_rect(static_cast<int>(page_x_double), |
897 static_cast<int>(page_y_double), | 895 static_cast<int>(page_y_double), |
898 cairo_image_surface_get_width(page_surface), | 896 cairo_image_surface_get_width(page_surface), |
899 cairo_image_surface_get_height(page_surface)); | 897 cairo_image_surface_get_height(page_surface)); |
900 #endif | 898 #endif |
901 // According to comments in the Windows code, the damage rect that we're given | 899 // According to comments in the Windows code, the damage rect that we're given |
902 // may project outside the image, so intersect their rects. | 900 // may project outside the image, so intersect their rects. |
903 gfx::Rect content_rect = rect; | 901 gfx::Rect content_rect = gfx::IntersectRects(rect, full_content_rect); |
904 content_rect.Intersect(full_content_rect); | |
905 | 902 |
906 #if defined(OS_MACOSX) | 903 #if defined(OS_MACOSX) |
907 const unsigned char* page_bytes = static_cast<const unsigned char*>( | 904 const unsigned char* page_bytes = static_cast<const unsigned char*>( |
908 CGBitmapContextGetData(context)); | 905 CGBitmapContextGetData(context)); |
909 int page_stride = CGBitmapContextGetBytesPerRow(context); | 906 int page_stride = CGBitmapContextGetBytesPerRow(context); |
910 int page_start_x = content_rect.x() - context_offset_x; | 907 int page_start_x = content_rect.x() - context_offset_x; |
911 int page_start_y = content_rect.y() - context_offset_y; | 908 int page_start_y = content_rect.y() - context_offset_y; |
912 | 909 |
913 skia::ScopedPlatformPaint scoped_platform_paint( | 910 skia::ScopedPlatformPaint scoped_platform_paint( |
914 background_store_.canvas.get()); | 911 background_store_.canvas.get()); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1184 if (plugin_) | 1181 if (plugin_) |
1185 plugin_->CancelResource(id); | 1182 plugin_->CancelResource(id); |
1186 } | 1183 } |
1187 | 1184 |
1188 void WebPluginDelegateProxy::OnInvalidateRect(const gfx::Rect& rect) { | 1185 void WebPluginDelegateProxy::OnInvalidateRect(const gfx::Rect& rect) { |
1189 if (!plugin_) | 1186 if (!plugin_) |
1190 return; | 1187 return; |
1191 | 1188 |
1192 // Clip the invalidation rect to the plugin bounds; the plugin may have been | 1189 // Clip the invalidation rect to the plugin bounds; the plugin may have been |
1193 // resized since the invalidate message was sent. | 1190 // resized since the invalidate message was sent. |
1194 gfx::Rect clipped_rect = rect; | 1191 gfx::Rect clipped_rect = |
1195 clipped_rect.Intersect(gfx::Rect(plugin_rect_.size())); | 1192 gfx::IntersectRects(rect, gfx::Rect(plugin_rect_.size())); |
1196 | 1193 |
1197 invalidate_pending_ = true; | 1194 invalidate_pending_ = true; |
1198 // The plugin is blocked on the renderer because the invalidate message it has | 1195 // The plugin is blocked on the renderer because the invalidate message it has |
1199 // sent us is synchronous, so we can use buffer flipping here if the caller | 1196 // sent us is synchronous, so we can use buffer flipping here if the caller |
1200 // allows it. | 1197 // allows it. |
1201 UpdateFrontBuffer(clipped_rect, true); | 1198 UpdateFrontBuffer(clipped_rect, true); |
1202 plugin_->InvalidateRect(clipped_rect); | 1199 plugin_->InvalidateRect(clipped_rect); |
1203 } | 1200 } |
1204 | 1201 |
1205 void WebPluginDelegateProxy::OnGetWindowScriptNPObject( | 1202 void WebPluginDelegateProxy::OnGetWindowScriptNPObject( |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1533 | 1530 |
1534 void WebPluginDelegateProxy::OnURLRedirectResponse(bool allow, | 1531 void WebPluginDelegateProxy::OnURLRedirectResponse(bool allow, |
1535 int resource_id) { | 1532 int resource_id) { |
1536 if (!plugin_) | 1533 if (!plugin_) |
1537 return; | 1534 return; |
1538 | 1535 |
1539 plugin_->URLRedirectResponse(allow, resource_id); | 1536 plugin_->URLRedirectResponse(allow, resource_id); |
1540 } | 1537 } |
1541 | 1538 |
1542 } // namespace content | 1539 } // namespace content |
OLD | NEW |