1 /*
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
24 #include <gui/Surface.h>
25
26 #include <android_runtime/android_graphics_SurfaceTexture.h>
27
28 #include "surfacetexture/SurfaceTexture.h"
29
30 using namespace android;
31
32 struct ASurfaceTexture {
33 sp<SurfaceTexture> consumer;
34 sp<IGraphicBufferProducer> producer;
35 };
36
ASurfaceTexture_fromSurfaceTexture(JNIEnv * env,jobject surfacetexture)37 ASurfaceTexture* ASurfaceTexture_fromSurfaceTexture(JNIEnv* env, jobject surfacetexture) {
38 if (!surfacetexture || !android_SurfaceTexture_isInstanceOf(env, surfacetexture)) {
39 return nullptr;
40 }
41 ASurfaceTexture* ast = new ASurfaceTexture;
42 ast->consumer = SurfaceTexture_getSurfaceTexture(env, surfacetexture);
43 ast->producer = SurfaceTexture_getProducer(env, surfacetexture);
44 return ast;
45 }
46
ASurfaceTexture_acquireANativeWindow(ASurfaceTexture * st)47 ANativeWindow* ASurfaceTexture_acquireANativeWindow(ASurfaceTexture* st) {
48 sp<Surface> surface = new Surface(st->producer);
49 ANativeWindow* win(surface.get());
50 ANativeWindow_acquire(win);
51 return win;
52 }
53
ASurfaceTexture_release(ASurfaceTexture * st)54 void ASurfaceTexture_release(ASurfaceTexture* st) {
55 delete st;
56 }
57
ASurfaceTexture_attachToGLContext(ASurfaceTexture * st,uint32_t tex)58 int ASurfaceTexture_attachToGLContext(ASurfaceTexture* st, uint32_t tex) {
59 return st->consumer->attachToContext(tex);
60 }
61
ASurfaceTexture_detachFromGLContext(ASurfaceTexture * st)62 int ASurfaceTexture_detachFromGLContext(ASurfaceTexture* st) {
63 return st->consumer->detachFromContext();
64 }
65
ASurfaceTexture_updateTexImage(ASurfaceTexture * st)66 int ASurfaceTexture_updateTexImage(ASurfaceTexture* st) {
67 return st->consumer->updateTexImage();
68 }
69
ASurfaceTexture_getTransformMatrix(ASurfaceTexture * st,float mtx[16])70 void ASurfaceTexture_getTransformMatrix(ASurfaceTexture* st, float mtx[16]) {
71 st->consumer->getTransformMatrix(mtx);
72 }
73
ASurfaceTexture_getTimestamp(ASurfaceTexture * st)74 int64_t ASurfaceTexture_getTimestamp(ASurfaceTexture* st) {
75 return st->consumer->getTimestamp();
76 }
77