From 25f0ffbcc5c23f70b5186b09f005e28ebeb967ee Mon Sep 17 00:00:00 2001
From: Julien Masson <jmasson@baylibre.com>
Date: Mon, 2 Dec 2024 12:35:31 +0100
Subject: [PATCH 1/6] graphics: rework tree structure with: allocator, composer
 and EGL

When we modify something in the graphics stack, it usually concerns:
- allocator:
We support eith ARM gralloc or minigbm.
We can select one of the them with TARGET_ALLOCATOR_BACKEND.
By default we use ARM gralloc.

- composer:
We only use hwc3 composer.

- EGL:
We support either SwAngle or Mali.
We can select one of the them with TARGET_GPU_BACKEND.
By default we use Mali.

These 3 components have been moved to dedicated folder.

Signed-off-by: Julien Masson <jmasson@baylibre.com>
---
 BoardConfig.mk                                |  3 --
 device.mk                                     |  3 --
 graphics/BoardConfig.mk                       | 13 ++++---
 graphics/allocator/BoardConfig.mk             | 24 +++++++++++++
 .../{gpu => allocator/arm}/BoardConfig.mk     |  2 +-
 .../{gpu => allocator/arm}/capabilities.xml   |  0
 graphics/allocator/arm/device.mk              | 24 +++++++++++++
 .../arm}/sepolicy/file_contexts               |  7 ----
 .../hal_graphics_allocator_default.te         |  0
 graphics/allocator/device.mk                  | 25 +++++++++++++
 graphics/allocator/minigbm/BoardConfig.mk     | 22 ++++++++++++
 graphics/allocator/minigbm/device.mk          | 25 +++++++++++++
 .../allocator/minigbm/sepolicy/file_contexts  |  7 ++++
 .../hal_graphics_allocator_default.te         |  0
 .../sepolicy/hal_graphics_composer_default.te |  0
 {display => graphics/composer}/BoardConfig.mk |  4 +--
 {display => graphics/composer}/device.mk      |  0
 .../composer}/display_settings.xml            |  0
 .../composer}/sepolicy/file.te                |  0
 .../composer}/sepolicy/file_contexts          |  0
 .../composer}/sepolicy/hal_drm_default.te     |  0
 .../sepolicy/hal_graphics_composer_default.te | 10 ++++++
 .../composer}/sepolicy/property_contexts      |  0
 graphics/device.mk                            | 17 +++------
 graphics/egl/BoardConfig.mk                   | 27 ++++++++++++++
 graphics/egl/device.mk                        | 35 +++++++++++++++++++
 graphics/egl/mali/BoardConfig.mk              | 18 ++++++++++
 graphics/{gpu => egl/mali}/device.mk          |  9 -----
 graphics/egl/mali/sepolicy/file_contexts      |  6 ++++
 graphics/egl/sepolicy/file_contexts           | 11 ++++++
 graphics/{ => egl}/sepolicy/property_contexts |  0
 graphics/{soft => egl/swangle}/BoardConfig.mk | 12 +------
 graphics/{soft => egl/swangle}/device.mk      |  8 -----
 graphics/sepolicy/file_contexts               | 12 -------
 graphics/soft/sepolicy/file_contexts          |  5 ---
 mt8188/mt8188.mk                              |  3 +-
 36 files changed, 251 insertions(+), 81 deletions(-)
 create mode 100644 graphics/allocator/BoardConfig.mk
 rename graphics/{gpu => allocator/arm}/BoardConfig.mk (89%)
 rename graphics/{gpu => allocator/arm}/capabilities.xml (100%)
 create mode 100644 graphics/allocator/arm/device.mk
 rename graphics/{gpu => allocator/arm}/sepolicy/file_contexts (73%)
 rename graphics/{gpu => allocator/arm}/sepolicy/hal_graphics_allocator_default.te (100%)
 create mode 100644 graphics/allocator/device.mk
 create mode 100644 graphics/allocator/minigbm/BoardConfig.mk
 create mode 100644 graphics/allocator/minigbm/device.mk
 create mode 100644 graphics/allocator/minigbm/sepolicy/file_contexts
 rename graphics/{ => allocator}/sepolicy/hal_graphics_allocator_default.te (100%)
 rename graphics/{ => allocator}/sepolicy/hal_graphics_composer_default.te (100%)
 rename {display => graphics/composer}/BoardConfig.mk (87%)
 rename {display => graphics/composer}/device.mk (100%)
 rename {display => graphics/composer}/display_settings.xml (100%)
 rename {display => graphics/composer}/sepolicy/file.te (100%)
 rename {display => graphics/composer}/sepolicy/file_contexts (100%)
 rename {display => graphics/composer}/sepolicy/hal_drm_default.te (100%)
 create mode 100644 graphics/composer/sepolicy/hal_graphics_composer_default.te
 rename {display => graphics/composer}/sepolicy/property_contexts (100%)
 create mode 100644 graphics/egl/BoardConfig.mk
 create mode 100644 graphics/egl/device.mk
 create mode 100644 graphics/egl/mali/BoardConfig.mk
 rename graphics/{gpu => egl/mali}/device.mk (80%)
 create mode 100644 graphics/egl/mali/sepolicy/file_contexts
 create mode 100644 graphics/egl/sepolicy/file_contexts
 rename graphics/{ => egl}/sepolicy/property_contexts (100%)
 rename graphics/{soft => egl/swangle}/BoardConfig.mk (64%)
 rename graphics/{soft => egl/swangle}/device.mk (80%)
 delete mode 100644 graphics/soft/sepolicy/file_contexts

diff --git a/BoardConfig.mk b/BoardConfig.mk
index 38dd85b..4aa641a 100644
--- a/BoardConfig.mk
+++ b/BoardConfig.mk
@@ -72,9 +72,6 @@ include device/mediatek/common/security/BoardConfig.mk
 # Media
 include device/mediatek/common/media/BoardConfig.mk
 
-# Display
-include device/mediatek/common/display/BoardConfig.mk
-
 # Fastboot
 include device/mediatek/common/fastboot/BoardConfig.mk
 
diff --git a/device.mk b/device.mk
index ed15a09..ae1419f 100644
--- a/device.mk
+++ b/device.mk
@@ -46,9 +46,6 @@ $(call inherit-product, device/mediatek/common/media/device.mk)
 # Utils
 $(call inherit-product, device/mediatek/common/utils/device.mk)
 
-# Display
-$(call inherit-product, device/mediatek/common/display/device.mk)
-
 # Fastboot
 $(call inherit-product, device/mediatek/common/fastboot/device.mk)
 
