somebar/src/shm_buffer.hpp

26 lines
585 B
C++
Raw Normal View History

2021-10-20 20:20:27 +02:00
// somebar - dwl bar
// See LICENSE file for copyright and license details.
#pragma once
#include <array>
#include <wayland-client.h>
// double buffered shm
// format is must be 32-bit
class ShmBuffer {
struct Buf {
2021-10-20 21:09:19 +02:00
uint8_t *data {nullptr};
2021-10-20 20:20:27 +02:00
wl_buffer *buffer {nullptr};
};
std::array<Buf, 2> _buffers;
int _current {0};
size_t _totalSize {0};
public:
int width, height, stride;
explicit ShmBuffer(int width, int height, wl_shm_format format);
2021-10-20 21:09:19 +02:00
uint8_t* data() const;
2021-10-20 20:20:27 +02:00
wl_buffer* buffer() const;
void flip();
~ShmBuffer();
};