| Index: ppapi/proxy/ppb_surface_3d_proxy.cc
|
| ===================================================================
|
| --- ppapi/proxy/ppb_surface_3d_proxy.cc (revision 89672)
|
| +++ ppapi/proxy/ppb_surface_3d_proxy.cc (working copy)
|
| @@ -8,117 +8,87 @@
|
| #include "ppapi/c/pp_errors.h"
|
| #include "ppapi/c/pp_resource.h"
|
| #include "ppapi/c/dev/ppb_surface_3d_dev.h"
|
| +#include "ppapi/proxy/enter_proxy.h"
|
| #include "ppapi/proxy/plugin_dispatcher.h"
|
| #include "ppapi/proxy/plugin_resource.h"
|
| #include "ppapi/proxy/ppapi_messages.h"
|
| #include "ppapi/proxy/ppb_context_3d_proxy.h"
|
| +#include "ppapi/thunk/enter.h"
|
| +#include "ppapi/thunk/resource_creation_api.h"
|
| +#include "ppapi/thunk/thunk.h"
|
|
|
| +using ppapi::thunk::EnterFunctionNoLock;
|
| +using ppapi::thunk::PPB_Surface3D_API;
|
| +using ppapi::thunk::ResourceCreationAPI;
|
| +
|
| namespace pp {
|
| namespace proxy {
|
|
|
| -Surface3D::~Surface3D() {
|
| - if (context_)
|
| - context_->BindSurfaces(NULL, NULL);
|
| -}
|
| -
|
| namespace {
|
|
|
| -PP_Resource Create(PP_Instance instance,
|
| - PP_Config3D_Dev config,
|
| - const int32_t* attrib_list) {
|
| - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
|
| - if (!dispatcher)
|
| - return PP_ERROR_BADARGUMENT;
|
| +InterfaceProxy* CreateSurface3DProxy(Dispatcher* dispatcher,
|
| + const void* target_interface) {
|
| + return new PPB_Surface3D_Proxy(dispatcher, target_interface);
|
| +}
|
|
|
| - std::vector<int32_t> attribs;
|
| - if (attrib_list) {
|
| - const int32_t* attr = attrib_list;
|
| - while(*attr != PP_GRAPHICS3DATTRIB_NONE) {
|
| - attribs.push_back(*(attr++)); // Attribute.
|
| - attribs.push_back(*(attr++)); // Value.
|
| - }
|
| - }
|
| - attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); // Always terminate.
|
| +} // namespace
|
|
|
| - HostResource result;
|
| - dispatcher->Send(new PpapiHostMsg_PPBSurface3D_Create(
|
| - INTERFACE_ID_PPB_SURFACE_3D, instance, config, attribs, &result));
|
| +// Surface3D -------------------------------------------------------------------
|
|
|
| - if (result.is_null())
|
| - return 0;
|
| - linked_ptr<Surface3D> surface_3d(new Surface3D(result));
|
| - PP_Resource resource =
|
| - PluginResourceTracker::GetInstance()->AddResource(surface_3d);
|
| - surface_3d->set_resource(resource);
|
| - return resource;
|
| +Surface3D::Surface3D(const HostResource& host_resource)
|
| + : PluginResource(host_resource),
|
| + resource_(0),
|
| + context_(NULL),
|
| + current_flush_callback_(PP_BlockUntilComplete()) {
|
| }
|
|
|
| -PP_Bool IsSurface3D(PP_Resource resource) {
|
| - Surface3D* object = PluginResource::GetAs<Surface3D>(resource);
|
| - return BoolToPPBool(!!object);
|
| +Surface3D::~Surface3D() {
|
| + if (context_)
|
| + context_->BindSurfaces(NULL, NULL);
|
| }
|
|
|
| -int32_t SetAttrib(PP_Resource surface_id,
|
| - int32_t attribute,
|
| - int32_t value) {
|
| +PPB_Surface3D_API* Surface3D::AsPPB_Surface3D_API() {
|
| + return this;
|
| +}
|
| +
|
| +int32_t Surface3D::SetAttrib(int32_t attribute, int32_t value) {
|
| // TODO(alokp): Implement me.
|
| return 0;
|
| }
|
|
|
| -int32_t GetAttrib(PP_Resource surface_id,
|
| - int32_t attribute,
|
| - int32_t* value) {
|
| +int32_t Surface3D::GetAttrib(int32_t attribute, int32_t* value) {
|
| // TODO(alokp): Implement me.
|
| return 0;
|
| }
|
|
|
| -int32_t SwapBuffers(PP_Resource surface_id,
|
| - PP_CompletionCallback callback) {
|
| - Surface3D* object = PluginResource::GetAs<Surface3D>(surface_id);
|
| - if (!object)
|
| - return PP_ERROR_BADRESOURCE;
|
| - PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
|
| - object->instance());
|
| - if (!dispatcher)
|
| - return PP_ERROR_FAILED;
|
| -
|
| +int32_t Surface3D::SwapBuffers(PP_CompletionCallback callback) {
|
| // For now, disallow blocking calls. We'll need to add support for other
|
| // threads to this later.
|
| if (!callback.func)
|
| return PP_ERROR_BADARGUMENT;
|
|
|
| - if (object->is_flush_pending())
|
| + if (is_flush_pending())
|
| return PP_ERROR_INPROGRESS; // Can't have >1 flush pending.
|
|
|
| - if (!object->context())
|
| + if (!context_)
|
| return PP_ERROR_FAILED;
|
|
|
| - object->set_current_flush_callback(callback);
|
| + current_flush_callback_ = callback;
|
|
|
| IPC::Message* msg = new PpapiHostMsg_PPBSurface3D_SwapBuffers(
|
| - INTERFACE_ID_PPB_SURFACE_3D, object->host_resource());
|
| + INTERFACE_ID_PPB_SURFACE_3D, host_resource());
|
| msg->set_unblock(true);
|
| - dispatcher->Send(msg);
|
| + GetDispatcher()->Send(msg);
|
|
|
| - object->context()->gles2_impl()->SwapBuffers();
|
| -
|
| + context_->gles2_impl()->SwapBuffers();
|
| return PP_OK_COMPLETIONPENDING;
|
| }
|
|
|
| -const PPB_Surface3D_Dev surface_3d_interface = {
|
| - &Create,
|
| - &IsSurface3D,
|
| - &SetAttrib,
|
| - &GetAttrib,
|
| - &SwapBuffers
|
| -};
|
| -
|
| -InterfaceProxy* CreateSurface3DProxy(Dispatcher* dispatcher,
|
| - const void* target_interface) {
|
| - return new PPB_Surface3D_Proxy(dispatcher, target_interface);
|
| +void Surface3D::SwapBuffersACK(int32_t pp_error) {
|
| + PP_RunAndClearCompletionCallback(¤t_flush_callback_, pp_error);
|
| }
|
|
|
| -} // namespace
|
| +// PPB_Surface3D_Proxy ---------------------------------------------------------
|
|
|
| PPB_Surface3D_Proxy::PPB_Surface3D_Proxy(Dispatcher* dispatcher,
|
| const void* target_interface)
|
| @@ -132,7 +102,7 @@
|
| // static
|
| const InterfaceProxy::Info* PPB_Surface3D_Proxy::GetInfo() {
|
| static const Info info = {
|
| - &surface_3d_interface,
|
| + ::ppapi::thunk::GetPPB_Surface3D_Thunk(),
|
| PPB_SURFACE_3D_DEV_INTERFACE,
|
| INTERFACE_ID_PPB_SURFACE_3D,
|
| false,
|
| @@ -141,6 +111,38 @@
|
| return &info;
|
| }
|
|
|
| +// static
|
| +PP_Resource PPB_Surface3D_Proxy::CreateProxyResource(
|
| + PP_Instance instance,
|
| + PP_Config3D_Dev config,
|
| + const int32_t* attrib_list) {
|
| + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
|
| + if (!dispatcher)
|
| + return PP_ERROR_BADARGUMENT;
|
| +
|
| + std::vector<int32_t> attribs;
|
| + if (attrib_list) {
|
| + const int32_t* attr = attrib_list;
|
| + while(*attr != PP_GRAPHICS3DATTRIB_NONE) {
|
| + attribs.push_back(*(attr++)); // Attribute.
|
| + attribs.push_back(*(attr++)); // Value.
|
| + }
|
| + }
|
| + attribs.push_back(PP_GRAPHICS3DATTRIB_NONE); // Always terminate.
|
| +
|
| + HostResource result;
|
| + dispatcher->Send(new PpapiHostMsg_PPBSurface3D_Create(
|
| + INTERFACE_ID_PPB_SURFACE_3D, instance, config, attribs, &result));
|
| +
|
| + if (result.is_null())
|
| + return 0;
|
| + linked_ptr<Surface3D> surface_3d(new Surface3D(result));
|
| + PP_Resource resource =
|
| + PluginResourceTracker::GetInstance()->AddResource(surface_3d);
|
| + surface_3d->set_resource(resource);
|
| + return resource;
|
| +}
|
| +
|
| bool PPB_Surface3D_Proxy::OnMessageReceived(const IPC::Message& msg) {
|
| bool handled = true;
|
| IPC_BEGIN_MESSAGE_MAP(PPB_Surface3D_Proxy, msg)
|
| @@ -161,18 +163,27 @@
|
| PP_Config3D_Dev config,
|
| std::vector<int32_t> attribs,
|
| HostResource* result) {
|
| - DCHECK(attribs.size() % 2 == 1);
|
| - DCHECK(attribs.back() == PP_GRAPHICS3DATTRIB_NONE);
|
| - PP_Resource resource =
|
| - ppb_surface_3d_target()->Create(instance, config, &attribs.front());
|
| - result->SetHostResource(instance, resource);
|
| + if (attribs.empty() ||
|
| + attribs.size() % 2 != 1 ||
|
| + attribs.back() != PP_GRAPHICS3DATTRIB_NONE)
|
| + return; // Bad message.
|
| +
|
| + EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true);
|
| + if (enter.succeeded()) {
|
| + result->SetHostResource(
|
| + instance,
|
| + enter.functions()->CreateSurface3D(instance, config, &attribs.front()));
|
| + }
|
| }
|
|
|
| void PPB_Surface3D_Proxy::OnMsgSwapBuffers(const HostResource& surface_3d) {
|
| CompletionCallback callback = callback_factory_.NewCallback(
|
| &PPB_Surface3D_Proxy::SendSwapBuffersACKToPlugin, surface_3d);
|
| - int32_t result = ppb_surface_3d_target()->SwapBuffers(
|
| - surface_3d.host_resource(), callback.pp_completion_callback());
|
| +
|
| + EnterHostFromHostResource<PPB_Surface3D_API> enter(surface_3d);
|
| + int32_t result = PP_ERROR_BADRESOURCE;
|
| + if (enter.succeeded())
|
| + result = enter.object()->SwapBuffers(callback.pp_completion_callback());
|
| if (result != PP_OK_COMPLETIONPENDING) {
|
| // There was some error, so we won't get a flush callback. We need to now
|
| // issue the ACK to the plugin hears about the error. This will also clean
|
| @@ -183,23 +194,9 @@
|
|
|
| void PPB_Surface3D_Proxy::OnMsgSwapBuffersACK(const HostResource& resource,
|
| int32_t pp_error) {
|
| - PP_Resource plugin_resource =
|
| - PluginResourceTracker::GetInstance()->PluginResourceForHostResource(
|
| - resource);
|
| - if (!plugin_resource)
|
| - return;
|
| - Surface3D* object = PluginResource::GetAs<Surface3D>(plugin_resource);
|
| - if (!object) {
|
| - // The plugin has released the Surface3D object so don't issue the
|
| - // callback.
|
| - return;
|
| - }
|
| -
|
| - // Be careful to make the callback NULL again before issuing the callback
|
| - // since the plugin might want to flush from within the callback.
|
| - PP_CompletionCallback callback = object->current_flush_callback();
|
| - object->set_current_flush_callback(PP_BlockUntilComplete());
|
| - PP_RunCompletionCallback(&callback, pp_error);
|
| + EnterPluginFromHostResource<PPB_Surface3D_API> enter(resource);
|
| + if (enter.succeeded())
|
| + static_cast<Surface3D*>(enter.object())->SwapBuffersACK(pp_error);
|
| }
|
|
|
| void PPB_Surface3D_Proxy::SendSwapBuffersACKToPlugin(
|
|
|