blob: 9d6cfbe0df08db19d8479ad3c6b60e6c8e1a828c [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]7f8b26b2011-08-18 15:41:0111#include "ppapi/shared_impl/resource.h"
[email protected]7ace8ad2011-08-06 03:23:5812#include "ppapi/thunk/ppb_buffer_api.h"
[email protected]43a40202010-11-12 16:25:0113
14struct PPB_Buffer_Dev;
15
[email protected]be0a84b2011-08-13 04:18:4416namespace ppapi {
17class HostResource;
18}
19
[email protected]43a40202010-11-12 16:25:0120namespace pp {
21namespace proxy {
22
[email protected]7ace8ad2011-08-06 03:23:5823class Buffer : public ppapi::thunk::PPB_Buffer_API,
[email protected]7f8b26b2011-08-18 15:41:0124 public ppapi::Resource {
[email protected]7ace8ad2011-08-06 03:23:5825 public:
[email protected]be0a84b2011-08-13 04:18:4426 Buffer(const ppapi::HostResource& resource,
[email protected]7ace8ad2011-08-06 03:23:5827 const base::SharedMemoryHandle& shm_handle,
28 uint32_t size);
29 virtual ~Buffer();
30
[email protected]7f8b26b2011-08-18 15:41:0131 // Resource overrides.
[email protected]7ace8ad2011-08-06 03:23:5832 virtual ppapi::thunk::PPB_Buffer_API* AsPPB_Buffer_API() OVERRIDE;
33
34 // PPB_Buffer_API implementation.
35 virtual PP_Bool Describe(uint32_t* size_in_bytes) OVERRIDE;
36 virtual PP_Bool IsMapped() OVERRIDE;
37 virtual void* Map() OVERRIDE;
38 virtual void Unmap() OVERRIDE;
39
40 private:
41 base::SharedMemory shm_;
42 uint32_t size_;
43 void* mapped_data_;
44 int map_count_;
45
46 DISALLOW_COPY_AND_ASSIGN(Buffer);
47};
48
[email protected]43a40202010-11-12 16:25:0149class PPB_Buffer_Proxy : public InterfaceProxy {
50 public:
51 PPB_Buffer_Proxy(Dispatcher* dispatcher, const void* target_interface);
52 virtual ~PPB_Buffer_Proxy();
53
[email protected]465faa22011-02-08 16:31:4654 static const Info* GetInfo();
55
[email protected]9815108e2011-05-27 21:50:2856 static PP_Resource CreateProxyResource(PP_Instance instance,
57 uint32_t size);
[email protected]be0a84b2011-08-13 04:18:4458 static PP_Resource AddProxyResource(const ppapi::HostResource& resource,
[email protected]0fa46e82011-08-09 07:31:4959 base::SharedMemoryHandle shm_handle,
60 uint32_t size);
[email protected]9815108e2011-05-27 21:50:2861
[email protected]43a40202010-11-12 16:25:0162 const PPB_Buffer_Dev* ppb_buffer_target() const {
63 return static_cast<const PPB_Buffer_Dev*>(target_interface());
64 }
65
66 // InterfaceProxy implementation.
[email protected]a95986a82010-12-24 06:19:2867 virtual bool OnMessageReceived(const IPC::Message& msg);
[email protected]43a40202010-11-12 16:25:0168
69 private:
70 // Message handlers.
[email protected]859a7f32011-01-15 03:44:1371 void OnMsgCreate(PP_Instance instance,
[email protected]867b76d632010-12-02 00:09:0772 uint32_t size,
[email protected]be0a84b2011-08-13 04:18:4473 ppapi::HostResource* result_resource,
[email protected]32523382011-06-10 02:30:0074 base::SharedMemoryHandle* result_shm_handle);
[email protected]43a40202010-11-12 16:25:0175};
76
77} // namespace proxy
78} // namespace pp
79
80#endif // PPAPI_PPB_BUFFER_PROXY_H_