[common] rects: implement routine to copy rectangles from framebuffer

This commit is contained in:
Quantum 2021-08-06 23:58:26 -04:00 committed by Geoffrey McRae
parent cab95c5eed
commit 0462cee9db
4 changed files with 41 additions and 1 deletions

View File

@ -61,6 +61,12 @@ void framebuffer_prepare(FrameBuffer * frame);
*/ */
bool framebuffer_write(FrameBuffer * frame, const void * src, size_t size); bool framebuffer_write(FrameBuffer * frame, const void * src, size_t size);
/**
* Gets the underlying data buffer of the framebuffer.
* For custom read routines only.
*/
const uint8_t * framebuffer_get_buffer(const FrameBuffer * frame);
/** /**
* Gets the underlying data buffer of the framebuffer. * Gets the underlying data buffer of the framebuffer.
* For custom write routines only. * For custom write routines only.

View File

@ -42,4 +42,8 @@ void rectsBufferToFramebuffer(FrameDamageRect * rects, int count,
FrameBuffer * frame, int dstStride, int height, FrameBuffer * frame, int dstStride, int height,
const uint8_t * src, int srcStride); const uint8_t * src, int srcStride);
void rectsFramebufferToBuffer(FrameDamageRect * rects, int count,
uint8_t * dst, int dstStride, int height,
const FrameBuffer * frame, int srcStride);
#endif #endif

View File

@ -214,6 +214,11 @@ bool framebuffer_write(FrameBuffer * frame, const void * restrict src, size_t si
return true; return true;
} }
const uint8_t * framebuffer_get_buffer(const FrameBuffer * frame)
{
return frame->data;
}
uint8_t * framebuffer_get_data(FrameBuffer * frame) uint8_t * framebuffer_get_data(FrameBuffer * frame)
{ {
return frame->data; return frame->data;

View File

@ -50,6 +50,7 @@ static int cornerCompare(const void * a_, const void * b_)
inline static void rectsBufferCopy(FrameDamageRect * rects, int count, inline static void rectsBufferCopy(FrameDamageRect * rects, int count,
uint8_t * dst, int dstStride, int height, uint8_t * dst, int dstStride, int height,
const uint8_t * src, int srcStride, void * opaque, const uint8_t * src, int srcStride, void * opaque,
void (*rowCopyStart)(int y, void * opaque),
void (*rowCopyFinish)(int y, void * opaque)) void (*rowCopyFinish)(int y, void * opaque))
{ {
const int cornerCount = 4 * count; const int cornerCount = 4 * count;
@ -99,6 +100,9 @@ inline static void rectsBufferCopy(FrameDamageRect * rects, int count,
change[changes++] = (struct Edge) { .x = x, .delta = delta }; change[changes++] = (struct Edge) { .x = x, .delta = delta };
} }
if (rowCopyStart)
rowCopyStart(y, opaque);
struct Edge * active = active_[activeRow]; struct Edge * active = active_[activeRow];
int x1 = 0; int x1 = 0;
int in_rect = 0; int in_rect = 0;
@ -169,6 +173,27 @@ void rectsBufferToFramebuffer(FrameDamageRect * rects, int count,
{ {
struct ToFramebufferData data = { .frame = frame, .stride = dstStride }; struct ToFramebufferData data = { .frame = frame, .stride = dstStride };
rectsBufferCopy(rects, count, framebuffer_get_data(frame), dstStride, height, rectsBufferCopy(rects, count, framebuffer_get_data(frame), dstStride, height,
src, srcStride, &data, fbRowFinish); src, srcStride, &data, NULL, fbRowFinish);
framebuffer_set_write_ptr(frame, height * dstStride); framebuffer_set_write_ptr(frame, height * dstStride);
} }
struct FromFramebufferData
{
const FrameBuffer * frame;
int stride;
};
static void fbRowStart(int y, void * opaque)
{
struct FromFramebufferData * data = opaque;
framebuffer_wait(data->frame, y * data->stride);
}
void rectsFramebufferToBuffer(FrameDamageRect * rects, int count,
uint8_t * dst, int dstStride, int height,
const FrameBuffer * frame, int srcStride)
{
struct FromFramebufferData data = { .frame = frame, .stride = srcStride };
rectsBufferCopy(rects, count, dst, dstStride, height,
framebuffer_get_buffer(frame), srcStride, &data, fbRowStart, NULL);
}