27
27
* DEALINGS IN THE SOFTWARE.
30
#include <cutils/properties.h>
32
30
#include <dirent.h>
36
34
#include <stdbool.h>
37
#include <cutils/properties.h>
38
#include <drm-uapi/drm_fourcc.h>
38
39
#include <sync/sync.h>
39
40
#include <sys/types.h>
40
#include <drm-uapi/drm_fourcc.h>
42
42
#include "util/compiler.h"
43
#include "util/libsync.h"
43
44
#include "util/os_file.h"
44
#include "util/libsync.h"
46
47
#include "loader.h"
48
48
#include "platform_android.h"
50
50
#ifdef HAVE_DRM_GRALLOC
51
#include "gralloc_drm.h"
51
52
#include <gralloc_drm_handle.h>
52
#include "gralloc_drm.h"
53
53
#endif /* HAVE_DRM_GRALLOC */
55
#define ALIGN(val, align) (((val) + (align) - 1) & ~((align) - 1))
55
#define ALIGN(val, align) (((val) + (align)-1) & ~((align)-1))
57
57
enum chroma_order {
73
73
* on native format and information contained in android_ycbcr struct. */
74
74
static const struct droid_yuv_format droid_yuv_formats[] = {
75
75
/* Native format, YCrCb, Chroma step, DRI image FourCC */
76
{ HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 2, DRM_FORMAT_NV12 },
77
{ HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 1, DRM_FORMAT_YUV420 },
78
{ HAL_PIXEL_FORMAT_YCbCr_420_888, YCrCb, 1, DRM_FORMAT_YVU420 },
79
{ HAL_PIXEL_FORMAT_YV12, YCrCb, 1, DRM_FORMAT_YVU420 },
76
{HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 2, DRM_FORMAT_NV12},
77
{HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 1, DRM_FORMAT_YUV420},
78
{HAL_PIXEL_FORMAT_YCbCr_420_888, YCrCb, 1, DRM_FORMAT_YVU420},
79
{HAL_PIXEL_FORMAT_YV12, YCrCb, 1, DRM_FORMAT_YVU420},
80
80
/* HACK: See droid_create_image_from_prime_fds() and
81
81
* https://issuetracker.google.com/32077885. */
82
{ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 2, DRM_FORMAT_NV12 },
83
{ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 1, DRM_FORMAT_YUV420 },
84
{ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_YVU420 },
85
{ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_AYUV },
86
{ HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_XYUV8888 },
82
{HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 2, DRM_FORMAT_NV12},
83
{HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 1, DRM_FORMAT_YUV420},
84
{HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_YVU420},
85
{HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_AYUV},
86
{HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_XYUV8888},
142
143
/* createImageFromFds requires fourcc format */
143
static int get_fourcc(int native)
145
get_fourcc(int native)
145
147
switch (native) {
146
case HAL_PIXEL_FORMAT_RGB_565: return DRM_FORMAT_RGB565;
147
case HAL_PIXEL_FORMAT_BGRA_8888: return DRM_FORMAT_ARGB8888;
148
case HAL_PIXEL_FORMAT_RGBA_8888: return DRM_FORMAT_ABGR8888;
148
case HAL_PIXEL_FORMAT_RGB_565:
149
return DRM_FORMAT_RGB565;
150
case HAL_PIXEL_FORMAT_BGRA_8888:
151
return DRM_FORMAT_ARGB8888;
152
case HAL_PIXEL_FORMAT_RGBA_8888:
153
return DRM_FORMAT_ABGR8888;
149
154
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
151
156
* HACK: Hardcode this to RGBX_8888 as per cros_gralloc hack.
152
* TODO: Remove this once https://issuetracker.google.com/32077885 is fixed.
157
* TODO: Remove this once https://issuetracker.google.com/32077885 is
154
case HAL_PIXEL_FORMAT_RGBX_8888: return DRM_FORMAT_XBGR8888;
155
case HAL_PIXEL_FORMAT_RGBA_FP16: return DRM_FORMAT_ABGR16161616F;
156
case HAL_PIXEL_FORMAT_RGBA_1010102: return DRM_FORMAT_ABGR2101010;
160
case HAL_PIXEL_FORMAT_RGBX_8888:
161
return DRM_FORMAT_XBGR8888;
162
case HAL_PIXEL_FORMAT_RGBA_FP16:
163
return DRM_FORMAT_ABGR16161616F;
164
case HAL_PIXEL_FORMAT_RGBA_1010102:
165
return DRM_FORMAT_ABGR2101010;
158
167
_eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", native);
212
221
memset(&ycbcr, 0, sizeof(ycbcr));
213
ret = dri2_dpy->gralloc->lock_ycbcr(dri2_dpy->gralloc, buf->handle,
214
0, 0, 0, 0, 0, &ycbcr);
222
ret = dri2_dpy->gralloc->lock_ycbcr(dri2_dpy->gralloc, buf->handle, 0, 0, 0,
216
225
/* HACK: See native_window_buffer_get_buffer_info() and
217
226
* https://issuetracker.google.com/32077885.*/
229
238
* values of subsequent pixels, assumed to be the same for Cb and Cr. */
230
239
drm_fourcc = get_fourcc_yuv(buf->format, chroma_order, ycbcr.chroma_step);
231
240
if (drm_fourcc == -1) {
232
_eglLog(_EGL_WARNING, "unsupported YUV format, native = %x, chroma_order = %s, chroma_step = %d",
233
buf->format, chroma_order == YCbCr ? "YCbCr" : "YCrCb", ycbcr.chroma_step);
241
_eglLog(_EGL_WARNING,
242
"unsupported YUV format, native = %x, chroma_order = %s, "
244
buf->format, chroma_order == YCbCr ? "YCbCr" : "YCrCb",
239
251
.height = buf->height,
240
252
.drm_fourcc = drm_fourcc,
241
253
.num_planes = ycbcr.chroma_step == 2 ? 2 : 3,
242
.fds = { -1, -1, -1, -1 },
254
.fds = {-1, -1, -1, -1},
243
255
.modifier = DRM_FORMAT_MOD_INVALID,
244
256
.yuv_color_space = EGL_ITU_REC601_EXT,
245
257
.sample_range = EGL_YUV_NARROW_RANGE_EXT,
337
349
.height = buf->height,
338
350
.drm_fourcc = drm_fourcc,
339
351
.num_planes = num_planes,
340
.fds = { fds[0], -1, -1, -1 },
352
.fds = {fds[0], -1, -1, -1},
341
353
.modifier = DRM_FORMAT_MOD_INVALID,
342
.offsets = { 0, 0, 0, 0 },
343
.pitches = { pitch, 0, 0, 0 },
354
.offsets = {0, 0, 0, 0},
355
.pitches = {pitch, 0, 0, 0},
344
356
.yuv_color_space = EGL_ITU_REC601_EXT,
345
357
.sample_range = EGL_YUV_NARROW_RANGE_EXT,
346
358
.horizontal_siting = EGL_YUV_CHROMA_SITING_0_EXT,
355
367
* offsets and strides. If we have this, we can skip straight to
356
368
* createImageFromDmaBufs2() and avoid all the guessing and recalculations.
357
369
* This also gives us the modifier and plane offsets/strides for multiplanar
358
* compressed buffers (eg Intel CCS buffers) in order to make that work in Android.
370
* compressed buffers (eg Intel CCS buffers) in order to make that work in
361
374
static const char cros_gralloc_module_name[] = "CrOS Gralloc";
363
#define CROS_GRALLOC_DRM_GET_BUFFER_INFO 4
364
#define CROS_GRALLOC_DRM_GET_USAGE 5
376
#define CROS_GRALLOC_DRM_GET_BUFFER_INFO 4
377
#define CROS_GRALLOC_DRM_GET_USAGE 5
365
378
#define CROS_GRALLOC_DRM_GET_USAGE_FRONT_RENDERING_BIT 0x1
367
380
struct cros_gralloc0_buffer_info {
383
396
if (strcmp(dri2_dpy->gralloc->common.name, cros_gralloc_module_name) == 0 &&
384
397
dri2_dpy->gralloc->perform &&
385
398
dri2_dpy->gralloc->perform(dri2_dpy->gralloc,
386
CROS_GRALLOC_DRM_GET_BUFFER_INFO,
387
buf->handle, &info) == 0) {
399
CROS_GRALLOC_DRM_GET_BUFFER_INFO, buf->handle,
388
401
*out_buf_info = (struct buffer_info){
389
402
.width = buf->width,
390
403
.height = buf->height,
391
404
.drm_fourcc = info.drm_fourcc,
392
405
.num_planes = info.num_fds,
393
.fds = { -1, -1, -1, -1 },
406
.fds = {-1, -1, -1, -1},
394
407
.modifier = info.modifier,
395
408
.yuv_color_space = EGL_ITU_REC601_EXT,
396
409
.sample_range = EGL_YUV_NARROW_RANGE_EXT,
423
435
buf_info->drm_fourcc, buf_info->modifier, buf_info->fds,
424
436
buf_info->num_planes, buf_info->pitches, buf_info->offsets,
425
437
buf_info->yuv_color_space, buf_info->sample_range,
426
buf_info->horizontal_siting, buf_info->vertical_siting, &error,
438
buf_info->horizontal_siting, buf_info->vertical_siting, &error, priv);
430
441
return dri2_dpy->image->createImageFromDmaBufs(
597
609
_eglLog(_EGL_DEBUG, "%s: mode=%d", __func__, mode);
599
611
if (ANativeWindow_setSharedBufferMode(window, mode)) {
600
_eglLog(_EGL_WARNING, "failed ANativeWindow_setSharedBufferMode"
601
"(window=%p, mode=%d)", window, mode);
612
_eglLog(_EGL_WARNING,
613
"failed ANativeWindow_setSharedBufferMode"
614
"(window=%p, mode=%d)",
640
655
dri2_surf->in_fence_fd = -1;
642
if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list,
643
true, native_window))
657
if (!dri2_init_surface(&dri2_surf->base, disp, type, conf, attrib_list, true,
644
659
goto cleanup_surface;
646
661
if (type == EGL_WINDOW_BIT) {
667
682
/* Required buffer caching slots. */
668
683
buffer_count = min_undequeued_buffers + 2;
670
dri2_surf->color_buffers = calloc(buffer_count,
671
sizeof(*dri2_surf->color_buffers));
685
dri2_surf->color_buffers =
686
calloc(buffer_count, sizeof(*dri2_surf->color_buffers));
672
687
if (!dri2_surf->color_buffers) {
673
688
_eglError(EGL_BAD_ALLOC, "droid_create_surface");
674
689
goto cleanup_surface;
676
691
dri2_surf->color_buffers_count = buffer_count;
678
693
if (format != dri2_conf->base.NativeVisualID) {
679
_eglLog(_EGL_WARNING, "Native format mismatch: 0x%x != 0x%x",
680
format, dri2_conf->base.NativeVisualID);
694
_eglLog(_EGL_WARNING, "Native format mismatch: 0x%x != 0x%x", format,
695
dri2_conf->base.NativeVisualID);
683
698
ANativeWindow_query(window, ANATIVEWINDOW_QUERY_DEFAULT_WIDTH,
728
743
droid_create_window_surface(_EGLDisplay *disp, _EGLConfig *conf,
729
744
void *native_window, const EGLint *attrib_list)
731
return droid_create_surface(disp, EGL_WINDOW_BIT, conf,
732
native_window, attrib_list);
746
return droid_create_surface(disp, EGL_WINDOW_BIT, conf, native_window,
735
750
static _EGLSurface *
736
751
droid_create_pbuffer_surface(_EGLDisplay *disp, _EGLConfig *conf,
737
752
const EGLint *attrib_list)
739
return droid_create_surface(disp, EGL_PBUFFER_BIT, conf,
754
return droid_create_surface(disp, EGL_PBUFFER_BIT, conf, NULL, attrib_list);
743
757
static EGLBoolean
758
772
if (dri2_surf->dri_image_back) {
759
_eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_back", __func__, __LINE__);
773
_eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_back", __func__,
760
775
dri2_dpy->image->destroyImage(dri2_surf->dri_image_back);
761
776
dri2_surf->dri_image_back = NULL;
764
779
if (dri2_surf->dri_image_front) {
765
_eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_front", __func__, __LINE__);
780
_eglLog(_EGL_DEBUG, "%s : %d : destroy dri_image_front", __func__,
766
782
dri2_dpy->image->destroyImage(dri2_surf->dri_image_front);
767
783
dri2_surf->dri_image_front = NULL;
832
848
* and mesa doesn't have the implementation of this case.
833
849
* Add warning message, but not treat it as error.
835
_eglLog(_EGL_DEBUG, "DRI driver requested unsupported front buffer for window surface");
853
"DRI driver requested unsupported front buffer for window surface");
836
854
} else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
837
dri2_surf->dri_image_front =
838
dri2_dpy->image->createImage(dri2_dpy->dri_screen_render_gpu,
839
dri2_surf->base.Width,
840
dri2_surf->base.Height,
855
dri2_surf->dri_image_front = dri2_dpy->image->createImage(
856
dri2_dpy->dri_screen_render_gpu, dri2_surf->base.Width,
857
dri2_surf->base.Height, format, 0, NULL);
844
858
if (!dri2_surf->dri_image_front) {
845
859
_eglLog(_EGL_WARNING, "dri2_image_front allocation failed");
874
888
handle_in_fence_fd(dri2_surf, dri2_surf->dri_image_back);
876
890
} else if (dri2_surf->base.Type == EGL_PBUFFER_BIT) {
877
/* The EGL 1.5 spec states that pbuffers are single-buffered. Specifically,
878
* the spec states that they have a back buffer but no front buffer, in
879
* contrast to pixmaps, which have a front buffer but no back buffer.
891
/* The EGL 1.5 spec states that pbuffers are single-buffered.
892
* Specifically, the spec states that they have a back buffer but no front
893
* buffer, in contrast to pixmaps, which have a front buffer but no back
881
* Single-buffered surfaces with no front buffer confuse Mesa; so we deviate
882
* from the spec, following the precedent of Mesa's EGL X11 platform. The
883
* X11 platform correctly assigns pbuffers to single-buffered configs, but
884
* assigns the pbuffer a front buffer instead of a back buffer.
896
* Single-buffered surfaces with no front buffer confuse Mesa; so we
897
* deviate from the spec, following the precedent of Mesa's EGL X11
898
* platform. The X11 platform correctly assigns pbuffers to
899
* single-buffered configs, but assigns the pbuffer a front buffer instead
886
902
* Pbuffers in the X11 platform mostly work today, so let's just copy its
887
903
* behavior instead of trying to fix (and hence potentially breaking) the
890
_eglLog(_EGL_DEBUG, "DRI driver requested unsupported back buffer for pbuffer surface");
908
"DRI driver requested unsupported back buffer for pbuffer surface");
899
917
* return error when the allocation for supported buffer failed.
902
droid_image_get_buffers(__DRIdrawable *driDrawable,
906
uint32_t buffer_mask,
907
struct __DRIimageList *images)
920
droid_image_get_buffers(__DRIdrawable *driDrawable, unsigned int format,
921
uint32_t *stamp, void *loaderPrivate,
922
uint32_t buffer_mask, struct __DRIimageList *images)
909
924
struct dri2_egl_surface *dri2_surf = loaderPrivate;
997
1011
if (dri2_surf->back)
998
1012
dri2_surf->back->age = 1;
1000
dri2_flush_drawable_for_swapbuffers_flags(disp, draw, __DRI2_NOTHROTTLE_SWAPBUFFER);
1014
dri2_flush_drawable_for_swapbuffers_flags(disp, draw,
1015
__DRI2_NOTHROTTLE_SWAPBUFFER);
1002
/* dri2_surf->buffer can be null even when no error has occured. For
1017
/* dri2_surf->buffer can be null even when no error has occurred. For
1003
1018
* example, if the user has called no GL rendering commands since the
1004
1019
* previous eglSwapBuffers, then the driver may have not triggered
1005
1020
* a callback to ANativeWindow_dequeueBuffer, in which case
1013
1028
/* Update the shared buffer mode */
1014
1029
if (has_mutable_rb &&
1015
1030
draw->ActiveRenderBuffer != draw->RequestedRenderBuffer) {
1016
bool mode = (draw->RequestedRenderBuffer == EGL_SINGLE_BUFFER);
1017
_eglLog(_EGL_DEBUG, "%s: change to shared buffer mode %d",
1031
bool mode = (draw->RequestedRenderBuffer == EGL_SINGLE_BUFFER);
1032
_eglLog(_EGL_DEBUG, "%s: change to shared buffer mode %d", __func__,
1020
1035
if (!droid_set_shared_buffer_mode(disp, draw, mode))
1021
1036
return EGL_FALSE;
1028
1043
#ifdef HAVE_DRM_GRALLOC
1029
static int get_format(int format)
1045
get_format(int format)
1031
1047
switch (format) {
1032
case HAL_PIXEL_FORMAT_BGRA_8888: return __DRI_IMAGE_FORMAT_ARGB8888;
1033
case HAL_PIXEL_FORMAT_RGB_565: return __DRI_IMAGE_FORMAT_RGB565;
1034
case HAL_PIXEL_FORMAT_RGBA_8888: return __DRI_IMAGE_FORMAT_ABGR8888;
1048
case HAL_PIXEL_FORMAT_BGRA_8888:
1049
return __DRI_IMAGE_FORMAT_ARGB8888;
1050
case HAL_PIXEL_FORMAT_RGB_565:
1051
return __DRI_IMAGE_FORMAT_RGB565;
1052
case HAL_PIXEL_FORMAT_RGBA_8888:
1053
return __DRI_IMAGE_FORMAT_ABGR8888;
1035
1054
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
1037
1056
* HACK: Hardcode this to RGBX_8888 as per cros_gralloc hack.
1038
* TODO: Revert this once https://issuetracker.google.com/32077885 is fixed.
1057
* TODO: Revert this once https://issuetracker.google.com/32077885 is
1040
case HAL_PIXEL_FORMAT_RGBX_8888: return __DRI_IMAGE_FORMAT_XBGR8888;
1041
case HAL_PIXEL_FORMAT_RGBA_FP16: return __DRI_IMAGE_FORMAT_ABGR16161616F;
1042
case HAL_PIXEL_FORMAT_RGBA_1010102: return __DRI_IMAGE_FORMAT_ABGR2101010;
1060
case HAL_PIXEL_FORMAT_RGBX_8888:
1061
return __DRI_IMAGE_FORMAT_XBGR8888;
1062
case HAL_PIXEL_FORMAT_RGBA_FP16:
1063
return __DRI_IMAGE_FORMAT_ABGR16161616F;
1064
case HAL_PIXEL_FORMAT_RGBA_1010102:
1065
return __DRI_IMAGE_FORMAT_ABGR2101010;
1044
1067
_eglLog(_EGL_WARNING, "unsupported native buffer format 0x%x", format);
1064
1086
format = get_format(buf->format);
1065
1087
if (format == -1)
1069
dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen_render_gpu,
1090
return dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen_render_gpu,
1091
buf->width, buf->height, format,
1092
name, buf->stride, priv);
1077
1094
#endif /* HAVE_DRM_GRALLOC */
1079
1096
static EGLBoolean
1080
droid_query_surface(_EGLDisplay *disp, _EGLSurface *surf,
1081
EGLint attribute, EGLint *value)
1097
droid_query_surface(_EGLDisplay *disp, _EGLSurface *surf, EGLint attribute,
1083
1100
struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
1084
1101
switch (attribute) {
1086
if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->window) {
1087
ANativeWindow_query(dri2_surf->window,
1088
ANATIVEWINDOW_QUERY_DEFAULT_WIDTH, value);
1093
if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->window) {
1094
ANativeWindow_query(dri2_surf->window,
1095
ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT, value);
1103
if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->window) {
1104
ANativeWindow_query(dri2_surf->window,
1105
ANATIVEWINDOW_QUERY_DEFAULT_WIDTH, value);
1110
if (dri2_surf->base.Type == EGL_WINDOW_BIT && dri2_surf->window) {
1111
ANativeWindow_query(dri2_surf->window,
1112
ANATIVEWINDOW_QUERY_DEFAULT_HEIGHT, value);
1102
1119
return _eglQuerySurface(disp, surf, attribute, value);
1105
1122
static _EGLImage *
1106
dri2_create_image_android_native_buffer(_EGLDisplay *disp,
1123
dri2_create_image_android_native_buffer(_EGLDisplay *disp, _EGLContext *ctx,
1108
1124
struct ANativeWindowBuffer *buf)
1110
1126
if (ctx != NULL) {
1150
1167
switch (target) {
1151
1168
case EGL_NATIVE_BUFFER_ANDROID:
1152
return dri2_create_image_android_native_buffer(disp, ctx,
1153
(struct ANativeWindowBuffer *) buffer);
1169
return dri2_create_image_android_native_buffer(
1170
disp, ctx, (struct ANativeWindowBuffer *)buffer);
1155
1172
return dri2_create_image_khr(disp, ctx, target, buffer, attr_list);
1160
droid_flush_front_buffer(__DRIdrawable * driDrawable, void *loaderPrivate)
1177
droid_flush_front_buffer(__DRIdrawable *driDrawable, void *loaderPrivate)
1220
1237
static __DRIbuffer *
1221
droid_get_buffers_with_format(__DRIdrawable * driDrawable,
1222
int *width, int *height,
1223
unsigned int *attachments, int count,
1224
int *out_count, void *loaderPrivate)
1238
droid_get_buffers_with_format(__DRIdrawable *driDrawable, int *width,
1239
int *height, unsigned int *attachments, int count,
1240
int *out_count, void *loaderPrivate)
1226
1242
struct dri2_egl_surface *dri2_surf = loaderPrivate;
1228
1244
if (update_buffers(dri2_surf) < 0)
1231
*out_count = droid_get_buffers_parse_attachments(dri2_surf, attachments, count);
1248
droid_get_buffers_parse_attachments(dri2_surf, attachments, count);
1234
1251
*width = dri2_surf->base.Width;
1271
1288
int rgba_shifts[4];
1272
1289
unsigned int rgba_sizes[4];
1273
1290
} visuals[] = {
1274
{ HAL_PIXEL_FORMAT_RGBA_8888, { 0, 8, 16, 24 }, { 8, 8, 8, 8 } },
1275
{ HAL_PIXEL_FORMAT_RGBX_8888, { 0, 8, 16, -1 }, { 8, 8, 8, 0 } },
1276
{ HAL_PIXEL_FORMAT_RGB_565, { 11, 5, 0, -1 }, { 5, 6, 5, 0 } },
1291
{HAL_PIXEL_FORMAT_RGBA_8888, {0, 8, 16, 24}, {8, 8, 8, 8}},
1292
{HAL_PIXEL_FORMAT_RGBX_8888, {0, 8, 16, -1}, {8, 8, 8, 0}},
1293
{HAL_PIXEL_FORMAT_RGB_565, {11, 5, 0, -1}, {5, 6, 5, 0}},
1277
1294
/* This must be after HAL_PIXEL_FORMAT_RGBA_8888, we only keep BGRA
1278
1295
* visual if it turns out RGBA visual is not available.
1280
{ HAL_PIXEL_FORMAT_BGRA_8888, { 16, 8, 0, 24 }, { 8, 8, 8, 8 } },
1297
{HAL_PIXEL_FORMAT_BGRA_8888, {16, 8, 0, 24}, {8, 8, 8, 8}},
1283
unsigned int format_count[ARRAY_SIZE(visuals)] = { 0 };
1300
unsigned int format_count[ARRAY_SIZE(visuals)] = {0};
1284
1301
int config_count = 0;
1286
1303
/* The nesting of loops is significant here. Also significant is the order
1312
1329
const EGLint surface_type = EGL_WINDOW_BIT | EGL_PBUFFER_BIT;
1314
1331
const EGLint config_attrs[] = {
1315
EGL_NATIVE_VISUAL_ID, visuals[i].format,
1316
EGL_NATIVE_VISUAL_TYPE, visuals[i].format,
1317
EGL_FRAMEBUFFER_TARGET_ANDROID, EGL_TRUE,
1318
EGL_RECORDABLE_ANDROID, EGL_TRUE,
1332
EGL_NATIVE_VISUAL_ID,
1334
EGL_NATIVE_VISUAL_TYPE,
1336
EGL_FRAMEBUFFER_TARGET_ANDROID,
1338
EGL_RECORDABLE_ANDROID,
1322
struct dri2_egl_config *dri2_conf =
1323
dri2_add_config(disp, dri2_dpy->driver_configs[j],
1324
config_count + 1, surface_type, config_attrs,
1325
visuals[i].rgba_shifts, visuals[i].rgba_sizes);
1343
struct dri2_egl_config *dri2_conf = dri2_add_config(
1344
disp, dri2_dpy->driver_configs[j], config_count + 1, surface_type,
1345
config_attrs, visuals[i].rgba_shifts, visuals[i].rgba_sizes);
1326
1346
if (dri2_conf) {
1327
1347
if (dri2_conf->base.ConfigID == config_count + 1)
1328
1348
config_count++;
1360
1380
#ifdef HAVE_DRM_GRALLOC
1361
1381
static const __DRIdri2LoaderExtension droid_dri2_loader_extension = {
1362
.base = { __DRI_DRI2_LOADER, 5 },
1382
.base = {__DRI_DRI2_LOADER, 5},
1365
.flushFrontBuffer = droid_flush_front_buffer,
1366
.getBuffersWithFormat = droid_get_buffers_with_format,
1367
.getCapability = droid_get_capability,
1368
.destroyLoaderImageState = droid_destroy_loader_image_state,
1385
.flushFrontBuffer = droid_flush_front_buffer,
1386
.getBuffersWithFormat = droid_get_buffers_with_format,
1387
.getCapability = droid_get_capability,
1388
.destroyLoaderImageState = droid_destroy_loader_image_state,
1371
1391
static const __DRIextension *droid_dri2_loader_extensions[] = {
1380
1400
#endif /* HAVE_DRM_GRALLOC */
1382
1402
static const __DRIimageLoaderExtension droid_image_loader_extension = {
1383
.base = { __DRI_IMAGE_LOADER, 4 },
1403
.base = {__DRI_IMAGE_LOADER, 4},
1385
.getBuffers = droid_image_get_buffers,
1386
.flushFrontBuffer = droid_flush_front_buffer,
1387
.getCapability = droid_get_capability,
1388
.flushSwapBuffers = NULL,
1389
.destroyLoaderImageState = droid_destroy_loader_image_state,
1405
.getBuffers = droid_image_get_buffers,
1406
.flushFrontBuffer = droid_flush_front_buffer,
1407
.getCapability = droid_get_capability,
1408
.flushSwapBuffers = NULL,
1409
.destroyLoaderImageState = droid_destroy_loader_image_state,
1451
1471
handle_in_fence_fd(dri2_surf, dri2_surf->dri_image_back);
1454
static const __DRImutableRenderBufferLoaderExtension droid_mutable_render_buffer_extension = {
1455
.base = { __DRI_MUTABLE_RENDER_BUFFER_LOADER, 1 },
1456
.displaySharedBuffer = droid_display_shared_buffer,
1474
static const __DRImutableRenderBufferLoaderExtension
1475
droid_mutable_render_buffer_extension = {
1476
.base = {__DRI_MUTABLE_RENDER_BUFFER_LOADER, 1},
1477
.displaySharedBuffer = droid_display_shared_buffer,
1459
1480
static const __DRIextension *droid_image_loader_extensions[] = {
1617
1637
dri2_dpy->fd_render_gpu = loader_open_device(device->nodes[node_type]);
1618
1638
if (dri2_dpy->fd_render_gpu < 0) {
1619
_eglLog(_EGL_WARNING, "%s() Failed to open DRM device %s",
1620
__func__, device->nodes[node_type]);
1639
_eglLog(_EGL_WARNING, "%s() Failed to open DRM device %s", __func__,
1640
device->nodes[node_type]);
1768
1788
if (!strcmp(dri2_dpy->gralloc->common.name, cros_gralloc_module_name) &&
1769
1789
dri2_dpy->gralloc->perform &&
1770
1790
dri2_dpy->gralloc->perform(
1771
dri2_dpy->gralloc, CROS_GRALLOC_DRM_GET_USAGE,
1772
CROS_GRALLOC_DRM_GET_USAGE_FRONT_RENDERING_BIT,
1773
&front_rendering_usage) == 0) {
1791
dri2_dpy->gralloc, CROS_GRALLOC_DRM_GET_USAGE,
1792
CROS_GRALLOC_DRM_GET_USAGE_FRONT_RENDERING_BIT,
1793
&front_rendering_usage) == 0) {
1774
1794
dri2_dpy->front_rendering_usage = front_rendering_usage;
1775
1795
disp->Extensions.KHR_mutable_render_buffer = EGL_TRUE;