diff options
Diffstat (limited to 'ppapi/cpp/dev')
25 files changed, 317 insertions, 325 deletions
diff --git a/ppapi/cpp/dev/audio_config_dev.cc b/ppapi/cpp/dev/audio_config_dev.cc index c68dd84..c8f8f3a 100644 --- a/ppapi/cpp/dev/audio_config_dev.cc +++ b/ppapi/cpp/dev/audio_config_dev.cc @@ -7,10 +7,16 @@ #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" -DeviceFuncs<PPB_AudioConfig_Dev> audio_cfg_f(PPB_AUDIO_CONFIG_DEV_INTERFACE); - namespace pp { +namespace { + +template <> const char* interface_name<PPB_AudioConfig_Dev>() { + return PPB_AUDIO_CONFIG_DEV_INTERFACE; +} + +} // namespace + AudioConfig_Dev::AudioConfig_Dev() : sample_rate_(PP_AUDIOSAMPLERATE_NONE), sample_frame_count_(0) { @@ -20,19 +26,20 @@ AudioConfig_Dev::AudioConfig_Dev(PP_AudioSampleRate_Dev sample_rate, uint32_t sample_frame_count) : sample_rate_(sample_rate), sample_frame_count_(sample_frame_count) { - if (audio_cfg_f) { - PassRefFromConstructor(audio_cfg_f->CreateStereo16Bit( - Module::Get()->pp_module(), sample_rate, - sample_frame_count)); + if (has_interface<PPB_AudioConfig_Dev>()) { + PassRefFromConstructor( + get_interface<PPB_AudioConfig_Dev>()->CreateStereo16Bit( + Module::Get()->pp_module(), sample_rate, sample_frame_count)); } } // static uint32_t AudioConfig_Dev::RecommendSampleFrameCount( uint32_t requested_sample_frame_count) { - if (!audio_cfg_f) + if (!has_interface<PPB_AudioConfig_Dev>()) return 0; - return audio_cfg_f->RecommendSampleFrameCount(requested_sample_frame_count); + return get_interface<PPB_AudioConfig_Dev>()-> + RecommendSampleFrameCount(requested_sample_frame_count); } } // namespace pp diff --git a/ppapi/cpp/dev/audio_dev.cc b/ppapi/cpp/dev/audio_dev.cc index c747c78..850d4d1 100644 --- a/ppapi/cpp/dev/audio_dev.cc +++ b/ppapi/cpp/dev/audio_dev.cc @@ -6,32 +6,35 @@ #include "ppapi/cpp/module_impl.h" +namespace pp { + namespace { -DeviceFuncs<PPB_Audio_Dev> audio_f(PPB_AUDIO_DEV_INTERFACE); +template <> const char* interface_name<PPB_Audio_Dev>() { + return PPB_AUDIO_DEV_INTERFACE; +} } // namespace -namespace pp { - Audio_Dev::Audio_Dev(const Instance& instance, const AudioConfig_Dev& config, PPB_Audio_Callback callback, void* user_data) : config_(config) { - if (audio_f) { - PassRefFromConstructor(audio_f->Create(instance.pp_instance(), - config.pp_resource(), - callback, user_data)); + if (has_interface<PPB_Audio_Dev>()) { + PassRefFromConstructor(get_interface<PPB_Audio_Dev>()->Create( + instance.pp_instance(), config.pp_resource(), callback, user_data)); } } bool Audio_Dev::StartPlayback() { - return audio_f && audio_f->StartPlayback(pp_resource()); + return has_interface<PPB_Audio_Dev>() && + get_interface<PPB_Audio_Dev>()->StartPlayback(pp_resource()); } bool Audio_Dev::StopPlayback() { - return audio_f && audio_f->StopPlayback(pp_resource()); + return has_interface<PPB_Audio_Dev>() && + get_interface<PPB_Audio_Dev>()->StopPlayback(pp_resource()); } } // namespace pp diff --git a/ppapi/cpp/dev/buffer_dev.cc b/ppapi/cpp/dev/buffer_dev.cc index 3f5c2c8..678211a 100644 --- a/ppapi/cpp/dev/buffer_dev.cc +++ b/ppapi/cpp/dev/buffer_dev.cc @@ -9,14 +9,16 @@ #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" +namespace pp { + namespace { -DeviceFuncs<PPB_Buffer_Dev> buffer_f(PPB_BUFFER_DEV_INTERFACE); +template <> const char* interface_name<PPB_Buffer_Dev>() { + return PPB_BUFFER_DEV_INTERFACE; +} } // namespace -namespace pp { - Buffer_Dev::Buffer_Dev() : data_(NULL), size_(0) { } @@ -27,24 +29,15 @@ Buffer_Dev::Buffer_Dev(const Buffer_Dev& other) } Buffer_Dev::Buffer_Dev(uint32_t size) : data_(NULL), size_(0) { - if (!buffer_f) + if (!has_interface<PPB_Buffer_Dev>()) return; - PassRefFromConstructor(buffer_f->Create(Module::Get()->pp_module(), size)); - if (!buffer_f->Describe(pp_resource(), &size_) || - !(data_ = buffer_f->Map(pp_resource()))) + PassRefFromConstructor(get_interface<PPB_Buffer_Dev>()->Create( + Module::Get()->pp_module(), size)); + if (!get_interface<PPB_Buffer_Dev>()->Describe(pp_resource(), &size_) || + !(data_ = get_interface<PPB_Buffer_Dev>()->Map(pp_resource()))) *this = Buffer_Dev(); } -Buffer_Dev::~Buffer_Dev() { -} - -Buffer_Dev& Buffer_Dev::operator=(const Buffer_Dev& other) { - Resource::operator=(other); - size_ = other.size_; - data_ = other.data_; - return *this; -} - } // namespace pp diff --git a/ppapi/cpp/dev/buffer_dev.h b/ppapi/cpp/dev/buffer_dev.h index 19e9e68..e5f7325 100644 --- a/ppapi/cpp/dev/buffer_dev.h +++ b/ppapi/cpp/dev/buffer_dev.h @@ -20,10 +20,6 @@ class Buffer_Dev : public Resource { // resulting object will be is_null() if the allocation failed. explicit Buffer_Dev(uint32_t size); - ~Buffer_Dev(); - - Buffer_Dev& operator=(const Buffer_Dev& other); - uint32_t size() const { return size_; } void* data() const { return data_; } diff --git a/ppapi/cpp/dev/directory_reader_dev.cc b/ppapi/cpp/dev/directory_reader_dev.cc index 0802944..0b461e0b 100644 --- a/ppapi/cpp/dev/directory_reader_dev.cc +++ b/ppapi/cpp/dev/directory_reader_dev.cc @@ -11,38 +11,33 @@ #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" +namespace pp { + namespace { -DeviceFuncs<PPB_DirectoryReader_Dev> directory_reader_f( - PPB_DIRECTORYREADER_DEV_INTERFACE); +template <> const char* interface_name<PPB_DirectoryReader_Dev>() { + return PPB_DIRECTORYREADER_DEV_INTERFACE; +} } // namespace -namespace pp { - DirectoryReader_Dev::DirectoryReader_Dev(const FileRef_Dev& directory_ref) { - if (!directory_reader_f) + if (!has_interface<PPB_DirectoryReader_Dev>()) return; - PassRefFromConstructor( - directory_reader_f->Create(directory_ref.pp_resource())); + PassRefFromConstructor(get_interface<PPB_DirectoryReader_Dev>()->Create( + directory_ref.pp_resource())); } DirectoryReader_Dev::DirectoryReader_Dev(const DirectoryReader_Dev& other) : Resource(other) { } -DirectoryReader_Dev& DirectoryReader_Dev::operator=( - const DirectoryReader_Dev& other) { - Resource::operator=(other); - return *this; -} - int32_t DirectoryReader_Dev::GetNextEntry(DirectoryEntry_Dev* entry, const CompletionCallback& cc) { - if (!directory_reader_f) + if (!has_interface<PPB_DirectoryReader_Dev>()) return PP_ERROR_NOINTERFACE; - return directory_reader_f->GetNextEntry(pp_resource(), &entry->data_, - cc.pp_completion_callback()); + return get_interface<PPB_DirectoryReader_Dev>()->GetNextEntry( + pp_resource(), &entry->data_, cc.pp_completion_callback()); } } // namespace pp diff --git a/ppapi/cpp/dev/directory_reader_dev.h b/ppapi/cpp/dev/directory_reader_dev.h index 92f2a23..775d427 100644 --- a/ppapi/cpp/dev/directory_reader_dev.h +++ b/ppapi/cpp/dev/directory_reader_dev.h @@ -23,8 +23,6 @@ class DirectoryReader_Dev : public Resource { DirectoryReader_Dev(const DirectoryReader_Dev& other); - DirectoryReader_Dev& operator=(const DirectoryReader_Dev& other); - // See PPB_DirectoryReader::GetNextEntry. int32_t GetNextEntry(DirectoryEntry_Dev* entry, const CompletionCallback& cc); diff --git a/ppapi/cpp/dev/file_chooser_dev.cc b/ppapi/cpp/dev/file_chooser_dev.cc index 458ba12..1e63ec9 100644 --- a/ppapi/cpp/dev/file_chooser_dev.cc +++ b/ppapi/cpp/dev/file_chooser_dev.cc @@ -12,43 +12,40 @@ #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" +namespace pp { + namespace { -DeviceFuncs<PPB_FileChooser_Dev> file_chooser_f(PPB_FILECHOOSER_DEV_INTERFACE); +template <> const char* interface_name<PPB_FileChooser_Dev>() { + return PPB_FILECHOOSER_DEV_INTERFACE; +} } // namespace -namespace pp { - FileChooser_Dev::FileChooser_Dev(const Instance& instance, const PP_FileChooserOptions_Dev& options) { - if (!file_chooser_f) + if (!has_interface<PPB_FileChooser_Dev>()) return; - PassRefFromConstructor(file_chooser_f->Create(instance.pp_instance(), - &options)); + PassRefFromConstructor(get_interface<PPB_FileChooser_Dev>()->Create( + instance.pp_instance(), &options)); } FileChooser_Dev::FileChooser_Dev(const FileChooser_Dev& other) : Resource(other) { } -FileChooser_Dev& FileChooser_Dev::operator=(const FileChooser_Dev& other) { - Resource::operator=(other); - return *this; -} - - int32_t FileChooser_Dev::Show(const CompletionCallback& cc) { - if (!file_chooser_f) + if (!has_interface<PPB_FileChooser_Dev>()) return PP_ERROR_NOINTERFACE; - return file_chooser_f->Show(pp_resource(), cc.pp_completion_callback()); + return get_interface<PPB_FileChooser_Dev>()->Show( + pp_resource(), cc.pp_completion_callback()); } FileRef_Dev FileChooser_Dev::GetNextChosenFile() const { - if (!file_chooser_f) + if (!has_interface<PPB_FileChooser_Dev>()) return FileRef_Dev(); return FileRef_Dev(FileRef_Dev::PassRef(), - file_chooser_f->GetNextChosenFile(pp_resource())); + get_interface<PPB_FileChooser_Dev>()->GetNextChosenFile(pp_resource())); } } // namespace pp diff --git a/ppapi/cpp/dev/file_chooser_dev.h b/ppapi/cpp/dev/file_chooser_dev.h index 2d0ed22..1feff61 100644 --- a/ppapi/cpp/dev/file_chooser_dev.h +++ b/ppapi/cpp/dev/file_chooser_dev.h @@ -25,8 +25,6 @@ class FileChooser_Dev : public Resource { FileChooser_Dev(const FileChooser_Dev& other); - FileChooser_Dev& operator=(const FileChooser_Dev& other); - // PPB_FileChooser methods: int32_t Show(const CompletionCallback& cc); FileRef_Dev GetNextChosenFile() const; diff --git a/ppapi/cpp/dev/file_io_dev.cc b/ppapi/cpp/dev/file_io_dev.cc index bccfa99..5dae1d3 100644 --- a/ppapi/cpp/dev/file_io_dev.cc +++ b/ppapi/cpp/dev/file_io_dev.cc @@ -12,93 +12,95 @@ #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" +namespace pp { + namespace { -DeviceFuncs<PPB_FileIO_Dev> file_io_f(PPB_FILEIO_DEV_INTERFACE); +template <> const char* interface_name<PPB_FileIO_Dev>() { + return PPB_FILEIO_DEV_INTERFACE; +} } // namespace -namespace pp { - FileIO_Dev::FileIO_Dev() { - if (!file_io_f) + if (!has_interface<PPB_FileIO_Dev>()) return; - PassRefFromConstructor(file_io_f->Create(Module::Get()->pp_module())); + PassRefFromConstructor(get_interface<PPB_FileIO_Dev>()->Create( + Module::Get()->pp_module())); } FileIO_Dev::FileIO_Dev(const FileIO_Dev& other) : Resource(other) { } -FileIO_Dev& FileIO_Dev::operator=(const FileIO_Dev& other) { - Resource::operator=(other); - return *this; -} - int32_t FileIO_Dev::Open(const FileRef_Dev& file_ref, int32_t open_flags, const CompletionCallback& cc) { - if (!file_io_f) + if (!has_interface<PPB_FileIO_Dev>()) return PP_ERROR_NOINTERFACE; - return file_io_f->Open(pp_resource(), file_ref.pp_resource(), open_flags, - cc.pp_completion_callback()); + return get_interface<PPB_FileIO_Dev>()->Open( + pp_resource(), file_ref.pp_resource(), open_flags, + cc.pp_completion_callback()); } int32_t FileIO_Dev::Query(PP_FileInfo_Dev* result_buf, const CompletionCallback& cc) { - if (!file_io_f) + if (!has_interface<PPB_FileIO_Dev>()) return PP_ERROR_NOINTERFACE; - return file_io_f->Query(pp_resource(), result_buf, - cc.pp_completion_callback()); + return get_interface<PPB_FileIO_Dev>()->Query( + pp_resource(), result_buf, cc.pp_completion_callback()); } int32_t FileIO_Dev::Touch(PP_Time last_access_time, PP_Time last_modified_time, const CompletionCallback& cc) { - if (!file_io_f) + if (!has_interface<PPB_FileIO_Dev>()) return PP_ERROR_NOINTERFACE; - return file_io_f->Touch(pp_resource(), last_access_time, last_modified_time, - cc.pp_completion_callback()); + return get_interface<PPB_FileIO_Dev>()->Touch( + pp_resource(), last_access_time, last_modified_time, + cc.pp_completion_callback()); } int32_t FileIO_Dev::Read(int64_t offset, char* buffer, int32_t bytes_to_read, const CompletionCallback& cc) { - if (!file_io_f) + if (!has_interface<PPB_FileIO_Dev>()) return PP_ERROR_NOINTERFACE; - return file_io_f->Read(pp_resource(), offset, buffer, bytes_to_read, - cc.pp_completion_callback()); + return get_interface<PPB_FileIO_Dev>()->Read(pp_resource(), + offset, buffer, bytes_to_read, cc.pp_completion_callback()); } int32_t FileIO_Dev::Write(int64_t offset, const char* buffer, int32_t bytes_to_write, const CompletionCallback& cc) { - if (!file_io_f) + if (!has_interface<PPB_FileIO_Dev>()) return PP_ERROR_NOINTERFACE; - return file_io_f->Write(pp_resource(), offset, buffer, bytes_to_write, - cc.pp_completion_callback()); + return get_interface<PPB_FileIO_Dev>()->Write( + pp_resource(), offset, buffer, bytes_to_write, + cc.pp_completion_callback()); } int32_t FileIO_Dev::SetLength(int64_t length, const CompletionCallback& cc) { - if (!file_io_f) + if (!has_interface<PPB_FileIO_Dev>()) return PP_ERROR_NOINTERFACE; - return file_io_f->SetLength(pp_resource(), length, - cc.pp_completion_callback()); + return get_interface<PPB_FileIO_Dev>()->SetLength( + pp_resource(), length, cc.pp_completion_callback()); } int32_t FileIO_Dev::Flush(const CompletionCallback& cc) { - if (!file_io_f) + if (!has_interface<PPB_FileIO_Dev>()) return PP_ERROR_NOINTERFACE; - return file_io_f->Flush(pp_resource(), cc.pp_completion_callback()); + return get_interface<PPB_FileIO_Dev>()->Flush( + pp_resource(), cc.pp_completion_callback()); } void FileIO_Dev::Close() { - if (!file_io_f) + if (!has_interface<PPB_FileIO_Dev>()) return; - file_io_f->Close(pp_resource()); + get_interface<PPB_FileIO_Dev>()->Close(pp_resource()); } } // namespace pp diff --git a/ppapi/cpp/dev/file_io_dev.h b/ppapi/cpp/dev/file_io_dev.h index 1ec4d06..1da3652 100644 --- a/ppapi/cpp/dev/file_io_dev.h +++ b/ppapi/cpp/dev/file_io_dev.h @@ -20,9 +20,7 @@ class FileIO_Dev : public Resource { FileIO_Dev(); FileIO_Dev(const FileIO_Dev& other); - FileIO_Dev& operator=(const FileIO_Dev& other); - - // PPB_FileIO methods: + // PPB_FileIO methods: int32_t Open(const FileRef_Dev& file_ref, int32_t open_flags, const CompletionCallback& cc); diff --git a/ppapi/cpp/dev/file_ref_dev.cc b/ppapi/cpp/dev/file_ref_dev.cc index 9a8db58..5a8caae 100644 --- a/ppapi/cpp/dev/file_ref_dev.cc +++ b/ppapi/cpp/dev/file_ref_dev.cc @@ -9,14 +9,17 @@ #include "ppapi/cpp/dev/file_system_dev.h" #include "ppapi/cpp/module_impl.h" + +namespace pp { + namespace { -DeviceFuncs<PPB_FileRef_Dev> file_ref_f(PPB_FILEREF_DEV_INTERFACE); +template <> const char* interface_name<PPB_FileRef_Dev>() { + return PPB_FILEREF_DEV_INTERFACE; +} } // namespace -namespace pp { - FileRef_Dev::FileRef_Dev(PP_Resource resource) : Resource(resource) { } @@ -26,94 +29,94 @@ FileRef_Dev::FileRef_Dev(PassRef, PP_Resource resource) { FileRef_Dev::FileRef_Dev(const FileSystem_Dev& file_system, const char* path) { - if (!file_ref_f) + if (!has_interface<PPB_FileRef_Dev>()) return; - PassRefFromConstructor(file_ref_f->Create(file_system.pp_resource(), path)); + PassRefFromConstructor(get_interface<PPB_FileRef_Dev>()->Create( + file_system.pp_resource(), path)); } FileRef_Dev::FileRef_Dev(const FileRef_Dev& other) : Resource(other) { } -FileRef_Dev& FileRef_Dev::operator=(const FileRef_Dev& other) { - Resource::operator=(other); - return *this; -} - PP_FileSystemType_Dev FileRef_Dev::GetFileSystemType() const { - if (!file_ref_f) + if (!has_interface<PPB_FileRef_Dev>()) return PP_FILESYSTEMTYPE_EXTERNAL; - return file_ref_f->GetFileSystemType(pp_resource()); + return get_interface<PPB_FileRef_Dev>()->GetFileSystemType(pp_resource()); } Var FileRef_Dev::GetName() const { - if (!file_ref_f) + if (!has_interface<PPB_FileRef_Dev>()) return Var(); - return Var(Var::PassRef(), file_ref_f->GetName(pp_resource())); + return Var(Var::PassRef(), + get_interface<PPB_FileRef_Dev>()->GetName(pp_resource())); } Var FileRef_Dev::GetPath() const { - if (!file_ref_f) + if (!has_interface<PPB_FileRef_Dev>()) return Var(); - return Var(Var::PassRef(), file_ref_f->GetPath(pp_resource())); + return Var(Var::PassRef(), + get_interface<PPB_FileRef_Dev>()->GetPath(pp_resource())); } FileRef_Dev FileRef_Dev::GetParent() const { - if (!file_ref_f) + if (!has_interface<PPB_FileRef_Dev>()) return FileRef_Dev(); - return FileRef_Dev(PassRef(), file_ref_f->GetParent(pp_resource())); + return FileRef_Dev(PassRef(), + get_interface<PPB_FileRef_Dev>()->GetParent( + pp_resource())); } int32_t FileRef_Dev::MakeDirectory(const CompletionCallback& cc) { - if (!file_ref_f) + if (!has_interface<PPB_FileRef_Dev>()) return PP_ERROR_NOINTERFACE; - return file_ref_f->MakeDirectory(pp_resource(), - PP_FALSE, // make_ancestors - cc.pp_completion_callback()); + return get_interface<PPB_FileRef_Dev>()->MakeDirectory( + pp_resource(), + PP_FALSE, // make_ancestors + cc.pp_completion_callback()); } int32_t FileRef_Dev::MakeDirectoryIncludingAncestors( const CompletionCallback& cc) { - if (!file_ref_f) + if (!has_interface<PPB_FileRef_Dev>()) return PP_ERROR_NOINTERFACE; - return file_ref_f->MakeDirectory(pp_resource(), - PP_TRUE, // make_ancestors - cc.pp_completion_callback()); + return get_interface<PPB_FileRef_Dev>()->MakeDirectory( + pp_resource(), + PP_TRUE, // make_ancestors + cc.pp_completion_callback()); } int32_t FileRef_Dev::Query(PP_FileInfo_Dev* result_buf, const CompletionCallback& cc) { - if (!file_ref_f) + if (!has_interface<PPB_FileRef_Dev>()) return PP_ERROR_NOINTERFACE; - return file_ref_f->Query(pp_resource(), - result_buf, - cc.pp_completion_callback()); + return get_interface<PPB_FileRef_Dev>()->Query( + pp_resource(), result_buf, cc.pp_completion_callback()); } int32_t FileRef_Dev::Touch(PP_Time last_access_time, PP_Time last_modified_time, const CompletionCallback& cc) { - if (!file_ref_f) + if (!has_interface<PPB_FileRef_Dev>()) return PP_ERROR_NOINTERFACE; - return file_ref_f->Touch(pp_resource(), - last_access_time, - last_modified_time, - cc.pp_completion_callback()); + return get_interface<PPB_FileRef_Dev>()->Touch( + pp_resource(), last_access_time, last_modified_time, + cc.pp_completion_callback()); } int32_t FileRef_Dev::Delete(const CompletionCallback& cc) { - if (!file_ref_f) + if (!has_interface<PPB_FileRef_Dev>()) return PP_ERROR_NOINTERFACE; - return file_ref_f->Delete(pp_resource(), cc.pp_completion_callback()); + return get_interface<PPB_FileRef_Dev>()->Delete( + pp_resource(), cc.pp_completion_callback()); } int32_t FileRef_Dev::Rename(const FileRef_Dev& new_file_ref, const CompletionCallback& cc) { - if (!file_ref_f) + if (!has_interface<PPB_FileRef_Dev>()) return PP_ERROR_NOINTERFACE; - return file_ref_f->Rename(pp_resource(), - new_file_ref.pp_resource(), - cc.pp_completion_callback()); + return get_interface<PPB_FileRef_Dev>()->Rename( + pp_resource(), new_file_ref.pp_resource(), cc.pp_completion_callback()); } } // namespace pp diff --git a/ppapi/cpp/dev/file_ref_dev.h b/ppapi/cpp/dev/file_ref_dev.h index 99abd03..279728a 100644 --- a/ppapi/cpp/dev/file_ref_dev.h +++ b/ppapi/cpp/dev/file_ref_dev.h @@ -34,8 +34,6 @@ class FileRef_Dev : public Resource { FileRef_Dev(const FileRef_Dev& other); - FileRef_Dev& operator=(const FileRef_Dev& other); - // Returns the file system type. PP_FileSystemType_Dev GetFileSystemType() const; diff --git a/ppapi/cpp/dev/file_system_dev.cc b/ppapi/cpp/dev/file_system_dev.cc index e6dfaff..6c25e23 100644 --- a/ppapi/cpp/dev/file_system_dev.cc +++ b/ppapi/cpp/dev/file_system_dev.cc @@ -11,27 +11,30 @@ #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" +namespace pp { + namespace { -DeviceFuncs<PPB_FileSystem_Dev> file_sys_f(PPB_FILESYSTEM_DEV_INTERFACE); +template <> const char* interface_name<PPB_FileSystem_Dev>() { + return PPB_FILESYSTEM_DEV_INTERFACE; +} } // namespace -namespace pp { - FileSystem_Dev::FileSystem_Dev(Instance* instance, PP_FileSystemType_Dev type) { - if (!file_sys_f) + if (!has_interface<PPB_FileSystem_Dev>()) return; - PassRefFromConstructor(file_sys_f->Create(instance->pp_instance(), type)); + PassRefFromConstructor(get_interface<PPB_FileSystem_Dev>()->Create( + instance->pp_instance(), type)); } int32_t FileSystem_Dev::Open(int64_t expected_size, const CompletionCallback& cc) { - if (!file_sys_f) + if (!has_interface<PPB_FileSystem_Dev>()) return PP_ERROR_NOINTERFACE; - return file_sys_f->Open(pp_resource(), expected_size, - cc.pp_completion_callback()); + return get_interface<PPB_FileSystem_Dev>()->Open( + pp_resource(), expected_size, cc.pp_completion_callback()); } } // namespace pp diff --git a/ppapi/cpp/dev/find_dev.cc b/ppapi/cpp/dev/find_dev.cc index 74e5915..31a25bd 100644 --- a/ppapi/cpp/dev/find_dev.cc +++ b/ppapi/cpp/dev/find_dev.cc @@ -14,6 +14,10 @@ namespace pp { namespace { +template <> const char* interface_name<PPB_Find_Dev>() { + return PPB_FIND_DEV_INTERFACE; +} + static const char kPPPFindInterface[] = PPP_FIND_DEV_INTERFACE; PP_Bool StartFind(PP_Instance instance, @@ -48,8 +52,6 @@ const PPP_Find_Dev ppp_find = { &StopFind }; -DeviceFuncs<PPB_Find_Dev> ppb_find_f(PPB_FIND_DEV_INTERFACE); - } // namespace Find_Dev::Find_Dev(Instance* instance) : associated_instance_(instance) { @@ -62,17 +64,16 @@ Find_Dev::~Find_Dev() { } void Find_Dev::NumberOfFindResultsChanged(int32_t total, bool final_result) { - if (ppb_find_f) { - ppb_find_f->NumberOfFindResultsChanged(associated_instance_->pp_instance(), - total, - BoolToPPBool(final_result)); + if (has_interface<PPB_Find_Dev>()) { + get_interface<PPB_Find_Dev>()->NumberOfFindResultsChanged( + associated_instance_->pp_instance(), total, BoolToPPBool(final_result)); } } void Find_Dev::SelectedFindResultChanged(int32_t index) { - if (ppb_find_f) { - ppb_find_f->SelectedFindResultChanged(associated_instance_->pp_instance(), - index); + if (has_interface<PPB_Find_Dev>()) { + get_interface<PPB_Find_Dev>()->SelectedFindResultChanged( + associated_instance_->pp_instance(), index); } } diff --git a/ppapi/cpp/dev/font_dev.cc b/ppapi/cpp/dev/font_dev.cc index a58aec2..0bf9cbd 100644 --- a/ppapi/cpp/dev/font_dev.cc +++ b/ppapi/cpp/dev/font_dev.cc @@ -13,14 +13,16 @@ #include "ppapi/cpp/rect.h" #include "ppapi/cpp/module_impl.h" +namespace pp { + namespace { -DeviceFuncs<PPB_Font_Dev> font_f(PPB_FONT_DEV_INTERFACE); +template <> const char* interface_name<PPB_Font_Dev>() { + return PPB_FONT_DEV_INTERFACE; +} } // namespace -namespace pp { - // FontDescription_Dev --------------------------------------------------------- FontDescription_Dev::FontDescription_Dev() { @@ -99,29 +101,25 @@ Font_Dev::Font_Dev(PP_Resource resource) : Resource(resource) { } Font_Dev::Font_Dev(const FontDescription_Dev& description) { - if (!font_f) + if (!has_interface<PPB_Font_Dev>()) return; - PassRefFromConstructor(font_f->Create( + PassRefFromConstructor(get_interface<PPB_Font_Dev>()->Create( Module::Get()->pp_module(), &description.pp_font_description())); } Font_Dev::Font_Dev(const Font_Dev& other) : Resource(other) { } -Font_Dev& Font_Dev::operator=(const Font_Dev& other) { - Resource::operator=(other); - return *this; -} bool Font_Dev::Describe(FontDescription_Dev* description, PP_FontMetrics_Dev* metrics) const { - if (!font_f) + if (!has_interface<PPB_Font_Dev>()) return false; // Be careful with ownership of the |face| string. It will come back with // a ref of 1, which we want to assign to the |face_| member of the C++ class. - if (!font_f->Describe(pp_resource(), &description->pp_font_description_, - metrics)) + if (!get_interface<PPB_Font_Dev>()->Describe( + pp_resource(), &description->pp_font_description_, metrics)) return false; description->face_ = Var(Var::PassRef(), description->pp_font_description_.face); @@ -135,38 +133,40 @@ bool Font_Dev::DrawTextAt(ImageData* dest, uint32_t color, const Rect& clip, bool image_data_is_opaque) const { - if (!font_f) + if (!has_interface<PPB_Font_Dev>()) return false; - return PPBoolToBool(font_f->DrawTextAt(pp_resource(), - dest->pp_resource(), - &text.pp_text_run(), - &position.pp_point(), - color, - &clip.pp_rect(), - BoolToPPBool(image_data_is_opaque))); + return PPBoolToBool(get_interface<PPB_Font_Dev>()->DrawTextAt( + pp_resource(), + dest->pp_resource(), + &text.pp_text_run(), + &position.pp_point(), + color, + &clip.pp_rect(), + BoolToPPBool(image_data_is_opaque))); } int32_t Font_Dev::MeasureText(const TextRun_Dev& text) const { - if (!font_f) + if (!has_interface<PPB_Font_Dev>()) return -1; - return font_f->MeasureText(pp_resource(), &text.pp_text_run()); + return get_interface<PPB_Font_Dev>()->MeasureText(pp_resource(), + &text.pp_text_run()); } uint32_t Font_Dev::CharacterOffsetForPixel(const TextRun_Dev& text, int32_t pixel_position) const { - if (!font_f) + if (!has_interface<PPB_Font_Dev>()) return 0; - return font_f->CharacterOffsetForPixel(pp_resource(), &text.pp_text_run(), - pixel_position); + return get_interface<PPB_Font_Dev>()->CharacterOffsetForPixel( + pp_resource(), &text.pp_text_run(), pixel_position); } int32_t Font_Dev::PixelOffsetForCharacter(const TextRun_Dev& text, uint32_t char_offset) const { - if (!font_f) + if (!has_interface<PPB_Font_Dev>()) return 0; - return font_f->PixelOffsetForCharacter(pp_resource(), &text.pp_text_run(), - char_offset); + return get_interface<PPB_Font_Dev>()->PixelOffsetForCharacter( + pp_resource(), &text.pp_text_run(), char_offset); } bool Font_Dev::DrawSimpleText(ImageData* dest, diff --git a/ppapi/cpp/dev/font_dev.h b/ppapi/cpp/dev/font_dev.h index e356b2b..cbe4b23 100644 --- a/ppapi/cpp/dev/font_dev.h +++ b/ppapi/cpp/dev/font_dev.h @@ -30,12 +30,12 @@ class FontDescription_Dev { FontDescription_Dev(const FontDescription_Dev& other); ~FontDescription_Dev(); + FontDescription_Dev& operator=(const FontDescription_Dev& other); + const PP_FontDescription_Dev& pp_font_description() const { return pp_font_description_; } - FontDescription_Dev& operator=(const FontDescription_Dev& other); - Var face() const { return face_; } void set_face(const Var& face) { face_ = face; diff --git a/ppapi/cpp/dev/fullscreen_dev.cc b/ppapi/cpp/dev/fullscreen_dev.cc index b398b49..e68b296 100644 --- a/ppapi/cpp/dev/fullscreen_dev.cc +++ b/ppapi/cpp/dev/fullscreen_dev.cc @@ -14,9 +14,11 @@ namespace pp { namespace { -DeviceFuncs<PPB_Fullscreen_Dev> ppb_fullscreen_f(PPB_FULLSCREEN_DEV_INTERFACE); +template <> const char* interface_name<PPB_Fullscreen_Dev>() { + return PPB_FULLSCREEN_DEV_INTERFACE; +} -} // anonymous namespace +} // namespace Fullscreen_Dev::Fullscreen_Dev(Instance* instance) : associated_instance_(instance) { @@ -26,16 +28,16 @@ Fullscreen_Dev::~Fullscreen_Dev() { } bool Fullscreen_Dev::IsFullscreen() { - return ppb_fullscreen_f && ppb_fullscreen_f->IsFullscreen( - associated_instance_->pp_instance()); + return has_interface<PPB_Fullscreen_Dev>() && + get_interface<PPB_Fullscreen_Dev>()->IsFullscreen( + associated_instance_->pp_instance()); } bool Fullscreen_Dev::SetFullscreen(bool fullscreen) { - if (!ppb_fullscreen_f) + if (!has_interface<PPB_Fullscreen_Dev>()) return false; - return PPBoolToBool( - ppb_fullscreen_f->SetFullscreen(associated_instance_->pp_instance(), - BoolToPPBool(fullscreen))); + return PPBoolToBool(get_interface<PPB_Fullscreen_Dev>()->SetFullscreen( + associated_instance_->pp_instance(), BoolToPPBool(fullscreen))); } } // namespace pp diff --git a/ppapi/cpp/dev/graphics_3d_dev.cc b/ppapi/cpp/dev/graphics_3d_dev.cc index a15417c..8f03697 100644 --- a/ppapi/cpp/dev/graphics_3d_dev.cc +++ b/ppapi/cpp/dev/graphics_3d_dev.cc @@ -14,27 +14,31 @@ extern "C" { const PPB_OpenGLES_Dev* pepper_opengl_interface = NULL; } +namespace pp { + namespace { -DeviceFuncs<PPB_Graphics3D_Dev> graphics_3d_f(PPB_GRAPHICS_3D_DEV_INTERFACE); -DeviceFuncs<PPB_OpenGLES_Dev> opengles_f(PPB_OPENGLES_DEV_INTERFACE); +template <> const char* interface_name<PPB_Graphics3D_Dev>() { + return PPB_GRAPHICS_3D_DEV_INTERFACE; +} + +template <> const char* interface_name<PPB_OpenGLES_Dev>() { + return PPB_OPENGLES_DEV_INTERFACE; +} inline void InitializeOpenGLCInterface() { if (!pepper_opengl_interface) - pepper_opengl_interface = &(*opengles_f); + pepper_opengl_interface = get_interface<PPB_OpenGLES_Dev>(); } } // namespace -namespace pp { - // static bool Graphics3D_Dev::GetConfigs(int32_t *configs, int32_t config_size, int32_t *num_config) { - if (graphics_3d_f) { - return PPBoolToBool(graphics_3d_f->GetConfigs(configs, - config_size, - num_config)); + if (has_interface<PPB_Graphics3D_Dev>()) { + return PPBoolToBool(get_interface<PPB_Graphics3D_Dev>()->GetConfigs( + configs, config_size, num_config)); } return false; } @@ -42,11 +46,9 @@ bool Graphics3D_Dev::GetConfigs(int32_t *configs, int32_t config_size, // static bool Graphics3D_Dev::ChooseConfig(const int32_t *attrib_list, int32_t *configs, int32_t config_size, int32_t *num_config) { - if (graphics_3d_f) { - return PPBoolToBool(graphics_3d_f->ChooseConfig(attrib_list, - configs, - config_size, - num_config)); + if (has_interface<PPB_Graphics3D_Dev>()) { + return PPBoolToBool(get_interface<PPB_Graphics3D_Dev>()->ChooseConfig( + attrib_list, configs, config_size, num_config)); } return false; } @@ -54,73 +56,77 @@ bool Graphics3D_Dev::ChooseConfig(const int32_t *attrib_list, int32_t *configs, // static bool Graphics3D_Dev::GetConfigAttrib(int32_t config, int32_t attribute, int32_t *value) { - if (graphics_3d_f) { - return PPBoolToBool(graphics_3d_f->GetConfigAttrib(config, - attribute, - value)); + if (has_interface<PPB_Graphics3D_Dev>()) { + return PPBoolToBool(get_interface<PPB_Graphics3D_Dev>()->GetConfigAttrib( + config, attribute, value)); } return false; } // static const char* Graphics3D_Dev::QueryString(int32_t name) { - if (graphics_3d_f) - return graphics_3d_f->QueryString(name); + if (has_interface<PPB_Graphics3D_Dev>()) + return get_interface<PPB_Graphics3D_Dev>()->QueryString(name); return NULL; } // static void* Graphics3D_Dev::GetProcAddress(const char* name) { - if (graphics_3d_f) - return graphics_3d_f->GetProcAddress(name); + if (has_interface<PPB_Graphics3D_Dev>()) + return get_interface<PPB_Graphics3D_Dev>()->GetProcAddress(name); return NULL; } Graphics3D_Dev Graphics3D_Dev::FromResource(PP_Resource resource_id) { - if (graphics_3d_f && graphics_3d_f->IsGraphics3D(resource_id)) + if (has_interface<PPB_Graphics3D_Dev>() && + get_interface<PPB_Graphics3D_Dev>()->IsGraphics3D(resource_id)) return Graphics3D_Dev(resource_id); return Graphics3D_Dev(); } bool Graphics3D_Dev::ResetCurrent() { - return graphics_3d_f && graphics_3d_f->MakeCurent(0); + return has_interface<PPB_Graphics3D_Dev>() && + get_interface<PPB_Graphics3D_Dev>()->MakeCurent(0); } Graphics3D_Dev Graphics3D_Dev::GetCurrentContext() { - if (graphics_3d_f) - return FromResource(graphics_3d_f->GetCurrentContext()); + if (has_interface<PPB_Graphics3D_Dev>()) + return FromResource( + get_interface<PPB_Graphics3D_Dev>()->GetCurrentContext()); return Graphics3D_Dev(); } uint32_t Graphics3D_Dev::GetError() { - if (graphics_3d_f) - return graphics_3d_f->GetError(); + if (has_interface<PPB_Graphics3D_Dev>()) + return get_interface<PPB_Graphics3D_Dev>()->GetError(); return PP_GRAPHICS_3D_ERROR_NOT_INITIALIZED; } const PPB_OpenGLES_Dev* Graphics3D_Dev::GetImplementation() { - return &(*opengles_f); + return get_interface<PPB_OpenGLES_Dev>(); } Graphics3D_Dev::Graphics3D_Dev(const Instance& instance, int32_t config, int32_t share_context, const int32_t* attrib_list) { - if (graphics_3d_f && opengles_f) { + if (has_interface<PPB_Graphics3D_Dev>() && + has_interface<PPB_OpenGLES_Dev>()) { InitializeOpenGLCInterface(); - PassRefFromConstructor(graphics_3d_f->CreateContext(instance.pp_instance(), - config, share_context, - attrib_list)); + PassRefFromConstructor(get_interface<PPB_Graphics3D_Dev>()->CreateContext( + instance.pp_instance(), config, share_context, attrib_list)); } } bool Graphics3D_Dev::MakeCurrent() const { InitializeOpenGLCInterface(); - return graphics_3d_f && graphics_3d_f->MakeCurent(pp_resource()); + return has_interface<PPB_Graphics3D_Dev>() && + get_interface<PPB_Graphics3D_Dev>()->MakeCurent(pp_resource()); } bool Graphics3D_Dev::SwapBuffers() const { - return graphics_3d_f && graphics_3d_f->SwapBuffers(pp_resource()); + return has_interface<PPB_Graphics3D_Dev>() && + get_interface<PPB_Graphics3D_Dev>()->SwapBuffers(pp_resource()); } } // namespace pp diff --git a/ppapi/cpp/dev/scrollbar_dev.cc b/ppapi/cpp/dev/scrollbar_dev.cc index f5dc570..456190f 100644 --- a/ppapi/cpp/dev/scrollbar_dev.cc +++ b/ppapi/cpp/dev/scrollbar_dev.cc @@ -12,57 +12,54 @@ #include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/rect.h" +namespace pp { + namespace { -DeviceFuncs<PPB_Scrollbar_Dev> scrollbar_f(PPB_SCROLLBAR_DEV_INTERFACE); +template <> const char* interface_name<PPB_Scrollbar_Dev>() { + return PPB_SCROLLBAR_DEV_INTERFACE; +} } // namespace -namespace pp { - Scrollbar_Dev::Scrollbar_Dev(PP_Resource resource) : Widget_Dev(resource) { } Scrollbar_Dev::Scrollbar_Dev(const Instance& instance, bool vertical) { - if (!scrollbar_f) + if (!has_interface<PPB_Scrollbar_Dev>()) return; - PassRefFromConstructor(scrollbar_f->Create(instance.pp_instance(), - BoolToPPBool(vertical))); + PassRefFromConstructor(get_interface<PPB_Scrollbar_Dev>()->Create( + instance.pp_instance(), BoolToPPBool(vertical))); } Scrollbar_Dev::Scrollbar_Dev(const Scrollbar_Dev& other) : Widget_Dev(other) { } -Scrollbar_Dev& Scrollbar_Dev::operator=(const Scrollbar_Dev& other) { - Resource::operator=(other); - return *this; -} - uint32_t Scrollbar_Dev::GetThickness() { - if (!scrollbar_f) + if (!has_interface<PPB_Scrollbar_Dev>()) return 0; - return scrollbar_f->GetThickness(); + return get_interface<PPB_Scrollbar_Dev>()->GetThickness(); } uint32_t Scrollbar_Dev::GetValue() { - if (!scrollbar_f) + if (!has_interface<PPB_Scrollbar_Dev>()) return 0; - return scrollbar_f->GetValue(pp_resource()); + return get_interface<PPB_Scrollbar_Dev>()->GetValue(pp_resource()); } void Scrollbar_Dev::SetValue(uint32_t value) { - if (scrollbar_f) - scrollbar_f->SetValue(pp_resource(), value); + if (has_interface<PPB_Scrollbar_Dev>()) + get_interface<PPB_Scrollbar_Dev>()->SetValue(pp_resource(), value); } void Scrollbar_Dev::SetDocumentSize(uint32_t size) { - if (scrollbar_f) - scrollbar_f->SetDocumentSize(pp_resource(), size); + if (has_interface<PPB_Scrollbar_Dev>()) + get_interface<PPB_Scrollbar_Dev>()->SetDocumentSize(pp_resource(), size); } void Scrollbar_Dev::SetTickMarks(const Rect* tick_marks, uint32_t count) { - if (!scrollbar_f) + if (!has_interface<PPB_Scrollbar_Dev>()) return; std::vector<PP_Rect> temp; @@ -70,12 +67,15 @@ void Scrollbar_Dev::SetTickMarks(const Rect* tick_marks, uint32_t count) { for (uint32_t i = 0; i < count; ++i) temp[i] = tick_marks[i]; - scrollbar_f->SetTickMarks(pp_resource(), count ? &temp[0] : NULL, count); + get_interface<PPB_Scrollbar_Dev>()->SetTickMarks( + pp_resource(), count ? &temp[0] : NULL, count); } void Scrollbar_Dev::ScrollBy(PP_ScrollBy_Dev unit, int32_t multiplier) { - if (scrollbar_f) - scrollbar_f->ScrollBy(pp_resource(), unit, multiplier); + if (has_interface<PPB_Scrollbar_Dev>()) + get_interface<PPB_Scrollbar_Dev>()->ScrollBy(pp_resource(), + unit, + multiplier); } } // namespace pp diff --git a/ppapi/cpp/dev/transport_dev.cc b/ppapi/cpp/dev/transport_dev.cc index f7eae6b..0ea4a34 100644 --- a/ppapi/cpp/dev/transport_dev.cc +++ b/ppapi/cpp/dev/transport_dev.cc @@ -9,19 +9,21 @@ #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" +namespace pp { + namespace { -DeviceFuncs<PPB_Transport_Dev> transport_f(PPB_TRANSPORT_DEV_INTERFACE); +template <> const char* interface_name<PPB_Transport_Dev>() { + return PPB_TRANSPORT_DEV_INTERFACE; +} } // namespace -namespace pp { - Transport_Dev::Transport_Dev(const char* name, const char* proto) { - if (transport_f) - PassRefFromConstructor( - transport_f->CreateTransport(Module::Get()->pp_module(), name, proto)); + if (has_interface<PPB_Transport_Dev>()) + PassRefFromConstructor(get_interface<PPB_Transport_Dev>()->CreateTransport( + Module::Get()->pp_module(), name, proto)); } } // namespace pp diff --git a/ppapi/cpp/dev/video_decoder_dev.cc b/ppapi/cpp/dev/video_decoder_dev.cc index bda3b58..503b446 100644 --- a/ppapi/cpp/dev/video_decoder_dev.cc +++ b/ppapi/cpp/dev/video_decoder_dev.cc @@ -10,71 +10,64 @@ #include "ppapi/cpp/module.h" #include "ppapi/cpp/module_impl.h" +namespace pp { + namespace { -DeviceFuncs<PPB_VideoDecoder_Dev> video_decoder_f( - PPB_VIDEODECODER_DEV_INTERFACE); +template <> const char* interface_name<PPB_VideoDecoder_Dev>() { + return PPB_VIDEODECODER_DEV_INTERFACE; +} } // namespace - -namespace pp { - VideoDecoder_Dev::VideoDecoder_Dev(PP_Resource resource) : Resource(resource) { } VideoDecoder_Dev::VideoDecoder_Dev( const Instance& instance, const PP_VideoDecoderConfig_Dev& decoder_config) { - if (!video_decoder_f) + if (!has_interface<PPB_VideoDecoder_Dev>()) return; - PassRefFromConstructor(video_decoder_f->Create(instance.pp_instance(), - &decoder_config)); + PassRefFromConstructor(get_interface<PPB_VideoDecoder_Dev>()->Create( + instance.pp_instance(), &decoder_config)); } VideoDecoder_Dev::VideoDecoder_Dev(const VideoDecoder_Dev& other) : Resource(other) { } -VideoDecoder_Dev& VideoDecoder_Dev::operator=(const VideoDecoder_Dev& other) { - Resource::operator=(other); - return *this; -} - // static bool VideoDecoder_Dev::GetConfig(const Instance& instance, PP_VideoCodecId_Dev codec, PP_VideoConfig_Dev* configs, int32_t config_size, int32_t* num_config) { - if (!video_decoder_f) + if (!has_interface<PPB_VideoDecoder_Dev>()) return false; - return PPBoolToBool(video_decoder_f->GetConfig(instance.pp_instance(), - codec, - configs, - config_size, - num_config)); + return PPBoolToBool(get_interface<PPB_VideoDecoder_Dev>()->GetConfig( + instance.pp_instance(), codec, configs, config_size, num_config)); } bool VideoDecoder_Dev::Decode(PP_VideoCompressedDataBuffer_Dev& input_buffer) { - if (!video_decoder_f || !pp_resource()) + if (!has_interface<PPB_VideoDecoder_Dev>() || !pp_resource()) return false; - return PPBoolToBool(video_decoder_f->Decode(pp_resource(), &input_buffer)); + return PPBoolToBool(get_interface<PPB_VideoDecoder_Dev>()->Decode( + pp_resource(), &input_buffer)); } int32_t VideoDecoder_Dev::Flush(PP_CompletionCallback callback) { - if (!video_decoder_f) + if (!has_interface<PPB_VideoDecoder_Dev>()) return PP_ERROR_NOINTERFACE; - return video_decoder_f->Flush(pp_resource(), callback); + return get_interface<PPB_VideoDecoder_Dev>()->Flush(pp_resource(), callback); } bool VideoDecoder_Dev::ReturnUncompressedDataBuffer( PP_VideoUncompressedDataBuffer_Dev& buffer) { - if (!video_decoder_f || !pp_resource()) + if (!has_interface<PPB_VideoDecoder_Dev>() || !pp_resource()) return false; return PPBoolToBool( - video_decoder_f->ReturnUncompressedDataBuffer(pp_resource(), - &buffer)); + get_interface<PPB_VideoDecoder_Dev>()->ReturnUncompressedDataBuffer( + pp_resource(), &buffer)); } } // namespace pp diff --git a/ppapi/cpp/dev/video_decoder_dev.h b/ppapi/cpp/dev/video_decoder_dev.h index 15743ca..ea7d052 100644 --- a/ppapi/cpp/dev/video_decoder_dev.h +++ b/ppapi/cpp/dev/video_decoder_dev.h @@ -25,8 +25,6 @@ class VideoDecoder_Dev : public Resource { const PP_VideoDecoderConfig_Dev& decoder_config); VideoDecoder_Dev(const VideoDecoder_Dev& other); - VideoDecoder_Dev& operator=(const VideoDecoder_Dev& other); - // PPB_VideoDecoder methods: static bool GetConfig(const Instance& instance, PP_VideoCodecId_Dev codec, diff --git a/ppapi/cpp/dev/widget_dev.cc b/ppapi/cpp/dev/widget_dev.cc index 46f36b5..f69a873 100644 --- a/ppapi/cpp/dev/widget_dev.cc +++ b/ppapi/cpp/dev/widget_dev.cc @@ -12,49 +12,47 @@ #include "ppapi/cpp/rect.h" #include "ppapi/cpp/module_impl.h" +namespace pp { + namespace { -DeviceFuncs<PPB_Widget_Dev> widget_f(PPB_WIDGET_DEV_INTERFACE); +template <> const char* interface_name<PPB_Widget_Dev>() { + return PPB_WIDGET_DEV_INTERFACE; +} } // namespace -namespace pp { - Widget_Dev::Widget_Dev(PP_Resource resource) : Resource(resource) { } Widget_Dev::Widget_Dev(const Widget_Dev& other) : Resource(other) { } -Widget_Dev& Widget_Dev::operator=(const Widget_Dev& other) { - Resource::operator=(other); - return *this; -} - bool Widget_Dev::Paint(const Rect& rect, ImageData* image) { - if (!widget_f) + if (!has_interface<PPB_Widget_Dev>()) return false; - return PPBoolToBool(widget_f->Paint(pp_resource(), - &rect.pp_rect(), - image->pp_resource())); + return PPBoolToBool(get_interface<PPB_Widget_Dev>()->Paint( + pp_resource(), &rect.pp_rect(), image->pp_resource())); } bool Widget_Dev::HandleEvent(const PP_InputEvent& event) { - if (!widget_f) + if (!has_interface<PPB_Widget_Dev>()) return false; - return PPBoolToBool(widget_f->HandleEvent(pp_resource(), &event)); + return PPBoolToBool(get_interface<PPB_Widget_Dev>()->HandleEvent( + pp_resource(), &event)); } bool Widget_Dev::GetLocation(Rect* location) { - if (!widget_f) + if (!has_interface<PPB_Widget_Dev>()) return false; - return PPBoolToBool(widget_f->GetLocation(pp_resource(), - &location->pp_rect())); + return PPBoolToBool(get_interface<PPB_Widget_Dev>()->GetLocation( + pp_resource(), &location->pp_rect())); } void Widget_Dev::SetLocation(const Rect& location) { - if (widget_f) - widget_f->SetLocation(pp_resource(), &location.pp_rect()); + if (has_interface<PPB_Widget_Dev>()) + get_interface<PPB_Widget_Dev>()->SetLocation(pp_resource(), + &location.pp_rect()); } } // namespace pp diff --git a/ppapi/cpp/dev/widget_dev.h b/ppapi/cpp/dev/widget_dev.h index 8252946..bdc1399 100644 --- a/ppapi/cpp/dev/widget_dev.h +++ b/ppapi/cpp/dev/widget_dev.h @@ -26,8 +26,6 @@ class Widget_Dev : public Resource { explicit Widget_Dev(PP_Resource resource); Widget_Dev(const Widget_Dev& other); - Widget_Dev& operator=(const Widget_Dev& other); - // PPB_Widget methods: bool Paint(const Rect& rect, ImageData* image); bool HandleEvent(const PP_InputEvent& event); diff --git a/ppapi/cpp/dev/zoom_dev.cc b/ppapi/cpp/dev/zoom_dev.cc index 3d20676..9451e9a 100644 --- a/ppapi/cpp/dev/zoom_dev.cc +++ b/ppapi/cpp/dev/zoom_dev.cc @@ -31,7 +31,9 @@ const PPP_Zoom_Dev ppp_zoom = { &Zoom }; -DeviceFuncs<PPB_Zoom_Dev> ppb_zoom_f(PPB_ZOOM_DEV_INTERFACE); +template <> const char* interface_name<PPB_Zoom_Dev>() { + return PPB_ZOOM_DEV_INTERFACE; +} } // namespace @@ -45,15 +47,16 @@ Zoom_Dev::~Zoom_Dev() { } void Zoom_Dev::ZoomChanged(double factor) { - if (ppb_zoom_f) - ppb_zoom_f->ZoomChanged(associated_instance_->pp_instance(), factor); + if (has_interface<PPB_Zoom_Dev>()) + get_interface<PPB_Zoom_Dev>()->ZoomChanged( + associated_instance_->pp_instance(), factor); } void Zoom_Dev::ZoomLimitsChanged(double minimum_factor, double maximium_factor) { - if (!ppb_zoom_f) + if (!has_interface<PPB_Zoom_Dev>()) return; - ppb_zoom_f->ZoomLimitsChanged( + get_interface<PPB_Zoom_Dev>()->ZoomLimitsChanged( associated_instance_->pp_instance(), minimum_factor, maximium_factor); } |