diff options
Diffstat (limited to 'ppapi/thunk')
-rw-r--r-- | ppapi/thunk/enter.h | 30 | ||||
-rw-r--r-- | ppapi/thunk/ppb_audio_api.h | 23 | ||||
-rw-r--r-- | ppapi/thunk/ppb_audio_config_api.h | 22 | ||||
-rw-r--r-- | ppapi/thunk/ppb_audio_config_thunk.cc | 70 | ||||
-rw-r--r-- | ppapi/thunk/ppb_audio_thunk.cc | 67 | ||||
-rw-r--r-- | ppapi/thunk/ppb_audio_trusted_api.h | 25 | ||||
-rw-r--r-- | ppapi/thunk/ppb_audio_trusted_thunk.cc | 62 | ||||
-rw-r--r-- | ppapi/thunk/ppb_image_data_thunk.cc | 4 | ||||
-rw-r--r-- | ppapi/thunk/resource_creation_api.h | 10 | ||||
-rw-r--r-- | ppapi/thunk/thunk.h | 8 |
10 files changed, 312 insertions, 9 deletions
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(); |