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

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

Issue 1529005: New experimental Pepper device API.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 8 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
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 "build/build_config.h" 7 #include "build/build_config.h"
8 #if defined(OS_WIN) 8 #if defined(OS_WIN)
9 #include <vsstyle.h> 9 #include <vsstyle.h>
10 #endif 10 #endif
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 67
68 namespace { 68 namespace {
69 69
70 // Implementation artifacts for a context 70 // Implementation artifacts for a context
71 struct Device2DImpl { 71 struct Device2DImpl {
72 TransportDIB* dib; 72 TransportDIB* dib;
73 }; 73 };
74 74
75 struct Device3DImpl { 75 struct Device3DImpl {
76 gpu::CommandBuffer* command_buffer; 76 gpu::CommandBuffer* command_buffer;
77 bool dynamically_created;
77 }; 78 };
78 79
80 const int32 kDefaultCommandBufferSize = 1024 * 1024;
81
79 #if defined(OS_WIN) 82 #if defined(OS_WIN)
80 struct ScrollbarThemeMapping { 83 struct ScrollbarThemeMapping {
81 NPThemeItem item; 84 NPThemeItem item;
82 NPThemeState state; 85 NPThemeState state;
83 int state_id; // Used by uxtheme. 86 int state_id; // Used by uxtheme.
84 }; 87 };
85 static const ScrollbarThemeMapping scrollbar_mappings[] = { 88 static const ScrollbarThemeMapping scrollbar_mappings[] = {
86 { NPThemeItemScrollbarDownArrow, NPThemeStateDisabled, ABS_DOWNDISABLED}, 89 { NPThemeItemScrollbarDownArrow, NPThemeStateDisabled, ABS_DOWNDISABLED},
87 { NPThemeItemScrollbarDownArrow, NPThemeStateHot, ABS_DOWNHOT}, 90 { NPThemeItemScrollbarDownArrow, NPThemeStateHot, ABS_DOWNHOT},
88 { NPThemeItemScrollbarDownArrow, NPThemeStateHover, ABS_DOWNHOVER}, 91 { NPThemeItemScrollbarDownArrow, NPThemeStateHover, ABS_DOWNHOVER},
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 command_buffer_->SetWindowSize(window_rect_.size()); 726 command_buffer_->SetWindowSize(window_rect_.size());
724 #endif // OS_MACOSX 727 #endif // OS_MACOSX
725 728
726 // Make sure the nested delegate shows up in the right place 729 // Make sure the nested delegate shows up in the right place
727 // on the page. 730 // on the page.
728 SendNestedDelegateGeometryToBrowser(window_rect_, clip_rect_); 731 SendNestedDelegateGeometryToBrowser(window_rect_, clip_rect_);
729 732
730 // Save the implementation information (the CommandBuffer). 733 // Save the implementation information (the CommandBuffer).
731 Device3DImpl* impl = new Device3DImpl; 734 Device3DImpl* impl = new Device3DImpl;
732 impl->command_buffer = command_buffer_; 735 impl->command_buffer = command_buffer_;
736 impl->dynamically_created = false;
733 context->reserved = impl; 737 context->reserved = impl;
734 738
735 return NPERR_NO_ERROR; 739 return NPERR_NO_ERROR;
736 } 740 }
737 } 741 }
738 742
739 nested_delegate_->DestroyCommandBuffer(command_buffer_); 743 nested_delegate_->DestroyCommandBuffer(command_buffer_);
740 command_buffer_ = NULL; 744 command_buffer_ = NULL;
741 } 745 }
742 746
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 NPError WebPluginDelegatePepper::Device3DDestroyContext( 811 NPError WebPluginDelegatePepper::Device3DDestroyContext(
808 NPDeviceContext3D* context) { 812 NPDeviceContext3D* context) {
809 if (!context) 813 if (!context)
810 return NPERR_GENERIC_ERROR; 814 return NPERR_GENERIC_ERROR;
811 815
812 #if defined(ENABLE_GPU) 816 #if defined(ENABLE_GPU)
813 // Prevent any async flush callbacks from being invoked after the context 817 // Prevent any async flush callbacks from being invoked after the context
814 // has been destroyed. 818 // has been destroyed.
815 method_factory3d_.RevokeAll(); 819 method_factory3d_.RevokeAll();
816 820
817 delete static_cast<Device3DImpl*>(context->reserved); 821 // TODO(apatrick): this will be much simpler when we switch to the new device
822 // API. There should be no need for the Device3DImpl and the context will
823 // always be destroyed dynamically.
824 Device3DImpl* impl = static_cast<Device3DImpl*>(context->reserved);
825 bool dynamically_created = impl->dynamically_created;
826 delete impl;
818 context->reserved = NULL; 827 context->reserved = NULL;
828 if (dynamically_created) {
829 delete context;
830 }
819 831
820 if (nested_delegate_) { 832 if (nested_delegate_) {
821 if (command_buffer_) { 833 if (command_buffer_) {
822 nested_delegate_->DestroyCommandBuffer(command_buffer_); 834 nested_delegate_->DestroyCommandBuffer(command_buffer_);
823 command_buffer_ = NULL; 835 command_buffer_ = NULL;
824 } 836 }
825 837
826 nested_delegate_->PluginDestroyed(); 838 nested_delegate_->PluginDestroyed();
827 nested_delegate_ = NULL; 839 nested_delegate_ = NULL;
828 } 840 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 } 872 }
861 873
862 NPError WebPluginDelegatePepper::Device3DMapBuffer( 874 NPError WebPluginDelegatePepper::Device3DMapBuffer(
863 NPDeviceContext3D* context, 875 NPDeviceContext3D* context,
864 int32 id, 876 int32 id,
865 NPDeviceBuffer* np_buffer) { 877 NPDeviceBuffer* np_buffer) {
866 if (!context) 878 if (!context)
867 return NPERR_GENERIC_ERROR; 879 return NPERR_GENERIC_ERROR;
868 880
869 #if defined(ENABLE_GPU) 881 #if defined(ENABLE_GPU)
870 Buffer gpu_buffer = command_buffer_->GetTransferBuffer(id); 882 Buffer gpu_buffer;
883 if (id == NP3DCommandBufferId) {
884 gpu_buffer = command_buffer_->GetRingBuffer();
885 } else {
886 gpu_buffer = command_buffer_->GetTransferBuffer(id);
887 }
888
871 np_buffer->ptr = gpu_buffer.ptr; 889 np_buffer->ptr = gpu_buffer.ptr;
872 np_buffer->size = gpu_buffer.size; 890 np_buffer->size = gpu_buffer.size;
873 if (!np_buffer->ptr) 891 if (!np_buffer->ptr)
874 return NPERR_GENERIC_ERROR; 892 return NPERR_GENERIC_ERROR;
875 #endif // ENABLE_GPU 893 #endif // ENABLE_GPU
876 894
877 return NPERR_NO_ERROR; 895 return NPERR_NO_ERROR;
878 } 896 }
879 897
898 NPError WebPluginDelegatePepper::Device3DGetNumConfigs(int32* num_configs) {
899 if (!num_configs)
900 return NPERR_GENERIC_ERROR;
901
902 *num_configs = 1;
903 return NPERR_NO_ERROR;
904 }
905
906 NPError WebPluginDelegatePepper::Device3DGetConfigAttribs(
907 int32 config,
908 int32* attrib_list) {
909 // Only one config available currently.
910 if (config != 0)
911 return NPERR_GENERIC_ERROR;
912
913 if (attrib_list) {
914 for (int32* attrib_pair = attrib_list; *attrib_pair; attrib_pair += 2) {
915 switch (attrib_pair[0]) {
916 case NP3DAttrib_BufferSize:
917 attrib_pair[1] = 32;
918 break;
919 case NP3DAttrib_AlphaSize:
920 case NP3DAttrib_BlueSize:
921 case NP3DAttrib_GreenSize:
922 case NP3DAttrib_RedSize:
923 attrib_pair[1] = 8;
924 break;
925 case NP3DAttrib_DepthSize:
926 attrib_pair[1] = 24;
927 break;
928 case NP3DAttrib_StencilSize:
929 attrib_pair[1] = 8;
930 break;
931 case NP3DAttrib_SurfaceType:
932 attrib_pair[1] = 0;
933 break;
934 default:
935 return NPERR_GENERIC_ERROR;
936 }
937 }
938 }
939
940 return NPERR_NO_ERROR;
941 }
942
943 NPError WebPluginDelegatePepper::Device3DCreateContext(
944 int32 config,
945 int32* attrib_list,
946 NPDeviceContext3D** context) {
947 if (!context)
948 return NPERR_GENERIC_ERROR;
949
950 // Only one config available currently.
951 if (config != 0)
952 return NPERR_GENERIC_ERROR;
953
954 // For now, just use the old API to initialize the context.
955 NPDeviceContext3DConfig old_config;
956 old_config.commandBufferSize = kDefaultCommandBufferSize;
957 if (attrib_list) {
958 for (int32* attrib_pair = attrib_list; *attrib_pair; attrib_pair += 2) {
959 switch (attrib_pair[0]) {
960 case NP3DAttrib_CommandBufferSize:
961 old_config.commandBufferSize = attrib_pair[1];
962 break;
963 default:
964 return NPERR_GENERIC_ERROR;
965 }
966 }
967 }
968
969 *context = new NPDeviceContext3D;
970 Device3DInitializeContext(&old_config, *context);
971
972 // Flag the context as dynamically created by the browser. TODO(apatrick):
973 // take this out when all contexts are dynamically created.
974 Device3DImpl* impl = static_cast<Device3DImpl*>((*context)->reserved);
975 impl->dynamically_created = true;
976
977 return NPERR_NO_ERROR;
978 }
979
980 NPError WebPluginDelegatePepper::Device3DRegisterCallback(
981 NPP id,
982 NPDeviceContext3D* context,
983 int32 callback_type,
984 NPDeviceGenericCallbackPtr callback,
985 void* callback_data) {
986 if (!context)
987 return NPERR_GENERIC_ERROR;
988
989 switch (callback_type) {
990 case NP3DCallback_Repaint:
991 context->repaintCallback = reinterpret_cast<NPDeviceContext3DRepaintPtr>(
992 callback);
993 break;
994 default:
995 return NPERR_GENERIC_ERROR;
996 }
997
998 return NPERR_NO_ERROR;
999 }
1000
1001 NPError WebPluginDelegatePepper::Device3DSynchronizeContext(
1002 NPP id,
1003 NPDeviceContext3D* context,
1004 NPDeviceSynchronizationMode mode,
1005 const int32* input_attrib_list,
1006 int32* output_attrib_list,
1007 NPDeviceSynchronizeContextCallbackPtr callback,
1008 void* callback_data) {
1009 if (!context)
1010 return NPERR_GENERIC_ERROR;
1011
1012 // Copy input attributes into context.
1013 if (input_attrib_list) {
1014 for (const int32* attrib_pair = input_attrib_list;
1015 *attrib_pair;
1016 attrib_pair += 2) {
1017 switch (attrib_pair[0]) {
1018 case NP3DAttrib_PutOffset:
1019 context->putOffset = attrib_pair[1];
1020 break;
1021 default:
1022 return NPERR_GENERIC_ERROR;
1023 }
1024 }
1025 }
1026
1027 // Use existing flush mechanism for now.
1028 if (mode != NPDeviceSynchronizationMode_Cached) {
1029 context->waitForProgress = mode == NPDeviceSynchronizationMode_Flush;
1030 Device3DFlushContext(id, context, callback, callback_data);
1031 }
1032
1033 // Copy most recent output attributes from context.
1034 // To read output attributes after the completion of an asynchronous flush,
1035 // invoke SynchronizeContext again with mode
1036 // NPDeviceSynchronizationMode_Cached from the callback function.
1037 if (output_attrib_list) {
1038 for (int32* attrib_pair = output_attrib_list;
1039 *attrib_pair;
1040 attrib_pair += 2) {
1041 switch (attrib_pair[0]) {
1042 case NP3DAttrib_CommandBufferSize:
1043 attrib_pair[1] = context->commandBufferSize;
1044 break;
1045 case NP3DAttrib_GetOffset:
1046 attrib_pair[1] = context->getOffset;
1047 break;
1048 case NP3DAttrib_PutOffset:
1049 attrib_pair[1] = context->putOffset;
1050 break;
1051 case NP3DAttrib_Token:
1052 attrib_pair[1] = context->token;
1053 break;
1054 default:
1055 return NPERR_GENERIC_ERROR;
1056 }
1057 }
1058 }
1059
1060 return NPERR_NO_ERROR;
1061 }
1062
880 NPError WebPluginDelegatePepper::DeviceAudioQueryCapability(int32 capability, 1063 NPError WebPluginDelegatePepper::DeviceAudioQueryCapability(int32 capability,
881 int32* value) { 1064 int32* value) {
882 // TODO(neb,cpu) implement QueryCapability 1065 // TODO(neb,cpu) implement QueryCapability
883 return NPERR_GENERIC_ERROR; 1066 return NPERR_GENERIC_ERROR;
884 } 1067 }
885 1068
886 NPError WebPluginDelegatePepper::DeviceAudioQueryConfig( 1069 NPError WebPluginDelegatePepper::DeviceAudioQueryConfig(
887 const NPDeviceContextAudioConfig* request, 1070 const NPDeviceContextAudioConfig* request,
888 NPDeviceContextAudioConfig* obtain) { 1071 NPDeviceContextAudioConfig* obtain) {
889 // TODO(neb,cpu) implement QueryConfig 1072 // TODO(neb,cpu) implement QueryConfig
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1456 StretchDIBits(dc, printable_area.x(), printable_area.y(), 1639 StretchDIBits(dc, printable_area.x(), printable_area.y(),
1457 printable_area.width(), printable_area.height(), 1640 printable_area.width(), printable_area.height(),
1458 0, 0, bitmap.width(), bitmap.height(), 1641 0, 0, bitmap.width(), bitmap.height(),
1459 &compressed_image.front(), 1642 &compressed_image.front(),
1460 reinterpret_cast<const BITMAPINFO*>(&bmi), 1643 reinterpret_cast<const BITMAPINFO*>(&bmi),
1461 DIB_RGB_COLORS, SRCCOPY); 1644 DIB_RGB_COLORS, SRCCOPY);
1462 return true; 1645 return true;
1463 } 1646 }
1464 #endif // OS_WIN 1647 #endif // OS_WIN
1465 1648
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698