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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/public/cpp/environment/logging.h" 5 #include "mojo/public/cpp/environment/logging.h"
6 #include "mojo/services/media/common/cpp/mapped_shared_buffer.h" 6 #include "mojo/services/media/common/cpp/mapped_shared_buffer.h"
7 7
8 namespace mojo { 8 namespace mojo {
9 namespace media { 9 namespace media {
10 10
11 MappedSharedBuffer::MappedSharedBuffer() {} 11 MappedSharedBuffer::MappedSharedBuffer() {}
12 12
13 MappedSharedBuffer::~MappedSharedBuffer() {} 13 MappedSharedBuffer::~MappedSharedBuffer() {}
14 14
15 void MappedSharedBuffer::InitNew(uint64_t size) { 15 void MappedSharedBuffer::InitNew(uint64_t size) {
16 MOJO_DCHECK(size > 0); 16 MOJO_DCHECK(size > 0);
17 17
18 buffer_.reset(new SharedBuffer(size)); 18 buffer_.reset(new SharedBuffer(size));
19 handle_.reset(); 19 handle_.reset();
20 20
21 InitInternal(buffer_->handle, size); 21 InitInternal(buffer_->handle);
22 } 22 }
23 23
24 void MappedSharedBuffer::InitFromHandle( 24 void MappedSharedBuffer::InitFromHandle(ScopedSharedBufferHandle handle) {
25 ScopedSharedBufferHandle handle,
26 uint64_t size) {
27 MOJO_DCHECK(handle.is_valid()); 25 MOJO_DCHECK(handle.is_valid());
28 MOJO_DCHECK(size > 0);
29 26
30 buffer_.reset(); 27 buffer_.reset();
31 handle_ = handle.Pass(); 28 handle_ = handle.Pass();
32 29
33 InitInternal(handle_, size); 30 InitInternal(handle_);
34 } 31 }
35 32
36 void MappedSharedBuffer::InitInternal( 33 void MappedSharedBuffer::InitInternal(const ScopedSharedBufferHandle& handle) {
37 ScopedSharedBufferHandle& handle,
38 uint64_t size) {
39 MOJO_DCHECK(handle.is_valid()); 34 MOJO_DCHECK(handle.is_valid());
35
36 // Query the buffer for its size.
37 // TODO(johngro) : It would be nice if we could do something other than
38 // DCHECK if things don't go exactly our way.
39 MojoBufferInformation info;
40 MojoResult res = MojoGetBufferInformation(handle.get().value(),
41 &info,
42 sizeof(info));
43 uint64_t size = info.num_bytes;
44 MOJO_DCHECK(res == MOJO_RESULT_OK);
40 MOJO_DCHECK(size > 0); 45 MOJO_DCHECK(size > 0);
41 46
42 size_ = size; 47 size_ = size;
43 buffer_ptr_.reset(); 48 buffer_ptr_.reset();
44 49
45 void* ptr; 50 void* ptr;
46 auto result = MapBuffer( 51 auto result = MapBuffer(
47 handle.get(), 52 handle.get(),
48 0, // offset 53 0, // offset
49 size, 54 size,
50 &ptr, 55 &ptr,
51 MOJO_MAP_BUFFER_FLAG_NONE); 56 MOJO_MAP_BUFFER_FLAG_NONE);
52 MOJO_DCHECK(result == MOJO_RESULT_OK); 57 MOJO_DCHECK(result == MOJO_RESULT_OK);
53 MOJO_DCHECK(ptr); 58 MOJO_DCHECK(ptr);
54 59
55 buffer_ptr_.reset(reinterpret_cast<uint8_t*>(ptr)); 60 buffer_ptr_.reset(reinterpret_cast<uint8_t*>(ptr));
56 61
57 OnInit(); 62 OnInit();
58 } 63 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 if (ptr == nullptr) { 98 if (ptr == nullptr) {
94 return FifoAllocator::kNullOffset; 99 return FifoAllocator::kNullOffset;
95 } 100 }
96 uint64_t offset = reinterpret_cast<uint8_t*>(ptr) - buffer_ptr_.get(); 101 uint64_t offset = reinterpret_cast<uint8_t*>(ptr) - buffer_ptr_.get();
97 MOJO_DCHECK(offset < size_); 102 MOJO_DCHECK(offset < size_);
98 return offset; 103 return offset;
99 } 104 }
100 105
101 void MappedSharedBuffer::OnInit() {} 106 void MappedSharedBuffer::OnInit() {}
102 107
103 } // namespace media 108 } // namespace media
104 } // namespace mojo 109 } // namespace mojo
OLDNEW
« 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