• 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     BufferInfo* bufferInfo = BaseGfxEngine::GetInstance()->GetFBBufferInfo();
43     if (bufferInfo == nullptr) {
44         return false;
45     }
46     uint16_t screenWidth = BaseGfxEngine::GetInstance()->GetScreenWidth();
47     uint16_t screenHeight = BaseGfxEngine::GetInstance()->GetScreenHeight();
48     info.header.colorMode = ARGB8888;
49     info.dataSize = screenWidth * screenHeight * DrawUtils::GetByteSizeByColorMode(info.header.colorMode);
50     info.data = reinterpret_cast<uint8_t*>(ImageCacheMalloc(info));
51     if (info.data == nullptr) {
52         return false;
53     }
54     info.header.width = screenWidth;
55     info.header.height = screenHeight;
56     info.header.reserved = 0;
57     info.header.compressMode = 0;
58 
59     Rect screenRect = {0, 0, static_cast<int16_t>(screenWidth - 1), static_cast<int16_t>(screenHeight - 1)};
60     Point dstPos = {0, 0};
61     BlendOption blendOption;
62     blendOption.opacity = OPA_OPAQUE;
63 
64     BufferInfo dstBufferInfo;
65     dstBufferInfo.rect = screenRect;
66     dstBufferInfo.mode = ARGB8888;
67     dstBufferInfo.color = 0x44;
68     dstBufferInfo.phyAddr = dstBufferInfo.virAddr = static_cast<void*>(const_cast<uint8_t*>(info.data));
69     dstBufferInfo.stride = screenWidth * 4; // 4: bpp
70     dstBufferInfo.width = screenWidth;
71     dstBufferInfo.height = screenHeight;
72 
73     BaseGfxEngine::GetInstance()->Blit(dstBufferInfo, dstPos, *bufferInfo, screenRect, blendOption);
74     return true;
75 }
76 
GetScreenShape()77 ScreenShape Screen::GetScreenShape()
78 {
79     return BaseGfxEngine::GetInstance()->GetScreenShape();
80 }
81 } // namespace OHOS
82