diff --git a/graphics/BoardConfig.mk b/graphics/BoardConfig.mk
index 5947b7b..acd2479 100644
--- a/graphics/BoardConfig.mk
+++ b/graphics/BoardConfig.mk
@@ -14,12 +14,11 @@
 # limitations under the License.
 #
 
+include device/mediatek/common/graphics/allocator/BoardConfig.mk
+
+include device/mediatek/common/graphics/composer/BoardConfig.mk
+
+include device/mediatek/common/graphics/egl/BoardConfig.mk
+
 # Sepolicy
 BOARD_SEPOLICY_DIRS += device/mediatek/common/graphics/sepolicy
-
-# GPU / Soft
-ifeq ($(GRAPHICS_SOFT_ENABLE), true)
-include device/mediatek/common/graphics/soft/BoardConfig.mk
-else
-include device/mediatek/common/graphics/gpu/BoardConfig.mk
-endif
diff --git a/graphics/allocator/BoardConfig.mk b/graphics/allocator/BoardConfig.mk
new file mode 100644
index 0000000..824d947
--- /dev/null
+++ b/graphics/allocator/BoardConfig.mk
@@ -0,0 +1,24 @@
+#
+# Copyright 2024 BayLibre SAS
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Backend
+ifeq ($(TARGET_ALLOCATOR_BACKEND), arm)
+include device/mediatek/common/graphics/allocator/arm/BoardConfig.mk
+else ifeq ($(TARGET_ALLOCATOR_BACKEND), minigbm)
+include device/mediatek/common/graphics/allocator/minigbm/BoardConfig.mk
+else
+$(error TARGET_ALLOCATOR_BACKEND not supported)
+endif
diff --git a/graphics/gpu/BoardConfig.mk b/graphics/allocator/arm/BoardConfig.mk
similarity index 89%
rename from graphics/gpu/BoardConfig.mk
rename to graphics/allocator/arm/BoardConfig.mk
index cbc96ee..9bee93d 100644
--- a/graphics/gpu/BoardConfig.mk
+++ b/graphics/allocator/arm/BoardConfig.mk
@@ -15,7 +15,7 @@
 #
 
 # Sepolicy
-BOARD_SEPOLICY_DIRS += device/mediatek/common/graphics/gpu/sepolicy
+BOARD_SEPOLICY_DIRS += device/mediatek/common/graphics/allocator/arm/sepolicy
 
 # ARM gralloc
 include vendor/arm/android-gralloc/android/gralloc.device.mk
diff --git a/graphics/gpu/capabilities.xml b/graphics/allocator/arm/capabilities.xml
similarity index 100%
rename from graphics/gpu/capabilities.xml
rename to graphics/allocator/arm/capabilities.xml
diff --git a/graphics/allocator/arm/device.mk b/graphics/allocator/arm/device.mk
new file mode 100644
index 0000000..afb0188
--- /dev/null
+++ b/graphics/allocator/arm/device.mk
@@ -0,0 +1,24 @@
+#
+# Copyright 2024 BayLibre SAS
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# ARM mapper/allocator
+PRODUCT_PACKAGES += \
+    android.hardware.graphics.mapper@4.0-impl-arm \
+    android.hardware.graphics.allocator-service \
+    mapper.arm
+
+PRODUCT_COPY_FILES += \
+    $(LOCAL_PATH)/capabilities.xml:$(TARGET_COPY_OUT_VENDOR)/etc/gralloc/capabilities.xml
diff --git a/graphics/gpu/sepolicy/file_contexts b/graphics/allocator/arm/sepolicy/file_contexts
similarity index 73%
rename from graphics/gpu/sepolicy/file_contexts
rename to graphics/allocator/arm/sepolicy/file_contexts
index c5d969d..cb71b50 100644
--- a/graphics/gpu/sepolicy/file_contexts
+++ b/graphics/allocator/arm/sepolicy/file_contexts
@@ -1,7 +1,3 @@
-# mali
-/dev/mali[0-9]                                                                 u:object_r:gpu_device:s0
-/vendor/lib(64)?/hw/vulkan\.mali\.so                                           u:object_r:same_process_hal_file:s0
-
 # allocator
 /vendor/bin/hw/android\.hardware\.graphics\.allocator-service                  u:object_r:hal_graphics_allocator_default_exec:s0
 
@@ -13,6 +9,3 @@
 /vendor/lib(64)?/arm\.graphics-V5-ndk\.so                                      u:object_r:same_process_hal_file:s0
 /vendor/lib(64)?/hw/android\.hardware\.graphics\.mapper@4\.0-impl-arm\.so      u:object_r:same_process_hal_file:s0
 /vendor/lib(64)?/hw/mapper\.arm\.so                                            u:object_r:same_process_hal_file:s0
