blob: f6927dd0f2945f217a4d729caa6f733be6eb6fd7 (
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
|
// somebar - dwl bar
// See LICENSE file for copyright and license details.
#pragma once
#include <array>
#include <sys/mman.h>
#include <wayland-client.h>
#include "common.hpp"
class MemoryMapping {
void* _ptr {nullptr};
size_t _size {0};
public:
MemoryMapping() { }
explicit MemoryMapping(void* ptr, size_t size) : _ptr(ptr), _size(size) { }
MemoryMapping(const MemoryMapping&) = delete;
MemoryMapping(MemoryMapping&& other) { swap(other); }
MemoryMapping& operator=(const MemoryMapping& other) = delete;
MemoryMapping& operator=(MemoryMapping&& other) { swap(other); return *this; }
~MemoryMapping() { if (_ptr) munmap(_ptr, _size); }
void swap(MemoryMapping &other) {
using std::swap;
swap(_ptr, other._ptr);
swap(_size, other._size);
}
};
// double buffered shm
// format is must be 32-bit
class ShmBuffer {
struct Buf {
uint8_t* data {nullptr};
wl_unique_ptr<wl_buffer> buffer;
};
std::array<Buf, 2> _buffers;
int _current {0};
MemoryMapping _mapping;
public:
const uint32_t width, height, stride;
explicit ShmBuffer(int width, int height, wl_shm_format format);
uint8_t* data();
wl_buffer* buffer();
void flip();
};
|