blob: ced2792775d4ed4b222a38e4d6b4d30a28e79981 [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
26#include <android_runtime/android_graphics_SurfaceTexture.h>
27
Stan Iliev564ca3e2018-09-04 22:00:00 +000028#include "surfacetexture/SurfaceTexture.h"
29
Mathias Agopianc3c8d422018-01-30 18:07:27 -080030using namespace android;
31
32struct ASurfaceTexture {
Stan Iliev564ca3e2018-09-04 22:00:00 +000033 sp<SurfaceTexture> consumer;
Mathias Agopianc3c8d422018-01-30 18:07:27 -080034 sp<IGraphicBufferProducer> producer;
35};
36
37ASurfaceTexture* 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
47ANativeWindow* 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
54void ASurfaceTexture_release(ASurfaceTexture* st) {
55 delete st;
56}
57
58int ASurfaceTexture_attachToGLContext(ASurfaceTexture* st, uint32_t tex) {
59 return st->consumer->attachToContext(tex);
60}
61
62int ASurfaceTexture_detachFromGLContext(ASurfaceTexture* st) {
63 return st->consumer->detachFromContext();
64}
65
66int ASurfaceTexture_updateTexImage(ASurfaceTexture* st) {
67 return st->consumer->updateTexImage();
68}
69
70void ASurfaceTexture_getTransformMatrix(ASurfaceTexture* st, float mtx[16]) {
71 st->consumer->getTransformMatrix(mtx);
72}
73
74int64_t ASurfaceTexture_getTimestamp(ASurfaceTexture* st) {
75 return st->consumer->getTimestamp();
76}