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 };
31 
32 class UiRotation final {
33     DISALLOW_COPY_MOVE(UiRotation);
34 public:
35     UiRotation() = default;
36     ~UiRotation() = default;
37     static UiRotation &GetInstance(void);
38     void SetDegree(UI_ROTATION_DEGREE degree);
39     void InitRotation(int realWidth, int realHeight, uint8_t pixelBytes);
40     int GetWidth(void);
41     int GetHeight(void);
42     void RotateBuffer(const uint8_t *origBuf, uint8_t *dstBuf, uint32_t size);
43     void SetFlushRange(const OHOS::Rect &rect);
44     std::pair<int, int> RotateXY(int x, int y);
45 private:
46     void RotateWidthHeight(int realWidth, int realHeight);
47     int width_ {};
48     int height_ {};
49     uint8_t pixelBytes_ {};
50     int sinR_ {};
51     int cosR_ {};
52     int offsetX_ {};
53     int offsetY_ {};
54     int oldRowBytes_ {};
55     int newRowBytes_ {};
56     OHOS::Rect rect_ {};
57     UI_ROTATION_DEGREE degree_ {UI_ROTATION_DEGREE::UI_ROTATION_0};
58 };
59 }
60 
61 #endif // UI_ROTATION_H