OLD | NEW |
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/plugin/webplugin_proxy.h" | 5 #include "content/plugin/webplugin_proxy.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 CGContextClipToRect(windowless_context(), rect.ToCGRect()); | 364 CGContextClipToRect(windowless_context(), rect.ToCGRect()); |
365 // TODO(caryclark): This is a temporary workaround to allow the Darwin / Skia | 365 // TODO(caryclark): This is a temporary workaround to allow the Darwin / Skia |
366 // port to share code with the Darwin / CG port. All ports will eventually use | 366 // port to share code with the Darwin / CG port. All ports will eventually use |
367 // the common code below. | 367 // the common code below. |
368 delegate_->CGPaint(windowless_context(), rect); | 368 delegate_->CGPaint(windowless_context(), rect); |
369 if (windowless_contexts_[saved_index].get() == saved_context_weak) | 369 if (windowless_contexts_[saved_index].get() == saved_context_weak) |
370 CGContextRestoreGState(windowless_contexts_[saved_index]); | 370 CGContextRestoreGState(windowless_contexts_[saved_index]); |
371 #else | 371 #else |
372 // See above comment about windowless_context_ changing. | 372 // See above comment about windowless_context_ changing. |
373 // http::/crbug.com/139462 | 373 // http::/crbug.com/139462 |
374 skia::PlatformCanvas* saved_canvas = windowless_canvas(); | 374 skia::RefPtr<skia::PlatformCanvas> saved_canvas = windowless_canvas(); |
375 SkAutoRef local_ref(saved_canvas); | |
376 #if defined(USE_X11) | 375 #if defined(USE_X11) |
377 scoped_refptr<SharedTransportDIB> local_dib_ref( | 376 scoped_refptr<SharedTransportDIB> local_dib_ref( |
378 windowless_dibs_[windowless_buffer_index_]); | 377 windowless_dibs_[windowless_buffer_index_]); |
379 #endif | 378 #endif |
380 | 379 |
381 saved_canvas->save(); | 380 saved_canvas->save(); |
382 | 381 |
383 // The given clip rect is relative to the plugin coordinate system. | 382 // The given clip rect is relative to the plugin coordinate system. |
384 SkRect sk_rect = { SkIntToScalar(rect.x()), | 383 SkRect sk_rect = { SkIntToScalar(rect.x()), |
385 SkIntToScalar(rect.y()), | 384 SkIntToScalar(rect.y()), |
386 SkIntToScalar(rect.right()), | 385 SkIntToScalar(rect.right()), |
387 SkIntToScalar(rect.bottom()) }; | 386 SkIntToScalar(rect.bottom()) }; |
388 saved_canvas->clipRect(sk_rect); | 387 saved_canvas->clipRect(sk_rect); |
389 | 388 |
390 // Fill a transparent value so that if the plugin supports transparency that | 389 // Fill a transparent value so that if the plugin supports transparency that |
391 // will work. | 390 // will work. |
392 saved_canvas->drawColor(SkColorSetARGB(0, 0, 0, 0), SkXfermode::kSrc_Mode); | 391 saved_canvas->drawColor(SkColorSetARGB(0, 0, 0, 0), SkXfermode::kSrc_Mode); |
393 | 392 |
394 // Bring the windowless canvas into the window coordinate system, which is | 393 // Bring the windowless canvas into the window coordinate system, which is |
395 // how the plugin expects to draw (since the windowless API was originally | 394 // how the plugin expects to draw (since the windowless API was originally |
396 // designed just for scribbling over the web page). | 395 // designed just for scribbling over the web page). |
397 saved_canvas->translate(SkIntToScalar(-delegate_->GetRect().x()), | 396 saved_canvas->translate(SkIntToScalar(-delegate_->GetRect().x()), |
398 SkIntToScalar(-delegate_->GetRect().y())); | 397 SkIntToScalar(-delegate_->GetRect().y())); |
399 | 398 |
400 // Before we send the invalidate, paint so that renderer uses the updated | 399 // Before we send the invalidate, paint so that renderer uses the updated |
401 // bitmap. | 400 // bitmap. |
402 delegate_->Paint(saved_canvas, offset_rect); | 401 delegate_->Paint(saved_canvas.get(), offset_rect); |
403 | 402 |
404 saved_canvas->restore(); | 403 saved_canvas->restore(); |
405 #endif | 404 #endif |
406 } | 405 } |
407 | 406 |
408 void WebPluginProxy::UpdateGeometry( | 407 void WebPluginProxy::UpdateGeometry( |
409 const gfx::Rect& window_rect, | 408 const gfx::Rect& window_rect, |
410 const gfx::Rect& clip_rect, | 409 const gfx::Rect& clip_rect, |
411 const TransportDIB::Handle& windowless_buffer0, | 410 const TransportDIB::Handle& windowless_buffer0, |
412 const TransportDIB::Handle& windowless_buffer1, | 411 const TransportDIB::Handle& windowless_buffer1, |
(...skipping 30 matching lines...) Expand all Loading... |
443 !damaged_rect_.IsEmpty()) { | 442 !damaged_rect_.IsEmpty()) { |
444 InvalidateRect(damaged_rect_); | 443 InvalidateRect(damaged_rect_); |
445 } | 444 } |
446 } | 445 } |
447 | 446 |
448 #if defined(OS_WIN) | 447 #if defined(OS_WIN) |
449 | 448 |
450 void WebPluginProxy::CreateCanvasFromHandle( | 449 void WebPluginProxy::CreateCanvasFromHandle( |
451 const TransportDIB::Handle& dib_handle, | 450 const TransportDIB::Handle& dib_handle, |
452 const gfx::Rect& window_rect, | 451 const gfx::Rect& window_rect, |
453 SkAutoTUnref<skia::PlatformCanvas>* canvas) { | 452 skia::RefPtr<skia::PlatformCanvas>* canvas) { |
454 canvas->reset(skia::CreatePlatformCanvas(window_rect.width(), | 453 *canvas = skia::AdoptRef( |
455 window_rect.height(), | 454 skia::CreatePlatformCanvas(window_rect.width(), |
456 true, | 455 window_rect.height(), |
457 dib_handle, | 456 true, |
458 skia::RETURN_NULL_ON_FAILURE)); | 457 dib_handle, |
| 458 skia::RETURN_NULL_ON_FAILURE)); |
459 // The canvas does not own the section so we need to close it now. | 459 // The canvas does not own the section so we need to close it now. |
460 CloseHandle(dib_handle); | 460 CloseHandle(dib_handle); |
461 } | 461 } |
462 | 462 |
463 void WebPluginProxy::SetWindowlessBuffers( | 463 void WebPluginProxy::SetWindowlessBuffers( |
464 const TransportDIB::Handle& windowless_buffer0, | 464 const TransportDIB::Handle& windowless_buffer0, |
465 const TransportDIB::Handle& windowless_buffer1, | 465 const TransportDIB::Handle& windowless_buffer1, |
466 const gfx::Rect& window_rect) { | 466 const gfx::Rect& window_rect) { |
467 CreateCanvasFromHandle(windowless_buffer0, | 467 CreateCanvasFromHandle(windowless_buffer0, |
468 window_rect, | 468 window_rect, |
469 &windowless_canvases_[0]); | 469 &windowless_canvases_[0]); |
470 if (!windowless_canvases_[0].get()) { | 470 if (!windowless_canvases_[0]) { |
471 windowless_canvases_[1].reset(NULL); | 471 windowless_canvases_[1].clear(); |
472 return; | 472 return; |
473 } | 473 } |
474 CreateCanvasFromHandle(windowless_buffer1, | 474 CreateCanvasFromHandle(windowless_buffer1, |
475 window_rect, | 475 window_rect, |
476 &windowless_canvases_[1]); | 476 &windowless_canvases_[1]); |
477 if (!windowless_canvases_[1].get()) { | 477 if (!windowless_canvases_[1]) { |
478 windowless_canvases_[0].reset(NULL); | 478 windowless_canvases_[0].clear(); |
479 return; | 479 return; |
480 } | 480 } |
481 } | 481 } |
482 | 482 |
483 #elif defined(OS_MACOSX) | 483 #elif defined(OS_MACOSX) |
484 | 484 |
485 void WebPluginProxy::CreateDIBAndCGContextFromHandle( | 485 void WebPluginProxy::CreateDIBAndCGContextFromHandle( |
486 const TransportDIB::Handle& dib_handle, | 486 const TransportDIB::Handle& dib_handle, |
487 const gfx::Rect& window_rect, | 487 const gfx::Rect& window_rect, |
488 scoped_ptr<TransportDIB>* dib_out, | 488 scoped_ptr<TransportDIB>* dib_out, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 &windowless_dibs_[1], | 520 &windowless_dibs_[1], |
521 &windowless_contexts_[1]); | 521 &windowless_contexts_[1]); |
522 } | 522 } |
523 | 523 |
524 #elif defined(USE_X11) | 524 #elif defined(USE_X11) |
525 | 525 |
526 void WebPluginProxy::CreateDIBAndCanvasFromHandle( | 526 void WebPluginProxy::CreateDIBAndCanvasFromHandle( |
527 const TransportDIB::Handle& dib_handle, | 527 const TransportDIB::Handle& dib_handle, |
528 const gfx::Rect& window_rect, | 528 const gfx::Rect& window_rect, |
529 scoped_refptr<SharedTransportDIB>* dib_out, | 529 scoped_refptr<SharedTransportDIB>* dib_out, |
530 SkAutoTUnref<skia::PlatformCanvas>* canvas) { | 530 skia::RefPtr<skia::PlatformCanvas>* canvas) { |
531 TransportDIB* dib = TransportDIB::Map(dib_handle); | 531 TransportDIB* dib = TransportDIB::Map(dib_handle); |
532 // dib may be NULL if the renderer has already destroyed the TransportDIB by | 532 // dib may be NULL if the renderer has already destroyed the TransportDIB by |
533 // the time we receive the handle, e.g. in case of multiple resizes. | 533 // the time we receive the handle, e.g. in case of multiple resizes. |
534 if (dib) { | 534 if (dib) { |
535 canvas->reset( | 535 *canvas = skia::AdoptRef( |
536 dib->GetPlatformCanvas(window_rect.width(), window_rect.height())); | 536 dib->GetPlatformCanvas(window_rect.width(), window_rect.height())); |
537 } else { | 537 } else { |
538 canvas->reset(NULL); | 538 canvas->clear(); |
539 } | 539 } |
540 *dib_out = new SharedTransportDIB(dib); | 540 *dib_out = new SharedTransportDIB(dib); |
541 } | 541 } |
542 | 542 |
543 void WebPluginProxy::CreateShmPixmapFromDIB( | 543 void WebPluginProxy::CreateShmPixmapFromDIB( |
544 TransportDIB* dib, | 544 TransportDIB* dib, |
545 const gfx::Rect& window_rect, | 545 const gfx::Rect& window_rect, |
546 XID* pixmap_out) { | 546 XID* pixmap_out) { |
547 if (dib) { | 547 if (dib) { |
548 Display* display = ui::GetXDisplay(); | 548 Display* display = ui::GetXDisplay(); |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 int input_type; | 724 int input_type; |
725 gfx::Rect caret_rect; | 725 gfx::Rect caret_rect; |
726 if (!delegate_->GetIMEStatus(&input_type, &caret_rect)) | 726 if (!delegate_->GetIMEStatus(&input_type, &caret_rect)) |
727 return; | 727 return; |
728 | 728 |
729 Send(new PluginHostMsg_NotifyIMEStatus(route_id_, input_type, caret_rect)); | 729 Send(new PluginHostMsg_NotifyIMEStatus(route_id_, input_type, caret_rect)); |
730 } | 730 } |
731 #endif | 731 #endif |
732 | 732 |
733 } // namespace content | 733 } // namespace content |
OLD | NEW |