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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm
#pragma once
#include "libvideostitch/input.hpp"
#include "gpu/buffer.hpp"
#include "gpu/hostBuffer.hpp"
namespace VideoStitch {
namespace Core {
class Buffer {
public:
explicit Buffer(GPU::HostBuffer<unsigned char> host) : host(host), device(), address(Host), initialized(true) {}
explicit Buffer(GPU::Buffer<unsigned char> device) : host(), device(device), address(Device), initialized(true) {}
Buffer() : host(), device(), address(), initialized(false) {}
bool operator==(const Buffer& o) const {
if (initialized != o.initialized) {
return false;
}
if (!initialized) {
return true;
}
if (address != o.address) {
return false;
}
switch (address) {
case Host:
return host == o.host;
case Device:
return device == o.device;
}
assert(false);
return false;
}
AddressSpace addressSpace() const { return address; }
GPU::HostBuffer<unsigned char> hostBuffer() const {
assert(address == Host);
return host;
}
GPU::Buffer<unsigned char> deviceBuffer() const {
assert(address == Device);
return device;
}
void release() {
if (!initialized) {
return;
}
switch (address) {
case Host:
host.release();
break;
case Device:
device.release();
break;
}
}
unsigned char* rawPtr() const {
if (!initialized) {
return nullptr;
}
switch (address) {
case Host:
return hostBuffer().hostPtr();
case Device:
return (unsigned char*)deviceBuffer().devicePtr();
}
assert(false);
return nullptr;
}
private:
GPU::HostBuffer<unsigned char> host;
GPU::Buffer<unsigned char> device;
AddressSpace address;
bool initialized;
};
} // namespace Core
} // namespace VideoStitch