1 /*
2  * Copyright 2020 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_BUFFER_QUEUE_CONVERTER_H
18 #define ANDROID_BUFFER_QUEUE_CONVERTER_H
19 
20 #include <gui/IGraphicBufferProducer.h>
21 #include <android/native_window.h>
22 
23 using ::android::sp;
24 using HGraphicBufferProducer =
25       ::android::hardware::graphics::bufferqueue::V2_0::IGraphicBufferProducer;
26 
27 namespace android {
28     /**
29      * Opaque handle for a data structure holding Surface.
30      */
31     typedef struct SurfaceHolder SurfaceHolder;
32 
33     /**
34      * SurfaceHolder unique pointer type
35      */
36     using SurfaceHolderUniquePtr = std::unique_ptr<SurfaceHolder, void(*)(SurfaceHolder*)>;
37 
38     /**
39      * Returns a SurfaceHolder that wraps a Surface generated from a given HGBP.
40      *
41      * @param  token         Hardware IGraphicBufferProducer to create a
42      *                       Surface.
43      * @return SurfaceHolder Unique pointer to created SurfaceHolder object.
44      */
45     SurfaceHolderUniquePtr getSurfaceFromHGBP(const sp<HGraphicBufferProducer>& token);
46 
47     /**
48      * Returns ANativeWindow pointer from a given SurfaceHolder.  Returned
49      * pointer is valid only while the containing SurfaceHolder is alive.
50      *
51      * @param  surfaceHolder  SurfaceHolder to generate a native window.
52      * @return ANativeWindow* a pointer to a generated native window.
53      */
54     ANativeWindow* getNativeWindow(SurfaceHolder* surfaceHolder);
55 
56 } // namespace android
57 
58 #endif // ANDROID_BUFFER_QUEUE_CONVERTER_H
59