1 /*
2  * Copyright 2016, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_HARDWARE_GRAPHICS_BUFFERQUEUE_V1_0_H2BGRAPHICBUFFERPRODUCER_H
18 #define ANDROID_HARDWARE_GRAPHICS_BUFFERQUEUE_V1_0_H2BGRAPHICBUFFERPRODUCER_H
19 
20 #include <hidl/MQDescriptor.h>
21 #include <hidl/Status.h>
22 
23 #include <binder/Binder.h>
24 #include <gui/IGraphicBufferProducer.h>
25 #include <gui/IProducerListener.h>
26 
27 #include <hidl/HybridInterface.h>
28 #include <android/hardware/graphics/bufferqueue/1.0/IGraphicBufferProducer.h>
29 
30 namespace android {
31 namespace hardware {
32 namespace graphics {
33 namespace bufferqueue {
34 namespace V1_0 {
35 namespace utils {
36 
37 using ::android::hidl::base::V1_0::IBase;
38 using ::android::hardware::hidl_array;
39 using ::android::hardware::hidl_memory;
40 using ::android::hardware::hidl_string;
41 using ::android::hardware::hidl_vec;
42 using ::android::hardware::Return;
43 using ::android::hardware::Void;
44 using ::android::sp;
45 
46 using ::android::hardware::graphics::common::V1_0::PixelFormat;
47 using ::android::hardware::media::V1_0::AnwBuffer;
48 
49 typedef ::android::hardware::graphics::bufferqueue::V1_0::IGraphicBufferProducer
50         HGraphicBufferProducer;
51 typedef ::android::hardware::graphics::bufferqueue::V1_0::IProducerListener
52         HProducerListener;
53 
54 typedef ::android::IGraphicBufferProducer BGraphicBufferProducer;
55 using ::android::BnGraphicBufferProducer;
56 using ::android::IProducerListener;
57 
58 struct H2BGraphicBufferProducer : public ::android::H2BConverter<
59         HGraphicBufferProducer,
60         BnGraphicBufferProducer> {
H2BGraphicBufferProducerH2BGraphicBufferProducer61     explicit H2BGraphicBufferProducer(sp<HGraphicBufferProducer> const& base) : CBase(base) {}
62 
63     status_t requestBuffer(int slot, sp<GraphicBuffer>* buf) override;
64     status_t setMaxDequeuedBufferCount(int maxDequeuedBuffers) override;
65     status_t setAsyncMode(bool async) override;
66     status_t dequeueBuffer(int* slot, sp<Fence>* fence, uint32_t w, uint32_t h,
67                            ::android::PixelFormat format, uint64_t usage, uint64_t* outBufferAge,
68                            FrameEventHistoryDelta* outTimestamps) override;
69     status_t detachBuffer(int slot) override;
70     status_t detachNextBuffer(sp<GraphicBuffer>* outBuffer, sp<Fence>* outFence)
71             override;
72     status_t attachBuffer(int* outSlot, const sp<GraphicBuffer>& buffer)
73             override;
74     status_t queueBuffer(int slot,
75             const QueueBufferInput& input,
76             QueueBufferOutput* output) override;
77     status_t cancelBuffer(int slot, const sp<Fence>& fence) override;
78     int query(int what, int* value) override;
79     status_t connect(const sp<IProducerListener>& listener, int api,
80             bool producerControlledByApp, QueueBufferOutput* output) override;
81     status_t disconnect(int api, DisconnectMode mode = DisconnectMode::Api)
82             override;
83     status_t setSidebandStream(const sp<NativeHandle>& stream) override;
84     void allocateBuffers(uint32_t width, uint32_t height,
85             ::android::PixelFormat format, uint64_t usage) override;
86     status_t allowAllocation(bool allow) override;
87     status_t setGenerationNumber(uint32_t generationNumber) override;
88     String8 getConsumerName() const override;
89     status_t setSharedBufferMode(bool sharedBufferMode) override;
90     status_t setAutoRefresh(bool autoRefresh) override;
91     status_t setDequeueTimeout(nsecs_t timeout) override;
92     status_t getLastQueuedBuffer(sp<GraphicBuffer>* outBuffer,
93           sp<Fence>* outFence, float outTransformMatrix[16]) override;
94     void getFrameTimestamps(FrameEventHistoryDelta* outDelta) override;
95     status_t getUniqueId(uint64_t* outId) const override;
96     status_t getConsumerUsage(uint64_t* outUsage) const override;
97 };
98 
99 }  // namespace utils
100 }  // namespace V1_0
101 }  // namespace bufferqueue
102 }  // namespace graphics
103 }  // namespace hardware
104 }  // namespace android
105 
106 #endif  // ANDROID_HARDWARE_GRAPHICS_BUFFERQUEUE_V1_0_H2BGRAPHICBUFFERPRODUCER_H
107