-
-# egl
-/vendor/lib(64)?/egl/libGLES_mali\.so                                          u:object_r:same_process_hal_file:s0
diff --git a/graphics/gpu/sepolicy/hal_graphics_allocator_default.te b/graphics/allocator/arm/sepolicy/hal_graphics_allocator_default.te
similarity index 100%
rename from graphics/gpu/sepolicy/hal_graphics_allocator_default.te
rename to graphics/allocator/arm/sepolicy/hal_graphics_allocator_default.te
diff --git a/graphics/allocator/device.mk b/graphics/allocator/device.mk
new file mode 100644
index 0000000..17f10d7
--- /dev/null
+++ b/graphics/allocator/device.mk
@@ -0,0 +1,25 @@
+#
+# Copyright 2024 BayLibre SAS
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Backend
+TARGET_ALLOCATOR_BACKEND ?= arm
+ifeq ($(TARGET_ALLOCATOR_BACKEND), arm)
+$(call inherit-product, device/mediatek/common/graphics/allocator/arm/device.mk)
+else ifeq ($(TARGET_ALLOCATOR_BACKEND), minigbm)
+$(call inherit-product, device/mediatek/common/graphics/allocator/minigbm/device.mk)
+else
+$(error TARGET_ALLOCATOR_BACKEND not supported)
+endif
diff --git a/graphics/allocator/minigbm/BoardConfig.mk b/graphics/allocator/minigbm/BoardConfig.mk
new file mode 100644
index 0000000..90b4ad4
--- /dev/null
+++ b/graphics/allocator/minigbm/BoardConfig.mk
@@ -0,0 +1,22 @@
+#
+# Copyright 2024 BayLibre SAS
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
+$(warning Minigbm works only with SELinux as permissive)
+endif
+
+# Sepolicy
+BOARD_SEPOLICY_DIRS += device/mediatek/common/graphics/allocator/minigbm/sepolicy
diff --git a/graphics/allocator/minigbm/device.mk b/graphics/allocator/minigbm/device.mk
new file mode 100644
index 0000000..1b7fd24
--- /dev/null
+++ b/graphics/allocator/minigbm/device.mk
@@ -0,0 +1,25 @@
+#
+# Copyright 2024 BayLibre SAS
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Minigbm mapper/allocator
+PRODUCT_PACKAGES += \
+    android.hardware.graphics.allocator-service.minigbm \
+    android.hardware.graphics.mapper@4.0-impl.minigbm \
+    gralloc.minigbm \
+    libminigbm_gralloc \
+    mapper.minigbm
+
+PRODUCT_VENDOR_PROPERTIES += ro.hardware.gralloc=minigbm
diff --git a/graphics/allocator/minigbm/sepolicy/file_contexts b/graphics/allocator/minigbm/sepolicy/file_contexts
new file mode 100644
index 0000000..823715c
--- /dev/null
+++ b/graphics/allocator/minigbm/sepolicy/file_contexts
@@ -0,0 +1,7 @@
+# minigbm
+/vendor/bin/hw/android\.hardware\.graphics\.allocator-service\.minigbm         u:object_r:hal_graphics_allocator_default_exec:s0
+/vendor/lib(64)?/hw/android\.hardware\.graphics\.mapper@4\.0-impl\.minigbm\.so u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/hw/gralloc\.minigbm\.so                                       u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/hw/mapper\.minigbm\.so                                        u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/libminigbm_gralloc.so                                         u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/libminigbm_gralloc4_utils.so                                  u:object_r:same_process_hal_file:s0
diff --git a/graphics/sepolicy/hal_graphics_allocator_default.te b/graphics/allocator/sepolicy/hal_graphics_allocator_default.te
similarity index 100%
rename from graphics/sepolicy/hal_graphics_allocator_default.te
rename to graphics/allocator/sepolicy/hal_graphics_allocator_default.te
diff --git a/graphics/sepolicy/hal_graphics_composer_default.te b/graphics/allocator/sepolicy/hal_graphics_composer_default.te
similarity index 100%
rename from graphics/sepolicy/hal_graphics_composer_default.te
rename to graphics/allocator/sepolicy/hal_graphics_composer_default.te
diff --git a/display/BoardConfig.mk b/graphics/composer/BoardConfig.mk
similarity index 87%
rename from display/BoardConfig.mk
rename to graphics/composer/BoardConfig.mk
index a595ccf..79a7be1 100644
--- a/display/BoardConfig.mk
+++ b/graphics/composer/BoardConfig.mk
@@ -14,5 +14,5 @@
 # limitations under the License.
 #
 
-# sepolicy
-BOARD_SEPOLICY_DIRS += device/mediatek/common/display/sepolicy
+# Sepolicy
+BOARD_SEPOLICY_DIRS += device/mediatek/common/graphics/composer/sepolicy
diff --git a/display/device.mk b/graphics/composer/device.mk
similarity index 100%
rename from display/device.mk
rename to graphics/composer/device.mk
diff --git a/display/display_settings.xml b/graphics/composer/display_settings.xml
similarity index 100%
rename from display/display_settings.xml
rename to graphics/composer/display_settings.xml
diff --git a/display/sepolicy/file.te b/graphics/composer/sepolicy/file.te
similarity index 100%
rename from display/sepolicy/file.te
rename to graphics/composer/sepolicy/file.te
diff --git a/display/sepolicy/file_contexts b/graphics/composer/sepolicy/file_contexts
similarity index 100%
rename from display/sepolicy/file_contexts
rename to graphics/composer/sepolicy/file_contexts
diff --git a/display/sepolicy/hal_drm_default.te b/graphics/composer/sepolicy/hal_drm_default.te
similarity index 100%
rename from display/sepolicy/hal_drm_default.te
rename to graphics/composer/sepolicy/hal_drm_default.te
diff --git a/graphics/composer/sepolicy/hal_graphics_composer_default.te b/graphics/composer/sepolicy/hal_graphics_composer_default.te
new file mode 100644
index 0000000..46bd902
--- /dev/null
+++ b/graphics/composer/sepolicy/hal_graphics_composer_default.te
@@ -0,0 +1,10 @@
+vndbinder_use(hal_graphics_composer_default);
+hal_client_domain(hal_graphics_composer_default, hal_graphics_allocator);
+
+allow hal_graphics_composer_default self:netlink_kobject_uevent_socket create_socket_perms_no_ioctl;
+
+allow hal_graphics_composer_default gpu_device:chr_file { open read write ioctl };
+
+get_prop(hal_graphics_composer_default, vendor_cf_graphics_config_prop)
+
+allow hal_graphics_composer_default hal_graphics_allocator_default_tmpfs:file { read write map };
diff --git a/display/sepolicy/property_contexts b/graphics/composer/sepolicy/property_contexts
similarity index 100%
rename from display/sepolicy/property_contexts
rename to graphics/composer/sepolicy/property_contexts
diff --git a/graphics/device.mk b/graphics/device.mk
index 40e6861..5543e0a 100644
--- a/graphics/device.mk
+++ b/graphics/device.mk
@@ -14,16 +14,9 @@
 # limitations under the License.
 #
 
-# GPU / Soft
-ifeq ($(GRAPHICS_SOFT_ENABLE), true)
-$(call inherit-product, device/mediatek/common/graphics/soft/device.mk)
-else
-$(call inherit-product, device/mediatek/common/graphics/gpu/device.mk)
-endif
 
