wlmaker
Loading...
Searching...
No Matches
dblbuf.c File Reference
#include "dblbuf.h"
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <libbase/libbase.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
#include <wayland-client-protocol.h>
Include dependency graph for dblbuf.c:

Classes

struct  wlcl_buffer_t
struct  _wlcl_dblbuf_t

Macros

#define _WLCL_DBLBUF_NUM   2

Functions

static void _wlcl_dblbuf_callback_if_ready (wlcl_dblbuf_t *dblbuf_ptr)
static void _wlcl_dblbuf_handle_frame_done (void *data_ptr, struct wl_callback *callback, uint32_t time)
static bool _wlcl_dblbuf_create_buffer (wlcl_buffer_t *buffer_ptr, wlcl_dblbuf_t *dblbuf_ptr, struct wl_shm_pool *wl_shm_pool_ptr, unsigned page, unsigned width, unsigned height)
static void _wlcl_dblbuf_handle_wl_buffer_release (void *data_ptr, struct wl_buffer *wl_buffer_ptr)
static int _wlcl_dblbuf_shm_create (const char *app_id_ptr, size_t size)
wlcl_dblbuf_twlcl_dblbuf_create (const char *app_id_ptr, struct wl_surface *wl_surface_ptr, struct wl_shm *wl_shm_ptr, unsigned width, unsigned height)
void wlcl_dblbuf_destroy (wlcl_dblbuf_t *dblbuf_ptr)
void wlcl_dblbuf_register_ready_callback (wlcl_dblbuf_t *dblbuf_ptr, wlcl_dblbuf_ready_callback_t callback, void *callback_ud_ptr)

Variables

static const uint32_t SHM_OPEN_RETRIES = 256
static const struct wl_buffer_listener _wlcl_dblbuf_wl_buffer_listener
static const struct wl_callback_listener _wlcl_dblbuf_frame_listener

Detailed Description

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Macro Definition Documentation

◆ _WLCL_DBLBUF_NUM

#define _WLCL_DBLBUF_NUM   2

How many buffers to hold for the double buffer: Two.

Function Documentation

◆ _wlcl_dblbuf_callback_if_ready()

void _wlcl_dblbuf_callback_if_ready ( wlcl_dblbuf_t * dblbuf_ptr)
static

Calls wlcl_dblbuf_t::callback, if it is registered, a frame is due, and if there are available buffers. If so, and if the callback returns true, the corresponding buffer will be attached to the surface and the surface is committed.

Parameters
dblbuf_ptr

◆ _wlcl_dblbuf_create_buffer()

bool _wlcl_dblbuf_create_buffer ( wlcl_buffer_t * buffer_ptr,
wlcl_dblbuf_t * dblbuf_ptr,
struct wl_shm_pool * wl_shm_pool_ptr,
unsigned page,
unsigned width,
unsigned height )
static

Helper: Creates a struct wl_buffer from the wl_shm_pool_ptr at given dimensions and page number, and stores all into buffer_ptr.

Parameters
buffer_ptr
dblbuf_ptr
wl_shm_pool_ptr
page
width
height
Returns
true on success.

◆ _wlcl_dblbuf_handle_frame_done()

void _wlcl_dblbuf_handle_frame_done ( void * data_ptr,
struct wl_callback * callback,
uint32_t time )
static

Callback for when the compositor indicates a frame is due.

◆ _wlcl_dblbuf_handle_wl_buffer_release()

void _wlcl_dblbuf_handle_wl_buffer_release ( void * data_ptr,
struct wl_buffer * wl_buffer_ptr )
static

Handles the release notification of the wl_buffer interface.

Parameters
data_ptr
wl_buffer_ptr

◆ _wlcl_dblbuf_shm_create()

int _wlcl_dblbuf_shm_create ( const char * app_id_ptr,
size_t size )
static

Creates a POSIX shared memory object and allocates size bytes to it.

Parameters
app_id_ptr
size
Returns
The file descriptor (a non-negative integer) on success, or -1 on failure. The file descriptor must be closed with close(2).

◆ wlcl_dblbuf_create()

wlcl_dblbuf_t * wlcl_dblbuf_create ( const char * app_id_ptr,
struct wl_surface * wl_surface_ptr,
struct wl_shm * wl_shm_ptr,
unsigned width,
unsigned height )

Creates a double buffer for the surface with provided dimensions.

Parameters
app_id_ptr
wl_surface_ptr
wl_shm_ptr
width
height
Returns
Pointer to state of the double buffer, or NULL on error. Call wlcl_dblbuf_destroy for freeing up the associated resources.

◆ wlcl_dblbuf_destroy()

void wlcl_dblbuf_destroy ( wlcl_dblbuf_t * dblbuf_ptr)

Destroys the double buffer.

◆ wlcl_dblbuf_register_ready_callback()

void wlcl_dblbuf_register_ready_callback ( wlcl_dblbuf_t * dblbuf_ptr,
wlcl_dblbuf_ready_callback_t callback,
void * callback_ud_ptr )

Registers a callback for when a frame can be drawn into the buffer.

The frame can be drawn if (1) it is due, and (2) there is a back buffer available ("released") for drawing into. If these conditions hold true, callback will be called right away. Otherwise, it will be called once these conditions are fulfilled.

The callback will be called only once. If the client wishes further notifications, they must call wlcl_dblbuf_register_ready_callback again.

The callback must be registered only after the surface is ready. Eg. for an XDG toplevel, after it has received & acknowledged configure.

Parameters
dblbuf_ptr
callbackThe callback function, or NULL to clear the callback.
callback_ud_ptrArgument to use for callback.

Variable Documentation

◆ _wlcl_dblbuf_frame_listener

const struct wl_callback_listener _wlcl_dblbuf_frame_listener
static
Initial value:
= {
}
static void _wlcl_dblbuf_handle_frame_done(void *data_ptr, struct wl_callback *callback, uint32_t time)
Definition dblbuf.c:261

Listener implementation for the frame.

◆ _wlcl_dblbuf_wl_buffer_listener

const struct wl_buffer_listener _wlcl_dblbuf_wl_buffer_listener
static
Initial value:
= {
}
static void _wlcl_dblbuf_handle_wl_buffer_release(void *data_ptr, struct wl_buffer *wl_buffer_ptr)
Definition dblbuf.c:333

Listener implementation for the wl_buffer.

◆ SHM_OPEN_RETRIES

const uint32_t SHM_OPEN_RETRIES = 256
static

How many attempts to try shm_open before giving up.