• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #ifndef RS_ANCO_MANAGER_H
16 #define RS_ANCO_MANAGER_H
17 
18 #include "common/rs_common_def.h"
19 #include "pipeline/rs_surface_handler.h"
20 #include "pipeline/rs_surface_render_node.h"
21 #include "screen_manager/screen_types.h"
22 
23 namespace OHOS::Rosen {
24 struct AncoBufferInfo {
25     int32_t width_ = 0;
26     int32_t height_ = 0;
27     int32_t format_ = GRAPHIC_PIXEL_FMT_BUTT;
28 };
29 
30 class RSAncoManager {
31 public:
32     static RSAncoManager* Instance();
33     AncoHebcStatus GetAncoHebcStatus() const;
34     void SetAncoHebcStatus(AncoHebcStatus hebcStatus);
35     bool AncoOptimizeScreenNode(std::shared_ptr<RSSurfaceHandler>& surfaceHandler,
36         std::vector<std::shared_ptr<RSSurfaceRenderNode>>& hardwareEnabledNodes,
37         ScreenRotation rotation, uint32_t width, uint32_t height);
38     virtual bool IsAncoOptimize(ScreenRotation rotation);
39     // When the anco node is rendered in a unified way, ancoSrcCrop is effective
40     static void UpdateCropRectForAnco(const uint32_t ancoFlags, const Rect& cropRect,
41         const AncoBufferInfo& ancoInfo, Drawing::Rect& outSrcRect);
42     // When the anco layer is redrawed in dss, ancoSrcCrop is effective
43     static void UpdateCropRectForAnco(const uint32_t ancoFlags, const GraphicIRect& cropRect,
44         const AncoBufferInfo& ancoInfo, Drawing::Rect& outSrcRect);
45     // When the anco node generates a layer, ancoSrcCrop takes effect
46     static void UpdateLayerSrcRectForAnco(const uint32_t ancoFlags, const GraphicIRect& cropRect,
47         GraphicIRect& outSrcRect);
48     static bool IsAncoSfv(const uint32_t ancoFlags);
49     // Check whether CropRect is valid.
50     static bool ValidCropRect(const GraphicIRect& cropRect);
51     static void IntersectCrop(const GraphicIRect& cropRect, GraphicIRect& outSrcRect);
52     // If the cropRect is smaller than the buffer size, it needs to shrink inwards by a few pixels.
53     static float CalculateShrinkAmount(const int32_t format);
54     static void ShrinkAmountIfNeed(const AncoBufferInfo& ancoInfo, Drawing::Rect& outSrcRect);
55 
56 private:
57     bool AncoOptimizeCheck(bool isHebc, int nodesCnt, int sfvNodesCnt);
58     // anco screenNode use hebc
59     std::atomic<int32_t> ancoHebcStatus_ = static_cast<int32_t>(AncoHebcStatus::INITIAL);
60 protected:
61     RSAncoManager() = default;
62     virtual ~RSAncoManager() = default;
63 };
64 } // namespace OHOS::Rosen
65 #endif // RS_ANCO_MANAGER_H
66