1 /*
2  * Copyright (C) 2024 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 IMAGE_EFFECT_SURFACE_ADAPTER_H
17 #define IMAGE_EFFECT_SURFACE_ADAPTER_H
18 
19 #include <cstdint>
20 #include <functional>
21 #include <iconsumer_surface.h>
22 #include <refbase.h>
23 
24 #include "error_code.h"
25 
26 namespace OHOS {
27 namespace Media {
28 namespace Effect {
29 using ConsumerBufferAvailable = std::function<bool(sptr<SurfaceBuffer> &inBuffer, sptr<SurfaceBuffer> &outBuffer,
30     const OHOS::Rect &damages, int64_t timeStamp)>;
31 
32 class EffectSurfaceAdapter : public IBufferConsumerListenerClazz {
33 public:
34     EffectSurfaceAdapter();
35     ~EffectSurfaceAdapter();
36 
37     sptr<Surface> GetProducerSurface();
38     ErrorCode SetConsumerListener(ConsumerBufferAvailable &&consumerBufferAvailable);
39     GraphicTransformType GetTransform() const;
40     void SetOutputSurfaceDefaultUsage(uint64_t usage);
41 
42     void ConsumerRequestCpuAccess(bool isCpuAccess);
43 
44     // IBufferConsumerListener 接口的实现 begin
45     void OnBufferAvailable() override;
46     void OnTunnelHandleChange() override;
47     void OnGoBackground() override;
48     void OnCleanCache() override;
49     // IBufferConsumerListener 接口的实现 end
50 
51 private:
52     ErrorCode Initialize();
53 
54     OHOS::sptr<IConsumerSurface> receiverConsumerSurface_ = nullptr;
55     OHOS::sptr<Surface> fromProducerSurface_ = nullptr;
56     ConsumerBufferAvailable consumerBufferAvailable_;
57     uint64_t outputSurfaceDefaultUsage_ = 0;
58     volatile int32_t effectSurfaceFlag_ = 0;
59 };
60 }
61 }
62 }
63 
64 #endif // IMAGE_EFFECT_SURFACE_ADAPTER_H