aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-04-05 19:47:12 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2022-04-05 19:47:12 +0000
commita3b96f760cbb497d23553af383c5d6cfa265d644 (patch)
tree7c00afac9f3e363720dddbbff6c730ad93f24fee
parent6f211c7234e3d28128f0579821382200babcbc1a (diff)
parente3651284204f4ebaf9fc83ae70e3051edf1ca8e7 (diff)
downloadgoldfish-opengl-emu-31-release.tar.gz
Snap for 8403122 from e3651284204f4ebaf9fc83ae70e3051edf1ca8e7 to emu-31-releaseemu-31-release
Change-Id: Iba3af1b4805f5fdae1bf12ff86dc9596448f137b
-rw-r--r--meson.build1
-rw-r--r--shared/GoldfishAddressSpace/Android.bp1
-rw-r--r--shared/GoldfishAddressSpace/Android.mk2
-rw-r--r--shared/GoldfishAddressSpace/CMakeLists.txt4
-rw-r--r--shared/GoldfishAddressSpace/include/goldfish_address_space.h1
-rw-r--r--shared/GoldfishAddressSpace/include/goldfish_address_space_android.impl37
-rw-r--r--shared/GoldfishAddressSpace/meson.build3
-rwxr-xr-xsystem/GLESv2_enc/GL2Encoder.cpp2
-rw-r--r--system/OpenglSystemCommon/AddressSpaceStream.cpp31
-rw-r--r--system/OpenglSystemCommon/AddressSpaceStream.h9
-rw-r--r--system/OpenglSystemCommon/HostConnection.cpp62
-rw-r--r--system/OpenglSystemCommon/HostConnection.h2
-rw-r--r--system/OpenglSystemCommon/ProcessPipe.cpp8
-rw-r--r--system/OpenglSystemCommon/ProcessPipe.h2
-rw-r--r--system/OpenglSystemCommon/VirtioGpuPipeStream.cpp20
-rw-r--r--system/OpenglSystemCommon/VirtioGpuPipeStream.h5
-rw-r--r--system/OpenglSystemCommon/VirtioGpuStream.cpp4
-rw-r--r--system/OpenglSystemCommon/VirtioGpuStream.h2
-rw-r--r--system/OpenglSystemCommon/meson.build3
-rw-r--r--system/codecs/c2/decoders/base/color_buffer_utils.cpp2
-rw-r--r--system/egl/egl.cpp4
-rw-r--r--system/hwc2/Android.mk1
-rw-r--r--system/hwc2/Common.cpp6
-rw-r--r--system/hwc2/Common.h1
-rw-r--r--system/hwc2/Composer.h1
-rw-r--r--system/hwc2/Device.cpp19
-rw-r--r--system/hwc2/DisplayConfig.cpp6
-rw-r--r--system/hwc2/DisplayFinder.cpp36
-rw-r--r--system/hwc2/DrmPresenter.cpp3
-rw-r--r--system/hwc2/DrmPresenter.h12
-rw-r--r--system/hwc2/HostComposer.cpp178
-rw-r--r--system/hwc2/HostComposer.h39
-rw-r--r--system/hwc2/NoOpComposer.cpp75
-rw-r--r--system/hwc2/NoOpComposer.h63
l---------system/hwc2/virtgpu_drm.h1
-rw-r--r--system/include/virtgpu_drm.h (renamed from shared/GoldfishAddressSpace/include/virtgpu_drm.h)0
-rw-r--r--system/meson.build1
-rw-r--r--system/vulkan_enc/ResourceTracker.cpp36
-rw-r--r--system/vulkan_enc/meson.build2
l---------system/vulkan_enc/virtgpu_drm.h1
-rw-r--r--system/vulkan_enc/vk_struct_id.h1
41 files changed, 509 insertions, 178 deletions
diff --git a/meson.build b/meson.build
index 3fc09284..19cc4ac7 100644
--- a/meson.build
+++ b/meson.build
@@ -51,6 +51,7 @@ thread_dep = dependency('threads')
inc_android_emu = include_directories('android-emu')
inc_host = include_directories('host/include/libOpenglRender')
+inc_system = include_directories('system/include')
#================#
# Subdirectories #
diff --git a/shared/GoldfishAddressSpace/Android.bp b/shared/GoldfishAddressSpace/Android.bp
index 11e2450c..26cc4685 100644
--- a/shared/GoldfishAddressSpace/Android.bp
+++ b/shared/GoldfishAddressSpace/Android.bp
@@ -24,4 +24,5 @@ cc_library_static {
"-DLOG_TAG=\"goldfish-address-space\"",
"-DVIRTIO_GPU",
],
+ include_dirs: ["device/generic/goldfish-opengl/system/include"],
}
diff --git a/shared/GoldfishAddressSpace/Android.mk b/shared/GoldfishAddressSpace/Android.mk
index 221ea8bb..65ad4aeb 100644
--- a/shared/GoldfishAddressSpace/Android.mk
+++ b/shared/GoldfishAddressSpace/Android.mk
@@ -8,6 +8,8 @@ LOCAL_SRC_FILES := goldfish_address_space.cpp
LOCAL_CFLAGS += -DLOG_TAG=\"goldfish-address-space\"
+LOCAL_C_INCLUDES += device/generic/goldfish-opengl/system/include
+
$(call emugl-export,SHARED_LIBRARIES,liblog android-emu-shared)
$(call emugl-export,C_INCLUDES,$(LOCAL_PATH)/include)
$(call emugl-end-module)
diff --git a/shared/GoldfishAddressSpace/CMakeLists.txt b/shared/GoldfishAddressSpace/CMakeLists.txt
index 764f4787..d2d3a05b 100644
--- a/shared/GoldfishAddressSpace/CMakeLists.txt
+++ b/shared/GoldfishAddressSpace/CMakeLists.txt
@@ -1,10 +1,10 @@
# This is an autogenerated file! Do not edit!
# instead run make from .../device/generic/goldfish-opengl
# which will re-generate this file.
-android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/Android.mk" "2b12d7f8c4c62c3a909b9771662cf18c9e4d16c58c95a11e225fe2b46432e862")
+android_validate_sha256("${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/Android.mk" "a8b27a12e9d8e1cf4679c3ee1007f5ce8e846d7b07e6956c6eb46be289af9365")
set(GoldfishAddressSpace_host_src goldfish_address_space.cpp)
android_add_library(TARGET GoldfishAddressSpace_host LICENSE Apache-2.0 SRC goldfish_address_space.cpp)
-target_include_directories(GoldfishAddressSpace_host PRIVATE ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest)
+target_include_directories(GoldfishAddressSpace_host PRIVATE ${GOLDFISH_DEVICE_ROOT}/shared/GoldfishAddressSpace/include ${GOLDFISH_DEVICE_ROOT}/./host/include/libOpenglRender ${GOLDFISH_DEVICE_ROOT}/./system/include ${GOLDFISH_DEVICE_ROOT}/./../../../external/qemu/android/android-emugl/guest ${GOLDFISH_DEVICE_ROOT}/device/generic/goldfish-opengl/system/include)
target_compile_definitions(GoldfishAddressSpace_host PRIVATE "-DPLATFORM_SDK_VERSION=29" "-DGOLDFISH_HIDL_GRALLOC" "-DHOST_BUILD" "-DANDROID" "-DGL_GLEXT_PROTOTYPES" "-DPAGE_SIZE=4096" "-DGFXSTREAM" "-DLOG_TAG=\"goldfish-address-space\"")
target_compile_options(GoldfishAddressSpace_host PRIVATE "-fvisibility=default" "-Wno-unused-parameter")
target_link_libraries(GoldfishAddressSpace_host PRIVATE log android-emu-shared) \ No newline at end of file
diff --git a/shared/GoldfishAddressSpace/include/goldfish_address_space.h b/shared/GoldfishAddressSpace/include/goldfish_address_space.h
index 847845a6..d0381b8e 100644
--- a/shared/GoldfishAddressSpace/include/goldfish_address_space.h
+++ b/shared/GoldfishAddressSpace/include/goldfish_address_space.h
@@ -185,7 +185,6 @@ struct address_space_virtgpu_info {
void* resp_mapped_ptr;
};
-address_space_handle_t open_virtgpu(uint32_t capset_id);
address_space_handle_t virtgpu_address_space_open();
void virtgpu_address_space_close(address_space_handle_t);
diff --git a/shared/GoldfishAddressSpace/include/goldfish_address_space_android.impl b/shared/GoldfishAddressSpace/include/goldfish_address_space_android.impl
index 5c06e295..e390ba84 100644
--- a/shared/GoldfishAddressSpace/include/goldfish_address_space_android.impl
+++ b/shared/GoldfishAddressSpace/include/goldfish_address_space_android.impl
@@ -549,43 +549,6 @@ bool goldfish_address_space_ping(
#define CAPSET_GFXSTREAM 3
-// This is a no-op because virtgpu doesn't really use the GoldfishAddressSpaceBlockProvider
-address_space_handle_t open_virtgpu(uint32_t capset_id) {
- int fd = drmOpenRender(128);
- if (fd < 0) {
- ALOGE("Failed to open rendernode: %s", strerror(errno));
- return fd;
- }
-
- // Don't use capset id yet. Not clear if we want just:
- // - one gfxstream capset
- // - a ranchu capset, a vulkan capset, or GLES capset
- if (capset_id) {
- int ret;
- struct drm_virtgpu_context_init init = {0};
- struct drm_virtgpu_context_set_param ctx_set_params[2] = {{0}};
-
- ctx_set_params[0].param = VIRTGPU_CONTEXT_PARAM_NUM_RINGS;
- ctx_set_params[0].value = 1;
- init.num_params = 1;
-
- // TODO(b/218538495): A KI in the 5.4 kernel will sometimes result in capsets not
- // being properly queried.
-#if defined(__linux__) && !defined(__ANDROID__)
- ctx_set_params[1].param = VIRTGPU_CONTEXT_PARAM_CAPSET_ID;
- ctx_set_params[1].value = capset_id;
- init.num_params++;
-#endif
-
- init.ctx_set_params = (unsigned long long)&ctx_set_params[0];
- ret = drmIoctl(fd, DRM_IOCTL_VIRTGPU_CONTEXT_INIT, &init);
- if (ret) {
- ALOGE("DRM_IOCTL_VIRTGPU_CONTEXT_INIT failed with %s, continuing without context...", strerror(errno));
- }
- }
-
- return fd;
-}
address_space_handle_t virtgpu_address_space_open() {
return -EINVAL;
diff --git a/shared/GoldfishAddressSpace/meson.build b/shared/GoldfishAddressSpace/meson.build
index 1db9258b..50fef3a4 100644
--- a/shared/GoldfishAddressSpace/meson.build
+++ b/shared/GoldfishAddressSpace/meson.build
@@ -12,6 +12,7 @@ lib_goldfish_address_space = static_library(
files_lib_goldfish_address_space,
cpp_args: cpp_args,
include_directories: [inc_android_compat,
- inc_goldfish_address_space],
+ inc_goldfish_address_space,
+ inc_system],
dependencies: drm_dep
)
diff --git a/system/GLESv2_enc/GL2Encoder.cpp b/system/GLESv2_enc/GL2Encoder.cpp
index 9fcce622..382274c4 100755
--- a/system/GLESv2_enc/GL2Encoder.cpp
+++ b/system/GLESv2_enc/GL2Encoder.cpp
@@ -3039,7 +3039,7 @@ void GL2Encoder::s_glFramebufferTexture2D(void* self,
SET_ERROR_IF(!GLESv2Validation::isCubeMapTarget(textarget) && state->isTextureCubeMap(texture), GL_INVALID_OPERATION);
SET_ERROR_IF((texture && (level < 0)), GL_INVALID_VALUE);
- if (target == GL_TEXTURE_2D) {
+ if (textarget == GL_TEXTURE_2D) {
SET_ERROR_IF(level > ilog2(ctx->m_state->getMaxTextureSize()), GL_INVALID_VALUE);
} else {
SET_ERROR_IF(level > ilog2(ctx->m_state->getMaxTextureSizeCubeMap()), GL_INVALID_VALUE);
diff --git a/system/OpenglSystemCommon/AddressSpaceStream.cpp b/system/OpenglSystemCommon/AddressSpaceStream.cpp
index c5f6c0bc..8e12550a 100644
--- a/system/OpenglSystemCommon/AddressSpaceStream.cpp
+++ b/system/OpenglSystemCommon/AddressSpaceStream.cpp
@@ -147,32 +147,9 @@ AddressSpaceStream* createAddressSpaceStream(size_t ignored_bufSize) {
return res;
}
-#if defined(HOST_BUILD) || defined(__Fuchsia__)
-AddressSpaceStream* createVirtioGpuAddressSpaceStream(size_t ignored_bufSize, uint32_t capset_id) {
- // Ignore incoming ignored_bufSize
- (void)ignored_bufSize;
- return nullptr;
-}
-#else
-static address_space_handle_t openVirtGpuAddressSpace(uint32_t capset_id) {
- address_space_handle_t ret;
- uint8_t retryCount = 64;
- do {
- ret = open_virtgpu(capset_id);
- } while(ret < 0 && retryCount-- > 0 && errno == EINTR);
- return ret;
-}
-
-AddressSpaceStream* createVirtioGpuAddressSpaceStream(size_t ignored_bufSize, uint32_t capset_id) {
- // Ignore incoming ignored_bufSize
- (void)ignored_bufSize;
-
- auto handle = openVirtGpuAddressSpace(capset_id);
- if (handle <= reinterpret_cast<address_space_handle_t>(-1)) {
- ALOGE("AddressSpaceStream::create failed (open device) %d (%s)\n", errno, strerror(errno));
- return nullptr;
- }
-
+#if defined(VIRTIO_GPU) && !defined(HOST_BUILD)
+AddressSpaceStream* createVirtioGpuAddressSpaceStream(const struct StreamCreate &streamCreate) {
+ auto handle = reinterpret_cast<address_space_handle_t>(streamCreate.streamHandle);
struct address_space_virtgpu_info virtgpu_info;
ALOGD("%s: create subdevice and get resp\n", __func__);
@@ -294,7 +271,7 @@ AddressSpaceStream* createVirtioGpuAddressSpaceStream(size_t ignored_bufSize, ui
return res;
}
-#endif // HOST_BUILD || __Fuchsia__
+#endif // VIRTIO_GPU && !HOST_BUILD
AddressSpaceStream::AddressSpaceStream(
diff --git a/system/OpenglSystemCommon/AddressSpaceStream.h b/system/OpenglSystemCommon/AddressSpaceStream.h
index 0ab76a04..68ad80df 100644
--- a/system/OpenglSystemCommon/AddressSpaceStream.h
+++ b/system/OpenglSystemCommon/AddressSpaceStream.h
@@ -24,7 +24,14 @@
class AddressSpaceStream;
AddressSpaceStream* createAddressSpaceStream(size_t bufSize);
-AddressSpaceStream* createVirtioGpuAddressSpaceStream(size_t bufSize, uint32_t capset_id);
+
+#if defined(VIRTIO_GPU) && !defined(HOST_BUILD)
+struct StreamCreate {
+ int streamHandle;
+};
+
+AddressSpaceStream* createVirtioGpuAddressSpaceStream(const struct StreamCreate &streamCreate);
+#endif
class AddressSpaceStream : public IOStream {
public:
diff --git a/system/OpenglSystemCommon/HostConnection.cpp b/system/OpenglSystemCommon/HostConnection.cpp
index 69896d2c..ac7ef15a 100644
--- a/system/OpenglSystemCommon/HostConnection.cpp
+++ b/system/OpenglSystemCommon/HostConnection.cpp
@@ -83,9 +83,9 @@ using goldfish_vk::VkEncoder;
#include "VirtioGpuStream.h"
#include "VirtioGpuPipeStream.h"
+#include "virtgpu_drm.h"
#include <cros_gralloc_handle.h>
-#include <virtgpu_drm.h>
#include <xf86drm.h>
#endif
@@ -378,9 +378,9 @@ private:
class GoldfishProcessPipe : public ProcessPipe
{
public:
- bool processPipeInit(HostConnectionType connType, renderControl_encoder_context_t *rcEnc)
+ bool processPipeInit(int stream_handle, HostConnectionType connType, renderControl_encoder_context_t *rcEnc)
{
- return ::processPipeInit(connType, rcEnc);
+ return ::processPipeInit(stream_handle, connType, rcEnc);
}
};
@@ -421,6 +421,42 @@ HostConnection::~HostConnection()
}
}
+#if defined(VIRTIO_GPU) && !defined(HOST_BUILD)
+int virtgpuOpen(uint32_t capset_id) {
+ int fd = drmOpenRender(128);
+ if (fd < 0) {
+ ALOGE("Failed to open rendernode: %s", strerror(errno));
+ return fd;
+ }
+
+ if (capset_id) {
+ int ret;
+ struct drm_virtgpu_context_init init = {0};
+ struct drm_virtgpu_context_set_param ctx_set_params[2] = {{0}};
+
+ ctx_set_params[0].param = VIRTGPU_CONTEXT_PARAM_NUM_RINGS;
+ ctx_set_params[0].value = 1;
+ init.num_params = 1;
+
+ // TODO(b/218538495): A KI in the 5.4 kernel will sometimes result in capsets not
+ // being properly queried.
+#if defined(__linux__) && !defined(__ANDROID__)
+ ctx_set_params[1].param = VIRTGPU_CONTEXT_PARAM_CAPSET_ID;
+ ctx_set_params[1].value = capset_id;
+ init.num_params++;
+#endif
+
+ init.ctx_set_params = (unsigned long long)&ctx_set_params[0];
+ ret = drmIoctl(fd, DRM_IOCTL_VIRTGPU_CONTEXT_INIT, &init);
+ if (ret) {
+ ALOGE("DRM_IOCTL_VIRTGPU_CONTEXT_INIT failed with %s, continuing without context...", strerror(errno));
+ }
+ }
+
+ return fd;
+}
+#endif
+
// static
std::unique_ptr<HostConnection> HostConnection::connect(uint32_t capset_id) {
const enum HostConnectionType connType = getConnectionTypeFromProperty();
@@ -482,7 +518,7 @@ std::unique_ptr<HostConnection> HostConnection::connect(uint32_t capset_id) {
break;
#endif
}
-#ifdef VIRTIO_GPU
+#if defined(VIRTIO_GPU) && !defined(HOST_BUILD)
case HOST_CONNECTION_VIRTIO_GPU: {
auto stream = new VirtioGpuStream(STREAM_BUFFER_SIZE);
if (!stream) {
@@ -536,11 +572,17 @@ std::unique_ptr<HostConnection> HostConnection::connect(uint32_t capset_id) {
con->m_processPipe = &m_goldfishProcessPipe;
break;
}
-#if !defined(HOST_BUILD) && !defined(__Fuchsia__)
case HOST_CONNECTION_VIRTIO_GPU_ADDRESS_SPACE: {
- auto stream = createVirtioGpuAddressSpaceStream(STREAM_BUFFER_SIZE, capset_id);
+ struct StreamCreate streamCreate = {0};
+ streamCreate.streamHandle = virtgpuOpen(capset_id);
+ if (streamCreate.streamHandle < 0) {
+ ALOGE("Failed to open virtgpu for ASG host connection\n");
+ return nullptr;
+ }
+
+ auto stream = createVirtioGpuAddressSpaceStream(streamCreate);
if (!stream) {
- ALOGE("Failed to create virtgpu AddressSpaceStream for host connection\n");
+ ALOGE("Failed to create virtgpu AddressSpaceStream\n");
return nullptr;
}
con->m_connectionType = HOST_CONNECTION_VIRTIO_GPU_ADDRESS_SPACE;
@@ -565,11 +607,9 @@ std::unique_ptr<HostConnection> HostConnection::connect(uint32_t capset_id) {
con->m_processPipe = &m_goldfishProcessPipe;
break;
}
-#endif // !HOST_BUILD && !__Fuchsia__
-#else
+#endif // !VIRTIO_GPU && !HOST_BUILD_
default:
break;
-#endif
}
// send zero 'clientFlags' to the host.
@@ -705,7 +745,7 @@ ExtendedRCEncoderContext *HostConnection::rcEncoder()
queryAndSetHWCMultiConfigs(rcEnc);
queryVersion(rcEnc);
if (m_processPipe) {
- m_processPipe->processPipeInit(m_connectionType, rcEnc);
+ m_processPipe->processPipeInit(m_rendernodeFd, m_connectionType, rcEnc);
}
}
return m_rcEnc.get();
diff --git a/system/OpenglSystemCommon/HostConnection.h b/system/OpenglSystemCommon/HostConnection.h
index 9d31610b..d954c024 100644
--- a/system/OpenglSystemCommon/HostConnection.h
+++ b/system/OpenglSystemCommon/HostConnection.h
@@ -149,7 +149,7 @@ public:
// Abstraction for process pipe helper
class ProcessPipe {
public:
- virtual bool processPipeInit(HostConnectionType connType, renderControl_encoder_context_t *rcEnc) = 0;
+ virtual bool processPipeInit(int stream_handle, HostConnectionType connType, renderControl_encoder_context_t *rcEnc) = 0;
virtual ~ProcessPipe() {}
};
diff --git a/system/OpenglSystemCommon/ProcessPipe.cpp b/system/OpenglSystemCommon/ProcessPipe.cpp
index 6a8aef13..e444f737 100644
--- a/system/OpenglSystemCommon/ProcessPipe.cpp
+++ b/system/OpenglSystemCommon/ProcessPipe.cpp
@@ -42,6 +42,7 @@ static QEMU_PIPE_HANDLE sProcDevice = 0;
#include "VirtioGpuPipeStream.h"
static VirtioGpuPipeStream* sVirtioGpuPipeStream = 0;
+static int sStreamHandle = -1;
#endif // !__Fuchsia__
@@ -193,7 +194,7 @@ static void processPipeInitOnce() {
break;
case HOST_CONNECTION_VIRTIO_GPU_PIPE:
case HOST_CONNECTION_VIRTIO_GPU_ADDRESS_SPACE: {
- sVirtioGpuPipeStream = new VirtioGpuPipeStream(4096);
+ sVirtioGpuPipeStream = new VirtioGpuPipeStream(4096, sStreamHandle);
sProcUID = sVirtioGpuPipeStream->initProcessPipe();
break;
}
@@ -202,8 +203,11 @@ static void processPipeInitOnce() {
}
#endif // !__Fuchsia__
-bool processPipeInit(HostConnectionType connType, renderControl_encoder_context_t *rcEnc) {
+bool processPipeInit(int streamHandle, HostConnectionType connType, renderControl_encoder_context_t *rcEnc) {
sConnType = connType;
+#ifndef __Fuchsia__
+ sStreamHandle = streamHandle;
+#endif // !__Fuchsia
pthread_once(&sProcPipeOnce, processPipeInitOnce);
bool pipeHandleInvalid = !sProcPipe;
#ifndef __Fuchsia__
diff --git a/system/OpenglSystemCommon/ProcessPipe.h b/system/OpenglSystemCommon/ProcessPipe.h
index c2bd7cea..2e5890b0 100644
--- a/system/OpenglSystemCommon/ProcessPipe.h
+++ b/system/OpenglSystemCommon/ProcessPipe.h
@@ -33,7 +33,7 @@
struct renderControl_encoder_context_t;
-extern bool processPipeInit(HostConnectionType connType, renderControl_encoder_context_t *rcEnc);
+extern bool processPipeInit(int stream_handle, HostConnectionType connType, renderControl_encoder_context_t *rcEnc);
extern uint64_t getPuid();
// For testing purposes; this will close the current process pipe if opened, reset the state to initial,
diff --git a/system/OpenglSystemCommon/VirtioGpuPipeStream.cpp b/system/OpenglSystemCommon/VirtioGpuPipeStream.cpp
index 1625eb8d..1cb242e0 100644
--- a/system/OpenglSystemCommon/VirtioGpuPipeStream.cpp
+++ b/system/OpenglSystemCommon/VirtioGpuPipeStream.cpp
@@ -15,8 +15,8 @@
*/
#include "VirtioGpuPipeStream.h"
+#include "virtgpu_drm.h"
-#include <virtgpu_drm.h>
#include <xf86drm.h>
#include <sys/types.h>
@@ -49,7 +49,21 @@ VirtioGpuPipeStream::VirtioGpuPipeStream(size_t bufSize) :
m_buf(nullptr),
m_read(0),
m_readLeft(0),
- m_writtenPos(0) { }
+ m_writtenPos(0),
+ m_fd_owned(true) { }
+
+VirtioGpuPipeStream::VirtioGpuPipeStream(size_t bufSize, int stream_handle) :
+ IOStream(bufSize),
+ m_fd(stream_handle),
+ m_virtio_rh(~0U),
+ m_virtio_bo(0),
+ m_virtio_mapped(nullptr),
+ m_bufsize(bufSize),
+ m_buf(nullptr),
+ m_read(0),
+ m_readLeft(0),
+ m_writtenPos(0),
+ m_fd_owned(false) { }
VirtioGpuPipeStream::~VirtioGpuPipeStream()
{
@@ -64,7 +78,7 @@ VirtioGpuPipeStream::~VirtioGpuPipeStream()
drmIoctl(m_fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
}
- if (m_fd >= 0) {
+ if (m_fd >= 0 && m_fd_owned) {
close(m_fd);
}
diff --git a/system/OpenglSystemCommon/VirtioGpuPipeStream.h b/system/OpenglSystemCommon/VirtioGpuPipeStream.h
index 91c76fc6..1d99c120 100644
--- a/system/OpenglSystemCommon/VirtioGpuPipeStream.h
+++ b/system/OpenglSystemCommon/VirtioGpuPipeStream.h
@@ -31,6 +31,7 @@ public:
typedef enum { ERR_INVALID_SOCKET = -1000 } QemuPipeStreamError;
explicit VirtioGpuPipeStream(size_t bufsize = 10000);
+ explicit VirtioGpuPipeStream(size_t bufsize, int stream_handle);
~VirtioGpuPipeStream();
int connect(const char* serviceName = 0);
static int openRendernode();
@@ -59,6 +60,8 @@ private:
ssize_t transferFromHost(void* buffer, size_t len);
int m_fd; // rendernode fd
+ int m_fd_owned; // Do we own the fd? We should consider using
+ // modern C++ for this.
uint32_t m_virtio_rh; // transfer buffer res handle
uint32_t m_virtio_bo; // transfer bo handle
@@ -71,6 +74,4 @@ private:
size_t m_readLeft;
size_t m_writtenPos;
-
- VirtioGpuPipeStream(int sock, size_t bufSize);
};
diff --git a/system/OpenglSystemCommon/VirtioGpuStream.cpp b/system/OpenglSystemCommon/VirtioGpuStream.cpp
index 988cb5e6..21a76e9f 100644
--- a/system/OpenglSystemCommon/VirtioGpuStream.cpp
+++ b/system/OpenglSystemCommon/VirtioGpuStream.cpp
@@ -15,8 +15,8 @@
*/
#include "VirtioGpuStream.h"
+#include "virtgpu_drm.h"
-#include <virtgpu_drm.h>
#include <xf86drm.h>
#include <sys/types.h>
@@ -59,7 +59,7 @@ union process_pipe_info {
} id;
};
-bool VirtioGpuProcessPipe::processPipeInit(HostConnectionType, renderControl_encoder_context_t *rcEnc)
+bool VirtioGpuProcessPipe::processPipeInit(int stream_handle, HostConnectionType, renderControl_encoder_context_t *rcEnc)
{
union process_pipe_info info;
diff --git a/system/OpenglSystemCommon/VirtioGpuStream.h b/system/OpenglSystemCommon/VirtioGpuStream.h
index 1c7a4964..4f2c2dc3 100644
--- a/system/OpenglSystemCommon/VirtioGpuStream.h
+++ b/system/OpenglSystemCommon/VirtioGpuStream.h
@@ -30,7 +30,7 @@ struct VirtioGpuCmd;
class VirtioGpuProcessPipe : public ProcessPipe
{
public:
- virtual bool processPipeInit(HostConnectionType connType, renderControl_encoder_context_t *rcEnc);
+ virtual bool processPipeInit(int stream_handle, HostConnectionType connType, renderControl_encoder_context_t *rcEnc);
};
class VirtioGpuStream : public IOStream
diff --git a/system/OpenglSystemCommon/meson.build b/system/OpenglSystemCommon/meson.build
index f880f650..90f01937 100644
--- a/system/OpenglSystemCommon/meson.build
+++ b/system/OpenglSystemCommon/meson.build
@@ -18,7 +18,8 @@ lib_stream = static_library(
include_directories: [inc_host, inc_opengl_codec, inc_android_emu,
inc_render_enc, inc_android_compat,
inc_qemu_pipe, inc_qemu_pipe_types, inc_gralloc,
- inc_vulkan_enc, inc_goldfish_address_space],
+ inc_vulkan_enc, inc_goldfish_address_space,
+ inc_system],
link_with: [lib_codec_common, lib_goldfish_address_space, lib_qemu_pipe,
lib_render_control_enc],
dependencies: drm_dep
diff --git a/system/codecs/c2/decoders/base/color_buffer_utils.cpp b/system/codecs/c2/decoders/base/color_buffer_utils.cpp
index 36aa3362..a36ba323 100644
--- a/system/codecs/c2/decoders/base/color_buffer_utils.cpp
+++ b/system/codecs/c2/decoders/base/color_buffer_utils.cpp
@@ -19,10 +19,10 @@
#include <android-base/strings.h>
#include <log/log.h>
#include <gralloc_cb_bp.h>
-#include <drm/virtgpu_drm.h>
#include <xf86drm.h>
#include "cros_gralloc_handle.h"
+#include "virtgpu_drm.h"
static bool isMinigbmFromProperty() {
static constexpr const auto kGrallocProp = "ro.hardware.gralloc";
diff --git a/system/egl/egl.cpp b/system/egl/egl.cpp
index 4907bb20..fc3d0a98 100644
--- a/system/egl/egl.cpp
+++ b/system/egl/egl.cpp
@@ -48,9 +48,11 @@
#include <GLES3/gl31.h>
#ifdef VIRTIO_GPU
-#include <drm/virtgpu_drm.h>
#include <xf86drm.h>
#include <poll.h>
+
+#include "virtgpu_drm.h"
+
#endif // VIRTIO_GPU
#ifdef GFXSTREAM
diff --git a/system/hwc2/Android.mk b/system/hwc2/Android.mk
index e9090df4..b53456ce 100644
--- a/system/hwc2/Android.mk
+++ b/system/hwc2/Android.mk
@@ -70,6 +70,7 @@ emulator_hwcomposer2_src_files := \
HostComposer.cpp \
HostUtils.cpp \
Layer.cpp \
+ NoOpComposer.cpp \
VsyncThread.cpp \
include $(CLEAR_VARS)
diff --git a/system/hwc2/Common.cpp b/system/hwc2/Common.cpp
index 19217411..3e465c22 100644
--- a/system/hwc2/Common.cpp
+++ b/system/hwc2/Common.cpp
@@ -26,4 +26,8 @@ bool IsCuttlefishFoldable() {
return IsCuttlefish() &&
android::base::GetProperty("ro.product.name", "").find("foldable") !=
std::string::npos;
-} \ No newline at end of file
+}
+
+bool IsNoOpMode() {
+ return android::base::GetProperty("ro.vendor.hwcomposer.mode", "") == "noop";
+}
diff --git a/system/hwc2/Common.h b/system/hwc2/Common.h
index 45af8609..b0e07700 100644
--- a/system/hwc2/Common.h
+++ b/system/hwc2/Common.h
@@ -44,5 +44,6 @@
bool IsCuttlefish();
bool IsCuttlefishFoldable();
+bool IsNoOpMode();
#endif
diff --git a/system/hwc2/Composer.h b/system/hwc2/Composer.h
index 0c47eab7..f19178e5 100644
--- a/system/hwc2/Composer.h
+++ b/system/hwc2/Composer.h
@@ -18,6 +18,7 @@
#define ANDROID_HWC_COMPOSER_H
#include <android-base/unique_fd.h>
+
#include <functional>
#include <tuple>
#include <unordered_map>
diff --git a/system/hwc2/Device.cpp b/system/hwc2/Device.cpp
index b427f60b..1be15b3d 100644
--- a/system/hwc2/Device.cpp
+++ b/system/hwc2/Device.cpp
@@ -21,6 +21,7 @@
#include "DisplayFinder.h"
#include "GuestComposer.h"
#include "HostComposer.h"
+#include "NoOpComposer.h"
namespace android {
namespace {
@@ -73,18 +74,24 @@ Device::Device() {
HWC2::Error Device::init() {
DEBUG_LOG("%s", __FUNCTION__);
bool isMinigbm = isMinigbmFromProperty();
- if (ShouldUseGuestComposer()) {
+
+ if (IsNoOpMode()) {
+ DEBUG_LOG("%s: using NoOpComposer", __FUNCTION__);
+ mComposer = std::make_unique<NoOpComposer>();
+ } else if (ShouldUseGuestComposer()) {
+ DEBUG_LOG("%s: using GuestComposer", __FUNCTION__);
mComposer = std::make_unique<GuestComposer>(mDrmPresenter.get());
} else {
+ DEBUG_LOG("%s: using HostComposer", __FUNCTION__);
mComposer = std::make_unique<HostComposer>(mDrmPresenter.get(), isMinigbm);
}
- if (ShouldUseGuestComposer() || isMinigbm) {
- bool success = mDrmPresenter->init(
+ if (!IsNoOpMode() && (ShouldUseGuestComposer() || isMinigbm)) {
+ bool success = mDrmPresenter->init(
[this](bool connected, uint32_t id, uint32_t width, uint32_t height,
- uint32_t dpiX, uint32_t dpiY, uint32_t refreshRate) {
- handleHotplug(connected, id, width, height, dpiX, dpiY, refreshRate);
- });
+ uint32_t dpiX, uint32_t dpiY, uint32_t refreshRate) {
+ handleHotplug(connected, id, width, height, dpiX, dpiY, refreshRate);
+ });
if (!success) {
ALOGE("%s: failed to initialize DrmPresenter", __FUNCTION__);
diff --git a/system/hwc2/DisplayConfig.cpp b/system/hwc2/DisplayConfig.cpp
index ee4cbb1e..abd0b89e 100644
--- a/system/hwc2/DisplayConfig.cpp
+++ b/system/hwc2/DisplayConfig.cpp
@@ -57,11 +57,13 @@ int32_t DisplayConfig::getAttribute(HWC2::Attribute attribute) const {
return mHeight;
}
if (attribute == HWC2::Attribute::DpiX) {
- // From hwcomposer2.h, HWC2_ATTRIBUTE_DPI_X returns "Dots per thousand inches (DPI * 1000)".
+ // From hwcomposer2.h, HWC2_ATTRIBUTE_DPI_X returns "Dots per thousand
+ // inches (DPI * 1000)".
return getDotsPerThousandInchesX();
}
if (attribute == HWC2::Attribute::DpiY) {
- // From hwcomposer2.h, HWC2_ATTRIBUTE_DPI_Y returns "Dots per thousand inches (DPI * 1000)"
+ // From hwcomposer2.h, HWC2_ATTRIBUTE_DPI_Y returns "Dots per thousand
+ // inches (DPI * 1000)"
return getDotsPerThousandInchesY();
}
if (attribute == HWC2::Attribute::VsyncPeriod) {
diff --git a/system/hwc2/DisplayFinder.cpp b/system/hwc2/DisplayFinder.cpp
index 5fb192b5..a55a49d6 100644
--- a/system/hwc2/DisplayFinder.cpp
+++ b/system/hwc2/DisplayFinder.cpp
@@ -47,12 +47,11 @@ static int getVsyncHzFromProperty() {
return static_cast<int>(vsyncPeriod);
}
-int32_t getVsyncForDisplay(DrmPresenter* drmPresenter,
- uint32_t displayId) {
- const int32_t vsyncPeriodForDisplay = drmPresenter->refreshRate(displayId);
- return vsyncPeriodForDisplay < 0 ?
- HertzToPeriodNanos(getVsyncHzFromProperty()) :
- HertzToPeriodNanos(vsyncPeriodForDisplay);
+int32_t getVsyncForDisplay(DrmPresenter* drmPresenter, uint32_t displayId) {
+ const int32_t vsyncPeriodForDisplay = drmPresenter->refreshRate(displayId);
+ return vsyncPeriodForDisplay < 0
+ ? HertzToPeriodNanos(getVsyncHzFromProperty())
+ : HertzToPeriodNanos(vsyncPeriodForDisplay);
}
HWC2::Error findCuttlefishDisplays(std::vector<DisplayMultiConfigs>& displays) {
@@ -89,8 +88,7 @@ HWC2::Error findCuttlefishDisplays(std::vector<DisplayMultiConfigs>& displays) {
}
HWC2::Error findGoldfishPrimaryDisplay(
- DrmPresenter* drmPresenter,
- std::vector<DisplayMultiConfigs>& displays) {
+ DrmPresenter* drmPresenter, std::vector<DisplayMultiConfigs>& displays) {
DEBUG_LOG("%s", __FUNCTION__);
DEFINE_AND_VALIDATE_HOST_CONNECTION
@@ -205,12 +203,32 @@ HWC2::Error findGoldfishDisplays(DrmPresenter* drmPresenter,
return error;
}
+// This is currently only used for Gem5 bring-up where virtio-gpu and drm
+// are not currently available. For now, just return a placeholder display.
+HWC2::Error findNoOpDisplays(std::vector<DisplayMultiConfigs>& displays) {
+ displays.push_back(DisplayMultiConfigs{
+ .displayId = 0,
+ .activeConfigId = 0,
+ .configs = {DisplayConfig(0,
+ /*width=*/720, //
+ /*heighth=*/1280, //
+ /*dpiXh=*/320, //
+ /*dpiYh=*/320, //
+ /*vsyncPeriod=*/HertzToPeriodNanos(30) //
+ )},
+ });
+
+ return HWC2::Error::None;
+}
+
} // namespace
HWC2::Error findDisplays(DrmPresenter* drmPresenter,
std::vector<DisplayMultiConfigs>& displays) {
HWC2::Error error = HWC2::Error::None;
- if (IsCuttlefish()) {
+ if (IsNoOpMode()) {
+ error = findNoOpDisplays(displays);
+ } else if (IsCuttlefish()) {
error = findCuttlefishDisplays(displays);
} else {
error = findGoldfishDisplays(drmPresenter, displays);
diff --git a/system/hwc2/DrmPresenter.cpp b/system/hwc2/DrmPresenter.cpp
index b805749a..40b4c37a 100644
--- a/system/hwc2/DrmPresenter.cpp
+++ b/system/hwc2/DrmPresenter.cpp
@@ -530,8 +530,7 @@ std::optional<std::vector<uint8_t>> DrmPresenter::getEdid(uint32_t id) {
return edid;
}
-DrmBuffer::DrmBuffer(const native_handle_t* handle,
- DrmPresenter* drmPresenter)
+DrmBuffer::DrmBuffer(const native_handle_t* handle, DrmPresenter* drmPresenter)
: mDrmPresenter(drmPresenter), mBo({}) {
if (!convertBoInfo(handle)) {
mDrmPresenter->getDrmFB(mBo);
diff --git a/system/hwc2/DrmPresenter.h b/system/hwc2/DrmPresenter.h
index fdf06b78..24614acd 100644
--- a/system/hwc2/DrmPresenter.h
+++ b/system/hwc2/DrmPresenter.h
@@ -22,7 +22,6 @@
#include <xf86drm.h>
#include <xf86drmMode.h>
-#include <android-base/unique_fd.h>
#include <map>
#include <memory>
#include <tuple>
@@ -40,8 +39,7 @@ class DrmPresenter;
// A RAII object that will clear a drm framebuffer upon destruction.
class DrmBuffer {
public:
- DrmBuffer(const native_handle_t* handle,
- DrmPresenter* drmPresenter);
+ DrmBuffer(const native_handle_t* handle, DrmPresenter* drmPresenter);
~DrmBuffer();
DrmBuffer(const DrmBuffer&) = delete;
@@ -79,11 +77,11 @@ class DrmPresenter {
bool init(const HotplugCallback& cb);
uint32_t refreshRate(uint32_t display) const {
- if (display < mConnectors.size()) {
- return mConnectors[display].mRefreshRateAsInteger;
- }
+ if (display < mConnectors.size()) {
+ return mConnectors[display].mRefreshRateAsInteger;
+ }
- return -1;
+ return -1;
}
std::tuple<HWC2::Error, base::unique_fd> flushToDisplay(
diff --git a/system/hwc2/HostComposer.cpp b/system/hwc2/HostComposer.cpp
index 73d717dd..5bf324e0 100644
--- a/system/hwc2/HostComposer.cpp
+++ b/system/hwc2/HostComposer.cpp
@@ -28,6 +28,8 @@
#include <ui/GraphicBufferAllocator.h>
#include <ui/GraphicBufferMapper.h>
+#include <algorithm>
+#include <iterator>
#include <optional>
#include <tuple>
@@ -102,32 +104,134 @@ class ComposeMsg_v2 {
ComposeDevice_v2* mComposeDevice;
};
-const native_handle_t* AllocateDisplayColorBuffer(int width, int height) {
+} // namespace
+
+std::unique_ptr<HostComposer::CompositionResultBuffer>
+HostComposer::CompositionResultBuffer::create(int32_t width, int32_t height) {
const uint32_t layerCount = 1;
const uint64_t graphicBufferId = 0; // not used
- buffer_handle_t h;
+ buffer_handle_t handle;
uint32_t stride;
if (GraphicBufferAllocator::get().allocate(
width, height, PIXEL_FORMAT_RGBA_8888, layerCount,
(GraphicBuffer::USAGE_HW_COMPOSER | GraphicBuffer::USAGE_HW_RENDER),
- &h, &stride, graphicBufferId, "EmuHWC2") == OK) {
- return static_cast<const native_handle_t*>(h);
- } else {
+ &handle, &stride, graphicBufferId, "EmuHWC2") != OK) {
+ return nullptr;
+ }
+
+ std::unique_ptr<FencedBuffer> fencedBuffer = std::make_unique<FencedBuffer>();
+ fencedBuffer->setBuffer(handle);
+ std::unique_ptr<CompositionResultBuffer> res(new CompositionResultBuffer());
+ res->mFencedBuffer = std::move(fencedBuffer);
+ return res;
+}
+
+std::unique_ptr<HostComposer::CompositionResultBuffer>
+HostComposer::CompositionResultBuffer::createWithDrmBuffer(
+ int32_t width, int32_t height, DrmPresenter& drmPresenter) {
+ std::unique_ptr<CompositionResultBuffer> res = create(width, height);
+ if (!res) {
return nullptr;
}
+ res->mDrmBuffer = std::make_unique<DrmBuffer>(res->mFencedBuffer->getBuffer(),
+ &drmPresenter);
+ return res;
}
-void FreeDisplayColorBuffer(const native_handle_t* h) {
- GraphicBufferAllocator::get().free(h);
+HostComposer::CompositionResultBuffer::~CompositionResultBuffer() {
+ mDrmBuffer = nullptr;
+ waitForFence();
+ buffer_handle_t handle = mFencedBuffer->getBuffer();
+ mFencedBuffer = nullptr;
+ GraphicBufferAllocator::get().free(handle);
}
-} // namespace
+DrmBuffer& HostComposer::CompositionResultBuffer::waitAndGetDrmBuffer() {
+ waitForFence();
+ return *mDrmBuffer;
+}
-HostComposer::HostComposer(DrmPresenter* drmPresenter,
- bool isMinigbm) :
- mDrmPresenter(drmPresenter),
- mIsMinigbm(isMinigbm) {}
+buffer_handle_t
+HostComposer::CompositionResultBuffer::waitAndGetBufferHandle() {
+ waitForFence();
+ return mFencedBuffer->getBuffer();
+}
+
+bool HostComposer::CompositionResultBuffer::isReady() const {
+ base::unique_fd fence = mFencedBuffer->getFence();
+ if (!fence.ok()) {
+ return true;
+ }
+ if (sync_wait(fence, 0) == 0) {
+ return true;
+ }
+ if (errno != ETIME) {
+ ALOGE("%s: fail when calling sync_wait: %s(%d).", __func__, strerror(errno),
+ errno);
+ }
+ return false;
+}
+
+void HostComposer::CompositionResultBuffer::setFence(base::unique_fd fence) {
+ mFencedBuffer->setFence(std::move(fence));
+}
+
+void HostComposer::CompositionResultBuffer::waitForFence() {
+ base::unique_fd fence = mFencedBuffer->getFence();
+ if (!fence.ok()) {
+ return;
+ }
+ constexpr int kWaitInterval = 3000;
+ while (true) {
+ int ret = sync_wait(fence, kWaitInterval);
+ if (ret == 0) {
+ return;
+ }
+ if (errno == ETIME) {
+ ALOGI(
+ "%s: timeout when calling sync_wait with fence = %d, timeout = %d, "
+ "retry.",
+ __func__, static_cast<int>(fence), kWaitInterval);
+ continue;
+ }
+ ALOGE(
+ "%s: error when calling sync_wait with fence = %d, timeout = %d: "
+ "%s(%d). Quit.",
+ __func__, static_cast<int>(fence), kWaitInterval, strerror(errno),
+ errno);
+ return;
+ }
+}
+
+void HostComposer::HostComposerDisplayInfo::resetCompositionResultBuffers(
+ std::vector<std::unique_ptr<CompositionResultBuffer>>
+ newCompositionResultBuffers) {
+ compositionResultBuffers = std::move(newCompositionResultBuffers);
+}
+
+HostComposer::CompositionResultBuffer&
+HostComposer::HostComposerDisplayInfo::getNextCompositionResultBuffer() {
+ auto i = compositionResultBuffers.begin();
+ // Find the buffer that is already ready for the next composition.
+ for (; i != compositionResultBuffers.end(); i++) {
+ if ((*i)->isReady()) {
+ break;
+ }
+ }
+ // If no buffers are ready, choose the first buffer which should be the
+ // earliest buffer sent for composition.
+ if (i == compositionResultBuffers.end()) {
+ i = compositionResultBuffers.begin();
+ }
+ // Move the selected buffer to the end of compositionResultBuffers without
+ // changing the existing order of other buffers.
+ std::rotate(i, std::next(i), compositionResultBuffers.end());
+ return *compositionResultBuffers.back();
+}
+
+HostComposer::HostComposer(DrmPresenter* drmPresenter, bool isMinigbm)
+ : mDrmPresenter(drmPresenter), mIsMinigbm(isMinigbm) {}
HWC2::Error HostComposer::init() {
if (!mIsMinigbm) {
@@ -173,21 +277,27 @@ HWC2::Error HostComposer::createHostComposerDisplayInfo(
displayInfo.hostDisplayId = hostDisplayId;
- if (displayInfo.compositionResultBuffer) {
- FreeDisplayColorBuffer(displayInfo.compositionResultBuffer);
- }
- displayInfo.compositionResultBuffer =
- AllocateDisplayColorBuffer(displayWidth, displayHeight);
- if (displayInfo.compositionResultBuffer == nullptr) {
- ALOGE("%s: display:%" PRIu64 " failed to create target buffer",
- __FUNCTION__, displayId);
- return HWC2::Error::NoResources;
- }
-
- if (mIsMinigbm) {
- displayInfo.compositionResultDrmBuffer.reset(
- new DrmBuffer(displayInfo.compositionResultBuffer, mDrmPresenter));
+ std::vector<std::unique_ptr<CompositionResultBuffer>>
+ compositionResultBuffers;
+ constexpr uint32_t kCompositionInFlight = 3;
+ for (uint32_t i = 0; i < kCompositionInFlight; i++) {
+ std::unique_ptr<CompositionResultBuffer> buffer = nullptr;
+ if (mIsMinigbm) {
+ buffer = CompositionResultBuffer::createWithDrmBuffer(
+ displayWidth, displayHeight, *mDrmPresenter);
+ } else {
+ buffer = CompositionResultBuffer::create(displayWidth, displayHeight);
+ }
+ if (!buffer) {
+ ALOGE("%s: display:%" PRIu64
+ " failed to create composition target buffer",
+ __FUNCTION__, displayId);
+ return HWC2::Error::NoResources;
+ }
+ compositionResultBuffers.emplace_back(std::move(buffer));
}
+ displayInfo.resetCompositionResultBuffers(
+ std::move(compositionResultBuffers));
return HWC2::Error::None;
}
@@ -311,8 +421,6 @@ HWC2::Error HostComposer::onDisplayDestroy(Display* display) {
hostCon->unlock();
}
- FreeDisplayColorBuffer(displayInfo.compositionResultBuffer);
-
mDisplayInfos.erase(it);
return HWC2::Error::None;
@@ -554,16 +662,19 @@ std::tuple<HWC2::Error, base::unique_fd> HostComposer::presentDisplay(
layer->getZ(), l->composeMode, l->transform);
l++;
}
+
+ auto& compositionResultBuffer =
+ displayInfo.getNextCompositionResultBuffer();
if (hostCompositionV1) {
p->version = 1;
p->targetHandle = hostCon->grallocHelper()->getHostHandle(
- displayInfo.compositionResultBuffer);
+ compositionResultBuffer.waitAndGetBufferHandle());
p->numLayers = numLayer;
} else {
p2->version = 2;
p2->displayId = displayInfo.hostDisplayId;
p2->targetHandle = hostCon->grallocHelper()->getHostHandle(
- displayInfo.compositionResultBuffer);
+ compositionResultBuffer.waitAndGetBufferHandle());
p2->numLayers = numLayer;
}
@@ -614,8 +725,9 @@ std::tuple<HWC2::Error, base::unique_fd> HostComposer::presentDisplay(
}
if (mIsMinigbm) {
- auto [_, fence] = displayInfo.compositionResultDrmBuffer->flushToDisplay(
- display->getId(), -1);
+ auto [_, fence] =
+ compositionResultBuffer.waitAndGetDrmBuffer().flushToDisplay(
+ display->getId(), -1);
retire_fd = std::move(fence);
} else {
int fd;
@@ -638,7 +750,7 @@ std::tuple<HWC2::Error, base::unique_fd> HostComposer::presentDisplay(
}
hostCon->unlock();
}
-
+ compositionResultBuffer.setFence(base::unique_fd(dup(retire_fd.get())));
} else {
// we set all layers Composition::Client, so do nothing.
FencedBuffer& displayClientTarget = display->getClientTarget();
diff --git a/system/hwc2/HostComposer.h b/system/hwc2/HostComposer.h
index 14fc0a78..f17b6102 100644
--- a/system/hwc2/HostComposer.h
+++ b/system/hwc2/HostComposer.h
@@ -18,11 +18,14 @@
#define ANDROID_HWC_HOSTCOMPOSER_H
#include <android-base/unique_fd.h>
+
#include <tuple>
+#include <vector>
#include "Common.h"
#include "Composer.h"
#include "DrmPresenter.h"
+#include "FencedBuffer.h"
#include "HostConnection.h"
namespace android {
@@ -69,17 +72,43 @@ class HostComposer : public Composer {
int mSyncDeviceFd = -1;
- struct HostComposerDisplayInfo {
- uint32_t hostDisplayId = 0;
+ class CompositionResultBuffer {
+ public:
+ static std::unique_ptr<CompositionResultBuffer> create(int32_t width,
+ int32_t height);
+ static std::unique_ptr<CompositionResultBuffer> createWithDrmBuffer(
+ int32_t width, int32_t height, DrmPresenter&);
+ ~CompositionResultBuffer();
- // Additional per display buffer for the composition result.
- const native_handle_t* compositionResultBuffer = nullptr;
+ DrmBuffer& waitAndGetDrmBuffer();
+ buffer_handle_t waitAndGetBufferHandle();
+ bool isReady() const;
+ void setFence(base::unique_fd fence);
+
+ private:
+ CompositionResultBuffer() = default;
+
+ void waitForFence();
+ std::unique_ptr<FencedBuffer> mFencedBuffer;
// Drm info for the additional composition result buffer.
- std::unique_ptr<DrmBuffer> compositionResultDrmBuffer;
+ std::unique_ptr<DrmBuffer> mDrmBuffer;
+ };
+ class HostComposerDisplayInfo {
+ public:
+ HostComposerDisplayInfo() = default;
+ void resetCompositionResultBuffers(
+ std::vector<std::unique_ptr<CompositionResultBuffer>>);
+ CompositionResultBuffer& getNextCompositionResultBuffer();
+ uint32_t hostDisplayId = 0;
// Drm info for the displays client target buffer.
std::unique_ptr<DrmBuffer> clientTargetDrmBuffer;
+
+ private:
+ // Additional per display buffer for the composition result.
+ std::vector<std::unique_ptr<CompositionResultBuffer>>
+ compositionResultBuffers;
};
std::unordered_map<hwc2_display_t, HostComposerDisplayInfo> mDisplayInfos;
diff --git a/system/hwc2/NoOpComposer.cpp b/system/hwc2/NoOpComposer.cpp
new file mode 100644
index 00000000..f0bcfe23
--- /dev/null
+++ b/system/hwc2/NoOpComposer.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * 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.
+ */
+
+#include "NoOpComposer.h"
+
+#include "Device.h"
+#include "Display.h"
+#include "Drm.h"
+#include "Layer.h"
+
+namespace android {
+
+NoOpComposer::NoOpComposer() {}
+
+HWC2::Error NoOpComposer::init() {
+ DEBUG_LOG("%s", __FUNCTION__);
+
+ return HWC2::Error::None;
+}
+
+HWC2::Error NoOpComposer::onDisplayCreate(Display*) {
+ DEBUG_LOG("%s", __FUNCTION__);
+
+ return HWC2::Error::None;
+}
+
+HWC2::Error NoOpComposer::onDisplayDestroy(Display*) {
+ DEBUG_LOG("%s", __FUNCTION__);
+
+ return HWC2::Error::None;
+}
+
+HWC2::Error NoOpComposer::onDisplayClientTargetSet(Display*) {
+ DEBUG_LOG("%s", __FUNCTION__);
+
+ return HWC2::Error::None;
+}
+
+HWC2::Error NoOpComposer::onActiveConfigChange(Display*) {
+ DEBUG_LOG("%s", __FUNCTION__);
+
+ return HWC2::Error::None;
+};
+
+HWC2::Error NoOpComposer::validateDisplay(
+ Display* display, std::unordered_map<hwc2_layer_t, HWC2::Composition>*) {
+ const auto displayId = display->getId();
+ DEBUG_LOG("%s display:%" PRIu64, __FUNCTION__, displayId);
+
+ return HWC2::Error::None;
+}
+
+std::tuple<HWC2::Error, base::unique_fd> NoOpComposer::presentDisplay(
+ Display*) {
+ ATRACE_CALL();
+ DEBUG_LOG("%s", __FUNCTION__);
+
+ base::unique_fd emptyFence;
+ return std::make_tuple(HWC2::Error::None, std::move(emptyFence));
+}
+
+} // namespace android
diff --git a/system/hwc2/NoOpComposer.h b/system/hwc2/NoOpComposer.h
new file mode 100644
index 00000000..c3cbb4e8
--- /dev/null
+++ b/system/hwc2/NoOpComposer.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * 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.
+ */
+
+#ifndef ANDROID_HWC_NOOPCOMPOSER_H
+#define ANDROID_HWC_NOOPCOMPOSER_H
+
+#include "Common.h"
+#include "Composer.h"
+#include "Display.h"
+#include "DrmPresenter.h"
+#include "Gralloc.h"
+#include "Layer.h"
+
+namespace android {
+
+class NoOpComposer : public Composer {
+ public:
+ NoOpComposer();
+
+ NoOpComposer(const NoOpComposer&) = delete;
+ NoOpComposer& operator=(const NoOpComposer&) = delete;
+
+ NoOpComposer(NoOpComposer&&) = delete;
+ NoOpComposer& operator=(NoOpComposer&&) = delete;
+
+ HWC2::Error init() override;
+
+ HWC2::Error onDisplayCreate(Display*) override;
+
+ HWC2::Error onDisplayDestroy(Display*) override;
+
+ HWC2::Error onDisplayClientTargetSet(Display*) override;
+
+ HWC2::Error onActiveConfigChange(Display*) override;
+
+ // Determines if this composer can compose the given layers on the given
+ // display and requests changes for layers that can't not be composed.
+ HWC2::Error validateDisplay(
+ Display* display, std::unordered_map<hwc2_layer_t, HWC2::Composition>*
+ outLayerCompositionChanges) override;
+
+ // Performs the actual composition of layers and presents the composed result
+ // to the display.
+ std::tuple<HWC2::Error, base::unique_fd> presentDisplay(
+ Display* display) override;
+};
+
+} // namespace android
+
+#endif
diff --git a/system/hwc2/virtgpu_drm.h b/system/hwc2/virtgpu_drm.h
deleted file mode 120000
index b85a9f43..00000000
--- a/system/hwc2/virtgpu_drm.h
+++ /dev/null
@@ -1 +0,0 @@
-../../shared/GoldfishAddressSpace/include/virtgpu_drm.h \ No newline at end of file
diff --git a/shared/GoldfishAddressSpace/include/virtgpu_drm.h b/system/include/virtgpu_drm.h
index a13e20cc..a13e20cc 100644
--- a/shared/GoldfishAddressSpace/include/virtgpu_drm.h
+++ b/system/include/virtgpu_drm.h
diff --git a/system/meson.build b/system/meson.build
index f14306be..53ab8766 100644
--- a/system/meson.build
+++ b/system/meson.build
@@ -1,7 +1,6 @@
# Copyright 2022 Android Open Source Project
# SPDX-License-Identifier: MIT
-inc_system = include_directories('include')
inc_opengl_system = include_directories('OpenglSystemCommon')
inc_render_enc = include_directories('renderControl_enc')
inc_vulkan_enc = include_directories('vulkan_enc')
diff --git a/system/vulkan_enc/ResourceTracker.cpp b/system/vulkan_enc/ResourceTracker.cpp
index 2f64e551..80862a64 100644
--- a/system/vulkan_enc/ResourceTracker.cpp
+++ b/system/vulkan_enc/ResourceTracker.cpp
@@ -2580,18 +2580,20 @@ public:
}
// Get row alignment from host GPU.
- VkDeviceSize offset;
- VkDeviceSize rowPitchAlignment;
-
- VkImageCreateInfo createInfoDup = *createInfo;
- createInfoDup.pNext = nullptr;
- enc->vkGetLinearImageLayout2GOOGLE(device, &createInfoDup, &offset,
- &rowPitchAlignment,
- true /* do lock */);
- ALOGD(
- "vkGetLinearImageLayout2GOOGLE: format %d offset %lu "
- "rowPitchAlignment = %lu",
- (int)createInfo->format, offset, rowPitchAlignment);
+ VkDeviceSize offset = 0;
+ VkDeviceSize rowPitchAlignment = 1u;
+
+ if (tiling == VK_IMAGE_TILING_LINEAR) {
+ VkImageCreateInfo createInfoDup = *createInfo;
+ createInfoDup.pNext = nullptr;
+ enc->vkGetLinearImageLayout2GOOGLE(device, &createInfoDup, &offset,
+ &rowPitchAlignment,
+ true /* do lock */);
+ ALOGD(
+ "vkGetLinearImageLayout2GOOGLE: format %d offset %lu "
+ "rowPitchAlignment = %lu",
+ (int)createInfo->format, offset, rowPitchAlignment);
+ }
imageConstraints.min_coded_width = createInfo->extent.width;
imageConstraints.max_coded_width = 0xfffffff;
@@ -5167,7 +5169,6 @@ public:
const VkSamplerCreateInfo* pCreateInfo,
const VkAllocationCallbacks* pAllocator,
VkSampler* pSampler) {
-
VkSamplerCreateInfo localCreateInfo = vk_make_orphan_copy(*pCreateInfo);
vk_struct_chain_iterator structChainIter = vk_make_chain_iterator(&localCreateInfo);
@@ -5181,6 +5182,15 @@ public:
vk_append_struct(&structChainIter, &localVkSamplerYcbcrConversionInfo);
}
}
+
+ VkSamplerCustomBorderColorCreateInfoEXT localVkSamplerCustomBorderColorCreateInfo;
+ const VkSamplerCustomBorderColorCreateInfoEXT* samplerCustomBorderColorCreateInfo =
+ vk_find_struct<VkSamplerCustomBorderColorCreateInfoEXT>(pCreateInfo);
+ if (samplerCustomBorderColorCreateInfo) {
+ localVkSamplerCustomBorderColorCreateInfo =
+ vk_make_orphan_copy(*samplerCustomBorderColorCreateInfo);
+ vk_append_struct(&structChainIter, &localVkSamplerCustomBorderColorCreateInfo);
+ }
#endif
VkEncoder* enc = (VkEncoder*)context;
diff --git a/system/vulkan_enc/meson.build b/system/vulkan_enc/meson.build
index ab53b6ad..be3eba99 100644
--- a/system/vulkan_enc/meson.build
+++ b/system/vulkan_enc/meson.build
@@ -26,7 +26,7 @@ lib_vulkan_enc = static_library(
files_lib_vulkan_enc,
cpp_args: cpp_args,
include_directories: [inc_android_emu, inc_host, inc_android_compat,
- inc_opengl_codec, inc_render_enc,
+ inc_opengl_codec, inc_render_enc, inc_system,
inc_goldfish_address_space],
dependencies: dependency('libdrm'),
)
diff --git a/system/vulkan_enc/virtgpu_drm.h b/system/vulkan_enc/virtgpu_drm.h
deleted file mode 120000
index b85a9f43..00000000
--- a/system/vulkan_enc/virtgpu_drm.h
+++ /dev/null
@@ -1 +0,0 @@
-../../shared/GoldfishAddressSpace/include/virtgpu_drm.h \ No newline at end of file
diff --git a/system/vulkan_enc/vk_struct_id.h b/system/vulkan_enc/vk_struct_id.h
index 48ecc244..cee3d9d9 100644
--- a/system/vulkan_enc/vk_struct_id.h
+++ b/system/vulkan_enc/vk_struct_id.h
@@ -53,6 +53,7 @@ REGISTER_VK_STRUCT_ID(VkBufferCollectionImageCreateInfoFUCHSIAX, VK_STRUCTURE_TY
REGISTER_VK_STRUCT_ID(VkBufferCollectionBufferCreateInfoFUCHSIAX, VK_STRUCTURE_TYPE_BUFFER_COLLECTION_BUFFER_CREATE_INFO_FUCHSIAX);
#endif // VK_USE_PLATFORM_FUCHSIA
REGISTER_VK_STRUCT_ID(VkSamplerCreateInfo, VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO);
+REGISTER_VK_STRUCT_ID(VkSamplerCustomBorderColorCreateInfoEXT, VK_STRUCTURE_TYPE_SAMPLER_CUSTOM_BORDER_COLOR_CREATE_INFO_EXT);
REGISTER_VK_STRUCT_ID(VkSamplerYcbcrConversionInfo, VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO);
REGISTER_VK_STRUCT_ID(VkFenceCreateInfo, VK_STRUCTURE_TYPE_FENCE_CREATE_INFO);
REGISTER_VK_STRUCT_ID(VkExportFenceCreateInfo, VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO);