mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-16 22:43:24 +09:00
Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7308668488 | ||
|
|
134791b4b9 | ||
|
|
c24926cafe | ||
|
|
c5fa722be7 | ||
|
|
b7aa8d2011 | ||
|
|
378020adf3 | ||
|
|
028cf4eb62 | ||
|
|
08124c99f1 |
Vendored
-538
@@ -1,538 +0,0 @@
|
||||
/*
|
||||
* Copyright © 2011 Intel Corporation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Authors:
|
||||
* Benjamin Franzke <benjaminfranzke@googlemail.com>
|
||||
*/
|
||||
|
||||
#ifndef _GBM_H_
|
||||
#define _GBM_H_
|
||||
|
||||
#define __GBM__ 1
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* \file gbm.h
|
||||
* \brief Generic Buffer Manager
|
||||
*/
|
||||
|
||||
struct gbm_device;
|
||||
struct gbm_bo;
|
||||
struct gbm_surface;
|
||||
|
||||
/**
|
||||
* \mainpage The Generic Buffer Manager
|
||||
*
|
||||
* This module provides an abstraction that the caller can use to request a
|
||||
* buffer from the underlying memory management system for the platform.
|
||||
*
|
||||
* This allows the creation of portable code whilst still allowing access to
|
||||
* the underlying memory manager.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstraction representing the handle to a buffer allocated by the
|
||||
* manager
|
||||
*/
|
||||
union gbm_bo_handle {
|
||||
void *ptr;
|
||||
int32_t s32;
|
||||
uint32_t u32;
|
||||
int64_t s64;
|
||||
uint64_t u64;
|
||||
};
|
||||
|
||||
/** Format of the allocated buffer */
|
||||
enum gbm_bo_format {
|
||||
/** RGB with 8 bits per channel in a 32 bit value */
|
||||
GBM_BO_FORMAT_XRGB8888,
|
||||
/** ARGB with 8 bits per channel in a 32 bit value */
|
||||
GBM_BO_FORMAT_ARGB8888
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The FourCC format codes are taken from the drm_fourcc.h definition, and
|
||||
* re-namespaced. New GBM formats must not be added, unless they are
|
||||
* identical ports from drm_fourcc.
|
||||
*/
|
||||
#define __gbm_fourcc_code(a,b,c,d) ((uint32_t)(a) | ((uint32_t)(b) << 8) | \
|
||||
((uint32_t)(c) << 16) | ((uint32_t)(d) << 24))
|
||||
|
||||
#define GBM_FORMAT_BIG_ENDIAN (1<<31) /* format is big endian instead of little endian */
|
||||
|
||||
/* color index */
|
||||
#define GBM_FORMAT_C8 __gbm_fourcc_code('C', '8', ' ', ' ') /* [7:0] C */
|
||||
|
||||
/* 8 bpp Red */
|
||||
#define GBM_FORMAT_R8 __gbm_fourcc_code('R', '8', ' ', ' ') /* [7:0] R */
|
||||
|
||||
/* 16 bpp Red */
|
||||
#define GBM_FORMAT_R16 __gbm_fourcc_code('R', '1', '6', ' ') /* [15:0] R little endian */
|
||||
|
||||
/* 16 bpp RG */
|
||||
#define GBM_FORMAT_GR88 __gbm_fourcc_code('G', 'R', '8', '8') /* [15:0] G:R 8:8 little endian */
|
||||
|
||||
/* 32 bpp RG */
|
||||
#define GBM_FORMAT_RG1616 __gbm_fourcc_code('R', 'G', '3', '2') /* [31:0] R:G 16:16 little endian */
|
||||
#define GBM_FORMAT_GR1616 __gbm_fourcc_code('G', 'R', '3', '2') /* [31:0] G:R 16:16 little endian */
|
||||
|
||||
/* 8 bpp RGB */
|
||||
#define GBM_FORMAT_RGB332 __gbm_fourcc_code('R', 'G', 'B', '8') /* [7:0] R:G:B 3:3:2 */
|
||||
#define GBM_FORMAT_BGR233 __gbm_fourcc_code('B', 'G', 'R', '8') /* [7:0] B:G:R 2:3:3 */
|
||||
|
||||
/* 16 bpp RGB */
|
||||
#define GBM_FORMAT_XRGB4444 __gbm_fourcc_code('X', 'R', '1', '2') /* [15:0] x:R:G:B 4:4:4:4 little endian */
|
||||
#define GBM_FORMAT_XBGR4444 __gbm_fourcc_code('X', 'B', '1', '2') /* [15:0] x:B:G:R 4:4:4:4 little endian */
|
||||
#define GBM_FORMAT_RGBX4444 __gbm_fourcc_code('R', 'X', '1', '2') /* [15:0] R:G:B:x 4:4:4:4 little endian */
|
||||
#define GBM_FORMAT_BGRX4444 __gbm_fourcc_code('B', 'X', '1', '2') /* [15:0] B:G:R:x 4:4:4:4 little endian */
|
||||
|
||||
#define GBM_FORMAT_ARGB4444 __gbm_fourcc_code('A', 'R', '1', '2') /* [15:0] A:R:G:B 4:4:4:4 little endian */
|
||||
#define GBM_FORMAT_ABGR4444 __gbm_fourcc_code('A', 'B', '1', '2') /* [15:0] A:B:G:R 4:4:4:4 little endian */
|
||||
#define GBM_FORMAT_RGBA4444 __gbm_fourcc_code('R', 'A', '1', '2') /* [15:0] R:G:B:A 4:4:4:4 little endian */
|
||||
#define GBM_FORMAT_BGRA4444 __gbm_fourcc_code('B', 'A', '1', '2') /* [15:0] B:G:R:A 4:4:4:4 little endian */
|
||||
|
||||
#define GBM_FORMAT_XRGB1555 __gbm_fourcc_code('X', 'R', '1', '5') /* [15:0] x:R:G:B 1:5:5:5 little endian */
|
||||
#define GBM_FORMAT_XBGR1555 __gbm_fourcc_code('X', 'B', '1', '5') /* [15:0] x:B:G:R 1:5:5:5 little endian */
|
||||
#define GBM_FORMAT_RGBX5551 __gbm_fourcc_code('R', 'X', '1', '5') /* [15:0] R:G:B:x 5:5:5:1 little endian */
|
||||
#define GBM_FORMAT_BGRX5551 __gbm_fourcc_code('B', 'X', '1', '5') /* [15:0] B:G:R:x 5:5:5:1 little endian */
|
||||
|
||||
#define GBM_FORMAT_ARGB1555 __gbm_fourcc_code('A', 'R', '1', '5') /* [15:0] A:R:G:B 1:5:5:5 little endian */
|
||||
#define GBM_FORMAT_ABGR1555 __gbm_fourcc_code('A', 'B', '1', '5') /* [15:0] A:B:G:R 1:5:5:5 little endian */
|
||||
#define GBM_FORMAT_RGBA5551 __gbm_fourcc_code('R', 'A', '1', '5') /* [15:0] R:G:B:A 5:5:5:1 little endian */
|
||||
#define GBM_FORMAT_BGRA5551 __gbm_fourcc_code('B', 'A', '1', '5') /* [15:0] B:G:R:A 5:5:5:1 little endian */
|
||||
|
||||
#define GBM_FORMAT_RGB565 __gbm_fourcc_code('R', 'G', '1', '6') /* [15:0] R:G:B 5:6:5 little endian */
|
||||
#define GBM_FORMAT_BGR565 __gbm_fourcc_code('B', 'G', '1', '6') /* [15:0] B:G:R 5:6:5 little endian */
|
||||
|
||||
/* 24 bpp RGB */
|
||||
#define GBM_FORMAT_RGB888 __gbm_fourcc_code('R', 'G', '2', '4') /* [23:0] R:G:B little endian */
|
||||
#define GBM_FORMAT_BGR888 __gbm_fourcc_code('B', 'G', '2', '4') /* [23:0] B:G:R little endian */
|
||||
|
||||
/* 32 bpp RGB */
|
||||
#define GBM_FORMAT_XRGB8888 __gbm_fourcc_code('X', 'R', '2', '4') /* [31:0] x:R:G:B 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_XBGR8888 __gbm_fourcc_code('X', 'B', '2', '4') /* [31:0] x:B:G:R 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_RGBX8888 __gbm_fourcc_code('R', 'X', '2', '4') /* [31:0] R:G:B:x 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_BGRX8888 __gbm_fourcc_code('B', 'X', '2', '4') /* [31:0] B:G:R:x 8:8:8:8 little endian */
|
||||
|
||||
#define GBM_FORMAT_ARGB8888 __gbm_fourcc_code('A', 'R', '2', '4') /* [31:0] A:R:G:B 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_ABGR8888 __gbm_fourcc_code('A', 'B', '2', '4') /* [31:0] A:B:G:R 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_RGBA8888 __gbm_fourcc_code('R', 'A', '2', '4') /* [31:0] R:G:B:A 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_BGRA8888 __gbm_fourcc_code('B', 'A', '2', '4') /* [31:0] B:G:R:A 8:8:8:8 little endian */
|
||||
|
||||
#define GBM_FORMAT_XRGB2101010 __gbm_fourcc_code('X', 'R', '3', '0') /* [31:0] x:R:G:B 2:10:10:10 little endian */
|
||||
#define GBM_FORMAT_XBGR2101010 __gbm_fourcc_code('X', 'B', '3', '0') /* [31:0] x:B:G:R 2:10:10:10 little endian */
|
||||
#define GBM_FORMAT_RGBX1010102 __gbm_fourcc_code('R', 'X', '3', '0') /* [31:0] R:G:B:x 10:10:10:2 little endian */
|
||||
#define GBM_FORMAT_BGRX1010102 __gbm_fourcc_code('B', 'X', '3', '0') /* [31:0] B:G:R:x 10:10:10:2 little endian */
|
||||
|
||||
#define GBM_FORMAT_ARGB2101010 __gbm_fourcc_code('A', 'R', '3', '0') /* [31:0] A:R:G:B 2:10:10:10 little endian */
|
||||
#define GBM_FORMAT_ABGR2101010 __gbm_fourcc_code('A', 'B', '3', '0') /* [31:0] A:B:G:R 2:10:10:10 little endian */
|
||||
#define GBM_FORMAT_RGBA1010102 __gbm_fourcc_code('R', 'A', '3', '0') /* [31:0] R:G:B:A 10:10:10:2 little endian */
|
||||
#define GBM_FORMAT_BGRA1010102 __gbm_fourcc_code('B', 'A', '3', '0') /* [31:0] B:G:R:A 10:10:10:2 little endian */
|
||||
|
||||
/* 64 bpp RGB */
|
||||
#define GBM_FORMAT_XBGR16161616 __gbm_fourcc_code('X', 'B', '4', '8') /* [63:0] x:B:G:R 16:16:16:16 little endian */
|
||||
|
||||
#define GBM_FORMAT_ABGR16161616 __gbm_fourcc_code('A', 'B', '4', '8') /* [63:0] A:B:G:R 16:16:16:16 little endian */
|
||||
|
||||
/*
|
||||
* Floating point 64bpp RGB
|
||||
* IEEE 754-2008 binary16 half-precision float
|
||||
* [15:0] sign:exponent:mantissa 1:5:10
|
||||
*/
|
||||
#define GBM_FORMAT_XBGR16161616F __gbm_fourcc_code('X', 'B', '4', 'H') /* [63:0] x:B:G:R 16:16:16:16 little endian */
|
||||
|
||||
#define GBM_FORMAT_ABGR16161616F __gbm_fourcc_code('A', 'B', '4', 'H') /* [63:0] A:B:G:R 16:16:16:16 little endian */
|
||||
|
||||
/* packed YCbCr */
|
||||
#define GBM_FORMAT_YUYV __gbm_fourcc_code('Y', 'U', 'Y', 'V') /* [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_YVYU __gbm_fourcc_code('Y', 'V', 'Y', 'U') /* [31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_UYVY __gbm_fourcc_code('U', 'Y', 'V', 'Y') /* [31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian */
|
||||
#define GBM_FORMAT_VYUY __gbm_fourcc_code('V', 'Y', 'U', 'Y') /* [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian */
|
||||
|
||||
#define GBM_FORMAT_AYUV __gbm_fourcc_code('A', 'Y', 'U', 'V') /* [31:0] A:Y:Cb:Cr 8:8:8:8 little endian */
|
||||
|
||||
/*
|
||||
* 2 plane YCbCr
|
||||
* index 0 = Y plane, [7:0] Y
|
||||
* index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
|
||||
* or
|
||||
* index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
|
||||
*/
|
||||
#define GBM_FORMAT_NV12 __gbm_fourcc_code('N', 'V', '1', '2') /* 2x2 subsampled Cr:Cb plane */
|
||||
#define GBM_FORMAT_NV21 __gbm_fourcc_code('N', 'V', '2', '1') /* 2x2 subsampled Cb:Cr plane */
|
||||
#define GBM_FORMAT_NV16 __gbm_fourcc_code('N', 'V', '1', '6') /* 2x1 subsampled Cr:Cb plane */
|
||||
#define GBM_FORMAT_NV61 __gbm_fourcc_code('N', 'V', '6', '1') /* 2x1 subsampled Cb:Cr plane */
|
||||
|
||||
/*
|
||||
* 3 plane YCbCr
|
||||
* index 0: Y plane, [7:0] Y
|
||||
* index 1: Cb plane, [7:0] Cb
|
||||
* index 2: Cr plane, [7:0] Cr
|
||||
* or
|
||||
* index 1: Cr plane, [7:0] Cr
|
||||
* index 2: Cb plane, [7:0] Cb
|
||||
*/
|
||||
#define GBM_FORMAT_YUV410 __gbm_fourcc_code('Y', 'U', 'V', '9') /* 4x4 subsampled Cb (1) and Cr (2) planes */
|
||||
#define GBM_FORMAT_YVU410 __gbm_fourcc_code('Y', 'V', 'U', '9') /* 4x4 subsampled Cr (1) and Cb (2) planes */
|
||||
#define GBM_FORMAT_YUV411 __gbm_fourcc_code('Y', 'U', '1', '1') /* 4x1 subsampled Cb (1) and Cr (2) planes */
|
||||
#define GBM_FORMAT_YVU411 __gbm_fourcc_code('Y', 'V', '1', '1') /* 4x1 subsampled Cr (1) and Cb (2) planes */
|
||||
#define GBM_FORMAT_YUV420 __gbm_fourcc_code('Y', 'U', '1', '2') /* 2x2 subsampled Cb (1) and Cr (2) planes */
|
||||
#define GBM_FORMAT_YVU420 __gbm_fourcc_code('Y', 'V', '1', '2') /* 2x2 subsampled Cr (1) and Cb (2) planes */
|
||||
#define GBM_FORMAT_YUV422 __gbm_fourcc_code('Y', 'U', '1', '6') /* 2x1 subsampled Cb (1) and Cr (2) planes */
|
||||
#define GBM_FORMAT_YVU422 __gbm_fourcc_code('Y', 'V', '1', '6') /* 2x1 subsampled Cr (1) and Cb (2) planes */
|
||||
#define GBM_FORMAT_YUV444 __gbm_fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */
|
||||
#define GBM_FORMAT_YVU444 __gbm_fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */
|
||||
|
||||
struct gbm_format_name_desc {
|
||||
char name[5];
|
||||
};
|
||||
|
||||
/**
|
||||
* Flags to indicate the intended use for the buffer - these are passed into
|
||||
* gbm_bo_create(). The caller must set the union of all the flags that are
|
||||
* appropriate
|
||||
*
|
||||
* \sa Use gbm_device_is_format_supported() to check if the combination of format
|
||||
* and use flags are supported
|
||||
*/
|
||||
enum gbm_bo_flags {
|
||||
/**
|
||||
* Buffer is going to be presented to the screen using an API such as KMS
|
||||
*/
|
||||
GBM_BO_USE_SCANOUT = (1 << 0),
|
||||
/**
|
||||
* Buffer is going to be used as cursor
|
||||
*/
|
||||
GBM_BO_USE_CURSOR = (1 << 1),
|
||||
/**
|
||||
* Deprecated
|
||||
*/
|
||||
GBM_BO_USE_CURSOR_64X64 = GBM_BO_USE_CURSOR,
|
||||
/**
|
||||
* Buffer is to be used for rendering - for example it is going to be used
|
||||
* as the storage for a color buffer
|
||||
*/
|
||||
GBM_BO_USE_RENDERING = (1 << 2),
|
||||
/**
|
||||
* Buffer can be used for gbm_bo_write. This is guaranteed to work
|
||||
* with GBM_BO_USE_CURSOR, but may not work for other combinations.
|
||||
*/
|
||||
GBM_BO_USE_WRITE = (1 << 3),
|
||||
/**
|
||||
* Buffer is linear, i.e. not tiled.
|
||||
*/
|
||||
GBM_BO_USE_LINEAR = (1 << 4),
|
||||
/**
|
||||
* Buffer is protected, i.e. encrypted and not readable by CPU or any
|
||||
* other non-secure / non-trusted components nor by non-trusted OpenGL,
|
||||
* OpenCL, and Vulkan applications.
|
||||
*/
|
||||
GBM_BO_USE_PROTECTED = (1 << 5),
|
||||
|
||||
/**
|
||||
* The buffer will be used for front buffer rendering. On some
|
||||
* platforms this may (for example) disable framebuffer compression
|
||||
* to avoid problems with compression flags data being out of sync
|
||||
* with pixel data.
|
||||
*/
|
||||
GBM_BO_USE_FRONT_RENDERING = (1 << 6),
|
||||
|
||||
/**
|
||||
* Allow the driver to select fixed-rate compression parameters.
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_DEFAULT = (1 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 1bpc, less than 2bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_1BPC = (2 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 2bpc, less than 3bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_2BPC = (3 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 3bpc, less than 4bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_3BPC = (4 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 4bpc, less than 5bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_4BPC = (5 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 5bpc, less than 6bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_5BPC = (6 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 6bpc, less than 7bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_6BPC = (7 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 7bpc, less than 8bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_7BPC = (8 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 8bpc, less than 9bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_8BPC = (9 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 9bpc, less than 10bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_9BPC = (10 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 10bpc, less than 11bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_10BPC = (11 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 11bpc, less than 12bpc
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_11BPC = (12 << 7),
|
||||
|
||||
/**
|
||||
* Fixed-rate compression: at least 12bpc, no maximum rate
|
||||
*/
|
||||
GBM_BO_FIXED_COMPRESSION_12BPC = (13 << 7),
|
||||
|
||||
/* next available value is (1 << 11) */
|
||||
};
|
||||
|
||||
#define GBM_BO_FIXED_COMPRESSION_MASK (((1 << 11) - 1) & ~((1 << 7) - 1))
|
||||
|
||||
int
|
||||
gbm_device_get_fd(struct gbm_device *gbm);
|
||||
|
||||
const char *
|
||||
gbm_device_get_backend_name(struct gbm_device *gbm);
|
||||
|
||||
int
|
||||
gbm_device_is_format_supported(struct gbm_device *gbm,
|
||||
uint32_t format, uint32_t flags);
|
||||
|
||||
int
|
||||
gbm_device_get_format_modifier_plane_count(struct gbm_device *gbm,
|
||||
uint32_t format,
|
||||
uint64_t modifier);
|
||||
|
||||
void
|
||||
gbm_device_destroy(struct gbm_device *gbm);
|
||||
|
||||
struct gbm_device *
|
||||
gbm_create_device(int fd);
|
||||
|
||||
struct gbm_bo *
|
||||
gbm_bo_create(struct gbm_device *gbm,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t format, uint32_t flags);
|
||||
|
||||
struct gbm_bo *
|
||||
gbm_bo_create_with_modifiers(struct gbm_device *gbm,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t format,
|
||||
const uint64_t *modifiers,
|
||||
const unsigned int count);
|
||||
|
||||
struct gbm_bo *
|
||||
gbm_bo_create_with_modifiers2(struct gbm_device *gbm,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t format,
|
||||
const uint64_t *modifiers,
|
||||
const unsigned int count,
|
||||
uint32_t flags);
|
||||
|
||||
#define GBM_BO_IMPORT_WL_BUFFER 0x5501
|
||||
#define GBM_BO_IMPORT_EGL_IMAGE 0x5502
|
||||
#define GBM_BO_IMPORT_FD 0x5503
|
||||
#define GBM_BO_IMPORT_FD_MODIFIER 0x5504
|
||||
|
||||
struct gbm_import_fd_data {
|
||||
int fd;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t stride;
|
||||
uint32_t format;
|
||||
};
|
||||
|
||||
#define GBM_MAX_PLANES 4
|
||||
|
||||
struct gbm_import_fd_modifier_data {
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t format;
|
||||
uint32_t num_fds;
|
||||
int fds[GBM_MAX_PLANES];
|
||||
int strides[GBM_MAX_PLANES];
|
||||
int offsets[GBM_MAX_PLANES];
|
||||
uint64_t modifier;
|
||||
};
|
||||
|
||||
struct gbm_bo *
|
||||
gbm_bo_import(struct gbm_device *gbm, uint32_t type,
|
||||
void *buffer, uint32_t flags);
|
||||
|
||||
/**
|
||||
* Flags to indicate the type of mapping for the buffer - these are
|
||||
* passed into gbm_bo_map(). The caller must set the union of all the
|
||||
* flags that are appropriate.
|
||||
*
|
||||
* These flags are independent of the GBM_BO_USE_* creation flags. However,
|
||||
* mapping the buffer may require copying to/from a staging buffer.
|
||||
*
|
||||
* See also: pipe_map_flags
|
||||
*/
|
||||
enum gbm_bo_transfer_flags {
|
||||
/**
|
||||
* Buffer contents read back (or accessed directly) at transfer
|
||||
* create time.
|
||||
*/
|
||||
GBM_BO_TRANSFER_READ = (1 << 0),
|
||||
/**
|
||||
* Buffer contents will be written back at unmap time
|
||||
* (or modified as a result of being accessed directly).
|
||||
*/
|
||||
GBM_BO_TRANSFER_WRITE = (1 << 1),
|
||||
/**
|
||||
* Read/modify/write
|
||||
*/
|
||||
GBM_BO_TRANSFER_READ_WRITE = (GBM_BO_TRANSFER_READ | GBM_BO_TRANSFER_WRITE),
|
||||
};
|
||||
|
||||
void *
|
||||
gbm_bo_map(struct gbm_bo *bo,
|
||||
uint32_t x, uint32_t y, uint32_t width, uint32_t height,
|
||||
uint32_t flags, uint32_t *stride, void **map_data);
|
||||
|
||||
void
|
||||
gbm_bo_unmap(struct gbm_bo *bo, void *map_data);
|
||||
|
||||
uint32_t
|
||||
gbm_bo_get_width(struct gbm_bo *bo);
|
||||
|
||||
uint32_t
|
||||
gbm_bo_get_height(struct gbm_bo *bo);
|
||||
|
||||
uint32_t
|
||||
gbm_bo_get_stride(struct gbm_bo *bo);
|
||||
|
||||
uint32_t
|
||||
gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane);
|
||||
|
||||
uint32_t
|
||||
gbm_bo_get_format(struct gbm_bo *bo);
|
||||
|
||||
uint32_t
|
||||
gbm_bo_get_bpp(struct gbm_bo *bo);
|
||||
|
||||
uint32_t
|
||||
gbm_bo_get_offset(struct gbm_bo *bo, int plane);
|
||||
|
||||
struct gbm_device *
|
||||
gbm_bo_get_device(struct gbm_bo *bo);
|
||||
|
||||
union gbm_bo_handle
|
||||
gbm_bo_get_handle(struct gbm_bo *bo);
|
||||
|
||||
int
|
||||
gbm_bo_get_fd(struct gbm_bo *bo);
|
||||
|
||||
uint64_t
|
||||
gbm_bo_get_modifier(struct gbm_bo *bo);
|
||||
|
||||
int
|
||||
gbm_bo_get_plane_count(struct gbm_bo *bo);
|
||||
|
||||
union gbm_bo_handle
|
||||
gbm_bo_get_handle_for_plane(struct gbm_bo *bo, int plane);
|
||||
|
||||
int
|
||||
gbm_bo_get_fd_for_plane(struct gbm_bo *bo, int plane);
|
||||
|
||||
int
|
||||
gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count);
|
||||
|
||||
void
|
||||
gbm_bo_set_user_data(struct gbm_bo *bo, void *data,
|
||||
void (*destroy_user_data)(struct gbm_bo *, void *));
|
||||
|
||||
void *
|
||||
gbm_bo_get_user_data(struct gbm_bo *bo);
|
||||
|
||||
void
|
||||
gbm_bo_destroy(struct gbm_bo *bo);
|
||||
|
||||
struct gbm_surface *
|
||||
gbm_surface_create(struct gbm_device *gbm,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t format, uint32_t flags);
|
||||
|
||||
struct gbm_surface *
|
||||
gbm_surface_create_with_modifiers(struct gbm_device *gbm,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t format,
|
||||
const uint64_t *modifiers,
|
||||
const unsigned int count);
|
||||
|
||||
struct gbm_surface *
|
||||
gbm_surface_create_with_modifiers2(struct gbm_device *gbm,
|
||||
uint32_t width, uint32_t height,
|
||||
uint32_t format,
|
||||
const uint64_t *modifiers,
|
||||
const unsigned int count,
|
||||
uint32_t flags);
|
||||
|
||||
struct gbm_bo *
|
||||
gbm_surface_lock_front_buffer(struct gbm_surface *surface);
|
||||
|
||||
void
|
||||
gbm_surface_release_buffer(struct gbm_surface *surface, struct gbm_bo *bo);
|
||||
|
||||
int
|
||||
gbm_surface_has_free_buffers(struct gbm_surface *surface);
|
||||
|
||||
void
|
||||
gbm_surface_destroy(struct gbm_surface *surface);
|
||||
|
||||
char *
|
||||
gbm_format_get_name(uint32_t gbm_format, struct gbm_format_name_desc *desc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Vendored
-11
@@ -1,11 +0,0 @@
|
||||
# glvnd vendor ABI headers
|
||||
|
||||
'libeglabi.h' and 'GLdispatchABI.h' from libglvnd (MIT), copied verbatim with their own licence
|
||||
headers intact.
|
||||
|
||||
They are here because MobileGL implements the *vendor* half of glvnd's EGL ABI - the side a library
|
||||
exposes so the system's 'libEGL.so.1', which IS glvnd, can dispatch to it. The distribution ships
|
||||
the runtime but not these headers in the base image, and a vendored copy of two MIT headers is a
|
||||
smaller dependency than a build-time download of a source tree.
|
||||
|
||||
Upstream ABI version implemented: 'EGL_VENDOR_ABI_MAJOR_VERSION' 0 (the header pins it).
|
||||
-141
@@ -1,141 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013, NVIDIA CORPORATION.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and/or associated documentation files (the
|
||||
* "Materials"), to deal in the Materials without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
* permit persons to whom the Materials are furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* unaltered in all copies or substantial portions of the Materials.
|
||||
* Any additions, deletions, or changes to the original source files
|
||||
* must be clearly indicated in accompanying documentation.
|
||||
*
|
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
#if !defined(__GL_DISPATCH_ABI_H)
|
||||
#define __GL_DISPATCH_ABI_H
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \defgroup gldispatchabi GL dispatching ABI
|
||||
*
|
||||
* This is not a complete ABI, but rather a fragment common to the libEGL and
|
||||
* libGLX ABIs. Changes to this file should be accompanied by a version bump to
|
||||
* these client ABIs.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Thread-local implementation used by libglvnd. This is passed into the patch
|
||||
* function callback via the type parameter.
|
||||
*
|
||||
* For most architectures, the vendor library can ignore this parameter, since
|
||||
* it will always be the same value. It's used for systems like ARM, where the
|
||||
* stubs might be use the ARM or Thumb instruction sets.
|
||||
*
|
||||
* The stub type does not make any distinction between TLS and TSD stubs. The
|
||||
* entire purpose of entrypoint rewriting is to skip the dispatch table in
|
||||
* libGLdispatch.so, so it doesn't matter how that dispatch table is stored.
|
||||
*/
|
||||
enum {
|
||||
/*!
|
||||
* Indicates that the stubs aren't defined in assembly. For example, if the
|
||||
* dispatch stubs are written in C. Vendor libraries generally won't see
|
||||
* this value.
|
||||
*/
|
||||
__GLDISPATCH_STUB_UNKNOWN,
|
||||
|
||||
/*!
|
||||
* Used for stubs on x86 systems.
|
||||
*/
|
||||
__GLDISPATCH_STUB_X86,
|
||||
|
||||
/*!
|
||||
* Used for stubs on x86-64 systems.
|
||||
*/
|
||||
__GLDISPATCH_STUB_X86_64,
|
||||
|
||||
/*!
|
||||
* Used for stubs on ARMv7, using the Thumb instruction set.
|
||||
*/
|
||||
__GLDISPATCH_STUB_ARMV7_THUMB,
|
||||
|
||||
/*!
|
||||
* Used for stubs on ARMv7, using the normal ARM instruction set.
|
||||
*/
|
||||
__GLDISPATCH_STUB_ARMV7_ARM,
|
||||
|
||||
/*!
|
||||
* Used for stubs on ARMv8/aarch64.
|
||||
*/
|
||||
__GLDISPATCH_STUB_AARCH64,
|
||||
|
||||
/*!
|
||||
* Used for stubs on x32 builds (x86-64 with 32-bit pointers).
|
||||
*/
|
||||
__GLDISPATCH_STUB_X32,
|
||||
|
||||
/*!
|
||||
* Used for stubs on PPC64 systems.
|
||||
*/
|
||||
__GLDISPATCH_STUB_PPC64,
|
||||
|
||||
/*!
|
||||
* Used for stubs on PPC64LE systems. Same as PPC64, for compatibility.
|
||||
*/
|
||||
__GLDISPATCH_STUB_PPC64LE = __GLDISPATCH_STUB_PPC64,
|
||||
|
||||
/*!
|
||||
* Used for stubs on LOONGARCH/loongarch64.
|
||||
*/
|
||||
__GLDISPATCH_STUB_LOONGARCH64,
|
||||
};
|
||||
|
||||
/*!
|
||||
* A callback function called by the vendor library to fetch the address of an
|
||||
* entrypoint.
|
||||
*
|
||||
* The function returns two pointers, one writable and one executable. The two
|
||||
* pointers may or may not be the same virtual address, but they will both be
|
||||
* mappings of the same physical memory.
|
||||
*
|
||||
* The vendor library should write its entrypoint to the address returned by
|
||||
* \p writePtr, but should use the address from \p execPtr for things like
|
||||
* calculating PC-relative offsets.
|
||||
*
|
||||
* Note that if this function fails, then the vendor library can still try to
|
||||
* patch other entrypoints.
|
||||
*
|
||||
* Note that on ARM, the low-order bit of both \c execPtr and \p writePtr will
|
||||
* be zero, even if the stub uses the thumb instruction set. The vendor library
|
||||
* should use the \c type parameter of \c initiatePatch to determine which
|
||||
* instruction set to use.
|
||||
*
|
||||
* \param funcName The function name.
|
||||
* \param[out] writePtr The pointer that the vendor library can write to.
|
||||
* \param[out] execPtr The pointer to the executable code.
|
||||
* \return GL_TRUE if the entrypoint exists, or GL_FALSE if it doesn't.
|
||||
*/
|
||||
typedef GLboolean (*DispatchPatchLookupStubOffset)(const char *funcName,
|
||||
void **writePtr, const void **execPtr);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __GL_DISPATCH_ABI_H
|
||||
-464
@@ -1,464 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2013, NVIDIA CORPORATION.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and/or associated documentation files (the
|
||||
* "Materials"), to deal in the Materials without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Materials, and to
|
||||
* permit persons to whom the Materials are furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* unaltered in all copies or substantial portions of the Materials.
|
||||
* Any additions, deletions, or changes to the original source files
|
||||
* must be clearly indicated in accompanying documentation.
|
||||
*
|
||||
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
|
||||
*/
|
||||
|
||||
#if !defined(__LIB_EGL_ABI_H)
|
||||
#define __LIB_EGL_ABI_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#include "glvnd/GLdispatchABI.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \defgroup eglvendorabi EGL Vendor ABI
|
||||
*
|
||||
* Definition of ABI exported by libEGL.so to libEGL_VENDOR.so libraries.
|
||||
*
|
||||
* Each vendor is associated with three distinct dispatch table types:
|
||||
*
|
||||
* - static EGL dispatch table: this is the fixed list of EGL 1.5 entrypoints
|
||||
* provided by the vendor at load time during the initial handshake.
|
||||
* - dynamic EGL dispatch table: this is a structure allocated by the API
|
||||
* library at runtime used to manage EGL extension functions which are not
|
||||
* present in the static table.
|
||||
* - core GL dispatch table: this is a structure maintained by the API library
|
||||
* which contains both GL core (static) and GL extension (dynamic) functions.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*
|
||||
* Rendering API handling:
|
||||
*
|
||||
* libEGL only supports OpenGL and OpenGL ES, not OpenVG. If OpenVG or any
|
||||
* other API is added, then the major version number will be incremented.
|
||||
*
|
||||
* When the application calls eglBindAPI, libEGL will forward the call to every
|
||||
* vendor library. In addition, a vendor library can query the current API from
|
||||
* libEGL using the getCurrentApi callback.
|
||||
*
|
||||
* Vendor libraries are not required to support both GL and GLES, but they must
|
||||
* be able to deal with either one as the current rendering API. If a vendor
|
||||
* doesn't support the current API, then it should return an error from
|
||||
* eglCreateContext.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Current version of the ABI.
|
||||
*
|
||||
* This version number contains a major number in the high-order 16 bits, and
|
||||
* a minor version number in the low-order 16 bits.
|
||||
*
|
||||
* The major version number is incremented when an interface change will break
|
||||
* backwards compatibility with existing vendor libraries. The minor version
|
||||
* number is incremented when there's a change but existing vendor libraries
|
||||
* will still work.
|
||||
*/
|
||||
#define EGL_VENDOR_ABI_MAJOR_VERSION ((uint32_t) 0)
|
||||
#define EGL_VENDOR_ABI_MINOR_VERSION ((uint32_t) 2)
|
||||
#define EGL_VENDOR_ABI_VERSION ((EGL_VENDOR_ABI_MAJOR_VERSION << 16) | EGL_VENDOR_ABI_MINOR_VERSION)
|
||||
static inline uint32_t EGL_VENDOR_ABI_GET_MAJOR_VERSION(uint32_t version)
|
||||
{
|
||||
return version >> 16;
|
||||
}
|
||||
static inline uint32_t EGL_VENDOR_ABI_GET_MINOR_VERSION(uint32_t version)
|
||||
{
|
||||
return version & 0xFFFF;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* This opaque structure stores function pointers for EGL extension functions.
|
||||
* It is allocated at runtime by the API library. Vendor-provided dispatch
|
||||
* functions retrieve and operate on this structure using the API below.
|
||||
*/
|
||||
typedef struct __EGLvendorInfoRec __EGLvendorInfo;
|
||||
|
||||
/****************************************************************************
|
||||
* API library exports *
|
||||
****************************************************************************/
|
||||
|
||||
typedef struct __EGLapiExportsRec {
|
||||
/************************************************************************
|
||||
* The following routines are used by vendor-implemented EGL dispatch
|
||||
* functions to lookup and call into the right vendor.
|
||||
************************************************************************/
|
||||
|
||||
/*!
|
||||
* This function must be called at the start of every EGL dispatch stub. It
|
||||
* performs any necessary per-call bookkeeping.
|
||||
*/
|
||||
void (* threadInit) (void);
|
||||
|
||||
EGLenum (* getCurrentApi)(void);
|
||||
|
||||
/*!
|
||||
* This function retrieves the appropriate current dynamic dispatch table,
|
||||
* if a GL context is current. Otherwise, this returns NULL.
|
||||
*/
|
||||
__EGLvendorInfo *(*getCurrentVendor)(void);
|
||||
|
||||
/*!
|
||||
* This retrieves the current context for this thread.
|
||||
*/
|
||||
EGLContext (*getCurrentContext)(void);
|
||||
|
||||
/*!
|
||||
* Returns the current display for this thread.
|
||||
*/
|
||||
EGLDisplay (*getCurrentDisplay)(void);
|
||||
|
||||
/*!
|
||||
* Returns the current drawable for this thread.
|
||||
*/
|
||||
EGLSurface (*getCurrentSurface)(EGLint readDraw);
|
||||
|
||||
/*!
|
||||
* This function retrieves an entry point from the dynamic dispatch table
|
||||
* given an index into the table.
|
||||
*/
|
||||
__eglMustCastToProperFunctionPointerType (*fetchDispatchEntry) (__EGLvendorInfo *dynDispatch, int index);
|
||||
|
||||
/*!
|
||||
* Sets the last error for the current thread. The error will be returned
|
||||
* the next time the app calls eglGetError().
|
||||
*
|
||||
* This function will override a call to \c setLastVendor, and vice-versa.
|
||||
*/
|
||||
void (* setEGLError) (EGLint errorCode);
|
||||
|
||||
/*!
|
||||
* Notifies libEGL about the vendor library that an EGL function is
|
||||
* dispatched to. This is used to look up the last EGL error code from a
|
||||
* vendor.
|
||||
*
|
||||
* A vendor library may generate an EGL error asynchronously, if it
|
||||
* offloads some EGL functions onto a worker thread. In that case, calling
|
||||
* \c setEGLError to set the last error would not work.
|
||||
*
|
||||
* When an EGL dispatch stubs finds the vendor library, it must call this
|
||||
* function before it dispatches the function call.
|
||||
*
|
||||
* This function will override a call to \c setEGLError, and vice-versa.
|
||||
*
|
||||
* \param vendor The vendor library of the current EGL function call.
|
||||
* \return EGL_TRUE on success, or EGL_FALSE on failure.
|
||||
*/
|
||||
EGLBoolean (* setLastVendor) (__EGLvendorInfo *vendor);
|
||||
|
||||
/************************************************************************
|
||||
* These routines are used by vendor dispatch functions to look up
|
||||
* and add mappings between various objects and vendors.
|
||||
************************************************************************/
|
||||
|
||||
// As far as I can tell, all EGL functions that take a context or drawable
|
||||
// also take an EGLDisplay. So, we don't need any extra functions for
|
||||
// mapping a context/surface/whatever to a EGLDisplay or vendor.
|
||||
|
||||
/*!
|
||||
* Returns the EGL vendor for an EGLDisplay handle.
|
||||
*/
|
||||
__EGLvendorInfo *(*getVendorFromDisplay)(EGLDisplay dpy);
|
||||
|
||||
/*!
|
||||
* Returns the EGL vendor for an EGLDeviceEXT handle.
|
||||
*/
|
||||
__EGLvendorInfo *(*getVendorFromDevice)(EGLDeviceEXT dev);
|
||||
|
||||
/**
|
||||
* Sets the EGL vendor for an EGLDeviceEXT handle. The dispatch stub for
|
||||
* any function that returns an EGLDeviceEXT handle should call this.
|
||||
*
|
||||
* Supported since ABI version 1.2.
|
||||
*/
|
||||
EGLBoolean (* setVendorForDevice)(EGLDeviceEXT dev, __EGLvendorInfo *vendor);
|
||||
} __EGLapiExports;
|
||||
|
||||
/*****************************************************************************
|
||||
* API library imports *
|
||||
*****************************************************************************/
|
||||
|
||||
/*!
|
||||
* The enum values accepted by \c __EGLapiImports::getVendorString.
|
||||
*/
|
||||
enum
|
||||
{
|
||||
/*!
|
||||
* The set of platform extensions that the vendor supports.
|
||||
*
|
||||
* Platform extensions typically just add enums to the existing
|
||||
* eglGetPlatformDisplay function, so we don't need any additional logic
|
||||
* or special handling from libEGL itself.
|
||||
*
|
||||
* As a result, vendor libraries can add these extensions without having
|
||||
* to modify libEGL to match.
|
||||
*/
|
||||
__EGL_VENDOR_STRING_PLATFORM_EXTENSIONS,
|
||||
};
|
||||
|
||||
/*!
|
||||
* This structure stores required and optional vendor library callbacks.
|
||||
*/
|
||||
typedef struct __EGLapiImportsRec {
|
||||
/**
|
||||
* Creates an EGLDisplay. This function is used to handle both
|
||||
* \c eglGetDisplay and \c eglGetPlatformDisplay.
|
||||
*
|
||||
* For some platform types, libEGL may be able to identify a specific
|
||||
* vendor to use.
|
||||
*
|
||||
* If libEGL can't figure out which vendor to use on its own, then it will
|
||||
* go through the list of available vendor libraries and call this function
|
||||
* until one succeeds.
|
||||
*
|
||||
* If the application calls eglGetPlatformDisplay, then the parameters are
|
||||
* passed through from the application.
|
||||
*
|
||||
* If the application calls eglGetDisplay, and the native display handle is
|
||||
* not \c EGL_DEFAULT_DISPLAY, then libEGL will try to guess a platform
|
||||
* type, and will pass that platform to the vendor library.
|
||||
*
|
||||
* Lastly, if eglGetDisplay is called with \c EGL_DEFAULT_DISPLAY, then
|
||||
* libEGL will call into each vendor library with \p platform set to
|
||||
* \c EGL_NONE. The vendor library can then select a default display to
|
||||
* return.
|
||||
*
|
||||
* In all cases, if the vendor library can't find a matching EGLDisplay,
|
||||
* then it should return \c EGL_NO_DISPLAY. Any errors should be reported
|
||||
* through the vendor's \c eglGetError function.
|
||||
*/
|
||||
EGLDisplay (* getPlatformDisplay) (EGLenum platform, void *nativeDisplay,
|
||||
const EGLAttrib *attrib_list);
|
||||
|
||||
/*!
|
||||
* Checks if the vendor library supports a given client API (that is, the
|
||||
* API value passed to \c eglBindAPI).
|
||||
*/
|
||||
EGLBoolean (* getSupportsAPI) (EGLenum api);
|
||||
|
||||
/*!
|
||||
* (OPTIONAL) Returns a string from the vendor library. This is used for
|
||||
* anything that isn't available from eglQueryString.
|
||||
*/
|
||||
const char * (* getVendorString) (int name);
|
||||
|
||||
/*
|
||||
* NOTE: libEGL will load all of the vendor libraries up front, so it
|
||||
* handles extension functions slightly differently than EGL.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* This retrieves the pointer to the real EGL or core GL function.
|
||||
*
|
||||
* \param procName The name of the function.
|
||||
* \return A pointer to a function, or \c NULL if the vendor does not
|
||||
* support the function.
|
||||
*/
|
||||
void * (* getProcAddress) (const char *procName);
|
||||
|
||||
/*!
|
||||
* This retrieves vendor-neutral functions which use the
|
||||
* __EGLdispatchTableDynamic API above to dispatch to the correct vendor.
|
||||
*
|
||||
* A vendor library must provide a dispatch function for all EGL display
|
||||
* extension functions that it supports.
|
||||
*
|
||||
* Client extension functions cannot be dispatched based on an EGDisplay,
|
||||
* so they must be handled in libEGL itself.
|
||||
*
|
||||
* \param procName The name of the function.
|
||||
* \return A pointer to a function, or \c NULL if the vendor does not
|
||||
* support the function or \p procName is not a EGL display function.
|
||||
*/
|
||||
void * (*getDispatchAddress) (const char *procName);
|
||||
|
||||
/*!
|
||||
* This notifies the vendor library which dispatch table index is
|
||||
* assigned to a particular EGL extension function.
|
||||
*/
|
||||
void (*setDispatchIndex) (const char *procName, int index);
|
||||
|
||||
/*
|
||||
* The vendor library may use the isPatchSupported, initiatePatch,
|
||||
* releasePatch, and patchThreadAttach callbacks to re-write libglvnd's
|
||||
* entrypoints at make current time, provided no other contexts are current
|
||||
* and the TLS model supports this functionality. This is a performance
|
||||
* optimization that may not be available at runtime; the vendor library
|
||||
* must not depend on this functionality for correctness.
|
||||
*
|
||||
* To use this optimization, the vendor library must provide at least the
|
||||
* isPatchSupported and initiatePatch entrypoints.
|
||||
*
|
||||
* Note that these functions are identical to the ones used in GLX.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* (OPTIONAL) Checks to see if the vendor library supports patching the
|
||||
* given stub type and size.
|
||||
*
|
||||
* \param type The type of entrypoints. This will be a one of the
|
||||
* __GLDISPATCH_STUB_* values.
|
||||
* \param stubSize The maximum size of the stub that the vendor library can
|
||||
* write, in bytes.
|
||||
* \param lookupStubOffset A callback into libglvnd to look up the address
|
||||
* of each entrypoint.
|
||||
*/
|
||||
GLboolean (* isPatchSupported)(int type, int stubSize);
|
||||
|
||||
/*!
|
||||
* (OPTIONAL) Called by libglvnd to request that a vendor library patch its
|
||||
* top-level entrypoints.
|
||||
*
|
||||
* The vendor library should use the \p lookupStubOffset callback to find
|
||||
* the addresses of each entrypoint.
|
||||
*
|
||||
* This function may be called more than once to patch multiple sets of
|
||||
* entrypoints. For example, depending on how they're built, libOpenGL.so
|
||||
* or libGL.so may have their own entrypoints that are separate functions
|
||||
* from the ones in libGLdispatch.
|
||||
*
|
||||
* Note that during this call is the only time that the entrypoints can be
|
||||
* modified. After the call to \c initiatePatch returns, the vendor library
|
||||
* should treat the entrypoints as read-only.
|
||||
*
|
||||
* \param type The type of entrypoints. This will be a one of the
|
||||
* __GLDISPATCH_STUB_* values.
|
||||
* \param stubSize The maximum size of the stub that the vendor library can
|
||||
* write, in bytes.
|
||||
* \param lookupStubOffset A callback into libglvnd to look up the address
|
||||
* of each entrypoint.
|
||||
*
|
||||
* \return GL_TRUE if the vendor library supports patching with this type
|
||||
* and size.
|
||||
*/
|
||||
GLboolean (*initiatePatch)(int type,
|
||||
int stubSize,
|
||||
DispatchPatchLookupStubOffset lookupStubOffset);
|
||||
|
||||
/*!
|
||||
* (OPTIONAL) Called by libglvnd to notify the current vendor that it no
|
||||
* longer owns the top-level entrypoints.
|
||||
*
|
||||
* Libglvnd will take care of the restoring the entrypoints back to their
|
||||
* original state. The vendor library must not try to modify them.
|
||||
*/
|
||||
void (*releasePatch)(void);
|
||||
|
||||
/*!
|
||||
* (OPTIONAL) Called at the start of window-system functions (GLX and EGL).
|
||||
* This callback allows vendor libraries to perform any per-thread
|
||||
* initialization.
|
||||
*
|
||||
* This is basically a workaround for broken applications. A lot of apps
|
||||
* will make one or more invalid GLX/EGL calls on a thread (often including
|
||||
* a MakeCurrent with invalid parameters), and then will try to call an
|
||||
* OpenGL function.
|
||||
*
|
||||
* A non-libglvnd-based driver would be able to initialize any thread state
|
||||
* even on a bogus GLX call, but with libglvnd, those calls wouldn't get
|
||||
* past libGLX.
|
||||
*
|
||||
* This function is optional. If it's \c NULL, then libGLdispatch will
|
||||
* simply ignore it.
|
||||
*
|
||||
* \note This function may be called concurrently from multiple threads.
|
||||
*/
|
||||
void (*patchThreadAttach)(void);
|
||||
|
||||
/*!
|
||||
* (OPTIONAL) Tries to determine the platform type for a native display.
|
||||
*
|
||||
* If the vendor library provides this function, then libglvnd will call it
|
||||
* to determine which platform to use for a native display handle in
|
||||
* eglGetDisplay.
|
||||
*
|
||||
* If no vendor library identifies the platform, then libglvnd will fall
|
||||
* back to its own platform detection logic.
|
||||
*
|
||||
* Libglvnd can call this function for any native display handle except
|
||||
* \c EGL_DEFAULT_DISPLAY.
|
||||
*
|
||||
* No matter what the value of \p native_display, the vendor library must
|
||||
* not crash, and must not return a false match. If the vendor library
|
||||
* can't identify the display, then it must return \c EGL_NONE.
|
||||
*
|
||||
* In particular, that means that a vendor library must not return any sort
|
||||
* of default or fallback platform.
|
||||
*
|
||||
* \param native_display The native display handle passed to eglGetDisplay.
|
||||
* \return Either a platform type enum or EGL_NONE.
|
||||
*/
|
||||
EGLenum (* findNativeDisplayPlatform) (void *native_display);
|
||||
} __EGLapiImports;
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#define __EGL_MAIN_PROTO_NAME "__egl_Main"
|
||||
|
||||
typedef EGLBoolean (* __PFNEGLMAINPROC) (uint32_t version, const __EGLapiExports *exports,
|
||||
__EGLvendorInfo *vendor, __EGLapiImports *imports);
|
||||
|
||||
/*!
|
||||
* Vendor libraries must export a function called __egl_Main() with the
|
||||
* following prototype.
|
||||
*
|
||||
* This function also performs a handshake based on the ABI version number.
|
||||
* Vendor libraries can optionally use the version number to support older
|
||||
* versions of the ABI.
|
||||
*
|
||||
* \param[in] version The ABI version. The upper 16 bits contains the major version
|
||||
* number, and the lower 16 bits contains the minor version number.
|
||||
*
|
||||
* \param[in] exports The table of functions provided by libEGL. This pointer will
|
||||
* remain valid for as long as the vendor is loaded.
|
||||
*
|
||||
* \param[in] vendor The opaque pointer used to identify this vendor library. This
|
||||
* may be used in future versions to provide additional per-vendor information.
|
||||
*
|
||||
* \param[out] imports The function table that the vendor library should fill
|
||||
* in. The vendor library must assign every non-optional function in the
|
||||
* struct.
|
||||
*
|
||||
* \return True on success. If the vendor library does not support the
|
||||
* requested ABI version or if some other error occurs, then it should return
|
||||
* False.
|
||||
*/
|
||||
EGLBoolean __egl_Main(uint32_t version, const __EGLapiExports *exports,
|
||||
__EGLvendorInfo *vendor, __EGLapiImports *imports);
|
||||
|
||||
/*!
|
||||
* @}
|
||||
*/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __LIB_EGL_ABI_H */
|
||||
-104
@@ -403,10 +403,7 @@ set(SOURCE_FILES
|
||||
MobileGL/MG_Impl/GLXImpl/LookUp/LookUp.cpp
|
||||
|
||||
MobileGL/MG_Impl/EGLImpl/Exporting/Definitions.cpp
|
||||
|
||||
MobileGL/MG_Impl/EGLImpl/Exporting/GlvndVendor.cpp
|
||||
MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp
|
||||
MobileGL/MG_Impl/EGLImpl/WaylandWindow.cpp
|
||||
|
||||
# @INSERTION_POINT:SOURCE_FILE_GLIMPL@ #
|
||||
MobileGL/MG_Impl/GLImpl/Sampler/Validators.cpp
|
||||
@@ -437,14 +434,10 @@ set(SOURCE_FILES
|
||||
MobileGL/MG_Backend/Init.cpp
|
||||
MobileGL/MG_Backend/BackendObject.cpp
|
||||
|
||||
MobileGL/MG_Backend/HostFrameBridge.cpp
|
||||
MobileGL/MG_Backend/GbmFrameChannel.cpp
|
||||
|
||||
MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp
|
||||
MobileGL/MG_Backend/DirectGLES/BackendObject_DirectGLES.cpp
|
||||
MobileGL/MG_Backend/DirectGLES/Utils.cpp
|
||||
MobileGL/MG_Backend/DirectGLES/Managers.cpp
|
||||
MobileGL/MG_Backend/DirectGLES/HostFrameTarget.cpp
|
||||
MobileGL/MG_Backend/DirectGLES/MultiDraw.cpp
|
||||
|
||||
MobileGL/MG_Backend/DirectVulkan/DirectVulkan.cpp
|
||||
@@ -647,7 +640,6 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
MobileGL/MG_Remote/FatalFunnel.cpp
|
||||
MobileGL/MG_Remote/Wire/PipeWireCodec.cpp
|
||||
MobileGL/MG_Remote/Client/ClientSession.cpp
|
||||
MobileGL/MG_Remote/Client/DmaBufImport.cpp
|
||||
MobileGL/MG_Remote/Client/EmitTables.cpp
|
||||
MobileGL/MG_Remote/Client/CapsMirror.cpp
|
||||
# P5 c1: the client role's BackendObject. pActiveBackendObject holds one of these
|
||||
@@ -786,9 +778,6 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
# target, and above all no flatc in the build graph. protocol_generated.h
|
||||
# is committed and regenerated by scripts/gen_protocol.py.
|
||||
list(APPEND MOBILEGL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/3rdparty/flatbuffers/include)
|
||||
# The vendored glvnd vendor-ABI headers (3rdparty/glvnd): the entry point a vendor library
|
||||
# exposes so the system libEGL - which IS glvnd - can dispatch to it.
|
||||
list(APPEND MOBILEGL_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/3rdparty/glvnd/include)
|
||||
endif()
|
||||
|
||||
add_library(${CMAKE_PROJECT_NAME} SHARED
|
||||
@@ -826,17 +815,6 @@ target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||
${MOBILEGL_LINK_LIBRARIES}
|
||||
)
|
||||
|
||||
# A LINUX BUILD COMPILES THE DirectVulkan BACKEND BUT HAS NO VULKAN LOADER TO LINK AGAINST, so the
|
||||
# resulting shared library carries undefined vk* symbols - and that is not theoretical: glvnd dlopens
|
||||
# this file as the EGL vendor with RTLD_NOW, so the load fails outright with "undefined symbol:
|
||||
# vkGetQueryPoolResults" (measured on the phone's container). Android links the loader already; on
|
||||
# Linux the caller passes the runtime's own libvulkan.so.1, and leaving the variable empty keeps the
|
||||
# previous behaviour for every build that has no Vulkan runtime to point at.
|
||||
set(MOBILEGL_VULKAN_LOADER "" CACHE FILEPATH "Vulkan loader (libvulkan.so.1) to link into the GL library")
|
||||
if (UNIX AND NOT ANDROID AND MOBILEGL_VULKAN_LOADER)
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${MOBILEGL_VULKAN_LOADER})
|
||||
endif()
|
||||
|
||||
target_compile_definitions(${CMAKE_PROJECT_NAME}
|
||||
PUBLIC
|
||||
${MOBILEGL_COMPILE_DEF}
|
||||
@@ -903,68 +881,6 @@ if(NOT ANDROID)
|
||||
)
|
||||
endif()
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# MobileGLGbm: the GBM drop-in the container's compositor loads.
|
||||
#
|
||||
# kwin - the Wayland compositor in the container half of the split - allocates the
|
||||
# buffers it renders into and scans out through libgbm, and the dma-buf fds it gets
|
||||
# back are what the Anland display producer ships to the phone. Mesa's libgbm cannot
|
||||
# serve that: its buffers belong to the host GPU, and the phone would receive a copy
|
||||
# through a path that was never designed to carry one. This target is the library
|
||||
# that is loaded in its place, under the name a loader looks for.
|
||||
#
|
||||
# It is deliberately NOT part of libMobileGL.so. The compositor needs one file named
|
||||
# libgbm.so that it loads instead of Mesa's, and folding this code into the GL
|
||||
# library would put a second GL frontend, a second Vulkan instance and a second
|
||||
# glslang in the compositor's address space to serve an API that shares none of them.
|
||||
#
|
||||
# The include paths below are borrowed rather than linked. Includes.h - which this
|
||||
# library includes for the MobileGL types and the MGLOG macros - pulls in the GL,
|
||||
# EGL, Vulkan, glslang, SPIRV-Cross and xxHash HEADERS transitively, and headers are
|
||||
# all this library wants from them: linking any of those static libraries into a
|
||||
# libgbm would embed a copy of each in a process that already has one.
|
||||
#
|
||||
# -Bsymbolic-functions, for the same reason the main target carries it: the point of
|
||||
# this library is to REPLACE a libgbm that may already be loaded in the process, so
|
||||
# every internal reference has to bind to this file's own definitions rather than to
|
||||
# whatever else the process has under the same names.
|
||||
# ---------------------------------------------------------------------------
|
||||
add_library(MobileGLGbm SHARED
|
||||
MobileGL/MG_Gbm/GbmDevice.cpp
|
||||
# The display host's socket protocol, kept in its own translation unit so that the
|
||||
# allocation paths never have to know how a frame arrives - only that one did.
|
||||
MobileGL/MG_Gbm/GbmHostChannel.cpp
|
||||
MobileGL/MG_Gbm/GbmApi.cpp
|
||||
# MGLOG_I/W/E expand to a call to MobileGL::MG_Util::Debug::Log, and this is the
|
||||
# one translation unit that defines it. It is compiled in rather than linked from
|
||||
# libMobileGL.so because this library has to load into a compositor that has no
|
||||
# libMobileGL in it at all - and because a libgbm with an undefined symbol is a
|
||||
# library that fails on the first diagnostic rather than at a link step somebody
|
||||
# could have read.
|
||||
MobileGL/MG_Util/Debug/Log.cpp
|
||||
)
|
||||
|
||||
# The vendored gbm.h first: this library implements THAT declaration set, and a
|
||||
# system <gbm.h> from another Mesa version on the include path ahead of it would
|
||||
# change the ABI under the implementations in GbmApi.cpp.
|
||||
target_include_directories(MobileGLGbm PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/3rdparty/gbm/include
|
||||
${MOBILEGL_INCLUDE_DIR}
|
||||
${CMAKE_SOURCE_DIR}/3rdparty/glslang
|
||||
${CMAKE_SOURCE_DIR}/3rdparty/SPIRV-Cross
|
||||
${CMAKE_SOURCE_DIR}/3rdparty/xxHash
|
||||
${CMAKE_SOURCE_DIR}/3rdparty/Vulkan-Headers/include
|
||||
)
|
||||
|
||||
set_target_properties(MobileGLGbm PROPERTIES
|
||||
OUTPUT_NAME gbm
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
)
|
||||
|
||||
if (UNIX AND NOT APPLE)
|
||||
target_link_options(MobileGLGbm PRIVATE "LINKER:-Bsymbolic-functions")
|
||||
endif()
|
||||
|
||||
if (TRACY_ENABLE)
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC Tracy::TracyClient)
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME}_s PUBLIC Tracy::TracyClient)
|
||||
@@ -972,19 +888,6 @@ if (TRACY_ENABLE)
|
||||
target_compile_definitions(${CMAKE_PROJECT_NAME}_s PUBLIC -DTRACY_ENABLE)
|
||||
endif ()
|
||||
|
||||
# GLVND, AND WHY THIS IS A LINKER FLAG RATHER THAN A VISIBILITY ONE.
|
||||
#
|
||||
# MobileGL can serve as a glvnd EGL vendor - the library the system's libEGL.so.1 dispatches to -
|
||||
# and a vendor must hand glvnd ITS OWN entry points: glvnd calls whatever address it is given, so
|
||||
# an address that resolves to another libEGL in the process is a call back into the dispatcher.
|
||||
# With default visibility every reference inside this library resolves against the whole process,
|
||||
# and a process that loaded the system libEGL first wins. Marking the entry points protected says
|
||||
# the same thing in the source, except the platform's own GL/EGL headers declare them default and
|
||||
# the two visibilities do not mix; this flag is that promise made by the linker instead.
|
||||
if (UNIX AND NOT APPLE)
|
||||
target_link_options(${CMAKE_PROJECT_NAME} PRIVATE "LINKER:-Bsymbolic-functions")
|
||||
endif()
|
||||
|
||||
if (ANDROID)
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC
|
||||
android
|
||||
@@ -1253,10 +1156,3 @@ if (ANDROID AND MOBILEGL_BUILD_EXTMEM_PROBE)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# The GBM library carries the tree's logger, which reaches Android's own log. The main target gets
|
||||
# these libraries in its own Android block; a library built from the same sources needs them for the
|
||||
# same reason, and without them it is the LINK that fails rather than anything in the code.
|
||||
if (ANDROID)
|
||||
target_link_libraries(MobileGLGbm PRIVATE log android)
|
||||
endif()
|
||||
|
||||
+3
-12
@@ -423,8 +423,9 @@ namespace MobileGL::MG_Config {
|
||||
Uint32 PipeIndexMirrorMb = 64;
|
||||
// MOBILEGL_PIPE_STATS_PERIOD: frames per boundary-counter summary line. 120 is the
|
||||
// steady-state cadence; the device retrace harness never reaches the teardown dump
|
||||
// and a trimmed fixture (create-indirect) is shorter than 120 frames, so a run that
|
||||
// needs its numbers at all sets this low enough to land at least one window.
|
||||
// and a trimmed fixture (minecraft-1.21.1-neoforge-create-indirect-in-world-align1024)
|
||||
// is shorter than 120 frames, so a run that needs its numbers at all sets this low
|
||||
// enough to land at least one window.
|
||||
Uint32 PipeStatsPeriod = 120;
|
||||
// MOBILEGL_PIPE_STATS_FILE: where the boundary counters' teardown JSON dump goes.
|
||||
// Empty (the default) means no dump; the per-120-frame summary line still goes to
|
||||
@@ -499,7 +500,6 @@ namespace MobileGL::MG_Config {
|
||||
enum class IpcSurface : Uint8 {
|
||||
Offscreen = 0, // a window surface is the client's own window, as before (the default)
|
||||
Server = 1, // a window surface is the SERVER's window: WindowKind::ServerOwned
|
||||
Host = 2, // a window surface draws into frames the DISPLAY HOST owns; the host presents
|
||||
};
|
||||
// IpcTable::AdoptTier when MOBILEGL_IPC_ADOPT_TIER is unset (or unparseable): T0 by default,
|
||||
// with QUIET fallbacks. Not a tier a user can type - the knob admits 0..2.
|
||||
@@ -730,15 +730,6 @@ namespace MobileGL::MG_Config {
|
||||
inline Bool ServerOwnedWindowSurfaces() {
|
||||
return Transport == TransportMode::Spawn && Ipc.Surface == IpcSurface::Server;
|
||||
}
|
||||
|
||||
// P12: the other on-screen shape, and the mirror image of the one above. The display host
|
||||
// (the Android side that owns the screen) allocates the frames, offers each one over the
|
||||
// host frame bridge, and puts it on the glass when this side says it is drawn - so a
|
||||
// client that asks for this has no window of its own either, and the server takes the
|
||||
// frames rather than making a window.
|
||||
inline Bool HostFrameWindowSurfaces() {
|
||||
return Transport == TransportMode::Spawn && Ipc.Surface == IpcSurface::Host;
|
||||
}
|
||||
#else
|
||||
// The whole point: in a build without MG_Remote this folds at compile time, so
|
||||
// `if (MG_Config::Transport != MG_Config::TransportMode::Monolith)` in Init.cpp is a
|
||||
|
||||
@@ -494,8 +494,8 @@ namespace MobileGL::MG_ConfigLoader {
|
||||
}
|
||||
}
|
||||
|
||||
// P12 (on-screen): MOBILEGL_IPC_SURFACE = offscreen | server | host (Config.h has the
|
||||
// semantics). An unknown value is named and read as the default, like every knob here.
|
||||
// P12 (on-screen server window): MOBILEGL_IPC_SURFACE = offscreen | server (Config.h has
|
||||
// the semantics). An unknown value is named and read as the default, like every knob here.
|
||||
{
|
||||
String surface;
|
||||
QueryEnvVariable("MOBILEGL_IPC_SURFACE", surface, "offscreen");
|
||||
@@ -505,11 +505,9 @@ namespace MobileGL::MG_ConfigLoader {
|
||||
ipc.Surface = MG_Config::IpcSurface::Offscreen;
|
||||
} else if (surface == "server") {
|
||||
ipc.Surface = MG_Config::IpcSurface::Server;
|
||||
} else if (surface == "host") {
|
||||
ipc.Surface = MG_Config::IpcSurface::Host;
|
||||
} else {
|
||||
MGLOG_W("Config: Ignoring invalid env variable MOBILEGL_IPC_SURFACE='%s'; expected "
|
||||
"offscreen|server|host, using offscreen",
|
||||
"offscreen|server, using offscreen",
|
||||
surface.c_str());
|
||||
ipc.Surface = MG_Config::IpcSurface::Offscreen;
|
||||
}
|
||||
@@ -517,14 +515,12 @@ namespace MobileGL::MG_ConfigLoader {
|
||||
// parses this before RunSession sets its own transport, and has no client half anyway.)
|
||||
const char* role = std::getenv("MOBILEGL_IPC_ROLE");
|
||||
const Bool serverProcess = role != nullptr && std::strcmp(role, "server") == 0;
|
||||
if (ipc.Surface != MG_Config::IpcSurface::Offscreen && !serverProcess &&
|
||||
if (ipc.Surface == MG_Config::IpcSurface::Server && !serverProcess &&
|
||||
MG_Config::Transport != MG_Config::TransportMode::Spawn) {
|
||||
// Said, not silently honoured: there is no remote server here to own a window.
|
||||
MGLOG_W("Config: MOBILEGL_IPC_SURFACE=%s is IGNORED - it asks for an on-screen "
|
||||
"surface (the server's own window, or the frames the display host owns) and "
|
||||
"this run has no remote server to provide one: MOBILEGL_TRANSPORT is not "
|
||||
"spawn. Window surfaces stay the client's own",
|
||||
ipc.Surface == MG_Config::IpcSurface::Server ? "server" : "host");
|
||||
MGLOG_W("Config: MOBILEGL_IPC_SURFACE=server is IGNORED - it asks a remote server "
|
||||
"(MOBILEGL_TRANSPORT=spawn, a fork or tcp:// control) to own the window surface, "
|
||||
"and this run has none. Window surfaces stay the client's own");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-9
@@ -8,8 +8,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
// ============== Platform-specific definitions and macros ============== //
|
||||
// No __ANDROID_API__ pin here on purpose. The effective API level is owned by
|
||||
// the build system (gradle minSdk 26 -> -DANDROID_PLATFORM=android-26, enforced
|
||||
@@ -36,11 +34,6 @@
|
||||
#ifdef _WIN32
|
||||
#define MOBILEGL_EXPORT extern "C" __declspec(dllexport)
|
||||
#else
|
||||
// Default visibility, which is what the platform's own GL and EGL headers declare their entry
|
||||
// points with. The one place where that is not enough - a vendor library handing glvnd its own
|
||||
// entry points, where a reference resolving against the process instead of this library would be a
|
||||
// call back into the dispatcher - is answered at link time with -Bsymbolic-functions rather than
|
||||
// here, because a second visibility on the same declaration does not compile.
|
||||
#define MOBILEGL_EXPORT extern "C" __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
@@ -112,8 +105,8 @@
|
||||
#define MOBILEGL_ASSERT(condition, ...) \
|
||||
do { \
|
||||
if (!(condition)) { \
|
||||
fprintf(stderr, "Assertion failed" __VA_OPT__(": ") "%s", "" __VA_ARGS__); \
|
||||
fprintf(stderr, " at %s:%d (%s)\n", __FILE__, __LINE__, __func__); \
|
||||
MGLOG_F("Assertion failed" __VA_OPT__(": ") __VA_ARGS__); \
|
||||
MGLOG_F(" at %s:%d (%s)", __FILE__, __LINE__, __func__); \
|
||||
TRAP; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@@ -172,15 +172,11 @@ namespace MobileGL::MG_Backend {
|
||||
return false;
|
||||
}
|
||||
|
||||
// A DISPLAY IS A CONNECTION, NOT A RESOURCE THIS BACKEND OWNS, and refusing the second one
|
||||
// refused a caller for a reason that is not there: the surface and context tables are keyed
|
||||
// by the display each was created on, every operation carries its own display handle, and
|
||||
// this field has no reader anywhere - it was the whole of the rule.
|
||||
//
|
||||
// What the rule cost was a compositor. One asks for the display it will draw into AFTER
|
||||
// probing another, so the second eglInitialize is the one that matters, and a refusal there
|
||||
// is reported one layer up as "no usable DRM render device" - the probe having succeeded
|
||||
// and the real display having failed, with nothing in between that says which was refused.
|
||||
if (m_eglDisplayInitialized && m_eglDisplay != dpy) {
|
||||
MGLOG_E("InitializeEGLDisplay failed: backend already bound to a different EGLDisplay");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_eglDisplay = dpy;
|
||||
m_eglDisplayInitialized = true;
|
||||
if (major) {
|
||||
@@ -213,28 +209,6 @@ namespace MobileGL::MG_Backend {
|
||||
return true;
|
||||
}
|
||||
|
||||
// The frame itself is the backend's business (InitHostFrameSurface); what happens here is
|
||||
// the registration every surface kind shares, so the swap path and the state mirrors see
|
||||
// a host-framed surface exactly like any other.
|
||||
Bool BackendObject::CreateEGLHostFrameSurface(EGLSurface surface, Uint32 width, Uint32 height) {
|
||||
const std::lock_guard<std::recursive_mutex> lock(m_eglStateMutex);
|
||||
if (!m_eglDisplayInitialized) {
|
||||
MGLOG_E("CreateEGLHostFrameSurface failed: EGL display is not initialized");
|
||||
return false;
|
||||
}
|
||||
if (surface == EGL_NO_SURFACE) {
|
||||
MGLOG_E("CreateEGLHostFrameSurface failed: invalid EGLSurface");
|
||||
return false;
|
||||
}
|
||||
auto& state = m_eglSurfaces[surface];
|
||||
state = EGLSurfaceState{
|
||||
.Kind = SurfaceKind::HostFrame,
|
||||
.Width = static_cast<EGLint>(std::max<Uint32>(width, 1)),
|
||||
.Height = static_cast<EGLint>(std::max<Uint32>(height, 1)),
|
||||
};
|
||||
return ActivateEGLSurface(surface);
|
||||
}
|
||||
|
||||
Bool BackendObject::CreateEGLPbufferSurface(EGLSurface surface, EGLint width, EGLint height) {
|
||||
const std::lock_guard<std::recursive_mutex> lock(m_eglStateMutex);
|
||||
return RegisterEGLPbufferSurface(surface, width, height) && ActivateEGLSurface(surface);
|
||||
@@ -316,11 +290,6 @@ namespace MobileGL::MG_Backend {
|
||||
MGLOG_E("ActivateEGLSurface failed: backend InitPbufferSurface failed");
|
||||
return false;
|
||||
}
|
||||
} else if (surfaceState->Kind == SurfaceKind::HostFrame) {
|
||||
if (!InitHostFrameSurface(surfaceState->Width, surfaceState->Height)) {
|
||||
MGLOG_E("ActivateEGLSurface failed: backend InitHostFrameSurface failed");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
MGLOG_E("ActivateEGLSurface failed: unsupported surface kind");
|
||||
return false;
|
||||
@@ -346,29 +315,6 @@ namespace MobileGL::MG_Backend {
|
||||
MGLOG_E("MakeEGLCurrent failed: EGL display mismatch or not initialized");
|
||||
return false;
|
||||
}
|
||||
// EGL_KHR_surfaceless_context. A context whose draw and read surfaces are both absent has
|
||||
// no framebuffer of its own to be bound to: the caller draws into framebuffers it binds
|
||||
// itself, and this side only has to have its own GL context current on this thread for the
|
||||
// records that follow. Everything below this point describes a surface, so none of it
|
||||
// applies - and what is recorded is exactly what was asked for, so a later swap on a
|
||||
// surface that does not exist is never made to look like one that does.
|
||||
if (draw == EGL_NO_SURFACE && read == EGL_NO_SURFACE && ctx != EGL_NO_CONTEXT) {
|
||||
if (!m_backendCapabilitiesInitialized) {
|
||||
if (!InitCapabilities()) {
|
||||
MGLOG_E("MakeEGLCurrent failed: InitCapabilities failed");
|
||||
return false;
|
||||
}
|
||||
m_backendCapabilitiesInitialized = true;
|
||||
}
|
||||
ReleaseEGLCurrentThread(threadKey);
|
||||
m_eglCurrentThreads[threadKey] = EGLCurrentState{
|
||||
.Display = dpy,
|
||||
.DrawSurface = EGL_NO_SURFACE,
|
||||
.ReadSurface = EGL_NO_SURFACE,
|
||||
.Context = ctx,
|
||||
};
|
||||
return true;
|
||||
}
|
||||
if (!m_eglSurfaceInitialized) {
|
||||
if (draw != read || !ActivateEGLSurface(draw)) {
|
||||
MGLOG_E("MakeEGLCurrent failed: EGL surface is not initialized");
|
||||
@@ -441,12 +387,6 @@ namespace MobileGL::MG_Backend {
|
||||
return false;
|
||||
}
|
||||
|
||||
// A host-framed surface has no swapchain: presenting it means telling the host the frame
|
||||
// is drawn, because the host is what puts it on the glass.
|
||||
if (m_eglSurfaceKind == SurfaceKind::HostFrame) {
|
||||
return PresentHostFrame();
|
||||
}
|
||||
|
||||
const auto& backendFunctions = GetBackendFunctions();
|
||||
if (!backendFunctions.Present) {
|
||||
MGLOG_E("SwapEGLBuffers failed: backend Present function is null");
|
||||
@@ -464,27 +404,6 @@ namespace MobileGL::MG_Backend {
|
||||
}
|
||||
}
|
||||
|
||||
// A backend that has no host-framed surfaces says so by name: the server may ask for one
|
||||
// (MOBILEGL_IPC_SURFACE=host) against a build that cannot serve it, and that has to be a
|
||||
// refusal with a reason rather than a surface that draws nowhere.
|
||||
Bool BackendObject::InitHostFrameSurface(EGLint width, EGLint height) {
|
||||
(void)width;
|
||||
(void)height;
|
||||
MGLOG_E("InitHostFrameSurface: this backend has no host-framed surfaces");
|
||||
return false;
|
||||
}
|
||||
|
||||
Bool BackendObject::PresentHostFrame() {
|
||||
MGLOG_E("PresentHostFrame: this backend has no host-framed surfaces");
|
||||
return false;
|
||||
}
|
||||
|
||||
Bool BackendObject::PresentHostFrameIfCurrent() {
|
||||
const std::lock_guard<std::recursive_mutex> lock(m_eglStateMutex);
|
||||
if (!m_eglSurfaceInitialized || m_eglSurfaceKind != SurfaceKind::HostFrame) return true;
|
||||
return PresentHostFrame();
|
||||
}
|
||||
|
||||
Bool BackendObject::IsEGLSurfaceCurrent(EGLSurface surface) const {
|
||||
if (surface == EGL_NO_SURFACE) {
|
||||
return false;
|
||||
|
||||
@@ -595,18 +595,6 @@ namespace MobileGL {
|
||||
virtual Bool CreateEGLWindowSurface(EGLSurface surface, const WindowHandle& handle);
|
||||
virtual Bool ResizeEGLWindowSurface(EGLSurface surface, Uint32 width, Uint32 height);
|
||||
virtual Bool CreateEGLPbufferSurface(EGLSurface surface, EGLint width, EGLint height);
|
||||
// The host owns the screen: this side never gets a window of the client's to draw
|
||||
// into, so the surface it draws into is a frame the host allocated and offered over
|
||||
// the host frame bridge. Each swap tells the host the frame is done and takes the
|
||||
// next; presentation is the host's, not a swapchain's.
|
||||
virtual Bool CreateEGLHostFrameSurface(EGLSurface surface, Uint32 width, Uint32 height);
|
||||
virtual Bool InitHostFrameSurface(EGLint width, EGLint height);
|
||||
virtual Bool PresentHostFrame();
|
||||
// The present RECORD's half of a host-framed swap. A split client's swap reaches the
|
||||
// server as a present record (ServerVerbSink::OnPresent), never as SwapEGLBuffers, so
|
||||
// without this the host was never told a frame was drawn. True when the current
|
||||
// surface is not host-framed: there is nothing to present then.
|
||||
Bool PresentHostFrameIfCurrent();
|
||||
virtual Bool MakeEGLCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
|
||||
virtual Bool SwapEGLBuffers(EGLDisplay dpy, EGLSurface draw);
|
||||
// Forwards the app-requested eglSwapInterval to the backend's native
|
||||
@@ -628,11 +616,7 @@ namespace MobileGL {
|
||||
enum class SurfaceKind {
|
||||
None,
|
||||
Window,
|
||||
Pbuffer,
|
||||
// A surface whose drawing target is a frame the display host owns. There is no
|
||||
// swapchain behind it: the host puts the frame on the glass when this side says
|
||||
// it is drawn, which is why presenting one is its own call and not a Present.
|
||||
HostFrame
|
||||
Pbuffer
|
||||
};
|
||||
|
||||
struct EGLCurrentState {
|
||||
|
||||
@@ -6,12 +6,6 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED && defined(__ANDROID__)
|
||||
// The role's own backend is resolved the way Utils.cpp (C6 / ID-52) resolves it; that needs this
|
||||
// header, and it has to be included at file scope - a header included inside this file's namespace
|
||||
// would nest its own namespace under it.
|
||||
#include <MG_Remote/Server/ServerLoop.h>
|
||||
#endif
|
||||
#include "BackendObject_DirectGLES.h"
|
||||
#include "MG_Backend/BackendObject.h"
|
||||
#include "MG_Backend/BackendObjects.h"
|
||||
@@ -1034,241 +1028,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
#endif
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED && defined(__ANDROID__)
|
||||
namespace {
|
||||
// The host may still be starting when the client asks for its surface: it is a separate
|
||||
// app that has to come up and allocate its pool. Waiting is better than refusing a
|
||||
// surface a client is entitled to, and the wait is answered by name if it expires.
|
||||
constexpr Int kHostFrameWaitMs = 30000;
|
||||
}
|
||||
|
||||
Bool TakeHostFrameForExternalTexture(Uint width, Uint height) {
|
||||
// THIS ROLE'S OWN BACKEND, resolved exactly the way ActiveBackendFormatCaps (Utils.cpp,
|
||||
// C6 / ID-52) resolves it: under a live split session the SERVER's private backend owns the
|
||||
// context on the apply thread, and pActiveBackendObject is the CLIENT's mirror there.
|
||||
MG_Backend::BackendObject* backend = nullptr;
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith) {
|
||||
backend = MG_Remote::Server::ServerLoopInstance().Backend();
|
||||
} else {
|
||||
backend = MG_Backend::pActiveBackendObject.get();
|
||||
}
|
||||
if (backend == nullptr) return false;
|
||||
return backend->InitHostFrameSurface(static_cast<EGLint>(width), static_cast<EGLint>(height));
|
||||
}
|
||||
|
||||
Bool BackendObject_DirectGLES::InitHostFrameSurface(EGLint width, EGLint height) {
|
||||
// The EGL context comes from the same place a pbuffer session's does. What changes is not
|
||||
// how this side draws but what it draws INTO: a frame the display host allocated, bound as
|
||||
// this context's framebuffer. The pbuffer stays as the draw target for the moment before
|
||||
// the first frame arrives, which is the only moment it is used.
|
||||
if (!DirectGLES::InitPbufferSurface(width, height)) {
|
||||
MGLOG_E("InitHostFrameSurface: the context the host frames are drawn in did not come up");
|
||||
return false;
|
||||
}
|
||||
if (!m_hostFrameBridgeOpen) {
|
||||
String why;
|
||||
if (!m_hostFrameBridge.Open(MG_Backend::kHostFrameSocket, kHostFrameWaitMs, why)) {
|
||||
MGLOG_E("InitHostFrameSurface: no display host: %s", why.c_str());
|
||||
return false;
|
||||
}
|
||||
m_hostFrameBridgeOpen = true;
|
||||
}
|
||||
return TakeHostFrame();
|
||||
}
|
||||
|
||||
Bool BackendObject_DirectGLES::TakeHostFrame() {
|
||||
String why;
|
||||
struct AHardwareBuffer* frame = nullptr;
|
||||
MG_Backend::HostFrameOffer offer{};
|
||||
if (!m_hostFrameBridge.Acquire(&frame, offer, why)) {
|
||||
MGLOG_E("TakeHostFrame: %s", why.c_str());
|
||||
return false;
|
||||
}
|
||||
HostFrameTarget target;
|
||||
if (!HostFrameTargetCreate(frame, target, why)) {
|
||||
MGLOG_E("TakeHostFrame: the host frame %ux%u did not become a draw target: %s", offer.Width,
|
||||
offer.Height, why.c_str());
|
||||
AHardwareBuffer_release(frame);
|
||||
return false;
|
||||
}
|
||||
DestroyHostFrame();
|
||||
m_hostFrameTarget = target;
|
||||
m_hostFrameBuffer = frame;
|
||||
m_hostFrameOffer = offer;
|
||||
// The canvas is made at the first frame's size and kept; a failure leaves the frame itself
|
||||
// as the draw target, which is how this path behaved before the canvas existed.
|
||||
if (!EnsureHostFrameCanvas(target.Width, target.Height))
|
||||
MGLOG_E_ONCE("TakeHostFrame: no canvas in front of the host frames; drawing into the frame itself");
|
||||
const HostFrameTarget& drawTarget = HostFrameDrawTarget();
|
||||
// BEFORE the bind: every default-framebuffer bind the engine makes from here on has to
|
||||
// resolve to this target, and that resolution is what this global is.
|
||||
g_hostFrameFramebufferId = drawTarget.Framebuffer;
|
||||
// Published together with the framebuffer, because they describe the same target: the STORAGE
|
||||
// an attachment is bound to when the client's texture has none of its own, and the SIZE that
|
||||
// decides whether binding it is right at all.
|
||||
g_hostFrameRenderbuffer = drawTarget.Renderbuffer;
|
||||
g_hostFrameWidth = drawTarget.Width;
|
||||
g_hostFrameHeight = drawTarget.Height;
|
||||
FramebufferImpl::InvalidateFramebufferBindingCache();
|
||||
HostFrameTargetBind(drawTarget);
|
||||
// AND ON TO THE CONTAINER, as the dma-buf descriptor behind it. The Wayland compositor
|
||||
// over there renders into THESE frames - it runs this project's own GBM, whose
|
||||
// gbm_bo_create answers with the phone's frame instead of an allocation of its own - so
|
||||
// every frame taken here is useless to it until its descriptor has crossed. Open() binds
|
||||
// the listening socket a container dials, and the IsUp() test keeps the ordinary frame
|
||||
// down to an integer compare: the socket outlives every container and every connection,
|
||||
// while OfferFrame accepts whoever dialled since the last frame and opens the socket
|
||||
// itself when the first frame arrives before any container has.
|
||||
//
|
||||
// NEITHER ANSWER IS EXAMINED, and that is the channel's contract rather than an
|
||||
// oversight: no container running, a container that has died, or one that has taken the
|
||||
// descriptor and stopped reading must all leave this frame drawn and presented exactly as
|
||||
// it would have been without a channel - the descriptor is a copy of the pixels' route,
|
||||
// not a step in producing them.
|
||||
if (!m_gbmFrameChannel.IsUp()) m_gbmFrameChannel.Open();
|
||||
(void)m_gbmFrameChannel.OfferFrame(frame, offer);
|
||||
MGLOG_I("host frame %u is the draw target: %ux%u", offer.Index, target.Width, target.Height);
|
||||
return true;
|
||||
}
|
||||
|
||||
void BackendObject_DirectGLES::DestroyHostFrame() {
|
||||
// The canvas outlives the frame, so with one the globals keep naming it: the attachments
|
||||
// made over it stay valid between this frame being handed back and the next one arriving.
|
||||
g_hostFrameFramebufferId = m_hostFrameCanvas.Framebuffer;
|
||||
g_hostFrameRenderbuffer = m_hostFrameCanvas.Renderbuffer;
|
||||
g_hostFrameWidth = m_hostFrameCanvas.Width;
|
||||
g_hostFrameHeight = m_hostFrameCanvas.Height;
|
||||
HostFrameTargetDestroy(m_hostFrameTarget);
|
||||
if (m_hostFrameBuffer != nullptr) {
|
||||
AHardwareBuffer_release(m_hostFrameBuffer);
|
||||
m_hostFrameBuffer = nullptr;
|
||||
}
|
||||
// AND NOTHING IS SAID TO THE CHANNEL HERE, which is the fix rather than an omission. This
|
||||
// runs once per presented frame: it used to Close() the channel (unlinking the container's
|
||||
// socket node and dropping its connection sixty times a second - measured: connect()
|
||||
// answered EAGAIN(11) on every attempt) and it used to tell the channel to forget the frame,
|
||||
// which left the ONE window a compositor's first allocations arrive in - between this frame
|
||||
// being presented and the host handing the next one over, i.e. inside Complete() above -
|
||||
// with nothing to answer a dialer with. A compositor allocates its swapchain ONCE and keeps
|
||||
// those buffers for the life of the process, so a dialer that finds nothing here renders
|
||||
// its whole life into buffers nobody displays. The frame the channel remembers is the last
|
||||
// one the host handed over: the next offer replaces it and Close() releases it.
|
||||
}
|
||||
|
||||
Bool BackendObject_DirectGLES::PresentHostFrame() {
|
||||
// When this returns, the pixels are complete: glFinish is the fence the host is told
|
||||
// about, and the host's own readback - which Complete reads - is what proves the drawing
|
||||
// landed where the screen will look.
|
||||
BlitHostFrameCanvas();
|
||||
if (g_GLESFuncs.glFinish != nullptr) g_GLESFuncs.glFinish();
|
||||
// WHAT THE CONTAINER SAID WHILE THIS FRAME WAS BEING DRAWN. This is the one place the
|
||||
// server's apply loop passes through the host channel - the swap it runs lands here for a
|
||||
// host-framed surface - and a release is the container's compositor saying it is done
|
||||
// reading a frame this side handed over. Poll() is a bare recvmsg on a non-blocking
|
||||
// socket: with no container connected it returns on its first test, and a container that
|
||||
// is between frames answers EAGAIN, so a pass costs nothing when there is nothing to
|
||||
// read. Nothing here is waited for and nothing is required to arrive; the count of
|
||||
// frames offered and not released is a number the channel keeps for the log, never a
|
||||
// frame the render path waits on.
|
||||
m_gbmFrameChannel.Poll();
|
||||
String why;
|
||||
if (!m_hostFrameBridge.Complete(m_hostFrameOffer, /*imported=*/true, /*drawn=*/true, /*fenceOk=*/true, why)) {
|
||||
MGLOG_E("PresentHostFrame: %s", why.c_str());
|
||||
return false;
|
||||
}
|
||||
// The answer has been read, so the host has already put this frame on the glass: it is
|
||||
// this side's to drop, and the next one becomes the drawing target.
|
||||
DestroyHostFrame();
|
||||
return TakeHostFrame();
|
||||
}
|
||||
|
||||
Bool BackendObject_DirectGLES::EnsureHostFrameCanvas(Uint width, Uint height) {
|
||||
if (m_hostFrameCanvas.Framebuffer != 0) return true;
|
||||
if (width == 0 || height == 0 || !g_GLESFuncs.glRenderbufferStorage || !g_GLESFuncs.glBlitFramebuffer ||
|
||||
!g_GLESFuncs.glGenRenderbuffers || !g_GLESFuncs.glGenFramebuffers || !g_GLESFuncs.glCheckFramebufferStatus)
|
||||
return false;
|
||||
// RAW binds, as HostFrameTargetCreate makes them: the caller invalidates the engine's
|
||||
// framebuffer shadow and binds through it right after.
|
||||
GLuint renderbuffer = 0;
|
||||
g_GLESFuncs.glGenRenderbuffers(1, &renderbuffer);
|
||||
g_GLESFuncs.glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
|
||||
// The frames are R8G8B8A8_UNORM (the display host allocates them so), and so is this.
|
||||
g_GLESFuncs.glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, static_cast<GLsizei>(width),
|
||||
static_cast<GLsizei>(height));
|
||||
GLuint framebuffer = 0;
|
||||
g_GLESFuncs.glGenFramebuffers(1, &framebuffer);
|
||||
g_GLESFuncs.glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
g_GLESFuncs.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
|
||||
const GLenum status = g_GLESFuncs.glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||
MGLOG_E("host frame canvas %ux%u: framebuffer status 0x%04x", width, height, status);
|
||||
g_GLESFuncs.glDeleteFramebuffers(1, &framebuffer);
|
||||
g_GLESFuncs.glDeleteRenderbuffers(1, &renderbuffer);
|
||||
return false;
|
||||
}
|
||||
m_hostFrameCanvas.Renderbuffer = renderbuffer;
|
||||
m_hostFrameCanvas.Framebuffer = framebuffer;
|
||||
m_hostFrameCanvas.Width = width;
|
||||
m_hostFrameCanvas.Height = height;
|
||||
MGLOG_I("host frame canvas: %ux%u as framebuffer %u (renderbuffer %u), copied into each frame at present",
|
||||
width, height, framebuffer, renderbuffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
void BackendObject_DirectGLES::BlitHostFrameCanvas() {
|
||||
if (m_hostFrameCanvas.Framebuffer == 0 || m_hostFrameTarget.Framebuffer == 0) return;
|
||||
// Whatever the compositor had bound is put back as it was, raw for raw, so the engine's
|
||||
// shadow (which never saw this) is still right afterwards. The scissor test and
|
||||
// rasterizer discard both apply to a blit, so they are lifted for it.
|
||||
GLint readBinding = 0;
|
||||
GLint drawBinding = 0;
|
||||
g_GLESFuncs.glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &readBinding);
|
||||
g_GLESFuncs.glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &drawBinding);
|
||||
const GLboolean scissor = g_GLESFuncs.glIsEnabled(GL_SCISSOR_TEST);
|
||||
const GLboolean discard = g_GLESFuncs.glIsEnabled(GL_RASTERIZER_DISCARD);
|
||||
if (scissor) g_GLESFuncs.glDisable(GL_SCISSOR_TEST);
|
||||
if (discard) g_GLESFuncs.glDisable(GL_RASTERIZER_DISCARD);
|
||||
g_GLESFuncs.glBindFramebuffer(GL_READ_FRAMEBUFFER, m_hostFrameCanvas.Framebuffer);
|
||||
g_GLESFuncs.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_hostFrameTarget.Framebuffer);
|
||||
const Bool sameSize = m_hostFrameCanvas.Width == m_hostFrameTarget.Width &&
|
||||
m_hostFrameCanvas.Height == m_hostFrameTarget.Height;
|
||||
g_GLESFuncs.glBlitFramebuffer(0, 0, static_cast<GLint>(m_hostFrameCanvas.Width),
|
||||
static_cast<GLint>(m_hostFrameCanvas.Height), 0, 0,
|
||||
static_cast<GLint>(m_hostFrameTarget.Width),
|
||||
static_cast<GLint>(m_hostFrameTarget.Height), GL_COLOR_BUFFER_BIT,
|
||||
sameSize ? GL_NEAREST : GL_LINEAR);
|
||||
g_GLESFuncs.glBindFramebuffer(GL_READ_FRAMEBUFFER, static_cast<GLuint>(readBinding));
|
||||
g_GLESFuncs.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, static_cast<GLuint>(drawBinding));
|
||||
if (scissor) g_GLESFuncs.glEnable(GL_SCISSOR_TEST);
|
||||
if (discard) g_GLESFuncs.glEnable(GL_RASTERIZER_DISCARD);
|
||||
}
|
||||
|
||||
#else // !(MOBILEGL_BUILD_DISAGGREGATED && __ANDROID__)
|
||||
|
||||
// The other arm's half: on a build with no host frames there is no frame to take, and the
|
||||
// attach site's ordinary path (a storage-less external texture, exactly as before) is the honest
|
||||
// behaviour there rather than a link error.
|
||||
Bool TakeHostFrameForExternalTexture(Uint, Uint) { return false; }
|
||||
|
||||
Bool BackendObject_DirectGLES::InitHostFrameSurface(EGLint width, EGLint height) {
|
||||
(void)width;
|
||||
(void)height;
|
||||
MGLOG_E("InitHostFrameSurface: host frames are a disaggregated Android path");
|
||||
return false;
|
||||
}
|
||||
|
||||
Bool BackendObject_DirectGLES::TakeHostFrame() { return false; }
|
||||
void BackendObject_DirectGLES::DestroyHostFrame() {}
|
||||
Bool BackendObject_DirectGLES::EnsureHostFrameCanvas(Uint, Uint) { return false; }
|
||||
void BackendObject_DirectGLES::BlitHostFrameCanvas() {}
|
||||
|
||||
Bool BackendObject_DirectGLES::PresentHostFrame() {
|
||||
MGLOG_E("PresentHostFrame: host frames are a disaggregated Android path");
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Bool BackendObject_DirectGLES::InitPbufferSurface(EGLint width, EGLint height) {
|
||||
return DirectGLES::InitPbufferSurface(width, height);
|
||||
}
|
||||
@@ -1293,42 +1052,13 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
MGLOG_E("MakeEGLCurrent failed: EGL display mismatch or not initialized");
|
||||
return false;
|
||||
}
|
||||
// EGL_KHR_surfaceless_context, WHICH IS THE SHAPE A COMPOSITOR ASKS FOR. Its context has no
|
||||
// draw surface of its own - every frame goes into a framebuffer it binds itself, and under
|
||||
// this project that framebuffer is one of the display host's frames - so the surface checks
|
||||
// below describe a surface that legitimately does not exist. What the server still needs is
|
||||
// its own GL context current on this thread for the records that follow, and that is what
|
||||
// the native bind underneath them does.
|
||||
const Bool surfaceless = draw == EGL_NO_SURFACE && read == EGL_NO_SURFACE && ctx != EGL_NO_CONTEXT;
|
||||
if (surfaceless && !m_eglSurfaceInitialized) {
|
||||
// A DRAWABLE OF THIS SIDE'S OWN, WHICH IS WHAT A SURFACELESS CLIENT LEAVES TO US. The
|
||||
// backend's native context has to be current on a surface of some kind before a single
|
||||
// record of the client's can run - that is what the Init*Surface calls establish - and a
|
||||
// client that makes its context current with no surface at all supplies none of its own.
|
||||
// A pbuffer is the one that costs nothing to keep: it is never scanned out and never
|
||||
// read, because every frame the client draws goes into a framebuffer it binds itself.
|
||||
// The client is NOT told it has a surface - m_eglSurface stays EGL_NO_SURFACE - so a
|
||||
// swap on one is still the refusal it was.
|
||||
if (!InitPbufferSurface(1, 1)) {
|
||||
MGLOG_E("MakeEGLCurrent failed: the backend's own drawable for a surfaceless context could not "
|
||||
"be created");
|
||||
return false;
|
||||
}
|
||||
m_eglSurface = EGL_NO_SURFACE;
|
||||
m_eglSurfaceInitialized = true;
|
||||
m_eglSurfaceKind = SurfaceKind::Pbuffer;
|
||||
m_eglCurrentThreads.clear();
|
||||
m_backendCapabilitiesInitialized = false;
|
||||
if (!m_eglSurfaceInitialized) {
|
||||
MGLOG_E("MakeEGLCurrent failed: EGL surface is not initialized");
|
||||
return false;
|
||||
}
|
||||
if (!surfaceless) {
|
||||
if (!m_eglSurfaceInitialized) {
|
||||
MGLOG_E("MakeEGLCurrent failed: EGL surface is not initialized");
|
||||
return false;
|
||||
}
|
||||
if (draw == EGL_NO_SURFACE || read == EGL_NO_SURFACE || ctx == EGL_NO_CONTEXT) {
|
||||
MGLOG_E("MakeEGLCurrent failed: draw/read/context is invalid");
|
||||
return false;
|
||||
}
|
||||
if (draw == EGL_NO_SURFACE || read == EGL_NO_SURFACE || ctx == EGL_NO_CONTEXT) {
|
||||
MGLOG_E("MakeEGLCurrent failed: draw/read/context is invalid");
|
||||
return false;
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
@@ -1356,9 +1086,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// function table instead of 1), or make NativeBindCanBeSkippedFor answer true for any tuple
|
||||
// (the ID-67 control's different tuple stays at 1 native bind where 2 are required).
|
||||
const Bool nativelyCurrentAlready = MG_Config::Transport != MG_Config::TransportMode::Monolith &&
|
||||
m_eglSurfaceInitialized && m_eglSurface == draw &&
|
||||
DirectGLES::IsBackendContextCurrentOnThisThread() &&
|
||||
(surfaceless || (m_eglSurfaceInitialized && m_eglSurface == draw &&
|
||||
NativeBindCanBeSkippedFor(dpy, draw, read, ctx)));
|
||||
NativeBindCanBeSkippedFor(dpy, draw, read, ctx);
|
||||
if (!nativelyCurrentAlready && !DirectGLES::MakeCurrent()) {
|
||||
NoteNativeContextGone();
|
||||
return false;
|
||||
@@ -1377,15 +1107,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
// A HOST-FRAMED SURFACE HAS TO BE PUT BACK AFTER EVERY MAKE-CURRENT. The native call
|
||||
// binds the surface's own default framebuffer - the pbuffer this path makes its context
|
||||
// with - and that is not where these pixels go. Both the driver and the engine's binding
|
||||
// shadow have to be told again, or the next default-framebuffer bind is deduped away and
|
||||
// every draw lands in a pbuffer nobody sees.
|
||||
if (m_eglSurfaceKind == SurfaceKind::HostFrame && m_hostFrameTarget.Framebuffer != 0) {
|
||||
FramebufferImpl::InvalidateFramebufferBindingCache();
|
||||
HostFrameTargetBind(HostFrameDrawTarget());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1542,40 +1263,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// Advertised with GL_NUM_PROGRAM_BINARY_FORMATS = 0, which the
|
||||
// extension explicitly permits. It is also the only thing that
|
||||
// exposes glProgramParameteri before GL 4.1.
|
||||
E_GL_ARB_get_program_binary,
|
||||
// kwin_wayland 6.7.3 will not use a context it cannot drive, and it asks for these
|
||||
// three names first: EglContext::checkSupported() (src/opengl/eglcontext.cpp) takes the
|
||||
// DESKTOP-OpenGL branch for every context whose GL_VERSION is not an "OpenGL ES"
|
||||
// string, and that branch requires GL_ARB_shader_objects, GL_ARB_fragment_shader and
|
||||
// GL_ARB_vertex_shader. GL_VERSION here is "4.6.0 MobileGL ...", so with the names
|
||||
// missing checkSupported() answered false, EglContext::create() returned nullptr,
|
||||
// EglBackend::createContext() returned false, and kwin printed "Could not initialize
|
||||
// rendering context" and quit before drawing a frame.
|
||||
//
|
||||
// The three are true statements about this backend now rather than a test unlock: every
|
||||
// procedure they define is implemented in MG_Impl/GLImpl/Exporting/Definitions.cpp over
|
||||
// the same shader and program objects the core entry points drive - the 39 of
|
||||
// ARB_shader_objects, ARB_vertex_shader's three attrib-location entry points, and none
|
||||
// at all for ARB_fragment_shader ("New Procedures and Functions: None" - it is the
|
||||
// capability half, and the reason kwin's conjunction names it).
|
||||
E_GL_ARB_shader_objects, E_GL_ARB_vertex_shader, E_GL_ARB_fragment_shader,
|
||||
// NPOT textures: core since GL 2.0, and every host this backend can run on provides
|
||||
// them. Full non-power-of-two support - mipmapping and every wrap mode, not ES 2.0's
|
||||
// CLAMP_TO_EDGE-only exception - is required from ES 3.0 on, and the entries this list
|
||||
// already advertises without any gate (compute shaders, shader storage buffers,
|
||||
// indirect draws) need an ES 3.1 host. Nothing in the texture path rejects or pads a
|
||||
// non-power-of-two size - storage and sampling are forwarded to that host - so the
|
||||
// string describes what an application actually gets.
|
||||
E_GL_ARB_texture_non_power_of_two,
|
||||
// GL_OES_EGL_image: the entry points are real (MG_Impl/GLImpl/Exporting/Definitions.cpp)
|
||||
// and this name is what makes them reachable - libepoxy in kwin resolves
|
||||
// glEGLImageTargetTexture2DOES BY NAME and refuses the import path without it, printing
|
||||
// "No provider of glEGLImageTargetTexture2DOES found. Requires one of: GL_OES_EGL_image".
|
||||
// That import path is how the compositor's scene reaches the display daemon's dma-bufs.
|
||||
// The render-server half of the import (fd over the GBM socket, then the server-side
|
||||
// EGLImage) is the next change; until it lands an imported texture has no storage behind
|
||||
// it, which is logged once at the entry point rather than left to look like a black frame.
|
||||
E_GL_OES_EGL_image};
|
||||
E_GL_ARB_get_program_binary};
|
||||
// Minecraft 26.3 checks this prerequisite before it even considers
|
||||
// GL_ARB_multi_draw_indirect. ES 3.1 supplies both single-draw entry points; the loader
|
||||
// folds the version and pointer checks into SupportsDrawIndirect.
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
#include "HostFrameTarget.h"
|
||||
#include "MG_Backend/HostFrameBridge.h"
|
||||
#include "MG_Backend/GbmFrameChannel.h"
|
||||
#include "../BackendObject.h"
|
||||
#include <MG_Util/BackendLoaders/OpenGL/Loader.h>
|
||||
|
||||
@@ -59,46 +56,8 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
private:
|
||||
void UpdateDynamicBackendParameters();
|
||||
Bool InitPbufferSurface(EGLint width, EGLint height) override;
|
||||
// A host-framed surface draws into a frame the display host owns; presenting one
|
||||
// tells the host the frame is drawn, because the host is what puts it on the glass.
|
||||
// NOT CreateEGLHostFrameSurface: the base class registers the surface and activates it,
|
||||
// and activation is what reaches InitHostFrameSurface below. There is nothing about the
|
||||
// EGL side of a host-framed surface this backend needs to do its own way.
|
||||
Bool InitHostFrameSurface(EGLint width, EGLint height) override;
|
||||
Bool PresentHostFrame() override;
|
||||
// Takes the next frame from the host and makes it this context's framebuffer.
|
||||
Bool TakeHostFrame();
|
||||
void DestroyHostFrame();
|
||||
// The canvas the compositor draws into, made once at the first frame's size.
|
||||
Bool EnsureHostFrameCanvas(Uint width, Uint height);
|
||||
// Copies the canvas into the frame about to be presented.
|
||||
void BlitHostFrameCanvas();
|
||||
// What draws resolve to: the canvas when there is one, the frame itself otherwise.
|
||||
const HostFrameTarget& HostFrameDrawTarget() const {
|
||||
return m_hostFrameCanvas.Framebuffer != 0 ? m_hostFrameCanvas : m_hostFrameTarget;
|
||||
}
|
||||
void OnEGLSurfaceReleased(EGLSurface surface) override;
|
||||
|
||||
// MOBILEGL_IPC_SURFACE=host: the frames the display host owns, one at a time, which
|
||||
// is what the host offers - it hands one over and waits for the answer before it
|
||||
// presents it and offers the next.
|
||||
MG_Backend::HostFrameBridge m_hostFrameBridge;
|
||||
// The frames the bridge just took, on to the container: the Wayland compositor over there
|
||||
// renders into this same memory, and the only route to it that end has is the dma-buf
|
||||
// descriptor this channel offers per frame and reads a release back from.
|
||||
MG_Backend::GbmFrameChannel m_gbmFrameChannel;
|
||||
HostFrameTarget m_hostFrameTarget;
|
||||
// A STABLE TARGET IN FRONT OF THE FRAMES. Every present hands the frame back and takes
|
||||
// a different one, and its renderbuffer is deleted with it - but a compositor attaches
|
||||
// its framebuffers ONCE (kwin: one per daemon buffer, for the life of the process), so
|
||||
// attachments bound to a frame's own renderbuffer named a deleted object from the second
|
||||
// frame on. The attachments name this instead, and each present copies it into the
|
||||
// frame. No EGLImage behind it (Image stays null).
|
||||
HostFrameTarget m_hostFrameCanvas;
|
||||
struct AHardwareBuffer* m_hostFrameBuffer = nullptr;
|
||||
MG_Backend::HostFrameOffer m_hostFrameOffer{};
|
||||
Bool m_hostFrameBridgeOpen = false;
|
||||
|
||||
Bool m_initialized = false;
|
||||
MG_External::EGLFunctionsTable m_EGLFunctions;
|
||||
MG_External::GLESFunctionsTable m_GLESFunctions;
|
||||
|
||||
@@ -87,10 +87,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
#endif
|
||||
|
||||
MG_External::EGLFunctionsTable g_EGLFuncs;
|
||||
Uint g_hostFrameFramebufferId = 0;
|
||||
Uint g_hostFrameRenderbuffer = 0;
|
||||
Uint g_hostFrameWidth = 0;
|
||||
Uint g_hostFrameHeight = 0;
|
||||
MG_External::GLESFunctionsTable g_GLESFuncs;
|
||||
MG_External::GLESCapabilities g_GLESCapabilities;
|
||||
|
||||
@@ -6519,7 +6515,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// Through the shadow: a raw bind here would leave the shadow claiming
|
||||
// the previous user FBO, false-skipping its next re-bind.
|
||||
FramebufferImpl::BindFramebufferId(
|
||||
target == FramebufferTarget::Draw ? GL_DRAW_FRAMEBUFFER : GL_READ_FRAMEBUFFER, g_hostFrameFramebufferId);
|
||||
target == FramebufferTarget::Draw ? GL_DRAW_FRAMEBUFFER : GL_READ_FRAMEBUFFER, 0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -6588,7 +6584,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// Through the shadow: a raw bind here would leave the shadow claiming
|
||||
// the previous user FBO, false-skipping its next re-bind.
|
||||
FramebufferImpl::BindFramebufferId(
|
||||
target == FramebufferTarget::Draw ? GL_DRAW_FRAMEBUFFER : GL_READ_FRAMEBUFFER, g_hostFrameFramebufferId);
|
||||
target == FramebufferTarget::Draw ? GL_DRAW_FRAMEBUFFER : GL_READ_FRAMEBUFFER, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6608,7 +6604,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
FramebufferImpl::g_integerColorDrawBufferMask = 0;
|
||||
}
|
||||
FramebufferImpl::BindFramebufferId(
|
||||
target == FramebufferTarget::Draw ? GL_DRAW_FRAMEBUFFER : GL_READ_FRAMEBUFFER, g_hostFrameFramebufferId);
|
||||
target == FramebufferTarget::Draw ? GL_DRAW_FRAMEBUFFER : GL_READ_FRAMEBUFFER, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -6649,7 +6645,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
FramebufferImpl::g_integerColorDrawBufferMask = 0;
|
||||
}
|
||||
FramebufferImpl::BindFramebufferId(
|
||||
target == FramebufferTarget::Draw ? GL_DRAW_FRAMEBUFFER : GL_READ_FRAMEBUFFER, g_hostFrameFramebufferId);
|
||||
target == FramebufferTarget::Draw ? GL_DRAW_FRAMEBUFFER : GL_READ_FRAMEBUFFER, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -249,26 +249,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
void InvalidateSyncedRenderState();
|
||||
} // namespace RenderStateImpl
|
||||
|
||||
// MOBILEGL_IPC_SURFACE=host: what the client's DEFAULT framebuffer means while a host-framed
|
||||
// surface is current. Zero everywhere else, because the driver's own 0 IS the EGL surface
|
||||
// then - but on a host-framed surface the pixels belong to a frame the display host owns,
|
||||
// and drawing into the driver's 0 would draw into a pbuffer nobody ever sees.
|
||||
extern Uint g_hostFrameFramebufferId;
|
||||
// WHAT THE HOST FRAME'S STORAGE IS, for the one caller that has to bind it in place of a
|
||||
// storage-less attachment: an imported dma-buf is the display host's frame (same memory, same
|
||||
// size), and the frame's storage is a RENDERBUFFER (HostFrameTarget.cpp binds it with
|
||||
// glFramebufferRenderbuffer). A texture argument cannot name it, which is why these exist and
|
||||
// why g_hostFrameFramebufferId alone was not enough. Zero whenever no frame is held.
|
||||
extern Uint g_hostFrameRenderbuffer;
|
||||
extern Uint g_hostFrameWidth;
|
||||
extern Uint g_hostFrameHeight;
|
||||
// TAKE THE FRAME WHEN NOTHING ELSE WILL. On the anland route the container's compositor never
|
||||
// creates a window surface, so ActivateEGLSurface never runs and InitHostFrameSurface is never
|
||||
// reached: the FIRST proof that the display host's frame is wanted is an ATTACHMENT of an
|
||||
// imported external texture (Managers.cpp's 0x8D65 arm), and that is where the frame has to be
|
||||
// taken. The host's own offer carries the width/height, so the numbers passed here are only
|
||||
// what the bridge logs. Answers false (and changes nothing) whenever no backend is up.
|
||||
Bool TakeHostFrameForExternalTexture(Uint width, Uint height);
|
||||
extern MG_External::EGLFunctionsTable g_EGLFuncs;
|
||||
extern MG_External::GLESFunctionsTable g_GLESFuncs;
|
||||
extern MG_External::GLESCapabilities g_GLESCapabilities;
|
||||
|
||||
@@ -1,208 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/DirectGLES/HostFrameTarget.cpp
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#include "HostFrameTarget.h"
|
||||
#include "DirectGLES.h"
|
||||
#include "Managers.h"
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED && defined(__ANDROID__)
|
||||
|
||||
#include <android/hardware_buffer.h>
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
|
||||
namespace MobileGL::MG_Backend::DirectGLES {
|
||||
namespace {
|
||||
// The four entry points this is spelled in are optional everywhere: the loader's own
|
||||
// tables do not carry them (a missing EGL function there is MGLOG_F), so the extension
|
||||
// strings decide first and the pointers are taken only once they have.
|
||||
using GetNativeClientBufferFn = EGLClientBuffer (*)(const struct AHardwareBuffer*);
|
||||
using CreateImageFn = EGLImageKHR (*)(EGLDisplay, EGLContext, EGLenum, EGLClientBuffer, const EGLint*);
|
||||
using DestroyImageFn = EGLBoolean (*)(EGLDisplay, EGLImageKHR);
|
||||
using ImageTargetRenderbufferFn = void (*)(GLenum, GLeglImageOES);
|
||||
|
||||
Bool HasExtensionWord(const char* list, const char* word) {
|
||||
if (list == nullptr) return false;
|
||||
const SizeT n = std::strlen(word);
|
||||
for (const char* at = std::strstr(list, word); at != nullptr; at = std::strstr(at + 1, word)) {
|
||||
const Bool startOk = at == list || at[-1] == ' ';
|
||||
const Bool endOk = !at[n] || at[n] == ' ';
|
||||
if (startOk && endOk) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
struct EntryPoints {
|
||||
GetNativeClientBufferFn GetNativeClientBuffer = nullptr;
|
||||
CreateImageFn CreateImage = nullptr;
|
||||
DestroyImageFn DestroyImage = nullptr;
|
||||
ImageTargetRenderbufferFn TargetRenderbuffer = nullptr;
|
||||
};
|
||||
|
||||
// Resolved once per process and cached together with the refusal: a driver that lacks one
|
||||
// of these does not grow it later, and the answer names what is missing.
|
||||
const EntryPoints& Resolved(String& why) {
|
||||
static EntryPoints points;
|
||||
static Bool resolved = false;
|
||||
static String refusal;
|
||||
if (!resolved) {
|
||||
resolved = true;
|
||||
if (!g_EGLFuncs.eglGetProcAddress || !g_EGLFuncs.eglQueryString || !g_EGLFuncs.eglGetCurrentDisplay ||
|
||||
!g_GLESFuncs.glGetString) {
|
||||
refusal = "the loader has no eglGetProcAddress/eglQueryString/eglGetCurrentDisplay/glGetString";
|
||||
} else {
|
||||
const char* egl = g_EGLFuncs.eglQueryString(g_EGLFuncs.eglGetCurrentDisplay(), EGL_EXTENSIONS);
|
||||
const char* gl = reinterpret_cast<const char*>(g_GLESFuncs.glGetString(GL_EXTENSIONS));
|
||||
if (!HasExtensionWord(egl, "EGL_ANDROID_get_native_client_buffer")) {
|
||||
refusal = "EGL_ANDROID_get_native_client_buffer is not advertised";
|
||||
} else if (!HasExtensionWord(egl, "EGL_KHR_image_base")) {
|
||||
refusal = "EGL_KHR_image_base is not advertised";
|
||||
} else if (!HasExtensionWord(gl, "GL_OES_EGL_image")) {
|
||||
refusal = "GL_OES_EGL_image is not advertised";
|
||||
} else {
|
||||
points.GetNativeClientBuffer = reinterpret_cast<GetNativeClientBufferFn>(
|
||||
g_EGLFuncs.eglGetProcAddress("eglGetNativeClientBufferANDROID"));
|
||||
points.CreateImage =
|
||||
reinterpret_cast<CreateImageFn>(g_EGLFuncs.eglGetProcAddress("eglCreateImageKHR"));
|
||||
points.DestroyImage =
|
||||
reinterpret_cast<DestroyImageFn>(g_EGLFuncs.eglGetProcAddress("eglDestroyImageKHR"));
|
||||
points.TargetRenderbuffer = reinterpret_cast<ImageTargetRenderbufferFn>(
|
||||
g_EGLFuncs.eglGetProcAddress("glEGLImageTargetRenderbufferStorageOES"));
|
||||
if (points.GetNativeClientBuffer == nullptr || points.CreateImage == nullptr ||
|
||||
points.DestroyImage == nullptr || points.TargetRenderbuffer == nullptr) {
|
||||
refusal = "eglGetProcAddress gave no eglGetNativeClientBufferANDROID / eglCreateImageKHR / "
|
||||
"eglDestroyImageKHR / glEGLImageTargetRenderbufferStorageOES";
|
||||
points = EntryPoints{};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
why = refusal;
|
||||
return points;
|
||||
}
|
||||
|
||||
void DrainGLErrors() {
|
||||
if (!g_GLESFuncs.glGetError) return;
|
||||
for (Uint guard = 0; guard < 16 && g_GLESFuncs.glGetError() != GL_NO_ERROR; ++guard) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Bool HostFrameTargetSupported(String& why) {
|
||||
const EntryPoints& points = Resolved(why);
|
||||
return points.GetNativeClientBuffer != nullptr;
|
||||
}
|
||||
|
||||
Bool HostFrameTargetCreate(const struct AHardwareBuffer* buffer, HostFrameTarget& target, String& why) {
|
||||
target = HostFrameTarget{};
|
||||
if (buffer == nullptr) {
|
||||
why = "no buffer";
|
||||
return false;
|
||||
}
|
||||
const EntryPoints& points = Resolved(why);
|
||||
if (points.GetNativeClientBuffer == nullptr) return false;
|
||||
|
||||
if (!g_GLESFuncs.glGenRenderbuffers || !g_GLESFuncs.glBindRenderbuffer || !g_GLESFuncs.glGenFramebuffers ||
|
||||
!g_GLESFuncs.glBindFramebuffer || !g_GLESFuncs.glFramebufferRenderbuffer ||
|
||||
!g_GLESFuncs.glCheckFramebufferStatus) {
|
||||
why = "the loader has no glGenRenderbuffers/glBindRenderbuffer/glGenFramebuffers/glBindFramebuffer/"
|
||||
"glFramebufferRenderbuffer/glCheckFramebufferStatus";
|
||||
return false;
|
||||
}
|
||||
|
||||
AHardwareBuffer_Desc desc{};
|
||||
AHardwareBuffer_describe(buffer, &desc);
|
||||
|
||||
DrainGLErrors();
|
||||
const EGLClientBuffer clientBuffer = points.GetNativeClientBuffer(buffer);
|
||||
if (clientBuffer == nullptr) {
|
||||
why = "eglGetNativeClientBufferANDROID returned null";
|
||||
return false;
|
||||
}
|
||||
const EGLint imageAttribs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
|
||||
const EGLImageKHR image =
|
||||
points.CreateImage(g_EGLFuncs.eglGetCurrentDisplay(), EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID,
|
||||
clientBuffer, imageAttribs);
|
||||
if (image == EGL_NO_IMAGE_KHR) {
|
||||
why = "eglCreateImageKHR(EGL_NATIVE_BUFFER_ANDROID) refused the host frame";
|
||||
return false;
|
||||
}
|
||||
|
||||
GLuint renderbuffer = 0;
|
||||
g_GLESFuncs.glGenRenderbuffers(1, &renderbuffer);
|
||||
g_GLESFuncs.glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
|
||||
points.TargetRenderbuffer(GL_RENDERBUFFER, reinterpret_cast<GLeglImageOES>(image));
|
||||
const GLenum renderbufferError = g_GLESFuncs.glGetError ? g_GLESFuncs.glGetError() : GL_NO_ERROR;
|
||||
if (renderbufferError != GL_NO_ERROR) {
|
||||
why = std::format("glEGLImageTargetRenderbufferStorageOES -> 0x{:04x}", renderbufferError);
|
||||
g_GLESFuncs.glDeleteRenderbuffers(1, &renderbuffer);
|
||||
points.DestroyImage(g_EGLFuncs.eglGetCurrentDisplay(), image);
|
||||
return false;
|
||||
}
|
||||
|
||||
GLuint framebuffer = 0;
|
||||
g_GLESFuncs.glGenFramebuffers(1, &framebuffer);
|
||||
g_GLESFuncs.glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
|
||||
g_GLESFuncs.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
|
||||
const GLenum status = g_GLESFuncs.glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||
why = std::format("the host frame as a color attachment -> framebuffer status 0x{:04x}", status);
|
||||
g_GLESFuncs.glDeleteFramebuffers(1, &framebuffer);
|
||||
g_GLESFuncs.glDeleteRenderbuffers(1, &renderbuffer);
|
||||
points.DestroyImage(g_EGLFuncs.eglGetCurrentDisplay(), image);
|
||||
return false;
|
||||
}
|
||||
|
||||
target.Image = image;
|
||||
target.Renderbuffer = renderbuffer;
|
||||
target.Framebuffer = framebuffer;
|
||||
target.Width = desc.width;
|
||||
target.Height = desc.height;
|
||||
MGLOG_I("host frame target: %ux%d as framebuffer %u (stride %u, format 0x%x)", desc.width, desc.height,
|
||||
framebuffer, desc.stride, desc.format);
|
||||
return true;
|
||||
}
|
||||
|
||||
void HostFrameTargetBind(const HostFrameTarget& target) {
|
||||
if (target.Framebuffer == 0) return;
|
||||
// THROUGH THE ENGINE'S SHADOW, never raw: a raw bind would leave the shadow claiming
|
||||
// the previous framebuffer and false-skip the next re-bind (FramebufferImpl, Managers.h).
|
||||
FramebufferImpl::BindFramebufferId(GL_FRAMEBUFFER, target.Framebuffer);
|
||||
}
|
||||
|
||||
void HostFrameTargetDestroy(HostFrameTarget& target) {
|
||||
if (target.Framebuffer != 0 && g_GLESFuncs.glDeleteFramebuffers)
|
||||
g_GLESFuncs.glDeleteFramebuffers(1, &target.Framebuffer);
|
||||
if (target.Renderbuffer != 0 && g_GLESFuncs.glDeleteRenderbuffers)
|
||||
g_GLESFuncs.glDeleteRenderbuffers(1, &target.Renderbuffer);
|
||||
if (target.Image != nullptr) {
|
||||
String why;
|
||||
const EntryPoints& points = Resolved(why);
|
||||
if (points.DestroyImage != nullptr && g_EGLFuncs.eglGetCurrentDisplay)
|
||||
points.DestroyImage(g_EGLFuncs.eglGetCurrentDisplay(), static_cast<EGLImageKHR>(target.Image));
|
||||
}
|
||||
target = HostFrameTarget{};
|
||||
}
|
||||
}
|
||||
|
||||
#else // !(MOBILEGL_BUILD_DISAGGREGATED && __ANDROID__)
|
||||
|
||||
namespace MobileGL::MG_Backend::DirectGLES {
|
||||
Bool HostFrameTargetSupported(String& why) {
|
||||
why = "host frames are a disaggregated Android path";
|
||||
return false;
|
||||
}
|
||||
Bool HostFrameTargetCreate(const struct AHardwareBuffer*, HostFrameTarget&, String& why) {
|
||||
why = "host frames are a disaggregated Android path";
|
||||
return false;
|
||||
}
|
||||
void HostFrameTargetBind(const HostFrameTarget&) {}
|
||||
void HostFrameTargetDestroy(HostFrameTarget& target) { target = HostFrameTarget{}; }
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,52 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/DirectGLES/HostFrameTarget.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
struct AHardwareBuffer;
|
||||
|
||||
namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// THE FRAME THE DISPLAY HOST IS ABOUT TO SCAN OUT, AS A DRAW TARGET.
|
||||
//
|
||||
// The display host (the Android side that owns the screen) allocates its frames itself and
|
||||
// offers each one over a socket as an AHardwareBuffer. That is not a convenience: measured
|
||||
// on the device, AHardwareBuffer_createFromHandle accepts an AHardwareBuffer this side
|
||||
// allocated and refuses one the display queue handed over (gralloc BAD_VALUE), so the frames
|
||||
// a render server can draw into are the ones the host made for it.
|
||||
//
|
||||
// What this makes of such a frame: an EGLImage the driver accepts as a renderbuffer, and a
|
||||
// framebuffer that is the drawing target while that frame is the current one. None of
|
||||
// Android's window machinery is involved - no ANativeWindow, no SurfaceFlinger - which is
|
||||
// the point: the host puts the frame on the glass when this side says it is drawn.
|
||||
struct HostFrameTarget {
|
||||
void* Image = nullptr; // EGLImageKHR; opaque here so this header stays free of EGL types
|
||||
Uint Renderbuffer = 0;
|
||||
Uint Framebuffer = 0;
|
||||
Uint Width = 0;
|
||||
Uint Height = 0;
|
||||
};
|
||||
|
||||
// Whether the driver advertises what this is spelled in. False is answered with the missing
|
||||
// name in `why`, never an abort: a server that cannot take host frames has to be able to
|
||||
// say so.
|
||||
Bool HostFrameTargetSupported(String& why);
|
||||
|
||||
// Imports `buffer` as a render target. On failure `target` is left empty and `why` says
|
||||
// which call refused; no GL name is leaked.
|
||||
Bool HostFrameTargetCreate(const struct AHardwareBuffer* buffer, HostFrameTarget& target, String& why);
|
||||
|
||||
// Binds the target as the current draw framebuffer, called when its frame becomes current.
|
||||
void HostFrameTargetBind(const HostFrameTarget& target);
|
||||
|
||||
// Drops the GL names and the EGLImage. The AHardwareBuffer belongs to the bridge, which
|
||||
// releases it; this never touches it.
|
||||
void HostFrameTargetDestroy(HostFrameTarget& target);
|
||||
}
|
||||
@@ -2983,6 +2983,67 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
return imported;
|
||||
}
|
||||
|
||||
// The POST's second round: the CPU writes region 1 through the held lock only now, after
|
||||
// the import and a GPU use of it, and reads region 4 (the first round's fill) back into
|
||||
// its cache; a second dispatch copies region 1 out and overwrites region 4. Appends its
|
||||
// counts to `detail`.
|
||||
Bool SelfTestExternalSteady(GLuint imported, GLuint out, void* heldPtr, char* detail, SizeT detailBytes) {
|
||||
constexpr Uint32 kWords = 1024;
|
||||
constexpr Uint32 kSteadyAtWord = kWords; // region 1
|
||||
constexpr Uint32 kFillAtWord = 4 * kWords; // region 4
|
||||
auto* held = static_cast<volatile Uint32*>(heldPtr);
|
||||
Uint32 cached = 0;
|
||||
for (Uint32 i = 0; i < kWords; ++i) {
|
||||
held[kSteadyAtWord + i] = 0xA5000000u ^ (i * 40503u);
|
||||
cached ^= held[kFillAtWord + i];
|
||||
}
|
||||
(void)cached;
|
||||
static const char* kSource =
|
||||
"#version 310 es\n"
|
||||
"layout(local_size_x = 64) in;\n"
|
||||
"layout(std430, binding = 0) buffer Ext { uint w[]; } ext;\n"
|
||||
"layout(std430, binding = 1) buffer Out { uint w[]; } outb;\n"
|
||||
"void main() {\n"
|
||||
" uint i = gl_GlobalInvocationID.x;\n"
|
||||
" outb.w[i] = ext.w[1024u + i];\n"
|
||||
" ext.w[4096u + i] = 0x3D5EA11Eu ^ i;\n"
|
||||
"}\n";
|
||||
const GLuint program = g_GLESFuncs.glCreateShaderProgramv(GL_COMPUTE_SHADER, 1, &kSource);
|
||||
GLint linked = 0;
|
||||
if (program != 0) g_GLESFuncs.glGetProgramiv(program, GL_LINK_STATUS, &linked);
|
||||
const SizeT used = std::strlen(detail);
|
||||
if (!linked) {
|
||||
if (program != 0) g_GLESFuncs.glDeleteProgram(program);
|
||||
std::snprintf(detail + used, detailBytes - used, "; steady: the second program did not link");
|
||||
return false;
|
||||
}
|
||||
g_GLESFuncs.glUseProgram(program);
|
||||
g_GLESFuncs.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, imported);
|
||||
g_GLESFuncs.glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, out);
|
||||
g_GLESFuncs.glMemoryBarrier(0x00004000 /*GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT_EXT*/);
|
||||
g_GLESFuncs.glDispatchCompute(kWords / 64, 1, 1);
|
||||
g_GLESFuncs.glMemoryBarrier(GL_BUFFER_UPDATE_BARRIER_BIT | GL_SHADER_STORAGE_BARRIER_BIT |
|
||||
0x00004000 /*GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT_EXT*/);
|
||||
g_GLESFuncs.glFinish();
|
||||
Uint32 steadyRead = 0, steadySaw = 0;
|
||||
for (Uint32 i = 0; i < kWords; ++i)
|
||||
if (held[kFillAtWord + i] == (0x3D5EA11Eu ^ i)) ++steadySaw;
|
||||
g_GLESFuncs.glBindBuffer(GL_SHADER_STORAGE_BUFFER, out);
|
||||
const auto* copied = static_cast<const Uint32*>(
|
||||
g_GLESFuncs.glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, kWords * 4, GL_MAP_READ_BIT));
|
||||
if (copied != nullptr) {
|
||||
for (Uint32 i = 0; i < kWords; ++i)
|
||||
if (copied[i] == (0xA5000000u ^ (i * 40503u))) ++steadyRead;
|
||||
g_GLESFuncs.glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
|
||||
}
|
||||
g_GLESFuncs.glDeleteProgram(program);
|
||||
std::snprintf(detail + used, detailBytes - used,
|
||||
"; with the import in use, GPU read %u/%u words the CPU wrote after it, GPU write "
|
||||
"seen through the held lock %u/%u words",
|
||||
steadyRead, kWords, steadySaw, kWords);
|
||||
return steadyRead == kWords && steadySaw == kWords;
|
||||
}
|
||||
|
||||
// THE POST (B2, the standing rule: decide by probe, never by driver name). The AHB API
|
||||
// promises CPU coherence only across an unlock/lock; T0 keeps the client's lock for the
|
||||
// store's life, so the pattern it depends on is exactly what this exercises, on this
|
||||
@@ -2993,7 +3054,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// gpu - a compute dispatch copies that pattern out of the import (the GPU read) and
|
||||
// fills another region of it (the GPU write);
|
||||
// back - after glFinish the fill is read through the HELD pointer and the copy is
|
||||
// read back from the dispatch's output.
|
||||
// read back from the dispatch's output;
|
||||
// steady - the same again with bytes the CPU wrote AFTER the import and its first GPU
|
||||
// use (VkBufferManager::SelfTestWireImport says why the first round is not enough).
|
||||
// In a throwaway ES 3.1 pbuffer context, so none of this context's state or Espryt's
|
||||
// binding caches is disturbed; the caller's bind is restored before returning.
|
||||
Bool Ops_H_SelfTestExternal(char* whyOut, Uint64 whyBytes) {
|
||||
@@ -3046,7 +3109,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
GLuint out = 0, program = 0;
|
||||
void* hostMap = nullptr;
|
||||
const GLuint imported = ImportAhbAsBuffer(held.ahb, kBytes, &hostMap, why, /*throwaway=*/true);
|
||||
char detail[256] = {};
|
||||
char detail[512] = {};
|
||||
if (imported == 0) {
|
||||
std::snprintf(detail, sizeof(detail), "import: %s", why.c_str());
|
||||
} else if (std::memcmp(hostMap, pattern.data(), kWords * 4) != 0) {
|
||||
@@ -3096,6 +3159,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
"64 KiB AHB, lock held throughout: host map read ok, GPU read %u/%u words of "
|
||||
"the CPU's pattern, GPU write seen through the held lock %u/%u words",
|
||||
gpuRead, kWords, heldSaw, kWords);
|
||||
if (ok) ok = SelfTestExternalSteady(imported, out, held.ptr, detail, sizeof(detail));
|
||||
}
|
||||
}
|
||||
if (program != 0) g_GLESFuncs.glDeleteProgram(program);
|
||||
@@ -3183,7 +3247,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
case MG_Pipe::MGPipeResourceTarget::Tex2DMSArray: return TextureTarget::Texture2DMultisampleArray;
|
||||
case MG_Pipe::MGPipeResourceTarget::TexRect: return TextureTarget::TextureRectangle;
|
||||
case MG_Pipe::MGPipeResourceTarget::TexBuffer: return TextureTarget::TextureBuffer;
|
||||
case MG_Pipe::MGPipeResourceTarget::TexExternalOES: return TextureTarget::TextureExternalOES;
|
||||
default: return TextureTarget::Unknown;
|
||||
}
|
||||
}
|
||||
@@ -10152,7 +10215,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
}
|
||||
MGLOG_D("Texture state changed significantly or not initialized, regenerating texture buffer with "
|
||||
"ID: %u, buffer ID: %u, buffer size: %zu, format: %s",
|
||||
m_backendTextureId, backendId, buffer ? buffer->GetSize() : (SizeT)0,
|
||||
m_backendTextureId, backendId, buffer ? buffer->GetSize() : rangeSize,
|
||||
MG_Util::ConvertGLEnumToString(glInternalFormat).c_str());
|
||||
// A texture that names a window of the buffer needs the range form; the
|
||||
// whole-buffer forms report offset 0 and the buffer's current size, which
|
||||
@@ -11283,45 +11346,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
const Bool isCubeFace = glTextureTarget >= GL_TEXTURE_CUBE_MAP_POSITIVE_X &&
|
||||
glTextureTarget <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
|
||||
backendTextureObject->Bind(isCubeFace ? GL_TEXTURE_CUBE_MAP : glTextureTarget);
|
||||
// THE TEXTURE'S OWN TARGET, not the attach target: an external texture is attached
|
||||
// through the GL_TEXTURE_2D upload target (TextureEnumConverter maps 0x8D65 there so the
|
||||
// attach validates), so glTextureTarget is never 0x8D65 here and the arms below were
|
||||
// dead - kwin's framebuffers got a storage-less texture and every draw into them failed
|
||||
// with GL_INVALID_FRAMEBUFFER_OPERATION.
|
||||
const Bool externalTexture =
|
||||
glTextureTarget == 0x8D65 || textureObject->GetTarget() == TextureTarget::TextureExternalOES;
|
||||
if (externalTexture && g_hostFrameRenderbuffer == 0) {
|
||||
// NOBODY ELSE TAKES THE FRAME ON THIS ROUTE (DirectGLES.h): the compositor
|
||||
// here never creates a window surface, so this attachment is the first place
|
||||
// the display host's frame is known to be wanted. A failed take leaves the
|
||||
// ordinary arm below exactly as it was.
|
||||
// The numbers size only the fallback pbuffer that is the draw target for the
|
||||
// moment before the first frame arrives; the frame's real extent comes from the
|
||||
// display host's own offer. They are the panel's, because that is the surface
|
||||
// this route exists to fill.
|
||||
(void)TakeHostFrameForExternalTexture(1440, 3200);
|
||||
}
|
||||
if (externalTexture && g_hostFrameRenderbuffer != 0) {
|
||||
// THE IMPORTED dma-buf IS THE DISPLAY HOST'S FRAME. Measured, and the whole reason
|
||||
// this branch exists: kwin_wayland in the container imports the display daemon's
|
||||
// dma-buf as an EGLImage ("taking target 0x8d65 over an EGLImage of 1440x2937
|
||||
// fourcc 0x34324241") and builds a framebuffer over that texture - and a texture
|
||||
// that arrived this way has NO storage on this side, so the attachment was bound
|
||||
// as an empty texture and kwin refused its own framebuffer ("framebuffer for
|
||||
// dmabuf 0 is not complete"). The buffer it imports IS the frame the display
|
||||
// host handed this process (same memory, same size), and that frame's storage is
|
||||
// a RENDERBUFFER - a texture argument cannot name it - so the attachment is bound
|
||||
// to the frame itself. The gate is the measured shape of that case: target
|
||||
// GL_TEXTURE_EXTERNAL_OES (0x8d65), which nothing else in this stack binds, and a
|
||||
// frame currently held. Every other attachment - a normal GL_TEXTURE_2D, or any
|
||||
// moment with no frame - takes the ordinary path below, unchanged.
|
||||
g_GLESFuncs.glFramebufferRenderbuffer(glFBOTarget, glBackendAttachment, GL_RENDERBUFFER,
|
||||
g_hostFrameRenderbuffer);
|
||||
} else {
|
||||
g_GLESFuncs.glFramebufferTexture2D(glFBOTarget, glBackendAttachment, glTextureTarget,
|
||||
backendTextureObject->GetBackendTextureId(),
|
||||
static_cast<GLint>(attachmentObject.GetTextureLevel()));
|
||||
}
|
||||
g_GLESFuncs.glFramebufferTexture2D(glFBOTarget, glBackendAttachment, glTextureTarget,
|
||||
backendTextureObject->GetBackendTextureId(),
|
||||
static_cast<GLint>(attachmentObject.GetTextureLevel()));
|
||||
}
|
||||
} else if (attachmentObject.IsRenderbuffer()) {
|
||||
const auto& renderbufferObject = attachmentObject.GetRenderbuffer();
|
||||
@@ -11637,23 +11664,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// nothing here is the whole of the agreement. (The legacy arm does the same.)
|
||||
return true;
|
||||
}
|
||||
// AN IMPORTED dma-buf AT A COLOUR POINT IS THE DISPLAY HOST'S FRAME. The client marks the
|
||||
// texture it bound an imported EGLImage to as GL_TEXTURE_EXTERNAL_OES (TextureObject2D's
|
||||
// target), the server never received that dma-buf's storage, and the compositor's
|
||||
// framebuffer over it was incomplete (measured: status 0x8cd7, every draw
|
||||
// GL_INVALID_FRAMEBUFFER_OPERATION). It is bound to the host frame canvas instead - the
|
||||
// storage the display host's frames are copied out of at present - before any twin or
|
||||
// storage sync, which have nothing to offer a texture with no storage.
|
||||
if (surface.Kind == MG_Pipe::kMGPipeSurfaceKindTexture &&
|
||||
surface.TextureTarget ==
|
||||
static_cast<decltype(surface.TextureTarget)>(TextureTarget::TextureExternalOES)) {
|
||||
if (g_hostFrameRenderbuffer == 0) (void)TakeHostFrameForExternalTexture(1440, 3200);
|
||||
if (g_hostFrameRenderbuffer != 0) {
|
||||
g_GLESFuncs.glFramebufferRenderbuffer(glFBOTarget, glBackendAttachment, GL_RENDERBUFFER,
|
||||
g_hostFrameRenderbuffer);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (surface.Kind == MG_Pipe::kMGPipeSurfaceKindTexture) {
|
||||
// The record's handle is validated BEFORE the frontend is consulted (N-3): it is
|
||||
// the untrusted half, the frontend cross-check below is the corroboration, and
|
||||
@@ -11737,38 +11747,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
const Bool isCubeFace = glTextureTarget >= GL_TEXTURE_CUBE_MAP_POSITIVE_X &&
|
||||
glTextureTarget <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
|
||||
backendTextureObject->Bind(isCubeFace ? GL_TEXTURE_CUBE_MAP : glTextureTarget);
|
||||
if (glTextureTarget == 0x8D65 && g_hostFrameRenderbuffer == 0) {
|
||||
// NOBODY ELSE TAKES THE FRAME ON THIS ROUTE (DirectGLES.h): the compositor
|
||||
// here never creates a window surface, so this attachment is the first place
|
||||
// the display host's frame is known to be wanted. A failed take leaves the
|
||||
// ordinary arm below exactly as it was.
|
||||
// The numbers size only the fallback pbuffer that is the draw target for the
|
||||
// moment before the first frame arrives; the frame's real extent comes from the
|
||||
// display host's own offer. They are the panel's, because that is the surface
|
||||
// this route exists to fill.
|
||||
(void)TakeHostFrameForExternalTexture(1440, 3200);
|
||||
}
|
||||
if (glTextureTarget == 0x8D65 && g_hostFrameRenderbuffer != 0) {
|
||||
// THE IMPORTED dma-buf IS THE DISPLAY HOST'S FRAME. Measured, and the whole reason
|
||||
// this branch exists: kwin_wayland in the container imports the display daemon's
|
||||
// dma-buf as an EGLImage ("taking target 0x8d65 over an EGLImage of 1440x2937
|
||||
// fourcc 0x34324241") and builds a framebuffer over that texture - and a texture
|
||||
// that arrived this way has NO storage on this side, so the attachment was bound
|
||||
// as an empty texture and kwin refused its own framebuffer ("framebuffer for
|
||||
// dmabuf 0 is not complete"). The buffer it imports IS the frame the display
|
||||
// host handed this process (same memory, same size), and that frame's storage is
|
||||
// a RENDERBUFFER - a texture argument cannot name it - so the attachment is bound
|
||||
// to the frame itself. The gate is the measured shape of that case: target
|
||||
// GL_TEXTURE_EXTERNAL_OES (0x8d65), which nothing else in this stack binds, and a
|
||||
// frame currently held. Every other attachment - a normal GL_TEXTURE_2D, or any
|
||||
// moment with no frame - takes the ordinary path below, unchanged.
|
||||
g_GLESFuncs.glFramebufferRenderbuffer(glFBOTarget, glBackendAttachment, GL_RENDERBUFFER,
|
||||
g_hostFrameRenderbuffer);
|
||||
} else {
|
||||
g_GLESFuncs.glFramebufferTexture2D(glFBOTarget, glBackendAttachment, glTextureTarget,
|
||||
backendTextureObject->GetBackendTextureId(),
|
||||
static_cast<GLint>(surface.Level));
|
||||
}
|
||||
g_GLESFuncs.glFramebufferTexture2D(glFBOTarget, glBackendAttachment, glTextureTarget,
|
||||
backendTextureObject->GetBackendTextureId(),
|
||||
static_cast<GLint>(surface.Level));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -14133,7 +14114,8 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// re-serialised copy either way, and adopting that copy for every vertex
|
||||
// shader would put every one of them through a round trip they do not need
|
||||
// - which is not free: it cost the create-indirect retrace 0.15 SSIM the
|
||||
// first time this gate was missing.
|
||||
// first time this gate was missing (the original capture; the case is now
|
||||
// minecraft-1.21.1-neoforge-create-indirect-in-world-align1024).
|
||||
effectiveSpirv = &splitArrayInputSpirv;
|
||||
}
|
||||
|
||||
@@ -14141,8 +14123,10 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// blocks - the optimizer hands back a re-serialised copy either way, and taking
|
||||
// that copy for a module it did not rewrite is not free (it cost the
|
||||
// create-indirect retrace 0.15 SSIM when the array-input split first missed
|
||||
// this gate). The report has to be per stage, not cumulative: a fragment shader
|
||||
// consuming the same block reports a name the vertex stage already reported,
|
||||
// this gate; the case is now
|
||||
// minecraft-1.21.1-neoforge-create-indirect-in-world-align1024). The report has to be
|
||||
// per stage, not cumulative: a fragment shader consuming the same block reports a
|
||||
// name the vertex stage already reported,
|
||||
// and its own rewrite must still be taken or the two stages stop matching.
|
||||
Vector<unsigned int> flattenedXfbSpirv;
|
||||
if (!xfbCaptureBlockNames.empty()) {
|
||||
@@ -14861,8 +14845,10 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// per stage below so a producer and its consumer keep naming the same block.
|
||||
// Gated twice over, because a re-serialised module is not free (it cost the
|
||||
// create-indirect retrace 0.15 SSIM the first time the array-input split missed
|
||||
// its gate): only a tessellation or geometry stage can declare blocks in both
|
||||
// directions at all, and even then the probe has to FIND a collision before any
|
||||
// its gate; the case is now
|
||||
// minecraft-1.21.1-neoforge-create-indirect-in-world-align1024): only a tessellation
|
||||
// or geometry stage can declare blocks in both directions at all, and even then the
|
||||
// probe has to FIND a collision before any
|
||||
// stage is rewritten.
|
||||
std::set<String> collidingIoBlockNames;
|
||||
std::set<String> declaredIoBlockNames;
|
||||
|
||||
@@ -1879,9 +1879,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
return TextureTarget::Texture2D;
|
||||
case TextureTarget::Texture1DArray:
|
||||
return TextureTarget::Texture2DArray;
|
||||
// An external texture's storage is an imported EGLImage; to the driver it is 2D.
|
||||
case TextureTarget::TextureExternalOES:
|
||||
return TextureTarget::Texture2D;
|
||||
default:
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -659,38 +659,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// Advertised with GL_NUM_PROGRAM_BINARY_FORMATS = 0, which the
|
||||
// extension explicitly permits. It is also the only thing that
|
||||
// exposes glProgramParameteri before GL 4.1.
|
||||
E_GL_ARB_get_program_binary,
|
||||
// kwin_wayland 6.7.3 will not use a context it cannot drive, and it asks for these
|
||||
// three names first: EglContext::checkSupported() (src/opengl/eglcontext.cpp) takes the
|
||||
// DESKTOP-OpenGL branch for every context whose GL_VERSION is not an "OpenGL ES"
|
||||
// string, and that branch requires GL_ARB_shader_objects, GL_ARB_fragment_shader and
|
||||
// GL_ARB_vertex_shader. GL_VERSION here is "4.6.0 MobileGL ...", so with the names
|
||||
// missing checkSupported() answered false, EglContext::create() returned nullptr,
|
||||
// EglBackend::createContext() returned false, and kwin printed "Could not initialize
|
||||
// rendering context" and quit before drawing a frame.
|
||||
//
|
||||
// The three are true statements about this backend too, and the entry points behind
|
||||
// them are the same ones the DirectGLES half of this list is advertised with: the
|
||||
// frontend implements all 39 ARB_shader_objects procedures, ARB_vertex_shader's three
|
||||
// attrib-location entry points, and nothing for ARB_fragment_shader, whose "New
|
||||
// Procedures and Functions" section reads "None". The shader and program objects live in
|
||||
// MG_Impl/MG_State, above the backend that draws with them, so a name that is true on
|
||||
// one backend is true on the other.
|
||||
E_GL_ARB_shader_objects, E_GL_ARB_vertex_shader, E_GL_ARB_fragment_shader,
|
||||
// NPOT textures: Vulkan puts no power-of-two restriction on an image, its mip chain or
|
||||
// its samplers, so this is the strongest form of the promise the string makes. Kept
|
||||
// identical to the DirectGLES group so the two backends do not disagree about what
|
||||
// MobileGL is.
|
||||
E_GL_ARB_texture_non_power_of_two,
|
||||
// GL_OES_EGL_image: the entry points are real (MG_Impl/GLImpl/Exporting/Definitions.cpp)
|
||||
// and this name is what makes them reachable - libepoxy in kwin resolves
|
||||
// glEGLImageTargetTexture2DOES BY NAME and refuses the import path without it, printing
|
||||
// "No provider of glEGLImageTargetTexture2DOES found. Requires one of: GL_OES_EGL_image".
|
||||
// That import path is how the compositor's scene reaches the display daemon's dma-bufs.
|
||||
// The render-server half of the import (fd over the GBM socket, then the server-side
|
||||
// EGLImage) is the next change; until it lands an imported texture has no storage behind
|
||||
// it, which is logged once at the entry point rather than left to look like a black frame.
|
||||
E_GL_OES_EGL_image};
|
||||
E_GL_ARB_get_program_binary};
|
||||
// Vulkan's drawIndirectFirstInstance feature is optional. Direct base-instance calls work
|
||||
// without it, but ARB_base_instance also promises non-zero firstInstance in GPU indirect
|
||||
// commands; the renderer supplies true only when that word is legal and gl_InstanceID can
|
||||
|
||||
@@ -786,7 +786,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// read - this server's own host map of the import reads what the CPU wrote through the lock;
|
||||
// gpu - one submission copies that pattern out of the import (the GPU read) and fills another
|
||||
// region of it (the GPU write), then a transfer->host barrier and a fence wait;
|
||||
// back - the fill is read through the HELD pointer, the copy from a host-visible staging buffer.
|
||||
// back - the fill is read through the HELD pointer, the copy from a host-visible staging buffer;
|
||||
// steady - the same again with bytes the CPU wrote AFTER the import and its first GPU use (the
|
||||
// block at the end says why the first round alone is not enough).
|
||||
Bool VkBufferManager::SelfTestWireImport(char* whyOut, Uint64 whyBytes) {
|
||||
const auto answer = [&](Bool ok, const String& text) {
|
||||
std::snprintf(whyOut, static_cast<SizeT>(whyBytes), "%s", text.c_str());
|
||||
@@ -909,6 +911,55 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
String(imported.coherent ? "coherent" : "non-coherent") + " memory), GPU read " +
|
||||
std::to_string(gpuRead) + "/1024 words of the CPU's pattern, GPU write seen through the "
|
||||
"held lock " + std::to_string(heldSaw) + "/1024 words";
|
||||
if (!ok) break;
|
||||
|
||||
// STEADY STATE. The round above reads bytes the CPU wrote BEFORE the import, and an import
|
||||
// can clean the CPU's caches on its way in, so it passes on a device whose GPU never sees a
|
||||
// write made through the held lock afterwards - which is all of T0's real traffic (Mali-G1
|
||||
// on a Dimensity: the first round passed, then Flywheel's staging scatter read stale bytes
|
||||
// and the create-indirect trace lost every instanced object). So the CPU now writes a fresh
|
||||
// pattern into region 1 and reads region 4 back into its cache, and one more submission
|
||||
// copies region 1 out and overwrites region 4.
|
||||
constexpr Uint64 kSteadyAt = 1 * 4096; // region 1
|
||||
constexpr Uint32 kSteadyFillWord = 0x3D5EA11Eu;
|
||||
auto* heldWrite = static_cast<volatile Uint32*>(held.ptr);
|
||||
Uint32 cached = 0;
|
||||
for (Uint32 i = 0; i < kWords; ++i) {
|
||||
heldWrite[kSteadyAt / 4 + i] = 0xA5000000u ^ (i * 40503u);
|
||||
cached ^= heldWrite[kFillAt / 4 + i];
|
||||
}
|
||||
(void)cached;
|
||||
std::memset(staging.mapped, 0, kWords * 4);
|
||||
if (vkResetFences(ctx.device, 1, &fence) != VK_SUCCESS ||
|
||||
vkResetCommandPool(ctx.device, pool, 0) != VK_SUCCESS ||
|
||||
vkBeginCommandBuffer(commands, &begin) != VK_SUCCESS) {
|
||||
ok = false;
|
||||
verdict = "steady: the second submission could not be recorded";
|
||||
break;
|
||||
}
|
||||
vkCmdPipelineBarrier(commands, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 1,
|
||||
&hostWrites, 0, nullptr, 0, nullptr);
|
||||
VkBufferCopy steadyRegion{kSteadyAt, 0, kWords * 4};
|
||||
vkCmdCopyBuffer(commands, imported.buffer, staging.buffer, 1, &steadyRegion);
|
||||
vkCmdFillBuffer(commands, imported.buffer, kFillAt, kWords * 4, kSteadyFillWord);
|
||||
vkCmdPipelineBarrier(commands, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 1, &toHost,
|
||||
0, nullptr, 0, nullptr);
|
||||
vkEndCommandBuffer(commands);
|
||||
if (vkQueueSubmit(ctx.queue, 1, &submit, fence) != VK_SUCCESS ||
|
||||
vkWaitForFences(ctx.device, 1, &fence, VK_TRUE, 2'000'000'000ull) != VK_SUCCESS) {
|
||||
ok = false;
|
||||
verdict = "steady: the second submission did not complete within 2 s";
|
||||
break;
|
||||
}
|
||||
Uint32 steadyRead = 0, steadySaw = 0;
|
||||
for (Uint32 i = 0; i < kWords; ++i) {
|
||||
if (copied[i] == (0xA5000000u ^ (i * 40503u))) ++steadyRead;
|
||||
if (heldWords[kFillAt / 4 + i] == kSteadyFillWord) ++steadySaw;
|
||||
}
|
||||
ok = steadyRead == kWords && steadySaw == kWords;
|
||||
verdict += "; with the import in use, GPU read " + std::to_string(steadyRead) +
|
||||
"/1024 words the CPU wrote after it, GPU write seen through the held lock " +
|
||||
std::to_string(steadySaw) + "/1024 words";
|
||||
} while (false);
|
||||
if (fence != VK_NULL_HANDLE) vkDestroyFence(ctx.device, fence, nullptr);
|
||||
if (pool != VK_NULL_HANDLE) vkDestroyCommandPool(ctx.device, pool, nullptr);
|
||||
|
||||
@@ -1,737 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/GbmFrameChannel.cpp
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#include "GbmFrameChannel.h"
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED && defined(__ANDROID__)
|
||||
|
||||
#include <android/hardware_buffer.h>
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <poll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// WHAT THIS FILE IS WRITTEN AGAINST, AND WHAT HAS NOT BEEN RUN.
|
||||
//
|
||||
// The other end exists and is tested on this machine: MobileGL/MG_Gbm/GbmHostChannel.cpp dials
|
||||
// this socket with SOCK_SEQPACKET, reads one message per frame, computes that message's expected
|
||||
// length from the handle's own two counts, and refuses any other length. Every byte below is
|
||||
// written to that parser. There is no phone attached to the machine this was written on, so the
|
||||
// file is compile-verified for aarch64 Android and nothing more: the first run on a device is what
|
||||
// will say whether the relay in RelayHandle() reads back the handle's bytes exactly as
|
||||
// AHardwareBuffer_sendHandleToUnixSocket writes them, which is why that path is written to
|
||||
// survive both layouts the platform's serializer could have (see the note there).
|
||||
|
||||
namespace MobileGL::MG_Backend {
|
||||
namespace {
|
||||
// THE LAYOUT IS A PROTOCOL, SO ITS SIZES ARE ASSERTED AND NOT ASSUMED. The container
|
||||
// derives the length of a frame message from these three sizes plus the handle's counts,
|
||||
// so a field added here, or the packing attribute dropped, would not be a compile error
|
||||
// over there - it would be every frame skipped with a message about its length.
|
||||
static_assert(sizeof(GbmFrameOffer) == 10 * sizeof(Uint32), "the offer is ten 32 bit fields on the wire");
|
||||
static_assert(sizeof(GbmFrameRelease) == 3 * sizeof(Uint32), "the release is three 32 bit fields on the wire");
|
||||
static_assert(sizeof(GbmNativeHandleHeader) == 3 * sizeof(Int32),
|
||||
"a native handle begins with a version and two counts, on every Android ABI");
|
||||
|
||||
// The container reads one message per frame into a 4 KiB buffer and skips a message that
|
||||
// does not fit in it (GbmHostMessageMax, GbmHostChannel.cpp), so a message larger than this
|
||||
// is refused here rather than built and dropped there.
|
||||
constexpr SizeT kMessageMax = 4096;
|
||||
// The descriptors one handle may carry, which is the container's own cap (GbmHostMaxFds).
|
||||
// Every AHardwareBuffer handle this project has seen carries one - the dma-buf - and both
|
||||
// ends refuse a frame whose handle names more than they can take rather than forward a
|
||||
// truncated list into a buffer of unknown memory.
|
||||
constexpr Int kMaxHandleFds = 8;
|
||||
// How many release messages one call reads before it returns to the frame. A cap and not a
|
||||
// loop to exhaustion: the messages left behind stay in the socket, whose buffer the kernel
|
||||
// bounds, and the next frame drains them.
|
||||
constexpr Int kDrainMax = 64;
|
||||
// HOW MANY DIALERS THE KERNEL MAY HOLD FOR THIS LISTENER. One container is the protocol,
|
||||
// but the queue is not the connection: every compositor that was restarted dials once more,
|
||||
// and a listener that only ever has one slot leaves its queue full for the next one. With
|
||||
// listen(fd, 1) that is exactly what was measured - connect() from the container answered
|
||||
// EAGAIN(11) on four attempts out of four after two restarts, and no dialer reached this
|
||||
// side again for as long as the server lived.
|
||||
constexpr Int kDialerBacklog = 16;
|
||||
// The acceptor's poll timeout. It is a wake-up and not a schedule, so it only has to be
|
||||
// short enough that a container dialling into a socket nothing else touches is taken
|
||||
// promptly; a dialer that arrives while the thread is waiting wakes it at once.
|
||||
constexpr Int kAcceptPollMs = 100;
|
||||
// How long the relay read waits for bytes the send one statement earlier has already put in
|
||||
// the socket. It exists only so that an invariant broken somewhere else cannot park the
|
||||
// apply thread; on a local socketpair the wait is zero.
|
||||
constexpr Int kRelayWaitMs = 2;
|
||||
|
||||
// close() may overwrite the errno a caller is in the middle of reporting, and every caller
|
||||
// here is reporting a failure errno describes.
|
||||
void CloseQuietly(Int fd) {
|
||||
if (fd < 0) return;
|
||||
const Int savedErrno = errno;
|
||||
::close(fd);
|
||||
errno = savedErrno;
|
||||
}
|
||||
}
|
||||
|
||||
GbmFrameChannel::~GbmFrameChannel() { Close(); }
|
||||
|
||||
Bool GbmFrameChannel::Open() {
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (m_listen >= 0) return true;
|
||||
|
||||
const char* configured = ::getenv(kGbmFrameSocketEnv);
|
||||
const char* path = (configured != nullptr && configured[0] != 0) ? configured : kGbmFrameSocketPath;
|
||||
constexpr SizeT pathMax = sizeof(((struct sockaddr_un*)nullptr)->sun_path);
|
||||
if (std::strlen(path) >= pathMax) {
|
||||
MGLOG_E_ONCE("gbm frame channel: the container socket path %s does not fit in sun_path (%zu bytes); no "
|
||||
"container can be served",
|
||||
path, pathMax);
|
||||
return false;
|
||||
}
|
||||
|
||||
// SOCK_SEQPACKET because that is what the container dials with (GbmHostChannel::EnsureOpen
|
||||
// asks for exactly this), and a stream listener answers it EPROTOTYPE - the container
|
||||
// prints that as "a socket of a different type". SOCK_NONBLOCK because the accept below
|
||||
// runs on the apply thread and may not wait for a container that is not there; SOCK_CLOEXEC
|
||||
// because every process this server starts would otherwise inherit a socket that receives
|
||||
// the phone's frames.
|
||||
const Int fd = ::socket(AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
|
||||
if (fd < 0) {
|
||||
MGLOG_E_ONCE("gbm frame channel: socket(AF_UNIX, SOCK_SEQPACKET): %s; the frames are drawn and presented "
|
||||
"without a container",
|
||||
std::strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
// A node left behind by a server that died is not a reason to refuse a container: bind
|
||||
// would answer EADDRINUSE for a socket nobody is listening on.
|
||||
::unlink(path);
|
||||
|
||||
struct sockaddr_un address = {};
|
||||
address.sun_family = AF_UNIX;
|
||||
// The terminator travels with the name: sun_path is a C string for a pathname socket, and a
|
||||
// name without one is a name the kernel reads past the end of.
|
||||
std::memcpy(address.sun_path, path, std::strlen(path) + 1);
|
||||
if (::bind(fd, reinterpret_cast<struct sockaddr*>(&address), sizeof(address)) != 0) {
|
||||
MGLOG_E_ONCE("gbm frame channel: bind(%s): %s; the frames are drawn and presented without a container",
|
||||
path, std::strerror(errno));
|
||||
CloseQuietly(fd);
|
||||
return false;
|
||||
}
|
||||
// connect() to a pathname socket needs write permission on the node, and the container is
|
||||
// not this process's user, so the umask's usual 0755 would leave it refused for a reason it
|
||||
// could not see. 0666 is what makes the node reachable by the other half of a split run; a
|
||||
// chmod that fails is not fatal, because a peer running as this uid still dials it.
|
||||
if (::chmod(path, 0666) != 0) {
|
||||
MGLOG_W_ONCE("gbm frame channel: chmod(%s, 0666): %s; a container running as another user cannot dial "
|
||||
"this socket",
|
||||
path, std::strerror(errno));
|
||||
}
|
||||
if (::listen(fd, kDialerBacklog) != 0) {
|
||||
MGLOG_E_ONCE("gbm frame channel: listen(%s): %s; the frames are drawn and presented without a container",
|
||||
path, std::strerror(errno));
|
||||
::unlink(path);
|
||||
CloseQuietly(fd);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_listen = fd;
|
||||
m_path = path;
|
||||
// THE ACCEPTOR IS STARTED WITH THE SOCKET AND NOT WITH THE FIRST FRAME. A compositor dials
|
||||
// at its device creation and keeps the connection, so the dial a frame would have answered
|
||||
// has already happened by the time that frame is offered: an accept on the offer path is an
|
||||
// accept that runs after the thing it exists for. The descriptor is copied into the thread
|
||||
// as an argument - it is the one piece of this object the thread reads without the lock,
|
||||
// which is what lets Close() join it before closing that descriptor.
|
||||
m_accepting.store(true, std::memory_order_release);
|
||||
try {
|
||||
m_acceptor = std::thread(&GbmFrameChannel::AcceptLoop, this, fd);
|
||||
} catch (...) {
|
||||
// A thread that cannot be made is a phone that is out of them, not a reason to refuse
|
||||
// the frames the container can still be given one at a time.
|
||||
m_accepting.store(false, std::memory_order_release);
|
||||
MGLOG_W_ONCE("gbm frame channel: the acceptor thread could not be started; a container is only taken in "
|
||||
"when a frame is offered, and one that dials between frames waits for the next one");
|
||||
}
|
||||
MGLOG_I("gbm frame channel: listening on %s for one container (SOCK_SEQPACKET, one message per frame)", path);
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool GbmFrameChannel::EnsureRelay() {
|
||||
if (m_relay[0] >= 0 && m_relay[1] >= 0) return true;
|
||||
// Both ends are dropped before a new pair is made: half a socketpair is a socket with bytes
|
||||
// in it that nothing will ever read, and the next handle read from it would be the tail of
|
||||
// the last one.
|
||||
DropRelay();
|
||||
Int pair[2] = {-1, -1};
|
||||
if (::socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0, pair) != 0) {
|
||||
MGLOG_E_ONCE("gbm frame channel: socketpair for the handle relay: %s; no frame can be offered until one "
|
||||
"can be made",
|
||||
std::strerror(errno));
|
||||
return false;
|
||||
}
|
||||
m_relay[0] = pair[0];
|
||||
m_relay[1] = pair[1];
|
||||
return true;
|
||||
}
|
||||
|
||||
void GbmFrameChannel::DropRelay() {
|
||||
CloseQuietly(m_relay[0]);
|
||||
CloseQuietly(m_relay[1]);
|
||||
m_relay[0] = -1;
|
||||
m_relay[1] = -1;
|
||||
}
|
||||
|
||||
Bool GbmFrameChannel::RelayHandle(struct AHardwareBuffer* buffer, Uint8* payload, SizeT capacity, SizeT& payloadBytes,
|
||||
Int* fds, Int& fdCount) {
|
||||
payloadBytes = 0;
|
||||
fdCount = 0;
|
||||
if (!EnsureRelay()) return false;
|
||||
|
||||
// WHY A FRAME'S HANDLE GOES THROUGH A SOCKETPAIR OF THIS CHANNEL'S OWN.
|
||||
//
|
||||
// The container takes ONE message per frame - the offer, then the handle's counts, then the
|
||||
// arrays those counts describe, with the descriptors in that same message's SCM_RIGHTS
|
||||
// control data - and it refuses a message of any other length. Two sends cannot be one
|
||||
// message on a message-oriented socket, so AHardwareBuffer_sendHandleToUnixSocket, which
|
||||
// sends a handle as a message of its own, is pointed at a socketpair this channel owns, and
|
||||
// what comes out of the other end is both halves of what the container wants: the handle's
|
||||
// own bytes, read here, and its descriptors, as SCM_RIGHTS.
|
||||
//
|
||||
// The alternative does not exist: the NDK's <android/hardware_buffer.h> declares no way to
|
||||
// ask a buffer for its descriptors. AHardwareBuffer_getNativeHandle is a platform API and
|
||||
// is absent from the NDK's copy of that header (checked against NDK 27.3.13750724 in this
|
||||
// tree's build-termux toolchain), so this is the one route from an AHardwareBuffer to a
|
||||
// dma-buf descriptor that an app can take.
|
||||
const Int code = AHardwareBuffer_sendHandleToUnixSocket(buffer, m_relay[0]);
|
||||
if (code != 0) {
|
||||
MGLOG_W_ONCE("gbm frame channel: the frame's handle did not cross the relay socket (rc %d, errno %d); the "
|
||||
"frame is not offered to the container",
|
||||
code, errno);
|
||||
// The relay is dropped rather than kept: a send that failed part way through would
|
||||
// leave bytes that the next handle's read would take for its own header.
|
||||
DropRelay();
|
||||
return false;
|
||||
}
|
||||
|
||||
struct iovec vector = {};
|
||||
vector.iov_base = payload;
|
||||
vector.iov_len = capacity;
|
||||
Uint8 control[CMSG_SPACE(sizeof(Int) * (SizeT)kMaxHandleFds)] = {};
|
||||
struct msghdr message = {};
|
||||
message.msg_iov = &vector;
|
||||
message.msg_iovlen = 1;
|
||||
message.msg_control = control;
|
||||
message.msg_controllen = sizeof(control);
|
||||
|
||||
// MSG_DONTWAIT for the promise at the top of this file, and MSG_CMSG_CLOEXEC so a descriptor
|
||||
// read out of the relay does not survive into a child of this process, which would then hold
|
||||
// the phone's frame until it died.
|
||||
ssize_t got = ::recvmsg(m_relay[1], &message, MSG_DONTWAIT | MSG_CMSG_CLOEXEC);
|
||||
if (got < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
|
||||
struct pollfd waiting = {};
|
||||
waiting.fd = m_relay[1];
|
||||
waiting.events = POLLIN;
|
||||
if (::poll(&waiting, 1, kRelayWaitMs) > 0) {
|
||||
// The kernel rewrites these on every call, so a retry starts from the same state as
|
||||
// the first attempt.
|
||||
message.msg_controllen = sizeof(control);
|
||||
message.msg_flags = 0;
|
||||
got = ::recvmsg(m_relay[1], &message, MSG_DONTWAIT | MSG_CMSG_CLOEXEC);
|
||||
}
|
||||
}
|
||||
if (got < 0) {
|
||||
MGLOG_W_ONCE("gbm frame channel: a relayed handle could not be read back (%d: %s); the frame is not "
|
||||
"offered to the container",
|
||||
errno, std::strerror(errno));
|
||||
DropRelay();
|
||||
return false;
|
||||
}
|
||||
if (got == 0) {
|
||||
// Zero bytes on a connected socket is the end of it. Only this process holds either end
|
||||
// of this socketpair, so this is a bug being reported rather than a peer going away.
|
||||
MGLOG_W_ONCE("gbm frame channel: the handle relay is closed; the frame is not offered to the container");
|
||||
DropRelay();
|
||||
return false;
|
||||
}
|
||||
|
||||
// The descriptors come out of the control data before anything is decided about the
|
||||
// message, because they belong to this process from the moment they were received: a path
|
||||
// that returns without closing them leaks a descriptor per frame.
|
||||
Int collected = 0;
|
||||
for (struct cmsghdr* header = CMSG_FIRSTHDR(&message); header != nullptr;
|
||||
header = CMSG_NXTHDR(&message, header)) {
|
||||
if (header->cmsg_level != SOL_SOCKET || header->cmsg_type != SCM_RIGHTS) continue;
|
||||
const SizeT bytes = (SizeT)header->cmsg_len - CMSG_LEN(0);
|
||||
const Int count = (Int)(bytes / sizeof(Int));
|
||||
const Int* descriptors = reinterpret_cast<const Int*>(CMSG_DATA(header));
|
||||
for (Int i = 0; i < count; ++i) {
|
||||
if (collected < kMaxHandleFds) {
|
||||
fds[collected++] = descriptors[i];
|
||||
} else {
|
||||
// More descriptors than a frame can carry: they are this process's now, so they
|
||||
// are closed here rather than leaked.
|
||||
CloseQuietly(descriptors[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((message.msg_flags & MSG_CTRUNC) != 0) {
|
||||
MGLOG_W_ONCE("gbm frame channel: a frame's control data did not fit in %zu bytes; the frame is not "
|
||||
"offered because its descriptor list is incomplete",
|
||||
sizeof(control));
|
||||
for (Int i = 0; i < collected; ++i) CloseQuietly(fds[i]);
|
||||
DropRelay();
|
||||
return false;
|
||||
}
|
||||
if ((message.msg_flags & MSG_TRUNC) != 0 || (SizeT)got < sizeof(GbmNativeHandleHeader)) {
|
||||
// A message longer than a handle can be, or shorter than the three counts every handle
|
||||
// begins with. Either way it cannot describe a frame, and a relay that has been read
|
||||
// past the end of one message must not carry the next frame's header: it is recreated.
|
||||
MGLOG_W_ONCE("gbm frame channel: a relayed handle is %zd bytes and %s; the frame is not offered", got,
|
||||
((message.msg_flags & MSG_TRUNC) != 0) ? "longer than a handle can be"
|
||||
: "too short to hold its own counts");
|
||||
for (Int i = 0; i < collected; ++i) CloseQuietly(fds[i]);
|
||||
DropRelay();
|
||||
return false;
|
||||
}
|
||||
|
||||
// THE BYTES THAT COME BACK ARE THE HANDLE'S INTEGER ARRAY, NOT A handle AND ITS COUNTS.
|
||||
// Measured on the phone: parsing the front of this payload as {version, numFds, numInts}
|
||||
// produced a NumFds taken from the buffer's own integer data, and every frame was refused
|
||||
// with "its handle carries more descriptors than either end takes" - which is what the
|
||||
// container saw as a connection that was accepted and then closed without a frame. The two
|
||||
// counts are known HERE and are not in those bytes: the descriptors came out of the control
|
||||
// data (collected of them) and the payload is their integer array. So the header is BUILT
|
||||
// rather than copied, and what leaves this process is a real native_handle_t layout -
|
||||
// version, numFds, numInts, then the ints - which is exactly what the container's parser
|
||||
// reads (GbmInternal.h's AHBNativeHandleHeader).
|
||||
if (payloadBytes + sizeof(GbmNativeHandleHeader) > capacity) {
|
||||
MGLOG_W_ONCE("gbm frame channel: a handle's integer array does not fit in a frame message with its "
|
||||
"header; the frame is not offered to the container");
|
||||
for (Int i = 0; i < collected; ++i) CloseQuietly(fds[i]);
|
||||
DropRelay();
|
||||
return false;
|
||||
}
|
||||
std::memmove(payload + sizeof(GbmNativeHandleHeader), payload, payloadBytes);
|
||||
GbmNativeHandleHeader header = {};
|
||||
header.Version = (Int32)sizeof(GbmNativeHandleHeader);
|
||||
header.NumFds = (Int32)collected;
|
||||
header.NumInts = (Int32)(payloadBytes / sizeof(Int32));
|
||||
std::memcpy(payload, &header, sizeof(header));
|
||||
payloadBytes += sizeof(header);
|
||||
fdCount = collected;
|
||||
return true;
|
||||
}
|
||||
|
||||
// The acceptor. It touches the listener - its own copy of the descriptor, which nothing else
|
||||
// closes while this loop runs - and, once per dialer, the channel under its lock.
|
||||
void GbmFrameChannel::AcceptLoop(Int listen) {
|
||||
while (m_accepting.load(std::memory_order_acquire)) {
|
||||
struct pollfd waiting = {};
|
||||
waiting.fd = listen;
|
||||
waiting.events = POLLIN;
|
||||
const Int ready = ::poll(&waiting, 1, kAcceptPollMs);
|
||||
if (ready < 0) {
|
||||
if (errno == EINTR) continue;
|
||||
MGLOG_W_ONCE("gbm frame channel: poll on the listening socket failed (%d: %s); no container can be "
|
||||
"taken in until the socket is opened again",
|
||||
errno, std::strerror(errno));
|
||||
return;
|
||||
}
|
||||
if (ready == 0) continue;
|
||||
// accept4, so the connection is close-on-exec and non-blocking from the moment it
|
||||
// exists: a container that stops reading must not be able to park a send on either
|
||||
// thread.
|
||||
const Int fd = ::accept4(listen, nullptr, nullptr, SOCK_CLOEXEC | SOCK_NONBLOCK);
|
||||
if (fd < 0) {
|
||||
if (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK || errno == ECONNABORTED) continue;
|
||||
MGLOG_W_ONCE("gbm frame channel: accept failed (%d: %s); no container can be taken in until the "
|
||||
"socket is opened again",
|
||||
errno, std::strerror(errno));
|
||||
return;
|
||||
}
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
AdoptLocked(fd);
|
||||
}
|
||||
}
|
||||
|
||||
void GbmFrameChannel::AdoptLocked(Int fd) {
|
||||
if (ClientAliveLocked()) {
|
||||
// ONE CLIENT, which is what the protocol is written for, and a dialer that arrives while
|
||||
// a live one is connected is closed rather than left connected - it learns it is not the
|
||||
// one being served instead of holding a connection whose frames nobody reads.
|
||||
CloseQuietly(fd);
|
||||
MGLOG_W_ONCE("gbm frame channel: a second peer dialled %s while a container is connected; it is closed "
|
||||
"and the frames stay with the connected one",
|
||||
m_path.c_str());
|
||||
return;
|
||||
}
|
||||
m_client = fd;
|
||||
MGLOG_I("gbm frame channel: a container is connected on %s; every frame the host offers is sent to it as "
|
||||
"the dma-buf descriptor behind it",
|
||||
m_path.c_str());
|
||||
// AND THE FRAME IT DIALED FOR GOES OUT FROM HERE. A compositor creates its GBM device before
|
||||
// it asks for a surface, so the frame that is the draw target right now was offered before
|
||||
// this connection existed; a container that is not told about it allocates every buffer of
|
||||
// its new swapchain locally, and keeps them for the life of the process.
|
||||
ReofferFrameLocked();
|
||||
}
|
||||
|
||||
Bool GbmFrameChannel::ClientAliveLocked() {
|
||||
if (m_client < 0) return false;
|
||||
Uint8 peek = 0;
|
||||
// MSG_PEEK, because a release waiting in the socket belongs to the render path: this test
|
||||
// only asks whether the peer is still there, and a release it consumed would be a frame the
|
||||
// channel believed was still outstanding.
|
||||
const ssize_t got = ::recv(m_client, &peek, sizeof(peek), MSG_DONTWAIT | MSG_PEEK);
|
||||
if (got > 0) return true;
|
||||
if (got == 0) {
|
||||
// Zero bytes on a connected socket is the end of it, whether the container exited or
|
||||
// the kernel gave up on it. A compositor that crashed and is being restarted is
|
||||
// exactly this, and its successor is the dialer standing right here.
|
||||
MarkDown("the container closed the connection", 0);
|
||||
return false;
|
||||
}
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) return true;
|
||||
MarkDown("recv", errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
void GbmFrameChannel::MarkDown(const char* what, Int error) {
|
||||
if (m_client < 0) return;
|
||||
CloseQuietly(m_client);
|
||||
m_client = -1;
|
||||
if (error != 0) {
|
||||
MGLOG_W("gbm frame channel: the container connection is down: %s failed (%d: %s); the frames are still "
|
||||
"drawn and presented, and the container stops receiving them until it dials again",
|
||||
what, error, std::strerror(error));
|
||||
} else {
|
||||
MGLOG_W("gbm frame channel: the container connection is down: %s; the frames are still drawn and "
|
||||
"presented, and the container stops receiving them until it dials again",
|
||||
what);
|
||||
}
|
||||
}
|
||||
|
||||
Bool GbmFrameChannel::OfferFrame(struct AHardwareBuffer* buffer, const HostFrameOffer& offer) {
|
||||
if (buffer == nullptr) return false;
|
||||
// Open() does nothing once the socket exists, so this is an integer test in the common case.
|
||||
Open();
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
// The releases the container has sent since the last frame, which is also how a container
|
||||
// that died is noticed. Whoever replaced it was taken by the acceptor's own thread the
|
||||
// moment it dialled: that thread is what makes a container's connect() succeed at all.
|
||||
PollLocked();
|
||||
// AND THE FRAME IS REMEMBERED BEFORE IT IS SENT. A container that dials while this call is
|
||||
// running is one the acceptor hands the frame it finds here to, so the two threads must not
|
||||
// be able to disagree about which frame is the one being drawn into.
|
||||
const Uint32 seq = m_nextSeq;
|
||||
RememberFrameLocked(buffer, offer, seq);
|
||||
if (m_client < 0) return false;
|
||||
return SendFrameLocked(buffer, offer, seq, /*counting=*/true);
|
||||
}
|
||||
|
||||
void GbmFrameChannel::RememberFrameLocked(struct AHardwareBuffer* buffer, const HostFrameOffer& offer, Uint32 seq) {
|
||||
if (m_frame == buffer) {
|
||||
// The host redrawing into the buffer it already handed over: the same frame under a new
|
||||
// sequence number. Acquiring it again would be a reference this channel takes and never
|
||||
// gives back.
|
||||
m_frameOffer = offer;
|
||||
m_frameSeq = seq;
|
||||
return;
|
||||
}
|
||||
// The reference is this channel's own, and it is what makes the frame a container that dials
|
||||
// late is owed safe to hold: the backend drops its handle the moment the frame is presented,
|
||||
// and a frame owed to a dialer arriving in the same millisecond may not be memory that has
|
||||
// already gone back to the host's pool.
|
||||
AHardwareBuffer_acquire(buffer);
|
||||
ReleaseFrameLocked();
|
||||
m_frame = buffer;
|
||||
m_frameOffer = offer;
|
||||
m_frameSeq = seq;
|
||||
}
|
||||
|
||||
void GbmFrameChannel::ReleaseFrameLocked() {
|
||||
if (m_frame == nullptr) return;
|
||||
AHardwareBuffer_release(m_frame);
|
||||
m_frame = nullptr;
|
||||
m_frameOffer = {};
|
||||
m_frameSeq = 0;
|
||||
}
|
||||
|
||||
void GbmFrameChannel::DropFrame() {
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
ReleaseFrameLocked();
|
||||
}
|
||||
|
||||
void GbmFrameChannel::ReofferFrameLocked() {
|
||||
if (m_frame == nullptr) return;
|
||||
// The same frame, under the sequence number it was offered with: it IS the frame that is the
|
||||
// draw target now, and a second number for it would be this channel claiming the host had
|
||||
// handed over a frame it never handed over.
|
||||
MGLOG_I("gbm frame channel: a container dialled after frame %u was offered; it is sent that frame, which is "
|
||||
"still the draw target",
|
||||
m_frameSeq);
|
||||
SendFrameLocked(m_frame, m_frameOffer, m_frameSeq, /*counting=*/false);
|
||||
}
|
||||
|
||||
Bool GbmFrameChannel::SendFrameLocked(struct AHardwareBuffer* buffer, const HostFrameOffer& offer, Uint32 seq,
|
||||
Bool counting) {
|
||||
if (m_client < 0) return false;
|
||||
|
||||
Uint8 payload[kMessageMax];
|
||||
SizeT payloadBytes = 0;
|
||||
Int fds[kMaxHandleFds];
|
||||
for (Int i = 0; i < kMaxHandleFds; ++i) fds[i] = -1;
|
||||
Int fdCount = 0;
|
||||
if (!RelayHandle(buffer, payload, sizeof(payload), payloadBytes, fds, fdCount)) return false;
|
||||
|
||||
GbmNativeHandleHeader handle = {};
|
||||
std::memcpy(&handle, payload, sizeof(handle));
|
||||
const SizeT tail = ((SizeT)handle.NumFds + (SizeT)handle.NumInts) * sizeof(Int32);
|
||||
const SizeT messageBytes = sizeof(GbmFrameOffer) + sizeof(GbmNativeHandleHeader) + tail;
|
||||
|
||||
// EVERY REASON THIS CHANNEL REFUSES A FRAME, IN ONE PLACE. Each of them is a frame the
|
||||
// container would refuse anyway - it checks the same counts and the same geometry - and a
|
||||
// frame that is refused here costs nothing: no message, no sequence number, and no entry in
|
||||
// the count of frames waiting to be released.
|
||||
const char* refusal = nullptr;
|
||||
if (offer.Width == 0 || offer.Height == 0 || offer.StrideBytes == 0) {
|
||||
refusal = "the host described it with a width, height or stride of zero, and a buffer with no size is "
|
||||
"not one a compositor can render into";
|
||||
} else if (handle.NumFds < 1) {
|
||||
refusal = "its handle carries no descriptor, and a frame without a dma-buf is not one the container "
|
||||
"can render into";
|
||||
} else if (handle.NumFds > kMaxHandleFds) {
|
||||
refusal = "its handle carries more descriptors than either end takes";
|
||||
} else if (handle.NumInts < 0) {
|
||||
refusal = "its handle claims a negative number of integers";
|
||||
} else if ((SizeT)handle.NumInts > kMessageMax / sizeof(Int32)) {
|
||||
// This is what keeps the message's length arithmetic from wrapping on a 32 bit ABI: a
|
||||
// handle whose integer array alone is longer than a whole message cannot be carried by
|
||||
// this protocol whatever the rest of it says, and the check below would otherwise be
|
||||
// reading a number that had already turned into a small and plausible one.
|
||||
refusal = "its handle names more integers than a whole message could carry";
|
||||
} else if (fdCount < handle.NumFds) {
|
||||
refusal = "fewer descriptors arrived with it than its handle names";
|
||||
} else if (messageBytes > kMessageMax) {
|
||||
refusal = "the message it makes is longer than the container reads";
|
||||
}
|
||||
|
||||
Bool offered = false;
|
||||
if (refusal != nullptr) {
|
||||
// ONCE, not per frame: a host that describes every frame the same broken way must not
|
||||
// turn this into a line per frame on the apply thread.
|
||||
MGLOG_W_ONCE("gbm frame channel: frame %u (%ux%u) is not offered to the container: %s", offer.Index,
|
||||
offer.Width, offer.Height, refusal);
|
||||
} else {
|
||||
// One message, built whole: the offer, then the handle's own three counts, then the two
|
||||
// arrays the counts describe. What came back from the relay is copied in as far as it
|
||||
// goes and the remainder is left zero, because the container checks the LENGTH it
|
||||
// derives from those counts and never reads the arrays themselves - it takes the
|
||||
// descriptors from the control data and hands the first one to GBM. So a handle whose
|
||||
// bytes are shorter than its own counts imply is padded rather than refused, and one
|
||||
// longer than they imply is cut to what the counts say; either way the length the
|
||||
// container computes is the length it receives.
|
||||
Uint8 message[kMessageMax] = {};
|
||||
GbmFrameOffer out = {};
|
||||
out.Magic = kGbmFrameOfferMagic;
|
||||
out.Version = kGbmFrameVersion;
|
||||
out.Seq = seq;
|
||||
out.Index = offer.Index;
|
||||
out.Width = offer.Width;
|
||||
out.Height = offer.Height;
|
||||
out.StrideBytes = offer.StrideBytes;
|
||||
out.Format = offer.Format;
|
||||
out.UsageLo = offer.UsageLo;
|
||||
out.UsageHi = offer.UsageHi;
|
||||
std::memcpy(message, &out, sizeof(out));
|
||||
const SizeT handleBytes = (payloadBytes < sizeof(GbmNativeHandleHeader) + tail)
|
||||
? payloadBytes
|
||||
: (sizeof(GbmNativeHandleHeader) + tail);
|
||||
std::memcpy(message + sizeof(out), payload, handleBytes);
|
||||
|
||||
struct iovec vector = {};
|
||||
vector.iov_base = message;
|
||||
vector.iov_len = messageBytes;
|
||||
Uint8 control[CMSG_SPACE(sizeof(Int) * (SizeT)kMaxHandleFds)] = {};
|
||||
struct msghdr outgoing = {};
|
||||
outgoing.msg_iov = &vector;
|
||||
outgoing.msg_iovlen = 1;
|
||||
outgoing.msg_control = control;
|
||||
outgoing.msg_controllen = CMSG_SPACE(sizeof(Int) * (SizeT)handle.NumFds);
|
||||
struct cmsghdr* rights = CMSG_FIRSTHDR(&outgoing);
|
||||
rights->cmsg_level = SOL_SOCKET;
|
||||
rights->cmsg_type = SCM_RIGHTS;
|
||||
rights->cmsg_len = CMSG_LEN(sizeof(Int) * (SizeT)handle.NumFds);
|
||||
std::memcpy(CMSG_DATA(rights), fds, sizeof(Int) * (SizeT)handle.NumFds);
|
||||
|
||||
// MSG_DONTWAIT for the promise at the top of this file, and MSG_NOSIGNAL because a
|
||||
// server killed by SIGPIPE when the container goes away takes the frames it was drawing
|
||||
// with it. A full socket, a reset peer and a broken pipe all say the same thing here:
|
||||
// this connection can no longer be trusted with a frame, so it is closed and the next
|
||||
// container to dial is served.
|
||||
const ssize_t sent = ::sendmsg(m_client, &outgoing, MSG_DONTWAIT | MSG_NOSIGNAL);
|
||||
if (sent != (ssize_t)messageBytes) {
|
||||
MarkDown("sendmsg", (sent < 0) ? errno : 0);
|
||||
} else {
|
||||
// A frame offered for the first time is the next sequence number and one more frame
|
||||
// outstanding. The same frame sent again to a container that has just dialled is
|
||||
// neither: the host handed over nothing new, and a count of frames waiting to be
|
||||
// released may not be moved by a message that describes one already in it.
|
||||
if (counting) {
|
||||
m_nextSeq = seq + 1;
|
||||
++m_offered;
|
||||
++m_outstanding;
|
||||
}
|
||||
offered = true;
|
||||
// The first offer is the one worth a line, and it carries the host's own numbers:
|
||||
// the format in particular is the field the two ends could disagree about without
|
||||
// either failing, so the value the host actually sends is put where a run on a
|
||||
// device can be read afterwards.
|
||||
MGLOG_I_ONCE("gbm frame channel: the first frame is offered to the container (seq %u index %u %ux%u "
|
||||
"stride %u format 0x%08x)",
|
||||
out.Seq, out.Index, out.Width, out.Height, out.StrideBytes, out.Format);
|
||||
MGLOG_D("gbm frame channel: frame seq=%u index=%u offered (%zu bytes, %d descriptor(s), %llu "
|
||||
"outstanding)",
|
||||
out.Seq, out.Index, messageBytes, handle.NumFds, (unsigned long long)m_outstanding);
|
||||
}
|
||||
}
|
||||
|
||||
// The kernel took its own copies of these when the message was sent, and one that was not
|
||||
// sent is not the container's to hold: every path closes what the relay handed over.
|
||||
for (Int i = 0; i < fdCount; ++i) CloseQuietly(fds[i]);
|
||||
return offered;
|
||||
}
|
||||
|
||||
void GbmFrameChannel::Poll() {
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
PollLocked();
|
||||
}
|
||||
|
||||
void GbmFrameChannel::PollLocked() {
|
||||
if (m_client < 0) return;
|
||||
for (Int drained = 0; drained < kDrainMax; ++drained) {
|
||||
GbmFrameRelease release = {};
|
||||
struct iovec vector = {};
|
||||
vector.iov_base = &release;
|
||||
vector.iov_len = sizeof(release);
|
||||
struct msghdr message = {};
|
||||
message.msg_iov = &vector;
|
||||
message.msg_iovlen = 1;
|
||||
// recvmsg and not recv, for MSG_TRUNC: a message longer than a release can only be a
|
||||
// peer speaking something else, and a release read out of the first twelve bytes of it
|
||||
// would name a frame nobody released.
|
||||
const ssize_t got = ::recvmsg(m_client, &message, MSG_DONTWAIT);
|
||||
if (got < 0) {
|
||||
if (errno == EINTR) continue;
|
||||
// Nothing said, which is what a container that is between frames looks like.
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) return;
|
||||
MarkDown("recvmsg", errno);
|
||||
return;
|
||||
}
|
||||
if (got == 0) {
|
||||
// Zero bytes on a connected socket is the end of it, whether the container exited or
|
||||
// the kernel gave up on it. Its replacement is taken by the next frame.
|
||||
MarkDown("the container closed the connection", 0);
|
||||
return;
|
||||
}
|
||||
if ((message.msg_flags & MSG_TRUNC) != 0 || got != (ssize_t)sizeof(release)) {
|
||||
// The message is skipped, not the connection: on a message-oriented socket a
|
||||
// message too long for the buffer is consumed whole, so the next one is still a
|
||||
// message rather than the tail of this one.
|
||||
MGLOG_W_ONCE("gbm frame channel: the container sent a message that is not a %zu byte release; it is "
|
||||
"skipped",
|
||||
sizeof(release));
|
||||
continue;
|
||||
}
|
||||
if (release.Magic != kGbmFrameReleaseMagic) {
|
||||
MGLOG_W_ONCE("gbm frame channel: a message from the container begins with 0x%08x rather than 'MGGR'; "
|
||||
"it is skipped",
|
||||
release.Magic);
|
||||
continue;
|
||||
}
|
||||
if (release.Version != kGbmFrameVersion) {
|
||||
// Refused rather than acted on: the version is what says how the rest of the message
|
||||
// is laid out, and a release read with the wrong layout names a frame the container
|
||||
// did not mean.
|
||||
MGLOG_E_ONCE("gbm frame channel: the container speaks protocol version %u where this server speaks "
|
||||
"version %u; its releases are refused until the two agree",
|
||||
release.Version, (Uint32)kGbmFrameVersion);
|
||||
continue;
|
||||
}
|
||||
++m_released;
|
||||
if (m_outstanding > 0) --m_outstanding;
|
||||
// The first release is the only one worth a line: it is the proof that the container
|
||||
// took the descriptor and its compositor retired the frame, where every later one says
|
||||
// the same thing sixty times a second.
|
||||
MGLOG_I_ONCE("gbm frame channel: the container is releasing frames (first: seq %u)", release.Seq);
|
||||
}
|
||||
// Anything past this cap stays in the socket, whose buffer the kernel bounds, and goes out
|
||||
// with the next frame: a peer that says nothing but releases may not spend the apply thread
|
||||
// here.
|
||||
}
|
||||
|
||||
void GbmFrameChannel::Close() {
|
||||
// THE ACCEPTOR IS STOPPED AND JOINED FIRST, and outside the lock. It may be inside that
|
||||
// lock when this is called - a teardown that waited for it while holding it would wait for
|
||||
// ever - and it polls the listening descriptor, which may not be closed under it: the next
|
||||
// open() in this process hands out the descriptor number a moment later, and the thread
|
||||
// would then be polling somebody else's socket.
|
||||
m_accepting.store(false, std::memory_order_release);
|
||||
if (m_acceptor.joinable()) m_acceptor.join();
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
// The frame is this channel's reference and is released with it: the backend has already
|
||||
// dropped its own by the time a teardown here is a teardown of the frame as well.
|
||||
ReleaseFrameLocked();
|
||||
// The connection is closed quietly rather than marked down: this is a teardown, not a
|
||||
// failure, and a warning about it would be noise in a log read for the failures.
|
||||
CloseQuietly(m_client);
|
||||
m_client = -1;
|
||||
DropRelay();
|
||||
if (m_listen >= 0) {
|
||||
// The node is this channel's to remove only while it still IS this channel's socket: a
|
||||
// server that was restarted has bound the same path with a socket of its own, and a
|
||||
// teardown that unlinked it would take the successor's node away with it. st_dev and
|
||||
// st_ino against the listening descriptor is the cheapest way to ask, and a check that
|
||||
// fails only leaves a name behind that the next Open() unlinks anyway.
|
||||
struct stat node = {};
|
||||
struct stat socket = {};
|
||||
if (!m_path.empty() && ::stat(m_path.c_str(), &node) == 0 && ::fstat(m_listen, &socket) == 0 &&
|
||||
node.st_dev == socket.st_dev && node.st_ino == socket.st_ino) {
|
||||
::unlink(m_path.c_str());
|
||||
}
|
||||
CloseQuietly(m_listen);
|
||||
m_listen = -1;
|
||||
}
|
||||
m_path.clear();
|
||||
// The counters are history and stay: a caller that logs Outstanding() after a teardown is
|
||||
// asking what happened, and IsUp() is what answers what is connected now.
|
||||
}
|
||||
}
|
||||
|
||||
#else // !(MOBILEGL_BUILD_DISAGGREGATED && __ANDROID__)
|
||||
|
||||
namespace MobileGL::MG_Backend {
|
||||
// A build that is not the Android render server has no AHardwareBuffer to offer and no
|
||||
// container beside it. The class exists so that callers do not have to be compiled
|
||||
// differently, and every entry point answers the way an absent container does.
|
||||
GbmFrameChannel::~GbmFrameChannel() = default;
|
||||
Bool GbmFrameChannel::Open() { return false; }
|
||||
Bool GbmFrameChannel::OfferFrame(struct AHardwareBuffer*, const HostFrameOffer&) { return false; }
|
||||
void GbmFrameChannel::Poll() {}
|
||||
void GbmFrameChannel::Close() {}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// End of Source File Header
|
||||
@@ -1,281 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/GbmFrameChannel.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
|
||||
#include "HostFrameBridge.h"
|
||||
|
||||
struct AHardwareBuffer;
|
||||
|
||||
namespace MobileGL::MG_Backend {
|
||||
// THE FRAME THE HOST HANDED OVER, HANDED ON TO THE CONTAINER AS A dma-buf.
|
||||
//
|
||||
// The display host owns a pool of AHardwareBuffers: it allocates them, this side imports the
|
||||
// one it offers as a draw target (HostFrameBridge, DirectGLES::HostFrameTarget), and the host
|
||||
// puts it on the glass when this side answers that it is drawn. The Wayland compositor in the
|
||||
// Linux container has to render into THOSE SAME frames - it runs this project's own GBM, and a
|
||||
// gbm_bo_create there answers with the phone's frame instead of a dma-heap allocation of its
|
||||
// own - so every frame this side takes has to reach the container as that frame's dma-buf
|
||||
// descriptor. That, and the release that comes back, is all this channel carries.
|
||||
//
|
||||
// The container's end is MobileGL/MG_Gbm/GbmHostChannel.cpp. It reads exactly the bytes
|
||||
// declared below and answers with a release once its compositor no longer reads the frame.
|
||||
// The three shapes ARE that file's GbmFrameOffer/GbmFrameRelease and GbmInternal.h's
|
||||
// AHBNativeHandleHeader, field for field and packing included. They are restated here rather
|
||||
// than shared because the two ends are built into different libraries from different build
|
||||
// configurations: MG_Backend is the Android render server and never sees libgbm's headers,
|
||||
// while MG_Gbm is built for the container and never sees Android's. A change on either side
|
||||
// is a protocol change, and the magic is what makes a mismatched pair fail loudly instead of
|
||||
// being read as plausible numbers.
|
||||
//
|
||||
// ONE MESSAGE PER FRAME, on SOCK_SEQPACKET, and that is part of the protocol rather than an
|
||||
// implementation detail: an offer and its handle only mean anything together, and the message
|
||||
// boundary is what lets the reader take the two as one thing. The container derives the
|
||||
// length of the message it expects from the handle's own two counts and refuses any other
|
||||
// length, so this end sends the offer immediately followed by the handle's counts and its two
|
||||
// arrays, with the descriptors in the SCM_RIGHTS control data of that same sendmsg.
|
||||
//
|
||||
// The channel is OPTIONAL, and that is the rule the implementation is built around: a
|
||||
// container that is not running, has died, or has stopped reading may cost the render path a
|
||||
// syscall or two, and may never block it, fail it, or grow without bound. Every entry point
|
||||
// below is non-blocking and answers silence with silence.
|
||||
inline constexpr Uint32 kGbmFrameOfferMagic = 0x4647474Du; // 'M','G','G','F' in memory order
|
||||
inline constexpr Uint32 kGbmFrameReleaseMagic = 0x5247474Du; // 'M','G','G','R' in memory order
|
||||
inline constexpr Uint32 kGbmFrameVersion = 1u;
|
||||
// WHERE THE CONTAINER DIALS. /data/local/tmp is the one directory both halves of a split run
|
||||
// can be pointed at on a device, and the default lives on this end because this end is the
|
||||
// server. The container's compiled-in default is /run/mobilegl-gbm.sock - the same protocol
|
||||
// with the path each side can reach unaided - so a deployment that puts the two in different
|
||||
// mount namespaces sets MOBILEGL_GBM_SOCKET on both; it is read here and in
|
||||
// GbmHostChannelCreate, from the same variable, for that reason.
|
||||
inline constexpr const char* kGbmFrameSocketPath = "/data/local/tmp/mobilegl-gbm.sock";
|
||||
inline constexpr const char* kGbmFrameSocketEnv = "MOBILEGL_GBM_SOCKET";
|
||||
|
||||
// One frame the host offered, described for the container. Width, Height, StrideBytes and
|
||||
// Format are the host's own numbers for the frame (HostFrameOffer), carried through
|
||||
// unchanged: they describe the memory the descriptor points at, and this end is not the place
|
||||
// where a number the other two ends agreed on gets rewritten.
|
||||
struct GbmFrameOffer {
|
||||
Uint32 Magic;
|
||||
Uint32 Version;
|
||||
Uint32 Seq; // this channel's, one per frame offered
|
||||
Uint32 Index; // the host's own buffer index, echoed so the phone can match a frame
|
||||
Uint32 Width;
|
||||
Uint32 Height;
|
||||
Uint32 StrideBytes;
|
||||
Uint32 Format;
|
||||
Uint32 UsageLo;
|
||||
Uint32 UsageHi;
|
||||
} __attribute__((packed));
|
||||
|
||||
// What the container says once it is done with a frame. It may arrive late, it may never
|
||||
// arrive, and both are cheap here: the channel keeps a count and no per-frame record (see
|
||||
// Outstanding below), so nothing is leaked and nothing grows when one is missed.
|
||||
struct GbmFrameRelease {
|
||||
Uint32 Magic;
|
||||
Uint32 Version;
|
||||
Uint32 Seq;
|
||||
} __attribute__((packed));
|
||||
|
||||
// THE OTHER DIRECTION: A dma-buf THE CONTAINER WANTS THIS SIDE TO BACK A TEXTURE WITH.
|
||||
//
|
||||
// The compositor's scene reaches the display daemon's dma-bufs through glEGLImageTargetTexture2DOES
|
||||
// (MG_Impl/GLImpl/Exporting/Definitions.cpp, MG_Backend/DirectGLES/BackendObject_DirectGLES.cpp both
|
||||
// name this half as the next change). eglCreateImageKHR has already held a dup() of every plane's
|
||||
// descriptor since the image was made; what was missing is the render server's half - telling THIS
|
||||
// side which texture that dma-buf backs, over the one channel that can carry a descriptor across the
|
||||
// container boundary. This message is that half: the client names the texture target and the
|
||||
// texture's own name, describes the buffer exactly as drmModeAddFB2 would, and the plane descriptors
|
||||
// ride in the SCM_RIGHTS control data of the same sendmsg. One message per import, as SEQPACKET
|
||||
// requires, so a descriptor and its description are never read apart.
|
||||
//
|
||||
// The reply is what the client waits for before a framebuffer is allowed to be complete over the
|
||||
// texture: Ok=0 means this side could not make the import real, and the client keeps treating the
|
||||
// texture as having no storage rather than letting it render into nothing.
|
||||
inline constexpr Uint32 kGbmImportRequestMagic = 0x4947474Du; // 'M','G','G','I' in memory order
|
||||
inline constexpr Uint32 kGbmImportReplyMagic = 0x52474749u; // 'I','G','G','R' in memory order
|
||||
inline constexpr Uint32 kGbmImportVersion = 1u;
|
||||
inline constexpr Uint32 kGbmImportMaxPlanes = 4u;
|
||||
|
||||
struct GbmImportRequest {
|
||||
Uint32 Magic;
|
||||
Uint32 Version;
|
||||
Uint32 Target; // the GL texture target the image was bound to (0x8D65 = GL_TEXTURE_EXTERNAL_OES)
|
||||
Uint32 TexName; // the CLIENT's texture name; this side resolves its twin
|
||||
Uint32 Width;
|
||||
Uint32 Height;
|
||||
Uint32 FourCC;
|
||||
Uint32 PlaneCount; // 1..kGbmImportMaxPlanes; the descriptors are the message's control data
|
||||
Int32 Stride[kGbmImportMaxPlanes];
|
||||
Int32 Offset[kGbmImportMaxPlanes];
|
||||
Uint64 Modifier[kGbmImportMaxPlanes];
|
||||
Uint32 HasModifier[kGbmImportMaxPlanes];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct GbmImportReply {
|
||||
Uint32 Magic;
|
||||
Uint32 Version;
|
||||
Uint32 Ok;
|
||||
Uint32 Reserved;
|
||||
} __attribute__((packed));
|
||||
|
||||
// An AHardwareBuffer native handle as it appears on the wire: the platform's native_handle_t
|
||||
// (version, then the two counts, then the descriptor array followed by the integer array),
|
||||
// written by AHardwareBuffer_sendHandleToUnixSocket and read by the container's
|
||||
// AHBNativeHandleHeader. The counts are 32 bit on every Android ABI, which is why they are
|
||||
// spelled out here rather than taken from a platform header this library cannot include.
|
||||
struct GbmNativeHandleHeader {
|
||||
Int32 Version;
|
||||
Int32 NumFds;
|
||||
Int32 NumInts;
|
||||
} __attribute__((packed));
|
||||
|
||||
// ONE CONTAINER, ONE LISTENING SOCKET, TWO THREADS: the render path's, and an acceptor's.
|
||||
//
|
||||
// A compositor dials ONCE - when it creates its GBM device - and keeps that connection for the
|
||||
// life of the process, while this side offers a frame per drawn frame. An accept that only ran
|
||||
// inside OfferFrame therefore ran after the dial it was supposed to answer, and a dialer that
|
||||
// nobody took kept the listener's queue full for every later one. That is measured on the
|
||||
// phone rather than argued: with accept() only on the offer path, connect() from the container
|
||||
// answered EAGAIN(11) on four attempts out of four while the node sat there listening.
|
||||
//
|
||||
// So the accept has a thread of its own, started by Open() and stopped by Close(), and it
|
||||
// adopts what it takes on the spot - including sending it the frame the host last handed over,
|
||||
// because a compositor's first allocation is the one its swapchain is built from. The
|
||||
// connected socket, the frame that is remembered, the relay and the counters are shared between
|
||||
// the two threads and guarded by the one mutex below; both entry points are non-blocking, so
|
||||
// neither thread can park the other for longer than a syscall.
|
||||
class GbmFrameChannel {
|
||||
public:
|
||||
GbmFrameChannel() = default;
|
||||
GbmFrameChannel(const GbmFrameChannel&) = delete;
|
||||
GbmFrameChannel& operator=(const GbmFrameChannel&) = delete;
|
||||
~GbmFrameChannel();
|
||||
|
||||
// Creates the listening socket if it is not there yet and starts the acceptor, and does
|
||||
// nothing otherwise. It never waits for a container: the socket is bound, a backlog is
|
||||
// given to listen(), and the acceptor takes whoever dials from then on - whether or not a
|
||||
// frame is being drawn. A caller that wants the container to find the socket before the
|
||||
// first frame - the container dials once at its own device creation and retries about once
|
||||
// a second - can call this when the host-framed surface is initialized, beside
|
||||
// HostFrameBridge::Open.
|
||||
Bool Open();
|
||||
|
||||
// Offers one frame the host just handed over, as the dma-buf descriptor behind it.
|
||||
// False means the frame did not go out, for any of the reasons this channel treats as
|
||||
// ordinary: no container is connected, the container just died, or the frame could not be
|
||||
// described. None of them is the caller's problem and none of them is fatal - the frame
|
||||
// is drawn and presented exactly as it would have been without a channel at all.
|
||||
Bool OfferFrame(struct AHardwareBuffer* buffer, const HostFrameOffer& offer);
|
||||
|
||||
// Reads whatever the container has said since the last call and marks the channel down if
|
||||
// the connection has ended. OfferFrame already does this once per frame, so a caller only
|
||||
// needs it if it wants releases drained on a path that has no new frame in it.
|
||||
void Poll();
|
||||
|
||||
// The frame the host handed over is gone - it was presented, or it was replaced - and this
|
||||
// channel may no longer hold it or offer it to anybody. THE CHANNEL ITSELF STAYS OPEN, and
|
||||
// that is the point of the call: the listening socket, its node and the container's
|
||||
// connection outlive every frame, and a channel that was closed and reopened per frame took
|
||||
// the node away sixty times a second - a container dialling at the wrong moment got ENOENT
|
||||
// for a socket that was there a millisecond earlier and would be there a millisecond later.
|
||||
void DropFrame();
|
||||
|
||||
// True while a container is connected and the frames are being offered to it.
|
||||
Bool IsUp() const {
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
return m_client >= 0;
|
||||
}
|
||||
|
||||
// How many frames have been offered and not released, as a count of messages and not a
|
||||
// record of them. It is here to be logged, and it is deliberately the only per-frame state
|
||||
// the channel keeps: a release that never arrives costs a number that is too high, and
|
||||
// nothing else, which is what makes a container that stops reading harmless.
|
||||
Uint64 Outstanding() const {
|
||||
const std::lock_guard<std::mutex> lock(m_mutex);
|
||||
return m_outstanding;
|
||||
}
|
||||
|
||||
// Closes the connection, the listening socket and the node it created. Idempotent, safe
|
||||
// from a destructor, and safe to call while a container is connected: the container sees
|
||||
// the connection end and goes back to allocating its frames locally, which is the state it
|
||||
// starts in.
|
||||
void Close();
|
||||
|
||||
private:
|
||||
// The socketpair a frame's handle is handed to and read back from. Recreated on demand,
|
||||
// because the one call the NDK offers for a buffer's descriptors sends them as a message
|
||||
// of its own and the container takes one message per frame - see the note in the .cpp.
|
||||
Bool EnsureRelay();
|
||||
void DropRelay();
|
||||
Bool RelayHandle(struct AHardwareBuffer* buffer, Uint8* payload, SizeT capacity, SizeT& payloadBytes,
|
||||
Int* fds, Int& fdCount);
|
||||
|
||||
// Takes the one container the protocol allows, and closes anyone else who dials while a
|
||||
// LIVE one is connected rather than leaving them to believe they are being served. A
|
||||
// connection whose peer has exited is not a live one: it is closed here and its dialer's
|
||||
// replacement is taken, which is what a compositor that crashed and was restarted is.
|
||||
void AdoptLocked(Int fd);
|
||||
|
||||
// True while the connected container is still there. recvmsg with MSG_PEEK is what asks:
|
||||
// zero bytes is the peer's close, EAGAIN is a peer that is between frames, and a release
|
||||
// waiting in the socket is a peer that is alive - peeked at rather than read, because the
|
||||
// render path is the one that spends releases.
|
||||
Bool ClientAliveLocked();
|
||||
|
||||
// Takes the one container the protocol allows out of whoever dialled.
|
||||
void AcceptLoop(Int listen);
|
||||
|
||||
// Sends the frame that is the draw target to a container that has just connected.
|
||||
void ReofferFrameLocked();
|
||||
|
||||
// Remembers the frame the host last handed over, holding a reference to it so that a
|
||||
// container which dials after the offer can still be given it. The previous one is
|
||||
// released here; nothing else in the channel holds a frame.
|
||||
void RememberFrameLocked(struct AHardwareBuffer* buffer, const HostFrameOffer& offer, Uint32 seq);
|
||||
void ReleaseFrameLocked();
|
||||
|
||||
// The offer itself: the handle relayed out of the buffer, the message built, one sendmsg.
|
||||
// A frame that has already been offered once is sent again with the sequence number it was
|
||||
// offered under and does not move the counters, because it is the same frame and not a new
|
||||
// one.
|
||||
Bool SendFrameLocked(struct AHardwareBuffer* buffer, const HostFrameOffer& offer, Uint32 seq, Bool counting);
|
||||
|
||||
// The body of Poll(), for a caller that is already holding the lock.
|
||||
void PollLocked();
|
||||
|
||||
// Closes the connection and says why, once. The channel stays open for the next container.
|
||||
void MarkDown(const char* what, Int error);
|
||||
|
||||
Int m_listen = -1;
|
||||
Int m_client = -1;
|
||||
Int m_relay[2] = {-1, -1};
|
||||
String m_path;
|
||||
// Bumped only for a frame that actually went out, so a sequence number is never reused and
|
||||
// a release can never be read as belonging to a frame of an earlier connection.
|
||||
Uint32 m_nextSeq = 0;
|
||||
Uint64 m_offered = 0;
|
||||
Uint64 m_released = 0;
|
||||
Uint64 m_outstanding = 0;
|
||||
// The frame the host handed over most recently, held by this channel's own reference for as
|
||||
// long as it is the draw target: it is what a container that dials late is sent.
|
||||
struct AHardwareBuffer* m_frame = nullptr;
|
||||
HostFrameOffer m_frameOffer = {};
|
||||
Uint32 m_frameSeq = 0;
|
||||
// The acceptor, and the flag that ends it. The listening descriptor is handed to the thread
|
||||
// as its own copy, so it is the only thing in here that thread reads without the lock - and
|
||||
// Close() joins the thread before it closes that descriptor.
|
||||
std::thread m_acceptor;
|
||||
std::atomic<Bool> m_accepting{false};
|
||||
// Guards every member above, from both threads. Mutable because the two const questions a
|
||||
// caller asks about the channel - is a container connected, how many frames are outstanding
|
||||
// - are answers that have to be read under it.
|
||||
mutable std::mutex m_mutex;
|
||||
};
|
||||
}
|
||||
@@ -1,189 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/HostFrameBridge.cpp
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#include "HostFrameBridge.h"
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED && defined(__ANDROID__)
|
||||
|
||||
#include <android/hardware_buffer.h>
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <poll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace MobileGL::MG_Backend {
|
||||
namespace {
|
||||
Bool ReadExactly(Int fd, void* out, SizeT n) {
|
||||
Uint8* at = static_cast<Uint8*>(out);
|
||||
while (n > 0) {
|
||||
const ssize_t got = ::read(fd, at, n);
|
||||
if (got <= 0) {
|
||||
if (got < 0 && errno == EINTR) continue;
|
||||
return false;
|
||||
}
|
||||
at += got;
|
||||
n -= static_cast<SizeT>(got);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool WriteExactly(Int fd, const void* in, SizeT n) {
|
||||
const Uint8* at = static_cast<const Uint8*>(in);
|
||||
while (n > 0) {
|
||||
const ssize_t put = ::write(fd, at, n);
|
||||
if (put <= 0) {
|
||||
if (put < 0 && errno == EINTR) continue;
|
||||
return false;
|
||||
}
|
||||
at += put;
|
||||
n -= static_cast<SizeT>(put);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
HostFrameBridge::~HostFrameBridge() { Close(); }
|
||||
|
||||
Bool HostFrameBridge::Open(const char* path, Int acceptTimeoutMs, String& why) {
|
||||
Close();
|
||||
const char* name = (path != nullptr && path[0] != 0) ? path : kHostFrameSocket;
|
||||
|
||||
m_listen = ::socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (m_listen < 0) {
|
||||
why = std::format("socket(AF_UNIX): {}", std::strerror(errno));
|
||||
return false;
|
||||
}
|
||||
sockaddr_un address{};
|
||||
address.sun_family = AF_UNIX;
|
||||
if (std::strlen(name) >= sizeof(address.sun_path)) {
|
||||
why = std::format("the socket name is longer than the kernel takes: {}", name);
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
// "@name" is the abstract namespace: sun_path[0] is NUL and the name follows it.
|
||||
// Nothing is created on disk, so nothing is left behind and no file permission stands
|
||||
// between two apps that may not write each other's directories.
|
||||
if (name[0] == '@') {
|
||||
address.sun_path[0] = 0;
|
||||
std::strncpy(address.sun_path + 1, name + 1, sizeof(address.sun_path) - 2);
|
||||
} else {
|
||||
std::strncpy(address.sun_path, name, sizeof(address.sun_path) - 1);
|
||||
// A leftover socket file from a server that died is not a reason to refuse the host.
|
||||
::unlink(name);
|
||||
}
|
||||
if (::bind(m_listen, reinterpret_cast<sockaddr*>(&address), sizeof(address)) != 0) {
|
||||
why = std::format("bind({}): {}", name, std::strerror(errno));
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
if (::listen(m_listen, 1) != 0) {
|
||||
why = std::format("listen({}): {}", name, std::strerror(errno));
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
pollfd waiting{};
|
||||
waiting.fd = m_listen;
|
||||
waiting.events = POLLIN;
|
||||
const Int ready = ::poll(&waiting, 1, acceptTimeoutMs);
|
||||
if (ready <= 0) {
|
||||
why = (ready == 0) ? std::format("no display host dialled {} within {} ms", name, acceptTimeoutMs)
|
||||
: std::format("poll({}): {}", name, std::strerror(errno));
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
m_fd = ::accept(m_listen, nullptr, nullptr);
|
||||
if (m_fd < 0) {
|
||||
why = std::format("accept({}): {}", name, std::strerror(errno));
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
MGLOG_I("host frame bridge: a display host is on %s", name);
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool HostFrameBridge::Acquire(struct AHardwareBuffer** buffer, HostFrameOffer& offer, String& why) {
|
||||
*buffer = nullptr;
|
||||
offer = HostFrameOffer{};
|
||||
if (m_fd < 0) {
|
||||
why = "the bridge is not open";
|
||||
return false;
|
||||
}
|
||||
AHardwareBuffer* received = nullptr;
|
||||
if (AHardwareBuffer_recvHandleFromUnixSocket(m_fd, &received) != 0 || received == nullptr) {
|
||||
why = "the host stopped offering frames, or the handle did not cross";
|
||||
return false;
|
||||
}
|
||||
if (!ReadExactly(m_fd, &offer, sizeof(offer)) || offer.Magic != kHostFrameMagic) {
|
||||
// The handle is already this side's by the time this fails, so it goes back before
|
||||
// the failure does: a reference held past the connection starves the host's pool.
|
||||
AHardwareBuffer_release(received);
|
||||
why = std::format("the frame's description did not follow its handle (magic 0x{:08x})", offer.Magic);
|
||||
return false;
|
||||
}
|
||||
*buffer = received;
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool HostFrameBridge::Complete(const HostFrameOffer& offer, Bool imported, Bool drawn, Bool fenceOk, String& why) {
|
||||
if (m_fd < 0) {
|
||||
why = "the bridge is not open";
|
||||
return false;
|
||||
}
|
||||
HostFrameAck ack{};
|
||||
ack.Magic = kHostFrameMagic;
|
||||
ack.Version = kHostFrameVersion;
|
||||
ack.Index = offer.Index;
|
||||
ack.Imported = imported ? 1u : 0u;
|
||||
ack.Drawn = drawn ? 1u : 0u;
|
||||
ack.FenceOk = fenceOk ? 1u : 0u;
|
||||
if (!WriteExactly(m_fd, &ack, sizeof(ack))) {
|
||||
why = std::format("the answer to frame {} did not go out: {}", offer.Index, std::strerror(errno));
|
||||
return false;
|
||||
}
|
||||
// The host answers with its own view of the pixels. It is what closes the round trip, so
|
||||
// it is read here and kept rather than left in the socket for the next frame to trip over.
|
||||
m_lastSeen = HostFrameSeen{};
|
||||
if (!ReadExactly(m_fd, &m_lastSeen, sizeof(m_lastSeen)) || m_lastSeen.Magic != kHostFrameMagic) {
|
||||
why = std::format("frame {} was answered but the host's readback did not arrive", offer.Index);
|
||||
m_lastSeen = HostFrameSeen{};
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void HostFrameBridge::Close() {
|
||||
if (m_fd >= 0) ::close(m_fd);
|
||||
if (m_listen >= 0) ::close(m_listen);
|
||||
m_fd = -1;
|
||||
m_listen = -1;
|
||||
}
|
||||
}
|
||||
|
||||
#else // !(MOBILEGL_BUILD_DISAGGREGATED && __ANDROID__)
|
||||
|
||||
namespace MobileGL::MG_Backend {
|
||||
HostFrameBridge::~HostFrameBridge() = default;
|
||||
Bool HostFrameBridge::Open(const char*, Int, String& why) {
|
||||
why = "host frames are a disaggregated Android path";
|
||||
return false;
|
||||
}
|
||||
Bool HostFrameBridge::Acquire(struct AHardwareBuffer**, HostFrameOffer&, String& why) {
|
||||
why = "host frames are a disaggregated Android path";
|
||||
return false;
|
||||
}
|
||||
Bool HostFrameBridge::Complete(const HostFrameOffer&, Bool, Bool, Bool, String& why) {
|
||||
why = "host frames are a disaggregated Android path";
|
||||
return false;
|
||||
}
|
||||
void HostFrameBridge::Close() {}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,103 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Backend/HostFrameBridge.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
|
||||
struct AHardwareBuffer;
|
||||
|
||||
namespace MobileGL::MG_Backend {
|
||||
// THE DISPLAY HOST'S FRAMES, AS THEY ARRIVE.
|
||||
//
|
||||
// The Android side that owns the screen allocates its frames itself and offers each one over
|
||||
// an AF_UNIX socket: the handle travels ahead of a fixed-size description on the same
|
||||
// connection, and the host then waits for this side to say the frame is drawn before it puts
|
||||
// it on the glass. Why the host allocates rather than this side asking for the display's own
|
||||
// buffers is measured, not chosen: AHardwareBuffer_createFromHandle accepts an
|
||||
// AHardwareBuffer this process allocated and refuses one the display queue handed over
|
||||
// (gralloc BAD_VALUE), so the only frames a render server can draw into are the ones the host
|
||||
// made for it.
|
||||
//
|
||||
// The three message shapes below ARE the host's (its ahb_bridge.h), field for field and
|
||||
// packing included. They are restated here rather than shared because the two ends are built
|
||||
// by different projects; a change on either side is a protocol change, and the magic is what
|
||||
// makes a mismatched pair fail loudly instead of being read as plausible numbers.
|
||||
inline constexpr Uint32 kHostFrameMagic = 0x4D474C41u; // the host spells it "ALGM" in memory
|
||||
inline constexpr Uint32 kHostFrameVersion = 1u;
|
||||
// AN ABSTRACT NAME, not a path: the two ends are separate apps, and neither may create a
|
||||
// socket file in /data/local/tmp (its directory grants others traverse only). An abstract
|
||||
// name lives in the kernel namespace instead of the filesystem, so there is no file
|
||||
// permission to get wrong - the same reason this project names its own endpoints @mgl-*.
|
||||
inline constexpr const char* kHostFrameSocket = "@mobilegl-host-frame";
|
||||
|
||||
struct HostFrameOffer {
|
||||
Uint32 Magic;
|
||||
Uint32 Version;
|
||||
Uint32 Index;
|
||||
Uint32 Width;
|
||||
Uint32 Height;
|
||||
Uint32 StrideBytes;
|
||||
Uint32 Format;
|
||||
Uint32 UsageLo;
|
||||
Uint32 UsageHi;
|
||||
char Note[64];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct HostFrameAck {
|
||||
Uint32 Magic;
|
||||
Uint32 Version;
|
||||
Uint32 Index;
|
||||
Uint32 Imported;
|
||||
Uint32 Drawn;
|
||||
Uint32 FenceOk;
|
||||
Uint8 Color[4];
|
||||
char Note[64];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct HostFrameSeen {
|
||||
Uint32 Magic;
|
||||
Uint32 Version;
|
||||
Uint32 Index;
|
||||
Uint32 Locked;
|
||||
Uint8 Observed[4];
|
||||
Uint8 ObservedCorner[4];
|
||||
char Note[64];
|
||||
} __attribute__((packed));
|
||||
|
||||
// One host connection at a time, which is what the host offers: it dials, hands over a frame,
|
||||
// waits for the answer, and hands over the next.
|
||||
class HostFrameBridge {
|
||||
public:
|
||||
HostFrameBridge() = default;
|
||||
HostFrameBridge(const HostFrameBridge&) = delete;
|
||||
HostFrameBridge& operator=(const HostFrameBridge&) = delete;
|
||||
~HostFrameBridge();
|
||||
|
||||
// Listens on `path` (the well-known name by default) and waits for the host. A host that
|
||||
// never dials is answered with false and a reason, never an abort.
|
||||
Bool Open(const char* path, Int acceptTimeoutMs, String& why);
|
||||
|
||||
// Takes the next frame. Ownership of the returned AHardwareBuffer is the caller's, who
|
||||
// must hand it back through ReleaseOwned() once the frame is off the glass.
|
||||
Bool Acquire(struct AHardwareBuffer** buffer, HostFrameOffer& offer, String& why);
|
||||
|
||||
// Tells the host what became of the frame it offered, and reads back what the host's own
|
||||
// view of the pixels holds. `drawn` is what the host waits for before it presents.
|
||||
Bool Complete(const HostFrameOffer& offer, Bool imported, Bool drawn, Bool fenceOk, String& why);
|
||||
|
||||
// The readback the host returned for the last completed frame, as the host reported it.
|
||||
const HostFrameSeen& LastSeen() const { return m_lastSeen; }
|
||||
|
||||
void Close();
|
||||
|
||||
private:
|
||||
Int m_fd = -1;
|
||||
Int m_listen = -1;
|
||||
HostFrameSeen m_lastSeen{};
|
||||
};
|
||||
}
|
||||
@@ -14,7 +14,6 @@
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
#include <MG_Pipe/MGPipe.h>
|
||||
#include <MG_Pipe/PipeApply.h>
|
||||
#include <MG_Pipe/PipeMutation.h> // MGPipeForgetAllPublications, at the end of ShutdownSplitRoles
|
||||
#include <MG_Remote/Client/ClientSession.h>
|
||||
#include <MG_Remote/FatalFunnel.h> // InstallPipeSessionFailHook, installed at step 0 below
|
||||
#include <MG_Remote/Server/ServerLoop.h>
|
||||
@@ -399,9 +398,6 @@ namespace MobileGL::MG_Backend {
|
||||
// and every later split bring-up in the process fails at CreateBackend's m_backend!=null
|
||||
// guard.
|
||||
MG_Remote::Server::ServerLoopInstance().Stop();
|
||||
// The server's twins died with the session; the frontend objects that are destroyed after
|
||||
// this (the GL context's) have nothing left on the other side to delete.
|
||||
MG_Pipe::MGPipeForgetAllPublications();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,663 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Gbm/GbmApi.cpp
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
//
|
||||
// The extern "C" surface: every entry point gbm.h declares, and nothing else.
|
||||
//
|
||||
// This file is a translation layer, and it is kept that way on purpose. Each entry
|
||||
// point does three things - check the pointers it was handed, take the device's one
|
||||
// mutex for the whole call, and hand the work to GbmDevice.cpp - so the concurrency
|
||||
// rule ("one mutex per device, taken once at the API boundary, never inside the
|
||||
// allocation code") is visible in one place instead of being spread over the
|
||||
// backends. A missing lock is a bug that only shows up in the compositor, so the
|
||||
// boilerplate is deliberately identical in every function.
|
||||
//
|
||||
// Two conventions are observable from outside and are stated here because they are
|
||||
// the ones a caller can get wrong:
|
||||
//
|
||||
// * gbm_bo_get_fd and gbm_bo_get_fd_for_plane return a DUP the caller owns. The
|
||||
// caller closes what it was given; the buffer's own descriptor is closed once,
|
||||
// when the buffer is destroyed, and never by a caller's close.
|
||||
// * Nothing here throws and nothing here aborts. A failure is reported the way
|
||||
// GBM reports failures: null or -1 with errno set, so that the strerror(errno)
|
||||
// a caller prints describes the failure that actually happened.
|
||||
|
||||
#include "GbmInternal.h"
|
||||
|
||||
#include <cerrno>
|
||||
|
||||
using namespace MobileGL;
|
||||
using namespace MobileGL::MG_Gbm;
|
||||
|
||||
namespace
|
||||
{
|
||||
// The one mutex that guards a record, reached through the device that owns it.
|
||||
// Null means the pointer was not one this library handed out, and every entry
|
||||
// point turns that into its own failure answer rather than dereferencing it.
|
||||
//
|
||||
// A buffer or surface with no owner cannot exist while the library is used
|
||||
// correctly - the device destroys everything it still holds before it goes away
|
||||
// - so null here is a defence against a stale pointer rather than a state the
|
||||
// code produces.
|
||||
std::mutex* MutexOf(struct gbm_device* device) noexcept
|
||||
{
|
||||
return device != nullptr ? &device->Impl.Mutex : nullptr;
|
||||
}
|
||||
|
||||
std::mutex* MutexOf(struct gbm_bo* bo) noexcept
|
||||
{
|
||||
return bo != nullptr ? MutexOf(bo->Impl.Owner) : nullptr;
|
||||
}
|
||||
|
||||
std::mutex* MutexOf(struct gbm_surface* surface) noexcept
|
||||
{
|
||||
return surface != nullptr ? MutexOf(surface->Impl.Owner) : nullptr;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Device
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
extern "C" struct gbm_device* gbm_create_device(int fd)
|
||||
{
|
||||
// No lock to take: the device being built is not reachable by any other thread
|
||||
// until this call returns it.
|
||||
return GbmDeviceCreate(fd);
|
||||
}
|
||||
|
||||
extern "C" void gbm_device_destroy(struct gbm_device* gbm)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// The lock is taken and deliberately never released: the mutex lives inside the
|
||||
// record this call deletes, and unlocking a destroyed mutex is worse than
|
||||
// leaving a dead one locked. Any other thread touching this device after its
|
||||
// owner declared it dead is already outside what GBM can be asked to survive.
|
||||
mutex->lock();
|
||||
GbmDeviceDestroy(*gbm);
|
||||
}
|
||||
|
||||
extern "C" int gbm_device_get_fd(struct gbm_device* gbm)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// The device's own dup of the fd it was created with, or -1 when it was created
|
||||
// without one and no render node could be opened. That is not an error state:
|
||||
// the self-allocated backend never talks to the node, so a device can be fully
|
||||
// usable and still have no descriptor to report.
|
||||
return gbm->Impl.DeviceFd;
|
||||
}
|
||||
|
||||
extern "C" const char* gbm_device_get_backend_name(struct gbm_device* gbm)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// The name says which memory this device hands out ("mobilegl-dma-heap" or
|
||||
// "mobilegl-memfd"), because the callers that read it - a compositor logging its
|
||||
// backend, a peer test recording what it got - are asking exactly that. The
|
||||
// string lives in the device and outlives every call that can read it.
|
||||
return gbm->Impl.BackendName.c_str();
|
||||
}
|
||||
|
||||
extern "C" int gbm_device_is_format_supported(struct gbm_device* gbm, uint32_t format, uint32_t flags)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// Every buffer this device produces is linear, mappable and shareable, so the
|
||||
// usage flags do not narrow the answer to any of the usual combinations -
|
||||
// including GBM_BO_USE_SCANOUT, which a linear dma-buf from the system heap
|
||||
// satisfies. The one request the backend cannot honour is protected memory.
|
||||
if ((flags & GBM_BO_USE_PROTECTED) != 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return GbmFormatIsSupported(format) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" int gbm_device_get_format_modifier_plane_count(struct gbm_device* gbm, uint32_t format, uint64_t modifier)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// Only linear memory exists here, so any other modifier names a buffer this
|
||||
// device will never produce and the answer is zero planes. INVALID is answered
|
||||
// as well, because it means "no modifier was declared", which is the same
|
||||
// layout question asked without an answer.
|
||||
if (modifier != DrmFormatModLinear && modifier != DrmFormatModInvalid)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
GbmPlaneLayout planes[GbmMaxPlanes] = {};
|
||||
Int planeCount = 0;
|
||||
SizeT totalBytes = 0;
|
||||
if (!GbmDescribeFormat(format, 1, 1, planes, planeCount, totalBytes))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return planeCount;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Buffer objects
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
extern "C" struct gbm_bo* gbm_bo_create(struct gbm_device* gbm, uint32_t width, uint32_t height, uint32_t format,
|
||||
uint32_t flags)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// No modifier list: the buffer is linear and gbm_bo_get_modifier says so.
|
||||
return GbmBufferCreate(*gbm, width, height, format, flags, nullptr, 0);
|
||||
}
|
||||
|
||||
extern "C" struct gbm_bo* gbm_bo_create_with_modifiers(struct gbm_device* gbm, uint32_t width, uint32_t height,
|
||||
uint32_t format, const uint64_t* modifiers,
|
||||
const unsigned int count)
|
||||
{
|
||||
// The modifier-less variant is the one with no flags parameter, so it is the
|
||||
// flags-0 case of the other, and saying that here keeps one implementation.
|
||||
return gbm_bo_create_with_modifiers2(gbm, width, height, format, modifiers, count, 0);
|
||||
}
|
||||
|
||||
extern "C" struct gbm_bo* gbm_bo_create_with_modifiers2(struct gbm_device* gbm, uint32_t width, uint32_t height,
|
||||
uint32_t format, const uint64_t* modifiers,
|
||||
const unsigned int count, uint32_t flags)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return GbmBufferCreate(*gbm, width, height, format, flags, modifiers, (Uint32)count);
|
||||
}
|
||||
|
||||
extern "C" struct gbm_bo* gbm_bo_import(struct gbm_device* gbm, uint32_t type, void* buffer, uint32_t flags)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return GbmBufferImport(*gbm, type, buffer, flags);
|
||||
}
|
||||
|
||||
extern "C" void* gbm_bo_map(struct gbm_bo* bo, uint32_t x, uint32_t y, uint32_t width, uint32_t height,
|
||||
uint32_t flags, uint32_t* stride, void** map_data)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
// The rectangle's size is not used to size the mapping: the whole buffer is
|
||||
// mapped once, at its own length, and the rectangle is applied as an offset into
|
||||
// it. That is what lets two overlapping maps share one address, and it is why a
|
||||
// buffer's mapping stays valid for a caller that only ever asks for a corner.
|
||||
(void)width;
|
||||
(void)height;
|
||||
(void)flags;
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
Uint32 mapStride = 0;
|
||||
void* address = GbmBufferMap(*bo, x, y, mapStride);
|
||||
if (address == nullptr)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
if (stride != nullptr)
|
||||
{
|
||||
*stride = mapStride;
|
||||
}
|
||||
if (map_data != nullptr)
|
||||
{
|
||||
// The same address the function returns. Callers pass back either one to
|
||||
// gbm_bo_unmap, and both have to name this mapping.
|
||||
*map_data = address;
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
||||
extern "C" void gbm_bo_unmap(struct gbm_bo* bo, void* map_data)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
GbmBufferUnmap(*bo, map_data);
|
||||
}
|
||||
|
||||
extern "C" uint32_t gbm_bo_get_width(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return bo->Impl.Width;
|
||||
}
|
||||
|
||||
extern "C" uint32_t gbm_bo_get_height(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return bo->Impl.Height;
|
||||
}
|
||||
|
||||
extern "C" uint32_t gbm_bo_get_stride(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return bo->Impl.Strides[0];
|
||||
}
|
||||
|
||||
extern "C" uint32_t gbm_bo_get_stride_for_plane(struct gbm_bo* bo, int plane)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// A plane this buffer does not have is answered with zero, which is the only
|
||||
// value a caller can tell apart from a real stride.
|
||||
if (plane < 0 || plane >= bo->Impl.PlaneCount)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
return bo->Impl.Strides[plane];
|
||||
}
|
||||
|
||||
extern "C" uint32_t gbm_bo_get_format(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return bo->Impl.Format;
|
||||
}
|
||||
|
||||
extern "C" uint32_t gbm_bo_get_bpp(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// Bits per pixel: a 32 bit format answers 32, which is what a caller computing a
|
||||
// row length in bits or a row length in bytes from the same number expects.
|
||||
return bo->Impl.BytesPerPixel * 8;
|
||||
}
|
||||
|
||||
extern "C" uint32_t gbm_bo_get_offset(struct gbm_bo* bo, int plane)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
if (plane < 0 || plane >= bo->Impl.PlaneCount)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
return bo->Impl.Offsets[plane];
|
||||
}
|
||||
|
||||
extern "C" struct gbm_device* gbm_bo_get_device(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
return bo->Impl.Owner;
|
||||
}
|
||||
|
||||
extern "C" union gbm_bo_handle gbm_bo_get_handle(struct gbm_bo* bo)
|
||||
{
|
||||
union gbm_bo_handle handle;
|
||||
handle.ptr = nullptr;
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
handle.s32 = -1;
|
||||
return handle;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// The kernel-level name of a dma-buf in this process is its file descriptor. A
|
||||
// GEM handle would be a name that exists only relative to a DRM node, and this
|
||||
// library deliberately does not require one, so the fd is the only answer here
|
||||
// that is true for every buffer it hands out. Callers that need a name for a
|
||||
// device should ask for the fd and pass that.
|
||||
handle.s32 = bo->Impl.Fds[0];
|
||||
return handle;
|
||||
}
|
||||
|
||||
extern "C" int gbm_bo_get_fd(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// A dup, close-on-exec, owned by the caller. Closing it cannot affect the buffer
|
||||
// or any other caller's copy.
|
||||
return GbmBufferDupFd(*bo, 0);
|
||||
}
|
||||
|
||||
extern "C" uint64_t gbm_bo_get_modifier(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return DrmFormatModInvalid;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return bo->Impl.Modifier;
|
||||
}
|
||||
|
||||
extern "C" int gbm_bo_get_plane_count(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return bo->Impl.PlaneCount;
|
||||
}
|
||||
|
||||
extern "C" union gbm_bo_handle gbm_bo_get_handle_for_plane(struct gbm_bo* bo, int plane)
|
||||
{
|
||||
union gbm_bo_handle handle;
|
||||
handle.ptr = nullptr;
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
handle.s32 = -1;
|
||||
return handle;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
if (plane < 0 || plane >= bo->Impl.PlaneCount)
|
||||
{
|
||||
errno = EINVAL;
|
||||
handle.s32 = -1;
|
||||
return handle;
|
||||
}
|
||||
// Same reasoning as gbm_bo_get_handle: the fd is the buffer's kernel name. Every
|
||||
// plane of a self-allocated buffer lives in the one dma-buf, so all of them
|
||||
// answer with that descriptor; the plane's position inside it is
|
||||
// gbm_bo_get_offset.
|
||||
const Int fd = bo->Impl.Fds[plane] >= 0 ? bo->Impl.Fds[plane] : bo->Impl.Fds[0];
|
||||
handle.s32 = fd;
|
||||
return handle;
|
||||
}
|
||||
|
||||
extern "C" int gbm_bo_get_fd_for_plane(struct gbm_bo* bo, int plane)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return GbmBufferDupFd(*bo, plane);
|
||||
}
|
||||
|
||||
extern "C" int gbm_bo_write(struct gbm_bo* bo, const void* buf, size_t count)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr || buf == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
if (count == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (count > bo->Impl.AllocationSize)
|
||||
{
|
||||
// Refused rather than truncated: a caller that writes 4 MiB into a 1 MiB
|
||||
// buffer and is told "0 bytes written, success" would read back memory it
|
||||
// never wrote and call the result correct.
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
// The write goes through the same counted mapping the rest of the API uses, so a
|
||||
// caller that already holds the buffer mapped does not get a second mapping (or
|
||||
// lose its own) behind its back.
|
||||
Uint32 stride = 0;
|
||||
void* address = GbmBufferMap(*bo, 0, 0, stride);
|
||||
if (address == nullptr)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
memcpy(address, buf, count);
|
||||
GbmBufferUnmap(*bo, address);
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" void gbm_bo_set_user_data(struct gbm_bo* bo, void* data,
|
||||
void (*destroy_user_data)(struct gbm_bo*, void*))
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// Assigning over existing data does not call the old callback: the record calls
|
||||
// it exactly once, when the buffer goes away, which is the one moment a caller
|
||||
// can still recognise the pointer it registered.
|
||||
bo->Impl.UserData = data;
|
||||
bo->Impl.UserDataDestroy = destroy_user_data;
|
||||
}
|
||||
|
||||
extern "C" void* gbm_bo_get_user_data(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return bo->Impl.UserData;
|
||||
}
|
||||
|
||||
extern "C" void gbm_bo_destroy(struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(bo);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// Drops this caller's reference. A buffer a surface still holds stays alive -
|
||||
// that is what the surface's own reference is for - so destroying a buffer that
|
||||
// is currently presented is not a use-after-free waiting to happen.
|
||||
GbmBufferRelease(*bo->Impl.Owner, *bo);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Surfaces
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
extern "C" struct gbm_surface* gbm_surface_create(struct gbm_device* gbm, uint32_t width, uint32_t height,
|
||||
uint32_t format, uint32_t flags)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return GbmSurfaceCreate(*gbm, width, height, format, flags, nullptr, 0);
|
||||
}
|
||||
|
||||
extern "C" struct gbm_surface* gbm_surface_create_with_modifiers(struct gbm_device* gbm, uint32_t width,
|
||||
uint32_t height, uint32_t format,
|
||||
const uint64_t* modifiers,
|
||||
const unsigned int count)
|
||||
{
|
||||
// As with the buffer pair: the modifier-less form is the flags-0 case.
|
||||
return gbm_surface_create_with_modifiers2(gbm, width, height, format, modifiers, count, 0);
|
||||
}
|
||||
|
||||
extern "C" struct gbm_surface* gbm_surface_create_with_modifiers2(struct gbm_device* gbm, uint32_t width,
|
||||
uint32_t height, uint32_t format,
|
||||
const uint64_t* modifiers,
|
||||
const unsigned int count, uint32_t flags)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(gbm);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
return GbmSurfaceCreate(*gbm, width, height, format, flags, modifiers, (Uint32)count);
|
||||
}
|
||||
|
||||
extern "C" struct gbm_bo* gbm_surface_lock_front_buffer(struct gbm_surface* surface)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(surface);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// Null with errno = EBUSY when the compositor still holds every buffer: that is a
|
||||
// state the caller has to handle, and pretending otherwise by handing out a
|
||||
// buffer that is still being scanned out would be a torn frame rather than an
|
||||
// error.
|
||||
return GbmSurfaceLockFront(*surface);
|
||||
}
|
||||
|
||||
extern "C" void gbm_surface_release_buffer(struct gbm_surface* surface, struct gbm_bo* bo)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(surface);
|
||||
if (mutex == nullptr || bo == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
GbmSurfaceReleaseBuffer(*surface, *bo);
|
||||
}
|
||||
|
||||
extern "C" int gbm_surface_has_free_buffers(struct gbm_surface* surface)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(surface);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
// Truthful by construction: the swapchain exists from the moment the surface
|
||||
// does, so this answers about buffers that were really allocated rather than
|
||||
// about how many could still be.
|
||||
return GbmSurfaceHasFreeBuffers(*surface) ? 1 : 0;
|
||||
}
|
||||
|
||||
extern "C" void gbm_surface_destroy(struct gbm_surface* surface)
|
||||
{
|
||||
std::mutex* mutex = MutexOf(surface);
|
||||
if (mutex == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(*mutex);
|
||||
GbmSurfaceDestroy(*surface);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Format names
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
extern "C" char* gbm_format_get_name(uint32_t gbm_format, struct gbm_format_name_desc* desc)
|
||||
{
|
||||
if (desc == nullptr)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return nullptr;
|
||||
}
|
||||
// The name of a fourcc is its four characters, most significant byte last, and
|
||||
// that is all there is to it: a caller compares these strings against "AR24" and
|
||||
// friends, and the big-endian bit is part of the value rather than something to
|
||||
// spell out here.
|
||||
desc->name[0] = (char)(gbm_format & 0xffu);
|
||||
desc->name[1] = (char)((gbm_format >> 8) & 0xffu);
|
||||
desc->name[2] = (char)((gbm_format >> 16) & 0xffu);
|
||||
desc->name[3] = (char)((gbm_format >> 24) & 0xffu);
|
||||
desc->name[4] = '\0';
|
||||
return desc->name;
|
||||
}
|
||||
|
||||
// End of Source File Header
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,835 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Gbm/GbmHostChannel.cpp
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
//
|
||||
// The host-frame backend: the socket the container receives the phone's frames on.
|
||||
//
|
||||
// The container half of MobileGL runs a Wayland compositor, and the frames that
|
||||
// compositor renders into have to be the frames the phone already owns - the phone
|
||||
// allocates them, its GPU draws into them, and its display scans them out. A buffer
|
||||
// allocated from the container's own dma-heap would be a copy that has to travel back
|
||||
// to the phone before anything can be shown, so when the display host is reachable this
|
||||
// backend hands the compositor the phone's own buffers instead, and the fd the
|
||||
// compositor passes on is the fd of a frame the display path already knows.
|
||||
//
|
||||
// What that costs is the one thing GBM normally promises: the geometry. A frame's
|
||||
// width, height, stride and format are the display's and not the caller's, so a
|
||||
// gbm_bo_create that takes an offered frame answers with the offer's geometry, and the
|
||||
// caller reads it back with gbm_bo_get_width and its neighbours. That is this backend's
|
||||
// documented behaviour rather than a surprise: the host decides what a frame is.
|
||||
//
|
||||
// Three rules keep this backend from ever being worse than not having it.
|
||||
//
|
||||
// * Nothing on the allocation path blocks. The socket is non-blocking and connect()
|
||||
// to a pathname socket either succeeds or fails immediately, so a call that cannot
|
||||
// be served from the host falls through to a local allocation inside the same call
|
||||
// instead of waiting for a phone that may never answer. The one wait in this file is
|
||||
// in device creation, after a display host has already accepted the connection, and
|
||||
// it exists because of a measured race: the compositor builds its swapchain within
|
||||
// microseconds of creating the device, while the offer for the first frame needs the
|
||||
// round trip of the connection plus whatever the phone does before it sends. Without
|
||||
// that wait the swapchain - the buffers that are shown for the life of the process -
|
||||
// is allocated locally and the host's frames arrive for nobody to take.
|
||||
// * A channel that dies is closed and marked down, and the next frame is allocated
|
||||
// locally again. This library is loaded by a compositor that has to keep painting,
|
||||
// so losing the display host may cost the frames their path to the screen but it
|
||||
// may not cost the session.
|
||||
// * A frame is released exactly once, when the record holding it is destroyed, and
|
||||
// only into the connection that offered it. Releasing on gbm_bo_destroy would be a
|
||||
// lie - the surface may still be scanning that frame out - and releasing an old
|
||||
// frame into a new connection would free a slot belonging to another session.
|
||||
//
|
||||
// The device mutex is the only lock in here. Both callers of this file - the allocation
|
||||
// path and the buffer record's destructor - already run under it, so there is no second
|
||||
// lock to order against and no state of this file's own that another thread can see.
|
||||
|
||||
#include "GbmInternal.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cerrno>
|
||||
#include <chrono>
|
||||
|
||||
namespace MobileGL::MG_Gbm
|
||||
{
|
||||
namespace
|
||||
{
|
||||
// One frame per message, and a message is the offer followed by the handle the
|
||||
// offer describes. 4 KiB is far more than an AHardwareBuffer handle needs (a
|
||||
// handle is a version, two counts and their two arrays) while still being small
|
||||
// enough that a message which does not fit is a peer speaking something else -
|
||||
// which is worth refusing rather than growing a buffer for.
|
||||
constexpr SizeT GbmHostMessageMax = 4096;
|
||||
|
||||
// The descriptors one handle may carry. An AHardwareBuffer handle carries one
|
||||
// (the dma-buf) in every layout this library has seen and the protocol reads only
|
||||
// the first, so this sizes the control buffer rather than claiming anything about
|
||||
// real handles.
|
||||
constexpr Int GbmHostMaxFds = 8;
|
||||
|
||||
// How many messages one gbm_bo_create may look at before it gives up and
|
||||
// allocates locally. An unusable message is skipped rather than fatal, so this
|
||||
// bounds the work a peer that sends nothing but unusable messages can cause
|
||||
// inside a single allocation.
|
||||
constexpr Int GbmHostTakeAttempts = 16;
|
||||
|
||||
// The floor between two connection attempts. A container with no display host is
|
||||
// the normal case, so a retry may not turn every allocation into a connect plus a
|
||||
// log line; one attempt per second is often enough that a phone which comes up is
|
||||
// picked up within a frame or two of the compositor's next allocation.
|
||||
constexpr std::chrono::milliseconds GbmHostRetryInterval{1000};
|
||||
|
||||
// How long device creation waits for the display host's first frame once the
|
||||
// connection is up. A frame the phone offers immediately needs one round trip on
|
||||
// a unix socket, so this is orders of magnitude more than that and it is only
|
||||
// ever spent by a device that has a host which then says nothing; a compile or a
|
||||
// test run without a display host never reaches it, because the connect fails
|
||||
// first.
|
||||
constexpr Int GbmHostFirstOfferWaitMs = 250;
|
||||
|
||||
// Frame releases the socket would not take. A release is twelve bytes, so a full
|
||||
// socket buffer is hundreds of frames' worth of them and this queue is only
|
||||
// reached once the phone has stopped reading; the cap is what stops a peer that
|
||||
// never reads from growing it without bound.
|
||||
constexpr SizeT GbmHostMaxPendingReleases = 256;
|
||||
|
||||
// sun_path is where a pathname socket's name lives, and a name that does not fit
|
||||
// is one the kernel cannot be told about at all.
|
||||
constexpr SizeT GbmHostPathMax = sizeof(((struct sockaddr_un*)nullptr)->sun_path);
|
||||
|
||||
// close() may overwrite errno, and every caller here is in the middle of
|
||||
// reporting a failure that errno describes. Saving it around the close keeps the
|
||||
// reported failure the one that happened.
|
||||
void GbmHostCloseQuietly(Int fd) noexcept
|
||||
{
|
||||
if (fd < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const Int savedErrno = errno;
|
||||
close(fd);
|
||||
errno = savedErrno;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// One connection to the display host, for the life of one device.
|
||||
class GbmHostChannel
|
||||
{
|
||||
public:
|
||||
explicit GbmHostChannel(const String& path) noexcept : Path(path) {}
|
||||
~GbmHostChannel() noexcept;
|
||||
|
||||
GbmHostChannel(const GbmHostChannel&) = delete;
|
||||
GbmHostChannel& operator=(const GbmHostChannel&) = delete;
|
||||
|
||||
// Connects when there is no connection and the retry interval has passed. A
|
||||
// failure is never the caller's problem: the channel stays closed and the
|
||||
// allocation that asked for a frame falls back to local memory.
|
||||
void EnsureOpen(::gbm_device& device) noexcept;
|
||||
|
||||
// Waits, once, for the connection's first frame to be readable. Called from
|
||||
// device creation and nowhere else: see the banner for why that one wait exists.
|
||||
void AwaitFirstOffer(::gbm_device& device) noexcept;
|
||||
|
||||
// The next frame the host offered, or false when none is waiting.
|
||||
Bool TakeFrame(::gbm_device& device, GbmHostFrame& frameOut) noexcept;
|
||||
|
||||
// Queues the release for one frame and tries to send what is queued.
|
||||
void ReleaseFrame(::gbm_device& device, Uint32 seq, Uint64 generation) noexcept;
|
||||
|
||||
private:
|
||||
// Turns one message into a frame. Everything it refuses is reported with the
|
||||
// reason, because a peer this library cannot understand is the one thing that
|
||||
// would otherwise be invisible from the outside.
|
||||
Bool ParseOffer(const Uint8* payload, SizeT length, const Int* fds, Int fdCount,
|
||||
GbmHostFrame& frameOut) noexcept;
|
||||
|
||||
// Sends what is queued. False means the connection can no longer be trusted to
|
||||
// carry a twelve byte message, with errno describing what happened.
|
||||
Bool FlushReleases() noexcept;
|
||||
|
||||
// Closes the socket and drops whatever was queued for it.
|
||||
void CloseSocket() noexcept;
|
||||
|
||||
// Closes the socket and tells the device what that means for its backend name.
|
||||
void MarkDown(::gbm_device& device, const char* what, Int error) noexcept;
|
||||
|
||||
String Path;
|
||||
Int SocketFd = -1;
|
||||
// Set by a connection this process has just made, and read once by the allocation that
|
||||
// follows it: the accept and the frame that answers the dial happen on the other side of
|
||||
// this socket, so an allocation that reads immediately after connecting reads before the
|
||||
// answer to its own connection has been written. See TakeFrame.
|
||||
Bool FreshConnection = false;
|
||||
// Bumped by every connection, so a frame taken from a connection which has since
|
||||
// died can be recognised as one that must not be released into its replacement.
|
||||
Uint64 Generation = 0;
|
||||
std::chrono::steady_clock::time_point NextRetry{};
|
||||
// The errno of the last failed attempt, so that a failure which repeats once a
|
||||
// second is not logged once a second.
|
||||
Int LastFailureErrno = 0;
|
||||
std::vector<GbmFrameRelease> PendingReleases;
|
||||
Bool ReleaseOverflowLogged = false;
|
||||
};
|
||||
|
||||
// ---- the offered-frame record ------------------------------------------
|
||||
|
||||
GbmHostFrame::~GbmHostFrame()
|
||||
{
|
||||
// The record owns the dup it was built on, which is why it is move-only: a copy
|
||||
// would close the same descriptor twice.
|
||||
if (Fd >= 0)
|
||||
{
|
||||
close(Fd);
|
||||
Fd = -1;
|
||||
}
|
||||
}
|
||||
|
||||
GbmHostFrame::GbmHostFrame(GbmHostFrame&& other) noexcept
|
||||
{
|
||||
*this = static_cast<GbmHostFrame&&>(other);
|
||||
}
|
||||
|
||||
GbmHostFrame& GbmHostFrame::operator=(GbmHostFrame&& other) noexcept
|
||||
{
|
||||
if (this == &other)
|
||||
{
|
||||
return *this;
|
||||
}
|
||||
if (Fd >= 0)
|
||||
{
|
||||
close(Fd);
|
||||
}
|
||||
Seq = other.Seq;
|
||||
Index = other.Index;
|
||||
Width = other.Width;
|
||||
Height = other.Height;
|
||||
StrideBytes = other.StrideBytes;
|
||||
Format = other.Format;
|
||||
BytesPerPixel = other.BytesPerPixel;
|
||||
Usage = other.Usage;
|
||||
Generation = other.Generation;
|
||||
Fd = other.Fd;
|
||||
Size = other.Size;
|
||||
// The source must not close what this record now owns.
|
||||
other.Fd = -1;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ---- the connection ----------------------------------------------------
|
||||
|
||||
GbmHostChannel::~GbmHostChannel() noexcept
|
||||
{
|
||||
// One last try for whatever is queued - the phone may still be reading - and
|
||||
// then the socket goes away with the process.
|
||||
if (SocketFd >= 0 && !PendingReleases.empty())
|
||||
{
|
||||
FlushReleases();
|
||||
}
|
||||
if (!PendingReleases.empty())
|
||||
{
|
||||
MGLOG_W("gbm: %zu frame release(s) could not be sent to the display host at %s; the phone reclaims "
|
||||
"those slots when the session ends",
|
||||
PendingReleases.size(), Path.c_str());
|
||||
}
|
||||
CloseSocket();
|
||||
}
|
||||
|
||||
void GbmHostChannel::EnsureOpen(::gbm_device& device) noexcept
|
||||
{
|
||||
if (SocketFd >= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
|
||||
if (now < NextRetry)
|
||||
{
|
||||
return;
|
||||
}
|
||||
NextRetry = now + GbmHostRetryInterval;
|
||||
|
||||
// SOCK_SEQPACKET because a frame and its descriptors are one message and the
|
||||
// reader may not reassemble either half; SOCK_NONBLOCK because the caller is a
|
||||
// compositor's frame loop and may not be parked on a phone; SOCK_CLOEXEC because
|
||||
// every process this compositor starts would otherwise inherit a socket it can
|
||||
// read frames from.
|
||||
const Int fd = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
|
||||
if (fd < 0)
|
||||
{
|
||||
MGLOG_E_ONCE("gbm: cannot create the socket to the display host (%d: %s); every frame is allocated "
|
||||
"locally",
|
||||
errno, strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
if (Path.empty() || Path.size() >= GbmHostPathMax)
|
||||
{
|
||||
MGLOG_E_ONCE("gbm: the display host socket path \"%s\" does not fit in sun_path (%zu bytes); every "
|
||||
"frame is allocated locally",
|
||||
Path.c_str(), GbmHostPathMax);
|
||||
GbmHostCloseQuietly(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
struct sockaddr_un address = {};
|
||||
address.sun_family = AF_UNIX;
|
||||
// The terminator travels with the name: sun_path is a C string for a pathname
|
||||
// socket, and a name without one is a name the kernel reads past the end of.
|
||||
memcpy(address.sun_path, Path.c_str(), Path.size() + 1);
|
||||
|
||||
if (connect(fd, reinterpret_cast<struct sockaddr*>(&address), sizeof(address)) != 0)
|
||||
{
|
||||
const Int connectErrno = errno;
|
||||
GbmHostCloseQuietly(fd);
|
||||
// A failure that repeats once a second is not news: a container with no
|
||||
// display host fails here on every retry, and a line per second saying so
|
||||
// would bury the rest of the log. A failure that changed is news, because it
|
||||
// says the path or the peer changed.
|
||||
if (connectErrno != LastFailureErrno)
|
||||
{
|
||||
LastFailureErrno = connectErrno;
|
||||
if (connectErrno == EPROTOTYPE)
|
||||
{
|
||||
MGLOG_E("gbm: %s is a socket of a different type (%d: %s). The frame protocol is "
|
||||
"SOCK_SEQPACKET - one message per frame, carrying that frame's descriptors - "
|
||||
"because a reader cannot tell from a byte stream which frame a descriptor "
|
||||
"belongs to; frames are allocated locally instead",
|
||||
Path.c_str(), connectErrno, strerror(connectErrno));
|
||||
}
|
||||
else
|
||||
{
|
||||
MGLOG_I("gbm: no display host at %s (%d: %s); every frame is allocated locally until one "
|
||||
"answers",
|
||||
Path.c_str(), connectErrno, strerror(connectErrno));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
SocketFd = fd;
|
||||
FreshConnection = true;
|
||||
// A new connection is a new session with its own frames, which is what makes the
|
||||
// generation a correct answer to "may this release be sent here".
|
||||
Generation++;
|
||||
LastFailureErrno = 0;
|
||||
device.Impl.HostAvailable = true;
|
||||
device.Impl.BackendName = "mobilegl-host-frame";
|
||||
MGLOG_I("gbm: connected to the display host at %s (one SOCK_SEQPACKET message per frame, up to %zu "
|
||||
"bytes); frames offered over it become gbm_bos whose geometry is the offer's",
|
||||
Path.c_str(), GbmHostMessageMax);
|
||||
}
|
||||
|
||||
void GbmHostChannel::AwaitFirstOffer(::gbm_device& device) noexcept
|
||||
{
|
||||
if (SocketFd < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
const std::chrono::steady_clock::time_point deadline =
|
||||
std::chrono::steady_clock::now() + std::chrono::milliseconds(GbmHostFirstOfferWaitMs);
|
||||
for (;;)
|
||||
{
|
||||
const std::chrono::milliseconds left =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(deadline - std::chrono::steady_clock::now());
|
||||
if (left.count() <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
// poll() and not recvmsg(): the frame has to stay in the socket for the
|
||||
// allocation that is about to ask for it, and a peek at a message carrying
|
||||
// SCM_RIGHTS is a question with no safe answer.
|
||||
struct pollfd waiting = {};
|
||||
waiting.fd = SocketFd;
|
||||
waiting.events = POLLIN;
|
||||
const Int ready = poll(&waiting, 1, (Int)left.count());
|
||||
if (ready > 0)
|
||||
{
|
||||
MGLOG_I("gbm: the display host at %s has a frame waiting; the buffers the compositor is about "
|
||||
"to allocate come from it",
|
||||
Path.c_str());
|
||||
return;
|
||||
}
|
||||
if (ready == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if (errno != EINTR)
|
||||
{
|
||||
MarkDown(device, "poll", errno);
|
||||
return;
|
||||
}
|
||||
}
|
||||
MGLOG_W("gbm: the display host at %s accepted the connection but offered no frame within %d ms; the "
|
||||
"buffers allocated before its first frame are local ones",
|
||||
Path.c_str(), GbmHostFirstOfferWaitMs);
|
||||
}
|
||||
|
||||
Bool GbmHostChannel::TakeFrame(::gbm_device& device, GbmHostFrame& frameOut) noexcept
|
||||
{
|
||||
EnsureOpen(device);
|
||||
if (SocketFd < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// THE FIRST ALLOCATION AFTER A DIAL WAITS FOR THE ANSWER TO IT. The accept and the offer that
|
||||
// answers the connection this call has just made are written by the phone, a round trip
|
||||
// behind the connect() that returns here — and what is allocated before that offer arrives
|
||||
// is a local buffer, which is what a compositor builds its whole swapchain out of and then
|
||||
// keeps for the life of the process. So a connection made on this path is given the same
|
||||
// first-offer window device creation gives one, once, and only while it is new.
|
||||
if (FreshConnection)
|
||||
{
|
||||
FreshConnection = false;
|
||||
AwaitFirstOffer(device);
|
||||
}
|
||||
// Releases the socket would not take last time are retried here, because this is
|
||||
// the one call in the library that happens once per frame and therefore the
|
||||
// natural place for a queue waiting for room to get its next chance.
|
||||
if (!PendingReleases.empty() && !FlushReleases())
|
||||
{
|
||||
MarkDown(device, "sendmsg", errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
Uint8 payload[GbmHostMessageMax];
|
||||
for (Int attempt = 0; attempt < GbmHostTakeAttempts; ++attempt)
|
||||
{
|
||||
Int receivedFds[GbmHostMaxFds];
|
||||
for (Int i = 0; i < GbmHostMaxFds; ++i)
|
||||
{
|
||||
receivedFds[i] = -1;
|
||||
}
|
||||
|
||||
struct iovec payloadVector = {};
|
||||
payloadVector.iov_base = payload;
|
||||
payloadVector.iov_len = sizeof(payload);
|
||||
|
||||
Uint8 control[CMSG_SPACE(sizeof(Int) * GbmHostMaxFds)] = {};
|
||||
|
||||
struct msghdr message = {};
|
||||
message.msg_iov = &payloadVector;
|
||||
message.msg_iovlen = 1;
|
||||
message.msg_control = control;
|
||||
message.msg_controllen = sizeof(control);
|
||||
|
||||
// MSG_DONTWAIT for the promise at the top of this file, and MSG_CMSG_CLOEXEC
|
||||
// so a descriptor the phone sent does not survive into a child of this
|
||||
// compositor, which would then hold a frame nothing will ever release.
|
||||
const ssize_t received = recvmsg(SocketFd, &message, MSG_DONTWAIT | MSG_CMSG_CLOEXEC);
|
||||
if (received < 0)
|
||||
{
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||
{
|
||||
// Nothing offered yet, which is what an idle display looks like. The
|
||||
// caller allocates locally and asks again on its next frame.
|
||||
return false;
|
||||
}
|
||||
if (errno == EINTR)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
MarkDown(device, "recvmsg", errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
// The descriptors come out of the control data before anything is decided
|
||||
// about the message, because they belong to this process from the moment it
|
||||
// was received: a path that returns without closing them leaks a descriptor
|
||||
// per unusable message.
|
||||
Int fdCount = 0;
|
||||
for (struct cmsghdr* header = CMSG_FIRSTHDR(&message); header != nullptr;
|
||||
header = CMSG_NXTHDR(&message, header))
|
||||
{
|
||||
if (header->cmsg_level != SOL_SOCKET || header->cmsg_type != SCM_RIGHTS)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const SizeT bytes = (SizeT)header->cmsg_len - CMSG_LEN(0);
|
||||
const Int count = (Int)(bytes / sizeof(Int));
|
||||
const Int* descriptors = reinterpret_cast<const Int*>(CMSG_DATA(header));
|
||||
for (Int i = 0; i < count; ++i)
|
||||
{
|
||||
if (fdCount < GbmHostMaxFds)
|
||||
{
|
||||
receivedFds[fdCount++] = descriptors[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
// More descriptors than a frame can carry: they are this
|
||||
// process's now, so they are closed here rather than leaked.
|
||||
GbmHostCloseQuietly(descriptors[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((message.msg_flags & MSG_CTRUNC) != 0)
|
||||
{
|
||||
MGLOG_W_ONCE("gbm: an offered frame's control data did not fit in %zu bytes; the frame is "
|
||||
"skipped because its descriptor list is incomplete",
|
||||
sizeof(control));
|
||||
for (Int i = 0; i < fdCount; ++i)
|
||||
{
|
||||
GbmHostCloseQuietly(receivedFds[i]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (received == 0)
|
||||
{
|
||||
// Zero bytes on a connected socket is the end of it, whether the phone
|
||||
// closed cleanly or the kernel gave up on it. Either way the frames have
|
||||
// to come from somewhere else from here on.
|
||||
for (Int i = 0; i < fdCount; ++i)
|
||||
{
|
||||
GbmHostCloseQuietly(receivedFds[i]);
|
||||
}
|
||||
MarkDown(device, "the display host closed the connection", 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((message.msg_flags & MSG_TRUNC) != 0)
|
||||
{
|
||||
// Longer than a frame message can be, so it is not one - and on a
|
||||
// message-oriented socket the rest is already gone while the next message
|
||||
// is still a whole message, which is why this skips one message instead
|
||||
// of ending the channel.
|
||||
MGLOG_W_ONCE("gbm: the display host sent a message longer than %zu bytes; it is skipped",
|
||||
GbmHostMessageMax);
|
||||
for (Int i = 0; i < fdCount; ++i)
|
||||
{
|
||||
GbmHostCloseQuietly(receivedFds[i]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const Bool parsed = ParseOffer(payload, (SizeT)received, receivedFds, fdCount, frameOut);
|
||||
// Whatever the frame did not keep is closed here: the copy of the dma-buf
|
||||
// descriptor the phone sent (the frame owns its own dup) and the rest of the
|
||||
// handle, which is a layout this library does not interpret.
|
||||
for (Int i = 0; i < fdCount; ++i)
|
||||
{
|
||||
GbmHostCloseQuietly(receivedFds[i]);
|
||||
}
|
||||
if (parsed)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Bool GbmHostChannel::ParseOffer(const Uint8* payload, SizeT length, const Int* fds, Int fdCount,
|
||||
GbmHostFrame& frameOut) noexcept
|
||||
{
|
||||
constexpr SizeT HeaderBytes = sizeof(GbmFrameOffer) + sizeof(AHBNativeHandleHeader);
|
||||
if (length < HeaderBytes)
|
||||
{
|
||||
MGLOG_W_ONCE("gbm: the display host sent a %zu byte message where a frame message is at least %zu "
|
||||
"bytes (the offer followed by the handle header); it is skipped",
|
||||
length, HeaderBytes);
|
||||
return false;
|
||||
}
|
||||
|
||||
GbmFrameOffer offer = {};
|
||||
memcpy(&offer, payload, sizeof(offer));
|
||||
if (offer.Magic != GbmFrameOfferMagic)
|
||||
{
|
||||
MGLOG_W_ONCE("gbm: a message from the display host begins with 0x%08x rather than 'MGGF'; it is "
|
||||
"skipped",
|
||||
offer.Magic);
|
||||
return false;
|
||||
}
|
||||
if (offer.Version != GbmHostProtocolVersion)
|
||||
{
|
||||
// Refused rather than read as if the versions agreed: the version is what
|
||||
// says how the rest of the message is laid out, and a frame read with the
|
||||
// wrong layout is memory the compositor would render into.
|
||||
MGLOG_E_ONCE("gbm: the display host offers frames in protocol version %u where this library speaks "
|
||||
"version %u; its frames are refused until the two agree",
|
||||
offer.Version, (Uint32)GbmHostProtocolVersion);
|
||||
return false;
|
||||
}
|
||||
|
||||
AHBNativeHandleHeader handle = {};
|
||||
memcpy(&handle, payload + sizeof(offer), sizeof(handle));
|
||||
if (handle.NumFds < 1 || handle.NumInts < 0)
|
||||
{
|
||||
MGLOG_W_ONCE("gbm: an offered frame's handle carries %d descriptor(s) and %d integer(s), where the "
|
||||
"dma-buf is the first descriptor and there has to be one; the frame is skipped",
|
||||
handle.NumFds, handle.NumInts);
|
||||
return false;
|
||||
}
|
||||
|
||||
// The handle describes itself with its two counts, so the message has to be
|
||||
// exactly as long as those counts make it. Any other length means the two ends
|
||||
// disagree about the layout, and a frame built from a message whose layout was
|
||||
// guessed is a buffer of unknown memory.
|
||||
const SizeT expected = HeaderBytes + ((SizeT)handle.NumFds + (SizeT)handle.NumInts) * sizeof(Int32);
|
||||
if (length != expected)
|
||||
{
|
||||
MGLOG_W_ONCE("gbm: an offered frame's message is %zu bytes where its handle (%d descriptors, %d "
|
||||
"integers) makes it %zu; the frame is skipped",
|
||||
length, handle.NumFds, handle.NumInts, expected);
|
||||
return false;
|
||||
}
|
||||
if (fdCount < handle.NumFds)
|
||||
{
|
||||
MGLOG_W_ONCE("gbm: an offered frame's handle names %d descriptor(s) and %d arrived with the "
|
||||
"message; the frame is skipped",
|
||||
handle.NumFds, fdCount);
|
||||
return false;
|
||||
}
|
||||
if (offer.Width == 0 || offer.Height == 0 || offer.StrideBytes == 0)
|
||||
{
|
||||
MGLOG_W_ONCE("gbm: an offered frame is %ux%u with a stride of %u bytes; a buffer with no size is "
|
||||
"not one this library can hand out",
|
||||
offer.Width, offer.Height, offer.StrideBytes);
|
||||
return false;
|
||||
}
|
||||
|
||||
// The frame is built on a dup of the first descriptor rather than on the
|
||||
// descriptor itself: the copy that arrived belongs to the message, and the frame
|
||||
// outlives it. Close-on-exec, like every other descriptor this library hands out.
|
||||
const Int frameFd = fcntl(fds[0], F_DUPFD_CLOEXEC, 0);
|
||||
if (frameFd < 0)
|
||||
{
|
||||
MGLOG_E_ONCE("gbm: cannot dup the descriptor of an offered frame (%d: %s)", errno, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
// How long the frame really is, asked of the descriptor instead of computed from
|
||||
// the geometry: a gralloc dma-buf is usually larger than stride x height, and a
|
||||
// mapping has to cover what exists rather than what the arithmetic expects.
|
||||
SizeT size = 0;
|
||||
const off_t end = lseek(frameFd, 0, SEEK_END);
|
||||
if (end > 0)
|
||||
{
|
||||
size = (SizeT)end;
|
||||
}
|
||||
const SizeT described = (SizeT)offer.StrideBytes * (SizeT)offer.Height;
|
||||
if (size == 0)
|
||||
{
|
||||
// A descriptor that does not answer for its own length - an exporter that
|
||||
// does not implement llseek - leaves the offer's arithmetic as the only
|
||||
// length there is.
|
||||
size = described;
|
||||
}
|
||||
if (size < described)
|
||||
{
|
||||
MGLOG_W_ONCE("gbm: an offered frame's descriptor holds %zu bytes where %u rows of %u bytes need %zu; "
|
||||
"the frame is skipped rather than mapped over memory that is not there",
|
||||
size, offer.Height, offer.StrideBytes, described);
|
||||
GbmHostCloseQuietly(frameFd);
|
||||
return false;
|
||||
}
|
||||
|
||||
frameOut.Seq = offer.Seq;
|
||||
frameOut.Index = offer.Index;
|
||||
frameOut.Width = offer.Width;
|
||||
frameOut.Height = offer.Height;
|
||||
frameOut.StrideBytes = offer.StrideBytes;
|
||||
frameOut.Format = offer.Format;
|
||||
frameOut.Usage = ((Uint64)offer.UsageHi << 32) | (Uint64)offer.UsageLo;
|
||||
frameOut.Generation = Generation;
|
||||
frameOut.Fd = frameFd;
|
||||
frameOut.Size = size;
|
||||
frameOut.BytesPerPixel = GbmFormatBytesPerPixel(offer.Format);
|
||||
if (frameOut.BytesPerPixel == 0)
|
||||
{
|
||||
// A format this library has no table entry for is still a frame the phone
|
||||
// drew. The offer's stride is then the only description of a pixel that
|
||||
// exists: a row of Width pixels is StrideBytes long.
|
||||
frameOut.BytesPerPixel = offer.StrideBytes / offer.Width;
|
||||
}
|
||||
|
||||
MGLOG_I("gbm: frame seq=%u index=%u %ux%u stride=%u format=0x%08x (%u bytes per pixel, %zu bytes "
|
||||
"measured) taken from the display host",
|
||||
offer.Seq, offer.Index, offer.Width, offer.Height, offer.StrideBytes, offer.Format,
|
||||
frameOut.BytesPerPixel, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
void GbmHostChannel::ReleaseFrame(::gbm_device& device, Uint32 seq, Uint64 generation) noexcept
|
||||
{
|
||||
if (SocketFd < 0)
|
||||
{
|
||||
// A release only means anything on the connection that offered the frame,
|
||||
// and there is none.
|
||||
return;
|
||||
}
|
||||
if (generation != Generation)
|
||||
{
|
||||
// The frame was offered by a connection that has since died and been
|
||||
// replaced. Sending this into the replacement would name a frame of another
|
||||
// session, and the phone would recycle a slot this buffer was not made of.
|
||||
MGLOG_W_ONCE("gbm: a frame offered by a display host connection that has since died is not "
|
||||
"released into its replacement");
|
||||
return;
|
||||
}
|
||||
if (PendingReleases.size() >= GbmHostMaxPendingReleases)
|
||||
{
|
||||
if (!ReleaseOverflowLogged)
|
||||
{
|
||||
ReleaseOverflowLogged = true;
|
||||
MGLOG_W("gbm: %zu frame releases to the display host at %s are already waiting for room in the "
|
||||
"socket; this one is dropped rather than queued without bound, and the phone reclaims "
|
||||
"the slot when the session ends",
|
||||
PendingReleases.size(), Path.c_str());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
GbmFrameRelease release = {};
|
||||
release.Magic = GbmFrameReleaseMagic;
|
||||
release.Version = GbmHostProtocolVersion;
|
||||
release.Seq = seq;
|
||||
PendingReleases.push_back(release);
|
||||
|
||||
if (!FlushReleases())
|
||||
{
|
||||
MarkDown(device, "sendmsg", errno);
|
||||
}
|
||||
}
|
||||
|
||||
Bool GbmHostChannel::FlushReleases() noexcept
|
||||
{
|
||||
while (!PendingReleases.empty())
|
||||
{
|
||||
struct iovec releaseVector = {};
|
||||
releaseVector.iov_base = &PendingReleases.front();
|
||||
releaseVector.iov_len = sizeof(GbmFrameRelease);
|
||||
|
||||
struct msghdr message = {};
|
||||
message.msg_iov = &releaseVector;
|
||||
message.msg_iovlen = 1;
|
||||
|
||||
// MSG_DONTWAIT for the same reason every other call here is non-blocking, and
|
||||
// MSG_NOSIGNAL because a compositor killed by SIGPIPE when the phone goes
|
||||
// away is a desktop that disappears with it.
|
||||
const ssize_t sent = sendmsg(SocketFd, &message, MSG_DONTWAIT | MSG_NOSIGNAL);
|
||||
if (sent == (ssize_t)sizeof(GbmFrameRelease))
|
||||
{
|
||||
PendingReleases.erase(PendingReleases.begin());
|
||||
continue;
|
||||
}
|
||||
if (sent < 0 && errno == EINTR)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (sent < 0 && (errno == EAGAIN || errno == EWOULDBLOCK))
|
||||
{
|
||||
// A full socket is a phone that has stopped reading rather than a dead
|
||||
// one: the release stays queued and goes out with a later frame.
|
||||
return true;
|
||||
}
|
||||
// A short send, a reset and a broken pipe all say the same thing: this
|
||||
// connection can no longer be trusted to have carried a twelve byte message,
|
||||
// and acting on a maybe is worse than handing the slot back when the session
|
||||
// ends. errno describes which of them it was.
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void GbmHostChannel::CloseSocket() noexcept
|
||||
{
|
||||
if (SocketFd >= 0)
|
||||
{
|
||||
GbmHostCloseQuietly(SocketFd);
|
||||
SocketFd = -1;
|
||||
}
|
||||
PendingReleases.clear();
|
||||
}
|
||||
|
||||
void GbmHostChannel::MarkDown(::gbm_device& device, const char* what, Int error) noexcept
|
||||
{
|
||||
if (!PendingReleases.empty())
|
||||
{
|
||||
MGLOG_W("gbm: %zu frame release(s) were still queued for the display host and cannot be sent over a "
|
||||
"connection that is gone; the phone reclaims those slots when the session ends",
|
||||
PendingReleases.size());
|
||||
}
|
||||
CloseSocket();
|
||||
if (error != 0)
|
||||
{
|
||||
MGLOG_W("gbm: the display host connection at %s is down: %s failed (%d: %s); frames are allocated "
|
||||
"locally from here on, and a new connection is attempted on a later allocation",
|
||||
Path.c_str(), what, error, strerror(error));
|
||||
}
|
||||
else
|
||||
{
|
||||
MGLOG_W("gbm: the display host connection at %s is down: %s; frames are allocated locally from here "
|
||||
"on, and a new connection is attempted on a later allocation",
|
||||
Path.c_str(), what);
|
||||
}
|
||||
device.Impl.HostAvailable = false;
|
||||
device.Impl.BackendName = device.Impl.SelfAllocatedBackendName;
|
||||
}
|
||||
|
||||
// ---- the device-facing entry points ------------------------------------
|
||||
|
||||
void GbmHostChannelCreate(::gbm_device& device) noexcept
|
||||
{
|
||||
const char* configured = getenv("MOBILEGL_GBM_SOCKET");
|
||||
const String path =
|
||||
(configured != nullptr && configured[0] != '\0') ? String(configured) : String("/run/mobilegl-gbm.sock");
|
||||
device.Impl.SocketPath = path;
|
||||
try
|
||||
{
|
||||
GbmHostChannel* channel = new GbmHostChannel(path);
|
||||
device.Impl.Host = channel;
|
||||
// The one attempt made at creation. It is allowed to fail: a machine that is
|
||||
// not the container half of a split run has no display host, and that is a
|
||||
// device which allocates locally rather than a device that could not exist.
|
||||
channel->EnsureOpen(device);
|
||||
// A connection that came up is waited on once, and only here, so that the
|
||||
// compositor's swapchain is built out of the host's frames rather than out of
|
||||
// local ones it will keep for the life of the process.
|
||||
channel->AwaitFirstOffer(device);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
device.Impl.Host = nullptr;
|
||||
device.Impl.HostAvailable = false;
|
||||
MGLOG_W("gbm: the display host channel could not be created; every frame is allocated locally");
|
||||
}
|
||||
}
|
||||
|
||||
void GbmHostChannelDestroy(::gbm_device& device) noexcept
|
||||
{
|
||||
GbmHostChannel* channel = device.Impl.Host;
|
||||
if (channel == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
device.Impl.Host = nullptr;
|
||||
device.Impl.HostAvailable = false;
|
||||
delete channel;
|
||||
}
|
||||
|
||||
Bool GbmHostChannelTakeFrame(::gbm_device& device, GbmHostFrame& frameOut) noexcept
|
||||
{
|
||||
GbmHostChannel* channel = device.Impl.Host;
|
||||
if (channel == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return channel->TakeFrame(device, frameOut);
|
||||
}
|
||||
|
||||
void GbmHostChannelReleaseFrame(::gbm_device& device, Uint32 seq, Uint64 generation) noexcept
|
||||
{
|
||||
GbmHostChannel* channel = device.Impl.Host;
|
||||
if (channel == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
channel->ReleaseFrame(device, seq, generation);
|
||||
}
|
||||
} // namespace MobileGL::MG_Gbm
|
||||
|
||||
// End of Source File Header
|
||||
@@ -1,476 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Gbm/GbmInternal.h
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
//
|
||||
// This header carries the internal model shared by the GBM front-end files: the
|
||||
// device, buffer-object and surface records, the two allocation backends, and the
|
||||
// wire protocol used to talk to a phone that owns the real display hardware.
|
||||
//
|
||||
// The reason a GBM implementation has to exist in this tree at all is that the
|
||||
// container half of MobileGL runs a Wayland compositor (kwin). That compositor
|
||||
// needs libgbm to allocate the buffers it renders into, and the fd of such a
|
||||
// buffer is handed to the Anland display producer, which ships the frame to the
|
||||
// phone. If Mesa's libgbm is loaded, the compositor renders into Mesa buffers and
|
||||
// the phone ends up receiving a copy through a path that was never designed to
|
||||
// carry them. When this library is loaded instead, the buffers are either frames
|
||||
// the phone itself offered to us, or buffers allocated from the kernel's dma-heap
|
||||
// so that they are dma-bufs the display host can consume directly.
|
||||
//
|
||||
// The ownership rules below are the whole contract, because every one of them is
|
||||
// observable from outside this library:
|
||||
//
|
||||
// * A buffer record owns its descriptors. gbm_bo_get_fd and
|
||||
// gbm_bo_get_fd_for_plane hand out a dup, so a caller that closes what it was
|
||||
// given cannot invalidate the buffer, and the matching close happens exactly
|
||||
// once, in ~GbmBufferObject.
|
||||
// * A mapping is one mmap of the buffer's fd, counted rather than duplicated, so
|
||||
// two overlapping gbm_bo_map calls share one address and the last matching
|
||||
// gbm_bo_unmap releases it.
|
||||
// * A surface owns one reference per swapchain buffer, and every
|
||||
// gbm_surface_lock_front_buffer hands the caller a reference of its own. That
|
||||
// is what makes gbm_bo_destroy on a locked buffer harmless: it drops the
|
||||
// caller's reference and leaves the surface's bookkeeping intact.
|
||||
// * One mutex per device. GBM calls arrive from the compositor's render thread
|
||||
// and from its main thread, and the state they touch (the buffer table, the
|
||||
// swapchains, the backends) is small enough that one lock is cheaper than
|
||||
// several - and, more importantly, one lock cannot be taken in the wrong order.
|
||||
//
|
||||
// The helpers declared at the bottom of this file are the entire internal interface
|
||||
// between GbmDevice.cpp (the records and the self-allocated backend) and GbmApi.cpp
|
||||
// (the extern "C" surface). Every one of them assumes the device mutex is already
|
||||
// held: the lock is taken once, in the API layer, so that a compositor call can
|
||||
// never interleave with another half way through a swapchain update.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Includes.h>
|
||||
|
||||
#include <gbm.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace MobileGL::MG_Gbm
|
||||
{
|
||||
// DRM_FORMAT_MOD_LINEAR and DRM_FORMAT_MOD_INVALID. drm_fourcc.h is not part of
|
||||
// libgbm's interface, and these two values are frozen kernel UAPI, so they are
|
||||
// spelled out here rather than made a build dependency on libdrm's headers.
|
||||
static constexpr Uint64 DrmFormatModLinear = 0ULL;
|
||||
static constexpr Uint64 DrmFormatModInvalid = 0x00ffffffffffffffULL;
|
||||
|
||||
// Every buffer this library hands out is described by one of these. HostFrame
|
||||
// buffers are owned by the phone and only borrowed by us, so they must be
|
||||
// released back over the channel instead of being freed locally.
|
||||
enum class GbmBackend
|
||||
{
|
||||
None = 0,
|
||||
HostFrame,
|
||||
DmaHeap,
|
||||
MemFd,
|
||||
};
|
||||
|
||||
// The phone offers frames with this packed struct immediately followed by an
|
||||
// AHardwareBuffer native handle in the payload of one message, with the handle's
|
||||
// descriptors in the SCM_RIGHTS control data of that same message. The layout is
|
||||
// fixed by the phone side, so the packing attribute is load bearing and the field
|
||||
// order may not be rearranged.
|
||||
//
|
||||
// The transport below the two structs is SOCK_SEQPACKET, and that is part of the
|
||||
// protocol rather than an implementation detail: a frame and its descriptors only
|
||||
// mean anything together, and the message boundary is what lets the reader take
|
||||
// the two as one thing. A stream socket would let a reader receive half an offer,
|
||||
// or a descriptor whose position in the byte stream it had to reconstruct, and the
|
||||
// failure mode of getting that arithmetic wrong is a frame silently made of
|
||||
// another frame's memory.
|
||||
//
|
||||
// Format is a DRM fourcc and not an AHardwareBuffer format, because it is what
|
||||
// gbm_bo_get_format has to answer with and a compositor compares it against
|
||||
// DRM_FORMAT_* values. StrideBytes is the byte distance between two rows of plane
|
||||
// 0, which is the same single-stride description GBM_BO_IMPORT_FD carries - and
|
||||
// the reason a frame read from this struct is reported as linear.
|
||||
struct GbmFrameOffer
|
||||
{
|
||||
uint32_t Magic; // 'M','G','G','F' little endian on both ends of the wire
|
||||
uint32_t Version;
|
||||
uint32_t Seq;
|
||||
uint32_t Index;
|
||||
uint32_t Width;
|
||||
uint32_t Height;
|
||||
uint32_t StrideBytes;
|
||||
uint32_t Format;
|
||||
uint32_t UsageLo;
|
||||
uint32_t UsageHi;
|
||||
} __attribute__((packed));
|
||||
|
||||
// The container replies with this once it no longer reads the frame, which is
|
||||
// what lets the phone recycle the slot. Without it the display host would run
|
||||
// out of buffers after a handful of frames.
|
||||
struct GbmFrameRelease
|
||||
{
|
||||
uint32_t Magic; // 'M','G','G','R'
|
||||
uint32_t Version;
|
||||
uint32_t Seq;
|
||||
} __attribute__((packed));
|
||||
|
||||
static constexpr uint32_t GbmFrameOfferMagic = 0x4647474Du; // "MGGF"
|
||||
static constexpr uint32_t GbmFrameReleaseMagic = 0x5247474Du; // "MGGR"
|
||||
static constexpr uint32_t GbmHostProtocolVersion = 1;
|
||||
|
||||
// THE REVERSE DIRECTION: this end asking the render server to back one of its textures with a
|
||||
// dma-buf. The compositor's scene reaches the display daemon's buffers through
|
||||
// glEGLImageTargetTexture2DOES, and the server has to be told which texture that dma-buf backs -
|
||||
// over this same socket, because it is the one channel that can carry a descriptor across the
|
||||
// container boundary. Restated here rather than shared with MG_Backend/GbmFrameChannel.h for the
|
||||
// same reason the two frame shapes are: the ends are built into different libraries from
|
||||
// different build configurations (that file is the Android render server and never sees libgbm).
|
||||
// Field for field, packing included; the plane descriptors ride in the SCM_RIGHTS control data of
|
||||
// the same sendmsg, one message per import.
|
||||
struct GbmImportRequest
|
||||
{
|
||||
uint32_t Magic; // 'M','G','G','I'
|
||||
uint32_t Version;
|
||||
uint32_t Target; // the GL texture target the image was bound to (0x8D65 = GL_TEXTURE_EXTERNAL_OES)
|
||||
uint32_t TexName; // THIS side's texture name; the server resolves its twin
|
||||
uint32_t Width;
|
||||
uint32_t Height;
|
||||
uint32_t FourCC;
|
||||
uint32_t PlaneCount;
|
||||
int32_t Stride[4];
|
||||
int32_t Offset[4];
|
||||
uint64_t Modifier[4];
|
||||
uint32_t HasModifier[4];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct GbmImportReply
|
||||
{
|
||||
uint32_t Magic; // 'I','G','G','R'
|
||||
uint32_t Version;
|
||||
uint32_t Ok;
|
||||
uint32_t Reserved;
|
||||
} __attribute__((packed));
|
||||
|
||||
static constexpr uint32_t GbmImportRequestMagic = 0x4947474Du; // "MGGI"
|
||||
static constexpr uint32_t GbmImportReplyMagic = 0x52474749u; // "IGGR"
|
||||
static constexpr uint32_t GbmImportMaxPlanes = 4;
|
||||
|
||||
// An AHardwareBuffer native handle as it appears on the wire: three counts
|
||||
// followed by numFds file descriptors and numInts integers. The counts are
|
||||
// 32 bit even on 64 bit Android, which is why they are spelled out here
|
||||
// rather than using the platform's native_handle_t.
|
||||
struct AHBNativeHandleHeader
|
||||
{
|
||||
int32_t Version;
|
||||
int32_t NumFds;
|
||||
int32_t NumInts;
|
||||
} __attribute__((packed));
|
||||
|
||||
static constexpr uint32_t GbmMaxPlanes = 4;
|
||||
|
||||
// How one plane of a buffer is laid out inside the single allocation that backs
|
||||
// it. Multi-plane formats keep every plane in one dma-buf and describe the
|
||||
// separation with Offsets, which is the layout a modifier of
|
||||
// DRM_FORMAT_MOD_LINEAR can express and the only one this library produces.
|
||||
struct GbmPlaneLayout
|
||||
{
|
||||
Uint32 Stride = 0;
|
||||
Uint32 Offset = 0;
|
||||
SizeT Size = 0;
|
||||
};
|
||||
|
||||
// One frame the phone offered, as this process holds it: the offer's own
|
||||
// description of the memory, plus the descriptor this library duped out of the
|
||||
// handle the phone sent. It owns that descriptor for as long as it lives, so a
|
||||
// caller that takes a frame and then fails still closes it, and the descriptor the
|
||||
// phone sent is closed with the rest of the message's descriptors rather than kept.
|
||||
struct GbmHostFrame
|
||||
{
|
||||
Uint32 Seq = 0;
|
||||
Uint32 Index = 0;
|
||||
Uint32 Width = 0;
|
||||
Uint32 Height = 0;
|
||||
Uint32 StrideBytes = 0;
|
||||
Uint32 Format = 0;
|
||||
// Bytes per pixel of plane 0. The offer carries a fourcc, so it comes from the
|
||||
// format table when there is an entry for it and from the stride otherwise.
|
||||
Uint32 BytesPerPixel = 0;
|
||||
Uint64 Usage = 0;
|
||||
// Which connection offered the frame. A release names a frame, and a frame only
|
||||
// means anything to the connection that offered it.
|
||||
Uint64 Generation = 0;
|
||||
// The duped dma-buf descriptor, and how many bytes it actually backs as asked
|
||||
// of the descriptor itself rather than computed from the offered geometry.
|
||||
Int Fd = -1;
|
||||
SizeT Size = 0;
|
||||
|
||||
// Move-only, because two records naming one descriptor would close it twice.
|
||||
GbmHostFrame() = default;
|
||||
GbmHostFrame(const GbmHostFrame&) = delete;
|
||||
GbmHostFrame& operator=(const GbmHostFrame&) = delete;
|
||||
GbmHostFrame(GbmHostFrame&& other) noexcept;
|
||||
GbmHostFrame& operator=(GbmHostFrame&& other) noexcept;
|
||||
~GbmHostFrame();
|
||||
};
|
||||
|
||||
// One imported or locally allocated buffer. The struct is private to this
|
||||
// library; gbm_bo is the public opaque name and is defined in terms of it.
|
||||
struct GbmBufferObject
|
||||
{
|
||||
Uint32 Width = 0;
|
||||
Uint32 Height = 0;
|
||||
Uint32 Format = 0;
|
||||
Uint32 Stride = 0;
|
||||
Uint64 Modifier = DrmFormatModLinear;
|
||||
Uint64 Usage = 0;
|
||||
Int PlaneCount = 1;
|
||||
// Bytes per pixel of plane 0. Kept beside the layout because gbm_bo_map
|
||||
// needs it to place a sub-rectangle, and because a format this library can
|
||||
// allocate but cannot describe in bytes would be a format it must refuse.
|
||||
Uint32 BytesPerPixel = 0;
|
||||
|
||||
// Fds owned by this record. get_fd and get_fd_for_plane hand out dups so
|
||||
// that a caller closing its fd can never invalidate the buffer. Index 0 is
|
||||
// the only one a self-allocated buffer has: every plane of a linear image
|
||||
// lives in that one dma-buf, and Fds[1..] stay -1 for it. An import with
|
||||
// several descriptors fills several entries, and the destructor closes
|
||||
// every entry that is not -1.
|
||||
Int Fds[GbmMaxPlanes] = {-1, -1, -1, -1};
|
||||
Uint32 Strides[GbmMaxPlanes] = {0, 0, 0, 0};
|
||||
Uint32 Offsets[GbmMaxPlanes] = {0, 0, 0, 0};
|
||||
Uint64 Modifiers[GbmMaxPlanes] = {0, 0, 0, 0};
|
||||
|
||||
// The number of bytes the descriptors actually back, rounded up to the page
|
||||
// size because that is what both backends allocate. It is the only length
|
||||
// that is safe to mmap: a mapping longer than the object faults on the last
|
||||
// page, and a shorter one would hide the caller's own stride arithmetic.
|
||||
SizeT AllocationSize = 0;
|
||||
|
||||
GbmBackend Backend = GbmBackend::None;
|
||||
|
||||
// Set only for host frames: the slot index and sequence number that the
|
||||
// release message has to mention so the phone can recycle the right slot, and
|
||||
// the connection the frame arrived on. A frame left over from a connection
|
||||
// that has since died is never released into the one that replaced it, because
|
||||
// that would free a slot belonging to another session.
|
||||
Uint32 HostIndex = 0;
|
||||
Uint32 HostSeq = 0;
|
||||
Uint64 HostGeneration = 0;
|
||||
Bool HostOwned = false;
|
||||
|
||||
// How many maps are outstanding. The mapping itself is kept here so that
|
||||
// unmap can find and tear down the right one.
|
||||
Int MapRefCount = 0;
|
||||
void* MapAddress = nullptr;
|
||||
SizeT MapSize = 0;
|
||||
|
||||
// Surfaces keep their buffers alive by count rather than by ownership, so
|
||||
// the device knows when a bo is truly unreferenced.
|
||||
Int RefCount = 1;
|
||||
|
||||
// gbm_bo_set_user_data's pair. The destroy callback is invoked with the
|
||||
// gbm_bo that is going away, once, from the destructor below.
|
||||
void* UserData = nullptr;
|
||||
void (*UserDataDestroy)(::gbm_bo*, void*) = nullptr;
|
||||
|
||||
::gbm_device* Owner = nullptr;
|
||||
|
||||
// The record releases its own descriptors and its own mapping, so that no
|
||||
// failure path anywhere in this library can leak either one - an allocation
|
||||
// that fails half way through construction still cleans up when the record
|
||||
// it was building is destroyed.
|
||||
~GbmBufferObject();
|
||||
};
|
||||
|
||||
// A real swapchain. The compositor asks for a buffer to render into, presents
|
||||
// it, and later returns it; the three states below are exactly the states the
|
||||
// GBM API can express.
|
||||
struct GbmSurface
|
||||
{
|
||||
Uint32 Width = 0;
|
||||
Uint32 Height = 0;
|
||||
Uint32 Format = 0;
|
||||
Uint32 Flags = 0;
|
||||
|
||||
std::vector<::gbm_bo*> Buffers;
|
||||
// Index of the buffer currently handed to the compositor as the front
|
||||
// buffer, or -1 when nothing has been locked.
|
||||
Int LockedIndex = -1;
|
||||
// Indices of buffers the compositor has released and that may be handed
|
||||
// out again, plus the one that is locked.
|
||||
std::vector<Bool> Free;
|
||||
|
||||
::gbm_device* Owner = nullptr;
|
||||
|
||||
// Dropping the surface's references here is what keeps the creation path
|
||||
// free of a second failure path: if the third swapchain buffer cannot be
|
||||
// allocated, unwinding the half-built surface returns the two that exist.
|
||||
~GbmSurface();
|
||||
};
|
||||
|
||||
// The device ties one backend choice, one host channel and one mutex together.
|
||||
// The single mutex is deliberate: GBM calls arrive from the compositor's
|
||||
// render thread and from its main thread, and the state they touch (the bo
|
||||
// table, the backends) is small enough that one lock is cheaper than several.
|
||||
struct GbmDevice
|
||||
{
|
||||
// The fd this device was created with. It is a private dup taken at
|
||||
// creation, never the caller's descriptor, so gbm_device_destroy can close
|
||||
// it without ever closing an fd the caller still has open. -1 when the
|
||||
// caller passed none and no render node could be opened: the self-allocated
|
||||
// backend does not need a DRM node, so that is a working device and not an
|
||||
// error.
|
||||
Int DeviceFd = -1;
|
||||
// The dma-heap node this device allocates from, or -1 when none could be
|
||||
// opened, in which case every allocation falls back to a memfd.
|
||||
Int HeapFd = -1;
|
||||
String HeapPath;
|
||||
|
||||
// Where the display host is reached, as configured when the device was created.
|
||||
String SocketPath;
|
||||
GbmBackend DefaultBackend = GbmBackend::DmaHeap;
|
||||
// True while the channel below is connected and frames are arriving over it.
|
||||
// False means every allocation this device answers is answered locally.
|
||||
Bool HostAvailable = false;
|
||||
// The name gbm_device_get_backend_name reports. It names what this device
|
||||
// actually does, because a compositor that logs it is asking exactly that - so
|
||||
// it changes when the host channel connects and when that connection dies, and
|
||||
// SelfAllocatedBackendName is what it falls back to when it does.
|
||||
String BackendName = "mobilegl";
|
||||
String SelfAllocatedBackendName = "mobilegl";
|
||||
|
||||
std::mutex Mutex;
|
||||
std::unordered_map<::gbm_bo*, GbmBufferObject*> Buffers;
|
||||
std::unordered_map<::gbm_surface*, GbmSurface*> Surfaces;
|
||||
|
||||
// The host channel is a separate translation unit so that the socket protocol
|
||||
// never leaks into the allocation paths. It lives for as long as the device
|
||||
// does and is reached only under this device's mutex, which is what lets the
|
||||
// allocation path ask it for a frame without a second lock to order against.
|
||||
class GbmHostChannel* Host = nullptr;
|
||||
|
||||
// Closes the heap node and the private device dup, so that a device which
|
||||
// fails to finish constructing still releases the descriptors it opened.
|
||||
~GbmDevice();
|
||||
};
|
||||
|
||||
// ---- format description ------------------------------------------------
|
||||
|
||||
// Fills planes[]/planeCount/totalBytes with the linear layout this library
|
||||
// would allocate for format at width x height, and returns false for a format
|
||||
// it cannot lay out. gbm_bo_create refuses a format this refuses, because a
|
||||
// buffer whose plane layout was guessed is worse than a buffer that was not
|
||||
// handed out at all.
|
||||
Bool GbmDescribeFormat(Uint32 format, Uint32 width, Uint32 height, GbmPlaneLayout planes[GbmMaxPlanes],
|
||||
Int& planeCount, SizeT& totalBytes) noexcept;
|
||||
|
||||
// Whether this library can allocate the format at all.
|
||||
Bool GbmFormatIsSupported(Uint32 format) noexcept;
|
||||
|
||||
// Bytes per pixel of plane 0: what gbm_bo_map needs to place a sub-rectangle,
|
||||
// and half of what gbm_bo_get_bpp reports.
|
||||
Uint32 GbmFormatBytesPerPixel(Uint32 format) noexcept;
|
||||
|
||||
// ---- records and the self-allocated backend ----------------------------
|
||||
|
||||
// Builds a device. The only helper here that is called without the mutex,
|
||||
// because no other thread can see the device it is building.
|
||||
::gbm_device* GbmDeviceCreate(Int fd) noexcept;
|
||||
|
||||
// Tears the device down: every remaining surface, every remaining buffer, the
|
||||
// heap node, the private device fd, and the record itself.
|
||||
void GbmDeviceDestroy(::gbm_device& device) noexcept;
|
||||
|
||||
// Allocates a buffer from the device's heap node, or from a memfd when there
|
||||
// is none, and records it in the device's table. Returns null with errno set.
|
||||
::gbm_bo* GbmBufferCreate(::gbm_device& device, Uint32 width, Uint32 height, Uint32 format, Uint64 usage,
|
||||
const Uint64* modifiers, Uint32 modifierCount) noexcept;
|
||||
|
||||
// Wraps descriptors the caller already owns. The descriptors are duped, so the
|
||||
// caller keeps ownership of its own; type is GBM_BO_IMPORT_FD or
|
||||
// GBM_BO_IMPORT_FD_MODIFIER.
|
||||
::gbm_bo* GbmBufferImport(::gbm_device& device, Uint32 type, const void* buffer, Uint64 usage) noexcept;
|
||||
|
||||
// Drops one reference, destroying the buffer when it was the last one.
|
||||
void GbmBufferRelease(::gbm_device& device, ::gbm_bo& bo) noexcept;
|
||||
|
||||
// Destroys a buffer outright, whatever its reference count says. Only the
|
||||
// device's own teardown uses this: by then no caller's reference is meaningful.
|
||||
void GbmBufferForceDestroy(::gbm_device& device, ::gbm_bo& bo) noexcept;
|
||||
|
||||
// Hands out a dup of the descriptor backing a plane, which the caller then owns.
|
||||
// A plane this buffer does not have is refused with errno = EINVAL.
|
||||
Int GbmBufferDupFd(::gbm_bo& bo, Int plane) noexcept;
|
||||
|
||||
// Maps the whole buffer once and counts the call; strideOut receives the
|
||||
// stride of plane 0. The rect (x, y) is applied to the returned address.
|
||||
void* GbmBufferMap(::gbm_bo& bo, Uint32 x, Uint32 y, Uint32& strideOut) noexcept;
|
||||
|
||||
// Drops one mapping; the last one unmaps.
|
||||
void GbmBufferUnmap(::gbm_bo& bo, void* mapData) noexcept;
|
||||
|
||||
// ---- host frames -------------------------------------------------------
|
||||
|
||||
// Builds the channel to the display host and makes one attempt to connect it, then
|
||||
// stores it in the device. A machine that is not the container half of a split run
|
||||
// has nothing at that path, and that is a device which allocates locally from then
|
||||
// on - not a device that failed to be created.
|
||||
void GbmHostChannelCreate(::gbm_device& device) noexcept;
|
||||
|
||||
// Closes the channel and releases what it holds. Called from the device's
|
||||
// destructor, after the buffers that still name offered frames are gone, so that
|
||||
// their releases can still be sent.
|
||||
void GbmHostChannelDestroy(::gbm_device& device) noexcept;
|
||||
|
||||
// Takes the next frame the host offered, or returns false when none is waiting or
|
||||
// the channel is down. Never blocks: the socket is non-blocking, so a caller that
|
||||
// finds nothing allocates locally in the same call, which is what makes this usable
|
||||
// from a compositor's frame loop.
|
||||
Bool GbmHostChannelTakeFrame(::gbm_device& device, GbmHostFrame& frameOut) noexcept;
|
||||
|
||||
// Tells the host that a frame may be recycled. Called from the buffer record's
|
||||
// destructor, so a frame goes back exactly when nothing in this process can still
|
||||
// read it, and only into the connection that offered it.
|
||||
void GbmHostChannelReleaseFrame(::gbm_device& device, Uint32 seq, Uint64 generation) noexcept;
|
||||
|
||||
// ---- swapchains --------------------------------------------------------
|
||||
|
||||
// Builds a surface and its swapchain up front, so that
|
||||
// gbm_surface_has_free_buffers can answer truthfully from the first call.
|
||||
::gbm_surface* GbmSurfaceCreate(::gbm_device& device, Uint32 width, Uint32 height, Uint32 format, Uint64 usage,
|
||||
const Uint64* modifiers, Uint32 modifierCount) noexcept;
|
||||
|
||||
// Unregisters the surface and destroys it, returning the swapchain buffers it
|
||||
// still owns to the device.
|
||||
void GbmSurfaceDestroy(::gbm_surface& surface) noexcept;
|
||||
|
||||
// Hands out the next free swapchain buffer with a reference of its own, or
|
||||
// null with errno = EBUSY when the compositor still holds every one of them.
|
||||
::gbm_bo* GbmSurfaceLockFront(::gbm_surface& surface) noexcept;
|
||||
|
||||
// Takes a locked buffer back, dropping the reference the lock handed out.
|
||||
void GbmSurfaceReleaseBuffer(::gbm_surface& surface, ::gbm_bo& bo) noexcept;
|
||||
|
||||
Bool GbmSurfaceHasFreeBuffers(::gbm_surface& surface) noexcept;
|
||||
} // namespace MobileGL::MG_Gbm
|
||||
|
||||
// The public opaque types are the internal records. Callers only ever see the
|
||||
// pointers, so this costs nothing and removes a layer of casting.
|
||||
struct gbm_device
|
||||
{
|
||||
MobileGL::MG_Gbm::GbmDevice Impl;
|
||||
};
|
||||
|
||||
struct gbm_bo
|
||||
{
|
||||
MobileGL::MG_Gbm::GbmBufferObject Impl;
|
||||
};
|
||||
|
||||
struct gbm_surface
|
||||
{
|
||||
MobileGL::MG_Gbm::GbmSurface Impl;
|
||||
};
|
||||
|
||||
// End of Source File Header
|
||||
@@ -7,8 +7,6 @@
|
||||
// End of Source File Header
|
||||
|
||||
#include "EGLImpl.h"
|
||||
#include "EGLPlatformExtensions.h"
|
||||
#include "WaylandWindow.h"
|
||||
#include "../GetProcAddress.h"
|
||||
#include <Init.h>
|
||||
#include <MG_Backend/BackendObjects.h>
|
||||
@@ -22,36 +20,6 @@
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
|
||||
// The KHR spellings of the image entry points, exported by Exporting/Definitions.cpp. Declared
|
||||
// here because the bundled EGL headers declare them only under EGL_EGLEXT_PROTOTYPES, which no
|
||||
// build of this library defines, and because eglGetProcAddress below answers them by name.
|
||||
extern "C" EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer,
|
||||
const EGLint* attrib_list);
|
||||
extern "C" EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image);
|
||||
|
||||
// The swap-and-sync family the compositor resolves by name while bringing its EGL backend up; defined
|
||||
// in Exporting/Definitions.cpp and answered from GetProcAddress below (see the definitions).
|
||||
extern "C" EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface, const EGLint* rects,
|
||||
EGLint n_rects);
|
||||
extern "C" EGLBoolean eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface, const EGLint* rects,
|
||||
EGLint n_rects);
|
||||
extern "C" EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint* attrib_list);
|
||||
extern "C" EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync);
|
||||
extern "C" EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
|
||||
extern "C" EGLBoolean eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags);
|
||||
extern "C" EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint* value);
|
||||
// THE DEVICE-QUERY FAMILY, exported by Exporting/Definitions.cpp and answered by name below: kwin
|
||||
// reaches eglQueryDisplayAttribEXT through libepoxy's pointer (that is how finding a render device
|
||||
// starts), and libepoxy asks for it by name. See the definitions for why these had to exist.
|
||||
extern "C" EGLBoolean eglQueryDevicesEXT(EGLint max_devices, EGLDeviceEXT* devices, EGLint* num_devices);
|
||||
extern "C" EGLBoolean eglQueryDeviceAttribEXT(EGLDeviceEXT device, EGLint attribute, EGLAttrib* value);
|
||||
extern "C" const char* eglQueryDeviceStringEXT(EGLDeviceEXT device, EGLint name);
|
||||
extern "C" EGLBoolean eglQueryDisplayAttribEXT(EGLDisplay dpy, EGLint attribute, EGLAttrib* value);
|
||||
extern "C" EGLSurface eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config, void* native_window,
|
||||
const EGLAttrib* attrib_list);
|
||||
extern "C" EGLSurface eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config, void* native_pixmap,
|
||||
const EGLAttrib* attrib_list);
|
||||
|
||||
namespace MobileGL::MG_Impl::EGLImpl {
|
||||
namespace {
|
||||
using EGLStateContext = MG_State::EGLState::EGLContext;
|
||||
@@ -148,73 +116,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
return reinterpret_cast<void*>(static_cast<SizeT>(nativeHandle));
|
||||
}
|
||||
}
|
||||
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
// Every Wayland window surface's presentation, by surface. Guarded by EGLOperationMutex,
|
||||
// which every entry point that reaches it holds.
|
||||
UnorderedMap<EGLSurface, UniquePtr<Wayland::WindowSurface>>& WaylandSurfaces() {
|
||||
static auto* surfaces = new UnorderedMap<EGLSurface, UniquePtr<Wayland::WindowSurface>>();
|
||||
return *surfaces;
|
||||
}
|
||||
|
||||
// A WINDOW ON A WAYLAND DISPLAY. Whatever MOBILEGL_IPC_SURFACE says, the window is this
|
||||
// application's own wl_surface, so neither the server's window nor the display host's frame
|
||||
// is what it shows: the backend draws into a pbuffer of the window's size, and each swap
|
||||
// reads the frame back and attaches it to the wl_surface (WaylandWindow.h). Answers false
|
||||
// when the display is not a Wayland one; otherwise *out is the surface, or EGL_NO_SURFACE
|
||||
// with the error set.
|
||||
template <typename State>
|
||||
Bool CreateWaylandWindowSurface(State* state, EGLDisplay dpy, EGLConfig config, void* window,
|
||||
Bool platformWindow, EGLSurface* out) {
|
||||
Uint64 nativeDisplay = 0;
|
||||
EGLenum platform = EGL_NONE;
|
||||
if (!state->GetDisplayNative(dpy, &nativeDisplay, &platform) ||
|
||||
!Wayland::IsWaylandDisplay(nativeDisplay, platform)) {
|
||||
return false;
|
||||
}
|
||||
*out = EGL_NO_SURFACE;
|
||||
if (!state->IsDisplayInitialized(dpy)) {
|
||||
state->SetError(EGL_NOT_INITIALIZED);
|
||||
return true;
|
||||
}
|
||||
if (!state->ValidateConfigOnDisplay(dpy, config)) {
|
||||
state->SetError(EGL_BAD_CONFIG);
|
||||
return true;
|
||||
}
|
||||
EGLint width = 0;
|
||||
EGLint height = 0;
|
||||
if (!Wayland::WindowSize(window, &width, &height)) {
|
||||
state->SetError(EGL_BAD_NATIVE_WINDOW);
|
||||
return true;
|
||||
}
|
||||
EGLint alpha = 0;
|
||||
(void)state->GetConfigAttrib(dpy, config, EGL_ALPHA_SIZE, &alpha);
|
||||
auto presentation =
|
||||
Wayland::WindowSurface::Create(reinterpret_cast<void*>(static_cast<uintptr_t>(nativeDisplay)), window,
|
||||
width, height, alpha > 0);
|
||||
if (!presentation) {
|
||||
state->SetError(EGL_BAD_NATIVE_WINDOW);
|
||||
return true;
|
||||
}
|
||||
const EGLSurface surface =
|
||||
platformWindow ? state->CreatePlatformWindowSurface(dpy, config, window, nullptr)
|
||||
: state->CreateWindowSurface(
|
||||
dpy, config, (NativeWindowType)(reinterpret_cast<uintptr_t>(window)), nullptr);
|
||||
if (surface == EGL_NO_SURFACE) return true;
|
||||
(void)state->ResizeSurface(dpy, surface, width, height);
|
||||
auto* backendObject = GetBackendObject(state);
|
||||
if (!backendObject || !backendObject->CreateEGLPbufferSurface(surface, width, height)) {
|
||||
MGLOG_E("eglCreateWindowSurface: the backend refused the %dx%d drawable behind a Wayland window",
|
||||
width, height);
|
||||
state->DestroySurface(dpy, surface);
|
||||
state->SetError(EGL_BAD_ALLOC);
|
||||
return true;
|
||||
}
|
||||
WaylandSurfaces()[surface] = std::move(presentation);
|
||||
*out = surface;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
} // namespace
|
||||
|
||||
EGLSurface CreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window,
|
||||
@@ -223,16 +124,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
if (!state) {
|
||||
return EGL_NO_SURFACE;
|
||||
}
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
{
|
||||
const std::lock_guard<std::recursive_mutex> operationLock(EGLOperationMutex());
|
||||
EGLSurface waylandSurface = EGL_NO_SURFACE;
|
||||
if (CreateWaylandWindowSurface(state, dpy, config, ToVoidHandle(window), /*platformWindow=*/false,
|
||||
&waylandSurface)) {
|
||||
return waylandSurface;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (!state->IsDisplayInitialized(dpy)) {
|
||||
state->SetError(EGL_NOT_INITIALIZED);
|
||||
return EGL_NO_SURFACE;
|
||||
@@ -246,11 +137,8 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
// the window is the SERVER's: a headless client passes none, so NULL is not
|
||||
// EGL_BAD_NATIVE_WINDOW here. Whatever the client passed never reaches the wire - the
|
||||
// remote backend sends WindowKind::ServerOwned with token 0 (BackendObject_Remote).
|
||||
// Either on-screen shape leaves this side without a window of its own: =server asks the
|
||||
// server for its own window, =host draws into the frames the display host offers.
|
||||
const Bool windowlessOnScreen =
|
||||
MG_Config::ServerOwnedWindowSurfaces() || MG_Config::HostFrameWindowSurfaces();
|
||||
if (IsNullNativeHandle(window) && !windowlessOnScreen) {
|
||||
const Bool serverOwnedWindow = MG_Config::ServerOwnedWindowSurfaces();
|
||||
if (IsNullNativeHandle(window) && !serverOwnedWindow) {
|
||||
#else
|
||||
if (IsNullNativeHandle(window)) {
|
||||
#endif
|
||||
@@ -269,15 +157,15 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
// alike; the same game in a landscape window was right). The native window it handed us
|
||||
// knows the size the game believes it has: ask for THAT, and the server fixes its window
|
||||
// buffer to it and aspect-fits the view (MobileGLDisplayActivity), letterboxed.
|
||||
if (windowlessOnScreen && requestedWidth == 0 && requestedHeight == 0 && !IsNullNativeHandle(window)) {
|
||||
if (serverOwnedWindow && requestedWidth == 0 && requestedHeight == 0 && !IsNullNativeHandle(window)) {
|
||||
auto* native = reinterpret_cast<ANativeWindow*>(ToVoidHandle(window));
|
||||
const int32_t nativeWidth = ANativeWindow_getWidth(native);
|
||||
const int32_t nativeHeight = ANativeWindow_getHeight(native);
|
||||
if (nativeWidth > 0 && nativeHeight > 0) {
|
||||
requestedWidth = static_cast<Uint32>(nativeWidth);
|
||||
requestedHeight = static_cast<Uint32>(nativeHeight);
|
||||
MGLOG_I("eglCreateWindowSurface: no EGL_WIDTH/EGL_HEIGHT; the on-screen surface is asked for "
|
||||
"the native window's %dx%d", nativeWidth, nativeHeight);
|
||||
MGLOG_I("eglCreateWindowSurface: no EGL_WIDTH/EGL_HEIGHT; the server-owned window is asked for the "
|
||||
"native window's %dx%d", nativeWidth, nativeHeight);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -289,20 +177,11 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
};
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
EGLSurface surface = EGL_NO_SURFACE;
|
||||
if (MG_Config::ServerOwnedWindowSurfaces()) {
|
||||
// The server's own window: it makes one and draws into it.
|
||||
surface = state->CreateServerOwnedWindowSurface(
|
||||
dpy, config, windowHandle.Handle, static_cast<EGLint>(windowHandle.Width),
|
||||
static_cast<EGLint>(windowHandle.Height), /*platformWindow=*/false);
|
||||
} else if (MG_Config::HostFrameWindowSurfaces()) {
|
||||
// The display host's frames, as above: no window of the client's either way.
|
||||
surface = state->CreateHostFrameWindowSurface(
|
||||
dpy, config, windowHandle.Handle, static_cast<EGLint>(windowHandle.Width),
|
||||
static_cast<EGLint>(windowHandle.Height), /*platformWindow=*/false);
|
||||
} else {
|
||||
surface = state->CreateWindowSurface(dpy, config, window, attrib_list);
|
||||
}
|
||||
EGLSurface surface = serverOwnedWindow
|
||||
? state->CreateServerOwnedWindowSurface(
|
||||
dpy, config, windowHandle.Handle, static_cast<EGLint>(windowHandle.Width),
|
||||
static_cast<EGLint>(windowHandle.Height), /*platformWindow=*/false)
|
||||
: state->CreateWindowSurface(dpy, config, window, attrib_list);
|
||||
#else
|
||||
EGLSurface surface = state->CreateWindowSurface(dpy, config, window, attrib_list);
|
||||
#endif
|
||||
@@ -332,7 +211,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
return EGL_FALSE;
|
||||
}
|
||||
if (!state->ValidateSurfaceOnDisplay(dpy, draw)) {
|
||||
MGLOG_E_ONCE("eglSwapBuffers: surface %p is not a surface of display %p (EGL_BAD_SURFACE)", draw, dpy);
|
||||
state->SetError(EGL_BAD_SURFACE);
|
||||
return EGL_FALSE;
|
||||
}
|
||||
@@ -342,11 +220,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
MGLOG_E_ONCE("activeBackendObject not initialized!");
|
||||
return EGL_FALSE;
|
||||
}
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
// A Wayland window shows what is attached to it: the frame is read back and attached
|
||||
// BEFORE the swap, while it is still the drawable's content.
|
||||
if (auto it = WaylandSurfaces().find(draw); it != WaylandSurfaces().end()) (void)it->second->Present();
|
||||
#endif
|
||||
if (!backendObject->SwapEGLBuffers(dpy, draw)) {
|
||||
MGLOG_E_ONCE("eglSwapBuffers failed on thread=%s dpy=%p draw=%p", CurrentThreadIdString().c_str(), dpy, draw);
|
||||
state->SetError(EGL_BAD_SURFACE);
|
||||
@@ -357,13 +230,7 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
|
||||
EGLBoolean ChooseConfig(EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs, EGLint config_size,
|
||||
EGLint* num_config) {
|
||||
// eglChooseConfig can be an application's first EGL call after eglGetPlatformDisplay + eglInitialize,
|
||||
// and for a display built from an EGLDeviceEXT nothing has brought MobileGL up yet: GetState()
|
||||
// then answers NULL and the call lands in EGLContext::ChooseConfig with a null this - measured as
|
||||
// a crash inside that function (pc/lr both resolved to it) with kwin's own "pEGLContext is null.
|
||||
// MG_State may not be initialized." as the only warning, and reported one layer up as
|
||||
// "Could not initialize rendering context".
|
||||
auto* state = GetStateEnsureInitialized();
|
||||
auto* state = GetState();
|
||||
if (!state) {
|
||||
return EGL_FALSE;
|
||||
}
|
||||
@@ -371,26 +238,11 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
}
|
||||
|
||||
EGLContext CreateContext(EGLDisplay dpy, EGLConfig config, EGLContext shareCtx, const EGLint* attrib_list) {
|
||||
// WHICH CONTEXT IS BEING ASKED FOR, and what came back. kwin's OpenGL compositing fails with
|
||||
// "Could not initialize rendering context" while the same path succeeds from a probe against
|
||||
// this same library (probe10: a 3.3 core context on a GBM surface, makeCurrent answered 1),
|
||||
// so the difference has to be in this argument list - and an EGL vendor cannot see it from the
|
||||
// outside. The list is dumped in EGL_NONE-terminated pairs; EGL_NONE is 0x3038, not 0.
|
||||
MGLOG_I("eglCreateContext(dpy=%p, config=%p, share=%p)", dpy, config, shareCtx);
|
||||
if (attrib_list != nullptr) {
|
||||
for (int index = 0; attrib_list[index] != EGL_NONE; index += 2) {
|
||||
MGLOG_I(" attrib 0x%04x = %d", attrib_list[index], attrib_list[index + 1]);
|
||||
}
|
||||
} else {
|
||||
MGLOG_I(" (no attribute list)");
|
||||
}
|
||||
auto* state = GetStateEnsureInitialized();
|
||||
auto* state = GetState();
|
||||
if (!state) {
|
||||
return EGL_NO_CONTEXT;
|
||||
}
|
||||
EGLContext context = state->CreateContext(dpy, config, shareCtx, attrib_list);
|
||||
MGLOG_I("eglCreateContext -> %p", static_cast<void*>(context));
|
||||
return context;
|
||||
return state->CreateContext(dpy, config, shareCtx, attrib_list);
|
||||
}
|
||||
|
||||
EGLBoolean Initialize(EGLDisplay dpy, EGLint* major, EGLint* minor) {
|
||||
@@ -430,13 +282,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
return state->ConsumeError();
|
||||
}
|
||||
|
||||
// THE DISPLAY HOST'S FRAME, AS THE COMPOSITOR PRESENTS IT. Set by the surfaceless-bind hook in
|
||||
// MakeCurrent when this client (the compositor) takes the host frame; read by glFlush, which is
|
||||
// that compositor's only frame boundary - it never calls eglSwapBuffers, and without a present
|
||||
// the display host is never told a frame is done, so nothing ever reaches the glass.
|
||||
EGLDisplay g_hostFramePresentDisplay = nullptr;
|
||||
EGLSurface g_hostFramePresentSurface = nullptr;
|
||||
|
||||
EGLBoolean MakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx) {
|
||||
const std::lock_guard<std::recursive_mutex> operationLock(EGLOperationMutex());
|
||||
auto* state = GetState();
|
||||
@@ -453,81 +298,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
MGLOG_D("eglMakeCurrent begin thread=%s dpy=%p draw=%p read=%p ctx=%p oldDpy=%p oldDraw=%p oldRead=%p oldCtx=%p",
|
||||
threadId.c_str(), dpy, draw, read, ctx, oldDisplay, oldDraw, oldRead, oldContext);
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// THE DISPLAY HOST'S FRAMES, TO A CLIENT THAT ASKS FOR NO SURFACE.
|
||||
//
|
||||
// A compositor on this route never calls eglCreateWindowSurface: it imports the display host's
|
||||
// dma-bufs and draws into them through framebuffers, binding its contexts with EGL_NO_SURFACE.
|
||||
// The host frame bridge, though, is opened by exactly one thing - a surface being CREATED and
|
||||
// activated (ServerLoop's CreateWindowSurface with the host-frame window backend ->
|
||||
// InitHostFrameSurface) - so with no surface ever created the bridge stayed shut, the display
|
||||
// host kept offering frames into a name nobody served ("offer buffer 0: bridge fd=-1"), and no
|
||||
// frame could reach the glass no matter how much was drawn. So: when the session asked for
|
||||
// host-framed surfaces and a real context is being bound with no surface, make it the surface
|
||||
// eglCreatePlatformWindowSurface would have made, once, and bind that. The size is the display
|
||||
// host's own frame size; the client's window value is not on this path at all.
|
||||
// ONLY THE COMPOSITOR TAKES THE HOST FRAME. A desktop is full of processes that bind a
|
||||
// context with no surface - konsole, plasmashell, kactivitymanagerd - and measured with
|
||||
// probe15 as the second client: such a bind from a NON-compositor process made the host-frame
|
||||
// activation fail (makeCurrent=0) and the process aborted. The compositor is marked by its
|
||||
// launcher with MOBILEGL_HOST_FRAME_CLIENT=1; everyone else keeps the plain surfaceless bind,
|
||||
// which is all they ever wanted.
|
||||
if (draw == EGL_NO_SURFACE && read == EGL_NO_SURFACE && ctx != EGL_NO_CONTEXT &&
|
||||
MG_Config::HostFrameWindowSurfaces() &&
|
||||
(std::getenv("MOBILEGL_HOST_FRAME_CLIENT") != nullptr &&
|
||||
std::string("1") == std::getenv("MOBILEGL_HOST_FRAME_CLIENT"))) {
|
||||
static Bool hostFrameSurfaceTaken = false;
|
||||
if (!hostFrameSurfaceTaken) {
|
||||
hostFrameSurfaceTaken = true;
|
||||
EGLConfig hostFrameConfig = nullptr;
|
||||
EGLint hostFrameConfigCount = 0;
|
||||
const EGLint hostFrameChoose[] = {EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE};
|
||||
if (state->ChooseConfig(dpy, hostFrameChoose, &hostFrameConfig, 1,
|
||||
&hostFrameConfigCount) &&
|
||||
hostFrameConfigCount > 0 && hostFrameConfig != nullptr) {
|
||||
// BOTH HALVES, exactly as eglCreateWindowSurface makes one: the EGL state's
|
||||
// registration (without it every later bind and swap of this surface was refused
|
||||
// as EGL_BAD_SURFACE - measured: "eglMakeCurrent rejected by EGLState
|
||||
// error=0x300d", and glFlush's swaps returned before reaching the backend), then
|
||||
// the backend's own window-surface entry, which the remote backend routes to the
|
||||
// host frame (BackendObject_Remote::CreateHostFrameWindowSurface) - the call that
|
||||
// puts a CreateWindowSurface frame with the host-frame window backend on the wire.
|
||||
const EGLSurface hostFrameSurface = state->CreateHostFrameWindowSurface(
|
||||
dpy, hostFrameConfig, nullptr, 1440, 3200, /*platformWindow=*/false);
|
||||
MG_Backend::WindowHandle hostFrameHandle{};
|
||||
hostFrameHandle.Width = 1440;
|
||||
hostFrameHandle.Height = 3200;
|
||||
if (hostFrameSurface == EGL_NO_SURFACE) {
|
||||
MGLOG_E("host frame: the EGL state refused the display host's frame surface");
|
||||
} else if (!MG_Backend::pActiveBackendObject->CreateEGLWindowSurface(hostFrameSurface,
|
||||
hostFrameHandle)) {
|
||||
MGLOG_E("host frame: the backend refused the display host's frame surface");
|
||||
state->DestroySurface(dpy, hostFrameSurface);
|
||||
} else {
|
||||
// The frame boundary of a compositor that never swaps is its glFlush. glFlush
|
||||
// has no EGL context of its own, so remember HERE which surface presents the
|
||||
// display host's frame; glFlush presents it (see the host-frame present in
|
||||
// glFlush's implementation).
|
||||
g_hostFramePresentDisplay = dpy;
|
||||
g_hostFramePresentSurface = hostFrameSurface;
|
||||
MGLOG_I("host frame: the first surfaceless eglMakeCurrent made the display host's "
|
||||
"frame surface %p (%dx%d)",
|
||||
hostFrameSurface, 1440, 3200);
|
||||
}
|
||||
} else {
|
||||
MGLOG_E("host frame: no config for the display host's frame surface");
|
||||
}
|
||||
}
|
||||
// EVERY surfaceless bind, not only the first: the compositor rebinds with EGL_NO_SURFACE
|
||||
// all the time, and a bind without the surface leaves nothing current for glFlush's swap
|
||||
// to present (BackendObject::SwapEGLBuffers: "draw surface is not current on this thread").
|
||||
if (g_hostFramePresentSurface != nullptr && dpy == g_hostFramePresentDisplay) {
|
||||
draw = g_hostFramePresentSurface;
|
||||
read = g_hostFramePresentSurface;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!state->MakeCurrent(dpy, draw, read, ctx)) {
|
||||
const EGLint error = state->ConsumeError();
|
||||
MGLOG_D("eglMakeCurrent rejected by EGLState thread=%s error=0x%04x", threadId.c_str(), error);
|
||||
@@ -585,9 +355,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
if (!state->DestroySurface(dpy, surface)) {
|
||||
return EGL_FALSE;
|
||||
}
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
WaylandSurfaces().erase(surface);
|
||||
#endif
|
||||
if (auto* backendObject = MG_Backend::pActiveBackendObject.get()) {
|
||||
backendObject->ReleaseEGLSurface(surface);
|
||||
}
|
||||
@@ -696,10 +463,14 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
case EGL_CLIENT_APIS:
|
||||
return "OpenGL OpenGL_ES";
|
||||
case EGL_EXTENSIONS:
|
||||
// One list, in EGLPlatformExtensions.h, because the vendor string glvnd reads and
|
||||
// this query an application reads have to agree: an application that does not see the
|
||||
// platform extension here never asks for a platform display at all.
|
||||
return display == EGL_NO_DISPLAY ? kClientExtensionString : kDisplayExtensionString;
|
||||
if (display == EGL_NO_DISPLAY) {
|
||||
return "EGL_EXT_client_extensions "
|
||||
"EGL_EXT_platform_base "
|
||||
"EGL_KHR_platform_base "
|
||||
"EGL_MESA_platform_surfaceless";
|
||||
}
|
||||
return "EGL_KHR_create_context "
|
||||
"EGL_MESA_platform_surfaceless";
|
||||
default:
|
||||
state->SetError(EGL_BAD_PARAMETER);
|
||||
return nullptr;
|
||||
@@ -934,23 +705,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
return state->DestroyImage(dpy, image) ? EGL_TRUE : EGL_FALSE;
|
||||
}
|
||||
|
||||
EGLImageKHR CreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer,
|
||||
const EGLint* attrib_list) {
|
||||
// EGL_KHR_image_base spells its attribute list in EGLint pairs and the core eglCreateImage
|
||||
// in EGLAttrib pairs, and the two are not the same memory: on a 64-bit build one entry is
|
||||
// twice the width of the other, so the caller's array cannot be handed over as it stands.
|
||||
// Re-spelling it is therefore part of the entry point rather than a detail of the state.
|
||||
Vector<EGLAttrib> attribs;
|
||||
if (attrib_list != nullptr) {
|
||||
for (SizeT i = 0; attrib_list[i] != EGL_NONE; i += 2) {
|
||||
attribs.push_back(static_cast<EGLAttrib>(attrib_list[i]));
|
||||
attribs.push_back(static_cast<EGLAttrib>(attrib_list[i + 1]));
|
||||
}
|
||||
attribs.push_back(static_cast<EGLAttrib>(EGL_NONE));
|
||||
}
|
||||
return CreateImage(dpy, ctx, target, buffer, attribs.empty() ? nullptr : attribs.data());
|
||||
}
|
||||
|
||||
EGLDisplay GetPlatformDisplay(EGLenum platform, void* native_display, const EGLAttrib* attrib_list) {
|
||||
(void)attrib_list;
|
||||
|
||||
@@ -967,24 +721,11 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
if (!state) {
|
||||
return EGL_NO_SURFACE;
|
||||
}
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
{
|
||||
const std::lock_guard<std::recursive_mutex> operationLock(EGLOperationMutex());
|
||||
EGLSurface waylandSurface = EGL_NO_SURFACE;
|
||||
if (CreateWaylandWindowSurface(state, dpy, config, native_window, /*platformWindow=*/true,
|
||||
&waylandSurface)) {
|
||||
return waylandSurface;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P12 (on-screen server window), D1: as CreateWindowSurface - with MOBILEGL_IPC_SURFACE=server
|
||||
// the window is the server's, and a headless client's NULL is accepted.
|
||||
// Either on-screen shape leaves this side without a window of its own: =server asks the
|
||||
// server for its own window, =host draws into the frames the display host offers.
|
||||
const Bool windowlessOnScreen =
|
||||
MG_Config::ServerOwnedWindowSurfaces() || MG_Config::HostFrameWindowSurfaces();
|
||||
if (native_window == nullptr && !windowlessOnScreen) {
|
||||
const Bool serverOwnedWindow = MG_Config::ServerOwnedWindowSurfaces();
|
||||
if (native_window == nullptr && !serverOwnedWindow) {
|
||||
#else
|
||||
if (native_window == nullptr) {
|
||||
#endif
|
||||
@@ -1008,21 +749,11 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
};
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
EGLSurface surface = EGL_NO_SURFACE;
|
||||
if (MG_Config::ServerOwnedWindowSurfaces()) {
|
||||
// The server's own window: it makes one and draws into it.
|
||||
surface = state->CreateServerOwnedWindowSurface(
|
||||
dpy, config, native_window, static_cast<EGLint>(windowHandle.Width),
|
||||
static_cast<EGLint>(windowHandle.Height), /*platformWindow=*/true);
|
||||
} else if (MG_Config::HostFrameWindowSurfaces()) {
|
||||
// The display host's frames: it allocates them, the server draws into them,
|
||||
// and the host puts each one on the glass when the server says it is drawn.
|
||||
surface = state->CreateHostFrameWindowSurface(
|
||||
dpy, config, native_window, static_cast<EGLint>(windowHandle.Width),
|
||||
static_cast<EGLint>(windowHandle.Height), /*platformWindow=*/true);
|
||||
} else {
|
||||
surface = state->CreatePlatformWindowSurface(dpy, config, native_window, attrib_list);
|
||||
}
|
||||
EGLSurface surface = serverOwnedWindow
|
||||
? state->CreateServerOwnedWindowSurface(
|
||||
dpy, config, native_window, static_cast<EGLint>(windowHandle.Width),
|
||||
static_cast<EGLint>(windowHandle.Height), /*platformWindow=*/true)
|
||||
: state->CreatePlatformWindowSurface(dpy, config, native_window, attrib_list);
|
||||
#else
|
||||
EGLSurface surface = state->CreatePlatformWindowSurface(dpy, config, native_window, attrib_list);
|
||||
#endif
|
||||
@@ -1091,72 +822,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
MobileGL::EnsureInitialized();
|
||||
|
||||
MGLOG_D("eglGetProcAddress(%s)", name);
|
||||
|
||||
// THE KHR SPELLINGS ARE ENTRY POINTS OF THEIR OWN, and by name is the only way anything
|
||||
// asks for them. Measured in the Fedora container that runs this library as the glvnd EGL
|
||||
// vendor, before they were answered here: eglGetProcAddress("eglCreateImageKHR") -> NULL and
|
||||
// eglGetProcAddress("eglDestroyImageKHR") -> NULL. kwin_wayland's anland backend imports
|
||||
// the display daemon's dma-bufs through exactly these two (AnlandEglLayer::importBuffers ->
|
||||
// EglBackend::importDmaBufAsTexture -> EglDisplay::importBufferAsImage ->
|
||||
// EglDisplay::createImage, which calls the pointer without a null check), so a NULL here is
|
||||
// a compositor that cannot draw a single pixel into the frames the daemon hands it. The
|
||||
// core spellings were already in the table below; these are the same functions under the
|
||||
// names EGL_KHR_image_base gives them, which is also why they answer in the glvnd vendor
|
||||
// table beside them (Exporting/GlvndVendor.cpp).
|
||||
if (std::strcmp(name, "eglCreateImageKHR") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglCreateImageKHR);
|
||||
}
|
||||
if (std::strcmp(name, "eglDestroyImageKHR") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglDestroyImageKHR);
|
||||
}
|
||||
// The device-query family and the EXT platform-surface spellings. Measured in the container
|
||||
// before they were answered here: eglGetProcAddress returned NULL for eglQueryDisplayAttribEXT,
|
||||
// eglQueryDevicesEXT, eglQueryDeviceAttribEXT, eglQueryDeviceStringEXT and
|
||||
// eglCreatePlatformWindowSurfaceEXT while the extension strings announced EGL_EXT_device_query -
|
||||
// a NULL libepoxy then called (kwin crashed at pc=0), and withdrawing the announcement instead
|
||||
// left kwin without a render device and its compositing inactive.
|
||||
if (std::strcmp(name, "eglQueryDevicesEXT") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglQueryDevicesEXT);
|
||||
}
|
||||
if (std::strcmp(name, "eglQueryDeviceAttribEXT") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglQueryDeviceAttribEXT);
|
||||
}
|
||||
if (std::strcmp(name, "eglQueryDeviceStringEXT") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglQueryDeviceStringEXT);
|
||||
}
|
||||
if (std::strcmp(name, "eglQueryDisplayAttribEXT") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglQueryDisplayAttribEXT);
|
||||
}
|
||||
if (std::strcmp(name, "eglCreatePlatformWindowSurfaceEXT") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglCreatePlatformWindowSurfaceEXT);
|
||||
}
|
||||
if (std::strcmp(name, "eglCreatePlatformPixmapSurfaceEXT") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglCreatePlatformPixmapSurfaceEXT);
|
||||
}
|
||||
// The swap-and-sync spellings kwin resolves by name while it is still bringing its EGL backend
|
||||
// up (see the definitions: EGL_KHR_fence_sync, the damage variants, EGL_EXT_buffer_age).
|
||||
if (std::strcmp(name, "eglSwapBuffersWithDamageKHR") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglSwapBuffersWithDamageKHR);
|
||||
}
|
||||
if (std::strcmp(name, "eglSwapBuffersWithDamageEXT") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglSwapBuffersWithDamageEXT);
|
||||
}
|
||||
if (std::strcmp(name, "eglCreateSyncKHR") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglCreateSyncKHR);
|
||||
}
|
||||
if (std::strcmp(name, "eglDestroySyncKHR") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglDestroySyncKHR);
|
||||
}
|
||||
if (std::strcmp(name, "eglClientWaitSyncKHR") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglClientWaitSyncKHR);
|
||||
}
|
||||
if (std::strcmp(name, "eglWaitSyncKHR") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglWaitSyncKHR);
|
||||
}
|
||||
if (std::strcmp(name, "eglGetSyncAttribKHR") == 0) {
|
||||
return reinterpret_cast<__eglMustCastToProperFunctionPointerType>(eglGetSyncAttribKHR);
|
||||
}
|
||||
|
||||
void* proc = MG_Impl::GetProcAddress(name);
|
||||
if (!proc) {
|
||||
MGLOG_D("Failed to get function: %s", name);
|
||||
|
||||
@@ -8,18 +8,8 @@
|
||||
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
// EGLImageKHR: the return type of the KHR spelling of eglCreateImage below. Includes.h brings in
|
||||
// the core egl.h, which has no KHR types in it.
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
namespace MobileGL::MG_Impl::EGLImpl {
|
||||
// The display host's frame surface, as taken by the surfaceless-bind hook in MakeCurrent, and the
|
||||
// display it belongs to. glFlush reads these: a compositor's frame boundary is glFlush, and the
|
||||
// host frame's "frame is done" signal IS a swap of this surface. Null until a client marked
|
||||
// MOBILEGL_HOST_FRAME_CLIENT=1 actually took the frame.
|
||||
extern EGLDisplay g_hostFramePresentDisplay;
|
||||
extern EGLSurface g_hostFramePresentSurface;
|
||||
|
||||
EGLSurface CreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window,
|
||||
const EGLint* attrib_list);
|
||||
EGLBoolean SwapBuffers(EGLDisplay dpy, EGLSurface draw);
|
||||
@@ -63,10 +53,6 @@ namespace MobileGL::MG_Impl::EGLImpl {
|
||||
EGLBoolean GetSyncAttrib(EGLDisplay dpy, EGLSync sync, EGLint attribute, EGLAttrib* value);
|
||||
EGLImage CreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer,
|
||||
const EGLAttrib* attrib_list);
|
||||
// The same image under EGL_KHR_image_base's name and its EGLint attribute list: the two lists
|
||||
// are pairs of different widths, so the caller's array is re-spelled rather than cast.
|
||||
EGLImageKHR CreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer,
|
||||
const EGLint* attrib_list);
|
||||
EGLBoolean DestroyImage(EGLDisplay dpy, EGLImage image);
|
||||
EGLDisplay GetPlatformDisplay(EGLenum platform, void* native_display, const EGLAttrib* attrib_list);
|
||||
EGLSurface CreatePlatformWindowSurface(EGLDisplay dpy, EGLConfig config, void* native_window,
|
||||
|
||||
@@ -1,158 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Impl/EGLImpl/EGLPlatformExtensions.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace MobileGL::MG_Impl::EGLImpl {
|
||||
// THE PLATFORMS THIS IMPLEMENTATION SERVES, in the words EGL spells them.
|
||||
//
|
||||
// Two callers need exactly the same list, and they disagree if it is written twice:
|
||||
// eglQueryString(EGL_EXTENSIONS) is what an application reads BEFORE it decides to call
|
||||
// eglGetPlatformDisplay at all - libepoxy refuses to use eglGetPlatformDisplayEXT unless the
|
||||
// string names EGL_EXT_platform_base - and the glvnd vendor string is what the system's
|
||||
// libEGL reads to decide which vendor library a platform request should be routed to. A
|
||||
// vendor that does not claim the platform is never asked for it, and the caller is told there
|
||||
// is no provider: the library can be loaded, initialized, and still never called.
|
||||
//
|
||||
// GBM is on the list because a compositor asks for its display on the GBM device it owns.
|
||||
// This side treats that device the way it treats every other native display - the frames come
|
||||
// from the display host, not from the device - so the claim is exact rather than optimistic.
|
||||
inline constexpr const char* kDeviceExtensionString =
|
||||
"EGL_EXT_device_base "
|
||||
"EGL_EXT_device_enumeration "
|
||||
"EGL_EXT_device_query "
|
||||
"EGL_EXT_device_drm "
|
||||
"EGL_EXT_device_drm_render_node";
|
||||
|
||||
// EGL_EXT_client_extensions IS ON THE PLATFORM LIST FOR A MEASURED REASON. libglvnd only folds
|
||||
// a vendor client-extension string (the answer to eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS))
|
||||
// into its own no-display answer when the vendor PLATFORM string - the one __egl_Main publishes
|
||||
// for the platform-extensions query - names EGL_EXT_client_extensions. Without it the client
|
||||
// string never reached libepoxy, so libepoxy concluded EGL_EXT_device_query was absent and left
|
||||
// epoxy_eglQueryDisplayAttribEXT as a NULL pointer, while kwin (which reads the display string,
|
||||
// where the extension IS present) called it: measured as signal 11, fault_addr=(nil), pc=0x0,
|
||||
// from KWin::EglDisplay::determineRenderNode() through the GOT slot whose relocation is
|
||||
// R_AARCH64_GLOB_DAT epoxy_eglQueryDisplayAttribEXT.
|
||||
// Wayland where a Wayland client can exist (WaylandWindow.h: window surfaces presented through
|
||||
// wl_shm). Without it glvnd never hands this vendor a Wayland display at all.
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
#define MOBILEGL_PLATFORM_WAYLAND_EXTENSIONS " EGL_KHR_platform_wayland EGL_EXT_platform_wayland"
|
||||
#else
|
||||
#define MOBILEGL_PLATFORM_WAYLAND_EXTENSIONS ""
|
||||
#endif
|
||||
inline constexpr const char* kPlatformExtensionString =
|
||||
"EGL_EXT_client_extensions "
|
||||
"EGL_EXT_platform_base "
|
||||
"EGL_KHR_platform_base "
|
||||
"EGL_KHR_platform_gbm "
|
||||
"EGL_EXT_platform_gbm "
|
||||
"EGL_MESA_platform_gbm "
|
||||
"EGL_EXT_platform_device "
|
||||
"EGL_MESA_platform_surfaceless" MOBILEGL_PLATFORM_WAYLAND_EXTENSIONS;
|
||||
|
||||
// What a display answers for EGL_EXTENSIONS: the extensions this implementation provides that
|
||||
// are not platform ones, then the platform list above.
|
||||
// EGL_KHR_no_config_context and EGL_KHR_surfaceless_context are on the display and client lists
|
||||
// because both are answered by this implementation rather than announced by a driver: a context
|
||||
// is created with EGL_NO_CONFIG_KHR and made current with EGL_NO_SURFACE, which is the pair a
|
||||
// compositor asks for when it renders into framebuffers of its own. Measured on kwin_wayland
|
||||
// against this vendor before they were here: createContext() refused with
|
||||
// "EGL_KHR_no_config_context extension is unsupported" and the session ended at
|
||||
// "no usable DRM render device; cannot bring up OpenGL compositing".
|
||||
//
|
||||
// EGL_KHR_image_base AND EGL_EXT_image_dma_buf_import ARE ONE FEATURE HERE, and they are on the
|
||||
// list for a measured reason rather than a plausible one. In the Fedora container that runs
|
||||
// this library as the glvnd EGL vendor, eglGetProcAddress("eglCreateImageKHR") and
|
||||
// eglGetProcAddress("eglDestroyImageKHR") both returned NULL, and kwin_wayland 6.7.3's anland
|
||||
// backend imports the display daemon's dma-bufs through exactly those two
|
||||
// (AnlandEglLayer::importBuffers -> EglBackend::importDmaBufAsTexture ->
|
||||
// EglDisplay::importBufferAsImage -> EglDisplay::createImage) before it can draw a pixel into a
|
||||
// frame the daemon produced - so with a NULL the whole composited scene has no image to be
|
||||
// drawn into. Both names are backed by entry points that exist: EGL_KHR_image_base by
|
||||
// eglCreateImage/eglDestroyImage and their KHR spellings (Exporting/Definitions.cpp, and the
|
||||
// same names in the glvnd vendor table), EGL_EXT_image_dma_buf_import by EGL_LINUX_DMA_BUF_EXT
|
||||
// images, which carry the caller's EGL_WIDTH, EGL_HEIGHT and EGL_LINUX_DRM_FOURCC_EXT and own a
|
||||
// dup() of every plane's fd, offset and pitch (EGLState/Core.cpp, CreateImage).
|
||||
//
|
||||
// EGL_EXT_image_dma_buf_import_modifiers IS DELIBERATELY NOT NAMED. Its own two entry points -
|
||||
// eglQueryDmaBufFormatsEXT and eglQueryDmaBufModifiersEXT - do not exist in this library, and a
|
||||
// name in this string means the entry points beside it are there. The modifier attributes
|
||||
// (EGL_DMA_BUF_PLANEn_MODIFIER_LO/HI_EXT) are nevertheless ACCEPTED and carried on the image:
|
||||
// a caller does not need the name to send them, and kwin's does not look at any extension
|
||||
// string before it does - EglDisplay::importDmaBufAsImage appends the pair whenever the
|
||||
// buffer's modifier is not DRM_FORMAT_MOD_INVALID.
|
||||
inline constexpr const char* kDisplayExtensionString =
|
||||
"EGL_KHR_create_context "
|
||||
// WHAT THE COMPOSITOR CHECKS BETWEEN ITS CONTEXT AND ITS FIRST SURFACE. EglBackend::init
|
||||
// asks for these three by name right after initRenderingContext() and before createSurfaces();
|
||||
// the entry points behind them are published beside this string (Exporting/Definitions.cpp),
|
||||
// so the announcement and the answers are one thing rather than two.
|
||||
"EGL_KHR_fence_sync "
|
||||
"EGL_KHR_wait_sync "
|
||||
"EGL_KHR_swap_buffers_with_damage "
|
||||
"EGL_EXT_swap_buffers_with_damage "
|
||||
"EGL_EXT_buffer_age "
|
||||
"EGL_KHR_image_base "
|
||||
"EGL_EXT_image_dma_buf_import "
|
||||
"EGL_KHR_no_config_context "
|
||||
"EGL_KHR_surfaceless_context "
|
||||
// ANNOUNCED BECAUSE IT IS NOW ANSWERED: the four names below are published as real entry
|
||||
// points and eglGetProcAddress answers them (see Exporting/Definitions.cpp and
|
||||
// EGLImpl::GetProcAddress). Both earlier states were measured failures: announcing the
|
||||
// extension while the names resolved to NULL made kwin jump to that NULL (signal 11,
|
||||
// pc=0x0, from KWin::EglDisplay::determineRenderNode()), and withdrawing the announcement
|
||||
// left kwin without a render device so its compositing never became active and nothing was
|
||||
// ever painted.
|
||||
"EGL_EXT_device_base "
|
||||
"EGL_EXT_device_enumeration "
|
||||
"EGL_EXT_device_query "
|
||||
"EGL_EXT_device_drm "
|
||||
"EGL_EXT_device_drm_render_node "
|
||||
// KWin::EglDisplay::determineRenderNode() at libkwin.so.6+0x308b9c. A compositor that is
|
||||
// never told the extension exists cannot take that path; announcing it again is the right
|
||||
// move once these four names are really published and resolvable.
|
||||
"EGL_EXT_platform_device "
|
||||
"EGL_EXT_platform_base "
|
||||
"EGL_KHR_platform_base "
|
||||
"EGL_KHR_platform_gbm "
|
||||
"EGL_EXT_platform_gbm "
|
||||
"EGL_MESA_platform_gbm "
|
||||
"EGL_MESA_platform_surfaceless";
|
||||
|
||||
// ... and what EGL_NO_DISPLAY answers: the same, plus the client-extension marker that tells a
|
||||
// caller the no-display query is meaningful here.
|
||||
inline constexpr const char* kClientExtensionString =
|
||||
"EGL_EXT_client_extensions "
|
||||
"EGL_KHR_create_context "
|
||||
"EGL_KHR_image_base "
|
||||
"EGL_EXT_image_dma_buf_import "
|
||||
"EGL_KHR_no_config_context "
|
||||
"EGL_KHR_surfaceless_context "
|
||||
// ANNOUNCED BECAUSE IT IS NOW ANSWERED: the four names below are published as real entry
|
||||
// points and eglGetProcAddress answers them (see Exporting/Definitions.cpp and
|
||||
// EGLImpl::GetProcAddress). Both earlier states were measured failures: announcing the
|
||||
// extension while the names resolved to NULL made kwin jump to that NULL (signal 11,
|
||||
// pc=0x0, from KWin::EglDisplay::determineRenderNode()), and withdrawing the announcement
|
||||
// left kwin without a render device so its compositing never became active and nothing was
|
||||
// ever painted.
|
||||
"EGL_EXT_device_base "
|
||||
"EGL_EXT_device_enumeration "
|
||||
"EGL_EXT_device_query "
|
||||
"EGL_EXT_device_drm "
|
||||
"EGL_EXT_device_drm_render_node "
|
||||
// KWin::EglDisplay::determineRenderNode() at libkwin.so.6+0x308b9c. A compositor that is
|
||||
// never told the extension exists cannot take that path; announcing it again is the right
|
||||
// move once these four names are really published and resolvable.
|
||||
"EGL_EXT_platform_device "
|
||||
"EGL_EXT_platform_base "
|
||||
"EGL_KHR_platform_base "
|
||||
"EGL_KHR_platform_gbm "
|
||||
"EGL_EXT_platform_gbm "
|
||||
"EGL_MESA_platform_gbm "
|
||||
"EGL_MESA_platform_surfaceless";
|
||||
}
|
||||
@@ -7,9 +7,6 @@
|
||||
// End of Source File Header
|
||||
|
||||
#include <Includes.h>
|
||||
// EGLImageKHR, for the KHR spellings of the image entry points defined at the bottom of this file:
|
||||
// Includes.h brings in the core egl.h only.
|
||||
#include <EGL/eglext.h>
|
||||
#include "../EGLImpl.h"
|
||||
|
||||
MOBILEGL_EGL_API EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, NativeWindowType window,
|
||||
@@ -231,25 +228,6 @@ MOBILEGL_EGL_API EGLBoolean eglDestroyImage(EGLDisplay dpy, EGLImage image) {
|
||||
return MobileGL::MG_Impl::EGLImpl::DestroyImage(dpy, image);
|
||||
}
|
||||
|
||||
// EGL_KHR_image_base's spellings of the same two entry points, exported under their own names
|
||||
// because that is the only thing that answers for them: measured in the Fedora container that runs
|
||||
// this library as the glvnd EGL vendor, eglGetProcAddress("eglCreateImageKHR") and
|
||||
// eglGetProcAddress("eglDestroyImageKHR") both returned NULL, and kwin_wayland's anland backend
|
||||
// imports the display daemon's dma-bufs through exactly these two.
|
||||
MOBILEGL_EGL_API EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer,
|
||||
const EGLint* attrib_list) {
|
||||
MGLOG_D("eglCreateImageKHR(dpy=%p, ctx=%p, target=%u, buffer=%p, attrib_list=%p)", dpy, ctx, target, buffer,
|
||||
attrib_list);
|
||||
// Not an alias of eglCreateImage: this list is EGLint pairs and the core one EGLAttrib pairs.
|
||||
return MobileGL::MG_Impl::EGLImpl::CreateImageKHR(dpy, ctx, target, buffer, attrib_list);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image) {
|
||||
MGLOG_D("eglDestroyImageKHR(dpy=%p, image=%p)", dpy, image);
|
||||
// One handle under two spellings: EGLImageKHR and EGLImage are the same pointer.
|
||||
return MobileGL::MG_Impl::EGLImpl::DestroyImage(dpy, image);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLDisplay eglGetPlatformDisplay(EGLenum platform, void* native_display,
|
||||
const EGLAttrib* attrib_list) {
|
||||
MGLOG_D("eglGetPlatformDisplay(platform=%u, native_display=%p, attrib_list=%p)", platform, native_display,
|
||||
@@ -272,138 +250,6 @@ MOBILEGL_EGL_API EGLSurface eglCreatePlatformWindowSurface(EGLDisplay dpy, EGLCo
|
||||
return MobileGL::MG_Impl::EGLImpl::CreatePlatformWindowSurface(dpy, config, native_window, attrib_list);
|
||||
}
|
||||
|
||||
// THE SWAP-AND-SYNC FAMILY, which kwin asks for in EglBackend::init right after the rendering
|
||||
// context is up and BEFORE it creates any surface: EGL_KHR_fence_sync, EGL_KHR_swap_buffers_with_damage
|
||||
// and EGL_EXT_buffer_age are checked there, and a compositing mode whose backend init returns false
|
||||
// is exactly the "Could not fulfill the requested compositing mode in KWIN_COMPOSE: 1" this run
|
||||
// reports. Each of these names is a spelling of something this library already implements (the core
|
||||
// eglSwapBuffers and the state layer's sync objects), so they are published as real exports rather
|
||||
// than promised and not delivered.
|
||||
MOBILEGL_EGL_API EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface, const EGLint* rects,
|
||||
EGLint n_rects) {
|
||||
// The damage rectangles are a hint about what changed; this side swaps the whole surface either
|
||||
// way, so the honest answer is the core swap.
|
||||
(void)rects;
|
||||
(void)n_rects;
|
||||
return MobileGL::MG_Impl::EGLImpl::SwapBuffers(dpy, surface) ? EGL_TRUE : EGL_FALSE;
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface, const EGLint* rects,
|
||||
EGLint n_rects) {
|
||||
return eglSwapBuffersWithDamageKHR(dpy, surface, rects, n_rects);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint* attrib_list) {
|
||||
// EGL_KHR_fence_sync's list is EGLint pairs; the state layer takes EGLAttrib pairs.
|
||||
EGLAttrib attributes[16];
|
||||
int count = 0;
|
||||
if (attrib_list != nullptr) {
|
||||
for (int index = 0; attrib_list[index] != EGL_NONE && count + 1 < 16; index += 2) {
|
||||
attributes[count++] = static_cast<EGLAttrib>(attrib_list[index]);
|
||||
attributes[count++] = static_cast<EGLAttrib>(attrib_list[index + 1]);
|
||||
}
|
||||
}
|
||||
attributes[count] = EGL_NONE;
|
||||
return reinterpret_cast<EGLSyncKHR>(MobileGL::MG_Impl::EGLImpl::CreateSync(dpy, type, attributes));
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync) {
|
||||
return MobileGL::MG_Impl::EGLImpl::DestroySync(dpy, reinterpret_cast<EGLSync>(sync)) ? EGL_TRUE : EGL_FALSE;
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout) {
|
||||
return MobileGL::MG_Impl::EGLImpl::ClientWaitSync(dpy, reinterpret_cast<EGLSync>(sync), flags,
|
||||
static_cast<EGLTime>(timeout));
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags) {
|
||||
return MobileGL::MG_Impl::EGLImpl::WaitSync(dpy, reinterpret_cast<EGLSync>(sync), flags) ? EGL_TRUE : EGL_FALSE;
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint* value) {
|
||||
EGLAttrib answered = EGL_NONE;
|
||||
if (!MobileGL::MG_Impl::EGLImpl::GetSyncAttrib(dpy, reinterpret_cast<EGLSync>(sync), attribute, &answered)) {
|
||||
return EGL_FALSE;
|
||||
}
|
||||
if (value != nullptr) {
|
||||
*value = static_cast<EGLint>(answered);
|
||||
}
|
||||
return EGL_TRUE;
|
||||
}
|
||||
|
||||
// THE DEVICE-QUERY FAMILY, PUBLISHED AS REAL ENTRY POINTS. It is not academic: with the extension
|
||||
// announced but these names unresolvable, libepoxy leaves epoxy_eglQueryDisplayAttribEXT NULL and
|
||||
// kwin, trusting the announcement, jumps to it (measured: signal 11, fault_addr=(nil), pc=0x0 from
|
||||
// KWin::EglDisplay::determineRenderNode()); with the announcement withdrawn instead, kwin stops
|
||||
// asking and its compositing never becomes active (measured: org.kde.kwin.Compositing active =
|
||||
// false), so nothing is ever painted and the display daemon frames are never imported. Publishing
|
||||
// them is the only answer that leaves kwin both safe and able to find its render device.
|
||||
namespace {
|
||||
// One device, one identity - the same shape the vendor side uses (Exporting/GlvndVendor.cpp): a
|
||||
// pointer to a private object, so a device from somewhere else cannot compare equal by accident.
|
||||
struct DeviceToken { int unused; };
|
||||
DeviceToken g_deviceToken;
|
||||
} // namespace
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglQueryDevicesEXT(EGLint max_devices, EGLDeviceEXT* devices, EGLint* num_devices) {
|
||||
if (num_devices == nullptr) return EGL_FALSE;
|
||||
*num_devices = 1;
|
||||
if (devices != nullptr && max_devices >= 1) devices[0] = reinterpret_cast<EGLDeviceEXT>(&g_deviceToken);
|
||||
return EGL_TRUE;
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglQueryDeviceAttribEXT(EGLDeviceEXT device, EGLint attribute, EGLAttrib* value) {
|
||||
if (device != reinterpret_cast<EGLDeviceEXT>(&g_deviceToken) || value == nullptr) return EGL_FALSE;
|
||||
switch (attribute) {
|
||||
case EGL_DRM_DEVICE_FILE_EXT:
|
||||
case EGL_DRM_RENDER_NODE_FILE_EXT:
|
||||
*value = reinterpret_cast<EGLAttrib>("/dev/dri/renderD128");
|
||||
return EGL_TRUE;
|
||||
default:
|
||||
return EGL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API const char* eglQueryDeviceStringEXT(EGLDeviceEXT device, EGLint name) {
|
||||
if (device != reinterpret_cast<EGLDeviceEXT>(&g_deviceToken)) return nullptr;
|
||||
// THE NODE IS NAMED, AND THAT CHANGED BECAUSE THE MEASUREMENT CHANGED. An empty answer was the
|
||||
// right shape while this query was unreachable: nothing asked, so nothing depended on it. Now
|
||||
// that the name resolves, it is exactly what kwin asks on the way into its EGL backend, and the
|
||||
// fork says out loud what an empty answer costs it - "Error during init of AnlandEglBackend",
|
||||
// after which it falls back to the plain AnlandBackend, whose compositing never becomes active
|
||||
// (supportInformation: "LogicalOutput backend: KWin::AnlandBackend" + "Compositing is not
|
||||
// active"), so nothing is ever painted and the display daemon frames are never imported. The
|
||||
// path answered is the one the environment configures the compositor with (ANLAND_DRM_DEVICE),
|
||||
// so the node named here and the node in use are the same node.
|
||||
if (name == EGL_DRM_DEVICE_FILE_EXT || name == EGL_DRM_RENDER_NODE_FILE_EXT) {
|
||||
return "/dev/dri/renderD128";
|
||||
}
|
||||
if (name == EGL_EXTENSIONS) return "EGL_EXT_device_drm_render_node";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLBoolean eglQueryDisplayAttribEXT(EGLDisplay dpy, EGLint attribute, EGLAttrib* value) {
|
||||
(void)dpy;
|
||||
if (value == nullptr) return EGL_FALSE;
|
||||
if (attribute == EGL_DEVICE_EXT) {
|
||||
*value = reinterpret_cast<EGLAttrib>(&g_deviceToken);
|
||||
return EGL_TRUE;
|
||||
}
|
||||
return EGL_FALSE;
|
||||
}
|
||||
|
||||
// The EXT spellings of the platform surface entry points: EGL_EXT_platform_base defines them by those
|
||||
// names, and a dispatcher-based client resolves them by those names. Identical ABI (EGLAttrib list).
|
||||
MOBILEGL_EGL_API EGLSurface eglCreatePlatformWindowSurfaceEXT(EGLDisplay dpy, EGLConfig config, void* native_window,
|
||||
const EGLAttrib* attrib_list) {
|
||||
return eglCreatePlatformWindowSurface(dpy, config, native_window, attrib_list);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLSurface eglCreatePlatformPixmapSurfaceEXT(EGLDisplay dpy, EGLConfig config, void* native_pixmap,
|
||||
const EGLAttrib* attrib_list) {
|
||||
return eglCreatePlatformPixmapSurface(dpy, config, native_pixmap, attrib_list);
|
||||
}
|
||||
|
||||
MOBILEGL_EGL_API EGLSurface eglCreatePlatformPixmapSurface(EGLDisplay dpy, EGLConfig config, void* native_pixmap,
|
||||
const EGLAttrib* attrib_list) {
|
||||
MGLOG_D("eglCreatePlatformPixmapSurface(dpy=%p, config=%p, native_pixmap=%p, attrib_list=%p)", dpy, config,
|
||||
|
||||
@@ -1,395 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Impl/EGLImpl/Exporting/GlvndVendor.cpp
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
// MOBILEGL AS A GLVND EGL VENDOR.
|
||||
//
|
||||
// On a system with libglvnd, the libEGL.so.1 an application links is not an implementation at all:
|
||||
// it is a dispatcher, and the implementations are vendor libraries it loads from
|
||||
// /usr/share/glvnd/egl_vendor.d (or from whatever __EGL_VENDOR_LIBRARY_FILENAMES names) and routes
|
||||
// every EGL call to. That is the supported way to be the implementation an application actually
|
||||
// talks to, and on this machine it is the ONLY way that reaches a caller which does not link EGL
|
||||
// directly: kwin goes through libepoxy, which dlopen()s libEGL.so.1 and dlsyms its entry points at
|
||||
// startup, so a library injected with LD_PRELOAD is invisible to it however loudly it is named.
|
||||
//
|
||||
// What glvnd asks a vendor for is the other half of that ABI, and this file is it: glvnd calls
|
||||
// __egl_Main once, the library answers with the functions it wants dispatched to it, and - the part
|
||||
// that decides whether a compositor can use it at all - with the string naming the PLATFORMS it
|
||||
// serves. A vendor that does not claim EGL_PLATFORM_GBM_KHR is never asked for a GBM display, and
|
||||
// the caller that asked for one is told there is no usable device: the client sitting in its maps,
|
||||
// loaded and never called, is exactly what that looks like from the outside.
|
||||
//
|
||||
// The entry points below are this library's own (MG_Impl::EGLImpl, the same functions
|
||||
// Exporting/Definitions.cpp exports), so a vendor call and a direct call cannot drift apart.
|
||||
|
||||
#include <Includes.h>
|
||||
#include <glvnd/libeglabi.h>
|
||||
// EGLImageKHR, for the KHR spellings the entry-point table below answers: Includes.h brings in the
|
||||
// core egl.h only.
|
||||
#include <EGL/eglext.h>
|
||||
|
||||
#include "../EGLImpl.h"
|
||||
#include "../EGLPlatformExtensions.h"
|
||||
|
||||
// The KHR spellings of the image entry points, declared here because the bundled EGL headers
|
||||
// declare them only under EGL_EGLEXT_PROTOTYPES and because glvnd asks for entry points BY NAME -
|
||||
// the table below is where it finds this one.
|
||||
extern "C" EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer,
|
||||
const EGLint* attrib_list);
|
||||
extern "C" EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image);
|
||||
|
||||
// THE SWAP-AND-SYNC EXPORTS, declared here for the same reason the image pair is: they are defined in
|
||||
// Exporting/Definitions.cpp and this file only names them in the vendor table below.
|
||||
extern "C" EGLBoolean eglSwapBuffersWithDamageKHR(EGLDisplay dpy, EGLSurface surface, const EGLint* rects,
|
||||
EGLint n_rects);
|
||||
extern "C" EGLBoolean eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface, const EGLint* rects,
|
||||
EGLint n_rects);
|
||||
extern "C" EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint* attrib_list);
|
||||
extern "C" EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync);
|
||||
extern "C" EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout);
|
||||
extern "C" EGLBoolean eglWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags);
|
||||
extern "C" EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint* value);
|
||||
|
||||
namespace {
|
||||
using namespace MobileGL;
|
||||
|
||||
const __EGLapiExports* g_eglExports = nullptr;
|
||||
|
||||
// The platforms this vendor serves. GBM is the one that matters here: the compositor asks for
|
||||
// a display on the GBM device it opened, and a vendor that does not name the platform is not
|
||||
// asked at all. This side treats a GBM device as it treats every other native display - the
|
||||
// frames come from the display host, not from the device - so claiming the platform is honest
|
||||
// rather than optimistic.
|
||||
constexpr const char* kPlatformExtensions = MG_Impl::EGLImpl::kPlatformExtensionString;
|
||||
|
||||
// glvnd asks for the client-only extension list separately from the platform one; the split is
|
||||
// its own invention, and this side answers both from the same query.
|
||||
const char* EGLAPIENTRY VendorQueryString(EGLDisplay dpy, EGLint name) {
|
||||
return MG_Impl::EGLImpl::QueryString(dpy, name);
|
||||
}
|
||||
|
||||
EGLDisplay EGLAPIENTRY VendorGetPlatformDisplay(EGLenum platform, void* native_display,
|
||||
const EGLAttrib* attrib_list) {
|
||||
// EGL_NONE means the application called eglGetDisplay(EGL_DEFAULT_DISPLAY): the vendor is
|
||||
// being asked to name its own default display.
|
||||
if (platform == EGL_NONE) {
|
||||
return MG_Impl::EGLImpl::GetDisplay(EGL_DEFAULT_DISPLAY);
|
||||
}
|
||||
return MG_Impl::EGLImpl::GetPlatformDisplay(platform, native_display, attrib_list);
|
||||
}
|
||||
|
||||
EGLBoolean EGLAPIENTRY VendorGetSupportsAPI(EGLenum api) {
|
||||
// What this library answers for EGL_CLIENT_APIS, said as a question.
|
||||
return (api == EGL_OPENGL_ES_API || api == EGL_OPENGL_API) ? EGL_TRUE : EGL_FALSE;
|
||||
}
|
||||
|
||||
const char* EGLAPIENTRY VendorGetVendorString(int name) {
|
||||
if (name == __EGL_VENDOR_STRING_PLATFORM_EXTENSIONS) {
|
||||
return kPlatformExtensions;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// GLVND ASKS FOR EVERY EGL ENTRY POINT BY NAME, AND DROPS THE VENDOR IF ONE IS MISSING: the
|
||||
// first eight functions the table below names are looked up before this library is ever asked
|
||||
// for a display, and a single null answer means glvnd quietly stops considering it - the
|
||||
// library is loaded, __egl_Main has run, and nothing is ever dispatched to it.
|
||||
struct EntryPoint {
|
||||
const char* name;
|
||||
void* address;
|
||||
};
|
||||
|
||||
// ---- the device family -------------------------------------------------------------------
|
||||
//
|
||||
// A compositor does not ask for a display and hope. It asks which devices exist, reads the DRM
|
||||
// node off the one it wants, and only then asks for a display ON that device - so a vendor that
|
||||
// answers "no devices" is one it cannot use, however well the vendor draws. The message it
|
||||
// gives is "no usable DRM render device", which names where it stopped rather than why.
|
||||
//
|
||||
// This implementation therefore names one device: the render node of the machine it runs on.
|
||||
// That is an honest answer even though the frames do not come from that node - they come from
|
||||
// the display host on the other end of the socket, which is why every surface here is a host
|
||||
// frame - because the question is which device this display is associated with, and the answer
|
||||
// is what lets the compositor match its own node to the display it is about to draw into.
|
||||
const char* DrmRenderNode() {
|
||||
// MOBILEGL_DEVICE_DRM_NODE names another node: a machine with more than one GPU, or a test
|
||||
// that wants the mismatch refused rather than papered over.
|
||||
const char* configured = std::getenv("MOBILEGL_DEVICE_DRM_NODE");
|
||||
return (configured != nullptr && configured[0] != '\0') ? configured : "/dev/dri/renderD128";
|
||||
}
|
||||
|
||||
// One device, one identity. A pointer to a private object rather than a number, so that a
|
||||
// device from somewhere else cannot compare equal to this one by accident.
|
||||
struct DeviceToken { int unused; };
|
||||
DeviceToken g_deviceToken;
|
||||
|
||||
EGLBoolean EGLAPIENTRY VendorQueryDevicesEXT(EGLint max_devices, EGLDeviceEXT* devices, EGLint* num_devices) {
|
||||
if (num_devices == nullptr) {
|
||||
return EGL_FALSE;
|
||||
}
|
||||
*num_devices = 1;
|
||||
if (devices != nullptr && max_devices >= 1) {
|
||||
devices[0] = reinterpret_cast<EGLDeviceEXT>(&g_deviceToken);
|
||||
}
|
||||
return EGL_TRUE;
|
||||
}
|
||||
|
||||
EGLBoolean EGLAPIENTRY VendorQueryDeviceAttribEXT(EGLDeviceEXT device, EGLint attribute, EGLAttrib* value) {
|
||||
MGLOG_I("vendor eglQueryDeviceAttribEXT(device=%p, attribute=0x%04x)", static_cast<void*>(device),
|
||||
static_cast<unsigned>(attribute));
|
||||
if (device != reinterpret_cast<EGLDeviceEXT>(&g_deviceToken) || value == nullptr) {
|
||||
return EGL_FALSE;
|
||||
}
|
||||
switch (attribute) {
|
||||
case EGL_DRM_DEVICE_FILE_EXT:
|
||||
case EGL_DRM_RENDER_NODE_FILE_EXT:
|
||||
// THE ATTRIBUTE FORM OF THE SAME QUERY, and the last place the empty answer lived. kwin
|
||||
// asks for the node as an ATTRIBUTE as well as a string; with this one empty its log said
|
||||
// "couldn't find dev node for drm device" even after the string form was answered, and
|
||||
// the compositing mode it had just successfully started through this library was then
|
||||
// declared unfulfillable. The path is the environment's own (ANLAND_DRM_DEVICE).
|
||||
*value = reinterpret_cast<EGLAttrib>("/dev/dri/renderD128");
|
||||
return EGL_TRUE;
|
||||
default:
|
||||
return EGL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
const char* EGLAPIENTRY VendorQueryDeviceStringEXT(EGLDeviceEXT device, EGLint name) {
|
||||
// WHICH DEVICE QUERY THE COMPOSITOR MAKES, and by which name: the string form and the attribute
|
||||
// form are different entry points with different answers (glvnd answers the string form itself
|
||||
// and only forwards the attribute one), so the caller decides which of the two it gets.
|
||||
MGLOG_I("vendor eglQueryDeviceStringEXT(device=%p, name=0x%04x)", static_cast<void*>(device),
|
||||
static_cast<unsigned>(name));
|
||||
if (device != reinterpret_cast<EGLDeviceEXT>(&g_deviceToken)) {
|
||||
return nullptr;
|
||||
}
|
||||
// THE NODE IS NAMED HERE TOO, AND THAT IS WHAT THE VENDOR-SIDE ANSWER WAS MISSING. An empty
|
||||
// answer was measured to be harmless only while this query was unreachable; through glvnd it
|
||||
// IS the query a compositor makes before it opens anything, and an empty string is what its
|
||||
// next line reports - "Failed to open drm node : No such file or directory" (the name is the
|
||||
// blank between "node" and ":"), followed by "couldn't find dev node for drm device" and a
|
||||
// dead OpenGL compositing mode. The path is the one the environment configures the
|
||||
// compositor with (ANLAND_DRM_DEVICE), so the node named here and the node in use are one.
|
||||
if (name == EGL_DRM_DEVICE_FILE_EXT || name == EGL_DRM_RENDER_NODE_FILE_EXT) {
|
||||
return "/dev/dri/renderD128";
|
||||
}
|
||||
if (name == EGL_EXTENSIONS) {
|
||||
return "EGL_EXT_device_drm_render_node";
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
EGLBoolean EGLAPIENTRY VendorQueryDisplayAttribEXT(EGLDisplay dpy, EGLint attribute, EGLAttrib* value) {
|
||||
(void)dpy;
|
||||
if (value == nullptr) {
|
||||
return EGL_FALSE;
|
||||
}
|
||||
if (attribute == EGL_DEVICE_EXT) {
|
||||
*value = reinterpret_cast<EGLAttrib>(&g_deviceToken);
|
||||
return EGL_TRUE;
|
||||
}
|
||||
return EGL_FALSE;
|
||||
}
|
||||
|
||||
// Three of the names glvnd insists on are debug extensions this implementation does not
|
||||
// provide, and glvnd insists on them all the same - a vendor that answers null for any of them
|
||||
// is dropped. They are answered honestly rather than pretended: KHR_debug is not in the
|
||||
// extension strings above, so a caller that reads them will not call these at all.
|
||||
EGLint EGLAPIENTRY VendorDebugMessageControlKHR(EGLDEBUGPROCKHR callback, const EGLAttrib* attrib_list) {
|
||||
(void)callback;
|
||||
(void)attrib_list;
|
||||
return EGL_FALSE;
|
||||
}
|
||||
|
||||
EGLBoolean EGLAPIENTRY VendorQueryDebugKHR(EGLint attribute, EGLAttrib* value) {
|
||||
(void)attribute;
|
||||
(void)value;
|
||||
return EGL_FALSE;
|
||||
}
|
||||
|
||||
EGLint EGLAPIENTRY VendorLabelObjectKHR(EGLDisplay dpy, EGLenum objectType, EGLObjectKHR object, EGLLabelKHR label) {
|
||||
(void)dpy;
|
||||
(void)objectType;
|
||||
(void)object;
|
||||
(void)label;
|
||||
return EGL_BAD_PARAMETER;
|
||||
}
|
||||
|
||||
const EntryPoint kEglEntryPoints[] = {
|
||||
// The core of EGL 1.5, every one of which glvnd looks up by name before it considers this
|
||||
// library usable.
|
||||
{"eglInitialize", reinterpret_cast<void*>(eglInitialize)},
|
||||
{"eglChooseConfig", reinterpret_cast<void*>(eglChooseConfig)},
|
||||
{"eglCopyBuffers", reinterpret_cast<void*>(eglCopyBuffers)},
|
||||
{"eglCreateContext", reinterpret_cast<void*>(eglCreateContext)},
|
||||
{"eglCreatePbufferSurface", reinterpret_cast<void*>(eglCreatePbufferSurface)},
|
||||
{"eglCreatePixmapSurface", reinterpret_cast<void*>(eglCreatePixmapSurface)},
|
||||
{"eglCreateWindowSurface", reinterpret_cast<void*>(eglCreateWindowSurface)},
|
||||
{"eglDestroyContext", reinterpret_cast<void*>(eglDestroyContext)},
|
||||
{"eglDestroySurface", reinterpret_cast<void*>(eglDestroySurface)},
|
||||
{"eglGetConfigAttrib", reinterpret_cast<void*>(eglGetConfigAttrib)},
|
||||
{"eglGetConfigs", reinterpret_cast<void*>(eglGetConfigs)},
|
||||
{"eglMakeCurrent", reinterpret_cast<void*>(eglMakeCurrent)},
|
||||
{"eglQueryContext", reinterpret_cast<void*>(eglQueryContext)},
|
||||
{"eglQuerySurface", reinterpret_cast<void*>(eglQuerySurface)},
|
||||
{"eglSwapBuffers", reinterpret_cast<void*>(eglSwapBuffers)},
|
||||
{"eglTerminate", reinterpret_cast<void*>(eglTerminate)},
|
||||
{"eglWaitGL", reinterpret_cast<void*>(eglWaitGL)},
|
||||
{"eglWaitNative", reinterpret_cast<void*>(eglWaitNative)},
|
||||
{"eglBindTexImage", reinterpret_cast<void*>(eglBindTexImage)},
|
||||
{"eglReleaseTexImage", reinterpret_cast<void*>(eglReleaseTexImage)},
|
||||
{"eglSurfaceAttrib", reinterpret_cast<void*>(eglSurfaceAttrib)},
|
||||
{"eglSwapInterval", reinterpret_cast<void*>(eglSwapInterval)},
|
||||
{"eglBindAPI", reinterpret_cast<void*>(eglBindAPI)},
|
||||
{"eglCreatePbufferFromClientBuffer", reinterpret_cast<void*>(eglCreatePbufferFromClientBuffer)},
|
||||
{"eglReleaseThread", reinterpret_cast<void*>(eglReleaseThread)},
|
||||
{"eglWaitClient", reinterpret_cast<void*>(eglWaitClient)},
|
||||
{"eglGetError", reinterpret_cast<void*>(eglGetError)},
|
||||
{"eglCreateSync", reinterpret_cast<void*>(eglCreateSync)},
|
||||
{"eglDestroySync", reinterpret_cast<void*>(eglDestroySync)},
|
||||
{"eglClientWaitSync", reinterpret_cast<void*>(eglClientWaitSync)},
|
||||
{"eglGetSyncAttrib", reinterpret_cast<void*>(eglGetSyncAttrib)},
|
||||
{"eglWaitSync", reinterpret_cast<void*>(eglWaitSync)},
|
||||
{"eglCreateImage", reinterpret_cast<void*>(eglCreateImage)},
|
||||
{"eglDestroyImage", reinterpret_cast<void*>(eglDestroyImage)},
|
||||
// THE KHR SPELLINGS OF THOSE TWO, and they are entries rather than aliases because glvnd
|
||||
// resolves a name it does not know through this table alone. Measured in the Fedora
|
||||
// container that runs this library as the EGL vendor: with only the core pair here,
|
||||
// eglGetProcAddress("eglCreateImageKHR") and eglGetProcAddress("eglDestroyImageKHR") both
|
||||
// answered NULL, and kwin_wayland's anland backend reaches the display daemon's dma-bufs
|
||||
// through them (AnlandEglLayer::importBuffers -> EglBackend::importDmaBufAsTexture ->
|
||||
// EglDisplay::importBufferAsImage) - so the compositor had no entry point to import a frame
|
||||
// with. eglCreateImageKHR is not the same ABI as eglCreateImage: EGL_KHR_image_base's
|
||||
// attribute list is EGLint pairs, which is why Exporting/Definitions.cpp exports it as its
|
||||
// own function rather than letting the core spelling stand in for it.
|
||||
{"eglCreateImageKHR", reinterpret_cast<void*>(eglCreateImageKHR)},
|
||||
{"eglDestroyImageKHR", reinterpret_cast<void*>(eglDestroyImageKHR)},
|
||||
{"eglCreatePlatformWindowSurface", reinterpret_cast<void*>(eglCreatePlatformWindowSurface)},
|
||||
{"eglCreatePlatformPixmapSurface", reinterpret_cast<void*>(eglCreatePlatformPixmapSurface)},
|
||||
// EGL_EXT_platform_base's OWN SPELLINGS, and the reason this file exists at all: the vendor
|
||||
// string below advertises that extension, whose entry points ARE the EXT-named ones, and a
|
||||
// dispatcher-based client resolves them by exactly those names (libepoxy in kwin does). With
|
||||
// only the core spellings in this table the lookup answered NULL and the caller - which had
|
||||
// already checked the extension string and so had every reason to trust it - jumped to it:
|
||||
// measured as signal 11 with fault_addr=(nil) and pc=0x0 immediately after "MobileGL
|
||||
// initialized", in both the systemd and the direct run, and it is what kept the compositor
|
||||
// from ever reaching its output. The ABI is identical (an EGLAttrib list, not EGLint pairs),
|
||||
// so the core implementation is what serves them.
|
||||
{"eglCreatePlatformWindowSurfaceEXT", reinterpret_cast<void*>(eglCreatePlatformWindowSurface)},
|
||||
{"eglCreatePlatformPixmapSurfaceEXT", reinterpret_cast<void*>(eglCreatePlatformPixmapSurface)},
|
||||
// The platform and current-state queries: not in glvnd's required list, but the names an
|
||||
// application that talks to a vendor through a dispatcher will ask for by name.
|
||||
{"eglGetDisplay", reinterpret_cast<void*>(eglGetDisplay)},
|
||||
{"eglGetCurrentDisplay", reinterpret_cast<void*>(eglGetCurrentDisplay)},
|
||||
{"eglGetCurrentSurface", reinterpret_cast<void*>(eglGetCurrentSurface)},
|
||||
{"eglGetCurrentContext", reinterpret_cast<void*>(eglGetCurrentContext)},
|
||||
{"eglQueryAPI", reinterpret_cast<void*>(eglQueryAPI)},
|
||||
{"eglGetProcAddress", reinterpret_cast<void*>(eglGetProcAddress)},
|
||||
// The two queries whose answer depends on which side of glvnd is asking.
|
||||
{"eglQueryString", reinterpret_cast<void*>(VendorQueryString)},
|
||||
{"eglGetPlatformDisplay", reinterpret_cast<void*>(VendorGetPlatformDisplay)},
|
||||
{"eglGetPlatformDisplayEXT", reinterpret_cast<void*>(VendorGetPlatformDisplay)},
|
||||
// What glvnd requires and this implementation does not otherwise have.
|
||||
{"eglQueryDevicesEXT", reinterpret_cast<void*>(VendorQueryDevicesEXT)},
|
||||
{"eglQueryDeviceAttribEXT", reinterpret_cast<void*>(VendorQueryDeviceAttribEXT)},
|
||||
{"eglQueryDeviceStringEXT", reinterpret_cast<void*>(VendorQueryDeviceStringEXT)},
|
||||
{"eglQueryDisplayAttribEXT", reinterpret_cast<void*>(VendorQueryDisplayAttribEXT)},
|
||||
// The swap-and-sync family, published through the same table the names are answered from.
|
||||
// Declared above this table because they are exports of Definitions.cpp, like the image pair.
|
||||
{"eglSwapBuffersWithDamageKHR", reinterpret_cast<void*>(eglSwapBuffersWithDamageKHR)},
|
||||
{"eglSwapBuffersWithDamageEXT", reinterpret_cast<void*>(eglSwapBuffersWithDamageEXT)},
|
||||
{"eglCreateSyncKHR", reinterpret_cast<void*>(eglCreateSyncKHR)},
|
||||
{"eglDestroySyncKHR", reinterpret_cast<void*>(eglDestroySyncKHR)},
|
||||
{"eglClientWaitSyncKHR", reinterpret_cast<void*>(eglClientWaitSyncKHR)},
|
||||
{"eglWaitSyncKHR", reinterpret_cast<void*>(eglWaitSyncKHR)},
|
||||
{"eglGetSyncAttribKHR", reinterpret_cast<void*>(eglGetSyncAttribKHR)},
|
||||
{"eglDebugMessageControlKHR", reinterpret_cast<void*>(VendorDebugMessageControlKHR)},
|
||||
{"eglQueryDebugKHR", reinterpret_cast<void*>(VendorQueryDebugKHR)},
|
||||
{"eglLabelObjectKHR", reinterpret_cast<void*>(VendorLabelObjectKHR)},
|
||||
};
|
||||
|
||||
// THE SAME ANSWER TO BOTH OF GLVND'S QUESTIONS, and that is not a shortcut - glvnd asks them
|
||||
// from two places and a library that answers one of them has a hole the size of the other:
|
||||
//
|
||||
// getProcAddress is asked for every entry point glvnd builds its own static EGL table
|
||||
// from, so a null here drops the vendor outright.
|
||||
// getDispatchAddress is what glvnd falls back to for eglGetProcAddress on any name it does
|
||||
// not know itself - which is every extension entry point that is not in
|
||||
// its list, the device queries among them. A vendor that answers these
|
||||
// from a GL-only table hands the application a null for a function the
|
||||
// vendor implements, and the caller reports the extension as missing.
|
||||
void* LookupEntryPoint(const char* procName) {
|
||||
if (procName == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
for (const EntryPoint& entry : kEglEntryPoints) {
|
||||
if (std::strcmp(entry.name, procName) == 0) {
|
||||
return entry.address;
|
||||
}
|
||||
}
|
||||
// Anything that is not EGL is a GL or GLES entry point, and the tree's own resolver is the
|
||||
// table for those.
|
||||
return reinterpret_cast<void*>(MG_Impl::EGLImpl::GetProcAddress(procName));
|
||||
}
|
||||
|
||||
void* EGLAPIENTRY VendorGetProcAddress(const char* procName) { return LookupEntryPoint(procName); }
|
||||
|
||||
// glvnd hands a vendor the index each EGL entry point occupies in its dispatch table, so that a
|
||||
// vendor whose entry points are thin wrappers around glvnd can call back into the right slot.
|
||||
// This library's entry points ARE the implementation - they never re-enter glvnd - so there is
|
||||
// nothing to record; the callback exists because glvnd refuses a vendor that does not provide
|
||||
// one, and refusing it means the library is loaded and never dispatched to.
|
||||
void EGLAPIENTRY VendorSetDispatchIndex(const char* procName, int index) {
|
||||
(void)procName;
|
||||
(void)index;
|
||||
}
|
||||
|
||||
void* EGLAPIENTRY VendorGetDispatchAddress(const char* procName) {
|
||||
// glvnd asks THIS vendor for GL entry points as well: after eglMakeCurrent, the dispatch
|
||||
// table of the now-current context is filled from here, one name at a time. LookupEntryPoint
|
||||
// knows EGL names only, so every GL name (glGetString, glCreateProgram, ...) answered NULL,
|
||||
// glvnd wrote NULL into its dispatch slots, and the first glGetString of the compositor's
|
||||
// context came back NULL - kwin's "Could not initialize rendering context", while the very
|
||||
// same context answered fine through a direct eglGetProcAddress (measured: probe6 vs probe12).
|
||||
// GL names go through the full GL/EGL lookup, which is the same table eglGetProcAddress uses.
|
||||
if (void* address = LookupEntryPoint(procName)) {
|
||||
return address;
|
||||
}
|
||||
return reinterpret_cast<void*>(MG_Impl::EGLImpl::GetProcAddress(procName));
|
||||
}
|
||||
} // namespace
|
||||
|
||||
extern "C" MOBILEGL_EGL_API EGLBoolean __egl_Main(uint32_t version, const __EGLapiExports* exports,
|
||||
__EGLvendorInfo* vendor, __EGLapiImports* imports) {
|
||||
(void)vendor;
|
||||
if (EGL_VENDOR_ABI_GET_MAJOR_VERSION(version) != EGL_VENDOR_ABI_MAJOR_VERSION) {
|
||||
// A vendor that does not know the ABI it is being handed must say so, not guess: the
|
||||
// structures on either side are the ABI.
|
||||
MGLOG_E("__egl_Main: unsupported glvnd vendor ABI version 0x%08x (this library implements %u.%u)", version,
|
||||
static_cast<unsigned>(EGL_VENDOR_ABI_MAJOR_VERSION),
|
||||
static_cast<unsigned>(EGL_VENDOR_ABI_MINOR_VERSION));
|
||||
return EGL_FALSE;
|
||||
}
|
||||
if (exports == nullptr || imports == nullptr) {
|
||||
MGLOG_E("__egl_Main: glvnd handed no exports/imports table");
|
||||
return EGL_FALSE;
|
||||
}
|
||||
g_eglExports = exports;
|
||||
|
||||
imports->getPlatformDisplay = VendorGetPlatformDisplay;
|
||||
imports->getSupportsAPI = VendorGetSupportsAPI;
|
||||
imports->getVendorString = VendorGetVendorString;
|
||||
imports->getProcAddress = VendorGetProcAddress;
|
||||
imports->getDispatchAddress = VendorGetDispatchAddress;
|
||||
imports->setDispatchIndex = VendorSetDispatchIndex;
|
||||
|
||||
MGLOG_I("glvnd vendor: MobileGL is serving EGL through libglvnd (ABI %u.%u, platforms: %s)",
|
||||
static_cast<unsigned>(EGL_VENDOR_ABI_MAJOR_VERSION), static_cast<unsigned>(EGL_VENDOR_ABI_MINOR_VERSION),
|
||||
kPlatformExtensions);
|
||||
return EGL_TRUE;
|
||||
}
|
||||
@@ -1,398 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Impl/EGLImpl/WaylandWindow.cpp
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#include "WaylandWindow.h"
|
||||
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
|
||||
#include <MG_Impl/GLImpl/Buffer/GL_Buffer.h>
|
||||
#include <MG_Impl/GLImpl/Framebuffer/GL_Framebuffer.h>
|
||||
#include <MG_Impl/GLImpl/Getter/GL_Getter.h>
|
||||
#include <MG_Impl/GLImpl/RenderState/GL_RenderState.h>
|
||||
#include <MG_Util/Debug/Log.h>
|
||||
#include <cerrno>
|
||||
#include <cstdarg>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <dlfcn.h>
|
||||
#include <fcntl.h>
|
||||
#include <mutex>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace MobileGL::MG_Impl::EGLImpl::Wayland {
|
||||
namespace {
|
||||
// libwayland-client's types are opaque here: everything goes through wl_proxy_* and the
|
||||
// exported interface descriptions, and nothing reads a field of either.
|
||||
struct wl_proxy;
|
||||
struct wl_interface;
|
||||
struct wl_event_queue;
|
||||
|
||||
// wayland-egl-backend.h, WL_EGL_WINDOW_VERSION 3: the struct libwayland-egl allocates for
|
||||
// wl_egl_window_create and the driver reads. The ABI is versioned by its first word.
|
||||
struct EglWindow {
|
||||
const intptr_t version;
|
||||
int width;
|
||||
int height;
|
||||
int dx;
|
||||
int dy;
|
||||
int attached_width;
|
||||
int attached_height;
|
||||
void* driver_private;
|
||||
void (*resize_callback)(EglWindow*, void*);
|
||||
void (*destroy_window_callback)(void*);
|
||||
wl_proxy* surface;
|
||||
};
|
||||
constexpr intptr_t kEglWindowVersion = 3;
|
||||
|
||||
// Request opcodes (wayland.xml, the order the requests are declared in).
|
||||
constexpr uint32_t kDisplayGetRegistry = 1;
|
||||
constexpr uint32_t kRegistryBind = 0;
|
||||
constexpr uint32_t kShmCreatePool = 0;
|
||||
constexpr uint32_t kShmPoolCreateBuffer = 0;
|
||||
constexpr uint32_t kShmPoolDestroy = 1;
|
||||
constexpr uint32_t kBufferDestroy = 0;
|
||||
constexpr uint32_t kSurfaceAttach = 1;
|
||||
constexpr uint32_t kSurfaceDamage = 2;
|
||||
constexpr uint32_t kSurfaceCommit = 6;
|
||||
constexpr uint32_t kSurfaceDamageBuffer = 9; // since wl_surface version 4
|
||||
constexpr uint32_t kMarshalFlagDestroy = 1u << 0;
|
||||
// wl_shm formats. The two every compositor must support; byte order in memory is
|
||||
// B, G, R, A for both (little-endian 0xAARRGGBB).
|
||||
constexpr uint32_t kShmFormatArgb8888 = 0;
|
||||
constexpr uint32_t kShmFormatXrgb8888 = 1;
|
||||
|
||||
struct Api {
|
||||
Bool loaded = false;
|
||||
const wl_interface* displayInterface = nullptr;
|
||||
const wl_interface* registryInterface = nullptr;
|
||||
const wl_interface* shmInterface = nullptr;
|
||||
const wl_interface* shmPoolInterface = nullptr;
|
||||
const wl_interface* bufferInterface = nullptr;
|
||||
wl_proxy* (*marshalFlags)(wl_proxy*, uint32_t, const wl_interface*, uint32_t, uint32_t, ...) = nullptr;
|
||||
int (*addListener)(wl_proxy*, void (**)(void), void*) = nullptr;
|
||||
void (*destroy)(wl_proxy*) = nullptr;
|
||||
uint32_t (*getVersion)(wl_proxy*) = nullptr;
|
||||
void* (*createWrapper)(void*) = nullptr;
|
||||
void (*wrapperDestroy)(void*) = nullptr;
|
||||
void (*setQueue)(wl_proxy*, wl_event_queue*) = nullptr;
|
||||
wl_event_queue* (*createQueue)(void*) = nullptr;
|
||||
void (*queueDestroy)(wl_event_queue*) = nullptr;
|
||||
int (*roundtripQueue)(void*, wl_event_queue*) = nullptr;
|
||||
int (*dispatchQueue)(void*, wl_event_queue*) = nullptr;
|
||||
int (*dispatchQueuePending)(void*, wl_event_queue*) = nullptr;
|
||||
int (*flush)(void*) = nullptr;
|
||||
};
|
||||
|
||||
// Loaded once. RTLD_NOLOAD first: a Wayland client has the library already, and the copy
|
||||
// it is using is the one whose wl_display this must talk to.
|
||||
const Api& WaylandApi() {
|
||||
static Api api;
|
||||
static std::once_flag once;
|
||||
std::call_once(once, [] {
|
||||
void* lib = dlopen("libwayland-client.so.0", RTLD_NOW | RTLD_NOLOAD);
|
||||
if (lib == nullptr) lib = dlopen("libwayland-client.so.0", RTLD_NOW);
|
||||
if (lib == nullptr) return;
|
||||
const auto sym = [lib](const char* name) { return dlsym(lib, name); };
|
||||
api.displayInterface = static_cast<const wl_interface*>(sym("wl_display_interface"));
|
||||
api.registryInterface = static_cast<const wl_interface*>(sym("wl_registry_interface"));
|
||||
api.shmInterface = static_cast<const wl_interface*>(sym("wl_shm_interface"));
|
||||
api.shmPoolInterface = static_cast<const wl_interface*>(sym("wl_shm_pool_interface"));
|
||||
api.bufferInterface = static_cast<const wl_interface*>(sym("wl_buffer_interface"));
|
||||
api.marshalFlags = reinterpret_cast<decltype(api.marshalFlags)>(sym("wl_proxy_marshal_flags"));
|
||||
api.addListener = reinterpret_cast<decltype(api.addListener)>(sym("wl_proxy_add_listener"));
|
||||
api.destroy = reinterpret_cast<decltype(api.destroy)>(sym("wl_proxy_destroy"));
|
||||
api.getVersion = reinterpret_cast<decltype(api.getVersion)>(sym("wl_proxy_get_version"));
|
||||
api.createWrapper = reinterpret_cast<decltype(api.createWrapper)>(sym("wl_proxy_create_wrapper"));
|
||||
api.wrapperDestroy = reinterpret_cast<decltype(api.wrapperDestroy)>(sym("wl_proxy_wrapper_destroy"));
|
||||
api.setQueue = reinterpret_cast<decltype(api.setQueue)>(sym("wl_proxy_set_queue"));
|
||||
api.createQueue = reinterpret_cast<decltype(api.createQueue)>(sym("wl_display_create_queue"));
|
||||
api.queueDestroy = reinterpret_cast<decltype(api.queueDestroy)>(sym("wl_event_queue_destroy"));
|
||||
api.roundtripQueue = reinterpret_cast<decltype(api.roundtripQueue)>(sym("wl_display_roundtrip_queue"));
|
||||
api.dispatchQueue = reinterpret_cast<decltype(api.dispatchQueue)>(sym("wl_display_dispatch_queue"));
|
||||
api.dispatchQueuePending =
|
||||
reinterpret_cast<decltype(api.dispatchQueuePending)>(sym("wl_display_dispatch_queue_pending"));
|
||||
api.flush = reinterpret_cast<decltype(api.flush)>(sym("wl_display_flush"));
|
||||
api.loaded = api.displayInterface && api.registryInterface && api.shmInterface &&
|
||||
api.shmPoolInterface && api.bufferInterface && api.marshalFlags && api.addListener && api.destroy &&
|
||||
api.getVersion && api.createWrapper && api.wrapperDestroy && api.setQueue &&
|
||||
api.createQueue && api.queueDestroy && api.roundtripQueue && api.dispatchQueue &&
|
||||
api.dispatchQueuePending && api.flush;
|
||||
if (!api.loaded) MGLOG_E("Wayland: libwayland-client.so.0 lacks an entry point this library uses");
|
||||
});
|
||||
return api;
|
||||
}
|
||||
|
||||
struct ShmBuffer {
|
||||
wl_proxy* buffer = nullptr;
|
||||
void* map = nullptr;
|
||||
SizeT size = 0;
|
||||
EGLint width = 0;
|
||||
EGLint height = 0;
|
||||
EGLint stride = 0;
|
||||
Bool busy = false;
|
||||
};
|
||||
|
||||
// The compositor is done with a buffer: it may be drawn into again.
|
||||
void OnBufferRelease(void* data, wl_proxy*) { static_cast<ShmBuffer*>(data)->busy = false; }
|
||||
void (*const kBufferListener[])(void) = {reinterpret_cast<void (*)(void)>(&OnBufferRelease)};
|
||||
} // namespace
|
||||
|
||||
struct WindowSurface::Impl {
|
||||
void* display = nullptr;
|
||||
EglWindow* window = nullptr;
|
||||
wl_event_queue* queue = nullptr;
|
||||
void* displayWrapper = nullptr;
|
||||
wl_proxy* registry = nullptr;
|
||||
wl_proxy* shm = nullptr;
|
||||
uint32_t format = kShmFormatXrgb8888;
|
||||
EGLint width = 0;
|
||||
EGLint height = 0;
|
||||
// Three: one on the glass, one the compositor may still be reading, one to draw into.
|
||||
ShmBuffer buffers[3];
|
||||
Vector<Uint8> scratch;
|
||||
|
||||
~Impl() {
|
||||
const Api& api = WaylandApi();
|
||||
for (auto& buffer : buffers) Release(buffer);
|
||||
// Neither wl_shm (version 1) nor wl_registry has a destroy request: the proxies go
|
||||
// on this side only.
|
||||
if (shm) api.destroy(shm);
|
||||
if (registry) api.destroy(registry);
|
||||
if (displayWrapper) api.wrapperDestroy(displayWrapper);
|
||||
if (queue) api.queueDestroy(queue);
|
||||
if (window && window->driver_private == this) {
|
||||
window->driver_private = nullptr;
|
||||
window->destroy_window_callback = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Release(ShmBuffer& buffer) {
|
||||
const Api& api = WaylandApi();
|
||||
if (buffer.buffer) api.marshalFlags(buffer.buffer, kBufferDestroy, nullptr, api.getVersion(buffer.buffer),
|
||||
kMarshalFlagDestroy);
|
||||
if (buffer.map) munmap(buffer.map, buffer.size);
|
||||
buffer = ShmBuffer{};
|
||||
}
|
||||
|
||||
Bool Allocate(ShmBuffer& buffer) {
|
||||
const Api& api = WaylandApi();
|
||||
Release(buffer);
|
||||
const EGLint stride = width * 4;
|
||||
const SizeT size = static_cast<SizeT>(stride) * static_cast<SizeT>(height);
|
||||
const int fd = memfd_create("mobilegl-wayland", MFD_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
MGLOG_E("Wayland: memfd_create for a %dx%d buffer failed: %s", width, height, std::strerror(errno));
|
||||
return false;
|
||||
}
|
||||
if (ftruncate(fd, static_cast<off_t>(size)) != 0) {
|
||||
MGLOG_E("Wayland: sizing a %dx%d buffer failed: %s", width, height, std::strerror(errno));
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
void* map = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (map == MAP_FAILED) {
|
||||
MGLOG_E("Wayland: mapping a %dx%d buffer failed: %s", width, height, std::strerror(errno));
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
// One pool per buffer, destroyed at once: the buffer keeps the memory alive.
|
||||
wl_proxy* pool = api.marshalFlags(shm, kShmCreatePool, api.shmPoolInterface, api.getVersion(shm), 0, nullptr,
|
||||
fd, static_cast<int32_t>(size));
|
||||
close(fd);
|
||||
if (pool == nullptr) {
|
||||
munmap(map, size);
|
||||
return false;
|
||||
}
|
||||
wl_proxy* wlBuffer = api.marshalFlags(pool, kShmPoolCreateBuffer, api.bufferInterface, api.getVersion(pool),
|
||||
0, nullptr, 0, width, height, stride, format);
|
||||
api.marshalFlags(pool, kShmPoolDestroy, nullptr, api.getVersion(pool), kMarshalFlagDestroy);
|
||||
if (wlBuffer == nullptr) {
|
||||
munmap(map, size);
|
||||
return false;
|
||||
}
|
||||
buffer.buffer = wlBuffer;
|
||||
buffer.map = map;
|
||||
buffer.size = size;
|
||||
buffer.width = width;
|
||||
buffer.height = height;
|
||||
buffer.stride = stride;
|
||||
buffer.busy = false;
|
||||
api.addListener(wlBuffer, const_cast<void (**)(void)>(kBufferListener), &buffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
// A buffer the compositor is not reading: the events already received first, then (all
|
||||
// three still held) a blocking wait for the next release.
|
||||
ShmBuffer* NextFree() {
|
||||
const Api& api = WaylandApi();
|
||||
for (;;) {
|
||||
if (api.dispatchQueuePending(display, queue) < 0) return nullptr;
|
||||
for (auto& buffer : buffers) {
|
||||
if (buffer.buffer == nullptr || buffer.busy) continue;
|
||||
if (buffer.width != width || buffer.height != height) {
|
||||
if (!Allocate(buffer)) return nullptr;
|
||||
}
|
||||
return &buffer;
|
||||
}
|
||||
for (auto& buffer : buffers) {
|
||||
if (buffer.buffer == nullptr) return Allocate(buffer) ? &buffer : nullptr;
|
||||
}
|
||||
if (api.dispatchQueue(display, queue) < 0) return nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
namespace {
|
||||
void OnRegistryGlobal(void* data, wl_proxy* registry, uint32_t name, const char* interface, uint32_t) {
|
||||
auto* impl = static_cast<WindowSurface::Impl*>(data);
|
||||
if (impl->shm != nullptr || std::strcmp(interface, "wl_shm") != 0) return;
|
||||
const Api& api = WaylandApi();
|
||||
impl->shm = api.marshalFlags(registry, kRegistryBind, api.shmInterface, 1, 0, name, "wl_shm", 1u, nullptr);
|
||||
}
|
||||
void OnRegistryGlobalRemove(void*, wl_proxy*, uint32_t) {}
|
||||
void (*const kRegistryListener[])(void) = {reinterpret_cast<void (*)(void)>(&OnRegistryGlobal),
|
||||
reinterpret_cast<void (*)(void)>(&OnRegistryGlobalRemove)};
|
||||
|
||||
// The application destroyed its wl_egl_window first: nothing may be read from it after this.
|
||||
void OnWindowDestroyed(void* data) { static_cast<WindowSurface::Impl*>(data)->window = nullptr; }
|
||||
} // namespace
|
||||
|
||||
Bool IsWaylandDisplay(Uint64 nativeDisplay, EGLenum platform) {
|
||||
if (platform == kPlatformWayland) return true;
|
||||
if (nativeDisplay == 0 || (platform != EGL_NONE && platform != 0)) return false;
|
||||
const Api& api = WaylandApi();
|
||||
if (!api.loaded) return false;
|
||||
return *reinterpret_cast<const void* const*>(static_cast<uintptr_t>(nativeDisplay)) == api.displayInterface;
|
||||
}
|
||||
|
||||
Bool IsWaylandWindow(const void* window) {
|
||||
if (window == nullptr) return false;
|
||||
const auto* eglWindow = static_cast<const EglWindow*>(window);
|
||||
return eglWindow->version >= kEglWindowVersion && eglWindow->surface != nullptr;
|
||||
}
|
||||
|
||||
Bool WindowSize(const void* window, EGLint* width, EGLint* height) {
|
||||
if (!IsWaylandWindow(window)) return false;
|
||||
const auto* eglWindow = static_cast<const EglWindow*>(window);
|
||||
*width = eglWindow->width;
|
||||
*height = eglWindow->height;
|
||||
return eglWindow->width > 0 && eglWindow->height > 0;
|
||||
}
|
||||
|
||||
WindowSurface::WindowSurface(UniquePtr<Impl> impl) : m_impl(std::move(impl)) {}
|
||||
WindowSurface::~WindowSurface() = default;
|
||||
|
||||
UniquePtr<WindowSurface> WindowSurface::Create(void* wlDisplay, void* wlEglWindow, EGLint width, EGLint height,
|
||||
Bool hasAlpha) {
|
||||
const Api& api = WaylandApi();
|
||||
if (!api.loaded) {
|
||||
MGLOG_E("Wayland: a window surface needs libwayland-client.so.0, and it could not be used");
|
||||
return nullptr;
|
||||
}
|
||||
if (wlDisplay == nullptr || !IsWaylandWindow(wlEglWindow) || width <= 0 || height <= 0) return nullptr;
|
||||
auto impl = MakeUnique<Impl>();
|
||||
impl->display = wlDisplay;
|
||||
impl->window = static_cast<EglWindow*>(wlEglWindow);
|
||||
impl->width = width;
|
||||
impl->height = height;
|
||||
impl->format = hasAlpha ? kShmFormatArgb8888 : kShmFormatXrgb8888;
|
||||
// A queue of this surface's own, so the application's dispatching never sees these events
|
||||
// and this never dispatches the application's.
|
||||
impl->queue = api.createQueue(wlDisplay);
|
||||
impl->displayWrapper = api.createWrapper(wlDisplay);
|
||||
if (impl->queue == nullptr || impl->displayWrapper == nullptr) return nullptr;
|
||||
api.setQueue(static_cast<wl_proxy*>(impl->displayWrapper), impl->queue);
|
||||
auto* wrapper = static_cast<wl_proxy*>(impl->displayWrapper);
|
||||
impl->registry = api.marshalFlags(wrapper, kDisplayGetRegistry, api.registryInterface, api.getVersion(wrapper),
|
||||
0, nullptr);
|
||||
if (impl->registry == nullptr) return nullptr;
|
||||
api.addListener(impl->registry, const_cast<void (**)(void)>(kRegistryListener), impl.get());
|
||||
if (api.roundtripQueue(wlDisplay, impl->queue) < 0 || impl->shm == nullptr) {
|
||||
MGLOG_E("Wayland: the compositor offers no wl_shm; a window surface cannot be presented");
|
||||
return nullptr;
|
||||
}
|
||||
impl->window->driver_private = impl.get();
|
||||
impl->window->destroy_window_callback = &OnWindowDestroyed;
|
||||
MGLOG_I("Wayland: window surface %dx%d presented through wl_shm (%s)", width, height,
|
||||
hasAlpha ? "ARGB8888" : "XRGB8888");
|
||||
return UniquePtr<WindowSurface>(new WindowSurface(std::move(impl)));
|
||||
}
|
||||
|
||||
Bool WindowSurface::Present() {
|
||||
Impl& impl = *m_impl;
|
||||
if (impl.window == nullptr) return false;
|
||||
const Api& api = WaylandApi();
|
||||
ShmBuffer* buffer = impl.NextFree();
|
||||
if (buffer == nullptr) {
|
||||
MGLOG_E_ONCE("Wayland: no wl_shm buffer could be taken for the frame; it is not shown");
|
||||
return false;
|
||||
}
|
||||
|
||||
// The frame, out of the default framebuffer, through this library's own entry points: the
|
||||
// application's read framebuffer, pack buffer and pack state are saved and put back, so
|
||||
// the readback is invisible to it.
|
||||
namespace GL = MG_Impl::GLImpl;
|
||||
GLint readFramebuffer = 0, packBuffer = 0, alignment = 4, rowLength = 0, skipRows = 0, skipPixels = 0;
|
||||
GL::GetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &readFramebuffer);
|
||||
GL::GetIntegerv(GL_PIXEL_PACK_BUFFER_BINDING, &packBuffer);
|
||||
GL::GetIntegerv(GL_PACK_ALIGNMENT, &alignment);
|
||||
GL::GetIntegerv(GL_PACK_ROW_LENGTH, &rowLength);
|
||||
GL::GetIntegerv(GL_PACK_SKIP_ROWS, &skipRows);
|
||||
GL::GetIntegerv(GL_PACK_SKIP_PIXELS, &skipPixels);
|
||||
if (readFramebuffer != 0) GL::BindFramebuffer(GL_READ_FRAMEBUFFER, 0);
|
||||
if (packBuffer != 0) GL::BindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
||||
GL::PixelStorei(GL_PACK_ALIGNMENT, 4);
|
||||
GL::PixelStorei(GL_PACK_ROW_LENGTH, 0);
|
||||
GL::PixelStorei(GL_PACK_SKIP_ROWS, 0);
|
||||
GL::PixelStorei(GL_PACK_SKIP_PIXELS, 0);
|
||||
const SizeT rowBytes = static_cast<SizeT>(impl.width) * 4;
|
||||
impl.scratch.resize(rowBytes * static_cast<SizeT>(impl.height));
|
||||
GL::ReadPixels(0, 0, impl.width, impl.height, GL_RGBA, GL_UNSIGNED_BYTE, impl.scratch.data());
|
||||
GL::PixelStorei(GL_PACK_ALIGNMENT, alignment);
|
||||
GL::PixelStorei(GL_PACK_ROW_LENGTH, rowLength);
|
||||
GL::PixelStorei(GL_PACK_SKIP_ROWS, skipRows);
|
||||
GL::PixelStorei(GL_PACK_SKIP_PIXELS, skipPixels);
|
||||
if (packBuffer != 0) GL::BindBuffer(GL_PIXEL_PACK_BUFFER, static_cast<GLuint>(packBuffer));
|
||||
if (readFramebuffer != 0) GL::BindFramebuffer(GL_READ_FRAMEBUFFER, static_cast<GLuint>(readFramebuffer));
|
||||
|
||||
// GL's rows run bottom-up and RGBA; a wl_shm buffer's run top-down and B, G, R, A.
|
||||
auto* dst = static_cast<Uint8*>(buffer->map);
|
||||
for (EGLint y = 0; y < impl.height; ++y) {
|
||||
const Uint8* src = impl.scratch.data() + static_cast<SizeT>(impl.height - 1 - y) * rowBytes;
|
||||
Uint8* row = dst + static_cast<SizeT>(y) * static_cast<SizeT>(buffer->stride);
|
||||
for (EGLint x = 0; x < impl.width; ++x) {
|
||||
row[x * 4 + 0] = src[x * 4 + 2];
|
||||
row[x * 4 + 1] = src[x * 4 + 1];
|
||||
row[x * 4 + 2] = src[x * 4 + 0];
|
||||
row[x * 4 + 3] = src[x * 4 + 3];
|
||||
}
|
||||
}
|
||||
|
||||
wl_proxy* surface = impl.window->surface;
|
||||
const uint32_t surfaceVersion = api.getVersion(surface);
|
||||
api.marshalFlags(surface, kSurfaceAttach, nullptr, surfaceVersion, 0, buffer->buffer, impl.window->dx,
|
||||
impl.window->dy);
|
||||
if (surfaceVersion >= 4) {
|
||||
api.marshalFlags(surface, kSurfaceDamageBuffer, nullptr, surfaceVersion, 0, 0, 0, impl.width,
|
||||
impl.height);
|
||||
} else {
|
||||
api.marshalFlags(surface, kSurfaceDamage, nullptr, surfaceVersion, 0, 0, 0, impl.width, impl.height);
|
||||
}
|
||||
api.marshalFlags(surface, kSurfaceCommit, nullptr, surfaceVersion, 0);
|
||||
buffer->busy = true;
|
||||
impl.window->attached_width = impl.width;
|
||||
impl.window->attached_height = impl.height;
|
||||
impl.window->dx = 0;
|
||||
impl.window->dy = 0;
|
||||
api.flush(impl.display);
|
||||
return true;
|
||||
}
|
||||
} // namespace MobileGL::MG_Impl::EGLImpl::Wayland
|
||||
|
||||
#endif
|
||||
@@ -1,72 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Impl/EGLImpl/WaylandWindow.h
|
||||
// Copyright (c) 2025-2026 MobileGL-Dev
|
||||
// Licensed under the GNU Lesser General Public License v3.0:
|
||||
// https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#pragma once
|
||||
|
||||
// WAYLAND WINDOW SURFACES. A Wayland client hands eglCreateWindowSurface a wl_egl_window, and what
|
||||
// the compositor shows is whatever wl_buffer the client attaches to that window's wl_surface. The
|
||||
// pixels of a MobileGL frame are drawn where the backend is - on a split build, in another process
|
||||
// on another OS - so a window surface here is a pbuffer the backend draws into, plus this: at every
|
||||
// swap the frame is read back and attached to the wl_surface as a wl_shm buffer.
|
||||
//
|
||||
// libwayland-client is loaded at run time (it is already in every Wayland client's process), so the
|
||||
// library neither links it nor needs its headers to build.
|
||||
|
||||
#include <Includes.h>
|
||||
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
#define MOBILEGL_WAYLAND_WINDOWS 1
|
||||
#else
|
||||
#define MOBILEGL_WAYLAND_WINDOWS 0
|
||||
#endif
|
||||
|
||||
#if MOBILEGL_WAYLAND_WINDOWS
|
||||
|
||||
#include <EGL/egl.h>
|
||||
|
||||
namespace MobileGL::MG_Impl::EGLImpl::Wayland {
|
||||
// EGL_PLATFORM_WAYLAND_KHR and EGL_PLATFORM_WAYLAND_EXT are the same enum.
|
||||
inline constexpr EGLenum kPlatformWayland = 0x31D8;
|
||||
|
||||
// Whether a display is a Wayland one: asked for as EGL_PLATFORM_WAYLAND, or (eglGetDisplay with
|
||||
// no platform) a native display that is a wl_display - recognised the way Mesa does, by its
|
||||
// first word being libwayland-client's wl_display_interface.
|
||||
Bool IsWaylandDisplay(Uint64 nativeDisplay, EGLenum platform);
|
||||
|
||||
// Whether `window` looks like a wl_egl_window this library can present to.
|
||||
Bool IsWaylandWindow(const void* window);
|
||||
|
||||
// The size the application last gave its wl_egl_window.
|
||||
Bool WindowSize(const void* window, EGLint* width, EGLint* height);
|
||||
|
||||
// One window surface's presentation: the shm buffers, the event queue they are dispatched on,
|
||||
// and the readback scratch. Created for a wl_egl_window on a wl_display; null with the reason
|
||||
// logged when libwayland-client or the compositor's wl_shm is not there.
|
||||
class WindowSurface {
|
||||
public:
|
||||
static UniquePtr<WindowSurface> Create(void* wlDisplay, void* wlEglWindow, EGLint width, EGLint height,
|
||||
Bool hasAlpha);
|
||||
~WindowSurface();
|
||||
WindowSurface(const WindowSurface&) = delete;
|
||||
WindowSurface& operator=(const WindowSurface&) = delete;
|
||||
|
||||
// Reads the frame back out of the current context's default framebuffer and puts it on
|
||||
// the window: attach, damage, commit. The application's read-framebuffer and pack state
|
||||
// are put back exactly as they were. False (logged) when the frame did not reach the
|
||||
// window; the swap itself goes on regardless.
|
||||
Bool Present();
|
||||
|
||||
struct Impl;
|
||||
|
||||
private:
|
||||
explicit WindowSurface(UniquePtr<Impl> impl);
|
||||
UniquePtr<Impl> m_impl;
|
||||
};
|
||||
} // namespace MobileGL::MG_Impl::EGLImpl::Wayland
|
||||
|
||||
#endif
|
||||
@@ -6,9 +6,6 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
// The dma-buf import's client half: eglCreateImageKHR keeps a dup() of every plane's descriptor,
|
||||
// and this is what tells the render server which texture that buffer backs (see the header).
|
||||
#include <MG_Remote/Client/DmaBufImport.h>
|
||||
#include <Includes.h>
|
||||
#include "../Buffer/GL_Buffer.h"
|
||||
#include "../Getter/GL_Getter.h"
|
||||
@@ -25,13 +22,6 @@
|
||||
#include "../Sync/GL_Sync.h"
|
||||
#include "../Debug/GL_Debug.h"
|
||||
#include <MG_State/GLState/Core.h>
|
||||
// The EGL side of the state, for the two GL_OES_EGL_image entry points: what an EGLImage handle
|
||||
// names is an object eglCreateImageKHR built (its geometry, its fourcc and the descriptors it owns),
|
||||
// and that object lives in the EGL state. Same include the other GLImpl files that touch it use.
|
||||
#include <MG_State/EGLState/Core.h>
|
||||
// The compositor's frame boundary: glFlush presents the display host's frame when the surfaceless
|
||||
// bind hook took one (see EGLImpl.cpp). The EGL side declares the pair and the swap entry.
|
||||
#include <MG_Impl/EGLImpl/EGLImpl.h>
|
||||
|
||||
#define DECLARE_GL_FUNCTION_STUB_HEAD(type, name, ...) MOBILEGL_GL_API type gl##name(__VA_ARGS__) {
|
||||
|
||||
@@ -135,17 +125,6 @@ MOBILEGL_GL_API void glFlush() {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
MobileGL::MG_Pipe::MGPipeClientFlush();
|
||||
#endif
|
||||
// A COMPOSITOR'S FRAME BOUNDARY. kwin binds the display host's frame surface and draws the
|
||||
// desktop into it, then calls glFlush - and glFlush alone. It never calls eglSwapBuffers, so
|
||||
// without this the stream reached the server and the server drew, but the display host was
|
||||
// never told a frame was done: the host's own present loop (AHardwareBuffer_acquire ->
|
||||
// draw -> notify) is what puts pixels on the glass, and its notify is exactly this swap.
|
||||
// Guarded by whether the surfaceless-bind hook actually took the host frame.
|
||||
if (MobileGL::MG_Impl::EGLImpl::g_hostFramePresentSurface != nullptr &&
|
||||
MobileGL::MG_Impl::EGLImpl::g_hostFramePresentDisplay != nullptr) {
|
||||
MobileGL::MG_Impl::EGLImpl::SwapBuffers(MobileGL::MG_Impl::EGLImpl::g_hostFramePresentDisplay,
|
||||
MobileGL::MG_Impl::EGLImpl::g_hostFramePresentSurface);
|
||||
}
|
||||
}
|
||||
DECLARE_GL_FUNCTION_HEAD(void, FramebufferRenderbuffer, GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) DECLARE_GL_FUNCTION_END_NO_RETURN(void, FramebufferRenderbuffer, target, attachment, renderbuffertarget, renderbuffer)
|
||||
DECLARE_GL_FUNCTION_HEAD(void, FramebufferTexture2D, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) DECLARE_GL_FUNCTION_END_NO_RETURN(void, FramebufferTexture2D, target, attachment, textarget, texture, level)
|
||||
@@ -1318,325 +1297,17 @@ DECLARE_GL_FUNCTION_STUB_HEAD(void, GetnMinmaxARB, GLenum target, GLboolean rese
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, FramebufferSampleLocationsfvARB, GLenum target, GLuint start, GLsizei count, const GLfloat* v) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, FramebufferSampleLocationsfvARB, target, start, count, v)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, NamedFramebufferSampleLocationsfvARB, GLuint framebuffer, GLuint start, GLsizei count, const GLfloat* v) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, NamedFramebufferSampleLocationsfvARB, framebuffer, start, count, v)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, EvaluateDepthValuesARB, void) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, EvaluateDepthValuesARB, )
|
||||
// GL_ARB_shader_objects, GL_ARB_vertex_shader, GL_ARB_fragment_shader.
|
||||
//
|
||||
// kwin_wayland 6.7.3 refuses a MobileGL context over three of the names these extensions add.
|
||||
// EglContext::checkSupported() (src/opengl/eglcontext.cpp) takes the DESKTOP-OpenGL branch for
|
||||
// every context whose GL_VERSION is not an "OpenGL ES" string:
|
||||
// const bool supportsGLSL = m_isOpenglES || (hasOpenglExtension("GL_ARB_shader_objects") &&
|
||||
// hasOpenglExtension("GL_ARB_fragment_shader") && hasOpenglExtension("GL_ARB_vertex_shader"));
|
||||
// GL_VERSION here is "4.6.0 MobileGL ...", so all three names were REQUIRED of a context that did
|
||||
// not carry them: checkSupported() answered false, EglContext::create() returned nullptr,
|
||||
// EglBackend::createContext() returned false, and kwin printed "Could not initialize rendering
|
||||
// context" and quit without drawing a frame. Both backends now advertise the three, and this block
|
||||
// is what makes that advertisement true instead of a test unlock - every entry point the three
|
||||
// extensions define is implemented here, over the shader and program objects the core entry points
|
||||
// already own:
|
||||
//
|
||||
// ARB_shader_objects the 39 functions of the block include/GL/glext.h:4095-4173 declares.
|
||||
// ARB_vertex_shader the three attrib-location entry points of glext.h:4856-4862.
|
||||
// ARB_fragment_shader none. Its "New Procedures and Functions" section reads "None" - it is the
|
||||
// capability half of the pair, and the reason kwin names it at all.
|
||||
//
|
||||
// HANDLES. The ARB family names objects with GLhandleARB. This repository's own glext.h types that
|
||||
// as void* on Apple and as unsigned int on every other platform (glext.h:4055-4059, the same split
|
||||
// the system headers carry), so on Linux, Windows and Android a handle IS the GLuint name this
|
||||
// implementation hands out and both conversions below are the identity there. The pointer arm is
|
||||
// not decoration: a caller on Apple passes a pointer, and an id written straight into its void*
|
||||
// slot would be a size error rather than a cast error. H is a template parameter, and both arms
|
||||
// cast through it, so the arm a platform does not use is never instantiated - and never has to be
|
||||
// well-formed for the other typedef: reinterpret_cast between two integers, which is what the
|
||||
// pointer arm becomes on Linux, is not a cast clang accepts. The shape is the one
|
||||
// MG_State/EGLState/Core.h already uses for EGL's handles.
|
||||
template <typename H = GLhandleARB>
|
||||
static GLhandleARB ToGLHandleARB(GLuint name) {
|
||||
if constexpr (std::is_pointer_v<H>) {
|
||||
return reinterpret_cast<H>(static_cast<std::uintptr_t>(name));
|
||||
} else {
|
||||
return static_cast<H>(name);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename H = GLhandleARB>
|
||||
static GLuint FromGLHandleARB(GLhandleARB handle) {
|
||||
if constexpr (std::is_pointer_v<H>) {
|
||||
return static_cast<GLuint>(reinterpret_cast<std::uintptr_t>(static_cast<H>(handle)));
|
||||
} else {
|
||||
return static_cast<GLuint>(handle);
|
||||
}
|
||||
}
|
||||
|
||||
// The answer behind GetObjectParameter{if}vARB, and the reason neither of them carries a pname
|
||||
// translation table: the GL_OBJECT_*_ARB tokens ARE the core tokens, numerically. Core GL took the
|
||||
// object pnames over unchanged when ARB_shader_objects was folded in -
|
||||
// GL_OBJECT_DELETE_STATUS_ARB through GL_OBJECT_SHADER_SOURCE_LENGTH_ARB are 0x8B80-0x8B88, the
|
||||
// same numbers glcorearb.h gives GL_DELETE_STATUS through GL_SHADER_SOURCE_LENGTH
|
||||
// (glext.h:4086-4094) - so the mapping is a RENAME and the same pname goes to the core getter of
|
||||
// the same object kind. Handing it to that getter is also the right ERROR behaviour, and the reason
|
||||
// this does not whitelist pnames: GL_OBJECT_LINK_STATUS_ARB asked of a SHADER has to come back
|
||||
// INVALID_ENUM, and glGetShaderiv is where the set of pnames a shader accepts is defined.
|
||||
//
|
||||
// The one token core never took is GL_OBJECT_TYPE_ARB (0x8B4E; core's GL_OBJECT_TYPE, 0x9112, is
|
||||
// ARB_program_interface_query's interface class, a different question with a different value
|
||||
// space), so the object kind is the single thing answered here without a core getter. It is also
|
||||
// the only way an ARB-era caller can ask whether a handle names a program or a shader: there is no
|
||||
// glIsProgramARB/glIsShaderARB in ARB_shader_objects (include/GL/glext.h:4095-4173 declares
|
||||
// neither, and the glIsProgramARB the registry does know, glext.h:3280, belongs to
|
||||
// ARB_vertex_program/ARB_fragment_program - those ASM program objects are not these).
|
||||
static MobileGL::Bool AnswerObjectParameterARB(GLuint name, GLenum pname, GLint* params) {
|
||||
if (pname == GL_OBJECT_TYPE_ARB) {
|
||||
if (glIsProgram(name)) {
|
||||
*params = GL_PROGRAM_OBJECT_ARB;
|
||||
return true;
|
||||
}
|
||||
if (glIsShader(name)) {
|
||||
*params = GL_SHADER_OBJECT_ARB;
|
||||
return true;
|
||||
}
|
||||
// The error ARB_vertex_shader's own text specifies: "The error INVALID_VALUE is generated
|
||||
// by any command that takes one or more handles as input, and one or more handles are not
|
||||
// an object handle generated by OpenGL."
|
||||
MobileGL::MG_State::pGLContext->RecordError(
|
||||
MobileGL::ErrorCode::InvalidValue,
|
||||
MobileGL::MakeUnique<MobileGL::GenericErrorInfo>(
|
||||
"MG_Impl/GLImpl", __func__,
|
||||
std::to_string(name) + " is not an object handle generated by OpenGL."));
|
||||
return false;
|
||||
}
|
||||
if (glIsProgram(name)) {
|
||||
glGetProgramiv(name, pname, params);
|
||||
return true;
|
||||
}
|
||||
// A shader, or a name that is neither. glGetShaderiv owns both the shader pname set and the
|
||||
// name validation, which is the one place that splits a program name handed to a shader query
|
||||
// (INVALID_OPERATION) from a name GL never generated (INVALID_VALUE) - the split GL 3.3 core
|
||||
// 2.11 requires. It writes nothing in either error case, which is what the caller reads as
|
||||
// "no answer".
|
||||
const MobileGL::Bool isShader = glIsShader(name) == GL_TRUE;
|
||||
glGetShaderiv(name, pname, params);
|
||||
return isShader;
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glDeleteObjectARB(GLhandleARB obj) {
|
||||
// ARB_shader_objects has ONE object namespace - a handle names a program or a shader and
|
||||
// nothing else - and DeleteObjectARB is the deletion entry point for both kinds, so the kind
|
||||
// is decided here. IsProgram/IsShader answer over the same single namespace this
|
||||
// implementation hands names out of, so a program name cannot be taken for a shader name.
|
||||
// Zero, and a handle that names neither object, are ignored: there is no object to delete.
|
||||
const GLuint name = FromGLHandleARB(obj);
|
||||
if (glIsProgram(name)) {
|
||||
glDeleteProgram(name);
|
||||
} else if (glIsShader(name)) {
|
||||
glDeleteShader(name);
|
||||
}
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API GLhandleARB glGetHandleARB(GLenum pname) {
|
||||
if (pname != GL_PROGRAM_OBJECT_ARB) {
|
||||
MobileGL::MG_State::pGLContext->RecordError(
|
||||
MobileGL::ErrorCode::InvalidEnum,
|
||||
MobileGL::MakeUnique<MobileGL::GenericErrorInfo>(
|
||||
"MG_Impl/GLImpl", __func__,
|
||||
"pname " + std::to_string(pname) + " is not GL_PROGRAM_OBJECT_ARB."));
|
||||
return ToGLHandleARB(0u);
|
||||
}
|
||||
// "The program object currently in use", read from the state GL_CURRENT_PROGRAM is answered
|
||||
// from - so a program bound through glUseProgram is found here too, and a
|
||||
// UseProgramObjectARB(0) reads back as the zero handle.
|
||||
const auto& currentProgram = MobileGL::MG_State::pGLContext->GetCurrentProgram();
|
||||
return ToGLHandleARB(currentProgram ? static_cast<GLuint>(currentProgram->GetExternalIndex()) : 0u);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glDetachObjectARB(GLhandleARB containerObj, GLhandleARB attachedObj) {
|
||||
glDetachShader(FromGLHandleARB(containerObj), FromGLHandleARB(attachedObj));
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API GLhandleARB glCreateShaderObjectARB(GLenum shaderType) {
|
||||
return ToGLHandleARB(glCreateShader(shaderType));
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glShaderSourceARB(GLhandleARB shaderObj, GLsizei count, const GLcharARB** string,
|
||||
const GLint* length) {
|
||||
glShaderSource(FromGLHandleARB(shaderObj), count, string, length);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glCompileShaderARB(GLhandleARB shaderObj) {
|
||||
glCompileShader(FromGLHandleARB(shaderObj));
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API GLhandleARB glCreateProgramObjectARB(void) {
|
||||
return ToGLHandleARB(glCreateProgram());
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glAttachObjectARB(GLhandleARB containerObj, GLhandleARB obj) {
|
||||
glAttachShader(FromGLHandleARB(containerObj), FromGLHandleARB(obj));
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glLinkProgramARB(GLhandleARB programObj) {
|
||||
glLinkProgram(FromGLHandleARB(programObj));
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUseProgramObjectARB(GLhandleARB programObj) {
|
||||
glUseProgram(FromGLHandleARB(programObj));
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glValidateProgramARB(GLhandleARB programObj) {
|
||||
glValidateProgram(FromGLHandleARB(programObj));
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform1fARB(GLint location, GLfloat v0) {
|
||||
glUniform1f(location, v0);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform2fARB(GLint location, GLfloat v0, GLfloat v1) {
|
||||
glUniform2f(location, v0, v1);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform3fARB(GLint location, GLfloat v0, GLfloat v1, GLfloat v2) {
|
||||
glUniform3f(location, v0, v1, v2);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform4fARB(GLint location, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) {
|
||||
glUniform4f(location, v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform1iARB(GLint location, GLint v0) {
|
||||
glUniform1i(location, v0);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform2iARB(GLint location, GLint v0, GLint v1) {
|
||||
glUniform2i(location, v0, v1);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform3iARB(GLint location, GLint v0, GLint v1, GLint v2) {
|
||||
glUniform3i(location, v0, v1, v2);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform4iARB(GLint location, GLint v0, GLint v1, GLint v2, GLint v3) {
|
||||
glUniform4i(location, v0, v1, v2, v3);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform1fvARB(GLint location, GLsizei count, const GLfloat* value) {
|
||||
glUniform1fv(location, count, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform2fvARB(GLint location, GLsizei count, const GLfloat* value) {
|
||||
glUniform2fv(location, count, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform3fvARB(GLint location, GLsizei count, const GLfloat* value) {
|
||||
glUniform3fv(location, count, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform4fvARB(GLint location, GLsizei count, const GLfloat* value) {
|
||||
glUniform4fv(location, count, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform1ivARB(GLint location, GLsizei count, const GLint* value) {
|
||||
glUniform1iv(location, count, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform2ivARB(GLint location, GLsizei count, const GLint* value) {
|
||||
glUniform2iv(location, count, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform3ivARB(GLint location, GLsizei count, const GLint* value) {
|
||||
glUniform3iv(location, count, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniform4ivARB(GLint location, GLsizei count, const GLint* value) {
|
||||
glUniform4iv(location, count, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniformMatrix2fvARB(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
|
||||
glUniformMatrix2fv(location, count, transpose, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniformMatrix3fvARB(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
|
||||
glUniformMatrix3fv(location, count, transpose, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glUniformMatrix4fvARB(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value) {
|
||||
glUniformMatrix4fv(location, count, transpose, value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetObjectParameterfvARB(GLhandleARB obj, GLenum pname, GLfloat* params) {
|
||||
// The fv form asks the same questions - the ARB object model holds no float-valued object
|
||||
// state - so the answer is the iv answer widened. A query the iv path refuses leaves the
|
||||
// output untouched here as well, rather than putting a plausible-looking 0.0 where there is
|
||||
// no answer.
|
||||
GLint value = 0;
|
||||
if (!AnswerObjectParameterARB(FromGLHandleARB(obj), pname, &value)) return;
|
||||
*params = static_cast<GLfloat>(value);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetObjectParameterivARB(GLhandleARB obj, GLenum pname, GLint* params) {
|
||||
AnswerObjectParameterARB(FromGLHandleARB(obj), pname, params);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetInfoLogARB(GLhandleARB obj, GLsizei maxLength, GLsizei* length, GLcharARB* infoLog) {
|
||||
// The same handle-kind dispatch as AnswerObjectParameterARB, and the same fallback: the shader
|
||||
// getter is also where the name validation and its error code live.
|
||||
const GLuint name = FromGLHandleARB(obj);
|
||||
if (glIsProgram(name)) {
|
||||
glGetProgramInfoLog(name, maxLength, length, infoLog);
|
||||
} else {
|
||||
glGetShaderInfoLog(name, maxLength, length, infoLog);
|
||||
}
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetAttachedObjectsARB(GLhandleARB containerObj, GLsizei maxCount, GLsizei* count,
|
||||
GLhandleARB* obj) {
|
||||
// The caller's array holds GLhandleARB while glGetAttachedShaders writes GLuint names, and on
|
||||
// Apple those are different sizes, so the ids are gathered first and converted one at a time.
|
||||
// A negative maxCount is passed through: glGetAttachedShaders is where its INVALID_VALUE is.
|
||||
MobileGL::Vector<GLuint> shaders(maxCount > 0 ? static_cast<MobileGL::SizeT>(maxCount) : 0, 0);
|
||||
GLsizei attached = 0;
|
||||
glGetAttachedShaders(FromGLHandleARB(containerObj), maxCount, &attached, shaders.data());
|
||||
for (GLsizei i = 0; i < attached; ++i) {
|
||||
obj[i] = ToGLHandleARB(shaders[i]);
|
||||
}
|
||||
if (count) *count = attached;
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API GLint glGetUniformLocationARB(GLhandleARB programObj, const GLcharARB* name) {
|
||||
return glGetUniformLocation(FromGLHandleARB(programObj), name);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetActiveUniformARB(GLhandleARB programObj, GLuint index, GLsizei maxLength,
|
||||
GLsizei* length, GLint* size, GLenum* type, GLcharARB* name) {
|
||||
glGetActiveUniform(FromGLHandleARB(programObj), index, maxLength, length, size, type, name);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetUniformfvARB(GLhandleARB programObj, GLint location, GLfloat* params) {
|
||||
glGetUniformfv(FromGLHandleARB(programObj), location, params);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetUniformivARB(GLhandleARB programObj, GLint location, GLint* params) {
|
||||
glGetUniformiv(FromGLHandleARB(programObj), location, params);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetShaderSourceARB(GLhandleARB obj, GLsizei maxLength, GLsizei* length,
|
||||
GLcharARB* source) {
|
||||
glGetShaderSource(FromGLHandleARB(obj), maxLength, length, source);
|
||||
}
|
||||
|
||||
// ARB_vertex_shader's three entry points. The generic-attribute family that extension also
|
||||
// describes is spelled with the ARB_vertex_program names (glVertexAttribPointerARB and the rest),
|
||||
// which glext.h declares in that other block and which MobileGL does not advertise; nothing here
|
||||
// claims them.
|
||||
MOBILEGL_GL_API void glBindAttribLocationARB(GLhandleARB programObj, GLuint index, const GLcharARB* name) {
|
||||
glBindAttribLocation(FromGLHandleARB(programObj), index, name);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glGetActiveAttribARB(GLhandleARB programObj, GLuint index, GLsizei maxLength,
|
||||
GLsizei* length, GLint* size, GLenum* type, GLcharARB* name) {
|
||||
glGetActiveAttrib(FromGLHandleARB(programObj), index, maxLength, length, size, type, name);
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API GLint glGetAttribLocationARB(GLhandleARB programObj, const GLcharARB* name) {
|
||||
return glGetAttribLocation(FromGLHandleARB(programObj), name);
|
||||
}
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, DeleteObjectARB, GLhandleARB obj) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, DeleteObjectARB, obj)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(GLhandleARB, GetHandleARB, GLenum pname) DECLARE_GL_FUNCTION_STUB_END(GLhandleARB, GetHandleARB, pname)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, DetachObjectARB, GLhandleARB containerObj, GLhandleARB attachedObj) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, DetachObjectARB, containerObj, attachedObj)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(GLhandleARB, CreateShaderObjectARB, GLenum shaderType) DECLARE_GL_FUNCTION_STUB_END(GLhandleARB, CreateShaderObjectARB, shaderType)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(GLhandleARB, CreateProgramObjectARB, void) DECLARE_GL_FUNCTION_STUB_END(GLhandleARB, CreateProgramObjectARB, )
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, AttachObjectARB, GLhandleARB containerObj, GLhandleARB obj) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, AttachObjectARB, containerObj, obj)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, UseProgramObjectARB, GLhandleARB programObj) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, UseProgramObjectARB, programObj)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, GetObjectParameterfvARB, GLhandleARB obj, GLenum pname, GLfloat* params) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, GetObjectParameterfvARB, obj, pname, params)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, GetObjectParameterivARB, GLhandleARB obj, GLenum pname, GLint* params) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, GetObjectParameterivARB, obj, pname, params)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, GetInfoLogARB, GLhandleARB obj, GLsizei maxLength, GLsizei* length, GLcharARB* infoLog) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, GetInfoLogARB, obj, maxLength, length, infoLog)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, GetAttachedObjectsARB, GLhandleARB containerObj, GLsizei maxCount, GLsizei* count, GLhandleARB* obj) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, GetAttachedObjectsARB, containerObj, maxCount, count, obj)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, NamedStringARB, GLenum type, GLint namelen, const GLchar* name, GLint strinen, const GLchar* string) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, NamedStringARB, type, namelen, name, strinen, string)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, DeleteNamedStringARB, GLint namelen, const GLchar* name) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, DeleteNamedStringARB, namelen, name)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, CompileShaderIncludeARB, GLuint shader, GLsizei count, const GLchar* const* path, const GLint* length) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, CompileShaderIncludeARB, shader, count, path, length)
|
||||
@@ -2042,141 +1713,6 @@ DECLARE_GL_FUNCTION_STUB_HEAD(void, VertexBlendEnviATI, GLenum pname, GLint para
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, VertexBlendEnvfATI, GLenum pname, GLfloat param) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, VertexBlendEnvfATI, pname, param)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, EGLImageTargetTexStorageEXT, GLenum target, GLeglImageOES image, const GLint* attrib_list) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, EGLImageTargetTexStorageEXT, target, image, attrib_list)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, EGLImageTargetTextureStorageEXT, GLuint texture, GLeglImageOES image, const GLint* attrib_list) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, EGLImageTargetTextureStorageEXT, texture, image, attrib_list)
|
||||
|
||||
// GL_OES_EGL_image.
|
||||
//
|
||||
// MEASURED, and the whole reason this block exists: libepoxy in kwin_wayland prints
|
||||
// No provider of glEGLImageTargetTexture2DOES found. Requires one of: GL_OES_EGL_image
|
||||
// and refuses the import path there - and that path is how the compositor's scene reaches the
|
||||
// display daemon's dma-bufs, i.e. how a Linux desktop gets onto the phone's screen. The EGL half is
|
||||
// real: eglCreateImageKHR builds an EGL_LINUX_DMA_BUF_EXT image that owns a dup() of every plane's
|
||||
// descriptor and carries that buffer's geometry and fourcc (MG_State/EGLState/Core.h). So a handle
|
||||
// that arrives here is resolvable, and what these two entry points do is exactly that: resolve it,
|
||||
// refuse what names nothing, and say ONCE what is not wired yet. What is not wired yet is the
|
||||
// render-server half - telling the server which texture a dma-buf backs, over the one channel that
|
||||
// can carry a descriptor across the container boundary - so a framebuffer built over an imported
|
||||
// texture is not complete until that lands. Pretending otherwise (attaching the image to a texture
|
||||
// object that has no storage behind it) would turn "not implemented" into "mysteriously black",
|
||||
// which is what the log line below is here to prevent.
|
||||
MOBILEGL_GL_API void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image) {
|
||||
// 0x8D65 is GL_TEXTURE_EXTERNAL_OES, which the headers this file compiles against do not spell
|
||||
// out. It matters here MORE than GL_TEXTURE_2D does: a compositor that could not map an
|
||||
// imported dma-buf's format to a non-external one binds its image to THIS target, so refusing it
|
||||
// would turn "no format map yet" into an INVALID_ENUM the caller cannot act on (kwin 6.7.3 does
|
||||
// exactly that when EglDisplay::queryImportFormats() answers nothing).
|
||||
constexpr GLenum kTextureExternalOes = 0x8D65;
|
||||
if (target != GL_TEXTURE_2D && target != kTextureExternalOes) {
|
||||
MobileGL::MG_State::pGLContext->RecordError(
|
||||
MobileGL::ErrorCode::InvalidEnum,
|
||||
MobileGL::MakeUnique<MobileGL::GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"target is not a texture target this entry point takes."));
|
||||
return;
|
||||
}
|
||||
EGLint imageWidth = 0;
|
||||
EGLint imageHeight = 0;
|
||||
EGLint imageFourCC = 0;
|
||||
EGLint imagePlanes = 0;
|
||||
const MobileGL::Bool imageKnown =
|
||||
MobileGL::MG_State::pEGLContext != nullptr &&
|
||||
MobileGL::MG_State::pEGLContext->DescribeImage(reinterpret_cast<::EGLImage>(image), &imageWidth, &imageHeight,
|
||||
&imageFourCC, &imagePlanes);
|
||||
if (!imageKnown) {
|
||||
// A handle this side did not hand out: ARB/OES text puts that on INVALID_VALUE, and it is
|
||||
// the answer a caller can act on rather than a texture that renders nowhere.
|
||||
MobileGL::MG_State::pGLContext->RecordError(
|
||||
MobileGL::ErrorCode::InvalidValue,
|
||||
MobileGL::MakeUnique<MobileGL::GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"image is not an EGLImage this display created."));
|
||||
return;
|
||||
}
|
||||
MGLOG_W_ONCE("glEGLImageTargetTexture2DOES: taking target 0x%04x over an EGLImage of %dx%d fourcc 0x%08x "
|
||||
"(%d plane(s)) that this side holds; the render server has NOT been told which texture that "
|
||||
"dma-buf backs yet, so a framebuffer over this texture is not complete (the fd transport over "
|
||||
"the GBM socket and the server-side import are the next change)",
|
||||
target, imageWidth, imageHeight, imageFourCC, imagePlanes);
|
||||
|
||||
// AND NOW WIRE IT: a texture bound to an imported EGLImage has no storage on the render server,
|
||||
// and a framebuffer built over it there is not complete - kwin 6.7.3 aborts on its own
|
||||
// RenderTarget assertion right after this log line (measured twice). So the server is told which
|
||||
// buffer backs the texture: one message per plane, each carrying that plane's descriptor over the
|
||||
// session transport's SCM_RIGHTS channel. No session, or a transport without that channel, is a
|
||||
// refusal by name from ShareImportedDmaBuf - the texture simply keeps having no storage, which is
|
||||
// the honest state rather than a silent render into nothing.
|
||||
MGLOG_I("dma-buf import: entry (target=0x%04x, image=%p)", static_cast<unsigned>(target), static_cast<void*>(image));
|
||||
if (MobileGL::MG_State::pEGLContext != nullptr) {
|
||||
constexpr MobileGL::Int kDmaBufImportPlanes = 4;
|
||||
EGLint planeCount = 0;
|
||||
EGLint planeFds[kDmaBufImportPlanes] = {-1, -1, -1, -1};
|
||||
EGLint planeOffsets[kDmaBufImportPlanes] = {0, 0, 0, 0};
|
||||
EGLint planePitches[kDmaBufImportPlanes] = {0, 0, 0, 0};
|
||||
MobileGL::Uint64 planeModifiers[kDmaBufImportPlanes] = {0, 0, 0, 0};
|
||||
MobileGL::Bool planeHasModifier[kDmaBufImportPlanes] = {false, false, false, false};
|
||||
if (MobileGL::MG_State::pEGLContext->DescribeImagePlanes(
|
||||
reinterpret_cast<::EGLImage>(image), &planeCount, planeFds, planeOffsets, planePitches,
|
||||
planeModifiers, planeHasModifier, kDmaBufImportPlanes)) {
|
||||
// The texture the image was bound to. 0x8D65 has no TextureTarget member in this state
|
||||
// layer (nothing else here binds it), so the name is looked up through Texture2D and may
|
||||
// come back 0 - the server logs what it was told rather than guessing.
|
||||
MobileGL::Uint32 texName = 0;
|
||||
if (MobileGL::MG_State::pGLContext != nullptr) {
|
||||
const MobileGL::Int unit = MobileGL::MG_State::pGLContext->GetActiveTextureUnit();
|
||||
// THE EXTERNAL SLOT, which is where a compositor's imported dma-buf texture lives.
|
||||
const auto& bound = MobileGL::MG_State::pGLContext->GetTextureUnitObject(unit)
|
||||
.GetBindingSlot(MobileGL::TextureTarget::TextureExternalOES)
|
||||
.GetBoundObject();
|
||||
if (bound != nullptr) {
|
||||
texName = static_cast<MobileGL::Uint32>(bound->GetExternalIndex());
|
||||
// AN IMPORTED TEXTURE IS BACKED, SO IT IS COMPLETE. Without this the state layer
|
||||
// answers incompletely (TextureObjectBase::IsComplete only looks at the internal
|
||||
// format) and the compositor, having attached it to a framebuffer, reports
|
||||
// "framebuffer for dmabuf 0 is not complete" and stops before drawing anything.
|
||||
bound->SetInternalFormat(MobileGL::TextureInternalFormat::RGBA8);
|
||||
}
|
||||
}
|
||||
MGLOG_I("dma-buf import: textures resolved (texName=%u planes=%d), sharing", texName,
|
||||
static_cast<int>(planeCount));
|
||||
for (MobileGL::Int plane = 0; plane < planeCount; plane++) {
|
||||
if (planeFds[plane] < 0) continue;
|
||||
MGLOG_I("dma-buf import: sharing plane %d fd=%d", static_cast<int>(plane), planeFds[plane]);
|
||||
(void)MobileGL::MG_Remote::Client::ShareImportedDmaBuf(
|
||||
static_cast<MobileGL::Uint32>(target), texName, static_cast<MobileGL::Uint32>(imageWidth),
|
||||
static_cast<MobileGL::Uint32>(imageHeight), static_cast<MobileGL::Uint32>(imageFourCC),
|
||||
static_cast<MobileGL::Uint32>(plane), static_cast<MobileGL::Uint32>(planeCount), planeFds[plane],
|
||||
planePitches[plane], planeOffsets[plane], planeModifiers[plane], planeHasModifier[plane]);
|
||||
MGLOG_I("dma-buf import: plane %d shared", static_cast<int>(plane));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MOBILEGL_GL_API void glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image) {
|
||||
if (target != GL_RENDERBUFFER) {
|
||||
MobileGL::MG_State::pGLContext->RecordError(
|
||||
MobileGL::ErrorCode::InvalidEnum,
|
||||
MobileGL::MakeUnique<MobileGL::GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"target is not GL_RENDERBUFFER."));
|
||||
return;
|
||||
}
|
||||
EGLint imageWidth = 0;
|
||||
EGLint imageHeight = 0;
|
||||
EGLint imageFourCC = 0;
|
||||
EGLint imagePlanes = 0;
|
||||
const MobileGL::Bool imageKnown =
|
||||
MobileGL::MG_State::pEGLContext != nullptr &&
|
||||
MobileGL::MG_State::pEGLContext->DescribeImage(reinterpret_cast<::EGLImage>(image), &imageWidth, &imageHeight,
|
||||
&imageFourCC, &imagePlanes);
|
||||
if (!imageKnown) {
|
||||
MobileGL::MG_State::pGLContext->RecordError(
|
||||
MobileGL::ErrorCode::InvalidValue,
|
||||
MobileGL::MakeUnique<MobileGL::GenericErrorInfo>("MG_Impl/GLImpl", __func__,
|
||||
"image is not an EGLImage this display created."));
|
||||
return;
|
||||
}
|
||||
MGLOG_W_ONCE("glEGLImageTargetRenderbufferStorageOES: the renderbuffer takes an EGLImage of %dx%d fourcc "
|
||||
"0x%08x; the render-server half of the import is the next change, exactly as for the texture "
|
||||
"entry point beside this one",
|
||||
imageWidth, imageHeight, imageFourCC);
|
||||
}
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(void, UniformBufferEXT, GLuint program, GLint location, GLuint buffer) DECLARE_GL_FUNCTION_STUB_END_NO_RETURN(void, UniformBufferEXT, program, location, buffer)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(GLint, GetUniformBufferSizeEXT, GLuint program, GLint location) DECLARE_GL_FUNCTION_STUB_END(GLint, GetUniformBufferSizeEXT, program, location)
|
||||
DECLARE_GL_FUNCTION_STUB_HEAD(GLintptr, GetUniformOffsetEXT, GLuint program, GLint location) DECLARE_GL_FUNCTION_STUB_END(GLintptr, GetUniformOffsetEXT, program, location)
|
||||
|
||||
@@ -100,13 +100,6 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
}
|
||||
|
||||
Bool HasDefinedAttachment(const MG_State::GLState::FramebufferObject& framebufferObject) {
|
||||
// NOT gated on the host frame, and that is deliberate: this only decides the ERROR CODE
|
||||
// once completeness has already failed (CheckFramebufferStatus_State asks
|
||||
// CheckCompleteness first), and the imported dma-buf's attachment is counted as valid
|
||||
// THERE (MG_State/GLState/FramebufferState/FramebufferObject.cpp, whose gate lands before
|
||||
// its own validity test for exactly this reason). Touching it here would add a second
|
||||
// place that has to know the backend's frame - and the frontend knowing that fact is the
|
||||
// compromise the completeness comment already names the end of.
|
||||
for (const auto& attachment : framebufferObject.GetAllAttachmentObjects()) {
|
||||
if (attachment.IsValid() && !attachment.IsEmpty()) {
|
||||
return true;
|
||||
@@ -618,9 +611,7 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
|
||||
const auto expectedTextureTarget = MG_Util::ConvertTextureUploadTargetToTextureTarget(textureUploadTarget);
|
||||
if (expectedTextureTarget == TextureTarget::Unknown ||
|
||||
(textureObject->GetTarget() != expectedTextureTarget &&
|
||||
!(textureObject->GetTarget() == TextureTarget::TextureExternalOES &&
|
||||
expectedTextureTarget == TextureTarget::Texture2D))) {
|
||||
textureObject->GetTarget() != expectedTextureTarget) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeUnique<GenericErrorInfo>(
|
||||
@@ -1391,9 +1382,7 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
|
||||
const auto expectedTextureTarget = MG_Util::ConvertTextureUploadTargetToTextureTarget(textureUploadTarget);
|
||||
if (expectedTextureTarget == TextureTarget::Unknown ||
|
||||
(textureObject->GetTarget() != expectedTextureTarget &&
|
||||
!(textureObject->GetTarget() == TextureTarget::TextureExternalOES &&
|
||||
expectedTextureTarget == TextureTarget::Texture2D))) {
|
||||
textureObject->GetTarget() != expectedTextureTarget) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeUnique<GenericErrorInfo>(
|
||||
@@ -1543,9 +1532,7 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
|
||||
const auto expectedTextureTarget = MG_Util::ConvertTextureUploadTargetToTextureTarget(textureUploadTarget);
|
||||
if (expectedTextureTarget == TextureTarget::Unknown ||
|
||||
(textureObject->GetTarget() != expectedTextureTarget &&
|
||||
!(textureObject->GetTarget() == TextureTarget::TextureExternalOES &&
|
||||
expectedTextureTarget == TextureTarget::Texture2D))) {
|
||||
textureObject->GetTarget() != expectedTextureTarget) {
|
||||
MG_State::pGLContext->RecordError(
|
||||
ErrorCode::InvalidOperation,
|
||||
MakeUnique<GenericErrorInfo>(
|
||||
|
||||
@@ -869,55 +869,6 @@ namespace MobileGL::MG_Impl {
|
||||
GETPROC(glNamedBufferPageCommitmentARB, name);
|
||||
GETPROC(glTexPageCommitmentARB, name);
|
||||
GETPROC(glTexBufferARB, name);
|
||||
// ARB_shader_objects and ARB_vertex_shader, by name, because a name is the only way an
|
||||
// application ever asks for an extension entry point. Measured path: kwin_wayland resolves GL
|
||||
// through libepoxy, and libepoxy asks eglGetProcAddress -> EGLImpl::GetProcAddress -> this
|
||||
// table. Before these lines the callers that need the extension whose STRINGS make
|
||||
// checkSupported() pass got a nullptr for every function of it - dlsym on the library found
|
||||
// them, this table did not. The strings and the implementations are advertised from
|
||||
// MG_Impl/GLImpl/Exporting/Definitions.cpp and the two BackendObject_* extension lists.
|
||||
GETPROC(glDeleteObjectARB, name);
|
||||
GETPROC(glGetHandleARB, name);
|
||||
GETPROC(glDetachObjectARB, name);
|
||||
GETPROC(glCreateShaderObjectARB, name);
|
||||
GETPROC(glShaderSourceARB, name);
|
||||
GETPROC(glCompileShaderARB, name);
|
||||
GETPROC(glCreateProgramObjectARB, name);
|
||||
GETPROC(glAttachObjectARB, name);
|
||||
GETPROC(glLinkProgramARB, name);
|
||||
GETPROC(glUseProgramObjectARB, name);
|
||||
GETPROC(glValidateProgramARB, name);
|
||||
GETPROC(glUniform1fARB, name);
|
||||
GETPROC(glUniform2fARB, name);
|
||||
GETPROC(glUniform3fARB, name);
|
||||
GETPROC(glUniform4fARB, name);
|
||||
GETPROC(glUniform1iARB, name);
|
||||
GETPROC(glUniform2iARB, name);
|
||||
GETPROC(glUniform3iARB, name);
|
||||
GETPROC(glUniform4iARB, name);
|
||||
GETPROC(glUniform1fvARB, name);
|
||||
GETPROC(glUniform2fvARB, name);
|
||||
GETPROC(glUniform3fvARB, name);
|
||||
GETPROC(glUniform4fvARB, name);
|
||||
GETPROC(glUniform1ivARB, name);
|
||||
GETPROC(glUniform2ivARB, name);
|
||||
GETPROC(glUniform3ivARB, name);
|
||||
GETPROC(glUniform4ivARB, name);
|
||||
GETPROC(glUniformMatrix2fvARB, name);
|
||||
GETPROC(glUniformMatrix3fvARB, name);
|
||||
GETPROC(glUniformMatrix4fvARB, name);
|
||||
GETPROC(glGetObjectParameterfvARB, name);
|
||||
GETPROC(glGetObjectParameterivARB, name);
|
||||
GETPROC(glGetInfoLogARB, name);
|
||||
GETPROC(glGetAttachedObjectsARB, name);
|
||||
GETPROC(glGetUniformLocationARB, name);
|
||||
GETPROC(glGetActiveUniformARB, name);
|
||||
GETPROC(glGetUniformfvARB, name);
|
||||
GETPROC(glGetUniformivARB, name);
|
||||
GETPROC(glGetShaderSourceARB, name);
|
||||
GETPROC(glBindAttribLocationARB, name);
|
||||
GETPROC(glGetActiveAttribARB, name);
|
||||
GETPROC(glGetAttribLocationARB, name);
|
||||
GETPROC(glDepthRangeArraydvNV, name);
|
||||
GETPROC(glDepthRangeIndexeddNV, name);
|
||||
GETPROC(glBlendBarrierKHR, name);
|
||||
@@ -935,8 +886,6 @@ namespace MobileGL::MG_Impl {
|
||||
GETPROC(glBeginPerfMonitorAMD, name);
|
||||
GETPROC(glEndPerfMonitorAMD, name);
|
||||
GETPROC(glGetPerfMonitorCounterDataAMD, name);
|
||||
GETPROC(glEGLImageTargetTexture2DOES, name);
|
||||
GETPROC(glEGLImageTargetRenderbufferStorageOES, name);
|
||||
GETPROC(glEGLImageTargetTexStorageEXT, name);
|
||||
GETPROC(glEGLImageTargetTextureStorageEXT, name);
|
||||
GETPROC(glLabelObjectEXT, name);
|
||||
|
||||
@@ -1828,11 +1828,6 @@ namespace MobileGL::MG_Pipe {
|
||||
*entry = Entry{};
|
||||
}
|
||||
|
||||
void Clear() {
|
||||
for (auto& table : m_kinds) table.clear();
|
||||
m_band.clear();
|
||||
}
|
||||
|
||||
private:
|
||||
struct Entry {
|
||||
Uint32 Gen = 0;
|
||||
@@ -1897,15 +1892,6 @@ namespace MobileGL::MG_Pipe {
|
||||
PublicationLatch().NoteUnpublished(kind, handle);
|
||||
}
|
||||
|
||||
void MGPipeForgetAllPublications() {
|
||||
PublicationLatch().Clear();
|
||||
// The two families whose death asks their own record rather than the latch: vertex
|
||||
// elements (MGPipeEmitVertexElementsDestroyAndFree's RecordIsPublished) and buffers
|
||||
// (MGPipeEmitResourceDestroyAndFree's WasPublished).
|
||||
MGPipeVertexInputEmitterInstance().ForgetAllRecords();
|
||||
MGPipeResourceTrackerInstance().ForgetAllPublished();
|
||||
}
|
||||
|
||||
// THE GATE ITSELF, AS AN OBSERVABLE (ID-39, widened by S-3 / ID-41). Every P4a birth hook
|
||||
// below and every `wants()` row in the walk resolve through FamilyIsLive /
|
||||
// P4aFamilyHasItsConsumer / P4aFamilyDependenciesAreSet, and none of the three is reachable
|
||||
|
||||
@@ -340,10 +340,6 @@ namespace MobileGL::MG_Pipe {
|
||||
const SizeT slot = handle.Slot;
|
||||
return slot < m_bySlot.size() && m_bySlot[slot].Published;
|
||||
}
|
||||
// The session that held every buffer's record is gone (MGPipeForgetAllPublications).
|
||||
void ForgetAllPublished() {
|
||||
for (Entry& entry : m_bySlot) entry.Published = false;
|
||||
}
|
||||
|
||||
// The sticky everBoundAs mask. Sticky exactly as MGPResourceDesc::ImageBindableHint's
|
||||
// everImageBound is: ORed, never cleared, so a buffer that was an element array once
|
||||
|
||||
@@ -351,14 +351,6 @@ namespace MobileGL::MG_Pipe {
|
||||
m_boundLifetimeId = 0;
|
||||
}
|
||||
|
||||
// The session that held the records is gone (MGPipeForgetAllPublications): both halves go,
|
||||
// the record half included, because no applier holds any of them any more.
|
||||
void ForgetAllRecords() {
|
||||
for (Latch& latch : m_latch) latch = Latch{};
|
||||
m_boundHandle = kMGPipeNullHandle;
|
||||
m_boundLifetimeId = 0;
|
||||
}
|
||||
|
||||
void ResetCounters() { m_creates = m_binds = m_bufferSets = m_indexSets = 0; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -3119,12 +3119,10 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
"MOBILEGL_IPC_LOG_FORWARD=1" "MOBILEGL_IPC_TOKEN="
|
||||
"MGITEST_TCP_LANE=1" "MOBILEGL_ITEST_REQUIRE_GPU=1")
|
||||
set(mglD2Extra FIXTURES_REQUIRED mobilegl-tcp)
|
||||
# The loopback supervisor used to serve ONE session (a second Hello was answered
|
||||
# Refuse{Busy}), and `ctest -L integration-gpu -j N` ran this case beside another Tcp
|
||||
# case so that whichever client connected second died Refuse{Busy} ->
|
||||
# Fatal{CapsBeforeFirstSnapshot}. It serves several side by side now (ServerMain.cpp
|
||||
# TcpSupervisor, fork shape); every Tcp entry still holds this lock, so the cases do not
|
||||
# share the fixture's one server and its log while they run.
|
||||
# The loopback supervisor serves ONE session (ServerMain.cpp answers a second Hello
|
||||
# Refuse{Busy}), and every other Tcp entry holds this lock. Without it `ctest -L
|
||||
# integration-gpu -j N` ran this case beside another Tcp case and whichever client
|
||||
# connected second died Refuse{Busy} -> Fatal{CapsBeforeFirstSnapshot}.
|
||||
# scripts/ci/spawn_lane_parity.py and junit_tally.py --discovery now refuse any entry
|
||||
# on the fixture that does not hold it.
|
||||
set(mglD2Locks "${mglD2LogName}\;mobilegl-tcp")
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
//
|
||||
// Before P8-D every wire indirect draw read its commands (and its count word) through
|
||||
// ReadWireBuffer and expanded them on the CPU, and a store a shader had written turned that read
|
||||
// into a whole-GPU wait per draw (create-indirect: 321 expansions, 327 waits, ~4-8 s of waiting
|
||||
// per replay on lavapipe). The cases pin both halves of the change:
|
||||
// into a whole-GPU wait per draw (the create-indirect trace, now
|
||||
// minecraft-1.21.1-neoforge-create-indirect-in-world-align1024: 321 expansions, 327 waits, ~4-8 s of
|
||||
// waiting per replay on lavapipe). The cases pin both halves of the change:
|
||||
// * PIXELS, on every arm and both backends where the backend's own semantics allow it - each
|
||||
// indirect form draws exactly the strips its commands name, and GPU-written commands are the
|
||||
// ones the draw sees (the poison the buffers start with names the OTHER strips);
|
||||
@@ -336,8 +337,9 @@ void main() { words[gl_GlobalInvocationID.x] = source[gl_GlobalInvocationID.x];
|
||||
EXPECT_EQ(delta.barriers, 2u) << "one barrier per draw whose count store a shader wrote";
|
||||
}
|
||||
|
||||
// Flywheel's shape (create-indirect's trace: 322 cull-then-draw rounds, no glMemoryBarrier
|
||||
// between them). GL leaves it undefined; the wire arm orders it anyway, once per write,
|
||||
// Flywheel's shape (minecraft-1.21.1-neoforge-create-indirect-in-world-align1024: 322
|
||||
// cull-then-draw rounds, no glMemoryBarrier between them). GL leaves it undefined; the
|
||||
// wire arm orders it anyway, once per write,
|
||||
// because the CPU path it replaced did (by waiting). Magma's split arms only: the monolith
|
||||
// arm records no dependency here (recorded for dev), and Espryt's is its driver's.
|
||||
TEST_F(WireIndirectDrawScenario, ShaderWrittenCommandsWithoutAnApplicationBarrierAreOrdered) {
|
||||
|
||||
@@ -214,8 +214,6 @@ namespace MobileGL::MG_Pipe {
|
||||
TexCubeArray,
|
||||
Tex2DMS,
|
||||
Tex2DMSArray,
|
||||
// GL_TEXTURE_EXTERNAL_OES
|
||||
TexExternalOES,
|
||||
Renderbuffer,
|
||||
TexBuffer,
|
||||
TexRect,
|
||||
@@ -265,10 +263,6 @@ namespace MobileGL::MG_Pipe {
|
||||
return static_cast<Uint32>(MGPipeResourceTarget::TexCubeArray);
|
||||
case MobileGL::TextureTarget::Texture2DMultisampleArray:
|
||||
return static_cast<Uint32>(MGPipeResourceTarget::Tex2DMSArray);
|
||||
// GL_TEXTURE_EXTERNAL_OES gets its own row for the same reason TextureRectangle has one: it is
|
||||
// a real target a descriptor may carry (the compositor's imported dma-buf textures live on it).
|
||||
case MobileGL::TextureTarget::TextureExternalOES:
|
||||
return static_cast<Uint32>(MGPipeResourceTarget::TexExternalOES);
|
||||
// NOT TEXTURE TARGETS. Listed rather than defaulted so the completeness assert still
|
||||
// sees them, and mapped to the sentinel because no descriptor may carry either: the
|
||||
// count is the enum's bound and Unknown is what an unresolved GL enum becomes.
|
||||
|
||||
@@ -341,12 +341,6 @@ namespace MobileGL::MG_Pipe {
|
||||
void MGPipeNoteHandlePublished(MGPipeKind kind, MGPipeHandle handle);
|
||||
Bool MGPipeHandleIsPublished(MGPipeKind kind, MGPipeHandle handle);
|
||||
void MGPipeNoteHandleUnpublished(MGPipeKind kind, MGPipeHandle handle);
|
||||
// THE SESSION IS GONE, AND EVERYTHING IT HELD WITH IT. Called once the split roles are shut
|
||||
// down: every object the server twinned died with the session, so nothing is published any
|
||||
// more - and the frontend objects that die after it (MobileGL::Destroy resets the GL context
|
||||
// after ShutdownSplitRoles, by design) must not route a delete for a twin that no longer
|
||||
// exists to whichever applier is installed now, which asserts on the unknown handle.
|
||||
void MGPipeForgetAllPublications();
|
||||
|
||||
// ---- the four mints (pure allocator work, no family knowledge) ----
|
||||
//
|
||||
|
||||
@@ -264,10 +264,13 @@
|
||||
|
||||
### POST(`kCapAdoptT0` 的前提)
|
||||
|
||||
持续持锁形状:分配 64 KiB AHB,**整个测试期间 CPU lock 不放**,导入,GPU 读 CPU 写的图案、GPU 写一段,经持有的指针读回比较。
|
||||
- Espryt(`Ops_H_SelfTestExternal`):一次性 ES 3.1 pbuffer 上下文(不碰 Espryt 的绑定缓存),`glBufferStorageExternalEXT` + 持久 coherent 映射,映射读一遍,compute shader 把 region 0 拷到输出、在 word 4096 起写 `0x6C0FFEE0 ^ i`。
|
||||
- Magma(`VkBufferManager::SelfTestWireImport`,`VkBufferManager.cpp:768`):renderer 的设备,`vkCmdCopyBuffer` region 0 → staging、`vkCmdFillBuffer` region 4,栅栏等 2 s。
|
||||
- 结果一行 I `T0 POST (<后端>, sustained-lock pattern) PASSED|FAILED - …`。红米(Adreno 830)两后端 PASSED。
|
||||
持续持锁形状:分配 64 KiB AHB,**整个测试期间 CPU lock 不放**,导入,GPU 读 CPU 写的图案、GPU 写一段,经持有的指针读回比较。**两轮**:
|
||||
- 第一轮读的是导入**之前**写进去的图案。导入会顺手清 CPU 缓存,所以只有这一轮的 POST 在「导入之后经持有指针的写 GPU 永远看不见」的设备上照样通过——而 T0 的真实流量全是导入之后的写。
|
||||
- 第二轮(steady,2026-09-30 补):导入且 GPU 用过之后,CPU 才经持有的指针写 region 1、把 region 4(第一轮的 GPU 写)读进缓存;再一次 GPU 工作把 region 1 拷出、改写 region 4,两个方向都比对。两轮都全对才 PASSED。
|
||||
- 实测:Mali-G1-Ultra(天玑,`3B159D009VZ00000`)第一轮全对、第二轮 Magma 读到 0/1024 词、写回 16/1024(import 内存 non-coherent),Espryt 48/1024、160/1024 → FAILED,T0 回退 T2。改之前该机 T0 被授予,`create-indirect-in-world-align1024` × Magma 的 inproc / spawn 丢掉全部 Flywheel 实例物体(0.867 / 0.848),同 trace 的 T2 0.99998;改之后两臂 0.999984。红米(Adreno 830)两后端两轮全对(Magma coherent),T0 照旧授予。
|
||||
- Espryt(`Ops_H_SelfTestExternal`,第二轮 `SelfTestExternalSteady`):一次性 ES 3.1 pbuffer 上下文(不碰 Espryt 的绑定缓存),`glBufferStorageExternalEXT` + 持久 coherent 映射,映射读一遍,compute shader 把 region 0 拷到输出、在 word 4096 起写 `0x6C0FFEE0 ^ i`;第二轮另一个 compute program 拷 word 1024 起、在 word 4096 起写 `0x3D5EA11E ^ i`。
|
||||
- Magma(`VkBufferManager::SelfTestWireImport`,`VkBufferManager.cpp:768`):renderer 的设备,`vkCmdCopyBuffer` region 0 → staging、`vkCmdFillBuffer` region 4,栅栏等 2 s;第二轮同一命令池重录:region 1 → staging、region 4 填 `0x3D5EA11E`。
|
||||
- 结果一行 I `T0 POST (<后端>, sustained-lock pattern) PASSED|FAILED - …`,两轮的计数都在这一行。红米(Adreno 830)两后端 PASSED;Mali-G1-Ultra 两后端 FAILED(缺省旋钮下这行降为 D,见上表)。
|
||||
|
||||
### server 端存储
|
||||
|
||||
|
||||
@@ -216,10 +216,6 @@ namespace MobileGL::MG_Remote::Client {
|
||||
WaitForApplyBeforeEglForwarder("CreateEGLWindowSurface");
|
||||
// P12 (D1): unless the window is the SERVER's - then there is no handle of ours to tell.
|
||||
if (MG_Config::ServerOwnedWindowSurfaces()) return CreateServerOwnedWindowSurface(surface, handle);
|
||||
// The other on-screen shape: the frames belong to the display host, and the server takes
|
||||
// them from the bridge. As for the server-owned shape, no window of the client's crosses
|
||||
// the wire - only the size it asked for.
|
||||
if (MG_Config::HostFrameWindowSurfaces()) return CreateHostFrameWindowSurface(surface, handle);
|
||||
Server::ServerSetWindowHandle(handle);
|
||||
if (!Server::ServerCreateEGLWindowSurface(surface, handle)) return false;
|
||||
// The server's surface init published the default framebuffer's shape as a
|
||||
@@ -299,10 +295,6 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// dereferenced - the client's InitWindowSurface is a no-op - and never crosses the wire
|
||||
// (the ServerOwned frame carries token 0).
|
||||
char g_serverOwnedWindowPlaceholder = 0;
|
||||
// The host-framed shape names no window of the client's either; the base class still wants
|
||||
// a handle to register the surface with, and this is the same stand-in the server-owned
|
||||
// shape uses.
|
||||
char g_hostFrameWindowPlaceholder = 0;
|
||||
} // namespace
|
||||
|
||||
Bool BackendObject_Remote::CreateServerOwnedWindowSurface(EGLSurface surface,
|
||||
@@ -368,46 +360,6 @@ namespace MobileGL::MG_Remote::Client {
|
||||
return MG_Backend::BackendObject::CreateEGLWindowSurface(surface, local);
|
||||
}
|
||||
|
||||
Bool BackendObject_Remote::CreateHostFrameWindowSurface(EGLSurface surface,
|
||||
const MG_Backend::WindowHandle& handle) {
|
||||
// The size crosses the wire and nothing else of the client's does: the server takes frames
|
||||
// from the display host at that size and answers with the extent the surface has.
|
||||
const Server::ServerOwnedWindowReply reply =
|
||||
Server::ServerCreateHostFrameWindowSurface(surface, handle.Width, handle.Height);
|
||||
if (!reply.ok) {
|
||||
// FAILS BY NAME ON THIS SIDE TOO, as the server-owned shape does: the server logged its
|
||||
// reason, and the refusal code is what lets this line say the same thing.
|
||||
switch (reply.refusal) {
|
||||
case Server::SurfaceRefusalCode::SurfaceModeMismatch:
|
||||
MGLOG_E("MG_Remote client: Refuse HostFrame (SurfaceModeMismatch) - MOBILEGL_IPC_SURFACE=host "
|
||||
"asked for this %ux%u window surface in a session that already chose a pbuffer: only "
|
||||
"one rendering path is active per session. eglCreateWindowSurface fails with "
|
||||
"EGL_BAD_NATIVE_WINDOW",
|
||||
handle.Width, handle.Height);
|
||||
break;
|
||||
case Server::SurfaceRefusalCode::NoServerWindow:
|
||||
MGLOG_E("MG_Remote client: Refuse HostFrame (NoServerWindow) - the server could not take a frame "
|
||||
"from the display host for this %ux%u surface; its log names what the host or the "
|
||||
"bridge said (its own answer was %ux%u)",
|
||||
handle.Width, handle.Height, reply.width, reply.height);
|
||||
break;
|
||||
default:
|
||||
MGLOG_E("MG_Remote client: Refuse HostFrame (code %u) for this %ux%u window surface",
|
||||
static_cast<Uint>(reply.refusal), handle.Width, handle.Height);
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// From here the frames are the server's and the host's business; this side only registers the
|
||||
// surface, exactly as it does for the server-owned shape.
|
||||
MG_Backend::WindowHandle local = handle;
|
||||
if (local.Backend == MG_Backend::WindowBackend::Unknown) local.Backend = MG_Backend::WindowBackend::Android;
|
||||
if (local.Handle == nullptr) local.Handle = &g_hostFrameWindowPlaceholder;
|
||||
local.Width = reply.width;
|
||||
local.Height = reply.height;
|
||||
return MG_Backend::BackendObject::CreateEGLWindowSurface(surface, local);
|
||||
}
|
||||
|
||||
Bool BackendObject_Remote::MakeEGLCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read,
|
||||
EGLContext ctx) {
|
||||
// FORWARD FIRST, THEN RUN THE BASE. The server has to own the context before the base
|
||||
|
||||
@@ -91,9 +91,6 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// CreateEGLWindowSurface - ONE ServerOwned frame, no SetWindowHandle, the server's real
|
||||
// geometry adopted before it returns, and every refusal named in this process's log.
|
||||
Bool CreateServerOwnedWindowSurface(EGLSurface surface, const MG_Backend::WindowHandle& handle);
|
||||
// MOBILEGL_IPC_SURFACE=host: the frames are the display host's, and the server takes
|
||||
// them from the host frame bridge. Nothing of the client's crosses the wire here either.
|
||||
Bool CreateHostFrameWindowSurface(EGLSurface surface, const MG_Backend::WindowHandle& handle);
|
||||
|
||||
// The generation of the snapshot m_formatCapabilities was filled from. Exposed only
|
||||
// through the log line on a refresh: a cache that silently stopped tracking the mirror
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Remote/Client/DmaBufImport.cpp
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
#include "DmaBufImport.h"
|
||||
|
||||
#include "ClientSession.h"
|
||||
#include "../Protocol/mg_protocol_base.h"
|
||||
#include "../Transport/ITransport.h"
|
||||
|
||||
namespace MobileGL::MG_Remote::Client {
|
||||
|
||||
Bool ShareImportedDmaBuf(Uint32 target, Uint32 texName, Uint32 width, Uint32 height, Uint32 fourCC,
|
||||
Uint32 planeIndex, Uint32 planeCount, Int planeFd, Int stride, Int offset,
|
||||
Uint64 modifier, Bool hasModifier) {
|
||||
if (planeFd < 0 || planeCount == 0 || planeCount > kDmaBufImportMaxPlanes) return false;
|
||||
// The session's control-plane transport is where the descriptor channel lives; no session or
|
||||
// no channel (a TCP session whose aux came up without SCM_RIGHTS) is a named refusal here.
|
||||
ClientSession* session = ClientSession::Active();
|
||||
if (session == nullptr) return false;
|
||||
Transport::ITransport* transport = session->Control_Plane();
|
||||
if (transport == nullptr) return false;
|
||||
|
||||
DmaBufImportRequest request{};
|
||||
request.Magic = kDmaBufImportRequestMagic;
|
||||
request.Version = kDmaBufImportVersion;
|
||||
request.Target = target;
|
||||
request.TexName = texName;
|
||||
request.Width = width;
|
||||
request.Height = height;
|
||||
request.FourCC = fourCC;
|
||||
request.PlaneCount = planeCount;
|
||||
request.Stride[planeIndex % kDmaBufImportMaxPlanes] = stride;
|
||||
request.Offset[planeIndex % kDmaBufImportMaxPlanes] = offset;
|
||||
request.Modifier[planeIndex % kDmaBufImportMaxPlanes] = modifier;
|
||||
request.HasModifier[planeIndex % kDmaBufImportMaxPlanes] = hasModifier ? 1u : 0u;
|
||||
|
||||
MobileGLByteSpan sideband{};
|
||||
sideband.data = &request;
|
||||
sideband.size = sizeof(request);
|
||||
return transport->ShareFd(planeFd, sideband) == MOBILEGL_OK;
|
||||
}
|
||||
} // namespace MobileGL::MG_Remote::Client
|
||||
@@ -1,53 +0,0 @@
|
||||
// MobileGL - MobileGL/MG_Remote/Client/DmaBufImport.h
|
||||
// SPDX-License-Identifier: LGPL-3.0-only
|
||||
// End of Source File Header
|
||||
|
||||
// TELLING THE RENDER SERVER WHICH TEXTURE A dma-buf BACKS.
|
||||
//
|
||||
// The compositor's scene reaches the display daemon's buffers through glEGLImageTargetTexture2DOES:
|
||||
// eglCreateImageKHR already holds a dup() of every plane's descriptor, and a texture bound to that
|
||||
// image has NO storage on the server - so a framebuffer built over it is not complete and kwin aborts
|
||||
// on its own RenderTarget assertion (measured, twice: "taking target 0x8d65 over an EGLImage of
|
||||
// 1440x3200 fourcc 0x34324241 ... the render server has NOT been told which texture that dma-buf
|
||||
// backs yet"). This is the client's half of closing that: one message per plane, each carrying one
|
||||
// descriptor in the SCM_RIGHTS control data of the session transport's aux socket (ITransport::ShareFd,
|
||||
// FdPassing.h - "a dedicated AF_UNIX SOCK_DGRAM socketpair, so one sendmsg is exactly one recvmsg").
|
||||
//
|
||||
// The byte layout is restated from the server's reader rather than shared with it, for the same reason
|
||||
// the GBM frame shapes are (MG_Backend/GbmFrameChannel.h): the two ends are built into different
|
||||
// libraries from different build configurations. A change on either side is a protocol change, and the
|
||||
// magic is what makes a mismatched pair fail loudly instead of being read as plausible numbers.
|
||||
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
|
||||
namespace MobileGL::MG_Remote::Client {
|
||||
|
||||
inline constexpr Uint32 kDmaBufImportRequestMagic = 0x4947474Du; // 'M','G','G','I' in memory order
|
||||
inline constexpr Uint32 kDmaBufImportVersion = 1u;
|
||||
inline constexpr Uint32 kDmaBufImportMaxPlanes = 4u;
|
||||
|
||||
struct DmaBufImportRequest {
|
||||
Uint32 Magic;
|
||||
Uint32 Version;
|
||||
Uint32 Target; // the GL texture target the image was bound to (0x8D65 = GL_TEXTURE_EXTERNAL_OES)
|
||||
Uint32 TexName; // THIS side's texture name; the server resolves its twin
|
||||
Uint32 Width;
|
||||
Uint32 Height;
|
||||
Uint32 FourCC;
|
||||
Uint32 PlaneCount;
|
||||
Int32 Stride[kDmaBufImportMaxPlanes];
|
||||
Int32 Offset[kDmaBufImportMaxPlanes];
|
||||
Uint64 Modifier[kDmaBufImportMaxPlanes];
|
||||
Uint32 HasModifier[kDmaBufImportMaxPlanes];
|
||||
} __attribute__((packed));
|
||||
|
||||
// Shares one plane's descriptor with the server, describing the buffer in the same fields
|
||||
// drmModeAddFB2 takes. Answers false when the session has no descriptor channel (auxFd == -1:
|
||||
// SocketTransport answers MOBILEGL_ERR_UNSUPPORTED) or when the send failed - the caller keeps
|
||||
// treating the texture as having no storage, which is the honest state, rather than rendering
|
||||
// into nothing.
|
||||
Bool ShareImportedDmaBuf(Uint32 target, Uint32 texName, Uint32 width, Uint32 height, Uint32 fourCC,
|
||||
Uint32 planeIndex, Uint32 planeCount, Int planeFd, Int stride, Int offset,
|
||||
Uint64 modifier, Bool hasModifier);
|
||||
} // namespace MobileGL::MG_Remote::Client
|
||||
@@ -513,18 +513,6 @@ namespace MobileGL::MG_Remote::Client {
|
||||
if (CreateIsSuspect(handle) || g_createSuspects.size() >= kCreateSuspectMax) return;
|
||||
g_createSuspects.push_back(handle);
|
||||
}
|
||||
// THE WINDOW IS A SESSION'S, NOT THE PROCESS'S. Every entry names a sequence number of the
|
||||
// session that wrote it, and a process can run several sessions one after another (eglinfo
|
||||
// terminates one display and initializes the next). An entry left by the previous session
|
||||
// made the new session's first create wait for a sequence number the new server would not
|
||||
// reach for a long time (measured: the second session hung on its first texture create, in
|
||||
// DrainCreateWindow's blocking WaitForApplied). Its answer, and the object it was about,
|
||||
// died with that session; the suspects are that session's handles too.
|
||||
void ForgetPreviousSessionCreates() {
|
||||
g_createWindowHead = 0;
|
||||
g_createWindowCount = 0;
|
||||
g_createSuspects.clear();
|
||||
}
|
||||
void ClearCreateSuspect(MG_Pipe::MGPipeHandle handle) {
|
||||
for (SizeT i = 0; i < g_createSuspects.size(); ++i) {
|
||||
if (g_createSuspects[i].Slot != handle.Slot || g_createSuspects[i].Gen != handle.Gen)
|
||||
@@ -1221,7 +1209,6 @@ namespace MobileGL::MG_Remote::Client {
|
||||
|
||||
void InstallClientWireTables() {
|
||||
using namespace MG_Pipe;
|
||||
ForgetPreviousSessionCreates();
|
||||
|
||||
// DirectGLES normally installs this notice while creating its handle
|
||||
// backend. An independent client never creates that backend: without a
|
||||
|
||||
@@ -58,11 +58,6 @@ namespace MobileGL::MG_Remote {
|
||||
static_assert(static_cast<Uint8>(::MobileGL::Wire::WindowKind::MetalLayer) == 6);
|
||||
// P12's append, on the same terms: the value is wire ABI.
|
||||
static_assert(static_cast<Uint8>(::MobileGL::Wire::WindowKind::ServerOwned) == 7);
|
||||
static_assert(static_cast<Uint8>(::MobileGL::Wire::WindowKind::HostFrame) == 8);
|
||||
static_assert(static_cast<Uint8>(::MobileGL::Wire::SurfaceRefusal::HostFrameOnSetWindowHandle) ==
|
||||
static_cast<Uint8>(Server::SurfaceRefusalCode::HostFrameOnSetWindowHandle));
|
||||
static_assert(Server::kHostFrameWindowBackend > Server::kServerOwnedWindowBackend,
|
||||
"kHostFrameWindowBackend must not collide with the server-owned tag");
|
||||
// The frame's refusal codes ARE the wire's SurfaceRefusal (SurfaceControlFrame.h), pinned
|
||||
// value by value so a schema edit that renumbers either side fails here.
|
||||
using Server::SurfaceRefusalCode;
|
||||
@@ -99,8 +94,6 @@ namespace MobileGL::MG_Remote {
|
||||
case SurfaceWireError::AndroidNativeWindowArrived: return "AndroidNativeWindowArrived";
|
||||
case SurfaceWireError::ServerOwnedTokenNotZero: return "ServerOwnedTokenNotZero";
|
||||
case SurfaceWireError::ServerOwnedOnSetWindowHandle: return "ServerOwnedOnSetWindowHandle";
|
||||
case SurfaceWireError::HostFrameTokenNotZero: return "HostFrameTokenNotZero";
|
||||
case SurfaceWireError::HostFrameOnSetWindowHandle: return "HostFrameOnSetWindowHandle";
|
||||
}
|
||||
return "<unknown SurfaceWireError>";
|
||||
}
|
||||
@@ -174,15 +167,6 @@ namespace MobileGL::MG_Remote {
|
||||
}
|
||||
windowKind = ::MobileGL::Wire::WindowKind::ServerOwned;
|
||||
nativeToken = 0;
|
||||
} else if (frame.windowBackend == Server::kHostFrameWindowBackend) {
|
||||
// MOBILEGL_IPC_SURFACE=host: the frames are the DISPLAY HOST's, taken by the
|
||||
// server from the host frame bridge. As for the server-owned tag - a creation
|
||||
// only, and the token is 0 whatever the frame carried.
|
||||
if (frame.kind != SurfaceControlOp::CreateWindowSurface) {
|
||||
return SurfaceWireError::HostFrameOnSetWindowHandle;
|
||||
}
|
||||
windowKind = ::MobileGL::Wire::WindowKind::HostFrame;
|
||||
nativeToken = 0;
|
||||
} else if (!WireWindowKindForWindowBackend(
|
||||
static_cast<MG_Backend::WindowBackend>(frame.windowBackend), &windowKind)) {
|
||||
return SurfaceWireError::UnknownWindowKind;
|
||||
@@ -229,21 +213,6 @@ namespace MobileGL::MG_Remote {
|
||||
*frame = decoded;
|
||||
return SurfaceWireError::None;
|
||||
}
|
||||
if (op.windowKind() == ::MobileGL::Wire::WindowKind::HostFrame) {
|
||||
// MOBILEGL_IPC_SURFACE=host. As above: a creation only, and a token of 0
|
||||
// only - anything else is a value from the peer's window system trying to
|
||||
// cross (Rule G), which is corruption rather than a refusal.
|
||||
if (kind != SurfaceControlOp::CreateWindowSurface) {
|
||||
return SurfaceWireError::HostFrameOnSetWindowHandle;
|
||||
}
|
||||
if (op.nativeToken() != 0) {
|
||||
return SurfaceWireError::HostFrameTokenNotZero;
|
||||
}
|
||||
decoded.windowBackend = Server::kHostFrameWindowBackend;
|
||||
decoded.nativeToken = 0;
|
||||
*frame = decoded;
|
||||
return SurfaceWireError::None;
|
||||
}
|
||||
if (op.windowKind() == ::MobileGL::Wire::WindowKind::AndroidNativeWindow) {
|
||||
// The one refusal that is not corruption: the window kind is LEGAL and the token
|
||||
// is an ANativeWindow*, which names memory in the CLIENT's process. Real window
|
||||
@@ -256,10 +225,10 @@ namespace MobileGL::MG_Remote {
|
||||
}
|
||||
MG_Backend::WindowBackend backend;
|
||||
if (!WindowBackendForWireWindowKind(op.windowKind(), &backend)) {
|
||||
// THE UPPER BOUND IS THE LAST APPENDED KIND (P12: HostFrame), for the reason
|
||||
// THE UPPER BOUND IS THE LAST APPENDED KIND (P12: ServerOwned), for the reason
|
||||
// SurfaceControlOpForWireKind's bound gives.
|
||||
return ::flatbuffers::IsOutRange(op.windowKind(), ::MobileGL::Wire::WindowKind::None,
|
||||
::MobileGL::Wire::WindowKind::HostFrame)
|
||||
::MobileGL::Wire::WindowKind::ServerOwned)
|
||||
? SurfaceWireError::UnknownWindowKind
|
||||
: SurfaceWireError::WindowKindNamesNoBackend;
|
||||
}
|
||||
|
||||
@@ -68,9 +68,6 @@ namespace MobileGL::MG_Remote {
|
||||
// CreateWindowSurface only, and only with nativeToken 0:
|
||||
ServerOwnedTokenNotZero, // -> Fatal{ProtocolCorruption, "SurfaceOp.nativeToken"}, latched
|
||||
ServerOwnedOnSetWindowHandle, // -> a NAMED REFUSAL (reply ok=false), not a latch
|
||||
// MOBILEGL_IPC_SURFACE=host, the same two rules for the other on-screen shape:
|
||||
HostFrameTokenNotZero, // -> Fatal{ProtocolCorruption, "SurfaceOp.nativeToken"}, latched
|
||||
HostFrameOnSetWindowHandle, // -> a NAMED REFUSAL (reply ok=false), not a latch
|
||||
};
|
||||
|
||||
const char* SurfaceWireErrorName(SurfaceWireError error);
|
||||
|
||||
@@ -341,12 +341,11 @@ enum class WindowKind : uint8_t {
|
||||
Pbuffer = 5,
|
||||
MetalLayer = 6,
|
||||
ServerOwned = 7,
|
||||
HostFrame = 8,
|
||||
MIN = None,
|
||||
MAX = HostFrame
|
||||
MAX = ServerOwned
|
||||
};
|
||||
|
||||
inline const WindowKind (&EnumValuesWindowKind())[9] {
|
||||
inline const WindowKind (&EnumValuesWindowKind())[8] {
|
||||
static const WindowKind values[] = {
|
||||
WindowKind::None,
|
||||
WindowKind::AndroidNativeWindow,
|
||||
@@ -355,14 +354,13 @@ inline const WindowKind (&EnumValuesWindowKind())[9] {
|
||||
WindowKind::Surfaceless,
|
||||
WindowKind::Pbuffer,
|
||||
WindowKind::MetalLayer,
|
||||
WindowKind::ServerOwned,
|
||||
WindowKind::HostFrame
|
||||
WindowKind::ServerOwned
|
||||
};
|
||||
return values;
|
||||
}
|
||||
|
||||
inline const char * const *EnumNamesWindowKind() {
|
||||
static const char * const names[10] = {
|
||||
static const char * const names[9] = {
|
||||
"None",
|
||||
"AndroidNativeWindow",
|
||||
"X11",
|
||||
@@ -371,14 +369,13 @@ inline const char * const *EnumNamesWindowKind() {
|
||||
"Pbuffer",
|
||||
"MetalLayer",
|
||||
"ServerOwned",
|
||||
"HostFrame",
|
||||
nullptr
|
||||
};
|
||||
return names;
|
||||
}
|
||||
|
||||
inline const char *EnumNameWindowKind(WindowKind e) {
|
||||
if (::flatbuffers::IsOutRange(e, WindowKind::None, WindowKind::HostFrame)) return "";
|
||||
if (::flatbuffers::IsOutRange(e, WindowKind::None, WindowKind::ServerOwned)) return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesWindowKind()[index];
|
||||
}
|
||||
@@ -389,38 +386,35 @@ enum class SurfaceRefusal : uint8_t {
|
||||
NoServerWindow = 2,
|
||||
SurfaceModeMismatch = 3,
|
||||
ServerOwnedOnSetWindowHandle = 4,
|
||||
HostFrameOnSetWindowHandle = 5,
|
||||
MIN = None,
|
||||
MAX = HostFrameOnSetWindowHandle
|
||||
MAX = ServerOwnedOnSetWindowHandle
|
||||
};
|
||||
|
||||
inline const SurfaceRefusal (&EnumValuesSurfaceRefusal())[6] {
|
||||
inline const SurfaceRefusal (&EnumValuesSurfaceRefusal())[5] {
|
||||
static const SurfaceRefusal values[] = {
|
||||
SurfaceRefusal::None,
|
||||
SurfaceRefusal::NoServerDisplay,
|
||||
SurfaceRefusal::NoServerWindow,
|
||||
SurfaceRefusal::SurfaceModeMismatch,
|
||||
SurfaceRefusal::ServerOwnedOnSetWindowHandle,
|
||||
SurfaceRefusal::HostFrameOnSetWindowHandle
|
||||
SurfaceRefusal::ServerOwnedOnSetWindowHandle
|
||||
};
|
||||
return values;
|
||||
}
|
||||
|
||||
inline const char * const *EnumNamesSurfaceRefusal() {
|
||||
static const char * const names[7] = {
|
||||
static const char * const names[6] = {
|
||||
"None",
|
||||
"NoServerDisplay",
|
||||
"NoServerWindow",
|
||||
"SurfaceModeMismatch",
|
||||
"ServerOwnedOnSetWindowHandle",
|
||||
"HostFrameOnSetWindowHandle",
|
||||
nullptr
|
||||
};
|
||||
return names;
|
||||
}
|
||||
|
||||
inline const char *EnumNameSurfaceRefusal(SurfaceRefusal e) {
|
||||
if (::flatbuffers::IsOutRange(e, SurfaceRefusal::None, SurfaceRefusal::HostFrameOnSetWindowHandle)) return "";
|
||||
if (::flatbuffers::IsOutRange(e, SurfaceRefusal::None, SurfaceRefusal::ServerOwnedOnSetWindowHandle)) return "";
|
||||
const size_t index = static_cast<size_t>(e);
|
||||
return EnumNamesSurfaceRefusal()[index];
|
||||
}
|
||||
|
||||
@@ -274,12 +274,6 @@ enum WindowKind : ubyte {
|
||||
// SurfaceView) and has none of its own to name, so `nativeToken` is always 0 and no pointer
|
||||
// crosses (Rule G/H). Legal on CreateWindowSurface only; SetWindowHandle may not name it.
|
||||
ServerOwned = 7,
|
||||
// P12, appended: the OTHER on-screen shape, and its mirror image. The client names no
|
||||
// window here either - but the frames are the DISPLAY HOST's: it allocates them, offers
|
||||
// each one over the host frame bridge, and puts them on the glass itself, while the
|
||||
// server draws into them. `nativeToken` is always 0, as for ServerOwned, and it is legal
|
||||
// on CreateWindowSurface only.
|
||||
HostFrame = 8,
|
||||
}
|
||||
|
||||
// P12, appended: WHY A SURFACE OP WAS DECLINED, so the client can name the refusal in its own log
|
||||
@@ -291,7 +285,6 @@ enum SurfaceRefusal : ubyte {
|
||||
NoServerWindow = 2, // the server owns a display, but no window came within its wait
|
||||
SurfaceModeMismatch = 3, // the session's surface mode (on-screen / offscreen) is the other one
|
||||
ServerOwnedOnSetWindowHandle = 4, // SetWindowHandle named the server's own window
|
||||
HostFrameOnSetWindowHandle = 5, // SetWindowHandle named the display host's frames
|
||||
}
|
||||
|
||||
table SurfaceOp {
|
||||
|
||||
@@ -404,15 +404,6 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// was wanted, recorded here so a future swap-without-present is looked for rather than
|
||||
// assumed impossible. Presents() is exposed for a lane that wants to make the comparison.
|
||||
table->Present();
|
||||
// A HOST-FRAMED SURFACE IS PRESENTED BY TELLING THE HOST, not by the swap above (which
|
||||
// swaps the pbuffer the context was made with). BackendObject::SwapEGLBuffers is the
|
||||
// only other route to PresentHostFrame and a split client never reaches it, so this is
|
||||
// where the display host learns the frame is drawn - before the credit goes back, so a
|
||||
// client released by it is released by a frame that is on its way to the glass.
|
||||
if (m_backend != nullptr) {
|
||||
if (!m_backend->PresentHostFrameIfCurrent())
|
||||
MGLOG_E_ONCE("OnPresent: the host frame was not presented (PresentHostFrame failed; see above)");
|
||||
}
|
||||
++m_presents;
|
||||
// FrameSerial 0 means "the server stamps its own" (c1-v1 8.3): P5 has no client-side
|
||||
// present credit, so the client sends 0 and the frame count on this side IS the serial.
|
||||
|
||||
@@ -287,7 +287,6 @@ namespace MobileGL::MG_Remote::Server {
|
||||
m_surfaceMode = SessionSurfaceMode::None;
|
||||
m_holdsWindowLease = false;
|
||||
m_serverOwnedSurfaces.clear();
|
||||
m_hostFrameSurfaces.clear();
|
||||
m_windowLostRequested.store(false, std::memory_order_release);
|
||||
m_serverWindowsLost.store(0, std::memory_order_release);
|
||||
m_testLogFloodLines = ApplyLogFloodLinesForTest();
|
||||
@@ -1339,8 +1338,6 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// P12 (D3): the SERVER's window, asked for by a headless client. Before the unpack,
|
||||
// which would refuse the frame-local tag as a WindowBackend out of range.
|
||||
if (frame.windowBackend == kServerOwnedWindowBackend) return ApplyServerOwnedWindowSurface(backend, frame);
|
||||
// The mirror image: the frames are the display host's, and it presents them.
|
||||
if (frame.windowBackend == kHostFrameWindowBackend) return ApplyHostFrameWindowSurface(backend, frame);
|
||||
MG_Backend::WindowHandle window;
|
||||
if (!UnpackWindowHandle(frame, &window)) {
|
||||
frame.ok = false;
|
||||
@@ -1448,7 +1445,6 @@ namespace MobileGL::MG_Remote::Server {
|
||||
const EGLSurface surface = HandleFromToken<EGLSurface>(frame.surface);
|
||||
backend->ReleaseEGLSurface(surface);
|
||||
ForgetServerOwnedSurface(surface);
|
||||
ForgetHostFrameSurface(surface);
|
||||
// N-3: a released surface the held tuple names may have taken the context with it
|
||||
// (BackendObject::ReleaseEGLSurface -> OnEGLSurfaceReleased -> DestroyEGLContext once
|
||||
// nothing holds it current). Forgetting when the base class only DEFERRED the destroy
|
||||
@@ -1662,52 +1658,6 @@ namespace MobileGL::MG_Remote::Server {
|
||||
return MOBILEGL_OK;
|
||||
}
|
||||
|
||||
MobileGLResult ServerLoop::ApplyHostFrameWindowSurface(MG_Backend::BackendObject* backend,
|
||||
SurfaceControlFrame& frame) {
|
||||
frame.ok = false;
|
||||
frame.refusal = static_cast<Uint8>(SurfaceRefusalCode::None);
|
||||
const Uint32 wantWidth = frame.width > 0 ? static_cast<Uint32>(frame.width) : 0u;
|
||||
const Uint32 wantHeight = frame.height > 0 ? static_cast<Uint32>(frame.height) : 0u;
|
||||
// Both on-screen shapes are the same session mode: one rendering path per session, and
|
||||
// this is the on-screen one whichever side owns the window.
|
||||
if (!SessionSurfaceModeAdmits(m_surfaceMode, /*serverOwnedWindow=*/true)) {
|
||||
frame.refusal = static_cast<Uint8>(SurfaceRefusalCode::SurfaceModeMismatch);
|
||||
MGLOG_E("MG_Remote server: SurfaceModeMismatch - a HostFrame CreateWindowSurface (seq %llu, "
|
||||
"%ux%u) in a session whose surface mode is %s. Refused, the session is not latched",
|
||||
static_cast<unsigned long long>(frame.seq), wantWidth, wantHeight,
|
||||
SessionSurfaceModeName(m_surfaceMode));
|
||||
return MOBILEGL_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
const EGLSurface surface = HandleFromToken<EGLSurface>(frame.surface);
|
||||
// THE SUBSTITUTION, the other way round from ServerOwned: nothing of the client's and
|
||||
// nothing of the server's goes into the backend call - the backend takes the frames from
|
||||
// the display host, and every swap hands the next one back to it.
|
||||
frame.ok = backend->CreateEGLHostFrameSurface(surface, wantWidth, wantHeight);
|
||||
if (!frame.ok) {
|
||||
MGLOG_E("MG_Remote server: the backend could not take the display host frames (seq %llu, %ux%u)",
|
||||
static_cast<unsigned long long>(frame.seq), wantWidth, wantHeight);
|
||||
return MOBILEGL_OK;
|
||||
}
|
||||
ForgetCurrentTuple();
|
||||
m_surfaceMode = SessionSurfaceMode::OnScreen;
|
||||
if (!IsHostFrameSurface(surface)) m_hostFrameSurfaces.push_back(surface);
|
||||
frame.width = static_cast<Int>(wantWidth);
|
||||
frame.height = static_cast<Int>(wantHeight);
|
||||
MGLOG_I("MG_Remote server: surface=window %ux%u owner=host (HostFrame seq %llu)", wantWidth,
|
||||
wantHeight, static_cast<unsigned long long>(frame.seq));
|
||||
return MOBILEGL_OK;
|
||||
}
|
||||
|
||||
Bool ServerLoop::IsHostFrameSurface(EGLSurface surface) const {
|
||||
return std::find(m_hostFrameSurfaces.begin(), m_hostFrameSurfaces.end(), surface) !=
|
||||
m_hostFrameSurfaces.end();
|
||||
}
|
||||
|
||||
void ServerLoop::ForgetHostFrameSurface(EGLSurface surface) {
|
||||
m_hostFrameSurfaces.erase(std::remove(m_hostFrameSurfaces.begin(), m_hostFrameSurfaces.end(), surface),
|
||||
m_hostFrameSurfaces.end());
|
||||
}
|
||||
|
||||
Bool ServerLoop::IsServerOwnedSurface(EGLSurface surface) const {
|
||||
return std::find(m_serverOwnedSurfaces.begin(), m_serverOwnedSurfaces.end(), surface) !=
|
||||
m_serverOwnedSurfaces.end();
|
||||
@@ -1820,25 +1770,6 @@ namespace MobileGL::MG_Remote::Server {
|
||||
return rc == MOBILEGL_OK && frame.ok;
|
||||
}
|
||||
|
||||
ServerOwnedWindowReply ServerCreateHostFrameWindowSurface(EGLSurface surface, Uint32 width, Uint32 height) {
|
||||
// One frame, and no SetWindowHandle in front of it: the client names no window, and this
|
||||
// side does not make one - the frames are the display host's, taken from the bridge.
|
||||
SurfaceControlFrame frame;
|
||||
frame.kind = SurfaceControlOp::CreateWindowSurface;
|
||||
frame.surface = TokenFromHandle(surface);
|
||||
frame.windowBackend = kHostFrameWindowBackend;
|
||||
frame.nativeToken = 0;
|
||||
frame.width = static_cast<Int>(width);
|
||||
frame.height = static_cast<Int>(height);
|
||||
const MobileGLResult rc = ServerLoopInstance().RunSurfaceControlFrame(frame);
|
||||
ServerOwnedWindowReply reply;
|
||||
reply.transport = rc;
|
||||
reply.ok = rc == MOBILEGL_OK && frame.ok;
|
||||
reply.refusal = static_cast<SurfaceRefusalCode>(frame.refusal);
|
||||
reply.width = frame.width > 0 ? static_cast<Uint32>(frame.width) : 0u;
|
||||
reply.height = frame.height > 0 ? static_cast<Uint32>(frame.height) : 0u;
|
||||
return reply;
|
||||
}
|
||||
ServerOwnedWindowReply ServerCreateServerOwnedWindowSurface(EGLSurface surface, Uint32 width, Uint32 height) {
|
||||
// P12 (D1/D2): ONE frame, and no SetWindowHandle in front of it - the window is the
|
||||
// server's, so there is nothing of the client's to name. The frame-local tag is what the
|
||||
|
||||
@@ -459,9 +459,6 @@ namespace MobileGL::MG_Remote::Server {
|
||||
|
||||
// P12. The ServerOwned arm of the CreateWindowSurface dispatch (D3, D4).
|
||||
MobileGLResult ApplyServerOwnedWindowSurface(MG_Backend::BackendObject* backend, SurfaceControlFrame& frame);
|
||||
MobileGLResult ApplyHostFrameWindowSurface(MG_Backend::BackendObject* backend, SurfaceControlFrame& frame);
|
||||
Bool IsHostFrameSurface(EGLSurface surface) const;
|
||||
void ForgetHostFrameSurface(EGLSurface surface);
|
||||
// P12 (D6), apply thread: the lost window's backend surface goes, the lease ends, and the
|
||||
// session latches ServerWindowLost. Runs from PumpControlRequest when Detach asked.
|
||||
void ReleaseLostServerWindow();
|
||||
@@ -474,10 +471,6 @@ namespace MobileGL::MG_Remote::Server {
|
||||
void ForgetServerOwnedSurface(EGLSurface surface);
|
||||
// Apply thread only: this session's surfaces created on the server's window; reset by Start().
|
||||
std::vector<EGLSurface> m_serverOwnedSurfaces;
|
||||
// The surfaces whose drawing target is a frame the display host owns. Kept apart from
|
||||
// the server-owned list because the two are different paths with different owners,
|
||||
// and a resize or a release has to reach the right one.
|
||||
std::vector<EGLSurface> m_hostFrameSurfaces;
|
||||
// ServerDisplay's lost hook: called under the display's lock from Detach's thread. Sets the
|
||||
// request and rings the apply thread's bell; never blocks.
|
||||
static void ServerWindowLostThunk(void* self);
|
||||
@@ -666,10 +659,6 @@ namespace MobileGL::MG_Remote::Server {
|
||||
Uint32 height = 0;
|
||||
};
|
||||
ServerOwnedWindowReply ServerCreateServerOwnedWindowSurface(EGLSurface surface, Uint32 width, Uint32 height);
|
||||
// The host-framed on-screen shape (MOBILEGL_IPC_SURFACE=host): the client names no window
|
||||
// either, but the frames come from the display host over the host frame bridge, and the
|
||||
// host presents them. The reply carries the size the surface was made at.
|
||||
ServerOwnedWindowReply ServerCreateHostFrameWindowSurface(EGLSurface surface, Uint32 width, Uint32 height);
|
||||
// P12 review fix: ResizeWindowSurface for a surface created on the server's window. The server
|
||||
// resizes its WINDOW (a geometry request) and replies with the window's real extent.
|
||||
ServerOwnedWindowReply ServerResizeServerOwnedWindowSurface(EGLSurface surface, Uint32 width, Uint32 height);
|
||||
|
||||
@@ -1035,32 +1035,12 @@ private:
|
||||
};
|
||||
|
||||
bool Reap() {
|
||||
if (m_handoffShape == Handoff::Thread) {
|
||||
const bool reaped = ReapSessionThread();
|
||||
if (m_active <= 0 && m_handoff >= 0) { ::close(m_handoff); m_handoff = -1; }
|
||||
return reaped;
|
||||
}
|
||||
// The fork shape: every live child is asked, and a reaped one takes its hand-off with it.
|
||||
bool reaped = false;
|
||||
for (auto child = m_children.begin(); child != m_children.end();) {
|
||||
if (ReapActiveSession(child->pid, m_sessionsFaulted)) {
|
||||
if (child->handoff >= 0) ::close(child->handoff);
|
||||
child = m_children.erase(child);
|
||||
reaped = true;
|
||||
} else {
|
||||
++child;
|
||||
}
|
||||
}
|
||||
m_active = m_children.empty() ? -1 : m_children.back().pid;
|
||||
const bool reaped = m_handoffShape == Handoff::Thread ? ReapSessionThread()
|
||||
: ReapActiveSession(m_active, m_sessionsFaulted);
|
||||
if (m_active <= 0 && m_handoff >= 0) { ::close(m_handoff); m_handoff = -1; }
|
||||
return reaped;
|
||||
}
|
||||
|
||||
// Whether an authenticated Hello has to be told Busy: the thread shape serves one session, the
|
||||
// fork shape up to kMaxForkedSessions side by side.
|
||||
bool SessionsFull() const {
|
||||
return m_handoffShape == Handoff::Thread ? m_active > 0 : m_children.size() >= kMaxForkedSessions;
|
||||
}
|
||||
|
||||
// P12 (D5): the thread shape's reap - the same line a forked child's reap prints, and the same
|
||||
// count, then the latch put back for the next session (ResetSessionLatch: the thread took no
|
||||
// process with it, so the latch it armed and maybe latched is still this process's).
|
||||
@@ -1102,7 +1082,7 @@ private:
|
||||
// make the loop wait here; a DataBind's routing takes one look (Judge, fix round).
|
||||
void WaitOutAnExitingSession() {
|
||||
const auto reapDeadline = Clock::now() + std::chrono::milliseconds(50);
|
||||
while (SessionsFull() && Clock::now() < reapDeadline) {
|
||||
while (m_active > 0 && Clock::now() < reapDeadline) {
|
||||
if (Reap()) break;
|
||||
::usleep(1000);
|
||||
}
|
||||
@@ -1196,15 +1176,7 @@ private:
|
||||
// either has cut its hand-off already (the send below fails and is refused by name) or
|
||||
// refuses what is queued on its way out (ExitBeforeAccept / CloseHandoffRefusingQueued).
|
||||
Reap();
|
||||
// WHICH SESSION IT BELONGS TO. The thread shape has one; the fork shape knows every
|
||||
// child's nonce (it minted them, Fork) and hands the connection to the child it names.
|
||||
int handoff = m_active > 0 ? m_handoff : -1;
|
||||
if (m_handoffShape == Handoff::Fork) {
|
||||
handoff = -1;
|
||||
for (const auto& child : m_children)
|
||||
if (ConstantTimeNonceMatch(child.nonce, nonce)) handoff = child.handoff;
|
||||
}
|
||||
if (handoff < 0) {
|
||||
if (m_active <= 0) {
|
||||
// StreamLink's frames may already follow the DataBind; read them away so the close
|
||||
// does not become an RST that discards the refusal.
|
||||
DrainUnread(fd);
|
||||
@@ -1214,7 +1186,7 @@ private:
|
||||
// The send is MSG_DONTWAIT and the child cuts its end the moment its own data
|
||||
// connection is bound (CloseHandoffRefusingQueued), so this either queues the
|
||||
// descriptor for a child that will read or refuse it, or fails and is refused here.
|
||||
if (FdPassing::SendFd(handoff, fd, MobileGLByteSpan{nonce, sizeof(nonce)},
|
||||
if (m_handoff >= 0 && FdPassing::SendFd(m_handoff, fd, MobileGLByteSpan{nonce, sizeof(nonce)},
|
||||
/*dontWait=*/true) == MOBILEGL_OK) {
|
||||
// The child holds its own descriptor now; ours goes without a shutdown(2), which
|
||||
// would disconnect the child's too.
|
||||
@@ -1245,11 +1217,9 @@ private:
|
||||
}
|
||||
m_backoff.NoteSuccess(peer.address);
|
||||
WaitOutAnExitingSession();
|
||||
if (SessionsFull()) {
|
||||
if (m_active > 0) {
|
||||
// The frame is consumed, so closing cannot RST the refusal away.
|
||||
Refuse(*connection, Protocol::RefuseCode::Busy,
|
||||
m_handoffShape == Handoff::Thread ? "one session is already active"
|
||||
: "the session limit is reached");
|
||||
Refuse(*connection, Protocol::RefuseCode::Busy, "one session is already active");
|
||||
return;
|
||||
}
|
||||
Fork(std::move(connection), payload);
|
||||
@@ -1265,25 +1235,12 @@ private:
|
||||
StartSessionThread(std::move(connection), hello, pair);
|
||||
return;
|
||||
}
|
||||
// The child's data nonce, minted HERE so this supervisor can route the child's DataBind to it
|
||||
// among other live sessions; the child adopts it instead of minting its own.
|
||||
LiveChild live;
|
||||
if (SocketTransport::MintNonce(live.nonce, sizeof(live.nonce)) != MOBILEGL_OK) {
|
||||
::close(pair[0]);
|
||||
::close(pair[1]);
|
||||
Refuse(*connection, Protocol::RefuseCode::Busy, "could not mint the session's data nonce");
|
||||
return;
|
||||
}
|
||||
std::fflush(nullptr);
|
||||
const pid_t supervisor = ::getpid();
|
||||
const pid_t child = ::fork();
|
||||
if (child == 0) {
|
||||
// P12 (D8): the child dies with this supervisor, not after its client has gone.
|
||||
DieWithSupervisor(supervisor);
|
||||
Server::PresetDataNonceForThisProcess(live.nonce, sizeof(live.nonce));
|
||||
// The other live sessions' hand-offs are the supervisor's.
|
||||
for (const auto& other : m_children)
|
||||
if (other.handoff >= 0) ::close(other.handoff);
|
||||
// The child owns this one connection and its end of the hand-off. Every OTHER pending
|
||||
// peer's descriptor is closed here, or the supervisor's refusal of that peer would not
|
||||
// end its connection while this session lives.
|
||||
@@ -1303,11 +1260,9 @@ private:
|
||||
Refuse(*connection, Protocol::RefuseCode::Busy, "could not create session child");
|
||||
return;
|
||||
}
|
||||
live.pid = child;
|
||||
live.handoff = pair[0];
|
||||
m_children.push_back(live);
|
||||
m_active = child;
|
||||
::close(pair[1]);
|
||||
m_handoff = pair[0];
|
||||
connection->CloseLocalCopy();
|
||||
}
|
||||
|
||||
@@ -1355,21 +1310,10 @@ private:
|
||||
std::atomic<bool> m_sessionDone{false};
|
||||
std::atomic<int> m_sessionExit{0};
|
||||
unsigned long m_sessionOrdinal = 0;
|
||||
// A live session: the newest child's pid for the fork shape, this process's for the thread shape.
|
||||
pid_t m_active = -1;
|
||||
// The thread shape's end of its session's data-connection hand-off (PH-7 (4)); -1 while no
|
||||
// session is live. It goes with the session: a reaped session can be handed nothing.
|
||||
// The supervisor's end of the live child's data-connection hand-off (PH-7 (4)); -1 while no
|
||||
// session is live. It goes with the child: a reaped session can be handed nothing.
|
||||
int m_handoff = -1;
|
||||
// THE FORK SHAPE'S LIVE SESSIONS, side by side: a desktop is a compositor AND the GL programs
|
||||
// run inside it, each its own client with its own session. Each child keeps its end of the
|
||||
// hand-off and the data nonce this supervisor minted for it, which is how a DataBind finds it.
|
||||
struct LiveChild {
|
||||
pid_t pid = -1;
|
||||
int handoff = -1;
|
||||
std::uint8_t nonce[kDataNonceBytes] = {};
|
||||
};
|
||||
static constexpr std::size_t kMaxForkedSessions = 8;
|
||||
std::vector<LiveChild> m_children;
|
||||
std::vector<PendingPeer> m_pending;
|
||||
std::vector<PendingPeer> m_ready;
|
||||
// Accepting resumes at this time after accept(2) ran out of descriptors or memory.
|
||||
|
||||
@@ -42,24 +42,6 @@
|
||||
#endif
|
||||
|
||||
namespace MobileGL::MG_Remote::Server {
|
||||
namespace {
|
||||
Uint8 g_presetDataNonce[Transport::kDataNonceBytes] = {};
|
||||
Bool g_presetDataNonceSet = false;
|
||||
|
||||
Bool TakePresetDataNonce(Uint8* out, SizeT size) {
|
||||
if (!g_presetDataNonceSet || size != sizeof(g_presetDataNonce)) return false;
|
||||
std::memcpy(out, g_presetDataNonce, size);
|
||||
g_presetDataNonceSet = false;
|
||||
return true;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void PresetDataNonceForThisProcess(const Uint8* nonce, SizeT size) {
|
||||
if (nonce == nullptr || size != sizeof(g_presetDataNonce)) return;
|
||||
std::memcpy(g_presetDataNonce, nonce, size);
|
||||
g_presetDataNonceSet = true;
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
// F1 (P7 wave 2). THE ONLY KNOB THAT CAN MAKE THE FIRST CapsSnapshot LATE.
|
||||
@@ -734,9 +716,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
if (socket == nullptr || !socket->IsTcp() || !m_dataSource)
|
||||
return RefuseHandshake(transport, ::MobileGL::Wire::RefuseCode::LinkTerms,
|
||||
"stream needs a TCP control connection and a data-connection source");
|
||||
created = TakePresetDataNonce(dataNonce, sizeof(dataNonce))
|
||||
? MOBILEGL_OK
|
||||
: Transport::SocketTransport::MintNonce(dataNonce, sizeof(dataNonce));
|
||||
created = Transport::SocketTransport::MintNonce(dataNonce, sizeof(dataNonce));
|
||||
if (created != MOBILEGL_OK) {
|
||||
// (F fix round) The peer is told by name instead of seeing a bare close. The
|
||||
// return value stays the fault it is - exit 67 in ServerMain, counted in
|
||||
|
||||
@@ -63,13 +63,6 @@
|
||||
|
||||
namespace MobileGL::MG_Remote::Server {
|
||||
|
||||
// THE DATA NONCE A FORKED SESSION CHILD IS BORN WITH. The TCP supervisor serves sessions side by
|
||||
// side and routes each data connection (DataBind) to the child whose nonce it presents, so it has
|
||||
// to know every child's nonce: it mints the nonce itself just before fork() and the child adopts
|
||||
// it here instead of minting its own. One use: the session that takes it clears it. Never set in
|
||||
// a process that runs more than one session, so the shared storage is the child's alone.
|
||||
void PresetDataNonceForThisProcess(const Uint8* nonce, SizeT size);
|
||||
|
||||
class ServerSession {
|
||||
public:
|
||||
static ServerSession* Active();
|
||||
|
||||
@@ -60,7 +60,6 @@ namespace MobileGL::MG_Remote::Server {
|
||||
case SurfaceRefusalCode::NoServerWindow: return "NoServerWindow";
|
||||
case SurfaceRefusalCode::SurfaceModeMismatch: return "SurfaceModeMismatch";
|
||||
case SurfaceRefusalCode::ServerOwnedOnSetWindowHandle: return "ServerOwnedOnSetWindowHandle";
|
||||
case SurfaceRefusalCode::HostFrameOnSetWindowHandle: return "HostFrameOnSetWindowHandle";
|
||||
}
|
||||
return "<unknown SurfaceRefusalCode>";
|
||||
}
|
||||
|
||||
@@ -87,14 +87,6 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// substitutes its own window there; no pointer crosses the wire (Rule G/H).
|
||||
inline constexpr Int kServerOwnedWindowBackend = 0x10000;
|
||||
|
||||
// The OTHER on-screen shape, and its mirror image. With MOBILEGL_IPC_SURFACE=server the
|
||||
// client has no window and the SERVER's own goes into the backend call; with =host the
|
||||
// client still has no window, but the frames are the display host's - it allocates them,
|
||||
// offers each one over the host frame bridge, and puts them on the glass itself. Same
|
||||
// kind of frame-local tag as the one above, and for the same reason: it names no
|
||||
// WindowBackend of MG_Backend's enum, which is in the pull build (gate G1).
|
||||
inline constexpr Int kHostFrameWindowBackend = 0x10001;
|
||||
|
||||
// P12. Why the server declined a surface op, carried back in the reply half (`refusal`). The
|
||||
// values ARE the wire's SurfaceRefusal (protocol.fbs); SurfaceOpCodec pins the agreement with
|
||||
// static_asserts, the way it pins SurfaceControlOp against SurfaceOpKind. None of them latches
|
||||
@@ -105,7 +97,6 @@ namespace MobileGL::MG_Remote::Server {
|
||||
NoServerWindow = 2, // a display, but no window within the wait
|
||||
SurfaceModeMismatch = 3, // D4: the session's surface mode is the other one
|
||||
ServerOwnedOnSetWindowHandle = 4, // SetWindowHandle named the server's own window
|
||||
HostFrameOnSetWindowHandle = 5, // SetWindowHandle named the display host's frames
|
||||
};
|
||||
|
||||
const char* SurfaceRefusalCodeName(SurfaceRefusalCode code);
|
||||
|
||||
@@ -46,13 +46,6 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
class ITransport {
|
||||
public:
|
||||
virtual ~ITransport() = default;
|
||||
// THE AUX DESCRIPTOR CHANNEL, IF THIS TRANSPORT HAS ONE. SCM_RIGHTS needs a socket of its own
|
||||
// (SocketTransport.h:77), and a caller that wants to hand a dma-buf to the server has to name it:
|
||||
// the session's transport is held as an ITransport, so the seam has to answer here rather than in a
|
||||
// downcast. -1 means "this transport carries no descriptors", which is a legal state a caller must
|
||||
// degrade on - the texture then simply has no storage rather than the process failing.
|
||||
virtual int AuxFd() const { return -1; }
|
||||
|
||||
|
||||
ITransport(const ITransport&) = delete;
|
||||
ITransport& operator=(const ITransport&) = delete;
|
||||
|
||||
@@ -180,7 +180,7 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
// For `sm`'s process discipline and for the arm-proof gate: the fds this
|
||||
// transport owns, so a test can assert the child inherited exactly these.
|
||||
int StreamFd() const { return m_streamFd; }
|
||||
int AuxFd() const override { return m_auxFd; }
|
||||
int AuxFd() const { return m_auxFd; }
|
||||
bool IsTcp() const { return m_tcp; }
|
||||
// TCP's second connection belongs exclusively to the data plane.
|
||||
// Taking it disables all descriptor passing on this transport.
|
||||
|
||||
@@ -8,15 +8,6 @@
|
||||
|
||||
#include "Core.h"
|
||||
#include <EGL/eglext.h>
|
||||
// An imported buffer is held by descriptors, and the copy an image takes of one is the platform's
|
||||
// own dup()/close(): unistd.h's where the import exists, io.h's on the Windows build that compiles
|
||||
// this file but never sees EGL_LINUX_DMA_BUF_EXT.
|
||||
#if defined(_WIN32)
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <cerrno>
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_State {
|
||||
@@ -39,54 +30,6 @@ namespace MobileGL {
|
||||
return Nullopt;
|
||||
}
|
||||
|
||||
// Taking and closing the descriptor an image owns, per platform. Named rather
|
||||
// than spelled inline so the ownership rule reads the same on both.
|
||||
#if defined(_WIN32)
|
||||
Int DuplicateImageDescriptor(Int fd) { return _dup(fd); }
|
||||
void CloseImageDescriptor(Int fd) { _close(fd); }
|
||||
#else
|
||||
Int DuplicateImageDescriptor(Int fd) { return ::dup(fd); }
|
||||
void CloseImageDescriptor(Int fd) { ::close(fd); }
|
||||
#endif
|
||||
|
||||
// ONE PLANE'S ATTRIBUTE SPELLINGS, in plane order. Plane 0's fd/offset/pitch triple
|
||||
// is EGL_EXT_image_dma_buf_import's; plane 3's triple and every MODIFIER_LO/HI pair
|
||||
// belong to EGL_EXT_image_dma_buf_import_modifiers.
|
||||
struct DmaBufPlaneAttributes {
|
||||
EGLint Fd;
|
||||
EGLint Offset;
|
||||
EGLint Pitch;
|
||||
EGLint ModifierLo;
|
||||
EGLint ModifierHi;
|
||||
};
|
||||
|
||||
constexpr DmaBufPlaneAttributes kDmaBufPlaneAttributes[EGLContext::kMaxImagePlanes] = {
|
||||
{EGL_DMA_BUF_PLANE0_FD_EXT, EGL_DMA_BUF_PLANE0_OFFSET_EXT, EGL_DMA_BUF_PLANE0_PITCH_EXT,
|
||||
EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT, EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT},
|
||||
{EGL_DMA_BUF_PLANE1_FD_EXT, EGL_DMA_BUF_PLANE1_OFFSET_EXT, EGL_DMA_BUF_PLANE1_PITCH_EXT,
|
||||
EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT, EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT},
|
||||
{EGL_DMA_BUF_PLANE2_FD_EXT, EGL_DMA_BUF_PLANE2_OFFSET_EXT, EGL_DMA_BUF_PLANE2_PITCH_EXT,
|
||||
EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT, EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT},
|
||||
{EGL_DMA_BUF_PLANE3_FD_EXT, EGL_DMA_BUF_PLANE3_OFFSET_EXT, EGL_DMA_BUF_PLANE3_PITCH_EXT,
|
||||
EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT, EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT},
|
||||
};
|
||||
|
||||
// The EGL spelling of one plane attribute, for the single line a refused image gets:
|
||||
// the attribute list is gone by the time the caller reads eglGetError.
|
||||
String DmaBufPlaneAttributeName(Int plane, const char* role) {
|
||||
return std::format("EGL_DMA_BUF_PLANE{}_{}", plane, role);
|
||||
}
|
||||
|
||||
// Whether the caller mentioned this plane at all, so that a description with a hole
|
||||
// in it can be refused by name instead of silently losing the planes past the hole.
|
||||
Bool HasAnyPlaneAttribute(const EGLAttrib* attribList, Int plane) {
|
||||
const DmaBufPlaneAttributes& attributes = kDmaBufPlaneAttributes[plane];
|
||||
return ParseAttribValue(attribList, attributes.Fd) || ParseAttribValue(attribList, attributes.Offset) ||
|
||||
ParseAttribValue(attribList, attributes.Pitch) ||
|
||||
ParseAttribValue(attribList, attributes.ModifierLo) ||
|
||||
ParseAttribValue(attribList, attributes.ModifierHi);
|
||||
}
|
||||
|
||||
EGLint QueryDefaultX11VisualId() {
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
const char* displayName = std::getenv("DISPLAY");
|
||||
@@ -349,9 +292,6 @@ namespace MobileGL {
|
||||
|
||||
for (auto imageIt = m_images.begin(); imageIt != m_images.end();) {
|
||||
if (imageIt->second.Display == display) {
|
||||
// The display is going away and takes its images with it, so the descriptors
|
||||
// they own go too: an image erased without this leaks an fd per plane.
|
||||
ReleaseImageDescriptors(imageIt->second);
|
||||
imageIt = m_images.erase(imageIt);
|
||||
} else {
|
||||
++imageIt;
|
||||
@@ -394,16 +334,6 @@ namespace MobileGL {
|
||||
return displayObject && displayObject->Initialized;
|
||||
}
|
||||
|
||||
Bool EGLContext::GetDisplayNative(EGLDisplayHandle display, Uint64* nativeDisplayKey,
|
||||
EGLenum* platform) const {
|
||||
const std::lock_guard<std::recursive_mutex> lock(m_mutex);
|
||||
const auto* displayObject = TryGetDisplay(display);
|
||||
if (!displayObject) return false;
|
||||
*nativeDisplayKey = displayObject->NativeDisplayKey;
|
||||
*platform = displayObject->Platform;
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool EGLContext::InitializeDisplay(EGLDisplayHandle display, EGLint* major, EGLint* minor) {
|
||||
const std::lock_guard<std::recursive_mutex> lock(m_mutex);
|
||||
auto* displayObject = TryGetDisplay(display);
|
||||
@@ -487,12 +417,6 @@ namespace MobileGL {
|
||||
for (SizeT i = 0; attribList[i] != EGL_NONE; i += 2) {
|
||||
const EGLint attr = attribList[i];
|
||||
const EGLint requested = attribList[i + 1];
|
||||
// WHAT DIES HERE, exactly: with an attribute list present this loop is where
|
||||
// eglChooseConfig faults (a NULL list survives it and answers two configs),
|
||||
// and the fault is one instruction inside the attribute switch. These two
|
||||
// lines name the attribute and the config before either is dereferenced.
|
||||
MGLOG_I("chooseConfig: attr=0x%04x requested=%d config=%p", attr, requested,
|
||||
static_cast<const void*>(cfg));
|
||||
if (requested == EGL_DONT_CARE) {
|
||||
continue;
|
||||
}
|
||||
@@ -701,13 +625,7 @@ namespace MobileGL {
|
||||
SetError(EGL_NOT_INITIALIZED);
|
||||
return nullptr;
|
||||
}
|
||||
// EGL_KHR_no_config_context: a context with NO config of its own. It is the shape a
|
||||
// compositor asks for - its contexts are used with whatever framebuffer the frame
|
||||
// needs, so pinning one config to the context would be a claim about the future the
|
||||
// caller does not have - and EGL spells the request as this null handle. A context
|
||||
// that does name a config is validated exactly as before.
|
||||
const Bool noConfigContext = (config == nullptr);
|
||||
if (!noConfigContext && !ValidateConfigOnDisplay(display, config)) {
|
||||
if (!ValidateConfigOnDisplay(display, config)) {
|
||||
SetError(EGL_BAD_CONFIG);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1173,18 +1091,6 @@ namespace MobileGL {
|
||||
return surface;
|
||||
}
|
||||
|
||||
// MOBILEGL_IPC_SURFACE=host: the registration is the server-owned one verbatim, because
|
||||
// what makes a window surface host-framed is not its EGL state but where its pixels go -
|
||||
// and that is decided one layer down, by the backend the creation calls next.
|
||||
EGLContext::EGLSurfaceHandle EGLContext::CreateHostFrameWindowSurface(EGLDisplayHandle display,
|
||||
EGLConfigHandle config,
|
||||
const void* nativeWindow,
|
||||
EGLint width, EGLint height,
|
||||
Bool platformWindow) {
|
||||
return CreateServerOwnedWindowSurface(display, config, nativeWindow, width, height,
|
||||
platformWindow);
|
||||
}
|
||||
|
||||
Bool EGLContext::SetSurfaceExtent(EGLSurfaceHandle surface, EGLint width, EGLint height) {
|
||||
const std::lock_guard<std::recursive_mutex> lock(m_mutex);
|
||||
auto surfaceIt = m_surfaces.find(surface);
|
||||
@@ -1332,13 +1238,7 @@ namespace MobileGL {
|
||||
SetError(EGL_BAD_CONTEXT);
|
||||
return false;
|
||||
}
|
||||
// EGL_KHR_surfaceless_context: BOTH surfaces absent is a context that draws into
|
||||
// framebuffers it binds itself, which is how a compositor draws the frames the
|
||||
// display host handed it. One absent and one present stays refused - that is a
|
||||
// pair EGL gives no meaning to, and accepting it would record a draw target that
|
||||
// does not exist.
|
||||
const Bool surfaceless = (draw == EGL_NO_SURFACE && read == EGL_NO_SURFACE);
|
||||
if (!surfaceless && (draw == EGL_NO_SURFACE || read == EGL_NO_SURFACE)) {
|
||||
if (draw == EGL_NO_SURFACE || read == EGL_NO_SURFACE) {
|
||||
SetError(EGL_BAD_MATCH);
|
||||
return false;
|
||||
}
|
||||
@@ -1542,20 +1442,11 @@ namespace MobileGL {
|
||||
return true;
|
||||
}
|
||||
|
||||
void EGLContext::ReleaseImageDescriptors(ImageObject& imageObject) {
|
||||
for (Int plane = 0; plane < imageObject.PlaneCount; ++plane) {
|
||||
if (imageObject.Planes[plane].Fd >= 0) {
|
||||
CloseImageDescriptor(imageObject.Planes[plane].Fd);
|
||||
imageObject.Planes[plane].Fd = -1;
|
||||
}
|
||||
}
|
||||
imageObject.PlaneCount = 0;
|
||||
}
|
||||
|
||||
EGLContext::EGLImageHandle EGLContext::CreateImage(EGLDisplayHandle display, EGLContextHandle context,
|
||||
EGLenum target, EGLClientBuffer buffer,
|
||||
const EGLAttrib* attribList) {
|
||||
const std::lock_guard<std::recursive_mutex> lock(m_mutex);
|
||||
(void)attribList;
|
||||
if (!IsDisplayInitialized(display)) {
|
||||
SetError(EGL_NOT_INITIALIZED);
|
||||
return EGL_NO_IMAGE;
|
||||
@@ -1565,149 +1456,13 @@ namespace MobileGL {
|
||||
return EGL_NO_IMAGE;
|
||||
}
|
||||
|
||||
ImageObject imageObject = {
|
||||
const auto image = EncodeHandle<EGLImageHandle>(m_nextImageHandle++);
|
||||
m_images[image] = ImageObject{
|
||||
.Display = display,
|
||||
.Context = context,
|
||||
.Target = target,
|
||||
.Buffer = buffer,
|
||||
};
|
||||
|
||||
// EGL_LINUX_DMA_BUF_EXT: the caller handed over a DESCRIPTOR and described the
|
||||
// memory behind it, and that description is the whole image - there is no handle to
|
||||
// import later. Every other target still names a buffer this state cannot see, so
|
||||
// it stays what it was: the record of the target it was made for.
|
||||
if (target == EGL_LINUX_DMA_BUF_EXT) {
|
||||
// ONE line per refusal, naming what was missing: a caller that gets
|
||||
// EGL_BAD_PARAMETER for a buffer it believes it described completely has
|
||||
// nowhere else to look - the attribute list is gone by the time eglGetError is
|
||||
// read, and the frame it wanted to draw into is the frame it cannot.
|
||||
const auto refuse = [&](const String& missing) {
|
||||
SetError(EGL_BAD_PARAMETER);
|
||||
MGLOG_E("eglCreateImage(EGL_LINUX_DMA_BUF_EXT): %s is missing; refusing the image "
|
||||
"(EGL_BAD_PARAMETER)",
|
||||
missing.c_str());
|
||||
};
|
||||
|
||||
const auto width = ParseAttribValue(attribList, EGL_WIDTH);
|
||||
const auto height = ParseAttribValue(attribList, EGL_HEIGHT);
|
||||
const auto fourCC = ParseAttribValue(attribList, EGL_LINUX_DRM_FOURCC_EXT);
|
||||
if (!width) {
|
||||
refuse("EGL_WIDTH");
|
||||
return EGL_NO_IMAGE;
|
||||
}
|
||||
if (!height) {
|
||||
refuse("EGL_HEIGHT");
|
||||
return EGL_NO_IMAGE;
|
||||
}
|
||||
if (!fourCC) {
|
||||
refuse("EGL_LINUX_DRM_FOURCC_EXT");
|
||||
return EGL_NO_IMAGE;
|
||||
}
|
||||
|
||||
// The planes, read and checked BEFORE one descriptor is duplicated, so that a
|
||||
// refusal leaves nothing behind to close.
|
||||
EGLint planeFd[EGLContext::kMaxImagePlanes] = {};
|
||||
EGLint planeOffset[EGLContext::kMaxImagePlanes] = {};
|
||||
EGLint planePitch[EGLContext::kMaxImagePlanes] = {};
|
||||
Uint64 planeModifier[EGLContext::kMaxImagePlanes] = {};
|
||||
Bool planeHasModifier[EGLContext::kMaxImagePlanes] = {};
|
||||
EGLint planeCount = 0;
|
||||
for (Int plane = 0; plane < EGLContext::kMaxImagePlanes; ++plane) {
|
||||
const DmaBufPlaneAttributes& attributes = kDmaBufPlaneAttributes[plane];
|
||||
const auto fd = ParseAttribValue(attribList, attributes.Fd);
|
||||
const auto offset = ParseAttribValue(attribList, attributes.Offset);
|
||||
const auto pitch = ParseAttribValue(attribList, attributes.Pitch);
|
||||
const auto modifierLo = ParseAttribValue(attribList, attributes.ModifierLo);
|
||||
const auto modifierHi = ParseAttribValue(attribList, attributes.ModifierHi);
|
||||
if (!fd && !offset && !pitch && !modifierLo && !modifierHi) {
|
||||
// The caller never mentioned this plane. Planes are positional - the
|
||||
// description carries no plane index - so this ends the list, and a
|
||||
// plane past the hole is refused by name rather than dropped.
|
||||
for (Int higher = plane + 1; higher < EGLContext::kMaxImagePlanes; ++higher) {
|
||||
if (HasAnyPlaneAttribute(attribList, higher)) {
|
||||
refuse(DmaBufPlaneAttributeName(plane, "FD_EXT"));
|
||||
return EGL_NO_IMAGE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
// All three of fd/offset/pitch or none, and both halves of the modifier or
|
||||
// neither: a partial triple describes memory no importer could read.
|
||||
if (!fd) {
|
||||
refuse(DmaBufPlaneAttributeName(plane, "FD_EXT"));
|
||||
return EGL_NO_IMAGE;
|
||||
}
|
||||
if (!offset) {
|
||||
refuse(DmaBufPlaneAttributeName(plane, "OFFSET_EXT"));
|
||||
return EGL_NO_IMAGE;
|
||||
}
|
||||
if (!pitch) {
|
||||
refuse(DmaBufPlaneAttributeName(plane, "PITCH_EXT"));
|
||||
return EGL_NO_IMAGE;
|
||||
}
|
||||
if (modifierLo.has_value() != modifierHi.has_value()) {
|
||||
refuse(DmaBufPlaneAttributeName(plane, modifierLo ? "MODIFIER_HI_EXT" : "MODIFIER_LO_EXT"));
|
||||
return EGL_NO_IMAGE;
|
||||
}
|
||||
planeFd[plane] = static_cast<EGLint>(*fd);
|
||||
planeOffset[plane] = static_cast<EGLint>(*offset);
|
||||
planePitch[plane] = static_cast<EGLint>(*pitch);
|
||||
if (modifierLo) {
|
||||
// The modifier arrives in two halves and is one number: DRM cuts a
|
||||
// DRM_FORMAT_MOD_* where EGL takes an EGLint.
|
||||
planeModifier[plane] = (static_cast<Uint64>(static_cast<Uint32>(*modifierHi)) << 32) |
|
||||
static_cast<Uint32>(*modifierLo);
|
||||
planeHasModifier[plane] = true;
|
||||
}
|
||||
planeCount = plane + 1;
|
||||
}
|
||||
if (planeCount == 0) {
|
||||
// A dma-buf image with no plane at all: the description starts here, so
|
||||
// this is the attribute that is missing.
|
||||
refuse(DmaBufPlaneAttributeName(0, "FD_EXT"));
|
||||
return EGL_NO_IMAGE;
|
||||
}
|
||||
|
||||
// THE IMAGE TAKES ITS OWN DESCRIPTORS. The caller's fds stay the caller's -
|
||||
// kwin hands over a dup() of its DmaBufAttributes and closes it as soon as
|
||||
// eglCreateImage returns, and an image that had borrowed it would be holding a
|
||||
// number some other part of the process now owns.
|
||||
for (Int plane = 0; plane < planeCount; ++plane) {
|
||||
const Int ownedFd = DuplicateImageDescriptor(planeFd[plane]);
|
||||
if (ownedFd < 0) {
|
||||
SetError(EGL_BAD_ALLOC);
|
||||
MGLOG_E("eglCreateImage(EGL_LINUX_DMA_BUF_EXT): cannot take a copy of %s=%d (%s); "
|
||||
"refusing the image (EGL_BAD_ALLOC)",
|
||||
DmaBufPlaneAttributeName(plane, "FD_EXT").c_str(), planeFd[plane],
|
||||
std::strerror(errno));
|
||||
ReleaseImageDescriptors(imageObject);
|
||||
return EGL_NO_IMAGE;
|
||||
}
|
||||
imageObject.Planes[plane] = ImagePlane{
|
||||
.Fd = ownedFd,
|
||||
.Offset = planeOffset[plane],
|
||||
.Pitch = planePitch[plane],
|
||||
.Modifier = planeModifier[plane],
|
||||
.HasModifier = planeHasModifier[plane],
|
||||
};
|
||||
// Counted as they are stored, so that a failure below releases exactly what
|
||||
// has been taken.
|
||||
imageObject.PlaneCount = plane + 1;
|
||||
}
|
||||
imageObject.Width = static_cast<EGLint>(*width);
|
||||
imageObject.Height = static_cast<EGLint>(*height);
|
||||
imageObject.FourCC = static_cast<EGLint>(*fourCC);
|
||||
|
||||
MGLOG_D("eglCreateImage(EGL_LINUX_DMA_BUF_EXT): %dx%d fourcc=0x%08x planes=%d plane0(fd=%d "
|
||||
"offset=%d pitch=%d %s0x%016llx)",
|
||||
imageObject.Width, imageObject.Height, imageObject.FourCC, imageObject.PlaneCount,
|
||||
imageObject.Planes[0].Fd, imageObject.Planes[0].Offset, imageObject.Planes[0].Pitch,
|
||||
imageObject.Planes[0].HasModifier ? "modifier=" : "no-modifier=",
|
||||
static_cast<unsigned long long>(imageObject.Planes[0].Modifier));
|
||||
}
|
||||
|
||||
const auto image = EncodeHandle<EGLImageHandle>(m_nextImageHandle++);
|
||||
m_images[image] = imageObject;
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -1722,9 +1477,6 @@ namespace MobileGL {
|
||||
SetError(EGL_BAD_MATCH);
|
||||
return false;
|
||||
}
|
||||
// The descriptors this image owns die with it. Nothing else in this process holds
|
||||
// them: they are copies, and the caller's originals were never touched.
|
||||
ReleaseImageDescriptors(imageIt->second);
|
||||
m_images.erase(imageIt);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -22,12 +22,6 @@ namespace MobileGL {
|
||||
using EGLSyncHandle = ::EGLSync;
|
||||
using EGLImageHandle = ::EGLImage;
|
||||
|
||||
// How many planes EGL describes an imported buffer with: EGL_DMA_BUF_PLANE0_* comes
|
||||
// from EGL_EXT_image_dma_buf_import, EGL_DMA_BUF_PLANE3_* and every MODIFIER pair
|
||||
// from EGL_EXT_image_dma_buf_import_modifiers. The reader in Core.cpp and the image
|
||||
// object below have to agree on the count, so it is named once.
|
||||
static constexpr Int kMaxImagePlanes = 4;
|
||||
|
||||
EGLContext() = default;
|
||||
|
||||
// Error
|
||||
@@ -43,9 +37,6 @@ namespace MobileGL {
|
||||
EGLDisplayHandle GetPlatformDisplay(EGLenum platform, void* nativeDisplay);
|
||||
Bool ValidateDisplay(EGLDisplayHandle display) const;
|
||||
Bool IsDisplayInitialized(EGLDisplayHandle display) const;
|
||||
// The native display a display was made for and the platform it was asked for on
|
||||
// (EGL_NONE for eglGetDisplay): what decides how its window surfaces are presented.
|
||||
Bool GetDisplayNative(EGLDisplayHandle display, Uint64* nativeDisplayKey, EGLenum* platform) const;
|
||||
Bool InitializeDisplay(EGLDisplayHandle display, EGLint* major, EGLint* minor);
|
||||
Bool TerminateDisplay(EGLDisplayHandle display);
|
||||
// Whole-library idle checks used by EGLImpl::Terminate to decide
|
||||
@@ -106,13 +97,6 @@ namespace MobileGL {
|
||||
EGLSurfaceHandle CreateServerOwnedWindowSurface(EGLDisplayHandle display, EGLConfigHandle config,
|
||||
const void* nativeWindow, EGLint width,
|
||||
EGLint height, Bool platformWindow);
|
||||
// MOBILEGL_IPC_SURFACE=host: the same registration under the other on-screen name.
|
||||
// The EGL state does not care which side owns the frames - that is the backend's
|
||||
// business - but a trace has to be able to tell the two runs apart, and the two
|
||||
// paths part company in the backend call that follows.
|
||||
EGLSurfaceHandle CreateHostFrameWindowSurface(EGLDisplayHandle display, EGLConfigHandle config,
|
||||
const void* nativeWindow, EGLint width,
|
||||
EGLint height, Bool platformWindow);
|
||||
// P12: the server's REAL extent of a surface - a server-owned window's geometry, from
|
||||
// the CreateWindowSurface reply and from every surface-changed event after it - so
|
||||
// eglQuerySurface(EGL_WIDTH/EGL_HEIGHT) answers what the server renders at. Unlike
|
||||
@@ -127,57 +111,6 @@ namespace MobileGL {
|
||||
EGLContextHandle GetCurrentContext() const;
|
||||
EGLDisplayHandle GetCurrentDisplay() const;
|
||||
EGLSurfaceHandle GetCurrentSurface(EGLint readdraw) const;
|
||||
// WHAT A HANDLE NAMES, for the GL side of GL_OES_EGL_image: the two entry points in
|
||||
// MG_Impl/GLImpl/Exporting/Definitions.cpp are handed a GLeglImageOES and have to
|
||||
// answer whether it is an image this display created, and with what geometry. A
|
||||
// read-only lookup belongs beside the other queries a caller outside this class
|
||||
// makes, and it is the same object eglCreateImageKHR built and eglDestroyImage
|
||||
// removes - the private one stays private for the class's own use.
|
||||
// WHAT A HANDLE NAMES, for the GL side of GL_OES_EGL_image. The two entry points in
|
||||
// MG_Impl/GLImpl/Exporting/Definitions.cpp are handed a GLeglImageOES and have to
|
||||
// answer (a) whether it is an image this display created and (b) what buffer it
|
||||
// describes. The numbers come back rather than the record itself: the image table and
|
||||
// its layout are this class's own business, and a caller outside it has no use for
|
||||
// either - which is also why this is a function and not a friend declaration.
|
||||
Bool DescribeImage(EGLImageHandle image, EGLint* width, EGLint* height, EGLint* fourCc,
|
||||
EGLint* planeCount) const {
|
||||
const ImageObject* imageObject = TryGetImage(image);
|
||||
if (imageObject == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (width != nullptr) *width = imageObject->Width;
|
||||
if (height != nullptr) *height = imageObject->Height;
|
||||
if (fourCc != nullptr) *fourCc = imageObject->FourCC;
|
||||
if (planeCount != nullptr) *planeCount = imageObject->PlaneCount;
|
||||
return true;
|
||||
}
|
||||
|
||||
// THE PLANE DESCRIPTORS OF AN IMAGE THIS DISPLAY CREATED, for the one caller that has
|
||||
// to hand them to the render server: the dma-buf import (a texture bound to an imported
|
||||
// EGLImage has no storage on the server, so the server is told which buffer backs it -
|
||||
// one descriptor per plane, over the session transport's SCM_RIGHTS channel). The fd
|
||||
// here is THIS side's dup(), owned by the image; the transport dups again for the
|
||||
// sending process, which is why the caller does not close anything.
|
||||
Bool DescribeImagePlanes(EGLImageHandle image, EGLint* planeCount, EGLint* fds, EGLint* offsets,
|
||||
EGLint* pitches, Uint64* modifiers, Bool* hasModifiers, Int maxPlanes) const {
|
||||
const ImageObject* imageObject = TryGetImage(image);
|
||||
if (imageObject == nullptr) {
|
||||
return false;
|
||||
}
|
||||
Int count = imageObject->PlaneCount;
|
||||
if (count > maxPlanes) count = maxPlanes;
|
||||
if (count < 0) count = 0;
|
||||
if (planeCount != nullptr) *planeCount = count;
|
||||
for (Int plane = 0; plane < count; plane++) {
|
||||
const ImagePlane& described = imageObject->Planes[plane];
|
||||
if (fds != nullptr) fds[plane] = described.Fd;
|
||||
if (offsets != nullptr) offsets[plane] = described.Offset;
|
||||
if (pitches != nullptr) pitches[plane] = described.Pitch;
|
||||
if (modifiers != nullptr) modifiers[plane] = described.Modifier;
|
||||
if (hasModifiers != nullptr) hasModifiers[plane] = described.HasModifier;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Bool IsDoubleBufferedSurface(EGLSurfaceHandle surface) const;
|
||||
|
||||
// Sync
|
||||
@@ -278,39 +211,11 @@ namespace MobileGL {
|
||||
EGLenum Status = EGL_SIGNALED;
|
||||
};
|
||||
|
||||
// ONE PLANE OF AN IMPORTED BUFFER. The fd/offset/pitch triple is the same
|
||||
// description drmModeAddFB2 takes, and the modifier is the DRM_FORMAT_MOD_* the
|
||||
// caller declared; EGL carries up to four of these (EGL_DMA_BUF_PLANE0..3_*).
|
||||
struct ImagePlane {
|
||||
// THIS library's descriptor, dup()ed from the caller's when the image was made
|
||||
// and closed when it dies: an EGLImage outlives the call that created it, and
|
||||
// the caller is free to close its own fd the moment eglCreateImage returns.
|
||||
EGLint Fd = -1;
|
||||
EGLint Offset = 0;
|
||||
EGLint Pitch = 0;
|
||||
// The two EGL_DMA_BUF_PLANEn_MODIFIER_LO/HI_EXT halves joined back into the
|
||||
// DRM_FORMAT_MOD_* they were cut from.
|
||||
Uint64 Modifier = 0;
|
||||
Bool HasModifier = false;
|
||||
};
|
||||
|
||||
struct ImageObject {
|
||||
EGLDisplayHandle Display = EGL_NO_DISPLAY;
|
||||
EGLContextHandle Context = nullptr;
|
||||
EGLenum Target = EGL_NONE;
|
||||
EGLClientBuffer Buffer = nullptr;
|
||||
// WHAT AN EGL_LINUX_DMA_BUF_EXT IMAGE IS HOLDING, and zero for every other
|
||||
// target: the buffer's geometry and the fourcc that says what its samples mean.
|
||||
// It is kept here because the image is the only thing that outlives the call -
|
||||
// a caller that handed over an fd has nothing left to describe it with.
|
||||
EGLint Width = 0;
|
||||
EGLint Height = 0;
|
||||
EGLint FourCC = 0;
|
||||
EGLint PlaneCount = 0;
|
||||
// Planes 0..PlaneCount-1 are described, in order; index 0 is the plane every
|
||||
// import in this tree reads, the rest are carried because EGL describes them and
|
||||
// a consumer that understands a multi-plane format must be able to see them.
|
||||
ImagePlane Planes[kMaxImagePlanes];
|
||||
};
|
||||
|
||||
struct ThreadCurrentState {
|
||||
@@ -346,9 +251,6 @@ namespace MobileGL {
|
||||
const SurfaceObject* TryGetSurface(EGLSurfaceHandle surface) const;
|
||||
const SyncObject* TryGetSync(EGLSyncHandle sync) const;
|
||||
const ImageObject* TryGetImage(EGLImageHandle image) const;
|
||||
// Closes the descriptors an image owns. Both places an image can die call it:
|
||||
// eglDestroyImage, and eglTerminate, which drops a display's images wholesale.
|
||||
static void ReleaseImageDescriptors(ImageObject& imageObject);
|
||||
|
||||
void ReleaseDisplayObjects(EGLDisplayHandle display);
|
||||
void ReleaseThreadUnlocked(const std::thread::id& threadKey);
|
||||
|
||||
@@ -105,20 +105,7 @@ namespace MobileGL::MG_State::GLState {
|
||||
return m_bufferBindPointTargets[i][index];
|
||||
}
|
||||
}
|
||||
// A GLOBAL TARGET ASKED THROUGH THE INDEXED LOOKUP. Only four targets have per-index binding
|
||||
// points (Uniform, TransformFeedback, AtomicCounter, ShaderStorage); the rest - Vertex, Index,
|
||||
// PixelPack/Unpack, Texture, CopyRead/Write, Query, the indirect ones - are global, and a caller
|
||||
// that asks for one here is reading the wrong accessor, not passing a bad enum.
|
||||
//
|
||||
// This used to abort, and the compositor reached it right after its vertex-attrib setup: the
|
||||
// whole session died on Trace/breakpoint trap ("Invalid BufferTarget enum value for binding
|
||||
// point"). Aborting a compositor over an accessor mix-up is the wrong trade, so the answer is
|
||||
// a one-time warning and index 0 of the indexed array: the caller gets a valid slot, the
|
||||
// global binding is untouched, and the mismatch stays visible in the log instead of being a
|
||||
// crash. The proper fix is for that caller to use the global accessor.
|
||||
MGLOG_W_ONCE("BufferState::GetBindingPoint: target=%d has no per-index binding points; answering "
|
||||
"index 0 of the indexed array (a global target was asked through the indexed lookup)",
|
||||
static_cast<int>(target));
|
||||
MOBILEGL_ASSERT(false, "Invalid BufferTarget enum value for binding point: %d", static_cast<int>(target));
|
||||
return m_bufferBindPointTargets[0][index];
|
||||
}
|
||||
} // namespace MobileGL::MG_State::GLState
|
||||
|
||||
@@ -13,23 +13,6 @@
|
||||
#include <atomic>
|
||||
#include <MG_Pipe/PipeMutation.h>
|
||||
|
||||
// The display host's frame, as the backend publishes it (MG_Backend/DirectGLES/DirectGLES.h).
|
||||
// DECLARED HERE RATHER THAN INCLUDED, and that is a deliberate compromise with a named end: the
|
||||
// client asks whether its framebuffer is complete BEFORE any backend binding runs, so this judgement
|
||||
// cannot ask the backend - and the frontend knowing a backend fact is exactly what a record is for.
|
||||
// The wire does not carry one yet (MG_Protocol's dispatch has no glEGLImageTargetTexture2DOES), so
|
||||
// the fact is read from where it already is; when that record lands, this block goes with it.
|
||||
// The backend namespace is the one DirectGLES.cpp:67 opens and defines these in - the SAME nesting
|
||||
// as Uint g_hostFrameFramebufferId beside them. Getting this wrong is not a typo with no cost: a
|
||||
// Linux shared library links with undefined symbols allowed, so the container build passed while the
|
||||
// Android server build (ld.lld, --no-undefined) named all three - which is how a latent runtime
|
||||
// failure was caught by the platform that builds the render server.
|
||||
namespace MobileGL::MG_Backend::DirectGLES {
|
||||
extern Uint g_hostFrameRenderbuffer;
|
||||
extern Uint g_hostFrameWidth;
|
||||
extern Uint g_hostFrameHeight;
|
||||
}
|
||||
|
||||
namespace MobileGL::MG_State::GLState {
|
||||
// Starts at 1 so a zero-initialized memo slot can never carry a live object's id.
|
||||
// Atomic for the same reason as the VAO counter: it costs nothing, and a duplicate
|
||||
@@ -191,34 +174,8 @@ namespace MobileGL::MG_State::GLState {
|
||||
|
||||
Int width = -1, height = -1;
|
||||
Int validAttachmentCount = 0;
|
||||
// THE IMPORTED dma-buf, and why it is judged BEFORE the validity test rather than after it.
|
||||
// Measured: with kwin_wayland's framebuffer attached - it imports the display daemon's
|
||||
// dma-buf as an EGLImage ("taking target 0x8d65 over an EGLImage of 1440x2937 fourcc
|
||||
// 0x34324241") and builds an FBO over that texture - the server answered
|
||||
// "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT". The old early-continue below dropped the
|
||||
// attachment (a texture that arrived this way has no storage, so it reports itself invalid)
|
||||
// and the completeness gate further down was never reached.
|
||||
//
|
||||
// THE GATE IS THE MEASURED SHAPE, and it is deliberately narrow: this process is holding a
|
||||
// display host frame (g_hostFrameRenderbuffer != 0), and the attachment is a texture with no
|
||||
// storage of its own. That buffer IS the frame the host handed this process - same memory -
|
||||
// and the backend binds the frame's renderbuffer in place of the empty texture
|
||||
// (MG_Backend/DirectGLES/Managers.cpp). A size comparison would be the sharper test and is
|
||||
// impossible here: the imported attachment has no size, which is exactly why the wire needs a
|
||||
// record to say so (MG_Protocol's dispatch has no glEGLImageTargetTexture2DOES yet); when it
|
||||
// lands, this gate is replaced by that record and nothing else changes.
|
||||
// AND IT DELIBERATELY DOES NOT ASK WHETHER THE FRAME IS IN HAND YET, which the first version
|
||||
// of this gate did - and that version did not work, measured: kwin imports the dma-buf and
|
||||
// builds its framebuffer BEFORE the host-framed surface exists, so g_hostFrameRenderbuffer is
|
||||
// still zero at the instant the client asks, the gate refused, and kwin printed
|
||||
// "GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT" again. What the attachment IS is the fact
|
||||
// that holds at that instant: a texture with no storage of its own is the imported dma-buf,
|
||||
// and the buffer it names is the display daemon's frame - the one this process is about to be
|
||||
// handed. The backend binds that frame's renderbuffer to the attachment as soon as it has
|
||||
// one (Managers.cpp re-syncs attachments per draw, so the first draw after the frame arrives
|
||||
// lands in it).
|
||||
for (const auto& attachmentObject : m_attachmentObjects) {
|
||||
if (!attachmentObject.IsValid() && !attachmentObject.IsTexture()) continue;
|
||||
if (!attachmentObject.IsValid()) continue;
|
||||
|
||||
++validAttachmentCount;
|
||||
const auto& attachment = attachmentObject;
|
||||
@@ -233,44 +190,7 @@ namespace MobileGL::MG_State::GLState {
|
||||
return false;
|
||||
}
|
||||
|
||||
// AN IMPORTED dma-buf COUNTS AS COMPLETE, in the measured shape and no other: the
|
||||
// attachment has no storage of its own and this process holds a display host frame of the
|
||||
// same size. Measured, and the reason this is here at all: kwin_wayland imports the
|
||||
// display daemon's dma-buf as an EGLImage ("taking target 0x8d65 over an EGLImage of
|
||||
// 1440x2937 fourcc 0x34324241") and then refuses its own framebuffer with "framebuffer for
|
||||
// dmabuf 0 is not complete" - a refusal that is WRONG here, because the buffer it imported
|
||||
// IS the frame the display host handed this process (same memory, same size) and the
|
||||
// backend binds that frame's renderbuffer in place of the empty texture
|
||||
// (MG_Backend/DirectGLES/Managers.cpp, the external-OES arm under the same gate). A size
|
||||
// that differs, or no frame held, keeps the old answer: an ordinary empty attachment is
|
||||
// still incomplete, and nothing is ever rendered into a buffer of the wrong size.
|
||||
// AND IT DOES NOT ASK WHETHER A FRAME IS HELD, OR HOW BIG IT IS - which the first version
|
||||
// of this gate did, and which is why it never worked. This judgement runs on BOTH sides
|
||||
// of a split run: the client answers glCheckFramebufferStatus out of its own state before
|
||||
// any backend binding happens, and the client holds no frame at all. So a gate that
|
||||
// required g_hostFrameRenderbuffer != 0 and a matching size refused on the client every
|
||||
// time, and kwin kept printing "Invalid framebuffer status:
|
||||
// GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT" - measured, twice, after that gate was
|
||||
// deployed. What the attachment IS is the fact that holds on both sides: a texture with
|
||||
// no storage of its own is the imported dma-buf, and the server binds the display host's
|
||||
// frame to it as soon as it has one (Managers.cpp re-syncs the attachments per draw, so
|
||||
// the first draw after the frame arrives lands in it). An attachment that IS valid - an
|
||||
// ordinary texture or renderbuffer with real storage - still has to be complete.
|
||||
// A TEXTURE ATTACHMENT THAT IS NOT COMPLETE IS THE IMPORTED dma-buf, and it counts. The
|
||||
// condition is written on IsTexture() and NOT on IsValid(), which is the mistake two
|
||||
// earlier versions of this gate made - measured both times as
|
||||
// "Invalid framebuffer status: GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT" from a session
|
||||
// that was healthy and had really reached the import:
|
||||
// * requiring a host frame to be in hand refused on the CLIENT, which holds none;
|
||||
// * requiring the attachment to be INVALID refused too, because AttachTexture registers
|
||||
// the attachment (FramebufferObject.cpp:163) whether or not the texture has storage -
|
||||
// so the imported one is perfectly valid and simply incomplete.
|
||||
// What is true on both sides, at that instant, is what this asks: the attachment is a
|
||||
// TEXTURE and it is incomplete, i.e. it has no storage of its own, and the server binds the
|
||||
// display host's frame to it as soon as it holds one (Managers.cpp re-syncs the attachments
|
||||
// per draw). A RENDERBUFFER attachment still has to be complete, so an ordinary empty
|
||||
// attachment of that kind keeps the old refusal.
|
||||
if (!attachment.IsComplete() && !attachment.IsTexture()) {
|
||||
if (!attachment.IsComplete()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,6 @@ namespace MobileGL {
|
||||
Texture2DArray,
|
||||
TextureCubeMapArray,
|
||||
Texture2DMultisampleArray,
|
||||
// GL_TEXTURE_EXTERNAL_OES, APPENDED SO NO EXISTING VALUE MOVES. The compositor imports the
|
||||
// display daemon's dma-buf with eglCreateImageKHR and binds the result through this target
|
||||
// (glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex) + glEGLImageTargetTexture2DOES). Without a
|
||||
// member here the bind is answered INVALID_ENUM (measured with probe15: error 0x500 -> 0x0500),
|
||||
// the texture never enters a binding slot, it has no internal format, and the framebuffer
|
||||
// built over it is reported incomplete - "framebuffer for dmabuf 0 is not complete".
|
||||
TextureExternalOES,
|
||||
TextureTargetCount,
|
||||
Unknown = -1
|
||||
};
|
||||
|
||||
@@ -14,9 +14,6 @@ namespace MobileGL {
|
||||
TextureObject2D::TextureObject2D(Uint externalIndex)
|
||||
: TextureObjectWithOneMipmap(TextureTarget::Texture2D, externalIndex) {}
|
||||
|
||||
TextureObject2D::TextureObject2D(Uint externalIndex, TextureTarget target)
|
||||
: TextureObjectWithOneMipmap(target, externalIndex) {}
|
||||
|
||||
Uint TextureObject2D::GetIndexOfTextureUploadTarget(TextureUploadTarget target) const {
|
||||
MOBILEGL_ASSERT(target == TextureUploadTarget::Texture2D ||
|
||||
target == TextureUploadTarget::ProxyTexture2D,
|
||||
|
||||
@@ -15,9 +15,6 @@ namespace MobileGL {
|
||||
class TextureObject2D : public TextureObjectWithOneMipmap {
|
||||
public:
|
||||
explicit TextureObject2D(Uint externalIndex);
|
||||
// An external texture (GL_TEXTURE_EXTERNAL_OES) is a 2D texture whose storage is an
|
||||
// imported EGLImage; it keeps that target so the render server can tell it apart.
|
||||
TextureObject2D(Uint externalIndex, TextureTarget target);
|
||||
const Vector<TextureUploadTarget>& GetUploadTargets() const override { return m_uploadTargets; }
|
||||
|
||||
protected:
|
||||
|
||||
@@ -35,14 +35,6 @@ namespace MobileGL::MG_State::GLState {
|
||||
return MakeShared<TextureObject2DCube>(index);
|
||||
case TextureTarget::Texture2D:
|
||||
return MakeShared<TextureObject2D>(index);
|
||||
// GL_TEXTURE_EXTERNAL_OES: an external texture IS a 2D texture whose storage comes from an
|
||||
// imported EGLImage (the compositor's display-daemon dma-buf). The object is the 2D one; what
|
||||
// differs is where the storage comes from, and the import path records that. Without this row
|
||||
// the factory asserted "Unimplemented texture type when creating texture object!" the moment
|
||||
// kwin bound one (measured: the compositor died on Trace/breakpoint trap right after the bind
|
||||
// was accepted).
|
||||
case TextureTarget::TextureExternalOES:
|
||||
return MakeShared<TextureObject2D>(index, TextureTarget::TextureExternalOES);
|
||||
case TextureTarget::Texture3D:
|
||||
return MakeShared<TextureObject3D>(index);
|
||||
case TextureTarget::TextureBuffer:
|
||||
|
||||
@@ -634,8 +634,8 @@ void main() { noBinding.c = afterLayout.a + beforeLayout.b + uint(texelFetch(tex
|
||||
<< "a samplerBuffer is not a buffer block";
|
||||
}
|
||||
|
||||
// THE REGRESSION THIS MIGRATION EXISTS FOR (7de7cfc6,
|
||||
// minecraft-1.21.1-neoforge-create-indirect-in-world, both backends). Flywheel's indirect
|
||||
// THE REGRESSION THIS MIGRATION EXISTS FOR (7de7cfc6, the original capture now replayed as
|
||||
// minecraft-1.21.1-neoforge-create-indirect-in-world-align1024, both backends). Flywheel's indirect
|
||||
// engine spells every storage-block binding as a macro, and the scan that used to answer this
|
||||
// question ran on MACRO-UNEXPANDED text: MobileGL's preprocessing rewrites the source, it does
|
||||
// not run the C preprocessor, so `binding = _FLW_MODEL_BUFFER_BINDING` reached the scanner
|
||||
|
||||
@@ -19,10 +19,6 @@ namespace MobileGL {
|
||||
case GL_TEXTURE_2D:
|
||||
case GL_PROXY_TEXTURE_2D:
|
||||
return TextureTarget::Texture2D;
|
||||
// GL_TEXTURE_EXTERNAL_OES: what the compositor binds an imported dma-buf to. Spelled as
|
||||
// the number because the GL headers this tree bundles do not define the token.
|
||||
case 0x8D65:
|
||||
return TextureTarget::TextureExternalOES;
|
||||
case GL_TEXTURE_3D:
|
||||
case GL_PROXY_TEXTURE_3D:
|
||||
return TextureTarget::Texture3D;
|
||||
@@ -404,14 +400,6 @@ namespace MobileGL {
|
||||
return TextureUploadTarget::Texture1D;
|
||||
case GL_TEXTURE_2D:
|
||||
return TextureUploadTarget::Texture2D;
|
||||
// GL_TEXTURE_EXTERNAL_OES (0x8D65), an upload target of its own right: the compositor
|
||||
// attaches the imported dma-buf texture to a framebuffer through this enum, and the attach
|
||||
// path validates the target here. Left unmapped it became Unknown, the validation failed,
|
||||
// the attachment was never recorded, and the compositor's own check then read
|
||||
// GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT. External textures ARE two-dimensional, so
|
||||
// the upload target is the 2D one.
|
||||
case 0x8D65:
|
||||
return TextureUploadTarget::Texture2D;
|
||||
case GL_TEXTURE_3D:
|
||||
return TextureUploadTarget::Texture3D;
|
||||
case GL_PROXY_TEXTURE_2D:
|
||||
|
||||
@@ -497,7 +497,6 @@ namespace MobileGL {
|
||||
CASE(E_GL_OES_fixed_point)
|
||||
CASE(E_GL_OES_single_precision)
|
||||
CASE(E_GL_OES_compressed_paletted_texture)
|
||||
CASE(E_GL_OES_EGL_image)
|
||||
CASE(E_GL_OES_read_format)
|
||||
CASE(E_GL_OES_query_matrix)
|
||||
CASE(E_GL_EXT_depth_bounds_test)
|
||||
|
||||
@@ -124,7 +124,6 @@
|
||||
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <MG_Util/PlatformStubs.h>
|
||||
|
||||
namespace MobileGL {
|
||||
namespace MG_Util {
|
||||
|
||||
@@ -489,11 +489,6 @@ namespace MobileGL {
|
||||
E_GL_OES_fixed_point,
|
||||
E_GL_OES_single_precision,
|
||||
E_GL_OES_compressed_paletted_texture,
|
||||
// GL_OES_EGL_image: taking a texture (or renderbuffer) over an EGLImage. Named because
|
||||
// libepoxy resolves glEGLImageTargetTexture2DOES by NAME and the entry points are now real
|
||||
// (MG_Impl/GLImpl/Exporting/Definitions.cpp), with the render-server half of the import
|
||||
// still to come - see the note there.
|
||||
E_GL_OES_EGL_image,
|
||||
E_GL_OES_read_format,
|
||||
E_GL_OES_query_matrix,
|
||||
E_GL_EXT_depth_bounds_test,
|
||||
|
||||
@@ -8,12 +8,6 @@
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
|
||||
<!-- The two permissions that decide whether the server survives a dozing phone: the
|
||||
notification one lets the foreground service show the notification that is its reason to
|
||||
exist (Android 13+), and the exemption one is what the user grants from the control screen
|
||||
so the system stops freezing the process. -->
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
|
||||
<application
|
||||
android:hasCode="true"
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
package top.mobilegl.plugin;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import android.graphics.Typeface;
|
||||
import android.net.LocalSocket;
|
||||
import android.net.LocalSocketAddress;
|
||||
@@ -64,8 +58,6 @@ public final class ServerControlActivity extends Activity {
|
||||
private Button stopButton;
|
||||
private TextView statusView;
|
||||
private volatile Thread probeThread;
|
||||
private Button allowBackgroundButton;
|
||||
private TextView keepAliveView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -116,28 +108,6 @@ public final class ServerControlActivity extends Activity {
|
||||
boxParams.topMargin = dp(8);
|
||||
contentLayout.addView(onScreenBox, boxParams);
|
||||
|
||||
// KEEPING THE SERVER ALIVE IS TWO PERMISSIONS THE USER GIVES, and both are invisible
|
||||
// until something goes wrong: without the notification one (Android 13+) the service
|
||||
// notification cannot be shown, and without the battery exemption a dozing phone freezes
|
||||
// the process - the listener stays in /proc/net and stops accepting, which from the other
|
||||
// side of the socket looks exactly like a network fault. This section shows the state of
|
||||
// both, and asks for whichever is missing.
|
||||
keepAliveView = makeText("", 12, COLOR_INFO, false);
|
||||
LinearLayout.LayoutParams keepParams = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
keepParams.topMargin = dp(12);
|
||||
contentLayout.addView(keepAliveView, keepParams);
|
||||
|
||||
allowBackgroundButton = new Button(this);
|
||||
allowBackgroundButton.setText("Allow background (notification + battery)");
|
||||
allowBackgroundButton.setAllCaps(false);
|
||||
allowBackgroundButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
|
||||
allowBackgroundButton.setOnClickListener(v -> requestKeepAlive());
|
||||
LinearLayout.LayoutParams allowParams = new LinearLayout.LayoutParams(
|
||||
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
allowParams.topMargin = dp(6);
|
||||
contentLayout.addView(allowBackgroundButton, allowParams);
|
||||
|
||||
LinearLayout buttons = new LinearLayout(this);
|
||||
buttons.setOrientation(LinearLayout.HORIZONTAL);
|
||||
LinearLayout.LayoutParams buttonsParams = new LinearLayout.LayoutParams(
|
||||
@@ -544,73 +514,6 @@ public final class ServerControlActivity extends Activity {
|
||||
statusView.setTextColor(color);
|
||||
}
|
||||
|
||||
// ---- keeping the server alive ----------------------------------------------------------
|
||||
|
||||
private static final int NOTIFICATION_PERMISSION_REQUEST = 40614;
|
||||
|
||||
private boolean notificationsAllowed() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) return true;
|
||||
return checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS)
|
||||
== PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
|
||||
private boolean batteryExempt() {
|
||||
PowerManager power = getSystemService(PowerManager.class);
|
||||
return power != null && power.isIgnoringBatteryOptimizations(getPackageName());
|
||||
}
|
||||
|
||||
private void refreshKeepAlive() {
|
||||
if (keepAliveView == null) return;
|
||||
boolean notifications = notificationsAllowed();
|
||||
boolean exempt = batteryExempt();
|
||||
keepAliveView.setText("Keep alive: notification " + (notifications ? "allowed" : "NOT allowed")
|
||||
+ ", battery exemption " + (exempt ? "granted" : "NOT granted"));
|
||||
keepAliveView.setTextColor(notifications && exempt ? COLOR_PASS : COLOR_WARN);
|
||||
if (allowBackgroundButton != null) allowBackgroundButton.setEnabled(!(notifications && exempt));
|
||||
}
|
||||
|
||||
private void requestKeepAlive() {
|
||||
// One at a time, and in this order: the notification prompt is a system dialog of ours,
|
||||
// while the battery one leaves the app entirely - so it goes second, and coming back from
|
||||
// it re-runs the other branch through onResume.
|
||||
if (!notificationsAllowed() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
requestPermissions(new String[] { Manifest.permission.POST_NOTIFICATIONS },
|
||||
NOTIFICATION_PERMISSION_REQUEST);
|
||||
return;
|
||||
}
|
||||
if (!batteryExempt()) {
|
||||
try {
|
||||
startActivity(new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
|
||||
Uri.parse("package:" + getPackageName())));
|
||||
} catch (RuntimeException missingDialog) {
|
||||
// Some builds ship without that dialog; the list is the honest fallback rather than
|
||||
// a button that does nothing.
|
||||
Log.w(TAG, "no battery-optimization dialog; opening the list", missingDialog);
|
||||
startActivity(new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS));
|
||||
}
|
||||
return;
|
||||
}
|
||||
setStatus("Already kept alive: the notification is allowed and the battery exemption is granted.",
|
||||
COLOR_PASS);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
refreshKeepAlive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] results) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, results);
|
||||
if (requestCode != NOTIFICATION_PERMISSION_REQUEST) return;
|
||||
refreshKeepAlive();
|
||||
// The denial is worth saying out loud: the server still runs, but its notification is gone,
|
||||
// and a service the system cannot show is a service it may stop.
|
||||
if (!notificationsAllowed())
|
||||
setStatus("Notifications are denied, so the server has no visible notification. "
|
||||
+ "Android may stop it in the background.", COLOR_WARN);
|
||||
}
|
||||
private TextView makeText(String text, int sizeSp, int color, boolean bold) {
|
||||
TextView view = new TextView(this);
|
||||
view.setText(text);
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
# 容器当 client,手机当 server(上屏)
|
||||
|
||||
> 2026-10-01 在 Redmi 23117RK66C(Adreno 750,Android 16)与它的 Droidspaces Fedora 44
|
||||
> 容器上实测通过。本文记的是那条链路上**真正要设的东西**,以及两个会让人白跑一次的坑。
|
||||
|
||||
## 为什么不需要 `adb forward`
|
||||
|
||||
Droidspaces 容器与 Android **共用网络命名空间**(实测:容器里 `127.0.0.1:22` 就是 Android 的
|
||||
sshd,`ip addr` 列出的是手机的 `wlan0` / `rmnet_data5`)。所以服务端监听手机回环即可,
|
||||
容器直接用 `tcp://127.0.0.1:<port>` 连上去,不需要 `adb forward`,也不需要局域网地址。
|
||||
|
||||
## 起服务端(手机侧,上屏形态)
|
||||
|
||||
```bash
|
||||
TOKEN=<>=16 字节>
|
||||
adb shell am start -n top.mobilegl.plugin/top.mobilegl.plugin.MobileGLDisplayActivity \
|
||||
--es listen tcp://127.0.0.1:40613 --es token "$TOKEN"
|
||||
# 就绪行:
|
||||
# MG_Remote server: pid=… listening on tcp://127.0.0.1:40613 (in-process display server, display installed)
|
||||
```
|
||||
|
||||
**不要**给这次启动加 `--es env MOBILEGL_IPC_REQUIRE_SAME_BUILD=1`,除非两端确实同 build:
|
||||
按契约,`Dial == Connect` 时 build stamp 不同**只应警告**;加上它,服务端会因为 app 的戳(发布
|
||||
APK 里是 0)与容器客户端的戳(源码树短哈希)不同而 `Refuse{BuildFingerprint}`——症状是客户端
|
||||
在 `eglCreateWindowSurface` 之前就被 abort,日志里只有一条与真正原因无关的 caps 门。
|
||||
|
||||
## 容器侧(客户端)
|
||||
|
||||
```bash
|
||||
export MOBILEGL_TRANSPORT=spawn # 两进程;endpoint 由下面这条给
|
||||
export MOBILEGL_IPC_CONTROL=tcp://127.0.0.1:40613
|
||||
export MOBILEGL_IPC_DATA=stream # 跨进程字节流;同机共享段是另一条轴
|
||||
export MOBILEGL_IPC_SURFACE=server # 窗口是服务端的:客户端传 NULL 窗口
|
||||
export MOBILEGL_IPC_TOKEN=<同一个>
|
||||
export LD_LIBRARY_PATH=/root/build-cont # 容器里那份 split 构建
|
||||
./onscreen_client # eglCreateWindowSurface(dpy, cfg, NULL, {EGL_WIDTH,EGL_HEIGHT})
|
||||
```
|
||||
|
||||
客户端侧不需要 GPU、不需要 `/dev/dri`、不需要 Wayland:它只记录,画的是服务端。
|
||||
|
||||
## 实测结果
|
||||
|
||||
```
|
||||
EGL 1.5 vendor=MobileGL version=1.5 MobileGL
|
||||
surface created: 1440x3200 (asked 1440x3200)
|
||||
GL_RENDERER=Espryt (MobileGL Core) (Adreno (TM) 750, OpenGL ES 3.2)
|
||||
frame 0..11 swap=1
|
||||
```
|
||||
|
||||
服务端逐帧:
|
||||
|
||||
```
|
||||
P65ServerFrame frame=8..12 records=4 apply_ms=1.0..1.7
|
||||
```
|
||||
|
||||
抓屏为整屏 `#72e3d8`,即客户端第 3 种清屏色 `(0.20, 0.90, 0.85)` 经 sRGB 转换后的值——
|
||||
容器里那个没有 GPU 的进程要求画的东西,出现在手机屏幕上。
|
||||
|
||||
## 待办(本页不含)
|
||||
|
||||
- kwin:让 Plasma 的合成也走这条客户端(`LD_PRELOAD` 或直接链接容器里那份 `libEGL`),
|
||||
窗口面仍是服务端形态;此时 Anland 只剩 Wayland 协议与输入。
|
||||
- 两端同 build:容器里的源码树与 APK 从同一 revision 构建后,`REQUIRE_SAME_BUILD=1` 才有意义。
|
||||
@@ -1,6 +1,6 @@
|
||||
# 仍开放的债务(跨阶段)
|
||||
|
||||
> 路线图只列"有债务、看这里"。每条写明去向;已关闭的历史债与当时的完整债务表见 [`p5b/README.md`](p5b/README.md) 末节。开放问题另见 [`OPEN-QUESTIONS.md`](OPEN-QUESTIONS.md)。更新:2026-09-30(P8 第二波;按债务审查重排)。去向「需裁定」= 等用户定;「可进行」= 随时可开的小修,不依赖别的阶段。
|
||||
> 路线图只列"有债务、看这里"。每条写明去向;已关闭的历史债与当时的完整债务表见 [`p5b/README.md`](p5b/README.md) 末节。开放问题另见 [`OPEN-QUESTIONS.md`](OPEN-QUESTIONS.md)。更新:2026-09-30(P8 第二波;按债务审查重排。同日:create-indirect 换成派生 fixture `minecraft-1.21.1-neoforge-create-indirect-in-world-align1024`(不是原抓取,16 字节对齐的 SSBO 范围绑定挪到 1024 对齐),ID-P8-14、ID-P8-19 两条关闭——红米两后端 monolith / spawn 全过,Magma spawn 不再丢设备)。去向「需裁定」= 等用户定;「可进行」= 随时可开的小修,不依赖别的阶段。
|
||||
|
||||
| 债务 | 去向 |
|
||||
|---|---|
|
||||
@@ -18,14 +18,12 @@
|
||||
| P11 转出(B2):handle 臂的 CPU 读者读采纳 / T0 映射前先落排队常驻写——split 半已由 P8-C 实现(`SplitHostBytesForCpuRead` 的 T0 臂:落写 + `glFinish`,ID-P8-9),但主机无 T0、未能证红 | 需设备验证(红米 Android 集成测试 + static-peek) |
|
||||
| P11 转出(B2):server 准了 T0 而 client 选了 T2 时,每个存储的 `map_persistent` 等 2 s 再具名拒绝(产品里 grant 与 caps 一致,只在变异下见过) | 可进行(小修:每会话一个「client 不要 T0」提示) |
|
||||
| P9 转出:Espryt 重铸保留路径上 framebuffer clear 后 `imageLoad` 偶读旧值(主机 3/30,加 barrier 后 0/30;`TextureRemintPullScenario` case C 暂钉 barrier),疑 llvmpipe(ID-P9-11);P11 合并 dev 后 push 单进程臂上也见过一次,`ImageBindableRemintScenario` 同样钉 barrier(ID-P11-6) | 可进行(在红米上不加 barrier 归因) |
|
||||
| P8 转出(D):应用省略 `glMemoryBarrier` 时,两臂在计算写与顶点着色器读之间都没有依赖(GL 未定义,但真实应用依赖它);D 的每轮屏障在真机上的开销未测;create-indirect 验证不了这两件事(ID-P8-14),需要一个「计算写命令、无应用屏障、不重写」的 fixture | 待归因(需新 fixture) |
|
||||
| P8 转出(D):应用省略 `glMemoryBarrier` 时,两臂在计算写与顶点着色器读之间都没有依赖(GL 未定义,但真实应用依赖它);D 的每轮屏障在真机上的开销未测;create-indirect(现为派生的 `minecraft-1.21.1-neoforge-create-indirect-in-world-align1024`,内容相同)验证不了这两件事(ID-P8-14),需要一个「计算写命令、无应用屏障、不重写」的 fixture | 待归因(需新 fixture) |
|
||||
| P8 转出(E):driver-written 标按整张纹理打(`GenerateMipmap` 也打),驱动拒读时连基级也具名拒绝,偏保守;跨格式拷贝 store 不跟随;拒绝仍是会话 Fatal(要改回包状态才能答 `GL_INVALID_OPERATION`) | 小修(按 level 打标);其余按需 |
|
||||
| P8 转出(B):`PipeCalls.def:260` `GenerateMipmap` 仍是 `kWaitApplied`,裁定 14 的理由(CPU 滤波碰 client 影子)已不成立,可改 `kWaitNone` | 性能工作(协议行为变更,需单独裁定) |
|
||||
| P8 转出(C):server SSBO 标记过近似(窗口内每个绑定的 SSBO 都标);一个留在 SSBO 绑定上又当 restart EBO 用的 buffer 每次 draw 都回读 | 性能工作 |
|
||||
| P8 转出(monolith,ID-P8-13):9 条 monolith 缺陷真实内容 0 命中,不在 dev 上修——Espryt `*IndirectCount` / 原生 indirect `gl_BaseVertex` / fp64 收窄读未同步影子;Magma `glMultiDrawArraysIndirectCount` CPU 臂同病;Magma 录制中途 `SyncGpuWrites` → SIGSEGV;Espryt RGB16F / RGB32F CPU 滤波读陈旧影子、R11F / 深度链无视 BASE / MAX;Magma 无 BLIT 颜色格式缺着色器 mip 臂;Espryt 拷贝后 `glGetTexImage` 读拷贝前影子(证据见 `notes/p8/{B,C,D,E}.md`) | P13(monolith 换到已修好的记录臂) |
|
||||
| P8 转出(monolith,feat,ID-P8-14):feat 的 monolith 臂每次 indirect draw 在命令缓冲有 GPU 写时整 buffer 同步回读(`SyncClientSideVertexArraysForIndirectFetch`,`62bfe461`,dev 无);Magma 的 split 构建 monolith 深度 mip 不传 view 类型,无深度 `BLIT_DST` 的设备上 1D 深度链会拿到 2D view(推断,Release 下断言编译掉,SV) | P13(monolith 换臂) |
|
||||
| P8 转出(ID-P8-19):create-indirect × Magma × spawn 在红米上由 0.84 变为每次丢设备(该 fixture 的 indirect 命令本身是乱的;推断 D 原生化后乱命令直达 GPU,monolith 臂一直原生、基线上也偶发丢设备);坏命令能打挂 GPU 是 GL 未定义行为,robust buffer access 可兜住 | 待归因(fixture 重抓后复测) |
|
||||
| P8 转出(ID-P8-14):create-indirect fixture 在桌面上抓(SSBO 偏移对齐 16),Adreno 要求 64,任何臂任何后端都过不了;设备车道记为不适用 | 需要时在对齐 64 的设备上重抓 |
|
||||
| P8 转出(MD):dev 的 `RingAllocateSlow` 在出错的上下文上无上限地排水(设备上挂在 `glFinish`) | 小修(dev) |
|
||||
| P8 转出:`LogForwardChannel.APeerThatStopsReadingCostsWarnLinesNotTheCallersTime` 在负载下超时(两次),单跑必过 | 小修(放宽时限或隔离) |
|
||||
| P8 转出(SV):`gen_pipe_dirty_surface.py` 扫描集成测试源,测试成员名与 GLContext 成员同名(如 `m_parameters`)会静默弄坏它的自检;`.Mip3DValidation.` 在没装校验层的车道上是失败不是跳过 | 小修 / CI 记录 |
|
||||
|
||||
@@ -20,7 +20,7 @@ P0 已回答的不再列出(spike A 的域、spike B 的分档、`posix_spawn`
|
||||
14. **推送模型改变哪些按拉取模式调过的缓存命中率。** 幸存者容量在 P13 重调。一条线索:设备上 26.3 Espryt 的 `sve` ≈ draw 数(每 draw 重发一次 sampler-view 集合),桌面只有 ~0.07/draw;列入 P3b/P4b 优化清单。
|
||||
15. **monolith 的 `*IndirectCount` 不调 `SyncGpuWrites()` 是不是潜在缺口。** 独立 `dev` 问题,拆分不得借机顺手修。**已答(2026-09-30):是**——P8-C / P8-D 主机 red-once 证实(Espryt `*IndirectCount`、Magma `glMultiDrawArraysIndirectCount` 读到 0);split 半已修(ID-P8-9),monolith 半在 P8 第二波的 dev 包里修(ID-P8-3)。
|
||||
16. **索引宿主镜像的实际内存占用。** MC / Sodium / Iris 语料里 element-array buffer 总量未测;若显著超 64 MiB,退化路径的频率与代价必须实测。P8。
|
||||
17. **`create-indirect` fixture 在 Adreno 830 上的失败**是 `dev@81b17c0b` 就有的(基线 APK 复现),不是本分支造成;`rd12` + Magma 在两台 Adreno 830 上的 `scudo::reportMapError` 崩溃同样是 `dev` 侧。两者排除在设备 A/B 之外、留在桌面语料里;P8 要在 `create-indirect` 上断言 `roundtrips-per-frame == 0`,所以 `dev` 的修复在别人的关键路径上。
|
||||
17. **`create-indirect` fixture 在 Adreno 830 上的失败**是 `dev@81b17c0b` 就有的(基线 APK 复现),不是本分支造成;`rd12` + Magma 在两台 Adreno 830 上的 `scudo::reportMapError` 崩溃同样是 `dev` 侧。两者排除在设备 A/B 之外、留在桌面语料里;P8 要在 `create-indirect` 上断言 `roundtrips-per-frame == 0`,所以 `dev` 的修复在别人的关键路径上。**create-indirect 部分已答(2026-09-30)**:原 fixture 在 `GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT` = 16 的桌面驱动上抓,Flywheel 按 16 摆 scatter 列表;Adreno 830 两后端与 Mali 的 Vulkan 要 64,1,270 次范围绑定全被 `GL_INVALID_VALUE` 拒掉。原 fixture 退役,换成派生的 `minecraft-1.21.1-neoforge-create-indirect-in-world-align1024`(**不是同一个 trace**:`tools/trace_replay/fixture_tools/realign_buffer_ranges.cpp --align 1024` 把这些绑定挪到 1024 对齐的槽,插入 3,812 个调用,目标调用 504631 → 508443;主机 SSIM 与原 fixture 9 位一致)。红米两后端 monolith / spawn 全过;Mali-G1-Ultra 上 Magma 全过(split 臂另修了 T0 POST,见 `CONTRACT-P11.md` POST 节),Espryt 仍 0.848:该机 GLES 驱动顶点阶段 SSBO 上限为 0,Flywheel indirect 的顶点程序链接不了(能力缺失,不是分离缺陷)。
|
||||
18. **split 两侧的负载平衡。** P5e 解锁出来的新问题:VD32(~3550 draws/帧)下 apply 线程 **11-12 ms**、client **15.7 ms**,**client 是瓶颈且打满 ~94%**。把工作从 client 挪到 apply 会直接降瓶颈——这在 lockstep 下毫无意义(两侧串行相加),**run-ahead 才使它成为一个杠杆**。供选:编码侧的 emitter、tracker 走查、持久映射的脏页追踪(`change_protection` 在侧写里占 1.3%)。需先重新侧写:等待消失后尾部各项的分母都变了。排在 P5e 之后;无主,2026-09-22 建议挂在路线图推完后的优化阶段,P6.5 的 2×2 矩阵车道顺带重新侧写
|
||||
19. **链路带宽预算与压缩。** TCP 终局下 `SEG_STAGE` 字节/帧对的是 Wi-Fi / USB(量级 30–100 MB/s),不是内存;`ARCHITECTURE.md` §14 的 ~1 MB/帧预算在 60 fps 是 60 MB/s,已贴着 Wi-Fi 上限。是否对 stage 载荷做 LZ4 类压缩、纹理上传是否按内容哈希在 server 侧去重,要等门 8 的分布出来再定。P6.5 契约写下第一行之前必答。
|
||||
20. **大单次上传的停顿。** 128 MiB 一次上传在 50 MB/s 上是 2.5 s;内容侧分块解决的是"装不装得下",不是"要等多久"。跨机臂上要么接受并记录,要么给上传做异步化(与 P9 的语义一起想)。不假装解决。
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
| **P12**(已收官)server 自有屏幕窗口 | [`p12/`](p12/README.md) | `PLAN-P12.md`、`INTEGRATOR-DECISIONS-P12.md`、`device/` |
|
||||
| P8 / P9 / P10 / P11 / P13(待排) | [`p8/`](p8/README.md)、[`p9/`](p9/README.md)、[`p10/`](p10/README.md)、[`p11/`](p11/README.md)、[`p13/`](p13/README.md) | 目前只有路线图上的完整范围与出口门 |
|
||||
|
||||
跨阶段:[`DEBTS.md`](DEBTS.md)(仍开放的债务与去向)、[`OPEN-QUESTIONS.md`](OPEN-QUESTIONS.md)(开放问题全文,编号稳定);[`handoff/`](handoff/)(P7 的集成者审查稿,路径被 P7 交接文档引用,保持原位);[`recovered/`](recovered/)(从失败的 workflow 运行里捞回的 P0–P2 期材料,`wf1` 设计定稿前的计划草案、`wf2` P0、`wf3` P0.5、`wf4` P1、`wf5` P2;与阶段目录逐字节重复的副本已于 2026-09-24 删除,只留独有的);[`perf-five-arm-20260928/`](perf-five-arm-20260928/README.md)(非阶段的五臂传输性能对比与瓶颈归因,2026-09-28)。
|
||||
跨阶段:[`DEBTS.md`](DEBTS.md)(仍开放的债务与去向)、[`OPEN-QUESTIONS.md`](OPEN-QUESTIONS.md)(开放问题全文,编号稳定);[`handoff/`](handoff/)(P7 的集成者审查稿,路径被 P7 交接文档引用,保持原位);[`recovered/`](recovered/)(从失败的 workflow 运行里捞回的 P0–P2 期材料,`wf1` 设计定稿前的计划草案、`wf2` P0、`wf3` P0.5、`wf4` P1、`wf5` P2;与阶段目录逐字节重复的副本已于 2026-09-24 删除,只留独有的);[`perf-five-arm-20260928/`](perf-five-arm-20260928/README.md)(非阶段的五臂传输性能对比与瓶颈归因,2026-09-28);[`anland/`](anland/README.md)(非阶段的调研:MobileGL 给 Anland——root Android 上的 Wayland 宿主——当 GL 提供者,两边各要做什么,2026-09-30)。
|
||||
|
||||
## 旧引用怎么找
|
||||
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
# MobileGL 作为 Anland 的 GL 提供者:调研(2026-09-30)
|
||||
|
||||
> 非阶段笔记。只读源码调研,**没做原型、没上设备**。Anland 审计于 `SuperTurtleDev/anland@cc169180`(6.x main),MobileGL 审计于 `p8/main@648800a2`(P8 收官头)。结论里凡是"要做 / 要改"的都是推断,事实部分在两份报告里逐行有出处(方案 B 与 Mesa 对照两处的 Anland 事实直接链到源码)。
|
||||
|
||||
| 文件 | 内容 |
|
||||
|---|---|
|
||||
| [`report-anland.md`](report-anland.md) | Anland 侧:缓冲入口契约、伪造 AHB、同步、帧节奏、进程与 SELinux、容器 GPU 现状、Xwayland glamor、衍生项目、改动插入点(382 处引用) |
|
||||
| [`report-mobilegl.md`](report-mobilegl.md) | MobileGL 侧:Linux client 构建与导出、EGL / GLX 能力、split 的 present 路径、AHB / fd / fence 现状、会话与多窗口限制、GL 覆盖面、文档漂移 |
|
||||
| [`kgsl-as-server.md`](kgsl-as-server.md) | 把内核 kgsl 看成 server:A / B 实为"缓冲归谁"之分,6.x + Mesa 是 A、5.x 是 B;拆分层级与 virtio-gpu native context / virgl 的对应 |
|
||||
| [`brief-anland.md`](brief-anland.md)、[`brief-mobilegl.md`](brief-mobilegl.md) | 派给 Codex 的原始提示词。**两份都把后端名写反了**:Espryt = DirectGLES(GLES),Magma = DirectVulkan(Vulkan);报告已纠正 |
|
||||
|
||||
## 结论
|
||||
|
||||
可行,但两边都要新东西:
|
||||
|
||||
- MobileGL 没有"把帧交回 client"这条路:`MGPPresent` 只有 `FrameSerial`,P12 画在 server 自己的 SurfaceView 上;没有 Wayland WSI、没有可导出的颜色图像、没有 sync_file。
|
||||
- Anland 的 GPU 缓冲入口只有 `linux-dmabuf` v3 的单平面线性 AR24/XR24,靠高通 snapalloc 布局伪造 AHB(非高通直接失败,没有 CPU 退路);没有原生 AHB 入口。
|
||||
- 两条路线:**A** 走标准 Wayland 缓冲(MobileGL 像 Mesa 一样交 `wl_buffer`);**B** 让 Anland 把窗口的 Surface 直接交给 MobileGL server(FCL 形态)。一个应用一个 GL 顶层窗口(游戏)选 B:接口面小、零拷贝、厂商中立,MobileGL 侧主要是推广 P12 已有机制;A 的 `wl_shm` 回读作兜底,A 的原生 AHB 入口按需再做。
|
||||
|
||||
## Anland 是什么
|
||||
|
||||
root Android(KernelSU / SukiSU 模块)上的 Wayland 宿主:守护进程 `waylandbridge`(root,`awl_daemon` 域,bionic,链 Android EGL / GLESv3)实现 Wayland 协议。每个 `xdg_toplevel` 按需挂到一个独立的 Android 窗口(一个 Activity,来自宿主 APK 或接入 libawl 的应用;可随时分离,Wayland 窗口不死);多个 toplevel 可同时各挂一个;popup 与子 surface 合成进父窗口,不单独开窗。Droidspaces 容器经 `/run/anland/wayland-0`(绑定自 `/data/local/tmp/awl`)连入。容器内 GPU 加速 = Mesa freedreno / turnip on kgsl,只有 Adreno;Mali 等走 llvmpipe。
|
||||
|
||||
## 两条路线
|
||||
|
||||
```
|
||||
A:标准 Wayland 缓冲
|
||||
容器应用 ─ MobileGL client(glibc libEGL/libGL)── wl_buffer(wl_shm / AHB 令牌)──→ waylandbridge ─ SC / GLES 合成 ─ SurfaceFlinger
|
||||
│ 同机 unix socket + 共享内存(split 现成) ↑
|
||||
Android 侧 MobileGL render server(root 守护进程,厂商驱动)── AHB 完整句柄(原生入口)──┘
|
||||
|
||||
B:窗口 Surface 直通
|
||||
容器应用 ─ MobileGL client ─ 令牌(Anland 扩展)─→ waylandbridge
|
||||
│ 同机 unix socket + 共享内存 │ binder:窗口 Surface + 挂上 / 分离 / 尺寸
|
||||
Android 侧 MobileGL render server ←────────────────────────┘
|
||||
└ 厂商 EGL / Vulkan swapchain 直接画进该 Surface ─ SurfaceFlinger(Anland 的 popup / 子 surface / 光标作为子层叠在上面)
|
||||
```
|
||||
|
||||
- 两条路线里 Wayland 连接、`xdg_toplevel`、输入与输入法都归 Linux 应用 / Anland;MobileGL 只管帧。
|
||||
- P12 的 server 自有窗口不适用:Anland 下 Android 窗口归 Anland(Activity 的 Surface 交给 waylandbridge 绘制,输入也从这里转成 Wayland 事件),应用的帧必须作为 `wl_buffer` 提交到自己的 `wl_surface`;P12 画进 MobileGL 自己的 Activity,会绕开 Anland 的窗口与输入。B 不是 P12:窗口仍是 Anland 的,只是生产者换成 MobileGL。
|
||||
- 容器内直接让 Magma 跑在 turnip 上:只有 Adreno,和现有 Mesa 同一驱动,价值小;MobileGL 的价值是把厂商驱动(含 Mali)带进来,只能靠 split 跨到 bionic。
|
||||
|
||||
## 对照:容器里现在的 Mesa(freedreno / turnip)
|
||||
|
||||
Mesa 属于 A,准确地说是 A 里"Anland 不改、走 dma-buf"那一档,只是渲染在应用进程内、没有 server。
|
||||
|
||||
| | Mesa freedreno / turnip | 方案 A | 方案 B |
|
||||
|---|---|---|---|
|
||||
| 在哪渲染 | 应用进程内,容器里直接调 kgsl([anland-session.sh:108–112](https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/anland-session/anland-session.sh#L108-L112):`GALLIUM_DRIVER=kgsl`、`FD_FORCE_KGSL=1`) | Android 侧 render server | Android 侧 render server |
|
||||
| 缓冲谁分配 | 应用进程里的 Mesa 经 kgsl 分配,没有 gralloc 元数据 | server 用 gralloc 分配 AHB | Anland 窗口 Surface 自己的缓冲队列 |
|
||||
| 怎么交给 Anland | 标准 Wayland:`zwp_linux_dmabuf_v1` 单平面线性 AR24/XR24 | 标准 Wayland:`wl_buffer` | 不经过 Wayland 缓冲,直接画进 Surface |
|
||||
| Anland 怎么处理 | 伪造 AHB(高通 snapalloc donor)→ SC / GLES 合成 | 原生 AHB 入口,不伪造 | 不经手,只在上面叠子层 |
|
||||
| 同步 | 隐式:提交时 `DMA_BUF_IOCTL_EXPORT_SYNC_FILE` 从 dma-buf 抓写 fence,失败就轮询 dma-buf([awl_surface.c:199–209](https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L199-L209));Mesa EGL 不走 explicit sync v1 是推断 | explicit sync(sync_file) | 缓冲队列内部 |
|
||||
|
||||
Anland 6.x 的 dma-buf 入口就是照 Mesa / kgsl 的产物做的:
|
||||
|
||||
- 伪造 AHB 的起因:注释写明容器 kgsl dma-buf 缺 gralloc 元数据,直接导入被拒([awl_ahb.cpp:10–14](https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L10-L14));这也是只有 Adreno 能加速的原因之一。
|
||||
- Xwayland 补丁迁就 kgsl:把 DRI3 报的错误 modifier `1274` 改成 LINEAR,强制提交 `DRM_FORMAT_MOD_INVALID`,无 v4 feedback 也启用 glamor([anland-kgsl-glamor.patch](https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/patches/xwayland/anland-kgsl-glamor.patch))。
|
||||
- SC 直出 / 拷贝切换按 turnip WSI 调:vkmark 123 fps 对 ~1300 fps([awl_sc.cpp:60–75](https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L60-L75))。
|
||||
|
||||
对 MobileGL 的含义:Mesa 相当于"容器里的 monolith MobileGL",因为 kgsl 能在 glibc 进程里直接用;厂商驱动(bionic)不能,所以 MobileGL 必须 split,渲染挪到 Android 侧,缓冲来源从 kgsl dma-buf 变成 gralloc AHB。"Magma 跑在容器 turnip 上"就是 Mesa 这条路的翻版。
|
||||
|
||||
B 在 6.x 没有对应物(今天只有 waylandbridge 自己往窗口 Surface 里画)。5.x 的私有 Anland Display Protocol 介于两者之间:
|
||||
|
||||
- 像 B:Android 端从窗口自己的缓冲队列 `dequeueBuffer`,只导出 `handle->data[0]` 给容器里的合成器(如 KWin + Mesa),合成器画完回 sync_file,Android 端 `queueBuffer`;缓冲属于窗口,零拷贝、不伪造([protocol.h:7–49](https://github.com/SuperTurtleDev/anland/blob/9ab13eb146bc9f3dd3cc44cabc268659d9eb0a46/common/protocol.h#L7-L49)、[native_consumer.c:144–172](https://github.com/SuperTurtleDev/anland/blob/9ab13eb146bc9f3dd3cc44cabc268659d9eb0a46/consumers/anland_v5/android_consumer/app/src/main/jni/native_consumer.c#L144-L172)、[:955–1003](https://github.com/SuperTurtleDev/anland/blob/9ab13eb146bc9f3dd3cc44cabc268659d9eb0a46/consumers/anland_v5/android_consumer/app/src/main/jni/native_consumer.c#L955-L1003))。
|
||||
- 像 A:缓冲仍以 dma-buf 跨进程,依赖容器 Mesa / kgsl 能把 gralloc 的 `data[0]` 当线性缓冲导入,同样只有 Adreno。
|
||||
|
||||
6.x 为了让原生合成器不改就能接入,换回了标准 Wayland 缓冲(A 这条路)。
|
||||
|
||||
换个角度——把内核 kgsl 当 server 读这张表——见 [`kgsl-as-server.md`](kgsl-as-server.md)。
|
||||
|
||||
## 两边现状
|
||||
|
||||
| | MobileGL | Anland |
|
||||
|---|---|---|
|
||||
| 帧入口 / 出口 | `MGPPresent{FrameSerial}`;P12 画在 server 窗口 | `wl_shm` v2(ARGB / XRGB);`linux-dmabuf` v3 单平面线性 AR24/XR24 |
|
||||
| 窗口 / Surface | P12 `ServerDisplay` 租约(acquire / release / 几何),每进程一个自有窗口,失窗即 `Fatal{ServerWindowLost}` | 每个挂上的窗口一个 Surface,经 binder `T_SURFACE` 用 `ANativeWindow_readFromParcel` 收进守护进程([waylandbridge.cpp:1587–1626](https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L1587-L1626));EGL 模式守护进程是它的生产者([awl_renderer.cpp:101](https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_renderer.cpp#L101)),SC 模式只从它挂子层([awl_sc.cpp:676](https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L676)),缓冲队列空闲 |
|
||||
| 窗口系统 | 无 Wayland;EGL 扩展只有 `EGL_KHR_create_context`、`EGL_MESA_platform_surfaceless` | dma-buf → 高通 snapalloc donor 伪造 AHB(写死 HAL BGRA=5,要求 2 fd 句柄) |
|
||||
| 同步 | 无 sync_file / SYNC_FD;`eglCreateSync` 创建即 signaled,`eglCreateImage` 只登记 | explicit sync v2(sync_file),acquire / release 都有;无 drm-syncobj |
|
||||
| 原生缓冲 | AHB 只用于 P11 T0 的 BLOB 缓冲存储 | 无原生 AHB 入口;但 SC 池自己分配并上屏 RGBA AHB(`GPU_COLOR_OUTPUT\|GPU_SAMPLED_IMAGE\|COMPOSER_OVERLAY`),消费端能力已有 |
|
||||
| 并发 | 每 supervisor 一个会话(`Refuse{Busy}`);`pGLContext`、Espryt `g_Display/g_Context/g_Surface`、Magma `pVulkanRenderer` 全局;多 context 未做(DEBTS) | 客户端不限;每窗 ≤16 层;队列 8;SC 模式为默认(`sc_enabled=1`) |
|
||||
| 部署 | Linux client 只验过 x86_64;无 aarch64 glibc;只有 `libEGL.so(.1)` 别名,无 glvnd | 模块启动,`awl_daemon` 域 permissive;容器进程在 `droidspacesd` 域 |
|
||||
|
||||
## MobileGL 要做的
|
||||
|
||||
### 两条路线共用
|
||||
|
||||
| # | 项 | 内容 | 量级 |
|
||||
|---|---|---|---|
|
||||
| C1 | aarch64 glibc 构建与加载 | 交叉工具链 + CI + 与 Android server 的 wireFingerprint 验收;建议做 glvnd vendor(`__egl_Main` + egl_vendor.d JSON),容器 Mesa 就是 glvnd | M |
|
||||
| C2 | 多 client / 多窗口 / 多 context | 先 worker-per-client(离屏 fork-per-session 有底子,去掉 Busy、做路由),再 per-surface 状态,再真 share group;单窗口游戏可暂缓,GTK / Qt / 浏览器离不开 | L |
|
||||
| C3 | 部署 | `libMobileGLServer.so --serve unix:/data/local/tmp/awl/mobilegl.sock` 作 root 守护进程由模块拉起、独立 SELinux 域,不走 APK;GLES 有 waylandbridge 先例,Vulkan 需实测 | S |
|
||||
| C4 | 桌面程序会撞的空壳 | EGL sync / image 空壳;无 `EGL_KHR_surfaceless_context`;GLES context 名不副实(`GL_VERSION` 报桌面 4.6);无固定管线;device lost 时 swap 不返回 `EGL_CONTEXT_LOST`(与 design/08 不符) | 按需 |
|
||||
| C5 | X11 | GLX 外壳 + MIT-SHM 回读上屏(通用、慢);DRI3 需要 Xwayland glamor(GBM + dma-buf 导入导出)→ 建议 Xwayland 继续用 Mesa / 软件 | 后置 |
|
||||
|
||||
### 仅方案 A
|
||||
|
||||
| # | 项 | 内容 | 量级 |
|
||||
|---|---|---|---|
|
||||
| A1 | 帧回交 | server 每个窗口 surface 约 4 个 AHB 槽(RGBA8888);Espryt 用 EGLImage 当默认帧缓冲,Magma 用外部内存 VkImage 代替 swapchain;Present 带 surface id / 槽号 | L |
|
||||
| A2 | 真 fence | Espryt `EGL_ANDROID_native_fence_sync`、Magma `VK_KHR_external_semaphore_fd`(SYNC_FD)导出完成 fence;导入 release fence 后才复用槽 | M |
|
||||
| A3 | 协议 | 新窗口类型 + 缓冲池注册 / 帧就绪(带 fence fd)/ 缓冲释放;现有 fd 传递单条 1 fd、sideband 256 B、client 只在握手收 → 要常驻接收;TCP 不传 fd,只能走 unix / `fd:` 端点 | M |
|
||||
| A4 | client 端 Wayland | `EGL_PLATFORM_WAYLAND_KHR` / `wl_egl_window`;attach / damage / commit、frame callback 定节奏、configure / resize、viewporter 与分数缩放(缓冲像素 ≠ 逻辑尺寸);Anland 隐藏窗口会扣住 callback,不能因此 `PresentCreditTimeout` 丢会话。`wl_shm` 兜底也要这一项 | M |
|
||||
|
||||
### 仅方案 B
|
||||
|
||||
| # | 项 | 内容 | 量级 |
|
||||
|---|---|---|---|
|
||||
| B1 | Surface 接入 | server 经 binder 从 Anland 接窗口 Surface(`ANativeWindow_readFromParcel`,API 34+,与 waylandbridge 同一要求),交给现有 swapchain 路径(Espryt `eglCreateWindowSurface`、Magma `vkCreateAndroidSurfaceKHR`) | S |
|
||||
| B2 | 推广 `ServerDisplay` | P12 的租约从"进程唯一的自有窗口"推广为"每个 surface 由 Anland 按令牌提供的窗口";尺寸由 Anland 事件驱动 | M |
|
||||
| B3 | 失窗非致命 | Anland 分离窗口 → Surface 销毁 → 释放后端 surface,client 的 `eglSwapBuffers` 阻塞或丢帧直到重新挂上;今天 P12 是 `Fatal{ServerWindowLost}` 闩会话 | M |
|
||||
| B4 | client 端 | `wl_egl_window` 只用来拿 `wl_surface` 与尺寸:从 Anland 扩展取令牌交给 server、转发 resize,不提交 `wl_buffer`;节奏靠 server 端 swapchain 的 FIFO | S |
|
||||
|
||||
## Anland 要改的
|
||||
|
||||
### 方案 A
|
||||
|
||||
| 档 | 改动 | 得到 |
|
||||
|---|---|---|
|
||||
| 不改 | server 回读进 `wl_shm`(写进 client 的 shm pool) | 所有 GPU 可用;每帧回读 + 上传(1080p ≈ 8 MB);正确性基线,也是 B 覆盖不到时的兜底 |
|
||||
| 不改(dma-buf) | server 专门分配线性 BGRA,client 解析 AHB 线格式取 fd[0] 走 `linux-dmabuf` | 只有高通,脆弱,不推荐 |
|
||||
| 原生 AHB 入口 | ① 给 render server 的本机注册通道(`AHardwareBuffer_recvHandleFromUnixSocket` 或新 binder 事务),返回绑定 client uid 的令牌 ② 新 Wayland 全局把令牌包成 `wl_buffer` ③ `awl_buffer` / `awl_bq_buffer` 改带类型标签(现把 `dmabuf_fd<0` 当空) ④ `awl_ahb_cache_get` 原生缓冲跳过伪造 ⑤ `awl_ahb_hwc_scanout_ok` 不作用于原生缓冲 ⑥ 原生缓冲只走显式 release ⑦ GL / SC 路径正确处理 RGBA | 不依赖高通、Mali 可用;保留 UBWC 与 HWC 直出;glibc client 不碰 gralloc |
|
||||
|
||||
### 方案 B
|
||||
|
||||
| 改动 | 说明 |
|
||||
|---|---|
|
||||
| Wayland 扩展 | 把某个 `wl_surface` 标成外部渲染 → 返回令牌;允许不提交 `wl_buffer` 也能映射;frame callback 仍按 vsync 发 |
|
||||
| Surface 交接 | 把该窗口的 Surface 与挂上 / 分离 / 尺寸事件交给 MobileGL server(守护进程 `ANativeWindow_writeToParcel` 转发,或 server 调 `anland.host` 新事务在回包里取);分离前先通知收回 |
|
||||
| SC 结构 | 该窗口强制 SC 模式;不给根 surface 建子层;popup / 子 surface / 光标照常作为子层叠在上面 |
|
||||
| 鉴权 | 只把 Surface 交给与该 `wl_surface` 同一 client uid 的会话 |
|
||||
|
||||
局限:只覆盖 toplevel 的根 surface(子 surface 上的 GL 如视频播放器走 A);GL 画面与其他图层不是原子提交;父层之下的子 surface 看不见;EGL 模式不可用;Anland 基于缓冲的机制(扣缓冲停车、SC 直出 / 拷贝切换)不作用于这个窗口。
|
||||
|
||||
### 共用
|
||||
|
||||
| 档 | 改动 | 得到 |
|
||||
|---|---|---|
|
||||
| 顺手修 | `DRM_FORMAT_MOD_INVALID` 写成 `0x00ffffff00000000`(UAPI 为 `0x00ffffffffffffff`);offset 被忽略、modifier 不校验 | 修 bug;只往格式表加 AB24 不够(伪造写死 BGRA) |
|
||||
| 部署 | `service.sh` 拉起 MobileGL server;sepolicy 新域:`droidspacesd` connectto、双向 fd use、SurfaceFlinger / HWC / system_server 对新域 fd 的 use;B 另需 binder 互调规则 | 必需 |
|
||||
| 可选 | `linux-dmabuf` v4 feedback(main_device)、`wp_presentation` | Xwayland / 帧时统计 |
|
||||
|
||||
A 的原生 AHB 入口与 B 的扩展都要 Anland 作者合入,先给他们接口草案;B 贴合 Anland 现有的 SC 结构,但是 Anland 专用,不是标准协议。
|
||||
|
||||
## 分期
|
||||
|
||||
1. **M0**(Anland 不改):C1 + A4 + `wl_shm` 回读,单应用单窗口闭环;验节奏、resize、隐藏窗口。之后作兜底。
|
||||
2. **M1**(方案 B):Anland 扩展 + B1–B4;一个 GL 顶层窗口的应用零拷贝。
|
||||
3. **M2**:C2 多 client / 多窗口 / 多 context,GLES context。
|
||||
4. **M3**(按需):A1–A3 + Anland 原生 AHB 入口,覆盖子 surface 上的 GL 与 EGL 模式。
|
||||
5. **M4**:C5 X11 走 MIT-SHM;glamor / GBM 视需求。
|
||||
|
||||
## 只能上设备回答的
|
||||
|
||||
- root 守护进程能否加载厂商 Vulkan(GLES 有 waylandbridge 先例)。
|
||||
- enforcing 下完整的 SELinux 规则。
|
||||
- B:外部进程连上 SurfaceView 父 Surface 当生产者,与 Anland 的子 SurfaceControl 并存是否正常;resize 时缓冲尺寸与层几何短暂不一致的表现。
|
||||
- A:各家 gralloc 的 RGBA / UBWC 缓冲能否被 SF 直接上屏;Mali 上回读路径的性能。
|
||||
|
||||
## 旁支
|
||||
|
||||
- Termux 原生(bionic)程序可以进程内直接加载 MobileGL(monolith,厂商驱动),不需要 split;帧交接同样是 A(A1、A2、A4)或 B(Surface 交给该进程)二选一。但 Termux 线目前基于 Anland 5.x(lfdevs 维护)。
|
||||
- 这项工作不在 [`../../ROADMAP.md`](../../ROADMAP.md) 里,要做是一个新阶段。
|
||||
@@ -0,0 +1,24 @@
|
||||
# Brief A — Anland deep dive (READ-ONLY research)
|
||||
|
||||
Context: we are evaluating whether MobileGL (a desktop-OpenGL implementation for Android that translates GL onto the device's GLES driver ("Magma" backend) or Vulkan driver ("Espryt" backend), and which can now run split into a *client* process (the app's libGL/libEGL, can be glibc Linux) and a *render server* process (on Android, uses the vendor bionic GPU driver), connected by unix socket + shared memory or TCP) could be the GL provider for graphical Linux apps shown through **Anland**. We need precise facts about what Anland accepts and how it works, so we can say what MobileGL must implement and what Anland must change.
|
||||
|
||||
Repos are already cloned (shallow, read-only) under:
|
||||
`<scratchpad>/anland/`
|
||||
- `SuperTurtleDev_anland` (main = 6.x; the core: `services/waylandbridge/`, `app/`, `app/libawl/`, `module/`, `anland-session/`, `patches/`)
|
||||
- `SuperTurtleDev_anland-shell`, `lfdevs_anland-termux`, `E7G_wlroots-anland`, `asveroid_anland-plasma-termux`, `Yizhou147_anland-drm`
|
||||
You may also `git clone --depth 1 -b legacy https://github.com/SuperTurtleDev/anland.git` into that same `anland/` folder if you need to compare with 5.x, and use the web / GitHub (`gh`) for issues/discussions about GPU acceleration. Do NOT modify any other location. Use the shell available to you (Git Bash on Windows is fine; WSL `wsl.exe -d Arch -- bash -lc "..."` also works).
|
||||
|
||||
Answer each question with file:line citations. Be concrete; quote struct/enum values and constants where relevant.
|
||||
|
||||
1. **Buffer ingress contract of waylandbridge.** Which wl_buffer kinds are accepted (wl_shm formats; zwp_linux_dmabuf_v1 version, formats, modifiers, number of planes, feedback/default-feedback support, `main_device`/dev_t advertised?). What exactly happens to a dma-buf from `create`/`create_immed` to display: read `awl_dmabuf.c`, `awl_bufferqueue.*`, `awl_ahb.cpp` (the "forging" of an AHardwareBuffer around a container dma-buf: donor blob, calibration, `AHardwareBuffer_recvHandleFromUnixSocket`), `awl_gl.cpp`, `awl_sc.cpp`, `awl_renderer.cpp`. What are the preconditions for a dma-buf to be accepted (linear only? stride rules? size? format BGRA only? what if the buffer came from gralloc already?) and failure modes (refuse vs GPU copy). Is there any path that accepts a *native* AHardwareBuffer / gralloc handle from a client directly (not a raw dma-buf)? How is UBWC/compression handled or excluded?
|
||||
2. **Sync.** `awl_esync.c`: which explicit-sync protocol (zwp_linux_explicit_synchronization_v1 version, linux-drm-syncobj?), acquire fence handling (waits CPU-side? hands to SF as acquire fence?), release fences, `wl_buffer.release` timing in SC vs EGL modes. Implicit sync assumptions for clients that don't use explicit sync.
|
||||
3. **Presentation / frame pacing.** frame callbacks, presentation-time, how many buffers a client should cycle, what "parking" of hidden windows does to clients (frame callbacks stop?), viewporter/fractional-scale, subsurfaces.
|
||||
4. **Connection & process model.** How a container app reaches waylandbridge (socket path, bind mount, binder fd passing, `anland-session`/`setup.sh`), what uid / SELinux domain the daemon runs in (`module/sepolicy.rule`, `plat_service_contexts.anland`, `service.sh`), what the container's processes run as, and whether a *second* Android-side daemon (e.g., a GL render server executable shipped by us) could be launched the same way and reached from the container (socket location, SELinux rules that would be needed for fd passing between container processes and that daemon, or an untrusted_app APK process). How does libawl let a third-party Android app host Wayland windows (binder API, `Awl.java`, `AwlClient.java`, `include/awl.h`) — could an Android-side GL server use it?
|
||||
5. **GPU acceleration today.** How container apps get GPU rendering now (Mesa turnip/freedreno on kgsl? zink? llvmpipe on Mali?): check `patches/xwayland/anland-kgsl-glamor.patch` + README, `anland-session/*`, `lfdevs_anland-termux` (mesa version/build flags, what drivers, termux-native vs proot vs chroot), `asveroid_anland-plasma-termux`, anland-shell. Any mention of Mali/PowerVR/Xclipse support or lack thereof, GL version reached, known perf numbers. What does Xwayland glamor need (GBM, EGL_EXT_image_dma_buf_import, EGL_MESA_image_dma_buf_export, DRI3) and what did the patch change?
|
||||
6. **The waylandbridge renderer itself.** Does waylandbridge use Android's own EGL/GLES (bionic, vendor driver) — how is it statically linked yet using the vendor driver? What does it tell us about a root native executable on Android loading the vendor GLES/Vulkan driver (linker namespaces)?
|
||||
7. **Derivatives.** `E7G_wlroots-anland` ("native Anland dma-buf backend"), `Yizhou147_anland-drm`, legacy 5.x "Anland Display Protocol": one paragraph each on what they reveal about alternative frame paths (e.g., a private protocol that could carry AHB handles).
|
||||
8. **Where Anland would need to change** to (a) accept buffers rendered by an Android-side GL server that allocates them with AHardwareBuffer_allocate (gralloc, possibly UBWC, RGBA8888 i.e. DRM ABGR8888), and (b) avoid the forge round-trip. List the concrete insertion points (functions/files) and the smallest viable change vs the clean change.
|
||||
|
||||
Output: write the full report (Markdown, Chinese or English, tables welcome, every claim cited file:line) to
|
||||
`<scratchpad>/report-anland.md`
|
||||
**BEFORE** your final message; then make your final message a 10-line summary. Mark anything you inferred (not read) as "inferred".
|
||||
@@ -0,0 +1,21 @@
|
||||
# Brief B — MobileGL inventory for a "GL provider for Linux-on-Android (Anland)" scenario (READ-ONLY)
|
||||
|
||||
Context: Anland (github.com/SuperTurtleDev/anland, 6.x) is a Wayland host on rooted Android: Linux apps run in a glibc container (Droidspaces chroot; also Termux native (bionic) and PRoot) and connect to a root Android daemon `waylandbridge` over a wayland socket. waylandbridge accepts `wl_shm` and `zwp_linux_dmabuf_v1` buffers (today: single-plane ARGB8888/XRGB8888, LINEAR/INVALID modifier only), forges an AHardwareBuffer around the dma-buf and hands it to SurfaceFlinger (SurfaceControl mode) or composites it with GLES (EGL mode); it also implements zwp_linux_explicit_synchronization_v1. Container apps get GPU today only through Mesa (turnip/freedreno on kgsl, zink) — i.e. Adreno only.
|
||||
The question: what must **MobileGL** implement so that Linux apps in that container (and Xwayland/X11 apps) render through MobileGL — most plausibly by using the disaggregated split: a glibc aarch64 *client* in the container, the Android *render server* using the vendor driver — and hand frames to Anland.
|
||||
|
||||
Code: the up-to-date integration tree is in Arch WSL at `~/w7/p9-main` (branch feat/disaggregated, P8 closed). Operate it ONLY through `wsl.exe -d Arch -- bash -lc "<cmd>"` and read-only commands (cat/grep/git log/git grep/find). Do NOT build, do NOT edit, do NOT run git commands that change the tree (checkout/restore/stash/reset/commit), do NOT touch other trees or devices. Docs to start from: `docs/Disaggregated/ARCHITECTURE.md`, `design/*.md` (esp. 06-transport, 08-runtime-and-platform, 09-build-switches-counters), `ROADMAP.md`, `notes/p12/*`, `notes/DEBTS.md`, `notes/OPEN-QUESTIONS.md`, `MobileGL/MG_Remote/CONTRACT-*.md`, then the code (`MobileGL/MG_Remote/`, `MobileGL/MG_Impl/EGLImpl*`, `MobileGL/MG_Impl/GLXImpl/`, backends' surface/swapchain/present code, CMake options for Linux/client/server builds, `android-plugin/` server APK / `MobileGLDisplayActivity` / `MobileGLServerService`).
|
||||
|
||||
Answer each with file:line citations (paths relative to the tree root):
|
||||
|
||||
1. **Linux client build.** Can the client side be built for Linux glibc today (x86_64 WSL/CI yes? aarch64?) Which CMake options/presets; which libraries are produced (names/sonames: libGL? libEGL? libMobileGL.so?); which API entry points are exported (desktop GL core/compat versions, GLES API via eglBindAPI(EGL_OPENGL_ES_API)? GLX? EGL?). Is there libglvnd vendor integration (`__egl_Main`, `__glx_Main`, egl_vendor.d JSON) or does it replace libGL/libEGL directly?
|
||||
2. **EGL frontend capabilities.** Supported EGL platforms/native window types on Linux (surfaceless only? `EGL_PLATFORM` handling, x11/wayland/gbm?), `eglGetPlatformDisplay`, config attributes, window/pbuffer/pixmap surfaces, context sharing, multiple contexts/threads per client, which EGL extensions are advertised (esp. EGL_EXT_image_dma_buf_import(_modifiers), EGL_MESA_image_dma_buf_export, EGL_KHR_fence_sync / EGL_ANDROID_native_fence_sync, EGL_KHR_swap_buffers_with_damage, EGL_EXT_buffer_age). What does GLXImpl do (does it talk to an X server? DRI? or is it a stub for desktop builds)?
|
||||
3. **Present path in split mode today.** Trace `eglSwapBuffers` from client to server for (a) client-owned window (`SetWindowHandle`, Rule H), (b) `MOBILEGL_IPC_SURFACE=server` ServerOwned (P12), (c) pbuffer/surfaceless. Where does the server get its presentation target in each backend (Espryt: VkSurfaceKHR/VkSwapchainKHR from ANativeWindow? Magma: EGL window surface?). Is there ANY existing code that renders the default framebuffer into an exportable buffer (AHardwareBuffer, dma-buf, VK_ANDROID_external_memory_android_hardware_buffer, VK_KHR_external_memory_fd, EGLImage from AHB, `eglGetNativeClientBufferANDROID`) and sends it back to the client, or that exports a fence fd (VK_KHR_external_semaphore_fd SYNC_FD / EGL_ANDROID_native_fence_sync)? Grep for AHardwareBuffer, dma_buf, DMA_BUF, SCM_RIGHTS, sync_file, SYNC_FD, external_memory across the tree and report every hit's purpose (e.g. P11 adoption / T0 POST).
|
||||
4. **Fd passing & transports.** Which transports can carry file descriptors (control plane is said not to; the ShmLink aux AF_UNIX rendezvous does SCM_RIGHTS) — where is that code, and how hard is it to add "server → client: here is a buffer fd + a fence fd per present"? Who creates the shm segments (client-owned SEG_CMD/SEG_STAGE via memfd on Linux) — relevant because an Android untrusted_app server may be SELinux-denied `fd use` on fds created by a root container process.
|
||||
5. **Session/multiplicity limits.** One server per device, one session at a time (`Refuse{Busy}`), one surface mode per session, server-owned single window, "fork-per-session" supervisor for offscreen — cite where these limits live and how deep they are (supervisor only, or process-global state in backends?). What would it take to serve N concurrent clients each with M windows (a Linux desktop runs many GL apps + possibly Xwayland glamor)?
|
||||
6. **Window-system-facing events already in the protocol.** Resize/geometry, `SurfaceOp/SurfaceReply`, `WindowKind`, device-lost behavior, present credit (`MOBILEGL_IPC_PRESENT_CREDIT`) and how a compositor's frame callbacks / buffer release would plug in.
|
||||
7. **GL coverage relevant to generic Linux desktop apps** (not only Minecraft): max GL version per backend, compatibility profile / fixed-function support, GLES contexts, GLX_ARB_create_context, known gaps listed in docs. One short table.
|
||||
8. **Anything in docs/notes/OPEN-QUESTIONS/DEBTS that already anticipates Linux-on-Android, Wayland, dma-buf, AHB export, multi-client, or Termux** — quote it.
|
||||
|
||||
Output: write the full report (Markdown; Chinese OK; tables welcome; every claim cited) to the Windows path
|
||||
`<scratchpad>/report-mobilegl.md`
|
||||
using your own file-writing tool (not a heredoc inside bash -lc), **BEFORE** your final message; then make your final message a 10-line summary. Mark anything you inferred (not read) as "inferred".
|
||||
@@ -0,0 +1,47 @@
|
||||
# 把 kgsl 看成 server:A / B 两条路线的另一种读法(2026-09-30)
|
||||
|
||||
> 接 [`README.md`](README.md) 的"对照:容器里现在的 Mesa"。只读推演,没做实验;Anland 事实链到审计版本(6.x `cc169180`、5.x `9ab13eb1`)。
|
||||
|
||||
## 结论
|
||||
|
||||
A / B 的区别不在"渲染器放在哪",而在**缓冲归谁**:
|
||||
|
||||
- **A**:server 分配缓冲、画好,把句柄交给合成器。
|
||||
- **B**:窗口把自己的缓冲交给 server,server 直接画进去。
|
||||
|
||||
把内核 kgsl 当 server,Anland 两代现有路径正好各占一条:6.x + Mesa 是 A,5.x 私有协议是 B。
|
||||
|
||||
## 对照
|
||||
|
||||
| | 6.x + Mesa | 5.x 私有协议 | MobileGL A | MobileGL B |
|
||||
|---|---|---|---|---|
|
||||
| client | 应用进程里的完整用户态驱动(freedreno / turnip) | 合成器进程(如 KWin)里的 Mesa | 应用进程里的 GL 前端 | 同 A |
|
||||
| server | 内核 kgsl | 内核 kgsl | Android 用户态进程(厂商驱动,往下仍是 kgsl / kbase) | 同 A |
|
||||
| 命令通道 | ioctl + 共享 GPU 内存 | 同左 | MGPipe(共享内存环 + 门铃) | 同 A |
|
||||
| 缓冲归谁 | kgsl 分配 → dma-buf 给 client → `wl_buffer` → Anland 导入(伪造 AHB) | 窗口缓冲队列分配 → `data[0]` 以 dma-buf 交给 kgsl 渲染 → 回 sync_file → Android 端 `queueBuffer` | server 用 gralloc 分配 AHB → Anland | 窗口 Surface 交给 server |
|
||||
| 形状 | A | B | A | B |
|
||||
|
||||
5.x 出处:[protocol.h:7–49](https://github.com/SuperTurtleDev/anland/blob/9ab13eb146bc9f3dd3cc44cabc268659d9eb0a46/common/protocol.h#L7-L49)、[native_consumer.c:144–172](https://github.com/SuperTurtleDev/anland/blob/9ab13eb146bc9f3dd3cc44cabc268659d9eb0a46/consumers/anland_v5/android_consumer/app/src/main/jni/native_consumer.c#L144-L172)、[:955–1003](https://github.com/SuperTurtleDev/anland/blob/9ab13eb146bc9f3dd3cc44cabc268659d9eb0a46/consumers/anland_v5/android_consumer/app/src/main/jni/native_consumer.c#L955-L1003);6.x 伪造 AHB 的起因:[awl_ahb.cpp:10–14](https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L10-L14)。
|
||||
|
||||
## 读出来的三点
|
||||
|
||||
1. **B 不是新东西。** Anland 5.x 就是 B,只是 server 在内核。6.x 放弃它是为了让原生合成器不改就能接入,不是因为做不通。
|
||||
|
||||
2. **server 在内核时两条路都只需要传 fd;挪到用户态就多一层。**
|
||||
- 内核对象(dma-buf fd、sync_file)任何进程都认。
|
||||
- server 是用户态进程时:A 要传完整 AHB(gralloc 元数据 + dma-buf),B 要传缓冲队列的生产端(Surface)。
|
||||
- 与现状正好相反:kgsl 句柄通用但缺 gralloc 元数据,所以 Anland 只能伪造;MobileGL server 的 AHB 本来就带元数据,Anland 只要肯收完整句柄。
|
||||
- B 也可以照 5.x 逐缓冲交接(Anland `dequeueBuffer` → 整个 AHB 交 server → 回 sync_file → Anland `queueBuffer`);对 MobileGL 交 Surface 更省,直接复用 swapchain。
|
||||
|
||||
3. **拆分层级不同 = virtio-gpu 的 native context 对 virgl / venus。**
|
||||
|
||||
| | Mesa / kgsl(拆在硬件命令层) | MobileGL(拆在 GL 状态层) |
|
||||
|---|---|---|
|
||||
| client 要懂什么 | 这块 GPU 的硬件命令 | 只懂 GL |
|
||||
| 能覆盖的 GPU | 有开源用户态驱动的(现在只有 Adreno) | 有厂商驱动的(含 Mali) |
|
||||
| 额外开销 | 几乎没有 | 状态序列化 + IPC |
|
||||
|
||||
## 对 MobileGL 的启示
|
||||
|
||||
- **server 必须天然多 client**:kgsl 同时服务任意多进程、每进程独立 GPU 上下文——对应 README 的 C2(今天每 supervisor 一个会话)。
|
||||
- **fence 导出(A2)没有原理障碍**:厂商驱动导出 SYNC_FD,最终也是向 kgsl / kbase 要一个 sync_file,fence 仍是内核对象。
|
||||
@@ -0,0 +1,270 @@
|
||||
# Anland × MobileGL: buffer, synchronization, process and integration study
|
||||
|
||||
Research date: 2026-09-30. This is a source audit, not a device validation. All audited checkouts were clean; exact revisions are in the table below. Repository citations link to those revisions. Citations of third-party material that was snapshotted during the audit (Xwayland, drm_fourcc.h, Mesa/Termux build files, libwayland, the AHB header, Anland issues/PRs) link to the upstream source at the snapshotted revision; `refs/heads/main` links (the Android header) may have drifted since 2026-09-30. Statements marked **inferred** are architectural conclusions or proposed changes, not implemented behavior.
|
||||
|
||||
| Tree | Audited revision | Scope |
|
||||
|---|---|---|
|
||||
| `SuperTurtleDev_anland` | `cc1691805fe6aca6851b6fcccb6a1e33019026c1` | Current 6.x main |
|
||||
| `SuperTurtleDev_anland-shell` | `920fcfc8159690f5232e2d9c7c3294d4c1481145` | Droidspaces launcher |
|
||||
| `lfdevs_anland-termux` | `a70879f059a2e8439fdb132195c3dd10d4810106` | Legacy-derived Termux integration |
|
||||
| `E7G_wlroots-anland` | `351399132de0b208ddb36d0ea2fa74cbe668fb72` | Private-protocol wlroots backend |
|
||||
| `asveroid_anland-plasma-termux` | `099710d413b47d2f3f8c5091a95ee2732d3be0e6` | Termux Plasma installer |
|
||||
| `Yizhou147_anland-drm` | `850f7ca0e0f25d34dd04baa7e12e8751bcff4951` | Experimental DRM consumer |
|
||||
| `SuperTurtleDev_anland_legacy` | `9ab13eb146bc9f3dd3cc44cabc268659d9eb0a46` | 5.x comparison |
|
||||
|
||||
Main explicitly identifies itself as the 6.x rewrite and explains that 5.x used a private display protocol requiring compositor-specific backends. Do not apply Termux/5.x results automatically to waylandbridge 6.x. [anland/README.md:9–25](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/README.md#L9-L25>) [Termux/README.md:7–13](<https://github.com/lfdevs/anland-termux/blob/a70879f059a2e8439fdb132195c3dd10d4810106/README.md#L7-L13>)
|
||||
|
||||
## Decision in brief
|
||||
|
||||
**Inferred:** MobileGL can supply rendering to Anland, but successful GL command execution is only half the integration. Current 6.x needs either a `wl_shm` buffer or its narrow raw-dma-buf representation. It does **not** currently expose a native AHardwareBuffer producer import API. The best path for an Android render server is an added native-AHB buffer ingress that preserves the complete gralloc handle, with Wayland buffer lifetime and sync-file fences carried alongside it. The existing Android rendering side already imports AHBs as EGLImages and submits AHBs to SurfaceControl. [waylandbridge/awl_server.c:385–401](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_server.c#L385-L401>) [waylandbridge/awl_internal.h:65–81](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_internal.h#L65-L81>) [waylandbridge/awl_gl.cpp:257–289](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_gl.cpp#L257-L289>) [waylandbridge/awl_sc.cpp:727–743](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L727-L743>)
|
||||
|
||||
The highest-impact findings are:
|
||||
|
||||
- dma-buf is **v3, one plane, AR24/XR24**, with no device feedback. Native RGBA8888/DRM ABGR8888 is outside that format list. [waylandbridge/awl_dmabuf.c:17–22](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L17-L22>) [waylandbridge/awl_dmabuf.c:105–127](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L105-L127>) [waylandbridge/awl_dmabuf.c:212–237](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L212-L237>) [drm-uapi/drm_fourcc.h:193–199](https://github.com/lfdevs/mesa-for-android-container/blob/98f3d6229d61452cef80f8563af7c56ae599dc14/include/drm-uapi/drm_fourcc.h#L193-L199)
|
||||
- The actual local `DRM_FORMAT_MOD_INVALID` constant is **wrong relative to DRM UAPI**: `0x00ffffff00000000ULL`, versus UAPI `0x00ffffffffffffff`. Linear `0` is unambiguous. [waylandbridge/awl_internal.h:35–40](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_internal.h#L35-L40>) [drm-uapi/drm_fourcc.h:467–492](https://github.com/lfdevs/mesa-for-android-container/blob/98f3d6229d61452cef80f8563af7c56ae599dc14/include/drm-uapi/drm_fourcc.h#L467-L492) [drm-uapi/drm_fourcc.h:527–544](https://github.com/lfdevs/mesa-for-android-container/blob/98f3d6229d61452cef80f8563af7c56ae599dc14/include/drm-uapi/drm_fourcc.h#L527-L544)
|
||||
- Both dma-buf rendering modes depend on a **Qualcomm snapalloc-style donor forge**. A GPU-copy fallback for pitch or pacing still needs the forge to succeed; it is not a generic fallback for unknown gralloc layouts. [waylandbridge/awl_ahb.cpp:139–146](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L139-L146>) [waylandbridge/awl_ahb.cpp:325–340](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L325-L340>) [waylandbridge/awl_sc.cpp:903–935](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L903-L935>)
|
||||
- The “statically-linked ELF” description does not mean a fully static graphics stack: the target links Android `EGL`, `GLESv3`, `nativewindow`, `android`, and `binder_ndk`. [anland/README.md:73–78](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/README.md#L73-L78>) [waylandbridge/CMakeLists.txt:303–308](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/CMakeLists.txt#L303-L308>) [waylandbridge/CMakeLists.txt:364–365](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/CMakeLists.txt#L364-L365>)
|
||||
|
||||
## 1. Buffer ingress contract and the complete dma-buf path
|
||||
|
||||
### 1.1 What the Wayland endpoint advertises and accepts
|
||||
|
||||
| Item | Exact current behavior |
|
||||
|---|---|
|
||||
| Core compositor | `wl_compositor` **v4**. [waylandbridge/awl_surface.c:1110–1120](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L1110-L1120>) |
|
||||
| Shared memory | The pinned libwayland's `wl_display_init_shm()` creates `wl_shm` **v2** and supplies ARGB8888 and XRGB8888. Anland adds no extra formats in server initialization. In `wl_shm` these are **0 and 1**, not DRM fourcc values. [waylandbridge/awl_server.c:385–401](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_server.c#L385-L401>) [libwayland/wayland-shm.c:451–475](https://github.com/SuperTurtleDev/libwayland/blob/37032ecd5bf7657629b9d9725c084025497840d9/src/wayland-shm.c#L451-L475) [waylandbridge/awl_surface.c:1155–1160](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L1155-L1160>) |
|
||||
| dma-buf global | `zwp_linux_dmabuf_v1` **v3**, with client binds capped at 3. Only `destroy` and `create_params` are implemented on the factory. [waylandbridge/awl_dmabuf.c:212–237](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L212-L237>) |
|
||||
| dma-buf formats | `AWL_FORMAT_ARGB8888 = fourcc('A','R','2','4')` and `AWL_FORMAT_XRGB8888 = fourcc('X','R','2','4')`; little-endian memory is `[B,G,R,A]` or `[B,G,R,X]`. No AB24/XB24, RGB565, YUV or multi-plane video format. [waylandbridge/awl_internal.h:29–33](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_internal.h#L29-L33>) [waylandbridge/awl_dmabuf.c:17–22](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L17-L22>) [waylandbridge/awl_dmabuf.c:54–57](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L54-L57>) |
|
||||
| Advertised modifiers | Each format has entries named `DRM_FORMAT_MOD_INVALID` and `DRM_FORMAT_MOD_LINEAR`. The former is locally defined as **`0x00ffffff00000000ULL`**, the latter as **`0ULL`**. Bind sends `format` for every entry, so the two formats are each announced twice; modifier events are conditional on protocol version. [waylandbridge/awl_dmabuf.c:17–22](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L17-L22>) [waylandbridge/awl_dmabuf.c:217–229](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L217-L229>) [waylandbridge/awl_internal.h:35–40](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_internal.h#L35-L40>) |
|
||||
| Planes and offset | Only `plane_idx == 0`; other planes close the supplied fd and post `ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_IDX`. Repeated plane-0 `add` overwrites the previous fd. **Offset is ignored**, not validated or retained. [waylandbridge/awl_dmabuf.c:105–127](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L105-L127>) |
|
||||
| Feedback / device | No `get_default_feedback`, `get_surface_feedback`, feedback object, format-table/tranche events, or `main_device`/`dev_t` advertisement in this v3 implementation. This is absence of a device advertisement, not a zero-valued or fabricated `dev_t`. The Xwayland patch explicitly compensates for it. [waylandbridge/awl_dmabuf.c:212–237](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L212-L237>) [anland/patches/xwayland/README.anland.md:29–39](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/patches/xwayland/README.anland.md#L29-L39>) |
|
||||
|
||||
**Modifier mismatch:** DRM UAPI defines INVALID as `fourcc_mod_code(NONE, DRM_FORMAT_RESERVED)`, with `NONE=0` and `DRM_FORMAT_RESERVED=((1ULL<<56)-1)`. Thus the advertised nonzero value in Anland is not standard INVALID. **Inferred:** a client that compares exact modifier values can reject/misinterpret it. However, Anland's creation path itself does not reject an unadvertised modifier: it only passes the value into logging, then discards it from the persistent buffer wrapper. Therefore “only linear supported” is the intended usable layout, **not a correctly enforced request validator**. [drm-uapi/drm_fourcc.h:467–492](https://github.com/lfdevs/mesa-for-android-container/blob/98f3d6229d61452cef80f8563af7c56ae599dc14/include/drm-uapi/drm_fourcc.h#L467-L492) [drm-uapi/drm_fourcc.h:527–544](https://github.com/lfdevs/mesa-for-android-container/blob/98f3d6229d61452cef80f8563af7c56ae599dc14/include/drm-uapi/drm_fourcc.h#L527-L544) [waylandbridge/awl_internal.h:35–40](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_internal.h#L35-L40>) [waylandbridge/awl_dmabuf.c:49–85](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L49-L85>)
|
||||
|
||||
### 1.2 From `create` / `create_immed` to a displayed frame
|
||||
|
||||
1. **Protocol creation:** `params_add` records one fd, byte stride and modifier; `create`/`create_immed` require an fd and positive width/height. `dmabuf_buffer_create` rejects formats outside AR24/XR24, takes the fd, records its inode with `fstat`, and constructs a `wl_buffer`. There is no EGL/gralloc import at this stage. `create` sends `created` or `failed`; `create_immed` creates the requested object or posts `INVALID_WL_BUFFER`. Both ignore the `flags` argument. [waylandbridge/awl_dmabuf.c:49–85](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L49-L85>) [waylandbridge/awl_dmabuf.c:105–175](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L105-L175>)
|
||||
2. **Commit:** `awl_surface_apply_buffer` duplicates the dma-buf fd, takes the explicit acquire fence or snapshots implicit write completion with `awl_dmabuf_export_sync_file`, copies geometry/format into `struct awl_bq_buffer`, and references the `awl_buffer` through an `awl_bufref` release cookie. A full queue returns/drops the new frame immediately. Destroying the protocol buffer does not invalidate already queued frames, which hold their own fd and wrapper references. [waylandbridge/awl_surface.c:184–218](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L184-L218>) [waylandbridge/awl_dmabuf.c:33–46](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L33-L46>) [waylandbridge/awl_bufferqueue.h:63–76](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.h#L63-L76>)
|
||||
3. **Queue:** mailbox-like draining drops superseded heads only while the next element is ready, assuming FIFO completion. The retained head and consumer references determine lifetime; the last reference runs the release callback and closes its owned fds. Capacity is **8** elements, including the head. [waylandbridge/awl_bufferqueue.c:43–48](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.c#L43-L48>) [waylandbridge/awl_bufferqueue.c:201–210](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.c#L201-L210>) [waylandbridge/awl_bufferqueue.c:379–388](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.c#L379-L388>)
|
||||
4. **AHB resolution:** each layer has an eight-slot cache. Its key is **`(ino,width,height,stride)`**, not modifier or format. A miss calls `awl_ahb_wrap`; a hit reuses the registered AHB and, for GL, its EGLImage/texture payload. A failed forge leaves the cache unchanged for a later retry. [waylandbridge/awl_ahb.hpp:53–69](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.hpp#L53-L69>) [waylandbridge/awl_ahb.cpp:534–569](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L534-L569>)
|
||||
5. **EGL renderer:** ready dma-buf → forged AHB → `eglGetNativeClientBufferANDROID` → `eglCreateImageKHR(..., EGL_NATIVE_BUFFER_ANDROID, ...)` → `glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, ...)` → per-window GPU composition → `eglSwapBuffers`. A missing texture skips that layer; no direct `EGL_LINUX_DMA_BUF_EXT` fallback is attempted here. [waylandbridge/awl_renderer.cpp:292–323](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_renderer.cpp#L292-L323>) [waylandbridge/awl_gl.cpp:257–289](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_gl.cpp#L257-L289>) [waylandbridge/awl_renderer.cpp:382–419](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_renderer.cpp#L382-L419>)
|
||||
6. **SurfaceControl renderer:** `enum sc_mode { SC_MODE_NONE=0, SC_MODE_SCANOUT, SC_MODE_EGL, SC_MODE_EGL_SHM }`. `SCANOUT` submits the forged client AHB through `ASurfaceTransaction_setBuffer[WithRelease]`. `EGL` samples that forged AHB into a platform-allocated AHB for this layer. `EGL_SHM` uploads shared-memory pixels into a texture and blits into such a target. Every Wayland layer becomes a SurfaceControl sibling. **Inferred:** the name `SCANOUT` describes Anland's zero-copy submission; actual HWC-plane assignment remains SurfaceFlinger's decision. [waylandbridge/awl_sc.cpp:1–30](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L1-L30>) [waylandbridge/awl_sc.cpp:358–364](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L358-L364>) [waylandbridge/awl_sc.cpp:727–743](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L727-L743>) [waylandbridge/awl_sc.cpp:903–975](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L903-L975>)
|
||||
|
||||
### 1.3 What the forge actually does
|
||||
|
||||
The source describes a specific Qualcomm **snapalloc** layout: native handle **fd[0] = pixel dma-buf, fd[1] = metadata blob**, observed as about **28 KiB**. It explains that a container KGSL dma-buf lacks that descriptor and a bare `GB01+fd` import was rejected. `donor_blob_fd` explicitly refuses a donor unless `numFds == 2`. This is not a vendor-neutral construction of an AHB from any dma-buf. [waylandbridge/awl_ahb.cpp:5–28](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L5-L28>) [waylandbridge/awl_ahb.cpp:139–146](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L139-L146>)
|
||||
|
||||
Calibration allocates BGRA donors of **300×300** and **1134×567**, both with `AWL_AHB_DONOR_USAGE = AHARDWAREBUFFER_USAGE_GPU_SAMPLED_IMAGE`. It reads allocator-reported stride and pixel-allocation size, mmaps their metadata blobs, and locates geometry/size fields by comparing the two layouts. Blob sizes must agree and be positive; native-handle integer counts must agree and be at most **64**. It requires recognized stride-in-pixels, stride-in-bytes, height, allocation/exact size, extent and native-handle integer fields; failure reports **“vendor layout changed, refusing to forge.”** [waylandbridge/awl_ahb.hpp:19–23](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.hpp#L19-L23>) [waylandbridge/awl_ahb.cpp:172–220](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L172-L220>) [waylandbridge/awl_ahb.cpp:223–274](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L223-L274>)
|
||||
|
||||
`awl_ahb_wrap` serializes calibration/import with a mutex and hardcodes **`AWL_HAL_BGRA_8888 = 5`**. It reuses an existing matching-geometry AHB as donor, without modifying its live blob, or allocates a **4×4** donor. It patches the cold donor's blob and integer payload to client geometry, **`stride/4`** and **`stride*height`**. Both calibrated allocation-size and exact-size metadata fields are set to that product; this path does not query or validate the actual client dma-buf extent. [waylandbridge/awl_geom.h:42–51](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_geom.h#L42-L51>) [waylandbridge/awl_ahb.cpp:300–320](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L300-L320>) [waylandbridge/awl_ahb.cpp:325–395](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L325-L395>)
|
||||
|
||||
It then fabricates the Android `GraphicBuffer::flatten` representation: **13 int32 header words**, magic **`0x47423031` (`GB01`)**, width/height/stride/HAL format, layer count **1**, usage words, synthetic buffer id with **bit 63 set**, generation **0**, **two fds**, and the donor's integer count. A local `AF_UNIX/SOCK_STREAM` socketpair carries the flattened bytes plus `SCM_RIGHTS` containing **`dup(client_pixel_fd)` and `dup(donor_blob_fd)`**. `AHardwareBuffer_recvHandleFromUnixSocket` reconstructs/registers the AHB through Android/gralloc. That socketpair is entirely inside the daemon; it is **not** a client-facing native-AHB transport. [waylandbridge/awl_ahb.cpp:398–480](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L398-L480>)
|
||||
|
||||
### 1.4 Usable layout preconditions versus checks that are actually implemented
|
||||
|
||||
| Condition | What is checked / practical implication |
|
||||
|---|---|
|
||||
| Format | Protocol admits only AR24/XR24; forge always describes HAL BGRA8888. RGBA8888 is DRM **AB24**, so simply relabeling it AR24 swaps red/blue. [waylandbridge/awl_dmabuf.c:54–57](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L54-L57>) [waylandbridge/awl_ahb.cpp:334–336](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L334-L336>) [drm-uapi/drm_fourcc.h:193–199](https://github.com/lfdevs/mesa-for-android-container/blob/98f3d6229d61452cef80f8563af7c56ae599dc14/include/drm-uapi/drm_fourcc.h#L193-L199) |
|
||||
| Linear, zero-offset data | Offset is ignored and modifier is not kept in `awl_buffer` or the queue. **Inferred:** correct pixels require the simple packed layout described by the forge; arbitrary tiling/compression cannot be represented by supplying an fd alone. [waylandbridge/awl_dmabuf.c:105–127](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L105-L127>) [waylandbridge/awl_internal.h:71–81](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_internal.h#L71-L81>) [waylandbridge/awl_bufferqueue.h:63–76](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.h#L63-L76>) |
|
||||
| Dimensions / byte extent | Only `width>0,height>0` are validated at request time. There is no request-time `stride>=width*4`, overflow, actual-fd-size or maximum-texture-size check in this constructor. **Inferred:** the client must provide sufficiently large storage with sane geometry; protocol creation success does not establish import or sampling safety. [waylandbridge/awl_dmabuf.c:49–85](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L49-L85>) [waylandbridge/awl_dmabuf.c:130–175](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L130-L175>) [waylandbridge/awl_ahb.cpp:377–395](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L377-L395>) |
|
||||
| Byte stride | Forge converts with integer `stride/4`. Scanout rejects a stride not divisible by 4; that is not a universal ingress rejection. **Inferred:** valid packed-32-bit buffers should use a stride divisible by 4 and at least width×4. [waylandbridge/awl_ahb.cpp:87–91](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L87-L91>) [waylandbridge/awl_ahb.cpp:377–395](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L377-L395>) |
|
||||
| HWC-compatible stride | Let `p = stride/4`. `awl_ahb_hwc_scanout_ok` probes allocator stride for **width p**, height **64**, BGRA and donor usage. It accepts if the returned pitch equals p, or if the probe returns **0** (no verdict, keep HWC). It does not merely compare allocator stride at the buffer's logical width. [waylandbridge/awl_ahb.cpp:60–91](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L60-L91>) |
|
||||
| Non-fixed-point pitch | Forces a GPU blit into a platform allocation. The source documents pitch **1024 px → gralloc 1280 px** causing DRM `ADDFB2` failure/blank HWC output while GPU composition/screenshots looked correct. The forge must still succeed for that source texture. [waylandbridge/awl_sc.cpp:22–30](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L22-L30>) [waylandbridge/awl_sc.cpp:903–935](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L903-L935>) |
|
||||
| Unsupported donor layout | Wrong fd count, unrecognized metadata, mmap/allocation/import failure → `NULL`, log, blank/skipped or old retained layer. There is no generic CPU upload fallback in the audited main. [waylandbridge/awl_ahb.cpp:139–146](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L139-L146>) [waylandbridge/awl_ahb.cpp:264–274](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L264-L274>) [waylandbridge/awl_ahb.cpp:337–340](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L337-L340>) [waylandbridge/awl_renderer.cpp:295–323](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_renderer.cpp#L295-L323>) [waylandbridge/awl_sc.cpp:729–735](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L729-L735>) |
|
||||
|
||||
**Already-gralloc-allocated input:** extracting only its pixel fd and submitting it through linux-dmabuf still enters this forge; the original gralloc metadata and complete native handle never reach the renderer. There is no detection of “this came from gralloc, use its original handle.” **Inferred:** a genuinely linear BGRA allocation with compatible pitch might happen to work, but native allocation provenance alone is no guarantee. A compressed native allocation is especially unsuitable for this reconstruction. [waylandbridge/awl_internal.h:71–81](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_internal.h#L71-L81>) [waylandbridge/awl_ahb.cpp:422–464](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L422-L464>) [waylandbridge/awl_ahb.cpp:562–569](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L562-L569>)
|
||||
|
||||
**UBWC/compression:** neither supported modifier list names a Qualcomm compressed modifier; no modifier or compression metadata survives in the queue. The donor path assumes the sampled BGRA layout, but contains no general UBWC detection, decompressor, or universal vendor “disable compression” operation. **Inferred:** compression is excluded from the usable raw-dma-buf contract, although the request handler fails to enforce that exclusion. `DRM_FORMAT_MOD_INVALID` must not be treated as permission to send an opaque compressed AHB pixel fd. A later GPU copy does not solve this: first it must import/sample the source correctly. [waylandbridge/awl_dmabuf.c:17–22](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L17-L22>) [waylandbridge/awl_dmabuf.c:49–85](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L49-L85>) [waylandbridge/awl_bufferqueue.h:63–76](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.h#L63-L76>) [waylandbridge/awl_ahb.cpp:334–395](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L334-L395>) [waylandbridge/awl_sc.cpp:922–930](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L922-L930>)
|
||||
|
||||
**Native-handle ingress today:** none in the audited buffer factory/global list or Binder transaction table. Binder `T_CONNECT=18` transfers a Wayland **connection socket**; `T_SURFACE=1` transfers an Android **destination Surface**. Neither submits a producer AHardwareBuffer. The sole `recvHandleFromUnixSocket` in the frame-import path consumes the daemon's fabricated local wire message. [waylandbridge/awl_server.c:385–401](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_server.c#L385-L401>) [waylandbridge/waylandbridge.cpp:140–197](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L140-L197>) [libawl/AwlClient.java:80–95](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/app/libawl/src/main/java/com/anlandnext/awl/AwlClient.java#L80-L95>) [libawl/AwlClient.java:335–381](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/app/libawl/src/main/java/com/anlandnext/awl/AwlClient.java#L335-L381>) [waylandbridge/awl_ahb.cpp:444–464](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L444-L464>)
|
||||
|
||||
**External evidence, not merged behavior:** draft PR [#92](https://github.com/SuperTurtleDev/anland/pull/92), open and unmerged when retrieved, reports black Nautilus/Kitty/Chromium content on Snapdragon 870/Adreno 650 with `sc_enabled=0`; its sample is AR24 **2024×1344, stride 8192, modifier 0**, with nonzero CPU-mappable pixels but forge failure. The proposal adds synchronized mmap/CPU upload. It is not present in the audited main and is explicitly limited to linear packed data. [anland PR #92](https://github.com/SuperTurtleDev/anland/pull/92) [anland PR #92](https://github.com/SuperTurtleDev/anland/pull/92) [anland PR #92](https://github.com/SuperTurtleDev/anland/pull/92)
|
||||
|
||||
Android service access can also fail more severely than a returned import error: closed issue [#84](https://github.com/SuperTurtleDev/anland/issues/84) reports a 6.1.2 process abort inside `AHardwareBuffer_allocate`, with **“Failed to load matching allocator for mapper version 4”** and allocator/mapper service-discovery denials. Current policy contains the corresponding mapper/allocator `find` grants. This is historical device evidence, not a claim that the same defect remains unfixed in the audited revision. [anland issue #84](https://github.com/SuperTurtleDev/anland/issues/84) [anland/module/sepolicy.rule:159–161](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L159-L161>)
|
||||
|
||||
## 2. Synchronization and buffer release
|
||||
|
||||
### 2.1 Protocol and producer completion
|
||||
|
||||
The implemented protocol is **`zwp_linux_explicit_synchronization_v1` v2**, using per-commit Linux **sync_file fds**. `set_acquire_fence` validates with `SYNC_IOC_FILE_INFO`, rejects invalid fds and duplicate pending fences, and stores `pend_acquire_fd`. `get_release` creates a `zwp_linux_buffer_release_v1` object. Commit validation rejects acquire/release without an attached buffer; an acquire fence on `wl_shm` is `UNSUPPORTED_BUFFER`, although requesting a release object alone for shm is permitted. Sync-subsurface latching moves fence/release state with the buffer. [waylandbridge/awl_esync.c:1–26](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_esync.c#L1-L26>) [waylandbridge/awl_esync.c:121–170](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_esync.c#L121-L170>) [waylandbridge/awl_esync.c:179–200](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_esync.c#L179-L200>) [waylandbridge/awl_esync.c:265–277](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_esync.c#L265-L277>) [waylandbridge/awl_bufferqueue.c:175–179](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.c#L175-L179>)
|
||||
|
||||
No **linux-drm-syncobj** global is registered or implemented by waylandbridge. The XML comment saying the older explicit-sync protocol is superseded is not an implementation of its successor. In particular, the pinned Xwayland source has its own syncobj-related code; that does not mean the Anland compositor advertises it. [waylandbridge/awl_server.c:385–401](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_server.c#L385-L401>) [waylandbridge/CMakeLists.txt:309–349](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/CMakeLists.txt#L309-L349>) [waylandbridge/protocols/linux-explicit-synchronization-unstable-v1.xml:39](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/protocols/linux-explicit-synchronization-unstable-v1.xml#L39>) [xserver/hw/xwayland/xwayland-glamor-gbm.c:1788–1797](https://gitlab.freedesktop.org/xorg/xserver/-/blob/5a873951579f1ff894f71489f3651a55d6dde250/hw/xwayland/xwayland-glamor-gbm.c#L1788-1797)
|
||||
|
||||
| Consumer path | Acquire fence handling |
|
||||
|---|---|
|
||||
| Whole-window EGL renderer | Calls `awl_bufferqueue_gethead(q,100)`. This is a CPU `poll`; **100 ms is only a warning threshold**. On timeout it waits again with **`-1`**, i.e. indefinitely, before sampling. A real wait error logs and can return the head anyway. Header descriptions calling the wait “bounded” are incomplete compared with this body. [waylandbridge/awl_renderer.cpp:276–279](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_renderer.cpp#L276-L279>) [waylandbridge/awl_bufferqueue.c:121–137](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.c#L121-L137>) [waylandbridge/awl_bufferqueue.c:395–417](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.c#L395-L417>) |
|
||||
| SC scanout / SC source selection | `tryhead` never waits; an unsignaled frame retains the previous buffer/geometry. The render-thread looper watches completion and triggers another pass. When scanout submits the buffer, its original acquire fence is already signaled, so `setBuffer` receives **`-1`**, not the client fence. [waylandbridge/awl_bufferqueue.c:420–425](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.c#L420-L425>) [waylandbridge/awl_sc.cpp:472–501](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L472-L501>) [waylandbridge/awl_sc.cpp:727–740](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L727-L740>) [waylandbridge/awl_sc.cpp:847–860](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L847-L860>) |
|
||||
| SC GPU-copy destination | The daemon exports the blit's native fence and passes that fence to SF as the destination AHB's acquire fence. Reusing a target waits on SF's prior release fence via `eglWaitSyncKHR` where available; fallback is CPU wait. These are the daemon-owned target's fences, distinct from the client-source fence. [waylandbridge/awl_sc.cpp:752–796](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L752-L796>) [waylandbridge/awl_gl.cpp:399–411](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_gl.cpp#L399-L411>) |
|
||||
|
||||
Poll treats error/hangup/invalid-fd events as completion to avoid permanent stalls; `SYNC_IOC_FILE_INFO` validates the explicit fence type but does not make these error paths successful rendering. **Inferred:** MobileGL should send valid, signaled-on-completion sync_files and propagate rendering failure separately rather than rely on error-event behavior. [waylandbridge/awl_bufferqueue.c:111–137](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.c#L111-L137>) [waylandbridge/awl_bufferqueue.c:175–192](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.c#L175-L192>)
|
||||
|
||||
### 2.2 Release fences and `wl_buffer.release`
|
||||
|
||||
The common rule is **last queue/consumer reference → `bq_release_cb`**. If the commit has an explicit release object, it gets `fenced_release(release_fd)` or `immediate_release` when no fence exists. Otherwise the daemon tries to import its read-completion fence into the dma-buf reservation with `DMA_BUF_IOCTL_IMPORT_SYNC_FILE`, `DMA_BUF_SYNC_READ`. A live `wl_buffer` then gets **`wl_buffer.release` in both cases**, even with explicit sync. `release` therefore need not mean the fence has already signaled. [waylandbridge/awl_bufferqueue.c:201–210](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.c#L201-L210>) [waylandbridge/awl_surface.c:84–108](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L84-L108>) [waylandbridge/awl_esync.c:66–78](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_esync.c#L66-L78>)
|
||||
|
||||
| Mode | When the consumer reference is returned |
|
||||
|---|---|
|
||||
| EGL whole-window | After draw submission, with a native GPU-read fence; `glFinish()` if native-fence creation fails. `put` happens **before** the vsync-blocking `eglSwapBuffers`. The ring may still retain its current head, so this is not an unconditional immediate protocol release of the newest buffer. [waylandbridge/awl_renderer.cpp:382–405](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_renderer.cpp#L382-L405>) [waylandbridge/awl_bufferqueue.c:379–388](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.c#L379-L388>) |
|
||||
| SC `SCANOUT` | Held while SF uses it. API **36+**, if the symbol is available: `setBufferWithRelease` → per-buffer callback → `put(element,release_fence)`. Older **29–35** strategy: transaction `OnComplete` reports the **previous** buffer's release fence after replacement. [waylandbridge/awl_sc.cpp:86–97](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L86-L97>) [waylandbridge/awl_sc.cpp:329–353](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L329-L353>) |
|
||||
| SC `EGL` | Client source is put with the blit's fence after copying; SF keeps a reference to Anland's separate pool slot instead. Again the ring head may defer actual protocol release. [waylandbridge/awl_sc.cpp:94–97](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L94-L97>) [waylandbridge/awl_sc.cpp:922–935](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L922-L935>) |
|
||||
| shm, either renderer | Logic stores the latest shm source; backend uploads the damaged pixels. `awl_surface_shm_end(consumed=1)` sends source `wl_buffer.release` and immediate explicit release after the CPU source has been read. Failed uploads leave the source pending. [anland/include/awl.h:325–342](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/include/awl.h#L325-L342>) [waylandbridge/awl_surface.c:1201–1209](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L1201-L1209>) |
|
||||
|
||||
Without explicit sync, commit snapshots existing writer fences using `DMA_BUF_IOCTL_EXPORT_SYNC_FILE` with `DMA_BUF_SYNC_READ`; `ENOTTY` or `EINVAL` disables future export attempts and readiness falls back to polling the dma-buf itself for `POLLIN`. This assumes the producer driver records completion in the dma-buf reservation. The release-side import return value is ignored by `bq_release_cb`, so there is no implemented CPU-wait fallback if that ioctl is unsupported. **Inferred:** a split MobileGL producer should prefer explicit acquire **and** release synchronization; CPU-complete submission is a slower safe producer fallback, but reuse must still honor the consumer's release fence. [waylandbridge/awl_surface.c:199–209](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L199-L209>) [waylandbridge/awl_bufferqueue.c:140–159](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.c#L140-L159>) [waylandbridge/awl_bufferqueue.c:184–192](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.c#L184-L192>) [waylandbridge/awl_surface.c:90–102](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L90-L102>)
|
||||
|
||||
## 3. Presentation, pacing, buffering, scaling and subsurfaces
|
||||
|
||||
`wl_surface.frame` creates callbacks on the surface's list. `awl_surface_presented()` sends each outstanding callback `done(awl_now_ms())`; `awl_now_ms` derives from **CLOCK_MONOTONIC** and wraps into a 32-bit millisecond value. It does not deliver a hardware presentation timestamp. No `wp_presentation` global or presentation-time implementation appears in server setup/build registration. **Inferred:** frame callbacks are pacing opportunities here, not evidence that a particular frame physically scanned out. [waylandbridge/awl_surface.c:825–859](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L825-L859>) [waylandbridge/awl_surface.c:1221–1238](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L1221-L1238>) [waylandbridge/awl_internal.h:43–46](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_internal.h#L43-L46>) [waylandbridge/awl_server.c:385–401](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_server.c#L385-L401>) [waylandbridge/CMakeLists.txt:309–349](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/CMakeLists.txt#L309-L349>)
|
||||
|
||||
EGL uses **one render thread per window**, `eglSwapInterval(...,1)`, and sends callbacks for the layers drawn after `eglSwapBuffers` returns. SC has a shared Choreographer render loop: callbacks go out on the **vsync tick** for visible layers that have a buffer; commits can trigger one off-tick latch opportunity per window/interval, and fence completion can retry it. Off-tick passes do not send frame callbacks. The comments document that sending callbacks from SF `OnComplete` introduced an extra vsync and reduced a paced client to **29 fps**. [waylandbridge/awl_renderer.cpp:417–439](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_renderer.cpp#L417-L439>) [waylandbridge/awl_sc.cpp:46–75](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L46-L75>) [waylandbridge/awl_sc.cpp:431–440](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L431-L440>) [waylandbridge/awl_sc.cpp:982–984](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L982-L984>) [waylandbridge/awl_sc.cpp:1105–1145](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L1105-L1145>)
|
||||
|
||||
**How many buffers:** there is no protocol requirement to use exactly two or three. The queue holds **8** and the AHB cache holds **8**. SC's own copy-target pool is **4** because three slots skipped alternate frames in the documented SF pipeline. SC comments describe up to three client buffers held by SF plus the newest queue head as a fourth, and Mesa mailbox commonly having four. **Inferred recommendation:** start a dma-buf/AHB swapchain with **four reusable buffers**, pace normal GUI rendering by callbacks, and handle release/fence backpressure; allow more buffers if device testing requires them. A one-buffer renderer cannot assume the current head will be released without replacement. Do not interpret an eight-slot queue as eight-buffer minimum. [waylandbridge/awl_bufferqueue.c:43–48](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.c#L43-L48>) [waylandbridge/awl_ahb.hpp:53–63](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.hpp#L53-L63>) [waylandbridge/awl_sc.cpp:224–235](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L224-L235>) [waylandbridge/awl_sc.cpp:389–400](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L389-L400>) [waylandbridge/awl_bufferqueue.c:379–388](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.c#L379-L388>)
|
||||
|
||||
A client repeatedly running ahead of vsync switches from SC scanout to GPU-copy mode after **15** consecutive ticks with dropped/superseded frames, and returns after **120** quiet ticks. The comments call these roughly ¼ s / 2 s, but the code thresholds are ticks, so their duration depends on refresh rate. The stated experiment is **vkmark 123 fps scanned out versus ~1300 fps copying**; those are source-comment measurements of producer throughput, not 1300 screen refreshes or a portable benchmark result. [waylandbridge/awl_sc.cpp:389–400](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L389-L400>) [waylandbridge/awl_sc.cpp:871–884](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L871-L884>)
|
||||
|
||||
**Parking:** detaching/pausing an Android host window marks it unattached and tears down its renderer/SC tree. New dirty notifications become no-ops and do not send `frame_done`. Commit-time queue draining is disabled for detached roots, intentionally withholding buffers so ordinary clients park on swap/release/callback waits. Cursor queues are an explicit exception and still drain. **Inferred:** this is cooperative backpressure, not SIGSTOP or a guarantee that an app ignoring callbacks and continually allocating new buffers uses zero CPU; queue-full frames are returned immediately. [waylandbridge/waylandbridge.cpp:328–333](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L328-L333>) [waylandbridge/waylandbridge.cpp:1118–1122](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L1118-L1122>) [waylandbridge/awl_surface.c:231–249](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L231-L249>) [waylandbridge/awl_surface.c:211–215](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L211-L215>)
|
||||
|
||||
**Scaling:** actual globals are **`wp_viewporter` v1** and **`wp_fractional_scale_manager_v1` v1** (some comments inaccurately use a `zwp_` prefix). Source/destination state is double buffered; output scale stays 1; preferred scale is quantized in **1/120** units as `(zoom_pct*120+50)/100`, sent on object creation and on zoom changes. Viewport destination determines logical size when set. MobileGL WSI must distinguish surface logical size from pixel-buffer dimensions. The last sentence is **inferred** from these transformations. [waylandbridge/awl_viewport.c:1–17](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_viewport.c#L1-L17>) [waylandbridge/awl_viewport.c:53–63](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_viewport.c#L53-L63>) [waylandbridge/awl_viewport.c:352–369](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_viewport.c#L352-L369>) [waylandbridge/awl_viewport.c:416–456](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_viewport.c#L416-L456>)
|
||||
|
||||
**Subsurfaces:** `wl_subcompositor` v1 supports synchronized and desynchronized children, parent-applied position/stacking, ancestor-recursive effective sync, and cascade application of latched state. Each child has its own buffer queue; SC maps layers to siblings, EGL composites the traversal. The public collection limit is **`AWL_MAX_LAYERS=16`**; the renderer separately includes a cursor slot. **Inferred:** whole-desktop nested compositors and clients with many layers should be tested against this finite layer collection, and a MobileGL integration must preserve per-surface rather than only per-window buffer/fence state. [waylandbridge/awl_subsurface.c:10–35](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_subsurface.c#L10-L35>) [waylandbridge/awl_subsurface.c:396–417](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_subsurface.c#L396-L417>) [waylandbridge/awl_subsurface.c:494–506](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_subsurface.c#L494-L506>) [anland/include/awl.h:369–388](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/include/awl.h#L369-L388>) [waylandbridge/awl_renderer.cpp:284–288](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_renderer.cpp#L284-L288>)
|
||||
|
||||
## 4. Connection and process model, including another Android daemon
|
||||
|
||||
### 4.1 Container connection and identities
|
||||
|
||||
The actual default is **`/data/local/tmp/awl/wayland-0`**. Config keys `runtime_dir` and `socket_listen` choose another directory or disable the pathname listener. `socket_listen` defaults true; the daemon makes the runtime directory mode **0777**, binds an `AF_UNIX/SOCK_STREAM` listener with backlog **8**, and chmods the socket **0666**. This contradicts the README table's blanket “No socket file” statement; that statement describes Binder-only operation, not the default code path. [waylandbridge/waylandbridge.cpp:1175–1199](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L1175-L1199>) [waylandbridge/waylandbridge.cpp:2085–2105](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L2085-L2105>) [waylandbridge/waylandbridge.cpp:2126–2143](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L2126-L2143>) [anland/README.md:31–38](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/README.md#L31-L38>)
|
||||
|
||||
Droidspaces is expected to bind **`/data/local/tmp/awl:/run/anland`** into the container. This checkout documents/assumes that preconfiguration; `anland-session/setup.sh` does not create the Android/container bind mount. Setup runs as the non-root desktop user and installs the user service and patched Xwayland. The session sets `XDG_RUNTIME_DIR=/run/user/$(id -u)` if absent, links **`$XDG_RUNTIME_DIR/wayland-anland` → `/run/anland/wayland-0`**, and exports **`WAYLAND_DISPLAY=wayland-anland`**. It launches rootless Xwayland, obtains the display number with `-displayfd`, runs miniwm, and publishes environment through `~/.anlandx-env` and `systemctl --user set-environment`. [shell/src/main/java/com/anland/shell/ds/DsCli.java:31–44](<https://github.com/SuperTurtleDev/anland-shell/blob/920fcfc8159690f5232e2d9c7c3294d4c1481145/src/main/java/com/anland/shell/ds/DsCli.java#L31-L44>) [anland/anland-session/setup.sh:1–13](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/anland-session/setup.sh#L1-L13>) [anland/anland-session/setup.sh:61–64](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/anland-session/setup.sh#L61-L64>) [anland/anland-session/anland-session.sh:26–45](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/anland-session/anland-session.sh#L26-L45>) [anland/anland-session/anland-session.sh:108–120](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/anland-session/anland-session.sh#L108-L120>) [anland/anland-session/anland-session.sh:146–184](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/anland-session/anland-session.sh#L146-L184>)
|
||||
|
||||
`service.sh` is the module's late-start service: it labels `waylandbridge` **`u:object_r:awl_daemon_exec:s0`** and starts it directly with `nohup`. Policy transitions **`ksu + awl_daemon_exec → awl_daemon`**, and explicitly marks **`awl_daemon` permissive**. There is no UID drop in this launch/main path. **Inferred:** in the intended root-manager launch, the daemon remains **UID 0**, SELinux domain **`u:r:awl_daemon:s0`**; the executable label is a different SELinux object type. Do not generalize this to launches through an unconfigured root manager/domain. [anland/module/service.sh:1–26](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/service.sh#L1-L26>) [anland/module/sepolicy.rule:14–26](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L14-L26>) [waylandbridge/waylandbridge.cpp:2110–2124](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L2110-L2124>)
|
||||
|
||||
Container apps run as the selected **Linux desktop account**, not a universal fixed UID: anland-shell defaults to the first non-root account, probes passwd for the UID, then uses `su - <user>` and `systemd-run --user`; explicit root launches use a different direct path. Anland's policy comments identify container Chrome as **`droidspacesd`**, and rules grant that domain socket/fd access. **Inferred:** this is the expected Android SELinux domain for the documented Droidspaces deployment; exact host UID mapping and domain for another chroot/PRoot/LXC setup must be measured because Droidspaces implementation/user-namespace configuration is not included here. [shell/src/main/java/com/anland/shell/ds/DsCli.java:318–339](<https://github.com/SuperTurtleDev/anland-shell/blob/920fcfc8159690f5232e2d9c7c3294d4c1481145/src/main/java/com/anland/shell/ds/DsCli.java#L318-L339>) [shell/src/main/java/com/anland/shell/ds/DsCli.java:374–392](<https://github.com/SuperTurtleDev/anland-shell/blob/920fcfc8159690f5232e2d9c7c3294d4c1481145/src/main/java/com/anland/shell/ds/DsCli.java#L374-L392>) [shell/src/main/java/com/anland/shell/ds/DsCli.java:435–458](<https://github.com/SuperTurtleDev/anland-shell/blob/920fcfc8159690f5232e2d9c7c3294d4c1481145/src/main/java/com/anland/shell/ds/DsCli.java#L435-L458>) [anland/module/sepolicy.rule:76–87](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L76-L87>) [anland/module/sepolicy.rule:142–154](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L142-L154>)
|
||||
|
||||
The Binder name is **`anland.host`**, interface **`anland.IHost`**, service label **`u:object_r:anland_host_service:s0`**. `customize.sh` copies the device's live platform service contexts and appends the supplied mapping. Third-party app domains `untrusted_app_29` and `untrusted_app` are allowed to find the service. Socket pathname access is deliberately narrower: `awl_runtime_sock` is created by a type transition and container `droidspacesd` gets socket-file access and `connectto`; APKs are intended to use Binder connection injection. World-writable DAC permissions alone are insufficient. [anland/module/plat_service_contexts.anland:1](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/plat_service_contexts.anland#L1>) [anland/module/customize.sh:13–26](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/customize.sh#L13-L26>) [anland/module/sepolicy.rule:4–7](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L4-L7>) [anland/module/sepolicy.rule:76–92](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L76-L92>) [waylandbridge/waylandbridge.cpp:2153–2177](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L2153-L2177>)
|
||||
|
||||
### 4.2 Binder fd injection and libawl
|
||||
|
||||
`Awl.getWaylandFd()` delegates to `AwlClient.connect()`, which creates **the socketpair in the app**, sends one end through Binder **`T_CONNECT=18`**, closes its local duplicate of the sent end, and keeps the other for `wl_display_connect_to_fd`. Creating the pair in the app preserves its `SO_PEERCRED` UID/PID for ownership checks. The exact Java parcel body is **`writeInt(1); writeInt(0); writeFileDescriptor(theirs)`**, after the interface token. Use that implementation as the authority: nearby daemon comments/log text contain inconsistent abbreviated descriptions of the ParcelFileDescriptor wire. [libawl/Awl.java:69–78](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/app/libawl/src/main/java/com/anlandnext/awl/Awl.java#L69-L78>) [libawl/AwlClient.java:335–381](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/app/libawl/src/main/java/com/anlandnext/awl/AwlClient.java#L335-L381>) [anland/include/awl.h:140–150](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/include/awl.h#L140-L150>) [waylandbridge/waylandbridge.cpp:1820–1847](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L1820-L1847>)
|
||||
|
||||
The Binder handler passes the fd to `awl_server_add_client`; a pipe marshals the integer fd to the Wayland event thread, which calls `wl_client_create`. Binder is used to establish the connection; subsequent Wayland messages and buffer/fence fd passing use that socket. [waylandbridge/awl_server.c:308–347](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_server.c#L308-L347>) [waylandbridge/waylandbridge.cpp:1837–1847](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L1837-L1847>)
|
||||
|
||||
`Awl.java` exposes connection, window listing/events, `attachWindow`, and native client spawning. `spawnClient` inherits the connection as **`WAYLAND_SOCKET=<fd>`** through fork/exec. `attachWindow` hosts a Wayland window in an Activity; `AwlClient.surface` sends window id, dimensions, Android `Surface`, death token and host identity through **`T_SURFACE=1`**. The daemon compares the Binder caller UID with the Wayland client's UID for non-allowlisted hosts; root/self/host APK have privileged scope. [libawl/Awl.java:25–41](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/app/libawl/src/main/java/com/anlandnext/awl/Awl.java#L25-L41>) [libawl/Awl.java:188–227](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/app/libawl/src/main/java/com/anlandnext/awl/Awl.java#L188-L227>) [libawl/Awl.java:279–294](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/app/libawl/src/main/java/com/anlandnext/awl/Awl.java#L279-L294>) [libawl/AwlClient.java:28–40](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/app/libawl/src/main/java/com/anlandnext/awl/AwlClient.java#L28-L40>) [libawl/AwlClient.java:80–95](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/app/libawl/src/main/java/com/anlandnext/awl/AwlClient.java#L80-L95>) [waylandbridge/waylandbridge.cpp:1528–1567](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L1528-L1567>)
|
||||
|
||||
`include/awl.h` is the daemon's **logic-layer C API**, despite its header comment saying v2 while **`AWL_ABI_VERSION=3`**. It provides `awl_server_start/add_client`, window callbacks, per-surface queue access and shm access. It is not an Android client AHB-submission library; the Android AAR and this server-internal API serve different roles. [anland/include/awl.h:1–25](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/include/awl.h#L1-L25>) [anland/include/awl.h:132–150](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/include/awl.h#L132-L150>) [anland/include/awl.h:309–342](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/include/awl.h#L309-L342>)
|
||||
|
||||
**Could an Android GL server use libawl? — inferred:** yes, as a Wayland client/host under its own identity, or by implementing the same Binder connection protocol natively. It still needs Wayland WSI and one of Anland's accepted buffer types. An unprivileged server APK cannot use `attachWindow` to claim arbitrary existing container-UID windows. For split rendering while the Linux application owns the Wayland connection, keep that ownership and associate imported buffers with that client's resources through a new controlled native-buffer import/broker interface. `libawl` alone does not create this association. [libawl/Awl.java:69–81](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/app/libawl/src/main/java/com/anlandnext/awl/Awl.java#L69-L81>) [libawl/Awl.java:279–294](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/app/libawl/src/main/java/com/anlandnext/awl/Awl.java#L279-L294>) [waylandbridge/waylandbridge.cpp:1528–1567](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L1528-L1567>) [waylandbridge/awl_internal.h:71–81](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_internal.h#L71-L81>)
|
||||
|
||||
### 4.3 Launching a second Android-side daemon and required access
|
||||
|
||||
**Inferred: feasible using the same deployment pattern.** A bionic MobileGL render-server ELF can be launched by a root-module service and expose, for example, **`/data/local/tmp/awl/mobilegl.sock`**, seen as **`/run/anland/mobilegl.sock`** in the existing bind mount. Anland already demonstrates a second Android native service: PulseAudio is launched from the same module, in `awl_daemon` but under the host APK UID because Android audio policy requires a package-associated UID. That audio-specific UID rule is not evidence that GLES requires an APK UID. [anland/module/service.sh:29–42](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/service.sh#L29-L42>) [anland/module/service.sh:119–138](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/service.sh#L119-L138>) [anland/module/service.sh:153–170](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/service.sh#L153-L170>) [shell/src/main/java/com/anland/shell/ds/DsCli.java:31–35](<https://github.com/SuperTurtleDev/anland-shell/blob/920fcfc8159690f5232e2d9c7c3294d4c1481145/src/main/java/com/anland/shell/ds/DsCli.java#L31-L35>)
|
||||
|
||||
The following are **inferred policy requirements**, mapped to working Anland rules rather than claimed as a tested complete policy for every vendor:
|
||||
|
||||
| Direction / resource | Existing evidence and implication for MobileGL |
|
||||
|---|---|
|
||||
| Container connects to render server | Need runtime-directory traversal, socket-file read/write/open permissions, and `droidspacesd → mobilegl_daemon:unix_stream_socket connectto`; mirror the existing runtime socket labeling/allow rules. Reusing `awl_daemon` and its runtime socket type is the smallest deployment experiment; a separate domain/type is the maintainable change. [anland/module/sepolicy.rule:76–102](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L76-L102>) |
|
||||
| Cross-domain fd passing | Grant **both relevant directions of `fd use`**, e.g. `mobilegl_daemon ↔ droidspacesd` and `mobilegl_daemon ↔ awl_daemon`, plus communication and underlying file/device access. Anland has explicit `droidspacesd ↔ awl_daemon` grants. Shared memory/dma-buf/fence access is more than pathname connectivity. [anland/module/sepolicy.rule:142–146](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L142-L146>) [anland/module/sepolicy.rule:111–120](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L111-L120>) |
|
||||
| APK-based GL server | Anland's grants for `untrusted_app[_29] ↔ awl_daemon` do not automatically authorize `untrusted_app ↔ droidspacesd`. Either add appropriate direct socket/fd permissions for the new relation, or use a trusted Android broker to pass a socketpair through Binder. Binder service labeling/find, `call transfer`, `fd use`, and socket read/write rights are separate requirements. [anland/module/sepolicy.rule:4–7](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L4-L7>) [anland/module/sepolicy.rule:39–51](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L39-L51>) [anland/module/sepolicy.rule:76–87](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L76-L87>) |
|
||||
| Native server's Android graphics access | Mirror GPU node, dma-buf heap, vendor library, allocator/mapper service access; root DAC does not replace SELinux/service-manager policy. The audited domain is permissive, so its allow list is not proof of completeness in enforcing mode. [anland/module/sepolicy.rule:18](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L18>) [anland/module/sepolicy.rule:111–125](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L111-L125>) [anland/module/sepolicy.rule:159–161](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L159-L161>) |
|
||||
| Imported native buffers reach SF/HWC | Consumers may need `fd use` for the domain that originally opened/allocated the fd, not merely the relay daemon. Existing rules explicitly grant `surfaceflinger`, `system_server`, and `hal_graphics_composer_default` access to `awl_daemon` fds. For a new allocation domain, audit/add that new origin's grants too. [anland/module/sepolicy.rule:126–141](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L126-L141>) |
|
||||
|
||||
**Inferred transport limit:** local Unix fd passing is a natural fit. TCP cannot transmit a kernel fd/AHB handle as a usable remote kernel object; TCP rendering needs a local allocation broker and pixel/data transfer, or another explicitly implemented transport, before the final local Wayland buffer submission. Anland's relevant existing paths all use local fd passing or local shm, not TCP buffer ingress. [waylandbridge/waylandbridge.cpp:2085–2105](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L2085-L2105>) [libawl/AwlClient.java:342–365](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/app/libawl/src/main/java/com/anlandnext/awl/AwlClient.java#L342-L365>) [waylandbridge/awl_ahb.cpp:444–464](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L444-L464>) [waylandbridge/awl_bufferqueue.h:63–76](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.h#L63-L76>)
|
||||
|
||||
## 5. GPU acceleration supplied today and Xwayland requirements
|
||||
|
||||
### 5.1 What each project actually configures
|
||||
|
||||
| Project / environment | Observed rendering stack |
|
||||
|---|---|
|
||||
| Main 6.x container session | Defaults **`MESA_LOADER_DRIVER_OVERRIDE=kgsl`**, **`GALLIUM_DRIVER=kgsl`**, **`FD_FORCE_KGSL=1`**. Dependency setup installs an external lfdevs Mesa tarball containing EGL/GLX/GBM/Gallium/`kgsl_dri.so` and Turnip Vulkan. These are container-side Mesa drivers; waylandbridge's Android EGL is separate. [anland/anland-session/anland-session.sh:108–112](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/anland-session/anland-session.sh#L108-L112>) [anland/anland-session/deps_noble.sh:104–113](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/anland-session/deps_noble.sh#L104-L113>) [anland/anland-session/deps_noble.sh:130–141](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/anland-session/deps_noble.sh#L130-L141>) |
|
||||
| anland-shell | Root/Droidspaces app launcher, not a renderer. It supplies the same KGSL defaults and starts the selected user's app in the container session. [shell/src/main/java/com/anland/shell/ds/DsCli.java:31–44](<https://github.com/SuperTurtleDev/anland-shell/blob/920fcfc8159690f5232e2d9c7c3294d4c1481145/src/main/java/com/anland/shell/ds/DsCli.java#L31-L44>) [shell/src/main/java/com/anland/shell/ds/DsCli.java:59–68](<https://github.com/SuperTurtleDev/anland-shell/blob/920fcfc8159690f5232e2d9c7c3294d4c1481145/src/main/java/com/anland/shell/ds/DsCli.java#L59-L68>) [shell/src/main/java/com/anland/shell/ds/DsCli.java:374–382](<https://github.com/SuperTurtleDev/anland-shell/blob/920fcfc8159690f5232e2d9c7c3294d4c1481145/src/main/java/com/anland/shell/ds/DsCli.java#L374-L382>) |
|
||||
| lfdevs Anland: Termux | Explicitly legacy-based; supports Termux native and PRoot/Chroot/LXC. Qualcomm acceleration uses **Freedreno OpenGL and Turnip Vulkan**. Native installation guide currently points to **26.3.0-devel-20260824**, except Weston to **26.2.0-devel-20260709-weston**; container guide points to mesa-for-android-container. Image package URLs pin the 26.3 snapshot. [Termux/README.md:7–13](<https://github.com/lfdevs/anland-termux/blob/a70879f059a2e8439fdb132195c3dd10d4810106/README.md#L7-L13>) [Termux/docs/user-guide.md:148–152](<https://github.com/lfdevs/anland-termux/blob/a70879f059a2e8439fdb132195c3dd10d4810106/docs/user-guide.md#L148-L152>) [Termux/images/packages.json:1–16](<https://github.com/lfdevs/anland-termux/blob/a70879f059a2e8439fdb132195c3dd10d4810106/images/packages.json#L1-L16>) |
|
||||
| Termux Mesa build at that release tag | Package version **26.3.0**, Mesa commit **`98f3d6229d61452cef80f8563af7c56ae599dc14`**. `-Dgbm=enabled -Dopengl=true -Degl=enabled -Dgles2=enabled -Dglx=dri -Dllvm=enabled -Dplatforms=x11,wayland -Dglvnd=enabled`; Gallium **llvmpipe,softpipe,virgl,zink**, plus **freedreno** on ARM/aarch64; Vulkan **swrast**, plus **freedreno**; **`-Dfreedreno-kmds=msm,kgsl`**. [termux-packages/mesa/build.sh:6–35](https://github.com/lfdevs/termux-packages/blob/ccc9cc550efc604188242285f99884183596ebb0/packages/mesa/build.sh#L6-L35) [termux-packages/mesa/build.sh:177–185](https://github.com/lfdevs/termux-packages/blob/ccc9cc550efc604188242285f99884183596ebb0/packages/mesa/build.sh#L177-L185) |
|
||||
| Container Mesa workflow at the same Mesa commit | `-Dplatforms=x11,wayland`, Gallium **freedreno,zink,virgl,llvmpipe**, Vulkan **freedreno**, EGL/GLES2/GLVND enabled, GLX DRI, **`-Dfreedreno-kmds=kgsl`**. These are build settings in the release-tag tree, not proof every installed package/device selects every built driver. [mesa-for-android-container/build-check.yml:57–81](https://github.com/lfdevs/mesa-for-android-container/blob/98f3d6229d61452cef80f8563af7c56ae599dc14/.github/workflows/build-check.yml#L57-L81) |
|
||||
| asveroid Plasma installer | Explicitly **Termux Native**, no root, Snapdragon/Adreno. Installs patched KWin/Xwayland and Freedreno; script still pins **26.2.0-devel-20260709** Mesa and `mesa-vulkan-icd-freedreno`, older than lfdevs' current guide. [Plasma/README.md:3–23](<https://github.com/asveroid/anland-plasma-termux/blob/099710d413b47d2f3f8c5091a95ee2732d3be0e6/README.md#L3-L23>) [Plasma/install-anland-plasma.sh:26–31](<https://github.com/asveroid/anland-plasma-termux/blob/099710d413b47d2f3f8c5091a95ee2732d3be0e6/install-anland-plasma.sh#L26-L31>) |
|
||||
|
||||
**Zink:** it is built in both Mesa configurations above, but neither main 6.x's defaults nor Termux's documented KGSL overrides establish it as the default path. Termux's manual examples use `GALLIUM_DRIVER=freedreno`, `TURNIP_KMD=kgsl`, `FD_FORCE_KGSL=1` and `XWAYLAND_FORCE_KGSL_SURFACELESS=1`; the native example also uses `ANLAND_NO_DRM_DEVICE=1 EGL_PLATFORM=surfaceless`. Do not conflate this legacy Termux surfaceless integration with the four-hunk main 6.x Xwayland patch. [termux-packages/mesa/build.sh:177–185](https://github.com/lfdevs/termux-packages/blob/ccc9cc550efc604188242285f99884183596ebb0/packages/mesa/build.sh#L177-L185) [mesa-for-android-container/build-check.yml:65–80](https://github.com/lfdevs/mesa-for-android-container/blob/98f3d6229d61452cef80f8563af7c56ae599dc14/.github/workflows/build-check.yml#L65-L80) [Termux/docs/user-guide.md:251–262](<https://github.com/lfdevs/anland-termux/blob/a70879f059a2e8439fdb132195c3dd10d4810106/docs/user-guide.md#L251-L262>) [Termux/docs/user-guide.md:294–300](<https://github.com/lfdevs/anland-termux/blob/a70879f059a2e8439fdb132195c3dd10d4810106/docs/user-guide.md#L294-L300>) [anland/patches/xwayland/anland-kgsl-glamor.patch:1–109](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/patches/xwayland/anland-kgsl-glamor.patch#L1-L109>)
|
||||
|
||||
**Native vs containers:** Termux-native uses Android/Termux packages; container images install distro-appropriate Mesa into `/usr`. PRoot-Distro examples use `--shared-tmp`; the general guide bind-mounts Termux `$TMPDIR` to container `/tmp`, so the legacy daemon socket is shared. Official GitHub Termux APK variants use shared UID; the compatible variant instead holds the socket in Termux and transfers its fd over Binder. These are legacy transport arrangements, not the 6.x `/run/anland/wayland-0` setup. [Termux/README.md:31–34](<https://github.com/lfdevs/anland-termux/blob/a70879f059a2e8439fdb132195c3dd10d4810106/README.md#L31-L34>) [Termux/docs/user-guide.md:60–96](<https://github.com/lfdevs/anland-termux/blob/a70879f059a2e8439fdb132195c3dd10d4810106/docs/user-guide.md#L60-L96>) [Termux/docs/user-guide.md:199–206](<https://github.com/lfdevs/anland-termux/blob/a70879f059a2e8439fdb132195c3dd10d4810106/docs/user-guide.md#L199-L206>) [Termux/images/debian-plasma.Dockerfile:55–58](<https://github.com/lfdevs/anland-termux/blob/a70879f059a2e8439fdb132195c3dd10d4810106/images/debian-plasma.Dockerfile#L55-L58>) [Termux/docs/user-guide.md:294–300](<https://github.com/lfdevs/anland-termux/blob/a70879f059a2e8439fdb132195c3dd10d4810106/docs/user-guide.md#L294-L300>)
|
||||
|
||||
**Non-Adreno GPUs:** lfdevs says MediaTek Dimensity, Google Tensor and Samsung Exynos currently use **LLVMpipe**, may fail to enter the desktop, and only **Tensor G1** had been personally tested successfully in PRoot/Chroot. The Plasma installer repeats the software-rendering limitation. This is not a verified hardware-accelerated Mali, PowerVR or Xclipse support statement. No specific accelerated PowerVR/Xclipse result or desktop GL-version claim was established in the reviewed docs/builds. **Inferred:** MobileGL may remove the Mesa KGSL dependency for rendering, but current 6.x's snapalloc-dependent buffer import is a separate obstacle on other vendors. [Termux/README.md:25–29](<https://github.com/lfdevs/anland-termux/blob/a70879f059a2e8439fdb132195c3dd10d4810106/README.md#L25-L29>) [Plasma/README.md:59](<https://github.com/asveroid/anland-plasma-termux/blob/099710d413b47d2f3f8c5091a95ee2732d3be0e6/README.md#L59>) [termux-packages/mesa/build.sh:177–185](https://github.com/lfdevs/termux-packages/blob/ccc9cc550efc604188242285f99884183596ebb0/packages/mesa/build.sh#L177-L185) [waylandbridge/awl_ahb.cpp:139–146](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L139-L146>) [waylandbridge/awl_ahb.cpp:264–274](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L264-L274>)
|
||||
|
||||
**GL versions and performance:** the evidence establishes Freedreno FD650 direct acceleration in a device issue, and waylandbridge requests an **OpenGL ES 3 context**; neither establishes that graphical Linux apps universally get desktop GL 4.6 or any other specific maximum. No `glxinfo`/`eglinfo` version result was found in the cited compatibility docs or device report. The concrete performance figures available in the current code are the **29 fps** callback-placement regression and **123 vs ~1300 fps** vkmark scanout/copy comparison, with the measurement limitations described in §3. [anland issue #84](https://github.com/SuperTurtleDev/anland/issues/84) [waylandbridge/awl_gl.cpp:102–105](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_gl.cpp#L102-L105>) [Termux/README.md:25–29](<https://github.com/lfdevs/anland-termux/blob/a70879f059a2e8439fdb132195c3dd10d4810106/README.md#L25-L29>) [waylandbridge/awl_sc.cpp:60–75](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L60-L75>) [waylandbridge/awl_sc.cpp:389–400](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L389-L400>)
|
||||
|
||||
### 5.2 What Xwayland glamor needs, and what the patch changes
|
||||
|
||||
The vendored source is Xwayland **24.1.10**. The patch README explicitly says the display GPU is reached via KGSL and that the chosen fallback `/dev/dri/renderD128` is redirected by the patched Mesa stack. It does not demonstrate that a stock distro GBM can open a working DRM render node on every phone. [anland/patches/xwayland/README.anland.md:1–9](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/patches/xwayland/README.anland.md#L1-L9>) [anland/patches/xwayland/README.anland.md:29–39](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/patches/xwayland/README.anland.md#L29-L39>)
|
||||
|
||||
| Requirement / interface | Actual pinned GBM implementation |
|
||||
|---|---|
|
||||
| GBM device and EGL platform | Opens/uses a device fd, calls `gbm_create_device`, gets `EGL_PLATFORM_GBM_MESA`, and initializes EGL. It tries desktop GL then GLES, requires a renderer and `GL_OES_EGL_image`, and rejects named llvmpipe/softpipe glamor renderers. [xserver/hw/xwayland/xwayland-glamor-gbm.c:1710–1766](https://gitlab.freedesktop.org/xorg/xserver/-/blob/5a873951579f1ff894f71489f3651a55d6dde250/hw/xwayland/xwayland-glamor-gbm.c#L1710-1766) |
|
||||
| dma-buf image import | Tests both dma-buf import and modifiers extension support for `dmabuf_capable`; constructs `EGL_LINUX_DMA_BUF_EXT` images with plane fds, offsets, pitches and modifier words. **Inferred:** a replacement provider for this path needs compatible GBM allocation/import and EGL image behavior, not only GL draw entry points. [xserver/hw/xwayland/xwayland-glamor-gbm.c:243–277](https://gitlab.freedesktop.org/xorg/xserver/-/blob/5a873951579f1ff894f71489f3651a55d6dde250/hw/xwayland/xwayland-glamor-gbm.c#L243-277) [xserver/hw/xwayland/xwayland-glamor-gbm.c:1769–1773](https://gitlab.freedesktop.org/xorg/xserver/-/blob/5a873951579f1ff894f71489f3651a55d6dde250/hw/xwayland/xwayland-glamor-gbm.c#L1769-1773) |
|
||||
| dma-buf export | The pinned GBM path obtains fds through **`gbm_bo_get_fd_for_plane` / `gbm_bo_get_fd`**. It does **not** require/call `EGL_MESA_image_dma_buf_export` in this file. That extension can be useful for an EGL-owned-image export design, but calling it a universal glamor prerequisite would overstate this implementation. [xserver/hw/xwayland/xwayland-glamor-gbm.c:486–533](https://gitlab.freedesktop.org/xorg/xserver/-/blob/5a873951579f1ff894f71489f3651a55d6dde250/hw/xwayland/xwayland-glamor-gbm.c#L486-533) [xserver/hw/xwayland/xwayland-glamor-gbm.c:844–881](https://gitlab.freedesktop.org/xorg/xserver/-/blob/5a873951579f1ff894f71489f3651a55d6dde250/hw/xwayland/xwayland-glamor-gbm.c#L844-881) |
|
||||
| DRI3 | Registers `dri3_screen_init` and import/export callbacks for pixmaps/fds. The patch fixes a modifier problem specifically in imported DRI3 buffers. **Inferred:** accelerated X11 clients need a compatible GLX/DRI3/GBM integration (or another deliberate X11 route); a MobileGL Wayland EGL swap implementation alone does not transparently replace that client/server contract. [xserver/hw/xwayland/xwayland-glamor-gbm.c:1812–1826](https://gitlab.freedesktop.org/xorg/xserver/-/blob/5a873951579f1ff894f71489f3651a55d6dde250/hw/xwayland/xwayland-glamor-gbm.c#L1812-1826) [anland/patches/xwayland/anland-kgsl-glamor.patch:22–37](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/patches/xwayland/anland-kgsl-glamor.patch#L22-L37>) |
|
||||
|
||||
The four patch changes are precise:
|
||||
|
||||
1. Submit **`DRM_FORMAT_MOD_INVALID`** via linux-dmabuf without requiring it to be found in the advertised modifier set. [anland/patches/xwayland/anland-kgsl-glamor.patch:3–21](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/patches/xwayland/anland-kgsl-glamor.patch#L3-L21>)
|
||||
2. Rewrite bogus modifier **`1274ULL` (`0x4FA`) → DRM_FORMAT_MOD_LINEAR`** before GBM import, for the documented Mesa/KGSL DRI3 bug. This is not general tiled-buffer conversion. [anland/patches/xwayland/anland-kgsl-glamor.patch:22–37](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/patches/xwayland/anland-kgsl-glamor.patch#L22-L37>)
|
||||
3. Wait for default feedback only when protocol version is **≥4**; initialize `main_dev=NULL`; when unavailable or without a render node, use **`XWAYLAND_GBM_DEVICE`**, default **`/dev/dri/renderD128`**. [anland/patches/xwayland/anland-kgsl-glamor.patch:38–91](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/patches/xwayland/anland-kgsl-glamor.patch#L38-L91>)
|
||||
4. Permit glamor when **linux-dmabuf v3** exists despite no `wl_drm` or v4 feedback. [anland/patches/xwayland/anland-kgsl-glamor.patch:92–109](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/patches/xwayland/anland-kgsl-glamor.patch#L92-L109>)
|
||||
|
||||
**Inferred:** these changes solve device selection and buffer-routing assumptions in that Mesa-based stack. They do not implement a GBM backend for MobileGL, import full AHB handles into Anland, add AB24/UBWC support, or make container glibc load Android vendor GLES directly. [anland/patches/xwayland/anland-kgsl-glamor.patch:1–109](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/patches/xwayland/anland-kgsl-glamor.patch#L1-L109>) [waylandbridge/awl_dmabuf.c:17–22](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L17-L22>) [waylandbridge/awl_ahb.cpp:334–340](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L334-L340>)
|
||||
|
||||
## 6. waylandbridge's own renderer and Android driver loading
|
||||
|
||||
The build uses the Android NDK toolchain, **arm64-v8a**, platform **android-35**. Wayland/ffi are static dependencies, and Anland's protocol/adapter source is compiled into one executable. The graphics/system dependencies remain **`binder_ndk android log EGL GLESv3 nativewindow`**; there is no evidence here of a fully static libc+vendor-GLES binary. The README's “single statically-linked ELF” should be read in light of the executable's actual link configuration. [anland/Makefile:77–83](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/Makefile#L77-L83>) [waylandbridge/CMakeLists.txt:225–244](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/CMakeLists.txt#L225-L244>) [waylandbridge/CMakeLists.txt:303–308](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/CMakeLists.txt#L303-L308>) [waylandbridge/CMakeLists.txt:364–365](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/CMakeLists.txt#L364-L365>) [anland/README.md:73–78](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/README.md#L73-L78>)
|
||||
|
||||
The renderer calls ordinary Android EGL entry points: `eglGetDisplay(EGL_DEFAULT_DISPLAY)`, `eglInitialize`, `eglChooseConfig` for ES3 and window/pbuffer use, and `eglCreateContext(...CLIENT_VERSION,3)`. It resolves EGLImage/native-buffer/fence procedures with `eglGetProcAddress`. Root executable startup and policy explicitly provide GPU/vendor-file access. **Inferred:** this is a bionic Android-native consumer of the platform EGL/GLES dispatch stack and device graphics implementation, not container Mesa doing the daemon's composition. [waylandbridge/awl_gl.cpp:34–106](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_gl.cpp#L34-L106>) [anland/module/service.sh:20–26](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/service.sh#L20-L26>) [anland/module/sepolicy.rule:111–120](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L111-L120>)
|
||||
|
||||
There is no custom graphics linker namespace creation or `android_dlopen_ext` bypass in these renderer files. The explicit `dlopen` shown in `waylandbridge.cpp` loads **`libbinder_ndk.so`** to resolve platform-only service-manager/thread-pool functions, not a vendor GLES driver. **Inferred:** a root bionic executable can follow this platform-EGL route without being an APK; root is not itself a linker-namespace bypass. This source does not prove that arbitrary vendor DSOs can be dlopened directly from arbitrary namespaces, nor that a glibc executable can load them. [waylandbridge/waylandbridge.cpp:100–119](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L100-L119>) [waylandbridge/awl_gl.cpp:34–76](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_gl.cpp#L34-L76>) [waylandbridge/CMakeLists.txt:364–365](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/CMakeLists.txt#L364-L365>)
|
||||
|
||||
The target does not link Vulkan or call it in these rendering paths. **Inferred:** Anland provides concrete precedent for MobileGL's bionic GLES/Magma server deployment; an Espryt/Vulkan server using Android's Vulkan loader is a separate validation task. Linker/loader policy, extension support and buffer interoperability for that Vulkan path cannot be certified from Anland's GLES implementation. [waylandbridge/CMakeLists.txt:350–365](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/CMakeLists.txt#L350-L365>) [waylandbridge/awl_gl.cpp:34–106](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_gl.cpp#L34-L106>)
|
||||
|
||||
## 7. What the derivatives reveal about other frame paths
|
||||
|
||||
**E7G wlroots-anland.** This is a wlroots **0.20.x** native backend for the **E7G private Anland protocol**, not a backend for 6.x linux-dmabuf Wayland ingress. It connects to `ANLAND_SOCKET` (default `/tmp/display_daemon.sock`) and imports a **consumer-owned pool**. Its allocator gets the selected pool fd/info, wraps a one-plane `wlr_dmabuf_attributes` with offset/stride/modifier, and advertises `WLR_BUFFER_CAP_DMABUF`. Commit locks the submitted buffer until consumer-ready, then sends a wlroots presentation event and a new frame opportunity. **Inferred:** this demonstrates an alternative allocation direction useful for MobileGL—Android supplies render targets—but does not supply native-AHB ingress to current waylandbridge. Its `VSYNC|ZERO_COPY` presentation flags are backend claims based on consumer-ready, not proof of a physical scanout timestamp. [wlroots/README.anland.md:3–19](<https://github.com/E7G/wlroots-anland/blob/351399132de0b208ddb36d0ea2fa74cbe668fb72/README.anland.md#L3-L19>) [wlroots/backend/anland/allocator.c:33–58](<https://github.com/E7G/wlroots-anland/blob/351399132de0b208ddb36d0ea2fa74cbe668fb72/backend/anland/allocator.c#L33-L58>) [wlroots/backend/anland/allocator.c:64–76](<https://github.com/E7G/wlroots-anland/blob/351399132de0b208ddb36d0ea2fa74cbe668fb72/backend/anland/allocator.c#L64-L76>) [wlroots/backend/anland/output.c:21–34](<https://github.com/E7G/wlroots-anland/blob/351399132de0b208ddb36d0ea2fa74cbe668fb72/backend/anland/output.c#L21-L34>) [wlroots/backend/anland/output.c:67–76](<https://github.com/E7G/wlroots-anland/blob/351399132de0b208ddb36d0ea2fa74cbe668fb72/backend/anland/output.c#L67-L76>)
|
||||
|
||||
**Yizhou147 anland-drm.** This replaces the legacy Android APK consumer with a DRM/KMS consumer. The implemented main display allocation uses **DRM dumb buffers**, exports PRIME fds, sends a pool with format **1 (RGBA8888)**, modifier **0**, offset **0**, selects a producer render target, then page-flips it. Although the README lists dma-heap/ion helpers, those are not the allocation calls used by this main display path. Its README says untested, but the newer progress note reports a binary running on **houji/Snapdragon 8 Gen 3**, detecting a **5120×2560@60** connector/input, while `drmModeSetCrtc` still fails **Permission denied**, even after stopping SF and trying root. **Inferred:** it demonstrates the protocol's independence from Android windowing, not a working universal replacement for HWC. Its loop closes the returned render fence before page-flip without waiting/passing it onward, so it is also not a reliable synchronization precedent. [anland-drm/consumer/drm_display.c:146–196](<https://github.com/Yizhou147/anland-drm/blob/850f7ca0e0f25d34dd04baa7e12e8751bcff4951/consumer/drm_display.c#L146-L196>) [anland-drm/consumer/drm_consumer.c:242](<https://github.com/Yizhou147/anland-drm/blob/850f7ca0e0f25d34dd04baa7e12e8751bcff4951/consumer/drm_consumer.c#L242>) [anland-drm/consumer/drm_consumer.c:275–320](<https://github.com/Yizhou147/anland-drm/blob/850f7ca0e0f25d34dd04baa7e12e8751bcff4951/consumer/drm_consumer.c#L275-L320>) [anland-drm/README.md:3–13](<https://github.com/Yizhou147/anland-drm/blob/850f7ca0e0f25d34dd04baa7e12e8751bcff4951/README.md#L3-L13>) [anland-drm/PROGRESS.md:14–34](<https://github.com/Yizhou147/anland-drm/blob/850f7ca0e0f25d34dd04baa7e12e8751bcff4951/PROGRESS.md#L14-L34>)
|
||||
|
||||
**Legacy 5.x “Anland Display Protocol.”** `common/protocol.h` defines packed control/data messages (`CONSUMER_HELLO=1`, `PRODUCER_HELLO=2`, `SCREEN_INFO=7`, `PICKUP_FDS=9`, `FDS_READY=10`; data `BUF_READY=100`, `REFRESH_DONE=101`, `BUFS_READY=200`; `MAX_BUFS=8`) and `buf_info {uint32_t stride,width,height,format; uint64_t modifier; uint32_t offset;}`. Android consumer dequeues **real ANativeWindow buffers**, retains the original `ANativeWindowBuffer*`, exports only native-handle **fd[0]** plus descriptor, and sets modifier/offset **0**. It waits on dequeue fences before selecting a producer target; producer completion returns a sync_file that is passed to `queueBuffer` for SF to wait on. There is no need to forge a return-path AHB because the Android consumer kept the original native buffer. **Inferred:** this is a strong pattern for a native-handle extension or Android-owned target pool, but the existing private protocol itself does **not** transmit a complete arbitrary native_handle/AHB; compressed storage cannot safely be represented just by claiming modifier 0. [legacy/common/protocol.h:7–49](<https://github.com/SuperTurtleDev/anland/blob/9ab13eb146bc9f3dd3cc44cabc268659d9eb0a46/common/protocol.h#L7-L49>) [legacy/consumers/anland_v5/android_consumer/app/src/main/jni/native_consumer.c:133–188](<https://github.com/SuperTurtleDev/anland/blob/9ab13eb146bc9f3dd3cc44cabc268659d9eb0a46/consumers/anland_v5/android_consumer/app/src/main/jni/native_consumer.c#L133-L188>) [legacy/consumers/anland_v5/android_consumer/app/src/main/jni/native_consumer.c:778–813](<https://github.com/SuperTurtleDev/anland/blob/9ab13eb146bc9f3dd3cc44cabc268659d9eb0a46/consumers/anland_v5/android_consumer/app/src/main/jni/native_consumer.c#L778-L813>) [legacy/consumers/anland_v5/android_consumer/app/src/main/jni/native_consumer.c:953–1003](<https://github.com/SuperTurtleDev/anland/blob/9ab13eb146bc9f3dd3cc44cabc268659d9eb0a46/consumers/anland_v5/android_consumer/app/src/main/jni/native_consumer.c#L953-L1003>)
|
||||
|
||||
## 8. Concrete changes for MobileGL AHB output and avoiding the forge
|
||||
|
||||
This section is **inferred design**, not existing Anland functionality. The starting constraint is that MobileGL allocates genuine Android AHBs, commonly **`AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM`**, with DRM identity **ABGR8888/AB24** for little-endian RGBA bytes. Current Anland admits AR24/XR24 and then overwrites the storage description with BGRA donor metadata. In contrast, Anland's **own SC copy pool already allocates RGBA AHBs** with `GPU_COLOR_OUTPUT | GPU_SAMPLED_IMAGE | COMPOSER_OVERLAY` and imports/displays them. Thus the output side is already capable of consuming suitable genuine RGBA AHBs; ingress, representation and lifetime are the missing pieces. [drm-uapi/drm_fourcc.h:193–199](https://github.com/lfdevs/mesa-for-android-container/blob/98f3d6229d61452cef80f8563af7c56ae599dc14/include/drm-uapi/drm_fourcc.h#L193-L199) [waylandbridge/awl_dmabuf.c:17–22](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L17-L22>) [waylandbridge/awl_ahb.cpp:334–336](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L334-L336>) [waylandbridge/awl_sc.cpp:279–300](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L279-L300>)
|
||||
|
||||
### 8.1 Smallest paths, and exactly what each buys
|
||||
|
||||
| Path | Changes and limits — all inferred |
|
||||
|---|---|
|
||||
| **No Anland change, functional baseline** | MobileGL finishes/readbacks or otherwise converts to packed BGRA/XRGB in `wl_shm`, and its client-side Wayland WSI commits it. This avoids forge/vendor metadata dependence but pays readback/transfer/upload and does not preserve compressed zero-copy buffers. Anland's shm upload/release path already exists. [waylandbridge/awl_gl.cpp:331–379](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_gl.cpp#L331-L379>) [anland/include/awl.h:325–342](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/include/awl.h#L325-L342>) |
|
||||
| **No Anland change, narrow dma-buf experiment** | Produce actual linear, zero-offset AR24/XR24 storage, send modifier **0**, correct byte pitch and sync_files. Requires a device where the snapalloc calibration/import works; allocating an RGBA/UBWC AHB and sending fd[0] is not this path. There is no generic portability guarantee. [waylandbridge/awl_dmabuf.c:17–22](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L17-L22>) [waylandbridge/awl_ahb.cpp:139–146](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L139-L146>) [waylandbridge/awl_ahb.cpp:264–274](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L264-L274>) [waylandbridge/awl_ahb.cpp:334–395](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L334-L395>) |
|
||||
| **Smallest meaningful native-AHB change** | Add a native-AHB registration/import side channel and a way to create/associate a Wayland `wl_buffer` with the registered object. Keep the existing renderers/SC transactions, but resolve registered buffers directly to retained AHBs instead of `awl_ahb_wrap`. Add correct RGBA/AB24 format handling and propagate lifetime/fences. This avoids donor allocation/calibration/patching and the fabricated local socketpair round-trip. [waylandbridge/awl_internal.h:71–81](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_internal.h#L71-L81>) [waylandbridge/awl_surface.c:184–218](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L184-L218>) [waylandbridge/awl_ahb.cpp:534–569](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L534-L569>) [waylandbridge/awl_gl.cpp:257–289](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_gl.cpp#L257-L289>) [waylandbridge/awl_sc.cpp:727–743](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L727-L743>) |
|
||||
| **Clean native buffer path** | Versioned Wayland extension or authenticated broker protocol, typed buffer payload, resource-owned native import and stable generation/identity; preserve linux-dmabuf as a separate raw-layout importer. Full AHB metadata stays on Android; the glibc client carries an opaque resource/token and fences. This makes native compressed layouts opaque to Anland's logical layer and leaves import interpretation to gralloc/EGL/SF. [waylandbridge/awl_bufferqueue.h:5–8](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.h#L5-L8>) [waylandbridge/awl_bufferqueue.h:63–76](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.h#L63-L76>) [anland/include/awl.h:309–323](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/include/awl.h#L309-L323>) [waylandbridge/awl_gl.cpp:257–289](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_gl.cpp#L257-L289>) |
|
||||
|
||||
Adding only AB24 to `k_supported` is **insufficient**: `awl_ahb_wrap` still forces HAL BGRA, the cache does not include format, and no original native metadata is available. Extending the forge to another HAL format could help a narrowly compatible linear layout but would still retain the vendor-layout dependency and would not preserve UBWC. [waylandbridge/awl_dmabuf.c:17–22](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L17-L22>) [waylandbridge/awl_ahb.cpp:334–336](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L334-L336>) [waylandbridge/awl_ahb.cpp:546–568](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L546-L568>)
|
||||
|
||||
### 8.2 Concrete insertion points
|
||||
|
||||
| Function / file | Small viable edit → clean design direction — all inferred |
|
||||
|---|---|
|
||||
| `awl_dmabuf_setup`, `params_*`, `dmabuf_buffer_create` in `awl_dmabuf.c`; `awl_server_start`; protocol generation in `CMakeLists.txt` | Add a distinct native-buffer factory/registration protocol and register it at startup; do not overload linux-dmabuf plane fds with arbitrary gralloc metadata. For the existing raw path, fix INVALID and explicitly validate supported modifier, zero offset, format, dimensions and extent instead of discarding layout information. [waylandbridge/awl_dmabuf.c:49–85](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L49-L85>) [waylandbridge/awl_dmabuf.c:105–175](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L105-L175>) [waylandbridge/awl_server.c:385–401](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_server.c#L385-L401>) [waylandbridge/CMakeLists.txt:309–349](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/CMakeLists.txt#L309-L349>) [waylandbridge/awl_internal.h:35–40](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_internal.h#L35-L40>) |
|
||||
| `host_on_transact` / Binder transaction enum in `waylandbridge.cpp`, if choosing an Android broker | Add a **new** registration operation for complete AHB handle/descriptor import, returning a scoped token. Reuse Binder only as transport/identity infrastructure: `T_CONNECT` currently transfers a Wayland socket. Bind a token to the right client/resource or an explicit delegated registration capability, accounting for the different container and Android-server UIDs. [waylandbridge/waylandbridge.cpp:184–196](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L184-L196>) [waylandbridge/waylandbridge.cpp:1528–1567](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L1528-L1567>) [waylandbridge/waylandbridge.cpp:1820–1847](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L1820-L1847>) |
|
||||
| `struct awl_buffer` / destruction in `awl_internal.h`, `awl_surface.c`, `awl_dmabuf.c` | Add payload kind and opaque native import reference, with acquire/release ownership, descriptor and stable identity. Keep the imported AHB alive after `wl_buffer.destroy` while queue/SF references exist, following the existing wrapper lifetime pattern. [waylandbridge/awl_internal.h:65–81](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_internal.h#L65-L81>) [waylandbridge/awl_dmabuf.c:33–46](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_dmabuf.c#L33-L46>) [waylandbridge/awl_surface.c:58–67](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L58-L67>) |
|
||||
| `awl_surface_apply_buffer` and `struct awl_bq_buffer` | Carry an opaque native-buffer reference/token with each frame; preserve acquire/release fences and format/geometry. The current queue treats **`dmabuf_fd<0` as NULL/unmap**, so merely adding an AHB pointer while leaving fd=-1 silently breaks readiness/render selection. Introduce a tagged payload or retain a real backing fd in the narrow implementation; update readiness, close/unref, and all fd-based branches. [waylandbridge/awl_surface.c:184–218](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L184-L218>) [waylandbridge/awl_bufferqueue.h:63–76](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.h#L63-L76>) [waylandbridge/awl_bufferqueue.c:184–210](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.c#L184-L210>) [waylandbridge/awl_sc.cpp:896–898](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L896-L898>) |
|
||||
| `awl_ahb_cache_get` / `awl_ahb_wrap` | Resolve native registrations directly to an acquired AHB, bypassing the forge. An inode-only association can be a controlled prototype, but the clean key is an imported-buffer identity/generation plus complete descriptor; include format and distinguish native handles from reconstructed raw buffers. Multiple metadata handles or reuse must not collide. Cache the real AHB/EGLImage per swapchain buffer. [waylandbridge/awl_ahb.cpp:534–569](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L534-L569>) [waylandbridge/awl_ahb.hpp:53–86](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.hpp#L53-L86>) |
|
||||
| `awl_gl_tex_import`, `render_frame` in `awl_renderer.cpp` | `awl_gl_tex_import` already takes any suitable AHB through native-buffer EGL import. Feed it the real AHB; extend source selection and format/opacity handling for AB24/XB24. Keep shm's BGRA byte uploader separate; do not apply an unnecessary R/B swap to native RGBA. [waylandbridge/awl_gl.cpp:257–289](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_gl.cpp#L257-L289>) [waylandbridge/awl_gl.cpp:331–345](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_gl.cpp#L331-L345>) [waylandbridge/awl_renderer.cpp:292–334](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_renderer.cpp#L292-L334>) |
|
||||
| `sc_render_window`, `latch_scanout`, `latch_egl` in `awl_sc.cpp`; `awl_ahb_hwc_scanout_ok` | The pitch oracle is specifically for forged linear BGRA and must not decide native opaque/compressed AHB eligibility. Submit a real allocation with its original metadata; require suitable AHB usage and let Android import/composition determine support. Retain a real-AHB-to-real-AHB GPU-copy mode for pacing or unsupported direct composition where source sampling succeeds. [waylandbridge/awl_ahb.cpp:60–91](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L60-L91>) [waylandbridge/awl_sc.cpp:279–300](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L279-L300>) [waylandbridge/awl_sc.cpp:727–796](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L727-L796>) [waylandbridge/awl_sc.cpp:903–935](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L903-L935>) |
|
||||
| `awl_esync.c`, queue readiness/release, SC release callbacks | Reuse sync_file per-commit semantics. Minimal implementation can keep current ready-before-latch behavior. A later SC optimization can pass the producer fence directly to SF instead of waiting for readiness, but requires redesigning mailbox selection, ownership and fence lifetime; it is not a one-line replacement of `-1`. Native payloads without a raw dma-buf need explicit release, not the current implicit-reservation fallback. [waylandbridge/awl_esync.c:121–170](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_esync.c#L121-L170>) [waylandbridge/awl_bufferqueue.c:184–192](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_bufferqueue.c#L184-L192>) [waylandbridge/awl_surface.c:84–108](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L84-L108>) [waylandbridge/awl_sc.cpp:329–353](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L329-L353>) [waylandbridge/awl_sc.cpp:727–740](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L727-L740>) |
|
||||
| `module/service.sh`, `module/sepolicy.rule`, service contexts; container mount/session configuration | Launch the bionic server and expose the local socket/broker, with domain-specific communication, allocator/GPU and fd-origin consumer permissions as in §4. Keep normal Wayland surface ownership tied to the Linux app unless explicitly choosing an APK-owned client architecture. [anland/module/service.sh:20–26](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/service.sh#L20-L26>) [anland/module/sepolicy.rule:76–87](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L76-L87>) [anland/module/sepolicy.rule:111–161](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L111-L161>) [waylandbridge/waylandbridge.cpp:1528–1567](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L1528-L1567>) |
|
||||
|
||||
### 8.3 Native handle transport, UBWC and the remaining MobileGL responsibilities
|
||||
|
||||
**Inferred native transport design:** use **`AHardwareBuffer_sendHandleToUnixSocket` → `AHardwareBuffer_recvHandleFromUnixSocket`** on a **dedicated local Unix channel** between the two bionic processes, or design a Binder HardwareBuffer/native-handle transport. The two Unix APIs are documented for `AF_UNIX` and available since **API 26**. Preserve **all** handle fds and integer metadata, original descriptor/usage and allocation identity; do not copy the forge's hardcoded two-fd/13-word reconstruction as a universal format. Associate the imported object with a Wayland `wl_buffer` by a scoped token/protocol object. Do not interleave AHB's byte stream into the ordinary Wayland socket without a defined protocol envelope. A real interprocess AHB receive/import remains, but the fabricated local donor round-trip and its calibration are eliminated. [android/hardware_buffer.h:528–549](https://android.googlesource.com/platform/frameworks/native/+/refs/heads/main/libs/nativewindow/include/android/hardware_buffer.h#528) [waylandbridge/awl_ahb.cpp:139–146](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L139-L146>) [waylandbridge/awl_ahb.cpp:398–464](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L398-L464>) [waylandbridge/awl_internal.h:65–81](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_internal.h#L65-L81>) [waylandbridge/waylandbridge.cpp:1820–1847](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/waylandbridge.cpp#L1820-L1847>)
|
||||
|
||||
For SC presentation, allocate with the intended usage from the start. Android's header specifically says **`AHARDWAREBUFFER_USAGE_COMPOSER_OVERLAY`** is needed for `ASurfaceTransaction_setBuffer` when the buffer was allocated directly with `AHardwareBuffer_allocate`; the framework normally adds it for framework-managed buffers. **Inferred:** MobileGL's native target pool should use the render/sample/composer combination already used by `pool_create`, subject to device support, rather than changing usage words after allocation. [android/hardware_buffer.h:270–290](https://android.googlesource.com/platform/frameworks/native/+/refs/heads/main/libs/nativewindow/include/android/hardware_buffer.h#270) [waylandbridge/awl_sc.cpp:284–300](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L284-L300>)
|
||||
|
||||
**Inferred UBWC policy:** allow only genuine native allocations that the consuming Android stack can import/sample/present with their original metadata. The extension should carry them opaquely, not assert a linear DRM modifier or patch a donor blob. Unsupported native import should fail clearly before claiming the buffer usable; an optional GPU blit requires the native source to be importable first. RGBA support and compressed-layout support are related but distinct. Anland's own RGBA target pool demonstrates the right allocation/import pattern, not proof of every vendor's compression support. [waylandbridge/awl_sc.cpp:279–300](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L279-L300>) [waylandbridge/awl_gl.cpp:257–285](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_gl.cpp#L257-L285>) [waylandbridge/awl_ahb.cpp:334–395](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L334-L395>)
|
||||
|
||||
**Inferred MobileGL work items:** client-side Wayland EGL/GL window-system integration must create/resize buffers, attach/damage/commit the correct `wl_surface`, obey configure/viewport geometry, pace frames, and retain each buffer until release plus fence completion. Android-side rendering must allocate/import the target, export a real completion sync_file, and honor consumer release before reuse. The Anland changes above solve buffer handoff, not missing GL entry points or X11 GLX/DRI3/GBM integration. A staged validation should first prove `wl_shm`, then native uncompressed RGBA AHB import, then fence/lifetime/resize/parking correctness, and only then vendor compression and direct-SC behavior. These stages are recommendations grounded in the existing independent paths, not tests performed in this audit. [waylandbridge/awl_surface.c:184–218](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L184-L218>) [waylandbridge/awl_surface.c:825–859](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_surface.c#L825-L859>) [waylandbridge/awl_viewport.c:1–17](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_viewport.c#L1-L17>) [waylandbridge/awl_esync.c:121–200](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_esync.c#L121-L200>) [waylandbridge/awl_sc.cpp:279–300](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L279-L300>) [waylandbridge/awl_sc.cpp:727–796](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L727-L796>) [xserver/hw/xwayland/xwayland-glamor-gbm.c:1710–1773](https://gitlab.freedesktop.org/xorg/xserver/-/blob/5a873951579f1ff894f71489f3651a55d6dde250/hw/xwayland/xwayland-glamor-gbm.c#L1710-1773) [xserver/hw/xwayland/xwayland-glamor-gbm.c:1812–1826](https://gitlab.freedesktop.org/xorg/xserver/-/blob/5a873951579f1ff894f71489f3651a55d6dde250/hw/xwayland/xwayland-glamor-gbm.c#L1812-1826)
|
||||
|
||||
**Preferred integration, inferred:** keep Linux applications as ordinary Wayland clients, keep MobileGL's render server bionic, and add a small native-buffer bridge into Anland's existing AHB-consuming renderers. This addresses both RGBA/opaque gralloc layouts and the donor-forge dependency without making the glibc client understand vendor gralloc internals. The exact viable compressed formats, enforced SELinux policy and release-depth behavior remain device-validation questions. [waylandbridge/awl_gl.cpp:257–289](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_gl.cpp#L257-L289>) [waylandbridge/awl_sc.cpp:279–300](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L279-L300>) [waylandbridge/awl_sc.cpp:727–743](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_sc.cpp#L727-L743>) [waylandbridge/awl_ahb.cpp:139–146](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/services/waylandbridge/awl_ahb.cpp#L139-L146>) [anland/module/sepolicy.rule:18](<https://github.com/SuperTurtleDev/anland/blob/cc1691805fe6aca6851b6fcccb6a1e33019026c1/module/sepolicy.rule#L18>)
|
||||
@@ -0,0 +1,591 @@
|
||||
# MobileGL → Anland:只读代码盘点
|
||||
|
||||
审计日期:2026-09-30。对象:Arch WSL 的 ~/w7/p9-main。实际分支为 **p8/main**,HEAD **648800a2da231e8152760d400da33e500d511ca6**,提交说明为关闭 P8;不是任务描述里的 feat/disaggregated。依据是本次只读 git status / git branch --show-current / git log -1;未切换分支。路线图也将 P8 标记完成(docs/Disaggregated/ROADMAP.md:3、:36)。所有源码引用均为此目录、此时点的树根相对路径。未构建、未执行测试或设备操作;“已验证”只指被引用的历史证据。Anland 的格式、modifier、同步和部署条件采用题目给定前提,未另行审计 Anland。
|
||||
|
||||
**结论:拆分 GL 执行已存在,Anland 所需的窗口系统与帧交付链尚不存在。** 已有 Linux client → Android vendor-driver server 的历史跨机验收;当前 P12 在服务器自己的 SurfaceView 上呈现,未把每帧 dma-buf / fence fd 交回 Linux client。要作为通用 Linux desktop GL provider,仍需 Linux WSI、可交付图像、跨进程同步、buffer 生命周期、多会话/多窗口与真实 context/share-group 支持。前两句有代码/验收直接依据;“所需工作”是 **inferred**,详见各节。(docs/Disaggregated/notes/p12/CROSSHOST-ACCEPTANCE.md:3–17;MobileGL/MG_Remote/CONTRACT-P12.md:7、:16、:44;MobileGL/MG_Pipe/MGPipeTypes.h:1807–1809;MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp:17252–17283;MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp:14528–14547)
|
||||
|
||||
先纠正名称:**Espryt = DirectGLES(原生 EGL/GLES);Magma = DirectVulkan(Vulkan)**。题目第 3 项括号中的两个后端正好相反。(MobileGL/MG_Backend/DirectGLES/BackendObject_DirectGLES.cpp:812–822;MobileGL/MG_Backend/DirectVulkan/BackendObject_DirectVulkan.cpp:543–551)
|
||||
|
||||
## 1. Linux client 构建、库与加载器
|
||||
|
||||
### 1.1 哪些平台能确认
|
||||
|
||||
| 平台 / 问题 | 当前结论及依据 |
|
||||
|---|---|
|
||||
| Linux glibc x86_64 / WSL | **有实际 client 证据**。P6.5 明确部署 x86_64 WSL client ↔ aarch64 Redmi server;P12 的 WSL trace client 对 Android DirectGLES/stream 已验收 OpenRA 和 rd12。它证明 glibc client 可运行和跨 ABI 的特定组合可工作,不证明任意 Linux GUI 程序已可在 Anland 上显示。(docs/Disaggregated/notes/p65/README.md:61、:93;docs/Disaggregated/notes/p12/CROSSHOST-ACCEPTANCE.md:3–17) |
|
||||
| Linux CI | 存在 Ubuntu split build,clang/clang++ 20、Release、disaggregated/inproc/push 和 integration tests 配置。这里没有重跑 CI。(.github/workflows/test.yml:1206、:1260、:1269–1296) |
|
||||
| Linux glibc aarch64 | **未找到该组合的现成 preset 或运行验收,不能写成“已验证支持”**。Linux POSIX transport 路径不限制 x86,wire 已为 x86_64↔aarch64 固定宽度/布局校验;因此原生或交叉 glibc aarch64 构建是合理移植目标,属于 **inferred**。Android arm64 NDK 构建不能替代 glibc arm64 验收。(CMakeLists.txt:177–183、:503–545、:783–835、:954–962;MobileGL/MG_Remote/Transport/ShmSegmentPosix.cpp:61–77;docs/Disaggregated/notes/p65/README.md:93;docs/Disaggregated/notes/OPEN-QUESTIONS.md:28) |
|
||||
| “纯 client”库 | 当前是同一 libMobileGL 内编入两种角色,remote client 不构造本地具体 backend;server 可执行文件也链接这份库。没有产品级 client-only / server-only CMake 目标开关。**inferred**:精简 glibc client 的链接依赖是可选后续工作,而不是使用 split 的先决条件。(MobileGL/MG_Remote/Client/BackendObject_Remote.cpp:22–26、:98–105;CMakeLists.txt:594–623、:783–785、:1033–1040;docs/Disaggregated/design/07-memory-readback-verification.md:27) |
|
||||
|
||||
可复用的配置形状(仅示意,本次未执行):
|
||||
|
||||
cmake -S . -B build-split -G Ninja
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
-DMOBILEGL_BUILD_DISAGGREGATED=ON
|
||||
-DMOBILEGL_PIPE_PUSH=ON
|
||||
-DMOBILEGL_BUILD_DISAGGREGATED_INPROC=ON
|
||||
-DMOBILEGL_BUILD_BENCHMARK=OFF
|
||||
|
||||
INPROC 是测试/同进程两角色形态的超集,不是跨进程 client 必需项;INPROC 隐含 DISAGGREGATED,后者隐含 PIPE_PUSH。FlatBuffers submodule runtime header 缺失时 CMake 会警告并把 split 在本次配置中关闭。根目录/两层查找未见 CMakePresets 文件;项目说明和 CI 都用直接 CMake 选项。(CMakeLists.txt:23–30、:503–545;docs/Disaggregated/guide/build-and-run.md:7–12;.github/workflows/test.yml:1275–1293)
|
||||
|
||||
工具链最低 CMake 3.22.1、C++23;glslang、SPIRV-Cross、SPIRV-Tools、SPIRV-Reflect、xxHash、VMA、Threads 被链接,非 Android 配置还查找 Vulkan。CI 安装 Mesa EGL/GLES/Vulkan 开发依赖用于主机后端和测试。aarch64 glibc 应用同样需合适 sysroot/工具链并验证 wireFingerprint;目前没有证据可指定一个现成 arm64 glibc preset。(CMakeLists.txt:1、:177–183、:277–283、:719–731、:954–962;.github/workflows/test.yml:1260;docs/Disaggregated/design/06-transport.md:64;最后一句为 **inferred**。)
|
||||
|
||||
### 1.2 产物与 SONAME
|
||||
|
||||
| 产物 | 源码能确认的事实 |
|
||||
|---|---|
|
||||
| libMobileGL.so | CMake 项目 MobileGL 的 SHARED target;GL、EGL、Linux GLX 都在这份库里。(CMakeLists.txt:3、:401–406、:783–785) |
|
||||
| libEGL.so、libEGL.so.1 | 非 Android、非 Apple UNIX 构建后创建的符号链接,指向上述 target。代码实际只列了这两个 alias。(CMakeLists.txt:825–834) |
|
||||
| libGL.so / libGL.so.1、libOpenGL.so、libGLESv2.so | 未见同等构建 alias / 独立输出目标。不能因为 comment 写“GL/EGL loaders”就称已经产出 libGL;使用 libGL 的系统程序还需 loader 包装/部署策略,后半句为 **inferred**。(CMakeLists.txt:825–834;GL 导出见 MobileGL/MG_Impl/GLImpl/Exporting/Definitions.cpp:26–59) |
|
||||
| libMobileGL_s.a | NOT ANDROID 下另建 MobileGL_s STATIC,同一源集合。(CMakeLists.txt:849–881) |
|
||||
| libMobileGLServer.so | 实际是 PIE **executable**,不是供应用当 EGL vendor dlopen 的库;Android 与 desktop 都强制 lib 前缀、.so 后缀,链接 libMobileGL 并设 $ORIGIN RPATH。(CMakeLists.txt:1033–1085) |
|
||||
| ELF SONAME | 未发现 VERSION/SOVERSION 或 SONAME override。按 CMake Linux 默认,预期 SONAME 为 libMobileGL.so(**inferred,未读 ELF 动态段**);libEGL.so.1 是文件系统 alias,不证明 ELF SONAME 变成 libEGL.so.1。(CMakeLists.txt:783–835) |
|
||||
|
||||
### 1.3 API 导出与 GLVND
|
||||
|
||||
GL/EGL/GLX 导出宏都是 extern C + default visibility;EGL 导出覆盖 display/config/context/current、window/pbuffer/pixmap、swap、查询、EGL 1.5 sync/image/platform 接口,以及 eglGetPlatformDisplayEXT。除通用 glXGetProcAddress/ARB 包装外,具体 GLX 导出在 Linux 非 Android 条件下编译,包含 glXCreateContextAttribsARB(MobileGL/MG_Impl/GLXImpl/Exporting/Definitions.cpp:12–23;MobileGL/MG_Impl/GLXImpl/GLXImpl.h:38)。大量 GL core/extension 名称也被导出,但部分明确是 stub;“dlsym 成功”不能当能力证明。(MobileGL/Defines.h:33–44;MobileGL/MG_Impl/EGLImpl/Exporting/Definitions.cpp:12–25、:112–155、:198–240;MobileGL/MG_Impl/GLXImpl/GLXImpl.h:12–39;MobileGL/MG_Impl/GLImpl/Exporting/Definitions.cpp:26–35、:152、:395–429)
|
||||
|
||||
两个 backend 的目标/报告 GL 和 GLSL 都为 **4.6.0**,静态 identity 的 IsCompatibilityProfile=false;前端 GL_VERSION 直接从这个 TargetGLVersion 生成,而不是按当前 EGL bound API 切换 OpenGL ES 字符串。README 仍写短期目标 OpenGL 4.2 Core,不能把这些数字解释为“已完成 GL 4.6 conformance”。GLX 可接受 compatibility context 请求,但固定功能不完整,见第 7 节。(MobileGL/MG_Backend/DirectGLES/BackendObject_DirectGLES.cpp:817–822;MobileGL/MG_Backend/DirectVulkan/BackendObject_DirectVulkan.cpp:546–551;MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp:619–638;README.md:49–56)
|
||||
|
||||
**没有查到 libglvnd vendor 集成**:全项目检索没有 MobileGL 的 __egl_Main / __glx_Main 定义或 MobileGL egl_vendor.d JSON;目前是直接导出入口、libEGL alias / 由应用指定 MobileGL 加载的形态。CI/测试出现 egl_vendor.d 是选择服务器侧 Mesa/NVIDIA 原生 EGL vendor,不是注册 MobileGL 为 vendor。(CMakeLists.txt:825–834;MobileGL/MG_Impl/EGLImpl/Exporting/Definitions.cpp:12–127;MobileGL/MG_IntegrationTest/CMakeLists.txt:280–299;MobileGL/MG_Benchmark/Driver/run_driver_bench.sh:19)
|
||||
|
||||
**inferred:**Anland 集成需要决定“私有库搜索路径下直接替代 GL/EGL”还是实现 GLVND vendor ABI;已有 GLX 入口不会自动让系统 GLVND 将所有 GLX 应用派发给 MobileGL。依据为上述 alias 和导出形态。
|
||||
|
||||
## 2. EGL frontend 与 GLX 的实际能力
|
||||
|
||||
### 2.1 平台与 native window
|
||||
|
||||
- eglGetDisplay 将 native display key 登记为 EGL_NONE 平台;eglGetPlatformDisplay 将任意 platform/native key 放进显示表,前端并没有按 Wayland/X11/GBM 平台进行真实 WSI 分派。因此“返回非空 EGLDisplay”不构成该平台支持。(MobileGL/MG_State/EGLState/Core.cpp:316–324;MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:708–715)
|
||||
- window backend 按**编译平台**决定:Android / MetalLayer / Win32 / Linux X11;Linux 不是运行时看到 EGL_PLATFORM=wayland 就变为 Wayland。没有 wl_display、wl_egl_window 或 gbm_surface 的实现分支。(MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:64–75、:744–770;未发现这些 WSI 集成的检索结论也与 docs/Disaggregated/design/08-runtime-and-platform.md:32 一致。)
|
||||
- EGL_PLATFORM=surfaceless 是 headless 测试 harness 在未显式设置时写给原生 Mesa loader 的环境变量;DirectGLES 后端仍调用原生 eglGetDisplay(EGL_DEFAULT_DISPLAY)。这不是 MobileGL frontend 完整实现了所有 EGL platform。(MobileGL/MG_IntegrationTest/Harness/HeadlessGL.cpp:172–191;MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp:16587–16593)
|
||||
- Linux **并非源码只有 surfaceless**:有真实 X11 window 代码,GLX 查询 XGetGeometry,Magma 创建 VkXlibSurfaceKHR;而拆分验收/WSL/CI 的平台政策是不打开窗口。Linux-local X11 支持和“Linux client → Android server → Anland”是不同能力,后一个并未打通。(MobileGL/MG_Impl/GLXImpl/GLXImpl.cpp:258–327;MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp:16450–16500;docs/Disaggregated/design/08-runtime-and-platform.md:32)
|
||||
- “surfaceless 平台”也应与 EGL_NO_SURFACE context 区分:backend MakeEGLCurrent 要求注册 surface、draw=read,并拒绝 draw/read 为 EGL_NO_SURFACE 的有效 context bind。因此不能宣称完整 EGL_KHR_surfaceless_context;其广告表也没有该扩展。(MobileGL/MG_Backend/BackendObject.cpp:314–338;MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:465–473)
|
||||
|
||||
### 2.2 Config 与 surface
|
||||
|
||||
Config 是前端合成值:每 display 两个默认 config(stencil=0 和 8),RGBA 各 8、depth 24;surface bits 宣告 WINDOW|PBUFFER|PIXMAP,renderable bits 宣告 OPENGL|ES2|ES3;swap interval 0..4;Linux visual 来自 X11 查询,Android visual ID 是 RGBA8888 AHB format 常量。它们不是由每个 frontend config 对等选择的 vendor config 完整镜像。(MobileGL/MG_State/EGLState/Core.cpp:153–182;DirectGLES 实际另选 native config:MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp:16500–16531、:16593)
|
||||
|
||||
查询还固定返回 EGL_RGB_BUFFER、EGL_CONFIG_CAVEAT=EGL_NONE、EGL_NATIVE_RENDERABLE=TRUE、EGL_SAMPLES/SAMPLE_BUFFERS=0,EGL_CONFORMANT 直接等于 RenderableType;这些广告不补足尚缺的 ES/pixmap 实现。(MobileGL/MG_State/EGLState/Core.cpp:535–599;第 2.2、2.3 节实现证据)
|
||||
|
||||
| Surface / API | 实际路径 |
|
||||
|---|---|
|
||||
| Window / platform window | 创建前端状态后调用 backend CreateEGLWindowSurface;split 经 SurfaceOp。普通模式拒绝空 native window;ServerOwned 可为空,且丢弃客户端窗口 token。(MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:121–204、:718–776) |
|
||||
| Pbuffer | 创建前端状态,随后真调用 backend CreateEGLPbufferSurface;缺省 width/height=1;原生实现见第 3 节。(MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:498–520) |
|
||||
| Pixmap / platform pixmap | frontend 只建 SurfaceObject,EGLImpl 没有配套 backend pixmap 创建;没有 GLX pixmap / DRI pixmap 通路可据此认定。**inferred:**广告 EGL_PIXMAP_BIT 高于当前可证明的原生能力。(MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:580–587、:801–807;MobileGL/MG_State/EGLState/Core.cpp:886–915、:991–1020;MobileGL/MG_Backend/BackendObject.cpp:324–338) |
|
||||
| PbufferFromClientBuffer | 只转给 EGLState 登记,并无对应 backend 导入调用。(MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:571–578;MobileGL/MG_State/EGLState/Core.cpp:922–956) |
|
||||
| BindTexImage / ReleaseTexImage / CopyBuffers | 检查句柄/参数后直接成功,未进行纹理绑定或 native pixmap copy;不是可用的图像共享捷径。(MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:523–568) |
|
||||
|
||||
### 2.3 Context、GLES、sharing 与线程
|
||||
|
||||
eglBindAPI(EGL_OPENGL_ES_API) **返回成功**,EGL_CLIENT_APIS 也写 OpenGL OpenGL_ES;甚至 OPENVG_API 也被接受。CreateContext 只检查 display/config/shareCtx 的存在,存 ClientAPI、version、profile、flags,然后铸造 frontend handle;不会在这里选择 ES 实现或创建原生 share context。(MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:240–245、:414–428、:463–464;MobileGL/MG_State/EGLState/Core.cpp:615–689)
|
||||
|
||||
所以答案是:**有 ES API 接受和 ES2/ES3 config bits,但没有证据可称为完整 GLES provider、或给出一个经确认的 frontend GLES 最大版本。** Espryt 内部确实请求原生 ES 3.2→3.1→3.0,但那是实现 desktop GL 的 backend context,不等于应用请求的独立 GLES context。GL_VERSION 路径依然返回 desktop target;glGetShaderPrecisionFormat 还是 stub。(MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp:16591–16612;MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp:619–626;MobileGL/MG_Impl/GLImpl/Exporting/Definitions.cpp:152)
|
||||
|
||||
前端 EGLState 有多个 context handle、per-thread current/error/API 表、context owner 检查;shareCtx 被存为 SharedContext。然而 GL 状态仍通过全局 pGLContext,active backend 是全局单例,Espryt 只有一套 g_Display/g_Context/g_Surface,Magma 只有全局 pVulkanRenderer。协议 SurfaceOp 没有 CreateContext/DestroyContext/share-group 消息。**inferred:**多个 EGL handle 可创建、context 可在线程间迁移,不等于 N 个独立 GL context 或正确 share-group 隔离;多线程同时发 GL 命令的通用实现不能视为已支持。(MobileGL/MG_State/EGLState/Core.cpp:101–126、:637–641、:1204–1278;MobileGL/MG_State/GLState/Core.h:701;MobileGL/GlobalObjects.cpp:23–24;MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp:16183–16185、:16685;MobileGL/MG_Backend/DirectVulkan/DirectVulkan.cpp:38–39;MobileGL/MG_Remote/Protocol/protocol.fbs:240–258)
|
||||
|
||||
文档明确把多 context 留作未做;INPROC 角色隔离也明确不是给 1494 个 pGLContext 读点加 TLS。服务器 native context 常驻 apply 线程,客户端 ReleaseCurrent 只改变逻辑 live 状态,不真实解绑 native context。(MobileGL/MG_Remote/CONTRACT-P12.md:64;docs/Disaggregated/design/09-build-switches-counters.md:21;MobileGL/MG_Remote/Server/ServerLoop.cpp:330–391)
|
||||
|
||||
### 2.4 EGL extension 广告与真实实现
|
||||
|
||||
完整广告字符串如下,没有隐藏的 dma-buf/fence/damage/buffer-age 附加表:(MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:458–473)
|
||||
|
||||
| QueryString 范围 | 广告 |
|
||||
|---|---|
|
||||
| EGL_NO_DISPLAY | EGL_EXT_client_extensions、EGL_EXT_platform_base、EGL_KHR_platform_base、EGL_MESA_platform_surfaceless |
|
||||
| initialized display | EGL_KHR_create_context、EGL_MESA_platform_surfaceless |
|
||||
|
||||
以下均**未广告**:EGL_EXT_image_dma_buf_import、EGL_EXT_image_dma_buf_import_modifiers、EGL_MESA_image_dma_buf_export、EGL_KHR_fence_sync、EGL_ANDROID_native_fence_sync、EGL_KHR_swap_buffers_with_damage、EGL_EXT_swap_buffers_with_damage、EGL_EXT_buffer_age、EGL_KHR_surfaceless_context。(同上 MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:465–473)
|
||||
|
||||
eglCreateImage 虽有入口,却忽略 attribList,仅保存 target/buffer/context 到 map,不调用 driver 或解析 plane fd/offset/stride/modifier。eglCreateSync 只接受 EGL_SYNC_FENCE,创建时直接标 EGL_SIGNALED;ClientWaitSync 直接返回 EGL_CONDITION_SATISFIED,WaitSync 只验证归属。因此这些入口不能用作 Anland 的 dma-buf import/export 或 explicit sync。include/EGL/eglext.h 中的声明也不能改变这一事实。(MobileGL/MG_State/EGLState/Core.cpp:1336–1359、:1378–1394、:1430–1466;include/EGL/eglext.h:784–829、:1103–1111)
|
||||
|
||||
### 2.5 GLXImpl 是否是 stub
|
||||
|
||||
**不是纯 stub,也不是 Mesa DRI/DRI3 provider。** 它是 MobileGL EGL 上的一层 GLX facade;动态加载 libX11 并解析 XGetGeometry、XGetVisualInfo、XDefaultScreen/Visual、XVisualIDFromVisual、XFree、XSync;按 drawable 建立 EGL surface,swap 前最多每 250ms 查询一次几何并 resize,再调用 EGLImpl::SwapBuffers。没有查到实现 X11 GLX wire rendering、DRI loader driver 或 DRI3/Present buffer 交付的代码。(MobileGL/MG_Impl/GLXImpl/GLXImpl.h:12–17;MobileGL/MG_Impl/GLXImpl/GLXImpl.cpp:129–149、:258–327、:956–965、:1019–1023;后一个“没有”是对本实现及检索的结论。)
|
||||
|
||||
它的 QueryVersion 固定答 GLX 1.4,QueryServerString 复用本地 client string,并未向 X server 查询 GLX 能力。(MobileGL/MG_Impl/GLXImpl/GLXImpl.cpp:543–571)它广告 GLX_ARB_create_context、_no_error、_profile、ARB_get_proc_address,以及 EXT/MESA/SGI swap_control;CreateContextAttribsARB 把版本/profile/flags 翻译为 MobileGL EGL 属性。legacy CreateContext/NewContext 默认请求 3.3 compatibility。GLXWindow 就是输入 XID;draw/read 不同时实际用 draw 同时充当 read,却记录用户 read handle。(MobileGL/MG_Impl/GLXImpl/GLXImpl.cpp:84–86、:785–883、:941–953、:968–979)
|
||||
|
||||
**inferred:**这可作为将来 Linux X11 frontend 的复用起点;对 Anland/Xwayland,需要新增本地 X drawable 的图像提交机制(例如 DRI3/Present,或先用 CPU image copy),不能把 XID 发给 Android 后端当 ANativeWindow,更不能仅把 ServerOwned 打开就得到每个 X 窗口的内容。依据为该 facade、下面 Rule H / native window 路径。
|
||||
|
||||
## 3. Split 模式的 present 路径
|
||||
|
||||
### 3.1 共用调用链
|
||||
|
||||
1. 导出的 eglSwapBuffers → EGLImpl::SwapBuffers,检查 surface,进入 BackendObject_Remote::SwapEGLBuffers。
|
||||
2. Remote 调用 base SwapEGLBuffers,验证当前线程、display、唯一 active surface,再通过 GetBackendFunctions().Present 调用 client emitter;不额外调用 ServerSwapEGLBuffers。
|
||||
3. EmitPresent 先获取 present credit,铸造 FrameSerial,再 EmitAndWait(Present);MGPPresent 本体**只有 FrameSerial**。
|
||||
4. server 解码至 ServerVerbSink::OnPresent → backend table Present();返回后更新 frame serial、报告已完成 GL fences、ReturnPresentCredit。
|
||||
(MobileGL/MG_Impl/EGLImpl/Exporting/Definitions.cpp:112–117;MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:207–228;MobileGL/MG_Remote/Client/BackendObject_Remote.cpp:396–404;MobileGL/MG_Backend/BackendObject.cpp:369–397;MobileGL/MG_Remote/Client/EmitTables.cpp:1165–1188;MobileGL/MG_Pipe/MGPipeTypes.h:1807–1809;MobileGL/MG_Remote/Server/PipeApplier.cpp:388–438)
|
||||
|
||||
没有一条 present 回包包含 image/buffer fd、fence fd、surface id、format、stride、offset 或 modifier。它目前确认服务器本地 Present 已返回,不是“Linux compositor 已经采用或释放某个 buffer”。(上述 MGPPresent / OnPresent;后一语义解释为 **inferred**。)
|
||||
|
||||
### 3.2 三类 surface
|
||||
|
||||
| 模式 | 创建/目标/呈现 |
|
||||
|---|---|
|
||||
| (a) Client-owned native window | Remote 先 ServerSetWindowHandle 再 ServerCreateEGLWindowSurface;每个 EGL forwarder 先等已提交命令 apply,避免跨批次乱序。(MobileGL/MG_Remote/Client/BackendObject_Remote.cpp:178–220)Rule H 永久禁止 peer-window-system-local value 跨进程,不是等 P12 将来补。(MobileGL/MG_Remote/CONTRACT-P6.md:31–45)wire 的 AndroidNativeWindow 和 MetalLayer 被 decoder 拒绝、以 UnmigratedSurface 闩会话。(MobileGL/MG_Remote/Protocol/SurfaceOpCodec.cpp:216–224、:303–314) |
|
||||
| (a) X11/Win32/None 的残留例外 | decoder 仍接受这些 token,UnpackWindowHandle 强转 void*;Linux-local Magma 可用 XID+XOpenDisplay 建 Xlib surface,但 Android build 创建的是 VkAndroidSurfaceKHR。**inferred:**被 decoder 接受不是容器 XID 对 Android 有效,更不是 Anland 集成,存在未封住的窗口种类路径。(MobileGL/MG_Remote/Protocol/SurfaceOpCodec.cpp:124–143、:226–236;MobileGL/MG_Remote/Server/ServerLoop.cpp:1226–1264;MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp:16429–16500) |
|
||||
| (b) MOBILEGL_IPC_SURFACE=server | Remote 不发 SetWindowHandle;WindowKind=ServerOwned,nativeToken=0。服务器从 ServerDisplay 取得窗口租约,替换为本进程 Android WindowHandle,调用同一 backend window 创建;reply 返回实际尺寸。Java SurfaceView 是目标,**不是 Anland wl_surface**。(MobileGL/MG_Remote/Client/BackendObject_Remote.cpp:216–218;MobileGL/MG_Remote/Protocol/SurfaceOpCodec.cpp:160–169;MobileGL/MG_Remote/Server/ServerLoop.cpp:1600–1652;MobileGL/MG_Remote/Server/DisplayServerJni.cpp:11–24) |
|
||||
| (c) Pbuffer / headless | CreatePbufferSurface → SurfaceOp → server backend pbuffer;会话闩为 Offscreen。Espryt 建原生 EGL pbuffer;Magma 创建带尺寸的 windowless renderer,在 Linux 用 VK_EXT_headless_surface,在 Android 无此扩展时使用 AImageReader 的 ANativeWindow 作为不可见 producer target。该 Android fallback 明确“never acquires images”,没有把图像回给 client。(MobileGL/MG_Remote/Client/BackendObject_Remote.cpp:271–288;MobileGL/MG_Remote/Server/ServerLoop.cpp:1361–1381;MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp:16667–16680;MobileGL/MG_Backend/DirectVulkan/BackendObject_DirectVulkan.cpp:378–387;MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp:16344–16410) |
|
||||
|
||||
即使 pbuffer 调用 eglSwapBuffers,也走同一 Present 命令,不是 readback-pixels 的自动交付。真正 EGL_NO_SURFACE 的应用 bind 受第 2 节限制;文档里的“surfaceless”通常描述 headless native display/pbuffer 路线。(MobileGL/MG_Backend/BackendObject.cpp:314–338、:369–397;MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:498–520)
|
||||
|
||||
### 3.3 后端如何拿到 presentation target
|
||||
|
||||
**Espryt / DirectGLES:**窗口来自 backend 的 WindowHandle(ServerOwned 时为租约中的 ANativeWindow),用 vendor EGL 的 eglGetDisplay / eglInitialize / eglBindAPI(ES),创建一个原生 ES context 和 eglCreateWindowSurface;Present 在 native GL 命令流插 GLsync,然后原生 eglSwapBuffers(g_Display,g_Surface),轮询 GLsync 推进资源回收水位。这里不是 EGL native-fence fd。(MobileGL/MG_Remote/Server/ServerLoop.cpp:1623–1635;MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp:16587–16612、:16639–16664、:17252–17290)
|
||||
|
||||
**Magma / DirectVulkan:**InitWindowSurface 将 m_windowHandle.Handle 放入全局 VulkanRenderer;Android CreateSurface 以此 ANativeWindow 调 vkCreateAndroidSurfaceKHR,再 vkCreateSwapchainKHR。Present 提交 VkCommandBuffer,调用 vkQueuePresentKHR,并继续 acquire/重建逻辑;VkFence/VkSemaphore 是该 renderer 内部同步。(MobileGL/MG_Backend/DirectVulkan/BackendObject_DirectVulkan.cpp:359–374;MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp:16429–16435、:14528–14569、:14634–14645;MobileGL/MG_Backend/DirectVulkan/Renderer/SwapchainObject.cpp:284)
|
||||
|
||||
### 3.4 AHB、dma-buf 与 fence fd:现有命中的真正用途
|
||||
|
||||
**未找到产品帧导出路径。** 有 AHB import、有 external-memory 扩展、有 fd passing;用途与“default framebuffer 导出给 client”不同。完整逐命中位置/用途索引见附录 A(主仓库 tracked tree 586 个匹配行、134 个文件;包含文档、历史日志、公共 EGL header,不把 submodule 内上游声明算作 MobileGL 实现)。
|
||||
|
||||
| 命中类别 | 用途与是否可直接用于 Anland present |
|
||||
|---|---|
|
||||
| P11 AdoptT0 | client 分配 **AHARDWAREBUFFER_FORMAT_BLOB**,height=1,usage=CPU read/write + GPU_DATA_BUFFER,持 CPU lock;通过 hop socket 传 handle,server 收到后校验 BLOB 宽度=size。是 persistent GL buffer 的 backing store,**不是颜色图像**。(MobileGL/MG_Remote/Transport/AdoptT0.cpp:35–75、:78–96、:108–125) |
|
||||
| GLES eglGetNativeClientBufferANDROID | 用在 glBufferStorageExternalEXT(nativeClientBuffer),然后 MapBufferRange persistent/coherent。没有把该 AHB 做 EGLImage render target。(MobileGL/MG_Backend/DirectGLES/Managers.cpp:2799–2817、:2835–2857、:2875–2897) |
|
||||
| Vulkan VK_ANDROID_external_memory_android_hardware_buffer | VkBufferManager 将 client 的 AHB BLOB 导入 **VkBuffer**、dedicated VkDeviceMemory,并处理持久映射/生命周期;VulkanRenderer 按条件启用扩展供它用。不是导出 VkImage / swapchain image。(MobileGL/MG_Backend/DirectVulkan/Renderer/VkBufferManager.cpp:631–742;MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp:15348–15362;MobileGL/MG_Backend/DirectVulkan/Renderer/VkBufferObject.h:75–80) |
|
||||
| POST / T0 self-test | server bind 时按允许开关、平台 AHB、后端 import op 和 POST 决定 kCapAdoptT0;失败退 T2。产品 T1 已关闭;显式选择 T1 也退 T2。(MobileGL/MG_Remote/Server/ServerSession.cpp:1092–1143;MobileGL/MG_Remote/CONTRACT-P11.md:233–248) |
|
||||
| extmem_probe 的 external_memory_fd / DMA_BUF / SCM_RIGHTS | 独立探针测试 T1 host-visible buffer fd 导出、T0 AHB BLOB 导入、T3 host memory。它确实有 vkGetMemoryFdKHR 与跨进程读写,但不是 renderer 的逐帧图像输出。(tools/spikes/extmem_probe/README.md:23–60;tools/spikes/extmem_probe/extmem_probe.cpp:8–20、:1718–1773、:2182–2188、:2356–2378、:3590–3664) |
|
||||
| AImageReader / AHARDWAREBUFFER_USAGE_GPU_COLOR_OUTPUT | integration、CTS、piglit harness 创建 Android 测试窗口;Magma headless fallback 也使用 AImageReader window,但未 acquire 导出图像。(MobileGL/MG_IntegrationTest/Harness/HeadlessGL.cpp:102;tools/cts/platform/tcuMobileGLPlatform.cpp:129–130;tools/cts/probe/mgprobe.c:158–159;tools/piglit-android/patches/waffle-mobilegl-android.patch:277–278;MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp:16355–16390) |
|
||||
| SCM_RIGHTS 产品实现 | 共享段和门铃交付、supervisor 数据连接 handoff,以及 T0 的 hop;详见第 4 节。没有定义 FrameReady(bufferFd,fenceFd) 消息。(MobileGL/MG_Remote/Transport/FdPassing.cpp:108–149;MobileGL/MG_Remote/Client/ClientSession.cpp:1186–1251;MobileGL/MG_Remote/CONTRACT-P11.md:257) |
|
||||
| include/EGL/eglext.h | Khronos 公共声明:AHB native client buffer、dma-buf import/modifiers/export。只有声明,不是 MobileGL 功能。(include/EGL/eglext.h:517–520、:784–829、:1103–1111) |
|
||||
| 历史日志 | vendor Vulkan extension 枚举及运行诊断;证明该次 driver 暴露了名字,不证明 MobileGL 调用该扩展输出帧。逐行出处见附录 A。 |
|
||||
|
||||
对主仓库 tracked tree 的指定精确子串检索中,**sync_file 和 SYNC_FD 无命中**;另外检索未找到产品 vkGetSemaphoreFdKHR / eglDupNativeFenceFDANDROID 调用。EGL_ANDROID_native_fence_sync 未广告,前端 EGL sync 只是状态对象;GLsync / 完成水位也不是可交给 zwp_linux_explicit_synchronization_v1 的 sync_file fd。(检索范围见附录 A;MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:465–473;MobileGL/MG_State/EGLState/Core.cpp:1336–1394;MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp:17252–17283)
|
||||
|
||||
**inferred:**Anland 需要新增 image 路线,不能把 P11 BLOB 改个名字就用。最直接候选是 server 分配/导入可渲染 AHB image(GLES:EGLImage+FBO;Vulkan:external-memory VkImage),输出单平面图像描述及真实同步;也可改造 AImageReader 为实际 acquire/release 的 buffer 消费链。必须验证四字符格式、stride/offset、LINEAR/INVALID modifier 以及 AHB/gralloc native handle 与普通 dma-buf 的可转换性,不能把 opaque fd 或 AHB 多 fd handle 默认当成 Anland 可导入的线性 ARGB/XRGB。依据:当前 BLOB/import 代码与题目给定 Anland buffer 限制;历史探针甚至在 Adreno/Mali 两台上都没得到 T1-dma-buf 导出(docs/Disaggregated/notes/p0/p0-device-findings.md:18–27),但该 buffer 探针也不能证明所有 image 路线必然失败。
|
||||
|
||||
## 4. Fd passing、transport 与 SELinux
|
||||
|
||||
### 4.1 今天实际可用的组合
|
||||
|
||||
| 拓扑/端点 | 实际数据面 | fd 能力 |
|
||||
|---|---|---|
|
||||
| inproc | 同进程共享段/双角色 | InProcessTransport 复制描述符给 peer,模拟所有权;不是跨 Android 安全域方案。(MobileGL/MG_Remote/Transport/InProcessTransport.cpp:200;docs/Disaggregated/guide/build-and-run.md:20–22) |
|
||||
| spawn + fork | ShmLink | launch server 后连接本机 AF_UNIX;四段+三个门铃经 aux fd passing。配置只收 auto/shm。(MobileGL/MG_Remote/Client/ClientSession.cpp:954–1005、:1186–1251) |
|
||||
| spawn + unix:path / @abstract | ShmLink | control 与 aux 配对;ShareFd/ReceiveFd 在 aux 上 SCM_RIGHTS。(MobileGL/MG_Remote/Client/ClientSession.cpp:928–950;MobileGL/MG_Remote/Transport/SocketTransport.cpp:849–868) |
|
||||
| spawn + fd:control,aux | ShmLink | P11 B1 已连接的两根 AF_UNIX SOCK_STREAM socket;可由 Android helper/broker 交接。只收 auto/shm。(MobileGL/MG_Remote/CONTRACT-P11.md:110–125;MobileGL/MG_Remote/Client/ClientSession.cpp:877–924) |
|
||||
| spawn + tcp://host:port | StreamLink | **不传 fd**。SocketTransport::ShareFd/ReceiveFd 对 m_tcp 返回 UNSUPPORTED;client 只接 auto/stream。(MobileGL/MG_Remote/Transport/SocketTransport.cpp:849–868;MobileGL/MG_Remote/Client/ClientSession.cpp:928–950、:1025–1026) |
|
||||
| TCP control + shm data | 设计过,**当前未接线** | design/06 描述的 ShmLink 独立 AF_UNIX rendezvous 是第二波设计;同文件最后明确第一波仅 TCP+stream。当前上层按 IsTcp 选数据面并拒绝混搭,不能按愿景回答已经支持。(docs/Disaggregated/design/06-transport.md:54–67;MobileGL/MG_Remote/Client/ClientSession.cpp:928–936、:1025–1026) |
|
||||
|
||||
“控制面不传 fd”作为协议层概念成立:SCM_RIGHTS 不塞进 FlatBuffers 控制字节流。但当前实现的 **ITransport 接口仍保留 ShareFd / ReceiveFd**,由 SocketTransport 的 aux socket 实现;并非代码已经完全迁到 ShmLink 自有交付 API。新实现应尊重实际的 ITransport/aux 接口,而不是仅照旧契约措辞接线。(MobileGL/MG_Remote/Transport/ITransport.h:87–108;MobileGL/MG_Remote/Transport/SocketTransport.cpp:849–868;对照 MobileGL/MG_Remote/CONTRACT-P6.md:636–648)
|
||||
|
||||
### 4.2 “每帧 server → client buffer fd + fence fd”有多少现成基础
|
||||
|
||||
基础发送已是**双向**接口;server 现在就把共享段 fd 发给 client。SendFd 的 ancillary buffer 只放一个 int;ReceiveFd 虽收集至多四个以便关闭多余 fd,随后明确要求 receivedCount==1。sideband 最大 256 字节。不能原样把“两 fd”塞进一次现有消息。(MobileGL/MG_Remote/Transport/ITransport.h:89–108;MobileGL/MG_Remote/Transport/FdPassing.h:36–38、:48–73;MobileGL/MG_Remote/Transport/FdPassing.cpp:131–149、:253–267、:289–301;MobileGL/MG_Remote/Client/ClientSession.cpp:1194–1217)
|
||||
|
||||
**inferred:fd 搬运本身是局部扩展,完整呈现协议是显著工作。** 可选择两个带相同 frame/buffer serial、不同 fd-kind 的单 fd offer,或定义版本化 multi-fd packet;更有效的是 buffer pool 首次注册发 buffer fd,之后每次 present 仅发 buffer id + acquire fence。需要同时实现:
|
||||
|
||||
1. session/surface/buffer/generation/frame 关联、format/plane metadata、协商和协议修订;
|
||||
2. client 持续接收 server aux offer 的 dispatcher,不能只在握手读取 7 个 fd;与已有 T0 aux 用途协调;
|
||||
3. fence=-1 / 无 fence 情况、重复/陈旧/中断消息及 fd 关闭规则;
|
||||
4. buffer release / release fence 的反向通道,在 compositor 未释放前禁止复用;
|
||||
5. 有界发送和背压,避免 apply 线程在 client 不读 fd 时永久阻塞;
|
||||
6. StreamLink 没有本地 fd 传递的 fallback:如同机额外 AF_UNIX,或显式像素传输模式。
|
||||
|
||||
这些是设计建议,不是现有功能。依据:一次一个 fd、有限 sideband、仅 serial 的 Present、T0 offer 协议及当前单独的阶段性接收逻辑。(MobileGL/MG_Remote/Transport/FdPassing.h:36–73;MobileGL/MG_Remote/Client/ClientSession.cpp:1186–1251;MobileGL/MG_Remote/CONTRACT-P11.md:257;MobileGL/MG_Pipe/MGPipeTypes.h:1807–1809;MobileGL/MG_Remote/Transport/SocketTransport.cpp:849–868)
|
||||
|
||||
### 4.3 谁创建共享段:文档 owner 不等于 allocation owner
|
||||
|
||||
**当前跨进程产品代码由 server 创建全部四段**:
|
||||
|
||||
- ServerSession::Accept 的非 stream 分支调用 Memory().Create(sizes, MemoryRole::Server)。
|
||||
- SessionSegments::Create 枚举 mgl-cmd、mgl-stage、mgl-reply、mgl-event,并逐个 ShmSegment::Create / Map。
|
||||
- client 收 7 个 fd(4 段+3 门铃),再 AdoptFromDescriptors(..., MemoryRole::Client)。
|
||||
|
||||
(MobileGL/MG_Remote/Server/ServerSession.cpp:713–737;MobileGL/MG_Remote/Transport/ShmSegment.cpp:236–284;MobileGL/MG_Remote/Client/ClientSession.cpp:1186–1251)
|
||||
|
||||
设计表把 SEG_CMD/SEG_STAGE “拥有者”写 client,适合解释写者/语义归属,**不能用于证明 fd 是 root container client 创建的**。Linux 的 ShmSegment::Create 用 raw memfd_create syscall + ftruncate,失败退 shm_open+立即 unlink;Android 用 ASharedMemory_create。若 server 是 Android app,其握手段走 Android 创建分支,而非 Linux client 的 memfd 分支。(docs/Disaggregated/design/06-transport.md:9–17;MobileGL/MG_Remote/Transport/ShmSegmentPosix.cpp:51–109;上段调用点)
|
||||
|
||||
StreamLink 用私有段传字节,本地 memfd/存储并不以 fd 共享给对端;这与 ShmLink 的跨进程共享不同。(docs/Disaggregated/design/06-transport.md:17、:59;MobileGL/MG_Remote/Server/ServerSession.cpp:713–737)
|
||||
|
||||
**inferred:**因此题目担心的“Android untrusted_app 使用 root-client 创建的 CMD/STAGE fd”不是当前握手路径的准确模型;真正需要验证的是 root/container 域接收和映射 app-origin fds、AF_UNIX connectto/namespace 可达性,以及今后客户端返回 release fence 的 fd use。P11 T0 确实是相反方向的 client-origin AHB,但 glibc client 没有该 Android AHB allocator,不能自动享有 T0;可先明确选择 T2。(MobileGL/MG_Remote/Transport/AdoptT0.cpp:35–54;MobileGL/MG_Remote/Transport/AdoptT0.h:56–61;MobileGL/MG_Remote/CONTRACT-P11.md:233–248)
|
||||
|
||||
历史 SELinux 测量:shell 和另一个 untrusted_app 连 server 的 abstract unix socket 被 connectto 拒;root relay 打通连接后,另一 app mmap server 创建的段可用。B1 因而实现令牌 broker + app_process helper + Binder PFD 交接,helper exec 外部程序并设置 fd: 端点。**该证据不是 Droidspaces root glibc/chroot 域的测试结论**,不能承诺所有 ROM 或 root 策略都允许。(docs/Disaggregated/notes/p11/B0-CROSS-APP.md:3–15;MobileGL/MG_Remote/CONTRACT-P11.md:110–125、:195–197)
|
||||
|
||||
还有部署限制:目前 broker 只认离屏 MobileGLServerService,显示 Activity :mglwin 在跑时也可答 server-not-running;它不是 P12 onscreen server 的通用 broker。(MobileGL/MG_Remote/CONTRACT-P11.md:147)
|
||||
|
||||
## 5. Session / 多 client / 多窗口限制
|
||||
|
||||
### 5.1 哪些是宿主管理策略,哪些深入进程状态
|
||||
|
||||
| 限制 | 所在层与深度 |
|
||||
|---|---|
|
||||
| “同设备一个 server” | P12 APK 产品策略:DisplayActivity 启动会 stopService;Service 启动会结束显示 server。不是 kernel / wire 全设备唯一锁。(MobileGL/MG_Remote/CONTRACT-P12.md:46;android-plugin/app/src/main/java/top/mobilegl/plugin/MobileGLDisplayActivity.java:119;android-plugin/app/src/main/java/top/mobilegl/plugin/MobileGLServerService.java:85–103、:139) |
|
||||
| 这个口号已有例外 | B1 在主监听为 TCP 时另起一个私有 UNIX broker supervisor。两者是独立 process/supervisor;所以不能把“一个 device 最多一个 session”当已严格执行的全局不变量。**inferred:**不同 supervisor 各自的 Busy 不互相协调。(android-plugin/app/src/main/java/top/mobilegl/plugin/MobileGLServerService.java:147–162;MobileGL/MG_Remote/CONTRACT-P11.md:113;MobileGL/MG_Remote/Server/ServerMain.cpp:1222、:1363、:1548) |
|
||||
| 每 supervisor 一个 active session | TCP authenticated second Hello → Refuse Busy;UNIX/thread/fork 路线也做 Busy。单个慢启动但已配对 client 可占槽;很晚才发 Hello 的第二个 client 可能只看见发送失败。(MobileGL/MG_Remote/Server/ServerMain.cpp:915、:1222–1260、:1363、:1548–1565;MobileGL/MG_Remote/CONTRACT-P11.md:130) |
|
||||
| Offscreen fork-per-session | Service exec libMobileGLServer.so endpoint --serve;每 session 子进程 fork,并设 PR_SET_PDEATHSIG 随 supervisor 退出。它本来具备进程隔离结构,但调度仍串行。(android-plugin/app/src/main/java/top/mobilegl/plugin/MobileGLServerService.java:180–188;MobileGL/MG_Remote/Server/ServerMain.cpp:317、:1240、:1553;MobileGL/MG_Remote/CONTRACT-P12.md:45) |
|
||||
| Onscreen 串行进程内 session | Activity 的 :mglwin 持 SurfaceView,server 用 Handoff::Thread;backend 按进程钉住,首次 session 可决定类型,之后不能换另一 backend。会话间重置 latch / 清 backend 状态。(MobileGL/MG_Remote/CONTRACT-P12.md:44;MobileGL/MG_Remote/Server/ServerMain.cpp:520–542、:1623;docs/Disaggregated/notes/p12/INTEGRATOR-DECISIONS-P12.md:10–14) |
|
||||
| 一会话一个 surface mode | 首次成功 pbuffer → Offscreen;ServerOwned → OnScreen。另一类返回 SurfaceModeMismatch,拒绝不等于杀 session。X11/Win32/None 残留路径不闩模式,是未收紧的例外。(MobileGL/MG_Remote/CONTRACT-P12.md:17、:23;MobileGL/MG_Remote/Server/ServerLoop.cpp:1361–1381、:1539–1543、:1606–1614) |
|
||||
| ServerOwned 只有一个实际窗口 | 多个 surface token 可以存在,但都指 server 的同一窗口;一个 extent 应用到全部。不是 M 个独立窗口。(docs/Disaggregated/notes/p12/INTEGRATOR-DECISIONS-P12.md:16;MobileGL/MG_Remote/Server/ServerLoop.cpp:1627–1648;MobileGL/MG_Remote/Client/ClientSession.cpp:449–463) |
|
||||
| Session 单例 | ServerSession::Active 是一个进程全局 atomic 指针,ServerSessionInstance / ClientSessionInstance 为单例;segment resolver 也明确全进程唯一,反向 callback 表为全局。(MobileGL/MG_Remote/Server/ServerSession.cpp:527–543、:832–857;MobileGL/MG_Remote/Client/ClientSession.cpp:616–619;MobileGL/MG_Pipe/MGPipeCallbacks.h:76–77) |
|
||||
| Backend / frontend 单例 | pGLContext、pActiveBackendObject、global function table;Espryt g_Display/g_Context/g_Surface;Magma pVulkanRenderer。切换 surface 会替换 renderer/运行时状态,不是独立 per-window/context renderer 集合。(MobileGL/MG_State/GLState/Core.h:701;MobileGL/GlobalObjects.cpp:23–24;MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp:16183–16185;MobileGL/MG_Backend/DirectVulkan/DirectVulkan.cpp:38–39;MobileGL/MG_Backend/DirectVulkan/BackendObject_DirectVulkan.cpp:359–387) |
|
||||
| 热路径缺乏多窗口身份 | Present 只有 FrameSerial;MGPSurfaceInfo 只有尺寸/格式/samples/layers/default 标记,没有 surface id。当前依赖 session 当前绑定目标,无法直接表达并行多窗口完成/释放。(MobileGL/MG_Pipe/MGPipeTypes.h:1807–1809、:1999–2005) |
|
||||
|
||||
### 5.2 要服务 N clients × M windows,需要什么
|
||||
|
||||
以下均为 **inferred**,基于上表结构:
|
||||
|
||||
- **N 个 client 最小方案:每 client 一个 worker process。** 扩展 offscreen supervisor 为多 child/session registry、把控制/数据配对、认证、额度、日志、退出清理路由到对应 worker;这样可以暂时保留大量 backend process-global 状态。仅删一个 Busy 判断不够,当前 child/session handoff 和 Active 指针模型必须保持隔离。(基础:MobileGL/MG_Remote/Server/ServerMain.cpp:915、:1222–1260;MobileGL/MG_Remote/Server/ServerSession.cpp:527–543)
|
||||
- **同一进程并发 N sessions** 则要 session 化 active backend、resolver、callback 表、latch、caps、backend resource/cache 全局,或完整线程/对象归属隔离;目前 P12 的结束清理只服务串行重用。(基础:MobileGL/MG_Remote/Server/ServerSession.cpp:832–857;MobileGL/MG_Pipe/MGPipeCallbacks.h:76–77;docs/Disaggregated/notes/p12/INTEGRATOR-DECISIONS-P12.md:12–14)
|
||||
- **单 client 的 M windows** 要有每 surface 独立 framebuffer / image pool、尺寸世代、swap interval / credits、present/release identity;修改 active-surface backend 生命周期,避免换窗即丢弃该进程唯一 renderer。共享 GL 资源不能粗暴一窗口一进程来保证,还要真实 context/share-group。(基础:MobileGL/MG_Backend/DirectVulkan/BackendObject_DirectVulkan.cpp:359–387;MobileGL/MG_Backend/BackendObject.cpp:314–338;MobileGL/MG_Pipe/MGPipeTypes.h:1807–1809、:1999–2005)
|
||||
- **Xwayland glamor** 应单独当系统级 EGL/GLES/图像共享消费者验证;应用 GLX facade 可用并不能保证 glamor 所需 EGLImage、dma-buf import/export、同步和 renderer 资源互通。可以先让 Xwayland 保持其他渲染/软件路径,仅给选定 GL 应用使用 MobileGL;这属于分阶段部署选择,不是现成配置承诺。(基础:第 2 节 image/sync/config 和 GLX 证据;Anland/Xwayland 场景取自题目。)
|
||||
|
||||
## 6. 窗口系统事件、几何、失效与 pacing
|
||||
|
||||
### 6.1 现有协议能表达什么
|
||||
|
||||
SurfaceOpKind 完整列表为 InitializeDisplay、CreateWindowSurface、CreatePbufferSurface、ResizeWindowSurface、ReleaseSurface、MakeCurrent、ReleaseCurrent、SetSwapInterval、ReleaseResources、SetWindowHandle、InitCapabilities(另有 None)。它有 seq/display/surface/windowKind/nativeToken/width/height/swapInterval/readSurface/context;没有 Wayland object、DRM format/modifier、damage region 或 buffer release。(MobileGL/MG_Remote/Protocol/protocol.fbs:240–305)
|
||||
|
||||
WindowKind 为 None=0、AndroidNativeWindow=1、X11=2、Win32Hwnd=3、Surfaceless=4、Pbuffer=5、MetalLayer=6、ServerOwned=7;**没有 Wayland/GBM**。ServerOwned 只合法于 CreateWindowSurface,token 必须 0。(MobileGL/MG_Remote/Protocol/protocol.fbs:261–276;MobileGL/MG_Remote/Protocol/SurfaceOpCodec.cpp:199–214)
|
||||
|
||||
SurfaceReply 含 seq/ok/EGL version/eventHead/width/height/refusal;defaultFb schema 字段还在,但 encoder 固定传 0,实际 framebuffer 几何通过 kEventSurfaceChanged。eventHead 保证更早的数据面事件先于 reply 被观察。(MobileGL/MG_Remote/Protocol/protocol.fbs:308–323;MobileGL/MG_Remote/Protocol/SurfaceOpCodec.cpp:242–260)
|
||||
|
||||
ServerOwned 的 resize 为 Java SurfaceHolder.setFixedSize / setSizeFromLayout 请求,窗口实际尺寸经 reply/event 返回;Activity 做等比 letterbox。kEventSurfaceChanged 带 Width/Height/InternalFormat/Samples/Layers/IsDefault,client 更新默认 framebuffer 和所有 ServerOwned surface extent。没有 frame callback、presentation timestamp 或 input forwarding。(MobileGL/MG_Remote/CONTRACT-P12.md:31–35、:64;MobileGL/MG_Remote/Server/DisplayServerJni.cpp:27–34;MobileGL/MG_Remote/Client/ClientSession.cpp:449–463;MobileGL/MG_Pipe/MGPipeTypes.h:1999–2005)
|
||||
|
||||
SurfaceProgress 是冷启动 SurfaceOp 心跳,不是“该帧可显示”的事件。P10 的 kEventFenceSignaled 是逻辑 GL fence 完成报告,不是 sync_file fd。(MobileGL/MG_Remote/Protocol/protocol.fbs:390–398;docs/Disaggregated/ROADMAP.md:38;MobileGL/MG_Remote/Server/PipeApplier.cpp:433–438)
|
||||
|
||||
### 6.2 device-lost:文档承诺与代码差异
|
||||
|
||||
现有 peer hangup 设置 ClientSession::m_deviceLost,一次日志后后续 wire verbs DECLINED;不自动 respawn。窗口被撤销时,先在 apply 线程释放 backend surface,再 Fatal ServerWindowLost,最后归还 lease;Detach 有界 3 秒。纯等待超时不应被当成 peer 死亡,但仍有自己的 Fatal timeout 失败家族。(MobileGL/MG_Remote/Client/ClientSession.cpp:595–613;MobileGL/MG_Remote/CONTRACT-P12.md:27–40;MobileGL/MG_Remote/Client/ClientSession.cpp:2432–2438)
|
||||
|
||||
**不能照抄“eglSwapBuffers 返回 EGL_CONTEXT_LOST”为当前已实现行为。** design/08:33 确实这样写,但实际 EGLImpl swap 只有 validation/backend false 时 SetError(EGL_BAD_SURFACE),成功则 TRUE;base 调 void Present() 后返回 true,Remote 直接复用 base。检索产品代码中 EGL_CONTEXT_LOST 仅见 enum-to-string,未见 lost→EGL error 映射。因此:GL reset/device-lost 机制存在,EGL swap 的标准错误映射有缺口;**inferred:**死亡后某些调用可仍沿现有 Bool 路径成功,具体时序未运行验证。(docs/Disaggregated/design/08-runtime-and-platform.md:33;MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:207–228;MobileGL/MG_Backend/BackendObject.cpp:390–397;MobileGL/MG_Remote/Client/BackendObject_Remote.cpp:396–404;MobileGL/MG_Util/Converters/EGLToStr/EGLEnumConverter.cpp:77)
|
||||
|
||||
### 6.3 Present credit 与 compositor 怎样接
|
||||
|
||||
MOBILEGL_IPC_PRESENT_CREDIT 默认 1、范围 1..8;client 在编码 present **之前**等待 serial-credit 的 presentAckSerial。server 在 backend Present() 返回之后还 credit。它限制命令执行/本地 swap 的 run-ahead,独立于 CMD/STAGE 字节 credit。(docs/Disaggregated/design/08-runtime-and-platform.md:7–8;MobileGL/MG_Remote/Client/ClientSession.cpp:2385–2438;MobileGL/MG_Remote/Client/EmitTables.cpp:1165–1181;MobileGL/MG_Remote/Server/PipeApplier.cpp:426–438)
|
||||
|
||||
文档 design/08 仍称 credit>1 未测,但后来的 P12 跨机验收已测 1/2/3;报告应以后者为准,不能把它写成仍完全未知。(docs/Disaggregated/design/08-runtime-and-platform.md:8;docs/Disaggregated/notes/p12/CROSSHOST-ACCEPTANCE.md:16、:23–34)
|
||||
|
||||
**inferred:接 Anland 至少要分开三种事件。**
|
||||
|
||||
| 事件 | 建议接线 / 不可混用的语义 |
|
||||
|---|---|
|
||||
| GPU frame ready | server 输出 image identity + acquire fence;client 可将 fd 交给 Wayland explicit synchronization。不能用现有 presentAckSerial 冒充 GPU fence。(基础:MobileGL/MG_Remote/Server/PipeApplier.cpp:426–438;题目给定 explicit sync) |
|
||||
| compositor frame callback | 用于允许/建议下一帧节奏;可控制 frontend swap pacing、有限 credit 或单独 queue-depth。不能证明旧 buffer 已可重写。(基础:当前 credit 返回条件同上;新 compositor 语义为集成设计推断) |
|
||||
| wl_buffer.release / explicit release fence | 发回 server 的 BufferReleased(surface,buffer,generation[,fence]),决定 image pool 的复用。多窗口要每窗/每池计数,不能只用全会话一个 frame serial。(基础:MobileGL/MG_Pipe/MGPipeTypes.h:1807–1809、:1999–2005;题目给定 Anland buffer 路线) |
|
||||
|
||||
还需让隐藏/最小化/长期无 frame callback 的窗口不会触发现有“credit 长期不还→PresentCreditTimeout”而丢会话;必须定义暂停、丢帧、buffer pool 耗尽和断连回收规则。这是 **inferred** 的协议设计需求,不是现有行为。(MobileGL/MG_Remote/Client/ClientSession.cpp:2432–2438;MobileGL/MG_Remote/CONTRACT-P12.md:64)
|
||||
|
||||
## 7. 通用 Linux 桌面 GL 覆盖:一张短表
|
||||
|
||||
| 能力 | Espryt / DirectGLES | Magma / DirectVulkan | 对 Linux 应用的含义 |
|
||||
|---|---|---|---|
|
||||
| 最大报告/目标 GL、GLSL | 4.6.0 / 4.6.0,静态 core identity。(MobileGL/MG_Backend/DirectGLES/BackendObject_DirectGLES.cpp:817–822) | 同为 4.6.0,静态 core identity。(MobileGL/MG_Backend/DirectVulkan/BackendObject_DirectVulkan.cpp:546–551) | 是广告/目标,不是完整一致性认证;README 仍写 4.2 Core 目标。(README.md:49–56) |
|
||||
| Compatibility / fixed function | 两者共用前端:compat profile 属性可保存并用于宽松语义,但不是完整 legacy pipeline。导出/lookup 未找到核心 glBegin/glEnd、glMatrixMode、glLightfv、glMaterialfv、glNewList、glDrawPixels 的真实链;一些 EXT matrix 名只是扩展符号表存在。 | 同左 | 无法承诺旧 GL1.x/2.x fixed-function 桌面程序。依据:MobileGL/MG_State/GLState/Core.h:703–708;MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp:2426;MobileGL/MG_Impl/GetProcAddress.cpp:896–910、:1406–1407;MobileGL/MG_Impl/GLImpl/Exporting/Definitions.cpp:26–35;“无法承诺”为 **inferred**。 |
|
||||
| GLES contexts | frontend BindAPI(ES) 接受;backend 内部 ES3.2→3.0 negotiation。 | frontend 同样接受 ES;backend 是 Vulkan。 | 没有完整 GLES profile/version 保证;GL_VERSION 不切 ES,GetShaderPrecisionFormat stub。(MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:414–428;MobileGL/MG_Backend/DirectGLES/DirectGLES.cpp:16595–16612;MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp:619–626;MobileGL/MG_Impl/GLImpl/Exporting/Definitions.cpp:152) |
|
||||
| GLX_ARB_create_context | 共用 Linux GLX facade;广告并将版本/profile 转到 EGL。(MobileGL/MG_Impl/GLXImpl/GLXImpl.cpp:84–86、:818–883) | 同左 | 入口可用≠完整 share group / DRI3 / Xwayland present。(第 2、5 节证据;判断为 **inferred**。) |
|
||||
| 已知非游戏专属缺口 | DebugMessageControl/Callback/GetDebugMessageLog、若干 robustness/GetnUniform 等导出仍 stub;EGL image/sync 属于状态壳。 | 同样共用前端 | 会影响调试、robustness、图像互通和 compositor 消费者。(MobileGL/MG_Impl/GLImpl/Exporting/Definitions.cpp:397–429;MobileGL/MG_State/EGLState/Core.cpp:1336–1466;影响判断为 **inferred**。) |
|
||||
| docs 记录的未完项 | fp64 server 广告/client 编译配置不一致;driver-written texture 拒读仍可变 session Fatal;多 context 未做。 | 有 malformed indirect fixture 丢设备、设备对齐约束及 monolith 特有债。 | 应以真实目标应用/GL CTS 子集验收,不能用 Minecraft 或 trace 成功覆盖全部 desktop workloads。(docs/Disaggregated/notes/DEBTS.md:14、:22、:25–28、:42;验收建议为 **inferred**。) |
|
||||
|
||||
这里的固定功能否定基于实际入口/前端检索,不把“IsCompatibilityProfile=false”单独当证明;相反,EGL/GLX 的 compatibility 请求和 getter 确实存在,必须与完整功能实现区分。(MobileGL/MG_Impl/GLXImpl/GLXImpl.cpp:794–812;MobileGL/MG_State/EGLState/Core.cpp:657–659;MobileGL/MG_Impl/GLImpl/Getter/GL_Getter.cpp:2426)
|
||||
|
||||
## 8. 文档是否已预见 Linux-on-Android / Wayland / AHB / 多 client / Termux
|
||||
|
||||
以下为原文节录。保留“历史设计”与“当前实现”的区别,不把旧推测当新验收。
|
||||
|
||||
| 主题 | 原文与出处 | 如何解读 |
|
||||
|---|---|---|
|
||||
| 容器 Linux / Termux | “**B 容器类 guest(DroidSpace / Winlator / Termux,共享内核)** … AF_UNIX … 同上(含 AHardwareBuffer_sendHandleToUnixSocket,API 26) … **整套 P6 机制逐字可用**。”(docs/Disaggregated/notes/p6/P6-ENDSTATE-REVIEW.md:138) | 同内核 transport 的历史论证;并非 Anland WSI 或 glibc AHB API 验收。 |
|
||||
| 后来场景变更 | “**形态 B 不再是操作性场景;终局是 D,P6.5 在关键路径上。**”(docs/Disaggregated/notes/p6/P6-ENDSTATE-REVIEW.md:142) | 不能据历史容器表声称已为 Anland 交付。 |
|
||||
| Linux client 范围 | “**默认先 Linux + Android(现有 CI 能验),Windows client 第二批 … macOS 仍不拆分。**”(docs/Disaggregated/notes/OPEN-QUESTIONS.md:28) | Linux client 是明确目标,但无 aarch64 glibc 专项验收。 |
|
||||
| Wayland | “**Linux / WSL / CI 永不开窗(EGL_PLATFORM=surfaceless);Wayland 不支持。**”(docs/Disaggregated/design/08-runtime-and-platform.md:32) | 当前声明不支持;本次也没有查到 Wayland frontend/present 实现。 |
|
||||
| 历史 X11 设想 | “**Window 是 XID,nativeToken:u64 直接送。backend 自己 XOpenDisplay(getenv(\"DISPLAY\")) 并构造 VkXlibSurfaceCreateInfoKHR … Wayland 今天不支持 … 维持。**”(docs/Disaggregated/notes/recovered/wf1/final/part3.md:80) | 是同 X server 的 XID 设想,不能移植成 Android ANativeWindow token。 |
|
||||
| T0 与 T1 | “**T0 = client 分配 AHardwareBuffer、server 导入;T1 = server 导出 opaque fd;T2 = 拒绝,client 保留 shadow 并推送。**”(MobileGL/MG_Remote/CONTRACT-P11.md:3) | 全部处于 persistent-map store 议题;不是 frames。T1 当前关闭见 :239。 |
|
||||
| AHB 帧输出方案曾被讨论 | “**Child renders into AHardwareBuffers, sends them over a unix socket, app presents.**” 并明确需 “**a new buffer-ring/fence protocol, an Espryt default-framebuffer-to-AHB FBO, Magma AHB import**”。(docs/Disaggregated/notes/p12/map-apk-process.md:87–90;另见 docs/Disaggregated/notes/p12/map-docs-contract.md:103、docs/Disaggregated/notes/p12/map-server-surface.md:113) | 这是 P12 调研中的备选方案,确实预见了帧 AHB 交付;并未落地为当前 present 路径。 |
|
||||
| P12 为何没有交付该方案 | “**in-process server … renders straight into its SurfaceView; sessions run sequentially in that process. (Not fork + AHB.)**”(docs/Disaggregated/notes/p12/BRIEF-onscreen.md:14–15) | 最终范围明确选服务器进程内 SurfaceView,放弃这一阶段的 fork+AHB 帧桥。 |
|
||||
| dma-buf 历史设想 | “**T0 — server 导入 client 分配:client 分配 AHardwareBuffer/dma-buf … 理想但可用性未知。**”(docs/Disaggregated/notes/recovered/wf1/final/part2.md:172) | 旧设计;落地是 AHB BLOB T0。 |
|
||||
| Export 的实际局限 | “**T1-dma-buf … UNSUPPORTED**”两台设备;“**Tier decision for P11 (persistent maps across the process boundary)** … T0 … BLOB。”(docs/Disaggregated/notes/p0/p0-device-findings.md:21、:27) | 不要将 persistent VkBuffer opaque-fd 成功解释为线性 frame dma-buf 成功。 |
|
||||
| Termux 消费者 | “**消费者:同一台手机上从另一个 app(Termux、adb shell)启动、没有 Java Context 的原生 GL 程序。**”(MobileGL/MG_Remote/CONTRACT-P11.md:104) | 已落地 helper/broker/fd: 路线的真实目标;历史验收用 retrace/shell/第二 APK,非真实 Termux glibc 图形桌面。 |
|
||||
| 跨 app 限制 | “**SELinux 挡的是连接这一步。** … 一旦连上 … 现有代码就走 SharedSegments … **缺的是跨上下文的连接中介。**”(docs/Disaggregated/notes/p11/B0-CROSS-APP.md:7) | 之后 B1 已实现中介;root container 仍是不同待验证安全域。 |
|
||||
| 多 session / context | “**DirectGLES g_Display / g_Surface / g_Context 仍是全局 … 多 context;server 窗口不转发输入**”,状态为“**等出现第二个会话 / 第二个 context 的需求**”。(docs/Disaggregated/notes/DEBTS.md:42) | 明确尚未进入通用桌面多上下文阶段。 |
|
||||
| 唯一会话 / Busy | “**同时只服务一个会话,第二个连接 Refuse{Busy}**。”(docs/Disaggregated/design/08-runtime-and-platform.md:17) | 精确实施范围是每个 supervisor;B1 双 supervisor 例外见第 5 节。 |
|
||||
| 跨机 client | “**client 是 trace 重放器,不是活的 Minecraft 实例**。”(docs/Disaggregated/notes/p12/CROSSHOST-ACCEPTANCE.md:11) | 更不能扩大成已经验证任意 Linux desktop app。 |
|
||||
|
||||
本次对 docs、notes、contracts 检索未找到 “Anland” 的专项实施方案;也未找到“导出 framebuffer AHB/dma-buf 给 Wayland client”的已落地设计。P12 调研**确实提出过 AHB frame bridge**,列明 buffer-ring/fence、GLES FBO、Magma AHB import 等新增工作;最终 brief 明确选择进程内 SurfaceView,未选择 fork+AHB。P11 则另行落地 persistent-buffer T0。这三件事应分开阅读。(docs/Disaggregated/notes/p12/map-apk-process.md:87–94;docs/Disaggregated/notes/p12/BRIEF-onscreen.md:14–15;MobileGL/MG_Remote/CONTRACT-P11.md:227–257;MobileGL/MG_Remote/CONTRACT-P12.md:7、:16、:44)
|
||||
|
||||
### 8.1 对接 Anland 的可实施分解(全部 inferred)
|
||||
|
||||
这些是基于本次源码盘点的实现建议,尚未构建或原型验证:
|
||||
|
||||
| 工作包 | 应做的具体事 | 可复用基础 / 缺口依据 |
|
||||
|---|---|---|
|
||||
| A. glibc arm64 client 与加载器 | 增加 aarch64 glibc toolchain/CI 和与 Android arm64 server 的 wireFingerprint 验收;决定 libGL/libEGL 直接替代部署或 GLVND vendor;先锁定目标 API/profile,修正虚假成功/广告。 | CMakeLists.txt:503–545、:783–835;.github/workflows/test.yml:1269–1293;MobileGL/MG_State/EGLState/Core.cpp:615–689、:1336–1466 |
|
||||
| B. Linux WSI | EGL Wayland native display/window + resize/current/swap;client 在 glibc 侧持 wl_surface / wl_buffer。X11 路线补 local drawable 的 buffer present;另列 Xwayland glamor 支持门。 | MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:64–75;MobileGL/MG_Impl/GLXImpl/GLXImpl.cpp:258–327、:956–965 |
|
||||
| C. server image provider | 新增导出型 offscreen surface,而非重用 P12 fullscreen DisplayActivity 作为目标;GLES AHB-image/EGLImage/FBO 或 Vulkan external VkImage;初期只协商题设 Anland 接受的单平面格式/modifier。若图像导出不可行,可先显式 readback 到 wl_shm 建立正确性基线,不能称其零拷贝。 | MobileGL/MG_Remote/Server/ServerLoop.cpp:1600–1652;MobileGL/MG_Backend/DirectGLES/Managers.cpp:2799–2809;MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp:14528–14547;现有 readback 入口/成本清单:docs/Disaggregated/design/07-memory-readback-verification.md:21–22 |
|
||||
| D. transport 与同步 | 复用 UNIX/fd: aux,版本化 BufferCreate/FrameReady/BufferRelease;真实 acquire/release fence fd;buffer pool 与 fd 生命周期;compositor callback pacing。root-container 域做定向 fd/connect/mmap 验证。 | MobileGL/MG_Remote/Transport/FdPassing.cpp:108–149、:289–301;MobileGL/MG_Remote/Protocol/protocol.fbs:290–323;MobileGL/MG_Pipe/MGPipeTypes.h:1807–1809 |
|
||||
| E. 多用户态 client / 多窗口 / context | N clients 先用 worker-per-client 隔离;M windows 要 per-surface image pool/事件/credit;context 状态、share groups、同步归属和并发 frontends 必须从全局状态拆出。 | MobileGL/MG_Remote/Server/ServerMain.cpp:1222–1260;MobileGL/GlobalObjects.cpp:23–24;MobileGL/MG_State/GLState/Core.h:701;MobileGL/MG_Backend/DirectVulkan/DirectVulkan.cpp:38–39 |
|
||||
| F. 通用应用验收 | 最小现代 GL EGL/GLX 程序→多 context/thread/share/window→桌面 toolkit/browser/Electron/Qt/Gtk 等目标工作负载→Xwayland glamor;按实测决定 GLES、compatibility 和 GL 版本广告。验证 resize、遮挡、无 callback、断连、释放 fence 与内容正确性。 | 第 2、5、6、7 节的具体缺口;历史跨机验收仅 trace:docs/Disaggregated/notes/p12/CROSSHOST-ACCEPTANCE.md:10–17、:39–44 |
|
||||
|
||||
**inferred 的优先级判断:**最先证明“单 glibc arm64 client、单窗口、现代 GL、Android server 渲染→Anland 接受图像和同步→release 后复用”这一闭环,再扩大到 N×M 与 legacy/GLES。现有代码最有价值的是完整 command/state split 和已工作的 vendor-driver backend;最关键的新边界是 **frame/image ownership**,它目前不在 Present 协议中。(MobileGL/MG_Remote/Client/EmitTables.cpp:1165–1181;MobileGL/MG_Remote/Server/PipeApplier.cpp:388–438;MobileGL/MG_Pipe/MGPipeTypes.h:1807–1809)
|
||||
|
||||
### 8.2 本次识别的文档/代码漂移
|
||||
|
||||
| 文档说法 | 当前应采用的结论 |
|
||||
|---|---|
|
||||
| CMD/STAGE owner=client | producer 语义仍可这样称呼;跨进程四段的 allocator 是 server。(docs/Disaggregated/design/06-transport.md:9–17;MobileGL/MG_Remote/Server/ServerSession.cpp:737;MobileGL/MG_Remote/Transport/ShmSegment.cpp:253–284) |
|
||||
| ShmLink 独立 aux,可 TCP+shm | 这是第二波设计;当前 client 拒绝该组合,fd API 仍在 ITransport/SocketTransport。(docs/Disaggregated/design/06-transport.md:62、:67;MobileGL/MG_Remote/Client/ClientSession.cpp:928–936;MobileGL/MG_Remote/Transport/ITransport.h:98–108) |
|
||||
| split 今天固定 T2 / T0 握手 Fatal | 已被 P11 B2 取代:默认尝试 T0、不可用退 T2,T1 关闭。(docs/Disaggregated/design/07-memory-readback-verification.md:13;MobileGL/MG_Remote/CONTRACT-P11.md:233–248) |
|
||||
| D8 debt 将 MetalLayer 列为仍接受 | 映射函数有 MetalLayer,但 wire decoder 先明确拒绝它;X11/Win32/None 才是残留接受项。(docs/Disaggregated/notes/DEBTS.md:34;MobileGL/MG_Remote/Protocol/SurfaceOpCodec.cpp:216–236) |
|
||||
| device-lost 时 swap 返回 EGL_CONTEXT_LOST | 未找到实现映射;当前 Bool/void Present 链不能据文档认定标准 EGL 错误正确。(docs/Disaggregated/design/08-runtime-and-platform.md:33;MobileGL/MG_Impl/EGLImpl/EGLImpl.cpp:207–228;MobileGL/MG_Backend/BackendObject.cpp:396–397) |
|
||||
| present credit>1 从未测 | P12 已有 1/2/3 的跨机 trace 测量。(docs/Disaggregated/design/08-runtime-and-platform.md:8;docs/Disaggregated/notes/p12/CROSSHOST-ACCEPTANCE.md:23–34) |
|
||||
| 一设备一个 server | 是 APK display/service 模式策略;B1 TCP service 同时有独立 UNIX broker supervisor,且进程全局不等于设备全局。(MobileGL/MG_Remote/CONTRACT-P12.md:46;android-plugin/app/src/main/java/top/mobilegl/plugin/MobileGLServerService.java:147–162) |
|
||||
|
||||
## 附录 A. 指定关键词逐命中用途索引(主仓库)
|
||||
|
||||
检索通过指定 WSL 入口进行;模式为大小写不敏感的 AHardwareBuffer / dma_buf / DMA_BUF / SCM_RIGHTS / sync_file / SYNC_FD / external_memory。先对主仓库 git tracked 内容做 git grep,再补查实际展开的 3rdparty 目录(附录 B)。主仓库结果 **586 个匹配行、134 个文件**,附录 B 另有 **2108 个匹配行、88 个文件**。同一行多个关键词只算一个匹配行。未把 build 产物、Git 元数据或二进制的任意字节串当产品代码;未执行被检索脚本。
|
||||
|
||||
下表列出每一个匹配行的位置;同文件同用途合并,连续数字表示区间内每一行均命中。引用方式为“文件路径 + 行号”。无主仓库 sync_file / SYNC_FD 命中;3rdparty 有标准 SYNC_FD 枚举,Asio 有 async_file 子串匹配,因此**不能说整个磁盘树完全没有这些字符串**。
|
||||
|
||||
| 文件(树根相对路径) | 所有命中行 | 用途 |
|
||||
|---|---|---|
|
||||
| CMakeLists.txt | 621 | 编译 P11 T0 store/hop 的产品源文件。 |
|
||||
| CMakeLists.txt | 1138 | 将独立 extmem_probe 打包成 server 替身,测试 AHB 跨 app 路由。 |
|
||||
| MobileGL/Config.h | 635 | T0 不可用时退 T2 的配置说明。 |
|
||||
| MobileGL/MG_Backend/DirectGLES/Managers.cpp | 33, 1242, 1244, 2192, 2349, 2406, 2799, 2814, 2878, 3304, 3857, 4060 | P11 T0:导入 client AHB BLOB 为 GL buffer,persistent map / POST / GPU 完成后的引用释放;非 EGLImage 颜色目标。 |
|
||||
| MobileGL/MG_Backend/DirectGLES/Managers.h | 1055, 1133, 1333 | P11 T0:导入 client AHB BLOB 为 GL buffer,persistent map / POST / GPU 完成后的引用释放;非 EGLImage 颜色目标。 |
|
||||
| MobileGL/MG_Backend/DirectVulkan/Renderer/VkBufferManager.cpp | 266, 576, 631, 678, 683–684, 710, 742, 798, 920 | P11 T0:AHB BLOB→VkBuffer 的 external-memory import、映射、回读和延迟释放;非帧图像。 |
|
||||
| MobileGL/MG_Backend/DirectVulkan/Renderer/VkBufferManager.h | 145, 147, 265 | P11 T0:AHB BLOB→VkBuffer 的 external-memory import、映射、回读和延迟释放;非帧图像。 |
|
||||
| MobileGL/MG_Backend/DirectVulkan/Renderer/VkBufferObject.cpp | 129 | P11 T0:AHB BLOB→VkBuffer 的 external-memory import、映射、回读和延迟释放;非帧图像。 |
|
||||
| MobileGL/MG_Backend/DirectVulkan/Renderer/VkBufferObject.h | 75–76, 80 | P11 T0:AHB BLOB→VkBuffer 的 external-memory import、映射、回读和延迟释放;非帧图像。 |
|
||||
| MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.cpp | 15348, 15358, 15361–15362 | 仅为 P11 T0 buffer import 启用/记录 AHB external-memory device extensions。 |
|
||||
| MobileGL/MG_Backend/DirectVulkan/Renderer/VulkanRenderer.h | 171–172, 596 | 仅为 P11 T0 buffer import 启用/记录 AHB external-memory device extensions。 |
|
||||
| MobileGL/MG_IntegrationTest/CMakeLists.txt | 2543, 2560, 4120, 4126 | T0 adoption 集成用例、主机没有 AHB 的回退断言和测试注册。 |
|
||||
| MobileGL/MG_IntegrationTest/Harness/HeadlessGL.cpp | 102 | AImageReader 测试窗口的 sampled-image/color-output usage;测试 harness,不向 Linux compositor 导出帧。 |
|
||||
| MobileGL/MG_IntegrationTest/Scenarios/LargeArenaAdoptionScenario.cpp | 103, 328, 414, 704 | T0 adoption 集成用例、主机没有 AHB 的回退断言和测试注册。 |
|
||||
| MobileGL/MG_Pipe/MGPipeTypes.h | 155 | P11 T0 capability / resource ImportExternal 边界声明;persistent buffer store。 |
|
||||
| MobileGL/MG_Pipe/PipeApply.h | 131, 134, 1319 | P11 T0 capability / resource ImportExternal 边界声明;persistent buffer store。 |
|
||||
| MobileGL/MG_Remote/CONTRACT-P11.md | 3, 227, 240, 257, 275, 311–312 | P11 persistent map tiers、T0 BLOB offer/hop/import/POST 与测试;不是 present。 |
|
||||
| MobileGL/MG_Remote/CONTRACT-P11.md | 80 | PairBind 后 aux 是 SCM_RIGHTS 的配对纪律。 |
|
||||
| MobileGL/MG_Remote/CONTRACT-P11.md | 116 | B1 外部 client 握手接收 7 fd 的契约。 |
|
||||
| MobileGL/MG_Remote/CONTRACT-P6.md | 39, 644 | Rule G 描述符边界及 aux/未来 ShmLink delivery 设计;不是帧协议。 |
|
||||
| MobileGL/MG_Remote/Client/ClientSession.cpp | 858, 1187 | Client 采用 server 创建并发送的匿名共享段 fd。 |
|
||||
| MobileGL/MG_Remote/Client/ClientSession.cpp | 2734, 2746, 2832, 2845 | T0 AHB store 协商、导入回复和回退/成功日志。 |
|
||||
| MobileGL/MG_Remote/Client/ClientSession.h | 153, 171 | 共享段 Attach/Adopt/SCM_RIGHTS 启动契约。 |
|
||||
| MobileGL/MG_Remote/Client/PersistentMapTracker.h | 272 | T0 persistent GL buffer 的客户端 backing store、wire map_persistent 及 CPU shadow 语义。 |
|
||||
| MobileGL/MG_Remote/Client/WireTables.cpp | 951 | T0 persistent GL buffer 的客户端 backing store、wire map_persistent 及 CPU shadow 语义。 |
|
||||
| MobileGL/MG_Remote/Protocol/mg_protocol_base.h | 105 | 跨进程 fd 交付/句柄存活期的协议边界说明。 |
|
||||
| MobileGL/MG_Remote/Protocol/protocol.fbs | 46, 155 | SegmentRef/PairBind:fd 在 aux 交付,不把 fd 数字当跨进程对象。 |
|
||||
| MobileGL/MG_Remote/Protocol/protocol.fbs | 73 | Hello 的 persistent-map adoptTier 说明。 |
|
||||
| MobileGL/MG_Remote/Server/InProcessServer.h | 38 | Server 连接配对与 UNIX aux/共享段启动;不是 per-present buffer 交付。 |
|
||||
| MobileGL/MG_Remote/Server/PairAcceptor.h | 12 | Server 连接配对与 UNIX aux/共享段启动;不是 per-present buffer 交付。 |
|
||||
| MobileGL/MG_Remote/Server/ServerMain.cpp | 357, 1327 | Server 连接配对与 UNIX aux/共享段启动;不是 per-present buffer 交付。 |
|
||||
| MobileGL/MG_Remote/Server/ServerSession.cpp | 1101, 1127, 1143, 1172, 1182, 1192 | T0 grant / 平台判定 / POST / 收 hop AHB / import / 回退。 |
|
||||
| MobileGL/MG_Remote/Server/ServerSession.h | 302, 318 | T0 grant / 平台判定 / POST / 收 hop AHB / import / 回退。 |
|
||||
| MobileGL/MG_Remote/Transport/AdoptT0.cpp | 42, 46, 50–54, 56, 60–61, 63–64, 85–86, 88, 101–103, 110–111, 113, 116–118, 121, 129, 133, 138, 144, 155, 172 | T0 AHB BLOB 分配、lock、hop send/recv、引用释放、host fallback;tier 名称/测试钩子。 |
|
||||
| MobileGL/MG_Remote/Transport/AdoptT0.h | 10, 13, 18, 56, 61, 75, 85, 95 | T0 AHB BLOB 分配、lock、hop send/recv、引用释放、host fallback;tier 名称/测试钩子。 |
|
||||
| MobileGL/MG_Remote/Transport/AdoptTier.h | 12 | T0 AHB BLOB 分配、lock、hop send/recv、引用释放、host fallback;tier 名称/测试钩子。 |
|
||||
| MobileGL/MG_Remote/Transport/FdPassing.cpp | 147, 259 | 通用 AF_UNIX SCM_RIGHTS 单 fd sendmsg/recvmsg 与平台可用性。 |
|
||||
| MobileGL/MG_Remote/Transport/FdPassing.h | 9, 12, 40 | 通用 AF_UNIX SCM_RIGHTS 单 fd sendmsg/recvmsg 与平台可用性。 |
|
||||
| MobileGL/MG_Remote/Transport/ITransport.h | 89 | ITransport::ShareFd 契约:通过 aux 交 fd,调用者保留原 fd。 |
|
||||
| MobileGL/MG_Remote/Transport/InProcessTransport.cpp | 200 | 同进程 transport 复制 fd,模拟 SCM_RIGHTS 所有权。 |
|
||||
| MobileGL/MG_Remote/Transport/SessionRings.h | 129, 153, 165 | 匿名共享段创建、Attach/Adopt、映射/大小校验和描述符交付职责。 |
|
||||
| MobileGL/MG_Remote/Transport/ShmSegment.cpp | 349, 423 | 匿名共享段创建、Attach/Adopt、映射/大小校验和描述符交付职责。 |
|
||||
| MobileGL/MG_Remote/Transport/ShmSegment.h | 22, 55 | 匿名共享段创建、Attach/Adopt、映射/大小校验和描述符交付职责。 |
|
||||
| MobileGL/MG_Remote/Transport/ShmSegmentPosix.cpp | 84 | 匿名共享段创建、Attach/Adopt、映射/大小校验和描述符交付职责。 |
|
||||
| MobileGL/MG_Remote/Transport/ShmSegmentWin32.cpp | 89 | Windows 没有 SCM_RIGHTS;共享 section 按名称访问的说明。 |
|
||||
| MobileGL/MG_Remote/Transport/SocketTransport.cpp | 650, 892 | control/aux socket 组织与 POSIX fd passing,Windows 不支持的路径。 |
|
||||
| MobileGL/MG_Remote/Transport/SocketTransport.h | 34, 63, 77, 131 | control/aux socket 组织与 POSIX fd passing,Windows 不支持的路径。 |
|
||||
| MobileGL/MG_Remote/Wire/PipeWireCodec.cpp | 1830 | T0 persistent GL buffer 的客户端 backing store、wire map_persistent 及 CPU shadow 语义。 |
|
||||
| MobileGL/MG_Remote/Wire/PipeWireCodec.h | 509 | T0 persistent GL buffer 的客户端 backing store、wire map_persistent 及 CPU shadow 语义。 |
|
||||
| MobileGL/MG_State/EGLState/Core.cpp | 180 | Android EGL config NativeVisualId 使用 RGBA8888 AHB format 常量;不是 AHB 分配/导出。 |
|
||||
| MobileGL/MG_State/GLState/BufferState/BufferObject.cpp | 594 | T0 persistent GL buffer 的客户端 backing store、wire map_persistent 及 CPU shadow 语义。 |
|
||||
| MobileGL/MG_Test/Wire/AdoptInboxTest.cpp | 11 | T0 offer/order/回退测试,主机用测试钩子;不证明 host 有 AHB allocator。 |
|
||||
| MobileGL/MG_Test/Wire/CMakeLists.txt | 4, 26, 40 | SCM_RIGHTS / 共享段 / socket transport / spawn 的单元测试及构建注册。 |
|
||||
| MobileGL/MG_Test/Wire/FdPassingTest.cpp | 9 | SCM_RIGHTS / 共享段 / socket transport / spawn 的单元测试及构建注册。 |
|
||||
| MobileGL/MG_Test/Wire/InProcessTransportTest.cpp | 191 | SCM_RIGHTS / 共享段 / socket transport / spawn 的单元测试及构建注册。 |
|
||||
| MobileGL/MG_Test/Wire/RemoteClientAdoptT0.inc | 3, 246, 249, 292, 303 | T0 offer/order/回退测试,主机用测试钩子;不证明 host 有 AHB allocator。 |
|
||||
| MobileGL/MG_Test/Wire/ServerSpawnTest.cpp | 33, 257, 939 | SCM_RIGHTS / 共享段 / socket transport / spawn 的单元测试及构建注册。 |
|
||||
| MobileGL/MG_Test/Wire/SessionTest.cpp | 1124 | SCM_RIGHTS / 共享段 / socket transport / spawn 的单元测试及构建注册。 |
|
||||
| MobileGL/MG_Test/Wire/SocketTransportTest.cpp | 470 | SCM_RIGHTS / 共享段 / socket transport / spawn 的单元测试及构建注册。 |
|
||||
| docs/Disaggregated/design/06-transport.md | 17 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/design/07-memory-readback-verification.md | 11 | 文档/历史设计或探针结果:外部内存 tiers、AHB BLOB persistent-map 或同内核 transport 可行性;不能当成当前 frame export。 |
|
||||
| docs/Disaggregated/notes/p0/BRIEF-DOCS.md | 16 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/p0/README.md | 37 | 文档/历史设计或探针结果:外部内存 tiers、AHB BLOB persistent-map 或同内核 transport 可行性;不能当成当前 frame export。 |
|
||||
| docs/Disaggregated/notes/p0/p0-device-findings.md | 21, 23–24, 27 | 文档/历史设计或探针结果:外部内存 tiers、AHB BLOB persistent-map 或同内核 transport 可行性;不能当成当前 frame export。 |
|
||||
| docs/Disaggregated/notes/p11/B0-CROSS-APP.md | 7, 43 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/p11/INTEGRATOR-DECISIONS-P11.md | 23 | 文档/历史设计或探针结果:外部内存 tiers、AHB BLOB persistent-map 或同内核 transport 可行性;不能当成当前 frame export。 |
|
||||
| docs/Disaggregated/notes/p11/PLAN-P11.md | 33, 37 | 文档/历史设计或探针结果:外部内存 tiers、AHB BLOB persistent-map 或同内核 transport 可行性;不能当成当前 frame export。 |
|
||||
| docs/Disaggregated/notes/p12/device/2-onscreen-magma/check.log | 76, 99 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p12/device/trial-a4a940db/2-onscreen-magma/check.log | 64, 87 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p12/map-apk-process.md | 87–88 | P12 调研备选方案:child 渲染到 AHB,经 UNIX/SCM_RIGHTS 交 APK presenter;最终未选(BRIEF-onscreen.md:14–15)。 |
|
||||
| docs/Disaggregated/notes/p12/map-docs-contract.md | 103 | P12 调研备选方案:child 渲染到 AHB,经 UNIX/SCM_RIGHTS 交 APK presenter;最终未选(BRIEF-onscreen.md:14–15)。 |
|
||||
| docs/Disaggregated/notes/p12/map-server-surface.md | 113 | P12 调研备选方案:child 渲染到 AHB,经 UNIX/SCM_RIGHTS 交 APK presenter;最终未选(BRIEF-onscreen.md:14–15)。 |
|
||||
| docs/Disaggregated/notes/p5/p5-results/s1-v1.md | 126, 358 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/p5/scout-backend-install-and-thread.md | 350 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/p5/scout-transport.md | 89, 100, 261, 289, 321 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/p5c/p5c-audit-v1.md | 99 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/p6/P6-CONTRACT-DRAFT.md | 33, 58 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/p6/P6-ENDSTATE-REVIEW.md | 30, 137, 139, 143, 186, 399 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/p6/P6-ENDSTATE-REVIEW.md | 138 | 文档/历史设计或探针结果:外部内存 tiers、AHB BLOB persistent-map 或同内核 transport 可行性;不能当成当前 frame export。 |
|
||||
| docs/Disaggregated/notes/p6/P6-SPAWN-PLAN.md | 17 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/p6/README.md | 7, 16, 46 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/p6/a6-audit-rows.md | 28 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/p65/README.md | 17 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/E0-attribution/E0a-inproc.log | 94, 158, 359, 416, 480, 1550, 1607, 1671, 1809, 1986, 2043, 2107, 2248, 2743, 2800, 2864, 2960, 3024, 3178, 3235, 3299, 3397, 3461, 3613, 3670, 3734, 3830, 3894, 4145, 4209, 4336 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/E0-attribution/E0a-monolith.log | 175, 232, 296, 1914, 1971, 2035 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/E1-lockstep/E1.log | 94, 158, 330, 387, 451, 592, 766, 823, 887, 983, 1047, 1201, 1258, 1322, 1419, 1483, 1693, 1757, 1902 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/E7-coldcache/E7-cold-ra1-1.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/E7-coldcache/E7-cold-ra1-2.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/E7-coldcache/E7-cold-ra1-3.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/E7-coldcache/E8-cold-fif1-2.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/F1-verify/F1-ra0.log | 130, 194, 367, 431 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/F1-verify/F1-ra1.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/audit-cold-2.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/audit-warm-1.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/bsl-mem-inproc.log | 68, 132, 263 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/bsl-mem-spawn.log | 67, 131 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/bsl-spawn.log | 67, 131, 499, 563 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/dump-inproc-1.log | 96, 160 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/dump-inproc-2.log | 96, 160 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/dump-inproc-3.log | 96, 160 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/dump-inproc-4.log | 96, 160 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/dump2-inproc-1.log | 96, 160 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/dump2-inproc-2.log | 96, 160 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/dump2-inproc-3.log | 96, 160 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/dump2-spawn-1.log | 96, 160 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/dump2-spawn-2.log | 96, 160 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/fif1-cold-2.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/fif4-1.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/fif4-2.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/fif4-3.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/fif8-1.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/fif8-2.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/fif8-3.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/matrix-inproc.log | 94, 158, 359, 416, 480, 1978, 2035, 2099, 2362, 2426, 2571 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/openra-cold-2.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/openra-cold-3.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/plain-cold-5.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/plain-warm-1.log | 94, 158 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/spawn-1.log | 93, 157 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/spawn-3.log | 93, 157 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/W4-verify/stats-lockstep-cold-1.log | 100 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/device-window-1/X1-verify/X1-dv-inproc.log | 41, 98, 162 | 历史运行日志中的 vendor Vulkan extension 枚举;不是调用点,也不是 frame export。 |
|
||||
| docs/Disaggregated/notes/p7/ph-f.md | 104 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/recovered/wf1/final/part1.md | 135 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/recovered/wf1/final/part2.md | 18 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/recovered/wf1/final/part2.md | 171–172 | 文档/历史设计或探针结果:外部内存 tiers、AHB BLOB persistent-map 或同内核 transport 可行性;不能当成当前 frame export。 |
|
||||
| docs/Disaggregated/notes/recovered/wf1/final/part3.md | 16 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/recovered/wf1/final/part4.md | 13, 20, 50, 176–177, 191 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/recovered/wf1/final/part4.md | 178 | 文档/历史设计或探针结果:外部内存 tiers、AHB BLOB persistent-map 或同内核 transport 可行性;不能当成当前 frame export。 |
|
||||
| docs/Disaggregated/notes/recovered/wf2/final/part3.md | 139 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/recovered/wf2/final/part4.md | 19, 256 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/recovered/wf2/final/part4.md | 233 | 文档/历史设计或探针结果:外部内存 tiers、AHB BLOB persistent-map 或同内核 transport 可行性;不能当成当前 frame export。 |
|
||||
| docs/Disaggregated/notes/recovered/wf2/final/synth-part3.md | 89 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/recovered/wf2/final/synth-part4.md | 16, 182 | 文档/历史审查:共享段、SCM_RIGHTS、配对、线程或 transport 平台边界;不新增实现。 |
|
||||
| docs/Disaggregated/notes/recovered/wf2/final/synth-part4.md | 161 | 文档/历史设计或探针结果:外部内存 tiers、AHB BLOB persistent-map 或同内核 transport 可行性;不能当成当前 frame export。 |
|
||||
| include/EGL/eglext.h | 517–518, 520 | Khronos EGL_ANDROID_get_native_client_buffer 的 AHB 类型/入口声明。 |
|
||||
| include/EGL/eglext.h | 784–786, 788–796, 808, 810–822, 829 | Khronos dma-buf import/modifiers token 和 guard 声明;非实现。 |
|
||||
| include/EGL/eglext.h | 1103–1104, 1111 | Khronos EGL_MESA_image_dma_buf_export guard 声明;非实现。 |
|
||||
| scripts/ci/fatal_census.py | 206 | CI fatal/refusal census 对 T0 不可用→T2 的说明。 |
|
||||
| tools/cts/platform/tcuMobileGLPlatform.cpp | 129–130 | AImageReader 测试窗口的 sampled-image/color-output usage;测试 harness,不向 Linux compositor 导出帧。 |
|
||||
| tools/cts/probe/mgprobe.c | 158–159 | AImageReader 测试窗口的 sampled-image/color-output usage;测试 harness,不向 Linux compositor 导出帧。 |
|
||||
| tools/piglit-android/README.md | 94 | 构建 piglit 时明确关闭 DMA_BUF tests 与 GBM。 |
|
||||
| tools/piglit-android/patches/waffle-mobilegl-android.patch | 277–278 | AImageReader 测试窗口的 sampled-image/color-output usage;测试 harness,不向 Linux compositor 导出帧。 |
|
||||
| tools/spikes/extmem_probe/CMakeLists.txt | 28 | 独立 probe 的 host 构建关闭 Android-only T0;保留其它 tier 探测。 |
|
||||
| tools/spikes/extmem_probe/README.md | 23, 33, 50, 52–53, 55, 59–60, 157, 197–198 | 独立探针的 T0/T1/T3、BLOB 跨进程与真实 route 说明;不接 renderer Present。 |
|
||||
| tools/spikes/extmem_probe/extmem_probe.cpp | 8, 16, 18, 20 | 独立探针 T1 fd export / T0 AHB import / T3 host import 的范围说明。 |
|
||||
| tools/spikes/extmem_probe/extmem_probe.cpp | 407, 428, 469 | 独立探针自己的 SCM_RIGHTS sendmsg/recvmsg。 |
|
||||
| tools/spikes/extmem_probe/extmem_probe.cpp | 580–581, 609, 627–630, 646–649, 651, 916, 918, 920, 925, 1477, 1491, 1628–1630, 1653–1657, 1673–1674, 1676, 1678–1679, 1695 | 探针 extension 枚举、external buffer capabilities/配置/类型和报告;没有 renderer 帧交付。 |
|
||||
| tools/spikes/extmem_probe/extmem_probe.cpp | 1718, 1721–1722, 1771, 1773, 1904, 1983–1984, 1991, 2012, 2015, 2116, 2182–2183, 2188 | T1:host-visible VkBuffer 外部内存导出/接收/导入,opaque fd 或 DMA_BUF,及 GL memory-object import 对照。 |
|
||||
| tools/spikes/extmem_probe/extmem_probe.cpp | 2356, 2370, 2374–2378, 2384, 2388–2389, 2395, 2404, 2407–2408, 2414, 2420, 2428, 2432, 2479–2480, 2487–2488, 2501, 2504, 2507, 2513, 2522, 2535–2536, 2778 | T0:AHB BLOB client allocation、CPU lock、socket handoff、Vulkan/GL buffer import 与字节验证。 |
|
||||
| tools/spikes/extmem_probe/extmem_probe.cpp | 2784, 2796, 2808, 2812–2816, 2822, 2826–2827, 2830–2831, 2837, 2842, 2846, 2853, 2884, 2886, 2891, 2943, 2972–2973, 2981, 2989, 2999, 3005–3006 | T0S:保持 AHB CPU lock 的持续 CPU/GPU 读写一致性 probe。 |
|
||||
| tools/spikes/extmem_probe/extmem_probe.cpp | 3219, 3232–3233, 3360, 3364, 3372, 3381–3383, 3394, 3399, 3451, 3455–3459, 3463, 3467–3468, 3471, 3488, 3492, 3515, 3569, 3576 | B2 route probe:经真实 app/socket direct 或 hop 交 AHB BLOB;host SKIP 分支。 |
|
||||
| tools/spikes/extmem_probe/extmem_probe.cpp | 3590, 3632, 3638–3639, 3664, 3793, 3925–3926 | T3:VK_EXT_external_memory_host 导入 memfd/host mapping 的测试。 |
|
||||
| tools/spikes/extmem_probe/extmem_probe.cpp | 4199–4200, 4204, 4206, 4208 | 探针 main 调度 T1/T0/T0S/T3,各为 buffer 内存测试。 |
|
||||
|
||||
## 附录 B. 已展开第三方目录的全部匹配
|
||||
|
||||
这些文件随依赖源码在树内,但不是 MobileGL 已接通的帧协议。其中 DiligentCore 的 add_subdirectory 在主 CMake 中仍注释掉(CMakeLists.txt:277),VMA/Vulkan headers/utilities 则进入依赖(CMakeLists.txt:280–282)。任何上游函数声明、loader、sample 或 Win32 export 都没有改变第 3 节的产品 Present 调用链。
|
||||
|
||||
| 文件(树根相对路径) | 所有命中行 | 用途 |
|
||||
|---|---|---|
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/include/vulkan/vulkan.cppm | 525, 1233, 1237, 1242, 1304, 1309, 1315, 1320, 1504, 1522, 1690, 2246, 2271, 2441, 2619, 2738, 3554, 3557, 3562, 3585, 3592, 3724, 3868, 4293, 4327, 4480, 4683, 4847, 6534, 6538, 6545, 6589, 6600, 6801, 7038, 7693, 7746, 7982, 8311, 8583 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/include/vulkan/vulkan.hpp | 3087, 3104, 3217, 3227, 3244, 3715, 3718, 3726, 4268, 5205, 5301, 6036, 6246, 7196, 7199, 7507–7511, 7513–7517, 7520–7524, 7589–7591, 7593–7595, 7598–7600, 7603–7605, 7791–7793, 7808–7810, 7977–7979, 8534–8536, 8559–8561, 8729–8731, 8904–8906, 9022–9024, 11655, 11675, 11755, 11775, 12124, 12706, 15066, 15163, 16070, 17299, 18135, 18780, 18784, 18817, 18821, 18829, 18967, 19073, 19338, 19377, 19544, 19596, 20088, 20093, 20152, 20159, 20165, 20325, 20472, 20843, 20876, 21084, 21157, 21469, 21491, 21496, 21599, 21739, 22053, 22086, 22276, 22341 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/include/vulkan/vulkan_android.h | 46–50, 80, 108–109, 114, 120 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/include/vulkan/vulkan_core.h | 311–312, 565, 730, 973, 1052, 1165, 1302–1303, 5241–5265, 5270–5276, 5284, 5288, 5321, 5328, 10023–10026, 10058–10061, 10071–10074, 13544–13547, 13550–13554, 13559–13562, 13587–13590, 14152–14155, 15239–15242, 18172–18173, 18175–18176, 19325–19328 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/include/vulkan/vulkan_enums.hpp | 450–453, 887, 1059, 1312, 1389, 1509, 4239–4246, 4248, 4250–4251, 4253, 4255, 4257, 4260–4262, 4302–4304, 4329, 4419, 6184, 6190–6193, 6214–6216 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/include/vulkan/vulkan_extension_inspection.hpp | 55–56, 58, 114, 116, 127, 129, 131, 170, 174, 219, 356, 362, 402, 446, 476, 512, 519, 696, 699, 702, 705, 710, 743, 749, 752, 756, 759, 763, 766, 773, 990, 993, 998, 1008, 1013, 1170, 1173, 1929, 1932–1933, 1945, 1950, 1974, 1977, 2199, 2202, 2263, 2432, 2437, 2563, 2566, 2663–2664, 2778, 2780, 2782, 2784, 2787, 2789, 2907, 2911, 3269–3270, 3272, 3302, 3304, 3309, 3311, 3313, 3335, 3338, 3362, 3432, 3434, 3455, 3477, 3492, 3523, 3528, 3576 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/include/vulkan/vulkan_fuchsia.h | 45–48 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/include/vulkan/vulkan_funcs.hpp | 7522, 13547, 13590, 13610, 13632, 14389, 14415, 14428, 14449, 14486, 14502, 14522, 14556, 17337, 17343, 17357, 17362, 17377, 17382, 17401, 17413, 17419, 17422, 20728, 20757, 26007, 26031, 26072, 26466, 26489, 30367, 30390, 30409, 31687, 31708, 31747 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/include/vulkan/vulkan_handles.hpp | 756, 759, 764, 787, 794, 926, 1070, 1495, 1529, 1682, 1885, 2049, 13578, 13625, 13656, 14084, 14090, 14098, 14103, 14110, 14116, 15099, 16209, 16405, 17308, 17628, 18716, 18912 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/include/vulkan/vulkan_metal.h | 192–195 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/include/vulkan/vulkan_raii.hpp | 190, 233, 507, 529, 983, 1005, 1010, 1113, 1253, 1567, 1600, 1790, 1855, 2147, 2162, 2170, 2258, 2363, 2575, 2614, 2767, 2815, 3694, 3770, 4606, 4617, 4735, 4740, 4746, 4750, 4985, 5252, 5289, 5499, 5577, 9559, 17061, 19577, 19590, 19608, 19613, 19993, 20001, 20012, 20018, 20034, 20048, 20053, 20067, 21222, 21227, 21230, 21244, 21247, 21261, 21265, 21267, 22737, 22745, 25028, 25035, 25051, 25213, 25219, 26994, 27002, 27019, 27488, 27494, 27511 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/include/vulkan/vulkan_screen.h | 52–55 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/include/vulkan/vulkan_static_assertions.hpp | 2897, 2905, 2920, 2979, 3006, 3497, 4214, 6021, 6170, 6826, 7729, 8586 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/include/vulkan/vulkan_structs.hpp | 56639, 56668, 56699, 56728 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/include/vulkan/vulkan_to_string.hpp | 2803, 8124 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/include/vulkan/vulkan_win32.h | 51–54, 216–219 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/registry/validusage.json | 2596, 7211, 7216, 7310, 7315, 8044, 8049, 8373, 8378, 8735, 20628, 20683, 20703, 20708, 20743, 20748, 20753, 20758, 20763, 20768, 20773, 20783, 20788, 20793, 20798, 20803, 20808, 20813, 20833, 20873, 20878, 20883, 20937, 20942, 20947, 20952, 20962, 20967, 21179, 21213, 21445, 21503, 21537, 21580, 21590, 21595, 21619, 21629, 21634, 21682, 21692, 21711, 21720, 21749, 21759, 21867, 21891, 21953, 22345, 22403, 22437, 22690, 22883, 23299, 23990, 23995, 24020, 24025, 24446, 24460, 24705, 24798, 27017, 27022, 27185, 27190, 27419, 27577, 27744, 27912, 103968, 104608, 105427, 106451 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/Vulkan-Headers/registry/vk.xml | 236, 2441, 2485, 2937, 2943, 4275, 4559, 6973, 9052, 9612, 11249–11252, 11255–11257, 11361–11367, 11370–11372, 11380, 11393, 14840, 14847, 17627, 17646–17648, 19478, 19480–19481, 19490, 19492–19494, 19500, 19502–19503, 19511, 19731, 19733–19734, 19743–19749, 19752–19754, 19764, 19766–19769, 19778, 19780–19781, 19794, 19796–19797, 19808, 19830, 20274, 20464, 20466–20468, 20471, 20524, 20526–20528, 20543, 21488, 21490–21491, 21494–21496, 24101, 24103–24104, 24108, 24129, 24213, 24215–24216, 24218, 24220, 24278, 24280–24281, 24286–24288, 25124, 25126–25128, 25432, 26388, 26390–26392, 26397, 27139, 27232, 27234–27235, 27239–27241 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/glew/auto/doc/log.html | 40 | 上游 GLEW EGL extension 元数据、入口加载和 glewinfo 枚举;不实现 image 导入/导出。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/glew/auto/extensions/gl/EGL_EXT_image_dma_buf_import | 1, 3, 5, 7–15 | 上游 GLEW EGL extension 元数据、入口加载和 glewinfo 枚举;不实现 image 导入/导出。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/glew/auto/extensions/gl/EGL_EXT_image_dma_buf_import_modifiers | 1, 3, 5–15 | 上游 GLEW EGL extension 元数据、入口加载和 glewinfo 枚举;不实现 image 导入/导出。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/glew/auto/extensions/gl/EGL_MESA_image_dma_buf_export | 1, 3 | 上游 GLEW EGL extension 元数据、入口加载和 glewinfo 枚举;不实现 image 导入/导出。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/glew/doc/log.html | 138 | 上游 GLEW EGL extension 元数据、入口加载和 glewinfo 枚举;不实现 image 导入/导出。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/glew/include/GL/eglew.h | 798, 800–801, 803, 805–813, 826, 828, 830, 832–833, 835–845, 853, 855, 1801, 1803–1804, 1812, 1814, 2506–2507, 2568 | 上游 GLEW EGL extension 元数据、入口加载和 glewinfo 枚举;不实现 image 导入/导出。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/glew/src/glew.c | 17567–17568, 17629, 17861, 17863, 17873, 18177, 18179, 18189, 18476–18482, 18684–18687, 27867–27868, 27870, 27874–27875, 27877, 28313–28314, 28316 | 上游 GLEW EGL extension 元数据、入口加载和 glewinfo 枚举;不实现 image 导入/导出。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/glew/src/glewinfo.c | 10644, 10646, 10648, 10651, 10653, 10655, 10657, 10663, 11276, 11278, 11280, 11286, 15990–15995, 16176–16178 | 上游 GLEW EGL extension 元数据、入口加载和 glewinfo 枚举;不实现 image 导入/导出。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/volk/volk.c | 329, 331, 416, 418, 677, 680, 749, 751–752, 755, 863, 866, 983, 986–987, 990, 1187, 1189–1190, 1192, 1261, 1263, 1621, 1624, 1693, 1695–1696, 1699, 1807, 1810, 1927, 1930–1931, 1934, 2131, 2133–2134, 2136, 2205, 2207, 2601, 2604, 2710, 2712–2713, 2716, 2835, 2838, 2983, 2985–2986, 2989–2990, 2993, 3264, 3266–3267, 3269–3270, 3272, 3342, 3344 | 上游 volk Vulkan entrypoint dispatch loader;有函数指针不代表 MobileGL 调用了它。 |
|
||||
| 3rdparty/DiligentCore/ThirdParty/volk/volk.h | 477, 482, 579, 583–584, 589, 743, 748, 909, 914–915, 920, 1201, 1205–1206, 1210, 1307, 1311, 1753, 1756, 1862, 1864–1865, 1868, 1987, 1990, 2135, 2137–2138, 2141–2142, 2145, 2416, 2418–2419, 2421–2422, 2424, 2494, 2496 | 上游 volk Vulkan entrypoint dispatch loader;有函数指针不代表 MobileGL 调用了它。 |
|
||||
| 3rdparty/Vulkan-Headers/include/vulkan/vulkan.cppm | 434, 438, 467, 471, 476, 601, 708, 955, 982, 1057, 1184, 1247 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/include/vulkan/vulkan.hpp | 4111, 4128, 4241, 4251, 4270, 4751, 4754, 4762, 5385, 6397, 6493, 6818, 7462, 7728, 8839, 8842, 9158–9162, 9164–9168, 9171–9175, 9240–9242, 9244–9246, 9249–9251, 9254–9256, 9442–9444, 9459–9461, 9636–9638, 10203–10205, 10228–10230, 10407–10409, 10412–10414, 10629–10631, 10785–10787, 13505, 13525, 13605, 13625, 13992, 14702, 17015, 17112, 18058, 18132, 19895, 21009, 22090, 22094, 22127, 22131, 22139, 22277, 22395, 22666, 22705, 22783, 22913, 22980, 23495, 23500, 23559, 23566, 23572, 23732, 23892, 24273, 24306, 24403, 24565, 24652, 24988, 25010, 25015, 25118, 25269, 25593, 25626, 25714, 25859, 25933 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/include/vulkan/vulkan_android.h | 48–52, 82, 110–111, 117, 125 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/include/vulkan/vulkan_core.h | 292–293, 563, 744, 986, 1073, 1099, 1258, 1450–1451, 5481–5506, 5511–5517, 5525, 5529, 5562, 5569, 10409–10412, 10446–10449, 10459–10462, 14715–14718, 14721–14725, 14730–14733, 14760–14763, 15355–15358, 16916–16919, 20010–20011, 20013–20014, 21289–21292 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/include/vulkan/vulkan_enums.hpp | 421–424, 893, 1081, 1333, 1420, 1446, 1619, 4437–4451, 4453, 4455–4456, 4458, 4460, 4462, 4465, 4468–4470, 4513–4518, 4546–4547, 4645–4646, 6697, 6703–6706, 6727–6729 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/include/vulkan/vulkan_extension_inspection.hpp | 58–59, 61, 117, 119, 130, 132, 134, 173, 177, 224, 363, 369, 412, 414, 469, 507, 557, 564, 756, 759, 763, 766, 771, 807, 813, 816, 821, 824, 829, 832, 840, 1067, 1070, 1075, 1086, 1091, 1268, 1271, 2063, 2066–2067, 2079, 2084, 2109, 2112, 2367, 2372, 2381, 2384, 2447, 2724, 2729, 2943, 2946, 3164–3165, 3289, 3291, 3293, 3295, 3298, 3300, 3422, 3426, 3824–3825, 3827, 3857, 3859, 3864, 3866, 3868, 3890, 3893, 3917, 3987, 3989, 4012, 4014, 4041, 4059, 4097, 4102, 4158 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/include/vulkan/vulkan_fuchsia.h | 47–50 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/include/vulkan/vulkan_funcs.hpp | 6628, 12530, 12573, 12593, 12613, 13345, 13370, 13383, 13403, 13438, 13454, 13473, 13504, 16197, 16203, 16215, 16220, 16239, 16244, 16261, 16272, 16278, 16281, 19666, 19691, 24641, 24663, 24702, 25064, 25085, 26384, 26406, 26425, 26456, 30136, 30158, 30177, 31542, 31562, 31597 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/include/vulkan/vulkan_handles.hpp | 755, 758, 763, 786, 793, 925, 1102, 1523, 1557, 1715, 1724, 2027, 2244, 14312, 14361, 14393, 14853, 14860, 14869, 14878, 14886, 14893, 16022, 17210, 17422, 17790, 18888, 19245, 20392, 20616 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/include/vulkan/vulkan_metal.h | 196–199 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/include/vulkan/vulkan_ohos.h | 22–23, 25–26 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/include/vulkan/vulkan_raii.hpp | 179, 222, 526, 548, 1033, 1055, 1060, 1163, 1314, 1638, 1671, 1759, 1904, 1978, 2282, 2297, 2305, 2393, 2509, 2727, 2766, 2835, 2957, 3013, 3893, 3976, 4763, 4774, 4895, 4900, 4906, 4910, 5147, 5403, 5440, 5543, 5751, 5824, 9910, 17419, 19870, 19883, 19901, 19907, 20295, 20303, 20314, 20320, 20336, 20350, 20355, 20369, 21554, 21559, 21562, 21576, 21579, 21592, 21596, 21598, 23134, 23142, 25369, 25376, 25392, 25554, 25560, 26225, 26232, 26248, 26263, 27776, 27784, 27801, 28316, 28322, 28339 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/include/vulkan/vulkan_screen.h | 56–59 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/include/vulkan/vulkan_static_assertions.hpp | 2897, 2905, 2920, 2979, 3006, 3497, 4415, 6212, 6361, 7023, 7061, 8456, 9528 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/include/vulkan/vulkan_structs.hpp | 77061, 77096, 77102, 77130, 77157 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/include/vulkan/vulkan_to_string.hpp | 2907, 8814 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/include/vulkan/vulkan_win32.h | 55–58, 232–235 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/registry/validusage.json | 2846, 7751, 7756, 7850, 7855, 8529, 8534, 8883, 8888, 9163, 9168, 9603, 22402, 22462, 22482, 22487, 22522, 22527, 22532, 22537, 22542, 22547, 22552, 22562, 22567, 22572, 22577, 22582, 22587, 22592, 22612, 22652, 22657, 22662, 22716, 22721, 22726, 22731, 22741, 22746, 22833, 22982, 23016, 23248, 23306, 23340, 23383, 23393, 23398, 23422, 23432, 23437, 23485, 23495, 23514, 23523, 23552, 23562, 23670, 23694, 23756, 24148, 24206, 24240, 24503, 24691, 25132, 25939, 25944, 25969, 25974, 26425, 26556, 26801, 26894, 29264, 29269, 29513, 29518, 29752, 29920, 30097, 30270, 30575, 31144, 118352, 119055, 120081, 121223 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Headers/registry/vk.xml | 245, 2565, 2609, 3082, 3088, 4549, 4833, 7281, 9443, 10058, 10954, 12457–12460, 12463–12465, 12571–12577, 12580–12582, 12590, 12603, 16214, 16221, 19260, 19279–19281, 21272, 21274–21275, 21284, 21286–21288, 21294, 21296–21297, 21305, 21535, 21537–21538, 21547–21553, 21556–21558, 21568, 21570–21573, 21582, 21584–21585, 21598, 21600–21601, 21612, 21634, 22104, 22294, 22296–22298, 22301, 22354, 22356–22358, 22373, 23486, 23488–23489, 23492–23494, 26166, 26168–26169, 26173, 26194, 26278, 26280–26281, 26283, 26285, 26343, 26345–26346, 26351–26353, 27203, 27205–27206, 27220, 27225, 27227–27229, 27427, 27620, 28724, 28726–28728, 28733, 29676, 29678–29679, 29683–29685 | 上游 Vulkan C/C++ API 类型、常量、dispatch/RAII wrapper 或 registry/valid-usage 规则;含 AHB/external memory/SYNC_FD 声明,不是 MobileGL 接线。 |
|
||||
| 3rdparty/Vulkan-Utility-Libraries/include/vulkan/utility/vk_safe_struct.hpp | 11766 | 上游 Vulkan enum→string、sType、safe-struct 拷贝和生成器支持;不创建或发送呈现 buffer。 |
|
||||
| 3rdparty/Vulkan-Utility-Libraries/include/vulkan/utility/vk_struct_helper.hpp | 106–107, 580, 701, 909, 998, 1023, 1124 | 上游 Vulkan enum→string、sType、safe-struct 拷贝和生成器支持;不创建或发送呈现 buffer。 |
|
||||
| 3rdparty/Vulkan-Utility-Libraries/include/vulkan/vk_enum_string_helper.h | 295–298, 837–838, 1175–1176, 1641–1642, 1805–1806, 1857–1858, 2169–2170, 7719–7754, 7778–7783, 7813–7814, 7923–7924, 9969–9976, 10000–10005, 11602, 11604, 12530, 12760, 13160, 13332, 13382, 13579 | 上游 Vulkan enum→string、sType、safe-struct 拷贝和生成器支持;不创建或发送呈现 buffer。 |
|
||||
| 3rdparty/Vulkan-Utility-Libraries/scripts/generators/safe_struct_generator.py | 53 | 上游 Vulkan enum→string、sType、safe-struct 拷贝和生成器支持;不创建或发送呈现 buffer。 |
|
||||
| 3rdparty/Vulkan-Utility-Libraries/src/vulkan/vk_safe_struct_core.cpp | 7708, 7756 | 上游 Vulkan enum→string、sType、safe-struct 拷贝和生成器支持;不创建或发送呈现 buffer。 |
|
||||
| 3rdparty/Vulkan-Utility-Libraries/src/vulkan/vk_safe_struct_ext.cpp | 5408, 14352 | 上游 Vulkan enum→string、sType、safe-struct 拷贝和生成器支持;不创建或发送呈现 buffer。 |
|
||||
| 3rdparty/Vulkan-Utility-Libraries/src/vulkan/vk_safe_struct_utils.cpp | 129, 132, 1064, 1292, 1707, 1915, 1963, 2157, 2508, 2511, 3443, 3671, 4086, 4294, 4342, 4536 | 上游 Vulkan enum→string、sType、safe-struct 拷贝和生成器支持;不创建或发送呈现 buffer。 |
|
||||
| 3rdparty/Vulkan-Utility-Libraries/src/vulkan/vk_safe_struct_vendor.cpp | 799, 10627, 14544, 19724 | 上游 Vulkan enum→string、sType、safe-struct 拷贝和生成器支持;不创建或发送呈现 buffer。 |
|
||||
| 3rdparty/VulkanMemoryAllocator/CHANGELOG.md | 27 | 上游 VMA 通用 external-memory allocation/Win32 handle 导出支持、示例测试及文档;没有 MobileGL 帧 dma-buf/fence 协议。 |
|
||||
| 3rdparty/VulkanMemoryAllocator/Doxyfile | 2469–2470 | 上游 VMA 通用 external-memory allocation/Win32 handle 导出支持、示例测试及文档;没有 MobileGL 帧 dma-buf/fence 协议。 |
|
||||
| 3rdparty/VulkanMemoryAllocator/README.md | 56 | 上游 VMA 通用 external-memory allocation/Win32 handle 导出支持、示例测试及文档;没有 MobileGL 帧 dma-buf/fence 协议。 |
|
||||
| 3rdparty/VulkanMemoryAllocator/docs/html/faq.html | 126 | 上游 VMA 通用 external-memory allocation/Win32 handle 导出支持、示例测试及文档;没有 MobileGL 帧 dma-buf/fence 协议。 |
|
||||
| 3rdparty/VulkanMemoryAllocator/docs/html/globals.html | 110 | 上游 VMA 通用 external-memory allocation/Win32 handle 导出支持、示例测试及文档;没有 MobileGL 帧 dma-buf/fence 协议。 |
|
||||
| 3rdparty/VulkanMemoryAllocator/docs/html/globals_eval.html | 103 | 上游 VMA 通用 external-memory allocation/Win32 handle 导出支持、示例测试及文档;没有 MobileGL 帧 dma-buf/fence 协议。 |
|
||||
| 3rdparty/VulkanMemoryAllocator/docs/html/group__group__alloc.html | 2500–2501, 2547–2552, 2561, 2565 | 上游 VMA 通用 external-memory allocation/Win32 handle 导出支持、示例测试及文档;没有 MobileGL 帧 dma-buf/fence 协议。 |
|
||||
| 3rdparty/VulkanMemoryAllocator/docs/html/group__group__init.html | 132, 359, 557, 569 | 上游 VMA 通用 external-memory allocation/Win32 handle 导出支持、示例测试及文档;没有 MobileGL 帧 dma-buf/fence 协议。 |
|
||||
| 3rdparty/VulkanMemoryAllocator/docs/html/other_api_interop.html | 84, 89–90, 97, 101, 153, 191, 195, 209, 212 | 上游 VMA 通用 external-memory allocation/Win32 handle 导出支持、示例测试及文档;没有 MobileGL 帧 dma-buf/fence 协议。 |
|
||||
| 3rdparty/VulkanMemoryAllocator/docs/html/quick_start.html | 162 | 上游 VMA 通用 external-memory allocation/Win32 handle 导出支持、示例测试及文档;没有 MobileGL 帧 dma-buf/fence 协议。 |
|
||||
| 3rdparty/VulkanMemoryAllocator/docs/html/search/all_14.js | 66 | 上游 VMA 通用 external-memory allocation/Win32 handle 导出支持、示例测试及文档;没有 MobileGL 帧 dma-buf/fence 协议。 |
|
||||
| 3rdparty/VulkanMemoryAllocator/docs/html/search/enumvalues_0.js | 29 | 上游 VMA 通用 external-memory allocation/Win32 handle 导出支持、示例测试及文档;没有 MobileGL 帧 dma-buf/fence 协议。 |
|
||||
| 3rdparty/VulkanMemoryAllocator/docs/html/vk__mem__alloc_8h.html | 220 | 上游 VMA 通用 external-memory allocation/Win32 handle 导出支持、示例测试及文档;没有 MobileGL 帧 dma-buf/fence 协议。 |
|
||||
| 3rdparty/VulkanMemoryAllocator/docs/html/vk_khr_external_memory_win32.html | 8, 78, 81–82, 86–87, 89, 91, 96, 100, 147, 151, 177, 189, 193 | 上游 VMA 通用 external-memory allocation/Win32 handle 导出支持、示例测试及文档;没有 MobileGL 帧 dma-buf/fence 协议。 |
|
||||
| 3rdparty/VulkanMemoryAllocator/include/vk_mem_alloc.h | 242–245, 247, 251–254, 256, 480, 486, 1062, 1136, 1147, 1711, 2169, 2195, 2199–2200, 2221–2226, 2234, 2249–2250, 2265, 6396, 6483, 6552, 6559, 6670, 6672, 10716, 10721, 10729, 10731, 11137, 11143, 11458, 11474, 12078, 12086, 13217, 13310, 13313, 13324, 13326, 13350, 13356, 13540, 13648, 13702, 13959, 13967, 15625–15626, 17112, 17118, 17124–17129, 17133, 17298, 17523, 18933, 18946, 18949, 18966, 18970, 19028, 19070, 19075, 19120, 19123 | 上游 VMA 通用 external-memory allocation/Win32 handle 导出支持、示例测试及文档;没有 MobileGL 帧 dma-buf/fence 协议。 |
|
||||
| 3rdparty/VulkanMemoryAllocator/src/Tests.cpp | 42, 8490–8491, 8497, 8506, 8530, 8536, 8584–8585, 8591, 8600, 8624, 8632 | 上游 VMA 通用 external-memory allocation/Win32 handle 导出支持、示例测试及文档;没有 MobileGL 帧 dma-buf/fence 协议。 |
|
||||
| 3rdparty/VulkanMemoryAllocator/src/VulkanSample.cpp | 72, 1494, 1540, 1542, 1933–1934, 2095–2096 | 上游 VMA 通用 external-memory allocation/Win32 handle 导出支持、示例测试及文档;没有 MobileGL 帧 dma-buf/fence 协议。 |
|
||||
| 3rdparty/apitrace/specs/dxgi.py | 732, 740 | DXGI DMA_BUFFER_BOUNDARY 枚举;与 Linux dma-buf 无关的子串匹配。 |
|
||||
| 3rdparty/apitrace/specs/eglapi.py | 62, 302, 304–312, 318–329, 422, 477 | apitrace 的 EGL API/enum trace 描述及 Khronos header;不是 MobileGL EGL extension 实现。 |
|
||||
| 3rdparty/apitrace/specs/eglenum.py | 275, 277–285, 340–350 | apitrace 的 EGL API/enum trace 描述及 Khronos header;不是 MobileGL EGL extension 实现。 |
|
||||
| 3rdparty/apitrace/thirdparty/khronos/EGL/eglext.h | 517–518, 520, 770–772, 774–782, 794, 796–808, 815, 1089–1090, 1097 | apitrace 的 EGL API/enum trace 描述及 Khronos header;不是 MobileGL EGL extension 实现。 |
|
||||
| 3rdparty/asio/asio.manifest | 6515 | async_file_copy 示例/清单;sync_file 命中是 async_file 的子串,非 Linux GPU sync_file。 |
|
||||
| 3rdparty/asio/asio/src/examples/cpp11/Makefile.am | 32, 184 | async_file_copy 示例/清单;sync_file 命中是 async_file 的子串,非 Linux GPU sync_file。 |
|
||||
| 3rdparty/asio/asio/src/examples/cpp11/files/.gitignore | 1 | async_file_copy 示例/清单;sync_file 命中是 async_file 的子串,非 Linux GPU sync_file。 |
|
||||
| 3rdparty/asio/asio/src/examples/cpp11/files/async_file_copy.cpp | 2, 79 | async_file_copy 示例/清单;sync_file 命中是 async_file 的子串,非 Linux GPU sync_file。 |
|
||||
| 3rdparty/asio/asio/src/examples/cpp11/local/fd_passing_stream_client.cpp | 71 | Asio 的独立 AF_UNIX SCM_RIGHTS 示例程序;非 MobileGL transport。 |
|
||||
| 3rdparty/asio/asio/src/examples/cpp11/local/fd_passing_stream_server.cpp | 87 | Asio 的独立 AF_UNIX SCM_RIGHTS 示例程序;非 MobileGL transport。 |
|
||||
| 3rdparty/asio/boost_asio.manifest | 6951 | async_file_copy 示例/清单;sync_file 命中是 async_file 的子串,非 Linux GPU sync_file。 |
|
||||
| 3rdparty/asio/src/examples/cpp11/Makefile.am | 32, 184 | async_file_copy 示例/清单;sync_file 命中是 async_file 的子串,非 Linux GPU sync_file。 |
|
||||
| 3rdparty/asio/src/examples/cpp11/files/.gitignore | 1 | async_file_copy 示例/清单;sync_file 命中是 async_file 的子串,非 Linux GPU sync_file。 |
|
||||
| 3rdparty/asio/src/examples/cpp11/files/async_file_copy.cpp | 2, 79 | async_file_copy 示例/清单;sync_file 命中是 async_file 的子串,非 Linux GPU sync_file。 |
|
||||
| 3rdparty/asio/src/examples/cpp11/local/fd_passing_stream_client.cpp | 71 | Asio 的独立 AF_UNIX SCM_RIGHTS 示例程序;非 MobileGL transport。 |
|
||||
| 3rdparty/asio/src/examples/cpp11/local/fd_passing_stream_server.cpp | 87 | Asio 的独立 AF_UNIX SCM_RIGHTS 示例程序;非 MobileGL transport。 |
|
||||
|
||||
@@ -181,128 +181,6 @@ and the client reads both fills through the still-held pointer; after the last
|
||||
round it unlocks and relocks once more (`after unlock+relock`), which separates
|
||||
"GPU writes never landed" from "the held mapping kept stale lines".
|
||||
|
||||
## T4 — an image allocated outside Android
|
||||
|
||||
Can the render server draw into an image that was allocated **outside** Android —
|
||||
a GBM buffer minted in a Linux container on the same kernel? That is the
|
||||
`{Owner=Platform, Storage=OfferedImage}` cell an Anland-style Wayland host needs,
|
||||
and nothing in MobileGL imports a dma-buf today. It is a per-device fact, not a
|
||||
code fact.
|
||||
|
||||
### What the device answered
|
||||
|
||||
Redmi 23117RK66C, Adreno 750, Android 16, Droidspaces Fedora 44 container,
|
||||
2026-09-30. The answer has two halves and they point in opposite directions.
|
||||
|
||||
| row | verdict | what it means |
|
||||
|---|---|---|
|
||||
| `T4-image-import` | `UNSUPPORTED` | This driver does not advertise `EGL_EXT_image_dma_buf_import`, so a container-minted dma-buf has no spelling as an EGLImage here. A capability answer, not a failure — and the reason the second row exists. |
|
||||
| `T4-ahb-image` | `FAIL`, and the failure is the finding | **Android-side allocation works end to end.** `AHardwareBuffer_allocate` → `eglGetNativeClientBufferANDROID` → `eglCreateImageKHR(EGL_NATIVE_BUFFER_ANDROID)` → `glEGLImageTargetRenderbufferStorageOES` (FBO `GL_FRAMEBUFFER_COMPLETE`) → clear, `glFinish`, and a waited `glFenceSync` — all clean — and `glEGLImageTargetTexture2DOES` reads **the same bytes back on both pixels**. The container then imports the same handle's fd with `gbm_bo_import(GBM_BO_IMPORT_FD_MODIFIER, …)` and **that** is where it breaks: the bytes it maps are not the bytes the GPU wrote, and its own writes do not arrive either. |
|
||||
|
||||
The reason is visible in the offer: the AHB's handle carries **two** descriptors,
|
||||
while the import claims `DRM_FORMAT_MOD_LINEAR` over plane 0 alone. A multi-plane,
|
||||
possibly compressed allocation imported as one linear plane is not a view of that
|
||||
buffer, so a CPU mapping of it agrees with nothing — and no userspace API hands the
|
||||
importer the modifier it should have used, because `AHardwareBuffer` does not expose
|
||||
one. (`AHardwareBuffer_Desc::stride`, for its part, is in **pixels** while every
|
||||
consumer on the wire wants bytes; that trap cost a device run and is now a named
|
||||
constant beside the fourcc.)
|
||||
|
||||
### What this decides
|
||||
|
||||
The cell is reachable **only** when the image is allocated where the server can use
|
||||
it — on the Android side — **and** its layout travels with the offer. That is a
|
||||
requirement on the host that mints the scanout buffers, not a MobileGL feature:
|
||||
Anland-style hosts that allocate in the container cannot be served by this driver,
|
||||
and a host that publishes plane count, strides, offsets and modifier alongside the
|
||||
fd can be. Note also that the container never needs a CPU view of the image in the
|
||||
product: the compositor hands the buffer to its GL, which is MobileGL, and the
|
||||
server renders into it. The CPU mapping in this leg is a *verification device* —
|
||||
which is exactly why `FAIL` here means "a linear view is invalid", not "the driver
|
||||
cannot render into an AHardwareBuffer".
|
||||
|
||||
This leg's topology differs from every other one: the peer is **not** a re-exec
|
||||
child. It is a glibc process inside the container, because only that side can
|
||||
allocate on the device Anland hands the container. So the probe **listens**
|
||||
(`--only-t4[=@endpoint]`, default `@mgl-t4`) and the peer **dials** it. The
|
||||
endpoint is an abstract socket name because a Droidspaces container runs
|
||||
`net_mode=host`: the abstract namespace is common to both sides, while a
|
||||
filesystem pathname would have to exist in the other side's root.
|
||||
|
||||
Both rows run on the one connection `--only-t4` opens, so the peer never waits for
|
||||
a frame by name and a skipped row is not an error.
|
||||
|
||||
* **`T4-image-import`** — the container-minted direction. This side has no GBM
|
||||
device, so it waits for an fd, asks the driver whether the announced
|
||||
`(fourcc, modifier)` pair is one it even lists (`eglQueryDmaBufFormatsEXT` / `eglQueryDmaBufModifiersEXT`; a pair
|
||||
the driver does not list is a capability answer, an import failure on a pair it
|
||||
*does* list is a driver bug, and the two are never reported the same way),
|
||||
imports the buffer as a texture **and** as a renderbuffer, reads two pixels on
|
||||
each path — `(0,0)` and the far corner, so a wrong stride or offset cannot
|
||||
pass as a working import — and then clears each path to a colour.
|
||||
* **`T4-ahb-image`** — the Android-minted direction, and the one the measurement
|
||||
says the architecture must use. This side allocates an `AHardwareBuffer`
|
||||
(`R8G8B8A8_UNORM`, `GPU_SAMPLED_IMAGE|GPU_COLOR_OUTPUT|CPU_READ_OFTEN|CPU_WRITE_OFTEN`),
|
||||
imports **the same buffer** into GL as an EGLImage, clears it through the
|
||||
renderbuffer path behind a reported fence, hands its handle to the peer over a
|
||||
socketpair (`AHardwareBuffer_sendHandleToUnixSocket`), and then reads the peer's
|
||||
answer back through the **texture** path at `(0,0)` and at the far corner. One
|
||||
decisive leg, `ahb[D]`: it needs the peer to have seen this side's clear colour
|
||||
at both pixels *and* this side to have read the peer's pattern at both.
|
||||
* **`peer/t4_gbm_peer.c`** — serves both rows. For the first it allocates with
|
||||
`gbm_bo_create(…, GBM_FORMAT_ARGB8888,
|
||||
GBM_BO_USE_RENDERING|GBM_BO_USE_LINEAR)`, fills the whole mapping with
|
||||
`--seed=RRGGBBAA` in ARGB8888 memory order (B,G,R,A; a *solid* fill, so a
|
||||
vertical flip cannot turn a working import into a reported failure), sends the
|
||||
fd over `SCM_RIGHTS`, and after each of the probe's two writes takes a **fresh**
|
||||
read mapping and answers with the bytes it actually saw. A driver that refuses
|
||||
the allocation has answered the question: the refusal is printed verbatim and
|
||||
the peer exits non-zero, with no silent fallback to another format. For the
|
||||
second it takes the descriptors off the socketpair, imports the first with
|
||||
`gbm_bo_import(GBM_BO_IMPORT_FD_MODIFIER, …)` and reports **how many** arrived —
|
||||
the plane count is itself evidence — then compares both pixels against the
|
||||
announced colour before writing a pattern of its own.
|
||||
|
||||
The peer **must run inside the container**: `/dev/dri/renderD128` there is the
|
||||
Anland-backed `msm_drm` GBM device, and the Android side has no GBM device at all.
|
||||
|
||||
```sh
|
||||
S=<serial>; DS="/data/local/Droidspaces/bin/droidspaces --name=Fedora"
|
||||
|
||||
# peer: into the container's own rootfs (adb push lands on the Android side),
|
||||
# then built there with the container's own glibc gcc -- the documented line is
|
||||
# gcc -O2 -o t4_gbm_peer t4_gbm_peer.c -lgbm
|
||||
base64 -w0 tools/spikes/extmem_probe/peer/t4_gbm_peer.c > /tmp/t4_gbm_peer.c.b64
|
||||
adb -s $S shell "$DS run sh -c 'base64 -d > /root/t4_gbm_peer.c'" < /tmp/t4_gbm_peer.c.b64
|
||||
adb -s $S shell "$DS run sh -c 'cd /root && gcc -O2 -o t4_gbm_peer t4_gbm_peer.c -lgbm'"
|
||||
|
||||
# probe: build and start it FIRST — it is the side that listens
|
||||
ANDROID_NDK=$HOME/android-sdk/ndk/27.3.13750724 ./build_android.sh /tmp/extmem-build
|
||||
adb -s $S push /tmp/extmem-build/extmem_probe /data/local/tmp/extmem_probe
|
||||
adb -s $S shell "chmod 755 /data/local/tmp/extmem_probe && /data/local/tmp/extmem_probe --only-t4" \
|
||||
| tee out-t4-$S.txt
|
||||
|
||||
# then, with the probe listening, dial it from the container
|
||||
adb -s $S shell "$DS run /root/t4_gbm_peer --endpoint=@mgl-t4"
|
||||
```
|
||||
|
||||
Peer options: `--endpoint=@mgl-t4`, `--width=64`, `--height=64`,
|
||||
`--seed=RRGGBBAA`, `--timeout=60`. The row is `T4-image-import`, with two
|
||||
decisive legs `tex[D]` and `rb[D]` under the usual rule: `OK` needs each path to
|
||||
have read the peer's seed bytes **and** to have had its own write observed by the
|
||||
peer. The peer exits 0 only on that same two-way condition, and its last line
|
||||
carries every raw value (stride, format, modifier, the fd's kernel name, the
|
||||
exporter, both pixels of both paths) — read those, not the exit code.
|
||||
|
||||
Two things there will look like failures and are not. `gbm_bo_unmap()` of a
|
||||
**WRITE** mapping segfaults on this container's mixed-version Mesa (distro
|
||||
`libgbm`/`dri_gbm` 26.1.5 plus an unowned self-built
|
||||
`libgallium-26.2.0-devel.so`), so the peer deliberately leaves its fill mapping
|
||||
mapped instead. And the peer's fd name plus exporter (`/dmabuf:`,
|
||||
`exp_name: system`) is the evidence that this is the same *kind* of object the
|
||||
compositor scans out: kwin's own scanout allocations come from that same system
|
||||
dma-heap.
|
||||
|
||||
## Route mode (P11 B2 step 1)
|
||||
|
||||
Does a client's AHB cross the *real* B1 routes into the server app? A spike APK built with
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -124,10 +124,18 @@ The bundled fixtures cover:
|
||||
- minecraft-1.21.4-fabric-iris-sundial-lite-in-world: captured from Minecraft 1.21.4 Fabric with Sodium, Iris, and
|
||||
Sundial Lite after entering a singleplayer world.
|
||||

|
||||
- minecraft-1.21.1-neoforge-create-indirect-in-world: captured from Minecraft 1.21.1 NeoForge with Create, Sodium,
|
||||
and Iris (no shader pack) in a world facing Create water wheels and a large cogwheel, with Flywheel's
|
||||
`flywheel:indirect` backend (compute-shader culling, glMultiDrawElementsIndirect, persistent-mapped staging).
|
||||

|
||||
- minecraft-1.21.1-neoforge-create-indirect-in-world-align1024: **not an original capture** - derived from the retired
|
||||
`minecraft-1.21.1-neoforge-create-indirect-in-world` capture (Minecraft 1.21.1 NeoForge with Create, Sodium, and
|
||||
Iris (no shader pack) in a world facing Create water wheels and a large cogwheel, with Flywheel's
|
||||
`flywheel:indirect` backend: compute-shader culling, glMultiDrawElementsIndirect, persistent-mapped staging). That
|
||||
capture came from a desktop driver whose `GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT` is 16, so Flywheel bound its
|
||||
scatter lists at 16-byte offsets, and a driver that requires more (Adreno 830: 64) rejects every one of those binds
|
||||
with `GL_INVALID_VALUE`. [`fixture_tools/realign_buffer_ranges.cpp`](fixture_tools/realign_buffer_ranges.cpp)
|
||||
`--align 1024` rewrote it: each of the 1,270 range binds off a 1024-byte boundary now binds a 1024-aligned slot of
|
||||
an added buffer that is filled with the same bytes right before the dispatch that reads them. The 3,812 inserted
|
||||
calls renumber the trace (target call 504631 -> 508443); the golden is the original one (the same frame), and the
|
||||
host replay matches it with the original's SSIM to 9 digits on both backends.
|
||||

|
||||
- minecraft-1.21.1-neoforge-create-instancing-in-world: same world and camera as the indirect case, with Flywheel's
|
||||
`flywheel:instancing` backend (texture-buffer instance data, glDrawElementsInstancedBaseVertex).
|
||||

|
||||
|
||||
@@ -0,0 +1,432 @@
|
||||
// realign_buffer_ranges: make a GL trace's indexed uniform / storage buffer range binds portable.
|
||||
//
|
||||
// An app sizes glBindBufferRange offsets by the GL_{UNIFORM,SHADER_STORAGE}_BUFFER_OFFSET_ALIGNMENT
|
||||
// of the driver it was captured on (Flywheel's staging scatter lists: 16 on desktop). A driver that
|
||||
// requires more rejects those binds with GL_INVALID_VALUE. This tool rewrites every such bind whose
|
||||
// offset is not a multiple of --align:
|
||||
// - the bind itself becomes glBindBuffer(target, buffer) (the generic binding it also set);
|
||||
// - right before the next draw / dispatch, the bytes the range holds at that point are uploaded into a
|
||||
// fresh --align-aligned slot of one relocation buffer, and that slot is bound at the same index.
|
||||
// The bytes come from the trace itself (buffer data / subdata and the persistent-map memcpy commits), so a
|
||||
// source buffer written any other way (GPU copies, clears) is refused rather than guessed.
|
||||
//
|
||||
// Inserting calls renumbers every later call: --map-call N prints where original call N landed (a case's
|
||||
// target_call). The output is snappy-compressed; `apitrace repack --brotli` it before packaging.
|
||||
//
|
||||
// Build (A = 3rdparty/apitrace, B = a Release build of it, e.g. `cmake -S $A -B $B -G Ninja -DENABLE_GUI=OFF
|
||||
// && ninja -C $B apitrace`):
|
||||
// g++ -std=c++17 -O2 -flto=auto -fno-rtti -fno-exceptions -I$A/lib/trace -I$A/lib/os -I$B -I$B/lib/trace \
|
||||
// realign_buffer_ranges.cpp -o realign_buffer_ranges $B/lib/trace/libcommon.a $B/lib/guids/libguids.a \
|
||||
// $B/lib/highlight/libhighlight.a $B/lib/os/libos.a $B/thirdparty/libbacktrace.a $B/thirdparty/libsnappy.a \
|
||||
// $B/thirdparty/libzstd_seekable.a -lbrotlidec -lbrotlienc -lz -lzstd -lpthread -ldl
|
||||
// Usage: realign_buffer_ranges [--align N] [--map-call N]... in.trace out.trace
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "trace_model.hpp"
|
||||
#include "trace_parser.hpp"
|
||||
#include "trace_writer.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr unsigned kUniformBuffer = 0x8A11;
|
||||
constexpr unsigned kShaderStorageBuffer = 0x90D2;
|
||||
constexpr unsigned kDynamicStorageBit = 0x0100;
|
||||
constexpr unsigned kRelocBufferName = 1000000;
|
||||
|
||||
[[noreturn]] void Fail(const trace::Call *call, const std::string &what) {
|
||||
std::fprintf(stderr, "error: call %u %s: %s\n", call ? call->no : 0u, call ? call->name() : "-", what.c_str());
|
||||
std::exit(1);
|
||||
}
|
||||
|
||||
bool Is(const trace::Call *call, const char *name) { return std::strcmp(call->name(), name) == 0; }
|
||||
|
||||
bool StartsWith(const char *s, const char *prefix) { return std::strncmp(s, prefix, std::strlen(prefix)) == 0; }
|
||||
|
||||
bool ReadsIndexedBuffers(const trace::Call *call) {
|
||||
const char *n = call->name();
|
||||
return StartsWith(n, "glDraw") || StartsWith(n, "glMultiDraw") || StartsWith(n, "glDispatchCompute");
|
||||
}
|
||||
|
||||
bool IsRangeTarget(unsigned target) { return target == kUniformBuffer || target == kShaderStorageBuffer; }
|
||||
|
||||
struct MapRegion {
|
||||
unsigned buffer;
|
||||
uint64_t offset;
|
||||
uint64_t length;
|
||||
uint64_t ptr;
|
||||
};
|
||||
|
||||
struct Reloc {
|
||||
unsigned src = 0;
|
||||
uint64_t offset = 0;
|
||||
uint64_t size = 0;
|
||||
bool dirty = true;
|
||||
std::vector<char> last;
|
||||
const trace::EnumSig *targetSig = nullptr;
|
||||
};
|
||||
|
||||
// Signatures for the calls this tool inserts; ids are allocated past the trace's own.
|
||||
struct Sigs {
|
||||
const char *createNames[2] = {"n", "buffers"};
|
||||
const char *storageNames[4] = {"buffer", "size", "data", "flags"};
|
||||
const char *subDataNames[4] = {"buffer", "offset", "size", "data"};
|
||||
const char *bindRangeNames[5] = {"target", "index", "buffer", "offset", "size"};
|
||||
const char *bindNames[2] = {"target", "buffer"};
|
||||
trace::FunctionSig create{}, storage{}, subData{}, bindRange{}, bind{};
|
||||
|
||||
void Init(trace::Id firstId) {
|
||||
create = {firstId + 0, "glCreateBuffers", 2, createNames};
|
||||
storage = {firstId + 1, "glNamedBufferStorage", 4, storageNames};
|
||||
subData = {firstId + 2, "glNamedBufferSubData", 4, subDataNames};
|
||||
bindRange = {firstId + 3, "glBindBufferRange", 5, bindRangeNames};
|
||||
bind = {firstId + 4, "glBindBuffer", 2, bindNames};
|
||||
}
|
||||
};
|
||||
|
||||
class Rewriter {
|
||||
public:
|
||||
uint64_t align = 1024;
|
||||
std::set<unsigned> mapCalls;
|
||||
|
||||
int Run(const char *in, const char *out) {
|
||||
Scan(in);
|
||||
if (relocSrc_.empty()) {
|
||||
std::fprintf(stderr, "nothing to realign at %llu bytes\n", (unsigned long long)align);
|
||||
return 2;
|
||||
}
|
||||
sigs_.Init(maxSigId_ + 1);
|
||||
stride_ = (maxRelocSize_ + align - 1) / align * align;
|
||||
Pass(in, nullptr); // dry run: count the slots
|
||||
slotCap_ = slotsUsed_;
|
||||
Pass(in, out);
|
||||
std::fprintf(stderr,
|
||||
"realigned %llu binds of %zu source buffer(s) to %llu bytes: %llu uploads, relocation buffer %llu "
|
||||
"bytes, %llu calls inserted\n",
|
||||
(unsigned long long)relocBinds_, relocSrc_.size(), (unsigned long long)align,
|
||||
(unsigned long long)slotsUsed_, (unsigned long long)(slotCap_ * stride_),
|
||||
(unsigned long long)inserted_);
|
||||
for (const auto &m : callMap_) {
|
||||
std::printf("call %u -> %llu\n", m.first, (unsigned long long)m.second);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
// Pass 0: which buffers need relocating, and the sizes involved.
|
||||
void Scan(const char *in) {
|
||||
trace::Parser p;
|
||||
if (!p.open(in)) Fail(nullptr, std::string("cannot open ") + in);
|
||||
trace::Call *call;
|
||||
while ((call = p.parse_call())) {
|
||||
maxSigId_ = std::max(maxSigId_, call->sig->id);
|
||||
if (Is(call, "glBindBufferRange")) {
|
||||
unsigned target = unsigned(call->arg(0).toSInt());
|
||||
uint64_t offset = uint64_t(call->arg(3).toSInt());
|
||||
if (IsRangeTarget(target) && offset % align != 0) {
|
||||
relocSrc_.insert(unsigned(call->arg(2).toUInt()));
|
||||
maxRelocSize_ = std::max(maxRelocSize_, uint64_t(call->arg(4).toSInt()));
|
||||
}
|
||||
} else if (Is(call, "glBindBuffersRange")) {
|
||||
unsigned target = unsigned(call->arg(0).toSInt());
|
||||
const trace::Array *offsets = call->arg(4).toArray();
|
||||
if (IsRangeTarget(target) && offsets) {
|
||||
for (const trace::Value *v : offsets->values) {
|
||||
if (uint64_t(v->toSInt()) % align != 0) Fail(call, "misaligned glBindBuffersRange is not handled");
|
||||
}
|
||||
}
|
||||
}
|
||||
delete call;
|
||||
}
|
||||
}
|
||||
|
||||
void Pass(const char *in, const char *out) {
|
||||
trace::Parser p;
|
||||
if (!p.open(in)) Fail(nullptr, std::string("cannot open ") + in);
|
||||
trace::Writer writer;
|
||||
writer_ = nullptr;
|
||||
if (out) {
|
||||
if (!writer.open(out, p.getVersion(), p.getProperties())) Fail(nullptr, std::string("cannot create ") + out);
|
||||
writer_ = &writer;
|
||||
}
|
||||
shadow_.clear();
|
||||
maps_.clear();
|
||||
generic_.clear();
|
||||
relocs_.clear();
|
||||
slotsUsed_ = 0;
|
||||
relocBinds_ = 0;
|
||||
inserted_ = 0;
|
||||
created_ = false;
|
||||
|
||||
trace::Call *call;
|
||||
while ((call = p.parse_call())) {
|
||||
Process(call);
|
||||
delete call;
|
||||
}
|
||||
if (writer_) writer.close();
|
||||
writer_ = nullptr;
|
||||
}
|
||||
|
||||
unsigned BufferArg(trace::Call *call, unsigned index) { return unsigned(call->arg(index).toUInt()); }
|
||||
|
||||
unsigned Generic(unsigned target) {
|
||||
auto it = generic_.find(target);
|
||||
return it == generic_.end() ? 0 : it->second;
|
||||
}
|
||||
|
||||
std::vector<char> *Shadow(unsigned buffer) {
|
||||
auto it = shadow_.find(buffer);
|
||||
return it == shadow_.end() ? nullptr : &it->second;
|
||||
}
|
||||
|
||||
void Specify(trace::Call *call, unsigned buffer, uint64_t size, trace::Value *data) {
|
||||
if (!relocSrc_.count(buffer)) return;
|
||||
std::vector<char> &s = shadow_[buffer];
|
||||
s.assign(size, 0);
|
||||
const trace::Blob *blob = data ? data->toBlob() : nullptr;
|
||||
if (blob) std::memcpy(s.data(), blob->buf, std::min<uint64_t>(size, blob->size));
|
||||
for (auto &r : relocs_) {
|
||||
if (r.second.src == buffer) r.second.dirty = true;
|
||||
}
|
||||
(void)call;
|
||||
}
|
||||
|
||||
void Write(trace::Call *call, unsigned buffer, uint64_t offset, const char *bytes, uint64_t size) {
|
||||
std::vector<char> *s = Shadow(buffer);
|
||||
if (!s) return;
|
||||
if (offset + size > s->size()) Fail(call, "write past the end of a tracked buffer");
|
||||
std::memcpy(s->data() + offset, bytes, size);
|
||||
}
|
||||
|
||||
void Refuse(trace::Call *call, unsigned buffer) {
|
||||
if (relocSrc_.count(buffer)) Fail(call, "writes a relocated source buffer in a way the trace does not carry the bytes of");
|
||||
}
|
||||
|
||||
void Emit(trace::Call *call) {
|
||||
if (!writer_) return;
|
||||
if (mapCalls.count(call->no)) callMap_[call->no] = writtenCalls_;
|
||||
writer_->writeCall(call);
|
||||
++writtenCalls_;
|
||||
}
|
||||
|
||||
void EmitNew(trace::Call *call) {
|
||||
++inserted_;
|
||||
if (writer_) {
|
||||
writer_->writeCall(call);
|
||||
++writtenCalls_;
|
||||
}
|
||||
delete call;
|
||||
}
|
||||
|
||||
trace::Call *NewCall(const trace::FunctionSig *sig, unsigned thread) {
|
||||
return new trace::Call(sig, trace::CallFlags(0), thread);
|
||||
}
|
||||
|
||||
void EmitBind(unsigned thread, const trace::EnumSig *targetSig, unsigned target, unsigned buffer) {
|
||||
trace::Call *c = NewCall(&sigs_.bind, thread);
|
||||
c->args[0].value = targetSig ? static_cast<trace::Value *>(new trace::Enum(targetSig, target))
|
||||
: static_cast<trace::Value *>(new trace::SInt(target));
|
||||
c->args[1].value = new trace::UInt(buffer);
|
||||
EmitNew(c);
|
||||
}
|
||||
|
||||
void CreateRelocBuffer(unsigned thread) {
|
||||
trace::Call *c = NewCall(&sigs_.create, thread);
|
||||
c->args[0].value = new trace::SInt(1);
|
||||
trace::Array *names = new trace::Array(1);
|
||||
names->values[0] = new trace::UInt(kRelocBufferName);
|
||||
c->args[1].value = names;
|
||||
EmitNew(c);
|
||||
|
||||
c = NewCall(&sigs_.storage, thread);
|
||||
c->args[0].value = new trace::UInt(kRelocBufferName);
|
||||
c->args[1].value = new trace::SInt(int64_t(slotCap_ * stride_));
|
||||
c->args[2].value = new trace::Null();
|
||||
c->args[3].value = new trace::UInt(kDynamicStorageBit);
|
||||
EmitNew(c);
|
||||
created_ = true;
|
||||
}
|
||||
|
||||
void Upload(trace::Call *before, unsigned target, unsigned index, Reloc &r) {
|
||||
std::vector<char> *s = Shadow(r.src);
|
||||
if (!s) Fail(before, "a relocated range reads a buffer whose storage the trace never specified");
|
||||
if (r.offset + r.size > s->size()) Fail(before, "a relocated range runs past its buffer");
|
||||
std::vector<char> bytes(s->begin() + r.offset, s->begin() + r.offset + r.size);
|
||||
if (!r.dirty && bytes == r.last) return;
|
||||
|
||||
unsigned thread = before->thread_id;
|
||||
if (writer_ && slotsUsed_ >= slotCap_) Fail(before, "relocation slots exceeded the dry run");
|
||||
uint64_t slotOffset = slotsUsed_++ * stride_;
|
||||
if (!created_) CreateRelocBuffer(thread);
|
||||
|
||||
trace::Call *c = NewCall(&sigs_.subData, thread);
|
||||
c->args[0].value = new trace::UInt(kRelocBufferName);
|
||||
c->args[1].value = new trace::SInt(int64_t(slotOffset));
|
||||
c->args[2].value = new trace::SInt(int64_t(r.size));
|
||||
trace::Blob *blob = new trace::Blob(r.size);
|
||||
std::memcpy(blob->buf, bytes.data(), r.size);
|
||||
c->args[3].value = blob;
|
||||
EmitNew(c);
|
||||
|
||||
c = NewCall(&sigs_.bindRange, thread);
|
||||
c->args[0].value = r.targetSig ? static_cast<trace::Value *>(new trace::Enum(r.targetSig, target))
|
||||
: static_cast<trace::Value *>(new trace::SInt(target));
|
||||
c->args[1].value = new trace::UInt(index);
|
||||
c->args[2].value = new trace::UInt(kRelocBufferName);
|
||||
c->args[3].value = new trace::SInt(int64_t(slotOffset));
|
||||
c->args[4].value = new trace::SInt(int64_t(r.size));
|
||||
EmitNew(c);
|
||||
|
||||
// glBindBufferRange also moved the generic binding; put back the app's.
|
||||
EmitBind(thread, r.targetSig, target, Generic(target));
|
||||
|
||||
r.last = std::move(bytes);
|
||||
r.dirty = false;
|
||||
}
|
||||
|
||||
void Process(trace::Call *call) {
|
||||
const char *n = call->name();
|
||||
|
||||
if (Is(call, "glBindBuffer")) {
|
||||
generic_[unsigned(call->arg(0).toSInt())] = BufferArg(call, 1);
|
||||
} else if (Is(call, "glBindBufferBase")) {
|
||||
unsigned target = unsigned(call->arg(0).toSInt());
|
||||
generic_[target] = BufferArg(call, 2);
|
||||
relocs_.erase({target, unsigned(call->arg(1).toUInt())});
|
||||
} else if (Is(call, "glBindBufferRange")) {
|
||||
unsigned target = unsigned(call->arg(0).toSInt());
|
||||
unsigned index = unsigned(call->arg(1).toUInt());
|
||||
unsigned buffer = BufferArg(call, 2);
|
||||
uint64_t offset = uint64_t(call->arg(3).toSInt());
|
||||
generic_[target] = buffer;
|
||||
if (IsRangeTarget(target) && offset % align != 0) {
|
||||
Reloc r;
|
||||
r.src = buffer;
|
||||
r.offset = offset;
|
||||
r.size = uint64_t(call->arg(4).toSInt());
|
||||
trace::Value &t = call->arg(0);
|
||||
trace::Enum *e = nullptr;
|
||||
// Enum values print by name in dumps; keep the trace's own enum signature when it has one.
|
||||
struct EnumProbe : trace::Visitor {
|
||||
trace::Enum *found = nullptr;
|
||||
void visit(trace::Enum *node) override { found = node; }
|
||||
} probe;
|
||||
t.visit(probe);
|
||||
e = probe.found;
|
||||
r.targetSig = e ? e->sig : nullptr;
|
||||
relocs_[{target, index}] = std::move(r);
|
||||
++relocBinds_;
|
||||
if (mapCalls.count(call->no) && writer_) callMap_[call->no] = writtenCalls_;
|
||||
// Only the generic binding survives at this point; the indexed one is bound before its first read.
|
||||
EmitBind(call->thread_id, e ? e->sig : nullptr, target, buffer);
|
||||
--inserted_; // a replacement, not an insertion
|
||||
return;
|
||||
}
|
||||
relocs_.erase({target, index});
|
||||
} else if (Is(call, "glBindBuffersBase") || Is(call, "glBindBuffersRange")) {
|
||||
unsigned target = unsigned(call->arg(0).toSInt());
|
||||
unsigned first = unsigned(call->arg(1).toUInt());
|
||||
unsigned count = unsigned(call->arg(2).toSInt());
|
||||
for (unsigned i = first; i < first + count; ++i) relocs_.erase({target, i});
|
||||
} else if (Is(call, "glNamedBufferStorage") || Is(call, "glNamedBufferData")) {
|
||||
Specify(call, BufferArg(call, 0), uint64_t(call->arg(1).toSInt()), &call->arg(2));
|
||||
} else if (Is(call, "glBufferStorage") || Is(call, "glBufferData")) {
|
||||
Specify(call, Generic(unsigned(call->arg(0).toSInt())), uint64_t(call->arg(1).toSInt()), &call->arg(2));
|
||||
} else if (Is(call, "glNamedBufferSubData") || Is(call, "glBufferSubData")) {
|
||||
unsigned buffer = Is(call, "glNamedBufferSubData") ? BufferArg(call, 0) : Generic(unsigned(call->arg(0).toSInt()));
|
||||
if (relocSrc_.count(buffer)) {
|
||||
const trace::Blob *blob = call->arg(3).toBlob();
|
||||
if (!blob) Fail(call, "subdata without bytes");
|
||||
Write(call, buffer, uint64_t(call->arg(1).toSInt()), blob->buf,
|
||||
std::min<uint64_t>(uint64_t(call->arg(2).toSInt()), blob->size));
|
||||
}
|
||||
} else if (Is(call, "glCopyNamedBufferSubData")) {
|
||||
Refuse(call, BufferArg(call, 1));
|
||||
} else if (Is(call, "glCopyBufferSubData")) {
|
||||
Refuse(call, Generic(unsigned(call->arg(1).toSInt())));
|
||||
} else if (StartsWith(n, "glClearNamedBuffer")) {
|
||||
Refuse(call, BufferArg(call, 0));
|
||||
} else if (StartsWith(n, "glClearBuffer") && (StartsWith(n, "glClearBufferData") || StartsWith(n, "glClearBufferSubData"))) {
|
||||
Refuse(call, Generic(unsigned(call->arg(0).toSInt())));
|
||||
} else if (Is(call, "glMapNamedBufferRange") || Is(call, "glMapBufferRange")) {
|
||||
unsigned buffer = Is(call, "glMapNamedBufferRange") ? BufferArg(call, 0) : Generic(unsigned(call->arg(0).toSInt()));
|
||||
if (relocSrc_.count(buffer) && call->ret) {
|
||||
maps_.push_back({buffer, uint64_t(call->arg(1).toSInt()), uint64_t(call->arg(2).toSInt()),
|
||||
call->ret->toUIntPtr()});
|
||||
}
|
||||
} else if (Is(call, "glMapNamedBuffer") || Is(call, "glMapBuffer")) {
|
||||
unsigned buffer = Is(call, "glMapNamedBuffer") ? BufferArg(call, 0) : Generic(unsigned(call->arg(0).toSInt()));
|
||||
std::vector<char> *s = Shadow(buffer);
|
||||
if (s && call->ret) maps_.push_back({buffer, 0, s->size(), call->ret->toUIntPtr()});
|
||||
} else if (Is(call, "glUnmapNamedBuffer") || Is(call, "glUnmapBuffer")) {
|
||||
unsigned buffer = Is(call, "glUnmapNamedBuffer") ? BufferArg(call, 0) : Generic(unsigned(call->arg(0).toSInt()));
|
||||
maps_.erase(std::remove_if(maps_.begin(), maps_.end(), [&](const MapRegion &m) { return m.buffer == buffer; }),
|
||||
maps_.end());
|
||||
} else if (Is(call, "memcpy")) {
|
||||
uint64_t dest = call->arg(0).toUIntPtr();
|
||||
const trace::Blob *blob = call->arg(1).toBlob();
|
||||
uint64_t size = call->arg(2).toUInt();
|
||||
if (blob) {
|
||||
size = std::min<uint64_t>(size, blob->size);
|
||||
for (const MapRegion &m : maps_) {
|
||||
uint64_t lo = std::max(dest, m.ptr);
|
||||
uint64_t hi = std::min(dest + size, m.ptr + m.length);
|
||||
if (lo >= hi) continue;
|
||||
Write(call, m.buffer, m.offset + (lo - m.ptr), blob->buf + (lo - dest), hi - lo);
|
||||
}
|
||||
}
|
||||
} else if (ReadsIndexedBuffers(call)) {
|
||||
for (auto &r : relocs_) Upload(call, r.first.first, r.first.second, r.second);
|
||||
}
|
||||
|
||||
Emit(call);
|
||||
}
|
||||
|
||||
Sigs sigs_;
|
||||
trace::Id maxSigId_ = 0;
|
||||
std::set<unsigned> relocSrc_;
|
||||
uint64_t maxRelocSize_ = 0;
|
||||
uint64_t stride_ = 0;
|
||||
uint64_t slotCap_ = 0;
|
||||
uint64_t slotsUsed_ = 0;
|
||||
uint64_t relocBinds_ = 0;
|
||||
uint64_t inserted_ = 0;
|
||||
uint64_t writtenCalls_ = 0;
|
||||
bool created_ = false;
|
||||
trace::Writer *writer_ = nullptr;
|
||||
std::unordered_map<unsigned, std::vector<char>> shadow_;
|
||||
std::vector<MapRegion> maps_;
|
||||
std::unordered_map<unsigned, unsigned> generic_;
|
||||
std::map<std::pair<unsigned, unsigned>, Reloc> relocs_;
|
||||
std::map<unsigned, uint64_t> callMap_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
Rewriter rw;
|
||||
std::vector<const char *> files;
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (!std::strcmp(argv[i], "--align") && i + 1 < argc) {
|
||||
rw.align = std::strtoull(argv[++i], nullptr, 0);
|
||||
} else if (!std::strcmp(argv[i], "--map-call") && i + 1 < argc) {
|
||||
rw.mapCalls.insert(unsigned(std::strtoul(argv[++i], nullptr, 0)));
|
||||
} else {
|
||||
files.push_back(argv[i]);
|
||||
}
|
||||
}
|
||||
if (files.size() != 2 || rw.align == 0) {
|
||||
std::fprintf(stderr, "usage: %s [--align N] [--map-call N]... in.trace out.trace\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
return rw.Run(files[0], files[1]);
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -268,10 +268,11 @@
|
||||
"target_call": 145353
|
||||
},
|
||||
{
|
||||
"name": "minecraft-1.21.1-neoforge-create-indirect-in-world",
|
||||
"trace_archive": "minecraft-1.21.1-neoforge-create-indirect-in-world.tgz",
|
||||
"golden": "minecraft-1.21.1-neoforge-create-indirect-in-world.0000504631.png",
|
||||
"target_call": 504631,
|
||||
"name": "minecraft-1.21.1-neoforge-create-indirect-in-world-align1024",
|
||||
"derived_from": "minecraft-1.21.1-neoforge-create-indirect-in-world (the original desktop capture, retired): NOT the same trace - its 16-byte-aligned uniform/storage buffer range binds were relocated to 1024-aligned slots by tools/trace_replay/fixture_tools/realign_buffer_ranges.cpp --align 1024, which inserts calls and renumbers them (original target_call 504631)",
|
||||
"trace_archive": "minecraft-1.21.1-neoforge-create-indirect-in-world-align1024.tgz",
|
||||
"golden": "minecraft-1.21.1-neoforge-create-indirect-in-world-align1024.0000508443.png",
|
||||
"target_call": 508443,
|
||||
"timeout_seconds": 1800,
|
||||
"coherent_as_flush": true
|
||||
},
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user