blob: 786965934794a0aa2d029f8c00285c0366997ef0 [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
10#include "base/macros.h"
Matthew Caryfc3757f2019-07-30 21:32:4611#include "base/memory/shared_memory_mapping.h"
12#include "base/memory/unsafe_shared_memory_region.h"
[email protected]859a7f32011-01-15 03:44:1313#include "ppapi/c/pp_instance.h"
[email protected]43a40202010-11-12 16:25:0114#include "ppapi/proxy/interface_proxy.h"
[email protected]7f8b26b2011-08-18 15:41:0115#include "ppapi/shared_impl/resource.h"
[email protected]7ace8ad2011-08-06 03:23:5816#include "ppapi/thunk/ppb_buffer_api.h"
[email protected]43a40202010-11-12 16:25:0117
[email protected]be0a84b2011-08-13 04:18:4418namespace ppapi {
[email protected]be0a84b2011-08-13 04:18:4419
[email protected]4d2efd22011-08-18 21:58:0220class HostResource;
21
[email protected]43a40202010-11-12 16:25:0122namespace proxy {
23
[email protected]eb5960da2013-01-16 23:23:5324class SerializedHandle;
25
[email protected]4d2efd22011-08-18 21:58:0226class Buffer : public thunk::PPB_Buffer_API, public Resource {
[email protected]7ace8ad2011-08-06 03:23:5827 public:
[email protected]4d2efd22011-08-18 21:58:0228 Buffer(const HostResource& resource,
Matthew Caryfc3757f2019-07-30 21:32:4629 base::UnsafeSharedMemoryRegion shm_handle);
Peter Boström3d5b3cb2021-09-23 21:35:4530
31 Buffer(const Buffer&) = delete;
32 Buffer& operator=(const Buffer&) = delete;
33
nicke4784432015-04-23 14:01:4834 ~Buffer() override;
[email protected]7ace8ad2011-08-06 03:23:5835
[email protected]7f8b26b2011-08-18 15:41:0136 // Resource overrides.
nicke4784432015-04-23 14:01:4837 thunk::PPB_Buffer_API* AsPPB_Buffer_API() override;
[email protected]7ace8ad2011-08-06 03:23:5838
39 // PPB_Buffer_API implementation.
nicke4784432015-04-23 14:01:4840 PP_Bool Describe(uint32_t* size_in_bytes) override;
41 PP_Bool IsMapped() override;
42 void* Map() override;
43 void Unmap() override;
[email protected]7ace8ad2011-08-06 03:23:5844
[email protected]e3da4e802013-03-23 23:50:4945 // Trusted
Matthew Caryfc3757f2019-07-30 21:32:4646 int32_t GetSharedMemory(base::UnsafeSharedMemoryRegion** shm) override;
[email protected]e3da4e802013-03-23 23:50:4947
[email protected]7ace8ad2011-08-06 03:23:5848 private:
Matthew Caryfc3757f2019-07-30 21:32:4649 base::UnsafeSharedMemoryRegion shm_;
50 base::WritableSharedMemoryMapping mapping_;
[email protected]7ace8ad2011-08-06 03:23:5851 int map_count_;
[email protected]7ace8ad2011-08-06 03:23:5852};
53
[email protected]43a40202010-11-12 16:25:0154class PPB_Buffer_Proxy : public InterfaceProxy {
55 public:
[email protected]0a6d5f62011-11-11 08:04:0756 explicit PPB_Buffer_Proxy(Dispatcher* dispatcher);
Lei Zhang94f57fe32017-08-30 23:58:2457 ~PPB_Buffer_Proxy() override;
[email protected]43a40202010-11-12 16:25:0158
[email protected]9815108e2011-05-27 21:50:2859 static PP_Resource CreateProxyResource(PP_Instance instance,
60 uint32_t size);
Matthew Caryfc3757f2019-07-30 21:32:4661 static PP_Resource AddProxyResource(
62 const HostResource& resource,
63 base::UnsafeSharedMemoryRegion shm_region);
[email protected]9815108e2011-05-27 21:50:2864
[email protected]43a40202010-11-12 16:25:0165 // InterfaceProxy implementation.
Lei Zhang94f57fe32017-08-30 23:58:2466 bool OnMessageReceived(const IPC::Message& msg) override;
[email protected]43a40202010-11-12 16:25:0167
[email protected]ac4b54d2011-10-20 23:09:2868 static const ApiID kApiID = API_ID_PPB_BUFFER;
[email protected]5c966022011-09-13 18:09:3769
[email protected]43a40202010-11-12 16:25:0170 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]4d2efd22011-08-18 21:58:0274 HostResource* result_resource,
[email protected]246fc492012-08-27 20:28:1875 ppapi::proxy::SerializedHandle* result_shm_handle);
[email protected]43a40202010-11-12 16:25:0176};
77
78} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:0279} // namespace ppapi
[email protected]43a40202010-11-12 16:25:0180
[email protected]0a6d5f62011-11-11 08:04:0781#endif // PPAPI_PROXY_PPB_BUFFER_PROXY_H_