Merge "Remove GenericMetadata from composer3"
diff --git a/libs/binder/ndk/ibinder.cpp b/libs/binder/ndk/ibinder.cpp
index 6949c2c..28e3ff4 100644
--- a/libs/binder/ndk/ibinder.cpp
+++ b/libs/binder/ndk/ibinder.cpp
@@ -799,3 +799,12 @@
void AIBinder_setMinSchedulerPolicy(AIBinder* binder, int policy, int priority) {
binder->asABBinder()->setMinSchedulerPolicy(policy, priority);
}
+
+void AIBinder_setInheritRt(AIBinder* binder, bool inheritRt) {
+ ABBinder* localBinder = binder->asABBinder();
+ if (localBinder == nullptr) {
+ LOG(FATAL) << "AIBinder_setInheritRt must be called on a local binder";
+ }
+
+ localBinder->setInheritRt(inheritRt);
+}
diff --git a/libs/binder/ndk/include_platform/android/binder_ibinder_platform.h b/libs/binder/ndk/include_platform/android/binder_ibinder_platform.h
index b0217c4..0549198 100644
--- a/libs/binder/ndk/include_platform/android/binder_ibinder_platform.h
+++ b/libs/binder/ndk/include_platform/android/binder_ibinder_platform.h
@@ -68,4 +68,15 @@
*/
void AIBinder_setMinSchedulerPolicy(AIBinder* binder, int policy, int priority) __INTRODUCED_IN(33);
+/**
+ * Allow the binder to inherit realtime scheduling policies from its caller.
+ *
+ * This must be called before the object is sent to another process. Not thread
+ * safe.
+ *
+ * \param inheritRt whether to inherit realtime scheduling policies (default is
+ * false).
+ */
+void AIBinder_setInheritRt(AIBinder* binder, bool inheritRt) __INTRODUCED_IN(33);
+
__END_DECLS
diff --git a/libs/binder/ndk/libbinder_ndk.map.txt b/libs/binder/ndk/libbinder_ndk.map.txt
index 197c0a1..3824a1b 100644
--- a/libs/binder/ndk/libbinder_ndk.map.txt
+++ b/libs/binder/ndk/libbinder_ndk.map.txt
@@ -146,6 +146,7 @@
AIBinder_Class_disableInterfaceTokenHeader;
AIBinder_DeathRecipient_setOnUnlinked;
AIBinder_isHandlingTransaction;
+ AIBinder_setInheritRt; # llndk
AIBinder_setMinSchedulerPolicy; # llndk
AParcel_marshal;
AParcel_unmarshal;
diff --git a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp
index 499f88e..58fa13a 100644
--- a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp
+++ b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp
@@ -505,6 +505,31 @@
}
};
+TEST(NdkBinder, SetInheritRt) {
+ // functional test in binderLibTest
+ sp<IFoo> foo = sp<MyTestFoo>::make();
+ AIBinder* binder = foo->getBinder();
+
+ // does not abort
+ AIBinder_setInheritRt(binder, true);
+ AIBinder_setInheritRt(binder, false);
+ AIBinder_setInheritRt(binder, true);
+
+ AIBinder_decStrong(binder);
+}
+
+TEST(NdkBinder, SetInheritRtNonLocal) {
+ AIBinder* binder = AServiceManager_getService(kExistingNonNdkService);
+ ASSERT_NE(binder, nullptr);
+
+ ASSERT_TRUE(AIBinder_isRemote(binder));
+
+ EXPECT_DEATH(AIBinder_setInheritRt(binder, true), "");
+ EXPECT_DEATH(AIBinder_setInheritRt(binder, false), "");
+
+ AIBinder_decStrong(binder);
+}
+
TEST(NdkBinder, AddNullService) {
EXPECT_EQ(EX_ILLEGAL_ARGUMENT, AServiceManager_addService(nullptr, "any-service-name"));
}
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index aafa5e4..cf04ec8 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -1104,7 +1104,8 @@
}
if ((mask & layer_state_t::eLayerOpaque) || (mask & layer_state_t::eLayerHidden) ||
(mask & layer_state_t::eLayerSecure) || (mask & layer_state_t::eLayerSkipScreenshot) ||
- (mask & layer_state_t::eEnableBackpressure)) {
+ (mask & layer_state_t::eEnableBackpressure) ||
+ (mask & layer_state_t::eLayerIsDisplayDecoration)) {
s->what |= layer_state_t::eFlagsChanged;
}
s->flags &= ~mask;
diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h
index b01eed4..a0d3162 100644
--- a/libs/gui/include/gui/LayerState.h
+++ b/libs/gui/include/gui/LayerState.h
@@ -109,6 +109,7 @@
// set. This blocks the client until all the buffers have been presented. If the buffers
// have presentation timestamps, then we may drop buffers.
eEnableBackpressure = 0x100, // ENABLE_BACKPRESSURE
+ eLayerIsDisplayDecoration = 0x200, // DISPLAY_DECORATION
};
enum {
diff --git a/libs/renderengine/threaded/RenderEngineThreaded.cpp b/libs/renderengine/threaded/RenderEngineThreaded.cpp
index 3d446e8..08fc814 100644
--- a/libs/renderengine/threaded/RenderEngineThreaded.cpp
+++ b/libs/renderengine/threaded/RenderEngineThreaded.cpp
@@ -178,6 +178,10 @@
void RenderEngineThreaded::genTextures(size_t count, uint32_t* names) {
ATRACE_CALL();
+ // This is a no-op in SkiaRenderEngine.
+ if (getRenderEngineType() != RenderEngineType::THREADED) {
+ return;
+ }
std::promise<void> resultPromise;
std::future<void> resultFuture = resultPromise.get_future();
{
@@ -194,6 +198,10 @@
void RenderEngineThreaded::deleteTextures(size_t count, uint32_t const* names) {
ATRACE_CALL();
+ // This is a no-op in SkiaRenderEngine.
+ if (getRenderEngineType() != RenderEngineType::THREADED) {
+ return;
+ }
std::promise<void> resultPromise;
std::future<void> resultFuture = resultPromise.get_future();
{
diff --git a/services/surfaceflinger/BufferLayer.cpp b/services/surfaceflinger/BufferLayer.cpp
index e26c763..d61a4cb 100644
--- a/services/surfaceflinger/BufferLayer.cpp
+++ b/services/surfaceflinger/BufferLayer.cpp
@@ -295,6 +295,9 @@
compositionState->compositionType =
aidl::android::hardware::graphics::composer3::Composition::SIDEBAND;
return;
+ } else if ((mDrawingState.flags & layer_state_t::eLayerIsDisplayDecoration) != 0) {
+ compositionState->compositionType =
+ aidl::android::hardware::graphics::composer3::Composition::DISPLAY_DECORATION;
} else {
// Normal buffer layers
compositionState->hdrMetadata = mBufferInfo.mHdrMetadata;
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/CompositionRefreshArgs.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/CompositionRefreshArgs.h
index 93586ed..f201751 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/CompositionRefreshArgs.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/CompositionRefreshArgs.h
@@ -85,6 +85,9 @@
// to prevent an early presentation of a frame.
std::shared_ptr<FenceTime> previousPresentFence;
+ // The expected time for the next present
+ nsecs_t expectedPresentTime{0};
+
// If set, a frame has been scheduled for that time.
std::optional<std::chrono::steady_clock::time_point> scheduledFrameTime;
};
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputCompositionState.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputCompositionState.h
index c5b6443..c8f177b 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputCompositionState.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/OutputCompositionState.h
@@ -121,6 +121,9 @@
// to prevent an early presentation of a frame.
std::shared_ptr<FenceTime> previousPresentFence;
+ // The expected time for the next present
+ nsecs_t expectedPresentTime{0};
+
// Current display brightness
float displayBrightnessNits{-1.f};
diff --git a/services/surfaceflinger/CompositionEngine/src/Display.cpp b/services/surfaceflinger/CompositionEngine/src/Display.cpp
index 3571319..5543ad5 100644
--- a/services/surfaceflinger/CompositionEngine/src/Display.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/Display.cpp
@@ -227,7 +227,8 @@
if (status_t result =
hwc.getDeviceCompositionChanges(*halDisplayId, anyLayersRequireClientComposition(),
getState().earliestPresentTime,
- getState().previousPresentFence, &changes);
+ getState().previousPresentFence,
+ getState().expectedPresentTime, &changes);
result != NO_ERROR) {
ALOGE("chooseCompositionStrategy failed for %s: %d (%s)", getName().c_str(), result,
strerror(-result));
diff --git a/services/surfaceflinger/CompositionEngine/src/Output.cpp b/services/surfaceflinger/CompositionEngine/src/Output.cpp
index d503153..6833584 100644
--- a/services/surfaceflinger/CompositionEngine/src/Output.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/Output.cpp
@@ -728,6 +728,7 @@
editState().earliestPresentTime = refreshArgs.earliestPresentTime;
editState().previousPresentFence = refreshArgs.previousPresentFence;
+ editState().expectedPresentTime = refreshArgs.expectedPresentTime;
compositionengine::OutputLayer* peekThroughLayer = nullptr;
sp<GraphicBuffer> previousOverride = nullptr;
diff --git a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
index 94ad6c3..545e2a2 100644
--- a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp
@@ -685,12 +685,12 @@
case Composition::DEVICE:
case Composition::SOLID_COLOR:
- case Composition::DISPLAY_DECORATION:
result = (to == Composition::CLIENT);
break;
case Composition::CURSOR:
case Composition::SIDEBAND:
+ case Composition::DISPLAY_DECORATION:
result = (to == Composition::CLIENT || to == Composition::DEVICE);
break;
}
diff --git a/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp b/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp
index 3bdb2c0..88f00a5 100644
--- a/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp
+++ b/services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp
@@ -560,7 +560,7 @@
TEST_F(DisplayChooseCompositionStrategyTest, takesEarlyOutOnHwcError) {
EXPECT_CALL(*mDisplay, anyLayersRequireClientComposition()).WillOnce(Return(false));
EXPECT_CALL(mHwComposer,
- getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), false, _, _, _))
+ getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), false, _, _, _, _))
.WillOnce(Return(INVALID_OPERATION));
mDisplay->chooseCompositionStrategy();
@@ -583,7 +583,7 @@
.WillOnce(Return(false));
EXPECT_CALL(mHwComposer,
- getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _))
+ getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
.WillOnce(Return(NO_ERROR));
EXPECT_CALL(*mDisplay, allLayersRequireClientComposition()).WillOnce(Return(false));
@@ -615,8 +615,8 @@
.WillOnce(Return(false));
EXPECT_CALL(mHwComposer,
- getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _))
- .WillOnce(DoAll(SetArgPointee<4>(changes), Return(NO_ERROR)));
+ getDeviceCompositionChanges(HalDisplayId(DEFAULT_DISPLAY_ID), true, _, _, _, _))
+ .WillOnce(DoAll(SetArgPointee<5>(changes), Return(NO_ERROR)));
EXPECT_CALL(*mDisplay, applyChangedTypesToLayers(changes.changedTypes)).Times(1);
EXPECT_CALL(*mDisplay, applyDisplayRequests(changes.displayRequests)).Times(1);
EXPECT_CALL(*mDisplay, applyLayerRequestsToLayers(changes.layerRequests)).Times(1);
diff --git a/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h b/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h
index 224dad1..0f174db 100644
--- a/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h
+++ b/services/surfaceflinger/CompositionEngine/tests/MockHWComposer.h
@@ -51,9 +51,9 @@
MOCK_METHOD2(allocatePhysicalDisplay, void(hal::HWDisplayId, PhysicalDisplayId));
MOCK_METHOD1(createLayer, std::shared_ptr<HWC2::Layer>(HalDisplayId));
- MOCK_METHOD5(getDeviceCompositionChanges,
+ MOCK_METHOD6(getDeviceCompositionChanges,
status_t(HalDisplayId, bool, std::chrono::steady_clock::time_point,
- const std::shared_ptr<FenceTime>&,
+ const std::shared_ptr<FenceTime>&, nsecs_t,
std::optional<android::HWComposer::DeviceRequestedChanges>*));
MOCK_METHOD5(setClientTarget,
status_t(HalDisplayId, uint32_t, const sp<Fence>&, const sp<GraphicBuffer>&,
diff --git a/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp b/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp
index e80fc34..081f526 100644
--- a/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp
+++ b/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp
@@ -245,6 +245,7 @@
bool AidlComposer::isSupported(OptionalFeature feature) const {
switch (feature) {
case OptionalFeature::RefreshRateSwitching:
+ case OptionalFeature::ExpectedPresentTime:
return true;
}
}
@@ -525,9 +526,8 @@
return Error::NONE;
}
-Error AidlComposer::setColorTransform(Display display, const float* matrix, ColorTransform hint) {
- mWriter.setColorTransform(translate<int64_t>(display), matrix,
- translate<AidlColorTransform>(hint));
+Error AidlComposer::setColorTransform(Display display, const float* matrix) {
+ mWriter.setColorTransform(translate<int64_t>(display), matrix);
return Error::NONE;
}
@@ -569,10 +569,11 @@
return Error::NONE;
}
-Error AidlComposer::validateDisplay(Display display, uint32_t* outNumTypes,
- uint32_t* outNumRequests) {
+Error AidlComposer::validateDisplay(Display display, nsecs_t expectedPresentTime,
+ uint32_t* outNumTypes, uint32_t* outNumRequests) {
ATRACE_NAME("HwcValidateDisplay");
- mWriter.validateDisplay(translate<int64_t>(display));
+ mWriter.validateDisplay(translate<int64_t>(display),
+ ClockMonotonicTimestamp{expectedPresentTime});
Error error = execute();
if (error != Error::NONE) {
@@ -584,11 +585,12 @@
return Error::NONE;
}
-Error AidlComposer::presentOrValidateDisplay(Display display, uint32_t* outNumTypes,
- uint32_t* outNumRequests, int* outPresentFence,
- uint32_t* state) {
+Error AidlComposer::presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
+ uint32_t* outNumTypes, uint32_t* outNumRequests,
+ int* outPresentFence, uint32_t* state) {
ATRACE_NAME("HwcPresentOrValidateDisplay");
- mWriter.presentOrvalidateDisplay(translate<int64_t>(display));
+ mWriter.presentOrvalidateDisplay(translate<int64_t>(display),
+ ClockMonotonicTimestamp{expectedPresentTime});
Error error = execute();
if (error != Error::NONE) {
diff --git a/services/surfaceflinger/DisplayHardware/AidlComposerHal.h b/services/surfaceflinger/DisplayHardware/AidlComposerHal.h
index fa33d96..777b295 100644
--- a/services/surfaceflinger/DisplayHardware/AidlComposerHal.h
+++ b/services/surfaceflinger/DisplayHardware/AidlComposerHal.h
@@ -116,7 +116,7 @@
int acquireFence, Dataspace dataspace,
const std::vector<IComposerClient::Rect>& damage) override;
Error setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) override;
- Error setColorTransform(Display display, const float* matrix, ColorTransform hint) override;
+ Error setColorTransform(Display display, const float* matrix) override;
Error setOutputBuffer(Display display, const native_handle_t* buffer,
int releaseFence) override;
Error setPowerMode(Display display, IComposerClient::PowerMode mode) override;
@@ -124,10 +124,11 @@
Error setClientTargetSlotCount(Display display) override;
- Error validateDisplay(Display display, uint32_t* outNumTypes,
+ Error validateDisplay(Display display, nsecs_t expectedPresentTime, uint32_t* outNumTypes,
uint32_t* outNumRequests) override;
- Error presentOrValidateDisplay(Display display, uint32_t* outNumTypes, uint32_t* outNumRequests,
+ Error presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
+ uint32_t* outNumTypes, uint32_t* outNumRequests,
int* outPresentFence, uint32_t* state) override;
Error setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) override;
diff --git a/services/surfaceflinger/DisplayHardware/ComposerHal.h b/services/surfaceflinger/DisplayHardware/ComposerHal.h
index 6f2aa78..a6a1e6f 100644
--- a/services/surfaceflinger/DisplayHardware/ComposerHal.h
+++ b/services/surfaceflinger/DisplayHardware/ComposerHal.h
@@ -77,6 +77,7 @@
enum class OptionalFeature {
RefreshRateSwitching,
+ ExpectedPresentTime,
};
virtual bool isSupported(OptionalFeature) const = 0;
@@ -138,7 +139,7 @@
int acquireFence, Dataspace dataspace,
const std::vector<IComposerClient::Rect>& damage) = 0;
virtual Error setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) = 0;
- virtual Error setColorTransform(Display display, const float* matrix, ColorTransform hint) = 0;
+ virtual Error setColorTransform(Display display, const float* matrix) = 0;
virtual Error setOutputBuffer(Display display, const native_handle_t* buffer,
int releaseFence) = 0;
virtual Error setPowerMode(Display display, IComposerClient::PowerMode mode) = 0;
@@ -146,12 +147,12 @@
virtual Error setClientTargetSlotCount(Display display) = 0;
- virtual Error validateDisplay(Display display, uint32_t* outNumTypes,
- uint32_t* outNumRequests) = 0;
+ virtual Error validateDisplay(Display display, nsecs_t expectedPresentTime,
+ uint32_t* outNumTypes, uint32_t* outNumRequests) = 0;
- virtual Error presentOrValidateDisplay(Display display, uint32_t* outNumTypes,
- uint32_t* outNumRequests, int* outPresentFence,
- uint32_t* state) = 0;
+ virtual Error presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
+ uint32_t* outNumTypes, uint32_t* outNumRequests,
+ int* outPresentFence, uint32_t* state) = 0;
virtual Error setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) = 0;
/* see setClientTarget for the purpose of slot */
diff --git a/services/surfaceflinger/DisplayHardware/HWC2.cpp b/services/surfaceflinger/DisplayHardware/HWC2.cpp
index 5dbec05..3dcea61 100644
--- a/services/surfaceflinger/DisplayHardware/HWC2.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWC2.cpp
@@ -436,8 +436,8 @@
return static_cast<Error>(intError);
}
-Error Display::setColorTransform(const android::mat4& matrix, ColorTransform hint) {
- auto intError = mComposer.setColorTransform(mId, matrix.asArray(), hint);
+Error Display::setColorTransform(const android::mat4& matrix) {
+ auto intError = mComposer.setColorTransform(mId, matrix.asArray());
return static_cast<Error>(intError);
}
@@ -492,11 +492,11 @@
return static_cast<Error>(intError);
}
-Error Display::validate(uint32_t* outNumTypes, uint32_t* outNumRequests)
-{
+Error Display::validate(nsecs_t expectedPresentTime, uint32_t* outNumTypes,
+ uint32_t* outNumRequests) {
uint32_t numTypes = 0;
uint32_t numRequests = 0;
- auto intError = mComposer.validateDisplay(mId, &numTypes, &numRequests);
+ auto intError = mComposer.validateDisplay(mId, expectedPresentTime, &numTypes, &numRequests);
auto error = static_cast<Error>(intError);
if (error != Error::NONE && !hasChangesError(error)) {
return error;
@@ -507,14 +507,14 @@
return error;
}
-Error Display::presentOrValidate(uint32_t* outNumTypes, uint32_t* outNumRequests,
- sp<android::Fence>* outPresentFence, uint32_t* state) {
-
+Error Display::presentOrValidate(nsecs_t expectedPresentTime, uint32_t* outNumTypes,
+ uint32_t* outNumRequests, sp<android::Fence>* outPresentFence,
+ uint32_t* state) {
uint32_t numTypes = 0;
uint32_t numRequests = 0;
int32_t presentFenceFd = -1;
- auto intError = mComposer.presentOrValidateDisplay(
- mId, &numTypes, &numRequests, &presentFenceFd, state);
+ auto intError = mComposer.presentOrValidateDisplay(mId, expectedPresentTime, &numTypes,
+ &numRequests, &presentFenceFd, state);
auto error = static_cast<Error>(intError);
if (error != Error::NONE && !hasChangesError(error)) {
return error;
diff --git a/services/surfaceflinger/DisplayHardware/HWC2.h b/services/surfaceflinger/DisplayHardware/HWC2.h
index 1425c61..c2ebd45 100644
--- a/services/surfaceflinger/DisplayHardware/HWC2.h
+++ b/services/surfaceflinger/DisplayHardware/HWC2.h
@@ -128,16 +128,17 @@
[[clang::warn_unused_result]] virtual hal::Error setColorMode(
hal::ColorMode mode, hal::RenderIntent renderIntent) = 0;
[[clang::warn_unused_result]] virtual hal::Error setColorTransform(
- const android::mat4& matrix, hal::ColorTransform hint) = 0;
+ const android::mat4& matrix) = 0;
[[clang::warn_unused_result]] virtual hal::Error setOutputBuffer(
const android::sp<android::GraphicBuffer>& buffer,
const android::sp<android::Fence>& releaseFence) = 0;
[[clang::warn_unused_result]] virtual hal::Error setPowerMode(hal::PowerMode mode) = 0;
[[clang::warn_unused_result]] virtual hal::Error setVsyncEnabled(hal::Vsync enabled) = 0;
- [[clang::warn_unused_result]] virtual hal::Error validate(uint32_t* outNumTypes,
+ [[clang::warn_unused_result]] virtual hal::Error validate(nsecs_t expectedPresentTime,
+ uint32_t* outNumTypes,
uint32_t* outNumRequests) = 0;
[[clang::warn_unused_result]] virtual hal::Error presentOrValidate(
- uint32_t* outNumTypes, uint32_t* outNumRequests,
+ nsecs_t expectedPresentTime, uint32_t* outNumTypes, uint32_t* outNumRequests,
android::sp<android::Fence>* outPresentFence, uint32_t* state) = 0;
[[clang::warn_unused_result]] virtual std::future<hal::Error> setDisplayBrightness(
float brightness) = 0;
@@ -197,13 +198,15 @@
const android::sp<android::Fence>& acquireFence,
hal::Dataspace dataspace) override;
hal::Error setColorMode(hal::ColorMode, hal::RenderIntent) override;
- hal::Error setColorTransform(const android::mat4& matrix, hal::ColorTransform hint) override;
+ hal::Error setColorTransform(const android::mat4& matrix) override;
hal::Error setOutputBuffer(const android::sp<android::GraphicBuffer>&,
const android::sp<android::Fence>& releaseFence) override;
hal::Error setPowerMode(hal::PowerMode) override;
hal::Error setVsyncEnabled(hal::Vsync enabled) override;
- hal::Error validate(uint32_t* outNumTypes, uint32_t* outNumRequests) override;
- hal::Error presentOrValidate(uint32_t* outNumTypes, uint32_t* outNumRequests,
+ hal::Error validate(nsecs_t expectedPresentTime, uint32_t* outNumTypes,
+ uint32_t* outNumRequests) override;
+ hal::Error presentOrValidate(nsecs_t expectedPresentTime, uint32_t* outNumTypes,
+ uint32_t* outNumRequests,
android::sp<android::Fence>* outPresentFence,
uint32_t* state) override;
std::future<hal::Error> setDisplayBrightness(float brightness) override;
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
index 6d6aa8e..3b4fff0 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp
@@ -459,7 +459,7 @@
status_t HWComposer::getDeviceCompositionChanges(
HalDisplayId displayId, bool frameUsesClientComposition,
std::chrono::steady_clock::time_point earliestPresentTime,
- const std::shared_ptr<FenceTime>& previousPresentFence,
+ const std::shared_ptr<FenceTime>& previousPresentFence, nsecs_t expectedPresentTime,
std::optional<android::HWComposer::DeviceRequestedChanges>* outChanges) {
ATRACE_CALL();
@@ -481,16 +481,30 @@
// earliest time to present. Otherwise, we may present a frame too early.
// 2. There is no client composition. Otherwise, we first need to render the
// client target buffer.
- const bool prevFencePending =
- previousPresentFence->getSignalTime() == Fence::SIGNAL_TIME_PENDING;
- const bool canPresentEarly =
- !prevFencePending && std::chrono::steady_clock::now() < earliestPresentTime;
- const bool canSkipValidate = !canPresentEarly && !frameUsesClientComposition;
+ const bool canSkipValidate = [&] {
+ // We must call validate if we have client composition
+ if (frameUsesClientComposition) {
+ return false;
+ }
+
+ // If composer supports getting the expected present time, we can skip
+ // as composer will make sure to prevent early presentation
+ if (mComposer->isSupported(Hwc2::Composer::OptionalFeature::ExpectedPresentTime)) {
+ return true;
+ }
+
+ // composer doesn't support getting the expected present time. We can only
+ // skip validate if we know that we are not going to present early.
+ return std::chrono::steady_clock::now() >= earliestPresentTime ||
+ previousPresentFence->getSignalTime() == Fence::SIGNAL_TIME_PENDING;
+ }();
+
displayData.validateWasSkipped = false;
if (canSkipValidate) {
sp<Fence> outPresentFence;
uint32_t state = UINT32_MAX;
- error = hwcDisplay->presentOrValidate(&numTypes, &numRequests, &outPresentFence , &state);
+ error = hwcDisplay->presentOrValidate(expectedPresentTime, &numTypes, &numRequests,
+ &outPresentFence, &state);
if (!hasChangesError(error)) {
RETURN_IF_HWC_ERROR_FOR("presentOrValidate", error, displayId, UNKNOWN_ERROR);
}
@@ -505,7 +519,7 @@
}
// Present failed but Validate ran.
} else {
- error = hwcDisplay->validate(&numTypes, &numRequests);
+ error = hwcDisplay->validate(expectedPresentTime, &numTypes, &numRequests);
}
ALOGV("SkipValidate failed, Falling back to SLOW validate/present");
if (!hasChangesError(error)) {
@@ -571,9 +585,11 @@
return NO_ERROR;
}
- const bool previousFramePending =
- previousPresentFence->getSignalTime() == Fence::SIGNAL_TIME_PENDING;
- if (!previousFramePending) {
+ const bool waitForEarliestPresent =
+ !mComposer->isSupported(Hwc2::Composer::OptionalFeature::ExpectedPresentTime) &&
+ previousPresentFence->getSignalTime() != Fence::SIGNAL_TIME_PENDING;
+
+ if (waitForEarliestPresent) {
ATRACE_NAME("wait for earliest present time");
std::this_thread::sleep_until(earliestPresentTime);
}
@@ -657,11 +673,7 @@
RETURN_IF_INVALID_DISPLAY(displayId, BAD_INDEX);
auto& displayData = mDisplayData[displayId];
- bool isIdentity = transform == mat4();
- auto error = displayData.hwcDisplay
- ->setColorTransform(transform,
- isIdentity ? hal::ColorTransform::IDENTITY
- : hal::ColorTransform::ARBITRARY_MATRIX);
+ auto error = displayData.hwcDisplay->setColorTransform(transform);
RETURN_IF_HWC_ERROR(error, displayId, UNKNOWN_ERROR);
return NO_ERROR;
}
diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.h b/services/surfaceflinger/DisplayHardware/HWComposer.h
index be2e769..b7f1064 100644
--- a/services/surfaceflinger/DisplayHardware/HWComposer.h
+++ b/services/surfaceflinger/DisplayHardware/HWComposer.h
@@ -134,7 +134,7 @@
virtual status_t getDeviceCompositionChanges(
HalDisplayId, bool frameUsesClientComposition,
std::chrono::steady_clock::time_point earliestPresentTime,
- const std::shared_ptr<FenceTime>& previousPresentFence,
+ const std::shared_ptr<FenceTime>& previousPresentFence, nsecs_t expectedPresentTime,
std::optional<DeviceRequestedChanges>* outChanges) = 0;
virtual status_t setClientTarget(HalDisplayId, uint32_t slot, const sp<Fence>& acquireFence,
@@ -283,7 +283,7 @@
status_t getDeviceCompositionChanges(
HalDisplayId, bool frameUsesClientComposition,
std::chrono::steady_clock::time_point earliestPresentTime,
- const std::shared_ptr<FenceTime>& previousPresentFence,
+ const std::shared_ptr<FenceTime>& previousPresentFence, nsecs_t expectedPresentTime,
std::optional<DeviceRequestedChanges>* outChanges) override;
status_t setClientTarget(HalDisplayId, uint32_t slot, const sp<Fence>& acquireFence,
diff --git a/services/surfaceflinger/DisplayHardware/HidlComposerHal.cpp b/services/surfaceflinger/DisplayHardware/HidlComposerHal.cpp
index ab16027..96f4496 100644
--- a/services/surfaceflinger/DisplayHardware/HidlComposerHal.cpp
+++ b/services/surfaceflinger/DisplayHardware/HidlComposerHal.cpp
@@ -158,6 +158,8 @@
switch (feature) {
case OptionalFeature::RefreshRateSwitching:
return mClient_2_4 != nullptr;
+ case OptionalFeature::ExpectedPresentTime:
+ return false;
}
}
@@ -505,9 +507,12 @@
return unwrapRet(ret);
}
-Error HidlComposer::setColorTransform(Display display, const float* matrix, ColorTransform hint) {
+Error HidlComposer::setColorTransform(Display display, const float* matrix) {
mWriter.selectDisplay(display);
- mWriter.setColorTransform(matrix, hint);
+ const bool isIdentity = (mat4(matrix) == mat4());
+ mWriter.setColorTransform(matrix,
+ isIdentity ? ColorTransform::IDENTITY
+ : ColorTransform::ARBITRARY_MATRIX);
return Error::NONE;
}
@@ -540,8 +545,8 @@
return unwrapRet(ret);
}
-Error HidlComposer::validateDisplay(Display display, uint32_t* outNumTypes,
- uint32_t* outNumRequests) {
+Error HidlComposer::validateDisplay(Display display, nsecs_t /*expectedPresentTime*/,
+ uint32_t* outNumTypes, uint32_t* outNumRequests) {
ATRACE_NAME("HwcValidateDisplay");
mWriter.selectDisplay(display);
mWriter.validateDisplay();
@@ -556,9 +561,9 @@
return Error::NONE;
}
-Error HidlComposer::presentOrValidateDisplay(Display display, uint32_t* outNumTypes,
- uint32_t* outNumRequests, int* outPresentFence,
- uint32_t* state) {
+Error HidlComposer::presentOrValidateDisplay(Display display, nsecs_t /*expectedPresentTime*/,
+ uint32_t* outNumTypes, uint32_t* outNumRequests,
+ int* outPresentFence, uint32_t* state) {
ATRACE_NAME("HwcPresentOrValidateDisplay");
mWriter.selectDisplay(display);
mWriter.presentOrvalidateDisplay();
diff --git a/services/surfaceflinger/DisplayHardware/HidlComposerHal.h b/services/surfaceflinger/DisplayHardware/HidlComposerHal.h
index d60d12c..8190c17 100644
--- a/services/surfaceflinger/DisplayHardware/HidlComposerHal.h
+++ b/services/surfaceflinger/DisplayHardware/HidlComposerHal.h
@@ -227,7 +227,7 @@
int acquireFence, Dataspace dataspace,
const std::vector<IComposerClient::Rect>& damage) override;
Error setColorMode(Display display, ColorMode mode, RenderIntent renderIntent) override;
- Error setColorTransform(Display display, const float* matrix, ColorTransform hint) override;
+ Error setColorTransform(Display display, const float* matrix) override;
Error setOutputBuffer(Display display, const native_handle_t* buffer,
int releaseFence) override;
Error setPowerMode(Display display, IComposerClient::PowerMode mode) override;
@@ -235,10 +235,11 @@
Error setClientTargetSlotCount(Display display) override;
- Error validateDisplay(Display display, uint32_t* outNumTypes,
+ Error validateDisplay(Display display, nsecs_t expectedPresentTime, uint32_t* outNumTypes,
uint32_t* outNumRequests) override;
- Error presentOrValidateDisplay(Display display, uint32_t* outNumTypes, uint32_t* outNumRequests,
+ Error presentOrValidateDisplay(Display display, nsecs_t expectedPresentTime,
+ uint32_t* outNumTypes, uint32_t* outNumRequests,
int* outPresentFence, uint32_t* state) override;
Error setCursorPosition(Display display, Layer layer, int32_t x, int32_t y) override;
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 80ca8a3..4d7e4d9 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -269,6 +269,7 @@
enum Permission {
ACCESS_SURFACE_FLINGER = 0x1,
ROTATE_SURFACE_FLINGER = 0x2,
+ INTERNAL_SYSTEM_WINDOW = 0x4,
};
struct IdleTimerConfig {
@@ -316,6 +317,7 @@
const String16 sControlDisplayBrightness("android.permission.CONTROL_DISPLAY_BRIGHTNESS");
const String16 sDump("android.permission.DUMP");
const String16 sCaptureBlackoutContent("android.permission.CAPTURE_BLACKOUT_CONTENT");
+const String16 sInternalSystemWindow("android.permission.INTERNAL_SYSTEM_WINDOW");
const char* KERNEL_IDLE_TIMER_PROP = "graphics.display.kernel_idle_timer.enabled";
@@ -358,6 +360,13 @@
PermissionCache::checkPermission(sRotateSurfaceFlinger, pid, uid);
}
+bool callingThreadHasInternalSystemWindowAccess() {
+ IPCThreadState* ipc = IPCThreadState::self();
+ const int pid = ipc->getCallingPid();
+ const int uid = ipc->getCallingUid();
+ return PermissionCache::checkPermission(sInternalSystemWindow, pid, uid);
+}
+
SurfaceFlinger::SurfaceFlinger(Factory& factory, SkipInitializationTag)
: mFactory(factory),
mPid(getpid()),
@@ -2101,11 +2110,13 @@
refreshArgs.devOptFlashDirtyRegionsDelay = std::chrono::milliseconds(mDebugFlashDelay);
}
- const auto prevVsyncTime = mScheduler->getPreviousVsyncFrom(mExpectedPresentTime);
+ const auto expectedPresentTime = mExpectedPresentTime.load();
+ const auto prevVsyncTime = mScheduler->getPreviousVsyncFrom(expectedPresentTime);
const auto hwcMinWorkDuration = mVsyncConfiguration->getCurrentConfigs().hwcMinWorkDuration;
refreshArgs.earliestPresentTime = prevVsyncTime - hwcMinWorkDuration;
refreshArgs.previousPresentFence = mPreviousPresentFences[0].fenceTime;
refreshArgs.scheduledFrameTime = mScheduler->getScheduledFrameTime();
+ refreshArgs.expectedPresentTime = expectedPresentTime;
// Store the present time just before calling to the composition engine so we could notify
// the scheduler.
@@ -3810,6 +3821,10 @@
permissions |= Permission::ROTATE_SURFACE_FLINGER;
}
+ if (callingThreadHasInternalSystemWindowAccess()) {
+ permissions |= Permission::INTERNAL_SYSTEM_WINDOW;
+ }
+
if (!(permissions & Permission::ACCESS_SURFACE_FLINGER) &&
(flags & (eEarlyWakeupStart | eEarlyWakeupEnd))) {
ALOGE("Only WindowManager is allowed to use eEarlyWakeup[Start|End] flags");
@@ -4147,8 +4162,15 @@
flags |= eTraversalNeeded;
}
if (what & layer_state_t::eFlagsChanged) {
- if (layer->setFlags(s.flags, s.mask))
- flags |= eTraversalNeeded;
+ auto changedFlags = s.flags;
+ if (changedFlags & layer_state_t::eLayerIsDisplayDecoration) {
+ if ((permissions & Permission::INTERNAL_SYSTEM_WINDOW) == 0) {
+ changedFlags &= ~layer_state_t::eLayerIsDisplayDecoration;
+ ALOGE("Attempt to use eLayerIsDisplayDecoration without permission "
+ "INTERNAL_SYSTEM_WINDOW!");
+ }
+ }
+ if (layer->setFlags(changedFlags, s.mask)) flags |= eTraversalNeeded;
}
if (what & layer_state_t::eCornerRadiusChanged) {
if (layer->setCornerRadius(s.cornerRadius))
diff --git a/services/surfaceflinger/tests/unittests/CompositionTest.cpp b/services/surfaceflinger/tests/unittests/CompositionTest.cpp
index 554e454..89a517f 100644
--- a/services/surfaceflinger/tests/unittests/CompositionTest.cpp
+++ b/services/surfaceflinger/tests/unittests/CompositionTest.cpp
@@ -87,6 +87,11 @@
constexpr int DEFAULT_SIDEBAND_STREAM = 51;
+MATCHER(IsIdentityMatrix, "") {
+ constexpr auto kIdentity = mat4();
+ return (mat4(arg) == kIdentity);
+}
+
class CompositionTest : public testing::Test {
public:
CompositionTest() {
@@ -325,9 +330,7 @@
template <typename Case>
static void setupCommonCompositionCallExpectations(CompositionTest* test) {
- EXPECT_CALL(*test->mComposer,
- setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
- .Times(1);
+ EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
EXPECT_CALL(*test->mComposer, getDisplayRequests(HWC_DISPLAY, _, _, _)).Times(1);
EXPECT_CALL(*test->mComposer, acceptDisplayChanges(HWC_DISPLAY)).Times(1);
EXPECT_CALL(*test->mComposer, presentDisplay(HWC_DISPLAY, _)).Times(1);
@@ -367,7 +370,8 @@
}
static void setupHwcCompositionCallExpectations(CompositionTest* test) {
- EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
+ EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
+ .Times(1);
EXPECT_CALL(*test->mDisplaySurface,
prepareFrame(compositionengine::DisplaySurface::CompositionType::Hwc))
@@ -375,11 +379,12 @@
}
static void setupHwcClientCompositionCallExpectations(CompositionTest* test) {
- EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _)).Times(1);
+ EXPECT_CALL(*test->mComposer, presentOrValidateDisplay(HWC_DISPLAY, _, _, _, _, _))
+ .Times(1);
}
static void setupHwcForcedClientCompositionCallExpectations(CompositionTest* test) {
- EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _)).Times(1);
+ EXPECT_CALL(*test->mComposer, validateDisplay(HWC_DISPLAY, _, _, _)).Times(1);
}
static void setupRECompositionCallExpectations(CompositionTest* test) {
@@ -446,9 +451,7 @@
template <typename Case>
static void setupCommonCompositionCallExpectations(CompositionTest* test) {
// TODO: This seems like an unnecessary call if display is powered off.
- EXPECT_CALL(*test->mComposer,
- setColorTransform(HWC_DISPLAY, _, Hwc2::ColorTransform::IDENTITY))
- .Times(1);
+ EXPECT_CALL(*test->mComposer, setColorTransform(HWC_DISPLAY, IsIdentityMatrix())).Times(1);
// TODO: This seems like an unnecessary call if display is powered off.
Case::CompositionType::setupHwcSetCallExpectations(test);
diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h
index 5cf8278..a1aacc0 100644
--- a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h
+++ b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockComposer.h
@@ -84,13 +84,14 @@
Error(Display, uint32_t, const sp<GraphicBuffer>&, int, Dataspace,
const std::vector<IComposerClient::Rect>&));
MOCK_METHOD3(setColorMode, Error(Display, ColorMode, RenderIntent));
- MOCK_METHOD3(setColorTransform, Error(Display, const float*, ColorTransform));
+ MOCK_METHOD2(setColorTransform, Error(Display, const float*));
MOCK_METHOD3(setOutputBuffer, Error(Display, const native_handle_t*, int));
MOCK_METHOD2(setPowerMode, Error(Display, IComposerClient::PowerMode));
MOCK_METHOD2(setVsyncEnabled, Error(Display, IComposerClient::Vsync));
MOCK_METHOD1(setClientTargetSlotCount, Error(Display));
- MOCK_METHOD3(validateDisplay, Error(Display, uint32_t*, uint32_t*));
- MOCK_METHOD5(presentOrValidateDisplay, Error(Display, uint32_t*, uint32_t*, int*, uint32_t*));
+ MOCK_METHOD4(validateDisplay, Error(Display, nsecs_t, uint32_t*, uint32_t*));
+ MOCK_METHOD6(presentOrValidateDisplay,
+ Error(Display, nsecs_t, uint32_t*, uint32_t*, int*, uint32_t*));
MOCK_METHOD4(setCursorPosition, Error(Display, Layer, int32_t, int32_t));
MOCK_METHOD5(setLayerBuffer, Error(Display, Layer, uint32_t, const sp<GraphicBuffer>&, int));
MOCK_METHOD3(setLayerSurfaceDamage,
diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockHWC2.h b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockHWC2.h
index d4fefee..b43bc0e 100644
--- a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockHWC2.h
+++ b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockHWC2.h
@@ -68,16 +68,16 @@
const android::sp<android::Fence> &, hal::Dataspace),
(override));
MOCK_METHOD(hal::Error, setColorMode, (hal::ColorMode, hal::RenderIntent), (override));
- MOCK_METHOD(hal::Error, setColorTransform, (const android::mat4 &, hal::ColorTransform),
- (override));
+ MOCK_METHOD(hal::Error, setColorTransform, (const android::mat4 &), (override));
MOCK_METHOD(hal::Error, setOutputBuffer,
(const android::sp<android::GraphicBuffer> &, const android::sp<android::Fence> &),
(override));
MOCK_METHOD(hal::Error, setPowerMode, (hal::PowerMode), (override));
MOCK_METHOD(hal::Error, setVsyncEnabled, (hal::Vsync), (override));
- MOCK_METHOD(hal::Error, validate, (uint32_t *, uint32_t *), (override));
+ MOCK_METHOD(hal::Error, validate, (nsecs_t, uint32_t *, uint32_t *), (override));
MOCK_METHOD(hal::Error, presentOrValidate,
- (uint32_t *, uint32_t *, android::sp<android::Fence> *, uint32_t *), (override));
+ (nsecs_t, uint32_t *, uint32_t *, android::sp<android::Fence> *, uint32_t *),
+ (override));
MOCK_METHOD(std::future<hal::Error>, setDisplayBrightness, (float), (override));
MOCK_METHOD(hal::Error, setActiveConfigWithConstraints,
(hal::HWConfigId, const hal::VsyncPeriodChangeConstraints &,
diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp
index e6717d7..4a6b4f1 100644
--- a/vulkan/libvulkan/swapchain.cpp
+++ b/vulkan/libvulkan/swapchain.cpp
@@ -1236,6 +1236,12 @@
return VK_ERROR_SURFACE_LOST_KHR;
}
+ // In shared mode the num_images must be one regardless of how many
+ // buffers were allocated for the buffer queue.
+ if (swapchain_image_usage & VK_SWAPCHAIN_IMAGE_USAGE_SHARED_BIT_ANDROID) {
+ num_images = 1;
+ }
+
int32_t legacy_usage = 0;
if (dispatch.GetSwapchainGrallocUsage2ANDROID) {
uint64_t consumer_usage, producer_usage;