diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-27 21:50:28 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-27 21:50:28 +0000 |
commit | 9815108ef72b28eab4c78fe43db9db171f24cd57 (patch) | |
tree | f7fe8ea186168eb655eb927113a7f68886ed65dd /ppapi/proxy/ppb_buffer_proxy.cc | |
parent | 25fe7fc560ac4350eb57f070194e2755279f7fb4 (diff) | |
download | chromium_src-9815108ef72b28eab4c78fe43db9db171f24cd57.zip chromium_src-9815108ef72b28eab4c78fe43db9db171f24cd57.tar.gz chromium_src-9815108ef72b28eab4c78fe43db9db171f24cd57.tar.bz2 |
Move Broker, Buffer, CharSet, and CursorControl to use the new thunk/API system.
This changes the way that the function APIs work in the webkit directory, now
they're created per-instance rather than globally, and have their
Plugininstance as a class member (this cleans up some code). I had to move the
InstanceData member to be a linked_ptr due to copy constructor issues, but this
should be more efficient anyway.
Review URL: http://codereview.chromium.org/7077024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87094 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy/ppb_buffer_proxy.cc')
-rw-r--r-- | ppapi/proxy/ppb_buffer_proxy.cc | 117 |
1 files changed, 55 insertions, 62 deletions
diff --git a/ppapi/proxy/ppb_buffer_proxy.cc b/ppapi/proxy/ppb_buffer_proxy.cc index a74bf18..d6f910f 100644 --- a/ppapi/proxy/ppb_buffer_proxy.cc +++ b/ppapi/proxy/ppb_buffer_proxy.cc @@ -14,11 +14,23 @@ #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource.h" #include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/thunk/ppb_buffer_api.h" +#include "ppapi/thunk/thunk.h" namespace pp { namespace proxy { -class Buffer : public PluginResource { +namespace { + +InterfaceProxy* CreateBufferProxy(Dispatcher* dispatcher, + const void* target_interface) { + return new PPB_Buffer_Proxy(dispatcher, target_interface); +} + +} // namespace + +class Buffer : public ppapi::thunk::PPB_Buffer_API, + public PluginResource { public: Buffer(const HostResource& resource, int memory_handle, @@ -26,12 +38,16 @@ class Buffer : public PluginResource { virtual ~Buffer(); // Resource overrides. - virtual Buffer* AsBuffer() { return this; } + virtual Buffer* AsBuffer() OVERRIDE; - uint32_t size() const { return size_; } + // ResourceObjectBase overries. + virtual ppapi::thunk::PPB_Buffer_API* AsBuffer_API() OVERRIDE; - 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: int memory_handle_; @@ -55,75 +71,32 @@ Buffer::~Buffer() { Unmap(); } -void* Buffer::Map() { - // TODO(brettw) implement this. - return mapped_data_; +Buffer* Buffer::AsBuffer() { + return this; } -void Buffer::Unmap() { - // TODO(brettw) implement this. +ppapi::thunk::PPB_Buffer_API* Buffer::AsBuffer_API() { + return this; } -namespace { - -PP_Resource Create(PP_Instance instance, uint32_t size) { - HostResource result; - int32_t shm_handle = -1; - PluginDispatcher::GetForInstance(instance)->Send( - new PpapiHostMsg_PPBBuffer_Create( - INTERFACE_ID_PPB_BUFFER, instance, size, - &result, &shm_handle)); - if (result.is_null()) - return 0; - - linked_ptr<Buffer> object(new Buffer(result, - static_cast<int>(shm_handle), size)); - return PluginResourceTracker::GetInstance()->AddResource(object); -} - -PP_Bool IsBuffer(PP_Resource resource) { - Buffer* object = PluginResource::GetAs<Buffer>(resource); - return BoolToPPBool(!!object); -} - -PP_Bool Describe(PP_Resource resource, uint32_t* size_in_bytes) { - Buffer* object = PluginResource::GetAs<Buffer>(resource); - if (!object) { - *size_in_bytes = 0; - return PP_FALSE; - } - *size_in_bytes = object->size(); +PP_Bool Buffer::Describe(uint32_t* size_in_bytes) { + *size_in_bytes = size_; return PP_TRUE; } -void* Map(PP_Resource resource) { - Buffer* object = PluginResource::GetAs<Buffer>(resource); - if (!object) - return NULL; - return object->Map(); +PP_Bool Buffer::IsMapped() { + return PP_FromBool(!!mapped_data_); } -void Unmap(PP_Resource resource) { - Buffer* object = PluginResource::GetAs<Buffer>(resource); - if (object) - object->Unmap(); +void* Buffer::Map() { + // TODO(brettw) implement this. + return mapped_data_; } -const PPB_Buffer_Dev buffer_interface = { - &Create, - &IsBuffer, - &Describe, - &Map, - &Unmap, -}; - -InterfaceProxy* CreateBufferProxy(Dispatcher* dispatcher, - const void* target_interface) { - return new PPB_Buffer_Proxy(dispatcher, target_interface); +void Buffer::Unmap() { + // TODO(brettw) implement this. } -} // namespace - PPB_Buffer_Proxy::PPB_Buffer_Proxy(Dispatcher* dispatcher, const void* target_interface) : InterfaceProxy(dispatcher, target_interface) { @@ -135,7 +108,7 @@ PPB_Buffer_Proxy::~PPB_Buffer_Proxy() { // static const InterfaceProxy::Info* PPB_Buffer_Proxy::GetInfo() { static const Info info = { - &buffer_interface, + ppapi::thunk::GetPPB_Buffer_Thunk(), PPB_BUFFER_DEV_INTERFACE, INTERFACE_ID_PPB_BUFFER, false, @@ -144,6 +117,26 @@ const InterfaceProxy::Info* PPB_Buffer_Proxy::GetInfo() { return &info; } +// static +PP_Resource PPB_Buffer_Proxy::CreateProxyResource(PP_Instance instance, + uint32_t size) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return 0; + + HostResource result; + int32_t shm_handle = -1; + dispatcher->Send(new PpapiHostMsg_PPBBuffer_Create( + INTERFACE_ID_PPB_BUFFER, instance, size, + &result, &shm_handle)); + if (result.is_null()) + return 0; + + linked_ptr<Buffer> object(new Buffer(result, + static_cast<int>(shm_handle), size)); + return PluginResourceTracker::GetInstance()->AddResource(object); +} + bool PPB_Buffer_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_Buffer_Proxy, msg) |