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