blob: 13b606c3286734c4ad04723fd5248239b27143f1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gpu/command_buffer/common/buffer.h"
#include <stddef.h>
#include <stdint.h>
#include "base/format_macros.h"
#include "base/logging.h"
#include "base/numerics/safe_math.h"
#include "base/strings/stringprintf.h"
namespace gpu {
bool BufferBacking::is_shared() const {
return false;
}
SharedMemoryBufferBacking::SharedMemoryBufferBacking(
std::unique_ptr<base::SharedMemory> shared_memory,
size_t size)
: shared_memory_(std::move(shared_memory)), size_(size) {}
SharedMemoryBufferBacking::~SharedMemoryBufferBacking() {}
bool SharedMemoryBufferBacking::is_shared() const {
return true;
}
void* SharedMemoryBufferBacking::GetMemory() const {
return shared_memory_->memory();
}
size_t SharedMemoryBufferBacking::GetSize() const { return size_; }
Buffer::Buffer(std::unique_ptr<BufferBacking> backing)
: backing_(std::move(backing)),
memory_(backing_->GetMemory()),
size_(backing_->GetSize()) {
DCHECK(memory_) << "The memory must be mapped to create a Buffer";
}
Buffer::~Buffer() {}
void* Buffer::GetDataAddress(uint32_t data_offset, uint32_t data_size) const {
base::CheckedNumeric<uint32_t> end = data_offset;
end += data_size;
if (!end.IsValid() || end.ValueOrDie() > static_cast<uint32_t>(size_))
return NULL;
return static_cast<uint8_t*>(memory_) + data_offset;
}
void* Buffer::GetDataAddressAndSize(uint32_t data_offset,
uint32_t* data_size) const {
if (data_offset > static_cast<uint32_t>(size_))
return NULL;
*data_size = GetRemainingSize(data_offset);
return static_cast<uint8_t*>(memory_) + data_offset;
}
uint32_t Buffer::GetRemainingSize(uint32_t data_offset) const {
if (data_offset > static_cast<uint32_t>(size_))
return 0;
return static_cast<uint32_t>(size_) - data_offset;
}
base::trace_event::MemoryAllocatorDumpGuid GetBufferGUIDForTracing(
uint64_t tracing_process_id,
int32_t buffer_id) {
return base::trace_event::MemoryAllocatorDumpGuid(base::StringPrintf(
"gpu-buffer-x-process/%" PRIx64 "/%d", tracing_process_id, buffer_id));
}
} // namespace gpu
|