Skip to content

Commit

Permalink
Nuke wlr_renderer implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Nov 11, 2022
1 parent 2791466 commit 55ee371
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 106 deletions.
86 changes: 4 additions & 82 deletions src/rendervulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3248,100 +3248,22 @@ bool vulkan_supports_modifiers(void)
return g_device.supportsModifiers();
}

static void texture_destroy( struct wlr_texture *wlr_texture )
{
VulkanWlrTexture_t *tex = (VulkanWlrTexture_t *)wlr_texture;
wlr_buffer_unlock( tex->buf );
delete tex;
}

static const struct wlr_texture_impl texture_impl = {
.destroy = texture_destroy,
};

static uint32_t renderer_get_render_buffer_caps( struct wlr_renderer *renderer )
{
return 0;
}

static void renderer_begin( struct wlr_renderer *renderer, uint32_t width, uint32_t height )
{
abort(); // unreachable
}

static void renderer_end( struct wlr_renderer *renderer )
{
abort(); // unreachable
}

static void renderer_clear( struct wlr_renderer *renderer, const float color[4] )
{
abort(); // unreachable
}

static void renderer_scissor( struct wlr_renderer *renderer, struct wlr_box *box )
{
abort(); // unreachable
}

static bool renderer_render_subtexture_with_matrix( struct wlr_renderer *renderer, struct wlr_texture *texture, const struct wlr_fbox *box, const float matrix[9], float alpha )
{
abort(); // unreachable
}

static void renderer_render_quad_with_matrix( struct wlr_renderer *renderer, const float color[4], const float matrix[9] )
{
abort(); // unreachable
}

static const uint32_t *renderer_get_shm_texture_formats( struct wlr_renderer *wlr_renderer, size_t *len
)
void vulkan_get_shm_formats(const uint32_t **formats, size_t *len)
{
*formats = sampledShmFormats.data();
*len = sampledShmFormats.size();
return sampledShmFormats.data();
}

static const struct wlr_drm_format_set *renderer_get_dmabuf_texture_formats( struct wlr_renderer *wlr_renderer )
const struct wlr_drm_format_set *vulkan_get_dmabuf_texture_formats()
{
return &sampledDRMFormats;
}

static int renderer_get_drm_fd( struct wlr_renderer *wlr_renderer )
int vulkan_get_drm_fd()
{
return g_device.drmRenderFd();
}

static struct wlr_texture *renderer_texture_from_buffer( struct wlr_renderer *wlr_renderer, struct wlr_buffer *buf )
{
VulkanWlrTexture_t *tex = new VulkanWlrTexture_t();
wlr_texture_init( &tex->base, &texture_impl, buf->width, buf->height );
tex->buf = wlr_buffer_lock( buf );
// TODO: check format/modifier
// TODO: if DMA-BUF, try importing it into Vulkan
return &tex->base;
}

static const struct wlr_renderer_impl renderer_impl = {
.begin = renderer_begin,
.end = renderer_end,
.clear = renderer_clear,
.scissor = renderer_scissor,
.render_subtexture_with_matrix = renderer_render_subtexture_with_matrix,
.render_quad_with_matrix = renderer_render_quad_with_matrix,
.get_shm_texture_formats = renderer_get_shm_texture_formats,
.get_dmabuf_texture_formats = renderer_get_dmabuf_texture_formats,
.get_drm_fd = renderer_get_drm_fd,
.get_render_buffer_caps = renderer_get_render_buffer_caps,
.texture_from_buffer = renderer_texture_from_buffer,
};

struct wlr_renderer *vulkan_renderer_create( void )
{
VulkanRenderer_t *renderer = new VulkanRenderer_t();
wlr_renderer_init(&renderer->base, &renderer_impl);
return &renderer->base;
}

std::shared_ptr<CVulkanTexture> vulkan_create_texture_from_wlr_buffer( struct wlr_buffer *buf )
{

Expand Down
15 changes: 3 additions & 12 deletions src/rendervulkan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,6 @@ extern "C" {
#include <vulkan/vulkan.h>
#include <drm_fourcc.h>

struct VulkanRenderer_t
{
struct wlr_renderer base;
};

struct VulkanWlrTexture_t
{
struct wlr_texture base;
struct wlr_buffer *buf;
};

class CVulkanTexture
{
public:
Expand Down Expand Up @@ -242,4 +231,6 @@ bool acquire_next_image( void );
bool vulkan_primary_dev_id(dev_t *id);
bool vulkan_supports_modifiers(void);

struct wlr_renderer *vulkan_renderer_create( void );
void vulkan_get_shm_formats(const uint32_t **formats, size_t *len);
const struct wlr_drm_format_set *vulkan_get_dmabuf_texture_formats();
int vulkan_get_drm_fd();
20 changes: 9 additions & 11 deletions src/wlserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ extern "C" {
#include <wlr/backend/libinput.h>
#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_keyboard.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_pointer.h>
#include <wlr/types/wlr_touch.h>
Expand Down Expand Up @@ -119,13 +118,7 @@ void xwayland_surface_role_commit(struct wlr_surface *wlr_surface) {
return;
}

VulkanWlrTexture_t *tex = (VulkanWlrTexture_t *) wlr_surface_get_texture( wlr_surface );
if ( tex == NULL )
{
return;
}

struct wlr_buffer *buf = wlr_buffer_lock( tex->buf );
struct wlr_buffer *buf = wlr_buffer_lock(wlr_surface->current.buffer);

gpuvis_trace_printf( "xwayland_surface_role_commit wlr_surface %p", wlr_surface );

Expand Down Expand Up @@ -838,11 +831,16 @@ bool wlserver_init( void ) {

wlserver.wlr.virtual_keyboard_device = kbd_dev;

wlserver.wlr.renderer = vulkan_renderer_create();
const uint32_t *shm_formats;
size_t shm_formats_len;
vulkan_get_shm_formats(&shm_formats, &shm_formats_len);
wlr_shm_create(wlserver.display, 1, shm_formats, shm_formats_len);

wlr_renderer_init_wl_display(wlserver.wlr.renderer, wlserver.display);
// TODO: use helper to build default feedback
const struct wlr_linux_dmabuf_feedback_v1 *default_feedback = NULL;
wlr_linux_dmabuf_v1_create(wlserver.display, 4, default_feedback);

wlserver.wlr.compositor = wlr_compositor_create(wlserver.display, wlserver.wlr.renderer);
wlserver.wlr.compositor = wlr_compositor_create(wlserver.display, nullptr);

wl_signal_add( &wlserver.wlr.compositor->events.new_surface, &new_surface_listener );

Expand Down
1 change: 0 additions & 1 deletion src/wlserver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ struct wlserver_t {
struct wlr_backend *headless_backend;
struct wlr_backend *libinput_backend;

struct wlr_renderer *renderer;
struct wlr_compositor *compositor;
struct wlr_session *session;
struct wlr_seat *seat;
Expand Down

0 comments on commit 55ee371

Please sign in to comment.