Rev up vr_hwc to composer@2.3
Fix for issue: "[GSI XR] VrFlinger doesn't work on GSI/MTP845."
The flow that causes the issue is:
SurfaceFlinger gets an hotplug event and adds a display id of the
internal display (For instance, display id of 19260371107735809). This
display id gets added to the HWComposer through the hotplug event.
When updateVrFlinger() is eventually called in SurfaceFlinger, a new
HWComposer is created which has no display ids being tracked in
HWComposer. Another hotplug event starts from vr_hwc.cpp, which has a
display id of 0. SurfaceFlinger receives this hot plug event so
SurfaceFlinger has an display ids of [19260371107735809, 0]. HWComposer
only has display id 0.
Next processDisplayChangesLocked() is called in SurfaceFlinger and a new
FramebufferSurface is created with display id 19260371107735809.
In the FramebufferSurface it tries to call getActiveConfig() in
HWComposer with the display id of 19260371107735809, which HWComposer
does not know about. This results in a crash.
The display id is created from the edid data and display port.
The fix is to have the vr_hwc return the same edid data and display port
as the internal display. This will make the display id originating
from vr_hwc be the same as the internal display id. SurfaceFlinger
will now only have the display id of 19260371107735809, since it does not
overwrite the same display id on the hotplug events. HWComposer will only
have display id of 19260371107735809. The SurfaceFlinger and HwComposer
display ids match the code works correctly now.
This is accomplished by creating a version 2.0 of the vr_composer_client
and having vr_hwc inherit from version 2.3 instead of version 2.1 of the
composer hal. These changes are required to be able to pass through the
edid data. The display port and edid data is retrieved by vr_hwc via the
display_client.
The other required changes needed for this to work is:
ag/9215156
ag/9226524
Bug: 137325030
Bug: 138938154
Bug: 137448042
Test: manual - ran through modified unit test to make sure the edid data
was returned on the MTP 845.
Change-Id: I1c54e6cfda348260cf1013d6dca0dda58acb3b3c
diff --git a/services/surfaceflinger/Android.bp b/services/surfaceflinger/Android.bp
index afb9cec..97b7697 100644
--- a/services/surfaceflinger/Android.bp
+++ b/services/surfaceflinger/Android.bp
@@ -19,7 +19,7 @@
"-DEGL_EGLEXT_PROTOTYPES",
],
shared_libs: [
- "android.frameworks.vr.composer@1.0",
+ "android.frameworks.vr.composer@2.0",
"android.hardware.configstore-utils",
"android.hardware.configstore@1.0",
"android.hardware.configstore@1.1",
@@ -58,6 +58,14 @@
"libutils",
"libSurfaceFlingerProp",
],
+ // VrComposer is not used when building surfaceflinger for vendors
+ target: {
+ vendor: {
+ exclude_shared_libs: [
+ "android.frameworks.vr.composer@2.0",
+ ],
+ },
+ },
static_libs: [
"libcompositionengine",
"librenderengine",
@@ -177,6 +185,17 @@
// can be easily replaced.
"SurfaceFlingerFactory.cpp",
],
+ cflags: [
+ "-DUSE_VR_COMPOSER=1",
+ ],
+ // VrComposer is not used when building surfaceflinger for vendors
+ target: {
+ vendor: {
+ cflags: [
+ "-DUSE_VR_COMPOSER=0",
+ ],
+ },
+ },
logtags: ["EventLog/EventLogTags.logtags"],
}
diff --git a/services/surfaceflinger/CompositionEngine/Android.bp b/services/surfaceflinger/CompositionEngine/Android.bp
index ae6bdbc..d2e95d0 100644
--- a/services/surfaceflinger/CompositionEngine/Android.bp
+++ b/services/surfaceflinger/CompositionEngine/Android.bp
@@ -5,7 +5,7 @@
"-DLOG_TAG=\"CompositionEngine\"",
],
shared_libs: [
- "android.frameworks.vr.composer@1.0",
+ "android.frameworks.vr.composer@2.0",
"android.hardware.graphics.allocator@2.0",
"android.hardware.graphics.composer@2.1",
"android.hardware.graphics.composer@2.2",
diff --git a/services/surfaceflinger/DisplayHardware/ComposerHal.cpp b/services/surfaceflinger/DisplayHardware/ComposerHal.cpp
index 7f47a2e..e53d099 100644
--- a/services/surfaceflinger/DisplayHardware/ComposerHal.cpp
+++ b/services/surfaceflinger/DisplayHardware/ComposerHal.cpp
@@ -110,6 +110,7 @@
namespace impl {
+#if defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
Composer::CommandWriter::CommandWriter(uint32_t initialMaxSize)
: CommandWriterBase(initialMaxSize) {}
@@ -160,6 +161,7 @@
writeSigned(static_cast<int32_t>(metadata.format));
write64(metadata.usage);
}
+#endif // defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
Composer::Composer(const std::string& serviceName)
: mWriter(kWriterInitialSize),
@@ -198,12 +200,14 @@
LOG_ALWAYS_FATAL("failed to create composer client");
}
+#if defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
if (mIsUsingVrComposer) {
sp<IVrComposerClient> vrClient = IVrComposerClient::castFrom(mClient);
if (vrClient == nullptr) {
LOG_ALWAYS_FATAL("failed to create vr composer client");
}
}
+#endif // defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
}
Composer::~Composer() = default;
@@ -565,17 +569,20 @@
const std::vector<IComposerClient::Rect>& damage)
{
mWriter.selectDisplay(display);
+
+#if defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
if (mIsUsingVrComposer && target.get()) {
IVrComposerClient::BufferMetadata metadata = {
- .width = target->getWidth(),
- .height = target->getHeight(),
- .stride = target->getStride(),
- .layerCount = target->getLayerCount(),
- .format = static_cast<types::V1_0::PixelFormat>(target->getPixelFormat()),
- .usage = target->getUsage(),
+ .width = target->getWidth(),
+ .height = target->getHeight(),
+ .stride = target->getStride(),
+ .layerCount = target->getLayerCount(),
+ .format = static_cast<types::V1_2::PixelFormat>(target->getPixelFormat()),
+ .usage = target->getUsage(),
};
mWriter.setClientTargetMetadata(metadata);
}
+#endif // defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
const native_handle_t* handle = nullptr;
if (target.get()) {
@@ -695,17 +702,20 @@
{
mWriter.selectDisplay(display);
mWriter.selectLayer(layer);
+
+#if defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
if (mIsUsingVrComposer && buffer.get()) {
IVrComposerClient::BufferMetadata metadata = {
- .width = buffer->getWidth(),
- .height = buffer->getHeight(),
- .stride = buffer->getStride(),
- .layerCount = buffer->getLayerCount(),
- .format = static_cast<types::V1_0::PixelFormat>(buffer->getPixelFormat()),
- .usage = buffer->getUsage(),
+ .width = buffer->getWidth(),
+ .height = buffer->getHeight(),
+ .stride = buffer->getStride(),
+ .layerCount = buffer->getLayerCount(),
+ .format = static_cast<types::V1_2::PixelFormat>(buffer->getPixelFormat()),
+ .usage = buffer->getUsage(),
};
mWriter.setLayerBufferMetadata(metadata);
}
+#endif // defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
const native_handle_t* handle = nullptr;
if (buffer.get()) {
@@ -823,6 +833,7 @@
return Error::NONE;
}
+#if defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
Error Composer::setLayerInfo(Display display, Layer layer, uint32_t type,
uint32_t appId)
{
@@ -833,6 +844,15 @@
}
return Error::NONE;
}
+#else
+Error Composer::setLayerInfo(Display display, Layer layer, uint32_t, uint32_t) {
+ if (mIsUsingVrComposer) {
+ mWriter.selectDisplay(display);
+ mWriter.selectLayer(layer);
+ }
+ return Error::NONE;
+}
+#endif // defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
Error Composer::execute()
{
diff --git a/services/surfaceflinger/DisplayHardware/ComposerHal.h b/services/surfaceflinger/DisplayHardware/ComposerHal.h
index c4e952b..9f6cac2 100644
--- a/services/surfaceflinger/DisplayHardware/ComposerHal.h
+++ b/services/surfaceflinger/DisplayHardware/ComposerHal.h
@@ -23,7 +23,9 @@
#include <utility>
#include <vector>
-#include <android/frameworks/vr/composer/1.0/IVrComposerClient.h>
+#if defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
+#include <android/frameworks/vr/composer/2.0/IVrComposerClient.h>
+#endif // defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
#include <android/hardware/graphics/common/1.1/types.h>
#include <android/hardware/graphics/composer/2.3/IComposer.h>
#include <android/hardware/graphics/composer/2.3/IComposerClient.h>
@@ -38,7 +40,9 @@
namespace Hwc2 {
-using frameworks::vr::composer::V1_0::IVrComposerClient;
+#if defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
+using frameworks::vr::composer::V2_0::IVrComposerClient;
+#endif // defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
namespace types = hardware::graphics::common;
@@ -418,6 +422,7 @@
Error setDisplayBrightness(Display display, float brightness) override;
private:
+#if defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
class CommandWriter : public CommandWriterBase {
public:
explicit CommandWriter(uint32_t initialMaxSize);
@@ -433,6 +438,13 @@
void writeBufferMetadata(
const IVrComposerClient::BufferMetadata& metadata);
};
+#else
+ class CommandWriter : public CommandWriterBase {
+ public:
+ explicit CommandWriter(uint32_t initialMaxSize) : CommandWriterBase(initialMaxSize) {}
+ ~CommandWriter() override {}
+ };
+#endif // defined(USE_VR_COMPOSER) && USE_VR_COMPOSER
// Many public functions above simply write a command into the command
// queue to batch the calls. validateDisplay and presentDisplay will call