diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-13 19:22:53 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-13 19:22:53 +0000 |
commit | 55cdf605cda8900f0c6c4d8098fb1ba951767fd2 (patch) | |
tree | 05f1d89fdf3f46d1cfd4350ee169ca9c282ae5e0 /ppapi | |
parent | e1873b977ecb681d9261d9ce9fbe606e036b7d5b (diff) | |
download | chromium_src-55cdf605cda8900f0c6c4d8098fb1ba951767fd2.zip chromium_src-55cdf605cda8900f0c6c4d8098fb1ba951767fd2.tar.gz chromium_src-55cdf605cda8900f0c6c4d8098fb1ba951767fd2.tar.bz2 |
Convert audio-related messages to the new thunk/API system for Pepper.
This has a bit of a change from the previous couple of resources that were
converted in that the ResourceCreationProxy now calls a static proxy function
for actually doing the work. It became too complicated and required that the
ResourceCreationProxy know a lot about the internals of the objects.
Did a little namespace cleanup. This renames "pp::shared_impl" to just use the
"ppapi" namespace. The "shared_impl" was ugly and didn't help anything. Some
files in that directory used "ppapi::shared_impl" instead which was even more
confusing.
Do a little build cleanup. The old ppapi_shared_proxy.gypi is now split into
two sub-files, one for ppapi_shared, and one for ppapi_proxy. It's hopefully
easier to find stuff now.
Review URL: http://codereview.chromium.org/7014024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85303 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
55 files changed, 784 insertions, 407 deletions
diff --git a/ppapi/examples/audio/audio.cc b/ppapi/examples/audio/audio.cc index 3e0fedd..91042fa 100644 --- a/ppapi/examples/audio/audio.cc +++ b/ppapi/examples/audio/audio.cc @@ -43,7 +43,7 @@ class MyInstance : public pp::Instance { } private: - static void SineWaveCallback(void* samples, size_t num_bytes, void* thiz) { + static void SineWaveCallback(void* samples, uint32_t num_bytes, void* thiz) { const double delta_l = kTwoPi * frequency_l / sample_frequency; const double delta_r = kTwoPi * frequency_r / sample_frequency; diff --git a/ppapi/ppapi_internal.gyp b/ppapi/ppapi_internal.gyp index 520c3cc..5714516 100644 --- a/ppapi/ppapi_internal.gyp +++ b/ppapi/ppapi_internal.gyp @@ -24,7 +24,8 @@ ], }, 'includes': [ - 'ppapi_shared_proxy.gypi', + 'ppapi_proxy.gypi', + 'ppapi_shared.gypi', 'ppapi_tests.gypi', ], } diff --git a/ppapi/ppapi_shared_proxy.gypi b/ppapi/ppapi_proxy.gypi index 5656970..06ed0ff 100644 --- a/ppapi/ppapi_shared_proxy.gypi +++ b/ppapi/ppapi_proxy.gypi @@ -5,57 +5,6 @@ { 'targets': [ { - 'target_name': 'ppapi_shared_impl', - 'type': 'static_library', - 'dependencies': [ - 'ppapi.gyp:ppapi_c', - '../base/base.gyp:base', - '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', - '../build/temp_gyp/googleurl.gyp:googleurl', - '../skia/skia.gyp:skia', - '../third_party/icu/icu.gyp:icuuc', - '../ui/gfx/surface/surface.gyp:surface', - ], - 'include_dirs': [ - '..', - ], - 'export_dependent_settings': [ - '../base/base.gyp:base', - ], - 'sources': [ - 'shared_impl/audio_impl.cc', - 'shared_impl/audio_impl.h', - 'shared_impl/char_set_impl.cc', - 'shared_impl/char_set_impl.h', - 'shared_impl/crypto_impl.cc', - 'shared_impl/crypto_impl.h', - 'shared_impl/font_impl.cc', - 'shared_impl/font_impl.h', - 'shared_impl/image_data_impl.cc', - 'shared_impl/image_data_impl.h', - 'shared_impl/tracker_base.cc', - 'shared_impl/tracker_base.h', - 'shared_impl/url_util_impl.cc', - 'shared_impl/url_util_impl.h', - 'shared_impl/webkit_forwarding.cc', - 'shared_impl/webkit_forwarding.h', - - 'thunk/enter.h', - 'thunk/ppb_font_api.h', - 'thunk/ppb_font_thunk.cc', - 'thunk/ppb_graphics_2d_api.h', - 'thunk/ppb_graphics_2d_thunk.cc', - 'thunk/ppb_image_data_api.h', - 'thunk/ppb_image_data_thunk.cc', - 'thunk/thunk.h', - ], - 'conditions': [ - ['OS=="win"', { - 'msvs_guid': 'E7420D65-A885-41EB-B4BE-04DE0C97033B', - }], - ], - }, - { 'target_name': 'ppapi_proxy', 'type': 'static_library', 'dependencies': [ @@ -64,7 +13,7 @@ '../skia/skia.gyp:skia', '../ui/gfx/surface/surface.gyp:surface', 'ppapi.gyp:ppapi_c', - 'ppapi_shared_impl', + 'ppapi_shared', ], 'all_dependent_settings': { 'include_dirs': [ diff --git a/ppapi/ppapi_shared.gypi b/ppapi/ppapi_shared.gypi new file mode 100644 index 0000000..386159b --- /dev/null +++ b/ppapi/ppapi_shared.gypi @@ -0,0 +1,67 @@ +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +{ + 'targets': [ + { + 'target_name': 'ppapi_shared', + 'type': 'static_library', + 'dependencies': [ + 'ppapi.gyp:ppapi_c', + '../base/base.gyp:base', + '../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', + '../build/temp_gyp/googleurl.gyp:googleurl', + '../skia/skia.gyp:skia', + '../third_party/icu/icu.gyp:icuuc', + '../ui/gfx/surface/surface.gyp:surface', + ], + 'include_dirs': [ + '..', + ], + 'export_dependent_settings': [ + '../base/base.gyp:base', + ], + 'sources': [ + 'shared_impl/audio_config_impl.cc', + 'shared_impl/audio_config_impl.h', + 'shared_impl/audio_impl.cc', + 'shared_impl/audio_impl.h', + 'shared_impl/char_set_impl.cc', + 'shared_impl/char_set_impl.h', + 'shared_impl/crypto_impl.cc', + 'shared_impl/crypto_impl.h', + 'shared_impl/font_impl.cc', + 'shared_impl/font_impl.h', + 'shared_impl/image_data_impl.cc', + 'shared_impl/image_data_impl.h', + 'shared_impl/tracker_base.cc', + 'shared_impl/tracker_base.h', + 'shared_impl/url_util_impl.cc', + 'shared_impl/url_util_impl.h', + 'shared_impl/webkit_forwarding.cc', + 'shared_impl/webkit_forwarding.h', + + 'thunk/enter.h', + 'thunk/ppb_audio_api.h', + 'thunk/ppb_audio_config_api.h', + 'thunk/ppb_audio_config_thunk.cc', + 'thunk/ppb_audio_thunk.cc', + 'thunk/ppb_audio_trusted_api.h', + 'thunk/ppb_audio_trusted_thunk.cc', + 'thunk/ppb_font_api.h', + 'thunk/ppb_font_thunk.cc', + 'thunk/ppb_graphics_2d_api.h', + 'thunk/ppb_graphics_2d_thunk.cc', + 'thunk/ppb_image_data_api.h', + 'thunk/ppb_image_data_thunk.cc', + 'thunk/thunk.h', + ], + 'conditions': [ + ['OS=="win"', { + 'msvs_guid': 'E7420D65-A885-41EB-B4BE-04DE0C97033B', + }], + ], + }, + ], +} diff --git a/ppapi/proxy/dispatcher.h b/ppapi/proxy/dispatcher.h index 2dd8052..2dc1fe6 100644 --- a/ppapi/proxy/dispatcher.h +++ b/ppapi/proxy/dispatcher.h @@ -20,12 +20,11 @@ #include "ppapi/proxy/interface_proxy.h" #include "ppapi/proxy/plugin_var_tracker.h" -namespace pp { - -namespace shared_impl { +namespace ppapi { class WebKitForwarding; } +namespace pp { namespace proxy { class VarSerializationRules; @@ -60,7 +59,7 @@ class Dispatcher : public ProxyChannel { // Returns the WebKit forwarding object used to make calls into WebKit. // Necessary only on the plugin side. The host side can return NULL. - virtual pp::shared_impl::WebKitForwarding* GetWebKitForwarding() = 0; + virtual ppapi::WebKitForwarding* GetWebKitForwarding() = 0; // Posts the given task to the WebKit thread associated with this plugin // process. For host processes, this will not be called and can do diff --git a/ppapi/proxy/host_dispatcher.h b/ppapi/proxy/host_dispatcher.h index 29d3c25..608223d 100644 --- a/ppapi/proxy/host_dispatcher.h +++ b/ppapi/proxy/host_dispatcher.h @@ -119,7 +119,7 @@ class HostDispatcher : public Dispatcher { // Function proxies created for "new-style" FunctionGroups. // TODO(brettw) this is in progress. It should be merged with the target // proxies so there is one list to consult. - scoped_ptr< ::ppapi::shared_impl::FunctionGroupBase > + scoped_ptr< ::ppapi::FunctionGroupBase > function_proxies_[INTERFACE_ID_COUNT]; // Guaranteed non-NULL. diff --git a/ppapi/proxy/host_resource.h b/ppapi/proxy/host_resource.h index badd2fd..fe1abb2 100644 --- a/ppapi/proxy/host_resource.h +++ b/ppapi/proxy/host_resource.h @@ -27,6 +27,16 @@ class HostResource { return !host_resource_; } + // Some resources are plugin-side only and don't have a corresponding + // resource in the host. Yet these resources still need an instance to be + // associated with. This function creates a HostResource with the given + // instances and a 0 host resource ID for these cases. + static HostResource MakeInstanceOnly(PP_Instance instance) { + HostResource resource; + resource.SetHostResource(instance, 0); + return resource; + } + // Sets and retrieves the internal PP_Resource which is valid for the host // (a.k.a. renderer, as opposed to the plugin) process. // diff --git a/ppapi/proxy/plugin_dispatcher.cc b/ppapi/proxy/plugin_dispatcher.cc index 2a79e91..b8ac146 100644 --- a/ppapi/proxy/plugin_dispatcher.cc +++ b/ppapi/proxy/plugin_dispatcher.cc @@ -45,7 +45,7 @@ PluginDispatcher::PluginDispatcher(base::ProcessHandle remote_process_handle, // GetInterface call or name for it, so we insert it into our table now. target_proxies_[INTERFACE_ID_PPP_CLASS].reset(new PPP_Class_Proxy(this)); - ::ppapi::shared_impl::TrackerBase::Init( + ::ppapi::TrackerBase::Init( &PluginResourceTracker::GetTrackerBaseInstance); } @@ -208,11 +208,11 @@ void PluginDispatcher::PostToWebKitThread( return dispatcher_delegate_->PostToWebKitThread(from_here, task); } -pp::shared_impl::WebKitForwarding* PluginDispatcher::GetWebKitForwarding() { +ppapi::WebKitForwarding* PluginDispatcher::GetWebKitForwarding() { return dispatcher_delegate_->GetWebKitForwarding(); } -::ppapi::shared_impl::FunctionGroupBase* PluginDispatcher::GetFunctionAPI( +::ppapi::FunctionGroupBase* PluginDispatcher::GetFunctionAPI( pp::proxy::InterfaceID id) { if (function_proxies_[id].get()) return function_proxies_[id].get(); diff --git a/ppapi/proxy/plugin_dispatcher.h b/ppapi/proxy/plugin_dispatcher.h index 959a7ac..65c4c82 100644 --- a/ppapi/proxy/plugin_dispatcher.h +++ b/ppapi/proxy/plugin_dispatcher.h @@ -80,13 +80,13 @@ class PluginDispatcher : public Dispatcher { const base::Closure& task); // Returns the WebKitForwarding object used to forward events to WebKit. - pp::shared_impl::WebKitForwarding* GetWebKitForwarding(); + ppapi::WebKitForwarding* GetWebKitForwarding(); // Returns the "new-style" function API for the given interface ID, creating // it if necessary. // TODO(brettw) this is in progress. It should be merged with the target // proxies so there is one list to consult. - ::ppapi::shared_impl::FunctionGroupBase* GetFunctionAPI( + ppapi::FunctionGroupBase* GetFunctionAPI( pp::proxy::InterfaceID id); private: @@ -106,7 +106,7 @@ class PluginDispatcher : public Dispatcher { // Function proxies created for "new-style" FunctionGroups. // TODO(brettw) this is in progress. It should be merged with the target // proxies so there is one list to consult. - scoped_ptr< ::ppapi::shared_impl::FunctionGroupBase > + scoped_ptr< ::ppapi::FunctionGroupBase > function_proxies_[INTERFACE_ID_COUNT]; typedef base::hash_map<PP_Instance, InstanceData> InstanceDataMap; diff --git a/ppapi/proxy/plugin_resource.h b/ppapi/proxy/plugin_resource.h index 5009af8..eff74b4 100644 --- a/ppapi/proxy/plugin_resource.h +++ b/ppapi/proxy/plugin_resource.h @@ -42,7 +42,7 @@ namespace proxy { FOR_ALL_PLUGIN_RESOURCES(DECLARE_RESOURCE_CLASS) #undef DECLARE_RESOURCE_CLASS -class PluginResource : public ::ppapi::shared_impl::ResourceObjectBase { +class PluginResource : public ::ppapi::ResourceObjectBase { public: PluginResource(const HostResource& resource); virtual ~PluginResource(); diff --git a/ppapi/proxy/plugin_resource_tracker.cc b/ppapi/proxy/plugin_resource_tracker.cc index 24d1281..a6e087f 100644 --- a/ppapi/proxy/plugin_resource_tracker.cc +++ b/ppapi/proxy/plugin_resource_tracker.cc @@ -20,7 +20,7 @@ namespace { // When non-NULL, this object overrides the ResourceTrackerSingleton. PluginResourceTracker* g_resource_tracker_override = NULL; -::ppapi::shared_impl::TrackerBase* GetTrackerBase() { +::ppapi::TrackerBase* GetTrackerBase() { return PluginResourceTracker::GetInstance(); } @@ -39,7 +39,7 @@ PluginResourceTracker::ResourceInfo::ResourceInfo(const ResourceInfo& other) : ref_count(other.ref_count), resource(other.resource) { // Wire up the new shared resource tracker base to use our implementation. - ::ppapi::shared_impl::TrackerBase::Init(&GetTrackerBase); + ::ppapi::TrackerBase::Init(&GetTrackerBase); } PluginResourceTracker::ResourceInfo::~ResourceInfo() { @@ -75,7 +75,7 @@ PluginResourceTracker* PluginResourceTracker::GetInstance() { } // static -::ppapi::shared_impl::TrackerBase* +::ppapi::TrackerBase* PluginResourceTracker::GetTrackerBaseInstance() { return GetInstance(); } @@ -122,7 +122,7 @@ PP_Resource PluginResourceTracker::PluginResourceForHostResource( return found->second; } -::ppapi::shared_impl::ResourceObjectBase* PluginResourceTracker::GetResourceAPI( +::ppapi::ResourceObjectBase* PluginResourceTracker::GetResourceAPI( PP_Resource res) { ResourceMap::iterator found = resource_map_.find(res); if (found == resource_map_.end()) @@ -130,7 +130,7 @@ PP_Resource PluginResourceTracker::PluginResourceForHostResource( return found->second.resource.get(); } -::ppapi::shared_impl::FunctionGroupBase* PluginResourceTracker::GetFunctionAPI( +::ppapi::FunctionGroupBase* PluginResourceTracker::GetFunctionAPI( PP_Instance inst, pp::proxy::InterfaceID id) { PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(inst); diff --git a/ppapi/proxy/plugin_resource_tracker.h b/ppapi/proxy/plugin_resource_tracker.h index 268709f..5dfdf82 100644 --- a/ppapi/proxy/plugin_resource_tracker.h +++ b/ppapi/proxy/plugin_resource_tracker.h @@ -25,7 +25,7 @@ namespace proxy { class PluginDispatcher; class PluginResource; -class PluginResourceTracker : public ::ppapi::shared_impl::TrackerBase { +class PluginResourceTracker : public ::ppapi::TrackerBase { public: // Called by tests that want to specify a specific ResourceTracker. This // allows them to use a unique one each time and avoids singletons sticking @@ -34,7 +34,7 @@ class PluginResourceTracker : public ::ppapi::shared_impl::TrackerBase { // Returns the global singleton resource tracker for the plugin. static PluginResourceTracker* GetInstance(); - static ::ppapi::shared_impl::TrackerBase* GetTrackerBaseInstance(); + static ::ppapi::TrackerBase* GetTrackerBaseInstance(); // Returns the object associated with the given resource ID, or NULL if // there isn't one. @@ -55,9 +55,9 @@ class PluginResourceTracker : public ::ppapi::shared_impl::TrackerBase { const HostResource& resource) const; // TrackerBase. - virtual ::ppapi::shared_impl::ResourceObjectBase* GetResourceAPI( + virtual ::ppapi::ResourceObjectBase* GetResourceAPI( PP_Resource res); - virtual ::ppapi::shared_impl::FunctionGroupBase* GetFunctionAPI( + virtual ::ppapi::FunctionGroupBase* GetFunctionAPI( PP_Instance inst, pp::proxy::InterfaceID id); diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index a5decc8..d00e6d0 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -250,26 +250,15 @@ IPC_MESSAGE_CONTROL1(PpapiHostMsg_ChannelCreated, IPC::ChannelHandle /* handle */) // PPB_Audio. -IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBAudio_Create, +IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBAudio_Create, PP_Instance /* instance_id */, - pp::proxy::HostResource /* config_id */, + int32_t /* sample_rate */, + uint32_t /* sample_frame_count */, pp::proxy::HostResource /* result */) IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBAudio_StartOrStop, pp::proxy::HostResource /* audio_id */, bool /* play */) -// PPB_AudioConfig. -IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBAudioConfig_Create, - PP_Instance /* instance */, - int32_t /* sample_rate */, - uint32_t /* sample_frame_count */, - pp::proxy::HostResource /* result */) -IPC_SYNC_MESSAGE_ROUTED2_1( - PpapiHostMsg_PPBAudioConfig_RecommendSampleFrameCount, - int32_t /* sample_rate */, - uint32_t /* requested */, - uint32_t /* result */) - // PPB_Broker. IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBBroker_Create, PP_Instance /* instance */, diff --git a/ppapi/proxy/ppb_audio_config_proxy.cc b/ppapi/proxy/ppb_audio_config_proxy.cc index 0c8eaab..8e78ecd 100644 --- a/ppapi/proxy/ppb_audio_config_proxy.cc +++ b/ppapi/proxy/ppb_audio_config_proxy.cc @@ -8,92 +8,39 @@ #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/shared_impl/audio_config_impl.h" +#include "ppapi/thunk/thunk.h" namespace pp { namespace proxy { -class AudioConfig : public PluginResource { +// The implementation is actually in AudioConfigImpl. +class AudioConfig : public PluginResource, + public ppapi::AudioConfigImpl { public: - AudioConfig(const HostResource& resource, - PP_AudioSampleRate sample_rate, - uint32_t sample_frame_count) - : PluginResource(resource), - sample_rate_(sample_rate), - sample_frame_count_(sample_frame_count) { - } - virtual ~AudioConfig() {} + // Note that you must call Init (on AudioConfigImpl) before using this class. + AudioConfig(const HostResource& resource); + virtual ~AudioConfig(); - // Resource overrides. - virtual AudioConfig* AsAudioConfig() { return this; } - - PP_AudioSampleRate sample_rate() const { return sample_rate_; } - uint32_t sample_frame_count() const { return sample_frame_count_; } + // ResourceObjectBase overrides. + virtual ::ppapi::thunk::PPB_AudioConfig_API* AsAudioConfig_API() OVERRIDE; private: - PP_AudioSampleRate sample_rate_; - uint32_t sample_frame_count_; - DISALLOW_COPY_AND_ASSIGN(AudioConfig); }; -namespace { - -PP_Resource CreateStereo16bit(PP_Instance instance, - PP_AudioSampleRate sample_rate, - uint32_t sample_frame_count) { - HostResource resource; - PluginDispatcher::GetForInstance(instance)->Send( - new PpapiHostMsg_PPBAudioConfig_Create( - INTERFACE_ID_PPB_AUDIO_CONFIG, instance, - static_cast<int32_t>(sample_rate), sample_frame_count, - &resource)); - if (resource.is_null()) - return 0; - - linked_ptr<AudioConfig> object( - new AudioConfig(resource, sample_rate, sample_frame_count)); - return PluginResourceTracker::GetInstance()->AddResource(object); -} - -uint32_t RecommendSampleFrameCount(PP_AudioSampleRate sample_rate, - uint32_t requested_sample_frame_count) { - // TODO(brettw) Currently we don't actually query to get a value from the - // hardware, so we always return the input for in-range values. - // - // Danger: this code is duplicated in the audio config implementation. - if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) - return PP_AUDIOMINSAMPLEFRAMECOUNT; - if (requested_sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT) - return PP_AUDIOMAXSAMPLEFRAMECOUNT; - return requested_sample_frame_count; +AudioConfig::AudioConfig(const HostResource& resource) + : PluginResource(resource) { } -PP_Bool IsAudioConfig(PP_Resource resource) { - AudioConfig* object = PluginResource::GetAs<AudioConfig>(resource); - return BoolToPPBool(!!object); +AudioConfig::~AudioConfig() { } -PP_AudioSampleRate GetSampleRate(PP_Resource config_id) { - AudioConfig* object = PluginResource::GetAs<AudioConfig>(config_id); - if (!object) - return PP_AUDIOSAMPLERATE_NONE; - return object->sample_rate(); +::ppapi::thunk::PPB_AudioConfig_API* AudioConfig::AsAudioConfig_API() { + return this; } -uint32_t GetSampleFrameCount(PP_Resource config_id) { - AudioConfig* object = PluginResource::GetAs<AudioConfig>(config_id); - if (!object) - return 0; - return object->sample_frame_count(); -} - -const PPB_AudioConfig audio_config_interface = { - &CreateStereo16bit, - &RecommendSampleFrameCount, - &IsAudioConfig, - &GetSampleRate, - &GetSampleFrameCount -}; +namespace { InterfaceProxy* CreateAudioConfigProxy(Dispatcher* dispatcher, const void* target_interface) { @@ -113,7 +60,7 @@ PPB_AudioConfig_Proxy::~PPB_AudioConfig_Proxy() { // static const InterfaceProxy::Info* PPB_AudioConfig_Proxy::GetInfo() { static const Info info = { - &audio_config_interface, + ::ppapi::thunk::GetPPB_AudioConfig_Thunk(), PPB_AUDIO_CONFIG_INTERFACE, INTERFACE_ID_PPB_AUDIO_CONFIG, false, @@ -122,35 +69,22 @@ const InterfaceProxy::Info* PPB_AudioConfig_Proxy::GetInfo() { return &info; } -bool PPB_AudioConfig_Proxy::OnMessageReceived(const IPC::Message& msg) { - bool handled = true; - IPC_BEGIN_MESSAGE_MAP(PPB_AudioConfig_Proxy, msg) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudioConfig_Create, - OnMsgCreateStereo16Bit) - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBAudioConfig_RecommendSampleFrameCount, - OnMsgRecommendSampleFrameCount) - IPC_MESSAGE_UNHANDLED(handled = false) - IPC_END_MESSAGE_MAP() - return handled; -} - -void PPB_AudioConfig_Proxy::OnMsgCreateStereo16Bit(PP_Instance instance, - int32_t sample_rate, - uint32_t sample_frame_count, - HostResource* result) { - result->SetHostResource(instance, - ppb_audio_config_target()->CreateStereo16Bit( - instance, static_cast<PP_AudioSampleRate>(sample_rate), - sample_frame_count)); +// static +PP_Resource PPB_AudioConfig_Proxy::CreateProxyResource( + PP_Instance instance, + PP_AudioSampleRate sample_rate, + uint32_t sample_frame_count) { + linked_ptr<AudioConfig> object(new AudioConfig( + HostResource::MakeInstanceOnly(instance))); + if (!object->Init(sample_rate, sample_frame_count)) + return 0; + return PluginResourceTracker::GetInstance()->AddResource(object); } -void PPB_AudioConfig_Proxy::OnMsgRecommendSampleFrameCount( - int32_t sample_rate, - uint32_t requested_sample_frame_count, - uint32_t* result) { - *result = ppb_audio_config_target()->RecommendSampleFrameCount( - static_cast<PP_AudioSampleRate>(sample_rate), - requested_sample_frame_count); +bool PPB_AudioConfig_Proxy::OnMessageReceived(const IPC::Message& msg) { + // There are no IPC messages for this interface. + NOTREACHED(); + return false; } } // namespace proxy diff --git a/ppapi/proxy/ppb_audio_config_proxy.h b/ppapi/proxy/ppb_audio_config_proxy.h index c6c9588..e8a12e8 100644 --- a/ppapi/proxy/ppb_audio_config_proxy.h +++ b/ppapi/proxy/ppb_audio_config_proxy.h @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_resource.h" +#include "ppapi/c/ppb_audio_config.h" #include "ppapi/proxy/interface_proxy.h" struct PPB_AudioConfig; @@ -24,23 +25,14 @@ class PPB_AudioConfig_Proxy : public InterfaceProxy { static const Info* GetInfo(); - const PPB_AudioConfig* ppb_audio_config_target() const { - return static_cast<const PPB_AudioConfig*>(target_interface()); - } + static PP_Resource CreateProxyResource(PP_Instance instance, + PP_AudioSampleRate sample_rate, + uint32_t sample_frame_count); // InterfaceProxy implementation. virtual bool OnMessageReceived(const IPC::Message& msg); private: - // Message handlers. - void OnMsgCreateStereo16Bit(PP_Instance instance, - int32_t sample_rate, - uint32_t sample_frame_count, - HostResource* result); - void OnMsgRecommendSampleFrameCount(int32_t sample_rate, - uint32_t requested, - uint32_t* result); - DISALLOW_COPY_AND_ASSIGN(PPB_AudioConfig_Proxy); }; diff --git a/ppapi/proxy/ppb_audio_proxy.cc b/ppapi/proxy/ppb_audio_proxy.cc index 6e34674..6c2cc7a 100644 --- a/ppapi/proxy/ppb_audio_proxy.cc +++ b/ppapi/proxy/ppb_audio_proxy.cc @@ -7,122 +7,92 @@ #include "base/threading/simple_thread.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppb_audio.h" +#include "ppapi/c/ppb_audio_config.h" +#include "ppapi/c/ppb_var.h" #include "ppapi/c/trusted/ppb_audio_trusted.h" #include "ppapi/proxy/interface_id.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/shared_impl/audio_impl.h" +#include "ppapi/thunk/ppb_audio_config_api.h" +#include "ppapi/thunk/ppb_audio_trusted_api.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/resource_creation_api.h" +#include "ppapi/thunk/thunk.h" namespace pp { namespace proxy { -class Audio : public PluginResource, public pp::shared_impl::AudioImpl { +class Audio : public PluginResource, public ppapi::AudioImpl { public: Audio(const HostResource& audio_id, PP_Resource config_id, PPB_Audio_Callback callback, - void* user_data) - : PluginResource(audio_id), - config_(config_id) { - SetCallback(callback, user_data); - PluginResourceTracker::GetInstance()->AddRefResource(config_); - } - virtual ~Audio() { - PluginResourceTracker::GetInstance()->ReleaseResource(config_); - } - - // Resource overrides. - virtual Audio* AsAudio() { return this; } + void* user_data); + virtual ~Audio(); - PP_Resource config() const { return config_; } + // ResourceObjectBase overrides. + virtual ::ppapi::thunk::PPB_Audio_API* AsAudio_API(); - void StartPlayback(PP_Resource resource) { - if (playing()) - return; - SetStartPlaybackState(); - PluginDispatcher::GetForInstance(instance())->Send( - new PpapiHostMsg_PPBAudio_StartOrStop( - INTERFACE_ID_PPB_AUDIO, host_resource(), true)); - } - - void StopPlayback(PP_Resource resource) { - if (!playing()) - return; - PluginDispatcher::GetForInstance(instance())->Send( - new PpapiHostMsg_PPBAudio_StartOrStop( - INTERFACE_ID_PPB_AUDIO, host_resource(), false)); - SetStopPlaybackState(); - } + // PPB_Audio_API implementation. + virtual PP_Resource GetCurrentConfig() OVERRIDE; + virtual PP_Bool StartPlayback() OVERRIDE; + virtual PP_Bool StopPlayback() OVERRIDE; private: + // Owning reference to the current config object. This isn't actually used, + // we just dish it out as requested by the plugin. PP_Resource config_; DISALLOW_COPY_AND_ASSIGN(Audio); }; -namespace { - -PP_Resource Create(PP_Instance instance_id, - PP_Resource config_id, - PPB_Audio_Callback callback, - void* user_data) { - PluginResource* config = PluginResourceTracker::GetInstance()-> - GetResourceObject(config_id); - if (!config) - return 0; - - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); - if (!dispatcher) - return 0; - - HostResource result; - dispatcher->Send(new PpapiHostMsg_PPBAudio_Create( - INTERFACE_ID_PPB_AUDIO, instance_id, config->host_resource(), &result)); - if (result.is_null()) - return 0; +Audio::Audio(const HostResource& audio_id, + PP_Resource config_id, + PPB_Audio_Callback callback, + void* user_data) + : PluginResource(audio_id), + config_(config_id) { + SetCallback(callback, user_data); + PluginResourceTracker::GetInstance()->AddRefResource(config_); +} - linked_ptr<Audio> object(new Audio(result, config_id, callback, user_data)); - return PluginResourceTracker::GetInstance()->AddResource(object); +Audio::~Audio() { + PluginResourceTracker::GetInstance()->ReleaseResource(config_); } -PP_Bool IsAudio(PP_Resource resource) { - Audio* object = PluginResource::GetAs<Audio>(resource); - return BoolToPPBool(!!object); +::ppapi::thunk::PPB_Audio_API* Audio::AsAudio_API() { + return this; } -PP_Resource GetCurrentConfiguration(PP_Resource audio_id) { - Audio* object = PluginResource::GetAs<Audio>(audio_id); - if (!object) - return 0; - PP_Resource result = object->config(); - PluginResourceTracker::GetInstance()->AddRefResource(result); - return result; +PP_Resource Audio::GetCurrentConfig() { + // AddRef for the caller. + PluginResourceTracker::GetInstance()->AddRefResource(config_); + return config_; } -PP_Bool StartPlayback(PP_Resource audio_id) { - Audio* object = PluginResource::GetAs<Audio>(audio_id); - if (!object) - return PP_FALSE; - object->StartPlayback(audio_id); +PP_Bool Audio::StartPlayback() { + if (playing()) + return PP_TRUE; + SetStartPlaybackState(); + PluginDispatcher::GetForInstance(instance())->Send( + new PpapiHostMsg_PPBAudio_StartOrStop( + INTERFACE_ID_PPB_AUDIO, host_resource(), true)); return PP_TRUE; } -PP_Bool StopPlayback(PP_Resource audio_id) { - Audio* object = PluginResource::GetAs<Audio>(audio_id); - if (!object) - return PP_FALSE; - object->StopPlayback(audio_id); +PP_Bool Audio::StopPlayback() { + if (!playing()) + return PP_TRUE; + PluginDispatcher::GetForInstance(instance())->Send( + new PpapiHostMsg_PPBAudio_StartOrStop( + INTERFACE_ID_PPB_AUDIO, host_resource(), false)); + SetStopPlaybackState(); return PP_TRUE; } -const PPB_Audio audio_interface = { - &Create, - &IsAudio, - &GetCurrentConfiguration, - &StartPlayback, - &StopPlayback -}; +namespace { InterfaceProxy* CreateAudioProxy(Dispatcher* dispatcher, const void* target_interface) { @@ -155,7 +125,7 @@ PPB_Audio_Proxy::~PPB_Audio_Proxy() { // static const InterfaceProxy::Info* PPB_Audio_Proxy::GetInfo() { static const Info info = { - &audio_interface, + ppapi::thunk::GetPPB_Audio_Thunk(), PPB_AUDIO_INTERFACE, INTERFACE_ID_PPB_AUDIO, false, @@ -164,6 +134,34 @@ const InterfaceProxy::Info* PPB_Audio_Proxy::GetInfo() { return &info; } +// static +PP_Resource PPB_Audio_Proxy::CreateProxyResource( + PP_Instance instance_id, + PP_Resource config_id, + PPB_Audio_Callback audio_callback, + void* user_data) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); + if (!dispatcher) + return 0; + + ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_AudioConfig_API> + config(config_id, true); + if (config.failed()) + return 0; + + HostResource result; + dispatcher->Send(new PpapiHostMsg_PPBAudio_Create( + INTERFACE_ID_PPB_AUDIO, instance_id, + config.object()->GetSampleRate(), config.object()->GetSampleFrameCount(), + &result)); + if (result.is_null()) + return 0; + + linked_ptr<Audio> object(new Audio(result, config_id, + audio_callback, user_data)); + return PluginResourceTracker::GetInstance()->AddResource(object); +} + bool PPB_Audio_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_Audio_Proxy, msg) @@ -178,26 +176,45 @@ bool PPB_Audio_Proxy::OnMessageReceived(const IPC::Message& msg) { } void PPB_Audio_Proxy::OnMsgCreate(PP_Instance instance_id, - const HostResource& config_id, + int32_t sample_rate, + uint32_t sample_frame_count, HostResource* result) { - const PPB_AudioTrusted* audio_trusted = - reinterpret_cast<const PPB_AudioTrusted*>( - dispatcher()->GetLocalInterface(PPB_AUDIO_TRUSTED_INTERFACE)); - if (!audio_trusted) + ::ppapi::thunk::EnterFunction< ::ppapi::thunk::ResourceCreationAPI> + resource_creation(instance_id, true); + if (resource_creation.failed()) return; - result->SetHostResource(instance_id, - audio_trusted->CreateTrusted(instance_id)); + // Make the resource and get the API pointer to its trusted interface. + result->SetHostResource( + instance_id, + resource_creation.functions()->CreateAudioTrusted(instance_id)); if (result->is_null()) return; + ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_AudioTrusted_API> + trusted_audio(result->host_resource(), false); + if (trusted_audio.failed()) + return; + // Make an audio config object. + PP_Resource audio_config_res = + resource_creation.functions()->CreateAudioConfig( + instance_id, static_cast<PP_AudioSampleRate>(sample_rate), + sample_frame_count); + if (!audio_config_res) + return; + + // Initiate opening the audio object. CompletionCallback callback = callback_factory_.NewCallback( &PPB_Audio_Proxy::AudioChannelConnected, *result); - int32_t open_error = audio_trusted->Open(result->host_resource(), - config_id.host_resource(), - callback.pp_completion_callback()); + int32_t open_error = trusted_audio.object()->OpenTrusted( + audio_config_res, callback.pp_completion_callback()); if (open_error != PP_OK_COMPLETIONPENDING) callback.Run(open_error); + + // Clean up the temporary audio config resource we made. + const PPB_Core* core = static_cast<const PPB_Core*>( + dispatcher()->GetLocalInterface(PPB_CORE_INTERFACE)); + core->ReleaseResource(audio_config_res); } void PPB_Audio_Proxy::OnMsgStartOrStop(const HostResource& audio_id, @@ -218,9 +235,9 @@ void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( PP_Resource plugin_resource = PluginResourceTracker::GetInstance()->PluginResourceForHostResource( audio_id); - Audio* object = plugin_resource ? - PluginResource::GetAs<Audio>(plugin_resource) : NULL; - if (!object || result_code != PP_OK) { + ppapi::thunk::EnterResource<ppapi::thunk::PPB_Audio_API> enter( + plugin_resource, false); + if (enter.failed() || result_code != PP_OK) { // The caller may still have given us these handles in the failure case. // The easiest way to clean these up is to just put them in the objects // and then close them. This failure case is not performance critical. @@ -229,7 +246,8 @@ void PPB_Audio_Proxy::OnMsgNotifyAudioStreamCreated( base::SharedMemory temp_mem(handle, false); return; } - object->SetStreamInfo( + Audio* audio = static_cast<Audio*>(enter.object()); + audio->SetStreamInfo( handle, length, IPC::PlatformFileForTransitToPlatformFile(socket_handle)); } @@ -264,16 +282,14 @@ int32_t PPB_Audio_Proxy::GetAudioConnectedHandles( base::SharedMemoryHandle* foreign_shared_memory_handle, uint32_t* shared_memory_length) { // Get the trusted audio interface which will give us the handles. - const PPB_AudioTrusted* audio_trusted = - reinterpret_cast<const PPB_AudioTrusted*>( - dispatcher()->GetLocalInterface(PPB_AUDIO_TRUSTED_INTERFACE)); - if (!audio_trusted) + ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_AudioTrusted_API> + trusted_audio(resource.host_resource(), false); + if (trusted_audio.failed()) return PP_ERROR_NOINTERFACE; // Get the socket handle for signaling. int32_t socket_handle; - int32_t result = audio_trusted->GetSyncSocket(resource.host_resource(), - &socket_handle); + int32_t result = trusted_audio.object()->GetSyncSocket(&socket_handle); if (result != PP_OK) return result; @@ -285,9 +301,8 @@ int32_t PPB_Audio_Proxy::GetAudioConnectedHandles( // Get the shared memory for the buffer. int shared_memory_handle; - result = audio_trusted->GetSharedMemory(resource.host_resource(), - &shared_memory_handle, - shared_memory_length); + result = trusted_audio.object()->GetSharedMemory(&shared_memory_handle, + shared_memory_length); if (result != PP_OK) return result; diff --git a/ppapi/proxy/ppb_audio_proxy.h b/ppapi/proxy/ppb_audio_proxy.h index 6574ef7..e39a82d 100644 --- a/ppapi/proxy/ppb_audio_proxy.h +++ b/ppapi/proxy/ppb_audio_proxy.h @@ -5,6 +5,8 @@ #ifndef PPAPI_PROXY_PPB_AUDIO_PROXY_H_ #define PPAPI_PROXY_PPB_AUDIO_PROXY_H_ +#include <utility> + #include "base/basictypes.h" #include "base/shared_memory.h" #include "base/sync_socket.h" @@ -12,6 +14,8 @@ #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_module.h" #include "ppapi/c/pp_resource.h" +#include "ppapi/c/ppb_audio.h" +#include "ppapi/c/ppb_audio_config.h" #include "ppapi/cpp/completion_callback.h" #include "ppapi/proxy/interface_proxy.h" #include "ppapi/proxy/proxy_non_thread_safe_ref_count.h" @@ -30,6 +34,13 @@ class PPB_Audio_Proxy : public InterfaceProxy { static const Info* GetInfo(); + // Creates an Audio object in the plugin process. + static PP_Resource CreateProxyResource(PP_Instance instance_id, + PP_Resource config_id, + PPB_Audio_Callback audio_callback, + void* user_data); + + const PPB_Audio* ppb_audio_target() const { return static_cast<const PPB_Audio*>(target_interface()); } @@ -40,7 +51,8 @@ class PPB_Audio_Proxy : public InterfaceProxy { private: // Plugin->renderer message handlers. void OnMsgCreate(PP_Instance instance_id, - const HostResource& config_id, + int32_t sample_rate, + uint32_t sample_frame_count, HostResource* result); void OnMsgStartOrStop(const HostResource& audio_id, bool play); diff --git a/ppapi/proxy/ppb_char_set_proxy.cc b/ppapi/proxy/ppb_char_set_proxy.cc index 5c9c7d0..5a0be2e 100644 --- a/ppapi/proxy/ppb_char_set_proxy.cc +++ b/ppapi/proxy/ppb_char_set_proxy.cc @@ -27,7 +27,7 @@ char* UTF16ToCharSet(PP_Instance /* instance */, const char* output_char_set, PP_CharSet_ConversionError on_error, uint32_t* output_length) { - return pp::shared_impl::CharSetImpl::UTF16ToCharSet( + return ppapi::CharSetImpl::UTF16ToCharSet( GetCoreInterface(), utf16, utf16_len, output_char_set, on_error, output_length); } @@ -37,7 +37,7 @@ uint16_t* CharSetToUTF16(PP_Instance /* instance */, const char* input_char_set, PP_CharSet_ConversionError on_error, uint32_t* output_length) { - return pp::shared_impl::CharSetImpl::CharSetToUTF16( + return ppapi::CharSetImpl::CharSetToUTF16( GetCoreInterface(), input, input_len, input_char_set, on_error, output_length); } diff --git a/ppapi/proxy/ppb_crypto_proxy.cc b/ppapi/proxy/ppb_crypto_proxy.cc index 207b400..d900800 100644 --- a/ppapi/proxy/ppb_crypto_proxy.cc +++ b/ppapi/proxy/ppb_crypto_proxy.cc @@ -14,7 +14,7 @@ namespace proxy { namespace { const PPB_Crypto_Dev crypto_interface = { - &pp::shared_impl::CryptoImpl::GetRandomBytes + &ppapi::CryptoImpl::GetRandomBytes }; InterfaceProxy* CreateCryptoProxy(Dispatcher* dispatcher, diff --git a/ppapi/proxy/ppb_font_proxy.cc b/ppapi/proxy/ppb_font_proxy.cc index 9d52fcc..ace9f76 100644 --- a/ppapi/proxy/ppb_font_proxy.cc +++ b/ppapi/proxy/ppb_font_proxy.cc @@ -14,7 +14,7 @@ #include "ppapi/thunk/thunk.h" using ppapi::thunk::PPB_ImageData_API; -using pp::shared_impl::WebKitForwarding; +using ppapi::WebKitForwarding; namespace pp { namespace proxy { @@ -121,8 +121,8 @@ PP_Bool Font::DrawTextAt(PP_Resource pp_image_data, const PP_Rect* clip, PP_Bool image_data_is_opaque) { // Convert to an ImageData object. - ppapi::shared_impl::ResourceObjectBase* image_base = - ppapi::shared_impl::TrackerBase::Get()->GetResourceAPI(pp_image_data); + ppapi::ResourceObjectBase* image_base = + ppapi::TrackerBase::Get()->GetResourceAPI(pp_image_data); if (!image_base) return PP_FALSE; PPB_ImageData_API* image_api = image_base->GetAs<PPB_ImageData_API>(); diff --git a/ppapi/proxy/ppb_font_proxy.h b/ppapi/proxy/ppb_font_proxy.h index 35b1c55..8fec581 100644 --- a/ppapi/proxy/ppb_font_proxy.h +++ b/ppapi/proxy/ppb_font_proxy.h @@ -73,7 +73,7 @@ class Font : public PluginResource, base::WaitableEvent webkit_event_; - scoped_ptr<pp::shared_impl::WebKitForwarding::Font> font_forwarding_; + scoped_ptr<ppapi::WebKitForwarding::Font> font_forwarding_; DISALLOW_COPY_AND_ASSIGN(Font); }; diff --git a/ppapi/proxy/ppb_image_data_proxy.h b/ppapi/proxy/ppb_image_data_proxy.h index 71198bd..6bd97a5ad 100644 --- a/ppapi/proxy/ppb_image_data_proxy.h +++ b/ppapi/proxy/ppb_image_data_proxy.h @@ -47,7 +47,7 @@ class PPB_ImageData_Proxy : public InterfaceProxy { class ImageData : public PluginResource, public ::ppapi::thunk::PPB_ImageData_API, - public pp::shared_impl::ImageDataImpl { + public ppapi::ImageDataImpl { public: ImageData(const HostResource& resource, const PP_ImageDataDesc& desc, diff --git a/ppapi/proxy/ppb_url_util_proxy.cc b/ppapi/proxy/ppb_url_util_proxy.cc index 17b36ea..b59ef3c 100644 --- a/ppapi/proxy/ppb_url_util_proxy.cc +++ b/ppapi/proxy/ppb_url_util_proxy.cc @@ -15,7 +15,7 @@ namespace pp { namespace proxy { -using pp::shared_impl::URLUtilImpl; +using ppapi::URLUtilImpl; namespace { diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index 7346add..44d903d 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -9,18 +9,20 @@ #include "ppapi/proxy/host_resource.h" #include "ppapi/proxy/interface_id.h" #include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/c/trusted/ppb_image_data_trusted.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" -#include "ppapi/proxy/ppb_graphics_2d_proxy.h" +#include "ppapi/proxy/ppb_audio_config_proxy.h" +#include "ppapi/proxy/ppb_audio_proxy.h" #include "ppapi/proxy/ppb_font_proxy.h" +#include "ppapi/proxy/ppb_graphics_2d_proxy.h" #include "ppapi/proxy/ppb_image_data_proxy.h" -#include "ppapi/c/trusted/ppb_image_data_trusted.h" #include "ppapi/shared_impl/font_impl.h" #include "ppapi/shared_impl/function_group_base.h" #include "ppapi/thunk/enter.h" #include "ppapi/thunk/ppb_image_data_api.h" -using ::ppapi::thunk::ResourceCreationAPI; +using ppapi::thunk::ResourceCreationAPI; namespace pp { namespace proxy { @@ -37,17 +39,36 @@ ResourceCreationProxy::AsResourceCreation() { return this; } +PP_Resource ResourceCreationProxy::CreateAudio( + PP_Instance instance, + PP_Resource config_id, + PPB_Audio_Callback audio_callback, + void* user_data) { + return PPB_Audio_Proxy::CreateProxyResource(instance, config_id, + audio_callback, user_data); +} + +PP_Resource ResourceCreationProxy::CreateAudioConfig( + PP_Instance instance, + PP_AudioSampleRate sample_rate, + uint32_t sample_frame_count) { + return PPB_AudioConfig_Proxy::CreateProxyResource( + instance, sample_rate, sample_frame_count); +} + +PP_Resource ResourceCreationProxy::CreateAudioTrusted(PP_Instance instance) { + // Proxied plugins can't created trusted audio devices. + return 0; +} + PP_Resource ResourceCreationProxy::CreateFontObject( PP_Instance instance, const PP_FontDescription_Dev* description) { - if (!pp::shared_impl::FontImpl::IsPPFontDescriptionValid(*description)) + if (!ppapi::FontImpl::IsPPFontDescriptionValid(*description)) return 0; - // See the comment above Font's constructor for why we do this. - HostResource resource; - resource.SetHostResource(instance, 0); - - linked_ptr<Font> object(new Font(resource, *description)); + linked_ptr<Font> object(new Font(HostResource::MakeInstanceOnly(instance), + *description)); return PluginResourceTracker::GetInstance()->AddResource(object); } @@ -143,8 +164,8 @@ void ResourceCreationProxy::OnMsgCreateImageData( result->SetHostResource(instance, resource); // Get the description, it's just serialized as a string. - ppapi::thunk::EnterResource<ppapi::thunk::PPB_ImageData_API> enter_resource( - resource, false); + ppapi::thunk::EnterResourceNoLock<ppapi::thunk::PPB_ImageData_API> + enter_resource(resource, false); PP_ImageDataDesc desc; if (enter_resource.object()->Describe(&desc) == PP_TRUE) { image_data_desc->resize(sizeof(PP_ImageDataDesc)); diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h index 4cc1391..c0cae7f 100644 --- a/ppapi/proxy/resource_creation_proxy.h +++ b/ppapi/proxy/resource_creation_proxy.h @@ -21,7 +21,7 @@ namespace proxy { class HostResource; class Dispatcher; -class ResourceCreationProxy : public ::ppapi::shared_impl::FunctionGroupBase, +class ResourceCreationProxy : public ::ppapi::FunctionGroupBase, public ::ppapi::thunk::ResourceCreationAPI, public ::IPC::Channel::Listener, public IPC::Message::Sender { @@ -29,25 +29,37 @@ class ResourceCreationProxy : public ::ppapi::shared_impl::FunctionGroupBase, ResourceCreationProxy(Dispatcher* dispatcher); virtual ~ResourceCreationProxy(); - virtual ::ppapi::thunk::ResourceCreationAPI* AsResourceCreation(); + virtual ::ppapi::thunk::ResourceCreationAPI* AsResourceCreation() OVERRIDE; // ResourceCreationAPI (called in plugin). + virtual PP_Resource CreateAudio(PP_Instance instance, + PP_Resource config_id, + PPB_Audio_Callback audio_callback, + void* user_data) OVERRIDE; + virtual PP_Resource CreateAudioConfig(PP_Instance instance, + PP_AudioSampleRate sample_rate, + uint32_t sample_frame_count) OVERRIDE; + virtual PP_Resource CreateAudioTrusted(PP_Instance instance) OVERRIDE; virtual PP_Resource CreateFontObject( PP_Instance instance, - const PP_FontDescription_Dev* description); + const PP_FontDescription_Dev* description) OVERRIDE; virtual PP_Resource CreateGraphics2D(PP_Instance pp_instance, const PP_Size& size, - PP_Bool is_always_opaque); + PP_Bool is_always_opaque) OVERRIDE; virtual PP_Resource CreateImageData(PP_Instance instance, PP_ImageDataFormat format, const PP_Size& size, - PP_Bool init_to_zero); + PP_Bool init_to_zero) OVERRIDE; - virtual bool Send(IPC::Message* msg); - virtual bool OnMessageReceived(const IPC::Message& msg); + virtual bool Send(IPC::Message* msg) OVERRIDE; + virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; private: // IPC message handlers (called in browser). + void OnMsgCreateAudio(PP_Instance instance, + int32_t sample_rate, + uint32_t sample_frame_count, + HostResource* result); void OnMsgCreateGraphics2D(PP_Instance instance, const PP_Size& size, PP_Bool is_always_opaque, diff --git a/ppapi/shared_impl/audio_config_impl.cc b/ppapi/shared_impl/audio_config_impl.cc new file mode 100644 index 0000000..da4d8c5 --- /dev/null +++ b/ppapi/shared_impl/audio_config_impl.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/shared_impl/audio_config_impl.h" + +namespace ppapi { + +AudioConfigImpl::AudioConfigImpl() + : sample_rate_(PP_AUDIOSAMPLERATE_NONE), + sample_frame_count_(0) { +} + +AudioConfigImpl::~AudioConfigImpl() { +} + +bool AudioConfigImpl::Init(PP_AudioSampleRate sample_rate, + uint32_t sample_frame_count) { + // TODO(brettw): Currently we don't actually check what the hardware + // supports, so just allow sample rates of the "guaranteed working" ones. + if (sample_rate != PP_AUDIOSAMPLERATE_44100 && + sample_rate != PP_AUDIOSAMPLERATE_48000) + return false; + + // TODO(brettw): Currently we don't actually query to get a value from the + // hardware, so just validate the range. + if (sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT || + sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) + return false; + + sample_rate_ = sample_rate; + sample_frame_count_ = sample_frame_count; + return true; +} + +PP_AudioSampleRate AudioConfigImpl::GetSampleRate() { + return sample_rate_; +} + +uint32_t AudioConfigImpl::GetSampleFrameCount() { + return sample_frame_count_; +} + +} // namespace ppapi diff --git a/ppapi/shared_impl/audio_config_impl.h b/ppapi/shared_impl/audio_config_impl.h new file mode 100644 index 0000000..230856f --- /dev/null +++ b/ppapi/shared_impl/audio_config_impl.h @@ -0,0 +1,38 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_SHARED_IMPL_AUDIO_CONFIG_IMPL_H_ +#define PPAPI_SHARED_IMPL_AUDIO_CONFIG_IMPL_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "ppapi/shared_impl/resource_object_base.h" +#include "ppapi/thunk/ppb_audio_config_api.h" + +namespace ppapi { + +class AudioConfigImpl : public thunk::PPB_AudioConfig_API { + public: + // You must call Init before using this object. + AudioConfigImpl(); + virtual ~AudioConfigImpl(); + + // Returns false if the arguments are invalid, the object should not be + // used in this case. + bool Init(PP_AudioSampleRate sample_rate, uint32_t sample_frame_count); + + // PPB_AudioConfig_API implementation. + virtual PP_AudioSampleRate GetSampleRate() OVERRIDE; + virtual uint32_t GetSampleFrameCount() OVERRIDE; + + private: + PP_AudioSampleRate sample_rate_; + uint32_t sample_frame_count_; + + DISALLOW_COPY_AND_ASSIGN(AudioConfigImpl); +}; + +} // namespace ppapi + +#endif // PPAPI_SHARED_IMPL_AUDIO_CONFIG_IMPL_H_ diff --git a/ppapi/shared_impl/audio_impl.cc b/ppapi/shared_impl/audio_impl.cc index 30e1bab..0173d6e 100644 --- a/ppapi/shared_impl/audio_impl.cc +++ b/ppapi/shared_impl/audio_impl.cc @@ -6,8 +6,7 @@ #include "base/logging.h" -namespace pp { -namespace shared_impl { +namespace ppapi { AudioImpl::AudioImpl() : playing_(false), @@ -26,6 +25,10 @@ AudioImpl::~AudioImpl() { } } +::ppapi::thunk::PPB_Audio_API* AudioImpl::AsAudio_API() { + return this; +} + void AudioImpl::SetCallback(PPB_Audio_Callback callback, void* user_data) { callback_ = callback; user_data_ = user_data; @@ -93,5 +96,4 @@ void AudioImpl::Run() { } } -} // namespace shared_impl -} // namespace pp +} // namespace ppapi diff --git a/ppapi/shared_impl/audio_impl.h b/ppapi/shared_impl/audio_impl.h index cec4a07..ba7c780 100644 --- a/ppapi/shared_impl/audio_impl.h +++ b/ppapi/shared_impl/audio_impl.h @@ -10,18 +10,24 @@ #include "base/sync_socket.h" #include "base/threading/simple_thread.h" #include "ppapi/c/ppb_audio.h" +#include "ppapi/shared_impl/resource_object_base.h" +#include "ppapi/thunk/ppb_audio_api.h" -namespace pp { -namespace shared_impl { +namespace ppapi { // Implements the logic to map shared memory and run the audio thread signaled // from the sync socket. Both the proxy and the renderer implementation use // this code. -class AudioImpl : public base::DelegateSimpleThread::Delegate { +class AudioImpl : public ResourceObjectBase, + public thunk::PPB_Audio_API, + public base::DelegateSimpleThread::Delegate { public: AudioImpl(); virtual ~AudioImpl(); + // ResourceObjectBase implementation. + virtual ::ppapi::thunk::PPB_Audio_API* AsAudio_API() OVERRIDE; + bool playing() const { return playing_; } // Sets the callback information that the background thread will use. This @@ -79,7 +85,6 @@ class AudioImpl : public base::DelegateSimpleThread::Delegate { void* user_data_; }; -} // namespace shared_impl -} // namespace pp +} // namespace ppapi #endif // PPAPI_SHARED_IMPL_AUDIO_IMPL_H_ diff --git a/ppapi/shared_impl/char_set_impl.cc b/ppapi/shared_impl/char_set_impl.cc index 012f9d6..cad3142 100644 --- a/ppapi/shared_impl/char_set_impl.cc +++ b/ppapi/shared_impl/char_set_impl.cc @@ -11,8 +11,7 @@ #include "unicode/ucnv_err.h" #include "unicode/ustring.h" -namespace pp { -namespace shared_impl { +namespace ppapi { namespace { @@ -149,5 +148,4 @@ uint16_t* CharSetImpl::CharSetToUTF16(const PPB_Core* core, return ret_buf; } -} // namespace shared_impl -} // namespace pp +} // namespace ppapi diff --git a/ppapi/shared_impl/char_set_impl.h b/ppapi/shared_impl/char_set_impl.h index 985a5d6..41411a4 100644 --- a/ppapi/shared_impl/char_set_impl.h +++ b/ppapi/shared_impl/char_set_impl.h @@ -10,8 +10,7 @@ struct PPB_Core; -namespace pp { -namespace shared_impl { +namespace ppapi { // Contains the implementation of character set conversion that is shared // between the proxy and the renderer. @@ -32,7 +31,6 @@ class CharSetImpl { uint32_t* output_length); }; -} // namespace shared_impl -} // namespace pp +} // namespace ppapi #endif // PPAPI_SHARED_IMPL_CHAR_SET_IMPL_H_ diff --git a/ppapi/shared_impl/crypto_impl.cc b/ppapi/shared_impl/crypto_impl.cc index f8e4aa2..814e629 100644 --- a/ppapi/shared_impl/crypto_impl.cc +++ b/ppapi/shared_impl/crypto_impl.cc @@ -6,13 +6,11 @@ #include "base/rand_util.h" -namespace pp { -namespace shared_impl { +namespace ppapi { // static void CryptoImpl::GetRandomBytes(char* buffer, uint32_t num_bytes) { base::RandBytes(buffer, num_bytes); } -} // namespace shared_impl -} // namespace pp +} // namespace ppapi diff --git a/ppapi/shared_impl/crypto_impl.h b/ppapi/shared_impl/crypto_impl.h index c3b3cd4..a959bc9 100644 --- a/ppapi/shared_impl/crypto_impl.h +++ b/ppapi/shared_impl/crypto_impl.h @@ -8,15 +8,13 @@ #include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_stdint.h" -namespace pp { -namespace shared_impl { +namespace ppapi { class CryptoImpl { public: static void GetRandomBytes(char* buffer, uint32_t num_bytes); }; -} // namespace shared_impl -} // namespace pp +} // namespace ppapi #endif // PPAPI_SHARED_IMPL_CRYPTO_IMPL_H_ diff --git a/ppapi/shared_impl/font_impl.cc b/ppapi/shared_impl/font_impl.cc index 3feaf9f..66ac5a6 100644 --- a/ppapi/shared_impl/font_impl.cc +++ b/ppapi/shared_impl/font_impl.cc @@ -6,8 +6,7 @@ #include "ppapi/c/dev/ppb_font_dev.h" -namespace pp { -namespace shared_impl { +namespace ppapi { // static bool FontImpl::IsPPFontDescriptionValid(const PP_FontDescription_Dev& desc) { @@ -32,5 +31,4 @@ bool FontImpl::IsPPFontDescriptionValid(const PP_FontDescription_Dev& desc) { return true; } -} // namespace shared_impl -} // namespace pp +} // namespace ppapi diff --git a/ppapi/shared_impl/font_impl.h b/ppapi/shared_impl/font_impl.h index ebdf38a..9117ffb 100644 --- a/ppapi/shared_impl/font_impl.h +++ b/ppapi/shared_impl/font_impl.h @@ -15,8 +15,7 @@ struct PP_FontDescription_Dev; -namespace pp { -namespace shared_impl { +namespace ppapi { class FontImpl { public: @@ -27,7 +26,6 @@ class FontImpl { DISALLOW_COPY_AND_ASSIGN(FontImpl); }; -} // namespace shared_impl -} // namespace pp +} // namespace ppapi #endif // PPAPI_SHARED_IMPL_FONT_IMPL_H_ diff --git a/ppapi/shared_impl/function_group_base.h b/ppapi/shared_impl/function_group_base.h index 9b3f728..6b8976e 100644 --- a/ppapi/shared_impl/function_group_base.h +++ b/ppapi/shared_impl/function_group_base.h @@ -11,8 +11,6 @@ namespace thunk { class ResourceCreationAPI; } -namespace shared_impl { - class FunctionGroupBase { public: // Dynamic casting for this object. Returns the pointer to the given type if @@ -23,11 +21,10 @@ class FunctionGroupBase { }; template<> -inline thunk::ResourceCreationAPI* FunctionGroupBase::GetAs() { +inline ppapi::thunk::ResourceCreationAPI* FunctionGroupBase::GetAs() { return AsResourceCreation(); } -} // namespace shared_impl } // namespace ppapi #endif // PPAPI_SHARED_IMPL_FUNCTION_GROUP_BASE_H_ diff --git a/ppapi/shared_impl/image_data_impl.cc b/ppapi/shared_impl/image_data_impl.cc index 9392927..e07d2cb 100644 --- a/ppapi/shared_impl/image_data_impl.cc +++ b/ppapi/shared_impl/image_data_impl.cc @@ -6,8 +6,7 @@ #include "third_party/skia/include/core/SkTypes.h" -namespace pp { -namespace shared_impl { +namespace ppapi { // static PP_ImageDataFormat ImageDataImpl::GetNativeImageDataFormat() { @@ -25,5 +24,4 @@ bool ImageDataImpl::IsImageDataFormatSupported(PP_ImageDataFormat format) { format == PP_IMAGEDATAFORMAT_RGBA_PREMUL; } -} // namespace shared_impl -} // namespace pp +} // namespace ppapi diff --git a/ppapi/shared_impl/image_data_impl.h b/ppapi/shared_impl/image_data_impl.h index 6b8a7cc..1d2f76f5 100644 --- a/ppapi/shared_impl/image_data_impl.h +++ b/ppapi/shared_impl/image_data_impl.h @@ -8,8 +8,7 @@ #include "ppapi/c/pp_bool.h" #include "ppapi/c/ppb_image_data.h" -namespace pp { -namespace shared_impl { +namespace ppapi { // Contains the implementation of some simple image data functions that are // shared between the proxy and Chrome's implementation. Since these functions @@ -26,7 +25,6 @@ class ImageDataImpl { static bool IsImageDataFormatSupported(PP_ImageDataFormat format); }; -} // namespace shared_impl -} // namespace pp +} // namespace ppapi #endif // PPAPI_SHARED_IMPL_IMAGE_DATA_IMPL_H_ diff --git a/ppapi/shared_impl/resource_object_base.h b/ppapi/shared_impl/resource_object_base.h index 1a87360..05ed923 100644 --- a/ppapi/shared_impl/resource_object_base.h +++ b/ppapi/shared_impl/resource_object_base.h @@ -8,16 +8,20 @@ namespace ppapi { namespace thunk { +class PPB_Audio_API; +class PPB_AudioConfig_API; +class PPB_AudioTrusted_API; class PPB_Font_API; class PPB_Graphics2D_API; class PPB_ImageData_API; } -namespace shared_impl { - class ResourceObjectBase { public: + virtual thunk::PPB_Audio_API* AsAudio_API() { return NULL; } + virtual thunk::PPB_AudioConfig_API* AsAudioConfig_API() { return NULL; } + virtual thunk::PPB_AudioTrusted_API* AsAudioTrusted_API() { return NULL; } virtual thunk::PPB_Font_API* AsFont_API() { return NULL; } virtual thunk::PPB_Graphics2D_API* AsGraphics2D_API() { return NULL; } virtual thunk::PPB_ImageData_API* AsImageData_API() { return NULL; } @@ -26,6 +30,18 @@ class ResourceObjectBase { }; template<> +inline thunk::PPB_Audio_API* ResourceObjectBase::GetAs() { + return AsAudio_API(); +} +template<> +inline thunk::PPB_AudioConfig_API* ResourceObjectBase::GetAs() { + return AsAudioConfig_API(); +} +template<> +inline thunk::PPB_AudioTrusted_API* ResourceObjectBase::GetAs() { + return AsAudioTrusted_API(); +} +template<> inline thunk::PPB_Font_API* ResourceObjectBase::GetAs() { return AsFont_API(); } @@ -38,7 +54,6 @@ inline thunk::PPB_ImageData_API* ResourceObjectBase::GetAs() { return AsImageData_API(); } -} // namespace shared_impl } // namespace ppapi #endif // PPAPI_SHARED_IMPL_RESOURCE_OBJECT_BASE_H_ diff --git a/ppapi/shared_impl/tracker_base.cc b/ppapi/shared_impl/tracker_base.cc index 79c4b4e..291bc18 100644 --- a/ppapi/shared_impl/tracker_base.cc +++ b/ppapi/shared_impl/tracker_base.cc @@ -7,7 +7,6 @@ #include "base/logging.h" namespace ppapi { -namespace shared_impl { static TrackerBase* (*g_global_getter)() = NULL; @@ -21,5 +20,4 @@ TrackerBase* TrackerBase::Get() { return g_global_getter(); } -} // namespace shared_impl } // namespace ppapi diff --git a/ppapi/shared_impl/tracker_base.h b/ppapi/shared_impl/tracker_base.h index c44ee2b..4b7e447 100644 --- a/ppapi/shared_impl/tracker_base.h +++ b/ppapi/shared_impl/tracker_base.h @@ -10,7 +10,6 @@ #include "ppapi/proxy/interface_id.h" namespace ppapi { -namespace shared_impl { class FunctionGroupBase; class ResourceObjectBase; @@ -43,7 +42,6 @@ class TrackerBase { pp::proxy::InterfaceID id) = 0; }; -} // namespace shared_impl } // namespace ppapi #endif // PPAPI_SHARED_IMPL_TRACKER_BASE_H_ diff --git a/ppapi/shared_impl/url_util_impl.cc b/ppapi/shared_impl/url_util_impl.cc index 32aab48..f45d4fef 100644 --- a/ppapi/shared_impl/url_util_impl.cc +++ b/ppapi/shared_impl/url_util_impl.cc @@ -6,8 +6,7 @@ #include "googleurl/src/gurl.h" -namespace pp { -namespace shared_impl { +namespace ppapi { namespace { @@ -102,5 +101,4 @@ PP_Var URLUtilImpl::GenerateURLReturn(VarFromUtf8 var_from_utf8, static_cast<uint32_t>(url.possibly_invalid_spec().size())); } -} // namespace shared_impl -} // namespace pp +} // namespace ppapi diff --git a/ppapi/shared_impl/url_util_impl.h b/ppapi/shared_impl/url_util_impl.h index 91c7999..008f317 100644 --- a/ppapi/shared_impl/url_util_impl.h +++ b/ppapi/shared_impl/url_util_impl.h @@ -15,8 +15,7 @@ class GURL; -namespace pp { -namespace shared_impl { +namespace ppapi { // Contains the implementation of PPB_URLUtil that is shared between the proxy // and the renderer. @@ -61,7 +60,6 @@ class URLUtilImpl { PP_URLComponents_Dev* components); }; -} // namespace shared_impl -} // namespace pp +} // namespace ppapi #endif diff --git a/ppapi/shared_impl/webkit_forwarding.cc b/ppapi/shared_impl/webkit_forwarding.cc index 02573f8..a99d754 100644 --- a/ppapi/shared_impl/webkit_forwarding.cc +++ b/ppapi/shared_impl/webkit_forwarding.cc @@ -4,8 +4,7 @@ #include "ppapi/shared_impl/webkit_forwarding.h" -namespace pp { -namespace shared_impl { +namespace ppapi { WebKitForwarding::Font::DrawTextParams::DrawTextParams( skia::PlatformCanvas* destination_arg, @@ -31,6 +30,5 @@ WebKitForwarding::Font::~Font() { WebKitForwarding::~WebKitForwarding() { } -} // namespace shared_impl -} // namespace pp +} // namespace ppapi diff --git a/ppapi/shared_impl/webkit_forwarding.h b/ppapi/shared_impl/webkit_forwarding.h index aa788f8..4f45344 100644 --- a/ppapi/shared_impl/webkit_forwarding.h +++ b/ppapi/shared_impl/webkit_forwarding.h @@ -23,8 +23,7 @@ namespace skia { class PlatformCanvas; } -namespace pp { -namespace shared_impl { +namespace ppapi { class WebKitForwarding { public: @@ -98,7 +97,6 @@ class WebKitForwarding { }; -} // namespace shared_impl -} // namespace pp +} // namespace ppapi #endif // PPAPI_SHARED_IMPL_WEBKIT_FORWARDING_H_ diff --git a/ppapi/thunk/enter.h b/ppapi/thunk/enter.h index 1a18cf6..b7e2f8b 100644 --- a/ppapi/thunk/enter.h +++ b/ppapi/thunk/enter.h @@ -41,9 +41,8 @@ class EnterFunction { public: EnterFunction(PP_Instance instance, bool report_error) : functions_(NULL) { - shared_impl::FunctionGroupBase* base = - shared_impl::TrackerBase::Get()->GetFunctionAPI( - instance, FunctionsT::interface_id); + FunctionGroupBase* base = TrackerBase::Get()->GetFunctionAPI( + instance, FunctionsT::interface_id); if (base) functions_ = base->GetAs<FunctionsT>(); // TODO(brettw) check error and if report_error is set, do something. @@ -61,13 +60,23 @@ class EnterFunction { DISALLOW_COPY_AND_ASSIGN(EnterFunction); }; +// Like EnterResource but assumes the lock is already held. +// TODO(brettw) actually implement locks, this is just a placeholder for now. +template<typename FunctionsT> +class EnterFunctionNoLock : public EnterFunction<FunctionsT> { + public: + EnterFunctionNoLock(PP_Instance instance, bool report_error) + : EnterFunction<FunctionsT>(instance, report_error) { + // TODO(brettw) assert the lock is held. + } +}; + template<typename ResourceT> class EnterResource { public: EnterResource(PP_Resource resource, bool report_error) : object_(NULL) { - shared_impl::ResourceObjectBase* base = - shared_impl::TrackerBase::Get()->GetResourceAPI(resource); + ResourceObjectBase* base = TrackerBase::Get()->GetResourceAPI(resource); if (base) object_ = base->GetAs<ResourceT>(); // TODO(brettw) check error and if report_error is set, do something. @@ -85,6 +94,17 @@ class EnterResource { DISALLOW_COPY_AND_ASSIGN(EnterResource); }; +// Like EnterResource but assumes the lock is already held. +// TODO(brettw) actually implement locks, this is just a placeholder for now. +template<typename ResourceT> +class EnterResourceNoLock : public EnterResource<ResourceT> { + public: + EnterResourceNoLock(PP_Resource resource, bool report_error) + : EnterResource<ResourceT>(resource, report_error) { + // TODO(brettw) assert the lock is held. + } +}; + } // namespace thunk } // namespace ppapi diff --git a/ppapi/thunk/ppb_audio_api.h b/ppapi/thunk/ppb_audio_api.h new file mode 100644 index 0000000..449aa1b --- /dev/null +++ b/ppapi/thunk/ppb_audio_api.h @@ -0,0 +1,23 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_THUNK_AUDIO_API_H_ +#define PPAPI_THUNK_AUDIO_API_H_ + +#include "ppapi/c/ppb_audio.h" + +namespace ppapi { +namespace thunk { + +class PPB_Audio_API { + public: + virtual PP_Resource GetCurrentConfig() = 0; + virtual PP_Bool StartPlayback() = 0; + virtual PP_Bool StopPlayback() = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_AUDIO_API_H_ diff --git a/ppapi/thunk/ppb_audio_config_api.h b/ppapi/thunk/ppb_audio_config_api.h new file mode 100644 index 0000000..3303153 --- /dev/null +++ b/ppapi/thunk/ppb_audio_config_api.h @@ -0,0 +1,22 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_THUNK_AUDIO_CONFIG_API_H_ +#define PPAPI_THUNK_AUDIO_CONFIG_API_H_ + +#include "ppapi/c/ppb_audio_config.h" + +namespace ppapi { +namespace thunk { + +class PPB_AudioConfig_API { + public: + virtual PP_AudioSampleRate GetSampleRate() = 0; + virtual uint32_t GetSampleFrameCount() = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_AUDIO_CONFIG_API_H_ diff --git a/ppapi/thunk/ppb_audio_config_thunk.cc b/ppapi/thunk/ppb_audio_config_thunk.cc new file mode 100644 index 0000000..8ee8ffd --- /dev/null +++ b/ppapi/thunk/ppb_audio_config_thunk.cc @@ -0,0 +1,70 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_audio_config_api.h" +#include "ppapi/thunk/resource_creation_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +PP_Resource CreateStereo16bit(PP_Instance instance, + PP_AudioSampleRate sample_rate, + uint32_t sample_frame_count) { + EnterFunction<ResourceCreationAPI> enter(instance, true); + if (enter.failed()) + return 0; + return enter.functions()->CreateAudioConfig(instance, sample_rate, + sample_frame_count); +} + +uint32_t RecommendSampleFrameCount(PP_AudioSampleRate sample_rate, + uint32_t requested_sample_frame_count) { + // TODO(brettw) Currently we don't actually query to get a value from the + // hardware, so we always return the input for in-range values. + if (requested_sample_frame_count < PP_AUDIOMINSAMPLEFRAMECOUNT) + return PP_AUDIOMINSAMPLEFRAMECOUNT; + if (requested_sample_frame_count > PP_AUDIOMAXSAMPLEFRAMECOUNT) + return PP_AUDIOMAXSAMPLEFRAMECOUNT; + return requested_sample_frame_count; +} + +PP_Bool IsAudioConfig(PP_Resource resource) { + EnterResource<PPB_AudioConfig_API> enter(resource, false); + return enter.succeeded() ? PP_TRUE : PP_FALSE; +} + +PP_AudioSampleRate GetSampleRate(PP_Resource config_id) { + EnterResource<PPB_AudioConfig_API> enter(config_id, true); + if (enter.failed()) + return PP_AUDIOSAMPLERATE_NONE; + return enter.object()->GetSampleRate(); +} + +uint32_t GetSampleFrameCount(PP_Resource config_id) { + EnterResource<PPB_AudioConfig_API> enter(config_id, true); + if (enter.failed()) + return 0; + return enter.object()->GetSampleFrameCount(); +} + +const PPB_AudioConfig g_ppb_audio_config_thunk = { + &CreateStereo16bit, + &RecommendSampleFrameCount, + &IsAudioConfig, + &GetSampleRate, + &GetSampleFrameCount +}; + +} // namespace + +const PPB_AudioConfig* GetPPB_AudioConfig_Thunk() { + return &g_ppb_audio_config_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/ppb_audio_thunk.cc b/ppapi/thunk/ppb_audio_thunk.cc new file mode 100644 index 0000000..426ba29 --- /dev/null +++ b/ppapi/thunk/ppb_audio_thunk.cc @@ -0,0 +1,67 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_audio_api.h" +#include "ppapi/thunk/resource_creation_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +PP_Resource Create(PP_Instance instance, + PP_Resource config_id, + PPB_Audio_Callback callback, + void* user_data) { + EnterFunction<ResourceCreationAPI> enter(instance, true); + if (enter.failed()) + return 0; + return enter.functions()->CreateAudio(instance, config_id, + callback, user_data); +} + +PP_Bool IsAudio(PP_Resource resource) { + EnterResource<PPB_Audio_API> enter(resource, false); + return enter.succeeded() ? PP_TRUE : PP_FALSE; +} + +PP_Resource GetCurrentConfiguration(PP_Resource audio_id) { + EnterResource<PPB_Audio_API> enter(audio_id, true); + if (enter.failed()) + return 0; + return enter.object()->GetCurrentConfig(); +} + +PP_Bool StartPlayback(PP_Resource audio_id) { + EnterResource<PPB_Audio_API> enter(audio_id, true); + if (enter.failed()) + return PP_FALSE; + return enter.object()->StartPlayback(); +} + +PP_Bool StopPlayback(PP_Resource audio_id) { + EnterResource<PPB_Audio_API> enter(audio_id, true); + if (enter.failed()) + return PP_FALSE; + return enter.object()->StopPlayback(); +} + +const PPB_Audio g_ppb_audio_thunk = { + &Create, + &IsAudio, + &GetCurrentConfiguration, + &StartPlayback, + &StopPlayback +}; + +} // namespace + +const PPB_Audio* GetPPB_Audio_Thunk() { + return &g_ppb_audio_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/ppb_audio_trusted_api.h b/ppapi/thunk/ppb_audio_trusted_api.h new file mode 100644 index 0000000..73864f1 --- /dev/null +++ b/ppapi/thunk/ppb_audio_trusted_api.h @@ -0,0 +1,25 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_THUNK_AUDIO_TRUSTED_API_H_ +#define PPAPI_THUNK_AUDIO_TRUSTED_API_H_ + +#include "ppapi/c/trusted/ppb_audio_trusted.h" +#include "ppapi/c/ppb_audio.h" + +namespace ppapi { +namespace thunk { + +class PPB_AudioTrusted_API { + public: + virtual int32_t OpenTrusted(PP_Resource config_id, + PP_CompletionCallback create_callback) = 0; + virtual int32_t GetSyncSocket(int* sync_socket) = 0; + virtual int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size) = 0; +}; + +} // namespace thunk +} // namespace ppapi + +#endif // PPAPI_THUNK_AUDIO_TRUSTED_API_H_ diff --git a/ppapi/thunk/ppb_audio_trusted_thunk.cc b/ppapi/thunk/ppb_audio_trusted_thunk.cc new file mode 100644 index 0000000..5cb0bfd --- /dev/null +++ b/ppapi/thunk/ppb_audio_trusted_thunk.cc @@ -0,0 +1,62 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/c/pp_errors.h" +#include "ppapi/thunk/thunk.h" +#include "ppapi/thunk/enter.h" +#include "ppapi/thunk/ppb_audio_trusted_api.h" +#include "ppapi/thunk/resource_creation_api.h" + +namespace ppapi { +namespace thunk { + +namespace { + +PP_Resource Create(PP_Instance instance_id) { + EnterFunction<ResourceCreationAPI> enter(instance_id, true); + if (enter.failed()) + return 0; + return enter.functions()->CreateAudioTrusted(instance_id); +} + +int32_t Open(PP_Resource audio_id, + PP_Resource config_id, + PP_CompletionCallback created) { + EnterResource<PPB_AudioTrusted_API> enter(audio_id, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->OpenTrusted(config_id, created); +} + +int32_t GetSyncSocket(PP_Resource audio_id, int* sync_socket) { + EnterResource<PPB_AudioTrusted_API> enter(audio_id, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->GetSyncSocket(sync_socket); +} + +int32_t GetSharedMemory(PP_Resource audio_id, + int* shm_handle, + uint32_t* shm_size) { + EnterResource<PPB_AudioTrusted_API> enter(audio_id, true); + if (enter.failed()) + return PP_ERROR_BADRESOURCE; + return enter.object()->GetSharedMemory(shm_handle, shm_size); +} + +const PPB_AudioTrusted g_ppb_audio_trusted_thunk = { + &Create, + &Open, + &GetSyncSocket, + &GetSharedMemory, +}; + +} // namespace + +const PPB_AudioTrusted* GetPPB_AudioTrusted_Thunk() { + return &g_ppb_audio_trusted_thunk; +} + +} // namespace thunk +} // namespace ppapi diff --git a/ppapi/thunk/ppb_image_data_thunk.cc b/ppapi/thunk/ppb_image_data_thunk.cc index 6f75d79..9d91302 100644 --- a/ppapi/thunk/ppb_image_data_thunk.cc +++ b/ppapi/thunk/ppb_image_data_thunk.cc @@ -15,11 +15,11 @@ namespace thunk { namespace { PP_ImageDataFormat GetNativeImageDataFormat() { - return pp::shared_impl::ImageDataImpl::GetNativeImageDataFormat(); + return ppapi::ImageDataImpl::GetNativeImageDataFormat(); } PP_Bool IsImageDataFormatSupported(PP_ImageDataFormat format) { - return pp::shared_impl::ImageDataImpl::IsImageDataFormatSupported(format) + return ppapi::ImageDataImpl::IsImageDataFormatSupported(format) ? PP_TRUE : PP_FALSE; } diff --git a/ppapi/thunk/resource_creation_api.h b/ppapi/thunk/resource_creation_api.h index c6561b9..4dd9204 100644 --- a/ppapi/thunk/resource_creation_api.h +++ b/ppapi/thunk/resource_creation_api.h @@ -8,6 +8,8 @@ #include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_resource.h" +#include "ppapi/c/ppb_audio.h" +#include "ppapi/c/ppb_audio_config.h" #include "ppapi/c/ppb_image_data.h" #include "ppapi/proxy/interface_id.h" @@ -27,6 +29,14 @@ class ResourceCreationAPI { static const ::pp::proxy::InterfaceID interface_id = ::pp::proxy::INTERFACE_ID_RESOURCE_CREATION; + virtual PP_Resource CreateAudio(PP_Instance instance, + PP_Resource config_id, + PPB_Audio_Callback audio_callback, + void* user_data) = 0; + virtual PP_Resource CreateAudioTrusted(PP_Instance instace) = 0; + virtual PP_Resource CreateAudioConfig(PP_Instance instance, + PP_AudioSampleRate sample_rate, + uint32_t sample_frame_count) = 0; // Note: can't be called CreateFont due to Windows #defines. virtual PP_Resource CreateFontObject( PP_Instance instance, diff --git a/ppapi/thunk/thunk.h b/ppapi/thunk/thunk.h index 49bb515..efe320e 100644 --- a/ppapi/thunk/thunk.h +++ b/ppapi/thunk/thunk.h @@ -5,8 +5,9 @@ #ifndef PPAPI_THUNK_THUNK_H_ #define PPAPI_THUNK_THUNK_H_ -#include "base/synchronization/lock.h" - +struct PPB_Audio; +struct PPB_AudioConfig; +struct PPB_AudioTrusted; struct PPB_Font_Dev; struct PPB_Graphics2D; struct PPB_ImageData; @@ -14,6 +15,9 @@ struct PPB_ImageData; namespace ppapi { namespace thunk { +const PPB_Audio* GetPPB_Audio_Thunk(); +const PPB_AudioConfig* GetPPB_AudioConfig_Thunk(); +const PPB_AudioTrusted* GetPPB_AudioTrusted_Thunk(); const PPB_Font_Dev* GetPPB_Font_Thunk(); const PPB_Graphics2D* GetPPB_Graphics2D_Thunk(); const PPB_ImageData* GetPPB_ImageData_Thunk(); |