add windowmanager & add window js api

Signed-off-by: laiguizhong <laiguizhong@huawei.com>
Change-Id: Ia303d155a0d30da4736e96b009125f40d4c3837a
This commit is contained in:
laiguizhong
2022-01-06 21:01:15 +08:00
parent 57e081b521
commit 49486f0153
107 changed files with 4081 additions and 763 deletions
+8 -15
View File
@@ -13,8 +13,8 @@
import("//build/ohos.gni")
## Build libwmadaptertest.so {{{
config("libwmadaptertest_config") {
## Build libwmadapter.so {{{
config("libwmadapter_config") {
visibility = [ ":*" ]
include_dirs = [
@@ -37,16 +37,12 @@ config("libwmadaptertest_config") {
"//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content",
"//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include",
"//foundation/aafwk/standard/interfaces/innerkits/base/include",
]
cflags = [
"-Wall",
"-Werror",
"-g3",
"//third_party/jsoncpp/include",
"//third_party/json/include",
]
}
config("libwmadaptertest_public_config") {
config("libwmadapter_public_config") {
include_dirs = [
"//foundation/graphic/standard/interfaces/innerkits/wmclient",
"//foundation/windowmanager/interfaces/innerkits/wm",
@@ -56,12 +52,12 @@ config("libwmadaptertest_public_config") {
]
}
ohos_shared_library("libwmadaptertest") {
ohos_shared_library("libwmadapter") {
sources = [ "src/adapter.cpp" ]
configs = [ ":libwmadaptertest_config" ]
configs = [ ":libwmadapter_config" ]
public_configs = [ ":libwmadaptertest_public_config" ]
public_configs = [ ":libwmadapter_public_config" ]
deps = [
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
@@ -77,9 +73,6 @@ ohos_shared_library("libwmadaptertest") {
# ace
"//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent",
# aafwk
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
]
public_deps = [
+1 -1
View File
@@ -27,7 +27,7 @@
#include "wm_common.h"
#include "window.h"
#include "foundation/graphic/standard/interfaces/innerkits/wmclient/window_option.h"
#include "window_manager.h"
#include "foundation/graphic/standard/interfaces/innerkits/wmclient/window_manager.h"
#include "window_manager_hilog.h"
namespace OHOS {
+8 -5
View File
@@ -17,7 +17,7 @@
#define FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H
#include <map>
#include <refbase.h>
#include <surface.h>
#include "display.h"
#include "display_manager_interface.h"
@@ -30,13 +30,16 @@ public:
virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override;
};
class DisplayManagerAdapter : public RefBase {
DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerAdapter);
class DisplayManagerAdapter {
DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerAdapter);
public:
sptr<Display> GetDisplay(DisplayType type);
DisplayId GetDefaultDisplayId();
sptr<Display> GetDisplayById(DisplayId displayId);
DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo,
sptr<Surface> surface);
bool DestroyVirtualDisplay(DisplayId displayId);
// TODO: fix me
// sptr<Media::PixelMap> GetDisplaySnapshot(DisplayId displayId);
void Clear();
private:
DisplayManagerAdapter() = default;
+51 -32
View File
@@ -15,7 +15,7 @@
#include "display_manager.h"
#include <inttypes.h>
#include <cinttypes>
#include "display_manager_adapter.h"
#include "window_manager_hilog.h"
@@ -25,43 +25,14 @@ namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManager"};
}
IMPLEMENT_SINGLE_INSTANCE(DisplayManager);
DisplayManager::DisplayManager()
{
dmsAdapter_ = SingletonContainer::Get<DisplayManagerAdapter>();
}
DisplayManager::~DisplayManager()
{
}
const sptr<Display>& DisplayManager::GetDisplay(const DisplayType type)
{
if (dmsAdapter_ == nullptr) {
WLOGFE("DisplayManager::GetDisplay null!");
return nullptr;
}
return dmsAdapter_->GetDisplay(type);
}
DisplayId DisplayManager::GetDefaultDisplayId()
{
if (dmsAdapter_ == nullptr) {
WLOGFE("DisplayManager::GetDefaultDisplayId null!\n");
return DISPLAY_ID_INVALD;
}
return dmsAdapter_->GetDefaultDisplayId();
return SingletonContainer::Get<DisplayManagerAdapter>().GetDefaultDisplayId();
}
const sptr<Display> DisplayManager::GetDisplayById(DisplayId displayId)
{
if (dmsAdapter_ == nullptr) {
WLOGFE("DisplayManager::GetDisplayById null!\n");
return nullptr;
}
sptr<Display> display = dmsAdapter_->GetDisplayById(displayId);
sptr<Display> display = SingletonContainer::Get<DisplayManagerAdapter>().GetDisplayById(displayId);
if (display == nullptr) {
WLOGFE("DisplayManager::GetDisplayById failed!\n");
return nullptr;
@@ -69,6 +40,40 @@ const sptr<Display> DisplayManager::GetDisplayById(DisplayId displayId)
return display;
}
// TODO: fix me
// sptr<Media::PixelMap> DisplayManager::GetScreenshot(DisplayId displayId)
// {
// sptr<Media::PixelMap> screenShot = SingletonContainer::Get<DisplayManagerAdapter>().GetDisplaySnapshot(displayId);
// if (screenShot == nullptr) {
// WLOGFE("DisplayManager::GetScreenshot failed!\n");
// return nullptr;
// }
// return screenShot;
// }
// sptr<Media::PixelMap> DisplayManager::GetScreenshot(DisplayId displayId, const Media::Rect &rect,
// const Media::Size &size, int rotation)
// {
// sptr<Media::PixelMap> screenShot = SingletonContainer::Get<DisplayManagerAdapter>().GetDisplaySnapshot(displayId);
// if (screenShot == nullptr) {
// WLOGFE("DisplayManager::GetScreenshot failed!\n");
// return nullptr;
// }
// // create crop dest pixelmap
// Media::InitializationOptions opt;
// opt.size.width = size.width;
// opt.size.height = size.height;
// opt.scaleMode = Media::ScaleMode::FIT_TARGET_SIZE;
// opt.editable = false;
// opt.useSourceIfMatch = true;
// auto dstScreenshot = Media::PixelMap::Create(*screenShot, rect, opt);
// sptr<Media::PixelMap> dstScreenshot_ = dstScreenshot.release();
// return dstScreenshot_;
// }
const sptr<Display> DisplayManager::GetDefaultDisplay()
{
@@ -97,4 +102,18 @@ std::vector<const sptr<Display>> DisplayManager::GetAllDisplays()
}
return res;
}
DisplayId DisplayManager::CreateVirtualDisplay(const std::string &name, uint32_t width, uint32_t height,
sptr<Surface> surface, DisplayId displayIdToMirror, int32_t flags)
{
WLOGFI("DisplayManager::CreateVirtualDisplay multi params");
VirtualDisplayInfo info(name, width, height, displayIdToMirror, flags);
return SingletonContainer::Get<DisplayManagerAdapter>().CreateVirtualDisplay(info, surface);
}
bool DisplayManager::DestroyVirtualDisplay(DisplayId displayId)
{
WLOGFI("DisplayManager::DestroyVirtualDisplay override params");
return SingletonContainer::Get<DisplayManagerAdapter>().DestroyVirtualDisplay(displayId);
}
} // namespace OHOS::Rosen
+35 -16
View File
@@ -27,21 +27,6 @@ namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerAdapter"};
}
IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAdapter);
sptr<Display> DisplayManagerAdapter::GetDisplay(DisplayType type)
{
std::lock_guard<std::mutex> lock(mutex_);
if (!InitDMSProxyLocked()) {
WLOGFE("displayManagerAdapter::GetDisplay: InitDMSProxyLocked failed!");
return nullptr;
}
sptr<DisplayInfo> info = displayManagerServiceProxy_->GetDisplayInfo(type);
// TODO DisplayInfo内容更新到对应的Display.displayInfo_. auto iter = displayMap_.find(info.id_);
return nullptr;
}
DisplayId DisplayManagerAdapter::GetDefaultDisplayId()
{
std::lock_guard<std::mutex> lock(mutex_);
@@ -79,6 +64,40 @@ sptr<Display> DisplayManagerAdapter::GetDisplayById(DisplayId displayId)
return display;
}
// TODO: fix me
// sptr<Media::PixelMap> DisplayManagerAdapter::GetDisplaySnapshot(DisplayId displayId)
// {
// std::lock_guard<std::mutex> lock(mutex_);
// if (!InitDMSProxyLocked()) {
// WLOGFE("displayManagerAdapter::GetDisplaySnapshot: InitDMSProxyLocked failed!");
// return nullptr;
// }
// sptr<Media::PixelMap> dispalySnapshot = displayManagerServiceProxy_->GetDispalySnapshot(displayId);
// return dispalySnapshot;
// }
DisplayId DisplayManagerAdapter::CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo,
sptr<Surface> surface)
{
if (!InitDMSProxyLocked()) {
return DISPLAY_ID_INVALD;
}
WLOGFI("DisplayManagerAdapter::CreateVirtualDisplay");
return displayManagerServiceProxy_->CreateVirtualDisplay(virtualDisplayInfo, surface);
}
bool DisplayManagerAdapter::DestroyVirtualDisplay(DisplayId displayId)
{
if (!InitDMSProxyLocked()) {
return false;
}
WLOGFI("DisplayManagerAdapter::DestroyVirtualDisplay");
return displayManagerServiceProxy_->DestroyVirtualDisplay(displayId);
}
bool DisplayManagerAdapter::InitDMSProxyLocked()
{
WLOGFI("InitDMSProxy");
@@ -128,7 +147,7 @@ void DMSDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
WLOGFE("object is null");
return;
}
SingletonContainer::Get<DisplayManagerAdapter>().GetRefPtr()->Clear();
SingletonContainer::Get<DisplayManagerAdapter>().Clear();
return;
}
@@ -13,17 +13,17 @@
* limitations under the License.
*/
#ifndef FOUNDATION_DMSERVER_DISPLAY_SCREEN_H
#define FOUNDATION_DMSERVER_DISPLAY_SCREEN_H
#ifndef FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H
#define FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H
#include <refbase.h>
#include "display_info.h"
namespace OHOS::Rosen {
class DisplayScreen : public RefBase {
class AbstractDisplay : public RefBase {
public:
DisplayScreen(const DisplayInfo& info);
~DisplayScreen() = default;
AbstractDisplay(const DisplayInfo& info);
~AbstractDisplay() = default;
DisplayId GetId() const;
int32_t GetWidth() const;
@@ -42,4 +42,4 @@ private:
uint32_t freshRate_ {0};
};
} // namespace OHOS::Rosen
#endif // FOUNDATION_DMSERVER_DISPLAY_SCREEN_H
#endif // FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_H
@@ -13,32 +13,36 @@
* limitations under the License.
*/
#ifndef FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H
#define FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H
#ifndef FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_MANAGER_H
#define FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_MANAGER_H
#include <map>
#include <refbase.h>
#include <surface.h>
#include "display_screen.h"
#include "abstract_display.h"
#include "single_instance.h"
#include "transaction/rs_interfaces.h"
#include "virtual_display_info.h"
namespace OHOS::Rosen {
class DisplayScreenManager : public RefBase {
DECLARE_SINGLE_INSTANCE_BASE(DisplayScreenManager);
class AbstractDisplayManager {
DECLARE_SINGLE_INSTANCE_BASE(AbstractDisplayManager);
public:
std::map<int32_t, sptr<DisplayScreen>> displayScreenMap_;
std::map<int32_t, sptr<AbstractDisplay>> abstractDisplayMap_;
ScreenId GetDefaultScreenId();
RSScreenModeInfo GetScreenActiveMode(ScreenId id);
ScreenId CreateVirtualScreen(const VirtualDisplayInfo &virtualDisplayInfo, sptr<Surface> surface);
bool DestroyVirtualScreen(ScreenId screenId);
// TODO: fix me
// sptr<Media::PixelMap> GetScreenSnapshot(ScreenId screenId);
private:
DisplayScreenManager();
~DisplayScreenManager();
AbstractDisplayManager();
~AbstractDisplayManager();
void parepareRSScreenManger();
OHOS::Rosen::RSInterfaces *rsInterface_;
};
} // namespace OHOS::Rosen
#endif // FOUNDATION_DMSERVER_DISPLAY_SCREEN_MANAGER_H
#endif // FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_MANAGER_H
+18 -5
View File
@@ -18,23 +18,36 @@
#include <iremote_broker.h>
#include <surface.h>
#include "display_info.h"
#include "virtual_display_info.h"
// #include "pixel_map.h"
namespace OHOS::Rosen {
class IDisplayManager : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IDisplayManager");
enum {
TRANS_ID_GET_DISPLAY_INFO = 1,
TRANS_ID_GET_DEFAULT_DISPLAY_ID = 2,
TRANS_ID_GET_DISPLAY_BY_ID = 3,
TRANS_ID_GET_DEFAULT_DISPLAY_ID = 0,
TRANS_ID_GET_DISPLAY_BY_ID,
TRANS_ID_CREATE_VIRTUAL_DISPLAY,
TRANS_ID_DESTROY_VIRTUAL_DISPLAY,
// TODO: fix me
// TRANS_ID_GET_DISPLAY_SNAPSHOT,
};
virtual const sptr<DisplayInfo>& GetDisplayInfo(const DisplayType type) = 0;
virtual DisplayId GetDefaultDisplayId() = 0;
virtual DisplayInfo GetDisplayInfoById(DisplayId displayId) = 0;
virtual DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo,
sptr<Surface> surface) = 0;
virtual bool DestroyVirtualDisplay(DisplayId displayId) = 0;
// TODO: fix me
// virtual sptr<Media::PixelMap> GetDispalySnapshot(DisplayId displayId) = 0;
};
} // namespace OHOS::Rosen
+6 -2
View File
@@ -27,10 +27,14 @@ public:
: IRemoteProxy<IDisplayManager>(impl) {};
~DisplayManagerProxy() {};
const sptr<DisplayInfo>& GetDisplayInfo(const DisplayType type) override;
DisplayId GetDefaultDisplayId() override;
DisplayInfo GetDisplayInfoById(DisplayId displayId) override;
DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo,
sptr<Surface> surface) override;
bool DestroyVirtualDisplay(DisplayId displayId) override;
// TODO: fix me
// sptr<Media::PixelMap> GetDispalySnapshot(DisplayId displayId) override;
private:
static inline BrokerDelegator<DisplayManagerProxy> delegator_;
};
+9 -6
View File
@@ -20,12 +20,13 @@
#include <mutex>
#include <system_ability.h>
#include <surface.h>
#include "abstract_display.h"
#include "abstract_display_manager.h"
#include "display_manager_stub.h"
#include "display_screen.h"
#include "single_instance.h"
#include "singleton_delegator.h"
#include "display_screen_manager.h"
namespace OHOS::Rosen {
class DisplayManagerService : public SystemAbility, public DisplayManagerStub {
@@ -36,11 +37,14 @@ DECLARE_SINGLE_INSTANCE_BASE(DisplayManagerService);
public:
void OnStart() override;
void OnStop() override;
const sptr<DisplayInfo>& GetDisplayInfo(const DisplayType type) override;
DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo,
sptr<Surface> surface) override;
bool DestroyVirtualDisplay(DisplayId displayId) override;
DisplayId GetDefaultDisplayId() override;
DisplayInfo GetDisplayInfoById(DisplayId displayId) override;
// TODO: fix me
// sptr<Media::PixelMap> GetDispalySnapshot(DisplayId displayId) override;
private:
DisplayManagerService();
~DisplayManagerService() = default;
@@ -49,8 +53,7 @@ private:
ScreenId GetScreenIdFromDisplayId(DisplayId displayId);
static inline SingletonDelegator<DisplayManagerService> delegator_;
std::map<int32_t, sptr<DisplayScreen>> displayScreenMap_;
sptr<DisplayScreenManager> displayScreenManager_;
std::map<int32_t, sptr<AbstractDisplay>> abstractDisplayMap_;
};
} // namespace OHOS::Rosen
@@ -19,19 +19,19 @@
#include <vector>
#include <system_ability.h>
#include "display_screen.h"
#include "abstract_display.h"
#include "single_instance.h"
#include "singleton_delegator.h"
namespace OHOS::Rosen {
class DisplayManagerServiceInner : public RefBase {
class DisplayManagerServiceInner {
DECLARE_SINGLE_INSTANCE(DisplayManagerServiceInner);
public:
std::vector<const sptr<DisplayScreen>> GetAllDisplays();
std::vector<const sptr<AbstractDisplay>> GetAllDisplays();
DisplayId GetDefaultDisplayId();
const sptr<DisplayScreen> GetDefaultDisplay();
const sptr<DisplayScreen> GetDisplayById(DisplayId displayId);
const sptr<AbstractDisplay> GetDefaultDisplay();
const sptr<AbstractDisplay> GetDisplayById(DisplayId displayId);
std::vector<DisplayId> GetAllDisplayIds();
};
} // namespace OHOS::Rosen
+46
View File
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2021 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 FOUNDATION_VIRTUAL_DISPLAY_INFO_H
#define FOUNDATION_VIRTUAL_DISPLAY_INFO_H
#include <refbase.h>
#include <string>
#include <parcel.h>
#include "display.h"
namespace OHOS::Rosen {
class VirtualDisplayInfo : public Parcelable {
public:
VirtualDisplayInfo();
VirtualDisplayInfo(const std::string &name, uint32_t width, uint32_t height,
DisplayId displayIdToMirror, int32_t flags);
~VirtualDisplayInfo() = default;
virtual bool Marshalling(Parcel& parcel) const override;
static VirtualDisplayInfo* Unmarshalling(Parcel& parcel);
std::string name_;
uint32_t width_;
uint32_t height_;
DisplayId displayIdToMirror_;
int32_t flags_;
};
} // namespace OHOS::Rosen
#endif // FOUNDATION_VIRTUAL_DISPLAY_INFO_H
@@ -13,10 +13,10 @@
* limitations under the License.
*/
#include "display_screen.h"
#include "abstract_display.h"
namespace OHOS::Rosen {
DisplayScreen::DisplayScreen(const DisplayInfo& info)
AbstractDisplay::AbstractDisplay(const DisplayInfo& info)
: id_(info.id_),
width_(info.width_),
height_(info.height_),
@@ -24,42 +24,42 @@ DisplayScreen::DisplayScreen(const DisplayInfo& info)
{
}
DisplayId DisplayScreen::GetId() const
DisplayId AbstractDisplay::GetId() const
{
return id_;
}
int32_t DisplayScreen::GetWidth() const
int32_t AbstractDisplay::GetWidth() const
{
return width_;
}
int32_t DisplayScreen::GetHeight() const
int32_t AbstractDisplay::GetHeight() const
{
return height_;
}
uint32_t DisplayScreen::GetFreshRate() const
uint32_t AbstractDisplay::GetFreshRate() const
{
return freshRate_;
}
void DisplayScreen::SetWidth(int32_t width)
void AbstractDisplay::SetWidth(int32_t width)
{
width_ = width;
}
void DisplayScreen::SetHeight(int32_t height)
void AbstractDisplay::SetHeight(int32_t height)
{
height_ = height;
}
void DisplayScreen::SetFreshRate(uint32_t freshRate)
void AbstractDisplay::SetFreshRate(uint32_t freshRate)
{
freshRate_ = freshRate;
}
void DisplayScreen::SetId(DisplayId id)
void AbstractDisplay::SetId(DisplayId id)
{
id_ = id;
}
+136
View File
@@ -0,0 +1,136 @@
/*
* Copyright (c) 2021 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 "abstract_display_manager.h"
#include "window_manager_hilog.h"
#include <surface.h>
namespace OHOS::Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "AbstractDisplayManager"};
}
#define SCREENSHOT_GENERATOR
AbstractDisplayManager::AbstractDisplayManager() : rsInterface_(&(RSInterfaces::GetInstance()))
{
parepareRSScreenManger();
}
AbstractDisplayManager::~AbstractDisplayManager()
{
rsInterface_ = nullptr;
}
void AbstractDisplayManager::parepareRSScreenManger()
{
}
ScreenId AbstractDisplayManager::GetDefaultScreenId()
{
if (rsInterface_ == nullptr) {
return INVALID_SCREEN_ID;
}
return rsInterface_->GetDefaultScreenId();
}
RSScreenModeInfo AbstractDisplayManager::GetScreenActiveMode(ScreenId id)
{
RSScreenModeInfo screenModeInfo;
if (rsInterface_ == nullptr) {
return screenModeInfo;
}
return rsInterface_->GetScreenActiveMode(id);
}
ScreenId AbstractDisplayManager::CreateVirtualScreen(const VirtualDisplayInfo &virtualDisplayInfo,
sptr<Surface> surface)
{
if (rsInterface_ == nullptr) {
return INVALID_SCREEN_ID;
}
ScreenId result = rsInterface_->CreateVirtualScreen(virtualDisplayInfo.name_, virtualDisplayInfo.width_,
virtualDisplayInfo.height_, surface, virtualDisplayInfo.displayIdToMirror_, virtualDisplayInfo.flags_);
WLOGFI("AbstractDisplayManager::CreateVirtualDisplay id: %{public}llu", result >> 32);
return result;
}
bool AbstractDisplayManager::DestroyVirtualScreen(ScreenId screenId)
{
if (rsInterface_ == nullptr) {
return false;
}
WLOGFI("AbstractDisplayManager::DestroyVirtualScreen");
rsInterface_->RemoveVirtualScreen(screenId);
return true;
}
// TODO: fix me
// #ifdef SCREENSHOT_GENERATOR
// sptr<Media::PixelMap> TempCreatePixelMap()
// {
// // pixel_map testing code
// Media::InitializationOptions opt;
// opt.size.width = 1920;
// opt.size.height = 1080;
// opt.pixelFormat = Media::PixelFormat::RGBA_8888;
// opt.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
// opt.scaleMode = Media::ScaleMode::FIT_TARGET_SIZE;
// opt.editable = false;
// opt.useSourceIfMatch = false;
// const int bitmapDepth = 8; // color depth
// const int bpp = 4; // bytes per pixel
// const int maxByteNum = 256;
// auto data = (uint32_t *)malloc(opt.size.width * opt.size.height * bpp);
// uint8_t *pic = (uint8_t *)data;
// for (uint32_t i = 0; i < opt.size.width; i++) {
// for (uint32_t j = 0; j < opt.size.height; j++) {
// for (uint32_t k = 0; k < bpp; k++) {
// pic[0] = rand() % maxByteNum;
// pic++;
// }
// }
// }
// uint32_t colorLen = opt.size.width * opt.size.height * bpp * bitmapDepth;
// auto newPixelMap = Media::PixelMap::Create(data, colorLen, opt);
// sptr<Media::PixelMap> pixelMap_ = newPixelMap.release();
// if (pixelMap_ == nullptr) {
// WLOGFE("Failed to get pixelMap");
// return nullptr;
// }
// return pixelMap_;
// }
// #endif
// sptr<Media::PixelMap> AbstractDisplayManager::GetScreenSnapshot(ScreenId screenId)
// {
// if (rsInterface_ == nullptr) {
// return nullptr;
// }
// #ifdef SCREENSHOT_GENERATOR
// sptr<Media::PixelMap> screenshot = TempCreatePixelMap();
// #else
// sptr<Media::PixelMap> screenshot = rsInterface_->GetScreenSnapshot(screenId);
// #endif
// return screenshot;
// }
} // namespace OHOS::Rosen
+92 -25
View File
@@ -15,40 +15,18 @@
#include "display_manager_proxy.h"
#include <inttypes.h>
#include <cinttypes>
#include <ipc_types.h>
#include "window_manager_hilog.h"
#include <parcel.h>
namespace OHOS::Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerProxy"};
}
const sptr<DisplayInfo>& DisplayManagerProxy::GetDisplayInfo(const DisplayType type)
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
WLOGFW("get display: remote is nullptr");
return nullptr;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("get display: WriteInterfaceToken failed");
return nullptr;
}
data.WriteInt32(static_cast<int32_t>(type));
if (remote->SendRequest(TRANS_ID_GET_DISPLAY_INFO, data, reply, option) != ERR_NONE) {
WLOGFW("get display: SendRequest failed");
return nullptr;
}
// TODO: decode reply
return nullptr;
}
DisplayId DisplayManagerProxy::GetDefaultDisplayId()
{
sptr<IRemoteObject> remote = Remote();
@@ -102,4 +80,93 @@ DisplayInfo DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId)
}
return *info;
}
DisplayId DisplayManagerProxy::CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo,
sptr<Surface> surface)
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
WLOGFW("create virtual display: remote is nullptr");
return DISPLAY_ID_INVALD;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("create virtual display: WriteInterfaceToken failed");
return DISPLAY_ID_INVALD;
}
bool res = data.WriteParcelable(&virtualDisplayInfo) &&
data.WriteRemoteObject(surface->GetProducer()->AsObject());
if (!res) {
return DISPLAY_ID_INVALD;
}
if (remote->SendRequest(TRANS_ID_CREATE_VIRTUAL_DISPLAY, data, reply, option) != ERR_NONE) {
WLOGFW("create virtual display: SendRequest failed");
return DISPLAY_ID_INVALD;
}
DisplayId displayId = reply.ReadUint64();
WLOGFI("DisplayManagerProxy::CreateVirtualDisplay %" PRIu64"", displayId);
return displayId;
}
bool DisplayManagerProxy::DestroyVirtualDisplay(DisplayId displayId)
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
WLOGFW("destroy virtual display: remote is nullptr");
return false;
}
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("destroy virtual display: WriteInterfaceToken failed");
return false;
}
data.WriteUint64(static_cast<uint64_t>(displayId));
if (remote->SendRequest(TRANS_ID_DESTROY_VIRTUAL_DISPLAY, data, reply, option) != ERR_NONE) {
WLOGFW("destroy virtual display: SendRequest failed");
return false;
}
return reply.ReadBool();
}
// TODO: fix me
// sptr<Media::PixelMap> DisplayManagerProxy::GetDispalySnapshot(DisplayId displayId)
// {
// sptr<IRemoteObject> remote = Remote();
// if (remote == nullptr) {
// WLOGFW("GetDispalySnapshot: remote is nullptr");
// return nullptr;
// }
// MessageParcel data;
// MessageParcel reply;
// MessageOption option;
// if (!data.WriteInterfaceToken(GetDescriptor())) {
// WLOGFE("GetDispalySnapshot: WriteInterfaceToken failed");
// return nullptr;
// }
// if (!data.WriteUint64(displayId)) {
// WLOGFE("Write dispalyId failed");
// return nullptr;
// }
// if (remote->SendRequest(TRANS_ID_GET_DISPLAY_SNAPSHOT, data, reply, option) != ERR_NONE) {
// WLOGFW("GetDispalySnapshot: SendRequest failed");
// return nullptr;
// }
// sptr<Media::PixelMap> pixelMap = reply.ReadParcelable<Media::PixelMap>();
// if (pixelMap == nullptr) {
// WLOGFW("DisplayManagerProxy::GetDispalySnapshot SendRequest nullptr.");
// return nullptr;
// }
// return pixelMap;
// }
} // namespace OHOS::Rosen
+28 -25
View File
@@ -29,10 +29,7 @@ namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerService"};
}
IMPLEMENT_SINGLE_INSTANCE(DisplayManagerService);
const bool REGISTER_RESULT =
SystemAbility::MakeAndRegisterAbility(SingletonContainer::Get<DisplayManagerService>().GetRefPtr());
const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get<DisplayManagerService>());
DisplayManagerService::DisplayManagerService() : SystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID, true)
{
@@ -54,22 +51,10 @@ bool DisplayManagerService::Init()
WLOGFW("DisplayManagerService::Init failed");
return false;
}
displayScreenManager_ = DisplayScreenManager::GetInstance();
if (displayScreenManager_ == nullptr) {
WLOGFW("Get DisplayScreenManager failed");
return false;
}
WLOGFI("DisplayManagerService::Init success");
return true;
}
const sptr<DisplayInfo>& DisplayManagerService::GetDisplayInfo(const DisplayType type)
{
// TODO 从displayScreenMap_得到DisplayInfo
WLOGFI("DisplayManagerService::GetDisplayInfo");
return new DisplayInfo();
}
DisplayId DisplayManagerService::GetDisplayIdFromScreenId(ScreenId screenId)
{
return (DisplayId)screenId;
@@ -82,10 +67,7 @@ ScreenId DisplayManagerService::GetScreenIdFromDisplayId(DisplayId displayId)
DisplayId DisplayManagerService::GetDefaultDisplayId()
{
if (displayScreenManager_ == nullptr) {
return DISPLAY_ID_INVALD;
}
ScreenId screenId = displayScreenManager_->GetDefaultScreenId();
ScreenId screenId = AbstractDisplayManager::GetInstance().GetDefaultScreenId();
WLOGFI("GetDefaultDisplayId %{public}llu", screenId);
return GetDisplayIdFromScreenId(screenId);
}
@@ -93,11 +75,8 @@ DisplayId DisplayManagerService::GetDefaultDisplayId()
DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId)
{
DisplayInfo displayInfo;
if (displayScreenManager_ == nullptr) {
return displayInfo;
}
ScreenId screenId = GetScreenIdFromDisplayId(displayId);
auto screenModeInfo = displayScreenManager_->GetScreenActiveMode(screenId);
auto screenModeInfo = AbstractDisplayManager::GetInstance().GetScreenActiveMode(screenId);
displayInfo.id_ = displayId;
displayInfo.width_ = screenModeInfo.GetScreenWidth();
displayInfo.height_ = screenModeInfo.GetScreenHeight();
@@ -105,9 +84,33 @@ DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId)
return displayInfo;
}
DisplayId DisplayManagerService::CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo,
sptr<Surface> surface)
{
WLOGFI("name %{public}s, width %{public}u, height %{public}u, mirrotId %{public}llu, flags %{public}d",
virtualDisplayInfo.name_.c_str(), virtualDisplayInfo.width_, virtualDisplayInfo.height_,
virtualDisplayInfo.displayIdToMirror_, virtualDisplayInfo.flags_);
ScreenId screenId = AbstractDisplayManager::GetInstance().CreateVirtualScreen(virtualDisplayInfo, surface);
return GetDisplayIdFromScreenId(screenId);
}
bool DisplayManagerService::DestroyVirtualDisplay(DisplayId displayId)
{
WLOGFI("DisplayManagerService::DestroyVirtualDisplay");
ScreenId screenId = GetScreenIdFromDisplayId(displayId);
return AbstractDisplayManager::GetInstance().DestroyVirtualScreen(screenId);
}
// TODO: fix me
// sptr<Media::PixelMap> DisplayManagerService::GetDispalySnapshot(DisplayId displayId)
// {
// ScreenId screenId = GetScreenIdFromDisplayId(displayId);
// sptr<Media::PixelMap> screenSnapshot = AbstractDisplayManager::GetInstance().GetScreenSnapshot(screenId);
// return screenSnapshot;
// }
void DisplayManagerService::OnStop()
{
WLOGFI("ready to stop display service.");
displayScreenManager_ = nullptr;
}
} // namespace OHOS::Rosen
+9 -23
View File
@@ -16,14 +16,13 @@
#include "display_manager_service_inner.h"
#include <cinttypes>
#include <inttypes.h>
#include <unistd.h>
#include <ipc_skeleton.h>
#include <iservice_registry.h>
#include <system_ability_definition.h>
#include "display_screen_manager.h"
#include "abstract_display_manager.h"
#include "display_manager_service.h"
#include "window_manager_hilog.h"
@@ -32,28 +31,15 @@ namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerServiceInner"};
}
IMPLEMENT_SINGLE_INSTANCE(DisplayManagerServiceInner);
DisplayId DisplayManagerServiceInner::GetDefaultDisplayId()
{
auto dms = DisplayManagerService::GetInstance();
if (dms == nullptr) {
WLOGFE("GetDefaultDisplayId null!\n");
return DISPLAY_ID_INVALD;
}
return dms->GetDefaultDisplayId();
return DisplayManagerService::GetInstance().GetDefaultDisplayId();
}
const sptr<DisplayScreen> DisplayManagerServiceInner::GetDisplayById(DisplayId displayId)
const sptr<AbstractDisplay> DisplayManagerServiceInner::GetDisplayById(DisplayId displayId)
{
auto dms = DisplayManagerService::GetInstance();
if (dms == nullptr) {
WLOGFE("GetDisplayById null!\n");
return nullptr;
}
DisplayInfo displayInfo = dms->GetDisplayInfoById(displayId);
sptr<DisplayScreen> display = new DisplayScreen(displayInfo);
DisplayInfo displayInfo = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId);
sptr<AbstractDisplay> display = new AbstractDisplay(displayInfo);
if (display == nullptr) {
WLOGFE("GetDisplayById failed!\n");
return nullptr;
@@ -61,7 +47,7 @@ const sptr<DisplayScreen> DisplayManagerServiceInner::GetDisplayById(DisplayId d
return display;
}
const sptr<DisplayScreen> DisplayManagerServiceInner::GetDefaultDisplay()
const sptr<AbstractDisplay> DisplayManagerServiceInner::GetDefaultDisplay()
{
return GetDisplayById(GetDefaultDisplayId());
}
@@ -73,12 +59,12 @@ std::vector<DisplayId> DisplayManagerServiceInner::GetAllDisplayIds()
return res;
}
std::vector<const sptr<DisplayScreen>> DisplayManagerServiceInner::GetAllDisplays()
std::vector<const sptr<AbstractDisplay>> DisplayManagerServiceInner::GetAllDisplays()
{
std::vector<const sptr<DisplayScreen>> res;
std::vector<const sptr<AbstractDisplay>> res;
auto displayIds = GetAllDisplayIds();
for (auto displayId: displayIds) {
const sptr<DisplayScreen> display = GetDisplayById(displayId);
const sptr<AbstractDisplay> display = GetDisplayById(displayId);
if (display != nullptr) {
res.push_back(display);
} else {
+26 -6
View File
@@ -19,6 +19,8 @@
#include "window_manager_hilog.h"
#include "transaction/rs_interfaces.h"
namespace OHOS::Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "DisplayManagerStub"};
@@ -33,12 +35,6 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
return -1;
}
switch (code) {
case TRANS_ID_GET_DISPLAY_INFO: {
DisplayType type = static_cast<DisplayType>(data.ReadInt32());
sptr<DisplayInfo> info = GetDisplayInfo(type);
reply.WriteParcelable(info.GetRefPtr());
break;
}
case TRANS_ID_GET_DEFAULT_DISPLAY_ID: {
DisplayId displayId = GetDefaultDisplayId();
reply.WriteUint64(displayId);
@@ -50,6 +46,30 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data,
reply.WriteParcelable(&info);
break;
}
case TRANS_ID_CREATE_VIRTUAL_DISPLAY: {
VirtualDisplayInfo* virtualDisplayInfo = data.ReadParcelable<VirtualDisplayInfo>();
sptr<IRemoteObject> surfaceObject = data.ReadRemoteObject();
sptr<IBufferProducer> bp = iface_cast<IBufferProducer>(surfaceObject);
sptr<Surface> surface = Surface::CreateSurfaceAsProducer(bp);
DisplayId virtualId = CreateVirtualDisplay(*virtualDisplayInfo, surface);
reply.WriteUint64(virtualId);
virtualDisplayInfo = nullptr;
break;
}
case TRANS_ID_DESTROY_VIRTUAL_DISPLAY: {
DisplayId virtualId = static_cast<DisplayId>(data.ReadUint64());
bool result = DestroyVirtualDisplay(virtualId);
reply.WriteBool(result);
break;
}
// TODO: fix me
// case TRANS_ID_GET_DISPLAY_SNAPSHOT: {
// DisplayId displayId = data.ReadUint64();
// sptr<Media::PixelMap> dispalySnapshot = GetDispalySnapshot(displayId);
// reply.WriteParcelable(dispalySnapshot.GetRefPtr());
// break;
// }
default:
WLOGFW("unknown transaction code");
return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
-51
View File
@@ -1,51 +0,0 @@
/*
* Copyright (c) 2021 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 "display_screen_manager.h"
namespace OHOS::Rosen {
IMPLEMENT_SINGLE_INSTANCE(DisplayScreenManager);
DisplayScreenManager::DisplayScreenManager() : rsInterface_(&(RSInterfaces::GetInstance()))
{
parepareRSScreenManger();
}
DisplayScreenManager::~DisplayScreenManager()
{
rsInterface_ = nullptr;
}
void DisplayScreenManager::parepareRSScreenManger()
{
}
ScreenId DisplayScreenManager::GetDefaultScreenId()
{
if (rsInterface_ == nullptr) {
return INVALID_SCREEN_ID;
}
return rsInterface_->GetDefaultScreenId();
}
RSScreenModeInfo DisplayScreenManager::GetScreenActiveMode(ScreenId id)
{
RSScreenModeInfo screenModeInfo;
if (rsInterface_ == nullptr) {
return screenModeInfo;
}
return rsInterface_->GetScreenActiveMode(id);
}
} // namespace OHOS::Rosen
-2
View File
@@ -26,8 +26,6 @@ namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "RsAdapter"};
}
IMPLEMENT_SINGLE_INSTANCE(RsAdapter);
bool RsAdapter::InitRSProxyLocked()
{
WLOGFI("InitRProxy");
+61
View File
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2021 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 "virtual_display_info.h"
namespace OHOS::Rosen {
VirtualDisplayInfo::VirtualDisplayInfo()
{
name_ = "";
width_ = 0;
height_ = 0;
displayIdToMirror_ = 0;
flags_ = 0;
}
VirtualDisplayInfo::VirtualDisplayInfo(const std::string &name, uint32_t width, uint32_t height,
DisplayId displayIdToMirror, int32_t flags)
{
name_ = name;
width_ = width;
height_ = height;
displayIdToMirror_ = displayIdToMirror;
flags_ = flags;
}
bool VirtualDisplayInfo::Marshalling(Parcel &parcel) const
{
return parcel.WriteString(name_) && parcel.WriteUint32(width_) &&
parcel.WriteUint32(height_) && parcel.WriteUint64(displayIdToMirror_) &&
parcel.WriteInt32(flags_);
}
VirtualDisplayInfo* VirtualDisplayInfo::Unmarshalling(Parcel &parcel)
{
VirtualDisplayInfo *virtualDisplayInfo = new VirtualDisplayInfo();
if (virtualDisplayInfo == nullptr) {
return nullptr;
}
bool res = parcel.ReadString(virtualDisplayInfo->name_) &&
parcel.ReadUint32(virtualDisplayInfo->width_) &&
parcel.ReadUint32(virtualDisplayInfo->height_) &&
parcel.ReadUint64(virtualDisplayInfo->displayIdToMirror_) &&
parcel.ReadInt32(virtualDisplayInfo->flags_);
if (!res) {
return nullptr;
}
return virtualDisplayInfo;
}
} // namespace OHOS::Rosen
+1
View File
@@ -26,6 +26,7 @@ ohos_shared_library("wm_interface") {
public_deps = [
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client",
"//foundation/multimedia/image_standard/interfaces/innerkits:image_native",
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-client",
"//utils/native/base:utils",
]
+15 -8
View File
@@ -16,19 +16,22 @@
#ifndef FOUNDATION_DM_DISPLAY_MANAGER_H
#define FOUNDATION_DM_DISPLAY_MANAGER_H
#include <refbase.h>
#include <vector>
#include <surface.h>
#include "display.h"
#include "single_instance.h"
#include "virtual_display_info.h"
// #include "pixel_map.h"
// #include "wm_common.h"
namespace OHOS::Rosen {
class DisplayManagerAdapter;
class DisplayManager : public RefBase {
DECLARE_SINGLE_INSTANCE_BASE(DisplayManager);
class DisplayManager {
DECLARE_SINGLE_INSTANCE(DisplayManager);
public:
const sptr<Display>& GetDisplay(const DisplayType type);
std::vector<const sptr<Display>> GetAllDisplays();
DisplayId GetDefaultDisplayId();
@@ -38,10 +41,14 @@ public:
std::vector<DisplayId> GetAllDisplayIds();
private:
DisplayManager();
~DisplayManager();
sptr<DisplayManagerAdapter> dmsAdapter_;
DisplayId CreateVirtualDisplay(const std::string &name, uint32_t width, uint32_t height,
sptr<Surface> surface, DisplayId displayIdToMirror, int32_t flags);
bool DestroyVirtualDisplay(DisplayId displayId);
// TODO: fix me
// sptr<Media::PixelMap> GetScreenshot(DisplayId displayId);
// sptr<Media::PixelMap> GetScreenshot(DisplayId displayId, const Media::Rect &rect,
// const Media::Size &size, int rotation);
};
} // namespace OHOS::Rosen
+20 -2
View File
@@ -30,6 +30,9 @@
class NativeValue;
class NativeEngine;
namespace OHOS::AppExecFwk {
class Configuration;
}
namespace OHOS::AbilityRuntime {
class AbilityContext;
@@ -42,10 +45,15 @@ public:
virtual void OnSizeChange(Rect rect) = 0;
};
class IWindowSystemBarChangeListener : public RefBase {
public:
virtual void OnSystemBarPropertyChange(uint32_t displayId, WindowType type, const SystemBarProperty& prop) = 0;
};
class Window : public RefBase {
public:
static sptr<Window> Create(const std::string& windowName,
sptr<WindowOption>& option, const sptr<IRemoteObject>& abilityToken = nullptr);
sptr<WindowOption>& option, const std::shared_ptr<AbilityRuntime::AbilityContext>& abilityContext = nullptr);
static sptr<Window> Find(const std::string& windowName);
virtual std::shared_ptr<RSSurfaceNode> GetSurfaceNode() const = 0;
@@ -55,9 +63,15 @@ public:
virtual WindowMode GetMode() const = 0;
virtual const std::string& GetWindowName() const = 0;
virtual uint32_t GetWindowId() = 0;
virtual uint32_t GetWindowFlags() = 0;
virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) = 0;
virtual WMError SetWindowType(WindowType type) = 0;
virtual WMError SetWindowMode(WindowMode mode) = 0;
virtual WMError AddWindowFlag(WindowFlag flag) = 0;
virtual WMError RemoveWindowFlag(WindowFlag flag) = 0;
virtual WMError SetWindowFlags(uint32_t flags) = 0;
virtual WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) = 0;
virtual WMError Destroy() = 0;
virtual WMError Show() = 0;
@@ -70,11 +84,15 @@ public:
virtual void AddInputEventListener(std::shared_ptr<MMI::IInputEventConsumer>& inputEventListener) = 0; // for api 7
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 RegisterWindowChangeListener(sptr<IWindowChangeListener>& listener) = 0;
virtual void RegisterWindowSystemBarChangeListener(sptr<IWindowSystemBarChangeListener>& listener) = 0;
virtual WMError SetUIContent(std::shared_ptr<AbilityRuntime::AbilityContext> context,
std::string& url, NativeEngine* engine, NativeValue* storage) = 0;
std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed = false) = 0;
virtual const std::string& GetContentInfo() = 0;
};
}
}
@@ -25,7 +25,9 @@ public:
virtual void AfterForeground() = 0;
virtual void AfterBackground() = 0;
virtual void AfterFocused() = 0;
virtual void AfterUnFocused() = 0;
// TODO: need rename AfterUnFocused to AfterUnfocused
virtual void AfterUnFocused() {}
virtual void AfterUnfocused() {}
};
}
}
+57
View File
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2021 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_WINDOW_MANAGER_H
#define OHOS_ROSEN_WINDOW_MANAGER_H
#include <memory>
#include <refbase.h>
#include <vector>
#include <iremote_object.h>
#include "single_instance.h"
#include "singleton_delegator.h"
#include "wm_common.h"
namespace OHOS {
namespace Rosen {
class IFocusChangedListener : public RefBase {
public:
virtual void OnFocused(uint32_t windowId, sptr<IRemoteObject> abilityToken,
WindowType windowType, int32_t displayId) = 0;
virtual void OnUnfocused(uint32_t windowId, sptr<IRemoteObject> abilityToken,
WindowType windowType, int32_t displayId) = 0;
};
class WindowManager : public RefBase {
DECLARE_SINGLE_INSTANCE_BASE(WindowManager);
friend class WindowManagerAgent;
public:
void RegisterFocusChangedListener(const sptr<IFocusChangedListener>& listener);
void UnregisterFocusChangedListener(const sptr<IFocusChangedListener>& listener);
private:
WindowManager();
~WindowManager();
class Impl;
std::unique_ptr<Impl> pImpl_;
void UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
int32_t displayId, bool focused) const;
};
} // namespace Rosen
} // namespace OHOS
#endif // OHOS_ROSEN_WINDOW_MANAGER_H
+8 -1
View File
@@ -15,8 +15,9 @@
#ifndef OHOS_ROSEN_WINDOW_OPTION_H
#define OHOS_ROSEN_WINDOW_OPTION_H
#include <string>
#include <refbase.h>
#include <string>
#include <unordered_map>
#include "wm_common.h"
namespace OHOS {
@@ -37,6 +38,7 @@ public:
void AddWindowFlag(WindowFlag flag);
void RemoveWindowFlag(WindowFlag flag);
void SetWindowFlags(uint32_t flags);
void SetSystemBarProperty(WindowType type, const SystemBarProperty& property);
Rect GetWindowRect() const;
WindowType GetWindowType() const;
@@ -47,6 +49,7 @@ public:
const std::string& GetParentName() const;
const std::string& GetWindowName() const;
uint32_t GetWindowFlags() const;
const std::unordered_map<WindowType, SystemBarProperty>& GetSystemBarProperty() const;
private:
Rect windowRect_ { 0, 0, 0, 0 };
WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
@@ -57,6 +60,10 @@ private:
std::string parentName_ { "" };
std::string windowName_ { "" };
uint32_t flags_ { 0 };
std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ {
{ WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() },
{ WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() },
};
};
}
}
+6 -1
View File
@@ -19,6 +19,7 @@
#include <refbase.h>
#include <iremote_object.h>
#include <ability_context.h>
#include <configuration.h>
#include "window.h"
#include "window_option.h"
@@ -34,7 +35,7 @@ public:
~WindowScene();
WMError Init(int32_t displayId, std::shared_ptr<AbilityRuntime::AbilityContext>& abilityContext,
sptr<IWindowLifeCycle>& listener);
sptr<IWindowLifeCycle>& listener, sptr<WindowOption> option = nullptr);
sptr<Window> CreateWindow(const std::string& windowName, sptr<WindowOption>& option) const;
@@ -44,6 +45,10 @@ public:
WMError GoBackground() const;
WMError RequestFocus() const;
void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration);
WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) const;
const std::string& GetContentInfo() const;
private:
static inline std::atomic<uint32_t> count { 0 };
+32 -6
View File
@@ -22,18 +22,23 @@ namespace OHOS {
namespace Rosen {
enum class WindowType : uint32_t {
APP_WINDOW_BASE = 1,
WINDOW_TYPE_APP_MAIN_WINDOW = APP_WINDOW_BASE,
APP_WINDOW_END = 999,
APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE,
WINDOW_TYPE_APP_MAIN_WINDOW = APP_MAIN_WINDOW_BASE,
APP_MAIN_WINDOW_END = WINDOW_TYPE_APP_MAIN_WINDOW, // equals last window type
APP_SUB_WINDOW_BASE = 1000,
WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE,
WINDOW_TYPE_APP_SUB_WINDOW,
APP_SUB_WINDOW_END = 1999,
APP_SUB_WINDOW_END = WINDOW_TYPE_APP_SUB_WINDOW, // equals last window type
APP_WINDOW_END = APP_SUB_WINDOW_END,
SYSTEM_WINDOW_BASE = 2000,
BELOW_APP_SYSTEM_WINDOW_BASE = SYSTEM_WINDOW_BASE,
WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE,
BELOW_APP_SYSTEM_WINDOW_END = WINDOW_TYPE_WALLPAPER, // equals last window type
ABOVE_APP_SYSTEM_WINDOW_BASE = 2100,
WINDOW_TYPE_APP_LAUNCHING,
WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE,
WINDOW_TYPE_DOCK_SLICE,
WINDOW_TYPE_INCOMING_CALL,
WINDOW_TYPE_SEARCHING_BAR,
@@ -48,12 +53,14 @@ enum class WindowType : uint32_t {
WINDOW_TYPE_NAVIGATION_BAR,
WINDOW_TYPE_DRAGGING_EFFECT,
WINDOW_TYPE_POINTER,
SYSTEM_WINDOW_END = 2999,
ABOVE_APP_SYSTEM_WINDOW_END = WINDOW_TYPE_POINTER, // equals last window type
SYSTEM_WINDOW_END = ABOVE_APP_SYSTEM_WINDOW_END,
};
enum class WindowMode : uint32_t {
WINDOW_MODE_FULLSCREEN,
WINDOW_MODE_SPLIT,
WINDOW_MODE_SPLIT_PRIMARY,
WINDOW_MODE_SPLIT_SECONDARY,
WINDOW_MODE_FLOATING,
WINDOW_MODE_PIP
};
@@ -68,6 +75,7 @@ enum class WMError : int32_t {
WM_ERROR_DESTROYED_OBJECT = 140,
WM_ERROR_DEATH_RECIPIENT = 150,
WM_ERROR_INVALID_WINDOW = 160,
WM_ERROR_INVALID_OPERATION = 170,
WM_ERROR_UNKNOWN,
/* weston adater */
@@ -85,6 +93,24 @@ enum class WindowFlag : uint32_t {
WINDOW_FLAG_END = 1 << 2,
};
namespace {
constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF;
constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000;
}
struct SystemBarProperty {
bool enable_;
uint32_t backgroundColor_;
uint32_t contentColor_;
SystemBarProperty() : enable_(true), backgroundColor_(SYSTEM_COLOR_WHITE), contentColor_(SYSTEM_COLOR_BLACK) {}
SystemBarProperty(bool enable, uint32_t background, uint32_t content)
: enable_(enable), backgroundColor_(background), contentColor_(content) {}
bool operator == (const SystemBarProperty& a) const
{
return (enable_ == a.enable_ && backgroundColor_ == a.backgroundColor_ && contentColor_ == a.contentColor_);
}
};
struct Rect {
int32_t posX_;
int32_t posY_;
+1
View File
@@ -54,5 +54,6 @@ group("napi_packages") {
deps = [
"display:display",
"window:window",
"window_runtime:windowmanager_napi",
]
}
@@ -13,11 +13,8 @@
* limitations under the License.
*/
#include "native_display_module.h"
#include <inttypes.h>
#include "display_manager.h"
#include "native_display_module.h"
#include "wm_common.h"
#include "wm_napi_common.h"
@@ -31,19 +28,13 @@ struct Param {
void Async(napi_env env, std::unique_ptr<Param> &param)
{
sptr<DisplayManager> dm = DisplayManager::GetInstance();
if (dm == nullptr) {
GNAPI_LOG("dm error!\n");
return;
}
param->display = dm->GetDefaultDisplay();
param->display = DisplayManager::GetInstance().GetDefaultDisplay();
if (param->display == nullptr) {
GNAPI_LOG("Get display failed!");
param->wret = WMError::WM_ERROR_NULLPTR;
return;
}
GNAPI_LOG("GetDefaultDisplay: id %" PRIu64", w %d, h %d",
GNAPI_LOG("GetDefaultDisplay: id %{public}llu, w %{public}d, h %{public}d",
param->display->GetId(), param->display->GetWidth(), param->display->GetHeight());
param->wret = WMError::WM_OK;
}
@@ -57,7 +57,11 @@ struct Param {
void Async(napi_env env, std::unique_ptr<Param>& param)
{
param->ability->GetScene()->GetMainWindow()->Resize(param->width, param->height);
if (param == nullptr || param->ability == nullptr || param->ability->GetWindow() == nullptr) {
GNAPI_LOG("Error, use nullptr!)");
return;
}
param->ability->GetWindow()->Resize(param->width, param->height);
}
napi_value MainFunc(napi_env env, napi_callback_info info)
@@ -90,7 +94,11 @@ struct Param {
void Async(napi_env env, std::unique_ptr<Param>& param)
{
param->ability->GetScene()->GetMainWindow()->MoveTo(param->x, param->y);
if (param == nullptr || param->ability == nullptr || param->ability->GetWindow() == nullptr) {
GNAPI_LOG("Error, use nullptr!)");
return;
}
param->ability->GetWindow()->MoveTo(param->x, param->y);
}
napi_value MainFunc(napi_env env, napi_callback_info info)
@@ -122,7 +130,11 @@ struct Param {
void Async(napi_env env, std::unique_ptr<Param>& param)
{
param->ability->GetScene()->GetMainWindow()->SetWindowType(static_cast<WindowType>(param->windowType));
if (param == nullptr || param->ability == nullptr || param->ability->GetWindow() == nullptr) {
GNAPI_LOG("Error, use nullptr!)");
return;
}
param->ability->GetWindow()->SetWindowType(static_cast<WindowType>(param->windowType));
}
void CreateWindowTypeObject(napi_env env, napi_value value)
@@ -163,12 +175,12 @@ struct Param {
void Async(napi_env env, std::unique_ptr<Param> &param)
{
param->window = param->ability->GetScene()->GetMainWindow();
if (param->window == nullptr) {
GNAPI_LOG("Get main-window failed!");
if (param == nullptr || param->ability == nullptr) {
GNAPI_LOG("Get top window failed!");
param->wret = WMError::WM_ERROR_NULLPTR;
return;
}
param->window = param->ability->GetWindow();
param->wret = WMError::WM_OK;
}
@@ -184,6 +196,7 @@ napi_value MainFunc(napi_env env, napi_callback_info info)
GNAPI_LOG("Window Interface: getTopWindow()");
GNAPI_LOG("%{public}s called", __PRETTY_FUNCTION__);
auto param = std::make_unique<Param>();
NAPI_CALL(env, GetAbility(env, info, param->ability));
return CreatePromise<Param>(env, __PRETTY_FUNCTION__, Async, Resolve, param);
}
} // namespace getTopWindow
@@ -0,0 +1,55 @@
# Copyright (c) 2021 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.
import("//ark/ts2abc/ts2panda/ts2abc_config.gni")
import("//build/ohos.gni")
config("window_manager_napi_config") {
visibility = [ ":*" ]
include_dirs = [
"//foundation/windowmanager/interfaces/kits/napi/window_runtime",
"//foundation/windowmanager/interfaces/innerkits/wm",
"//foundation/windowmanager/interfaces/innerkits/dm",
"//foundation/windowmanager/wm/include",
"//foundation/windowmanager/utils/include",
]
}
ohos_shared_library("windowmanager_napi") {
sources = [
"js_window.cpp",
"js_window_listener.cpp",
"js_window_manager.cpp",
"js_window_utils.cpp",
"window_manager_module.cpp",
]
configs = [ ":window_manager_napi_config" ]
deps = [
"//foundation/windowmanager/wm:libwm",
"//foundation/windowmanager/wm:libwmutil",
"//foundation/windowmanager/wmserver:libwms",
]
external_deps = [
"aafwk_standard:runtime",
"hiviewdfx_hilog_native:libhilog",
"napi:ace_napi",
]
relative_install_dir = "module/application"
part_name = "window_manager"
subsystem_name = "window"
}
@@ -0,0 +1,249 @@
/*
* Copyright (c) 2021 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.
*/
/**
* Window manager.
* @devices tv, phone, tablet, wearable.
*/
declare namespace windowmanager {
enum WindowType {
APP_WINDOW_BASE = 1,
APP_MAIN_WINDOW_BASE = APP_WINDOW_BASE,
WINDOW_TYPE_APP_MAIN_WINDOW = APP_MAIN_WINDOW_BASE,
APP_MAIN_WINDOW_END = WINDOW_TYPE_APP_MAIN_WINDOW, // equals last window type
APP_SUB_WINDOW_BASE = 1000,
WINDOW_TYPE_MEDIA = APP_SUB_WINDOW_BASE,
WINDOW_TYPE_APP_SUB_WINDOW,
APP_SUB_WINDOW_END = WINDOW_TYPE_APP_SUB_WINDOW, // equals last window type
APP_WINDOW_END = APP_SUB_WINDOW_END,
SYSTEM_WINDOW_BASE = 2000,
BELOW_APP_SYSTEM_WINDOW_BASE = SYSTEM_WINDOW_BASE,
WINDOW_TYPE_WALLPAPER = SYSTEM_WINDOW_BASE,
BELOW_APP_SYSTEM_WINDOW_END = WINDOW_TYPE_WALLPAPER, // equals last window type
ABOVE_APP_SYSTEM_WINDOW_BASE = 2100,
WINDOW_TYPE_APP_LAUNCHING = ABOVE_APP_SYSTEM_WINDOW_BASE,
WINDOW_TYPE_DOCK_SLICE,
WINDOW_TYPE_INCOMING_CALL,
WINDOW_TYPE_SEARCHING_BAR,
WINDOW_TYPE_SYSTEM_ALARM_WINDOW,
WINDOW_TYPE_INPUT_METHOD_FLOAT,
WINDOW_TYPE_FLOAT,
WINDOW_TYPE_TOAST,
WINDOW_TYPE_STATUS_BAR,
WINDOW_TYPE_PANEL,
WINDOW_TYPE_KEYGUARD,
WINDOW_TYPE_VOLUME_OVERLAY,
WINDOW_TYPE_NAVIGATION_BAR,
WINDOW_TYPE_DRAGGING_EFFECT,
WINDOW_TYPE_POINTER,
ABOVE_APP_SYSTEM_WINDOW_END = WINDOW_TYPE_POINTER, // equals last window type
SYSTEM_WINDOW_END = ABOVE_APP_SYSTEM_WINDOW_END,
}
enum WindowMode {
/**
* FullSCREEN.
*/
WINDOW_MODE_FULLSCREEN,
/**
* SPLIT.
*/
WINDOW_MODE_SPLIT,
/**
* FREEFORM.
*/
WINDOW_MODE_FLOATING,
/**
* PIP.
*/
WINDOW_MODE_PIP
}
interface WindowManager {
/**
* Create a sub window with a specific id and type.
* @param id Indicates window id.
* @param type Indicates window type.
* @permission ohos.permission.SYSTEM_FLOAT_WINDOW
* @since 7
*/
create(id: string, type: WindowType, callback: AsyncCallback<Window>): void;
/**
* Create a sub window with a specific id and type.
* @param id Indicates window id.
* @param type Indicates window type.
* @permission ohos.permission.SYSTEM_FLOAT_WINDOW
* @since 7
*/
create(id: string, type: WindowType): Promise<Window>;
/**
* Find the sub window by id.
* @param id Indicates window id.
* @since 7
*/
find(id: string, callback: AsyncCallback<Window>): void;
/**
* Find the sub window by id.
* @param id Indicates window id.
* @since 7
*/
find(id: string): Promise<Window>;
}
/**
* Rectangle
* @devices tv, phone, tablet, wearable, car
* @since 7
*/
interface Rect {
left: number;
top: number;
width: number;
height: number;
}
/**
* window size
* @devices tv, phone, tablet, wearable, car
* @since 7
*/
interface Size {
/**
* the width of the window.
*/
width: number;
/**
* the height of the window.
*/
height: number;
}
/**
* Properties of window, it couldn't update automatically
* @devices tv, phone, tablet, wearable, car
* @since 6
*/
interface WindowProperties {
/**
* the position and size of the window
* @since 7
*/
windowRect: Rect;
/**
* window type
* @since 7
*/
type: WindowType;
}
interface Window {
/**
* hide sub window.
* @systemapi Hide this for inner system use.
* @since 7
*/
hide (callback: AsyncCallback<void>): void;
/**
* hide sub window.
* @systemapi Hide this for inner system use.
* @since 7
*/
hide(): Promise<void>;
/**
* show sub window.
* @since 7
*/
show(callback: AsyncCallback<void>): void;
/**
* show sub window.
* @since 7
*/
show(): Promise<void>;
/**
* Destroy the sub window.
* @since 7
*/
destroy(callback: AsyncCallback<void>): void;
/**
* Destroy the sub window.
* @since 7
*/
destroy(): Promise<void>;
/**
* Set the position of a window.
* @param x Indicate the X-coordinate of the window.
* @param y Indicate the Y-coordinate of the window.
* @devices tv, phone, tablet, wearable, liteWearable.
*/
moveTo(x:number, y:number): Promise<void>;
/**
* Set the size of a window .
* @param width Indicates the width of the window.
* @param height Indicates the height of the window.
* @devices tv, phone, tablet, wearable, liteWearable.
*/
resize(width:number, height:number): Promise<void>;
/**
* Set the type of a window.
* @param windowType Indicate the type of a window.
* @devices tv, phone, tablet, wearable, liteWearable.
*/
setWindowType(windowType: WindowType): Promise<void>;
/**
* Set the type of a window.
* @param windowMode Indicate the mode of a window.
* @devices tv, phone, tablet, wearable, liteWearable.
*/
setWindowMode(windowMode: WindowMode): Promise<void>;
/**
* get the properties of current window
* @devices tv, phone, tablet, wearable, car
* @since 6
*/
getProperties(callback: AsyncCallback<WindowProperties>): void;
/**
* get the properties of current window
* @devices tv, phone, tablet, wearable, car
* @since 6
*/
getProperties(): Promise<WindowProperties>;
/**
* register the callback of windowSizeChange
* @param type: 'windowSizeChange'
* @devices tv, phone, tablet, wearable, car
* @since 7
*/
on(type: 'windowSizeChange', callback: Callback<Size>): void;
/**
* unregister the callback of windowSizeChange
* @param type: 'windowSizeChange'
* @devices tv, phone, tablet, wearable, car
* @since 7
*/
off(type: 'windowSizeChange', callback?: Callback<Size>): void;
}
}
export default windowmanager;
@@ -0,0 +1,420 @@
/*
* Copyright (c) 2021 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 "js_window.h"
#include "window.h"
#include "window_manager_hilog.h"
#include "window_option.h"
namespace OHOS {
namespace Rosen {
using namespace AbilityRuntime;
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsWindow"};
}
JsWindow::JsWindow(const sptr<Window>& window, NativeEngine& engine) : windowToken_(window)
{
windowListener_ = new JsWindowListener(&engine);
}
void JsWindow::Finalizer(NativeEngine* engine, void* data, void* hint)
{
WLOGFI("JsWindow::Finalizer is called");
std::unique_ptr<JsWindow>(static_cast<JsWindow*>(data));
}
NativeValue* JsWindow::Show(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::Show is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnShow(*engine, *info) : nullptr;
}
NativeValue* JsWindow::Destroy(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::Destroy is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnDestroy(*engine, *info) : nullptr;
}
NativeValue* JsWindow::Hide(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::Hide is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnHide(*engine, *info) : nullptr;
}
NativeValue* JsWindow::MoveTo(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::MoveTo is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnMoveTo(*engine, *info) : nullptr;
}
NativeValue* JsWindow::Resize(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::Resize is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnResize(*engine, *info) : nullptr;
}
NativeValue* JsWindow::SetWindowType(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::SetWindowType is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnSetWindowType(*engine, *info) : nullptr;
}
NativeValue* JsWindow::SetWindowMode(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::SetWindowMode is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnSetWindowMode(*engine, *info) : nullptr;
}
NativeValue* JsWindow::GetProperties(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::GetProperties is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnGetProperties(*engine, *info) : nullptr;
}
NativeValue* JsWindow::RegisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::RegisterWindowCallback is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnRegisterWindowCallback(*engine, *info) : nullptr;
}
NativeValue* JsWindow::UnRegisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info)
{
WLOGFI("JsWindow::UnRegisterWindowCallback is called");
JsWindow* me = CheckParamsAndGetThis<JsWindow>(engine, info);
return (me != nullptr) ? me->OnUnRegisterWindowCallback(*engine, *info) : nullptr;
}
NativeValue* JsWindow::OnShow(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnShow is called");
if (windowToken_ == nullptr) {
WLOGFE("JsWindow windowToken_ is nullptr");
return engine.CreateUndefined();
}
AsyncTask::CompleteCallback complete =
[this](NativeEngine& engine, AsyncTask& task, int32_t status) {
WMError ret = windowToken_->Show();
if (ret == WMError::WM_OK) {
task.Resolve(engine, engine.CreateUndefined());
WLOGFI("JsWindow::OnShow success");
} else {
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "ShowWindow failed."));
}
};
NativeValue* lastParam = (info.argc == 0) ? nullptr : info.argv[0];
NativeValue* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindow::OnDestroy(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnDestroy is called");
if (windowToken_ == nullptr) {
WLOGFE("JsWindow windowToken_ is nullptr");
return engine.CreateUndefined();
}
AsyncTask::CompleteCallback complete =
[this](NativeEngine& engine, AsyncTask& task, int32_t status) {
WMError ret = windowToken_->Destroy();
windowToken_ = nullptr;
if (ret == WMError::WM_OK) {
task.Resolve(engine, engine.CreateUndefined());
WLOGFI("JsWindow::OnDestroy success");
} else {
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "JsWindow::OnDestroy failed."));
}
};
NativeValue* lastParam = (info.argc == 0) ? nullptr : info.argv[0];
NativeValue* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindow::OnHide(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnHide is called");
if (windowToken_ == nullptr) {
WLOGFE("JsWindow windowToken_ is nullptr");
return engine.CreateUndefined();
}
AsyncTask::CompleteCallback complete =
[this](NativeEngine& engine, AsyncTask& task, int32_t status) {
WMError ret = windowToken_->Hide();
if (ret == WMError::WM_OK) {
task.Resolve(engine, engine.CreateUndefined());
WLOGFI("JsWindow::OnHide success");
} else {
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "JsWindow::OnHide failed."));
}
};
NativeValue* lastParam = (info.argc == 0) ? nullptr : info.argv[0];
NativeValue* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindow::OnMoveTo(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnMoveTo is called");
if (windowToken_ == nullptr) {
WLOGFE("JsWindow windowToken_ is nullptr");
return engine.CreateUndefined();
}
int32_t x;
if (!ConvertFromJsValue(engine, info.argv[0], x)) {
WLOGFE("Failed to convert parameter to x");
return engine.CreateUndefined();
}
int32_t y;
if (!ConvertFromJsValue(engine, info.argv[1], y)) {
WLOGFE("Failed to convert parameter to y");
return engine.CreateUndefined();
}
AsyncTask::CompleteCallback complete =
[this, x, y](NativeEngine& engine, AsyncTask& task, int32_t status) {
WMError ret = windowToken_->MoveTo(x, y);
if (ret == WMError::WM_OK) {
task.Resolve(engine, engine.CreateUndefined());
WLOGFI("JsWindow::OnMoveTo success");
} else {
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "JsWindow::OnMoveTo failed."));
}
};
NativeValue* lastParam = (info.argc == ARGC_TWO) ? nullptr : info.argv[INDEX_TWO];
NativeValue* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindow::OnResize(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnResize is called");
if (windowToken_ == nullptr) {
WLOGFE("JsWindow windowToken_ is nullptr");
return engine.CreateUndefined();
}
uint32_t width;
if (!ConvertFromJsValue(engine, info.argv[0], width)) {
WLOGFE("Failed to convert parameter to width");
return engine.CreateUndefined();
}
uint32_t height;
if (!ConvertFromJsValue(engine, info.argv[1], height)) {
WLOGFE("Failed to convert parameter to height");
return engine.CreateUndefined();
}
AsyncTask::CompleteCallback complete =
[this, width, height](NativeEngine& engine, AsyncTask& task, int32_t status) {
WMError ret = windowToken_->Resize(width, height);
if (ret == WMError::WM_OK) {
task.Resolve(engine, engine.CreateUndefined());
} else {
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(ret), "JsWindow::OnResize failed."));
}
};
NativeValue* lastParam = (info.argc == ARGC_TWO) ? nullptr : info.argv[INDEX_TWO];
NativeValue* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindow::OnSetWindowType(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnSetWindowType is called");
if (windowToken_ == nullptr) {
WLOGFE("JsWindow windowToken_ is nullptr");
return engine.CreateUndefined();
}
NativeNumber* nativeType = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
if (nativeType == nullptr) {
WLOGFE("Failed to convert parameter to windowType");
return engine.CreateUndefined();
}
WindowType winType = static_cast<WindowType>(static_cast<uint32_t>(*nativeType));
AsyncTask::CompleteCallback complete =
[this, winType](NativeEngine& engine, AsyncTask& task, int32_t status) {
WMError ret = windowToken_->SetWindowType(winType);
if (ret == WMError::WM_OK) {
task.Resolve(engine, engine.CreateUndefined());
WLOGFI("JsWindow::OnSetWindowType success");
} else {
task.Reject(engine, CreateJsError(engine,
static_cast<int32_t>(ret), "JsWindow::OnSetWindowType failed."));
}
};
NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE];
NativeValue* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindow::OnSetWindowMode(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnSetWindowMode is called");
if (windowToken_ == nullptr) {
WLOGFE("JsWindow windowToken_ is nullptr");
return engine.CreateUndefined();
}
NativeNumber* nativeMode = ConvertNativeValueTo<NativeNumber>(info.argv[0]);
if (nativeMode == nullptr) {
WLOGFE("Failed to convert parameter to windowMode");
return engine.CreateUndefined();
}
WindowMode winMode = static_cast<WindowMode>(static_cast<uint32_t>(*nativeMode));
AsyncTask::CompleteCallback complete =
[this, winMode](NativeEngine& engine, AsyncTask& task, int32_t status) {
WMError ret = windowToken_->SetWindowMode(winMode);
if (ret == WMError::WM_OK) {
task.Resolve(engine, engine.CreateUndefined());
WLOGFI("JsWindow::OnSetWindowMode success");
} else {
task.Reject(engine,
CreateJsError(engine, static_cast<int32_t>(ret), "JsWindow::OnSetWindowMode failed."));
}
};
NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE];
NativeValue* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindow::OnGetProperties(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnGetProperties is called");
if (windowToken_ == nullptr) {
WLOGFE("JsWindow windowToken_ is nullptr");
return engine.CreateUndefined();
}
AsyncTask::CompleteCallback complete =
[this](NativeEngine& engine, AsyncTask& task, int32_t status) {
auto objValue = CreateJsWindowPropertiesObject(engine, windowToken_);
WLOGFI("JsWindow::OnGetProperties objValue %{public}p", objValue);
if (objValue != nullptr) {
task.Resolve(engine, objValue);
WLOGFI("JsWindow::OnGetProperties success");
} else {
task.Reject(engine, CreateJsError(engine,
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "JsWindow::OnGetProperties failed."));
}
};
NativeValue* lastParam = (info.argc == 0) ? nullptr : info.argv[0];
NativeValue* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* JsWindow::OnRegisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnRegisterWindowCallback is called");
if (windowToken_ == nullptr || windowListener_ == nullptr) {
WLOGFE("JsWindow windowToken_ or windowListener_ is nullptr");
return engine.CreateUndefined();
}
if (info.argc != ARGC_TWO) {
WLOGFE("Params not match");
return engine.CreateUndefined();
}
std::string cbType;
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
WLOGFE("Failed to convert parameter to callbackType");
return engine.CreateUndefined();
}
NativeValue* value = info.argv[1];
if (!value->IsCallable()) {
WLOGFI("JsWindow::OnRegisterWindowCallback info->argv[1] is not callable");
return engine.CreateUndefined();
}
if (!windowListener_->AddJsListenerObject(cbType, info.argv[1])) {
WLOGFI("JsWindow::OnRegisterWindowCallback failed");
return engine.CreateUndefined();
}
if (cbType.compare("windowSizeChange") == 0) {
sptr<IWindowChangeListener> thisListener(windowListener_);
windowToken_->RegisterWindowChangeListener(thisListener);
WLOGFI("JsWindow::OnRegisterWindowCallback success");
}
return engine.CreateUndefined();
}
NativeValue* JsWindow::OnUnRegisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsWindow::OnUnRegisterWindowCallback is called");
if (windowToken_ == nullptr || windowListener_ == nullptr) {
WLOGFE("JsWindow windowToken_ or windowListener_ is nullptr");
return engine.CreateUndefined();
}
if (info.argc == 0) {
WLOGFE("Params not match");
return engine.CreateUndefined();
}
std::string cbType;
if (!ConvertFromJsValue(engine, info.argv[0], cbType)) {
WLOGFE("Failed to convert parameter to callbackType");
return engine.CreateUndefined();
}
NativeValue* lastParam = (info.argc == 1) ? nullptr : info.argv[1];
windowListener_->RemoveJsListenerObject(cbType, lastParam);
return engine.CreateUndefined();
}
NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr<Window>& window)
{
WLOGFI("JsWindow::CreateJsWindow is called");
NativeValue* objValue = engine.CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
std::unique_ptr<JsWindow> jsWindow = std::make_unique<JsWindow>(window, engine);
object->SetNativePointer(jsWindow.release(), JsWindow::Finalizer, nullptr);
BindNativeFunction(engine, *object, "show", JsWindow::Show);
BindNativeFunction(engine, *object, "destroy", JsWindow::Destroy);
BindNativeFunction(engine, *object, "hide", JsWindow::Hide);
BindNativeFunction(engine, *object, "moveTo", JsWindow::MoveTo);
BindNativeFunction(engine, *object, "resetSize", JsWindow::Resize);
BindNativeFunction(engine, *object, "setWindowType", JsWindow::SetWindowType);
BindNativeFunction(engine, *object, "setWindowMode", JsWindow::SetWindowMode);
BindNativeFunction(engine, *object, "getProperties", JsWindow::GetProperties);
BindNativeFunction(engine, *object, "on", JsWindow::RegisterWindowCallback);
BindNativeFunction(engine, *object, "off", JsWindow::UnRegisterWindowCallback);
return objValue;
}
} // namespace Rosen
} // namespace OHOS
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2021 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_JS_WINDOW_H
#define OHOS_JS_WINDOW_H
#include "js_runtime_utils.h"
#include "js_window_listener.h"
#include "js_window_utils.h"
#include "native_engine/native_engine.h"
#include "native_engine/native_value.h"
#include "window.h"
namespace OHOS {
namespace Rosen {
NativeValue* CreateJsWindowObject(NativeEngine& engine, sptr<Window>& window);
class JsWindow final {
public:
JsWindow(const sptr<Window>& window, NativeEngine& engine);
~JsWindow() = default;
static void Finalizer(NativeEngine* engine, void* data, void* hint);
static NativeValue* Show(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* Destroy(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* Hide(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* MoveTo(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* Resize(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetWindowType(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* SetWindowMode(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* GetProperties(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* RegisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info);
static NativeValue* UnRegisterWindowCallback(NativeEngine* engine, NativeCallbackInfo* info);
private:
NativeValue* OnShow(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnDestroy(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnHide(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnMoveTo(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnResize(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSetWindowType(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnSetWindowMode(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnGetProperties(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnRegisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info);
NativeValue* OnUnRegisterWindowCallback(NativeEngine& engine, NativeCallbackInfo& info);
sptr<Window> windowToken_ = nullptr;
sptr<JsWindowListener> windowListener_ = nullptr;
};
} // namespace Rosen
} // namespace OHOS
#endif
@@ -0,0 +1,118 @@
/*
* Copyright (c) 2021 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 "js_window_listener.h"
#include "js_runtime_utils.h"
#include "window_manager_hilog.h"
namespace OHOS {
namespace Rosen {
using namespace AbilityRuntime;
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsWindowListener"};
}
bool JsWindowListener::IsCallbackExists(std::string type, NativeValue* jsListenerObject)
{
if (jsWinodwListenerObjectMap_.find(type) == jsWinodwListenerObjectMap_.end()) {
WLOGFE("JsWindowListener::IsCallbackExists methodName %{public}s not exist!", type.c_str());
return false;
}
for (auto iter = jsWinodwListenerObjectMap_[type].begin();
iter != jsWinodwListenerObjectMap_[type].end(); iter++) {
if (jsListenerObject->StrictEquals((*iter)->Get())) {
WLOGFI("JsWindowListener::AddJsListenerObject callback already exists!");
return true;
}
}
return false;
}
bool JsWindowListener::AddJsListenerObject(std::string type, NativeValue* jsListenerObject)
{
WLOGFI("JsWindowListener::AddJsListenerObject is called");
std::lock_guard<std::mutex> lock(listenerMutex_);
std::unique_ptr<NativeReference> callbackRef;
callbackRef.reset(engine_->CreateReference(jsListenerObject, 1));
if (IsCallbackExists(type, jsListenerObject)) {
WLOGFI("JsWindowListener::AddJsListenerObject jsWinodwListenerObjectMap_ size: %{public}d!",
jsWinodwListenerObjectMap_[type].size());
return false;
}
jsWinodwListenerObjectMap_[type].insert(std::move(callbackRef));
WLOGFI("JsWindowListener::AddJsListenerObject failed jsWinodwListenerObjectMap_ size: %{public}d!",
jsWinodwListenerObjectMap_[type].size());
return true;
}
void JsWindowListener::RemoveJsListenerObject(std::string type, NativeValue* jsListenerObject)
{
WLOGFI("JsWindowListener::RemoveJsListenerObject is called");
std::lock_guard<std::mutex> lock(listenerMutex_);
if (jsWinodwListenerObjectMap_.find(type) == jsWinodwListenerObjectMap_.end()) {
WLOGFE("methodName %{public}s not exist!", type.c_str());
return;
}
if (jsListenerObject == nullptr) {
jsWinodwListenerObjectMap_.erase(type);
} else {
for (auto iter = jsWinodwListenerObjectMap_[type].begin();
iter != jsWinodwListenerObjectMap_[type].end(); iter++) {
if (jsListenerObject->StrictEquals((*iter)->Get())) {
jsWinodwListenerObjectMap_[type].erase(iter);
}
}
}
WLOGFI("JsWindowListener::RemoveJsListenerObject jsWinodwListenerObjectMap_ size: %{public}d!",
jsWinodwListenerObjectMap_[type].size());
WLOGFI("JsWindowListener::RemoveJsListenerObject success!");
}
void JsWindowListener::OnSizeChange(Rect rect)
{
WLOGFI("JsWindowListener::OnSizeChange is called");
NativeValue* sizeValue = engine_->CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(sizeValue);
if (object == nullptr) {
WLOGFE("Failed to convert rect to jsObject");
return;
}
object->SetProperty("width", CreateJsValue(*engine_, rect.width_));
object->SetProperty("height", CreateJsValue(*engine_, rect.height_));
NativeValue* argv[] = {sizeValue};
CallJsMethod("windowSizeChange", argv, ArraySize(argv));
}
void JsWindowListener::CallJsMethod(const char* methodName, NativeValue* const* argv, size_t argc)
{
WLOGFI("CallJsMethod methodName = %{public}s", methodName);
if (engine_ == nullptr) {
WLOGFE("engine_ nullptr");
return;
}
std::lock_guard<std::mutex> lock(listenerMutex_);
std::string type(methodName);
if (jsWinodwListenerObjectMap_.find(type) == jsWinodwListenerObjectMap_.end()) {
WLOGFE("methodName %{public}s not exist!", methodName);
return;
}
for (auto iter = jsWinodwListenerObjectMap_[type].begin(); iter != jsWinodwListenerObjectMap_[type].end(); iter++) {
NativeValue* method = (*iter)->Get();
if (method == nullptr) {
WLOGFE("Failed to get method callback from object");
return;
}
engine_->CallFunction(engine_->CreateUndefined(), method, argv, argc);
}
}
} // namespace Rosen
} // namespace OHOS
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2021 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_JS_WINDOW_LISTENER_H
#define OHOS_JS_WINDOW_LISTENER_H
#include <map>
#include <mutex>
#include <unordered_set>
#include "native_engine/native_engine.h"
#include "native_engine/native_value.h"
#include "window.h"
namespace OHOS {
namespace Rosen {
class JsWindowListener : public IWindowChangeListener {
public:
explicit JsWindowListener(NativeEngine* engine) : engine_(engine) {}
virtual ~JsWindowListener() = default;
void OnSizeChange(Rect rect) override;
bool AddJsListenerObject(std::string type, NativeValue* jsListenerObject);
void RemoveJsListenerObject(std::string type, NativeValue* jsListenerObject);
private:
void CallJsMethod(const char* methodName, NativeValue* const* argv = nullptr, size_t argc = 0);
bool IsCallbackExists(std::string type, NativeValue* jsListenerObject);
NativeEngine* engine_ = nullptr;
std::map<std::string, std::unordered_set<std::unique_ptr<NativeReference>>> jsWinodwListenerObjectMap_;
std::mutex listenerMutex_;
};
} // namespace Rosen
} // namespace OHOS
#endif /* OHOS_JS_WINDOW_LISTENER_H */
@@ -0,0 +1,149 @@
/*
* Copyright (c) 2021 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 "js_window_manager.h"
#include "js_runtime_utils.h"
#include "js_window.h"
#include "js_window_utils.h"
#include "native_engine/native_reference.h"
#include "window_manager_hilog.h"
#include "window_option.h"
namespace OHOS {
namespace Rosen {
using namespace AbilityRuntime;
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsWindowManager"};
}
class JsWindowManager {
public:
JsWindowManager() = default;
~JsWindowManager() = default;
static void Finalizer(NativeEngine* engine, void* data, void* hint)
{
WLOGFI("JsWindowManager::Finalizer is called");
std::unique_ptr<JsWindowManager>(static_cast<JsWindowManager*>(data));
}
static NativeValue* CreateWindow(NativeEngine* engine, NativeCallbackInfo* info)
{
JsWindowManager* me = CheckParamsAndGetThis<JsWindowManager>(engine, info);
return (me != nullptr) ? me->OnCreateWindow(*engine, *info) : nullptr;
}
static NativeValue* FindWindow(NativeEngine* engine, NativeCallbackInfo* info)
{
JsWindowManager* me = CheckParamsAndGetThis<JsWindowManager>(engine, info);
return (me != nullptr) ? me->OnFindWindow(*engine, *info) : nullptr;
}
private:
NativeValue* OnCreateWindow(NativeEngine& engine, NativeCallbackInfo& info)
{
WLOGFI("JsOnCreateWindow is called");
if (info.argc < ARGC_TWO) {
WLOGFE("OnCreateWindow MUST set windowname");
return engine.CreateUndefined();
}
std::string windowName;
if (!ConvertFromJsValue(engine, info.argv[0], windowName)) {
WLOGFE("Failed to convert parameter to windowName");
return engine.CreateUndefined();
}
NativeNumber* nativeType = ConvertNativeValueTo<NativeNumber>(info.argv[1]);
if (nativeType == nullptr) {
WLOGFE("Failed to convert parameter to windowType");
return engine.CreateUndefined();
}
WindowType winType = static_cast<WindowType>(static_cast<uint32_t>(*nativeType));
AsyncTask::CompleteCallback complete =
[windowName, winType](NativeEngine& engine, AsyncTask& task, int32_t status) {
sptr<WindowOption> windowOption = new WindowOption();
windowOption->SetWindowType(winType);
sptr<Window> window = Window::Create(windowName, windowOption);
if (window != nullptr) {
task.Resolve(engine, CreateJsWindowObject(engine, window));
WLOGFI("JsWindowManager::OnCreateWindow success");
} else {
task.Reject(engine, CreateJsError(engine,
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "JsWindowManager::OnCreateWindow failed."));
}
};
NativeValue* lastParam = (info.argc == ARGC_TWO) ? nullptr : info.argv[INDEX_TWO];
NativeValue* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
NativeValue* OnFindWindow(NativeEngine& engine, NativeCallbackInfo& info)
{
std::string windowName;
if (!ConvertFromJsValue(engine, info.argv[0], windowName)) {
WLOGFE("Failed to convert parameter to windowName");
return engine.CreateUndefined();
}
AsyncTask::CompleteCallback complete =
[windowName](NativeEngine& engine, AsyncTask& task, int32_t status) {
sptr<Window> window = Window::Find(windowName);
if (window != nullptr) {
task.Resolve(engine, CreateJsWindowObject(engine, window));
WLOGFI("JsWindowManager::OnFindWindow success");
} else {
task.Reject(engine, CreateJsError(engine,
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "JsWindow::OnFindWindow failed."));
}
};
NativeValue* lastParam = (info.argc == ARGC_ONE) ? nullptr : info.argv[INDEX_ONE];
if (lastParam == nullptr) {
WLOGFI("JsWindowManager::OnFindWindow lastParam is nullptr");
}
NativeValue* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
return result;
}
};
NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj)
{
WLOGFI("JsWindowManagerInit is called");
if (engine == nullptr || exportObj == nullptr) {
WLOGFE("JsWindowManagerInit engine or exportObj is nullptr");
return nullptr;
}
NativeObject* object = ConvertNativeValueTo<NativeObject>(exportObj);
if (object == nullptr) {
WLOGFE("JsWindowManagerInit object is nullptr");
return nullptr;
}
std::unique_ptr<JsWindowManager> jsWinManager = std::make_unique<JsWindowManager>();
object->SetNativePointer(jsWinManager.release(), JsWindowManager::Finalizer, nullptr);
BindNativeFunction(*engine, *object, "create", JsWindowManager::CreateWindow);
BindNativeFunction(*engine, *object, "find", JsWindowManager::FindWindow);
return engine->CreateUndefined();
}
} // namespace Rosen
} // namespace OHOS
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2021 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 "native_engine/native_engine.h"
#include "native_engine/native_value.h"
#ifndef OHOS_JS_WINDOW_MANAGER_H
#define OHOS_JS_WINDOW_MANAGER_H
namespace OHOS {
namespace Rosen {
NativeValue* JsWindowManagerInit(NativeEngine* engine, NativeValue* exportObj);
} // namespace Rosen
} // namespace OHOS
#endif
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2021 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 "js_window_utils.h"
#include "js_runtime_utils.h"
#include "window_manager_hilog.h"
namespace OHOS {
namespace Rosen {
using namespace AbilityRuntime;
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "JsWindowUtils"};
}
static NativeValue* GetRectAndConvertToJsValue(NativeEngine& engine, const Rect& rect)
{
NativeValue* objValue = engine.CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
WLOGFE("Failed to convert rect to jsObject");
return engine.CreateUndefined();
}
object->SetProperty("left", CreateJsValue(engine, rect.posX_));
object->SetProperty("top", CreateJsValue(engine, rect.posY_));
object->SetProperty("width", CreateJsValue(engine, rect.width_));
object->SetProperty("height", CreateJsValue(engine, rect.height_));
return objValue;
}
NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr<Window>& window)
{
WLOGFI("JsWindow::CreateJsWindowPropertiesObject is called");
NativeValue* objValue = engine.CreateObject();
NativeObject* object = ConvertNativeValueTo<NativeObject>(objValue);
if (object == nullptr) {
WLOGFE("Failed to convert windowProperties to jsObject");
return nullptr;
}
Rect rect = window->GetRect();
NativeValue* rectObj = GetRectAndConvertToJsValue(engine, rect);
if (rectObj == nullptr) {
WLOGFE("GetRect failed!");
}
object->SetProperty("windowRect", rectObj);
object->SetProperty("type", CreateJsValue(engine, window->GetType()));
return objValue;
}
} // namespace Rosen
} // namespace OHOS
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2021 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_JS_WINDOW_UTILS_H
#define OHOS_JS_WINDOW_UTILS_H
#include "native_engine/native_engine.h"
#include "native_engine/native_value.h"
#include "window.h"
#include "window_option.h"
#include "wm_common.h"
namespace OHOS {
namespace Rosen {
namespace {
constexpr size_t ARGC_ONE = 1;
constexpr size_t ARGC_TWO = 2;
constexpr int32_t INDEX_ONE = 1;
constexpr int32_t INDEX_TWO = 2;
}
NativeValue* CreateJsWindowPropertiesObject(NativeEngine& engine, sptr<Window>& window);
}
}
#endif
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2021 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 "js_window_manager.h"
#include "native_engine/native_engine.h"
extern "C" __attribute__((constructor))
void NAPI_application_windowmanager_AutoRegister()
{
auto moduleManager = NativeModuleManager::GetInstance();
NativeModule newModuleInfo = {
.name = "application.windowmanager",
.fileName = "application/libwindowmanager_napi.so/windowmanager.js",
.registerCallback = OHOS::Rosen::JsWindowManagerInit,
};
moduleManager->Register(&newModuleInfo);
}
+16
View File
@@ -21,6 +21,22 @@ class WindowStage {
setUIContent(context, url, storage) {
return this.__window_stage__.setUIContent(context, url, storage)
}
getMainWindow() {
return this.__window_stage__.getMainWindow()
}
on(type, callback) {
return this.__window_stage__.on(type, callback)
}
off(type) {
return this.__window_stage__.off(type)
}
off(type, callback) {
return this.__window_stage__.off(type, callback)
}
}
export default WindowStage
+1 -2
View File
@@ -5,11 +5,10 @@
"module_list": [
"//foundation/windowmanager/interfaces/kits/js/declaration:window",
"//foundation/windowmanager/sa_profile:wms_sa_profile",
"//foundation/windowmanager/adapter:libwmadaptertest",
"//foundation/windowmanager/adapter:libwmadapter",
"//foundation/windowmanager/wm:libwm",
"//foundation/windowmanager/wmserver:libwms",
"//foundation/windowmanager/wm:libwmutil",
"//foundation/windowmanager/wmtest:rosenwmtest",
"//foundation/windowmanager/interfaces/kits/napi:windowstage",
"//foundation/windowmanager/interfaces/kits/napi:napi_packages"
+1 -1
View File
@@ -23,4 +23,4 @@
<distributed>false</distributed> <!-- "true" means the system ability supports distributed scheduling while "false" is not.-->
<dump-level>1</dump-level> <!-- Declare the dump level. 1-high; 2-media; 3-low -->
</systemability>
</info>
</info>
+42
View File
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2021 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_NONCOPYABLE_H
#define OHOS_WM_INCLUDE_NONCOPYABLE_H
#define WM_DISALLOW_COPY_AND_MOVE(className) \
WM_DISALLOW_COPY(className); \
WM_DISALLOW_MOVE(className)
#define WM_DISALLOW_COPY(className) \
className(const className&) = delete; \
className& operator=(const className&) = delete
#define WM_DISALLOW_MOVE(className) \
className(className&&) = delete; \
className& operator=(className&&) = delete
namespace OHOS::Rosen {
class NonCopyable {
protected:
NonCopyable() = default;
virtual ~NonCopyable() = default;
private:
WM_DISALLOW_COPY_AND_MOVE(NonCopyable);
};
} // namespace OHOS::Rosen
#endif // OHOS_WM_INCLUDE_NONCOPYABLE_H
+8 -13
View File
@@ -19,26 +19,21 @@ namespace OHOS {
namespace Rosen {
#define DECLARE_SINGLE_INSTANCE_BASE(className) \
public: \
static sptr<className> GetInstance(); \
private: \
static className& GetInstance() \
{ \
static className instance; \
return instance; \
} \
className(const className&) = delete; \
className& operator= (const className&) = delete; \
className(className&&) = delete; \
className& operator= (className&&) = delete; \
className& operator= (className&&) = delete;
#define DECLARE_SINGLE_INSTANCE(className) \
DECLARE_SINGLE_INSTANCE_BASE(className) \
private: \
protected: \
className() = default; \
~className() = default; \
#define IMPLEMENT_SINGLE_INSTANCE(className) \
sptr<className> className::GetInstance() \
{ \
static sptr<className> instance = new className(); \
return instance; \
}
virtual ~className() = default;
} // namespace OHOS
}
#endif // OHOS_SINGLE_INSTANCE_H
+18 -26
View File
@@ -22,53 +22,46 @@
#include <set>
#include <string>
#include <refbase.h>
#include "single_instance.h"
namespace OHOS {
namespace Rosen {
class SingletonContainer : public RefBase {
public:
static sptr<SingletonContainer> GetInstance();
class SingletonContainer {
DECLARE_SINGLE_INSTANCE_BASE(SingletonContainer);
void AddSingleton(const std::string &name, const std::any &instance);
void SetSingleton(const std::string &name, const std::any &instance);
const std::any &GetSingleton(const std::string &name);
const std::any &DependOn(const std::string &instance, const std::string &name);
public:
void AddSingleton(const std::string& name, void* instance);
void SetSingleton(const std::string& name, void* instance);
void* GetSingleton(const std::string& name);
void* DependOn(const std::string& instance, const std::string& name);
template<class T>
static sptr<T> Get()
static T& Get()
{
std::string nameT = __PRETTY_FUNCTION__;
nameT = nameT.substr(nameT.find("T = "));
nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = "));
using sptrT = sptr<T>;
sptrT ret = nullptr;
const std::any &instance = SingletonContainer::GetInstance()->GetSingleton(nameT);
auto pRet = std::any_cast<sptrT>(&instance);
if (pRet != nullptr) {
ret = *pRet;
}
return ret;
return *(reinterpret_cast<T*>(SingletonContainer::GetInstance().GetSingleton(nameT)));
}
template<class T>
static void Set(const sptr<T> &ptr)
static void Set(T& instance)
{
std::string nameT = __PRETTY_FUNCTION__;
nameT = nameT.substr(nameT.find("T = "));
nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = "));
SingletonContainer::GetInstance()->SetSingleton(nameT, ptr);
SingletonContainer::GetInstance().SetSingleton(nameT, &instance);
}
private:
SingletonContainer() = default;
virtual ~SingletonContainer() override;
static inline sptr<SingletonContainer> instance = nullptr;
virtual ~SingletonContainer();
struct Singleton {
std::any value;
void* value;
int32_t refCount;
};
std::map<std::string, int32_t> stringMap;
@@ -77,5 +70,4 @@ private:
};
} // namespace Rosen
} // namespace OHOS
#endif // FRAMEWORKS_WM_INCLUDE_SINGLETON_CONTAINER_H
+3 -5
View File
@@ -30,21 +30,19 @@ public:
nameT = __PRETTY_FUNCTION__;
nameT = nameT.substr(nameT.find("T = "));
nameT = nameT.substr(sizeof("T ="), nameT.length() - sizeof("T = "));
SingletonContainer::GetInstance()->AddSingleton(nameT, T::GetInstance());
SingletonContainer::GetInstance().AddSingleton(nameT, &T::GetInstance());
}
~SingletonDelegator() = default;
template<class S>
sptr<S> Dep()
S& Dep()
{
std::string nameS = __PRETTY_FUNCTION__;
nameS = nameS.substr(nameS.find("S = "));
nameS = nameS.substr(sizeof("S ="), nameS.length() - sizeof("S = "));
auto ret = SingletonContainer::Get<S>();
if (ret != nullptr) {
SingletonContainer::GetInstance()->DependOn(nameT, nameS);
}
SingletonContainer::GetInstance().DependOn(nameT, nameS);
return ret;
}
+3 -3
View File
@@ -23,11 +23,11 @@
#include "window_option.h"
namespace OHOS {
namespace Rosen {
class StaticCall : public RefBase {
DECLARE_SINGLE_INSTANCE_BASE(StaticCall);
class StaticCall {
DECLARE_SINGLE_INSTANCE_BASE(StaticCall);
public:
virtual sptr<Window> CreateWindow(const std::string& windowName,
sptr<WindowOption>& option, const sptr<IRemoteObject>& abilityToken = nullptr);
sptr<WindowOption>& option, std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr);
protected:
StaticCall() = default;
private:
+60
View File
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2021 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_HELPER_H
#define OHOS_WM_INCLUDE_WM_HELPER_H
#include <wm_common.h>
namespace OHOS {
namespace Rosen {
class WindowHelper {
public:
static inline bool IsMainWindow(WindowType type)
{
return (type >= WindowType::APP_MAIN_WINDOW_BASE && type <= WindowType::APP_MAIN_WINDOW_END);
}
static inline bool IsSubWindow(WindowType type)
{
return (type >= WindowType::APP_SUB_WINDOW_BASE && type <= WindowType::APP_SUB_WINDOW_END);
}
static inline bool IsAppWindow(WindowType type)
{
return (IsMainWindow(type) || IsSubWindow(type));
}
static inline bool IsBelowSystemWindow(WindowType type)
{
return (type >= WindowType::BELOW_APP_SYSTEM_WINDOW_BASE && type <= WindowType::BELOW_APP_SYSTEM_WINDOW_END);
}
static inline bool IsAboveSystemWindow(WindowType type)
{
return (type >= WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE && type <= WindowType::ABOVE_APP_SYSTEM_WINDOW_END);
}
static inline bool IsSystemWindow(WindowType type)
{
return (IsBelowSystemWindow(type) || IsAboveSystemWindow(type));
}
WindowHelper() = default;
~WindowHelper() = default;
};
} // namespace OHOS
} // namespace Rosen
#endif // OHOS_WM_INCLUDE_WM_HELPER_H
+55
View File
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2021 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 "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()
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();
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
+7 -20
View File
@@ -23,18 +23,6 @@ namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManager_SingletonContainer"};
} // namespace
sptr<SingletonContainer> SingletonContainer::GetInstance()
{
if (instance == nullptr) {
static std::mutex mutex;
std::lock_guard<std::mutex> lock(mutex);
if (instance == nullptr) {
instance = new SingletonContainer();
}
}
return instance;
}
SingletonContainer::~SingletonContainer()
{
while (singletonMap.empty() == false) {
@@ -63,7 +51,7 @@ SingletonContainer::~SingletonContainer()
}
}
void SingletonContainer::AddSingleton(const std::string &name, const std::any &instance)
void SingletonContainer::AddSingleton(const std::string& name, void* instance)
{
if (stringMap.find(name) == stringMap.end()) {
static int32_t nextId = 0;
@@ -76,7 +64,7 @@ void SingletonContainer::AddSingleton(const std::string &name, const std::any &i
}
}
void SingletonContainer::SetSingleton(const std::string &name, const std::any &instance)
void SingletonContainer::SetSingleton(const std::string& name, void* instance)
{
if (stringMap.find(name) == stringMap.end()) {
AddSingleton(name, instance);
@@ -86,21 +74,20 @@ void SingletonContainer::SetSingleton(const std::string &name, const std::any &i
}
}
const std::any &SingletonContainer::GetSingleton(const std::string &name)
void* SingletonContainer::GetSingleton(const std::string& name)
{
if (stringMap.find(name) == stringMap.end()) {
WLOGFD("cannot get %{public}s", name.c_str());
static std::any voidAny;
return voidAny;
return nullptr;
}
return singletonMap[stringMap[name]].value;
}
const std::any &SingletonContainer::DependOn(const std::string &instance, const std::string &name)
void* SingletonContainer::DependOn(const std::string& instance, const std::string& name)
{
auto &instanceDependencySet = dependencySetMap[stringMap[instance]];
auto& instanceDependencySet = dependencySetMap[stringMap[instance]];
if (instanceDependencySet.find(stringMap[name]) == instanceDependencySet.end()) {
WLOGFD("%{public}s dependon %{public}s", instance.c_str(), name.c_str());
WLOGFD("%{public}s DependOn %{public}s", instance.c_str(), name.c_str());
instanceDependencySet.insert(stringMap[name]);
singletonMap[stringMap[name]].refCount++;
}
+2 -4
View File
@@ -17,12 +17,10 @@
namespace OHOS {
namespace Rosen {
IMPLEMENT_SINGLE_INSTANCE(StaticCall);
sptr<Window> StaticCall::CreateWindow(const std::string& windowName,
sptr<WindowOption>& option, const sptr<IRemoteObject>& abilityToken)
sptr<WindowOption>& option, std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext)
{
return Window::Create(windowName, option, abilityToken);
return Window::Create(windowName, option, abilityContext);
}
} // namespace Rosen
} // namespace OHOS
+92
View File
@@ -0,0 +1,92 @@
/*
* Copyright (c) 2021 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 <bytrace.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);
// TODOneed BYTRACE_TAG_WINDOW_MANAGER
StartTrace(BYTRACE_TAG_GRAPHIC_AGP, nameStr);
}
void WmTraceEnd()
{
if (WmTraceEnabled()) {
// TODOneed BYTRACE_TAG_WINDOW_MANAGER
FinishTrace(BYTRACE_TAG_GRAPHIC_AGP);
}
}
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
+22 -12
View File
@@ -43,12 +43,8 @@ config("libwm_config") {
"//foundation/graphic/standard/interfaces/innerkits/common",
# weston adapter end
]
cflags = [
"-Wall",
"-Werror",
"-g3",
"//third_party/jsoncpp/include",
"//third_party/json/include",
]
}
@@ -66,11 +62,12 @@ config("libwm_public_config") {
ohos_shared_library("libwmutil") {
sources = [
"../dmserver/src/display_info.cpp",
"../dmserver/src/virtual_display_info.cpp",
"../utils/src/wm_trace.cpp",
"//foundation/windowmanager/dmserver/src/display_manager_proxy.cpp",
"//foundation/windowmanager/utils/src/singleton_container.cpp",
"//foundation/windowmanager/wm/src/window_proxy.cpp",
"//foundation/windowmanager/wmserver/src/window_manager_proxy.cpp",
"src/window_option.cpp",
"src/window_property.cpp",
]
@@ -85,11 +82,16 @@ ohos_shared_library("libwmutil") {
public_deps = [
# RSSurface
"//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
"//foundation/graphic/standard:libsurface",
"//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base",
"//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client",
]
external_deps = [ "ipc:ipc_core" ]
external_deps = [
"bytrace_standard:bytrace_core",
"ipc:ipc_core",
]
part_name = "window_manager"
subsystem_name = "window"
@@ -110,8 +112,12 @@ ohos_shared_library("libwm") {
"src/window_agent.cpp",
"src/window_impl.cpp",
"src/window_input_channel.cpp",
"src/window_manager.cpp",
"src/window_manager_agent.cpp",
"src/window_option.cpp",
"src/window_scene.cpp",
"src/window_stub.cpp",
"src/zidl/window_manager_agent_stub.cpp",
]
configs = [ ":libwm_config" ]
@@ -120,14 +126,15 @@ ohos_shared_library("libwm") {
deps = [
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//foundation/windowmanager/wm:libwmutil",
"//utils/native/base:utils",
# TODO: fix me
# "//foundation/multimedia/image_standard/interfaces/innerkits:image_native",
# weston adapter
"//foundation/windowmanager/adapter:libwmadaptertest",
"//foundation/windowmanager/adapter:libwmadapter",
# ace
"//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent",
@@ -137,6 +144,7 @@ ohos_shared_library("libwm") {
# native value
# RSSurface
"//foundation/ace/napi:ace_napi",
"//foundation/graphic/standard:libsurface",
# vsync
"//foundation/graphic/standard:libvsync_client",
@@ -148,11 +156,13 @@ ohos_shared_library("libwm") {
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-common",
# weston adapter
"//foundation/windowmanager/adapter:libwmadaptertest",
"//foundation/windowmanager/adapter:libwmadapter",
"//foundation/windowmanager/wm:libwmutil",
]
external_deps = [
"aafwk_standard:ability_context_native",
"bytrace_standard:bytrace_core",
"ipc:ipc_core",
]
+6 -4
View File
@@ -17,7 +17,6 @@
#define OHOS_INPUT_TRANSFER_STATION
#include <refbase.h>
#include <single_instance.h>
#include "input_manager.h"
#include "pointer_event.h"
@@ -28,20 +27,23 @@
namespace OHOS {
namespace Rosen {
class InputEventListener;
class InputTransferStation : public RefBase {
class InputTransferStation {
DECLARE_SINGLE_INSTANCE(InputTransferStation);
friend class InputEventListener;
public:
void AddInputWindow(const sptr<Window>& window);
void RemoveInputWindow(const sptr<Window>& window);
void SetInputListener(uint32_t windowId, std::shared_ptr<MMI::IInputEventConsumer>& listener);
private:
sptr<WindowInputChannel> GetInputChannel(uint32_t windowId);
bool initInputListener_ = false;
std::unordered_map<uint32_t, sptr<WindowInputChannel>> windowInputChannels_;
std::shared_ptr<MMI::IInputEventConsumer> inputListener_;
std::shared_ptr<MMI::IInputEventConsumer> inputListener_ = nullptr;
};
class InputEventListener: public RefBase, public MMI::IInputEventConsumer {
class InputEventListener : public RefBase, public MMI::IInputEventConsumer {
public:
InputEventListener() = default;
void OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent) const override;
+3 -1
View File
@@ -29,7 +29,7 @@
namespace OHOS {
namespace Rosen {
class VsyncStation : public RefBase {
class VsyncStation {
DECLARE_SINGLE_INSTANCE_BASE(VsyncStation);
using OnCallback = std::function<void(int64_t)>;
public:
@@ -48,6 +48,8 @@ private:
VsyncStation() = default;
static void OnVsync(int64_t nanoTimestamp, void* client);
void VsyncCallbackInner(int64_t nanoTimestamp);
std::shared_ptr<AppExecFwk::EventHandler> mainHandler_ = nullptr;
std::mutex lock_;
std::atomic_bool hasRequestedVsync_ {false};
std::map<CallbackType, std::unordered_set<std::shared_ptr<VsyncCallback>>> vsyncCallbacks_ = {
{CallbackType::CALLBACK_INPUT, {}},
+8 -5
View File
@@ -17,6 +17,7 @@
#define OHOS_WINDOW_ADAPTER_H
#include <refbase.h>
#include <zidl/window_manager_agent_interface.h>
#include "window.h"
#include "window_proxy.h"
@@ -31,10 +32,9 @@ public:
virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override;
};
class WindowAdapter : public RefBase {
DECLARE_SINGLE_INSTANCE_BASE(WindowAdapter);
class WindowAdapter {
DECLARE_SINGLE_INSTANCE(WindowAdapter);
public:
~WindowAdapter() = default;
virtual WMError CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& windowProperty,
std::shared_ptr<RSSurfaceNode> surfaceNode, uint32_t& windowId);
virtual WMError AddWindow(sptr<WindowProperty>& windowProperty);
@@ -44,10 +44,13 @@ public:
virtual WMError MoveTo(uint32_t windowId, int32_t x, int32_t y);
virtual WMError Resize(uint32_t windowId, uint32_t width, uint32_t height);
virtual WMError RequestFocus(uint32_t windowId);
virtual WMError SetWindowFlags(uint32_t windowId, uint32_t flags);
virtual WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property);
virtual void RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent);
virtual void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent);
virtual void ClearWindowAdapter();
protected:
WindowAdapter() = default;
private:
static inline SingletonDelegator<WindowAdapter> delegator;
bool InitWMSProxyLocked();
+1
View File
@@ -30,6 +30,7 @@ public:
void UpdateWindowRect(const struct Rect& rect) override;
void UpdateWindowMode(WindowMode mode) override;
void UpdateFocusStatus(bool focused) override;
void UpdateSystemBarProperty(const SystemBarProperty& prop) override;
private:
sptr<WindowImpl> window_;
+26 -3
View File
@@ -21,6 +21,7 @@
#include <ui_content.h>
#include "window.h"
#include "input_transfer_station.h"
#include "vsync_station.h"
#include "window_property.h"
namespace OHOS {
@@ -48,10 +49,17 @@ public:
virtual WindowMode GetMode() const override;
virtual const std::string& GetWindowName() const override;
virtual uint32_t GetWindowId() override;
virtual uint32_t GetWindowFlags() override;
virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) override;
virtual WMError SetWindowType(WindowType type) override;
virtual WMError SetWindowMode(WindowMode mode) 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;
WMError Create(const std::string& parentName, const sptr<IRemoteObject>& abilityToken = nullptr);
WMError Create(const std::string& parentName,
const std::shared_ptr<AbilityRuntime::AbilityContext>& abilityContext = nullptr);
virtual WMError Destroy() override;
virtual WMError Show() override;
virtual WMError Hide() override;
@@ -63,15 +71,20 @@ public:
virtual void RegisterLifeCycleListener(sptr<IWindowLifeCycle>& listener) override;
virtual void RegisterWindowChangeListener(sptr<IWindowChangeListener>& listener) override;
virtual void RegisterWindowSystemBarChangeListener(sptr<IWindowSystemBarChangeListener>& listener) override;
void UpdateRect(const struct Rect& rect);
void UpdateMode(WindowMode mode);
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);
void UpdateSystemBarProperty(const SystemBarProperty& prop);
virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
virtual WMError SetUIContent(std::shared_ptr<AbilityRuntime::AbilityContext> context,
std::string& url, NativeEngine* engine, NativeValue* storage) override;
std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed) override;
virtual const std::string& GetContentInfo() override;
private:
inline void NotifyAfterForeground() const
@@ -88,7 +101,7 @@ private:
}
inline void NotifyAfterUnFocused() const
{
CALL_LIFECYCLE_LISTENER(AfterUnFocused, UnFocus);
CALL_LIFECYCLE_LISTENER(AfterUnfocused, UnFocus);
}
inline void NotifyBeforeDestroy() const
{
@@ -98,6 +111,7 @@ private:
}
void SetDefaultOption(); // for api7
bool IsWindowValid() const;
void OnVsync(int64_t timeStamp);
enum WindowState {
STATE_INITIAL,
@@ -108,14 +122,23 @@ private:
STATE_BOTTOM = STATE_DESTROYED,
};
std::shared_ptr<VsyncStation::VsyncCallback> callback_ =
std::make_shared<VsyncStation::VsyncCallback>(VsyncStation::VsyncCallback());
static std::map<std::string, std::pair<uint32_t, sptr<Window>>> windowMap_;
static std::map<uint32_t, std::vector<sptr<Window>>> subWindowMap_;
sptr<WindowProperty> property_;
WindowState state_ { STATE_INITIAL };
sptr<IWindowLifeCycle> lifecycleListener_;
sptr<IWindowChangeListener> windowChangeListener_;
sptr<IWindowSystemBarChangeListener> systemBarChangeListener_;
std::shared_ptr<RSSurfaceNode> surfaceNode_;
std::string name_;
std::unique_ptr<Ace::UIContent> uiContent_;
std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
const float STATUS_BAR_RATIO = 0.07;
const float NAVIGATION_BAR_RATIO = 0.07;
const float SYSTEM_ALARM_WINDOW_WIDTH_RATIO = 0.8;
const float SYSTEM_ALARM_WINDOW_HEIGHT_RATIO = 0.3;
};
}
}
+2
View File
@@ -30,12 +30,14 @@ public:
TRANS_ID_UPDATE_WINDOW_RECT,
TRANS_ID_UPDATE_WINDOW_MODE,
TRANS_ID_UPDATE_FOCUS_STATUS,
TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY,
};
virtual void UpdateWindowProperty(const WindowProperty& windowProperty) = 0;
virtual void UpdateWindowRect(const struct Rect& rect) = 0;
virtual void UpdateWindowMode(WindowMode mode) = 0;
virtual void UpdateFocusStatus(bool focused) = 0;
virtual void UpdateSystemBarProperty(const SystemBarProperty& prop) = 0;
};
} // namespace Rosen
} // namespace OHOS
+33
View File
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2021 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_WINDOW_MANAGER_AGENT_H
#define OHOS_WINDOW_MANAGER_AGENT_H
#include "zidl/window_manager_agent_stub.h"
namespace OHOS {
namespace Rosen {
class WindowManagerAgent : public WindowManagerAgentStub {
public:
WindowManagerAgent() = default;
~WindowManagerAgent() = default;
void UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
int32_t displayId, bool focused) override;
};
} // namespace Rosen
} // namespace OHOS
#endif // OHOS_WINDOW_MANAGER_AGENT_H
+9 -1
View File
@@ -18,6 +18,7 @@
#include <refbase.h>
#include <string>
#include <unordered_map>
#include "parcel.h"
#include "wm_common.h"
@@ -41,6 +42,7 @@ public:
void SetWindowId(uint32_t windowId);
void SetParentId(uint32_t parentId);
void SetWindowFlags(uint32_t flags);
void SetSystemBarProperty(WindowType type, const SystemBarProperty& state);
Rect GetWindowRect() const;
WindowType GetWindowType() const;
@@ -55,10 +57,10 @@ public:
uint32_t GetWindowId() const;
uint32_t GetParentId() const;
uint32_t GetWindowFlags() const;
const std::unordered_map<WindowType, SystemBarProperty>& GetSystemBarProperty() const;
virtual bool Marshalling(Parcel& parcel) const override;
static sptr<WindowProperty> Unmarshalling(Parcel& parcel);
private:
Rect windowRect_ { 0, 0, 0, 0 };
WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
@@ -73,6 +75,12 @@ private:
int32_t displayId_ { 0 };
uint32_t windowId_ { 0 };
uint32_t parentId_ { 0 };
std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ {
{ WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() },
{ WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() },
};
bool MapMarshalling(Parcel& parcel) const;
static void MapUnmarshalling(Parcel& parcel, sptr<WindowProperty>& property);
};
}
}
+1
View File
@@ -31,6 +31,7 @@ public:
void UpdateWindowRect(const struct Rect& rect) override;
void UpdateWindowMode(WindowMode mode) override;
void UpdateFocusStatus(bool focused) override;
void UpdateSystemBarProperty(const SystemBarProperty& prop) override;
private:
static inline BrokerDelegator<WindowProxy> delegator_;
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2021 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_WINDOW_MANAGER_AGENT_INTERFACE_H
#define OHOS_WINDOW_MANAGER_AGENT_INTERFACE_H
#include <iremote_broker.h>
#include "wm_common.h"
namespace OHOS {
namespace Rosen {
class IWindowManagerAgent : public IRemoteBroker {
public:
DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IWindowManagerAgent");
enum {
TRANS_ID_UPDATE_FOCUS_STATUS = 1,
};
virtual void UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
int32_t displayId, bool focused) = 0;
};
} // namespace Rosen
} // namespace OHOS
#endif // OHOS_WINDOW_MANAGER_AGENT_INTERFACE_H
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2021 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_WINDOW_MANAGER_AGENT_PROXY_H
#define OHOS_WINDOW_MANAGER_AGENT_PROXY_H
#include "window_manager_agent_interface.h"
#include "iremote_proxy.h"
namespace OHOS {
namespace Rosen {
class WindowManagerAgentProxy : public IRemoteProxy<IWindowManagerAgent> {
public:
explicit WindowManagerAgentProxy(const sptr<IRemoteObject>& impl) : IRemoteProxy<IWindowManagerAgent>(impl) {};
~WindowManagerAgentProxy() {};
void UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
int32_t displayId, bool focused) override;
private:
static inline BrokerDelegator<WindowManagerAgentProxy> delegator_;
};
} // namespace Rosen
} // namespace OHOS
#endif // OHOS_WINDOW_MANAGER_PROXY_H
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2021 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_WINDOW_MANAGER_AGENT_STUB_H
#define OHOS_WINDOW_MANAGER_AGENT_STUB_H
#include "window_manager_agent_interface.h"
#include "iremote_stub.h"
namespace OHOS {
namespace Rosen {
class WindowManagerAgentStub : public IRemoteStub<IWindowManagerAgent> {
public:
WindowManagerAgentStub() = default;
~WindowManagerAgentStub() = default;
virtual int OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply,
MessageOption& option) override;
};
} // namespace Rosen
} // namespace OHOS
#endif // OHOS_WINDOW_MANAGER_AGENT_STUB_H
+2 -3
View File
@@ -21,7 +21,6 @@ namespace Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "InputTransferStation"};
}
IMPLEMENT_SINGLE_INSTANCE(InputTransferStation)
void InputEventListener::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) const
{
WLOGFI("OnInputEvent: receive keyEvent");
@@ -30,7 +29,7 @@ void InputEventListener::OnInputEvent(std::shared_ptr<MMI::KeyEvent> keyEvent) c
return;
}
uint32_t windowId = keyEvent->GetAgentWindowId();
auto channel = InputTransferStation::GetInstance()->GetInputChannel(windowId);
auto channel = InputTransferStation::GetInstance().GetInputChannel(windowId);
if (channel == nullptr) {
WLOGE("OnInputEvent channel is nullptr");
return;
@@ -56,7 +55,7 @@ void InputEventListener::OnInputEvent(std::shared_ptr<MMI::PointerEvent> pointer
return;
}
uint32_t windowId = pointerEvent->GetAgentWindowId();
auto channel = InputTransferStation::GetInstance()->GetInputChannel(windowId);
auto channel = InputTransferStation::GetInstance().GetInputChannel(windowId);
if (channel == nullptr) {
WLOGE("OnInputEvent channel is nullptr");
return;
+20 -10
View File
@@ -23,25 +23,34 @@ namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "VsyncStation"};
}
IMPLEMENT_SINGLE_INSTANCE(VsyncStation);
void VsyncStation::RequestVsync(CallbackType type, std::shared_ptr<VsyncCallback> vsyncCallback)
{
std::lock_guard<std::mutex> lock_l(lock_);
auto iter = vsyncCallbacks_.find(type);
if (iter == vsyncCallbacks_.end()) {
WLOGFE("wrong callback type.");
return;
}
iter->second.insert(vsyncCallback);
if (!hasRequestedVsync_) {
hasRequestedVsync_.store(true);
callback_.timestamp_ = 0;
callback_.userdata_ = this;
callback_.callback_ = OnVsync;
VsyncError ret = VsyncHelper::Current()->RequestFrameCallback(callback_);
if (ret != VSYNC_ERROR_OK) {
WLOGFE("VsyncStation::RequestNextVsync fail: %s", VsyncErrorStr(ret).c_str());
if (mainHandler_ == nullptr) {
if (AppExecFwk::EventRunner::GetMainEventRunner() == nullptr) {
WLOGFE("can not get main event runner.");
return;
}
mainHandler_ = std::make_shared<AppExecFwk::EventHandler>(AppExecFwk::EventRunner::GetMainEventRunner());
}
if (!hasRequestedVsync_) {
mainHandler_->PostTask([this]() {
callback_.timestamp_ = 0;
callback_.userdata_ = this;
callback_.callback_ = OnVsync;
WLOGFI("request vsync start.");
VsyncError ret = VsyncHelper::Current()->RequestFrameCallback(callback_);
if (ret != VSYNC_ERROR_OK) {
WLOGFE("VsyncStation::RequestNextVsync fail: %{public}s", VsyncErrorStr(ret).c_str());
}
});
hasRequestedVsync_.store(true);
}
}
@@ -58,6 +67,7 @@ void VsyncStation::VsyncCallbackInner(int64_t timestamp)
void VsyncStation::OnVsync(int64_t timestamp, void* client)
{
WLOGFI("on vsync callback.");
auto vsyncClient = static_cast<VsyncStation*>(client);
if (vsyncClient) {
vsyncClient->VsyncCallbackInner(timestamp);
+8 -2
View File
@@ -14,6 +14,7 @@
*/
#include "window.h"
#include "window_helper.h"
#include "window_impl.h"
#include "window_manager_hilog.h"
@@ -23,7 +24,7 @@ namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowImpl"};
}
sptr<Window> Window::Create(const std::string& windowName, sptr<WindowOption>& option,
const sptr<IRemoteObject>& abilityToken)
const std::shared_ptr<AbilityRuntime::AbilityContext>& abilityContext)
{
if (windowName.empty()) {
WLOGFE("window name is empty");
@@ -32,9 +33,14 @@ sptr<Window> Window::Create(const std::string& windowName, sptr<WindowOption>& o
if (option == nullptr) {
option = new WindowOption();
}
WindowType type = option->GetWindowType();
if (!(WindowHelper::IsAppWindow(type) || WindowHelper::IsSystemWindow(type))) {
WLOGFE("window type is invalid %{public}d", type);
return nullptr;
}
option->SetWindowName(windowName);
sptr<WindowImpl> windowImpl = new WindowImpl(option);
WMError error = windowImpl->Create(option->GetParentName(), abilityToken);
WMError error = windowImpl->Create(option->GetParentName(), abilityContext);
if (error != WMError::WM_OK) {
return nullptr;
}
+42 -5
View File
@@ -25,8 +25,6 @@ namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowAdapter"};
}
IMPLEMENT_SINGLE_INSTANCE(WindowAdapter);
WMError WindowAdapter::SaveAbilityToken(const sptr<IRemoteObject>& abilityToken, uint32_t windowId)
{
std::lock_guard<std::mutex> lock(mutex_);
@@ -108,6 +106,46 @@ WMError WindowAdapter::RequestFocus(uint32_t windowId)
return windowManagerServiceProxy_->RequestFocus(windowId);
}
WMError WindowAdapter::SetWindowFlags(uint32_t windowId, uint32_t flags)
{
std::lock_guard<std::mutex> lock(mutex_);
if (!InitWMSProxyLocked()) {
return WMError::WM_ERROR_SAMGR;
}
return windowManagerServiceProxy_->SetWindowFlags(windowId, flags);
}
WMError WindowAdapter::SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property)
{
std::lock_guard<std::mutex> lock(mutex_);
if (!InitWMSProxyLocked()) {
return WMError::WM_ERROR_SAMGR;
}
return windowManagerServiceProxy_->SetSystemBarProperty(windowId, type, property);
}
void WindowAdapter::RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
{
std::lock_guard<std::mutex> lock(mutex_);
if (!InitWMSProxyLocked()) {
return;
}
return windowManagerServiceProxy_->RegisterFocusChangedListener(windowManagerAgent);
}
void WindowAdapter::UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
{
std::lock_guard<std::mutex> lock(mutex_);
if (!InitWMSProxyLocked()) {
return;
}
return windowManagerServiceProxy_->UnregisterFocusChangedListener(windowManagerAgent);
}
bool WindowAdapter::InitWMSProxyLocked()
{
if (!windowManagerServiceProxy_) {
@@ -136,8 +174,7 @@ bool WindowAdapter::InitWMSProxyLocked()
return false;
}
if (!remoteObject->AddDeathRecipient(wmsDeath_)) {
WLOGFE("Failed to add death recipient");
return false;
WLOGFI("Failed to add death recipient");
}
}
return true;
@@ -164,7 +201,7 @@ void WMSDeathRecipient::OnRemoteDied(const wptr<IRemoteObject>& wptrDeath)
WLOGFE("object is null");
return;
}
SingletonContainer::Get<WindowAdapter>()->ClearWindowAdapter();
SingletonContainer::Get<WindowAdapter>().ClearWindowAdapter();
return;
}
} // namespace Rosen
+9
View File
@@ -57,5 +57,14 @@ void WindowAgent::UpdateFocusStatus(bool focused)
}
window_->UpdateFocusStatus(focused);
}
void WindowAgent::UpdateSystemBarProperty(const SystemBarProperty& prop)
{
if (window_ == nullptr) {
WLOGFE("window_ is nullptr");
return;
}
window_->UpdateSystemBarProperty(prop);
}
} // namespace Rosen
} // namespace OHOS
+223 -31
View File
@@ -18,6 +18,7 @@
#include "singleton_container.h"
#include "window_adapter.h"
#include "window_agent.h"
#include "window_helper.h"
#include "window_manager_hilog.h"
#ifndef _NEW_RENDERSERVER_
#include "adapter.h"
@@ -30,6 +31,7 @@ namespace {
}
std::map<std::string, std::pair<uint32_t, sptr<Window>>> WindowImpl::windowMap_;
std::map<uint32_t, std::vector<sptr<Window>>> WindowImpl::subWindowMap_;
WindowImpl::WindowImpl(const sptr<WindowOption>& option)
{
@@ -42,7 +44,12 @@ WindowImpl::WindowImpl(const sptr<WindowOption>& option)
property_->SetTouchable(option->GetTouchable());
property_->SetDisplayId(option->GetDisplayId());
property_->SetWindowFlags(option->GetWindowFlags());
auto& sysBarPropMap = option->GetSystemBarProperty();
for (auto it : sysBarPropMap) {
property_->SetSystemBarProperty(it.first, it.second);
}
name_ = option->GetWindowName();
callback_->onCallback = std::bind(&WindowImpl::OnVsync, this, std::placeholders::_1);
#ifdef _NEW_RENDERSERVER_
struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
@@ -94,13 +101,29 @@ uint32_t WindowImpl::GetWindowId()
return property_->GetWindowId();
}
uint32_t WindowImpl::GetWindowFlags()
{
return property_->GetWindowFlags();
}
SystemBarProperty WindowImpl::GetSystemBarPropertyByType(WindowType type)
{
auto curProperties = property_->GetSystemBarProperty();
return curProperties[type];
}
WMError WindowImpl::SetWindowType(WindowType type)
{
WLOGFI("window id: %{public}d, type:%{public}d", property_->GetWindowId(), static_cast<uint32_t>(type));
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
if (state_ == STATE_CREATED) {
if (!(WindowHelper::IsAppWindow(type) || WindowHelper::IsSystemWindow(type))) {
WLOGFE("window type is invalid %{public}d", type);
return WMError::WM_ERROR_INVALID_PARAM;
}
property_->SetWindowType(type);
return WMError::WM_OK;
}
@@ -126,8 +149,41 @@ WMError WindowImpl::SetWindowMode(WindowMode mode)
return WMError::WM_OK;
}
WMError WindowImpl::AddWindowFlag(WindowFlag flag)
{
uint32_t updateFlags = property_->GetWindowFlags() | (static_cast<uint32_t>(flag));
return SetWindowFlags(updateFlags);
}
WMError WindowImpl::RemoveWindowFlag(WindowFlag flag)
{
uint32_t updateFlags = property_->GetWindowFlags() & (~(static_cast<uint32_t>(flag)));
return SetWindowFlags(updateFlags);
}
WMError WindowImpl::SetWindowFlags(uint32_t flags)
{
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
if (property_->GetWindowFlags() == flags) {
return WMError::WM_OK;
}
property_->SetWindowFlags(flags);
if (state_ == STATE_CREATED || state_ == STATE_HIDDEN) {
return WMError::WM_OK;
}
WMError ret = SingletonContainer::Get<WindowAdapter>().SetWindowFlags(property_->GetWindowId(), flags);
if (ret != WMError::WM_OK) {
WLOGFE("SetWindowFlags errCode:%{public}d winId:%{public}d",
static_cast<int32_t>(ret), property_->GetWindowId());
}
return ret;
}
WMError WindowImpl::SetUIContent(std::shared_ptr<AbilityRuntime::AbilityContext> context,
std::string& url, NativeEngine* engine, NativeValue* storage)
std::string& contentInfo, NativeEngine* engine, NativeValue* storage, bool isdistributed)
{
WLOGFI("SetUIContent");
uiContent_ = Ace::UIContent::Create(context.get(), engine);
@@ -135,12 +191,52 @@ WMError WindowImpl::SetUIContent(std::shared_ptr<AbilityRuntime::AbilityContext>
WLOGFE("fail to SetUIContent id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_NULLPTR;
}
uiContent_->Initialize(this, url, storage);
// TODO: fix me
// if (isdistributed) {
// uiContent_->Restore(this, contentInfo, storage);
// } else {
// uiContent_->Initialize(this, contentInfo, storage);
// }
return WMError::WM_OK;
}
WMError WindowImpl::Create(const std::string& parentName, const sptr<IRemoteObject>& abilityToken)
const std::string& WindowImpl::GetContentInfo()
{
WLOGFI("GetContentInfo");
if (uiContent_ == nullptr) {
WLOGFE("fail to GetContentInfo id: %{public}d", property_->GetWindowId());
return "";
}
// TODO: fix me - uiContent_->GetContentInfo()
return "";
}
WMError WindowImpl::SetSystemBarProperty(WindowType type, const SystemBarProperty& property)
{
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
if (GetSystemBarPropertyByType(type) == property) {
return WMError::WM_OK;
}
property_->SetSystemBarProperty(type, property);
if (state_ == STATE_CREATED || state_ == STATE_HIDDEN) {
return WMError::WM_OK;
}
WMError ret = SingletonContainer::Get<WindowAdapter>().SetSystemBarProperty(property_->GetWindowId(),
type, property);
if (ret != WMError::WM_OK) {
WLOGFE("SetSystemBarProperty errCode:%{public}d winId:%{public}d",
static_cast<int32_t>(ret), property_->GetWindowId());
}
return ret;
}
WMError WindowImpl::Create(const std::string& parentName,
const std::shared_ptr<AbilityRuntime::AbilityContext>& abilityContext)
{
WLOGFI("[Client] Window Create");
#ifdef _NEW_RENDERSERVER_
// check window name, same window names are forbidden
if (windowMap_.find(name_) != windowMap_.end()) {
@@ -161,7 +257,7 @@ WMError WindowImpl::Create(const std::string& parentName, const sptr<IRemoteObje
sptr<WindowImpl> window(this);
sptr<IWindow> windowAgent(new WindowAgent(window));
uint32_t windowId = 0;
WMError ret = SingletonContainer::Get<WindowAdapter>()->CreateWindow(windowAgent, property_, surfaceNode_,
WMError ret = SingletonContainer::Get<WindowAdapter>().CreateWindow(windowAgent, property_, surfaceNode_,
windowId);
property_->SetWindowId(windowId);
@@ -169,17 +265,20 @@ WMError WindowImpl::Create(const std::string& parentName, const sptr<IRemoteObje
WLOGFE("create window failed with errCode:%{public}d", static_cast<int32_t>(ret));
return ret;
}
if (abilityToken != nullptr) {
ret = SingletonContainer::Get<WindowAdapter>()->SaveAbilityToken(abilityToken, windowId);
if (abilityContext != nullptr) {
ret = SingletonContainer::Get<WindowAdapter>().SaveAbilityToken(abilityContext->GetAbilityToken(), windowId);
abilityContext_ = abilityContext;
if (ret != WMError::WM_OK) {
WLOGFE("SaveAbilityToken failed with errCode:%{public}d", static_cast<int32_t>(ret));
return ret;
}
}
windowMap_.insert({ name_, std::pair<uint32_t, sptr<Window>>(windowId, this) });
if (parentName != "") { // add to subWindowMap_
subWindowMap_[property_->GetParentId()].push_back(this);
}
state_ = STATE_CREATED;
WLOGFI("create window success with winId:%{public}d", windowId);
InputTransferStation::GetInstance()->AddInputWindow(this);
InputTransferStation::GetInstance().AddInputWindow(this);
return ret;
#else
/* weston adapter */
@@ -191,19 +290,30 @@ WMError WindowImpl::Destroy()
{
NotifyBeforeDestroy();
#ifdef _NEW_RENDERSERVER_
WLOGFI("[Client] Window %{public}d Destroy", property_->GetWindowId());
// should destroy surface here
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_OK;
}
WLOGFI("destroy window id: %{public}d", property_->GetWindowId());
WMError ret = SingletonContainer::Get<WindowAdapter>()->DestroyWindow(property_->GetWindowId());
WMError ret = SingletonContainer::Get<WindowAdapter>().DestroyWindow(property_->GetWindowId());
windowMap_.erase(GetWindowName());
if (subWindowMap_.count(property_->GetParentId()) > 0) { // remove from subWindowMap_
std::vector<sptr<Window>>& subWindows = subWindowMap_.at(property_->GetParentId());
for (auto iter = subWindows.begin(); iter < subWindows.end(); ++iter) {
if ((*iter)->GetWindowId() == GetWindowId()) {
subWindows.erase(iter);
break;
}
}
}
subWindowMap_.erase(GetWindowId());
state_ = STATE_DESTROYED;
InputTransferStation::GetInstance()->RemoveInputWindow(this);
InputTransferStation::GetInstance().RemoveInputWindow(this);
return ret;
#else
InputTransferStation::GetInstance()->RemoveInputWindow(this);
InputTransferStation::GetInstance().RemoveInputWindow(this);
Adapter::DestroyWestonWindow();
#endif
return WMError::WM_OK;
@@ -212,6 +322,7 @@ WMError WindowImpl::Destroy()
WMError WindowImpl::Show()
{
#ifdef _NEW_RENDERSERVER_
WLOGFI("[Client] Window %{public}d Show", property_->GetWindowId());
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
@@ -221,15 +332,13 @@ WMError WindowImpl::Show()
return WMError::WM_OK;
}
SetDefaultOption();
WMError ret = SingletonContainer::Get<WindowAdapter>()->AddWindow(property_);
WMError ret = SingletonContainer::Get<WindowAdapter>().AddWindow(property_);
if (ret == WMError::WM_OK || ret == WMError::WM_ERROR_DEATH_RECIPIENT) {
Rect rect = property_->GetWindowRect();
WLOGFI("show x: %{public}d ; y: %{public}d; width: %{public}d; height: %{public}d, winId:%{public}d;",
rect.posX_, rect.posY_, rect.width_, rect.height_, property_->GetWindowId());
state_ = STATE_SHOWN;
NotifyAfterForeground();
} else {
WLOGFE("show errCode:%{public}d for winId:%{public}d", static_cast<int32_t>(ret), property_->GetWindowId());
}
WLOGFE("show errCode:%{public}d for winId:%{public}d", static_cast<int32_t>(ret), property_->GetWindowId());
return ret;
#else
/* weston adapter */
@@ -241,7 +350,7 @@ WMError WindowImpl::Show()
} else {
WLOGFE("Show error=%d", static_cast<int>(rtn));
}
InputTransferStation::GetInstance()->AddInputWindow(this);
InputTransferStation::GetInstance().AddInputWindow(this);
return rtn;
#endif
}
@@ -249,6 +358,7 @@ WMError WindowImpl::Show()
WMError WindowImpl::Hide()
{
#ifdef _NEW_RENDERSERVER_
WLOGFI("[Client] Window %{public}d Hide", property_->GetWindowId());
if (!IsWindowValid()) {
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
@@ -257,9 +367,9 @@ WMError WindowImpl::Hide()
WLOGFI("window is already hidden id: %{public}d", property_->GetWindowId());
return WMError::WM_OK;
}
WMError ret = SingletonContainer::Get<WindowAdapter>()->RemoveWindow(property_->GetWindowId());
WLOGFI("hide errCode:%{public}d for winId:%{public}d", static_cast<int32_t>(ret), property_->GetWindowId());
WMError ret = SingletonContainer::Get<WindowAdapter>().RemoveWindow(property_->GetWindowId());
if (ret != WMError::WM_OK) {
WLOGFE("hide errCode:%{public}d for winId:%{public}d", static_cast<int32_t>(ret), property_->GetWindowId());
return ret;
}
state_ = STATE_HIDDEN;
@@ -275,7 +385,7 @@ WMError WindowImpl::Hide()
} else {
WLOGFE("WindowImpl::Show error=%d", static_cast<int>(rtn));
}
InputTransferStation::GetInstance()->RemoveInputWindow(this);
InputTransferStation::GetInstance().RemoveInputWindow(this);
return rtn;
#endif
}
@@ -295,7 +405,7 @@ WMError WindowImpl::MoveTo(int32_t x, int32_t y)
property_->GetWindowId(), rect.posX_, rect.posY_, x, y);
return WMError::WM_OK;
}
return SingletonContainer::Get<WindowAdapter>()->MoveTo(property_->GetWindowId(), x, y);
return SingletonContainer::Get<WindowAdapter>().MoveTo(property_->GetWindowId(), x, y);
#else
return Adapter::MoveTo(x, y);
#endif
@@ -316,7 +426,7 @@ WMError WindowImpl::Resize(uint32_t width, uint32_t height)
property_->GetWindowId(), rect.posX_, rect.posY_, width, height);
return WMError::WM_OK;
}
return SingletonContainer::Get<WindowAdapter>()->Resize(property_->GetWindowId(), width, height);
return SingletonContainer::Get<WindowAdapter>().Resize(property_->GetWindowId(), width, height);
#else
return Adapter::Resize(width, height);
#endif
@@ -328,12 +438,12 @@ WMError WindowImpl::RequestFocus() const
WLOGFI("window is already destroyed or not created! id: %{public}d", property_->GetWindowId());
return WMError::WM_ERROR_INVALID_WINDOW;
}
return SingletonContainer::Get<WindowAdapter>()->RequestFocus(property_->GetWindowId());
return SingletonContainer::Get<WindowAdapter>().RequestFocus(property_->GetWindowId());
}
void WindowImpl::AddInputEventListener(std::shared_ptr<MMI::IInputEventConsumer>& inputEventListener)
{
InputTransferStation::GetInstance()->SetInputListener(GetWindowId(), inputEventListener);
InputTransferStation::GetInstance().SetInputListener(GetWindowId(), inputEventListener);
}
void WindowImpl::RegisterLifeCycleListener(sptr<IWindowLifeCycle>& listener)
@@ -346,12 +456,24 @@ void WindowImpl::RegisterWindowChangeListener(sptr<IWindowChangeListener>& liste
windowChangeListener_ = listener;
}
void WindowImpl::RegisterWindowSystemBarChangeListener(sptr<IWindowSystemBarChangeListener>& listener)
{
systemBarChangeListener_ = listener;
}
void WindowImpl::UpdateRect(const struct Rect& rect)
{
WLOGFI("winId:%{public}d, rect[%{public}d, %{public}d, %{public}d, %{public}d]", GetWindowId(), rect.posX_,
rect.posY_, rect.width_, rect.height_);
property_->SetWindowRect(rect);
if (windowChangeListener_ != nullptr) {
windowChangeListener_->OnSizeChange(rect);
}
if (uiContent_ != nullptr) {
Ace::ViewportConfig config;
config.SetSize(rect.width_, rect.height_);
uiContent_->UpdateViewportConfig(config);
WLOGFI("notify uiContent window size change end");
}
}
void WindowImpl::UpdateMode(WindowMode mode)
@@ -361,13 +483,53 @@ void WindowImpl::UpdateMode(WindowMode mode)
void WindowImpl::ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent>& keyEvent)
{
uiContent_->ProcessKeyEvent(keyEvent);
int32_t keyCode = keyEvent->GetKeyCode();
int32_t keyAction = keyEvent->GetKeyAction();
WLOGFI("ConsumeKeyEvent: enter GetKeyCode: %{public}d, action: %{public}d", keyCode, keyAction);
if (keyCode == MMI::KeyEvent::KEYCODE_BACK) {
if (keyAction != MMI::KeyEvent::KEY_ACTION_UP) {
return;
}
if (uiContent_ != nullptr && uiContent_->ProcessBackPressed()) {
WLOGI("ConsumeKeyEvent keyEvent is consumed");
return;
}
if (abilityContext_ != nullptr) {
WLOGI("ConsumeKeyEvent ability TerminateSelf");
abilityContext_->TerminateSelf();
} else {
WLOGI("ConsumeKeyEvent destroy window");
Destroy();
}
} else {
if (uiContent_ == nullptr) {
WLOGE("ConsumeKeyEvent uiContent is nullptr");
return;
}
if (!uiContent_->ProcessKeyEvent(keyEvent)) {
WLOGI("ConsumeKeyEvent no comsumer window exit");
}
}
}
void WindowImpl::ConsumePointerEvent(std::shared_ptr<MMI::PointerEvent>& pointerEvent)
{
if (uiContent_ == nullptr) {
WLOGE("ConsumePointerEvent uiContent is nullptr");
return;
}
uiContent_->ProcessPointerEvent(pointerEvent);
}
void WindowImpl::OnVsync(int64_t timeStamp)
{
uiContent_->ProcessVsyncEvent(timeStamp);
}
void WindowImpl::RequestFrame()
{
VsyncStation::GetInstance().RequestVsync(VsyncStation::CallbackType::CALLBACK_FRAME, callback_);
}
void WindowImpl::UpdateFocusStatus(bool focused)
{
WLOGFI("window focus status: %{public}d, id: %{public}d", focused, property_->GetWindowId());
@@ -378,9 +540,34 @@ void WindowImpl::UpdateFocusStatus(bool focused)
}
}
void WindowImpl::UpdateSystemBarProperty(const SystemBarProperty& prop)
{
WLOGFI("winId:%{public}d, enable:%{public}d, backgroundColor:%{public}x, contentColor:%{public}x", GetWindowId(),
prop.enable_, prop.backgroundColor_, prop.contentColor_);
if (systemBarChangeListener_ != nullptr) {
systemBarChangeListener_->OnSystemBarPropertyChange(property_->GetDisplayId(),
property_->GetWindowType(), prop);
}
}
void WindowImpl::UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration)
{
if (uiContent_ != nullptr) {
WLOGFD("notify ace winId:%{public}d", GetWindowId());
// TODO: fix me
// uiContent_->UpdateConfiguration(configuration);
}
if (subWindowMap_.count(GetWindowId()) == 0) {
return;
}
for (auto& subWindow : subWindowMap_.at(GetWindowId())) {
subWindow->UpdateConfiguration(configuration);
}
}
void WindowImpl::SetDefaultOption()
{
auto display = DisplayManager::GetInstance()->GetDisplayById(property_->GetDisplayId());
auto display = DisplayManager::GetInstance().GetDisplayById(property_->GetDisplayId());
if (display == nullptr) {
WLOGFE("get display failed displayId:%{public}d, window id:%{public}u", property_->GetDisplayId(),
property_->GetWindowId());
@@ -393,21 +580,23 @@ void WindowImpl::SetDefaultOption()
Rect rect;
switch (property_->GetWindowType()) {
case WindowType::WINDOW_TYPE_STATUS_BAR: {
rect = { 0, 0, width, static_cast<uint32_t>((static_cast<float>(height) * 0.07)) };
rect = { 0, 0, width, static_cast<uint32_t>((static_cast<float>(height) * STATUS_BAR_RATIO)) };
property_->SetWindowRect(rect);
property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
break;
}
case WindowType::WINDOW_TYPE_NAVIGATION_BAR: {
uint32_t navHeight = static_cast<uint32_t>((static_cast<float>(height) * 0.07));
uint32_t navHeight = static_cast<uint32_t>((static_cast<float>(height) * NAVIGATION_BAR_RATIO));
rect = { 0, static_cast<int32_t>(height - navHeight), width, navHeight };
property_->SetWindowRect(rect);
property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
break;
}
case WindowType::WINDOW_TYPE_SYSTEM_ALARM_WINDOW: {
uint32_t alarmWidth = static_cast<uint32_t>((static_cast<float>(width) * 0.8));
uint32_t alarmHeight = static_cast<uint32_t>((static_cast<float>(height) * 0.3));
uint32_t alarmWidth = static_cast<uint32_t>((static_cast<float>(width) *
SYSTEM_ALARM_WINDOW_WIDTH_RATIO));
uint32_t alarmHeight = static_cast<uint32_t>((static_cast<float>(height) *
SYSTEM_ALARM_WINDOW_HEIGHT_RATIO));
rect = { static_cast<int32_t>((width - alarmWidth) / 2), static_cast<int32_t>((height - alarmHeight) / 2),
alarmWidth, alarmHeight };
@@ -415,10 +604,13 @@ void WindowImpl::SetDefaultOption()
property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
break;
}
case WindowType::WINDOW_TYPE_DRAGGING_EFFECT: {
property_->SetWindowFlags(0);
break;
}
default:
break;
}
}
bool WindowImpl::IsWindowValid() const
{
+5 -2
View File
@@ -56,8 +56,10 @@ void WindowInputChannel::HandlePointerEvent(std::shared_ptr<MMI::PointerEvent>&
pointerEventPool_.clear();
}
pointerEventPool_.emplace_back(pointerEvent);
VsyncStation::GetInstance()->RequestVsync(VsyncStation::CallbackType::CALLBACK_INPUT, callback_);
WLOGI("HandlePointerEvent RequestVsync");
VsyncStation::GetInstance().RequestVsync(VsyncStation::CallbackType::CALLBACK_INPUT, callback_);
} else {
WLOGI("HandlePointerEvent cosume non-move");
window_->ConsumePointerEvent(pointerEvent);
pointerEvent->MarkProcessed();
}
@@ -70,7 +72,8 @@ void WindowInputChannel::OnVsync(int64_t timeStamp)
return;
}
auto pointerEvent = pointerEventPool_.back();
HandlePointerEvent(pointerEvent);
WLOGI("HandlePointerEvent onVsync consume move");
window_->ConsumePointerEvent(pointerEvent);
pointerEvent->MarkProcessed();
pointerEventPool_.clear();
}
+116
View File
@@ -0,0 +1,116 @@
/*
* Copyright (c) 2021 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 "foundation/windowmanager/interfaces/innerkits/wm/window_manager.h"
#include <algorithm>
#include "window_adapter.h"
#include "window_manager_agent.h"
#include "window_manager_hilog.h"
namespace OHOS {
namespace Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManager"};
}
class WindowManager::Impl {
public:
void NotifyFocused(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
WindowType windowType, int32_t displayId) const;
void NotifyUnfocused(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
WindowType windowType, int32_t displayId) const;
static inline SingletonDelegator<WindowManager> delegator_;
std::mutex mutex_;
std::vector<sptr<IFocusChangedListener>> focusChangedListeners_;
sptr<WindowManagerAgent> focusChangedListenerAgent_;
};
void WindowManager::Impl::NotifyFocused(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
WindowType windowType, int32_t displayId) const
{
WLOGFI("NotifyFocused [%{public}d; %{public}p; %{public}d; %{public}d]", windowId, abilityToken.GetRefPtr(),
static_cast<uint32_t>(windowType), displayId);
for (auto& listener : focusChangedListeners_) {
listener->OnFocused(windowId, abilityToken, windowType, displayId);
}
}
void WindowManager::Impl::NotifyUnfocused(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
WindowType windowType, int32_t displayId) const
{
WLOGFI("NotifyUnfocused [%{public}d; %{public}p; %{public}d; %{public}d]", windowId, abilityToken.GetRefPtr(),
static_cast<uint32_t>(windowType), displayId);
for (auto& listener : focusChangedListeners_) {
listener->OnUnfocused(windowId, abilityToken, windowType, displayId);
}
}
WindowManager::WindowManager() : pImpl_(std::make_unique<Impl>())
{
}
WindowManager::~WindowManager()
{
}
void WindowManager::RegisterFocusChangedListener(const sptr<IFocusChangedListener>& listener)
{
if (listener == nullptr) {
WLOGFE("listener could not be null");
return;
}
std::lock_guard<std::mutex> lock(pImpl_->mutex_);
pImpl_->focusChangedListeners_.push_back(listener);
if (pImpl_->focusChangedListenerAgent_ == nullptr) {
pImpl_->focusChangedListenerAgent_ = new WindowManagerAgent();
SingletonContainer::Get<WindowAdapter>().RegisterFocusChangedListener(pImpl_->focusChangedListenerAgent_);
}
}
void WindowManager::UnregisterFocusChangedListener(const sptr<IFocusChangedListener>& listener)
{
if (listener == nullptr) {
WLOGFE("listener could not be null");
return;
}
std::lock_guard<std::mutex> lock(pImpl_->mutex_);
auto iter = std::find(pImpl_->focusChangedListeners_.begin(), pImpl_->focusChangedListeners_.end(), listener);
if (iter == pImpl_->focusChangedListeners_.end()) {
WLOGFE("could not find this listener");
return;
}
pImpl_->focusChangedListeners_.erase(iter);
if (pImpl_->focusChangedListeners_.empty() && pImpl_->focusChangedListenerAgent_ != nullptr) {
SingletonContainer::Get<WindowAdapter>().UnregisterFocusChangedListener(pImpl_->focusChangedListenerAgent_);
}
}
void WindowManager::UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
int32_t displayId, bool focused) const
{
WLOGFI("window focus status: %{public}d, id: %{public}d", focused, windowId);
if (focused) {
pImpl_->NotifyFocused(windowId, abilityToken, windowType, displayId);
} else {
pImpl_->NotifyUnfocused(windowId, abilityToken, windowType, displayId);
}
}
} // namespace Rosen
} // namespace OHOS
+28
View File
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2021 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 "window_manager_agent.h"
#include "foundation/windowmanager/interfaces/innerkits/wm/window_manager.h"
#include "singleton_container.h"
namespace OHOS {
namespace Rosen {
void WindowManagerAgent::UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
WindowType windowType, int32_t displayId, bool focused)
{
SingletonContainer::Get<WindowManager>().UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused);
}
} // namespace Rosen
} // namespace OHOS
+12
View File
@@ -77,6 +77,13 @@ void WindowOption::SetWindowFlags(uint32_t flags)
flags_ = flags;
}
void WindowOption::SetSystemBarProperty(WindowType type, const SystemBarProperty& property)
{
if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
sysBarPropMap_[type] = property;
}
}
Rect WindowOption::GetWindowRect() const
{
return windowRect_;
@@ -121,6 +128,11 @@ uint32_t WindowOption::GetWindowFlags() const
{
return flags_;
}
const std::unordered_map<WindowType, SystemBarProperty>& WindowOption::GetSystemBarProperty() const
{
return sysBarPropMap_;
}
}
}
+49
View File
@@ -72,6 +72,13 @@ void WindowProperty::SetWindowFlags(uint32_t flags)
flags_ = flags;
}
void WindowProperty::SetSystemBarProperty(WindowType type, const SystemBarProperty& property)
{
if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
sysBarPropMap_[type] = property;
}
}
Rect WindowProperty::GetWindowRect() const
{
return windowRect_;
@@ -127,6 +134,11 @@ uint32_t WindowProperty::GetWindowFlags() const
return flags_;
}
const std::unordered_map<WindowType, SystemBarProperty>& WindowProperty::GetSystemBarProperty() const
{
return sysBarPropMap_;
}
// TODO
void WindowProperty::SetWindowId(uint32_t windowId)
{
@@ -145,6 +157,37 @@ uint32_t WindowProperty::GetParentId() const
return parentId_;
}
bool WindowProperty::MapMarshalling(Parcel& parcel) const
{
auto size = sysBarPropMap_.size();
if (!parcel.WriteUint32(static_cast<uint32_t>(size))) {
return false;
}
for (auto it : sysBarPropMap_) {
// write key(type)
if (!parcel.WriteUint32(static_cast<uint32_t>(it.first))) {
return false;
}
// write val(UIState)
if (!(parcel.WriteBool(it.second.enable_) && parcel.WriteUint32(it.second.backgroundColor_) &&
parcel.WriteUint32(it.second.contentColor_))) {
return false;
}
}
return true;
}
void WindowProperty::MapUnmarshalling(Parcel& parcel, sptr<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());
SystemBarProperty prop = { parcel.ReadBool(), parcel.ReadUint32(), parcel.ReadUint32() };
property->SetSystemBarProperty(type, prop);
}
}
bool WindowProperty::Marshalling(Parcel& parcel) const
{
// write windowRect_
@@ -212,6 +255,11 @@ bool WindowProperty::Marshalling(Parcel& parcel) const
if (!parcel.WriteUint32(parentId_)) {
return false;
}
// write sysUIStateMap_
if (!MapMarshalling(parcel)) {
return false;
}
return true;
}
@@ -232,6 +280,7 @@ sptr<WindowProperty> WindowProperty::Unmarshalling(Parcel& parcel)
property->SetDisplayId(parcel.ReadInt32());
property->SetWindowId(parcel.ReadUint32());
property->SetParentId(parcel.ReadUint32());
MapUnmarshalling(parcel, property);
return property;
}
}
+20
View File
@@ -53,6 +53,26 @@ void WindowProxy::UpdateWindowRect(const struct Rect& rect)
return;
}
void WindowProxy::UpdateSystemBarProperty(const SystemBarProperty& prop)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return;
}
if (!(data.WriteBool(prop.enable_) && data.WriteUint32(prop.backgroundColor_) &&
data.WriteUint32(prop.contentColor_))) {
WLOGFE("Write property failed");
return;
}
if (Remote()->SendRequest(TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
}
return;
}
void WindowProxy::UpdateWindowMode(WindowMode mode)
{
MessageParcel data;
+30 -11
View File
@@ -39,11 +39,13 @@ WindowScene::~WindowScene()
}
WMError WindowScene::Init(int32_t displayId, std::shared_ptr<AbilityRuntime::AbilityContext>& abilityContext,
sptr<IWindowLifeCycle>& listener)
sptr<IWindowLifeCycle>& listener, sptr<WindowOption> option)
{
displayId_ = displayId;
abilityContext_ = abilityContext;
sptr<WindowOption> option = new WindowOption();
if (option == nullptr) {
option = new WindowOption();
}
option->SetDisplayId(displayId);
#ifndef _NEW_RENDERSERVER_
@@ -51,14 +53,8 @@ WMError WindowScene::Init(int32_t displayId, std::shared_ptr<AbilityRuntime::Abi
Adapter::Init();
mainWindow_ = CreateWindow(MAIN_WINDOW_ID, option);
#else
if (abilityContext_ != nullptr) {
mainWindow_ = SingletonContainer::Get<StaticCall>()->CreateWindow(
MAIN_WINDOW_ID + std::to_string(count++), option, abilityContext_->GetAbilityToken());
} else {
mainWindow_ = SingletonContainer::Get<StaticCall>()->CreateWindow(
MAIN_WINDOW_ID + std::to_string(count++), option);
}
mainWindow_ = SingletonContainer::Get<StaticCall>().CreateWindow(
MAIN_WINDOW_ID + std::to_string(count++), option, abilityContext_);
#endif
if (mainWindow_ == nullptr) {
return WMError::WM_ERROR_NULLPTR;
@@ -76,7 +72,7 @@ sptr<Window> WindowScene::CreateWindow(const std::string& windowName, sptr<Windo
return nullptr;
}
option->SetParentName(mainWindow_->GetWindowName());
return SingletonContainer::Get<StaticCall>()->CreateWindow(windowName, option);
return SingletonContainer::Get<StaticCall>().CreateWindow(windowName, option);
#else
/* weston adapter */
if (!Adapter::CreateWestonWindow(option)) {
@@ -116,6 +112,14 @@ WMError WindowScene::GoBackground() const
return mainWindow_->Hide();
}
WMError WindowScene::SetSystemBarProperty(WindowType type, const SystemBarProperty& property) const
{
if (mainWindow_ == nullptr) {
return WMError::WM_ERROR_NULLPTR;
}
return mainWindow_->SetSystemBarProperty(type, property);
}
WMError WindowScene::RequestFocus() const
{
if (mainWindow_ == nullptr) {
@@ -123,5 +127,20 @@ WMError WindowScene::RequestFocus() const
}
return mainWindow_->RequestFocus();
}
void WindowScene::UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration)
{
WLOGFI("notify mainWindow winId:%{public}d", mainWindow_->GetWindowId());
mainWindow_->UpdateConfiguration(configuration);
}
const std::string& WindowScene::GetContentInfo() const
{
if (mainWindow_ == nullptr) {
WLOGFE("WindowScene::GetContentInfo mainWindow_ is null");
return "";
}
return mainWindow_->GetContentInfo();
}
} // namespace Rosen
} // namespace OHOS
+5 -1
View File
@@ -26,7 +26,6 @@ namespace {
int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
WLOGFI("WindowStub::OnRemoteRequest code is %{public}d", code);
if (data.ReadInterfaceToken() != GetDescriptor()) {
WLOGFE("InterfaceToken check failed");
return -1;
@@ -50,6 +49,11 @@ int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParce
UpdateFocusStatus(focused);
break;
}
case TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY: {
SystemBarProperty property = { data.ReadBool(), data.ReadUint32(), data.ReadUint32() };
UpdateSystemBarProperty(property);
break;
}
default:
break;
}
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2021 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 "zidl/window_manager_agent_proxy.h"
#include <ipc_types.h>
#include "window_manager_hilog.h"
namespace OHOS {
namespace Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerAgentProxy"};
}
void WindowManagerAgentProxy::UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
WindowType windowType, int32_t displayId, bool focused)
{
MessageParcel data;
MessageParcel reply;
MessageOption option(MessageOption::TF_ASYNC);
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return;
}
if (!data.WriteUint32(windowId)) {
WLOGFE("Write windowId failed");
return;
}
if (!data.WriteRemoteObject(abilityToken)) {
WLOGFI("Write abilityToken failed");
}
if (!data.WriteUint32(static_cast<uint32_t>(windowType))) {
WLOGFE("Write windowType failed");
return;
}
if (!data.WriteInt32(displayId)) {
WLOGFE("Write displayId failed");
return;
}
if (!data.WriteBool(focused)) {
WLOGFE("Write Focus failed");
return;
}
if (Remote()->SendRequest(TRANS_ID_UPDATE_FOCUS_STATUS, data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
}
}
} // namespace Rosen
} // namespace OHOS
+51
View File
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2021 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 "zidl/window_manager_agent_stub.h"
#include "ipc_skeleton.h"
#include "window_manager_hilog.h"
#include "wm_common.h"
namespace OHOS {
namespace Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerAgentStub"};
}
int WindowManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
MessageParcel& reply, MessageOption& option)
{
WLOGFI("WindowManagerAgentStub::OnRemoteRequest code is %{public}d", code);
if (data.ReadInterfaceToken() != GetDescriptor()) {
WLOGFE("InterfaceToken check failed");
return -1;
}
switch (code) {
case TRANS_ID_UPDATE_FOCUS_STATUS: {
uint32_t windowId = data.ReadUint32();
sptr<IRemoteObject> abilityToken = data.ReadRemoteObject();
WindowType windowType = static_cast<WindowType>(data.ReadUint32());
int32_t displayId = data.ReadInt32();
bool focused = data.ReadBool();
UpdateFocusStatus(windowId, abilityToken, windowType, displayId, focused);
break;
}
default:
break;
}
return 0;
}
} // namespace Rosen
} // namespace OHOS
+16 -17
View File
@@ -27,23 +27,18 @@ config("libwms_config") {
"//foundation/windowmanager/dm/include",
"//foundation/windowmanager/dmserver/include",
]
cflags = [
"-Wall",
"-Werror",
"-g3",
]
}
ohos_shared_library("libwms") {
sources = [
"../dmserver/src/abstract_display.cpp",
"../dmserver/src/abstract_display_manager.cpp",
"../dmserver/src/display_manager_service.cpp",
"../dmserver/src/display_manager_service_inner.cpp",
"../dmserver/src/display_manager_stub.cpp",
"../dmserver/src/display_node_control.cpp",
"../dmserver/src/display_screen.cpp",
"../dmserver/src/display_screen_manager.cpp",
"../dmserver/src/screen.cpp",
"../wm/src/zidl/window_manager_agent_proxy.cpp",
"src/input_window_monitor.cpp",
"src/window_controller.cpp",
"src/window_layout_policy.cpp",
@@ -61,24 +56,28 @@ ohos_shared_library("libwms") {
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
"//foundation/windowmanager/wm:libwmutil",
"//utils/native/base:utils",
# RSSurface
"//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base",
"//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client",
# IMS
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-client",
]
public_deps = [
# ability manager
"//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager",
"//foundation/aafwk/standard/interfaces/innerkits/want:want",
"//foundation/graphic/standard:libsurface",
"//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base",
# RSSurface
"//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client",
# IMS
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-client",
"//foundation/windowmanager/wm:libwmutil",
]
external_deps = [ "ipc:ipc_core" ]
external_deps = [
"bytrace_standard:bytrace_core",
"ipc:ipc_core",
]
part_name = "window_manager"
subsystem_name = "window"
+1 -1
View File
@@ -34,7 +34,7 @@ private:
sptr<WindowRoot> windowRoot_;
std::vector<MMI::PhysicalDisplayInfo> physicalDisplays_;
std::vector<MMI::LogicalDisplayInfo> logicalDisplays_;
std::unordered_set<WindowType> windowTypeSkipped_ { WindowType::WINDOW_TYPE_POINTER};
std::unordered_set<WindowType> windowTypeSkipped_ { WindowType::WINDOW_TYPE_POINTER };
const int INVALID_DISPLAY_ID = -1;
const int INVALID_WINDOW_ID = -1;
void TraverseWindowNodes(const std::vector<sptr<WindowNode>>& windowNodes,
+8 -1
View File
@@ -17,6 +17,7 @@
#define OHOS_ROSEN_WINDOW_CONTROLLER_H
#include <refbase.h>
#include "zidl/window_manager_agent_interface.h"
#include "window_root.h"
namespace OHOS {
@@ -35,10 +36,16 @@ public:
WMError Resize(uint32_t windowId, uint32_t width, uint32_t height);
WMError RequestFocus(uint32_t windowId);
WMError SaveAbilityToken(const sptr<IRemoteObject>& abilityToken, uint32_t windowId);
WMError SetWindowMode(uint32_t windowId, WindowMode mode);
WMError SetWindowType(uint32_t windowId, WindowType type);
WMError SetWindowFlags(uint32_t windowId, uint32_t flags);
WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property);
void RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent);
void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent);
private:
uint32_t GenWindowId();
WMError LayoutWindowNodeTrees();
sptr<WindowRoot> windowRoot_;
std::atomic<uint32_t> windowId_ { 0 };
+14 -9
View File
@@ -28,25 +28,30 @@ namespace Rosen {
class WindowLayoutPolicy : public RefBase {
public:
WindowLayoutPolicy() = default;
WindowLayoutPolicy(const sptr<WindowNode>& belowAppNode,
const sptr<WindowNode>& appNode, const sptr<WindowNode>& aboveAppNode);
~WindowLayoutPolicy() = default;
WMError UpdateDisplayInfo(const Rect& displayRect);
WMError LayoutWindow(sptr<WindowNode>& node);
void UpdateDisplayInfo(const Rect& displayRect);
void AddWindowNode(sptr<WindowNode>& node);
void RemoveWindowNode(sptr<WindowNode>& node);
void UpdateWindowNode(sptr<WindowNode>& node);
private:
Rect displayRect_ = {0, 0, 0, 0};
sptr<WindowNode> belowAppWindowNode_ = new WindowNode();
sptr<WindowNode> appWindowNode_ = new WindowNode();
sptr<WindowNode> aboveAppWindowNode_ = new WindowNode();
Rect limitRect_ = {0, 0, 0, 0};
std::map<uint32_t, sptr<WindowNode>> aviodNodes_;
const std::set<WindowType> aviodTypes_ {
std::map<uint32_t, sptr<WindowNode>> avoidNodes_;
const std::set<WindowType> avoidTypes_ {
WindowType::WINDOW_TYPE_STATUS_BAR,
WindowType::WINDOW_TYPE_NAVIGATION_BAR,
};
void UpdateLimitRect(const sptr<WindowNode>& node);
void RecordAvoidRect(const sptr<WindowNode>& node);
bool UpdateLayoutRects(sptr<WindowNode>& node);
bool IsNeedAvoidNode(const sptr<WindowNode>& node);
bool IsFullScreenNode(const sptr<WindowNode>& node);
bool IsParentLimitNode(const sptr<WindowNode>& node);
bool IsRectChanged(const Rect& l, const Rect& r);
void UpdateLayoutRect(sptr<WindowNode>& node);
void LayoutWindowTree();
void LayoutWindowNode(sptr<WindowNode>& node);
};
}
}
@@ -20,6 +20,7 @@
#include <ui/rs_surface_node.h>
#include "window_property.h"
#include "window_interface.h"
#include "zidl/window_manager_agent_interface.h"
namespace OHOS {
namespace Rosen {
@@ -35,7 +36,13 @@ public:
TRANS_ID_MOVE,
TRANS_ID_RESIZE,
TRANS_ID_REQUEST_FOCUS,
TRANS_ID_UPDATE_TYPE,
TRANS_ID_UPDATE_MODE,
TRANS_ID_UPDATE_FLAGS,
TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY,
TRANS_ID_SEND_ABILITY_TOKEN,
TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER,
TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER,
};
virtual WMError CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& property,
const std::shared_ptr<RSSurfaceNode>& surfaceNode, uint32_t& windowId) = 0;
@@ -45,7 +52,14 @@ public:
virtual WMError MoveTo(uint32_t windowId, int32_t x, int32_t y) = 0;
virtual WMError Resize(uint32_t windowId, uint32_t width, uint32_t height) = 0;
virtual WMError RequestFocus(uint32_t windowId) = 0;
virtual WMError SetWindowMode(uint32_t windowId, WindowMode mode) = 0;
virtual WMError SetWindowType(uint32_t windowId, WindowType type) = 0;
virtual WMError SetWindowFlags(uint32_t windowId, uint32_t flags) = 0;
virtual WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) = 0;
virtual WMError SaveAbilityToken(const sptr<IRemoteObject>& abilityToken, uint32_t windowId) = 0;
virtual void RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
virtual void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent) = 0;
};
}
}
+7
View File
@@ -36,6 +36,13 @@ public:
WMError Resize(uint32_t windowId, uint32_t width, uint32_t height) override;
WMError RequestFocus(uint32_t windowId) override;
WMError SaveAbilityToken(const sptr<IRemoteObject>& abilityToken, uint32_t windowId) override;
WMError SetWindowMode(uint32_t windowId, WindowMode mode) override;
WMError SetWindowType(uint32_t windowId, WindowType type) override;
WMError SetWindowFlags(uint32_t windowId, uint32_t flags) override;
WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) override;
void RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent) override;
void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent) override;
private:
static inline BrokerDelegator<WindowManagerProxy> delegator_;
+14 -3
View File
@@ -36,7 +36,6 @@ DECLARE_SYSTEM_ABILITY(WindowManagerService);
DECLARE_SINGLE_INSTANCE_BASE(WindowManagerService);
public:
~WindowManagerService() = default;
void OnStart() override;
void OnStop() override;
@@ -49,14 +48,26 @@ public:
WMError Resize(uint32_t windowId, uint32_t width, uint32_t height) override;
WMError RequestFocus(uint32_t windowId) override;
WMError SaveAbilityToken(const sptr<IRemoteObject>& abilityToken, uint32_t windowId) override;
private:
WMError SetWindowMode(uint32_t windowId, WindowMode mode) override;
WMError SetWindowType(uint32_t windowId, WindowType type) override;
WMError SetWindowFlags(uint32_t windowId, uint32_t flags) override;
WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop) override;
void RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent) override;
void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent) override;
protected:
WindowManagerService();
virtual ~WindowManagerService() = default;
private:
bool Init();
static inline SingletonDelegator<WindowManagerService> delegator;
std::mutex mutex_;
std::recursive_mutex mutex_;
sptr<WindowRoot> windowRoot_;
sptr<WindowController> windowController_;
sptr<InputWindowMonitor> inputWindowMonitor_;
const int WAITING_RS_TIME = 10;
};
}
}
+5 -10
View File
@@ -24,13 +24,6 @@
namespace OHOS {
namespace Rosen {
struct LayoutRects {
Rect displayRect_ = { 0, 0, 0, 0 };
Rect parentRect_ = { 0, 0, 0, 0 };
Rect limitRect_ = { 0, 0, 0, 0 };
Rect rect_ = { 0, 0, 0, 0 };
};
class WindowNode : public RefBase {
public:
WindowNode(const sptr<WindowProperty>& property, const sptr<IWindow>& window,
@@ -48,19 +41,21 @@ public:
~WindowNode() = default;
void SetDisplayId(int32_t displayId);
void UpdateLayoutRects(const LayoutRects& rects);
void SetLayoutRect(const Rect& rect);
void SetWindowProperty(const sptr<WindowProperty>& property);
void SetSystemBarProperty(WindowType type, const SystemBarProperty& property);
const sptr<IWindow>& GetWindowToken() const;
uint32_t GetWindowId() const;
int32_t GetDisplayId() const;
const LayoutRects& GetLayoutRects() const;
const Rect& GetLayoutRect() const;
WindowType GetWindowType() const;
WindowMode GetWindowMode() const;
uint32_t GetWindowFlags() const;
const sptr<WindowProperty>& GetWindowProperty() const;
int32_t GetCallingPid() const;
int32_t GetCallingUid() const;
const std::unordered_map<WindowType, SystemBarProperty>& GetSystemBarProperty() const;
sptr<WindowNode> parent_;
std::vector<sptr<WindowNode>> children_;
@@ -73,7 +68,7 @@ public:
private:
sptr<WindowProperty> property_;
sptr<IWindow> windowToken_;
LayoutRects layoutRects_;
Rect layoutRect_ { 0, 0, 0, 0 };
int32_t callingPid_;
int32_t callingUid_;
};
+20 -16
View File
@@ -24,23 +24,16 @@
namespace OHOS {
namespace Rosen {
using UpdateFocusStatusFunc = std::function<void (uint32_t windowId, const sptr<IRemoteObject>& abilityToken,
WindowType windowType, int32_t displayId, bool focused)>;
class WindowNodeContainer : public RefBase {
public:
WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height) : screenId_(screenId)
{
struct RSDisplayNodeConfig config = {screenId};
displayNode_ = RSDisplayNode::Create(config);
displayRect_ = {
.posX_ = 0,
.posY_ = 0,
.width_ = width,
.height_ = height
};
}
WindowNodeContainer(uint64_t screenId, uint32_t width, uint32_t height, UpdateFocusStatusFunc callback);
~WindowNodeContainer();
WMError AddWindowNode(sptr<WindowNode>& node, sptr<WindowNode>& parentNode);
WMError RemoveWindowNode(sptr<WindowNode>& node);
WMError UpdateWindowNode(sptr<WindowNode>& node);
WMError DestroyWindowNode(sptr<WindowNode>& node, std::vector<uint32_t>& windowIds);
const std::vector<uint32_t>& Destroy();
void AssignZOrder();
@@ -48,9 +41,10 @@ public:
uint32_t GetFocusWindow() const;
WMError MinimizeOtherFullScreenAbility(); // adapt to api7
void TraverseContainer(std::vector<sptr<WindowNode>>& windowNodes);
WMError LayoutWindowNodes();
uint64_t GetScreenId() const;
Rect GetDisplayRect() const;
sptr<WindowNode> GetTopImmersiveNode() const;
void NotifySystemBarIfChanged();
private:
void AssignZOrder(sptr<WindowNode>& node);
@@ -62,17 +56,27 @@ private:
void UpdateWindowTree(sptr<WindowNode>& node);
bool UpdateRSTree(sptr<WindowNode>& node, bool isAdd);
sptr<WindowZorderPolicy> zorderPolicy_ = new WindowZorderPolicy();
sptr<WindowLayoutPolicy> layoutPolicy_ = new WindowLayoutPolicy();
sptr<WindowNode> belowAppWindowNode_ = new WindowNode();
sptr<WindowNode> appWindowNode_ = new WindowNode();
sptr<WindowNode> aboveAppWindowNode_ = new WindowNode();
sptr<WindowLayoutPolicy> layoutPolicy_ =
new WindowLayoutPolicy(belowAppWindowNode_, appWindowNode_, aboveAppWindowNode_);
std::shared_ptr<RSDisplayNode> displayNode_;
std::vector<uint32_t> removedIds_;
std::unordered_map<WindowType, sptr<WindowNode>> sysBarNodeMap_ {
{ WindowType::WINDOW_TYPE_STATUS_BAR, nullptr },
{ WindowType::WINDOW_TYPE_NAVIGATION_BAR, nullptr },
};
std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ {
{ WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() },
{ WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() },
};
uint32_t zOrder_ { 0 };
uint64_t screenId_ = 0;
uint32_t focusedWindow_ { 0 };
Rect displayRect_;
WMError LayoutWindowNode(sptr<WindowNode>& node);
uint64_t screenId_ = 0;
UpdateFocusStatusFunc focusStatusCallBack_;
void DumpScreenWindowTree();
};
}
}
+27 -2
View File
@@ -17,6 +17,7 @@
#include <refbase.h>
#include <iremote_object.h>
#include "zidl/window_manager_agent_interface.h"
#include "window_node_container.h"
namespace OHOS {
@@ -28,12 +29,24 @@ public:
virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override;
private:
std::function<void (sptr<IRemoteObject>&)> callback_;
};
class WindowManagerAgentDeathRecipient : public IRemoteObject::DeathRecipient {
public:
WindowManagerAgentDeathRecipient(std::function<void (sptr<IRemoteObject>&)> callback) : callback_(callback) {}
~WindowManagerAgentDeathRecipient() = default;
virtual void OnRemoteDied(const wptr<IRemoteObject>& wptrDeath) override;
private:
std::function<void (sptr<IRemoteObject>&)> callback_;
};
class WindowRoot : public RefBase {
public:
WindowRoot() = default;
WindowRoot(std::recursive_mutex& mutex) : mutex_(mutex) {}
~WindowRoot() = default;
sptr<WindowNodeContainer> GetOrCreateWindowNodeContainer(int32_t displayId);
@@ -44,21 +57,33 @@ public:
WMError AddWindowNode(uint32_t parentId, sptr<WindowNode>& node);
WMError RemoveWindowNode(uint32_t windowId);
WMError DestroyWindow(uint32_t windowId);
const std::map<int32_t, sptr<WindowNodeContainer>>& GetWindowNodeContainerMap() const;
WMError UpdateWindowNode(uint32_t windowId);
WMError RequestFocus(uint32_t windowId);
WMError MinimizeOtherFullScreenAbility(sptr<WindowNode>& node);
void RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent);
void UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent);
private:
void ClearWindow(const sptr<IRemoteObject>& remoteObject);
void ClearWindowManagerAgent(const sptr<IRemoteObject>& remoteObject);
void UnregisterFocusChangedListener(const sptr<IRemoteObject>& windowManagerAgent);
void UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
int32_t displayId, bool focused);
WMError DestroyWindowInner(sptr<WindowNode>& node);
std::recursive_mutex& mutex_;
std::map<int32_t, sptr<WindowNodeContainer>> windowNodeContainerMap_;
std::map<uint32_t, sptr<WindowNode>> windowNodeMap_;
std::map<sptr<IRemoteObject>, uint32_t> windowIdMap_;
std::vector<sptr<IWindowManagerAgent>> focusChangedListenerAgents_;
sptr<WindowDeathRecipient> windowDeath_ = new WindowDeathRecipient(std::bind(&WindowRoot::ClearWindow,
this, std::placeholders::_1));
sptr<WindowManagerAgentDeathRecipient> windowManagerAgentDeath_ = new WindowManagerAgentDeathRecipient(
std::bind(&WindowRoot::ClearWindowManagerAgent, this, std::placeholders::_1));
};
}
}
+7 -8
View File
@@ -47,7 +47,6 @@ void InputWindowMonitor::UpdateInputWindow(uint32_t windowId)
UpdateDisplaysInfo(container);
std::vector<sptr<WindowNode>> windowNodes;
container->TraverseContainer(windowNodes);
auto iter = std::find_if(logicalDisplays_.begin(), logicalDisplays_.end(),
[displayId](MMI::LogicalDisplayInfo& logicalDisplay) {
return logicalDisplay.id == displayId;
@@ -84,7 +83,7 @@ void InputWindowMonitor::UpdateDisplaysInfo(const sptr<WindowNodeContainer>& con
};
auto physicalDisplayIter = std::find_if(physicalDisplays_.begin(), physicalDisplays_.end(),
[&physicalDisplayInfo](MMI::PhysicalDisplayInfo& physicalDisplay) {
return physicalDisplay.id = physicalDisplayInfo.id;
return physicalDisplay.id == physicalDisplayInfo.id;
});
if (physicalDisplayIter != physicalDisplays_.end()) {
*physicalDisplayIter = physicalDisplayInfo;
@@ -106,7 +105,7 @@ void InputWindowMonitor::UpdateDisplaysInfo(const sptr<WindowNodeContainer>& con
};
auto logicalDisplayIter = std::find_if(logicalDisplays_.begin(), logicalDisplays_.end(),
[&logicalDisplayInfo](MMI::LogicalDisplayInfo& logicalDisplay) {
return logicalDisplay.id = logicalDisplayInfo.id;
return logicalDisplay.id == logicalDisplayInfo.id;
});
if (logicalDisplayIter != logicalDisplays_.end()) {
*logicalDisplayIter = logicalDisplayInfo;
@@ -116,7 +115,7 @@ void InputWindowMonitor::UpdateDisplaysInfo(const sptr<WindowNodeContainer>& con
}
void InputWindowMonitor::TraverseWindowNodes(const std::vector<sptr<WindowNode>> &windowNodes,
std::vector<MMI::LogicalDisplayInfo>::iterator& iter)
std::vector<MMI::LogicalDisplayInfo>::iterator& iter)
{
iter->windowsInfo_.clear();
for (auto& windowNode: windowNodes) {
@@ -129,10 +128,10 @@ void InputWindowMonitor::TraverseWindowNodes(const std::vector<sptr<WindowNode>>
.id = static_cast<int32_t>(windowNode->GetWindowId()),
.pid = windowNode->GetCallingPid(),
.uid = windowNode->GetCallingUid(),
.topLeftX = windowNode->GetLayoutRects().rect_.posX_,
.topLeftY = windowNode->GetLayoutRects().rect_.posY_,
.width = static_cast<int32_t>(windowNode->GetLayoutRects().rect_.width_),
.height = static_cast<int32_t>(windowNode->GetLayoutRects().rect_.height_),
.topLeftX = windowNode->GetLayoutRect().posX_,
.topLeftY = windowNode->GetLayoutRect().posY_,
.width = static_cast<int32_t>(windowNode->GetLayoutRect().width_),
.height = static_cast<int32_t>(windowNode->GetLayoutRect().height_),
.displayId = windowNode->GetDisplayId(),
.agentWindowId = static_cast<int32_t>(windowNode->GetWindowId()),
};
+100 -29
View File
@@ -16,6 +16,7 @@
#include "window_controller.h"
#include <transaction/rs_transaction.h>
#include "window_manager_hilog.h"
#include "wm_trace.h"
namespace OHOS {
namespace Rosen {
@@ -63,13 +64,12 @@ WMError WindowController::AddWindowNode(sptr<WindowProperty>& property)
if (res != WMError::WM_OK) {
return res;
}
res = LayoutWindowNodeTrees();
RSTransaction::FlushImplicitTransaction();
WLOGFI("AddWindowNode FlushImplicitTransaction end");
if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN) {
WLOGFI("need minimize previous fullscreen window if exists");
WM_SCOPED_TRACE_BEGIN("controller:MinimizeOtherFullScreenAbility");
WMError res = windowRoot_->MinimizeOtherFullScreenAbility(node);
WM_SCOPED_TRACE_END();
if (res != WMError::WM_OK) {
WLOGFE("Minimize other fullscreen window failed");
}
@@ -77,32 +77,13 @@ WMError WindowController::AddWindowNode(sptr<WindowProperty>& property)
return res;
}
WMError WindowController::LayoutWindowNodeTrees()
{
auto& windowContainerMap = windowRoot_->GetWindowNodeContainerMap();
if (windowContainerMap.empty()) {
WLOGFE("could not find window container");
return WMError::WM_ERROR_INVALID_PARAM;
}
for (auto& iter : windowContainerMap) {
const sptr<WindowNodeContainer>& windowContainer = iter.second;
WMError ret = windowContainer->LayoutWindowNodes();
if (ret != WMError::WM_OK) {
return ret;
}
}
return WMError::WM_OK;
}
WMError WindowController::RemoveWindowNode(uint32_t windowId)
{
WMError res = windowRoot_->RemoveWindowNode(windowId);
if (res != WMError::WM_OK) {
return res;
}
res = LayoutWindowNodeTrees();
RSTransaction::FlushImplicitTransaction();
WLOGFI("RemoveWindowNode FlushImplicitTransaction end");
return res;
}
@@ -112,9 +93,7 @@ WMError WindowController::DestroyWindow(uint32_t windowId)
if (res != WMError::WM_OK) {
return res;
}
res = LayoutWindowNodeTrees();
RSTransaction::FlushImplicitTransaction();
WLOGFI("DestroyWindow FlushImplicitTransaction end");
return res;
}
@@ -125,10 +104,15 @@ WMError WindowController::MoveTo(uint32_t windowId, int32_t x, int32_t y)
WLOGFE("could not find window");
return WMError::WM_ERROR_NULLPTR;
}
Vector2f pos(x, y);
node->surfaceNode_->SetBoundsPosition(pos);
auto property = node->GetWindowProperty();
Rect lastRect = property->GetWindowRect();
Rect newRect = { x, y, lastRect.width_, lastRect.height_ };
property->SetWindowRect(newRect);
WMError res = windowRoot_->UpdateWindowNode(windowId);
if (res != WMError::WM_OK) {
return res;
}
RSTransaction::FlushImplicitTransaction();
WLOGFI("MoveTo FlushImplicitTransaction end");
return WMError::WM_OK;
}
@@ -139,9 +123,15 @@ WMError WindowController::Resize(uint32_t windowId, uint32_t width, uint32_t hei
WLOGFE("could not find window");
return WMError::WM_ERROR_NULLPTR;
}
node->surfaceNode_->SetBoundsSize(width, height);
auto property = node->GetWindowProperty();
Rect lastRect = property->GetWindowRect();
Rect newRect = { lastRect.posX_, lastRect.posY_, width, height };
property->SetWindowRect(newRect);
WMError res = windowRoot_->UpdateWindowNode(windowId);
if (res != WMError::WM_OK) {
return res;
}
RSTransaction::FlushImplicitTransaction();
WLOGFI("Resize FlushImplicitTransaction end");
return WMError::WM_OK;
}
@@ -149,5 +139,86 @@ WMError WindowController::RequestFocus(uint32_t windowId)
{
return windowRoot_->RequestFocus(windowId);
}
WMError WindowController::SetWindowMode(uint32_t windowId, WindowMode mode)
{
auto node = windowRoot_->GetWindowNode(windowId);
if (node == nullptr) {
WLOGFE("could not find window");
return WMError::WM_ERROR_NULLPTR;
}
auto property = node->GetWindowProperty();
property->SetWindowMode(mode);
WMError res = windowRoot_->UpdateWindowNode(windowId);
if (res != WMError::WM_OK) {
return res;
}
RSTransaction::FlushImplicitTransaction();
WLOGFI("SetWindowMode FlushImplicitTransaction end");
return res;
}
WMError WindowController::SetWindowType(uint32_t windowId, WindowType type)
{
auto node = windowRoot_->GetWindowNode(windowId);
if (node == nullptr) {
WLOGFE("could not find window");
return WMError::WM_ERROR_NULLPTR;
}
auto property = node->GetWindowProperty();
property->SetWindowType(type);
WMError res = windowRoot_->UpdateWindowNode(windowId);
if (res != WMError::WM_OK) {
return res;
}
RSTransaction::FlushImplicitTransaction();
WLOGFI("SetWindowType FlushImplicitTransaction end");
return res;
}
WMError WindowController::SetWindowFlags(uint32_t windowId, uint32_t flags)
{
auto node = windowRoot_->GetWindowNode(windowId);
if (node == nullptr) {
WLOGFE("could not find window");
return WMError::WM_ERROR_NULLPTR;
}
auto property = node->GetWindowProperty();
property->SetWindowFlags(flags);
WMError res = windowRoot_->UpdateWindowNode(windowId);
if (res != WMError::WM_OK) {
return res;
}
RSTransaction::FlushImplicitTransaction();
WLOGFI("SetWindowFlags FlushImplicitTransaction end");
return res;
}
WMError WindowController::SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property)
{
auto node = windowRoot_->GetWindowNode(windowId);
if (node == nullptr) {
WLOGFE("could not find window");
return WMError::WM_ERROR_NULLPTR;
}
node->SetSystemBarProperty(type, property);
WMError res = windowRoot_->UpdateWindowNode(windowId);
if (res != WMError::WM_OK) {
return res;
}
RSTransaction::FlushImplicitTransaction();
WLOGFI("SetSystemBarProperty FlushImplicitTransaction end");
return res;
}
void WindowController::RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
{
windowRoot_->RegisterFocusChangedListener(windowManagerAgent);
}
void WindowController::UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
{
windowRoot_->UnregisterFocusChangedListener(windowManagerAgent);
}
}
}
+118 -112
View File
@@ -14,7 +14,9 @@
*/
#include "window_layout_policy.h"
#include "window_helper.h"
#include "window_manager_hilog.h"
#include "wm_trace.h"
namespace OHOS {
namespace Rosen {
@@ -22,163 +24,167 @@ namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowLayoutPolicy"};
}
WMError WindowLayoutPolicy::UpdateDisplayInfo(const Rect& displayRect)
WindowLayoutPolicy::WindowLayoutPolicy(const sptr<WindowNode>& belowAppNode,
const sptr<WindowNode>& appNode, const sptr<WindowNode>& aboveAppNode)
{
belowAppWindowNode_ = belowAppNode;
appWindowNode_ = appNode;
aboveAppWindowNode_ = aboveAppNode;
}
void WindowLayoutPolicy::UpdateDisplayInfo(const Rect& displayRect)
{
if (displayRect.height_ == 0 || displayRect.width_ == 0) {
return WMError::WM_ERROR_INVALID_PARAM;
}
displayRect_ = displayRect;
limitRect_ = displayRect;
aviodNodes_.clear();
return WMError::WM_OK;
limitRect_ = displayRect_;
avoidNodes_.clear();
}
WMError WindowLayoutPolicy::LayoutWindow(sptr<WindowNode>& node)
void WindowLayoutPolicy::LayoutWindowTree()
{
if (node->GetWindowType() >= WindowType::SYSTEM_WINDOW_END) {
WLOGFE("unknown window type!");
return WMError::WM_ERROR_INVALID_PARAM;
limitRect_ = displayRect_;
avoidNodes_.clear();
std::vector<sptr<WindowNode>> rootNodes = { aboveAppWindowNode_, appWindowNode_, belowAppWindowNode_ };
for (auto& node : rootNodes) { // ensure that the avoid area windows are traversed first
LayoutWindowNode(node);
}
UpdateLayoutRects(node);
if (aviodTypes_.find(node->GetWindowType()) != aviodTypes_.end()) {
RecordAvoidRect(node);
}
return WMError::WM_OK;
}
bool WindowLayoutPolicy::IsRectChanged(const Rect& l, const Rect& r)
void WindowLayoutPolicy::LayoutWindowNode(sptr<WindowNode>& node)
{
if (node == nullptr) {
return;
}
if (node->parent_ != nullptr) { // isn't root node
UpdateLayoutRect(node);
if (avoidTypes_.find(node->GetWindowType()) != avoidTypes_.end()) {
RecordAvoidRect(node);
}
}
for (auto& childNode : node->children_) {
LayoutWindowNode(childNode);
}
}
void WindowLayoutPolicy::AddWindowNode(sptr<WindowNode>& node)
{
WM_FUNCTION_TRACE();
UpdateWindowNode(node); // currently, update and add do the same process
}
void WindowLayoutPolicy::RemoveWindowNode(sptr<WindowNode>& node)
{
WM_FUNCTION_TRACE();
auto type = node->GetWindowType();
// affect other windows, trigger off global layout
if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
LayoutWindowTree();
} else if (type == WindowType::WINDOW_TYPE_DOCK_SLICE) { // split screen mode
// TODO: change split screen
LayoutWindowTree();
}
}
void WindowLayoutPolicy::UpdateWindowNode(sptr<WindowNode>& node)
{
WM_FUNCTION_TRACE();
auto type = node->GetWindowType();
// affect other windows, trigger off global layout
if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
LayoutWindowTree();
} else if (type == WindowType::WINDOW_TYPE_DOCK_SLICE) { // split screen mode
// TODO: change split screen
LayoutWindowTree();
} else { // layout single window
LayoutWindowNode(node);
}
}
static bool IsLayoutChanged(const Rect& l, const Rect& r)
{
return !((l.posX_ == r.posX_) && (l.posY_ == r.posY_) && (l.width_ == r.width_) && (l.height_ == r.height_));
}
bool WindowLayoutPolicy::UpdateLayoutRects(sptr<WindowNode>& node)
void WindowLayoutPolicy::UpdateLayoutRect(sptr<WindowNode>& node)
{
bool needAvoid = IsNeedAvoidNode(node);
bool fullScreen = IsFullScreenNode(node);
bool parentLimit = IsParentLimitNode(node);
bool subWindow = (node->GetWindowType() == WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
bool floatingWindow = (node->GetWindowMode() == WindowMode::WINDOW_MODE_FLOATING);
WLOGFI("Id:%{public}d, avoid:%{public}d fullS:%{public}d parLimit:%{public}d float:%{public}d, types:%{public}d",
node->GetWindowId(), needAvoid, fullScreen, parentLimit, floatingWindow,
static_cast<uint32_t>(node->GetWindowType()));
const LayoutRects& layoutRects = node->GetLayoutRects();
Rect lastRect = layoutRects.rect_;
Rect dRect = layoutRects.displayRect_;
Rect pRect = layoutRects.parentRect_;
Rect lRect = layoutRects.limitRect_;
auto type = node->GetWindowType();
auto mode = node->GetWindowMode();
auto flags = node->GetWindowFlags();
bool needAvoid = (flags & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_NEED_AVOID));
bool parentLimit = (flags & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT));
bool subWindow = WindowHelper::IsSubWindow(type);
bool floatingWindow = (mode == WindowMode::WINDOW_MODE_FLOATING);
const Rect& layoutRect = node->GetLayoutRect();
Rect lastRect = layoutRect;
Rect limitRect = displayRect_;
Rect winRect = node->GetWindowProperty()->GetWindowRect();
WLOGFI("Id:%{public}d, avoid:%{public}d parLimit:%{public}d floating:%{public}d, sub:%{public}d," \
"type:%{public}d, requestRect:[%{public}d, %{public}d, %{public}d, %{public}d]",
node->GetWindowId(), needAvoid, parentLimit, floatingWindow, subWindow,
static_cast<uint32_t>(type), winRect.posX_, winRect.posY_, winRect.width_, winRect.height_);
if (needAvoid) {
dRect = limitRect_;
} else {
dRect = displayRect_;
limitRect = limitRect_;
}
if (subWindow) {
pRect = node->parent_->GetLayoutRects().rect_;
} else {
pRect = dRect;
if (!floatingWindow) { // fullscreen window
winRect = limitRect;
} else { // floating window
if (subWindow && parentLimit) { // subwidow and limited by parent
limitRect = node->parent_->GetLayoutRect();
winRect.width_ = std::min(limitRect.width_, winRect.width_);
winRect.height_ = std::min(limitRect.height_, winRect.height_);
winRect.posX_ = std::max(limitRect.posX_, winRect.posX_);
winRect.posY_ = std::max(limitRect.posY_, winRect.posY_);
winRect.posX_ = std::min(
limitRect.posX_ + static_cast<int32_t>(limitRect.width_) - static_cast<int32_t>(winRect.width_),
winRect.posX_);
winRect.posY_ = std::min(
limitRect.posY_ + static_cast<int32_t>(limitRect.height_) - static_cast<int32_t>(winRect.height_),
winRect.posY_);
}
}
if (parentLimit) {
lRect = pRect;
} else {
lRect = dRect;
}
if (fullScreen) {
winRect = lRect;
} else if (!floatingWindow) {
winRect.width_ = std::min(lRect.width_, winRect.width_);
winRect.height_ = std::min(lRect.height_, winRect.height_);
winRect.posX_ = std::max(lRect.posX_, winRect.posX_);
winRect.posY_ = std::max(lRect.posY_, winRect.posY_);
winRect.posX_ = std::min(
lRect.posX_ + static_cast<int32_t>(lRect.width_) - static_cast<int32_t>(winRect.width_),
winRect.posX_);
winRect.posY_ = std::min(
lRect.posY_ + static_cast<int32_t>(lRect.height_) - static_cast<int32_t>(winRect.height_),
winRect.posY_);
}
node->UpdateLayoutRects({ dRect, pRect, lRect, winRect });
if (IsRectChanged(lastRect, winRect)) {
// Limit window to the maximum window size
winRect.width_ = std::min(displayRect_.width_, winRect.width_);
winRect.height_ = std::min(displayRect_.height_, winRect.height_);
winRect.width_ = std::max(1u, winRect.width_);
winRect.height_ = std::max(1u, winRect.height_);
node->SetLayoutRect(winRect);
if (IsLayoutChanged(lastRect, winRect)) {
node->GetWindowToken()->UpdateWindowRect(winRect);
node->surfaceNode_->SetBounds(winRect.posX_, winRect.posY_, winRect.width_, winRect.height_);
WLOGFI("UpdateLayoutRects for winId: %{public}d, Rect: %{public}d %{public}d %{public}d %{public}d",
node->GetWindowId(), winRect.posX_, winRect.posY_, winRect.width_, winRect.height_);
return true;
}
WLOGFI("UpdateLayoutRects rect not changed for winId: %{public}d", node->GetWindowId());
return false;
}
void WindowLayoutPolicy::UpdateLimitRect(const sptr<WindowNode>& node)
{
auto& layoutRects = node->GetLayoutRects();
auto& layoutRect = node->GetLayoutRect();
if (node->GetWindowType() == WindowType::WINDOW_TYPE_STATUS_BAR) { // STATUS_BAR
int32_t boundTop = limitRect_.posY_;
int32_t rectBottom = layoutRects.rect_.posY_ + layoutRects.rect_.height_;
int32_t rectBottom = layoutRect.posY_ + layoutRect.height_;
int32_t offsetH = rectBottom - boundTop;
limitRect_.posY_ += offsetH;
limitRect_.height_ -= offsetH;
} else if (node->GetWindowType() == WindowType::WINDOW_TYPE_NAVIGATION_BAR) { // NAVIGATION_BAR
int32_t boundBottom = limitRect_.posY_ + limitRect_.height_;
int32_t offsetH = boundBottom - layoutRects.rect_.posY_;
int32_t offsetH = boundBottom - layoutRect.posY_;
limitRect_.height_ -= offsetH;
}
WLOGFI("after add WinId: %{public}d, limitRect: %{public}d %{public}d %{public}d %{public}d",
node->GetWindowId(), limitRect_.posX_, limitRect_.posY_, limitRect_.width_, limitRect_.height_);
WLOGFI("Type: %{public}d, limitRect: %{public}d %{public}d %{public}d %{public}d",
node->GetWindowType(), limitRect_.posX_, limitRect_.posY_, limitRect_.width_, limitRect_.height_);
}
void WindowLayoutPolicy::RecordAvoidRect(const sptr<WindowNode>& node)
{
uint32_t id = node->GetWindowId();
if (aviodNodes_.find(id) == aviodNodes_.end()) { // new avoid rect
aviodNodes_.insert(std::pair<uint32_t, sptr<WindowNode>>(id, node));
if (avoidNodes_.find(id) == avoidNodes_.end()) { // new avoid rect
avoidNodes_.insert(std::pair<uint32_t, sptr<WindowNode>>(id, node));
UpdateLimitRect(node);
} else { // update existing avoid rect
limitRect_ = displayRect_;
aviodNodes_[id] = node;
for (auto item : aviodNodes_) {
avoidNodes_[id] = node;
for (auto item : avoidNodes_) {
UpdateLimitRect(item.second);
}
}
}
bool WindowLayoutPolicy::IsNeedAvoidNode(const sptr<WindowNode>& node)
{
auto type = node->GetWindowType();
auto mode = node->GetWindowMode();
auto flags = node->GetWindowFlags();
if (mode == WindowMode::WINDOW_MODE_FLOATING) {
return false;
}
if (type >= WindowType::APP_WINDOW_BASE &&
type <= WindowType::APP_SUB_WINDOW_END &&
(flags & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_NEED_AVOID))) {
return true;
}
return false;
}
bool WindowLayoutPolicy::IsFullScreenNode(const sptr<WindowNode>& node)
{
auto mode = node->GetWindowMode();
if (mode == WindowMode::WINDOW_MODE_FULLSCREEN || mode == WindowMode::WINDOW_MODE_SPLIT) {
return true;
}
return false;
}
bool WindowLayoutPolicy::IsParentLimitNode(const sptr<WindowNode>& node)
{
auto mode = node->GetWindowMode();
auto flags = node->GetWindowFlags();
if (mode != WindowMode::WINDOW_MODE_FLOATING &&
(flags & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT))) {
return true;
}
return false;
}
}
}
+145 -1
View File
@@ -215,6 +215,111 @@ WMError WindowManagerProxy::RequestFocus(uint32_t windowId)
return static_cast<WMError>(ret);
}
WMError WindowManagerProxy::SetWindowMode(uint32_t windowId, WindowMode mode)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(windowId)) {
WLOGFE("Write windowId failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(static_cast<uint32_t>(mode))) {
WLOGFE("Write type failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(TRANS_ID_UPDATE_MODE, data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
WMError WindowManagerProxy::SetWindowType(uint32_t windowId, WindowType type)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(windowId)) {
WLOGFE("Write windowId failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(static_cast<uint32_t>(type))) {
WLOGFE("Write type failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(TRANS_ID_UPDATE_TYPE, data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
WMError WindowManagerProxy::SetWindowFlags(uint32_t windowId, uint32_t flags)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(windowId)) {
WLOGFE("Write windowId failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(flags)) {
WLOGFE("Write type failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(TRANS_ID_UPDATE_FLAGS, data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
WMError WindowManagerProxy::SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(windowId)) {
WLOGFE("Write windowId failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!data.WriteUint32(static_cast<uint32_t>(type))) {
WLOGFE("Write type failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (!(data.WriteBool(prop.enable_) && data.WriteUint32(prop.backgroundColor_) &&
data.WriteUint32(prop.contentColor_))) {
WLOGFE("Write property failed");
return WMError::WM_ERROR_IPC_FAILED;
}
if (Remote()->SendRequest(TRANS_ID_UPDATE_SYSTEM_BAR_PROPERTY, data, reply, option) != ERR_NONE) {
return WMError::WM_ERROR_IPC_FAILED;
}
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
WMError WindowManagerProxy::SaveAbilityToken(const sptr<IRemoteObject>& abilityToken, uint32_t windowId)
{
MessageParcel data;
@@ -242,6 +347,45 @@ WMError WindowManagerProxy::SaveAbilityToken(const sptr<IRemoteObject>& abilityT
int32_t ret = reply.ReadInt32();
return static_cast<WMError>(ret);
}
}
void WindowManagerProxy::RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return;
}
if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
WLOGFE("Write IWindowManagerAgent failed");
return;
}
if (Remote()->SendRequest(TRANS_ID_REGISTER_FOCUS_CHANGED_LISTENER, data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
}
}
void WindowManagerProxy::UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return;
}
if (!data.WriteRemoteObject(windowManagerAgent->AsObject())) {
WLOGFE("Write IWindowManagerAgent failed");
return;
}
if (Remote()->SendRequest(TRANS_ID_UNREGISTER_FOCUS_CHANGED_LISTENER, data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
}
}
}
}
+82 -14
View File
@@ -21,6 +21,7 @@
#include <system_ability_definition.h>
#include "window_manager_hilog.h"
#include "wm_trace.h"
namespace OHOS {
namespace Rosen {
@@ -28,14 +29,11 @@ namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WindowManagerService"};
}
IMPLEMENT_SINGLE_INSTANCE(WindowManagerService);
const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(
SingletonContainer::Get<WindowManagerService>().GetRefPtr());
const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&SingletonContainer::Get<WindowManagerService>());
WindowManagerService::WindowManagerService() : SystemAbility(WINDOW_MANAGER_SERVICE_ID, true)
{
windowRoot_ = new WindowRoot();
windowRoot_ = new WindowRoot(mutex_);
windowController_ = new WindowController(windowRoot_);
inputWindowMonitor_ = new InputWindowMonitor(windowRoot_);
}
@@ -57,7 +55,7 @@ bool WindowManagerService::Init()
return false;
}
WLOGFI("WindowManagerService::Init success");
sleep(10); // for RS temporary
sleep(WAITING_RS_TIME); // for RS temporary
return true;
}
@@ -69,17 +67,28 @@ void WindowManagerService::OnStop()
WMError WindowManagerService::CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& property,
const std::shared_ptr<RSSurfaceNode>& surfaceNode, uint32_t& windowId)
{
WM_SCOPED_TRACE("wms:CreateWindow(%d)", windowId);
if (window == nullptr || property == nullptr || surfaceNode == nullptr) {
WLOGFE("window is invalid");
return WMError::WM_ERROR_NULLPTR;
}
std::lock_guard<std::mutex> lock(mutex_);
if ((!window) || (!window->AsObject())) {
WLOGFE("failed to get window agent");
return WMError::WM_ERROR_NULLPTR;
}
std::lock_guard<std::recursive_mutex> lock(mutex_);
return windowController_->CreateWindow(window, property, surfaceNode, windowId);
}
WMError WindowManagerService::AddWindow(sptr<WindowProperty>& property)
{
std::lock_guard<std::mutex> lock(mutex_);
Rect rect = property->GetWindowRect();
WLOGFI("[WMS] Add: %{public}5d %{public}4d %{public}4d %{public}4d [%{public}4d %{public}4d " \
"%{public}4d %{public}4d]", property->GetWindowId(), property->GetWindowType(), property->GetWindowMode(),
property->GetWindowFlags(), rect.posX_, rect.posY_, rect.width_, rect.height_);
WM_SCOPED_TRACE("wms:AddWindow(%d)", property->GetWindowId());
std::lock_guard<std::recursive_mutex> lock(mutex_);
WMError res = windowController_->AddWindowNode(property);
if (res == WMError::WM_OK) {
inputWindowMonitor_->UpdateInputWindow(property->GetWindowId());
@@ -89,7 +98,9 @@ WMError WindowManagerService::AddWindow(sptr<WindowProperty>& property)
WMError WindowManagerService::RemoveWindow(uint32_t windowId)
{
std::lock_guard<std::mutex> lock(mutex_);
WLOGFI("[WMS] Remove: %{public}d", windowId);
WM_SCOPED_TRACE("wms:RemoveWindow(%d)", windowId);
std::lock_guard<std::recursive_mutex> lock(mutex_);
WMError res = windowController_->RemoveWindowNode(windowId);
if (res == WMError::WM_OK) {
inputWindowMonitor_->UpdateInputWindow(windowId);
@@ -99,7 +110,9 @@ WMError WindowManagerService::RemoveWindow(uint32_t windowId)
WMError WindowManagerService::DestroyWindow(uint32_t windowId)
{
std::lock_guard<std::mutex> lock(mutex_);
WLOGFI("[WMS] Destroy: %{public}d", windowId);
WM_SCOPED_TRACE("wms:DestroyWindow(%d)", windowId);
std::lock_guard<std::recursive_mutex> lock(mutex_);
WMError res = windowController_->DestroyWindow(windowId);
if (res == WMError::WM_OK) {
inputWindowMonitor_->UpdateInputWindow(windowId);
@@ -109,26 +122,81 @@ WMError WindowManagerService::DestroyWindow(uint32_t windowId)
WMError WindowManagerService::MoveTo(uint32_t windowId, int32_t x, int32_t y)
{
std::lock_guard<std::mutex> lock(mutex_);
WLOGFI("[WMS] MoveTo: %{public}d [%{public}d, %{public}d]", windowId, x, y);
WM_SCOPED_TRACE("wms:MoveTo");
std::lock_guard<std::recursive_mutex> lock(mutex_);
return windowController_->MoveTo(windowId, x, y);
}
WMError WindowManagerService::Resize(uint32_t windowId, uint32_t width, uint32_t height)
{
std::lock_guard<std::mutex> lock(mutex_);
WLOGFI("[WMS] Resize: %{public}d [%{public}d, %{public}d]", windowId, width, height);
WM_SCOPED_TRACE("wms:Resize");
std::lock_guard<std::recursive_mutex> lock(mutex_);
return windowController_->Resize(windowId, width, height);
}
WMError WindowManagerService::RequestFocus(uint32_t windowId)
{
std::lock_guard<std::mutex> lock(mutex_);
WLOGFI("[WMS] RequestFocus: %{public}d", windowId);
WM_SCOPED_TRACE("wms:RequestFocus");
std::lock_guard<std::recursive_mutex> lock(mutex_);
return windowController_->RequestFocus(windowId);
}
WMError WindowManagerService::SetWindowMode(uint32_t windowId, WindowMode mode)
{
WM_SCOPED_TRACE("wms:SetWindowMode");
std::lock_guard<std::recursive_mutex> lock(mutex_);
return windowController_->SetWindowMode(windowId, mode);
}
WMError WindowManagerService::SetWindowType(uint32_t windowId, WindowType type)
{
WM_SCOPED_TRACE("wms:SetWindowType");
std::lock_guard<std::recursive_mutex> lock(mutex_);
return windowController_->SetWindowType(windowId, type);
}
WMError WindowManagerService::SetWindowFlags(uint32_t windowId, uint32_t flags)
{
WM_SCOPED_TRACE("wms:SetWindowFlags");
std::lock_guard<std::recursive_mutex> lock(mutex_);
return windowController_->SetWindowFlags(windowId, flags);
}
WMError WindowManagerService::SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& prop)
{
WM_SCOPED_TRACE("wms:SetSystemBarProperty");
std::lock_guard<std::recursive_mutex> lock(mutex_);
return windowController_->SetSystemBarProperty(windowId, type, prop);
}
WMError WindowManagerService::SaveAbilityToken(const sptr<IRemoteObject>& abilityToken, uint32_t windowId)
{
std::lock_guard<std::mutex> lock(mutex_);
WLOGFI("[WMS] SaveAbilityToken: %{public}d", windowId);
std::lock_guard<std::recursive_mutex> lock(mutex_);
return windowController_->SaveAbilityToken(abilityToken, windowId);
}
void WindowManagerService::RegisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
{
if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) {
WLOGFE("failed to get window manager agent");
return;
}
std::lock_guard<std::recursive_mutex> lock(mutex_);
windowController_->RegisterFocusChangedListener(windowManagerAgent);
}
void WindowManagerService::UnregisterFocusChangedListener(const sptr<IWindowManagerAgent>& windowManagerAgent)
{
if ((windowManagerAgent == nullptr) || (windowManagerAgent->AsObject() == nullptr)) {
WLOGFE("windowManagerAgent is null");
return;
}
std::lock_guard<std::recursive_mutex> lock(mutex_);
windowController_->UnregisterFocusChangedListener(windowManagerAgent);
}
}
}

Some files were not shown because too many files have changed in this diff Show More