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

Side by Side Diff: chrome/renderer/webplugin_delegate_pepper.cc

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

Powered by Google App Engine
This is Rietveld 408576698