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