diff options
Diffstat (limited to 'cmds')
| -rw-r--r-- | cmds/bootanimation/BootAnimation.cpp | 83 | ||||
| -rw-r--r-- | cmds/bootanimation/BootAnimation.h | 4 | ||||
| -rw-r--r-- | cmds/idmap2/idmap2d/Idmap2Service.cpp | 37 | ||||
| -rw-r--r-- | cmds/idmap2/idmap2d/Idmap2Service.h | 11 | ||||
| -rw-r--r-- | cmds/idmap2/idmap2d/aidl/services/android/os/IIdmap2.aidl | 6 |
5 files changed, 110 insertions, 31 deletions
diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp index e840739399df..1efdf7759f32 100644 --- a/cmds/bootanimation/BootAnimation.cpp +++ b/cmds/bootanimation/BootAnimation.cpp @@ -132,14 +132,14 @@ static const char IMAGE_FRAG_DYNAMIC_COLORING_SHADER_SOURCE[] = R"( uniform sampler2D uTexture; uniform float uFade; uniform float uColorProgress; - uniform vec4 uStartColor0; - uniform vec4 uStartColor1; - uniform vec4 uStartColor2; - uniform vec4 uStartColor3; - uniform vec4 uEndColor0; - uniform vec4 uEndColor1; - uniform vec4 uEndColor2; - uniform vec4 uEndColor3; + uniform vec3 uStartColor0; + uniform vec3 uStartColor1; + uniform vec3 uStartColor2; + uniform vec3 uStartColor3; + uniform vec3 uEndColor0; + uniform vec3 uEndColor1; + uniform vec3 uEndColor2; + uniform vec3 uEndColor3; varying highp vec2 vUv; void main() { vec4 mask = texture2D(uTexture, vUv); @@ -152,12 +152,12 @@ static const char IMAGE_FRAG_DYNAMIC_COLORING_SHADER_SOURCE[] = R"( * step(cWhiteMaskThreshold, g) * step(cWhiteMaskThreshold, b) * step(cWhiteMaskThreshold, a); - vec4 color = r * mix(uStartColor0, uEndColor0, uColorProgress) + vec3 color = r * mix(uStartColor0, uEndColor0, uColorProgress) + g * mix(uStartColor1, uEndColor1, uColorProgress) + b * mix(uStartColor2, uEndColor2, uColorProgress) + a * mix(uStartColor3, uEndColor3, uColorProgress); - color = mix(color, vec4(vec3((r + g + b + a) * 0.25), 1.0), useWhiteMask); - gl_FragColor = vec4(color.x, color.y, color.z, (1.0 - uFade)) * color.a; + color = mix(color, vec3((r + g + b + a) * 0.25), useWhiteMask); + gl_FragColor = vec4(color.x, color.y, color.z, (1.0 - uFade)); })"; static const char IMAGE_FRAG_SHADER_SOURCE[] = R"( precision mediump float; @@ -584,6 +584,15 @@ status_t BootAnimation::readyToRun() { mFlingerSurface = s; mTargetInset = -1; + // Rotate the boot animation according to the value specified in the sysprop + // ro.bootanim.set_orientation_<display_id>. Four values are supported: ORIENTATION_0, + // ORIENTATION_90, ORIENTATION_180 and ORIENTATION_270. + // If the value isn't specified or is ORIENTATION_0, nothing will be changed. + // This is needed to support having boot animation in orientations different from the natural + // device orientation. For example, on tablets that may want to keep natural orientation + // portrait for applications compatibility and to have the boot animation in landscape. + rotateAwayFromNaturalOrientationIfNeeded(); + projectSceneToWindow(); // Register a display event receiver @@ -597,6 +606,50 @@ status_t BootAnimation::readyToRun() { return NO_ERROR; } +void BootAnimation::rotateAwayFromNaturalOrientationIfNeeded() { + const auto orientation = parseOrientationProperty(); + + if (orientation == ui::ROTATION_0) { + // Do nothing if the sysprop isn't set or is set to ROTATION_0. + return; + } + + if (orientation == ui::ROTATION_90 || orientation == ui::ROTATION_270) { + std::swap(mWidth, mHeight); + std::swap(mInitWidth, mInitHeight); + mFlingerSurfaceControl->updateDefaultBufferSize(mWidth, mHeight); + } + + Rect displayRect(0, 0, mWidth, mHeight); + Rect layerStackRect(0, 0, mWidth, mHeight); + + SurfaceComposerClient::Transaction t; + t.setDisplayProjection(mDisplayToken, orientation, layerStackRect, displayRect); + t.apply(); +} + +ui::Rotation BootAnimation::parseOrientationProperty() { + const auto displayIds = SurfaceComposerClient::getPhysicalDisplayIds(); + if (displayIds.size() == 0) { + return ui::ROTATION_0; + } + const auto displayId = displayIds[0]; + const auto syspropName = [displayId] { + std::stringstream ss; + ss << "ro.bootanim.set_orientation_" << displayId.value; + return ss.str(); + }(); + const auto syspropValue = android::base::GetProperty(syspropName, "ORIENTATION_0"); + if (syspropValue == "ORIENTATION_90") { + return ui::ROTATION_90; + } else if (syspropValue == "ORIENTATION_180") { + return ui::ROTATION_180; + } else if (syspropValue == "ORIENTATION_270") { + return ui::ROTATION_270; + } + return ui::ROTATION_0; +} + void BootAnimation::projectSceneToWindow() { glViewport(0, 0, mWidth, mHeight); glScissor(0, 0, mWidth, mHeight); @@ -1446,12 +1499,12 @@ void BootAnimation::initDynamicColors() { for (int i = 0; i < DYNAMIC_COLOR_COUNT; i++) { float *startColor = mAnimation->startColors[i]; float *endColor = mAnimation->endColors[i]; - glUniform4f(glGetUniformLocation(mImageShader, + glUniform3f(glGetUniformLocation(mImageShader, (U_START_COLOR_PREFIX + std::to_string(i)).c_str()), - startColor[0], startColor[1], startColor[2], 1 /* alpha */); - glUniform4f(glGetUniformLocation(mImageShader, + startColor[0], startColor[1], startColor[2]); + glUniform3f(glGetUniformLocation(mImageShader, (U_END_COLOR_PREFIX + std::to_string(i)).c_str()), - endColor[0], endColor[1], endColor[2], 1 /* alpha */); + endColor[0], endColor[1], endColor[2]); } mImageColorProgressLocation = glGetUniformLocation(mImageShader, U_COLOR_PROGRESS); } diff --git a/cmds/bootanimation/BootAnimation.h b/cmds/bootanimation/BootAnimation.h index 86582053b4e1..8683b71a3762 100644 --- a/cmds/bootanimation/BootAnimation.h +++ b/cmds/bootanimation/BootAnimation.h @@ -30,6 +30,8 @@ #include <utils/Thread.h> #include <binder/IBinder.h> +#include <ui/Rotation.h> + #include <EGL/egl.h> #include <GLES2/gl2.h> @@ -200,6 +202,8 @@ private: ui::Size limitSurfaceSize(int width, int height) const; void resizeSurface(int newWidth, int newHeight); void projectSceneToWindow(); + void rotateAwayFromNaturalOrientationIfNeeded(); + ui::Rotation parseOrientationProperty(); bool shouldStopPlayingPart(const Animation::Part& part, int fadedFramesCount, int lastDisplayedProgress); diff --git a/cmds/idmap2/idmap2d/Idmap2Service.cpp b/cmds/idmap2/idmap2d/Idmap2Service.cpp index 1b2d905aec0a..e2638106994c 100644 --- a/cmds/idmap2/idmap2d/Idmap2Service.cpp +++ b/cmds/idmap2/idmap2d/Idmap2Service.cpp @@ -23,6 +23,7 @@ #include <cstring> #include <filesystem> #include <fstream> +#include <limits> #include <memory> #include <ostream> #include <string> @@ -295,26 +296,42 @@ Status Idmap2Service::createFabricatedOverlay( return ok(); } -Status Idmap2Service::acquireFabricatedOverlayIterator() { +Status Idmap2Service::acquireFabricatedOverlayIterator(int32_t* _aidl_return) { + std::lock_guard l(frro_iter_mutex_); if (frro_iter_.has_value()) { LOG(WARNING) << "active ffro iterator was not previously released"; } frro_iter_ = std::filesystem::directory_iterator(kIdmapCacheDir); + if (frro_iter_id_ == std::numeric_limits<int32_t>::max()) { + frro_iter_id_ = 0; + } else { + ++frro_iter_id_; + } + *_aidl_return = frro_iter_id_; return ok(); } -Status Idmap2Service::releaseFabricatedOverlayIterator() { +Status Idmap2Service::releaseFabricatedOverlayIterator(int32_t iteratorId) { + std::lock_guard l(frro_iter_mutex_); if (!frro_iter_.has_value()) { LOG(WARNING) << "no active ffro iterator to release"; + } else if (frro_iter_id_ != iteratorId) { + LOG(WARNING) << "incorrect iterator id in a call to release"; + } else { + frro_iter_.reset(); } return ok(); } -Status Idmap2Service::nextFabricatedOverlayInfos( +Status Idmap2Service::nextFabricatedOverlayInfos(int32_t iteratorId, std::vector<os::FabricatedOverlayInfo>* _aidl_return) { + std::lock_guard l(frro_iter_mutex_); + constexpr size_t kMaxEntryCount = 100; if (!frro_iter_.has_value()) { return error("no active frro iterator"); + } else if (frro_iter_id_ != iteratorId) { + return error("incorrect iterator id in a call to next"); } size_t count = 0; @@ -322,22 +339,22 @@ Status Idmap2Service::nextFabricatedOverlayInfos( auto entry_iter_end = end(*frro_iter_); for (; entry_iter != entry_iter_end && count < kMaxEntryCount; ++entry_iter) { auto& entry = *entry_iter; - if (!entry.is_regular_file() || !android::IsFabricatedOverlay(entry.path())) { + if (!entry.is_regular_file() || !android::IsFabricatedOverlay(entry.path().native())) { continue; } - const auto overlay = FabricatedOverlayContainer::FromPath(entry.path()); + const auto overlay = FabricatedOverlayContainer::FromPath(entry.path().native()); if (!overlay) { LOG(WARNING) << "Failed to open '" << entry.path() << "': " << overlay.GetErrorMessage(); continue; } - const auto info = (*overlay)->GetManifestInfo(); + auto info = (*overlay)->GetManifestInfo(); os::FabricatedOverlayInfo out_info; - out_info.packageName = info.package_name; - out_info.overlayName = info.name; - out_info.targetPackageName = info.target_package; - out_info.targetOverlayable = info.target_name; + out_info.packageName = std::move(info.package_name); + out_info.overlayName = std::move(info.name); + out_info.targetPackageName = std::move(info.target_package); + out_info.targetOverlayable = std::move(info.target_name); out_info.path = entry.path(); _aidl_return->emplace_back(std::move(out_info)); count++; diff --git a/cmds/idmap2/idmap2d/Idmap2Service.h b/cmds/idmap2/idmap2d/Idmap2Service.h index c61e4bc98a54..cc8cc5f218d2 100644 --- a/cmds/idmap2/idmap2d/Idmap2Service.h +++ b/cmds/idmap2/idmap2d/Idmap2Service.h @@ -26,7 +26,10 @@ #include <filesystem> #include <memory> +#include <mutex> +#include <optional> #include <string> +#include <variant> #include <vector> namespace android::os { @@ -60,11 +63,11 @@ class Idmap2Service : public BinderService<Idmap2Service>, public BnIdmap2 { binder::Status deleteFabricatedOverlay(const std::string& overlay_path, bool* _aidl_return) override; - binder::Status acquireFabricatedOverlayIterator() override; + binder::Status acquireFabricatedOverlayIterator(int32_t* _aidl_return) override; - binder::Status releaseFabricatedOverlayIterator() override; + binder::Status releaseFabricatedOverlayIterator(int32_t iteratorId) override; - binder::Status nextFabricatedOverlayInfos( + binder::Status nextFabricatedOverlayInfos(int32_t iteratorId, std::vector<os::FabricatedOverlayInfo>* _aidl_return) override; binder::Status dumpIdmap(const std::string& overlay_path, std::string* _aidl_return) override; @@ -74,7 +77,9 @@ class Idmap2Service : public BinderService<Idmap2Service>, public BnIdmap2 { // be able to be recalculated if idmap2 dies and restarts. std::unique_ptr<idmap2::TargetResourceContainer> framework_apk_cache_; + int32_t frro_iter_id_ = 0; std::optional<std::filesystem::directory_iterator> frro_iter_; + std::mutex frro_iter_mutex_; template <typename T> using MaybeUniquePtr = std::variant<std::unique_ptr<T>, T*>; diff --git a/cmds/idmap2/idmap2d/aidl/services/android/os/IIdmap2.aidl b/cmds/idmap2/idmap2d/aidl/services/android/os/IIdmap2.aidl index 0059cf293177..2bbfba97a6c6 100644 --- a/cmds/idmap2/idmap2d/aidl/services/android/os/IIdmap2.aidl +++ b/cmds/idmap2/idmap2d/aidl/services/android/os/IIdmap2.aidl @@ -41,9 +41,9 @@ interface IIdmap2 { @nullable FabricatedOverlayInfo createFabricatedOverlay(in FabricatedOverlayInternal overlay); boolean deleteFabricatedOverlay(@utf8InCpp String path); - void acquireFabricatedOverlayIterator(); - void releaseFabricatedOverlayIterator(); - List<FabricatedOverlayInfo> nextFabricatedOverlayInfos(); + int acquireFabricatedOverlayIterator(); + void releaseFabricatedOverlayIterator(int iteratorId); + List<FabricatedOverlayInfo> nextFabricatedOverlayInfos(int iteratorId); @utf8InCpp String dumpIdmap(@utf8InCpp String overlayApkPath); } |