blob: ae208a6e75b934a2ccc40e8621d452d14ad2d39e [file] [log] [blame]
Craig Donnerc7e8dae2017-01-03 10:24:58 -08001/*
2 * Copyright (C) 2017 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/**
Krzysztof Kosiński22fb2ff2019-05-14 19:22:59 -070018 * @addtogroup AHardwareBuffer
19 * @{
20 */
21
22/**
Craig Donnerc7e8dae2017-01-03 10:24:58 -080023 * @file hardware_buffer_jni.h
Krzysztof Kosiński22fb2ff2019-05-14 19:22:59 -070024 * @brief JNI glue for native hardware buffers.
Craig Donnerc7e8dae2017-01-03 10:24:58 -080025 */
26
27#ifndef ANDROID_HARDWARE_BUFFER_JNI_H
28#define ANDROID_HARDWARE_BUFFER_JNI_H
29
30#include <sys/cdefs.h>
31
32#include <android/hardware_buffer.h>
33
34#include <jni.h>
35
36__BEGIN_DECLS
37
38/**
Krzysztof Kosiński22fb2ff2019-05-14 19:22:59 -070039 * Return the AHardwareBuffer wrapped by a Java HardwareBuffer object.
40 *
41 * This method does not acquire any additional reference to the AHardwareBuffer
Nick Cook8fc3b0a2020-07-09 19:29:25 +000042 * that is returned. To keep the AHardwareBuffer alive after the Java
43 * HardwareBuffer object is closed, explicitly or by the garbage collector, be
44 * sure to use AHardwareBuffer_acquire() to acquire an additional reference.
Elliott Hughes3d70e532019-10-29 08:59:39 -070045 *
46 * Available since API level 26.
Craig Donnerc7e8dae2017-01-03 10:24:58 -080047 */
48AHardwareBuffer* AHardwareBuffer_fromHardwareBuffer(JNIEnv* env,
Krzysztof Kosiński22fb2ff2019-05-14 19:22:59 -070049 jobject hardwareBufferObj) __INTRODUCED_IN(26);
Craig Donnerc7e8dae2017-01-03 10:24:58 -080050
51/**
52 * Return a new Java HardwareBuffer object that wraps the passed native
Nick Cook8fc3b0a2020-07-09 19:29:25 +000053 * AHardwareBuffer object. The Java HardwareBuffer will acquire a reference to
54 * the internal buffer and manage its lifetime. For example:
55 *
56 * <pre><code>
57 * AHardwareBuffer* buffer;
58 * AHardwareBuffer_allocate(..., &buffer); // `buffer` has reference count 1
59 * jobject java_result = AHardwareBuffer_toHardwareBuffer(buffer); // `buffer` has reference count 2.
60 * AHardwareBuffer_release(buffer); // `buffer` has reference count 1
61 * return result; // The underlying buffer is kept alive by `java_result` and
62 * // will be set to 0 when it is closed on the Java side with
63 * // HardwareBuffer::close().
64 * </code></pre>
Elliott Hughes3d70e532019-10-29 08:59:39 -070065 *
66 * Available since API level 26.
Craig Donnerc7e8dae2017-01-03 10:24:58 -080067 */
68jobject AHardwareBuffer_toHardwareBuffer(JNIEnv* env,
Krzysztof Kosiński22fb2ff2019-05-14 19:22:59 -070069 AHardwareBuffer* hardwareBuffer) __INTRODUCED_IN(26);
Craig Donnerc7e8dae2017-01-03 10:24:58 -080070
71__END_DECLS
72
73#endif // ANDROID_HARDWARE_BUFFER_JNI_H
Krzysztof Kosiński22fb2ff2019-05-14 19:22:59 -070074
75/** @} */