| 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> |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include "app/gfx/canvas.h" | 13 #include "app/gfx/canvas.h" |
| 14 #include "app/l10n_util.h" | 14 #include "app/l10n_util.h" |
| 15 #include "app/resource_bundle.h" | 15 #include "app/resource_bundle.h" |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/ref_counted.h" | 18 #include "base/ref_counted.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "base/gfx/blit.h" |
| 20 #include "base/gfx/size.h" | 21 #include "base/gfx/size.h" |
| 21 #include "base/gfx/native_widget_types.h" | 22 #include "base/gfx/native_widget_types.h" |
| 22 #include "chrome/common/child_process_logging.h" | 23 #include "chrome/common/child_process_logging.h" |
| 23 #include "chrome/common/plugin_messages.h" | 24 #include "chrome/common/plugin_messages.h" |
| 24 #include "chrome/common/render_messages.h" | 25 #include "chrome/common/render_messages.h" |
| 25 #include "chrome/plugin/npobject_proxy.h" | 26 #include "chrome/plugin/npobject_proxy.h" |
| 26 #include "chrome/plugin/npobject_stub.h" | 27 #include "chrome/plugin/npobject_stub.h" |
| 27 #include "chrome/plugin/npobject_util.h" | 28 #include "chrome/plugin/npobject_util.h" |
| 28 #include "chrome/renderer/render_thread.h" | 29 #include "chrome/renderer/render_thread.h" |
| 29 #include "chrome/renderer/render_view.h" | 30 #include "chrome/renderer/render_view.h" |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 | 517 |
| 517 // Limit the damaged rectangle to whatever is contained inside the plugin | 518 // Limit the damaged rectangle to whatever is contained inside the plugin |
| 518 // rectangle, as that's the rectangle that we'll bitblt to the hdc. | 519 // rectangle, as that's the rectangle that we'll bitblt to the hdc. |
| 519 gfx::Rect rect = damaged_rect.Intersect(plugin_rect_); | 520 gfx::Rect rect = damaged_rect.Intersect(plugin_rect_); |
| 520 gfx::Rect offset_rect = rect; | 521 gfx::Rect offset_rect = rect; |
| 521 offset_rect.Offset(-plugin_rect_.x(), -plugin_rect_.y()); | 522 offset_rect.Offset(-plugin_rect_.x(), -plugin_rect_.y()); |
| 522 | 523 |
| 523 bool background_changed = false; | 524 bool background_changed = false; |
| 524 if (background_store_canvas_.get() && BackgroundChanged(context, rect)) { | 525 if (background_store_canvas_.get() && BackgroundChanged(context, rect)) { |
| 525 background_changed = true; | 526 background_changed = true; |
| 526 #if defined(OS_WIN) | 527 BlitContextToCanvas(background_store_canvas_.get(), offset_rect, |
| 527 HDC background_hdc = | 528 context, rect.origin()); |
| 528 background_store_canvas_->getTopPlatformDevice().getBitmapDC(); | |
| 529 BitBlt(background_hdc, offset_rect.x(), offset_rect.y(), | |
| 530 rect.width(), rect.height(), context, rect.x(), rect.y(), SRCCOPY); | |
| 531 #elif defined(OS_MACOSX) | |
| 532 CGContextRef background_context = | |
| 533 background_store_canvas_->getTopPlatformDevice().GetBitmapContext(); | |
| 534 scoped_cftyperef<CGImageRef> | |
| 535 background_image(CGBitmapContextCreateImage(background_context)); | |
| 536 scoped_cftyperef<CGImageRef> sub_image( | |
| 537 CGImageCreateWithImageInRect(background_image, offset_rect.ToCGRect())); | |
| 538 CGContextDrawImage(context, rect.ToCGRect(), sub_image); | |
| 539 #else | |
| 540 cairo_t *cairo = | |
| 541 background_store_canvas_->getTopPlatformDevice().beginPlatformPaint(); | |
| 542 cairo_save(cairo); | |
| 543 double surface_x = plugin_rect_.x(); | |
| 544 double surface_y = plugin_rect_.y(); | |
| 545 cairo_user_to_device(context, &surface_x, &surface_y); | |
| 546 cairo_set_source_surface(cairo, cairo_get_target(context), | |
| 547 -surface_x, -surface_y); | |
| 548 cairo_rectangle(cairo, offset_rect.x(), offset_rect.y(), | |
| 549 offset_rect.width(), offset_rect.height()); | |
| 550 cairo_clip(cairo); | |
| 551 cairo_paint(cairo); | |
| 552 cairo_restore(cairo); | |
| 553 #endif | |
| 554 } | 529 } |
| 555 | 530 |
| 556 if (background_changed || !backing_store_painted_.Contains(offset_rect)) { | 531 if (background_changed || !backing_store_painted_.Contains(offset_rect)) { |
| 557 Send(new PluginMsg_Paint(instance_id_, offset_rect)); | 532 Send(new PluginMsg_Paint(instance_id_, offset_rect)); |
| 558 CopyFromTransportToBacking(offset_rect); | 533 CopyFromTransportToBacking(offset_rect); |
| 559 } | 534 } |
| 560 | 535 |
| 561 #if defined(OS_WIN) | 536 BlitCanvasToContext(context, rect, backing_store_canvas_.get(), |
| 562 HDC backing_hdc = backing_store_canvas_->getTopPlatformDevice().getBitmapDC(); | 537 offset_rect.origin()); |
| 563 BitBlt(context, rect.x(), rect.y(), rect.width(), rect.height(), backing_hdc, | |
| 564 offset_rect.x(), offset_rect.y(), SRCCOPY); | |
| 565 #elif defined(OS_MACOSX) | |
| 566 CGContextRef backing_context = | |
| 567 backing_store_canvas_->getTopPlatformDevice().GetBitmapContext(); | |
| 568 scoped_cftyperef<CGImageRef> | |
| 569 backing_image(CGBitmapContextCreateImage(backing_context)); | |
| 570 scoped_cftyperef<CGImageRef> sub_image( | |
| 571 CGImageCreateWithImageInRect(backing_image, offset_rect.ToCGRect())); | |
| 572 CGContextDrawImage(context, rect.ToCGRect(), sub_image); | |
| 573 #else | |
| 574 cairo_save(context); | |
| 575 cairo_t *cairo = | |
| 576 backing_store_canvas_->getTopPlatformDevice().beginPlatformPaint(); | |
| 577 cairo_set_source_surface(context, cairo_get_target(cairo), | |
| 578 plugin_rect_.x(), plugin_rect_.y()); | |
| 579 cairo_rectangle(context, rect.x(), rect.y(), rect.width(), rect.height()); | |
| 580 cairo_paint(context); | |
| 581 cairo_clip(context); | |
| 582 cairo_restore(context); | |
| 583 #endif | |
| 584 | 538 |
| 585 if (invalidate_pending_) { | 539 if (invalidate_pending_) { |
| 586 // Only send the PaintAck message if this paint is in response to an | 540 // Only send the PaintAck message if this paint is in response to an |
| 587 // invalidate from the plugin, since this message acts as an access token | 541 // invalidate from the plugin, since this message acts as an access token |
| 588 // to ensure only one process is using the transport dib at a time. | 542 // to ensure only one process is using the transport dib at a time. |
| 589 invalidate_pending_ = false; | 543 invalidate_pending_ = false; |
| 590 Send(new PluginMsg_DidPaint(instance_id_)); | 544 Send(new PluginMsg_DidPaint(instance_id_)); |
| 591 } | 545 } |
| 592 } | 546 } |
| 593 | 547 |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 if (!sad_plugin_) { | 888 if (!sad_plugin_) { |
| 935 sad_plugin_ = ResourceBundle::GetSharedInstance().GetBitmapNamed( | 889 sad_plugin_ = ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 936 IDR_SAD_PLUGIN); | 890 IDR_SAD_PLUGIN); |
| 937 } | 891 } |
| 938 | 892 |
| 939 if (sad_plugin_) { | 893 if (sad_plugin_) { |
| 940 canvas.DrawBitmapInt(*sad_plugin_, | 894 canvas.DrawBitmapInt(*sad_plugin_, |
| 941 std::max(0, (width - sad_plugin_->width())/2), | 895 std::max(0, (width - sad_plugin_->width())/2), |
| 942 std::max(0, (height - sad_plugin_->height())/2)); | 896 std::max(0, (height - sad_plugin_->height())/2)); |
| 943 } | 897 } |
| 944 | 898 BlitCanvasToContext(context, plugin_rect_, &canvas, gfx::Point(0, 0)); |
| 945 #if defined(OS_WIN) | |
| 946 skia::PlatformDevice& device = canvas.getTopPlatformDevice(); | |
| 947 device.drawToHDC(context, plugin_rect_.x(), plugin_rect_.y(), NULL); | |
| 948 #elif defined(OS_LINUX) | |
| 949 cairo_save(context); | |
| 950 cairo_t* cairo = canvas.getTopPlatformDevice().beginPlatformPaint(); | |
| 951 cairo_set_source_surface(context, cairo_get_target(cairo), | |
| 952 plugin_rect_.x(), plugin_rect_.y()); | |
| 953 cairo_rectangle(context, rect.x(), rect.y(), rect.width(), rect.height()); | |
| 954 cairo_clip(context); | |
| 955 cairo_paint(context); | |
| 956 cairo_restore(context); | |
| 957 // We have no endPlatformPaint() on the Linux PlatformDevice. | |
| 958 // The cairo_t* is owned by the device. | |
| 959 #elif defined(OS_MACOSX) | |
| 960 canvas.getTopPlatformDevice().DrawToContext( | |
| 961 context, plugin_rect_.x(), plugin_rect_.y(), NULL); | |
| 962 #else | |
| 963 NOTIMPLEMENTED(); | |
| 964 #endif | |
| 965 } | 899 } |
| 966 | 900 |
| 967 void WebPluginDelegateProxy::CopyFromTransportToBacking(const gfx::Rect& rect) { | 901 void WebPluginDelegateProxy::CopyFromTransportToBacking(const gfx::Rect& rect) { |
| 968 if (!backing_store_canvas_.get()) { | 902 if (!backing_store_canvas_.get()) { |
| 969 return; | 903 return; |
| 970 } | 904 } |
| 971 | 905 |
| 972 // Copy the damaged rect from the transport bitmap to the backing store. | 906 // Copy the damaged rect from the transport bitmap to the backing store. |
| 973 #if defined(OS_WIN) | 907 BlitCanvasToCanvas(backing_store_canvas_.get(), rect, |
| 974 HDC backing = backing_store_canvas_->getTopPlatformDevice().getBitmapDC(); | 908 transport_store_canvas_.get(), rect.origin()); |
| 975 HDC transport = transport_store_canvas_->getTopPlatformDevice().getBitmapDC(); | |
| 976 BitBlt(backing, rect.x(), rect.y(), rect.width(), rect.height(), | |
| 977 transport, rect.x(), rect.y(), SRCCOPY); | |
| 978 #elif defined(OS_MACOSX) | |
| 979 gfx::NativeDrawingContext backing = | |
| 980 backing_store_canvas_->getTopPlatformDevice().GetBitmapContext(); | |
| 981 gfx::NativeDrawingContext transport = | |
| 982 transport_store_canvas_->getTopPlatformDevice().GetBitmapContext(); | |
| 983 scoped_cftyperef<CGImageRef> image(CGBitmapContextCreateImage(transport)); | |
| 984 scoped_cftyperef<CGImageRef> sub_image( | |
| 985 CGImageCreateWithImageInRect(image, rect.ToCGRect())); | |
| 986 CGContextDrawImage(backing, rect.ToCGRect(), sub_image); | |
| 987 #else | |
| 988 cairo_t *cairo = | |
| 989 backing_store_canvas_->getTopPlatformDevice().beginPlatformPaint(); | |
| 990 cairo_save(cairo); | |
| 991 cairo_t *transport = | |
| 992 transport_store_canvas_->getTopPlatformDevice().beginPlatformPaint(); | |
| 993 cairo_set_source_surface(cairo, cairo_get_target(transport), 0, 0); | |
| 994 cairo_rectangle(cairo, rect.x(), rect.y(), rect.width(), rect.height()); | |
| 995 cairo_clip(cairo); | |
| 996 cairo_paint(cairo); | |
| 997 cairo_restore(cairo); | |
| 998 #endif | |
| 999 backing_store_painted_ = backing_store_painted_.Union(rect); | 909 backing_store_painted_ = backing_store_painted_.Union(rect); |
| 1000 } | 910 } |
| 1001 | 911 |
| 1002 void WebPluginDelegateProxy::OnHandleURLRequest( | 912 void WebPluginDelegateProxy::OnHandleURLRequest( |
| 1003 const PluginHostMsg_URLRequest_Params& params) { | 913 const PluginHostMsg_URLRequest_Params& params) { |
| 1004 const char* data = NULL; | 914 const char* data = NULL; |
| 1005 if (params.buffer.size()) | 915 if (params.buffer.size()) |
| 1006 data = ¶ms.buffer[0]; | 916 data = ¶ms.buffer[0]; |
| 1007 | 917 |
| 1008 const char* target = NULL; | 918 const char* target = NULL; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1037 plugin_->CancelDocumentLoad(); | 947 plugin_->CancelDocumentLoad(); |
| 1038 } | 948 } |
| 1039 | 949 |
| 1040 void WebPluginDelegateProxy::OnInitiateHTTPRangeRequest( | 950 void WebPluginDelegateProxy::OnInitiateHTTPRangeRequest( |
| 1041 const std::string& url, const std::string& range_info, | 951 const std::string& url, const std::string& range_info, |
| 1042 intptr_t existing_stream, bool notify_needed, intptr_t notify_data) { | 952 intptr_t existing_stream, bool notify_needed, intptr_t notify_data) { |
| 1043 plugin_->InitiateHTTPRangeRequest(url.c_str(), range_info.c_str(), | 953 plugin_->InitiateHTTPRangeRequest(url.c_str(), range_info.c_str(), |
| 1044 existing_stream, notify_needed, | 954 existing_stream, notify_needed, |
| 1045 notify_data); | 955 notify_data); |
| 1046 } | 956 } |
| OLD | NEW |