OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_SERVICES_MEDIA_COMMON_CPP_MAPPED_SHARED_BUFFER_H_ | 5 #ifndef MOJO_SERVICES_MEDIA_COMMON_CPP_MAPPED_SHARED_BUFFER_H_ |
6 #define MOJO_SERVICES_MEDIA_COMMON_CPP_MAPPED_SHARED_BUFFER_H_ | 6 #define MOJO_SERVICES_MEDIA_COMMON_CPP_MAPPED_SHARED_BUFFER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "mojo/public/cpp/system/buffer.h" | 10 #include "mojo/public/cpp/system/buffer.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 // Gets the size of the buffer. | 39 // Gets the size of the buffer. |
40 uint64_t size() const; | 40 uint64_t size() const; |
41 | 41 |
42 // Gets a duplicate handle for the shared buffer. | 42 // Gets a duplicate handle for the shared buffer. |
43 ScopedSharedBufferHandle GetDuplicateHandle() const; | 43 ScopedSharedBufferHandle GetDuplicateHandle() const; |
44 | 44 |
45 // Translates an offset into a pointer. | 45 // Translates an offset into a pointer. |
46 void* PtrFromOffset(uint64_t offset) const; | 46 void* PtrFromOffset(uint64_t offset) const; |
47 | 47 |
48 // Translates a pointer into an offset. | 48 // Translates a pointer into an offset. |
49 uint64_t OffsetFromPtr(void *payload_ptr) const; | 49 uint64_t OffsetFromPtr(void* payload_ptr) const; |
50 | 50 |
51 protected: | 51 protected: |
52 void InitInternal(const ScopedSharedBufferHandle& handle); | 52 void InitInternal(const ScopedSharedBufferHandle& handle); |
53 | 53 |
54 // Does nothing. Called when initialization is complete. Subclasses may | 54 // Does nothing. Called when initialization is complete. Subclasses may |
55 // override. | 55 // override. |
56 virtual void OnInit(); | 56 virtual void OnInit(); |
57 | 57 |
58 private: | 58 private: |
59 struct MappedBufferDeleter { | 59 struct MappedBufferDeleter { |
60 inline void operator()(uint8_t* ptr) const { | 60 inline void operator()(uint8_t* ptr) const { UnmapBuffer(ptr); } |
61 UnmapBuffer(ptr); | |
62 } | |
63 }; | 61 }; |
64 | 62 |
65 // Size of the shared buffer. | 63 // Size of the shared buffer. |
66 uint64_t size_; | 64 uint64_t size_; |
67 | 65 |
68 // Shared buffer when initialized with InitNew. | 66 // Shared buffer when initialized with InitNew. |
69 std::unique_ptr<SharedBuffer> buffer_; | 67 std::unique_ptr<SharedBuffer> buffer_; |
70 | 68 |
71 // Handle to shared buffer when initialized with InitFromHandle. | 69 // Handle to shared buffer when initialized with InitFromHandle. |
72 ScopedSharedBufferHandle handle_; | 70 ScopedSharedBufferHandle handle_; |
73 | 71 |
74 // Pointer to the mapped buffer. | 72 // Pointer to the mapped buffer. |
75 std::unique_ptr<uint8_t, MappedBufferDeleter> buffer_ptr_; | 73 std::unique_ptr<uint8_t, MappedBufferDeleter> buffer_ptr_; |
76 }; | 74 }; |
77 | 75 |
78 } // namespace media | 76 } // namespace media |
79 } // namespace mojo | 77 } // namespace mojo |
80 | 78 |
81 #endif // MOJO_SERVICES_MEDIA_COMMON_CPP_MAPPED_SHARED_BUFFER_H_ | 79 #endif // MOJO_SERVICES_MEDIA_COMMON_CPP_MAPPED_SHARED_BUFFER_H_ |
OLD | NEW |