-# Vulkan
-PRODUCT_COPY_FILES += \
-    frameworks/native/data/etc/android.hardware.vulkan.version-1_1.xml:vendor/etc/permissions/android.hardware.vulkan.version.xml \
-    frameworks/native/data/etc/android.hardware.vulkan.compute-0.xml:vendor/etc/permissions/android.hardware.vulkan.compute.xml \
-    frameworks/native/data/etc/android.hardware.vulkan.level-1.xml:vendor/etc/permissions/android.hardware.vulkan.level.xml \
-    frameworks/native/data/etc/android.software.vulkan.deqp.level-2020-03-01.xml:vendor/etc/permissions/android.software.vulkan.deqp.level.xml
+$(call inherit-product, device/mediatek/common/graphics/allocator/device.mk)
+
+$(call inherit-product, device/mediatek/common/graphics/composer/device.mk)
+
+$(call inherit-product, device/mediatek/common/graphics/egl/device.mk)
diff --git a/graphics/egl/BoardConfig.mk b/graphics/egl/BoardConfig.mk
new file mode 100644
index 0000000..a6ff49a
--- /dev/null
+++ b/graphics/egl/BoardConfig.mk
@@ -0,0 +1,27 @@
+#
+# Copyright 2024 BayLibre SAS
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Sepolicy
+BOARD_SEPOLICY_DIRS += device/mediatek/common/graphics/egl/sepolicy
+
+# Backend
+ifeq ($(TARGET_GPU_BACKEND), mali)
+include device/mediatek/common/graphics/egl/mali/BoardConfig.mk
+else ifeq ($(TARGET_GPU_BACKEND), swangle)
+include device/mediatek/common/graphics/egl/swangle/BoardConfig.mk
+else
+$(error TARGET_GPU_BACKEND not supported)
+endif
diff --git a/graphics/egl/device.mk b/graphics/egl/device.mk
new file mode 100644
index 0000000..ecd9139
--- /dev/null
+++ b/graphics/egl/device.mk
@@ -0,0 +1,35 @@
+#
+# Copyright 2024 BayLibre SAS
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Backend
+TARGET_GPU_BACKEND ?= mali
+ifeq ($(TARGET_GPU_BACKEND), mali)
+$(call inherit-product, device/mediatek/common/graphics/egl/mali/device.mk)
+else ifeq ($(TARGET_GPU_BACKEND), swangle)
+$(call inherit-product, device/mediatek/common/graphics/egl/swangle/device.mk)
+else
+$(error TARGET_GPU_BACKEND not supported)
+endif
+
+# scrcpy
+PRODUCT_VENDOR_PROPERTIES += debug.stagefright.c2inputsurface=-1
+
+# Vulkan
+PRODUCT_COPY_FILES += \
+    frameworks/native/data/etc/android.hardware.vulkan.version-1_1.xml:vendor/etc/permissions/android.hardware.vulkan.version.xml \
+    frameworks/native/data/etc/android.hardware.vulkan.compute-0.xml:vendor/etc/permissions/android.hardware.vulkan.compute.xml \
+    frameworks/native/data/etc/android.hardware.vulkan.level-1.xml:vendor/etc/permissions/android.hardware.vulkan.level.xml \
+    frameworks/native/data/etc/android.software.vulkan.deqp.level-2020-03-01.xml:vendor/etc/permissions/android.software.vulkan.deqp.level.xml
diff --git a/graphics/egl/mali/BoardConfig.mk b/graphics/egl/mali/BoardConfig.mk
new file mode 100644
index 0000000..17c9922
--- /dev/null
+++ b/graphics/egl/mali/BoardConfig.mk
@@ -0,0 +1,18 @@
+#
+# Copyright 2024 BayLibre SAS
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Sepolicy
+BOARD_SEPOLICY_DIRS += device/mediatek/common/graphics/egl/mali/sepolicy
diff --git a/graphics/gpu/device.mk b/graphics/egl/mali/device.mk
similarity index 80%
rename from graphics/gpu/device.mk
rename to graphics/egl/mali/device.mk
index fc0d0ab..e652d78 100644
--- a/graphics/gpu/device.mk
+++ b/graphics/egl/mali/device.mk
@@ -14,15 +14,6 @@
 # limitations under the License.
 #
 
-# ARM mapper/allocator
-PRODUCT_PACKAGES += \
-    android.hardware.graphics.mapper@4.0-impl-arm \
-    android.hardware.graphics.allocator-service \
-    mapper.arm
-
-PRODUCT_COPY_FILES += \
-    $(LOCAL_PATH)/capabilities.xml:$(TARGET_COPY_OUT_VENDOR)/etc/gralloc/capabilities.xml
-
 # Mali
 PRODUCT_PACKAGES += \
     libGLES_mali \
diff --git a/graphics/egl/mali/sepolicy/file_contexts b/graphics/egl/mali/sepolicy/file_contexts
new file mode 100644
index 0000000..7d3fc1a
--- /dev/null
+++ b/graphics/egl/mali/sepolicy/file_contexts
@@ -0,0 +1,6 @@
+# mali
+/dev/mali[0-9]                             u:object_r:gpu_device:s0
+/vendor/lib(64)?/hw/vulkan\.mali\.so       u:object_r:same_process_hal_file:s0
+
+# egl
+/vendor/lib(64)?/egl/libGLES_mali\.so      u:object_r:same_process_hal_file:s0
diff --git a/graphics/egl/sepolicy/file_contexts b/graphics/egl/sepolicy/file_contexts
new file mode 100644
index 0000000..d835654
--- /dev/null
+++ b/graphics/egl/sepolicy/file_contexts
@@ -0,0 +1,11 @@
+# allocator
+/vendor/lib(64)?/android\.hardware\.graphics\.allocator@2\.0\.so  u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/android\.hardware\.graphics\.allocator@3\.0\.so  u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/android\.hardware\.graphics\.allocator@4\.0\.so  u:object_r:same_process_hal_file:s0
+
+# mapper
+/vendor/lib(64)?/android\.hardware\.graphics\.mapper@2.0.so       u:object_r:same_process_hal_file:s0
+
+# libui
+/vendor/lib(64)?/libui\.so                                        u:object_r:same_process_hal_file:s0
+
diff --git a/graphics/sepolicy/property_contexts b/graphics/egl/sepolicy/property_contexts
similarity index 100%
rename from graphics/sepolicy/property_contexts
rename to graphics/egl/sepolicy/property_contexts
diff --git a/graphics/soft/BoardConfig.mk b/graphics/egl/swangle/BoardConfig.mk
similarity index 64%
rename from graphics/soft/BoardConfig.mk
rename to graphics/egl/swangle/BoardConfig.mk
index 9ebb0e9..5396fe8 100644
--- a/graphics/soft/BoardConfig.mk
+++ b/graphics/egl/swangle/BoardConfig.mk
@@ -14,15 +14,5 @@
 # limitations under the License.
 #
 
-# Swiftshader needs to create executable memory and cannot be executed
-# with SELinux as enforcing.
-ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT)))
-$(warning SELinux set as permissive)
-BOARD_KERNEL_CMDLINE += androidboot.selinux=permissive
-endif
-
-# SwAngle Sepolicy
+# Sepolicy
 BOARD_SEPOLICY_DIRS += device/linaro/dragonboard/shared/graphics/swangle/sepolicy
-
-# Soft Sepolicy
-BOARD_SEPOLICY_DIRS += device/mediatek/common/graphics/soft/sepolicy
diff --git a/graphics/soft/device.mk b/graphics/egl/swangle/device.mk
similarity index 80%
rename from graphics/soft/device.mk
rename to graphics/egl/swangle/device.mk
index 6e889dc..38578f5 100644
--- a/graphics/soft/device.mk
+++ b/graphics/egl/swangle/device.mk
@@ -14,14 +14,6 @@
 # limitations under the License.
 #
 
