• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef DISPLAY_MOCK_SURFACE
16 #define DISPLAY_MOCK_SURFACE
17 #include <queue>
18 #include <unordered_map>
19 #include "hardware_buffer.h"
20 #include "surface.h"
21 #include "hdi_layer.h"
22 #include "display_gralloc.h"
23 
24 namespace OHOS {
25 class DisplayMockSurface : public Surface {
26 public:
27     bool Init(uint32_t width, uint32_t height);
28     bool AllocBuffer(AllocInfo &info);
29 
30     ~DisplayMockSurface() = default;
31 
32     bool IsConsumer() const;
33     sptr<IBufferProducer> GetProducer() const;
34 
35     GSError RequestBuffer(sptr<SurfaceBuffer> &buffer, int32_t &fence, BufferRequestConfig &config);
36 
37     GSError CancelBuffer(sptr<SurfaceBuffer> &buffer);
38 
39     GSError FlushBuffer(sptr<SurfaceBuffer> &buffer, int32_t fence, BufferFlushConfig &config);
40 
41     GSError AcquireBuffer(sptr<SurfaceBuffer> &buffer, int32_t &fence, int64_t &timestamp, Rect &damage);
42     GSError ReleaseBuffer(sptr<SurfaceBuffer> &buffer, int32_t fence);
43 
44     GSError AttachBuffer(sptr<SurfaceBuffer> &buffer);
45 
46     GSError DetachBuffer(sptr<SurfaceBuffer> &buffer);
47 
48     uint32_t GetQueueSize();
49     GSError SetQueueSize(uint32_t queueSize);
50 
51     GSError SetDefaultWidthAndHeight(int32_t width, int32_t height);
52     int32_t GetDefaultWidth();
53     int32_t GetDefaultHeight();
54 
55     GSError SetDefaultUsage(uint32_t usage);
56     uint32_t GetDefaultUsage();
57 
58     GSError SetUserData(const std::string &key, const std::string &val);
59     std::string GetUserData(const std::string &key);
60 
61     GSError GetName(std::string &name);
62 
63     GSError RegisterConsumerListener(sptr<IBufferConsumerListener> &listener);
64     GSError RegisterConsumerListener(IBufferConsumerListenerClazz *listener);
65     GSError RegisterReleaseListener(OnReleaseFunc func);
66     GSError UnregisterConsumerListener();
67 
68     uint64_t GetUniqueId() const;
69 
70     void Dump(std::string &result) const;
71 
72     GSError CleanCache();
73     void AcquireBufferHandle(HDI::DISPLAY::HdiLayer &layer);
74     void SetReleaseFence(int32_t fence);
75 
76 private:
77     static constexpr const uint32_t BUFFER_NUM = 3;
78     std::queue<OHOS::sptr<OHOS::SurfaceBuffer>> hardwareBufferQueue_;
79     sptr<OHOS::SurfaceBuffer> curentPresentBuffer_ = nullptr;
80     GrallocFuncs *grallocFuncs_ = nullptr;
81     uint32_t width_ = 0;
82     uint32_t height_ = 0;
83 };
84 } // OHOS
85 
86 #endif // DISPLAY_MOCK_SURFACE