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

Unified Diff: content/common/gpu/media/shared_memory_region.cc

Issue 1541353002: Add offset support to BitstreamBuffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handle the offset with a helper class Created 5 years 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 side-by-side diff with in-line comments
Download patch
Index: content/common/gpu/media/shared_memory_region.cc
diff --git a/content/common/gpu/media/shared_memory_region.cc b/content/common/gpu/media/shared_memory_region.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5dc0b369690ba04170ffcf6a82e34b62c118aefe
--- /dev/null
+++ b/content/common/gpu/media/shared_memory_region.cc
@@ -0,0 +1,35 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/sys_info.h"
+#include "content/common/gpu/media/shared_memory_region.h"
+
+namespace content {
+
+SharedMemoryRegion::SharedMemoryRegion(const base::SharedMemoryHandle& handle,
+ off_t offset,
+ size_t size,
+ bool read_only)
+ : shm_(handle, read_only), offset_(offset), size_(size) {}
+
+SharedMemoryRegion::SharedMemoryRegion(
+ const media::BitstreamBuffer& bitstream_buffer,
+ bool read_only)
+ : SharedMemoryRegion(bitstream_buffer.handle(),
+ bitstream_buffer.offset(),
+ bitstream_buffer.size(),
+ read_only) {}
+
+bool SharedMemoryRegion::Map() {
+ 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.
+ 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.
+}
+
+void* SharedMemoryRegion::memory() {
+ off_t mask = base::SysInfo::VMAllocationGranularity() - 1;
+ int8_t* addr = reinterpret_cast<int8_t*>(shm_.memory());
+ return addr ? addr + (offset_ & mask) : nullptr;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698