-# Minigbm mapper/allocator
-PRODUCT_PACKAGES += \
-    android.hardware.graphics.allocator-service.minigbm \
-    mapper.minigbm
-
-# scrcpy
-PRODUCT_VENDOR_PROPERTIES += debug.stagefright.c2inputsurface=-1
-
 # SwAngle
 $(call inherit-product, device/linaro/dragonboard/shared/graphics/swangle/device.mk)
 
diff --git a/graphics/sepolicy/file_contexts b/graphics/sepolicy/file_contexts
index fbc757f..eeaca49 100644
--- a/graphics/sepolicy/file_contexts
+++ b/graphics/sepolicy/file_contexts
@@ -1,14 +1,2 @@
 # graphics cards
 /dev/dri/card[0-9]*    u:object_r:dri_device:s0
-
-# allocator
-/vendor/lib(64)?/android\.hardware\.graphics\.allocator@2\.0\.so  u:object_r:same_process_hal_file:s0
-/vendor/lib(64)?/android\.hardware\.graphics\.allocator@3\.0\.so  u:object_r:same_process_hal_file:s0
-/vendor/lib(64)?/android\.hardware\.graphics\.allocator@4\.0\.so  u:object_r:same_process_hal_file:s0
-
-# mapper
-/vendor/lib(64)?/android\.hardware\.graphics\.mapper@2.0.so       u:object_r:same_process_hal_file:s0
-
-# libui
-/vendor/lib(64)?/libui\.so                                        u:object_r:same_process_hal_file:s0
-
diff --git a/graphics/soft/sepolicy/file_contexts b/graphics/soft/sepolicy/file_contexts
deleted file mode 100644
index dc808ca..0000000
--- a/graphics/soft/sepolicy/file_contexts
+++ /dev/null
@@ -1,5 +0,0 @@
-# minigbm
-/vendor/bin/hw/android\.hardware\.graphics\.allocator-service\.minigbm   u:object_r:hal_graphics_allocator_default_exec:s0
-/vendor/lib(64)?/hw/mapper\.minigbm\.so                                  u:object_r:same_process_hal_file:s0
-/vendor/lib(64)?/libminigbm_gralloc.so                                   u:object_r:same_process_hal_file:s0
-/vendor/lib(64)?/libminigbm_gralloc4_utils.so                            u:object_r:same_process_hal_file:s0
diff --git a/mt8188/mt8188.mk b/mt8188/mt8188.mk
index 4e936fe..c562c3a 100644
--- a/mt8188/mt8188.mk
+++ b/mt8188/mt8188.mk
@@ -15,7 +15,8 @@
 #
 
 # Grahics software rendering with VKMS on /dev/dri/card0
-GRAPHICS_SOFT_ENABLE := true
+TARGET_GPU_BACKEND := swangle
+TARGET_ALLOCATOR_BACKEND := minigbm
 PRODUCT_VENDOR_PROPERTIES += vendor.hwc.drm.device=/dev/dri/card0
 
 $(call inherit-product, device/mediatek/common/device.mk)
-- 
GitLab


From d36d0c2c84686d9753bafcdcece1ea368eb8ec37 Mon Sep 17 00:00:00 2001
From: Julien Masson <jmasson@baylibre.com>
Date: Mon, 2 Dec 2024 12:44:29 +0100
Subject: [PATCH 2/6] graphics: sepolicy: add dri SELinux rules

SELinux errors are raised concerning dri_device, several rules have
been added to fix them.

Error example:
I/android.hardwar: type=1400 audit(0.0:62): avc:  denied  { search } for  name="dri" dev="tmpfs" ino=697 scontext=u:r:hal_graphics_allocator_default:s0 tcontext=u:object_r:dri_device:s0 tclass=dir permissive=1

Signed-off-by: Julien Masson <jmasson@baylibre.com>
---
 graphics/allocator/sepolicy/hal_graphics_allocator_default.te | 1 +
 graphics/composer/sepolicy/hal_graphics_composer_default.te   | 2 ++
 graphics/sepolicy/bootanim.te                                 | 1 +
 graphics/sepolicy/file_contexts                               | 1 +
 graphics/sepolicy/mediaswcodec.te                             | 1 +
 graphics/sepolicy/platform_app.te                             | 1 +
 graphics/sepolicy/priv_app.te                                 | 1 +
 graphics/sepolicy/recovery.te                                 | 1 +
 graphics/sepolicy/surfaceflinger.te                           | 1 +
 graphics/sepolicy/system_app.te                               | 1 +
 graphics/sepolicy/system_server.te                            | 1 +
 11 files changed, 12 insertions(+)
 create mode 100644 graphics/sepolicy/recovery.te

diff --git a/graphics/allocator/sepolicy/hal_graphics_allocator_default.te b/graphics/allocator/sepolicy/hal_graphics_allocator_default.te
index 198ec2a..646da52 100644
--- a/graphics/allocator/sepolicy/hal_graphics_allocator_default.te
+++ b/graphics/allocator/sepolicy/hal_graphics_allocator_default.te
@@ -1,2 +1,3 @@
 allow hal_graphics_allocator_default gpu_device:chr_file rw_file_perms;
 allow hal_graphics_allocator_default dri_device:chr_file rw_file_perms;
+allow hal_graphics_allocator_default dri_device:dir r_dir_perms;
diff --git a/graphics/composer/sepolicy/hal_graphics_composer_default.te b/graphics/composer/sepolicy/hal_graphics_composer_default.te
index 46bd902..7bb4905 100644
--- a/graphics/composer/sepolicy/hal_graphics_composer_default.te
+++ b/graphics/composer/sepolicy/hal_graphics_composer_default.te
@@ -3,6 +3,8 @@ hal_client_domain(hal_graphics_composer_default, hal_graphics_allocator);
 
 allow hal_graphics_composer_default self:netlink_kobject_uevent_socket create_socket_perms_no_ioctl;
 
+allow hal_graphics_composer_default dri_device:chr_file rw_file_perms;
+allow hal_graphics_composer_default dri_device:dir r_dir_perms;
 allow hal_graphics_composer_default gpu_device:chr_file { open read write ioctl };
 
 get_prop(hal_graphics_composer_default, vendor_cf_graphics_config_prop)
diff --git a/graphics/sepolicy/bootanim.te b/graphics/sepolicy/bootanim.te
index 9ed83fa..d2d4151 100644
--- a/graphics/sepolicy/bootanim.te
+++ b/graphics/sepolicy/bootanim.te
@@ -1 +1,2 @@
 allow bootanim dri_device:chr_file rw_file_perms;
