• 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 FRAMEWORKS_SURFACE_INCLUDE_CONSUMER_SURFACE_H
17 #define FRAMEWORKS_SURFACE_INCLUDE_CONSUMER_SURFACE_H
18 
19 #include <map>
20 #include <string>
21 
22 #include <surface.h>
23 
24 #include "buffer_queue.h"
25 #include "buffer_queue_producer.h"
26 #include "buffer_queue_consumer.h"
27 
28 namespace OHOS {
29 class ConsumerSurface : public Surface {
30 public:
31     ConsumerSurface(const std::string &name, bool isShared = false);
32     virtual ~ConsumerSurface();
33     GSError Init();
34 
35     bool IsConsumer() const override;
36     sptr<IBufferProducer> GetProducer() const override;
37     GSError RequestBuffer(sptr<SurfaceBuffer>& buffer,
38         int32_t &fence, BufferRequestConfig &config) override;
39 
40     GSError CancelBuffer(sptr<SurfaceBuffer>& buffer) override;
41 
42     GSError FlushBuffer(sptr<SurfaceBuffer>& buffer,
43         int32_t fence, BufferFlushConfig &config) override;
44 
45     GSError AcquireBuffer(sptr<SurfaceBuffer>& buffer, int32_t &fence,
46         int64_t &timestamp, Rect &damage) override;
47     GSError ReleaseBuffer(sptr<SurfaceBuffer>& buffer, int32_t fence) override;
48 
49     GSError AttachBuffer(sptr<SurfaceBuffer>& buffer) override;
50     GSError DetachBuffer(sptr<SurfaceBuffer>& buffer) override;
51 
52     uint32_t GetQueueSize() override;
53     GSError SetQueueSize(uint32_t queueSize) override;
54 
55     GSError GetName(std::string &name) override;
56 
57     GSError SetDefaultWidthAndHeight(int32_t width, int32_t height) override;
58     int32_t GetDefaultWidth() override;
59     int32_t GetDefaultHeight() override;
60     GSError SetDefaultUsage(uint32_t usage) override;
61     uint32_t GetDefaultUsage() override;
62 
63     GSError SetUserData(const std::string &key, const std::string &val) override;
64     std::string GetUserData(const std::string &key) override;
65 
66     GSError RegisterConsumerListener(sptr<IBufferConsumerListener>& listener) override;
67     GSError RegisterConsumerListener(IBufferConsumerListenerClazz *listener) override;
68     GSError RegisterReleaseListener(OnReleaseFunc func) override;
69     GSError UnregisterConsumerListener() override;
70 
71     uint64_t GetUniqueId() const override;
72 
73     void Dump(std::string &result) const override;
74 
75     GSError CleanCache() override;
76 
77 private:
78     std::map<std::string, std::string> userData_;
79     sptr<BufferQueueProducer> producer_ = nullptr;
80     sptr<BufferQueueConsumer> consumer_ = nullptr;
81     std::string name_ = "not init";
82     bool isShared_ = false;
83 };
84 } // namespace OHOS
85 
86 #endif // FRAMEWORKS_SURFACE_INCLUDE_CONSUMER_SURFACE_H
87