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 #define PEPPER_APIS_ENABLED 1 | 5 #define PEPPER_APIS_ENABLED 1 |
6 | 6 |
7 #include "chrome/renderer/webplugin_delegate_pepper.h" | 7 #include "chrome/renderer/webplugin_delegate_pepper.h" |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #elif defined(OS_LINUX) | 56 #elif defined(OS_LINUX) |
57 #include "chrome/renderer/renderer_sandbox_support_linux.h" | 57 #include "chrome/renderer/renderer_sandbox_support_linux.h" |
58 #include "printing/pdf_ps_metafile_cairo.h" | 58 #include "printing/pdf_ps_metafile_cairo.h" |
59 #elif defined(OS_WIN) | 59 #elif defined(OS_WIN) |
60 #include "printing/units.h" | 60 #include "printing/units.h" |
61 #include "skia/ext/vector_platform_device.h" | 61 #include "skia/ext/vector_platform_device.h" |
62 #include "ui/gfx/codec/jpeg_codec.h" | 62 #include "ui/gfx/codec/jpeg_codec.h" |
63 #include "ui/gfx/gdi_util.h" | 63 #include "ui/gfx/gdi_util.h" |
64 #endif | 64 #endif |
65 | 65 |
| 66 #if defined(ENABLE_GPU) |
| 67 #include "webkit/plugins/npapi/plugin_constants_win.h" |
| 68 #endif |
| 69 |
| 70 #if defined(ENABLE_GPU) |
| 71 using gpu::Buffer; |
| 72 #endif |
| 73 |
66 using webkit::npapi::WebPlugin; | 74 using webkit::npapi::WebPlugin; |
67 using webkit::npapi::WebPluginDelegate; | 75 using webkit::npapi::WebPluginDelegate; |
68 using webkit::npapi::WebPluginResourceClient; | 76 using webkit::npapi::WebPluginResourceClient; |
69 using WebKit::WebCursorInfo; | 77 using WebKit::WebCursorInfo; |
70 using WebKit::WebKeyboardEvent; | 78 using WebKit::WebKeyboardEvent; |
71 using WebKit::WebInputEvent; | 79 using WebKit::WebInputEvent; |
72 using WebKit::WebMouseEvent; | 80 using WebKit::WebMouseEvent; |
73 using WebKit::WebMouseWheelEvent; | 81 using WebKit::WebMouseWheelEvent; |
74 | 82 |
75 namespace { | 83 namespace { |
76 | 84 |
77 // Implementation artifacts for a context | 85 // Implementation artifacts for a context |
78 struct Device2DImpl { | 86 struct Device2DImpl { |
79 TransportDIB* dib; | 87 TransportDIB* dib; |
80 }; | 88 }; |
81 | 89 |
| 90 struct Device3DImpl { |
| 91 #if defined(ENABLE_GPU) |
| 92 gpu::CommandBuffer* command_buffer; |
| 93 #endif |
| 94 bool dynamically_created; |
| 95 }; |
| 96 |
| 97 const int32 kDefaultCommandBufferSize = 1024 * 1024; |
| 98 |
82 } // namespace | 99 } // namespace |
83 | 100 |
84 static const float kPointsPerInch = 72.0; | 101 static const float kPointsPerInch = 72.0; |
85 | 102 |
86 #if defined(OS_WIN) | 103 #if defined(OS_WIN) |
87 // Exported by pdf.dll | 104 // Exported by pdf.dll |
88 typedef bool (*RenderPDFPageToDCProc)( | 105 typedef bool (*RenderPDFPageToDCProc)( |
89 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc, | 106 const unsigned char* pdf_buffer, int buffer_size, int page_number, HDC dc, |
90 int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y, | 107 int dpi_x, int dpi_y, int bounds_origin_x, int bounds_origin_y, |
91 int bounds_width, int bounds_height, bool fit_to_bounds, | 108 int bounds_width, int bounds_height, bool fit_to_bounds, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 190 |
174 window_.window = NULL; | 191 window_.window = NULL; |
175 instance_->NPP_SetWindow(&window_); | 192 instance_->NPP_SetWindow(&window_); |
176 | 193 |
177 instance_->NPP_Destroy(); | 194 instance_->NPP_Destroy(); |
178 | 195 |
179 instance_->set_web_plugin(NULL); | 196 instance_->set_web_plugin(NULL); |
180 | 197 |
181 instance_ = 0; | 198 instance_ = 0; |
182 } | 199 } |
| 200 |
| 201 // Destroy the nested GPU plugin only after first destroying the underlying |
| 202 // Pepper plugin. This is so the Pepper plugin does not attempt to issue |
| 203 // rendering commands after the GPU plugin has stopped processing them and |
| 204 // responding to them. |
| 205 if (nested_delegate_) { |
| 206 #if defined(ENABLE_GPU) |
| 207 if (command_buffer_) { |
| 208 nested_delegate_->DestroyCommandBuffer(command_buffer_); |
| 209 command_buffer_ = NULL; |
| 210 } |
| 211 #endif |
| 212 |
| 213 nested_delegate_->PluginDestroyed(); |
| 214 nested_delegate_ = NULL; |
| 215 } |
183 } | 216 } |
184 | 217 |
185 void WebPluginDelegatePepper::UpdateGeometry( | 218 void WebPluginDelegatePepper::UpdateGeometry( |
186 const gfx::Rect& window_rect, | 219 const gfx::Rect& window_rect, |
187 const gfx::Rect& clip_rect) { | 220 const gfx::Rect& clip_rect) { |
188 // Only resend to the instance if the geometry has changed. | 221 // Only resend to the instance if the geometry has changed. |
189 if (window_rect == window_rect_ && clip_rect == clip_rect_) | 222 if (window_rect == window_rect_ && clip_rect == clip_rect_) |
190 return; | 223 return; |
191 | 224 |
192 clip_rect_ = clip_rect; | 225 clip_rect_ = clip_rect; |
193 cutout_rects_.clear(); | 226 cutout_rects_.clear(); |
194 | 227 |
195 if (window_rect_ == window_rect) | 228 if (window_rect_ == window_rect) |
196 return; | 229 return; |
197 window_rect_ = window_rect; | 230 window_rect_ = window_rect; |
198 | 231 |
199 // TODO(brettw) figure out how to tell the plugin that the size changed and it | 232 // TODO(brettw) figure out how to tell the plugin that the size changed and it |
200 // needs to repaint? | 233 // needs to repaint? |
201 SkBitmap new_committed; | 234 SkBitmap new_committed; |
202 new_committed.setConfig(SkBitmap::kARGB_8888_Config, | 235 new_committed.setConfig(SkBitmap::kARGB_8888_Config, |
203 window_rect_.width(), window_rect_.height()); | 236 window_rect_.width(), window_rect_.height()); |
204 new_committed.allocPixels(); | 237 new_committed.allocPixels(); |
205 committed_bitmap_ = new_committed; | 238 committed_bitmap_ = new_committed; |
206 | 239 |
| 240 // Forward the new geometry to the nested plugin instance. |
| 241 if (nested_delegate_) |
| 242 nested_delegate_->UpdateGeometry(window_rect, clip_rect); |
| 243 |
| 244 #if defined(ENABLE_GPU) |
| 245 #if defined(OS_MACOSX) |
| 246 // Send the new window size to the command buffer service code so it |
| 247 // can allocate a new backing store. The handle to the new backing |
| 248 // store is sent back to the browser asynchronously. |
| 249 if (command_buffer_) { |
| 250 command_buffer_->SetWindowSize(window_rect_.size()); |
| 251 } |
| 252 #endif // OS_MACOSX |
| 253 #endif // ENABLE_GPU |
| 254 |
207 if (!instance()) | 255 if (!instance()) |
208 return; | 256 return; |
209 | 257 |
210 ForwardSetWindow(); | 258 ForwardSetWindow(); |
211 } | 259 } |
212 | 260 |
213 NPObject* WebPluginDelegatePepper::GetPluginScriptableObject() { | 261 NPObject* WebPluginDelegatePepper::GetPluginScriptableObject() { |
214 return instance_->GetPluginScriptableObject(); | 262 return instance_->GetPluginScriptableObject(); |
215 } | 263 } |
216 | 264 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 | 560 |
513 NPError WebPluginDelegatePepper::Device2DInitializeContext( | 561 NPError WebPluginDelegatePepper::Device2DInitializeContext( |
514 const NPDeviceContext2DConfig* config, | 562 const NPDeviceContext2DConfig* config, |
515 NPDeviceContext2D* context) { | 563 NPDeviceContext2D* context) { |
516 | 564 |
517 if (!render_view_) { | 565 if (!render_view_) { |
518 return NPERR_GENERIC_ERROR; | 566 return NPERR_GENERIC_ERROR; |
519 } | 567 } |
520 | 568 |
521 // This is a windowless plugin, so set it to have no handle. Defer this | 569 // This is a windowless plugin, so set it to have no handle. Defer this |
522 // until we know the plugin will use the 2D device. | 570 // until we know the plugin will use the 2D device. If it uses the 3D device |
| 571 // it will have a window handle. |
523 plugin_->SetWindow(gfx::kNullPluginWindow); | 572 plugin_->SetWindow(gfx::kNullPluginWindow); |
524 | 573 |
525 scoped_ptr<Graphics2DDeviceContext> g2d(new Graphics2DDeviceContext(this)); | 574 scoped_ptr<Graphics2DDeviceContext> g2d(new Graphics2DDeviceContext(this)); |
526 NPError status = g2d->Initialize(window_rect_, config, context); | 575 NPError status = g2d->Initialize(window_rect_, config, context); |
527 if (NPERR_NO_ERROR == status) { | 576 if (NPERR_NO_ERROR == status) { |
528 context->reserved = reinterpret_cast<void *>( | 577 context->reserved = reinterpret_cast<void *>( |
529 graphic2d_contexts_.Add(g2d.release())); | 578 graphic2d_contexts_.Add(g2d.release())); |
530 } | 579 } |
531 return status; | 580 return status; |
532 } | 581 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 | 662 |
614 NPError WebPluginDelegatePepper::Device3DQueryConfig( | 663 NPError WebPluginDelegatePepper::Device3DQueryConfig( |
615 const NPDeviceContext3DConfig* request, | 664 const NPDeviceContext3DConfig* request, |
616 NPDeviceContext3DConfig* obtain) { | 665 NPDeviceContext3DConfig* obtain) { |
617 return NPERR_GENERIC_ERROR; | 666 return NPERR_GENERIC_ERROR; |
618 } | 667 } |
619 | 668 |
620 NPError WebPluginDelegatePepper::Device3DInitializeContext( | 669 NPError WebPluginDelegatePepper::Device3DInitializeContext( |
621 const NPDeviceContext3DConfig* config, | 670 const NPDeviceContext3DConfig* config, |
622 NPDeviceContext3D* context) { | 671 NPDeviceContext3D* context) { |
| 672 if (!context) |
| 673 return NPERR_GENERIC_ERROR; |
| 674 |
| 675 #if defined(ENABLE_GPU) |
| 676 // Check to see if the GPU plugin is already initialized and fail if so. |
| 677 if (nested_delegate_) |
| 678 return NPERR_GENERIC_ERROR; |
| 679 |
| 680 // Create an instance of the GPU plugin that is responsible for 3D |
| 681 // rendering. |
| 682 nested_delegate_ = new WebPluginDelegateProxy( |
| 683 "application/vnd.google.chrome.gpu-plugin", render_view_); |
| 684 |
| 685 // TODO(apatrick): should the GPU plugin be attached to plugin_? |
| 686 if (nested_delegate_->Initialize(GURL(), |
| 687 std::vector<std::string>(), |
| 688 std::vector<std::string>(), |
| 689 plugin_, |
| 690 false)) { |
| 691 plugin_->SetAcceptsInputEvents(true); |
| 692 |
| 693 // Ensure the window has the correct size before initializing the |
| 694 // command buffer. |
| 695 nested_delegate_->UpdateGeometry(window_rect_, clip_rect_); |
| 696 |
| 697 // Ask the GPU plugin to create a command buffer and return a proxy. |
| 698 command_buffer_ = nested_delegate_->CreateCommandBuffer(); |
| 699 if (command_buffer_) { |
| 700 // Initialize the proxy command buffer. |
| 701 if (command_buffer_->Initialize(config->commandBufferSize)) { |
| 702 // Get the initial command buffer state. |
| 703 gpu::CommandBuffer::State state = command_buffer_->GetState(); |
| 704 |
| 705 // Initialize the 3D context. |
| 706 context->reserved = NULL; |
| 707 context->waitForProgress = true; |
| 708 Buffer ring_buffer = command_buffer_->GetRingBuffer(); |
| 709 context->commandBuffer = ring_buffer.ptr; |
| 710 context->commandBufferSize = state.num_entries; |
| 711 context->repaintCallback = NULL; |
| 712 Synchronize3DContext(context, state); |
| 713 |
| 714 ScheduleHandleRepaint(instance_->npp(), context); |
| 715 |
| 716 #if defined(OS_MACOSX) |
| 717 command_buffer_->SetWindowSize(window_rect_.size()); |
| 718 #endif // OS_MACOSX |
| 719 |
| 720 // Make sure the nested delegate shows up in the right place |
| 721 // on the page. |
| 722 SendNestedDelegateGeometryToBrowser(window_rect_, clip_rect_); |
| 723 |
| 724 // Save the implementation information (the CommandBuffer). |
| 725 Device3DImpl* impl = new Device3DImpl; |
| 726 impl->command_buffer = command_buffer_; |
| 727 impl->dynamically_created = false; |
| 728 context->reserved = impl; |
| 729 |
| 730 return NPERR_NO_ERROR; |
| 731 } |
| 732 |
| 733 nested_delegate_->DestroyCommandBuffer(command_buffer_); |
| 734 command_buffer_ = NULL; |
| 735 } |
| 736 } |
| 737 |
| 738 nested_delegate_->PluginDestroyed(); |
| 739 nested_delegate_ = NULL; |
| 740 #endif // ENABLE_GPU |
| 741 |
623 return NPERR_GENERIC_ERROR; | 742 return NPERR_GENERIC_ERROR; |
624 } | 743 } |
625 | 744 |
626 NPError WebPluginDelegatePepper::Device3DSetStateContext( | 745 NPError WebPluginDelegatePepper::Device3DSetStateContext( |
627 NPDeviceContext3D* context, | 746 NPDeviceContext3D* context, |
628 int32 state, | 747 int32 state, |
629 intptr_t value) { | 748 intptr_t value) { |
630 return NPERR_GENERIC_ERROR; | 749 return NPERR_GENERIC_ERROR; |
631 } | 750 } |
632 | 751 |
633 NPError WebPluginDelegatePepper::Device3DGetStateContext( | 752 NPError WebPluginDelegatePepper::Device3DGetStateContext( |
634 NPDeviceContext3D* context, | 753 NPDeviceContext3D* context, |
635 int32 state, | 754 int32 state, |
636 intptr_t* value) { | 755 intptr_t* value) { |
637 return NPERR_GENERIC_ERROR; | 756 return NPERR_GENERIC_ERROR; |
638 } | 757 } |
639 | 758 |
640 NPError WebPluginDelegatePepper::Device3DFlushContext( | 759 NPError WebPluginDelegatePepper::Device3DFlushContext( |
641 NPP id, | 760 NPP id, |
642 NPDeviceContext3D* context, | 761 NPDeviceContext3D* context, |
643 NPDeviceFlushContextCallbackPtr callback, | 762 NPDeviceFlushContextCallbackPtr callback, |
644 void* user_data) { | 763 void* user_data) { |
645 return NPERR_GENERIC_ERROR; | 764 if (!context) |
| 765 return NPERR_GENERIC_ERROR; |
| 766 |
| 767 #if defined(ENABLE_GPU) |
| 768 gpu::CommandBuffer::State state; |
| 769 |
| 770 if (context->waitForProgress) { |
| 771 if (callback) { |
| 772 command_buffer_->AsyncFlush( |
| 773 context->putOffset, |
| 774 method_factory3d_.NewRunnableMethod( |
| 775 &WebPluginDelegatePepper::Device3DUpdateState, |
| 776 id, |
| 777 context, |
| 778 callback, |
| 779 user_data)); |
| 780 } else { |
| 781 state = command_buffer_->FlushSync(context->putOffset); |
| 782 Synchronize3DContext(context, state); |
| 783 } |
| 784 } else { |
| 785 if (callback) { |
| 786 command_buffer_->AsyncGetState( |
| 787 method_factory3d_.NewRunnableMethod( |
| 788 &WebPluginDelegatePepper::Device3DUpdateState, |
| 789 id, |
| 790 context, |
| 791 callback, |
| 792 user_data)); |
| 793 } else { |
| 794 state = command_buffer_->GetState(); |
| 795 Synchronize3DContext(context, state); |
| 796 } |
| 797 } |
| 798 #endif // ENABLE_GPU |
| 799 return NPERR_NO_ERROR; |
646 } | 800 } |
647 | 801 |
648 NPError WebPluginDelegatePepper::Device3DDestroyContext( | 802 NPError WebPluginDelegatePepper::Device3DDestroyContext( |
649 NPDeviceContext3D* context) { | 803 NPDeviceContext3D* context) { |
650 return NPERR_GENERIC_ERROR; | 804 if (!context) |
| 805 return NPERR_GENERIC_ERROR; |
| 806 |
| 807 #if defined(ENABLE_GPU) |
| 808 // Prevent any async flush callbacks from being invoked after the context |
| 809 // has been destroyed. |
| 810 method_factory3d_.RevokeAll(); |
| 811 |
| 812 // TODO(apatrick): this will be much simpler when we switch to the new device |
| 813 // API. There should be no need for the Device3DImpl and the context will |
| 814 // always be destroyed dynamically. |
| 815 Device3DImpl* impl = static_cast<Device3DImpl*>(context->reserved); |
| 816 bool dynamically_created = impl->dynamically_created; |
| 817 delete impl; |
| 818 context->reserved = NULL; |
| 819 if (dynamically_created) { |
| 820 delete context; |
| 821 } |
| 822 |
| 823 if (nested_delegate_) { |
| 824 if (command_buffer_) { |
| 825 nested_delegate_->DestroyCommandBuffer(command_buffer_); |
| 826 command_buffer_ = NULL; |
| 827 } |
| 828 |
| 829 nested_delegate_->PluginDestroyed(); |
| 830 nested_delegate_ = NULL; |
| 831 } |
| 832 #endif // ENABLE_GPU |
| 833 |
| 834 return NPERR_NO_ERROR; |
651 } | 835 } |
652 | 836 |
653 NPError WebPluginDelegatePepper::Device3DCreateBuffer( | 837 NPError WebPluginDelegatePepper::Device3DCreateBuffer( |
654 NPDeviceContext3D* context, | 838 NPDeviceContext3D* context, |
655 size_t size, | 839 size_t size, |
656 int32* id) { | 840 int32* id) { |
657 return NPERR_GENERIC_ERROR; | 841 if (!context) |
| 842 return NPERR_GENERIC_ERROR; |
| 843 |
| 844 #if defined(ENABLE_GPU) |
| 845 *id = command_buffer_->CreateTransferBuffer(size); |
| 846 if (*id < 0) |
| 847 return NPERR_GENERIC_ERROR; |
| 848 #endif // ENABLE_GPU |
| 849 |
| 850 return NPERR_NO_ERROR; |
658 } | 851 } |
659 | 852 |
660 NPError WebPluginDelegatePepper::Device3DDestroyBuffer( | 853 NPError WebPluginDelegatePepper::Device3DDestroyBuffer( |
661 NPDeviceContext3D* context, | 854 NPDeviceContext3D* context, |
662 int32 id) { | 855 int32 id) { |
663 return NPERR_GENERIC_ERROR; | 856 if (!context) |
| 857 return NPERR_GENERIC_ERROR; |
| 858 |
| 859 #if defined(ENABLE_GPU) |
| 860 command_buffer_->DestroyTransferBuffer(id); |
| 861 #endif // ENABLE_GPU |
| 862 return NPERR_NO_ERROR; |
664 } | 863 } |
665 | 864 |
666 NPError WebPluginDelegatePepper::Device3DMapBuffer( | 865 NPError WebPluginDelegatePepper::Device3DMapBuffer( |
667 NPDeviceContext3D* context, | 866 NPDeviceContext3D* context, |
668 int32 id, | 867 int32 id, |
669 NPDeviceBuffer* np_buffer) { | 868 NPDeviceBuffer* np_buffer) { |
670 return NPERR_GENERIC_ERROR; | 869 if (!context) |
| 870 return NPERR_GENERIC_ERROR; |
| 871 |
| 872 #if defined(ENABLE_GPU) |
| 873 Buffer gpu_buffer; |
| 874 if (id == NP3DCommandBufferId) { |
| 875 gpu_buffer = command_buffer_->GetRingBuffer(); |
| 876 } else { |
| 877 gpu_buffer = command_buffer_->GetTransferBuffer(id); |
| 878 } |
| 879 |
| 880 np_buffer->ptr = gpu_buffer.ptr; |
| 881 np_buffer->size = gpu_buffer.size; |
| 882 if (!np_buffer->ptr) |
| 883 return NPERR_GENERIC_ERROR; |
| 884 #endif // ENABLE_GPU |
| 885 |
| 886 return NPERR_NO_ERROR; |
671 } | 887 } |
672 | 888 |
673 NPError WebPluginDelegatePepper::Device3DGetNumConfigs(int32* num_configs) { | 889 NPError WebPluginDelegatePepper::Device3DGetNumConfigs(int32* num_configs) { |
674 return NPERR_GENERIC_ERROR; | 890 if (!num_configs) |
| 891 return NPERR_GENERIC_ERROR; |
| 892 |
| 893 *num_configs = 1; |
| 894 return NPERR_NO_ERROR; |
675 } | 895 } |
676 | 896 |
677 NPError WebPluginDelegatePepper::Device3DGetConfigAttribs( | 897 NPError WebPluginDelegatePepper::Device3DGetConfigAttribs( |
678 int32 config, | 898 int32 config, |
679 int32* attrib_list) { | 899 int32* attrib_list) { |
680 return NPERR_GENERIC_ERROR; | 900 // Only one config available currently. |
| 901 if (config != 0) |
| 902 return NPERR_GENERIC_ERROR; |
| 903 |
| 904 if (attrib_list) { |
| 905 for (int32* attrib_pair = attrib_list; *attrib_pair; attrib_pair += 2) { |
| 906 switch (attrib_pair[0]) { |
| 907 case NP3DAttrib_BufferSize: |
| 908 attrib_pair[1] = 32; |
| 909 break; |
| 910 case NP3DAttrib_AlphaSize: |
| 911 case NP3DAttrib_BlueSize: |
| 912 case NP3DAttrib_GreenSize: |
| 913 case NP3DAttrib_RedSize: |
| 914 attrib_pair[1] = 8; |
| 915 break; |
| 916 case NP3DAttrib_DepthSize: |
| 917 attrib_pair[1] = 24; |
| 918 break; |
| 919 case NP3DAttrib_StencilSize: |
| 920 attrib_pair[1] = 8; |
| 921 break; |
| 922 case NP3DAttrib_SurfaceType: |
| 923 attrib_pair[1] = 0; |
| 924 break; |
| 925 default: |
| 926 return NPERR_GENERIC_ERROR; |
| 927 } |
| 928 } |
| 929 } |
| 930 |
| 931 return NPERR_NO_ERROR; |
681 } | 932 } |
682 | 933 |
683 NPError WebPluginDelegatePepper::Device3DCreateContext( | 934 NPError WebPluginDelegatePepper::Device3DCreateContext( |
684 int32 config, | 935 int32 config, |
685 const int32* attrib_list, | 936 const int32* attrib_list, |
686 NPDeviceContext3D** context) { | 937 NPDeviceContext3D** context) { |
687 return NPERR_GENERIC_ERROR; | 938 if (!context) |
| 939 return NPERR_GENERIC_ERROR; |
| 940 |
| 941 // Only one config available currently. |
| 942 if (config != 0) |
| 943 return NPERR_GENERIC_ERROR; |
| 944 |
| 945 // For now, just use the old API to initialize the context. |
| 946 NPDeviceContext3DConfig old_config; |
| 947 old_config.commandBufferSize = kDefaultCommandBufferSize; |
| 948 if (attrib_list) { |
| 949 for (const int32* attrib_pair = attrib_list; *attrib_pair; |
| 950 attrib_pair += 2) { |
| 951 switch (attrib_pair[0]) { |
| 952 case NP3DAttrib_CommandBufferSize: |
| 953 old_config.commandBufferSize = attrib_pair[1]; |
| 954 break; |
| 955 default: |
| 956 return NPERR_GENERIC_ERROR; |
| 957 } |
| 958 } |
| 959 } |
| 960 |
| 961 *context = new NPDeviceContext3D; |
| 962 Device3DInitializeContext(&old_config, *context); |
| 963 |
| 964 // Flag the context as dynamically created by the browser. TODO(apatrick): |
| 965 // take this out when all contexts are dynamically created. |
| 966 Device3DImpl* impl = static_cast<Device3DImpl*>((*context)->reserved); |
| 967 impl->dynamically_created = true; |
| 968 |
| 969 return NPERR_NO_ERROR; |
688 } | 970 } |
689 | 971 |
690 NPError WebPluginDelegatePepper::Device3DRegisterCallback( | 972 NPError WebPluginDelegatePepper::Device3DRegisterCallback( |
691 NPP id, | 973 NPP id, |
692 NPDeviceContext3D* context, | 974 NPDeviceContext3D* context, |
693 int32 callback_type, | 975 int32 callback_type, |
694 NPDeviceGenericCallbackPtr callback, | 976 NPDeviceGenericCallbackPtr callback, |
695 void* callback_data) { | 977 void* callback_data) { |
696 return NPERR_GENERIC_ERROR; | 978 if (!context) |
| 979 return NPERR_GENERIC_ERROR; |
| 980 |
| 981 switch (callback_type) { |
| 982 case NP3DCallback_Repaint: |
| 983 context->repaintCallback = reinterpret_cast<NPDeviceContext3DRepaintPtr>( |
| 984 callback); |
| 985 break; |
| 986 default: |
| 987 return NPERR_GENERIC_ERROR; |
| 988 } |
| 989 |
| 990 return NPERR_NO_ERROR; |
697 } | 991 } |
698 | 992 |
699 NPError WebPluginDelegatePepper::Device3DSynchronizeContext( | 993 NPError WebPluginDelegatePepper::Device3DSynchronizeContext( |
700 NPP id, | 994 NPP id, |
701 NPDeviceContext3D* context, | 995 NPDeviceContext3D* context, |
702 NPDeviceSynchronizationMode mode, | 996 NPDeviceSynchronizationMode mode, |
703 const int32* input_attrib_list, | 997 const int32* input_attrib_list, |
704 int32* output_attrib_list, | 998 int32* output_attrib_list, |
705 NPDeviceSynchronizeContextCallbackPtr callback, | 999 NPDeviceSynchronizeContextCallbackPtr callback, |
706 void* callback_data) { | 1000 void* callback_data) { |
707 return NPERR_GENERIC_ERROR; | 1001 if (!context) |
| 1002 return NPERR_GENERIC_ERROR; |
| 1003 |
| 1004 // Copy input attributes into context. |
| 1005 if (input_attrib_list) { |
| 1006 for (const int32* attrib_pair = input_attrib_list; |
| 1007 *attrib_pair; |
| 1008 attrib_pair += 2) { |
| 1009 switch (attrib_pair[0]) { |
| 1010 case NP3DAttrib_PutOffset: |
| 1011 context->putOffset = attrib_pair[1]; |
| 1012 break; |
| 1013 default: |
| 1014 return NPERR_GENERIC_ERROR; |
| 1015 } |
| 1016 } |
| 1017 } |
| 1018 |
| 1019 // Use existing flush mechanism for now. |
| 1020 if (mode != NPDeviceSynchronizationMode_Cached) { |
| 1021 context->waitForProgress = mode == NPDeviceSynchronizationMode_Flush; |
| 1022 Device3DFlushContext(id, context, callback, callback_data); |
| 1023 } |
| 1024 |
| 1025 // Copy most recent output attributes from context. |
| 1026 // To read output attributes after the completion of an asynchronous flush, |
| 1027 // invoke SynchronizeContext again with mode |
| 1028 // NPDeviceSynchronizationMode_Cached from the callback function. |
| 1029 if (output_attrib_list) { |
| 1030 for (int32* attrib_pair = output_attrib_list; |
| 1031 *attrib_pair; |
| 1032 attrib_pair += 2) { |
| 1033 switch (attrib_pair[0]) { |
| 1034 case NP3DAttrib_CommandBufferSize: |
| 1035 attrib_pair[1] = context->commandBufferSize; |
| 1036 break; |
| 1037 case NP3DAttrib_GetOffset: |
| 1038 attrib_pair[1] = context->getOffset; |
| 1039 break; |
| 1040 case NP3DAttrib_PutOffset: |
| 1041 attrib_pair[1] = context->putOffset; |
| 1042 break; |
| 1043 case NP3DAttrib_Token: |
| 1044 attrib_pair[1] = context->token; |
| 1045 break; |
| 1046 default: |
| 1047 return NPERR_GENERIC_ERROR; |
| 1048 } |
| 1049 } |
| 1050 } |
| 1051 |
| 1052 return NPERR_NO_ERROR; |
708 } | 1053 } |
709 | 1054 |
710 NPError WebPluginDelegatePepper::DeviceAudioQueryCapability(int32 capability, | 1055 NPError WebPluginDelegatePepper::DeviceAudioQueryCapability(int32 capability, |
711 int32* value) { | 1056 int32* value) { |
712 // TODO(neb,cpu) implement QueryCapability | 1057 // TODO(neb,cpu) implement QueryCapability |
713 return NPERR_GENERIC_ERROR; | 1058 return NPERR_GENERIC_ERROR; |
714 } | 1059 } |
715 | 1060 |
716 NPError WebPluginDelegatePepper::DeviceAudioQueryConfig( | 1061 NPError WebPluginDelegatePepper::DeviceAudioQueryConfig( |
717 const NPDeviceContextAudioConfig* request, | 1062 const NPDeviceContextAudioConfig* request, |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 pdf_output_done_ = false; | 1376 pdf_output_done_ = false; |
1032 #endif // defined(OS_LINUX) | 1377 #endif // defined(OS_LINUX) |
1033 } | 1378 } |
1034 | 1379 |
1035 WebPluginDelegatePepper::WebPluginDelegatePepper( | 1380 WebPluginDelegatePepper::WebPluginDelegatePepper( |
1036 const base::WeakPtr<RenderView>& render_view, | 1381 const base::WeakPtr<RenderView>& render_view, |
1037 webkit::npapi::PluginInstance *instance) | 1382 webkit::npapi::PluginInstance *instance) |
1038 : render_view_(render_view), | 1383 : render_view_(render_view), |
1039 plugin_(NULL), | 1384 plugin_(NULL), |
1040 instance_(instance), | 1385 instance_(instance), |
| 1386 nested_delegate_(NULL), |
1041 current_printer_dpi_(-1), | 1387 current_printer_dpi_(-1), |
1042 #if defined (OS_LINUX) | 1388 #if defined (OS_LINUX) |
1043 num_pages_(0), | 1389 num_pages_(0), |
1044 pdf_output_done_(false), | 1390 pdf_output_done_(false), |
1045 #endif // (OS_LINUX) | 1391 #endif // (OS_LINUX) |
| 1392 #if defined(ENABLE_GPU) |
| 1393 command_buffer_(NULL), |
| 1394 method_factory3d_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 1395 #endif |
1046 find_identifier_(-1), | 1396 find_identifier_(-1), |
1047 current_choose_file_callback_(NULL), | 1397 current_choose_file_callback_(NULL), |
1048 current_choose_file_user_data_(NULL) { | 1398 current_choose_file_user_data_(NULL) { |
1049 // For now we keep a window struct, although it isn't used. | 1399 // For now we keep a window struct, although it isn't used. |
1050 memset(&window_, 0, sizeof(window_)); | 1400 memset(&window_, 0, sizeof(window_)); |
1051 // All Pepper plugins are windowless and transparent. | 1401 // All Pepper plugins are windowless and transparent. |
1052 // TODO(sehr): disable resetting these NPPVs by plugins. | 1402 // TODO(sehr): disable resetting these NPPVs by plugins. |
1053 instance->set_windowless(true); | 1403 instance->set_windowless(true); |
1054 instance->set_transparent(true); | 1404 instance->set_transparent(true); |
1055 } | 1405 } |
(...skipping 17 matching lines...) Expand all Loading... |
1073 window_.type = NPWindowTypeDrawable; | 1423 window_.type = NPWindowTypeDrawable; |
1074 instance()->NPP_SetWindow(&window_); | 1424 instance()->NPP_SetWindow(&window_); |
1075 } | 1425 } |
1076 | 1426 |
1077 void WebPluginDelegatePepper::PluginDestroyed() { | 1427 void WebPluginDelegatePepper::PluginDestroyed() { |
1078 delete this; | 1428 delete this; |
1079 } | 1429 } |
1080 | 1430 |
1081 void WebPluginDelegatePepper::Paint(WebKit::WebCanvas* canvas, | 1431 void WebPluginDelegatePepper::Paint(WebKit::WebCanvas* canvas, |
1082 const gfx::Rect& rect) { | 1432 const gfx::Rect& rect) { |
1083 // Blit from background_context to context. | 1433 if (nested_delegate_) { |
1084 if (!committed_bitmap_.isNull()) { | 1434 // TODO(apatrick): The GPU plugin will render to an offscreen render target. |
| 1435 // Need to copy it to the screen here. |
| 1436 } else { |
| 1437 // Blit from background_context to context. |
| 1438 if (!committed_bitmap_.isNull()) { |
1085 #if defined(OS_MACOSX) | 1439 #if defined(OS_MACOSX) |
1086 DrawSkBitmapToCanvas(committed_bitmap_, canvas, window_rect_, | 1440 DrawSkBitmapToCanvas(committed_bitmap_, canvas, window_rect_, |
1087 static_cast<int>(CGBitmapContextGetHeight(canvas))); | 1441 static_cast<int>(CGBitmapContextGetHeight(canvas))); |
1088 #else | 1442 #else |
1089 canvas->drawBitmap(committed_bitmap_, | 1443 canvas->drawBitmap(committed_bitmap_, |
1090 SkIntToScalar(window_rect_.origin().x()), | 1444 SkIntToScalar(window_rect_.origin().x()), |
1091 SkIntToScalar(window_rect_.origin().y())); | 1445 SkIntToScalar(window_rect_.origin().y())); |
1092 #endif | 1446 #endif |
| 1447 } |
1093 } | 1448 } |
1094 } | 1449 } |
1095 | 1450 |
1096 void WebPluginDelegatePepper::Print(gfx::NativeDrawingContext context) { | 1451 void WebPluginDelegatePepper::Print(gfx::NativeDrawingContext context) { |
1097 NOTIMPLEMENTED(); | 1452 NOTIMPLEMENTED(); |
1098 } | 1453 } |
1099 | 1454 |
1100 void WebPluginDelegatePepper::InstallMissingPlugin() { | 1455 void WebPluginDelegatePepper::InstallMissingPlugin() { |
1101 NOTIMPLEMENTED(); | 1456 NOTIMPLEMENTED(); |
1102 } | 1457 } |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 case NPEventType_Device: | 1577 case NPEventType_Device: |
1223 // NOTIMPLEMENTED(); | 1578 // NOTIMPLEMENTED(); |
1224 break; | 1579 break; |
1225 } | 1580 } |
1226 bool rv = instance()->NPP_HandleEvent(&npevent) != 0; | 1581 bool rv = instance()->NPP_HandleEvent(&npevent) != 0; |
1227 if (cursor_.get()) | 1582 if (cursor_.get()) |
1228 *cursor_info = *cursor_; | 1583 *cursor_info = *cursor_; |
1229 return rv; | 1584 return rv; |
1230 } | 1585 } |
1231 | 1586 |
| 1587 #if defined(ENABLE_GPU) |
| 1588 |
| 1589 void WebPluginDelegatePepper::ScheduleHandleRepaint( |
| 1590 NPP npp, NPDeviceContext3D* context) { |
| 1591 command_buffer_->SetNotifyRepaintTask(method_factory3d_.NewRunnableMethod( |
| 1592 &WebPluginDelegatePepper::ForwardHandleRepaint, |
| 1593 npp, |
| 1594 context)); |
| 1595 } |
| 1596 |
| 1597 void WebPluginDelegatePepper::ForwardHandleRepaint( |
| 1598 NPP npp, NPDeviceContext3D* context) { |
| 1599 if (context->repaintCallback) |
| 1600 context->repaintCallback(npp, context); |
| 1601 ScheduleHandleRepaint(npp, context); |
| 1602 } |
| 1603 |
| 1604 void WebPluginDelegatePepper::Synchronize3DContext( |
| 1605 NPDeviceContext3D* context, |
| 1606 const gpu::CommandBuffer::State& state) { |
| 1607 context->getOffset = state.get_offset; |
| 1608 context->putOffset = state.put_offset; |
| 1609 context->token = state.token; |
| 1610 context->error = static_cast<NPDeviceContext3DError>(state.error); |
| 1611 } |
| 1612 |
| 1613 void WebPluginDelegatePepper::Device3DUpdateState( |
| 1614 NPP npp, |
| 1615 NPDeviceContext3D* context, |
| 1616 NPDeviceFlushContextCallbackPtr callback, |
| 1617 void* user_data) { |
| 1618 if (command_buffer_) { |
| 1619 Synchronize3DContext(context, command_buffer_->GetLastState()); |
| 1620 if (callback) |
| 1621 callback(npp, context, NPERR_NO_ERROR, user_data); |
| 1622 } |
| 1623 } |
| 1624 |
| 1625 #endif // ENABLE_GPU |
| 1626 |
| 1627 void WebPluginDelegatePepper::SendNestedDelegateGeometryToBrowser( |
| 1628 const gfx::Rect& window_rect, |
| 1629 const gfx::Rect& clip_rect) { |
| 1630 // Inform the browser about the location of the plugin on the page. |
| 1631 // It appears that initially the plugin does not get laid out correctly -- |
| 1632 // possibly due to lazy creation of the nested delegate. |
| 1633 if (!nested_delegate_ || |
| 1634 !nested_delegate_->GetPluginWindowHandle() || |
| 1635 !render_view_) { |
| 1636 return; |
| 1637 } |
| 1638 |
| 1639 webkit::npapi::WebPluginGeometry geom; |
| 1640 geom.window = nested_delegate_->GetPluginWindowHandle(); |
| 1641 geom.window_rect = window_rect; |
| 1642 geom.clip_rect = clip_rect; |
| 1643 // Rects_valid must be true for this to work in the Gtk port; |
| 1644 // hopefully not having the cutout rects will not cause incorrect |
| 1645 // clipping. |
| 1646 geom.rects_valid = true; |
| 1647 geom.visible = true; |
| 1648 render_view_->DidMovePlugin(geom); |
| 1649 } |
| 1650 |
1232 bool WebPluginDelegatePepper::CalculatePrintedPageDimensions( | 1651 bool WebPluginDelegatePepper::CalculatePrintedPageDimensions( |
1233 int page_number, | 1652 int page_number, |
1234 NPPPrintExtensions* print_extensions, | 1653 NPPPrintExtensions* print_extensions, |
1235 gfx::Size* page_dimensions) { | 1654 gfx::Size* page_dimensions) { |
1236 int32 width_in_pixels = 0; | 1655 int32 width_in_pixels = 0; |
1237 int32 height_in_pixels = 0; | 1656 int32 height_in_pixels = 0; |
1238 NPError err = print_extensions->getRasterDimensions( | 1657 NPError err = print_extensions->getRasterDimensions( |
1239 instance()->npp(), page_number, &width_in_pixels, &height_in_pixels); | 1658 instance()->npp(), page_number, &width_in_pixels, &height_in_pixels); |
1240 if (err != NPERR_NO_ERROR) | 1659 if (err != NPERR_NO_ERROR) |
1241 return false; | 1660 return false; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 CGRect bounds; | 1760 CGRect bounds; |
1342 bounds.origin.x = dest_rect.x(); | 1761 bounds.origin.x = dest_rect.x(); |
1343 bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height(); | 1762 bounds.origin.y = canvas_height - dest_rect.y() - dest_rect.height(); |
1344 bounds.size.width = dest_rect.width(); | 1763 bounds.size.width = dest_rect.width(); |
1345 bounds.size.height = dest_rect.height(); | 1764 bounds.size.height = dest_rect.height(); |
1346 | 1765 |
1347 CGContextDrawImage(canvas, bounds, image); | 1766 CGContextDrawImage(canvas, bounds, image); |
1348 CGContextRestoreGState(canvas); | 1767 CGContextRestoreGState(canvas); |
1349 } | 1768 } |
1350 #endif // defined(OS_MACOSX) | 1769 #endif // defined(OS_MACOSX) |
OLD | NEW |