+allow bootanim dri_device:dir r_dir_perms;
diff --git a/graphics/sepolicy/file_contexts b/graphics/sepolicy/file_contexts
index eeaca49..f8c62ba 100644
--- a/graphics/sepolicy/file_contexts
+++ b/graphics/sepolicy/file_contexts
@@ -1,2 +1,3 @@
 # graphics cards
+/dev/dri               u:object_r:dri_device:s0
 /dev/dri/card[0-9]*    u:object_r:dri_device:s0
diff --git a/graphics/sepolicy/mediaswcodec.te b/graphics/sepolicy/mediaswcodec.te
index b0d4c88..1cc8077 100644
--- a/graphics/sepolicy/mediaswcodec.te
+++ b/graphics/sepolicy/mediaswcodec.te
@@ -1 +1,2 @@
 allow mediaswcodec dri_device:chr_file rw_file_perms;
+allow mediaswcodec dri_device:dir r_dir_perms;
diff --git a/graphics/sepolicy/platform_app.te b/graphics/sepolicy/platform_app.te
index 6f2fadb..b3a8025 100644
--- a/graphics/sepolicy/platform_app.te
+++ b/graphics/sepolicy/platform_app.te
@@ -1 +1,2 @@
 allow platform_app dri_device:chr_file rw_file_perms;
+allow platform_app dri_device:dir r_dir_perms;
diff --git a/graphics/sepolicy/priv_app.te b/graphics/sepolicy/priv_app.te
index 8bd0018..44710c8 100644
--- a/graphics/sepolicy/priv_app.te
+++ b/graphics/sepolicy/priv_app.te
@@ -1 +1,2 @@
 allow priv_app dri_device:chr_file rw_file_perms;
+allow priv_app dri_device:dir r_dir_perms;
diff --git a/graphics/sepolicy/recovery.te b/graphics/sepolicy/recovery.te
new file mode 100644
index 0000000..252cafe
--- /dev/null
+++ b/graphics/sepolicy/recovery.te
@@ -0,0 +1 @@
+allow recovery dri_device:dir r_dir_perms;
diff --git a/graphics/sepolicy/surfaceflinger.te b/graphics/sepolicy/surfaceflinger.te
index c8bc9c5..e9d1365 100644
--- a/graphics/sepolicy/surfaceflinger.te
+++ b/graphics/sepolicy/surfaceflinger.te
@@ -1 +1,2 @@
 allow surfaceflinger dri_device:chr_file rw_file_perms;
+allow surfaceflinger dri_device:dir r_dir_perms;
\ No newline at end of file
diff --git a/graphics/sepolicy/system_app.te b/graphics/sepolicy/system_app.te
index 619d701..3c5a860 100644
--- a/graphics/sepolicy/system_app.te
+++ b/graphics/sepolicy/system_app.te
@@ -1 +1,2 @@
 allow system_app dri_device:chr_file rw_file_perms;
+allow system_app dri_device:dir r_dir_perms;
diff --git a/graphics/sepolicy/system_server.te b/graphics/sepolicy/system_server.te
index 182e05d..0d52c28 100644
--- a/graphics/sepolicy/system_server.te
+++ b/graphics/sepolicy/system_server.te
@@ -1 +1,2 @@
 allow system_server dri_device:chr_file rw_file_perms;
+allow system_server dri_device:dir r_dir_perms;
-- 
GitLab


From 531cf6bd6bf1d447ba7de217e2f9390898218a08 Mon Sep 17 00:00:00 2001
From: Julien Masson <jmasson@baylibre.com>
Date: Mon, 2 Dec 2024 12:49:36 +0100
Subject: [PATCH 3/6] graphics: sepolicy: add sysfs_display

Several uevent sysfs related to graphics must be label as
sysfs_display.
Additionnals SELinux have been for services/processes which interact
with these nodes.

Signed-off-by: Julien Masson <jmasson@baylibre.com>
---
 graphics/sepolicy/bootanim.te       | 1 +
 graphics/sepolicy/file.te           | 1 +
 graphics/sepolicy/genfs_contexts    | 4 ++++
 graphics/sepolicy/platform_app.te   | 1 +
 graphics/sepolicy/priv_app.te       | 1 +
 graphics/sepolicy/surfaceflinger.te | 3 ++-
 graphics/sepolicy/system_app.te     | 1 +
 7 files changed, 11 insertions(+), 1 deletion(-)
 create mode 100644 graphics/sepolicy/genfs_contexts

diff --git a/graphics/sepolicy/bootanim.te b/graphics/sepolicy/bootanim.te
index d2d4151..a5cc8c2 100644
--- a/graphics/sepolicy/bootanim.te
+++ b/graphics/sepolicy/bootanim.te
@@ -1,2 +1,3 @@
 allow bootanim dri_device:chr_file rw_file_perms;
 allow bootanim dri_device:dir r_dir_perms;
+allow bootanim sysfs_display:file r_file_perms;
diff --git a/graphics/sepolicy/file.te b/graphics/sepolicy/file.te
index 8b54b20..177bb5d 100644
--- a/graphics/sepolicy/file.te
+++ b/graphics/sepolicy/file.te
@@ -1 +1,2 @@
 type dri_device, dev_type;
+type sysfs_display, fs_type, sysfs_type;
diff --git a/graphics/sepolicy/genfs_contexts b/graphics/sepolicy/genfs_contexts
new file mode 100644
index 0000000..054da3f
--- /dev/null
+++ b/graphics/sepolicy/genfs_contexts
@@ -0,0 +1,4 @@
+genfscon sysfs /devices/platform/soc/14000000.syscon/mediatek-drm.1.auto/uevent u:object_r:sysfs_display:s0
+genfscon sysfs /devices/platform/soc/13040000.mali/uevent u:object_r:sysfs_display:s0
+genfscon sysfs /devices/platform/vkms/uevent u:object_r:sysfs_display:s0
+genfscon sysfs /devices/platform/apu@0/uevent u:object_r:sysfs_display:s0
diff --git a/graphics/sepolicy/platform_app.te b/graphics/sepolicy/platform_app.te
index b3a8025..3a7e5c1 100644
--- a/graphics/sepolicy/platform_app.te
+++ b/graphics/sepolicy/platform_app.te
@@ -1,2 +1,3 @@
 allow platform_app dri_device:chr_file rw_file_perms;
 allow platform_app dri_device:dir r_dir_perms;
