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

Unified Diff: mojo/services/media/common/cpp/mapped_shared_buffer.cc

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 side-by-side diff with in-line comments
Download patch
Index: mojo/services/media/common/cpp/mapped_shared_buffer.cc
diff --git a/mojo/services/media/common/cpp/mapped_shared_buffer.cc b/mojo/services/media/common/cpp/mapped_shared_buffer.cc
index 5d0cb4b6f4ea1dac946a7f74c477c58b522f902c..976858ac6b7ba873ed519ffacd1a3e7749c4ae20 100644
--- a/mojo/services/media/common/cpp/mapped_shared_buffer.cc
+++ b/mojo/services/media/common/cpp/mapped_shared_buffer.cc
@@ -18,25 +18,30 @@ void MappedSharedBuffer::InitNew(uint64_t size) {
buffer_.reset(new SharedBuffer(size));
handle_.reset();
- InitInternal(buffer_->handle, size);
+ InitInternal(buffer_->handle);
}
-void MappedSharedBuffer::InitFromHandle(
- ScopedSharedBufferHandle handle,
- uint64_t size) {
+void MappedSharedBuffer::InitFromHandle(ScopedSharedBufferHandle handle) {
MOJO_DCHECK(handle.is_valid());
- MOJO_DCHECK(size > 0);
buffer_.reset();
handle_ = handle.Pass();
- InitInternal(handle_, size);
+ InitInternal(handle_);
}
-void MappedSharedBuffer::InitInternal(
- ScopedSharedBufferHandle& handle,
- uint64_t size) {
+void MappedSharedBuffer::InitInternal(const ScopedSharedBufferHandle& handle) {
MOJO_DCHECK(handle.is_valid());
+
+ // Query the buffer for its size.
+ // TODO(johngro) : It would be nice if we could do something other than
+ // DCHECK if things don't go exactly our way.
+ MojoBufferInformation info;
+ MojoResult res = MojoGetBufferInformation(handle.get().value(),
+ &info,
+ sizeof(info));
+ uint64_t size = info.num_bytes;
+ MOJO_DCHECK(res == MOJO_RESULT_OK);
MOJO_DCHECK(size > 0);
size_ = size;
@@ -45,7 +50,7 @@ void MappedSharedBuffer::InitInternal(
void* ptr;
auto result = MapBuffer(
handle.get(),
- 0, // offset
+ 0, // offset
size,
&ptr,
MOJO_MAP_BUFFER_FLAG_NONE);
@@ -100,5 +105,5 @@ uint64_t MappedSharedBuffer::OffsetFromPtr(void *ptr) const {
void MappedSharedBuffer::OnInit() {}
-} // namespace media
-} // namespace mojo
+} // namespace media
+} // namespace mojo
« no previous file with comments | « mojo/services/media/common/cpp/mapped_shared_buffer.h ('k') | mojo/services/media/common/interfaces/media_transport.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698