diff options
Diffstat (limited to 'webkit/plugins/ppapi/ppb_buffer_impl.h')
-rw-r--r-- | webkit/plugins/ppapi/ppb_buffer_impl.h | 59 |
1 files changed, 39 insertions, 20 deletions
diff --git a/webkit/plugins/ppapi/ppb_buffer_impl.h b/webkit/plugins/ppapi/ppb_buffer_impl.h index e7d83f9..f68c825 100644 --- a/webkit/plugins/ppapi/ppb_buffer_impl.h +++ b/webkit/plugins/ppapi/ppb_buffer_impl.h @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "base/shared_memory.h" +#include "ppapi/thunk/ppb_buffer_api.h" #include "webkit/plugins/ppapi/resource.h" struct PPB_Buffer_Dev; @@ -17,41 +18,59 @@ namespace ppapi { class PluginInstance; -class PPB_Buffer_Impl : public Resource { +class PPB_Buffer_Impl : public Resource, + public ::ppapi::thunk::PPB_Buffer_API { public: - explicit PPB_Buffer_Impl(PluginInstance* instance); virtual ~PPB_Buffer_Impl(); - uint32_t size() const { return size_; } - unsigned char* mapped_buffer() const { - return static_cast<unsigned char*>(shared_memory_->memory()); - } - base::SharedMemoryHandle handle() const { return shared_memory_->handle(); } + static PP_Resource Create(PP_Instance instance, uint32_t size); - // Returns true if this buffer is mapped. False means that the buffer is - // either invalid or not mapped. - bool is_mapped() const { return mapped_buffer() != NULL; } + virtual PPB_Buffer_Impl* AsPPB_Buffer_Impl(); - // Returns a pointer to the interface implementing PPB_Buffer_Impl that is - // exposed to the plugin. - static const PPB_Buffer_Dev* GetInterface(); + base::SharedMemory* shared_memory() const { return shared_memory_.get(); } + uint32_t size() const { return size_; } - // Resource overrides. - virtual PPB_Buffer_Impl* AsPPB_Buffer_Impl(); + // ResourceObjectBase overries. + virtual ::ppapi::thunk::PPB_Buffer_API* AsBuffer_API() OVERRIDE; - // PPB_Buffer_Impl implementation. - bool Init(uint32_t size); - void Describe(uint32_t* size_in_bytes) const; - void* Map(); - void Unmap(); + // PPB_Buffer_API implementation. + virtual PP_Bool Describe(uint32_t* size_in_bytes) OVERRIDE; + virtual PP_Bool IsMapped() OVERRIDE; + virtual void* Map() OVERRIDE; + virtual void Unmap() OVERRIDE; private: + explicit PPB_Buffer_Impl(PluginInstance* instance); + bool Init(uint32_t size); + scoped_ptr<base::SharedMemory> shared_memory_; uint32_t size_; DISALLOW_COPY_AND_ASSIGN(PPB_Buffer_Impl); }; +// Ensures that the given buffer is mapped, and retursn it to its previous +// mapped state in the destructor. +class BufferAutoMapper { + public: + BufferAutoMapper(::ppapi::thunk::PPB_Buffer_API* api); + ~BufferAutoMapper(); + + // Will be NULL on failure to map. + void* data() { return data_; } + uint32_t size() { return size_; } + + private: + ::ppapi::thunk::PPB_Buffer_API* api_; + + bool needs_unmap_; + + void* data_; + uint32_t size_; + + DISALLOW_COPY_AND_ASSIGN(BufferAutoMapper); +}; + } // namespace ppapi } // namespace webkit |