diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index 53e1c8d30d47048812a1b844fafe936a302229b6..7037c76bc0ba0de6271b25929bdff5e1fa110aa2 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -38,8 +38,7 @@ public: DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, sptr surface); bool DestroyVirtualDisplay(DisplayId displayId); - // TODO: fix me - // sptr GetDisplaySnapshot(DisplayId displayId); + sptr GetDisplaySnapshot(DisplayId displayId); void Clear(); private: DisplayManagerAdapter() = default; diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index 6ec0eb691009bf810c5635e3815aa0b3d16fe592..a391e697421b8f5d474ecaa013b739fa3c52cfff 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -40,40 +40,77 @@ const sptr DisplayManager::GetDisplayById(DisplayId displayId) return display; } -// TODO: fix me -// sptr DisplayManager::GetScreenshot(DisplayId displayId) -// { -// sptr screenShot = SingletonContainer::Get().GetDisplaySnapshot(displayId); -// if (screenShot == nullptr) { -// WLOGFE("DisplayManager::GetScreenshot failed!\n"); -// return nullptr; -// } - -// return screenShot; -// } - -// sptr DisplayManager::GetScreenshot(DisplayId displayId, const Media::Rect &rect, -// const Media::Size &size, int rotation) -// { -// sptr screenShot = SingletonContainer::Get().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 dstScreenshot_ = dstScreenshot.release(); - -// return dstScreenshot_; -// } +sptr DisplayManager::GetScreenshot(DisplayId displayId) +{ + if (displayId == DISPLAY_ID_INVALD) { + WLOGFE("displayId invalid!"); + return nullptr; + } + sptr screenShot = SingletonContainer::Get().GetDisplaySnapshot(displayId); + if (screenShot == nullptr) { + WLOGFE("DisplayManager::GetScreenshot failed!"); + return nullptr; + } + + return screenShot; +} + +bool DisplayManager::CheckRectOffsetValid(int32_t param) const +{ + if (param < 0 || param > MAX_RESOLUTION_VALUE) { + return false; + } + return true; +} + +bool DisplayManager::CheckRectSizeValid(int32_t param) const +{ + if (param < MIN_RESOLUTION_VALUE || param > MAX_RESOLUTION_VALUE) { + return false; + } + return true; +} + +sptr DisplayManager::GetScreenshot(DisplayId displayId, const Media::Rect &rect, + const Media::Size &size, int rotation) +{ + if (displayId == DISPLAY_ID_INVALD) { + WLOGFE("displayId invalid!"); + return nullptr; + } + if (!CheckRectOffsetValid(rect.left) || !CheckRectOffsetValid(rect.top) || + !CheckRectSizeValid(rect.width) || !CheckRectSizeValid(rect.height)) { + WLOGFE("rect invalid! left %{public}d, top %{public}d, w %{public}d, h %{public}d", + rect.left, rect.top, rect.width, rect.height); + return nullptr; + } + if (!CheckRectSizeValid(size.width) || !CheckRectSizeValid(size.height)) { + WLOGFE("size invalid! w %{public}d, h %{public}d", rect.width, rect.height); + return nullptr; + } + sptr screenShot = SingletonContainer::Get().GetDisplaySnapshot(displayId); + if (screenShot == nullptr) { + WLOGFE("DisplayManager::GetScreenshot failed!"); + 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 pixelMap = Media::PixelMap::Create(*screenShot, rect, opt); + if (pixelMap == nullptr) { + WLOGFE("Media::PixelMap::Create failed!"); + return nullptr; + } + sptr dstScreenshot = pixelMap.release(); + + return dstScreenshot; +} const sptr DisplayManager::GetDefaultDisplay() { diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index e9d4949d1af8e01431324206399f2c4e8bd98f9e..1aa9a4c1ae52f367a39b804ad9169c0806704dfc 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -64,20 +64,19 @@ sptr DisplayManagerAdapter::GetDisplayById(DisplayId displayId) return display; } -// TODO: fix me -// sptr DisplayManagerAdapter::GetDisplaySnapshot(DisplayId displayId) -// { -// std::lock_guard lock(mutex_); +sptr DisplayManagerAdapter::GetDisplaySnapshot(DisplayId displayId) +{ + std::lock_guard lock(mutex_); -// if (!InitDMSProxyLocked()) { -// WLOGFE("displayManagerAdapter::GetDisplaySnapshot: InitDMSProxyLocked failed!"); -// return nullptr; -// } + if (!InitDMSProxyLocked()) { + WLOGFE("displayManagerAdapter::GetDisplaySnapshot: InitDMSProxyLocked failed!"); + return nullptr; + } -// sptr dispalySnapshot = displayManagerServiceProxy_->GetDispalySnapshot(displayId); + sptr dispalySnapshot = displayManagerServiceProxy_->GetDispalySnapshot(displayId); -// return dispalySnapshot; -// } + return dispalySnapshot; +} DisplayId DisplayManagerAdapter::CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, sptr surface) diff --git a/dmserver/include/abstract_display_manager.h b/dmserver/include/abstract_display_manager.h index e18dbbaa1780856bf79a979360e19debfdef3073..d2a7852dc21082604ea0d26de1d7fdb98f7253b1 100644 --- a/dmserver/include/abstract_display_manager.h +++ b/dmserver/include/abstract_display_manager.h @@ -17,6 +17,7 @@ #define FOUNDATION_DMSERVER_ABSTRACT_DISPLAY_MANAGER_H #include +#include #include #include "abstract_display.h" @@ -34,8 +35,7 @@ public: RSScreenModeInfo GetScreenActiveMode(ScreenId id); ScreenId CreateVirtualScreen(const VirtualDisplayInfo &virtualDisplayInfo, sptr surface); bool DestroyVirtualScreen(ScreenId screenId); - // TODO: fix me - // sptr GetScreenSnapshot(ScreenId screenId); + sptr GetScreenSnapshot(ScreenId screenId); private: AbstractDisplayManager(); diff --git a/dmserver/include/display_manager_interface.h b/dmserver/include/display_manager_interface.h index aff799ad3342a6bb296ee2f9d6d5d49ab06c5fef..c7a73f6abb1d22c1702a39f63ba1d955a249042b 100644 --- a/dmserver/include/display_manager_interface.h +++ b/dmserver/include/display_manager_interface.h @@ -17,13 +17,11 @@ #define FOUNDATION_DMSERVER_DISPLAY_MANAGER_INTERFACE_H #include - +#include #include #include "display_info.h" - #include "virtual_display_info.h" -// #include "pixel_map.h" namespace OHOS::Rosen { class IDisplayManager : public IRemoteBroker { @@ -35,8 +33,7 @@ public: TRANS_ID_GET_DISPLAY_BY_ID, TRANS_ID_CREATE_VIRTUAL_DISPLAY, TRANS_ID_DESTROY_VIRTUAL_DISPLAY, - // TODO: fix me - // TRANS_ID_GET_DISPLAY_SNAPSHOT, + TRANS_ID_GET_DISPLAY_SNAPSHOT, }; virtual DisplayId GetDefaultDisplayId() = 0; @@ -46,8 +43,7 @@ public: sptr surface) = 0; virtual bool DestroyVirtualDisplay(DisplayId displayId) = 0; - // TODO: fix me - // virtual sptr GetDispalySnapshot(DisplayId displayId) = 0; + virtual sptr GetDispalySnapshot(DisplayId displayId) = 0; }; } // namespace OHOS::Rosen diff --git a/dmserver/include/display_manager_proxy.h b/dmserver/include/display_manager_proxy.h index 141bb41156691123513823a8e0b9caa2a6e8bc8e..ab8d6b24abadc270345f905c6015461e37b7d088 100644 --- a/dmserver/include/display_manager_proxy.h +++ b/dmserver/include/display_manager_proxy.h @@ -33,8 +33,7 @@ public: DisplayId CreateVirtualDisplay(const VirtualDisplayInfo &virtualDisplayInfo, sptr surface) override; bool DestroyVirtualDisplay(DisplayId displayId) override; - // TODO: fix me - // sptr GetDispalySnapshot(DisplayId displayId) override; + sptr GetDispalySnapshot(DisplayId displayId) override; private: static inline BrokerDelegator delegator_; }; diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index 2a07d16bd591e6454eb8752c9ac0d4dbc560353c..0684e31432840b6768ec88379aa60b4b8e2387f5 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -43,8 +43,7 @@ public: DisplayId GetDefaultDisplayId() override; DisplayInfo GetDisplayInfoById(DisplayId displayId) override; - // TODO: fix me - // sptr GetDispalySnapshot(DisplayId displayId) override; + sptr GetDispalySnapshot(DisplayId displayId) override; private: DisplayManagerService(); ~DisplayManagerService() = default; diff --git a/dmserver/src/abstract_display_manager.cpp b/dmserver/src/abstract_display_manager.cpp index 06cadffaeaa1d18d2fe8af141f3c26bf4aa8d878..2ed3b24e268ee374a83ddcb8ba224b596c159988 100644 --- a/dmserver/src/abstract_display_manager.cpp +++ b/dmserver/src/abstract_display_manager.cpp @@ -24,8 +24,6 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "AbstractDisplayManager"}; } -#define SCREENSHOT_GENERATOR - AbstractDisplayManager::AbstractDisplayManager() : rsInterface_(&(RSInterfaces::GetInstance())) { parepareRSScreenManger(); @@ -79,58 +77,14 @@ bool AbstractDisplayManager::DestroyVirtualScreen(ScreenId screenId) return true; } -// TODO: fix me -// #ifdef SCREENSHOT_GENERATOR -// sptr 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 pixelMap_ = newPixelMap.release(); -// if (pixelMap_ == nullptr) { -// WLOGFE("Failed to get pixelMap"); -// return nullptr; -// } - -// return pixelMap_; -// } -// #endif - -// sptr AbstractDisplayManager::GetScreenSnapshot(ScreenId screenId) -// { -// if (rsInterface_ == nullptr) { -// return nullptr; -// } +sptr AbstractDisplayManager::GetScreenSnapshot(ScreenId screenId) +{ + if (rsInterface_ == nullptr) { + return nullptr; + } -// #ifdef SCREENSHOT_GENERATOR -// sptr screenshot = TempCreatePixelMap(); -// #else -// sptr screenshot = rsInterface_->GetScreenSnapshot(screenId); -// #endif + sptr screenshot = nullptr; -// return screenshot; -// } + return screenshot; +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_proxy.cpp b/dmserver/src/display_manager_proxy.cpp index 53c309942803fa82bd7a7399032630b9dc2726f3..5bc29b93849f9364645fbc8b2026363041388703 100644 --- a/dmserver/src/display_manager_proxy.cpp +++ b/dmserver/src/display_manager_proxy.cpp @@ -135,38 +135,37 @@ bool DisplayManagerProxy::DestroyVirtualDisplay(DisplayId displayId) return reply.ReadBool(); } -// TODO: fix me -// sptr DisplayManagerProxy::GetDispalySnapshot(DisplayId displayId) -// { -// sptr 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 pixelMap = reply.ReadParcelable(); -// if (pixelMap == nullptr) { -// WLOGFW("DisplayManagerProxy::GetDispalySnapshot SendRequest nullptr."); -// return nullptr; -// } -// return pixelMap; -// } +sptr DisplayManagerProxy::GetDispalySnapshot(DisplayId displayId) +{ + sptr 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 pixelMap = reply.ReadParcelable(); + if (pixelMap == nullptr) { + WLOGFW("DisplayManagerProxy::GetDispalySnapshot SendRequest nullptr."); + return nullptr; + } + return pixelMap; +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index ef9aff6428ccc5311f63e393c962a88a8397979d..d95ee09530754c12dce71c676e2c2be501acaaf6 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -101,13 +101,12 @@ bool DisplayManagerService::DestroyVirtualDisplay(DisplayId displayId) return AbstractDisplayManager::GetInstance().DestroyVirtualScreen(screenId); } -// TODO: fix me -// sptr DisplayManagerService::GetDispalySnapshot(DisplayId displayId) -// { -// ScreenId screenId = GetScreenIdFromDisplayId(displayId); -// sptr screenSnapshot = AbstractDisplayManager::GetInstance().GetScreenSnapshot(screenId); -// return screenSnapshot; -// } +sptr DisplayManagerService::GetDispalySnapshot(DisplayId displayId) +{ + ScreenId screenId = GetScreenIdFromDisplayId(displayId); + sptr screenSnapshot = AbstractDisplayManager::GetInstance().GetScreenSnapshot(screenId); + return screenSnapshot; +} void DisplayManagerService::OnStop() { diff --git a/dmserver/src/display_manager_stub.cpp b/dmserver/src/display_manager_stub.cpp index 260a1416bdf11b61422718dac8fa35000a57dc01..90c35cdd420fc06f64662cc2cc1660421c93c9fb 100644 --- a/dmserver/src/display_manager_stub.cpp +++ b/dmserver/src/display_manager_stub.cpp @@ -62,14 +62,17 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, reply.WriteBool(result); break; } - // TODO: fix me - // case TRANS_ID_GET_DISPLAY_SNAPSHOT: { - // DisplayId displayId = data.ReadUint64(); + case TRANS_ID_GET_DISPLAY_SNAPSHOT: { + DisplayId displayId = data.ReadUint64(); - // sptr dispalySnapshot = GetDispalySnapshot(displayId); - // reply.WriteParcelable(dispalySnapshot.GetRefPtr()); - // break; - // } + sptr dispalySnapshot = GetDispalySnapshot(displayId); + if (dispalySnapshot == nullptr) { + reply.WriteParcelable(nullptr); + break; + } + reply.WriteParcelable(dispalySnapshot.GetRefPtr()); + break; + } default: WLOGFW("unknown transaction code"); return IPCObjectStub::OnRemoteRequest(code, data, reply, option); diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index 6c913281dde56ffa5d202b6cd182a856ee8566f1..e4ac6224b7317f19840870d84cf386b228d207ec 100644 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -9,7 +9,7 @@ # 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. +# limitations under the License. import("//build/ohos.gni") diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index 7db69d16d697357260494f2e3c3b32ed453bcb59..92bb9dc4b12c211e03a61b2f4e2fd6204e9ed8e2 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -17,12 +17,12 @@ #define FOUNDATION_DM_DISPLAY_MANAGER_H #include +#include #include #include "display.h" #include "single_instance.h" #include "virtual_display_info.h" -// #include "pixel_map.h" // #include "wm_common.h" @@ -45,10 +45,16 @@ public: sptr surface, DisplayId displayIdToMirror, int32_t flags); bool DestroyVirtualDisplay(DisplayId displayId); - // TODO: fix me - // sptr GetScreenshot(DisplayId displayId); - // sptr GetScreenshot(DisplayId displayId, const Media::Rect &rect, - // const Media::Size &size, int rotation); + sptr GetScreenshot(DisplayId displayId); + sptr GetScreenshot(DisplayId displayId, const Media::Rect &rect, + const Media::Size &size, int rotation); + +private: + bool CheckRectOffsetValid(int32_t param) const; + bool CheckRectSizeValid(int32_t param) const; + + const int32_t MAX_RESOLUTION_VALUE = 15260; // max resolution, 16K + const int32_t MIN_RESOLUTION_VALUE = 16; // min resolution }; } // namespace OHOS::Rosen diff --git a/wm/BUILD.gn b/wm/BUILD.gn index 6d7293a9b242d1b90f6c90445f67eadb4a8646e7..3b813c46b489e500a9b6cd2b491c742a3ebd52cd 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -86,6 +86,7 @@ ohos_shared_library("libwmutil") { "//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", + "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", ] external_deps = [ @@ -128,11 +129,9 @@ ohos_shared_library("libwm") { "//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/multimedia/image_standard/interfaces/innerkits:image_native", "//utils/native/base:utils", - # TODO: fix me - # "//foundation/multimedia/image_standard/interfaces/innerkits:image_native", - # weston adapter "//foundation/windowmanager/adapter:libwmadapter",