test.c
/* test.c */ #include <stdio.h> #include <stdlib.h> #include <wlr/render/allocator.h> #include <wlr/render/drm_format_set.h> #include <wlr/types/wlr_buffer.h> #include <wlr/util/log.h> #include <drm/drm_fourcc.h> #include "rdprail.h" static int mock_open_pool(GfxRedirServerContext *ctx, GFXREDIR_OPEN_POOL_PDU *open_pool) { open_pool->poolId = 1; // Assign a mock pool ID return 0; } static int mock_create_buffer(GfxRedirServerContext *ctx, GFXREDIR_CREATE_BUFFER_PDU *create_buffer) { create_buffer->bufferId = 1; // Assign a mock buffer ID return 0; } int main() { wlr_log_init(WLR_DEBUG, NULL); // Create mock RDP context GfxRedirServerContext mock_ctx = { .OpenPool = mock_open_pool, .CreateBuffer = mock_create_buffer }; // Create allocator struct wlr_allocator *alloc = wlr_rdp_allocator_create(&mock_ctx); if (!alloc) { fprintf(stderr, "Failed to create allocator\n"); return 1; } // Create buffer struct wlr_drm_format format = { .format = DRM_FORMAT_ARGB8888, .len = 1, }; struct wlr_buffer *buffer = wlr_allocator_create_buffer(alloc, 640, 480, &format); if (!buffer) { fprintf(stderr, "Failed to create buffer\n"); wlr_allocator_destroy(alloc); return 1; } // Get buffer data void *data; uint32_t buffer_format; size_t stride; if (wlr_buffer_begin_data_ptr_access(buffer, WLR_BUFFER_DATA_PTR_ACCESS_WRITE, &data, &buffer_format, &stride)) { uint32_t *pixels = data; for (int i = 0; i < (640 * 480); i++) { pixels[i] = 0xFF0000FF; // Fill with red } wlr_buffer_end_data_ptr_access(buffer); printf("Buffer filled with red\n"); } // Cleanup wlr_buffer_drop(buffer); wlr_allocator_destroy(alloc); return 0; }
Leave a Comment