mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-19 17:08:11 -04:00
window effect config
Signed-off-by: qianlf <qianliangfang@huawei.com> Change-Id: I9ae6d011d94266e437ef6b5bdc3a1d36e721bdff
This commit is contained in:
@@ -359,11 +359,6 @@ enum class WindowUpdateType : int32_t {
|
||||
WINDOW_UPDATE_PROPERTY,
|
||||
};
|
||||
|
||||
struct SystemConfig {
|
||||
bool isSystemDecorEnable_ = true;
|
||||
bool isStretchable_ = false;
|
||||
};
|
||||
|
||||
using OnCallback = std::function<void(int64_t)>;
|
||||
struct VsyncCallback {
|
||||
OnCallback onCallback;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "window_helper.h"
|
||||
#include "window_manager_hilog.h"
|
||||
#include "window_option.h"
|
||||
#include "wm_math.h"
|
||||
#include "pixel_map.h"
|
||||
#include "pixel_map_napi.h"
|
||||
#include "napi_remote_object.h"
|
||||
@@ -2269,7 +2270,7 @@ NativeValue* JsWindow::OnSetCornerRadius(NativeEngine& engine, NativeCallbackInf
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
NativeNumber* nativeVal = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
|
||||
if (nativeVal == nullptr || WindowHelper::LessNotEqual(static_cast<double>(*nativeVal), 0.0)) {
|
||||
if (nativeVal == nullptr || MathHelper::LessNotEqual(static_cast<double>(*nativeVal), 0.0)) {
|
||||
WLOGFE("[NAPI]SetCornerRadius invalid radius");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
@@ -2295,7 +2296,7 @@ NativeValue* JsWindow::OnSetShadow(NativeEngine& engine, NativeCallbackInfo& inf
|
||||
|
||||
{ // parse the 1st param: radius
|
||||
NativeNumber* nativeVal = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
|
||||
if (nativeVal == nullptr || WindowHelper::LessNotEqual(static_cast<double>(*nativeVal), 0.0)) {
|
||||
if (nativeVal == nullptr || MathHelper::LessNotEqual(static_cast<double>(*nativeVal), 0.0)) {
|
||||
WLOGFE("[NAPI]SetShadow invalid radius");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
@@ -2350,7 +2351,7 @@ NativeValue* JsWindow::OnSetBlur(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
NativeNumber* nativeVal = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
|
||||
if (nativeVal == nullptr || WindowHelper::LessNotEqual(static_cast<double>(*nativeVal), 0.0)) {
|
||||
if (nativeVal == nullptr || MathHelper::LessNotEqual(static_cast<double>(*nativeVal), 0.0)) {
|
||||
WLOGFE("[NAPI]SetBlur invalid radius");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
@@ -2374,7 +2375,7 @@ NativeValue* JsWindow::OnSetBackdropBlur(NativeEngine& engine, NativeCallbackInf
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
NativeNumber* nativeVal = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
|
||||
if (nativeVal == nullptr || WindowHelper::LessNotEqual(static_cast<double>(*nativeVal), 0.0)) {
|
||||
if (nativeVal == nullptr || MathHelper::LessNotEqual(static_cast<double>(*nativeVal), 0.0)) {
|
||||
WLOGFE("[NAPI]SetBackdropBlur invalid radius");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
@@ -60,4 +60,32 @@
|
||||
</keyboardAnimation>
|
||||
<!--enable/disable remote animation-->
|
||||
<remoteAnimation enable="true"></remoteAnimation>
|
||||
<!--window effect config-->
|
||||
<windowEffect>
|
||||
<appWindows>
|
||||
<cornerRadius>
|
||||
<!--off: no corner, defaultCornerRadiusXS: 4vp, defaultCornerRadiusS: 8vp-->
|
||||
<!--defaultCornerRadiusM: 12vp, defaultCornerRadiusL: 16vp, defaultCornerRadiusXL: 24vp-->
|
||||
<fullScreen>off</fullScreen>
|
||||
<split>off</split>
|
||||
<float>off</float>
|
||||
</cornerRadius>
|
||||
<shadow>
|
||||
<focused>
|
||||
<elevation>0</elevation>
|
||||
<color>#000000</color>
|
||||
<offsetX>0</offsetX>
|
||||
<offsetY>0</offsetY>
|
||||
<alpha>0</alpha>
|
||||
</focused>
|
||||
<unfocused>
|
||||
<elevation>0</elevation>
|
||||
<color>#000000</color>
|
||||
<offsetX>0</offsetX>
|
||||
<offsetY>0</offsetY>
|
||||
<alpha>0</alpha>
|
||||
</unfocused>
|
||||
</shadow>
|
||||
</appWindows>
|
||||
</windowEffect>
|
||||
</Configs>
|
||||
@@ -292,12 +292,18 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool IsFloatingNumber(std::string str)
|
||||
static bool IsFloatingNumber(std::string str, bool allowNeg = false)
|
||||
{
|
||||
if (str.size() == 0) {
|
||||
return false;
|
||||
}
|
||||
for (int32_t i = 0; i < static_cast<int32_t>(str.size()); i++) {
|
||||
|
||||
int32_t i = 0;
|
||||
if (allowNeg && str.at(i) == '-') {
|
||||
i++;
|
||||
}
|
||||
|
||||
for (; i < static_cast<int32_t>(str.size()); i++) {
|
||||
if ((str.at(i) < '0' || str.at(i) > '9') &&
|
||||
(str.at(i) != '.' || std::count(str.begin(), str.end(), '.') > 1)) {
|
||||
return false;
|
||||
@@ -482,12 +488,6 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline bool LessNotEqual(double left, double right)
|
||||
{
|
||||
static constexpr double eps = -0.001f;
|
||||
return (left - right) < eps;
|
||||
}
|
||||
|
||||
private:
|
||||
WindowHelper() = default;
|
||||
~WindowHelper() = default;
|
||||
|
||||
@@ -104,6 +104,87 @@ struct ModeChangeHotZonesConfig {
|
||||
uint32_t secondaryRange_;
|
||||
};
|
||||
|
||||
struct WindowShadowParameters {
|
||||
float elevation_;
|
||||
std::string color_;
|
||||
float offsetX_;
|
||||
float offsetY_;
|
||||
float alpha_;
|
||||
};
|
||||
|
||||
struct AppWindowEffectConfig {
|
||||
float fullScreenCornerRadius_;
|
||||
float splitCornerRadius_;
|
||||
float floatCornerRadius_;
|
||||
|
||||
WindowShadowParameters focusedShadow_;
|
||||
WindowShadowParameters unfocusedShadow_;
|
||||
|
||||
// defaultCornerRadiusL = 16.0vp
|
||||
AppWindowEffectConfig() : fullScreenCornerRadius_(0.0), splitCornerRadius_(0.0), floatCornerRadius_(0.0)
|
||||
{
|
||||
focusedShadow_ = {0, "#000000", 0, 0, 0};
|
||||
unfocusedShadow_ = {0, "#000000", 0, 0, 0};
|
||||
}
|
||||
};
|
||||
|
||||
struct SystemConfig : public Parcelable {
|
||||
bool isSystemDecorEnable_ = true;
|
||||
bool isStretchable_ = false;
|
||||
AppWindowEffectConfig effectConfig_;
|
||||
|
||||
virtual bool Marshalling(Parcel& parcel) const override
|
||||
{
|
||||
if (!parcel.WriteBool(isSystemDecorEnable_) || !parcel.WriteBool(isStretchable_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteFloat(effectConfig_.fullScreenCornerRadius_) ||
|
||||
!parcel.WriteFloat(effectConfig_.splitCornerRadius_) ||
|
||||
!parcel.WriteFloat(effectConfig_.floatCornerRadius_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteFloat(effectConfig_.focusedShadow_.elevation_) ||
|
||||
!parcel.WriteString(effectConfig_.focusedShadow_.color_) ||
|
||||
!parcel.WriteFloat(effectConfig_.focusedShadow_.offsetX_) ||
|
||||
!parcel.WriteFloat(effectConfig_.focusedShadow_.offsetY_) ||
|
||||
!parcel.WriteFloat(effectConfig_.focusedShadow_.alpha_)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!parcel.WriteFloat(effectConfig_.unfocusedShadow_.elevation_) ||
|
||||
!parcel.WriteString(effectConfig_.unfocusedShadow_.color_) ||
|
||||
!parcel.WriteFloat(effectConfig_.unfocusedShadow_.offsetX_) ||
|
||||
!parcel.WriteFloat(effectConfig_.unfocusedShadow_.offsetY_) ||
|
||||
!parcel.WriteFloat(effectConfig_.unfocusedShadow_.alpha_)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static SystemConfig* Unmarshalling(Parcel& parcel)
|
||||
{
|
||||
SystemConfig* config = new SystemConfig();
|
||||
config->isSystemDecorEnable_ = parcel.ReadBool();
|
||||
config->isStretchable_ = parcel.ReadBool();
|
||||
config->effectConfig_.fullScreenCornerRadius_ = parcel.ReadFloat();
|
||||
config->effectConfig_.splitCornerRadius_ = parcel.ReadFloat();
|
||||
config->effectConfig_.floatCornerRadius_ = parcel.ReadFloat();
|
||||
config->effectConfig_.focusedShadow_.elevation_ = parcel.ReadFloat();
|
||||
config->effectConfig_.focusedShadow_.color_ = parcel.ReadString();
|
||||
config->effectConfig_.focusedShadow_.offsetX_ = parcel.ReadFloat();
|
||||
config->effectConfig_.focusedShadow_.offsetY_ = parcel.ReadFloat();
|
||||
config->effectConfig_.focusedShadow_.alpha_ = parcel.ReadFloat();
|
||||
config->effectConfig_.unfocusedShadow_.elevation_ = parcel.ReadFloat();
|
||||
config->effectConfig_.unfocusedShadow_.color_ = parcel.ReadString();
|
||||
config->effectConfig_.unfocusedShadow_.offsetX_ = parcel.ReadFloat();
|
||||
config->effectConfig_.unfocusedShadow_.offsetY_ = parcel.ReadFloat();
|
||||
config->effectConfig_.unfocusedShadow_.alpha_ = parcel.ReadFloat();
|
||||
return config;
|
||||
}
|
||||
};
|
||||
|
||||
struct WindowSizeLimits {
|
||||
uint32_t maxWidth_;
|
||||
uint32_t maxHeight_;
|
||||
|
||||
@@ -41,6 +41,18 @@ inline float ToDegrees(float radians)
|
||||
return radians * 180.0f / PI;
|
||||
}
|
||||
|
||||
inline bool LessNotEqual(double left, double right)
|
||||
{
|
||||
static constexpr double eps = -0.001f;
|
||||
return (left - right) < eps;
|
||||
}
|
||||
|
||||
inline bool GreatNotEqual(double left, double right)
|
||||
{
|
||||
static constexpr double eps = 0.001f;
|
||||
return (left - right) > eps;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T Max(const T& a, const T& b)
|
||||
{
|
||||
|
||||
@@ -392,6 +392,11 @@ private:
|
||||
WMError PreProcessShow(uint32_t reason, bool withAnimation);
|
||||
bool NeedToStopShowing();
|
||||
void CalculateStartRectExceptHotZone(float virtualPixelRatio, const TransformHelper::Vector2& hotZoneScale);
|
||||
void SetSystemConfig();
|
||||
bool IsAppMainOrSunOrFloatingWindow();
|
||||
void SetWindowCornerRadiusAccordingToSystemConfig();
|
||||
bool IsAppMainOrSubOrFloatingWindow();
|
||||
void UpdateWindowShadowAccordingToSystemConfig();
|
||||
|
||||
// colorspace, gamut
|
||||
using ColorSpaceConvertMap = struct {
|
||||
@@ -439,6 +444,8 @@ private:
|
||||
bool needRemoveWindowInputChannel_ = false;
|
||||
bool isListenerHandlerRunning_ = false;
|
||||
bool isMainHandlerAvailable_ = true;
|
||||
bool isAppFloatingWindow_ = false;
|
||||
bool isFocused_ = false;
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
+121
-13
@@ -34,6 +34,7 @@
|
||||
#include "window_manager_hilog.h"
|
||||
#include "wm_common.h"
|
||||
#include "wm_common_inner.h"
|
||||
#include "wm_math.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
@@ -778,6 +779,112 @@ void WindowImpl::UpdateTitleButtonVisibility()
|
||||
uiContent_->HideWindowTitleButton(hideSplitButton, hideMaximizeButton, false);
|
||||
}
|
||||
|
||||
bool WindowImpl::IsAppMainOrSubOrFloatingWindow()
|
||||
{
|
||||
// App main window need decor config, stretchable config and effect config
|
||||
// App sub window and float window need effect config
|
||||
if (WindowHelper::IsAppWindow(GetType())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (WindowHelper::IsAppFloatingWindow(GetType())) {
|
||||
for (auto& winPair : windowMap_) {
|
||||
auto win = winPair.second.second;
|
||||
if (win != nullptr && win->GetType() == WindowType::WINDOW_TYPE_APP_MAIN_WINDOW &&
|
||||
context_.get() == win->GetContext().get()) {
|
||||
isAppFloatingWindow_ = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void WindowImpl::SetWindowCornerRadiusAccordingToSystemConfig()
|
||||
{
|
||||
auto display = DisplayManager::GetInstance().GetDisplayById(property_->GetDisplayId());
|
||||
if (display == nullptr) {
|
||||
WLOGFE("get display failed displayId:%{public}" PRIu64", window id:%{public}u", property_->GetDisplayId(),
|
||||
property_->GetWindowId());
|
||||
return;
|
||||
}
|
||||
auto vpr = display->GetVirtualPixelRatio();
|
||||
auto fullscreenRadius = windowSystemConfig_.effectConfig_.fullScreenCornerRadius_ * vpr;
|
||||
auto splitRadius = windowSystemConfig_.effectConfig_.splitCornerRadius_ * vpr;
|
||||
auto floatRadius = windowSystemConfig_.effectConfig_.floatCornerRadius_ * vpr;
|
||||
|
||||
WLOGFI("[WEffect] [name:%{public}s] mode: %{public}u, vpr: %{public}f, [%{public}f, %{public}f, %{public}f]",
|
||||
name_.c_str(), GetMode(), vpr, fullscreenRadius, splitRadius, floatRadius);
|
||||
|
||||
if (WindowHelper::IsFullScreenWindow(GetMode()) && MathHelper::GreatNotEqual(fullscreenRadius, 0.0)) {
|
||||
SetCornerRadius(fullscreenRadius);
|
||||
} else if (WindowHelper::IsSplitWindowMode(GetMode()) && MathHelper::GreatNotEqual(splitRadius, 0.0)) {
|
||||
SetCornerRadius(splitRadius);
|
||||
} else if (WindowHelper::IsFloatingWindow(GetMode()) && MathHelper::GreatNotEqual(floatRadius, 0.0)) {
|
||||
SetCornerRadius(floatRadius);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowImpl::UpdateWindowShadowAccordingToSystemConfig()
|
||||
{
|
||||
if (!WindowHelper::IsAppWindow(GetType()) && !isAppFloatingWindow_) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& shadow = isFocused_ ? windowSystemConfig_.effectConfig_.focusedShadow_ :
|
||||
windowSystemConfig_.effectConfig_.unfocusedShadow_;
|
||||
|
||||
if (MathHelper::NearZero(shadow.elevation_)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!WindowHelper::IsFloatingWindow(GetMode())) {
|
||||
surfaceNode_->SetShadowElevation(0.f);
|
||||
WLOGFI("[WEffect][%{public}s]close shadow", name_.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
auto display = DisplayManager::GetInstance().GetDisplayById(property_->GetDisplayId());
|
||||
if (display == nullptr) {
|
||||
WLOGFE("get display failed displayId:%{public}" PRIu64", window id:%{public}u", property_->GetDisplayId(),
|
||||
property_->GetWindowId());
|
||||
return;
|
||||
}
|
||||
auto vpr = display->GetVirtualPixelRatio();
|
||||
|
||||
uint32_t colorValue;
|
||||
if (!ColorParser::Parse(shadow.color_, colorValue)) {
|
||||
WLOGFE("[WEffect]invalid color string: %{public}s", shadow.color_.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
WLOGFI("[WEffect][%{public}s]focused: %{public}u, [%{public}f, %{public}s, %{public}f, %{public}f, %{public}f]",
|
||||
name_.c_str(), isFocused_, shadow.elevation_, shadow.color_.c_str(),
|
||||
shadow.offsetX_, shadow.offsetY_, shadow.alpha_);
|
||||
|
||||
surfaceNode_->SetShadowElevation(shadow.elevation_ * vpr);
|
||||
surfaceNode_->SetShadowColor(colorValue);
|
||||
surfaceNode_->SetShadowOffsetX(shadow.offsetX_);
|
||||
surfaceNode_->SetShadowOffsetY(shadow.offsetY_);
|
||||
surfaceNode_->SetShadowAlpha(shadow.alpha_);
|
||||
}
|
||||
|
||||
void WindowImpl::SetSystemConfig()
|
||||
{
|
||||
if (IsAppMainOrSubOrFloatingWindow()) {
|
||||
if (SingletonContainer::Get<WindowAdapter>().GetSystemConfig(windowSystemConfig_) == WMError::WM_OK) {
|
||||
if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
|
||||
WLOGFI("get system decor enable:%{public}d", windowSystemConfig_.isSystemDecorEnable_);
|
||||
property_->SetDecorEnable(windowSystemConfig_.isSystemDecorEnable_);
|
||||
WLOGFI("get stretchable enable:%{public}d", windowSystemConfig_.isStretchable_);
|
||||
property_->SetStretchable(windowSystemConfig_.isStretchable_);
|
||||
}
|
||||
SetWindowCornerRadiusAccordingToSystemConfig();
|
||||
}
|
||||
UpdateWindowShadowAccordingToSystemConfig();
|
||||
}
|
||||
}
|
||||
|
||||
WMError WindowImpl::Create(const std::string& parentName, const std::shared_ptr<AbilityRuntime::Context>& context)
|
||||
{
|
||||
WLOGFI("[Client] Window [name:%{public}s] Create", name_.c_str());
|
||||
@@ -814,15 +921,10 @@ WMError WindowImpl::Create(const std::string& parentName, const std::shared_ptr<
|
||||
property_->SetTokenState(true);
|
||||
}
|
||||
}
|
||||
|
||||
SetSystemConfig();
|
||||
|
||||
if (WindowHelper::IsMainWindow(property_->GetWindowType())) {
|
||||
if (SingletonContainer::Get<WindowAdapter>().GetSystemConfig(windowSystemConfig_) == WMError::WM_OK) {
|
||||
WLOGFE("get system decor enable:%{public}d", windowSystemConfig_.isSystemDecorEnable_);
|
||||
if (windowSystemConfig_.isSystemDecorEnable_) {
|
||||
property_->SetDecorEnable(true);
|
||||
}
|
||||
WLOGFI("get stretchable enable:%{public}d", windowSystemConfig_.isStretchable_);
|
||||
property_->SetStretchable(windowSystemConfig_.isStretchable_);
|
||||
}
|
||||
GetConfigurationFromAbilityInfo();
|
||||
}
|
||||
WMError ret = SingletonContainer::Get<WindowAdapter>().CreateWindow(windowAgent, property_, surfaceNode_,
|
||||
@@ -1908,6 +2010,10 @@ void WindowImpl::UpdateMode(WindowMode mode)
|
||||
uiContent_->UpdateWindowMode(mode);
|
||||
WLOGFI("notify uiContent window mode change end");
|
||||
}
|
||||
// different modes have different corner radius settings
|
||||
SetWindowCornerRadiusAccordingToSystemConfig();
|
||||
// fullscreen and split have no shadow, float has shadow
|
||||
UpdateWindowShadowAccordingToSystemConfig();
|
||||
}
|
||||
|
||||
void WindowImpl::UpdateModeSupportInfo(uint32_t modeSupportInfo)
|
||||
@@ -2309,6 +2415,8 @@ void WindowImpl::UpdateFocusStatus(bool focused)
|
||||
} else {
|
||||
NotifyAfterUnfocused();
|
||||
}
|
||||
isFocused_ = focused;
|
||||
UpdateWindowShadowAccordingToSystemConfig();
|
||||
}
|
||||
|
||||
void WindowImpl::UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration)
|
||||
@@ -2738,7 +2846,7 @@ bool WindowImpl::CheckCameraFloatingWindowMultiCreated(WindowType type)
|
||||
WMError WindowImpl::SetCornerRadius(float cornerRadius)
|
||||
{
|
||||
WLOGFI("[Client] Window %{public}s set corner radius %{public}f", name_.c_str(), cornerRadius);
|
||||
if (WindowHelper::LessNotEqual(cornerRadius, 0.0)) {
|
||||
if (MathHelper::LessNotEqual(cornerRadius, 0.0)) {
|
||||
return WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
surfaceNode_->SetCornerRadius(cornerRadius);
|
||||
@@ -2748,7 +2856,7 @@ WMError WindowImpl::SetCornerRadius(float cornerRadius)
|
||||
WMError WindowImpl::SetShadowRadius(float radius)
|
||||
{
|
||||
WLOGFI("[Client] Window %{public}s set shadow radius %{public}f", name_.c_str(), radius);
|
||||
if (WindowHelper::LessNotEqual(radius, 0.0)) {
|
||||
if (MathHelper::LessNotEqual(radius, 0.0)) {
|
||||
return WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
surfaceNode_->SetShadowRadius(radius);
|
||||
@@ -2781,7 +2889,7 @@ void WindowImpl::SetShadowOffsetY(float offsetY)
|
||||
WMError WindowImpl::SetBlur(float radius)
|
||||
{
|
||||
WLOGFI("[Client] Window %{public}s set blur radius %{public}f", name_.c_str(), radius);
|
||||
if (WindowHelper::LessNotEqual(radius, 0.0)) {
|
||||
if (MathHelper::LessNotEqual(radius, 0.0)) {
|
||||
return WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
surfaceNode_->SetFilter(RSFilter::CreateBlurFilter(radius, radius));
|
||||
@@ -2791,7 +2899,7 @@ WMError WindowImpl::SetBlur(float radius)
|
||||
WMError WindowImpl::SetBackdropBlur(float radius)
|
||||
{
|
||||
WLOGFI("[Client] Window %{public}s set backdrop blur radius %{public}f", name_.c_str(), radius);
|
||||
if (WindowHelper::LessNotEqual(radius, 0.0)) {
|
||||
if (MathHelper::LessNotEqual(radius, 0.0)) {
|
||||
return WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
surfaceNode_->SetBackgroundFilter(RSFilter::CreateBlurFilter(radius, radius));
|
||||
@@ -2806,7 +2914,7 @@ WMError WindowImpl::SetBackdropBlurStyle(WindowBlurStyle blurStyle)
|
||||
}
|
||||
|
||||
if (blurStyle == WindowBlurStyle::WINDOW_BLUR_OFF) {
|
||||
surfaceNode_->SetBackgroundFilter(RSFilter::CreateBlurFilter(0.0, 0.0));
|
||||
surfaceNode_->SetBackgroundFilter(nullptr);
|
||||
} else {
|
||||
auto display = DisplayManager::GetInstance().GetDisplayById(property_->GetDisplayId());
|
||||
if (display == nullptr) {
|
||||
|
||||
@@ -35,6 +35,7 @@ public:
|
||||
STRING,
|
||||
INTS,
|
||||
FLOATS,
|
||||
POSITIVE_FLOATS,
|
||||
};
|
||||
struct ConfigItem {
|
||||
std::map<std::string, ConfigItem>* property_ = nullptr;
|
||||
@@ -249,7 +250,8 @@ private:
|
||||
static bool IsValidNode(const xmlNode& currNode);
|
||||
static void ReadProperty(const xmlNodePtr& currNode, std::map<std::string, ConfigItem>& property);
|
||||
static void ReadIntNumbersConfigInfo(const xmlNodePtr& currNode, std::vector<int>& intsValue);
|
||||
static void ReadFloatNumbersConfigInfo(const xmlNodePtr& currNode, std::vector<float>& floatsValue);
|
||||
static void ReadFloatNumbersConfigInfo(const xmlNodePtr& currNode, std::vector<float>& floatsValue, bool allowNeg);
|
||||
static void ReadStringConfigInfo(const xmlNodePtr& currNode, std::string& stringValue);
|
||||
static void ReadConfig(const xmlNodePtr& rootPtr, std::map<std::string, ConfigItem>& mapValue);
|
||||
static std::string GetConfigPath(const std::string& configFileName);
|
||||
};
|
||||
|
||||
@@ -156,6 +156,9 @@ private:
|
||||
void ConfigKeyboardAnimation(const WindowManagerConfig::ConfigItem& animeConfig);
|
||||
RSAnimationTimingCurve CreateCurve(const WindowManagerConfig::ConfigItem& curveConfig);
|
||||
void RecordShowTimeEvent(int64_t costTime);
|
||||
void ConfigWindowEffect(const WindowManagerConfig::ConfigItem& effectConfig);
|
||||
bool ConfigAppWindowCornerRadius(const WindowManagerConfig::ConfigItem& item, float& out);
|
||||
bool ConfigAppWindowShadow(const WindowManagerConfig::ConfigItem& shadowConfig, WindowShadowParameters& outShadow);
|
||||
|
||||
static inline SingletonDelegator<WindowManagerService> delegator;
|
||||
AtomicMap<uint32_t, uint32_t> accessTokenIdMaps_;
|
||||
|
||||
@@ -35,13 +35,27 @@ const std::map<std::string, WindowManagerConfig::ValueType> WindowManagerConfig:
|
||||
{ "windowAnimation", WindowManagerConfig::ValueType::MAP },
|
||||
{ "keyboardAnimation", WindowManagerConfig::ValueType::MAP },
|
||||
{ "timing", WindowManagerConfig::ValueType::MAP },
|
||||
{ "curve", WindowManagerConfig::ValueType::FLOATS },
|
||||
{ "splitRatios", WindowManagerConfig::ValueType::FLOATS },
|
||||
{ "exitSplitRatios", WindowManagerConfig::ValueType::FLOATS },
|
||||
{ "scale", WindowManagerConfig::ValueType::FLOATS },
|
||||
{ "rotation", WindowManagerConfig::ValueType::FLOATS },
|
||||
{ "translate", WindowManagerConfig::ValueType::FLOATS },
|
||||
{ "opacity", WindowManagerConfig::ValueType::FLOATS },
|
||||
{ "windowEffect", WindowManagerConfig::ValueType::MAP },
|
||||
{ "appWindows", WindowManagerConfig::ValueType::MAP },
|
||||
{ "cornerRadius", WindowManagerConfig::ValueType::MAP },
|
||||
{ "shadow", WindowManagerConfig::ValueType::MAP },
|
||||
{ "focused", WindowManagerConfig::ValueType::MAP },
|
||||
{ "unfocused", WindowManagerConfig::ValueType::MAP },
|
||||
{ "curve", WindowManagerConfig::ValueType::POSITIVE_FLOATS },
|
||||
{ "splitRatios", WindowManagerConfig::ValueType::POSITIVE_FLOATS },
|
||||
{ "exitSplitRatios", WindowManagerConfig::ValueType::POSITIVE_FLOATS },
|
||||
{ "scale", WindowManagerConfig::ValueType::POSITIVE_FLOATS },
|
||||
{ "rotation", WindowManagerConfig::ValueType::POSITIVE_FLOATS },
|
||||
{ "translate", WindowManagerConfig::ValueType::POSITIVE_FLOATS },
|
||||
{ "opacity", WindowManagerConfig::ValueType::POSITIVE_FLOATS },
|
||||
{ "elevation", WindowManagerConfig::ValueType::POSITIVE_FLOATS },
|
||||
{ "alpha", WindowManagerConfig::ValueType::POSITIVE_FLOATS },
|
||||
{ "offsetX", WindowManagerConfig::ValueType::FLOATS },
|
||||
{ "offsetY", WindowManagerConfig::ValueType::FLOATS },
|
||||
{ "fullScreen", WindowManagerConfig::ValueType::STRING },
|
||||
{ "split", WindowManagerConfig::ValueType::STRING },
|
||||
{ "float", WindowManagerConfig::ValueType::STRING },
|
||||
{ "color", WindowManagerConfig::ValueType::STRING },
|
||||
{ "decor", WindowManagerConfig::ValueType::UNDIFINED },
|
||||
{ "minimizeByOther", WindowManagerConfig::ValueType::UNDIFINED },
|
||||
{ "stretchable", WindowManagerConfig::ValueType::UNDIFINED },
|
||||
@@ -81,9 +95,15 @@ void WindowManagerConfig::ReadConfig(const xmlNodePtr& rootPtr, std::map<std::st
|
||||
mapValue[reinterpret_cast<const char*>(curNodePtr->name)].SetValue(v);
|
||||
break;
|
||||
}
|
||||
case ValueType::POSITIVE_FLOATS: {
|
||||
std::vector<float> v;
|
||||
ReadFloatNumbersConfigInfo(curNodePtr, v, false);
|
||||
mapValue[reinterpret_cast<const char*>(curNodePtr->name)].SetValue(v);
|
||||
break;
|
||||
}
|
||||
case ValueType::FLOATS: {
|
||||
std::vector<float> v;
|
||||
ReadFloatNumbersConfigInfo(curNodePtr, v);
|
||||
ReadFloatNumbersConfigInfo(curNodePtr, v, true);
|
||||
mapValue[reinterpret_cast<const char*>(curNodePtr->name)].SetValue(v);
|
||||
break;
|
||||
}
|
||||
@@ -93,6 +113,12 @@ void WindowManagerConfig::ReadConfig(const xmlNodePtr& rootPtr, std::map<std::st
|
||||
mapValue[reinterpret_cast<const char*>(curNodePtr->name)].SetValue(v);
|
||||
break;
|
||||
}
|
||||
case ValueType::STRING: {
|
||||
std::string v;
|
||||
ReadStringConfigInfo(curNodePtr, v);
|
||||
mapValue[reinterpret_cast<const char*>(curNodePtr->name)].SetValue(v);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -180,7 +206,7 @@ void WindowManagerConfig::ReadIntNumbersConfigInfo(const xmlNodePtr& currNode, s
|
||||
}
|
||||
|
||||
void WindowManagerConfig::ReadFloatNumbersConfigInfo(const xmlNodePtr& currNode,
|
||||
std::vector<float>& floatsValue)
|
||||
std::vector<float>& floatsValue, bool allowNeg)
|
||||
{
|
||||
xmlChar* context = xmlNodeGetContent(currNode);
|
||||
if (context == nullptr) {
|
||||
@@ -194,7 +220,7 @@ void WindowManagerConfig::ReadFloatNumbersConfigInfo(const xmlNodePtr& currNode,
|
||||
}
|
||||
auto numbers = WindowHelper::Split(numbersStr, " ");
|
||||
for (auto& num : numbers) {
|
||||
if (!WindowHelper::IsFloatingNumber(num)) {
|
||||
if (!WindowHelper::IsFloatingNumber(num, allowNeg)) {
|
||||
WLOGFE("[WmConfig] read float number error: nodeName:(%{public}s)", currNode->name);
|
||||
xmlFree(context);
|
||||
return;
|
||||
@@ -204,6 +230,18 @@ void WindowManagerConfig::ReadFloatNumbersConfigInfo(const xmlNodePtr& currNode,
|
||||
xmlFree(context);
|
||||
}
|
||||
|
||||
void WindowManagerConfig::ReadStringConfigInfo(const xmlNodePtr& currNode, std::string& stringValue)
|
||||
{
|
||||
xmlChar* context = xmlNodeGetContent(currNode);
|
||||
if (context == nullptr) {
|
||||
WLOGFE("[WmConfig] read xml node error: nodeName:(%{public}s)", currNode->name);
|
||||
return;
|
||||
}
|
||||
|
||||
stringValue = std::string(reinterpret_cast<const char*>(context));
|
||||
xmlFree(context);
|
||||
}
|
||||
|
||||
void WindowManagerConfig::DumpConfig(const std::map<std::string, ConfigItem>& config)
|
||||
{
|
||||
for (auto& conf : config) {
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <sstream>
|
||||
#include "xcollie/watchdog.h"
|
||||
|
||||
#include "color_parser.h"
|
||||
#include "display_manager_service_inner.h"
|
||||
#include "dm_common.h"
|
||||
#include "drag_controller.h"
|
||||
@@ -42,6 +43,7 @@
|
||||
#include "window_manager_agent_controller.h"
|
||||
#include "window_manager_hilog.h"
|
||||
#include "wm_common.h"
|
||||
#include "wm_math.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
@@ -342,6 +344,10 @@ void WindowManagerService::ConfigureWindowManagerService()
|
||||
if (item.IsMap()) {
|
||||
ConfigKeyboardAnimation(item);
|
||||
}
|
||||
item = config["windowEffect"];
|
||||
if (item.IsMap()) {
|
||||
ConfigWindowEffect(item);
|
||||
}
|
||||
}
|
||||
|
||||
void WindowManagerService::ConfigHotZones(const std::vector<int>& numbers)
|
||||
@@ -432,6 +438,105 @@ void WindowManagerService::ConfigKeyboardAnimation(const WindowManagerConfig::Co
|
||||
}
|
||||
}
|
||||
|
||||
bool WindowManagerService::ConfigAppWindowCornerRadius(const WindowManagerConfig::ConfigItem& item, float& out)
|
||||
{
|
||||
std::map<std::string, float> stringToCornerRadius = {
|
||||
{"off", 0.0f}, {"defaultCornerRadiusXS", 4.0f}, {"defaultCornerRadiusS", 8.0f},
|
||||
{"defaultCornerRadiusM", 12.0f}, {"defaultCornerRadiusL", 16.0f}, {"defaultCornerRadiusXL", 24.0f}
|
||||
};
|
||||
|
||||
if (item.IsString()) {
|
||||
auto value = item.stringValue_;
|
||||
if (stringToCornerRadius.find(value) != stringToCornerRadius.end()) {
|
||||
out = stringToCornerRadius[value];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool WindowManagerService::ConfigAppWindowShadow(const WindowManagerConfig::ConfigItem& shadowConfig,
|
||||
WindowShadowParameters& outShadow)
|
||||
{
|
||||
WindowManagerConfig::ConfigItem item = shadowConfig["elevation"];
|
||||
if (item.IsFloats()) {
|
||||
auto elevation = *item.floatsValue_;
|
||||
if (elevation.size() != 1 || (elevation.size() == 1 && MathHelper::LessNotEqual(elevation[0], 0.0))) {
|
||||
return false;
|
||||
}
|
||||
outShadow.elevation_ = elevation[0];
|
||||
}
|
||||
|
||||
item = shadowConfig["color"];
|
||||
if (item.IsString()) {
|
||||
auto color = item.stringValue_;
|
||||
uint32_t colorValue;
|
||||
if (!ColorParser::Parse(color, colorValue)) {
|
||||
return false;
|
||||
}
|
||||
outShadow.color_ = color;
|
||||
}
|
||||
|
||||
item = shadowConfig["offsetX"];
|
||||
if (item.IsFloats()) {
|
||||
auto offsetX = *item.floatsValue_;
|
||||
if (offsetX.size() != 1) {
|
||||
return false;
|
||||
}
|
||||
outShadow.offsetX_ = offsetX[0];
|
||||
}
|
||||
|
||||
item = shadowConfig["offsetY"];
|
||||
if (item.IsFloats()) {
|
||||
auto offsetY = *item.floatsValue_;
|
||||
if (offsetY.size() != 1) {
|
||||
return false;
|
||||
}
|
||||
outShadow.offsetY_ = offsetY[0];
|
||||
}
|
||||
|
||||
item = shadowConfig["alpha"];
|
||||
if (item.IsFloats()) {
|
||||
auto alpha = *item.floatsValue_;
|
||||
if (alpha.size() != 1 || (alpha.size() == 1 &&
|
||||
MathHelper::LessNotEqual(alpha[0], 0.0) && MathHelper::GreatNotEqual(alpha[0], 1.0))) {
|
||||
return false;
|
||||
}
|
||||
outShadow.alpha_ = alpha[0];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void WindowManagerService::ConfigWindowEffect(const WindowManagerConfig::ConfigItem& effectConfig)
|
||||
{
|
||||
AppWindowEffectConfig config;
|
||||
|
||||
// config corner radius
|
||||
WindowManagerConfig::ConfigItem item = effectConfig["appWindows"]["cornerRadius"];
|
||||
if (item.IsMap()) {
|
||||
if (ConfigAppWindowCornerRadius(item["fullScreen"], config.fullScreenCornerRadius_) &&
|
||||
ConfigAppWindowCornerRadius(item["split"], config.splitCornerRadius_) &&
|
||||
ConfigAppWindowCornerRadius(item["float"], config.floatCornerRadius_)) {
|
||||
systemConfig_.effectConfig_ = config;
|
||||
}
|
||||
}
|
||||
|
||||
// config shadow
|
||||
item = effectConfig["appWindows"]["shadow"]["focused"];
|
||||
if (item.IsMap()) {
|
||||
if (ConfigAppWindowShadow(item, config.focusedShadow_)) {
|
||||
systemConfig_.effectConfig_.focusedShadow_ = config.focusedShadow_;
|
||||
}
|
||||
}
|
||||
|
||||
item = effectConfig["appWindows"]["shadow"]["unfocused"];
|
||||
if (item.IsMap()) {
|
||||
if (ConfigAppWindowShadow(item, config.unfocusedShadow_)) {
|
||||
systemConfig_.effectConfig_.unfocusedShadow_ = config.unfocusedShadow_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RSAnimationTimingCurve WindowManagerService::CreateCurve(const WindowManagerConfig::ConfigItem& curveConfig)
|
||||
{
|
||||
const auto& nameItem = curveConfig.GetProp("name");
|
||||
@@ -835,8 +940,7 @@ WMError WindowManagerService::GetAccessibilityWindowInfo(sptr<AccessibilityWindo
|
||||
|
||||
WMError WindowManagerService::GetSystemConfig(SystemConfig& systemConfig)
|
||||
{
|
||||
systemConfig.isSystemDecorEnable_ = systemConfig_.isSystemDecorEnable_;
|
||||
systemConfig.isStretchable_ = systemConfig_.isStretchable_;
|
||||
systemConfig = systemConfig_;
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -479,8 +479,7 @@ WMError WindowManagerProxy::GetSystemConfig(SystemConfig& systemConfig)
|
||||
data, reply, option) != ERR_NONE) {
|
||||
return WMError::WM_ERROR_IPC_FAILED;
|
||||
}
|
||||
systemConfig.isSystemDecorEnable_ = reply.ReadBool();
|
||||
systemConfig.isStretchable_ = reply.ReadBool();
|
||||
systemConfig = *(reply.ReadParcelable<SystemConfig>());
|
||||
int32_t ret = reply.ReadInt32();
|
||||
return static_cast<WMError>(ret);
|
||||
}
|
||||
|
||||
@@ -158,8 +158,7 @@ int32_t WindowManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M
|
||||
case WindowManagerMessage::TRANS_ID_GET_SYSTEM_CONFIG: {
|
||||
SystemConfig config;
|
||||
WMError errCode = GetSystemConfig(config);
|
||||
reply.WriteBool(config.isSystemDecorEnable_);
|
||||
reply.WriteBool(config.isStretchable_);
|
||||
reply.WriteParcelable(&config);
|
||||
reply.WriteInt32(static_cast<int32_t>(errCode));
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user