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 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 // Intended for converting rects between flipped and non-flipped contexts. | 730 // Intended for converting rects between flipped and non-flipped contexts. |
731 static void FlipRectVerticallyWithHeight(gfx::Rect* rect, int height) { | 731 static void FlipRectVerticallyWithHeight(gfx::Rect* rect, int height) { |
732 rect->set_y(height - rect->bottom()); | 732 rect->set_y(height - rect->bottom()); |
733 } | 733 } |
734 #endif | 734 #endif |
735 | 735 |
736 void WebPluginDelegateProxy::Paint(WebKit::WebCanvas* canvas, | 736 void WebPluginDelegateProxy::Paint(WebKit::WebCanvas* canvas, |
737 const gfx::Rect& damaged_rect) { | 737 const gfx::Rect& damaged_rect) { |
738 // Limit the damaged rectangle to whatever is contained inside the plugin | 738 // Limit the damaged rectangle to whatever is contained inside the plugin |
739 // rectangle, as that's the rectangle that we'll actually draw. | 739 // rectangle, as that's the rectangle that we'll actually draw. |
740 gfx::Rect rect = damaged_rect.Intersect(plugin_rect_); | 740 gfx::Rect rect = damaged_rect; |
| 741 rect.Intersect(plugin_rect_); |
741 | 742 |
742 // If the plugin is no longer connected (channel crashed) draw a crashed | 743 // If the plugin is no longer connected (channel crashed) draw a crashed |
743 // plugin bitmap | 744 // plugin bitmap |
744 if (!channel_host_ || !channel_host_->channel_valid()) { | 745 if (!channel_host_ || !channel_host_->channel_valid()) { |
745 PaintSadPlugin(canvas, rect); | 746 PaintSadPlugin(canvas, rect); |
746 return; | 747 return; |
747 } | 748 } |
748 | 749 |
749 if (!uses_shared_bitmaps_) | 750 if (!uses_shared_bitmaps_) |
750 return; | 751 return; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 XFORM xf; | 845 XFORM xf; |
845 if (!GetWorldTransform(context, &xf)) { | 846 if (!GetWorldTransform(context, &xf)) { |
846 NOTREACHED(); | 847 NOTREACHED(); |
847 return true; | 848 return true; |
848 } | 849 } |
849 | 850 |
850 // The damaged rect that we're given can be larger than the bitmap, so | 851 // The damaged rect that we're given can be larger than the bitmap, so |
851 // intersect their rects first. | 852 // intersect their rects first. |
852 gfx::Rect bitmap_rect(static_cast<int>(-xf.eDx), static_cast<int>(-xf.eDy), | 853 gfx::Rect bitmap_rect(static_cast<int>(-xf.eDx), static_cast<int>(-xf.eDy), |
853 bitmap.bmWidth, bitmap.bmHeight); | 854 bitmap.bmWidth, bitmap.bmHeight); |
854 gfx::Rect check_rect = rect.Intersect(bitmap_rect); | 855 gfx::Rect check_rect = rect; |
| 856 check_rect.Intersect(bitmap_rect); |
855 int row_byte_size = check_rect.width() * (bitmap.bmBitsPixel / 8); | 857 int row_byte_size = check_rect.width() * (bitmap.bmBitsPixel / 8); |
856 for (int y = check_rect.y(); y < check_rect.bottom(); y++) { | 858 for (int y = check_rect.y(); y < check_rect.bottom(); y++) { |
857 char* hdc_row_start = static_cast<char*>(bitmap.bmBits) + | 859 char* hdc_row_start = static_cast<char*>(bitmap.bmBits) + |
858 (y + static_cast<int>(xf.eDy)) * bitmap.bmWidthBytes + | 860 (y + static_cast<int>(xf.eDy)) * bitmap.bmWidthBytes + |
859 (check_rect.x() + static_cast<int>(xf.eDx)) * (bitmap.bmBitsPixel / 8); | 861 (check_rect.x() + static_cast<int>(xf.eDx)) * (bitmap.bmBitsPixel / 8); |
860 | 862 |
861 // 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 |
862 // the plugin origin from the coordinates. | 864 // the plugin origin from the coordinates. |
863 uint32_t* canvas_row_start = | 865 uint32_t* canvas_row_start = |
864 background_store_.canvas->getDevice()->accessBitmap(true).getAddr32( | 866 background_store_.canvas->getDevice()->accessBitmap(true).getAddr32( |
(...skipping 24 matching lines...) Expand all Loading... |
889 double page_x_double = 0; | 891 double page_x_double = 0; |
890 double page_y_double = 0; | 892 double page_y_double = 0; |
891 cairo_device_to_user(context, &page_x_double, &page_y_double); | 893 cairo_device_to_user(context, &page_x_double, &page_y_double); |
892 gfx::Rect full_content_rect(static_cast<int>(page_x_double), | 894 gfx::Rect full_content_rect(static_cast<int>(page_x_double), |
893 static_cast<int>(page_y_double), | 895 static_cast<int>(page_y_double), |
894 cairo_image_surface_get_width(page_surface), | 896 cairo_image_surface_get_width(page_surface), |
895 cairo_image_surface_get_height(page_surface)); | 897 cairo_image_surface_get_height(page_surface)); |
896 #endif | 898 #endif |
897 // 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 |
898 // may project outside the image, so intersect their rects. | 900 // may project outside the image, so intersect their rects. |
899 gfx::Rect content_rect = rect.Intersect(full_content_rect); | 901 gfx::Rect content_rect = rect; |
| 902 content_rect.Intersect(full_content_rect); |
900 | 903 |
901 #if defined(OS_MACOSX) | 904 #if defined(OS_MACOSX) |
902 const unsigned char* page_bytes = static_cast<const unsigned char*>( | 905 const unsigned char* page_bytes = static_cast<const unsigned char*>( |
903 CGBitmapContextGetData(context)); | 906 CGBitmapContextGetData(context)); |
904 int page_stride = CGBitmapContextGetBytesPerRow(context); | 907 int page_stride = CGBitmapContextGetBytesPerRow(context); |
905 int page_start_x = content_rect.x() - context_offset_x; | 908 int page_start_x = content_rect.x() - context_offset_x; |
906 int page_start_y = content_rect.y() - context_offset_y; | 909 int page_start_y = content_rect.y() - context_offset_y; |
907 | 910 |
908 skia::ScopedPlatformPaint scoped_platform_paint( | 911 skia::ScopedPlatformPaint scoped_platform_paint( |
909 background_store_.canvas.get()); | 912 background_store_.canvas.get()); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 if (plugin_) | 1182 if (plugin_) |
1180 plugin_->CancelResource(id); | 1183 plugin_->CancelResource(id); |
1181 } | 1184 } |
1182 | 1185 |
1183 void WebPluginDelegateProxy::OnInvalidateRect(const gfx::Rect& rect) { | 1186 void WebPluginDelegateProxy::OnInvalidateRect(const gfx::Rect& rect) { |
1184 if (!plugin_) | 1187 if (!plugin_) |
1185 return; | 1188 return; |
1186 | 1189 |
1187 // Clip the invalidation rect to the plugin bounds; the plugin may have been | 1190 // Clip the invalidation rect to the plugin bounds; the plugin may have been |
1188 // resized since the invalidate message was sent. | 1191 // resized since the invalidate message was sent. |
1189 const gfx::Rect clipped_rect(rect.Intersect(gfx::Rect(plugin_rect_.size()))); | 1192 gfx::Rect clipped_rect = rect; |
| 1193 clipped_rect.Intersect(gfx::Rect(plugin_rect_.size())); |
1190 | 1194 |
1191 invalidate_pending_ = true; | 1195 invalidate_pending_ = true; |
1192 // The plugin is blocked on the renderer because the invalidate message it has | 1196 // The plugin is blocked on the renderer because the invalidate message it has |
1193 // sent us is synchronous, so we can use buffer flipping here if the caller | 1197 // sent us is synchronous, so we can use buffer flipping here if the caller |
1194 // allows it. | 1198 // allows it. |
1195 UpdateFrontBuffer(clipped_rect, true); | 1199 UpdateFrontBuffer(clipped_rect, true); |
1196 plugin_->InvalidateRect(clipped_rect); | 1200 plugin_->InvalidateRect(clipped_rect); |
1197 } | 1201 } |
1198 | 1202 |
1199 void WebPluginDelegateProxy::OnGetWindowScriptNPObject( | 1203 void WebPluginDelegateProxy::OnGetWindowScriptNPObject( |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1300 // want to use buffer flipping at all since it would add extra locking. | 1304 // want to use buffer flipping at all since it would add extra locking. |
1301 // (Alternatively we could probably safely use async updates for buffer | 1305 // (Alternatively we could probably safely use async updates for buffer |
1302 // flipping all the time since the size is not changing.) | 1306 // flipping all the time since the size is not changing.) |
1303 if (UseSynchronousGeometryUpdates()) { | 1307 if (UseSynchronousGeometryUpdates()) { |
1304 allow_buffer_flipping = false; | 1308 allow_buffer_flipping = false; |
1305 } | 1309 } |
1306 #endif | 1310 #endif |
1307 | 1311 |
1308 // Plugin has just painted "rect" into the back-buffer, so the front-buffer | 1312 // Plugin has just painted "rect" into the back-buffer, so the front-buffer |
1309 // no longer holds the latest content for that rectangle. | 1313 // no longer holds the latest content for that rectangle. |
1310 front_buffer_diff_ = front_buffer_diff_.Subtract(rect); | 1314 front_buffer_diff_.Subtract(rect); |
1311 if (allow_buffer_flipping && front_buffer_diff_.IsEmpty()) { | 1315 if (allow_buffer_flipping && front_buffer_diff_.IsEmpty()) { |
1312 // Back-buffer contains the latest content for all areas; simply flip | 1316 // Back-buffer contains the latest content for all areas; simply flip |
1313 // the buffers. | 1317 // the buffers. |
1314 front_buffer_index_ = back_buffer_index(); | 1318 front_buffer_index_ = back_buffer_index(); |
1315 SendUpdateGeometry(false); | 1319 SendUpdateGeometry(false); |
1316 // The front-buffer now holds newer content for this region than the | 1320 // The front-buffer now holds newer content for this region than the |
1317 // back-buffer. | 1321 // back-buffer. |
1318 front_buffer_diff_ = rect; | 1322 front_buffer_diff_ = rect; |
1319 } else { | 1323 } else { |
1320 // Back-buffer contains the latest content for "rect" but the front-buffer | 1324 // Back-buffer contains the latest content for "rect" but the front-buffer |
1321 // contains the latest content for some other areas (or buffer flipping not | 1325 // contains the latest content for some other areas (or buffer flipping not |
1322 // allowed); fall back to copying the data. | 1326 // allowed); fall back to copying the data. |
1323 CopyFromBackBufferToFrontBuffer(rect); | 1327 CopyFromBackBufferToFrontBuffer(rect); |
1324 } | 1328 } |
1325 transport_store_painted_ = transport_store_painted_.Union(rect); | 1329 transport_store_painted_.Union(rect); |
1326 } | 1330 } |
1327 | 1331 |
1328 void WebPluginDelegateProxy::OnHandleURLRequest( | 1332 void WebPluginDelegateProxy::OnHandleURLRequest( |
1329 const PluginHostMsg_URLRequest_Params& params) { | 1333 const PluginHostMsg_URLRequest_Params& params) { |
1330 const char* data = NULL; | 1334 const char* data = NULL; |
1331 if (params.buffer.size()) | 1335 if (params.buffer.size()) |
1332 data = ¶ms.buffer[0]; | 1336 data = ¶ms.buffer[0]; |
1333 | 1337 |
1334 const char* target = NULL; | 1338 const char* target = NULL; |
1335 if (params.target.length()) | 1339 if (params.target.length()) |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1525 } | 1529 } |
1526 #endif | 1530 #endif |
1527 | 1531 |
1528 void WebPluginDelegateProxy::OnURLRedirectResponse(bool allow, | 1532 void WebPluginDelegateProxy::OnURLRedirectResponse(bool allow, |
1529 int resource_id) { | 1533 int resource_id) { |
1530 if (!plugin_) | 1534 if (!plugin_) |
1531 return; | 1535 return; |
1532 | 1536 |
1533 plugin_->URLRedirectResponse(allow, resource_id); | 1537 plugin_->URLRedirectResponse(allow, resource_id); |
1534 } | 1538 } |
OLD | NEW |