Commit 2a1d6d91 authored by brettw@chromium.org's avatar brettw@chromium.org

Regularize how ImageData and Graphics2D are created.

These objects were created differently than any other resoures. This cleans
them up to behave like the other resources.

BUG=
TEST=

Review URL: http://codereview.chromium.org/8790009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112946 0039d316-1c4b-4281-b951-d872f2087c98
parent 1098044e
...@@ -754,6 +754,11 @@ IPC_SYNC_MESSAGE_CONTROL0_1(PpapiHostMsg_PPBFont_GetFontFamilies, ...@@ -754,6 +754,11 @@ IPC_SYNC_MESSAGE_CONTROL0_1(PpapiHostMsg_PPBFont_GetFontFamilies,
std::string /* result */) std::string /* result */)
// PPB_Graphics2D. // PPB_Graphics2D.
IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBGraphics2D_Create,
PP_Instance /* instance */,
PP_Size /* size */,
PP_Bool /* is_always_opaque */,
ppapi::HostResource /* result */)
IPC_MESSAGE_ROUTED5(PpapiHostMsg_PPBGraphics2D_PaintImageData, IPC_MESSAGE_ROUTED5(PpapiHostMsg_PPBGraphics2D_PaintImageData,
ppapi::HostResource /* graphics_2d */, ppapi::HostResource /* graphics_2d */,
ppapi::HostResource /* image_data */, ppapi::HostResource /* image_data */,
...@@ -776,44 +781,46 @@ IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBGraphics3D_Create, ...@@ -776,44 +781,46 @@ IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBGraphics3D_Create,
PP_Instance /* instance */, PP_Instance /* instance */,
std::vector<int32_t> /* attrib_list */, std::vector<int32_t> /* attrib_list */,
ppapi::HostResource /* result */) ppapi::HostResource /* result */)
IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBGraphics3D_InitCommandBuffer, IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBGraphics3D_InitCommandBuffer,
ppapi::HostResource /* context */, ppapi::HostResource /* context */,
int32 /* size */, int32 /* size */,
base::SharedMemoryHandle /* ring_buffer */) base::SharedMemoryHandle /* ring_buffer */)
IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBGraphics3D_GetState, IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBGraphics3D_GetState,
ppapi::HostResource /* context */, ppapi::HostResource /* context */,
gpu::CommandBuffer::State /* state */) gpu::CommandBuffer::State /* state */)
IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBGraphics3D_Flush, IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBGraphics3D_Flush,
ppapi::HostResource /* context */, ppapi::HostResource /* context */,
int32 /* put_offset */, int32 /* put_offset */,
int32 /* last_known_get */, int32 /* last_known_get */,
gpu::CommandBuffer::State /* state */) gpu::CommandBuffer::State /* state */)
IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBGraphics3D_AsyncFlush, IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBGraphics3D_AsyncFlush,
ppapi::HostResource /* context */, ppapi::HostResource /* context */,
int32 /* put_offset */) int32 /* put_offset */)
IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer, IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer,
ppapi::HostResource /* context */, ppapi::HostResource /* context */,
int32 /* size */, int32 /* size */,
int32 /* id */) int32 /* id */)
IPC_SYNC_MESSAGE_ROUTED2_0(PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer, IPC_SYNC_MESSAGE_ROUTED2_0(PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer,
ppapi::HostResource /* context */, ppapi::HostResource /* context */,
int32 /* id */) int32 /* id */)
IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBGraphics3D_GetTransferBuffer, IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBGraphics3D_GetTransferBuffer,
ppapi::HostResource /* context */, ppapi::HostResource /* context */,
int32 /* id */, int32 /* id */,
base::SharedMemoryHandle /* transfer_buffer */, base::SharedMemoryHandle /* transfer_buffer */,
uint32 /* size */) uint32 /* size */)
IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBGraphics3D_SwapBuffers, IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBGraphics3D_SwapBuffers,
ppapi::HostResource /* graphics_3d */) ppapi::HostResource /* graphics_3d */)
// PPB_ImageData.
IPC_SYNC_MESSAGE_ROUTED4_3(PpapiHostMsg_PPBImageData_Create,
PP_Instance /* instance */,
int32 /* format */,
PP_Size /* size */,
PP_Bool /* init_to_zero */,
ppapi::HostResource /* result_resource */,
std::string /* image_data_desc */,
ppapi::proxy::ImageHandle /* result */)
// PPB_Instance. // PPB_Instance.
IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBInstance_GetWindowObject, IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBInstance_GetWindowObject,
PP_Instance /* instance */, PP_Instance /* instance */,
...@@ -1026,20 +1033,6 @@ IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBVar_CreateObjectDeprecated, ...@@ -1026,20 +1033,6 @@ IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBVar_CreateObjectDeprecated,
int64 /* object_data */, int64 /* object_data */,
ppapi::proxy::SerializedVar /* result */) ppapi::proxy::SerializedVar /* result */)
IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_ResourceCreation_Graphics2D,
PP_Instance /* instance */,
PP_Size /* size */,
PP_Bool /* is_always_opaque */,
ppapi::HostResource /* result */)
IPC_SYNC_MESSAGE_ROUTED4_3(PpapiHostMsg_ResourceCreation_ImageData,
PP_Instance /* instance */,
int32 /* format */,
PP_Size /* size */,
PP_Bool /* init_to_zero */,
ppapi::HostResource /* result_resource */,
std::string /* image_data_desc */,
ppapi::proxy::ImageHandle /* result */)
// PPB_VideoCapture_Dev. // PPB_VideoCapture_Dev.
IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBVideoCapture_Create, IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBVideoCapture_Create,
PP_Instance /* instance */, PP_Instance /* instance */,
......
...@@ -52,6 +52,8 @@ class Graphics2D : public Resource, public thunk::PPB_Graphics2D_API { ...@@ -52,6 +52,8 @@ class Graphics2D : public Resource, public thunk::PPB_Graphics2D_API {
return PluginDispatcher::GetForResource(this); return PluginDispatcher::GetForResource(this);
} }
static const ApiID kApiID = API_ID_PPB_GRAPHICS_2D;
PP_Size size_; PP_Size size_;
PP_Bool is_always_opaque_; PP_Bool is_always_opaque_;
...@@ -95,9 +97,8 @@ void Graphics2D::PaintImageData(PP_Resource image_data, ...@@ -95,9 +97,8 @@ void Graphics2D::PaintImageData(PP_Resource image_data,
PP_Rect dummy; PP_Rect dummy;
memset(&dummy, 0, sizeof(PP_Rect)); memset(&dummy, 0, sizeof(PP_Rect));
GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_PaintImageData( GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_PaintImageData(
API_ID_PPB_GRAPHICS_2D, host_resource(), kApiID, host_resource(), image_object->host_resource(), *top_left,
image_object->host_resource(), *top_left, !!src_rect, !!src_rect, src_rect ? *src_rect : dummy));
src_rect ? *src_rect : dummy));
} }
void Graphics2D::Scroll(const PP_Rect* clip_rect, void Graphics2D::Scroll(const PP_Rect* clip_rect,
...@@ -105,8 +106,8 @@ void Graphics2D::Scroll(const PP_Rect* clip_rect, ...@@ -105,8 +106,8 @@ void Graphics2D::Scroll(const PP_Rect* clip_rect,
PP_Rect dummy; PP_Rect dummy;
memset(&dummy, 0, sizeof(PP_Rect)); memset(&dummy, 0, sizeof(PP_Rect));
GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Scroll( GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Scroll(
API_ID_PPB_GRAPHICS_2D, host_resource(), kApiID, host_resource(), !!clip_rect, clip_rect ? *clip_rect : dummy,
!!clip_rect, clip_rect ? *clip_rect : dummy, *amount)); *amount));
} }
void Graphics2D::ReplaceContents(PP_Resource image_data) { void Graphics2D::ReplaceContents(PP_Resource image_data) {
...@@ -116,8 +117,7 @@ void Graphics2D::ReplaceContents(PP_Resource image_data) { ...@@ -116,8 +117,7 @@ void Graphics2D::ReplaceContents(PP_Resource image_data) {
return; return;
GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents( GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_ReplaceContents(
API_ID_PPB_GRAPHICS_2D, host_resource(), kApiID, host_resource(), image_object->host_resource()));
image_object->host_resource()));
} }
int32_t Graphics2D::Flush(PP_CompletionCallback callback) { int32_t Graphics2D::Flush(PP_CompletionCallback callback) {
...@@ -130,8 +130,8 @@ int32_t Graphics2D::Flush(PP_CompletionCallback callback) { ...@@ -130,8 +130,8 @@ int32_t Graphics2D::Flush(PP_CompletionCallback callback) {
return PP_ERROR_INPROGRESS; // Can't have >1 flush pending. return PP_ERROR_INPROGRESS; // Can't have >1 flush pending.
current_flush_callback_ = callback; current_flush_callback_ = callback;
GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Flush( GetDispatcher()->Send(new PpapiHostMsg_PPBGraphics2D_Flush(kApiID,
API_ID_PPB_GRAPHICS_2D, host_resource())); host_resource()));
return PP_OK_COMPLETIONPENDING; return PP_OK_COMPLETIONPENDING;
} }
...@@ -157,9 +157,8 @@ PP_Resource PPB_Graphics2D_Proxy::CreateProxyResource( ...@@ -157,9 +157,8 @@ PP_Resource PPB_Graphics2D_Proxy::CreateProxyResource(
return 0; return 0;
HostResource result; HostResource result;
dispatcher->Send(new PpapiHostMsg_ResourceCreation_Graphics2D( dispatcher->Send(new PpapiHostMsg_PPBGraphics2D_Create(
API_ID_RESOURCE_CREATION, instance, size, is_always_opaque, kApiID, instance, size, is_always_opaque, &result));
&result));
if (result.is_null()) if (result.is_null())
return 0; return 0;
return (new Graphics2D(result, size, is_always_opaque))->GetReference(); return (new Graphics2D(result, size, is_always_opaque))->GetReference();
...@@ -168,24 +167,37 @@ PP_Resource PPB_Graphics2D_Proxy::CreateProxyResource( ...@@ -168,24 +167,37 @@ PP_Resource PPB_Graphics2D_Proxy::CreateProxyResource(
bool PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) { bool PPB_Graphics2D_Proxy::OnMessageReceived(const IPC::Message& msg) {
bool handled = true; bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PPB_Graphics2D_Proxy, msg) IPC_BEGIN_MESSAGE_MAP(PPB_Graphics2D_Proxy, msg)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Create,
OnHostMsgCreate)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData, IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_PaintImageData,
OnMsgPaintImageData) OnHostMsgPaintImageData)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Scroll, IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Scroll,
OnMsgScroll) OnHostMsgScroll)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents, IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_ReplaceContents,
OnMsgReplaceContents) OnHostMsgReplaceContents)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Flush, IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics2D_Flush,
OnMsgFlush) OnHostMsgFlush)
IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics2D_FlushACK, IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics2D_FlushACK,
OnMsgFlushACK) OnPluginMsgFlushACK)
IPC_MESSAGE_UNHANDLED(handled = false) IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP() IPC_END_MESSAGE_MAP()
// FIXME(brettw) handle bad messages! // FIXME(brettw) handle bad messages!
return handled; return handled;
} }
void PPB_Graphics2D_Proxy::OnMsgPaintImageData( void PPB_Graphics2D_Proxy::OnHostMsgCreate(PP_Instance instance,
const PP_Size& size,
PP_Bool is_always_opaque,
HostResource* result) {
thunk::EnterResourceCreation enter(instance);
if (enter.succeeded()) {
result->SetHostResource(instance, enter.functions()->CreateGraphics2D(
instance, size, is_always_opaque));
}
}
void PPB_Graphics2D_Proxy::OnHostMsgPaintImageData(
const HostResource& graphics_2d, const HostResource& graphics_2d,
const HostResource& image_data, const HostResource& image_data,
const PP_Point& top_left, const PP_Point& top_left,
...@@ -198,17 +210,17 @@ void PPB_Graphics2D_Proxy::OnMsgPaintImageData( ...@@ -198,17 +210,17 @@ void PPB_Graphics2D_Proxy::OnMsgPaintImageData(
src_rect_specified ? &src_rect : NULL); src_rect_specified ? &src_rect : NULL);
} }
void PPB_Graphics2D_Proxy::OnMsgScroll(const HostResource& graphics_2d, void PPB_Graphics2D_Proxy::OnHostMsgScroll(const HostResource& graphics_2d,
bool clip_specified, bool clip_specified,
const PP_Rect& clip, const PP_Rect& clip,
const PP_Point& amount) { const PP_Point& amount) {
EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d);
if (enter.failed()) if (enter.failed())
return; return;
enter.object()->Scroll(clip_specified ? &clip : NULL, &amount); enter.object()->Scroll(clip_specified ? &clip : NULL, &amount);
} }
void PPB_Graphics2D_Proxy::OnMsgReplaceContents( void PPB_Graphics2D_Proxy::OnHostMsgReplaceContents(
const HostResource& graphics_2d, const HostResource& graphics_2d,
const HostResource& image_data) { const HostResource& image_data) {
EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d); EnterHostFromHostResource<PPB_Graphics2D_API> enter(graphics_2d);
...@@ -217,7 +229,7 @@ void PPB_Graphics2D_Proxy::OnMsgReplaceContents( ...@@ -217,7 +229,7 @@ void PPB_Graphics2D_Proxy::OnMsgReplaceContents(
enter.object()->ReplaceContents(image_data.host_resource()); enter.object()->ReplaceContents(image_data.host_resource());
} }
void PPB_Graphics2D_Proxy::OnMsgFlush(const HostResource& graphics_2d) { void PPB_Graphics2D_Proxy::OnHostMsgFlush(const HostResource& graphics_2d) {
EnterHostFromHostResourceForceCallback<PPB_Graphics2D_API> enter( EnterHostFromHostResourceForceCallback<PPB_Graphics2D_API> enter(
graphics_2d, callback_factory_, graphics_2d, callback_factory_,
&PPB_Graphics2D_Proxy::SendFlushACKToPlugin, graphics_2d); &PPB_Graphics2D_Proxy::SendFlushACKToPlugin, graphics_2d);
...@@ -226,8 +238,9 @@ void PPB_Graphics2D_Proxy::OnMsgFlush(const HostResource& graphics_2d) { ...@@ -226,8 +238,9 @@ void PPB_Graphics2D_Proxy::OnMsgFlush(const HostResource& graphics_2d) {
enter.SetResult(enter.object()->Flush(enter.callback())); enter.SetResult(enter.object()->Flush(enter.callback()));
} }
void PPB_Graphics2D_Proxy::OnMsgFlushACK(const HostResource& host_resource, void PPB_Graphics2D_Proxy::OnPluginMsgFlushACK(
int32_t pp_error) { const HostResource& host_resource,
int32_t pp_error) {
EnterPluginFromHostResource<PPB_Graphics2D_API> enter(host_resource); EnterPluginFromHostResource<PPB_Graphics2D_API> enter(host_resource);
if (enter.succeeded()) if (enter.succeeded())
static_cast<Graphics2D*>(enter.object())->FlushACK(pp_error); static_cast<Graphics2D*>(enter.object())->FlushACK(pp_error);
...@@ -236,8 +249,8 @@ void PPB_Graphics2D_Proxy::OnMsgFlushACK(const HostResource& host_resource, ...@@ -236,8 +249,8 @@ void PPB_Graphics2D_Proxy::OnMsgFlushACK(const HostResource& host_resource,
void PPB_Graphics2D_Proxy::SendFlushACKToPlugin( void PPB_Graphics2D_Proxy::SendFlushACKToPlugin(
int32_t result, int32_t result,
const HostResource& graphics_2d) { const HostResource& graphics_2d) {
dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK( dispatcher()->Send(new PpapiMsg_PPBGraphics2D_FlushACK(kApiID, graphics_2d,
API_ID_PPB_GRAPHICS_2D, graphics_2d, result)); result));
} }
} // namespace proxy } // namespace proxy
......
...@@ -39,27 +39,31 @@ class PPB_Graphics2D_Proxy : public InterfaceProxy { ...@@ -39,27 +39,31 @@ class PPB_Graphics2D_Proxy : public InterfaceProxy {
static const ApiID kApiID = API_ID_PPB_GRAPHICS_2D; static const ApiID kApiID = API_ID_PPB_GRAPHICS_2D;
private: private:
// Plugin->renderer message handlers. // Plugin->host message handlers.
void OnMsgPaintImageData(const ppapi::HostResource& graphics_2d, void OnHostMsgCreate(PP_Instance instance,
const ppapi::HostResource& image_data, const PP_Size& size,
const PP_Point& top_left, PP_Bool is_always_opaque,
bool src_rect_specified, HostResource* result);
const PP_Rect& src_rect); void OnHostMsgPaintImageData(const HostResource& graphics_2d,
void OnMsgScroll(const ppapi::HostResource& graphics_2d, const HostResource& image_data,
bool clip_specified, const PP_Point& top_left,
const PP_Rect& clip, bool src_rect_specified,
const PP_Point& amount); const PP_Rect& src_rect);
void OnMsgReplaceContents(const ppapi::HostResource& graphics_2d, void OnHostMsgScroll(const HostResource& graphics_2d,
const ppapi::HostResource& image_data); bool clip_specified,
void OnMsgFlush(const ppapi::HostResource& graphics_2d); const PP_Rect& clip,
const PP_Point& amount);
void OnHostMsgReplaceContents(const HostResource& graphics_2d,
const HostResource& image_data);
void OnHostMsgFlush(const HostResource& graphics_2d);
// Renderer->plugin message handlers. // Host->plugin message handlers.
void OnMsgFlushACK(const ppapi::HostResource& graphics_2d, void OnPluginMsgFlushACK(const HostResource& graphics_2d,
int32_t pp_error); int32_t pp_error);
// Called in the renderer to send the given flush ACK to the plugin. // Called in the renderer to send the given flush ACK to the plugin.
void SendFlushACKToPlugin(int32_t result, void SendFlushACKToPlugin(int32_t result,
const ppapi::HostResource& graphics_2d); const HostResource& graphics_2d);
pp::CompletionCallbackFactory<PPB_Graphics2D_Proxy, pp::CompletionCallbackFactory<PPB_Graphics2D_Proxy,
ProxyNonThreadSafeRefCount> callback_factory_; ProxyNonThreadSafeRefCount> callback_factory_;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/shared_impl/host_resource.h" #include "ppapi/shared_impl/host_resource.h"
#include "ppapi/shared_impl/resource.h" #include "ppapi/shared_impl/resource.h"
#include "ppapi/thunk/enter.h"
#include "ppapi/thunk/thunk.h" #include "ppapi/thunk/thunk.h"
#include "skia/ext/platform_canvas.h" #include "skia/ext/platform_canvas.h"
#include "ui/gfx/surface/transport_dib.h" #include "ui/gfx/surface/transport_dib.h"
...@@ -94,5 +95,88 @@ ImageHandle ImageData::HandleFromInt(int32_t i) { ...@@ -94,5 +95,88 @@ ImageHandle ImageData::HandleFromInt(int32_t i) {
#endif #endif
} }
PPB_ImageData_Proxy::PPB_ImageData_Proxy(Dispatcher* dispatcher)
: InterfaceProxy(dispatcher) {
}
PPB_ImageData_Proxy::~PPB_ImageData_Proxy() {
}
// static
PP_Resource PPB_ImageData_Proxy::CreateProxyResource(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,
PP_Bool init_to_zero) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
if (!dispatcher)
return 0;
HostResource result;
std::string image_data_desc;
ImageHandle image_handle = ImageData::NullHandle;
dispatcher->Send(new PpapiHostMsg_PPBImageData_Create(
kApiID, instance, format, size, init_to_zero,
&result, &image_data_desc, &image_handle));
if (result.is_null() || image_data_desc.size() != sizeof(PP_ImageDataDesc))
return 0;
// We serialize the PP_ImageDataDesc just by copying to a string.
PP_ImageDataDesc desc;
memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc));
return (new ImageData(result, desc, image_handle))->GetReference();
}
bool PPB_ImageData_Proxy::OnMessageReceived(const IPC::Message& msg) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PPB_ImageData_Proxy, msg)
IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_Create, OnHostMsgCreate)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void PPB_ImageData_Proxy::OnHostMsgCreate(PP_Instance instance,
int32_t format,
const PP_Size& size,
PP_Bool init_to_zero,
HostResource* result,
std::string* image_data_desc,
ImageHandle* result_image_handle) {
*result_image_handle = ImageData::NullHandle;
thunk::EnterResourceCreation enter(instance);
if (enter.failed())
return;
PP_Resource resource = enter.functions()->CreateImageData(
instance, static_cast<PP_ImageDataFormat>(format), size, init_to_zero);
if (!resource)
return;
result->SetHostResource(instance, resource);
// Get the description, it's just serialized as a string.
thunk::EnterResourceNoLock<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));
memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc));
}
// Get the shared memory handle.
uint32_t byte_count = 0;
int32_t handle = 0;
if (enter_resource.object()->GetSharedMemory(&handle, &byte_count) == PP_OK) {
#if defined(OS_WIN)
ImageHandle ih = ImageData::HandleFromInt(handle);
*result_image_handle = dispatcher()->ShareHandleWithRemote(ih, false);
#else
*result_image_handle = ImageData::HandleFromInt(handle);
#endif
}
}
} // namespace proxy } // namespace proxy
} // namespace ppapi } // namespace ppapi
...@@ -32,6 +32,8 @@ class HostResource; ...@@ -32,6 +32,8 @@ class HostResource;
namespace proxy { namespace proxy {
// The proxied image data resource. Unlike most resources, this needs to be
// public in the header since a number of other resources need to access it.
class ImageData : public ppapi::Resource, class ImageData : public ppapi::Resource,
public ppapi::thunk::PPB_ImageData_API, public ppapi::thunk::PPB_ImageData_API,
public ppapi::ImageDataImpl { public ppapi::ImageDataImpl {
...@@ -68,6 +70,34 @@ class ImageData : public ppapi::Resource, ...@@ -68,6 +70,34 @@ class ImageData : public ppapi::Resource,
DISALLOW_COPY_AND_ASSIGN(ImageData); DISALLOW_COPY_AND_ASSIGN(ImageData);
}; };
class PPB_ImageData_Proxy : public InterfaceProxy {
public:
PPB_ImageData_Proxy(Dispatcher* dispatcher);
virtual ~PPB_ImageData_Proxy();
static PP_Resource CreateProxyResource(PP_Instance instance,
PP_ImageDataFormat format,
const PP_Size& size,
PP_Bool init_to_zero);
// InterfaceProxy implementation.
virtual bool OnMessageReceived(const IPC::Message& msg);
static const ApiID kApiID = API_ID_PPB_IMAGE_DATA;
private:
// Message handler.
void OnHostMsgCreate(PP_Instance instance,
int32_t format,
const PP_Size& size,
PP_Bool init_to_zero,
HostResource* result,
std::string* image_data_desc,
ImageHandle* result_image_handle);
DISALLOW_COPY_AND_ASSIGN(PPB_ImageData_Proxy);
};
} // namespace proxy } // namespace proxy
} // namespace ppapi } // namespace ppapi
......
...@@ -168,25 +168,8 @@ PP_Resource ResourceCreationProxy::CreateImageData(PP_Instance instance, ...@@ -168,25 +168,8 @@ PP_Resource ResourceCreationProxy::CreateImageData(PP_Instance instance,
PP_ImageDataFormat format, PP_ImageDataFormat format,
const PP_Size& size, const PP_Size& size,
PP_Bool init_to_zero) { PP_Bool init_to_zero) {
PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); return PPB_ImageData_Proxy::CreateProxyResource(instance, format, size,
if (!dispatcher) init_to_zero);
return 0;
HostResource result;
std::string image_data_desc;
ImageHandle image_handle = ImageData::NullHandle;
dispatcher->Send(new PpapiHostMsg_ResourceCreation_ImageData(
API_ID_RESOURCE_CREATION, instance, format, size, init_to_zero,
&result, &image_data_desc, &image_handle));
if (result.is_null() || image_data_desc.size() != sizeof(PP_ImageDataDesc))
return 0;
// We serialize the PP_ImageDataDesc just by copying to a string.
PP_ImageDataDesc desc;
memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc));
return (new ImageData(result, desc, image_handle))->GetReference();
} }
PP_Resource ResourceCreationProxy::CreateKeyboardInputEvent( PP_Resource ResourceCreationProxy::CreateKeyboardInputEvent(
...@@ -345,73 +328,7 @@ bool ResourceCreationProxy::Send(IPC::Message* msg) { ...@@ -345,73 +328,7 @@ bool ResourceCreationProxy::Send(IPC::Message* msg) {
} }
bool ResourceCreationProxy::OnMessageReceived(const IPC::Message& msg) { bool ResourceCreationProxy::OnMessageReceived(const IPC::Message& msg) {
bool handled = true; return false;
IPC_BEGIN_MESSAGE_MAP(ResourceCreationProxy, msg)
IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCreation_Graphics2D,
OnMsgCreateGraphics2D)
IPC_MESSAGE_HANDLER(PpapiHostMsg_ResourceCreation_ImageData,
OnMsgCreateImageData)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void ResourceCreationProxy::OnMsgCreateGraphics2D(PP_Instance instance,
const PP_Size& size,
PP_Bool is_always_opaque,
HostResource* result) {
ppapi::thunk::EnterFunction<ResourceCreationAPI> enter(instance, false);
if (enter.succeeded()) {
result->SetHostResource(instance, enter.functions()->CreateGraphics2D(
instance, size, is_always_opaque));
}
}
void ResourceCreationProxy::OnMsgCreateImageData(
PP_Instance instance,
int32_t format,
const PP_Size& size,
PP_Bool init_to_zero,
HostResource* result,
std::string* image_data_desc,
ImageHandle* result_image_handle) {
*result_image_handle = ImageData::NullHandle;
ppapi::thunk::EnterFunction<ResourceCreationAPI> enter(instance, false);
if (enter.failed())
return;
PP_Resource resource = enter.functions()->CreateImageData(
instance, static_cast<PP_ImageDataFormat>(format), size, init_to_zero);
if (!resource)
return;
result->SetHostResource(instance, resource);
// Get the description, it's just serialized as a string.
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));
memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc));
}
// Get the shared memory handle.
const PPB_ImageDataTrusted* trusted =
reinterpret_cast<const PPB_ImageDataTrusted*>(
dispatcher()->local_get_interface()(PPB_IMAGEDATA_TRUSTED_INTERFACE));
uint32_t byte_count = 0;
if (trusted) {
int32_t handle;
if (trusted->GetSharedMemory(resource, &handle, &byte_count) == PP_OK) {
#if defined(OS_WIN)
ImageHandle ih = ImageData::HandleFromInt(handle);
*result_image_handle = dispatcher()->ShareHandleWithRemote(ih, false);
#else
*result_image_handle = ImageData::HandleFromInt(handle);
#endif
}
}
} }
} // namespace proxy } // namespace proxy
......
...@@ -131,25 +131,6 @@ class ResourceCreationProxy : public InterfaceProxy, ...@@ -131,25 +131,6 @@ class ResourceCreationProxy : public InterfaceProxy,
virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
private: private:
// IPC message handlers (called in browser).
void OnMsgCreateAudio(PP_Instance instance,
int32_t sample_rate,
uint32_t sample_frame_count,
HostResource* result);
void OnMsgCreateAudioInput(PP_Instance instance,
HostResource* result);
void OnMsgCreateGraphics2D(PP_Instance instance,
const PP_Size& size,
PP_Bool is_always_opaque,
HostResource* result);
void OnMsgCreateImageData(PP_Instance instance,
int32_t format,
const PP_Size& size,
PP_Bool init_to_zero,
HostResource* result,
std::string* image_data_desc,
ImageHandle* result_image_handle);
DISALLOW_COPY_AND_ASSIGN(ResourceCreationProxy); DISALLOW_COPY_AND_ASSIGN(ResourceCreationProxy);
}; };
......
...@@ -32,6 +32,7 @@ enum ApiID { ...@@ -32,6 +32,7 @@ enum ApiID {
API_ID_PPB_FONT, API_ID_PPB_FONT,
API_ID_PPB_GRAPHICS_2D, API_ID_PPB_GRAPHICS_2D,
API_ID_PPB_GRAPHICS_3D, API_ID_PPB_GRAPHICS_3D,
API_ID_PPB_IMAGE_DATA,
API_ID_PPB_INSTANCE, API_ID_PPB_INSTANCE,
API_ID_PPB_INSTANCE_PRIVATE, API_ID_PPB_INSTANCE_PRIVATE,
API_ID_PPB_OPENGLES2, API_ID_PPB_OPENGLES2,
......
...@@ -26,7 +26,7 @@ UNPROXIED_API(PPB_FileIO) ...@@ -26,7 +26,7 @@ UNPROXIED_API(PPB_FileIO)
PROXIED_API(PPB_FileRef) PROXIED_API(PPB_FileRef)
PROXIED_API(PPB_FileSystem) PROXIED_API(PPB_FileSystem)
PROXIED_API(PPB_Graphics2D) PROXIED_API(PPB_Graphics2D)
UNPROXIED_API(PPB_ImageData) PROXIED_API(PPB_ImageData)
PROXIED_API(PPB_Instance) PROXIED_API(PPB_Instance)
PROXIED_API(PPB_URLLoader) PROXIED_API(PPB_URLLoader)
PROXIED_API(PPB_URLResponseInfo) PROXIED_API(PPB_URLResponseInfo)
...@@ -55,9 +55,7 @@ PROXIED_IFACE(PPB_FileRef, PPB_FILEREF_INTERFACE_1_0, PPB_FileRef) ...@@ -55,9 +55,7 @@ PROXIED_IFACE(PPB_FileRef, PPB_FILEREF_INTERFACE_1_0, PPB_FileRef)
PROXIED_IFACE(PPB_FileSystem, PPB_FILESYSTEM_INTERFACE_1_0, PPB_FileSystem) PROXIED_IFACE(PPB_FileSystem, PPB_FILESYSTEM_INTERFACE_1_0, PPB_FileSystem)
PROXIED_IFACE(PPB_Graphics2D, PPB_GRAPHICS_2D_INTERFACE_1_0, PPB_Graphics2D) PROXIED_IFACE(PPB_Graphics2D, PPB_GRAPHICS_2D_INTERFACE_1_0, PPB_Graphics2D)
PROXIED_IFACE(PPB_Graphics3D, PPB_GRAPHICS_3D_INTERFACE_1_0, PPB_Graphics3D) PROXIED_IFACE(PPB_Graphics3D, PPB_GRAPHICS_3D_INTERFACE_1_0, PPB_Graphics3D)
// ImageData doesn't have a normal _Proxy object since it only uses Create PROXIED_IFACE(PPB_ImageData, PPB_IMAGEDATA_INTERFACE_1_0, PPB_ImageData)
// to proxy, and that happens in the ResourceCreationAPI.
PROXIED_IFACE(NoAPIName, PPB_IMAGEDATA_INTERFACE_1_0, PPB_ImageData)
PROXIED_IFACE(PPB_Instance, PPB_INSTANCE_INTERFACE_1_0, PPB_Instance) PROXIED_IFACE(PPB_Instance, PPB_INSTANCE_INTERFACE_1_0, PPB_Instance)
PROXIED_IFACE(NoAPIName, PPB_INPUT_EVENT_INTERFACE_1_0, PPB_InputEvent) PROXIED_IFACE(NoAPIName, PPB_INPUT_EVENT_INTERFACE_1_0, PPB_InputEvent)
PROXIED_IFACE(NoAPIName, PPB_KEYBOARD_INPUT_EVENT_INTERFACE_1_0, PROXIED_IFACE(NoAPIName, PPB_KEYBOARD_INPUT_EVENT_INTERFACE_1_0,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment