Merge changes from topic "inputdevice-supportsusi"
* changes:
Determine whether an input device supports USI using IDC files
TouchInputMapper: Cancel ongoing gesture when resetting
TouchInputMapper: Use early return in populateDeviceInfo
diff --git a/TEST_MAPPING b/TEST_MAPPING
index 260ee8d..f54f132 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -56,6 +56,9 @@
},
{
"include-filter": "*RefreshRateOverlayTest.*"
+ },
+ {
+ "exclude-filter": "*ChildLayerTest#ChildrenSurviveParentDestruction"
}
]
},
diff --git a/cmds/dumpstate/Android.bp b/cmds/dumpstate/Android.bp
index a60972b..a62bd01 100644
--- a/cmds/dumpstate/Android.bp
+++ b/cmds/dumpstate/Android.bp
@@ -126,6 +126,7 @@
],
required: [
"atrace",
+ "bugreport_procdump",
"dmabuf_dump",
"ip",
"iptables",
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 60c2077..b076c15 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -1624,7 +1624,8 @@
RunCommand("CPU INFO", {"top", "-b", "-n", "1", "-H", "-s", "6", "-o",
"pid,tid,user,pr,ni,%cpu,s,virt,res,pcy,cmd,name"});
- RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(RunCommand, "PROCRANK", {"procrank"}, AS_ROOT_20);
+ RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(RunCommand, "BUGREPORT_PROCDUMP", {"bugreport_procdump"},
+ CommandOptions::AS_ROOT);
RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(DumpVisibleWindowViews);
@@ -1641,9 +1642,6 @@
RunCommand("PROCESSES AND THREADS",
{"ps", "-A", "-T", "-Z", "-O", "pri,nice,rtprio,sched,pcy,time"});
- RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(RunCommand, "LIBRANK", {"librank"},
- CommandOptions::AS_ROOT);
-
if (ds.dump_pool_) {
WAIT_TASK_WITH_CONSENT_CHECK(std::move(dump_hals));
} else {
@@ -1673,8 +1671,6 @@
RunCommand("LIST OF OPEN FILES", {"lsof"}, CommandOptions::AS_ROOT);
- RUN_SLOW_FUNCTION_WITH_CONSENT_CHECK(for_each_pid, do_showmap, "SMAPS OF ALL PROCESSES");
-
for_each_tid(show_wchan, "BLOCKED PROCESS WAIT-CHANNELS");
for_each_pid(show_showtime, "PROCESS TIMES (pid cmd user system iowait+percentage)");
@@ -3922,15 +3918,6 @@
return;
}
-void do_showmap(int pid, const char *name) {
- char title[255];
- char arg[255];
-
- snprintf(title, sizeof(title), "SHOW MAP %d (%s)", pid, name);
- snprintf(arg, sizeof(arg), "%d", pid);
- RunCommand(title, {"showmap", "-q", arg}, CommandOptions::AS_ROOT);
-}
-
int Dumpstate::DumpFile(const std::string& title, const std::string& path) {
DurationReporter duration_reporter(title);
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h
index ee6b1ae..66f84cb 100644
--- a/cmds/dumpstate/dumpstate.h
+++ b/cmds/dumpstate/dumpstate.h
@@ -619,9 +619,6 @@
/* Displays a processes times */
void show_showtime(int pid, const char *name);
-/* Runs "showmap" for a process */
-void do_showmap(int pid, const char *name);
-
/* Gets the dmesg output for the kernel */
void do_dmesg();
diff --git a/include/attestation/HmacKeyManager.h b/include/attestation/HmacKeyManager.h
index 571a361..d725be1 100644
--- a/include/attestation/HmacKeyManager.h
+++ b/include/attestation/HmacKeyManager.h
@@ -14,6 +14,9 @@
* limitations under the License.
*/
+#ifndef ATTESTATION_HMACKEYMANAGER_H
+#define ATTESTATION_HMACKEYMANAGER_H
+
#include <array>
namespace android {
@@ -29,4 +32,6 @@
private:
const std::array<uint8_t, 128> mHmacKey;
};
-} // namespace android
\ No newline at end of file
+} // namespace android
+
+#endif // ATTESTATION_HMACKEYMANAGER_H
\ No newline at end of file
diff --git a/libs/binder/RpcSession.cpp b/libs/binder/RpcSession.cpp
index ff50c16..7d6bcfc 100644
--- a/libs/binder/RpcSession.cpp
+++ b/libs/binder/RpcSession.cpp
@@ -324,16 +324,18 @@
}
void RpcSession::WaitForShutdownListener::onSessionIncomingThreadEnded() {
+ mShutdownCount += 1;
mCv.notify_all();
}
void RpcSession::WaitForShutdownListener::waitForShutdown(RpcMutexUniqueLock& lock,
const sp<RpcSession>& session) {
- while (session->mConnections.mIncoming.size() > 0) {
+ while (mShutdownCount < session->mConnections.mMaxIncoming) {
if (std::cv_status::timeout == mCv.wait_for(lock, std::chrono::seconds(1))) {
ALOGE("Waiting for RpcSession to shut down (1s w/o progress): %zu incoming connections "
- "still.",
- session->mConnections.mIncoming.size());
+ "still %zu/%zu fully shutdown.",
+ session->mConnections.mIncoming.size(), mShutdownCount.load(),
+ session->mConnections.mMaxIncoming);
}
}
}
diff --git a/libs/binder/include/binder/RpcSession.h b/libs/binder/include/binder/RpcSession.h
index 5e5d4ea..40faf2c 100644
--- a/libs/binder/include/binder/RpcSession.h
+++ b/libs/binder/include/binder/RpcSession.h
@@ -240,6 +240,7 @@
private:
RpcConditionVariable mCv;
+ std::atomic<size_t> mShutdownCount = 0;
};
friend WaitForShutdownListener;
@@ -380,6 +381,7 @@
// hint index into clients, ++ when sending an async transaction
size_t mOutgoingOffset = 0;
std::vector<sp<RpcConnection>> mOutgoing;
+ // max size of mIncoming. Once any thread starts down, no more can be started.
size_t mMaxIncoming = 0;
std::vector<sp<RpcConnection>> mIncoming;
std::map<RpcMaybeThread::id, RpcMaybeThread> mThreads;
diff --git a/libs/binder/rust/src/binder.rs b/libs/binder/rust/src/binder.rs
index 63c8684..976f54d 100644
--- a/libs/binder/rust/src/binder.rs
+++ b/libs/binder/rust/src/binder.rs
@@ -1091,7 +1091,7 @@
}
} => {
$( #[$attr] )*
- #[derive(Debug, Default, Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
+ #[derive(Default, Copy, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)]
#[allow(missing_docs)]
pub struct $enum(pub $backing);
impl $enum {
@@ -1104,6 +1104,15 @@
}
}
+ impl std::fmt::Debug for $enum {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ match self.0 {
+ $($value => f.write_str(stringify!($name)),)*
+ _ => f.write_fmt(format_args!("{}", self.0))
+ }
+ }
+ }
+
impl $crate::binder_impl::Serialize for $enum {
fn serialize(&self, parcel: &mut $crate::binder_impl::BorrowedParcel<'_>) -> std::result::Result<(), $crate::StatusCode> {
parcel.write(&self.0)
diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp
index 2759c58..924e65e 100644
--- a/libs/gui/LayerState.cpp
+++ b/libs/gui/LayerState.cpp
@@ -40,13 +40,13 @@
x(0),
y(0),
z(0),
- alpha(0),
flags(0),
mask(0),
reserved(0),
cornerRadius(0.0f),
backgroundBlurRadius(0),
- transform(0),
+ color(0),
+ bufferTransform(0),
transformToDisplayInverse(false),
crop(Rect::INVALID_RECT),
dataspace(ui::Dataspace::UNKNOWN),
@@ -83,20 +83,19 @@
SAFE_PARCEL(output.writeFloat, y);
SAFE_PARCEL(output.writeInt32, z);
SAFE_PARCEL(output.writeUint32, layerStack.id);
- SAFE_PARCEL(output.writeFloat, alpha);
SAFE_PARCEL(output.writeUint32, flags);
SAFE_PARCEL(output.writeUint32, mask);
SAFE_PARCEL(matrix.write, output);
SAFE_PARCEL(output.write, crop);
- SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, reparentSurfaceControl);
SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, relativeLayerSurfaceControl);
SAFE_PARCEL(SurfaceControl::writeNullableToParcel, output, parentSurfaceControlForChild);
SAFE_PARCEL(output.writeFloat, color.r);
SAFE_PARCEL(output.writeFloat, color.g);
SAFE_PARCEL(output.writeFloat, color.b);
+ SAFE_PARCEL(output.writeFloat, color.a);
SAFE_PARCEL(windowInfoHandle->writeToParcel, &output);
SAFE_PARCEL(output.write, transparentRegion);
- SAFE_PARCEL(output.writeUint32, transform);
+ SAFE_PARCEL(output.writeUint32, bufferTransform);
SAFE_PARCEL(output.writeBool, transformToDisplayInverse);
SAFE_PARCEL(output.writeBool, borderEnabled);
SAFE_PARCEL(output.writeFloat, borderWidth);
@@ -177,7 +176,6 @@
SAFE_PARCEL(input.readFloat, &y);
SAFE_PARCEL(input.readInt32, &z);
SAFE_PARCEL(input.readUint32, &layerStack.id);
- SAFE_PARCEL(input.readFloat, &alpha);
SAFE_PARCEL(input.readUint32, &flags);
@@ -185,7 +183,6 @@
SAFE_PARCEL(matrix.read, input);
SAFE_PARCEL(input.read, crop);
- SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &reparentSurfaceControl);
SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &relativeLayerSurfaceControl);
SAFE_PARCEL(SurfaceControl::readNullableFromParcel, input, &parentSurfaceControlForChild);
@@ -197,10 +194,13 @@
color.g = tmpFloat;
SAFE_PARCEL(input.readFloat, &tmpFloat);
color.b = tmpFloat;
+ SAFE_PARCEL(input.readFloat, &tmpFloat);
+ color.a = tmpFloat;
+
SAFE_PARCEL(windowInfoHandle->readFromParcel, &input);
SAFE_PARCEL(input.read, transparentRegion);
- SAFE_PARCEL(input.readUint32, &transform);
+ SAFE_PARCEL(input.readUint32, &bufferTransform);
SAFE_PARCEL(input.readBool, &transformToDisplayInverse);
SAFE_PARCEL(input.readBool, &borderEnabled);
SAFE_PARCEL(input.readFloat, &tmpFloat);
@@ -453,7 +453,7 @@
}
if (other.what & eAlphaChanged) {
what |= eAlphaChanged;
- alpha = other.alpha;
+ color.a = other.color.a;
}
if (other.what & eMatrixChanged) {
what |= eMatrixChanged;
@@ -495,12 +495,9 @@
what |= eReparent;
parentSurfaceControlForChild = other.parentSurfaceControlForChild;
}
- if (other.what & eDestroySurface) {
- what |= eDestroySurface;
- }
- if (other.what & eTransformChanged) {
- what |= eTransformChanged;
- transform = other.transform;
+ if (other.what & eBufferTransformChanged) {
+ what |= eBufferTransformChanged;
+ bufferTransform = other.bufferTransform;
}
if (other.what & eTransformToDisplayInverseChanged) {
what |= eTransformToDisplayInverseChanged;
@@ -547,7 +544,7 @@
}
if (other.what & eBackgroundColorChanged) {
what |= eBackgroundColorChanged;
- color = other.color;
+ color.rgb = other.color.rgb;
bgColorAlpha = other.bgColorAlpha;
bgColorDataspace = other.bgColorDataspace;
}
@@ -612,7 +609,7 @@
}
if (other.what & eColorChanged) {
what |= eColorChanged;
- color = other.color;
+ color.rgb = other.color.rgb;
}
if (other.what & eColorSpaceAgnosticChanged) {
what |= eColorSpaceAgnosticChanged;
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index 694bc5a..04d4a07 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -25,6 +25,7 @@
#include <android/gui/ISurfaceComposerClient.h>
#include <android/gui/IWindowInfosListener.h>
#include <android/os/IInputConstants.h>
+#include <gui/TraceUtils.h>
#include <utils/Errors.h>
#include <utils/Log.h>
#include <utils/SortedVector.h>
@@ -910,9 +911,14 @@
uncacheBuffer.token = BufferCache::getInstance().getToken();
uncacheBuffer.id = cacheId;
- sf->setTransactionState(FrameTimelineInfo{}, {}, {}, ISurfaceComposer::eOneWay,
- Transaction::getDefaultApplyToken(), {}, systemTime(), true,
- uncacheBuffer, false, {}, generateId());
+ status_t status =
+ sf->setTransactionState(FrameTimelineInfo{}, {}, {}, ISurfaceComposer::eOneWay,
+ Transaction::getDefaultApplyToken(), {}, systemTime(), true,
+ uncacheBuffer, false, {}, generateId());
+ if (status != NO_ERROR) {
+ ALOGE_AND_TRACE("SurfaceComposerClient::doUncacheBufferTransaction - %s",
+ strerror(-status));
+ }
}
void SurfaceComposerClient::Transaction::cacheBuffers() {
@@ -1293,7 +1299,7 @@
ALOGE("SurfaceComposerClient::Transaction::setAlpha: invalid alpha %f, clamping", alpha);
}
s->what |= layer_state_t::eAlphaChanged;
- s->alpha = std::clamp(alpha, 0.f, 1.f);
+ s->color.a = std::clamp(alpha, 0.f, 1.f);
registerSurfaceControlForCallback(sc);
return *this;
@@ -1424,7 +1430,7 @@
return *this;
}
s->what |= layer_state_t::eColorChanged;
- s->color = color;
+ s->color.rgb = color;
registerSurfaceControlForCallback(sc);
return *this;
@@ -1439,7 +1445,7 @@
}
s->what |= layer_state_t::eBackgroundColorChanged;
- s->color = color;
+ s->color.rgb = color;
s->bgColorAlpha = alpha;
s->bgColorDataspace = dataspace;
@@ -1454,8 +1460,8 @@
mStatus = BAD_INDEX;
return *this;
}
- s->what |= layer_state_t::eTransformChanged;
- s->transform = transform;
+ s->what |= layer_state_t::eBufferTransformChanged;
+ s->bufferTransform = transform;
registerSurfaceControlForCallback(sc);
return *this;
@@ -2237,18 +2243,6 @@
// ----------------------------------------------------------------------------
-status_t SurfaceComposerClient::enableVSyncInjections(bool enable) {
- sp<gui::ISurfaceComposer> sf(ComposerServiceAIDL::getComposerService());
- binder::Status status = sf->enableVSyncInjections(enable);
- return statusTFromBinderStatus(status);
-}
-
-status_t SurfaceComposerClient::injectVSync(nsecs_t when) {
- sp<gui::ISurfaceComposer> sf(ComposerServiceAIDL::getComposerService());
- binder::Status status = sf->injectVSync(when);
- return statusTFromBinderStatus(status);
-}
-
status_t SurfaceComposerClient::getDisplayState(const sp<IBinder>& display,
ui::DisplayState* state) {
gui::DisplayState ds;
diff --git a/libs/gui/aidl/android/gui/ISurfaceComposer.aidl b/libs/gui/aidl/android/gui/ISurfaceComposer.aidl
index ac1442b..ca0b97f 100644
--- a/libs/gui/aidl/android/gui/ISurfaceComposer.aidl
+++ b/libs/gui/aidl/android/gui/ISurfaceComposer.aidl
@@ -224,10 +224,6 @@
*/
PullAtomData onPullAtom(int atomId);
- oneway void enableVSyncInjections(boolean enable);
-
- oneway void injectVSync(long when);
-
/**
* Gets the list of active layers in Z order for debugging purposes
*
diff --git a/libs/gui/fuzzer/libgui_fuzzer_utils.h b/libs/gui/fuzzer/libgui_fuzzer_utils.h
index 433b044..315b925 100644
--- a/libs/gui/fuzzer/libgui_fuzzer_utils.h
+++ b/libs/gui/fuzzer/libgui_fuzzer_utils.h
@@ -102,8 +102,6 @@
MOCK_METHOD(binder::Status, overrideHdrTypes, (const sp<IBinder>&, const std::vector<int32_t>&),
(override));
MOCK_METHOD(binder::Status, onPullAtom, (int32_t, gui::PullAtomData*), (override));
- MOCK_METHOD(binder::Status, enableVSyncInjections, (bool), (override));
- MOCK_METHOD(binder::Status, injectVSync, (int64_t), (override));
MOCK_METHOD(binder::Status, getLayerDebugInfo, (std::vector<gui::LayerDebugInfo>*), (override));
MOCK_METHOD(binder::Status, getColorManagement, (bool*), (override));
MOCK_METHOD(binder::Status, getCompositionPreference, (gui::CompositionPreference*),
diff --git a/libs/gui/fuzzer/libgui_surfaceComposerClient_fuzzer.cpp b/libs/gui/fuzzer/libgui_surfaceComposerClient_fuzzer.cpp
index 5bd6531..eecbe0f 100644
--- a/libs/gui/fuzzer/libgui_surfaceComposerClient_fuzzer.cpp
+++ b/libs/gui/fuzzer/libgui_surfaceComposerClient_fuzzer.cpp
@@ -271,10 +271,6 @@
sp<Surface> surfaceParent(
new Surface(producer, mFdp.ConsumeBool() /*controlledByApp*/, handle));
- SurfaceComposerClient::enableVSyncInjections(mFdp.ConsumeBool() /*secure*/);
- nsecs_t when = mFdp.ConsumeIntegral<uint32_t>();
- SurfaceComposerClient::injectVSync(when);
-
fuzzOnPullAtom();
SurfaceComposerClient::setDisplayContentSamplingEnabled(displayToken,
mFdp.ConsumeBool() /*enable*/,
diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h
index c8927ad..45272e7 100644
--- a/libs/gui/include/gui/LayerState.h
+++ b/libs/gui/include/gui/LayerState.h
@@ -148,12 +148,14 @@
enum {
ePositionChanged = 0x00000001,
eLayerChanged = 0x00000002,
- // unused = 0x00000004,
+ /* unused = 0x00000004, */
eAlphaChanged = 0x00000008,
eMatrixChanged = 0x00000010,
eTransparentRegionChanged = 0x00000020,
eFlagsChanged = 0x00000040,
eLayerStackChanged = 0x00000080,
+ /* unused = 0x00000100, */
+ /* unused = 0x00000200, */
eDimmingEnabledChanged = 0x00000400,
eShadowRadiusChanged = 0x00000800,
eRenderBorderChanged = 0x00001000,
@@ -161,8 +163,8 @@
eRelativeLayerChanged = 0x00004000,
eReparent = 0x00008000,
eColorChanged = 0x00010000,
- eDestroySurface = 0x00020000,
- eTransformChanged = 0x00040000,
+ /* unused = 0x00020000, */
+ eBufferTransformChanged = 0x00040000,
eTransformToDisplayInverseChanged = 0x00080000,
eCropChanged = 0x00100000,
eBufferChanged = 0x00200000,
@@ -218,25 +220,22 @@
float y;
int32_t z;
ui::LayerStack layerStack = ui::DEFAULT_LAYER_STACK;
- float alpha;
uint32_t flags;
uint32_t mask;
uint8_t reserved;
matrix22_t matrix;
float cornerRadius;
uint32_t backgroundBlurRadius;
- sp<SurfaceControl> reparentSurfaceControl;
sp<SurfaceControl> relativeLayerSurfaceControl;
sp<SurfaceControl> parentSurfaceControlForChild;
- half3 color;
+ half4 color;
// non POD must be last. see write/read
Region transparentRegion;
-
- uint32_t transform;
+ uint32_t bufferTransform;
bool transformToDisplayInverse;
Rect crop;
std::shared_ptr<BufferData> bufferData = nullptr;
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index 04d3ab2..d138d68 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -358,10 +358,6 @@
//! Get token for a physical display given its stable ID
static sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId);
- static status_t enableVSyncInjections(bool enable);
-
- static status_t injectVSync(nsecs_t when);
-
struct SCHash {
std::size_t operator()(const sp<SurfaceControl>& sc) const {
return std::hash<SurfaceControl *>{}(sc.get());
diff --git a/libs/gui/include/gui/TraceUtils.h b/libs/gui/include/gui/TraceUtils.h
index 4c01683..441b833 100644
--- a/libs/gui/include/gui/TraceUtils.h
+++ b/libs/gui/include/gui/TraceUtils.h
@@ -30,6 +30,12 @@
#define ATRACE_FORMAT_INSTANT(fmt, ...) \
(CC_UNLIKELY(ATRACE_ENABLED()) && (TraceUtils::instantFormat(fmt, ##__VA_ARGS__), true))
+#define ALOGE_AND_TRACE(fmt, ...) \
+ do { \
+ ALOGE(fmt, ##__VA_ARGS__); \
+ ATRACE_FORMAT_INSTANT(fmt, ##__VA_ARGS__); \
+ } while (false)
+
namespace android {
class TraceUtils {
diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp
index d5cc55f..72d76ee 100644
--- a/libs/gui/tests/Surface_test.cpp
+++ b/libs/gui/tests/Surface_test.cpp
@@ -851,10 +851,6 @@
return binder::Status::ok();
}
- binder::Status enableVSyncInjections(bool /*enable*/) override { return binder::Status::ok(); }
-
- binder::Status injectVSync(int64_t /*when*/) override { return binder::Status::ok(); }
-
binder::Status getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* /*outLayers*/) override {
return binder::Status::ok();
}
diff --git a/libs/jpegrecoverymap/Android.bp b/libs/jpegrecoverymap/Android.bp
new file mode 100644
index 0000000..285f8d5
--- /dev/null
+++ b/libs/jpegrecoverymap/Android.bp
@@ -0,0 +1,34 @@
+// 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.
+
+package {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "frameworks_native_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-Apache-2.0
+ default_applicable_licenses: ["frameworks_native_license"],
+}
+
+cc_library_static {
+ name: "libjpegrecoverymap",
+ vendor_available: true,
+
+ export_include_dirs: ["include"],
+ local_include_dirs: ["include"],
+
+ srcs: [
+ "recoverymap.cpp",
+ ],
+}
\ No newline at end of file
diff --git a/libs/jpegrecoverymap/OWNERS b/libs/jpegrecoverymap/OWNERS
new file mode 100644
index 0000000..6ace354
--- /dev/null
+++ b/libs/jpegrecoverymap/OWNERS
@@ -0,0 +1,3 @@
+arifdikici@google.com
+dichenzhang@google.com
+kyslov@google.com
\ No newline at end of file
diff --git a/libs/jpegrecoverymap/include/jpegrecoverymap/recoverymap.h b/libs/jpegrecoverymap/include/jpegrecoverymap/recoverymap.h
new file mode 100644
index 0000000..c5f8e9a
--- /dev/null
+++ b/libs/jpegrecoverymap/include/jpegrecoverymap/recoverymap.h
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+namespace android::recoverymap {
+
+class RecoveryMap {
+public:
+ /*
+ * This method is called in the decoding pipeline. It will decode the recovery map.
+ *
+ * input: compressed recovery map
+ * output: uncompressed recovery map
+ */
+ void* decodeRecoveryMap(void* compressed_recovery_map);
+
+ /*
+ * This method is called in the encoding pipeline. It will encode the recovery map.
+ *
+ * input: uncompressed recovery map
+ * output: compressed recovery map
+ */
+ void* encodeRecoveryMap(void* uncompressed_recovery_map);
+
+ /*
+ * This method is called in the encoding pipeline. It will take the uncompressed 8-bit and
+ * 10-bit yuv images as input, and calculate the uncompressed recovery map.
+ *
+ * input: uncompressed yuv_420 image, uncompressed p010 image
+ * output: uncompressed recovery map
+ */
+ void* generateRecoveryMap(void* uncompressed_yuv_420_image, void* uncompressed_p010_image);
+
+ /*
+ * This method is called in the decoding pipeline. It will take the uncompressed (decoded)
+ * 8-bit yuv image and the uncompressed(decoded) recovery map as input, and calculate the
+ * 10-bit recovered image (in p010 color format).
+ *
+ * input: uncompressed yuv_420 image, uncompressed recovery map
+ * output: uncompress p010 image
+ */
+ void* applyRecoveryMap(void* uncompressed_yuv_420_image, void* uncompressed_recovery_map);
+
+ /*
+ * This method is called in the decoding pipeline. It will read XMP metadata to find the start
+ * position of the compressed recovery map, and will extract the compressed recovery map.
+ *
+ * input: compressed JPEG-G image (8-bit JPEG + compressed recovery map)
+ * output: compressed recovery map
+ */
+ void* extractRecoveryMap(void* compressed_jpeg_g_image);
+
+ /*
+ * This method is called in the encoding pipeline. It will take the standard 8-bit JPEG image
+ * and the compressed recovery map as input, and update the XMP metadata with the end of JPEG
+ * marker, and append the compressed gian map after the JPEG.
+ *
+ * input: compressed 8-bit JPEG image (standard JPEG), compressed recovery map
+ * output: compressed JPEG-G image (8-bit JPEG + compressed recovery map)
+ */
+ void* appendRecoveryMap(void* compressed_jpeg_image, void* compressed_recovery_map);
+};
+
+} // namespace android::recoverymap
\ No newline at end of file
diff --git a/libs/jpegrecoverymap/recoverymap.cpp b/libs/jpegrecoverymap/recoverymap.cpp
new file mode 100644
index 0000000..3e95a31
--- /dev/null
+++ b/libs/jpegrecoverymap/recoverymap.cpp
@@ -0,0 +1,77 @@
+/*
+ * 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 <jpegrecoverymap/recoverymap.h>
+
+namespace android::recoverymap {
+
+void* RecoveryMap::decodeRecoveryMap(void* compressed_recovery_map) {
+ if (compressed_recovery_map == nullptr) {
+ return nullptr;
+ }
+
+ // TBD
+ return nullptr;
+}
+
+void* RecoveryMap::encodeRecoveryMap(void* uncompressed_recovery_map) {
+ if (uncompressed_recovery_map == nullptr) {
+ return nullptr;
+ }
+
+ // TBD
+ return nullptr;
+}
+
+void* RecoveryMap::generateRecoveryMap(
+ void* uncompressed_yuv_420_image, void* uncompressed_p010_image) {
+ if (uncompressed_yuv_420_image == nullptr || uncompressed_p010_image == nullptr) {
+ return nullptr;
+ }
+
+ // TBD
+ return nullptr;
+}
+
+void* RecoveryMap::applyRecoveryMap(
+ void* uncompressed_yuv_420_image, void* uncompressed_recovery_map) {
+ if (uncompressed_yuv_420_image == nullptr || uncompressed_recovery_map == nullptr) {
+ return nullptr;
+ }
+
+ // TBD
+ return nullptr;
+}
+
+void* RecoveryMap::extractRecoveryMap(void* compressed_jpeg_g_image) {
+ if (compressed_jpeg_g_image == nullptr) {
+ return nullptr;
+ }
+
+ // TBD
+ return nullptr;
+}
+
+void* RecoveryMap::appendRecoveryMap(void* compressed_jpeg_image, void* compressed_recovery_map) {
+ if (compressed_jpeg_image == nullptr || compressed_recovery_map == nullptr) {
+ return nullptr;
+ }
+
+ // TBD
+ return nullptr;
+}
+
+} // namespace android::recoverymap
diff --git a/libs/jpegrecoverymap/tests/Android.bp b/libs/jpegrecoverymap/tests/Android.bp
new file mode 100644
index 0000000..79bf723
--- /dev/null
+++ b/libs/jpegrecoverymap/tests/Android.bp
@@ -0,0 +1,33 @@
+// 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.
+
+package {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "frameworks_native_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-Apache-2.0
+ default_applicable_licenses: ["frameworks_native_license"],
+}
+
+cc_test {
+ name: "libjpegrecoverymap_test",
+ test_suites: ["device-tests"],
+ srcs: [
+ "recoverymap_test.cpp",
+ ],
+ static_libs: [
+ "libjpegrecoverymap",
+ ],
+}
\ No newline at end of file
diff --git a/libs/jpegrecoverymap/tests/recoverymap_test.cpp b/libs/jpegrecoverymap/tests/recoverymap_test.cpp
new file mode 100644
index 0000000..c436138
--- /dev/null
+++ b/libs/jpegrecoverymap/tests/recoverymap_test.cpp
@@ -0,0 +1,22 @@
+/*
+ * 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 <jpegrecoverymap/recoverymap.h>
+
+namespace android {
+
+// Add new tests here.
+} // namespace android
diff --git a/services/inputflinger/tests/PreferStylusOverTouch_test.cpp b/services/inputflinger/tests/PreferStylusOverTouch_test.cpp
index 8e2ab88..bd05360 100644
--- a/services/inputflinger/tests/PreferStylusOverTouch_test.cpp
+++ b/services/inputflinger/tests/PreferStylusOverTouch_test.cpp
@@ -33,14 +33,8 @@
constexpr int32_t TOUCHSCREEN = AINPUT_SOURCE_TOUCHSCREEN;
constexpr int32_t STYLUS = AINPUT_SOURCE_STYLUS;
-struct PointerData {
- float x;
- float y;
-};
-
static NotifyMotionArgs generateMotionArgs(nsecs_t downTime, nsecs_t eventTime, int32_t action,
- const std::vector<PointerData>& points,
- uint32_t source) {
+ const std::vector<Point>& points, uint32_t source) {
size_t pointerCount = points.size();
if (action == DOWN || action == UP) {
EXPECT_EQ(1U, pointerCount) << "Actions DOWN and UP can only contain a single pointer";
diff --git a/services/surfaceflinger/ClientCache.cpp b/services/surfaceflinger/ClientCache.cpp
index cf932a8..b01932e 100644
--- a/services/surfaceflinger/ClientCache.cpp
+++ b/services/surfaceflinger/ClientCache.cpp
@@ -22,6 +22,7 @@
#include <cinttypes>
#include <android-base/stringprintf.h>
+#include <gui/TraceUtils.h>
#include <renderengine/impl/ExternalTexture.h>
#include "ClientCache.h"
@@ -36,12 +37,12 @@
ClientCacheBuffer** outClientCacheBuffer) {
auto& [processToken, id] = cacheId;
if (processToken == nullptr) {
- ALOGE("failed to get buffer, invalid (nullptr) process token");
+ ALOGE_AND_TRACE("ClientCache::getBuffer - invalid (nullptr) process token");
return false;
}
auto it = mBuffers.find(processToken);
if (it == mBuffers.end()) {
- ALOGE("failed to get buffer, invalid process token");
+ ALOGE_AND_TRACE("ClientCache::getBuffer - invalid process token");
return false;
}
@@ -49,7 +50,7 @@
auto bufItr = processBuffers.find(id);
if (bufItr == processBuffers.end()) {
- ALOGV("failed to get buffer, invalid buffer id");
+ ALOGE_AND_TRACE("ClientCache::getBuffer - invalid buffer id");
return false;
}
@@ -61,12 +62,12 @@
bool ClientCache::add(const client_cache_t& cacheId, const sp<GraphicBuffer>& buffer) {
auto& [processToken, id] = cacheId;
if (processToken == nullptr) {
- ALOGE("failed to cache buffer: invalid process token");
+ ALOGE_AND_TRACE("ClientCache::add - invalid (nullptr) process token");
return false;
}
if (!buffer) {
- ALOGE("failed to cache buffer: invalid buffer");
+ ALOGE_AND_TRACE("ClientCache::add - invalid (nullptr) buffer");
return false;
}
@@ -79,7 +80,7 @@
if (it == mBuffers.end()) {
token = processToken.promote();
if (!token) {
- ALOGE("failed to cache buffer: invalid token");
+ ALOGE_AND_TRACE("ClientCache::add - invalid token");
return false;
}
@@ -87,7 +88,7 @@
if (token->localBinder() == nullptr) {
status_t err = token->linkToDeath(mDeathRecipient);
if (err != NO_ERROR) {
- ALOGE("failed to cache buffer: could not link to death");
+ ALOGE_AND_TRACE("ClientCache::add - could not link to death");
return false;
}
}
@@ -102,7 +103,7 @@
auto& processBuffers = it->second.second;
if (processBuffers.size() > BUFFER_CACHE_MAX_SIZE) {
- ALOGE("failed to cache buffer: cache is full");
+ ALOGE_AND_TRACE("ClientCache::add - cache is full");
return false;
}
diff --git a/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp b/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp
index 79dcd15..3651231 100644
--- a/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp
+++ b/services/surfaceflinger/DisplayHardware/AidlComposerHal.cpp
@@ -264,17 +264,21 @@
}
std::string str;
+ // Use other thread to read pipe to prevent
+ // pipe is full, making HWC be blocked in writing.
+ std::thread t([&]() {
+ base::ReadFdToString(pipefds[0], &str);
+ });
const auto status = mAidlComposer->dump(pipefds[1], /*args*/ nullptr, /*numArgs*/ 0);
// Close the write-end of the pipe to make sure that when reading from the
// read-end we will get eof instead of blocking forever
close(pipefds[1]);
- if (status == STATUS_OK) {
- base::ReadFdToString(pipefds[0], &str);
- } else {
+ if (status != STATUS_OK) {
ALOGE("dumpDebugInfo: dump failed: %d", status);
}
+ t.join();
close(pipefds[0]);
return str;
}
diff --git a/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp b/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp
index c73a75c..cd1ba70 100644
--- a/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp
+++ b/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp
@@ -892,6 +892,10 @@
mJankType = JankType::Unknown;
deadlineDelta = 0;
deltaToVsync = 0;
+ if (mSurfaceFlingerActuals.presentTime == Fence::SIGNAL_TIME_INVALID) {
+ mSurfaceFlingerActuals.presentTime = mSurfaceFlingerActuals.endTime;
+ }
+
return;
}
@@ -1168,22 +1172,50 @@
static_cast<float>(totalPresentToPresentWalls);
}
+std::optional<size_t> FrameTimeline::getFirstSignalFenceIndex() const {
+ for (size_t i = 0; i < mPendingPresentFences.size(); i++) {
+ const auto& [fence, _] = mPendingPresentFences[i];
+ if (fence && fence->isValid() && fence->getSignalTime() != Fence::SIGNAL_TIME_PENDING) {
+ return i;
+ }
+ }
+
+ return {};
+}
+
void FrameTimeline::flushPendingPresentFences() {
+ const auto firstSignaledFence = getFirstSignalFenceIndex();
+ if (!firstSignaledFence.has_value()) {
+ return;
+ }
+
// Perfetto is using boottime clock to void drifts when the device goes
// to suspend.
const auto monoBootOffset = mUseBootTimeClock
? (systemTime(SYSTEM_TIME_BOOTTIME) - systemTime(SYSTEM_TIME_MONOTONIC))
: 0;
+ // Present fences are expected to be signaled in order. Mark all the previous
+ // pending fences as errors.
+ for (size_t i = 0; i < firstSignaledFence.value(); i++) {
+ const auto& pendingPresentFence = *mPendingPresentFences.begin();
+ const nsecs_t signalTime = Fence::SIGNAL_TIME_INVALID;
+ auto& displayFrame = pendingPresentFence.second;
+ displayFrame->onPresent(signalTime, mPreviousPresentTime);
+ displayFrame->trace(mSurfaceFlingerPid, monoBootOffset);
+ mPendingPresentFences.erase(mPendingPresentFences.begin());
+ }
+
for (size_t i = 0; i < mPendingPresentFences.size(); i++) {
const auto& pendingPresentFence = mPendingPresentFences[i];
nsecs_t signalTime = Fence::SIGNAL_TIME_INVALID;
if (pendingPresentFence.first && pendingPresentFence.first->isValid()) {
signalTime = pendingPresentFence.first->getSignalTime();
if (signalTime == Fence::SIGNAL_TIME_PENDING) {
- continue;
+ break;
}
}
+
auto& displayFrame = pendingPresentFence.second;
displayFrame->onPresent(signalTime, mPreviousPresentTime);
displayFrame->trace(mSurfaceFlingerPid, monoBootOffset);
diff --git a/services/surfaceflinger/FrameTimeline/FrameTimeline.h b/services/surfaceflinger/FrameTimeline/FrameTimeline.h
index a2305af..31074b1 100644
--- a/services/surfaceflinger/FrameTimeline/FrameTimeline.h
+++ b/services/surfaceflinger/FrameTimeline/FrameTimeline.h
@@ -474,6 +474,7 @@
friend class android::frametimeline::FrameTimelineTest;
void flushPendingPresentFences() REQUIRES(mMutex);
+ std::optional<size_t> getFirstSignalFenceIndex() const REQUIRES(mMutex);
void finalizeCurrentDisplayFrame() REQUIRES(mMutex);
void dumpAll(std::string& result);
void dumpJank(std::string& result);
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 410e438..9bb9305 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -3633,7 +3633,7 @@
}
if (s.what & layer_state_t::eAlphaChanged) {
- if (mDrawingState.color.a != s.alpha) {
+ if (mDrawingState.color.a != s.color.a) {
ALOGV("%s: false [eAlphaChanged changed]", __func__);
return false;
}
@@ -3677,9 +3677,9 @@
}
}
- if (s.what & layer_state_t::eTransformChanged) {
- if (mDrawingState.bufferTransform != s.transform) {
- ALOGV("%s: false [eTransformChanged changed]", __func__);
+ if (s.what & layer_state_t::eBufferTransformChanged) {
+ if (mDrawingState.bufferTransform != s.bufferTransform) {
+ ALOGV("%s: false [eBufferTransformChanged changed]", __func__);
return false;
}
}
@@ -4177,15 +4177,12 @@
}
bool Layer::setColor(const half3& color) {
- if (mDrawingState.color.r == color.r && mDrawingState.color.g == color.g &&
- mDrawingState.color.b == color.b) {
+ if (mDrawingState.color.rgb == color) {
return false;
}
mDrawingState.sequence++;
- mDrawingState.color.r = color.r;
- mDrawingState.color.g = color.g;
- mDrawingState.color.b = color.b;
+ mDrawingState.color.rgb = color;
mDrawingState.modified = true;
setTransactionFlags(eTransactionNeeded);
return true;
diff --git a/services/surfaceflinger/Scheduler/InjectVSyncSource.h b/services/surfaceflinger/Scheduler/InjectVSyncSource.h
deleted file mode 100644
index 760a4ee..0000000
--- a/services/surfaceflinger/Scheduler/InjectVSyncSource.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2018 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.
- */
-
-#pragma once
-
-#include <mutex>
-
-#include "EventThread.h"
-
-namespace android {
-
-/**
- * VSync signals used during SurfaceFlinger trace playback (traces we captured
- * with SurfaceInterceptor).
- */
-class InjectVSyncSource final : public VSyncSource {
-public:
- ~InjectVSyncSource() override = default;
-
- void setCallback(VSyncSource::Callback* callback) override {
- std::lock_guard<std::mutex> lock(mCallbackMutex);
- mCallback = callback;
- }
-
- void onInjectSyncEvent(nsecs_t when, nsecs_t expectedVSyncTimestamp,
- nsecs_t deadlineTimestamp) {
- std::lock_guard<std::mutex> lock(mCallbackMutex);
- if (mCallback) {
- mCallback->onVSyncEvent(when, {expectedVSyncTimestamp, deadlineTimestamp});
- }
- }
-
- const char* getName() const override { return "inject"; }
- void setVSyncEnabled(bool) override {}
- void setDuration(std::chrono::nanoseconds, std::chrono::nanoseconds) override {}
- VSyncData getLatestVSyncData() const override { return {}; }
- void dump(std::string&) const override {}
-
-private:
- std::mutex mCallbackMutex;
- VSyncSource::Callback* mCallback GUARDED_BY(mCallbackMutex) = nullptr;
-};
-
-} // namespace android
diff --git a/services/surfaceflinger/Scheduler/MessageQueue.cpp b/services/surfaceflinger/Scheduler/MessageQueue.cpp
index e4e65b4..ae10ff4 100644
--- a/services/surfaceflinger/Scheduler/MessageQueue.cpp
+++ b/services/surfaceflinger/Scheduler/MessageQueue.cpp
@@ -57,37 +57,6 @@
mLooper(sp<Looper>::make(kAllowNonCallbacks)),
mHandler(std::move(handler)) {}
-// TODO(b/169865816): refactor VSyncInjections to use MessageQueue directly
-// and remove the EventThread from MessageQueue
-void MessageQueue::setInjector(sp<EventThreadConnection> connection) {
- auto& tube = mInjector.tube;
-
- if (const int fd = tube.getFd(); fd >= 0) {
- mLooper->removeFd(fd);
- }
-
- if (connection) {
- // The EventThreadConnection is retained when disabling injection, so avoid subsequently
- // stealing invalid FDs. Note that the stolen FDs are kept open.
- if (tube.getFd() < 0) {
- connection->stealReceiveChannel(&tube);
- } else {
- ALOGW("Recycling channel for VSYNC injection.");
- }
-
- mLooper->addFd(
- tube.getFd(), 0, Looper::EVENT_INPUT,
- [](int, int, void* data) {
- reinterpret_cast<MessageQueue*>(data)->injectorCallback();
- return 1; // Keep registration.
- },
- this);
- }
-
- std::lock_guard lock(mInjector.mutex);
- mInjector.connection = std::move(connection);
-}
-
void MessageQueue::vsyncCallback(nsecs_t vsyncTime, nsecs_t targetWakeupTime, nsecs_t readyTime) {
ATRACE_CALL();
// Trace VSYNC-sf
@@ -174,15 +143,6 @@
void MessageQueue::scheduleFrame() {
ATRACE_CALL();
- {
- std::lock_guard lock(mInjector.mutex);
- if (CC_UNLIKELY(mInjector.connection)) {
- ALOGD("%s while injecting VSYNC", __func__);
- mInjector.connection->requestNextVsync();
- return;
- }
- }
-
std::lock_guard lock(mVsync.mutex);
mVsync.scheduledFrameTime =
mVsync.registration->schedule({.workDuration = mVsync.workDuration.get().count(),
@@ -190,22 +150,6 @@
.earliestVsync = mVsync.lastCallbackTime.ns()});
}
-void MessageQueue::injectorCallback() {
- ssize_t n;
- DisplayEventReceiver::Event buffer[8];
- while ((n = DisplayEventReceiver::getEvents(&mInjector.tube, buffer, 8)) > 0) {
- for (int i = 0; i < n; i++) {
- if (buffer[i].header.type == DisplayEventReceiver::DISPLAY_EVENT_VSYNC) {
- auto& vsync = buffer[i].vsync.vsyncData;
- mHandler->dispatchFrame(VsyncId{vsync.preferredVsyncId()},
- TimePoint::fromNs(
- vsync.preferredExpectedPresentationTime()));
- break;
- }
- }
- }
-}
-
auto MessageQueue::getScheduledFrameTime() const -> std::optional<Clock::time_point> {
if (mHandler->isFramePending()) {
return Clock::now();
diff --git a/services/surfaceflinger/Scheduler/MessageQueue.h b/services/surfaceflinger/Scheduler/MessageQueue.h
index 899233a..04de492 100644
--- a/services/surfaceflinger/Scheduler/MessageQueue.h
+++ b/services/surfaceflinger/Scheduler/MessageQueue.h
@@ -76,7 +76,6 @@
virtual void initVsync(scheduler::VSyncDispatch&, frametimeline::TokenManager&,
std::chrono::nanoseconds workDuration) = 0;
virtual void setDuration(std::chrono::nanoseconds workDuration) = 0;
- virtual void setInjector(sp<EventThreadConnection>) = 0;
virtual void waitMessage() = 0;
virtual void postMessage(sp<MessageHandler>&&) = 0;
virtual void scheduleConfigure() = 0;
@@ -132,16 +131,7 @@
TracedOrdinal<int> value = {"VSYNC-sf", 0};
};
- struct Injector {
- gui::BitTube tube;
- std::mutex mutex;
- sp<EventThreadConnection> connection GUARDED_BY(mutex);
- };
-
Vsync mVsync;
- Injector mInjector;
-
- void injectorCallback();
public:
explicit MessageQueue(ICompositor&);
@@ -149,7 +139,6 @@
void initVsync(scheduler::VSyncDispatch&, frametimeline::TokenManager&,
std::chrono::nanoseconds workDuration) override;
void setDuration(std::chrono::nanoseconds workDuration) override;
- void setInjector(sp<EventThreadConnection>) override;
void waitMessage() override;
void postMessage(sp<MessageHandler>&&) override;
diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp
index 72b6545..12949d6 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.cpp
+++ b/services/surfaceflinger/Scheduler/Scheduler.cpp
@@ -43,7 +43,6 @@
#include "DispSyncSource.h"
#include "EventThread.h"
#include "FrameRateOverrideMappings.h"
-#include "InjectVSyncSource.h"
#include "OneShotTimer.h"
#include "SurfaceFlingerProperties.h"
#include "VSyncPredictor.h"
@@ -403,43 +402,6 @@
thread->setDuration(workDuration, readyDuration);
}
-ConnectionHandle Scheduler::enableVSyncInjection(bool enable) {
- if (mInjectVSyncs == enable) {
- return {};
- }
-
- ALOGV("%s VSYNC injection", enable ? "Enabling" : "Disabling");
-
- if (!mInjectorConnectionHandle) {
- auto vsyncSource = std::make_unique<InjectVSyncSource>();
- mVSyncInjector = vsyncSource.get();
-
- auto eventThread =
- std::make_unique<impl::EventThread>(std::move(vsyncSource),
- /*tokenManager=*/nullptr,
- impl::EventThread::ThrottleVsyncCallback(),
- impl::EventThread::GetVsyncPeriodFunction());
-
- // EventThread does not dispatch VSYNC unless the display is connected and powered on.
- eventThread->onHotplugReceived(PhysicalDisplayId::fromPort(0), true);
- eventThread->onScreenAcquired();
-
- mInjectorConnectionHandle = createConnection(std::move(eventThread));
- }
-
- mInjectVSyncs = enable;
- return mInjectorConnectionHandle;
-}
-
-bool Scheduler::injectVSync(nsecs_t when, nsecs_t expectedVSyncTime, nsecs_t deadlineTimestamp) {
- if (!mInjectVSyncs || !mVSyncInjector) {
- return false;
- }
-
- mVSyncInjector->onInjectSyncEvent(when, expectedVSyncTime, deadlineTimestamp);
- return true;
-}
-
void Scheduler::enableHardwareVsync() {
std::lock_guard<std::mutex> lock(mHWVsyncLock);
if (!mPrimaryHWVsyncEnabled && mHWVsyncAvailable) {
@@ -764,28 +726,30 @@
std::vector<RefreshRateRankingsAndSignals> refreshRateRankingsAndSignalsPerDisplay;
refreshRateRankingsAndSignalsPerDisplay.reserve(mDisplays.size());
- const auto displayModeSelectionParams = getDisplayModeSelectionParams();
+ for (const auto& [id, display] : mDisplays) {
+ const auto [rankings, signals] =
+ display->holdRefreshRateConfigs()
+ ->getRankedRefreshRates(mPolicy.contentRequirements, makeGlobalSignals());
- std::for_each(mDisplays.begin(), mDisplays.end(), [&](const auto& display) {
- const auto& [refreshRateRankings, globalSignals] =
- display.second->holdRefreshRateConfigs()
- ->getRankedRefreshRates(displayModeSelectionParams.layerRequirements,
- displayModeSelectionParams.globalSignals);
refreshRateRankingsAndSignalsPerDisplay.emplace_back(
- RefreshRateRankingsAndSignals{refreshRateRankings, globalSignals});
- });
+ RefreshRateRankingsAndSignals{rankings, signals});
+ }
// FPS and their Aggregated score.
std::unordered_map<Fps, AggregatedFpsScore, FpsHash, FpsApproxEqual> aggregatedScoresPerFps =
getAggregatedScoresPerFps(refreshRateRankingsAndSignalsPerDisplay);
- Fps chosenFps = std::max_element(aggregatedScoresPerFps.begin(), aggregatedScoresPerFps.end(),
- [](const auto& max, const auto& current) {
- return max.second.totalScore <= current.second.totalScore;
- })
- ->first;
-
- return getDisplayModeConfigsForTheChosenFps(chosenFps, refreshRateRankingsAndSignalsPerDisplay);
+ auto maxScoreIt = aggregatedScoresPerFps.cbegin();
+ // Selects the max Fps that is present on all the displays.
+ for (auto it = aggregatedScoresPerFps.cbegin(); it != aggregatedScoresPerFps.cend(); ++it) {
+ const auto [fps, aggregatedScore] = *it;
+ if (aggregatedScore.numDisplays == mDisplays.size() &&
+ aggregatedScore.totalScore >= maxScoreIt->second.totalScore) {
+ maxScoreIt = it;
+ }
+ }
+ return getDisplayModeConfigsForTheChosenFps(maxScoreIt->first,
+ refreshRateRankingsAndSignalsPerDisplay);
}
std::vector<DisplayModeConfig> Scheduler::getDisplayModeConfigsForTheChosenFps(
@@ -810,34 +774,26 @@
return displayModeConfigs;
}
-DisplayModeSelectionParams Scheduler::getDisplayModeSelectionParams() const {
+GlobalSignals Scheduler::makeGlobalSignals() const {
const bool powerOnImminent = mDisplayPowerTimer &&
(mPolicy.displayPowerMode != hal::PowerMode::ON ||
mPolicy.displayPowerTimer == TimerState::Reset);
- const GlobalSignals signals{.touch = mTouchTimer && mPolicy.touch == TouchState::Active,
- .idle = mPolicy.idleTimer == TimerState::Expired,
- .powerOnImminent = powerOnImminent};
-
- return {mPolicy.contentRequirements, signals};
-}
-
-auto Scheduler::getRankedDisplayModes()
- -> std::pair<std::vector<RefreshRateRanking>, GlobalSignals> {
- ATRACE_CALL();
-
- const auto configs = holdRefreshRateConfigs();
-
- const auto displayModeSelectionParams = getDisplayModeSelectionParams();
- return configs->getRankedRefreshRates(displayModeSelectionParams.layerRequirements,
- displayModeSelectionParams.globalSignals);
+ return {.touch = mTouchTimer && mPolicy.touch == TouchState::Active,
+ .idle = mPolicy.idleTimer == TimerState::Expired,
+ .powerOnImminent = powerOnImminent};
}
DisplayModePtr Scheduler::getPreferredDisplayMode() {
std::lock_guard<std::mutex> lock(mPolicyLock);
// Make sure the stored mode is up to date.
if (mPolicy.mode) {
- mPolicy.mode = getRankedDisplayModes().first.front().displayModePtr;
+ const auto configs = holdRefreshRateConfigs();
+ const auto rankings =
+ configs->getRankedRefreshRates(mPolicy.contentRequirements, makeGlobalSignals())
+ .first;
+
+ mPolicy.mode = rankings.front().displayModePtr;
}
return mPolicy.mode;
}
diff --git a/services/surfaceflinger/Scheduler/Scheduler.h b/services/surfaceflinger/Scheduler/Scheduler.h
index 4c49562..25fa714 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.h
+++ b/services/surfaceflinger/Scheduler/Scheduler.h
@@ -78,7 +78,6 @@
namespace android {
class FenceTime;
-class InjectVSyncSource;
namespace frametimeline {
class TokenManager;
@@ -116,12 +115,6 @@
size_t numDisplays;
};
-// Represents LayerRequirements and GlobalSignals to be considered for the display mode selection.
-struct DisplayModeSelectionParams {
- std::vector<RefreshRateConfigs::LayerRequirement> layerRequirements;
- GlobalSignals globalSignals;
-};
-
// Represents the RefreshRateRankings and GlobalSignals for the selected RefreshRateRankings.
struct RefreshRateRankingsAndSignals {
std::vector<RefreshRateRanking> refreshRateRankings;
@@ -144,7 +137,6 @@
void createVsyncSchedule(FeatureFlags);
using Impl::initVsync;
- using Impl::setInjector;
using Impl::getScheduledFrameTime;
using Impl::setDuration;
@@ -182,10 +174,6 @@
void setDuration(ConnectionHandle, std::chrono::nanoseconds workDuration,
std::chrono::nanoseconds readyDuration);
- // Returns injector handle if injection has toggled, or an invalid handle otherwise.
- ConnectionHandle enableVSyncInjection(bool enable);
- // Returns false if injection is disabled.
- bool injectVSync(nsecs_t when, nsecs_t expectedVSyncTime, nsecs_t deadlineTimestamp);
void enableHardwareVsync();
void disableHardwareVsync(bool makeUnavailable);
@@ -302,11 +290,6 @@
template <typename S, typename T>
GlobalSignals applyPolicy(S Policy::*, T&&) EXCLUDES(mPolicyLock);
- // Returns the list of display modes in descending order of their priority that fulfills the
- // policy, and the signals that were considered.
- std::pair<std::vector<RefreshRateRanking>, GlobalSignals> getRankedDisplayModes()
- REQUIRES(mPolicyLock);
-
// Returns the best display mode per display.
std::vector<DisplayModeConfig> getBestDisplayModeConfigs() const REQUIRES(mPolicyLock);
@@ -314,9 +297,7 @@
std::vector<DisplayModeConfig> getDisplayModeConfigsForTheChosenFps(
Fps chosenFps, const std::vector<RefreshRateRankingsAndSignals>&) const;
- // Returns the DisplayModeSelectionParams to be considered for the
- // DisplayMode selection based on the current Policy and GlobalSignals.
- DisplayModeSelectionParams getDisplayModeSelectionParams() const REQUIRES(mPolicyLock);
+ GlobalSignals makeGlobalSignals() const REQUIRES(mPolicyLock);
bool updateFrameRateOverrides(GlobalSignals, Fps displayRefreshRate) REQUIRES(mPolicyLock);
@@ -342,10 +323,6 @@
mutable std::mutex mConnectionsLock;
std::unordered_map<ConnectionHandle, Connection> mConnections GUARDED_BY(mConnectionsLock);
- bool mInjectVSyncs = false;
- InjectVSyncSource* mVSyncInjector = nullptr;
- ConnectionHandle mInjectorConnectionHandle;
-
mutable std::mutex mHWVsyncLock;
bool mPrimaryHWVsyncEnabled GUARDED_BY(mHWVsyncLock) = false;
bool mHWVsyncAvailable GUARDED_BY(mHWVsyncLock) = false;
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 5466497..e4fee1c 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -1542,27 +1542,6 @@
return NO_ERROR;
}
-status_t SurfaceFlinger::enableVSyncInjections(bool enable) {
- auto future = mScheduler->schedule([=] {
- Mutex::Autolock lock(mStateLock);
-
- if (const auto handle = mScheduler->enableVSyncInjection(enable)) {
- mScheduler->setInjector(enable ? mScheduler->getEventConnection(handle) : nullptr);
- }
- });
-
- future.wait();
- return NO_ERROR;
-}
-
-status_t SurfaceFlinger::injectVSync(nsecs_t when) {
- Mutex::Autolock lock(mStateLock);
- const nsecs_t expectedPresentTime = calculateExpectedPresentTime(TimePoint::fromNs(when)).ns();
- const nsecs_t deadlineTimestamp = expectedPresentTime;
- return mScheduler->injectVSync(when, expectedPresentTime, deadlineTimestamp) ? NO_ERROR
- : BAD_VALUE;
-}
-
status_t SurfaceFlinger::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) {
outLayers->clear();
auto future = mScheduler->schedule([=] {
@@ -4152,12 +4131,10 @@
}
}
if (what & layer_state_t::eAlphaChanged) {
- if (layer->setAlpha(s.alpha))
- flags |= eTraversalNeeded;
+ if (layer->setAlpha(s.color.a)) flags |= eTraversalNeeded;
}
if (what & layer_state_t::eColorChanged) {
- if (layer->setColor(s.color))
- flags |= eTraversalNeeded;
+ if (layer->setColor(s.color.rgb)) flags |= eTraversalNeeded;
}
if (what & layer_state_t::eColorTransformChanged) {
if (layer->setColorTransform(s.colorTransform)) {
@@ -4165,7 +4142,7 @@
}
}
if (what & layer_state_t::eBackgroundColorChanged) {
- if (layer->setBackgroundColor(s.color, s.bgColorAlpha, s.bgColorDataspace)) {
+ if (layer->setBackgroundColor(s.color.rgb, s.bgColorAlpha, s.bgColorDataspace)) {
flags |= eTraversalNeeded;
}
}
@@ -4214,8 +4191,8 @@
flags |= eTransactionNeeded | eTraversalNeeded | eTransformHintUpdateNeeded;
}
}
- if (what & layer_state_t::eTransformChanged) {
- if (layer->setTransform(s.transform)) flags |= eTraversalNeeded;
+ if (what & layer_state_t::eBufferTransformChanged) {
+ if (layer->setTransform(s.bufferTransform)) flags |= eTraversalNeeded;
}
if (what & layer_state_t::eTransformToDisplayInverseChanged) {
if (layer->setTransformToDisplayInverse(s.transformToDisplayInverse))
@@ -7375,30 +7352,6 @@
return binderStatusFromStatusT(status);
}
-binder::Status SurfaceComposerAIDL::enableVSyncInjections(bool enable) {
- if (!mFlinger->hasMockHwc()) {
- return binderStatusFromStatusT(PERMISSION_DENIED);
- }
-
- status_t status = checkAccessPermission();
- if (status == OK) {
- status = mFlinger->enableVSyncInjections(enable);
- }
- return binderStatusFromStatusT(status);
-}
-
-binder::Status SurfaceComposerAIDL::injectVSync(int64_t when) {
- if (!mFlinger->hasMockHwc()) {
- return binderStatusFromStatusT(PERMISSION_DENIED);
- }
-
- status_t status = checkAccessPermission();
- if (status == OK) {
- status = mFlinger->injectVSync(when);
- }
- return binderStatusFromStatusT(status);
-}
-
binder::Status SurfaceComposerAIDL::getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) {
if (!outLayers) {
return binderStatusFromStatusT(UNEXPECTED_NULL);
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 1bc45d9..c4c5b56 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -530,8 +530,6 @@
status_t overrideHdrTypes(const sp<IBinder>& displayToken,
const std::vector<ui::Hdr>& hdrTypes);
status_t onPullAtom(const int32_t atomId, std::string* pulledData, bool* success);
- status_t enableVSyncInjections(bool enable);
- status_t injectVSync(nsecs_t when);
status_t getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers);
status_t getColorManagement(bool* outGetColorManagement) const;
status_t getCompositionPreference(ui::Dataspace* outDataspace, ui::PixelFormat* outPixelFormat,
@@ -1262,8 +1260,6 @@
const std::string mHwcServiceName;
- bool hasMockHwc() const { return mHwcServiceName == "mock"; }
-
/*
* Scheduler
*/
@@ -1433,8 +1429,6 @@
binder::Status overrideHdrTypes(const sp<IBinder>& display,
const std::vector<int32_t>& hdrTypes) override;
binder::Status onPullAtom(int32_t atomId, gui::PullAtomData* outPullData) override;
- binder::Status enableVSyncInjections(bool enable) override;
- binder::Status injectVSync(int64_t when) override;
binder::Status getLayerDebugInfo(std::vector<gui::LayerDebugInfo>* outLayers) override;
binder::Status getColorManagement(bool* outGetColorManagement) override;
binder::Status getCompositionPreference(gui::CompositionPreference* outPref) override;
diff --git a/services/surfaceflinger/Tracing/TransactionProtoParser.cpp b/services/surfaceflinger/Tracing/TransactionProtoParser.cpp
index 267f3d0..3418c82 100644
--- a/services/surfaceflinger/Tracing/TransactionProtoParser.cpp
+++ b/services/surfaceflinger/Tracing/TransactionProtoParser.cpp
@@ -111,7 +111,7 @@
}
if (layer.what & layer_state_t::eAlphaChanged) {
- proto.set_alpha(layer.alpha);
+ proto.set_alpha(layer.color.a);
}
if (layer.what & layer_state_t::eColorChanged) {
@@ -123,8 +123,8 @@
if (layer.what & layer_state_t::eTransparentRegionChanged) {
LayerProtoHelper::writeToProto(layer.transparentRegion, proto.mutable_transparent_region());
}
- if (layer.what & layer_state_t::eTransformChanged) {
- proto.set_transform(layer.transform);
+ if (layer.what & layer_state_t::eBufferTransformChanged) {
+ proto.set_transform(layer.bufferTransform);
}
if (layer.what & layer_state_t::eTransformToDisplayInverseChanged) {
proto.set_transform_to_display_inverse(layer.transformToDisplayInverse);
@@ -395,7 +395,7 @@
}
if (proto.what() & layer_state_t::eAlphaChanged) {
- layer.alpha = proto.alpha();
+ layer.color.a = proto.alpha();
}
if (proto.what() & layer_state_t::eColorChanged) {
@@ -407,8 +407,8 @@
if (proto.what() & layer_state_t::eTransparentRegionChanged) {
LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion);
}
- if (proto.what() & layer_state_t::eTransformChanged) {
- layer.transform = proto.transform();
+ if (proto.what() & layer_state_t::eBufferTransformChanged) {
+ layer.bufferTransform = proto.transform();
}
if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) {
layer.transformToDisplayInverse = proto.transform_to_display_inverse();
diff --git a/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h b/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h
index 03630c9..ed2fe23 100644
--- a/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h
+++ b/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h
@@ -576,8 +576,6 @@
onPullAtom(&mFdp);
- mFlinger->injectVSync(mFdp.ConsumeIntegral<nsecs_t>());
-
getCompositionPreference();
getDisplayedContentSample(display, &mFdp);
getDesiredDisplayModeSpecs(display);
diff --git a/services/surfaceflinger/layerproto/transactions.proto b/services/surfaceflinger/layerproto/transactions.proto
index b687abc..4c6a9cf 100644
--- a/services/surfaceflinger/layerproto/transactions.proto
+++ b/services/surfaceflinger/layerproto/transactions.proto
@@ -98,8 +98,7 @@
eReparent = 0x00008000;
eColorChanged = 0x00010000;
- eDestroySurface = 0x00020000;
- eTransformChanged = 0x00040000;
+ eBufferTransformChanged = 0x00040000;
eTransformToDisplayInverseChanged = 0x00080000;
eCropChanged = 0x00100000;
diff --git a/services/surfaceflinger/tests/Android.bp b/services/surfaceflinger/tests/Android.bp
index 71b1c0e..bd6367d 100644
--- a/services/surfaceflinger/tests/Android.bp
+++ b/services/surfaceflinger/tests/Android.bp
@@ -126,7 +126,6 @@
}
subdirs = [
- "fakehwc",
"hwc2",
"unittests",
"utils",
diff --git a/services/surfaceflinger/tests/fakehwc/Android.bp b/services/surfaceflinger/tests/fakehwc/Android.bp
deleted file mode 100644
index 0d40e70..0000000
--- a/services/surfaceflinger/tests/fakehwc/Android.bp
+++ /dev/null
@@ -1,64 +0,0 @@
-package {
- // See: http://go/android-license-faq
- // A large-scale-change added 'default_applicable_licenses' to import
- // all of the 'license_kinds' from "frameworks_native_license"
- // to get the below license kinds:
- // SPDX-license-identifier-Apache-2.0
- default_applicable_licenses: ["frameworks_native_license"],
-}
-
-cc_test {
- name: "sffakehwc_test",
- defaults: [
- "android.hardware.graphics.composer3-ndk_shared",
- "surfaceflinger_defaults",
- ],
- test_suites: ["device-tests"],
- srcs: [
- "FakeComposerClient.cpp",
- "FakeComposerService.cpp",
- "FakeComposerUtils.cpp",
- "SFFakeHwc_test.cpp",
- ],
- require_root: true,
- shared_libs: [
- "android.hardware.graphics.composer@2.1",
- "android.hardware.graphics.composer@2.2",
- "android.hardware.graphics.composer@2.3",
- "android.hardware.graphics.composer@2.4",
- "android.hardware.graphics.mapper@2.0",
- "android.hardware.graphics.mapper@3.0",
- "android.hardware.graphics.mapper@4.0",
- "android.hardware.power@1.3",
- "android.hardware.power-V2-cpp",
- "libbase",
- "libbinder",
- "libbinder_ndk",
- "libcutils",
- "libfmq",
- "libgui",
- "libhidlbase",
- "liblayers_proto",
- "liblog",
- "libnativewindow",
- "libsync",
- "libtimestats",
- "libui",
- "libutils",
- ],
- static_libs: [
- "android.hardware.graphics.composer@2.1-resources",
- "libaidlcommonsupport",
- "libcompositionengine",
- "libgmock",
- "libperfetto_client_experimental",
- "librenderengine",
- "libaidlcommonsupport",
- ],
- header_libs: [
- "android.hardware.graphics.composer@2.4-command-buffer",
- "android.hardware.graphics.composer@2.4-hal",
- "android.hardware.graphics.composer3-command-buffer",
- "libsurfaceflinger_headers",
- ],
-}
diff --git a/services/surfaceflinger/tests/fakehwc/FakeComposerClient.cpp b/services/surfaceflinger/tests/fakehwc/FakeComposerClient.cpp
deleted file mode 100644
index a5cca35..0000000
--- a/services/surfaceflinger/tests/fakehwc/FakeComposerClient.cpp
+++ /dev/null
@@ -1,929 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-// TODO(b/129481165): remove the #pragma below and fix conversion issues
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wconversion"
-
-//#define LOG_NDEBUG 0
-#undef LOG_TAG
-#define LOG_TAG "FakeComposer"
-
-#include "FakeComposerClient.h"
-
-#include <gui/SurfaceComposerClient.h>
-
-#include <log/log.h>
-
-#include <gtest/gtest.h>
-
-#include <inttypes.h>
-#include <time.h>
-#include <algorithm>
-#include <condition_variable>
-#include <iostream>
-#include <mutex>
-#include <set>
-#include <thread>
-
-constexpr Config NULL_DISPLAY_CONFIG = static_cast<Config>(0);
-
-using namespace sftest;
-
-using android::Condition;
-using android::Mutex;
-
-using Clock = std::chrono::steady_clock;
-using TimePoint = std::chrono::time_point<Clock>;
-
-namespace {
-
-// Internal state of a layer in the HWC API.
-class LayerImpl {
-public:
- LayerImpl() = default;
-
- bool mValid = true;
- RenderState mRenderState;
- uint32_t mZ = 0;
-};
-
-// Struct for storing per frame rectangle state. Contains the render
-// state shared to the test case. Basically a snapshot and a subset of
-// LayerImpl sufficient to re-create the pixels of a layer for the
-// frame.
-struct FrameRect {
-public:
- FrameRect(Layer layer_, const RenderState& state, uint32_t z_)
- : layer(layer_), renderState(state), z(z_) {}
-
- const Layer layer;
- const RenderState renderState;
- const uint32_t z;
-};
-
-// Collection of FrameRects forming one rendered frame. Could store
-// related fences and other data in the future.
-class Frame {
-public:
- Frame() = default;
- std::vector<std::unique_ptr<FrameRect>> rectangles;
-};
-
-class DelayedEventGenerator {
-public:
- explicit DelayedEventGenerator(std::function<void()> onTimerExpired)
- : mOnTimerExpired(onTimerExpired) {
- mThread = std::thread([this]() { loop(); });
- }
-
- ~DelayedEventGenerator() {
- ALOGI("DelayedEventGenerator exiting.");
- {
- std::unique_lock<std::mutex> lock(mMutex);
- mRunning = false;
- mWakeups.clear();
- mCondition.notify_one();
- }
- mThread.join();
- ALOGI("DelayedEventGenerator exited.");
- }
-
- void wakeAfter(std::chrono::nanoseconds waitTime) {
- std::unique_lock<std::mutex> lock(mMutex);
- mWakeups.insert(Clock::now() + waitTime);
- mCondition.notify_one();
- }
-
-private:
- void loop() {
- while (true) {
- // Lock scope
- {
- std::unique_lock<std::mutex> lock(mMutex);
- mCondition.wait(lock, [this]() { return !mRunning || !mWakeups.empty(); });
- if (!mRunning && mWakeups.empty()) {
- // This thread should only exit once the destructor has been called and all
- // wakeups have been processed
- return;
- }
-
- // At this point, mWakeups will not be empty
-
- TimePoint target = *(mWakeups.begin());
- auto status = mCondition.wait_until(lock, target);
- while (status == std::cv_status::no_timeout) {
- // This was either a spurious wakeup or another wakeup was added, so grab the
- // oldest point and wait again
- target = *(mWakeups.begin());
- status = mCondition.wait_until(lock, target);
- }
-
- // status must have been timeout, so we can finally clear this point
- mWakeups.erase(target);
- }
- // Callback *without* locks!
- mOnTimerExpired();
- }
- }
-
- std::function<void()> mOnTimerExpired;
- std::thread mThread;
- std::mutex mMutex;
- std::condition_variable mCondition;
- bool mRunning = true;
- std::set<TimePoint> mWakeups;
-};
-
-} // namespace
-
-FakeComposerClient::FakeComposerClient()
- : mEventCallback(nullptr),
- mEventCallback_2_4(nullptr),
- mCurrentConfig(NULL_DISPLAY_CONFIG),
- mVsyncEnabled(false),
- mLayers(),
- mDelayedEventGenerator(
- std::make_unique<DelayedEventGenerator>([this]() { this->requestVSync(); })),
- mSurfaceComposer(nullptr) {}
-
-FakeComposerClient::~FakeComposerClient() {}
-
-bool FakeComposerClient::hasCapability(hwc2_capability_t /*capability*/) {
- return false;
-}
-
-std::string FakeComposerClient::dumpDebugInfo() {
- return {};
-}
-
-void FakeComposerClient::registerEventCallback(EventCallback* callback) {
- ALOGV("registerEventCallback");
- LOG_FATAL_IF(mEventCallback_2_4 != nullptr,
- "already registered using registerEventCallback_2_4");
-
- mEventCallback = callback;
- if (mEventCallback) {
- mEventCallback->onHotplug(PRIMARY_DISPLAY, IComposerCallback::Connection::CONNECTED);
- }
-}
-
-void FakeComposerClient::unregisterEventCallback() {
- ALOGV("unregisterEventCallback");
- mEventCallback = nullptr;
-}
-
-void FakeComposerClient::hotplugDisplay(Display display, IComposerCallback::Connection state) {
- if (mEventCallback) {
- mEventCallback->onHotplug(display, state);
- } else if (mEventCallback_2_4) {
- mEventCallback_2_4->onHotplug(display, state);
- }
-}
-
-void FakeComposerClient::refreshDisplay(Display display) {
- if (mEventCallback) {
- mEventCallback->onRefresh(display);
- } else if (mEventCallback_2_4) {
- mEventCallback_2_4->onRefresh(display);
- }
-}
-
-uint32_t FakeComposerClient::getMaxVirtualDisplayCount() {
- ALOGV("getMaxVirtualDisplayCount");
- return 1;
-}
-
-V2_1::Error FakeComposerClient::createVirtualDisplay(uint32_t /*width*/, uint32_t /*height*/,
- V1_0::PixelFormat* /*format*/,
- Display* /*outDisplay*/) {
- ALOGV("createVirtualDisplay");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::destroyVirtualDisplay(Display /*display*/) {
- ALOGV("destroyVirtualDisplay");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::createLayer(Display /*display*/, Layer* outLayer) {
- ALOGV("createLayer");
- *outLayer = mLayers.size();
- auto newLayer = std::make_unique<LayerImpl>();
- mLayers.push_back(std::move(newLayer));
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::destroyLayer(Display /*display*/, Layer layer) {
- ALOGV("destroyLayer");
- mLayers[layer]->mValid = false;
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::getActiveConfig(Display display, Config* outConfig) {
- ALOGV("getActiveConfig");
- if (mMockHal) {
- return mMockHal->getActiveConfig(display, outConfig);
- }
-
- // TODO Assert outConfig != nullptr
-
- // TODO This is my reading of the
- // IComposerClient::getActiveConfig, but returning BAD_CONFIG
- // seems to not fit SurfaceFlinger plans. See version 2 below.
- // if (mCurrentConfig == NULL_DISPLAY_CONFIG) {
- // return V2_1::Error::BAD_CONFIG;
- // }
- //*outConfig = mCurrentConfig;
- *outConfig = 1; // Very special config for you my friend
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::getClientTargetSupport(Display /*display*/, uint32_t /*width*/,
- uint32_t /*height*/,
- V1_0::PixelFormat /*format*/,
- V1_0::Dataspace /*dataspace*/) {
- ALOGV("getClientTargetSupport");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::getColorModes(Display /*display*/,
- hidl_vec<V1_0::ColorMode>* /*outModes*/) {
- ALOGV("getColorModes");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::getDisplayAttribute(Display display, Config config,
- V2_1::IComposerClient::Attribute attribute,
- int32_t* outValue) {
- auto tmpError =
- getDisplayAttribute_2_4(display, config,
- static_cast<IComposerClient::Attribute>(attribute), outValue);
- return static_cast<V2_1::Error>(tmpError);
-}
-
-V2_1::Error FakeComposerClient::getDisplayConfigs(Display display, hidl_vec<Config>* outConfigs) {
- ALOGV("getDisplayConfigs");
- if (mMockHal) {
- return mMockHal->getDisplayConfigs(display, outConfigs);
- }
-
- // TODO assert display == 1, outConfigs != nullptr
-
- outConfigs->resize(1);
- (*outConfigs)[0] = 1;
-
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::getDisplayName(Display /*display*/, hidl_string* /*outName*/) {
- ALOGV("getDisplayName");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::getDisplayType(Display /*display*/,
- IComposerClient::DisplayType* outType) {
- ALOGV("getDisplayType");
- // TODO: This setting nothing on the output had no effect on initial trials. Is first display
- // assumed to be physical?
- *outType = static_cast<IComposerClient::DisplayType>(HWC2_DISPLAY_TYPE_PHYSICAL);
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::getDozeSupport(Display /*display*/, bool* /*outSupport*/) {
- ALOGV("getDozeSupport");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::getHdrCapabilities(Display /*display*/,
- hidl_vec<V1_0::Hdr>* /*outTypes*/,
- float* /*outMaxLuminance*/,
- float* /*outMaxAverageLuminance*/,
- float* /*outMinLuminance*/) {
- ALOGV("getHdrCapabilities");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setActiveConfig(Display display, Config config) {
- ALOGV("setActiveConfig");
- if (mMockHal) {
- return mMockHal->setActiveConfig(display, config);
- }
- mCurrentConfig = config;
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setColorMode(Display /*display*/, V1_0::ColorMode /*mode*/) {
- ALOGV("setColorMode");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setPowerMode(Display /*display*/,
- V2_1::IComposerClient::PowerMode /*mode*/) {
- ALOGV("setPowerMode");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setVsyncEnabled(Display /*display*/,
- IComposerClient::Vsync enabled) {
- mVsyncEnabled = (enabled == IComposerClient::Vsync::ENABLE);
- ALOGV("setVsyncEnabled(%s)", mVsyncEnabled ? "ENABLE" : "DISABLE");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setColorTransform(Display /*display*/, const float* /*matrix*/,
- int32_t /*hint*/) {
- ALOGV("setColorTransform");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setClientTarget(Display /*display*/, buffer_handle_t /*target*/,
- int32_t /*acquireFence*/, int32_t /*dataspace*/,
- const std::vector<hwc_rect_t>& /*damage*/) {
- ALOGV("setClientTarget");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setOutputBuffer(Display /*display*/, buffer_handle_t /*buffer*/,
- int32_t /*releaseFence*/) {
- ALOGV("setOutputBuffer");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::validateDisplay(
- Display /*display*/, std::vector<Layer>* /*outChangedLayers*/,
- std::vector<IComposerClient::Composition>* /*outCompositionTypes*/,
- uint32_t* /*outDisplayRequestMask*/, std::vector<Layer>* /*outRequestedLayers*/,
- std::vector<uint32_t>* /*outRequestMasks*/) {
- ALOGV("validateDisplay");
- // TODO: Assume touching nothing means All Korrekt!
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::acceptDisplayChanges(Display /*display*/) {
- ALOGV("acceptDisplayChanges");
- // Didn't ask for changes because software is omnipotent.
- return V2_1::Error::NONE;
-}
-
-bool layerZOrdering(const std::unique_ptr<FrameRect>& a, const std::unique_ptr<FrameRect>& b) {
- return a->z <= b->z;
-}
-
-V2_1::Error FakeComposerClient::presentDisplay(Display /*display*/, int32_t* /*outPresentFence*/,
- std::vector<Layer>* /*outLayers*/,
- std::vector<int32_t>* /*outReleaseFences*/) {
- ALOGV("presentDisplay");
- // TODO Leaving layers and their fences out for now. Doing so
- // means that we've already processed everything. Important to
- // test that the fences are respected, though. (How?)
-
- std::unique_ptr<Frame> newFrame(new Frame);
- for (uint64_t layer = 0; layer < mLayers.size(); layer++) {
- const LayerImpl& layerImpl = *mLayers[layer];
-
- if (!layerImpl.mValid) continue;
-
- auto rect = std::make_unique<FrameRect>(layer, layerImpl.mRenderState, layerImpl.mZ);
- newFrame->rectangles.push_back(std::move(rect));
- }
- std::sort(newFrame->rectangles.begin(), newFrame->rectangles.end(), layerZOrdering);
- {
- Mutex::Autolock _l(mStateMutex);
- mFrames.push_back(std::move(newFrame));
- mFramesAvailable.broadcast();
- }
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setLayerCursorPosition(Display /*display*/, Layer /*layer*/,
- int32_t /*x*/, int32_t /*y*/) {
- ALOGV("setLayerCursorPosition");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setLayerBuffer(Display /*display*/, Layer layer,
- buffer_handle_t buffer, int32_t acquireFence) {
- ALOGV("setLayerBuffer");
- LayerImpl& l = getLayerImpl(layer);
- if (buffer != l.mRenderState.mBuffer) {
- l.mRenderState.mSwapCount++; // TODO: Is setting to same value a swap or not?
- }
- l.mRenderState.mBuffer = buffer;
- l.mRenderState.mAcquireFence = acquireFence;
-
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setLayerSurfaceDamage(Display /*display*/, Layer /*layer*/,
- const std::vector<hwc_rect_t>& /*damage*/) {
- ALOGV("setLayerSurfaceDamage");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setLayerBlendMode(Display /*display*/, Layer layer, int32_t mode) {
- ALOGV("setLayerBlendMode");
- getLayerImpl(layer).mRenderState.mBlendMode = static_cast<hwc2_blend_mode_t>(mode);
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setLayerColor(Display /*display*/, Layer layer,
- IComposerClient::Color color) {
- ALOGV("setLayerColor");
- getLayerImpl(layer).mRenderState.mLayerColor.r = color.r;
- getLayerImpl(layer).mRenderState.mLayerColor.g = color.g;
- getLayerImpl(layer).mRenderState.mLayerColor.b = color.b;
- getLayerImpl(layer).mRenderState.mLayerColor.a = color.a;
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setLayerCompositionType(Display /*display*/, Layer /*layer*/,
- int32_t /*type*/) {
- ALOGV("setLayerCompositionType");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setLayerDataspace(Display /*display*/, Layer /*layer*/,
- int32_t /*dataspace*/) {
- ALOGV("setLayerDataspace");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setLayerDisplayFrame(Display /*display*/, Layer layer,
- const hwc_rect_t& frame) {
- ALOGV("setLayerDisplayFrame (%d, %d, %d, %d)", frame.left, frame.top, frame.right,
- frame.bottom);
- getLayerImpl(layer).mRenderState.mDisplayFrame = frame;
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setLayerPlaneAlpha(Display /*display*/, Layer layer, float alpha) {
- ALOGV("setLayerPlaneAlpha");
- getLayerImpl(layer).mRenderState.mPlaneAlpha = alpha;
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setLayerSidebandStream(Display /*display*/, Layer /*layer*/,
- buffer_handle_t /*stream*/) {
- ALOGV("setLayerSidebandStream");
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setLayerSourceCrop(Display /*display*/, Layer layer,
- const hwc_frect_t& crop) {
- ALOGV("setLayerSourceCrop");
- getLayerImpl(layer).mRenderState.mSourceCrop = crop;
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setLayerTransform(Display /*display*/, Layer layer,
- int32_t transform) {
- ALOGV("setLayerTransform");
- getLayerImpl(layer).mRenderState.mTransform = static_cast<hwc_transform_t>(transform);
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setLayerVisibleRegion(Display /*display*/, Layer layer,
- const std::vector<hwc_rect_t>& visible) {
- ALOGV("setLayerVisibleRegion");
- getLayerImpl(layer).mRenderState.mVisibleRegion = visible;
- return V2_1::Error::NONE;
-}
-
-V2_1::Error FakeComposerClient::setLayerZOrder(Display /*display*/, Layer layer, uint32_t z) {
- ALOGV("setLayerZOrder");
- getLayerImpl(layer).mZ = z;
- return V2_1::Error::NONE;
-}
-
-// Composer 2.2
-V2_1::Error FakeComposerClient::getPerFrameMetadataKeys(
- Display /*display*/, std::vector<V2_2::IComposerClient::PerFrameMetadataKey>* /*outKeys*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::setLayerPerFrameMetadata(
- Display /*display*/, Layer /*layer*/,
- const std::vector<V2_2::IComposerClient::PerFrameMetadata>& /*metadata*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::getReadbackBufferAttributes(
- Display /*display*/, graphics::common::V1_1::PixelFormat* /*outFormat*/,
- graphics::common::V1_1::Dataspace* /*outDataspace*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::setReadbackBuffer(Display /*display*/,
- const native_handle_t* /*bufferHandle*/,
- android::base::unique_fd /*fenceFd*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::getReadbackBufferFence(Display /*display*/,
- android::base::unique_fd* /*outFenceFd*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::createVirtualDisplay_2_2(
- uint32_t /*width*/, uint32_t /*height*/, graphics::common::V1_1::PixelFormat* /*format*/,
- Display* /*outDisplay*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-V2_1::Error FakeComposerClient::getClientTargetSupport_2_2(
- Display /*display*/, uint32_t /*width*/, uint32_t /*height*/,
- graphics::common::V1_1::PixelFormat /*format*/,
- graphics::common::V1_1::Dataspace /*dataspace*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::setPowerMode_2_2(Display /*display*/,
- V2_2::IComposerClient::PowerMode /*mode*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::setLayerFloatColor(Display /*display*/, Layer /*layer*/,
- V2_2::IComposerClient::FloatColor /*color*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::getColorModes_2_2(
- Display /*display*/, hidl_vec<graphics::common::V1_1::ColorMode>* /*outModes*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::getRenderIntents(
- Display /*display*/, graphics::common::V1_1::ColorMode /*mode*/,
- std::vector<graphics::common::V1_1::RenderIntent>* /*outIntents*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::setColorMode_2_2(Display /*display*/,
- graphics::common::V1_1::ColorMode /*mode*/,
- graphics::common::V1_1::RenderIntent /*intent*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-std::array<float, 16> FakeComposerClient::getDataspaceSaturationMatrix(
- graphics::common::V1_1::Dataspace /*dataspace*/) {
- return {};
-}
-
-// Composer 2.3
-V2_1::Error FakeComposerClient::getPerFrameMetadataKeys_2_3(
- Display /*display*/, std::vector<V2_3::IComposerClient::PerFrameMetadataKey>* /*outKeys*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::setColorMode_2_3(Display /*display*/,
- graphics::common::V1_2::ColorMode /*mode*/,
- graphics::common::V1_1::RenderIntent /*intent*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::getRenderIntents_2_3(
- Display /*display*/, graphics::common::V1_2::ColorMode /*mode*/,
- std::vector<graphics::common::V1_1::RenderIntent>* /*outIntents*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::getColorModes_2_3(
- Display /*display*/, hidl_vec<graphics::common::V1_2::ColorMode>* /*outModes*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::getClientTargetSupport_2_3(
- Display /*display*/, uint32_t /*width*/, uint32_t /*height*/,
- graphics::common::V1_2::PixelFormat /*format*/,
- graphics::common::V1_2::Dataspace /*dataspace*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::getReadbackBufferAttributes_2_3(
- Display /*display*/, graphics::common::V1_2::PixelFormat* /*outFormat*/,
- graphics::common::V1_2::Dataspace* /*outDataspace*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::getHdrCapabilities_2_3(
- Display /*display*/, hidl_vec<graphics::common::V1_2::Hdr>* /*outTypes*/,
- float* /*outMaxLuminance*/, float* /*outMaxAverageLuminance*/, float* /*outMinLuminance*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::setLayerPerFrameMetadata_2_3(
- Display /*display*/, Layer /*layer*/,
- const std::vector<V2_3::IComposerClient::PerFrameMetadata>& /*metadata*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::getDisplayIdentificationData(Display /*display*/,
- uint8_t* /*outPort*/,
- std::vector<uint8_t>* /*outData*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::setLayerColorTransform(Display /*display*/, Layer /*layer*/,
- const float* /*matrix*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::getDisplayedContentSamplingAttributes(
- uint64_t /*display*/, graphics::common::V1_2::PixelFormat& /*format*/,
- graphics::common::V1_2::Dataspace& /*dataspace*/,
- hidl_bitfield<V2_3::IComposerClient::FormatColorComponent>& /*componentMask*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::setDisplayedContentSamplingEnabled(
- uint64_t /*display*/, V2_3::IComposerClient::DisplayedContentSampling /*enable*/,
- hidl_bitfield<V2_3::IComposerClient::FormatColorComponent> /*componentMask*/,
- uint64_t /*maxFrames*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::getDisplayedContentSample(
- uint64_t /*display*/, uint64_t /*maxFrames*/, uint64_t /*timestamp*/,
- uint64_t& /*frameCount*/, hidl_vec<uint64_t>& /*sampleComponent0*/,
- hidl_vec<uint64_t>& /*sampleComponent1*/, hidl_vec<uint64_t>& /*sampleComponent2*/,
- hidl_vec<uint64_t>& /*sampleComponent3*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::getDisplayCapabilities(
- Display /*display*/,
- std::vector<V2_3::IComposerClient::DisplayCapability>* /*outCapabilities*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::setLayerPerFrameMetadataBlobs(
- Display /*display*/, Layer /*layer*/,
- std::vector<V2_3::IComposerClient::PerFrameMetadataBlob>& /*blobs*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::getDisplayBrightnessSupport(Display /*display*/,
- bool* /*outSupport*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-V2_1::Error FakeComposerClient::setDisplayBrightness(Display /*display*/, float /*brightness*/) {
- return V2_1::Error::UNSUPPORTED;
-}
-
-// Composer 2.4
-void FakeComposerClient::registerEventCallback_2_4(EventCallback_2_4* callback) {
- ALOGV("registerEventCallback_2_4");
- LOG_FATAL_IF(mEventCallback != nullptr, "already registered using registerEventCallback");
-
- mEventCallback_2_4 = callback;
- if (mEventCallback_2_4) {
- mEventCallback_2_4->onHotplug(PRIMARY_DISPLAY, IComposerCallback::Connection::CONNECTED);
- }
-}
-
-void FakeComposerClient::unregisterEventCallback_2_4() {
- ALOGV("unregisterEventCallback_2_4");
- mEventCallback_2_4 = nullptr;
-}
-
-V2_4::Error FakeComposerClient::getDisplayCapabilities_2_4(
- Display /*display*/,
- std::vector<V2_4::IComposerClient::DisplayCapability>* /*outCapabilities*/) {
- return V2_4::Error::UNSUPPORTED;
-}
-
-V2_4::Error FakeComposerClient::getDisplayConnectionType(
- Display /*display*/, V2_4::IComposerClient::DisplayConnectionType* /*outType*/) {
- return V2_4::Error::UNSUPPORTED;
-}
-
-V2_4::Error FakeComposerClient::getDisplayAttribute_2_4(Display display, Config config,
- IComposerClient::Attribute attribute,
- int32_t* outValue) {
- ALOGV("getDisplayAttribute (%d, %d, %d, %p)", static_cast<int>(display),
- static_cast<int>(config), static_cast<int>(attribute), outValue);
- if (mMockHal) {
- return mMockHal->getDisplayAttribute_2_4(display, config, attribute, outValue);
- }
-
- // TODO: SOOO much fun to be had with these alone
- switch (attribute) {
- case IComposerClient::Attribute::WIDTH:
- *outValue = 1920;
- break;
- case IComposerClient::Attribute::HEIGHT:
- *outValue = 1080;
- break;
- case IComposerClient::Attribute::VSYNC_PERIOD:
- *outValue = 1666666666;
- break; // TOOD: Tests break down if lowered to 16ms?
- case IComposerClient::Attribute::DPI_X:
- *outValue = 240;
- break;
- case IComposerClient::Attribute::DPI_Y:
- *outValue = 240;
- break;
- default:
- LOG_ALWAYS_FATAL("Say what!?! New attribute");
- }
-
- return Error::NONE;
-}
-
-V2_4::Error FakeComposerClient::getDisplayVsyncPeriod(Display display,
- V2_4::VsyncPeriodNanos* outVsyncPeriod) {
- ALOGV("getDisplayVsyncPeriod");
- if (mMockHal) {
- return mMockHal->getDisplayVsyncPeriod(display, outVsyncPeriod);
- }
-
- return V2_4::Error::UNSUPPORTED;
-}
-
-V2_4::Error FakeComposerClient::setActiveConfigWithConstraints(
- Display display, Config config,
- const V2_4::IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
- VsyncPeriodChangeTimeline* timeline) {
- ALOGV("setActiveConfigWithConstraints");
- if (mMockHal) {
- return mMockHal->setActiveConfigWithConstraints(display, config,
- vsyncPeriodChangeConstraints, timeline);
- }
- return V2_4::Error::UNSUPPORTED;
-}
-
-V2_4::Error FakeComposerClient::setAutoLowLatencyMode(Display, bool) {
- ALOGV("setAutoLowLatencyMode");
- return V2_4::Error::UNSUPPORTED;
-}
-
-V2_4::Error FakeComposerClient::getSupportedContentTypes(
- Display, std::vector<IComposerClient::ContentType>*) {
- ALOGV("getSupportedContentTypes");
- return V2_4::Error::UNSUPPORTED;
-}
-
-V2_4::Error FakeComposerClient::setContentType(Display, IComposerClient::ContentType) {
- ALOGV("setContentType");
- return V2_4::Error::UNSUPPORTED;
-}
-
-V2_4::Error FakeComposerClient::validateDisplay_2_4(
- Display /*display*/, std::vector<Layer>* /*outChangedLayers*/,
- std::vector<IComposerClient::Composition>* /*outCompositionTypes*/,
- uint32_t* /*outDisplayRequestMask*/, std::vector<Layer>* /*outRequestedLayers*/,
- std::vector<uint32_t>* /*outRequestMasks*/,
- IComposerClient::ClientTargetProperty* /*outClientTargetProperty*/) {
- return V2_4::Error::NONE;
-}
-
-V2_4::Error FakeComposerClient::setLayerGenericMetadata(Display, Layer, const std::string&, bool,
- const std::vector<uint8_t>&) {
- ALOGV("setLayerGenericMetadata");
- return V2_4::Error::UNSUPPORTED;
-}
-
-V2_4::Error FakeComposerClient::getLayerGenericMetadataKeys(
- std::vector<IComposerClient::LayerGenericMetadataKey>*) {
- ALOGV("getLayerGenericMetadataKeys");
- return V2_4::Error::UNSUPPORTED;
-}
-
-//////////////////////////////////////////////////////////////////
-
-void FakeComposerClient::requestVSync(uint64_t vsyncTime) {
- if (mEventCallback || mEventCallback_2_4) {
- uint64_t timestamp = vsyncTime;
- ALOGV("Vsync");
- if (timestamp == 0) {
- struct timespec ts;
- clock_gettime(CLOCK_MONOTONIC, &ts);
- timestamp = ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec;
- }
- if (mSurfaceComposer != nullptr) {
- mSurfaceComposer->injectVSync(timestamp);
- } else if (mEventCallback) {
- mEventCallback->onVsync(PRIMARY_DISPLAY, timestamp);
- } else {
- mEventCallback_2_4->onVsync_2_4(PRIMARY_DISPLAY, timestamp, 16'666'666);
- }
- }
-}
-
-void FakeComposerClient::runVSyncAfter(std::chrono::nanoseconds wait) {
- mDelayedEventGenerator->wakeAfter(wait);
-}
-
-LayerImpl& FakeComposerClient::getLayerImpl(Layer handle) {
- // TODO Change these to an internal state check that can be
- // invoked from the gtest? GTest macros do not seem all that safe
- // when used outside the test class
- EXPECT_GE(handle, static_cast<Layer>(0));
- EXPECT_LT(handle, mLayers.size());
- return *(mLayers[handle]);
-}
-
-int FakeComposerClient::getFrameCount() const {
- return mFrames.size();
-}
-
-static std::vector<RenderState> extractRenderState(
- const std::vector<std::unique_ptr<FrameRect>>& internalRects) {
- std::vector<RenderState> result;
- result.reserve(internalRects.size());
- for (const std::unique_ptr<FrameRect>& rect : internalRects) {
- result.push_back(rect->renderState);
- }
- return result;
-}
-
-std::vector<RenderState> FakeComposerClient::getFrameRects(int frame) const {
- Mutex::Autolock _l(mStateMutex);
- return extractRenderState(mFrames[frame]->rectangles);
-}
-
-std::vector<RenderState> FakeComposerClient::getLatestFrame() const {
- Mutex::Autolock _l(mStateMutex);
- return extractRenderState(mFrames[mFrames.size() - 1]->rectangles);
-}
-
-void FakeComposerClient::runVSyncAndWait(std::chrono::nanoseconds maxWait) {
- int currentFrame = 0;
- {
- Mutex::Autolock _l(mStateMutex); // I hope this is ok...
- currentFrame = static_cast<int>(mFrames.size());
- requestVSync();
- }
- waitUntilFrame(currentFrame + 1, maxWait);
-}
-
-void FakeComposerClient::waitUntilFrame(int targetFrame, std::chrono::nanoseconds maxWait) const {
- Mutex::Autolock _l(mStateMutex);
- while (mFrames.size() < static_cast<size_t>(targetFrame)) {
- android::status_t result = mFramesAvailable.waitRelative(mStateMutex, maxWait.count());
- if (result == android::TIMED_OUT) {
- ALOGE("Waiting for frame %d (at frame %zu now) timed out after %lld ns", targetFrame,
- mFrames.size(), maxWait.count());
- return;
- }
- }
-}
-
-void FakeComposerClient::clearFrames() {
- Mutex::Autolock _l(mStateMutex);
- mFrames.clear();
- for (const std::unique_ptr<LayerImpl>& layer : mLayers) {
- if (layer->mValid) {
- layer->mRenderState.mSwapCount = 0;
- }
- }
-}
-
-void FakeComposerClient::onSurfaceFlingerStart() {
- mSurfaceComposer = nullptr;
- do {
- mSurfaceComposer = android::sp<android::SurfaceComposerClient>::make();
- android::status_t initResult = mSurfaceComposer->initCheck();
- if (initResult != android::NO_ERROR) {
- ALOGD("Init result: %d", initResult);
- mSurfaceComposer = nullptr;
- std::this_thread::sleep_for(10ms);
- }
- } while (mSurfaceComposer == nullptr);
- ALOGD("SurfaceComposerClient created");
- mSurfaceComposer->enableVSyncInjections(true);
-}
-
-void FakeComposerClient::onSurfaceFlingerStop() {
- mSurfaceComposer->enableVSyncInjections(false);
- mSurfaceComposer->dispose();
- mSurfaceComposer.clear();
-}
-
-// Includes destroyed layers, stored in order of creation.
-int FakeComposerClient::getLayerCount() const {
- return mLayers.size();
-}
-
-Layer FakeComposerClient::getLayer(size_t index) const {
- // NOTE: If/when passing calls through to actual implementation,
- // this might get more involving.
- return static_cast<Layer>(index);
-}
-
-// TODO(b/129481165): remove the #pragma below and fix conversion issues
-#pragma clang diagnostic pop // ignored "-Wconversion"
diff --git a/services/surfaceflinger/tests/fakehwc/FakeComposerClient.h b/services/surfaceflinger/tests/fakehwc/FakeComposerClient.h
deleted file mode 100644
index 600e765..0000000
--- a/services/surfaceflinger/tests/fakehwc/FakeComposerClient.h
+++ /dev/null
@@ -1,301 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-
-#pragma once
-
-#include <chrono>
-
-#include <composer-hal/2.1/ComposerClient.h>
-#include <composer-hal/2.2/ComposerClient.h>
-#include <composer-hal/2.3/ComposerClient.h>
-#include <composer-hal/2.4/ComposerClient.h>
-#include <utils/Condition.h>
-
-#include "MockComposerHal.h"
-#include "RenderState.h"
-
-using namespace android::hardware::graphics::common;
-using namespace android::hardware::graphics::composer;
-using namespace android::hardware::graphics::composer::V2_4;
-using namespace android::hardware::graphics::composer::V2_4::hal;
-using namespace android::hardware;
-using namespace std::chrono_literals;
-
-namespace {
-class LayerImpl;
-class Frame;
-class DelayedEventGenerator;
-} // namespace
-
-namespace android {
-class SurfaceComposerClient;
-} // namespace android
-
-namespace sftest {
-// NOTE: The ID's need to be exactly these. VR composer and parts of
-// the SurfaceFlinger assume the display IDs to have these values
-// despite the enum being documented as a display type.
-// TODO: Reference to actual documentation
-constexpr Display PRIMARY_DISPLAY = static_cast<Display>(HWC_DISPLAY_PRIMARY);
-constexpr Display EXTERNAL_DISPLAY = static_cast<Display>(HWC_DISPLAY_EXTERNAL);
-
-class FakeComposerClient : public ComposerHal {
-public:
- FakeComposerClient();
- virtual ~FakeComposerClient();
-
- void setMockHal(MockComposerHal* mockHal) { mMockHal = mockHal; }
-
- bool hasCapability(hwc2_capability_t capability) override;
-
- std::string dumpDebugInfo() override;
- void registerEventCallback(EventCallback* callback) override;
- void unregisterEventCallback() override;
-
- uint32_t getMaxVirtualDisplayCount() override;
- V2_1::Error createVirtualDisplay(uint32_t width, uint32_t height, V1_0::PixelFormat* format,
- Display* outDisplay) override;
- V2_1::Error destroyVirtualDisplay(Display display) override;
- V2_1::Error createLayer(Display display, Layer* outLayer) override;
- V2_1::Error destroyLayer(Display display, Layer layer) override;
-
- V2_1::Error getActiveConfig(Display display, Config* outConfig) override;
- V2_1::Error getClientTargetSupport(Display display, uint32_t width, uint32_t height,
- V1_0::PixelFormat format,
- V1_0::Dataspace dataspace) override;
- V2_1::Error getColorModes(Display display, hidl_vec<V1_0::ColorMode>* outModes) override;
- V2_1::Error getDisplayAttribute(Display display, Config config,
- V2_1::IComposerClient::Attribute attribute,
- int32_t* outValue) override;
- V2_1::Error getDisplayConfigs(Display display, hidl_vec<Config>* outConfigs) override;
- V2_1::Error getDisplayName(Display display, hidl_string* outName) override;
- V2_1::Error getDisplayType(Display display, IComposerClient::DisplayType* outType) override;
- V2_1::Error getDozeSupport(Display display, bool* outSupport) override;
- V2_1::Error getHdrCapabilities(Display display, hidl_vec<V1_0::Hdr>* outTypes,
- float* outMaxLuminance, float* outMaxAverageLuminance,
- float* outMinLuminance) override;
-
- V2_1::Error setActiveConfig(Display display, Config config) override;
- V2_1::Error setColorMode(Display display, V1_0::ColorMode mode) override;
- V2_1::Error setPowerMode(Display display, V2_1::IComposerClient::PowerMode mode) override;
- V2_1::Error setVsyncEnabled(Display display, IComposerClient::Vsync enabled) override;
-
- V2_1::Error setColorTransform(Display display, const float* matrix, int32_t hint) override;
- V2_1::Error setClientTarget(Display display, buffer_handle_t target, int32_t acquireFence,
- int32_t dataspace, const std::vector<hwc_rect_t>& damage) override;
- V2_1::Error setOutputBuffer(Display display, buffer_handle_t buffer,
- int32_t releaseFence) override;
- V2_1::Error validateDisplay(Display display, std::vector<Layer>* outChangedLayers,
- std::vector<IComposerClient::Composition>* outCompositionTypes,
- uint32_t* outDisplayRequestMask,
- std::vector<Layer>* outRequestedLayers,
- std::vector<uint32_t>* outRequestMasks) override;
- V2_1::Error acceptDisplayChanges(Display display) override;
- V2_1::Error presentDisplay(Display display, int32_t* outPresentFence,
- std::vector<Layer>* outLayers,
- std::vector<int32_t>* outReleaseFences) override;
-
- V2_1::Error setLayerCursorPosition(Display display, Layer layer, int32_t x, int32_t y) override;
- V2_1::Error setLayerBuffer(Display display, Layer layer, buffer_handle_t buffer,
- int32_t acquireFence) override;
- V2_1::Error setLayerSurfaceDamage(Display display, Layer layer,
- const std::vector<hwc_rect_t>& damage) override;
- V2_1::Error setLayerBlendMode(Display display, Layer layer, int32_t mode) override;
- V2_1::Error setLayerColor(Display display, Layer layer, IComposerClient::Color color) override;
- V2_1::Error setLayerCompositionType(Display display, Layer layer, int32_t type) override;
- V2_1::Error setLayerDataspace(Display display, Layer layer, int32_t dataspace) override;
- V2_1::Error setLayerDisplayFrame(Display display, Layer layer,
- const hwc_rect_t& frame) override;
- V2_1::Error setLayerPlaneAlpha(Display display, Layer layer, float alpha) override;
- V2_1::Error setLayerSidebandStream(Display display, Layer layer,
- buffer_handle_t stream) override;
- V2_1::Error setLayerSourceCrop(Display display, Layer layer, const hwc_frect_t& crop) override;
- V2_1::Error setLayerTransform(Display display, Layer layer, int32_t transform) override;
- V2_1::Error setLayerVisibleRegion(Display display, Layer layer,
- const std::vector<hwc_rect_t>& visible) override;
- V2_1::Error setLayerZOrder(Display display, Layer layer, uint32_t z) override;
-
- // Composer 2.2
- V2_1::Error getPerFrameMetadataKeys(
- Display display,
- std::vector<V2_2::IComposerClient::PerFrameMetadataKey>* outKeys) override;
- V2_1::Error setLayerPerFrameMetadata(
- Display display, Layer layer,
- const std::vector<V2_2::IComposerClient::PerFrameMetadata>& metadata) override;
-
- V2_1::Error getReadbackBufferAttributes(
- Display display, graphics::common::V1_1::PixelFormat* outFormat,
- graphics::common::V1_1::Dataspace* outDataspace) override;
- V2_1::Error setReadbackBuffer(Display display, const native_handle_t* bufferHandle,
- android::base::unique_fd fenceFd) override;
- V2_1::Error getReadbackBufferFence(Display display,
- android::base::unique_fd* outFenceFd) override;
- V2_1::Error createVirtualDisplay_2_2(uint32_t width, uint32_t height,
- graphics::common::V1_1::PixelFormat* format,
- Display* outDisplay) override;
- V2_1::Error getClientTargetSupport_2_2(Display display, uint32_t width, uint32_t height,
- graphics::common::V1_1::PixelFormat format,
- graphics::common::V1_1::Dataspace dataspace) override;
- V2_1::Error setPowerMode_2_2(Display display, V2_2::IComposerClient::PowerMode mode) override;
-
- V2_1::Error setLayerFloatColor(Display display, Layer layer,
- V2_2::IComposerClient::FloatColor color) override;
-
- V2_1::Error getColorModes_2_2(Display display,
- hidl_vec<graphics::common::V1_1::ColorMode>* outModes) override;
- V2_1::Error getRenderIntents(
- Display display, graphics::common::V1_1::ColorMode mode,
- std::vector<graphics::common::V1_1::RenderIntent>* outIntents) override;
- V2_1::Error setColorMode_2_2(Display display, graphics::common::V1_1::ColorMode mode,
- graphics::common::V1_1::RenderIntent intent) override;
-
- std::array<float, 16> getDataspaceSaturationMatrix(
- graphics::common::V1_1::Dataspace dataspace) override;
-
- // Composer 2.3
- V2_1::Error getPerFrameMetadataKeys_2_3(
- Display display,
- std::vector<V2_3::IComposerClient::PerFrameMetadataKey>* outKeys) override;
-
- V2_1::Error setColorMode_2_3(Display display, graphics::common::V1_2::ColorMode mode,
- graphics::common::V1_1::RenderIntent intent) override;
-
- V2_1::Error getRenderIntents_2_3(
- Display display, graphics::common::V1_2::ColorMode mode,
- std::vector<graphics::common::V1_1::RenderIntent>* outIntents) override;
-
- V2_1::Error getColorModes_2_3(Display display,
- hidl_vec<graphics::common::V1_2::ColorMode>* outModes) override;
-
- V2_1::Error getClientTargetSupport_2_3(Display display, uint32_t width, uint32_t height,
- graphics::common::V1_2::PixelFormat format,
- graphics::common::V1_2::Dataspace dataspace) override;
- V2_1::Error getReadbackBufferAttributes_2_3(
- Display display, graphics::common::V1_2::PixelFormat* outFormat,
- graphics::common::V1_2::Dataspace* outDataspace) override;
- V2_1::Error getHdrCapabilities_2_3(Display display,
- hidl_vec<graphics::common::V1_2::Hdr>* outTypes,
- float* outMaxLuminance, float* outMaxAverageLuminance,
- float* outMinLuminance) override;
- V2_1::Error setLayerPerFrameMetadata_2_3(
- Display display, Layer layer,
- const std::vector<V2_3::IComposerClient::PerFrameMetadata>& metadata) override;
- V2_1::Error getDisplayIdentificationData(Display display, uint8_t* outPort,
- std::vector<uint8_t>* outData) override;
- V2_1::Error setLayerColorTransform(Display display, Layer layer, const float* matrix) override;
- V2_1::Error getDisplayedContentSamplingAttributes(
- uint64_t display, graphics::common::V1_2::PixelFormat& format,
- graphics::common::V1_2::Dataspace& dataspace,
- hidl_bitfield<V2_3::IComposerClient::FormatColorComponent>& componentMask) override;
- V2_1::Error setDisplayedContentSamplingEnabled(
- uint64_t display, V2_3::IComposerClient::DisplayedContentSampling enable,
- hidl_bitfield<V2_3::IComposerClient::FormatColorComponent> componentMask,
- uint64_t maxFrames) override;
- V2_1::Error getDisplayedContentSample(uint64_t display, uint64_t maxFrames, uint64_t timestamp,
- uint64_t& frameCount,
- hidl_vec<uint64_t>& sampleComponent0,
- hidl_vec<uint64_t>& sampleComponent1,
- hidl_vec<uint64_t>& sampleComponent2,
- hidl_vec<uint64_t>& sampleComponent3) override;
- V2_1::Error getDisplayCapabilities(
- Display display,
- std::vector<V2_3::IComposerClient::DisplayCapability>* outCapabilities) override;
- V2_1::Error setLayerPerFrameMetadataBlobs(
- Display display, Layer layer,
- std::vector<V2_3::IComposerClient::PerFrameMetadataBlob>& blobs) override;
- V2_1::Error getDisplayBrightnessSupport(Display display, bool* outSupport) override;
- V2_1::Error setDisplayBrightness(Display display, float brightness) override;
-
- // Composer 2.4
- void registerEventCallback_2_4(EventCallback_2_4* callback) override;
-
- void unregisterEventCallback_2_4() override;
-
- V2_4::Error getDisplayCapabilities_2_4(
- Display display,
- std::vector<V2_4::IComposerClient::DisplayCapability>* outCapabilities) override;
- V2_4::Error getDisplayConnectionType(
- Display display, V2_4::IComposerClient::DisplayConnectionType* outType) override;
- V2_4::Error getDisplayAttribute_2_4(Display display, Config config,
- IComposerClient::Attribute attribute,
- int32_t* outValue) override;
- V2_4::Error getDisplayVsyncPeriod(Display display,
- V2_4::VsyncPeriodNanos* outVsyncPeriod) override;
- V2_4::Error setActiveConfigWithConstraints(
- Display display, Config config,
- const V2_4::IComposerClient::VsyncPeriodChangeConstraints& vsyncPeriodChangeConstraints,
- VsyncPeriodChangeTimeline* outTimeline) override;
- V2_4::Error setAutoLowLatencyMode(Display display, bool on) override;
- V2_4::Error getSupportedContentTypes(
- Display display,
- std::vector<IComposerClient::ContentType>* outSupportedContentTypes) override;
- V2_4::Error setContentType(Display display, IComposerClient::ContentType type) override;
- V2_4::Error validateDisplay_2_4(
- Display display, std::vector<Layer>* outChangedLayers,
- std::vector<IComposerClient::Composition>* outCompositionTypes,
- uint32_t* outDisplayRequestMask, std::vector<Layer>* outRequestedLayers,
- std::vector<uint32_t>* outRequestMasks,
- IComposerClient::ClientTargetProperty* outClientTargetProperty) override;
- V2_4::Error setLayerGenericMetadata(Display display, Layer layer, const std::string& key,
- bool mandatory, const std::vector<uint8_t>& value) override;
- V2_4::Error getLayerGenericMetadataKeys(
- std::vector<IComposerClient::LayerGenericMetadataKey>* outKeys) override;
-
- void setClient(ComposerClient* client);
-
- void requestVSync(uint64_t vsyncTime = 0);
- // We don't want tests hanging, so always use a timeout. Remember
- // to always check the number of frames with test ASSERT_!
- // Wait until next frame is rendered after requesting vsync.
- void runVSyncAndWait(std::chrono::nanoseconds maxWait = 100ms);
- void runVSyncAfter(std::chrono::nanoseconds wait);
-
- int getFrameCount() const;
- // We don't want tests hanging, so always use a timeout. Remember
- // to always check the number of frames with test ASSERT_!
- void waitUntilFrame(int targetFrame, std::chrono::nanoseconds maxWait = 100ms) const;
- std::vector<RenderState> getFrameRects(int frame) const;
- std::vector<RenderState> getLatestFrame() const;
- void clearFrames();
-
- void onSurfaceFlingerStart();
- void onSurfaceFlingerStop();
-
- int getLayerCount() const;
- Layer getLayer(size_t index) const;
-
- void hotplugDisplay(Display display, IComposerCallback::Connection state);
- void refreshDisplay(Display display);
-
-private:
- LayerImpl& getLayerImpl(Layer handle);
-
- EventCallback* mEventCallback;
- EventCallback_2_4* mEventCallback_2_4;
- Config mCurrentConfig;
- bool mVsyncEnabled;
- std::vector<std::unique_ptr<LayerImpl>> mLayers;
- std::vector<std::unique_ptr<Frame>> mFrames;
- // Using a pointer to hide the implementation into the CPP file.
- std::unique_ptr<DelayedEventGenerator> mDelayedEventGenerator;
- android::sp<android::SurfaceComposerClient> mSurfaceComposer; // For VSync injections
- mutable android::Mutex mStateMutex;
- mutable android::Condition mFramesAvailable;
-
- MockComposerHal* mMockHal = nullptr;
-};
-
-} // namespace sftest
diff --git a/services/surfaceflinger/tests/fakehwc/FakeComposerService.cpp b/services/surfaceflinger/tests/fakehwc/FakeComposerService.cpp
deleted file mode 100644
index c656eed..0000000
--- a/services/surfaceflinger/tests/fakehwc/FakeComposerService.cpp
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-// TODO(b/129481165): remove the #pragma below and fix conversion issues
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wconversion"
-
-#define LOG_NDEBUG 0
-#undef LOG_TAG
-#define LOG_TAG "FakeHwcService"
-#include <log/log.h>
-
-#include "FakeComposerService.h"
-
-using namespace android::hardware;
-using namespace android::hardware::graphics::composer;
-
-namespace sftest {
-
-FakeComposerService_2_1::FakeComposerService_2_1(android::sp<ComposerClient>& client)
- : mClient(client) {}
-
-FakeComposerService_2_1::~FakeComposerService_2_1() {
- ALOGI("Maybe killing client %p", mClient.get());
- // Rely on sp to kill the client.
-}
-
-Return<void> FakeComposerService_2_1::getCapabilities(getCapabilities_cb hidl_cb) {
- ALOGI("FakeComposerService::getCapabilities");
- hidl_cb(hidl_vec<Capability>());
- return Void();
-}
-
-Return<void> FakeComposerService_2_1::dumpDebugInfo(dumpDebugInfo_cb hidl_cb) {
- ALOGI("FakeComposerService::dumpDebugInfo");
- hidl_cb(hidl_string());
- return Void();
-}
-
-Return<void> FakeComposerService_2_1::createClient(createClient_cb hidl_cb) {
- ALOGI("FakeComposerService::createClient %p", mClient.get());
- if (!mClient->init()) {
- LOG_ALWAYS_FATAL("failed to initialize ComposerClient");
- }
- hidl_cb(V2_1::Error::NONE, mClient);
- return Void();
-}
-
-FakeComposerService_2_2::FakeComposerService_2_2(android::sp<ComposerClient>& client)
- : mClient(client) {}
-
-FakeComposerService_2_2::~FakeComposerService_2_2() {
- ALOGI("Maybe killing client %p", mClient.get());
- // Rely on sp to kill the client.
-}
-
-Return<void> FakeComposerService_2_2::getCapabilities(getCapabilities_cb hidl_cb) {
- ALOGI("FakeComposerService::getCapabilities");
- hidl_cb(hidl_vec<Capability>());
- return Void();
-}
-
-Return<void> FakeComposerService_2_2::dumpDebugInfo(dumpDebugInfo_cb hidl_cb) {
- ALOGI("FakeComposerService::dumpDebugInfo");
- hidl_cb(hidl_string());
- return Void();
-}
-
-Return<void> FakeComposerService_2_2::createClient(createClient_cb hidl_cb) {
- ALOGI("FakeComposerService::createClient %p", mClient.get());
- if (!mClient->init()) {
- LOG_ALWAYS_FATAL("failed to initialize ComposerClient");
- }
- hidl_cb(V2_1::Error::NONE, mClient);
- return Void();
-}
-
-FakeComposerService_2_3::FakeComposerService_2_3(android::sp<ComposerClient>& client)
- : mClient(client) {}
-
-FakeComposerService_2_3::~FakeComposerService_2_3() {
- ALOGI("Maybe killing client %p", mClient.get());
- // Rely on sp to kill the client.
-}
-
-Return<void> FakeComposerService_2_3::getCapabilities(getCapabilities_cb hidl_cb) {
- ALOGI("FakeComposerService::getCapabilities");
- hidl_cb(hidl_vec<Capability>());
- return Void();
-}
-
-Return<void> FakeComposerService_2_3::dumpDebugInfo(dumpDebugInfo_cb hidl_cb) {
- ALOGI("FakeComposerService::dumpDebugInfo");
- hidl_cb(hidl_string());
- return Void();
-}
-
-Return<void> FakeComposerService_2_3::createClient(createClient_cb hidl_cb) {
- LOG_ALWAYS_FATAL("createClient called on FakeComposerService_2_3");
- if (!mClient->init()) {
- LOG_ALWAYS_FATAL("failed to initialize ComposerClient");
- }
- hidl_cb(V2_1::Error::UNSUPPORTED, nullptr);
- return Void();
-}
-
-Return<void> FakeComposerService_2_3::createClient_2_3(createClient_2_3_cb hidl_cb) {
- ALOGI("FakeComposerService_2_3::createClient_2_3 %p", mClient.get());
- if (!mClient->init()) {
- LOG_ALWAYS_FATAL("failed to initialize ComposerClient");
- }
- hidl_cb(V2_1::Error::NONE, mClient);
- return Void();
-}
-
-FakeComposerService_2_4::FakeComposerService_2_4(android::sp<ComposerClient>& client)
- : mClient(client) {}
-
-FakeComposerService_2_4::~FakeComposerService_2_4() {
- ALOGI("Maybe killing client %p", mClient.get());
- // Rely on sp to kill the client.
-}
-
-Return<void> FakeComposerService_2_4::getCapabilities(getCapabilities_cb hidl_cb) {
- ALOGI("FakeComposerService::getCapabilities");
- hidl_cb(hidl_vec<Capability>());
- return Void();
-}
-
-Return<void> FakeComposerService_2_4::dumpDebugInfo(dumpDebugInfo_cb hidl_cb) {
- ALOGI("FakeComposerService::dumpDebugInfo");
- hidl_cb(hidl_string());
- return Void();
-}
-
-Return<void> FakeComposerService_2_4::createClient(createClient_cb hidl_cb) {
- LOG_ALWAYS_FATAL("createClient called on FakeComposerService_2_4");
- if (!mClient->init()) {
- LOG_ALWAYS_FATAL("failed to initialize ComposerClient");
- }
- hidl_cb(V2_1::Error::UNSUPPORTED, nullptr);
- return Void();
-}
-
-Return<void> FakeComposerService_2_4::createClient_2_3(createClient_2_3_cb hidl_cb) {
- LOG_ALWAYS_FATAL("createClient_2_3 called on FakeComposerService_2_4");
- if (!mClient->init()) {
- LOG_ALWAYS_FATAL("failed to initialize ComposerClient");
- }
- hidl_cb(V2_1::Error::UNSUPPORTED, nullptr);
- return Void();
-}
-
-Return<void> FakeComposerService_2_4::createClient_2_4(createClient_2_4_cb hidl_cb) {
- ALOGI("FakeComposerService_2_4::createClient_2_4 %p", mClient.get());
- if (!mClient->init()) {
- LOG_ALWAYS_FATAL("failed to initialize ComposerClient");
- }
- hidl_cb(V2_4::Error::NONE, mClient);
- return Void();
-}
-
-} // namespace sftest
-
-// TODO(b/129481165): remove the #pragma below and fix conversion issues
-#pragma clang diagnostic pop // ignored "-Wconversion"
diff --git a/services/surfaceflinger/tests/fakehwc/FakeComposerService.h b/services/surfaceflinger/tests/fakehwc/FakeComposerService.h
deleted file mode 100644
index 47f970f..0000000
--- a/services/surfaceflinger/tests/fakehwc/FakeComposerService.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-#pragma once
-
-#include <android/hardware/graphics/composer/2.4/IComposer.h>
-#include <composer-hal/2.1/ComposerClient.h>
-#include <composer-hal/2.2/ComposerClient.h>
-#include <composer-hal/2.3/ComposerClient.h>
-#include <composer-hal/2.4/ComposerClient.h>
-
-using android::hardware::Return;
-
-using ComposerClient = android::hardware::graphics::composer::V2_4::hal::ComposerClient;
-
-namespace sftest {
-
-using IComposer_2_1 = android::hardware::graphics::composer::V2_1::IComposer;
-
-class FakeComposerService_2_1 : public IComposer_2_1 {
-public:
- explicit FakeComposerService_2_1(android::sp<ComposerClient>& client);
- virtual ~FakeComposerService_2_1();
-
- Return<void> getCapabilities(getCapabilities_cb hidl_cb) override;
- Return<void> dumpDebugInfo(dumpDebugInfo_cb hidl_cb) override;
- Return<void> createClient(createClient_cb hidl_cb) override;
-
-private:
- android::sp<ComposerClient> mClient;
-};
-
-using IComposer_2_2 = android::hardware::graphics::composer::V2_2::IComposer;
-class FakeComposerService_2_2 : public IComposer_2_2 {
-public:
- explicit FakeComposerService_2_2(android::sp<ComposerClient>& client);
- virtual ~FakeComposerService_2_2();
-
- Return<void> getCapabilities(getCapabilities_cb hidl_cb) override;
- Return<void> dumpDebugInfo(dumpDebugInfo_cb hidl_cb) override;
- Return<void> createClient(createClient_cb hidl_cb) override;
-
-private:
- android::sp<ComposerClient> mClient;
-};
-
-using IComposer_2_3 = android::hardware::graphics::composer::V2_3::IComposer;
-class FakeComposerService_2_3 : public IComposer_2_3 {
-public:
- explicit FakeComposerService_2_3(android::sp<ComposerClient>& client);
- virtual ~FakeComposerService_2_3();
-
- Return<void> getCapabilities(getCapabilities_cb hidl_cb) override;
- Return<void> dumpDebugInfo(dumpDebugInfo_cb hidl_cb) override;
- Return<void> createClient(createClient_cb hidl_cb) override;
- Return<void> createClient_2_3(createClient_2_3_cb hidl_cb) override;
-
-private:
- android::sp<ComposerClient> mClient;
-};
-
-using IComposer_2_4 = android::hardware::graphics::composer::V2_4::IComposer;
-
-class FakeComposerService_2_4 : public IComposer_2_4 {
-public:
- explicit FakeComposerService_2_4(android::sp<ComposerClient>& client);
- virtual ~FakeComposerService_2_4();
-
- Return<void> getCapabilities(getCapabilities_cb hidl_cb) override;
- Return<void> dumpDebugInfo(dumpDebugInfo_cb hidl_cb) override;
- Return<void> createClient(createClient_cb hidl_cb) override;
- Return<void> createClient_2_3(createClient_2_3_cb hidl_cb) override;
- Return<void> createClient_2_4(createClient_2_4_cb hidl_cb) override;
-
-private:
- android::sp<ComposerClient> mClient;
-};
-
-} // namespace sftest
diff --git a/services/surfaceflinger/tests/fakehwc/FakeComposerUtils.cpp b/services/surfaceflinger/tests/fakehwc/FakeComposerUtils.cpp
deleted file mode 100644
index 1cea25a..0000000
--- a/services/surfaceflinger/tests/fakehwc/FakeComposerUtils.cpp
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-
-// TODO(b/129481165): remove the #pragma below and fix conversion issues
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wconversion"
-
-#define LOG_NDEBUG 0
-#undef LOG_TAG
-#define LOG_TAG "FakeHwcUtil"
-#include <log/log.h>
-
-#include "FakeComposerUtils.h"
-#include "RenderState.h"
-
-#include "SurfaceFlinger.h" // Get the name of the service...
-
-#include <binder/IServiceManager.h>
-#include <cutils/properties.h>
-#include <hidl/ServiceManagement.h>
-
-#include <iomanip>
-#include <thread>
-
-using android::String16;
-using android::sp;
-using namespace std::chrono_literals;
-using namespace sftest;
-using std::setw;
-
-namespace sftest {
-
-// clang-format off
-inline void printSourceRectAligned(::std::ostream& os, const hwc_frect_t& sourceRect, int align) {
- os << std::fixed << std::setprecision(1) << "("
- << setw(align) << sourceRect.left << setw(0) << ","
- << setw(align) << sourceRect.top << setw(0) << ","
- << setw(align) << sourceRect.right << setw(0) << ","
- << setw(align) << sourceRect.bottom << setw(0) << ")";
-}
-
-inline void printDisplayRectAligned(::std::ostream& os, const hwc_rect_t& displayRect, int align) {
- os << "("
- << setw(align) << displayRect.left << setw(0) << ","
- << setw(align) << displayRect.top << setw(0) << ","
- << setw(align) << displayRect.right << setw(0) << ","
- << setw(align) << displayRect.bottom << setw(0) << ")";
-}
-// clang-format on
-
-inline ::std::ostream& operator<<(::std::ostream& os, const sftest::RenderState& state) {
- printSourceRectAligned(os, state.mSourceCrop, 7);
- os << "->";
- printDisplayRectAligned(os, state.mDisplayFrame, 5);
- return os << " Swaps:" << state.mSwapCount << " Alpha:" << std::setprecision(3)
- << state.mPlaneAlpha << " Xform:" << state.mTransform;
-}
-
-// Helper for verifying the parts of the RenderState
-template <typename T>
-bool valuesMatch(::testing::AssertionResult& message, const T& ref, const T& val,
- const char* name) {
- if (ref != val) {
- message = message << "Expected " << name << ":" << ref << ", got:" << val << ".";
- return false;
- }
- return true;
-}
-
-::testing::AssertionResult rectsAreSame(const RenderState& ref, const RenderState& val) {
- // TODO: Message could start as success and be assigned as failure.
- // Only problem is that utility assumes it to be failure and just adds stuff. Would
- // need still special case the initial failure in the utility?
- // TODO: ... or would it be possible to break this back to gtest primitives?
- ::testing::AssertionResult message = ::testing::AssertionFailure();
- bool passes = true;
-
- // The work here is mostly about providing good log strings for differences
- passes &= valuesMatch(message, ref.mDisplayFrame, val.mDisplayFrame, "display frame");
- passes &= valuesMatch(message, ref.mPlaneAlpha, val.mPlaneAlpha, "alpha");
- passes &= valuesMatch(message, ref.mSwapCount, val.mSwapCount, "swap count");
- passes &= valuesMatch(message, ref.mSourceCrop, val.mSourceCrop, "source crop");
- // ... add more
- if (passes) {
- return ::testing::AssertionSuccess();
- }
- return message;
-}
-
-::testing::AssertionResult framesAreSame(const std::vector<RenderState>& ref,
- const std::vector<RenderState>& val) {
- ::testing::AssertionResult message = ::testing::AssertionFailure();
- bool passed = true;
- if (ref.size() != val.size()) {
- message << "Expected " << ref.size() << " rects, got " << val.size() << ".";
- passed = false;
- }
- for (size_t rectIndex = 0; rectIndex < std::min(ref.size(), val.size()); rectIndex++) {
- ::testing::AssertionResult rectResult = rectsAreSame(ref[rectIndex], val[rectIndex]);
- if (rectResult == false) {
- message << "First different rect at " << rectIndex << ": " << rectResult.message();
- passed = false;
- break;
- }
- }
-
- if (passed) {
- return ::testing::AssertionSuccess();
- } else {
- message << "\nReference:";
- for (auto state = ref.begin(); state != ref.end(); ++state) {
- message << "\n" << *state;
- }
- message << "\nActual:";
- for (auto state = val.begin(); state != val.end(); ++state) {
- message << "\n" << *state;
- }
- }
- return message;
-}
-
-void startSurfaceFlinger() {
- ALOGI("Start SurfaceFlinger");
- system("start surfaceflinger");
-
- sp<android::IServiceManager> sm(android::defaultServiceManager());
- sp<android::IBinder> sf;
- while (sf == nullptr) {
- std::this_thread::sleep_for(10ms);
- sf = sm->checkService(String16(android::SurfaceFlinger::getServiceName()));
- }
- ALOGV("SurfaceFlinger running");
-}
-
-void stopSurfaceFlinger() {
- ALOGI("Stop SurfaceFlinger");
- system("stop surfaceflinger");
- sp<android::IServiceManager> sm(android::defaultServiceManager());
- sp<android::IBinder> sf;
- while (sf != nullptr) {
- std::this_thread::sleep_for(10ms);
- sf = sm->checkService(String16(android::SurfaceFlinger::getServiceName()));
- }
- ALOGV("SurfaceFlinger stopped");
-}
-
-////////////////////////////////////////////////
-
-void FakeHwcEnvironment::SetUp() {
- ALOGI("Test env setup");
- system("setenforce 0");
- system("stop");
- property_set("debug.sf.nobootanimation", "1");
- {
- char value[PROPERTY_VALUE_MAX];
- property_get("debug.sf.nobootanimation", value, "0");
- LOG_FATAL_IF(atoi(value) != 1, "boot skip not set");
- }
- // TODO: Try registering the mock as the default service instead.
- property_set("debug.sf.hwc_service_name", "mock");
-
- // This allows tests/SF to register/load a HIDL service not listed in manifest files.
- android::hardware::details::setTrebleTestingOverride(true);
- property_set("debug.sf.treble_testing_override", "true");
-}
-
-void FakeHwcEnvironment::TearDown() {
- ALOGI("Test env tear down");
- system("stop");
- // Wait for mock call signaling teardown?
- property_set("debug.sf.nobootanimation", "0");
- property_set("debug.sf.hwc_service_name", "default");
- system("setenforce 1");
- ALOGI("Test env tear down - done");
-}
-
-} // namespace sftest
-
-// TODO(b/129481165): remove the #pragma below and fix conversion issues
-#pragma clang diagnostic pop // ignored "-Wconversion"
diff --git a/services/surfaceflinger/tests/fakehwc/FakeComposerUtils.h b/services/surfaceflinger/tests/fakehwc/FakeComposerUtils.h
deleted file mode 100644
index 383a111..0000000
--- a/services/surfaceflinger/tests/fakehwc/FakeComposerUtils.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-
-#pragma once
-
-#include "FakeComposerClient.h"
-
-#include <gui/SurfaceComposerClient.h>
-#include <log/log.h>
-#include <gtest/gtest.h>
-
-// clang-format off
-// Note: This needs to reside in the global namespace for the GTest to use it
-inline ::std::ostream& operator<<(::std::ostream& os, const hwc_rect_t& rect) {
- return os << "(" << rect.left << ","
- << rect.top << ","
- << rect.right << ","
- << rect.bottom << ")";
-}
-
-inline ::std::ostream& operator<<(::std::ostream& os, const hwc_frect_t& rect) {
- return os << "(" << rect.left << ","
- << rect.top << ","
- << rect.right << ","
- << rect.bottom << ")";
-}
-// clang-format on
-
-namespace sftest {
-
-class RenderState;
-
-// clang-format off
-inline bool operator==(const hwc_rect_t& a, const hwc_rect_t& b) {
- return a.top == b.top &&
- a.left == b.left &&
- a.bottom == b.bottom &&
- a.right == b.right;
-}
-
-inline bool operator==(const hwc_frect_t& a, const hwc_frect_t& b) {
- return a.top == b.top &&
- a.left == b.left &&
- a.bottom == b.bottom &&
- a.right == b.right;
-}
-// clang-format on
-
-inline bool operator!=(const hwc_rect_t& a, const hwc_rect_t& b) {
- return !(a == b);
-}
-
-inline bool operator!=(const hwc_frect_t& a, const hwc_frect_t& b) {
- return !(a == b);
-}
-
-::testing::AssertionResult rectsAreSame(const RenderState& ref, const RenderState& val);
-::testing::AssertionResult framesAreSame(const std::vector<RenderState>& ref,
- const std::vector<RenderState>& val);
-
-void startSurfaceFlinger();
-void stopSurfaceFlinger();
-
-class FakeHwcEnvironment : public ::testing::Environment {
-public:
- virtual ~FakeHwcEnvironment() {}
- void SetUp() override;
- void TearDown() override;
-};
-
-/*
- * All surface state changes are supposed to happen inside a global
- * transaction. TransactionScope object at the beginning of
- * scope automates the process. The resulting scope gives a visual cue
- * on the span of the transaction as well.
- *
- * Closing the transaction is synchronous, i.e., it waits for
- * SurfaceFlinger to composite one frame. Now, the FakeComposerClient
- * is built to explicitly request vsyncs one at the time. A delayed
- * request must be made before closing the transaction or the test
- * thread stalls until SurfaceFlinger does an emergency vsync by
- * itself. TransactionScope encapsulates this vsync magic.
- */
-class TransactionScope : public android::SurfaceComposerClient::Transaction {
-public:
- explicit TransactionScope(FakeComposerClient& composer) : Transaction(), mComposer(composer) {}
-
- ~TransactionScope() {
- int frameCount = mComposer.getFrameCount();
- mComposer.runVSyncAfter(1ms);
- LOG_ALWAYS_FATAL_IF(android::NO_ERROR != apply());
- // Make sure that exactly one frame has been rendered.
- mComposer.waitUntilFrame(frameCount + 1);
- // LOG_ALWAYS_FATAL_IF(frameCount + 1 != mComposer.getFrameCount(),
- // "Unexpected frame advance. Delta: %d",
- // mComposer.getFrameCount() - frameCount);
- }
-
- FakeComposerClient& mComposer;
-};
-
-} // namespace sftest
diff --git a/services/surfaceflinger/tests/fakehwc/MockComposerHal.h b/services/surfaceflinger/tests/fakehwc/MockComposerHal.h
deleted file mode 100644
index 5dc3778..0000000
--- a/services/surfaceflinger/tests/fakehwc/MockComposerHal.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2019 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.
- */
-
-#pragma once
-
-#include <composer-hal/2.4/ComposerClient.h>
-
-#include <gmock/gmock.h>
-
-using namespace android::hardware::graphics::common;
-using namespace android::hardware::graphics::composer;
-using namespace android::hardware::graphics::composer::V2_4;
-using namespace android::hardware::graphics::composer::V2_4::hal;
-using namespace android::hardware;
-using namespace std::chrono_literals;
-
-namespace sftest {
-
-// Mock class for ComposerHal. Implements only the functions used in the test.
-class MockComposerHal {
-public:
- MOCK_METHOD2(getActiveConfig, V2_1::Error(Display, Config*));
- MOCK_METHOD4(getDisplayAttribute_2_4,
- V2_4::Error(Display, Config, V2_4::IComposerClient::Attribute, int32_t*));
- MOCK_METHOD2(getDisplayConfigs, V2_1::Error(Display, hidl_vec<Config>*));
- MOCK_METHOD2(setActiveConfig, V2_1::Error(Display, Config));
- MOCK_METHOD2(getDisplayVsyncPeriod, V2_4::Error(Display, V2_4::VsyncPeriodNanos*));
- MOCK_METHOD4(setActiveConfigWithConstraints,
- V2_4::Error(Display, Config,
- const V2_4::IComposerClient::VsyncPeriodChangeConstraints&,
- VsyncPeriodChangeTimeline*));
-};
-
-} // namespace sftest
\ No newline at end of file
diff --git a/services/surfaceflinger/tests/fakehwc/RenderState.h b/services/surfaceflinger/tests/fakehwc/RenderState.h
deleted file mode 100644
index 40193f2..0000000
--- a/services/surfaceflinger/tests/fakehwc/RenderState.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2017 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.
- */
-
-#pragma once
-
-#include <vector>
-
-namespace sftest {
-// Description of a rendered rectangle. Should only contain
-// instructions necessary to rasterize the rectangle. The full scene
-// is given as a sorted list of rectangles, bottom layer at index 0.
-class RenderState {
-public:
- RenderState() = default;
- // Default copy-ctor
-
- hwc_rect_t mDisplayFrame = {0, 0, 0, 0};
- hwc_frect_t mSourceCrop = {0.f, 0.f, 0.f, 0.f};
- std::vector<hwc_rect_t> mVisibleRegion;
- hwc2_blend_mode_t mBlendMode = HWC2_BLEND_MODE_NONE;
- buffer_handle_t mBuffer = 0;
- uint32_t mSwapCount = 0; // How many set buffer calls to the layer.
- int32_t mAcquireFence = 0; // Probably should not be here.
- float mPlaneAlpha = 0.f;
- hwc_color_t mLayerColor = {0, 0, 0, 0};
- hwc_transform_t mTransform = static_cast<hwc_transform_t>(0);
-};
-
-} // namespace sftest
diff --git a/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp b/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp
deleted file mode 100644
index 1d3401a..0000000
--- a/services/surfaceflinger/tests/fakehwc/SFFakeHwc_test.cpp
+++ /dev/null
@@ -1,1794 +0,0 @@
-/*
- * Copyright (C) 2017 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.
- */
-
-// TODO(b/129481165): remove the #pragma below and fix conversion issues
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wconversion"
-#pragma clang diagnostic ignored "-Wextra"
-
-// #define LOG_NDEBUG 0
-#undef LOG_TAG
-#define LOG_TAG "FakeHwcTest"
-
-#include "FakeComposerClient.h"
-#include "FakeComposerService.h"
-#include "FakeComposerUtils.h"
-#include "MockComposerHal.h"
-
-#include <binder/Parcel.h>
-#include <gui/AidlStatusUtil.h>
-#include <gui/DisplayEventReceiver.h>
-#include <gui/ISurfaceComposer.h>
-#include <gui/LayerDebugInfo.h>
-#include <gui/LayerState.h>
-#include <gui/Surface.h>
-#include <gui/SurfaceComposerClient.h>
-
-#include <android/hidl/manager/1.0/IServiceManager.h>
-#include <android/looper.h>
-#include <android/native_window.h>
-#include <binder/ProcessState.h>
-#include <hwbinder/ProcessState.h>
-#include <log/log.h>
-#include <private/gui/ComposerService.h>
-#include <private/gui/ComposerServiceAIDL.h>
-#include <ui/DisplayMode.h>
-#include <ui/DynamicDisplayInfo.h>
-#include <utils/Looper.h>
-
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
-
-#include <limits>
-#include <thread>
-
-using namespace std::chrono_literals;
-
-using namespace android;
-using namespace android::hardware;
-
-using namespace sftest;
-
-namespace {
-
-// Mock test helpers
-using ::testing::_;
-using ::testing::DoAll;
-using ::testing::Return;
-using ::testing::SetArgPointee;
-
-using Transaction = SurfaceComposerClient::Transaction;
-using Attribute = V2_4::IComposerClient::Attribute;
-using Display = V2_1::Display;
-
-///////////////////////////////////////////////
-constexpr PhysicalDisplayId physicalIdFromHwcDisplayId(Display hwcId) {
- return PhysicalDisplayId::fromPort(hwcId);
-}
-constexpr PhysicalDisplayId kPrimaryDisplayId = physicalIdFromHwcDisplayId(PRIMARY_DISPLAY);
-constexpr PhysicalDisplayId kExternalDisplayId = physicalIdFromHwcDisplayId(EXTERNAL_DISPLAY);
-
-struct TestColor {
-public:
- uint8_t r;
- uint8_t g;
- uint8_t b;
- uint8_t a;
-};
-
-constexpr static TestColor RED = {195, 63, 63, 255};
-constexpr static TestColor LIGHT_RED = {255, 177, 177, 255};
-constexpr static TestColor GREEN = {63, 195, 63, 255};
-constexpr static TestColor BLUE = {63, 63, 195, 255};
-constexpr static TestColor LIGHT_GRAY = {200, 200, 200, 255};
-
-// Fill an RGBA_8888 formatted surface with a single color.
-static void fillSurfaceRGBA8(const sp<SurfaceControl>& sc, const TestColor& color,
- bool unlock = true) {
- ANativeWindow_Buffer outBuffer;
- sp<Surface> s = sc->getSurface();
- ASSERT_TRUE(s != nullptr);
- ASSERT_EQ(NO_ERROR, s->lock(&outBuffer, nullptr));
- uint8_t* img = reinterpret_cast<uint8_t*>(outBuffer.bits);
- for (int y = 0; y < outBuffer.height; y++) {
- for (int x = 0; x < outBuffer.width; x++) {
- uint8_t* pixel = img + (4 * (y * outBuffer.stride + x));
- pixel[0] = color.r;
- pixel[1] = color.g;
- pixel[2] = color.b;
- pixel[3] = color.a;
- }
- }
- if (unlock) {
- ASSERT_EQ(NO_ERROR, s->unlockAndPost());
- }
-}
-
-inline RenderState makeSimpleRect(int left, int top, int right, int bottom) {
- RenderState res;
- res.mDisplayFrame = hwc_rect_t{left, top, right, bottom};
- res.mPlaneAlpha = 1.0f;
- res.mSwapCount = 0;
- res.mSourceCrop = hwc_frect_t{0.f, 0.f, static_cast<float>(right - left),
- static_cast<float>(bottom - top)};
- return res;
-}
-
-inline RenderState makeSimpleRect(unsigned int left, unsigned int top, unsigned int right,
- unsigned int bottom) {
- EXPECT_LE(left, static_cast<unsigned int>(INT_MAX));
- EXPECT_LE(top, static_cast<unsigned int>(INT_MAX));
- EXPECT_LE(right, static_cast<unsigned int>(INT_MAX));
- EXPECT_LE(bottom, static_cast<unsigned int>(INT_MAX));
- return makeSimpleRect(static_cast<int>(left), static_cast<int>(top), static_cast<int>(right),
- static_cast<int>(bottom));
-}
-
-///////////////////////////////////////////////
-template <typename FakeComposerService>
-class DisplayTest : public ::testing::Test {
-protected:
- struct TestConfig {
- int32_t id;
- int32_t w;
- int32_t h;
- int32_t vsyncPeriod;
- int32_t group;
- };
-
- static int processDisplayEvents(int /*fd*/, int /*events*/, void* data) {
- auto self = static_cast<DisplayTest*>(data);
-
- ssize_t n;
- DisplayEventReceiver::Event buffer[1];
-
- while ((n = self->mReceiver->getEvents(buffer, 1)) > 0) {
- for (int i = 0; i < n; i++) {
- self->mReceivedDisplayEvents.push_back(buffer[i]);
- }
- }
- ALOGD_IF(n < 0, "Error reading events (%s)", strerror(-n));
- return 1;
- }
-
- Error getDisplayAttributeNoMock(Display display, Config config,
- V2_4::IComposerClient::Attribute attribute, int32_t* outValue) {
- mFakeComposerClient->setMockHal(nullptr);
- auto ret =
- mFakeComposerClient->getDisplayAttribute_2_4(display, config, attribute, outValue);
- mFakeComposerClient->setMockHal(mMockComposer.get());
- return ret;
- }
-
- void setExpectationsForConfigs(Display display, std::vector<TestConfig> testConfigs,
- Config activeConfig, V2_4::VsyncPeriodNanos defaultVsyncPeriod) {
- std::vector<Config> configIds;
- for (size_t i = 0; i < testConfigs.size(); i++) {
- configIds.push_back(testConfigs[i].id);
-
- EXPECT_CALL(*mMockComposer,
- getDisplayAttribute_2_4(display, testConfigs[i].id, Attribute::WIDTH, _))
- .WillRepeatedly(DoAll(SetArgPointee<3>(testConfigs[i].w), Return(Error::NONE)));
- EXPECT_CALL(*mMockComposer,
- getDisplayAttribute_2_4(display, testConfigs[i].id, Attribute::HEIGHT, _))
- .WillRepeatedly(DoAll(SetArgPointee<3>(testConfigs[i].h), Return(Error::NONE)));
- EXPECT_CALL(*mMockComposer,
- getDisplayAttribute_2_4(display, testConfigs[i].id, Attribute::VSYNC_PERIOD,
- _))
- .WillRepeatedly(DoAll(SetArgPointee<3>(testConfigs[i].vsyncPeriod),
- Return(Error::NONE)));
- EXPECT_CALL(*mMockComposer,
- getDisplayAttribute_2_4(display, testConfigs[i].id, Attribute::CONFIG_GROUP,
- _))
- .WillRepeatedly(
- DoAll(SetArgPointee<3>(testConfigs[i].group), Return(Error::NONE)));
- EXPECT_CALL(*mMockComposer,
- getDisplayAttribute_2_4(display, testConfigs[i].id, Attribute::DPI_X, _))
- .WillRepeatedly(Return(Error::UNSUPPORTED));
- EXPECT_CALL(*mMockComposer,
- getDisplayAttribute_2_4(display, testConfigs[i].id, Attribute::DPI_Y, _))
- .WillRepeatedly(Return(Error::UNSUPPORTED));
- }
-
- EXPECT_CALL(*mMockComposer, getDisplayConfigs(display, _))
- .WillRepeatedly(DoAll(SetArgPointee<1>(hidl_vec<Config>(configIds)),
- Return(V2_1::Error::NONE)));
-
- EXPECT_CALL(*mMockComposer, getActiveConfig(display, _))
- .WillRepeatedly(DoAll(SetArgPointee<1>(activeConfig), Return(V2_1::Error::NONE)));
-
- EXPECT_CALL(*mMockComposer, getDisplayVsyncPeriod(display, _))
- .WillRepeatedly(
- DoAll(SetArgPointee<1>(defaultVsyncPeriod), Return(V2_4::Error::NONE)));
- }
-
- void SetUp() override {
- mMockComposer = std::make_unique<MockComposerHal>();
- mFakeComposerClient = new FakeComposerClient();
- mFakeComposerClient->setMockHal(mMockComposer.get());
-
- auto client = sp<V2_4::hal::ComposerClient>::make(mFakeComposerClient);
- mFakeService = sp<FakeComposerService>::make(client);
- ASSERT_EQ(android::OK, mFakeService->registerAsService("mock"));
-
- android::hardware::ProcessState::self()->startThreadPool();
- android::ProcessState::self()->startThreadPool();
-
- setExpectationsForConfigs(PRIMARY_DISPLAY,
- {{
- .id = 1,
- .w = 1920,
- .h = 1024,
- .vsyncPeriod = 16'666'666,
- .group = 0,
- }},
- 1, 16'666'666);
-
- startSurfaceFlinger();
-
- // Fake composer wants to enable VSync injection
- mFakeComposerClient->onSurfaceFlingerStart();
-
- mComposerClient = sp<SurfaceComposerClient>::make();
- ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
-
- mReceiver.reset(
- new DisplayEventReceiver(gui::ISurfaceComposer::VsyncSource::eVsyncSourceApp,
- gui::ISurfaceComposer::EventRegistration::modeChanged));
- mLooper = sp<Looper>::make(false);
- mLooper->addFd(mReceiver->getFd(), 0, ALOOPER_EVENT_INPUT, processDisplayEvents, this);
- }
-
- void TearDown() override {
- mLooper = nullptr;
- mReceiver = nullptr;
-
- mComposerClient->dispose();
- mComposerClient = nullptr;
-
- // Fake composer needs to release SurfaceComposerClient before the stop.
- mFakeComposerClient->onSurfaceFlingerStop();
- stopSurfaceFlinger();
-
- mFakeComposerClient->setMockHal(nullptr);
-
- mFakeService = nullptr;
- // TODO: Currently deleted in FakeComposerClient::removeClient(). Devise better lifetime
- // management.
- mMockComposer = nullptr;
- }
-
- void waitForDisplayTransaction(Display display) {
- // Both a refresh and a vsync event are needed to apply pending display
- // transactions.
- mFakeComposerClient->refreshDisplay(display);
- mFakeComposerClient->runVSyncAndWait();
-
- // Extra vsync and wait to avoid a 10% flake due to a race.
- mFakeComposerClient->runVSyncAndWait();
- }
-
- bool waitForHotplugEvent(Display displayId, bool connected) {
- return waitForHotplugEvent(physicalIdFromHwcDisplayId(displayId), connected);
- }
-
- bool waitForHotplugEvent(PhysicalDisplayId displayId, bool connected) {
- int waitCount = 20;
- while (waitCount--) {
- while (!mReceivedDisplayEvents.empty()) {
- auto event = mReceivedDisplayEvents.front();
- mReceivedDisplayEvents.pop_front();
-
- ALOGV_IF(event.header.type == DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG,
- "event hotplug: displayId %s, connected %d",
- to_string(event.header.displayId).c_str(), event.hotplug.connected);
-
- if (event.header.type == DisplayEventReceiver::DISPLAY_EVENT_HOTPLUG &&
- event.header.displayId == displayId && event.hotplug.connected == connected) {
- return true;
- }
- }
-
- mLooper->pollOnce(1);
- }
- return false;
- }
-
- bool waitForModeChangedEvent(Display display, int32_t modeId) {
- PhysicalDisplayId displayId = physicalIdFromHwcDisplayId(display);
- int waitCount = 20;
- while (waitCount--) {
- while (!mReceivedDisplayEvents.empty()) {
- auto event = mReceivedDisplayEvents.front();
- mReceivedDisplayEvents.pop_front();
-
- ALOGV_IF(event.header.type == DisplayEventReceiver::DISPLAY_EVENT_MODE_CHANGE,
- "event mode: displayId %s, modeId %d",
- to_string(event.header.displayId).c_str(), event.modeChange.modeId);
-
- if (event.header.type == DisplayEventReceiver::DISPLAY_EVENT_MODE_CHANGE &&
- event.header.displayId == displayId && event.modeChange.modeId == modeId) {
- return true;
- }
- }
-
- mLooper->pollOnce(1);
- }
- return false;
- }
-
- void Test_HotplugOneConfig() {
- ALOGD("DisplayTest::Test_Hotplug_oneConfig");
-
- setExpectationsForConfigs(EXTERNAL_DISPLAY,
- {{.id = 1,
- .w = 200,
- .h = 400,
- .vsyncPeriod = 16'666'666,
- .group = 0}},
- 1, 16'666'666);
-
- mFakeComposerClient->hotplugDisplay(EXTERNAL_DISPLAY,
- V2_1::IComposerCallback::Connection::CONNECTED);
- waitForDisplayTransaction(EXTERNAL_DISPLAY);
- EXPECT_TRUE(waitForHotplugEvent(EXTERNAL_DISPLAY, true));
-
- {
- const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kExternalDisplayId);
- EXPECT_FALSE(display == nullptr);
-
- ui::DisplayMode mode;
- EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode));
- const ui::Size& resolution = mode.resolution;
- EXPECT_EQ(ui::Size(200, 400), resolution);
- EXPECT_EQ(1e9f / 16'666'666, mode.refreshRate);
-
- auto surfaceControl =
- mComposerClient->createSurface(String8("Display Test Surface Foo"),
- resolution.getWidth(), resolution.getHeight(),
- PIXEL_FORMAT_RGBA_8888, 0);
- EXPECT_TRUE(surfaceControl != nullptr);
- EXPECT_TRUE(surfaceControl->isValid());
- fillSurfaceRGBA8(surfaceControl, BLUE);
-
- {
- TransactionScope ts(*mFakeComposerClient);
- ts.setDisplayLayerStack(display, ui::DEFAULT_LAYER_STACK);
-
- ts.setLayer(surfaceControl, INT32_MAX - 2).show(surfaceControl);
- }
- }
-
- mFakeComposerClient->hotplugDisplay(EXTERNAL_DISPLAY,
- V2_1::IComposerCallback::Connection::DISCONNECTED);
- waitForDisplayTransaction(EXTERNAL_DISPLAY);
- mFakeComposerClient->clearFrames();
- EXPECT_TRUE(waitForHotplugEvent(EXTERNAL_DISPLAY, false));
-
- {
- const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kExternalDisplayId);
- EXPECT_TRUE(display == nullptr);
-
- ui::DisplayMode mode;
- EXPECT_NE(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode));
- }
- }
-
- void Test_HotplugTwoSeparateConfigs() {
- ALOGD("DisplayTest::Test_HotplugTwoSeparateConfigs");
-
- setExpectationsForConfigs(EXTERNAL_DISPLAY,
- {{.id = 1,
- .w = 200,
- .h = 400,
- .vsyncPeriod = 16'666'666,
- .group = 0},
- {.id = 2,
- .w = 800,
- .h = 1600,
- .vsyncPeriod = 11'111'111,
- .group = 1}},
- 1, 16'666'666);
-
- mFakeComposerClient->hotplugDisplay(EXTERNAL_DISPLAY,
- V2_1::IComposerCallback::Connection::CONNECTED);
- waitForDisplayTransaction(EXTERNAL_DISPLAY);
- EXPECT_TRUE(waitForHotplugEvent(EXTERNAL_DISPLAY, true));
-
- const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kExternalDisplayId);
- EXPECT_FALSE(display == nullptr);
-
- ui::DisplayMode mode;
- EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode));
- EXPECT_EQ(ui::Size(200, 400), mode.resolution);
- EXPECT_EQ(1e9f / 16'666'666, mode.refreshRate);
-
- mFakeComposerClient->clearFrames();
- {
- const ui::Size& resolution = mode.resolution;
- auto surfaceControl =
- mComposerClient->createSurface(String8("Display Test Surface Foo"),
- resolution.getWidth(), resolution.getHeight(),
- PIXEL_FORMAT_RGBA_8888, 0);
- EXPECT_TRUE(surfaceControl != nullptr);
- EXPECT_TRUE(surfaceControl->isValid());
- fillSurfaceRGBA8(surfaceControl, BLUE);
-
- {
- TransactionScope ts(*mFakeComposerClient);
- ts.setDisplayLayerStack(display, ui::DEFAULT_LAYER_STACK);
-
- ts.setLayer(surfaceControl, INT32_MAX - 2).show(surfaceControl);
- }
- }
-
- ui::DynamicDisplayInfo info;
- EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getDynamicDisplayInfo(display, &info));
- const auto& modes = info.supportedDisplayModes;
- EXPECT_EQ(modes.size(), 2);
-
- // change active mode
-
- if (mIs2_4Client) {
- EXPECT_CALL(*mMockComposer, setActiveConfigWithConstraints(EXTERNAL_DISPLAY, 2, _, _))
- .WillOnce(Return(V2_4::Error::NONE));
- } else {
- EXPECT_CALL(*mMockComposer, setActiveConfig(EXTERNAL_DISPLAY, 2))
- .WillOnce(Return(V2_1::Error::NONE));
- }
-
- for (int i = 0; i < modes.size(); i++) {
- const auto& mode = modes[i];
- if (mode.resolution.getWidth() == 800) {
- EXPECT_EQ(NO_ERROR,
- SurfaceComposerClient::setDesiredDisplayModeSpecs(display, i, false,
- mode.refreshRate,
- mode.refreshRate,
- mode.refreshRate,
- mode.refreshRate));
- waitForDisplayTransaction(EXTERNAL_DISPLAY);
- EXPECT_TRUE(waitForModeChangedEvent(EXTERNAL_DISPLAY, i));
- break;
- }
- }
-
- EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode));
- EXPECT_EQ(ui::Size(800, 1600), mode.resolution);
- EXPECT_EQ(1e9f / 11'111'111, mode.refreshRate);
-
- mFakeComposerClient->clearFrames();
- {
- const ui::Size& resolution = mode.resolution;
- auto surfaceControl =
- mComposerClient->createSurface(String8("Display Test Surface Foo"),
- resolution.getWidth(), resolution.getHeight(),
- PIXEL_FORMAT_RGBA_8888, 0);
- EXPECT_TRUE(surfaceControl != nullptr);
- EXPECT_TRUE(surfaceControl->isValid());
- fillSurfaceRGBA8(surfaceControl, BLUE);
-
- {
- TransactionScope ts(*mFakeComposerClient);
- ts.setDisplayLayerStack(display, ui::DEFAULT_LAYER_STACK);
-
- ts.setLayer(surfaceControl, INT32_MAX - 2).show(surfaceControl);
- }
- }
-
- mFakeComposerClient->hotplugDisplay(EXTERNAL_DISPLAY,
- V2_1::IComposerCallback::Connection::DISCONNECTED);
- waitForDisplayTransaction(EXTERNAL_DISPLAY);
- mFakeComposerClient->clearFrames();
- EXPECT_TRUE(waitForHotplugEvent(EXTERNAL_DISPLAY, false));
- }
-
- void Test_HotplugTwoConfigsSameGroup() {
- ALOGD("DisplayTest::Test_HotplugTwoConfigsSameGroup");
-
- setExpectationsForConfigs(EXTERNAL_DISPLAY,
- {{.id = 2,
- .w = 800,
- .h = 1600,
- .vsyncPeriod = 16'666'666,
- .group = 31},
- {.id = 3,
- .w = 800,
- .h = 1600,
- .vsyncPeriod = 11'111'111,
- .group = 31}},
- 2, 16'666'666);
-
- mFakeComposerClient->hotplugDisplay(EXTERNAL_DISPLAY,
- V2_1::IComposerCallback::Connection::CONNECTED);
- waitForDisplayTransaction(EXTERNAL_DISPLAY);
- EXPECT_TRUE(waitForHotplugEvent(EXTERNAL_DISPLAY, true));
-
- const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kExternalDisplayId);
- EXPECT_FALSE(display == nullptr);
-
- ui::DisplayMode mode;
- EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode));
- EXPECT_EQ(ui::Size(800, 1600), mode.resolution);
- EXPECT_EQ(1e9f / 16'666'666, mode.refreshRate);
-
- mFakeComposerClient->clearFrames();
- {
- const ui::Size& resolution = mode.resolution;
- auto surfaceControl =
- mComposerClient->createSurface(String8("Display Test Surface Foo"),
- resolution.getWidth(), resolution.getHeight(),
- PIXEL_FORMAT_RGBA_8888, 0);
- EXPECT_TRUE(surfaceControl != nullptr);
- EXPECT_TRUE(surfaceControl->isValid());
- fillSurfaceRGBA8(surfaceControl, BLUE);
-
- {
- TransactionScope ts(*mFakeComposerClient);
- ts.setDisplayLayerStack(display, ui::DEFAULT_LAYER_STACK);
-
- ts.setLayer(surfaceControl, INT32_MAX - 2).show(surfaceControl);
- }
- }
-
- ui::DynamicDisplayInfo info;
- EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getDynamicDisplayInfo(display, &info));
- const auto& modes = info.supportedDisplayModes;
- EXPECT_EQ(modes.size(), 2);
-
- // change active mode
- if (mIs2_4Client) {
- EXPECT_CALL(*mMockComposer, setActiveConfigWithConstraints(EXTERNAL_DISPLAY, 3, _, _))
- .WillOnce(Return(V2_4::Error::NONE));
- } else {
- EXPECT_CALL(*mMockComposer, setActiveConfig(EXTERNAL_DISPLAY, 3))
- .WillOnce(Return(V2_1::Error::NONE));
- }
-
- for (int i = 0; i < modes.size(); i++) {
- const auto& mode = modes[i];
- if (mode.refreshRate == 1e9f / 11'111'111) {
- EXPECT_EQ(NO_ERROR,
- SurfaceComposerClient::setDesiredDisplayModeSpecs(display, i, false,
- mode.refreshRate,
- mode.refreshRate,
- mode.refreshRate,
- mode.refreshRate));
- waitForDisplayTransaction(EXTERNAL_DISPLAY);
- EXPECT_TRUE(waitForModeChangedEvent(EXTERNAL_DISPLAY, i));
- break;
- }
- }
-
- EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode));
- EXPECT_EQ(ui::Size(800, 1600), mode.resolution);
- EXPECT_EQ(1e9f / 11'111'111, mode.refreshRate);
-
- mFakeComposerClient->clearFrames();
- {
- const ui::Size& resolution = mode.resolution;
- auto surfaceControl =
- mComposerClient->createSurface(String8("Display Test Surface Foo"),
- resolution.getWidth(), resolution.getHeight(),
- PIXEL_FORMAT_RGBA_8888, 0);
- EXPECT_TRUE(surfaceControl != nullptr);
- EXPECT_TRUE(surfaceControl->isValid());
- fillSurfaceRGBA8(surfaceControl, BLUE);
-
- {
- TransactionScope ts(*mFakeComposerClient);
- ts.setDisplayLayerStack(display, ui::DEFAULT_LAYER_STACK);
-
- ts.setLayer(surfaceControl, INT32_MAX - 2).show(surfaceControl);
- }
- }
-
- mFakeComposerClient->hotplugDisplay(EXTERNAL_DISPLAY,
- V2_1::IComposerCallback::Connection::DISCONNECTED);
- waitForDisplayTransaction(EXTERNAL_DISPLAY);
- mFakeComposerClient->clearFrames();
- EXPECT_TRUE(waitForHotplugEvent(EXTERNAL_DISPLAY, false));
- }
-
- void Test_HotplugThreeConfigsMixedGroups() {
- ALOGD("DisplayTest::Test_HotplugThreeConfigsMixedGroups");
-
- setExpectationsForConfigs(EXTERNAL_DISPLAY,
- {{.id = 2,
- .w = 800,
- .h = 1600,
- .vsyncPeriod = 16'666'666,
- .group = 0},
- {.id = 3,
- .w = 800,
- .h = 1600,
- .vsyncPeriod = 11'111'111,
- .group = 0},
- {.id = 4,
- .w = 1600,
- .h = 3200,
- .vsyncPeriod = 8'333'333,
- .group = 1},
- {.id = 5,
- .w = 1600,
- .h = 3200,
- .vsyncPeriod = 11'111'111,
- .group = 1}},
- 2, 16'666'666);
-
- mFakeComposerClient->hotplugDisplay(EXTERNAL_DISPLAY,
- V2_1::IComposerCallback::Connection::CONNECTED);
- waitForDisplayTransaction(EXTERNAL_DISPLAY);
- EXPECT_TRUE(waitForHotplugEvent(EXTERNAL_DISPLAY, true));
-
- const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kExternalDisplayId);
- EXPECT_FALSE(display == nullptr);
-
- ui::DisplayMode mode;
- EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode));
- EXPECT_EQ(ui::Size(800, 1600), mode.resolution);
- EXPECT_EQ(1e9f / 16'666'666, mode.refreshRate);
-
- mFakeComposerClient->clearFrames();
- {
- const ui::Size& resolution = mode.resolution;
- auto surfaceControl =
- mComposerClient->createSurface(String8("Display Test Surface Foo"),
- resolution.getWidth(), resolution.getHeight(),
- PIXEL_FORMAT_RGBA_8888, 0);
- EXPECT_TRUE(surfaceControl != nullptr);
- EXPECT_TRUE(surfaceControl->isValid());
- fillSurfaceRGBA8(surfaceControl, BLUE);
-
- {
- TransactionScope ts(*mFakeComposerClient);
- ts.setDisplayLayerStack(display, ui::DEFAULT_LAYER_STACK);
-
- ts.setLayer(surfaceControl, INT32_MAX - 2).show(surfaceControl);
- }
- }
-
- ui::DynamicDisplayInfo info;
- EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getDynamicDisplayInfo(display, &info));
- const auto& modes = info.supportedDisplayModes;
- EXPECT_EQ(modes.size(), 4);
-
- // change active mode to 800x1600@90Hz
- if (mIs2_4Client) {
- EXPECT_CALL(*mMockComposer, setActiveConfigWithConstraints(EXTERNAL_DISPLAY, 3, _, _))
- .WillOnce(Return(V2_4::Error::NONE));
- } else {
- EXPECT_CALL(*mMockComposer, setActiveConfig(EXTERNAL_DISPLAY, 3))
- .WillOnce(Return(V2_1::Error::NONE));
- }
-
- for (size_t i = 0; i < modes.size(); i++) {
- const auto& mode = modes[i];
- if (mode.resolution.getWidth() == 800 && mode.refreshRate == 1e9f / 11'111'111) {
- EXPECT_EQ(NO_ERROR,
- SurfaceComposerClient::setDesiredDisplayModeSpecs(display, i, false,
- modes[i].refreshRate,
- modes[i].refreshRate,
- modes[i].refreshRate,
- modes[i].refreshRate));
- waitForDisplayTransaction(EXTERNAL_DISPLAY);
- EXPECT_TRUE(waitForModeChangedEvent(EXTERNAL_DISPLAY, i));
- break;
- }
- }
-
- EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode));
- EXPECT_EQ(ui::Size(800, 1600), mode.resolution);
- EXPECT_EQ(1e9f / 11'111'111, mode.refreshRate);
-
- mFakeComposerClient->clearFrames();
- {
- const ui::Size& resolution = mode.resolution;
- auto surfaceControl =
- mComposerClient->createSurface(String8("Display Test Surface Foo"),
- resolution.getWidth(), resolution.getHeight(),
- PIXEL_FORMAT_RGBA_8888, 0);
- EXPECT_TRUE(surfaceControl != nullptr);
- EXPECT_TRUE(surfaceControl->isValid());
- fillSurfaceRGBA8(surfaceControl, BLUE);
-
- {
- TransactionScope ts(*mFakeComposerClient);
- ts.setDisplayLayerStack(display, ui::DEFAULT_LAYER_STACK);
-
- ts.setLayer(surfaceControl, INT32_MAX - 2).show(surfaceControl);
- }
- }
-
- // change active mode to 1600x3200@120Hz
- if (mIs2_4Client) {
- EXPECT_CALL(*mMockComposer, setActiveConfigWithConstraints(EXTERNAL_DISPLAY, 4, _, _))
- .WillOnce(Return(V2_4::Error::NONE));
- } else {
- EXPECT_CALL(*mMockComposer, setActiveConfig(EXTERNAL_DISPLAY, 4))
- .WillOnce(Return(V2_1::Error::NONE));
- }
-
- for (int i = 0; i < modes.size(); i++) {
- const auto& mode = modes[i];
- if (mode.refreshRate == 1e9f / 8'333'333) {
- EXPECT_EQ(NO_ERROR,
- SurfaceComposerClient::setDesiredDisplayModeSpecs(display, i, false,
- mode.refreshRate,
- mode.refreshRate,
- mode.refreshRate,
- mode.refreshRate));
- waitForDisplayTransaction(EXTERNAL_DISPLAY);
- EXPECT_TRUE(waitForModeChangedEvent(EXTERNAL_DISPLAY, i));
- break;
- }
- }
-
- EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode));
- EXPECT_EQ(ui::Size(1600, 3200), mode.resolution);
- EXPECT_EQ(1e9f / 8'333'333, mode.refreshRate);
-
- mFakeComposerClient->clearFrames();
- {
- const ui::Size& resolution = mode.resolution;
- auto surfaceControl =
- mComposerClient->createSurface(String8("Display Test Surface Foo"),
- resolution.getWidth(), resolution.getHeight(),
- PIXEL_FORMAT_RGBA_8888, 0);
- EXPECT_TRUE(surfaceControl != nullptr);
- EXPECT_TRUE(surfaceControl->isValid());
- fillSurfaceRGBA8(surfaceControl, BLUE);
-
- {
- TransactionScope ts(*mFakeComposerClient);
- ts.setDisplayLayerStack(display, ui::DEFAULT_LAYER_STACK);
-
- ts.setLayer(surfaceControl, INT32_MAX - 2).show(surfaceControl);
- }
- }
-
- // change active mode to 1600x3200@90Hz
- if (mIs2_4Client) {
- EXPECT_CALL(*mMockComposer, setActiveConfigWithConstraints(EXTERNAL_DISPLAY, 5, _, _))
- .WillOnce(Return(V2_4::Error::NONE));
- } else {
- EXPECT_CALL(*mMockComposer, setActiveConfig(EXTERNAL_DISPLAY, 5))
- .WillOnce(Return(V2_1::Error::NONE));
- }
-
- for (int i = 0; i < modes.size(); i++) {
- const auto& mode = modes[i];
- if (mode.resolution.getWidth() == 1600 && mode.refreshRate == 1e9f / 11'111'111) {
- EXPECT_EQ(NO_ERROR,
- SurfaceComposerClient::setDesiredDisplayModeSpecs(display, i, false,
- mode.refreshRate,
- mode.refreshRate,
- mode.refreshRate,
- mode.refreshRate));
- waitForDisplayTransaction(EXTERNAL_DISPLAY);
- EXPECT_TRUE(waitForModeChangedEvent(EXTERNAL_DISPLAY, i));
- break;
- }
- }
-
- EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode));
- EXPECT_EQ(ui::Size(1600, 3200), mode.resolution);
- EXPECT_EQ(1e9f / 11'111'111, mode.refreshRate);
-
- mFakeComposerClient->clearFrames();
- {
- const ui::Size& resolution = mode.resolution;
- auto surfaceControl =
- mComposerClient->createSurface(String8("Display Test Surface Foo"),
- resolution.getWidth(), resolution.getHeight(),
- PIXEL_FORMAT_RGBA_8888, 0);
- EXPECT_TRUE(surfaceControl != nullptr);
- EXPECT_TRUE(surfaceControl->isValid());
- fillSurfaceRGBA8(surfaceControl, BLUE);
-
- {
- TransactionScope ts(*mFakeComposerClient);
- ts.setDisplayLayerStack(display, ui::DEFAULT_LAYER_STACK);
-
- ts.setLayer(surfaceControl, INT32_MAX - 2).show(surfaceControl);
- }
- }
-
- mFakeComposerClient->hotplugDisplay(EXTERNAL_DISPLAY,
- V2_1::IComposerCallback::Connection::DISCONNECTED);
- waitForDisplayTransaction(EXTERNAL_DISPLAY);
- mFakeComposerClient->clearFrames();
- EXPECT_TRUE(waitForHotplugEvent(EXTERNAL_DISPLAY, false));
- }
-
- void Test_HotplugPrimaryDisplay() {
- ALOGD("DisplayTest::HotplugPrimaryDisplay");
-
- mFakeComposerClient->hotplugDisplay(PRIMARY_DISPLAY,
- V2_1::IComposerCallback::Connection::DISCONNECTED);
-
- waitForDisplayTransaction(PRIMARY_DISPLAY);
-
- EXPECT_TRUE(waitForHotplugEvent(PRIMARY_DISPLAY, false));
- {
- const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kPrimaryDisplayId);
- EXPECT_TRUE(display == nullptr);
-
- ui::DisplayMode mode;
- auto result = SurfaceComposerClient::getActiveDisplayMode(display, &mode);
- EXPECT_NE(NO_ERROR, result);
- }
-
- mFakeComposerClient->clearFrames();
-
- setExpectationsForConfigs(PRIMARY_DISPLAY,
- {{.id = 1,
- .w = 400,
- .h = 200,
- .vsyncPeriod = 16'666'666,
- .group = 0}},
- 1, 16'666'666);
-
- mFakeComposerClient->hotplugDisplay(PRIMARY_DISPLAY,
- V2_1::IComposerCallback::Connection::CONNECTED);
-
- waitForDisplayTransaction(PRIMARY_DISPLAY);
-
- EXPECT_TRUE(waitForHotplugEvent(PRIMARY_DISPLAY, true));
-
- {
- const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kPrimaryDisplayId);
- EXPECT_FALSE(display == nullptr);
-
- ui::DisplayMode mode;
- auto result = SurfaceComposerClient::getActiveDisplayMode(display, &mode);
- EXPECT_EQ(NO_ERROR, result);
- ASSERT_EQ(ui::Size(400, 200), mode.resolution);
- EXPECT_EQ(1e9f / 16'666'666, mode.refreshRate);
- }
- }
-
- void Test_SubsequentHotplugConnectUpdatesDisplay(Display hwcDisplayId) {
- ALOGD("DisplayTest::Test_SubsequentHotplugConnectUpdatesDisplay");
-
- // Send a hotplug connected event to set up the initial display modes.
- // The primary display is already connected so this will update it.
- // If we're running the test of an external display this will create it.
- setExpectationsForConfigs(hwcDisplayId,
- {{.id = 1,
- .w = 800,
- .h = 1600,
- .vsyncPeriod = 11'111'111,
- .group = 1}},
- /* activeConfig */ 1, 11'111'111);
-
- mFakeComposerClient->hotplugDisplay(hwcDisplayId,
- V2_1::IComposerCallback::Connection::CONNECTED);
- waitForDisplayTransaction(hwcDisplayId);
- EXPECT_TRUE(waitForHotplugEvent(hwcDisplayId, true));
-
- const auto displayId = physicalIdFromHwcDisplayId(hwcDisplayId);
- const auto display = SurfaceComposerClient::getPhysicalDisplayToken(displayId);
- EXPECT_FALSE(display == nullptr);
-
- // Verify that the active mode and the supported moded are updated
- {
- ui::DisplayMode mode;
- EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode));
- EXPECT_EQ(ui::Size(800, 1600), mode.resolution);
- EXPECT_EQ(1e9f / 11'111'111, mode.refreshRate);
-
- ui::DynamicDisplayInfo info;
- EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getDynamicDisplayInfo(display, &info));
- const auto& modes = info.supportedDisplayModes;
- EXPECT_EQ(modes.size(), 1);
- }
-
- // Send another hotplug connected event
- setExpectationsForConfigs(hwcDisplayId,
- {
- {.id = 1,
- .w = 800,
- .h = 1600,
- .vsyncPeriod = 16'666'666,
- .group = 1},
- {.id = 2,
- .w = 800,
- .h = 1600,
- .vsyncPeriod = 11'111'111,
- .group = 1},
- {.id = 3,
- .w = 800,
- .h = 1600,
- .vsyncPeriod = 8'333'333,
- .group = 1},
- },
- /* activeConfig */ 1, 16'666'666);
-
- mFakeComposerClient->hotplugDisplay(hwcDisplayId,
- V2_1::IComposerCallback::Connection::CONNECTED);
- waitForDisplayTransaction(hwcDisplayId);
- EXPECT_TRUE(waitForHotplugEvent(hwcDisplayId, true));
-
- // Verify that the active mode and the supported moded are updated
- {
- ui::DisplayMode mode;
- EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode));
- EXPECT_EQ(ui::Size(800, 1600), mode.resolution);
- EXPECT_EQ(1e9f / 16'666'666, mode.refreshRate);
- }
-
- ui::DynamicDisplayInfo info;
- EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getDynamicDisplayInfo(display, &info));
- const auto& modes = info.supportedDisplayModes;
- EXPECT_EQ(modes.size(), 3);
-
- EXPECT_EQ(ui::Size(800, 1600), modes[0].resolution);
- EXPECT_EQ(1e9f / 16'666'666, modes[0].refreshRate);
-
- EXPECT_EQ(ui::Size(800, 1600), modes[1].resolution);
- EXPECT_EQ(1e9f / 11'111'111, modes[1].refreshRate);
-
- EXPECT_EQ(ui::Size(800, 1600), modes[2].resolution);
- EXPECT_EQ(1e9f / 8'333'333, modes[2].refreshRate);
-
- // Verify that we are able to switch to any of the modes
- for (int i = modes.size() - 1; i >= 0; i--) {
- const auto hwcId = i + 1;
- // Set up HWC expectations for the mode change
- if (mIs2_4Client) {
- EXPECT_CALL(*mMockComposer,
- setActiveConfigWithConstraints(hwcDisplayId, hwcId, _, _))
- .WillOnce(Return(V2_4::Error::NONE));
- } else {
- EXPECT_CALL(*mMockComposer, setActiveConfig(hwcDisplayId, hwcId))
- .WillOnce(Return(V2_1::Error::NONE));
- }
-
- EXPECT_EQ(NO_ERROR,
- SurfaceComposerClient::setDesiredDisplayModeSpecs(display, i, false,
- modes[i].refreshRate,
- modes[i].refreshRate,
- modes[i].refreshRate,
- modes[i].refreshRate));
- // We need to refresh twice - once to apply the pending mode change request,
- // and once to process the change.
- waitForDisplayTransaction(hwcDisplayId);
- waitForDisplayTransaction(hwcDisplayId);
- EXPECT_TRUE(waitForModeChangedEvent(hwcDisplayId, i))
- << "Failure while switching to mode " << i;
-
- ui::DisplayMode mode;
- EXPECT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode));
- EXPECT_EQ(ui::Size(800, 1600), mode.resolution);
- EXPECT_EQ(modes[i].refreshRate, mode.refreshRate);
- }
- }
-
- sp<V2_1::IComposer> mFakeService;
- sp<SurfaceComposerClient> mComposerClient;
-
- std::unique_ptr<MockComposerHal> mMockComposer;
- FakeComposerClient* mFakeComposerClient;
-
- std::unique_ptr<DisplayEventReceiver> mReceiver;
- sp<Looper> mLooper;
- std::deque<DisplayEventReceiver::Event> mReceivedDisplayEvents;
-
- static constexpr bool mIs2_4Client =
- std::is_same<FakeComposerService, FakeComposerService_2_4>::value;
-};
-
-using DisplayTest_2_1 = DisplayTest<FakeComposerService_2_1>;
-
-// Tests that VSYNC injection can be safely toggled while invalidating.
-TEST_F(DisplayTest_2_1, VsyncInjection) {
- const auto flinger = ComposerServiceAIDL::getComposerService();
- bool enable = true;
-
- for (int i = 0; i < 100; i++) {
- flinger->enableVSyncInjections(enable);
- enable = !enable;
-
- constexpr uint32_t kForceInvalidate = 1004;
- android::Parcel data, reply;
- data.writeInterfaceToken(String16("android.ui.ISurfaceComposer"));
- EXPECT_EQ(NO_ERROR,
- android::IInterface::asBinder(flinger)->transact(kForceInvalidate, data, &reply));
-
- std::this_thread::sleep_for(5ms);
- }
-}
-
-TEST_F(DisplayTest_2_1, HotplugOneConfig) {
- Test_HotplugOneConfig();
-}
-
-TEST_F(DisplayTest_2_1, HotplugTwoSeparateConfigs) {
- Test_HotplugTwoSeparateConfigs();
-}
-
-TEST_F(DisplayTest_2_1, HotplugTwoConfigsSameGroup) {
- Test_HotplugTwoConfigsSameGroup();
-}
-
-TEST_F(DisplayTest_2_1, HotplugThreeConfigsMixedGroups) {
- Test_HotplugThreeConfigsMixedGroups();
-}
-
-TEST_F(DisplayTest_2_1, HotplugPrimaryOneConfig) {
- Test_HotplugPrimaryDisplay();
-}
-
-TEST_F(DisplayTest_2_1, SubsequentHotplugConnectUpdatesPrimaryDisplay) {
- Test_SubsequentHotplugConnectUpdatesDisplay(PRIMARY_DISPLAY);
-}
-
-TEST_F(DisplayTest_2_1, SubsequentHotplugConnectUpdatesExternalDisplay) {
- Test_SubsequentHotplugConnectUpdatesDisplay(EXTERNAL_DISPLAY);
-}
-
-using DisplayTest_2_2 = DisplayTest<FakeComposerService_2_2>;
-
-TEST_F(DisplayTest_2_2, HotplugOneConfig) {
- Test_HotplugOneConfig();
-}
-
-TEST_F(DisplayTest_2_2, HotplugTwoSeparateConfigs) {
- Test_HotplugTwoSeparateConfigs();
-}
-
-TEST_F(DisplayTest_2_2, HotplugTwoConfigsSameGroup) {
- Test_HotplugTwoConfigsSameGroup();
-}
-
-TEST_F(DisplayTest_2_2, HotplugThreeConfigsMixedGroups) {
- Test_HotplugThreeConfigsMixedGroups();
-}
-
-TEST_F(DisplayTest_2_2, HotplugPrimaryOneConfig) {
- Test_HotplugPrimaryDisplay();
-}
-
-TEST_F(DisplayTest_2_2, SubsequentHotplugConnectUpdatesPrimaryDisplay) {
- Test_SubsequentHotplugConnectUpdatesDisplay(PRIMARY_DISPLAY);
-}
-
-TEST_F(DisplayTest_2_2, SubsequentHotplugConnectUpdatesExternalDisplay) {
- Test_SubsequentHotplugConnectUpdatesDisplay(EXTERNAL_DISPLAY);
-}
-
-using DisplayTest_2_3 = DisplayTest<FakeComposerService_2_3>;
-
-TEST_F(DisplayTest_2_3, HotplugOneConfig) {
- Test_HotplugOneConfig();
-}
-
-TEST_F(DisplayTest_2_3, HotplugTwoSeparateConfigs) {
- Test_HotplugTwoSeparateConfigs();
-}
-
-TEST_F(DisplayTest_2_3, HotplugTwoConfigsSameGroup) {
- Test_HotplugTwoConfigsSameGroup();
-}
-
-TEST_F(DisplayTest_2_3, HotplugThreeConfigsMixedGroups) {
- Test_HotplugThreeConfigsMixedGroups();
-}
-
-TEST_F(DisplayTest_2_3, HotplugPrimaryOneConfig) {
- Test_HotplugPrimaryDisplay();
-}
-
-TEST_F(DisplayTest_2_3, SubsequentHotplugConnectUpdatesPrimaryDisplay) {
- Test_SubsequentHotplugConnectUpdatesDisplay(PRIMARY_DISPLAY);
-}
-
-TEST_F(DisplayTest_2_3, SubsequentHotplugConnectUpdatesExternalDisplay) {
- Test_SubsequentHotplugConnectUpdatesDisplay(EXTERNAL_DISPLAY);
-}
-
-using DisplayTest_2_4 = DisplayTest<FakeComposerService_2_4>;
-
-TEST_F(DisplayTest_2_4, HotplugOneConfig) {
- Test_HotplugOneConfig();
-}
-
-TEST_F(DisplayTest_2_4, HotplugTwoSeparateConfigs) {
- Test_HotplugTwoSeparateConfigs();
-}
-
-TEST_F(DisplayTest_2_4, HotplugTwoConfigsSameGroup) {
- Test_HotplugTwoConfigsSameGroup();
-}
-
-TEST_F(DisplayTest_2_4, HotplugThreeConfigsMixedGroups) {
- Test_HotplugThreeConfigsMixedGroups();
-}
-
-TEST_F(DisplayTest_2_4, HotplugPrimaryOneConfig) {
- Test_HotplugPrimaryDisplay();
-}
-
-TEST_F(DisplayTest_2_4, SubsequentHotplugConnectUpdatesPrimaryDisplay) {
- Test_SubsequentHotplugConnectUpdatesDisplay(PRIMARY_DISPLAY);
-}
-
-TEST_F(DisplayTest_2_4, SubsequentHotplugConnectUpdatesExternalDisplay) {
- Test_SubsequentHotplugConnectUpdatesDisplay(EXTERNAL_DISPLAY);
-}
-
-////////////////////////////////////////////////
-
-template <typename FakeComposerService>
-class TransactionTest : public ::testing::Test {
-protected:
- // Layer array indexing constants.
- constexpr static int BG_LAYER = 0;
- constexpr static int FG_LAYER = 1;
-
- static void SetUpTestCase() {
- // TODO: See TODO comment at DisplayTest::SetUp for background on
- // the lifetime of the FakeComposerClient.
- sFakeComposer = new FakeComposerClient;
- auto client = sp<V2_4::hal::ComposerClient>::make(sFakeComposer);
- sp<V2_1::IComposer> fakeService = sp<FakeComposerService>::make(client);
- (void)fakeService->registerAsService("mock");
-
- android::hardware::ProcessState::self()->startThreadPool();
- android::ProcessState::self()->startThreadPool();
-
- startSurfaceFlinger();
-
- // Fake composer wants to enable VSync injection
- sFakeComposer->onSurfaceFlingerStart();
- }
-
- static void TearDownTestCase() {
- // Fake composer needs to release SurfaceComposerClient before the stop.
- sFakeComposer->onSurfaceFlingerStop();
- stopSurfaceFlinger();
- // TODO: This is deleted when the ComposerClient calls
- // removeClient. Devise better lifetime control.
- sFakeComposer = nullptr;
- }
-
- void SetUp() override {
- ALOGI("TransactionTest::SetUp");
- mComposerClient = sp<SurfaceComposerClient>::make();
- ASSERT_EQ(NO_ERROR, mComposerClient->initCheck());
-
- ALOGI("TransactionTest::SetUp - display");
- const auto display = SurfaceComposerClient::getPhysicalDisplayToken(kPrimaryDisplayId);
- ASSERT_FALSE(display == nullptr);
-
- ui::DisplayMode mode;
- ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(display, &mode));
-
- const ui::Size& resolution = mode.resolution;
- mDisplayWidth = resolution.getWidth();
- mDisplayHeight = resolution.getHeight();
-
- // Background surface
- mBGSurfaceControl =
- mComposerClient->createSurface(String8("BG Test Surface"), mDisplayWidth,
- mDisplayHeight, PIXEL_FORMAT_RGBA_8888, 0);
- ASSERT_TRUE(mBGSurfaceControl != nullptr);
- ASSERT_TRUE(mBGSurfaceControl->isValid());
- fillSurfaceRGBA8(mBGSurfaceControl, BLUE);
-
- // Foreground surface
- mFGSurfaceControl = mComposerClient->createSurface(String8("FG Test Surface"), 64, 64,
- PIXEL_FORMAT_RGBA_8888, 0);
- ASSERT_TRUE(mFGSurfaceControl != nullptr);
- ASSERT_TRUE(mFGSurfaceControl->isValid());
-
- fillSurfaceRGBA8(mFGSurfaceControl, RED);
-
- Transaction t;
- t.setDisplayLayerStack(display, ui::DEFAULT_LAYER_STACK);
-
- t.setLayer(mBGSurfaceControl, INT32_MAX - 2);
- t.show(mBGSurfaceControl);
-
- t.setLayer(mFGSurfaceControl, INT32_MAX - 1);
- t.setPosition(mFGSurfaceControl, 64, 64);
- t.show(mFGSurfaceControl);
-
- // Synchronous transaction will stop this thread, so we set up a
- // delayed, off-thread vsync request before closing the
- // transaction. In the test code this is usually done with
- // TransactionScope. Leaving here in the 'vanilla' form for
- // reference.
- ASSERT_EQ(0, sFakeComposer->getFrameCount());
- sFakeComposer->runVSyncAfter(1ms);
- t.apply();
- sFakeComposer->waitUntilFrame(1);
-
- // Reference data. This is what the HWC should see.
- static_assert(BG_LAYER == 0 && FG_LAYER == 1, "Unexpected enum values for array indexing");
- mBaseFrame.push_back(makeSimpleRect(0u, 0u, mDisplayWidth, mDisplayHeight));
- mBaseFrame[BG_LAYER].mSwapCount = 1;
- mBaseFrame.push_back(makeSimpleRect(64, 64, 64 + 64, 64 + 64));
- mBaseFrame[FG_LAYER].mSwapCount = 1;
-
- auto frame = sFakeComposer->getFrameRects(0);
- ASSERT_TRUE(framesAreSame(mBaseFrame, frame));
- }
-
- void TearDown() override {
- ALOGD("TransactionTest::TearDown");
-
- mComposerClient->dispose();
- mBGSurfaceControl = 0;
- mFGSurfaceControl = 0;
- mComposerClient = 0;
-
- sFakeComposer->runVSyncAndWait();
- mBaseFrame.clear();
- sFakeComposer->clearFrames();
- ASSERT_EQ(0, sFakeComposer->getFrameCount());
-
- sp<gui::ISurfaceComposer> sf(ComposerServiceAIDL::getComposerService());
- std::vector<gui::LayerDebugInfo> layers;
- binder::Status status = sf->getLayerDebugInfo(&layers);
- status_t result = gui::aidl_utils::statusTFromBinderStatus(status);
- if (result != NO_ERROR) {
- ALOGE("Failed to get layers %s %d", strerror(-result), result);
- } else {
- // If this fails, the test being torn down leaked layers.
- EXPECT_EQ(0u, layers.size());
- if (layers.size() > 0) {
- for (auto layer = layers.begin(); layer != layers.end(); ++layer) {
- std::cout << to_string(*layer).c_str();
- }
- // To ensure the next test has clean slate, will run the class
- // tear down and setup here.
- TearDownTestCase();
- SetUpTestCase();
- }
- }
- ALOGD("TransactionTest::TearDown - complete");
- }
-
- void Test_LayerMove() {
- ALOGD("TransactionTest::LayerMove");
-
- // The scope opens and closes a global transaction and, at the
- // same time, makes sure the SurfaceFlinger progresses one frame
- // after the transaction closes. The results of the transaction
- // should be available in the latest frame stored by the fake
- // composer.
- {
- TransactionScope ts(*sFakeComposer);
- ts.setPosition(mFGSurfaceControl, 128, 128);
- // NOTE: No changes yet, so vsync will do nothing, HWC does not get any calls.
- // (How to verify that? Throw in vsync and wait a 2x frame time? Separate test?)
- //
- // sFakeComposer->runVSyncAndWait();
- }
-
- fillSurfaceRGBA8(mFGSurfaceControl, GREEN);
- sFakeComposer->runVSyncAndWait();
-
- ASSERT_EQ(3, sFakeComposer->getFrameCount()); // Make sure the waits didn't time out and
- // there's no extra frames.
-
- // NOTE: Frame 0 is produced in the SetUp.
- auto frame1Ref = mBaseFrame;
- frame1Ref[FG_LAYER].mDisplayFrame =
- hwc_rect_t{128, 128, 128 + 64, 128 + 64}; // Top-most layer moves.
- EXPECT_TRUE(framesAreSame(frame1Ref, sFakeComposer->getFrameRects(1)));
-
- auto frame2Ref = frame1Ref;
- frame2Ref[FG_LAYER].mSwapCount++;
- EXPECT_TRUE(framesAreSame(frame2Ref, sFakeComposer->getFrameRects(2)));
- }
-
- void Test_LayerCrop() {
- // TODO: Add scaling to confirm that crop happens in buffer space?
- {
- TransactionScope ts(*sFakeComposer);
- Rect cropRect(16, 16, 32, 32);
- ts.setCrop(mFGSurfaceControl, cropRect);
- }
- ASSERT_EQ(2, sFakeComposer->getFrameCount());
-
- auto referenceFrame = mBaseFrame;
- referenceFrame[FG_LAYER].mSourceCrop = hwc_frect_t{16.f, 16.f, 32.f, 32.f};
- referenceFrame[FG_LAYER].mDisplayFrame = hwc_rect_t{64 + 16, 64 + 16, 64 + 32, 64 + 32};
- EXPECT_TRUE(framesAreSame(referenceFrame, sFakeComposer->getLatestFrame()));
- }
-
- void Test_LayerSetLayer() {
- {
- TransactionScope ts(*sFakeComposer);
- ts.setLayer(mFGSurfaceControl, INT_MAX - 3);
- }
- ASSERT_EQ(2, sFakeComposer->getFrameCount());
-
- // The layers will switch order, but both are rendered because the background layer is
- // transparent (RGBA8888).
- std::vector<RenderState> referenceFrame(2);
- referenceFrame[0] = mBaseFrame[FG_LAYER];
- referenceFrame[1] = mBaseFrame[BG_LAYER];
- EXPECT_TRUE(framesAreSame(referenceFrame, sFakeComposer->getLatestFrame()));
- }
-
- void Test_LayerSetLayerOpaque() {
- {
- TransactionScope ts(*sFakeComposer);
- ts.setLayer(mFGSurfaceControl, INT_MAX - 3);
- ts.setFlags(mBGSurfaceControl, layer_state_t::eLayerOpaque,
- layer_state_t::eLayerOpaque);
- }
- ASSERT_EQ(2, sFakeComposer->getFrameCount());
-
- // The former foreground layer is now covered with opaque layer - it should have disappeared
- std::vector<RenderState> referenceFrame(1);
- referenceFrame[BG_LAYER] = mBaseFrame[BG_LAYER];
- EXPECT_TRUE(framesAreSame(referenceFrame, sFakeComposer->getLatestFrame()));
- }
-
- void Test_SetLayerStack() {
- ALOGD("TransactionTest::SetLayerStack");
- {
- TransactionScope ts(*sFakeComposer);
- ts.setLayerStack(mFGSurfaceControl, ui::LayerStack{1});
- }
-
- // Foreground layer should have disappeared.
- ASSERT_EQ(2, sFakeComposer->getFrameCount());
- std::vector<RenderState> refFrame(1);
- refFrame[BG_LAYER] = mBaseFrame[BG_LAYER];
- EXPECT_TRUE(framesAreSame(refFrame, sFakeComposer->getLatestFrame()));
- }
-
- void Test_LayerShowHide() {
- ALOGD("TransactionTest::LayerShowHide");
- {
- TransactionScope ts(*sFakeComposer);
- ts.hide(mFGSurfaceControl);
- }
-
- // Foreground layer should have disappeared.
- ASSERT_EQ(2, sFakeComposer->getFrameCount());
- std::vector<RenderState> refFrame(1);
- refFrame[BG_LAYER] = mBaseFrame[BG_LAYER];
- EXPECT_TRUE(framesAreSame(refFrame, sFakeComposer->getLatestFrame()));
-
- {
- TransactionScope ts(*sFakeComposer);
- ts.show(mFGSurfaceControl);
- }
-
- // Foreground layer should be back
- ASSERT_EQ(3, sFakeComposer->getFrameCount());
- EXPECT_TRUE(framesAreSame(mBaseFrame, sFakeComposer->getLatestFrame()));
- }
-
- void Test_LayerSetAlpha() {
- {
- TransactionScope ts(*sFakeComposer);
- ts.setAlpha(mFGSurfaceControl, 0.75f);
- }
-
- ASSERT_EQ(2, sFakeComposer->getFrameCount());
- auto referenceFrame = mBaseFrame;
- referenceFrame[FG_LAYER].mPlaneAlpha = 0.75f;
- EXPECT_TRUE(framesAreSame(referenceFrame, sFakeComposer->getLatestFrame()));
- }
-
- void Test_LayerSetFlags() {
- {
- TransactionScope ts(*sFakeComposer);
- ts.setFlags(mFGSurfaceControl, layer_state_t::eLayerHidden,
- layer_state_t::eLayerHidden);
- }
-
- // Foreground layer should have disappeared.
- ASSERT_EQ(2, sFakeComposer->getFrameCount());
- std::vector<RenderState> refFrame(1);
- refFrame[BG_LAYER] = mBaseFrame[BG_LAYER];
- EXPECT_TRUE(framesAreSame(refFrame, sFakeComposer->getLatestFrame()));
- }
-
- void Test_LayerSetMatrix() {
- struct matrixTestData {
- float matrix[4];
- hwc_transform_t expectedTransform;
- hwc_rect_t expectedDisplayFrame;
- };
-
- // The matrix operates on the display frame and is applied before
- // the position is added. So, the foreground layer rect is (0, 0,
- // 64, 64) is first transformed, potentially yielding negative
- // coordinates and then the position (64, 64) is added yielding
- // the final on-screen rectangles given.
-
- const matrixTestData MATRIX_TESTS[7] = // clang-format off
- {{{-1.f, 0.f, 0.f, 1.f}, HWC_TRANSFORM_FLIP_H, {0, 64, 64, 128}},
- {{1.f, 0.f, 0.f, -1.f}, HWC_TRANSFORM_FLIP_V, {64, 0, 128, 64}},
- {{0.f, 1.f, -1.f, 0.f}, HWC_TRANSFORM_ROT_90, {0, 64, 64, 128}},
- {{-1.f, 0.f, 0.f, -1.f}, HWC_TRANSFORM_ROT_180, {0, 0, 64, 64}},
- {{0.f, -1.f, 1.f, 0.f}, HWC_TRANSFORM_ROT_270, {64, 0, 128, 64}},
- {{0.f, 1.f, 1.f, 0.f}, HWC_TRANSFORM_FLIP_H_ROT_90, {64, 64, 128, 128}},
- {{0.f, 1.f, 1.f, 0.f}, HWC_TRANSFORM_FLIP_V_ROT_90, {64, 64, 128, 128}}};
- // clang-format on
- constexpr int TEST_COUNT = sizeof(MATRIX_TESTS) / sizeof(matrixTestData);
-
- for (int i = 0; i < TEST_COUNT; i++) {
- // TODO: How to leverage the HWC2 stringifiers?
- const matrixTestData& xform = MATRIX_TESTS[i];
- SCOPED_TRACE(i);
- {
- TransactionScope ts(*sFakeComposer);
- ts.setMatrix(mFGSurfaceControl, xform.matrix[0], xform.matrix[1], xform.matrix[2],
- xform.matrix[3]);
- }
-
- auto referenceFrame = mBaseFrame;
- referenceFrame[FG_LAYER].mTransform = xform.expectedTransform;
- referenceFrame[FG_LAYER].mDisplayFrame = xform.expectedDisplayFrame;
-
- EXPECT_TRUE(framesAreSame(referenceFrame, sFakeComposer->getLatestFrame()));
- }
- }
-
- void Test_SetRelativeLayer() {
- constexpr int RELATIVE_LAYER = 2;
- auto relativeSurfaceControl = mComposerClient->createSurface(String8("Test Surface"), 64,
- 64, PIXEL_FORMAT_RGBA_8888, 0);
- fillSurfaceRGBA8(relativeSurfaceControl, LIGHT_RED);
-
- // Now we stack the surface above the foreground surface and make sure it is visible.
- {
- TransactionScope ts(*sFakeComposer);
- ts.setPosition(relativeSurfaceControl, 64, 64);
- ts.show(relativeSurfaceControl);
- ts.setRelativeLayer(relativeSurfaceControl, mFGSurfaceControl, 1);
- }
- auto referenceFrame = mBaseFrame;
- // NOTE: All three layers will be visible as the surfaces are
- // transparent because of the RGBA format.
- referenceFrame.push_back(makeSimpleRect(64, 64, 64 + 64, 64 + 64));
- referenceFrame[RELATIVE_LAYER].mSwapCount = 1;
- EXPECT_TRUE(framesAreSame(referenceFrame, sFakeComposer->getLatestFrame()));
-
- // A call to setLayer will override a call to setRelativeLayer
- {
- TransactionScope ts(*sFakeComposer);
- ts.setLayer(relativeSurfaceControl, 0);
- }
-
- // Previous top layer will now appear at the bottom.
- auto referenceFrame2 = mBaseFrame;
- referenceFrame2.insert(referenceFrame2.begin(), referenceFrame[RELATIVE_LAYER]);
- EXPECT_EQ(3, sFakeComposer->getFrameCount());
- EXPECT_TRUE(framesAreSame(referenceFrame2, sFakeComposer->getLatestFrame()));
- }
-
- sp<SurfaceComposerClient> mComposerClient;
- sp<SurfaceControl> mBGSurfaceControl;
- sp<SurfaceControl> mFGSurfaceControl;
- std::vector<RenderState> mBaseFrame;
- uint32_t mDisplayWidth;
- uint32_t mDisplayHeight;
-
- static inline FakeComposerClient* sFakeComposer;
-};
-
-using TransactionTest_2_1 = TransactionTest<FakeComposerService_2_1>;
-
-TEST_F(TransactionTest_2_1, DISABLED_LayerMove) {
- Test_LayerMove();
-}
-
-TEST_F(TransactionTest_2_1, DISABLED_LayerCrop) {
- Test_LayerCrop();
-}
-
-TEST_F(TransactionTest_2_1, DISABLED_LayerSetLayer) {
- Test_LayerSetLayer();
-}
-
-TEST_F(TransactionTest_2_1, DISABLED_LayerSetLayerOpaque) {
- Test_LayerSetLayerOpaque();
-}
-
-TEST_F(TransactionTest_2_1, DISABLED_SetLayerStack) {
- Test_SetLayerStack();
-}
-
-TEST_F(TransactionTest_2_1, DISABLED_LayerShowHide) {
- Test_LayerShowHide();
-}
-
-TEST_F(TransactionTest_2_1, DISABLED_LayerSetAlpha) {
- Test_LayerSetAlpha();
-}
-
-TEST_F(TransactionTest_2_1, DISABLED_LayerSetFlags) {
- Test_LayerSetFlags();
-}
-
-TEST_F(TransactionTest_2_1, DISABLED_LayerSetMatrix) {
- Test_LayerSetMatrix();
-}
-
-TEST_F(TransactionTest_2_1, DISABLED_SetRelativeLayer) {
- Test_SetRelativeLayer();
-}
-
-template <typename FakeComposerService>
-class ChildLayerTest : public TransactionTest<FakeComposerService> {
- using Base = TransactionTest<FakeComposerService>;
-
-protected:
- constexpr static int CHILD_LAYER = 2;
-
- void SetUp() override {
- Base::SetUp();
- mChild = Base::mComposerClient->createSurface(String8("Child surface"), 10, 10,
- PIXEL_FORMAT_RGBA_8888, 0,
- Base::mFGSurfaceControl->getHandle());
- fillSurfaceRGBA8(mChild, LIGHT_GRAY);
-
- Base::sFakeComposer->runVSyncAndWait();
- Base::mBaseFrame.push_back(makeSimpleRect(64, 64, 64 + 10, 64 + 10));
- Base::mBaseFrame[CHILD_LAYER].mSwapCount = 1;
- ASSERT_EQ(2, Base::sFakeComposer->getFrameCount());
- ASSERT_TRUE(framesAreSame(Base::mBaseFrame, Base::sFakeComposer->getLatestFrame()));
- }
-
- void TearDown() override {
- mChild = 0;
- Base::TearDown();
- }
-
- void Test_Positioning() {
- {
- TransactionScope ts(*Base::sFakeComposer);
- ts.show(mChild);
- ts.setPosition(mChild, 10, 10);
- // Move to the same position as in the original setup.
- ts.setPosition(Base::mFGSurfaceControl, 64, 64);
- }
-
- auto referenceFrame = Base::mBaseFrame;
- referenceFrame[Base::FG_LAYER].mDisplayFrame = hwc_rect_t{64, 64, 64 + 64, 64 + 64};
- referenceFrame[CHILD_LAYER].mDisplayFrame =
- hwc_rect_t{64 + 10, 64 + 10, 64 + 10 + 10, 64 + 10 + 10};
- EXPECT_TRUE(framesAreSame(referenceFrame, Base::sFakeComposer->getLatestFrame()));
-
- {
- TransactionScope ts(*Base::sFakeComposer);
- ts.setPosition(Base::mFGSurfaceControl, 0, 0);
- }
-
- auto referenceFrame2 = Base::mBaseFrame;
- referenceFrame2[Base::FG_LAYER].mDisplayFrame = hwc_rect_t{0, 0, 0 + 64, 0 + 64};
- referenceFrame2[CHILD_LAYER].mDisplayFrame =
- hwc_rect_t{0 + 10, 0 + 10, 0 + 10 + 10, 0 + 10 + 10};
- EXPECT_TRUE(framesAreSame(referenceFrame2, Base::sFakeComposer->getLatestFrame()));
- }
-
- void Test_Cropping() {
- {
- TransactionScope ts(*Base::sFakeComposer);
- ts.show(mChild);
- ts.setPosition(mChild, 0, 0);
- ts.setPosition(Base::mFGSurfaceControl, 0, 0);
- ts.setCrop(Base::mFGSurfaceControl, Rect(0, 0, 5, 5));
- }
- // NOTE: The foreground surface would be occluded by the child
- // now, but is included in the stack because the child is
- // transparent.
- auto referenceFrame = Base::mBaseFrame;
- referenceFrame[Base::FG_LAYER].mDisplayFrame = hwc_rect_t{0, 0, 0 + 5, 0 + 5};
- referenceFrame[Base::FG_LAYER].mSourceCrop = hwc_frect_t{0.f, 0.f, 5.f, 5.f};
- referenceFrame[CHILD_LAYER].mDisplayFrame = hwc_rect_t{0, 0, 0 + 5, 0 + 5};
- referenceFrame[CHILD_LAYER].mSourceCrop = hwc_frect_t{0.f, 0.f, 5.f, 5.f};
- EXPECT_TRUE(framesAreSame(referenceFrame, Base::sFakeComposer->getLatestFrame()));
- }
-
- void Test_Constraints() {
- {
- TransactionScope ts(*Base::sFakeComposer);
- ts.show(mChild);
- ts.setPosition(Base::mFGSurfaceControl, 0, 0);
- ts.setPosition(mChild, 63, 63);
- }
- auto referenceFrame = Base::mBaseFrame;
- referenceFrame[Base::FG_LAYER].mDisplayFrame = hwc_rect_t{0, 0, 64, 64};
- referenceFrame[CHILD_LAYER].mDisplayFrame = hwc_rect_t{63, 63, 64, 64};
- referenceFrame[CHILD_LAYER].mSourceCrop = hwc_frect_t{0.f, 0.f, 1.f, 1.f};
- EXPECT_TRUE(framesAreSame(referenceFrame, Base::sFakeComposer->getLatestFrame()));
- }
-
- void Test_Scaling() {
- {
- TransactionScope ts(*Base::sFakeComposer);
- ts.setPosition(Base::mFGSurfaceControl, 0, 0);
- }
- auto referenceFrame = Base::mBaseFrame;
- referenceFrame[Base::FG_LAYER].mDisplayFrame = hwc_rect_t{0, 0, 64, 64};
- referenceFrame[CHILD_LAYER].mDisplayFrame = hwc_rect_t{0, 0, 10, 10};
- EXPECT_TRUE(framesAreSame(referenceFrame, Base::sFakeComposer->getLatestFrame()));
-
- {
- TransactionScope ts(*Base::sFakeComposer);
- ts.setMatrix(Base::mFGSurfaceControl, 2.0, 0, 0, 2.0);
- }
-
- auto referenceFrame2 = Base::mBaseFrame;
- referenceFrame2[Base::FG_LAYER].mDisplayFrame = hwc_rect_t{0, 0, 128, 128};
- referenceFrame2[CHILD_LAYER].mDisplayFrame = hwc_rect_t{0, 0, 20, 20};
- EXPECT_TRUE(framesAreSame(referenceFrame2, Base::sFakeComposer->getLatestFrame()));
- }
-
- void Test_LayerAlpha() {
- {
- TransactionScope ts(*Base::sFakeComposer);
- ts.show(mChild);
- ts.setPosition(mChild, 0, 0);
- ts.setPosition(Base::mFGSurfaceControl, 0, 0);
- ts.setAlpha(mChild, 0.5);
- }
-
- auto referenceFrame = Base::mBaseFrame;
- referenceFrame[Base::FG_LAYER].mDisplayFrame = hwc_rect_t{0, 0, 64, 64};
- referenceFrame[CHILD_LAYER].mDisplayFrame = hwc_rect_t{0, 0, 10, 10};
- referenceFrame[CHILD_LAYER].mPlaneAlpha = 0.5f;
- EXPECT_TRUE(framesAreSame(referenceFrame, Base::sFakeComposer->getLatestFrame()));
-
- {
- TransactionScope ts(*Base::sFakeComposer);
- ts.setAlpha(Base::mFGSurfaceControl, 0.5);
- }
-
- auto referenceFrame2 = referenceFrame;
- referenceFrame2[Base::FG_LAYER].mPlaneAlpha = 0.5f;
- referenceFrame2[CHILD_LAYER].mPlaneAlpha = 0.25f;
- EXPECT_TRUE(framesAreSame(referenceFrame2, Base::sFakeComposer->getLatestFrame()));
- }
-
- sp<SurfaceControl> mChild;
-};
-
-using ChildLayerTest_2_1 = ChildLayerTest<FakeComposerService_2_1>;
-
-TEST_F(ChildLayerTest_2_1, DISABLED_Positioning) {
- Test_Positioning();
-}
-
-TEST_F(ChildLayerTest_2_1, DISABLED_Cropping) {
- Test_Cropping();
-}
-
-TEST_F(ChildLayerTest_2_1, DISABLED_Constraints) {
- Test_Constraints();
-}
-
-TEST_F(ChildLayerTest_2_1, DISABLED_Scaling) {
- Test_Scaling();
-}
-
-TEST_F(ChildLayerTest_2_1, DISABLED_LayerAlpha) {
- Test_LayerAlpha();
-}
-
-template <typename FakeComposerService>
-class ChildColorLayerTest : public ChildLayerTest<FakeComposerService> {
- using Base = ChildLayerTest<FakeComposerService>;
-
-protected:
- void SetUp() override {
- Base::SetUp();
- Base::mChild =
- Base::mComposerClient->createSurface(String8("Child surface"), 0, 0,
- PIXEL_FORMAT_RGBA_8888,
- ISurfaceComposerClient::eFXSurfaceEffect,
- Base::mFGSurfaceControl->getHandle());
- {
- TransactionScope ts(*Base::sFakeComposer);
- ts.setColor(Base::mChild,
- {LIGHT_GRAY.r / 255.0f, LIGHT_GRAY.g / 255.0f, LIGHT_GRAY.b / 255.0f});
- ts.setCrop(Base::mChild, Rect(0, 0, 10, 10));
- }
-
- Base::sFakeComposer->runVSyncAndWait();
- Base::mBaseFrame.push_back(makeSimpleRect(64, 64, 64 + 10, 64 + 10));
- Base::mBaseFrame[Base::CHILD_LAYER].mSourceCrop = hwc_frect_t{0.0f, 0.0f, 0.0f, 0.0f};
- Base::mBaseFrame[Base::CHILD_LAYER].mSwapCount = 0;
- ASSERT_EQ(2, Base::sFakeComposer->getFrameCount());
- ASSERT_TRUE(framesAreSame(Base::mBaseFrame, Base::sFakeComposer->getLatestFrame()));
- }
-
- void Test_LayerAlpha() {
- {
- TransactionScope ts(*Base::sFakeComposer);
- ts.show(Base::mChild);
- ts.setPosition(Base::mChild, 0, 0);
- ts.setPosition(Base::mFGSurfaceControl, 0, 0);
- ts.setAlpha(Base::mChild, 0.5);
- }
-
- auto referenceFrame = Base::mBaseFrame;
- referenceFrame[Base::FG_LAYER].mDisplayFrame = hwc_rect_t{0, 0, 64, 64};
- referenceFrame[Base::CHILD_LAYER].mDisplayFrame = hwc_rect_t{0, 0, 10, 10};
- referenceFrame[Base::CHILD_LAYER].mPlaneAlpha = 0.5f;
- EXPECT_TRUE(framesAreSame(referenceFrame, Base::sFakeComposer->getLatestFrame()));
-
- {
- TransactionScope ts(*Base::sFakeComposer);
- ts.setAlpha(Base::mFGSurfaceControl, 0.5);
- }
-
- auto referenceFrame2 = referenceFrame;
- referenceFrame2[Base::FG_LAYER].mPlaneAlpha = 0.5f;
- referenceFrame2[Base::CHILD_LAYER].mPlaneAlpha = 0.25f;
- EXPECT_TRUE(framesAreSame(referenceFrame2, Base::sFakeComposer->getLatestFrame()));
- }
-
- void Test_LayerZeroAlpha() {
- {
- TransactionScope ts(*Base::sFakeComposer);
- ts.show(Base::mChild);
- ts.setPosition(Base::mChild, 0, 0);
- ts.setPosition(Base::mFGSurfaceControl, 0, 0);
- ts.setAlpha(Base::mChild, 0.5);
- }
-
- auto referenceFrame = Base::mBaseFrame;
- referenceFrame[Base::FG_LAYER].mDisplayFrame = hwc_rect_t{0, 0, 64, 64};
- referenceFrame[Base::CHILD_LAYER].mDisplayFrame = hwc_rect_t{0, 0, 10, 10};
- referenceFrame[Base::CHILD_LAYER].mPlaneAlpha = 0.5f;
- EXPECT_TRUE(framesAreSame(referenceFrame, Base::sFakeComposer->getLatestFrame()));
-
- {
- TransactionScope ts(*Base::sFakeComposer);
- ts.setAlpha(Base::mFGSurfaceControl, 0.0f);
- }
-
- std::vector<RenderState> refFrame(1);
- refFrame[Base::BG_LAYER] = Base::mBaseFrame[Base::BG_LAYER];
-
- EXPECT_TRUE(framesAreSame(refFrame, Base::sFakeComposer->getLatestFrame()));
- }
-};
-
-using ChildColorLayerTest_2_1 = ChildColorLayerTest<FakeComposerService_2_1>;
-
-TEST_F(ChildColorLayerTest_2_1, DISABLED_LayerAlpha) {
- Test_LayerAlpha();
-}
-
-TEST_F(ChildColorLayerTest_2_1, DISABLED_LayerZeroAlpha) {
- Test_LayerZeroAlpha();
-}
-} // namespace
-
-int main(int argc, char** argv) {
- ::testing::InitGoogleTest(&argc, argv);
-
- auto* fakeEnvironment = new sftest::FakeHwcEnvironment;
- ::testing::AddGlobalTestEnvironment(fakeEnvironment);
- ::testing::InitGoogleMock(&argc, argv);
- return RUN_ALL_TESTS();
-}
-
-// TODO(b/129481165): remove the #pragma below and fix conversion issues
-#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
diff --git a/services/surfaceflinger/tests/unittests/FrameTimelineTest.cpp b/services/surfaceflinger/tests/unittests/FrameTimelineTest.cpp
index 874fa7c..f47ac6d 100644
--- a/services/surfaceflinger/tests/unittests/FrameTimelineTest.cpp
+++ b/services/surfaceflinger/tests/unittests/FrameTimelineTest.cpp
@@ -480,7 +480,7 @@
addEmptyDisplayFrame();
auto displayFrame0 = getDisplayFrame(0);
- EXPECT_EQ(displayFrame0->getActuals().presentTime, -1);
+ EXPECT_EQ(displayFrame0->getActuals().presentTime, 59);
EXPECT_EQ(displayFrame0->getJankType(), JankType::Unknown);
EXPECT_EQ(surfaceFrame1->getActuals().presentTime, -1);
EXPECT_EQ(surfaceFrame1->getJankType(), JankType::Unknown);
@@ -2228,6 +2228,50 @@
EXPECT_EQ(displayFrame2->getJankType(), JankType::SurfaceFlingerCpuDeadlineMissed);
}
+TEST_F(FrameTimelineTest, jankClassification_presentFenceError) {
+ auto erroneousPresentFence1 = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
+ auto erroneousPresentFence2 = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
+ auto validPresentFence = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
+ int64_t sfToken1 = mTokenManager->generateTokenForPredictions({22, 26, 40});
+ int64_t sfToken2 = mTokenManager->generateTokenForPredictions({52, 60, 60});
+ int64_t sfToken3 = mTokenManager->generateTokenForPredictions({72, 80, 80});
+
+ mFrameTimeline->setSfWakeUp(sfToken1, 22, Fps::fromPeriodNsecs(11));
+ mFrameTimeline->setSfPresent(26, erroneousPresentFence1);
+
+ mFrameTimeline->setSfWakeUp(sfToken2, 52, Fps::fromPeriodNsecs(11));
+ mFrameTimeline->setSfPresent(60, erroneousPresentFence2);
+
+ mFrameTimeline->setSfWakeUp(sfToken3, 72, Fps::fromPeriodNsecs(11));
+ mFrameTimeline->setSfPresent(80, validPresentFence);
+
+ validPresentFence->signalForTest(80);
+
+ addEmptyDisplayFrame();
+
+ {
+ auto displayFrame = getDisplayFrame(0);
+ EXPECT_EQ(displayFrame->getActuals().presentTime, 26);
+ EXPECT_EQ(displayFrame->getFramePresentMetadata(), FramePresentMetadata::UnknownPresent);
+ EXPECT_EQ(displayFrame->getFrameReadyMetadata(), FrameReadyMetadata::UnknownFinish);
+ EXPECT_EQ(displayFrame->getJankType(), JankType::Unknown);
+ }
+ {
+ auto displayFrame = getDisplayFrame(1);
+ EXPECT_EQ(displayFrame->getActuals().presentTime, 60);
+ EXPECT_EQ(displayFrame->getFramePresentMetadata(), FramePresentMetadata::UnknownPresent);
+ EXPECT_EQ(displayFrame->getFrameReadyMetadata(), FrameReadyMetadata::UnknownFinish);
+ EXPECT_EQ(displayFrame->getJankType(), JankType::Unknown);
+ }
+ {
+ auto displayFrame = getDisplayFrame(2);
+ EXPECT_EQ(displayFrame->getActuals().presentTime, 80);
+ EXPECT_EQ(displayFrame->getFramePresentMetadata(), FramePresentMetadata::OnTimePresent);
+ EXPECT_EQ(displayFrame->getFrameReadyMetadata(), FrameReadyMetadata::OnTimeFinish);
+ EXPECT_EQ(displayFrame->getJankType(), JankType::None);
+ }
+}
+
TEST_F(FrameTimelineTest, computeFps_noLayerIds_returnsZero) {
EXPECT_EQ(mFrameTimeline->computeFps({}), 0.0f);
}
diff --git a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp
index 8d2130f..406d2bc 100644
--- a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp
+++ b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp
@@ -65,6 +65,7 @@
static inline const DisplayModePtr kMode120_1 = createDisplayMode(DisplayModeId(1), 120_Hz);
static inline const DisplayModePtr kMode60_2 = createDisplayMode(DisplayModeId(2), 60_Hz);
static inline const DisplayModePtr kMode120_2 = createDisplayMode(DisplayModeId(3), 120_Hz);
+ static inline const DisplayModePtr kMode60_3 = createDisplayMode(DisplayModeId(4), 60_Hz);
std::shared_ptr<RefreshRateConfigs> mConfigs =
std::make_shared<RefreshRateConfigs>(makeModes(kMode60_1), kMode60_1->getId());
@@ -305,7 +306,7 @@
mScheduler->registerDisplay(display1);
mScheduler->registerDisplay(display2);
- const std::vector<sp<DisplayDevice>>& expectedDisplays = {display1, display2};
+ std::vector<sp<DisplayDevice>> expectedDisplays = {display1, display2};
std::vector<RefreshRateConfigs::LayerRequirement> layers = {{.weight = 1.f}, {.weight = 1.f}};
GlobalSignals globalSignals = {.idle = true};
std::vector<DisplayModeConfig> expectedConfigs = {DisplayModeConfig{globalSignals, kMode60_1},
@@ -350,6 +351,32 @@
<< displayModeConfigs.at(i).displayModePtr->getFps().getIntValue();
EXPECT_EQ(globalSignals, displayModeConfigs.at(i).signals);
}
+
+ // Filters out the 120Hz as it's not present on the display3, even with touch active
+ // we select 60Hz here.
+ auto display3 = mFakeDisplayInjector.injectDefaultInternalDisplay(
+ [&](FakeDisplayDeviceInjector& injector) {
+ injector.setDisplayModes(makeModes(kMode60_3), kMode60_3->getId());
+ },
+ mFlinger, /* port */ 252u);
+ mScheduler->registerDisplay(display3);
+
+ expectedDisplays = {display1, display2, display3};
+ globalSignals = {.touch = true};
+ mScheduler->replaceTouchTimer(10);
+ expectedConfigs = std::vector<DisplayModeConfig>{DisplayModeConfig{globalSignals, kMode60_1},
+ DisplayModeConfig{globalSignals, kMode60_2},
+ DisplayModeConfig{globalSignals, kMode60_3}};
+ mScheduler->setTouchStateAndIdleTimerPolicy(globalSignals);
+ displayModeConfigs = mScheduler->getBestDisplayModeConfigs();
+ ASSERT_EQ(expectedConfigs.size(), displayModeConfigs.size());
+ for (size_t i = 0; i < expectedConfigs.size(); ++i) {
+ EXPECT_EQ(expectedConfigs.at(i).displayModePtr, displayModeConfigs.at(i).displayModePtr)
+ << "Expected fps " << expectedConfigs.at(i).displayModePtr->getFps().getIntValue()
+ << " Actual fps "
+ << displayModeConfigs.at(i).displayModePtr->getFps().getIntValue();
+ EXPECT_EQ(globalSignals, displayModeConfigs.at(i).signals);
+ }
}
} // namespace android::scheduler