diff options
author | piman@google.com <piman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-02 18:12:31 +0000 |
---|---|---|
committer | piman@google.com <piman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-02 18:12:31 +0000 |
commit | f56279ca6fb81d883f77c6501c2f54dd95d4933d (patch) | |
tree | 8a69dcd6fb2c1ae6abe2985a00320f74ab2b8ab5 /ppapi/proxy | |
parent | ed355815b599eecfeda838ef8e7fa7adcbb5a9a9 (diff) | |
download | chromium_src-f56279ca6fb81d883f77c6501c2f54dd95d4933d.zip chromium_src-f56279ca6fb81d883f77c6501c2f54dd95d4933d.tar.gz chromium_src-f56279ca6fb81d883f77c6501c2f54dd95d4933d.tar.bz2 |
Implement proxy for 3d-related interfaces
BUG=none
TEST=Pepper Flash
Review URL: http://codereview.chromium.org/6400007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73472 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/proxy')
-rw-r--r-- | ppapi/proxy/DEPS | 1 | ||||
-rw-r--r-- | ppapi/proxy/dispatcher.cc | 22 | ||||
-rw-r--r-- | ppapi/proxy/interface_id.h | 3 | ||||
-rw-r--r-- | ppapi/proxy/interface_proxy.h | 2 | ||||
-rw-r--r-- | ppapi/proxy/plugin_dispatcher.cc | 15 | ||||
-rw-r--r-- | ppapi/proxy/plugin_dispatcher.h | 19 | ||||
-rw-r--r-- | ppapi/proxy/plugin_resource.h | 2 | ||||
-rw-r--r-- | ppapi/proxy/ppapi_messages_internal.h | 66 | ||||
-rw-r--r-- | ppapi/proxy/ppb_context_3d_proxy.cc | 584 | ||||
-rw-r--r-- | ppapi/proxy/ppb_context_3d_proxy.h | 120 | ||||
-rw-r--r-- | ppapi/proxy/ppb_gles_chromium_texture_mapping_proxy.cc | 70 | ||||
-rw-r--r-- | ppapi/proxy/ppb_gles_chromium_texture_mapping_proxy.h | 36 | ||||
-rw-r--r-- | ppapi/proxy/ppb_opengles2_proxy.cc | 1037 | ||||
-rw-r--r-- | ppapi/proxy/ppb_opengles2_proxy.h | 35 | ||||
-rw-r--r-- | ppapi/proxy/ppb_surface_3d_proxy.cc | 196 | ||||
-rw-r--r-- | ppapi/proxy/ppb_surface_3d_proxy.h | 100 | ||||
-rw-r--r-- | ppapi/proxy/ppp_instance_proxy.cc | 18 |
17 files changed, 2321 insertions, 5 deletions
diff --git a/ppapi/proxy/DEPS b/ppapi/proxy/DEPS index af862c1..5c5b2d4 100644 --- a/ppapi/proxy/DEPS +++ b/ppapi/proxy/DEPS @@ -1,6 +1,7 @@ include_rules = [ "+base", "+ipc", + "+gpu", # We don't want the proxy to depend on the C++ layer, which is appropriate # for plugins only. However, the completion callback factory is a very useful diff --git a/ppapi/proxy/dispatcher.cc b/ppapi/proxy/dispatcher.cc index f852c49..9ad6aca 100644 --- a/ppapi/proxy/dispatcher.cc +++ b/ppapi/proxy/dispatcher.cc @@ -15,11 +15,13 @@ #include "ipc/ipc_test_sink.h" #include "ppapi/c/dev/ppb_buffer_dev.h" #include "ppapi/c/dev/ppb_char_set_dev.h" +#include "ppapi/c/dev/ppb_context_3d_dev.h" #include "ppapi/c/dev/ppb_cursor_control_dev.h" -#include "ppapi/c/dev/ppb_cursor_control_dev.h" +#include "ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h" #include "ppapi/c/dev/ppb_font_dev.h" #include "ppapi/c/dev/ppb_fullscreen_dev.h" -#include "ppapi/c/dev/ppb_fullscreen_dev.h" +#include "ppapi/c/dev/ppb_opengles_dev.h" +#include "ppapi/c/dev/ppb_surface_3d_dev.h" #include "ppapi/c/dev/ppb_testing_dev.h" #include "ppapi/c/dev/ppb_var_deprecated.h" #include "ppapi/c/pp_errors.h" @@ -41,15 +43,19 @@ #include "ppapi/proxy/ppb_audio_proxy.h" #include "ppapi/proxy/ppb_buffer_proxy.h" #include "ppapi/proxy/ppb_char_set_proxy.h" +#include "ppapi/proxy/ppb_context_3d_proxy.h" #include "ppapi/proxy/ppb_core_proxy.h" #include "ppapi/proxy/ppb_cursor_control_proxy.h" #include "ppapi/proxy/ppb_flash_proxy.h" #include "ppapi/proxy/ppb_font_proxy.h" #include "ppapi/proxy/ppb_fullscreen_proxy.h" +#include "ppapi/proxy/ppb_gles_chromium_texture_mapping_proxy.h" #include "ppapi/proxy/ppb_graphics_2d_proxy.h" #include "ppapi/proxy/ppb_image_data_proxy.h" #include "ppapi/proxy/ppb_instance_proxy.h" +#include "ppapi/proxy/ppb_opengles2_proxy.h" #include "ppapi/proxy/ppb_pdf_proxy.h" +#include "ppapi/proxy/ppb_surface_3d_proxy.h" #include "ppapi/proxy/ppb_testing_proxy.h" #include "ppapi/proxy/ppb_url_loader_proxy.h" #include "ppapi/proxy/ppb_url_request_info_proxy.h" @@ -159,7 +165,9 @@ const void* Dispatcher::GetProxiedInterface(const std::string& interface) { // Save our proxy. proxies_[interface] = proxy; - id_to_proxy_[proxy->GetInterfaceId()] = proxy.get(); + InterfaceID id = proxy->GetInterfaceId(); + if (id != INTERFACE_ID_NONE) + id_to_proxy_[id] = proxy.get(); return proxy->GetSourceInterface(); } @@ -246,6 +254,8 @@ InterfaceProxy* Dispatcher::CreateProxyForInterface( return new PPB_Buffer_Proxy(this, interface_functions); if (interface_name == PPB_CHAR_SET_DEV_INTERFACE) return new PPB_CharSet_Proxy(this, interface_functions); + if (interface_name == PPB_CONTEXT_3D_DEV_INTERFACE) + return new PPB_Context3D_Proxy(this, interface_functions); if (interface_name == PPB_CORE_INTERFACE) return new PPB_Core_Proxy(this, interface_functions); if (interface_name == PPB_CURSOR_CONTROL_DEV_INTERFACE) @@ -254,12 +264,18 @@ InterfaceProxy* Dispatcher::CreateProxyForInterface( return new PPB_Font_Proxy(this, interface_functions); if (interface_name == PPB_FULLSCREEN_DEV_INTERFACE) return new PPB_Fullscreen_Proxy(this, interface_functions); + if (interface_name == PPB_GLES_CHROMIUM_TEXTURE_MAPPING_DEV_INTERFACE) + return new PPB_GLESChromiumTextureMapping_Proxy(this, interface_functions); if (interface_name == PPB_GRAPHICS_2D_INTERFACE) return new PPB_Graphics2D_Proxy(this, interface_functions); if (interface_name == PPB_IMAGEDATA_INTERFACE) return new PPB_ImageData_Proxy(this, interface_functions); if (interface_name == PPB_INSTANCE_INTERFACE) return new PPB_Instance_Proxy(this, interface_functions); + if (interface_name == PPB_OPENGLES2_DEV_INTERFACE) + return new PPB_OpenGLES2_Proxy(this, interface_functions); + if (interface_name == PPB_SURFACE_3D_DEV_INTERFACE) + return new PPB_Surface3D_Proxy(this, interface_functions); if (interface_name == PPB_TESTING_DEV_INTERFACE) return new PPB_Testing_Proxy(this, interface_functions); if (interface_name == PPB_URLLOADER_INTERFACE) diff --git a/ppapi/proxy/interface_id.h b/ppapi/proxy/interface_id.h index aca2016..f2ea1bf 100644 --- a/ppapi/proxy/interface_id.h +++ b/ppapi/proxy/interface_id.h @@ -12,10 +12,12 @@ namespace proxy { // to route messages to the appropriate message handler. enum InterfaceID { // Zero is reserved for control messages. + INTERFACE_ID_NONE = 0, INTERFACE_ID_PPB_AUDIO = 1, INTERFACE_ID_PPB_AUDIO_CONFIG, INTERFACE_ID_PPB_BUFFER, INTERFACE_ID_PPB_CHAR_SET, + INTERFACE_ID_PPB_CONTEXT_3D, INTERFACE_ID_PPB_CORE, INTERFACE_ID_PPB_CURSORCONTROL, INTERFACE_ID_PPB_FLASH, @@ -25,6 +27,7 @@ enum InterfaceID { INTERFACE_ID_PPB_IMAGE_DATA, INTERFACE_ID_PPB_INSTANCE, INTERFACE_ID_PPB_PDF, + INTERFACE_ID_PPB_SURFACE_3D, INTERFACE_ID_PPB_TESTING, INTERFACE_ID_PPB_URL_LOADER, INTERFACE_ID_PPB_URL_LOADER_TRUSTED, diff --git a/ppapi/proxy/interface_proxy.h b/ppapi/proxy/interface_proxy.h index 672e268..9c7bba9 100644 --- a/ppapi/proxy/interface_proxy.h +++ b/ppapi/proxy/interface_proxy.h @@ -45,7 +45,7 @@ class InterfaceProxy : public IPC::Channel::Listener, // This will be NULL when this proxy is a source proxy. const void* target_interface() const { return target_interface_; } - Dispatcher* dispatcher() { return dispatcher_; } + Dispatcher* dispatcher() const { return dispatcher_; } // IPC::Message::Sender implementation. virtual bool Send(IPC::Message* msg); diff --git a/ppapi/proxy/plugin_dispatcher.cc b/ppapi/proxy/plugin_dispatcher.cc index 8de9cea..48c7ad2 100644 --- a/ppapi/proxy/plugin_dispatcher.cc +++ b/ppapi/proxy/plugin_dispatcher.cc @@ -90,6 +90,21 @@ bool PluginDispatcher::OnMessageReceived(const IPC::Message& msg) { return Dispatcher::OnMessageReceived(msg); } +void PluginDispatcher::DidCreateInstance(PP_Instance instance) { + instance_map_[instance] = InstanceData(); +} + +void PluginDispatcher::DidDestroyInstance(PP_Instance instance) { + InstanceDataMap::iterator it = instance_map_.find(instance); + if (it != instance_map_.end()) + instance_map_.erase(it); +} + +InstanceData* PluginDispatcher::GetInstanceData(PP_Instance instance) { + InstanceDataMap::iterator it = instance_map_.find(instance); + return (it == instance_map_.end()) ? NULL : &it->second; +} + void PluginDispatcher::OnMsgInitializeModule(PP_Module pp_module, bool* result) { set_pp_module(pp_module); diff --git a/ppapi/proxy/plugin_dispatcher.h b/ppapi/proxy/plugin_dispatcher.h index 6ce5c14..d2ab30a 100644 --- a/ppapi/proxy/plugin_dispatcher.h +++ b/ppapi/proxy/plugin_dispatcher.h @@ -7,8 +7,10 @@ #include <string> +#include "base/hash_tables.h" #include "base/process.h" #include "base/scoped_ptr.h" +#include "ppapi/c/pp_rect.h" #include "ppapi/c/pp_instance.h" #include "ppapi/proxy/dispatcher.h" @@ -21,6 +23,11 @@ class WaitableEvent; namespace pp { namespace proxy { +// Used to keep track of per-instance data. +struct InstanceData { + PP_Rect position; +}; + class PluginDispatcher : public Dispatcher { public: // Constructor for the plugin side. The init and shutdown functions will be @@ -58,6 +65,15 @@ class PluginDispatcher : public Dispatcher { // IPC::Channel::Listener implementation. virtual bool OnMessageReceived(const IPC::Message& msg); + // Keep track of all active instances to associate data with it, like the + // current size. + void DidCreateInstance(PP_Instance instance); + void DidDestroyInstance(PP_Instance instance); + + // Gets the data for an existing instance, or NULL if the instance id doesn't + // correspond to a known instance. + InstanceData* GetInstanceData(PP_Instance instance); + private: // IPC message handlers. void OnMsgInitializeModule(PP_Module pp_module, bool* result); @@ -66,6 +82,9 @@ class PluginDispatcher : public Dispatcher { InitModuleFunc init_module_; ShutdownModuleFunc shutdown_module_; + typedef base::hash_map<PP_Instance, InstanceData> InstanceDataMap; + InstanceDataMap instance_map_; + DISALLOW_COPY_AND_ASSIGN(PluginDispatcher); }; diff --git a/ppapi/proxy/plugin_resource.h b/ppapi/proxy/plugin_resource.h index 9fda1b5..1113f6a 100644 --- a/ppapi/proxy/plugin_resource.h +++ b/ppapi/proxy/plugin_resource.h @@ -16,11 +16,13 @@ F(Audio) \ F(AudioConfig) \ F(Buffer) \ + F(Context3D) \ F(Font) \ F(Graphics2D) \ F(ImageData) \ F(MockResource) \ F(PrivateFontFile) \ + F(Surface3D) \ F(URLLoader) \ F(URLRequestInfo)\ F(URLResponseInfo) diff --git a/ppapi/proxy/ppapi_messages_internal.h b/ppapi/proxy/ppapi_messages_internal.h index 07cf77b..2bc4da4 100644 --- a/ppapi/proxy/ppapi_messages_internal.h +++ b/ppapi/proxy/ppapi_messages_internal.h @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "gpu/command_buffer/common/command_buffer.h" +#include "gpu/ipc/gpu_command_buffer_traits.h" #include "ipc/ipc_message_macros.h" #include "ppapi/c/dev/pp_file_info_dev.h" #include "ppapi/c/ppb_var.h" @@ -57,6 +59,11 @@ IPC_MESSAGE_ROUTED2(PpapiMsg_PPBGraphics2D_FlushACK, pp::proxy::HostResource /* graphics_2d */, int32_t /* pp_error */) +// PPB_Surface3D. +IPC_MESSAGE_ROUTED2(PpapiMsg_PPBSurface3D_SwapBuffersACK, + pp::proxy::HostResource /* surface_3d */, + int32_t /* pp_error */) + // PPP_Class. IPC_SYNC_MESSAGE_ROUTED3_2(PpapiMsg_PPPClass_HasProperty, int64 /* ppp_class */, @@ -117,7 +124,9 @@ IPC_SYNC_MESSAGE_ROUTED3_1(PpapiMsg_PPPInstance_DidCreate, PP_Bool /* result */) IPC_MESSAGE_ROUTED1(PpapiMsg_PPPInstance_DidDestroy, PP_Instance /* instance */) -IPC_MESSAGE_ROUTED3(PpapiMsg_PPPInstance_DidChangeView, +// TODO(piman): DidChangeView should be async, but doing so causes an issue with +// webkit and accelerated compositing. Turn back to async once this is fixed. +IPC_SYNC_MESSAGE_ROUTED3_0(PpapiMsg_PPPInstance_DidChangeView, PP_Instance /* instance */, PP_Rect /* position */, PP_Rect /* clip */) @@ -180,6 +189,52 @@ IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBBuffer_Create, pp::proxy::HostResource /* result_resource */, int32_t /* result_shm_handle */) +// PPB_Context3D. +IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBContext3D_Create, + PP_Instance /* instance */, + int32_t /* config */, + std::vector<int32_t> /* attrib_list */, + pp::proxy::HostResource /* result */) + +IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBContext3D_BindSurfaces, + pp::proxy::HostResource /* context */, + pp::proxy::HostResource /* draw */, + pp::proxy::HostResource /* read */, + int32_t /* result */) + +IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBContext3D_Initialize, + pp::proxy::HostResource /* context */, + int32 /* size */, + base::SharedMemoryHandle /* ring_buffer */) + +IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBContext3D_GetState, + pp::proxy::HostResource /* context */, + gpu::CommandBuffer::State /* state */) + +IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBContext3D_Flush, + pp::proxy::HostResource /* context */, + int32 /* put_offset */, + gpu::CommandBuffer::State /* state */) + +IPC_MESSAGE_ROUTED2(PpapiHostMsg_PPBContext3D_AsyncFlush, + pp::proxy::HostResource /* context */, + int32 /* put_offset */) + +IPC_SYNC_MESSAGE_ROUTED2_1(PpapiHostMsg_PPBContext3D_CreateTransferBuffer, + pp::proxy::HostResource /* context */, + int32 /* size */, + int32 /* id */) + +IPC_SYNC_MESSAGE_ROUTED2_0(PpapiHostMsg_PPBContext3D_DestroyTransferBuffer, + pp::proxy::HostResource /* context */, + int32 /* id */) + +IPC_SYNC_MESSAGE_ROUTED2_2(PpapiHostMsg_PPBContext3D_GetTransferBuffer, + pp::proxy::HostResource /* context */, + int32 /* id */, + base::SharedMemoryHandle /* transfer_buffer */, + uint32 /* size */) + // PPB_Core. IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBCore_AddRefResource, pp::proxy::HostResource) @@ -382,6 +437,15 @@ IPC_SYNC_MESSAGE_ROUTED2_1( uint32_t /* table */, std::string /* result */) +// PPB_Surface3D. +IPC_SYNC_MESSAGE_ROUTED3_1(PpapiHostMsg_PPBSurface3D_Create, + PP_Instance /* instance */, + int32_t /* config */, + std::vector<int32_t> /* attrib_list */, + pp::proxy::HostResource /* result */) +IPC_MESSAGE_ROUTED1(PpapiHostMsg_PPBSurface3D_SwapBuffers, + pp::proxy::HostResource /* surface_3d */) + // PPB_Testing. IPC_SYNC_MESSAGE_ROUTED3_1( PpapiHostMsg_PPBTesting_ReadImageData, diff --git a/ppapi/proxy/ppb_context_3d_proxy.cc b/ppapi/proxy/ppb_context_3d_proxy.cc new file mode 100644 index 0000000..9650c84 --- /dev/null +++ b/ppapi/proxy/ppb_context_3d_proxy.cc @@ -0,0 +1,584 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/proxy/ppb_context_3d_proxy.h" + +#include "base/hash_tables.h" +#include "gpu/command_buffer/client/gles2_cmd_helper.h" +#include "gpu/command_buffer/client/gles2_implementation.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/pp_resource.h" +#include "ppapi/c/dev/ppb_context_3d_dev.h" +#include "ppapi/c/dev/ppb_context_3d_trusted_dev.h" +#include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/proxy/ppapi_messages.h" +#include "ppapi/proxy/ppb_surface_3d_proxy.h" + +namespace pp { +namespace proxy { + +namespace { + +PP_Resource Create(PP_Instance instance, + PP_Config3D_Dev config, + PP_Resource share_context, + const int32_t* attrib_list) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return PP_ERROR_BADARGUMENT; + + // TODO(alokp): Support shared context. + DCHECK_EQ(0, share_context); + if (share_context != 0) + return 0; + + std::vector<int32_t> attribs; + if (attrib_list) { + for (const int32_t* attr = attrib_list; attr; ++attr) + attribs.push_back(*attr); + } else { + attribs.push_back(0); + } + + HostResource result; + dispatcher->Send(new PpapiHostMsg_PPBContext3D_Create( + INTERFACE_ID_PPB_CONTEXT_3D, instance, config, attribs, &result)); + + if (result.is_null()) + return 0; + linked_ptr<Context3D> context_3d(new Context3D(result)); + if (!context_3d->CreateImplementation()) + return 0; + return PluginResourceTracker::GetInstance()->AddResource(context_3d); +} + +PP_Bool IsContext3D(PP_Resource resource) { + Context3D* object = PluginResource::GetAs<Context3D>(resource); + return BoolToPPBool(!!object); +} + +int32_t GetAttrib(PP_Resource context, + int32_t attribute, + int32_t* value) { + // TODO(alokp): Implement me. + return 0; +} + +int32_t BindSurfaces(PP_Resource context_id, + PP_Resource draw, + PP_Resource read) { + Context3D* object = PluginResource::GetAs<Context3D>(context_id); + if (!object) + return PP_ERROR_BADRESOURCE; + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( + object->instance()); + if (!dispatcher) + return PP_ERROR_FAILED; + + // TODO(alokp): Support separate draw-read surfaces. + DCHECK_EQ(draw, read); + if (draw != read) + return PP_GRAPHICS3DERROR_BAD_MATCH; + + Surface3D* draw_surface = PluginResource::GetAs<Surface3D>(draw); + Surface3D* read_surface = PluginResource::GetAs<Surface3D>(read); + if (draw && !draw_surface) + return PP_ERROR_BADRESOURCE; + if (read && !read_surface) + return PP_ERROR_BADRESOURCE; + HostResource host_draw = + draw_surface ? draw_surface->host_resource() : HostResource(); + HostResource host_read = + read_surface ? read_surface->host_resource() : HostResource(); + + int32_t result; + dispatcher->Send(new PpapiHostMsg_PPBContext3D_BindSurfaces( + INTERFACE_ID_PPB_CONTEXT_3D, + object->host_resource(), + host_draw, + host_read, + &result)); + + if (result == PP_OK) + object->BindSurfaces(draw_surface, read_surface); + + return result; +} + +int32_t GetBoundSurfaces(PP_Resource context, + PP_Resource* draw, + PP_Resource* read) { + Context3D* object = PluginResource::GetAs<Context3D>(context); + if (!object) + return PP_ERROR_BADRESOURCE; + + Surface3D* draw_surface = object->get_draw_surface(); + Surface3D* read_surface = object->get_read_surface(); + + *draw = draw_surface ? draw_surface->resource() : 0; + *read = read_surface ? read_surface->resource() : 0; + return PP_OK; +} + + +const PPB_Context3D_Dev ppb_context_3d = { + &Create, + &IsContext3D, + &GetAttrib, + &BindSurfaces, + &GetBoundSurfaces, +}; + +base::SharedMemoryHandle SHMHandleFromInt(int shm_handle) { +#if defined(OS_POSIX) + return base::FileDescriptor(shm_handle, true); +#elif defined(OS_WIN) + return reinterpret_cast<HANDLE>(shm_handle); +#else +#error "Platform not supported." +#endif +} + +gpu::CommandBuffer::State GPUStateFromPPState( + const PP_Context3DTrustedState& s) { + gpu::CommandBuffer::State state; + state.num_entries = s.num_entries; + state.get_offset = s.get_offset; + state.put_offset = s.put_offset; + state.token = s.token; + state.error = static_cast<gpu::error::Error>(s.error); + return state; +} + +// Size of the transfer buffer. +const int32 kCommandBufferSize = 1024 * 1024; +const int32 kTransferBufferSize = 1024 * 1024; + +} // namespace + +class PepperCommandBuffer : public gpu::CommandBuffer { + public: + PepperCommandBuffer(const HostResource& resource, + PluginDispatcher* dispatcher); + virtual ~PepperCommandBuffer(); + + // CommandBuffer implementation: + virtual bool Initialize(int32 size); + virtual gpu::Buffer GetRingBuffer(); + virtual State GetState(); + virtual void Flush(int32 put_offset); + virtual State FlushSync(int32 put_offset); + virtual void SetGetOffset(int32 get_offset); + virtual int32 CreateTransferBuffer(size_t size); + virtual void DestroyTransferBuffer(int32 id); + virtual gpu::Buffer GetTransferBuffer(int32 handle); + virtual void SetToken(int32 token); + virtual void SetParseError(gpu::error::Error error); + + private: + bool Send(IPC::Message* msg); + + int32 num_entries_; + scoped_ptr<base::SharedMemory> ring_buffer_; + + typedef base::hash_map<int32, gpu::Buffer> TransferBufferMap; + TransferBufferMap transfer_buffers_; + + State last_state_; + + HostResource resource_; + PluginDispatcher* dispatcher_; + + DISALLOW_COPY_AND_ASSIGN(PepperCommandBuffer); +}; + +PepperCommandBuffer::PepperCommandBuffer( + const HostResource& resource, + PluginDispatcher* dispatcher) + : num_entries_(0), + resource_(resource), + dispatcher_(dispatcher) { +} + +PepperCommandBuffer::~PepperCommandBuffer() { + // Delete all the locally cached shared memory objects, closing the handle + // in this process. + for (TransferBufferMap::iterator it = transfer_buffers_.begin(); + it != transfer_buffers_.end(); + ++it) { + delete it->second.shared_memory; + it->second.shared_memory = NULL; + } +} + +bool PepperCommandBuffer::Initialize(int32 size) { + DCHECK(!ring_buffer_.get()); + + // Initialize the service. Assuming we are sandboxed, the GPU + // process is responsible for duplicating the handle. This might not be true + // for NaCl. + base::SharedMemoryHandle handle; + if (Send(new PpapiHostMsg_PPBContext3D_Initialize( + INTERFACE_ID_PPB_CONTEXT_3D, resource_, size, &handle)) && + base::SharedMemory::IsHandleValid(handle)) { + ring_buffer_.reset(new base::SharedMemory(handle, false)); + if (ring_buffer_->Map(size)) { + num_entries_ = size / sizeof(gpu::CommandBufferEntry); + return true; + } + + ring_buffer_.reset(); + } + + return false; +} + +gpu::Buffer PepperCommandBuffer::GetRingBuffer() { + // Return locally cached ring buffer. + gpu::Buffer buffer; + buffer.ptr = ring_buffer_->memory(); + buffer.size = num_entries_ * sizeof(gpu::CommandBufferEntry); + buffer.shared_memory = ring_buffer_.get(); + return buffer; +} + +gpu::CommandBuffer::State PepperCommandBuffer::GetState() { + // Send will flag state with lost context if IPC fails. + if (last_state_.error == gpu::error::kNoError) { + Send(new PpapiHostMsg_PPBContext3D_GetState( + INTERFACE_ID_PPB_CONTEXT_3D, resource_, &last_state_)); + } + + return last_state_; +} + +void PepperCommandBuffer::Flush(int32 put_offset) { + if (last_state_.error != gpu::error::kNoError) + return; + + IPC::Message* message = new PpapiHostMsg_PPBContext3D_AsyncFlush( + INTERFACE_ID_PPB_CONTEXT_3D, resource_, put_offset); + + // Do not let a synchronous flush hold up this message. If this handler is + // deferred until after the synchronous flush completes, it will overwrite the + // cached last_state_ with out-of-date data. + message->set_unblock(true); + Send(message); +} + +gpu::CommandBuffer::State PepperCommandBuffer::FlushSync(int32 put_offset) { + // Send will flag state with lost context if IPC fails. + if (last_state_.error == gpu::error::kNoError) { + Send(new PpapiHostMsg_PPBContext3D_Flush( + INTERFACE_ID_PPB_CONTEXT_3D, resource_, put_offset, &last_state_)); + } + + return last_state_; +} + +void PepperCommandBuffer::SetGetOffset(int32 get_offset) { + // Not implemented in proxy. + NOTREACHED(); +} + +int32 PepperCommandBuffer::CreateTransferBuffer(size_t size) { + if (last_state_.error == gpu::error::kNoError) { + int32 id; + if (Send(new PpapiHostMsg_PPBContext3D_CreateTransferBuffer( + INTERFACE_ID_PPB_CONTEXT_3D, resource_, size, &id))) { + return id; + } + } + + return -1; +} + +void PepperCommandBuffer::DestroyTransferBuffer(int32 id) { + if (last_state_.error != gpu::error::kNoError) + return; + + // Remove the transfer buffer from the client side4 cache. + TransferBufferMap::iterator it = transfer_buffers_.find(id); + DCHECK(it != transfer_buffers_.end()); + + // Delete the shared memory object, closing the handle in this process. + delete it->second.shared_memory; + + transfer_buffers_.erase(it); + + Send(new PpapiHostMsg_PPBContext3D_DestroyTransferBuffer( + INTERFACE_ID_PPB_CONTEXT_3D, resource_, id)); +} + +gpu::Buffer PepperCommandBuffer::GetTransferBuffer(int32 id) { + if (last_state_.error != gpu::error::kNoError) + return gpu::Buffer(); + + // Check local cache to see if there is already a client side shared memory + // object for this id. + TransferBufferMap::iterator it = transfer_buffers_.find(id); + if (it != transfer_buffers_.end()) { + return it->second; + } + + // Assuming we are in the renderer process, the service is responsible for + // duplicating the handle. This might not be true for NaCl. + base::SharedMemoryHandle handle; + uint32 size; + if (!Send(new PpapiHostMsg_PPBContext3D_GetTransferBuffer( + INTERFACE_ID_PPB_CONTEXT_3D, resource_, id, &handle, &size))) { + return gpu::Buffer(); + } + + // Cache the transfer buffer shared memory object client side. + scoped_ptr<base::SharedMemory> shared_memory( + new base::SharedMemory(handle, false)); + + // Map the shared memory on demand. + if (!shared_memory->memory()) { + if (!shared_memory->Map(size)) { + return gpu::Buffer(); + } + } + + gpu::Buffer buffer; + buffer.ptr = shared_memory->memory(); + buffer.size = size; + buffer.shared_memory = shared_memory.release(); + transfer_buffers_[id] = buffer; + + return buffer; +} + +void PepperCommandBuffer::SetToken(int32 token) { + NOTREACHED(); +} + +void PepperCommandBuffer::SetParseError(gpu::error::Error error) { + NOTREACHED(); +} + +bool PepperCommandBuffer::Send(IPC::Message* msg) { + DCHECK(last_state_.error == gpu::error::kNoError); + + if (dispatcher_->Send(msg)) + return true; + + last_state_.error = gpu::error::kLostContext; + return false; +} + +Context3D::Context3D(const HostResource& resource) + : PluginResource(resource), + draw_(NULL), + read_(NULL), + transfer_buffer_id_(NULL) { +} + +Context3D::~Context3D() { + if (draw_) + draw_->set_context(NULL); +} + +bool Context3D::CreateImplementation() { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance()); + if (!dispatcher) + return false; + + command_buffer_.reset(new PepperCommandBuffer(host_resource(), dispatcher)); + + if (!command_buffer_->Initialize(kCommandBufferSize)) + return false; + + helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); + if (!helper_->Initialize(kCommandBufferSize)) + return false; + + transfer_buffer_id_ = + command_buffer_->CreateTransferBuffer(kTransferBufferSize); + if (transfer_buffer_id_ < 0) + return false; + + gpu::Buffer transfer_buffer = + command_buffer_->GetTransferBuffer(transfer_buffer_id_); + if (!transfer_buffer.ptr) + return false; + + gles2_impl_.reset(new gpu::gles2::GLES2Implementation( + helper_.get(), + transfer_buffer.size, + transfer_buffer.ptr, + transfer_buffer_id_, + false)); + + return true; +} + +void Context3D::BindSurfaces(Surface3D* draw, Surface3D* read) { + if (draw != draw_) { + if (draw_) + draw_->set_context(NULL); + if (draw) { + draw->set_context(this); + // Resize the backing texture to the size of the instance when it is + // bound. + // TODO(alokp): This should be the responsibility of plugins. + PluginDispatcher* dispatcher = + PluginDispatcher::GetForInstance(instance()); + DCHECK(dispatcher); + InstanceData* data = dispatcher->GetInstanceData(instance()); + DCHECK(data); + gles2_impl()->ResizeCHROMIUM(data->position.size.width, + data->position.size.height); + } + draw_ = draw; + } + read_ = read; +} + +PPB_Context3D_Proxy::PPB_Context3D_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { +} + +PPB_Context3D_Proxy::~PPB_Context3D_Proxy() { +} + +const PPB_Context3DTrusted_Dev* +PPB_Context3D_Proxy::ppb_context_3d_trusted() const { + return static_cast<const PPB_Context3DTrusted_Dev*>( + dispatcher()->GetLocalInterface( + PPB_CONTEXT_3D_TRUSTED_DEV_INTERFACE)); +} + +const void* PPB_Context3D_Proxy::GetSourceInterface() const { + return &ppb_context_3d; +} + +InterfaceID PPB_Context3D_Proxy::GetInterfaceId() const { + return INTERFACE_ID_PPB_CONTEXT_3D; +} + +bool PPB_Context3D_Proxy::OnMessageReceived(const IPC::Message& msg) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(PPB_Context3D_Proxy, msg) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_Create, + OnMsgCreate) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_BindSurfaces, + OnMsgBindSurfaces) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_Initialize, + OnMsgInitialize) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_GetState, + OnMsgGetState) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_Flush, + OnMsgFlush) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_AsyncFlush, + OnMsgAsyncFlush) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_CreateTransferBuffer, + OnMsgCreateTransferBuffer) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_DestroyTransferBuffer, + OnMsgDestroyTransferBuffer) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_GetTransferBuffer, + OnMsgGetTransferBuffer) + IPC_MESSAGE_UNHANDLED(handled = false) + + IPC_END_MESSAGE_MAP() + // FIXME(brettw) handle bad messages! + return handled; +} + +void PPB_Context3D_Proxy::OnMsgCreate(PP_Instance instance, + PP_Config3D_Dev config, + std::vector<int32_t> attribs, + HostResource* result) { + DCHECK(attribs.back() == 0); + PP_Resource resource = ppb_context_3d_trusted()->CreateRaw( + instance, config, 0, &attribs.front()); + result->SetHostResource(instance, resource); +} + +void PPB_Context3D_Proxy::OnMsgBindSurfaces(const HostResource& context, + const HostResource& draw, + const HostResource& read, + int32_t* result) { + *result = ppb_context_3d_target()->BindSurfaces(context.host_resource(), + draw.host_resource(), + read.host_resource()); +} + +void PPB_Context3D_Proxy::OnMsgInitialize( + const HostResource& context, + int32 size, + base::SharedMemoryHandle* ring_buffer) { + const PPB_Context3DTrusted_Dev* context_3d_trusted = ppb_context_3d_trusted(); + *ring_buffer = base::SharedMemory::NULLHandle(); + if (!context_3d_trusted->Initialize(context.host_resource(), size)) + return; + + int shm_handle; + uint32_t shm_size; + if (!context_3d_trusted->GetRingBuffer(context.host_resource(), + &shm_handle, + &shm_size)) { + return; + } + + *ring_buffer = SHMHandleFromInt(shm_handle); +} + +void PPB_Context3D_Proxy::OnMsgGetState(const HostResource& context, + gpu::CommandBuffer::State* state) { + PP_Context3DTrustedState pp_state = + ppb_context_3d_trusted()->GetState(context.host_resource()); + *state = GPUStateFromPPState(pp_state); +} + +void PPB_Context3D_Proxy::OnMsgFlush(const HostResource& context, + int32 put_offset, + gpu::CommandBuffer::State* state) { + PP_Context3DTrustedState pp_state = + ppb_context_3d_trusted()->FlushSync(context.host_resource(), put_offset); + *state = GPUStateFromPPState(pp_state); +} + +void PPB_Context3D_Proxy::OnMsgAsyncFlush(const HostResource& context, + int32 put_offset) { + ppb_context_3d_trusted()->Flush(context.host_resource(), put_offset); +} + +void PPB_Context3D_Proxy::OnMsgCreateTransferBuffer( + const HostResource& context, + int32 size, + int32* id) { + *id = ppb_context_3d_trusted()->CreateTransferBuffer( + context.host_resource(), size); +} + +void PPB_Context3D_Proxy::OnMsgDestroyTransferBuffer( + const HostResource& context, + int32 id) { + ppb_context_3d_trusted()->DestroyTransferBuffer(context.host_resource(), id); +} + +void PPB_Context3D_Proxy::OnMsgGetTransferBuffer( + const HostResource& context, + int32 id, + base::SharedMemoryHandle* transfer_buffer, + uint32* size) { + *transfer_buffer = base::SharedMemory::NULLHandle(); + int shm_handle; + uint32_t shm_size; + if (!ppb_context_3d_trusted()->GetTransferBuffer(context.host_resource(), + id, + &shm_handle, + &shm_size)) { + return; + } + *transfer_buffer = SHMHandleFromInt(shm_handle); + *size = shm_size; +} + +} // namespace proxy +} // namespace pp diff --git a/ppapi/proxy/ppb_context_3d_proxy.h b/ppapi/proxy/ppb_context_3d_proxy.h new file mode 100644 index 0000000..47b8146 --- /dev/null +++ b/ppapi/proxy/ppb_context_3d_proxy.h @@ -0,0 +1,120 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_PPB_CONTEXT_3D_PROXY_H_ +#define PPAPI_PPB_CONTEXT_3D_PROXY_H_ + +#include <vector> + +#include "base/shared_memory.h" +#include "gpu/command_buffer/common/command_buffer.h" +#include "ppapi/c/dev/pp_graphics_3d_dev.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/proxy/interface_proxy.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/proxy/proxy_non_thread_safe_ref_count.h" + +struct PPB_Context3D_Dev; +struct PPB_Context3DTrusted_Dev; + +namespace gpu { +class CommandBuffer; + +namespace gles2 { +class GLES2CmdHelper; +class GLES2Implementation; +} // namespace gles2 + +} // namespace gpu + +namespace pp { +namespace proxy { + +class Surface3D; + +class Context3D : public PluginResource { + public: + explicit Context3D(const HostResource& resource); + virtual ~Context3D(); + + // Resource overrides. + virtual Context3D* AsContext3D() { return this; } + + bool CreateImplementation(); + + Surface3D* get_draw_surface() const { + return draw_; + } + + Surface3D* get_read_surface() const { + return read_; + } + + void BindSurfaces(Surface3D* draw, Surface3D* read); + + gpu::gles2::GLES2Implementation* gles2_impl() const { + return gles2_impl_.get(); + } + + private: + Surface3D* draw_; + Surface3D* read_; + + scoped_ptr<gpu::CommandBuffer> command_buffer_; + scoped_ptr<gpu::gles2::GLES2CmdHelper> helper_; + int32 transfer_buffer_id_; + scoped_ptr<gpu::gles2::GLES2Implementation> gles2_impl_; + + DISALLOW_COPY_AND_ASSIGN(Context3D); +}; + +class PPB_Context3D_Proxy : public InterfaceProxy { + public: + PPB_Context3D_Proxy(Dispatcher* dispatcher, const void* target_interface); + virtual ~PPB_Context3D_Proxy(); + + const PPB_Context3D_Dev* ppb_context_3d_target() const { + return reinterpret_cast<const PPB_Context3D_Dev*>(target_interface()); + } + const PPB_Context3DTrusted_Dev* ppb_context_3d_trusted() const; + + // InterfaceProxy implementation. + virtual const void* GetSourceInterface() const; + virtual InterfaceID GetInterfaceId() const; + virtual bool OnMessageReceived(const IPC::Message& msg); + + private: + void OnMsgCreate(PP_Instance instance, + PP_Config3D_Dev config, + std::vector<int32_t> attribs, + HostResource* result); + void OnMsgBindSurfaces(const HostResource& context, + const HostResource& draw, + const HostResource& read, + int32_t* result); + void OnMsgInitialize(const HostResource& context, + int32 size, + base::SharedMemoryHandle* ring_buffer); + void OnMsgGetState(const HostResource& context, + gpu::CommandBuffer::State* state); + void OnMsgFlush(const HostResource& context, + int32 put_offset, + gpu::CommandBuffer::State* state); + void OnMsgAsyncFlush(const HostResource& context, + int32 put_offset); + void OnMsgCreateTransferBuffer(const HostResource& context, + int32 size, + int32* id); + void OnMsgDestroyTransferBuffer(const HostResource& context, + int32 id); + void OnMsgGetTransferBuffer(const HostResource& context, + int32 id, + base::SharedMemoryHandle* transfer_buffer, + uint32* size); +}; + +} // namespace proxy +} // namespace pp + +#endif // PPAPI_PPB_CONTEXT_3D_PROXY_H_ diff --git a/ppapi/proxy/ppb_gles_chromium_texture_mapping_proxy.cc b/ppapi/proxy/ppb_gles_chromium_texture_mapping_proxy.cc new file mode 100644 index 0000000..e8fdb27 --- /dev/null +++ b/ppapi/proxy/ppb_gles_chromium_texture_mapping_proxy.cc @@ -0,0 +1,70 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/proxy/ppb_gles_chromium_texture_mapping_proxy.h" + +#include "gpu/command_buffer/client/gles2_implementation.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/pp_resource.h" +#include "ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h" +#include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/proxy/ppb_context_3d_proxy.h" + +namespace pp { +namespace proxy { + +namespace { + +void* MapTexSubImage2DCHROMIUM(PP_Resource context_id, + GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLsizei width, + GLsizei height, + GLenum format, + GLenum type, + GLenum access) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + return context->gles2_impl()->MapTexSubImage2DCHROMIUM( + target, level, xoffset, yoffset, width, height, format, type, access); +} + +void UnmapTexSubImage2DCHROMIUM(PP_Resource context_id, const void* mem) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->UnmapTexSubImage2DCHROMIUM(mem); +} + +const struct PPB_GLESChromiumTextureMapping_Dev ppb_gles2_chromium_tm = { + MapTexSubImage2DCHROMIUM, + UnmapTexSubImage2DCHROMIUM +}; + +} // namespace + +PPB_GLESChromiumTextureMapping_Proxy::PPB_GLESChromiumTextureMapping_Proxy( + Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { +} + +PPB_GLESChromiumTextureMapping_Proxy::~PPB_GLESChromiumTextureMapping_Proxy() { +} + +const void* PPB_GLESChromiumTextureMapping_Proxy::GetSourceInterface() const { + return &ppb_gles2_chromium_tm; +} + +InterfaceID PPB_GLESChromiumTextureMapping_Proxy::GetInterfaceId() const { + return INTERFACE_ID_NONE; +} + +bool PPB_GLESChromiumTextureMapping_Proxy::OnMessageReceived( + const IPC::Message& msg) { + return false; +} + +} // namespace proxy +} // namespace pp diff --git a/ppapi/proxy/ppb_gles_chromium_texture_mapping_proxy.h b/ppapi/proxy/ppb_gles_chromium_texture_mapping_proxy.h new file mode 100644 index 0000000..eff9b4e --- /dev/null +++ b/ppapi/proxy/ppb_gles_chromium_texture_mapping_proxy.h @@ -0,0 +1,36 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_PPB_GLES_CHROMIUM_TEXTURE_MAPPING_PROXY_H_ +#define PPAPI_PPB_GLES_CHROMIUM_TEXTURE_MAPPING_PROXY_H_ + +#include "ppapi/proxy/interface_proxy.h" + +struct PPB_GLESChromiumTextureMapping_Dev; + +namespace pp { +namespace proxy { + +class PPB_GLESChromiumTextureMapping_Proxy : public InterfaceProxy { + public: + PPB_GLESChromiumTextureMapping_Proxy(Dispatcher* dispatcher, + const void* target_interface); + virtual ~PPB_GLESChromiumTextureMapping_Proxy(); + + const PPB_GLESChromiumTextureMapping_Dev* + ppb_gles_chromium_tm_target() const { + return reinterpret_cast<const PPB_GLESChromiumTextureMapping_Dev*>( + target_interface()); + } + + // InterfaceProxy implementation. + virtual const void* GetSourceInterface() const; + virtual InterfaceID GetInterfaceId() const; + virtual bool OnMessageReceived(const IPC::Message& msg); +}; + +} // namespace proxy +} // namespace pp + +#endif // PPAPI_PPB_GLES_CHROMIUM_TEXTURE_MAPPING_PROXY_H_ diff --git a/ppapi/proxy/ppb_opengles2_proxy.cc b/ppapi/proxy/ppb_opengles2_proxy.cc new file mode 100644 index 0000000..51a8d13 --- /dev/null +++ b/ppapi/proxy/ppb_opengles2_proxy.cc @@ -0,0 +1,1037 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file is auto-generated. DO NOT EDIT! + +#include "ppapi/proxy/ppb_opengles2_proxy.h" + +#include "gpu/command_buffer/client/gles2_implementation.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/pp_resource.h" +#include "ppapi/c/dev/ppb_opengles_dev.h" +#include "ppapi/proxy/plugin_dispatcher.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/proxy/ppb_context_3d_proxy.h" + +namespace pp { +namespace proxy { + +namespace { + +void ActiveTexture(PP_Resource context_id, GLenum texture) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->ActiveTexture(texture); +} + +void AttachShader(PP_Resource context_id, GLuint program, GLuint shader) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->AttachShader(program, shader); +} + +void BindAttribLocation( + PP_Resource context_id, GLuint program, GLuint index, const char* name) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->BindAttribLocation(program, index, name); +} + +void BindBuffer(PP_Resource context_id, GLenum target, GLuint buffer) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->BindBuffer(target, buffer); +} + +void BindFramebuffer( + PP_Resource context_id, GLenum target, GLuint framebuffer) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->BindFramebuffer(target, framebuffer); +} + +void BindRenderbuffer( + PP_Resource context_id, GLenum target, GLuint renderbuffer) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->BindRenderbuffer(target, renderbuffer); +} + +void BindTexture(PP_Resource context_id, GLenum target, GLuint texture) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->BindTexture(target, texture); +} + +void BlendColor( + PP_Resource context_id, GLclampf red, GLclampf green, GLclampf blue, + GLclampf alpha) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->BlendColor(red, green, blue, alpha); +} + +void BlendEquation(PP_Resource context_id, GLenum mode) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->BlendEquation(mode); +} + +void BlendEquationSeparate( + PP_Resource context_id, GLenum modeRGB, GLenum modeAlpha) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->BlendEquationSeparate(modeRGB, modeAlpha); +} + +void BlendFunc(PP_Resource context_id, GLenum sfactor, GLenum dfactor) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->BlendFunc(sfactor, dfactor); +} + +void BlendFuncSeparate( + PP_Resource context_id, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, + GLenum dstAlpha) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->BlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); +} + +void BufferData( + PP_Resource context_id, GLenum target, GLsizeiptr size, const void* data, + GLenum usage) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->BufferData(target, size, data, usage); +} + +void BufferSubData( + PP_Resource context_id, GLenum target, GLintptr offset, GLsizeiptr size, + const void* data) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->BufferSubData(target, offset, size, data); +} + +GLenum CheckFramebufferStatus(PP_Resource context_id, GLenum target) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + return context->gles2_impl()->CheckFramebufferStatus(target); +} + +void Clear(PP_Resource context_id, GLbitfield mask) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Clear(mask); +} + +void ClearColor( + PP_Resource context_id, GLclampf red, GLclampf green, GLclampf blue, + GLclampf alpha) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->ClearColor(red, green, blue, alpha); +} + +void ClearDepthf(PP_Resource context_id, GLclampf depth) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->ClearDepthf(depth); +} + +void ClearStencil(PP_Resource context_id, GLint s) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->ClearStencil(s); +} + +void ColorMask( + PP_Resource context_id, GLboolean red, GLboolean green, GLboolean blue, + GLboolean alpha) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->ColorMask(red, green, blue, alpha); +} + +void CompileShader(PP_Resource context_id, GLuint shader) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->CompileShader(shader); +} + +void CompressedTexImage2D( + PP_Resource context_id, GLenum target, GLint level, GLenum internalformat, + GLsizei width, GLsizei height, GLint border, GLsizei imageSize, + const void* data) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->CompressedTexImage2D( + target, level, internalformat, width, height, border, imageSize, data); +} + +void CompressedTexSubImage2D( + PP_Resource context_id, GLenum target, GLint level, GLint xoffset, + GLint yoffset, GLsizei width, GLsizei height, GLenum format, + GLsizei imageSize, const void* data) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->CompressedTexSubImage2D( + target, level, xoffset, yoffset, width, height, format, imageSize, data); +} + +void CopyTexImage2D( + PP_Resource context_id, GLenum target, GLint level, GLenum internalformat, + GLint x, GLint y, GLsizei width, GLsizei height, GLint border) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->CopyTexImage2D( + target, level, internalformat, x, y, width, height, border); +} + +void CopyTexSubImage2D( + PP_Resource context_id, GLenum target, GLint level, GLint xoffset, + GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->CopyTexSubImage2D( + target, level, xoffset, yoffset, x, y, width, height); +} + +GLuint CreateProgram(PP_Resource context_id) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + return context->gles2_impl()->CreateProgram(); +} + +GLuint CreateShader(PP_Resource context_id, GLenum type) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + return context->gles2_impl()->CreateShader(type); +} + +void CullFace(PP_Resource context_id, GLenum mode) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->CullFace(mode); +} + +void DeleteBuffers(PP_Resource context_id, GLsizei n, const GLuint* buffers) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->DeleteBuffers(n, buffers); +} + +void DeleteFramebuffers( + PP_Resource context_id, GLsizei n, const GLuint* framebuffers) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->DeleteFramebuffers(n, framebuffers); +} + +void DeleteProgram(PP_Resource context_id, GLuint program) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->DeleteProgram(program); +} + +void DeleteRenderbuffers( + PP_Resource context_id, GLsizei n, const GLuint* renderbuffers) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->DeleteRenderbuffers(n, renderbuffers); +} + +void DeleteShader(PP_Resource context_id, GLuint shader) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->DeleteShader(shader); +} + +void DeleteTextures( + PP_Resource context_id, GLsizei n, const GLuint* textures) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->DeleteTextures(n, textures); +} + +void DepthFunc(PP_Resource context_id, GLenum func) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->DepthFunc(func); +} + +void DepthMask(PP_Resource context_id, GLboolean flag) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->DepthMask(flag); +} + +void DepthRangef(PP_Resource context_id, GLclampf zNear, GLclampf zFar) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->DepthRangef(zNear, zFar); +} + +void DetachShader(PP_Resource context_id, GLuint program, GLuint shader) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->DetachShader(program, shader); +} + +void Disable(PP_Resource context_id, GLenum cap) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Disable(cap); +} + +void DisableVertexAttribArray(PP_Resource context_id, GLuint index) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->DisableVertexAttribArray(index); +} + +void DrawArrays( + PP_Resource context_id, GLenum mode, GLint first, GLsizei count) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->DrawArrays(mode, first, count); +} + +void DrawElements( + PP_Resource context_id, GLenum mode, GLsizei count, GLenum type, + const void* indices) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->DrawElements(mode, count, type, indices); +} + +void Enable(PP_Resource context_id, GLenum cap) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Enable(cap); +} + +void EnableVertexAttribArray(PP_Resource context_id, GLuint index) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->EnableVertexAttribArray(index); +} + +void Finish(PP_Resource context_id) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Finish(); +} + +void Flush(PP_Resource context_id) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Flush(); +} + +void FramebufferRenderbuffer( + PP_Resource context_id, GLenum target, GLenum attachment, + GLenum renderbuffertarget, GLuint renderbuffer) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->FramebufferRenderbuffer( + target, attachment, renderbuffertarget, renderbuffer); +} + +void FramebufferTexture2D( + PP_Resource context_id, GLenum target, GLenum attachment, GLenum textarget, + GLuint texture, GLint level) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->FramebufferTexture2D( + target, attachment, textarget, texture, level); +} + +void FrontFace(PP_Resource context_id, GLenum mode) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->FrontFace(mode); +} + +void GenBuffers(PP_Resource context_id, GLsizei n, GLuint* buffers) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GenBuffers(n, buffers); +} + +void GenerateMipmap(PP_Resource context_id, GLenum target) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GenerateMipmap(target); +} + +void GenFramebuffers(PP_Resource context_id, GLsizei n, GLuint* framebuffers) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GenFramebuffers(n, framebuffers); +} + +void GenRenderbuffers( + PP_Resource context_id, GLsizei n, GLuint* renderbuffers) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GenRenderbuffers(n, renderbuffers); +} + +void GenTextures(PP_Resource context_id, GLsizei n, GLuint* textures) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GenTextures(n, textures); +} + +void GetActiveAttrib( + PP_Resource context_id, GLuint program, GLuint index, GLsizei bufsize, + GLsizei* length, GLint* size, GLenum* type, char* name) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetActiveAttrib( + program, index, bufsize, length, size, type, name); +} + +void GetActiveUniform( + PP_Resource context_id, GLuint program, GLuint index, GLsizei bufsize, + GLsizei* length, GLint* size, GLenum* type, char* name) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetActiveUniform( + program, index, bufsize, length, size, type, name); +} + +void GetAttachedShaders( + PP_Resource context_id, GLuint program, GLsizei maxcount, GLsizei* count, + GLuint* shaders) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetAttachedShaders(program, maxcount, count, shaders); +} + +GLint GetAttribLocation( + PP_Resource context_id, GLuint program, const char* name) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + return context->gles2_impl()->GetAttribLocation(program, name); +} + +void GetBooleanv(PP_Resource context_id, GLenum pname, GLboolean* params) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetBooleanv(pname, params); +} + +void GetBufferParameteriv( + PP_Resource context_id, GLenum target, GLenum pname, GLint* params) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetBufferParameteriv(target, pname, params); +} + +GLenum GetError(PP_Resource context_id) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + return context->gles2_impl()->GetError(); +} + +void GetFloatv(PP_Resource context_id, GLenum pname, GLfloat* params) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetFloatv(pname, params); +} + +void GetFramebufferAttachmentParameteriv( + PP_Resource context_id, GLenum target, GLenum attachment, GLenum pname, + GLint* params) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetFramebufferAttachmentParameteriv( + target, attachment, pname, params); +} + +void GetIntegerv(PP_Resource context_id, GLenum pname, GLint* params) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetIntegerv(pname, params); +} + +void GetProgramiv( + PP_Resource context_id, GLuint program, GLenum pname, GLint* params) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetProgramiv(program, pname, params); +} + +void GetProgramInfoLog( + PP_Resource context_id, GLuint program, GLsizei bufsize, GLsizei* length, + char* infolog) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetProgramInfoLog(program, bufsize, length, infolog); +} + +void GetRenderbufferParameteriv( + PP_Resource context_id, GLenum target, GLenum pname, GLint* params) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetRenderbufferParameteriv(target, pname, params); +} + +void GetShaderiv( + PP_Resource context_id, GLuint shader, GLenum pname, GLint* params) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetShaderiv(shader, pname, params); +} + +void GetShaderInfoLog( + PP_Resource context_id, GLuint shader, GLsizei bufsize, GLsizei* length, + char* infolog) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetShaderInfoLog(shader, bufsize, length, infolog); +} + +void GetShaderPrecisionFormat( + PP_Resource context_id, GLenum shadertype, GLenum precisiontype, + GLint* range, GLint* precision) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetShaderPrecisionFormat( + shadertype, precisiontype, range, precision); +} + +void GetShaderSource( + PP_Resource context_id, GLuint shader, GLsizei bufsize, GLsizei* length, + char* source) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetShaderSource(shader, bufsize, length, source); +} + +const GLubyte* GetString(PP_Resource context_id, GLenum name) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + return context->gles2_impl()->GetString(name); +} + +void GetTexParameterfv( + PP_Resource context_id, GLenum target, GLenum pname, GLfloat* params) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetTexParameterfv(target, pname, params); +} + +void GetTexParameteriv( + PP_Resource context_id, GLenum target, GLenum pname, GLint* params) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetTexParameteriv(target, pname, params); +} + +void GetUniformfv( + PP_Resource context_id, GLuint program, GLint location, GLfloat* params) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetUniformfv(program, location, params); +} + +void GetUniformiv( + PP_Resource context_id, GLuint program, GLint location, GLint* params) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetUniformiv(program, location, params); +} + +GLint GetUniformLocation( + PP_Resource context_id, GLuint program, const char* name) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + return context->gles2_impl()->GetUniformLocation(program, name); +} + +void GetVertexAttribfv( + PP_Resource context_id, GLuint index, GLenum pname, GLfloat* params) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetVertexAttribfv(index, pname, params); +} + +void GetVertexAttribiv( + PP_Resource context_id, GLuint index, GLenum pname, GLint* params) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetVertexAttribiv(index, pname, params); +} + +void GetVertexAttribPointerv( + PP_Resource context_id, GLuint index, GLenum pname, void** pointer) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->GetVertexAttribPointerv(index, pname, pointer); +} + +void Hint(PP_Resource context_id, GLenum target, GLenum mode) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Hint(target, mode); +} + +GLboolean IsBuffer(PP_Resource context_id, GLuint buffer) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + return context->gles2_impl()->IsBuffer(buffer); +} + +GLboolean IsEnabled(PP_Resource context_id, GLenum cap) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + return context->gles2_impl()->IsEnabled(cap); +} + +GLboolean IsFramebuffer(PP_Resource context_id, GLuint framebuffer) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + return context->gles2_impl()->IsFramebuffer(framebuffer); +} + +GLboolean IsProgram(PP_Resource context_id, GLuint program) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + return context->gles2_impl()->IsProgram(program); +} + +GLboolean IsRenderbuffer(PP_Resource context_id, GLuint renderbuffer) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + return context->gles2_impl()->IsRenderbuffer(renderbuffer); +} + +GLboolean IsShader(PP_Resource context_id, GLuint shader) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + return context->gles2_impl()->IsShader(shader); +} + +GLboolean IsTexture(PP_Resource context_id, GLuint texture) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + return context->gles2_impl()->IsTexture(texture); +} + +void LineWidth(PP_Resource context_id, GLfloat width) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->LineWidth(width); +} + +void LinkProgram(PP_Resource context_id, GLuint program) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->LinkProgram(program); +} + +void PixelStorei(PP_Resource context_id, GLenum pname, GLint param) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->PixelStorei(pname, param); +} + +void PolygonOffset(PP_Resource context_id, GLfloat factor, GLfloat units) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->PolygonOffset(factor, units); +} + +void ReadPixels( + PP_Resource context_id, GLint x, GLint y, GLsizei width, GLsizei height, + GLenum format, GLenum type, void* pixels) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->ReadPixels(x, y, width, height, format, type, pixels); +} + +void ReleaseShaderCompiler(PP_Resource context_id) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->ReleaseShaderCompiler(); +} + +void RenderbufferStorage( + PP_Resource context_id, GLenum target, GLenum internalformat, GLsizei width, + GLsizei height) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->RenderbufferStorage( + target, internalformat, width, height); +} + +void SampleCoverage(PP_Resource context_id, GLclampf value, GLboolean invert) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->SampleCoverage(value, invert); +} + +void Scissor( + PP_Resource context_id, GLint x, GLint y, GLsizei width, GLsizei height) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Scissor(x, y, width, height); +} + +void ShaderBinary( + PP_Resource context_id, GLsizei n, const GLuint* shaders, + GLenum binaryformat, const void* binary, GLsizei length) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->ShaderBinary( + n, shaders, binaryformat, binary, length); +} + +void ShaderSource( + PP_Resource context_id, GLuint shader, GLsizei count, const char** str, + const GLint* length) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->ShaderSource(shader, count, str, length); +} + +void StencilFunc(PP_Resource context_id, GLenum func, GLint ref, GLuint mask) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->StencilFunc(func, ref, mask); +} + +void StencilFuncSeparate( + PP_Resource context_id, GLenum face, GLenum func, GLint ref, GLuint mask) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->StencilFuncSeparate(face, func, ref, mask); +} + +void StencilMask(PP_Resource context_id, GLuint mask) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->StencilMask(mask); +} + +void StencilMaskSeparate(PP_Resource context_id, GLenum face, GLuint mask) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->StencilMaskSeparate(face, mask); +} + +void StencilOp( + PP_Resource context_id, GLenum fail, GLenum zfail, GLenum zpass) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->StencilOp(fail, zfail, zpass); +} + +void StencilOpSeparate( + PP_Resource context_id, GLenum face, GLenum fail, GLenum zfail, + GLenum zpass) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->StencilOpSeparate(face, fail, zfail, zpass); +} + +void TexImage2D( + PP_Resource context_id, GLenum target, GLint level, GLint internalformat, + GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, + const void* pixels) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->TexImage2D( + target, level, internalformat, width, height, border, format, type, + pixels); +} + +void TexParameterf( + PP_Resource context_id, GLenum target, GLenum pname, GLfloat param) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->TexParameterf(target, pname, param); +} + +void TexParameterfv( + PP_Resource context_id, GLenum target, GLenum pname, + const GLfloat* params) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->TexParameterfv(target, pname, params); +} + +void TexParameteri( + PP_Resource context_id, GLenum target, GLenum pname, GLint param) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->TexParameteri(target, pname, param); +} + +void TexParameteriv( + PP_Resource context_id, GLenum target, GLenum pname, const GLint* params) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->TexParameteriv(target, pname, params); +} + +void TexSubImage2D( + PP_Resource context_id, GLenum target, GLint level, GLint xoffset, + GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, + const void* pixels) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->TexSubImage2D( + target, level, xoffset, yoffset, width, height, format, type, pixels); +} + +void Uniform1f(PP_Resource context_id, GLint location, GLfloat x) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Uniform1f(location, x); +} + +void Uniform1fv( + PP_Resource context_id, GLint location, GLsizei count, const GLfloat* v) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Uniform1fv(location, count, v); +} + +void Uniform1i(PP_Resource context_id, GLint location, GLint x) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Uniform1i(location, x); +} + +void Uniform1iv( + PP_Resource context_id, GLint location, GLsizei count, const GLint* v) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Uniform1iv(location, count, v); +} + +void Uniform2f(PP_Resource context_id, GLint location, GLfloat x, GLfloat y) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Uniform2f(location, x, y); +} + +void Uniform2fv( + PP_Resource context_id, GLint location, GLsizei count, const GLfloat* v) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Uniform2fv(location, count, v); +} + +void Uniform2i(PP_Resource context_id, GLint location, GLint x, GLint y) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Uniform2i(location, x, y); +} + +void Uniform2iv( + PP_Resource context_id, GLint location, GLsizei count, const GLint* v) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Uniform2iv(location, count, v); +} + +void Uniform3f( + PP_Resource context_id, GLint location, GLfloat x, GLfloat y, GLfloat z) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Uniform3f(location, x, y, z); +} + +void Uniform3fv( + PP_Resource context_id, GLint location, GLsizei count, const GLfloat* v) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Uniform3fv(location, count, v); +} + +void Uniform3i( + PP_Resource context_id, GLint location, GLint x, GLint y, GLint z) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Uniform3i(location, x, y, z); +} + +void Uniform3iv( + PP_Resource context_id, GLint location, GLsizei count, const GLint* v) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Uniform3iv(location, count, v); +} + +void Uniform4f( + PP_Resource context_id, GLint location, GLfloat x, GLfloat y, GLfloat z, + GLfloat w) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Uniform4f(location, x, y, z, w); +} + +void Uniform4fv( + PP_Resource context_id, GLint location, GLsizei count, const GLfloat* v) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Uniform4fv(location, count, v); +} + +void Uniform4i( + PP_Resource context_id, GLint location, GLint x, GLint y, GLint z, + GLint w) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Uniform4i(location, x, y, z, w); +} + +void Uniform4iv( + PP_Resource context_id, GLint location, GLsizei count, const GLint* v) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Uniform4iv(location, count, v); +} + +void UniformMatrix2fv( + PP_Resource context_id, GLint location, GLsizei count, GLboolean transpose, + const GLfloat* value) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->UniformMatrix2fv(location, count, transpose, value); +} + +void UniformMatrix3fv( + PP_Resource context_id, GLint location, GLsizei count, GLboolean transpose, + const GLfloat* value) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->UniformMatrix3fv(location, count, transpose, value); +} + +void UniformMatrix4fv( + PP_Resource context_id, GLint location, GLsizei count, GLboolean transpose, + const GLfloat* value) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->UniformMatrix4fv(location, count, transpose, value); +} + +void UseProgram(PP_Resource context_id, GLuint program) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->UseProgram(program); +} + +void ValidateProgram(PP_Resource context_id, GLuint program) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->ValidateProgram(program); +} + +void VertexAttrib1f(PP_Resource context_id, GLuint indx, GLfloat x) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->VertexAttrib1f(indx, x); +} + +void VertexAttrib1fv( + PP_Resource context_id, GLuint indx, const GLfloat* values) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->VertexAttrib1fv(indx, values); +} + +void VertexAttrib2f( + PP_Resource context_id, GLuint indx, GLfloat x, GLfloat y) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->VertexAttrib2f(indx, x, y); +} + +void VertexAttrib2fv( + PP_Resource context_id, GLuint indx, const GLfloat* values) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->VertexAttrib2fv(indx, values); +} + +void VertexAttrib3f( + PP_Resource context_id, GLuint indx, GLfloat x, GLfloat y, GLfloat z) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->VertexAttrib3f(indx, x, y, z); +} + +void VertexAttrib3fv( + PP_Resource context_id, GLuint indx, const GLfloat* values) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->VertexAttrib3fv(indx, values); +} + +void VertexAttrib4f( + PP_Resource context_id, GLuint indx, GLfloat x, GLfloat y, GLfloat z, + GLfloat w) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->VertexAttrib4f(indx, x, y, z, w); +} + +void VertexAttrib4fv( + PP_Resource context_id, GLuint indx, const GLfloat* values) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->VertexAttrib4fv(indx, values); +} + +void VertexAttribPointer( + PP_Resource context_id, GLuint indx, GLint size, GLenum type, + GLboolean normalized, GLsizei stride, const void* ptr) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->VertexAttribPointer( + indx, size, type, normalized, stride, ptr); +} + +void Viewport( + PP_Resource context_id, GLint x, GLint y, GLsizei width, GLsizei height) { + Context3D* context = PluginResource::GetAs<Context3D>(context_id); + context->gles2_impl()->Viewport(x, y, width, height); +} + +const struct PPB_OpenGLES2_Dev ppb_opengles2 = { + &ActiveTexture, + &AttachShader, + &BindAttribLocation, + &BindBuffer, + &BindFramebuffer, + &BindRenderbuffer, + &BindTexture, + &BlendColor, + &BlendEquation, + &BlendEquationSeparate, + &BlendFunc, + &BlendFuncSeparate, + &BufferData, + &BufferSubData, + &CheckFramebufferStatus, + &Clear, + &ClearColor, + &ClearDepthf, + &ClearStencil, + &ColorMask, + &CompileShader, + &CompressedTexImage2D, + &CompressedTexSubImage2D, + &CopyTexImage2D, + &CopyTexSubImage2D, + &CreateProgram, + &CreateShader, + &CullFace, + &DeleteBuffers, + &DeleteFramebuffers, + &DeleteProgram, + &DeleteRenderbuffers, + &DeleteShader, + &DeleteTextures, + &DepthFunc, + &DepthMask, + &DepthRangef, + &DetachShader, + &Disable, + &DisableVertexAttribArray, + &DrawArrays, + &DrawElements, + &Enable, + &EnableVertexAttribArray, + &Finish, + &Flush, + &FramebufferRenderbuffer, + &FramebufferTexture2D, + &FrontFace, + &GenBuffers, + &GenerateMipmap, + &GenFramebuffers, + &GenRenderbuffers, + &GenTextures, + &GetActiveAttrib, + &GetActiveUniform, + &GetAttachedShaders, + &GetAttribLocation, + &GetBooleanv, + &GetBufferParameteriv, + &GetError, + &GetFloatv, + &GetFramebufferAttachmentParameteriv, + &GetIntegerv, + &GetProgramiv, + &GetProgramInfoLog, + &GetRenderbufferParameteriv, + &GetShaderiv, + &GetShaderInfoLog, + &GetShaderPrecisionFormat, + &GetShaderSource, + &GetString, + &GetTexParameterfv, + &GetTexParameteriv, + &GetUniformfv, + &GetUniformiv, + &GetUniformLocation, + &GetVertexAttribfv, + &GetVertexAttribiv, + &GetVertexAttribPointerv, + &Hint, + &IsBuffer, + &IsEnabled, + &IsFramebuffer, + &IsProgram, + &IsRenderbuffer, + &IsShader, + &IsTexture, + &LineWidth, + &LinkProgram, + &PixelStorei, + &PolygonOffset, + &ReadPixels, + &ReleaseShaderCompiler, + &RenderbufferStorage, + &SampleCoverage, + &Scissor, + &ShaderBinary, + &ShaderSource, + &StencilFunc, + &StencilFuncSeparate, + &StencilMask, + &StencilMaskSeparate, + &StencilOp, + &StencilOpSeparate, + &TexImage2D, + &TexParameterf, + &TexParameterfv, + &TexParameteri, + &TexParameteriv, + &TexSubImage2D, + &Uniform1f, + &Uniform1fv, + &Uniform1i, + &Uniform1iv, + &Uniform2f, + &Uniform2fv, + &Uniform2i, + &Uniform2iv, + &Uniform3f, + &Uniform3fv, + &Uniform3i, + &Uniform3iv, + &Uniform4f, + &Uniform4fv, + &Uniform4i, + &Uniform4iv, + &UniformMatrix2fv, + &UniformMatrix3fv, + &UniformMatrix4fv, + &UseProgram, + &ValidateProgram, + &VertexAttrib1f, + &VertexAttrib1fv, + &VertexAttrib2f, + &VertexAttrib2fv, + &VertexAttrib3f, + &VertexAttrib3fv, + &VertexAttrib4f, + &VertexAttrib4fv, + &VertexAttribPointer, + &Viewport +}; + +} // namespace + +PPB_OpenGLES2_Proxy::PPB_OpenGLES2_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface) { +} + +PPB_OpenGLES2_Proxy::~PPB_OpenGLES2_Proxy() { +} + +const void* PPB_OpenGLES2_Proxy::GetSourceInterface() const { + return &ppb_opengles2; +} + +InterfaceID PPB_OpenGLES2_Proxy::GetInterfaceId() const { + return INTERFACE_ID_NONE; +} + +bool PPB_OpenGLES2_Proxy::OnMessageReceived(const IPC::Message& msg) { + return false; +} + +} // namespace proxy +} // namespace pp diff --git a/ppapi/proxy/ppb_opengles2_proxy.h b/ppapi/proxy/ppb_opengles2_proxy.h new file mode 100644 index 0000000..5901b4c --- /dev/null +++ b/ppapi/proxy/ppb_opengles2_proxy.h @@ -0,0 +1,35 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_PPB_OPENGLES2_PROXY_H_ +#define PPAPI_PPB_OPENGLES2_PROXY_H_ + +#include "ppapi/proxy/interface_proxy.h" + +struct PPB_OpenGLES2_Dev; + +namespace pp { +namespace proxy { + +class PPB_OpenGLES2_Proxy : public InterfaceProxy { + public: + PPB_OpenGLES2_Proxy(Dispatcher* dispatcher, const void* target_interface); + virtual ~PPB_OpenGLES2_Proxy(); + + const PPB_OpenGLES2_Dev* ppb_gles2_target() const { + return reinterpret_cast<const PPB_OpenGLES2_Dev*>(target_interface()); + } + + // InterfaceProxy implementation. + virtual const void* GetSourceInterface() const; + virtual InterfaceID GetInterfaceId() const; + virtual bool OnMessageReceived(const IPC::Message& msg); + + private: +}; + +} // namespace proxy +} // namespace pp + +#endif // PPAPI_PPB_OPENGLES2_PROXY_H_ diff --git a/ppapi/proxy/ppb_surface_3d_proxy.cc b/ppapi/proxy/ppb_surface_3d_proxy.cc new file mode 100644 index 0000000..eaca110 --- /dev/null +++ b/ppapi/proxy/ppb_surface_3d_proxy.cc @@ -0,0 +1,196 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/proxy/ppb_surface_3d_proxy.h" + +#include "gpu/command_buffer/client/gles2_implementation.h" +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/pp_resource.h" +#include "ppapi/c/dev/ppb_surface_3d_dev.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" + +namespace pp { +namespace proxy { + +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; + + std::vector<int32_t> attribs; + if (attrib_list) { + for (const int32_t* attr = attrib_list; attr; ++attr) + attribs.push_back(*attr); + } else { + attribs.push_back(0); + } + + 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; +} + +PP_Bool IsSurface3D(PP_Resource resource) { + Surface3D* object = PluginResource::GetAs<Surface3D>(resource); + return BoolToPPBool(!!object); +} + +int32_t SetAttrib(PP_Resource surface_id, + 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) { + // 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; + + // 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()) + return PP_ERROR_INPROGRESS; // Can't have >1 flush pending. + + if (!object->context()) + return PP_ERROR_FAILED; + + object->set_current_flush_callback(callback); + + IPC::Message* msg = new PpapiHostMsg_PPBSurface3D_SwapBuffers( + INTERFACE_ID_PPB_SURFACE_3D, object->host_resource()); + msg->set_unblock(true); + dispatcher->Send(msg); + + object->context()->gles2_impl()->SwapBuffers(); + + return PP_ERROR_WOULDBLOCK; +} + +const PPB_Surface3D_Dev ppb_surface_3d = { + &Create, + &IsSurface3D, + &SetAttrib, + &GetAttrib, + &SwapBuffers +}; + +} // namespace + +PPB_Surface3D_Proxy::PPB_Surface3D_Proxy(Dispatcher* dispatcher, + const void* target_interface) + : InterfaceProxy(dispatcher, target_interface), + callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { +} + +PPB_Surface3D_Proxy::~PPB_Surface3D_Proxy() { +} + +const void* PPB_Surface3D_Proxy::GetSourceInterface() const { + return &ppb_surface_3d; +} + +InterfaceID PPB_Surface3D_Proxy::GetInterfaceId() const { + return INTERFACE_ID_PPB_SURFACE_3D; +} + +bool PPB_Surface3D_Proxy::OnMessageReceived(const IPC::Message& msg) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(PPB_Surface3D_Proxy, msg) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBSurface3D_Create, + OnMsgCreate) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBSurface3D_SwapBuffers, + OnMsgSwapBuffers) + + IPC_MESSAGE_HANDLER(PpapiMsg_PPBSurface3D_SwapBuffersACK, + OnMsgSwapBuffersACK) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + // FIXME(brettw) handle bad messages! + return handled; +} + +void PPB_Surface3D_Proxy::OnMsgCreate(PP_Instance instance, + PP_Config3D_Dev config, + std::vector<int32_t> attribs, + HostResource* result) { + DCHECK(attribs.back() == 0); + PP_Resource resource = + ppb_surface_3d_target()->Create(instance, config, &attribs.front()); + result->SetHostResource(instance, resource); +} + +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()); + if (result != PP_ERROR_WOULDBLOCK) { + // 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 + // up the data associated with the callback. + callback.Run(result); + } +} + +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); +} + +void PPB_Surface3D_Proxy::SendSwapBuffersACKToPlugin( + int32_t result, + const HostResource& surface_3d) { + dispatcher()->Send(new PpapiMsg_PPBSurface3D_SwapBuffersACK( + INTERFACE_ID_PPB_SURFACE_3D, surface_3d, result)); +} + +} // namespace proxy +} // namespace pp diff --git a/ppapi/proxy/ppb_surface_3d_proxy.h b/ppapi/proxy/ppb_surface_3d_proxy.h new file mode 100644 index 0000000..2bd4f83 --- /dev/null +++ b/ppapi/proxy/ppb_surface_3d_proxy.h @@ -0,0 +1,100 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_PPB_SURFACE_3D_PROXY_H_ +#define PPAPI_PPB_SURFACE_3D_PROXY_H_ + +#include <vector> + +#include "ppapi/c/dev/pp_graphics_3d_dev.h" +#include "ppapi/c/pp_completion_callback.h" +#include "ppapi/c/pp_instance.h" +#include "ppapi/cpp/completion_callback.h" +#include "ppapi/proxy/interface_proxy.h" +#include "ppapi/proxy/plugin_resource.h" +#include "ppapi/proxy/proxy_non_thread_safe_ref_count.h" + +struct PPB_Surface3D_Dev; + +namespace pp { +namespace proxy { + +class Context3D; + +class Surface3D : public PluginResource { + public: + explicit Surface3D(const HostResource& host_resource) + : PluginResource(host_resource), + resource_(0), + context_(NULL), + current_flush_callback_(PP_BlockUntilComplete()) { + } + + // Resource overrides. + virtual Surface3D* AsSurface3D() { return this; } + + bool is_flush_pending() const { return !!current_flush_callback_.func; } + + PP_CompletionCallback current_flush_callback() const { + return current_flush_callback_; + } + + void set_current_flush_callback(PP_CompletionCallback cb) { + current_flush_callback_ = cb; + } + + void set_context(Context3D* context) { + context_ = context; + } + + Context3D* context() const { return context_; } + + void set_resource(PP_Resource resource) { resource_ = resource; } + PP_Resource resource() const { return resource_; } + + private: + PP_Resource resource_; + Context3D* context_; + // In the plugin, this is the current callback set for Flushes. When the + // callback function pointer is non-NULL, we're waiting for a flush ACK. + PP_CompletionCallback current_flush_callback_; + + DISALLOW_COPY_AND_ASSIGN(Surface3D); +}; + +class PPB_Surface3D_Proxy : public InterfaceProxy { + public: + PPB_Surface3D_Proxy(Dispatcher* dispatcher, const void* target_interface); + virtual ~PPB_Surface3D_Proxy(); + + const PPB_Surface3D_Dev* ppb_surface_3d_target() const { + return reinterpret_cast<const PPB_Surface3D_Dev*>(target_interface()); + } + + // InterfaceProxy implementation. + virtual const void* GetSourceInterface() const; + virtual InterfaceID GetInterfaceId() const; + virtual bool OnMessageReceived(const IPC::Message& msg); + + private: + // Message handlers. + void OnMsgCreate(PP_Instance instance, + PP_Config3D_Dev config, + std::vector<int32_t> attribs, + HostResource* result); + void OnMsgSwapBuffers(const HostResource& surface); + // Renderer->plugin message handlers. + void OnMsgSwapBuffersACK(const HostResource& surface, int32_t pp_error); + + void SendSwapBuffersACKToPlugin(int32_t result, + const HostResource& surface_3d); + + CompletionCallbackFactory<PPB_Surface3D_Proxy, + ProxyNonThreadSafeRefCount> callback_factory_; +}; + +} // namespace proxy +} // namespace pp + +#endif // PPAPI_PPB_SURFACE_3D_PROXY_H_ diff --git a/ppapi/proxy/ppp_instance_proxy.cc b/ppapi/proxy/ppp_instance_proxy.cc index b2103a3..144e3a1 100644 --- a/ppapi/proxy/ppp_instance_proxy.cc +++ b/ppapi/proxy/ppp_instance_proxy.cc @@ -9,6 +9,7 @@ #include "ppapi/c/pp_var.h" #include "ppapi/c/ppp_instance.h" #include "ppapi/proxy/host_dispatcher.h" +#include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/ppapi_messages.h" #include "ppapi/proxy/ppb_url_loader_proxy.h" @@ -142,6 +143,11 @@ void PPP_Instance_Proxy::OnMsgDidCreate( if (argn.size() != argv.size()) return; + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return; + dispatcher->DidCreateInstance(instance); + // Make sure the arrays always have at least one element so we can take the // address below. std::vector<const char*> argn_array( @@ -162,11 +168,23 @@ void PPP_Instance_Proxy::OnMsgDidCreate( void PPP_Instance_Proxy::OnMsgDidDestroy(PP_Instance instance) { ppp_instance_target()->DidDestroy(instance); + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return; + + dispatcher->DidDestroyInstance(instance); } void PPP_Instance_Proxy::OnMsgDidChangeView(PP_Instance instance, const PP_Rect& position, const PP_Rect& clip) { + PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); + if (!dispatcher) + return; + InstanceData* data = dispatcher->GetInstanceData(instance); + if (!data) + return; + data->position = position; ppp_instance_target()->DidChangeView(instance, &position, &clip); } |