screen_device_proxy.cpp 3.8 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright (c) 2020-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 "dock/screen_device_proxy.h"
#include "draw/draw_utils.h"
Z
zhangguyuan 已提交
18
#include "gfx_utils/graphic_log.h"
M
mamingshuai 已提交
19 20 21
#include "securec.h"

namespace OHOS {
Z
zhdengc 已提交
22 23 24 25 26 27
ScreenDeviceProxy* ScreenDeviceProxy::GetInstance()
{
    static ScreenDeviceProxy instance;
    return &instance;
}

M
mamingshuai 已提交
28 29 30 31 32 33 34
void ScreenDeviceProxy::Flush() {}

void ScreenDeviceProxy::OnFlushReady()
{
    flush_.Notify();
}

J
jsjzju 已提交
35
void ScreenDeviceProxy::OnRenderFinish(const Rect& mask)
M
mamingshuai 已提交
36 37
{
    if (device_ != nullptr) {
J
jsjzju 已提交
38
        device_->RenderFinish(mask);
M
mamingshuai 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
    }
}

void ScreenDeviceProxy::DrawAnimatorBuffer(const Rect& invalidatedArea)
{
}

void ScreenDeviceProxy::SetAnimatorRect(const Rect& rect)
{
    curViewRect_ = rect;
    uint16_t bufferWidth = (width_ > curViewRect_.GetWidth()) ? curViewRect_.GetWidth() : width_;
    uint16_t bufferHeight = (height_ > curViewRect_.GetHeight()) ? curViewRect_.GetHeight() : height_;

    animatorImageInfo_.header.colorMode = animatorBufferMode_;
    animatorImageInfo_.dataSize = bufferWidth * bufferHeight * DrawUtils::GetByteSizeByColorMode(animatorBufferMode_);
    animatorImageInfo_.header.width = bufferWidth;
    animatorImageInfo_.header.height = bufferHeight;
    animatorImageInfo_.header.reserved = 0;
    animatorImageInfo_.data = reinterpret_cast<uint8_t*>(GetBuffer());
    if (animatorImageInfo_.data == nullptr) {
        return;
    }

    SetAnimatorbufferWidth(bufferWidth);
    if (memset_s(reinterpret_cast<void*>(const_cast<uint8_t*>(animatorImageInfo_.data)), animatorImageInfo_.dataSize, 0,
Y
YueBiang 已提交
64
        animatorImageInfo_.dataSize) != EOK) {
65
        GRAPHIC_LOGE("animator buffer memset failed.");
M
mamingshuai 已提交
66 67 68 69 70 71
    }
}

void ScreenDeviceProxy::SetScreenSize(uint16_t width, uint16_t height)
{
    if ((width == 0) || (height == 0)) {
72
        GRAPHIC_LOGE("screen size can not be zero.");
M
mamingshuai 已提交
73 74 75 76 77 78 79 80
        return;
    }
    width_ = width;
    height_ = height;
}

uint8_t* ScreenDeviceProxy::GetBuffer()
{
81 82 83
    if (enableBitmapBuffer_) {
        return viewBitmapBuffer_;
    }
M
mamingshuai 已提交
84 85 86
    flush_.Wait();
    if (useAnimatorBuff_) {
        if (animatorBufferAddr_ == nullptr) {
87
            GRAPHIC_LOGE("Invalid param animatorBufferAddr_.");
M
mamingshuai 已提交
88 89
            return nullptr;
        }
J
jsjzju 已提交
90
        return animatorBufferAddr_;
M
mamingshuai 已提交
91 92
    }
    if (frameBufferAddr_ == nullptr) {
93
        GRAPHIC_LOGE("Invalid param frameBufferAddr_.");
M
mamingshuai 已提交
94 95
        return nullptr;
    }
J
jsjzju 已提交
96
    return frameBufferAddr_;
M
mamingshuai 已提交
97 98 99 100 101 102 103 104 105
}

ColorMode ScreenDeviceProxy::GetBufferMode()
{
    if (useAnimatorBuff_) {
        return animatorBufferMode_;
    }
    return frameBufferMode_;
}
106

107
void ScreenDeviceProxy::EnableBitmapBuffer(uint8_t* viewBitmapBuffer)
108
{
109 110
    if (viewBitmapBuffer == nullptr) {
        return;
111
    }
112
    viewBitmapBuffer_ = viewBitmapBuffer;
113 114 115
    enableBitmapBuffer_ = true;
}

116
bool ScreenDeviceProxy::GetScreenBitmapBuffer(uint8_t* dest, uint32_t size)
117
{
118 119
    if ((dest == nullptr) || (size == 0)) {
        return false;
120 121 122
    }
    uint8_t byteSize = DrawUtils::GetByteSizeByColorMode(frameBufferMode_);
    uint32_t bufSize = width_ * height_ * byteSize;
123 124 125 126
    if (size < bufSize) {
        return false;
    }
    uint8_t* buf = GetBuffer();
L
liqiang 已提交
127 128 129
    if (buf == nullptr) {
        return false;
    }
130 131
    if (memcpy_s(dest, size, buf, bufSize) != EOK) {
        return false;
132
    }
133
    return true;
134
}
M
mamingshuai 已提交
135
} // namespace OHOS