1 /* 2 * Copyright (c) 2025 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 #ifndef OHOS_ROSEN_WINDOW_SCENE_SNAPSHOT_HELPER_H 17 #define OHOS_ROSEN_WINDOW_SCENE_SNAPSHOT_HELPER_H 18 19 #include <string> 20 21 #include <dm_common.h> 22 23 namespace OHOS::Rosen { 24 namespace { 25 constexpr uint32_t SCREEN_UNKNOWN = 0; 26 constexpr uint32_t SCREEN_EXPAND = 1; 27 constexpr uint32_t SCREEN_FOLDED = 2; 28 constexpr uint32_t SCREEN_COUNT = 3; 29 constexpr uint32_t SNAPSHOT_PORTRAIT = 0; 30 constexpr uint32_t SNAPSHOT_LANDSCAPE = 1; 31 constexpr uint32_t ORIENTATION_COUNT = 2; 32 constexpr uint32_t PORTRAIT_ANGLE = 0; 33 constexpr uint32_t LANDSCAPE_ANGLE = 90; 34 constexpr uint32_t PORTRAIT_INVERTED_ANGLE = 180; 35 constexpr uint32_t LANDSCAPE_INVERTED_ANGLE = 270; 36 constexpr uint32_t ROTATION_ANGLE = 360; 37 constexpr uint32_t ROTATION_COUNT = 4; 38 constexpr uint32_t SECONDARY_EXPAND_OFFSET = 1; 39 } 40 using SnapshotStatus = std::pair<uint32_t, uint32_t>; 41 constexpr SnapshotStatus defaultStatus = { SCREEN_UNKNOWN, SNAPSHOT_PORTRAIT }; 42 constexpr SnapshotStatus defaultCapacity = { SCREEN_EXPAND, SNAPSHOT_LANDSCAPE }; 43 constexpr SnapshotStatus maxCapacity = { SCREEN_COUNT, ORIENTATION_COUNT }; 44 45 class WSSnapshotHelper { 46 public: 47 WSSnapshotHelper() = default; 48 ~WSSnapshotHelper() = default; 49 static uint32_t GetScreenStatus(); 50 static uint32_t GetScreenStatus(FoldStatus foldStatus); 51 static DisplayOrientation GetDisplayOrientation(int32_t rotation); GetOrientation(int32_t rotation)52 static inline uint32_t GetOrientation(int32_t rotation) 53 { 54 if (rotation == LANDSCAPE_ANGLE || rotation == LANDSCAPE_INVERTED_ANGLE) { 55 return SNAPSHOT_LANDSCAPE; 56 } 57 return SNAPSHOT_PORTRAIT; 58 } 59 GetOrientation(DisplayOrientation displayOrientation)60 static inline uint32_t GetOrientation(DisplayOrientation displayOrientation) 61 { 62 if (displayOrientation == DisplayOrientation::LANDSCAPE || 63 displayOrientation == DisplayOrientation::LANDSCAPE_INVERTED) { 64 return SNAPSHOT_LANDSCAPE; 65 } 66 return SNAPSHOT_PORTRAIT; 67 } 68 }; 69 } // namespace OHOS::Rosen 70 71 #endif // OHOS_ROSEN_WINDOW_SCENE_SNAPSHOT_HELPER_H