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

Side by Side Diff: content/renderer/pepper/pepper_plugin_instance_impl.cc

Issue 23866006: Make fullscreen pepper flash create a texture layer with software compositor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | « content/renderer/pepper/pepper_plugin_instance_impl.h ('k') | no next file » | 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) 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/renderer/pepper/pepper_plugin_instance_impl.h" 5 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/command_line.h"
9 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/memory/linked_ptr.h" 12 #include "base/memory/linked_ptr.h"
12 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
13 #include "base/stl_util.h" 14 #include "base/stl_util.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_offset_string_conversions.h" 16 #include "base/strings/utf_offset_string_conversions.h"
16 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
17 #include "base/time/time.h" 18 #include "base/time/time.h"
18 #include "cc/layers/texture_layer.h" 19 #include "cc/layers/texture_layer.h"
19 #include "content/common/content_constants_internal.h" 20 #include "content/common/content_constants_internal.h"
21 #include "content/public/common/content_switches.h"
20 #include "content/public/common/page_zoom.h" 22 #include "content/public/common/page_zoom.h"
21 #include "content/public/renderer/content_renderer_client.h" 23 #include "content/public/renderer/content_renderer_client.h"
22 #include "content/renderer/pepper/common.h" 24 #include "content/renderer/pepper/common.h"
23 #include "content/renderer/pepper/content_decryptor_delegate.h" 25 #include "content/renderer/pepper/content_decryptor_delegate.h"
24 #include "content/renderer/pepper/event_conversion.h" 26 #include "content/renderer/pepper/event_conversion.h"
25 #include "content/renderer/pepper/fullscreen_container.h" 27 #include "content/renderer/pepper/fullscreen_container.h"
26 #include "content/renderer/pepper/gfx_conversion.h" 28 #include "content/renderer/pepper/gfx_conversion.h"
27 #include "content/renderer/pepper/host_dispatcher_wrapper.h" 29 #include "content/renderer/pepper/host_dispatcher_wrapper.h"
28 #include "content/renderer/pepper/host_globals.h" 30 #include "content/renderer/pepper/host_globals.h"
29 #include "content/renderer/pepper/message_channel.h" 31 #include "content/renderer/pepper/message_channel.h"
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this); 520 resource_creation_ = host_impl->CreateInProcessResourceCreationAPI(this);
519 521
520 if (GetContentClient()->renderer() && // NULL in unit tests. 522 if (GetContentClient()->renderer() && // NULL in unit tests.
521 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name())) 523 GetContentClient()->renderer()->IsExternalPepperPlugin(module->name()))
522 external_document_load_ = true; 524 external_document_load_ = true;
523 } 525 }
524 526
525 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() { 527 PepperPluginInstanceImpl::~PepperPluginInstanceImpl() {
526 DCHECK(!fullscreen_container_); 528 DCHECK(!fullscreen_container_);
527 529
528 // Force-unbind any Graphics. In the case of Graphics2D, if the plugin
529 // leaks the graphics 2D, it may actually get cleaned up after our
530 // destruction, so we need its pointers to be up-to-date.
531 BindGraphics(pp_instance(), 0);
532
533 // Free all the plugin objects. This will automatically clear the back- 530 // Free all the plugin objects. This will automatically clear the back-
534 // pointer from the NPObject so WebKit can't call into the plugin any more. 531 // pointer from the NPObject so WebKit can't call into the plugin any more.
535 // 532 //
536 // Swap out the set so we can delete from it (the objects will try to 533 // Swap out the set so we can delete from it (the objects will try to
537 // unregister themselves inside the delete call). 534 // unregister themselves inside the delete call).
538 PluginObjectSet plugin_object_copy; 535 PluginObjectSet plugin_object_copy;
539 live_plugin_objects_.swap(plugin_object_copy); 536 live_plugin_objects_.swap(plugin_object_copy);
540 for (PluginObjectSet::iterator i = plugin_object_copy.begin(); 537 for (PluginObjectSet::iterator i = plugin_object_copy.begin();
541 i != plugin_object_copy.end(); ++i) 538 i != plugin_object_copy.end(); ++i)
542 delete *i; 539 delete *i;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 else 583 else
587 instance_interface_->DidDestroy(pp_instance()); 584 instance_interface_->DidDestroy(pp_instance());
588 // Ensure we don't attempt to call functions on the destroyed instance. 585 // Ensure we don't attempt to call functions on the destroyed instance.
589 original_instance_interface_.reset(); 586 original_instance_interface_.reset();
590 instance_interface_.reset(); 587 instance_interface_.reset();
591 588
592 if (fullscreen_container_) { 589 if (fullscreen_container_) {
593 fullscreen_container_->Destroy(); 590 fullscreen_container_->Destroy();
594 fullscreen_container_ = NULL; 591 fullscreen_container_ = NULL;
595 } 592 }
596 bound_graphics_3d_ = NULL; 593
597 UpdateLayer(); 594 // Force-unbind any Graphics. In the case of Graphics2D, if the plugin
595 // leaks the graphics 2D, it may actually get cleaned up after our
596 // destruction, so we need its pointers to be up-to-date.
597 BindGraphics(pp_instance(), 0);
598 container_ = NULL; 598 container_ = NULL;
599 } 599 }
600 600
601 void PepperPluginInstanceImpl::Paint(WebCanvas* canvas, 601 void PepperPluginInstanceImpl::Paint(WebCanvas* canvas,
602 const gfx::Rect& plugin_rect, 602 const gfx::Rect& plugin_rect,
603 const gfx::Rect& paint_rect) { 603 const gfx::Rect& paint_rect) {
604 TRACE_EVENT0("ppapi", "PluginInstance::Paint"); 604 TRACE_EVENT0("ppapi", "PluginInstance::Paint");
605 if (module()->is_crashed()) { 605 if (module()->is_crashed()) {
606 // Crashed plugin painting. 606 // Crashed plugin painting.
607 if (!sad_plugin_) // Lazily initialize bitmap. 607 if (!sad_plugin_) // Lazily initialize bitmap.
(...skipping 15 matching lines...) Expand all
623 fullscreen_container_->InvalidateRect(rect); 623 fullscreen_container_->InvalidateRect(rect);
624 } else { 624 } else {
625 if (!container_ || 625 if (!container_ ||
626 view_data_.rect.size.width == 0 || view_data_.rect.size.height == 0) 626 view_data_.rect.size.width == 0 || view_data_.rect.size.height == 0)
627 return; // Nothing to do. 627 return; // Nothing to do.
628 if (rect.IsEmpty()) 628 if (rect.IsEmpty())
629 container_->invalidate(); 629 container_->invalidate();
630 else 630 else
631 container_->invalidateRect(rect); 631 container_->invalidateRect(rect);
632 } 632 }
633 if (texture_layer_) {
634 if (rect.IsEmpty()) {
635 texture_layer_->SetNeedsDisplay();
636 } else {
637 texture_layer_->SetNeedsDisplayRect(rect);
638 }
639 }
633 } 640 }
634 641
635 void PepperPluginInstanceImpl::ScrollRect(int dx, 642 void PepperPluginInstanceImpl::ScrollRect(int dx,
636 int dy, 643 int dy,
637 const gfx::Rect& rect) { 644 const gfx::Rect& rect) {
638 if (fullscreen_container_) { 645 if (texture_layer_) {
646 InvalidateRect(rect);
647 } else if (fullscreen_container_) {
639 fullscreen_container_->ScrollRect(dx, dy, rect); 648 fullscreen_container_->ScrollRect(dx, dy, rect);
640 } else { 649 } else {
641 if (full_frame_ && !IsViewAccelerated()) { 650 if (full_frame_ && !IsViewAccelerated()) {
642 container_->scrollRect(dx, dy, rect); 651 container_->scrollRect(dx, dy, rect);
643 } else { 652 } else {
644 // Can't do optimized scrolling since there could be other elements on top 653 // Can't do optimized scrolling since there could be other elements on top
645 // of us or the view renders via the accelerated compositor which is 654 // of us or the view renders via the accelerated compositor which is
646 // incompatible with the move and backfill scrolling model. 655 // incompatible with the move and backfill scrolling model.
647 InvalidateRect(rect); 656 InvalidateRect(rect);
648 } 657 }
(...skipping 1009 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 bool flash_fullscreen) { 1667 bool flash_fullscreen) {
1659 bool is_mouselock_pending = TrackedCallback::IsPending(lock_mouse_callback_); 1668 bool is_mouselock_pending = TrackedCallback::IsPending(lock_mouse_callback_);
1660 1669
1661 if (flash_fullscreen == flash_fullscreen_) { 1670 if (flash_fullscreen == flash_fullscreen_) {
1662 // Manually clear callback when fullscreen fails with mouselock pending. 1671 // Manually clear callback when fullscreen fails with mouselock pending.
1663 if (!flash_fullscreen && is_mouselock_pending) 1672 if (!flash_fullscreen && is_mouselock_pending)
1664 lock_mouse_callback_->Run(PP_ERROR_FAILED); 1673 lock_mouse_callback_->Run(PP_ERROR_FAILED);
1665 return; 1674 return;
1666 } 1675 }
1667 1676
1668 PPB_Graphics3D_Impl* graphics_3d = bound_graphics_3d_.get(); 1677 UpdateLayer();
1669 if (graphics_3d)
1670 UpdateLayer();
1671 1678
1672 bool old_plugin_focus = PluginHasFocus(); 1679 bool old_plugin_focus = PluginHasFocus();
1673 flash_fullscreen_ = flash_fullscreen; 1680 flash_fullscreen_ = flash_fullscreen;
1674 if (is_mouselock_pending && !IsMouseLocked()) { 1681 if (is_mouselock_pending && !IsMouseLocked()) {
1675 if (!IsProcessingUserGesture() && 1682 if (!IsProcessingUserGesture() &&
1676 !module_->permissions().HasPermission( 1683 !module_->permissions().HasPermission(
1677 ppapi::PERMISSION_BYPASS_USER_GESTURE)) { 1684 ppapi::PERMISSION_BYPASS_USER_GESTURE)) {
1678 lock_mouse_callback_->Run(PP_ERROR_NO_USER_GESTURE); 1685 lock_mouse_callback_->Run(PP_ERROR_NO_USER_GESTURE);
1679 } else { 1686 } else {
1680 // Open a user gesture here so the Webkit user gesture checks will succeed 1687 // Open a user gesture here so the Webkit user gesture checks will succeed
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1800 1807
1801 void PepperPluginInstanceImpl::UpdateLayer() { 1808 void PepperPluginInstanceImpl::UpdateLayer() {
1802 if (!container_) 1809 if (!container_)
1803 return; 1810 return;
1804 1811
1805 gpu::Mailbox mailbox; 1812 gpu::Mailbox mailbox;
1806 if (bound_graphics_3d_.get()) { 1813 if (bound_graphics_3d_.get()) {
1807 PlatformContext3D* context = bound_graphics_3d_->platform_context(); 1814 PlatformContext3D* context = bound_graphics_3d_->platform_context();
1808 context->GetBackingMailbox(&mailbox); 1815 context->GetBackingMailbox(&mailbox);
1809 } 1816 }
1810 bool want_layer = !mailbox.IsZero(); 1817 bool want_3d_layer = !mailbox.IsZero();
1818 bool want_2d_layer = bound_graphics_2d_platform_ &&
1819 CommandLine::ForCurrentProcess()->HasSwitch(
1820 switches::kEnableSoftwareCompositing);
1821 bool want_layer = want_3d_layer || want_2d_layer;
1811 1822
1812 if (want_layer == !!texture_layer_.get() && 1823 if ((want_layer == !!texture_layer_.get()) &&
1824 (want_3d_layer == layer_is_hardware_) &&
1813 layer_bound_to_fullscreen_ == !!fullscreen_container_) 1825 layer_bound_to_fullscreen_ == !!fullscreen_container_)
1814 return; 1826 return;
1815 1827
1816 if (texture_layer_.get()) { 1828 if (texture_layer_) {
1817 if (!layer_bound_to_fullscreen_) 1829 if (!layer_bound_to_fullscreen_)
1818 container_->setWebLayer(NULL); 1830 container_->setWebLayer(NULL);
1819 else if (fullscreen_container_) 1831 else if (fullscreen_container_)
1820 fullscreen_container_->SetLayer(NULL); 1832 fullscreen_container_->SetLayer(NULL);
1821 web_layer_.reset(); 1833 web_layer_.reset();
1822 texture_layer_ = NULL; 1834 texture_layer_ = NULL;
1823 } 1835 }
1824 if (want_layer) { 1836 if (want_layer) {
1825 DCHECK(bound_graphics_3d_.get()); 1837 bool opaque = false;
1826 texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL); 1838 if (want_3d_layer) {
1839 DCHECK(bound_graphics_3d_.get());
1840 texture_layer_ = cc::TextureLayer::CreateForMailbox(NULL);
1841 opaque = bound_graphics_3d_->IsOpaque();
1842 texture_layer_->SetTextureMailbox(
1843 cc::TextureMailbox(mailbox, base::Bind(&IgnoreCallback), 0));
1844 } else {
1845 DCHECK(bound_graphics_2d_platform_);
1846 texture_layer_ = cc::TextureLayer::CreateForMailbox(this);
1847 bound_graphics_2d_platform_->AttachedToNewLayer();
1848 opaque = bound_graphics_2d_platform_->IsAlwaysOpaque();
1849 texture_layer_->SetFlipped(false);
1850 }
1827 web_layer_.reset(new webkit::WebLayerImpl(texture_layer_)); 1851 web_layer_.reset(new webkit::WebLayerImpl(texture_layer_));
1828 if (fullscreen_container_) { 1852 if (fullscreen_container_) {
1829 fullscreen_container_->SetLayer(web_layer_.get()); 1853 fullscreen_container_->SetLayer(web_layer_.get());
1830 // Ignore transparency in fullscreen, since that's what Flash always 1854 // Ignore transparency in fullscreen, since that's what Flash always
1831 // wants to do, and that lets it not recreate a context if 1855 // wants to do, and that lets it not recreate a context if
1832 // wmode=transparent was specified. 1856 // wmode=transparent was specified.
1833 texture_layer_->SetContentsOpaque(true); 1857 texture_layer_->SetContentsOpaque(true);
1834 } else { 1858 } else {
1835 container_->setWebLayer(web_layer_.get()); 1859 container_->setWebLayer(web_layer_.get());
1836 texture_layer_->SetContentsOpaque(bound_graphics_3d_->IsOpaque()); 1860 texture_layer_->SetContentsOpaque(opaque);
1837 } 1861 }
1838 texture_layer_->SetTextureMailbox(
1839 cc::TextureMailbox(mailbox, base::Bind(&IgnoreCallback), 0));
1840 } 1862 }
1841 layer_bound_to_fullscreen_ = !!fullscreen_container_; 1863 layer_bound_to_fullscreen_ = !!fullscreen_container_;
1864 layer_is_hardware_ = want_3d_layer;
1865 }
1866
1867 unsigned PepperPluginInstanceImpl::PrepareTexture() {
1868 return 0;
1869 }
1870
1871 WebKit::WebGraphicsContext3D* PepperPluginInstanceImpl::Context3d() {
1872 return NULL;
1873 }
1874
1875 bool PepperPluginInstanceImpl::PrepareTextureMailbox(
1876 cc::TextureMailbox* mailbox,
1877 bool use_shared_memory) {
1878 if (!bound_graphics_2d_platform_)
1879 return false;
1880 return bound_graphics_2d_platform_->PrepareTextureMailbox(mailbox);
1842 } 1881 }
1843 1882
1844 void PepperPluginInstanceImpl::AddPluginObject(PluginObject* plugin_object) { 1883 void PepperPluginInstanceImpl::AddPluginObject(PluginObject* plugin_object) {
1845 DCHECK(live_plugin_objects_.find(plugin_object) == 1884 DCHECK(live_plugin_objects_.find(plugin_object) ==
1846 live_plugin_objects_.end()); 1885 live_plugin_objects_.end());
1847 live_plugin_objects_.insert(plugin_object); 1886 live_plugin_objects_.insert(plugin_object);
1848 } 1887 }
1849 1888
1850 void PepperPluginInstanceImpl::RemovePluginObject(PluginObject* plugin_object) { 1889 void PepperPluginInstanceImpl::RemovePluginObject(PluginObject* plugin_object) {
1851 // Don't actually verify that the object is in the set since during module 1890 // Don't actually verify that the object is in the set since during module
(...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after
2906 // Running out-of-process. Initiate an IPC call to notify the plugin 2945 // Running out-of-process. Initiate an IPC call to notify the plugin
2907 // process. 2946 // process.
2908 ppapi::proxy::HostDispatcher* dispatcher = 2947 ppapi::proxy::HostDispatcher* dispatcher =
2909 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance()); 2948 ppapi::proxy::HostDispatcher::GetForInstance(pp_instance());
2910 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad( 2949 dispatcher->Send(new PpapiMsg_PPPInstance_HandleDocumentLoad(
2911 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data)); 2950 ppapi::API_ID_PPP_INSTANCE, pp_instance(), pending_host_id, data));
2912 } 2951 }
2913 } 2952 }
2914 2953
2915 } // namespace content 2954 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_plugin_instance_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698