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