blob: 552d422006fdf13759234e6821facc89c938e2d0 [file] [log] [blame]
[email protected]32523382011-06-10 02:30:001// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]43a40202010-11-12 16:25:012// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef PPAPI_PPB_BUFFER_PROXY_H_
6#define PPAPI_PPB_BUFFER_PROXY_H_
7
[email protected]32523382011-06-10 02:30:008#include "base/shared_memory.h"
[email protected]859a7f32011-01-15 03:44:139#include "ppapi/c/pp_instance.h"
[email protected]43a40202010-11-12 16:25:0110#include "ppapi/proxy/interface_proxy.h"
[email protected]7ace8ad2011-08-06 03:23:5811#include "ppapi/proxy/plugin_resource.h"
12#include "ppapi/thunk/ppb_buffer_api.h"
[email protected]43a40202010-11-12 16:25:0113
14struct PPB_Buffer_Dev;
15
16namespace pp {
17namespace proxy {
18
[email protected]f24448db2011-01-27 20:40:3919class HostResource;
20
[email protected]7ace8ad2011-08-06 03:23:5821class Buffer : public ppapi::thunk::PPB_Buffer_API,
22 public PluginResource {
23 public:
24 Buffer(const HostResource& resource,
25 const base::SharedMemoryHandle& shm_handle,
26 uint32_t size);
27 virtual ~Buffer();
28
29 // Resource overrides.
30 virtual Buffer* AsBuffer() OVERRIDE;
31
32 // ResourceObjectBase overrides.
33 virtual ppapi::thunk::PPB_Buffer_API* AsPPB_Buffer_API() OVERRIDE;
34
35 // PPB_Buffer_API implementation.
36 virtual PP_Bool Describe(uint32_t* size_in_bytes) OVERRIDE;
37 virtual PP_Bool IsMapped() OVERRIDE;
38 virtual void* Map() OVERRIDE;
39 virtual void Unmap() OVERRIDE;
40
41 private:
42 base::SharedMemory shm_;
43 uint32_t size_;
44 void* mapped_data_;
45 int map_count_;
46
47 DISALLOW_COPY_AND_ASSIGN(Buffer);
48};
49
[email protected]43a40202010-11-12 16:25:0150class PPB_Buffer_Proxy : public InterfaceProxy {
51 public:
52 PPB_Buffer_Proxy(Dispatcher* dispatcher, const void* target_interface);
53 virtual ~PPB_Buffer_Proxy();
54
[email protected]465faa22011-02-08 16:31:4655 static const Info* GetInfo();
56
[email protected]9815108e2011-05-27 21:50:2857 static PP_Resource CreateProxyResource(PP_Instance instance,
58 uint32_t size);
[email protected]0fa46e82011-08-09 07:31:4959 static PP_Resource AddProxyResource(const HostResource& resource,
60 base::SharedMemoryHandle shm_handle,
61 uint32_t size);
[email protected]9815108e2011-05-27 21:50:2862
[email protected]43a40202010-11-12 16:25:0163 const PPB_Buffer_Dev* ppb_buffer_target() const {
64 return static_cast<const PPB_Buffer_Dev*>(target_interface());
65 }
66
67 // InterfaceProxy implementation.
[email protected]a95986a82010-12-24 06:19:2868 virtual bool OnMessageReceived(const IPC::Message& msg);
[email protected]43a40202010-11-12 16:25:0169
70 private:
71 // Message handlers.
[email protected]859a7f32011-01-15 03:44:1372 void OnMsgCreate(PP_Instance instance,
[email protected]867b76d632010-12-02 00:09:0773 uint32_t size,
[email protected]f24448db2011-01-27 20:40:3974 HostResource* result_resource,
[email protected]32523382011-06-10 02:30:0075 base::SharedMemoryHandle* result_shm_handle);
[email protected]43a40202010-11-12 16:25:0176};
77
78} // namespace proxy
79} // namespace pp
80
81#endif // PPAPI_PPB_BUFFER_PROXY_H_