Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Side by Side Diff: content/renderer/webplugin_delegate_proxy.cc

Issue 11110004: Make gfx::Rect class operations consistently mutate the class they are called on. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: cc/ fixes Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/renderer/render_widget.cc ('k') | ui/app_list/apps_grid_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.Intersect(plugin_rect_); 742 gfx::Rect rect = damaged_rect;
743 rect.Intersect(plugin_rect_);
743 744
744 // If the plugin is no longer connected (channel crashed) draw a crashed 745 // If the plugin is no longer connected (channel crashed) draw a crashed
745 // plugin bitmap 746 // plugin bitmap
746 if (!channel_host_ || !channel_host_->channel_valid()) { 747 if (!channel_host_ || !channel_host_->channel_valid()) {
747 PaintSadPlugin(canvas, rect); 748 PaintSadPlugin(canvas, rect);
748 return; 749 return;
749 } 750 }
750 751
751 if (!uses_shared_bitmaps_) 752 if (!uses_shared_bitmaps_)
752 return; 753 return;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 XFORM xf; 847 XFORM xf;
847 if (!GetWorldTransform(context, &xf)) { 848 if (!GetWorldTransform(context, &xf)) {
848 NOTREACHED(); 849 NOTREACHED();
849 return true; 850 return true;
850 } 851 }
851 852
852 // The damaged rect that we're given can be larger than the bitmap, so 853 // The damaged rect that we're given can be larger than the bitmap, so
853 // intersect their rects first. 854 // intersect their rects first.
854 gfx::Rect bitmap_rect(static_cast<int>(-xf.eDx), static_cast<int>(-xf.eDy), 855 gfx::Rect bitmap_rect(static_cast<int>(-xf.eDx), static_cast<int>(-xf.eDy),
855 bitmap.bmWidth, bitmap.bmHeight); 856 bitmap.bmWidth, bitmap.bmHeight);
856 gfx::Rect check_rect = rect.Intersect(bitmap_rect); 857 gfx::Rect check_rect = rect;
858 check_rect.Intersect(bitmap_rect);
857 int row_byte_size = check_rect.width() * (bitmap.bmBitsPixel / 8); 859 int row_byte_size = check_rect.width() * (bitmap.bmBitsPixel / 8);
858 for (int y = check_rect.y(); y < check_rect.bottom(); y++) { 860 for (int y = check_rect.y(); y < check_rect.bottom(); y++) {
859 char* hdc_row_start = static_cast<char*>(bitmap.bmBits) + 861 char* hdc_row_start = static_cast<char*>(bitmap.bmBits) +
860 (y + static_cast<int>(xf.eDy)) * bitmap.bmWidthBytes + 862 (y + static_cast<int>(xf.eDy)) * bitmap.bmWidthBytes +
861 (check_rect.x() + static_cast<int>(xf.eDx)) * (bitmap.bmBitsPixel / 8); 863 (check_rect.x() + static_cast<int>(xf.eDx)) * (bitmap.bmBitsPixel / 8);
862 864
863 // getAddr32 doesn't use the translation units, so we have to subtract 865 // getAddr32 doesn't use the translation units, so we have to subtract
864 // the plugin origin from the coordinates. 866 // the plugin origin from the coordinates.
865 uint32_t* canvas_row_start = 867 uint32_t* canvas_row_start =
866 background_store_.canvas->getDevice()->accessBitmap(true).getAddr32( 868 background_store_.canvas->getDevice()->accessBitmap(true).getAddr32(
(...skipping 24 matching lines...) Expand all
891 double page_x_double = 0; 893 double page_x_double = 0;
892 double page_y_double = 0; 894 double page_y_double = 0;
893 cairo_device_to_user(context, &page_x_double, &page_y_double); 895 cairo_device_to_user(context, &page_x_double, &page_y_double);
894 gfx::Rect full_content_rect(static_cast<int>(page_x_double), 896 gfx::Rect full_content_rect(static_cast<int>(page_x_double),
895 static_cast<int>(page_y_double), 897 static_cast<int>(page_y_double),
896 cairo_image_surface_get_width(page_surface), 898 cairo_image_surface_get_width(page_surface),
897 cairo_image_surface_get_height(page_surface)); 899 cairo_image_surface_get_height(page_surface));
898 #endif 900 #endif
899 // According to comments in the Windows code, the damage rect that we're given 901 // According to comments in the Windows code, the damage rect that we're given
900 // may project outside the image, so intersect their rects. 902 // may project outside the image, so intersect their rects.
901 gfx::Rect content_rect = rect.Intersect(full_content_rect); 903 gfx::Rect content_rect = rect;
904 content_rect.Intersect(full_content_rect);
902 905
903 #if defined(OS_MACOSX) 906 #if defined(OS_MACOSX)
904 const unsigned char* page_bytes = static_cast<const unsigned char*>( 907 const unsigned char* page_bytes = static_cast<const unsigned char*>(
905 CGBitmapContextGetData(context)); 908 CGBitmapContextGetData(context));
906 int page_stride = CGBitmapContextGetBytesPerRow(context); 909 int page_stride = CGBitmapContextGetBytesPerRow(context);
907 int page_start_x = content_rect.x() - context_offset_x; 910 int page_start_x = content_rect.x() - context_offset_x;
908 int page_start_y = content_rect.y() - context_offset_y; 911 int page_start_y = content_rect.y() - context_offset_y;
909 912
910 skia::ScopedPlatformPaint scoped_platform_paint( 913 skia::ScopedPlatformPaint scoped_platform_paint(
911 background_store_.canvas.get()); 914 background_store_.canvas.get());
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 if (plugin_) 1184 if (plugin_)
1182 plugin_->CancelResource(id); 1185 plugin_->CancelResource(id);
1183 } 1186 }
1184 1187
1185 void WebPluginDelegateProxy::OnInvalidateRect(const gfx::Rect& rect) { 1188 void WebPluginDelegateProxy::OnInvalidateRect(const gfx::Rect& rect) {
1186 if (!plugin_) 1189 if (!plugin_)
1187 return; 1190 return;
1188 1191
1189 // Clip the invalidation rect to the plugin bounds; the plugin may have been 1192 // Clip the invalidation rect to the plugin bounds; the plugin may have been
1190 // resized since the invalidate message was sent. 1193 // resized since the invalidate message was sent.
1191 const gfx::Rect clipped_rect(rect.Intersect(gfx::Rect(plugin_rect_.size()))); 1194 gfx::Rect clipped_rect = rect;
1195 clipped_rect.Intersect(gfx::Rect(plugin_rect_.size()));
1192 1196
1193 invalidate_pending_ = true; 1197 invalidate_pending_ = true;
1194 // The plugin is blocked on the renderer because the invalidate message it has 1198 // The plugin is blocked on the renderer because the invalidate message it has
1195 // sent us is synchronous, so we can use buffer flipping here if the caller 1199 // sent us is synchronous, so we can use buffer flipping here if the caller
1196 // allows it. 1200 // allows it.
1197 UpdateFrontBuffer(clipped_rect, true); 1201 UpdateFrontBuffer(clipped_rect, true);
1198 plugin_->InvalidateRect(clipped_rect); 1202 plugin_->InvalidateRect(clipped_rect);
1199 } 1203 }
1200 1204
1201 void WebPluginDelegateProxy::OnGetWindowScriptNPObject( 1205 void WebPluginDelegateProxy::OnGetWindowScriptNPObject(
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1302 // want to use buffer flipping at all since it would add extra locking. 1306 // want to use buffer flipping at all since it would add extra locking.
1303 // (Alternatively we could probably safely use async updates for buffer 1307 // (Alternatively we could probably safely use async updates for buffer
1304 // flipping all the time since the size is not changing.) 1308 // flipping all the time since the size is not changing.)
1305 if (UseSynchronousGeometryUpdates()) { 1309 if (UseSynchronousGeometryUpdates()) {
1306 allow_buffer_flipping = false; 1310 allow_buffer_flipping = false;
1307 } 1311 }
1308 #endif 1312 #endif
1309 1313
1310 // Plugin has just painted "rect" into the back-buffer, so the front-buffer 1314 // Plugin has just painted "rect" into the back-buffer, so the front-buffer
1311 // no longer holds the latest content for that rectangle. 1315 // no longer holds the latest content for that rectangle.
1312 front_buffer_diff_ = front_buffer_diff_.Subtract(rect); 1316 front_buffer_diff_.Subtract(rect);
1313 if (allow_buffer_flipping && front_buffer_diff_.IsEmpty()) { 1317 if (allow_buffer_flipping && front_buffer_diff_.IsEmpty()) {
1314 // Back-buffer contains the latest content for all areas; simply flip 1318 // Back-buffer contains the latest content for all areas; simply flip
1315 // the buffers. 1319 // the buffers.
1316 front_buffer_index_ = back_buffer_index(); 1320 front_buffer_index_ = back_buffer_index();
1317 SendUpdateGeometry(false); 1321 SendUpdateGeometry(false);
1318 // The front-buffer now holds newer content for this region than the 1322 // The front-buffer now holds newer content for this region than the
1319 // back-buffer. 1323 // back-buffer.
1320 front_buffer_diff_ = rect; 1324 front_buffer_diff_ = rect;
1321 } else { 1325 } else {
1322 // Back-buffer contains the latest content for "rect" but the front-buffer 1326 // Back-buffer contains the latest content for "rect" but the front-buffer
1323 // contains the latest content for some other areas (or buffer flipping not 1327 // contains the latest content for some other areas (or buffer flipping not
1324 // allowed); fall back to copying the data. 1328 // allowed); fall back to copying the data.
1325 CopyFromBackBufferToFrontBuffer(rect); 1329 CopyFromBackBufferToFrontBuffer(rect);
1326 } 1330 }
1327 transport_store_painted_ = transport_store_painted_.Union(rect); 1331 transport_store_painted_.Union(rect);
1328 } 1332 }
1329 1333
1330 void WebPluginDelegateProxy::OnHandleURLRequest( 1334 void WebPluginDelegateProxy::OnHandleURLRequest(
1331 const PluginHostMsg_URLRequest_Params& params) { 1335 const PluginHostMsg_URLRequest_Params& params) {
1332 const char* data = NULL; 1336 const char* data = NULL;
1333 if (params.buffer.size()) 1337 if (params.buffer.size())
1334 data = &params.buffer[0]; 1338 data = &params.buffer[0];
1335 1339
1336 const char* target = NULL; 1340 const char* target = NULL;
1337 if (params.target.length()) 1341 if (params.target.length())
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 1533
1530 void WebPluginDelegateProxy::OnURLRedirectResponse(bool allow, 1534 void WebPluginDelegateProxy::OnURLRedirectResponse(bool allow,
1531 int resource_id) { 1535 int resource_id) {
1532 if (!plugin_) 1536 if (!plugin_)
1533 return; 1537 return;
1534 1538
1535 plugin_->URLRedirectResponse(allow, resource_id); 1539 plugin_->URLRedirectResponse(allow, resource_id);
1536 } 1540 }
1537 1541
1538 } // namespace content 1542 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_widget.cc ('k') | ui/app_list/apps_grid_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698