Merge "Return Key* from getKey" into udc-dev
diff --git a/libs/binder/RecordedTransaction.cpp b/libs/binder/RecordedTransaction.cpp
index ef58ed3..1c76135 100644
--- a/libs/binder/RecordedTransaction.cpp
+++ b/libs/binder/RecordedTransaction.cpp
@@ -131,12 +131,12 @@
return std::nullopt;
}
- if (t.mSent.setData(dataParcel.data(), dataParcel.dataSize()) != android::NO_ERROR) {
+ if (t.mSent.setData(dataParcel.data(), dataParcel.dataBufferSize()) != android::NO_ERROR) {
LOG(ERROR) << "Failed to set sent parcel data.";
return std::nullopt;
}
- if (t.mReply.setData(replyParcel.data(), replyParcel.dataSize()) != android::NO_ERROR) {
+ if (t.mReply.setData(replyParcel.data(), replyParcel.dataBufferSize()) != android::NO_ERROR) {
LOG(ERROR) << "Failed to set reply parcel data.";
return std::nullopt;
}
@@ -349,11 +349,11 @@
return UNKNOWN_ERROR;
}
- if (NO_ERROR != writeChunk(fd, DATA_PARCEL_CHUNK, mSent.dataSize(), mSent.data())) {
+ if (NO_ERROR != writeChunk(fd, DATA_PARCEL_CHUNK, mSent.dataBufferSize(), mSent.data())) {
LOG(ERROR) << "Failed to write sent Parcel to fd " << fd.get();
return UNKNOWN_ERROR;
}
- if (NO_ERROR != writeChunk(fd, REPLY_PARCEL_CHUNK, mReply.dataSize(), mReply.data())) {
+ if (NO_ERROR != writeChunk(fd, REPLY_PARCEL_CHUNK, mReply.dataBufferSize(), mReply.data())) {
LOG(ERROR) << "Failed to write reply Parcel to fd " << fd.get();
return UNKNOWN_ERROR;
}
diff --git a/libs/binder/trusty/RpcServerTrusty.cpp b/libs/binder/trusty/RpcServerTrusty.cpp
index 3a99606..68b0008 100644
--- a/libs/binder/trusty/RpcServerTrusty.cpp
+++ b/libs/binder/trusty/RpcServerTrusty.cpp
@@ -65,6 +65,10 @@
mTipcPort.msg_queue_len = 6; // Three each way
mTipcPort.priv = this;
+ // TODO(b/266741352): follow-up to prevent needing this in the future
+ // Trusty needs to be set to the latest stable version that is in prebuilts there.
+ mRpcServer->setProtocolVersion(0);
+
if (mPortAcl) {
// Initialize the array of pointers to uuids.
// The pointers in mUuidPtrs should stay valid across moves of
diff --git a/libs/jpegrecoverymap/tests/jpegencoderhelper_test.cpp b/libs/jpegrecoverymap/tests/jpegencoderhelper_test.cpp
deleted file mode 100644
index 095ac2f..0000000
--- a/libs/jpegrecoverymap/tests/jpegencoderhelper_test.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright 2022 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <jpegrecoverymap/jpegencoderhelper.h>
-#include <gtest/gtest.h>
-#include <utils/Log.h>
-
-#include <fcntl.h>
-
-namespace android::jpegrecoverymap {
-
-#define VALID_IMAGE "/sdcard/Documents/minnie-320x240.yu12"
-#define VALID_IMAGE_WIDTH 320
-#define VALID_IMAGE_HEIGHT 240
-#define SINGLE_CHANNEL_IMAGE "/sdcard/Documents/minnie-320x240.y"
-#define SINGLE_CHANNEL_IMAGE_WIDTH VALID_IMAGE_WIDTH
-#define SINGLE_CHANNEL_IMAGE_HEIGHT VALID_IMAGE_HEIGHT
-#define INVALID_SIZE_IMAGE "/sdcard/Documents/minnie-318x240.yu12"
-#define INVALID_SIZE_IMAGE_WIDTH 318
-#define INVALID_SIZE_IMAGE_HEIGHT 240
-#define JPEG_QUALITY 90
-
-class JpegEncoderHelperTest : public testing::Test {
-public:
- struct Image {
- std::unique_ptr<uint8_t[]> buffer;
- size_t width;
- size_t height;
- };
- JpegEncoderHelperTest();
- ~JpegEncoderHelperTest();
-protected:
- virtual void SetUp();
- virtual void TearDown();
-
- Image mValidImage, mInvalidSizeImage, mSingleChannelImage;
-};
-
-JpegEncoderHelperTest::JpegEncoderHelperTest() {}
-
-JpegEncoderHelperTest::~JpegEncoderHelperTest() {}
-
-static size_t getFileSize(int fd) {
- struct stat st;
- if (fstat(fd, &st) < 0) {
- ALOGW("%s : fstat failed", __func__);
- return 0;
- }
- return st.st_size; // bytes
-}
-
-static bool loadFile(const char filename[], JpegEncoderHelperTest::Image* result) {
- int fd = open(filename, O_CLOEXEC);
- if (fd < 0) {
- return false;
- }
- int length = getFileSize(fd);
- if (length == 0) {
- close(fd);
- return false;
- }
- result->buffer.reset(new uint8_t[length]);
- if (read(fd, result->buffer.get(), length) != static_cast<ssize_t>(length)) {
- close(fd);
- return false;
- }
- close(fd);
- return true;
-}
-
-void JpegEncoderHelperTest::SetUp() {
- if (!loadFile(VALID_IMAGE, &mValidImage)) {
- FAIL() << "Load file " << VALID_IMAGE << " failed";
- }
- mValidImage.width = VALID_IMAGE_WIDTH;
- mValidImage.height = VALID_IMAGE_HEIGHT;
- if (!loadFile(INVALID_SIZE_IMAGE, &mInvalidSizeImage)) {
- FAIL() << "Load file " << INVALID_SIZE_IMAGE << " failed";
- }
- mInvalidSizeImage.width = INVALID_SIZE_IMAGE_WIDTH;
- mInvalidSizeImage.height = INVALID_SIZE_IMAGE_HEIGHT;
- if (!loadFile(SINGLE_CHANNEL_IMAGE, &mSingleChannelImage)) {
- FAIL() << "Load file " << SINGLE_CHANNEL_IMAGE << " failed";
- }
- mSingleChannelImage.width = SINGLE_CHANNEL_IMAGE_WIDTH;
- mSingleChannelImage.height = SINGLE_CHANNEL_IMAGE_HEIGHT;
-}
-
-void JpegEncoderHelperTest::TearDown() {}
-
-TEST_F(JpegEncoderHelperTest, validImage) {
- JpegEncoderHelper encoder;
- EXPECT_TRUE(encoder.compressImage(mValidImage.buffer.get(), mValidImage.width,
- mValidImage.height, JPEG_QUALITY, NULL, 0));
- ASSERT_GT(encoder.getCompressedImageSize(), static_cast<uint32_t>(0));
-}
-
-TEST_F(JpegEncoderHelperTest, invalidSizeImage) {
- JpegEncoderHelper encoder;
- EXPECT_FALSE(encoder.compressImage(mInvalidSizeImage.buffer.get(), mInvalidSizeImage.width,
- mInvalidSizeImage.height, JPEG_QUALITY, NULL, 0));
-}
-
-TEST_F(JpegEncoderHelperTest, singleChannelImage) {
- JpegEncoderHelper encoder;
- EXPECT_TRUE(encoder.compressImage(mSingleChannelImage.buffer.get(), mSingleChannelImage.width,
- mSingleChannelImage.height, JPEG_QUALITY, NULL, 0, true));
- ASSERT_GT(encoder.getCompressedImageSize(), static_cast<uint32_t>(0));
-}
-
-} // namespace android::jpegrecoverymap
-
diff --git a/libs/renderengine/skia/SkiaVkRenderEngine.cpp b/libs/renderengine/skia/SkiaVkRenderEngine.cpp
index 936e316..b99e385 100644
--- a/libs/renderengine/skia/SkiaVkRenderEngine.cpp
+++ b/libs/renderengine/skia/SkiaVkRenderEngine.cpp
@@ -52,6 +52,20 @@
PFN_vkDestroyInstance vkDestroyInstance = nullptr;
};
+// Ref-Count a semaphore
+struct DestroySemaphoreInfo {
+ VkSemaphore mSemaphore;
+ // We need to make sure we don't delete the VkSemaphore until it is done being used by both Skia
+ // (including by the GPU) and inside SkiaVkRenderEngine. So we always start with two refs, one
+ // owned by Skia and one owned by the SkiaVkRenderEngine. The refs are decremented each time
+ // delete_semaphore* is called with this object. Skia will call destroy_semaphore* once it is
+ // done with the semaphore and the GPU has finished work on the semaphore. SkiaVkRenderEngine
+ // calls delete_semaphore* after sending the semaphore to Skia and exporting it if need be.
+ int mRefs = 2;
+
+ DestroySemaphoreInfo(VkSemaphore semaphore) : mSemaphore(semaphore) {}
+};
+
struct VulkanInterface {
bool initialized = false;
VkInstance instance;
@@ -588,14 +602,22 @@
return true;
}
-static void delete_semaphore(void* _semaphore) {
- VkSemaphore semaphore = (VkSemaphore)_semaphore;
- sVulkanInterface.destroySemaphore(semaphore);
+static void delete_semaphore(void* semaphore) {
+ DestroySemaphoreInfo* info = reinterpret_cast<DestroySemaphoreInfo*>(semaphore);
+ --info->mRefs;
+ if (!info->mRefs) {
+ sVulkanInterface.destroySemaphore(info->mSemaphore);
+ delete info;
+ }
}
-static void delete_semaphore_protected(void* _semaphore) {
- VkSemaphore semaphore = (VkSemaphore)_semaphore;
- sProtectedContentVulkanInterface.destroySemaphore(semaphore);
+static void delete_semaphore_protected(void* semaphore) {
+ DestroySemaphoreInfo* info = reinterpret_cast<DestroySemaphoreInfo*>(semaphore);
+ --info->mRefs;
+ if (!info->mRefs) {
+ sProtectedContentVulkanInterface.destroySemaphore(info->mSemaphore);
+ delete info;
+ }
}
static VulkanInterface& getVulkanInterface(bool protectedContext) {
@@ -624,19 +646,30 @@
}
base::unique_fd SkiaVkRenderEngine::flushAndSubmit(GrDirectContext* grContext) {
- VkSemaphore signalSemaphore = getVulkanInterface(isProtected()).createExportableSemaphore();
- GrBackendSemaphore beSignalSemaphore;
- beSignalSemaphore.initVulkan(signalSemaphore);
+ VulkanInterface& vi = getVulkanInterface(isProtected());
+ VkSemaphore semaphore = vi.createExportableSemaphore();
+
+ GrBackendSemaphore backendSemaphore;
+ backendSemaphore.initVulkan(semaphore);
+
GrFlushInfo flushInfo;
- flushInfo.fNumSemaphores = 1;
- flushInfo.fSignalSemaphores = &beSignalSemaphore;
- flushInfo.fFinishedProc = isProtected() ? delete_semaphore_protected : delete_semaphore;
- flushInfo.fFinishedContext = (void*)signalSemaphore;
+ DestroySemaphoreInfo* destroySemaphoreInfo = nullptr;
+ if (semaphore != VK_NULL_HANDLE) {
+ destroySemaphoreInfo = new DestroySemaphoreInfo(semaphore);
+ flushInfo.fNumSemaphores = 1;
+ flushInfo.fSignalSemaphores = &backendSemaphore;
+ flushInfo.fFinishedProc = isProtected() ? delete_semaphore_protected : delete_semaphore;
+ flushInfo.fFinishedContext = destroySemaphoreInfo;
+ }
GrSemaphoresSubmitted submitted = grContext->flush(flushInfo);
grContext->submit(false /* no cpu sync */);
int drawFenceFd = -1;
- if (GrSemaphoresSubmitted::kYes == submitted) {
- drawFenceFd = getVulkanInterface(isProtected()).exportSemaphoreSyncFd(signalSemaphore);
+ if (semaphore != VK_NULL_HANDLE) {
+ if (GrSemaphoresSubmitted::kYes == submitted) {
+ drawFenceFd = vi.exportSemaphoreSyncFd(semaphore);
+ }
+ // Now that drawFenceFd has been created, we can delete our reference to this semaphore
+ flushInfo.fFinishedProc(destroySemaphoreInfo);
}
base::unique_fd res(drawFenceFd);
return res;
diff --git a/libs/jpegrecoverymap/Android.bp b/libs/ultrahdr/Android.bp
similarity index 97%
rename from libs/jpegrecoverymap/Android.bp
rename to libs/ultrahdr/Android.bp
index a376ced..e3f709b 100644
--- a/libs/jpegrecoverymap/Android.bp
+++ b/libs/ultrahdr/Android.bp
@@ -22,7 +22,7 @@
}
cc_library {
- name: "libjpegrecoverymap",
+ name: "libultrahdr",
host_supported: true,
vendor_available: true,
export_include_dirs: ["include"],
diff --git a/libs/jpegrecoverymap/OWNERS b/libs/ultrahdr/OWNERS
similarity index 100%
rename from libs/jpegrecoverymap/OWNERS
rename to libs/ultrahdr/OWNERS
diff --git a/libs/jpegrecoverymap/gainmapmath.cpp b/libs/ultrahdr/gainmapmath.cpp
similarity index 94%
rename from libs/jpegrecoverymap/gainmapmath.cpp
rename to libs/ultrahdr/gainmapmath.cpp
index f15a078..37c3cf3 100644
--- a/libs/jpegrecoverymap/gainmapmath.cpp
+++ b/libs/ultrahdr/gainmapmath.cpp
@@ -16,9 +16,9 @@
#include <cmath>
#include <vector>
-#include <jpegrecoverymap/gainmapmath.h>
+#include <ultrahdr/gainmapmath.h>
-namespace android::jpegrecoverymap {
+namespace android::ultrahdr {
static const std::vector<float> kPqOETF = [] {
std::vector<float> result;
@@ -396,45 +396,46 @@
// TODO: confirm we always want to convert like this before calculating
// luminance.
-ColorTransformFn getHdrConversionFn(jpegr_color_gamut sdr_gamut, jpegr_color_gamut hdr_gamut) {
+ColorTransformFn getHdrConversionFn(ultrahdr_color_gamut sdr_gamut,
+ ultrahdr_color_gamut hdr_gamut) {
switch (sdr_gamut) {
- case JPEGR_COLORGAMUT_BT709:
+ case ULTRAHDR_COLORGAMUT_BT709:
switch (hdr_gamut) {
- case JPEGR_COLORGAMUT_BT709:
+ case ULTRAHDR_COLORGAMUT_BT709:
return identityConversion;
- case JPEGR_COLORGAMUT_P3:
+ case ULTRAHDR_COLORGAMUT_P3:
return p3ToBt709;
- case JPEGR_COLORGAMUT_BT2100:
+ case ULTRAHDR_COLORGAMUT_BT2100:
return bt2100ToBt709;
- case JPEGR_COLORGAMUT_UNSPECIFIED:
+ case ULTRAHDR_COLORGAMUT_UNSPECIFIED:
return nullptr;
}
break;
- case JPEGR_COLORGAMUT_P3:
+ case ULTRAHDR_COLORGAMUT_P3:
switch (hdr_gamut) {
- case JPEGR_COLORGAMUT_BT709:
+ case ULTRAHDR_COLORGAMUT_BT709:
return bt709ToP3;
- case JPEGR_COLORGAMUT_P3:
+ case ULTRAHDR_COLORGAMUT_P3:
return identityConversion;
- case JPEGR_COLORGAMUT_BT2100:
+ case ULTRAHDR_COLORGAMUT_BT2100:
return bt2100ToP3;
- case JPEGR_COLORGAMUT_UNSPECIFIED:
+ case ULTRAHDR_COLORGAMUT_UNSPECIFIED:
return nullptr;
}
break;
- case JPEGR_COLORGAMUT_BT2100:
+ case ULTRAHDR_COLORGAMUT_BT2100:
switch (hdr_gamut) {
- case JPEGR_COLORGAMUT_BT709:
+ case ULTRAHDR_COLORGAMUT_BT709:
return bt709ToBt2100;
- case JPEGR_COLORGAMUT_P3:
+ case ULTRAHDR_COLORGAMUT_P3:
return p3ToBt2100;
- case JPEGR_COLORGAMUT_BT2100:
+ case ULTRAHDR_COLORGAMUT_BT2100:
return identityConversion;
- case JPEGR_COLORGAMUT_UNSPECIFIED:
+ case ULTRAHDR_COLORGAMUT_UNSPECIFIED:
return nullptr;
}
break;
- case JPEGR_COLORGAMUT_UNSPECIFIED:
+ case ULTRAHDR_COLORGAMUT_UNSPECIFIED:
return nullptr;
}
}
@@ -442,12 +443,12 @@
////////////////////////////////////////////////////////////////////////////////
// Gain map calculations
-uint8_t encodeGain(float y_sdr, float y_hdr, jr_metadata_ptr metadata) {
+uint8_t encodeGain(float y_sdr, float y_hdr, ultrahdr_metadata_ptr metadata) {
return encodeGain(y_sdr, y_hdr, metadata,
log2(metadata->minContentBoost), log2(metadata->maxContentBoost));
}
-uint8_t encodeGain(float y_sdr, float y_hdr, jr_metadata_ptr metadata,
+uint8_t encodeGain(float y_sdr, float y_hdr, ultrahdr_metadata_ptr metadata,
float log2MinContentBoost, float log2MaxContentBoost) {
float gain = 1.0f;
if (y_sdr > 0.0f) {
@@ -462,14 +463,14 @@
* 255.0f);
}
-Color applyGain(Color e, float gain, jr_metadata_ptr metadata) {
+Color applyGain(Color e, float gain, ultrahdr_metadata_ptr metadata) {
float logBoost = log2(metadata->minContentBoost) * (1.0f - gain)
+ log2(metadata->maxContentBoost) * gain;
float gainFactor = exp2(logBoost);
return e * gainFactor;
}
-Color applyGain(Color e, float gain, jr_metadata_ptr metadata, float displayBoost) {
+Color applyGain(Color e, float gain, ultrahdr_metadata_ptr metadata, float displayBoost) {
float logBoost = log2(metadata->minContentBoost) * (1.0f - gain)
+ log2(metadata->maxContentBoost) * gain;
float gainFactor = exp2(logBoost * displayBoost / metadata->maxContentBoost);
@@ -511,7 +512,7 @@
chroma_stride = luma_stride;
}
if (chroma_data == nullptr) {
- chroma_data = &reinterpret_cast<uint16_t*>(image->data)[image->luma_stride * image->height];
+ chroma_data = &reinterpret_cast<uint16_t*>(image->data)[luma_stride * image->height];
}
size_t pixel_y_idx = y * luma_stride + x;
@@ -662,4 +663,4 @@
| (((uint64_t) floatToHalf(1.0f)) << 48);
}
-} // namespace android::jpegrecoverymap
+} // namespace android::ultrahdr
diff --git a/libs/jpegrecoverymap/icc.cpp b/libs/ultrahdr/icc.cpp
similarity index 92%
rename from libs/jpegrecoverymap/icc.cpp
rename to libs/ultrahdr/icc.cpp
index 6e78f67..c807705 100644
--- a/libs/jpegrecoverymap/icc.cpp
+++ b/libs/ultrahdr/icc.cpp
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#include <jpegrecoverymap/icc.h>
-#include <jpegrecoverymap/gainmapmath.h>
+#include <ultrahdr/icc.h>
+#include <ultrahdr/gainmapmath.h>
#include <vector>
#include <utils/Log.h>
@@ -23,7 +23,7 @@
#define FLT_MAX 0x1.fffffep127f
#endif
-namespace android::jpegrecoverymap {
+namespace android::ultrahdr {
static void Matrix3x3_apply(const Matrix3x3* m, float* x) {
float y0 = x[0] * m->vals[0][0] + x[1] * m->vals[0][1] + x[2] * m->vals[0][2];
float y1 = x[0] * m->vals[1][0] + x[1] * m->vals[1][1] + x[2] * m->vals[1][2];
@@ -127,17 +127,17 @@
}
}
-std::string IccHelper::get_desc_string(const jpegr_transfer_function tf,
- const jpegr_color_gamut gamut) {
+std::string IccHelper::get_desc_string(const ultrahdr_transfer_function tf,
+ const ultrahdr_color_gamut gamut) {
std::string result;
switch (gamut) {
- case JPEGR_COLORGAMUT_BT709:
+ case ULTRAHDR_COLORGAMUT_BT709:
result += "sRGB";
break;
- case JPEGR_COLORGAMUT_P3:
+ case ULTRAHDR_COLORGAMUT_P3:
result += "Display P3";
break;
- case JPEGR_COLORGAMUT_BT2100:
+ case ULTRAHDR_COLORGAMUT_BT2100:
result += "Rec2020";
break;
default:
@@ -146,16 +146,16 @@
}
result += " Gamut with ";
switch (tf) {
- case JPEGR_TF_SRGB:
+ case ULTRAHDR_TF_SRGB:
result += "sRGB";
break;
- case JPEGR_TF_LINEAR:
+ case ULTRAHDR_TF_LINEAR:
result += "Linear";
break;
- case JPEGR_TF_PQ:
+ case ULTRAHDR_TF_PQ:
result += "PQ";
break;
- case JPEGR_TF_HLG:
+ case ULTRAHDR_TF_HLG:
result += "HLG";
break;
default:
@@ -234,11 +234,11 @@
return dataStruct;
}
-float IccHelper::compute_tone_map_gain(const jpegr_transfer_function tf, float L) {
+float IccHelper::compute_tone_map_gain(const ultrahdr_transfer_function tf, float L) {
if (L <= 0.f) {
return 1.f;
}
- if (tf == JPEGR_TF_PQ) {
+ if (tf == ULTRAHDR_TF_PQ) {
// The PQ transfer function will map to the range [0, 1]. Linearly scale
// it up to the range [0, 10,000/203]. We will then tone map that back
// down to [0, 1].
@@ -251,7 +251,7 @@
constexpr float kToneMapB = 1.f / kOutputMaxLuminance;
return kInputMaxLuminance * (1.f + kToneMapA * L) / (1.f + kToneMapB * L);
}
- if (tf == JPEGR_TF_HLG) {
+ if (tf == ULTRAHDR_TF_HLG) {
// Let Lw be the brightness of the display in nits.
constexpr float Lw = 203.f;
const float gamma = 1.2f + 0.42f * std::log(Lw / 1000.f) / std::log(10.f);
@@ -295,7 +295,7 @@
float L = bt2100Luminance({{{rgb[0], rgb[1], rgb[2]}}});
// Compute the tone map gain based on the luminance.
- float tone_map_gain = compute_tone_map_gain(JPEGR_TF_PQ, L);
+ float tone_map_gain = compute_tone_map_gain(ULTRAHDR_TF_PQ, L);
// Apply the tone map gain.
for (size_t i = 0; i < kNumChannels; ++i) {
@@ -397,7 +397,8 @@
return dataStruct;
}
-sp<DataStruct> IccHelper::writeIccProfile(jpegr_transfer_function tf, jpegr_color_gamut gamut) {
+sp<DataStruct> IccHelper::writeIccProfile(ultrahdr_transfer_function tf,
+ ultrahdr_color_gamut gamut) {
ICCHeader header;
std::vector<std::pair<uint32_t, sp<DataStruct>>> tags;
@@ -409,13 +410,13 @@
Matrix3x3 toXYZD50;
switch (gamut) {
- case JPEGR_COLORGAMUT_BT709:
+ case ULTRAHDR_COLORGAMUT_BT709:
toXYZD50 = kSRGB;
break;
- case JPEGR_COLORGAMUT_P3:
+ case ULTRAHDR_COLORGAMUT_P3:
toXYZD50 = kDisplayP3;
break;
- case JPEGR_COLORGAMUT_BT2100:
+ case ULTRAHDR_COLORGAMUT_BT2100:
toXYZD50 = kRec2020;
break;
default:
@@ -437,8 +438,8 @@
tags.emplace_back(kTAG_wtpt, write_xyz_tag(kD50_x, kD50_y, kD50_z));
// Compute transfer curves.
- if (tf != JPEGR_TF_PQ) {
- if (tf == JPEGR_TF_HLG) {
+ if (tf != ULTRAHDR_TF_PQ) {
+ if (tf == ULTRAHDR_TF_HLG) {
std::vector<uint8_t> trc_table;
trc_table.resize(kTrcTableSize * 2);
for (uint32_t i = 0; i < kTrcTableSize; ++i) {
@@ -462,32 +463,32 @@
}
// Compute CICP.
- if (tf == JPEGR_TF_HLG || tf == JPEGR_TF_PQ) {
+ if (tf == ULTRAHDR_TF_HLG || tf == ULTRAHDR_TF_PQ) {
// The CICP tag is present in ICC 4.4, so update the header's version.
header.version = Endian_SwapBE32(0x04400000);
uint32_t color_primaries = 0;
- if (gamut == JPEGR_COLORGAMUT_BT709) {
+ if (gamut == ULTRAHDR_COLORGAMUT_BT709) {
color_primaries = kCICPPrimariesSRGB;
- } else if (gamut == JPEGR_COLORGAMUT_P3) {
+ } else if (gamut == ULTRAHDR_COLORGAMUT_P3) {
color_primaries = kCICPPrimariesP3;
}
uint32_t transfer_characteristics = 0;
- if (tf == JPEGR_TF_SRGB) {
+ if (tf == ULTRAHDR_TF_SRGB) {
transfer_characteristics = kCICPTrfnSRGB;
- } else if (tf == JPEGR_TF_LINEAR) {
+ } else if (tf == ULTRAHDR_TF_LINEAR) {
transfer_characteristics = kCICPTrfnLinear;
- } else if (tf == JPEGR_TF_PQ) {
+ } else if (tf == ULTRAHDR_TF_PQ) {
transfer_characteristics = kCICPTrfnPQ;
- } else if (tf == JPEGR_TF_HLG) {
+ } else if (tf == ULTRAHDR_TF_HLG) {
transfer_characteristics = kCICPTrfnHLG;
}
tags.emplace_back(kTAG_cicp, write_cicp_tag(color_primaries, transfer_characteristics));
}
// Compute A2B0.
- if (tf == JPEGR_TF_PQ) {
+ if (tf == ULTRAHDR_TF_PQ) {
std::vector<uint8_t> a2b_grid;
a2b_grid.resize(kGridSize * kGridSize * kGridSize * kNumChannels * 2);
size_t a2b_grid_index = 0;
@@ -520,7 +521,7 @@
}
// Compute B2A0.
- if (tf == JPEGR_TF_PQ) {
+ if (tf == ULTRAHDR_TF_PQ) {
auto b2a_data = write_mAB_or_mBA_tag(kTAG_mBAType,
/* has_a_curves */ false,
/* grid_points */ nullptr,
@@ -541,7 +542,7 @@
// Write the header.
header.data_color_space = Endian_SwapBE32(Signature_RGB);
- header.pcs = Endian_SwapBE32(tf == JPEGR_TF_PQ ? Signature_Lab : Signature_XYZ);
+ header.pcs = Endian_SwapBE32(tf == ULTRAHDR_TF_PQ ? Signature_Lab : Signature_XYZ);
header.size = Endian_SwapBE32(profile_size);
header.tag_count = Endian_SwapBE32(tags.size());
@@ -581,4 +582,4 @@
return dataStruct;
}
-} // namespace android::jpegrecoverymap
\ No newline at end of file
+} // namespace android::ultrahdr
\ No newline at end of file
diff --git a/libs/jpegrecoverymap/include/jpegrecoverymap/gainmapmath.h b/libs/ultrahdr/include/ultrahdr/gainmapmath.h
similarity index 93%
rename from libs/jpegrecoverymap/include/jpegrecoverymap/gainmapmath.h
rename to libs/ultrahdr/include/ultrahdr/gainmapmath.h
index 57fddd0..abc9356 100644
--- a/libs/jpegrecoverymap/include/jpegrecoverymap/gainmapmath.h
+++ b/libs/ultrahdr/include/ultrahdr/gainmapmath.h
@@ -14,15 +14,15 @@
* limitations under the License.
*/
-#ifndef ANDROID_JPEGRECOVERYMAP_RECOVERYMAPMATH_H
-#define ANDROID_JPEGRECOVERYMAP_RECOVERYMAPMATH_H
+#ifndef ANDROID_ULTRAHDR_RECOVERYMAPMATH_H
+#define ANDROID_ULTRAHDR_RECOVERYMAPMATH_H
#include <cmath>
#include <stdint.h>
-#include <jpegrecoverymap/jpegr.h>
+#include <ultrahdr/jpegr.h>
-namespace android::jpegrecoverymap {
+namespace android::ultrahdr {
#define CLIP3(x, min, max) ((x) < (min)) ? (min) : ((x) > (max)) ? (max) : (x)
@@ -132,7 +132,7 @@
constexpr size_t kGainFactorPrecision = 10;
constexpr size_t kGainFactorNumEntries = 1 << kGainFactorPrecision;
struct GainLUT {
- GainLUT(jr_metadata_ptr metadata) {
+ GainLUT(ultrahdr_metadata_ptr metadata) {
for (int idx = 0; idx < kGainFactorNumEntries; idx++) {
float value = static_cast<float>(idx) / static_cast<float>(kGainFactorNumEntries - 1);
float logBoost = log2(metadata->minContentBoost) * (1.0f - value)
@@ -141,7 +141,7 @@
}
}
- GainLUT(jr_metadata_ptr metadata, float displayBoost) {
+ GainLUT(ultrahdr_metadata_ptr metadata, float displayBoost) {
float boostFactor = displayBoost > 0 ? displayBoost / metadata->maxContentBoost : 1.0f;
for (int idx = 0; idx < kGainFactorNumEntries; idx++) {
float value = static_cast<float>(idx) / static_cast<float>(kGainFactorNumEntries - 1);
@@ -356,7 +356,7 @@
/*
* Get the conversion to apply to the HDR image for gain map generation
*/
-ColorTransformFn getHdrConversionFn(jpegr_color_gamut sdr_gamut, jpegr_color_gamut hdr_gamut);
+ColorTransformFn getHdrConversionFn(ultrahdr_color_gamut sdr_gamut, ultrahdr_color_gamut hdr_gamut);
////////////////////////////////////////////////////////////////////////////////
@@ -366,16 +366,16 @@
* Calculate the 8-bit unsigned integer gain value for the given SDR and HDR
* luminances in linear space, and the hdr ratio to encode against.
*/
-uint8_t encodeGain(float y_sdr, float y_hdr, jr_metadata_ptr metadata);
-uint8_t encodeGain(float y_sdr, float y_hdr, jr_metadata_ptr metadata,
+uint8_t encodeGain(float y_sdr, float y_hdr, ultrahdr_metadata_ptr metadata);
+uint8_t encodeGain(float y_sdr, float y_hdr, ultrahdr_metadata_ptr metadata,
float log2MinContentBoost, float log2MaxContentBoost);
/*
* Calculates the linear luminance in nits after applying the given gain
* value, with the given hdr ratio, to the given sdr input in the range [0, 1].
*/
-Color applyGain(Color e, float gain, jr_metadata_ptr metadata);
-Color applyGain(Color e, float gain, jr_metadata_ptr metadata, float displayBoost);
+Color applyGain(Color e, float gain, ultrahdr_metadata_ptr metadata);
+Color applyGain(Color e, float gain, ultrahdr_metadata_ptr metadata, float displayBoost);
Color applyGainLUT(Color e, float gain, GainLUT& gainLUT);
/*
@@ -426,6 +426,6 @@
*/
uint64_t colorToRgbaF16(Color e_gamma);
-} // namespace android::jpegrecoverymap
+} // namespace android::ultrahdr
-#endif // ANDROID_JPEGRECOVERYMAP_RECOVERYMAPMATH_H
+#endif // ANDROID_ULTRAHDR_RECOVERYMAPMATH_H
diff --git a/libs/jpegrecoverymap/include/jpegrecoverymap/icc.h b/libs/ultrahdr/include/ultrahdr/icc.h
similarity index 92%
rename from libs/jpegrecoverymap/include/jpegrecoverymap/icc.h
rename to libs/ultrahdr/include/ultrahdr/icc.h
index a81aa62..7f6ab88 100644
--- a/libs/jpegrecoverymap/include/jpegrecoverymap/icc.h
+++ b/libs/ultrahdr/include/ultrahdr/icc.h
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-#ifndef ANDROID_JPEGRECOVERYMAP_ICC_H
-#define ANDROID_JPEGRECOVERYMAP_ICC_H
+#ifndef ANDROID_ULTRAHDR_ICC_H
+#define ANDROID_ULTRAHDR_ICC_H
-#include <jpegrecoverymap/jpegr.h>
-#include <jpegrecoverymap/jpegrutils.h>
+#include <ultrahdr/jpegr.h>
+#include <ultrahdr/jpegrutils.h>
#include <utils/RefBase.h>
#include <cmath>
#include <string>
@@ -28,7 +28,7 @@
#define USE_BIG_ENDIAN true
#endif
-namespace android::jpegrecoverymap {
+namespace android::ultrahdr {
typedef int32_t Fixed;
#define Fixed1 (1 << 16)
@@ -210,12 +210,12 @@
static constexpr size_t kNumChannels = 3;
static sp<DataStruct> write_text_tag(const char* text);
- static std::string get_desc_string(const jpegr_transfer_function tf,
- const jpegr_color_gamut gamut);
+ static std::string get_desc_string(const ultrahdr_transfer_function tf,
+ const ultrahdr_color_gamut gamut);
static sp<DataStruct> write_xyz_tag(float x, float y, float z);
static sp<DataStruct> write_trc_tag(const int table_entries, const void* table_16);
static sp<DataStruct> write_trc_tag_for_linear();
- static float compute_tone_map_gain(const jpegr_transfer_function tf, float L);
+ static float compute_tone_map_gain(const ultrahdr_transfer_function tf, float L);
static sp<DataStruct> write_cicp_tag(uint32_t color_primaries,
uint32_t transfer_characteristics);
static sp<DataStruct> write_mAB_or_mBA_tag(uint32_t type,
@@ -226,9 +226,9 @@
static sp<DataStruct> write_clut(const uint8_t* grid_points, const uint8_t* grid_16);
public:
- static sp<DataStruct> writeIccProfile(const jpegr_transfer_function tf,
- const jpegr_color_gamut gamut);
+ static sp<DataStruct> writeIccProfile(const ultrahdr_transfer_function tf,
+ const ultrahdr_color_gamut gamut);
};
-} // namespace android::jpegrecoverymap
+} // namespace android::ultrahdr
-#endif //ANDROID_JPEGRECOVERYMAP_ICC_H
\ No newline at end of file
+#endif //ANDROID_ULTRAHDR_ICC_H
\ No newline at end of file
diff --git a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegdecoderhelper.h b/libs/ultrahdr/include/ultrahdr/jpegdecoderhelper.h
similarity index 94%
rename from libs/jpegrecoverymap/include/jpegrecoverymap/jpegdecoderhelper.h
rename to libs/ultrahdr/include/ultrahdr/jpegdecoderhelper.h
index 8748237..f642bad 100644
--- a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegdecoderhelper.h
+++ b/libs/ultrahdr/include/ultrahdr/jpegdecoderhelper.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef ANDROID_JPEGRECOVERYMAP_JPEGDECODERHELPER_H
-#define ANDROID_JPEGRECOVERYMAP_JPEGDECODERHELPER_H
+#ifndef ANDROID_ULTRAHDR_JPEGDECODERHELPER_H
+#define ANDROID_ULTRAHDR_JPEGDECODERHELPER_H
// We must include cstdio before jpeglib.h. It is a requirement of libjpeg.
#include <cstdio>
@@ -25,7 +25,7 @@
}
#include <utils/Errors.h>
#include <vector>
-namespace android::jpegrecoverymap {
+namespace android::ultrahdr {
/*
* Encapsulates a converter from JPEG to raw image (YUV420planer or grey-scale) format.
* This class is not thread-safe.
@@ -115,6 +115,6 @@
// Position of EXIF package, default value is -1 which means no EXIF package appears.
size_t mExifPos;
};
-} /* namespace android::jpegrecoverymap */
+} /* namespace android::ultrahdr */
-#endif // ANDROID_JPEGRECOVERYMAP_JPEGDECODERHELPER_H
+#endif // ANDROID_ULTRAHDR_JPEGDECODERHELPER_H
diff --git a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegencoderhelper.h b/libs/ultrahdr/include/ultrahdr/jpegencoderhelper.h
similarity index 89%
rename from libs/jpegrecoverymap/include/jpegrecoverymap/jpegencoderhelper.h
rename to libs/ultrahdr/include/ultrahdr/jpegencoderhelper.h
index 8b82b2b..2c6778e 100644
--- a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegencoderhelper.h
+++ b/libs/ultrahdr/include/ultrahdr/jpegencoderhelper.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef ANDROID_JPEGRECOVERYMAP_JPEGENCODERHELPER_H
-#define ANDROID_JPEGRECOVERYMAP_JPEGENCODERHELPER_H
+#ifndef ANDROID_ULTRAHDR_JPEGENCODERHELPER_H
+#define ANDROID_ULTRAHDR_JPEGENCODERHELPER_H
// We must include cstdio before jpeglib.h. It is a requirement of libjpeg.
#include <cstdio>
@@ -28,7 +28,7 @@
#include <utils/Errors.h>
#include <vector>
-namespace android::jpegrecoverymap {
+namespace android::ultrahdr {
/*
* Encapsulates a converter from raw image (YUV420planer or grey-scale) to JPEG format.
@@ -61,6 +61,11 @@
*/
size_t getCompressedImageSize();
+ /*
+ * Process 16 lines of Y and 16 lines of U/V each time.
+ * We must pass at least 16 scanlines according to libjpeg documentation.
+ */
+ static const int kCompressBatchSize = 16;
private:
// initDestination(), emptyOutputBuffer() and emptyOutputBuffer() are callback functions to be
// passed into jpeg library.
@@ -82,14 +87,11 @@
// The block size for encoded jpeg image buffer.
static const int kBlockSize = 16384;
- // Process 16 lines of Y and 16 lines of U/V each time.
- // We must pass at least 16 scanlines according to libjpeg documentation.
- static const int kCompressBatchSize = 16;
// The buffer that holds the compressed result.
std::vector<JOCTET> mResultBuffer;
};
-} /* namespace android::jpegrecoverymap */
+} /* namespace android::ultrahdr */
-#endif // ANDROID_JPEGRECOVERYMAP_JPEGENCODERHELPER_H
+#endif // ANDROID_ULTRAHDR_JPEGENCODERHELPER_H
diff --git a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegr.h b/libs/ultrahdr/include/ultrahdr/jpegr.h
similarity index 81%
rename from libs/jpegrecoverymap/include/jpegrecoverymap/jpegr.h
rename to libs/ultrahdr/include/ultrahdr/jpegr.h
index ce7b33b..88038f1 100644
--- a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegr.h
+++ b/libs/ultrahdr/include/ultrahdr/jpegr.h
@@ -14,41 +14,17 @@
* limitations under the License.
*/
-#ifndef ANDROID_JPEGRECOVERYMAP_JPEGR_H
-#define ANDROID_JPEGRECOVERYMAP_JPEGR_H
+#ifndef ANDROID_ULTRAHDR_JPEGR_H
+#define ANDROID_ULTRAHDR_JPEGR_H
#include "jpegrerrorcode.h"
+#include "ultrahdr.h"
#ifndef FLT_MAX
#define FLT_MAX 0x1.fffffep127f
#endif
-namespace android::jpegrecoverymap {
-
-// Color gamuts for image data
-typedef enum {
- JPEGR_COLORGAMUT_UNSPECIFIED,
- JPEGR_COLORGAMUT_BT709,
- JPEGR_COLORGAMUT_P3,
- JPEGR_COLORGAMUT_BT2100,
-} jpegr_color_gamut;
-
-// Transfer functions for image data
-typedef enum {
- JPEGR_TF_UNSPECIFIED = -1,
- JPEGR_TF_LINEAR = 0,
- JPEGR_TF_HLG = 1,
- JPEGR_TF_PQ = 2,
- JPEGR_TF_SRGB = 3,
-} jpegr_transfer_function;
-
-// Target output formats for decoder
-typedef enum {
- JPEGR_OUTPUT_SDR, // SDR in RGBA_8888 color format
- JPEGR_OUTPUT_HDR_LINEAR, // HDR in F16 color format (linear)
- JPEGR_OUTPUT_HDR_PQ, // HDR in RGBA_1010102 color format (PQ transfer function)
- JPEGR_OUTPUT_HDR_HLG, // HDR in RGBA_1010102 color format (HLG transfer function)
-} jpegr_output_format;
+namespace android::ultrahdr {
struct jpegr_info_struct {
size_t width;
@@ -68,7 +44,7 @@
// Height of the gain map or the luma plane of the image in pixels.
int height;
// Color gamut.
- jpegr_color_gamut colorGamut;
+ ultrahdr_color_gamut colorGamut;
// Values below are optional
// Pointer to chroma data, if it's NULL, chroma plane is considered to be immediately
@@ -96,7 +72,7 @@
// Maximum available data length in bytes.
int maxLength;
// Color gamut.
- jpegr_color_gamut colorGamut;
+ ultrahdr_color_gamut colorGamut;
};
/*
@@ -109,22 +85,9 @@
int length;
};
-/*
- * Holds information for gain map related metadata.
- */
-struct jpegr_metadata_struct {
- // JPEG/R version
- uint32_t version;
- // Max Content Boost for the map
- float maxContentBoost;
- // Min Content Boost for the map
- float minContentBoost;
-};
-
typedef struct jpegr_uncompressed_struct* jr_uncompressed_ptr;
typedef struct jpegr_compressed_struct* jr_compressed_ptr;
typedef struct jpegr_exif_struct* jr_exif_ptr;
-typedef struct jpegr_metadata_struct* jr_metadata_ptr;
typedef struct jpegr_info_struct* jr_info_ptr;
class JpegR {
@@ -140,14 +103,17 @@
* JPEG.
* @param uncompressed_p010_image uncompressed HDR image in P010 color format
* @param hdr_tf transfer function of the HDR image
- * @param dest destination of the compressed JPEGR image
+ * @param dest destination of the compressed JPEGR image. Please note that {@code maxLength}
+ * represents the maximum available size of the desitination buffer, and it must be
+ * set before calling this method. If the encoded JPEGR size exceeds
+ * {@code maxLength}, this method will return {@code ERROR_JPEGR_BUFFER_TOO_SMALL}.
* @param quality target quality of the JPEG encoding, must be in range of 0-100 where 100 is
* the highest quality
* @param exif pointer to the exif metadata.
* @return NO_ERROR if encoding succeeds, error code if error occurs.
*/
status_t encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
- jpegr_transfer_function hdr_tf,
+ ultrahdr_transfer_function hdr_tf,
jr_compressed_ptr dest,
int quality,
jr_exif_ptr exif);
@@ -162,7 +128,10 @@
* @param uncompressed_p010_image uncompressed HDR image in P010 color format
* @param uncompressed_yuv_420_image uncompressed SDR image in YUV_420 color format
* @param hdr_tf transfer function of the HDR image
- * @param dest destination of the compressed JPEGR image
+ * @param dest destination of the compressed JPEGR image. Please note that {@code maxLength}
+ * represents the maximum available size of the desitination buffer, and it must be
+ * set before calling this method. If the encoded JPEGR size exceeds
+ * {@code maxLength}, this method will return {@code ERROR_JPEGR_BUFFER_TOO_SMALL}.
* @param quality target quality of the JPEG encoding, must be in range of 0-100 where 100 is
* the highest quality
* @param exif pointer to the exif metadata.
@@ -170,7 +139,7 @@
*/
status_t encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
jr_uncompressed_ptr uncompressed_yuv_420_image,
- jpegr_transfer_function hdr_tf,
+ ultrahdr_transfer_function hdr_tf,
jr_compressed_ptr dest,
int quality,
jr_exif_ptr exif);
@@ -189,13 +158,16 @@
* input
* @param compressed_jpeg_image compressed 8-bit JPEG image
* @param hdr_tf transfer function of the HDR image
- * @param dest destination of the compressed JPEGR image
+ * @param dest destination of the compressed JPEGR image. Please note that {@code maxLength}
+ * represents the maximum available size of the desitination buffer, and it must be
+ * set before calling this method. If the encoded JPEGR size exceeds
+ * {@code maxLength}, this method will return {@code ERROR_JPEGR_BUFFER_TOO_SMALL}.
* @return NO_ERROR if encoding succeeds, error code if error occurs.
*/
status_t encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
jr_uncompressed_ptr uncompressed_yuv_420_image,
jr_compressed_ptr compressed_jpeg_image,
- jpegr_transfer_function hdr_tf,
+ ultrahdr_transfer_function hdr_tf,
jr_compressed_ptr dest);
/*
@@ -210,12 +182,34 @@
* @param uncompressed_p010_image uncompressed HDR image in P010 color format
* @param compressed_jpeg_image compressed 8-bit JPEG image
* @param hdr_tf transfer function of the HDR image
- * @param dest destination of the compressed JPEGR image
+ * @param dest destination of the compressed JPEGR image. Please note that {@code maxLength}
+ * represents the maximum available size of the desitination buffer, and it must be
+ * set before calling this method. If the encoded JPEGR size exceeds
+ * {@code maxLength}, this method will return {@code ERROR_JPEGR_BUFFER_TOO_SMALL}.
* @return NO_ERROR if encoding succeeds, error code if error occurs.
*/
status_t encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
jr_compressed_ptr compressed_jpeg_image,
- jpegr_transfer_function hdr_tf,
+ ultrahdr_transfer_function hdr_tf,
+ jr_compressed_ptr dest);
+
+ /*
+ * Encode API-4
+ * Assemble JPEGR image from SDR JPEG and gainmap JPEG.
+ *
+ * Assemble the primary JPEG image, the gain map and the metadata to JPEG/R format.
+ * @param compressed_jpeg_image compressed 8-bit JPEG image
+ * @param compressed_gainmap compressed 8-bit JPEG single channel image
+ * @param metadata metadata to be written in XMP of the primary jpeg
+ * @param dest destination of the compressed JPEGR image. Please note that {@code maxLength}
+ * represents the maximum available size of the desitination buffer, and it must be
+ * set before calling this method. If the encoded JPEGR size exceeds
+ * {@code maxLength}, this method will return {@code ERROR_JPEGR_BUFFER_TOO_SMALL}.
+ * @return NO_ERROR if encoding succeeds, error code if error occurs.
+ */
+ status_t encodeJPEGR(jr_compressed_ptr compressed_jpeg_image,
+ jr_compressed_ptr compressed_gainmap,
+ ultrahdr_metadata_ptr metadata,
jr_compressed_ptr dest);
/*
@@ -249,16 +243,16 @@
* @param metadata destination of the decoded metadata. The default value is NULL where the
decoder will do nothing about it. If configured not NULL the decoder will
write metadata into this structure. the format of metadata is defined in
- {@code jpegr_metadata}.
+ {@code ultrahdr_metadata_struct}.
* @return NO_ERROR if decoding succeeds, error code if error occurs.
*/
status_t decodeJPEGR(jr_compressed_ptr compressed_jpegr_image,
jr_uncompressed_ptr dest,
float max_display_boost = FLT_MAX,
jr_exif_ptr exif = nullptr,
- jpegr_output_format output_format = JPEGR_OUTPUT_HDR_LINEAR,
+ ultrahdr_output_format output_format = ULTRAHDR_OUTPUT_HDR_LINEAR,
jr_uncompressed_ptr gain_map = nullptr,
- jr_metadata_ptr metadata = nullptr);
+ ultrahdr_metadata_ptr metadata = nullptr);
/*
* Gets Info from JPEGR file without decoding it.
@@ -286,8 +280,8 @@
*/
status_t generateGainMap(jr_uncompressed_ptr uncompressed_yuv_420_image,
jr_uncompressed_ptr uncompressed_p010_image,
- jpegr_transfer_function hdr_tf,
- jr_metadata_ptr metadata,
+ ultrahdr_transfer_function hdr_tf,
+ ultrahdr_metadata_ptr metadata,
jr_uncompressed_ptr dest);
/*
@@ -308,8 +302,8 @@
*/
status_t applyGainMap(jr_uncompressed_ptr uncompressed_yuv_420_image,
jr_uncompressed_ptr uncompressed_gain_map,
- jr_metadata_ptr metadata,
- jpegr_output_format output_format,
+ ultrahdr_metadata_ptr metadata,
+ ultrahdr_output_format output_format,
float max_display_boost,
jr_uncompressed_ptr dest);
@@ -365,7 +359,7 @@
status_t appendGainMap(jr_compressed_ptr compressed_jpeg_image,
jr_compressed_ptr compressed_gain_map,
jr_exif_ptr exif,
- jr_metadata_ptr metadata,
+ ultrahdr_metadata_ptr metadata,
jr_compressed_ptr dest);
/*
@@ -389,6 +383,6 @@
jr_uncompressed_ptr uncompressed_yuv_420_image);
};
-} // namespace android::jpegrecoverymap
+} // namespace android::ultrahdr
-#endif // ANDROID_JPEGRECOVERYMAP_JPEGR_H
+#endif // ANDROID_ULTRAHDR_JPEGR_H
diff --git a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegrerrorcode.h b/libs/ultrahdr/include/ultrahdr/jpegrerrorcode.h
similarity index 91%
rename from libs/jpegrecoverymap/include/jpegrecoverymap/jpegrerrorcode.h
rename to libs/ultrahdr/include/ultrahdr/jpegrerrorcode.h
index 159aaa8..9f59c3e 100644
--- a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegrerrorcode.h
+++ b/libs/ultrahdr/include/ultrahdr/jpegrerrorcode.h
@@ -14,9 +14,12 @@
* limitations under the License.
*/
+#ifndef ANDROID_ULTRAHDR_JPEGRERRORCODE_H
+#define ANDROID_ULTRAHDR_JPEGRERRORCODE_H
+
#include <utils/Errors.h>
-namespace android::jpegrecoverymap {
+namespace android::ultrahdr {
enum {
// status_t map for errors in the media framework
@@ -50,4 +53,6 @@
ERROR_JPEGR_UNSUPPORTED_FEATURE = -20000,
};
-} // namespace android::jpegrecoverymap
+} // namespace android::ultrahdr
+
+#endif // ANDROID_ULTRAHDR_JPEGRERRORCODE_H
diff --git a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegrutils.h b/libs/ultrahdr/include/ultrahdr/jpegrutils.h
similarity index 90%
rename from libs/jpegrecoverymap/include/jpegrecoverymap/jpegrutils.h
rename to libs/ultrahdr/include/ultrahdr/jpegrutils.h
index 09f4165..ed38e07 100644
--- a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegrutils.h
+++ b/libs/ultrahdr/include/ultrahdr/jpegrutils.h
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-#ifndef ANDROID_JPEGRECOVERYMAP_JPEGRUTILS_H
-#define ANDROID_JPEGRECOVERYMAP_JPEGRUTILS_H
+#ifndef ANDROID_ULTRAHDR_JPEGRUTILS_H
+#define ANDROID_ULTRAHDR_JPEGRUTILS_H
-#include <jpegrecoverymap/jpegr.h>
+#include <ultrahdr/jpegr.h>
#include <utils/RefBase.h>
#include <sstream>
@@ -25,7 +25,7 @@
#include <string>
#include <cstdio>
-namespace android::jpegrecoverymap {
+namespace android::ultrahdr {
static constexpr uint32_t EndianSwap32(uint32_t value) {
return ((value & 0xFF) << 24) |
@@ -45,7 +45,7 @@
#define Endian_SwapBE16(n) (n)
#endif
-struct jpegr_metadata_struct;
+struct ultrahdr_metadata_struct;
/*
* Mutable data structure. Holds information for metadata.
*/
@@ -87,7 +87,7 @@
* @param metadata place to store HDR metadata values
* @return true if metadata is successfully retrieved, false otherwise
*/
-bool getMetadataFromXMP(uint8_t* xmp_data, size_t xmp_size, jpegr_metadata_struct* metadata);
+bool getMetadataFromXMP(uint8_t* xmp_data, size_t xmp_size, ultrahdr_metadata_struct* metadata);
/*
* This method generates XMP metadata for the primary image.
@@ -158,7 +158,7 @@
* @param metadata JPEG/R metadata to encode as XMP
* @return XMP metadata in type of string
*/
- std::string generateXmpForSecondaryImage(jpegr_metadata_struct& metadata);
-} // namespace android::jpegrecoverymap
+ std::string generateXmpForSecondaryImage(ultrahdr_metadata_struct& metadata);
+} // namespace android::ultrahdr
-#endif //ANDROID_JPEGRECOVERYMAP_JPEGRUTILS_H
+#endif //ANDROID_ULTRAHDR_JPEGRUTILS_H
diff --git a/libs/jpegrecoverymap/include/jpegrecoverymap/multipictureformat.h b/libs/ultrahdr/include/ultrahdr/multipictureformat.h
similarity index 87%
rename from libs/jpegrecoverymap/include/jpegrecoverymap/multipictureformat.h
rename to libs/ultrahdr/include/ultrahdr/multipictureformat.h
index cf3387d..c5bd09d 100644
--- a/libs/jpegrecoverymap/include/jpegrecoverymap/multipictureformat.h
+++ b/libs/ultrahdr/include/ultrahdr/multipictureformat.h
@@ -14,17 +14,17 @@
* limitations under the License.
*/
-#ifndef ANDROID_JPEGRECOVERYMAP_MULTIPICTUREFORMAT_H
-#define ANDROID_JPEGRECOVERYMAP_MULTIPICTUREFORMAT_H
+#ifndef ANDROID_ULTRAHDR_MULTIPICTUREFORMAT_H
+#define ANDROID_ULTRAHDR_MULTIPICTUREFORMAT_H
-#include <jpegrecoverymap/jpegrutils.h>
+#include <ultrahdr/jpegrutils.h>
#ifdef USE_BIG_ENDIAN
#undef USE_BIG_ENDIAN
#define USE_BIG_ENDIAN true
#endif
-namespace android::jpegrecoverymap {
+namespace android::ultrahdr {
constexpr size_t kNumPictures = 2;
constexpr size_t kMpEndianSize = 4;
@@ -59,6 +59,6 @@
sp<DataStruct> generateMpf(int primary_image_size, int primary_image_offset,
int secondary_image_size, int secondary_image_offset);
-} // namespace android::jpegrecoverymap
+} // namespace android::ultrahdr
-#endif //ANDROID_JPEGRECOVERYMAP_MULTIPICTUREFORMAT_H
+#endif //ANDROID_ULTRAHDR_MULTIPICTUREFORMAT_H
diff --git a/libs/ultrahdr/include/ultrahdr/ultrahdr.h b/libs/ultrahdr/include/ultrahdr/ultrahdr.h
new file mode 100644
index 0000000..302aeee
--- /dev/null
+++ b/libs/ultrahdr/include/ultrahdr/ultrahdr.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2023 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 ANDROID_ULTRAHDR_ULTRAHDR_H
+#define ANDROID_ULTRAHDR_ULTRAHDR_H
+
+namespace android::ultrahdr {
+// Color gamuts for image data
+typedef enum {
+ ULTRAHDR_COLORGAMUT_UNSPECIFIED,
+ ULTRAHDR_COLORGAMUT_BT709,
+ ULTRAHDR_COLORGAMUT_P3,
+ ULTRAHDR_COLORGAMUT_BT2100,
+} ultrahdr_color_gamut;
+
+// Transfer functions for image data
+typedef enum {
+ ULTRAHDR_TF_UNSPECIFIED = -1,
+ ULTRAHDR_TF_LINEAR = 0,
+ ULTRAHDR_TF_HLG = 1,
+ ULTRAHDR_TF_PQ = 2,
+ ULTRAHDR_TF_SRGB = 3,
+} ultrahdr_transfer_function;
+
+// Target output formats for decoder
+typedef enum {
+ ULTRAHDR_OUTPUT_SDR, // SDR in RGBA_8888 color format
+ ULTRAHDR_OUTPUT_HDR_LINEAR, // HDR in F16 color format (linear)
+ ULTRAHDR_OUTPUT_HDR_PQ, // HDR in RGBA_1010102 color format (PQ transfer function)
+ ULTRAHDR_OUTPUT_HDR_HLG, // HDR in RGBA_1010102 color format (HLG transfer function)
+} ultrahdr_output_format;
+
+/*
+ * Holds information for gain map related metadata.
+ */
+struct ultrahdr_metadata_struct {
+ // Ultra HDR library version
+ uint32_t version;
+ // Max Content Boost for the map
+ float maxContentBoost;
+ // Min Content Boost for the map
+ float minContentBoost;
+};
+typedef struct ultrahdr_metadata_struct* ultrahdr_metadata_ptr;
+
+} // namespace android::ultrahdr
+
+#endif //ANDROID_ULTRAHDR_ULTRAHDR_H
\ No newline at end of file
diff --git a/libs/jpegrecoverymap/jpegdecoderhelper.cpp b/libs/ultrahdr/jpegdecoderhelper.cpp
similarity index 98%
rename from libs/jpegrecoverymap/jpegdecoderhelper.cpp
rename to libs/ultrahdr/jpegdecoderhelper.cpp
index d36bbf8..12217b7 100644
--- a/libs/jpegrecoverymap/jpegdecoderhelper.cpp
+++ b/libs/ultrahdr/jpegdecoderhelper.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include <jpegrecoverymap/jpegdecoderhelper.h>
+#include <ultrahdr/jpegdecoderhelper.h>
#include <utils/Log.h>
@@ -24,7 +24,7 @@
using namespace std;
-namespace android::jpegrecoverymap {
+namespace android::ultrahdr {
const uint32_t kAPP0Marker = JPEG_APP0; // JFIF
const uint32_t kAPP1Marker = JPEG_APP0 + 1; // EXIF, XMP
@@ -413,4 +413,4 @@
return true;
}
-} // namespace jpegrecoverymap
+} // namespace ultrahdr
diff --git a/libs/jpegrecoverymap/jpegencoderhelper.cpp b/libs/ultrahdr/jpegencoderhelper.cpp
similarity index 96%
rename from libs/jpegrecoverymap/jpegencoderhelper.cpp
rename to libs/ultrahdr/jpegencoderhelper.cpp
index 586cd34..10a7630 100644
--- a/libs/jpegrecoverymap/jpegencoderhelper.cpp
+++ b/libs/ultrahdr/jpegencoderhelper.cpp
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-#include <jpegrecoverymap/jpegencoderhelper.h>
+#include <ultrahdr/jpegencoderhelper.h>
#include <utils/Log.h>
#include <errno.h>
-namespace android::jpegrecoverymap {
+namespace android::ultrahdr {
// The destination manager that can access |mResultBuffer| in JpegEncoderHelper.
struct destination_mgr {
@@ -38,11 +38,6 @@
bool JpegEncoderHelper::compressImage(const void* image, int width, int height, int quality,
const void* iccBuffer, unsigned int iccSize,
bool isSingleChannel) {
- if (width % 8 != 0 || height % 2 != 0) {
- ALOGE("Image size can not be handled: %dx%d", width, height);
- return false;
- }
-
mResultBuffer.clear();
if (!encode(image, width, height, quality, iccBuffer, iccSize, isSingleChannel)) {
return false;
@@ -236,4 +231,4 @@
return true;
}
-} // namespace jpegrecoverymap
+} // namespace ultrahdr
diff --git a/libs/jpegrecoverymap/jpegr.cpp b/libs/ultrahdr/jpegr.cpp
similarity index 90%
rename from libs/jpegrecoverymap/jpegr.cpp
rename to libs/ultrahdr/jpegr.cpp
index 2590f63..5f55d1b 100644
--- a/libs/jpegrecoverymap/jpegr.cpp
+++ b/libs/ultrahdr/jpegr.cpp
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-#include <jpegrecoverymap/jpegr.h>
-#include <jpegrecoverymap/jpegencoderhelper.h>
-#include <jpegrecoverymap/jpegdecoderhelper.h>
-#include <jpegrecoverymap/gainmapmath.h>
-#include <jpegrecoverymap/jpegrutils.h>
-#include <jpegrecoverymap/multipictureformat.h>
-#include <jpegrecoverymap/icc.h>
+#include <ultrahdr/jpegr.h>
+#include <ultrahdr/jpegencoderhelper.h>
+#include <ultrahdr/jpegdecoderhelper.h>
+#include <ultrahdr/gainmapmath.h>
+#include <ultrahdr/jpegrutils.h>
+#include <ultrahdr/multipictureformat.h>
+#include <ultrahdr/icc.h>
#include <image_io/jpeg/jpeg_marker.h>
#include <image_io/jpeg/jpeg_info.h>
@@ -43,7 +43,7 @@
using namespace std;
using namespace photos_editing_formats::image_io;
-namespace android::jpegrecoverymap {
+namespace android::ultrahdr {
#define USE_SRGB_INVOETF_LUT 1
#define USE_HLG_OETF_LUT 1
@@ -66,9 +66,12 @@
// Map is quarter res / sixteenth size
static const size_t kMapDimensionScaleFactor = 4;
// JPEG block size.
-// JPEG encoding / decoding will require 8 x 8 DCT transform.
-// Width must be 8 dividable, and height must be 2 dividable.
-static const size_t kJpegBlock = 8;
+// JPEG encoding / decoding will require block based DCT transform 16 x 16 for luma,
+// and 8 x 8 for chroma.
+// Width must be 16 dividable for luma, and 8 dividable for chroma.
+// If this criteria is not ficilitated, we will pad zeros based on the required block size.
+static const size_t kJpegBlock = JpegEncoderHelper::kCompressBatchSize;
+static const size_t kJpegBlockSquare = kJpegBlock * kJpegBlock;
// JPEG compress quality (0 ~ 100) for gain map
static const int kMapCompressQuality = 85;
@@ -92,13 +95,6 @@
return ERROR_JPEGR_INVALID_NULL_PTR;
}
- if (uncompressed_p010_image->width % kJpegBlock != 0
- || uncompressed_p010_image->height % 2 != 0) {
- ALOGE("Image size can not be handled: %dx%d.",
- uncompressed_p010_image->width, uncompressed_p010_image->height);
- return ERROR_JPEGR_INVALID_INPUT_TYPE;
- }
-
if (uncompressed_p010_image->luma_stride != 0
&& uncompressed_p010_image->luma_stride < uncompressed_p010_image->width) {
ALOGE("Image stride can not be smaller than width, stride=%d, width=%d",
@@ -136,7 +132,7 @@
/* Encode API-0 */
status_t JpegR::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
- jpegr_transfer_function hdr_tf,
+ ultrahdr_transfer_function hdr_tf,
jr_compressed_ptr dest,
int quality,
jr_exif_ptr exif) {
@@ -153,12 +149,17 @@
return ret;
}
- jpegr_metadata_struct metadata;
+ ultrahdr_metadata_struct metadata;
metadata.version = kJpegrVersion;
jpegr_uncompressed_struct uncompressed_yuv_420_image;
- unique_ptr<uint8_t[]> uncompressed_yuv_420_image_data = make_unique<uint8_t[]>(
- uncompressed_p010_image->width * uncompressed_p010_image->height * 3 / 2);
+ size_t gain_map_length = uncompressed_p010_image->width * uncompressed_p010_image->height * 3 / 2;
+ // Pad a pseudo chroma block (kJpegBlock / 2) x (kJpegBlock / 2)
+ // if width is not kJpegBlock aligned.
+ if (uncompressed_p010_image->width % kJpegBlock != 0) {
+ gain_map_length += kJpegBlockSquare / 4;
+ }
+ unique_ptr<uint8_t[]> uncompressed_yuv_420_image_data = make_unique<uint8_t[]>(gain_map_length);
uncompressed_yuv_420_image.data = uncompressed_yuv_420_image_data.get();
JPEGR_CHECK(toneMap(uncompressed_p010_image, &uncompressed_yuv_420_image));
@@ -174,7 +175,7 @@
compressed_map.data = compressed_map_data.get();
JPEGR_CHECK(compressGainMap(&map, &compressed_map));
- sp<DataStruct> icc = IccHelper::writeIccProfile(JPEGR_TF_SRGB,
+ sp<DataStruct> icc = IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB,
uncompressed_yuv_420_image.colorGamut);
JpegEncoderHelper jpeg_encoder;
@@ -196,7 +197,7 @@
/* Encode API-1 */
status_t JpegR::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
jr_uncompressed_ptr uncompressed_yuv_420_image,
- jpegr_transfer_function hdr_tf,
+ ultrahdr_transfer_function hdr_tf,
jr_compressed_ptr dest,
int quality,
jr_exif_ptr exif) {
@@ -215,7 +216,7 @@
return ret;
}
- jpegr_metadata_struct metadata;
+ ultrahdr_metadata_struct metadata;
metadata.version = kJpegrVersion;
jpegr_uncompressed_struct map;
@@ -230,7 +231,7 @@
compressed_map.data = compressed_map_data.get();
JPEGR_CHECK(compressGainMap(&map, &compressed_map));
- sp<DataStruct> icc = IccHelper::writeIccProfile(JPEGR_TF_SRGB,
+ sp<DataStruct> icc = IccHelper::writeIccProfile(ULTRAHDR_TF_SRGB,
uncompressed_yuv_420_image->colorGamut);
JpegEncoderHelper jpeg_encoder;
@@ -253,7 +254,7 @@
status_t JpegR::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
jr_uncompressed_ptr uncompressed_yuv_420_image,
jr_compressed_ptr compressed_jpeg_image,
- jpegr_transfer_function hdr_tf,
+ ultrahdr_transfer_function hdr_tf,
jr_compressed_ptr dest) {
if (uncompressed_p010_image == nullptr
|| uncompressed_yuv_420_image == nullptr
@@ -267,7 +268,7 @@
return ret;
}
- jpegr_metadata_struct metadata;
+ ultrahdr_metadata_struct metadata;
metadata.version = kJpegrVersion;
jpegr_uncompressed_struct map;
@@ -290,7 +291,7 @@
/* Encode API-3 */
status_t JpegR::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image,
jr_compressed_ptr compressed_jpeg_image,
- jpegr_transfer_function hdr_tf,
+ ultrahdr_transfer_function hdr_tf,
jr_compressed_ptr dest) {
if (uncompressed_p010_image == nullptr
|| compressed_jpeg_image == nullptr
@@ -318,7 +319,7 @@
return ERROR_JPEGR_RESOLUTION_MISMATCH;
}
- jpegr_metadata_struct metadata;
+ ultrahdr_metadata_struct metadata;
metadata.version = kJpegrVersion;
jpegr_uncompressed_struct map;
@@ -338,6 +339,16 @@
return NO_ERROR;
}
+/* Encode API-4 */
+status_t JpegR::encodeJPEGR(jr_compressed_ptr compressed_jpeg_image,
+ jr_compressed_ptr compressed_gainmap,
+ ultrahdr_metadata_ptr metadata,
+ jr_compressed_ptr dest) {
+ JPEGR_CHECK(appendGainMap(compressed_jpeg_image, compressed_gainmap, /* exif */ nullptr,
+ metadata, dest));
+ return NO_ERROR;
+}
+
status_t JpegR::getJPEGRInfo(jr_compressed_ptr compressed_jpegr_image, jr_info_ptr jpegr_info) {
if (compressed_jpegr_image == nullptr || jpegr_info == nullptr) {
return ERROR_JPEGR_INVALID_NULL_PTR;
@@ -362,9 +373,9 @@
jr_uncompressed_ptr dest,
float max_display_boost,
jr_exif_ptr exif,
- jpegr_output_format output_format,
+ ultrahdr_output_format output_format,
jr_uncompressed_ptr gain_map,
- jr_metadata_ptr metadata) {
+ ultrahdr_metadata_ptr metadata) {
if (compressed_jpegr_image == nullptr || dest == nullptr) {
return ERROR_JPEGR_INVALID_NULL_PTR;
}
@@ -373,7 +384,7 @@
return ERROR_JPEGR_INVALID_INPUT_TYPE;
}
- if (output_format == JPEGR_OUTPUT_SDR) {
+ if (output_format == ULTRAHDR_OUTPUT_SDR) {
JpegDecoderHelper jpeg_decoder;
if (!jpeg_decoder.decompressImage(compressed_jpegr_image->data, compressed_jpegr_image->length,
true)) {
@@ -423,19 +434,19 @@
memcpy(gain_map->data, gain_map_decoder.getDecompressedImagePtr(), size);
}
- jpegr_metadata_struct jr_metadata;
+ ultrahdr_metadata_struct uhdr_metadata;
if (!getMetadataFromXMP(static_cast<uint8_t*>(gain_map_decoder.getXMPPtr()),
- gain_map_decoder.getXMPSize(), &jr_metadata)) {
+ gain_map_decoder.getXMPSize(), &uhdr_metadata)) {
return ERROR_JPEGR_DECODE_ERROR;
}
if (metadata != nullptr) {
- metadata->version = jr_metadata.version;
- metadata->minContentBoost = jr_metadata.minContentBoost;
- metadata->maxContentBoost = jr_metadata.maxContentBoost;
+ metadata->version = uhdr_metadata.version;
+ metadata->minContentBoost = uhdr_metadata.minContentBoost;
+ metadata->maxContentBoost = uhdr_metadata.maxContentBoost;
}
- if (output_format == JPEGR_OUTPUT_SDR) {
+ if (output_format == ULTRAHDR_OUTPUT_SDR) {
return NO_ERROR;
}
@@ -465,7 +476,7 @@
uncompressed_yuv_420_image.width = jpeg_decoder.getDecompressedImageWidth();
uncompressed_yuv_420_image.height = jpeg_decoder.getDecompressedImageHeight();
- JPEGR_CHECK(applyGainMap(&uncompressed_yuv_420_image, &map, &jr_metadata, output_format,
+ JPEGR_CHECK(applyGainMap(&uncompressed_yuv_420_image, &map, &uhdr_metadata, output_format,
max_display_boost, dest));
return NO_ERROR;
}
@@ -493,7 +504,7 @@
memcpy(dest->data, jpeg_encoder.getCompressedImagePtr(), jpeg_encoder.getCompressedImageSize());
dest->length = jpeg_encoder.getCompressedImageSize();
- dest->colorGamut = JPEGR_COLORGAMUT_UNSPECIFIED;
+ dest->colorGamut = ULTRAHDR_COLORGAMUT_UNSPECIFIED;
return NO_ERROR;
}
@@ -556,8 +567,8 @@
status_t JpegR::generateGainMap(jr_uncompressed_ptr uncompressed_yuv_420_image,
jr_uncompressed_ptr uncompressed_p010_image,
- jpegr_transfer_function hdr_tf,
- jr_metadata_ptr metadata,
+ ultrahdr_transfer_function hdr_tf,
+ ultrahdr_metadata_ptr metadata,
jr_uncompressed_ptr dest) {
if (uncompressed_yuv_420_image == nullptr
|| uncompressed_p010_image == nullptr
@@ -571,8 +582,8 @@
return ERROR_JPEGR_RESOLUTION_MISMATCH;
}
- if (uncompressed_yuv_420_image->colorGamut == JPEGR_COLORGAMUT_UNSPECIFIED
- || uncompressed_p010_image->colorGamut == JPEGR_COLORGAMUT_UNSPECIFIED) {
+ if (uncompressed_yuv_420_image->colorGamut == ULTRAHDR_COLORGAMUT_UNSPECIFIED
+ || uncompressed_p010_image->colorGamut == ULTRAHDR_COLORGAMUT_UNSPECIFIED) {
return ERROR_JPEGR_INVALID_COLORGAMUT;
}
@@ -586,7 +597,7 @@
dest->width = map_stride;
dest->height = map_height_aligned;
- dest->colorGamut = JPEGR_COLORGAMUT_UNSPECIFIED;
+ dest->colorGamut = ULTRAHDR_COLORGAMUT_UNSPECIFIED;
dest->data = new uint8_t[map_stride * map_height_aligned];
std::unique_ptr<uint8_t[]> map_data;
map_data.reset(reinterpret_cast<uint8_t*>(dest->data));
@@ -594,10 +605,10 @@
ColorTransformFn hdrInvOetf = nullptr;
float hdr_white_nits = 0.0f;
switch (hdr_tf) {
- case JPEGR_TF_LINEAR:
+ case ULTRAHDR_TF_LINEAR:
hdrInvOetf = identityConversion;
break;
- case JPEGR_TF_HLG:
+ case ULTRAHDR_TF_HLG:
#if USE_HLG_INVOETF_LUT
hdrInvOetf = hlgInvOetfLUT;
#else
@@ -605,7 +616,7 @@
#endif
hdr_white_nits = kHlgMaxNits;
break;
- case JPEGR_TF_PQ:
+ case ULTRAHDR_TF_PQ:
#if USE_PQ_INVOETF_LUT
hdrInvOetf = pqInvOetfLUT;
#else
@@ -628,16 +639,16 @@
ColorCalculationFn luminanceFn = nullptr;
switch (uncompressed_yuv_420_image->colorGamut) {
- case JPEGR_COLORGAMUT_BT709:
+ case ULTRAHDR_COLORGAMUT_BT709:
luminanceFn = srgbLuminance;
break;
- case JPEGR_COLORGAMUT_P3:
+ case ULTRAHDR_COLORGAMUT_P3:
luminanceFn = p3Luminance;
break;
- case JPEGR_COLORGAMUT_BT2100:
+ case ULTRAHDR_COLORGAMUT_BT2100:
luminanceFn = bt2100Luminance;
break;
- case JPEGR_COLORGAMUT_UNSPECIFIED:
+ case ULTRAHDR_COLORGAMUT_UNSPECIFIED:
// Should be impossible to hit after input validation.
return ERROR_JPEGR_INVALID_COLORGAMUT;
}
@@ -703,8 +714,8 @@
status_t JpegR::applyGainMap(jr_uncompressed_ptr uncompressed_yuv_420_image,
jr_uncompressed_ptr uncompressed_gain_map,
- jr_metadata_ptr metadata,
- jpegr_output_format output_format,
+ ultrahdr_metadata_ptr metadata,
+ ultrahdr_output_format output_format,
float max_display_boost,
jr_uncompressed_ptr dest) {
if (uncompressed_yuv_420_image == nullptr
@@ -759,13 +770,13 @@
size_t pixel_idx = x + y * width;
switch (output_format) {
- case JPEGR_OUTPUT_HDR_LINEAR:
+ case ULTRAHDR_OUTPUT_HDR_LINEAR:
{
uint64_t rgba_f16 = colorToRgbaF16(rgb_hdr);
reinterpret_cast<uint64_t*>(dest->data)[pixel_idx] = rgba_f16;
break;
}
- case JPEGR_OUTPUT_HDR_HLG:
+ case ULTRAHDR_OUTPUT_HDR_HLG:
{
#if USE_HLG_OETF_LUT
ColorTransformFn hdrOetf = hlgOetfLUT;
@@ -777,7 +788,7 @@
reinterpret_cast<uint32_t*>(dest->data)[pixel_idx] = rgba_1010102;
break;
}
- case JPEGR_OUTPUT_HDR_PQ:
+ case ULTRAHDR_OUTPUT_HDR_PQ:
{
#if USE_HLG_OETF_LUT
ColorTransformFn hdrOetf = pqOetfLUT;
@@ -910,7 +921,7 @@
status_t JpegR::appendGainMap(jr_compressed_ptr compressed_jpeg_image,
jr_compressed_ptr compressed_gain_map,
jr_exif_ptr exif,
- jr_metadata_ptr metadata,
+ ultrahdr_metadata_ptr metadata,
jr_compressed_ptr dest) {
if (compressed_jpeg_image == nullptr
|| compressed_gain_map == nullptr
@@ -1034,7 +1045,7 @@
uint16_t* src_chroma_data = reinterpret_cast<uint16_t*>(src->chroma_data);
if (src_chroma_data == nullptr) {
- src_chroma_data = &reinterpret_cast<uint16_t*>(src->data)[src->luma_stride * src->height];
+ src_chroma_data = &reinterpret_cast<uint16_t*>(src->data)[src_luma_stride * src->height];
}
if (src_luma_stride == 0) {
src_luma_stride = src->width;
@@ -1077,4 +1088,4 @@
return NO_ERROR;
}
-} // namespace android::jpegrecoverymap
+} // namespace android::ultrahdr
diff --git a/libs/jpegrecoverymap/jpegrutils.cpp b/libs/ultrahdr/jpegrutils.cpp
similarity index 97%
rename from libs/jpegrecoverymap/jpegrutils.cpp
rename to libs/ultrahdr/jpegrutils.cpp
index cde0ceb..9d07a6f 100644
--- a/libs/jpegrecoverymap/jpegrutils.cpp
+++ b/libs/ultrahdr/jpegrutils.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include <jpegrecoverymap/jpegrutils.h>
+#include <ultrahdr/jpegrutils.h>
#include <algorithm>
#include <cmath>
@@ -30,7 +30,7 @@
using namespace photos_editing_formats::image_io;
using namespace std;
-namespace android::jpegrecoverymap {
+namespace android::ultrahdr {
/*
* Helper function used for generating XMP metadata.
*
@@ -256,7 +256,7 @@
const string XMPXmlHandler::minContentBoostAttrName = kMapGainMapMin;
const string XMPXmlHandler::maxContentBoostAttrName = kMapGainMapMax;
-bool getMetadataFromXMP(uint8_t* xmp_data, size_t xmp_size, jpegr_metadata_struct* metadata) {
+bool getMetadataFromXMP(uint8_t* xmp_data, size_t xmp_size, ultrahdr_metadata_struct* metadata) {
string nameSpace = "http://ns.adobe.com/xap/1.0/\0";
if (xmp_size < nameSpace.size()+2) {
@@ -338,7 +338,7 @@
return ss.str();
}
-string generateXmpForSecondaryImage(jpegr_metadata_struct& metadata) {
+string generateXmpForSecondaryImage(ultrahdr_metadata_struct& metadata) {
const vector<string> kConDirSeq({kConDirectory, string("rdf:Seq")});
std::stringstream ss;
@@ -365,4 +365,4 @@
return ss.str();
}
-} // namespace android::jpegrecoverymap
+} // namespace android::ultrahdr
diff --git a/libs/jpegrecoverymap/multipictureformat.cpp b/libs/ultrahdr/multipictureformat.cpp
similarity index 95%
rename from libs/jpegrecoverymap/multipictureformat.cpp
rename to libs/ultrahdr/multipictureformat.cpp
index a219aef..7a265c6 100644
--- a/libs/jpegrecoverymap/multipictureformat.cpp
+++ b/libs/ultrahdr/multipictureformat.cpp
@@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <jpegrecoverymap/multipictureformat.h>
-#include <jpegrecoverymap/jpegrutils.h>
+#include <ultrahdr/multipictureformat.h>
+#include <ultrahdr/jpegrutils.h>
-namespace android::jpegrecoverymap {
+namespace android::ultrahdr {
size_t calculateMpfSize() {
return sizeof(kMpfSig) + // Signature
kMpEndianSize + // Endianness
@@ -91,4 +91,4 @@
return dataStruct;
}
-} // namespace android::jpegrecoverymap
+} // namespace android::ultrahdr
diff --git a/libs/jpegrecoverymap/tests/Android.bp b/libs/ultrahdr/tests/Android.bp
similarity index 96%
rename from libs/jpegrecoverymap/tests/Android.bp
rename to libs/ultrahdr/tests/Android.bp
index 59b1237..7dd9d04 100644
--- a/libs/jpegrecoverymap/tests/Android.bp
+++ b/libs/ultrahdr/tests/Android.bp
@@ -22,7 +22,7 @@
}
cc_test {
- name: "libjpegrecoverymap_test",
+ name: "libultrahdr_test",
test_suites: ["device-tests"],
srcs: [
"jpegr_test.cpp",
@@ -38,7 +38,7 @@
"libgtest",
"libjpegdecoder",
"libjpegencoder",
- "libjpegrecoverymap",
+ "libultrahdr",
"libutils",
],
}
diff --git a/libs/jpegrecoverymap/tests/data/jpeg_image.jpg b/libs/ultrahdr/tests/data/jpeg_image.jpg
similarity index 100%
rename from libs/jpegrecoverymap/tests/data/jpeg_image.jpg
rename to libs/ultrahdr/tests/data/jpeg_image.jpg
Binary files differ
diff --git a/libs/jpegrecoverymap/tests/data/minnie-318x240.yu12 b/libs/ultrahdr/tests/data/minnie-318x240.yu12
similarity index 100%
rename from libs/jpegrecoverymap/tests/data/minnie-318x240.yu12
rename to libs/ultrahdr/tests/data/minnie-318x240.yu12
Binary files differ
diff --git a/libs/jpegrecoverymap/tests/data/minnie-320x240-y.jpg b/libs/ultrahdr/tests/data/minnie-320x240-y.jpg
similarity index 100%
rename from libs/jpegrecoverymap/tests/data/minnie-320x240-y.jpg
rename to libs/ultrahdr/tests/data/minnie-320x240-y.jpg
Binary files differ
diff --git a/libs/jpegrecoverymap/tests/data/minnie-320x240-yuv.jpg b/libs/ultrahdr/tests/data/minnie-320x240-yuv.jpg
similarity index 100%
rename from libs/jpegrecoverymap/tests/data/minnie-320x240-yuv.jpg
rename to libs/ultrahdr/tests/data/minnie-320x240-yuv.jpg
Binary files differ
diff --git a/libs/jpegrecoverymap/tests/data/minnie-320x240.y b/libs/ultrahdr/tests/data/minnie-320x240.y
similarity index 100%
rename from libs/jpegrecoverymap/tests/data/minnie-320x240.y
rename to libs/ultrahdr/tests/data/minnie-320x240.y
Binary files differ
diff --git a/libs/jpegrecoverymap/tests/data/minnie-320x240.yu12 b/libs/ultrahdr/tests/data/minnie-320x240.yu12
similarity index 100%
rename from libs/jpegrecoverymap/tests/data/minnie-320x240.yu12
rename to libs/ultrahdr/tests/data/minnie-320x240.yu12
Binary files differ
diff --git a/libs/jpegrecoverymap/tests/data/raw_p010_image.p010 b/libs/ultrahdr/tests/data/raw_p010_image.p010
similarity index 100%
rename from libs/jpegrecoverymap/tests/data/raw_p010_image.p010
rename to libs/ultrahdr/tests/data/raw_p010_image.p010
Binary files differ
diff --git a/libs/jpegrecoverymap/tests/data/raw_p010_image_with_stride.p010 b/libs/ultrahdr/tests/data/raw_p010_image_with_stride.p010
similarity index 100%
rename from libs/jpegrecoverymap/tests/data/raw_p010_image_with_stride.p010
rename to libs/ultrahdr/tests/data/raw_p010_image_with_stride.p010
Binary files differ
diff --git a/libs/jpegrecoverymap/tests/data/raw_yuv420_image.yuv420 b/libs/ultrahdr/tests/data/raw_yuv420_image.yuv420
similarity index 100%
rename from libs/jpegrecoverymap/tests/data/raw_yuv420_image.yuv420
rename to libs/ultrahdr/tests/data/raw_yuv420_image.yuv420
Binary files differ
diff --git a/libs/jpegrecoverymap/tests/gainmapmath_test.cpp b/libs/ultrahdr/tests/gainmapmath_test.cpp
similarity index 94%
rename from libs/jpegrecoverymap/tests/gainmapmath_test.cpp
rename to libs/ultrahdr/tests/gainmapmath_test.cpp
index 21de2e6..c456653 100644
--- a/libs/jpegrecoverymap/tests/gainmapmath_test.cpp
+++ b/libs/ultrahdr/tests/gainmapmath_test.cpp
@@ -17,9 +17,9 @@
#include <cmath>
#include <gtest/gtest.h>
#include <gmock/gmock.h>
-#include <jpegrecoverymap/gainmapmath.h>
+#include <ultrahdr/gainmapmath.h>
-namespace android::jpegrecoverymap {
+namespace android::ultrahdr {
class GainMapMathTest : public testing::Test {
public:
@@ -88,7 +88,7 @@
return luminance_scaled * scale_factor;
}
- Color Recover(Color yuv_gamma, float gain, jr_metadata_ptr metadata) {
+ Color Recover(Color yuv_gamma, float gain, ultrahdr_metadata_ptr metadata) {
Color rgb_gamma = srgbYuvToRgb(yuv_gamma);
Color rgb = srgbInvOetf(rgb_gamma);
return applyGain(rgb, gain, metadata);
@@ -108,7 +108,7 @@
0xB0, 0xB1,
0xB2, 0xB3,
};
- return { pixels, 4, 4, JPEGR_COLORGAMUT_BT709 };
+ return { pixels, 4, 4, ULTRAHDR_COLORGAMUT_BT709 };
}
Color (*Yuv420Colors())[4] {
@@ -141,7 +141,7 @@
0xA0 << 6, 0xB0 << 6, 0xA1 << 6, 0xB1 << 6,
0xA2 << 6, 0xB2 << 6, 0xA3 << 6, 0xB3 << 6,
};
- return { pixels, 4, 4, JPEGR_COLORGAMUT_BT709 };
+ return { pixels, 4, 4, ULTRAHDR_COLORGAMUT_BT709 };
}
Color (*P010Colors())[4] {
@@ -170,7 +170,7 @@
0x02, 0x12, 0x22, 0x32,
0x03, 0x13, 0x23, 0x33,
};
- return { pixels, 4, 4, JPEGR_COLORGAMUT_UNSPECIFIED };
+ return { pixels, 4, 4, ULTRAHDR_COLORGAMUT_UNSPECIFIED };
}
float (*MapValues())[4] {
@@ -554,7 +554,7 @@
TEST_F(GainMapMathTest, applyGainLUT) {
for (int boost = 1; boost <= 10; boost++) {
- jpegr_metadata_struct metadata = { .maxContentBoost = static_cast<float>(boost),
+ ultrahdr_metadata_struct metadata = { .maxContentBoost = static_cast<float>(boost),
.minContentBoost = 1.0f / static_cast<float>(boost) };
GainLUT gainLUT(&metadata);
GainLUT gainLUTWithBoost(&metadata, metadata.maxContentBoost);
@@ -584,7 +584,7 @@
}
for (int boost = 1; boost <= 10; boost++) {
- jpegr_metadata_struct metadata = { .maxContentBoost = static_cast<float>(boost),
+ ultrahdr_metadata_struct metadata = { .maxContentBoost = static_cast<float>(boost),
.minContentBoost = 1.0f };
GainLUT gainLUT(&metadata);
GainLUT gainLUTWithBoost(&metadata, metadata.maxContentBoost);
@@ -614,7 +614,7 @@
}
for (int boost = 1; boost <= 10; boost++) {
- jpegr_metadata_struct metadata = { .maxContentBoost = static_cast<float>(boost),
+ ultrahdr_metadata_struct metadata = { .maxContentBoost = static_cast<float>(boost),
.minContentBoost = 1.0f / pow(static_cast<float>(boost),
1.0f / 3.0f) };
GainLUT gainLUT(&metadata);
@@ -654,45 +654,45 @@
}
TEST_F(GainMapMathTest, ColorConversionLookup) {
- EXPECT_EQ(getHdrConversionFn(JPEGR_COLORGAMUT_BT709, JPEGR_COLORGAMUT_UNSPECIFIED),
+ EXPECT_EQ(getHdrConversionFn(ULTRAHDR_COLORGAMUT_BT709, ULTRAHDR_COLORGAMUT_UNSPECIFIED),
nullptr);
- EXPECT_EQ(getHdrConversionFn(JPEGR_COLORGAMUT_BT709, JPEGR_COLORGAMUT_BT709),
+ EXPECT_EQ(getHdrConversionFn(ULTRAHDR_COLORGAMUT_BT709, ULTRAHDR_COLORGAMUT_BT709),
identityConversion);
- EXPECT_EQ(getHdrConversionFn(JPEGR_COLORGAMUT_BT709, JPEGR_COLORGAMUT_P3),
+ EXPECT_EQ(getHdrConversionFn(ULTRAHDR_COLORGAMUT_BT709, ULTRAHDR_COLORGAMUT_P3),
p3ToBt709);
- EXPECT_EQ(getHdrConversionFn(JPEGR_COLORGAMUT_BT709, JPEGR_COLORGAMUT_BT2100),
+ EXPECT_EQ(getHdrConversionFn(ULTRAHDR_COLORGAMUT_BT709, ULTRAHDR_COLORGAMUT_BT2100),
bt2100ToBt709);
- EXPECT_EQ(getHdrConversionFn(JPEGR_COLORGAMUT_P3, JPEGR_COLORGAMUT_UNSPECIFIED),
+ EXPECT_EQ(getHdrConversionFn(ULTRAHDR_COLORGAMUT_P3, ULTRAHDR_COLORGAMUT_UNSPECIFIED),
nullptr);
- EXPECT_EQ(getHdrConversionFn(JPEGR_COLORGAMUT_P3, JPEGR_COLORGAMUT_BT709),
+ EXPECT_EQ(getHdrConversionFn(ULTRAHDR_COLORGAMUT_P3, ULTRAHDR_COLORGAMUT_BT709),
bt709ToP3);
- EXPECT_EQ(getHdrConversionFn(JPEGR_COLORGAMUT_P3, JPEGR_COLORGAMUT_P3),
+ EXPECT_EQ(getHdrConversionFn(ULTRAHDR_COLORGAMUT_P3, ULTRAHDR_COLORGAMUT_P3),
identityConversion);
- EXPECT_EQ(getHdrConversionFn(JPEGR_COLORGAMUT_P3, JPEGR_COLORGAMUT_BT2100),
+ EXPECT_EQ(getHdrConversionFn(ULTRAHDR_COLORGAMUT_P3, ULTRAHDR_COLORGAMUT_BT2100),
bt2100ToP3);
- EXPECT_EQ(getHdrConversionFn(JPEGR_COLORGAMUT_BT2100, JPEGR_COLORGAMUT_UNSPECIFIED),
+ EXPECT_EQ(getHdrConversionFn(ULTRAHDR_COLORGAMUT_BT2100, ULTRAHDR_COLORGAMUT_UNSPECIFIED),
nullptr);
- EXPECT_EQ(getHdrConversionFn(JPEGR_COLORGAMUT_BT2100, JPEGR_COLORGAMUT_BT709),
+ EXPECT_EQ(getHdrConversionFn(ULTRAHDR_COLORGAMUT_BT2100, ULTRAHDR_COLORGAMUT_BT709),
bt709ToBt2100);
- EXPECT_EQ(getHdrConversionFn(JPEGR_COLORGAMUT_BT2100, JPEGR_COLORGAMUT_P3),
+ EXPECT_EQ(getHdrConversionFn(ULTRAHDR_COLORGAMUT_BT2100, ULTRAHDR_COLORGAMUT_P3),
p3ToBt2100);
- EXPECT_EQ(getHdrConversionFn(JPEGR_COLORGAMUT_BT2100, JPEGR_COLORGAMUT_BT2100),
+ EXPECT_EQ(getHdrConversionFn(ULTRAHDR_COLORGAMUT_BT2100, ULTRAHDR_COLORGAMUT_BT2100),
identityConversion);
- EXPECT_EQ(getHdrConversionFn(JPEGR_COLORGAMUT_UNSPECIFIED, JPEGR_COLORGAMUT_UNSPECIFIED),
+ EXPECT_EQ(getHdrConversionFn(ULTRAHDR_COLORGAMUT_UNSPECIFIED, ULTRAHDR_COLORGAMUT_UNSPECIFIED),
nullptr);
- EXPECT_EQ(getHdrConversionFn(JPEGR_COLORGAMUT_UNSPECIFIED, JPEGR_COLORGAMUT_BT709),
+ EXPECT_EQ(getHdrConversionFn(ULTRAHDR_COLORGAMUT_UNSPECIFIED, ULTRAHDR_COLORGAMUT_BT709),
nullptr);
- EXPECT_EQ(getHdrConversionFn(JPEGR_COLORGAMUT_UNSPECIFIED, JPEGR_COLORGAMUT_P3),
+ EXPECT_EQ(getHdrConversionFn(ULTRAHDR_COLORGAMUT_UNSPECIFIED, ULTRAHDR_COLORGAMUT_P3),
nullptr);
- EXPECT_EQ(getHdrConversionFn(JPEGR_COLORGAMUT_UNSPECIFIED, JPEGR_COLORGAMUT_BT2100),
+ EXPECT_EQ(getHdrConversionFn(ULTRAHDR_COLORGAMUT_UNSPECIFIED, ULTRAHDR_COLORGAMUT_BT2100),
nullptr);
}
TEST_F(GainMapMathTest, EncodeGain) {
- jpegr_metadata_struct metadata = { .maxContentBoost = 4.0f,
+ ultrahdr_metadata_struct metadata = { .maxContentBoost = 4.0f,
.minContentBoost = 1.0f / 4.0f };
EXPECT_EQ(encodeGain(0.0f, 0.0f, &metadata), 127);
@@ -750,7 +750,7 @@
}
TEST_F(GainMapMathTest, ApplyGain) {
- jpegr_metadata_struct metadata = { .maxContentBoost = 4.0f,
+ ultrahdr_metadata_struct metadata = { .maxContentBoost = 4.0f,
.minContentBoost = 1.0f / 4.0f };
float displayBoost = metadata.maxContentBoost;
@@ -1049,7 +1049,7 @@
}
TEST_F(GainMapMathTest, ApplyMap) {
- jpegr_metadata_struct metadata = { .maxContentBoost = 8.0f,
+ ultrahdr_metadata_struct metadata = { .maxContentBoost = 8.0f,
.minContentBoost = 1.0f / 8.0f };
EXPECT_RGB_EQ(Recover(YuvWhite(), 1.0f, &metadata),
@@ -1134,4 +1134,4 @@
RgbWhite() / 2.0f);
}
-} // namespace android::jpegrecoverymap
+} // namespace android::ultrahdr
diff --git a/libs/jpegrecoverymap/tests/jpegdecoderhelper_test.cpp b/libs/ultrahdr/tests/jpegdecoderhelper_test.cpp
similarity index 95%
rename from libs/jpegrecoverymap/tests/jpegdecoderhelper_test.cpp
rename to libs/ultrahdr/tests/jpegdecoderhelper_test.cpp
index 2f32a56..c79dbe3 100644
--- a/libs/jpegrecoverymap/tests/jpegdecoderhelper_test.cpp
+++ b/libs/ultrahdr/tests/jpegdecoderhelper_test.cpp
@@ -14,13 +14,13 @@
* limitations under the License.
*/
-#include <jpegrecoverymap/jpegdecoderhelper.h>
+#include <ultrahdr/jpegdecoderhelper.h>
#include <gtest/gtest.h>
#include <utils/Log.h>
#include <fcntl.h>
-namespace android::jpegrecoverymap {
+namespace android::ultrahdr {
#define YUV_IMAGE "/sdcard/Documents/minnie-320x240-yuv.jpg"
#define YUV_IMAGE_SIZE 20193
@@ -99,4 +99,4 @@
ASSERT_GT(decoder.getDecompressedImageSize(), static_cast<uint32_t>(0));
}
-} // namespace android::jpegrecoverymap
\ No newline at end of file
+} // namespace android::ultrahdr
\ No newline at end of file
diff --git a/libs/ultrahdr/tests/jpegencoderhelper_test.cpp b/libs/ultrahdr/tests/jpegencoderhelper_test.cpp
new file mode 100644
index 0000000..8f18ac0
--- /dev/null
+++ b/libs/ultrahdr/tests/jpegencoderhelper_test.cpp
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <ultrahdr/jpegencoderhelper.h>
+#include <gtest/gtest.h>
+#include <utils/Log.h>
+
+#include <fcntl.h>
+
+namespace android::ultrahdr {
+
+#define ALIGNED_IMAGE "/sdcard/Documents/minnie-320x240.yu12"
+#define ALIGNED_IMAGE_WIDTH 320
+#define ALIGNED_IMAGE_HEIGHT 240
+#define SINGLE_CHANNEL_IMAGE "/sdcard/Documents/minnie-320x240.y"
+#define SINGLE_CHANNEL_IMAGE_WIDTH ALIGNED_IMAGE_WIDTH
+#define SINGLE_CHANNEL_IMAGE_HEIGHT ALIGNED_IMAGE_HEIGHT
+#define UNALIGNED_IMAGE "/sdcard/Documents/minnie-318x240.yu12"
+#define UNALIGNED_IMAGE_WIDTH 318
+#define UNALIGNED_IMAGE_HEIGHT 240
+#define JPEG_QUALITY 90
+
+class JpegEncoderHelperTest : public testing::Test {
+public:
+ struct Image {
+ std::unique_ptr<uint8_t[]> buffer;
+ size_t width;
+ size_t height;
+ };
+ JpegEncoderHelperTest();
+ ~JpegEncoderHelperTest();
+protected:
+ virtual void SetUp();
+ virtual void TearDown();
+
+ Image mAlignedImage, mUnalignedImage, mSingleChannelImage;
+};
+
+JpegEncoderHelperTest::JpegEncoderHelperTest() {}
+
+JpegEncoderHelperTest::~JpegEncoderHelperTest() {}
+
+static size_t getFileSize(int fd) {
+ struct stat st;
+ if (fstat(fd, &st) < 0) {
+ ALOGW("%s : fstat failed", __func__);
+ return 0;
+ }
+ return st.st_size; // bytes
+}
+
+static bool loadFile(const char filename[], JpegEncoderHelperTest::Image* result) {
+ int fd = open(filename, O_CLOEXEC);
+ if (fd < 0) {
+ return false;
+ }
+ int length = getFileSize(fd);
+ if (length == 0) {
+ close(fd);
+ return false;
+ }
+ result->buffer.reset(new uint8_t[length]);
+ if (read(fd, result->buffer.get(), length) != static_cast<ssize_t>(length)) {
+ close(fd);
+ return false;
+ }
+ close(fd);
+ return true;
+}
+
+void JpegEncoderHelperTest::SetUp() {
+ if (!loadFile(ALIGNED_IMAGE, &mAlignedImage)) {
+ FAIL() << "Load file " << ALIGNED_IMAGE << " failed";
+ }
+ mAlignedImage.width = ALIGNED_IMAGE_WIDTH;
+ mAlignedImage.height = ALIGNED_IMAGE_HEIGHT;
+ if (!loadFile(UNALIGNED_IMAGE, &mUnalignedImage)) {
+ FAIL() << "Load file " << UNALIGNED_IMAGE << " failed";
+ }
+ mUnalignedImage.width = UNALIGNED_IMAGE_WIDTH;
+ mUnalignedImage.height = UNALIGNED_IMAGE_HEIGHT;
+ if (!loadFile(SINGLE_CHANNEL_IMAGE, &mSingleChannelImage)) {
+ FAIL() << "Load file " << SINGLE_CHANNEL_IMAGE << " failed";
+ }
+ mSingleChannelImage.width = SINGLE_CHANNEL_IMAGE_WIDTH;
+ mSingleChannelImage.height = SINGLE_CHANNEL_IMAGE_HEIGHT;
+}
+
+void JpegEncoderHelperTest::TearDown() {}
+
+TEST_F(JpegEncoderHelperTest, encodeAlignedImage) {
+ JpegEncoderHelper encoder;
+ EXPECT_TRUE(encoder.compressImage(mAlignedImage.buffer.get(), mAlignedImage.width,
+ mAlignedImage.height, JPEG_QUALITY, NULL, 0));
+ ASSERT_GT(encoder.getCompressedImageSize(), static_cast<uint32_t>(0));
+}
+
+// The width of the "unaligned" image is not 16-aligned, and will fail if encoded directly.
+// Should pass with the padding zero method.
+TEST_F(JpegEncoderHelperTest, encodeUnalignedImage) {
+ JpegEncoderHelper encoder;
+ const size_t paddingZeroLength = JpegEncoderHelper::kCompressBatchSize
+ * JpegEncoderHelper::kCompressBatchSize / 4;
+ std::unique_ptr<uint8_t[]> imageWithPaddingZeros(
+ new uint8_t[UNALIGNED_IMAGE_WIDTH * UNALIGNED_IMAGE_HEIGHT * 3 / 2
+ + paddingZeroLength]);
+ memcpy(imageWithPaddingZeros.get(), mUnalignedImage.buffer.get(),
+ UNALIGNED_IMAGE_WIDTH * UNALIGNED_IMAGE_HEIGHT * 3 / 2);
+ EXPECT_TRUE(encoder.compressImage(imageWithPaddingZeros.get(), mUnalignedImage.width,
+ mUnalignedImage.height, JPEG_QUALITY, NULL, 0));
+ ASSERT_GT(encoder.getCompressedImageSize(), static_cast<uint32_t>(0));
+}
+
+TEST_F(JpegEncoderHelperTest, encodeSingleChannelImage) {
+ JpegEncoderHelper encoder;
+ EXPECT_TRUE(encoder.compressImage(mSingleChannelImage.buffer.get(), mSingleChannelImage.width,
+ mSingleChannelImage.height, JPEG_QUALITY, NULL, 0, true));
+ ASSERT_GT(encoder.getCompressedImageSize(), static_cast<uint32_t>(0));
+}
+
+} // namespace android::ultrahdr
+
diff --git a/libs/jpegrecoverymap/tests/jpegr_test.cpp b/libs/ultrahdr/tests/jpegr_test.cpp
similarity index 86%
rename from libs/jpegrecoverymap/tests/jpegr_test.cpp
rename to libs/ultrahdr/tests/jpegr_test.cpp
index 620f431..ba3b4d0 100644
--- a/libs/jpegrecoverymap/tests/jpegr_test.cpp
+++ b/libs/ultrahdr/tests/jpegr_test.cpp
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-#include <jpegrecoverymap/jpegr.h>
-#include <jpegrecoverymap/jpegrutils.h>
-#include <jpegrecoverymap/gainmapmath.h>
+#include <ultrahdr/jpegr.h>
+#include <ultrahdr/jpegrutils.h>
+#include <ultrahdr/gainmapmath.h>
#include <fcntl.h>
#include <fstream>
#include <gtest/gtest.h>
@@ -36,7 +36,7 @@
#define SAVE_DECODING_RESULT true
#define SAVE_INPUT_RGBA true
-namespace android::jpegrecoverymap {
+namespace android::ultrahdr {
struct Timer {
struct timeval StartingTime;
@@ -118,16 +118,16 @@
class JpegRBenchmark : public JpegR {
public:
void BenchmarkGenerateGainMap(jr_uncompressed_ptr yuv420Image, jr_uncompressed_ptr p010Image,
- jr_metadata_ptr metadata, jr_uncompressed_ptr map);
+ ultrahdr_metadata_ptr metadata, jr_uncompressed_ptr map);
void BenchmarkApplyGainMap(jr_uncompressed_ptr yuv420Image, jr_uncompressed_ptr map,
- jr_metadata_ptr metadata, jr_uncompressed_ptr dest);
+ ultrahdr_metadata_ptr metadata, jr_uncompressed_ptr dest);
private:
const int kProfileCount = 10;
};
void JpegRBenchmark::BenchmarkGenerateGainMap(jr_uncompressed_ptr yuv420Image,
jr_uncompressed_ptr p010Image,
- jr_metadata_ptr metadata,
+ ultrahdr_metadata_ptr metadata,
jr_uncompressed_ptr map) {
ASSERT_EQ(yuv420Image->width, p010Image->width);
ASSERT_EQ(yuv420Image->height, p010Image->height);
@@ -137,7 +137,7 @@
timerStart(&genRecMapTime);
for (auto i = 0; i < kProfileCount; i++) {
ASSERT_EQ(OK, generateGainMap(
- yuv420Image, p010Image, jpegr_transfer_function::JPEGR_TF_HLG, metadata, map));
+ yuv420Image, p010Image, ultrahdr_transfer_function::ULTRAHDR_TF_HLG, metadata, map));
if (i != kProfileCount - 1) delete[] static_cast<uint8_t *>(map->data);
}
timerStop(&genRecMapTime);
@@ -150,13 +150,13 @@
void JpegRBenchmark::BenchmarkApplyGainMap(jr_uncompressed_ptr yuv420Image,
jr_uncompressed_ptr map,
- jr_metadata_ptr metadata,
+ ultrahdr_metadata_ptr metadata,
jr_uncompressed_ptr dest) {
Timer applyRecMapTime;
timerStart(&applyRecMapTime);
for (auto i = 0; i < kProfileCount; i++) {
- ASSERT_EQ(OK, applyGainMap(yuv420Image, map, metadata, JPEGR_OUTPUT_HDR_HLG,
+ ASSERT_EQ(OK, applyGainMap(yuv420Image, map, metadata, ULTRAHDR_OUTPUT_HDR_HLG,
metadata->maxContentBoost /* displayBoost */, dest));
}
timerStop(&applyRecMapTime);
@@ -169,17 +169,17 @@
TEST_F(JpegRTest, build) {
// Force all of the gain map lib to be linked by calling all public functions.
JpegR jpegRCodec;
- jpegRCodec.encodeJPEGR(nullptr, static_cast<jpegr_transfer_function>(0), nullptr, 0, nullptr);
- jpegRCodec.encodeJPEGR(nullptr, nullptr, static_cast<jpegr_transfer_function>(0),
+ jpegRCodec.encodeJPEGR(nullptr, static_cast<ultrahdr_transfer_function>(0), nullptr, 0, nullptr);
+ jpegRCodec.encodeJPEGR(nullptr, nullptr, static_cast<ultrahdr_transfer_function>(0),
nullptr, 0, nullptr);
- jpegRCodec.encodeJPEGR(nullptr, nullptr, nullptr, static_cast<jpegr_transfer_function>(0),
+ jpegRCodec.encodeJPEGR(nullptr, nullptr, nullptr, static_cast<ultrahdr_transfer_function>(0),
nullptr);
- jpegRCodec.encodeJPEGR(nullptr, nullptr, static_cast<jpegr_transfer_function>(0), nullptr);
+ jpegRCodec.encodeJPEGR(nullptr, nullptr, static_cast<ultrahdr_transfer_function>(0), nullptr);
jpegRCodec.decodeJPEGR(nullptr, nullptr);
}
TEST_F(JpegRTest, writeXmpThenRead) {
- jpegr_metadata_struct metadata_expected;
+ ultrahdr_metadata_struct metadata_expected;
metadata_expected.maxContentBoost = 1.25;
metadata_expected.minContentBoost = 0.75;
const std::string nameSpace = "http://ns.adobe.com/xap/1.0/\0";
@@ -194,7 +194,7 @@
xmpData.insert(xmpData.end(), reinterpret_cast<const uint8_t*>(xmp.c_str()),
reinterpret_cast<const uint8_t*>(xmp.c_str()) + xmp.size());
- jpegr_metadata_struct metadata_read;
+ ultrahdr_metadata_struct metadata_read;
EXPECT_TRUE(getMetadataFromXMP(xmpData.data(), xmpData.size(), &metadata_read));
EXPECT_FLOAT_EQ(metadata_expected.maxContentBoost, metadata_read.maxContentBoost);
EXPECT_FLOAT_EQ(metadata_expected.minContentBoost, metadata_read.minContentBoost);
@@ -210,7 +210,7 @@
}
mRawP010Image.width = TEST_IMAGE_WIDTH;
mRawP010Image.height = TEST_IMAGE_HEIGHT;
- mRawP010Image.colorGamut = jpegr_color_gamut::JPEGR_COLORGAMUT_BT2100;
+ mRawP010Image.colorGamut = ultrahdr_color_gamut::ULTRAHDR_COLORGAMUT_BT2100;
JpegR jpegRCodec;
@@ -218,7 +218,8 @@
jpegR.maxLength = TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT * sizeof(uint8_t);
jpegR.data = malloc(jpegR.maxLength);
ret = jpegRCodec.encodeJPEGR(
- &mRawP010Image, jpegr_transfer_function::JPEGR_TF_HLG, &jpegR, DEFAULT_JPEG_QUALITY, nullptr);
+ &mRawP010Image, ultrahdr_transfer_function::ULTRAHDR_TF_HLG, &jpegR, DEFAULT_JPEG_QUALITY,
+ nullptr);
if (ret != OK) {
FAIL() << "Error code is " << ret;
}
@@ -264,7 +265,7 @@
mRawP010ImageWithStride.width = TEST_IMAGE_WIDTH;
mRawP010ImageWithStride.height = TEST_IMAGE_HEIGHT;
mRawP010ImageWithStride.luma_stride = TEST_IMAGE_STRIDE;
- mRawP010ImageWithStride.colorGamut = jpegr_color_gamut::JPEGR_COLORGAMUT_BT2100;
+ mRawP010ImageWithStride.colorGamut = ultrahdr_color_gamut::ULTRAHDR_COLORGAMUT_BT2100;
JpegR jpegRCodec;
@@ -272,7 +273,7 @@
jpegR.maxLength = TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT * sizeof(uint8_t);
jpegR.data = malloc(jpegR.maxLength);
ret = jpegRCodec.encodeJPEGR(
- &mRawP010ImageWithStride, jpegr_transfer_function::JPEGR_TF_HLG, &jpegR,
+ &mRawP010ImageWithStride, ultrahdr_transfer_function::ULTRAHDR_TF_HLG, &jpegR,
DEFAULT_JPEG_QUALITY, nullptr);
if (ret != OK) {
FAIL() << "Error code is " << ret;
@@ -318,14 +319,14 @@
}
mRawP010Image.width = TEST_IMAGE_WIDTH;
mRawP010Image.height = TEST_IMAGE_HEIGHT;
- mRawP010Image.colorGamut = jpegr_color_gamut::JPEGR_COLORGAMUT_BT2100;
+ mRawP010Image.colorGamut = ultrahdr_color_gamut::ULTRAHDR_COLORGAMUT_BT2100;
if (!loadFile(RAW_YUV420_IMAGE, mRawYuv420Image.data, nullptr)) {
FAIL() << "Load file " << RAW_P010_IMAGE << " failed";
}
mRawYuv420Image.width = TEST_IMAGE_WIDTH;
mRawYuv420Image.height = TEST_IMAGE_HEIGHT;
- mRawYuv420Image.colorGamut = jpegr_color_gamut::JPEGR_COLORGAMUT_BT709;
+ mRawYuv420Image.colorGamut = ultrahdr_color_gamut::ULTRAHDR_COLORGAMUT_BT709;
JpegR jpegRCodec;
@@ -333,7 +334,7 @@
jpegR.maxLength = TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT * sizeof(uint8_t);
jpegR.data = malloc(jpegR.maxLength);
ret = jpegRCodec.encodeJPEGR(
- &mRawP010Image, &mRawYuv420Image, jpegr_transfer_function::JPEGR_TF_HLG, &jpegR,
+ &mRawP010Image, &mRawYuv420Image, ultrahdr_transfer_function::ULTRAHDR_TF_HLG, &jpegR,
DEFAULT_JPEG_QUALITY, nullptr);
if (ret != OK) {
FAIL() << "Error code is " << ret;
@@ -379,19 +380,19 @@
}
mRawP010Image.width = TEST_IMAGE_WIDTH;
mRawP010Image.height = TEST_IMAGE_HEIGHT;
- mRawP010Image.colorGamut = jpegr_color_gamut::JPEGR_COLORGAMUT_BT2100;
+ mRawP010Image.colorGamut = ultrahdr_color_gamut::ULTRAHDR_COLORGAMUT_BT2100;
if (!loadFile(RAW_YUV420_IMAGE, mRawYuv420Image.data, nullptr)) {
FAIL() << "Load file " << RAW_P010_IMAGE << " failed";
}
mRawYuv420Image.width = TEST_IMAGE_WIDTH;
mRawYuv420Image.height = TEST_IMAGE_HEIGHT;
- mRawYuv420Image.colorGamut = jpegr_color_gamut::JPEGR_COLORGAMUT_BT709;
+ mRawYuv420Image.colorGamut = ultrahdr_color_gamut::ULTRAHDR_COLORGAMUT_BT709;
if (!loadFile(JPEG_IMAGE, mJpegImage.data, &mJpegImage.length)) {
FAIL() << "Load file " << JPEG_IMAGE << " failed";
}
- mJpegImage.colorGamut = jpegr_color_gamut::JPEGR_COLORGAMUT_BT709;
+ mJpegImage.colorGamut = ultrahdr_color_gamut::ULTRAHDR_COLORGAMUT_BT709;
JpegR jpegRCodec;
@@ -399,7 +400,8 @@
jpegR.maxLength = TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT * sizeof(uint8_t);
jpegR.data = malloc(jpegR.maxLength);
ret = jpegRCodec.encodeJPEGR(
- &mRawP010Image, &mRawYuv420Image, &mJpegImage, jpegr_transfer_function::JPEGR_TF_HLG, &jpegR);
+ &mRawP010Image, &mRawYuv420Image, &mJpegImage, ultrahdr_transfer_function::ULTRAHDR_TF_HLG,
+ &jpegR);
if (ret != OK) {
FAIL() << "Error code is " << ret;
}
@@ -444,7 +446,7 @@
}
mRawP010Image.width = TEST_IMAGE_WIDTH;
mRawP010Image.height = TEST_IMAGE_HEIGHT;
- mRawP010Image.colorGamut = jpegr_color_gamut::JPEGR_COLORGAMUT_BT2100;
+ mRawP010Image.colorGamut = ultrahdr_color_gamut::ULTRAHDR_COLORGAMUT_BT2100;
if (SAVE_INPUT_RGBA) {
size_t rgbaSize = mRawP010Image.width * mRawP010Image.height * sizeof(uint32_t);
@@ -472,7 +474,7 @@
if (!loadFile(JPEG_IMAGE, mJpegImage.data, &mJpegImage.length)) {
FAIL() << "Load file " << JPEG_IMAGE << " failed";
}
- mJpegImage.colorGamut = jpegr_color_gamut::JPEGR_COLORGAMUT_BT709;
+ mJpegImage.colorGamut = ultrahdr_color_gamut::ULTRAHDR_COLORGAMUT_BT709;
JpegR jpegRCodec;
@@ -480,7 +482,7 @@
jpegR.maxLength = TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT * sizeof(uint8_t);
jpegR.data = malloc(jpegR.maxLength);
ret = jpegRCodec.encodeJPEGR(
- &mRawP010Image, &mJpegImage, jpegr_transfer_function::JPEGR_TF_HLG, &jpegR);
+ &mRawP010Image, &mJpegImage, ultrahdr_transfer_function::ULTRAHDR_TF_HLG, &jpegR);
if (ret != OK) {
FAIL() << "Error code is " << ret;
}
@@ -525,25 +527,25 @@
}
mRawP010Image.width = kWidth;
mRawP010Image.height = kHeight;
- mRawP010Image.colorGamut = jpegr_color_gamut::JPEGR_COLORGAMUT_BT2100;
+ mRawP010Image.colorGamut = ultrahdr_color_gamut::ULTRAHDR_COLORGAMUT_BT2100;
if (!loadFile(RAW_YUV420_IMAGE, mRawYuv420Image.data, nullptr)) {
FAIL() << "Load file " << RAW_P010_IMAGE << " failed";
}
mRawYuv420Image.width = kWidth;
mRawYuv420Image.height = kHeight;
- mRawYuv420Image.colorGamut = jpegr_color_gamut::JPEGR_COLORGAMUT_BT709;
+ mRawYuv420Image.colorGamut = ultrahdr_color_gamut::ULTRAHDR_COLORGAMUT_BT709;
JpegRBenchmark benchmark;
- jpegr_metadata_struct metadata = { .version = 1,
+ ultrahdr_metadata_struct metadata = { .version = 1,
.maxContentBoost = 8.0f,
.minContentBoost = 1.0f / 8.0f };
jpegr_uncompressed_struct map = { .data = NULL,
.width = 0,
.height = 0,
- .colorGamut = JPEGR_COLORGAMUT_UNSPECIFIED };
+ .colorGamut = ULTRAHDR_COLORGAMUT_UNSPECIFIED };
benchmark.BenchmarkGenerateGainMap(&mRawYuv420Image, &mRawP010Image, &metadata, &map);
@@ -552,9 +554,9 @@
jpegr_uncompressed_struct dest = { .data = bufferDst.get(),
.width = 0,
.height = 0,
- .colorGamut = JPEGR_COLORGAMUT_UNSPECIFIED };
+ .colorGamut = ULTRAHDR_COLORGAMUT_UNSPECIFIED };
benchmark.BenchmarkApplyGainMap(&mRawYuv420Image, &map, &metadata, &dest);
}
-} // namespace android::recoverymap
+} // namespace android::ultrahdr
diff --git a/services/inputflinger/InputListener.cpp b/services/inputflinger/InputListener.cpp
index 1bc1adf..aa55873 100644
--- a/services/inputflinger/InputListener.cpp
+++ b/services/inputflinger/InputListener.cpp
@@ -47,16 +47,14 @@
void InputListenerInterface::notify(const NotifyArgs& generalArgs) {
Visitor v{
[&](const NotifyInputDevicesChangedArgs& args) { notifyInputDevicesChanged(args); },
- [&](const NotifyConfigurationChangedArgs& args) { notifyConfigurationChanged(&args); },
- [&](const NotifyKeyArgs& args) { notifyKey(&args); },
- [&](const NotifyMotionArgs& args) { notifyMotion(&args); },
- [&](const NotifySwitchArgs& args) { notifySwitch(&args); },
- [&](const NotifySensorArgs& args) { notifySensor(&args); },
- [&](const NotifyVibratorStateArgs& args) { notifyVibratorState(&args); },
- [&](const NotifyDeviceResetArgs& args) { notifyDeviceReset(&args); },
- [&](const NotifyPointerCaptureChangedArgs& args) {
- notifyPointerCaptureChanged(&args);
- },
+ [&](const NotifyConfigurationChangedArgs& args) { notifyConfigurationChanged(args); },
+ [&](const NotifyKeyArgs& args) { notifyKey(args); },
+ [&](const NotifyMotionArgs& args) { notifyMotion(args); },
+ [&](const NotifySwitchArgs& args) { notifySwitch(args); },
+ [&](const NotifySensorArgs& args) { notifySensor(args); },
+ [&](const NotifyVibratorStateArgs& args) { notifyVibratorState(args); },
+ [&](const NotifyDeviceResetArgs& args) { notifyDeviceReset(args); },
+ [&](const NotifyPointerCaptureChangedArgs& args) { notifyPointerCaptureChanged(args); },
};
std::visit(v, generalArgs);
}
@@ -78,45 +76,44 @@
mArgsQueue.emplace_back(args);
}
-void QueuedInputListener::notifyConfigurationChanged(
- const NotifyConfigurationChangedArgs* args) {
- traceEvent(__func__, args->id);
- mArgsQueue.emplace_back(*args);
+void QueuedInputListener::notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) {
+ traceEvent(__func__, args.id);
+ mArgsQueue.emplace_back(args);
}
-void QueuedInputListener::notifyKey(const NotifyKeyArgs* args) {
- traceEvent(__func__, args->id);
- mArgsQueue.emplace_back(*args);
+void QueuedInputListener::notifyKey(const NotifyKeyArgs& args) {
+ traceEvent(__func__, args.id);
+ mArgsQueue.emplace_back(args);
}
-void QueuedInputListener::notifyMotion(const NotifyMotionArgs* args) {
- traceEvent(__func__, args->id);
- mArgsQueue.emplace_back(*args);
+void QueuedInputListener::notifyMotion(const NotifyMotionArgs& args) {
+ traceEvent(__func__, args.id);
+ mArgsQueue.emplace_back(args);
}
-void QueuedInputListener::notifySwitch(const NotifySwitchArgs* args) {
- traceEvent(__func__, args->id);
- mArgsQueue.emplace_back(*args);
+void QueuedInputListener::notifySwitch(const NotifySwitchArgs& args) {
+ traceEvent(__func__, args.id);
+ mArgsQueue.emplace_back(args);
}
-void QueuedInputListener::notifySensor(const NotifySensorArgs* args) {
- traceEvent(__func__, args->id);
- mArgsQueue.emplace_back(*args);
+void QueuedInputListener::notifySensor(const NotifySensorArgs& args) {
+ traceEvent(__func__, args.id);
+ mArgsQueue.emplace_back(args);
}
-void QueuedInputListener::notifyVibratorState(const NotifyVibratorStateArgs* args) {
- traceEvent(__func__, args->id);
- mArgsQueue.emplace_back(*args);
+void QueuedInputListener::notifyVibratorState(const NotifyVibratorStateArgs& args) {
+ traceEvent(__func__, args.id);
+ mArgsQueue.emplace_back(args);
}
-void QueuedInputListener::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
- traceEvent(__func__, args->id);
- mArgsQueue.emplace_back(*args);
+void QueuedInputListener::notifyDeviceReset(const NotifyDeviceResetArgs& args) {
+ traceEvent(__func__, args.id);
+ mArgsQueue.emplace_back(args);
}
-void QueuedInputListener::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) {
- traceEvent(__func__, args->id);
- mArgsQueue.emplace_back(*args);
+void QueuedInputListener::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) {
+ traceEvent(__func__, args.id);
+ mArgsQueue.emplace_back(args);
}
void QueuedInputListener::flush() {
diff --git a/services/inputflinger/InputProcessor.cpp b/services/inputflinger/InputProcessor.cpp
index 6c0bcff..7a84be9 100644
--- a/services/inputflinger/InputProcessor.cpp
+++ b/services/inputflinger/InputProcessor.cpp
@@ -419,63 +419,63 @@
mQueuedListener.flush();
}
-void InputProcessor::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) {
+void InputProcessor::notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) {
// pass through
mQueuedListener.notifyConfigurationChanged(args);
mQueuedListener.flush();
}
-void InputProcessor::notifyKey(const NotifyKeyArgs* args) {
+void InputProcessor::notifyKey(const NotifyKeyArgs& args) {
// pass through
mQueuedListener.notifyKey(args);
mQueuedListener.flush();
}
-void InputProcessor::notifyMotion(const NotifyMotionArgs* args) {
+void InputProcessor::notifyMotion(const NotifyMotionArgs& args) {
{ // acquire lock
std::scoped_lock lock(mLock);
// MotionClassifier is only used for touch events, for now
- const bool sendToMotionClassifier = mMotionClassifier && isTouchEvent(*args);
+ const bool sendToMotionClassifier = mMotionClassifier && isTouchEvent(args);
if (!sendToMotionClassifier) {
mQueuedListener.notifyMotion(args);
} else {
- NotifyMotionArgs newArgs(*args);
+ NotifyMotionArgs newArgs(args);
const MotionClassification newClassification = mMotionClassifier->classify(newArgs);
- LOG_ALWAYS_FATAL_IF(args->classification != MotionClassification::NONE &&
+ LOG_ALWAYS_FATAL_IF(args.classification != MotionClassification::NONE &&
newClassification != MotionClassification::NONE,
"Conflicting classifications %s (new) and %s (old)!",
motionClassificationToString(newClassification),
- motionClassificationToString(args->classification));
+ motionClassificationToString(args.classification));
newArgs.classification = newClassification;
- mQueuedListener.notifyMotion(&newArgs);
+ mQueuedListener.notifyMotion(newArgs);
}
} // release lock
mQueuedListener.flush();
}
-void InputProcessor::notifySensor(const NotifySensorArgs* args) {
+void InputProcessor::notifySensor(const NotifySensorArgs& args) {
// pass through
mQueuedListener.notifySensor(args);
mQueuedListener.flush();
}
-void InputProcessor::notifyVibratorState(const NotifyVibratorStateArgs* args) {
+void InputProcessor::notifyVibratorState(const NotifyVibratorStateArgs& args) {
// pass through
mQueuedListener.notifyVibratorState(args);
mQueuedListener.flush();
}
-void InputProcessor::notifySwitch(const NotifySwitchArgs* args) {
+void InputProcessor::notifySwitch(const NotifySwitchArgs& args) {
// pass through
mQueuedListener.notifySwitch(args);
mQueuedListener.flush();
}
-void InputProcessor::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
+void InputProcessor::notifyDeviceReset(const NotifyDeviceResetArgs& args) {
{ // acquire lock
std::scoped_lock lock(mLock);
if (mMotionClassifier) {
- mMotionClassifier->reset(*args);
+ mMotionClassifier->reset(args);
}
} // release lock
@@ -484,7 +484,7 @@
mQueuedListener.flush();
}
-void InputProcessor::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) {
+void InputProcessor::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) {
// pass through
mQueuedListener.notifyPointerCaptureChanged(args);
mQueuedListener.flush();
diff --git a/services/inputflinger/InputProcessor.h b/services/inputflinger/InputProcessor.h
index 01795a8..dcbfebc 100644
--- a/services/inputflinger/InputProcessor.h
+++ b/services/inputflinger/InputProcessor.h
@@ -246,14 +246,14 @@
explicit InputProcessor(InputListenerInterface& listener);
void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override;
- void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override;
- void notifyKey(const NotifyKeyArgs* args) override;
- void notifyMotion(const NotifyMotionArgs* args) override;
- void notifySwitch(const NotifySwitchArgs* args) override;
- void notifySensor(const NotifySensorArgs* args) override;
- void notifyVibratorState(const NotifyVibratorStateArgs* args) override;
- void notifyDeviceReset(const NotifyDeviceResetArgs* args) override;
- void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) override;
+ void notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) override;
+ void notifyKey(const NotifyKeyArgs& args) override;
+ void notifyMotion(const NotifyMotionArgs& args) override;
+ void notifySwitch(const NotifySwitchArgs& args) override;
+ void notifySensor(const NotifySensorArgs& args) override;
+ void notifyVibratorState(const NotifyVibratorStateArgs& args) override;
+ void notifyDeviceReset(const NotifyDeviceResetArgs& args) override;
+ void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) override;
void dump(std::string& dump) override;
void monitor() override;
diff --git a/services/inputflinger/UnwantedInteractionBlocker.cpp b/services/inputflinger/UnwantedInteractionBlocker.cpp
index 6d43e8d..02bc47d 100644
--- a/services/inputflinger/UnwantedInteractionBlocker.cpp
+++ b/services/inputflinger/UnwantedInteractionBlocker.cpp
@@ -329,24 +329,24 @@
: mQueuedListener(listener), mEnablePalmRejection(enablePalmRejection) {}
void UnwantedInteractionBlocker::notifyConfigurationChanged(
- const NotifyConfigurationChangedArgs* args) {
+ const NotifyConfigurationChangedArgs& args) {
mQueuedListener.notifyConfigurationChanged(args);
mQueuedListener.flush();
}
-void UnwantedInteractionBlocker::notifyKey(const NotifyKeyArgs* args) {
+void UnwantedInteractionBlocker::notifyKey(const NotifyKeyArgs& args) {
mQueuedListener.notifyKey(args);
mQueuedListener.flush();
}
-void UnwantedInteractionBlocker::notifyMotion(const NotifyMotionArgs* args) {
- ALOGD_IF(DEBUG_INBOUND_MOTION, "%s: %s", __func__, args->dump().c_str());
+void UnwantedInteractionBlocker::notifyMotion(const NotifyMotionArgs& args) {
+ ALOGD_IF(DEBUG_INBOUND_MOTION, "%s: %s", __func__, args.dump().c_str());
{ // acquire lock
std::scoped_lock lock(mLock);
const std::vector<NotifyMotionArgs> processedArgs =
- mPreferStylusOverTouchBlocker.processMotion(*args);
+ mPreferStylusOverTouchBlocker.processMotion(args);
for (const NotifyMotionArgs& loopArgs : processedArgs) {
- notifyMotionLocked(&loopArgs);
+ notifyMotionLocked(loopArgs);
}
} // release lock
@@ -356,56 +356,56 @@
void UnwantedInteractionBlocker::enqueueOutboundMotionLocked(const NotifyMotionArgs& args) {
ALOGD_IF(DEBUG_OUTBOUND_MOTION, "%s: %s", __func__, args.dump().c_str());
- mQueuedListener.notifyMotion(&args);
+ mQueuedListener.notifyMotion(args);
}
-void UnwantedInteractionBlocker::notifyMotionLocked(const NotifyMotionArgs* args) {
- auto it = mPalmRejectors.find(args->deviceId);
- const bool sendToPalmRejector = it != mPalmRejectors.end() && isFromTouchscreen(args->source);
+void UnwantedInteractionBlocker::notifyMotionLocked(const NotifyMotionArgs& args) {
+ auto it = mPalmRejectors.find(args.deviceId);
+ const bool sendToPalmRejector = it != mPalmRejectors.end() && isFromTouchscreen(args.source);
if (!sendToPalmRejector) {
- enqueueOutboundMotionLocked(*args);
+ enqueueOutboundMotionLocked(args);
return;
}
- std::vector<NotifyMotionArgs> processedArgs = it->second.processMotion(*args);
+ std::vector<NotifyMotionArgs> processedArgs = it->second.processMotion(args);
for (const NotifyMotionArgs& loopArgs : processedArgs) {
enqueueOutboundMotionLocked(loopArgs);
}
}
-void UnwantedInteractionBlocker::notifySwitch(const NotifySwitchArgs* args) {
+void UnwantedInteractionBlocker::notifySwitch(const NotifySwitchArgs& args) {
mQueuedListener.notifySwitch(args);
mQueuedListener.flush();
}
-void UnwantedInteractionBlocker::notifySensor(const NotifySensorArgs* args) {
+void UnwantedInteractionBlocker::notifySensor(const NotifySensorArgs& args) {
mQueuedListener.notifySensor(args);
mQueuedListener.flush();
}
-void UnwantedInteractionBlocker::notifyVibratorState(const NotifyVibratorStateArgs* args) {
+void UnwantedInteractionBlocker::notifyVibratorState(const NotifyVibratorStateArgs& args) {
mQueuedListener.notifyVibratorState(args);
mQueuedListener.flush();
}
-void UnwantedInteractionBlocker::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
+void UnwantedInteractionBlocker::notifyDeviceReset(const NotifyDeviceResetArgs& args) {
{ // acquire lock
std::scoped_lock lock(mLock);
- auto it = mPalmRejectors.find(args->deviceId);
+ auto it = mPalmRejectors.find(args.deviceId);
if (it != mPalmRejectors.end()) {
AndroidPalmFilterDeviceInfo info = it->second.getPalmFilterDeviceInfo();
// Re-create the object instead of resetting it
mPalmRejectors.erase(it);
- mPalmRejectors.emplace(args->deviceId, info);
+ mPalmRejectors.emplace(args.deviceId, info);
}
mQueuedListener.notifyDeviceReset(args);
- mPreferStylusOverTouchBlocker.notifyDeviceReset(*args);
+ mPreferStylusOverTouchBlocker.notifyDeviceReset(args);
} // release lock
// Send events to the next stage without holding the lock
mQueuedListener.flush();
}
void UnwantedInteractionBlocker::notifyPointerCaptureChanged(
- const NotifyPointerCaptureChangedArgs* args) {
+ const NotifyPointerCaptureChangedArgs& args) {
mQueuedListener.notifyPointerCaptureChanged(args);
mQueuedListener.flush();
}
diff --git a/services/inputflinger/UnwantedInteractionBlocker.h b/services/inputflinger/UnwantedInteractionBlocker.h
index 3bc5240..419da83 100644
--- a/services/inputflinger/UnwantedInteractionBlocker.h
+++ b/services/inputflinger/UnwantedInteractionBlocker.h
@@ -91,14 +91,14 @@
explicit UnwantedInteractionBlocker(InputListenerInterface& listener, bool enablePalmRejection);
void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override;
- void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override;
- void notifyKey(const NotifyKeyArgs* args) override;
- void notifyMotion(const NotifyMotionArgs* args) override;
- void notifySwitch(const NotifySwitchArgs* args) override;
- void notifySensor(const NotifySensorArgs* args) override;
- void notifyVibratorState(const NotifyVibratorStateArgs* args) override;
- void notifyDeviceReset(const NotifyDeviceResetArgs* args) override;
- void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) override;
+ void notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) override;
+ void notifyKey(const NotifyKeyArgs& args) override;
+ void notifyMotion(const NotifyMotionArgs& args) override;
+ void notifySwitch(const NotifySwitchArgs& args) override;
+ void notifySensor(const NotifySensorArgs& args) override;
+ void notifyVibratorState(const NotifyVibratorStateArgs& args) override;
+ void notifyDeviceReset(const NotifyDeviceResetArgs& args) override;
+ void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) override;
void dump(std::string& dump) override;
void monitor() override;
@@ -119,7 +119,7 @@
// Use a separate palm rejector for every touch device.
std::map<int32_t /*deviceId*/, PalmRejector> mPalmRejectors GUARDED_BY(mLock);
// TODO(b/210159205): delete this when simultaneous stylus and touch is supported
- void notifyMotionLocked(const NotifyMotionArgs* args) REQUIRES(mLock);
+ void notifyMotionLocked(const NotifyMotionArgs& args) REQUIRES(mLock);
// Call this function for outbound events so that they can be logged when logging is enabled.
void enqueueOutboundMotionLocked(const NotifyMotionArgs& args) REQUIRES(mLock);
diff --git a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp
index 58324c4..f852001 100644
--- a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp
+++ b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp
@@ -277,12 +277,12 @@
motionArgs.action = AMOTION_EVENT_ACTION_DOWN;
motionArgs.downTime = now();
motionArgs.eventTime = motionArgs.downTime;
- dispatcher.notifyMotion(&motionArgs);
+ dispatcher.notifyMotion(motionArgs);
// Send ACTION_UP
motionArgs.action = AMOTION_EVENT_ACTION_UP;
motionArgs.eventTime = now();
- dispatcher.notifyMotion(&motionArgs);
+ dispatcher.notifyMotion(motionArgs);
window->consumeEvent();
window->consumeEvent();
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index d6bf5e8..e8434be 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -4025,9 +4025,9 @@
return splitMotionEntry;
}
-void InputDispatcher::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) {
+void InputDispatcher::notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) {
if (debugInboundEventDetails()) {
- ALOGD("notifyConfigurationChanged - eventTime=%" PRId64, args->eventTime);
+ ALOGD("notifyConfigurationChanged - eventTime=%" PRId64, args.eventTime);
}
bool needWake = false;
@@ -4035,7 +4035,7 @@
std::scoped_lock _l(mLock);
std::unique_ptr<ConfigurationChangedEntry> newEntry =
- std::make_unique<ConfigurationChangedEntry>(args->id, args->eventTime);
+ std::make_unique<ConfigurationChangedEntry>(args.id, args.eventTime);
needWake = enqueueInboundEventLocked(std::move(newEntry));
} // release lock
@@ -4083,23 +4083,22 @@
}
}
-void InputDispatcher::notifyKey(const NotifyKeyArgs* args) {
+void InputDispatcher::notifyKey(const NotifyKeyArgs& args) {
ALOGD_IF(debugInboundEventDetails(),
"notifyKey - id=%" PRIx32 ", eventTime=%" PRId64
", deviceId=%d, source=%s, displayId=%" PRId32
"policyFlags=0x%x, action=%s, flags=0x%x, keyCode=%s, scanCode=0x%x, metaState=0x%x, "
"downTime=%" PRId64,
- args->id, args->eventTime, args->deviceId,
- inputEventSourceToString(args->source).c_str(), args->displayId, args->policyFlags,
- KeyEvent::actionToString(args->action), args->flags, KeyEvent::getLabel(args->keyCode),
- args->scanCode, args->metaState, args->downTime);
- if (!validateKeyEvent(args->action)) {
+ args.id, args.eventTime, args.deviceId, inputEventSourceToString(args.source).c_str(),
+ args.displayId, args.policyFlags, KeyEvent::actionToString(args.action), args.flags,
+ KeyEvent::getLabel(args.keyCode), args.scanCode, args.metaState, args.downTime);
+ if (!validateKeyEvent(args.action)) {
return;
}
- uint32_t policyFlags = args->policyFlags;
- int32_t flags = args->flags;
- int32_t metaState = args->metaState;
+ uint32_t policyFlags = args.policyFlags;
+ int32_t flags = args.flags;
+ int32_t metaState = args.metaState;
// InputDispatcher tracks and generates key repeats on behalf of
// whatever notifies it, so repeatCount should always be set to 0
constexpr int32_t repeatCount = 0;
@@ -4113,13 +4112,13 @@
policyFlags |= POLICY_FLAG_TRUSTED;
- int32_t keyCode = args->keyCode;
- accelerateMetaShortcuts(args->deviceId, args->action, keyCode, metaState);
+ int32_t keyCode = args.keyCode;
+ accelerateMetaShortcuts(args.deviceId, args.action, keyCode, metaState);
KeyEvent event;
- event.initialize(args->id, args->deviceId, args->source, args->displayId, INVALID_HMAC,
- args->action, flags, keyCode, args->scanCode, metaState, repeatCount,
- args->downTime, args->eventTime);
+ event.initialize(args.id, args.deviceId, args.source, args.displayId, INVALID_HMAC, args.action,
+ flags, keyCode, args.scanCode, metaState, repeatCount, args.downTime,
+ args.eventTime);
android::base::Timer t;
mPolicy->interceptKeyBeforeQueueing(&event, /*byref*/ policyFlags);
@@ -4144,10 +4143,9 @@
}
std::unique_ptr<KeyEntry> newEntry =
- std::make_unique<KeyEntry>(args->id, args->eventTime, args->deviceId, args->source,
- args->displayId, policyFlags, args->action, flags,
- keyCode, args->scanCode, metaState, repeatCount,
- args->downTime);
+ std::make_unique<KeyEntry>(args.id, args.eventTime, args.deviceId, args.source,
+ args.displayId, policyFlags, args.action, flags, keyCode,
+ args.scanCode, metaState, repeatCount, args.downTime);
needWake = enqueueInboundEventLocked(std::move(newEntry));
mLock.unlock();
@@ -4158,50 +4156,50 @@
}
}
-bool InputDispatcher::shouldSendKeyToInputFilterLocked(const NotifyKeyArgs* args) {
+bool InputDispatcher::shouldSendKeyToInputFilterLocked(const NotifyKeyArgs& args) {
return mInputFilterEnabled;
}
-void InputDispatcher::notifyMotion(const NotifyMotionArgs* args) {
+void InputDispatcher::notifyMotion(const NotifyMotionArgs& args) {
if (debugInboundEventDetails()) {
ALOGD("notifyMotion - id=%" PRIx32 " eventTime=%" PRId64 ", deviceId=%d, source=%s, "
"displayId=%" PRId32 ", policyFlags=0x%x, "
"action=%s, actionButton=0x%x, flags=0x%x, metaState=0x%x, buttonState=0x%x, "
"edgeFlags=0x%x, xPrecision=%f, yPrecision=%f, xCursorPosition=%f, "
"yCursorPosition=%f, downTime=%" PRId64,
- args->id, args->eventTime, args->deviceId,
- inputEventSourceToString(args->source).c_str(), args->displayId, args->policyFlags,
- MotionEvent::actionToString(args->action).c_str(), args->actionButton, args->flags,
- args->metaState, args->buttonState, args->edgeFlags, args->xPrecision,
- args->yPrecision, args->xCursorPosition, args->yCursorPosition, args->downTime);
- for (uint32_t i = 0; i < args->pointerCount; i++) {
+ args.id, args.eventTime, args.deviceId, inputEventSourceToString(args.source).c_str(),
+ args.displayId, args.policyFlags, MotionEvent::actionToString(args.action).c_str(),
+ args.actionButton, args.flags, args.metaState, args.buttonState, args.edgeFlags,
+ args.xPrecision, args.yPrecision, args.xCursorPosition, args.yCursorPosition,
+ args.downTime);
+ for (uint32_t i = 0; i < args.pointerCount; i++) {
ALOGD(" Pointer %d: id=%d, toolType=%s, x=%f, y=%f, pressure=%f, size=%f, "
"touchMajor=%f, touchMinor=%f, toolMajor=%f, toolMinor=%f, orientation=%f",
- i, args->pointerProperties[i].id,
- ftl::enum_string(args->pointerProperties[i].toolType).c_str(),
- args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X),
- args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y),
- args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
- args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_SIZE),
- args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
- args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
- args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
- args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
- args->pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION));
+ i, args.pointerProperties[i].id,
+ ftl::enum_string(args.pointerProperties[i].toolType).c_str(),
+ args.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_X),
+ args.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_Y),
+ args.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_PRESSURE),
+ args.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_SIZE),
+ args.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR),
+ args.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR),
+ args.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR),
+ args.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR),
+ args.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION));
}
}
- if (!validateMotionEvent(args->action, args->actionButton, args->pointerCount,
- args->pointerProperties)) {
- LOG(ERROR) << "Invalid event: " << args->dump();
+ if (!validateMotionEvent(args.action, args.actionButton, args.pointerCount,
+ args.pointerProperties)) {
+ LOG(ERROR) << "Invalid event: " << args.dump();
return;
}
- uint32_t policyFlags = args->policyFlags;
+ uint32_t policyFlags = args.policyFlags;
policyFlags |= POLICY_FLAG_TRUSTED;
android::base::Timer t;
- mPolicy->interceptMotionBeforeQueueing(args->displayId, args->eventTime, /*byref*/ policyFlags);
+ mPolicy->interceptMotionBeforeQueueing(args.displayId, args.eventTime, policyFlags);
if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) {
ALOGW("Excessive delay in interceptMotionBeforeQueueing; took %s ms",
std::to_string(t.duration().count()).c_str());
@@ -4213,10 +4211,10 @@
if (!(policyFlags & POLICY_FLAG_PASS_TO_USER)) {
// Set the flag anyway if we already have an ongoing gesture. That would allow us to
// complete the processing of the current stroke.
- const auto touchStateIt = mTouchStatesByDisplay.find(args->displayId);
+ const auto touchStateIt = mTouchStatesByDisplay.find(args.displayId);
if (touchStateIt != mTouchStatesByDisplay.end()) {
const TouchState& touchState = touchStateIt->second;
- if (touchState.deviceId == args->deviceId && touchState.isDown()) {
+ if (touchState.deviceId == args.deviceId && touchState.isDown()) {
policyFlags |= POLICY_FLAG_PASS_TO_USER;
}
}
@@ -4224,20 +4222,20 @@
if (shouldSendMotionToInputFilterLocked(args)) {
ui::Transform displayTransform;
- if (const auto it = mDisplayInfos.find(args->displayId); it != mDisplayInfos.end()) {
+ if (const auto it = mDisplayInfos.find(args.displayId); it != mDisplayInfos.end()) {
displayTransform = it->second.transform;
}
mLock.unlock();
MotionEvent event;
- event.initialize(args->id, args->deviceId, args->source, args->displayId, INVALID_HMAC,
- args->action, args->actionButton, args->flags, args->edgeFlags,
- args->metaState, args->buttonState, args->classification,
- displayTransform, args->xPrecision, args->yPrecision,
- args->xCursorPosition, args->yCursorPosition, displayTransform,
- args->downTime, args->eventTime, args->pointerCount,
- args->pointerProperties, args->pointerCoords);
+ event.initialize(args.id, args.deviceId, args.source, args.displayId, INVALID_HMAC,
+ args.action, args.actionButton, args.flags, args.edgeFlags,
+ args.metaState, args.buttonState, args.classification,
+ displayTransform, args.xPrecision, args.yPrecision,
+ args.xCursorPosition, args.yCursorPosition, displayTransform,
+ args.downTime, args.eventTime, args.pointerCount,
+ args.pointerProperties, args.pointerCoords);
policyFlags |= POLICY_FLAG_FILTERED;
if (!mPolicy->filterInputEvent(&event, policyFlags)) {
@@ -4249,21 +4247,20 @@
// Just enqueue a new motion event.
std::unique_ptr<MotionEntry> newEntry =
- std::make_unique<MotionEntry>(args->id, args->eventTime, args->deviceId,
- args->source, args->displayId, policyFlags,
- args->action, args->actionButton, args->flags,
- args->metaState, args->buttonState,
- args->classification, args->edgeFlags,
- args->xPrecision, args->yPrecision,
- args->xCursorPosition, args->yCursorPosition,
- args->downTime, args->pointerCount,
- args->pointerProperties, args->pointerCoords);
+ std::make_unique<MotionEntry>(args.id, args.eventTime, args.deviceId, args.source,
+ args.displayId, policyFlags, args.action,
+ args.actionButton, args.flags, args.metaState,
+ args.buttonState, args.classification, args.edgeFlags,
+ args.xPrecision, args.yPrecision,
+ args.xCursorPosition, args.yCursorPosition,
+ args.downTime, args.pointerCount,
+ args.pointerProperties, args.pointerCoords);
- if (args->id != android::os::IInputConstants::INVALID_INPUT_EVENT_ID &&
- IdGenerator::getSource(args->id) == IdGenerator::Source::INPUT_READER &&
+ if (args.id != android::os::IInputConstants::INVALID_INPUT_EVENT_ID &&
+ IdGenerator::getSource(args.id) == IdGenerator::Source::INPUT_READER &&
!mInputFilterEnabled) {
- const bool isDown = args->action == AMOTION_EVENT_ACTION_DOWN;
- mLatencyTracker.trackListener(args->id, isDown, args->eventTime, args->readTime);
+ const bool isDown = args.action == AMOTION_EVENT_ACTION_DOWN;
+ mLatencyTracker.trackListener(args.id, isDown, args.eventTime, args.readTime);
}
needWake = enqueueInboundEventLocked(std::move(newEntry));
@@ -4275,12 +4272,12 @@
}
}
-void InputDispatcher::notifySensor(const NotifySensorArgs* args) {
+void InputDispatcher::notifySensor(const NotifySensorArgs& args) {
if (debugInboundEventDetails()) {
ALOGD("notifySensor - id=%" PRIx32 " eventTime=%" PRId64 ", deviceId=%d, source=0x%x, "
" sensorType=%s",
- args->id, args->eventTime, args->deviceId, args->source,
- ftl::enum_string(args->sensorType).c_str());
+ args.id, args.eventTime, args.deviceId, args.source,
+ ftl::enum_string(args.sensorType).c_str());
}
bool needWake = false;
@@ -4289,10 +4286,9 @@
// Just enqueue a new sensor event.
std::unique_ptr<SensorEntry> newEntry =
- std::make_unique<SensorEntry>(args->id, args->eventTime, args->deviceId,
- args->source, /* policyFlags=*/0, args->hwTimestamp,
- args->sensorType, args->accuracy,
- args->accuracyChanged, args->values);
+ std::make_unique<SensorEntry>(args.id, args.eventTime, args.deviceId, args.source,
+ /* policyFlags=*/0, args.hwTimestamp, args.sensorType,
+ args.accuracy, args.accuracyChanged, args.values);
needWake = enqueueInboundEventLocked(std::move(newEntry));
mLock.unlock();
@@ -4303,34 +4299,34 @@
}
}
-void InputDispatcher::notifyVibratorState(const NotifyVibratorStateArgs* args) {
+void InputDispatcher::notifyVibratorState(const NotifyVibratorStateArgs& args) {
if (debugInboundEventDetails()) {
- ALOGD("notifyVibratorState - eventTime=%" PRId64 ", device=%d, isOn=%d", args->eventTime,
- args->deviceId, args->isOn);
+ ALOGD("notifyVibratorState - eventTime=%" PRId64 ", device=%d, isOn=%d", args.eventTime,
+ args.deviceId, args.isOn);
}
- mPolicy->notifyVibratorState(args->deviceId, args->isOn);
+ mPolicy->notifyVibratorState(args.deviceId, args.isOn);
}
-bool InputDispatcher::shouldSendMotionToInputFilterLocked(const NotifyMotionArgs* args) {
+bool InputDispatcher::shouldSendMotionToInputFilterLocked(const NotifyMotionArgs& args) {
return mInputFilterEnabled;
}
-void InputDispatcher::notifySwitch(const NotifySwitchArgs* args) {
+void InputDispatcher::notifySwitch(const NotifySwitchArgs& args) {
if (debugInboundEventDetails()) {
ALOGD("notifySwitch - eventTime=%" PRId64 ", policyFlags=0x%x, switchValues=0x%08x, "
"switchMask=0x%08x",
- args->eventTime, args->policyFlags, args->switchValues, args->switchMask);
+ args.eventTime, args.policyFlags, args.switchValues, args.switchMask);
}
- uint32_t policyFlags = args->policyFlags;
+ uint32_t policyFlags = args.policyFlags;
policyFlags |= POLICY_FLAG_TRUSTED;
- mPolicy->notifySwitch(args->eventTime, args->switchValues, args->switchMask, policyFlags);
+ mPolicy->notifySwitch(args.eventTime, args.switchValues, args.switchMask, policyFlags);
}
-void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
+void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs& args) {
if (debugInboundEventDetails()) {
- ALOGD("notifyDeviceReset - eventTime=%" PRId64 ", deviceId=%d", args->eventTime,
- args->deviceId);
+ ALOGD("notifyDeviceReset - eventTime=%" PRId64 ", deviceId=%d", args.eventTime,
+ args.deviceId);
}
bool needWake = false;
@@ -4338,7 +4334,7 @@
std::scoped_lock _l(mLock);
std::unique_ptr<DeviceResetEntry> newEntry =
- std::make_unique<DeviceResetEntry>(args->id, args->eventTime, args->deviceId);
+ std::make_unique<DeviceResetEntry>(args.id, args.eventTime, args.deviceId);
needWake = enqueueInboundEventLocked(std::move(newEntry));
} // release lock
@@ -4347,17 +4343,17 @@
}
}
-void InputDispatcher::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) {
+void InputDispatcher::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) {
if (debugInboundEventDetails()) {
- ALOGD("notifyPointerCaptureChanged - eventTime=%" PRId64 ", enabled=%s", args->eventTime,
- args->request.enable ? "true" : "false");
+ ALOGD("notifyPointerCaptureChanged - eventTime=%" PRId64 ", enabled=%s", args.eventTime,
+ args.request.enable ? "true" : "false");
}
bool needWake = false;
{ // acquire lock
std::scoped_lock _l(mLock);
- auto entry = std::make_unique<PointerCaptureChangedEntry>(args->id, args->eventTime,
- args->request);
+ auto entry =
+ std::make_unique<PointerCaptureChangedEntry>(args.id, args.eventTime, args.request);
needWake = enqueueInboundEventLocked(std::move(entry));
} // release lock
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index aaf1214..4aba24c 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -94,14 +94,14 @@
status_t stop() override;
void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override{};
- void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override;
- void notifyKey(const NotifyKeyArgs* args) override;
- void notifyMotion(const NotifyMotionArgs* args) override;
- void notifySwitch(const NotifySwitchArgs* args) override;
- void notifySensor(const NotifySensorArgs* args) override;
- void notifyVibratorState(const NotifyVibratorStateArgs* args) override;
- void notifyDeviceReset(const NotifyDeviceResetArgs* args) override;
- void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) override;
+ void notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) override;
+ void notifyKey(const NotifyKeyArgs& args) override;
+ void notifyMotion(const NotifyMotionArgs& args) override;
+ void notifySwitch(const NotifySwitchArgs& args) override;
+ void notifySensor(const NotifySensorArgs& args) override;
+ void notifyVibratorState(const NotifyVibratorStateArgs& args) override;
+ void notifyDeviceReset(const NotifyDeviceResetArgs& args) override;
+ void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) override;
android::os::InputEventInjectionResult injectInputEvent(
const InputEvent* event, std::optional<int32_t> targetUid,
@@ -332,8 +332,8 @@
REQUIRES(mLock);
// Input filter processing.
- bool shouldSendKeyToInputFilterLocked(const NotifyKeyArgs* args) REQUIRES(mLock);
- bool shouldSendMotionToInputFilterLocked(const NotifyMotionArgs* args) REQUIRES(mLock);
+ bool shouldSendKeyToInputFilterLocked(const NotifyKeyArgs& args) REQUIRES(mLock);
+ bool shouldSendMotionToInputFilterLocked(const NotifyMotionArgs& args) REQUIRES(mLock);
// Inbound event processing.
void drainInboundQueueLocked() REQUIRES(mLock);
diff --git a/services/inputflinger/include/InputListener.h b/services/inputflinger/include/InputListener.h
index d1b86c8..4f78f03 100644
--- a/services/inputflinger/include/InputListener.h
+++ b/services/inputflinger/include/InputListener.h
@@ -38,14 +38,14 @@
virtual ~InputListenerInterface() { }
virtual void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) = 0;
- virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) = 0;
- virtual void notifyKey(const NotifyKeyArgs* args) = 0;
- virtual void notifyMotion(const NotifyMotionArgs* args) = 0;
- virtual void notifySwitch(const NotifySwitchArgs* args) = 0;
- virtual void notifySensor(const NotifySensorArgs* args) = 0;
- virtual void notifyVibratorState(const NotifyVibratorStateArgs* args) = 0;
- virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) = 0;
- virtual void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) = 0;
+ virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) = 0;
+ virtual void notifyKey(const NotifyKeyArgs& args) = 0;
+ virtual void notifyMotion(const NotifyMotionArgs& args) = 0;
+ virtual void notifySwitch(const NotifySwitchArgs& args) = 0;
+ virtual void notifySensor(const NotifySensorArgs& args) = 0;
+ virtual void notifyVibratorState(const NotifyVibratorStateArgs& args) = 0;
+ virtual void notifyDeviceReset(const NotifyDeviceResetArgs& args) = 0;
+ virtual void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) = 0;
void notify(const NotifyArgs& args);
};
@@ -60,14 +60,14 @@
explicit QueuedInputListener(InputListenerInterface& innerListener);
virtual void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override;
- virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override;
- virtual void notifyKey(const NotifyKeyArgs* args) override;
- virtual void notifyMotion(const NotifyMotionArgs* args) override;
- virtual void notifySwitch(const NotifySwitchArgs* args) override;
- virtual void notifySensor(const NotifySensorArgs* args) override;
- virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) override;
- void notifyVibratorState(const NotifyVibratorStateArgs* args) override;
- void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) override;
+ virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) override;
+ virtual void notifyKey(const NotifyKeyArgs& args) override;
+ virtual void notifyMotion(const NotifyMotionArgs& args) override;
+ virtual void notifySwitch(const NotifySwitchArgs& args) override;
+ virtual void notifySensor(const NotifySensorArgs& args) override;
+ virtual void notifyDeviceReset(const NotifyDeviceResetArgs& args) override;
+ void notifyVibratorState(const NotifyVibratorStateArgs& args) override;
+ void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) override;
void flush();
diff --git a/services/inputflinger/include/NotifyArgs.h b/services/inputflinger/include/NotifyArgs.h
index f12482b..7d29dd9 100644
--- a/services/inputflinger/include/NotifyArgs.h
+++ b/services/inputflinger/include/NotifyArgs.h
@@ -36,6 +36,7 @@
bool operator==(const NotifyInputDevicesChangedArgs& rhs) const = default;
NotifyInputDevicesChangedArgs(const NotifyInputDevicesChangedArgs& other) = default;
+ NotifyInputDevicesChangedArgs& operator=(const NotifyInputDevicesChangedArgs&) = default;
};
/* Describes a configuration change event. */
@@ -50,6 +51,7 @@
bool operator==(const NotifyConfigurationChangedArgs& rhs) const = default;
NotifyConfigurationChangedArgs(const NotifyConfigurationChangedArgs& other) = default;
+ NotifyConfigurationChangedArgs& operator=(const NotifyConfigurationChangedArgs&) = default;
};
/* Describes a key event. */
@@ -79,6 +81,7 @@
bool operator==(const NotifyKeyArgs& rhs) const = default;
NotifyKeyArgs(const NotifyKeyArgs& other) = default;
+ NotifyKeyArgs& operator=(const NotifyKeyArgs&) = default;
};
/* Describes a motion event. */
@@ -129,7 +132,6 @@
const std::vector<TouchVideoFrame>& videoFrames);
NotifyMotionArgs(const NotifyMotionArgs& other);
-
NotifyMotionArgs& operator=(const android::NotifyMotionArgs&) = default;
bool operator==(const NotifyMotionArgs& rhs) const;
@@ -157,6 +159,7 @@
bool accuracyChanged, nsecs_t hwTimestamp, std::vector<float> values);
NotifySensorArgs(const NotifySensorArgs& other) = default;
+ NotifySensorArgs& operator=(const NotifySensorArgs&) = default;
};
/* Describes a switch event. */
@@ -174,6 +177,7 @@
uint32_t switchMask);
NotifySwitchArgs(const NotifySwitchArgs& other) = default;
+ NotifySwitchArgs& operator=(const NotifySwitchArgs&) = default;
bool operator==(const NotifySwitchArgs& rhs) const = default;
};
@@ -191,6 +195,7 @@
NotifyDeviceResetArgs(int32_t id, nsecs_t eventTime, int32_t deviceId);
NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other) = default;
+ NotifyDeviceResetArgs& operator=(const NotifyDeviceResetArgs&) = default;
bool operator==(const NotifyDeviceResetArgs& rhs) const = default;
};
@@ -207,6 +212,7 @@
NotifyPointerCaptureChangedArgs(int32_t id, nsecs_t eventTime, const PointerCaptureRequest&);
NotifyPointerCaptureChangedArgs(const NotifyPointerCaptureChangedArgs& other) = default;
+ NotifyPointerCaptureChangedArgs& operator=(const NotifyPointerCaptureChangedArgs&) = default;
};
/* Describes a vibrator state event. */
@@ -222,6 +228,7 @@
NotifyVibratorStateArgs(int32_t id, nsecs_t eventTIme, int32_t deviceId, bool isOn);
NotifyVibratorStateArgs(const NotifyVibratorStateArgs& other) = default;
+ NotifyVibratorStateArgs& operator=(const NotifyVibratorStateArgs&) = default;
};
using NotifyArgs =
diff --git a/services/inputflinger/reader/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp
index 6f54faa..0afe79d 100644
--- a/services/inputflinger/reader/InputReader.cpp
+++ b/services/inputflinger/reader/InputReader.cpp
@@ -387,8 +387,7 @@
updateGlobalMetaStateLocked();
// Enqueue configuration changed.
- NotifyConfigurationChangedArgs args(mContext.getNextId(), when);
- mQueuedListener.notifyConfigurationChanged(&args);
+ mQueuedListener.notifyConfigurationChanged({mContext.getNextId(), when});
}
void InputReader::refreshConfigurationLocked(uint32_t changes) {
@@ -420,9 +419,8 @@
"There was no change in the pointer capture state.");
} else {
mCurrentPointerCaptureRequest = mConfig.pointerCaptureRequest;
- const NotifyPointerCaptureChangedArgs args(mContext.getNextId(), now,
- mCurrentPointerCaptureRequest);
- mQueuedListener.notifyPointerCaptureChanged(&args);
+ mQueuedListener.notifyPointerCaptureChanged(
+ {mContext.getNextId(), now, mCurrentPointerCaptureRequest});
}
}
}
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index 5e51bfc..27d7b9c 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -818,8 +818,7 @@
TEST_F(InputDispatcherTest, NotifyConfigurationChanged_CallsPolicy) {
constexpr nsecs_t eventTime = 20;
- NotifyConfigurationChangedArgs args(/*id=*/10, eventTime);
- mDispatcher->notifyConfigurationChanged(&args);
+ mDispatcher->notifyConfigurationChanged({/*id=*/10, eventTime});
ASSERT_TRUE(mDispatcher->waitForIdle());
mFakePolicy->assertNotifyConfigurationChangedWasCalled(eventTime);
@@ -828,7 +827,7 @@
TEST_F(InputDispatcherTest, NotifySwitch_CallsPolicy) {
NotifySwitchArgs args(/*id=*/10, /*eventTime=*/20, /*policyFlags=*/0, /*switchValues=*/1,
/*switchMask=*/2);
- mDispatcher->notifySwitch(&args);
+ mDispatcher->notifySwitch(args);
// InputDispatcher adds POLICY_FLAG_TRUSTED because the event went through InputListener
args.policyFlags |= POLICY_FLAG_TRUSTED;
@@ -1743,8 +1742,9 @@
return args;
}
-static NotifyMotionArgs generateMotionArgs(int32_t action, int32_t source, int32_t displayId,
- const std::vector<PointF>& points) {
+[[nodiscard]] static NotifyMotionArgs generateMotionArgs(int32_t action, int32_t source,
+ int32_t displayId,
+ const std::vector<PointF>& points) {
size_t pointerCount = points.size();
if (action == AMOTION_EVENT_ACTION_DOWN || action == AMOTION_EVENT_ACTION_UP) {
EXPECT_EQ(1U, pointerCount) << "Actions DOWN and UP can only contain a single pointer";
@@ -1946,26 +1946,20 @@
sp<FakeWindowHandle>::make(application, mDispatcher, "Window", ADISPLAY_ID_DEFAULT);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- NotifyMotionArgs args;
// First touch pointer down on right window
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
+ .build());
// Second touch pointer down
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
-
- .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
- .pointer(PointerBuilder(1, ToolType::FINGER).x(110).y(100))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
+ .pointer(PointerBuilder(1, ToolType::FINGER).x(110).y(100))
+ .build());
// First touch pointer lifts. The second one remains down
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(POINTER_0_UP, AINPUT_SOURCE_TOUCHSCREEN)
-
- .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
- .pointer(PointerBuilder(1, ToolType::FINGER).x(110).y(100))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_0_UP, AINPUT_SOURCE_TOUCHSCREEN)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
+ .pointer(PointerBuilder(1, ToolType::FINGER).x(110).y(100))
+ .build());
window->consumeMotionEvent(WithMotionAction(ACTION_DOWN));
window->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN));
window->consumeMotionEvent(WithMotionAction(POINTER_0_UP));
@@ -2256,54 +2250,48 @@
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {spyWindow, window}}});
const int32_t touchDeviceId = 4;
- NotifyMotionArgs args;
// Two pointers down
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .policyFlags(DEFAULT_POLICY_FLAGS)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
- .build()));
+ mDispatcher->notifyMotion(
+ MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .policyFlags(DEFAULT_POLICY_FLAGS)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
+ .build());
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .policyFlags(DEFAULT_POLICY_FLAGS)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
- .pointer(PointerBuilder(1, ToolType::FINGER).x(120).y(120))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .policyFlags(DEFAULT_POLICY_FLAGS)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
+ .pointer(PointerBuilder(1, ToolType::FINGER).x(120).y(120))
+ .build());
spyWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN));
spyWindow->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN));
window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN));
window->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN));
// Cancel the current gesture. Send the cancel without the default policy flags.
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(AMOTION_EVENT_ACTION_CANCEL, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .policyFlags(0)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
- .pointer(PointerBuilder(1, ToolType::FINGER).x(120).y(120))
- .build()));
+ mDispatcher->notifyMotion(
+ MotionArgsBuilder(AMOTION_EVENT_ACTION_CANCEL, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .policyFlags(0)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
+ .pointer(PointerBuilder(1, ToolType::FINGER).x(120).y(120))
+ .build());
spyWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL));
window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL));
// We don't need to reset the device to reproduce the issue, but the reset event typically
// follows, so we keep it here to model the actual listener behaviour more closely.
- NotifyDeviceResetArgs resetArgs;
- resetArgs.id = 1; // arbitrary id
- resetArgs.eventTime = systemTime(SYSTEM_TIME_MONOTONIC);
- resetArgs.deviceId = touchDeviceId;
- mDispatcher->notifyDeviceReset(&resetArgs);
+ mDispatcher->notifyDeviceReset({/*id=*/1, systemTime(SYSTEM_TIME_MONOTONIC), touchDeviceId});
// Start new gesture
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .policyFlags(DEFAULT_POLICY_FLAGS)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
- .build()));
+ mDispatcher->notifyMotion(
+ MotionArgsBuilder(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .policyFlags(DEFAULT_POLICY_FLAGS)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
+ .build());
spyWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN));
window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_DOWN));
@@ -2453,53 +2441,49 @@
NotifyMotionArgs args;
// Start hovering over the left window
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE)
- .deviceId(mouseDeviceId)
- .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE)
+ .deviceId(mouseDeviceId)
+ .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100))
+ .build());
leftWindow->consumeMotionEvent(
AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId)));
// Mouse down on left window
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE)
- .deviceId(mouseDeviceId)
- .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
- .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE)
+ .deviceId(mouseDeviceId)
+ .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
+ .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100))
+ .build());
leftWindow->consumeMotionEvent(
AllOf(WithMotionAction(ACTION_HOVER_EXIT), WithDeviceId(mouseDeviceId)));
leftWindow->consumeMotionEvent(
AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(mouseDeviceId)));
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, AINPUT_SOURCE_MOUSE)
- .deviceId(mouseDeviceId)
- .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
- .actionButton(AMOTION_EVENT_BUTTON_PRIMARY)
- .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100))
- .build()));
+ mDispatcher->notifyMotion(
+ MotionArgsBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, AINPUT_SOURCE_MOUSE)
+ .deviceId(mouseDeviceId)
+ .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
+ .actionButton(AMOTION_EVENT_BUTTON_PRIMARY)
+ .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100))
+ .build());
leftWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS));
// First touch pointer down on right window
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100))
+ .build());
leftWindow->consumeMotionEvent(WithMotionAction(ACTION_CANCEL));
rightWindow->consumeMotionEvent(WithMotionAction(ACTION_DOWN));
// Second touch pointer down on left window
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100))
- .pointer(PointerBuilder(1, ToolType::FINGER).x(100).y(100))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100))
+ .pointer(PointerBuilder(1, ToolType::FINGER).x(100).y(100))
+ .build());
leftWindow->consumeMotionEvent(
AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(touchDeviceId)));
// This MOVE event is not necessary (doesn't carry any new information), but it's there in the
@@ -2533,57 +2517,52 @@
NotifyMotionArgs args;
// First touch pointer down
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100))
+ .build());
// Second touch pointer down
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100))
- .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100))
+ .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100))
+ .build());
// First touch pointer lifts. The second one remains down
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(POINTER_0_UP, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100))
- .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_0_UP, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100))
+ .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100))
+ .build());
window->consumeMotionEvent(WithMotionAction(ACTION_DOWN));
window->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN));
window->consumeMotionEvent(WithMotionAction(POINTER_0_UP));
// Mouse down. The touch should be canceled
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE)
- .deviceId(mouseDeviceId)
- .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
- .pointer(PointerBuilder(0, ToolType::MOUSE).x(320).y(100))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE)
+ .deviceId(mouseDeviceId)
+ .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
+ .pointer(PointerBuilder(0, ToolType::MOUSE).x(320).y(100))
+ .build());
window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(touchDeviceId),
WithPointerCount(1u)));
window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(mouseDeviceId)));
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, AINPUT_SOURCE_MOUSE)
- .deviceId(mouseDeviceId)
- .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
- .actionButton(AMOTION_EVENT_BUTTON_PRIMARY)
- .pointer(PointerBuilder(0, ToolType::MOUSE).x(320).y(100))
- .build()));
+ mDispatcher->notifyMotion(
+ MotionArgsBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, AINPUT_SOURCE_MOUSE)
+ .deviceId(mouseDeviceId)
+ .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
+ .actionButton(AMOTION_EVENT_BUTTON_PRIMARY)
+ .pointer(PointerBuilder(0, ToolType::MOUSE).x(320).y(100))
+ .build());
window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS));
// Second touch pointer down.
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(POINTER_0_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100))
- .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_0_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100))
+ .pointer(PointerBuilder(1, ToolType::FINGER).x(350).y(100))
+ .build());
// The pointer_down event should be ignored
window->assertNoEvents();
}
@@ -2617,11 +2596,10 @@
// Now a real touch comes. Rather than crashing or dropping the real event, the injected pointer
// should be canceled and the new gesture should take over.
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(300).y(100))
+ .build());
window->consumeMotionEvent(
AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(VIRTUAL_KEYBOARD_ID)));
@@ -2823,46 +2801,38 @@
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {spyWindow, window}}});
- NotifyMotionArgs args;
-
// Start hovering with stylus
- mDispatcher->notifyMotion(
- &(args = MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS)
- .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS)
+ .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50))
+ .build());
spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER));
// Stop hovering
- mDispatcher->notifyMotion(
- &(args = MotionArgsBuilder(ACTION_HOVER_EXIT, AINPUT_SOURCE_STYLUS)
- .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_EXIT, AINPUT_SOURCE_STYLUS)
+ .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50))
+ .build());
spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT));
// Stylus touches down
- mDispatcher->notifyMotion(
- &(args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS)
- .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_STYLUS)
+ .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50))
+ .build());
spyWindow->consumeMotionEvent(WithMotionAction(ACTION_DOWN));
// Stylus goes up
- mDispatcher->notifyMotion(
- &(args = MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_STYLUS)
- .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_STYLUS)
+ .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50))
+ .build());
spyWindow->consumeMotionEvent(WithMotionAction(ACTION_UP));
// Again hover
- mDispatcher->notifyMotion(
- &(args = MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS)
- .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_STYLUS)
+ .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50))
+ .build());
spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER));
// Stop hovering
- mDispatcher->notifyMotion(
- &(args = MotionArgsBuilder(ACTION_HOVER_EXIT, AINPUT_SOURCE_STYLUS)
- .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_EXIT, AINPUT_SOURCE_STYLUS)
+ .pointer(PointerBuilder(0, ToolType::STYLUS).x(50).y(50))
+ .build());
spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT));
// No more events
@@ -2891,35 +2861,31 @@
const int32_t mouseDeviceId = 7;
const int32_t touchDeviceId = 4;
- NotifyMotionArgs args;
// Hover a bit with mouse first
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE)
- .deviceId(mouseDeviceId)
- .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE)
+ .deviceId(mouseDeviceId)
+ .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100))
+ .build());
spyWindow->consumeMotionEvent(
AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId)));
window->consumeMotionEvent(
AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId)));
// Start touching
- mDispatcher->notifyMotion(
- &(args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50))
+ .build());
spyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT));
window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT));
spyWindow->consumeMotionEvent(WithMotionAction(ACTION_DOWN));
window->consumeMotionEvent(WithMotionAction(ACTION_DOWN));
- mDispatcher->notifyMotion(
- &(args = MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(55).y(55))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(55).y(55))
+ .build());
spyWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE));
window->consumeMotionEvent(WithMotionAction(ACTION_MOVE));
@@ -2927,20 +2893,18 @@
EXPECT_EQ(OK, mDispatcher->pilferPointers(spyWindow->getToken()));
window->consumeMotionEvent(WithMotionAction(ACTION_CANCEL));
- mDispatcher->notifyMotion(
- &(args = MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(60).y(60))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(60).y(60))
+ .build());
spyWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE));
// Mouse down
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE)
- .deviceId(mouseDeviceId)
- .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
- .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE)
+ .deviceId(mouseDeviceId)
+ .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
+ .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100))
+ .build());
spyWindow->consumeMotionEvent(
AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(touchDeviceId)));
@@ -2948,32 +2912,30 @@
AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(mouseDeviceId)));
window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(mouseDeviceId)));
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, AINPUT_SOURCE_MOUSE)
- .deviceId(mouseDeviceId)
- .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
- .actionButton(AMOTION_EVENT_BUTTON_PRIMARY)
- .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100))
- .build()));
+ mDispatcher->notifyMotion(
+ MotionArgsBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, AINPUT_SOURCE_MOUSE)
+ .deviceId(mouseDeviceId)
+ .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
+ .actionButton(AMOTION_EVENT_BUTTON_PRIMARY)
+ .pointer(PointerBuilder(0, ToolType::MOUSE).x(100).y(100))
+ .build());
spyWindow->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS));
window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS));
// Mouse move!
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_MOUSE)
- .deviceId(mouseDeviceId)
- .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
- .pointer(PointerBuilder(0, ToolType::MOUSE).x(110).y(110))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_MOUSE)
+ .deviceId(mouseDeviceId)
+ .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
+ .pointer(PointerBuilder(0, ToolType::MOUSE).x(110).y(110))
+ .build());
spyWindow->consumeMotionEvent(WithMotionAction(ACTION_MOVE));
window->consumeMotionEvent(WithMotionAction(ACTION_MOVE));
// Touch move!
- mDispatcher->notifyMotion(
- &(args = MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(65).y(65))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(65).y(65))
+ .build());
// No more events
spyWindow->assertNoEvents();
@@ -2991,16 +2953,15 @@
sp<FakeWindowHandle>::make(application, mDispatcher, "Window", DISPLAY_ID);
mDispatcher->setInputWindows({{DISPLAY_ID, {window}}});
- NotifyMotionArgs args;
// Touch down on the empty space
- mDispatcher->notifyMotion(&(args = generateTouchArgs(AMOTION_EVENT_ACTION_DOWN, {{-1, -1}})));
+ mDispatcher->notifyMotion(generateTouchArgs(AMOTION_EVENT_ACTION_DOWN, {{-1, -1}}));
mDispatcher->waitForIdle();
window->assertNoEvents();
// Now touch down on the window with another pointer
- mDispatcher->notifyMotion(&(args = generateTouchArgs(POINTER_1_DOWN, {{-1, -1}, {10, 10}})));
+ mDispatcher->notifyMotion(generateTouchArgs(POINTER_1_DOWN, {{-1, -1}, {10, 10}}));
mDispatcher->waitForIdle();
window->consumeMotionDown();
}
@@ -3021,16 +2982,15 @@
mDispatcher->setInputWindows({{DISPLAY_ID, {window1, window2}}});
- NotifyMotionArgs args;
// Touch down on the non-touchable window
- mDispatcher->notifyMotion(&(args = generateTouchArgs(AMOTION_EVENT_ACTION_DOWN, {{50, 50}})));
+ mDispatcher->notifyMotion(generateTouchArgs(AMOTION_EVENT_ACTION_DOWN, {{50, 50}}));
mDispatcher->waitForIdle();
window1->assertNoEvents();
window2->assertNoEvents();
// Now touch down on the window with another pointer
- mDispatcher->notifyMotion(&(args = generateTouchArgs(POINTER_1_DOWN, {{50, 50}, {150, 50}})));
+ mDispatcher->notifyMotion(generateTouchArgs(POINTER_1_DOWN, {{50, 50}, {150, 50}}));
mDispatcher->waitForIdle();
window2->consumeMotionDown();
}
@@ -3050,9 +3010,8 @@
mDispatcher->setInputWindows({{DISPLAY_ID, {window1, window2}}});
- NotifyMotionArgs args;
// Touch down on the first window
- mDispatcher->notifyMotion(&(args = generateTouchArgs(AMOTION_EVENT_ACTION_DOWN, {{50, 50}})));
+ mDispatcher->notifyMotion(generateTouchArgs(AMOTION_EVENT_ACTION_DOWN, {{50, 50}}));
mDispatcher->waitForIdle();
InputEvent* inputEvent1 = window1->consume();
@@ -3063,7 +3022,7 @@
ASSERT_EQ(motionEvent1.getDownTime(), motionEvent1.getEventTime());
// Now touch down on the window with another pointer
- mDispatcher->notifyMotion(&(args = generateTouchArgs(POINTER_1_DOWN, {{50, 50}, {150, 50}})));
+ mDispatcher->notifyMotion(generateTouchArgs(POINTER_1_DOWN, {{50, 50}, {150, 50}}));
mDispatcher->waitForIdle();
InputEvent* inputEvent2 = window2->consume();
ASSERT_NE(inputEvent2, nullptr);
@@ -3073,14 +3032,12 @@
ASSERT_EQ(motionEvent2.getDownTime(), motionEvent2.getEventTime());
// Now move the pointer on the second window
- mDispatcher->notifyMotion(
- &(args = generateTouchArgs(AMOTION_EVENT_ACTION_MOVE, {{50, 50}, {151, 51}})));
+ mDispatcher->notifyMotion(generateTouchArgs(AMOTION_EVENT_ACTION_MOVE, {{50, 50}, {151, 51}}));
mDispatcher->waitForIdle();
window2->consumeMotionEvent(WithDownTime(downTimeForWindow2));
// Now add new touch down on the second window
- mDispatcher->notifyMotion(
- &(args = generateTouchArgs(POINTER_2_DOWN, {{50, 50}, {151, 51}, {150, 50}})));
+ mDispatcher->notifyMotion(generateTouchArgs(POINTER_2_DOWN, {{50, 50}, {151, 51}, {150, 50}}));
mDispatcher->waitForIdle();
window2->consumeMotionEvent(WithDownTime(downTimeForWindow2));
@@ -3089,13 +3046,13 @@
window1->assertNoEvents();
// Now move the pointer on the first window
- mDispatcher->notifyMotion(&(
- args = generateTouchArgs(AMOTION_EVENT_ACTION_MOVE, {{51, 51}, {151, 51}, {150, 50}})));
+ mDispatcher->notifyMotion(
+ generateTouchArgs(AMOTION_EVENT_ACTION_MOVE, {{51, 51}, {151, 51}, {150, 50}}));
mDispatcher->waitForIdle();
window1->consumeMotionEvent(WithDownTime(downTimeForWindow1));
- mDispatcher->notifyMotion(&(
- args = generateTouchArgs(POINTER_3_DOWN, {{51, 51}, {151, 51}, {150, 50}, {50, 50}})));
+ mDispatcher->notifyMotion(
+ generateTouchArgs(POINTER_3_DOWN, {{51, 51}, {151, 51}, {150, 50}, {50, 50}}));
mDispatcher->waitForIdle();
window1->consumeMotionEvent(WithDownTime(downTimeForWindow1));
}
@@ -3199,52 +3156,47 @@
const int32_t touchDeviceId = 4;
const int32_t mouseDeviceId = 6;
- NotifyMotionArgs args;
// Two pointers down
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
+ .build());
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
- .pointer(PointerBuilder(1, ToolType::FINGER).x(120).y(120))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(100).y(100))
+ .pointer(PointerBuilder(1, ToolType::FINGER).x(120).y(120))
+ .build());
window->consumeMotionEvent(WithMotionAction(ACTION_DOWN));
window->consumeMotionEvent(WithMotionAction(POINTER_1_DOWN));
// Inject a series of mouse events for a mouse click
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE)
- .deviceId(mouseDeviceId)
- .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
- .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_MOUSE)
+ .deviceId(mouseDeviceId)
+ .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
+ .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400))
+ .build());
window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_CANCEL), WithDeviceId(touchDeviceId),
WithPointerCount(2u)));
window->consumeMotionEvent(AllOf(WithMotionAction(ACTION_DOWN), WithDeviceId(mouseDeviceId)));
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, AINPUT_SOURCE_MOUSE)
- .deviceId(mouseDeviceId)
- .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
- .actionButton(AMOTION_EVENT_BUTTON_PRIMARY)
- .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400))
- .build()));
+ mDispatcher->notifyMotion(
+ MotionArgsBuilder(AMOTION_EVENT_ACTION_BUTTON_PRESS, AINPUT_SOURCE_MOUSE)
+ .deviceId(mouseDeviceId)
+ .buttonState(AMOTION_EVENT_BUTTON_PRIMARY)
+ .actionButton(AMOTION_EVENT_BUTTON_PRIMARY)
+ .pointer(PointerBuilder(0, ToolType::MOUSE).x(300).y(400))
+ .build());
window->consumeMotionEvent(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS));
// Try to send more touch events while the mouse is down. Since it's a continuation of an
// already canceled gesture, it should be ignored.
- mDispatcher->notifyMotion(&(
- args = MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(101).y(101))
- .pointer(PointerBuilder(1, ToolType::FINGER).x(121).y(121))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(101).y(101))
+ .pointer(PointerBuilder(1, ToolType::FINGER).x(121).y(121))
+ .build());
window->assertNoEvents();
}
@@ -3508,23 +3460,20 @@
const int32_t mouseDeviceId = 7;
const int32_t touchDeviceId = 4;
- NotifyMotionArgs args;
// Start hovering with the mouse
- mDispatcher->notifyMotion(
- &(args = MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE)
- .deviceId(mouseDeviceId)
- .pointer(PointerBuilder(0, ToolType::MOUSE).x(10).y(10))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE)
+ .deviceId(mouseDeviceId)
+ .pointer(PointerBuilder(0, ToolType::MOUSE).x(10).y(10))
+ .build());
window->consumeMotionEvent(
AllOf(WithMotionAction(ACTION_HOVER_ENTER), WithDeviceId(mouseDeviceId)));
// Touch goes down
- mDispatcher->notifyMotion(
- &(args = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
- .deviceId(touchDeviceId)
- .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50))
- .build()));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .deviceId(touchDeviceId)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50))
+ .build());
window->consumeMotionEvent(
AllOf(WithMotionAction(ACTION_HOVER_EXIT), WithDeviceId(mouseDeviceId)));
@@ -3550,15 +3499,15 @@
ADISPLAY_ID_DEFAULT, {{50, 50}});
motionArgs.xCursorPosition = 50;
motionArgs.yCursorPosition = 50;
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(motionArgs);
ASSERT_NO_FATAL_FAILURE(
window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER),
WithSource(AINPUT_SOURCE_MOUSE))));
// Tap on the window
- motionArgs = generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {{10, 10}});
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {{10, 10}}));
ASSERT_NO_FATAL_FAILURE(
window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT),
WithSource(AINPUT_SOURCE_MOUSE))));
@@ -3567,9 +3516,8 @@
window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
WithSource(AINPUT_SOURCE_TOUCHSCREEN))));
- motionArgs = generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {{10, 10}});
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, {{10, 10}}));
ASSERT_NO_FATAL_FAILURE(
window->consumeMotionEvent(AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
WithSource(AINPUT_SOURCE_TOUCHSCREEN))));
@@ -3661,16 +3609,14 @@
window->consumeFocusEvent(true);
- NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyKey(&keyArgs);
+ mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT));
// Window should receive key down event.
window->consumeKeyDown(ADISPLAY_ID_DEFAULT);
// When device reset happens, that key stream should be terminated with FLAG_CANCELED
// on the app side.
- NotifyDeviceResetArgs args(/*id=*/10, /*eventTime=*/20, DEVICE_ID);
- mDispatcher->notifyDeviceReset(&args);
+ mDispatcher->notifyDeviceReset({/*id=*/10, /*eventTime=*/20, DEVICE_ID});
window->consumeEvent(InputEventType::KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT,
AKEY_EVENT_FLAG_CANCELED);
}
@@ -3682,18 +3628,15 @@
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- NotifyMotionArgs motionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT));
// Window should receive motion down event.
window->consumeMotionDown(ADISPLAY_ID_DEFAULT);
// When device reset happens, that motion stream should be terminated with ACTION_CANCEL
// on the app side.
- NotifyDeviceResetArgs args(/*id=*/10, /*eventTime=*/20, DEVICE_ID);
- mDispatcher->notifyDeviceReset(&args);
+ mDispatcher->notifyDeviceReset({/*id=*/10, /*eventTime=*/20, DEVICE_ID});
window->consumeMotionEvent(
AllOf(WithMotionAction(ACTION_CANCEL), WithDisplayId(ADISPLAY_ID_DEFAULT)));
}
@@ -3709,11 +3652,11 @@
window->consumeFocusEvent(true);
- NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT);
+ const NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT);
const std::chrono::milliseconds interceptKeyTimeout = 50ms;
const nsecs_t injectTime = keyArgs.eventTime;
mFakePolicy->setInterceptKeyTimeout(interceptKeyTimeout);
- mDispatcher->notifyKey(&keyArgs);
+ mDispatcher->notifyKey(keyArgs);
// The dispatching time should be always greater than or equal to intercept key timeout.
window->consumeKeyDown(ADISPLAY_ID_DEFAULT);
ASSERT_TRUE((systemTime(SYSTEM_TIME_MONOTONIC) - injectTime) >=
@@ -3731,11 +3674,9 @@
window->consumeFocusEvent(true);
- NotifyKeyArgs keyDown = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT);
- NotifyKeyArgs keyUp = generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT);
mFakePolicy->setInterceptKeyTimeout(150ms);
- mDispatcher->notifyKey(&keyDown);
- mDispatcher->notifyKey(&keyUp);
+ mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT));
+ mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT));
// Window should receive key event immediately when same key up.
window->consumeKeyDown(ADISPLAY_ID_DEFAULT);
@@ -3764,10 +3705,9 @@
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {outsideWindow, window}}});
// Tap on first window.
- NotifyMotionArgs motionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {PointF{50, 50}});
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {PointF{50, 50}}));
window->consumeMotionDown();
// The coordinates of the tap in 'outsideWindow' are relative to its top left corner.
// Therefore, we should offset them by (100, 100) relative to the screen's top left corner.
@@ -3798,18 +3738,17 @@
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window, secondWindow, thirdWindow}}});
// First pointer lands outside all windows. `window` does not get ACTION_OUTSIDE.
- NotifyMotionArgs motionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {PointF{-10, -10}});
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {PointF{-10, -10}}));
window->assertNoEvents();
secondWindow->assertNoEvents();
// The second pointer lands inside `secondWindow`, which should receive a DOWN event.
// Now, `window` should get ACTION_OUTSIDE.
- motionArgs = generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
- {PointF{-10, -10}, PointF{105, 105}});
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT,
+ {PointF{-10, -10}, PointF{105, 105}}));
const std::map<int32_t, PointF> expectedPointers{{0, PointF{-10, -10}}, {1, PointF{105, 105}}};
window->consumeMotionEvent(
AllOf(WithMotionAction(ACTION_OUTSIDE), WithPointers(expectedPointers)));
@@ -3818,9 +3757,9 @@
// The third pointer lands inside `thirdWindow`, which should receive a DOWN event. There is
// no ACTION_OUTSIDE sent to `window` because one has already been sent for this gesture.
- motionArgs = generateMotionArgs(POINTER_2_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
- {PointF{-10, -10}, PointF{105, 105}, PointF{205, 205}});
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(
+ generateMotionArgs(POINTER_2_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {PointF{-10, -10}, PointF{105, 105}, PointF{205, 205}}));
window->assertNoEvents();
secondWindow->consumeMotionMove();
thirdWindow->consumeMotionDown();
@@ -3837,10 +3776,10 @@
window->consumeFocusEvent(true);
- NotifyKeyArgs keyDown = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT);
- NotifyKeyArgs keyUp = generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyKey(&keyDown);
- mDispatcher->notifyKey(&keyUp);
+ const NotifyKeyArgs keyDown = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT);
+ const NotifyKeyArgs keyUp = generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT);
+ mDispatcher->notifyKey(keyDown);
+ mDispatcher->notifyKey(keyUp);
window->consumeKeyDown(ADISPLAY_ID_DEFAULT);
window->consumeKeyUp(ADISPLAY_ID_DEFAULT);
@@ -3850,8 +3789,8 @@
window->consumeFocusEvent(false);
- mDispatcher->notifyKey(&keyDown);
- mDispatcher->notifyKey(&keyUp);
+ mDispatcher->notifyKey(keyDown);
+ mDispatcher->notifyKey(keyUp);
window->assertNoEvents();
}
@@ -3959,10 +3898,9 @@
// Send down to the first window. The point is represented in the display space. The point is
// selected so that if the hit test was performed with the point and the bounds being in
// different coordinate spaces, the event would end up in the incorrect window.
- NotifyMotionArgs downMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {PointF{75, 55}});
- mDispatcher->notifyMotion(&downMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {PointF{75, 55}}));
firstWindow->consumeMotionDown();
secondWindow->assertNoEvents();
@@ -4013,10 +3951,9 @@
auto [firstWindow, secondWindow] = setupScaledDisplayScenario();
// Send down to the second window.
- NotifyMotionArgs downMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {PointF{150, 220}});
- mDispatcher->notifyMotion(&downMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {PointF{150, 220}}));
firstWindow->assertNoEvents();
const MotionEvent* event = secondWindow->consumeMotion();
@@ -4071,14 +4008,14 @@
for (const auto pointInsideWindow : insidePoints) {
const vec2 p = displayTransform.inverse().transform(pointInsideWindow);
const PointF pointInDisplaySpace{p.x, p.y};
- const auto down = generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {pointInDisplaySpace});
- mDispatcher->notifyMotion(&down);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {pointInDisplaySpace}));
window->consumeMotionDown();
- const auto up = generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {pointInDisplaySpace});
- mDispatcher->notifyMotion(&up);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {pointInDisplaySpace}));
window->consumeMotionUp();
}
@@ -4088,13 +4025,13 @@
for (const auto pointOutsideWindow : outsidePoints) {
const vec2 p = displayTransform.inverse().transform(pointOutsideWindow);
const PointF pointInDisplaySpace{p.x, p.y};
- const auto down = generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {pointInDisplaySpace});
- mDispatcher->notifyMotion(&down);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {pointInDisplaySpace}));
- const auto up = generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {pointInDisplaySpace});
- mDispatcher->notifyMotion(&up);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {pointInDisplaySpace}));
}
window->assertNoEvents();
}
@@ -4132,10 +4069,8 @@
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {firstWindow, secondWindow, wallpaper}}});
// Send down to the first window
- NotifyMotionArgs downMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&downMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT));
// Only the first window should get the down event
firstWindow->consumeMotionDown();
@@ -4152,10 +4087,8 @@
wallpaper->consumeMotionCancel(ADISPLAY_ID_DEFAULT, expectedWallpaperFlags);
// Send up event to the second window
- NotifyMotionArgs upMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&upMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT));
// The first window gets no events and the second gets up
firstWindow->assertNoEvents();
secondWindow->consumeMotionUp();
@@ -4191,10 +4124,8 @@
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {spyWindow, firstWindow, secondWindow}}});
// Send down to the first window
- NotifyMotionArgs downMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&downMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT));
// Only the first window and spy should get the down event
spyWindow->consumeMotionDown();
firstWindow->consumeMotionDown();
@@ -4209,10 +4140,8 @@
secondWindow->consumeMotionDown();
// Send up event to the second window
- NotifyMotionArgs upMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&upMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT));
// The first window gets no events and the second+spy get up
firstWindow->assertNoEvents();
spyWindow->consumeMotionUp();
@@ -4238,19 +4167,16 @@
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {firstWindow, secondWindow}}});
// Send down to the first window
- NotifyMotionArgs downMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {touchPoint});
- mDispatcher->notifyMotion(&downMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {touchPoint}));
// Only the first window should get the down event
firstWindow->consumeMotionDown();
secondWindow->assertNoEvents();
// Send pointer down to the first window
- NotifyMotionArgs pointerDownMotionArgs =
- generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
- {touchPoint, touchPoint});
- mDispatcher->notifyMotion(&pointerDownMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, {touchPoint, touchPoint}));
// Only the first window should get the pointer down event
firstWindow->consumeMotionPointerDown(1);
secondWindow->assertNoEvents();
@@ -4265,19 +4191,15 @@
secondWindow->consumeMotionPointerDown(1);
// Send pointer up to the second window
- NotifyMotionArgs pointerUpMotionArgs =
- generateMotionArgs(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
- {touchPoint, touchPoint});
- mDispatcher->notifyMotion(&pointerUpMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, {touchPoint, touchPoint}));
// The first window gets nothing and the second gets pointer up
firstWindow->assertNoEvents();
secondWindow->consumeMotionPointerUp(1);
// Send up event to the second window
- NotifyMotionArgs upMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&upMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT));
// The first window gets nothing and the second gets up
firstWindow->assertNoEvents();
secondWindow->consumeMotionUp();
@@ -4308,10 +4230,8 @@
{{ADISPLAY_ID_DEFAULT, {firstWindow, wallpaper1, secondWindow, wallpaper2}}});
// Send down to the first window
- NotifyMotionArgs downMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&downMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT));
// Only the first window should get the down event
firstWindow->consumeMotionDown();
@@ -4331,10 +4251,8 @@
wallpaper2->consumeMotionDown(ADISPLAY_ID_DEFAULT, expectedWallpaperFlags);
// Send up event to the second window
- NotifyMotionArgs upMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&upMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT));
// The first window gets no events and the second gets up
firstWindow->assertNoEvents();
secondWindow->consumeMotionUp();
@@ -4378,19 +4296,17 @@
PointF pointInSecond = {300, 600};
// Send down to the first window
- NotifyMotionArgs firstDownMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {pointInFirst});
- mDispatcher->notifyMotion(&firstDownMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {pointInFirst}));
// Only the first window should get the down event
firstWindow->consumeMotionDown();
secondWindow->assertNoEvents();
// Send down to the second window
- NotifyMotionArgs secondDownMotionArgs =
- generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
- {pointInFirst, pointInSecond});
- mDispatcher->notifyMotion(&secondDownMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT,
+ {pointInFirst, pointInSecond}));
// The first window gets a move and the second a down
firstWindow->consumeMotionMove();
secondWindow->consumeMotionDown();
@@ -4402,19 +4318,16 @@
secondWindow->consumeMotionPointerDown(1);
// Send pointer up to the second window
- NotifyMotionArgs pointerUpMotionArgs =
- generateMotionArgs(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
- {pointInFirst, pointInSecond});
- mDispatcher->notifyMotion(&pointerUpMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT,
+ {pointInFirst, pointInSecond}));
// The first window gets nothing and the second gets pointer up
firstWindow->assertNoEvents();
secondWindow->consumeMotionPointerUp(1);
// Send up event to the second window
- NotifyMotionArgs upMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&upMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT));
// The first window gets nothing and the second gets up
firstWindow->assertNoEvents();
secondWindow->consumeMotionUp();
@@ -4444,19 +4357,17 @@
PointF pointInSecond = {300, 600};
// Send down to the first window
- NotifyMotionArgs firstDownMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {pointInFirst});
- mDispatcher->notifyMotion(&firstDownMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {pointInFirst}));
// Only the first window should get the down event
firstWindow->consumeMotionDown();
secondWindow->assertNoEvents();
// Send down to the second window
- NotifyMotionArgs secondDownMotionArgs =
- generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
- {pointInFirst, pointInSecond});
- mDispatcher->notifyMotion(&secondDownMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT,
+ {pointInFirst, pointInSecond}));
// The first window gets a move and the second a down
firstWindow->consumeMotionMove();
secondWindow->consumeMotionDown();
@@ -4471,19 +4382,16 @@
// The rest of the dispatch should proceed as normal
// Send pointer up to the second window
- NotifyMotionArgs pointerUpMotionArgs =
- generateMotionArgs(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
- {pointInFirst, pointInSecond});
- mDispatcher->notifyMotion(&pointerUpMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT,
+ {pointInFirst, pointInSecond}));
// The first window gets MOVE and the second gets pointer up
firstWindow->consumeMotionMove();
secondWindow->consumeMotionUp();
// Send up event to the first window
- NotifyMotionArgs upMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&upMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT));
// The first window gets nothing and the second gets up
firstWindow->consumeMotionUp();
secondWindow->assertNoEvents();
@@ -4618,8 +4526,7 @@
window->consumeFocusEvent(true);
- NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyKey(&keyArgs);
+ mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT));
// Window should receive key down event.
window->consumeKeyDown(ADISPLAY_ID_DEFAULT);
@@ -4632,8 +4539,7 @@
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyKey(&keyArgs);
+ mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT));
mDispatcher->waitForIdle();
window->assertNoEvents();
@@ -4648,13 +4554,10 @@
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
// Send key
- NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyKey(&keyArgs);
+ mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT));
// Send motion
- NotifyMotionArgs motionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT));
// Window should receive only the motion event
window->consumeMotionDown(ADISPLAY_ID_DEFAULT);
@@ -4681,19 +4584,17 @@
PointF pointInSecond = {300, 600};
// Send down to the first window
- NotifyMotionArgs firstDownMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {pointInFirst});
- mDispatcher->notifyMotion(&firstDownMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {pointInFirst}));
// Only the first window should get the down event
firstWindow->consumeMotionDown();
secondWindow->assertNoEvents();
// Send down to the second window
- NotifyMotionArgs secondDownMotionArgs =
- generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
- {pointInFirst, pointInSecond});
- mDispatcher->notifyMotion(&secondDownMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT,
+ {pointInFirst, pointInSecond}));
// The first window gets a move and the second a down
firstWindow->consumeMotionMove();
secondWindow->consumeMotionDown();
@@ -4703,16 +4604,14 @@
generateMotionArgs(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
{pointInFirst, pointInSecond});
pointerUpMotionArgs.flags |= AMOTION_EVENT_FLAG_CANCELED;
- mDispatcher->notifyMotion(&pointerUpMotionArgs);
+ mDispatcher->notifyMotion(pointerUpMotionArgs);
// The first window gets move and the second gets cancel.
firstWindow->consumeMotionMove(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_CANCELED);
secondWindow->consumeMotionCancel(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_CANCELED);
// Send up event.
- NotifyMotionArgs upMotionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&upMotionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT));
// The first window gets up and the second gets nothing.
firstWindow->consumeMotionUp();
secondWindow->assertNoEvents();
@@ -4934,7 +4833,7 @@
generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(motionArgs);
// Window should receive motion down event.
window->consumeMotionDown(ADISPLAY_ID_DEFAULT);
@@ -4944,7 +4843,7 @@
motionArgs.pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X,
motionArgs.pointerCoords[0].getX() - 10);
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(motionArgs);
window->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_MOVE, ADISPLAY_ID_DEFAULT,
/*expectedFlags=*/0);
}
@@ -5013,8 +4912,8 @@
window->consumeFocusEvent(/*hasFocus=*/true, /*inTouchMode=*/true);
- NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN);
- mDispatcher->notifyKey(&keyArgs);
+ const NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN);
+ mDispatcher->notifyKey(keyArgs);
InputEvent* event = window->consume();
ASSERT_NE(event, nullptr);
@@ -5055,10 +4954,10 @@
mDispatcher->onWindowInfosChanged({*window->getInfo()}, {displayInfo});
- NotifyMotionArgs motionArgs =
+ const NotifyMotionArgs motionArgs =
generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(motionArgs);
InputEvent* event = window->consume();
ASSERT_NE(event, nullptr);
@@ -5355,17 +5254,17 @@
{{ADISPLAY_ID_DEFAULT, {slipperyExitWindow, slipperyEnterWindow}}});
// Use notifyMotion instead of injecting to avoid dealing with injection permissions
- NotifyMotionArgs args = generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {{50, 50}});
- mDispatcher->notifyMotion(&args);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {{50, 50}}));
slipperyExitWindow->consumeMotionDown();
slipperyExitWindow->setFrame(Rect(70, 70, 100, 100));
mDispatcher->setInputWindows(
{{ADISPLAY_ID_DEFAULT, {slipperyExitWindow, slipperyEnterWindow}}});
- args = generateMotionArgs(AMOTION_EVENT_ACTION_MOVE, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {{51, 51}});
- mDispatcher->notifyMotion(&args);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_MOVE,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {{51, 51}}));
slipperyExitWindow->consumeMotionCancel();
@@ -5405,7 +5304,7 @@
NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT);
keyArgs.deviceId = deviceId;
keyArgs.policyFlags |= POLICY_FLAG_TRUSTED; // Otherwise it won't generate repeat event
- mDispatcher->notifyKey(&keyArgs);
+ mDispatcher->notifyKey(keyArgs);
// Window should receive key down event.
mWindow->consumeKeyDown(ADISPLAY_ID_DEFAULT);
@@ -5428,7 +5327,7 @@
NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT);
keyArgs.deviceId = deviceId;
keyArgs.policyFlags |= POLICY_FLAG_TRUSTED; // Unless it won't generate repeat event
- mDispatcher->notifyKey(&keyArgs);
+ mDispatcher->notifyKey(keyArgs);
// Window should receive key down event.
mWindow->consumeEvent(InputEventType::KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT,
@@ -5491,8 +5390,7 @@
TEST_F(InputDispatcherKeyRepeatTest, FocusedWindow_StopsKeyRepeatAfterDisableInputDevice) {
sendAndConsumeKeyDown(DEVICE_ID);
expectKeyRepeatOnce(/*repeatCount=*/1);
- NotifyDeviceResetArgs args(/*id=*/10, /*eventTime=*/20, DEVICE_ID);
- mDispatcher->notifyDeviceReset(&args);
+ mDispatcher->notifyDeviceReset({/*id=*/10, /*eventTime=*/20, DEVICE_ID});
mWindow->consumeKeyUp(ADISPLAY_ID_DEFAULT,
AKEY_EVENT_FLAG_CANCELED | AKEY_EVENT_FLAG_LONG_PRESS);
mWindow->assertNoEvents();
@@ -5744,10 +5642,10 @@
motionArgs =
generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, displayId);
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(motionArgs);
motionArgs =
generateMotionArgs(AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, displayId);
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(motionArgs);
ASSERT_TRUE(mDispatcher->waitForIdle());
if (expectToBeFiltered) {
const auto xy = transform.transform(motionArgs.pointerCoords->getXYValue());
@@ -5761,9 +5659,9 @@
NotifyKeyArgs keyArgs;
keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN);
- mDispatcher->notifyKey(&keyArgs);
+ mDispatcher->notifyKey(keyArgs);
keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_UP);
- mDispatcher->notifyKey(&keyArgs);
+ mDispatcher->notifyKey(keyArgs);
ASSERT_TRUE(mDispatcher->waitForIdle());
if (expectToBeFiltered) {
@@ -6113,9 +6011,8 @@
void touchAndAssertPositions(int32_t action, const std::vector<PointF>& touchedPoints,
std::vector<PointF> expectedPoints) {
- NotifyMotionArgs motionArgs = generateMotionArgs(action, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, touchedPoints);
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(action, AINPUT_SOURCE_TOUCHSCREEN,
+ ADISPLAY_ID_DEFAULT, touchedPoints));
// Always consume from window1 since it's the window that has the InputReceiver
consumeMotionEvent(mWindow1, action, expectedPoints);
@@ -6988,17 +6885,16 @@
// The other window should not be affected by that.
TEST_F(InputDispatcherMultiWindowAnr, SplitTouch_SingleWindowAnr) {
// Touch Window 1
- NotifyMotionArgs motionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {FOCUSED_WINDOW_LOCATION});
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {FOCUSED_WINDOW_LOCATION}));
mUnfocusedWindow->consumeEvent(InputEventType::MOTION, AMOTION_EVENT_ACTION_OUTSIDE,
ADISPLAY_ID_DEFAULT, /*flags=*/0);
// Touch Window 2
- motionArgs = generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
- {FOCUSED_WINDOW_LOCATION, UNFOCUSED_WINDOW_LOCATION});
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(
+ generateMotionArgs(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {FOCUSED_WINDOW_LOCATION, UNFOCUSED_WINDOW_LOCATION}));
const std::chrono::duration timeout =
mFocusedWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT);
@@ -7070,10 +6966,9 @@
std::this_thread::sleep_for(10ms);
// Touch unfocused window. This should force the pending key to get dropped.
- NotifyMotionArgs motionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {UNFOCUSED_WINDOW_LOCATION});
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {UNFOCUSED_WINDOW_LOCATION}));
// We do not consume the motion right away, because that would require dispatcher to first
// process (== drop) the key event, and by that time, ANR will be raised.
@@ -7128,10 +7023,9 @@
TEST_F(InputDispatcherMultiWindowOcclusionTests, NoInputChannelFeature_DropsTouches) {
PointF touchedPoint = {10, 10};
- NotifyMotionArgs motionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {touchedPoint});
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {touchedPoint}));
mNoInputWindow->assertNoEvents();
// Even though the window 'mNoInputWindow' positioned above 'mBottomWindow' does not have
@@ -7156,10 +7050,9 @@
PointF touchedPoint = {10, 10};
- NotifyMotionArgs motionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, {touchedPoint});
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ {touchedPoint}));
mNoInputWindow->assertNoEvents();
mBottomWindow->assertNoEvents();
@@ -7332,8 +7225,7 @@
}
void notifyPointerCaptureChanged(const PointerCaptureRequest& request) {
- const NotifyPointerCaptureChangedArgs args = generatePointerCaptureChangedArgs(request);
- mDispatcher->notifyPointerCaptureChanged(&args);
+ mDispatcher->notifyPointerCaptureChanged(generatePointerCaptureChangedArgs(request));
}
PointerCaptureRequest requestAndVerifyPointerCapture(const sp<FakeWindowHandle>& window,
@@ -7509,10 +7401,9 @@
}
void touch(const std::vector<PointF>& points = {PointF{100, 200}}) {
- NotifyMotionArgs args =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT, points);
- mDispatcher->notifyMotion(&args);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT,
+ points));
}
};
@@ -8322,27 +8213,22 @@
window->consumeFocusEvent(/*hasFocus=*/true, /*inTouchMode=*/true);
// With the flag set, window should not get any input
- NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyKey(&keyArgs);
+ mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT));
window->assertNoEvents();
- NotifyMotionArgs motionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT));
window->assertNoEvents();
// With the flag cleared, the window should get input
window->setDropInput(false);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}});
- keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyKey(&keyArgs);
+ mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT));
window->consumeKeyUp(ADISPLAY_ID_DEFAULT);
- motionArgs = generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT));
window->consumeMotionDown(ADISPLAY_ID_DEFAULT);
window->assertNoEvents();
}
@@ -8368,27 +8254,22 @@
window->consumeFocusEvent(/*hasFocus=*/true, /*inTouchMode=*/true);
// With the flag set, window should not get any input
- NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyKey(&keyArgs);
+ mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT));
window->assertNoEvents();
- NotifyMotionArgs motionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT));
window->assertNoEvents();
// With the flag cleared, the window should get input
window->setDropInputIfObscured(false);
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {obscuringWindow, window}}});
- keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyKey(&keyArgs);
+ mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT));
window->consumeKeyUp(ADISPLAY_ID_DEFAULT);
- motionArgs = generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT));
window->consumeMotionDown(ADISPLAY_ID_DEFAULT, AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED);
window->assertNoEvents();
}
@@ -8414,26 +8295,21 @@
window->consumeFocusEvent(/*hasFocus=*/true, /*inTouchMode=*/true);
// With the flag set, window should not get any input
- NotifyKeyArgs keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyKey(&keyArgs);
+ mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_DOWN, ADISPLAY_ID_DEFAULT));
window->assertNoEvents();
- NotifyMotionArgs motionArgs =
- generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT));
window->assertNoEvents();
// When the window is no longer obscured because it went on top, it should get input
mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window, obscuringWindow}}});
- keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyKey(&keyArgs);
+ mDispatcher->notifyKey(generateKeyArgs(AKEY_EVENT_ACTION_UP, ADISPLAY_ID_DEFAULT));
window->consumeKeyUp(ADISPLAY_ID_DEFAULT);
- motionArgs = generateMotionArgs(AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN,
- ADISPLAY_ID_DEFAULT);
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(generateMotionArgs(AMOTION_EVENT_ACTION_DOWN,
+ AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT));
window->consumeMotionDown(ADISPLAY_ID_DEFAULT);
window->assertNoEvents();
}
@@ -9167,10 +9043,9 @@
}
void sendFingerEvent(int32_t action) {
- NotifyMotionArgs motionArgs =
+ mDispatcher->notifyMotion(
generateMotionArgs(action, AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS,
- ADISPLAY_ID_DEFAULT, {PointF{20, 20}});
- mDispatcher->notifyMotion(&motionArgs);
+ ADISPLAY_ID_DEFAULT, {PointF{20, 20}}));
}
void sendStylusEvent(int32_t action) {
@@ -9178,7 +9053,7 @@
generateMotionArgs(action, AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS,
ADISPLAY_ID_DEFAULT, {PointF{30, 40}});
motionArgs.pointerProperties[0].toolType = ToolType::STYLUS;
- mDispatcher->notifyMotion(&motionArgs);
+ mDispatcher->notifyMotion(motionArgs);
}
};
diff --git a/services/inputflinger/tests/InputProcessor_test.cpp b/services/inputflinger/tests/InputProcessor_test.cpp
index 0ffdef9..3b7cbfa 100644
--- a/services/inputflinger/tests/InputProcessor_test.cpp
+++ b/services/inputflinger/tests/InputProcessor_test.cpp
@@ -72,7 +72,7 @@
// Create a basic configuration change and send to processor
NotifyConfigurationChangedArgs args(/*sequenceNum=*/1, /*eventTime=*/2);
- mProcessor->notifyConfigurationChanged(&args);
+ mProcessor->notifyConfigurationChanged(args);
NotifyConfigurationChangedArgs outArgs;
ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifyConfigurationChangedWasCalled(&outArgs));
ASSERT_EQ(args, outArgs);
@@ -85,10 +85,8 @@
AKEY_EVENT_ACTION_DOWN, /*flags=*/4, AKEYCODE_HOME, /*scanCode=*/5,
AMETA_NONE, /*downTime=*/6);
- mProcessor->notifyKey(&args);
- NotifyKeyArgs outArgs;
- ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifyKeyWasCalled(&outArgs));
- ASSERT_EQ(args, outArgs);
+ mProcessor->notifyKey(args);
+ ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifyKeyWasCalled(testing::Eq(args)));
}
/**
@@ -97,10 +95,8 @@
*/
TEST_F(InputProcessorTest, SendToNextStage_NotifyMotionArgs) {
NotifyMotionArgs motionArgs = generateBasicMotionArgs();
- mProcessor->notifyMotion(&motionArgs);
- NotifyMotionArgs args;
- ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(motionArgs, args);
+ mProcessor->notifyMotion(motionArgs);
+ ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifyMotionWasCalled(testing::Eq(motionArgs)));
}
/**
@@ -111,7 +107,7 @@
NotifySwitchArgs args(/*sequenceNum=*/1, /*eventTime=*/2, /*policyFlags=*/3,
/*switchValues=*/4, /*switchMask=*/5);
- mProcessor->notifySwitch(&args);
+ mProcessor->notifySwitch(args);
NotifySwitchArgs outArgs;
ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifySwitchWasCalled(&outArgs));
ASSERT_EQ(args, outArgs);
@@ -124,7 +120,7 @@
TEST_F(InputProcessorTest, SendToNextStage_NotifyDeviceResetArgs) {
NotifyDeviceResetArgs args(/*sequenceNum=*/1, /*eventTime=*/2, /*deviceId=*/3);
- mProcessor->notifyDeviceReset(&args);
+ mProcessor->notifyDeviceReset(args);
NotifyDeviceResetArgs outArgs;
ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifyDeviceResetWasCalled(&outArgs));
ASSERT_EQ(args, outArgs);
diff --git a/services/inputflinger/tests/TestInputListener.cpp b/services/inputflinger/tests/TestInputListener.cpp
index ac1dc05..fc917dd 100644
--- a/services/inputflinger/tests/TestInputListener.cpp
+++ b/services/inputflinger/tests/TestInputListener.cpp
@@ -168,47 +168,47 @@
}
template <class NotifyArgsType>
-void TestInputListener::addToQueue(const NotifyArgsType* args) {
+void TestInputListener::addToQueue(const NotifyArgsType& args) {
std::scoped_lock<std::mutex> lock(mLock);
std::vector<NotifyArgsType>& queue = std::get<std::vector<NotifyArgsType>>(mQueues);
- queue.push_back(*args);
+ queue.push_back(args);
mCondition.notify_all();
}
void TestInputListener::notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) {
- addToQueue<NotifyInputDevicesChangedArgs>(&args);
+ addToQueue<NotifyInputDevicesChangedArgs>(args);
}
-void TestInputListener::notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) {
+void TestInputListener::notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) {
addToQueue<NotifyConfigurationChangedArgs>(args);
}
-void TestInputListener::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
+void TestInputListener::notifyDeviceReset(const NotifyDeviceResetArgs& args) {
addToQueue<NotifyDeviceResetArgs>(args);
}
-void TestInputListener::notifyKey(const NotifyKeyArgs* args) {
+void TestInputListener::notifyKey(const NotifyKeyArgs& args) {
addToQueue<NotifyKeyArgs>(args);
}
-void TestInputListener::notifyMotion(const NotifyMotionArgs* args) {
+void TestInputListener::notifyMotion(const NotifyMotionArgs& args) {
addToQueue<NotifyMotionArgs>(args);
}
-void TestInputListener::notifySwitch(const NotifySwitchArgs* args) {
+void TestInputListener::notifySwitch(const NotifySwitchArgs& args) {
addToQueue<NotifySwitchArgs>(args);
}
-void TestInputListener::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) {
+void TestInputListener::notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) {
addToQueue<NotifyPointerCaptureChangedArgs>(args);
}
-void TestInputListener::notifySensor(const NotifySensorArgs* args) {
+void TestInputListener::notifySensor(const NotifySensorArgs& args) {
addToQueue<NotifySensorArgs>(args);
}
-void TestInputListener::notifyVibratorState(const NotifyVibratorStateArgs* args) {
+void TestInputListener::notifyVibratorState(const NotifyVibratorStateArgs& args) {
addToQueue<NotifyVibratorStateArgs>(args);
}
diff --git a/services/inputflinger/tests/TestInputListener.h b/services/inputflinger/tests/TestInputListener.h
index da2cab3..deb6048 100644
--- a/services/inputflinger/tests/TestInputListener.h
+++ b/services/inputflinger/tests/TestInputListener.h
@@ -77,25 +77,25 @@
void assertNotCalled(std::string message, std::optional<TimePoint> timeout = {});
template <class NotifyArgsType>
- void addToQueue(const NotifyArgsType* args);
+ void addToQueue(const NotifyArgsType& args);
virtual void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override;
- virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override;
+ virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) override;
- virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) override;
+ virtual void notifyDeviceReset(const NotifyDeviceResetArgs& args) override;
- virtual void notifyKey(const NotifyKeyArgs* args) override;
+ virtual void notifyKey(const NotifyKeyArgs& args) override;
- virtual void notifyMotion(const NotifyMotionArgs* args) override;
+ virtual void notifyMotion(const NotifyMotionArgs& args) override;
- virtual void notifySwitch(const NotifySwitchArgs* args) override;
+ virtual void notifySwitch(const NotifySwitchArgs& args) override;
- virtual void notifySensor(const NotifySensorArgs* args) override;
+ virtual void notifySensor(const NotifySensorArgs& args) override;
- virtual void notifyVibratorState(const NotifyVibratorStateArgs* args) override;
+ virtual void notifyVibratorState(const NotifyVibratorStateArgs& args) override;
- virtual void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) override;
+ virtual void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) override;
std::mutex mLock;
std::condition_variable mCondition;
diff --git a/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp b/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp
index be731b1..1fff2c7 100644
--- a/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp
+++ b/services/inputflinger/tests/UnwantedInteractionBlocker_test.cpp
@@ -421,7 +421,7 @@
// Create a basic configuration change and send to blocker
NotifyConfigurationChangedArgs args(/*sequenceNum=*/1, /*eventTime=*/2);
- mBlocker->notifyConfigurationChanged(&args);
+ mBlocker->notifyConfigurationChanged(args);
NotifyConfigurationChangedArgs outArgs;
ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifyConfigurationChangedWasCalled(&outArgs));
ASSERT_EQ(args, outArgs);
@@ -438,10 +438,8 @@
AKEY_EVENT_ACTION_DOWN, /*flags=*/4, AKEYCODE_HOME, /*scanCode=*/5,
AMETA_NONE, /*downTime=*/6);
- mBlocker->notifyKey(&args);
- NotifyKeyArgs outArgs;
- ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifyKeyWasCalled(&outArgs));
- ASSERT_EQ(args, outArgs);
+ mBlocker->notifyKey(args);
+ ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifyKeyWasCalled(testing::Eq(args)));
}
/**
@@ -452,10 +450,8 @@
TEST_F(UnwantedInteractionBlockerTest, DownEventIsPassedToNextListener) {
NotifyMotionArgs motionArgs =
generateMotionArgs(/*downTime=*/0, /*eventTime=*/0, DOWN, {{1, 2, 3}});
- mBlocker->notifyMotion(&motionArgs);
- NotifyMotionArgs args;
- ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifyMotionWasCalled(&args));
- ASSERT_EQ(motionArgs, args);
+ mBlocker->notifyMotion(motionArgs);
+ ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifyMotionWasCalled(testing::Eq(motionArgs)));
}
/**
@@ -466,7 +462,7 @@
NotifySwitchArgs args(/*sequenceNum=*/1, /*eventTime=*/2, /*policyFlags=*/3,
/*switchValues=*/4, /*switchMask=*/5);
- mBlocker->notifySwitch(&args);
+ mBlocker->notifySwitch(args);
NotifySwitchArgs outArgs;
ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifySwitchWasCalled(&outArgs));
ASSERT_EQ(args, outArgs);
@@ -479,7 +475,7 @@
TEST_F(UnwantedInteractionBlockerTest, DeviceResetIsPassedToNextListener) {
NotifyDeviceResetArgs args(/*sequenceNum=*/1, /*eventTime=*/2, DEVICE_ID);
- mBlocker->notifyDeviceReset(&args);
+ mBlocker->notifyDeviceReset(args);
NotifyDeviceResetArgs outArgs;
ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifyDeviceResetWasCalled(&outArgs));
ASSERT_EQ(args, outArgs);
@@ -491,17 +487,12 @@
* a crash due to inconsistent event stream could have occurred.
*/
TEST_F(UnwantedInteractionBlockerTest, NoCrashWhenResetHappens) {
- NotifyMotionArgs args;
mBlocker->notifyInputDevicesChanged({/*id=*/0, {generateTestDeviceInfo()}});
- mBlocker->notifyMotion(
- &(args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, DOWN, {{1, 2, 3}})));
- mBlocker->notifyMotion(
- &(args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/2, MOVE, {{4, 5, 6}})));
- NotifyDeviceResetArgs resetArgs(/*sequenceNum=*/1, /*eventTime=*/3, DEVICE_ID);
- mBlocker->notifyDeviceReset(&resetArgs);
+ mBlocker->notifyMotion(generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, DOWN, {{1, 2, 3}}));
+ mBlocker->notifyMotion(generateMotionArgs(/*downTime=*/0, /*eventTime=*/2, MOVE, {{4, 5, 6}}));
+ mBlocker->notifyDeviceReset({/*sequenceNum=*/1, /*eventTime=*/3, DEVICE_ID});
// Start a new gesture with a DOWN event, even though the previous event stream was incomplete.
- mBlocker->notifyMotion(
- &(args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/4, DOWN, {{7, 8, 9}})));
+ mBlocker->notifyMotion(generateMotionArgs(/*downTime=*/0, /*eventTime=*/4, DOWN, {{7, 8, 9}}));
}
TEST_F(UnwantedInteractionBlockerTest, NoCrashWhenStylusSourceWithFingerToolIsReceived) {
@@ -509,7 +500,7 @@
NotifyMotionArgs args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, DOWN, {{1, 2, 3}});
args.pointerProperties[0].toolType = ToolType::FINGER;
args.source = AINPUT_SOURCE_STYLUS;
- mBlocker->notifyMotion(&args);
+ mBlocker->notifyMotion(args);
}
/**
@@ -517,48 +508,41 @@
* UnwantedInteractionBlocker has not changed, there should not be a reset.
*/
TEST_F(UnwantedInteractionBlockerTest, NoResetIfDeviceInfoChanges) {
- NotifyMotionArgs args;
mBlocker->notifyInputDevicesChanged({/*id=*/0, {generateTestDeviceInfo()}});
- mBlocker->notifyMotion(
- &(args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, DOWN, {{1, 2, 3}})));
- mBlocker->notifyMotion(
- &(args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/2, MOVE, {{4, 5, 6}})));
+ mBlocker->notifyMotion(generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, DOWN, {{1, 2, 3}}));
+ mBlocker->notifyMotion(generateMotionArgs(/*downTime=*/0, /*eventTime=*/2, MOVE, {{4, 5, 6}}));
// Now pretend the device changed, even though nothing is different for DEVICE_ID in practice.
mBlocker->notifyInputDevicesChanged({/*id=*/0, {generateTestDeviceInfo()}});
// The MOVE event continues the gesture that started before 'devices changed', so it should not
// cause a crash.
- mBlocker->notifyMotion(
- &(args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/4, MOVE, {{7, 8, 9}})));
+ mBlocker->notifyMotion(generateMotionArgs(/*downTime=*/0, /*eventTime=*/4, MOVE, {{7, 8, 9}}));
}
/**
* Send a touch event, and then a stylus event. Make sure that both work.
*/
TEST_F(UnwantedInteractionBlockerTest, StylusAfterTouchWorks) {
- NotifyMotionArgs args;
mBlocker->notifyInputDevicesChanged({/*id=*/0, {generateTestDeviceInfo()}});
- args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/0, DOWN, {{1, 2, 3}});
- mBlocker->notifyMotion(&args);
- args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, MOVE, {{4, 5, 6}});
- mBlocker->notifyMotion(&args);
- args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/2, UP, {{4, 5, 6}});
- mBlocker->notifyMotion(&args);
+ mBlocker->notifyMotion(generateMotionArgs(/*downTime=*/0, /*eventTime=*/0, DOWN, {{1, 2, 3}}));
+ mBlocker->notifyMotion(generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, MOVE, {{4, 5, 6}}));
+ mBlocker->notifyMotion(generateMotionArgs(/*downTime=*/0, /*eventTime=*/2, UP, {{4, 5, 6}}));
// Now touch down stylus
+ NotifyMotionArgs args;
args = generateMotionArgs(/*downTime=*/3, /*eventTime=*/3, DOWN, {{10, 20, 30}});
args.pointerProperties[0].toolType = ToolType::STYLUS;
args.source |= AINPUT_SOURCE_STYLUS;
- mBlocker->notifyMotion(&args);
+ mBlocker->notifyMotion(args);
args = generateMotionArgs(/*downTime=*/3, /*eventTime=*/4, MOVE, {{40, 50, 60}});
args.pointerProperties[0].toolType = ToolType::STYLUS;
args.source |= AINPUT_SOURCE_STYLUS;
- mBlocker->notifyMotion(&args);
+ mBlocker->notifyMotion(args);
args = generateMotionArgs(/*downTime=*/3, /*eventTime=*/5, UP, {{40, 50, 60}});
args.pointerProperties[0].toolType = ToolType::STYLUS;
args.source |= AINPUT_SOURCE_STYLUS;
- mBlocker->notifyMotion(&args);
+ mBlocker->notifyMotion(args);
}
/**
@@ -569,16 +553,13 @@
*/
TEST_F(UnwantedInteractionBlockerTest, DumpCanBeAccessedOnAnotherThread) {
mBlocker->notifyInputDevicesChanged({/*id=*/0, {generateTestDeviceInfo()}});
- NotifyMotionArgs args1 = generateMotionArgs(/*downTime=*/0, /*eventTime=*/0, DOWN, {{1, 2, 3}});
- mBlocker->notifyMotion(&args1);
+ mBlocker->notifyMotion(generateMotionArgs(/*downTime=*/0, /*eventTime=*/0, DOWN, {{1, 2, 3}}));
std::thread dumpThread([this]() {
std::string dump;
mBlocker->dump(dump);
});
- NotifyMotionArgs args2 = generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, MOVE, {{4, 5, 6}});
- mBlocker->notifyMotion(&args2);
- NotifyMotionArgs args3 = generateMotionArgs(/*downTime=*/0, /*eventTime=*/2, UP, {{4, 5, 6}});
- mBlocker->notifyMotion(&args3);
+ mBlocker->notifyMotion(generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, MOVE, {{4, 5, 6}}));
+ mBlocker->notifyMotion(generateMotionArgs(/*downTime=*/0, /*eventTime=*/2, UP, {{4, 5, 6}}));
dumpThread.join();
}
@@ -589,20 +570,17 @@
TEST_F(UnwantedInteractionBlockerTest, HeuristicFilterWorks) {
mBlocker->notifyInputDevicesChanged({/*id=*/0, {generateTestDeviceInfo()}});
// Small touch down
- NotifyMotionArgs args1 = generateMotionArgs(/*downTime=*/0, /*eventTime=*/0, DOWN, {{1, 2, 3}});
- mBlocker->notifyMotion(&args1);
+ mBlocker->notifyMotion(generateMotionArgs(/*downTime=*/0, /*eventTime=*/0, DOWN, {{1, 2, 3}}));
mTestListener.assertNotifyMotionWasCalled(WithMotionAction(DOWN));
// Large touch oval on the next move
- NotifyMotionArgs args2 =
- generateMotionArgs(/*downTime=*/0, RESAMPLE_PERIOD, MOVE, {{4, 5, 200}});
- mBlocker->notifyMotion(&args2);
+ mBlocker->notifyMotion(
+ generateMotionArgs(/*downTime=*/0, RESAMPLE_PERIOD, MOVE, {{4, 5, 200}}));
mTestListener.assertNotifyMotionWasCalled(WithMotionAction(MOVE));
// Lift up the touch to force the model to decide on whether it's a palm
- NotifyMotionArgs args3 =
- generateMotionArgs(/*downTime=*/0, 2 * RESAMPLE_PERIOD, UP, {{4, 5, 200}});
- mBlocker->notifyMotion(&args3);
+ mBlocker->notifyMotion(
+ generateMotionArgs(/*downTime=*/0, 2 * RESAMPLE_PERIOD, UP, {{4, 5, 200}}));
mTestListener.assertNotifyMotionWasCalled(WithMotionAction(CANCEL));
}
@@ -618,14 +596,14 @@
mBlocker->notifyInputDevicesChanged(deviceChangedArgs);
NotifyMotionArgs args1 = generateMotionArgs(/*downTime=*/0, /*eventTime=*/0, DOWN, {{1, 2, 3}});
args1.pointerProperties[0].toolType = ToolType::STYLUS;
- mBlocker->notifyMotion(&args1);
+ mBlocker->notifyMotion(args1);
mTestListener.assertNotifyMotionWasCalled(WithMotionAction(DOWN));
// Move the stylus, setting large TOUCH_MAJOR/TOUCH_MINOR dimensions
NotifyMotionArgs args2 =
generateMotionArgs(/*downTime=*/0, RESAMPLE_PERIOD, MOVE, {{4, 5, 200}});
args2.pointerProperties[0].toolType = ToolType::STYLUS;
- mBlocker->notifyMotion(&args2);
+ mBlocker->notifyMotion(args2);
mTestListener.assertNotifyMotionWasCalled(WithMotionAction(MOVE));
// Lift up the stylus. If it were a touch event, this would force the model to decide on whether
@@ -633,7 +611,7 @@
NotifyMotionArgs args3 =
generateMotionArgs(/*downTime=*/0, 2 * RESAMPLE_PERIOD, UP, {{4, 5, 200}});
args3.pointerProperties[0].toolType = ToolType::STYLUS;
- mBlocker->notifyMotion(&args3);
+ mBlocker->notifyMotion(args3);
mTestListener.assertNotifyMotionWasCalled(WithMotionAction(UP));
}
@@ -649,28 +627,28 @@
// Touch down
NotifyMotionArgs args1 = generateMotionArgs(/*downTime=*/0, /*eventTime=*/0, DOWN, {{1, 2, 3}});
- mBlocker->notifyMotion(&args1);
+ mBlocker->notifyMotion(args1);
mTestListener.assertNotifyMotionWasCalled(WithMotionAction(DOWN));
// Stylus pointer down
NotifyMotionArgs args2 = generateMotionArgs(/*downTime=*/0, RESAMPLE_PERIOD, POINTER_1_DOWN,
{{1, 2, 3}, {10, 20, 30}});
args2.pointerProperties[1].toolType = ToolType::STYLUS;
- mBlocker->notifyMotion(&args2);
+ mBlocker->notifyMotion(args2);
mTestListener.assertNotifyMotionWasCalled(WithMotionAction(POINTER_1_DOWN));
// Large touch oval on the next finger move
NotifyMotionArgs args3 = generateMotionArgs(/*downTime=*/0, 2 * RESAMPLE_PERIOD, MOVE,
{{1, 2, 300}, {11, 21, 30}});
args3.pointerProperties[1].toolType = ToolType::STYLUS;
- mBlocker->notifyMotion(&args3);
+ mBlocker->notifyMotion(args3);
mTestListener.assertNotifyMotionWasCalled(WithMotionAction(MOVE));
// Lift up the finger pointer. It should be canceled due to the heuristic filter.
NotifyMotionArgs args4 = generateMotionArgs(/*downTime=*/0, 3 * RESAMPLE_PERIOD, POINTER_0_UP,
{{1, 2, 300}, {11, 21, 30}});
args4.pointerProperties[1].toolType = ToolType::STYLUS;
- mBlocker->notifyMotion(&args4);
+ mBlocker->notifyMotion(args4);
mTestListener.assertNotifyMotionWasCalled(
AllOf(WithMotionAction(POINTER_0_UP), WithFlags(FLAG_CANCELED)));
@@ -678,7 +656,7 @@
generateMotionArgs(/*downTime=*/0, 4 * RESAMPLE_PERIOD, MOVE, {{12, 22, 30}});
args5.pointerProperties[0].id = args4.pointerProperties[1].id;
args5.pointerProperties[0].toolType = ToolType::STYLUS;
- mBlocker->notifyMotion(&args5);
+ mBlocker->notifyMotion(args5);
mTestListener.assertNotifyMotionWasCalled(WithMotionAction(MOVE));
// Lift up the stylus pointer
@@ -686,7 +664,7 @@
generateMotionArgs(/*downTime=*/0, 5 * RESAMPLE_PERIOD, UP, {{4, 5, 200}});
args6.pointerProperties[0].id = args4.pointerProperties[1].id;
args6.pointerProperties[0].toolType = ToolType::STYLUS;
- mBlocker->notifyMotion(&args6);
+ mBlocker->notifyMotion(args6);
mTestListener.assertNotifyMotionWasCalled(WithMotionAction(UP));
}
@@ -700,17 +678,15 @@
ScopedSilentDeath _silentDeath;
NotifyMotionArgs args;
mBlocker->notifyInputDevicesChanged({/*id=*/0, {generateTestDeviceInfo()}});
- mBlocker->notifyMotion(
- &(args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, DOWN, {{1, 2, 3}})));
- mBlocker->notifyMotion(
- &(args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/2, MOVE, {{4, 5, 6}})));
+ mBlocker->notifyMotion(generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, DOWN, {{1, 2, 3}}));
+ mBlocker->notifyMotion(generateMotionArgs(/*downTime=*/0, /*eventTime=*/2, MOVE, {{4, 5, 6}}));
NotifyDeviceResetArgs resetArgs(/*sequenceNum=*/1, /*eventTime=*/3, DEVICE_ID);
- mBlocker->notifyDeviceReset(&resetArgs);
+ mBlocker->notifyDeviceReset(resetArgs);
// Sending MOVE without a DOWN -> should crash!
ASSERT_DEATH(
{
- mBlocker->notifyMotion(&(args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/4,
- MOVE, {{7, 8, 9}})));
+ mBlocker->notifyMotion(
+ generateMotionArgs(/*downTime=*/0, /*eventTime=*/4, MOVE, {{7, 8, 9}}));
},
"Could not find slot");
}
@@ -720,9 +696,13 @@
*/
TEST_F(UnwantedInteractionBlockerTestDeathTest, WhenMoveWithoutDownCausesACrash) {
ScopedSilentDeath _silentDeath;
- NotifyMotionArgs args = generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, MOVE, {{1, 2, 3}});
mBlocker->notifyInputDevicesChanged({/*id=*/0, {generateTestDeviceInfo()}});
- ASSERT_DEATH({ mBlocker->notifyMotion(&args); }, "Could not find slot");
+ ASSERT_DEATH(
+ {
+ mBlocker->notifyMotion(
+ generateMotionArgs(/*downTime=*/0, /*eventTime=*/1, MOVE, {{1, 2, 3}}));
+ },
+ "Could not find slot");
}
class PalmRejectorTest : public testing::Test {
diff --git a/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp b/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp
index 6617f65..f8ebc97 100644
--- a/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp
+++ b/services/inputflinger/tests/fuzzers/InputClassifierFuzzer.cpp
@@ -67,51 +67,42 @@
fdp.PickValueInArray<std::function<void()>>({
[&]() -> void {
// SendToNextStage_NotifyConfigurationChangedArgs
- NotifyConfigurationChangedArgs
- args(/*sequenceNum=*/fdp.ConsumeIntegral<uint32_t>(),
- /*eventTime=*/fdp.ConsumeIntegral<nsecs_t>());
- mClassifier->notifyConfigurationChanged(&args);
+ mClassifier->notifyConfigurationChanged(
+ {/*sequenceNum=*/fdp.ConsumeIntegral<int32_t>(),
+ /*eventTime=*/fdp.ConsumeIntegral<nsecs_t>()});
},
[&]() -> void {
// SendToNextStage_NotifyKeyArgs
const nsecs_t eventTime = fdp.ConsumeIntegral<nsecs_t>();
const nsecs_t readTime =
eventTime + fdp.ConsumeIntegralInRange<nsecs_t>(0, 1E8);
- NotifyKeyArgs keyArgs(/*sequenceNum=*/fdp.ConsumeIntegral<uint32_t>(),
- eventTime, readTime,
- /*deviceId=*/fdp.ConsumeIntegral<int32_t>(),
- AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_DEFAULT,
- /*policyFlags=*/fdp.ConsumeIntegral<uint32_t>(),
- AKEY_EVENT_ACTION_DOWN,
- /*flags=*/fdp.ConsumeIntegral<int32_t>(), AKEYCODE_HOME,
- /*scanCode=*/fdp.ConsumeIntegral<int32_t>(), AMETA_NONE,
- /*downTime=*/fdp.ConsumeIntegral<nsecs_t>());
-
- mClassifier->notifyKey(&keyArgs);
+ mClassifier->notifyKey({/*sequenceNum=*/fdp.ConsumeIntegral<int32_t>(),
+ eventTime, readTime,
+ /*deviceId=*/fdp.ConsumeIntegral<int32_t>(),
+ AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_DEFAULT,
+ /*policyFlags=*/fdp.ConsumeIntegral<uint32_t>(),
+ AKEY_EVENT_ACTION_DOWN,
+ /*flags=*/fdp.ConsumeIntegral<int32_t>(), AKEYCODE_HOME,
+ /*scanCode=*/fdp.ConsumeIntegral<int32_t>(), AMETA_NONE,
+ /*downTime=*/fdp.ConsumeIntegral<nsecs_t>()});
},
[&]() -> void {
// SendToNextStage_NotifyMotionArgs
- NotifyMotionArgs motionArgs = generateFuzzedMotionArgs(fdp);
- mClassifier->notifyMotion(&motionArgs);
+ mClassifier->notifyMotion(generateFuzzedMotionArgs(fdp));
},
[&]() -> void {
// SendToNextStage_NotifySwitchArgs
- NotifySwitchArgs switchArgs(/*sequenceNum=*/fdp.ConsumeIntegral<uint32_t>(),
- /*eventTime=*/fdp.ConsumeIntegral<nsecs_t>(),
- /*policyFlags=*/fdp.ConsumeIntegral<uint32_t>(),
- /*switchValues=*/fdp.ConsumeIntegral<uint32_t>(),
- /*switchMask=*/fdp.ConsumeIntegral<uint32_t>());
-
- mClassifier->notifySwitch(&switchArgs);
+ mClassifier->notifySwitch({/*sequenceNum=*/fdp.ConsumeIntegral<int32_t>(),
+ /*eventTime=*/fdp.ConsumeIntegral<nsecs_t>(),
+ /*policyFlags=*/fdp.ConsumeIntegral<uint32_t>(),
+ /*switchValues=*/fdp.ConsumeIntegral<uint32_t>(),
+ /*switchMask=*/fdp.ConsumeIntegral<uint32_t>()});
},
[&]() -> void {
// SendToNextStage_NotifyDeviceResetArgs
- NotifyDeviceResetArgs resetArgs(
- /*sequenceNum=*/fdp.ConsumeIntegral<uint32_t>(),
- /*eventTime=*/fdp.ConsumeIntegral<nsecs_t>(),
- /*deviceId=*/fdp.ConsumeIntegral<int32_t>());
-
- mClassifier->notifyDeviceReset(&resetArgs);
+ mClassifier->notifyDeviceReset({/*sequenceNum=*/fdp.ConsumeIntegral<int32_t>(),
+ /*eventTime=*/fdp.ConsumeIntegral<nsecs_t>(),
+ /*deviceId=*/fdp.ConsumeIntegral<int32_t>()});
},
[&]() -> void {
// InputClassifierConverterTest
diff --git a/services/inputflinger/tests/fuzzers/MapperHelpers.h b/services/inputflinger/tests/fuzzers/MapperHelpers.h
index 0dc627a..1e44e0f 100644
--- a/services/inputflinger/tests/fuzzers/MapperHelpers.h
+++ b/services/inputflinger/tests/fuzzers/MapperHelpers.h
@@ -294,14 +294,14 @@
class FuzzInputListener : public virtual InputListenerInterface {
public:
void notifyInputDevicesChanged(const NotifyInputDevicesChangedArgs& args) override {}
- void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) override {}
- void notifyKey(const NotifyKeyArgs* args) override {}
- void notifyMotion(const NotifyMotionArgs* args) override {}
- void notifySwitch(const NotifySwitchArgs* args) override {}
- void notifySensor(const NotifySensorArgs* args) override{};
- void notifyVibratorState(const NotifyVibratorStateArgs* args) override{};
- void notifyDeviceReset(const NotifyDeviceResetArgs* args) override {}
- void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs* args) override{};
+ void notifyConfigurationChanged(const NotifyConfigurationChangedArgs& args) override {}
+ void notifyKey(const NotifyKeyArgs& args) override {}
+ void notifyMotion(const NotifyMotionArgs& args) override {}
+ void notifySwitch(const NotifySwitchArgs& args) override {}
+ void notifySensor(const NotifySensorArgs& args) override{};
+ void notifyVibratorState(const NotifyVibratorStateArgs& args) override{};
+ void notifyDeviceReset(const NotifyDeviceResetArgs& args) override {}
+ void notifyPointerCaptureChanged(const NotifyPointerCaptureChangedArgs& args) override{};
};
class FuzzInputReaderContext : public InputReaderContext {
diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp
index 01db0cd..20f4de1 100644
--- a/services/surfaceflinger/DisplayDevice.cpp
+++ b/services/surfaceflinger/DisplayDevice.cpp
@@ -535,8 +535,8 @@
}
void DisplayDevice::adjustRefreshRate(Fps pacesetterDisplayRefreshRate) {
- using fps_approx_ops::operator==;
- if (mRequestedRefreshRate == 0_Hz) {
+ using fps_approx_ops::operator<=;
+ if (mRequestedRefreshRate <= 0_Hz) {
return;
}
@@ -547,7 +547,12 @@
}
unsigned divisor = static_cast<unsigned>(
- std::round(pacesetterDisplayRefreshRate.getValue() / mRequestedRefreshRate.getValue()));
+ std::floor(pacesetterDisplayRefreshRate.getValue() / mRequestedRefreshRate.getValue()));
+ if (divisor == 0) {
+ mAdjustedRefreshRate = 0_Hz;
+ return;
+ }
+
mAdjustedRefreshRate = pacesetterDisplayRefreshRate / divisor;
}
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index a538c6d..9c232b1 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -2442,16 +2442,7 @@
info.inputConfig |= WindowInfo::InputConfig::NOT_TOUCHABLE;
}
- // For compatibility reasons we let layers which can receive input
- // receive input before they have actually submitted a buffer. Because
- // of this we use canReceiveInput instead of isVisible to check the
- // policy-visibility, ignoring the buffer state. However for layers with
- // hasInputInfo()==false we can use the real visibility state.
- // We are just using these layers for occlusion detection in
- // InputDispatcher, and obviously if they aren't visible they can't occlude
- // anything.
- const bool visible = hasInputInfo() ? canReceiveInput() : isVisible();
- info.setInputConfig(WindowInfo::InputConfig::NOT_VISIBLE, !visible);
+ info.setInputConfig(WindowInfo::InputConfig::NOT_VISIBLE, !isVisibleForInput());
info.alpha = getAlpha();
fillTouchOcclusionMode(info);
diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h
index acdd01d..8d7c362 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -372,6 +372,21 @@
bool canReceiveInput() const;
/*
+ * Whether or not the layer should be considered visible for input calculations.
+ */
+ virtual bool isVisibleForInput() const {
+ // For compatibility reasons we let layers which can receive input
+ // receive input before they have actually submitted a buffer. Because
+ // of this we use canReceiveInput instead of isVisible to check the
+ // policy-visibility, ignoring the buffer state. However for layers with
+ // hasInputInfo()==false we can use the real visibility state.
+ // We are just using these layers for occlusion detection in
+ // InputDispatcher, and obviously if they aren't visible they can't occlude
+ // anything.
+ return hasInputInfo() ? canReceiveInput() : isVisible();
+ }
+
+ /*
* isProtected - true if the layer may contain protected contents in the
* GRALLOC_USAGE_PROTECTED sense.
*/
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 8394ffb..31bf7ef 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -3715,17 +3715,33 @@
return;
}
+ std::unordered_set<Layer*> visibleLayers;
+ mDrawingState.traverse([&visibleLayers](Layer* layer) {
+ if (layer->isVisibleForInput()) {
+ visibleLayers.insert(layer);
+ }
+ });
+ bool visibleLayersChanged = false;
+ if (visibleLayers != mVisibleLayers) {
+ visibleLayersChanged = true;
+ mVisibleLayers = std::move(visibleLayers);
+ }
+
BackgroundExecutor::getInstance().sendCallbacks({[updateWindowInfo,
windowInfos = std::move(windowInfos),
displayInfos = std::move(displayInfos),
inputWindowCommands =
std::move(mInputWindowCommands),
- inputFlinger = mInputFlinger, this]() {
+ inputFlinger = mInputFlinger, this,
+ visibleLayersChanged]() {
ATRACE_NAME("BackgroundExecutor::updateInputFlinger");
if (updateWindowInfo) {
mWindowInfosListenerInvoker
- ->windowInfosChanged(windowInfos, displayInfos,
- inputWindowCommands.windowInfosReportedListeners);
+ ->windowInfosChanged(std::move(windowInfos), std::move(displayInfos),
+ std::move(
+ inputWindowCommands.windowInfosReportedListeners),
+ /* forceImmediateCall= */ visibleLayersChanged ||
+ !inputWindowCommands.focusRequests.empty());
} else {
// If there are listeners but no changes to input windows, call the listeners
// immediately.
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 5783c8d..eb9dc74 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -499,7 +499,7 @@
// Implements ISurfaceComposer
sp<IBinder> createDisplay(const String8& displayName, bool secure,
- float requestedRefreshRate = 0);
+ float requestedRefreshRate = 0.0f);
void destroyDisplay(const sp<IBinder>& displayToken);
std::vector<PhysicalDisplayId> getPhysicalDisplayIds() const EXCLUDES(mStateLock) {
Mutex::Autolock lock(mStateLock);
@@ -1424,6 +1424,11 @@
TransactionHandler mTransactionHandler;
display::DisplayMap<ui::LayerStack, frontend::DisplayInfo> mFrontEndDisplayInfos;
bool mFrontEndDisplayInfosChanged = false;
+
+ // Layers visible during the last commit. This set should only be used for testing set equality
+ // and membership. The pointers should not be dereferenced as it's possible the set contains
+ // pointers to freed layers.
+ std::unordered_set<Layer*> mVisibleLayers;
};
class SurfaceComposerAIDL : public gui::BnSurfaceComposer {
diff --git a/services/surfaceflinger/WindowInfosListenerInvoker.cpp b/services/surfaceflinger/WindowInfosListenerInvoker.cpp
index 292083b..856fbbb 100644
--- a/services/surfaceflinger/WindowInfosListenerInvoker.cpp
+++ b/services/surfaceflinger/WindowInfosListenerInvoker.cpp
@@ -25,20 +25,17 @@
using gui::IWindowInfosListener;
using gui::WindowInfo;
-struct WindowInfosListenerInvoker::WindowInfosReportedListener : gui::BnWindowInfosReportedListener,
- DeathRecipient {
- explicit WindowInfosReportedListener(
- size_t callbackCount,
- const std::unordered_set<sp<gui::IWindowInfosReportedListener>,
- SpHash<gui::IWindowInfosReportedListener>>&
- windowInfosReportedListeners)
- : mCallbacksPending(callbackCount),
- mWindowInfosReportedListeners(windowInfosReportedListeners) {}
+using WindowInfosListenerVector = ftl::SmallVector<const sp<IWindowInfosListener>, 3>;
+
+struct WindowInfosReportedListenerInvoker : gui::BnWindowInfosReportedListener,
+ IBinder::DeathRecipient {
+ WindowInfosReportedListenerInvoker(WindowInfosListenerVector windowInfosListeners,
+ WindowInfosReportedListenerSet windowInfosReportedListeners)
+ : mCallbacksPending(windowInfosListeners.size()),
+ mWindowInfosListeners(std::move(windowInfosListeners)),
+ mWindowInfosReportedListeners(std::move(windowInfosReportedListeners)) {}
binder::Status onWindowInfosReported() override {
- // TODO(b/222421815) There could potentially be callbacks that we don't need to wait for
- // before calling the WindowInfosReportedListeners coming from InputWindowCommands. Filter
- // the list of callbacks down to those from system server.
if (--mCallbacksPending == 0) {
for (const auto& listener : mWindowInfosReportedListeners) {
sp<IBinder> asBinder = IInterface::asBinder(listener);
@@ -46,6 +43,12 @@
listener->onWindowInfosReported();
}
}
+
+ auto wpThis = wp<WindowInfosReportedListenerInvoker>::fromExisting(this);
+ for (const auto& listener : mWindowInfosListeners) {
+ sp<IBinder> binder = IInterface::asBinder(listener);
+ binder->unlinkToDeath(wpThis);
+ }
}
return binder::Status::ok();
}
@@ -54,9 +57,9 @@
private:
std::atomic<size_t> mCallbacksPending;
- std::unordered_set<sp<gui::IWindowInfosReportedListener>,
- SpHash<gui::IWindowInfosReportedListener>>
- mWindowInfosReportedListeners;
+ static constexpr size_t kStaticCapacity = 3;
+ const WindowInfosListenerVector mWindowInfosListeners;
+ WindowInfosReportedListenerSet mWindowInfosReportedListeners;
};
void WindowInfosListenerInvoker::addWindowInfosListener(sp<IWindowInfosListener> listener) {
@@ -82,38 +85,81 @@
}
void WindowInfosListenerInvoker::windowInfosChanged(
- const std::vector<WindowInfo>& windowInfos, const std::vector<DisplayInfo>& displayInfos,
- const std::unordered_set<sp<gui::IWindowInfosReportedListener>,
- SpHash<gui::IWindowInfosReportedListener>>&
- windowInfosReportedListeners) {
- ftl::SmallVector<const sp<IWindowInfosListener>, kStaticCapacity> windowInfosListeners;
+ std::vector<WindowInfo> windowInfos, std::vector<DisplayInfo> displayInfos,
+ WindowInfosReportedListenerSet reportedListeners, bool forceImmediateCall) {
+ reportedListeners.insert(sp<WindowInfosListenerInvoker>::fromExisting(this));
+ auto callListeners = [this, windowInfos = std::move(windowInfos),
+ displayInfos = std::move(displayInfos)](
+ WindowInfosReportedListenerSet reportedListeners) mutable {
+ WindowInfosListenerVector windowInfosListeners;
+ {
+ std::scoped_lock lock(mListenersMutex);
+ for (const auto& [_, listener] : mWindowInfosListeners) {
+ windowInfosListeners.push_back(listener);
+ }
+ }
+
+ auto reportedInvoker =
+ sp<WindowInfosReportedListenerInvoker>::make(windowInfosListeners,
+ std::move(reportedListeners));
+
+ for (const auto& listener : windowInfosListeners) {
+ sp<IBinder> asBinder = IInterface::asBinder(listener);
+
+ // linkToDeath is used here to ensure that the windowInfosReportedListeners
+ // are called even if one of the windowInfosListeners dies before
+ // calling onWindowInfosReported.
+ asBinder->linkToDeath(reportedInvoker);
+
+ auto status =
+ listener->onWindowInfosChanged(windowInfos, displayInfos, reportedInvoker);
+ if (!status.isOk()) {
+ reportedInvoker->onWindowInfosReported();
+ }
+ }
+ };
+
{
- std::scoped_lock lock(mListenersMutex);
- for (const auto& [_, listener] : mWindowInfosListeners) {
- windowInfosListeners.push_back(listener);
+ std::scoped_lock lock(mMessagesMutex);
+ // If there are unacked messages and this isn't a forced call, then return immediately.
+ // If a forced window infos change doesn't happen first, the update will be sent after
+ // the WindowInfosReportedListeners are called. If a forced window infos change happens or
+ // if there are subsequent delayed messages before this update is sent, then this message
+ // will be dropped and the listeners will only be called with the latest info. This is done
+ // to reduce the amount of binder memory used.
+ if (mActiveMessageCount > 0 && !forceImmediateCall) {
+ mWindowInfosChangedDelayed = std::move(callListeners);
+ mReportedListenersDelayed.merge(reportedListeners);
+ return;
}
+
+ mWindowInfosChangedDelayed = nullptr;
+ reportedListeners.merge(mReportedListenersDelayed);
+ mActiveMessageCount++;
+ }
+ callListeners(std::move(reportedListeners));
+}
+
+binder::Status WindowInfosListenerInvoker::onWindowInfosReported() {
+ std::function<void(WindowInfosReportedListenerSet)> callListeners;
+ WindowInfosReportedListenerSet reportedListeners;
+
+ {
+ std::scoped_lock lock{mMessagesMutex};
+ mActiveMessageCount--;
+ if (!mWindowInfosChangedDelayed || mActiveMessageCount > 0) {
+ return binder::Status::ok();
+ }
+
+ mActiveMessageCount++;
+ callListeners = std::move(mWindowInfosChangedDelayed);
+ mWindowInfosChangedDelayed = nullptr;
+ reportedListeners = std::move(mReportedListenersDelayed);
+ mReportedListenersDelayed.clear();
}
- auto windowInfosReportedListener = windowInfosReportedListeners.empty()
- ? nullptr
- : sp<WindowInfosReportedListener>::make(windowInfosListeners.size(),
- windowInfosReportedListeners);
- for (const auto& listener : windowInfosListeners) {
- sp<IBinder> asBinder = IInterface::asBinder(listener);
-
- // linkToDeath is used here to ensure that the windowInfosReportedListeners
- // are called even if one of the windowInfosListeners dies before
- // calling onWindowInfosReported.
- if (windowInfosReportedListener) {
- asBinder->linkToDeath(windowInfosReportedListener);
- }
-
- auto status = listener->onWindowInfosChanged(windowInfos, displayInfos,
- windowInfosReportedListener);
- if (windowInfosReportedListener && !status.isOk()) {
- windowInfosReportedListener->onWindowInfosReported();
- }
- }
+ callListeners(std::move(reportedListeners));
+ return binder::Status::ok();
}
} // namespace android
diff --git a/services/surfaceflinger/WindowInfosListenerInvoker.h b/services/surfaceflinger/WindowInfosListenerInvoker.h
index d60a9c4..4da9828 100644
--- a/services/surfaceflinger/WindowInfosListenerInvoker.h
+++ b/services/surfaceflinger/WindowInfosListenerInvoker.h
@@ -23,34 +23,42 @@
#include <android/gui/IWindowInfosReportedListener.h>
#include <binder/IBinder.h>
#include <ftl/small_map.h>
+#include <gui/SpHash.h>
#include <utils/Mutex.h>
namespace android {
-class SurfaceFlinger;
+using WindowInfosReportedListenerSet =
+ std::unordered_set<sp<gui::IWindowInfosReportedListener>,
+ gui::SpHash<gui::IWindowInfosReportedListener>>;
-class WindowInfosListenerInvoker : public IBinder::DeathRecipient {
+class WindowInfosListenerInvoker : public gui::BnWindowInfosReportedListener,
+ public IBinder::DeathRecipient {
public:
void addWindowInfosListener(sp<gui::IWindowInfosListener>);
void removeWindowInfosListener(const sp<gui::IWindowInfosListener>& windowInfosListener);
- void windowInfosChanged(const std::vector<gui::WindowInfo>&,
- const std::vector<gui::DisplayInfo>&,
- const std::unordered_set<sp<gui::IWindowInfosReportedListener>,
- SpHash<gui::IWindowInfosReportedListener>>&
- windowInfosReportedListeners);
+ void windowInfosChanged(std::vector<gui::WindowInfo>, std::vector<gui::DisplayInfo>,
+ WindowInfosReportedListenerSet windowInfosReportedListeners,
+ bool forceImmediateCall);
+
+ binder::Status onWindowInfosReported() override;
protected:
void binderDied(const wp<IBinder>& who) override;
private:
- struct WindowInfosReportedListener;
-
std::mutex mListenersMutex;
static constexpr size_t kStaticCapacity = 3;
ftl::SmallMap<wp<IBinder>, const sp<gui::IWindowInfosListener>, kStaticCapacity>
mWindowInfosListeners GUARDED_BY(mListenersMutex);
+
+ std::mutex mMessagesMutex;
+ uint32_t mActiveMessageCount GUARDED_BY(mMessagesMutex) = 0;
+ std::function<void(WindowInfosReportedListenerSet)> mWindowInfosChangedDelayed
+ GUARDED_BY(mMessagesMutex);
+ WindowInfosReportedListenerSet mReportedListenersDelayed;
};
} // namespace android
diff --git a/services/surfaceflinger/tests/unittests/SurfaceFlinger_CreateDisplayTest.cpp b/services/surfaceflinger/tests/unittests/SurfaceFlinger_CreateDisplayTest.cpp
index 6a9c970..1cc9ba4 100644
--- a/services/surfaceflinger/tests/unittests/SurfaceFlinger_CreateDisplayTest.cpp
+++ b/services/surfaceflinger/tests/unittests/SurfaceFlinger_CreateDisplayTest.cpp
@@ -17,12 +17,60 @@
#undef LOG_TAG
#define LOG_TAG "LibSurfaceFlingerUnittests"
+#include <scheduler/Fps.h>
+
#include "DisplayTransactionTestHelpers.h"
+#include "FpsOps.h"
namespace android {
namespace {
-class CreateDisplayTest : public DisplayTransactionTest {};
+class CreateDisplayTest : public DisplayTransactionTest {
+public:
+ void createDisplayWithRequestedRefreshRate(const String8& name, uint64_t displayId,
+ float pacesetterDisplayRefreshRate,
+ float requestedRefreshRate,
+ float expectedAdjustedRefreshRate) {
+ // --------------------------------------------------------------------
+ // Call Expectations
+
+ // --------------------------------------------------------------------
+ // Invocation
+
+ sp<IBinder> displayToken = mFlinger.createDisplay(name, false, requestedRefreshRate);
+
+ // --------------------------------------------------------------------
+ // Postconditions
+
+ // The display should have been added to the current state
+ ASSERT_TRUE(hasCurrentDisplayState(displayToken));
+ const auto& display = getCurrentDisplayState(displayToken);
+ EXPECT_TRUE(display.isVirtual());
+ EXPECT_EQ(display.requestedRefreshRate, Fps::fromValue(requestedRefreshRate));
+ EXPECT_EQ(name.string(), display.displayName);
+
+ std::optional<VirtualDisplayId> vid =
+ DisplayId::fromValue<VirtualDisplayId>(displayId | DisplayId::FLAG_VIRTUAL);
+ ASSERT_TRUE(vid.has_value());
+
+ sp<DisplayDevice> device =
+ mFlinger.createVirtualDisplayDevice(displayToken, *vid, requestedRefreshRate);
+ EXPECT_TRUE(device->isVirtual());
+ device->adjustRefreshRate(Fps::fromValue(pacesetterDisplayRefreshRate));
+ // verifying desired value
+ EXPECT_EQ(device->getAdjustedRefreshRate(), Fps::fromValue(expectedAdjustedRefreshRate));
+ // verifying rounding up
+ if (requestedRefreshRate < pacesetterDisplayRefreshRate) {
+ EXPECT_GE(device->getAdjustedRefreshRate(), Fps::fromValue(requestedRefreshRate));
+ } else {
+ EXPECT_EQ(device->getAdjustedRefreshRate(),
+ Fps::fromValue(pacesetterDisplayRefreshRate));
+ }
+
+ // --------------------------------------------------------------------
+ // Cleanup conditions
+ }
+};
TEST_F(CreateDisplayTest, createDisplaySetsCurrentStateForNonsecureDisplay) {
const String8 name("virtual.test");
@@ -84,5 +132,82 @@
EXPECT_CALL(*mFlinger.scheduler(), scheduleFrame()).Times(1);
}
+// Requesting 0 tells SF not to do anything, i.e., default to refresh as physical displays
+TEST_F(CreateDisplayTest, createDisplayWithRequestedRefreshRate0) {
+ const String8 displayName("virtual.test");
+ const uint64_t displayId = 123ull;
+ const float kPacesetterDisplayRefreshRate = 60.f;
+ const float kRequestedRefreshRate = 0.f;
+ const float kExpectedAdjustedRefreshRate = 0.f;
+ createDisplayWithRequestedRefreshRate(displayName, displayId, kPacesetterDisplayRefreshRate,
+ kRequestedRefreshRate, kExpectedAdjustedRefreshRate);
+}
+
+// Requesting negative refresh rate, will be ignored, same as requesting 0
+TEST_F(CreateDisplayTest, createDisplayWithRequestedRefreshRateNegative) {
+ const String8 displayName("virtual.test");
+ const uint64_t displayId = 123ull;
+ const float kPacesetterDisplayRefreshRate = 60.f;
+ const float kRequestedRefreshRate = -60.f;
+ const float kExpectedAdjustedRefreshRate = 0.f;
+ createDisplayWithRequestedRefreshRate(displayName, displayId, kPacesetterDisplayRefreshRate,
+ kRequestedRefreshRate, kExpectedAdjustedRefreshRate);
+}
+
+// Requesting a higher refresh rate than the pacesetter
+TEST_F(CreateDisplayTest, createDisplayWithRequestedRefreshRateHigh) {
+ const String8 displayName("virtual.test");
+ const uint64_t displayId = 123ull;
+ const float kPacesetterDisplayRefreshRate = 60.f;
+ const float kRequestedRefreshRate = 90.f;
+ const float kExpectedAdjustedRefreshRate = 60.f;
+ createDisplayWithRequestedRefreshRate(displayName, displayId, kPacesetterDisplayRefreshRate,
+ kRequestedRefreshRate, kExpectedAdjustedRefreshRate);
+}
+
+// Requesting the same refresh rate as the pacesetter
+TEST_F(CreateDisplayTest, createDisplayWithRequestedRefreshRateSame) {
+ const String8 displayName("virtual.test");
+ const uint64_t displayId = 123ull;
+ const float kPacesetterDisplayRefreshRate = 60.f;
+ const float kRequestedRefreshRate = 60.f;
+ const float kExpectedAdjustedRefreshRate = 60.f;
+ createDisplayWithRequestedRefreshRate(displayName, displayId, kPacesetterDisplayRefreshRate,
+ kRequestedRefreshRate, kExpectedAdjustedRefreshRate);
+}
+
+// Requesting a divisor (30) of the pacesetter (60) should be honored
+TEST_F(CreateDisplayTest, createDisplayWithRequestedRefreshRateDivisor) {
+ const String8 displayName("virtual.test");
+ const uint64_t displayId = 123ull;
+ const float kPacesetterDisplayRefreshRate = 60.f;
+ const float kRequestedRefreshRate = 30.f;
+ const float kExpectedAdjustedRefreshRate = 30.f;
+ createDisplayWithRequestedRefreshRate(displayName, displayId, kPacesetterDisplayRefreshRate,
+ kRequestedRefreshRate, kExpectedAdjustedRefreshRate);
+}
+
+// Requesting a non divisor (45) of the pacesetter (120) should round up to a divisor (60)
+TEST_F(CreateDisplayTest, createDisplayWithRequestedRefreshRateNoneDivisor) {
+ const String8 displayName("virtual.test");
+ const uint64_t displayId = 123ull;
+ const float kPacesetterDisplayRefreshRate = 120.f;
+ const float kRequestedRefreshRate = 45.f;
+ const float kExpectedAdjustedRefreshRate = 60.f;
+ createDisplayWithRequestedRefreshRate(displayName, displayId, kPacesetterDisplayRefreshRate,
+ kRequestedRefreshRate, kExpectedAdjustedRefreshRate);
+}
+
+// Requesting a non divisor (75) of the pacesetter (120) should round up to pacesetter (120)
+TEST_F(CreateDisplayTest, createDisplayWithRequestedRefreshRateNoneDivisorMax) {
+ const String8 displayName("virtual.test");
+ const uint64_t displayId = 123ull;
+ const float kPacesetterDisplayRefreshRate = 120.f;
+ const float kRequestedRefreshRate = 75.f;
+ const float kExpectedAdjustedRefreshRate = 120.f;
+ createDisplayWithRequestedRefreshRate(displayName, displayId, kPacesetterDisplayRefreshRate,
+ kRequestedRefreshRate, kExpectedAdjustedRefreshRate);
+}
+
} // namespace
} // namespace android
diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
index 6f48df8..cfa366f 100644
--- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
+++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h
@@ -48,10 +48,12 @@
#include "TestableScheduler.h"
#include "mock/DisplayHardware/MockComposer.h"
#include "mock/DisplayHardware/MockDisplayMode.h"
+#include "mock/DisplayHardware/MockPowerAdvisor.h"
#include "mock/MockEventThread.h"
#include "mock/MockFrameTimeline.h"
#include "mock/MockFrameTracer.h"
#include "mock/MockSchedulerCallback.h"
+#include "mock/system/window/MockNativeWindow.h"
namespace android {
namespace renderengine {
@@ -375,8 +377,8 @@
void commitAndComposite() { mFlinger->composite(commit(), kVsyncId); }
- auto createDisplay(const String8& displayName, bool secure) {
- return mFlinger->createDisplay(displayName, secure);
+ auto createDisplay(const String8& displayName, bool secure, float requestedRefreshRate = 0.0f) {
+ return mFlinger->createDisplay(displayName, secure, requestedRefreshRate);
}
auto destroyDisplay(const sp<IBinder>& displayToken) {
@@ -525,6 +527,24 @@
mFlinger->getDynamicDisplayInfoFromToken(displayToken, dynamicDisplayInfo);
}
+ sp<DisplayDevice> createVirtualDisplayDevice(const sp<IBinder> displayToken,
+ VirtualDisplayId displayId,
+ float requestedRefreshRate) {
+ constexpr ui::Size kResolution = {1080, 1920};
+ auto compositionDisplay = compositionengine::impl::
+ createDisplay(mFlinger->getCompositionEngine(),
+ compositionengine::DisplayCreationArgsBuilder()
+ .setId(displayId)
+ .setPixels(kResolution)
+ .setPowerAdvisor(&mPowerAdvisor)
+ .build());
+ DisplayDeviceCreationArgs creationArgs(mFlinger, mFlinger->getHwComposer(), displayToken,
+ compositionDisplay);
+ creationArgs.requestedRefreshRate = Fps::fromValue(requestedRefreshRate);
+ creationArgs.nativeWindow = sp<mock::NativeWindow>::make();
+ return sp<DisplayDevice>::make(creationArgs);
+ }
+
/* ------------------------------------------------------------------------
* Read-only access to private data to assert post-conditions.
*/
@@ -962,6 +982,7 @@
scheduler::mock::NoOpSchedulerCallback mNoOpSchedulerCallback;
std::unique_ptr<frametimeline::impl::TokenManager> mTokenManager;
scheduler::TestableScheduler* mScheduler = nullptr;
+ Hwc2::mock::PowerAdvisor mPowerAdvisor;
};
} // namespace android
diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp
index dec3b20..922a44f 100644
--- a/vulkan/libvulkan/swapchain.cpp
+++ b/vulkan/libvulkan/swapchain.cpp
@@ -252,27 +252,31 @@
Swapchain(Surface& surface_,
uint32_t num_images_,
VkPresentModeKHR present_mode,
- int pre_transform_)
+ int pre_transform_,
+ int64_t refresh_duration_)
: surface(surface_),
num_images(num_images_),
mailbox_mode(present_mode == VK_PRESENT_MODE_MAILBOX_KHR),
pre_transform(pre_transform_),
frame_timestamps_enabled(false),
+ refresh_duration(refresh_duration_),
acquire_next_image_timeout(-1),
shared(IsSharedPresentMode(present_mode)) {
- ANativeWindow* window = surface.window.get();
- native_window_get_refresh_cycle_duration(
- window,
- &refresh_duration);
}
- uint64_t get_refresh_duration()
+
+ VkResult get_refresh_duration(uint64_t& outRefreshDuration)
{
ANativeWindow* window = surface.window.get();
- native_window_get_refresh_cycle_duration(
+ int err = native_window_get_refresh_cycle_duration(
window,
&refresh_duration);
- return static_cast<uint64_t>(refresh_duration);
-
+ if (err != android::OK) {
+ ALOGE("%s:native_window_get_refresh_cycle_duration failed: %s (%d)",
+ __func__, strerror(-err), err );
+ return VK_ERROR_SURFACE_LOST_KHR;
+ }
+ outRefreshDuration = refresh_duration;
+ return VK_SUCCESS;
}
Surface& surface;
@@ -1626,6 +1630,13 @@
return VK_ERROR_SURFACE_LOST_KHR;
}
+ int64_t refresh_duration;
+ err = native_window_get_refresh_cycle_duration(window, &refresh_duration);
+ if (err != android::OK) {
+ ALOGE("native_window_get_refresh_cycle_duration query failed: %s (%d)",
+ strerror(-err), err);
+ return VK_ERROR_SURFACE_LOST_KHR;
+ }
// -- Allocate our Swapchain object --
// After this point, we must deallocate the swapchain on error.
@@ -1636,8 +1647,8 @@
return VK_ERROR_OUT_OF_HOST_MEMORY;
Swapchain* swapchain = new (mem)
Swapchain(surface, num_images, create_info->presentMode,
- TranslateVulkanToNativeTransform(create_info->preTransform));
-
+ TranslateVulkanToNativeTransform(create_info->preTransform),
+ refresh_duration);
VkSwapchainImageCreateInfoANDROID swapchain_image_create = {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wold-style-cast"
@@ -2308,9 +2319,7 @@
ATRACE_CALL();
Swapchain& swapchain = *SwapchainFromHandle(swapchain_handle);
- VkResult result = VK_SUCCESS;
-
- pDisplayTimingProperties->refreshDuration = swapchain.get_refresh_duration();
+ VkResult result = swapchain.get_refresh_duration(pDisplayTimingProperties->refreshDuration);
return result;
}