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

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

Issue 113637: Wire up windowless plugins. Mostly Mac related, some cross (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' 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 | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/webplugin_delegate_proxy.h ('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>
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/logging.h" 17 #include "base/logging.h"
17 #include "base/ref_counted.h" 18 #include "base/ref_counted.h"
18 #include "base/string_util.h" 19 #include "base/string_util.h"
19 #include "base/gfx/size.h" 20 #include "base/gfx/size.h"
20 #include "base/gfx/native_widget_types.h" 21 #include "base/gfx/native_widget_types.h"
21 #include "chrome/common/child_process_logging.h" 22 #include "chrome/common/child_process_logging.h"
22 #include "chrome/common/plugin_messages.h" 23 #include "chrome/common/plugin_messages.h"
23 #include "chrome/common/render_messages.h" 24 #include "chrome/common/render_messages.h"
24 #include "chrome/plugin/npobject_proxy.h" 25 #include "chrome/plugin/npobject_proxy.h"
25 #include "chrome/plugin/npobject_stub.h" 26 #include "chrome/plugin/npobject_stub.h"
(...skipping 10 matching lines...) Expand all
36 #include "webkit/api/public/WebVector.h" 37 #include "webkit/api/public/WebVector.h"
37 #include "webkit/glue/webframe.h" 38 #include "webkit/glue/webframe.h"
38 #include "webkit/glue/webkit_glue.h" 39 #include "webkit/glue/webkit_glue.h"
39 #include "webkit/glue/webplugin.h" 40 #include "webkit/glue/webplugin.h"
40 #include "webkit/glue/webview.h" 41 #include "webkit/glue/webview.h"
41 42
42 #if defined(OS_POSIX) 43 #if defined(OS_POSIX)
43 #include "chrome/common/ipc_channel_posix.h" 44 #include "chrome/common/ipc_channel_posix.h"
44 #endif 45 #endif
45 46
47 #if defined(OS_MACOSX)
48 #include "base/scoped_cftyperef.h"
49 #endif
50
46 using WebKit::WebCursorInfo; 51 using WebKit::WebCursorInfo;
47 using WebKit::WebInputEvent; 52 using WebKit::WebInputEvent;
48 using WebKit::WebDragData; 53 using WebKit::WebDragData;
49 using WebKit::WebVector; 54 using WebKit::WebVector;
50 using WebKit::WebString; 55 using WebKit::WebString;
51 56
52 // Proxy for WebPluginResourceClient. The object owns itself after creation, 57 // Proxy for WebPluginResourceClient. The object owns itself after creation,
53 // deleting itself after its callback has been called. 58 // deleting itself after its callback has been called.
54 class ResourceClientProxy : public WebPluginResourceClient { 59 class ResourceClientProxy : public WebPluginResourceClient {
55 public: 60 public:
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 if (plugin_) 387 if (plugin_)
383 plugin_->Invalidate(); 388 plugin_->Invalidate();
384 render_view_->PluginCrashed(plugin_path_); 389 render_view_->PluginCrashed(plugin_path_);
385 } 390 }
386 391
387 void WebPluginDelegateProxy::UpdateGeometry( 392 void WebPluginDelegateProxy::UpdateGeometry(
388 const gfx::Rect& window_rect, 393 const gfx::Rect& window_rect,
389 const gfx::Rect& clip_rect) { 394 const gfx::Rect& clip_rect) {
390 plugin_rect_ = window_rect; 395 plugin_rect_ = window_rect;
391 396
392 // Be careful to explicitly call the default constructors for these ids, 397 bool bitmaps_changed = false;
393 // as they can be POD on some platforms and we want them initialized.
394 TransportDIB::Id transport_store_id = TransportDIB::Id();
395 TransportDIB::Id background_store_id = TransportDIB::Id();
396 398
397 if (windowless_) { 399 if (windowless_) {
398 #if defined(OS_WIN)
399 // TODO(port): use TransportDIB instead of allocating these directly.
400 if (!backing_store_canvas_.get() || 400 if (!backing_store_canvas_.get() ||
401 (window_rect.width() != backing_store_canvas_->getDevice()->width() || 401 (window_rect.width() != backing_store_canvas_->getDevice()->width() ||
402 window_rect.height() != backing_store_canvas_->getDevice()->height())) { 402 window_rect.height() != backing_store_canvas_->getDevice()->height())) {
403 bitmaps_changed = true;
403 // Create a shared memory section that the plugin paints into 404 // Create a shared memory section that the plugin paints into
404 // asynchronously. 405 // asynchronously.
405 ResetWindowlessBitmaps(); 406 ResetWindowlessBitmaps();
406 if (!window_rect.IsEmpty()) { 407 if (!window_rect.IsEmpty()) {
407 if (!CreateBitmap(&backing_store_, &backing_store_canvas_) || 408 if (!CreateBitmap(&backing_store_, &backing_store_canvas_) ||
408 !CreateBitmap(&transport_store_, &transport_store_canvas_) || 409 !CreateBitmap(&transport_store_, &transport_store_canvas_) ||
409 (transparent_ && 410 (transparent_ &&
410 !CreateBitmap(&background_store_, &background_store_canvas_))) { 411 !CreateBitmap(&background_store_, &background_store_canvas_))) {
411 DCHECK(false); 412 DCHECK(false);
412 ResetWindowlessBitmaps(); 413 ResetWindowlessBitmaps();
413 return; 414 return;
414 } 415 }
415
416 // TODO(port): once we use TransportDIB we will properly fill in these
417 // ids; for now we just fill in the HANDLE field.
418 transport_store_id.handle = transport_store_->handle();
419 if (background_store_.get())
420 background_store_id.handle = background_store_->handle();
421 } 416 }
422 } 417 }
423 #else
424 // TODO(port): refactor our allocation of backing stores.
425 NOTIMPLEMENTED();
426 #endif
427 } 418 }
428 419
429 IPC::Message* msg = new PluginMsg_UpdateGeometry( 420 IPC::Message* msg = NULL;
430 instance_id_, window_rect, clip_rect, 421 #if defined(OS_POSIX)
431 transport_store_id, background_store_id); 422 // If we're using POSIX mmap'd TransportDIBs, sending the handle across
423 // IPC establishes a new mapping rather than just sending a window ID,
424 // so only do so if we've actually recreated the shared memory bitmaps.
425 if (!bitmaps_changed) {
426 msg = new PluginMsg_UpdateGeometry(instance_id_, window_rect, clip_rect,
427 TransportDIB::Handle(), TransportDIB::Handle());
428 } else
429 #endif
430 if (transport_store_.get() && background_store_.get()) {
431 msg = new PluginMsg_UpdateGeometry(instance_id_, window_rect, clip_rect,
432 transport_store_->handle(), background_store_->handle());
433 } else if (transport_store_.get()) {
434 msg = new PluginMsg_UpdateGeometry(instance_id_, window_rect, clip_rect,
435 transport_store_->handle(), TransportDIB::Handle());
436 } else {
437 msg = new PluginMsg_UpdateGeometry(instance_id_, window_rect, clip_rect,
438 TransportDIB::Handle(), TransportDIB::Handle());
439 }
440
432 msg->set_unblock(true); 441 msg->set_unblock(true);
433 Send(msg); 442 Send(msg);
434 } 443 }
435 444
436 #if defined(OS_WIN) 445 #if defined(OS_MACOSX)
437 // Copied from render_widget.cc 446 static void ReleaseTransportDIB(TransportDIB *dib) {
438 static size_t GetPaintBufSize(const gfx::Rect& rect) { 447 if (dib) {
439 // TODO(darin): protect against overflow 448 IPC::Message* msg = new ViewHostMsg_FreeTransportDIB(dib->id());
440 return 4 * rect.width() * rect.height(); 449 RenderThread::current()->Send(msg);
450 }
441 } 451 }
442 #endif 452 #endif
443 453
444 void WebPluginDelegateProxy::ResetWindowlessBitmaps() { 454 void WebPluginDelegateProxy::ResetWindowlessBitmaps() {
455 #if defined(OS_MACOSX)
456 // tell the browser to relase these TransportDIBs
457 ReleaseTransportDIB(backing_store_.get());
458 ReleaseTransportDIB(transport_store_.get());
459 ReleaseTransportDIB(background_store_.get());
460 #endif
461
445 backing_store_.reset(); 462 backing_store_.reset();
446 transport_store_.reset(); 463 transport_store_.reset();
447 backing_store_canvas_.reset(); 464 backing_store_canvas_.reset();
448 transport_store_canvas_.reset(); 465 transport_store_canvas_.reset();
449 background_store_.reset(); 466 background_store_.reset();
450 background_store_canvas_.release(); 467 background_store_canvas_.release();
451 backing_store_painted_ = gfx::Rect(); 468 backing_store_painted_ = gfx::Rect();
452 } 469 }
453 470
454 bool WebPluginDelegateProxy::CreateBitmap( 471 bool WebPluginDelegateProxy::CreateBitmap(
455 scoped_ptr<base::SharedMemory>* memory, 472 scoped_ptr<TransportDIB>* memory,
456 scoped_ptr<skia::PlatformCanvas>* canvas) { 473 scoped_ptr<skia::PlatformCanvas>* canvas) {
457 #if defined(OS_WIN) 474 int width = plugin_rect_.width();
458 size_t size = GetPaintBufSize(plugin_rect_); 475 int height = plugin_rect_.height();
459 scoped_ptr<base::SharedMemory> new_shared_memory(new base::SharedMemory()); 476 const size_t stride = skia::PlatformCanvas::StrideForWidth(width);
460 if (!new_shared_memory->Create(L"", false, true, size)) 477 const size_t size = stride * height;
478 #if defined(OS_LINUX)
479 static unsigned long max_size = 0;
480 if (max_size == 0) {
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)
461 return false; 486 return false;
462 487 #endif
463 scoped_ptr<skia::PlatformCanvas> new_canvas(new skia::PlatformCanvas); 488 #if defined(OS_MACOSX)
464 if (!new_canvas->initialize(plugin_rect_.width(), plugin_rect_.height(), 489 TransportDIB::Handle handle;
465 true, new_shared_memory->handle())) { 490 IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(size, &handle);
491 if (!RenderThread::current()->Send(msg))
466 return false; 492 return false;
467 } 493 if (handle.fd < 0)
468 494 return false;
469 memory->swap(new_shared_memory); 495 memory->reset(TransportDIB::Map(handle));
470 canvas->swap(new_canvas); 496 #else
497 static uint32 sequence_number = 0;
498 memory->reset(TransportDIB::Create(size, sequence_number++));
499 #endif
500 canvas->reset((*memory)->GetPlatformCanvas(width, height));
471 return true; 501 return true;
472 #else
473 // TODO(port): use TransportDIB properly.
474 NOTIMPLEMENTED();
475 return false;
476 #endif
477 } 502 }
478 503
479 void WebPluginDelegateProxy::Paint(gfx::NativeDrawingContext context, 504 void WebPluginDelegateProxy::Paint(gfx::NativeDrawingContext context,
480 const gfx::Rect& damaged_rect) { 505 const gfx::Rect& damaged_rect) {
481 // If the plugin is no longer connected (channel crashed) draw a crashed 506 // If the plugin is no longer connected (channel crashed) draw a crashed
482 // plugin bitmap 507 // plugin bitmap
483 if (!channel_host_->channel_valid()) { 508 if (!channel_host_->channel_valid()) {
484 PaintSadPlugin(context, damaged_rect); 509 PaintSadPlugin(context, damaged_rect);
485 return; 510 return;
486 } 511 }
487 512
488 // No paint events for windowed plugins. 513 // No paint events for windowed plugins.
489 if (!windowless_) 514 if (!windowless_)
490 return; 515 return;
491 516
492 // TODO(port): side-stepping some windowless plugin code for now.
493 #if defined(OS_WIN)
494 // We got a paint before the plugin's coordinates, so there's no buffer to 517 // We got a paint before the plugin's coordinates, so there's no buffer to
495 // copy from. 518 // copy from.
496 if (!backing_store_canvas_.get()) 519 if (!backing_store_canvas_.get()) {
497 return; 520 return;
521 }
498 522
499 // Limit the damaged rectangle to whatever is contained inside the plugin 523 // Limit the damaged rectangle to whatever is contained inside the plugin
500 // rectangle, as that's the rectangle that we'll bitblt to the hdc. 524 // rectangle, as that's the rectangle that we'll bitblt to the hdc.
501 gfx::Rect rect = damaged_rect.Intersect(plugin_rect_); 525 gfx::Rect rect = damaged_rect.Intersect(plugin_rect_);
526 gfx::Rect offset_rect = rect;
527 offset_rect.Offset(-plugin_rect_.x(), -plugin_rect_.y());
502 528
503 bool background_changed = false; 529 bool background_changed = false;
504 if (background_store_canvas_.get() && BackgroundChanged(context, rect)) { 530 if (background_store_canvas_.get() && BackgroundChanged(context, rect)) {
505 background_changed = true; 531 background_changed = true;
532 #if defined(OS_WIN)
506 HDC background_hdc = 533 HDC background_hdc =
507 background_store_canvas_->getTopPlatformDevice().getBitmapDC(); 534 background_store_canvas_->getTopPlatformDevice().getBitmapDC();
508 BitBlt(background_hdc, rect.x()-plugin_rect_.x(), rect.y()-plugin_rect_.y(), 535 BitBlt(background_hdc, offset_rect.x(), offset_rect.y(),
509 rect.width(), rect.height(), context, rect.x(), rect.y(), SRCCOPY); 536 rect.width(), rect.height(), context, rect.x(), rect.y(), SRCCOPY);
537 #elif defined(OS_MACOSX)
538 CGContextRef background_context =
539 background_store_canvas_->getTopPlatformDevice().GetBitmapContext();
540 scoped_cftyperef<CGImageRef>
541 background_image(CGBitmapContextCreateImage(background_context));
542 scoped_cftyperef<CGImageRef> sub_image(
543 CGImageCreateWithImageInRect(background_image, offset_rect.ToCGRect()));
544 CGContextDrawImage(context, rect.ToCGRect(), sub_image);
545 #else
546 NOTIMPLEMENTED();
547 #endif
510 } 548 }
511 549
512 gfx::Rect offset_rect = rect;
513 offset_rect.Offset(-plugin_rect_.x(), -plugin_rect_.y());
514 if (background_changed || !backing_store_painted_.Contains(offset_rect)) { 550 if (background_changed || !backing_store_painted_.Contains(offset_rect)) {
515 Send(new PluginMsg_Paint(instance_id_, offset_rect)); 551 Send(new PluginMsg_Paint(instance_id_, offset_rect));
516 CopyFromTransportToBacking(offset_rect); 552 CopyFromTransportToBacking(offset_rect);
517 } 553 }
518 554
555 #if defined(OS_WIN)
519 HDC backing_hdc = backing_store_canvas_->getTopPlatformDevice().getBitmapDC(); 556 HDC backing_hdc = backing_store_canvas_->getTopPlatformDevice().getBitmapDC();
520 BitBlt(context, rect.x(), rect.y(), rect.width(), rect.height(), backing_hdc, 557 BitBlt(context, rect.x(), rect.y(), rect.width(), rect.height(), backing_hdc,
521 rect.x()-plugin_rect_.x(), rect.y()-plugin_rect_.y(), SRCCOPY); 558 offset_rect.x(), offset_rect.y(), SRCCOPY);
559 #elif defined(OS_MACOSX)
560 CGContextRef backing_context =
561 backing_store_canvas_->getTopPlatformDevice().GetBitmapContext();
562 scoped_cftyperef<CGImageRef>
563 backing_image(CGBitmapContextCreateImage(backing_context));
564 scoped_cftyperef<CGImageRef> sub_image(
565 CGImageCreateWithImageInRect(backing_image, offset_rect.ToCGRect()));
566 CGContextDrawImage(context, rect.ToCGRect(), sub_image);
567 #else
568 NOTIMPLEMENTED();
569 #endif
522 570
523 if (invalidate_pending_) { 571 if (invalidate_pending_) {
524 // Only send the PaintAck message if this paint is in response to an 572 // Only send the PaintAck message if this paint is in response to an
525 // invalidate from the plugin, since this message acts as an access token 573 // invalidate from the plugin, since this message acts as an access token
526 // to ensure only one process is using the transport dib at a time. 574 // to ensure only one process is using the transport dib at a time.
527 invalidate_pending_ = false; 575 invalidate_pending_ = false;
528 Send(new PluginMsg_DidPaint(instance_id_)); 576 Send(new PluginMsg_DidPaint(instance_id_));
529 } 577 }
530 #else
531 // TODO(port): windowless plugin paint handling goes here.
532 NOTIMPLEMENTED();
533 #endif
534 } 578 }
535 579
580 bool WebPluginDelegateProxy::BackgroundChanged(
581 gfx::NativeDrawingContext hdc,
582 const gfx::Rect& rect) {
536 #if defined(OS_WIN) 583 #if defined(OS_WIN)
537 // TODO(port): this should be portable; just avoiding windowless plugins for
538 // now.
539 bool WebPluginDelegateProxy::BackgroundChanged(
540 HDC hdc,
541 const gfx::Rect& rect) {
542 HBITMAP hbitmap = static_cast<HBITMAP>(GetCurrentObject(hdc, OBJ_BITMAP)); 584 HBITMAP hbitmap = static_cast<HBITMAP>(GetCurrentObject(hdc, OBJ_BITMAP));
543 if (hbitmap == NULL) { 585 if (hbitmap == NULL) {
544 NOTREACHED(); 586 NOTREACHED();
545 return true; 587 return true;
546 } 588 }
547 589
548 BITMAP bitmap = { 0 }; 590 BITMAP bitmap = { 0 };
549 int result = GetObject(hbitmap, sizeof(bitmap), &bitmap); 591 int result = GetObject(hbitmap, sizeof(bitmap), &bitmap);
550 if (!result) { 592 if (!result) {
551 NOTREACHED(); 593 NOTREACHED();
(...skipping 19 matching lines...) Expand all
571 613
572 // getAddr32 doesn't use the translation units, so we have to subtract 614 // getAddr32 doesn't use the translation units, so we have to subtract
573 // the plugin origin from the coordinates. 615 // the plugin origin from the coordinates.
574 uint32_t* canvas_row_start = 616 uint32_t* canvas_row_start =
575 background_store_canvas_->getDevice()->accessBitmap(true).getAddr32( 617 background_store_canvas_->getDevice()->accessBitmap(true).getAddr32(
576 check_rect.x() - plugin_rect_.x(), y - plugin_rect_.y()); 618 check_rect.x() - plugin_rect_.x(), y - plugin_rect_.y());
577 if (memcmp(hdc_row_start, canvas_row_start, row_byte_size) != 0) 619 if (memcmp(hdc_row_start, canvas_row_start, row_byte_size) != 0)
578 return true; 620 return true;
579 } 621 }
580 622
623 #else
624 NOTIMPLEMENTED();
625 #endif
581 return false; 626 return false;
582 } 627 }
583 #endif
584 628
585 void WebPluginDelegateProxy::Print(gfx::NativeDrawingContext context) { 629 void WebPluginDelegateProxy::Print(gfx::NativeDrawingContext context) {
586 base::SharedMemoryHandle shared_memory; 630 base::SharedMemoryHandle shared_memory;
587 size_t size; 631 size_t size;
588 if (!Send(new PluginMsg_Print(instance_id_, &shared_memory, &size))) 632 if (!Send(new PluginMsg_Print(instance_id_, &shared_memory, &size)))
589 return; 633 return;
590 634
591 base::SharedMemory memory(shared_memory, true); 635 base::SharedMemory memory(shared_memory, true);
592 if (!memory.Map(size)) { 636 if (!memory.Map(size)) {
593 NOTREACHED(); 637 NOTREACHED();
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 897
854 void WebPluginDelegateProxy::OnMissingPluginStatus(int status) { 898 void WebPluginDelegateProxy::OnMissingPluginStatus(int status) {
855 if (render_view_) 899 if (render_view_)
856 render_view_->OnMissingPluginStatus(this, status); 900 render_view_->OnMissingPluginStatus(this, status);
857 } 901 }
858 902
859 void WebPluginDelegateProxy::OnGetCPBrowsingContext(uint32* context) { 903 void WebPluginDelegateProxy::OnGetCPBrowsingContext(uint32* context) {
860 *context = render_view_ ? render_view_->GetCPBrowsingContext() : 0; 904 *context = render_view_ ? render_view_->GetCPBrowsingContext() : 0;
861 } 905 }
862 906
863 void WebPluginDelegateProxy::PaintSadPlugin(gfx::NativeDrawingContext hdc, 907 void WebPluginDelegateProxy::PaintSadPlugin(gfx::NativeDrawingContext context,
864 const gfx::Rect& rect) { 908 const gfx::Rect& rect) {
865 const int width = plugin_rect_.width(); 909 const int width = plugin_rect_.width();
866 const int height = plugin_rect_.height(); 910 const int height = plugin_rect_.height();
867 911
868 gfx::Canvas canvas(width, height, false); 912 gfx::Canvas canvas(width, height, false);
869 SkPaint paint; 913 SkPaint paint;
870 914
871 paint.setStyle(SkPaint::kFill_Style); 915 paint.setStyle(SkPaint::kFill_Style);
872 paint.setColor(SK_ColorBLACK); 916 paint.setColor(SK_ColorBLACK);
873 canvas.drawRectCoords(0, 0, SkIntToScalar(width), SkIntToScalar(height), 917 canvas.drawRectCoords(0, 0, SkIntToScalar(width), SkIntToScalar(height),
874 paint); 918 paint);
875 919
876 if (!sad_plugin_) { 920 if (!sad_plugin_) {
877 sad_plugin_ = ResourceBundle::GetSharedInstance().GetBitmapNamed( 921 sad_plugin_ = ResourceBundle::GetSharedInstance().GetBitmapNamed(
878 IDR_SAD_PLUGIN); 922 IDR_SAD_PLUGIN);
879 } 923 }
880 924
881 if (sad_plugin_) { 925 if (sad_plugin_) {
882 canvas.DrawBitmapInt(*sad_plugin_, 926 canvas.DrawBitmapInt(*sad_plugin_,
883 std::max(0, (width - sad_plugin_->width())/2), 927 std::max(0, (width - sad_plugin_->width())/2),
884 std::max(0, (height - sad_plugin_->height())/2)); 928 std::max(0, (height - sad_plugin_->height())/2));
885 } 929 }
886 930
887 #if defined(OS_WIN) 931 #if defined(OS_WIN)
888 skia::PlatformDevice& device = canvas.getTopPlatformDevice(); 932 skia::PlatformDevice& device = canvas.getTopPlatformDevice();
889 device.drawToHDC(hdc, plugin_rect_.x(), plugin_rect_.y(), NULL); 933 device.drawToHDC(context, plugin_rect_.x(), plugin_rect_.y(), NULL);
890 #elif defined(OS_LINUX) 934 #elif defined(OS_LINUX)
891 // Though conceptually we've been handed a cairo_surface_t* and we 935 // Though conceptually we've been handed a cairo_surface_t* and we
892 // could've just hooked up the canvas to draw directly onto it, our 936 // could've just hooked up the canvas to draw directly onto it, our
893 // canvas implementation currently uses cairo as a dumb pixel buffer 937 // canvas implementation currently uses cairo as a dumb pixel buffer
894 // and would have done the following copy anyway. 938 // and would have done the following copy anyway.
895 // TODO(evanm): revisit when we have printing hooked up, as that might 939 // TODO(evanm): revisit when we have printing hooked up, as that might
896 // change our usage of cairo. 940 // change our usage of cairo.
897 skia::PlatformDevice& device = canvas.getTopPlatformDevice(); 941 skia::PlatformDevice& device = canvas.getTopPlatformDevice();
898 cairo_t* cairo = cairo_create(hdc); 942 cairo_t* cairo = cairo_create(context);
899 cairo_surface_t* source_surface = device.beginPlatformPaint(); 943 cairo_surface_t* source_surface = device.beginPlatformPaint();
900 cairo_set_source_surface(cairo, source_surface, plugin_rect_.x(), plugin_rect_ .y()); 944 cairo_set_source_surface(cairo, source_surface, plugin_rect_.x(), plugin_rect_ .y());
901 cairo_paint(cairo); 945 cairo_paint(cairo);
902 cairo_destroy(cairo); 946 cairo_destroy(cairo);
903 // We have no endPlatformPaint() on the Linux PlatformDevice. 947 // We have no endPlatformPaint() on the Linux PlatformDevice.
904 // The surface is owned by the device. 948 // The surface is owned by the device.
949 #elif defined(OS_MACOSX)
950 canvas.getTopPlatformDevice().DrawToContext(
951 context, plugin_rect_.x(), plugin_rect_.y(), NULL);
905 #else 952 #else
906 NOTIMPLEMENTED(); 953 NOTIMPLEMENTED();
907 #endif 954 #endif
908 } 955 }
909 956
910 void WebPluginDelegateProxy::CopyFromTransportToBacking(const gfx::Rect& rect) { 957 void WebPluginDelegateProxy::CopyFromTransportToBacking(const gfx::Rect& rect) {
911 if (!backing_store_canvas_.get()) 958 if (!backing_store_canvas_.get()) {
912 return; 959 return;
960 }
913 961
962 // Copy the damaged rect from the transport bitmap to the backing store.
914 #if defined(OS_WIN) 963 #if defined(OS_WIN)
915 // Copy the damaged rect from the transport bitmap to the backing store.
916 HDC backing = backing_store_canvas_->getTopPlatformDevice().getBitmapDC(); 964 HDC backing = backing_store_canvas_->getTopPlatformDevice().getBitmapDC();
917 HDC transport = transport_store_canvas_->getTopPlatformDevice().getBitmapDC(); 965 HDC transport = transport_store_canvas_->getTopPlatformDevice().getBitmapDC();
918 BitBlt(backing, rect.x(), rect.y(), rect.width(), rect.height(), 966 BitBlt(backing, rect.x(), rect.y(), rect.width(), rect.height(),
919 transport, rect.x(), rect.y(), SRCCOPY); 967 transport, rect.x(), rect.y(), SRCCOPY);
920 backing_store_painted_ = backing_store_painted_.Union(rect); 968 #elif defined(OS_MACOSX)
969 gfx::NativeDrawingContext backing =
970 backing_store_canvas_->getTopPlatformDevice().GetBitmapContext();
971 gfx::NativeDrawingContext transport =
972 transport_store_canvas_->getTopPlatformDevice().GetBitmapContext();
973 scoped_cftyperef<CGImageRef> image(CGBitmapContextCreateImage(transport));
974 scoped_cftyperef<CGImageRef> sub_image(
975 CGImageCreateWithImageInRect(image, rect.ToCGRect()));
976 CGContextDrawImage(backing, rect.ToCGRect(), sub_image);
921 #else 977 #else
922 // TODO(port): probably some new code in TransportDIB should go here. 978 // TODO(port): probably some new code in TransportDIB should go here.
923 NOTIMPLEMENTED(); 979 NOTIMPLEMENTED();
924 #endif 980 #endif
981 backing_store_painted_ = backing_store_painted_.Union(rect);
925 } 982 }
926 983
927 void WebPluginDelegateProxy::OnHandleURLRequest( 984 void WebPluginDelegateProxy::OnHandleURLRequest(
928 const PluginHostMsg_URLRequest_Params& params) { 985 const PluginHostMsg_URLRequest_Params& params) {
929 const char* data = NULL; 986 const char* data = NULL;
930 if (params.buffer.size()) 987 if (params.buffer.size())
931 data = &params.buffer[0]; 988 data = &params.buffer[0];
932 989
933 const char* target = NULL; 990 const char* target = NULL;
934 if (params.target.length()) 991 if (params.target.length())
(...skipping 27 matching lines...) Expand all
962 plugin_->CancelDocumentLoad(); 1019 plugin_->CancelDocumentLoad();
963 } 1020 }
964 1021
965 void WebPluginDelegateProxy::OnInitiateHTTPRangeRequest( 1022 void WebPluginDelegateProxy::OnInitiateHTTPRangeRequest(
966 const std::string& url, const std::string& range_info, 1023 const std::string& url, const std::string& range_info,
967 intptr_t existing_stream, bool notify_needed, intptr_t notify_data) { 1024 intptr_t existing_stream, bool notify_needed, intptr_t notify_data) {
968 plugin_->InitiateHTTPRangeRequest(url.c_str(), range_info.c_str(), 1025 plugin_->InitiateHTTPRangeRequest(url.c_str(), range_info.c_str(),
969 existing_stream, notify_needed, 1026 existing_stream, notify_needed,
970 notify_data); 1027 notify_data);
971 } 1028 }
OLDNEW
« no previous file with comments | « chrome/renderer/webplugin_delegate_proxy.h ('k') | webkit/glue/plugins/plugin_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698