+allow platform_app sysfs_display:file r_file_perms;
diff --git a/graphics/sepolicy/priv_app.te b/graphics/sepolicy/priv_app.te
index 44710c8..1165b14 100644
--- a/graphics/sepolicy/priv_app.te
+++ b/graphics/sepolicy/priv_app.te
@@ -1,2 +1,3 @@
 allow priv_app dri_device:chr_file rw_file_perms;
 allow priv_app dri_device:dir r_dir_perms;
+allow priv_app sysfs_display:file r_file_perms;
diff --git a/graphics/sepolicy/surfaceflinger.te b/graphics/sepolicy/surfaceflinger.te
index e9d1365..861463e 100644
--- a/graphics/sepolicy/surfaceflinger.te
+++ b/graphics/sepolicy/surfaceflinger.te
@@ -1,2 +1,3 @@
 allow surfaceflinger dri_device:chr_file rw_file_perms;
-allow surfaceflinger dri_device:dir r_dir_perms;
\ No newline at end of file
+allow surfaceflinger dri_device:dir r_dir_perms;
+allow surfaceflinger sysfs_display:file r_file_perms;
diff --git a/graphics/sepolicy/system_app.te b/graphics/sepolicy/system_app.te
index 3c5a860..44220d4 100644
--- a/graphics/sepolicy/system_app.te
+++ b/graphics/sepolicy/system_app.te
@@ -1,2 +1,3 @@
 allow system_app dri_device:chr_file rw_file_perms;
 allow system_app dri_device:dir r_dir_perms;
+allow system_app sysfs_display:file r_file_perms;
-- 
GitLab


From 06adbef96e74944d7d66b63b008c22483918126d Mon Sep 17 00:00:00 2001
From: Julien Masson <jmasson@baylibre.com>
Date: Mon, 2 Dec 2024 12:51:50 +0100
Subject: [PATCH 4/6] graphics: egl: add mesa support

mesa is the open source implementations of OpenGL, Vulkan ...
It's now supported in our build environment, it can be used as an
alternative TARGET_GPU_BACKEND.

Signed-off-by: Julien Masson <jmasson@baylibre.com>
---
 graphics/egl/BoardConfig.mk              |  2 ++
 graphics/egl/device.mk                   |  2 ++
 graphics/egl/mesa/BoardConfig.mk         | 18 ++++++++++++++
 graphics/egl/mesa/device.mk              | 31 ++++++++++++++++++++++++
 graphics/egl/mesa/sepolicy/file_contexts | 10 ++++++++
 5 files changed, 63 insertions(+)
 create mode 100644 graphics/egl/mesa/BoardConfig.mk
 create mode 100644 graphics/egl/mesa/device.mk
 create mode 100644 graphics/egl/mesa/sepolicy/file_contexts

diff --git a/graphics/egl/BoardConfig.mk b/graphics/egl/BoardConfig.mk
index a6ff49a..cd79343 100644
--- a/graphics/egl/BoardConfig.mk
+++ b/graphics/egl/BoardConfig.mk
@@ -20,6 +20,8 @@ BOARD_SEPOLICY_DIRS += device/mediatek/common/graphics/egl/sepolicy
 # Backend
 ifeq ($(TARGET_GPU_BACKEND), mali)
 include device/mediatek/common/graphics/egl/mali/BoardConfig.mk
+else ifeq ($(TARGET_GPU_BACKEND), mesa)
+include device/mediatek/common/graphics/egl/mesa/BoardConfig.mk
 else ifeq ($(TARGET_GPU_BACKEND), swangle)
 include device/mediatek/common/graphics/egl/swangle/BoardConfig.mk
 else
diff --git a/graphics/egl/device.mk b/graphics/egl/device.mk
index ecd9139..f8a10be 100644
--- a/graphics/egl/device.mk
+++ b/graphics/egl/device.mk
@@ -18,6 +18,8 @@
 TARGET_GPU_BACKEND ?= mali
 ifeq ($(TARGET_GPU_BACKEND), mali)
 $(call inherit-product, device/mediatek/common/graphics/egl/mali/device.mk)
+else ifeq ($(TARGET_GPU_BACKEND), mesa)
+$(call inherit-product, device/mediatek/common/graphics/egl/mesa/device.mk)
 else ifeq ($(TARGET_GPU_BACKEND), swangle)
 $(call inherit-product, device/mediatek/common/graphics/egl/swangle/device.mk)
 else
diff --git a/graphics/egl/mesa/BoardConfig.mk b/graphics/egl/mesa/BoardConfig.mk
new file mode 100644
index 0000000..46f61d5
--- /dev/null
+++ b/graphics/egl/mesa/BoardConfig.mk
@@ -0,0 +1,18 @@
+#
+# Copyright 2024 BayLibre SAS
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Sepolicy
+BOARD_SEPOLICY_DIRS += device/mediatek/common/graphics/egl/mesa/sepolicy
diff --git a/graphics/egl/mesa/device.mk b/graphics/egl/mesa/device.mk
new file mode 100644
index 0000000..234f852
--- /dev/null
+++ b/graphics/egl/mesa/device.mk
@@ -0,0 +1,31 @@
+#
+# Copyright 2024 BayLibre SAS
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Mesa
+PRODUCT_PACKAGES += \
+    libGLES_mesa \
+    libgallium_dri \
+    libglapi \
+    vulkan.mesa
+
+PRODUCT_PROPERTY_OVERRIDES += \
+    ro.hardware.egl=mesa \
+    ro.hardware.vulkan=mesa
+
+# opengles features
+PRODUCT_COPY_FILES += \
+    frameworks/native/data/etc/android.hardware.opengles.aep.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.opengles.aep.xml \
+    frameworks/native/data/etc/android.software.opengles.deqp.level-2021-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml
diff --git a/graphics/egl/mesa/sepolicy/file_contexts b/graphics/egl/mesa/sepolicy/file_contexts
new file mode 100644
index 0000000..7ff8b7d
--- /dev/null
+++ b/graphics/egl/mesa/sepolicy/file_contexts
@@ -0,0 +1,10 @@
+# render
+/dev/dri/renderD128                                                      u:object_r:gpu_device:s0
+
+# egl
+/vendor/lib(64)?/egl/libGLES_mesa\.so                                    u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/egl/libgallium_dri\.so                                  u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/egl/libglapi\.so                                        u:object_r:same_process_hal_file:s0
+
+# vulkan
+/vendor/lib(64)?/hw/vulkan\.mesa\.so                                     u:object_r:same_process_hal_file:s0
-- 
GitLab


From f9020cc72c1d56253c5eedd3dc9389c39cd6abb8 Mon Sep 17 00:00:00 2001
From: Julien Masson <jmasson@baylibre.com>
Date: Mon, 2 Dec 2024 20:17:39 +0100
Subject: [PATCH 5/6] graphics: egl: opengles features for all GPU backends

