From 0aaa4dcfc8b696fa6ba56f5c7684346471ff8a92 Mon Sep 17 00:00:00 2001 From: liqiang Date: Fri, 16 Apr 2021 10:39:48 +0800 Subject: [PATCH] adjust bitmap api and its implementation Change-Id: Iec8426e58b4d53ed40d79caa01af759eae576e68 --- frameworks/common/screen.cpp | 11 +++++--- frameworks/components/ui_view.cpp | 18 ++++++++----- frameworks/dock/screen_device_proxy.cpp | 25 +++++++++++-------- frameworks/dock/screen_device_proxy.h | 15 +++-------- interfaces/kits/common/screen.h | 7 ++++++ interfaces/kits/components/ui_view.h | 7 ++++++ .../qt/simulator/drivers/display/monitor.cpp | 2 -- tools/qt/simulator/drivers/display/monitor.h | 2 -- 8 files changed, 50 insertions(+), 37 deletions(-) diff --git a/frameworks/common/screen.cpp b/frameworks/common/screen.cpp index 718b1df..ac9e1ce 100755 --- a/frameworks/common/screen.cpp +++ b/frameworks/common/screen.cpp @@ -17,6 +17,7 @@ #include "core/render_manager.h" #include "dock/screen_device_proxy.h" #include "draw/draw_utils.h" +#include "gfx_utils/mem_api.h" namespace OHOS { uint16_t Screen::GetWidth() @@ -33,16 +34,18 @@ bool Screen::GetCurrentScreenBitmap(ImageInfo& info) { uint16_t screenWidth = ScreenDeviceProxy::GetInstance()->GetScreenWidth(); uint16_t screenHeight = ScreenDeviceProxy::GetInstance()->GetScreenHeight(); - info.data = ScreenDeviceProxy::GetInstance()->GetScreenBitmapBuffer(); - if (info.data == nullptr) { - return false; - } info.header.colorMode = ScreenDeviceProxy::GetInstance()->GetBufferMode(); info.dataSize = screenWidth * screenHeight * DrawUtils::GetByteSizeByColorMode(info.header.colorMode); + uint8_t* screenBitmapBuffer = reinterpret_cast(ImageCacheMalloc(info)); info.header.width = screenWidth; info.header.height = screenHeight; info.header.reserved = 0; info.header.compressMode = 0; + + if (!ScreenDeviceProxy::GetInstance()->GetScreenBitmapBuffer(screenBitmapBuffer, info.dataSize)) { + return false; + } + info.data = screenBitmapBuffer; return true; } } // namespace OHOS diff --git a/frameworks/components/ui_view.cpp b/frameworks/components/ui_view.cpp index 583cdb9..4741081 100755 --- a/frameworks/components/ui_view.cpp +++ b/frameworks/components/ui_view.cpp @@ -21,6 +21,7 @@ #include "draw/draw_rect.h" #include "draw/draw_utils.h" #include "gfx_utils/graphic_log.h" +#include "gfx_utils/mem_api.h" #include "themes/theme_manager.h" namespace OHOS { @@ -809,9 +810,6 @@ uint8_t UIView::GetMixOpaScale() bool UIView::GetBitmap(ImageInfo& bitmap) { - if (!ScreenDeviceProxy::GetInstance()->EnableBitmapBuffer()) { - return false; - } UIView* tempSibling = nextSibling_; UIView* tempParent = parent_; int16_t tempX = rect_.GetX(); @@ -827,15 +825,23 @@ bool UIView::GetBitmap(ImageInfo& bitmap) mask.Intersect(mask, screenRect); uint16_t bufferWidth = mask.GetWidth(); uint16_t bufferHeight = mask.GetHeight(); - ScreenDeviceProxy::GetInstance()->SetViewBitmapBufferWidth(bufferWidth); - RootView::GetInstance()->DrawTop(this, mask); - bitmap.data = ScreenDeviceProxy::GetInstance()->GetBuffer(); bitmap.header.colorMode = ScreenDeviceProxy::GetInstance()->GetBufferMode(); bitmap.dataSize = bufferWidth * bufferHeight * DrawUtils::GetByteSizeByColorMode(bitmap.header.colorMode); bitmap.header.width = bufferWidth; bitmap.header.height = bufferHeight; bitmap.header.reserved = 0; + uint8_t* viewBitmapBuffer = reinterpret_cast(ImageCacheMalloc(bitmap)); + if (viewBitmapBuffer == nullptr) { + nextSibling_ = tempSibling; + parent_ = tempParent; + rect_.SetPosition(tempX, tempY); + return false; + } + ScreenDeviceProxy::GetInstance()->EnableBitmapBuffer(viewBitmapBuffer); + ScreenDeviceProxy::GetInstance()->SetViewBitmapBufferWidth(bufferWidth); + RootView::GetInstance()->DrawTop(this, mask); + bitmap.data = viewBitmapBuffer; ScreenDeviceProxy::GetInstance()->DisableBitmapBuffer(); nextSibling_ = tempSibling; parent_ = tempParent; diff --git a/frameworks/dock/screen_device_proxy.cpp b/frameworks/dock/screen_device_proxy.cpp index 873420b..72a4b7b 100755 --- a/frameworks/dock/screen_device_proxy.cpp +++ b/frameworks/dock/screen_device_proxy.cpp @@ -109,26 +109,29 @@ ColorMode ScreenDeviceProxy::GetBufferMode() return frameBufferMode_; } -bool ScreenDeviceProxy::EnableBitmapBuffer() +void ScreenDeviceProxy::EnableBitmapBuffer(uint8_t* viewBitmapBuffer) { - if (viewBitmapBuffer_ == nullptr) { - return false; + if (viewBitmapBuffer == nullptr) { + return; } + viewBitmapBuffer_ = viewBitmapBuffer; enableBitmapBuffer_ = true; - return true; } -uint8_t* ScreenDeviceProxy::GetScreenBitmapBuffer() +bool ScreenDeviceProxy::GetScreenBitmapBuffer(uint8_t* dest, uint32_t size) { - if (screenBitmapBuffer_ == nullptr) { - return nullptr; + if ((dest == nullptr) || (size == 0)) { + return false; } - uint8_t* buf = GetBuffer(); uint8_t byteSize = DrawUtils::GetByteSizeByColorMode(frameBufferMode_); uint32_t bufSize = width_ * height_ * byteSize; - if (memcpy_s(screenBitmapBuffer_, bufSize, buf, bufSize) != EOK) { - return nullptr; + if (size < bufSize) { + return false; + } + uint8_t* buf = GetBuffer(); + if (memcpy_s(dest, size, buf, bufSize) != EOK) { + return false; } - return screenBitmapBuffer_; + return true; } } // namespace OHOS diff --git a/frameworks/dock/screen_device_proxy.h b/frameworks/dock/screen_device_proxy.h index 689ad99..0bf3c41 100755 --- a/frameworks/dock/screen_device_proxy.h +++ b/frameworks/dock/screen_device_proxy.h @@ -185,28 +185,20 @@ public: ColorMode GetBufferMode(); - void SetBitmapBuffer(uint8_t* addr0, uint8_t* addr1) - { - if ((addr0 == nullptr) || (addr1 == nullptr)) { - return; - } - viewBitmapBuffer_ = addr0; - screenBitmapBuffer_ = addr1; - } - void SetViewBitmapBufferWidth(uint16_t width) { bitmapBufferWidth_ = width; } - bool EnableBitmapBuffer(); + void EnableBitmapBuffer(uint8_t* viewBitmapBuffer); void DisableBitmapBuffer() { enableBitmapBuffer_ = false; } - uint8_t* GetScreenBitmapBuffer(); + bool GetScreenBitmapBuffer(uint8_t* dest, uint32_t size); +; private: ScreenDeviceProxy() {} virtual ~ScreenDeviceProxy() {} @@ -234,7 +226,6 @@ private: ImageInfo animatorImageInfo_ = {{0}}; // snapshot related uint8_t* viewBitmapBuffer_ = nullptr; - uint8_t* screenBitmapBuffer_ = nullptr; uint16_t bitmapBufferWidth_ = 0; bool enableBitmapBuffer_ = false; // snapshot related diff --git a/interfaces/kits/common/screen.h b/interfaces/kits/common/screen.h index 4bfbf84..f30d289 100755 --- a/interfaces/kits/common/screen.h +++ b/interfaces/kits/common/screen.h @@ -76,6 +76,13 @@ public: */ uint16_t GetHeight(); + /** + * @brief 获取当前屏幕的bitmap截图.请注意该接口会申请内存,请在需要释放时使用{@link ImageCacheFree()}接口. + * @param info bitmap存储对象,获取的截图将被存到该引用中. + * @return bitmap是否获取成功. + * @since 5.0 + * @version 3.0 + */ bool GetCurrentScreenBitmap(ImageInfo& info); private: diff --git a/interfaces/kits/components/ui_view.h b/interfaces/kits/components/ui_view.h index 8cd4a2d..da6474f 100755 --- a/interfaces/kits/components/ui_view.h +++ b/interfaces/kits/components/ui_view.h @@ -1429,6 +1429,13 @@ public: OnFocusListener* GetOnFocusListener() const { return onFocusListener_; } #endif + /** + * @brief 获取当前视图的bitmap截图.请注意该接口会申请内存,请在需要释放时使用{@link ImageCacheFree()}接口. + * @param info bitmap存储对象,获取的截图将被存到该引用中. + * @return bitmap是否获取成功. + * @since 5.0 + * @version 3.0 + */ bool GetBitmap(ImageInfo& bitmap); protected: diff --git a/tools/qt/simulator/drivers/display/monitor.cpp b/tools/qt/simulator/drivers/display/monitor.cpp index 90c91ab..50c8591 100755 --- a/tools/qt/simulator/drivers/display/monitor.cpp +++ b/tools/qt/simulator/drivers/display/monitor.cpp @@ -32,8 +32,6 @@ void Monitor::InitHal() HORIZONTAL_RESOLUTION); ScreenDeviceProxy::GetInstance()->SetAnimatorbuffer(reinterpret_cast(animaterBuffer_), ARGB8888, HORIZONTAL_RESOLUTION); - ScreenDeviceProxy::GetInstance()->SetBitmapBuffer(reinterpret_cast(viewBitmapBuffer_), - reinterpret_cast(screenBitmapBuffer_)); Monitor* display = Monitor::GetInstance(); ScreenDeviceProxy::GetInstance()->SetDevice(display); diff --git a/tools/qt/simulator/drivers/display/monitor.h b/tools/qt/simulator/drivers/display/monitor.h index d3adb86..c453b42 100755 --- a/tools/qt/simulator/drivers/display/monitor.h +++ b/tools/qt/simulator/drivers/display/monitor.h @@ -53,8 +53,6 @@ private: uint8_t fontPsramBaseAddr_[MIN_FONT_PSRAM_LENGTH]; uint32_t tftFb_[HORIZONTAL_RESOLUTION * VERTICAL_RESOLUTION]; uint32_t animaterBuffer_[HORIZONTAL_RESOLUTION * VERTICAL_RESOLUTION]; - uint32_t viewBitmapBuffer_[HORIZONTAL_RESOLUTION * VERTICAL_RESOLUTION]; - uint32_t screenBitmapBuffer_[HORIZONTAL_RESOLUTION * VERTICAL_RESOLUTION]; uint32_t defaultColor_; }; } // namespace OHOS -- GitLab