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