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

adjust bitmap api and its implementation

Change-Id: Iec8426e58b4d53ed40d79caa01af759eae576e68
上级 b3974e19
......@@ -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<uint8_t*>(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
......@@ -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<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();
nextSibling_ = tempSibling;
parent_ = tempParent;
......
......@@ -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
......@@ -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
......
......@@ -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:
......
......@@ -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:
......
......@@ -32,8 +32,6 @@ void Monitor::InitHal()
HORIZONTAL_RESOLUTION);
ScreenDeviceProxy::GetInstance()->SetAnimatorbuffer(reinterpret_cast<uint8_t*>(animaterBuffer_), ARGB8888,
HORIZONTAL_RESOLUTION);
ScreenDeviceProxy::GetInstance()->SetBitmapBuffer(reinterpret_cast<uint8_t*>(viewBitmapBuffer_),
reinterpret_cast<uint8_t*>(screenBitmapBuffer_));
Monitor* display = Monitor::GetInstance();
ScreenDeviceProxy::GetInstance()->SetDevice(display);
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册