• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 HDI_BACKEND_HDI_FRAMEBUFFER_SURFACE_H
17 #define HDI_BACKEND_HDI_FRAMEBUFFER_SURFACE_H
18 
19 #include <condition_variable>
20 #include <queue>
21 #include <refbase.h>
22 #include <surface.h>
23 #include <sync_fence.h>
24 #include "surface_buffer.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 struct FrameBufferEntry {
FrameBufferEntryFrameBufferEntry29     FrameBufferEntry(sptr<SurfaceBuffer> buf, sptr<SyncFence> fence, int64_t timeStamp, const Rect& damage)
30         : buffer(std::move(buf)), acquireFence(std::move(fence)), acquireTime(timeStamp), damageRect(damage)
31     {
32     }
33     ~FrameBufferEntry() noexcept = default;
34 
35     sptr<SurfaceBuffer> buffer;
36     sptr<SyncFence> acquireFence;
37     int64_t acquireTime = 0;
38     Rect damageRect = {0};
39 };
40 
41 class HdiFramebufferSurface : public IBufferConsumerListener {
42 public:
43     static sptr<HdiFramebufferSurface> CreateFramebufferSurface();
44     sptr<OHOS::Surface> GetSurface();
45     std::unique_ptr<FrameBufferEntry> GetFramebuffer();
46     int32_t ReleaseFramebuffer(
47         sptr<SurfaceBuffer> &buffer, const sptr<SyncFence> &releaseFence);
48 
49     void Dump(std::string &result);
50 
51 private:
52     mutable std::mutex mutex_;
53     std::condition_variable bufferCond_;
54     sptr<OHOS::Surface> consumerSurface_ = nullptr;
55     sptr<OHOS::Surface> producerSurface_ = nullptr;
56     std::queue<std::unique_ptr<FrameBufferEntry>> availableBuffers_;
57 
58     static constexpr uint32_t MAX_BUFFER_SIZE = 3;
59 
60     HdiFramebufferSurface();
61     virtual ~HdiFramebufferSurface() noexcept;
62 
63     void OnBufferAvailable() override;
64     OHOS::SurfaceError SetBufferQueueSize(uint32_t bufferSize);
65     OHOS::SurfaceError CreateSurface(sptr<HdiFramebufferSurface> &fbSurface);
66 };
67 } // namespace Rosen
68 } // namespace OHOS
69 
70 #endif // HDI_BACKEND_HDI_FRAMEBUFFER_SURFACE_H
71