Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gbm/main/gbm.c
4564 views
1
/*
2
* Copyright © 2011 Intel Corporation
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
13
* Software.
14
*
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
* DEALINGS IN THE SOFTWARE.
23
*
24
* Authors:
25
* Benjamin Franzke <[email protected]>
26
*/
27
28
#include <stddef.h>
29
#include <stdio.h>
30
#include <stdlib.h>
31
#include <string.h>
32
#include <stdint.h>
33
34
#ifdef MAJOR_IN_MKDEV
35
#include <sys/mkdev.h>
36
#endif
37
#ifdef MAJOR_IN_SYSMACROS
38
#include <sys/sysmacros.h>
39
#endif
40
#include <sys/stat.h>
41
#include <unistd.h>
42
#include <errno.h>
43
44
#include "gbm.h"
45
#include "gbmint.h"
46
#include "backend.h"
47
48
/** Returns the file description for the gbm device
49
*
50
* \return The fd that the struct gbm_device was created with
51
*/
52
GBM_EXPORT int
53
gbm_device_get_fd(struct gbm_device *gbm)
54
{
55
return gbm->v0.fd;
56
}
57
58
/** Get the backend name for the given gbm device
59
*
60
* \return The backend name string - this belongs to the device and must not
61
* be freed
62
*/
63
GBM_EXPORT const char *
64
gbm_device_get_backend_name(struct gbm_device *gbm)
65
{
66
return gbm->v0.name;
67
}
68
69
/** Test if a format is supported for a given set of usage flags.
70
*
71
* \param gbm The created buffer manager
72
* \param format The format to test
73
* \param usage A bitmask of the usages to test the format against
74
* \return 1 if the format is supported otherwise 0
75
*
76
* \sa enum gbm_bo_flags for the list of flags that the format can be
77
* tested against
78
*
79
* \sa enum gbm_bo_format for the list of formats
80
*/
81
GBM_EXPORT int
82
gbm_device_is_format_supported(struct gbm_device *gbm,
83
uint32_t format, uint32_t usage)
84
{
85
return gbm->v0.is_format_supported(gbm, format, usage);
86
}
87
88
/** Get the number of planes that are required for a given format+modifier
89
*
90
* \param gbm The gbm device returned from gbm_create_device()
91
* \param format The format to query
92
* \param modifier The modifier to query
93
*/
94
GBM_EXPORT int
95
gbm_device_get_format_modifier_plane_count(struct gbm_device *gbm,
96
uint32_t format,
97
uint64_t modifier)
98
{
99
return gbm->v0.get_format_modifier_plane_count(gbm, format, modifier);
100
}
101
102
/** Destroy the gbm device and free all resources associated with it.
103
*
104
* \param gbm The device created using gbm_create_device()
105
*/
106
GBM_EXPORT void
107
gbm_device_destroy(struct gbm_device *gbm)
108
{
109
_gbm_device_destroy(gbm);
110
}
111
112
/** Create a gbm device for allocating buffers
113
*
114
* The file descriptor passed in is used by the backend to communicate with
115
* platform for allocating the memory. For allocations using DRI this would be
116
* the file descriptor returned when opening a device such as \c
117
* /dev/dri/card0
118
*
119
* \param fd The file descriptor for a backend specific device
120
* \return The newly created struct gbm_device. The resources associated with
121
* the device should be freed with gbm_device_destroy() when it is no longer
122
* needed. If the creation of the device failed NULL will be returned.
123
*/
124
GBM_EXPORT struct gbm_device *
125
gbm_create_device(int fd)
126
{
127
struct gbm_device *gbm = NULL;
128
struct stat buf;
129
130
if (fd < 0 || fstat(fd, &buf) < 0 || !S_ISCHR(buf.st_mode)) {
131
errno = EINVAL;
132
return NULL;
133
}
134
135
gbm = _gbm_create_device(fd);
136
if (gbm == NULL)
137
return NULL;
138
139
gbm->dummy = gbm_create_device;
140
141
return gbm;
142
}
143
144
/** Get the width of the buffer object
145
*
146
* \param bo The buffer object
147
* \return The width of the allocated buffer object
148
*
149
*/
150
GBM_EXPORT uint32_t
151
gbm_bo_get_width(struct gbm_bo *bo)
152
{
153
return bo->v0.width;
154
}
155
156
/** Get the height of the buffer object
157
*
158
* \param bo The buffer object
159
* \return The height of the allocated buffer object
160
*/
161
GBM_EXPORT uint32_t
162
gbm_bo_get_height(struct gbm_bo *bo)
163
{
164
return bo->v0.height;
165
}
166
167
/** Get the stride of the buffer object
168
*
169
* This is calculated by the backend when it does the allocation in
170
* gbm_bo_create()
171
*
172
* \param bo The buffer object
173
* \return The stride of the allocated buffer object in bytes
174
*/
175
GBM_EXPORT uint32_t
176
gbm_bo_get_stride(struct gbm_bo *bo)
177
{
178
return gbm_bo_get_stride_for_plane(bo, 0);
179
}
180
181
/** Get the stride for the given plane
182
*
183
* \param bo The buffer object
184
* \param plane for which you want the stride
185
*
186
* \sa gbm_bo_get_stride()
187
*/
188
GBM_EXPORT uint32_t
189
gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane)
190
{
191
return bo->gbm->v0.bo_get_stride(bo, plane);
192
}
193
194
/** Get the format of the buffer object
195
*
196
* The format of the pixels in the buffer.
197
*
198
* \param bo The buffer object
199
* \return The format of buffer object, one of the GBM_FORMAT_* codes
200
*/
201
GBM_EXPORT uint32_t
202
gbm_bo_get_format(struct gbm_bo *bo)
203
{
204
return bo->v0.format;
205
}
206
207
/** Get the bit-per-pixel of the buffer object's format
208
*
209
* The bits-per-pixel of the buffer object's format.
210
*
211
* Note; The 'in-memory pixel' concept makes no sense for YUV formats
212
* (pixels are the result of the combination of multiple memory sources:
213
* Y, Cb & Cr; usually these are even in separate buffers), so YUV
214
* formats are not supported by this function.
215
*
216
* \param bo The buffer object
217
* \return The number of bits0per-pixel of the buffer object's format.
218
*/
219
GBM_EXPORT uint32_t
220
gbm_bo_get_bpp(struct gbm_bo *bo)
221
{
222
switch (bo->v0.format) {
223
default:
224
return 0;
225
case GBM_FORMAT_C8:
226
case GBM_FORMAT_R8:
227
case GBM_FORMAT_RGB332:
228
case GBM_FORMAT_BGR233:
229
return 8;
230
case GBM_FORMAT_GR88:
231
case GBM_FORMAT_XRGB4444:
232
case GBM_FORMAT_XBGR4444:
233
case GBM_FORMAT_RGBX4444:
234
case GBM_FORMAT_BGRX4444:
235
case GBM_FORMAT_ARGB4444:
236
case GBM_FORMAT_ABGR4444:
237
case GBM_FORMAT_RGBA4444:
238
case GBM_FORMAT_BGRA4444:
239
case GBM_FORMAT_XRGB1555:
240
case GBM_FORMAT_XBGR1555:
241
case GBM_FORMAT_RGBX5551:
242
case GBM_FORMAT_BGRX5551:
243
case GBM_FORMAT_ARGB1555:
244
case GBM_FORMAT_ABGR1555:
245
case GBM_FORMAT_RGBA5551:
246
case GBM_FORMAT_BGRA5551:
247
case GBM_FORMAT_RGB565:
248
case GBM_FORMAT_BGR565:
249
return 16;
250
case GBM_FORMAT_RGB888:
251
case GBM_FORMAT_BGR888:
252
return 24;
253
case GBM_FORMAT_XRGB8888:
254
case GBM_FORMAT_XBGR8888:
255
case GBM_FORMAT_RGBX8888:
256
case GBM_FORMAT_BGRX8888:
257
case GBM_FORMAT_ARGB8888:
258
case GBM_FORMAT_ABGR8888:
259
case GBM_FORMAT_RGBA8888:
260
case GBM_FORMAT_BGRA8888:
261
case GBM_FORMAT_XRGB2101010:
262
case GBM_FORMAT_XBGR2101010:
263
case GBM_FORMAT_RGBX1010102:
264
case GBM_FORMAT_BGRX1010102:
265
case GBM_FORMAT_ARGB2101010:
266
case GBM_FORMAT_ABGR2101010:
267
case GBM_FORMAT_RGBA1010102:
268
case GBM_FORMAT_BGRA1010102:
269
return 32;
270
case GBM_FORMAT_XBGR16161616F:
271
case GBM_FORMAT_ABGR16161616F:
272
return 64;
273
}
274
}
275
276
/** Get the offset for the data of the specified plane
277
*
278
* Extra planes, and even the first plane, may have an offset from the start of
279
* the buffer object. This function will provide the offset for the given plane
280
* to be used in various KMS APIs.
281
*
282
* \param bo The buffer object
283
* \return The offset
284
*/
285
GBM_EXPORT uint32_t
286
gbm_bo_get_offset(struct gbm_bo *bo, int plane)
287
{
288
return bo->gbm->v0.bo_get_offset(bo, plane);
289
}
290
291
/** Get the gbm device used to create the buffer object
292
*
293
* \param bo The buffer object
294
* \return Returns the gbm device with which the buffer object was created
295
*/
296
GBM_EXPORT struct gbm_device *
297
gbm_bo_get_device(struct gbm_bo *bo)
298
{
299
return bo->gbm;
300
}
301
302
/** Get the handle of the buffer object
303
*
304
* This is stored in the platform generic union gbm_bo_handle type. However
305
* the format of this handle is platform specific.
306
*
307
* \param bo The buffer object
308
* \return Returns the handle of the allocated buffer object
309
*/
310
GBM_EXPORT union gbm_bo_handle
311
gbm_bo_get_handle(struct gbm_bo *bo)
312
{
313
return bo->v0.handle;
314
}
315
316
/** Get a DMA-BUF file descriptor for the buffer object
317
*
318
* This function creates a DMA-BUF (also known as PRIME) file descriptor
319
* handle for the buffer object. Each call to gbm_bo_get_fd() returns a new
320
* file descriptor and the caller is responsible for closing the file
321
* descriptor.
322
323
* \param bo The buffer object
324
* \return Returns a file descriptor referring to the underlying buffer or -1
325
* if an error occurs.
326
*/
327
GBM_EXPORT int
328
gbm_bo_get_fd(struct gbm_bo *bo)
329
{
330
return bo->gbm->v0.bo_get_fd(bo);
331
}
332
333
/** Get the number of planes for the given bo.
334
*
335
* \param bo The buffer object
336
* \return The number of planes
337
*/
338
GBM_EXPORT int
339
gbm_bo_get_plane_count(struct gbm_bo *bo)
340
{
341
return bo->gbm->v0.bo_get_planes(bo);
342
}
343
344
/** Get the handle for the specified plane of the buffer object
345
*
346
* This function gets the handle for any plane associated with the BO. When
347
* dealing with multi-planar formats, or formats which might have implicit
348
* planes based on different underlying hardware it is necessary for the client
349
* to be able to get this information to pass to the DRM.
350
*
351
* \param bo The buffer object
352
* \param plane the plane to get a handle for
353
*
354
* \sa gbm_bo_get_handle()
355
*/
356
GBM_EXPORT union gbm_bo_handle
357
gbm_bo_get_handle_for_plane(struct gbm_bo *bo, int plane)
358
{
359
return bo->gbm->v0.bo_get_handle(bo, plane);
360
}
361
362
/** Get a DMA-BUF file descriptor for the specified plane of the buffer object
363
*
364
* This function creates a DMA-BUF (also known as PRIME) file descriptor
365
* handle for the specified plane of the buffer object. Each call to
366
* gbm_bo_get_fd_for_plane() returns a new file descriptor and the caller is
367
* responsible for closing the file descriptor.
368
369
* \param bo The buffer object
370
* \param plane The plane to get a DMA-BUF for
371
* \return Returns a file descriptor referring to the underlying buffer or -1
372
* if an error occurs.
373
*
374
* \sa gbm_bo_get_fd()
375
*/
376
GBM_EXPORT int
377
gbm_bo_get_fd_for_plane(struct gbm_bo *bo, int plane)
378
{
379
return bo->gbm->v0.bo_get_plane_fd(bo, plane);
380
}
381
382
/**
383
* Get the chosen modifier for the buffer object
384
*
385
* This function returns the modifier that was chosen for the object. These
386
* properties may be generic, or platform/implementation dependent.
387
*
388
* \param bo The buffer object
389
* \return Returns the selected modifier (chosen by the implementation) for the
390
* BO.
391
* \sa gbm_bo_create_with_modifiers() where possible modifiers are set
392
* \sa gbm_surface_create_with_modifiers() where possible modifiers are set
393
* \sa define DRM_FORMAT_MOD_* in drm_fourcc.h for possible modifiers
394
*/
395
GBM_EXPORT uint64_t
396
gbm_bo_get_modifier(struct gbm_bo *bo)
397
{
398
return bo->gbm->v0.bo_get_modifier(bo);
399
}
400
401
/** Write data into the buffer object
402
*
403
* If the buffer object was created with the GBM_BO_USE_WRITE flag,
404
* this function can be used to write data into the buffer object. The
405
* data is copied directly into the object and it's the responsibility
406
* of the caller to make sure the data represents valid pixel data,
407
* according to the width, height, stride and format of the buffer object.
408
*
409
* \param bo The buffer object
410
* \param buf The data to write
411
* \param count The number of bytes to write
412
* \return Returns 0 on success, otherwise -1 is returned an errno set
413
*/
414
GBM_EXPORT int
415
gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count)
416
{
417
return bo->gbm->v0.bo_write(bo, buf, count);
418
}
419
420
/** Set the user data associated with a buffer object
421
*
422
* \param bo The buffer object
423
* \param data The data to associate to the buffer object
424
* \param destroy_user_data A callback (which may be %NULL) that will be
425
* called prior to the buffer destruction
426
*/
427
GBM_EXPORT void
428
gbm_bo_set_user_data(struct gbm_bo *bo, void *data,
429
void (*destroy_user_data)(struct gbm_bo *, void *))
430
{
431
bo->v0.user_data = data;
432
bo->v0.destroy_user_data = destroy_user_data;
433
}
434
435
/** Get the user data associated with a buffer object
436
*
437
* \param bo The buffer object
438
* \return Returns the user data associated with the buffer object or %NULL
439
* if no data was associated with it
440
*
441
* \sa gbm_bo_set_user_data()
442
*/
443
GBM_EXPORT void *
444
gbm_bo_get_user_data(struct gbm_bo *bo)
445
{
446
return bo->v0.user_data;
447
}
448
449
/**
450
* Destroys the given buffer object and frees all resources associated with
451
* it.
452
*
453
* \param bo The buffer object
454
*/
455
GBM_EXPORT void
456
gbm_bo_destroy(struct gbm_bo *bo)
457
{
458
if (bo->v0.destroy_user_data)
459
bo->v0.destroy_user_data(bo, bo->v0.user_data);
460
461
bo->gbm->v0.bo_destroy(bo);
462
}
463
464
/**
465
* Allocate a buffer object for the given dimensions
466
*
467
* \param gbm The gbm device returned from gbm_create_device()
468
* \param width The width for the buffer
469
* \param height The height for the buffer
470
* \param format The format to use for the buffer, from GBM_FORMAT_* or
471
* GBM_BO_FORMAT_* tokens
472
* \param usage The union of the usage flags for this buffer
473
*
474
* \return A newly allocated buffer that should be freed with gbm_bo_destroy()
475
* when no longer needed. If an error occurs during allocation %NULL will be
476
* returned and errno set.
477
*
478
* \sa enum gbm_bo_flags for the list of usage flags
479
*/
480
GBM_EXPORT struct gbm_bo *
481
gbm_bo_create(struct gbm_device *gbm,
482
uint32_t width, uint32_t height,
483
uint32_t format, uint32_t usage)
484
{
485
if (width == 0 || height == 0) {
486
errno = EINVAL;
487
return NULL;
488
}
489
490
return gbm->v0.bo_create(gbm, width, height, format, usage, NULL, 0);
491
}
492
493
GBM_EXPORT struct gbm_bo *
494
gbm_bo_create_with_modifiers(struct gbm_device *gbm,
495
uint32_t width, uint32_t height,
496
uint32_t format,
497
const uint64_t *modifiers,
498
const unsigned int count)
499
{
500
if (width == 0 || height == 0) {
501
errno = EINVAL;
502
return NULL;
503
}
504
505
if ((count && !modifiers) || (modifiers && !count)) {
506
errno = EINVAL;
507
return NULL;
508
}
509
510
return gbm->v0.bo_create(gbm, width, height, format, 0, modifiers, count);
511
}
512
513
/**
514
* Create a gbm buffer object from a foreign object
515
*
516
* This function imports a foreign object and creates a new gbm bo for it.
517
* This enables using the foreign object with a display API such as KMS.
518
* Currently these types of foreign objects are supported, indicated by the type
519
* argument:
520
*
521
* GBM_BO_IMPORT_WL_BUFFER
522
* GBM_BO_IMPORT_EGL_IMAGE
523
* GBM_BO_IMPORT_FD
524
* GBM_BO_IMPORT_FD_MODIFIER
525
*
526
* The gbm bo shares the underlying pixels but its life-time is
527
* independent of the foreign object.
528
*
529
* \param gbm The gbm device returned from gbm_create_device()
530
* \param type The type of object we're importing
531
* \param buffer Pointer to the external object
532
* \param usage The union of the usage flags for this buffer
533
*
534
* \return A newly allocated buffer object that should be freed with
535
* gbm_bo_destroy() when no longer needed. On error, %NULL is returned
536
* and errno is set.
537
*
538
* \sa enum gbm_bo_flags for the list of usage flags
539
*/
540
GBM_EXPORT struct gbm_bo *
541
gbm_bo_import(struct gbm_device *gbm,
542
uint32_t type, void *buffer, uint32_t usage)
543
{
544
return gbm->v0.bo_import(gbm, type, buffer, usage);
545
}
546
547
/**
548
* Map a region of a gbm buffer object for cpu access
549
*
550
* This function maps a region of a gbm bo for cpu read and/or write
551
* access.
552
*
553
* The mapping exposes a linear view of the buffer object even if the buffer
554
* has a non-linear modifier.
555
*
556
* This function may require intermediate buffer copies (ie. it may be slow).
557
*
558
* \param bo The buffer object
559
* \param x The X (top left origin) starting position of the mapped region for
560
* the buffer
561
* \param y The Y (top left origin) starting position of the mapped region for
562
* the buffer
563
* \param width The width of the mapped region for the buffer
564
* \param height The height of the mapped region for the buffer
565
* \param flags The union of the GBM_BO_TRANSFER_* flags for this buffer
566
* \param stride Ptr for returned stride in bytes of the mapped region
567
* \param map_data Returned opaque ptr for the mapped region
568
*
569
* \return Address of the mapped buffer that should be unmapped with
570
* gbm_bo_unmap() when no longer needed. On error, %NULL is returned
571
* and errno is set.
572
*
573
* \sa enum gbm_bo_transfer_flags for the list of flags
574
*/
575
GBM_EXPORT void *
576
gbm_bo_map(struct gbm_bo *bo,
577
uint32_t x, uint32_t y,
578
uint32_t width, uint32_t height,
579
uint32_t flags, uint32_t *stride, void **map_data)
580
{
581
if (!bo || width == 0 || height == 0 || !stride || !map_data) {
582
errno = EINVAL;
583
return NULL;
584
}
585
586
return bo->gbm->v0.bo_map(bo, x, y, width, height,
587
flags, stride, map_data);
588
}
589
590
/**
591
* Unmap a previously mapped region of a gbm buffer object
592
*
593
* This function unmaps a region of a gbm bo for cpu read and/or write
594
* access.
595
*
596
* \param bo The buffer object
597
* \param map_data opaque ptr returned from prior gbm_bo_map
598
*/
599
GBM_EXPORT void
600
gbm_bo_unmap(struct gbm_bo *bo, void *map_data)
601
{
602
bo->gbm->v0.bo_unmap(bo, map_data);
603
}
604
605
/**
606
* Allocate a surface object
607
*
608
* \param gbm The gbm device returned from gbm_create_device()
609
* \param width The width for the surface
610
* \param height The height for the surface
611
* \param format The format to use for the surface
612
*
613
* \return A newly allocated surface that should be freed with
614
* gbm_surface_destroy() when no longer needed. If an error occurs
615
* during allocation %NULL will be returned.
616
*
617
* \sa enum gbm_bo_format for the list of formats
618
*/
619
GBM_EXPORT struct gbm_surface *
620
gbm_surface_create(struct gbm_device *gbm,
621
uint32_t width, uint32_t height,
622
uint32_t format, uint32_t flags)
623
{
624
return gbm->v0.surface_create(gbm, width, height, format, flags, NULL, 0);
625
}
626
627
GBM_EXPORT struct gbm_surface *
628
gbm_surface_create_with_modifiers(struct gbm_device *gbm,
629
uint32_t width, uint32_t height,
630
uint32_t format,
631
const uint64_t *modifiers,
632
const unsigned int count)
633
{
634
if ((count && !modifiers) || (modifiers && !count)) {
635
errno = EINVAL;
636
return NULL;
637
}
638
639
return gbm->v0.surface_create(gbm, width, height, format, 0,
640
modifiers, count);
641
}
642
643
/**
644
* Destroys the given surface and frees all resources associated with
645
* it.
646
*
647
* All buffers locked with gbm_surface_lock_front_buffer() should be
648
* released prior to calling this function.
649
*
650
* \param surf The surface
651
*/
652
GBM_EXPORT void
653
gbm_surface_destroy(struct gbm_surface *surf)
654
{
655
surf->gbm->v0.surface_destroy(surf);
656
}
657
658
/**
659
* Lock the surface's current front buffer
660
*
661
* Lock rendering to the surface's current front buffer until it is
662
* released with gbm_surface_release_buffer().
663
*
664
* This function must be called exactly once after calling
665
* eglSwapBuffers. Calling it before any eglSwapBuffer has happened
666
* on the surface or two or more times after eglSwapBuffers is an
667
* error. A new bo representing the new front buffer is returned. On
668
* multiple invocations, all the returned bos must be released in
669
* order to release the actual surface buffer.
670
*
671
* \param surf The surface
672
*
673
* \return A buffer object that should be released with
674
* gbm_surface_release_buffer() when no longer needed. The implementation
675
* is free to reuse buffers released with gbm_surface_release_buffer() so
676
* this bo should not be destroyed using gbm_bo_destroy(). If an error
677
* occurs this function returns %NULL.
678
*/
679
GBM_EXPORT struct gbm_bo *
680
gbm_surface_lock_front_buffer(struct gbm_surface *surf)
681
{
682
return surf->gbm->v0.surface_lock_front_buffer(surf);
683
}
684
685
/**
686
* Release a locked buffer obtained with gbm_surface_lock_front_buffer()
687
*
688
* Returns the underlying buffer to the gbm surface. Releasing a bo
689
* will typically make gbm_surface_has_free_buffer() return 1 and thus
690
* allow rendering the next frame, but not always. The implementation
691
* may choose to destroy the bo immediately or reuse it, in which case
692
* the user data associated with it is unchanged.
693
*
694
* \param surf The surface
695
* \param bo The buffer object
696
*/
697
GBM_EXPORT void
698
gbm_surface_release_buffer(struct gbm_surface *surf, struct gbm_bo *bo)
699
{
700
surf->gbm->v0.surface_release_buffer(surf, bo);
701
}
702
703
/**
704
* Return whether or not a surface has free (non-locked) buffers
705
*
706
* Before starting a new frame, the surface must have a buffer
707
* available for rendering. Initially, a gbm surface will have a free
708
* buffer, but after one or more buffers have been locked (\sa
709
* gbm_surface_lock_front_buffer()), the application must check for a
710
* free buffer before rendering.
711
*
712
* If a surface doesn't have a free buffer, the application must
713
* return a buffer to the surface using gbm_surface_release_buffer()
714
* and after that, the application can query for free buffers again.
715
*
716
* \param surf The surface
717
* \return 1 if the surface has free buffers, 0 otherwise
718
*/
719
GBM_EXPORT int
720
gbm_surface_has_free_buffers(struct gbm_surface *surf)
721
{
722
return surf->gbm->v0.surface_has_free_buffers(surf);
723
}
724
725
/* The two GBM_BO_FORMAT_[XA]RGB8888 formats alias the GBM_FORMAT_*
726
* formats of the same name. We want to accept them whenever someone
727
* has a GBM format, but never return them to the user. */
728
static uint32_t
729
format_canonicalize(uint32_t gbm_format)
730
{
731
switch (gbm_format) {
732
case GBM_BO_FORMAT_XRGB8888:
733
return GBM_FORMAT_XRGB8888;
734
case GBM_BO_FORMAT_ARGB8888:
735
return GBM_FORMAT_ARGB8888;
736
default:
737
return gbm_format;
738
}
739
}
740
741
/**
742
* Returns a string representing the fourcc format name.
743
*
744
* \param desc Caller-provided storage for the format name string.
745
* \return String containing the fourcc of the format.
746
*/
747
GBM_EXPORT char *
748
gbm_format_get_name(uint32_t gbm_format, struct gbm_format_name_desc *desc)
749
{
750
gbm_format = format_canonicalize(gbm_format);
751
752
desc->name[0] = gbm_format;
753
desc->name[1] = gbm_format >> 8;
754
desc->name[2] = gbm_format >> 16;
755
desc->name[3] = gbm_format >> 24;
756
desc->name[4] = 0;
757
758
return desc->name;
759
}
760
761
/**
762
* A global table of functions and global variables defined in the core GBM
763
* code that need to be accessed directly by GBM backends.
764
*/
765
struct gbm_core gbm_core = {
766
.v0.core_version = GBM_BACKEND_ABI_VERSION,
767
.v0.format_canonicalize = format_canonicalize,
768
};
769
770