1 /*
2  * Copyright (c) 2021 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 LAYER_CONTEXT_H
17 #define LAYER_CONTEXT_H
18 
19 #include <surface.h>
20 #include "hdi_layer_info.h"
21 #include "sync_fence.h"
22 
23 namespace OHOS {
24 namespace Rosen {
25 enum LayerType : uint32_t {
26     LAYER_STATUS,
27     LAYER_LAUNCHER,
28     LAYER_NAVIGATION,
29     LAYER_EXTRA
30 };
31 
32 using YUVPixel = struct {
33     uint8_t y;
34     uint8_t u;
35     uint8_t v;
36 };
37 
38 class LayerContext : public IBufferConsumerListenerClazz {
39 public:
40     LayerContext(GraphicIRect dst, GraphicIRect src, uint32_t zorder, LayerType layerType);
41     virtual ~LayerContext();
42     static constexpr uint32_t PIXEL_LINE_ALIGNMENT = 32;
43     static constexpr uint32_t RBGA_R_MOVEBITS = 24;
44     static constexpr uint32_t RBGA_B_MOVEBITS = 16;
45     static constexpr uint32_t RBGA_G_MOVEBITS = 8;
46     static constexpr uint32_t PIXEL_YCBCR420_UV_NUM = 2;
47     static constexpr float PIXEL_YCBCR420_BYTE = 1.5;
48 
49     void OnBufferAvailable() override;
50     SurfaceError DrawBufferColor();
51     void FillHDILayer();
52     SurfaceError FillHDIBuffer();
53     const std::shared_ptr<HdiLayerInfo> GetHdiLayer();
54     void SetTestClientStatus(bool status);
55     void SetTestRotateStatus(bool status);
56     void SetTestYUVStatus(bool status);
57     void SetTestLayerColor(bool status);
58     LayerType GetLayerType() const;
GetPreBuffer()59     sptr<SurfaceBuffer> GetPreBuffer() const
60     {
61         return prevBuffer_;
62     }
GetPreFence()63     sptr<SyncFence> GetPreFence() const
64     {
65         return prevFence_;
66     }
67 
68 private:
69     const std::vector<uint32_t> colors_ = {0xff0000ff, 0xffff00ff, 0xaa00ff00, 0xff00ffaa, 0xff0f0f00};
70     GraphicIRect dst_;
71     GraphicIRect src_;
72     uint32_t colorIndex_ = 0;
73     uint32_t frameCounter_ = 0;
74     uint32_t color_ = 0xffff1111;
75     uint32_t zorder_ = 0;
76     sptr<SyncFence> prevFence_;
77     OHOS::sptr<Surface> pSurface_;
78     OHOS::sptr<IConsumerSurface> cSurface_;
79     OHOS::sptr<SurfaceBuffer> prevBuffer_;
80     std::shared_ptr<HdiLayerInfo> hdiLayer_;
81     LayerType layerType_ = LayerType::LAYER_EXTRA;
82     bool testClient_ = false;
83     bool testRotate_ = false;
84     bool testYUV_ = false;
85     bool testLayerColor_ = false;
86 
87     void DrawColor(void *image, int width, int height);
88     void DrawExtraColor(void *image, uint32_t width, uint32_t height);
89     void DrawBaseColor(void *image, uint32_t width, uint32_t height);
90     void DrawYUVColor(void *image, uint32_t width, uint32_t height, YUVPixel pixelValueYUV);
91     void ConvertRBGA2YUV(uint32_t pixelValueRBGA, YUVPixel *pixelValueYUV);
92     void SetLayerTransformType();
93     void SetLayerCompositionType();
94 };
95 } // namespace Rosen
96 } // namespace OHOS
97 
98 #endif // LAYER_CONTEXT_H