| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/renderer/webplugin_delegate_proxy.h" | 5 #include "chrome/renderer/webplugin_delegate_proxy.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <atlbase.h> | 10 #include <atlbase.h> |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 if (invalidate_pending_) { | 568 if (invalidate_pending_) { |
| 569 // Only send the PaintAck message if this paint is in response to an | 569 // Only send the PaintAck message if this paint is in response to an |
| 570 // invalidate from the plugin, since this message acts as an access token | 570 // invalidate from the plugin, since this message acts as an access token |
| 571 // to ensure only one process is using the transport dib at a time. | 571 // to ensure only one process is using the transport dib at a time. |
| 572 invalidate_pending_ = false; | 572 invalidate_pending_ = false; |
| 573 Send(new PluginMsg_DidPaint(instance_id_)); | 573 Send(new PluginMsg_DidPaint(instance_id_)); |
| 574 } | 574 } |
| 575 } | 575 } |
| 576 | 576 |
| 577 bool WebPluginDelegateProxy::BackgroundChanged( | 577 bool WebPluginDelegateProxy::BackgroundChanged( |
| 578 gfx::NativeDrawingContext hdc, | 578 gfx::NativeDrawingContext context, |
| 579 const gfx::Rect& rect) { | 579 const gfx::Rect& rect) { |
| 580 #if defined(OS_WIN) | 580 #if defined(OS_WIN) |
| 581 HBITMAP hbitmap = static_cast<HBITMAP>(GetCurrentObject(hdc, OBJ_BITMAP)); | 581 HBITMAP hbitmap = static_cast<HBITMAP>(GetCurrentObject(context, OBJ_BITMAP)); |
| 582 if (hbitmap == NULL) { | 582 if (hbitmap == NULL) { |
| 583 NOTREACHED(); | 583 NOTREACHED(); |
| 584 return true; | 584 return true; |
| 585 } | 585 } |
| 586 | 586 |
| 587 BITMAP bitmap = { 0 }; | 587 BITMAP bitmap = { 0 }; |
| 588 int result = GetObject(hbitmap, sizeof(bitmap), &bitmap); | 588 int result = GetObject(hbitmap, sizeof(bitmap), &bitmap); |
| 589 if (!result) { | 589 if (!result) { |
| 590 NOTREACHED(); | 590 NOTREACHED(); |
| 591 return true; | 591 return true; |
| 592 } | 592 } |
| 593 | 593 |
| 594 XFORM xf; | 594 XFORM xf; |
| 595 if (!GetWorldTransform(hdc, &xf)) { | 595 if (!GetWorldTransform(context, &xf)) { |
| 596 NOTREACHED(); | 596 NOTREACHED(); |
| 597 return true; | 597 return true; |
| 598 } | 598 } |
| 599 | 599 |
| 600 // The damaged rect that we're given can be larger than the bitmap, so | 600 // The damaged rect that we're given can be larger than the bitmap, so |
| 601 // intersect their rects first. | 601 // intersect their rects first. |
| 602 gfx::Rect bitmap_rect(static_cast<int>(-xf.eDx), static_cast<int>(-xf.eDy), | 602 gfx::Rect bitmap_rect(static_cast<int>(-xf.eDx), static_cast<int>(-xf.eDy), |
| 603 bitmap.bmWidth, bitmap.bmHeight); | 603 bitmap.bmWidth, bitmap.bmHeight); |
| 604 gfx::Rect check_rect = rect.Intersect(bitmap_rect); | 604 gfx::Rect check_rect = rect.Intersect(bitmap_rect); |
| 605 int row_byte_size = check_rect.width() * (bitmap.bmBitsPixel / 8); | 605 int row_byte_size = check_rect.width() * (bitmap.bmBitsPixel / 8); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 619 return false; | 619 return false; |
| 620 #elif defined(OS_MACOSX) | 620 #elif defined(OS_MACOSX) |
| 621 // Needs implementation; see http://crbug.com/18193 | 621 // Needs implementation; see http://crbug.com/18193 |
| 622 // Implementation note: |rect| is in content-area-relative coordinates, | 622 // Implementation note: |rect| is in content-area-relative coordinates, |
| 623 // but we may be given a context that is a subset of the content area | 623 // but we may be given a context that is a subset of the content area |
| 624 // with a transform that makes the coordinates work out. We will likely | 624 // with a transform that makes the coordinates work out. We will likely |
| 625 // need to do fixup work like that done in BlitContextToContext when we | 625 // need to do fixup work like that done in BlitContextToContext when we |
| 626 // implement this. | 626 // implement this. |
| 627 return true; | 627 return true; |
| 628 #else | 628 #else |
| 629 NOTIMPLEMENTED(); | 629 cairo_surface_t* page_surface = cairo_get_target(context); |
| 630 return true; | 630 DCHECK_EQ(cairo_surface_get_type(page_surface), CAIRO_SURFACE_TYPE_IMAGE); |
| 631 DCHECK_EQ(cairo_image_surface_get_format(page_surface), CAIRO_FORMAT_ARGB32); |
| 632 |
| 633 const unsigned char* page_bytes = cairo_image_surface_get_data(page_surface); |
| 634 int page_stride = cairo_image_surface_get_stride(page_surface); |
| 635 |
| 636 // Transform context coordinates into surface coordinates. |
| 637 double page_x_double = rect.x(); |
| 638 double page_y_double = rect.y(); |
| 639 cairo_user_to_device(context, &page_x_double, &page_y_double); |
| 640 int page_x = page_x_double; |
| 641 int page_y = page_y_double; |
| 642 |
| 643 // Following comments from the Windows section, apparently the damage rect |
| 644 // can be larger than the image surface. |
| 645 int width = std::min(cairo_image_surface_get_width(page_surface), |
| 646 rect.width()); |
| 647 int height = std::min(cairo_image_surface_get_height(page_surface), |
| 648 rect.height()); |
| 649 |
| 650 skia::PlatformDevice& device = |
| 651 background_store_canvas_->getTopPlatformDevice(); |
| 652 cairo_surface_t* bg_surface = cairo_get_target(device.beginPlatformPaint()); |
| 653 DCHECK_EQ(cairo_surface_get_type(bg_surface), CAIRO_SURFACE_TYPE_IMAGE); |
| 654 DCHECK_EQ(cairo_image_surface_get_format(bg_surface), CAIRO_FORMAT_ARGB32); |
| 655 |
| 656 const unsigned char* bg_bytes = cairo_image_surface_get_data(bg_surface); |
| 657 int bg_stride = cairo_image_surface_get_stride(bg_surface); |
| 658 int bg_x = rect.x() - plugin_rect_.x(); |
| 659 int bg_y = rect.y() - plugin_rect_.y(); |
| 660 |
| 661 // rect is supposed to have been intersected with the plugin rect. |
| 662 DCHECK_LE(width, cairo_image_surface_get_width(bg_surface)); |
| 663 DCHECK_LE(height, cairo_image_surface_get_height(bg_surface)); |
| 664 |
| 665 static const int kBPP = 4; // ARGB32 = 4 bytes per pixel. |
| 666 |
| 667 for (int y = 0; y < height; ++y) { |
| 668 int page_offset = page_x * kBPP + page_stride * (page_y + y); |
| 669 int bg_offset = bg_x * kBPP + bg_stride * (bg_y + y); |
| 670 if (memcmp(page_bytes + page_offset, |
| 671 bg_bytes + bg_offset, |
| 672 width * kBPP) != 0) |
| 673 return true; |
| 674 } |
| 675 |
| 676 return false; |
| 631 #endif | 677 #endif |
| 632 } | 678 } |
| 633 | 679 |
| 634 void WebPluginDelegateProxy::Print(gfx::NativeDrawingContext context) { | 680 void WebPluginDelegateProxy::Print(gfx::NativeDrawingContext context) { |
| 635 base::SharedMemoryHandle shared_memory; | 681 base::SharedMemoryHandle shared_memory; |
| 636 size_t size; | 682 size_t size; |
| 637 if (!Send(new PluginMsg_Print(instance_id_, &shared_memory, &size))) | 683 if (!Send(new PluginMsg_Print(instance_id_, &shared_memory, &size))) |
| 638 return; | 684 return; |
| 639 | 685 |
| 640 base::SharedMemory memory(shared_memory, true); | 686 base::SharedMemory memory(shared_memory, true); |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 intptr_t existing_stream, bool notify_needed, intptr_t notify_data) { | 1045 intptr_t existing_stream, bool notify_needed, intptr_t notify_data) { |
| 1000 plugin_->InitiateHTTPRangeRequest(url.c_str(), range_info.c_str(), | 1046 plugin_->InitiateHTTPRangeRequest(url.c_str(), range_info.c_str(), |
| 1001 existing_stream, notify_needed, | 1047 existing_stream, notify_needed, |
| 1002 notify_data); | 1048 notify_data); |
| 1003 } | 1049 } |
| 1004 | 1050 |
| 1005 void WebPluginDelegateProxy::OnDeferResourceLoading(int resource_id, | 1051 void WebPluginDelegateProxy::OnDeferResourceLoading(int resource_id, |
| 1006 bool defer) { | 1052 bool defer) { |
| 1007 plugin_->SetDeferResourceLoading(resource_id, defer); | 1053 plugin_->SetDeferResourceLoading(resource_id, defer); |
| 1008 } | 1054 } |
| OLD | NEW |