Merge "Add unit tests for android::compositionengine::impl::planner::Flattener" into sc-dev
diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp
index 3a2c769..a999c9f 100644
--- a/cmds/dumpstate/dumpstate.cpp
+++ b/cmds/dumpstate/dumpstate.cpp
@@ -2414,7 +2414,9 @@
static void Vibrate(int duration_ms) {
// clang-format off
- RunCommand("", {"cmd", "vibrator", "vibrate", "-f", std::to_string(duration_ms), "dumpstate"},
+ std::vector<std::string> args = {"cmd", "vibrator_manager", "synced", "-f", "-d", "dumpstate",
+ "oneshot", std::to_string(duration_ms)};
+ RunCommand("", args,
CommandOptions::WithTimeout(10)
.Log("Vibrate: '%s'\n")
.Always()
@@ -2909,6 +2911,10 @@
// own activity pushes out interesting data from the trace ring buffer.
// The trace file is added to the zip by MaybeAddSystemTraceToZip().
MaybeSnapshotSystemTrace();
+
+ // If a winscope trace is running, snapshot it now. It will be pulled into bugreport later
+ // from WMTRACE_DATA_DIR.
+ MaybeSnapshotWinTrace();
}
onUiIntensiveBugreportDumpsFinished(calling_uid);
MaybeCheckUserConsent(calling_uid, calling_package);
@@ -3020,6 +3026,14 @@
// file in the later stages.
}
+void Dumpstate::MaybeSnapshotWinTrace() {
+ RunCommand(
+ // Empty name because it's not intended to be classified as a bugreport section.
+ // Actual tracing files can be found in "/data/misc/wmtrace/" in the bugreport.
+ "", {"cmd", "window", "tracing", "save-for-bugreport"},
+ CommandOptions::WithTimeout(10).Always().DropRoot().RedirectStderr().Build());
+}
+
void Dumpstate::onUiIntensiveBugreportDumpsFinished(int32_t calling_uid) {
if (calling_uid == AID_SHELL || !CalledByApi()) {
return;
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h
index f83968b..83e6787 100644
--- a/cmds/dumpstate/dumpstate.h
+++ b/cmds/dumpstate/dumpstate.h
@@ -549,6 +549,7 @@
void MaybeTakeEarlyScreenshot();
void MaybeSnapshotSystemTrace();
+ void MaybeSnapshotWinTrace();
void onUiIntensiveBugreportDumpsFinished(int32_t calling_uid);
diff --git a/cmds/installd/otapreopt.cpp b/cmds/installd/otapreopt.cpp
index ef052bd..ed31ad9 100644
--- a/cmds/installd/otapreopt.cpp
+++ b/cmds/installd/otapreopt.cpp
@@ -175,8 +175,10 @@
private:
bool ReadSystemProperties() {
+ // TODO This file does not have a stable format. It should be read by
+ // code shared by init and otapreopt. See b/181182967#comment80
static constexpr const char* kPropertyFiles[] = {
- "/default.prop", "/system/build.prop"
+ "/system/build.prop"
};
for (size_t i = 0; i < arraysize(kPropertyFiles); ++i) {
@@ -193,28 +195,38 @@
// export NAME VALUE
// For simplicity, don't respect string quotation. The values we are interested in can be
// encoded without them.
+ // init.environ.rc and etc/classpath have the same format for
+ // environment variable exports and can be matched by the same regex.
+ // TODO Just like with the system-properties above we really should have
+ // common code between init and otapreopt to deal with reading these
+ // things. See b/181182967
+ static constexpr const char* kEnvironmentVariableSources[] = {
+ "/init.environ.rc", "/etc/classpath"
+ };
+
std::regex export_regex("\\s*export\\s+(\\S+)\\s+(\\S+)");
- bool parse_result = ParseFile("/init.environ.rc", [&](const std::string& line) {
- std::smatch export_match;
- if (!std::regex_match(line, export_match, export_regex)) {
+ for (const char* env_vars_file : kEnvironmentVariableSources) {
+ bool parse_result = ParseFile(env_vars_file, [&](const std::string& line) {
+ std::smatch export_match;
+ if (!std::regex_match(line, export_match, export_regex)) {
+ return true;
+ }
+
+ if (export_match.size() != 3) {
+ return true;
+ }
+
+ std::string name = export_match[1].str();
+ std::string value = export_match[2].str();
+
+ system_properties_.SetProperty(name, value);
+
return true;
+ });
+ if (!parse_result) {
+ return false;
}
-
- if (export_match.size() != 3) {
- return true;
- }
-
- std::string name = export_match[1].str();
- std::string value = export_match[2].str();
-
- system_properties_.SetProperty(name, value);
-
- return true;
- });
- if (!parse_result) {
- return false;
}
-
if (system_properties_.GetProperty(kAndroidDataPathPropertyName) == nullptr) {
return false;
}
@@ -337,9 +349,6 @@
}
}
- // Clear cached artifacts.
- ClearDirectory(isa_path);
-
// Check whether we have a boot image.
// TODO: check that the files are correct wrt/ jars.
std::string preopted_boot_art_path =
@@ -383,37 +392,6 @@
return false;
}
- static void ClearDirectory(const std::string& dir) {
- DIR* c_dir = opendir(dir.c_str());
- if (c_dir == nullptr) {
- PLOG(WARNING) << "Unable to open " << dir << " to delete it's contents";
- return;
- }
-
- for (struct dirent* de = readdir(c_dir); de != nullptr; de = readdir(c_dir)) {
- const char* name = de->d_name;
- if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
- continue;
- }
- // We only want to delete regular files and symbolic links.
- std::string file = StringPrintf("%s/%s", dir.c_str(), name);
- if (de->d_type != DT_REG && de->d_type != DT_LNK) {
- LOG(WARNING) << "Unexpected file "
- << file
- << " of type "
- << std::hex
- << de->d_type
- << " encountered.";
- } else {
- // Try to unlink the file.
- if (unlink(file.c_str()) != 0) {
- PLOG(ERROR) << "Unable to unlink " << file;
- }
- }
- }
- CHECK_EQ(0, closedir(c_dir)) << "Unable to close directory.";
- }
-
static const char* ParseNull(const char* arg) {
return (strcmp(arg, "!") == 0) ? nullptr : arg;
}
diff --git a/cmds/installd/otapreopt_chroot.cpp b/cmds/installd/otapreopt_chroot.cpp
index 72c03bf..379cf92 100644
--- a/cmds/installd/otapreopt_chroot.cpp
+++ b/cmds/installd/otapreopt_chroot.cpp
@@ -20,14 +20,19 @@
#include <sys/stat.h>
#include <sys/wait.h>
+#include <fstream>
#include <sstream>
+#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/macros.h>
#include <android-base/stringprintf.h>
+#include <android-base/unique_fd.h>
#include <libdm/dm.h>
#include <selinux/android.h>
+#include <apex_file_repository.h>
+#include <apex_constants.h>
#include <apexd.h>
#include "installd_constants.h"
@@ -64,15 +69,34 @@
// system/apex/apexd/apexd.cpp.
//
// Only scan the APEX directory under /system, /system_ext and /vendor (within the chroot dir).
- std::vector<const char*> apex_dirs{apex::kApexPackageSystemDir, apex::kApexPackageSystemExtDir,
+ std::vector<std::string> apex_dirs{apex::kApexPackageSystemDir, apex::kApexPackageSystemExtDir,
apex::kApexPackageVendorDir};
+ // Initialize ApexFileRepository used internally in ScanPackagesDirAndActivate.
+ // This is a quick fix to fix apex activation in otapreopt_chroot.
+ apex::ApexFileRepository::GetInstance().AddPreInstalledApex(apex_dirs);
for (const auto& dir : apex_dirs) {
// Cast call to void to suppress warn_unused_result.
- static_cast<void>(apex::ScanPackagesDirAndActivate(dir));
+ static_cast<void>(apex::ScanPackagesDirAndActivate(dir.c_str()));
}
return apex::GetActivePackages();
}
+static void CreateApexInfoList(const std::vector<apex::ApexFile>& apex_files) {
+ // Setup the apex-info-list.xml file
+ const std::string apex_info_file = std::string(apex::kApexRoot) + "/" + apex::kApexInfoList;
+ std::fstream xml(apex_info_file.c_str(), std::ios::out | std::ios::trunc);
+ if (!xml.is_open()) {
+ PLOG(ERROR) << "Failed to open " << apex_info_file;
+ exit(216);
+ }
+
+ // we do not care about inactive apexs
+ std::vector<apex::ApexFile> inactive;
+ apex::CollectApexInfoList(xml, apex_files, inactive);
+ xml.flush();
+ xml.close();
+}
+
static void DeactivateApexPackages(const std::vector<apex::ApexFile>& active_packages) {
for (const apex::ApexFile& apex_file : active_packages) {
const std::string& package_path = apex_file.GetPath();
@@ -181,6 +205,13 @@
// want it for product APKs. Same notes as vendor above.
TryExtraMount("product", arg[2], "/postinstall/product");
+ constexpr const char* kPostInstallLinkerconfig = "/postinstall/linkerconfig";
+ // Try to mount /postinstall/linkerconfig. we will set it up after performing the chroot
+ if (mount("tmpfs", kPostInstallLinkerconfig, "tmpfs", 0, nullptr) != 0) {
+ PLOG(ERROR) << "Failed to mount a tmpfs for " << kPostInstallLinkerconfig;
+ exit(215);
+ }
+
// Setup APEX mount point and its security context.
static constexpr const char* kPostinstallApexDir = "/postinstall/apex";
// The following logic is similar to the one in system/core/rootdir/init.rc:
@@ -239,17 +270,37 @@
// Try to mount APEX packages in "/apex" in the chroot dir. We need at least
// the ART APEX, as it is required by otapreopt to run dex2oat.
std::vector<apex::ApexFile> active_packages = ActivateApexPackages();
+ CreateApexInfoList(active_packages);
// Check that an ART APEX has been activated; clean up and exit
// early otherwise.
- if (std::none_of(active_packages.begin(),
- active_packages.end(),
- [](const apex::ApexFile& package){
- return package.GetManifest().name() == "com.android.art";
- })) {
- LOG(FATAL_WITHOUT_ABORT) << "No activated com.android.art APEX package.";
- DeactivateApexPackages(active_packages);
- exit(217);
+ static constexpr const std::string_view kRequiredApexs[] = {
+ "com.android.art",
+ "com.android.runtime",
+ };
+ for (std::string_view apex : kRequiredApexs) {
+ if (std::none_of(active_packages.begin(), active_packages.end(),
+ [&](const apex::ApexFile& package) {
+ return package.GetManifest().name() == apex;
+ })) {
+ LOG(FATAL_WITHOUT_ABORT) << "No activated " << apex << " APEX package.";
+ DeactivateApexPackages(active_packages);
+ exit(217);
+ }
+ }
+
+ // Setup /linkerconfig. Doing it after the chroot means it doesn't need its own category
+ if (selinux_android_restorecon("/linkerconfig", 0) < 0) {
+ PLOG(ERROR) << "Failed to restorecon /linkerconfig";
+ exit(219);
+ }
+ std::vector<std::string> linkerconfig_cmd{"/apex/com.android.runtime/bin/linkerconfig",
+ "--target", "/linkerconfig"};
+ std::string linkerconfig_error_msg;
+ bool linkerconfig_exec_result = Exec(linkerconfig_cmd, &linkerconfig_error_msg);
+ if (!linkerconfig_exec_result) {
+ LOG(ERROR) << "Running linkerconfig failed: " << linkerconfig_error_msg;
+ exit(218);
}
// Now go on and run otapreopt.
diff --git a/include/android/input.h b/include/android/input.h
index 7973487..6fe95c0 100644
--- a/include/android/input.h
+++ b/include/android/input.h
@@ -166,6 +166,9 @@
/** Capture event */
AINPUT_EVENT_TYPE_CAPTURE = 4,
+
+ /** Drag event */
+ AINPUT_EVENT_TYPE_DRAG = 5,
};
/**
diff --git a/include/input/Input.h b/include/input/Input.h
index aa42db8..f9fe6b9 100644
--- a/include/input/Input.h
+++ b/include/input/Input.h
@@ -792,6 +792,30 @@
bool mPointerCaptureEnabled;
};
+/*
+ * Drag events.
+ */
+class DragEvent : public InputEvent {
+public:
+ virtual ~DragEvent() {}
+
+ virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_DRAG; }
+
+ inline bool isExiting() const { return mIsExiting; }
+
+ inline float getX() const { return mX; }
+
+ inline float getY() const { return mY; }
+
+ void initialize(int32_t id, float x, float y, bool isExiting);
+
+ void initialize(const DragEvent& from);
+
+protected:
+ bool mIsExiting;
+ float mX, mY;
+};
+
/**
* Base class for verified events.
* Do not create a VerifiedInputEvent explicitly.
@@ -855,6 +879,7 @@
virtual MotionEvent* createMotionEvent() = 0;
virtual FocusEvent* createFocusEvent() = 0;
virtual CaptureEvent* createCaptureEvent() = 0;
+ virtual DragEvent* createDragEvent() = 0;
};
/*
@@ -870,12 +895,14 @@
virtual MotionEvent* createMotionEvent() override { return &mMotionEvent; }
virtual FocusEvent* createFocusEvent() override { return &mFocusEvent; }
virtual CaptureEvent* createCaptureEvent() override { return &mCaptureEvent; }
+ virtual DragEvent* createDragEvent() override { return &mDragEvent; }
private:
KeyEvent mKeyEvent;
MotionEvent mMotionEvent;
FocusEvent mFocusEvent;
CaptureEvent mCaptureEvent;
+ DragEvent mDragEvent;
};
/*
@@ -890,6 +917,7 @@
virtual MotionEvent* createMotionEvent() override;
virtual FocusEvent* createFocusEvent() override;
virtual CaptureEvent* createCaptureEvent() override;
+ virtual DragEvent* createDragEvent() override;
void recycle(InputEvent* event);
@@ -900,6 +928,7 @@
std::queue<std::unique_ptr<MotionEvent>> mMotionEventPool;
std::queue<std::unique_ptr<FocusEvent>> mFocusEventPool;
std::queue<std::unique_ptr<CaptureEvent>> mCaptureEventPool;
+ std::queue<std::unique_ptr<DragEvent>> mDragEventPool;
};
} // namespace android
diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h
index 3b46cb5..3e5674e 100644
--- a/include/input/InputTransport.h
+++ b/include/input/InputTransport.h
@@ -33,6 +33,8 @@
#include <unordered_map>
#include <android-base/chrono_utils.h>
+#include <android-base/result.h>
+#include <android-base/unique_fd.h>
#include <binder/IBinder.h>
#include <binder/Parcelable.h>
@@ -44,7 +46,6 @@
#include <utils/RefBase.h>
#include <utils/Timers.h>
-#include <android-base/unique_fd.h>
namespace android {
class Parcel;
@@ -69,6 +70,7 @@
FINISHED,
FOCUS,
CAPTURE,
+ DRAG,
};
struct Header {
@@ -76,10 +78,15 @@
uint32_t seq;
} header;
- // Body *must* be 8 byte aligned.
// For keys and motions, rely on the fact that std::array takes up exactly as much space
// as the underlying data. This is not guaranteed by C++, but it simplifies the conversions.
static_assert(sizeof(std::array<uint8_t, 32>) == 32);
+
+ // For bool values, rely on the fact that they take up exactly one byte. This is not guaranteed
+ // by C++ and is implementation-dependent, but it simplifies the conversions.
+ static_assert(sizeof(bool) == 1);
+
+ // Body *must* be 8 byte aligned.
union Body {
struct Key {
int32_t eventId;
@@ -154,8 +161,8 @@
} motion;
struct Finished {
- uint32_t empty1;
- uint32_t handled; // actually a bool, but we must maintain 8-byte alignment
+ bool handled;
+ uint8_t empty[7];
nsecs_t consumeTime; // The time when the event was consumed by the receiving end
inline size_t size() const { return sizeof(Finished); }
@@ -163,19 +170,31 @@
struct Focus {
int32_t eventId;
- // The following two fields take up 4 bytes total
- uint16_t hasFocus; // actually a bool
- uint16_t inTouchMode; // actually a bool, but we must maintain 8-byte alignment
+ // The following 3 fields take up 4 bytes total
+ bool hasFocus;
+ bool inTouchMode;
+ uint8_t empty[2];
inline size_t size() const { return sizeof(Focus); }
} focus;
struct Capture {
int32_t eventId;
- uint32_t pointerCaptureEnabled; // actually a bool, but we maintain 8-byte alignment
+ bool pointerCaptureEnabled;
+ uint8_t empty[3];
inline size_t size() const { return sizeof(Capture); }
} capture;
+
+ struct Drag {
+ int32_t eventId;
+ float x;
+ float y;
+ bool isExiting;
+ uint8_t empty[3];
+
+ inline size_t size() const { return sizeof(Drag); }
+ } drag;
} __attribute__((aligned(8))) body;
bool isValid(size_t actualSize) const;
@@ -347,20 +366,33 @@
*/
status_t publishCaptureEvent(uint32_t seq, int32_t eventId, bool pointerCaptureEnabled);
- /* Receives the finished signal from the consumer in reply to the original dispatch signal.
- * If a signal was received, returns the message sequence number,
- * whether the consumer handled the message, and the time the event was first read by the
- * consumer.
- *
- * The returned sequence number is never 0 unless the operation failed.
+ /* Publishes a drag event to the input channel.
*
* Returns OK on success.
- * Returns WOULD_BLOCK if there is no signal present.
+ * Returns WOULD_BLOCK if the channel is full.
* Returns DEAD_OBJECT if the channel's peer has been closed.
* Other errors probably indicate that the channel is broken.
*/
- status_t receiveFinishedSignal(
- const std::function<void(uint32_t seq, bool handled, nsecs_t consumeTime)>& callback);
+ status_t publishDragEvent(uint32_t seq, int32_t eventId, float x, float y, bool isExiting);
+
+ struct Finished {
+ uint32_t seq;
+ bool handled;
+ nsecs_t consumeTime;
+ };
+
+ /* Receives the finished signal from the consumer in reply to the original dispatch signal.
+ * If a signal was received, returns a Finished object.
+ *
+ * The returned sequence number is never 0 unless the operation failed.
+ *
+ * Returned error codes:
+ * OK on success.
+ * WOULD_BLOCK if there is no signal present.
+ * DEAD_OBJECT if the channel's peer has been closed.
+ * Other errors probably indicate that the channel is broken.
+ */
+ android::base::Result<Finished> receiveFinishedSignal();
private:
std::shared_ptr<InputChannel> mChannel;
@@ -594,6 +626,7 @@
static void initializeMotionEvent(MotionEvent* event, const InputMessage* msg);
static void initializeFocusEvent(FocusEvent* event, const InputMessage* msg);
static void initializeCaptureEvent(CaptureEvent* event, const InputMessage* msg);
+ static void initializeDragEvent(DragEvent* event, const InputMessage* msg);
static void addSample(MotionEvent* event, const InputMessage* msg);
static bool canAddSample(const Batch& batch, const InputMessage* msg);
static ssize_t findSampleNoLaterThan(const Batch& batch, nsecs_t time);
diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp
index e9d866b..a17e482 100644
--- a/libs/binder/Android.bp
+++ b/libs/binder/Android.bp
@@ -214,8 +214,14 @@
"-misc-redundant-expression",
"-misc-unused-using-decls",
"performance*",
+ "-performance-no-int-to-ptr",
"portability*",
],
+
+ pgo: {
+ sampling: true,
+ profile_file: "libbinder/libbinder.profdata",
+ },
}
// AIDL interface between libbinder and framework.jar
diff --git a/libs/binder/BufferedTextOutput.cpp b/libs/binder/BufferedTextOutput.cpp
index 88c85bf..349658e 100644
--- a/libs/binder/BufferedTextOutput.cpp
+++ b/libs/binder/BufferedTextOutput.cpp
@@ -15,7 +15,6 @@
*/
#include "BufferedTextOutput.h"
-#include <binder/Debug.h>
#include <cutils/atomic.h>
#include <utils/Log.h>
@@ -26,6 +25,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include "Debug.h"
#include "Static.h"
// ---------------------------------------------------------------------------
diff --git a/libs/binder/Debug.cpp b/libs/binder/Debug.cpp
index 3a62059..e4ac4b4 100644
--- a/libs/binder/Debug.cpp
+++ b/libs/binder/Debug.cpp
@@ -14,7 +14,8 @@
* limitations under the License.
*/
-#include <binder/Debug.h>
+#include "Debug.h"
+
#include <binder/ProcessState.h>
#include <utils/misc.h>
diff --git a/libs/binder/include/binder/Debug.h b/libs/binder/Debug.h
similarity index 100%
rename from libs/binder/include/binder/Debug.h
rename to libs/binder/Debug.h
diff --git a/libs/binder/TextOutput.cpp b/libs/binder/TextOutput.cpp
index 684a7dc..a0ade50 100644
--- a/libs/binder/TextOutput.cpp
+++ b/libs/binder/TextOutput.cpp
@@ -16,7 +16,7 @@
#include <binder/TextOutput.h>
-#include <binder/Debug.h>
+#include "Debug.h"
#include <utils/String8.h>
#include <utils/String16.h>
diff --git a/libs/binder/rust/src/error.rs b/libs/binder/rust/src/error.rs
index 4492cf7..2598ebc 100644
--- a/libs/binder/rust/src/error.rs
+++ b/libs/binder/rust/src/error.rs
@@ -77,9 +77,7 @@
e if e == ExceptionCode::ILLEGAL_ARGUMENT as i32 => ExceptionCode::ILLEGAL_ARGUMENT,
e if e == ExceptionCode::NULL_POINTER as i32 => ExceptionCode::NULL_POINTER,
e if e == ExceptionCode::ILLEGAL_STATE as i32 => ExceptionCode::ILLEGAL_STATE,
- e if e == ExceptionCode::NETWORK_MAIN_THREAD as i32 => {
- ExceptionCode::NETWORK_MAIN_THREAD
- }
+ e if e == ExceptionCode::NETWORK_MAIN_THREAD as i32 => ExceptionCode::NETWORK_MAIN_THREAD,
e if e == ExceptionCode::UNSUPPORTED_OPERATION as i32 => {
ExceptionCode::UNSUPPORTED_OPERATION
}
@@ -96,6 +94,16 @@
/// Used in AIDL transactions to represent failed transactions.
pub struct Status(*mut sys::AStatus);
+// Safety: The `AStatus` that the `Status` points to must have an entirely thread-safe API for the
+// duration of the `Status` object's lifetime. We ensure this by not allowing mutation of a `Status`
+// in Rust, and the NDK API says we're the owner of our `AStatus` objects so outside code should not
+// be mutating them underneath us.
+unsafe impl Sync for Status {}
+
+// Safety: `Status` always contains an owning pointer to a global, immutable, interned `AStatus`.
+// A thread-local `AStatus` would not be valid.
+unsafe impl Send for Status {}
+
impl Status {
/// Create a status object representing a successful transaction.
pub fn ok() -> Self {
diff --git a/libs/binder/tests/binderTextOutputTest.cpp b/libs/binder/tests/binderTextOutputTest.cpp
index ce99f59..b37030e 100644
--- a/libs/binder/tests/binderTextOutputTest.cpp
+++ b/libs/binder/tests/binderTextOutputTest.cpp
@@ -26,7 +26,6 @@
#include <binder/Parcel.h>
#include <binder/TextOutput.h>
-#include <binder/Debug.h>
static void CheckMessage(CapturedStderr& cap,
const char* expected,
diff --git a/libs/binder/tests/fuzzers/TextOutputFuzz.cpp b/libs/binder/tests/fuzzers/TextOutputFuzz.cpp
index c950020..5e3502a 100644
--- a/libs/binder/tests/fuzzers/TextOutputFuzz.cpp
+++ b/libs/binder/tests/fuzzers/TextOutputFuzz.cpp
@@ -16,7 +16,6 @@
#include <fuzzer/FuzzedDataProvider.h>
-#include <binder/Debug.h>
#include <binder/Parcel.h>
#include <binder/TextOutput.h>
#include "android-base/file.h"
diff --git a/libs/graphicsenv/OWNERS b/libs/graphicsenv/OWNERS
index c0bb75f..8c28464 100644
--- a/libs/graphicsenv/OWNERS
+++ b/libs/graphicsenv/OWNERS
@@ -1,6 +1,4 @@
chrisforbes@google.com
cnorthrop@google.com
-courtneygo@google.com
lpy@google.com
timvp@google.com
-zzyiwei@google.com
diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp
index 05e1935..989abd9 100644
--- a/libs/gui/ISurfaceComposer.cpp
+++ b/libs/gui/ISurfaceComposer.cpp
@@ -755,11 +755,10 @@
return error;
}
- virtual status_t addFpsListener(const sp<IBinder>& layerHandle,
- const sp<gui::IFpsListener>& listener) {
+ virtual status_t addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener) {
Parcel data, reply;
SAFE_PARCEL(data.writeInterfaceToken, ISurfaceComposer::getInterfaceDescriptor());
- SAFE_PARCEL(data.writeStrongBinder, layerHandle);
+ SAFE_PARCEL(data.writeInt32, taskId);
SAFE_PARCEL(data.writeStrongBinder, IInterface::asBinder(listener));
const status_t error =
remote()->transact(BnSurfaceComposer::ADD_FPS_LISTENER, data, &reply);
@@ -1669,8 +1668,8 @@
}
case ADD_FPS_LISTENER: {
CHECK_INTERFACE(ISurfaceComposer, data, reply);
- sp<IBinder> layerHandle;
- status_t result = data.readNullableStrongBinder(&layerHandle);
+ int32_t taskId;
+ status_t result = data.readInt32(&taskId);
if (result != NO_ERROR) {
ALOGE("addFpsListener: Failed to read layer handle");
return result;
@@ -1681,7 +1680,7 @@
ALOGE("addFpsListener: Failed to read listener");
return result;
}
- return addFpsListener(layerHandle, listener);
+ return addFpsListener(taskId, listener);
}
case REMOVE_FPS_LISTENER: {
CHECK_INTERFACE(ISurfaceComposer, data, reply);
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index f5cde59..5e8ab92 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -1982,9 +1982,9 @@
return ComposerService::getComposerService()->removeRegionSamplingListener(listener);
}
-status_t SurfaceComposerClient::addFpsListener(const sp<IBinder>& layerHandle,
+status_t SurfaceComposerClient::addFpsListener(int32_t taskId,
const sp<gui::IFpsListener>& listener) {
- return ComposerService::getComposerService()->addFpsListener(layerHandle, listener);
+ return ComposerService::getComposerService()->addFpsListener(taskId, listener);
}
status_t SurfaceComposerClient::removeFpsListener(const sp<gui::IFpsListener>& listener) {
diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h
index 8b64bcf..88cfe4b 100644
--- a/libs/gui/include/gui/ISurfaceComposer.h
+++ b/libs/gui/include/gui/ISurfaceComposer.h
@@ -351,16 +351,15 @@
/* Registers a listener that streams fps updates from SurfaceFlinger.
*
- * The listener will stream fps updates for the layer tree rooted at layerHandle. Usually, this
- * should be tied to a task. Layers that are not descendants of that task are out of scope for
- * FPS computations.
+ * The listener will stream fps updates for the layer tree rooted at the layer denoted by the
+ * task ID, i.e., the layer must have the task ID as part of its layer metadata with key
+ * METADATA_TASK_ID. If there is no such layer, then no fps is expected to be reported.
*
* Multiple listeners may be supported.
*
- * Requires the ACCESS_SURFACE_FLINGER permission.
+ * Requires the READ_FRAME_BUFFER permission.
*/
- virtual status_t addFpsListener(const sp<IBinder>& layerHandle,
- const sp<gui::IFpsListener>& listener) = 0;
+ virtual status_t addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener) = 0;
/*
* Removes a listener that was streaming fps updates from SurfaceFlinger.
*/
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index ab0347c..de88943 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -589,8 +589,7 @@
const sp<IBinder>& stopLayerHandle,
const sp<IRegionSamplingListener>& listener);
static status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener);
- static status_t addFpsListener(const sp<IBinder>& layerHandle,
- const sp<gui::IFpsListener>& listener);
+ static status_t addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener);
static status_t removeFpsListener(const sp<gui::IFpsListener>& listener);
private:
diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp
index 91b2aff..e8fb71d 100644
--- a/libs/gui/tests/Surface_test.cpp
+++ b/libs/gui/tests/Surface_test.cpp
@@ -824,8 +824,7 @@
const sp<IRegionSamplingListener>& /*listener*/) override {
return NO_ERROR;
}
- status_t addFpsListener(const sp<IBinder>& /*layerHandle*/,
- const sp<gui::IFpsListener>& /*listener*/) {
+ status_t addFpsListener(int32_t /*taskId*/, const sp<gui::IFpsListener>& /*listener*/) {
return NO_ERROR;
}
status_t removeFpsListener(const sp<gui::IFpsListener>& /*listener*/) { return NO_ERROR; }
diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp
index 0a00d68..5600eb3 100644
--- a/libs/input/Input.cpp
+++ b/libs/input/Input.cpp
@@ -92,6 +92,9 @@
case AINPUT_EVENT_TYPE_CAPTURE: {
return "CAPTURE";
}
+ case AINPUT_EVENT_TYPE_DRAG: {
+ return "DRAG";
+ }
}
return "UNKNOWN";
}
@@ -770,6 +773,23 @@
mPointerCaptureEnabled = from.mPointerCaptureEnabled;
}
+// --- DragEvent ---
+
+void DragEvent::initialize(int32_t id, float x, float y, bool isExiting) {
+ InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN,
+ ADISPLAY_ID_NONE, INVALID_HMAC);
+ mIsExiting = isExiting;
+ mX = x;
+ mY = y;
+}
+
+void DragEvent::initialize(const DragEvent& from) {
+ InputEvent::initialize(from);
+ mIsExiting = from.mIsExiting;
+ mX = from.mX;
+ mY = from.mY;
+}
+
// --- PooledInputEventFactory ---
PooledInputEventFactory::PooledInputEventFactory(size_t maxPoolSize) :
@@ -815,6 +835,15 @@
return event;
}
+DragEvent* PooledInputEventFactory::createDragEvent() {
+ if (mDragEventPool.empty()) {
+ return new DragEvent();
+ }
+ DragEvent* event = mDragEventPool.front().release();
+ mDragEventPool.pop();
+ return event;
+}
+
void PooledInputEventFactory::recycle(InputEvent* event) {
switch (event->getType()) {
case AINPUT_EVENT_TYPE_KEY:
@@ -842,6 +871,12 @@
return;
}
break;
+ case AINPUT_EVENT_TYPE_DRAG:
+ if (mDragEventPool.size() < mMaxPoolSize) {
+ mDragEventPool.push(std::unique_ptr<DragEvent>(static_cast<DragEvent*>(event)));
+ return;
+ }
+ break;
}
delete event;
}
diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp
index 1e47a3c..c2a3cf1 100644
--- a/libs/input/InputTransport.cpp
+++ b/libs/input/InputTransport.cpp
@@ -108,6 +108,8 @@
return true;
case Type::CAPTURE:
return true;
+ case Type::DRAG:
+ return true;
}
}
return false;
@@ -125,6 +127,8 @@
return sizeof(Header) + body.focus.size();
case Type::CAPTURE:
return sizeof(Header) + body.capture.size();
+ case Type::DRAG:
+ return sizeof(Header) + body.drag.size();
}
return sizeof(Header);
}
@@ -249,6 +253,13 @@
msg->body.capture.pointerCaptureEnabled = body.capture.pointerCaptureEnabled;
break;
}
+ case InputMessage::Type::DRAG: {
+ msg->body.drag.eventId = body.drag.eventId;
+ msg->body.drag.x = body.drag.x;
+ msg->body.drag.y = body.drag.y;
+ msg->body.drag.isExiting = body.drag.isExiting;
+ break;
+ }
}
}
@@ -577,8 +588,8 @@
msg.header.type = InputMessage::Type::FOCUS;
msg.header.seq = seq;
msg.body.focus.eventId = eventId;
- msg.body.focus.hasFocus = hasFocus ? 1 : 0;
- msg.body.focus.inTouchMode = inTouchMode ? 1 : 0;
+ msg.body.focus.hasFocus = hasFocus;
+ msg.body.focus.inTouchMode = inTouchMode;
return mChannel->sendMessage(&msg);
}
@@ -595,28 +606,49 @@
msg.header.type = InputMessage::Type::CAPTURE;
msg.header.seq = seq;
msg.body.capture.eventId = eventId;
- msg.body.capture.pointerCaptureEnabled = pointerCaptureEnabled ? 1 : 0;
+ msg.body.capture.pointerCaptureEnabled = pointerCaptureEnabled;
return mChannel->sendMessage(&msg);
}
-status_t InputPublisher::receiveFinishedSignal(
- const std::function<void(uint32_t seq, bool handled, nsecs_t consumeTime)>& callback) {
+status_t InputPublisher::publishDragEvent(uint32_t seq, int32_t eventId, float x, float y,
+ bool isExiting) {
+ if (ATRACE_ENABLED()) {
+ std::string message =
+ StringPrintf("publishDragEvent(inputChannel=%s, x=%f, y=%f, isExiting=%s)",
+ mChannel->getName().c_str(), x, y, toString(isExiting));
+ ATRACE_NAME(message.c_str());
+ }
+
+ InputMessage msg;
+ msg.header.type = InputMessage::Type::DRAG;
+ msg.header.seq = seq;
+ msg.body.drag.eventId = eventId;
+ msg.body.drag.isExiting = isExiting;
+ msg.body.drag.x = x;
+ msg.body.drag.y = y;
+ return mChannel->sendMessage(&msg);
+}
+
+android::base::Result<InputPublisher::Finished> InputPublisher::receiveFinishedSignal() {
if (DEBUG_TRANSPORT_ACTIONS) {
- ALOGD("channel '%s' publisher ~ receiveFinishedSignal", mChannel->getName().c_str());
+ ALOGD("channel '%s' publisher ~ %s", mChannel->getName().c_str(), __func__);
}
InputMessage msg;
status_t result = mChannel->receiveMessage(&msg);
if (result) {
- return result;
+ return android::base::Error(result);
}
if (msg.header.type != InputMessage::Type::FINISHED) {
ALOGE("channel '%s' publisher ~ Received unexpected %s message from consumer",
mChannel->getName().c_str(), NamedEnum::string(msg.header.type).c_str());
- return UNKNOWN_ERROR;
+ return android::base::Error(UNKNOWN_ERROR);
}
- callback(msg.header.seq, msg.body.finished.handled == 1, msg.body.finished.consumeTime);
- return OK;
+ return Finished{
+ .seq = msg.header.seq,
+ .handled = msg.body.finished.handled,
+ .consumeTime = msg.body.finished.consumeTime,
+ };
}
// --- InputConsumer ---
@@ -779,6 +811,16 @@
*outEvent = captureEvent;
break;
}
+
+ case InputMessage::Type::DRAG: {
+ DragEvent* dragEvent = factory->createDragEvent();
+ if (!dragEvent) return NO_MEMORY;
+
+ initializeDragEvent(dragEvent, &mMsg);
+ *outSeq = mMsg.header.seq;
+ *outEvent = dragEvent;
+ break;
+ }
}
}
return OK;
@@ -1168,7 +1210,7 @@
InputMessage msg;
msg.header.type = InputMessage::Type::FINISHED;
msg.header.seq = seq;
- msg.body.finished.handled = handled ? 1 : 0;
+ msg.body.finished.handled = handled;
msg.body.finished.consumeTime = getConsumeTime(seq);
status_t result = mChannel->sendMessage(&msg);
if (result == OK) {
@@ -1228,12 +1270,17 @@
}
void InputConsumer::initializeFocusEvent(FocusEvent* event, const InputMessage* msg) {
- event->initialize(msg->body.focus.eventId, msg->body.focus.hasFocus == 1,
- msg->body.focus.inTouchMode == 1);
+ event->initialize(msg->body.focus.eventId, msg->body.focus.hasFocus,
+ msg->body.focus.inTouchMode);
}
void InputConsumer::initializeCaptureEvent(CaptureEvent* event, const InputMessage* msg) {
- event->initialize(msg->body.capture.eventId, msg->body.capture.pointerCaptureEnabled == 1);
+ event->initialize(msg->body.capture.eventId, msg->body.capture.pointerCaptureEnabled);
+}
+
+void InputConsumer::initializeDragEvent(DragEvent* event, const InputMessage* msg) {
+ event->initialize(msg->body.drag.eventId, msg->body.drag.x, msg->body.drag.y,
+ msg->body.drag.isExiting);
}
void InputConsumer::initializeMotionEvent(MotionEvent* event, const InputMessage* msg) {
@@ -1346,6 +1393,12 @@
.pointerCaptureEnabled));
break;
}
+ case InputMessage::Type::DRAG: {
+ out += android::base::StringPrintf("x=%.1f y=%.1f, isExiting=%s",
+ msg.body.drag.x, msg.body.drag.y,
+ toString(msg.body.drag.isExiting));
+ break;
+ }
}
out += "\n";
}
diff --git a/libs/input/android/os/IInputConstants.aidl b/libs/input/android/os/IInputConstants.aidl
index bce0ec8..4b90844 100644
--- a/libs/input/android/os/IInputConstants.aidl
+++ b/libs/input/android/os/IInputConstants.aidl
@@ -20,7 +20,10 @@
/** @hide */
interface IInputConstants
{
- const int DEFAULT_DISPATCHING_TIMEOUT_MILLIS = 5000; // 5 seconds
+ // This should be multiplied by the value of the system property ro.hw_timeout_multiplier before
+ // use. A pre-multiplied constant is available in Java in
+ // android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS.
+ const int UNMULTIPLIED_DEFAULT_DISPATCHING_TIMEOUT_MILLIS = 5000; // 5 seconds
// Compatibility changes.
/**
diff --git a/libs/input/tests/InputPublisherAndConsumer_test.cpp b/libs/input/tests/InputPublisherAndConsumer_test.cpp
index e7e566d..fc31715 100644
--- a/libs/input/tests/InputPublisherAndConsumer_test.cpp
+++ b/libs/input/tests/InputPublisherAndConsumer_test.cpp
@@ -27,6 +27,8 @@
#include <utils/StopWatch.h>
#include <utils/Timers.h>
+using android::base::Result;
+
namespace android {
class InputPublisherAndConsumerTest : public testing::Test {
@@ -52,6 +54,7 @@
void PublishAndConsumeMotionEvent();
void PublishAndConsumeFocusEvent();
void PublishAndConsumeCaptureEvent();
+ void PublishAndConsumeDragEvent();
};
TEST_F(InputPublisherAndConsumerTest, GetChannel_ReturnsTheChannel) {
@@ -121,23 +124,13 @@
ASSERT_EQ(OK, status)
<< "consumer sendFinishedSignal should return OK";
- uint32_t finishedSeq = 0;
- bool handled = false;
- nsecs_t consumeTime;
- status = mPublisher->receiveFinishedSignal(
- [&finishedSeq, &handled, &consumeTime](uint32_t inSeq, bool inHandled,
- nsecs_t inConsumeTime) -> void {
- finishedSeq = inSeq;
- handled = inHandled;
- consumeTime = inConsumeTime;
- });
- ASSERT_EQ(OK, status)
- << "publisher receiveFinishedSignal should return OK";
- ASSERT_EQ(seq, finishedSeq)
- << "publisher receiveFinishedSignal should have returned the original sequence number";
- ASSERT_TRUE(handled)
- << "publisher receiveFinishedSignal should have set handled to consumer's reply";
- ASSERT_GE(consumeTime, publishTime)
+ Result<InputPublisher::Finished> result = mPublisher->receiveFinishedSignal();
+ ASSERT_TRUE(result.ok()) << "publisher receiveFinishedSignal should return OK";
+ ASSERT_EQ(seq, result->seq)
+ << "receiveFinishedSignal should have returned the original sequence number";
+ ASSERT_TRUE(result->handled)
+ << "receiveFinishedSignal should have set handled to consumer's reply";
+ ASSERT_GE(result->consumeTime, publishTime)
<< "finished signal's consume time should be greater than publish time";
}
@@ -271,23 +264,13 @@
ASSERT_EQ(OK, status)
<< "consumer sendFinishedSignal should return OK";
- uint32_t finishedSeq = 0;
- bool handled = true;
- nsecs_t consumeTime;
- status = mPublisher->receiveFinishedSignal(
- [&finishedSeq, &handled, &consumeTime](uint32_t inSeq, bool inHandled,
- nsecs_t inConsumeTime) -> void {
- finishedSeq = inSeq;
- handled = inHandled;
- consumeTime = inConsumeTime;
- });
- ASSERT_EQ(OK, status)
- << "publisher receiveFinishedSignal should return OK";
- ASSERT_EQ(seq, finishedSeq)
- << "publisher receiveFinishedSignal should have returned the original sequence number";
- ASSERT_FALSE(handled)
- << "publisher receiveFinishedSignal should have set handled to consumer's reply";
- ASSERT_GE(consumeTime, publishTime)
+ Result<InputPublisher::Finished> result = mPublisher->receiveFinishedSignal();
+ ASSERT_TRUE(result.ok()) << "receiveFinishedSignal should return OK";
+ ASSERT_EQ(seq, result->seq)
+ << "receiveFinishedSignal should have returned the original sequence number";
+ ASSERT_FALSE(result->handled)
+ << "receiveFinishedSignal should have set handled to consumer's reply";
+ ASSERT_GE(result->consumeTime, publishTime)
<< "finished signal's consume time should be greater than publish time";
}
@@ -301,7 +284,7 @@
const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
status = mPublisher->publishFocusEvent(seq, eventId, hasFocus, inTouchMode);
- ASSERT_EQ(OK, status) << "publisher publishKeyEvent should return OK";
+ ASSERT_EQ(OK, status) << "publisher publishFocusEvent should return OK";
uint32_t consumeSeq;
InputEvent* event;
@@ -321,22 +304,14 @@
status = mConsumer->sendFinishedSignal(seq, true);
ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
- uint32_t finishedSeq = 0;
- bool handled = false;
- nsecs_t consumeTime;
- status = mPublisher->receiveFinishedSignal(
- [&finishedSeq, &handled, &consumeTime](uint32_t inSeq, bool inHandled,
- nsecs_t inConsumeTime) -> void {
- finishedSeq = inSeq;
- handled = inHandled;
- consumeTime = inConsumeTime;
- });
- ASSERT_EQ(OK, status) << "publisher receiveFinishedSignal should return OK";
- ASSERT_EQ(seq, finishedSeq)
- << "publisher receiveFinishedSignal should have returned the original sequence number";
- ASSERT_TRUE(handled)
- << "publisher receiveFinishedSignal should have set handled to consumer's reply";
- ASSERT_GE(consumeTime, publishTime)
+ Result<InputPublisher::Finished> result = mPublisher->receiveFinishedSignal();
+
+ ASSERT_TRUE(result.ok()) << "receiveFinishedSignal should return OK";
+ ASSERT_EQ(seq, result->seq)
+ << "receiveFinishedSignal should have returned the original sequence number";
+ ASSERT_TRUE(result->handled)
+ << "receiveFinishedSignal should have set handled to consumer's reply";
+ ASSERT_GE(result->consumeTime, publishTime)
<< "finished signal's consume time should be greater than publish time";
}
@@ -349,7 +324,7 @@
const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
status = mPublisher->publishCaptureEvent(seq, eventId, captureEnabled);
- ASSERT_EQ(OK, status) << "publisher publishKeyEvent should return OK";
+ ASSERT_EQ(OK, status) << "publisher publishCaptureEvent should return OK";
uint32_t consumeSeq;
InputEvent* event;
@@ -368,22 +343,55 @@
status = mConsumer->sendFinishedSignal(seq, true);
ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
- uint32_t finishedSeq = 0;
- bool handled = false;
- nsecs_t consumeTime;
- status = mPublisher->receiveFinishedSignal(
- [&finishedSeq, &handled, &consumeTime](uint32_t inSeq, bool inHandled,
- nsecs_t inConsumeTime) -> void {
- finishedSeq = inSeq;
- handled = inHandled;
- consumeTime = inConsumeTime;
- });
- ASSERT_EQ(OK, status) << "publisher receiveFinishedSignal should return OK";
- ASSERT_EQ(seq, finishedSeq)
+ android::base::Result<InputPublisher::Finished> result = mPublisher->receiveFinishedSignal();
+ ASSERT_TRUE(result.ok()) << "publisher receiveFinishedSignal should return OK";
+ ASSERT_EQ(seq, result->seq)
+ << "receiveFinishedSignal should have returned the original sequence number";
+ ASSERT_TRUE(result->handled)
+ << "receiveFinishedSignal should have set handled to consumer's reply";
+ ASSERT_GE(result->consumeTime, publishTime)
+ << "finished signal's consume time should be greater than publish time";
+}
+
+void InputPublisherAndConsumerTest::PublishAndConsumeDragEvent() {
+ status_t status;
+
+ constexpr uint32_t seq = 15;
+ int32_t eventId = InputEvent::nextId();
+ constexpr bool isExiting = false;
+ constexpr float x = 10;
+ constexpr float y = 15;
+ const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
+
+ status = mPublisher->publishDragEvent(seq, eventId, x, y, isExiting);
+ ASSERT_EQ(OK, status) << "publisher publishDragEvent should return OK";
+
+ uint32_t consumeSeq;
+ InputEvent* event;
+ status = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, &event);
+ ASSERT_EQ(OK, status) << "consumer consume should return OK";
+
+ ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
+ ASSERT_EQ(AINPUT_EVENT_TYPE_DRAG, event->getType())
+ << "consumer should have returned a drag event";
+
+ const DragEvent& dragEvent = static_cast<const DragEvent&>(*event);
+ EXPECT_EQ(seq, consumeSeq);
+ EXPECT_EQ(eventId, dragEvent.getId());
+ EXPECT_EQ(isExiting, dragEvent.isExiting());
+ EXPECT_EQ(x, dragEvent.getX());
+ EXPECT_EQ(y, dragEvent.getY());
+
+ status = mConsumer->sendFinishedSignal(seq, true);
+ ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
+
+ android::base::Result<InputPublisher::Finished> result = mPublisher->receiveFinishedSignal();
+ ASSERT_TRUE(result.ok()) << "publisher receiveFinishedSignal should return OK";
+ ASSERT_EQ(seq, result->seq)
<< "publisher receiveFinishedSignal should have returned the original sequence number";
- ASSERT_TRUE(handled)
+ ASSERT_TRUE(result->handled)
<< "publisher receiveFinishedSignal should have set handled to consumer's reply";
- ASSERT_GE(consumeTime, publishTime)
+ ASSERT_GE(result->consumeTime, publishTime)
<< "finished signal's consume time should be greater than publish time";
}
@@ -403,6 +411,10 @@
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeCaptureEvent());
}
+TEST_F(InputPublisherAndConsumerTest, PublishDragEvent_EndToEnd) {
+ ASSERT_NO_FATAL_FAILURE(PublishAndConsumeDragEvent());
+}
+
TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenSequenceNumberIsZero_ReturnsError) {
status_t status;
const size_t pointerCount = 1;
@@ -468,6 +480,7 @@
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeCaptureEvent());
+ ASSERT_NO_FATAL_FAILURE(PublishAndConsumeDragEvent());
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeMotionEvent());
ASSERT_NO_FATAL_FAILURE(PublishAndConsumeKeyEvent());
}
diff --git a/libs/input/tests/StructLayout_test.cpp b/libs/input/tests/StructLayout_test.cpp
index a886585..3d80b38 100644
--- a/libs/input/tests/StructLayout_test.cpp
+++ b/libs/input/tests/StructLayout_test.cpp
@@ -49,6 +49,7 @@
CHECK_OFFSET(InputMessage::Body::Key, downTime, 88);
CHECK_OFFSET(InputMessage::Body::Motion, eventId, 0);
+ CHECK_OFFSET(InputMessage::Body::Motion, empty1, 4);
CHECK_OFFSET(InputMessage::Body::Motion, eventTime, 8);
CHECK_OFFSET(InputMessage::Body::Motion, deviceId, 16);
CHECK_OFFSET(InputMessage::Body::Motion, source, 20);
@@ -60,6 +61,7 @@
CHECK_OFFSET(InputMessage::Body::Motion, metaState, 72);
CHECK_OFFSET(InputMessage::Body::Motion, buttonState, 76);
CHECK_OFFSET(InputMessage::Body::Motion, classification, 80);
+ CHECK_OFFSET(InputMessage::Body::Motion, empty2, 81);
CHECK_OFFSET(InputMessage::Body::Motion, edgeFlags, 84);
CHECK_OFFSET(InputMessage::Body::Motion, downTime, 88);
CHECK_OFFSET(InputMessage::Body::Motion, dsdx, 96);
@@ -73,16 +75,26 @@
CHECK_OFFSET(InputMessage::Body::Motion, xCursorPosition, 128);
CHECK_OFFSET(InputMessage::Body::Motion, yCursorPosition, 132);
CHECK_OFFSET(InputMessage::Body::Motion, pointerCount, 136);
+ CHECK_OFFSET(InputMessage::Body::Motion, empty3, 140);
CHECK_OFFSET(InputMessage::Body::Motion, pointers, 144);
CHECK_OFFSET(InputMessage::Body::Focus, eventId, 0);
CHECK_OFFSET(InputMessage::Body::Focus, hasFocus, 4);
- CHECK_OFFSET(InputMessage::Body::Focus, inTouchMode, 6);
+ CHECK_OFFSET(InputMessage::Body::Focus, inTouchMode, 5);
+ CHECK_OFFSET(InputMessage::Body::Focus, empty, 6);
CHECK_OFFSET(InputMessage::Body::Capture, eventId, 0);
CHECK_OFFSET(InputMessage::Body::Capture, pointerCaptureEnabled, 4);
+ CHECK_OFFSET(InputMessage::Body::Capture, empty, 5);
- CHECK_OFFSET(InputMessage::Body::Finished, handled, 4);
+ CHECK_OFFSET(InputMessage::Body::Drag, eventId, 0);
+ CHECK_OFFSET(InputMessage::Body::Drag, x, 4);
+ CHECK_OFFSET(InputMessage::Body::Drag, y, 8);
+ CHECK_OFFSET(InputMessage::Body::Drag, isExiting, 12);
+ CHECK_OFFSET(InputMessage::Body::Drag, empty, 13);
+
+ CHECK_OFFSET(InputMessage::Body::Finished, handled, 0);
+ CHECK_OFFSET(InputMessage::Body::Finished, empty, 1);
CHECK_OFFSET(InputMessage::Body::Finished, consumeTime, 8);
}
@@ -104,6 +116,7 @@
static_assert(sizeof(InputMessage::Body::Finished) == 16);
static_assert(sizeof(InputMessage::Body::Focus) == 8);
static_assert(sizeof(InputMessage::Body::Capture) == 8);
+ static_assert(sizeof(InputMessage::Body::Drag) == 16);
}
// --- VerifiedInputEvent ---
diff --git a/libs/renderengine/RenderEngine.cpp b/libs/renderengine/RenderEngine.cpp
index 79839c1..0c5a851 100644
--- a/libs/renderengine/RenderEngine.cpp
+++ b/libs/renderengine/RenderEngine.cpp
@@ -85,5 +85,15 @@
RenderEngine::~RenderEngine() = default;
+void RenderEngine::validateInputBufferUsage(const sp<GraphicBuffer>& buffer) {
+ LOG_ALWAYS_FATAL_IF(!(buffer->getUsage() & GraphicBuffer::USAGE_HW_TEXTURE),
+ "input buffer not gpu readable");
+}
+
+void RenderEngine::validateOutputBufferUsage(const sp<GraphicBuffer>& buffer) {
+ LOG_ALWAYS_FATAL_IF(!(buffer->getUsage() & GraphicBuffer::USAGE_HW_RENDER),
+ "output buffer not gpu writeable");
+}
+
} // namespace renderengine
} // namespace android
diff --git a/libs/renderengine/gl/GLESRenderEngine.cpp b/libs/renderengine/gl/GLESRenderEngine.cpp
index 397f038..2b09c15 100644
--- a/libs/renderengine/gl/GLESRenderEngine.cpp
+++ b/libs/renderengine/gl/GLESRenderEngine.cpp
@@ -1125,6 +1125,8 @@
return BAD_VALUE;
}
+ validateOutputBufferUsage(buffer);
+
std::unique_ptr<BindNativeBufferAsFramebuffer> fbo;
// Gathering layers that requested blur, we'll need them to decide when to render to an
// offscreen buffer, and when to render to the native buffer.
@@ -1249,6 +1251,7 @@
isOpaque = layer->source.buffer.isOpaque;
sp<GraphicBuffer> gBuf = layer->source.buffer.buffer;
+ validateInputBufferUsage(gBuf);
bindExternalTextureBuffer(layer->source.buffer.textureName, gBuf,
layer->source.buffer.fence);
diff --git a/libs/renderengine/include/renderengine/RenderEngine.h b/libs/renderengine/include/renderengine/RenderEngine.h
index 572d348..ddae34a 100644
--- a/libs/renderengine/include/renderengine/RenderEngine.h
+++ b/libs/renderengine/include/renderengine/RenderEngine.h
@@ -201,6 +201,9 @@
// we should not allow in general, so remove this.
RenderEngineType getRenderEngineType() const { return mRenderEngineType; }
+ static void validateInputBufferUsage(const sp<GraphicBuffer>&);
+ static void validateOutputBufferUsage(const sp<GraphicBuffer>&);
+
protected:
friend class threaded::RenderEngineThreaded;
const RenderEngineType mRenderEngineType;
diff --git a/libs/renderengine/skia/SkiaGLRenderEngine.cpp b/libs/renderengine/skia/SkiaGLRenderEngine.cpp
index cbb02a3..91b163e 100644
--- a/libs/renderengine/skia/SkiaGLRenderEngine.cpp
+++ b/libs/renderengine/skia/SkiaGLRenderEngine.cpp
@@ -598,6 +598,8 @@
return BAD_VALUE;
}
+ validateOutputBufferUsage(buffer);
+
auto grContext = mInProtectedContext ? mProtectedGrContext : mGrContext;
auto& cache = mInProtectedContext ? mProtectedTextureCache : mTextureCache;
AHardwareBuffer_Desc bufferDesc;
@@ -815,6 +817,7 @@
SkPaint paint;
if (layer->source.buffer.buffer) {
ATRACE_NAME("DrawImage");
+ validateInputBufferUsage(layer->source.buffer.buffer);
const auto& item = layer->source.buffer;
std::shared_ptr<AutoBackendTexture::LocalRef> imageTextureRef = nullptr;
auto iter = mTextureCache.find(item.buffer->getId());
diff --git a/libs/renderengine/skia/filters/BlurFilter.cpp b/libs/renderengine/skia/filters/BlurFilter.cpp
index 5960e48..ec710d9 100644
--- a/libs/renderengine/skia/filters/BlurFilter.cpp
+++ b/libs/renderengine/skia/filters/BlurFilter.cpp
@@ -36,13 +36,18 @@
SkString blurString(R"(
in shader input;
uniform float2 in_blurOffset;
+ uniform float2 in_maxSizeXY;
half4 main(float2 xy) {
half4 c = sample(input, xy);
- c += sample(input, xy + float2( in_blurOffset.x, in_blurOffset.y));
- c += sample(input, xy + float2( in_blurOffset.x, -in_blurOffset.y));
- c += sample(input, xy + float2(-in_blurOffset.x, in_blurOffset.y));
- c += sample(input, xy + float2(-in_blurOffset.x, -in_blurOffset.y));
+ c += sample(input, float2( clamp( in_blurOffset.x + xy.x, 0, in_maxSizeXY.x),
+ clamp(in_blurOffset.y + xy.y, 0, in_maxSizeXY.y)));
+ c += sample(input, float2( clamp( in_blurOffset.x + xy.x, 0, in_maxSizeXY.x),
+ clamp(-in_blurOffset.y + xy.y, 0, in_maxSizeXY.y)));
+ c += sample(input, float2( clamp( -in_blurOffset.x + xy.x, 0, in_maxSizeXY.x),
+ clamp(in_blurOffset.y + xy.y, 0, in_maxSizeXY.y)));
+ c += sample(input, float2( clamp( -in_blurOffset.x + xy.x, 0, in_maxSizeXY.x),
+ clamp(-in_blurOffset.y + xy.y, 0, in_maxSizeXY.y)));
return half4(c.rgb * 0.2, 1.0);
}
@@ -99,6 +104,8 @@
blurBuilder.child("input") =
input->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, linear, blurMatrix);
blurBuilder.uniform("in_blurOffset") = SkV2{stepX * kInputScale, stepY * kInputScale};
+ blurBuilder.uniform("in_maxSizeXY") =
+ SkV2{blurRect.width() * kInputScale - 1, blurRect.height() * kInputScale - 1};
sk_sp<SkImage> tmpBlur(blurBuilder.makeImage(context, nullptr, scaledInfo, false));
@@ -108,6 +115,8 @@
blurBuilder.child("input") =
tmpBlur->makeShader(SkTileMode::kClamp, SkTileMode::kClamp, linear);
blurBuilder.uniform("in_blurOffset") = SkV2{stepX * stepScale, stepY * stepScale};
+ blurBuilder.uniform("in_maxSizeXY") =
+ SkV2{blurRect.width() * kInputScale - 1, blurRect.height() * kInputScale - 1};
tmpBlur = blurBuilder.makeImage(context, nullptr, scaledInfo, false);
}
diff --git a/opengl/OWNERS b/opengl/OWNERS
index b505712..a9bd4bb 100644
--- a/opengl/OWNERS
+++ b/opengl/OWNERS
@@ -1,7 +1,6 @@
chrisforbes@google.com
cnorthrop@google.com
-courtneygo@google.com
ianelliott@google.com
jessehall@google.com
lpy@google.com
-zzyiwei@google.com
+timvp@google.com
diff --git a/opengl/libs/EGL/egl_angle_platform.cpp b/opengl/libs/EGL/egl_angle_platform.cpp
index c29181d..d38f2ef 100644
--- a/opengl/libs/EGL/egl_angle_platform.cpp
+++ b/opengl/libs/EGL/egl_angle_platform.cpp
@@ -22,6 +22,8 @@
#pragma GCC diagnostic ignored "-Wunused-parameter"
#include <EGL/Platform.h>
#pragma GCC diagnostic pop
+
+#include <android-base/properties.h>
#include <android/dlext.h>
#include <dlfcn.h>
#include <graphicsenv/GraphicsEnv.h>
@@ -33,7 +35,6 @@
namespace angle {
-constexpr char kAngleEs2Lib[] = "libGLESv2_angle.so";
constexpr int kAngleDlFlags = RTLD_LOCAL | RTLD_NOW;
static GetDisplayPlatformFunc angleGetDisplayPlatform = nullptr;
@@ -107,18 +108,36 @@
android_namespace_t* ns = android::GraphicsEnv::getInstance().getAngleNamespace();
void* so = nullptr;
if (ns) {
+ // Loading from an APK, so hard-code the suffix to "_angle".
+ constexpr char kAngleEs2Lib[] = "libGLESv2_angle.so";
const android_dlextinfo dlextinfo = {
.flags = ANDROID_DLEXT_USE_NAMESPACE,
.library_namespace = ns,
};
so = android_dlopen_ext(kAngleEs2Lib, kAngleDlFlags, &dlextinfo);
+ if (so) {
+ ALOGD("dlopen_ext from APK (%s) success at %p", kAngleEs2Lib, so);
+ } else {
+ ALOGE("dlopen_ext(\"%s\") failed: %s", kAngleEs2Lib, dlerror());
+ return false;
+ }
} else {
// If we are here, ANGLE is loaded as built-in gl driver in the sphal.
- so = android_load_sphal_library(kAngleEs2Lib, kAngleDlFlags);
- }
- if (!so) {
- ALOGE("%s failed to dlopen %s!", __FUNCTION__, kAngleEs2Lib);
- return false;
+ // Get the specified ANGLE library filename suffix.
+ std::string angleEs2LibSuffix = android::base::GetProperty("ro.hardware.egl", "");
+ if (angleEs2LibSuffix.empty()) {
+ ALOGE("%s failed to get valid ANGLE library filename suffix!", __FUNCTION__);
+ return false;
+ }
+
+ std::string angleEs2LibName = "libGLESv2_" + angleEs2LibSuffix + ".so";
+ so = android_load_sphal_library(angleEs2LibName.c_str(), kAngleDlFlags);
+ if (so) {
+ ALOGD("dlopen (%s) success at %p", angleEs2LibName.c_str(), so);
+ } else {
+ ALOGE("%s failed to dlopen %s!", __FUNCTION__, angleEs2LibName.c_str());
+ return false;
+ }
}
angleGetDisplayPlatform =
diff --git a/services/gpuservice/OWNERS b/services/gpuservice/OWNERS
index 5d02839..ac300d0 100644
--- a/services/gpuservice/OWNERS
+++ b/services/gpuservice/OWNERS
@@ -1,3 +1,2 @@
chrisforbes@google.com
lpy@google.com
-zzyiwei@google.com
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 465e8be..3183a98 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -48,6 +48,7 @@
#define DEBUG_HOVER 0
#include <android-base/chrono_utils.h>
+#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android/os/IInputConstants.h>
#include <binder/Binder.h>
@@ -78,6 +79,8 @@
#define INDENT3 " "
#define INDENT4 " "
+using android::base::HwTimeoutMultiplier;
+using android::base::Result;
using android::base::StringPrintf;
using android::os::BlockUntrustedTouchesMode;
using android::os::IInputConstants;
@@ -89,8 +92,9 @@
// Default input dispatching timeout if there is no focused application or paused window
// from which to determine an appropriate dispatching timeout.
-constexpr std::chrono::duration DEFAULT_INPUT_DISPATCHING_TIMEOUT =
- std::chrono::milliseconds(android::os::IInputConstants::DEFAULT_DISPATCHING_TIMEOUT_MILLIS);
+const std::chrono::duration DEFAULT_INPUT_DISPATCHING_TIMEOUT = std::chrono::milliseconds(
+ android::os::IInputConstants::UNMULTIPLIED_DEFAULT_DISPATCHING_TIMEOUT_MILLIS *
+ HwTimeoutMultiplier());
// Amount of time to allow for all pending events to be processed when an app switch
// key is on the way. This is used to preempt input dispatch and drop input events
@@ -329,10 +333,11 @@
int32_t inputTargetFlags) {
if (eventEntry->type == EventEntry::Type::MOTION) {
const MotionEntry& motionEntry = static_cast<const MotionEntry&>(*eventEntry);
- if (motionEntry.source & AINPUT_SOURCE_CLASS_JOYSTICK) {
+ if ((motionEntry.source & AINPUT_SOURCE_CLASS_POINTER) == 0) {
const ui::Transform identityTransform;
- // Use identity transform for joystick events events because they don't depend on
- // the window info
+ // Use identity transform for events that are not pointer events because their axes
+ // values do not represent on-screen coordinates, so they should not have any window
+ // transformations applied to them.
return std::make_unique<DispatchEntry>(eventEntry, inputTargetFlags, identityTransform,
1.0f /*globalScaleFactor*/);
}
@@ -3189,17 +3194,17 @@
nsecs_t currentTime = now();
bool gotOne = false;
- status_t status;
+ status_t status = OK;
for (;;) {
- std::function<void(uint32_t seq, bool handled, nsecs_t consumeTime)> callback =
- std::bind(&InputDispatcher::finishDispatchCycleLocked, d, currentTime,
- connection, std::placeholders::_1, std::placeholders::_2,
- std::placeholders::_3);
-
- status = connection->inputPublisher.receiveFinishedSignal(callback);
- if (status) {
+ Result<InputPublisher::Finished> result =
+ connection->inputPublisher.receiveFinishedSignal();
+ if (!result.ok()) {
+ status = result.error().code();
break;
}
+ const InputPublisher::Finished& finished = *result;
+ d->finishDispatchCycleLocked(currentTime, connection, finished.seq,
+ finished.handled, finished.consumeTime);
gotOne = true;
}
if (gotOne) {
@@ -4887,8 +4892,7 @@
}
}
-base::Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputChannel(
- const std::string& name) {
+Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputChannel(const std::string& name) {
#if DEBUG_CHANNEL_CREATION
ALOGD("channel '%s' ~ createInputChannel", name.c_str());
#endif
@@ -4917,8 +4921,10 @@
return clientChannel;
}
-base::Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputMonitor(
- int32_t displayId, bool isGestureMonitor, const std::string& name, int32_t pid) {
+Result<std::unique_ptr<InputChannel>> InputDispatcher::createInputMonitor(int32_t displayId,
+ bool isGestureMonitor,
+ const std::string& name,
+ int32_t pid) {
std::shared_ptr<InputChannel> serverChannel;
std::unique_ptr<InputChannel> clientChannel;
status_t result = openInputChannelPair(name, serverChannel, clientChannel);
diff --git a/services/inputflinger/docs/anr.md b/services/inputflinger/docs/anr.md
index ce64fe9..5b931d6 100644
--- a/services/inputflinger/docs/anr.md
+++ b/services/inputflinger/docs/anr.md
@@ -22,7 +22,7 @@
When a dispatch entry is sent to the app, its `deliveryTime` and `timeoutTime` fields are populated. The `deliveryTime` is the time that the event is delivered to the app. This is simply the current time inside `publishMotionEvent`. The `timeoutTime` is the time when this entry would be considered overdue. At that time, the ANR process would start for this connection.
-Most connections are associated with a window, and each window may have a custom timeout time. To calculate the timeout time of a specific event, simply add the `window.dispatchingTimeout` to the current time. In case where there is no associated window, such as gesture monitors, use the default dispatching timeout which is defined in `IInputConstants::DEFAULT_DISPATCHING_TIMEOUT_MILLIS`.
+Most connections are associated with a window, and each window may have a custom timeout time. To calculate the timeout time of a specific event, simply add the `window.dispatchingTimeout` to the current time. In case where there is no associated window, such as gesture monitors, use the default dispatching timeout which is defined in `android.os.InputConstants.DEFAULT_DISPATCHING_TIMEOUT_MILLIS`.
The `timeoutTime` field of the `DispatchEntry` is needed because the window associated with a specific connection may change its timeout time. Therefore, entries sent prior to the timeout change would need to follow the previous timeout value. If a window timeout changes, it only affects new events being dispatched, and does not alter the timeout times of events already sent to the app.
diff --git a/services/inputflinger/host/Android.bp b/services/inputflinger/host/Android.bp
index 18d0226..743587c 100644
--- a/services/inputflinger/host/Android.bp
+++ b/services/inputflinger/host/Android.bp
@@ -67,6 +67,7 @@
cflags: ["-Wall", "-Werror"],
shared_libs: [
+ "libbase",
"libbinder",
"libinputflingerhost",
"libutils",
diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.cpp b/services/inputflinger/reader/mapper/CursorInputMapper.cpp
index bb12be7..d6bd823 100644
--- a/services/inputflinger/reader/mapper/CursorInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/CursorInputMapper.cpp
@@ -188,11 +188,29 @@
if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
mOrientation = DISPLAY_ORIENTATION_0;
- if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
- std::optional<DisplayViewport> internalViewport =
- config->getDisplayViewportByType(ViewportType::INTERNAL);
- if (internalViewport) {
- mOrientation = internalViewport->orientation;
+ const bool isOrientedDevice =
+ (mParameters.orientationAware && mParameters.hasAssociatedDisplay);
+
+ if (isPerWindowInputRotationEnabled()) {
+ // When per-window input rotation is enabled, InputReader works in the un-rotated
+ // coordinate space, so we don't need to do anything if the device is already
+ // orientation-aware. If the device is not orientation-aware, then we need to apply the
+ // inverse rotation of the display so that when the display rotation is applied later
+ // as a part of the per-window transform, we get the expected screen coordinates.
+ if (!isOrientedDevice) {
+ std::optional<DisplayViewport> internalViewport =
+ config->getDisplayViewportByType(ViewportType::INTERNAL);
+ if (internalViewport) {
+ mOrientation = getInverseRotation(internalViewport->orientation);
+ }
+ }
+ } else {
+ if (isOrientedDevice) {
+ std::optional<DisplayViewport> internalViewport =
+ config->getDisplayViewportByType(ViewportType::INTERNAL);
+ if (internalViewport) {
+ mOrientation = internalViewport->orientation;
+ }
}
}
@@ -294,11 +312,8 @@
float deltaY = mCursorMotionAccumulator.getRelativeY() * mYScale;
bool moved = deltaX != 0 || deltaY != 0;
- // Rotate delta according to orientation if needed.
- if (mParameters.orientationAware && mParameters.hasAssociatedDisplay &&
- (deltaX != 0.0f || deltaY != 0.0f)) {
- rotateDelta(mOrientation, &deltaX, &deltaY);
- }
+ // Rotate delta according to orientation.
+ rotateDelta(mOrientation, &deltaX, &deltaY);
// Move the pointer.
PointerProperties pointerProperties;
@@ -326,7 +341,15 @@
mPointerController->setPresentation(PointerControllerInterface::Presentation::POINTER);
if (moved) {
- mPointerController->move(deltaX, deltaY);
+ float dx = deltaX;
+ float dy = deltaY;
+ if (isPerWindowInputRotationEnabled()) {
+ // Rotate the delta from InputReader's un-rotated coordinate space to
+ // PointerController's rotated coordinate space that is oriented with the
+ // viewport.
+ rotateDelta(getInverseRotation(mOrientation), &dx, &dy);
+ }
+ mPointerController->move(dx, dy);
}
if (buttonsChanged) {
diff --git a/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h b/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h
index 5344227..1843b03 100644
--- a/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h
+++ b/services/inputflinger/reader/mapper/TouchCursorInputMapperCommon.h
@@ -17,6 +17,7 @@
#ifndef _UI_INPUTREADER_TOUCH_CURSOR_INPUT_MAPPER_COMMON_H
#define _UI_INPUTREADER_TOUCH_CURSOR_INPUT_MAPPER_COMMON_H
+#include <android-base/properties.h>
#include <input/DisplayViewport.h>
#include <stdint.h>
@@ -28,6 +29,26 @@
// --- Static Definitions ---
+// When per-window input rotation is enabled, display transformations such as rotation and
+// projection are part of the input window's transform. This means InputReader should work in the
+// un-rotated coordinate space.
+static bool isPerWindowInputRotationEnabled() {
+ static const bool PER_WINDOW_INPUT_ROTATION =
+ base::GetBoolProperty("persist.debug.per_window_input_rotation", false);
+ return PER_WINDOW_INPUT_ROTATION;
+}
+
+static int32_t getInverseRotation(int32_t orientation) {
+ switch (orientation) {
+ case DISPLAY_ORIENTATION_90:
+ return DISPLAY_ORIENTATION_270;
+ case DISPLAY_ORIENTATION_270:
+ return DISPLAY_ORIENTATION_90;
+ default:
+ return orientation;
+ }
+}
+
static void rotateDelta(int32_t orientation, float* deltaX, float* deltaY) {
float temp;
switch (orientation) {
diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
index 1a7ddee..13712ee 100644
--- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
@@ -28,6 +28,30 @@
namespace android {
+namespace {
+
+// Rotates the given point (x, y) by the supplied orientation. The width and height are the
+// dimensions of the surface prior to this rotation being applied.
+void rotatePoint(int32_t orientation, float& x, float& y, int32_t width, int32_t height) {
+ rotateDelta(orientation, &x, &y);
+ switch (orientation) {
+ case DISPLAY_ORIENTATION_90:
+ y += width;
+ break;
+ case DISPLAY_ORIENTATION_180:
+ x += width;
+ y += height;
+ break;
+ case DISPLAY_ORIENTATION_270:
+ x += height;
+ break;
+ default:
+ break;
+ }
+}
+
+} // namespace
+
// --- Constants ---
// Maximum amount of latency to add to touch events while waiting for data from an
@@ -729,8 +753,20 @@
mSurfaceRight = mSurfaceLeft + naturalLogicalWidth;
mSurfaceBottom = mSurfaceTop + naturalLogicalHeight;
- mSurfaceOrientation =
- mParameters.orientationAware ? mViewport.orientation : DISPLAY_ORIENTATION_0;
+ if (isPerWindowInputRotationEnabled()) {
+ // When per-window input rotation is enabled, InputReader works in the un-rotated
+ // coordinate space, so we don't need to do anything if the device is already
+ // orientation-aware. If the device is not orientation-aware, then we need to apply
+ // the inverse rotation of the display so that when the display rotation is applied
+ // later as a part of the per-window transform, we get the expected screen
+ // coordinates.
+ mSurfaceOrientation = mParameters.orientationAware
+ ? DISPLAY_ORIENTATION_0
+ : getInverseRotation(mViewport.orientation);
+ } else {
+ mSurfaceOrientation = mParameters.orientationAware ? mViewport.orientation
+ : DISPLAY_ORIENTATION_0;
+ }
} else {
mPhysicalWidth = rawWidth;
mPhysicalHeight = rawHeight;
@@ -1637,10 +1673,9 @@
mPointerController->fade(PointerControllerInterface::Transition::GRADUAL);
mPointerController->setButtonState(mCurrentRawState.buttonState);
- mPointerController->setSpots(mCurrentCookedState.cookedPointerData.pointerCoords,
- mCurrentCookedState.cookedPointerData.idToIndex,
- mCurrentCookedState.cookedPointerData.touchingIdBits,
- mViewport.displayId);
+ setTouchSpots(mCurrentCookedState.cookedPointerData.pointerCoords,
+ mCurrentCookedState.cookedPointerData.idToIndex,
+ mCurrentCookedState.cookedPointerData.touchingIdBits, mViewport.displayId);
}
bool TouchInputMapper::isTouchScreen() {
@@ -2378,10 +2413,9 @@
}
if (mPointerGesture.currentGestureMode == PointerGesture::Mode::FREEFORM) {
- mPointerController->setSpots(mPointerGesture.currentGestureCoords,
- mPointerGesture.currentGestureIdToIndex,
- mPointerGesture.currentGestureIdBits,
- mPointerController->getDisplayId());
+ setTouchSpots(mPointerGesture.currentGestureCoords,
+ mPointerGesture.currentGestureIdToIndex,
+ mPointerGesture.currentGestureIdBits, mPointerController->getDisplayId());
}
} else {
mPointerController->setPresentation(PointerControllerInterface::Presentation::POINTER);
@@ -2525,8 +2559,7 @@
// the pointer is hovering again even if the user is not currently touching
// the touch pad. This ensures that a view will receive a fresh hover enter
// event after a tap.
- float x, y;
- mPointerController->getPosition(&x, &y);
+ auto [x, y] = getMouseCursorPosition();
PointerProperties pointerProperties;
pointerProperties.clear();
@@ -2783,13 +2816,12 @@
// Move the pointer using a relative motion.
// When using spots, the click will occur at the position of the anchor
// spot and all other spots will move there.
- mPointerController->move(deltaX, deltaY);
+ moveMouseCursor(deltaX, deltaY);
} else {
mPointerVelocityControl.reset();
}
- float x, y;
- mPointerController->getPosition(&x, &y);
+ auto [x, y] = getMouseCursorPosition();
mPointerGesture.currentGestureMode = PointerGesture::Mode::BUTTON_CLICK_OR_DRAG;
mPointerGesture.currentGestureIdBits.clear();
@@ -2815,8 +2847,7 @@
mPointerGesture.lastGestureMode == PointerGesture::Mode::TAP_DRAG) &&
lastFingerCount == 1) {
if (when <= mPointerGesture.tapDownTime + mConfig.pointerGestureTapInterval) {
- float x, y;
- mPointerController->getPosition(&x, &y);
+ auto [x, y] = getMouseCursorPosition();
if (fabs(x - mPointerGesture.tapX) <= mConfig.pointerGestureTapSlop &&
fabs(y - mPointerGesture.tapY) <= mConfig.pointerGestureTapSlop) {
#if DEBUG_GESTURES
@@ -2884,8 +2915,7 @@
mPointerGesture.currentGestureMode = PointerGesture::Mode::HOVER;
if (mPointerGesture.lastGestureMode == PointerGesture::Mode::TAP) {
if (when <= mPointerGesture.tapUpTime + mConfig.pointerGestureTapDragInterval) {
- float x, y;
- mPointerController->getPosition(&x, &y);
+ auto [x, y] = getMouseCursorPosition();
if (fabs(x - mPointerGesture.tapX) <= mConfig.pointerGestureTapSlop &&
fabs(y - mPointerGesture.tapY) <= mConfig.pointerGestureTapSlop) {
mPointerGesture.currentGestureMode = PointerGesture::Mode::TAP_DRAG;
@@ -2919,7 +2949,7 @@
// Move the pointer using a relative motion.
// When using spots, the hover or drag will occur at the position of the anchor spot.
- mPointerController->move(deltaX, deltaY);
+ moveMouseCursor(deltaX, deltaY);
} else {
mPointerVelocityControl.reset();
}
@@ -2941,8 +2971,7 @@
down = false;
}
- float x, y;
- mPointerController->getPosition(&x, &y);
+ auto [x, y] = getMouseCursorPosition();
mPointerGesture.currentGestureIdBits.clear();
mPointerGesture.currentGestureIdBits.markBit(mPointerGesture.activeGestureId);
@@ -3015,8 +3044,9 @@
mCurrentRawState.rawPointerData
.getCentroidOfTouchingPointers(&mPointerGesture.referenceTouchX,
&mPointerGesture.referenceTouchY);
- mPointerController->getPosition(&mPointerGesture.referenceGestureX,
- &mPointerGesture.referenceGestureY);
+ auto [x, y] = getMouseCursorPosition();
+ mPointerGesture.referenceGestureX = x;
+ mPointerGesture.referenceGestureY = y;
}
// Clear the reference deltas for fingers not yet included in the reference calculation.
@@ -3354,14 +3384,13 @@
if (!mCurrentCookedState.stylusIdBits.isEmpty()) {
uint32_t id = mCurrentCookedState.stylusIdBits.firstMarkedBit();
uint32_t index = mCurrentCookedState.cookedPointerData.idToIndex[id];
- float x = mCurrentCookedState.cookedPointerData.pointerCoords[index].getX();
- float y = mCurrentCookedState.cookedPointerData.pointerCoords[index].getY();
- mPointerController->setPosition(x, y);
+ setMouseCursorPosition(mCurrentCookedState.cookedPointerData.pointerCoords[index].getX(),
+ mCurrentCookedState.cookedPointerData.pointerCoords[index].getY());
hovering = mCurrentCookedState.cookedPointerData.hoveringIdBits.hasBit(id);
down = !hovering;
- mPointerController->getPosition(&x, &y);
+ auto [x, y] = getMouseCursorPosition();
mPointerSimple.currentCoords.copyFrom(
mCurrentCookedState.cookedPointerData.pointerCoords[index]);
mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x);
@@ -3402,7 +3431,7 @@
rotateDelta(mSurfaceOrientation, &deltaX, &deltaY);
mPointerVelocityControl.move(when, &deltaX, &deltaY);
- mPointerController->move(deltaX, deltaY);
+ moveMouseCursor(deltaX, deltaY);
} else {
mPointerVelocityControl.reset();
}
@@ -3410,8 +3439,7 @@
down = isPointerDown(mCurrentRawState.buttonState);
hovering = !down;
- float x, y;
- mPointerController->getPosition(&x, &y);
+ auto [x, y] = getMouseCursorPosition();
mPointerSimple.currentCoords.copyFrom(
mCurrentCookedState.cookedPointerData.pointerCoords[currentIndex]);
mPointerSimple.currentCoords.setAxisValue(AMOTION_EVENT_AXIS_X, x);
@@ -3451,9 +3479,7 @@
}
int32_t displayId = mPointerController->getDisplayId();
- float xCursorPosition;
- float yCursorPosition;
- mPointerController->getPosition(&xCursorPosition, &yCursorPosition);
+ auto [xCursorPosition, yCursorPosition] = getMouseCursorPosition();
if (mPointerSimple.down && !down) {
mPointerSimple.down = false;
@@ -3619,7 +3645,9 @@
float xCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION;
float yCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION;
if (mDeviceMode == DeviceMode::POINTER) {
- mPointerController->getPosition(&xCursorPosition, &yCursorPosition);
+ auto [x, y] = getMouseCursorPosition();
+ xCursorPosition = x;
+ yCursorPosition = y;
}
const int32_t displayId = getAssociatedDisplayId().value_or(ADISPLAY_ID_NONE);
const int32_t deviceId = getDeviceId();
@@ -3969,4 +3997,63 @@
return std::nullopt;
}
+void TouchInputMapper::moveMouseCursor(float dx, float dy) const {
+ if (isPerWindowInputRotationEnabled()) {
+ // Convert from InputReader's un-rotated coordinate space to PointerController's coordinate
+ // space that is oriented with the viewport.
+ rotateDelta(mViewport.orientation, &dx, &dy);
+ }
+
+ mPointerController->move(dx, dy);
+}
+
+std::pair<float, float> TouchInputMapper::getMouseCursorPosition() const {
+ float x = 0;
+ float y = 0;
+ mPointerController->getPosition(&x, &y);
+
+ if (!isPerWindowInputRotationEnabled()) return {x, y};
+ if (!mViewport.isValid()) return {x, y};
+
+ // Convert from PointerController's rotated coordinate space that is oriented with the viewport
+ // to InputReader's un-rotated coordinate space.
+ const int32_t orientation = getInverseRotation(mViewport.orientation);
+ rotatePoint(orientation, x, y, mViewport.deviceWidth, mViewport.deviceHeight);
+ return {x, y};
+}
+
+void TouchInputMapper::setMouseCursorPosition(float x, float y) const {
+ if (isPerWindowInputRotationEnabled() && mViewport.isValid()) {
+ // Convert from InputReader's un-rotated coordinate space to PointerController's rotated
+ // coordinate space that is oriented with the viewport.
+ rotatePoint(mViewport.orientation, x, y, mRawSurfaceWidth, mRawSurfaceHeight);
+ }
+
+ mPointerController->setPosition(x, y);
+}
+
+void TouchInputMapper::setTouchSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
+ BitSet32 spotIdBits, int32_t displayId) {
+ std::array<PointerCoords, MAX_POINTERS> outSpotCoords{};
+
+ for (BitSet32 idBits(spotIdBits); !idBits.isEmpty();) {
+ const uint32_t index = spotIdToIndex[idBits.clearFirstMarkedBit()];
+ float x = spotCoords[index].getX();
+ float y = spotCoords[index].getY();
+ float pressure = spotCoords[index].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE);
+
+ if (isPerWindowInputRotationEnabled()) {
+ // Convert from InputReader's un-rotated coordinate space to PointerController's rotated
+ // coordinate space.
+ rotatePoint(mViewport.orientation, x, y, mRawSurfaceWidth, mRawSurfaceHeight);
+ }
+
+ outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_X, x);
+ outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_Y, y);
+ outSpotCoords[index].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pressure);
+ }
+
+ mPointerController->setSpots(outSpotCoords.data(), spotIdToIndex, spotIdBits, displayId);
+}
+
} // namespace android
diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.h b/services/inputflinger/reader/mapper/TouchInputMapper.h
index 9b84ed5..5146299 100644
--- a/services/inputflinger/reader/mapper/TouchInputMapper.h
+++ b/services/inputflinger/reader/mapper/TouchInputMapper.h
@@ -776,6 +776,14 @@
const char* modeToString(DeviceMode deviceMode);
void rotateAndScale(float& x, float& y);
+
+ // Wrapper methods for interfacing with PointerController. These are used to convert points
+ // between the coordinate spaces used by InputReader and PointerController, if they differ.
+ void moveMouseCursor(float dx, float dy) const;
+ std::pair<float, float> getMouseCursorPosition() const;
+ void setMouseCursorPosition(float x, float y) const;
+ void setTouchSpots(const PointerCoords* spotCoords, const uint32_t* spotIdToIndex,
+ BitSet32 spotIdBits, int32_t displayId);
};
} // namespace android
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index 51f6f5d..5cdcfaf 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -2183,7 +2183,7 @@
EXPECT_EQ(motionArgs.buttonState, verifiedMotion.buttonState);
}
-TEST_F(InputDispatcherTest, NonPointerMotionEvent_JoystickNotTransformed) {
+TEST_F(InputDispatcherTest, NonPointerMotionEvent_NotTransformed) {
std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
sp<FakeWindowHandle> window =
new FakeWindowHandle(application, mDispatcher, "Test window", ADISPLAY_ID_DEFAULT);
@@ -2203,28 +2203,41 @@
// Second, we consume focus event if it is right or wrong according to onFocusChangedLocked.
window->consumeFocusEvent(true);
- NotifyMotionArgs motionArgs = generateMotionArgs(AMOTION_EVENT_ACTION_MOVE,
- AINPUT_SOURCE_JOYSTICK, ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&motionArgs);
+ constexpr const std::array nonPointerSources = {AINPUT_SOURCE_TRACKBALL,
+ AINPUT_SOURCE_MOUSE_RELATIVE,
+ AINPUT_SOURCE_JOYSTICK};
+ for (const int source : nonPointerSources) {
+ // Notify motion with a non-pointer source.
+ NotifyMotionArgs motionArgs =
+ generateMotionArgs(AMOTION_EVENT_ACTION_MOVE, source, ADISPLAY_ID_DEFAULT);
+ mDispatcher->notifyMotion(&motionArgs);
- // Third, we consume motion event.
- InputEvent* event = window->consume();
- ASSERT_NE(event, nullptr);
- ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType())
- << name.c_str() << "expected " << inputEventTypeToString(AINPUT_EVENT_TYPE_MOTION)
- << " event, got " << inputEventTypeToString(event->getType()) << " event";
+ InputEvent* event = window->consume();
+ ASSERT_NE(event, nullptr);
+ ASSERT_EQ(AINPUT_EVENT_TYPE_MOTION, event->getType())
+ << name.c_str() << "expected " << inputEventTypeToString(AINPUT_EVENT_TYPE_MOTION)
+ << " event, got " << inputEventTypeToString(event->getType()) << " event";
- const MotionEvent& motionEvent = static_cast<const MotionEvent&>(*event);
- EXPECT_EQ(AINPUT_EVENT_TYPE_MOTION, motionEvent.getAction());
+ const MotionEvent& motionEvent = static_cast<const MotionEvent&>(*event);
+ EXPECT_EQ(AMOTION_EVENT_ACTION_MOVE, motionEvent.getAction());
+ EXPECT_EQ(motionArgs.pointerCount, motionEvent.getPointerCount());
- float expectedX = motionArgs.pointerCoords[0].getX();
- float expectedY = motionArgs.pointerCoords[0].getY();
+ float expectedX = motionArgs.pointerCoords[0].getX();
+ float expectedY = motionArgs.pointerCoords[0].getY();
- // Finally we test if the axis values from the final motion event are not transformed
- EXPECT_EQ(expectedX, motionEvent.getX(0)) << "expected " << expectedX << " for x coord of "
- << name.c_str() << ", got " << motionEvent.getX(0);
- EXPECT_EQ(expectedY, motionEvent.getY(0)) << "expected " << expectedY << " for y coord of "
- << name.c_str() << ", got " << motionEvent.getY(0);
+ // Ensure the axis values from the final motion event are not transformed.
+ EXPECT_EQ(expectedX, motionEvent.getX(0))
+ << "expected " << expectedX << " for x coord of " << name.c_str() << ", got "
+ << motionEvent.getX(0);
+ EXPECT_EQ(expectedY, motionEvent.getY(0))
+ << "expected " << expectedY << " for y coord of " << name.c_str() << ", got "
+ << motionEvent.getY(0);
+ // Ensure the raw and transformed axis values for the motion event are the same.
+ EXPECT_EQ(motionEvent.getRawX(0), motionEvent.getX(0))
+ << "expected raw and transformed X-axis values to be equal";
+ EXPECT_EQ(motionEvent.getRawY(0), motionEvent.getY(0))
+ << "expected raw and transformed Y-axis values to be equal";
+ }
}
/**
diff --git a/services/sensorservice/SensorDevice.cpp b/services/sensorservice/SensorDevice.cpp
index 23893ea..d8e8b52 100644
--- a/services/sensorservice/SensorDevice.cpp
+++ b/services/sensorservice/SensorDevice.cpp
@@ -686,9 +686,9 @@
ALOGD_IF(DEBUG_CONNECTIONS, "enable index=%zd", info.batchParams.indexOfKey(ident));
if (isClientDisabledLocked(ident)) {
- ALOGE("SensorDevice::activate, isClientDisabledLocked(%p):true, handle:%d",
+ ALOGW("SensorDevice::activate, isClientDisabledLocked(%p):true, handle:%d",
ident, handle);
- return INVALID_OPERATION;
+ return NO_ERROR;
}
if (info.batchParams.indexOfKey(ident) >= 0) {
diff --git a/services/surfaceflinger/BufferLayer.cpp b/services/surfaceflinger/BufferLayer.cpp
index a96dffd..eac3d95 100644
--- a/services/surfaceflinger/BufferLayer.cpp
+++ b/services/surfaceflinger/BufferLayer.cpp
@@ -424,12 +424,12 @@
return isBufferDue(expectedPresentTime);
}
-bool BufferLayer::frameIsEarly(nsecs_t expectedPresentTime) const {
+bool BufferLayer::frameIsEarly(nsecs_t expectedPresentTime, int64_t vsyncId) const {
// TODO(b/169901895): kEarlyLatchVsyncThreshold should be based on the
// vsync period. We can do this change as soon as ag/13100772 is merged.
constexpr static std::chrono::nanoseconds kEarlyLatchVsyncThreshold = 5ms;
- const auto presentTime = nextPredictedPresentTime();
+ const auto presentTime = nextPredictedPresentTime(vsyncId);
if (!presentTime.has_value()) {
return false;
}
diff --git a/services/surfaceflinger/BufferLayer.h b/services/surfaceflinger/BufferLayer.h
index 2118f4a..d215298 100644
--- a/services/surfaceflinger/BufferLayer.h
+++ b/services/surfaceflinger/BufferLayer.h
@@ -191,7 +191,7 @@
// Returns true if the next frame is considered too early to present
// at the given expectedPresentTime
- bool frameIsEarly(nsecs_t expectedPresentTime) const;
+ bool frameIsEarly(nsecs_t expectedPresentTime, int64_t vsyncId) const;
std::atomic<bool> mAutoRefresh{false};
std::atomic<bool> mSidebandStreamChanged{false};
@@ -238,7 +238,7 @@
FloatRect computeSourceBounds(const FloatRect& parentBounds) const override;
// Returns the predicted present time of the next frame if available
- virtual std::optional<nsecs_t> nextPredictedPresentTime() const = 0;
+ virtual std::optional<nsecs_t> nextPredictedPresentTime(int64_t vsyncId) const = 0;
// The amount of time SF can delay a frame if it is considered early based
// on the VsyncModulator::VsyncConfig::appWorkDuration
diff --git a/services/surfaceflinger/BufferQueueLayer.cpp b/services/surfaceflinger/BufferQueueLayer.cpp
index 3615a02..63dd25f 100644
--- a/services/surfaceflinger/BufferQueueLayer.cpp
+++ b/services/surfaceflinger/BufferQueueLayer.cpp
@@ -215,7 +215,7 @@
return mQueuedFrames > 0;
}
-std::optional<nsecs_t> BufferQueueLayer::nextPredictedPresentTime() const {
+std::optional<nsecs_t> BufferQueueLayer::nextPredictedPresentTime(int64_t /*vsyncId*/) const {
Mutex::Autolock lock(mQueueItemLock);
if (mQueueItems.empty()) {
return std::nullopt;
diff --git a/services/surfaceflinger/BufferQueueLayer.h b/services/surfaceflinger/BufferQueueLayer.h
index 0ea02e1..3a34b95 100644
--- a/services/surfaceflinger/BufferQueueLayer.h
+++ b/services/surfaceflinger/BufferQueueLayer.h
@@ -117,7 +117,7 @@
// Temporary - Used only for LEGACY camera mode.
uint32_t getProducerStickyTransform() const;
- std::optional<nsecs_t> nextPredictedPresentTime() const override;
+ std::optional<nsecs_t> nextPredictedPresentTime(int64_t vsyncId) const override;
sp<BufferLayerConsumer> mConsumer;
sp<IGraphicBufferProducer> mProducer;
diff --git a/services/surfaceflinger/BufferStateLayer.cpp b/services/surfaceflinger/BufferStateLayer.cpp
index 296085a..e017cdc 100644
--- a/services/surfaceflinger/BufferStateLayer.cpp
+++ b/services/surfaceflinger/BufferStateLayer.cpp
@@ -171,6 +171,14 @@
void BufferStateLayer::onSurfaceFrameCreated(
const std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame) {
+ while (mPendingJankClassifications.size() >= kPendingClassificationMaxSurfaceFrames) {
+ // Too many SurfaceFrames pending classification. The front of the deque is probably not
+ // tracked by FrameTimeline and will never be presented. This will only result in a memory
+ // leak.
+ ALOGW("Removing the front of pending jank deque from layer - %s to prevent memory leak",
+ mName.c_str());
+ mPendingJankClassifications.pop_front();
+ }
mPendingJankClassifications.emplace_back(surfaceFrame);
}
@@ -605,13 +613,14 @@
return mCurrentStateModified && (c.buffer != nullptr || c.bgColorLayer != nullptr);
}
-std::optional<nsecs_t> BufferStateLayer::nextPredictedPresentTime() const {
- const State& drawingState(getDrawingState());
- if (!drawingState.isAutoTimestamp || !drawingState.bufferSurfaceFrameTX) {
+std::optional<nsecs_t> BufferStateLayer::nextPredictedPresentTime(int64_t vsyncId) const {
+ const auto prediction =
+ mFlinger->mFrameTimeline->getTokenManager()->getPredictionsForToken(vsyncId);
+ if (!prediction.has_value()) {
return std::nullopt;
}
- return drawingState.bufferSurfaceFrameTX->getPredictions().presentTime;
+ return prediction->presentTime;
}
status_t BufferStateLayer::updateTexImage(bool& /*recomputeVisibleRegions*/, nsecs_t latchTime,
diff --git a/services/surfaceflinger/BufferStateLayer.h b/services/surfaceflinger/BufferStateLayer.h
index 6b422ea..003edd5 100644
--- a/services/surfaceflinger/BufferStateLayer.h
+++ b/services/surfaceflinger/BufferStateLayer.h
@@ -156,7 +156,7 @@
bool bufferNeedsFiltering() const override;
- std::optional<nsecs_t> nextPredictedPresentTime() const override;
+ std::optional<nsecs_t> nextPredictedPresentTime(int64_t vsyncId) const override;
static const std::array<float, 16> IDENTITY_MATRIX;
@@ -174,6 +174,8 @@
nsecs_t mCallbackHandleAcquireTime = -1;
std::deque<std::shared_ptr<android::frametimeline::SurfaceFrame>> mPendingJankClassifications;
+ // An upper bound on the number of SurfaceFrames in the pending classifications deque.
+ static constexpr int kPendingClassificationMaxSurfaceFrames = 25;
const std::string mBlastTransactionName{"BufferTX - " + mName};
// This integer is incremented everytime a buffer arrives at the server for this layer,
diff --git a/services/surfaceflinger/EffectLayer.cpp b/services/surfaceflinger/EffectLayer.cpp
index 44d4d75..caef338 100644
--- a/services/surfaceflinger/EffectLayer.cpp
+++ b/services/surfaceflinger/EffectLayer.cpp
@@ -77,7 +77,7 @@
}
bool EffectLayer::isVisible() const {
- return !isHiddenByPolicy() && getAlpha() > 0.0_hf && hasSomethingToDraw();
+ return !isHiddenByPolicy() && (getAlpha() > 0.0_hf || hasBlur()) && hasSomethingToDraw();
}
bool EffectLayer::setColor(const half3& color) {
diff --git a/services/surfaceflinger/FpsReporter.cpp b/services/surfaceflinger/FpsReporter.cpp
index c7dbf88..0bc2d3e 100644
--- a/services/surfaceflinger/FpsReporter.cpp
+++ b/services/surfaceflinger/FpsReporter.cpp
@@ -18,14 +18,16 @@
#define LOG_TAG "FpsReporter"
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
-#include "FpsReporter.h"
+#include <algorithm>
+#include "FpsReporter.h"
#include "Layer.h"
+#include "SurfaceFlinger.h"
namespace android {
-FpsReporter::FpsReporter(frametimeline::FrameTimeline& frameTimeline)
- : mFrameTimeline(frameTimeline) {}
+FpsReporter::FpsReporter(frametimeline::FrameTimeline& frameTimeline, SurfaceFlinger& flinger)
+ : mFrameTimeline(frameTimeline), mFlinger(flinger) {}
void FpsReporter::dispatchLayerFps() const {
std::vector<TrackedListener> localListeners;
@@ -41,16 +43,33 @@
});
}
- for (const auto& listener : localListeners) {
- sp<Layer> promotedLayer = listener.layer.promote();
- if (promotedLayer != nullptr) {
- std::unordered_set<int32_t> layerIds;
+ std::unordered_set<int32_t> seenTasks;
+ std::vector<std::pair<TrackedListener, sp<Layer>>> listenersAndLayersToReport;
- promotedLayer->traverse(LayerVector::StateSet::Drawing,
- [&](Layer* layer) { layerIds.insert(layer->getSequence()); });
-
- listener.listener->onFpsReported(mFrameTimeline.computeFps(layerIds));
+ mFlinger.mCurrentState.traverse([&](Layer* layer) {
+ auto& currentState = layer->getCurrentState();
+ if (currentState.metadata.has(METADATA_TASK_ID)) {
+ int32_t taskId = currentState.metadata.getInt32(METADATA_TASK_ID, 0);
+ if (seenTasks.count(taskId) == 0) {
+ // localListeners is expected to be tiny
+ for (TrackedListener& listener : localListeners) {
+ if (listener.taskId == taskId) {
+ seenTasks.insert(taskId);
+ listenersAndLayersToReport.push_back({listener, sp<Layer>(layer)});
+ break;
+ }
+ }
+ }
}
+ });
+
+ for (const auto& [listener, layer] : listenersAndLayersToReport) {
+ std::unordered_set<int32_t> layerIds;
+
+ layer->traverse(LayerVector::StateSet::Current,
+ [&](Layer* layer) { layerIds.insert(layer->getSequence()); });
+
+ listener.listener->onFpsReported(mFrameTimeline.computeFps(layerIds));
}
}
@@ -59,11 +78,11 @@
mListeners.erase(who);
}
-void FpsReporter::addListener(const sp<gui::IFpsListener>& listener, const wp<Layer>& layer) {
+void FpsReporter::addListener(const sp<gui::IFpsListener>& listener, int32_t taskId) {
sp<IBinder> asBinder = IInterface::asBinder(listener);
asBinder->linkToDeath(this);
std::lock_guard lock(mMutex);
- mListeners.emplace(wp<IBinder>(asBinder), TrackedListener{listener, layer});
+ mListeners.emplace(wp<IBinder>(asBinder), TrackedListener{listener, taskId});
}
void FpsReporter::removeListener(const sp<gui::IFpsListener>& listener) {
diff --git a/services/surfaceflinger/FpsReporter.h b/services/surfaceflinger/FpsReporter.h
index d64b3dc..1cec295 100644
--- a/services/surfaceflinger/FpsReporter.h
+++ b/services/surfaceflinger/FpsReporter.h
@@ -27,10 +27,11 @@
namespace android {
class Layer;
+class SurfaceFlinger;
class FpsReporter : public IBinder::DeathRecipient {
public:
- FpsReporter(frametimeline::FrameTimeline& frameTimeline);
+ FpsReporter(frametimeline::FrameTimeline& frameTimeline, SurfaceFlinger& flinger);
// Dispatches updated layer fps values for the registered listeners
// This method promotes Layer weak pointers and performs layer stack traversals, so mStateLock
@@ -41,7 +42,7 @@
void binderDied(const wp<IBinder>&) override;
// Registers an Fps listener that listens to fps updates for the provided layer
- void addListener(const sp<gui::IFpsListener>& listener, const wp<Layer>& layer);
+ void addListener(const sp<gui::IFpsListener>& listener, int32_t taskId);
// Deregisters an Fps listener
void removeListener(const sp<gui::IFpsListener>& listener);
@@ -55,10 +56,11 @@
struct TrackedListener {
sp<gui::IFpsListener> listener;
- wp<Layer> layer;
+ int32_t taskId;
};
frametimeline::FrameTimeline& mFrameTimeline;
+ SurfaceFlinger& mFlinger;
std::unordered_map<wp<IBinder>, TrackedListener, WpHash> mListeners GUARDED_BY(mMutex);
};
diff --git a/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp b/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp
index 7515872..3442706 100644
--- a/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp
+++ b/services/surfaceflinger/FrameTimeline/FrameTimeline.cpp
@@ -207,6 +207,17 @@
}
}
+FrameTimelineEvent::PredictionType toProto(PredictionState predictionState) {
+ switch (predictionState) {
+ case PredictionState::Valid:
+ return FrameTimelineEvent::PREDICTION_VALID;
+ case PredictionState::Expired:
+ return FrameTimelineEvent::PREDICTION_EXPIRED;
+ case PredictionState::None:
+ return FrameTimelineEvent::PREDICTION_UNKNOWN;
+ }
+}
+
int32_t jankTypeBitmaskToProto(int32_t jankType) {
if (jankType == JankType::None) {
return FrameTimelineEvent::JANK_NONE;
@@ -433,37 +444,26 @@
dumpTable(result, mPredictions, mActuals, indent, mPredictionState, baseTime);
}
-void SurfaceFrame::onPresent(nsecs_t presentTime, int32_t displayFrameJankType, Fps refreshRate,
- nsecs_t displayDeadlineDelta, nsecs_t displayPresentDelta) {
- std::scoped_lock lock(mMutex);
-
- if (mPresentState != PresentState::Presented) {
- // No need to update dropped buffers
+void SurfaceFrame::classifyJankLocked(int32_t displayFrameJankType, const Fps& refreshRate,
+ nsecs_t& deadlineDelta) {
+ if (mPredictionState == PredictionState::Expired ||
+ mActuals.presentTime == Fence::SIGNAL_TIME_INVALID) {
+ // Cannot do any classification for invalid present time.
+ // For prediction expired case, we do not know what happened here to classify this
+ // correctly. This could potentially be AppDeadlineMissed but that's assuming no app will
+ // request frames 120ms apart.
+ mJankType = JankType::Unknown;
+ deadlineDelta = -1;
return;
}
- mActuals.presentTime = presentTime;
- // Jank Analysis for SurfaceFrame
if (mPredictionState == PredictionState::None) {
// Cannot do jank classification on frames that don't have a token.
return;
}
- if (mPredictionState == PredictionState::Expired) {
- // We do not know what happened here to classify this correctly. This could
- // potentially be AppDeadlineMissed but that's assuming no app will request frames
- // 120ms apart.
- mJankType = JankType::Unknown;
- mFramePresentMetadata = FramePresentMetadata::UnknownPresent;
- mFrameReadyMetadata = FrameReadyMetadata::UnknownFinish;
- const constexpr nsecs_t kAppDeadlineDelta = -1;
- mTimeStats->incrementJankyFrames({refreshRate, mRenderRate, mOwnerUid, mLayerName,
- mJankType, displayDeadlineDelta, displayPresentDelta,
- kAppDeadlineDelta});
- return;
- }
+ deadlineDelta = mActuals.endTime - mPredictions.endTime;
const nsecs_t presentDelta = mActuals.presentTime - mPredictions.presentTime;
- const nsecs_t deadlineDelta = mActuals.endTime - mPredictions.endTime;
const nsecs_t deltaToVsync = refreshRate.getPeriodNsecs() > 0
? std::abs(presentDelta) % refreshRate.getPeriodNsecs()
: 0;
@@ -547,8 +547,28 @@
}
}
}
- mTimeStats->incrementJankyFrames({refreshRate, mRenderRate, mOwnerUid, mLayerName, mJankType,
- displayDeadlineDelta, displayPresentDelta, deadlineDelta});
+}
+
+void SurfaceFrame::onPresent(nsecs_t presentTime, int32_t displayFrameJankType, Fps refreshRate,
+ nsecs_t displayDeadlineDelta, nsecs_t displayPresentDelta) {
+ std::scoped_lock lock(mMutex);
+
+ if (mPresentState != PresentState::Presented) {
+ // No need to update dropped buffers
+ return;
+ }
+
+ mActuals.presentTime = presentTime;
+ nsecs_t deadlineDelta = 0;
+
+ classifyJankLocked(displayFrameJankType, refreshRate, deadlineDelta);
+
+ if (mPredictionState != PredictionState::None) {
+ // Only update janky frames if the app used vsync predictions
+ mTimeStats->incrementJankyFrames({refreshRate, mRenderRate, mOwnerUid, mLayerName,
+ mJankType, displayDeadlineDelta, displayPresentDelta,
+ deadlineDelta});
+ }
}
void SurfaceFrame::tracePredictions(int64_t displayFrameToken) const {
@@ -628,6 +648,7 @@
FrameReadyMetadata::OnTimeFinish);
actualSurfaceFrameStartEvent->set_gpu_composition(mGpuComposition);
actualSurfaceFrameStartEvent->set_jank_type(jankTypeBitmaskToProto(mJankType));
+ actualSurfaceFrameStartEvent->set_prediction_type(toProto(mPredictionState));
});
// Actual timeline end
@@ -814,25 +835,28 @@
mSurfaceFlingerActuals.endTime = actualEndTime;
}
-void FrameTimeline::DisplayFrame::onPresent(nsecs_t signalTime) {
- mSurfaceFlingerActuals.presentTime = signalTime;
- if (mPredictionState == PredictionState::Expired) {
- // Cannot do jank classification with expired predictions
+void FrameTimeline::DisplayFrame::classifyJank(nsecs_t& deadlineDelta, nsecs_t& deltaToVsync) {
+ if (mPredictionState == PredictionState::Expired ||
+ mSurfaceFlingerActuals.presentTime == Fence::SIGNAL_TIME_INVALID) {
+ // Cannot do jank classification with expired predictions or invalid signal times.
mJankType = JankType::Unknown;
+ deadlineDelta = -1;
+ deltaToVsync = -1;
return;
}
// Delta between the expected present and the actual present
const nsecs_t presentDelta =
mSurfaceFlingerActuals.presentTime - mSurfaceFlingerPredictions.presentTime;
- const nsecs_t deadlineDelta =
+ deadlineDelta =
mSurfaceFlingerActuals.endTime - (mSurfaceFlingerPredictions.endTime - mHwcDuration);
// How far off was the presentDelta when compared to the vsyncPeriod. Used in checking if there
// was a prediction error or not.
- nsecs_t deltaToVsync = mRefreshRate.getPeriodNsecs() > 0
+ deltaToVsync = mRefreshRate.getPeriodNsecs() > 0
? std::abs(presentDelta) % mRefreshRate.getPeriodNsecs()
: 0;
+
if (std::abs(presentDelta) > mJankClassificationThresholds.presentThreshold) {
mFramePresentMetadata = presentDelta > 0 ? FramePresentMetadata::LatePresent
: FramePresentMetadata::EarlyPresent;
@@ -910,6 +934,14 @@
mJankType = JankType::Unknown;
}
}
+}
+
+void FrameTimeline::DisplayFrame::onPresent(nsecs_t signalTime) {
+ mSurfaceFlingerActuals.presentTime = signalTime;
+ nsecs_t deadlineDelta = 0;
+ nsecs_t deltaToVsync = 0;
+ classifyJank(deadlineDelta, deltaToVsync);
+
for (auto& surfaceFrame : mSurfaceFrames) {
surfaceFrame->onPresent(signalTime, mJankType, mRefreshRate, deadlineDelta, deltaToVsync);
}
@@ -968,6 +1000,7 @@
FrameReadyMetadata::OnTimeFinish);
actualDisplayFrameStartEvent->set_gpu_composition(mGpuComposition);
actualDisplayFrameStartEvent->set_jank_type(jankTypeBitmaskToProto(mJankType));
+ actualDisplayFrameStartEvent->set_prediction_type(toProto(mPredictionState));
});
// Actual timeline end
@@ -1071,11 +1104,9 @@
continue;
}
}
- if (signalTime != Fence::SIGNAL_TIME_INVALID) {
- auto& displayFrame = pendingPresentFence.second;
- displayFrame->onPresent(signalTime);
- displayFrame->trace(mSurfaceFlingerPid);
- }
+ auto& displayFrame = pendingPresentFence.second;
+ displayFrame->onPresent(signalTime);
+ displayFrame->trace(mSurfaceFlingerPid);
mPendingPresentFences.erase(mPendingPresentFences.begin() + static_cast<int>(i));
--i;
diff --git a/services/surfaceflinger/FrameTimeline/FrameTimeline.h b/services/surfaceflinger/FrameTimeline/FrameTimeline.h
index 7c6a0cc..b66e02a 100644
--- a/services/surfaceflinger/FrameTimeline/FrameTimeline.h
+++ b/services/surfaceflinger/FrameTimeline/FrameTimeline.h
@@ -216,6 +216,8 @@
private:
void tracePredictions(int64_t displayFrameToken) const;
void traceActuals(int64_t displayFrameToken) const;
+ void classifyJankLocked(int32_t displayFrameJankType, const Fps& refreshRate,
+ nsecs_t& deadlineDelta) REQUIRES(mMutex);
const int64_t mToken;
const int32_t mInputEventId;
@@ -355,7 +357,7 @@
// Sets the token, vsyncPeriod, predictions and SF start time.
void onSfWakeUp(int64_t token, Fps refreshRate, std::optional<TimelineItem> predictions,
nsecs_t wakeUpTime);
- // Sets the appropriate metadata, classifies the jank and returns the classified jankType.
+ // Sets the appropriate metadata and classifies the jank.
void onPresent(nsecs_t signalTime);
// Adds the provided SurfaceFrame to the current display frame.
void addSurfaceFrame(std::shared_ptr<SurfaceFrame> surfaceFrame);
@@ -383,6 +385,7 @@
void dump(std::string& result, nsecs_t baseTime) const;
void tracePredictions(pid_t surfaceFlingerPid) const;
void traceActuals(pid_t surfaceFlingerPid) const;
+ void classifyJank(nsecs_t& deadlineDelta, nsecs_t& deltaToVsync);
int64_t mToken = FrameTimelineInfo::INVALID_VSYNC_ID;
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index ce97155..34a9f39 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -922,7 +922,9 @@
pid_t getOwnerPid() { return mOwnerPid; }
- virtual bool frameIsEarly(nsecs_t /*expectedPresentTime*/) const { return false; }
+ virtual bool frameIsEarly(nsecs_t /*expectedPresentTime*/, int64_t /*vsyncId*/) const {
+ return false;
+ }
// This layer is not a clone, but it's the parent to the cloned hierarchy. The
// variable mClonedChild represents the top layer that will be cloned so this
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index ad91183..593855e 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -1433,14 +1433,12 @@
return NO_ERROR;
}
-status_t SurfaceFlinger::addFpsListener(const sp<IBinder>& layerHandle,
- const sp<gui::IFpsListener>& listener) {
+status_t SurfaceFlinger::addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener) {
if (!listener) {
return BAD_VALUE;
}
- const wp<Layer> layer = fromHandle(layerHandle);
- mFpsReporter->addListener(listener, layer);
+ mFpsReporter->addListener(listener, taskId);
return NO_ERROR;
}
@@ -3006,7 +3004,7 @@
mRegionSamplingThread =
new RegionSamplingThread(*this, *mScheduler,
RegionSamplingThread::EnvironmentTimingTunables());
- mFpsReporter = new FpsReporter(*mFrameTimeline);
+ mFpsReporter = new FpsReporter(*mFrameTimeline, *this);
// Dispatch a mode change request for the primary display on scheduler
// initialization, so that the EventThreads always contain a reference to a
// prior configuration.
@@ -3315,10 +3313,10 @@
while (!transactionQueue.empty()) {
const auto& transaction = transactionQueue.front();
- if (!transactionIsReadyToBeApplied(transaction.isAutoTimestamp,
+ if (!transactionIsReadyToBeApplied(transaction.frameTimelineInfo,
+ transaction.isAutoTimestamp,
transaction.desiredPresentTime,
- transaction.states,
- pendingBuffers)) {
+ transaction.states, pendingBuffers)) {
setTransactionFlags(eTransactionFlushNeeded);
break;
}
@@ -3342,10 +3340,10 @@
const auto& transaction = mTransactionQueue.front();
bool pendingTransactions = mPendingTransactionQueues.find(transaction.applyToken) !=
mPendingTransactionQueues.end();
- if (!transactionIsReadyToBeApplied(transaction.isAutoTimestamp,
+ if (!transactionIsReadyToBeApplied(transaction.frameTimelineInfo,
+ transaction.isAutoTimestamp,
transaction.desiredPresentTime,
- transaction.states,
- pendingBuffers) ||
+ transaction.states, pendingBuffers) ||
pendingTransactions) {
mPendingTransactionQueues[transaction.applyToken].push(transaction);
} else {
@@ -3375,7 +3373,8 @@
}
bool SurfaceFlinger::transactionIsReadyToBeApplied(
- bool isAutoTimestamp, int64_t desiredPresentTime, const Vector<ComposerState>& states,
+ const FrameTimelineInfo& info, bool isAutoTimestamp, int64_t desiredPresentTime,
+ const Vector<ComposerState>& states,
std::unordered_set<sp<IBinder>, ISurfaceComposer::SpHash<IBinder>>& pendingBuffers) {
const nsecs_t expectedPresentTime = mExpectedPresentTime.load();
bool ready = true;
@@ -3388,24 +3387,26 @@
for (const ComposerState& state : states) {
const layer_state_t& s = state.state;
- if (!(s.what & layer_state_t::eAcquireFenceChanged)) {
- continue;
- }
- if (s.acquireFence && s.acquireFence->getStatus() == Fence::Status::Unsignaled) {
+ const bool acquireFenceChanged = (s.what & layer_state_t::eAcquireFenceChanged);
+ if (acquireFenceChanged && s.acquireFence &&
+ s.acquireFence->getStatus() == Fence::Status::Unsignaled) {
ready = false;
}
sp<Layer> layer = nullptr;
if (s.surface) {
layer = fromHandleLocked(s.surface).promote();
- } else {
+ } else if (acquireFenceChanged) {
ALOGW("Transaction with buffer, but no Layer?");
continue;
}
if (!layer) {
continue;
}
- if (layer->frameIsEarly(expectedPresentTime)) {
+
+ const bool frameTimelineInfoChanged = (s.what & layer_state_t::eFrameTimelineInfoChanged);
+ const auto vsyncId = frameTimelineInfoChanged ? s.frameTimelineInfo.vsyncId : info.vsyncId;
+ if (isAutoTimestamp && layer->frameIsEarly(expectedPresentTime, vsyncId)) {
ATRACE_NAME("frameIsEarly()");
return false;
}
@@ -3415,11 +3416,14 @@
ready = false;
}
- // If backpressure is enabled and we already have a buffer to commit, keep the transaction
- // in the queue.
- const bool hasPendingBuffer = pendingBuffers.find(s.surface) != pendingBuffers.end();
- if (layer->backpressureEnabled() && hasPendingBuffer && isAutoTimestamp) {
- ready = false;
+ if (acquireFenceChanged) {
+ // If backpressure is enabled and we already have a buffer to commit, keep the
+ // transaction in the queue.
+ const bool hasPendingBuffer = pendingBuffers.find(s.surface) != pendingBuffers.end();
+ if (layer->backpressureEnabled() && hasPendingBuffer && isAutoTimestamp) {
+ ready = false;
+ }
+ pendingBuffers.insert(s.surface);
}
pendingBuffers.insert(s.surface);
}
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 6434ca2..40d63b2 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -363,6 +363,7 @@
friend class BufferQueueLayer;
friend class BufferStateLayer;
friend class Client;
+ friend class FpsReporter;
friend class Layer;
friend class MonitoredProducer;
friend class RefreshRateOverlay;
@@ -627,8 +628,7 @@
status_t addRegionSamplingListener(const Rect& samplingArea, const sp<IBinder>& stopLayerHandle,
const sp<IRegionSamplingListener>& listener) override;
status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener) override;
- status_t addFpsListener(const sp<IBinder>& layerHandle,
- const sp<gui::IFpsListener>& listener) override;
+ status_t addFpsListener(int32_t taskId, const sp<gui::IFpsListener>& listener) override;
status_t removeFpsListener(const sp<gui::IFpsListener>& listener) override;
status_t setDesiredDisplayModeSpecs(const sp<IBinder>& displayToken,
ui::DisplayModeId displayModeId, bool allowGroupSwitching,
@@ -800,7 +800,8 @@
void commitTransaction() REQUIRES(mStateLock);
void commitOffscreenLayers();
bool transactionIsReadyToBeApplied(
- bool isAutoTimestamp, int64_t desiredPresentTime, const Vector<ComposerState>& states,
+ const FrameTimelineInfo& info, bool isAutoTimestamp, int64_t desiredPresentTime,
+ const Vector<ComposerState>& states,
std::unordered_set<sp<IBinder>, ISurfaceComposer::SpHash<IBinder>>& pendingBuffers)
REQUIRES(mStateLock);
uint32_t setDisplayStateLocked(const DisplayState& s) REQUIRES(mStateLock);
diff --git a/services/surfaceflinger/TimeStats/OWNERS b/services/surfaceflinger/TimeStats/OWNERS
index 1441f91..ded3ebb 100644
--- a/services/surfaceflinger/TimeStats/OWNERS
+++ b/services/surfaceflinger/TimeStats/OWNERS
@@ -1,2 +1 @@
alecmouri@google.com
-zzyiwei@google.com
diff --git a/services/surfaceflinger/tests/BufferGenerator.cpp b/services/surfaceflinger/tests/BufferGenerator.cpp
index 4868c12..03f8e1a 100644
--- a/services/surfaceflinger/tests/BufferGenerator.cpp
+++ b/services/surfaceflinger/tests/BufferGenerator.cpp
@@ -70,7 +70,7 @@
consumer->setDefaultBufferSize(width, height);
consumer->setDefaultBufferFormat(format);
- mBufferItemConsumer = new BufferItemConsumer(consumer, 0);
+ mBufferItemConsumer = new BufferItemConsumer(consumer, GraphicBuffer::USAGE_HW_TEXTURE);
mListener = new BufferListener(consumer, callback);
mBufferItemConsumer->setFrameAvailableListener(mListener);
diff --git a/services/surfaceflinger/tests/EffectLayer_test.cpp b/services/surfaceflinger/tests/EffectLayer_test.cpp
index fafb49e..7a3c45d 100644
--- a/services/surfaceflinger/tests/EffectLayer_test.cpp
+++ b/services/surfaceflinger/tests/EffectLayer_test.cpp
@@ -111,6 +111,72 @@
}
}
+TEST_F(EffectLayerTest, BlurEffectLayerIsVisible) {
+ if (!deviceSupportsBlurs()) GTEST_SKIP();
+ if (!deviceUsesSkiaRenderEngine()) GTEST_SKIP();
+
+ const auto canvasSize = 256;
+
+ sp<SurfaceControl> leftLayer = createColorLayer("Left", Color::BLUE);
+ sp<SurfaceControl> rightLayer = createColorLayer("Right", Color::GREEN);
+ sp<SurfaceControl> blurLayer;
+ const auto leftRect = Rect(0, 0, canvasSize / 2, canvasSize);
+ const auto rightRect = Rect(canvasSize / 2, 0, canvasSize, canvasSize);
+ const auto blurRect = Rect(0, 0, canvasSize, canvasSize);
+
+ asTransaction([&](Transaction& t) {
+ t.setLayer(leftLayer, mLayerZBase + 1);
+ t.reparent(leftLayer, mParentLayer);
+ t.setCrop_legacy(leftLayer, leftRect);
+ t.setLayer(rightLayer, mLayerZBase + 2);
+ t.reparent(rightLayer, mParentLayer);
+ t.setCrop_legacy(rightLayer, rightRect);
+ t.show(leftLayer);
+ t.show(rightLayer);
+ });
+
+ {
+ auto shot = screenshot();
+ shot->expectColor(leftRect, Color::BLUE);
+ shot->expectColor(rightRect, Color::GREEN);
+ }
+
+ ASSERT_NO_FATAL_FAILURE(blurLayer = createColorLayer("BackgroundBlur", Color::TRANSPARENT));
+
+ const auto blurRadius = canvasSize / 2;
+ asTransaction([&](Transaction& t) {
+ t.setLayer(blurLayer, mLayerZBase + 3);
+ t.reparent(blurLayer, mParentLayer);
+ t.setBackgroundBlurRadius(blurLayer, blurRadius);
+ t.setCrop_legacy(blurLayer, blurRect);
+ t.setFrame(blurLayer, blurRect);
+ t.setAlpha(blurLayer, 0.0f);
+ t.show(blurLayer);
+ });
+
+ {
+ auto shot = screenshot();
+
+ const auto stepSize = 1;
+ const auto blurAreaOffset = blurRadius * 0.7f;
+ const auto blurAreaStartX = canvasSize / 2 - blurRadius + blurAreaOffset;
+ const auto blurAreaEndX = canvasSize / 2 + blurRadius - blurAreaOffset;
+ Color previousColor;
+ Color currentColor;
+ for (int y = 0; y < canvasSize; y++) {
+ shot->checkPixel(0, y, /* r = */ 0, /* g = */ 0, /* b = */ 255);
+ previousColor = shot->getPixelColor(0, y);
+ for (int x = blurAreaStartX; x < blurAreaEndX; x += stepSize) {
+ currentColor = shot->getPixelColor(x, y);
+ ASSERT_GT(currentColor.g, previousColor.g);
+ ASSERT_LT(currentColor.b, previousColor.b);
+ ASSERT_EQ(0, currentColor.r);
+ }
+ shot->checkPixel(canvasSize - 1, y, 0, 255, 0);
+ }
+ }
+}
+
} // namespace android
// TODO(b/129481165): remove the #pragma below and fix conversion issues
diff --git a/services/surfaceflinger/tests/LayerCallback_test.cpp b/services/surfaceflinger/tests/LayerCallback_test.cpp
index 6d28e62..aa1cce2 100644
--- a/services/surfaceflinger/tests/LayerCallback_test.cpp
+++ b/services/surfaceflinger/tests/LayerCallback_test.cpp
@@ -18,6 +18,10 @@
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wconversion"
+#include <sys/epoll.h>
+
+#include <gui/DisplayEventReceiver.h>
+
#include "LayerTransactionTest.h"
#include "utils/CallbackUtils.h"
@@ -30,6 +34,24 @@
class LayerCallbackTest : public LayerTransactionTest {
public:
+ void SetUp() override {
+ LayerTransactionTest::SetUp();
+
+ EXPECT_EQ(NO_ERROR, mDisplayEventReceiver.initCheck());
+
+ mEpollFd = epoll_create1(EPOLL_CLOEXEC);
+ EXPECT_GT(mEpollFd, 1);
+
+ epoll_event event;
+ event.events = EPOLLIN;
+ EXPECT_EQ(0, epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mDisplayEventReceiver.getFd(), &event));
+ }
+
+ void TearDown() override {
+ close(mEpollFd);
+ LayerTransactionTest::TearDown();
+ }
+
virtual sp<SurfaceControl> createBufferStateLayer() {
return createLayer(mClient, "test", 0, 0, ISurfaceComposerClient::eFXSurfaceBufferState);
}
@@ -82,6 +104,35 @@
ASSERT_NO_FATAL_FAILURE(helper.verifyFinalState());
}
}
+
+ DisplayEventReceiver mDisplayEventReceiver;
+ int mEpollFd;
+
+ struct Vsync {
+ int64_t vsyncId = FrameTimelineInfo::INVALID_VSYNC_ID;
+ nsecs_t expectedPresentTime = std::numeric_limits<nsecs_t>::max();
+ };
+
+ Vsync waitForNextVsync() {
+ mDisplayEventReceiver.requestNextVsync();
+ epoll_event epollEvent;
+ Vsync vsync;
+ EXPECT_EQ(1, epoll_wait(mEpollFd, &epollEvent, 1, 1000))
+ << "Timeout waiting for vsync event";
+ DisplayEventReceiver::Event event;
+ while (mDisplayEventReceiver.getEvents(&event, 1) > 0) {
+ if (event.header.type != DisplayEventReceiver::DISPLAY_EVENT_VSYNC) {
+ continue;
+ }
+
+ vsync = {event.vsync.vsyncId, event.vsync.expectedVSyncTimestamp};
+ }
+
+ EXPECT_GE(vsync.vsyncId, 1);
+ EXPECT_GT(event.vsync.expectedVSyncTimestamp, systemTime());
+
+ return vsync;
+ }
};
TEST_F(LayerCallbackTest, BufferColor) {
@@ -873,6 +924,29 @@
expected.addExpectedPresentTime(systemTime());
EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true));
}
+
+TEST_F(LayerCallbackTest, ExpectedPresentTime) {
+ sp<SurfaceControl> layer;
+ ASSERT_NO_FATAL_FAILURE(layer = createBufferStateLayer());
+
+ Transaction transaction;
+ CallbackHelper callback;
+ int err = fillTransaction(transaction, &callback, layer);
+ if (err) {
+ GTEST_SUCCEED() << "test not supported";
+ return;
+ }
+
+ const Vsync vsync = waitForNextVsync();
+ transaction.setFrameTimelineInfo({vsync.vsyncId, 0});
+ transaction.apply();
+
+ ExpectedResult expected;
+ expected.addSurface(ExpectedResult::Transaction::PRESENTED, layer);
+ expected.addExpectedPresentTimeForVsyncId(vsync.expectedPresentTime);
+ EXPECT_NO_FATAL_FAILURE(waitForCallback(callback, expected, true));
+}
+
} // namespace android
// TODO(b/129481165): remove the #pragma below and fix conversion issues
diff --git a/services/surfaceflinger/tests/LayerRenderTypeTransaction_test.cpp b/services/surfaceflinger/tests/LayerRenderTypeTransaction_test.cpp
index 52e1a4d..b35eaa9 100644
--- a/services/surfaceflinger/tests/LayerRenderTypeTransaction_test.cpp
+++ b/services/surfaceflinger/tests/LayerRenderTypeTransaction_test.cpp
@@ -43,6 +43,9 @@
protected:
LayerRenderPathTestHarness mHarness;
+
+ static constexpr int64_t kUsageFlags = BufferUsage::CPU_READ_OFTEN |
+ BufferUsage::CPU_WRITE_OFTEN | BufferUsage::COMPOSER_OVERLAY | BufferUsage::GPU_TEXTURE;
};
INSTANTIATE_TEST_CASE_P(LayerRenderTypeTransactionTests, LayerRenderTypeTransactionTest,
@@ -377,10 +380,7 @@
layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState));
sp<GraphicBuffer> buffer =
- new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1,
- BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
- BufferUsage::COMPOSER_OVERLAY,
- "test");
+ new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, kUsageFlags, "test");
ASSERT_NO_FATAL_FAILURE(
TransactionUtils::fillGraphicBufferColor(buffer, top, Color::TRANSPARENT));
@@ -405,10 +405,7 @@
shot->expectColor(bottom, Color::BLACK);
}
- buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1,
- BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
- BufferUsage::COMPOSER_OVERLAY,
- "test");
+ buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, kUsageFlags, "test");
ASSERT_NO_FATAL_FAILURE(TransactionUtils::fillGraphicBufferColor(buffer, top, Color::RED));
ASSERT_NO_FATAL_FAILURE(
@@ -1015,10 +1012,7 @@
ASSERT_NO_FATAL_FAILURE(
layer = createLayer("test", 32, 64, ISurfaceComposerClient::eFXSurfaceBufferState));
sp<GraphicBuffer> buffer =
- new GraphicBuffer(32, 64, PIXEL_FORMAT_RGBA_8888, 1,
- BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
- BufferUsage::COMPOSER_OVERLAY,
- "test");
+ new GraphicBuffer(32, 64, PIXEL_FORMAT_RGBA_8888, 1, kUsageFlags, "test");
TransactionUtils::fillGraphicBufferColor(buffer, Rect(0, 0, 32, 16), Color::BLUE);
TransactionUtils::fillGraphicBufferColor(buffer, Rect(0, 16, 32, 64), Color::RED);
@@ -1341,10 +1335,7 @@
size_t idx = 0;
for (auto& buffer : buffers) {
- buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1,
- BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
- BufferUsage::COMPOSER_OVERLAY,
- "test");
+ buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, kUsageFlags, "test");
Color color = colors[idx % colors.size()];
TransactionUtils::fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), color);
idx++;
@@ -1377,10 +1368,7 @@
size_t idx = 0;
for (auto& buffer : buffers) {
- buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1,
- BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
- BufferUsage::COMPOSER_OVERLAY,
- "test");
+ buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, kUsageFlags, "test");
Color color = colors[idx % colors.size()];
TransactionUtils::fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), color);
idx++;
@@ -1413,10 +1401,7 @@
size_t idx = 0;
for (auto& buffer : buffers) {
- buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1,
- BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
- BufferUsage::COMPOSER_OVERLAY,
- "test");
+ buffer = new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, kUsageFlags, "test");
Color color = colors[idx % colors.size()];
TransactionUtils::fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), color);
idx++;
@@ -1499,10 +1484,7 @@
layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState));
sp<GraphicBuffer> buffer =
- new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1,
- BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
- BufferUsage::COMPOSER_OVERLAY,
- "test");
+ new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, kUsageFlags, "test");
TransactionUtils::fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED);
sp<Fence> fence;
@@ -1528,10 +1510,7 @@
layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState));
sp<GraphicBuffer> buffer =
- new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1,
- BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
- BufferUsage::COMPOSER_OVERLAY,
- "test");
+ new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, kUsageFlags, "test");
TransactionUtils::fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED);
sp<Fence> fence = Fence::NO_FENCE;
@@ -1549,10 +1528,7 @@
layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState));
sp<GraphicBuffer> buffer =
- new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1,
- BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
- BufferUsage::COMPOSER_OVERLAY,
- "test");
+ new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, kUsageFlags, "test");
TransactionUtils::fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED);
Transaction().setBuffer(layer, buffer).setDataspace(layer, ui::Dataspace::UNKNOWN).apply();
@@ -1568,10 +1544,7 @@
layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState));
sp<GraphicBuffer> buffer =
- new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1,
- BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
- BufferUsage::COMPOSER_OVERLAY,
- "test");
+ new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, kUsageFlags, "test");
TransactionUtils::fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED);
HdrMetadata hdrMetadata;
@@ -1589,10 +1562,7 @@
layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState));
sp<GraphicBuffer> buffer =
- new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1,
- BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
- BufferUsage::COMPOSER_OVERLAY,
- "test");
+ new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, kUsageFlags, "test");
TransactionUtils::fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED);
Region region;
@@ -1610,10 +1580,7 @@
layer = createLayer("test", 32, 32, ISurfaceComposerClient::eFXSurfaceBufferState));
sp<GraphicBuffer> buffer =
- new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1,
- BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
- BufferUsage::COMPOSER_OVERLAY,
- "test");
+ new GraphicBuffer(32, 32, PIXEL_FORMAT_RGBA_8888, 1, kUsageFlags, "test");
TransactionUtils::fillGraphicBufferColor(buffer, Rect(0, 0, 32, 32), Color::RED);
Transaction().setBuffer(layer, buffer).setApi(layer, NATIVE_WINDOW_API_CPU).apply();
diff --git a/services/surfaceflinger/tests/LayerTransactionTest.h b/services/surfaceflinger/tests/LayerTransactionTest.h
index eba2c25..be6665b 100644
--- a/services/surfaceflinger/tests/LayerTransactionTest.h
+++ b/services/surfaceflinger/tests/LayerTransactionTest.h
@@ -21,6 +21,7 @@
#pragma clang diagnostic ignored "-Wconversion"
#pragma clang diagnostic ignored "-Wextra"
+#include <cutils/properties.h>
#include <gtest/gtest.h>
#include <gui/ISurfaceComposer.h>
#include <gui/SurfaceComposerClient.h>
@@ -138,7 +139,7 @@
sp<GraphicBuffer> buffer =
new GraphicBuffer(bufferWidth, bufferHeight, PIXEL_FORMAT_RGBA_8888, 1,
BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
- BufferUsage::COMPOSER_OVERLAY,
+ BufferUsage::COMPOSER_OVERLAY | BufferUsage::GPU_TEXTURE,
"test");
TransactionUtils::fillGraphicBufferColor(buffer, Rect(0, 0, bufferWidth, bufferHeight),
color);
@@ -207,7 +208,7 @@
sp<GraphicBuffer> buffer =
new GraphicBuffer(bufferWidth, bufferHeight, PIXEL_FORMAT_RGBA_8888, 1,
BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
- BufferUsage::COMPOSER_OVERLAY,
+ BufferUsage::COMPOSER_OVERLAY | BufferUsage::GPU_TEXTURE,
"test");
ASSERT_TRUE(bufferWidth % 2 == 0 && bufferHeight % 2 == 0);
@@ -245,6 +246,18 @@
sp<SurfaceComposerClient> mClient;
+ bool deviceSupportsBlurs() {
+ char value[PROPERTY_VALUE_MAX];
+ property_get("ro.surface_flinger.supports_background_blur", value, "0");
+ return atoi(value);
+ }
+
+ bool deviceUsesSkiaRenderEngine() {
+ char value[PROPERTY_VALUE_MAX];
+ property_get("debug.renderengine.backend", value, "default");
+ return strstr(value, "skia") != nullptr;
+ }
+
sp<IBinder> mDisplay;
uint32_t mDisplayWidth;
uint32_t mDisplayHeight;
@@ -307,4 +320,4 @@
} // namespace android
// TODO(b/129481165): remove the #pragma below and fix conversion issues
-#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
\ No newline at end of file
+#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
diff --git a/services/surfaceflinger/tests/LayerTypeAndRenderTypeTransaction_test.cpp b/services/surfaceflinger/tests/LayerTypeAndRenderTypeTransaction_test.cpp
index 782a364..67db717 100644
--- a/services/surfaceflinger/tests/LayerTypeAndRenderTypeTransaction_test.cpp
+++ b/services/surfaceflinger/tests/LayerTypeAndRenderTypeTransaction_test.cpp
@@ -18,7 +18,6 @@
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wconversion"
-#include <cutils/properties.h>
#include <gui/BufferItemConsumer.h>
#include "TransactionTestHarnesses.h"
@@ -40,6 +39,9 @@
protected:
LayerRenderPathTestHarness mRenderPathHarness;
+
+ static constexpr int64_t kUsageFlags = BufferUsage::CPU_READ_OFTEN |
+ BufferUsage::CPU_WRITE_OFTEN | BufferUsage::COMPOSER_OVERLAY | BufferUsage::GPU_TEXTURE;
};
::testing::Environment* const binderEnv =
@@ -301,47 +303,86 @@
}
}
-TEST_P(LayerTypeAndRenderTypeTransactionTest, SetBackgroundBlurRadius) {
- char value[PROPERTY_VALUE_MAX];
- property_get("ro.surface_flinger.supports_background_blur", value, "0");
- if (!atoi(value)) {
- // This device doesn't support blurs, no-op.
- return;
- }
+TEST_P(LayerTypeAndRenderTypeTransactionTest, SetBackgroundBlurRadiusSimple) {
+ if (!deviceSupportsBlurs()) GTEST_SKIP();
+ if (!deviceUsesSkiaRenderEngine()) GTEST_SKIP();
- auto size = 256;
- auto center = size / 2;
- auto blurRadius = 50;
-
- sp<SurfaceControl> backgroundLayer;
- ASSERT_NO_FATAL_FAILURE(backgroundLayer = createLayer("background", size, size));
- ASSERT_NO_FATAL_FAILURE(fillLayerColor(backgroundLayer, Color::GREEN, size, size));
+ const auto canvasSize = 256;
sp<SurfaceControl> leftLayer;
- ASSERT_NO_FATAL_FAILURE(leftLayer = createLayer("left", size / 2, size));
- ASSERT_NO_FATAL_FAILURE(fillLayerColor(leftLayer, Color::RED, size / 2, size));
-
+ sp<SurfaceControl> rightLayer;
+ sp<SurfaceControl> greenLayer;
sp<SurfaceControl> blurLayer;
- ASSERT_NO_FATAL_FAILURE(blurLayer = createLayer("blur", size, size));
- ASSERT_NO_FATAL_FAILURE(fillLayerColor(blurLayer, Color::TRANSPARENT, size, size));
+ const auto leftRect = Rect(0, 0, canvasSize / 2, canvasSize);
+ const auto rightRect = Rect(canvasSize / 2, 0, canvasSize, canvasSize);
+ const auto blurRect = Rect(0, 0, canvasSize, canvasSize);
- Transaction().setBackgroundBlurRadius(blurLayer, blurRadius).apply();
+ ASSERT_NO_FATAL_FAILURE(leftLayer =
+ createLayer("Left", leftRect.getWidth(), leftRect.getHeight()));
+ ASSERT_NO_FATAL_FAILURE(
+ fillLayerColor(leftLayer, Color::BLUE, leftRect.getWidth(), leftRect.getHeight()));
+ ASSERT_NO_FATAL_FAILURE(greenLayer = createLayer("Green", canvasSize * 2, canvasSize * 2));
+ ASSERT_NO_FATAL_FAILURE(
+ fillLayerColor(greenLayer, Color::GREEN, canvasSize * 2, canvasSize * 2));
+ ASSERT_NO_FATAL_FAILURE(
+ rightLayer = createLayer("Right", rightRect.getWidth(), rightRect.getHeight()));
+ ASSERT_NO_FATAL_FAILURE(
+ fillLayerColor(rightLayer, Color::RED, rightRect.getWidth(), rightRect.getHeight()));
- auto shot = getScreenCapture();
- // Edges are mixed
- shot->expectColor(Rect(center - 1, center - 5, center, center + 5), Color{150, 150, 0, 255},
- 50 /* tolerance */);
- shot->expectColor(Rect(center, center - 5, center + 1, center + 5), Color{150, 150, 0, 255},
- 50 /* tolerance */);
+ Transaction()
+ .setLayer(greenLayer, mLayerZBase)
+ .setFrame(leftLayer, {0, 0, canvasSize * 2, canvasSize * 2})
+ .setLayer(leftLayer, mLayerZBase + 1)
+ .setFrame(leftLayer, leftRect)
+ .setLayer(rightLayer, mLayerZBase + 2)
+ .setPosition(rightLayer, rightRect.left, rightRect.top)
+ .setFrame(rightLayer, rightRect)
+ .apply();
+
+ {
+ auto shot = getScreenCapture();
+ shot->expectColor(leftRect, Color::BLUE);
+ shot->expectColor(rightRect, Color::RED);
+ }
+
+ ASSERT_NO_FATAL_FAILURE(blurLayer = createColorLayer("BackgroundBlur", Color::TRANSPARENT));
+
+ const auto blurRadius = canvasSize / 2;
+ Transaction()
+ .setLayer(blurLayer, mLayerZBase + 3)
+ .setBackgroundBlurRadius(blurLayer, blurRadius)
+ .setCrop_legacy(blurLayer, blurRect)
+ .setFrame(blurLayer, blurRect)
+ .setSize(blurLayer, blurRect.getWidth(), blurRect.getHeight())
+ .setAlpha(blurLayer, 0.0f)
+ .apply();
+
+ {
+ auto shot = getScreenCapture();
+
+ const auto stepSize = 1;
+ const auto blurAreaOffset = blurRadius * 0.7f;
+ const auto blurAreaStartX = canvasSize / 2 - blurRadius + blurAreaOffset;
+ const auto blurAreaEndX = canvasSize / 2 + blurRadius - blurAreaOffset;
+ Color previousColor;
+ Color currentColor;
+ for (int y = 0; y < canvasSize; y++) {
+ shot->checkPixel(0, y, /* r = */ 0, /* g = */ 0, /* b = */ 255);
+ previousColor = shot->getPixelColor(0, y);
+ for (int x = blurAreaStartX; x < blurAreaEndX; x += stepSize) {
+ currentColor = shot->getPixelColor(x, y);
+ ASSERT_GT(currentColor.r, previousColor.r);
+ ASSERT_LT(currentColor.b, previousColor.b);
+ ASSERT_EQ(0, currentColor.g);
+ }
+ shot->checkPixel(canvasSize - 1, y, 255, 0, 0);
+ }
+ }
}
TEST_P(LayerTypeAndRenderTypeTransactionTest, SetBackgroundBlurRadiusOnMultipleLayers) {
- char value[PROPERTY_VALUE_MAX];
- property_get("ro.surface_flinger.supports_background_blur", value, "0");
- if (!atoi(value)) {
- // This device doesn't support blurs, no-op.
- return;
- }
+ if (!deviceSupportsBlurs()) GTEST_SKIP();
+ if (!deviceUsesSkiaRenderEngine()) GTEST_SKIP();
auto size = 256;
auto center = size / 2;
@@ -378,25 +419,15 @@
}
TEST_P(LayerTypeAndRenderTypeTransactionTest, SetBackgroundBlurAffectedByParentAlpha) {
- char value[PROPERTY_VALUE_MAX];
- property_get("ro.surface_flinger.supports_background_blur", value, "0");
- if (!atoi(value)) {
- // This device doesn't support blurs, no-op.
- return;
- }
-
- property_get("debug.renderengine.backend", value, "");
- if (strcmp(value, "skiagl") != 0) {
- // This device isn't using Skia render engine, no-op.
- return;
- }
+ if (!deviceSupportsBlurs()) GTEST_SKIP();
+ if (!deviceUsesSkiaRenderEngine()) GTEST_SKIP();
sp<SurfaceControl> left;
sp<SurfaceControl> right;
sp<SurfaceControl> blur;
sp<SurfaceControl> blurParent;
- const auto size = 32;
+ const auto size = 256;
ASSERT_NO_FATAL_FAILURE(left = createLayer("Left", size, size));
ASSERT_NO_FATAL_FAILURE(fillLayerColor(left, Color::BLUE, size, size));
ASSERT_NO_FATAL_FAILURE(right = createLayer("Right", size, size));
@@ -493,10 +524,7 @@
sp<Surface> surface = layer->getSurface();
sp<GraphicBuffer> buffer =
- new GraphicBuffer(width, height, PIXEL_FORMAT_RGBX_8888, 1,
- BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
- BufferUsage::COMPOSER_OVERLAY,
- "test");
+ new GraphicBuffer(width, height, PIXEL_FORMAT_RGBX_8888, 1, kUsageFlags, "test");
ASSERT_NO_FATAL_FAILURE(
TransactionUtils::fillGraphicBufferColor(buffer, crop, Color::TRANSPARENT));
@@ -512,10 +540,7 @@
shot->expectColor(crop, Color::BLACK);
}
- buffer = new GraphicBuffer(width, height, PIXEL_FORMAT_RGBA_8888, 1,
- BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN |
- BufferUsage::COMPOSER_OVERLAY,
- "test");
+ buffer = new GraphicBuffer(width, height, PIXEL_FORMAT_RGBA_8888, 1, kUsageFlags, "test");
ASSERT_NO_FATAL_FAILURE(
TransactionUtils::fillGraphicBufferColor(buffer, crop, Color::TRANSPARENT));
diff --git a/services/surfaceflinger/tests/unittests/FpsReporterTest.cpp b/services/surfaceflinger/tests/unittests/FpsReporterTest.cpp
index a9e5df3..a2291b2 100644
--- a/services/surfaceflinger/tests/unittests/FpsReporterTest.cpp
+++ b/services/surfaceflinger/tests/unittests/FpsReporterTest.cpp
@@ -76,7 +76,7 @@
void setupScheduler();
void setupComposer(uint32_t virtualDisplayCount);
- sp<BufferStateLayer> createBufferStateLayer();
+ sp<BufferStateLayer> createBufferStateLayer(LayerMetadata metadata);
TestableSurfaceFlinger mFlinger;
Hwc2::mock::Composer* mComposer = nullptr;
@@ -91,7 +91,7 @@
sp<Layer> mUnrelated;
sp<TestableFpsListener> mFpsListener;
- sp<FpsReporter> mFpsReporter = new FpsReporter(mFrameTimeline);
+ sp<FpsReporter> mFpsReporter = new FpsReporter(mFrameTimeline, *(mFlinger.flinger()));
};
FpsReporterTest::FpsReporterTest() {
@@ -110,10 +110,10 @@
ALOGD("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
}
-sp<BufferStateLayer> FpsReporterTest::createBufferStateLayer() {
+sp<BufferStateLayer> FpsReporterTest::createBufferStateLayer(LayerMetadata metadata = {}) {
sp<Client> client;
LayerCreationArgs args(mFlinger.flinger(), client, "buffer-state-layer", WIDTH, HEIGHT,
- LAYER_FLAGS, LayerMetadata());
+ LAYER_FLAGS, metadata);
return new BufferStateLayer(args);
}
@@ -154,7 +154,10 @@
TEST_F(FpsReporterTest, callsListeners) {
mParent = createBufferStateLayer();
- mTarget = createBufferStateLayer();
+ const constexpr int32_t kTaskId = 12;
+ LayerMetadata targetMetadata;
+ targetMetadata.setInt32(METADATA_TASK_ID, kTaskId);
+ mTarget = createBufferStateLayer(targetMetadata);
mChild = createBufferStateLayer();
mGrandChild = createBufferStateLayer();
mUnrelated = createBufferStateLayer();
@@ -162,6 +165,10 @@
mTarget->addChild(mChild);
mChild->addChild(mGrandChild);
mParent->commitChildList();
+ mFlinger.mutableCurrentState().layersSortedByZ.add(mParent);
+ mFlinger.mutableCurrentState().layersSortedByZ.add(mTarget);
+ mFlinger.mutableCurrentState().layersSortedByZ.add(mChild);
+ mFlinger.mutableCurrentState().layersSortedByZ.add(mGrandChild);
float expectedFps = 44.0;
@@ -170,7 +177,7 @@
mGrandChild->getSequence())))
.WillOnce(Return(expectedFps));
- mFpsReporter->addListener(mFpsListener, mTarget);
+ mFpsReporter->addListener(mFpsListener, kTaskId);
mFpsReporter->dispatchLayerFps();
EXPECT_EQ(expectedFps, mFpsListener->lastReportedFps);
mFpsReporter->removeListener(mFpsListener);
diff --git a/services/surfaceflinger/tests/unittests/FrameTimelineTest.cpp b/services/surfaceflinger/tests/unittests/FrameTimelineTest.cpp
index 6150b22..81efe0b 100644
--- a/services/surfaceflinger/tests/unittests/FrameTimelineTest.cpp
+++ b/services/surfaceflinger/tests/unittests/FrameTimelineTest.cpp
@@ -40,6 +40,7 @@
using ProtoFrameEnd = perfetto::protos::FrameTimelineEvent_FrameEnd;
using ProtoPresentType = perfetto::protos::FrameTimelineEvent_PresentType;
using ProtoJankType = perfetto::protos::FrameTimelineEvent_JankType;
+using ProtoPredictionType = perfetto::protos::FrameTimelineEvent_PredictionType;
namespace android::frametimeline {
@@ -419,7 +420,54 @@
EXPECT_EQ(getNumberOfDisplayFrames(), *maxDisplayFrames);
}
+TEST_F(FrameTimelineTest, presentFenceSignaled_invalidSignalTime) {
+ Fps refreshRate = Fps::fromPeriodNsecs(11);
+
+ auto presentFence1 = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
+ int64_t surfaceFrameToken1 = mTokenManager->generateTokenForPredictions({10, 20, 60});
+ int64_t sfToken1 = mTokenManager->generateTokenForPredictions({52, 60, 60});
+
+ auto surfaceFrame1 =
+ mFrameTimeline->createSurfaceFrameForToken({surfaceFrameToken1, sInputEventId}, sPidOne,
+ sUidOne, sLayerIdOne, sLayerNameOne,
+ sLayerNameOne);
+ mFrameTimeline->setSfWakeUp(sfToken1, 52, refreshRate);
+ surfaceFrame1->setAcquireFenceTime(20);
+ surfaceFrame1->setPresentState(SurfaceFrame::PresentState::Presented);
+ mFrameTimeline->addSurfaceFrame(surfaceFrame1);
+
+ mFrameTimeline->setSfPresent(59, presentFence1);
+ presentFence1->signalForTest(-1);
+ addEmptyDisplayFrame();
+
+ auto displayFrame0 = getDisplayFrame(0);
+ EXPECT_EQ(displayFrame0->getActuals().presentTime, -1);
+ EXPECT_EQ(displayFrame0->getJankType(), JankType::Unknown);
+ EXPECT_EQ(surfaceFrame1->getActuals().presentTime, -1);
+ EXPECT_EQ(surfaceFrame1->getJankType(), JankType::Unknown);
+}
+
// Tests related to TimeStats
+TEST_F(FrameTimelineTest, presentFenceSignaled_doesNotReportForInvalidTokens) {
+ Fps refreshRate = Fps::fromPeriodNsecs(11);
+ EXPECT_CALL(*mTimeStats, incrementJankyFrames(_)).Times(0);
+ auto presentFence1 = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
+ int64_t surfaceFrameToken1 = -1;
+ int64_t sfToken1 = -1;
+
+ auto surfaceFrame1 =
+ mFrameTimeline->createSurfaceFrameForToken({surfaceFrameToken1, sInputEventId}, sPidOne,
+ sUidOne, sLayerIdOne, sLayerNameOne,
+ sLayerNameOne);
+ mFrameTimeline->setSfWakeUp(sfToken1, 52, refreshRate);
+ surfaceFrame1->setAcquireFenceTime(20);
+ surfaceFrame1->setPresentState(SurfaceFrame::PresentState::Presented);
+ mFrameTimeline->addSurfaceFrame(surfaceFrame1);
+ presentFence1->signalForTest(70);
+
+ mFrameTimeline->setSfPresent(59, presentFence1);
+}
+
TEST_F(FrameTimelineTest, presentFenceSignaled_reportsLongSfCpu) {
Fps refreshRate = Fps::fromPeriodNsecs(11);
// Deadline delta is 2ms because, sf's adjusted deadline is 60 - composerTime(3) = 57ms.
@@ -602,6 +650,43 @@
EXPECT_EQ(surfaceFrame1->getJankType(), JankType::AppDeadlineMissed);
}
+TEST_F(FrameTimelineTest, presentFenceSignaled_displayFramePredictionExpiredPresentsSurfaceFrame) {
+ Fps refreshRate = Fps::fromPeriodNsecs(11);
+ Fps renderRate = Fps::fromPeriodNsecs(30);
+
+ EXPECT_CALL(*mTimeStats,
+ incrementJankyFrames(TimeStats::JankyFramesInfo{refreshRate, renderRate, sUidOne,
+ sLayerNameOne, JankType::Unknown,
+ -1, -1, 25}));
+ auto presentFence1 = fenceFactory.createFenceTimeForTest(Fence::NO_FENCE);
+ int64_t surfaceFrameToken1 = mTokenManager->generateTokenForPredictions({10, 20, 60});
+ int64_t sfToken1 = mTokenManager->generateTokenForPredictions({82, 90, 90});
+
+ auto surfaceFrame1 =
+ mFrameTimeline->createSurfaceFrameForToken({surfaceFrameToken1, sInputEventId}, sPidOne,
+ sUidOne, sLayerIdOne, sLayerNameOne,
+ sLayerNameOne);
+ surfaceFrame1->setAcquireFenceTime(45);
+ // Trigger a prediction expiry
+ flushTokens(systemTime() + maxTokenRetentionTime);
+ mFrameTimeline->setSfWakeUp(sfToken1, 52, refreshRate);
+
+ surfaceFrame1->setPresentState(SurfaceFrame::PresentState::Presented);
+ surfaceFrame1->setRenderRate(renderRate);
+ mFrameTimeline->addSurfaceFrame(surfaceFrame1);
+ presentFence1->signalForTest(90);
+ mFrameTimeline->setSfPresent(86, presentFence1);
+
+ auto displayFrame = getDisplayFrame(0);
+ EXPECT_EQ(displayFrame->getJankType(), JankType::Unknown);
+ EXPECT_EQ(displayFrame->getFrameStartMetadata(), FrameStartMetadata::UnknownStart);
+ EXPECT_EQ(displayFrame->getFrameReadyMetadata(), FrameReadyMetadata::UnknownFinish);
+ EXPECT_EQ(displayFrame->getFramePresentMetadata(), FramePresentMetadata::UnknownPresent);
+
+ EXPECT_EQ(surfaceFrame1->getActuals().presentTime, 90);
+ EXPECT_EQ(surfaceFrame1->getJankType(), JankType::Unknown);
+}
+
/*
* Tracing Tests
*
@@ -717,7 +802,7 @@
ProtoActualDisplayFrameStart createProtoActualDisplayFrameStart(
int64_t cookie, int64_t token, pid_t pid, ProtoPresentType presentType, bool onTimeFinish,
- bool gpuComposition, ProtoJankType jankType) {
+ bool gpuComposition, ProtoJankType jankType, ProtoPredictionType predictionType) {
ProtoActualDisplayFrameStart proto;
proto.set_cookie(cookie);
proto.set_token(token);
@@ -726,6 +811,7 @@
proto.set_on_time_finish(onTimeFinish);
proto.set_gpu_composition(gpuComposition);
proto.set_jank_type(jankType);
+ proto.set_prediction_type(predictionType);
return proto;
}
@@ -745,7 +831,7 @@
ProtoActualSurfaceFrameStart createProtoActualSurfaceFrameStart(
int64_t cookie, int64_t token, int64_t displayFrameToken, pid_t pid, std::string layerName,
ProtoPresentType presentType, bool onTimeFinish, bool gpuComposition,
- ProtoJankType jankType) {
+ ProtoJankType jankType, ProtoPredictionType predictionType) {
ProtoActualSurfaceFrameStart proto;
proto.set_cookie(cookie);
proto.set_token(token);
@@ -756,6 +842,7 @@
proto.set_on_time_finish(onTimeFinish);
proto.set_gpu_composition(gpuComposition);
proto.set_jank_type(jankType);
+ proto.set_prediction_type(predictionType);
return proto;
}
@@ -796,6 +883,8 @@
EXPECT_EQ(received.gpu_composition(), source.gpu_composition());
ASSERT_TRUE(received.has_jank_type());
EXPECT_EQ(received.jank_type(), source.jank_type());
+ ASSERT_TRUE(received.has_prediction_type());
+ EXPECT_EQ(received.prediction_type(), source.prediction_type());
}
void validateTraceEvent(const ProtoExpectedSurfaceFrameStart& received,
@@ -841,6 +930,8 @@
EXPECT_EQ(received.gpu_composition(), source.gpu_composition());
ASSERT_TRUE(received.has_jank_type());
EXPECT_EQ(received.jank_type(), source.jank_type());
+ ASSERT_TRUE(received.has_prediction_type());
+ EXPECT_EQ(received.prediction_type(), source.prediction_type());
}
void validateTraceEvent(const ProtoFrameEnd& received, const ProtoFrameEnd& source) {
@@ -869,7 +960,8 @@
createProtoActualDisplayFrameStart(traceCookie + 2, displayFrameToken1,
kSurfaceFlingerPid,
FrameTimelineEvent::PRESENT_ON_TIME, true, false,
- FrameTimelineEvent::JANK_NONE);
+ FrameTimelineEvent::JANK_NONE,
+ FrameTimelineEvent::PREDICTION_VALID);
auto protoActualDisplayFrameEnd = createProtoFrameEnd(traceCookie + 2);
addEmptyDisplayFrame();
@@ -944,7 +1036,8 @@
createProtoActualDisplayFrameStart(traceCookie + 1, displayFrameToken1,
kSurfaceFlingerPid,
FrameTimelineEvent::PRESENT_UNSPECIFIED, false,
- false, FrameTimelineEvent::JANK_UNKNOWN);
+ false, FrameTimelineEvent::JANK_UNKNOWN,
+ FrameTimelineEvent::PREDICTION_EXPIRED);
auto protoActualDisplayFrameEnd = createProtoFrameEnd(traceCookie + 1);
addEmptyDisplayFrame();
@@ -1014,7 +1107,8 @@
createProtoActualSurfaceFrameStart(traceCookie + 2, surfaceFrameToken,
displayFrameToken1, sPidOne, sLayerNameOne,
FrameTimelineEvent::PRESENT_DROPPED, false, false,
- FrameTimelineEvent::JANK_NONE);
+ FrameTimelineEvent::JANK_NONE,
+ FrameTimelineEvent::PREDICTION_VALID);
auto protoDroppedSurfaceFrameActualEnd = createProtoFrameEnd(traceCookie + 2);
auto protoPresentedSurfaceFrameExpectedStart =
@@ -1025,7 +1119,8 @@
createProtoActualSurfaceFrameStart(traceCookie + 4, surfaceFrameToken,
displayFrameToken1, sPidOne, sLayerNameOne,
FrameTimelineEvent::PRESENT_ON_TIME, true, false,
- FrameTimelineEvent::JANK_NONE);
+ FrameTimelineEvent::JANK_NONE,
+ FrameTimelineEvent::PREDICTION_VALID);
auto protoPresentedSurfaceFrameActualEnd = createProtoFrameEnd(traceCookie + 4);
// Set up the display frame
@@ -1167,7 +1262,8 @@
createProtoActualSurfaceFrameStart(traceCookie + 1, surfaceFrameToken,
displayFrameToken, sPidOne, sLayerNameOne,
FrameTimelineEvent::PRESENT_UNSPECIFIED, false,
- false, FrameTimelineEvent::JANK_UNKNOWN);
+ false, FrameTimelineEvent::JANK_UNKNOWN,
+ FrameTimelineEvent::PREDICTION_EXPIRED);
auto protoActualSurfaceFrameEnd = createProtoFrameEnd(traceCookie + 1);
// Set up the display frame
diff --git a/services/surfaceflinger/tests/utils/CallbackUtils.h b/services/surfaceflinger/tests/utils/CallbackUtils.h
index 1318deb..459b35c 100644
--- a/services/surfaceflinger/tests/utils/CallbackUtils.h
+++ b/services/surfaceflinger/tests/utils/CallbackUtils.h
@@ -81,6 +81,10 @@
mExpectedPresentTime = expectedPresentTime;
}
+ void addExpectedPresentTimeForVsyncId(nsecs_t expectedPresentTime) {
+ mExpectedPresentTimeForVsyncId = expectedPresentTime;
+ }
+
void verifyCallbackData(const CallbackData& callbackData) const {
const auto& [latchTime, presentFence, surfaceControlStats] = callbackData;
if (mTransactionResult == ExpectedResult::Transaction::PRESENTED) {
@@ -93,6 +97,11 @@
// misses vsync and we have to wait another 33.3ms
ASSERT_LE(presentFence->getSignalTime(),
mExpectedPresentTime + nsecs_t(66.666666 * 1e6));
+ } else if (mExpectedPresentTimeForVsyncId >= 0) {
+ ASSERT_EQ(presentFence->wait(3000), NO_ERROR);
+ // We give 4ms for prediction error
+ ASSERT_GE(presentFence->getSignalTime(),
+ mExpectedPresentTimeForVsyncId - 4'000'000);
}
} else {
ASSERT_EQ(presentFence, nullptr) << "transaction shouldn't have been presented";
@@ -151,6 +160,7 @@
};
ExpectedResult::Transaction mTransactionResult = ExpectedResult::Transaction::NOT_PRESENTED;
nsecs_t mExpectedPresentTime = -1;
+ nsecs_t mExpectedPresentTimeForVsyncId = -1;
std::unordered_map<sp<SurfaceControl>, ExpectedSurfaceResult, SCHash> mExpectedSurfaceResults;
};
diff --git a/services/surfaceflinger/tests/utils/ScreenshotUtils.h b/services/surfaceflinger/tests/utils/ScreenshotUtils.h
index 2fefa45..7efd730 100644
--- a/services/surfaceflinger/tests/utils/ScreenshotUtils.h
+++ b/services/surfaceflinger/tests/utils/ScreenshotUtils.h
@@ -159,6 +159,15 @@
}
}
+ Color getPixelColor(uint32_t x, uint32_t y) {
+ if (!mOutBuffer || mOutBuffer->getPixelFormat() != HAL_PIXEL_FORMAT_RGBA_8888) {
+ return {0, 0, 0, 0};
+ }
+
+ const uint8_t* pixel = mPixels + (4 * (y * mOutBuffer->getStride() + x));
+ return {pixel[0], pixel[1], pixel[2], pixel[3]};
+ }
+
void expectFGColor(uint32_t x, uint32_t y) { checkPixel(x, y, 195, 63, 63); }
void expectBGColor(uint32_t x, uint32_t y) { checkPixel(x, y, 63, 63, 195); }
diff --git a/services/vibratorservice/VibratorHalController.cpp b/services/vibratorservice/VibratorHalController.cpp
index bcd9957..537e49b 100644
--- a/services/vibratorservice/VibratorHalController.cpp
+++ b/services/vibratorservice/VibratorHalController.cpp
@@ -217,10 +217,10 @@
return apply(performEffectFn, "performEffect");
}
-HalResult<void> HalController::performComposedEffect(
+HalResult<milliseconds> HalController::performComposedEffect(
const std::vector<CompositeEffect>& primitiveEffects,
const std::function<void()>& completionCallback) {
- hal_fn<void> performComposedEffectFn = [&](std::shared_ptr<HalWrapper> hal) {
+ hal_fn<milliseconds> performComposedEffectFn = [&](std::shared_ptr<HalWrapper> hal) {
return hal->performComposedEffect(primitiveEffects, completionCallback);
};
return apply(performComposedEffectFn, "performComposedEffect");
diff --git a/services/vibratorservice/VibratorHalWrapper.cpp b/services/vibratorservice/VibratorHalWrapper.cpp
index 7fee82f..6faab38 100644
--- a/services/vibratorservice/VibratorHalWrapper.cpp
+++ b/services/vibratorservice/VibratorHalWrapper.cpp
@@ -224,12 +224,45 @@
return ret;
}
-HalResult<void> AidlHalWrapper::performComposedEffect(
+HalResult<milliseconds> AidlHalWrapper::performComposedEffect(
const std::vector<CompositeEffect>& primitiveEffects,
const std::function<void()>& completionCallback) {
// This method should always support callbacks, so no need to double check.
auto cb = new HalCallbackWrapper(completionCallback);
- return HalResult<void>::fromStatus(getHal()->compose(primitiveEffects, cb));
+ milliseconds duration(0);
+ for (const auto& effect : primitiveEffects) {
+ auto durationResult = getPrimitiveDuration(effect.primitive);
+ if (durationResult.isOk()) {
+ duration += durationResult.value();
+ }
+ duration += milliseconds(effect.delayMs);
+ }
+ return HalResult<milliseconds>::fromStatus(getHal()->compose(primitiveEffects, cb), duration);
+}
+
+HalResult<milliseconds> AidlHalWrapper::getPrimitiveDuration(CompositePrimitive primitive) {
+ std::lock_guard<std::mutex> lock(mSupportedPrimitivesMutex);
+ if (mPrimitiveDurations.empty()) {
+ constexpr auto primitiveRange = enum_range<CompositePrimitive>();
+ constexpr auto primitiveCount = std::distance(primitiveRange.begin(), primitiveRange.end());
+ mPrimitiveDurations.resize(primitiveCount);
+ }
+ auto primitiveIdx = static_cast<size_t>(primitive);
+ if (primitiveIdx >= mPrimitiveDurations.size()) {
+ // Safety check, should not happen if enum_range is correct.
+ return HalResult<milliseconds>::unsupported();
+ }
+ auto& cache = mPrimitiveDurations[primitiveIdx];
+ if (cache.has_value()) {
+ return HalResult<milliseconds>::ok(*cache);
+ }
+ int32_t duration;
+ auto result = getHal()->getPrimitiveDuration(primitive, &duration);
+ if (result.isOk()) {
+ // Cache copy of returned value.
+ cache.emplace(duration);
+ }
+ return HalResult<milliseconds>::fromStatus(result, milliseconds(duration));
}
HalResult<Capabilities> AidlHalWrapper::getCapabilitiesInternal() {
@@ -333,10 +366,10 @@
}
template <typename I>
-HalResult<void> HidlHalWrapper<I>::performComposedEffect(const std::vector<CompositeEffect>&,
- const std::function<void()>&) {
+HalResult<std::chrono::milliseconds> HidlHalWrapper<I>::performComposedEffect(
+ const std::vector<CompositeEffect>&, const std::function<void()>&) {
ALOGV("Skipped composed effect because Vibrator HAL AIDL is not available");
- return HalResult<void>::unsupported();
+ return HalResult<std::chrono::milliseconds>::unsupported();
}
template <typename I>
diff --git a/services/vibratorservice/include/vibratorservice/VibratorHalController.h b/services/vibratorservice/include/vibratorservice/VibratorHalController.h
index c405545..16d571d 100644
--- a/services/vibratorservice/include/vibratorservice/VibratorHalController.h
+++ b/services/vibratorservice/include/vibratorservice/VibratorHalController.h
@@ -77,7 +77,7 @@
hardware::vibrator::Effect effect, hardware::vibrator::EffectStrength strength,
const std::function<void()>& completionCallback) final override;
- HalResult<void> performComposedEffect(
+ HalResult<std::chrono::milliseconds> performComposedEffect(
const std::vector<hardware::vibrator::CompositeEffect>& primitiveEffects,
const std::function<void()>& completionCallback) final override;
diff --git a/services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h b/services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h
index 638b483..e22ad34 100644
--- a/services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h
+++ b/services/vibratorservice/include/vibratorservice/VibratorHalWrapper.h
@@ -189,7 +189,7 @@
hardware::vibrator::Effect effect, hardware::vibrator::EffectStrength strength,
const std::function<void()>& completionCallback) = 0;
- virtual HalResult<void> performComposedEffect(
+ virtual HalResult<std::chrono::milliseconds> performComposedEffect(
const std::vector<hardware::vibrator::CompositeEffect>& primitiveEffects,
const std::function<void()>& completionCallback) = 0;
@@ -236,7 +236,7 @@
hardware::vibrator::Effect effect, hardware::vibrator::EffectStrength strength,
const std::function<void()>& completionCallback) override final;
- HalResult<void> performComposedEffect(
+ HalResult<std::chrono::milliseconds> performComposedEffect(
const std::vector<hardware::vibrator::CompositeEffect>& primitiveEffects,
const std::function<void()>& completionCallback) override final;
@@ -252,6 +252,12 @@
GUARDED_BY(mSupportedEffectsMutex);
std::optional<std::vector<hardware::vibrator::CompositePrimitive>> mSupportedPrimitives
GUARDED_BY(mSupportedPrimitivesMutex);
+ std::vector<std::optional<std::chrono::milliseconds>> mPrimitiveDurations
+ GUARDED_BY(mSupportedPrimitivesMutex);
+
+ // Loads and caches from IVibrator.
+ HalResult<std::chrono::milliseconds> getPrimitiveDuration(
+ hardware::vibrator::CompositePrimitive primitive);
// Loads directly from IVibrator handle, skipping caches.
HalResult<Capabilities> getCapabilitiesInternal();
@@ -287,7 +293,7 @@
HalResult<std::vector<hardware::vibrator::CompositePrimitive>> getSupportedPrimitives()
override final;
- HalResult<void> performComposedEffect(
+ HalResult<std::chrono::milliseconds> performComposedEffect(
const std::vector<hardware::vibrator::CompositeEffect>& primitiveEffects,
const std::function<void()>& completionCallback) override final;
diff --git a/services/vibratorservice/test/VibratorHalControllerTest.cpp b/services/vibratorservice/test/VibratorHalControllerTest.cpp
index 2d9d0d6..c4b39ed 100644
--- a/services/vibratorservice/test/VibratorHalControllerTest.cpp
+++ b/services/vibratorservice/test/VibratorHalControllerTest.cpp
@@ -71,7 +71,7 @@
(Effect effect, EffectStrength strength,
const std::function<void()>& completionCallback),
(override));
- MOCK_METHOD(vibrator::HalResult<void>, performComposedEffect,
+ MOCK_METHOD(vibrator::HalResult<milliseconds>, performComposedEffect,
(const std::vector<CompositeEffect>& primitiveEffects,
const std::function<void()>& completionCallback),
(override));
@@ -143,7 +143,7 @@
.WillRepeatedly(Return(durationResult));
EXPECT_CALL(*mMockHal.get(), performComposedEffect(Eq(compositeEffects), _))
.Times(Exactly(cardinality))
- .WillRepeatedly(Return(voidResult));
+ .WillRepeatedly(Return(durationResult));
if (cardinality > 1) {
// One reconnection call after each failure.
@@ -208,7 +208,10 @@
ASSERT_TRUE(performEffectResult.isOk());
ASSERT_EQ(100ms, performEffectResult.value());
- ASSERT_TRUE(mController->performComposedEffect(compositeEffects, []() {}).isOk());
+ auto performComposedEffectResult =
+ mController->performComposedEffect(compositeEffects, []() {});
+ ASSERT_TRUE(performComposedEffectResult.isOk());
+ ASSERT_EQ(100ms, performComposedEffectResult.value());
ASSERT_EQ(1, mConnectCounter);
}
diff --git a/services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp b/services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp
index f85fa10..8b5caa5 100644
--- a/services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp
+++ b/services/vibratorservice/test/VibratorHalWrapperAidlTest.cpp
@@ -506,10 +506,21 @@
EXPECT_CALL(*mMockHal.get(), compose(Eq(emptyEffects), _))
.Times(Exactly(1))
.WillRepeatedly(DoAll(TriggerCallbackInArg1(), Return(Status())));
+
+ EXPECT_CALL(*mMockHal.get(), getPrimitiveDuration(Eq(CompositePrimitive::CLICK), _))
+ .Times(Exactly(1))
+ .WillRepeatedly(DoAll(SetArgPointee<1>(1), Return(Status())));
EXPECT_CALL(*mMockHal.get(), compose(Eq(singleEffect), _))
.Times(Exactly(1))
.WillRepeatedly(Return(
Status::fromExceptionCode(Status::Exception::EX_UNSUPPORTED_OPERATION)));
+
+ EXPECT_CALL(*mMockHal.get(), getPrimitiveDuration(Eq(CompositePrimitive::SPIN), _))
+ .Times(Exactly(1))
+ .WillRepeatedly(DoAll(SetArgPointee<1>(2), Return(Status())));
+ EXPECT_CALL(*mMockHal.get(), getPrimitiveDuration(Eq(CompositePrimitive::THUD), _))
+ .Times(Exactly(1))
+ .WillRepeatedly(DoAll(SetArgPointee<1>(3), Return(Status())));
EXPECT_CALL(*mMockHal.get(), compose(Eq(multipleEffects), _))
.Times(Exactly(1))
.WillRepeatedly(Return(Status::fromExceptionCode(Status::Exception::EX_SECURITY)));
@@ -520,6 +531,7 @@
auto result = mWrapper->performComposedEffect(emptyEffects, callback);
ASSERT_TRUE(result.isOk());
+ ASSERT_EQ(0ms, result.value());
ASSERT_EQ(1, *callbackCounter.get());
result = mWrapper->performComposedEffect(singleEffect, callback);
@@ -532,3 +544,40 @@
// Callback not triggered on failure
ASSERT_EQ(1, *callbackCounter.get());
}
+
+TEST_F(VibratorHalWrapperAidlTest, TestPerformComposedCachesPrimitiveDurationsAndIgnoresFailures) {
+ std::vector<CompositeEffect> multipleEffects;
+ multipleEffects.push_back(
+ vibrator::TestFactory::createCompositeEffect(CompositePrimitive::SPIN, 10ms, 0.5f));
+ multipleEffects.push_back(
+ vibrator::TestFactory::createCompositeEffect(CompositePrimitive::THUD, 100ms, 1.0f));
+
+ EXPECT_CALL(*mMockHal.get(), getPrimitiveDuration(Eq(CompositePrimitive::SPIN), _))
+ .Times(Exactly(1))
+ .WillRepeatedly(DoAll(SetArgPointee<1>(1), Return(Status())));
+ EXPECT_CALL(*mMockHal.get(), getPrimitiveDuration(Eq(CompositePrimitive::THUD), _))
+ .Times(Exactly(2))
+ .WillOnce(Return(Status::fromExceptionCode(Status::Exception::EX_SECURITY)))
+ .WillRepeatedly(DoAll(SetArgPointee<1>(2), Return(Status())));
+ EXPECT_CALL(*mMockHal.get(), compose(Eq(multipleEffects), _))
+ .Times(Exactly(3))
+ .WillRepeatedly(DoAll(TriggerCallbackInArg1(), Return(Status())));
+
+ std::unique_ptr<int32_t> callbackCounter = std::make_unique<int32_t>();
+ auto callback = vibrator::TestFactory::createCountingCallback(callbackCounter.get());
+
+ auto result = mWrapper->performComposedEffect(multipleEffects, callback);
+ ASSERT_TRUE(result.isOk());
+ ASSERT_EQ(111ms, result.value()); // Failed primitive duration counted as 0.
+ ASSERT_EQ(1, *callbackCounter.get());
+
+ result = mWrapper->performComposedEffect(multipleEffects, callback);
+ ASSERT_TRUE(result.isOk());
+ ASSERT_EQ(113ms, result.value()); // Second fetch succeeds and returns primitive duration.
+ ASSERT_EQ(2, *callbackCounter.get());
+
+ result = mWrapper->performComposedEffect(multipleEffects, callback);
+ ASSERT_TRUE(result.isOk());
+ ASSERT_EQ(113ms, result.value()); // Cached durations not fetched again, same duration returned.
+ ASSERT_EQ(3, *callbackCounter.get());
+}
diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp
index cb845a0..020b520 100644
--- a/vulkan/libvulkan/swapchain.cpp
+++ b/vulkan/libvulkan/swapchain.cpp
@@ -1093,13 +1093,6 @@
return VK_ERROR_SURFACE_LOST_KHR;
}
- err = native_window_set_buffer_count(window, 0);
- if (err != android::OK) {
- ALOGE("native_window_set_buffer_count(0) failed: %s (%d)",
- strerror(-err), err);
- return VK_ERROR_SURFACE_LOST_KHR;
- }
-
int swap_interval =
create_info->presentMode == VK_PRESENT_MODE_MAILBOX_KHR ? 0 : 1;
err = window->setSwapInterval(window, swap_interval);
@@ -1707,7 +1700,7 @@
if (err != android::OK) {
ALOGE("queueBuffer failed: %s (%d)", strerror(-err), err);
swapchain_result = WorstPresentResult(
- swapchain_result, VK_ERROR_OUT_OF_DATE_KHR);
+ swapchain_result, VK_ERROR_SURFACE_LOST_KHR);
} else {
if (img.dequeue_fence >= 0) {
close(img.dequeue_fence);
diff --git a/vulkan/vkjson/vkjson_info.cc b/vulkan/vkjson/vkjson_info.cc
deleted file mode 100644
index 3c4b08b..0000000
--- a/vulkan/vkjson/vkjson_info.cc
+++ /dev/null
@@ -1,184 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2015-2016 The Khronos Group Inc.
-// Copyright (c) 2015-2016 Valve Corporation
-// Copyright (c) 2015-2016 LunarG, Inc.
-// Copyright (c) 2015-2016 Google, Inc.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-///////////////////////////////////////////////////////////////////////////////
-
-#ifndef VK_PROTOTYPES
-#define VK_PROTOTYPES
-#endif
-
-#include "vkjson.h"
-
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <iostream>
-#include <vector>
-
-const uint32_t unsignedNegOne = (uint32_t)(-1);
-
-struct Options {
- bool instance = false;
- uint32_t device_index = unsignedNegOne;
- std::string device_name;
- std::string output_file;
-};
-
-bool ParseOptions(int argc, char* argv[], Options* options) {
- for (int i = 1; i < argc; ++i) {
- std::string arg(argv[i]);
- if (arg == "--instance" || arg == "-i") {
- options->instance = true;
- } else if (arg == "--first" || arg == "-f") {
- options->device_index = 0;
- } else {
- ++i;
- if (i >= argc) {
- std::cerr << "Missing parameter after: " << arg << std::endl;
- return false;
- }
- std::string arg2(argv[i]);
- if (arg == "--device-index" || arg == "-d") {
- int result = sscanf(arg2.c_str(), "%u", &options->device_index);
- if (result != 1) {
- options->device_index = static_cast<uint32_t>(-1);
- std::cerr << "Unable to parse index: " << arg2 << std::endl;
- return false;
- }
- } else if (arg == "--device-name" || arg == "-n") {
- options->device_name = arg2;
- } else if (arg == "--output" || arg == "-o") {
- options->output_file = arg2;
- } else {
- std::cerr << "Unknown argument: " << arg << std::endl;
- return false;
- }
- }
- }
- if (options->instance && (options->device_index != unsignedNegOne ||
- !options->device_name.empty())) {
- std::cerr << "Specifying a specific device is incompatible with dumping "
- "the whole instance." << std::endl;
- return false;
- }
- if (options->device_index != unsignedNegOne && !options->device_name.empty()) {
- std::cerr << "Must specify only one of device index and device name."
- << std::endl;
- return false;
- }
- if (options->instance && options->output_file.empty()) {
- std::cerr << "Must specify an output file when dumping the whole instance."
- << std::endl;
- return false;
- }
- if (!options->output_file.empty() && !options->instance &&
- options->device_index == unsignedNegOne && options->device_name.empty()) {
- std::cerr << "Must specify instance, device index, or device name when "
- "specifying "
- "output file." << std::endl;
- return false;
- }
- return true;
-}
-
-bool Dump(const VkJsonInstance& instance, const Options& options) {
- const VkJsonDevice* out_device = nullptr;
- if (options.device_index != unsignedNegOne) {
- if (static_cast<uint32_t>(options.device_index) >=
- instance.devices.size()) {
- std::cerr << "Error: device " << options.device_index
- << " requested but only " << instance.devices.size()
- << " devices found." << std::endl;
- return false;
- }
- out_device = &instance.devices[options.device_index];
- } else if (!options.device_name.empty()) {
- for (const auto& device : instance.devices) {
- if (device.properties.deviceName == options.device_name) {
- out_device = &device;
- }
- }
- if (!out_device) {
- std::cerr << "Error: device '" << options.device_name
- << "' requested but not found." << std::endl;
- return false;
- }
- }
-
- std::string output_file;
- if (options.output_file.empty()) {
- assert(out_device);
-#if defined(ANDROID)
- output_file.assign("/sdcard/Android/" + std::string(out_device->properties.deviceName));
-#else
- output_file.assign(out_device->properties.deviceName);
-#endif
- output_file.append(".json");
- } else {
- output_file = options.output_file;
- }
- FILE* file = nullptr;
- if (output_file == "-") {
- file = stdout;
- } else {
- file = fopen(output_file.c_str(), "w");
- if (!file) {
- std::cerr << "Unable to open file " << output_file << "." << std::endl;
- return false;
- }
- }
-
- std::string json = out_device ? VkJsonDeviceToJson(*out_device)
- : VkJsonInstanceToJson(instance);
- fwrite(json.data(), 1, json.size(), file);
- fputc('\n', file);
-
- if (output_file != "-") {
- fclose(file);
- std::cout << "Wrote file " << output_file;
- if (out_device)
- std::cout << " for device " << out_device->properties.deviceName;
- std::cout << "." << std::endl;
- }
- return true;
-}
-
-int main(int argc, char* argv[]) {
-#if defined(ANDROID)
- int vulkanSupport = InitVulkan();
- if (vulkanSupport == 0)
- return 1;
-#endif
- Options options;
- if (!ParseOptions(argc, argv, &options))
- return 1;
-
- VkJsonInstance instance = VkJsonGetInstance();
- if (options.instance || options.device_index != unsignedNegOne ||
- !options.device_name.empty()) {
- Dump(instance, options);
- } else {
- for (uint32_t i = 0, n = static_cast<uint32_t>(instance.devices.size()); i < n; i++) {
- options.device_index = i;
- Dump(instance, options);
- }
- }
-
- return 0;
-}
diff --git a/vulkan/vkjson/vkjson_unittest.cc b/vulkan/vkjson/vkjson_unittest.cc
deleted file mode 100644
index de765cd..0000000
--- a/vulkan/vkjson/vkjson_unittest.cc
+++ /dev/null
@@ -1,101 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////
-//
-// Copyright (c) 2015-2016 The Khronos Group Inc.
-// Copyright (c) 2015-2016 Valve Corporation
-// Copyright (c) 2015-2016 LunarG, Inc.
-// Copyright (c) 2015-2016 Google, Inc.
-//
-// 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 "vkjson.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-#include <iostream>
-
-#define EXPECT(X) if (!(X)) \
- ReportFailure(__FILE__, __LINE__, #X);
-
-#define ASSERT(X) if (!(X)) { \
- ReportFailure(__FILE__, __LINE__, #X); \
- return 2; \
-}
-
-int g_failures;
-
-void ReportFailure(const char* file, int line, const char* assertion) {
- std::cout << file << ":" << line << ": \"" << assertion << "\" failed."
- << std::endl;
- ++g_failures;
-}
-
-int main(int argc, char* argv[]) {
- std::string errors;
- bool result = false;
-
- VkJsonInstance instance;
- instance.devices.resize(1);
- VkJsonDevice& device = instance.devices[0];
-
- const char name[] = "Test device";
- memcpy(device.properties.deviceName, name, sizeof(name));
- device.properties.limits.maxImageDimension1D = 3;
- device.properties.limits.maxSamplerLodBias = 3.5f;
- device.properties.limits.bufferImageGranularity = 0x1ffffffffull;
- device.properties.limits.maxViewportDimensions[0] = 1;
- device.properties.limits.maxViewportDimensions[1] = 2;
- VkFormatProperties format_props = {
- VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT,
- VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT,
- VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT};
- device.formats.insert(std::make_pair(VK_FORMAT_R8_UNORM, format_props));
- device.formats.insert(std::make_pair(VK_FORMAT_R8G8_UNORM, format_props));
-
- std::string json = VkJsonInstanceToJson(instance);
- std::cout << json << std::endl;
-
- VkJsonInstance instance2;
- result = VkJsonInstanceFromJson(json, &instance2, &errors);
- EXPECT(result);
- if (!result)
- std::cout << "Error: " << errors << std::endl;
- const VkJsonDevice& device2 = instance2.devices.at(0);
-
- EXPECT(!memcmp(&device.properties, &device2.properties,
- sizeof(device.properties)));
- for (auto& kv : device.formats) {
- auto it = device2.formats.find(kv.first);
- EXPECT(it != device2.formats.end());
- EXPECT(!memcmp(&kv.second, &it->second, sizeof(kv.second)));
- }
-
- VkImageFormatProperties props = {};
- json = VkJsonImageFormatPropertiesToJson(props);
- VkImageFormatProperties props2 = {};
- result = VkJsonImageFormatPropertiesFromJson(json, &props2, &errors);
- EXPECT(result);
- if (!result)
- std::cout << "Error: " << errors << std::endl;
-
- EXPECT(!memcmp(&props, &props2, sizeof(props)));
-
- if (g_failures) {
- std::cout << g_failures << " failures." << std::endl;
- return 1;
- } else {
- std::cout << "Success." << std::endl;
- return 0;
- }
-}