1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include "disp_dev.h"
17#include "components/root_view.h"
18#include "draw/draw_utils.h"
19#include "fbdev.h"
20
21namespace OHOS {
22DispDev *DispDev::GetInstance()
23{
24    static DispDev instance;
25    if (!instance.isRegister_) {
26        FbdevInit();
27        instance.isRegister_ = true;
28    }
29    return &instance;
30}
31
32BufferInfo *DispDev::GetFBBufferInfo()
33{
34    const int DEFAULT_FBUF_COLOR = 0x44;
35
36    static BufferInfo bufferInfo;
37    LiteSurfaceData *surfaceData = GetDevSurfaceData();
38    bufferInfo.rect = {0, 0, HORIZONTAL_RESOLUTION - 1, VERTICAL_RESOLUTION - 1};
39    bufferInfo.mode = ARGB8888;
40    bufferInfo.color = DEFAULT_FBUF_COLOR;
41    bufferInfo.phyAddr = surfaceData->phyAddr;
42    bufferInfo.virAddr = surfaceData->virAddr;
43    bufferInfo.stride = HORIZONTAL_RESOLUTION * (DrawUtils::GetByteSizeByColorMode(bufferInfo.mode));
44    bufferInfo.width = HORIZONTAL_RESOLUTION;
45    bufferInfo.height = VERTICAL_RESOLUTION;
46    this->fbAddr = surfaceData->phyAddr;
47    return &bufferInfo;
48}
49
50void DispDev::UpdateFBBuffer()
51{
52    BufferInfo *bufferInfo = DispDev::GetInstance()->GetFBBufferInfo();
53    if (this->fbAddr != bufferInfo->phyAddr) {
54        this->fbAddr = bufferInfo->phyAddr;
55        RootView::GetInstance()->UpdateBufferInfo(bufferInfo);
56    }
57}
58
59void DispDev::Flush(const OHOS::Rect& flushRect)
60{
61    FbdevFlush();
62}
63} // namespace OHOS
64