-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpu.h
89 lines (73 loc) · 2.62 KB
/
gpu.h
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
/*
* Copyright (C) 2022 Mikhail Burakov. This file is part of framesconv.
*
* framesconv is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* framesconv is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with framesconv. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef FRAMESCONV_GPU_H_
#define FRAMESCONV_GPU_H_
#include <EGL/egl.h>
#include <GLES3/gl31.h>
#include <gbm.h>
#include <cstddef>
#include <istream>
#include <memory>
#include <ostream>
#include <string>
#include "utils.h"
class GbmBuffer {
public:
GbmBuffer(gbm_device* device, std::size_t width, std::size_t height);
void FillFrom(std::istream& stream) const;
void DrainTo(std::ostream& stream) const;
EGLImage CreateEglImage(EGLDisplay display) const;
private:
std::size_t width_{};
std::size_t height_{};
std::unique_ptr<gbm_bo, decltype(&gbm_bo_destroy)> bo_{nullptr,
&gbm_bo_destroy};
std::unique_ptr<std::nullptr_t, FdCloser> fd_;
};
class GbmDevice {
public:
explicit GbmDevice(const char* render_node);
GbmBuffer CreateGbmBuffer(std::size_t width, std::size_t height) const;
private:
std::unique_ptr<std::nullptr_t, FdCloser> fd_;
std::unique_ptr<gbm_device, decltype(&gbm_device_destroy)> device_{
nullptr, &gbm_device_destroy};
};
class EglContext {
public:
EglContext(EGLint major_version, EGLint minor_version);
~EglContext();
EglContext(const EglContext&) = delete;
EglContext(EglContext&& other) = delete;
EglContext& operator=(const EglContext&) = delete;
EglContext& operator=(EglContext&& other) = delete;
EGLDisplay GetDisplay() const { return display_; }
void MakeCurrent() const;
void ResetCurrent() const;
void Sync() const;
private:
EGLDisplay display_;
EGLContext context_;
};
std::string WrapEglError(const std::string& message,
EGLint error = eglGetError());
std::string WrapGlError(const std::string& message,
GLenum error = glGetError());
GLuint CreateGlTexture(GLenum target, EGLImage image);
GLuint CreateGlProgram(const char* source);
GLuint CreateGlProgram(const char* source_vertex, const char* source_fragment);
#endif // FRAMESCONV_GPU_H_