OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 #include "webkit/plugins/ppapi/host_globals.h" | 65 #include "webkit/plugins/ppapi/host_globals.h" |
66 #include "webkit/plugins/ppapi/message_channel.h" | 66 #include "webkit/plugins/ppapi/message_channel.h" |
67 #include "webkit/plugins/ppapi/npapi_glue.h" | 67 #include "webkit/plugins/ppapi/npapi_glue.h" |
68 #include "webkit/plugins/ppapi/plugin_delegate.h" | 68 #include "webkit/plugins/ppapi/plugin_delegate.h" |
69 #include "webkit/plugins/ppapi/plugin_module.h" | 69 #include "webkit/plugins/ppapi/plugin_module.h" |
70 #include "webkit/plugins/ppapi/plugin_object.h" | 70 #include "webkit/plugins/ppapi/plugin_object.h" |
71 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | 71 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
72 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" | 72 #include "webkit/plugins/ppapi/ppb_graphics_2d_impl.h" |
73 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" | 73 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" |
74 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" | 74 #include "webkit/plugins/ppapi/ppb_image_data_impl.h" |
75 #include "webkit/plugins/ppapi/ppb_surface_3d_impl.h" | |
76 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" | 75 #include "webkit/plugins/ppapi/ppb_url_loader_impl.h" |
77 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" | 76 #include "webkit/plugins/ppapi/ppb_url_request_info_impl.h" |
78 #include "webkit/plugins/ppapi/ppp_pdf.h" | 77 #include "webkit/plugins/ppapi/ppp_pdf.h" |
79 #include "webkit/plugins/ppapi/string.h" | 78 #include "webkit/plugins/ppapi/string.h" |
80 #include "webkit/plugins/sad_plugin.h" | 79 #include "webkit/plugins/sad_plugin.h" |
81 | 80 |
82 #if defined(OS_MACOSX) | 81 #if defined(OS_MACOSX) |
83 #include "base/mac/mac_util.h" | 82 #include "base/mac/mac_util.h" |
84 #include "base/mac/scoped_cftyperef.h" | 83 #include "base/mac/scoped_cftyperef.h" |
85 #include "printing/metafile_impl.h" | 84 #include "printing/metafile_impl.h" |
(...skipping 18 matching lines...) Expand all Loading... |
104 using ppapi::InputEventData; | 103 using ppapi::InputEventData; |
105 using ppapi::InputEventImpl; | 104 using ppapi::InputEventImpl; |
106 using ppapi::PpapiGlobals; | 105 using ppapi::PpapiGlobals; |
107 using ppapi::StringVar; | 106 using ppapi::StringVar; |
108 using ppapi::thunk::EnterResourceNoLock; | 107 using ppapi::thunk::EnterResourceNoLock; |
109 using ppapi::thunk::PPB_Buffer_API; | 108 using ppapi::thunk::PPB_Buffer_API; |
110 using ppapi::thunk::PPB_Graphics2D_API; | 109 using ppapi::thunk::PPB_Graphics2D_API; |
111 using ppapi::thunk::PPB_Graphics3D_API; | 110 using ppapi::thunk::PPB_Graphics3D_API; |
112 using ppapi::thunk::PPB_ImageData_API; | 111 using ppapi::thunk::PPB_ImageData_API; |
113 using ppapi::thunk::PPB_Instance_FunctionAPI; | 112 using ppapi::thunk::PPB_Instance_FunctionAPI; |
114 using ppapi::thunk::PPB_Surface3D_API; | |
115 using ppapi::Var; | 113 using ppapi::Var; |
116 using WebKit::WebBindings; | 114 using WebKit::WebBindings; |
117 using WebKit::WebCanvas; | 115 using WebKit::WebCanvas; |
118 using WebKit::WebConsoleMessage; | 116 using WebKit::WebConsoleMessage; |
119 using WebKit::WebCursorInfo; | 117 using WebKit::WebCursorInfo; |
120 using WebKit::WebDocument; | 118 using WebKit::WebDocument; |
121 using WebKit::WebFrame; | 119 using WebKit::WebFrame; |
122 using WebKit::WebElement; | 120 using WebKit::WebElement; |
123 using WebKit::WebInputEvent; | 121 using WebKit::WebInputEvent; |
124 using WebKit::WebPluginContainer; | 122 using WebKit::WebPluginContainer; |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 // of us or the view renders via the accelerated compositor which is | 400 // of us or the view renders via the accelerated compositor which is |
403 // incompatible with the move and backfill scrolling model. | 401 // incompatible with the move and backfill scrolling model. |
404 InvalidateRect(rect); | 402 InvalidateRect(rect); |
405 } | 403 } |
406 } | 404 } |
407 } | 405 } |
408 | 406 |
409 unsigned PluginInstance::GetBackingTextureId() { | 407 unsigned PluginInstance::GetBackingTextureId() { |
410 if (GetBoundGraphics3D()) | 408 if (GetBoundGraphics3D()) |
411 return GetBoundGraphics3D()->GetBackingTextureId(); | 409 return GetBoundGraphics3D()->GetBackingTextureId(); |
412 else if (GetBoundSurface3D()) | |
413 return GetBoundSurface3D()->GetBackingTextureId(); | |
414 | 410 |
415 return 0; | 411 return 0; |
416 } | 412 } |
417 | 413 |
418 void PluginInstance::CommitBackingTexture() { | 414 void PluginInstance::CommitBackingTexture() { |
419 if (fullscreen_container_) | 415 if (fullscreen_container_) |
420 fullscreen_container_->Invalidate(); | 416 fullscreen_container_->Invalidate(); |
421 else if (container_) | 417 else if (container_) |
422 container_->commitBackingTexture(); | 418 container_->commitBackingTexture(); |
423 } | 419 } |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 instance_interface_->DidChangeFocus(pp_instance(), | 792 instance_interface_->DidChangeFocus(pp_instance(), |
797 PP_FromBool(PluginHasFocus())); | 793 PP_FromBool(PluginHasFocus())); |
798 } | 794 } |
799 } | 795 } |
800 | 796 |
801 void PluginInstance::ViewInitiatedPaint() { | 797 void PluginInstance::ViewInitiatedPaint() { |
802 if (GetBoundGraphics2D()) | 798 if (GetBoundGraphics2D()) |
803 GetBoundGraphics2D()->ViewInitiatedPaint(); | 799 GetBoundGraphics2D()->ViewInitiatedPaint(); |
804 else if (GetBoundGraphics3D()) | 800 else if (GetBoundGraphics3D()) |
805 GetBoundGraphics3D()->ViewInitiatedPaint(); | 801 GetBoundGraphics3D()->ViewInitiatedPaint(); |
806 else if (GetBoundSurface3D()) | |
807 GetBoundSurface3D()->ViewInitiatedPaint(); | |
808 } | 802 } |
809 | 803 |
810 void PluginInstance::ViewFlushedPaint() { | 804 void PluginInstance::ViewFlushedPaint() { |
811 // Keep a reference on the stack. See NOTE above. | 805 // Keep a reference on the stack. See NOTE above. |
812 scoped_refptr<PluginInstance> ref(this); | 806 scoped_refptr<PluginInstance> ref(this); |
813 if (GetBoundGraphics2D()) | 807 if (GetBoundGraphics2D()) |
814 GetBoundGraphics2D()->ViewFlushedPaint(); | 808 GetBoundGraphics2D()->ViewFlushedPaint(); |
815 else if (GetBoundGraphics3D()) | 809 else if (GetBoundGraphics3D()) |
816 GetBoundGraphics3D()->ViewFlushedPaint(); | 810 GetBoundGraphics3D()->ViewFlushedPaint(); |
817 else if (GetBoundSurface3D()) | |
818 GetBoundSurface3D()->ViewFlushedPaint(); | |
819 } | 811 } |
820 | 812 |
821 bool PluginInstance::GetBitmapForOptimizedPluginPaint( | 813 bool PluginInstance::GetBitmapForOptimizedPluginPaint( |
822 const gfx::Rect& paint_bounds, | 814 const gfx::Rect& paint_bounds, |
823 TransportDIB** dib, | 815 TransportDIB** dib, |
824 gfx::Rect* location, | 816 gfx::Rect* location, |
825 gfx::Rect* clip) { | 817 gfx::Rect* clip) { |
826 if (!always_on_top_) | 818 if (!always_on_top_) |
827 return false; | 819 return false; |
828 if (!GetBoundGraphics2D() || !GetBoundGraphics2D()->is_always_opaque()) | 820 if (!GetBoundGraphics2D() || !GetBoundGraphics2D()->is_always_opaque()) |
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1537 | 1529 |
1538 PPB_Graphics3D_Impl* PluginInstance::GetBoundGraphics3D() const { | 1530 PPB_Graphics3D_Impl* PluginInstance::GetBoundGraphics3D() const { |
1539 if (bound_graphics_.get() == NULL) | 1531 if (bound_graphics_.get() == NULL) |
1540 return NULL; | 1532 return NULL; |
1541 | 1533 |
1542 if (bound_graphics_->AsPPB_Graphics3D_API()) | 1534 if (bound_graphics_->AsPPB_Graphics3D_API()) |
1543 return static_cast<PPB_Graphics3D_Impl*>(bound_graphics_.get()); | 1535 return static_cast<PPB_Graphics3D_Impl*>(bound_graphics_.get()); |
1544 return NULL; | 1536 return NULL; |
1545 } | 1537 } |
1546 | 1538 |
1547 PPB_Surface3D_Impl* PluginInstance::GetBoundSurface3D() const { | |
1548 if (bound_graphics_.get() == NULL) | |
1549 return NULL; | |
1550 | |
1551 if (bound_graphics_->AsPPB_Surface3D_API()) | |
1552 return static_cast<PPB_Surface3D_Impl*>(bound_graphics_.get()); | |
1553 return NULL; | |
1554 } | |
1555 | |
1556 void PluginInstance::setBackingTextureId(unsigned int id) { | 1539 void PluginInstance::setBackingTextureId(unsigned int id) { |
1557 // If we have a fullscreen_container_ (under PPB_FlashFullscreen) | 1540 // If we have a fullscreen_container_ (under PPB_FlashFullscreen) |
1558 // or desired_fullscreen_state is true (under PPB_Fullscreen), | 1541 // or desired_fullscreen_state is true (under PPB_Fullscreen), |
1559 // then the plugin is fullscreen or transitioning to fullscreen | 1542 // then the plugin is fullscreen or transitioning to fullscreen |
1560 // and the parent context is not the one for the browser page, | 1543 // and the parent context is not the one for the browser page, |
1561 // but for the fullscreen window, and so the parent texture ID | 1544 // but for the fullscreen window, and so the parent texture ID |
1562 // doesn't correspond to anything in the page's context. | 1545 // doesn't correspond to anything in the page's context. |
1563 // | 1546 // |
1564 // TODO(alokp): It would be better at some point to have the equivalent | 1547 // TODO(alokp): It would be better at some point to have the equivalent |
1565 // in the FullscreenContainer so that we don't need to poll | 1548 // in the FullscreenContainer so that we don't need to poll |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 return this; | 1606 return this; |
1624 } | 1607 } |
1625 | 1608 |
1626 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, | 1609 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, |
1627 PP_Resource device) { | 1610 PP_Resource device) { |
1628 if (bound_graphics_.get()) { | 1611 if (bound_graphics_.get()) { |
1629 if (GetBoundGraphics2D()) { | 1612 if (GetBoundGraphics2D()) { |
1630 GetBoundGraphics2D()->BindToInstance(NULL); | 1613 GetBoundGraphics2D()->BindToInstance(NULL); |
1631 } else if (GetBoundGraphics3D()) { | 1614 } else if (GetBoundGraphics3D()) { |
1632 GetBoundGraphics3D()->BindToInstance(false); | 1615 GetBoundGraphics3D()->BindToInstance(false); |
1633 } else if (GetBoundSurface3D()) { | |
1634 GetBoundSurface3D()->BindToInstance(false); | |
1635 } | 1616 } |
1636 bound_graphics_ = NULL; | 1617 bound_graphics_ = NULL; |
1637 } | 1618 } |
1638 | 1619 |
1639 // Special-case clearing the current device. | 1620 // Special-case clearing the current device. |
1640 if (!device) { | 1621 if (!device) { |
1641 setBackingTextureId(0); | 1622 setBackingTextureId(0); |
1642 InvalidateRect(gfx::Rect()); | 1623 InvalidateRect(gfx::Rect()); |
1643 return PP_TRUE; | 1624 return PP_TRUE; |
1644 } | 1625 } |
1645 | 1626 |
1646 // Refuse to bind if in transition to fullscreen with PPB_FlashFullscreen or | 1627 // Refuse to bind if in transition to fullscreen with PPB_FlashFullscreen or |
1647 // to/from fullscreen with PPB_Fullscreen. | 1628 // to/from fullscreen with PPB_Fullscreen. |
1648 if ((fullscreen_container_ && !flash_fullscreen_) || | 1629 if ((fullscreen_container_ && !flash_fullscreen_) || |
1649 desired_fullscreen_state_ != fullscreen_) | 1630 desired_fullscreen_state_ != fullscreen_) |
1650 return PP_FALSE; | 1631 return PP_FALSE; |
1651 | 1632 |
1652 EnterResourceNoLock<PPB_Graphics2D_API> enter_2d(device, false); | 1633 EnterResourceNoLock<PPB_Graphics2D_API> enter_2d(device, false); |
1653 PPB_Graphics2D_Impl* graphics_2d = enter_2d.succeeded() ? | 1634 PPB_Graphics2D_Impl* graphics_2d = enter_2d.succeeded() ? |
1654 static_cast<PPB_Graphics2D_Impl*>(enter_2d.object()) : NULL; | 1635 static_cast<PPB_Graphics2D_Impl*>(enter_2d.object()) : NULL; |
1655 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false); | 1636 EnterResourceNoLock<PPB_Graphics3D_API> enter_3d(device, false); |
1656 PPB_Graphics3D_Impl* graphics_3d = enter_3d.succeeded() ? | 1637 PPB_Graphics3D_Impl* graphics_3d = enter_3d.succeeded() ? |
1657 static_cast<PPB_Graphics3D_Impl*>(enter_3d.object()) : NULL; | 1638 static_cast<PPB_Graphics3D_Impl*>(enter_3d.object()) : NULL; |
1658 EnterResourceNoLock<PPB_Surface3D_API> enter_surface_3d(device, false); | |
1659 PPB_Surface3D_Impl* surface_3d = enter_surface_3d.succeeded() ? | |
1660 static_cast<PPB_Surface3D_Impl*>(enter_surface_3d.object()) : NULL; | |
1661 | 1639 |
1662 if (graphics_2d) { | 1640 if (graphics_2d) { |
1663 if (graphics_2d->pp_instance() != pp_instance()) | 1641 if (graphics_2d->pp_instance() != pp_instance()) |
1664 return PP_FALSE; // Can't bind other instance's contexts. | 1642 return PP_FALSE; // Can't bind other instance's contexts. |
1665 if (!graphics_2d->BindToInstance(this)) | 1643 if (!graphics_2d->BindToInstance(this)) |
1666 return PP_FALSE; // Can't bind to more than one instance. | 1644 return PP_FALSE; // Can't bind to more than one instance. |
1667 | 1645 |
1668 bound_graphics_ = graphics_2d; | 1646 bound_graphics_ = graphics_2d; |
1669 setBackingTextureId(0); | 1647 setBackingTextureId(0); |
1670 // BindToInstance will have invalidated the plugin if necessary. | 1648 // BindToInstance will have invalidated the plugin if necessary. |
1671 } else if (graphics_3d) { | 1649 } else if (graphics_3d) { |
1672 // Make sure graphics can only be bound to the instance it is | 1650 // Make sure graphics can only be bound to the instance it is |
1673 // associated with. | 1651 // associated with. |
1674 if (graphics_3d->pp_instance() != pp_instance()) | 1652 if (graphics_3d->pp_instance() != pp_instance()) |
1675 return PP_FALSE; | 1653 return PP_FALSE; |
1676 if (!graphics_3d->BindToInstance(true)) | 1654 if (!graphics_3d->BindToInstance(true)) |
1677 return PP_FALSE; | 1655 return PP_FALSE; |
1678 | 1656 |
1679 bound_graphics_ = graphics_3d; | 1657 bound_graphics_ = graphics_3d; |
1680 setBackingTextureId(graphics_3d->GetBackingTextureId()); | 1658 setBackingTextureId(graphics_3d->GetBackingTextureId()); |
1681 } else if (surface_3d) { | |
1682 // Make sure graphics can only be bound to the instance it is | |
1683 // associated with. | |
1684 if (surface_3d->pp_instance() != pp_instance()) | |
1685 return PP_FALSE; | |
1686 if (!surface_3d->BindToInstance(true)) | |
1687 return PP_FALSE; | |
1688 | |
1689 bound_graphics_ = surface_3d; | |
1690 setBackingTextureId(surface_3d->GetBackingTextureId()); | |
1691 } else { | 1659 } else { |
1692 // The device is not a valid resource type. | 1660 // The device is not a valid resource type. |
1693 return PP_FALSE; | 1661 return PP_FALSE; |
1694 } | 1662 } |
1695 | 1663 |
1696 return PP_TRUE; | 1664 return PP_TRUE; |
1697 } | 1665 } |
1698 | 1666 |
1699 PP_Bool PluginInstance::IsFullFrame(PP_Instance instance) { | 1667 PP_Bool PluginInstance::IsFullFrame(PP_Instance instance) { |
1700 return PP_FromBool(full_frame()); | 1668 return PP_FromBool(full_frame()); |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2057 screen_size_for_fullscreen_ = gfx::Size(); | 2025 screen_size_for_fullscreen_ = gfx::Size(); |
2058 WebElement element = container_->element(); | 2026 WebElement element = container_->element(); |
2059 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2027 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
2060 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2028 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
2061 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2029 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
2062 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2030 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
2063 } | 2031 } |
2064 | 2032 |
2065 } // namespace ppapi | 2033 } // namespace ppapi |
2066 } // namespace webkit | 2034 } // namespace webkit |
OLD | NEW |