| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |