1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
/* ========================================================================= */
/**
* @file gfxbuf.h
*
* @copyright
* Copyright 2023 Google LLC
*
* 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.
*/
#ifndef __WLMTK_GFXBUF_H__
#define __WLMTK_GFXBUF_H__
#include <cairo.h>
#include <libbase/libbase.h>
#define WLR_USE_UNSTABLE
#include <wlr/types/wlr_buffer.h>
#undef WLR_USE_UNSTABLE
struct wlr_buffer;
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
/**
* Creates a wlroots buffer tied to a libbase graphics buffer.
*
* This creates a libbase graphics buffer, and wraps it as `struct wlr_buffer`.
*
* @param width
* @param height
*
* @return A struct wlr_buffer. Must be released using wlr_buffer_drop().
*/
struct wlr_buffer *bs_gfxbuf_create_wlr_buffer(
unsigned width,
unsigned height);
/**
* Drops a WLR buffer, and sets the pointer to NULL.
*
* @param wlr_buffer_ptr_ptr Points to a pointer to a WLR buffer. The pointer
* to the WLR buffer may be NULL; in that case, the
* call is a no-op.
*/
void wlr_buffer_drop_nullify(struct wlr_buffer **wlr_buffer_ptr_ptr);
/**
* Returns the libbase graphics buffer for the `struct wlr_buffer`.
*
* @param wlr_buffer_ptr Pointer to a `struct wlr_buffer`. Must be a
* `wlr_buffer` that was previously created by
* @ref bs_gfxbuf_create_wlr_buffer.
*
* @return Pointer to the libbase graphics buffer. The `wlr_buffer_ptr` must
* outlive the `bs_gfxbuf_t*`. Must not be destroyed.
*/
bs_gfxbuf_t *bs_gfxbuf_from_wlr_buffer(struct wlr_buffer *wlr_buffer_ptr);
/**
* Returns a `cairo_t` for the WLR buffer backed by a libbase graphics buffer.
*
* @param wlr_buffer_ptr Pointer to a `struct wlr_buffer`. Must be a
* `wlr_buffer` that was previously created by
* @ref bs_gfxbuf_create_wlr_buffer.
*
* @return Pointer to the the cairo. The `wlr_buffer_ptr` must outlive the
* `cairo_t*`. It must be destroyed using `cairo_destroy`.
*/
cairo_t *cairo_create_from_wlr_buffer(struct wlr_buffer *wlr_buffer_ptr);
#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
#endif /* __WLMTK_GFXBUF_H__ */
/* == End of gfxbuf.h ====================================================== */
|