提交 0aaa4dcf 编写于 作者: L liqiang

adjust bitmap api and its implementation

Change-Id: Iec8426e58b4d53ed40d79caa01af759eae576e68
上级 b3974e19
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "core/render_manager.h" #include "core/render_manager.h"
#include "dock/screen_device_proxy.h" #include "dock/screen_device_proxy.h"
#include "draw/draw_utils.h" #include "draw/draw_utils.h"
#include "gfx_utils/mem_api.h"
namespace OHOS { namespace OHOS {
uint16_t Screen::GetWidth() uint16_t Screen::GetWidth()
...@@ -33,16 +34,18 @@ bool Screen::GetCurrentScreenBitmap(ImageInfo& info) ...@@ -33,16 +34,18 @@ bool Screen::GetCurrentScreenBitmap(ImageInfo& info)
{ {
uint16_t screenWidth = ScreenDeviceProxy::GetInstance()->GetScreenWidth(); uint16_t screenWidth = ScreenDeviceProxy::GetInstance()->GetScreenWidth();
uint16_t screenHeight = ScreenDeviceProxy::GetInstance()->GetScreenHeight(); uint16_t screenHeight = ScreenDeviceProxy::GetInstance()->GetScreenHeight();
info.data = ScreenDeviceProxy::GetInstance()->GetScreenBitmapBuffer();
if (info.data == nullptr) {
return false;
}
info.header.colorMode = ScreenDeviceProxy::GetInstance()->GetBufferMode(); info.header.colorMode = ScreenDeviceProxy::GetInstance()->GetBufferMode();
info.dataSize = screenWidth * screenHeight * DrawUtils::GetByteSizeByColorMode(info.header.colorMode); info.dataSize = screenWidth * screenHeight * DrawUtils::GetByteSizeByColorMode(info.header.colorMode);
uint8_t* screenBitmapBuffer = reinterpret_cast<uint8_t*>(ImageCacheMalloc(info));
info.header.width = screenWidth; info.header.width = screenWidth;
info.header.height = screenHeight; info.header.height = screenHeight;
info.header.reserved = 0; info.header.reserved = 0;
info.header.compressMode = 0; info.header.compressMode = 0;
if (!ScreenDeviceProxy::GetInstance()->GetScreenBitmapBuffer(screenBitmapBuffer, info.dataSize)) {
return false;
}
info.data = screenBitmapBuffer;
return true; return true;
} }
} // namespace OHOS } // namespace OHOS
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "draw/draw_rect.h" #include "draw/draw_rect.h"
#include "draw/draw_utils.h" #include "draw/draw_utils.h"
#include "gfx_utils/graphic_log.h" #include "gfx_utils/graphic_log.h"
#include "gfx_utils/mem_api.h"
#include "themes/theme_manager.h" #include "themes/theme_manager.h"
namespace OHOS { namespace OHOS {
...@@ -809,9 +810,6 @@ uint8_t UIView::GetMixOpaScale() ...@@ -809,9 +810,6 @@ uint8_t UIView::GetMixOpaScale()
bool UIView::GetBitmap(ImageInfo& bitmap) bool UIView::GetBitmap(ImageInfo& bitmap)
{ {
if (!ScreenDeviceProxy::GetInstance()->EnableBitmapBuffer()) {
return false;
}
UIView* tempSibling = nextSibling_; UIView* tempSibling = nextSibling_;
UIView* tempParent = parent_; UIView* tempParent = parent_;
int16_t tempX = rect_.GetX(); int16_t tempX = rect_.GetX();
...@@ -827,15 +825,23 @@ bool UIView::GetBitmap(ImageInfo& bitmap) ...@@ -827,15 +825,23 @@ bool UIView::GetBitmap(ImageInfo& bitmap)
mask.Intersect(mask, screenRect); mask.Intersect(mask, screenRect);
uint16_t bufferWidth = mask.GetWidth(); uint16_t bufferWidth = mask.GetWidth();
uint16_t bufferHeight = mask.GetHeight(); 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.header.colorMode = ScreenDeviceProxy::GetInstance()->GetBufferMode();
bitmap.dataSize = bufferWidth * bufferHeight * DrawUtils::GetByteSizeByColorMode(bitmap.header.colorMode); bitmap.dataSize = bufferWidth * bufferHeight * DrawUtils::GetByteSizeByColorMode(bitmap.header.colorMode);
bitmap.header.width = bufferWidth; bitmap.header.width = bufferWidth;
bitmap.header.height = bufferHeight; bitmap.header.height = bufferHeight;
bitmap.header.reserved = 0; bitmap.header.reserved = 0;
uint8_t* viewBitmapBuffer = reinterpret_cast<uint8_t*>(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(); ScreenDeviceProxy::GetInstance()->DisableBitmapBuffer();
nextSibling_ = tempSibling; nextSibling_ = tempSibling;
parent_ = tempParent; parent_ = tempParent;
......
...@@ -109,26 +109,29 @@ ColorMode ScreenDeviceProxy::GetBufferMode() ...@@ -109,26 +109,29 @@ ColorMode ScreenDeviceProxy::GetBufferMode()
return frameBufferMode_; return frameBufferMode_;
} }
bool ScreenDeviceProxy::EnableBitmapBuffer() void ScreenDeviceProxy::EnableBitmapBuffer(uint8_t* viewBitmapBuffer)
{ {
if (viewBitmapBuffer_ == nullptr) { if (viewBitmapBuffer == nullptr) {
return false; return;
} }
viewBitmapBuffer_ = viewBitmapBuffer;
enableBitmapBuffer_ = true; enableBitmapBuffer_ = true;
return true;
} }
uint8_t* ScreenDeviceProxy::GetScreenBitmapBuffer() bool ScreenDeviceProxy::GetScreenBitmapBuffer(uint8_t* dest, uint32_t size)
{ {
if (screenBitmapBuffer_ == nullptr) { if ((dest == nullptr) || (size == 0)) {
return nullptr; return false;
} }
uint8_t* buf = GetBuffer();
uint8_t byteSize = DrawUtils::GetByteSizeByColorMode(frameBufferMode_); uint8_t byteSize = DrawUtils::GetByteSizeByColorMode(frameBufferMode_);
uint32_t bufSize = width_ * height_ * byteSize; uint32_t bufSize = width_ * height_ * byteSize;
if (memcpy_s(screenBitmapBuffer_, bufSize, buf, bufSize) != EOK) { if (size < bufSize) {
return nullptr; return false;
}
uint8_t* buf = GetBuffer();
if (memcpy_s(dest, size, buf, bufSize) != EOK) {
return false;
} }
return screenBitmapBuffer_; return true;
} }
} // namespace OHOS } // namespace OHOS
...@@ -185,28 +185,20 @@ public: ...@@ -185,28 +185,20 @@ public:
ColorMode GetBufferMode(); 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) void SetViewBitmapBufferWidth(uint16_t width)
{ {
bitmapBufferWidth_ = width; bitmapBufferWidth_ = width;
} }
bool EnableBitmapBuffer(); void EnableBitmapBuffer(uint8_t* viewBitmapBuffer);
void DisableBitmapBuffer() void DisableBitmapBuffer()
{ {
enableBitmapBuffer_ = false; enableBitmapBuffer_ = false;
} }
uint8_t* GetScreenBitmapBuffer(); bool GetScreenBitmapBuffer(uint8_t* dest, uint32_t size);
;
private: private:
ScreenDeviceProxy() {} ScreenDeviceProxy() {}
virtual ~ScreenDeviceProxy() {} virtual ~ScreenDeviceProxy() {}
...@@ -234,7 +226,6 @@ private: ...@@ -234,7 +226,6 @@ private:
ImageInfo animatorImageInfo_ = {{0}}; ImageInfo animatorImageInfo_ = {{0}};
// snapshot related // snapshot related
uint8_t* viewBitmapBuffer_ = nullptr; uint8_t* viewBitmapBuffer_ = nullptr;
uint8_t* screenBitmapBuffer_ = nullptr;
uint16_t bitmapBufferWidth_ = 0; uint16_t bitmapBufferWidth_ = 0;
bool enableBitmapBuffer_ = false; bool enableBitmapBuffer_ = false;
// snapshot related // snapshot related
......
...@@ -76,6 +76,13 @@ public: ...@@ -76,6 +76,13 @@ public:
*/ */
uint16_t GetHeight(); uint16_t GetHeight();
/**
* @brief 获取当前屏幕的bitmap截图.请注意该接口会申请内存,请在需要释放时使用{@link ImageCacheFree()}接口.
* @param info bitmap存储对象,获取的截图将被存到该引用中.
* @return bitmap是否获取成功.
* @since 5.0
* @version 3.0
*/
bool GetCurrentScreenBitmap(ImageInfo& info); bool GetCurrentScreenBitmap(ImageInfo& info);
private: private:
......
...@@ -1429,6 +1429,13 @@ public: ...@@ -1429,6 +1429,13 @@ public:
OnFocusListener* GetOnFocusListener() const { return onFocusListener_; } OnFocusListener* GetOnFocusListener() const { return onFocusListener_; }
#endif #endif
/**
* @brief 获取当前视图的bitmap截图.请注意该接口会申请内存,请在需要释放时使用{@link ImageCacheFree()}接口.
* @param info bitmap存储对象,获取的截图将被存到该引用中.
* @return bitmap是否获取成功.
* @since 5.0
* @version 3.0
*/
bool GetBitmap(ImageInfo& bitmap); bool GetBitmap(ImageInfo& bitmap);
protected: protected:
......
...@@ -32,8 +32,6 @@ void Monitor::InitHal() ...@@ -32,8 +32,6 @@ void Monitor::InitHal()
HORIZONTAL_RESOLUTION); HORIZONTAL_RESOLUTION);
ScreenDeviceProxy::GetInstance()->SetAnimatorbuffer(reinterpret_cast<uint8_t*>(animaterBuffer_), ARGB8888, ScreenDeviceProxy::GetInstance()->SetAnimatorbuffer(reinterpret_cast<uint8_t*>(animaterBuffer_), ARGB8888,
HORIZONTAL_RESOLUTION); HORIZONTAL_RESOLUTION);
ScreenDeviceProxy::GetInstance()->SetBitmapBuffer(reinterpret_cast<uint8_t*>(viewBitmapBuffer_),
reinterpret_cast<uint8_t*>(screenBitmapBuffer_));
Monitor* display = Monitor::GetInstance(); Monitor* display = Monitor::GetInstance();
ScreenDeviceProxy::GetInstance()->SetDevice(display); ScreenDeviceProxy::GetInstance()->SetDevice(display);
......
...@@ -53,8 +53,6 @@ private: ...@@ -53,8 +53,6 @@ private:
uint8_t fontPsramBaseAddr_[MIN_FONT_PSRAM_LENGTH]; uint8_t fontPsramBaseAddr_[MIN_FONT_PSRAM_LENGTH];
uint32_t tftFb_[HORIZONTAL_RESOLUTION * VERTICAL_RESOLUTION]; uint32_t tftFb_[HORIZONTAL_RESOLUTION * VERTICAL_RESOLUTION];
uint32_t animaterBuffer_[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_; uint32_t defaultColor_;
}; };
} // namespace OHOS } // namespace OHOS
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册