• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 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 "common/screen.h"
17 #include "core/render_manager.h"
18 #include "draw/draw_utils.h"
19 #include "engines/gfx/gfx_engine_manager.h"
20 #include "gfx_utils/mem_api.h"
21 #include "securec.h"
22 
23 namespace OHOS {
GetInstance()24 Screen& Screen::GetInstance()
25 {
26     static Screen instance;
27     return instance;
28 }
29 
GetWidth()30 uint16_t Screen::GetWidth()
31 {
32     return BaseGfxEngine::GetInstance()->GetScreenWidth();
33 }
34 
GetHeight()35 uint16_t Screen::GetHeight()
36 {
37     return BaseGfxEngine::GetInstance()->GetScreenHeight();
38 }
39 
GetCurrentScreenBitmap(ImageInfo & info)40 bool Screen::GetCurrentScreenBitmap(ImageInfo& info)
41 {
42 #if defined ENABLE_WINDOW && ENABLE_WINDOW
43     return false;
44 #else
45     BufferInfo* bufferInfo = BaseGfxEngine::GetInstance()->GetFBBufferInfo();
46     if (bufferInfo == nullptr) {
47         return false;
48     }
49     uint16_t screenWidth = BaseGfxEngine::GetInstance()->GetFBBufferInfo()->width;
50     uint16_t screenHeight = BaseGfxEngine::GetInstance()->GetScreenHeight();
51     info.header.colorMode = ARGB8888;
52     info.dataSize = screenWidth * screenHeight * DrawUtils::GetByteSizeByColorMode(info.header.colorMode);
53     info.data = reinterpret_cast<uint8_t*>(ImageCacheMalloc(info));
54     if (info.data == nullptr) {
55         return false;
56     }
57     info.header.width = screenWidth;
58     info.header.height = screenHeight;
59     info.header.reserved = 0;
60     info.header.compressMode = 0;
61 
62     Rect screenRect = {0, 0, static_cast<int16_t>(screenWidth - 1), static_cast<int16_t>(screenHeight - 1)};
63     Point dstPos = {0, 0};
64     BlendOption blendOption;
65     blendOption.opacity = OPA_OPAQUE;
66     blendOption.mode = BLEND_SRC;
67 
68     BufferInfo dstBufferInfo;
69     dstBufferInfo.rect = screenRect;
70     dstBufferInfo.mode = ARGB8888;
71     dstBufferInfo.color = 0x44;
72     dstBufferInfo.phyAddr = dstBufferInfo.virAddr = static_cast<void*>(const_cast<uint8_t*>(info.data));
73     dstBufferInfo.stride = screenWidth * 4; // 4: bpp
74     dstBufferInfo.width = screenWidth;
75     dstBufferInfo.height = screenHeight;
76 
77     BaseGfxEngine::GetInstance()->Blit(dstBufferInfo, dstPos, *bufferInfo, screenRect, blendOption);
78     return true;
79 #endif
80 }
81 
GetScreenShape()82 ScreenShape Screen::GetScreenShape()
83 {
84     return BaseGfxEngine::GetInstance()->GetScreenShape();
85 }
86 } // namespace OHOS
87