Chromium Code Reviews| 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 base::CheckedNumeric<uint32_t> offset = data_offset; | |
| 49 if (!offset.IsValid() || offset.ValueOrDie() > static_cast<uint32_t>(size_)) | |
| 50 return NULL; | |
|
Zhenyao Mo
2016/05/25 20:05:49
I don't really understand why this is necessary (a
Geoff Lang
2016/05/25 20:44:30
Removed the checks, probably a result of an initia
| |
| 51 *data_size = GetRemainingSize(data_offset); | |
| 52 return static_cast<uint8_t*>(memory_) + data_offset; | |
| 53 } | |
| 54 | |
| 55 uint32_t Buffer::GetRemainingSize(uint32_t data_offset) const { | |
| 56 base::CheckedNumeric<uint32_t> offset = data_offset; | |
| 57 if (!offset.IsValid() || offset.ValueOrDie() > static_cast<uint32_t>(size_)) | |
| 58 return 0; | |
| 59 return static_cast<uint32_t>(size_) - data_offset; | |
| 60 } | |
| 61 | |
| 46 base::trace_event::MemoryAllocatorDumpGuid GetBufferGUIDForTracing( | 62 base::trace_event::MemoryAllocatorDumpGuid GetBufferGUIDForTracing( |
| 47 uint64_t tracing_process_id, | 63 uint64_t tracing_process_id, |
| 48 int32_t buffer_id) { | 64 int32_t buffer_id) { |
| 49 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf( | 65 return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf( |
| 50 "gpu-buffer-x-process/%" PRIx64 "/%d", tracing_process_id, buffer_id)); | 66 "gpu-buffer-x-process/%" PRIx64 "/%d", tracing_process_id, buffer_id)); |
| 51 } | 67 } |
| 52 | 68 |
| 53 } // namespace gpu | 69 } // namespace gpu |
| OLD | NEW |