1e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian/* 2e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian * Copyright (C) 2017 The Android Open Source Project 3e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian * 4e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 5e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian * you may not use this file except in compliance with the License. 6e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian * You may obtain a copy of the License at 7e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian * 8e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 9e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian * 10e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian * Unless required by applicable law or agreed to in writing, software 11e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 12e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian * See the License for the specific language governing permissions and 14e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian * limitations under the License. 15e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian */ 16e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian 17e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian#define LOG_TAG "Surface" 18e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian 19e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian#include <android/native_window_jni.h> 20e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian#include <android/native_window.h> 21e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian#include <system/window.h> 22e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian 23d28e8283d39e7eb6c714511a0430d4cc836298cbJiwen 'Steve' Cai#include <gui/Surface.h> 24e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian#include <utils/StrongPointer.h> 25e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian 26e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian#include <android_runtime/android_view_Surface.h> 27e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian 28e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopianusing namespace android; 29e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian 30e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias AgopianANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface) { 31e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian sp<ANativeWindow> win = android_view_Surface_getNativeWindow(env, surface); 32e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian if (win != NULL) { 33e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian win->incStrong((void*)ANativeWindow_fromSurface); 34e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian } 35e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian return win.get(); 36e68b4f73a92b4683a668608e1a64548eb7dbd27aMathias Agopian} 37d28e8283d39e7eb6c714511a0430d4cc836298cbJiwen 'Steve' Cai 38d28e8283d39e7eb6c714511a0430d4cc836298cbJiwen 'Steve' Caijobject ANativeWindow_toSurface(JNIEnv* env, ANativeWindow* window) { 39d28e8283d39e7eb6c714511a0430d4cc836298cbJiwen 'Steve' Cai if (window == NULL) { 40d28e8283d39e7eb6c714511a0430d4cc836298cbJiwen 'Steve' Cai return NULL; 41d28e8283d39e7eb6c714511a0430d4cc836298cbJiwen 'Steve' Cai } 42d28e8283d39e7eb6c714511a0430d4cc836298cbJiwen 'Steve' Cai sp<Surface> surface = static_cast<Surface*>(window); 43d28e8283d39e7eb6c714511a0430d4cc836298cbJiwen 'Steve' Cai return android_view_Surface_createFromSurface(env, surface); 44d28e8283d39e7eb6c714511a0430d4cc836298cbJiwen 'Steve' Cai} 45