The opengles xml files should be added to vendor for all GPU backends.

Signed-off-by: Julien Masson <jmasson@baylibre.com>
---
 graphics/egl/device.mk      | 5 +++++
 graphics/egl/mali/device.mk | 5 -----
 graphics/egl/mesa/device.mk | 5 -----
 3 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/graphics/egl/device.mk b/graphics/egl/device.mk
index f8a10be..bf5eb7d 100644
--- a/graphics/egl/device.mk
+++ b/graphics/egl/device.mk
@@ -29,6 +29,11 @@ endif
 # scrcpy
 PRODUCT_VENDOR_PROPERTIES += debug.stagefright.c2inputsurface=-1
 
+# opengles features
+PRODUCT_COPY_FILES += \
+    frameworks/native/data/etc/android.hardware.opengles.aep.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.opengles.aep.xml \
+    frameworks/native/data/etc/android.software.opengles.deqp.level-2021-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml
+
 # Vulkan
 PRODUCT_COPY_FILES += \
     frameworks/native/data/etc/android.hardware.vulkan.version-1_1.xml:vendor/etc/permissions/android.hardware.vulkan.version.xml \
diff --git a/graphics/egl/mali/device.mk b/graphics/egl/mali/device.mk
index e652d78..17bf6ef 100644
--- a/graphics/egl/mali/device.mk
+++ b/graphics/egl/mali/device.mk
@@ -23,8 +23,3 @@ PRODUCT_PACKAGES += \
 PRODUCT_PROPERTY_OVERRIDES += \
     ro.hardware.egl=mali \
     ro.hardware.vulkan=mali
-
-# opengles features
-PRODUCT_COPY_FILES += \
-    frameworks/native/data/etc/android.hardware.opengles.aep.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.opengles.aep.xml \
-    frameworks/native/data/etc/android.software.opengles.deqp.level-2021-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml
diff --git a/graphics/egl/mesa/device.mk b/graphics/egl/mesa/device.mk
index 234f852..bc02df7 100644
--- a/graphics/egl/mesa/device.mk
+++ b/graphics/egl/mesa/device.mk
@@ -24,8 +24,3 @@ PRODUCT_PACKAGES += \
 PRODUCT_PROPERTY_OVERRIDES += \
     ro.hardware.egl=mesa \
     ro.hardware.vulkan=mesa
-
-# opengles features
-PRODUCT_COPY_FILES += \
-    frameworks/native/data/etc/android.hardware.opengles.aep.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.opengles.aep.xml \
-    frameworks/native/data/etc/android.software.opengles.deqp.level-2021-03-01.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.software.opengles.deqp.level.xml
-- 
GitLab


From 4ce49816b6b8523853e95d403d0e9689de16e407 Mon Sep 17 00:00:00 2001
From: Julien Masson <jmasson@baylibre.com>
Date: Mon, 2 Dec 2024 20:33:00 +0100
Subject: [PATCH 6/6] graphics: egl: swangle: use own configs

several configs defined in linaro/dragonboard are in conflict with
mediatek configs like density property.
Let's define a minimal config for swangle in our project.

Signed-off-by: Julien Masson <jmasson@baylibre.com>
---
 graphics/egl/swangle/BoardConfig.mk         |  2 +-
 graphics/egl/swangle/device.mk              | 12 +++++++++++-
 graphics/egl/swangle/sepolicy/file_contexts |  5 +++++
 graphics/egl/swangle/sepolicy/sw_execmem.te |  5 +++++
 4 files changed, 22 insertions(+), 2 deletions(-)
 create mode 100644 graphics/egl/swangle/sepolicy/file_contexts
 create mode 100644 graphics/egl/swangle/sepolicy/sw_execmem.te

diff --git a/graphics/egl/swangle/BoardConfig.mk b/graphics/egl/swangle/BoardConfig.mk
index 5396fe8..28149e1 100644
--- a/graphics/egl/swangle/BoardConfig.mk
+++ b/graphics/egl/swangle/BoardConfig.mk
@@ -15,4 +15,4 @@
 #
 
 # Sepolicy
-BOARD_SEPOLICY_DIRS += device/linaro/dragonboard/shared/graphics/swangle/sepolicy
+BOARD_SEPOLICY_DIRS += device/mediatek/common/graphics/egl/swangle/sepolicy
diff --git a/graphics/egl/swangle/device.mk b/graphics/egl/swangle/device.mk
index 38578f5..ea5a438 100644
--- a/graphics/egl/swangle/device.mk
+++ b/graphics/egl/swangle/device.mk
@@ -15,7 +15,17 @@
 #
 
 # SwAngle
-$(call inherit-product, device/linaro/dragonboard/shared/graphics/swangle/device.mk)
+PRODUCT_REQUIRES_INSECURE_EXECMEM_FOR_SWIFTSHADER := true
+
+PRODUCT_PACKAGES := \
+    libEGL_angle \
+    libGLESv1_CM_angle \
+    libGLESv2_angle \
+    vulkan.pastel
+
+PRODUCT_VENDOR_PROPERTIES := \
+    ro.hardware.egl=angle \
+    ro.hardware.vulkan=pastel
 
 # SwAngle on vendor
 $(call soong_config_set,angle,angle_on_system,false)
diff --git a/graphics/egl/swangle/sepolicy/file_contexts b/graphics/egl/swangle/sepolicy/file_contexts
new file mode 100644
index 0000000..a2a26f5
--- /dev/null
+++ b/graphics/egl/swangle/sepolicy/file_contexts
@@ -0,0 +1,5 @@
+/vendor/lib(64)?/hw/vulkan.pastel.so            u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/libEGL_angle\.so               u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/libGLESv1_CM_angle\.so         u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/libGLESv2_angle\.so            u:object_r:same_process_hal_file:s0
+/vendor/lib(64)?/libfeature_support_angle\.so   u:object_r:same_process_hal_file:s0
diff --git a/graphics/egl/swangle/sepolicy/sw_execmem.te b/graphics/egl/swangle/sepolicy/sw_execmem.te
new file mode 100644
index 0000000..0844c3c
--- /dev/null
+++ b/graphics/egl/swangle/sepolicy/sw_execmem.te
@@ -0,0 +1,5 @@
+# TODO(b/65201432): Swiftshader needs to create executable memory.
+allow bootanim self:process execmem;
+allow surfaceflinger self:process execmem;
+allow system_server self:process execmem;
+allow zygote self:process execmem;
-- 
GitLab