diff options
49 files changed, 399 insertions, 172 deletions
diff --git a/libs/binder/rust/tests/Android.bp b/libs/binder/rust/tests/Android.bp index 1c875c0375..2d1175be75 100644 --- a/libs/binder/rust/tests/Android.bp +++ b/libs/binder/rust/tests/Android.bp @@ -23,9 +23,6 @@ rust_test { // this cannot be the same as the module name. stem: "rustBinderTestClientBinary", test_suites: ["general-tests"], - data: [ - ":rustBinderTestService", - ], } rust_test { @@ -39,6 +36,10 @@ rust_test { // this cannot be the same as the module name. stem: "rustBinderTestServiceBinary", test_harness: false, + // TODO(b/164473602): Remove this setting and add the module to `data` + // attribute of rustBinderTest. + auto_gen_config: false, + test_suites: ["general-tests"], } cc_test { @@ -99,7 +100,7 @@ cc_test { "libbase", ], static_libs: [ - "libbinder_rs_serialization_test", + "libbinder_rs_serialization_test" ], srcs: [ "serialization.cpp", @@ -115,10 +116,8 @@ rust_bindgen { source_stem: "bindings", cpp_std: "gnu++17", bindgen_flags: [ - "--allowlist-type", - "Transaction", - "--allowlist-var", - "TESTDATA_.*", + "--allowlist-type", "Transaction", + "--allowlist-var", "TESTDATA_.*", ], shared_libs: [ diff --git a/libs/gui/BLASTBufferQueue.cpp b/libs/gui/BLASTBufferQueue.cpp index aeb5406bbd..5c324b29cd 100644 --- a/libs/gui/BLASTBufferQueue.cpp +++ b/libs/gui/BLASTBufferQueue.cpp @@ -582,7 +582,8 @@ status_t BLASTBufferQueue::acquireNextBufferLocked( // Only update mSize for destination bounds if the incoming buffer matches the requested size. // Otherwise, it could cause stretching since the destination bounds will update before the // buffer with the new size is acquired. - if (mRequestedSize == getBufferSize(bufferItem)) { + if (mRequestedSize == getBufferSize(bufferItem) || + bufferItem.mScalingMode != NATIVE_WINDOW_SCALING_MODE_FREEZE) { mSize = mRequestedSize; } Rect crop = computeCrop(bufferItem); diff --git a/libs/gui/tests/BLASTBufferQueue_test.cpp b/libs/gui/tests/BLASTBufferQueue_test.cpp index fd69702843..7067c111a3 100644 --- a/libs/gui/tests/BLASTBufferQueue_test.cpp +++ b/libs/gui/tests/BLASTBufferQueue_test.cpp @@ -32,6 +32,7 @@ #include <private/gui/ComposerService.h> #include <private/gui/ComposerServiceAIDL.h> #include <ui/DisplayMode.h> +#include <ui/DisplayState.h> #include <ui/GraphicBuffer.h> #include <ui/GraphicTypes.h> #include <ui/Transform.h> @@ -200,11 +201,13 @@ protected: t.apply(); t.clear(); - ui::DisplayMode mode; - ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getActiveDisplayMode(mDisplayToken, &mode)); - const ui::Size& resolution = mode.resolution; + ui::DisplayState displayState; + ASSERT_EQ(NO_ERROR, SurfaceComposerClient::getDisplayState(mDisplayToken, &displayState)); + const ui::Size& resolution = displayState.layerStackSpaceRect; mDisplayWidth = resolution.getWidth(); mDisplayHeight = resolution.getHeight(); + ALOGV("Display: %dx%d orientation:%d", mDisplayWidth, mDisplayHeight, + displayState.orientation); mSurfaceControl = mClient->createSurface(String8("TestSurface"), mDisplayWidth, mDisplayHeight, PIXEL_FORMAT_RGBA_8888, diff --git a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegr.h b/libs/jpegrecoverymap/include/jpegrecoverymap/jpegr.h index 6262e18479..afec0655b3 100644 --- a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegr.h +++ b/libs/jpegrecoverymap/include/jpegrecoverymap/jpegr.h @@ -63,12 +63,26 @@ struct jpegr_info_struct { struct jpegr_uncompressed_struct { // Pointer to the data location. void* data; - // Width of the recovery map or image in pixels. + // Width of the recovery map or the luma plane of the image in pixels. int width; - // Height of the recovery map or image in pixels. + // Height of the recovery map or the luma plane of the image in pixels. int height; // Color gamut. jpegr_color_gamut colorGamut; + + // Values below are optional + // Pointer to chroma data, if it's NULL, chroma plane is considered to be immediately + // following after the luma plane. + // Note: currently this feature is only supported for P010 image (HDR input). + void* chroma_data = nullptr; + // Strides of Y plane in number of pixels, using 0 to present uninitialized, must be + // larger than or equal to luma width. + // Note: currently this feature is only supported for P010 image (HDR input). + int luma_stride = 0; + // Strides of UV plane in number of pixels, using 0 to present uninitialized, must be + // larger than or equal to chroma width. + // Note: currently this feature is only supported for P010 image (HDR input). + int chroma_stride = 0; }; /* @@ -363,6 +377,16 @@ private: */ status_t toneMap(jr_uncompressed_ptr src, jr_uncompressed_ptr dest); + + /* + * This method will check the validity of the input images. + * + * @param uncompressed_p010_image uncompressed HDR image in P010 color format + * @param uncompressed_yuv_420_image uncompressed SDR image in YUV_420 color format + * @return NO_ERROR if the input images are valid, error code is not valid. + */ + status_t areInputImagesValid(jr_uncompressed_ptr uncompressed_p010_image, + jr_uncompressed_ptr uncompressed_yuv_420_image); }; } // namespace android::jpegrecoverymap diff --git a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegrerrorcode.h b/libs/jpegrecoverymap/include/jpegrecoverymap/jpegrerrorcode.h index f73034338b..159aaa8107 100644 --- a/libs/jpegrecoverymap/include/jpegrecoverymap/jpegrerrorcode.h +++ b/libs/jpegrecoverymap/include/jpegrecoverymap/jpegrerrorcode.h @@ -46,6 +46,8 @@ enum { ERROR_JPEGR_CALCULATION_ERROR = JPEGR_RUNTIME_ERROR_BASE - 3, ERROR_JPEGR_METADATA_ERROR = JPEGR_RUNTIME_ERROR_BASE - 4, ERROR_JPEGR_TONEMAP_ERROR = JPEGR_RUNTIME_ERROR_BASE - 5, + + ERROR_JPEGR_UNSUPPORTED_FEATURE = -20000, }; } // namespace android::jpegrecoverymap diff --git a/libs/jpegrecoverymap/jpegr.cpp b/libs/jpegrecoverymap/jpegr.cpp index d147130209..cdf685e005 100644 --- a/libs/jpegrecoverymap/jpegr.cpp +++ b/libs/jpegrecoverymap/jpegr.cpp @@ -86,6 +86,54 @@ int GetCPUCoreCount() { return cpuCoreCount; } +status_t JpegR::areInputImagesValid(jr_uncompressed_ptr uncompressed_p010_image, + jr_uncompressed_ptr uncompressed_yuv_420_image) { + if (uncompressed_p010_image == nullptr) { + 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", + uncompressed_p010_image->luma_stride, uncompressed_p010_image->width); + return ERROR_JPEGR_INVALID_INPUT_TYPE; + } + + if (uncompressed_yuv_420_image == nullptr) { + return NO_ERROR; + } + + if (uncompressed_yuv_420_image->luma_stride != 0) { + ALOGE("Stride is not supported for YUV420 image"); + return ERROR_JPEGR_UNSUPPORTED_FEATURE; + } + + if (uncompressed_yuv_420_image->chroma_data != nullptr) { + ALOGE("Pointer to chroma plane is not supported for YUV420 image, chroma data must" + "be immediately after the luma data."); + return ERROR_JPEGR_UNSUPPORTED_FEATURE; + } + + if (uncompressed_p010_image->width != uncompressed_yuv_420_image->width + || uncompressed_p010_image->height != uncompressed_yuv_420_image->height) { + ALOGE("Image resolutions mismatch: P010: %dx%d, YUV420: %dx%d", + uncompressed_p010_image->width, + uncompressed_p010_image->height, + uncompressed_yuv_420_image->width, + uncompressed_yuv_420_image->height); + return ERROR_JPEGR_RESOLUTION_MISMATCH; + } + + return NO_ERROR; +} + /* Encode API-0 */ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image, jpegr_transfer_function hdr_tf, @@ -100,11 +148,9 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image, return ERROR_JPEGR_INVALID_INPUT_TYPE; } - 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 (status_t ret = areInputImagesValid( + uncompressed_p010_image, /* uncompressed_yuv_420_image */ nullptr) != NO_ERROR) { + return ret; } jpegr_metadata_struct metadata; @@ -164,16 +210,9 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image, return ERROR_JPEGR_INVALID_INPUT_TYPE; } - if (uncompressed_p010_image->width != uncompressed_yuv_420_image->width - || uncompressed_p010_image->height != uncompressed_yuv_420_image->height) { - return ERROR_JPEGR_RESOLUTION_MISMATCH; - } - - 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 (status_t ret = areInputImagesValid( + uncompressed_p010_image, uncompressed_yuv_420_image) != NO_ERROR) { + return ret; } jpegr_metadata_struct metadata; @@ -223,16 +262,9 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image, return ERROR_JPEGR_INVALID_NULL_PTR; } - if (uncompressed_p010_image->width != uncompressed_yuv_420_image->width - || uncompressed_p010_image->height != uncompressed_yuv_420_image->height) { - return ERROR_JPEGR_RESOLUTION_MISMATCH; - } - - 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 (status_t ret = areInputImagesValid( + uncompressed_p010_image, uncompressed_yuv_420_image) != NO_ERROR) { + return ret; } jpegr_metadata_struct metadata; @@ -266,11 +298,9 @@ status_t JpegR::encodeJPEGR(jr_uncompressed_ptr uncompressed_p010_image, 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 (status_t ret = areInputImagesValid( + uncompressed_p010_image, /* uncompressed_yuv_420_image */ nullptr) != NO_ERROR) { + return ret; } JpegDecoderHelper jpeg_decoder; @@ -998,25 +1028,43 @@ status_t JpegR::toneMap(jr_uncompressed_ptr src, jr_uncompressed_ptr dest) { return ERROR_JPEGR_INVALID_NULL_PTR; } + size_t src_luma_stride = src->luma_stride; + size_t src_chroma_stride = src->chroma_stride; + uint16_t* src_luma_data = reinterpret_cast<uint16_t*>(src->data); + 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]; + } + if (src_luma_stride == 0) { + src_luma_stride = src->width; + } + if (src_chroma_stride == 0) { + src_chroma_stride = src_luma_stride; + } + dest->width = src->width; dest->height = src->height; - size_t pixel_count = src->width * src->height; + size_t dest_luma_pixel_count = dest->width * dest->height; + for (size_t y = 0; y < src->height; ++y) { for (size_t x = 0; x < src->width; ++x) { - size_t pixel_y_idx = x + y * src->width; - size_t pixel_uv_idx = x / 2 + (y / 2) * (src->width / 2); - - uint16_t y_uint = reinterpret_cast<uint16_t*>(src->data)[pixel_y_idx] - >> 6; - uint16_t u_uint = reinterpret_cast<uint16_t*>(src->data)[pixel_count + pixel_uv_idx * 2] - >> 6; - uint16_t v_uint = reinterpret_cast<uint16_t*>(src->data)[pixel_count + pixel_uv_idx * 2 + 1] - >> 6; - - uint8_t* y = &reinterpret_cast<uint8_t*>(dest->data)[pixel_y_idx]; - uint8_t* u = &reinterpret_cast<uint8_t*>(dest->data)[pixel_count + pixel_uv_idx]; - uint8_t* v = &reinterpret_cast<uint8_t*>(dest->data)[pixel_count * 5 / 4 + pixel_uv_idx]; + size_t src_y_idx = y * src_luma_stride + x; + size_t src_u_idx = (y >> 1) * src_chroma_stride + (x & ~0x1); + size_t src_v_idx = src_u_idx + 1; + + uint16_t y_uint = src_luma_data[src_y_idx] >> 6; + uint16_t u_uint = src_chroma_data[src_u_idx] >> 6; + uint16_t v_uint = src_chroma_data[src_v_idx] >> 6; + + size_t dest_y_idx = x + y * dest->width; + size_t dest_uv_idx = x / 2 + (y / 2) * (dest->width / 2); + + uint8_t* y = &reinterpret_cast<uint8_t*>(dest->data)[dest_y_idx]; + uint8_t* u = &reinterpret_cast<uint8_t*>(dest->data)[dest_luma_pixel_count + dest_uv_idx]; + uint8_t* v = &reinterpret_cast<uint8_t*>( + dest->data)[dest_luma_pixel_count * 5 / 4 + dest_uv_idx]; *y = static_cast<uint8_t>((y_uint >> 2) & 0xff); *u = static_cast<uint8_t>((u_uint >> 2) & 0xff); diff --git a/libs/jpegrecoverymap/recoverymapmath.cpp b/libs/jpegrecoverymap/recoverymapmath.cpp index 8808b55b0c..ce6fc8fa47 100644 --- a/libs/jpegrecoverymap/recoverymapmath.cpp +++ b/libs/jpegrecoverymap/recoverymapmath.cpp @@ -499,17 +499,28 @@ Color getYuv420Pixel(jr_uncompressed_ptr image, size_t x, size_t y) { } Color getP010Pixel(jr_uncompressed_ptr image, size_t x, size_t y) { - size_t pixel_count = image->width * image->height; + size_t luma_stride = image->luma_stride; + size_t chroma_stride = image->chroma_stride; + uint16_t* luma_data = reinterpret_cast<uint16_t*>(image->data); + uint16_t* chroma_data = reinterpret_cast<uint16_t*>(image->chroma_data); - size_t pixel_y_idx = x + y * image->width; - size_t pixel_uv_idx = x / 2 + (y / 2) * (image->width / 2); + if (luma_stride == 0) { + luma_stride = image->width; + } + if (chroma_stride == 0) { + chroma_stride = luma_stride; + } + if (chroma_data == nullptr) { + chroma_data = &reinterpret_cast<uint16_t*>(image->data)[image->luma_stride * image->height]; + } + + size_t pixel_y_idx = y * luma_stride + x; + size_t pixel_u_idx = (y >> 1) * chroma_stride + (x & ~0x1); + size_t pixel_v_idx = pixel_u_idx + 1; - uint16_t y_uint = reinterpret_cast<uint16_t*>(image->data)[pixel_y_idx] - >> 6; - uint16_t u_uint = reinterpret_cast<uint16_t*>(image->data)[pixel_count + pixel_uv_idx * 2] - >> 6; - uint16_t v_uint = reinterpret_cast<uint16_t*>(image->data)[pixel_count + pixel_uv_idx * 2 + 1] - >> 6; + uint16_t y_uint = luma_data[pixel_y_idx] >> 6; + uint16_t u_uint = chroma_data[pixel_u_idx] >> 6; + uint16_t v_uint = chroma_data[pixel_v_idx] >> 6; // Conversions include taking narrow-range into account. return {{{ (static_cast<float>(y_uint) - 64.0f) / 876.0f, diff --git a/libs/jpegrecoverymap/tests/data/raw_p010_image_with_stride.p010 b/libs/jpegrecoverymap/tests/data/raw_p010_image_with_stride.p010 Binary files differnew file mode 100644 index 0000000000..e7a5dc84dc --- /dev/null +++ b/libs/jpegrecoverymap/tests/data/raw_p010_image_with_stride.p010 diff --git a/libs/jpegrecoverymap/tests/jpegr_test.cpp b/libs/jpegrecoverymap/tests/jpegr_test.cpp index 7c669aba0a..229d7dc93b 100644 --- a/libs/jpegrecoverymap/tests/jpegr_test.cpp +++ b/libs/jpegrecoverymap/tests/jpegr_test.cpp @@ -24,10 +24,12 @@ #include <utils/Log.h> #define RAW_P010_IMAGE "/sdcard/Documents/raw_p010_image.p010" +#define RAW_P010_IMAGE_WITH_STRIDE "/sdcard/Documents/raw_p010_image_with_stride.p010" #define RAW_YUV420_IMAGE "/sdcard/Documents/raw_yuv420_image.yuv420" #define JPEG_IMAGE "/sdcard/Documents/jpeg_image.jpg" #define TEST_IMAGE_WIDTH 1280 #define TEST_IMAGE_HEIGHT 720 +#define TEST_IMAGE_STRIDE 1288 #define DEFAULT_JPEG_QUALITY 90 #define SAVE_ENCODING_RESULT true @@ -97,6 +99,7 @@ protected: virtual void TearDown(); struct jpegr_uncompressed_struct mRawP010Image; + struct jpegr_uncompressed_struct mRawP010ImageWithStride; struct jpegr_uncompressed_struct mRawYuv420Image; struct jpegr_compressed_struct mJpegImage; }; @@ -107,6 +110,7 @@ JpegRTest::~JpegRTest() {} void JpegRTest::SetUp() {} void JpegRTest::TearDown() { free(mRawP010Image.data); + free(mRawP010ImageWithStride.data); free(mRawYuv420Image.data); free(mJpegImage.data); } @@ -249,6 +253,61 @@ TEST_F(JpegRTest, encodeFromP010ThenDecode) { free(decodedJpegR.data); } +/* Test Encode API-0 (with stride) and decode */ +TEST_F(JpegRTest, encodeFromP010WithStrideThenDecode) { + int ret; + + // Load input files. + if (!loadFile(RAW_P010_IMAGE_WITH_STRIDE, mRawP010ImageWithStride.data, nullptr)) { + FAIL() << "Load file " << RAW_P010_IMAGE_WITH_STRIDE << " failed"; + } + mRawP010ImageWithStride.width = TEST_IMAGE_WIDTH; + mRawP010ImageWithStride.height = TEST_IMAGE_HEIGHT; + mRawP010ImageWithStride.luma_stride = TEST_IMAGE_STRIDE; + mRawP010ImageWithStride.colorGamut = jpegr_color_gamut::JPEGR_COLORGAMUT_BT2100; + + JpegR jpegRCodec; + + jpegr_compressed_struct jpegR; + 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, + DEFAULT_JPEG_QUALITY, nullptr); + if (ret != OK) { + FAIL() << "Error code is " << ret; + } + if (SAVE_ENCODING_RESULT) { + // Output image data to file + std::string filePath = "/sdcard/Documents/encoded_from_p010_input.jpgr"; + std::ofstream imageFile(filePath.c_str(), std::ofstream::binary); + if (!imageFile.is_open()) { + ALOGE("%s: Unable to create file %s", __FUNCTION__, filePath.c_str()); + } + imageFile.write((const char*)jpegR.data, jpegR.length); + } + + jpegr_uncompressed_struct decodedJpegR; + int decodedJpegRSize = TEST_IMAGE_WIDTH * TEST_IMAGE_HEIGHT * 8; + decodedJpegR.data = malloc(decodedJpegRSize); + ret = jpegRCodec.decodeJPEGR(&jpegR, &decodedJpegR); + if (ret != OK) { + FAIL() << "Error code is " << ret; + } + if (SAVE_DECODING_RESULT) { + // Output image data to file + std::string filePath = "/sdcard/Documents/decoded_from_p010_input.rgb"; + std::ofstream imageFile(filePath.c_str(), std::ofstream::binary); + if (!imageFile.is_open()) { + ALOGE("%s: Unable to create file %s", __FUNCTION__, filePath.c_str()); + } + imageFile.write((const char*)decodedJpegR.data, decodedJpegRSize); + } + + free(jpegR.data); + free(decodedJpegR.data); +} + /* Test Encode API-1 and decode */ TEST_F(JpegRTest, encodeFromRawHdrAndSdrThenDecode) { int ret; diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index 6e2f86223f..851f13c0d5 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -626,7 +626,9 @@ std::vector<TouchedWindow> getHoveringWindowsLocked(const TouchState* oldState, touchedWindow.targetFlags = InputTarget::Flags::DISPATCH_AS_HOVER_ENTER; } else { // This pointer was already sent to the window. Use ACTION_HOVER_MOVE. - LOG_ALWAYS_FATAL_IF(maskedAction != AMOTION_EVENT_ACTION_HOVER_MOVE); + if (CC_UNLIKELY(maskedAction != AMOTION_EVENT_ACTION_HOVER_MOVE)) { + LOG(FATAL) << "Expected ACTION_HOVER_MOVE instead of " << entry.getDescription(); + } touchedWindow.targetFlags = InputTarget::Flags::DISPATCH_AS_IS; } touchedWindow.pointerIds.set(pointerId); diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp index eaed987320..ccf41189bc 100644 --- a/services/inputflinger/reader/InputDevice.cpp +++ b/services/inputflinger/reader/InputDevice.cpp @@ -253,7 +253,8 @@ void InputDevice::removeEventHubDevice(int32_t eventHubId) { mDevices.erase(eventHubId); } -std::list<NotifyArgs> InputDevice::configure(nsecs_t when, const InputReaderConfiguration* config, +std::list<NotifyArgs> InputDevice::configure(nsecs_t when, + const InputReaderConfiguration& readerConfig, uint32_t changes) { std::list<NotifyArgs> out; mSources = 0; @@ -291,7 +292,7 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when, const InputReaderConf }); mAssociatedDeviceType = - getValueByKey(config->deviceTypeAssociations, mIdentifier.location); + getValueByKey(readerConfig.deviceTypeAssociations, mIdentifier.location); } if (!changes || (changes & InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUTS)) { @@ -325,8 +326,8 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when, const InputReaderConf // Do not execute this code on the first configure, because 'setEnabled' would call // InputMapper::reset, and you can't reset a mapper before it has been configured. // The mappers are configured for the first time at the bottom of this function. - auto it = config->disabledDevices.find(mId); - bool enabled = it == config->disabledDevices.end(); + auto it = readerConfig.disabledDevices.find(mId); + bool enabled = it == readerConfig.disabledDevices.end(); out += setEnabled(enabled, when); } @@ -338,13 +339,14 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when, const InputReaderConf // Find the display port that corresponds to the current input port. const std::string& inputPort = mIdentifier.location; if (!inputPort.empty()) { - const std::unordered_map<std::string, uint8_t>& ports = config->portAssociations; + const std::unordered_map<std::string, uint8_t>& ports = + readerConfig.portAssociations; const auto& displayPort = ports.find(inputPort); if (displayPort != ports.end()) { mAssociatedDisplayPort = std::make_optional(displayPort->second); } else { const std::unordered_map<std::string, std::string>& displayUniqueIds = - config->uniqueIdAssociations; + readerConfig.uniqueIdAssociations; const auto& displayUniqueId = displayUniqueIds.find(inputPort); if (displayUniqueId != displayUniqueIds.end()) { mAssociatedDisplayUniqueId = displayUniqueId->second; @@ -356,9 +358,11 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when, const InputReaderConf // "disabledDevices" list. If it is associated with a specific display, and it was not // explicitly disabled, then enable/disable the device based on whether we can find the // corresponding viewport. - bool enabled = (config->disabledDevices.find(mId) == config->disabledDevices.end()); + bool enabled = + (readerConfig.disabledDevices.find(mId) == readerConfig.disabledDevices.end()); if (mAssociatedDisplayPort) { - mAssociatedViewport = config->getDisplayViewportByPort(*mAssociatedDisplayPort); + mAssociatedViewport = + readerConfig.getDisplayViewportByPort(*mAssociatedDisplayPort); if (!mAssociatedViewport) { ALOGW("Input device %s should be associated with display on port %" PRIu8 ", " "but the corresponding viewport is not found.", @@ -367,7 +371,7 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when, const InputReaderConf } } else if (mAssociatedDisplayUniqueId != std::nullopt) { mAssociatedViewport = - config->getDisplayViewportByUniqueId(*mAssociatedDisplayUniqueId); + readerConfig.getDisplayViewportByUniqueId(*mAssociatedDisplayUniqueId); if (!mAssociatedViewport) { ALOGW("Input device %s should be associated with display %s but the " "corresponding viewport cannot be found", @@ -384,15 +388,16 @@ std::list<NotifyArgs> InputDevice::configure(nsecs_t when, const InputReaderConf } } - for_each_mapper([this, when, &config, changes, &out](InputMapper& mapper) { - out += mapper.reconfigure(when, config, changes); + for_each_mapper([this, when, &readerConfig, changes, &out](InputMapper& mapper) { + out += mapper.reconfigure(when, readerConfig, changes); mSources |= mapper.getSources(); }); // If a device is just plugged but it might be disabled, we need to update some info like // axis range of touch from each InputMapper first, then disable it. if (!changes) { - out += setEnabled(config->disabledDevices.find(mId) == config->disabledDevices.end(), + out += setEnabled(readerConfig.disabledDevices.find(mId) == + readerConfig.disabledDevices.end(), when); } } diff --git a/services/inputflinger/reader/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp index 81ac03b7b3..80459a2945 100644 --- a/services/inputflinger/reader/InputReader.cpp +++ b/services/inputflinger/reader/InputReader.cpp @@ -234,7 +234,7 @@ void InputReader::addDeviceLocked(nsecs_t when, int32_t eventHubId) { InputDeviceIdentifier identifier = mEventHub->getDeviceIdentifier(eventHubId); std::shared_ptr<InputDevice> device = createDeviceLocked(eventHubId, identifier); - notifyAll(device->configure(when, &mConfig, 0)); + notifyAll(device->configure(when, mConfig, 0)); notifyAll(device->reset(when)); if (device->isIgnored()) { @@ -310,7 +310,7 @@ void InputReader::removeDeviceLocked(nsecs_t when, int32_t eventHubId) { std::list<NotifyArgs> resetEvents; if (device->hasEventHubDevices()) { - resetEvents += device->configure(when, &mConfig, 0); + resetEvents += device->configure(when, mConfig, 0); } resetEvents += device->reset(when); notifyAll(std::move(resetEvents)); @@ -408,7 +408,7 @@ void InputReader::refreshConfigurationLocked(uint32_t changes) { } else { for (auto& devicePair : mDevices) { std::shared_ptr<InputDevice>& device = devicePair.second; - notifyAll(device->configure(now, &mConfig, changes)); + notifyAll(device->configure(now, mConfig, changes)); } } diff --git a/services/inputflinger/reader/include/InputDevice.h b/services/inputflinger/reader/include/InputDevice.h index 4ae06fe77b..ad45cb102f 100644 --- a/services/inputflinger/reader/include/InputDevice.h +++ b/services/inputflinger/reader/include/InputDevice.h @@ -83,7 +83,7 @@ public: void addEventHubDevice(int32_t eventHubId, bool populateMappers = true); void removeEventHubDevice(int32_t eventHubId); [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& readerConfig, uint32_t changes); [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when); [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvents, size_t count); diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.cpp b/services/inputflinger/reader/mapper/CursorInputMapper.cpp index d7dc2aec70..1cc614ea4e 100644 --- a/services/inputflinger/reader/mapper/CursorInputMapper.cpp +++ b/services/inputflinger/reader/mapper/CursorInputMapper.cpp @@ -134,7 +134,7 @@ void CursorInputMapper::dump(std::string& dump) { } std::list<NotifyArgs> CursorInputMapper::reconfigure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& config, uint32_t changes) { std::list<NotifyArgs> out = InputMapper::reconfigure(when, config, changes); @@ -173,10 +173,10 @@ std::list<NotifyArgs> CursorInputMapper::reconfigure(nsecs_t when, } const bool configurePointerCapture = mParameters.mode != Parameters::Mode::NAVIGATION && - ((!changes && config->pointerCaptureRequest.enable) || + ((!changes && config.pointerCaptureRequest.enable) || (changes & InputReaderConfiguration::CHANGE_POINTER_CAPTURE)); if (configurePointerCapture) { - if (config->pointerCaptureRequest.enable) { + if (config.pointerCaptureRequest.enable) { if (mParameters.mode == Parameters::Mode::POINTER) { mParameters.mode = Parameters::Mode::POINTER_RELATIVE; mSource = AINPUT_SOURCE_MOUSE_RELATIVE; @@ -207,9 +207,9 @@ std::list<NotifyArgs> CursorInputMapper::reconfigure(nsecs_t when, mWheelXVelocityControl.setParameters(FLAT_VELOCITY_CONTROL_PARAMS); mWheelYVelocityControl.setParameters(FLAT_VELOCITY_CONTROL_PARAMS); } else { - mPointerVelocityControl.setParameters(config->pointerVelocityControlParameters); - mWheelXVelocityControl.setParameters(config->wheelVelocityControlParameters); - mWheelYVelocityControl.setParameters(config->wheelVelocityControlParameters); + mPointerVelocityControl.setParameters(config.pointerVelocityControlParameters); + mWheelXVelocityControl.setParameters(config.wheelVelocityControlParameters); + mWheelYVelocityControl.setParameters(config.wheelVelocityControlParameters); } } @@ -241,7 +241,7 @@ std::list<NotifyArgs> CursorInputMapper::reconfigure(nsecs_t when, // rotations and report values directly from the input device. if (!isOrientedDevice && mDisplayId && mParameters.mode != Parameters::Mode::POINTER_RELATIVE) { - if (auto viewport = config->getDisplayViewportById(*mDisplayId); viewport) { + if (auto viewport = config.getDisplayViewportById(*mDisplayId); viewport) { mOrientation = getInverseRotation(viewport->orientation); } } diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.h b/services/inputflinger/reader/mapper/CursorInputMapper.h index 987b9debb9..5f7a3adc88 100644 --- a/services/inputflinger/reader/mapper/CursorInputMapper.h +++ b/services/inputflinger/reader/mapper/CursorInputMapper.h @@ -60,7 +60,7 @@ public: virtual void populateDeviceInfo(InputDeviceInfo& deviceInfo) override; virtual void dump(std::string& dump) override; [[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& config, uint32_t changes) override; [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override; [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override; diff --git a/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp b/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp index c5a3075657..bbb641eb76 100644 --- a/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp +++ b/services/inputflinger/reader/mapper/ExternalStylusInputMapper.cpp @@ -47,7 +47,7 @@ void ExternalStylusInputMapper::dump(std::string& dump) { } std::list<NotifyArgs> ExternalStylusInputMapper::reconfigure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& config, uint32_t changes) { getAbsoluteAxisInfo(ABS_PRESSURE, &mRawPressureAxis); mTouchButtonAccumulator.configure(); diff --git a/services/inputflinger/reader/mapper/ExternalStylusInputMapper.h b/services/inputflinger/reader/mapper/ExternalStylusInputMapper.h index 0df8cf7b1b..3eac10d07f 100644 --- a/services/inputflinger/reader/mapper/ExternalStylusInputMapper.h +++ b/services/inputflinger/reader/mapper/ExternalStylusInputMapper.h @@ -33,7 +33,7 @@ public: void populateDeviceInfo(InputDeviceInfo& deviceInfo) override; void dump(std::string& dump) override; [[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& config, uint32_t changes) override; [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override; [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override; diff --git a/services/inputflinger/reader/mapper/InputMapper.cpp b/services/inputflinger/reader/mapper/InputMapper.cpp index 9d1e9ceb1c..5dd7bc4f8b 100644 --- a/services/inputflinger/reader/mapper/InputMapper.cpp +++ b/services/inputflinger/reader/mapper/InputMapper.cpp @@ -35,7 +35,7 @@ void InputMapper::populateDeviceInfo(InputDeviceInfo& info) { void InputMapper::dump(std::string& dump) {} -std::list<NotifyArgs> InputMapper::reconfigure(nsecs_t when, const InputReaderConfiguration* config, +std::list<NotifyArgs> InputMapper::reconfigure(nsecs_t when, const InputReaderConfiguration& config, uint32_t changes) { return {}; } diff --git a/services/inputflinger/reader/mapper/InputMapper.h b/services/inputflinger/reader/mapper/InputMapper.h index bb15e4d86b..ab573f054b 100644 --- a/services/inputflinger/reader/mapper/InputMapper.h +++ b/services/inputflinger/reader/mapper/InputMapper.h @@ -54,7 +54,7 @@ public: virtual void populateDeviceInfo(InputDeviceInfo& deviceInfo); virtual void dump(std::string& dump); [[nodiscard]] virtual std::list<NotifyArgs> reconfigure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& config, uint32_t changes); [[nodiscard]] virtual std::list<NotifyArgs> reset(nsecs_t when); [[nodiscard]] virtual std::list<NotifyArgs> process(const RawEvent* rawEvent) = 0; diff --git a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp index f60035bd00..3e840ee500 100644 --- a/services/inputflinger/reader/mapper/JoystickInputMapper.cpp +++ b/services/inputflinger/reader/mapper/JoystickInputMapper.cpp @@ -104,7 +104,7 @@ void JoystickInputMapper::dump(std::string& dump) { } std::list<NotifyArgs> JoystickInputMapper::reconfigure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& config, uint32_t changes) { std::list<NotifyArgs> out = InputMapper::reconfigure(when, config, changes); diff --git a/services/inputflinger/reader/mapper/JoystickInputMapper.h b/services/inputflinger/reader/mapper/JoystickInputMapper.h index 9adb07fb4e..6f1c6b7655 100644 --- a/services/inputflinger/reader/mapper/JoystickInputMapper.h +++ b/services/inputflinger/reader/mapper/JoystickInputMapper.h @@ -29,7 +29,7 @@ public: virtual void populateDeviceInfo(InputDeviceInfo& deviceInfo) override; virtual void dump(std::string& dump) override; [[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& config, uint32_t changes) override; [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override; [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override; diff --git a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp index fc00c4886d..f8dd3a85ac 100644 --- a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp +++ b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp @@ -118,21 +118,21 @@ void KeyboardInputMapper::dump(std::string& dump) { } std::optional<DisplayViewport> KeyboardInputMapper::findViewport( - const InputReaderConfiguration* config) { + const InputReaderConfiguration& readerConfig) { if (getDeviceContext().getAssociatedViewport()) { return getDeviceContext().getAssociatedViewport(); } // No associated display defined, try to find default display if orientationAware. if (mParameters.orientationAware) { - return config->getDisplayViewportByType(ViewportType::INTERNAL); + return readerConfig.getDisplayViewportByType(ViewportType::INTERNAL); } return std::nullopt; } std::list<NotifyArgs> KeyboardInputMapper::reconfigure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& config, uint32_t changes) { std::list<NotifyArgs> out = InputMapper::reconfigure(when, config, changes); @@ -147,7 +147,7 @@ std::list<NotifyArgs> KeyboardInputMapper::reconfigure(nsecs_t when, if (!changes || (changes & InputReaderConfiguration::CHANGE_KEYBOARD_LAYOUT_ASSOCIATION)) { mKeyboardLayoutInfo = - getValueByKey(config->keyboardLayoutAssociations, getDeviceContext().getLocation()); + getValueByKey(config.keyboardLayoutAssociations, getDeviceContext().getLocation()); } return out; diff --git a/services/inputflinger/reader/mapper/KeyboardInputMapper.h b/services/inputflinger/reader/mapper/KeyboardInputMapper.h index 52576c339c..0cb130d4cd 100644 --- a/services/inputflinger/reader/mapper/KeyboardInputMapper.h +++ b/services/inputflinger/reader/mapper/KeyboardInputMapper.h @@ -30,7 +30,7 @@ public: void populateDeviceInfo(InputDeviceInfo& deviceInfo) override; void dump(std::string& dump) override; [[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& config, uint32_t changes) override; [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override; [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override; @@ -96,7 +96,7 @@ private: void resetLedState(); void initializeLedState(LedState& ledState, int32_t led); void updateLedStateForModifier(LedState& ledState, int32_t led, int32_t modifier, bool reset); - std::optional<DisplayViewport> findViewport(const InputReaderConfiguration* config); + std::optional<DisplayViewport> findViewport(const InputReaderConfiguration& readerConfig); [[nodiscard]] std::list<NotifyArgs> cancelAllDownKeys(nsecs_t when); }; diff --git a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp index 5b7b29509e..b181aa0bf8 100644 --- a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp +++ b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.cpp @@ -64,7 +64,7 @@ void RotaryEncoderInputMapper::dump(std::string& dump) { } std::list<NotifyArgs> RotaryEncoderInputMapper::reconfigure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& config, uint32_t changes) { std::list<NotifyArgs> out = InputMapper::reconfigure(when, config, changes); if (!changes) { @@ -72,7 +72,7 @@ std::list<NotifyArgs> RotaryEncoderInputMapper::reconfigure(nsecs_t when, } if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) { std::optional<DisplayViewport> internalViewport = - config->getDisplayViewportByType(ViewportType::INTERNAL); + config.getDisplayViewportByType(ViewportType::INTERNAL); if (internalViewport) { mOrientation = internalViewport->orientation; } else { diff --git a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.h b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.h index 639a9876c7..37c94422e3 100644 --- a/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.h +++ b/services/inputflinger/reader/mapper/RotaryEncoderInputMapper.h @@ -32,7 +32,7 @@ public: virtual void populateDeviceInfo(InputDeviceInfo& deviceInfo) override; virtual void dump(std::string& dump) override; [[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& config, uint32_t changes) override; [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override; [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override; diff --git a/services/inputflinger/reader/mapper/SensorInputMapper.cpp b/services/inputflinger/reader/mapper/SensorInputMapper.cpp index 720fc6962d..f8a520d9f4 100644 --- a/services/inputflinger/reader/mapper/SensorInputMapper.cpp +++ b/services/inputflinger/reader/mapper/SensorInputMapper.cpp @@ -117,7 +117,7 @@ void SensorInputMapper::dump(std::string& dump) { } std::list<NotifyArgs> SensorInputMapper::reconfigure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& config, uint32_t changes) { std::list<NotifyArgs> out = InputMapper::reconfigure(when, config, changes); diff --git a/services/inputflinger/reader/mapper/SensorInputMapper.h b/services/inputflinger/reader/mapper/SensorInputMapper.h index 93cc244481..fa36ab30b1 100644 --- a/services/inputflinger/reader/mapper/SensorInputMapper.h +++ b/services/inputflinger/reader/mapper/SensorInputMapper.h @@ -34,7 +34,7 @@ public: void populateDeviceInfo(InputDeviceInfo& deviceInfo) override; void dump(std::string& dump) override; [[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& config, uint32_t changes) override; [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override; [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override; diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp index c19737d672..9a426bf014 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp @@ -288,11 +288,11 @@ void TouchInputMapper::dump(std::string& dump) { } std::list<NotifyArgs> TouchInputMapper::reconfigure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& config, uint32_t changes) { std::list<NotifyArgs> out = InputMapper::reconfigure(when, config, changes); - mConfig = *config; + mConfig = config; // Full configuration should happen the first time configure is called and // when the device type is changed. Changing a device type can affect diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.h b/services/inputflinger/reader/mapper/TouchInputMapper.h index d98ae607e9..0e8ff4b568 100644 --- a/services/inputflinger/reader/mapper/TouchInputMapper.h +++ b/services/inputflinger/reader/mapper/TouchInputMapper.h @@ -153,7 +153,7 @@ public: void populateDeviceInfo(InputDeviceInfo& deviceInfo) override; void dump(std::string& dump) override; [[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& config, uint32_t changes) override; [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override; [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override; diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp index 33f368e9eb..8135071da2 100644 --- a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp @@ -220,7 +220,7 @@ void TouchpadInputMapper::dump(std::string& dump) { } std::list<NotifyArgs> TouchpadInputMapper::reconfigure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& config, uint32_t changes) { if (!changes) { // First time configuration @@ -231,7 +231,7 @@ std::list<NotifyArgs> TouchpadInputMapper::reconfigure(nsecs_t when, std::optional<int32_t> displayId = mPointerController->getDisplayId(); ui::Rotation orientation = ui::ROTATION_0; if (displayId.has_value()) { - if (auto viewport = config->getDisplayViewportById(*displayId); viewport) { + if (auto viewport = config.getDisplayViewportById(*displayId); viewport) { orientation = getInverseRotation(viewport->orientation); } } @@ -242,14 +242,14 @@ std::list<NotifyArgs> TouchpadInputMapper::reconfigure(nsecs_t when, .setBoolValues({true}); GesturesProp accelCurveProp = mPropertyProvider.getProperty("Pointer Accel Curve"); accelCurveProp.setRealValues( - createAccelerationCurveForSensitivity(config->touchpadPointerSpeed, + createAccelerationCurveForSensitivity(config.touchpadPointerSpeed, accelCurveProp.getCount())); mPropertyProvider.getProperty("Invert Scrolling") - .setBoolValues({config->touchpadNaturalScrollingEnabled}); + .setBoolValues({config.touchpadNaturalScrollingEnabled}); mPropertyProvider.getProperty("Tap Enable") - .setBoolValues({config->touchpadTapToClickEnabled}); + .setBoolValues({config.touchpadTapToClickEnabled}); mPropertyProvider.getProperty("Button Right Click Zone Enable") - .setBoolValues({config->touchpadRightClickZoneEnabled}); + .setBoolValues({config.touchpadRightClickZoneEnabled}); } return {}; } diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.h b/services/inputflinger/reader/mapper/TouchpadInputMapper.h index 6f152fa557..27cdde1d45 100644 --- a/services/inputflinger/reader/mapper/TouchpadInputMapper.h +++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.h @@ -45,7 +45,7 @@ public: void dump(std::string& dump) override; [[nodiscard]] std::list<NotifyArgs> reconfigure(nsecs_t when, - const InputReaderConfiguration* config, + const InputReaderConfiguration& config, uint32_t changes) override; [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when) override; [[nodiscard]] std::list<NotifyArgs> process(const RawEvent* rawEvent) override; diff --git a/services/inputflinger/tests/FakeInputReaderPolicy.cpp b/services/inputflinger/tests/FakeInputReaderPolicy.cpp index 30c1719c35..3486d0f2a4 100644 --- a/services/inputflinger/tests/FakeInputReaderPolicy.cpp +++ b/services/inputflinger/tests/FakeInputReaderPolicy.cpp @@ -154,8 +154,8 @@ void FakeInputReaderPolicy::setPointerController( mPointerController = std::move(controller); } -const InputReaderConfiguration* FakeInputReaderPolicy::getReaderConfiguration() const { - return &mConfig; +const InputReaderConfiguration& FakeInputReaderPolicy::getReaderConfiguration() const { + return mConfig; } const std::vector<InputDeviceInfo>& FakeInputReaderPolicy::getInputDevices() const { diff --git a/services/inputflinger/tests/FakeInputReaderPolicy.h b/services/inputflinger/tests/FakeInputReaderPolicy.h index 28ac505284..85ff01a071 100644 --- a/services/inputflinger/tests/FakeInputReaderPolicy.h +++ b/services/inputflinger/tests/FakeInputReaderPolicy.h @@ -63,7 +63,7 @@ public: void addDisabledDevice(int32_t deviceId); void removeDisabledDevice(int32_t deviceId); void setPointerController(std::shared_ptr<FakePointerController> controller); - const InputReaderConfiguration* getReaderConfiguration() const; + const InputReaderConfiguration& getReaderConfiguration() const; const std::vector<InputDeviceInfo>& getInputDevices() const; TouchAffineTransformation getTouchAffineTransformation(const std::string& inputDeviceDescriptor, ui::Rotation surfaceRotation); diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index fb082da8e1..dcf8557d4b 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -263,7 +263,7 @@ private: } } - std::list<NotifyArgs> reconfigure(nsecs_t, const InputReaderConfiguration* config, + std::list<NotifyArgs> reconfigure(nsecs_t, const InputReaderConfiguration& config, uint32_t changes) override { std::scoped_lock<std::mutex> lock(mLock); mConfigureWasCalled = true; @@ -271,7 +271,7 @@ private: // Find the associated viewport if exist. const std::optional<uint8_t> displayPort = getDeviceContext().getAssociatedDisplayPort(); if (displayPort && (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) { - mViewport = config->getDisplayViewportByPort(*displayPort); + mViewport = config.getDisplayViewportByPort(*displayPort); } mStateChangedCondition.notify_all(); @@ -2319,7 +2319,7 @@ TEST_F(InputDeviceTest, WhenDeviceCreated_EnabledIsFalse) { TEST_F(InputDeviceTest, WhenNoMappersAreRegistered_DeviceIsIgnored) { // Configuration. InputReaderConfiguration config; - std::list<NotifyArgs> unused = mDevice->configure(ARBITRARY_TIME, &config, 0); + std::list<NotifyArgs> unused = mDevice->configure(ARBITRARY_TIME, config, 0); // Reset. unused += mDevice->reset(ARBITRARY_TIME); @@ -2378,7 +2378,7 @@ TEST_F(InputDeviceTest, WhenMappersAreRegistered_DeviceIsNotIgnoredAndForwardsRe mapper2.setMetaState(AMETA_SHIFT_ON); InputReaderConfiguration config; - std::list<NotifyArgs> unused = mDevice->configure(ARBITRARY_TIME, &config, 0); + std::list<NotifyArgs> unused = mDevice->configure(ARBITRARY_TIME, config, 0); std::optional<std::string> propertyValue = mDevice->getConfiguration().getString("key"); ASSERT_TRUE(propertyValue.has_value()) @@ -3669,7 +3669,7 @@ TEST_F(KeyboardInputMapperTest, LayoutInfoCorrectlyMapped) { addMapperAndConfigure<KeyboardInputMapper>(AINPUT_SOURCE_KEYBOARD, AINPUT_KEYBOARD_TYPE_ALPHABETIC); InputReaderConfiguration config; - std::list<NotifyArgs> unused = mDevice->configure(ARBITRARY_TIME, &config, 0); + std::list<NotifyArgs> unused = mDevice->configure(ARBITRARY_TIME, config, 0); ASSERT_EQ("en", mDevice->getDeviceInfo().getKeyboardLayoutInfo()->languageTag); ASSERT_EQ("extended", mDevice->getDeviceInfo().getKeyboardLayoutInfo()->layoutType); diff --git a/services/inputflinger/tests/fuzzers/CursorInputFuzzer.cpp b/services/inputflinger/tests/fuzzers/CursorInputFuzzer.cpp index 0d5f30c046..28873a39ea 100644 --- a/services/inputflinger/tests/fuzzers/CursorInputFuzzer.cpp +++ b/services/inputflinger/tests/fuzzers/CursorInputFuzzer.cpp @@ -52,13 +52,13 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) { [&]() -> void { mapper.getSources(); }, [&]() -> void { std::list<NotifyArgs> unused = - mapper.reconfigure(fdp->ConsumeIntegral<nsecs_t>(), &policyConfig, + mapper.reconfigure(fdp->ConsumeIntegral<nsecs_t>(), policyConfig, fdp->ConsumeIntegral<int32_t>()); }, [&]() -> void { // Need to reconfigure with 0 or you risk a NPE. std::list<NotifyArgs> unused = - mapper.reconfigure(fdp->ConsumeIntegral<nsecs_t>(), &policyConfig, 0); + mapper.reconfigure(fdp->ConsumeIntegral<nsecs_t>(), policyConfig, 0); InputDeviceInfo info; mapper.populateDeviceInfo(info); }, @@ -71,7 +71,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) { // Need to reconfigure with 0 or you risk a NPE. std::list<NotifyArgs> unused = - mapper.reconfigure(fdp->ConsumeIntegral<nsecs_t>(), &policyConfig, 0); + mapper.reconfigure(fdp->ConsumeIntegral<nsecs_t>(), policyConfig, 0); RawEvent rawEvent{fdp->ConsumeIntegral<nsecs_t>(), fdp->ConsumeIntegral<nsecs_t>(), fdp->ConsumeIntegral<int32_t>(), @@ -90,7 +90,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) { [&]() -> void { // Need to reconfigure with 0 or you risk a NPE. std::list<NotifyArgs> unused = - mapper.reconfigure(fdp->ConsumeIntegral<nsecs_t>(), &policyConfig, 0); + mapper.reconfigure(fdp->ConsumeIntegral<nsecs_t>(), policyConfig, 0); mapper.getAssociatedDisplayId(); }, })(); diff --git a/services/inputflinger/tests/fuzzers/FuzzContainer.h b/services/inputflinger/tests/fuzzers/FuzzContainer.h index 76d2bcd03d..d42d11c240 100644 --- a/services/inputflinger/tests/fuzzers/FuzzContainer.h +++ b/services/inputflinger/tests/fuzzers/FuzzContainer.h @@ -59,7 +59,7 @@ public: void configureDevice() { nsecs_t arbitraryTime = mFdp->ConsumeIntegral<nsecs_t>(); std::list<NotifyArgs> out; - out += mFuzzDevice->configure(arbitraryTime, &mPolicyConfig, 0); + out += mFuzzDevice->configure(arbitraryTime, mPolicyConfig, 0); out += mFuzzDevice->reset(arbitraryTime); for (const NotifyArgs& args : out) { mFuzzListener.notify(args); diff --git a/services/inputflinger/tests/fuzzers/KeyboardInputFuzzer.cpp b/services/inputflinger/tests/fuzzers/KeyboardInputFuzzer.cpp index 14cb8a5280..00b44b5158 100644 --- a/services/inputflinger/tests/fuzzers/KeyboardInputFuzzer.cpp +++ b/services/inputflinger/tests/fuzzers/KeyboardInputFuzzer.cpp @@ -64,7 +64,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) { [&]() -> void { mapper.getSources(); }, [&]() -> void { std::list<NotifyArgs> unused = - mapper.reconfigure(fdp->ConsumeIntegral<nsecs_t>(), &policyConfig, + mapper.reconfigure(fdp->ConsumeIntegral<nsecs_t>(), policyConfig, fdp->ConsumeIntegral<uint32_t>()); }, [&]() -> void { diff --git a/services/inputflinger/tests/fuzzers/MultiTouchInputFuzzer.cpp b/services/inputflinger/tests/fuzzers/MultiTouchInputFuzzer.cpp index 8352a9011e..70908ff8b6 100644 --- a/services/inputflinger/tests/fuzzers/MultiTouchInputFuzzer.cpp +++ b/services/inputflinger/tests/fuzzers/MultiTouchInputFuzzer.cpp @@ -79,7 +79,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) { [&]() -> void { mapper.getSources(); }, [&]() -> void { std::list<NotifyArgs> unused = - mapper.reconfigure(fdp->ConsumeIntegral<nsecs_t>(), &policyConfig, + mapper.reconfigure(fdp->ConsumeIntegral<nsecs_t>(), policyConfig, fdp->ConsumeIntegral<uint32_t>()); }, [&]() -> void { diff --git a/services/surfaceflinger/CompositionEngine/src/Output.cpp b/services/surfaceflinger/CompositionEngine/src/Output.cpp index e720af5a33..d64231f9e7 100644 --- a/services/surfaceflinger/CompositionEngine/src/Output.cpp +++ b/services/surfaceflinger/CompositionEngine/src/Output.cpp @@ -1574,9 +1574,10 @@ void Output::postFramebuffer() { } void Output::renderCachedSets(const CompositionRefreshArgs& refreshArgs) { - if (mPlanner) { - mPlanner->renderCachedSets(getState(), refreshArgs.scheduledFrameTime, - getState().usesDeviceComposition || getSkipColorTransform()); + const auto& outputState = getState(); + if (mPlanner && outputState.isEnabled) { + mPlanner->renderCachedSets(outputState, refreshArgs.scheduledFrameTime, + outputState.usesDeviceComposition || getSkipColorTransform()); } } diff --git a/services/surfaceflinger/FrontEnd/LayerHierarchy.cpp b/services/surfaceflinger/FrontEnd/LayerHierarchy.cpp index c30465fbd4..5913d4b589 100644 --- a/services/surfaceflinger/FrontEnd/LayerHierarchy.cpp +++ b/services/surfaceflinger/FrontEnd/LayerHierarchy.cpp @@ -30,7 +30,7 @@ auto layerZCompare = [](const std::pair<LayerHierarchy*, LayerHierarchy::Variant auto lhsLayer = lhs.first->getLayer(); auto rhsLayer = rhs.first->getLayer(); if (lhsLayer->layerStack.id != rhsLayer->layerStack.id) { - return lhsLayer->layerStack.id > rhsLayer->layerStack.id; + return lhsLayer->layerStack.id < rhsLayer->layerStack.id; } if (lhsLayer->z != rhsLayer->z) { return lhsLayer->z < rhsLayer->z; diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp index 25cbe7ae54..ce7d37e69b 100644 --- a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp +++ b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp @@ -817,7 +817,8 @@ void LayerSnapshotBuilder::updateSnapshot(LayerSnapshot& snapshot, const Args& a snapshot.frameRateSelectionPriority = requested.frameRateSelectionPriority; } - if (forceUpdate || snapshot.changes.any(RequestedLayerState::Changes::Content)) { + if (forceUpdate || snapshot.changes.any(RequestedLayerState::Changes::Content) || + snapshot.changes.any(RequestedLayerState::Changes::AffectsChildren)) { snapshot.color.rgb = requested.getColor().rgb; snapshot.isColorspaceAgnostic = requested.colorSpaceAgnostic; snapshot.backgroundBlurRadius = args.supportsBlur @@ -1069,6 +1070,10 @@ void LayerSnapshotBuilder::updateInput(LayerSnapshot& snapshot, // touches from going outside the cloned area. if (path.isClone()) { snapshot.inputInfo.inputConfig |= gui::WindowInfo::InputConfig::CLONE; + // Cloned layers shouldn't handle watch outside since their z order is not determined by + // WM or the client. + snapshot.inputInfo.inputConfig.clear(gui::WindowInfo::InputConfig::WATCH_OUTSIDE_TOUCH); + mNeedsTouchableRegionCrop.insert(path); } } diff --git a/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp b/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp index 4dcdd964b3..b397b82a27 100644 --- a/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp +++ b/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp @@ -32,10 +32,6 @@ using ftl::Flags; using namespace ftl::flag_operators; namespace { -std::string layerIdToString(uint32_t layerId) { - return layerId == UNASSIGNED_LAYER_ID ? "none" : std::to_string(layerId); -} - std::string layerIdsToString(const std::vector<uint32_t>& layerIds) { std::stringstream stream; stream << "{"; @@ -326,9 +322,13 @@ ui::Transform RequestedLayerState::getTransform(uint32_t displayRotationFlags) c std::string RequestedLayerState::getDebugString() const { std::stringstream debug; - debug << "RequestedLayerState{" << name << " parent=" << layerIdToString(parentId) - << " relativeParent=" << layerIdToString(relativeParentId) - << " mirrorId=" << layerIdsToString(mirrorIds) << " handle=" << handleAlive << " z=" << z; + debug << "RequestedLayerState{" << name; + if (parentId != UNASSIGNED_LAYER_ID) debug << " parentId=" << parentId; + if (relativeParentId != UNASSIGNED_LAYER_ID) debug << " relativeParentId=" << relativeParentId; + if (!mirrorIds.empty()) debug << " mirrorId=" << layerIdsToString(mirrorIds); + if (!handleAlive) debug << " !handle"; + if (z != 0) debug << " z=" << z; + if (layerStack.id != 0) debug << " layerStack=" << layerStack.id; return debug.str(); } diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp index 3e12db61e7..8ddcfa1ee6 100644 --- a/services/surfaceflinger/Scheduler/Scheduler.cpp +++ b/services/surfaceflinger/Scheduler/Scheduler.cpp @@ -130,7 +130,7 @@ void Scheduler::registerDisplayInternal(PhysicalDisplayId displayId, pacesetterVsyncSchedule = promotePacesetterDisplayLocked(); } - applyNewVsyncSchedule(std::move(pacesetterVsyncSchedule)); + applyNewVsyncScheduleIfNonNull(std::move(pacesetterVsyncSchedule)); } void Scheduler::unregisterDisplay(PhysicalDisplayId displayId) { @@ -149,7 +149,7 @@ void Scheduler::unregisterDisplay(PhysicalDisplayId displayId) { pacesetterVsyncSchedule = promotePacesetterDisplayLocked(); } - applyNewVsyncSchedule(std::move(pacesetterVsyncSchedule)); + applyNewVsyncScheduleIfNonNull(std::move(pacesetterVsyncSchedule)); } void Scheduler::run() { @@ -693,16 +693,17 @@ void Scheduler::promotePacesetterDisplay(std::optional<PhysicalDisplayId> pacese pacesetterVsyncSchedule = promotePacesetterDisplayLocked(pacesetterIdOpt); } - applyNewVsyncSchedule(std::move(pacesetterVsyncSchedule)); + applyNewVsyncScheduleIfNonNull(std::move(pacesetterVsyncSchedule)); } std::shared_ptr<VsyncSchedule> Scheduler::promotePacesetterDisplayLocked( std::optional<PhysicalDisplayId> pacesetterIdOpt) { // TODO(b/241286431): Choose the pacesetter display. + const auto oldPacesetterDisplayIdOpt = mPacesetterDisplayId; mPacesetterDisplayId = pacesetterIdOpt.value_or(mRefreshRateSelectors.begin()->first); ALOGI("Display %s is the pacesetter", to_string(*mPacesetterDisplayId).c_str()); - auto vsyncSchedule = getVsyncScheduleLocked(*mPacesetterDisplayId); + auto newVsyncSchedule = getVsyncScheduleLocked(*mPacesetterDisplayId); if (const auto pacesetterPtr = pacesetterSelectorPtrLocked()) { pacesetterPtr->setIdleTimerCallbacks( {.platform = {.onReset = [this] { idleTimerCallback(TimerState::Reset); }, @@ -713,15 +714,28 @@ std::shared_ptr<VsyncSchedule> Scheduler::promotePacesetterDisplayLocked( pacesetterPtr->startIdleTimer(); + // Track the new period, which may have changed due to switching to a + // new pacesetter or due to a hotplug event. In the former case, this + // is important so that VSYNC modulation does not get stuck in the + // initiated state if a transition started on the old pacesetter. const Fps refreshRate = pacesetterPtr->getActiveMode().modePtr->getFps(); - vsyncSchedule->startPeriodTransition(mSchedulerCallback, refreshRate.getPeriod(), - true /* force */); + newVsyncSchedule->startPeriodTransition(mSchedulerCallback, refreshRate.getPeriod(), + true /* force */); } - return vsyncSchedule; + if (oldPacesetterDisplayIdOpt == mPacesetterDisplayId) { + return nullptr; + } + return newVsyncSchedule; } -void Scheduler::applyNewVsyncSchedule(std::shared_ptr<VsyncSchedule> vsyncSchedule) { - onNewVsyncSchedule(vsyncSchedule->getDispatch()); +void Scheduler::applyNewVsyncScheduleIfNonNull( + std::shared_ptr<VsyncSchedule> pacesetterSchedulePtr) { + if (!pacesetterSchedulePtr) { + // The pacesetter has not changed, so there is no new VsyncSchedule to + // apply. + return; + } + onNewVsyncSchedule(pacesetterSchedulePtr->getDispatch()); std::vector<android::EventThread*> threads; { std::lock_guard<std::mutex> lock(mConnectionsLock); @@ -731,7 +745,7 @@ void Scheduler::applyNewVsyncSchedule(std::shared_ptr<VsyncSchedule> vsyncSchedu } } for (auto* thread : threads) { - thread->onNewVsyncSchedule(vsyncSchedule); + thread->onNewVsyncSchedule(pacesetterSchedulePtr); } } diff --git a/services/surfaceflinger/Scheduler/Scheduler.h b/services/surfaceflinger/Scheduler/Scheduler.h index 3423652163..720a1cbba2 100644 --- a/services/surfaceflinger/Scheduler/Scheduler.h +++ b/services/surfaceflinger/Scheduler/Scheduler.h @@ -329,10 +329,12 @@ private: // MessageQueue and EventThread need to use the new pacesetter's // VsyncSchedule, and this must happen while mDisplayLock is *not* locked, // or else we may deadlock with EventThread. + // Returns the new pacesetter's VsyncSchedule, or null if the pacesetter is + // unchanged. std::shared_ptr<VsyncSchedule> promotePacesetterDisplayLocked( std::optional<PhysicalDisplayId> pacesetterIdOpt = std::nullopt) REQUIRES(kMainThreadContext, mDisplayLock); - void applyNewVsyncSchedule(std::shared_ptr<VsyncSchedule>) EXCLUDES(mDisplayLock); + void applyNewVsyncScheduleIfNonNull(std::shared_ptr<VsyncSchedule>) EXCLUDES(mDisplayLock); // Blocks until the pacesetter's idle timer thread exits. `mDisplayLock` must not be locked by // the caller on the main thread to avoid deadlock, since the timer thread locks it before exit. diff --git a/services/surfaceflinger/TEST_MAPPING b/services/surfaceflinger/TEST_MAPPING index 57752b7a39..155a27531b 100644 --- a/services/surfaceflinger/TEST_MAPPING +++ b/services/surfaceflinger/TEST_MAPPING @@ -7,6 +7,14 @@ "name": "libcompositionengine_test" }, { + "name": "libgui_test", + "options": [ + { + "native-test-flag": "--gtest_filter=\"InputSurfacesTest*:MultiDisplayTests*\"" + } + ] + }, + { "name": "libscheduler_test" } ], diff --git a/services/surfaceflinger/tests/unittests/LayerHierarchyTest.cpp b/services/surfaceflinger/tests/unittests/LayerHierarchyTest.cpp index ddf3363244..88d39db17d 100644 --- a/services/surfaceflinger/tests/unittests/LayerHierarchyTest.cpp +++ b/services/surfaceflinger/tests/unittests/LayerHierarchyTest.cpp @@ -662,10 +662,9 @@ TEST_F(LayerHierarchyTest, zorderRespectsLayerStack) { mLifecycleManager.commitChanges(); LayerHierarchyBuilder hierarchyBuilder(mLifecycleManager.getLayers()); UPDATE_AND_VERIFY(hierarchyBuilder); - std::vector<uint32_t> expectedTraversalPath = {1, 11, 2, 21}; + std::vector<uint32_t> expectedTraversalPath = {2, 21, 1, 11}; EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expectedTraversalPath); - expectedTraversalPath = {1, 11, 2, 21}; EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expectedTraversalPath); expectedTraversalPath = {}; EXPECT_EQ(getTraversalPath(hierarchyBuilder.getOffscreenHierarchy()), expectedTraversalPath); @@ -678,8 +677,8 @@ TEST_F(LayerHierarchyTest, canMirrorDisplay) { setLayerStack(3, 1); UPDATE_AND_VERIFY(hierarchyBuilder); - std::vector<uint32_t> expected = {3, 1, 11, 111, 12, 121, 122, 1221, 13, 2, - 1, 11, 111, 12, 121, 122, 1221, 13, 2}; + std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3, + 1, 11, 111, 12, 121, 122, 1221, 13, 2}; EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expected); EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expected); expected = {}; @@ -693,7 +692,7 @@ TEST_F(LayerHierarchyTest, mirrorNonExistingDisplay) { setLayerStack(3, 1); UPDATE_AND_VERIFY(hierarchyBuilder); - std::vector<uint32_t> expected = {3, 1, 11, 111, 12, 121, 122, 1221, 13, 2}; + std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3}; EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expected); EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expected); expected = {}; @@ -710,8 +709,8 @@ TEST_F(LayerHierarchyTest, newRootLayerIsMirrored) { createRootLayer(4); UPDATE_AND_VERIFY(hierarchyBuilder); - std::vector<uint32_t> expected = {3, 1, 11, 111, 12, 121, 122, 1221, 13, 2, 4, - 1, 11, 111, 12, 121, 122, 1221, 13, 2, 4}; + std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 4, 3, + 1, 11, 111, 12, 121, 122, 1221, 13, 2, 4}; EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expected); EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expected); expected = {}; @@ -729,7 +728,7 @@ TEST_F(LayerHierarchyTest, removedRootLayerIsNoLongerMirrored) { destroyLayerHandle(1); UPDATE_AND_VERIFY(hierarchyBuilder); - std::vector<uint32_t> expected = {3, 2, 2}; + std::vector<uint32_t> expected = {2, 3, 2}; EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()), expected); EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()), expected); expected = {11, 111, 12, 121, 122, 1221, 13}; diff --git a/services/surfaceflinger/tests/unittests/LayerHierarchyTest.h b/services/surfaceflinger/tests/unittests/LayerHierarchyTest.h index 79cfd6a891..43011863ff 100644 --- a/services/surfaceflinger/tests/unittests/LayerHierarchyTest.h +++ b/services/surfaceflinger/tests/unittests/LayerHierarchyTest.h @@ -297,6 +297,17 @@ protected: mLifecycleManager.applyTransactions(transactions); } + void setBackgroundBlurRadius(uint32_t id, uint32_t backgroundBlurRadius) { + std::vector<TransactionState> transactions; + transactions.emplace_back(); + transactions.back().states.push_back({}); + + transactions.back().states.front().state.what = layer_state_t::eBackgroundBlurRadiusChanged; + transactions.back().states.front().layerId = id; + transactions.back().states.front().state.backgroundBlurRadius = backgroundBlurRadius; + mLifecycleManager.applyTransactions(transactions); + } + LayerLifecycleManager mLifecycleManager; }; diff --git a/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp b/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp index 5a066a6482..b8a7446b3a 100644 --- a/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp +++ b/services/surfaceflinger/tests/unittests/LayerSnapshotTest.cpp @@ -79,6 +79,7 @@ protected: .displays = mFrontEndDisplayInfos, .displayChanges = hasDisplayChanges, .globalShadowSettings = globalShadowSettings, + .supportsBlur = true, .supportedLayerGenericMetadata = {}, .genericLayerMetadataKeyMap = {}}; actualBuilder.update(args); @@ -333,6 +334,19 @@ TEST_F(LayerSnapshotTest, canCropTouchableRegion) { EXPECT_EQ(getSnapshot({.id = 111})->inputInfo.touchableRegion.bounds(), modifiedTouchCrop); } +TEST_F(LayerSnapshotTest, blurUpdatesWhenAlphaChanges) { + static constexpr int blurRadius = 42; + setBackgroundBlurRadius(1221, blurRadius); + + UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); + EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius); + + static constexpr float alpha = 0.5; + setAlpha(12, alpha); + UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); + EXPECT_EQ(getSnapshot({.id = 1221})->backgroundBlurRadius, blurRadius * alpha); +} + // Display Mirroring Tests // tree with 3 levels of children // ROOT (DISPLAY 0) @@ -352,7 +366,7 @@ TEST_F(LayerSnapshotTest, displayMirrorRespectsLayerSkipScreenshotFlag) { createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); setLayerStack(3, 1); - std::vector<uint32_t> expected = {3, 1, 11, 111, 13, 2, 1, 11, 111, 12, 121, 122, 1221, 13, 2}; + std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3, 1, 11, 111, 13, 2}; UPDATE_AND_VERIFY(mSnapshotBuilder, expected); } @@ -371,8 +385,8 @@ TEST_F(LayerSnapshotTest, mirrorLayerGetsCorrectLayerStack) { createDisplayMirrorLayer(4, ui::LayerStack::fromValue(0)); setLayerStack(4, 4); - std::vector<uint32_t> expected = {4, 1, 11, 111, 13, 2, 3, 1, 11, - 111, 13, 2, 1, 11, 111, 13, 2}; + std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111, + 13, 2, 4, 1, 11, 111, 13, 2}; UPDATE_AND_VERIFY(mSnapshotBuilder, expected); EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootId = 3})->outputFilter.layerStack.id, 3u); EXPECT_EQ(getSnapshot({.id = 111, .mirrorRootId = 4})->outputFilter.layerStack.id, 4u); @@ -395,7 +409,7 @@ TEST_F(LayerSnapshotTest, mirrorLayerTouchIsCroppedByMirrorRoot) { setCrop(111, Rect{200, 200}); Region touch{Rect{0, 0, 1000, 1000}}; setTouchableRegion(111, touch); - std::vector<uint32_t> expected = {3, 1, 11, 111, 13, 2, 1, 11, 111, 13, 2}; + std::vector<uint32_t> expected = {1, 11, 111, 13, 2, 3, 1, 11, 111, 13, 2}; UPDATE_AND_VERIFY(mSnapshotBuilder, expected); EXPECT_TRUE(getSnapshot({.id = 111})->inputInfo.touchableRegion.hasSameRects(touch)); Region touchCroppedByMirrorRoot{Rect{0, 0, 50, 50}}; @@ -407,7 +421,7 @@ TEST_F(LayerSnapshotTest, canRemoveDisplayMirror) { setFlags(12, layer_state_t::eLayerSkipScreenshot, layer_state_t::eLayerSkipScreenshot); createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); setLayerStack(3, 1); - std::vector<uint32_t> expected = {3, 1, 11, 111, 13, 2, 1, 11, 111, 12, 121, 122, 1221, 13, 2}; + std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3, 1, 11, 111, 13, 2}; UPDATE_AND_VERIFY(mSnapshotBuilder, expected); destroyLayerHandle(3); UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); @@ -417,8 +431,8 @@ TEST_F(LayerSnapshotTest, cleanUpUnreachableSnapshotsAfterMirroring) { size_t startingNumSnapshots = mSnapshotBuilder.getSnapshots().size(); createDisplayMirrorLayer(3, ui::LayerStack::fromValue(0)); setLayerStack(3, 1); - std::vector<uint32_t> expected = {3, 1, 11, 111, 12, 121, 122, 1221, 13, 2, - 1, 11, 111, 12, 121, 122, 1221, 13, 2}; + std::vector<uint32_t> expected = {1, 11, 111, 12, 121, 122, 1221, 13, 2, 3, + 1, 11, 111, 12, 121, 122, 1221, 13, 2}; UPDATE_AND_VERIFY(mSnapshotBuilder, expected); destroyLayerHandle(3); UPDATE_AND_VERIFY(mSnapshotBuilder, STARTING_ZORDER); diff --git a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp index dc76b4c90f..0c43831455 100644 --- a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp +++ b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp @@ -384,4 +384,23 @@ TEST_F(SchedulerTest, chooseDisplayModesMultipleDisplays) { } } +TEST_F(SchedulerTest, changingPacesetterChangesVsyncSchedule) { + // Add a second display so we can change the pacesetter. + mScheduler->registerDisplay(kDisplayId2, + std::make_shared<RefreshRateSelector>(kDisplay2Modes, + kDisplay2Mode60->getId())); + // Ensure that the pacesetter is the one we expect. + mScheduler->setPacesetterDisplay(kDisplayId1); + + // Switching to the other will call onNewVsyncSchedule. + EXPECT_CALL(*mEventThread, onNewVsyncSchedule(mScheduler->getVsyncSchedule(kDisplayId2))) + .Times(1); + mScheduler->setPacesetterDisplay(kDisplayId2); +} + +TEST_F(SchedulerTest, promotingSamePacesetterDoesNotChangeVsyncSchedule) { + EXPECT_CALL(*mEventThread, onNewVsyncSchedule(_)).Times(0); + mScheduler->setPacesetterDisplay(kDisplayId1); +} + } // namespace android::scheduler |