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

Side by Side Diff: webkit/plugins/ppapi/ppapi_plugin_instance.cc

Issue 11053003: Migrate Graphics2D to new design. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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
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 "webkit/plugins/ppapi/ppapi_plugin_instance.h" 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.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/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 #include "webkit/plugins/ppapi/content_decryptor_delegate.h" 70 #include "webkit/plugins/ppapi/content_decryptor_delegate.h"
71 #include "webkit/plugins/ppapi/event_conversion.h" 71 #include "webkit/plugins/ppapi/event_conversion.h"
72 #include "webkit/plugins/ppapi/fullscreen_container.h" 72 #include "webkit/plugins/ppapi/fullscreen_container.h"
73 #include "webkit/plugins/ppapi/gfx_conversion.h" 73 #include "webkit/plugins/ppapi/gfx_conversion.h"
74 #include "webkit/plugins/ppapi/host_globals.h" 74 #include "webkit/plugins/ppapi/host_globals.h"
75 #include "webkit/plugins/ppapi/message_channel.h" 75 #include "webkit/plugins/ppapi/message_channel.h"
76 #include "webkit/plugins/ppapi/npapi_glue.h" 76 #include "webkit/plugins/ppapi/npapi_glue.h"
77 #include "webkit/plugins/ppapi/plugin_module.h" 77 #include "webkit/plugins/ppapi/plugin_module.h"
78 #include "webkit/plugins/ppapi/plugin_object.h" 78 #include "webkit/plugins/ppapi/plugin_object.h"
79 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" 79 #include "webkit/plugins/ppapi/ppb_buffer_impl.h"
80 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h"
81 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" 80 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h"
82 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" 81 #include "webkit/plugins/ppapi/ppb_image_data_impl.h"
83 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" 82 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h"
84 #include "webkit/plugins/ppapi/ppp_pdf.h" 83 #include "webkit/plugins/ppapi/ppp_pdf.h"
85 #include "webkit/plugins/ppapi/url_request_info_util.h" 84 #include "webkit/plugins/ppapi/url_request_info_util.h"
86 #include "webkit/plugins/sad_plugin.h" 85 #include "webkit/plugins/sad_plugin.h"
87 86
88 #if defined(OS_MACOSX) 87 #if defined(OS_MACOSX)
89 #include "printing/metafile_impl.h" 88 #include "printing/metafile_impl.h"
90 #if !defined(USE_SKIA) 89 #if !defined(USE_SKIA)
(...skipping 15 matching lines...) Expand all
106 #include "ui/gfx/codec/jpeg_codec.h" 105 #include "ui/gfx/codec/jpeg_codec.h"
107 #include "ui/gfx/gdi_util.h" 106 #include "ui/gfx/gdi_util.h"
108 #endif 107 #endif
109 108
110 using base::StringPrintf; 109 using base::StringPrintf;
111 using ppapi::InputEventData; 110 using ppapi::InputEventData;
112 using ppapi::PpapiGlobals; 111 using ppapi::PpapiGlobals;
113 using ppapi::PPB_InputEvent_Shared; 112 using ppapi::PPB_InputEvent_Shared;
114 using ppapi::PPB_View_Shared; 113 using ppapi::PPB_View_Shared;
115 using ppapi::PPP_Instance_Combined; 114 using ppapi::PPP_Instance_Combined;
115 using ppapi::Resource;
116 using ppapi::ScopedPPResource; 116 using ppapi::ScopedPPResource;
117 using ppapi::StringVar; 117 using ppapi::StringVar;
118 using ppapi::TrackedCallback; 118 using ppapi::TrackedCallback;
119 using ppapi::thunk::EnterResourceNoLock; 119 using ppapi::thunk::EnterResourceNoLock;
120 using ppapi::thunk::PPB_Buffer_API; 120 using ppapi::thunk::PPB_Buffer_API;
121 using ppapi::thunk::PPB_Graphics2D_API; 121 using ppapi::thunk::PPB_Graphics2D_API;
122 using ppapi::thunk::PPB_Graphics3D_API; 122 using ppapi::thunk::PPB_Graphics3D_API;
123 using ppapi::thunk::PPB_ImageData_API; 123 using ppapi::thunk::PPB_ImageData_API;
124 using ppapi::Var; 124 using ppapi::Var;
125 using ppapi::ArrayBufferVar; 125 using ppapi::ArrayBufferVar;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 PluginModule* module, 333 PluginModule* module,
334 ::ppapi::PPP_Instance_Combined* instance_interface) 334 ::ppapi::PPP_Instance_Combined* instance_interface)
335 : delegate_(delegate), 335 : delegate_(delegate),
336 module_(module), 336 module_(module),
337 instance_interface_(instance_interface), 337 instance_interface_(instance_interface),
338 pp_instance_(0), 338 pp_instance_(0),
339 container_(NULL), 339 container_(NULL),
340 full_frame_(false), 340 full_frame_(false),
341 sent_initial_did_change_view_(false), 341 sent_initial_did_change_view_(false),
342 view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 342 view_change_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
343 bound_graphics_2d_platform_(NULL),
343 has_webkit_focus_(false), 344 has_webkit_focus_(false),
344 has_content_area_focus_(false), 345 has_content_area_focus_(false),
345 find_identifier_(-1), 346 find_identifier_(-1),
346 plugin_find_interface_(NULL), 347 plugin_find_interface_(NULL),
347 plugin_input_event_interface_(NULL), 348 plugin_input_event_interface_(NULL),
348 plugin_messaging_interface_(NULL), 349 plugin_messaging_interface_(NULL),
349 plugin_mouse_lock_interface_(NULL), 350 plugin_mouse_lock_interface_(NULL),
350 plugin_pdf_interface_(NULL), 351 plugin_pdf_interface_(NULL),
351 plugin_private_interface_(NULL), 352 plugin_private_interface_(NULL),
352 plugin_selection_interface_(NULL), 353 plugin_selection_interface_(NULL),
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 TRACE_EVENT0("ppapi", "PluginInstance::Paint"); 451 TRACE_EVENT0("ppapi", "PluginInstance::Paint");
451 if (module()->is_crashed()) { 452 if (module()->is_crashed()) {
452 // Crashed plugin painting. 453 // Crashed plugin painting.
453 if (!sad_plugin_) // Lazily initialize bitmap. 454 if (!sad_plugin_) // Lazily initialize bitmap.
454 sad_plugin_ = delegate_->GetSadPluginBitmap(); 455 sad_plugin_ = delegate_->GetSadPluginBitmap();
455 if (sad_plugin_) 456 if (sad_plugin_)
456 webkit::PaintSadPlugin(canvas, plugin_rect, *sad_plugin_); 457 webkit::PaintSadPlugin(canvas, plugin_rect, *sad_plugin_);
457 return; 458 return;
458 } 459 }
459 460
460 PPB_Graphics2D_Impl* bound_graphics_2d = GetBoundGraphics2D(); 461 PluginDelegate::PlatformGraphics2D* bound_graphics_2d = GetBoundGraphics2D();
461 if (bound_graphics_2d) 462 if (bound_graphics_2d)
462 bound_graphics_2d->Paint(canvas, plugin_rect, paint_rect); 463 bound_graphics_2d->Paint(canvas, plugin_rect, paint_rect);
463 } 464 }
464 465
465 void PluginInstance::InvalidateRect(const gfx::Rect& rect) { 466 void PluginInstance::InvalidateRect(const gfx::Rect& rect) {
466 if (fullscreen_container_) { 467 if (fullscreen_container_) {
467 if (rect.IsEmpty()) 468 if (rect.IsEmpty())
468 fullscreen_container_->Invalidate(); 469 fullscreen_container_->Invalidate();
469 else 470 else
470 fullscreen_container_->InvalidateRect(rect); 471 fullscreen_container_->InvalidateRect(rect);
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 } 918 }
918 919
919 bool PluginInstance::GetBitmapForOptimizedPluginPaint( 920 bool PluginInstance::GetBitmapForOptimizedPluginPaint(
920 const gfx::Rect& paint_bounds, 921 const gfx::Rect& paint_bounds,
921 TransportDIB** dib, 922 TransportDIB** dib,
922 gfx::Rect* location, 923 gfx::Rect* location,
923 gfx::Rect* clip, 924 gfx::Rect* clip,
924 float* scale_factor) { 925 float* scale_factor) {
925 if (!always_on_top_) 926 if (!always_on_top_)
926 return false; 927 return false;
927 if (!GetBoundGraphics2D() || !GetBoundGraphics2D()->is_always_opaque()) 928 if (!GetBoundGraphics2D() || !GetBoundGraphics2D()->IsAlwaysOpaque())
928 return false; 929 return false;
929 930
930 // We specifically want to compare against the area covered by the backing 931 // We specifically want to compare against the area covered by the backing
931 // store when seeing if we cover the given paint bounds, since the backing 932 // store when seeing if we cover the given paint bounds, since the backing
932 // store could be smaller than the declared plugin area. 933 // store could be smaller than the declared plugin area.
933 PPB_ImageData_Impl* image_data = GetBoundGraphics2D()->image_data(); 934 PPB_ImageData_Impl* image_data = GetBoundGraphics2D()->ImageData();
934 // ImageDatas created by NaCl don't have a PlatformImage, so can't be 935 // ImageDatas created by NaCl don't have a PlatformImage, so can't be
935 // optimized this way. 936 // optimized this way.
936 if (!image_data->PlatformImage()) 937 if (!image_data->PlatformImage())
937 return false; 938 return false;
938 939
939 gfx::Point plugin_origin = PP_ToGfxPoint(view_data_.rect.point); 940 gfx::Point plugin_origin = PP_ToGfxPoint(view_data_.rect.point);
940 gfx::Vector2d plugin_offset = plugin_origin.OffsetFromOrigin(); 941 gfx::Vector2d plugin_offset = plugin_origin.OffsetFromOrigin();
941 // Convert |paint_bounds| to be relative to the left-top corner of the plugin. 942 // Convert |paint_bounds| to be relative to the left-top corner of the plugin.
942 gfx::Rect relative_paint_bounds(paint_bounds); 943 gfx::Rect relative_paint_bounds(paint_bounds);
943 relative_paint_bounds.Offset(-plugin_offset); 944 relative_paint_bounds.Offset(-plugin_offset);
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
1675 skia::EndPlatformPaint(canvas); 1676 skia::EndPlatformPaint(canvas);
1676 } 1677 }
1677 #endif // defined(OS_WIN) 1678 #endif // defined(OS_WIN)
1678 1679
1679 return ret; 1680 return ret;
1680 #else // defined(ENABLE_PRINTING) 1681 #else // defined(ENABLE_PRINTING)
1681 return false; 1682 return false;
1682 #endif 1683 #endif
1683 } 1684 }
1684 1685
1685 PPB_Graphics2D_Impl* PluginInstance::GetBoundGraphics2D() const { 1686 PluginDelegate::PlatformGraphics2D* PluginInstance::GetBoundGraphics2D() const {
1686 if (bound_graphics_.get() == NULL) 1687 return bound_graphics_2d_platform_;
1687 return NULL;
1688
1689 if (bound_graphics_->AsPPB_Graphics2D_API())
1690 return static_cast<PPB_Graphics2D_Impl*>(bound_graphics_.get());
1691 return NULL;
1692 } 1688 }
1693 1689
1694 PPB_Graphics3D_Impl* PluginInstance::GetBoundGraphics3D() const { 1690 PPB_Graphics3D_Impl* PluginInstance::GetBoundGraphics3D() const {
1695 if (bound_graphics_.get() == NULL) 1691 if (bound_graphics_3d_.get() == NULL)
1696 return NULL; 1692 return NULL;
1697 1693 return static_cast<PPB_Graphics3D_Impl*>(bound_graphics_3d_.get());
1698 if (bound_graphics_->AsPPB_Graphics3D_API())
1699 return static_cast<PPB_Graphics3D_Impl*>(bound_graphics_.get());
1700 return NULL;
1701 } 1694 }
1702 1695
1703 void PluginInstance::setBackingTextureId(unsigned int id, bool is_opaque) { 1696 void PluginInstance::setBackingTextureId(unsigned int id, bool is_opaque) {
1704 // If we have a fullscreen_container_ (under PPB_FlashFullscreen) 1697 // If we have a fullscreen_container_ (under PPB_FlashFullscreen)
1705 // or desired_fullscreen_state is true (under PPB_Fullscreen), 1698 // or desired_fullscreen_state is true (under PPB_Fullscreen),
1706 // then the plugin is fullscreen or transitioning to fullscreen 1699 // then the plugin is fullscreen or transitioning to fullscreen
1707 // and the parent context is not the one for the browser page, 1700 // and the parent context is not the one for the browser page,
1708 // but for the fullscreen window, and so the parent texture ID 1701 // but for the fullscreen window, and so the parent texture ID
1709 // doesn't correspond to anything in the page's context. 1702 // doesn't correspond to anything in the page's context.
1710 // 1703 //
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1851 // Do nothing so that the pending user gesture will stay open for 1844 // Do nothing so that the pending user gesture will stay open for
1852 // kUserGestureDurationInSeconds. 1845 // kUserGestureDurationInSeconds.
1853 // TODO(yzshen): remove the code for closing pending user gesture. 1846 // TODO(yzshen): remove the code for closing pending user gesture.
1854 } 1847 }
1855 1848
1856 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, 1849 PP_Bool PluginInstance::BindGraphics(PP_Instance instance,
1857 PP_Resource device) { 1850 PP_Resource device) {
1858 TRACE_EVENT0("ppapi", "PluginInstance::BindGraphics"); 1851 TRACE_EVENT0("ppapi", "PluginInstance::BindGraphics");
1859 // The Graphics3D instance can't be destroyed until we call 1852 // The Graphics3D instance can't be destroyed until we call
1860 // setBackingTextureId. 1853 // setBackingTextureId.
1861 scoped_refptr< ::ppapi::Resource> old_graphics = bound_graphics_; 1854 scoped_refptr< ::ppapi::Resource> old_graphics = bound_graphics_3d_;
1862 if (bound_graphics_.get()) { 1855 if (bound_graphics_3d_.get()) {
1863 if (GetBoundGraphics2D()) { 1856 if (GetBoundGraphics3D()) {
1864 GetBoundGraphics2D()->BindToInstance(NULL);
1865 } else if (GetBoundGraphics3D()) {
1866 GetBoundGraphics3D()->BindToInstance(false); 1857 GetBoundGraphics3D()->BindToInstance(false);
1867 } 1858 }
1868 bound_graphics_ = NULL; 1859 bound_graphics_3d_ = NULL;
1860 }
1861 if (bound_graphics_2d_platform_) {
1862 GetBoundGraphics2D()->BindToInstance(NULL);
1863 bound_graphics_2d_platform_ = NULL;
1869 } 1864 }
1870 1865
1871 // Special-case clearing the current device. 1866 // Special-case clearing the current device.
1872 if (!device) { 1867 if (!device) {
1873 setBackingTextureId(0, false); 1868 setBackingTextureId(0, false);
1874 InvalidateRect(gfx::Rect()); 1869 InvalidateRect(gfx::Rect());
1875 return PP_TRUE; 1870 return PP_TRUE;
1876 } 1871 }
1877 1872
1878 // Refuse to bind if in transition to fullscreen with PPB_FlashFullscreen or 1873 // Refuse to bind if in transition to fullscreen with PPB_FlashFullscreen or
1879 // to/from fullscreen with PPB_Fullscreen. 1874 // to/from fullscreen with PPB_Fullscreen.
1880 if ((fullscreen_container_ && !flash_fullscreen_) || 1875 if ((fullscreen_container_ && !flash_fullscreen_) ||
1881 desired_fullscreen_state_ != view_data_.is_fullscreen) 1876 desired_fullscreen_state_ != view_data_.is_fullscreen)
1882 return PP_FALSE; 1877 return PP_FALSE;
1883 1878
1884 EnterResourceNoLock<PPB_Graphics2D_API> enter_2d(device, false); 1879 bound_graphics_2d_platform_ = delegate_->GetGraphics2D(this, device);
1885 PPB_Graphics2D_Impl* graphics_2d = enter_2d.succeeded() ?
1886 static_cast<PPB_Graphics2D_Impl*>(enter_2d.object()) : NULL;
1887 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false); 1880 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false);
1888 PPB_Graphics3D_Impl* graphics_3d = enter_3d.succeeded() ? 1881 PPB_Graphics3D_Impl* graphics_3d = enter_3d.succeeded() ?
1889 static_cast<PPB_Graphics3D_Impl*>(enter_3d.object()) : NULL; 1882 static_cast<PPB_Graphics3D_Impl*>(enter_3d.object()) : NULL;
1890 1883
1891 if (graphics_2d) { 1884 if (bound_graphics_2d_platform_) {
1892 if (graphics_2d->pp_instance() != pp_instance()) 1885 if (!bound_graphics_2d_platform_->BindToInstance(this))
1893 return PP_FALSE; // Can't bind other instance's contexts.
1894 if (!graphics_2d->BindToInstance(this))
1895 return PP_FALSE; // Can't bind to more than one instance. 1886 return PP_FALSE; // Can't bind to more than one instance.
1896 1887
1897 bound_graphics_ = graphics_2d; 1888 setBackingTextureId(0, bound_graphics_2d_platform_->IsAlwaysOpaque());
1898 setBackingTextureId(0, graphics_2d->is_always_opaque());
1899 // BindToInstance will have invalidated the plugin if necessary. 1889 // BindToInstance will have invalidated the plugin if necessary.
1900 } else if (graphics_3d) { 1890 } else if (graphics_3d) {
1901 // Make sure graphics can only be bound to the instance it is 1891 // Make sure graphics can only be bound to the instance it is
1902 // associated with. 1892 // associated with.
1903 if (graphics_3d->pp_instance() != pp_instance()) 1893 if (graphics_3d->pp_instance() != pp_instance())
1904 return PP_FALSE; 1894 return PP_FALSE;
1905 if (!graphics_3d->BindToInstance(true)) 1895 if (!graphics_3d->BindToInstance(true))
1906 return PP_FALSE; 1896 return PP_FALSE;
1907 1897
1908 bound_graphics_ = graphics_3d; 1898 bound_graphics_3d_ = graphics_3d;
1909 setBackingTextureId(graphics_3d->GetBackingTextureId(), 1899 setBackingTextureId(graphics_3d->GetBackingTextureId(),
1910 graphics_3d->IsOpaque()); 1900 graphics_3d->IsOpaque());
1911 } else { 1901 } else {
1912 // The device is not a valid resource type. 1902 // The device is not a valid resource type.
1913 return PP_FALSE; 1903 return PP_FALSE;
1914 } 1904 }
1915 1905
1916 return PP_TRUE; 1906 return PP_TRUE;
1917 } 1907 }
1918 1908
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
2475 screen_size_for_fullscreen_ = gfx::Size(); 2465 screen_size_for_fullscreen_ = gfx::Size();
2476 WebElement element = container_->element(); 2466 WebElement element = container_->element();
2477 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2467 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2478 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2468 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2479 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2469 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2480 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2470 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2481 } 2471 }
2482 2472
2483 } // namespace ppapi 2473 } // namespace ppapi
2484 } // namespace webkit 2474 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698