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

Side by Side Diff: mojo/services/media/common/cpp/mapped_shared_buffer.cc

Issue 1822333002: Motown: wholesale clang-format (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: dalesat 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
(...skipping 19 matching lines...) Expand all
30 InitInternal(handle_); 30 InitInternal(handle_);
31 } 31 }
32 32
33 void MappedSharedBuffer::InitInternal(const ScopedSharedBufferHandle& handle) { 33 void MappedSharedBuffer::InitInternal(const ScopedSharedBufferHandle& handle) {
34 MOJO_DCHECK(handle.is_valid()); 34 MOJO_DCHECK(handle.is_valid());
35 35
36 // Query the buffer for its size. 36 // Query the buffer for its size.
37 // TODO(johngro) : It would be nice if we could do something other than 37 // TODO(johngro) : It would be nice if we could do something other than
38 // DCHECK if things don't go exactly our way. 38 // DCHECK if things don't go exactly our way.
39 MojoBufferInformation info; 39 MojoBufferInformation info;
40 MojoResult res = MojoGetBufferInformation(handle.get().value(), 40 MojoResult res =
41 &info, 41 MojoGetBufferInformation(handle.get().value(), &info, sizeof(info));
42 sizeof(info));
43 uint64_t size = info.num_bytes; 42 uint64_t size = info.num_bytes;
44 MOJO_DCHECK(res == MOJO_RESULT_OK); 43 MOJO_DCHECK(res == MOJO_RESULT_OK);
45 MOJO_DCHECK(size > 0); 44 MOJO_DCHECK(size > 0);
46 45
47 size_ = size; 46 size_ = size;
48 buffer_ptr_.reset(); 47 buffer_ptr_.reset();
49 48
50 void* ptr; 49 void* ptr;
51 auto result = MapBuffer( 50 auto result = MapBuffer(handle.get(),
52 handle.get(), 51 0, // offset
53 0, // offset 52 size, &ptr, MOJO_MAP_BUFFER_FLAG_NONE);
54 size,
55 &ptr,
56 MOJO_MAP_BUFFER_FLAG_NONE);
57 MOJO_DCHECK(result == MOJO_RESULT_OK); 53 MOJO_DCHECK(result == MOJO_RESULT_OK);
58 MOJO_DCHECK(ptr); 54 MOJO_DCHECK(ptr);
59 55
60 buffer_ptr_.reset(reinterpret_cast<uint8_t*>(ptr)); 56 buffer_ptr_.reset(reinterpret_cast<uint8_t*>(ptr));
61 57
62 OnInit(); 58 OnInit();
63 } 59 }
64 60
65 bool MappedSharedBuffer::initialized() const { 61 bool MappedSharedBuffer::initialized() const {
66 return buffer_ptr_ != nullptr; 62 return buffer_ptr_ != nullptr;
(...skipping 19 matching lines...) Expand all
86 MOJO_DCHECK(buffer_ptr_); 82 MOJO_DCHECK(buffer_ptr_);
87 83
88 if (offset == FifoAllocator::kNullOffset) { 84 if (offset == FifoAllocator::kNullOffset) {
89 return nullptr; 85 return nullptr;
90 } 86 }
91 87
92 MOJO_DCHECK(offset < size_); 88 MOJO_DCHECK(offset < size_);
93 return buffer_ptr_.get() + offset; 89 return buffer_ptr_.get() + offset;
94 } 90 }
95 91
96 uint64_t MappedSharedBuffer::OffsetFromPtr(void *ptr) const { 92 uint64_t MappedSharedBuffer::OffsetFromPtr(void* ptr) const {
97 MOJO_DCHECK(buffer_ptr_); 93 MOJO_DCHECK(buffer_ptr_);
98 if (ptr == nullptr) { 94 if (ptr == nullptr) {
99 return FifoAllocator::kNullOffset; 95 return FifoAllocator::kNullOffset;
100 } 96 }
101 uint64_t offset = reinterpret_cast<uint8_t*>(ptr) - buffer_ptr_.get(); 97 uint64_t offset = reinterpret_cast<uint8_t*>(ptr) - buffer_ptr_.get();
102 MOJO_DCHECK(offset < size_); 98 MOJO_DCHECK(offset < size_);
103 return offset; 99 return offset;
104 } 100 }
105 101
106 void MappedSharedBuffer::OnInit() {} 102 void MappedSharedBuffer::OnInit() {}
107 103
108 } // namespace media 104 } // namespace media
109 } // namespace mojo 105 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/media/common/cpp/mapped_shared_buffer.h ('k') | mojo/services/media/common/cpp/shared_media_buffer_allocator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698