OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "gpu/command_buffer/common/buffer.h" | 5 #include "gpu/command_buffer/common/buffer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 Buffer::~Buffer() {} | 36 Buffer::~Buffer() {} |
37 | 37 |
38 void* Buffer::GetDataAddress(uint32_t data_offset, uint32_t data_size) const { | 38 void* Buffer::GetDataAddress(uint32_t data_offset, uint32_t data_size) const { |
39 base::CheckedNumeric<uint32_t> end = data_offset; | 39 base::CheckedNumeric<uint32_t> end = data_offset; |
40 end += data_size; | 40 end += data_size; |
41 if (!end.IsValid() || end.ValueOrDie() > static_cast<uint32_t>(size_)) | 41 if (!end.IsValid() || end.ValueOrDie() > static_cast<uint32_t>(size_)) |
42 return NULL; | 42 return NULL; |
43 return static_cast<uint8_t*>(memory_) + data_offset; | 43 return static_cast<uint8_t*>(memory_) + data_offset; |
44 } | 44 } |
45 | 45 |
| 46 void* Buffer::GetDataAddressAndSize(uint32_t data_offset, |
| 47 uint32_t* data_size) const { |
| 48 if (data_offset > static_cast<uint32_t>(size_)) |
| 49 return NULL; |
| 50 *data_size = GetRemainingSize(data_offset); |
| 51 return static_cast<uint8_t*>(memory_) + data_offset; |
| 52 } |
| 53 |
| 54 uint32_t Buffer::GetRemainingSize(uint32_t data_offset) const { |
| 55 if (data_offset > static_cast<uint32_t>(size_)) |
| 56 return 0; |
| 57 return static_cast<uint32_t>(size_) - data_offset; |
| 58 } |
| 59 |
46 base::trace_event::MemoryAllocatorDumpGuid GetBufferGUIDForTracing( | 60 base::trace_event::MemoryAllocatorDumpGuid GetBufferGUIDForTracing( |
47 uint64_t tracing_process_id, | 61 uint64_t tracing_process_id, |
48 int32_t buffer_id) { | 62 int32_t buffer_id) { |
49 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf( | 63 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf( |
50 "gpu-buffer-x-process/%" PRIx64 "/%d", tracing_process_id, buffer_id)); | 64 "gpu-buffer-x-process/%" PRIx64 "/%d", tracing_process_id, buffer_id)); |
51 } | 65 } |
52 | 66 |
53 } // namespace gpu | 67 } // namespace gpu |
OLD | NEW |