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 #include "base/sys_info.h" | |
6 #include "content/common/gpu/media/shared_memory_region.h" | |
7 | |
8 namespace content { | |
9 | |
10 SharedMemoryRegion::SharedMemoryRegion(const base::SharedMemoryHandle& handle, | |
11 off_t offset, | |
12 size_t size, | |
13 bool read_only) | |
14 : shm_(handle, read_only), offset_(offset), size_(size) {} | |
15 | |
16 SharedMemoryRegion::SharedMemoryRegion( | |
17 const media::BitstreamBuffer& bitstream_buffer, | |
18 bool read_only) | |
19 : SharedMemoryRegion(bitstream_buffer.handle(), | |
20 bitstream_buffer.offset(), | |
21 bitstream_buffer.size(), | |
22 read_only) {} | |
23 | |
24 bool SharedMemoryRegion::Map() { | |
25 off_t mask = base::SysInfo::VMAllocationGranularity() - 1; | |
Pawel Osciak
2015/12/31 02:05:53
This assumes granularity is a power of 2 (which no
Owen Lin
2016/01/04 08:54:17
Done.
| |
26 return shm_.MapAt((offset_ & ~mask), size_ + (offset_ & mask)); | |
Pawel Osciak
2015/12/31 02:05:53
Perhaps we could calculate new offset here (or eve
Owen Lin
2016/01/04 08:54:17
Done.
| |
27 } | |
28 | |
29 void* SharedMemoryRegion::memory() { | |
30 off_t mask = base::SysInfo::VMAllocationGranularity() - 1; | |
31 int8_t* addr = reinterpret_cast<int8_t*>(shm_.memory()); | |
32 return addr ? addr + (offset_ & mask) : nullptr; | |
33 } | |
34 | |
35 } // namespace content | |
OLD | NEW |