mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-18 16:24:27 -04:00
Merge branch 'master' of gitee.com:openharmony/windowmanager into master
This commit is contained in:
+26
-17
@@ -22,27 +22,36 @@
|
||||
],
|
||||
"deps": {
|
||||
"components": [
|
||||
"inputmethod_native",
|
||||
"sensor",
|
||||
"ability_base",
|
||||
"libhilog",
|
||||
"ipc_core",
|
||||
"system_ability_fwk",
|
||||
"samgr_proxy",
|
||||
"image_native",
|
||||
"utils",
|
||||
"bytrace_core",
|
||||
"surface",
|
||||
"ability_context_native",
|
||||
"graphic_graphic_2d",
|
||||
"hisysevent_native",
|
||||
"ability_runtime",
|
||||
"want",
|
||||
"ace_uicontent",
|
||||
"appexecfwk_base",
|
||||
"appexecfwk_core",
|
||||
"inputmethod_client",
|
||||
"libmmi-client",
|
||||
"ace_napi",
|
||||
"resource_management"
|
||||
"napi",
|
||||
"common_event_service",
|
||||
"hilog_native",
|
||||
"access_token",
|
||||
"init",
|
||||
"bundle_framework",
|
||||
"hiviewdfx_hilog_native",
|
||||
"ipc",
|
||||
"power_manager_native",
|
||||
"utils_base",
|
||||
"hitrace_native",
|
||||
"resource_management",
|
||||
"samgr_standard",
|
||||
"input",
|
||||
"safwk",
|
||||
"display_manager_native",
|
||||
"config_policy",
|
||||
"ace_engine",
|
||||
"multimedia_image_standard"
|
||||
],
|
||||
"third_party": [
|
||||
"flutter",
|
||||
"libxml2",
|
||||
"libpng"
|
||||
]
|
||||
},
|
||||
"build": {
|
||||
|
||||
@@ -89,6 +89,8 @@ public:
|
||||
virtual bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId);
|
||||
virtual sptr<ScreenInfo> GetScreenInfo(ScreenId screenId);
|
||||
virtual bool SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio);
|
||||
virtual void SetScreenRotationLocked(bool isLocked);
|
||||
virtual bool IsScreenRotationLocked();
|
||||
|
||||
// colorspace, gamut
|
||||
virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts);
|
||||
|
||||
@@ -125,6 +125,20 @@ DMError ScreenManagerAdapter::SetVirtualScreenSurface(ScreenId screenId, sptr<Su
|
||||
return displayManagerServiceProxy_->SetVirtualScreenSurface(screenId, surface);
|
||||
}
|
||||
|
||||
void ScreenManagerAdapter::SetScreenRotationLocked(bool isLocked)
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN();
|
||||
WLOGFI("DisplayManagerAdapter::SetScreenRotationLocked");
|
||||
displayManagerServiceProxy_->SetScreenRotationLocked(isLocked);
|
||||
}
|
||||
|
||||
bool ScreenManagerAdapter::IsScreenRotationLocked()
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN(false);
|
||||
WLOGFI("DisplayManagerAdapter::IsScreenRotationLocked");
|
||||
return displayManagerServiceProxy_->IsScreenRotationLocked();
|
||||
}
|
||||
|
||||
bool ScreenManagerAdapter::SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason)
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN(false);
|
||||
|
||||
@@ -435,6 +435,16 @@ ScreenPowerState ScreenManager::GetScreenPower(ScreenId dmsScreenId)
|
||||
return SingletonContainer::Get<ScreenManagerAdapter>().GetScreenPower(dmsScreenId);
|
||||
}
|
||||
|
||||
void ScreenManager::SetScreenRotationLocked(bool isLocked)
|
||||
{
|
||||
SingletonContainer::Get<ScreenManagerAdapter>().SetScreenRotationLocked(isLocked);
|
||||
}
|
||||
|
||||
bool ScreenManager::IsScreenRotationLocked()
|
||||
{
|
||||
return SingletonContainer::Get<ScreenManagerAdapter>().IsScreenRotationLocked();
|
||||
}
|
||||
|
||||
void ScreenManager::Impl::NotifyScreenConnect(sptr<ScreenInfo> info)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
|
||||
@@ -83,6 +83,8 @@ ohos_systemtest("dm_screenshot_cmd_test") {
|
||||
]
|
||||
|
||||
deps = [ ":dm_systemtest_common" ]
|
||||
|
||||
external_deps = [ "hitrace_native:hitrace_meter" ]
|
||||
}
|
||||
|
||||
## SystemTest dm_screenshot_cmd_test }}}
|
||||
@@ -143,7 +145,6 @@ ohos_static_library("dm_systemtest_common") {
|
||||
"//foundation/windowmanager/dmserver:libdms",
|
||||
"//foundation/windowmanager/utils:libwmutil",
|
||||
"//foundation/windowmanager/wm:libwm",
|
||||
"//foundation/windowmanager/wmserver:libwms",
|
||||
"//third_party/googletest:gmock",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
|
||||
@@ -409,19 +409,6 @@ HWTEST_F(DisplayPowerTest, set_screen_brightness_001, Function | MediumTest | Le
|
||||
ASSERT_EQ(level, brightnessLevel_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: set_screen_brightness_002
|
||||
* @tc.desc: Call SetScreenBrightness with an invalid value and check the GetScreenBrightness return value
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DisplayPowerTest, set_screen_brightness_002, Function | MediumTest | Level2)
|
||||
{
|
||||
bool ret = DisplayManager::GetInstance().SetScreenBrightness(defaultId_, invalidBrightnessLevel_);
|
||||
ASSERT_EQ(true, ret);
|
||||
uint32_t level = DisplayManager::GetInstance().GetScreenBrightness(defaultId_);
|
||||
ASSERT_NE(level, invalidBrightnessLevel_);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: window_life_cycle_001
|
||||
* @tc.desc: Add a window and then call SuspendEnd and check window state; Notify unlock and check window state
|
||||
|
||||
@@ -425,56 +425,6 @@ HWTEST_F(ScreenManagerTest, ScreenManager08, Function | MediumTest | Level2)
|
||||
ScreenManager::GetInstance().UnregisterScreenGroupListener(screenGroupChangeListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenManager09
|
||||
* @tc.desc: Create a virtual screen as expansion of default screen, create windowNode on virtual screen,
|
||||
* and destroy virtual screen
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, ScreenManager09, Function | MediumTest | Level2)
|
||||
{
|
||||
DisplayTestUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
defaultOption_.surface_ = utils.psurface_;
|
||||
defaultOption_.isForShot_ = false;
|
||||
CHECK_TEST_INIT_SCREEN_STATE
|
||||
ScreenId virtualScreenId = ScreenManager::GetInstance().CreateVirtualScreen(defaultOption_);
|
||||
CHECK_SCREEN_STATE_AFTER_CREATE_VIRTUAL_SCREEN
|
||||
CheckScreenStateInGroup(false, group, groupId, virtualScreen, virtualScreenId);
|
||||
sleep(TEST_SLEEP_S);
|
||||
std::vector<ExpandOption> options = {{defaultScreenId_, 0, 0}, {virtualScreenId, defaultWidth_, 0}};
|
||||
ScreenId expansionId = ScreenManager::GetInstance().MakeExpand(options);
|
||||
CheckScreenGroupState(ScreenCombination::SCREEN_EXPAND, ScreenGroupChangeEvent::ADD_TO_GROUP,
|
||||
virtualScreenId, group, screenGroupChangeListener);
|
||||
CheckScreenStateInGroup(true, group, groupId, virtualScreen, virtualScreenId);
|
||||
sleep(TEST_SLEEP_S);
|
||||
ASSERT_NE(SCREEN_ID_INVALID, expansionId);
|
||||
DisplayId virtualDisplayId = DisplayManager::GetInstance().GetDisplayByScreen(virtualScreenId)->GetId();
|
||||
ASSERT_NE(DISPLAY_ID_INVALID, virtualDisplayId);
|
||||
sptr<Window> window = CreateWindowByDisplayId(virtualDisplayId);
|
||||
ASSERT_NE(nullptr, window);
|
||||
sleep(TEST_SLEEP_S);
|
||||
auto surfaceNode = window->GetSurfaceNode();
|
||||
auto rsUiDirector = RSUIDirector::Create();
|
||||
rsUiDirector->Init();
|
||||
RSTransaction::FlushImplicitTransaction();
|
||||
sleep(TEST_SLEEP_S);
|
||||
rsUiDirector->SetRSSurfaceNode(surfaceNode);
|
||||
RootNodeInit(rsUiDirector, 200, 400);
|
||||
rsUiDirector->SendMessages();
|
||||
sleep(TEST_SLEEP_S);
|
||||
ASSERT_EQ(DMError::DM_OK, ScreenManager::GetInstance().DestroyVirtualScreen(virtualScreenId));
|
||||
CHECK_SCREEN_STATE_AFTER_DESTROY_VIRTUAL_SCREEN
|
||||
CheckScreenGroupState(ScreenCombination::SCREEN_EXPAND, ScreenGroupChangeEvent::REMOVE_FROM_GROUP,
|
||||
virtualScreenId, group, screenGroupChangeListener);
|
||||
CheckScreenStateInGroup(false, group, groupId, virtualScreen, virtualScreenId);
|
||||
ScreenManager::GetInstance().UnregisterScreenListener(screenListener);
|
||||
ScreenManager::GetInstance().UnregisterScreenGroupListener(screenGroupChangeListener);
|
||||
sleep(TEST_SLEEP_S);
|
||||
window->Show();
|
||||
sleep(TEST_SLEEP_S_LONG);
|
||||
window->Destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenManager10
|
||||
@@ -743,6 +693,20 @@ HWTEST_F(ScreenManagerTest, ScreenManager17, Function | MediumTest | Level2)
|
||||
ASSERT_NE(SCREEN_ID_INVALID, virtualScreenId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenManager18
|
||||
* @tc.desc: Set screen rotation lock, and check whether screen rotation lock is Locked.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, ScreenManager18, Function | SmallTest | Level1)
|
||||
{
|
||||
bool originalLockStatus = ScreenManager::GetInstance().IsScreenRotationLocked();
|
||||
ScreenManager::GetInstance().SetScreenRotationLocked(!originalLockStatus);
|
||||
bool modifiedLockedStatus = ScreenManager::GetInstance().IsScreenRotationLocked();
|
||||
ScreenManager::GetInstance().SetScreenRotationLocked(originalLockStatus);
|
||||
ASSERT_EQ(!originalLockStatus, modifiedLockedStatus);
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenshotCmdTest"};
|
||||
}
|
||||
|
||||
using utils = DisplayTestUtils;
|
||||
using Utils = DisplayTestUtils;
|
||||
class ScreenshotCmdTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Rosen {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenshotTest"};
|
||||
}
|
||||
using utils = DisplayTestUtils;
|
||||
using Utils = DisplayTestUtils;
|
||||
class ScreenshotTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
@@ -109,7 +109,7 @@ HWTEST_F(ScreenshotTest, ScreenShotValid03, Function | MediumTest | Level2)
|
||||
ASSERT_NE(nullptr, screenshot);
|
||||
|
||||
Media::Size screenSize = {screenshot->GetWidth(), screenshot->GetHeight()};
|
||||
ASSERT_TRUE(utils::SizeEqualToDisplay(dm.GetDefaultDisplay(), screenSize));
|
||||
ASSERT_TRUE(Utils::SizeEqualToDisplay(dm.GetDefaultDisplay(), screenSize));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,20 +137,20 @@ HWTEST_F(ScreenshotTest, ScreenShotValid05, Function | MediumTest | Level2)
|
||||
defaultImage_, defaultRot_);
|
||||
ASSERT_NE(nullptr, screenshot);
|
||||
Media::Size screenSize = {screenshot->GetWidth(), screenshot->GetHeight()};
|
||||
ASSERT_TRUE(utils::SizeEqual(defaultImage_, screenSize));
|
||||
ASSERT_TRUE(Utils::SizeEqual(defaultImage_, screenSize));
|
||||
|
||||
Media::Size halfDefault_ = {defaultImage_.width / 2, defaultImage_.height / 2};
|
||||
Media::Rect halfRect = {defaultScreen_.left, defaultScreen_.top, halfDefault_.width, halfDefault_.height};
|
||||
screenshot = dm.GetScreenshot(defaultId_, halfRect, defaultImage_, defaultRot_);
|
||||
ASSERT_NE(nullptr, screenshot);
|
||||
screenSize = {screenshot->GetWidth(), screenshot->GetHeight()};
|
||||
ASSERT_TRUE(utils::SizeEqual(defaultImage_, screenSize));
|
||||
ASSERT_TRUE(Utils::SizeEqual(defaultImage_, screenSize));
|
||||
|
||||
Media::Size halfSize = {halfDefault_.width, halfDefault_.height};
|
||||
screenshot = dm.GetScreenshot(defaultId_, defaultScreen_, halfSize, defaultRot_);
|
||||
ASSERT_NE(nullptr, screenshot);
|
||||
screenSize = {screenshot->GetWidth(), screenshot->GetHeight()};
|
||||
ASSERT_TRUE(utils::SizeEqual(halfSize, screenSize));
|
||||
ASSERT_TRUE(Utils::SizeEqual(halfSize, screenSize));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,7 +165,7 @@ HWTEST_F(ScreenshotTest, ScreenShotValid06, Function | MediumTest | Level2)
|
||||
defaultImage_, defaultRot_);
|
||||
ASSERT_NE(nullptr, screenshot);
|
||||
Media::Size screenSize = {screenshot->GetWidth(), screenshot->GetHeight()};
|
||||
ASSERT_TRUE(utils::SizeEqualToDisplay(dm.GetDefaultDisplay(), screenSize));
|
||||
ASSERT_TRUE(Utils::SizeEqualToDisplay(dm.GetDefaultDisplay(), screenSize));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,6 +60,8 @@ ohos_unittest("dm_snapshot_utils_test") {
|
||||
]
|
||||
|
||||
deps = [ ":dm_unittest_common" ]
|
||||
|
||||
external_deps = [ "hitrace_native:hitrace_meter" ]
|
||||
}
|
||||
|
||||
## UnitTest dm_snapshot_utils_test }}}
|
||||
@@ -130,7 +132,6 @@ ohos_static_library("dm_unittest_common") {
|
||||
"//foundation/windowmanager/snapshot:snapshot_display",
|
||||
"//foundation/windowmanager/utils:libwmutil",
|
||||
"//foundation/windowmanager/wm:libwm",
|
||||
"//foundation/windowmanager/wmserver:libwms",
|
||||
"//third_party/googletest:gmock",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//third_party/libpng:libpng", # png
|
||||
|
||||
@@ -51,11 +51,11 @@ void ScreenManagerTest::TearDown()
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* @tc.name: CreateAndDestory01
|
||||
* @tc.name: CreateAndDestroy01
|
||||
* @tc.desc: CreateVirtualScreen with invalid option and return invalid screen id
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, CreateAndDestory01, Function | SmallTest | Level1)
|
||||
HWTEST_F(ScreenManagerTest, CreateAndDestroy01, Function | SmallTest | Level1)
|
||||
{
|
||||
VirtualScreenOption wrongOption = {defaultName_, defaultWidth_, defaultHeight_,
|
||||
defaultDensity_, nullptr, defaultFlags_};
|
||||
@@ -69,11 +69,11 @@ HWTEST_F(ScreenManagerTest, CreateAndDestory01, Function | SmallTest | Level1)
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CreateAndDestory02
|
||||
* @tc.name: CreateAndDestroy02
|
||||
* @tc.desc: CreateVirtualScreen with valid option and return valid screen id
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, CreateAndDestory02, Function | SmallTest | Level1)
|
||||
HWTEST_F(ScreenManagerTest, CreateAndDestroy02, Function | SmallTest | Level1)
|
||||
{
|
||||
ScreenManagerUtils utils;
|
||||
ASSERT_TRUE(utils.CreateSurface());
|
||||
|
||||
@@ -26,7 +26,7 @@ using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
using utils = TestUtils;
|
||||
using Utils = TestUtils;
|
||||
constexpr int32_t TEST_IMAGE_HEIGHT = 1080;
|
||||
constexpr int32_t TEST_IMAGE_WIDTH = 1920;
|
||||
using Mocker = SingletonMocker<DisplayManagerAdapter, MockDisplayManagerAdapter>;
|
||||
|
||||
+4
-3
@@ -57,7 +57,8 @@ ohos_shared_library("libdms") {
|
||||
|
||||
external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"graphic_standard:surface",
|
||||
"config_policy:configpolicy_util",
|
||||
"graphic_graphic_2d:surface",
|
||||
"hilog_native:libhilog",
|
||||
"hitrace_native:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
@@ -68,9 +69,9 @@ ohos_shared_library("libdms") {
|
||||
]
|
||||
|
||||
if (is_standard_system) {
|
||||
external_deps += [ "startup_l2:syspara" ]
|
||||
external_deps += [ "init:libbegetutil" ]
|
||||
} else {
|
||||
external_deps += [ "startup:syspara" ]
|
||||
external_deps += [ "init_lite:libbegetutil" ]
|
||||
}
|
||||
|
||||
part_name = "window_manager"
|
||||
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
bool SetRotation(ScreenId screenId, Rotation rotationAfter, bool isFromWindow);
|
||||
|
||||
bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId);
|
||||
std::shared_ptr<RSDisplayNode> GetRSDisplayNodeByScreenId(ScreenId dmsScreenId) const;
|
||||
const std::shared_ptr<RSDisplayNode>& GetRSDisplayNodeByScreenId(ScreenId dmsScreenId) const;
|
||||
void UpdateRSTree(ScreenId dmsScreenId, std::shared_ptr<RSSurfaceNode>& surfaceNode, bool isAdd);
|
||||
bool MakeMirror(ScreenId, std::vector<ScreenId> screens);
|
||||
bool MakeExpand(std::vector<ScreenId> screenIds, std::vector<Point> startPoints);
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
DisplayManagerConfig() = delete;
|
||||
~DisplayManagerConfig() = default;
|
||||
|
||||
static bool LoadConfigXml(const std::string& configFilePath);
|
||||
static bool LoadConfigXml();
|
||||
static const std::map<std::string, std::vector<int>>& GetIntNumbersConfig();
|
||||
static void DumpConfig();
|
||||
|
||||
@@ -39,6 +39,7 @@ private:
|
||||
|
||||
static bool IsValidNode(const xmlNode& currNode);
|
||||
static void ReadIntNumbersConfigInfo(const xmlNodePtr& currNode);
|
||||
static std::string GetConfigPath(const std::string& configFileName);
|
||||
|
||||
static std::vector<std::string> Split(std::string str, std::string pattern);
|
||||
static inline bool IsNumber(std::string str);
|
||||
|
||||
@@ -71,6 +71,8 @@ public:
|
||||
TRANS_ID_SCREEN_GET_GAMUT_MAP,
|
||||
TRANS_ID_SCREEN_SET_GAMUT_MAP,
|
||||
TRANS_ID_SCREEN_SET_COLOR_TRANSFORM,
|
||||
TRANS_ID_IS_SCREEN_ROTATION_LOCKED,
|
||||
TRANS_ID_SET_SCREEN_ROTATION_LOCKED,
|
||||
};
|
||||
|
||||
virtual sptr<DisplayInfo> GetDefaultDisplayInfo() = 0;
|
||||
@@ -83,6 +85,8 @@ public:
|
||||
virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface) = 0;
|
||||
virtual bool SetOrientation(ScreenId screenId, Orientation orientation) = 0;
|
||||
virtual std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId) = 0;
|
||||
virtual void SetScreenRotationLocked(bool isLocked) = 0;
|
||||
virtual bool IsScreenRotationLocked() = 0;
|
||||
|
||||
// colorspace, gamut
|
||||
virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts) = 0;
|
||||
|
||||
@@ -41,6 +41,8 @@ public:
|
||||
DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface) override;
|
||||
bool SetOrientation(ScreenId screenId, Orientation orientation) override;
|
||||
std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId) override;
|
||||
bool IsScreenRotationLocked() override;
|
||||
void SetScreenRotationLocked(bool isLocked) override;
|
||||
|
||||
// colorspace, gamut
|
||||
DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts) override;
|
||||
|
||||
@@ -35,9 +35,6 @@
|
||||
#include "singleton_delegator.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
namespace {
|
||||
const std::string DISPLAY_MANAGER_CONFIG_XML = "/system/etc/window/resources/display_manager_config.xml";
|
||||
}
|
||||
class DisplayManagerService : public SystemAbility, public DisplayManagerStub {
|
||||
DECLARE_SYSTEM_ABILITY(DisplayManagerService);
|
||||
WM_DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerService);
|
||||
@@ -50,6 +47,8 @@ public:
|
||||
const sptr<IRemoteObject>& displayManagerAgent) override;
|
||||
DMError DestroyVirtualScreen(ScreenId screenId) override;
|
||||
DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface) override;
|
||||
bool IsScreenRotationLocked() override;
|
||||
void SetScreenRotationLocked(bool isLocked) override;
|
||||
|
||||
sptr<DisplayInfo> GetDefaultDisplayInfo() override;
|
||||
sptr<DisplayInfo> GetDisplayInfoById(DisplayId displayId) override;
|
||||
@@ -57,6 +56,7 @@ public:
|
||||
bool SetOrientation(ScreenId screenId, Orientation orientation) override;
|
||||
bool SetOrientationFromWindow(ScreenId screenId, Orientation orientation);
|
||||
bool SetRotationFromWindow(ScreenId screenId, Rotation targetRotation);
|
||||
void SetGravitySensorSubscriptionEnabled();
|
||||
std::shared_ptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId) override;
|
||||
ScreenId GetRSScreenId(DisplayId displayId) const;
|
||||
|
||||
@@ -98,6 +98,7 @@ public:
|
||||
bool SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio) override;
|
||||
static float GetCustomVirtualPixelRatio();
|
||||
void RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener);
|
||||
void GetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation);
|
||||
private:
|
||||
DisplayManagerService();
|
||||
~DisplayManagerService() = default;
|
||||
@@ -117,6 +118,7 @@ private:
|
||||
sptr<DisplayDumper> displayDumper_;
|
||||
static float customVirtualPixelRatio_;
|
||||
std::map<ScreenId, uint32_t> accessTokenIdMaps_;
|
||||
bool isAutoRotationOpen_;
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@ public:
|
||||
void RegisterDisplayChangeListener(sptr<IDisplayChangeListener> listener);
|
||||
bool SetOrientationFromWindow(DisplayId displayId, Orientation orientation);
|
||||
bool SetRotationFromWindow(DisplayId displayId, Rotation targetRotation);
|
||||
void SetGravitySensorSubscriptionEnabled();
|
||||
void GetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation);
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#ifndef OHOS_ROSEN_SCREEN_ROTATION_CONTROLLER_H
|
||||
#define OHOS_ROSEN_SCREEN_ROTATION_CONTROLLER_H
|
||||
|
||||
#include <map>
|
||||
#include <refbase.h>
|
||||
|
||||
#include "sensor_agent.h"
|
||||
@@ -25,6 +26,22 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
enum class SensorRotation: int32_t {
|
||||
INVALID = -1,
|
||||
ROTATION_0 = 0,
|
||||
ROTATION_90,
|
||||
ROTATION_180,
|
||||
ROTATION_270,
|
||||
};
|
||||
|
||||
enum class DeviceRotation: int32_t {
|
||||
INVALID = -1,
|
||||
ROTATION_PORTRAIT = 0,
|
||||
ROTATION_LANDSCAPE,
|
||||
ROTATION_PORTRAIT_INVERTED,
|
||||
ROTATION_LANDSCAPE_INVERTED,
|
||||
};
|
||||
|
||||
class ScreenRotationController : public RefBase {
|
||||
public:
|
||||
ScreenRotationController() = delete;
|
||||
@@ -34,27 +51,55 @@ public:
|
||||
static bool IsScreenRotationLocked();
|
||||
static void SetScreenRotationLocked(bool isLocked);
|
||||
static void SetDefaultDeviceRotationOffset(uint32_t defaultDeviceRotationOffset);
|
||||
static bool IsGravitySensorEnabled();
|
||||
static void ProcessOrientationSwitch(Orientation orientation);
|
||||
private:
|
||||
static void HandleGravitySensorEventCallback(SensorEvent *event);
|
||||
static Rotation GetCurrentDisplayRotation();
|
||||
static Orientation GetDisplayOrientation();
|
||||
static int CalcRotationDegree(GravityData* gravityData);
|
||||
static Rotation CalcTargetDisplayRotation(Orientation requestedOrientation, Rotation sensorRotation);
|
||||
static Rotation ProcessAutoRotationPortraitOrientation(Rotation sensorRotation);
|
||||
static Rotation ProcessAutoRotationLandscapeOrientation(Rotation sensorRotation);
|
||||
static void SetScreenRotation(Rotation targetRotation);
|
||||
static bool CheckCallbackTimeInterval();
|
||||
static int CalcSensorDisplayRotation(int orientationDegree);
|
||||
static Rotation ConvertToDeviceRotation(Rotation sensorRotation);
|
||||
static Rotation GetCurrentDisplayRotation();
|
||||
static Orientation GetPreferredOrientation();
|
||||
static void SetScreenRotation(Rotation targetRotation);
|
||||
static int CalcRotationDegree(GravityData* gravityData);
|
||||
static Rotation CalcTargetDisplayRotation(Orientation requestedOrientation,
|
||||
DeviceRotation sensorRotationConverted);
|
||||
static DeviceRotation CalcDeviceRotation(SensorRotation sensorRotation);
|
||||
static SensorRotation CalcSensorRotation(int sensorDegree);
|
||||
static DeviceRotation ConvertSensorToDeviceRotation(SensorRotation sensorRotation);
|
||||
static Rotation ConvertDeviceToDisplayRotation(DeviceRotation sensorRotationConverted);
|
||||
|
||||
static bool IsDeviceRotationVertical(DeviceRotation deviceRotation);
|
||||
static bool IsDeviceRotationHorizontal(DeviceRotation deviceRotation);
|
||||
static bool IsCurrentDisplayVertical();
|
||||
static bool IsCurrentDisplayHorizontal();
|
||||
static bool IsDisplayRotationVertical(Rotation rotation);
|
||||
static bool IsDisplayRotationHorizontal(Rotation rotation);
|
||||
static bool IsSensorRelatedOrientation(Orientation orientation);
|
||||
|
||||
static void ProcessRotationMapping();
|
||||
static void ProcessSwitchToAutoRotationPortrait(DeviceRotation rotation);
|
||||
static void ProcessSwitchToAutoRotationLandscape(DeviceRotation rotation);
|
||||
static void ProcessSwitchToAutoRotation(DeviceRotation rotation);
|
||||
static void ProcessSwitchToAutoRotationPortraitRestricted();
|
||||
static void ProcessSwitchToAutoRotationLandscapeRestricted();
|
||||
static void ProcessSwitchToSensorRelatedOrientation(Orientation orientation, DeviceRotation deviceRotation);
|
||||
static void ProcessSwitchToSensorUnrelatedOrientation(Orientation orientation);
|
||||
static Rotation ProcessAutoRotationPortraitOrientation(DeviceRotation sensorRotationConveted);
|
||||
static Rotation ProcessAutoRotationLandscapeOrientation(DeviceRotation sensorRotationConveted);
|
||||
|
||||
static DisplayId defaultDisplayId_;
|
||||
static SensorUser user_;
|
||||
static uint32_t defaultDeviceRotationOffset_;
|
||||
static uint32_t defaultDeviceRotation_;
|
||||
static std::map<SensorRotation, DeviceRotation> sensorToDeviceRotationMap_;
|
||||
static std::map<DeviceRotation, Rotation> deviceToDisplayRotationMap_;
|
||||
static long lastCallbackTime_;
|
||||
static Orientation lastOrientationType_;
|
||||
static Rotation currentDisplayRotation_;
|
||||
static Rotation lastSensorDecidedRotation_;
|
||||
static Rotation rotationLockedRotation_;
|
||||
static bool isGravitySensorSubscribed_;
|
||||
static bool isScreenRotationLocked_;
|
||||
static SensorUser user_;
|
||||
static Rotation currentDisplayRotation_;
|
||||
static long lastCallbackTime_;
|
||||
static uint32_t defaultDeviceRotationOffset_;
|
||||
static DeviceRotation lastSensorRotationConverted_;
|
||||
};
|
||||
} // Rosen
|
||||
} // OHOS
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
#include "abstract_display_controller.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <hitrace_meter.h>
|
||||
#include <surface.h>
|
||||
|
||||
#include "display_manager_agent_controller.h"
|
||||
#include "display_manager_service.h"
|
||||
#include "screen_group.h"
|
||||
#include "window_manager_hilog.h"
|
||||
#include "wm_trace.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
namespace {
|
||||
@@ -108,7 +108,7 @@ std::shared_ptr<Media::PixelMap> AbstractDisplayController::GetScreenSnapshot(Di
|
||||
{
|
||||
sptr<AbstractDisplay> abstractDisplay = GetAbstractDisplay(displayId);
|
||||
if (abstractDisplay == nullptr) {
|
||||
WLOGFE("GetScreenSnapshot: GetAbstarctDisplay failed");
|
||||
WLOGFE("GetScreenSnapshot: GetAbstractDisplay failed");
|
||||
return nullptr;
|
||||
}
|
||||
ScreenId dmsScreenId = abstractDisplay->GetAbstractScreenId();
|
||||
@@ -357,7 +357,7 @@ void AbstractDisplayController::ProcessDisplayUpdateOrientation(sptr<AbstractScr
|
||||
|
||||
void AbstractDisplayController::ProcessDisplaySizeChange(sptr<AbstractScreen> absScreen)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:ProcessDisplaySizeChange(%" PRIu64")", absScreen->dmsId_);
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:ProcessDisplaySizeChange(%" PRIu64")", absScreen->dmsId_);
|
||||
sptr<SupportedScreenModes> info = absScreen->GetActiveScreenMode();
|
||||
if (info == nullptr) {
|
||||
WLOGE("cannot get active screen info.");
|
||||
@@ -531,13 +531,13 @@ void AbstractDisplayController::AddScreenToExpandLocked(sptr<AbstractScreen> abs
|
||||
|
||||
void AbstractDisplayController::SetFreeze(std::vector<DisplayId> displayIds, bool toFreeze)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:SetAllFreeze");
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetAllFreeze");
|
||||
DisplayStateChangeType type = toFreeze ? DisplayStateChangeType::FREEZE : DisplayStateChangeType::UNFREEZE;
|
||||
DisplayChangeEvent event
|
||||
= toFreeze ? DisplayChangeEvent::DISPLAY_FREEZED : DisplayChangeEvent::DISPLAY_UNFREEZED;
|
||||
for (DisplayId displayId : displayIds) {
|
||||
sptr<AbstractDisplay> abstractDisplay;
|
||||
WM_SCOPED_TRACE("dms:SetFreeze(%" PRIu64")", displayId);
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetFreeze(%" PRIu64")", displayId);
|
||||
{
|
||||
WLOGI("setfreeze display %{public}" PRIu64"", displayId);
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
|
||||
@@ -37,7 +37,7 @@ AbstractScreen::~AbstractScreen()
|
||||
|
||||
sptr<SupportedScreenModes> AbstractScreen::GetActiveScreenMode() const
|
||||
{
|
||||
if (activeIdx_ < 0 || activeIdx_ >= modes_.size()) {
|
||||
if (activeIdx_ < 0 || activeIdx_ >= static_cast<int32_t>(modes_.size())) {
|
||||
WLOGE("active mode index is wrong: %{public}d", activeIdx_);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -243,7 +243,7 @@ Rotation AbstractScreen::CalcRotation(Orientation orientation) const
|
||||
if (info == nullptr) {
|
||||
return Rotation::ROTATION_0;
|
||||
}
|
||||
// virtical: phone(Plugin screen); horizontal: pad & external screen
|
||||
// vertical: phone(Plugin screen); horizontal: pad & external screen
|
||||
bool isVerticalScreen = info->width_ < info->height_;
|
||||
switch (orientation) {
|
||||
case Orientation::UNSPECIFIED: {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "abstract_screen_controller.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <hitrace_meter.h>
|
||||
#include <screen_manager/rs_screen_mode_info.h>
|
||||
#include <screen_manager/screen_types.h>
|
||||
#include <surface.h>
|
||||
@@ -24,8 +25,8 @@
|
||||
#include "display_manager_agent_controller.h"
|
||||
#include "display_manager_service.h"
|
||||
#include "event_runner.h"
|
||||
#include "screen_rotation_controller.h"
|
||||
#include "window_manager_hilog.h"
|
||||
#include "wm_trace.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
namespace {
|
||||
@@ -40,9 +41,7 @@ AbstractScreenController::AbstractScreenController(std::recursive_mutex& mutex)
|
||||
controllerHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
|
||||
}
|
||||
|
||||
AbstractScreenController::~AbstractScreenController()
|
||||
{
|
||||
}
|
||||
AbstractScreenController::~AbstractScreenController() = default;
|
||||
|
||||
void AbstractScreenController::Init()
|
||||
{
|
||||
@@ -54,13 +53,12 @@ void AbstractScreenController::RegisterRsScreenConnectionChangeListener()
|
||||
{
|
||||
WLOGFD("RegisterRsScreenConnectionChangeListener");
|
||||
auto res = rsInterface_.SetScreenChangeCallback(
|
||||
std::bind(&AbstractScreenController::OnRsScreenConnectionChange,
|
||||
this, std::placeholders::_1, std::placeholders::_2));
|
||||
[this](ScreenId rsScreenId, ScreenEvent screenEvent) { OnRsScreenConnectionChange(rsScreenId, screenEvent); });
|
||||
if (res != StatusCode::SUCCESS) {
|
||||
auto task = [this] {
|
||||
RegisterRsScreenConnectionChangeListener();
|
||||
};
|
||||
// posk task after 50 ms.
|
||||
// post task after 50 ms.
|
||||
controllerHandler_->PostTask(task, 50, AppExecFwk::EventQueue::Priority::HIGH);
|
||||
}
|
||||
bool callbackRegister = DisplayManagerAgentController::GetInstance().SetRemoveAgentCallback(
|
||||
@@ -75,8 +73,8 @@ std::vector<ScreenId> AbstractScreenController::GetAllScreenIds() const
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
std::vector<ScreenId> res;
|
||||
for (auto iter = dmsScreenMap_.begin(); iter != dmsScreenMap_.end(); iter++) {
|
||||
res.emplace_back(iter->first);
|
||||
for (const auto& iter : dmsScreenMap_) {
|
||||
res.emplace_back(iter.first);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -132,7 +130,7 @@ std::vector<ScreenId> AbstractScreenController::GetAllExpandOrMirrorScreenIds(
|
||||
return screenIds;
|
||||
}
|
||||
|
||||
std::shared_ptr<RSDisplayNode> AbstractScreenController::GetRSDisplayNodeByScreenId(ScreenId dmsScreenId) const
|
||||
const std::shared_ptr<RSDisplayNode>& AbstractScreenController::GetRSDisplayNodeByScreenId(ScreenId dmsScreenId) const
|
||||
{
|
||||
sptr<AbstractScreen> screen = GetAbstractScreen(dmsScreenId);
|
||||
if (screen == nullptr) {
|
||||
@@ -174,7 +172,7 @@ sptr<AbstractScreenGroup> AbstractScreenController::GetAbstractScreenGroup(Scree
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
auto iter = dmsScreenGroupMap_.find(dmsScreenId);
|
||||
if (iter == dmsScreenGroupMap_.end()) {
|
||||
WLOGE("didnot find screen:%{public}" PRIu64"", dmsScreenId);
|
||||
WLOGE("did not find screen:%{public}" PRIu64"", dmsScreenId);
|
||||
return nullptr;
|
||||
}
|
||||
return iter->second;
|
||||
@@ -497,7 +495,7 @@ ScreenId AbstractScreenController::CreateVirtualScreen(VirtualScreenOption optio
|
||||
}
|
||||
std::vector<ScreenId> virtualScreenIds;
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
std::map<sptr<IRemoteObject>, std::vector<ScreenId>>::iterator agIter = screenAgentMap_.find(displayManagerAgent);
|
||||
auto agIter = screenAgentMap_.find(displayManagerAgent);
|
||||
if (agIter == screenAgentMap_.end()) {
|
||||
if (!RegisterVirtualScreenAgent(displayManagerAgent)) {
|
||||
return SCREEN_ID_INVALID;
|
||||
@@ -556,7 +554,7 @@ DMError AbstractScreenController::DestroyVirtualScreen(ScreenId screenId)
|
||||
}
|
||||
}
|
||||
|
||||
std::map<ScreenId, std::shared_ptr<RSDisplayNode>>::iterator iter = displayNodeMap_.find(rsScreenId);
|
||||
auto iter = displayNodeMap_.find(rsScreenId);
|
||||
if (iter == displayNodeMap_.end()) {
|
||||
WLOGFI("displayNode is nullptr");
|
||||
} else {
|
||||
@@ -610,24 +608,22 @@ bool AbstractScreenController::SetOrientation(ScreenId screenId, Orientation new
|
||||
return false;
|
||||
}
|
||||
if (isFromWindow) {
|
||||
if (newOrientation == Orientation::UNSPECIFIED) {
|
||||
newOrientation = screen->screenRequestedOrientation_;
|
||||
}
|
||||
ScreenRotationController::ProcessOrientationSwitch(newOrientation);
|
||||
} else {
|
||||
screen->screenRequestedOrientation_ = newOrientation;
|
||||
Rotation rotationAfter = screen->CalcRotation(newOrientation);
|
||||
SetRotation(screenId, rotationAfter, false);
|
||||
screen->rotation_ = rotationAfter;
|
||||
}
|
||||
if (screen->orientation_ == newOrientation) {
|
||||
WLOGI("skip setting orientation. screen %{public}" PRIu64" orientation %{public}u", screenId, newOrientation);
|
||||
return true;
|
||||
}
|
||||
|
||||
Rotation rotationAfter = screen->CalcRotation(newOrientation);
|
||||
SetRotation(screenId, rotationAfter, false);
|
||||
|
||||
if (!screen->SetOrientation(newOrientation)) {
|
||||
WLOGE("fail to set rotation, screen %{public}" PRIu64"", screenId);
|
||||
return false;
|
||||
}
|
||||
screen->rotation_ = rotationAfter;
|
||||
|
||||
// Notify rotation event to ScreenManager
|
||||
NotifyScreenChanged(screen->ConvertToScreenInfo(), ScreenChangeEvent::UPDATE_ORIENTATION);
|
||||
@@ -642,7 +638,7 @@ bool AbstractScreenController::SetRotation(ScreenId screenId, Rotation rotationA
|
||||
{
|
||||
auto screen = GetAbstractScreen(screenId);
|
||||
if (rotationAfter != screen->rotation_) {
|
||||
WLOGI("set orientation. roatiton %{public}u", rotationAfter);
|
||||
WLOGI("set orientation. rotation %{public}u", rotationAfter);
|
||||
ScreenId rsScreenId;
|
||||
if (!screenIdManager_.ConvertToRsScreenId(screenId, rsScreenId)) {
|
||||
WLOGE("Convert to RsScreenId fail. screenId: %{public}" PRIu64"", screenId);
|
||||
@@ -760,7 +756,7 @@ bool AbstractScreenController::SetScreenActiveMode(ScreenId screenId, uint32_t m
|
||||
|
||||
void AbstractScreenController::ProcessScreenModeChanged(ScreenId dmsScreenId)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:ProcessScreenModeChanged(%" PRIu64")", dmsScreenId);
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:ProcessScreenModeChanged(%" PRIu64")", dmsScreenId);
|
||||
sptr<AbstractScreen> absScreen = nullptr;
|
||||
sptr<AbstractScreenCallback> absScreenCallback = nullptr;
|
||||
{
|
||||
@@ -966,7 +962,7 @@ bool AbstractScreenController::OnRemoteDied(const sptr<IRemoteObject>& agent)
|
||||
if (agent == nullptr) {
|
||||
return false;
|
||||
}
|
||||
std::map<sptr<IRemoteObject>, std::vector<ScreenId>>::iterator agentIter = screenAgentMap_.find(agent);
|
||||
auto agentIter = screenAgentMap_.find(agent);
|
||||
if (agentIter != screenAgentMap_.end()) {
|
||||
while (screenAgentMap_[agent].size() > 0) {
|
||||
auto diedId = screenAgentMap_[agent][0];
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "display_manager_config.h"
|
||||
#include "config_policy_utils.h"
|
||||
#include "window_manager_hilog.h"
|
||||
|
||||
namespace OHOS {
|
||||
@@ -51,8 +52,21 @@ bool inline DisplayManagerConfig::IsNumber(std::string str)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DisplayManagerConfig::LoadConfigXml(const std::string& configFilePath)
|
||||
std::string DisplayManagerConfig::GetConfigPath(const std::string& configFileName)
|
||||
{
|
||||
char buf[PATH_MAX + 1];
|
||||
char* configPath = GetOneCfgFile(configFileName.c_str(), buf, PATH_MAX + 1);
|
||||
char tmpPath[PATH_MAX + 1] = { 0 };
|
||||
if (!configPath || strlen(configPath) == 0 || strlen(configPath) > PATH_MAX || !realpath(configPath, tmpPath)) {
|
||||
WLOGFI("[DmConfig] can not get customization config file");
|
||||
return "/system/" + configFileName;
|
||||
}
|
||||
return std::string(tmpPath);
|
||||
}
|
||||
|
||||
bool DisplayManagerConfig::LoadConfigXml()
|
||||
{
|
||||
auto configFilePath = GetConfigPath("etc/window/resources/display_manager_config.xml");
|
||||
xmlDocPtr docPtr = xmlReadFile(configFilePath.c_str(), nullptr, XML_PARSE_NOBLANKS);
|
||||
WLOGFI("[DmConfig] filePath: %{public}s", configFilePath.c_str());
|
||||
if (docPtr == nullptr) {
|
||||
@@ -76,7 +90,8 @@ bool DisplayManagerConfig::LoadConfigXml(const std::string& configFilePath)
|
||||
|
||||
auto nodeName = curNodePtr->name;
|
||||
if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("dpi")) ||
|
||||
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("defaultDeviceRotationOffset"))) {
|
||||
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("defaultDeviceRotationOffset")) ||
|
||||
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("cutoutArea"))) {
|
||||
ReadIntNumbersConfigInfo(curNodePtr);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1005,4 +1005,53 @@ bool DisplayManagerProxy::SetVirtualPixelRatio(ScreenId screenId, float virtualP
|
||||
}
|
||||
return reply.ReadBool();
|
||||
}
|
||||
|
||||
bool DisplayManagerProxy::IsScreenRotationLocked()
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
WLOGFW("IsScreenRotationLocked: remote is nullptr");
|
||||
return false;
|
||||
}
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("IsScreenRotationLocked: WriteInterfaceToken failed");
|
||||
return false;
|
||||
}
|
||||
if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_IS_SCREEN_ROTATION_LOCKED),
|
||||
data, reply, option) != ERR_NONE) {
|
||||
WLOGFW("IsScreenRotationLocked: SendRequest failed");
|
||||
return false;
|
||||
}
|
||||
bool isLocked = reply.ReadBool();
|
||||
return isLocked;
|
||||
}
|
||||
|
||||
void DisplayManagerProxy::SetScreenRotationLocked(bool isLocked)
|
||||
{
|
||||
sptr<IRemoteObject> remote = Remote();
|
||||
if (remote == nullptr) {
|
||||
WLOGFW("SetScreenRotationLocked: remote is null");
|
||||
return;
|
||||
}
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
if (!data.WriteInterfaceToken(GetDescriptor())) {
|
||||
WLOGFE("SetScreenRotationLocked: WriteInterfaceToken failed");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteBool(isLocked)) {
|
||||
WLOGFE("SetScreenRotationLocked: write isLocked failed");
|
||||
return;
|
||||
}
|
||||
if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED),
|
||||
data, reply, option) != ERR_NONE) {
|
||||
WLOGFE("SetScreenRotationLocked: SendRequest failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "display_manager_service.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <hitrace_meter.h>
|
||||
#include <ipc_skeleton.h>
|
||||
#include <iservice_registry.h>
|
||||
#include <system_ability_definition.h>
|
||||
@@ -23,11 +24,11 @@
|
||||
#include "display_manager_agent_controller.h"
|
||||
#include "display_manager_config.h"
|
||||
#include "dm_common.h"
|
||||
#include "parameters.h"
|
||||
#include "permission.h"
|
||||
#include "screen_rotation_controller.h"
|
||||
#include "transaction/rs_interfaces.h"
|
||||
#include "window_manager_hilog.h"
|
||||
#include "wm_trace.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
namespace {
|
||||
@@ -52,7 +53,9 @@ DisplayManagerService::DisplayManagerService() : SystemAbility(DISPLAY_MANAGER_S
|
||||
abstractScreenController_(new AbstractScreenController(mutex_)),
|
||||
displayPowerController_(new DisplayPowerController(mutex_,
|
||||
std::bind(&DisplayManagerService::NotifyDisplayStateChange, this,
|
||||
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)))
|
||||
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4))),
|
||||
isAutoRotationOpen_(OHOS::system::GetParameter(
|
||||
"persist.display.ar.enabled", "1") == "1") // autoRotation default enabled
|
||||
{
|
||||
}
|
||||
|
||||
@@ -81,7 +84,7 @@ bool DisplayManagerService::Init()
|
||||
WLOGFW("DisplayManagerService::Init failed");
|
||||
return false;
|
||||
}
|
||||
if (DisplayManagerConfig::LoadConfigXml(DISPLAY_MANAGER_CONFIG_XML)) {
|
||||
if (DisplayManagerConfig::LoadConfigXml()) {
|
||||
DisplayManagerConfig::DumpConfig();
|
||||
ConfigureDisplayManagerService();
|
||||
}
|
||||
@@ -130,6 +133,13 @@ void DisplayManagerService::NotifyDisplayStateChange(DisplayId defaultDisplayId,
|
||||
}
|
||||
}
|
||||
|
||||
void DisplayManagerService::GetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation)
|
||||
{
|
||||
if (displayChangeListener_ != nullptr) {
|
||||
displayChangeListener_->OnGetWindowPreferredOrientation(displayId, orientation);
|
||||
}
|
||||
}
|
||||
|
||||
sptr<DisplayInfo> DisplayManagerService::GetDefaultDisplayInfo()
|
||||
{
|
||||
ScreenId dmsScreenId = abstractScreenController_->GetDefaultAbstractScreenId();
|
||||
@@ -165,7 +175,7 @@ sptr<DisplayInfo> DisplayManagerService::GetDisplayInfoByScreen(ScreenId screenI
|
||||
ScreenId DisplayManagerService::CreateVirtualScreen(VirtualScreenOption option,
|
||||
const sptr<IRemoteObject>& displayManagerAgent)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:CreateVirtualScreen(%s)", option.name_.c_str());
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:CreateVirtualScreen(%s)", option.name_.c_str());
|
||||
ScreenId screenId = abstractScreenController_->CreateVirtualScreen(option, displayManagerAgent);
|
||||
CHECK_SCREEN_AND_RETURN(SCREEN_ID_INVALID);
|
||||
accessTokenIdMaps_[screenId] = IPCSkeleton::GetCallingTokenID();
|
||||
@@ -181,7 +191,7 @@ DMError DisplayManagerService::DestroyVirtualScreen(ScreenId screenId)
|
||||
WLOGFI("DestroyVirtualScreen::ScreenId: %{public}" PRIu64 "", screenId);
|
||||
CHECK_SCREEN_AND_RETURN(DMError::DM_ERROR_INVALID_PARAM);
|
||||
|
||||
WM_SCOPED_TRACE("dms:DestroyVirtualScreen(%" PRIu64")", screenId);
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:DestroyVirtualScreen(%" PRIu64")", screenId);
|
||||
return abstractScreenController_->DestroyVirtualScreen(screenId);
|
||||
}
|
||||
|
||||
@@ -194,25 +204,25 @@ DMError DisplayManagerService::SetVirtualScreenSurface(ScreenId screenId, sptr<S
|
||||
|
||||
bool DisplayManagerService::SetOrientation(ScreenId screenId, Orientation orientation)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:SetOrientation(%" PRIu64")", screenId);
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetOrientation(%" PRIu64")", screenId);
|
||||
return abstractScreenController_->SetOrientation(screenId, orientation, false);
|
||||
}
|
||||
|
||||
bool DisplayManagerService::SetOrientationFromWindow(ScreenId screenId, Orientation orientation)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:SetOrientationFromWindow(%" PRIu64")", screenId);
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetOrientationFromWindow(%" PRIu64")", screenId);
|
||||
return abstractScreenController_->SetOrientation(screenId, orientation, true);
|
||||
}
|
||||
|
||||
bool DisplayManagerService::SetRotationFromWindow(ScreenId screenId, Rotation targetRotation)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:SetRotationFromWindow(%" PRIu64")", screenId);
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetRotationFromWindow(%" PRIu64")", screenId);
|
||||
return abstractScreenController_->SetRotation(screenId, targetRotation, true);
|
||||
}
|
||||
|
||||
std::shared_ptr<Media::PixelMap> DisplayManagerService::GetDisplaySnapshot(DisplayId displayId)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:GetDisplaySnapshot(%" PRIu64")", displayId);
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:GetDisplaySnapshot(%" PRIu64")", displayId);
|
||||
if (Permission::CheckCallingPermission("ohos.permission.CAPTURE_SCREEN") ||
|
||||
Permission::IsStartByHdcd()) {
|
||||
return abstractDisplayController_->GetScreenSnapshot(displayId);
|
||||
@@ -297,7 +307,7 @@ bool DisplayManagerService::UnregisterDisplayManagerAgent(const sptr<IDisplayMan
|
||||
|
||||
bool DisplayManagerService::WakeUpBegin(PowerStateChangeReason reason)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:WakeUpBegin(%u)", reason);
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:WakeUpBegin(%u)", reason);
|
||||
if (!Permission::IsSystemCalling()) {
|
||||
WLOGFI("permission denied!");
|
||||
return false;
|
||||
@@ -318,7 +328,7 @@ bool DisplayManagerService::WakeUpEnd()
|
||||
|
||||
bool DisplayManagerService::SuspendBegin(PowerStateChangeReason reason)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:SuspendBegin(%u)", reason);
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SuspendBegin(%u)", reason);
|
||||
if (!Permission::IsSystemCalling()) {
|
||||
WLOGFI("permission denied!");
|
||||
return false;
|
||||
@@ -366,7 +376,7 @@ ScreenId DisplayManagerService::GetScreenIdByDisplayId(DisplayId displayId) cons
|
||||
{
|
||||
sptr<AbstractDisplay> abstractDisplay = abstractDisplayController_->GetAbstractDisplay(displayId);
|
||||
if (abstractDisplay == nullptr) {
|
||||
WLOGFE("GetScreenIdByDisplayId: GetAbstarctDisplay failed");
|
||||
WLOGFE("GetScreenIdByDisplayId: GetAbstractDisplay failed");
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
return abstractDisplay->GetAbstractScreenId();
|
||||
@@ -415,7 +425,7 @@ ScreenId DisplayManagerService::MakeMirror(ScreenId mainScreenId, std::vector<Sc
|
||||
return SCREEN_ID_INVALID;
|
||||
}
|
||||
abstractScreenController_->SetShotScreen(mainScreenId, shotScreenIds);
|
||||
WM_SCOPED_TRACE("dms:MakeMirror");
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:MakeMirror");
|
||||
if (!allMirrorScreenIds.empty() && !abstractScreenController_->MakeMirror(mainScreenId, allMirrorScreenIds)) {
|
||||
WLOGFE("make mirror failed.");
|
||||
return SCREEN_ID_INVALID;
|
||||
@@ -530,7 +540,7 @@ ScreenId DisplayManagerService::MakeExpand(std::vector<ScreenId> expandScreenIds
|
||||
startPoints.erase(startPointIter);
|
||||
}
|
||||
abstractScreenController_->SetShotScreen(defaultScreenId, shotScreenIds);
|
||||
WM_SCOPED_TRACE("dms:MakeExpand");
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:MakeExpand");
|
||||
if (!allExpandScreenIds.empty() && !abstractScreenController_->MakeExpand(allExpandScreenIds, startPoints)) {
|
||||
WLOGFE("make expand failed.");
|
||||
return SCREEN_ID_INVALID;
|
||||
@@ -545,13 +555,14 @@ ScreenId DisplayManagerService::MakeExpand(std::vector<ScreenId> expandScreenIds
|
||||
|
||||
bool DisplayManagerService::SetScreenActiveMode(ScreenId screenId, uint32_t modeId)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:SetScreenActiveMode(%" PRIu64", %u)", screenId, modeId);
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetScreenActiveMode(%" PRIu64", %u)", screenId, modeId);
|
||||
return abstractScreenController_->SetScreenActiveMode(screenId, modeId);
|
||||
}
|
||||
|
||||
bool DisplayManagerService::SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio)
|
||||
{
|
||||
WM_SCOPED_TRACE("dms:SetVirtualPixelRatio(%" PRIu64", %f)", screenId, virtualPixelRatio);
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "dms:SetVirtualPixelRatio(%" PRIu64", %f)", screenId,
|
||||
virtualPixelRatio);
|
||||
return abstractScreenController_->SetVirtualPixelRatio(screenId, virtualPixelRatio);
|
||||
}
|
||||
|
||||
@@ -559,4 +570,23 @@ float DisplayManagerService::GetCustomVirtualPixelRatio()
|
||||
{
|
||||
return DisplayManagerService::customVirtualPixelRatio_;
|
||||
}
|
||||
|
||||
bool DisplayManagerService::IsScreenRotationLocked()
|
||||
{
|
||||
return ScreenRotationController::IsScreenRotationLocked();
|
||||
}
|
||||
|
||||
void DisplayManagerService::SetScreenRotationLocked(bool isLocked)
|
||||
{
|
||||
ScreenRotationController::SetScreenRotationLocked(isLocked);
|
||||
}
|
||||
|
||||
void DisplayManagerService::SetGravitySensorSubscriptionEnabled()
|
||||
{
|
||||
if (!isAutoRotationOpen_) {
|
||||
WLOGFE("autoRotation is not open");
|
||||
return;
|
||||
}
|
||||
ScreenRotationController::SubscribeGravitySensor();
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
@@ -147,4 +147,14 @@ bool DisplayManagerServiceInner::SetRotationFromWindow(DisplayId displayId, Rota
|
||||
return DisplayManagerService::GetInstance().
|
||||
SetRotationFromWindow(displayInfo->GetScreenId(), targetRotation);
|
||||
}
|
||||
|
||||
void DisplayManagerServiceInner::GetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation)
|
||||
{
|
||||
DisplayManagerService::GetInstance().GetWindowPreferredOrientation(displayId, orientation);
|
||||
}
|
||||
|
||||
void DisplayManagerServiceInner::SetGravitySensorSubscriptionEnabled()
|
||||
{
|
||||
DisplayManagerService::GetInstance().SetGravitySensorSubscriptionEnabled();
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
@@ -313,6 +313,16 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
|
||||
reply.WriteInt32(static_cast<int32_t>(ret));
|
||||
break;
|
||||
}
|
||||
case DisplayManagerMessage::TRANS_ID_IS_SCREEN_ROTATION_LOCKED: {
|
||||
bool isLocked = IsScreenRotationLocked();
|
||||
reply.WriteBool(isLocked);
|
||||
break;
|
||||
}
|
||||
case DisplayManagerMessage::TRANS_ID_SET_SCREEN_ROTATION_LOCKED: {
|
||||
bool isLocked = static_cast<bool>(data.ReadBool());
|
||||
SetScreenRotationLocked(isLocked);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
WLOGFW("unknown transaction code");
|
||||
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
|
||||
|
||||
@@ -23,22 +23,27 @@
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplaySensorController"};
|
||||
constexpr int64_t ORIENTATION_SENSOR_SAMPING_RATE = 200000000; // 200ms
|
||||
constexpr int64_t ORIENTATION_SENSOR_REPORTING_RATE = 200000000; // 200ms
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenRotationController"};
|
||||
constexpr int64_t ORIENTATION_SENSOR_SAMPLING_RATE = 200000000; // 200ms
|
||||
constexpr int64_t ORIENTATION_SENSOR_REPORTING_RATE = 0;
|
||||
constexpr long ORIENTATION_SENSOR_CALLBACK_TIME_INTERVAL = 200; // 200ms
|
||||
constexpr int VALID_INCLINATION_ANGLE_THRESHOLD_COEFFICIENT = 3;
|
||||
}
|
||||
|
||||
enum class ROTATION_DEGREE_RANGE { };
|
||||
|
||||
DisplayId ScreenRotationController::defaultDisplayId_ = 0;
|
||||
bool ScreenRotationController::isGravitySensorSubscribed_ = false;
|
||||
SensorUser ScreenRotationController::user_;
|
||||
Rotation ScreenRotationController::currentDisplayRotation_;
|
||||
bool ScreenRotationController::isScreenRotationLocked_ = false;
|
||||
bool ScreenRotationController::isScreenRotationLocked_ = true;
|
||||
long ScreenRotationController::lastCallbackTime_ = 0;
|
||||
uint32_t ScreenRotationController::defaultDeviceRotationOffset_ = 0;
|
||||
Orientation ScreenRotationController::lastOrientationType_ = Orientation::UNSPECIFIED;
|
||||
Rotation ScreenRotationController::lastSensorDecidedRotation_;
|
||||
Rotation ScreenRotationController::rotationLockedRotation_;
|
||||
uint32_t ScreenRotationController::defaultDeviceRotation_ = 0;
|
||||
std::map<SensorRotation, DeviceRotation> ScreenRotationController::sensorToDeviceRotationMap_;
|
||||
std::map<DeviceRotation, Rotation> ScreenRotationController::deviceToDisplayRotationMap_;
|
||||
DeviceRotation ScreenRotationController::lastSensorRotationConverted_ = DeviceRotation::INVALID;
|
||||
|
||||
void ScreenRotationController::SubscribeGravitySensor()
|
||||
{
|
||||
@@ -51,12 +56,22 @@ void ScreenRotationController::SubscribeGravitySensor()
|
||||
WLOGFE("dms strcpy_s error");
|
||||
return;
|
||||
}
|
||||
ProcessRotationMapping();
|
||||
user_.userData = nullptr;
|
||||
user_.callback = &HandleGravitySensorEventCallback;
|
||||
SubscribeSensor(SENSOR_TYPE_ID_GRAVITY, &user_);
|
||||
SetBatch(SENSOR_TYPE_ID_GRAVITY, &user_, ORIENTATION_SENSOR_SAMPING_RATE, ORIENTATION_SENSOR_REPORTING_RATE);
|
||||
if (SubscribeSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) {
|
||||
WLOGFE("dms: Subscribe gravity sensor failed");
|
||||
return;
|
||||
}
|
||||
SetBatch(SENSOR_TYPE_ID_GRAVITY, &user_, ORIENTATION_SENSOR_SAMPLING_RATE, ORIENTATION_SENSOR_REPORTING_RATE);
|
||||
SetMode(SENSOR_TYPE_ID_GRAVITY, &user_, SENSOR_ON_CHANGE);
|
||||
ActivateSensor(SENSOR_TYPE_ID_GRAVITY, &user_);
|
||||
if (ActivateSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) {
|
||||
WLOGFE("dms: Activate gravity sensor failed");
|
||||
return;
|
||||
}
|
||||
currentDisplayRotation_ = GetCurrentDisplayRotation();
|
||||
lastSensorDecidedRotation_ = currentDisplayRotation_;
|
||||
rotationLockedRotation_ = currentDisplayRotation_;
|
||||
isGravitySensorSubscribed_ = true;
|
||||
}
|
||||
|
||||
@@ -67,8 +82,14 @@ void ScreenRotationController::UnsubscribeGravitySensor()
|
||||
WLOGFE("dms: Orientation Sensor is not subscribed");
|
||||
return;
|
||||
}
|
||||
DeactivateSensor(SENSOR_TYPE_ID_GRAVITY, &user_);
|
||||
UnsubscribeSensor(SENSOR_TYPE_ID_GRAVITY, &user_);
|
||||
if (DeactivateSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) {
|
||||
WLOGFE("dms: Deactivate gravity sensor failed");
|
||||
return;
|
||||
}
|
||||
if (UnsubscribeSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) {
|
||||
WLOGFE("dms: Unsubscribe gravity sensor failed");
|
||||
return;
|
||||
}
|
||||
isGravitySensorSubscribed_ = false;
|
||||
}
|
||||
|
||||
@@ -79,6 +100,9 @@ bool ScreenRotationController::IsScreenRotationLocked()
|
||||
|
||||
void ScreenRotationController::SetScreenRotationLocked(bool isLocked)
|
||||
{
|
||||
if (isLocked) {
|
||||
rotationLockedRotation_ = GetCurrentDisplayRotation();
|
||||
}
|
||||
isScreenRotationLocked_ = isLocked;
|
||||
}
|
||||
|
||||
@@ -100,37 +124,24 @@ void ScreenRotationController::HandleGravitySensorEventCallback(SensorEvent *eve
|
||||
WLOGE("dms: Orientation Sensor Callback is not SENSOR_TYPE_ID_GRAVITY");
|
||||
return;
|
||||
}
|
||||
Orientation orientation = GetDisplayOrientation();
|
||||
Orientation orientation = GetPreferredOrientation();
|
||||
|
||||
currentDisplayRotation_ = GetCurrentDisplayRotation();
|
||||
GravityData* gravityData = reinterpret_cast<GravityData*>(event->data);
|
||||
int sensorDegree = CalcRotationDegree(gravityData);
|
||||
DeviceRotation sensorRotationConverted = ConvertSensorToDeviceRotation(CalcSensorRotation(sensorDegree));
|
||||
lastSensorRotationConverted_ = sensorRotationConverted;
|
||||
if (!IsSensorRelatedOrientation(orientation)) {
|
||||
return;
|
||||
}
|
||||
|
||||
GravityData* gravityData = reinterpret_cast<GravityData*>(event->data);
|
||||
int sensorDegree = CalcRotationDegree(gravityData);
|
||||
currentDisplayRotation_ = GetCurrentDisplayRotation();
|
||||
Rotation currentSensorRotation;
|
||||
// Use ROTATION_0 when degree range is [0, 30]∪[330, 359]
|
||||
if (sensorDegree >= 0 && (sensorDegree <= 30 || sensorDegree >= 330)) {
|
||||
currentSensorRotation = Rotation::ROTATION_0;
|
||||
} else if (sensorDegree >= 60 && sensorDegree <= 120) { // Use ROTATION_90 when degree range is [60, 120]
|
||||
currentSensorRotation = Rotation::ROTATION_90;
|
||||
} else if (sensorDegree >= 150 && sensorDegree <= 210) { // Use ROTATION_180 when degree range is [150, 210]
|
||||
currentSensorRotation = Rotation::ROTATION_180;
|
||||
} else if (sensorDegree >= 240 && sensorDegree <= 300) { // Use ROTATION_270 when degree range is [240, 300]
|
||||
currentSensorRotation = Rotation::ROTATION_270;
|
||||
} else {
|
||||
if (sensorRotationConverted == DeviceRotation::INVALID) {
|
||||
return;
|
||||
}
|
||||
if (ConvertToDeviceRotation(currentSensorRotation) == currentDisplayRotation_) {
|
||||
if (currentDisplayRotation_ == ConvertDeviceToDisplayRotation(sensorRotationConverted)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Rotation targetDisplayRotation = CalcTargetDisplayRotation(orientation, currentSensorRotation);
|
||||
if (ConvertToDeviceRotation(targetDisplayRotation) == currentDisplayRotation_) {
|
||||
return;
|
||||
}
|
||||
|
||||
SetScreenRotation(ConvertToDeviceRotation(targetDisplayRotation));
|
||||
Rotation targetDisplayRotation = CalcTargetDisplayRotation(orientation, sensorRotationConverted);
|
||||
SetScreenRotation(targetDisplayRotation);
|
||||
}
|
||||
|
||||
int ScreenRotationController::CalcRotationDegree(GravityData* gravityData)
|
||||
@@ -150,44 +161,58 @@ int ScreenRotationController::CalcRotationDegree(GravityData* gravityData)
|
||||
|
||||
Rotation ScreenRotationController::GetCurrentDisplayRotation()
|
||||
{
|
||||
return DisplayManagerServiceInner::GetInstance().GetDisplayById(defaultDisplayId_)->GetRotation();
|
||||
sptr<DisplayInfo> defaultDisplayInfo = DisplayManagerServiceInner::GetInstance().GetDefaultDisplay();
|
||||
if (defaultDisplayInfo == nullptr) {
|
||||
WLOGFE("Cannot get default display info");
|
||||
return defaultDeviceRotation_ == 0 ? ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT) :
|
||||
ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE);
|
||||
}
|
||||
return defaultDisplayInfo->GetRotation();
|
||||
}
|
||||
|
||||
Orientation ScreenRotationController::GetDisplayOrientation()
|
||||
Orientation ScreenRotationController::GetPreferredOrientation()
|
||||
{
|
||||
return DisplayManagerServiceInner::GetInstance().GetDefaultDisplay()->GetOrientation();
|
||||
sptr<ScreenInfo> screenInfo = DisplayManagerServiceInner::GetInstance().GetScreenInfoByDisplayId(defaultDisplayId_);
|
||||
if (screenInfo == nullptr) {
|
||||
WLOGFE("Cannot get default screen info");
|
||||
return Orientation::UNSPECIFIED;
|
||||
}
|
||||
return screenInfo->GetOrientation();
|
||||
}
|
||||
|
||||
Rotation ScreenRotationController::CalcTargetDisplayRotation(
|
||||
Orientation requestedOrientation, Rotation sensorRotation)
|
||||
Orientation requestedOrientation, DeviceRotation sensorRotationConverted)
|
||||
{
|
||||
switch (requestedOrientation) {
|
||||
case Orientation::SENSOR: {
|
||||
return sensorRotation;
|
||||
lastSensorDecidedRotation_ = ConvertDeviceToDisplayRotation(sensorRotationConverted);
|
||||
return ConvertDeviceToDisplayRotation(sensorRotationConverted);
|
||||
}
|
||||
case Orientation::SENSOR_VERTICAL: {
|
||||
return ProcessAutoRotationPortraitOrientation(sensorRotation);
|
||||
return ProcessAutoRotationPortraitOrientation(sensorRotationConverted);
|
||||
}
|
||||
case Orientation::SENSOR_HORIZONTAL: {
|
||||
return ProcessAutoRotationLandscapeOrientation(sensorRotation);
|
||||
return ProcessAutoRotationLandscapeOrientation(sensorRotationConverted);
|
||||
}
|
||||
case Orientation::UNSPECIFIED:
|
||||
case Orientation::AUTO_ROTATION_RESTRICTED: {
|
||||
if (isScreenRotationLocked_) {
|
||||
return currentDisplayRotation_;
|
||||
}
|
||||
return sensorRotation;
|
||||
lastSensorDecidedRotation_ = ConvertDeviceToDisplayRotation(sensorRotationConverted);
|
||||
return ConvertDeviceToDisplayRotation(sensorRotationConverted);
|
||||
}
|
||||
case Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED: {
|
||||
if (isScreenRotationLocked_) {
|
||||
return currentDisplayRotation_;
|
||||
}
|
||||
return ProcessAutoRotationPortraitOrientation(sensorRotation);
|
||||
return ProcessAutoRotationPortraitOrientation(sensorRotationConverted);
|
||||
}
|
||||
case Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED: {
|
||||
if (isScreenRotationLocked_) {
|
||||
return currentDisplayRotation_;
|
||||
}
|
||||
return ProcessAutoRotationLandscapeOrientation(sensorRotation);
|
||||
return ProcessAutoRotationLandscapeOrientation(sensorRotationConverted);
|
||||
}
|
||||
default: {
|
||||
return currentDisplayRotation_;
|
||||
@@ -195,26 +220,32 @@ Rotation ScreenRotationController::CalcTargetDisplayRotation(
|
||||
}
|
||||
}
|
||||
|
||||
Rotation ScreenRotationController::ProcessAutoRotationPortraitOrientation(Rotation sensorRotation)
|
||||
Rotation ScreenRotationController::ProcessAutoRotationPortraitOrientation(DeviceRotation sensorRotationConverted)
|
||||
{
|
||||
if (sensorRotation == Rotation::ROTATION_0 || sensorRotation == Rotation::ROTATION_180) {
|
||||
return sensorRotation;
|
||||
if (IsDeviceRotationHorizontal(sensorRotationConverted)) {
|
||||
return currentDisplayRotation_;
|
||||
}
|
||||
return currentDisplayRotation_;
|
||||
lastSensorDecidedRotation_ = ConvertDeviceToDisplayRotation(sensorRotationConverted);
|
||||
return ConvertDeviceToDisplayRotation(sensorRotationConverted);
|
||||
}
|
||||
|
||||
Rotation ScreenRotationController::ProcessAutoRotationLandscapeOrientation(Rotation sensorRotation)
|
||||
Rotation ScreenRotationController::ProcessAutoRotationLandscapeOrientation(DeviceRotation sensorRotationConverted)
|
||||
{
|
||||
if (sensorRotation == Rotation::ROTATION_90 || sensorRotation == Rotation::ROTATION_270) {
|
||||
return sensorRotation;
|
||||
if (IsDeviceRotationVertical(sensorRotationConverted)) {
|
||||
return currentDisplayRotation_;
|
||||
}
|
||||
return currentDisplayRotation_;
|
||||
lastSensorDecidedRotation_ = ConvertDeviceToDisplayRotation(sensorRotationConverted);
|
||||
return ConvertDeviceToDisplayRotation(sensorRotationConverted);
|
||||
}
|
||||
|
||||
void ScreenRotationController::SetScreenRotation(Rotation targetRotation)
|
||||
{
|
||||
DisplayManagerServiceInner::GetInstance().SetRotationFromWindow(defaultDisplayId_, targetRotation);
|
||||
if (targetRotation == GetCurrentDisplayRotation()) {
|
||||
return;
|
||||
}
|
||||
DisplayManagerServiceInner::GetInstance().GetDefaultDisplay()->SetRotation(targetRotation);
|
||||
DisplayManagerServiceInner::GetInstance().SetRotationFromWindow(defaultDisplayId_, targetRotation);
|
||||
WLOGFI("dms: Set screen rotation: %{public}u", targetRotation);
|
||||
}
|
||||
|
||||
bool ScreenRotationController::CheckCallbackTimeInterval()
|
||||
@@ -229,24 +260,269 @@ bool ScreenRotationController::CheckCallbackTimeInterval()
|
||||
return true;
|
||||
}
|
||||
|
||||
Rotation ScreenRotationController::ConvertToDeviceRotation(Rotation sensorRotation)
|
||||
DeviceRotation ScreenRotationController::CalcDeviceRotation(SensorRotation sensorRotation)
|
||||
{
|
||||
if (sensorRotation == SensorRotation::INVALID) {
|
||||
return DeviceRotation::INVALID;
|
||||
}
|
||||
int32_t bias = defaultDeviceRotationOffset_ / 90; // offset(in degree) divided by 90 to get rotation bias
|
||||
int32_t deviceRotationValue = static_cast<int32_t>(sensorRotation) - bias;
|
||||
while (deviceRotationValue < 0) {
|
||||
// +4 is used to normalize the values into the range 0~3, corresponding to the four rotations.
|
||||
deviceRotationValue += 4;
|
||||
}
|
||||
return static_cast<Rotation>(deviceRotationValue);
|
||||
if (defaultDeviceRotation_ == 1) {
|
||||
deviceRotationValue += defaultDeviceRotation_;
|
||||
// if device's default rotation is landscape, swap 0 and 90, 180 and 270, use %2 to adjust range.
|
||||
(deviceRotationValue % 2 == 0) && (deviceRotationValue -= 2);
|
||||
}
|
||||
return static_cast<DeviceRotation>(deviceRotationValue);
|
||||
}
|
||||
|
||||
bool ScreenRotationController::IsSensorRelatedOrientation(Orientation orientation)
|
||||
{
|
||||
if ((orientation >= Orientation::BEGIN && orientation <= Orientation::REVERSE_HORIZONTAL) ||
|
||||
if ((orientation >= Orientation::VERTICAL && orientation <= Orientation::REVERSE_HORIZONTAL) ||
|
||||
orientation == Orientation::LOCKED) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScreenRotationController::ProcessSwitchToSensorRelatedOrientation(
|
||||
Orientation orientation, DeviceRotation sensorRotationConverted)
|
||||
{
|
||||
if (lastOrientationType_ == orientation) {
|
||||
return;
|
||||
}
|
||||
lastOrientationType_ = orientation;
|
||||
switch (orientation) {
|
||||
case Orientation::UNSPECIFIED:
|
||||
case Orientation::AUTO_ROTATION_RESTRICTED: {
|
||||
if (isScreenRotationLocked_) {
|
||||
SetScreenRotation(rotationLockedRotation_);
|
||||
return;
|
||||
}
|
||||
[[fallthrough]];
|
||||
}
|
||||
case Orientation::SENSOR: {
|
||||
ProcessSwitchToAutoRotation(sensorRotationConverted);
|
||||
return;
|
||||
}
|
||||
case Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED: {
|
||||
if (isScreenRotationLocked_) {
|
||||
ProcessSwitchToAutoRotationPortraitRestricted();
|
||||
return;
|
||||
}
|
||||
[[fallthrough]];
|
||||
}
|
||||
case Orientation::SENSOR_VERTICAL: {
|
||||
ProcessSwitchToAutoRotationPortrait(sensorRotationConverted);
|
||||
return;
|
||||
}
|
||||
case Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED: {
|
||||
if (isScreenRotationLocked_) {
|
||||
ProcessSwitchToAutoRotationLandscapeRestricted();
|
||||
return;
|
||||
}
|
||||
[[fallthrough]];
|
||||
}
|
||||
case Orientation::SENSOR_HORIZONTAL: {
|
||||
ProcessSwitchToAutoRotationLandscape(sensorRotationConverted);
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenRotationController::ProcessSwitchToAutoRotation(DeviceRotation rotation)
|
||||
{
|
||||
if (rotation != DeviceRotation::INVALID) {
|
||||
return;
|
||||
}
|
||||
SetScreenRotation(lastSensorDecidedRotation_);
|
||||
}
|
||||
|
||||
void ScreenRotationController::ProcessSwitchToAutoRotationPortrait(DeviceRotation rotation)
|
||||
{
|
||||
if (IsCurrentDisplayVertical()) {
|
||||
return;
|
||||
}
|
||||
if (IsDeviceRotationVertical(rotation)) {
|
||||
return;
|
||||
}
|
||||
SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT));
|
||||
}
|
||||
|
||||
void ScreenRotationController::ProcessSwitchToAutoRotationLandscape(DeviceRotation rotation)
|
||||
{
|
||||
if (IsCurrentDisplayHorizontal()) {
|
||||
return;
|
||||
}
|
||||
if (IsDeviceRotationHorizontal(rotation)) {
|
||||
return;
|
||||
}
|
||||
SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE));
|
||||
}
|
||||
|
||||
void ScreenRotationController::ProcessSwitchToAutoRotationPortraitRestricted()
|
||||
{
|
||||
if (IsCurrentDisplayVertical()) {
|
||||
return;
|
||||
}
|
||||
if (IsDisplayRotationVertical(rotationLockedRotation_)) {
|
||||
SetScreenRotation(rotationLockedRotation_);
|
||||
return;
|
||||
}
|
||||
SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT));
|
||||
}
|
||||
|
||||
void ScreenRotationController::ProcessSwitchToAutoRotationLandscapeRestricted()
|
||||
{
|
||||
if (IsCurrentDisplayHorizontal()) {
|
||||
return;
|
||||
}
|
||||
if (IsDisplayRotationHorizontal(rotationLockedRotation_)) {
|
||||
SetScreenRotation(rotationLockedRotation_);
|
||||
return;
|
||||
}
|
||||
SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE));
|
||||
}
|
||||
|
||||
SensorRotation ScreenRotationController::CalcSensorRotation(int sensorDegree)
|
||||
{
|
||||
// Use ROTATION_0 when degree range is [0, 30]∪[330, 359]
|
||||
if (sensorDegree >= 0 && (sensorDegree <= 30 || sensorDegree >= 330)) {
|
||||
return SensorRotation::ROTATION_0;
|
||||
} else if (sensorDegree >= 60 && sensorDegree <= 120) { // Use ROTATION_90 when degree range is [60, 120]
|
||||
return SensorRotation::ROTATION_90;
|
||||
} else if (sensorDegree >= 150 && sensorDegree <= 210) { // Use ROTATION_180 when degree range is [150, 210]
|
||||
return SensorRotation::ROTATION_180;
|
||||
} else if (sensorDegree >= 240 && sensorDegree <= 300) { // Use ROTATION_270 when degree range is [240, 300]
|
||||
return SensorRotation::ROTATION_270;
|
||||
} else {
|
||||
return SensorRotation::INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
DeviceRotation ScreenRotationController::ConvertSensorToDeviceRotation(SensorRotation sensorRotation)
|
||||
{
|
||||
return sensorToDeviceRotationMap_.at(sensorRotation);
|
||||
}
|
||||
|
||||
Rotation ScreenRotationController::ConvertDeviceToDisplayRotation(DeviceRotation deviceRotation)
|
||||
{
|
||||
if (deviceRotation == DeviceRotation::INVALID) {
|
||||
return GetCurrentDisplayRotation();
|
||||
}
|
||||
return deviceToDisplayRotationMap_.at(deviceRotation);
|
||||
}
|
||||
|
||||
void ScreenRotationController::ProcessRotationMapping()
|
||||
{
|
||||
sptr<SupportedScreenModes> modes =
|
||||
DisplayManagerServiceInner::GetInstance().GetScreenModesByDisplayId(defaultDisplayId_);
|
||||
// 0 means PORTRAIT, 1 means LANDSCAPE.
|
||||
defaultDeviceRotation_ = modes->width_ < modes->height_ ? 0 : 1;
|
||||
if (deviceToDisplayRotationMap_.empty()) {
|
||||
deviceToDisplayRotationMap_ = {
|
||||
{DeviceRotation::ROTATION_PORTRAIT,
|
||||
defaultDeviceRotation_ == 0 ? Rotation::ROTATION_0 : Rotation::ROTATION_90},
|
||||
{DeviceRotation::ROTATION_LANDSCAPE,
|
||||
defaultDeviceRotation_ == 1 ? Rotation::ROTATION_0 : Rotation::ROTATION_90},
|
||||
{DeviceRotation::ROTATION_PORTRAIT_INVERTED,
|
||||
defaultDeviceRotation_ == 0 ? Rotation::ROTATION_180 : Rotation::ROTATION_270},
|
||||
{DeviceRotation::ROTATION_LANDSCAPE_INVERTED,
|
||||
defaultDeviceRotation_ == 1 ? Rotation::ROTATION_180 : Rotation::ROTATION_270},
|
||||
};
|
||||
}
|
||||
if (sensorToDeviceRotationMap_.empty()) {
|
||||
sensorToDeviceRotationMap_ = {
|
||||
{SensorRotation::ROTATION_0, CalcDeviceRotation(SensorRotation::ROTATION_0)},
|
||||
{SensorRotation::ROTATION_90, CalcDeviceRotation(SensorRotation::ROTATION_90)},
|
||||
{SensorRotation::ROTATION_180, CalcDeviceRotation(SensorRotation::ROTATION_180)},
|
||||
{SensorRotation::ROTATION_270, CalcDeviceRotation(SensorRotation::ROTATION_270)},
|
||||
{SensorRotation::INVALID, DeviceRotation::INVALID},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
bool ScreenRotationController::IsDeviceRotationVertical(DeviceRotation deviceRotation)
|
||||
{
|
||||
return (deviceRotation == DeviceRotation::ROTATION_PORTRAIT) ||
|
||||
(deviceRotation == DeviceRotation::ROTATION_PORTRAIT_INVERTED);
|
||||
}
|
||||
|
||||
bool ScreenRotationController::IsDeviceRotationHorizontal(DeviceRotation deviceRotation)
|
||||
{
|
||||
return (deviceRotation == DeviceRotation::ROTATION_LANDSCAPE) ||
|
||||
(deviceRotation == DeviceRotation::ROTATION_LANDSCAPE_INVERTED);
|
||||
}
|
||||
|
||||
bool ScreenRotationController::IsCurrentDisplayVertical()
|
||||
{
|
||||
return IsDisplayRotationVertical(GetCurrentDisplayRotation());
|
||||
}
|
||||
|
||||
bool ScreenRotationController::IsCurrentDisplayHorizontal()
|
||||
{
|
||||
return IsDisplayRotationHorizontal(GetCurrentDisplayRotation());
|
||||
}
|
||||
|
||||
bool ScreenRotationController::IsDisplayRotationVertical(Rotation rotation)
|
||||
{
|
||||
return (rotation == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT)) ||
|
||||
(rotation == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT_INVERTED));
|
||||
}
|
||||
|
||||
bool ScreenRotationController::IsDisplayRotationHorizontal(Rotation rotation)
|
||||
{
|
||||
return (rotation == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE)) ||
|
||||
(rotation == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE_INVERTED));
|
||||
}
|
||||
|
||||
bool ScreenRotationController::IsGravitySensorEnabled()
|
||||
{
|
||||
return isGravitySensorSubscribed_;
|
||||
}
|
||||
|
||||
void ScreenRotationController::ProcessSwitchToSensorUnrelatedOrientation(Orientation orientation)
|
||||
{
|
||||
if (lastOrientationType_ == orientation) {
|
||||
return;
|
||||
}
|
||||
lastOrientationType_ = orientation;
|
||||
switch (orientation) {
|
||||
case Orientation::VERTICAL: {
|
||||
SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT));
|
||||
break;
|
||||
}
|
||||
case Orientation::REVERSE_VERTICAL: {
|
||||
SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT_INVERTED));
|
||||
break;
|
||||
}
|
||||
case Orientation::HORIZONTAL: {
|
||||
SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE));
|
||||
break;
|
||||
}
|
||||
case Orientation::REVERSE_HORIZONTAL: {
|
||||
SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE_INVERTED));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenRotationController::ProcessOrientationSwitch(Orientation orientation)
|
||||
{
|
||||
if (!IsSensorRelatedOrientation(orientation)) {
|
||||
ProcessSwitchToSensorUnrelatedOrientation(orientation);
|
||||
} else {
|
||||
ProcessSwitchToSensorRelatedOrientation(orientation, lastSensorRotationConverted_);
|
||||
}
|
||||
}
|
||||
} // Rosen
|
||||
} // OHOS
|
||||
@@ -50,6 +50,7 @@ ohos_shared_library("libwindow_extension_client") {
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"ability_runtime:ability_manager",
|
||||
"hitrace_native:hitrace_meter",
|
||||
"input:libmmi-client",
|
||||
]
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <ability_connect_callback_stub.h>
|
||||
#include <ability_manager_client.h>
|
||||
#include <element_name.h>
|
||||
#include <hitrace_meter.h>
|
||||
#include <iremote_object.h>
|
||||
|
||||
#include "window_extension_proxy.h"
|
||||
@@ -25,7 +26,6 @@
|
||||
#include "window_manager_hilog.h"
|
||||
#include "wm_common.h"
|
||||
#include "wm_common_inner.h"
|
||||
#include "wm_trace.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
@@ -106,7 +106,7 @@ int WindowExtensionConnection::Impl::ConnectExtension(const AppExecFwk::ElementN
|
||||
{
|
||||
AAFwk::Want want;
|
||||
want.SetElement(element);
|
||||
WM_SCOPED_ASYNC_TRACE_BEGIN(static_cast<int32_t>(TraceTaskId::CONNECT_EXTENSION),
|
||||
StartAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast<int32_t>(TraceTaskId::CONNECT_EXTENSION),
|
||||
"WindowExtension %s-%s", element.GetBundleName().c_str(), element.GetAbilityName().c_str());
|
||||
want.SetParam(RECT_FORM_KEY_POS_X, rect.posX_);
|
||||
want.SetParam(RECT_FORM_KEY_POS_Y, rect.posY_);
|
||||
@@ -189,7 +189,7 @@ void WindowExtensionConnection::Impl::OnAbilityConnectDone(const AppExecFwk::Ele
|
||||
WLOGFI("GetExtensionWindow");
|
||||
}
|
||||
WLOGFI("call end");
|
||||
WM_SCOPED_ASYNC_END(static_cast<int32_t>(TraceTaskId::CONNECT_EXTENSION),
|
||||
FinishAsyncTraceArgs(HITRACE_TAG_WINDOW_MANAGER, static_cast<int32_t>(TraceTaskId::CONNECT_EXTENSION),
|
||||
"WindowExtension %s-%s", element.GetBundleName().c_str(), element.GetAbilityName().c_str());
|
||||
}
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ void WindowExtensionClientProxy::OnWindowReady(const std::shared_ptr<RSSurfaceNo
|
||||
WLOGFE("write token failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((!data.WriteParcelable(surfaceNode.get()))) {
|
||||
|
||||
if ((!surfaceNode->Marshalling(data))) {
|
||||
WLOGFE("write surfaceNode failed");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ int WindowExtensionClientStub::OnRemoteRequest(uint32_t code, MessageParcel& dat
|
||||
WLOGFI(" code is %{public}d", code);
|
||||
switch (code) {
|
||||
case TRANS_ID_ON_WINDOW_READY: {
|
||||
std::shared_ptr<RSSurfaceNode> surfaceNode(data.ReadParcelable<RSSurfaceNode>());
|
||||
std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Unmarshalling(data);
|
||||
OnWindowReady(surfaceNode);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ ohos_shared_library("libwindow_extension") {
|
||||
configs = [ ":libwindow_extension_private_config" ]
|
||||
|
||||
deps = [
|
||||
"//foundation/ability/ability_runtime/frameworks/js/napi/aafwk/inner/napi_common:napi_common",
|
||||
"//foundation/ability/ability_runtime/frameworks/kits/appkit:app_context",
|
||||
"${ability_runtime_napi_path}/inner/napi_common:napi_common",
|
||||
"${ability_runtime_path}/frameworks/native/appkit:app_context",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||
"//foundation/windowmanager/interfaces/kits/napi/window_runtime:window_native_kit",
|
||||
"//foundation/windowmanager/utils:libwmutil",
|
||||
@@ -56,8 +56,9 @@ ohos_shared_library("libwindow_extension") {
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:abilitykit_native",
|
||||
"ability_runtime:runtime",
|
||||
"graphic_standard:surface",
|
||||
"graphic_graphic_2d:surface",
|
||||
"hilog_native:libhilog",
|
||||
"hitrace_native:hitrace_meter",
|
||||
"input:libmmi-client",
|
||||
"utils_base:utils",
|
||||
]
|
||||
@@ -71,7 +72,7 @@ config("window_extension_module_private_config") {
|
||||
|
||||
include_dirs = [
|
||||
"include",
|
||||
"${aafwk_kits_path}/ability/ability_runtime/include",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime",
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "js_window_extension.h"
|
||||
|
||||
#include <hitrace_meter.h>
|
||||
#include <napi_common_want.h>
|
||||
#include <native_engine/native_reference.h>
|
||||
#include <native_engine/native_value.h>
|
||||
@@ -27,7 +28,6 @@
|
||||
#include "window_manager_hilog.h"
|
||||
#include "wm_common.h"
|
||||
#include "wm_common_inner.h"
|
||||
#include "wm_trace.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
@@ -61,7 +61,7 @@ void JsWindowExtension::Init(const std::shared_ptr<AbilityRuntime::AbilityLocalR
|
||||
std::shared_ptr<AbilityRuntime::AbilityHandler>& handler,
|
||||
const sptr<IRemoteObject>& token)
|
||||
{
|
||||
WM_SCOPED_TRACE("WindowExtension Init");
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "WindowExtension Init");
|
||||
WindowExtension::Init(record, application, handler, token);
|
||||
std::string srcPath;
|
||||
GetSrcPath(srcPath);
|
||||
@@ -143,7 +143,7 @@ void JsWindowExtension::GetSrcPath(std::string& srcPath) const
|
||||
|
||||
sptr<IRemoteObject> JsWindowExtension::OnConnect(const AAFwk::Want& want)
|
||||
{
|
||||
WM_SCOPED_TRACE("WindowExtension Init %s-%s",
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "WindowExtension OnConnect %s-%s",
|
||||
want.GetElement().GetAbilityName().c_str(), want.GetElement().GetAbilityName().c_str());
|
||||
WLOGFI("called.");
|
||||
Extension::OnConnect(want);
|
||||
@@ -194,7 +194,7 @@ void JsWindowExtension::OnDisconnect(const AAFwk::Want& want)
|
||||
|
||||
void JsWindowExtension::OnStart(const AAFwk::Want& want)
|
||||
{
|
||||
WM_SCOPED_TRACE("WindowExtension OnStart %s-%s",
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "WindowExtension OnStart %s-%s",
|
||||
want.GetElement().GetAbilityName().c_str(), want.GetElement().GetAbilityName().c_str());
|
||||
Extension::OnStart(want);
|
||||
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@
|
||||
# // __BASE is used for defining the basic info of the event.
|
||||
# // "type" optional values are: FAULT, STATISTICS, SECURITY, BEHAVIOR.
|
||||
# // "level" optional values are: CRITICAL, MINOR.
|
||||
# // "tag" set tags with may used by subscriber of this event, multiple tags devided by space.
|
||||
# // "tag" set tags with may used by subscriber of this event, multiple tags divided by space.
|
||||
# // "desc" full description of this event.
|
||||
# @PARAMETER: {type: parameter type, arrsize: array length(optional), desc: parameter description}.
|
||||
# // follow the __BASE block, each line defines a parameter of this event.
|
||||
|
||||
@@ -55,7 +55,8 @@ public:
|
||||
DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface);
|
||||
bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason);
|
||||
ScreenPowerState GetScreenPower(ScreenId screenId);
|
||||
|
||||
void SetScreenRotationLocked(bool isLocked);
|
||||
bool IsScreenRotationLocked();
|
||||
private:
|
||||
ScreenManager();
|
||||
~ScreenManager();
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace OHOS::MMI {
|
||||
struct IInputEventConsumer;
|
||||
class PointerEvent;
|
||||
class KeyEvent;
|
||||
class AxisEvent;
|
||||
}
|
||||
namespace OHOS::AppExecFwk {
|
||||
class Configuration;
|
||||
@@ -59,6 +60,7 @@ public:
|
||||
virtual void AfterFocused() = 0;
|
||||
virtual void AfterUnfocused() = 0;
|
||||
virtual void ForegroundFailed() {}
|
||||
virtual void ForegroundInvalidMode() {}
|
||||
virtual void AfterActive() {}
|
||||
virtual void AfterInactive() {}
|
||||
};
|
||||
@@ -71,7 +73,7 @@ public:
|
||||
|
||||
class IAvoidAreaChangedListener : virtual public RefBase {
|
||||
public:
|
||||
virtual void OnAvoidAreaChanged(std::vector<Rect> avoidAreas) = 0;
|
||||
virtual void OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type) = 0;
|
||||
};
|
||||
|
||||
class IWindowDragListener : virtual public RefBase {
|
||||
@@ -120,15 +122,42 @@ public:
|
||||
virtual void OnPointerInputEvent(std::shared_ptr<MMI::PointerEvent>& pointerEvent) = 0;
|
||||
};
|
||||
|
||||
class IInputEventConsumer {
|
||||
public:
|
||||
virtual bool OnInputEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const = 0;
|
||||
virtual bool OnInputEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) const = 0;
|
||||
virtual bool OnInputEvent(const std::shared_ptr<MMI::AxisEvent>& axisEvent) const = 0;
|
||||
};
|
||||
|
||||
class ITouchOutsideListener : virtual public RefBase {
|
||||
public:
|
||||
virtual void OnTouchOutside() = 0;
|
||||
virtual void OnTouchOutside() const = 0;
|
||||
};
|
||||
|
||||
class IAnimationTransitionController : virtual public RefBase {
|
||||
public:
|
||||
virtual void AnimationForShown() = 0;
|
||||
virtual void AnimationForHidden() = 0;
|
||||
};
|
||||
|
||||
class Window : public RefBase {
|
||||
public:
|
||||
/**
|
||||
* @brief create window, include main_window/sub_window/system_window
|
||||
*
|
||||
* @param windowName window name, identify window instance
|
||||
* @param option window propertion
|
||||
* @param context ability context
|
||||
* @return sptr<Window> If create window success,return window instance;Otherwise, return nullptr
|
||||
*/
|
||||
static sptr<Window> Create(const std::string& windowName,
|
||||
sptr<WindowOption>& option, const std::shared_ptr<AbilityRuntime::Context>& context = nullptr);
|
||||
/**
|
||||
* @brief find window by windowName
|
||||
*
|
||||
* @param windowName
|
||||
* @return sptr<Window> Return the window instance founded
|
||||
*/
|
||||
static sptr<Window> Find(const std::string& windowName);
|
||||
static sptr<Window> GetTopWindowWithContext(const std::shared_ptr<AbilityRuntime::Context>& context = nullptr);
|
||||
static sptr<Window> GetTopWindowWithId(uint32_t mainWinId);
|
||||
@@ -155,7 +184,9 @@ public:
|
||||
virtual WMError SetWindowType(WindowType type) = 0;
|
||||
virtual WMError SetWindowMode(WindowMode mode) = 0;
|
||||
virtual WMError SetWindowBackgroundBlur(WindowBlurLevel level) = 0;
|
||||
virtual WMError SetAlpha(float alpha) = 0;
|
||||
virtual void SetAlpha(float alpha) = 0;
|
||||
virtual void SetTransform(const Transform& trans) = 0;
|
||||
virtual Transform GetTransform() const = 0;
|
||||
virtual WMError AddWindowFlag(WindowFlag flag) = 0;
|
||||
virtual WMError RemoveWindowFlag(WindowFlag flag) = 0;
|
||||
virtual WMError SetWindowFlags(uint32_t flags) = 0;
|
||||
@@ -164,8 +195,8 @@ public:
|
||||
virtual WMError SetLayoutFullScreen(bool status) = 0;
|
||||
virtual WMError SetFullScreen(bool status) = 0;
|
||||
virtual WMError Destroy() = 0;
|
||||
virtual WMError Show(uint32_t reason = 0) = 0;
|
||||
virtual WMError Hide(uint32_t reason = 0) = 0;
|
||||
virtual WMError Show(uint32_t reason = 0, bool withAnimation = false) = 0;
|
||||
virtual WMError Hide(uint32_t reason = 0, bool withAnimation = false) = 0;
|
||||
|
||||
virtual WMError MoveTo(int32_t x, int32_t y) = 0;
|
||||
virtual WMError Resize(uint32_t width, uint32_t height) = 0;
|
||||
@@ -184,16 +215,18 @@ public:
|
||||
virtual void DisableAppWindowDecor() = 0;
|
||||
|
||||
virtual WMError RequestFocus() const = 0;
|
||||
virtual WMError UpdateSurfaceNodeAfterCustomAnimation(bool isAdd) = 0;
|
||||
// AddInputEventListener is for api 7
|
||||
virtual void SetInputEventConsumer(const std::shared_ptr<IInputEventConsumer>& inputEventConsumer) = 0;
|
||||
virtual void AddInputEventListener(const std::shared_ptr<MMI::IInputEventConsumer>& inputEventListener) = 0;
|
||||
virtual void ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent>& inputEvent) = 0;
|
||||
virtual void ConsumePointerEvent(std::shared_ptr<MMI::PointerEvent>& inputEvent) = 0;
|
||||
virtual void RequestFrame() = 0;
|
||||
virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) = 0;
|
||||
|
||||
virtual void RegisterLifeCycleListener(sptr<IWindowLifeCycle>& listener) = 0;
|
||||
virtual void RegisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener) = 0;
|
||||
virtual void RegisterWindowChangeListener(sptr<IWindowChangeListener>& listener) = 0;
|
||||
virtual void UnregisterLifeCycleListener(sptr<IWindowLifeCycle>& listener) = 0;
|
||||
virtual void UnregisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener) = 0;
|
||||
virtual void UnregisterWindowChangeListener(sptr<IWindowChangeListener>& listener) = 0;
|
||||
virtual void RegisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) = 0;
|
||||
virtual void UnregisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) = 0;
|
||||
@@ -201,23 +234,24 @@ public:
|
||||
virtual void UnregisterDragListener(const sptr<IWindowDragListener>& listener) = 0;
|
||||
virtual void RegisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) = 0;
|
||||
virtual void UnregisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) = 0;
|
||||
virtual void RegisterInputEventListener(sptr<IInputEventListener>& listener) = 0;
|
||||
virtual void UnregisterInputEventListener(sptr<IInputEventListener>& listener) = 0;
|
||||
virtual void RegisterInputEventListener(const sptr<IInputEventListener>& listener) = 0;
|
||||
virtual void UnregisterInputEventListener(const sptr<IInputEventListener>& listener) = 0;
|
||||
virtual void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) = 0;
|
||||
virtual void RegisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) = 0;
|
||||
virtual void UnregisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) = 0;
|
||||
virtual void RegisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener) = 0;
|
||||
virtual void UnregisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener) = 0;
|
||||
virtual void RegisterAnimationTransitionController(const sptr<IAnimationTransitionController>& listener) = 0;
|
||||
virtual void SetAceAbilityHandler(const sptr<IAceAbilityHandler>& handler) = 0;
|
||||
virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine,
|
||||
NativeValue* storage, bool isdistributed = false, AppExecFwk::Ability* ability = nullptr) = 0;
|
||||
NativeValue* storage, bool isDistributed = false, AppExecFwk::Ability* ability = nullptr) = 0;
|
||||
virtual std::string GetContentInfo() = 0;
|
||||
virtual Ace::UIContent* GetUIContent() const = 0;
|
||||
virtual void OnNewWant(const AAFwk::Want& want) = 0;
|
||||
virtual void SetRequestedOrientation(Orientation) = 0;
|
||||
virtual Orientation GetRequestedOrientation() = 0;
|
||||
virtual void SetModeSupportInfo(uint32_t modeSupportInfo) = 0;
|
||||
virtual uint32_t GetModeSupportInfo() const = 0;
|
||||
virtual void SetRequestModeSupportInfo(uint32_t modeSupportInfo) = 0;
|
||||
virtual uint32_t GetRequestModeSupportInfo() const = 0;
|
||||
virtual WMError SetTouchHotAreas(const std::vector<Rect>& rects) = 0;
|
||||
virtual void GetRequestedTouchHotAreas(std::vector<Rect>& rects) const = 0;
|
||||
|
||||
|
||||
@@ -125,6 +125,11 @@ public:
|
||||
virtual void OnWindowUpdate(const sptr<AccessibilityWindowInfo>& windowInfo, WindowUpdateType type) = 0;
|
||||
};
|
||||
|
||||
class ICameraFloatWindowChangedListener : virtual public RefBase {
|
||||
public:
|
||||
virtual void OnCameraFloatWindowChange(uint32_t accessTokenId, bool isShowing) = 0;
|
||||
};
|
||||
|
||||
class WindowManager {
|
||||
WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManager);
|
||||
friend class WindowManagerAgent;
|
||||
@@ -137,6 +142,8 @@ public:
|
||||
void UnregisterWindowUpdateListener(const sptr<IWindowUpdateListener>& listener);
|
||||
void RegisterVisibilityChangedListener(const sptr<IVisibilityChangedListener>& listener);
|
||||
void UnregisterVisibilityChangedListener(const sptr<IVisibilityChangedListener>& listener);
|
||||
void RegisterCameraFloatWindowChangedListener(const sptr<ICameraFloatWindowChangedListener>& listener);
|
||||
void UnregisterCameraFloatWindowChangedListener(const sptr<ICameraFloatWindowChangedListener>& listener);
|
||||
void MinimizeAllAppWindows(DisplayId displayId);
|
||||
WMError ToggleShownStateForAllAppWindows();
|
||||
WMError SetWindowLayoutMode(WindowLayoutMode mode);
|
||||
@@ -144,7 +151,7 @@ public:
|
||||
|
||||
private:
|
||||
WindowManager();
|
||||
~WindowManager();
|
||||
~WindowManager() = default;
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> pImpl_;
|
||||
|
||||
@@ -155,6 +162,7 @@ private:
|
||||
void NotifyAccessibilityWindowInfo(const sptr<AccessibilityWindowInfo>& windowInfo, WindowUpdateType type) const;
|
||||
void UpdateWindowVisibilityInfo(
|
||||
const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos) const;
|
||||
void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) const;
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -33,7 +33,6 @@ public:
|
||||
void SetWindowType(WindowType type);
|
||||
void SetWindowMode(WindowMode mode);
|
||||
void SetWindowBackgroundBlur(WindowBlurLevel level);
|
||||
void SetAlpha(float alpha);
|
||||
void SetFocusable(bool isFocusable);
|
||||
void SetTouchable(bool isTouchable);
|
||||
void SetDisplayId(DisplayId displayId);
|
||||
@@ -58,7 +57,6 @@ public:
|
||||
WindowType GetWindowType() const;
|
||||
WindowMode GetWindowMode() const;
|
||||
WindowBlurLevel GetWindowBackgroundBlur() const;
|
||||
float GetAlpha() const;
|
||||
bool GetFocusable() const;
|
||||
bool GetTouchable() const;
|
||||
DisplayId GetDisplayId() const;
|
||||
@@ -75,7 +73,6 @@ private:
|
||||
WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
|
||||
WindowMode mode_ { WindowMode::WINDOW_MODE_FULLSCREEN };
|
||||
WindowBlurLevel level_ { WindowBlurLevel::WINDOW_BLUR_OFF };
|
||||
float alpha_ { 1.0f };
|
||||
bool focusable_ { true };
|
||||
bool touchable_ { true };
|
||||
DisplayId displayId_ { 0 };
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#ifndef OHOS_ROSEN_WM_COMMON_H
|
||||
#define OHOS_ROSEN_WM_COMMON_H
|
||||
|
||||
#include <parcel.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
using DisplayId = uint64_t;
|
||||
@@ -59,6 +61,8 @@ enum class WindowType : uint32_t {
|
||||
WINDOW_TYPE_BOOT_ANIMATION,
|
||||
WINDOW_TYPE_FREEZE_DISPLAY,
|
||||
WINDOW_TYPE_VOICE_INTERACTION,
|
||||
WINDOW_TYPE_FLOAT_CAMERA,
|
||||
WINDOW_TYPE_PLACEHOLDER,
|
||||
ABOVE_APP_SYSTEM_WINDOW_END,
|
||||
SYSTEM_WINDOW_END = ABOVE_APP_SYSTEM_WINDOW_END,
|
||||
};
|
||||
@@ -99,6 +103,7 @@ enum class WMError : int32_t {
|
||||
WM_ERROR_DESTROYED_OBJECT,
|
||||
WM_ERROR_DEATH_RECIPIENT,
|
||||
WM_ERROR_INVALID_WINDOW,
|
||||
WM_ERROR_INVALID_WINDOW_MODE,
|
||||
WM_ERROR_INVALID_OPERATION,
|
||||
WM_ERROR_INVALID_PERMISSION,
|
||||
WM_ERROR_NO_REMOTE_ANIMATION,
|
||||
@@ -131,6 +136,7 @@ enum class WindowSizeChangeReason : uint32_t {
|
||||
RESIZE,
|
||||
MOVE,
|
||||
HIDE,
|
||||
TRANSFORM,
|
||||
};
|
||||
|
||||
enum class WindowLayoutMode : uint32_t {
|
||||
@@ -169,6 +175,45 @@ namespace {
|
||||
constexpr int32_t INVALID_UID = -1;
|
||||
}
|
||||
|
||||
class Transform {
|
||||
public:
|
||||
Transform()
|
||||
: pivotX_(0.5f), pivotY_(0.5f), scaleX_(1.f), scaleY_(1.f), rotationX_(0.f), rotationY_(0.f), rotationZ_(0.f),
|
||||
translateX_(0.f), translateY_(0.f), translateZ_(0.f)
|
||||
{}
|
||||
~Transform() {}
|
||||
|
||||
bool operator!=(const Transform& right) const
|
||||
{
|
||||
return (pivotX_ - right.pivotX_) || (pivotY_ - right.pivotY_) || (scaleX_ - right.scaleX_) ||
|
||||
(scaleY_ - right.scaleY_) || (rotationX_ - right.rotationX_) || (rotationY_ - right.rotationY_) ||
|
||||
(rotationZ_ - right.rotationZ_) || (translateX_ - right.translateX_) ||
|
||||
(translateY_ - right.translateY_) || (translateZ_ - right.translateZ_);
|
||||
}
|
||||
|
||||
bool operator==(const Transform& right) const
|
||||
{
|
||||
return !(*this != right);
|
||||
}
|
||||
|
||||
float pivotX_;
|
||||
float pivotY_;
|
||||
float scaleX_;
|
||||
float scaleY_;
|
||||
float rotationX_;
|
||||
float rotationY_;
|
||||
float rotationZ_;
|
||||
float translateX_;
|
||||
float translateY_;
|
||||
float translateZ_;
|
||||
|
||||
static const Transform& Identity()
|
||||
{
|
||||
static Transform I;
|
||||
return I;
|
||||
}
|
||||
};
|
||||
|
||||
struct SystemBarProperty {
|
||||
bool enable_;
|
||||
uint32_t backgroundColor_;
|
||||
@@ -198,6 +243,11 @@ struct Rect {
|
||||
return !this->operator==(a);
|
||||
}
|
||||
|
||||
bool isUninitializedRect() const
|
||||
{
|
||||
return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
|
||||
}
|
||||
|
||||
bool IsInsideOf(const Rect& a) const
|
||||
{
|
||||
return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
|
||||
@@ -209,6 +259,7 @@ enum class AvoidAreaType : uint32_t {
|
||||
TYPE_SYSTEM, // area of SystemUI
|
||||
TYPE_CUTOUT, // cutout of screen
|
||||
TYPE_SYSTEM_GESTURE, // area for system gesture
|
||||
TYPE_KEYBOARD, // area for soft input keyboard
|
||||
};
|
||||
|
||||
enum class OccupiedAreaType : uint32_t {
|
||||
@@ -223,13 +274,64 @@ enum class ColorSpace : uint32_t {
|
||||
enum class WindowAnimation : uint32_t {
|
||||
NONE,
|
||||
DEFAULT,
|
||||
CUSTOM,
|
||||
};
|
||||
|
||||
struct AvoidArea {
|
||||
Rect leftRect;
|
||||
Rect topRect;
|
||||
Rect rightRect;
|
||||
Rect bottomRect;
|
||||
class AvoidArea : public Parcelable {
|
||||
public:
|
||||
Rect topRect_ { 0, 0, 0, 0 };
|
||||
Rect leftRect_ { 0, 0, 0, 0 };
|
||||
Rect rightRect_ { 0, 0, 0, 0 };
|
||||
Rect bottomRect_ { 0, 0, 0, 0 };
|
||||
|
||||
bool operator==(const AvoidArea& a) const
|
||||
{
|
||||
return (leftRect_ == a.leftRect_ && topRect_ == a.topRect_ &&
|
||||
rightRect_ == a.rightRect_ && bottomRect_ == a.bottomRect_);
|
||||
}
|
||||
|
||||
bool operator!=(const AvoidArea& a) const
|
||||
{
|
||||
return !this->operator==(a);
|
||||
}
|
||||
|
||||
bool isEmptyAvoidArea() const
|
||||
{
|
||||
return topRect_.isUninitializedRect() && leftRect_.isUninitializedRect() &&
|
||||
rightRect_.isUninitializedRect() && bottomRect_.isUninitializedRect();
|
||||
}
|
||||
|
||||
static inline bool WriteParcel(Parcel& parcel, const Rect& rect)
|
||||
{
|
||||
return parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
|
||||
parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_);
|
||||
}
|
||||
|
||||
static inline bool ReadParcel(Parcel& parcel, Rect& rect)
|
||||
{
|
||||
return parcel.ReadInt32(rect.posX_) && parcel.ReadInt32(rect.posY_) &&
|
||||
parcel.ReadUint32(rect.width_) && parcel.ReadUint32(rect.height_);
|
||||
}
|
||||
|
||||
virtual bool Marshalling(Parcel& parcel) const override
|
||||
{
|
||||
return (WriteParcel(parcel, leftRect_) && WriteParcel(parcel, topRect_) &&
|
||||
WriteParcel(parcel, rightRect_) && WriteParcel(parcel, bottomRect_));
|
||||
}
|
||||
|
||||
static AvoidArea* Unmarshalling(Parcel& parcel)
|
||||
{
|
||||
AvoidArea *avoidArea = new(std::nothrow) AvoidArea();
|
||||
if (avoidArea == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
if (ReadParcel(parcel, avoidArea->leftRect_) && ReadParcel(parcel, avoidArea->topRect_) &&
|
||||
ReadParcel(parcel, avoidArea->rightRect_) && ReadParcel(parcel, avoidArea->bottomRect_)) {
|
||||
return avoidArea;
|
||||
}
|
||||
delete avoidArea;
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
enum class WindowUpdateType : int32_t {
|
||||
@@ -238,6 +340,7 @@ enum class WindowUpdateType : int32_t {
|
||||
WINDOW_UPDATE_FOCUSED,
|
||||
WINDOW_UPDATE_BOUNDS,
|
||||
WINDOW_UPDATE_ACTIVE,
|
||||
WINDOW_UPDATE_PROPERTY,
|
||||
};
|
||||
|
||||
struct SystemConfig {
|
||||
|
||||
@@ -35,9 +35,9 @@ ohos_shared_library("display_napi") {
|
||||
configs = [ ":display_config" ]
|
||||
|
||||
deps = [
|
||||
"${aafwk_kits_path}/ability/native:abilitykit_native",
|
||||
"${aafwk_kits_path}/appkit:app_context",
|
||||
"${aafwk_kits_path}/appkit:appkit_native",
|
||||
"${ability_runtime_path}/frameworks/native/ability/native:abilitykit_native",
|
||||
"${ability_runtime_path}/frameworks/native/appkit:app_context",
|
||||
"${ability_runtime_path}/frameworks/native/appkit:appkit_native",
|
||||
"../common:wm_napi_common",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||
"//foundation/windowmanager/dm:libdm",
|
||||
|
||||
@@ -33,6 +33,15 @@ public:
|
||||
private:
|
||||
sptr<Display> display_ = nullptr;
|
||||
};
|
||||
enum class DisplayStateMode : uint32_t {
|
||||
STATE_UNKNOWN = 0,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_DOZE,
|
||||
STATE_DOZE_SUSPEND,
|
||||
STATE_VR,
|
||||
STATE_ON_SUSPEND
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
#endif
|
||||
@@ -328,6 +328,36 @@ NativeValue* CreateJsDisplayArrayObject(NativeEngine& engine, std::vector<sptr<D
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* InitDisplayState(NativeEngine* engine)
|
||||
{
|
||||
WLOGFI("JsDisplayManager::InitDisplayState called");
|
||||
|
||||
if (engine == nullptr) {
|
||||
WLOGFE("engine is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *objValue = engine->CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to get object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
object->SetProperty("STATE_UNKNOWN", CreateJsValue(*engine, static_cast<int32_t>(DisplayStateMode::STATE_UNKNOWN)));
|
||||
object->SetProperty("STATE_OFF", CreateJsValue(*engine, static_cast<int32_t>(DisplayStateMode::STATE_OFF)));
|
||||
object->SetProperty("STATE_ON", CreateJsValue(*engine, static_cast<int32_t>(DisplayStateMode::STATE_ON)));
|
||||
object->SetProperty("STATE_DOZE",
|
||||
CreateJsValue(*engine, static_cast<int32_t>(DisplayStateMode::STATE_DOZE)));
|
||||
object->SetProperty("STATE_DOZE_SUSPEND",
|
||||
CreateJsValue(*engine, static_cast<int32_t>(DisplayStateMode::STATE_DOZE_SUSPEND)));
|
||||
object->SetProperty("STATE_VR",
|
||||
CreateJsValue(*engine, static_cast<int32_t>(DisplayStateMode::STATE_VR)));
|
||||
object->SetProperty("STATE_ON_SUSPEND",
|
||||
CreateJsValue(*engine, static_cast<int32_t>(DisplayStateMode::STATE_ON_SUSPEND)));
|
||||
return objValue;
|
||||
}
|
||||
|
||||
NativeValue* JsDisplayManagerInit(NativeEngine* engine, NativeValue* exportObj)
|
||||
{
|
||||
WLOGFI("JsDisplayManagerInit is called");
|
||||
@@ -346,6 +376,8 @@ NativeValue* JsDisplayManagerInit(NativeEngine* engine, NativeValue* exportObj)
|
||||
std::unique_ptr<JsDisplayManager> jsDisplayManager = std::make_unique<JsDisplayManager>(engine);
|
||||
object->SetNativePointer(jsDisplayManager.release(), JsDisplayManager::Finalizer, nullptr);
|
||||
|
||||
object->SetProperty("DisplayState", InitDisplayState(engine));
|
||||
|
||||
BindNativeFunction(*engine, *object, "getDefaultDisplay", JsDisplayManager::GetDefaultDisplay);
|
||||
BindNativeFunction(*engine, *object, "getDefaultDisplaySync", JsDisplayManager::GetDefaultDisplaySync);
|
||||
BindNativeFunction(*engine, *object, "getAllDisplay", JsDisplayManager::GetAllDisplay);
|
||||
|
||||
@@ -38,9 +38,9 @@ ohos_shared_library("screenrecorder_napi") {
|
||||
|
||||
configs = [ ":screen_runtime_config" ]
|
||||
deps = [
|
||||
"${aafwk_kits_path}/ability/native:abilitykit_native",
|
||||
"${aafwk_kits_path}/appkit:app_context",
|
||||
"${aafwk_kits_path}/appkit:appkit_native",
|
||||
"${ability_runtime_path}/frameworks/native/ability/native:abilitykit_native",
|
||||
"${ability_runtime_path}/frameworks/native/appkit:app_context",
|
||||
"${ability_runtime_path}/frameworks/native/appkit:appkit_native",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||
"//foundation/windowmanager/dm:libdm",
|
||||
"//foundation/windowmanager/dmserver:libdms",
|
||||
@@ -52,6 +52,7 @@ ohos_shared_library("screenrecorder_napi") {
|
||||
"ability_base:want",
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:runtime",
|
||||
"hitrace_native:hitrace_meter",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"napi:ace_napi",
|
||||
]
|
||||
|
||||
@@ -81,7 +81,7 @@ DMError ScreenRecorder::Start(std::vector<int> fds)
|
||||
void ScreenRecorder::Record()
|
||||
{
|
||||
WLOGFE("Record");
|
||||
if (stop_ || fileIndex_ >= fds_.size()) {
|
||||
if (stop_ || fileIndex_ >= static_cast<int>(fds_.size())) {
|
||||
isStarting_ = false;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,9 +37,9 @@ ohos_shared_library("screen_napi") {
|
||||
|
||||
configs = [ ":screen_runtime_config" ]
|
||||
deps = [
|
||||
"${aafwk_kits_path}/ability/native:abilitykit_native",
|
||||
"${aafwk_kits_path}/appkit:app_context",
|
||||
"${aafwk_kits_path}/appkit:appkit_native",
|
||||
"${ability_runtime_path}/frameworks/native/ability/native:abilitykit_native",
|
||||
"${ability_runtime_path}/frameworks/native/appkit:app_context",
|
||||
"${ability_runtime_path}/frameworks/native/appkit:appkit_native",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||
"//foundation/windowmanager/dm:libdm",
|
||||
"//foundation/windowmanager/dmserver:libdms",
|
||||
|
||||
@@ -82,6 +82,21 @@ declare namespace screen {
|
||||
function setVirtualScreenSurface(screenId:number, surfaceId: string, callback: AsyncCallback<void>): void;
|
||||
function setVirtualScreenSurface(screenId:number, surfaceId: string): Promise<void>;
|
||||
|
||||
/**
|
||||
* Get screen rotation lock status.
|
||||
* @since 9
|
||||
*/
|
||||
function isScreenRotationLocked(callback: AsyncCallback<boolean>): void;
|
||||
function isScreenRotationLocked(): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Set screen rotation lock status.
|
||||
* @param isLocked Indicates whether the screen rotation switch is locked.
|
||||
* @since 9
|
||||
*/
|
||||
function setScreenRotationLocked(isLocked:boolean, callback: AsyncCallback<void>): void;
|
||||
function setScreenRotationLocked(isLocked:boolean): Promise<void>;
|
||||
|
||||
/**
|
||||
* the parameter of making expand screen
|
||||
* @syscap SystemCapability.WindowManager.WindowManager.Core
|
||||
|
||||
@@ -98,6 +98,18 @@ static NativeValue* SetVirtualScreenSurface(NativeEngine* engine, NativeCallback
|
||||
JsScreenManager* me = CheckParamsAndGetThis<JsScreenManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnSetVirtualScreenSurface(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* IsScreenRotationLocked(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsScreenManager* me = CheckParamsAndGetThis<JsScreenManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnIsScreenRotationLocked(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
static NativeValue* SetScreenRotationLocked(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
JsScreenManager* me = CheckParamsAndGetThis<JsScreenManager>(engine, info);
|
||||
return (me != nullptr) ? me->OnSetScreenRotationLocked(*engine, *info) : nullptr;
|
||||
}
|
||||
private:
|
||||
std::map<std::string, std::map<std::unique_ptr<NativeReference>, sptr<JsScreenListener>>> jsCbMap_;
|
||||
std::mutex mtx_;
|
||||
@@ -607,8 +619,102 @@ NativeValue* OnSetVirtualScreenSurface(NativeEngine& engine, NativeCallbackInfo&
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* OnIsScreenRotationLocked(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("OnIsScreenRotationLocked is called");
|
||||
DMError errCode = DMError::DM_OK;
|
||||
if (info.argc > 1) {
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
|
||||
errCode = DMError::DM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != DMError::DM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
bool isLocked = SingletonContainer::Get<ScreenManager>().IsScreenRotationLocked();
|
||||
task.Resolve(engine, CreateJsValue(engine, isLocked));
|
||||
};
|
||||
NativeValue* lastParam = nullptr;
|
||||
if (info.argc == ARGC_ONE && info.argv[ARGC_ONE - 1]->TypeOf() == NATIVE_FUNCTION) {
|
||||
lastParam = info.argv[ARGC_ONE - 1];
|
||||
}
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule("JsScreenManager::OnIsScreenRotationLocked",
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* OnSetScreenRotationLocked(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WLOGFI("JsScreenManager::OnSetScreenRotationLocked is called");
|
||||
DMError errCode = DMError::DM_OK;
|
||||
if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
|
||||
errCode = DMError::DM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
bool isLocked = false;
|
||||
if (errCode == DMError::DM_OK) {
|
||||
NativeBoolean* nativeVal = ConvertNativeValueTo<NativeBoolean>(info.argv[0]);
|
||||
if (nativeVal == nullptr) {
|
||||
WLOGFE("[NAPI]Failed to convert parameter to isLocked");
|
||||
errCode = DMError::DM_ERROR_INVALID_PARAM;
|
||||
} else {
|
||||
isLocked = static_cast<bool>(*nativeVal);
|
||||
}
|
||||
}
|
||||
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[isLocked, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
if (errCode != DMError::DM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params."));
|
||||
return;
|
||||
}
|
||||
SingletonContainer::Get<ScreenManager>().SetScreenRotationLocked(isLocked);
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
};
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule("JsScreenManager::OnSetScreenRotationLocked",
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
NativeValue* InitScreenOrientation(NativeEngine* engine)
|
||||
{
|
||||
WLOGFI("JsScreenManager::InitScreenOrientation called");
|
||||
|
||||
if (engine == nullptr) {
|
||||
WLOGFE("engine is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *objValue = engine->CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("Failed to get object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
object->SetProperty("UNSPECIFIED", CreateJsValue(*engine, static_cast<int32_t>(Orientation::UNSPECIFIED)));
|
||||
object->SetProperty("VERTICAL", CreateJsValue(*engine, static_cast<int32_t>(Orientation::VERTICAL)));
|
||||
object->SetProperty("HORIZONTAL", CreateJsValue(*engine, static_cast<int32_t>(Orientation::HORIZONTAL)));
|
||||
object->SetProperty("REVERSE_VERTICAL",
|
||||
CreateJsValue(*engine, static_cast<int32_t>(Orientation::REVERSE_VERTICAL)));
|
||||
object->SetProperty("REVERSE_HORIZONTAL",
|
||||
CreateJsValue(*engine, static_cast<int32_t>(Orientation::REVERSE_HORIZONTAL)));
|
||||
object->SetProperty("SENSOR", CreateJsValue(*engine, static_cast<int32_t>(Orientation::SENSOR)));
|
||||
object->SetProperty("SENSOR_VERTICAL",
|
||||
CreateJsValue(*engine, static_cast<int32_t>(Orientation::SENSOR_VERTICAL)));
|
||||
object->SetProperty("SENSOR_HORIZONTAL",
|
||||
CreateJsValue(*engine, static_cast<int32_t>(Orientation::SENSOR_HORIZONTAL)));
|
||||
return objValue;
|
||||
}
|
||||
|
||||
NativeValue* JsScreenManagerInit(NativeEngine* engine, NativeValue* exportObj)
|
||||
{
|
||||
WLOGFI("JsScreenManagerInit is called");
|
||||
@@ -627,6 +733,8 @@ NativeValue* JsScreenManagerInit(NativeEngine* engine, NativeValue* exportObj)
|
||||
std::unique_ptr<JsScreenManager> jsScreenManager = std::make_unique<JsScreenManager>(engine);
|
||||
object->SetNativePointer(jsScreenManager.release(), JsScreenManager::Finalizer, nullptr);
|
||||
|
||||
object->SetProperty("Orientation", InitScreenOrientation(engine));
|
||||
|
||||
BindNativeFunction(*engine, *object, "getAllScreens", JsScreenManager::GetAllScreens);
|
||||
BindNativeFunction(*engine, *object, "on", JsScreenManager::RegisterScreenManagerCallback);
|
||||
BindNativeFunction(*engine, *object, "off", JsScreenManager::UnregisterScreenMangerCallback);
|
||||
@@ -635,6 +743,8 @@ NativeValue* JsScreenManagerInit(NativeEngine* engine, NativeValue* exportObj)
|
||||
BindNativeFunction(*engine, *object, "createVirtualScreen", JsScreenManager::CreateVirtualScreen);
|
||||
BindNativeFunction(*engine, *object, "destroyVirtualScreen", JsScreenManager::DestroyVirtualScreen);
|
||||
BindNativeFunction(*engine, *object, "setVirtualScreenSurface", JsScreenManager::SetVirtualScreenSurface);
|
||||
BindNativeFunction(*engine, *object, "setScreenRotationLocked", JsScreenManager::SetScreenRotationLocked);
|
||||
BindNativeFunction(*engine, *object, "isScreenRotationLocked", JsScreenManager::IsScreenRotationLocked);
|
||||
return engine->CreateUndefined();
|
||||
}
|
||||
} // namespace Rosen
|
||||
|
||||
@@ -50,9 +50,9 @@ ohos_shared_library("window_native_kit") {
|
||||
|
||||
configs = [ ":window_native_kit_config" ]
|
||||
deps = [
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||
"//foundation/windowmanager/utils:libwmutil",
|
||||
"//foundation/windowmanager/wm:libwm",
|
||||
"//foundation/windowmanager/wmserver:libwms",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
@@ -77,12 +77,12 @@ ohos_shared_library("window_napi") {
|
||||
configs = [ ":window_manager_napi_config" ]
|
||||
deps = [
|
||||
":window_native_kit",
|
||||
"${aafwk_kits_path}/ability/native:abilitykit_native",
|
||||
"${aafwk_kits_path}/appkit:app_context",
|
||||
"${aafwk_kits_path}/appkit:appkit_native",
|
||||
"${ability_runtime_path}/frameworks/native/ability/native:abilitykit_native",
|
||||
"${ability_runtime_path}/frameworks/native/appkit:app_context",
|
||||
"${ability_runtime_path}/frameworks/native/appkit:appkit_native",
|
||||
"//foundation/windowmanager/utils:libwmutil",
|
||||
"//foundation/windowmanager/wm:libwm",
|
||||
"//foundation/windowmanager/wmserver:libwms",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
@@ -109,13 +109,13 @@ ohos_shared_library("windowstage_kit") {
|
||||
":window_native_kit",
|
||||
"//foundation/windowmanager/utils:libwmutil",
|
||||
"//foundation/windowmanager/wm:libwm",
|
||||
"//foundation/windowmanager/wmserver:libwms",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_runtime:ability_manager",
|
||||
"ability_runtime:runtime",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"napi:ace_napi",
|
||||
"utils_base:utils",
|
||||
]
|
||||
|
||||
+171
-3
@@ -83,8 +83,90 @@ declare namespace window {
|
||||
/**
|
||||
* area for system gesture
|
||||
*/
|
||||
TYPE_SYSTEM_GESTURE
|
||||
TYPE_SYSTEM_GESTURE,
|
||||
|
||||
/**
|
||||
* area for soft input keyboard
|
||||
* @since 9
|
||||
*/
|
||||
TYPE_KEYBOARD
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the scale Transition Options of window
|
||||
* @syscap SystemCapability.WindowManager.WindowManager.Core
|
||||
* @since 9
|
||||
* @systemapi
|
||||
*/
|
||||
declare interface ScaleOptions {
|
||||
/**
|
||||
* The scale param of x direction. Default is 1.f
|
||||
*/
|
||||
x?: number;
|
||||
/**
|
||||
* The scale param of y direction. Default is 1.f
|
||||
*/
|
||||
y?: number;
|
||||
/**
|
||||
* The scale param of pivot point of x. Default is 0.5f, Interval is 0.f - 1.f
|
||||
*/
|
||||
pivotX?: number;
|
||||
/**
|
||||
* The scale param of pivot point of y. Default is 0.5f, Interval is 0.f - 1.f
|
||||
*/
|
||||
pivotY?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the rotate Transition Options of window
|
||||
* @syscap SystemCapability.WindowManager.WindowManager.Core
|
||||
* @since 9
|
||||
* @systemapi
|
||||
*/
|
||||
declare interface RotateOptions {
|
||||
/**
|
||||
* The rotate degree of x direction. Default value is 0.f
|
||||
*/
|
||||
x?: number;
|
||||
/**
|
||||
* The rotate degree of y direction. Default value is 0.f
|
||||
*/
|
||||
y?: number;
|
||||
/**
|
||||
* The rotate degree of z direction. Default value is 0.f
|
||||
*/
|
||||
z?: number;
|
||||
/**
|
||||
* The param of pivot point of x. Default is 0.5f, Interval is 0.f - 1.f
|
||||
*/
|
||||
pivotX?: number;
|
||||
/**
|
||||
* The param of pivot point of y. Default is 0.5f, Interval is 0.f - 1.f
|
||||
*/
|
||||
pivotY?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the translate Transition Options of window
|
||||
* @syscap SystemCapability.WindowManager.WindowManager.Core
|
||||
* @since 9
|
||||
* @systemapi
|
||||
*/
|
||||
declare interface TranslateOptions {
|
||||
/**
|
||||
* The translate pixel param of x direction. Default is 0.f
|
||||
*/
|
||||
x?: number;
|
||||
/**
|
||||
* The translate pixel param of y direction. Default is 0.f
|
||||
*/
|
||||
y?: number;
|
||||
/**
|
||||
* The translate pixel param of z direction. Default is 0.f
|
||||
*/
|
||||
z?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes the window mode of an application
|
||||
* @systemapi Hide this for inner system use.
|
||||
@@ -375,6 +457,12 @@ declare namespace window {
|
||||
* @since 7
|
||||
*/
|
||||
interface AvoidArea {
|
||||
/**
|
||||
* Whether avoidArea is visible on screen
|
||||
* @since 9
|
||||
*/
|
||||
visible: boolean;
|
||||
|
||||
/**
|
||||
* Rectangle on the left of the screen
|
||||
*/
|
||||
@@ -743,6 +831,7 @@ declare namespace window {
|
||||
* @param type: 'systemAvoidAreaChange'
|
||||
* @syscap SystemCapability.WindowManager.WindowManager.Core
|
||||
* @since 7
|
||||
* @deprecated since 9, please use on_avoidAreaChange instead.
|
||||
*/
|
||||
on(type: 'systemAvoidAreaChange', callback: Callback<AvoidArea>): void;
|
||||
|
||||
@@ -751,9 +840,26 @@ declare namespace window {
|
||||
* @param type: 'systemAvoidAreaChange'
|
||||
* @syscap SystemCapability.WindowManager.WindowManager.Core
|
||||
* @since 7
|
||||
* @deprecated since 9, please use off_avoidAreaChange instead.
|
||||
*/
|
||||
off(type: 'systemAvoidAreaChange', callback?: Callback<AvoidArea>): void;
|
||||
|
||||
/**
|
||||
* register the callback of avoidAreaChange
|
||||
* @param type: 'avoidAreaChange'
|
||||
* @syscap SystemCapability.WindowManager.WindowManager.Core
|
||||
* @since 9
|
||||
*/
|
||||
on(type: 'avoidAreaChange', callback: Callback<{ type: AvoidAreaType, area: AvoidArea }>): void;
|
||||
|
||||
/**
|
||||
* unregister the callback of avoidAreaChange
|
||||
* @param type: 'avoidAreaChange'
|
||||
* @syscap SystemCapability.WindowManager.WindowManager.Core
|
||||
* @since 9
|
||||
*/
|
||||
off(type: 'avoidAreaChange', callback?: Callback<{ type: AvoidAreaType, area: AvoidArea }>): void;
|
||||
|
||||
/**
|
||||
* Whether the window supports thr wide gamut setting.
|
||||
* @since 8
|
||||
@@ -918,6 +1024,20 @@ declare namespace window {
|
||||
*/
|
||||
setTransparent(isTransparent: boolean, callback: AsyncCallback<void>): void;
|
||||
|
||||
/**
|
||||
* Set the preferred orientation config of a window
|
||||
* @param orientation the orientation config of a window
|
||||
* @since 9
|
||||
*/
|
||||
setPreferredOrientation(orientation: Orientation): Promise<void>;
|
||||
|
||||
/**
|
||||
* Set the preferred orientation config of a window
|
||||
* @param orientation the orientation config of a window
|
||||
* @since 9
|
||||
*/
|
||||
setPreferredOrientation(orientation: Orientation, callback: AsyncCallback<void>): void;
|
||||
|
||||
/**
|
||||
* disable window decoration. It must be called before loadContent.
|
||||
* @systemapi
|
||||
@@ -941,7 +1061,7 @@ declare namespace window {
|
||||
* @systemapi
|
||||
* @since 9
|
||||
*/
|
||||
setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback<void>): void;
|
||||
setForbidSplitMove(isForbidSplitMove: boolean, callback: AsyncCallback<void>): void;
|
||||
|
||||
/**
|
||||
* set the flag of the window is forbidden to move in split screen mode
|
||||
@@ -950,7 +1070,35 @@ declare namespace window {
|
||||
* @systemapi
|
||||
* @since 9
|
||||
*/
|
||||
setForbidSplitMove(isForbidSplitMove: boolean): Promise<void>;
|
||||
setForbidSplitMove(isForbidSplitMove: boolean): Promise<void>;
|
||||
/**
|
||||
* Sets opacity of window
|
||||
* @param opacity Interval is 0.f-1.f.
|
||||
* @systemapi
|
||||
* @since 9
|
||||
*/
|
||||
setOpacitySync(opacity: number): void;
|
||||
/**
|
||||
* Sets scale options of window.
|
||||
* @param scaleOptions scale param of window.
|
||||
* @systemapi
|
||||
* @since 9
|
||||
*/
|
||||
setScaleSync(scaleOptions: ScaleOptions): void;
|
||||
/**
|
||||
* Sets rotate options of window.
|
||||
* @param rotateOptions rotate param of window.
|
||||
* @systemapi
|
||||
* @since 9
|
||||
*/
|
||||
setRotateSync(rotateOptions: RotateOptions): void;
|
||||
/**
|
||||
* Sets whether is transparent or not.
|
||||
* @param translateOptions translate param of window.
|
||||
* @systemapi
|
||||
* @since 9
|
||||
*/
|
||||
setTranslateSync(translateOptions: TranslateOptions): void;
|
||||
}
|
||||
|
||||
enum WindowStageEventType {
|
||||
@@ -1043,6 +1191,26 @@ declare namespace window {
|
||||
*/
|
||||
off(eventType: 'windowStageEvent', callback?: Callback<WindowStageEventType>): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* screen orientation
|
||||
* @syscap SystemCapability.WindowManager.WindowManager.Core
|
||||
* @since 9
|
||||
*/
|
||||
enum Orientation {
|
||||
UNSPECIFIED = 0,
|
||||
PORTRAIT = 1,
|
||||
LANDSCAPE = 2,
|
||||
PORTRAIT_INVERTED = 3,
|
||||
LANDSCAPE_INVERTED = 4,
|
||||
AUTO_ROTATION = 5,
|
||||
AUTO_ROTATION_PORTRAIT = 6,
|
||||
AUTO_ROTATION_LANDSCAPE = 7,
|
||||
AUTO_ROTATION_RESTRICTED = 8,
|
||||
AUTO_ROTATION_PORTRAIT_RESTRICTED = 9,
|
||||
AUTO_ROTATION_LANDSCAPE_RESTRICTED = 10,
|
||||
LOCKED = 11,
|
||||
}
|
||||
}
|
||||
|
||||
export default window;
|
||||
|
||||
@@ -166,7 +166,7 @@ static void CreateSystemWindowTask(void* contextPtr, std::string windowName, Win
|
||||
WLOGFE("[NAPI]Context is nullptr");
|
||||
return;
|
||||
}
|
||||
if (winType == WindowType::WINDOW_TYPE_FLOAT) {
|
||||
if (winType == WindowType::WINDOW_TYPE_FLOAT || winType == WindowType::WINDOW_TYPE_FLOAT_CAMERA) {
|
||||
auto abilityContext = Context::ConvertTo<AbilityRuntime::AbilityContext>(context->lock());
|
||||
if (abilityContext != nullptr) {
|
||||
if (!CheckCallingPermission("ohos.permission.SYSTEM_FLOAT_WINDOW")) {
|
||||
@@ -538,7 +538,7 @@ NativeValue* JsWindowManager::OnSetWindowLayoutMode(NativeEngine& engine, Native
|
||||
if (winLayoutMode != WindowLayoutMode::CASCADE && winLayoutMode != WindowLayoutMode::TILE) {
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
|
||||
WLOGFI("[NAPI]LayoutMode = %{public}u, err = %{public}d", winLayoutMode, errCode);
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
@@ -586,6 +586,7 @@ NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj)
|
||||
object->SetProperty("ColorSpace", ColorSpaceInit(engine));
|
||||
object->SetProperty("WindowStageEventType", WindowStageEventTypeInit(engine));
|
||||
object->SetProperty("WindowLayoutMode", WindowLayoutModeInit(engine));
|
||||
object->SetProperty("Orientation", OrientationInit(engine));
|
||||
BindNativeFunction(*engine, *object, "create", JsWindowManager::CreateWindow);
|
||||
BindNativeFunction(*engine, *object, "find", JsWindowManager::FindWindow);
|
||||
BindNativeFunction(*engine, *object, "on", JsWindowManager::RegisterWindowManagerCallback);
|
||||
|
||||
@@ -15,8 +15,10 @@
|
||||
|
||||
#include "js_window.h"
|
||||
#include <new>
|
||||
#include <ui/rs_surface_node.h>
|
||||
#include "js_window_utils.h"
|
||||
#include "window.h"
|
||||
#include "window_helper.h"
|
||||
#include "window_manager_hilog.h"
|
||||
#include "window_option.h"
|
||||
namespace OHOS {
|
||||
@@ -29,24 +31,28 @@ namespace {
|
||||
|
||||
static thread_local std::map<std::string, std::shared_ptr<NativeReference>> g_jsWindowMap;
|
||||
std::recursive_mutex g_mutex;
|
||||
static int ctorCnt = 0;
|
||||
static int dtorCnt = 0;
|
||||
static int finalizerCnt = 0;
|
||||
JsWindow::JsWindow(const sptr<Window>& window)
|
||||
: windowToken_(window), registerManager_(std::make_unique<JsWindowRegisterManager>())
|
||||
{
|
||||
NotifyNativeWinDestroyFunc func = [](std::string windowName) {
|
||||
std::lock_guard<std::recursive_mutex> lock(g_mutex);
|
||||
if (windowName.empty() || g_jsWindowMap.count(windowName) == 0) {
|
||||
WLOGE("[NAPI]Can not find window %{public}s ", windowName.c_str());
|
||||
WLOGFE("[NAPI]Can not find window %{public}s ", windowName.c_str());
|
||||
return;
|
||||
}
|
||||
g_jsWindowMap.erase(windowName);
|
||||
WLOGE("[NAPI]Destroy window %{public}s in js window", windowName.c_str());
|
||||
WLOGFI("[NAPI]Destroy window %{public}s in js window", windowName.c_str());
|
||||
};
|
||||
windowToken_->RegisterWindowDestroyedListener(func);
|
||||
WLOGFI("[NAPI] JsWindow constructor Count: %{public}d", ++ctorCnt);
|
||||
}
|
||||
|
||||
JsWindow::~JsWindow()
|
||||
{
|
||||
WLOGFI("[NAPI]~JsWindow");
|
||||
WLOGFI("[NAPI]~JsWindow deconstructor Count:%{public}d", ++dtorCnt);
|
||||
windowToken_ = nullptr;
|
||||
}
|
||||
|
||||
@@ -60,7 +66,7 @@ std::string JsWindow::GetWindowName()
|
||||
|
||||
void JsWindow::Finalizer(NativeEngine* engine, void* data, void* hint)
|
||||
{
|
||||
WLOGFI("[NAPI]Finalizer");
|
||||
WLOGFI("[NAPI]Finalizer Count:%{public}d", ++finalizerCnt);
|
||||
auto jsWin = std::unique_ptr<JsWindow>(static_cast<JsWindow*>(data));
|
||||
if (jsWin == nullptr) {
|
||||
WLOGFE("[NAPI]jsWin is nullptr");
|
||||
@@ -271,6 +277,13 @@ NativeValue* JsWindow::SetCallingWindow(NativeEngine* engine, NativeCallbackInfo
|
||||
return (me != nullptr) ? me->OnSetCallingWindow(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::SetPreferredOrientation(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("[NAPI]SetPreferredOrientation");
|
||||
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
|
||||
return (me != nullptr) ? me->OnSetPreferredOrientation(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::DisableWindowDecor(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("[NAPI]DisableWindowDecor");
|
||||
@@ -306,6 +319,34 @@ NativeValue* JsWindow::SetForbidSplitMove(NativeEngine* engine, NativeCallbackIn
|
||||
return (me != nullptr) ? me->OnSetForbidSplitMove(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::SetOpacitySync(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("[NAPI]SetOpacitySync");
|
||||
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
|
||||
return (me != nullptr) ? me->OnSetOpacitySync(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::SetScaleSync(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("[NAPI]SetScaleSync");
|
||||
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
|
||||
return (me != nullptr) ? me->OnSetScaleSync(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::SetRotateSync(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("[NAPI]SetRotateSync");
|
||||
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
|
||||
return (me != nullptr) ? me->OnSetRotateSync(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::SetTranslateSync(NativeEngine* engine, NativeCallbackInfo* info)
|
||||
{
|
||||
WLOGFI("[NAPI]SetTranslateSync");
|
||||
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
|
||||
return (me != nullptr) ? me->OnSetTranslateSync(*engine, *info) : nullptr;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::OnShow(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WMError errCode = WMError::WM_OK;
|
||||
@@ -972,10 +1013,13 @@ NativeValue* JsWindow::OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo&
|
||||
AvoidArea avoidArea;
|
||||
WMError ret = weakWindow->GetAvoidAreaByType(avoidAreaType, avoidArea);
|
||||
if (ret != WMError::WM_OK) {
|
||||
avoidArea = { g_emptyRect, g_emptyRect, g_emptyRect, g_emptyRect }; // left, top, right, bottom
|
||||
avoidArea.topRect_ = g_emptyRect;
|
||||
avoidArea.leftRect_ = g_emptyRect;
|
||||
avoidArea.rightRect_ = g_emptyRect;
|
||||
avoidArea.bottomRect_ = g_emptyRect;
|
||||
}
|
||||
// native avoidArea -> js avoidArea
|
||||
NativeValue* avoidAreaObj = ChangeAvoidAreaToJsValue(engine, avoidArea);
|
||||
NativeValue* avoidAreaObj = ConvertAvoidAreaToJsValue(engine, avoidArea, avoidAreaType);
|
||||
if (avoidAreaObj != nullptr) {
|
||||
task.Resolve(engine, avoidAreaObj);
|
||||
} else {
|
||||
@@ -1023,6 +1067,53 @@ NativeValue* JsWindow::OnIsShowing(NativeEngine& engine, NativeCallbackInfo& inf
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::OnSetPreferredOrientation(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WMError errCode = WMError::WM_OK;
|
||||
Orientation requestedOrientation = Orientation::UNSPECIFIED;
|
||||
if (info.argc < 1 || info.argc > 2) { // 2: maximum params num
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
} else {
|
||||
NativeNumber* nativeType = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
|
||||
if (nativeType == nullptr) {
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
WLOGFE("[NAPI]Failed to convert parameter to Orientation");
|
||||
} else {
|
||||
requestedOrientation = JS_TO_NATIVE_ORIENTATION_MAP.at(
|
||||
static_cast<ApiOrientation>(static_cast<uint32_t>(*nativeType)));
|
||||
if (requestedOrientation < Orientation::BEGIN || requestedOrientation > Orientation::END) {
|
||||
WLOGFE("[NAPI]Orientation %{public}u invalid!", static_cast<uint32_t>(requestedOrientation));
|
||||
errCode = WMError::WM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
}
|
||||
}
|
||||
wptr<Window> weakToken(windowToken_);
|
||||
AsyncTask::CompleteCallback complete =
|
||||
[weakToken, requestedOrientation, errCode](NativeEngine& engine, AsyncTask& task, int32_t status) {
|
||||
auto weakWindow = weakToken.promote();
|
||||
if (weakWindow == nullptr || errCode != WMError::WM_OK) {
|
||||
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode),
|
||||
"OnSetPreferredOrientation failed"));
|
||||
WLOGFE("[NAPI]Window is nullptr or get invalid param");
|
||||
return;
|
||||
}
|
||||
weakWindow->SetRequestedOrientation(requestedOrientation);
|
||||
task.Resolve(engine, engine.CreateUndefined());
|
||||
WLOGFI("[NAPI]Window [%{public}u, %{public}s] OnSetPreferredOrientation end, orientation = %{public}u",
|
||||
weakWindow->GetWindowId(),
|
||||
weakWindow->GetWindowName().c_str(),
|
||||
static_cast<uint32_t>(requestedOrientation));
|
||||
};
|
||||
|
||||
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
|
||||
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
|
||||
NativeValue* result = nullptr;
|
||||
AsyncTask::Schedule("JsWindow::OnSetPreferredOrientation",
|
||||
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::OnIsSupportWideGamut(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
WMError errCode = WMError::WM_OK;
|
||||
@@ -1586,6 +1677,199 @@ NativeValue* JsWindow::OnSetForbidSplitMove(NativeEngine& engine, NativeCallback
|
||||
return result;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::OnSetOpacitySync(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
if (info.argc != 1 || windowToken_ == nullptr) {
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu or windowToken_ is nullptr", info.argc);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
|
||||
WLOGFE("[NAPI]SetOpacitySync is not allowed since window is not system window");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
NativeNumber* nativeVal = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
|
||||
if (nativeVal == nullptr) {
|
||||
WLOGFE("[NAPI]Failed to convert parameter to alpha");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
float alpha = static_cast<double>(*nativeVal);
|
||||
windowToken_->SetAlpha(alpha);
|
||||
WLOGFI("[NAPI]Window [%{public}u, %{public}s] SetOpacitySync end, alpha = %{public}f",
|
||||
windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), alpha);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
bool JsWindow::ParseScaleOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans)
|
||||
{
|
||||
auto surfaceNode = windowToken_->GetSurfaceNode();
|
||||
if (surfaceNode == nullptr) {
|
||||
WLOGFE("[NAPI] surfaceNode is nullptr");
|
||||
return false;
|
||||
}
|
||||
double data = 0.0f;
|
||||
if (ParseJsDoubleValue(jsObject, engine, "pivotX", data)) {
|
||||
surfaceNode->SetPivotX(data);
|
||||
trans.pivotX_ = data;
|
||||
}
|
||||
if (ParseJsDoubleValue(jsObject, engine, "pivotY", data)) {
|
||||
surfaceNode->SetPivotY(data);
|
||||
trans.pivotY_ = data;
|
||||
}
|
||||
if (ParseJsDoubleValue(jsObject, engine, "x", data)) {
|
||||
surfaceNode->SetScaleX(data);
|
||||
trans.scaleX_ = data;
|
||||
}
|
||||
if (ParseJsDoubleValue(jsObject, engine, "y", data)) {
|
||||
surfaceNode->SetScaleY(data);
|
||||
trans.scaleY_ = data;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::OnSetScaleSync(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
if (info.argc != 1 || windowToken_ == nullptr) {
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu or windowToken_ is nullptr", info.argc);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
|
||||
WLOGFE("[NAPI]SetScaleSync is not allowed since window is not system window");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
NativeObject* nativeObj = ConvertNativeValueTo<NativeObject>(info.argv[0]);
|
||||
if (nativeObj == nullptr) {
|
||||
WLOGFE("[NAPI]Failed to convert object to ScaleOptions");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
auto trans = windowToken_->GetTransform();
|
||||
if (!ParseScaleOption(engine, nativeObj, trans)) {
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
windowToken_->SetTransform(trans);
|
||||
WLOGFI("[NAPI]Window [%{public}u, %{public}s] SetScaleSync end",
|
||||
windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str());
|
||||
WLOGFI("[NAPI]scaleX = %{public}f, scaleY = %{public}f, pivotX = %{public}f pivotY = %{public}f",
|
||||
trans.scaleX_, trans.scaleY_, trans.pivotX_, trans.pivotY_);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
bool JsWindow::ParseRotateOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans)
|
||||
{
|
||||
auto surfaceNode = windowToken_->GetSurfaceNode();
|
||||
if (surfaceNode == nullptr) {
|
||||
WLOGFE("[NAPI] surfaceNode is nullptr");
|
||||
return false;
|
||||
}
|
||||
double data = 0.0f;
|
||||
if (ParseJsDoubleValue(jsObject, engine, "pivotX", data)) {
|
||||
surfaceNode->SetPivotX(data);
|
||||
trans.pivotX_ = data;
|
||||
}
|
||||
if (ParseJsDoubleValue(jsObject, engine, "pivotY", data)) {
|
||||
surfaceNode->SetPivotY(data);
|
||||
trans.pivotY_ = data;
|
||||
}
|
||||
double coeff = 0.5 * 3.14 / 180; // 0.5 means half; 3.14 means pi; 180 means degree
|
||||
if (ParseJsDoubleValue(jsObject, engine, "x", data)) {
|
||||
float w = std::cos(data * coeff);
|
||||
float x = std::sin(data * coeff);
|
||||
surfaceNode->SetRotation(Quaternion(x, 0, 0, w));
|
||||
trans.rotationX_ = data;
|
||||
}
|
||||
if (ParseJsDoubleValue(jsObject, engine, "y", data)) {
|
||||
float w = std::cos(data * coeff);
|
||||
float y = std::sin(data * coeff);
|
||||
surfaceNode->SetRotation(Quaternion(0, y, 0, w));
|
||||
trans.rotationY_ = data;
|
||||
}
|
||||
if (ParseJsDoubleValue(jsObject, engine, "z", data)) {
|
||||
float w = std::cos(data * coeff);
|
||||
float z = std::sin(data * coeff);
|
||||
surfaceNode->SetRotation(Quaternion(0, 0, z, w));
|
||||
trans.rotationZ_ = data;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::OnSetRotateSync(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
if (info.argc != 1 || windowToken_ == nullptr) {
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu or windowToken_ is nullptr", info.argc);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
|
||||
WLOGFE("[NAPI]SetRotateSync is not allowed since window is not system window");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
NativeObject* nativeObj = ConvertNativeValueTo<NativeObject>(info.argv[0]);
|
||||
if (nativeObj == nullptr) {
|
||||
WLOGFE("[NAPI]Failed to convert object to RotateOptions");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
// cannot use sync task since next transform base on current transform
|
||||
auto trans = windowToken_->GetTransform();
|
||||
if (!ParseRotateOption(engine, nativeObj, trans)) {
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
windowToken_->SetTransform(trans);
|
||||
WLOGFI("[NAPI]Window [%{public}u, %{public}s] SetRotateSync end",
|
||||
windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str());
|
||||
WLOGFI("[NAPI]rotateX = %{public}f, rotateY = %{public}f," \
|
||||
"rotateZ = %{public}f pivotX = %{public}f pivotY = %{public}f",
|
||||
trans.rotationX_, trans.rotationY_, trans.rotationZ_, trans.pivotX_, trans.pivotY_);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
bool JsWindow::ParseTranslateOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans)
|
||||
{
|
||||
auto surfaceNode = windowToken_->GetSurfaceNode();
|
||||
if (surfaceNode == nullptr) {
|
||||
WLOGFE("[NAPI] surfaceNode is nullptr");
|
||||
return false;
|
||||
}
|
||||
double data = 0.0f;
|
||||
if (ParseJsDoubleValue(jsObject, engine, "x", data)) {
|
||||
surfaceNode->SetTranslateX(data);
|
||||
trans.translateX_ = data;
|
||||
}
|
||||
if (ParseJsDoubleValue(jsObject, engine, "y", data)) {
|
||||
surfaceNode->SetTranslateY(data);
|
||||
trans.translateY_ = data;
|
||||
}
|
||||
if (ParseJsDoubleValue(jsObject, engine, "z", data)) {
|
||||
surfaceNode->SetTranslateZ(data);
|
||||
trans.translateZ_ = data;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
NativeValue* JsWindow::OnSetTranslateSync(NativeEngine& engine, NativeCallbackInfo& info)
|
||||
{
|
||||
if (info.argc != 1 || windowToken_ == nullptr) {
|
||||
WLOGFE("[NAPI]Argc is invalid: %{public}zu or windowToken_ is nullptr", info.argc);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
if (!WindowHelper::IsSystemWindow(windowToken_->GetType())) {
|
||||
WLOGFE("[NAPI]SetTranslateSync is not allowed since window is not system window");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
NativeObject* nativeObj = ConvertNativeValueTo<NativeObject>(info.argv[0]);
|
||||
if (nativeObj == nullptr) {
|
||||
WLOGFE("[NAPI]Failed to convert object to TranslateOptions");
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
auto trans = windowToken_->GetTransform();
|
||||
if (!ParseTranslateOption(engine, nativeObj, trans)) {
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
windowToken_->SetTransform(trans);
|
||||
WLOGFI("[NAPI]Window [%{public}u, %{public}s] SetRotateSync end," \
|
||||
"translateX = %{public}f, translateY = %{public}f, translateZ = %{public}f",
|
||||
windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(),
|
||||
trans.translateX_, trans.translateY_, trans.translateZ_);
|
||||
return engine.CreateUndefined();
|
||||
}
|
||||
|
||||
std::shared_ptr<NativeReference> FindJsWindowObject(std::string windowName)
|
||||
{
|
||||
WLOGFI("[NAPI]Try to find window %{public}s in g_jsWindowMap", windowName.c_str());
|
||||
@@ -1614,6 +1898,17 @@ NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr<Window>& window)
|
||||
std::unique_ptr<JsWindow> jsWindow = std::make_unique<JsWindow>(window);
|
||||
object->SetNativePointer(jsWindow.release(), JsWindow::Finalizer, nullptr);
|
||||
|
||||
BindFunctions(engine, object);
|
||||
|
||||
std::shared_ptr<NativeReference> jsWindowRef;
|
||||
jsWindowRef.reset(engine.CreateReference(objValue, 1));
|
||||
std::lock_guard<std::recursive_mutex> lock(g_mutex);
|
||||
g_jsWindowMap[windowName] = jsWindowRef;
|
||||
return objValue;
|
||||
}
|
||||
|
||||
void BindFunctions(NativeEngine& engine, NativeObject* object)
|
||||
{
|
||||
BindNativeFunction(engine, *object, "show", JsWindow::Show);
|
||||
BindNativeFunction(engine, *object, "destroy", JsWindow::Destroy);
|
||||
BindNativeFunction(engine, *object, "hide", JsWindow::Hide);
|
||||
@@ -1647,12 +1942,11 @@ NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr<Window>& window)
|
||||
BindNativeFunction(engine, *object, "disableWindowDecor", JsWindow::DisableWindowDecor);
|
||||
BindNativeFunction(engine, *object, "dump", JsWindow::Dump);
|
||||
BindNativeFunction(engine, *object, "setForbidSplitMove", JsWindow::SetForbidSplitMove);
|
||||
|
||||
std::shared_ptr<NativeReference> jsWindowRef;
|
||||
jsWindowRef.reset(engine.CreateReference(objValue, 1));
|
||||
std::lock_guard<std::recursive_mutex> lock(g_mutex);
|
||||
g_jsWindowMap[windowName] = jsWindowRef;
|
||||
return objValue;
|
||||
BindNativeFunction(engine, *object, "setPreferredOrientation", JsWindow::SetPreferredOrientation);
|
||||
BindNativeFunction(engine, *object, "setOpacitySync", JsWindow::SetOpacitySync);
|
||||
BindNativeFunction(engine, *object, "setScaleSync", JsWindow::SetScaleSync);
|
||||
BindNativeFunction(engine, *object, "setRotateSync", JsWindow::SetRotateSync);
|
||||
BindNativeFunction(engine, *object, "setTranslateSync", JsWindow::SetTranslateSync);
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace OHOS {
|
||||
namespace Rosen {
|
||||
NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr<Window>& window);
|
||||
std::shared_ptr<NativeReference> FindJsWindowObject(std::string windowName);
|
||||
void BindFunctions(NativeEngine& engine, NativeObject* object);
|
||||
class JsWindow final {
|
||||
public:
|
||||
explicit JsWindow(const sptr<Window>& window);
|
||||
@@ -59,7 +60,7 @@ public:
|
||||
static NativeValue* SetTouchable(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* SetTransparent(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* SetCallingWindow(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
|
||||
static NativeValue* SetPreferredOrientation(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* DisableWindowDecor(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
// colorspace, gamut
|
||||
static NativeValue* IsSupportWideGamut(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
@@ -68,8 +69,16 @@ public:
|
||||
static NativeValue* Dump(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* SetForbidSplitMove(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
|
||||
// animation config
|
||||
static NativeValue* SetOpacitySync(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* SetScaleSync(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* SetRotateSync(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
static NativeValue* SetTranslateSync(NativeEngine* engine, NativeCallbackInfo* info);
|
||||
private:
|
||||
std::string GetWindowName();
|
||||
bool ParseScaleOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans);
|
||||
bool ParseRotateOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans);
|
||||
bool ParseTranslateOption(NativeEngine& engine, NativeObject* jsObject, Transform& trans);
|
||||
NativeValue* OnShow(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
NativeValue* OnDestroy(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
NativeValue* OnHide(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
@@ -87,6 +96,7 @@ private:
|
||||
NativeValue* OnLoadContent(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
NativeValue* OnGetAvoidArea(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
NativeValue* OnIsShowing(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
NativeValue* OnSetPreferredOrientation(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
|
||||
// colorspace, gamut
|
||||
NativeValue* OnIsSupportWideGamut(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
@@ -106,6 +116,11 @@ private:
|
||||
NativeValue* OnDump(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
NativeValue* OnSetForbidSplitMove(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
|
||||
// animation Config
|
||||
NativeValue* OnSetOpacitySync(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
NativeValue* OnSetScaleSync(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
NativeValue* OnSetRotateSync(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
NativeValue* OnSetTranslateSync(NativeEngine& engine, NativeCallbackInfo& info);
|
||||
sptr<Window> windowToken_ = nullptr;
|
||||
std::unique_ptr<JsWindowRegisterManager> registerManager_ = nullptr;
|
||||
};
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "js_window_listener.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "window_manager_hilog.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
using namespace AbilityRuntime;
|
||||
@@ -22,7 +23,6 @@ namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "JsWindowListener"};
|
||||
}
|
||||
|
||||
constexpr uint32_t AVOID_AREA_NUM = 4;
|
||||
JsWindowListener::~JsWindowListener()
|
||||
{
|
||||
WLOGFI("[NAPI]~JsWindowListener");
|
||||
@@ -48,7 +48,7 @@ void JsWindowListener::OnSizeChange(Rect rect, WindowSizeChangeReason reason)
|
||||
WLOGFI("[NAPI]OnSizeChange, wh[%{public}u, %{public}u], reason = %{public}u", rect.width_, rect.height_, reason);
|
||||
// js callback should run in js thread
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
|
||||
[self = wptr<JsWindowListener>(this), rect, eng = engine_] (NativeEngine &engine,
|
||||
[self = weakRef_, rect, eng = engine_] (NativeEngine &engine,
|
||||
AsyncTask &task, int32_t status) {
|
||||
auto thisListener = self.promote();
|
||||
if (thisListener == nullptr || eng == nullptr) {
|
||||
@@ -84,7 +84,7 @@ void JsWindowListener::OnSystemBarPropertyChange(DisplayId displayId, const Syst
|
||||
WLOGFI("[NAPI]OnSystemBarPropertyChange");
|
||||
// js callback should run in js thread
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
|
||||
[self = wptr<JsWindowListener>(this), displayId, tints, eng = engine_] (NativeEngine &engine,
|
||||
[self = weakRef_, displayId, tints, eng = engine_] (NativeEngine &engine,
|
||||
AsyncTask &task, int32_t status) {
|
||||
auto thisListener = self.promote();
|
||||
if (thisListener == nullptr || eng == nullptr) {
|
||||
@@ -110,37 +110,29 @@ void JsWindowListener::OnSystemBarPropertyChange(DisplayId displayId, const Syst
|
||||
*engine_, std::make_unique<AsyncTask>(callback, std::move(execute), std::move(complete)));
|
||||
}
|
||||
|
||||
void JsWindowListener::OnAvoidAreaChanged(const std::vector<Rect> avoidAreas)
|
||||
void JsWindowListener::OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type)
|
||||
{
|
||||
WLOGFI("[NAPI]OnAvoidAreaChanged");
|
||||
// js callback should run in js thread
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
|
||||
[self = wptr<JsWindowListener>(this), avoidAreas, eng = engine_] (NativeEngine &engine,
|
||||
[self = weakRef_, avoidArea, type, eng = engine_] (NativeEngine &engine,
|
||||
AsyncTask &task, int32_t status) {
|
||||
auto thisListener = self.promote();
|
||||
if (thisListener == nullptr || eng == nullptr) {
|
||||
WLOGFE("[NAPI]this listener or engine is nullptr");
|
||||
return;
|
||||
}
|
||||
NativeValue* avoidAreaValue = eng->CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(avoidAreaValue);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("[NAPI]Failed to convert rect to jsObject");
|
||||
NativeValue* avoidAreaValue = ConvertAvoidAreaToJsValue(engine, avoidArea, type);
|
||||
if (avoidAreaValue == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (static_cast<uint32_t>(avoidAreas.size()) != AVOID_AREA_NUM) {
|
||||
WLOGFE("[NAPI]AvoidAreas size is not 4 (left, top, right, bottom), size is %{public}u",
|
||||
static_cast<uint32_t>(avoidAreas.size()));
|
||||
return;
|
||||
if (thisListener->isDeprecatedInterface_) {
|
||||
NativeValue* argv[] = { avoidAreaValue };
|
||||
thisListener->CallJsMethod(SYSTEM_AVOID_AREA_CHANGE_CB.c_str(), argv, ArraySize(argv));
|
||||
} else {
|
||||
NativeValue* argv[] = { CreateJsValue(engine, static_cast<uint32_t>(type)), avoidAreaValue };
|
||||
thisListener->CallJsMethod(AVOID_AREA_CHANGE_CB.c_str(), argv, ArraySize(argv));
|
||||
}
|
||||
|
||||
object->SetProperty("leftRect", GetRectAndConvertToJsValue(*eng, avoidAreas[0])); // idx 0 : left
|
||||
object->SetProperty("topRect", GetRectAndConvertToJsValue(*eng, avoidAreas[1])); // idx 1 : top
|
||||
object->SetProperty("rightRect", GetRectAndConvertToJsValue(*eng, avoidAreas[2])); // idx 2 : right
|
||||
object->SetProperty("bottomRect", GetRectAndConvertToJsValue(*eng, avoidAreas[3])); // idx 3 : bottom
|
||||
NativeValue* argv[] = {avoidAreaValue};
|
||||
thisListener->CallJsMethod(SYSTEM_AVOID_AREA_CHANGE_CB.c_str(), argv, ArraySize(argv));
|
||||
}
|
||||
);
|
||||
|
||||
@@ -154,7 +146,7 @@ void JsWindowListener::LifeCycleCallBack(LifeCycleEventType eventType)
|
||||
{
|
||||
WLOGFI("[NAPI]LifeCycleCallBack, envent type: %{public}u", eventType);
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback>(
|
||||
[self = wptr<JsWindowListener>(this), eventType, eng = engine_] (NativeEngine &engine,
|
||||
[self = weakRef_, eventType, eng = engine_] (NativeEngine &engine,
|
||||
AsyncTask &task, int32_t status) {
|
||||
auto thisListener = self.promote();
|
||||
if (thisListener == nullptr || eng == nullptr) {
|
||||
@@ -198,7 +190,7 @@ void JsWindowListener::OnSizeChange(const sptr<OccupiedAreaChangeInfo>& info)
|
||||
info->rect_.posX_, info->rect_.posY_, info->rect_.width_, info->rect_.height_);
|
||||
// js callback should run in js thread
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
|
||||
[self = wptr<JsWindowListener>(this), info, eng = engine_] (NativeEngine &engine,
|
||||
[self = weakRef_, info, eng = engine_] (NativeEngine &engine,
|
||||
AsyncTask &task, int32_t status) {
|
||||
auto thisListener = self.promote();
|
||||
if (thisListener == nullptr || eng == nullptr) {
|
||||
@@ -216,10 +208,10 @@ void JsWindowListener::OnSizeChange(const sptr<OccupiedAreaChangeInfo>& info)
|
||||
*engine_, std::make_unique<AsyncTask>(callback, std::move(execute), std::move(complete)));
|
||||
}
|
||||
|
||||
void JsWindowListener::OnTouchOutside()
|
||||
void JsWindowListener::OnTouchOutside() const
|
||||
{
|
||||
std::unique_ptr<AsyncTask::CompleteCallback> complete = std::make_unique<AsyncTask::CompleteCallback> (
|
||||
[self = wptr<JsWindowListener>(this)] (NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
[self = weakRef_] (NativeEngine &engine, AsyncTask &task, int32_t status) {
|
||||
auto thisListener = self.promote();
|
||||
if (thisListener == nullptr) {
|
||||
WLOGFE("[NAPI]this listener is nullptr");
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
#include "class_var_definition.h"
|
||||
#include "js_window_utils.h"
|
||||
#include "native_engine/native_engine.h"
|
||||
#include "native_engine/native_value.h"
|
||||
@@ -31,6 +33,7 @@ namespace Rosen {
|
||||
const std::string WINDOW_SIZE_CHANGE_CB = "windowSizeChange";
|
||||
const std::string SYSTEM_BAR_TINT_CHANGE_CB = "systemBarTintChange";
|
||||
const std::string SYSTEM_AVOID_AREA_CHANGE_CB = "systemAvoidAreaChange";
|
||||
const std::string AVOID_AREA_CHANGE_CB = "avoidAreaChange";
|
||||
const std::string LIFECYCLE_EVENT_CB = "lifeCycleEvent";
|
||||
const std::string WINDOW_STAGE_EVENT_CB = "windowStageEvent";
|
||||
const std::string KEYBOARD_HEIGHT_CHANGE_CB = "keyboardHeightChange";
|
||||
@@ -44,23 +47,25 @@ class JsWindowListener : public IWindowChangeListener,
|
||||
public ITouchOutsideListener {
|
||||
public:
|
||||
JsWindowListener(NativeEngine* engine, std::shared_ptr<NativeReference> callback)
|
||||
: engine_(engine), jsCallBack_(callback) {}
|
||||
: engine_(engine), jsCallBack_(callback), weakRef_(wptr<JsWindowListener> (this)) {}
|
||||
~JsWindowListener();
|
||||
void OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints) override;
|
||||
void OnSizeChange(Rect rect, WindowSizeChangeReason reason) override;
|
||||
void OnModeChange(WindowMode mode) override;
|
||||
void OnAvoidAreaChanged(std::vector<Rect> avoidAreas) override;
|
||||
void OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type) override;
|
||||
void AfterForeground() override;
|
||||
void AfterBackground() override;
|
||||
void AfterFocused() override;
|
||||
void AfterUnfocused() override;
|
||||
void OnSizeChange(const sptr<OccupiedAreaChangeInfo>& info) override;
|
||||
void OnTouchOutside() override;
|
||||
void OnTouchOutside() const override;
|
||||
void CallJsMethod(const char* methodName, NativeValue* const* argv = nullptr, size_t argc = 0);
|
||||
private:
|
||||
void LifeCycleCallBack(LifeCycleEventType eventType);
|
||||
NativeEngine* engine_ = nullptr;
|
||||
std::shared_ptr<NativeReference> jsCallBack_ = nullptr;
|
||||
wptr<JsWindowListener> weakRef_ = nullptr;
|
||||
DEFINE_VAR_DEFAULT_FUNC_SET(bool, IsDeprecatedInterface, isDeprecatedInterface, false)
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -30,11 +30,12 @@ JsWindowRegisterManager::JsWindowRegisterManager()
|
||||
};
|
||||
// white register list for window
|
||||
listenerProcess_[CaseType::CASE_WINDOW] = {
|
||||
{WINDOW_SIZE_CHANGE_CB, &JsWindowRegisterManager::ProcessWindowChangeRegister },
|
||||
{SYSTEM_AVOID_AREA_CHANGE_CB, &JsWindowRegisterManager::ProcessAvoidAreaChangeRegister },
|
||||
{LIFECYCLE_EVENT_CB, &JsWindowRegisterManager::ProcessLifeCycleEventRegister },
|
||||
{KEYBOARD_HEIGHT_CHANGE_CB, &JsWindowRegisterManager::ProcesOccupiedAreaChangeRegister },
|
||||
{TOUCH_OUTSIDE_CB, &JsWindowRegisterManager::ProcessTouchOutsideRegister }
|
||||
{ WINDOW_SIZE_CHANGE_CB, &JsWindowRegisterManager::ProcessWindowChangeRegister },
|
||||
{ SYSTEM_AVOID_AREA_CHANGE_CB, &JsWindowRegisterManager::ProcessSystemAvoidAreaChangeRegister },
|
||||
{ AVOID_AREA_CHANGE_CB, &JsWindowRegisterManager::ProcessAvoidAreaChangeRegister },
|
||||
{ LIFECYCLE_EVENT_CB, &JsWindowRegisterManager::ProcessLifeCycleEventRegister },
|
||||
{ KEYBOARD_HEIGHT_CHANGE_CB, &JsWindowRegisterManager::ProcessOccupiedAreaChangeRegister },
|
||||
{ TOUCH_OUTSIDE_CB, &JsWindowRegisterManager::ProcessTouchOutsideRegister }
|
||||
};
|
||||
// white register list for window stage
|
||||
listenerProcess_[CaseType::CASE_STAGE] = {
|
||||
@@ -62,6 +63,27 @@ bool JsWindowRegisterManager::ProcessWindowChangeRegister(sptr<JsWindowListener>
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JsWindowRegisterManager::ProcessSystemAvoidAreaChangeRegister(sptr<JsWindowListener> listener,
|
||||
sptr<Window> window, bool isRegister)
|
||||
{
|
||||
if (window == nullptr) {
|
||||
WLOGFE("[NAPI]Window is nullptr");
|
||||
return false;
|
||||
}
|
||||
if (listener == nullptr) {
|
||||
WLOGFE("[NAPI]listener is nullptr");
|
||||
return false;
|
||||
}
|
||||
listener->SetIsDeprecatedInterface(true);
|
||||
sptr<IAvoidAreaChangedListener> thisListener(listener);
|
||||
if (isRegister) {
|
||||
window->RegisterAvoidAreaChangeListener(thisListener);
|
||||
} else {
|
||||
window->UnregisterAvoidAreaChangeListener(thisListener);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JsWindowRegisterManager::ProcessAvoidAreaChangeRegister(sptr<JsWindowListener> listener,
|
||||
sptr<Window> window, bool isRegister)
|
||||
{
|
||||
@@ -94,7 +116,7 @@ bool JsWindowRegisterManager::ProcessLifeCycleEventRegister(sptr<JsWindowListene
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JsWindowRegisterManager::ProcesOccupiedAreaChangeRegister(sptr<JsWindowListener> listener,
|
||||
bool JsWindowRegisterManager::ProcessOccupiedAreaChangeRegister(sptr<JsWindowListener> listener,
|
||||
sptr<Window> window, bool isRegister)
|
||||
{
|
||||
if (window == nullptr) {
|
||||
|
||||
@@ -40,9 +40,10 @@ public:
|
||||
private:
|
||||
bool IsCallbackRegistered(std::string type, NativeValue* jsListenerObject);
|
||||
bool ProcessWindowChangeRegister(sptr<JsWindowListener> listener, sptr<Window> window, bool isRegister);
|
||||
bool ProcessSystemAvoidAreaChangeRegister(sptr<JsWindowListener> listener, sptr<Window> window, bool isRegister);
|
||||
bool ProcessAvoidAreaChangeRegister(sptr<JsWindowListener> listener, sptr<Window> window, bool isRegister);
|
||||
bool ProcessLifeCycleEventRegister(sptr<JsWindowListener> listener, sptr<Window> window, bool isRegister);
|
||||
bool ProcesOccupiedAreaChangeRegister(sptr<JsWindowListener> listener, sptr<Window> window, bool isRegister);
|
||||
bool ProcessOccupiedAreaChangeRegister(sptr<JsWindowListener> listener, sptr<Window> window, bool isRegister);
|
||||
bool ProcessSystemBarChangeRegister(sptr<JsWindowListener> listener, sptr<Window> window, bool isRegister);
|
||||
bool ProcessTouchOutsideRegister(sptr<JsWindowListener> listener, sptr<Window> window, bool isRegister);
|
||||
using Func_t = bool(JsWindowRegisterManager::*)(sptr<JsWindowListener>, sptr<Window> window, bool);
|
||||
|
||||
@@ -62,6 +62,8 @@ NativeValue* WindowTypeInit(NativeEngine* engine)
|
||||
static_cast<int32_t>(ApiWindowType::TYPE_NAVIGATION_BAR)));
|
||||
object->SetProperty("TYPE_FLOAT", CreateJsValue(*engine,
|
||||
static_cast<int32_t>(ApiWindowType::TYPE_FLOAT)));
|
||||
object->SetProperty("TYPE_FLOAT_CAMERA", CreateJsValue(*engine,
|
||||
static_cast<int32_t>(ApiWindowType::TYPE_FLOAT_CAMERA)));
|
||||
object->SetProperty("TYPE_WALLPAPER", CreateJsValue(*engine,
|
||||
static_cast<int32_t>(ApiWindowType::TYPE_WALLPAPER)));
|
||||
object->SetProperty("TYPE_DESKTOP", CreateJsValue(*engine,
|
||||
@@ -98,6 +100,9 @@ NativeValue* AvoidAreaTypeInit(NativeEngine* engine)
|
||||
static_cast<int32_t>(AvoidAreaType::TYPE_SYSTEM)));
|
||||
object->SetProperty("TYPE_CUTOUT", CreateJsValue(*engine,
|
||||
static_cast<int32_t>(AvoidAreaType::TYPE_CUTOUT)));
|
||||
object->SetProperty("TYPE_SYSTEM_GESTURE", CreateJsValue(*engine,
|
||||
static_cast<int32_t>(AvoidAreaType::TYPE_SYSTEM_GESTURE)));
|
||||
object->SetProperty("TYPE_KEYBOARD", CreateJsValue(*engine, static_cast<int32_t>(AvoidAreaType::TYPE_KEYBOARD)));
|
||||
return objValue;
|
||||
}
|
||||
|
||||
@@ -153,6 +158,49 @@ NativeValue* ColorSpaceInit(NativeEngine* engine)
|
||||
return objValue;
|
||||
}
|
||||
|
||||
NativeValue* OrientationInit(NativeEngine* engine)
|
||||
{
|
||||
WLOGFI("[NAPI]OrientationInit");
|
||||
|
||||
if (engine == nullptr) {
|
||||
WLOGFE("[NAPI]Engine is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
NativeValue *objValue = engine->CreateObject();
|
||||
NativeObject *object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("[NAPI]Failed to get object");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
object->SetProperty("UNSPECIFIED", CreateJsValue(*engine,
|
||||
static_cast<int32_t>(Orientation::UNSPECIFIED)));
|
||||
object->SetProperty("PORTRAIT", CreateJsValue(*engine,
|
||||
static_cast<int32_t>(Orientation::VERTICAL)));
|
||||
object->SetProperty("LANDSCAPE", CreateJsValue(*engine,
|
||||
static_cast<int32_t>(Orientation::HORIZONTAL)));
|
||||
object->SetProperty("PORTRAIT_INVERTED", CreateJsValue(*engine,
|
||||
static_cast<int32_t>(Orientation::REVERSE_VERTICAL)));
|
||||
object->SetProperty("LANDSCAPE_INVERTED", CreateJsValue(*engine,
|
||||
static_cast<int32_t>(Orientation::REVERSE_HORIZONTAL)));
|
||||
object->SetProperty("AUTO_ROTATION", CreateJsValue(*engine,
|
||||
static_cast<int32_t>(Orientation::SENSOR)));
|
||||
object->SetProperty("AUTO_ROTATION_PORTRAIT", CreateJsValue(*engine,
|
||||
static_cast<int32_t>(Orientation::SENSOR_VERTICAL)));
|
||||
object->SetProperty("AUTO_ROTATION_LANDSCAPE", CreateJsValue(*engine,
|
||||
static_cast<int32_t>(Orientation::SENSOR_HORIZONTAL)));
|
||||
object->SetProperty("AUTO_ROTATION_RESTRICTED", CreateJsValue(*engine,
|
||||
static_cast<int32_t>(Orientation::AUTO_ROTATION_RESTRICTED)));
|
||||
object->SetProperty("AUTO_ROTATION_PORTRAIT_RESTRICTED", CreateJsValue(*engine,
|
||||
static_cast<int32_t>(Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED)));
|
||||
object->SetProperty("AUTO_ROTATION_LANDSCAPE_RESTRICTED", CreateJsValue(*engine,
|
||||
static_cast<int32_t>(Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED)));
|
||||
object->SetProperty("LOCKED", CreateJsValue(*engine,
|
||||
static_cast<int32_t>(Orientation::LOCKED)));
|
||||
return objValue;
|
||||
}
|
||||
|
||||
NativeValue* WindowStageEventTypeInit(NativeEngine* engine)
|
||||
{
|
||||
WLOGFI("[NAPI]WindowStageEventTypeInit");
|
||||
@@ -202,7 +250,7 @@ NativeValue* WindowLayoutModeInit(NativeEngine* engine)
|
||||
return objValue;
|
||||
}
|
||||
|
||||
NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect rect)
|
||||
NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect& rect)
|
||||
{
|
||||
NativeValue* objValue = engine.CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
@@ -425,18 +473,19 @@ bool SetSystemBarPropertiesFromJs(NativeEngine& engine, NativeObject* jsObject,
|
||||
return true;
|
||||
}
|
||||
|
||||
NativeValue* ChangeAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avoidArea)
|
||||
NativeValue* ConvertAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avoidArea, AvoidAreaType type)
|
||||
{
|
||||
NativeValue* objValue = engine.CreateObject();
|
||||
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
|
||||
if (object == nullptr) {
|
||||
WLOGFE("[NAPI]Failed to convert rect to jsObject");
|
||||
return engine.CreateUndefined();
|
||||
WLOGFE("[NAPI]Failed to convert avoidArea to jsObject");
|
||||
return nullptr;
|
||||
}
|
||||
object->SetProperty("leftRect", GetRectAndConvertToJsValue(engine, avoidArea.leftRect));
|
||||
object->SetProperty("topRect", GetRectAndConvertToJsValue(engine, avoidArea.topRect));
|
||||
object->SetProperty("rightRect", GetRectAndConvertToJsValue(engine, avoidArea.rightRect));
|
||||
object->SetProperty("bottomRect", GetRectAndConvertToJsValue(engine, avoidArea.bottomRect));
|
||||
object->SetProperty("visible", CreateJsValue(engine, type == AvoidAreaType::TYPE_CUTOUT ? false : true));
|
||||
object->SetProperty("leftRect", GetRectAndConvertToJsValue(engine, avoidArea.leftRect_));
|
||||
object->SetProperty("topRect", GetRectAndConvertToJsValue(engine, avoidArea.topRect_));
|
||||
object->SetProperty("rightRect", GetRectAndConvertToJsValue(engine, avoidArea.rightRect_));
|
||||
object->SetProperty("bottomRect", GetRectAndConvertToJsValue(engine, avoidArea.bottomRect_));
|
||||
return objValue;
|
||||
}
|
||||
|
||||
@@ -478,5 +527,20 @@ bool GetAPI7Ability(NativeEngine& engine, AppExecFwk::Ability* &ability)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ParseJsDoubleValue(NativeObject* jsObject, NativeEngine& engine, const std::string& name, double& data)
|
||||
{
|
||||
NativeValue* value = jsObject->GetProperty(name.c_str());
|
||||
if (value->TypeOf() != NATIVE_UNDEFINED) {
|
||||
if (!ConvertFromJsValue(engine, value, data)) {
|
||||
WLOGFE("[NAPI]Failed to convert parameter to scale %{public}s", name.c_str());
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
WLOGFI("[NAPI]no property with: %{public}s", name.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -44,7 +44,8 @@ enum class ApiWindowType : uint32_t {
|
||||
TYPE_LAUNCHER_DOCK,
|
||||
TYPE_VOICE_INTERACTION,
|
||||
TYPE_POINTER,
|
||||
TYPE_END = TYPE_POINTER,
|
||||
TYPE_FLOAT_CAMERA,
|
||||
TYPE_END = TYPE_FLOAT_CAMERA,
|
||||
};
|
||||
|
||||
enum class LifeCycleEventType : uint32_t {
|
||||
@@ -64,6 +65,7 @@ const std::map<WindowType, ApiWindowType> NATIVE_JS_TO_WINDOW_TYPE_MAP {
|
||||
{ WindowType::WINDOW_TYPE_VOLUME_OVERLAY, ApiWindowType::TYPE_VOLUME_OVERLAY },
|
||||
{ WindowType::WINDOW_TYPE_NAVIGATION_BAR, ApiWindowType::TYPE_NAVIGATION_BAR },
|
||||
{ WindowType::WINDOW_TYPE_FLOAT, ApiWindowType::TYPE_FLOAT },
|
||||
{ WindowType::WINDOW_TYPE_FLOAT_CAMERA, ApiWindowType::TYPE_FLOAT_CAMERA },
|
||||
{ WindowType::WINDOW_TYPE_WALLPAPER, ApiWindowType::TYPE_WALLPAPER },
|
||||
{ WindowType::WINDOW_TYPE_DESKTOP, ApiWindowType::TYPE_DESKTOP },
|
||||
{ WindowType::WINDOW_TYPE_LAUNCHER_RECENT, ApiWindowType::TYPE_LAUNCHER_RECENT },
|
||||
@@ -82,6 +84,7 @@ const std::map<ApiWindowType, WindowType> JS_TO_NATIVE_WINDOW_TYPE_MAP {
|
||||
{ ApiWindowType::TYPE_VOLUME_OVERLAY, WindowType::WINDOW_TYPE_VOLUME_OVERLAY },
|
||||
{ ApiWindowType::TYPE_NAVIGATION_BAR, WindowType::WINDOW_TYPE_NAVIGATION_BAR },
|
||||
{ ApiWindowType::TYPE_FLOAT, WindowType::WINDOW_TYPE_FLOAT },
|
||||
{ ApiWindowType::TYPE_FLOAT_CAMERA, WindowType::WINDOW_TYPE_FLOAT_CAMERA },
|
||||
{ ApiWindowType::TYPE_WALLPAPER, WindowType::WINDOW_TYPE_WALLPAPER },
|
||||
{ ApiWindowType::TYPE_DESKTOP, WindowType::WINDOW_TYPE_DESKTOP },
|
||||
{ ApiWindowType::TYPE_LAUNCHER_RECENT, WindowType::WINDOW_TYPE_LAUNCHER_RECENT },
|
||||
@@ -115,7 +118,37 @@ const std::map<ApiWindowMode, WindowMode> JS_TO_NATIVE_WINDOW_MODE_MAP {
|
||||
{ApiWindowMode::FLOATING, WindowMode::WINDOW_MODE_FLOATING },
|
||||
};
|
||||
|
||||
NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect rect);
|
||||
enum class ApiOrientation : uint32_t {
|
||||
UNSPECIFIED = 0,
|
||||
PORTRAIT = 1,
|
||||
LANDSCAPE = 2,
|
||||
PORTRAIT_INVERTED = 3,
|
||||
LANDSCAPE_INVERTED = 4,
|
||||
AUTO_ROTATION = 5,
|
||||
AUTO_ROTATION_PORTRAIT = 6,
|
||||
AUTO_ROTATION_LANDSCAPE = 7,
|
||||
AUTO_ROTATION_RESTRICTED = 8,
|
||||
AUTO_ROTATION_PORTRAIT_RESTRICTED = 9,
|
||||
AUTO_ROTATION_LANDSCAPE_RESTRICTED = 10,
|
||||
LOCKED = 11,
|
||||
};
|
||||
|
||||
const std::map<ApiOrientation, Orientation> JS_TO_NATIVE_ORIENTATION_MAP {
|
||||
{ApiOrientation::UNSPECIFIED, Orientation::UNSPECIFIED },
|
||||
{ApiOrientation::PORTRAIT, Orientation::VERTICAL },
|
||||
{ApiOrientation::LANDSCAPE, Orientation::HORIZONTAL },
|
||||
{ApiOrientation::PORTRAIT_INVERTED, Orientation::REVERSE_VERTICAL },
|
||||
{ApiOrientation::LANDSCAPE_INVERTED, Orientation::REVERSE_HORIZONTAL },
|
||||
{ApiOrientation::AUTO_ROTATION, Orientation::SENSOR },
|
||||
{ApiOrientation::AUTO_ROTATION_PORTRAIT, Orientation::SENSOR_VERTICAL },
|
||||
{ApiOrientation::AUTO_ROTATION_LANDSCAPE, Orientation::SENSOR_HORIZONTAL },
|
||||
{ApiOrientation::AUTO_ROTATION_RESTRICTED, Orientation::AUTO_ROTATION_RESTRICTED },
|
||||
{ApiOrientation::AUTO_ROTATION_PORTRAIT_RESTRICTED, Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED },
|
||||
{ApiOrientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED, Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED },
|
||||
{ApiOrientation::LOCKED, Orientation::LOCKED },
|
||||
};
|
||||
|
||||
NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect& rect);
|
||||
NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr<Window>& window);
|
||||
bool SetSystemBarPropertiesFromJs(NativeEngine& engine, NativeObject* jsObject,
|
||||
std::map<WindowType, SystemBarProperty>& properties, sptr<Window>& window);
|
||||
@@ -123,15 +156,17 @@ const std::map<ApiWindowMode, WindowMode> JS_TO_NATIVE_WINDOW_MODE_MAP {
|
||||
NativeEngine& engine, NativeCallbackInfo& info, sptr<Window>& window);
|
||||
NativeValue* CreateJsSystemBarRegionTintArrayObject(NativeEngine& engine,
|
||||
const SystemBarRegionTints& tints);
|
||||
NativeValue* ChangeAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avoidArea);
|
||||
NativeValue* ConvertAvoidAreaToJsValue(NativeEngine& engine, const AvoidArea& avoidArea, AvoidAreaType type);
|
||||
bool CheckCallingPermission(std::string permission);
|
||||
NativeValue* WindowTypeInit(NativeEngine* engine);
|
||||
NativeValue* AvoidAreaTypeInit(NativeEngine* engine);
|
||||
NativeValue* WindowModeInit(NativeEngine* engine);
|
||||
NativeValue* ColorSpaceInit(NativeEngine* engine);
|
||||
NativeValue* OrientationInit(NativeEngine* engine);
|
||||
NativeValue* WindowStageEventTypeInit(NativeEngine* engine);
|
||||
NativeValue* WindowLayoutModeInit(NativeEngine* engine);
|
||||
bool GetAPI7Ability(NativeEngine& engine, AppExecFwk::Ability* &ability);
|
||||
bool ParseJsDoubleValue(NativeObject* jsObject, NativeEngine& engine, const std::string& name, double& data);
|
||||
template<class T>
|
||||
inline bool ConvertNativeValueToVector(NativeEngine& engine, NativeValue* nativeValue, std::vector<T>& out)
|
||||
{
|
||||
|
||||
@@ -16,4 +16,6 @@
|
||||
<Configs>
|
||||
<!--Window display dpi, valid range is 80~640, use 0 if no configuration is requeired-->
|
||||
<dpi>0</dpi>
|
||||
<!--Cutout area Rect. This is temporary config. To delete when Rs cutout area interface is ready.-->
|
||||
<cutoutArea>10 10 100 20</cutoutArea>
|
||||
</Configs>
|
||||
@@ -19,4 +19,6 @@
|
||||
<!-- Indicate the deviation between the default device display direction and the direction -->
|
||||
<!-- of the sensor. Use 0 in default, available values are {0, 90, 180, 270} -->
|
||||
<defaultDeviceRotationOffset>0</defaultDeviceRotationOffset>
|
||||
<!--Cutout area Rect. This is temporary config. To delete when Rs cutout area interface is ready.-->
|
||||
<cutoutArea>10 10 100 20</cutoutArea>
|
||||
</Configs>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
<!--stretchable enable is true means all window be stretchable-->
|
||||
<stretchable enable="false"></stretchable>
|
||||
<!--exit split screen mode ratio config-->
|
||||
<exitSplitRatios>0.1 0.9</exitSplitRatios>
|
||||
<exitSplitRatios>0.1 0.9</exitSplitRatios>
|
||||
<!--split screen ratios config-->
|
||||
<splitRatios>0.5 0.33 0.67</splitRatios>
|
||||
</Configs>
|
||||
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
-->
|
||||
|
||||
<div class="container" style="background-color: {{ backgroundColor }}"
|
||||
ontouchend="onTouchEnd" ontouchstart="onTouching">
|
||||
<button class="divider-button" onclick="onExchange" ondoubleclick="onExchangeDoubleClick"
|
||||
<div class="container" style="background-color: {{ backgroundColor }}">
|
||||
<button class="divider-button" ondoubleclick="onExchangeDoubleClick"
|
||||
click-effect="spring-small">
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -13,37 +13,11 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import router from '@ohos.router'
|
||||
import window from '@ohos.window';
|
||||
|
||||
export default {
|
||||
data: {
|
||||
backgroundColor:"black"
|
||||
},
|
||||
onInit() {
|
||||
callNativeHandler("EVENT_INIT", "");
|
||||
},
|
||||
onCancel() {
|
||||
callNativeHandler("EVENT_CANCEL", "");
|
||||
},
|
||||
onExit() {
|
||||
callNativeHandler("EVENT_CANCEL", "");
|
||||
},
|
||||
onExchange() {
|
||||
},
|
||||
onExchangeDoubleClick() {
|
||||
console.info('double click exchange');
|
||||
},
|
||||
onFocus(){
|
||||
this.backgroundColor = "black"
|
||||
},
|
||||
recoveryColor(){
|
||||
this.backgroundColor = "gray"
|
||||
},
|
||||
onTouching(){
|
||||
this.backgroundColor = "gray"
|
||||
},
|
||||
onTouchEnd(){
|
||||
this.backgroundColor = "black"
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,16 @@ ohos_prebuilt_etc("window_divider_image") {
|
||||
relative_install_dir = "window/resources"
|
||||
}
|
||||
|
||||
group("window_resources_media") {
|
||||
deps = [ ":window_divider_image" ]
|
||||
ohos_prebuilt_etc("window_place_holder_image") {
|
||||
source = "//foundation/windowmanager/resources/media/img/bg_place_holder.png"
|
||||
part_name = "window_manager"
|
||||
subsystem_name = "window"
|
||||
relative_install_dir = "window/resources"
|
||||
}
|
||||
|
||||
group("window_resources_media") {
|
||||
deps = [
|
||||
":window_divider_image",
|
||||
":window_place_holder_image",
|
||||
]
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.4 KiB |
@@ -35,6 +35,7 @@ ohos_executable("snapshot_display") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hitrace_native:hitrace_meter",
|
||||
"multimedia_image_standard:image_native",
|
||||
"utils_base:utils",
|
||||
]
|
||||
@@ -61,6 +62,7 @@ ohos_executable("snapshot_virtual_screen") {
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hitrace_native:hitrace_meter",
|
||||
"multimedia_image_standard:image_native",
|
||||
"utils_base:utils",
|
||||
]
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
#include "snapshot_utils.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <hitrace_meter.h>
|
||||
#include <sys/time.h>
|
||||
#include <getopt.h>
|
||||
#include <securec.h>
|
||||
#include <png.h>
|
||||
#include "wm_trace.h"
|
||||
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::Rosen;
|
||||
@@ -142,7 +142,7 @@ bool SnapShotUtils::WriteToPng(const std::string &fileName, const WriteToPngPara
|
||||
return false;
|
||||
}
|
||||
|
||||
WM_SCOPED_TRACE("snapshot:WriteToPng(%s)", fileName.c_str());
|
||||
HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "snapshot:WriteToPng(%s)", fileName.c_str());
|
||||
|
||||
png_structp pngStruct = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
|
||||
if (pngStruct == nullptr) {
|
||||
|
||||
+3
-9
@@ -12,7 +12,6 @@
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/graphic/graphic_2d/graphic_config.gni")
|
||||
config("libwmutil_private_config") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
@@ -20,10 +19,6 @@ config("libwmutil_private_config") {
|
||||
"../interfaces/innerkits/dm",
|
||||
"../interfaces/innerkits/wm",
|
||||
]
|
||||
defines = []
|
||||
|
||||
# Get gpu defines
|
||||
defines += gpu_defines
|
||||
}
|
||||
|
||||
config("libwmutil_public_config") {
|
||||
@@ -44,7 +39,7 @@ ohos_shared_library("libwmutil") {
|
||||
"src/surface_reader_handler_impl.cpp",
|
||||
"src/window_property.cpp",
|
||||
"src/window_transition_info.cpp",
|
||||
"src/wm_trace.cpp",
|
||||
"src/wm_math.cpp",
|
||||
]
|
||||
|
||||
configs = [ ":libwmutil_private_config" ]
|
||||
@@ -52,17 +47,16 @@ ohos_shared_library("libwmutil") {
|
||||
public_configs = [ ":libwmutil_public_config" ]
|
||||
|
||||
deps = [
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||
"//third_party/flutter/build/skia:ace_skia_ohos",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_runtime:ability_manager",
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"graphic_standard:surface",
|
||||
"graphic_graphic_2d:surface",
|
||||
"hilog_native:libhilog",
|
||||
"hitrace_native:hitrace_meter",
|
||||
"ipc:ipc_core",
|
||||
"multimedia_image_standard:image_native",
|
||||
"safwk:system_ability_fwk",
|
||||
|
||||
@@ -68,6 +68,10 @@ public:
|
||||
DEFINE_VAR_DEFAULT(type, memberName, defaultValue) \
|
||||
DEFINE_FUNC_GET(type, funcName, memberName)
|
||||
|
||||
#define DEFINE_VAR_DEFAULT_FUNC_SET(type, funcName, memberName, defaultValue) \
|
||||
DEFINE_VAR_DEFAULT(type, memberName, defaultValue) \
|
||||
DEFINE_FUNC_SET(type, funcName, memberName)
|
||||
|
||||
#define DEFINE_VAR_FUNC_GET_SET(type, funcName, memberName) \
|
||||
DEFINE_VAR(type, memberName) \
|
||||
DEFINE_FUNC_GET(type, funcName, memberName) \
|
||||
|
||||
@@ -34,7 +34,8 @@ enum class DisplayStateChangeType : uint32_t {
|
||||
class IDisplayChangeListener : public RefBase {
|
||||
public:
|
||||
virtual void OnDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> info,
|
||||
const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type)= 0;
|
||||
const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type) = 0;
|
||||
virtual void OnGetWindowPreferredOrientation(DisplayId displayId, Orientation &orientation) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,12 @@
|
||||
|
||||
#include <ui/rs_surface_node.h>
|
||||
#include "pixel_map.h"
|
||||
#ifdef ACE_ENABLE_GL
|
||||
#include "render_context/render_context.h"
|
||||
#endif
|
||||
|
||||
#include "refbase.h"
|
||||
#include "wm_common.h"
|
||||
#include "draw/canvas.h"
|
||||
#include "nocopyable.h"
|
||||
#include "pixel_map.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
@@ -30,21 +31,26 @@ class SurfaceDraw {
|
||||
public:
|
||||
SurfaceDraw() = default;
|
||||
~SurfaceDraw() = default;
|
||||
void Init();
|
||||
void DrawBackgroundColor(std::shared_ptr<RSSurfaceNode> surfaceNode, Rect winRect, uint32_t bkgColor);
|
||||
void DrawBitmap(std::shared_ptr<RSSurfaceNode> surfaceNode, Rect winRect,
|
||||
SkBitmap& bitmap, uint32_t bkgColor);
|
||||
bool DecodeImageFile(const char* filename, SkBitmap& bitmap);
|
||||
void DrawSkImage(std::shared_ptr<RSSurfaceNode> surfaceNode, Rect winRect,
|
||||
sptr<Media::PixelMap> pixelMap, uint32_t bkgColor);
|
||||
static bool DrawColor(std::shared_ptr<RSSurfaceNode> surfaceNode, int32_t bufferWidth,
|
||||
int32_t bufferHeight, uint32_t color);
|
||||
static bool DrawImage(std::shared_ptr<RSSurfaceNode> surfaceNode, int32_t bufferWidth,
|
||||
int32_t bufferHeight, const std::string& imagePath);
|
||||
static bool DrawImage(std::shared_ptr<RSSurfaceNode> surfaceNode, int32_t bufferWidth,
|
||||
int32_t bufferHeight, std::shared_ptr<Media::PixelMap> pixelMap);
|
||||
static bool DrawImageRect(std::shared_ptr<RSSurfaceNode> surfaceNode, Rect winRect, sptr<Media::PixelMap> pixelMap,
|
||||
uint32_t bkgColor);
|
||||
|
||||
private:
|
||||
|
||||
std::shared_ptr<RSSurface> PrepareDraw(std::shared_ptr<RSSurfaceNode> surfaceNode,
|
||||
std::unique_ptr<RSSurfaceFrame>& frame, SkCanvas*& canvas, uint32_t width, uint32_t height);
|
||||
|
||||
#ifdef ACE_ENABLE_GL
|
||||
std::unique_ptr<RenderContext> rc_ = nullptr;
|
||||
#endif
|
||||
static bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const std::string& imagePath);
|
||||
static bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, uint32_t color);
|
||||
static bool DoDraw(uint8_t *addr, uint32_t width, uint32_t height, std::shared_ptr<Media::PixelMap> pixelMap);
|
||||
static sptr<OHOS::Surface> GetLayer(std::shared_ptr<RSSurfaceNode> surfaceNode);
|
||||
static sptr<OHOS::SurfaceBuffer> GetSurfaceBuffer(sptr<OHOS::Surface> layer, int32_t bufferWidth,
|
||||
int32_t bufferHeight);
|
||||
static void DrawPixelmap(Drawing::Canvas &canvas, const std::string& imagePath);
|
||||
static std::unique_ptr<OHOS::Media::PixelMap> DecodeImageToPixelMap(const std::string &imagePath);
|
||||
static bool DoDrawImageRect(uint8_t *addr, int32_t winWidth, int32_t winHeight, sptr<Media::PixelMap> pixelMap,
|
||||
uint32_t color);
|
||||
};
|
||||
} // Rosen
|
||||
} // OHOS
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
virtual ~SurfaceReaderHandler() noexcept
|
||||
{
|
||||
}
|
||||
virtual bool OnImageAvalible(sptr<Media::PixelMap> pixleMap) = 0;
|
||||
virtual bool OnImageAvailable(sptr<Media::PixelMap> pixelMap) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,14 +23,14 @@ namespace OHOS {
|
||||
namespace Rosen {
|
||||
class SurfaceReaderHandlerImpl : public SurfaceReaderHandler {
|
||||
public:
|
||||
bool OnImageAvalible(sptr<Media::PixelMap> pixleMap) override;
|
||||
bool OnImageAvailable(sptr<Media::PixelMap> pixelMap) override;
|
||||
bool IsImageOk();
|
||||
void ResetFlag();
|
||||
sptr<Media::PixelMap> GetPixelMap();
|
||||
|
||||
private:
|
||||
bool flag_ = false;
|
||||
sptr<Media::PixelMap> pixleMap_ = nullptr;
|
||||
sptr<Media::PixelMap> pixelMap_ = nullptr;
|
||||
std::recursive_mutex mutex_;
|
||||
};
|
||||
}
|
||||
|
||||
+167
-12
@@ -17,8 +17,10 @@
|
||||
#define OHOS_WM_INCLUDE_WM_HELPER_H
|
||||
|
||||
#include <vector>
|
||||
#include <wm_common.h>
|
||||
#include <wm_common_inner.h>
|
||||
#include "ability_info.h"
|
||||
#include "wm_common.h"
|
||||
#include "wm_common_inner.h"
|
||||
#include "wm_math.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
@@ -39,6 +41,11 @@ public:
|
||||
return (IsMainWindow(type) || IsSubWindow(type));
|
||||
}
|
||||
|
||||
static inline bool IsAppFloatingWindow(WindowType type)
|
||||
{
|
||||
return (type == WindowType::WINDOW_TYPE_FLOAT) || (type == WindowType::WINDOW_TYPE_FLOAT_CAMERA);
|
||||
}
|
||||
|
||||
static inline bool IsBelowSystemWindow(WindowType type)
|
||||
{
|
||||
return (type >= WindowType::BELOW_APP_SYSTEM_WINDOW_BASE && type < WindowType::BELOW_APP_SYSTEM_WINDOW_END);
|
||||
@@ -69,16 +76,23 @@ public:
|
||||
return ((IsMainWindow(type)) && (mode != WindowMode::WINDOW_MODE_FLOATING));
|
||||
}
|
||||
|
||||
static inline bool IsFloatintWindow(WindowMode mode)
|
||||
static inline bool IsFloatingWindow(WindowMode mode)
|
||||
{
|
||||
return mode == WindowMode::WINDOW_MODE_FLOATING;
|
||||
}
|
||||
|
||||
static inline bool IsAvoidAreaWindow(WindowType type)
|
||||
static inline bool IsSystemBarWindow(WindowType type)
|
||||
{
|
||||
return (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR);
|
||||
}
|
||||
|
||||
static inline bool IsOverlayWindow(WindowType type)
|
||||
{
|
||||
return (type == WindowType::WINDOW_TYPE_STATUS_BAR
|
||||
|| type == WindowType::WINDOW_TYPE_NAVIGATION_BAR
|
||||
|| type == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
|
||||
}
|
||||
|
||||
static inline bool IsFullScreenWindow(WindowMode mode)
|
||||
{
|
||||
return mode == WindowMode::WINDOW_MODE_FULLSCREEN;
|
||||
@@ -115,17 +129,19 @@ public:
|
||||
return !(r1XEnd < r2.posX_ || r1.posX_ > r2XEnd || r1YEnd < r2.posY_ || r1.posY_ > r2YEnd);
|
||||
}
|
||||
|
||||
static inline Rect GetOverlap(const Rect& rect1, const Rect& rect2, const int offsetX, const int offsetY)
|
||||
static Rect GetOverlap(const Rect& rect1, const Rect& rect2, const int offsetX, const int offsetY)
|
||||
{
|
||||
const static Rect noOverlapRect = { 0, 0, 0, 0};
|
||||
int32_t x_begin = std::max(rect1.posX_, rect2.posX_);
|
||||
int32_t x_end = std::min(rect1.posX_ + rect1.width_, rect2.posX_ + rect2.width_);
|
||||
int32_t x_end = std::min(rect1.posX_ + static_cast<int32_t>(rect1.width_),
|
||||
rect2.posX_ + static_cast<int32_t>(rect2.width_));
|
||||
int32_t y_begin = std::max(rect1.posY_, rect2.posY_);
|
||||
int32_t y_end = std::min(rect1.posY_ + rect1.height_, rect2.posY_ + rect2.height_);
|
||||
if (y_begin > y_end || x_begin > x_end) {
|
||||
return noOverlapRect;
|
||||
int32_t y_end = std::min(rect1.posY_ + static_cast<int32_t>(rect1.height_),
|
||||
rect2.posY_ + static_cast<int32_t>(rect2.height_));
|
||||
if (y_begin >= y_end || x_begin >= x_end) {
|
||||
return { 0, 0, 0, 0 };
|
||||
}
|
||||
return { x_begin - offsetX, y_begin - offsetY, x_end - x_begin + 1, y_end - y_begin + 1 };
|
||||
return { x_begin - offsetX, y_begin - offsetY,
|
||||
static_cast<uint32_t>(x_end - x_begin), static_cast<uint32_t>(y_end - y_begin) };
|
||||
}
|
||||
|
||||
static bool IsWindowModeSupported(uint32_t modeSupportInfo, WindowMode mode)
|
||||
@@ -167,6 +183,21 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static void ConvertSupportModesToSupportInfo(uint32_t& modeSupportInfo,
|
||||
const std::vector<AppExecFwk::SupportWindowMode>& supportModes)
|
||||
{
|
||||
for (auto& mode : supportModes) {
|
||||
if (mode == AppExecFwk::SupportWindowMode::FULLSCREEN) {
|
||||
modeSupportInfo |= WindowModeSupport::WINDOW_MODE_SUPPORT_FULLSCREEN;
|
||||
} else if (mode == AppExecFwk::SupportWindowMode::SPLIT) {
|
||||
modeSupportInfo |= (WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY |
|
||||
WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY);
|
||||
} else if (mode == AppExecFwk::SupportWindowMode::FLOATING) {
|
||||
modeSupportInfo |= WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Rect GetFixedWindowRectByLimitSize(const Rect& oriDstRect, const Rect& lastRect, bool isVertical,
|
||||
float virtualPixelRatio)
|
||||
{
|
||||
@@ -295,9 +326,99 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Transform a point at screen to its oringin position in 3D world and project to xy plane
|
||||
// A screen point only has x and y component, so we need a plane to calculate its z component.
|
||||
// | -- -- -- 0 |
|
||||
// | -- -- -- 0 |
|
||||
// There is no need to unify w component since the matrix is like | -- -- -- 0 |
|
||||
// | -- -- -- 1 |
|
||||
static PointInfo CalculateOriginPosition(const TransformHelper::Matrix4& transformMat,
|
||||
const TransformHelper::Plane& plane, const PointInfo& pointPos)
|
||||
{
|
||||
TransformHelper::Matrix4 invertMat = transformMat;
|
||||
invertMat.Invert();
|
||||
TransformHelper::Vector3 pointAtPlane;
|
||||
pointAtPlane.x_ = static_cast<float>(pointPos.x);
|
||||
pointAtPlane.y_ = static_cast<float>(pointPos.y);
|
||||
pointAtPlane.z_ = plane.ComponentZ(pointAtPlane.x_, pointAtPlane.y_);
|
||||
TransformHelper::Vector3 originPos = TransformHelper::Transform(pointAtPlane, invertMat);
|
||||
return PointInfo { static_cast<uint32_t>(originPos.x_), static_cast<uint32_t>(originPos.y_) };
|
||||
}
|
||||
|
||||
static TransformHelper::Matrix4 ComputeRectTransformMat4(const Transform& transform, const Rect& rect)
|
||||
{
|
||||
TransformHelper::Vector3 pivotPos = {
|
||||
rect.posX_ + transform.pivotX_ * rect.width_, rect.posY_ + transform.pivotY_ * rect.height_, 0 };
|
||||
// move pivot point to (0,0,0)
|
||||
TransformHelper::Matrix4 ret = TransformHelper::CreateTranslation(-pivotPos);
|
||||
// set scale
|
||||
if ((transform.scaleX_ - 1) || (transform.scaleY_ - 1)) {
|
||||
ret *= TransformHelper::CreateScale(transform.scaleX_, transform.scaleY_, 1.0f);
|
||||
}
|
||||
// set rotation
|
||||
if (transform.rotationX_) {
|
||||
ret *= TransformHelper::CreateRotationX(MathHelper::ToRadians(transform.rotationX_));
|
||||
}
|
||||
if (transform.rotationY_) {
|
||||
ret *= TransformHelper::CreateRotationY(MathHelper::ToRadians(transform.rotationY_));
|
||||
}
|
||||
if (transform.rotationZ_) {
|
||||
ret *= TransformHelper::CreateRotationZ(MathHelper::ToRadians(transform.rotationZ_));
|
||||
}
|
||||
// set translation
|
||||
if (transform.translateX_ || transform.translateY_ || transform.translateZ_) {
|
||||
ret *= TransformHelper::CreateTranslation(TransformHelper::Vector3(transform.translateX_,
|
||||
transform.translateY_, transform.translateZ_));
|
||||
}
|
||||
// move pivot point to old position
|
||||
ret *= TransformHelper::CreateTranslation(pivotPos);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Transform rect by matrix and get the circumscribed rect
|
||||
static Rect TransformRect(const TransformHelper::Matrix4& transformMat, const Rect& rect)
|
||||
{
|
||||
TransformHelper::Vector3 a = TransformHelper::Transform(
|
||||
TransformHelper::Vector3(rect.posX_, rect.posY_, 0), transformMat);
|
||||
TransformHelper::Vector3 b = TransformHelper::Transform(
|
||||
TransformHelper::Vector3(rect.posX_ + rect.width_, rect.posY_, 0), transformMat);
|
||||
TransformHelper::Vector3 c = TransformHelper::Transform(
|
||||
TransformHelper::Vector3(rect.posX_, rect.posY_ + rect.height_, 0), transformMat);
|
||||
TransformHelper::Vector3 d = b + c - a;
|
||||
// Return smallest rect involve transformed rect(abcd)
|
||||
int32_t xmin = MathHelper::Min(a.x_, b.x_, c.x_, d.x_);
|
||||
int32_t ymin = MathHelper::Min(a.y_, b.y_, c.y_, d.y_);
|
||||
int32_t xmax = MathHelper::Max(a.x_, b.x_, c.x_, d.x_);
|
||||
int32_t ymax = MathHelper::Max(a.y_, b.y_, c.y_, d.y_);
|
||||
uint32_t w = xmax - xmin;
|
||||
uint32_t h = ymax - ymin;
|
||||
return Rect { xmin, ymin, w, h };
|
||||
}
|
||||
|
||||
static TransformHelper::Vector2 CalculateHotZoneScale(const TransformHelper::Matrix4& transformMat,
|
||||
const TransformHelper::Plane& plane)
|
||||
{
|
||||
TransformHelper::Vector2 hotZoneScale;
|
||||
TransformHelper::Vector3 a = TransformHelper::Transform(TransformHelper::Vector3(0, 0, 0),
|
||||
transformMat);
|
||||
TransformHelper::Vector3 b = TransformHelper::Transform(TransformHelper::Vector3(1, 0, 0),
|
||||
transformMat);
|
||||
TransformHelper::Vector3 c = TransformHelper::Transform(TransformHelper::Vector3(0, 1, 0),
|
||||
transformMat);
|
||||
TransformHelper::Vector3 scale = transformMat.GetScale();
|
||||
hotZoneScale.x_ = scale.x_ * plane.ParallelDistanceGrad(a, c);
|
||||
hotZoneScale.y_ = scale.y_ * plane.ParallelDistanceGrad(a, b);
|
||||
if (std::isnan(hotZoneScale.x_) || std::isnan(hotZoneScale.y_)) {
|
||||
return TransformHelper::Vector2(1, 1);
|
||||
} else {
|
||||
return hotZoneScale;
|
||||
}
|
||||
}
|
||||
|
||||
static bool CalculateTouchHotAreas(const Rect& windowRect, const std::vector<Rect>& requestRects,
|
||||
std::vector<Rect>& outRects)
|
||||
{
|
||||
bool isOk = true;
|
||||
for (const auto& rect : requestRects) {
|
||||
if (rect.posX_ < 0 || rect.posY_ < 0 || rect.width_ == 0 || rect.height_ == 0) {
|
||||
return false;
|
||||
@@ -305,6 +426,7 @@ public:
|
||||
Rect hotArea;
|
||||
if (rect.posX_ >= static_cast<int32_t>(windowRect.width_) ||
|
||||
rect.posY_ >= static_cast<int32_t>(windowRect.height_)) {
|
||||
isOk = false;
|
||||
continue;
|
||||
}
|
||||
hotArea.posX_ = windowRect.posX_ + rect.posX_;
|
||||
@@ -315,7 +437,40 @@ public:
|
||||
std::min(hotArea.posY_ + rect.height_, windowRect.posY_ + windowRect.height_) - hotArea.posY_;
|
||||
outRects.emplace_back(hotArea);
|
||||
}
|
||||
return true;
|
||||
return isOk;
|
||||
}
|
||||
|
||||
static bool IsRectSatisfiedWithSizeLimits(const Rect& rect, const WindowSizeLimits& sizeLimits)
|
||||
{
|
||||
if (rect.height_ == 0) {
|
||||
return false;
|
||||
}
|
||||
auto curRatio = static_cast<float>(rect.width_) / static_cast<float>(rect.height_);
|
||||
if (sizeLimits.minWidth_ <= rect.width_ && rect.width_ <= sizeLimits.maxWidth_ &&
|
||||
sizeLimits.minHeight_ <= rect.height_ && rect.height_ <= sizeLimits.maxHeight_ &&
|
||||
sizeLimits.minRatio_ <= curRatio && curRatio <= sizeLimits.maxRatio_) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool IsOnlySupportSplitAndShowWhenLocked(bool isShowWhenLocked, uint32_t modeSupportInfo)
|
||||
{
|
||||
uint32_t splitModeInfo = (WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY |
|
||||
WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY);
|
||||
if (isShowWhenLocked && (splitModeInfo == modeSupportInfo)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool IsInvalidWindowInTileLayoutMode(uint32_t supportModeInfo, WindowLayoutMode layoutMode)
|
||||
{
|
||||
if ((!IsWindowModeSupported(supportModeInfo, WindowMode::WINDOW_MODE_FLOATING)) &&
|
||||
(layoutMode == WindowLayoutMode::TILE)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
#include <refbase.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include "parcel.h"
|
||||
|
||||
#include <parcel.h>
|
||||
#include "class_var_definition.h"
|
||||
#include "dm_common.h"
|
||||
#include "wm_common.h"
|
||||
#include "wm_common_inner.h"
|
||||
#include "wm_math.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
@@ -68,11 +68,16 @@ public:
|
||||
void SetWindowSizeChangeReason(WindowSizeChangeReason reason);
|
||||
void SetTokenState(bool hasToken);
|
||||
void SetModeSupportInfo(uint32_t modeSupportInfo);
|
||||
void SetRequestModeSupportInfo(uint32_t requestModeSupportInfo);
|
||||
void SetDragType(DragType dragType);
|
||||
void SetStretchable(bool stretchable);
|
||||
void SetOriginRect(const Rect& rect);
|
||||
void SetTouchHotAreas(const std::vector<Rect>& rects);
|
||||
void SetAccessTokenId(uint32_t accessTokenId);
|
||||
void SetSizeLimits(const WindowSizeLimits& sizeLimits);
|
||||
WindowSizeChangeReason GetWindowSizeChangeReason() const;
|
||||
void SetTransform(const Transform& trans);
|
||||
void ComputeTransform();
|
||||
|
||||
const std::string& GetWindowName() const;
|
||||
Rect GetRequestRect() const;
|
||||
@@ -103,10 +108,15 @@ public:
|
||||
const PointInfo& GetHitOffset() const;
|
||||
uint32_t GetAnimationFlag() const;
|
||||
uint32_t GetModeSupportInfo() const;
|
||||
uint32_t GetRequestModeSupportInfo() const;
|
||||
DragType GetDragType() const;
|
||||
bool GetStretchable() const;
|
||||
const Rect& GetOriginRect() const;
|
||||
void GetTouchHotAreas(std::vector<Rect>& rects) const;
|
||||
uint32_t GetAccessTokenId() const;
|
||||
Transform GetTransform() const;
|
||||
WindowSizeLimits GetSizeLimits() const;
|
||||
const TransformHelper::Matrix4& GetTransformMat() const;
|
||||
|
||||
virtual bool Marshalling(Parcel& parcel) const override;
|
||||
static WindowProperty* Unmarshalling(Parcel& parcel);
|
||||
@@ -118,6 +128,10 @@ private:
|
||||
static void MapUnmarshalling(Parcel& parcel, WindowProperty* property);
|
||||
bool MarshallingTouchHotAreas(Parcel& parcel) const;
|
||||
static void UnmarshallingTouchHotAreas(Parcel& parcel, WindowProperty* property);
|
||||
bool MarshallingTransform(Parcel& parcel) const;
|
||||
static void UnmarshallingTransform(Parcel& parcel, WindowProperty* property);
|
||||
bool MarshallingWindowSizeLimits(Parcel& parcel) const;
|
||||
static void UnmarshallingWindowSizeLimits(Parcel& parcel, WindowProperty* property);
|
||||
|
||||
std::string windowName_;
|
||||
Rect requestRect_ { 0, 0, 0, 0 }; // window rect requested by the client (without decoration size)
|
||||
@@ -144,7 +158,10 @@ private:
|
||||
uint32_t parentId_ { 0 };
|
||||
PointInfo hitOffset_ { 0, 0 };
|
||||
uint32_t animationFlag_ { static_cast<uint32_t>(WindowAnimation::DEFAULT) };
|
||||
// modeSupportInfo_ means supported modes in runtime, which can be changed
|
||||
uint32_t modeSupportInfo_ {WindowModeSupport::WINDOW_MODE_SUPPORT_ALL};
|
||||
// requestModeSupportInfo_ is configured in abilityInfo, usually can't be changed
|
||||
uint32_t requestModeSupportInfo_ {WindowModeSupport::WINDOW_MODE_SUPPORT_ALL};
|
||||
WindowSizeChangeReason windowSizeChangeReason_ = WindowSizeChangeReason::UNDEFINED;
|
||||
std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ {
|
||||
{ WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() },
|
||||
@@ -155,7 +172,15 @@ private:
|
||||
bool isStretchable_ {false};
|
||||
DragType dragType_ = DragType::DRAG_UNDEFINED;
|
||||
std::vector<Rect> touchHotAreas_; // coordinates relative to window.
|
||||
uint32_t accessTokenId_ { 0 };
|
||||
// Transform info
|
||||
Transform trans_;
|
||||
bool recomputeTransformMat_ { false };
|
||||
TransformHelper::Matrix4 transformMat_ = TransformHelper::Matrix4::Identity;
|
||||
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(Orientation, RequestedOrientation, requestedOrientation, Orientation::UNSPECIFIED);
|
||||
DEFINE_VAR_FUNC_GET_SET(TransformHelper::Plane, Plane, windowPlane);
|
||||
WindowSizeLimits sizeLimits_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#define OHOS_ROSEN_WINDOW_TRANSITION_INFO_H
|
||||
#include <iremote_object.h>
|
||||
#include <string>
|
||||
|
||||
#include "ability_info.h"
|
||||
#include "window_info.h"
|
||||
#include "wm_common.h"
|
||||
|
||||
@@ -52,6 +54,8 @@ public:
|
||||
void SetWindowType(WindowType windowType);
|
||||
WindowType GetWindowType();
|
||||
void SetShowFlagWhenLocked(bool isShow);
|
||||
void SetWindowSupportModes(const std::vector<AppExecFwk::SupportWindowMode> supportModes);
|
||||
std::vector<AppExecFwk::SupportWindowMode> GetWindowSupportModes();
|
||||
bool GetShowFlagWhenLocked();
|
||||
void SetTransitionReason(TransitionReason reason);
|
||||
TransitionReason GetTransitionReason();
|
||||
@@ -68,6 +72,7 @@ private:
|
||||
bool isShowWhenLocked_ = false;
|
||||
bool isRecent_ = false;
|
||||
TransitionReason reason_ = TransitionReason::ABILITY_TRANSITION;
|
||||
std::vector<AppExecFwk::SupportWindowMode> supportWindowModes_;
|
||||
};
|
||||
} // Rosen
|
||||
} // OHOS
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#ifndef OHOS_ROSEN_WM_COMMON_INNER_H
|
||||
#define OHOS_ROSEN_WM_COMMON_INNER_H
|
||||
|
||||
#include <cfloat>
|
||||
#include <cinttypes>
|
||||
#include "wm_common.h"
|
||||
|
||||
@@ -54,6 +55,7 @@ enum class WindowUpdateReason : uint32_t {
|
||||
UPDATE_TYPE,
|
||||
NEED_SWITCH_CASCADE_END,
|
||||
UPDATE_OTHER_PROPS,
|
||||
UPDATE_TRANSFORM,
|
||||
};
|
||||
|
||||
enum class AvoidPosType : uint32_t {
|
||||
@@ -84,6 +86,8 @@ enum class PropertyChangeAction : uint32_t {
|
||||
ACTION_UPDATE_SET_BRIGHTNESS = 1 << 10,
|
||||
ACTION_UPDATE_MODE_SUPPORT_INFO = 1 << 11,
|
||||
ACTION_UPDATE_TOUCH_HOT_AREA = 1 << 12,
|
||||
ACTION_UPDATE_TRANSFORM_PROPERTY = 1 << 13,
|
||||
ACTION_UPDATE_ANIMATION_FLAG = 1 << 14,
|
||||
};
|
||||
|
||||
struct ModeChangeHotZonesConfig {
|
||||
@@ -93,16 +97,20 @@ struct ModeChangeHotZonesConfig {
|
||||
uint32_t secondaryRange_;
|
||||
};
|
||||
|
||||
struct FloatingWindowLimitsConfig {
|
||||
bool isFloatingWindowLimitsConfigured_;
|
||||
struct WindowSizeLimits {
|
||||
bool isSizeLimitsUpdated_;
|
||||
uint32_t maxWidth_;
|
||||
uint32_t maxHeight_;
|
||||
uint32_t minWidth_;
|
||||
uint32_t minHeight_;
|
||||
float maxRatio_;
|
||||
float minRatio_;
|
||||
FloatingWindowLimitsConfig() : isFloatingWindowLimitsConfigured_(false), maxWidth_(0), maxHeight_(0), minWidth_(0),
|
||||
minHeight_(0), maxRatio_(0.0f), minRatio_(0.0f) {}
|
||||
WindowSizeLimits() : isSizeLimitsUpdated_(false), maxWidth_(UINT32_MAX), maxHeight_(UINT32_MAX),
|
||||
minWidth_(0), minHeight_(0), maxRatio_(FLT_MAX), minRatio_(0.0f) {}
|
||||
WindowSizeLimits(bool isSizeLimitsUpdated, uint32_t maxWidth, uint32_t maxHeight,
|
||||
uint32_t minWidth, uint32_t minHeight, float maxRatio, float minRatio)
|
||||
: isSizeLimitsUpdated_(isSizeLimitsUpdated), maxWidth_(maxWidth), maxHeight_(maxHeight),
|
||||
minWidth_(minWidth), minHeight_(minHeight), maxRatio_(maxRatio), minRatio_(minRatio) {}
|
||||
};
|
||||
|
||||
struct ModeChangeHotZones {
|
||||
@@ -135,6 +143,7 @@ enum class TraceTaskId : int32_t {
|
||||
namespace {
|
||||
constexpr float DEFAULT_SPLIT_RATIO = 0.5;
|
||||
constexpr float DEFAULT_ASPECT_RATIO = 0.66;
|
||||
constexpr int32_t IVALID_DIALOG_WINDOW_ID = -1;
|
||||
constexpr uint32_t DIVIDER_WIDTH = 8;
|
||||
constexpr uint32_t WINDOW_TITLE_BAR_HEIGHT = 37;
|
||||
constexpr uint32_t WINDOW_FRAME_WIDTH = 5;
|
||||
@@ -145,8 +154,8 @@ namespace {
|
||||
constexpr uint32_t MIN_VERTICAL_SPLIT_HEIGHT = 240;
|
||||
constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 320;
|
||||
constexpr uint32_t MAX_FLOATING_SIZE = 2560;
|
||||
const std::string WINDOW_MANAGER_CONFIG_XML = "/system/etc/window/resources/window_manager_config.xml";
|
||||
const Rect IVALID_EMPTY_RECT = {0, 0, 0, 0};
|
||||
const Rect INVALID_EMPTY_RECT = {0, 0, 0, 0};
|
||||
const Rect DEFAULT_PLACE_HOLDER_RECT = {0, 0, 512, 512};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_ROSEN_WM_MATH_H
|
||||
#define OHOS_ROSEN_WM_MATH_H
|
||||
|
||||
#include <limits>
|
||||
#include <cmath>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
namespace MathHelper {
|
||||
constexpr float PI = 3.14159265f;
|
||||
constexpr float INF = std::numeric_limits<float>::infinity();
|
||||
constexpr float NAG_INF = -std::numeric_limits<float>::infinity();
|
||||
constexpr float POS_ZERO = 0.001f;
|
||||
constexpr float NAG_ZERO = -POS_ZERO;
|
||||
inline bool NearZero(float val)
|
||||
{
|
||||
return val < POS_ZERO && val > NAG_ZERO;
|
||||
}
|
||||
|
||||
inline float ToRadians(float degrees)
|
||||
{
|
||||
return degrees * PI / 180.0f;
|
||||
}
|
||||
|
||||
inline float ToDegrees(float radians)
|
||||
{
|
||||
return radians * 180.0f / PI;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T Max(const T& a, const T& b)
|
||||
{
|
||||
return (a < b ? b : a);
|
||||
}
|
||||
|
||||
template <typename T, typename... Ts>
|
||||
T Max(const T& a, Ts... bs)
|
||||
{
|
||||
T b = Max(bs...);
|
||||
return (a > b ? a : b);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T Min(const T& a, const T& b)
|
||||
{
|
||||
return (a < b ? a : b);
|
||||
}
|
||||
|
||||
template <typename T, typename... Ts>
|
||||
T Min(const T& a, Ts... bs)
|
||||
{
|
||||
T b = Min(bs...);
|
||||
return (a < b ? a : b);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T Clamp(const T& value, const T& lower, const T& upper)
|
||||
{
|
||||
return Min(upper, Max(lower, value));
|
||||
}
|
||||
} // namespace MathHelper
|
||||
|
||||
namespace TransformHelper {
|
||||
struct Vector2 {
|
||||
float x_, y_;
|
||||
Vector2() : x_(0.0f), y_(0.0f) {}
|
||||
Vector2(float inX, float inY)
|
||||
: x_(inX), y_(inY) {}
|
||||
friend Vector2 operator-(const Vector2& v)
|
||||
{
|
||||
return Vector2 { -v.x_, -v.y_ };
|
||||
}
|
||||
friend Vector2 operator+(const Vector2& a, const Vector2& b)
|
||||
{
|
||||
return Vector2 { a.x_ + b.x_, a.y_ + b.y_ };
|
||||
}
|
||||
friend Vector2 operator-(const Vector2& a, const Vector2& b)
|
||||
{
|
||||
return Vector2 { a.x_ - b.x_, a.y_ - b.y_ };
|
||||
}
|
||||
float LengthSq() const
|
||||
{
|
||||
return (x_ * x_ + y_ * y_);
|
||||
}
|
||||
float Length() const
|
||||
{
|
||||
return (std::sqrt(LengthSq()));
|
||||
}
|
||||
};
|
||||
|
||||
struct Vector3 {
|
||||
float x_, y_, z_;
|
||||
Vector3() : x_(0.0f), y_(0.0f), z_(0.0f) {}
|
||||
Vector3(float inX, float inY, float inZ)
|
||||
: x_(inX), y_(inY), z_(inZ) {}
|
||||
friend Vector3 operator-(const Vector3& v)
|
||||
{
|
||||
return Vector3 { -v.x_, -v.y_, -v.z_ };
|
||||
}
|
||||
friend Vector3 operator+(const Vector3& a, const Vector3& b)
|
||||
{
|
||||
return Vector3 { a.x_ + b.x_, a.y_ + b.y_, a.z_ + b.z_ };
|
||||
}
|
||||
friend Vector3 operator-(const Vector3& a, const Vector3& b)
|
||||
{
|
||||
return Vector3 { a.x_ - b.x_, a.y_ - b.y_, a.z_ - b.z_ };
|
||||
}
|
||||
float LengthSq() const
|
||||
{
|
||||
return (x_ * x_ + y_ * y_ + z_ * z_);
|
||||
}
|
||||
float Length() const
|
||||
{
|
||||
return (std::sqrt(LengthSq()));
|
||||
}
|
||||
void Normalize()
|
||||
{
|
||||
float length = Length();
|
||||
if (length > MathHelper::POS_ZERO) {
|
||||
x_ /= length;
|
||||
y_ /= length;
|
||||
z_ /= length;
|
||||
}
|
||||
}
|
||||
static Vector3 Normalize(const Vector3& vec)
|
||||
{
|
||||
Vector3 temp = vec;
|
||||
temp.Normalize();
|
||||
return temp;
|
||||
}
|
||||
static float Dot(const Vector3& a, const Vector3& b)
|
||||
{
|
||||
return (a.x_ * b.x_ + a.y_ * b.y_ + a.z_ * b.z_);
|
||||
}
|
||||
static Vector3 Cross(const Vector3& a, const Vector3& b)
|
||||
{
|
||||
Vector3 temp;
|
||||
temp.x_ = a.y_ * b.z_ - a.z_ * b.y_;
|
||||
temp.y_ = a.z_ * b.x_ - a.x_ * b.z_;
|
||||
temp.z_ = a.x_ * b.y_ - a.y_ * b.x_;
|
||||
return temp;
|
||||
}
|
||||
};
|
||||
|
||||
struct Matrix3 {
|
||||
float mat_[3][3];
|
||||
|
||||
friend Matrix3 operator*(const Matrix3& left, const Matrix3& right);
|
||||
Matrix3& operator*=(const Matrix3& right);
|
||||
static const Matrix3 Identity;
|
||||
};
|
||||
|
||||
struct Matrix4 {
|
||||
float mat_[4][4];
|
||||
|
||||
friend Matrix4 operator*(const Matrix4& left, const Matrix4& right);
|
||||
Matrix4& operator*=(const Matrix4& right);
|
||||
void SwapRow(int row1, int row2);
|
||||
// Inverse matrix with Gauss-Jordan method
|
||||
void Invert();
|
||||
// Extract the scale component from the matrix
|
||||
Vector3 GetScale() const;
|
||||
static const Matrix4 Identity;
|
||||
static constexpr int MAT_SIZE = 4;
|
||||
};
|
||||
|
||||
struct Plane {
|
||||
Plane() : normal_ { 0, 0, 1 }, d_ { 0 } {}
|
||||
Plane(const Vector3& normal, float d);
|
||||
Plane(const Vector3& a, const Vector3& b, const Vector3& c);
|
||||
float ComponentZ(float x, float y) const;
|
||||
// Compute the distance of parallel lines projected from this plane to xy plane
|
||||
// it is assumed that distance of parallel lines in this plane is 1
|
||||
// a, b determine a line in this plane
|
||||
float ParallelDistanceGrad(const Vector3& a, const Vector3& b) const;
|
||||
|
||||
Vector3 normal_; // Normal vector of plane
|
||||
float d_; // Signed distance from (0,0,0) to plane
|
||||
};
|
||||
// Create a scale matrix with x and y scales(in xy-plane)
|
||||
Matrix3 CreateScale(float xScale, float yScale);
|
||||
// Create a rotation matrix about the Z axis
|
||||
// theta is in radians
|
||||
Matrix3 CreateRotation(float theta);
|
||||
// Create a translation matrix (on the xy-plane)
|
||||
Matrix3 CreateTranslation(const Vector2& trans);
|
||||
// Create a scale matrix with x, y, and z scales
|
||||
Matrix4 CreateScale(float xScale, float yScale, float zScale);
|
||||
// Create a rotation matrix about X axis
|
||||
// theta is in radians
|
||||
Matrix4 CreateRotationX(float theta);
|
||||
// Create a rotation matrix about Y axis
|
||||
// theta is in radians
|
||||
Matrix4 CreateRotationY(float theta);
|
||||
// Create a rotation matrix about Z axis
|
||||
// theta is in radians
|
||||
Matrix4 CreateRotationZ(float theta);
|
||||
// Create a 3D translation matrix
|
||||
Matrix4 CreateTranslation(const Vector3& trans);
|
||||
// Transform a Vector2 in xy-plane by matrix3
|
||||
Vector2 Transform(const Vector2& vec, const Matrix3& mat);
|
||||
// Transform a Vector3 in 3D world by matrix4
|
||||
Vector3 Transform(const Vector3& vec, const Matrix4& mat);
|
||||
} // namespace TransformHelper
|
||||
} // namespace OHOS
|
||||
} // namespace Rosen
|
||||
#endif // OHOS_ROSEN_WM_MATH_H
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_WM_INCLUDE_WM_TRACE_H
|
||||
#define OHOS_WM_INCLUDE_WM_TRACE_H
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "noncopyable.h"
|
||||
|
||||
#define WM_SCOPED_TRACE(fmt, ...) WmScopedTrace wmScopedTrace(fmt, ##__VA_ARGS__)
|
||||
#ifdef WM_DEBUG
|
||||
#define WM_DEBUG_SCOPED_TRACE(fmt, ...) WmScopedTrace wmScopedTrace(fmt, ##__VA_ARGS__)
|
||||
#else
|
||||
#define WM_DEBUG_SCOPED_TRACE(fmt, ...)
|
||||
#endif
|
||||
|
||||
#define WM_FUNCTION_TRACE() WM_SCOPED_TRACE(__func__)
|
||||
#define WM_SCOPED_TRACE_BEGIN(fmt, ...) WmTraceBeginWithArgs(fmt, ##__VA_ARGS__)
|
||||
#define WM_SCOPED_TRACE_END() WmTraceEnd()
|
||||
|
||||
#define WM_SCOPED_ASYNC_TRACE_BEGIN(taskId, fmt, ...) WmAsyncTraceWithArgs(true, taskId, fmt, ##__VA_ARGS__)
|
||||
#define WM_SCOPED_ASYNC_END(taskId, fmt, ...) WmAsyncTraceWithArgs(false, taskId, fmt, ##__VA_ARGS__)
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
bool WmTraceEnabled();
|
||||
void WmTraceBegin(const char* name);
|
||||
bool WmTraceBeginWithArgs(const char* format, ...) __attribute__((__format__(printf, 1, 2)));
|
||||
bool WmTraceBeginWithArgv(const char* format, va_list args);
|
||||
void WmTraceEnd();
|
||||
void WmAsyncTraceBegin(int32_t taskId, const char* name);
|
||||
void WmAsyncTraceEnd(int32_t taskId, const char* name);
|
||||
void WmAsyncTraceWithArgs(bool isBegin, int32_t taskId,
|
||||
const char* format, ...) __attribute__((__format__(printf, 3, 4)));
|
||||
void WmAsyncTraceWithArgv(bool isBegin, int32_t taskId, const char* format, va_list args);
|
||||
|
||||
class WmScopedTrace final {
|
||||
public:
|
||||
explicit WmScopedTrace(const char* format, ...) __attribute__((__format__(printf, 2, 3)));
|
||||
~WmScopedTrace();
|
||||
|
||||
WM_DISALLOW_COPY_AND_MOVE(WmScopedTrace);
|
||||
|
||||
private:
|
||||
bool traceEnabled_ { false };
|
||||
};
|
||||
} // namespace OHOS
|
||||
}
|
||||
#endif // OHOS_WM_INCLUDE_WM_TRACE_H
|
||||
+278
-176
@@ -19,220 +19,322 @@
|
||||
#include <surface.h>
|
||||
#include <ui/rs_surface_extractor.h>
|
||||
#include "window_manager_hilog.h"
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/codec/SkCodec.h"
|
||||
#include "include/core/SkData.h"
|
||||
#include "include/core/SkImage.h"
|
||||
#include "include/core/SkPixmap.h"
|
||||
|
||||
#include "image/bitmap.h"
|
||||
#include "image_source.h"
|
||||
#include "image_type.h"
|
||||
#include "image_utils.h"
|
||||
#include "pixel_map.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "SurfaceDraw"};
|
||||
} // namespace
|
||||
|
||||
void SurfaceDraw::Init()
|
||||
bool SurfaceDraw::DrawImage(std::shared_ptr<RSSurfaceNode> surfaceNode, int32_t bufferWidth,
|
||||
int32_t bufferHeight, const std::string& imagePath)
|
||||
{
|
||||
#ifdef ACE_ENABLE_GL
|
||||
WLOGFI("Draw divider on gpu");
|
||||
if (!rc_) {
|
||||
rc_ = std::make_unique<RenderContext>();
|
||||
rc_->InitializeEglContext();
|
||||
WLOGFI("Draw Init Success");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
std::shared_ptr<RSSurface> SurfaceDraw::PrepareDraw(std::shared_ptr<RSSurfaceNode> surfaceNode,
|
||||
std::unique_ptr<RSSurfaceFrame>& frame, SkCanvas*& canvas, uint32_t width, uint32_t height)
|
||||
{
|
||||
std::shared_ptr<RSSurface> rsSurface = RSSurfaceExtractor::ExtractRSSurface(surfaceNode);
|
||||
if (rsSurface == nullptr) {
|
||||
WLOGFE("RSSurface is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
#ifdef ACE_ENABLE_GL
|
||||
rsSurface->SetRenderContext(rc_.get());
|
||||
#endif
|
||||
frame = rsSurface->RequestFrame(width, height);
|
||||
if (frame == nullptr) {
|
||||
WLOGFE("DrawBackgroundColor frameptr is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
canvas = frame->GetCanvas();
|
||||
if (canvas == nullptr) {
|
||||
WLOGFE("DrawBackgroundColor canvas is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
return rsSurface;
|
||||
}
|
||||
|
||||
void SurfaceDraw::DrawBackgroundColor(std::shared_ptr<RSSurfaceNode> surfaceNode, Rect winRect, uint32_t bkgColor)
|
||||
{
|
||||
WLOGFI("DrawBackgroundColor winRect, [%{public}d, %{public}d, %{public}d, %{public}d], bkgColor:%{public}x",
|
||||
winRect.posX_, winRect.posY_, winRect.width_, winRect.height_, bkgColor);
|
||||
auto width = winRect.width_;
|
||||
auto height = winRect.height_;
|
||||
std::unique_ptr<RSSurfaceFrame> frame;
|
||||
SkCanvas* canvas;
|
||||
auto rsSurface = PrepareDraw(surfaceNode, frame, canvas, width, height);
|
||||
if (rsSurface == nullptr) {
|
||||
return;
|
||||
}
|
||||
SkPaint bkgPaint;
|
||||
bkgPaint.setColor(bkgColor);
|
||||
canvas->drawRect(SkRect::MakeXYWH(0.0, 0.0, width, height), bkgPaint);
|
||||
rsSurface->FlushFrame(frame);
|
||||
}
|
||||
|
||||
// just for test
|
||||
static bool g_isLoaded = false;
|
||||
|
||||
bool SurfaceDraw::DecodeImageFile(const char* filename, SkBitmap& bitmap)
|
||||
{
|
||||
if (g_isLoaded) {
|
||||
return true;
|
||||
}
|
||||
sk_sp<SkData> data(SkData::MakeFromFileName(filename));
|
||||
std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(std::move(data));
|
||||
if (codec == nullptr) {
|
||||
sptr<OHOS::Surface> layer = GetLayer(surfaceNode);
|
||||
if (layer == nullptr) {
|
||||
WLOGFE("layer is nullptr");
|
||||
return false;
|
||||
}
|
||||
SkColorType colorType = kN32_SkColorType;
|
||||
SkImageInfo info = codec->getInfo().makeColorType(colorType);
|
||||
if (!bitmap.tryAllocPixels(info)) {
|
||||
sptr<OHOS::SurfaceBuffer> buffer = GetSurfaceBuffer(layer, bufferWidth, bufferHeight);
|
||||
if (buffer == nullptr || buffer->GetVirAddr() == nullptr) {
|
||||
return false;
|
||||
}
|
||||
g_isLoaded = true;
|
||||
return SkCodec::kSuccess == codec->getPixels(info, bitmap.getPixels(), bitmap.rowBytes());
|
||||
auto addr = static_cast<uint8_t *>(buffer->GetVirAddr());
|
||||
if (!DoDraw(addr, buffer->GetWidth(), buffer->GetHeight(), imagePath)) {
|
||||
WLOGE("draw window pixel failed");
|
||||
return false;
|
||||
}
|
||||
OHOS::BufferFlushConfig flushConfig = {
|
||||
.damage = {
|
||||
.w = buffer->GetWidth(),
|
||||
.h = buffer->GetHeight(),
|
||||
},
|
||||
};
|
||||
OHOS::SurfaceError ret = layer->FlushBuffer(buffer, -1, flushConfig);
|
||||
if (ret != OHOS::SurfaceError::SURFACE_ERROR_OK) {
|
||||
WLOGFE("draw pointer FlushBuffer ret:%{public}s", SurfaceErrorStr(ret).c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SurfaceDraw::DrawBitmap(std::shared_ptr<RSSurfaceNode> surfaceNode, Rect winRect,
|
||||
SkBitmap& bitmap, uint32_t bkgColor)
|
||||
bool SurfaceDraw::DrawImage(std::shared_ptr<RSSurfaceNode> surfaceNode, int32_t bufferWidth,
|
||||
int32_t bufferHeight, std::shared_ptr<Media::PixelMap> pixelMap)
|
||||
{
|
||||
if (bitmap.isNull() || bitmap.width() == 0 || bitmap.height() == 0) {
|
||||
WLOGFE("bitmap is empty or width/height is 0");
|
||||
return;
|
||||
sptr<OHOS::Surface> layer = GetLayer(surfaceNode);
|
||||
if (layer == nullptr) {
|
||||
WLOGFE("layer is nullptr");
|
||||
return false;
|
||||
}
|
||||
WLOGFI("DrawBitmap winRect, x : %{public}d, y : %{public}d, width: %{public}d, height: %{public}d",
|
||||
winRect.posX_, winRect.posY_, winRect.width_, winRect.height_);
|
||||
auto width = static_cast<int32_t>(winRect.width_);
|
||||
auto height = static_cast<int32_t>(winRect.height_);
|
||||
std::unique_ptr<RSSurfaceFrame> frame;
|
||||
SkCanvas* canvas;
|
||||
auto rsSurface = PrepareDraw(surfaceNode, frame, canvas, width, height);
|
||||
if (rsSurface == nullptr) {
|
||||
return;
|
||||
sptr<OHOS::SurfaceBuffer> buffer = GetSurfaceBuffer(layer, bufferWidth, bufferHeight);
|
||||
if (buffer == nullptr || buffer->GetVirAddr() == nullptr) {
|
||||
return false;
|
||||
}
|
||||
SkPaint bkgPaint;
|
||||
bkgPaint.setColor(bkgColor);
|
||||
canvas->drawRect(SkRect::MakeXYWH(0.0, 0.0, width, height), bkgPaint);
|
||||
SkPaint paint;
|
||||
SkRect rect;
|
||||
int realHeight = std::min(height, bitmap.height()); // need to scale
|
||||
int realWidth = std::min(width, bitmap.width());
|
||||
int pointX = (width - realWidth) / 2;
|
||||
int pointY = (height - realHeight) / 2;
|
||||
rect.setXYWH(pointX, pointY, realWidth, realHeight);
|
||||
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bitmap);
|
||||
if (!image) {
|
||||
WLOGFE("image is nullptr");
|
||||
return;
|
||||
auto addr = static_cast<uint8_t *>(buffer->GetVirAddr());
|
||||
if (!DoDraw(addr, buffer->GetWidth(), buffer->GetHeight(), pixelMap)) {
|
||||
WLOGE("draw window pixel failed");
|
||||
return false;
|
||||
}
|
||||
canvas->drawImageRect(image.get(), rect, &paint);
|
||||
rsSurface->FlushFrame(frame);
|
||||
OHOS::BufferFlushConfig flushConfig = {
|
||||
.damage = {
|
||||
.w = buffer->GetWidth(),
|
||||
.h = buffer->GetHeight(),
|
||||
},
|
||||
};
|
||||
OHOS::SurfaceError ret = layer->FlushBuffer(buffer, -1, flushConfig);
|
||||
if (ret != OHOS::SurfaceError::SURFACE_ERROR_OK) {
|
||||
WLOGFE("draw pointer FlushBuffer ret:%{public}s", SurfaceErrorStr(ret).c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static SkAlphaType AlphaTypeToSkAlphaType(const sptr<Media::PixelMap>& pixmap)
|
||||
bool SurfaceDraw::DrawColor(std::shared_ptr<RSSurfaceNode> surfaceNode, int32_t bufferWidth,
|
||||
int32_t bufferHeight, uint32_t color)
|
||||
{
|
||||
switch (pixmap->GetAlphaType()) {
|
||||
case Media::AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN:
|
||||
return SkAlphaType::kUnknown_SkAlphaType;
|
||||
case Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE:
|
||||
return SkAlphaType::kOpaque_SkAlphaType;
|
||||
case Media::AlphaType::IMAGE_ALPHA_TYPE_PREMUL:
|
||||
return SkAlphaType::kPremul_SkAlphaType;
|
||||
case Media::AlphaType::IMAGE_ALPHA_TYPE_UNPREMUL:
|
||||
return SkAlphaType::kUnpremul_SkAlphaType;
|
||||
default:
|
||||
return SkAlphaType::kUnknown_SkAlphaType;
|
||||
sptr<OHOS::Surface> layer = GetLayer(surfaceNode);
|
||||
if (layer == nullptr) {
|
||||
WLOGFE("layer is nullptr");
|
||||
return false;
|
||||
}
|
||||
sptr<OHOS::SurfaceBuffer> buffer = GetSurfaceBuffer(layer, bufferWidth, bufferHeight);
|
||||
if (buffer == nullptr || buffer->GetVirAddr() == nullptr) {
|
||||
return false;
|
||||
}
|
||||
auto addr = static_cast<uint8_t *>(buffer->GetVirAddr());
|
||||
if (!DoDraw(addr, buffer->GetWidth(), buffer->GetHeight(), color)) {
|
||||
WLOGE("draw window color failed");
|
||||
return false;
|
||||
}
|
||||
OHOS::BufferFlushConfig flushConfig = {
|
||||
.damage = {
|
||||
.w = buffer->GetWidth(),
|
||||
.h = buffer->GetHeight(),
|
||||
},
|
||||
};
|
||||
OHOS::SurfaceError ret = layer->FlushBuffer(buffer, -1, flushConfig);
|
||||
if (ret != OHOS::SurfaceError::SURFACE_ERROR_OK) {
|
||||
WLOGFE("draw pointer FlushBuffer ret:%{public}s", SurfaceErrorStr(ret).c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static SkColorType PixelFormatToSkColorType(const sptr<Media::PixelMap>& pixmap)
|
||||
sptr<OHOS::Surface> SurfaceDraw::GetLayer(std::shared_ptr<RSSurfaceNode> surfaceNode)
|
||||
{
|
||||
switch (pixmap->GetPixelFormat()) {
|
||||
case Media::PixelFormat::RGB_565:
|
||||
return SkColorType::kRGB_565_SkColorType;
|
||||
case Media::PixelFormat::RGBA_8888:
|
||||
return SkColorType::kRGBA_8888_SkColorType;
|
||||
case Media::PixelFormat::BGRA_8888:
|
||||
return SkColorType::kBGRA_8888_SkColorType;
|
||||
case Media::PixelFormat::ALPHA_8:
|
||||
return SkColorType::kAlpha_8_SkColorType;
|
||||
case Media::PixelFormat::RGBA_F16:
|
||||
return SkColorType::kRGBA_F16_SkColorType;
|
||||
case Media::PixelFormat::UNKNOWN:
|
||||
case Media::PixelFormat::ARGB_8888:
|
||||
case Media::PixelFormat::RGB_888:
|
||||
case Media::PixelFormat::NV21:
|
||||
case Media::PixelFormat::NV12:
|
||||
case Media::PixelFormat::CMYK:
|
||||
default:
|
||||
return SkColorType::kUnknown_SkColorType;
|
||||
if (surfaceNode == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return surfaceNode->GetSurface();
|
||||
}
|
||||
|
||||
static SkImageInfo MakeSkImageInfoFromPixelMap(sptr<Media::PixelMap>& pixmap)
|
||||
sptr<OHOS::SurfaceBuffer> SurfaceDraw::GetSurfaceBuffer(sptr<OHOS::Surface> layer,
|
||||
int32_t bufferWidth, int32_t bufferHeight)
|
||||
{
|
||||
SkColorType colorType = PixelFormatToSkColorType(pixmap);
|
||||
SkAlphaType alphaType = AlphaTypeToSkAlphaType(pixmap);
|
||||
sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeSRGB();
|
||||
return SkImageInfo::Make(pixmap->GetWidth(), pixmap->GetHeight(), colorType, alphaType, colorSpace);
|
||||
sptr<OHOS::SurfaceBuffer> buffer;
|
||||
int32_t releaseFence = 0;
|
||||
OHOS::BufferRequestConfig config = {
|
||||
.width = bufferWidth,
|
||||
.height = bufferHeight,
|
||||
.strideAlignment = 0x8,
|
||||
.format = PIXEL_FMT_RGBA_8888,
|
||||
.usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA,
|
||||
};
|
||||
|
||||
OHOS::SurfaceError ret = layer->RequestBuffer(buffer, releaseFence, config);
|
||||
if (ret != OHOS::SURFACE_ERROR_OK) {
|
||||
WLOGFE("request buffer ret:%{public}s", SurfaceErrorStr(ret).c_str());
|
||||
return nullptr;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void SurfaceDraw::DrawSkImage(std::shared_ptr<RSSurfaceNode> surfaceNode, Rect winRect,
|
||||
sptr<Media::PixelMap> pixelMap, uint32_t bkgColor)
|
||||
std::unique_ptr<OHOS::Media::PixelMap> SurfaceDraw::DecodeImageToPixelMap(const std::string &imagePath)
|
||||
{
|
||||
// Get canvas
|
||||
WLOGFI("DrawSkImage winRect, [%{public}d, %{public}d, %{public}d, %{public}d], bkgColor:%{public}x",
|
||||
winRect.posX_, winRect.posY_, winRect.width_, winRect.height_, bkgColor);
|
||||
auto width = static_cast<int32_t>(winRect.width_);
|
||||
auto height = static_cast<int32_t>(winRect.height_);
|
||||
std::unique_ptr<RSSurfaceFrame> frame;
|
||||
SkCanvas* canvas;
|
||||
auto rsSurface = PrepareDraw(surfaceNode, frame, canvas, width, height);
|
||||
if (rsSurface == nullptr) {
|
||||
OHOS::Media::SourceOptions opts;
|
||||
opts.formatHint = "image/png";
|
||||
uint32_t ret = 0;
|
||||
auto imageSource = OHOS::Media::ImageSource::CreateImageSource(imagePath, opts, ret);
|
||||
if (imageSource == nullptr) {
|
||||
WLOGFE("invalid image path.");
|
||||
return nullptr;
|
||||
}
|
||||
std::set<std::string> formats;
|
||||
ret = imageSource->GetSupportedFormats(formats);
|
||||
WLOGFD("get supported format ret:%{public}u", ret);
|
||||
|
||||
OHOS::Media::DecodeOptions decodeOpts;
|
||||
std::unique_ptr<OHOS::Media::PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, ret);
|
||||
if (pixelMap == nullptr) {
|
||||
WLOGFE("pixelMap is nullptr");
|
||||
}
|
||||
return pixelMap;
|
||||
}
|
||||
|
||||
void SurfaceDraw::DrawPixelmap(Drawing::Canvas &canvas, const std::string& imagePath)
|
||||
{
|
||||
std::unique_ptr<OHOS::Media::PixelMap> pixelmap = DecodeImageToPixelMap(imagePath);
|
||||
if (pixelmap == nullptr) {
|
||||
WLOGFE("drawing pixel map is nullptr");
|
||||
return;
|
||||
}
|
||||
SkPaint bkgPaint;
|
||||
bkgPaint.setColor(bkgColor);
|
||||
canvas->drawRect(SkRect::MakeXYWH(0.0, 0.0, width, height), bkgPaint);
|
||||
Drawing::Pen pen;
|
||||
pen.SetAntiAlias(true);
|
||||
pen.SetColor(Drawing::Color::COLOR_BLUE);
|
||||
Drawing::scalar penWidth = 1;
|
||||
pen.SetWidth(penWidth);
|
||||
canvas.AttachPen(pen);
|
||||
canvas.DrawBitmap(*pixelmap, 0, 0);
|
||||
}
|
||||
|
||||
// Create SkPixmap from PixelMap
|
||||
auto imageInfo = MakeSkImageInfoFromPixelMap(pixelMap);
|
||||
SkPixmap imagePixmap(imageInfo, reinterpret_cast<const void*>(pixelMap->GetPixels()), pixelMap->GetRowBytes());
|
||||
|
||||
// Create SkImage from SkPixmap
|
||||
sk_sp<SkImage> skImage = SkImage::MakeFromRaster(imagePixmap, nullptr, nullptr);
|
||||
if (!skImage) {
|
||||
WLOGFE("sk image is null");
|
||||
return;
|
||||
bool SurfaceDraw::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, const std::string& imagePath)
|
||||
{
|
||||
Drawing::Bitmap bitmap;
|
||||
Drawing::BitmapFormat format { Drawing::ColorType::COLORTYPE_RGBA_8888,
|
||||
Drawing::AlphaType::ALPHATYPE_OPAQUE };
|
||||
bitmap.Build(width, height, format);
|
||||
Drawing::Canvas canvas;
|
||||
canvas.Bind(bitmap);
|
||||
canvas.Clear(Drawing::Color::COLOR_TRANSPARENT);
|
||||
DrawPixelmap(canvas, imagePath);
|
||||
static constexpr uint32_t stride = 4;
|
||||
uint32_t addrSize = width * height * stride;
|
||||
errno_t ret = memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize);
|
||||
if (ret != EOK) {
|
||||
WLOGFE("draw failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
SkPaint paint;
|
||||
SkRect rect;
|
||||
int realHeight = std::min(height, skImage->height()); // need to scale
|
||||
int realWidth = std::min(width, skImage->width());
|
||||
int pointX = (width - realWidth) / 2; // 2 is mid point
|
||||
int pointY = (height - realHeight) / 2; // 2 is mid point
|
||||
rect.setXYWH(pointX, pointY, realWidth, realHeight);
|
||||
bool SurfaceDraw::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, std::shared_ptr<Media::PixelMap> pixelMap)
|
||||
{
|
||||
Drawing::Bitmap bitmap;
|
||||
Drawing::Canvas canvas;
|
||||
Drawing::BitmapFormat format { Drawing::ColorType::COLORTYPE_RGBA_8888, Drawing::AlphaType::ALPHATYPE_OPAQUE };
|
||||
bitmap.Build(width, height, format);
|
||||
canvas.Bind(bitmap);
|
||||
canvas.Clear(Drawing::Color::COLOR_TRANSPARENT);
|
||||
|
||||
canvas->drawImageRect(skImage.get(), rect, &paint);
|
||||
if (!rsSurface->FlushFrame(frame)) {
|
||||
WLOGFE("fail to flush frame");
|
||||
return;
|
||||
Drawing::Image image;
|
||||
Drawing::Bitmap imageBitmap;
|
||||
Drawing::SamplingOptions sampling = Drawing::SamplingOptions(Drawing::FilterMode::NEAREST,
|
||||
Drawing::MipmapMode::NEAREST);
|
||||
imageBitmap.Build(pixelMap->GetWidth(), pixelMap->GetHeight(), format);
|
||||
imageBitmap.SetPixels(const_cast<uint8_t*>(pixelMap->GetPixels()));
|
||||
image.BuildFromBitmap(imageBitmap);
|
||||
|
||||
Drawing::Rect dst(0, 0, width, height);
|
||||
Drawing::Rect src(0, 0, pixelMap->GetWidth(), pixelMap->GetHeight());
|
||||
canvas.DrawImageRect(image, src, dst, sampling);
|
||||
|
||||
static constexpr uint32_t stride = 4;
|
||||
uint32_t addrSize = width * height * stride;
|
||||
errno_t ret = memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize);
|
||||
if (ret != EOK) {
|
||||
WLOGFE("draw failed");
|
||||
return false;
|
||||
}
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SurfaceDraw::DoDraw(uint8_t *addr, uint32_t width, uint32_t height, uint32_t color)
|
||||
{
|
||||
Drawing::Bitmap bitmap;
|
||||
Drawing::BitmapFormat format { Drawing::ColorType::COLORTYPE_RGBA_8888,
|
||||
Drawing::AlphaType::ALPHATYPE_OPAQUE };
|
||||
bitmap.Build(width, height, format);
|
||||
Drawing::Canvas canvas;
|
||||
canvas.Bind(bitmap);
|
||||
canvas.Clear(color);
|
||||
|
||||
static constexpr uint32_t stride = 4;
|
||||
uint32_t addrSize = width * height * stride;
|
||||
errno_t ret = memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize);
|
||||
if (ret != EOK) {
|
||||
WLOGFE("draw failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SurfaceDraw::DrawImageRect(std::shared_ptr<RSSurfaceNode> surfaceNode, Rect rect,
|
||||
sptr<Media::PixelMap> pixelMap, uint32_t color)
|
||||
{
|
||||
int32_t winHeight = static_cast<int32_t>(rect.height_);
|
||||
int32_t winWidth = static_cast<int32_t>(rect.width_);
|
||||
sptr<OHOS::Surface> layer = GetLayer(surfaceNode);
|
||||
if (layer == nullptr) {
|
||||
WLOGFE("layer is nullptr");
|
||||
return false;
|
||||
}
|
||||
sptr<OHOS::SurfaceBuffer> buffer = GetSurfaceBuffer(layer, winWidth, winHeight);
|
||||
if (buffer == nullptr || buffer->GetVirAddr() == nullptr) {
|
||||
return false;
|
||||
}
|
||||
auto addr = static_cast<uint8_t *>(buffer->GetVirAddr());
|
||||
if (!DoDrawImageRect(addr, winWidth, winHeight, pixelMap, color)) {
|
||||
WLOGE("draw image rect failed.");
|
||||
return false;
|
||||
}
|
||||
OHOS::BufferFlushConfig flushConfig = {
|
||||
.damage = {
|
||||
.w = buffer->GetWidth(),
|
||||
.h = buffer->GetHeight(),
|
||||
},
|
||||
};
|
||||
OHOS::SurfaceError surfaceRet = layer->FlushBuffer(buffer, -1, flushConfig);
|
||||
if (surfaceRet != OHOS::SurfaceError::SURFACE_ERROR_OK) {
|
||||
WLOGFE("draw pointer FlushBuffer ret:%{public}s", SurfaceErrorStr(surfaceRet).c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SurfaceDraw::DoDrawImageRect(uint8_t *addr, int32_t winWidth, int32_t winHeight,
|
||||
sptr<Media::PixelMap> pixelMap, uint32_t color)
|
||||
{
|
||||
Drawing::Bitmap bitmap;
|
||||
Drawing::BitmapFormat format { Drawing::ColorType::COLORTYPE_RGBA_8888,
|
||||
Drawing::AlphaType::ALPHATYPE_OPAQUE };
|
||||
bitmap.Build(winWidth, winHeight, format);
|
||||
Drawing::Canvas canvas;
|
||||
canvas.Bind(bitmap);
|
||||
canvas.Clear(color);
|
||||
if (pixelMap == nullptr) {
|
||||
WLOGFE("drawing pixel map is nullptr");
|
||||
return false;
|
||||
}
|
||||
uint32_t iconHeight = pixelMap->GetHeight();
|
||||
uint32_t iconWidth = pixelMap->GetWidth();
|
||||
Drawing::Image image;
|
||||
Drawing::Bitmap iconBitmap;
|
||||
iconBitmap.Build(iconWidth, iconHeight, format);
|
||||
iconBitmap.SetPixels(const_cast<uint8_t*>(pixelMap->GetPixels()));
|
||||
image.BuildFromBitmap(iconBitmap);
|
||||
Drawing::SamplingOptions sampling = Drawing::SamplingOptions(Drawing::FilterMode::NEAREST,
|
||||
Drawing::MipmapMode::NEAREST);
|
||||
|
||||
int realHeight = std::min(winHeight, pixelMap->GetHeight()); // need to scale
|
||||
int realWidth = std::min(winWidth, pixelMap->GetWidth());
|
||||
int pointX = (winWidth - realWidth) / 2; // 2 is mid point
|
||||
int pointY = (winHeight - realHeight) / 2; // 2 is mid point
|
||||
Drawing::Rect dst(pointX, pointY, pointX + realWidth, pointY + realHeight);
|
||||
canvas.DrawImageRect(image, dst, sampling);
|
||||
|
||||
uint32_t stride = 4;
|
||||
uint32_t addrSize = winWidth * winHeight * stride;
|
||||
errno_t ret = memcpy_s(addr, addrSize, bitmap.GetPixels(), addrSize);
|
||||
if (ret != EOK) {
|
||||
WLOGFE("draw failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // Rosen
|
||||
} // OHOS
|
||||
@@ -152,7 +152,7 @@ bool SurfaceReader::ProcessBuffer(const sptr<SurfaceBuffer> &buf)
|
||||
|
||||
pixelMap->SetPixelsAddr(data, nullptr, width * height, AllocatorType::HEAP_ALLOC, nullptr);
|
||||
|
||||
handler_->OnImageAvalible(pixelMap);
|
||||
handler_->OnImageAvailable(pixelMap);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,12 +21,12 @@ namespace Rosen {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SurfaceReaderHandlerImpl"};
|
||||
} // namespace
|
||||
bool SurfaceReaderHandlerImpl::OnImageAvalible(sptr<Media::PixelMap> pixleMap)
|
||||
bool SurfaceReaderHandlerImpl::OnImageAvailable(sptr<Media::PixelMap> pixelMap)
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
if (!flag_) {
|
||||
flag_ = true;
|
||||
pixleMap_ = pixleMap;
|
||||
pixelMap_ = pixelMap;
|
||||
WLOGFI("Get an Image!");
|
||||
}
|
||||
return true;
|
||||
@@ -49,7 +49,7 @@ void SurfaceReaderHandlerImpl::ResetFlag()
|
||||
sptr<Media::PixelMap> SurfaceReaderHandlerImpl::GetPixelMap()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
return pixleMap_;
|
||||
return pixelMap_;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ void WindowProperty::SetWindowName(const std::string& name)
|
||||
|
||||
void WindowProperty::SetWindowRect(const struct Rect& rect)
|
||||
{
|
||||
recomputeTransformMat_ = true;
|
||||
windowRect_ = rect;
|
||||
}
|
||||
|
||||
@@ -51,7 +52,7 @@ void WindowProperty::SetWindowType(WindowType type)
|
||||
|
||||
void WindowProperty::SetWindowMode(WindowMode mode)
|
||||
{
|
||||
if (!WindowHelper::IsValidWindowMode(mode)) {
|
||||
if (!WindowHelper::IsValidWindowMode(mode) || !WindowHelper::IsWindowModeSupported(modeSupportInfo_, mode)) {
|
||||
return;
|
||||
}
|
||||
if (!WindowHelper::IsSplitWindowMode(mode_)) {
|
||||
@@ -62,6 +63,9 @@ void WindowProperty::SetWindowMode(WindowMode mode)
|
||||
|
||||
void WindowProperty::SetLastWindowMode(WindowMode mode)
|
||||
{
|
||||
if (!WindowHelper::IsWindowModeSupported(modeSupportInfo_, mode)) {
|
||||
return;
|
||||
}
|
||||
lastMode_ = mode;
|
||||
}
|
||||
|
||||
@@ -103,6 +107,32 @@ void WindowProperty::SetAlpha(float alpha)
|
||||
alpha_ = alpha;
|
||||
}
|
||||
|
||||
void WindowProperty::SetTransform(const Transform& trans)
|
||||
{
|
||||
recomputeTransformMat_ = true;
|
||||
trans_ = trans;
|
||||
}
|
||||
|
||||
void WindowProperty::ComputeTransform()
|
||||
{
|
||||
if (recomputeTransformMat_ && (trans_ != Transform::Identity())) {
|
||||
// Update transform matrix
|
||||
transformMat_ = WindowHelper::ComputeRectTransformMat4(trans_, windowRect_);
|
||||
// Update window plane
|
||||
TransformHelper::Vector3 a = TransformHelper::Transform(
|
||||
TransformHelper::Vector3 { static_cast<float>(windowRect_.posX_),
|
||||
static_cast<float>(windowRect_.posY_), 0 }, transformMat_);
|
||||
TransformHelper::Vector3 b = TransformHelper::Transform(
|
||||
TransformHelper::Vector3 { static_cast<float>(windowRect_.posX_ + windowRect_.width_),
|
||||
static_cast<float>(windowRect_.posY_), 0 }, transformMat_);
|
||||
TransformHelper::Vector3 c = TransformHelper::Transform(
|
||||
TransformHelper::Vector3 { static_cast<float>(windowRect_.posX_),
|
||||
static_cast<float>(windowRect_.posY_+ windowRect_.height_), 0 }, transformMat_);
|
||||
windowPlane_ = TransformHelper::Plane(a, b, c);
|
||||
recomputeTransformMat_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
void WindowProperty::SetBrightness(float brightness)
|
||||
{
|
||||
brightness_ = brightness;
|
||||
@@ -133,6 +163,11 @@ void WindowProperty::SetWindowFlags(uint32_t flags)
|
||||
flags_ = flags;
|
||||
}
|
||||
|
||||
void WindowProperty::SetSizeLimits(const WindowSizeLimits& sizeLimits)
|
||||
{
|
||||
sizeLimits_ = sizeLimits;
|
||||
}
|
||||
|
||||
void WindowProperty::AddWindowFlag(WindowFlag flag)
|
||||
{
|
||||
flags_ |= static_cast<uint32_t>(flag);
|
||||
@@ -180,6 +215,11 @@ void WindowProperty::SetOriginRect(const Rect& rect)
|
||||
originRect_ = rect;
|
||||
}
|
||||
|
||||
void WindowProperty::SetAccessTokenId(uint32_t accessTokenId)
|
||||
{
|
||||
accessTokenId_ = accessTokenId;
|
||||
}
|
||||
|
||||
WindowSizeChangeReason WindowProperty::GetWindowSizeChangeReason() const
|
||||
{
|
||||
return windowSizeChangeReason_;
|
||||
@@ -187,6 +227,14 @@ WindowSizeChangeReason WindowProperty::GetWindowSizeChangeReason() const
|
||||
|
||||
void WindowProperty::ResumeLastWindowMode()
|
||||
{
|
||||
// if lastMode isn't supported, get supported mode from supportModeInfo
|
||||
if (!WindowHelper::IsWindowModeSupported(modeSupportInfo_, lastMode_)) {
|
||||
auto mode = WindowHelper::GetWindowModeFromModeSupportInfo(modeSupportInfo_);
|
||||
if (!WindowHelper::IsSplitWindowMode(mode)) {
|
||||
mode_ = mode;
|
||||
}
|
||||
return;
|
||||
}
|
||||
mode_ = lastMode_;
|
||||
}
|
||||
|
||||
@@ -265,6 +313,11 @@ float WindowProperty::GetAlpha() const
|
||||
return alpha_;
|
||||
}
|
||||
|
||||
Transform WindowProperty::GetTransform() const
|
||||
{
|
||||
return trans_;
|
||||
}
|
||||
|
||||
float WindowProperty::GetBrightness() const
|
||||
{
|
||||
return brightness_;
|
||||
@@ -320,6 +373,11 @@ void WindowProperty::SetModeSupportInfo(uint32_t modeSupportInfo)
|
||||
modeSupportInfo_ = modeSupportInfo;
|
||||
}
|
||||
|
||||
void WindowProperty::SetRequestModeSupportInfo(uint32_t requestModeSupportInfo)
|
||||
{
|
||||
requestModeSupportInfo_ = requestModeSupportInfo;
|
||||
}
|
||||
|
||||
uint32_t WindowProperty::GetWindowId() const
|
||||
{
|
||||
return windowId_;
|
||||
@@ -345,6 +403,11 @@ uint32_t WindowProperty::GetModeSupportInfo() const
|
||||
return modeSupportInfo_;
|
||||
}
|
||||
|
||||
uint32_t WindowProperty::GetRequestModeSupportInfo() const
|
||||
{
|
||||
return requestModeSupportInfo_;
|
||||
}
|
||||
|
||||
bool WindowProperty::GetTokenState() const
|
||||
{
|
||||
return tokenState_;
|
||||
@@ -365,6 +428,16 @@ bool WindowProperty::GetStretchable() const
|
||||
return isStretchable_;
|
||||
}
|
||||
|
||||
WindowSizeLimits WindowProperty::GetSizeLimits() const
|
||||
{
|
||||
return sizeLimits_;
|
||||
}
|
||||
|
||||
const TransformHelper::Matrix4& WindowProperty::GetTransformMat() const
|
||||
{
|
||||
return transformMat_;
|
||||
}
|
||||
|
||||
void WindowProperty::SetTouchHotAreas(const std::vector<Rect>& rects)
|
||||
{
|
||||
touchHotAreas_ = rects;
|
||||
@@ -375,6 +448,11 @@ void WindowProperty::GetTouchHotAreas(std::vector<Rect>& rects) const
|
||||
rects = touchHotAreas_;
|
||||
}
|
||||
|
||||
uint32_t WindowProperty::GetAccessTokenId() const
|
||||
{
|
||||
return accessTokenId_;
|
||||
}
|
||||
|
||||
bool WindowProperty::MapMarshalling(Parcel& parcel) const
|
||||
{
|
||||
auto size = sysBarPropMap_.size();
|
||||
@@ -397,7 +475,6 @@ bool WindowProperty::MapMarshalling(Parcel& parcel) const
|
||||
|
||||
void WindowProperty::MapUnmarshalling(Parcel& parcel, WindowProperty* property)
|
||||
{
|
||||
std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap;
|
||||
uint32_t size = parcel.ReadUint32();
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
WindowType type = static_cast<WindowType>(parcel.ReadUint32());
|
||||
@@ -430,6 +507,49 @@ void WindowProperty::UnmarshallingTouchHotAreas(Parcel& parcel, WindowProperty*
|
||||
}
|
||||
}
|
||||
|
||||
bool WindowProperty::MarshallingTransform(Parcel& parcel) const
|
||||
{
|
||||
return parcel.WriteFloat(trans_.pivotX_) && parcel.WriteFloat(trans_.pivotY_) &&
|
||||
parcel.WriteFloat(trans_.scaleX_) && parcel.WriteFloat(trans_.scaleY_) &&
|
||||
parcel.WriteFloat(trans_.rotationX_) && parcel.WriteFloat(trans_.rotationY_) &&
|
||||
parcel.WriteFloat(trans_.rotationZ_) && parcel.WriteFloat(trans_.translateX_) &&
|
||||
parcel.WriteFloat(trans_.translateY_) && parcel.WriteFloat(trans_.translateZ_);
|
||||
}
|
||||
|
||||
void WindowProperty::UnmarshallingTransform(Parcel& parcel, WindowProperty* property)
|
||||
{
|
||||
Transform trans;
|
||||
trans.pivotX_ = parcel.ReadFloat();
|
||||
trans.pivotY_ = parcel.ReadFloat();
|
||||
trans.scaleX_ = parcel.ReadFloat();
|
||||
trans.scaleY_ = parcel.ReadFloat();
|
||||
trans.rotationX_ = parcel.ReadFloat();
|
||||
trans.rotationY_ = parcel.ReadFloat();
|
||||
trans.rotationZ_ = parcel.ReadFloat();
|
||||
trans.translateX_ = parcel.ReadFloat();
|
||||
trans.translateY_ = parcel.ReadFloat();
|
||||
trans.translateZ_ = parcel.ReadFloat();
|
||||
property->SetTransform(trans);
|
||||
}
|
||||
|
||||
bool WindowProperty::MarshallingWindowSizeLimits(Parcel& parcel) const
|
||||
{
|
||||
if (parcel.WriteBool(sizeLimits_.isSizeLimitsUpdated_) && parcel.WriteUint32(sizeLimits_.maxWidth_) &&
|
||||
parcel.WriteUint32(sizeLimits_.maxHeight_) && parcel.WriteUint32(sizeLimits_.minWidth_) &&
|
||||
parcel.WriteUint32(sizeLimits_.minHeight_) && parcel.WriteFloat(sizeLimits_.maxRatio_) &&
|
||||
parcel.WriteFloat(sizeLimits_.minRatio_)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void WindowProperty::UnmarshallingWindowSizeLimits(Parcel& parcel, WindowProperty* property)
|
||||
{
|
||||
WindowSizeLimits sizeLimits = { parcel.ReadBool(), parcel.ReadUint32(), parcel.ReadUint32(), parcel.ReadUint32(),
|
||||
parcel.ReadUint32(), parcel.ReadFloat(), parcel.ReadFloat() };
|
||||
property->SetSizeLimits(sizeLimits);
|
||||
}
|
||||
|
||||
bool WindowProperty::Marshalling(Parcel& parcel) const
|
||||
{
|
||||
return parcel.WriteString(windowName_) && parcel.WriteInt32(windowRect_.posX_) &&
|
||||
@@ -448,9 +568,11 @@ bool WindowProperty::Marshalling(Parcel& parcel) const
|
||||
parcel.WriteUint32(static_cast<uint32_t>(windowSizeChangeReason_)) && parcel.WriteBool(tokenState_) &&
|
||||
parcel.WriteUint32(callingWindow_) && parcel.WriteUint32(static_cast<uint32_t>(requestedOrientation_)) &&
|
||||
parcel.WriteBool(turnScreenOn_) && parcel.WriteBool(keepScreenOn_) &&
|
||||
parcel.WriteUint32(modeSupportInfo_) && parcel.WriteUint32(static_cast<uint32_t>(dragType_)) &&
|
||||
parcel.WriteUint32(modeSupportInfo_) && parcel.WriteUint32(requestModeSupportInfo_) &&
|
||||
parcel.WriteUint32(static_cast<uint32_t>(dragType_)) &&
|
||||
parcel.WriteUint32(originRect_.width_) && parcel.WriteUint32(originRect_.height_) &&
|
||||
parcel.WriteBool(isStretchable_) && MarshallingTouchHotAreas(parcel);
|
||||
parcel.WriteBool(isStretchable_) && MarshallingTouchHotAreas(parcel) && parcel.WriteUint32(accessTokenId_) &&
|
||||
MarshallingTransform(parcel) && MarshallingWindowSizeLimits(parcel);
|
||||
}
|
||||
|
||||
WindowProperty* WindowProperty::Unmarshalling(Parcel& parcel)
|
||||
@@ -492,12 +614,16 @@ WindowProperty* WindowProperty::Unmarshalling(Parcel& parcel)
|
||||
property->SetTurnScreenOn(parcel.ReadBool());
|
||||
property->SetKeepScreenOn(parcel.ReadBool());
|
||||
property->SetModeSupportInfo(parcel.ReadUint32());
|
||||
property->SetRequestModeSupportInfo(parcel.ReadUint32());
|
||||
property->SetDragType(static_cast<DragType>(parcel.ReadUint32()));
|
||||
uint32_t w = parcel.ReadUint32();
|
||||
uint32_t h = parcel.ReadUint32();
|
||||
property->SetOriginRect(Rect { 0, 0, w, h });
|
||||
property->SetStretchable(parcel.ReadBool());
|
||||
UnmarshallingTouchHotAreas(parcel, property);
|
||||
property->SetAccessTokenId(parcel.ReadUint32());
|
||||
UnmarshallingTransform(parcel, property);
|
||||
UnmarshallingWindowSizeLimits(parcel, property);
|
||||
return property;
|
||||
}
|
||||
|
||||
@@ -549,6 +675,12 @@ bool WindowProperty::Write(Parcel& parcel, PropertyChangeAction action)
|
||||
case PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA:
|
||||
ret &= MarshallingTouchHotAreas(parcel);
|
||||
break;
|
||||
case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY:
|
||||
ret &= MarshallingTransform(parcel);
|
||||
break;
|
||||
case PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG:
|
||||
ret &= parcel.WriteUint32(animationFlag_);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -602,6 +734,13 @@ void WindowProperty::Read(Parcel& parcel, PropertyChangeAction action)
|
||||
case PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA:
|
||||
UnmarshallingTouchHotAreas(parcel, this);
|
||||
break;
|
||||
case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY:
|
||||
UnmarshallingTransform(parcel, this);
|
||||
break;
|
||||
case PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG: {
|
||||
SetAnimationFlag(parcel.ReadUint32());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -639,10 +778,14 @@ void WindowProperty::CopyFrom(const sptr<WindowProperty>& property)
|
||||
turnScreenOn_ = property->turnScreenOn_;
|
||||
keepScreenOn_ = property->keepScreenOn_;
|
||||
modeSupportInfo_ = property->modeSupportInfo_;
|
||||
requestModeSupportInfo_ = property->requestModeSupportInfo_;
|
||||
dragType_ = property->dragType_;
|
||||
originRect_ = property->originRect_;
|
||||
isStretchable_ = property->isStretchable_;
|
||||
touchHotAreas_ = property->touchHotAreas_;
|
||||
accessTokenId_ = property->accessTokenId_;
|
||||
trans_ = property->trans_;
|
||||
sizeLimits_ = property->sizeLimits_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,15 @@ WindowTransitionInfo::WindowTransitionInfo(sptr<AAFwk::AbilityTransitionInfo> in
|
||||
displayId_ = info->displayId_;
|
||||
isShowWhenLocked_ = info->isShowWhenLocked_;
|
||||
isRecent_ = info->isRecent_;
|
||||
if (info->windowModes_.empty()) {
|
||||
supportWindowModes_ = {
|
||||
AppExecFwk::SupportWindowMode::FULLSCREEN,
|
||||
AppExecFwk::SupportWindowMode::SPLIT,
|
||||
AppExecFwk::SupportWindowMode::FLOATING
|
||||
};
|
||||
} else {
|
||||
supportWindowModes_.assign(info->windowModes_.begin(), info->windowModes_.end());
|
||||
}
|
||||
}
|
||||
|
||||
void WindowTransitionInfo::SetBundleName(std::string name)
|
||||
@@ -103,6 +112,16 @@ void WindowTransitionInfo::SetShowFlagWhenLocked(bool isShow)
|
||||
isShowWhenLocked_ = isShow;
|
||||
}
|
||||
|
||||
void WindowTransitionInfo::SetWindowSupportModes(const std::vector<AppExecFwk::SupportWindowMode> supportModes)
|
||||
{
|
||||
supportWindowModes_.assign(supportModes.begin(), supportModes.end());
|
||||
}
|
||||
|
||||
std::vector<AppExecFwk::SupportWindowMode> WindowTransitionInfo::GetWindowSupportModes()
|
||||
{
|
||||
return supportWindowModes_;
|
||||
}
|
||||
|
||||
bool WindowTransitionInfo::GetShowFlagWhenLocked()
|
||||
{
|
||||
return isShowWhenLocked_;
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "wm_math.h"
|
||||
#include <memory>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
namespace TransformHelper {
|
||||
const Matrix3 Matrix3::Identity = { {
|
||||
{ 1, 0, 0 },
|
||||
{ 0, 1, 0 },
|
||||
{ 0, 0, 1 },
|
||||
} };
|
||||
const Matrix4 Matrix4::Identity = { {
|
||||
{ 1, 0, 0, 0 },
|
||||
{ 0, 1, 0, 0 },
|
||||
{ 0, 0, 1, 0 },
|
||||
{ 0, 0, 0, 1 },
|
||||
} };
|
||||
|
||||
Matrix3 operator*(const Matrix3& left, const Matrix3& right)
|
||||
{
|
||||
return { {
|
||||
// row 0
|
||||
{ left.mat_[0][0] * right.mat_[0][0] + left.mat_[0][1] * right.mat_[1][0] + left.mat_[0][2] * right.mat_[2][0],
|
||||
left.mat_[0][0] * right.mat_[0][1] + left.mat_[0][1] * right.mat_[1][1] + left.mat_[0][2] * right.mat_[2][1],
|
||||
left.mat_[0][0] * right.mat_[0][2] + left.mat_[0][1] * right.mat_[1][2] + left.mat_[0][2] * right.mat_[2][2] },
|
||||
|
||||
// row 1
|
||||
{ left.mat_[1][0] * right.mat_[0][0] + left.mat_[1][1] * right.mat_[1][0] + left.mat_[1][2] * right.mat_[2][0],
|
||||
left.mat_[1][0] * right.mat_[0][1] + left.mat_[1][1] * right.mat_[1][1] + left.mat_[1][2] * right.mat_[2][1],
|
||||
left.mat_[1][0] * right.mat_[0][2] + left.mat_[1][1] * right.mat_[1][2] + left.mat_[1][2] * right.mat_[2][2] },
|
||||
|
||||
// row 2
|
||||
{ left.mat_[2][0] * right.mat_[0][0] + left.mat_[2][1] * right.mat_[1][0] + left.mat_[2][2] * right.mat_[2][0],
|
||||
left.mat_[2][0] * right.mat_[0][1] + left.mat_[2][1] * right.mat_[1][1] + left.mat_[2][2] * right.mat_[2][1],
|
||||
left.mat_[2][0] * right.mat_[0][2] + left.mat_[2][1] * right.mat_[1][2] + left.mat_[2][2] * right.mat_[2][2] }
|
||||
} };
|
||||
}
|
||||
|
||||
Matrix3& Matrix3::operator*=(const Matrix3& right)
|
||||
{
|
||||
*this = *this * right;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Matrix4 operator*(const Matrix4& left, const Matrix4& right)
|
||||
{
|
||||
return { {
|
||||
// row 0
|
||||
{ left.mat_[0][0] * right.mat_[0][0] + left.mat_[0][1] * right.mat_[1][0] +
|
||||
left.mat_[0][2] * right.mat_[2][0] + left.mat_[0][3] * right.mat_[3][0],
|
||||
left.mat_[0][0] * right.mat_[0][1] + left.mat_[0][1] * right.mat_[1][1] +
|
||||
left.mat_[0][2] * right.mat_[2][1] + left.mat_[0][3] * right.mat_[3][1],
|
||||
left.mat_[0][0] * right.mat_[0][2] + left.mat_[0][1] * right.mat_[1][2] +
|
||||
left.mat_[0][2] * right.mat_[2][2] + left.mat_[0][3] * right.mat_[3][2],
|
||||
left.mat_[0][0] * right.mat_[0][3] + left.mat_[0][1] * right.mat_[1][3] +
|
||||
left.mat_[0][2] * right.mat_[2][3] + left.mat_[0][3] * right.mat_[3][3] },
|
||||
|
||||
// row 1
|
||||
{ left.mat_[1][0] * right.mat_[0][0] + left.mat_[1][1] * right.mat_[1][0] +
|
||||
left.mat_[1][2] * right.mat_[2][0] + left.mat_[1][3] * right.mat_[3][0],
|
||||
left.mat_[1][0] * right.mat_[0][1] + left.mat_[1][1] * right.mat_[1][1] +
|
||||
left.mat_[1][2] * right.mat_[2][1] + left.mat_[1][3] * right.mat_[3][1],
|
||||
left.mat_[1][0] * right.mat_[0][2] + left.mat_[1][1] * right.mat_[1][2] +
|
||||
left.mat_[1][2] * right.mat_[2][2] + left.mat_[1][3] * right.mat_[3][2],
|
||||
left.mat_[1][0] * right.mat_[0][3] + left.mat_[1][1] * right.mat_[1][3] +
|
||||
left.mat_[1][2] * right.mat_[2][3] + left.mat_[1][3] * right.mat_[3][3] },
|
||||
|
||||
// row 2
|
||||
{ left.mat_[2][0] * right.mat_[0][0] + left.mat_[2][1] * right.mat_[1][0] +
|
||||
left.mat_[2][2] * right.mat_[2][0] + left.mat_[2][3] * right.mat_[3][0],
|
||||
left.mat_[2][0] * right.mat_[0][1] + left.mat_[2][1] * right.mat_[1][1] +
|
||||
left.mat_[2][2] * right.mat_[2][1] + left.mat_[2][3] * right.mat_[3][1],
|
||||
left.mat_[2][0] * right.mat_[0][2] + left.mat_[2][1] * right.mat_[1][2] +
|
||||
left.mat_[2][2] * right.mat_[2][2] + left.mat_[2][3] * right.mat_[3][2],
|
||||
left.mat_[2][0] * right.mat_[0][3] + left.mat_[2][1] * right.mat_[1][3] +
|
||||
left.mat_[2][2] * right.mat_[2][3] + left.mat_[2][3] * right.mat_[3][3] },
|
||||
|
||||
// row 3
|
||||
{ left.mat_[3][0] * right.mat_[0][0] + left.mat_[3][1] * right.mat_[1][0] +
|
||||
left.mat_[3][2] * right.mat_[2][0] + left.mat_[3][3] * right.mat_[3][0],
|
||||
left.mat_[3][0] * right.mat_[0][1] + left.mat_[3][1] * right.mat_[1][1] +
|
||||
left.mat_[3][2] * right.mat_[2][1] + left.mat_[3][3] * right.mat_[3][1],
|
||||
left.mat_[3][0] * right.mat_[0][2] + left.mat_[3][1] * right.mat_[1][2] +
|
||||
left.mat_[3][2] * right.mat_[2][2] + left.mat_[3][3] * right.mat_[3][2],
|
||||
left.mat_[3][0] * right.mat_[0][3] + left.mat_[3][1] * right.mat_[1][3] +
|
||||
left.mat_[3][2] * right.mat_[2][3] + left.mat_[3][3] * right.mat_[3][3] }
|
||||
} };
|
||||
}
|
||||
|
||||
Matrix4& Matrix4::operator*=(const Matrix4& right)
|
||||
{
|
||||
*this = *this * right;
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Matrix4::SwapRow(int row1, int row2)
|
||||
{
|
||||
float *p = mat_[row1];
|
||||
float *q = mat_[row2];
|
||||
float tmp = p[0];
|
||||
p[0] = q[0];
|
||||
q[0] = tmp;
|
||||
|
||||
tmp = p[1];
|
||||
p[1] = q[1];
|
||||
q[1] = tmp;
|
||||
|
||||
tmp = p[2];
|
||||
p[2] = q[2];
|
||||
q[2] = tmp;
|
||||
|
||||
tmp = p[3];
|
||||
p[3] = q[3];
|
||||
q[3] = tmp;
|
||||
}
|
||||
|
||||
void Matrix4::Invert()
|
||||
{
|
||||
// Inverse matrix with Gauss-Jordan method
|
||||
Matrix4 tmp = Matrix4::Identity;
|
||||
int i, j, k;
|
||||
float t, u;
|
||||
for (k = 0; k < MAT_SIZE; k++) {
|
||||
t = mat_[k][k];
|
||||
if (t < MathHelper::POS_ZERO && t > MathHelper::NAG_ZERO) {
|
||||
for (i = k + 1; i < MAT_SIZE; i++) {
|
||||
if (mat_[i][k] < MathHelper::NAG_ZERO || mat_[i][k] > MathHelper::POS_ZERO) {
|
||||
SwapRow(k, i);
|
||||
tmp.SwapRow(k, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
t = mat_[k][k];
|
||||
}
|
||||
for (j = 0; j <= k; j++) {
|
||||
tmp.mat_[k][j] /= t;
|
||||
}
|
||||
for (; j < MAT_SIZE; j++) {
|
||||
mat_[k][j] /= t;
|
||||
tmp.mat_[k][j] /= t;
|
||||
}
|
||||
for (i = 0; i < MAT_SIZE; i++) {
|
||||
if (i == k) {
|
||||
continue;
|
||||
}
|
||||
u = mat_[i][k];
|
||||
for (j = 0; j <= k; j++) {
|
||||
tmp.mat_[i][j] -= tmp.mat_[k][j] * u;
|
||||
}
|
||||
for (; j < MAT_SIZE; j++) {
|
||||
mat_[i][j] -= mat_[k][j] * u;
|
||||
tmp.mat_[i][j] -= tmp.mat_[k][j] * u;
|
||||
}
|
||||
}
|
||||
}
|
||||
*this = tmp;
|
||||
}
|
||||
|
||||
Vector3 Matrix4::GetScale() const
|
||||
{
|
||||
Vector3 retVal;
|
||||
retVal.x_ = Vector3(mat_[0][0], mat_[0][1], mat_[0][2]).Length();
|
||||
retVal.y_ = Vector3(mat_[1][0], mat_[1][1], mat_[1][2]).Length();
|
||||
retVal.z_ = Vector3(mat_[2][0], mat_[2][1], mat_[2][2]).Length();
|
||||
return retVal;
|
||||
}
|
||||
|
||||
Plane::Plane(const Vector3& normal, float d)
|
||||
: normal_(normal), d_(d)
|
||||
{
|
||||
}
|
||||
|
||||
Plane::Plane(const Vector3& a, const Vector3& b, const Vector3& c)
|
||||
{
|
||||
Vector3 ab = b - a;
|
||||
Vector3 ac = c - a;
|
||||
normal_ = Vector3::Cross(ab, ac);
|
||||
normal_.Normalize();
|
||||
d_ = -Vector3::Dot(a, normal_);
|
||||
}
|
||||
|
||||
float Plane::ComponentZ(float x, float y) const
|
||||
{
|
||||
return (-d_ - normal_.x_ * x - normal_.y_ * y) / normal_.z_;
|
||||
}
|
||||
|
||||
float Plane::ParallelDistanceGrad(const Vector3& a, const Vector3& b) const
|
||||
{
|
||||
Vector2 axy(a.x_, a.y_), bxy(b.x_, b.y_);
|
||||
return (b - a).Length() * std::abs(normal_.z_) / (bxy - axy).Length();
|
||||
}
|
||||
|
||||
// Create a scale matrix with x and y scales
|
||||
Matrix3 CreateScale(float xScale, float yScale)
|
||||
{
|
||||
return { {
|
||||
{ xScale, 0.0f, 0.0f },
|
||||
{ 0.0f, yScale, 0.0f },
|
||||
{ 0.0f, 0.0f, 1.0f },
|
||||
} };
|
||||
}
|
||||
|
||||
// Create a rotation matrix about the Z axis
|
||||
// theta is in radians
|
||||
Matrix3 CreateRotation(float theta)
|
||||
{
|
||||
return { {
|
||||
{ std::cos(theta), std::sin(theta), 0.0f },
|
||||
{ -std::sin(theta), std::cos(theta), 0.0f },
|
||||
{ 0.0f, 0.0f, 1.0f },
|
||||
} };
|
||||
}
|
||||
|
||||
// Create a translation matrix (on the xy-plane)
|
||||
Matrix3 CreateTranslation(const Vector2& trans)
|
||||
{
|
||||
return { {
|
||||
{ 1.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 1.0f, 0.0f },
|
||||
{ trans.x_, trans.y_, 1.0f },
|
||||
} };
|
||||
}
|
||||
|
||||
// Create a scale matrix with x, y, and z scales
|
||||
Matrix4 CreateScale(float xScale, float yScale, float zScale)
|
||||
{
|
||||
return { {
|
||||
{ xScale, 0.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, yScale, 0.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, zScale, 0.0f },
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f },
|
||||
} };
|
||||
}
|
||||
|
||||
// Create a rotation matrix about X axis
|
||||
// theta is in radians
|
||||
Matrix4 CreateRotationX(float theta)
|
||||
{
|
||||
return { {
|
||||
{ 1.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, std::cos(theta), std::sin(theta), 0.0f },
|
||||
{ 0.0f, -std::sin(theta), std::cos(theta), 0.0f },
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f },
|
||||
} };
|
||||
}
|
||||
|
||||
// Create a rotation matrix about Y axis
|
||||
// theta is in radians
|
||||
Matrix4 CreateRotationY(float theta)
|
||||
{
|
||||
return { {
|
||||
{ std::cos(theta), 0.0f, -std::sin(theta), 0.0f },
|
||||
{ 0.0f, 1.0f, 0.0f, 0.0f },
|
||||
{ std::sin(theta), 0.0f, std::cos(theta), 0.0f },
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f },
|
||||
} };
|
||||
}
|
||||
|
||||
// Create a rotation matrix about Z axis
|
||||
// theta is in radians
|
||||
Matrix4 CreateRotationZ(float theta)
|
||||
{
|
||||
return { {
|
||||
{ std::cos(theta), std::sin(theta), 0.0f, 0.0f },
|
||||
{ -std::sin(theta), std::cos(theta), 0.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, 1.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, 0.0f, 1.0f },
|
||||
} };
|
||||
}
|
||||
|
||||
// Create a 3D translation matrix
|
||||
Matrix4 CreateTranslation(const Vector3& trans)
|
||||
{
|
||||
return { {
|
||||
{ 1.0f, 0.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 1.0f, 0.0f, 0.0f },
|
||||
{ 0.0f, 0.0f, 1.0f, 0.0f },
|
||||
{ trans.x_, trans.y_, trans.z_, 1.0f },
|
||||
} };
|
||||
}
|
||||
|
||||
// Transform a Vector2 in xy-plane by matrix3
|
||||
Vector2 Transform(const Vector2& vec, const Matrix3& mat)
|
||||
{
|
||||
Vector2 retVal;
|
||||
retVal.x_ = vec.x_ * mat.mat_[0][0] + vec.y_ * mat.mat_[1][0] + mat.mat_[2][0];
|
||||
retVal.y_ = vec.x_ * mat.mat_[0][1] + vec.y_ * mat.mat_[1][1] + mat.mat_[2][1];
|
||||
return retVal;
|
||||
}
|
||||
|
||||
// Transform a Vector3 in 3D world by matrix4
|
||||
Vector3 Transform(const Vector3& vec, const Matrix4& mat)
|
||||
{
|
||||
Vector3 retVal;
|
||||
retVal.x_ = vec.x_ * mat.mat_[0][0] + vec.y_ * mat.mat_[1][0] +
|
||||
vec.z_ * mat.mat_[2][0] + mat.mat_[3][0];
|
||||
retVal.y_ = vec.x_ * mat.mat_[0][1] + vec.y_ * mat.mat_[1][1] +
|
||||
vec.z_ * mat.mat_[2][1] + mat.mat_[3][1];
|
||||
retVal.z_ = vec.x_ * mat.mat_[0][2] + vec.y_ * mat.mat_[1][2] +
|
||||
vec.z_ * mat.mat_[2][2] + mat.mat_[3][2];
|
||||
return retVal;
|
||||
}
|
||||
} // namespace TransformHelper
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
@@ -1,131 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "wm_trace.h"
|
||||
|
||||
#include <hitrace_meter.h>
|
||||
|
||||
#ifndef WINDOWS_PLATFORM
|
||||
#include <securec.h>
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
namespace {
|
||||
const size_t MAX_STRING_SIZE = 128;
|
||||
}
|
||||
|
||||
bool WmTraceEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void WmTraceBegin(const char* name)
|
||||
{
|
||||
if (name == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::string nameStr(name);
|
||||
StartTrace(HITRACE_TAG_WINDOW_MANAGER, nameStr);
|
||||
}
|
||||
|
||||
void WmTraceEnd()
|
||||
{
|
||||
if (WmTraceEnabled()) {
|
||||
FinishTrace(HITRACE_TAG_WINDOW_MANAGER);
|
||||
}
|
||||
}
|
||||
|
||||
void WmAsyncTraceBegin(int32_t taskId, const char* name)
|
||||
{
|
||||
if (name == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::string nameStr(name);
|
||||
StartAsyncTrace(HITRACE_TAG_WINDOW_MANAGER, nameStr, taskId);
|
||||
}
|
||||
|
||||
void WmAsyncTraceEnd(int32_t taskId, const char* name)
|
||||
{
|
||||
if (name == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::string nameStr(name);
|
||||
FinishAsyncTrace(HITRACE_TAG_WINDOW_MANAGER, nameStr, taskId);
|
||||
}
|
||||
|
||||
void WmAsyncTraceWithArgs(bool isBegin, int32_t taskId, const char* format, ...)
|
||||
{
|
||||
if (WmTraceEnabled()) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
WmAsyncTraceWithArgv(isBegin, taskId, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
|
||||
void WmAsyncTraceWithArgv(bool isBegin, int32_t taskId, const char* format, va_list args)
|
||||
{
|
||||
char name[MAX_STRING_SIZE] = { 0 };
|
||||
if (vsnprintf_s(name, sizeof(name), sizeof(name) - 1, format, args) < 0) {
|
||||
return;
|
||||
}
|
||||
if (isBegin) {
|
||||
WmAsyncTraceBegin(taskId, name);
|
||||
} else {
|
||||
WmAsyncTraceEnd(taskId, name);
|
||||
}
|
||||
}
|
||||
|
||||
bool WmTraceBeginWithArgv(const char* format, va_list args)
|
||||
{
|
||||
char name[MAX_STRING_SIZE] = { 0 };
|
||||
if (vsnprintf_s(name, sizeof(name), sizeof(name) - 1, format, args) < 0) {
|
||||
return false;
|
||||
}
|
||||
WmTraceBegin(name);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WmTraceBeginWithArgs(const char* format, ...)
|
||||
{
|
||||
if (WmTraceEnabled()) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
bool retVal = WmTraceBeginWithArgv(format, args);
|
||||
va_end(args);
|
||||
return retVal;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
WmScopedTrace::WmScopedTrace(const char* format, ...) : traceEnabled_(WmTraceEnabled())
|
||||
{
|
||||
if (traceEnabled_) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
traceEnabled_ = WmTraceBeginWithArgv(format, args);
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
|
||||
WmScopedTrace::~WmScopedTrace()
|
||||
{
|
||||
if (traceEnabled_) {
|
||||
WmTraceEnd();
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
@@ -11,11 +11,11 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
aafwk_inner_api_path =
|
||||
"//foundation/ability/ability_runtime/interfaces/inner_api"
|
||||
aafwk_kits_path = "//foundation/ability/ability_runtime/frameworks/kits"
|
||||
aafwk_path = "//foundation/ability/ability_runtime"
|
||||
aafwk_services_path = "//foundation/ability/ability_runtime/services"
|
||||
ability_runtime_path = "//foundation/ability/ability_runtime"
|
||||
ability_runtime_inner_api_path = "${ability_runtime_path}/interfaces/inner_api"
|
||||
ability_runtime_kits_path = "${ability_runtime_path}/frameworks/kits"
|
||||
ability_runtime_services_path = "${ability_runtime_path}/services"
|
||||
ability_runtime_napi_path = "${ability_runtime_path}/frameworks/js/napi"
|
||||
|
||||
declare_args() {
|
||||
suspend_manager_enable = true
|
||||
@@ -23,4 +23,4 @@ declare_args() {
|
||||
!defined(global_parts_info.resourceschedule_suspend_manager)) {
|
||||
suspend_manager_enable = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-6
@@ -20,9 +20,9 @@ config("libwm_private_config") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"../wmserver/include",
|
||||
"${aafwk_kits_path}/ability/ability_runtime/include",
|
||||
"${aafwk_inner_api_path}/ability_manager/include",
|
||||
"${aafwk_inner_api_path}/app_manager/include/appmgr",
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime",
|
||||
"${ability_runtime_inner_api_path}/ability_manager/include",
|
||||
"${ability_runtime_inner_api_path}/app_manager/include/appmgr",
|
||||
"//third_party/jsoncpp/include",
|
||||
"//third_party/json/include",
|
||||
]
|
||||
@@ -73,11 +73,11 @@ ohos_shared_library("libwm") {
|
||||
"ability_base:want",
|
||||
"ability_runtime:ability_context_native",
|
||||
"ability_runtime:ability_manager",
|
||||
"ace_engine_standard:ace_uicontent",
|
||||
"ace_engine:ace_uicontent",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"graphic_standard:surface",
|
||||
"graphic_standard:window_animation",
|
||||
"graphic_graphic_2d:surface",
|
||||
"graphic_graphic_2d:window_animation",
|
||||
"hilog_native:libhilog",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"input:libmmi-client",
|
||||
|
||||
@@ -41,20 +41,18 @@ public:
|
||||
virtual WMError RemoveWindow(uint32_t windowId);
|
||||
virtual WMError DestroyWindow(uint32_t windowId);
|
||||
virtual WMError RequestFocus(uint32_t windowId);
|
||||
virtual WMError GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type, std::vector<Rect>& avoidRect);
|
||||
virtual WMError GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type, AvoidArea& avoidRect);
|
||||
virtual WMError SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLevel level);
|
||||
virtual WMError SetAlpha(uint32_t windowId, float alpha);
|
||||
virtual WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId);
|
||||
virtual void ProcessPointDown(uint32_t windowId, bool isStartDrag = false);
|
||||
virtual void ProcessPointUp(uint32_t windowId);
|
||||
virtual void MinimizeAllAppWindows(DisplayId displayId);
|
||||
virtual WMError ToggleShownStateForAllAppWindows();
|
||||
virtual WMError MaxmizeWindow(uint32_t windowId);
|
||||
virtual WMError SetWindowLayoutMode(WindowLayoutMode mode);
|
||||
virtual WMError UpdateProperty(sptr<WindowProperty>& windowProperty, PropertyChangeAction action);
|
||||
virtual WMError GetSystemConfig(SystemConfig& systemConfig);
|
||||
virtual WMError GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones);
|
||||
|
||||
virtual WMError UpdateRsTree(uint32_t windowId, bool isAdd);
|
||||
virtual void RegisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
const sptr<IWindowManagerAgent>& windowManagerAgent);
|
||||
virtual void UnregisterWindowManagerAgent(WindowManagerAgentType type,
|
||||
@@ -62,6 +60,7 @@ public:
|
||||
|
||||
virtual WMError SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller);
|
||||
virtual WMError NotifyWindowTransition(sptr<WindowTransitionInfo> from, sptr<WindowTransitionInfo> to);
|
||||
virtual WMError UpdateAvoidAreaListener(uint32_t windowId, bool haveListener);
|
||||
virtual void ClearWindowAdapter();
|
||||
|
||||
virtual WMError GetAccessibilityWindowInfo(sptr<AccessibilityWindowInfo>& windowInfo);
|
||||
|
||||
@@ -29,8 +29,9 @@ public:
|
||||
~WindowAgent() = default;
|
||||
void UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason) override;
|
||||
void UpdateWindowMode(WindowMode mode) override;
|
||||
void UpdateWindowModeSupportInfo(uint32_t modeSupportInfo) override;
|
||||
void UpdateFocusStatus(bool focused) override;
|
||||
void UpdateAvoidArea(const std::vector<Rect>& avoidAreas) override;
|
||||
void UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type) override;
|
||||
void UpdateWindowState(WindowState state) override;
|
||||
void UpdateWindowDragInfo(const PointInfo& point, DragEvent event) override;
|
||||
void UpdateDisplayId(DisplayId from, DisplayId to) override;
|
||||
|
||||
+60
-16
@@ -34,6 +34,8 @@
|
||||
#include "wm_common_inner.h"
|
||||
#include "wm_common.h"
|
||||
|
||||
using OHOS::AppExecFwk::DisplayOrientation;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
union ColorParam {
|
||||
@@ -54,6 +56,23 @@ union ColorParam {
|
||||
#endif
|
||||
uint32_t value;
|
||||
};
|
||||
|
||||
const std::map<DisplayOrientation, Orientation> ABILITY_TO_WMS_ORIENTATION_MAP {
|
||||
{DisplayOrientation::UNSPECIFIED, Orientation::UNSPECIFIED },
|
||||
{DisplayOrientation::LANDSCAPE, Orientation::HORIZONTAL },
|
||||
{DisplayOrientation::PORTRAIT, Orientation::VERTICAL },
|
||||
{DisplayOrientation::FOLLOWRECENT, Orientation::UNSPECIFIED },
|
||||
{DisplayOrientation::LANDSCAPE_INVERTED, Orientation::REVERSE_HORIZONTAL },
|
||||
{DisplayOrientation::PORTRAIT_INVERTED, Orientation::REVERSE_VERTICAL },
|
||||
{DisplayOrientation::AUTO_ROTATION, Orientation::SENSOR },
|
||||
{DisplayOrientation::AUTO_ROTATION_LANDSCAPE, Orientation::SENSOR_HORIZONTAL },
|
||||
{DisplayOrientation::AUTO_ROTATION_PORTRAIT, Orientation::SENSOR_VERTICAL },
|
||||
{DisplayOrientation::AUTO_ROTATION_RESTRICTED, Orientation::AUTO_ROTATION_RESTRICTED },
|
||||
{DisplayOrientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED, Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED },
|
||||
{DisplayOrientation::AUTO_ROTATION_PORTRAIT_RESTRICTED, Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED },
|
||||
{DisplayOrientation::LOCKED, Orientation::LOCKED },
|
||||
};
|
||||
|
||||
class WindowImpl : public Window {
|
||||
using ListenerTaskCallback = std::function<void()>;
|
||||
using EventHandler = OHOS::AppExecFwk::EventHandler;
|
||||
@@ -97,7 +116,7 @@ public:
|
||||
virtual const std::string& GetWindowName() const override;
|
||||
virtual uint32_t GetWindowId() const override;
|
||||
virtual uint32_t GetWindowFlags() const override;
|
||||
uint32_t GetModeSupportInfo() const override;
|
||||
uint32_t GetRequestModeSupportInfo() const override;
|
||||
inline NotifyNativeWinDestroyFunc GetNativeDestroyCallback()
|
||||
{
|
||||
return notifyNativefunc_;
|
||||
@@ -108,13 +127,16 @@ public:
|
||||
virtual WMError SetWindowType(WindowType type) override;
|
||||
virtual WMError SetWindowMode(WindowMode mode) override;
|
||||
virtual WMError SetWindowBackgroundBlur(WindowBlurLevel level) override;
|
||||
virtual WMError SetAlpha(float alpha) override;
|
||||
virtual void SetAlpha(float alpha) override;
|
||||
virtual void SetTransform(const Transform& trans) override;
|
||||
virtual WMError AddWindowFlag(WindowFlag flag) override;
|
||||
virtual WMError RemoveWindowFlag(WindowFlag flag) override;
|
||||
virtual WMError SetWindowFlags(uint32_t flags) override;
|
||||
virtual WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) override;
|
||||
virtual WMError SetLayoutFullScreen(bool status) override;
|
||||
virtual WMError SetFullScreen(bool status) override;
|
||||
virtual Transform GetTransform() const override;
|
||||
virtual WMError UpdateSurfaceNodeAfterCustomAnimation(bool isAdd) override;
|
||||
inline void SetWindowState(WindowState state)
|
||||
{
|
||||
state_ = state;
|
||||
@@ -124,8 +146,8 @@ public:
|
||||
WMError Create(const std::string& parentName,
|
||||
const std::shared_ptr<AbilityRuntime::Context>& context = nullptr);
|
||||
virtual WMError Destroy() override;
|
||||
virtual WMError Show(uint32_t reason = 0) override;
|
||||
virtual WMError Hide(uint32_t reason = 0) override;
|
||||
virtual WMError Show(uint32_t reason = 0, bool withAnimation = false) override;
|
||||
virtual WMError Hide(uint32_t reason = 0, bool withAnimation = false) override;
|
||||
virtual WMError MoveTo(int32_t x, int32_t y) override;
|
||||
virtual WMError Resize(uint32_t width, uint32_t height) override;
|
||||
virtual WMError SetKeepScreenOn(bool keepScreenOn) override;
|
||||
@@ -151,10 +173,11 @@ public:
|
||||
|
||||
virtual WMError RequestFocus() const override;
|
||||
virtual void AddInputEventListener(const std::shared_ptr<MMI::IInputEventConsumer>& inputEventListener) override;
|
||||
virtual void SetInputEventConsumer(const std::shared_ptr<IInputEventConsumer>& inputEventConsumer) override;
|
||||
|
||||
virtual void RegisterLifeCycleListener(sptr<IWindowLifeCycle>& listener) override;
|
||||
virtual void RegisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener) override;
|
||||
virtual void RegisterWindowChangeListener(sptr<IWindowChangeListener>& listener) override;
|
||||
virtual void UnregisterLifeCycleListener(sptr<IWindowLifeCycle>& listener) override;
|
||||
virtual void UnregisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener) override;
|
||||
virtual void UnregisterWindowChangeListener(sptr<IWindowChangeListener>& listener) override;
|
||||
virtual void RegisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) override;
|
||||
virtual void UnregisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) override;
|
||||
@@ -162,23 +185,25 @@ public:
|
||||
virtual void UnregisterDragListener(const sptr<IWindowDragListener>& listener) override;
|
||||
virtual void RegisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) override;
|
||||
virtual void UnregisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) override;
|
||||
virtual void RegisterInputEventListener(sptr<IInputEventListener>& listener) override;
|
||||
virtual void UnregisterInputEventListener(sptr<IInputEventListener>& listener) override;
|
||||
virtual void RegisterInputEventListener(const sptr<IInputEventListener>& listener) override;
|
||||
virtual void UnregisterInputEventListener(const sptr<IInputEventListener>& listener) override;
|
||||
virtual void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) override;
|
||||
virtual void RegisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) override;
|
||||
virtual void UnregisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) override;
|
||||
virtual void RegisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener) override;
|
||||
virtual void UnregisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener) override;
|
||||
virtual void RegisterAnimationTransitionController(const sptr<IAnimationTransitionController>& listener) override;
|
||||
virtual void SetAceAbilityHandler(const sptr<IAceAbilityHandler>& handler) override;
|
||||
virtual void SetModeSupportInfo(uint32_t modeSupportInfo) override;
|
||||
virtual void SetRequestModeSupportInfo(uint32_t modeSupportInfo) override;
|
||||
void UpdateRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason);
|
||||
void UpdateMode(WindowMode mode);
|
||||
void UpdateModeSupportInfo(uint32_t modeSupportInfo);
|
||||
virtual void ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent>& inputEvent) override;
|
||||
virtual void ConsumePointerEvent(std::shared_ptr<MMI::PointerEvent>& inputEvent) override;
|
||||
virtual void RequestFrame() override;
|
||||
void UpdateFocusStatus(bool focused);
|
||||
virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
|
||||
void UpdateAvoidArea(const std::vector<Rect>& avoidAreas);
|
||||
void UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type);
|
||||
void UpdateWindowState(WindowState state);
|
||||
sptr<WindowProperty> GetWindowProperty();
|
||||
void UpdateDragEvent(const PointInfo& point, DragEvent event);
|
||||
@@ -189,7 +214,7 @@ public:
|
||||
void NotifySizeChange(Rect rect, WindowSizeChangeReason reason);
|
||||
void NotifyKeyEvent(std::shared_ptr<MMI::KeyEvent> &keyEvent);
|
||||
void NotifyPointEvent(std::shared_ptr<MMI::PointerEvent>& pointerEvent);
|
||||
void NotifyAviodAreaChange(const std::vector<Rect>& avoidArea);
|
||||
void NotifyAvoidAreaChange(const sptr<AvoidArea>& avoidArea, AvoidAreaType type);
|
||||
void NotifyDisplayMoveChange(DisplayId from, DisplayId to);
|
||||
void NotifyOccupiedAreaChange(const sptr<OccupiedAreaChangeInfo>& info);
|
||||
void NotifyModeChange(WindowMode mode);
|
||||
@@ -253,7 +278,11 @@ private:
|
||||
}
|
||||
inline void NotifyBeforeDestroy(std::string windowName)
|
||||
{
|
||||
CALL_UI_CONTENT(Destroy);
|
||||
if (uiContent_ != nullptr) {
|
||||
auto uiContent = std::move(uiContent_);
|
||||
uiContent_ = nullptr;
|
||||
uiContent->Destroy();
|
||||
}
|
||||
if (notifyNativefunc_) {
|
||||
notifyNativefunc_(windowName);
|
||||
}
|
||||
@@ -286,6 +315,12 @@ private:
|
||||
CALL_LIFECYCLE_LISTENER(ForegroundFailed);
|
||||
});
|
||||
}
|
||||
inline void NotifyForegroundInvalidWindowMode()
|
||||
{
|
||||
PostListenerTask([this]() {
|
||||
CALL_LIFECYCLE_LISTENER(ForegroundInvalidMode);
|
||||
});
|
||||
}
|
||||
void DestroyFloatingWindow();
|
||||
void DestroySubWindow();
|
||||
void SetDefaultOption(); // for api7
|
||||
@@ -299,7 +334,7 @@ private:
|
||||
void ReadyToMoveOrDragWindow(int32_t globalX, int32_t globalY, int32_t pointId, const Rect& rect);
|
||||
void EndMoveOrDragWindow(int32_t posX, int32_t posY, int32_t pointId);
|
||||
bool IsPointerEventConsumed();
|
||||
void AdjustWindowAnimationFlag();
|
||||
void AdjustWindowAnimationFlag(bool withAnimation = false);
|
||||
void MapFloatingWindowToAppIfNeeded();
|
||||
WMError UpdateProperty(PropertyChangeAction action);
|
||||
WMError Destroy(bool needNotifyServer);
|
||||
@@ -310,14 +345,21 @@ private:
|
||||
Rect GetSystemAlarmWindowDefaultSize(Rect defaultRect);
|
||||
void HandleModeChangeHotZones(int32_t posX, int32_t posY);
|
||||
WMError NotifyWindowTransition(TransitionReason reason);
|
||||
void UpdatePointerEvent(std::shared_ptr<MMI::PointerEvent>& pointerEvent);
|
||||
void UpdatePointerEventForStretchableWindow(std::shared_ptr<MMI::PointerEvent>& pointerEvent);
|
||||
void UpdateDragType();
|
||||
void InitListenerHandler();
|
||||
|
||||
void HandleBackKeyPressedEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent);
|
||||
bool CheckCameraFloatingWindowMultiCreated(WindowType type);
|
||||
void GetConfigurationFromAbilityInfo();
|
||||
void UpdateTitleButtonVisibility();
|
||||
void SetModeSupportInfo(uint32_t modeSupportInfo);
|
||||
uint32_t GetModeSupportInfo() const;
|
||||
WMError PreProcessShow(uint32_t reason, bool withAnimation);
|
||||
// colorspace, gamut
|
||||
using ColorSpaceConvertMap = struct {
|
||||
ColorSpace colorSpace;
|
||||
ColorGamut sufaceColorGamut;
|
||||
ColorGamut surfaceColorGamut;
|
||||
};
|
||||
static const ColorSpaceConvertMap colorSpaceConvertMap[];
|
||||
static ColorSpace GetColorSpaceFromSurfaceGamut(ColorGamut ColorGamut);
|
||||
@@ -340,6 +382,8 @@ private:
|
||||
std::vector<sptr<IDisplayMoveListener>> displayMoveListeners_;
|
||||
std::vector<sptr<IOccupiedAreaChangeListener>> occupiedAreaChangeListeners_;
|
||||
std::vector<sptr<IInputEventListener>> inputEventListeners_;
|
||||
std::shared_ptr<IInputEventConsumer> inputEventConsumer_;
|
||||
sptr<IAnimationTransitionController> animationTranistionController_;
|
||||
NotifyNativeWinDestroyFunc notifyNativefunc_;
|
||||
std::shared_ptr<RSSurfaceNode> surfaceNode_;
|
||||
std::string name_;
|
||||
@@ -360,7 +404,7 @@ private:
|
||||
Rect startRectExceptFrame_ = { 0, 0, 0, 0 };
|
||||
Rect startRectExceptCorner_ = { 0, 0, 0, 0 };
|
||||
DragType dragType_ = DragType::DRAG_UNDEFINED;
|
||||
bool isAppDecorEnbale_ = true;
|
||||
bool isAppDecorEnable_ = true;
|
||||
SystemConfig windowSystemConfig_ ;
|
||||
bool isOriginRectSet_ = false;
|
||||
bool isWaitingFrame_ = false;
|
||||
|
||||
@@ -30,6 +30,7 @@ public:
|
||||
void UpdateSystemBarRegionTints(DisplayId displayId, const SystemBarRegionTints& props) override;
|
||||
void NotifyAccessibilityWindowInfo(const sptr<AccessibilityWindowInfo>& windowInfo, WindowUpdateType type) override;
|
||||
void UpdateWindowVisibilityInfo(const std::vector<sptr<WindowVisibilityInfo>>& visibilityInfos) override;
|
||||
void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) override;
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -31,6 +31,7 @@ public:
|
||||
enum class WindowMessage : uint32_t {
|
||||
TRANS_ID_UPDATE_WINDOW_RECT,
|
||||
TRANS_ID_UPDATE_WINDOW_MODE,
|
||||
TRANS_ID_UPDATE_MODE_SUPPORT_INFO,
|
||||
TRANS_ID_UPDATE_FOCUS_STATUS,
|
||||
TRANS_ID_UPDATE_AVOID_AREA,
|
||||
TRANS_ID_UPDATE_WINDOW_STATE,
|
||||
@@ -45,8 +46,9 @@ public:
|
||||
|
||||
virtual void UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason) = 0;
|
||||
virtual void UpdateWindowMode(WindowMode mode) = 0;
|
||||
virtual void UpdateWindowModeSupportInfo(uint32_t modeSupportInfo) = 0;
|
||||
virtual void UpdateFocusStatus(bool focused) = 0;
|
||||
virtual void UpdateAvoidArea(const std::vector<Rect>& avoidAreas) = 0;
|
||||
virtual void UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type) = 0;
|
||||
virtual void UpdateWindowState(WindowState state) = 0;
|
||||
virtual void UpdateWindowDragInfo(const PointInfo& point, DragEvent event) = 0;
|
||||
virtual void UpdateDisplayId(DisplayId from, DisplayId to) = 0;
|
||||
|
||||
@@ -27,6 +27,7 @@ enum class WindowManagerAgentType : uint32_t {
|
||||
WINDOW_MANAGER_AGENT_TYPE_SYSTEM_BAR,
|
||||
WINDOW_MANAGER_AGENT_TYPE_WINDOW_UPDATE,
|
||||
WINDOW_MANAGER_AGENT_TYPE_WINDOW_VISIBILITY,
|
||||
WINDOW_MANAGER_AGENT_TYPE_CAMERA_FLOAT,
|
||||
};
|
||||
|
||||
class IWindowManagerAgent : public IRemoteBroker {
|
||||
@@ -38,6 +39,7 @@ public:
|
||||
TRANS_ID_UPDATE_SYSTEM_BAR_PROPS,
|
||||
TRANS_ID_UPDATE_WINDOW_STATUS,
|
||||
TRANS_ID_UPDATE_WINDOW_VISIBILITY,
|
||||
TRANS_ID_UPDATE_CAMERA_FLOAT,
|
||||
};
|
||||
|
||||
virtual void UpdateFocusChangeInfo(const sptr<FocusChangeInfo>& focusChangeInfo, bool focused) = 0;
|
||||
@@ -45,6 +47,7 @@ public:
|
||||
virtual void NotifyAccessibilityWindowInfo(const sptr<AccessibilityWindowInfo>& windowInfo,
|
||||
WindowUpdateType type) = 0;
|
||||
virtual void UpdateWindowVisibilityInfo(const std::vector<sptr<WindowVisibilityInfo>>& visibilityInfos) = 0;
|
||||
virtual void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) = 0;
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -31,6 +31,7 @@ public:
|
||||
void UpdateSystemBarRegionTints(DisplayId displayId, const SystemBarRegionTints& tints) override;
|
||||
void NotifyAccessibilityWindowInfo(const sptr<AccessibilityWindowInfo>& windowInfo, WindowUpdateType type) override;
|
||||
void UpdateWindowVisibilityInfo(const std::vector<sptr<WindowVisibilityInfo>>& visibilityInfos) override;
|
||||
void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) override;
|
||||
|
||||
private:
|
||||
static inline BrokerDelegator<WindowManagerAgentProxy> delegator_;
|
||||
|
||||
@@ -30,8 +30,9 @@ public:
|
||||
|
||||
void UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason) override;
|
||||
void UpdateWindowMode(WindowMode mode) override;
|
||||
void UpdateWindowModeSupportInfo(uint32_t modeSupportInfo) override;
|
||||
void UpdateFocusStatus(bool focused) override;
|
||||
void UpdateAvoidArea(const std::vector<Rect>& avoidAreas) override;
|
||||
void UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type) override;
|
||||
void UpdateWindowState(WindowState state) override;
|
||||
void UpdateWindowDragInfo(const PointInfo& point, DragEvent event) override;
|
||||
void UpdateDisplayId(DisplayId from, DisplayId to) override;
|
||||
|
||||
+14
-17
@@ -99,11 +99,10 @@ WMError WindowAdapter::SetWindowAnimationController(const sptr<RSIWindowAnimatio
|
||||
return windowManagerServiceProxy_->SetWindowAnimationController(controller);
|
||||
}
|
||||
|
||||
WMError WindowAdapter::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type, std::vector<Rect>& avoidRect)
|
||||
WMError WindowAdapter::GetAvoidAreaByType(uint32_t windowId, AvoidAreaType type, AvoidArea& avoidArea)
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
|
||||
|
||||
avoidRect = windowManagerServiceProxy_->GetAvoidAreaByType(windowId, type);
|
||||
avoidArea = windowManagerServiceProxy_->GetAvoidAreaByType(windowId, type);
|
||||
return WMError::WM_OK;
|
||||
}
|
||||
|
||||
@@ -114,13 +113,6 @@ WMError WindowAdapter::SetWindowBackgroundBlur(uint32_t windowId, WindowBlurLeve
|
||||
return windowManagerServiceProxy_->SetWindowBackgroundBlur(windowId, level);
|
||||
}
|
||||
|
||||
WMError WindowAdapter::SetAlpha(uint32_t windowId, float alpha)
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
|
||||
|
||||
return windowManagerServiceProxy_->SetAlpha(windowId, alpha);
|
||||
}
|
||||
|
||||
void WindowAdapter::ProcessPointDown(uint32_t windowId, bool isStartDrag)
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN();
|
||||
@@ -149,13 +141,6 @@ WMError WindowAdapter::ToggleShownStateForAllAppWindows()
|
||||
return windowManagerServiceProxy_->ToggleShownStateForAllAppWindows();
|
||||
}
|
||||
|
||||
WMError WindowAdapter::MaxmizeWindow(uint32_t windowId)
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
|
||||
|
||||
return windowManagerServiceProxy_->MaxmizeWindow(windowId);
|
||||
}
|
||||
|
||||
WMError WindowAdapter::GetSystemConfig(SystemConfig& systemConfig)
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
|
||||
@@ -265,5 +250,17 @@ void WindowAdapter::MinimizeWindowsByLauncher(std::vector<uint32_t> windowIds, b
|
||||
windowManagerServiceProxy_->MinimizeWindowsByLauncher(windowIds, isAnimated, finishCallback);
|
||||
return;
|
||||
}
|
||||
|
||||
WMError WindowAdapter::UpdateAvoidAreaListener(uint32_t windowId, bool haveListener)
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
|
||||
return windowManagerServiceProxy_->UpdateAvoidAreaListener(windowId, haveListener);
|
||||
}
|
||||
|
||||
WMError WindowAdapter::UpdateRsTree(uint32_t windowId, bool isAdd)
|
||||
{
|
||||
INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR);
|
||||
return windowManagerServiceProxy_->UpdateRsTree(windowId, isAdd);
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
+13
-4
@@ -46,6 +46,15 @@ void WindowAgent::UpdateWindowMode(WindowMode mode)
|
||||
window_->UpdateMode(mode);
|
||||
}
|
||||
|
||||
void WindowAgent::UpdateWindowModeSupportInfo(uint32_t modeSupportInfo)
|
||||
{
|
||||
if (window_ == nullptr) {
|
||||
WLOGFE("window_ is nullptr");
|
||||
return;
|
||||
}
|
||||
window_->UpdateModeSupportInfo(modeSupportInfo);
|
||||
}
|
||||
|
||||
void WindowAgent::UpdateFocusStatus(bool focused)
|
||||
{
|
||||
if (window_ == nullptr) {
|
||||
@@ -55,13 +64,13 @@ void WindowAgent::UpdateFocusStatus(bool focused)
|
||||
window_->UpdateFocusStatus(focused);
|
||||
}
|
||||
|
||||
void WindowAgent::UpdateAvoidArea(const std::vector<Rect>& avoidArea)
|
||||
void WindowAgent::UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type)
|
||||
{
|
||||
if (window_ == nullptr) {
|
||||
WLOGFE("window_ is nullptr");
|
||||
if (window_ == nullptr || avoidArea == nullptr) {
|
||||
WLOGFE("window_ or avoidArea is nullptr.");
|
||||
return;
|
||||
}
|
||||
window_->UpdateAvoidArea(avoidArea);
|
||||
window_->UpdateAvoidArea(avoidArea, type);
|
||||
}
|
||||
|
||||
void WindowAgent::UpdateWindowState(WindowState state)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user