Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: mojo/services/media/common/cpp/mapped_shared_buffer.h

Issue 1823833003: Take advantage of MojoGetBufferInformation (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebase and fix a type mismatch which the android build caught Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 13 matching lines...) Expand all
24 class MappedSharedBuffer { 24 class MappedSharedBuffer {
25 public: 25 public:
26 MappedSharedBuffer(); 26 MappedSharedBuffer();
27 27
28 virtual ~MappedSharedBuffer(); 28 virtual ~MappedSharedBuffer();
29 29
30 // Initializes by creating a new shared buffer of the indicated size. 30 // Initializes by creating a new shared buffer of the indicated size.
31 void InitNew(uint64_t size); 31 void InitNew(uint64_t size);
32 32
33 // Initializes from a handle to an existing shared buffer. 33 // Initializes from a handle to an existing shared buffer.
34 void InitFromHandle(ScopedSharedBufferHandle handle, uint64_t size); 34 void InitFromHandle(ScopedSharedBufferHandle handle);
35 35
36 // Indicates whether the buffer is initialized. 36 // Indicates whether the buffer is initialized.
37 bool initialized() const; 37 bool initialized() const;
38 38
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(ScopedSharedBufferHandle& handle, uint64_t size); 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 {
61 UnmapBuffer(ptr); 61 UnmapBuffer(ptr);
62 } 62 }
63 }; 63 };
64 64
65 // Size of the shared buffer. 65 // Size of the shared buffer.
66 uint64_t size_; 66 uint64_t size_;
67 67
68 // Shared buffer when initialized with InitNew. 68 // Shared buffer when initialized with InitNew.
69 std::unique_ptr<SharedBuffer> buffer_; 69 std::unique_ptr<SharedBuffer> buffer_;
70 70
71 // Handle to shared buffer when initialized with InitFromHandle. 71 // Handle to shared buffer when initialized with InitFromHandle.
72 ScopedSharedBufferHandle handle_; 72 ScopedSharedBufferHandle handle_;
73 73
74 // Pointer to the mapped buffer. 74 // Pointer to the mapped buffer.
75 std::unique_ptr<uint8_t, MappedBufferDeleter> buffer_ptr_; 75 std::unique_ptr<uint8_t, MappedBufferDeleter> buffer_ptr_;
76 }; 76 };
77 77
78 } // namespace media 78 } // namespace media
79 } // namespace mojo 79 } // namespace mojo
80 80
81 #endif // MOJO_SERVICES_MEDIA_COMMON_CPP_MAPPED_SHARED_BUFFER_H_ 81 #endif // MOJO_SERVICES_MEDIA_COMMON_CPP_MAPPED_SHARED_BUFFER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698