blob: 0c1b2c84a3d1ca58a67ed858aec2b0a0108cf971 [file] [log] [blame]
[email protected]16b7b272012-07-25 21:54:491// Copyright (c) 2012 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
[email protected]0a6d5f62011-11-11 08:04:075#ifndef PPAPI_PROXY_PPB_BUFFER_PROXY_H_
6#define PPAPI_PROXY_PPB_BUFFER_PROXY_H_
[email protected]43a40202010-11-12 16:25:017
avie029c4132015-12-23 06:45:228#include <stdint.h>
9
Matthew Caryfc3757f2019-07-30 21:32:4610#include "base/memory/shared_memory_mapping.h"
11#include "base/memory/unsafe_shared_memory_region.h"
[email protected]859a7f32011-01-15 03:44:1312#include "ppapi/c/pp_instance.h"
[email protected]43a40202010-11-12 16:25:0113#include "ppapi/proxy/interface_proxy.h"
[email protected]7f8b26b2011-08-18 15:41:0114#include "ppapi/shared_impl/resource.h"
[email protected]7ace8ad2011-08-06 03:23:5815#include "ppapi/thunk/ppb_buffer_api.h"
[email protected]43a40202010-11-12 16:25:0116
[email protected]be0a84b2011-08-13 04:18:4417namespace ppapi {
[email protected]be0a84b2011-08-13 04:18:4418
[email protected]4d2efd22011-08-18 21:58:0219class HostResource;
20
[email protected]43a40202010-11-12 16:25:0121namespace proxy {
22
[email protected]eb5960da2013-01-16 23:23:5323class SerializedHandle;
24
[email protected]4d2efd22011-08-18 21:58:0225class Buffer : public thunk::PPB_Buffer_API, public Resource {
[email protected]7ace8ad2011-08-06 03:23:5826 public:
[email protected]4d2efd22011-08-18 21:58:0227 Buffer(const HostResource& resource,
Matthew Caryfc3757f2019-07-30 21:32:4628 base::UnsafeSharedMemoryRegion shm_handle);
Peter Boström3d5b3cb2021-09-23 21:35:4529
30 Buffer(const Buffer&) = delete;
31 Buffer& operator=(const Buffer&) = delete;
32
nicke4784432015-04-23 14:01:4833 ~Buffer() override;
[email protected]7ace8ad2011-08-06 03:23:5834
[email protected]7f8b26b2011-08-18 15:41:0135 // Resource overrides.
nicke4784432015-04-23 14:01:4836 thunk::PPB_Buffer_API* AsPPB_Buffer_API() override;
[email protected]7ace8ad2011-08-06 03:23:5837
38 // PPB_Buffer_API implementation.
nicke4784432015-04-23 14:01:4839 PP_Bool Describe(uint32_t* size_in_bytes) override;
40 PP_Bool IsMapped() override;
41 void* Map() override;
42 void Unmap() override;
[email protected]7ace8ad2011-08-06 03:23:5843
[email protected]e3da4e802013-03-23 23:50:4944 // Trusted
Matthew Caryfc3757f2019-07-30 21:32:4645 int32_t GetSharedMemory(base::UnsafeSharedMemoryRegion** shm) override;
[email protected]e3da4e802013-03-23 23:50:4946
[email protected]7ace8ad2011-08-06 03:23:5847 private:
Matthew Caryfc3757f2019-07-30 21:32:4648 base::UnsafeSharedMemoryRegion shm_;
49 base::WritableSharedMemoryMapping mapping_;
[email protected]7ace8ad2011-08-06 03:23:5850 int map_count_;
[email protected]7ace8ad2011-08-06 03:23:5851};
52
[email protected]43a40202010-11-12 16:25:0153class PPB_Buffer_Proxy : public InterfaceProxy {
54 public:
[email protected]0a6d5f62011-11-11 08:04:0755 explicit PPB_Buffer_Proxy(Dispatcher* dispatcher);
Lei Zhang94f57fe32017-08-30 23:58:2456 ~PPB_Buffer_Proxy() override;
[email protected]43a40202010-11-12 16:25:0157
[email protected]9815108e2011-05-27 21:50:2858 static PP_Resource CreateProxyResource(PP_Instance instance,
59 uint32_t size);
Matthew Caryfc3757f2019-07-30 21:32:4660 static PP_Resource AddProxyResource(
61 const HostResource& resource,
62 base::UnsafeSharedMemoryRegion shm_region);
[email protected]9815108e2011-05-27 21:50:2863
[email protected]43a40202010-11-12 16:25:0164 // InterfaceProxy implementation.
Lei Zhang94f57fe32017-08-30 23:58:2465 bool OnMessageReceived(const IPC::Message& msg) override;
[email protected]43a40202010-11-12 16:25:0166
[email protected]ac4b54d2011-10-20 23:09:2867 static const ApiID kApiID = API_ID_PPB_BUFFER;
[email protected]5c966022011-09-13 18:09:3768
[email protected]43a40202010-11-12 16:25:0169 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]4d2efd22011-08-18 21:58:0273 HostResource* result_resource,
[email protected]246fc492012-08-27 20:28:1874 ppapi::proxy::SerializedHandle* result_shm_handle);
[email protected]43a40202010-11-12 16:25:0175};
76
77} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:0278} // namespace ppapi
[email protected]43a40202010-11-12 16:25:0179
[email protected]0a6d5f62011-11-11 08:04:0780#endif // PPAPI_PROXY_PPB_BUFFER_PROXY_H_