summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/android/bitmap.h2
-rw-r--r--include/android/choreographer.h2
-rw-r--r--include/android/surface_control.h2
-rw-r--r--include/input/Input.h53
-rw-r--r--include/input/InputTransport.h57
-rw-r--r--include/input/LatencyStatistics.h59
6 files changed, 122 insertions, 53 deletions
diff --git a/include/android/bitmap.h b/include/android/bitmap.h
index 2def64dc90..6fba0ac9ca 100644
--- a/include/android/bitmap.h
+++ b/include/android/bitmap.h
@@ -60,6 +60,8 @@ enum AndroidBitmapFormat {
ANDROID_BITMAP_FORMAT_RGBA_4444 = 7,
/** Alpha: 8 bits. */
ANDROID_BITMAP_FORMAT_A_8 = 8,
+ /** Each component is stored as a half float. **/
+ ANDROID_BITMAP_FORMAT_RGBA_F16 = 9,
};
/** Bitmap info, see AndroidBitmap_getInfo(). */
diff --git a/include/android/choreographer.h b/include/android/choreographer.h
index 44883cc498..1b589bca72 100644
--- a/include/android/choreographer.h
+++ b/include/android/choreographer.h
@@ -83,7 +83,7 @@ void AChoreographer_postFrameCallbackDelayed(AChoreographer* choreographer,
* Power a callback to be run on the next frame. The data pointer provided will
* be passed to the callback function when it's called.
*/
-void AChoreographer_postFrameCallback64(AChoreographer* chroreographer,
+void AChoreographer_postFrameCallback64(AChoreographer* choreographer,
AChoreographer_frameCallback64 callback, void* data) __INTRODUCED_IN(29);
/**
diff --git a/include/android/surface_control.h b/include/android/surface_control.h
index ef2ad9998c..abb8368069 100644
--- a/include/android/surface_control.h
+++ b/include/android/surface_control.h
@@ -130,7 +130,7 @@ int64_t ASurfaceTransactionStats_getLatchTime(ASurfaceTransactionStats* surface_
/**
* Returns a sync fence that signals when the transaction has been presented.
* The recipient of the callback takes ownership of the fence and is responsible for closing
- * it.
+ * it. If a device does not support present fences, a -1 will be returned.
*/
int ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats* surface_transaction_stats)
__INTRODUCED_IN(29);
diff --git a/include/input/Input.h b/include/input/Input.h
index 805957a5ca..cbd1a412bf 100644
--- a/include/input/Input.h
+++ b/include/input/Input.h
@@ -24,12 +24,15 @@
*/
#include <android/input.h>
+#include <math.h>
+#include <stdint.h>
#include <utils/BitSet.h>
#include <utils/KeyedVector.h>
#include <utils/RefBase.h>
#include <utils/Timers.h>
#include <utils/Vector.h>
-#include <stdint.h>
+
+#include <limits>
/*
* Additional private constants not defined in ndk/ui/input.h.
@@ -246,6 +249,13 @@ enum class MotionClassification : uint8_t {
*/
const char* motionClassificationToString(MotionClassification classification);
+/**
+ * Invalid value for cursor position. Used for non-mouse events, tests and injected events. Don't
+ * use it for direct comparison with any other value, because NaN isn't equal to itself according to
+ * IEEE 754. Use isnan() instead to check if a cursor position is valid.
+ */
+constexpr float AMOTION_EVENT_INVALID_CURSOR_POSITION = std::numeric_limits<float>::quiet_NaN();
+
/*
* Pointer coordinate data.
*/
@@ -459,6 +469,18 @@ public:
inline float getYPrecision() const { return mYPrecision; }
+ inline float getRawXCursorPosition() const { return mRawXCursorPosition; }
+
+ float getXCursorPosition() const;
+
+ inline float getRawYCursorPosition() const { return mRawYCursorPosition; }
+
+ float getYCursorPosition() const;
+
+ void setCursorPosition(float x, float y);
+
+ static inline bool isValidCursorPosition(float x, float y) { return !isnan(x) && !isnan(y); }
+
inline nsecs_t getDownTime() const { return mDownTime; }
inline void setDownTime(nsecs_t downTime) { mDownTime = downTime; }
@@ -600,26 +622,13 @@ public:
ssize_t findPointerIndex(int32_t pointerId) const;
- void initialize(
- int32_t deviceId,
- int32_t source,
- int32_t displayId,
- int32_t action,
- int32_t actionButton,
- int32_t flags,
- int32_t edgeFlags,
- int32_t metaState,
- int32_t buttonState,
- MotionClassification classification,
- float xOffset,
- float yOffset,
- float xPrecision,
- float yPrecision,
- nsecs_t downTime,
- nsecs_t eventTime,
- size_t pointerCount,
- const PointerProperties* pointerProperties,
- const PointerCoords* pointerCoords);
+ void initialize(int32_t deviceId, int32_t source, int32_t displayId, int32_t action,
+ int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState,
+ int32_t buttonState, MotionClassification classification, float xOffset,
+ float yOffset, float xPrecision, float yPrecision, float rawXCursorPosition,
+ float rawYCursorPosition, nsecs_t downTime, nsecs_t eventTime,
+ size_t pointerCount, const PointerProperties* pointerProperties,
+ const PointerCoords* pointerCoords);
void copyFrom(const MotionEvent* other, bool keepHistory);
@@ -669,6 +678,8 @@ protected:
float mYOffset;
float mXPrecision;
float mYPrecision;
+ float mRawXCursorPosition;
+ float mRawYCursorPosition;
nsecs_t mDownTime;
Vector<PointerProperties> mPointerProperties;
Vector<nsecs_t> mSampleEventTimes;
diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h
index 63606e5911..28b8d80074 100644
--- a/include/input/InputTransport.h
+++ b/include/input/InputTransport.h
@@ -31,13 +31,18 @@
#include <string>
+#include <android-base/chrono_utils.h>
+
#include <binder/IBinder.h>
#include <input/Input.h>
+#include <input/LatencyStatistics.h>
+#include <utils/BitSet.h>
#include <utils/Errors.h>
-#include <utils/Timers.h>
#include <utils/RefBase.h>
+#include <utils/Timers.h>
#include <utils/Vector.h>
-#include <utils/BitSet.h>
+
+#include <android-base/unique_fd.h>
namespace android {
class Parcel;
@@ -113,6 +118,8 @@ struct InputMessage {
float yOffset;
float xPrecision;
float yPrecision;
+ float xCursorPosition;
+ float yCursorPosition;
uint32_t pointerCount;
uint32_t empty3;
// Note that PointerCoords requires 8 byte alignment.
@@ -161,8 +168,7 @@ protected:
virtual ~InputChannel();
public:
- InputChannel() = default;
- InputChannel(const std::string& name, int fd);
+ static sp<InputChannel> create(const std::string& name, android::base::unique_fd fd);
/* Creates a pair of input channels.
*
@@ -172,7 +178,7 @@ public:
sp<InputChannel>& outServerChannel, sp<InputChannel>& outClientChannel);
inline std::string getName() const { return mName; }
- inline int getFd() const { return mFd; }
+ inline int getFd() const { return mFd.get(); }
/* Sends a message to the other endpoint.
*
@@ -203,16 +209,15 @@ public:
sp<InputChannel> dup() const;
status_t write(Parcel& out) const;
- status_t read(const Parcel& from);
+ static sp<InputChannel> read(const Parcel& from);
sp<IBinder> getToken() const;
void setToken(const sp<IBinder>& token);
private:
- void setFd(int fd);
-
+ InputChannel(const std::string& name, android::base::unique_fd fd);
std::string mName;
- int mFd = -1;
+ android::base::unique_fd mFd;
sp<IBinder> mToken = nullptr;
};
@@ -261,27 +266,14 @@ public:
* Returns BAD_VALUE if seq is 0 or if pointerCount is less than 1 or greater than MAX_POINTERS.
* Other errors probably indicate that the channel is broken.
*/
- status_t publishMotionEvent(
- uint32_t seq,
- int32_t deviceId,
- int32_t source,
- int32_t displayId,
- int32_t action,
- int32_t actionButton,
- int32_t flags,
- int32_t edgeFlags,
- int32_t metaState,
- int32_t buttonState,
- MotionClassification classification,
- float xOffset,
- float yOffset,
- float xPrecision,
- float yPrecision,
- nsecs_t downTime,
- nsecs_t eventTime,
- uint32_t pointerCount,
- const PointerProperties* pointerProperties,
- const PointerCoords* pointerCoords);
+ status_t publishMotionEvent(uint32_t seq, int32_t deviceId, int32_t source, int32_t displayId,
+ int32_t action, int32_t actionButton, int32_t flags,
+ int32_t edgeFlags, int32_t metaState, int32_t buttonState,
+ MotionClassification classification, float xOffset, float yOffset,
+ float xPrecision, float yPrecision, float xCursorPosition,
+ float yCursorPosition, nsecs_t downTime, nsecs_t eventTime,
+ uint32_t pointerCount, const PointerProperties* pointerProperties,
+ const PointerCoords* pointerCoords);
/* Receives the finished signal from the consumer in reply to the original dispatch signal.
* If a signal was received, returns the message sequence number,
@@ -297,7 +289,12 @@ public:
status_t receiveFinishedSignal(uint32_t* outSeq, bool* outHandled);
private:
+ static constexpr std::chrono::duration TOUCH_STATS_REPORT_PERIOD = 5min;
+
sp<InputChannel> mChannel;
+ LatencyStatistics mTouchStatistics{TOUCH_STATS_REPORT_PERIOD};
+
+ void reportTouchEventForStatistics(nsecs_t evdevTime);
};
/*
diff --git a/include/input/LatencyStatistics.h b/include/input/LatencyStatistics.h
new file mode 100644
index 0000000000..bd86266901
--- /dev/null
+++ b/include/input/LatencyStatistics.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _UI_INPUT_STATISTICS_H
+#define _UI_INPUT_STATISTICS_H
+
+#include <android-base/chrono_utils.h>
+
+#include <stddef.h>
+
+namespace android {
+
+class LatencyStatistics {
+private:
+ /* Minimum sample recorded */
+ float mMin;
+ /* Maximum sample recorded */
+ float mMax;
+ /* Sum of all samples recorded */
+ float mSum;
+ /* Sum of all the squares of samples recorded */
+ float mSum2;
+ /* Count of all samples recorded */
+ size_t mCount;
+ /* The last time statistics were reported */
+ std::chrono::steady_clock::time_point mLastReportTime;
+ /* Statistics Report Frequency */
+ const std::chrono::seconds mReportPeriod;
+
+public:
+ LatencyStatistics(std::chrono::seconds period);
+
+ void addValue(float);
+ void reset();
+ bool shouldReport();
+
+ float getMean();
+ float getMin();
+ float getMax();
+ float getStDev();
+ size_t getCount();
+};
+
+} // namespace android
+
+#endif // _UI_INPUT_STATISTICS_H