1 /* 2 * Copyright (c) 2023 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 UI_ROTATION_H 17 #define UI_ROTATION_H 18 19 #include <cstdint> 20 #include <utility> 21 #include "gfx_utils/rect.h" 22 #include "macros_updater.h" 23 24 namespace Updater { 25 enum class UI_ROTATION_DEGREE { 26 UI_ROTATION_0, 27 UI_ROTATION_90, 28 UI_ROTATION_180, 29 UI_ROTATION_270, 30 UI_ROTATION_NULL 31 }; 32 33 class UiRotation final { 34 DISALLOW_COPY_MOVE(UiRotation); 35 public: 36 UiRotation() = default; 37 ~UiRotation() = default; 38 static UiRotation &GetInstance(void); 39 void SetDegree(UI_ROTATION_DEGREE degree); 40 void InitRotation(int realWidth, int realHeight, uint8_t pixelBytes); 41 int GetWidth(void); 42 int GetHeight(void); 43 void RotateBuffer(const uint8_t *origBuf, uint8_t *dstBuf, uint32_t size); 44 void SetFlushRange(const OHOS::Rect &rect); 45 std::pair<int, int> RotateXY(int x, int y); 46 private: 47 void RotateWidthHeight(int realWidth, int realHeight); 48 int width_ {}; 49 int height_ {}; 50 uint8_t pixelBytes_ {}; 51 int sinR_ {}; 52 int cosR_ {}; 53 int offsetX_ {}; 54 int offsetY_ {}; 55 int oldRowBytes_ {}; 56 int newRowBytes_ {}; 57 OHOS::Rect rect_ {}; 58 UI_ROTATION_DEGREE degree_ {UI_ROTATION_DEGREE::UI_ROTATION_0}; 59 }; 60 } 61 62 #endif // UI_ROTATION_H