[email protected] | 16b7b27 | 2012-07-25 21:54:49 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 0a6d5f6 | 2011-11-11 08:04:07 | [diff] [blame] | 5 | #ifndef PPAPI_PROXY_PPB_BUFFER_PROXY_H_ |
6 | #define PPAPI_PROXY_PPB_BUFFER_PROXY_H_ | ||||
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 7 | |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 8 | #include <stdint.h> |
9 | |||||
10 | #include "base/macros.h" | ||||
Matthew Cary | fc3757f | 2019-07-30 21:32:46 | [diff] [blame] | 11 | #include "base/memory/shared_memory_mapping.h" |
12 | #include "base/memory/unsafe_shared_memory_region.h" | ||||
[email protected] | 859a7f3 | 2011-01-15 03:44:13 | [diff] [blame] | 13 | #include "ppapi/c/pp_instance.h" |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 14 | #include "ppapi/proxy/interface_proxy.h" |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 15 | #include "ppapi/shared_impl/resource.h" |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 16 | #include "ppapi/thunk/ppb_buffer_api.h" |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 17 | |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 18 | namespace ppapi { |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 19 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 20 | class HostResource; |
21 | |||||
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 22 | namespace proxy { |
23 | |||||
[email protected] | eb5960da | 2013-01-16 23:23:53 | [diff] [blame] | 24 | class SerializedHandle; |
25 | |||||
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 26 | class Buffer : public thunk::PPB_Buffer_API, public Resource { |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 27 | public: |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 28 | Buffer(const HostResource& resource, |
Matthew Cary | fc3757f | 2019-07-30 21:32:46 | [diff] [blame] | 29 | base::UnsafeSharedMemoryRegion shm_handle); |
Peter Boström | 3d5b3cb | 2021-09-23 21:35:45 | [diff] [blame^] | 30 | |
31 | Buffer(const Buffer&) = delete; | ||||
32 | Buffer& operator=(const Buffer&) = delete; | ||||
33 | |||||
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 34 | ~Buffer() override; |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 35 | |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 36 | // Resource overrides. |
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 37 | thunk::PPB_Buffer_API* AsPPB_Buffer_API() override; |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 38 | |
39 | // PPB_Buffer_API implementation. | ||||
nick | e478443 | 2015-04-23 14:01:48 | [diff] [blame] | 40 | PP_Bool Describe(uint32_t* size_in_bytes) override; |
41 | PP_Bool IsMapped() override; | ||||
42 | void* Map() override; | ||||
43 | void Unmap() override; | ||||
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 44 | |
[email protected] | e3da4e80 | 2013-03-23 23:50:49 | [diff] [blame] | 45 | // Trusted |
Matthew Cary | fc3757f | 2019-07-30 21:32:46 | [diff] [blame] | 46 | int32_t GetSharedMemory(base::UnsafeSharedMemoryRegion** shm) override; |
[email protected] | e3da4e80 | 2013-03-23 23:50:49 | [diff] [blame] | 47 | |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 48 | private: |
Matthew Cary | fc3757f | 2019-07-30 21:32:46 | [diff] [blame] | 49 | base::UnsafeSharedMemoryRegion shm_; |
50 | base::WritableSharedMemoryMapping mapping_; | ||||
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 51 | int map_count_; |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 52 | }; |
53 | |||||
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 54 | class PPB_Buffer_Proxy : public InterfaceProxy { |
55 | public: | ||||
[email protected] | 0a6d5f6 | 2011-11-11 08:04:07 | [diff] [blame] | 56 | explicit PPB_Buffer_Proxy(Dispatcher* dispatcher); |
Lei Zhang | 94f57fe3 | 2017-08-30 23:58:24 | [diff] [blame] | 57 | ~PPB_Buffer_Proxy() override; |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 58 | |
[email protected] | 9815108e | 2011-05-27 21:50:28 | [diff] [blame] | 59 | static PP_Resource CreateProxyResource(PP_Instance instance, |
60 | uint32_t size); | ||||
Matthew Cary | fc3757f | 2019-07-30 21:32:46 | [diff] [blame] | 61 | static PP_Resource AddProxyResource( |
62 | const HostResource& resource, | ||||
63 | base::UnsafeSharedMemoryRegion shm_region); | ||||
[email protected] | 9815108e | 2011-05-27 21:50:28 | [diff] [blame] | 64 | |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 65 | // InterfaceProxy implementation. |
Lei Zhang | 94f57fe3 | 2017-08-30 23:58:24 | [diff] [blame] | 66 | bool OnMessageReceived(const IPC::Message& msg) override; |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 67 | |
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 68 | static const ApiID kApiID = API_ID_PPB_BUFFER; |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 69 | |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 70 | private: |
71 | // Message handlers. | ||||
[email protected] | 859a7f3 | 2011-01-15 03:44:13 | [diff] [blame] | 72 | void OnMsgCreate(PP_Instance instance, |
[email protected] | 867b76d63 | 2010-12-02 00:09:07 | [diff] [blame] | 73 | uint32_t size, |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 74 | HostResource* result_resource, |
[email protected] | 246fc49 | 2012-08-27 20:28:18 | [diff] [blame] | 75 | ppapi::proxy::SerializedHandle* result_shm_handle); |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 76 | }; |
77 | |||||
78 | } // namespace proxy | ||||
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 79 | } // namespace ppapi |
[email protected] | 43a4020 | 2010-11-12 16:25:01 | [diff] [blame] | 80 | |
[email protected] | 0a6d5f6 | 2011-11-11 08:04:07 | [diff] [blame] | 81 | #endif // PPAPI_PROXY_PPB_BUFFER_PROXY_H_ |