blob: 3049ec16e2d43601c81066ea01794140bfe37e34 [file] [log] [blame]
Mathias Agopianc3c8d422018-01-30 18:07:27 -08001/*
2 * Copyright (C) 2018 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#include <android/surface_texture.h>
18#include <android/surface_texture_jni.h>
19
20#define LOG_TAG "ASurfaceTexture"
21
22#include <utils/Log.h>
23
Mathias Agopianc3c8d422018-01-30 18:07:27 -080024#include <gui/Surface.h>
25
Stan Ilievaaa9e832019-09-17 14:07:23 -040026#include <gui/surfacetexture/surface_texture_platform.h>
27
Mathias Agopianc3c8d422018-01-30 18:07:27 -080028#include <android_runtime/android_graphics_SurfaceTexture.h>
29
30using namespace android;
31
Mathias Agopianc3c8d422018-01-30 18:07:27 -080032ASurfaceTexture* ASurfaceTexture_fromSurfaceTexture(JNIEnv* env, jobject surfacetexture) {
33 if (!surfacetexture || !android_SurfaceTexture_isInstanceOf(env, surfacetexture)) {
34 return nullptr;
35 }
Stan Ilievaaa9e832019-09-17 14:07:23 -040036 auto consumer = SurfaceTexture_getSurfaceTexture(env, surfacetexture);
37 auto producer = SurfaceTexture_getProducer(env, surfacetexture);
38 return ASurfaceTexture_create(consumer, producer);
Mathias Agopianc3c8d422018-01-30 18:07:27 -080039}
40
41ANativeWindow* ASurfaceTexture_acquireANativeWindow(ASurfaceTexture* st) {
42 sp<Surface> surface = new Surface(st->producer);
43 ANativeWindow* win(surface.get());
44 ANativeWindow_acquire(win);
45 return win;
46}
47
48void ASurfaceTexture_release(ASurfaceTexture* st) {
49 delete st;
50}
51
52int ASurfaceTexture_attachToGLContext(ASurfaceTexture* st, uint32_t tex) {
53 return st->consumer->attachToContext(tex);
54}
55
56int ASurfaceTexture_detachFromGLContext(ASurfaceTexture* st) {
57 return st->consumer->detachFromContext();
58}
59
60int ASurfaceTexture_updateTexImage(ASurfaceTexture* st) {
61 return st->consumer->updateTexImage();
62}
63
64void ASurfaceTexture_getTransformMatrix(ASurfaceTexture* st, float mtx[16]) {
65 st->consumer->getTransformMatrix(mtx);
66}
67
68int64_t ASurfaceTexture_getTimestamp(ASurfaceTexture* st) {
69 return st->consumer->getTimestamp();
70}