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 LAYER_CONTEXT_H
17 #define LAYER_CONTEXT_H
18 
19 #include <surface.h>
20 
21 #include "hdi_layer_info.h"
22 #include "sync_fence.h"
23 
24 #include "draw/canvas.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 namespace Drawing {
29 enum LayerType : uint32_t { LAYER_STATUS, LAYER_LAUNCHER, LAYER_NAVIGATION };
30 
31 class LayerContext : public IBufferConsumerListenerClazz {
32 public:
33     using TestFunc = std::function<void(Canvas&, uint32_t, uint32_t)>;
34     LayerContext(GraphicIRect dst, GraphicIRect src, uint32_t zorder, LayerType layerType);
35     virtual ~LayerContext();
36 
37     virtual void OnBufferAvailable() override;
38     SurfaceError DrawBuffer(TestFunc testFunc);
39     SurfaceError FillHDILayer();
40     const std::shared_ptr<HdiLayerInfo> GetHdiLayer();
GetPreBuffer()41     sptr<SurfaceBuffer> GetPreBuffer() const
42     {
43         return prevBuffer_;
44     }
GetPreFence()45     sptr<SyncFence> GetPreFence() const
46     {
47         return prevFence_;
48     }
49 
50 private:
51     GraphicIRect dst_;
52     GraphicIRect src_;
53     uint32_t zorder_ = 0;
54     sptr<SyncFence> prevFence_;
55     OHOS::sptr<Surface> pSurface_;
56     OHOS::sptr<IConsumerSurface> cSurface_;
57     OHOS::sptr<SurfaceBuffer> prevBuffer_;
58     std::shared_ptr<HdiLayerInfo> hdiLayer_;
59     LayerType layerType_ = LayerType::LAYER_STATUS;
60 
61     void DrawBaseLayer(void* image, int width, int height, TestFunc testFuc);
62 };
63 } // namespace Drawing
64 } // namespace Rosen
65 } // namespace OHOS
66 #endif // LAYER_CONTEXT_H