1 /*
2  * Copyright (c) 2022 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_DISPLAY_CUTOUT_CONTROLLER_H
17 #define OHOS_ROSEN_DISPLAY_CUTOUT_CONTROLLER_H
18 
19 #include <mutex>
20 #include <map>
21 #include <refbase.h>
22 #include <vector>
23 
24 #include "include/core/SkPath.h"
25 #include "include/core/SkMatrix.h"
26 #include "include/core/SkPathMeasure.h"
27 #include "include/utils/SkParsePath.h"
28 
29 #include "cutout_info.h"
30 #include "dm_common.h"
31 #include "noncopyable.h"
32 #include "window_manager_hilog.h"
33 
34 namespace OHOS {
35 namespace Rosen {
36 class DisplayCutoutController : public RefBase {
37 public:
DisplayCutoutController()38     DisplayCutoutController() {};
39     virtual ~DisplayCutoutController() = default;
40 
41     void SetCutoutSvgPath(DisplayId displayId, const std::string& svgPath);
42     sptr<CutoutInfo> GetCutoutInfo(DisplayId displayId);
43 
44     // For built-in display
45     void SetBuiltInDisplayCutoutSvgPath(const std::string& svgPath);
46     static void SetIsWaterfallDisplay(bool isWaterfallDisplay);
47     static bool IsWaterfallDisplay();
48     void SetCurvedScreenBoundary(std::vector<int> curvedScreenBoundary);
49 
50     // For waterfall display curved area compression.
51     static void SetWaterfallAreaCompressionEnableWhenHorzontal(bool isEnable);
52     static void SetWaterfallAreaCompressionSizeWhenHorizontal(uint32_t size);
53     static bool IsWaterfallAreaCompressionEnableWhenHorizontal();
54     static uint32_t GetWaterfallAreaCompressionSizeWhenHorizontal();
55 private:
56     DMRect CalcCutoutBoundingRect(std::string svgPath);
57     void CheckBoundingRectsBoundary(DisplayId displayId, std::vector<DMRect>& boundingRects);
58     void CalcBuiltInDisplayWaterfallRects();
59     void CalcBuiltInDisplayWaterfallRectsByRotation(Rotation rotation, uint32_t displayHeight, uint32_t displayWidth);
60     void TransferBoundingRectsByRotation(DisplayId displayId, std::vector<DMRect>& boundingRects);
61     void CurrentRotation90(std::vector<DMRect> resultVec, std::vector<DMRect> displayBoundingRects,
62         uint32_t displayHeight);
63     void CurrentRotation180(std::vector<DMRect> resultVec, std::vector<DMRect> displayBoundingRects,
64         uint32_t displayHeight, uint32_t displayWidth);
65     DMRect CreateWaterfallRect(uint32_t left, uint32_t top, uint32_t width, uint32_t height);
66 
67     // Raw data
68     std::map<DisplayId, std::vector<std::string>> svgPaths_;
69     static bool isWaterfallDisplay_;
70     std::vector<int> curvedScreenBoundary_; // Order: left top right bottom
71 
72     // Calulated data
73     WaterfallDisplayAreaRects waterfallDisplayAreaRects_ = {};
74     std::map<DisplayId, std::vector<DMRect>> boundingRects_;
75 
76     // For waterfall display curved area compression.
77     static bool isWaterfallAreaCompressionEnableWhenHorizontal_;
78     static uint32_t waterfallAreaCompressionSizeWhenHorizontal_; // The unit is vp.
79 };
80 } // Rosen
81 } // OHOS
82 #endif // OHOS_ROSEN_DISPLAY_CUTOUT_CONTROLLER_H