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

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

Issue 159128: linux: add windowless plugin plumbing (Closed)
Patch Set: address review comments Created 11 years, 5 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 | « chrome/plugin/webplugin_proxy.cc ('k') | webkit/glue/plugins/plugin_host.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) 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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 } 469 }
470 470
471 bool WebPluginDelegateProxy::CreateBitmap( 471 bool WebPluginDelegateProxy::CreateBitmap(
472 scoped_ptr<TransportDIB>* memory, 472 scoped_ptr<TransportDIB>* memory,
473 scoped_ptr<skia::PlatformCanvas>* canvas) { 473 scoped_ptr<skia::PlatformCanvas>* canvas) {
474 int width = plugin_rect_.width(); 474 int width = plugin_rect_.width();
475 int height = plugin_rect_.height(); 475 int height = plugin_rect_.height();
476 const size_t stride = skia::PlatformCanvas::StrideForWidth(width); 476 const size_t stride = skia::PlatformCanvas::StrideForWidth(width);
477 const size_t size = stride * height; 477 const size_t size = stride * height;
478 #if defined(OS_LINUX) 478 #if defined(OS_LINUX)
479 static unsigned long max_size = 0; 479 memory->reset(TransportDIB::Create(size, 0));
480 if (max_size == 0) { 480 if (!memory->get())
481 std::string contents;
482 file_util::ReadFileToString(FilePath("/proc/sys/kernel/shmmax"), &contents);
483 max_size = strtoul(contents.c_str(), NULL, 0);
484 }
485 if (size > max_size)
486 return false; 481 return false;
487 #endif 482 #endif
488 #if defined(OS_MACOSX) 483 #if defined(OS_MACOSX)
489 TransportDIB::Handle handle; 484 TransportDIB::Handle handle;
490 IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(size, &handle); 485 IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(size, &handle);
491 if (!RenderThread::current()->Send(msg)) 486 if (!RenderThread::current()->Send(msg))
492 return false; 487 return false;
493 if (handle.fd < 0) 488 if (handle.fd < 0)
494 return false; 489 return false;
495 memory->reset(TransportDIB::Map(handle)); 490 memory->reset(TransportDIB::Map(handle));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 rect.width(), rect.height(), context, rect.x(), rect.y(), SRCCOPY); 531 rect.width(), rect.height(), context, rect.x(), rect.y(), SRCCOPY);
537 #elif defined(OS_MACOSX) 532 #elif defined(OS_MACOSX)
538 CGContextRef background_context = 533 CGContextRef background_context =
539 background_store_canvas_->getTopPlatformDevice().GetBitmapContext(); 534 background_store_canvas_->getTopPlatformDevice().GetBitmapContext();
540 scoped_cftyperef<CGImageRef> 535 scoped_cftyperef<CGImageRef>
541 background_image(CGBitmapContextCreateImage(background_context)); 536 background_image(CGBitmapContextCreateImage(background_context));
542 scoped_cftyperef<CGImageRef> sub_image( 537 scoped_cftyperef<CGImageRef> sub_image(
543 CGImageCreateWithImageInRect(background_image, offset_rect.ToCGRect())); 538 CGImageCreateWithImageInRect(background_image, offset_rect.ToCGRect()));
544 CGContextDrawImage(context, rect.ToCGRect(), sub_image); 539 CGContextDrawImage(context, rect.ToCGRect(), sub_image);
545 #else 540 #else
546 NOTIMPLEMENTED(); 541 cairo_t *cairo =
542 background_store_canvas_->getTopPlatformDevice().beginPlatformPaint();
543 cairo_save(cairo);
544 double surface_x = plugin_rect_.x();
545 double surface_y = plugin_rect_.y();
546 cairo_user_to_device(context, &surface_x, &surface_y);
547 cairo_set_source_surface(cairo, cairo_get_target(context),
548 -surface_x, -surface_y);
549 cairo_rectangle(cairo, offset_rect.x(), offset_rect.y(),
550 offset_rect.width(), offset_rect.height());
551 cairo_clip(cairo);
552 cairo_paint(cairo);
553 cairo_restore(cairo);
547 #endif 554 #endif
548 } 555 }
549 556
550 if (background_changed || !backing_store_painted_.Contains(offset_rect)) { 557 if (background_changed || !backing_store_painted_.Contains(offset_rect)) {
551 Send(new PluginMsg_Paint(instance_id_, offset_rect)); 558 Send(new PluginMsg_Paint(instance_id_, offset_rect));
552 CopyFromTransportToBacking(offset_rect); 559 CopyFromTransportToBacking(offset_rect);
553 } 560 }
554 561
555 #if defined(OS_WIN) 562 #if defined(OS_WIN)
556 HDC backing_hdc = backing_store_canvas_->getTopPlatformDevice().getBitmapDC(); 563 HDC backing_hdc = backing_store_canvas_->getTopPlatformDevice().getBitmapDC();
557 BitBlt(context, rect.x(), rect.y(), rect.width(), rect.height(), backing_hdc, 564 BitBlt(context, rect.x(), rect.y(), rect.width(), rect.height(), backing_hdc,
558 offset_rect.x(), offset_rect.y(), SRCCOPY); 565 offset_rect.x(), offset_rect.y(), SRCCOPY);
559 #elif defined(OS_MACOSX) 566 #elif defined(OS_MACOSX)
560 CGContextRef backing_context = 567 CGContextRef backing_context =
561 backing_store_canvas_->getTopPlatformDevice().GetBitmapContext(); 568 backing_store_canvas_->getTopPlatformDevice().GetBitmapContext();
562 scoped_cftyperef<CGImageRef> 569 scoped_cftyperef<CGImageRef>
563 backing_image(CGBitmapContextCreateImage(backing_context)); 570 backing_image(CGBitmapContextCreateImage(backing_context));
564 scoped_cftyperef<CGImageRef> sub_image( 571 scoped_cftyperef<CGImageRef> sub_image(
565 CGImageCreateWithImageInRect(backing_image, offset_rect.ToCGRect())); 572 CGImageCreateWithImageInRect(backing_image, offset_rect.ToCGRect()));
566 CGContextDrawImage(context, rect.ToCGRect(), sub_image); 573 CGContextDrawImage(context, rect.ToCGRect(), sub_image);
567 #else 574 #else
568 NOTIMPLEMENTED(); 575 cairo_save(context);
576 cairo_t *cairo =
577 backing_store_canvas_->getTopPlatformDevice().beginPlatformPaint();
578 cairo_set_source_surface(context, cairo_get_target(cairo),
579 plugin_rect_.x(), plugin_rect_.y());
580 cairo_rectangle(context, rect.x(), rect.y(), rect.width(), rect.height());
581 cairo_paint(context);
582 cairo_clip(context);
583 cairo_restore(context);
569 #endif 584 #endif
570 585
571 if (invalidate_pending_) { 586 if (invalidate_pending_) {
572 // Only send the PaintAck message if this paint is in response to an 587 // Only send the PaintAck message if this paint is in response to an
573 // invalidate from the plugin, since this message acts as an access token 588 // invalidate from the plugin, since this message acts as an access token
574 // to ensure only one process is using the transport dib at a time. 589 // to ensure only one process is using the transport dib at a time.
575 invalidate_pending_ = false; 590 invalidate_pending_ = false;
576 Send(new PluginMsg_DidPaint(instance_id_)); 591 Send(new PluginMsg_DidPaint(instance_id_));
577 } 592 }
578 } 593 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 (check_rect.x() + static_cast<int>(xf.eDx)) * (bitmap.bmBitsPixel / 8); 627 (check_rect.x() + static_cast<int>(xf.eDx)) * (bitmap.bmBitsPixel / 8);
613 628
614 // getAddr32 doesn't use the translation units, so we have to subtract 629 // getAddr32 doesn't use the translation units, so we have to subtract
615 // the plugin origin from the coordinates. 630 // the plugin origin from the coordinates.
616 uint32_t* canvas_row_start = 631 uint32_t* canvas_row_start =
617 background_store_canvas_->getDevice()->accessBitmap(true).getAddr32( 632 background_store_canvas_->getDevice()->accessBitmap(true).getAddr32(
618 check_rect.x() - plugin_rect_.x(), y - plugin_rect_.y()); 633 check_rect.x() - plugin_rect_.x(), y - plugin_rect_.y());
619 if (memcmp(hdc_row_start, canvas_row_start, row_byte_size) != 0) 634 if (memcmp(hdc_row_start, canvas_row_start, row_byte_size) != 0)
620 return true; 635 return true;
621 } 636 }
622 637 return false;
623 #else 638 #else
624 NOTIMPLEMENTED(); 639 NOTIMPLEMENTED();
640 return true;
625 #endif 641 #endif
626 return false;
627 } 642 }
628 643
629 void WebPluginDelegateProxy::Print(gfx::NativeDrawingContext context) { 644 void WebPluginDelegateProxy::Print(gfx::NativeDrawingContext context) {
630 base::SharedMemoryHandle shared_memory; 645 base::SharedMemoryHandle shared_memory;
631 size_t size; 646 size_t size;
632 if (!Send(new PluginMsg_Print(instance_id_, &shared_memory, &size))) 647 if (!Send(new PluginMsg_Print(instance_id_, &shared_memory, &size)))
633 return; 648 return;
634 649
635 base::SharedMemory memory(shared_memory, true); 650 base::SharedMemory memory(shared_memory, true);
636 if (!memory.Map(size)) { 651 if (!memory.Map(size)) {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 if (sad_plugin_) { 940 if (sad_plugin_) {
926 canvas.DrawBitmapInt(*sad_plugin_, 941 canvas.DrawBitmapInt(*sad_plugin_,
927 std::max(0, (width - sad_plugin_->width())/2), 942 std::max(0, (width - sad_plugin_->width())/2),
928 std::max(0, (height - sad_plugin_->height())/2)); 943 std::max(0, (height - sad_plugin_->height())/2));
929 } 944 }
930 945
931 #if defined(OS_WIN) 946 #if defined(OS_WIN)
932 skia::PlatformDevice& device = canvas.getTopPlatformDevice(); 947 skia::PlatformDevice& device = canvas.getTopPlatformDevice();
933 device.drawToHDC(context, plugin_rect_.x(), plugin_rect_.y(), NULL); 948 device.drawToHDC(context, plugin_rect_.x(), plugin_rect_.y(), NULL);
934 #elif defined(OS_LINUX) 949 #elif defined(OS_LINUX)
950 cairo_save(context);
935 cairo_t* cairo = canvas.getTopPlatformDevice().beginPlatformPaint(); 951 cairo_t* cairo = canvas.getTopPlatformDevice().beginPlatformPaint();
936 cairo_set_source_surface(cairo, cairo_get_target(context), 952 cairo_set_source_surface(context, cairo_get_target(cairo),
937 plugin_rect_.x(), plugin_rect_.y()); 953 plugin_rect_.x(), plugin_rect_.y());
938 cairo_paint(cairo); 954 cairo_rectangle(context, rect.x(), rect.y(), rect.width(), rect.height());
955 cairo_clip(context);
956 cairo_paint(context);
957 cairo_restore(context);
939 // We have no endPlatformPaint() on the Linux PlatformDevice. 958 // We have no endPlatformPaint() on the Linux PlatformDevice.
940 // The cairo_t* is owned by the device. 959 // The cairo_t* is owned by the device.
941 #elif defined(OS_MACOSX) 960 #elif defined(OS_MACOSX)
942 canvas.getTopPlatformDevice().DrawToContext( 961 canvas.getTopPlatformDevice().DrawToContext(
943 context, plugin_rect_.x(), plugin_rect_.y(), NULL); 962 context, plugin_rect_.x(), plugin_rect_.y(), NULL);
944 #else 963 #else
945 NOTIMPLEMENTED(); 964 NOTIMPLEMENTED();
946 #endif 965 #endif
947 } 966 }
948 967
(...skipping 11 matching lines...) Expand all
960 #elif defined(OS_MACOSX) 979 #elif defined(OS_MACOSX)
961 gfx::NativeDrawingContext backing = 980 gfx::NativeDrawingContext backing =
962 backing_store_canvas_->getTopPlatformDevice().GetBitmapContext(); 981 backing_store_canvas_->getTopPlatformDevice().GetBitmapContext();
963 gfx::NativeDrawingContext transport = 982 gfx::NativeDrawingContext transport =
964 transport_store_canvas_->getTopPlatformDevice().GetBitmapContext(); 983 transport_store_canvas_->getTopPlatformDevice().GetBitmapContext();
965 scoped_cftyperef<CGImageRef> image(CGBitmapContextCreateImage(transport)); 984 scoped_cftyperef<CGImageRef> image(CGBitmapContextCreateImage(transport));
966 scoped_cftyperef<CGImageRef> sub_image( 985 scoped_cftyperef<CGImageRef> sub_image(
967 CGImageCreateWithImageInRect(image, rect.ToCGRect())); 986 CGImageCreateWithImageInRect(image, rect.ToCGRect()));
968 CGContextDrawImage(backing, rect.ToCGRect(), sub_image); 987 CGContextDrawImage(backing, rect.ToCGRect(), sub_image);
969 #else 988 #else
970 // TODO(port): probably some new code in TransportDIB should go here. 989 cairo_t *cairo =
971 NOTIMPLEMENTED(); 990 backing_store_canvas_->getTopPlatformDevice().beginPlatformPaint();
991 cairo_save(cairo);
992 cairo_t *transport =
993 transport_store_canvas_->getTopPlatformDevice().beginPlatformPaint();
994 cairo_set_source_surface(cairo, cairo_get_target(transport), 0, 0);
995 cairo_rectangle(cairo, rect.x(), rect.y(), rect.width(), rect.height());
996 cairo_clip(cairo);
997 cairo_paint(cairo);
998 cairo_restore(cairo);
972 #endif 999 #endif
973 backing_store_painted_ = backing_store_painted_.Union(rect); 1000 backing_store_painted_ = backing_store_painted_.Union(rect);
974 } 1001 }
975 1002
976 void WebPluginDelegateProxy::OnHandleURLRequest( 1003 void WebPluginDelegateProxy::OnHandleURLRequest(
977 const PluginHostMsg_URLRequest_Params& params) { 1004 const PluginHostMsg_URLRequest_Params& params) {
978 const char* data = NULL; 1005 const char* data = NULL;
979 if (params.buffer.size()) 1006 if (params.buffer.size())
980 data = &params.buffer[0]; 1007 data = &params.buffer[0];
981 1008
(...skipping 29 matching lines...) Expand all
1011 plugin_->CancelDocumentLoad(); 1038 plugin_->CancelDocumentLoad();
1012 } 1039 }
1013 1040
1014 void WebPluginDelegateProxy::OnInitiateHTTPRangeRequest( 1041 void WebPluginDelegateProxy::OnInitiateHTTPRangeRequest(
1015 const std::string& url, const std::string& range_info, 1042 const std::string& url, const std::string& range_info,
1016 intptr_t existing_stream, bool notify_needed, intptr_t notify_data) { 1043 intptr_t existing_stream, bool notify_needed, intptr_t notify_data) {
1017 plugin_->InitiateHTTPRangeRequest(url.c_str(), range_info.c_str(), 1044 plugin_->InitiateHTTPRangeRequest(url.c_str(), range_info.c_str(),
1018 existing_stream, notify_needed, 1045 existing_stream, notify_needed,
1019 notify_data); 1046 notify_data);
1020 } 1047 }
OLDNEW
« no previous file with comments | « chrome/plugin/webplugin_proxy.cc ('k') | webkit/glue/plugins/plugin_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698