OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_COMMON_GPU_MEDIA_SHARED_MEMORY_REGION_H_ |
| 6 #define CONTENT_COMMON_GPU_MEDIA_SHARED_MEMORY_REGION_H_ |
| 7 |
| 8 #include "base/memory/shared_memory.h" |
| 9 #include "media/base/bitstream_buffer.h" |
| 10 |
| 11 namespace content { |
| 12 |
| 13 // Helper class to access a region of a SharedMemory. Different from |
| 14 // SharedMemory, in which the |offset| of function MapAt() must be aligned to |
| 15 // the value of |SysInfo::VMAllocationGranularity()|, the |offset| of a |
| 16 // SharedMemoryRegion needs not to be aligned, this class hides the details |
| 17 // and returns the mapped address of the given offset. |
| 18 class SharedMemoryRegion { |
| 19 public: |
| 20 // Creates a SharedMemoryRegion. |
| 21 // The mapped memory region begins at |offset| bytes from the start of the |
| 22 // shared memory and the length is |size|. It will take the ownership of |
| 23 // the |handle| and release the resource when being destroyed. Different |
| 24 // from SharedMemory, the |offset| needs not to be aligned to the value of |
| 25 // |SysInfo::VMAllocationGranularity()|. |
| 26 SharedMemoryRegion(const base::SharedMemoryHandle& handle, |
| 27 off_t offset, |
| 28 size_t size, |
| 29 bool read_only); |
| 30 |
| 31 // Creates a SharedMemoryRegion from the given |bistream_buffer|. |
| 32 SharedMemoryRegion(const media::BitstreamBuffer& bitstream_buffer, |
| 33 bool read_only); |
| 34 |
| 35 // Maps the shared memory into the caller's address space. |
| 36 // Return true on success, false otherwise. |
| 37 bool Map(); |
| 38 |
| 39 // Gets a pointer to the mapped region if it has been mapped via Map(). |
| 40 // Returns |nullptr| if it is not mapped. The returned pointer points |
| 41 // to the memory at the offset previously passed to the constructor. |
| 42 void* memory(); |
| 43 |
| 44 size_t size() const { return size_; } |
| 45 |
| 46 private: |
| 47 base::SharedMemory shm_; |
| 48 off_t offset_; |
| 49 size_t size_; |
| 50 size_t alignment_size_; |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(SharedMemoryRegion); |
| 53 }; |
| 54 |
| 55 } // namespace content |
| 56 |
| 57 #endif // CONTENT_COMMON_GPU_MEDIA_SHARED_MEMORY_REGION_H_ |
OLD | NEW |