diff options
73 files changed, 340 insertions, 656 deletions
diff --git a/cmds/installd/InstalldNativeService.cpp b/cmds/installd/InstalldNativeService.cpp index 2c8adc7126..a278a48135 100644 --- a/cmds/installd/InstalldNativeService.cpp +++ b/cmds/installd/InstalldNativeService.cpp @@ -99,6 +99,8 @@ static constexpr const char* kXattrDefault = "user.default"; static constexpr const char* kDataMirrorCePath = "/data_mirror/data_ce"; static constexpr const char* kDataMirrorDePath = "/data_mirror/data_de"; +static constexpr const char* kMiscMirrorCePath = "/data_mirror/misc_ce"; +static constexpr const char* kMiscMirrorDePath = "/data_mirror/misc_de"; static constexpr const int MIN_RESTRICTED_HOME_SDK_VERSION = 24; // > M @@ -3579,16 +3581,28 @@ binder::Status InstalldNativeService::tryMountDataMirror( std::string mirrorVolCePath(StringPrintf("%s/%s", kDataMirrorCePath, uuid_)); if (fs_prepare_dir(mirrorVolCePath.c_str(), 0711, AID_SYSTEM, AID_SYSTEM) != 0) { - return error("Failed to create CE mirror"); + return error("Failed to create CE data mirror"); } std::string mirrorVolDePath(StringPrintf("%s/%s", kDataMirrorDePath, uuid_)); if (fs_prepare_dir(mirrorVolDePath.c_str(), 0711, AID_SYSTEM, AID_SYSTEM) != 0) { - return error("Failed to create DE mirror"); + return error("Failed to create DE data mirror"); + } + + std::string mirrorVolMiscCePath(StringPrintf("%s/%s", kMiscMirrorCePath, uuid_)); + if (fs_prepare_dir(mirrorVolMiscCePath.c_str(), 0711, AID_SYSTEM, AID_SYSTEM) != 0) { + return error("Failed to create CE misc mirror"); + } + + std::string mirrorVolMiscDePath(StringPrintf("%s/%s", kMiscMirrorDePath, uuid_)); + if (fs_prepare_dir(mirrorVolMiscDePath.c_str(), 0711, AID_SYSTEM, AID_SYSTEM) != 0) { + return error("Failed to create DE misc mirror"); } auto cePath = StringPrintf("%s/user", create_data_path(uuid_).c_str()); auto dePath = StringPrintf("%s/user_de", create_data_path(uuid_).c_str()); + auto miscCePath = StringPrintf("%s/misc_ce", create_data_path(uuid_).c_str()); + auto miscDePath = StringPrintf("%s/misc_de", create_data_path(uuid_).c_str()); if (access(cePath.c_str(), F_OK) != 0) { return error("Cannot access CE path: " + cePath); @@ -3596,6 +3610,12 @@ binder::Status InstalldNativeService::tryMountDataMirror( if (access(dePath.c_str(), F_OK) != 0) { return error("Cannot access DE path: " + dePath); } + if (access(miscCePath.c_str(), F_OK) != 0) { + return error("Cannot access misc CE path: " + cePath); + } + if (access(miscDePath.c_str(), F_OK) != 0) { + return error("Cannot access misc DE path: " + dePath); + } struct stat ceStat, mirrorCeStat; if (stat(cePath.c_str(), &ceStat) != 0) { @@ -3623,6 +3643,21 @@ binder::Status InstalldNativeService::tryMountDataMirror( MS_NOSUID | MS_NODEV | MS_NOATIME | MS_BIND | MS_NOEXEC, nullptr)) == -1) { return error("Failed to mount " + mirrorVolDePath); } + + // Mount misc CE mirror + if (TEMP_FAILURE_RETRY(mount(miscCePath.c_str(), mirrorVolMiscCePath.c_str(), NULL, + MS_NOSUID | MS_NODEV | MS_NOATIME | MS_BIND | MS_NOEXEC, + nullptr)) == -1) { + return error("Failed to mount " + mirrorVolMiscCePath); + } + + // Mount misc DE mirror + if (TEMP_FAILURE_RETRY(mount(miscDePath.c_str(), mirrorVolMiscDePath.c_str(), NULL, + MS_NOSUID | MS_NODEV | MS_NOATIME | MS_BIND | MS_NOEXEC, + nullptr)) == -1) { + return error("Failed to mount " + mirrorVolMiscDePath); + } + return ok(); } @@ -3645,6 +3680,8 @@ binder::Status InstalldNativeService::onPrivateVolumeRemoved( std::string mirrorCeVolPath(StringPrintf("%s/%s", kDataMirrorCePath, uuid_)); std::string mirrorDeVolPath(StringPrintf("%s/%s", kDataMirrorDePath, uuid_)); + std::string mirrorMiscCeVolPath(StringPrintf("%s/%s", kMiscMirrorCePath, uuid_)); + std::string mirrorMiscDeVolPath(StringPrintf("%s/%s", kMiscMirrorDePath, uuid_)); std::lock_guard<std::recursive_mutex> lock(mMountsLock); @@ -3669,6 +3706,29 @@ binder::Status InstalldNativeService::onPrivateVolumeRemoved( if (delete_dir_contents_and_dir(mirrorDeVolPath, true) != 0) { res = error("Failed to delete " + mirrorDeVolPath); } + + // Unmount misc CE storage + if (TEMP_FAILURE_RETRY(umount(mirrorMiscCeVolPath.c_str())) != 0) { + if (errno != ENOENT) { + res = error(StringPrintf("Failed to umount %s %s", mirrorMiscCeVolPath.c_str(), + strerror(errno))); + } + } + if (delete_dir_contents_and_dir(mirrorMiscCeVolPath, true) != 0) { + res = error("Failed to delete " + mirrorMiscCeVolPath); + } + + // Unmount misc DE storage + if (TEMP_FAILURE_RETRY(umount(mirrorMiscDeVolPath.c_str())) != 0) { + if (errno != ENOENT) { + res = error(StringPrintf("Failed to umount %s %s", mirrorMiscDeVolPath.c_str(), + strerror(errno))); + } + } + if (delete_dir_contents_and_dir(mirrorMiscDeVolPath, true) != 0) { + res = error("Failed to delete " + mirrorMiscDeVolPath); + } + return res; } diff --git a/cmds/servicemanager/ServiceManagerFuzzer.cpp b/cmds/servicemanager/ServiceManagerFuzzer.cpp index 39f8522f84..bc48fa920e 100644 --- a/cmds/servicemanager/ServiceManagerFuzzer.cpp +++ b/cmds/servicemanager/ServiceManagerFuzzer.cpp @@ -26,9 +26,15 @@ using ::android::ServiceManager; using ::android::sp; extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + FuzzedDataProvider provider(data, size); + + // Adding this random abort to check bug pipeline. + bool shouldAbort = provider.ConsumeBool(); + if (shouldAbort) abort(); + auto accessPtr = std::make_unique<Access>(); auto serviceManager = sp<ServiceManager>::make(std::move(accessPtr)); - fuzzService(serviceManager, FuzzedDataProvider(data, size)); + fuzzService(serviceManager, std::move(provider)); return 0; } diff --git a/include/input/DisplayViewport.h b/include/input/DisplayViewport.h index 9148fee532..98a18c9560 100644 --- a/include/input/DisplayViewport.h +++ b/include/input/DisplayViewport.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef _LIBINPUT_DISPLAY_VIEWPORT_H -#define _LIBINPUT_DISPLAY_VIEWPORT_H +#pragma once #include <android-base/stringprintf.h> #include <ftl/enum.h> @@ -144,5 +143,3 @@ struct DisplayViewport { }; } // namespace android - -#endif // _LIBINPUT_DISPLAY_VIEWPORT_H diff --git a/include/input/Input.h b/include/input/Input.h index a3c9f33f33..2dd651e9d7 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef _LIBINPUT_INPUT_H -#define _LIBINPUT_INPUT_H +#pragma once #pragma GCC system_header @@ -1104,5 +1103,3 @@ enum class PointerIconStyle : int32_t { }; } // namespace android - -#endif // _LIBINPUT_INPUT_H diff --git a/include/input/InputDevice.h b/include/input/InputDevice.h index d51d6a722a..415080d15d 100644 --- a/include/input/InputDevice.h +++ b/include/input/InputDevice.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef _LIBINPUT_INPUT_DEVICE_H -#define _LIBINPUT_INPUT_DEVICE_H +#pragma once #include <android/sensor.h> #include <input/Input.h> @@ -341,5 +340,3 @@ enum ReservedInputDeviceId : int32_t { }; } // namespace android - -#endif // _LIBINPUT_INPUT_DEVICE_H diff --git a/include/input/InputEventLabels.h b/include/input/InputEventLabels.h index 2a742f9cf4..b4374acdcc 100644 --- a/include/input/InputEventLabels.h +++ b/include/input/InputEventLabels.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef _LIBINPUT_INPUT_EVENT_LABELS_H -#define _LIBINPUT_INPUT_EVENT_LABELS_H +#pragma once #include <input/Input.h> #include <android/keycodes.h> @@ -68,4 +67,3 @@ private: }; } // namespace android -#endif // _LIBINPUT_INPUT_EVENT_LABELS_H diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h index dbc7bfa388..1c52792cf6 100644 --- a/include/input/InputTransport.h +++ b/include/input/InputTransport.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef _LIBINPUT_INPUT_TRANSPORT_H -#define _LIBINPUT_INPUT_TRANSPORT_H +#pragma once #pragma GCC system_header @@ -674,5 +673,3 @@ private: }; } // namespace android - -#endif // _LIBINPUT_INPUT_TRANSPORT_H diff --git a/include/input/KeyCharacterMap.h b/include/input/KeyCharacterMap.h index 1c9a5eaac1..dc928b806f 100644 --- a/include/input/KeyCharacterMap.h +++ b/include/input/KeyCharacterMap.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef _LIBINPUT_KEY_CHARACTER_MAP_H -#define _LIBINPUT_KEY_CHARACTER_MAP_H +#pragma once #include <stdint.h> #include <list> @@ -270,5 +269,3 @@ private: }; } // namespace android - -#endif // _LIBINPUT_KEY_CHARACTER_MAP_H diff --git a/include/input/KeyLayoutMap.h b/include/input/KeyLayoutMap.h index a6c696df26..e203d190a6 100644 --- a/include/input/KeyLayoutMap.h +++ b/include/input/KeyLayoutMap.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef _LIBINPUT_KEY_LAYOUT_MAP_H -#define _LIBINPUT_KEY_LAYOUT_MAP_H +#pragma once #include <android-base/result.h> #include <stdint.h> @@ -131,5 +130,3 @@ private: }; } // namespace android - -#endif // _LIBINPUT_KEY_LAYOUT_MAP_H diff --git a/include/input/Keyboard.h b/include/input/Keyboard.h index 9a3e15f1cd..f7f960f8e6 100644 --- a/include/input/Keyboard.h +++ b/include/input/Keyboard.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef _LIBINPUT_KEYBOARD_H -#define _LIBINPUT_KEYBOARD_H +#pragma once #include <input/Input.h> #include <input/InputDevice.h> @@ -88,5 +87,3 @@ extern int32_t normalizeMetaState(int32_t oldMetaState); extern bool isMetaKey(int32_t keyCode); } // namespace android - -#endif // _LIBINPUT_KEYBOARD_H diff --git a/include/input/PropertyMap.h b/include/input/PropertyMap.h index b1e3f85ed5..28e4816afe 100644 --- a/include/input/PropertyMap.h +++ b/include/input/PropertyMap.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef _UTILS_PROPERTY_MAP_H -#define _UTILS_PROPERTY_MAP_H +#pragma once #include <android-base/result.h> #include <utils/Tokenizer.h> @@ -98,5 +97,3 @@ private: }; } // namespace android - -#endif // _UTILS_PROPERTY_MAP_H diff --git a/include/input/TouchVideoFrame.h b/include/input/TouchVideoFrame.h index eda628e233..a616a95ab1 100644 --- a/include/input/TouchVideoFrame.h +++ b/include/input/TouchVideoFrame.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef _LIBINPUT_TOUCHVIDEOFRAME_H -#define _LIBINPUT_TOUCHVIDEOFRAME_H +#pragma once #include <stdint.h> #include <sys/time.h> @@ -75,5 +74,3 @@ private: }; } // namespace android - -#endif // _LIBINPUT_TOUCHVIDEOFRAME_H diff --git a/include/input/VelocityControl.h b/include/input/VelocityControl.h index f4c7061ad1..f72a1bdded 100644 --- a/include/input/VelocityControl.h +++ b/include/input/VelocityControl.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef _LIBINPUT_VELOCITY_CONTROL_H -#define _LIBINPUT_VELOCITY_CONTROL_H +#pragma once #include <input/Input.h> #include <input/VelocityTracker.h> @@ -103,5 +102,3 @@ private: }; } // namespace android - -#endif // _LIBINPUT_VELOCITY_CONTROL_H diff --git a/include/input/VelocityTracker.h b/include/input/VelocityTracker.h index da4d877d0f..4251f0417d 100644 --- a/include/input/VelocityTracker.h +++ b/include/input/VelocityTracker.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef _LIBINPUT_VELOCITY_TRACKER_H -#define _LIBINPUT_VELOCITY_TRACKER_H +#pragma once #include <input/Input.h> #include <utils/BitSet.h> @@ -347,5 +346,3 @@ private: }; } // namespace android - -#endif // _LIBINPUT_VELOCITY_TRACKER_H diff --git a/include/input/VirtualKeyMap.h b/include/input/VirtualKeyMap.h index 6e8e2c9cf4..a4381eaab9 100644 --- a/include/input/VirtualKeyMap.h +++ b/include/input/VirtualKeyMap.h @@ -14,8 +14,7 @@ * limitations under the License. */ -#ifndef _LIBINPUT_VIRTUAL_KEY_MAP_H -#define _LIBINPUT_VIRTUAL_KEY_MAP_H +#pragma once #include <stdint.h> @@ -77,5 +76,3 @@ private: }; } // namespace android - -#endif // _LIBINPUT_KEY_CHARACTER_MAP_H diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp index b50cfb3d19..bfcf39ad30 100644 --- a/libs/binder/IPCThreadState.cpp +++ b/libs/binder/IPCThreadState.cpp @@ -1318,6 +1318,13 @@ status_t IPCThreadState::executeCommand(int32_t cmd) LOG_ONEWAY("Sending reply to %d!", mCallingPid); if (error < NO_ERROR) reply.setError(error); + // b/238777741: clear buffer before we send the reply. + // Otherwise, there is a race where the client may + // receive the reply and send another transaction + // here and the space used by this transaction won't + // be freed for the client. + buffer.setDataSize(0); + constexpr uint32_t kForwardReplyFlags = TF_CLEAR_BUF; sendReply(reply, (tr.flags & kForwardReplyFlags)); } else { diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp index c0a8d74195..5db3eef392 100644 --- a/libs/binder/IServiceManager.cpp +++ b/libs/binder/IServiceManager.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_TAG "ServiceManager" +#define LOG_TAG "ServiceManagerCppClient" #include <binder/IServiceManager.h> diff --git a/libs/binder/tests/binderLibTest.cpp b/libs/binder/tests/binderLibTest.cpp index 5de08bdc00..6e1c8ac16a 100644 --- a/libs/binder/tests/binderLibTest.cpp +++ b/libs/binder/tests/binderLibTest.cpp @@ -1161,8 +1161,7 @@ TEST_F(BinderLibTest, VectorSent) { // see ProcessState.cpp BINDER_VM_SIZE = 1MB. // This value is not exposed, but some code in the framework relies on being able to use // buffers near the cap size. -// TODO(b/238777741): why do larger values, like 300K fail sometimes -constexpr size_t kSizeBytesAlmostFull = 100'000; +constexpr size_t kSizeBytesAlmostFull = 950'000; constexpr size_t kSizeBytesOverFull = 1'050'000; TEST_F(BinderLibTest, GargantuanVectorSent) { diff --git a/libs/input/Input.cpp b/libs/input/Input.cpp index 155cb040fb..2b7483d27d 100644 --- a/libs/input/Input.cpp +++ b/libs/input/Input.cpp @@ -949,6 +949,8 @@ std::ostream& operator<<(std::ostream& out, const MotionEvent& event) { out << ", actionButton=" << std::to_string(event.getActionButton()); } const size_t pointerCount = event.getPointerCount(); + LOG_ALWAYS_FATAL_IF(pointerCount > MAX_POINTERS, "Too many pointers : pointerCount = %zu", + pointerCount); for (size_t i = 0; i < pointerCount; i++) { out << ", id[" << i << "]=" << event.getPointerId(i); float x = event.getX(i); diff --git a/libs/renderengine/tests/RenderEngineTest.cpp b/libs/renderengine/tests/RenderEngineTest.cpp index 9d8b2df98a..777d02f415 100644 --- a/libs/renderengine/tests/RenderEngineTest.cpp +++ b/libs/renderengine/tests/RenderEngineTest.cpp @@ -37,7 +37,6 @@ #include <condition_variable> #include <fstream> -#include "../gl/GLESRenderEngine.h" #include "../skia/SkiaGLRenderEngine.h" #include "../threaded/RenderEngineThreaded.h" @@ -108,73 +107,9 @@ public: virtual std::string name() = 0; virtual renderengine::RenderEngine::RenderEngineType type() = 0; virtual std::unique_ptr<renderengine::RenderEngine> createRenderEngine() = 0; - virtual std::unique_ptr<renderengine::gl::GLESRenderEngine> createGLESRenderEngine() { - return nullptr; - } virtual bool useColorManagement() const = 0; }; -class GLESRenderEngineFactory : public RenderEngineFactory { -public: - std::string name() override { return "GLESRenderEngineFactory"; } - - renderengine::RenderEngine::RenderEngineType type() { - return renderengine::RenderEngine::RenderEngineType::GLES; - } - - std::unique_ptr<renderengine::RenderEngine> createRenderEngine() override { - return createGLESRenderEngine(); - } - - std::unique_ptr<renderengine::gl::GLESRenderEngine> createGLESRenderEngine() { - renderengine::RenderEngineCreationArgs reCreationArgs = - renderengine::RenderEngineCreationArgs::Builder() - .setPixelFormat(static_cast<int>(ui::PixelFormat::RGBA_8888)) - .setImageCacheSize(1) - .setUseColorManagerment(false) - .setEnableProtectedContext(false) - .setPrecacheToneMapperShaderOnly(false) - .setSupportsBackgroundBlur(true) - .setContextPriority(renderengine::RenderEngine::ContextPriority::MEDIUM) - .setRenderEngineType(type()) - .setUseColorManagerment(useColorManagement()) - .build(); - return renderengine::gl::GLESRenderEngine::create(reCreationArgs); - } - - bool useColorManagement() const override { return false; } -}; - -class GLESCMRenderEngineFactory : public RenderEngineFactory { -public: - std::string name() override { return "GLESCMRenderEngineFactory"; } - - renderengine::RenderEngine::RenderEngineType type() { - return renderengine::RenderEngine::RenderEngineType::GLES; - } - - std::unique_ptr<renderengine::RenderEngine> createRenderEngine() override { - return createGLESRenderEngine(); - } - - std::unique_ptr<renderengine::gl::GLESRenderEngine> createGLESRenderEngine() override { - renderengine::RenderEngineCreationArgs reCreationArgs = - renderengine::RenderEngineCreationArgs::Builder() - .setPixelFormat(static_cast<int>(ui::PixelFormat::RGBA_8888)) - .setImageCacheSize(1) - .setEnableProtectedContext(false) - .setPrecacheToneMapperShaderOnly(false) - .setSupportsBackgroundBlur(true) - .setContextPriority(renderengine::RenderEngine::ContextPriority::MEDIUM) - .setRenderEngineType(type()) - .setUseColorManagerment(useColorManagement()) - .build(); - return renderengine::gl::GLESRenderEngine::create(reCreationArgs); - } - - bool useColorManagement() const override { return true; } -}; - class SkiaGLESRenderEngineFactory : public RenderEngineFactory { public: std::string name() override { return "SkiaGLRenderEngineFactory"; } @@ -313,9 +248,6 @@ public: } for (uint32_t texName : mTexNames) { mRE->deleteTextures(1, &texName); - if (mGLESRE != nullptr) { - EXPECT_FALSE(mGLESRE->isTextureNameKnownForTesting(texName)); - } } const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info(); @@ -537,10 +469,6 @@ public: auto fence = result.value(); fence->waitForever(LOG_TAG); - - if (layers.size() > 0 && mGLESRE != nullptr) { - ASSERT_TRUE(mGLESRE->isFramebufferImageCachedForTesting(mBuffer->getBuffer()->getId())); - } } void drawEmptyLayers() { @@ -663,26 +591,13 @@ public: std::unique_ptr<renderengine::RenderEngine> mRE; std::shared_ptr<renderengine::ExternalTexture> mBuffer; - // GLESRenderEngine for testing GLES-specific behavior. - // Owened by mRE, but this is downcasted. - renderengine::gl::GLESRenderEngine* mGLESRE = nullptr; std::vector<uint32_t> mTexNames; }; void RenderEngineTest::initializeRenderEngine() { const auto& renderEngineFactory = GetParam(); - if (renderEngineFactory->type() == renderengine::RenderEngine::RenderEngineType::GLES) { - // Only GLESRenderEngine exposes test-only methods. Provide a pointer to the - // GLESRenderEngine if we're using it so that we don't need to dynamic_cast - // every time. - std::unique_ptr<renderengine::gl::GLESRenderEngine> renderEngine = - renderEngineFactory->createGLESRenderEngine(); - mGLESRE = renderEngine.get(); - mRE = std::move(renderEngine); - } else { - mRE = renderEngineFactory->createRenderEngine(); - } + mRE = renderEngineFactory->createRenderEngine(); mBuffer = allocateDefaultBuffer(); } @@ -1003,9 +918,9 @@ void RenderEngineTest::fillBufferWithColorTransformAndSourceDataspace( std::vector<renderengine::LayerSettings> layers; renderengine::LayerSettings layer; - layer.sourceDataspace = sourceDataspace; layer.geometry.boundaries = Rect(1, 1).toFloatRect(); SourceVariant::fillColor(layer, 0.5f, 0.25f, 0.125f, this); + layer.sourceDataspace = sourceDataspace; layer.alpha = 1.0f; // construct a fake color matrix @@ -1031,13 +946,13 @@ void RenderEngineTest::fillBufferColorTransform() { template <typename SourceVariant> void RenderEngineTest::fillBufferColorTransformAndSourceDataspace() { unordered_map<ui::Dataspace, ubyte4> dataspaceToColorMap; - dataspaceToColorMap[ui::Dataspace::V0_BT709] = {172, 0, 0, 255}; - dataspaceToColorMap[ui::Dataspace::BT2020] = {172, 0, 0, 255}; - dataspaceToColorMap[ui::Dataspace::ADOBE_RGB] = {172, 0, 0, 255}; + dataspaceToColorMap[ui::Dataspace::V0_BT709] = {77, 0, 0, 255}; + dataspaceToColorMap[ui::Dataspace::BT2020] = {101, 0, 0, 255}; + dataspaceToColorMap[ui::Dataspace::ADOBE_RGB] = {75, 0, 0, 255}; ui::Dataspace customizedDataspace = static_cast<ui::Dataspace>( ui::Dataspace::STANDARD_BT709 | ui::Dataspace::TRANSFER_GAMMA2_2 | ui::Dataspace::RANGE_FULL); - dataspaceToColorMap[customizedDataspace] = {172, 0, 0, 255}; + dataspaceToColorMap[customizedDataspace] = {61, 0, 0, 255}; for (const auto& [sourceDataspace, color] : dataspaceToColorMap) { fillBufferWithColorTransformAndSourceDataspace<SourceVariant>(sourceDataspace); expectBufferColor(fullscreenRect(), color.r, color.g, color.b, color.a, 1); @@ -1077,13 +992,13 @@ void RenderEngineTest::fillBufferWithColorTransformAndOutputDataspace( template <typename SourceVariant> void RenderEngineTest::fillBufferColorTransformAndOutputDataspace() { unordered_map<ui::Dataspace, ubyte4> dataspaceToColorMap; - dataspaceToColorMap[ui::Dataspace::V0_BT709] = {202, 0, 0, 255}; - dataspaceToColorMap[ui::Dataspace::BT2020] = {192, 0, 0, 255}; - dataspaceToColorMap[ui::Dataspace::ADOBE_RGB] = {202, 0, 0, 255}; + dataspaceToColorMap[ui::Dataspace::V0_BT709] = {198, 0, 0, 255}; + dataspaceToColorMap[ui::Dataspace::BT2020] = {187, 0, 0, 255}; + dataspaceToColorMap[ui::Dataspace::ADOBE_RGB] = {192, 0, 0, 255}; ui::Dataspace customizedDataspace = static_cast<ui::Dataspace>( ui::Dataspace::STANDARD_BT709 | ui::Dataspace::TRANSFER_GAMMA2_6 | ui::Dataspace::RANGE_FULL); - dataspaceToColorMap[customizedDataspace] = {202, 0, 0, 255}; + dataspaceToColorMap[customizedDataspace] = {205, 0, 0, 255}; for (const auto& [outputDataspace, color] : dataspaceToColorMap) { fillBufferWithColorTransformAndOutputDataspace<SourceVariant>(outputDataspace); expectBufferColor(fullscreenRect(), color.r, color.g, color.b, color.a, 1); @@ -1599,9 +1514,7 @@ void RenderEngineTest::tonemap(ui::Dataspace sourceDataspace, std::function<vec3 } INSTANTIATE_TEST_SUITE_P(PerRenderEngineType, RenderEngineTest, - testing::Values(std::make_shared<GLESRenderEngineFactory>(), - std::make_shared<GLESCMRenderEngineFactory>(), - std::make_shared<SkiaGLESRenderEngineFactory>(), + testing::Values(std::make_shared<SkiaGLESRenderEngineFactory>(), std::make_shared<SkiaGLESCMRenderEngineFactory>())); TEST_P(RenderEngineTest, drawLayers_noLayersToDraw) { @@ -1610,12 +1523,6 @@ TEST_P(RenderEngineTest, drawLayers_noLayersToDraw) { } TEST_P(RenderEngineTest, drawLayers_fillRedBufferAndEmptyBuffer) { - const auto& renderEngineFactory = GetParam(); - if (renderEngineFactory->type() == renderengine::RenderEngine::RenderEngineType::GLES) { - // GLES-specific test - return; - } - initializeRenderEngine(); renderengine::DisplaySettings settings; settings.physicalDisplay = fullscreenRect(); @@ -1689,41 +1596,6 @@ TEST_P(RenderEngineTest, drawLayers_nullOutputBuffer) { ASSERT_EQ(BAD_VALUE, result.error()); } -TEST_P(RenderEngineTest, drawLayers_doesNotCacheFramebuffer) { - const auto& renderEngineFactory = GetParam(); - - if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { - // GLES-specific test - return; - } - - initializeRenderEngine(); - - renderengine::DisplaySettings settings; - settings.outputDataspace = ui::Dataspace::V0_SRGB_LINEAR; - settings.physicalDisplay = fullscreenRect(); - settings.clip = fullscreenRect(); - - std::vector<renderengine::LayerSettings> layers; - renderengine::LayerSettings layer; - layer.geometry.boundaries = fullscreenRect().toFloatRect(); - BufferSourceVariant<ForceOpaqueBufferVariant>::fillColor(layer, 1.0f, 0.0f, 0.0f, this); - layer.alpha = 1.0; - layers.push_back(layer); - - ftl::Future<FenceResult> future = - mRE->drawLayers(settings, layers, mBuffer, false, base::unique_fd()); - ASSERT_TRUE(future.valid()); - auto result = future.get(); - - ASSERT_TRUE(result.ok()); - auto fence = result.value(); - fence->waitForever(LOG_TAG); - - ASSERT_FALSE(mGLESRE->isFramebufferImageCachedForTesting(mBuffer->getBuffer()->getId())); - expectBufferColor(fullscreenRect(), 255, 0, 0, 255); -} - TEST_P(RenderEngineTest, drawLayers_fillRedBuffer_colorSource) { initializeRenderEngine(); fillRedBuffer<ColorSourceVariant>(); @@ -1783,11 +1655,7 @@ TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransform_sourceDataspace) { const auto& renderEngineFactory = GetParam(); // skip for non color management if (!renderEngineFactory->useColorManagement()) { - return; - } - // skip for GLESRenderEngine - if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { - return; + GTEST_SKIP(); } initializeRenderEngine(); @@ -1798,11 +1666,7 @@ TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransform_outputDataspace) { const auto& renderEngineFactory = GetParam(); // skip for non color management if (!renderEngineFactory->useColorManagement()) { - return; - } - // skip for GLESRenderEngine - if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { - return; + GTEST_SKIP(); } initializeRenderEngine(); @@ -1893,11 +1757,7 @@ TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformAndSourceDataspace_o const auto& renderEngineFactory = GetParam(); // skip for non color management if (!renderEngineFactory->useColorManagement()) { - return; - } - // skip for GLESRenderEngine - if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { - return; + GTEST_SKIP(); } initializeRenderEngine(); @@ -1908,11 +1768,7 @@ TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformAndOutputDataspace_o const auto& renderEngineFactory = GetParam(); // skip for non color management if (!renderEngineFactory->useColorManagement()) { - return; - } - // skip for GLESRenderEngine - if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { - return; + GTEST_SKIP(); } initializeRenderEngine(); @@ -2003,11 +1859,7 @@ TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformAndSourceDataspace_b const auto& renderEngineFactory = GetParam(); // skip for non color management if (!renderEngineFactory->useColorManagement()) { - return; - } - // skip for GLESRenderEngine - if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { - return; + GTEST_SKIP(); } initializeRenderEngine(); @@ -2018,11 +1870,7 @@ TEST_P(RenderEngineTest, drawLayers_fillBufferColorTransformAndOutputDataspace_b const auto& renderEngineFactory = GetParam(); // skip for non color management if (!renderEngineFactory->useColorManagement()) { - return; - } - // skip for GLESRenderEngine - if (renderEngineFactory->type() != renderengine::RenderEngine::RenderEngineType::GLES) { - return; + GTEST_SKIP(); } initializeRenderEngine(); @@ -2537,10 +2385,6 @@ TEST_P(RenderEngineTest, testBorder) { } TEST_P(RenderEngineTest, testDimming) { - if (GetParam()->type() == renderengine::RenderEngine::RenderEngineType::GLES) { - GTEST_SKIP(); - } - initializeRenderEngine(); const ui::Dataspace dataspace = ui::Dataspace::V0_SRGB_LINEAR; @@ -2613,9 +2457,6 @@ TEST_P(RenderEngineTest, testDimming) { } TEST_P(RenderEngineTest, testDimming_inGammaSpace) { - if (GetParam()->type() == renderengine::RenderEngine::RenderEngineType::GLES) { - GTEST_SKIP(); - } initializeRenderEngine(); const ui::Dataspace dataspace = static_cast<ui::Dataspace>(ui::Dataspace::STANDARD_BT709 | @@ -2691,9 +2532,6 @@ TEST_P(RenderEngineTest, testDimming_inGammaSpace) { } TEST_P(RenderEngineTest, testDimming_inGammaSpace_withDisplayColorTransform) { - if (GetParam()->type() == renderengine::RenderEngine::RenderEngineType::GLES) { - GTEST_SKIP(); - } initializeRenderEngine(); const ui::Dataspace dataspace = static_cast<ui::Dataspace>(ui::Dataspace::STANDARD_BT709 | @@ -2754,9 +2592,6 @@ TEST_P(RenderEngineTest, testDimming_inGammaSpace_withDisplayColorTransform) { } TEST_P(RenderEngineTest, testDimming_inGammaSpace_withDisplayColorTransform_deviceHandles) { - if (GetParam()->type() == renderengine::RenderEngine::RenderEngineType::GLES) { - GTEST_SKIP(); - } initializeRenderEngine(); const ui::Dataspace dataspace = static_cast<ui::Dataspace>(ui::Dataspace::STANDARD_BT709 | @@ -2819,9 +2654,6 @@ TEST_P(RenderEngineTest, testDimming_inGammaSpace_withDisplayColorTransform_devi TEST_P(RenderEngineTest, testDimming_withoutTargetLuminance) { initializeRenderEngine(); - if (GetParam()->type() == renderengine::RenderEngine::RenderEngineType::GLES) { - return; - } const auto displayRect = Rect(2, 1); const renderengine::DisplaySettings display{ @@ -2927,10 +2759,6 @@ TEST_P(RenderEngineTest, test_tonemapPQMatches) { GTEST_SKIP(); } - if (GetParam()->type() == renderengine::RenderEngine::RenderEngineType::GLES) { - GTEST_SKIP(); - } - initializeRenderEngine(); tonemap( @@ -2948,10 +2776,6 @@ TEST_P(RenderEngineTest, test_tonemapHLGMatches) { GTEST_SKIP(); } - if (GetParam()->type() == renderengine::RenderEngine::RenderEngineType::GLES) { - GTEST_SKIP(); - } - initializeRenderEngine(); tonemap( @@ -2965,10 +2789,6 @@ TEST_P(RenderEngineTest, test_tonemapHLGMatches) { } TEST_P(RenderEngineTest, r8_behaves_as_mask) { - if (GetParam()->type() == renderengine::RenderEngine::RenderEngineType::GLES) { - return; - } - initializeRenderEngine(); const auto r8Buffer = allocateR8Buffer(2, 1); @@ -3026,10 +2846,6 @@ TEST_P(RenderEngineTest, r8_behaves_as_mask) { } TEST_P(RenderEngineTest, r8_respects_color_transform) { - if (GetParam()->type() == renderengine::RenderEngine::RenderEngineType::GLES) { - return; - } - initializeRenderEngine(); const auto r8Buffer = allocateR8Buffer(2, 1); @@ -3092,10 +2908,6 @@ TEST_P(RenderEngineTest, r8_respects_color_transform) { } TEST_P(RenderEngineTest, r8_respects_color_transform_when_device_handles) { - if (GetParam()->type() == renderengine::RenderEngine::RenderEngineType::GLES) { - return; - } - initializeRenderEngine(); const auto r8Buffer = allocateR8Buffer(2, 1); @@ -3161,10 +2973,6 @@ TEST_P(RenderEngineTest, r8_respects_color_transform_when_device_handles) { } TEST_P(RenderEngineTest, primeShaderCache) { - if (GetParam()->type() == renderengine::RenderEngine::RenderEngineType::GLES) { - GTEST_SKIP(); - } - initializeRenderEngine(); auto fut = mRE->primeCache(); diff --git a/services/inputflinger/dispatcher/DebugConfig.h b/services/inputflinger/dispatcher/DebugConfig.h index d34ae49072..d2ad40754a 100644 --- a/services/inputflinger/dispatcher/DebugConfig.h +++ b/services/inputflinger/dispatcher/DebugConfig.h @@ -74,11 +74,8 @@ const bool DEBUG_TOUCH_MODE = /** * Log debug messages about touch occlusion - * Enable this via "adb shell setprop log.tag.InputDispatcherTouchOcclusion DEBUG" (requires - * restart) */ -const bool DEBUG_TOUCH_OCCLUSION = - __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "TouchOcclusion", ANDROID_LOG_INFO); +constexpr bool DEBUG_TOUCH_OCCLUSION = true; /** * Log debug messages about the app switch latency optimization. diff --git a/services/inputflinger/dispatcher/FocusResolver.cpp b/services/inputflinger/dispatcher/FocusResolver.cpp index 85dcf8f4cf..4da846bcf8 100644 --- a/services/inputflinger/dispatcher/FocusResolver.cpp +++ b/services/inputflinger/dispatcher/FocusResolver.cpp @@ -39,7 +39,7 @@ sp<IBinder> FocusResolver::getFocusedWindowToken(int32_t displayId) const { return it != mFocusedWindowTokenByDisplay.end() ? it->second.second : nullptr; } -std::optional<FocusRequest> FocusResolver::getFocusRequest(int32_t displayId) const { +std::optional<FocusRequest> FocusResolver::getFocusRequest(int32_t displayId) { auto it = mFocusRequestByDisplay.find(displayId); return it != mFocusRequestByDisplay.end() ? std::make_optional<>(it->second) : std::nullopt; } diff --git a/services/inputflinger/dispatcher/FocusResolver.h b/services/inputflinger/dispatcher/FocusResolver.h index 8a6dfa4ca9..6d11a77aad 100644 --- a/services/inputflinger/dispatcher/FocusResolver.h +++ b/services/inputflinger/dispatcher/FocusResolver.h @@ -62,7 +62,6 @@ public: std::optional<FocusResolver::FocusChanges> setFocusedWindow( const android::gui::FocusRequest& request, const std::vector<sp<android::gui::WindowInfoHandle>>& windows); - std::optional<android::gui::FocusRequest> getFocusRequest(int32_t displayId) const; // Display has been removed from the system, clean up old references. void displayRemoved(int32_t displayId); @@ -113,6 +112,7 @@ private: std::optional<FocusResolver::FocusChanges> updateFocusedWindow( int32_t displayId, const std::string& reason, const sp<IBinder>& token, const std::string& tokenName = ""); + std::optional<android::gui::FocusRequest> getFocusRequest(int32_t displayId); }; } // namespace android::inputdispatcher diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index b52e3128db..ff63a6f05f 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -659,13 +659,6 @@ void InputDispatcher::processNoFocusedWindowAnrLocked() { if (focusedWindowHandle != nullptr) { return; // We now have a focused window. No need for ANR. } - std::optional<FocusRequest> pendingRequest = - mFocusResolver.getFocusRequest(mAwaitedApplicationDisplayId); - if (pendingRequest.has_value() && onAnrLocked(*pendingRequest)) { - // We don't have a focusable window but we know which window should have - // been focused. Blame that process in case it doesn't belong to the focused app. - return; - } onAnrLocked(mAwaitedFocusedApplication); } @@ -2998,7 +2991,7 @@ void InputDispatcher::enqueueDispatchEntriesLocked(nsecs_t currentTime, ATRACE_NAME(message.c_str()); } - bool wasEmpty = connection->outboundQueue.empty(); + const bool wasEmpty = connection->outboundQueue.empty(); // Enqueue dispatch entries for the requested modes. enqueueDispatchEntryLocked(connection, eventEntry, inputTarget, @@ -3681,6 +3674,8 @@ void InputDispatcher::synthesizeCancelationEventsForConnectionLocked( target.inputChannel = connection->inputChannel; target.flags = InputTarget::FLAG_DISPATCH_AS_IS; + const bool wasEmpty = connection->outboundQueue.empty(); + for (size_t i = 0; i < cancelationEvents.size(); i++) { std::unique_ptr<EventEntry> cancelationEventEntry = std::move(cancelationEvents[i]); switch (cancelationEventEntry->type) { @@ -3715,7 +3710,10 @@ void InputDispatcher::synthesizeCancelationEventsForConnectionLocked( InputTarget::FLAG_DISPATCH_AS_IS); } - startDispatchCycleLocked(currentTime, connection); + // If the outbound queue was previously empty, start the dispatch cycle going. + if (wasEmpty && !connection->outboundQueue.empty()) { + startDispatchCycleLocked(currentTime, connection); + } } void InputDispatcher::synthesizePointerDownEventsForConnectionLocked( @@ -3747,6 +3745,7 @@ void InputDispatcher::synthesizePointerDownEventsForConnectionLocked( target.inputChannel = connection->inputChannel; target.flags = InputTarget::FLAG_DISPATCH_AS_IS; + const bool wasEmpty = connection->outboundQueue.empty(); for (std::unique_ptr<EventEntry>& downEventEntry : downEvents) { switch (downEventEntry->type) { case EventEntry::Type::MOTION: { @@ -3773,7 +3772,10 @@ void InputDispatcher::synthesizePointerDownEventsForConnectionLocked( InputTarget::FLAG_DISPATCH_AS_IS); } - startDispatchCycleLocked(downTime, connection); + // If the outbound queue was previously empty, start the dispatch cycle going. + if (wasEmpty && !connection->outboundQueue.empty()) { + startDispatchCycleLocked(downTime, connection); + } } std::unique_ptr<MotionEntry> InputDispatcher::splitMotionEvent( @@ -5855,25 +5857,6 @@ void InputDispatcher::sendDropWindowCommandLocked(const sp<IBinder>& token, floa postCommandLocked(std::move(command)); } -bool InputDispatcher::onAnrLocked(const android::gui::FocusRequest& pendingFocusRequest) { - if (pendingFocusRequest.token == nullptr) { - return false; - } - - const std::string reason = android::base::StringPrintf("%s is not focusable.", - pendingFocusRequest.windowName.c_str()); - updateLastAnrStateLocked(pendingFocusRequest.windowName, reason); - sp<Connection> connection = getConnectionLocked(pendingFocusRequest.token); - if (connection != nullptr) { - processConnectionUnresponsiveLocked(*connection, std::move(reason)); - // Stop waking up for events on this connection, it is already unresponsive - cancelEventsForAnrLocked(connection); - } else { - sendWindowUnresponsiveCommandLocked(pendingFocusRequest.token, std::nullopt, reason); - } - return true; -} - void InputDispatcher::onAnrLocked(const sp<Connection>& connection) { if (connection == nullptr) { LOG_ALWAYS_FATAL("Caller must check for nullness"); diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h index d078b352bc..b5bbce8e8d 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.h +++ b/services/inputflinger/dispatcher/InputDispatcher.h @@ -657,7 +657,6 @@ private: void sendDropWindowCommandLocked(const sp<IBinder>& token, float x, float y) REQUIRES(mLock); void onAnrLocked(const sp<Connection>& connection) REQUIRES(mLock); void onAnrLocked(std::shared_ptr<InputApplicationHandle> application) REQUIRES(mLock); - bool onAnrLocked(const android::gui::FocusRequest& pendingFocusRequest) REQUIRES(mLock); void updateLastAnrStateLocked(const sp<android::gui::WindowInfoHandle>& window, const std::string& reason) REQUIRES(mLock); void updateLastAnrStateLocked(const InputApplicationHandle& application, diff --git a/services/inputflinger/include/InputReaderBase.h b/services/inputflinger/include/InputReaderBase.h index 44424597f8..cacb63cb8b 100644 --- a/services/inputflinger/include/InputReaderBase.h +++ b/services/inputflinger/include/InputReaderBase.h @@ -113,6 +113,8 @@ public: virtual std::optional<int32_t> getBatteryCapacity(int32_t deviceId) = 0; /* Get battery status of a particular input device. */ virtual std::optional<int32_t> getBatteryStatus(int32_t deviceId) = 0; + /* Get the device path for the battery of an input device. */ + virtual std::optional<std::string> getBatteryDevicePath(int32_t deviceId) = 0; virtual std::vector<InputDeviceLightInfo> getLights(int32_t deviceId) = 0; diff --git a/services/inputflinger/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp index ff0b9a5f7e..c9d21dc573 100644 --- a/services/inputflinger/reader/EventHub.cpp +++ b/services/inputflinger/reader/EventHub.cpp @@ -1555,7 +1555,7 @@ std::optional<int32_t> EventHub::getBatteryCapacity(int32_t deviceId, int32_t ba // the lock to prevent event processing from being blocked by this call. std::scoped_lock _l(mLock); - const auto infos = getBatteryInfoLocked(deviceId); + const auto& infos = getBatteryInfoLocked(deviceId); auto it = infos.find(batteryId); if (it == infos.end()) { return std::nullopt; @@ -1596,7 +1596,7 @@ std::optional<int32_t> EventHub::getBatteryStatus(int32_t deviceId, int32_t batt // the lock to prevent event processing from being blocked by this call. std::scoped_lock _l(mLock); - const auto infos = getBatteryInfoLocked(deviceId); + const auto& infos = getBatteryInfoLocked(deviceId); auto it = infos.find(batteryId); if (it == infos.end()) { return std::nullopt; diff --git a/services/inputflinger/reader/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp index 4750d90fd6..4c38ce81b6 100644 --- a/services/inputflinger/reader/InputReader.cpp +++ b/services/inputflinger/reader/InputReader.cpp @@ -721,7 +721,10 @@ std::optional<int32_t> InputReader::getBatteryCapacity(int32_t deviceId) { if (!eventHubId) return {}; const auto batteryIds = mEventHub->getRawBatteryIds(*eventHubId); - if (batteryIds.empty()) return {}; + if (batteryIds.empty()) { + ALOGW("%s: There are no battery ids for EventHub device %d", __func__, *eventHubId); + return {}; + } return mEventHub->getBatteryCapacity(*eventHubId, batteryIds.front()); } @@ -741,10 +744,35 @@ std::optional<int32_t> InputReader::getBatteryStatus(int32_t deviceId) { if (!eventHubId) return {}; const auto batteryIds = mEventHub->getRawBatteryIds(*eventHubId); - if (batteryIds.empty()) return {}; + if (batteryIds.empty()) { + ALOGW("%s: There are no battery ids for EventHub device %d", __func__, *eventHubId); + return {}; + } return mEventHub->getBatteryStatus(*eventHubId, batteryIds.front()); } +std::optional<std::string> InputReader::getBatteryDevicePath(int32_t deviceId) { + std::scoped_lock _l(mLock); + + InputDevice* device = findInputDeviceLocked(deviceId); + if (!device) return {}; + + std::optional<int32_t> eventHubId = device->getBatteryEventHubId(); + if (!eventHubId) return {}; + const auto batteryIds = mEventHub->getRawBatteryIds(*eventHubId); + if (batteryIds.empty()) { + ALOGW("%s: There are no battery ids for EventHub device %d", __func__, *eventHubId); + return {}; + } + const auto batteryInfo = mEventHub->getRawBatteryInfo(*eventHubId, batteryIds.front()); + if (!batteryInfo) { + ALOGW("%s: Failed to get RawBatteryInfo for battery %d of EventHub device %d", __func__, + batteryIds.front(), *eventHubId); + return {}; + } + return batteryInfo->path; +} + std::vector<InputDeviceLightInfo> InputReader::getLights(int32_t deviceId) { std::scoped_lock _l(mLock); diff --git a/services/inputflinger/reader/include/InputReader.h b/services/inputflinger/reader/include/InputReader.h index 24194a73fe..fbce87f9a7 100644 --- a/services/inputflinger/reader/include/InputReader.h +++ b/services/inputflinger/reader/include/InputReader.h @@ -99,6 +99,8 @@ public: std::optional<int32_t> getBatteryStatus(int32_t deviceId) override; + std::optional<std::string> getBatteryDevicePath(int32_t deviceId) override; + std::vector<InputDeviceLightInfo> getLights(int32_t deviceId) override; std::vector<InputDeviceSensorInfo> getSensors(int32_t deviceId) override; diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp index cd853a64e1..7ee6950b09 100644 --- a/services/inputflinger/tests/InputDispatcher_test.cpp +++ b/services/inputflinger/tests/InputDispatcher_test.cpp @@ -4718,36 +4718,6 @@ TEST_F(InputDispatcherSingleWindowAnr, OnKeyDown_BasicAnr) { // We have a focused application, but no focused window TEST_F(InputDispatcherSingleWindowAnr, FocusedApplication_NoFocusedWindow) { - FocusRequest request; - request.token = nullptr; - request.windowName = ""; - request.timestamp = systemTime(SYSTEM_TIME_MONOTONIC); - request.displayId = mWindow->getInfo()->displayId; - mDispatcher->setFocusedWindow(request); - mWindow->consumeFocusEvent(false); - - // taps on the window work as normal - ASSERT_EQ(InputEventInjectionResult::SUCCEEDED, - injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, - WINDOW_LOCATION)); - ASSERT_NO_FATAL_FAILURE(mWindow->consumeMotionDown()); - mDispatcher->waitForIdle(); - mFakePolicy->assertNotifyAnrWasNotCalled(); - - // Once a focused event arrives, we get an ANR for this application - // We specify the injection timeout to be smaller than the application timeout, to ensure that - // injection times out (instead of failing). - const InputEventInjectionResult result = - injectKey(mDispatcher, AKEY_EVENT_ACTION_DOWN, 0 /* repeatCount */, ADISPLAY_ID_DEFAULT, - InputEventInjectionSync::WAIT_FOR_RESULT, 10ms, false /* allowKeyRepeat */); - ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, result); - const std::chrono::duration timeout = mApplication->getDispatchingTimeout(DISPATCHING_TIMEOUT); - mFakePolicy->assertNotifyNoFocusedWindowAnrWasCalled(timeout, mApplication); - ASSERT_TRUE(mDispatcher->waitForIdle()); -} - -// We have a focused application, but we are waiting on the requested window to become focusable -TEST_F(InputDispatcherSingleWindowAnr, FocusedApplication_PendingFocusedRequest) { mWindow->setFocusable(false); mDispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {mWindow}}}); mWindow->consumeFocusEvent(false); @@ -4768,7 +4738,7 @@ TEST_F(InputDispatcherSingleWindowAnr, FocusedApplication_PendingFocusedRequest) InputEventInjectionSync::WAIT_FOR_RESULT, 10ms, false /* allowKeyRepeat */); ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, result); const std::chrono::duration timeout = mApplication->getDispatchingTimeout(DISPATCHING_TIMEOUT); - mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow); + mFakePolicy->assertNotifyNoFocusedWindowAnrWasCalled(timeout, mApplication); ASSERT_TRUE(mDispatcher->waitForIdle()); } @@ -4818,10 +4788,11 @@ TEST_F(InputDispatcherSingleWindowAnr, NoFocusedWindow_DoesNotSendDuplicateAnr) injectKey(mDispatcher, AKEY_EVENT_ACTION_DOWN, 0 /* repeatCount */, ADISPLAY_ID_DEFAULT, InputEventInjectionSync::WAIT_FOR_RESULT, 10ms, false /* allowKeyRepeat */); ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, result); - const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); - mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow); + const std::chrono::duration appTimeout = + mApplication->getDispatchingTimeout(DISPATCHING_TIMEOUT); + mFakePolicy->assertNotifyNoFocusedWindowAnrWasCalled(appTimeout, mApplication); - std::this_thread::sleep_for(timeout); + std::this_thread::sleep_for(appTimeout); // ANR should not be raised again. It is up to policy to do that if it desires. mFakePolicy->assertNotifyAnrWasNotCalled(); @@ -4842,8 +4813,8 @@ TEST_F(InputDispatcherSingleWindowAnr, NoFocusedWindow_DropsFocusedEvents) { InputEventInjectionSync::WAIT_FOR_RESULT, 10ms); ASSERT_EQ(InputEventInjectionResult::TIMED_OUT, result); - const std::chrono::duration timeout = mWindow->getDispatchingTimeout(DISPATCHING_TIMEOUT); - mFakePolicy->assertNotifyWindowUnresponsiveWasCalled(timeout, mWindow); + const std::chrono::duration timeout = mApplication->getDispatchingTimeout(DISPATCHING_TIMEOUT); + mFakePolicy->assertNotifyNoFocusedWindowAnrWasCalled(timeout, mApplication); // Future focused events get dropped right away ASSERT_EQ(InputEventInjectionResult::FAILED, injectKeyDown(mDispatcher)); diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index 19a7d86233..ee6993ced0 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -81,6 +81,7 @@ static constexpr int32_t THIRD_TRACKING_ID = 2; static constexpr int32_t DEFAULT_BATTERY = 1; static constexpr int32_t BATTERY_STATUS = 4; static constexpr int32_t BATTERY_CAPACITY = 66; +static const std::string BATTERY_DEVPATH = "/sys/devices/mydevice/power_supply/mybattery"; static constexpr int32_t LIGHT_BRIGHTNESS = 0x55000000; static constexpr int32_t LIGHT_COLOR = 0x7F448866; static constexpr int32_t LIGHT_PLAYER_ID = 2; @@ -1017,7 +1018,12 @@ private: std::optional<RawBatteryInfo> getRawBatteryInfo(int32_t deviceId, int32_t batteryId) const override { - return std::nullopt; + if (batteryId != DEFAULT_BATTERY) return {}; + static const auto BATTERY_INFO = RawBatteryInfo{.id = DEFAULT_BATTERY, + .name = "default battery", + .flags = InputBatteryClass::CAPACITY, + .path = BATTERY_DEVPATH}; + return BATTERY_INFO; } std::vector<int32_t> getRawLightIds(int32_t deviceId) const override { @@ -2235,6 +2241,21 @@ TEST_F(InputReaderTest, BatteryGetStatus) { ASSERT_EQ(mReader->getBatteryStatus(deviceId), BATTERY_STATUS); } +TEST_F(InputReaderTest, BatteryGetDevicePath) { + constexpr int32_t deviceId = END_RESERVED_ID + 1000; + ftl::Flags<InputDeviceClass> deviceClass = + InputDeviceClass::KEYBOARD | InputDeviceClass::BATTERY; + constexpr int32_t eventHubId = 1; + const char* DEVICE_LOCATION = "BLUETOOTH"; + std::shared_ptr<InputDevice> device = mReader->newDevice(deviceId, "fake", DEVICE_LOCATION); + device->addController<FakePeripheralController>(eventHubId); + mReader->pushNextDevice(device); + + ASSERT_NO_FATAL_FAILURE(addDevice(eventHubId, "fake", deviceClass, nullptr)); + + ASSERT_EQ(mReader->getBatteryDevicePath(deviceId), BATTERY_DEVPATH); +} + TEST_F(InputReaderTest, LightGetColor) { constexpr int32_t deviceId = END_RESERVED_ID + 1000; ftl::Flags<InputDeviceClass> deviceClass = InputDeviceClass::KEYBOARD | InputDeviceClass::LIGHT; diff --git a/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp b/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp index f15d871403..f5bd29763e 100644 --- a/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp +++ b/services/inputflinger/tests/fuzzers/InputReaderFuzzer.cpp @@ -107,6 +107,10 @@ public: return reader->getBatteryStatus(deviceId); } + std::optional<std::string> getBatteryDevicePath(int32_t deviceId) { + return reader->getBatteryDevicePath(deviceId); + } + std::vector<InputDeviceLightInfo> getLights(int32_t deviceId) { return reader->getLights(deviceId); } @@ -232,6 +236,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) { }, [&]() -> void { reader->getBatteryCapacity(fdp->ConsumeIntegral<int32_t>()); }, [&]() -> void { reader->getBatteryStatus(fdp->ConsumeIntegral<int32_t>()); }, + [&]() -> void { reader->getBatteryDevicePath(fdp->ConsumeIntegral<int32_t>()); }, [&]() -> void { reader->getLights(fdp->ConsumeIntegral<int32_t>()); }, [&]() -> void { reader->getSensors(fdp->ConsumeIntegral<int32_t>()); }, [&]() -> void { diff --git a/services/surfaceflinger/Android.bp b/services/surfaceflinger/Android.bp index 3348cec211..b911ae75d4 100644 --- a/services/surfaceflinger/Android.bp +++ b/services/surfaceflinger/Android.bp @@ -154,7 +154,6 @@ filegroup { "DisplayHardware/PowerAdvisor.cpp", "DisplayHardware/VirtualDisplaySurface.cpp", "DisplayRenderArea.cpp", - "EffectLayer.cpp", "Effects/Daltonizer.cpp", "EventLog/EventLog.cpp", "FlagManager.cpp", diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/Display.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/Display.h index 16cb41b024..5e84be1841 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/Display.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/Display.h @@ -56,6 +56,9 @@ public: // similar requests if needed. virtual void createClientCompositionCache(uint32_t cacheSize) = 0; + // Sends the brightness setting to HWC + virtual void applyDisplayBrightness(const bool applyImmediately) = 0; + protected: ~Display() = default; }; diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFE.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFE.h index 9753a6c83c..a738da045a 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFE.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFE.h @@ -53,31 +53,8 @@ public: // Called before composition starts. Should return true if this layer has // pending updates which would require an extra display refresh cycle to // process. - virtual bool onPreComposition(nsecs_t refreshStartTime) = 0; - - // Used with latchCompositionState() - enum class StateSubset { - // Gets the basic geometry (bounds, transparent region, visibility, - // transforms, alpha) for the layer, for computing visibility and - // coverage. - BasicGeometry, - - // Gets the full geometry (crops, buffer transforms, metadata) and - // content (buffer or color) state for the layer. - GeometryAndContent, - - // Gets the per frame content (buffer or color) state for the layer. - Content, - - // Gets the cursor state for the layer. - Cursor, - }; - - // Prepares the output-independent composition state for the layer. The - // StateSubset argument selects what portion of the state is actually needed - // by the CompositionEngine code, since computing everything may be - // expensive. - virtual void prepareCompositionState(StateSubset) = 0; + virtual bool onPreComposition(nsecs_t refreshStartTime, + bool updatingOutputGeometryThisFrame) = 0; struct ClientCompositionTargetSettings { enum class BlurSetting { diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/Output.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/Output.h index 2203639b1a..874b330c1c 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/Output.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/Output.h @@ -262,9 +262,6 @@ public: // Presents the output, finalizing all composition details virtual void present(const CompositionRefreshArgs&) = 0; - // Latches the front-end layer state for each output layer - virtual void updateLayerStateFromFE(const CompositionRefreshArgs&) const = 0; - // Enables predicting composition strategy to run client composition earlier virtual void setPredictCompositionStrategy(bool) = 0; diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/CompositionEngine.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/CompositionEngine.h index 386808d714..09079264da 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/CompositionEngine.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/CompositionEngine.h @@ -51,8 +51,6 @@ public: // Debugging void dump(std::string&) const override; - void updateLayerStateFromFE(CompositionRefreshArgs& args); - // Testing void setNeedsAnotherUpdateForTest(bool); diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h index fa7bc5da7f..33a10a36a7 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Display.h @@ -72,6 +72,7 @@ public: const compositionengine::DisplayColorProfileCreationArgs&) override; void createRenderSurface(const compositionengine::RenderSurfaceCreationArgs&) override; void createClientCompositionCache(uint32_t cacheSize) override; + void applyDisplayBrightness(const bool applyImmediately) override; // Internal helpers used by chooseCompositionStrategy() using ChangedTypes = android::HWComposer::DeviceRequestedChanges::ChangedTypes; diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Output.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Output.h index 38a391b114..23d5570096 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Output.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/Output.h @@ -89,7 +89,6 @@ public: compositionengine::Output::CoverageState&) override; void setReleasedLayers(const compositionengine::CompositionRefreshArgs&) override; - void updateLayerStateFromFE(const CompositionRefreshArgs&) const override; void updateCompositionState(const compositionengine::CompositionRefreshArgs&) override; void planComposition() override; void writeCompositionState(const compositionengine::CompositionRefreshArgs&) override; diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Display.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Display.h index 72e6f3bdbb..7e99ec2f5a 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Display.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Display.h @@ -41,6 +41,7 @@ public: MOCK_METHOD1(createDisplayColorProfile, void(const DisplayColorProfileCreationArgs&)); MOCK_METHOD1(createRenderSurface, void(const RenderSurfaceCreationArgs&)); MOCK_METHOD1(createClientCompositionCache, void(uint32_t)); + MOCK_METHOD1(applyDisplayBrightness, void(const bool)); MOCK_METHOD1(setPredictCompositionStrategy, void(bool)); }; diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/LayerFE.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/LayerFE.h index 2b704e697f..be0dbceffe 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/LayerFE.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/LayerFE.h @@ -42,9 +42,8 @@ public: MOCK_CONST_METHOD0(getCompositionState, const LayerFECompositionState*()); - MOCK_METHOD1(onPreComposition, bool(nsecs_t)); + MOCK_METHOD2(onPreComposition, bool(nsecs_t, bool)); - MOCK_METHOD1(prepareCompositionState, void(compositionengine::LayerFE::StateSubset)); MOCK_CONST_METHOD1(prepareClientComposition, std::optional<compositionengine::LayerFE::LayerSettings>( compositionengine::LayerFE::ClientCompositionTargetSettings&)); diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Output.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Output.h index 2a04949cff..7592cac582 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Output.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/mock/Output.h @@ -91,7 +91,6 @@ public: void(sp<compositionengine::LayerFE>&, compositionengine::Output::CoverageState&)); MOCK_METHOD1(setReleasedLayers, void(const compositionengine::CompositionRefreshArgs&)); - MOCK_CONST_METHOD1(updateLayerStateFromFE, void(const CompositionRefreshArgs&)); MOCK_METHOD1(updateCompositionState, void(const CompositionRefreshArgs&)); MOCK_METHOD0(planComposition, void()); MOCK_METHOD1(writeCompositionState, void(const CompositionRefreshArgs&)); diff --git a/services/surfaceflinger/CompositionEngine/src/CompositionEngine.cpp b/services/surfaceflinger/CompositionEngine/src/CompositionEngine.cpp index 6203dc6737..855507eec4 100644 --- a/services/surfaceflinger/CompositionEngine/src/CompositionEngine.cpp +++ b/services/surfaceflinger/CompositionEngine/src/CompositionEngine.cpp @@ -105,8 +105,6 @@ void CompositionEngine::present(CompositionRefreshArgs& args) { } } - updateLayerStateFromFE(args); - for (const auto& output : args.outputs) { output->present(args); } @@ -119,8 +117,6 @@ void CompositionEngine::updateCursorAsync(CompositionRefreshArgs& args) { for (const auto& output : args.outputs) { for (auto* layer : output->getOutputLayersOrderedByZ()) { if (layer->isHardwareCursor()) { - // Latch the cursor composition state from each front-end layer. - layer->getLayerFE().prepareCompositionState(LayerFE::StateSubset::Cursor); layer->writeCursorPositionToHWC(); } } @@ -136,7 +132,7 @@ void CompositionEngine::preComposition(CompositionRefreshArgs& args) { mRefreshStartTime = systemTime(SYSTEM_TIME_MONOTONIC); for (auto& layer : args.layers) { - if (layer->onPreComposition(mRefreshStartTime)) { + if (layer->onPreComposition(mRefreshStartTime, args.updatingOutputGeometryThisFrame)) { needsAnotherUpdate = true; } } @@ -152,12 +148,5 @@ void CompositionEngine::setNeedsAnotherUpdateForTest(bool value) { mNeedsAnotherUpdate = value; } -void CompositionEngine::updateLayerStateFromFE(CompositionRefreshArgs& args) { - // Update the composition state from each front-end layer - for (const auto& output : args.outputs) { - output->updateLayerStateFromFE(args); - } -} - } // namespace impl } // namespace android::compositionengine diff --git a/services/surfaceflinger/CompositionEngine/src/Display.cpp b/services/surfaceflinger/CompositionEngine/src/Display.cpp index 0ebbcd0103..0b69d44ac4 100644 --- a/services/surfaceflinger/CompositionEngine/src/Display.cpp +++ b/services/surfaceflinger/CompositionEngine/src/Display.cpp @@ -203,23 +203,16 @@ void Display::setReleasedLayers(const compositionengine::CompositionRefreshArgs& setReleasedLayers(std::move(releasedLayers)); } -void Display::beginFrame() { - Output::beginFrame(); - - // If we don't have a HWC display, then we are done. - const auto halDisplayId = HalDisplayId::tryCast(mId); - if (!halDisplayId) { - return; - } - +void Display::applyDisplayBrightness(const bool applyImmediately) { auto& hwc = getCompositionEngine().getHwComposer(); + const auto halDisplayId = HalDisplayId::tryCast(*getDisplayId()); if (const auto physicalDisplayId = PhysicalDisplayId::tryCast(*halDisplayId); physicalDisplayId && getState().displayBrightness) { const status_t result = hwc.setDisplayBrightness(*physicalDisplayId, *getState().displayBrightness, getState().displayBrightnessNits, Hwc2::Composer::DisplayBrightnessOptions{ - .applyImmediately = false}) + .applyImmediately = applyImmediately}) .get(); ALOGE_IF(result != NO_ERROR, "setDisplayBrightness failed for %s: %d, (%s)", getName().c_str(), result, strerror(-result)); @@ -228,6 +221,18 @@ void Display::beginFrame() { editState().displayBrightness.reset(); } +void Display::beginFrame() { + Output::beginFrame(); + + // If we don't have a HWC display, then we are done. + const auto halDisplayId = HalDisplayId::tryCast(mId); + if (!halDisplayId) { + return; + } + + applyDisplayBrightness(false); +} + bool Display::chooseCompositionStrategy( std::optional<android::HWComposer::DeviceRequestedChanges>* outChanges) { ATRACE_CALL(); diff --git a/services/surfaceflinger/CompositionEngine/src/Output.cpp b/services/surfaceflinger/CompositionEngine/src/Output.cpp index b5894cf0be..e3f3680c1c 100644 --- a/services/surfaceflinger/CompositionEngine/src/Output.cpp +++ b/services/surfaceflinger/CompositionEngine/src/Output.cpp @@ -501,7 +501,6 @@ void Output::ensureOutputLayerIfVisible(sp<compositionengine::LayerFE>& layerFE, // appear on multiple outputs. if (!coverage.latchedLayers.count(layerFE)) { coverage.latchedLayers.insert(layerFE); - layerFE->prepareCompositionState(compositionengine::LayerFE::StateSubset::BasicGeometry); } // Only consider the layers on this output @@ -725,14 +724,6 @@ void Output::setReleasedLayers(const compositionengine::CompositionRefreshArgs&) // The base class does nothing with this call. } -void Output::updateLayerStateFromFE(const CompositionRefreshArgs& args) const { - for (auto* layer : getOutputLayersOrderedByZ()) { - layer->getLayerFE().prepareCompositionState( - args.updatingGeometryThisFrame ? LayerFE::StateSubset::GeometryAndContent - : LayerFE::StateSubset::Content); - } -} - void Output::updateCompositionState(const compositionengine::CompositionRefreshArgs& refreshArgs) { ATRACE_CALL(); ALOGV(__FUNCTION__); diff --git a/services/surfaceflinger/CompositionEngine/tests/CompositionEngineTest.cpp b/services/surfaceflinger/CompositionEngine/tests/CompositionEngineTest.cpp index de9de0150d..b570979f1f 100644 --- a/services/surfaceflinger/CompositionEngine/tests/CompositionEngineTest.cpp +++ b/services/surfaceflinger/CompositionEngine/tests/CompositionEngineTest.cpp @@ -108,12 +108,6 @@ TEST_F(CompositionEnginePresentTest, worksAsExpected) { EXPECT_CALL(*mOutput2, prepare(Ref(mRefreshArgs), _)); EXPECT_CALL(*mOutput3, prepare(Ref(mRefreshArgs), _)); - // The next step in presenting is to make sure all outputs have the latest - // state from the front-end (SurfaceFlinger). - EXPECT_CALL(*mOutput1, updateLayerStateFromFE(Ref(mRefreshArgs))); - EXPECT_CALL(*mOutput2, updateLayerStateFromFE(Ref(mRefreshArgs))); - EXPECT_CALL(*mOutput3, updateLayerStateFromFE(Ref(mRefreshArgs))); - // The last step is to actually present each output. EXPECT_CALL(*mOutput1, present(Ref(mRefreshArgs))); EXPECT_CALL(*mOutput2, present(Ref(mRefreshArgs))); @@ -175,21 +169,18 @@ TEST_F(CompositionEngineUpdateCursorAsyncTest, handlesMultipleLayersBeingCursorL { InSequence seq; EXPECT_CALL(mOutput2Layer1.outputLayer, isHardwareCursor()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mOutput2Layer1.layerFE, prepareCompositionState(LayerFE::StateSubset::Cursor)); EXPECT_CALL(mOutput2Layer1.outputLayer, writeCursorPositionToHWC()); } { InSequence seq; EXPECT_CALL(mOutput3Layer1.outputLayer, isHardwareCursor()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mOutput3Layer1.layerFE, prepareCompositionState(LayerFE::StateSubset::Cursor)); EXPECT_CALL(mOutput3Layer1.outputLayer, writeCursorPositionToHWC()); } { InSequence seq; EXPECT_CALL(mOutput3Layer2.outputLayer, isHardwareCursor()).WillRepeatedly(Return(true)); - EXPECT_CALL(*mOutput3Layer2.layerFE, prepareCompositionState(LayerFE::StateSubset::Cursor)); EXPECT_CALL(mOutput3Layer2.outputLayer, writeCursorPositionToHWC()); } @@ -222,9 +213,12 @@ TEST_F(CompositionTestPreComposition, preCompositionInvokesLayerPreCompositionWi nsecs_t ts1 = 0; nsecs_t ts2 = 0; nsecs_t ts3 = 0; - EXPECT_CALL(*mLayer1FE, onPreComposition(_)).WillOnce(DoAll(SaveArg<0>(&ts1), Return(false))); - EXPECT_CALL(*mLayer2FE, onPreComposition(_)).WillOnce(DoAll(SaveArg<0>(&ts2), Return(false))); - EXPECT_CALL(*mLayer3FE, onPreComposition(_)).WillOnce(DoAll(SaveArg<0>(&ts3), Return(false))); + EXPECT_CALL(*mLayer1FE, onPreComposition(_, _)) + .WillOnce(DoAll(SaveArg<0>(&ts1), Return(false))); + EXPECT_CALL(*mLayer2FE, onPreComposition(_, _)) + .WillOnce(DoAll(SaveArg<0>(&ts2), Return(false))); + EXPECT_CALL(*mLayer3FE, onPreComposition(_, _)) + .WillOnce(DoAll(SaveArg<0>(&ts3), Return(false))); mRefreshArgs.outputs = {mOutput1}; mRefreshArgs.layers = {mLayer1FE, mLayer2FE, mLayer3FE}; @@ -238,9 +232,9 @@ TEST_F(CompositionTestPreComposition, preCompositionInvokesLayerPreCompositionWi } TEST_F(CompositionTestPreComposition, preCompositionDefaultsToNoUpdateNeeded) { - EXPECT_CALL(*mLayer1FE, onPreComposition(_)).WillOnce(Return(false)); - EXPECT_CALL(*mLayer2FE, onPreComposition(_)).WillOnce(Return(false)); - EXPECT_CALL(*mLayer3FE, onPreComposition(_)).WillOnce(Return(false)); + EXPECT_CALL(*mLayer1FE, onPreComposition(_, _)).WillOnce(Return(false)); + EXPECT_CALL(*mLayer2FE, onPreComposition(_, _)).WillOnce(Return(false)); + EXPECT_CALL(*mLayer3FE, onPreComposition(_, _)).WillOnce(Return(false)); mEngine.setNeedsAnotherUpdateForTest(true); @@ -255,9 +249,9 @@ TEST_F(CompositionTestPreComposition, preCompositionDefaultsToNoUpdateNeeded) { TEST_F(CompositionTestPreComposition, preCompositionSetsNeedsAnotherUpdateIfAtLeastOneLayerRequestsIt) { - EXPECT_CALL(*mLayer1FE, onPreComposition(_)).WillOnce(Return(true)); - EXPECT_CALL(*mLayer2FE, onPreComposition(_)).WillOnce(Return(false)); - EXPECT_CALL(*mLayer3FE, onPreComposition(_)).WillOnce(Return(false)); + EXPECT_CALL(*mLayer1FE, onPreComposition(_, _)).WillOnce(Return(true)); + EXPECT_CALL(*mLayer2FE, onPreComposition(_, _)).WillOnce(Return(false)); + EXPECT_CALL(*mLayer3FE, onPreComposition(_, _)).WillOnce(Return(false)); mRefreshArgs.outputs = {mOutput1}; mRefreshArgs.layers = {mLayer1FE, mLayer2FE, mLayer3FE}; diff --git a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp index ace28648d7..eb209e9b72 100644 --- a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp +++ b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp @@ -758,56 +758,6 @@ TEST_F(OutputSetReleasedLayersTest, setReleasedLayersTakesGivenLayers) { } /* - * Output::updateLayerStateFromFE() - */ - -using OutputUpdateLayerStateFromFETest = OutputTest; - -TEST_F(OutputUpdateLayerStateFromFETest, handlesNoOutputLayerCase) { - CompositionRefreshArgs refreshArgs; - - mOutput->updateLayerStateFromFE(refreshArgs); -} - -TEST_F(OutputUpdateLayerStateFromFETest, preparesContentStateForAllContainedLayers) { - InjectedLayer layer1; - InjectedLayer layer2; - InjectedLayer layer3; - - EXPECT_CALL(*layer1.layerFE.get(), prepareCompositionState(LayerFE::StateSubset::Content)); - EXPECT_CALL(*layer2.layerFE.get(), prepareCompositionState(LayerFE::StateSubset::Content)); - EXPECT_CALL(*layer3.layerFE.get(), prepareCompositionState(LayerFE::StateSubset::Content)); - - injectOutputLayer(layer1); - injectOutputLayer(layer2); - injectOutputLayer(layer3); - - CompositionRefreshArgs refreshArgs; - refreshArgs.updatingGeometryThisFrame = false; - - mOutput->updateLayerStateFromFE(refreshArgs); -} - -TEST_F(OutputUpdateLayerStateFromFETest, preparesGeometryAndContentStateForAllContainedLayers) { - InjectedLayer layer1; - InjectedLayer layer2; - InjectedLayer layer3; - - EXPECT_CALL(*layer1.layerFE, prepareCompositionState(LayerFE::StateSubset::GeometryAndContent)); - EXPECT_CALL(*layer2.layerFE, prepareCompositionState(LayerFE::StateSubset::GeometryAndContent)); - EXPECT_CALL(*layer3.layerFE, prepareCompositionState(LayerFE::StateSubset::GeometryAndContent)); - - injectOutputLayer(layer1); - injectOutputLayer(layer2); - injectOutputLayer(layer3); - - CompositionRefreshArgs refreshArgs; - refreshArgs.updatingGeometryThisFrame = true; - - mOutput->updateLayerStateFromFE(refreshArgs); -} - -/* * Output::updateAndWriteCompositionState() */ @@ -1536,9 +1486,6 @@ const Region OutputEnsureOutputLayerIfVisibleTest::kTransparentRegionHintNegativ TEST_F(OutputEnsureOutputLayerIfVisibleTest, performsGeomLatchBeforeCheckingIfLayerIncluded) { EXPECT_CALL(mOutput, includesLayer(sp<LayerFE>(mLayer.layerFE))).WillOnce(Return(false)); - EXPECT_CALL(*mLayer.layerFE, - prepareCompositionState(compositionengine::LayerFE::StateSubset::BasicGeometry)); - mGeomSnapshots.clear(); ensureOutputLayerIfVisible(); diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp index ebaf35a8f2..029e449c4d 100644 --- a/services/surfaceflinger/DisplayDevice.cpp +++ b/services/surfaceflinger/DisplayDevice.cpp @@ -164,6 +164,15 @@ auto DisplayDevice::getInputInfo() const -> InputInfo { } void DisplayDevice::setPowerMode(hal::PowerMode mode) { + if (mode == hal::PowerMode::OFF || mode == hal::PowerMode::ON) { + if (mStagedBrightness && mBrightness != *mStagedBrightness) { + getCompositionDisplay()->setNextBrightness(*mStagedBrightness); + mBrightness = *mStagedBrightness; + } + mStagedBrightness = std::nullopt; + getCompositionDisplay()->applyDisplayBrightness(true); + } + mPowerMode = mode; getCompositionDisplay()->setCompositionEnabled(mPowerMode.has_value() && diff --git a/services/surfaceflinger/EffectLayer.cpp b/services/surfaceflinger/EffectLayer.cpp deleted file mode 100644 index 7180fa6a58..0000000000 --- a/services/surfaceflinger/EffectLayer.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// TODO(b/129481165): remove the #pragma below and fix conversion issues -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wconversion" - -// #define LOG_NDEBUG 0 -#undef LOG_TAG -#define LOG_TAG "EffectLayer" - -#include "EffectLayer.h" - -#include <stdint.h> -#include <stdlib.h> -#include <sys/types.h> - -#include <compositionengine/CompositionEngine.h> -#include <compositionengine/LayerFECompositionState.h> -#include <renderengine/RenderEngine.h> -#include <ui/GraphicBuffer.h> -#include <utils/Errors.h> -#include <utils/Log.h> - -#include "DisplayDevice.h" -#include "SurfaceFlinger.h" - -namespace android { -// --------------------------------------------------------------------------- - -EffectLayer::EffectLayer(const LayerCreationArgs& args) : BufferStateLayer(args) {} -EffectLayer::~EffectLayer() = default; - -} // namespace android diff --git a/services/surfaceflinger/EffectLayer.h b/services/surfaceflinger/EffectLayer.h deleted file mode 100644 index 311d4935fc..0000000000 --- a/services/surfaceflinger/EffectLayer.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2007 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include <sys/types.h> - -#include <cstdint> - -#include "BufferStateLayer.h" - -namespace android { - -// A layer that can render a combination of the following effects. -// * fill the bounds of the layer with a color -// * render a shadow cast by the bounds of the layer -// If no effects are enabled, the layer is considered to be invisible. -class EffectLayer : public BufferStateLayer { -public: - explicit EffectLayer(const LayerCreationArgs&); - ~EffectLayer() override; -}; - -} // namespace android diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 701071b36e..08b71c2754 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -65,9 +65,9 @@ #include <mutex> #include <sstream> +#include "BufferStateLayer.h" #include "DisplayDevice.h" #include "DisplayHardware/HWComposer.h" -#include "EffectLayer.h" #include "FrameTimeline.h" #include "FrameTracer/FrameTracer.h" #include "LayerProtoHelper.h" @@ -465,6 +465,10 @@ void Layer::computeBounds(FloatRect parentBounds, ui::Transform parentTransform, for (const sp<Layer>& child : mDrawingChildren) { child->computeBounds(mBounds, mEffectiveTransform, childShadowRadius); } + + if (mPotentialCursor) { + prepareCursorCompositionState(); + } } Rect Layer::getCroppedBufferSize(const State& s) const { @@ -650,30 +654,6 @@ sp<compositionengine::LayerFE> Layer::asLayerFE() const { return sp<compositionengine::LayerFE>::fromExisting(layerFE); } -void Layer::prepareCompositionState(compositionengine::LayerFE::StateSubset subset) { - using StateSubset = compositionengine::LayerFE::StateSubset; - - switch (subset) { - case StateSubset::BasicGeometry: - prepareBasicGeometryCompositionState(); - break; - - case StateSubset::GeometryAndContent: - prepareBasicGeometryCompositionState(); - prepareGeometryCompositionState(); - preparePerFrameCompositionState(); - break; - - case StateSubset::Content: - preparePerFrameCompositionState(); - break; - - case StateSubset::Cursor: - prepareCursorCompositionState(); - break; - } -} - const char* Layer::getDebugName() const { return mName.c_str(); } @@ -2205,8 +2185,8 @@ void Layer::prepareShadowClientComposition(LayerFE::LayerSettings& caster, renderengine::ShadowSettings state = mFlinger->mDrawingState.globalShadowSettings; // Note: this preserves existing behavior of shadowing the entire layer and not cropping it if - // transparent regions are present. This may not be necessary since shadows are only cast by - // SurfaceFlinger's EffectLayers, which do not typically use transparent regions. + // transparent regions are present. This may not be necessary since shadows are typically cast + // by layers without transparent regions. state.boundaries = mBounds; // Shift the spot light x-position to the middle of the display and then @@ -3426,7 +3406,7 @@ bool Layer::fenceHasSignaled() const { return fenceSignaled; } -bool Layer::onPreComposition(nsecs_t refreshStartTime) { +bool Layer::onPreComposition(nsecs_t refreshStartTime, bool /* updatingOutputGeometryThisFrame */) { for (const auto& handle : mDrawingState.callbackHandles) { handle->refreshStartTime = refreshStartTime; } @@ -4240,6 +4220,18 @@ bool Layer::hasBlur() const { return getBackgroundBlurRadius() > 0 || getDrawingState().blurRegions.size() > 0; } +void Layer::updateSnapshot(bool updateGeometry) { + if (!getCompositionEngineLayerFE()) { + return; + } + + if (updateGeometry) { + prepareBasicGeometryCompositionState(); + prepareGeometryCompositionState(); + } + preparePerFrameCompositionState(); +} + // --------------------------------------------------------------------------- std::ostream& operator<<(std::ostream& stream, const Layer::FrameRate& rate) { diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index f6b9b0fd07..5030fd826e 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -574,9 +574,8 @@ public: // implements compositionengine::LayerFE const compositionengine::LayerFECompositionState* getCompositionState() const; bool fenceHasSignaled() const; - bool onPreComposition(nsecs_t); - void prepareCompositionState(compositionengine::LayerFE::StateSubset subset) override; - + // Called before composition. updatingOutputGeometryThisFrame is used by ARC++'s Layer subclass. + bool onPreComposition(nsecs_t refreshStartTime, bool updatingOutputGeometryThisFrame); std::optional<compositionengine::LayerFE::LayerSettings> prepareClientComposition( compositionengine::LayerFE::ClientCompositionTargetSettings&) const override; void onLayerDisplayed(ftl::SharedFuture<FenceResult>); @@ -868,6 +867,7 @@ public: bool simpleBufferUpdate(const layer_state_t&) const; static bool isOpaqueFormat(PixelFormat format); + void updateSnapshot(bool updateGeometry); protected: friend class impl::SurfaceInterceptor; diff --git a/services/surfaceflinger/LayerRenderArea.cpp b/services/surfaceflinger/LayerRenderArea.cpp index e17b01f520..6bc7dc1dd7 100644 --- a/services/surfaceflinger/LayerRenderArea.cpp +++ b/services/surfaceflinger/LayerRenderArea.cpp @@ -18,7 +18,6 @@ #include <ui/Transform.h> #include "DisplayDevice.h" -#include "EffectLayer.h" #include "Layer.h" #include "LayerRenderArea.h" #include "SurfaceFlinger.h" @@ -110,7 +109,7 @@ void LayerRenderArea::render(std::function<void()> drawLayers) { // layer which has no properties set and which does not draw. // We hold the statelock as the reparent-for-drawing operation modifies the // hierarchy and there could be readers on Binder threads, like dump. - sp<EffectLayer> screenshotParentLayer = mFlinger.getFactory().createEffectLayer( + auto screenshotParentLayer = mFlinger.getFactory().createEffectLayer( {&mFlinger, nullptr, "Screenshot Parent"s, ISurfaceComposerClient::eNoColorFill, LayerMetadata()}); { diff --git a/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp b/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp index d270655f4f..00886f030e 100644 --- a/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp +++ b/services/surfaceflinger/Scheduler/RefreshRateConfigs.cpp @@ -280,6 +280,15 @@ auto RefreshRateConfigs::getBestRefreshRateLocked(const std::vector<LayerRequire ATRACE_CALL(); ALOGV("%s: %zu layers", __func__, layers.size()); + const auto& activeMode = *getActiveModeItLocked()->second; + + // Keep the display at max refresh rate for the duration of powering on the display. + if (signals.powerOnImminent) { + ALOGV("Power On Imminent"); + const auto& max = getMaxRefreshRateByPolicyLocked(activeMode.getGroup()); + return {max, GlobalSignals{.powerOnImminent = true}}; + } + int noVoteLayers = 0; int minVoteLayers = 0; int maxVoteLayers = 0; @@ -326,7 +335,6 @@ auto RefreshRateConfigs::getBestRefreshRateLocked(const std::vector<LayerRequire const Policy* policy = getCurrentPolicyLocked(); const auto& defaultMode = mDisplayModes.get(policy->defaultMode)->get(); - const auto& activeMode = *getActiveModeItLocked()->second; // If the default mode group is different from the group of current mode, // this means a layer requesting a seamed mode switch just disappeared and diff --git a/services/surfaceflinger/Scheduler/RefreshRateConfigs.h b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h index b2cfb03e42..19bcb94bf2 100644 --- a/services/surfaceflinger/Scheduler/RefreshRateConfigs.h +++ b/services/surfaceflinger/Scheduler/RefreshRateConfigs.h @@ -185,9 +185,13 @@ public: bool touch = false; // True if the system hasn't seen any buffers posted to layers recently. bool idle = false; + // Whether the display is about to be powered on, or has been in PowerMode::ON + // within the timeout of DisplayPowerTimer. + bool powerOnImminent = false; bool operator==(GlobalSignals other) const { - return touch == other.touch && idle == other.idle; + return touch == other.touch && idle == other.idle && + powerOnImminent == other.powerOnImminent; } }; diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp index bec39a75d0..ff6b461449 100644 --- a/services/surfaceflinger/Scheduler/Scheduler.cpp +++ b/services/surfaceflinger/Scheduler/Scheduler.cpp @@ -704,17 +704,13 @@ auto Scheduler::chooseDisplayMode() -> std::pair<DisplayModePtr, GlobalSignals> const auto configs = holdRefreshRateConfigs(); - // If Display Power is not in normal operation we want to be in performance mode. When coming - // back to normal mode, a grace period is given with DisplayPowerTimer. - if (mDisplayPowerTimer && - (mPolicy.displayPowerMode != hal::PowerMode::ON || - mPolicy.displayPowerTimer == TimerState::Reset)) { - constexpr GlobalSignals kNoSignals; - return {configs->getMaxRefreshRateByPolicy(), kNoSignals}; - } + const bool powerOnImminent = mDisplayPowerTimer && + (mPolicy.displayPowerMode != hal::PowerMode::ON || + mPolicy.displayPowerTimer == TimerState::Reset); const GlobalSignals signals{.touch = mTouchTimer && mPolicy.touch == TouchState::Active, - .idle = mPolicy.idleTimer == TimerState::Expired}; + .idle = mPolicy.idleTimer == TimerState::Expired, + .powerOnImminent = powerOnImminent}; return configs->getBestRefreshRate(mPolicy.contentRequirements, signals); } diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 78eaa14e5b..e31490c66d 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -118,7 +118,6 @@ #include "DisplayHardware/PowerAdvisor.h" #include "DisplayHardware/VirtualDisplaySurface.h" #include "DisplayRenderArea.h" -#include "EffectLayer.h" #include "Effects/Daltonizer.h" #include "FlagManager.h" #include "FpsReporter.h" @@ -2190,10 +2189,6 @@ void SurfaceFlinger::composite(TimePoint frameTime, VsyncId vsyncId) displayIds.push_back(display->getId()); } mPowerAdvisor->setDisplays(displayIds); - mDrawingState.traverseInZOrder([&refreshArgs](Layer* layer) { - if (auto layerFE = layer->getCompositionEngineLayerFE()) - refreshArgs.layers.push_back(layerFE); - }); if (DOES_CONTAIN_BORDER) { refreshArgs.borderInfoList.clear(); @@ -2224,6 +2219,12 @@ void SurfaceFlinger::composite(TimePoint frameTime, VsyncId vsyncId) refreshArgs.updatingOutputGeometryThisFrame = mVisibleRegionsDirty; refreshArgs.updatingGeometryThisFrame = mGeometryDirty.exchange(false) || mVisibleRegionsDirty; + mDrawingState.traverseInZOrder([&refreshArgs](Layer* layer) { + layer->updateSnapshot(refreshArgs.updatingGeometryThisFrame); + if (auto layerFE = layer->getCompositionEngineLayerFE()) { + refreshArgs.layers.push_back(layerFE); + } + }); refreshArgs.blursAreExpensive = mBlursAreExpensive; refreshArgs.internalDisplayRotationFlags = DisplayDevice::getPrimaryDisplayRotationFlags(); diff --git a/services/surfaceflinger/SurfaceFlingerDefaultFactory.cpp b/services/surfaceflinger/SurfaceFlingerDefaultFactory.cpp index 15a791e4d6..319d014237 100644 --- a/services/surfaceflinger/SurfaceFlingerDefaultFactory.cpp +++ b/services/surfaceflinger/SurfaceFlingerDefaultFactory.cpp @@ -24,7 +24,6 @@ #include "BufferStateLayer.h" #include "DisplayDevice.h" -#include "EffectLayer.h" #include "FrameTracer/FrameTracer.h" #include "Layer.h" #include "NativeWindowSurface.h" @@ -94,8 +93,8 @@ sp<BufferStateLayer> DefaultFactory::createBufferStateLayer(const LayerCreationA return sp<BufferStateLayer>::make(args); } -sp<EffectLayer> DefaultFactory::createEffectLayer(const LayerCreationArgs& args) { - return sp<EffectLayer>::make(args); +sp<Layer> DefaultFactory::createEffectLayer(const LayerCreationArgs& args) { + return sp<Layer>::make(args); } std::unique_ptr<FrameTracer> DefaultFactory::createFrameTracer() { diff --git a/services/surfaceflinger/SurfaceFlingerDefaultFactory.h b/services/surfaceflinger/SurfaceFlingerDefaultFactory.h index 8d00379ba2..66022401b7 100644 --- a/services/surfaceflinger/SurfaceFlingerDefaultFactory.h +++ b/services/surfaceflinger/SurfaceFlingerDefaultFactory.h @@ -42,7 +42,7 @@ public: const sp<IGraphicBufferProducer>&) override; std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() override; sp<BufferStateLayer> createBufferStateLayer(const LayerCreationArgs& args) override; - sp<EffectLayer> createEffectLayer(const LayerCreationArgs& args) override; + sp<Layer> createEffectLayer(const LayerCreationArgs& args) override; std::unique_ptr<FrameTracer> createFrameTracer() override; std::unique_ptr<frametimeline::FrameTimeline> createFrameTimeline( std::shared_ptr<TimeStats> timeStats, pid_t surfaceFlingerPid) override; diff --git a/services/surfaceflinger/SurfaceFlingerFactory.h b/services/surfaceflinger/SurfaceFlingerFactory.h index 291838f81a..dc2afd3790 100644 --- a/services/surfaceflinger/SurfaceFlingerFactory.h +++ b/services/surfaceflinger/SurfaceFlingerFactory.h @@ -33,7 +33,6 @@ typedef int32_t PixelFormat; class BufferLayerConsumer; class BufferStateLayer; class DisplayDevice; -class EffectLayer; class FrameTracer; class GraphicBuffer; class HWComposer; @@ -91,7 +90,7 @@ public: virtual std::unique_ptr<compositionengine::CompositionEngine> createCompositionEngine() = 0; virtual sp<BufferStateLayer> createBufferStateLayer(const LayerCreationArgs& args) = 0; - virtual sp<EffectLayer> createEffectLayer(const LayerCreationArgs& args) = 0; + virtual sp<Layer> createEffectLayer(const LayerCreationArgs& args) = 0; virtual std::unique_ptr<FrameTracer> createFrameTracer() = 0; virtual std::unique_ptr<frametimeline::FrameTimeline> createFrameTimeline( std::shared_ptr<TimeStats> timeStats, pid_t surfaceFlingerPid) = 0; diff --git a/services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp b/services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp index 312d4ab45a..6501e2092b 100644 --- a/services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp +++ b/services/surfaceflinger/Tracing/tools/LayerTraceGenerator.cpp @@ -84,9 +84,7 @@ public: return sp<BufferStateLayer>::make(args); } - sp<EffectLayer> createEffectLayer(const LayerCreationArgs& args) { - return sp<EffectLayer>::make(args); - } + sp<Layer> createEffectLayer(const LayerCreationArgs& args) { return sp<Layer>::make(args); } std::unique_ptr<FrameTracer> createFrameTracer() override { return std::make_unique<testing::NiceMock<mock::FrameTracer>>(); diff --git a/services/surfaceflinger/fuzzer/README.md b/services/surfaceflinger/fuzzer/README.md index 7a5f229ae9..a06c41b139 100644 --- a/services/surfaceflinger/fuzzer/README.md +++ b/services/surfaceflinger/fuzzer/README.md @@ -78,9 +78,8 @@ You can find the possible values in the fuzzer's source code. Layer supports the following parameters: 1. Display Connection Types (parameter name: `fakeDisplay`) 2. State Sets (parameter name: `traverseInZOrder`) -3. State Subsets (parameter name: `prepareCompositionState`) -4. Disconnect modes (parameter name: `disconnect`) -5. Data Spaces (parameter name: `setDataspace`) +3. Disconnect modes (parameter name: `disconnect`) +4. Data Spaces (parameter name: `setDataspace`) You can find the possible values in the fuzzer's source code. diff --git a/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h b/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h index a8612638b2..22976186f2 100644 --- a/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h +++ b/services/surfaceflinger/fuzzer/surfaceflinger_fuzzers_utils.h @@ -33,7 +33,6 @@ #include "BufferStateLayer.h" #include "DisplayDevice.h" #include "DisplayHardware/ComposerHal.h" -#include "EffectLayer.h" #include "FrameTimeline/FrameTimeline.h" #include "FrameTracer/FrameTracer.h" #include "Layer.h" @@ -360,8 +359,8 @@ public: return nullptr; } - sp<EffectLayer> createEffectLayer(const LayerCreationArgs &args) override { - return sp<EffectLayer>::make(args); + sp<Layer> createEffectLayer(const LayerCreationArgs &args) override { + return sp<Layer>::make(args); } std::unique_ptr<FrameTracer> createFrameTracer() override { diff --git a/services/surfaceflinger/fuzzer/surfaceflinger_layer_fuzzer.cpp b/services/surfaceflinger/fuzzer/surfaceflinger_layer_fuzzer.cpp index aeccc522f3..9ece260ba5 100644 --- a/services/surfaceflinger/fuzzer/surfaceflinger_layer_fuzzer.cpp +++ b/services/surfaceflinger/fuzzer/surfaceflinger_layer_fuzzer.cpp @@ -17,7 +17,6 @@ #include <BufferStateLayer.h> #include <Client.h> #include <DisplayDevice.h> -#include <EffectLayer.h> #include <LayerRenderArea.h> #include <ftl/future.h> #include <fuzzer/FuzzedDataProvider.h> @@ -79,13 +78,13 @@ void LayerFuzzer::invokeEffectLayer() { TestableSurfaceFlinger flinger; sp<Client> client = sp<Client>::make(sp<SurfaceFlinger>::fromExisting(flinger.flinger())); const LayerCreationArgs layerCreationArgs = createLayerCreationArgs(&flinger, client); - sp<EffectLayer> effectLayer = sp<EffectLayer>::make(layerCreationArgs); + sp<Layer> effectLayer = sp<Layer>::make(layerCreationArgs); effectLayer->setColor({(mFdp.ConsumeFloatingPointInRange<float>(0, 255) /*x*/, mFdp.ConsumeFloatingPointInRange<float>(0, 255) /*y*/, mFdp.ConsumeFloatingPointInRange<float>(0, 255) /*z*/)}); effectLayer->setDataspace(mFdp.PickValueInArray(kDataspaces)); - sp<EffectLayer> parent = sp<EffectLayer>::make(layerCreationArgs); + sp<Layer> parent = sp<Layer>::make(layerCreationArgs); effectLayer->setChildrenDrawingParent(parent); const FrameTimelineInfo frameInfo = getFuzzedFrameTimelineInfo(); @@ -149,7 +148,8 @@ void LayerFuzzer::invokeBufferStateLayer() { layer->computeSourceBounds(getFuzzedFloatRect(&mFdp)); layer->fenceHasSignaled(); - layer->onPreComposition(mFdp.ConsumeIntegral<int64_t>()); + layer->onPreComposition(mFdp.ConsumeIntegral<int64_t>(), + false /*updatingOutputGeometryThisFrame*/); const std::vector<sp<CallbackHandle>> callbacks; layer->setTransactionCompletedListeners(callbacks); diff --git a/services/surfaceflinger/tests/unittests/CompositionTest.cpp b/services/surfaceflinger/tests/unittests/CompositionTest.cpp index e546c2f8c9..9485f48eea 100644 --- a/services/surfaceflinger/tests/unittests/CompositionTest.cpp +++ b/services/surfaceflinger/tests/unittests/CompositionTest.cpp @@ -38,7 +38,6 @@ #include <utils/String8.h> #include "DisplayRenderArea.h" -#include "EffectLayer.h" #include "Layer.h" #include "TestableSurfaceFlinger.h" #include "mock/DisplayHardware/MockComposer.h" @@ -857,13 +856,13 @@ struct BaseLayerVariant { template <typename LayerProperties> struct EffectLayerVariant : public BaseLayerVariant<LayerProperties> { using Base = BaseLayerVariant<LayerProperties>; - using FlingerLayerType = sp<EffectLayer>; + using FlingerLayerType = sp<Layer>; static FlingerLayerType createLayer(CompositionTest* test) { - FlingerLayerType layer = Base::template createLayerWithFactory<EffectLayer>(test, [test]() { - return sp<EffectLayer>::make( - LayerCreationArgs(test->mFlinger.flinger(), sp<Client>(), "test-layer", - LayerProperties::LAYER_FLAGS, LayerMetadata())); + FlingerLayerType layer = Base::template createLayerWithFactory<Layer>(test, [test]() { + return sp<Layer>::make(LayerCreationArgs(test->mFlinger.flinger(), sp<Client>(), + "test-layer", LayerProperties::LAYER_FLAGS, + LayerMetadata())); }); auto& layerDrawingState = test->mFlinger.mutableLayerDrawingState(layer); @@ -945,12 +944,12 @@ struct BufferLayerVariant : public BaseLayerVariant<LayerProperties> { template <typename LayerProperties> struct ContainerLayerVariant : public BaseLayerVariant<LayerProperties> { using Base = BaseLayerVariant<LayerProperties>; - using FlingerLayerType = sp<EffectLayer>; + using FlingerLayerType = sp<Layer>; static FlingerLayerType createLayer(CompositionTest* test) { LayerCreationArgs args(test->mFlinger.flinger(), sp<Client>(), "test-container-layer", LayerProperties::LAYER_FLAGS, LayerMetadata()); - FlingerLayerType layer = sp<EffectLayer>::make(args); + FlingerLayerType layer = sp<Layer>::make(args); Base::template initLayerDrawingStateAndComputeBounds(test, layer); return layer; } diff --git a/services/surfaceflinger/tests/unittests/FpsReporterTest.cpp b/services/surfaceflinger/tests/unittests/FpsReporterTest.cpp index 0b4e196d43..9789df5c3b 100644 --- a/services/surfaceflinger/tests/unittests/FpsReporterTest.cpp +++ b/services/surfaceflinger/tests/unittests/FpsReporterTest.cpp @@ -25,7 +25,6 @@ #include <gui/LayerMetadata.h> #include "BufferStateLayer.h" -#include "EffectLayer.h" #include "FpsReporter.h" #include "Layer.h" #include "TestableSurfaceFlinger.h" diff --git a/services/surfaceflinger/tests/unittests/LayerTest.cpp b/services/surfaceflinger/tests/unittests/LayerTest.cpp index 4974f90383..95e54f655b 100644 --- a/services/surfaceflinger/tests/unittests/LayerTest.cpp +++ b/services/surfaceflinger/tests/unittests/LayerTest.cpp @@ -17,7 +17,6 @@ #undef LOG_TAG #define LOG_TAG "LibSurfaceFlingerUnittests" -#include <EffectLayer.h> #include <gtest/gtest.h> #include <ui/FloatRect.h> #include <ui/Transform.h> diff --git a/services/surfaceflinger/tests/unittests/LayerTestUtils.cpp b/services/surfaceflinger/tests/unittests/LayerTestUtils.cpp index b7a8a93f5c..14304d1199 100644 --- a/services/surfaceflinger/tests/unittests/LayerTestUtils.cpp +++ b/services/surfaceflinger/tests/unittests/LayerTestUtils.cpp @@ -35,7 +35,7 @@ sp<Layer> BufferStateLayerFactory::createLayer(TestableSurfaceFlinger& flinger) sp<Layer> EffectLayerFactory::createLayer(TestableSurfaceFlinger& flinger) { sp<Client> client; LayerCreationArgs args(flinger.flinger(), client, "color-layer", LAYER_FLAGS, LayerMetadata()); - return sp<EffectLayer>::make(args); + return sp<Layer>::make(args); } std::string PrintToStringParamName( diff --git a/services/surfaceflinger/tests/unittests/LayerTestUtils.h b/services/surfaceflinger/tests/unittests/LayerTestUtils.h index fc9b6a27aa..ab446fafeb 100644 --- a/services/surfaceflinger/tests/unittests/LayerTestUtils.h +++ b/services/surfaceflinger/tests/unittests/LayerTestUtils.h @@ -23,8 +23,6 @@ // TODO(b/129481165): remove the #pragma below and fix conversion issues #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wconversion" -#include "BufferStateLayer.h" -#include "EffectLayer.h" #include "Layer.h" // TODO(b/129481165): remove the #pragma below and fix conversion issues #pragma clang diagnostic pop // ignored "-Wconversion" diff --git a/services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp b/services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp index 4f20932f2f..5d9b2a837d 100644 --- a/services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp +++ b/services/surfaceflinger/tests/unittests/RefreshRateConfigsTest.cpp @@ -977,6 +977,32 @@ TEST_F(RefreshRateConfigsTest, scrollWhileWatching60fps_60_90) { EXPECT_EQ(kMode90, configs.getBestRefreshRate(layers)); } +TEST_F(RefreshRateConfigsTest, powerOnImminentConsidered) { + RefreshRateConfigs configs(kModes_60_90, kModeId60); + + auto [refreshRate, signals] = configs.getBestRefreshRate({}, {}); + EXPECT_FALSE(signals.powerOnImminent); + EXPECT_EQ(kMode90, refreshRate); + + std::tie(refreshRate, signals) = configs.getBestRefreshRate({}, {.powerOnImminent = true}); + EXPECT_TRUE(signals.powerOnImminent); + EXPECT_EQ(kMode90, refreshRate); + + std::vector<LayerRequirement> layers = {{.weight = 1.f}}; + auto& lr1 = layers[0]; + lr1.vote = LayerVoteType::ExplicitExactOrMultiple; + lr1.desiredRefreshRate = 60_Hz; + lr1.name = "60Hz ExplicitExactOrMultiple"; + + std::tie(refreshRate, signals) = configs.getBestRefreshRate(layers, {.powerOnImminent = false}); + EXPECT_FALSE(signals.powerOnImminent); + EXPECT_EQ(kMode60, refreshRate); + + std::tie(refreshRate, signals) = configs.getBestRefreshRate(layers, {.powerOnImminent = true}); + EXPECT_TRUE(signals.powerOnImminent); + EXPECT_EQ(kMode90, refreshRate); +} + TEST_F(RefreshRateConfigsTest, touchConsidered) { RefreshRateConfigs configs(kModes_60_90, kModeId60); diff --git a/services/surfaceflinger/tests/unittests/RefreshRateSelectionTest.cpp b/services/surfaceflinger/tests/unittests/RefreshRateSelectionTest.cpp index 6752a39384..abf1786c0d 100644 --- a/services/surfaceflinger/tests/unittests/RefreshRateSelectionTest.cpp +++ b/services/surfaceflinger/tests/unittests/RefreshRateSelectionTest.cpp @@ -22,7 +22,6 @@ #include <gui/LayerMetadata.h> #include "BufferStateLayer.h" -#include "EffectLayer.h" #include "Layer.h" #include "TestableSurfaceFlinger.h" #include "mock/DisplayHardware/MockComposer.h" @@ -60,7 +59,7 @@ protected: void setupScheduler(); sp<BufferStateLayer> createBufferStateLayer(); - sp<EffectLayer> createEffectLayer(); + sp<Layer> createEffectLayer(); void setParent(Layer* child, Layer* parent); void commitTransaction(Layer* layer); @@ -96,10 +95,10 @@ sp<BufferStateLayer> RefreshRateSelectionTest::createBufferStateLayer() { return sp<BufferStateLayer>::make(args); } -sp<EffectLayer> RefreshRateSelectionTest::createEffectLayer() { +sp<Layer> RefreshRateSelectionTest::createEffectLayer() { sp<Client> client; LayerCreationArgs args(mFlinger.flinger(), client, "color-layer", LAYER_FLAGS, LayerMetadata()); - return sp<EffectLayer>::make(args); + return sp<Layer>::make(args); } void RefreshRateSelectionTest::setParent(Layer* child, Layer* parent) { diff --git a/services/surfaceflinger/tests/unittests/SetFrameRateTest.cpp b/services/surfaceflinger/tests/unittests/SetFrameRateTest.cpp index 6ee8174caf..51c6beabae 100644 --- a/services/surfaceflinger/tests/unittests/SetFrameRateTest.cpp +++ b/services/surfaceflinger/tests/unittests/SetFrameRateTest.cpp @@ -25,7 +25,6 @@ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wconversion" #include "BufferStateLayer.h" -#include "EffectLayer.h" #include "Layer.h" // TODO(b/129481165): remove the #pragma below and fix conversion issues #pragma clang diagnostic pop // ignored "-Wconversion" @@ -374,11 +373,6 @@ TEST_P(SetFrameRateTest, SetOnParentActivatesTree) { const auto& layerFactory = GetParam(); auto parent = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); - if (!parent->isVisible()) { - // This is a hack as all the test layers except EffectLayer are not visible, - // but since the logic is unified in Layer, it should be fine. - return; - } auto child = mLayers.emplace_back(layerFactory->createLayer(mFlinger)); addChild(parent, child); diff --git a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h index f8fdb65d31..1ce6e18d69 100644 --- a/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h +++ b/services/surfaceflinger/tests/unittests/TestableSurfaceFlinger.h @@ -32,7 +32,6 @@ #include "BufferStateLayer.h" #include "DisplayDevice.h" -#include "EffectLayer.h" #include "FakeVsyncConfiguration.h" #include "FrameTracer/FrameTracer.h" #include "Layer.h" @@ -125,7 +124,7 @@ public: return nullptr; } - sp<EffectLayer> createEffectLayer(const LayerCreationArgs&) override { return nullptr; } + sp<Layer> createEffectLayer(const LayerCreationArgs&) override { return nullptr; } std::unique_ptr<FrameTracer> createFrameTracer() override { return std::make_unique<mock::FrameTracer>(); |