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. |
| 14 class SharedMemoryRegion { |
| 15 public: |
| 16 // Creates a SharedMemoryRegion. |
| 17 // The mapped memory region begins at |offset| bytes from the start of the |
| 18 // shared memory and the length is |size|. It will take the ownership of |
| 19 // the |handle| and release the resource when being destroyed. |
| 20 SharedMemoryRegion(const base::SharedMemoryHandle& handle, |
| 21 off_t offset, |
| 22 size_t size, |
| 23 bool read_only); |
| 24 |
| 25 // Creates a SharedMemoryRegion from the given |bistream_buffer|. |
| 26 SharedMemoryRegion(const media::BitstreamBuffer& bitstream_buffer, |
| 27 bool read_only); |
| 28 |
| 29 // Maps the shared memory into the caller's address space. |
| 30 // Return true on success, false otherwise. |
| 31 bool Map(); |
| 32 |
| 33 // Gets a pointer to the mapped region if it has been mapped via Map(). |
| 34 // Returns |nullptr| if it is not mapped. The returned pointer points |
| 35 // to the memory at the offset previously passed to the constructor. |
| 36 void* memory(); |
| 37 |
| 38 size_t size() const { return size_; } |
| 39 |
| 40 private: |
| 41 base::SharedMemory shm_; |
| 42 off_t offset_; |
| 43 size_t size_; |
| 44 size_t alignment_size_; |
| 45 |
| 46 DISALLOW_COPY_AND_ASSIGN(SharedMemoryRegion); |
| 47 }; |
| 48 |
| 49 } // namespace content |
| 50 |
| 51 #endif // CONTENT_COMMON_GPU_MEDIA_SHARED_MEMORY_REGION_H_ |
OLD | NEW |