native_window.cpp revision 809820e28bdeb13a7625e0ce80e0dc2e2d76929f
1/* 2 * Copyright (C) 2010 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#define LOG_TAG "Surface" 18#include <utils/Log.h> 19 20#include <android/native_window_jni.h> 21#include <surfaceflinger/Surface.h> 22#include <android_runtime/android_view_Surface.h> 23#include <android_runtime/android_graphics_SurfaceTexture.h> 24 25using namespace android; 26 27ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface) { 28 sp<ANativeWindow> win = android_Surface_getNativeWindow(env, surface); 29 if (win != NULL) { 30 win->incStrong((void*)ANativeWindow_acquire); 31 } 32 return win.get(); 33} 34 35void ANativeWindow_acquire(ANativeWindow* window) { 36 window->incStrong((void*)ANativeWindow_acquire); 37} 38 39void ANativeWindow_release(ANativeWindow* window) { 40 window->decStrong((void*)ANativeWindow_acquire); 41} 42 43static int32_t getWindowProp(ANativeWindow* window, int what) { 44 int value; 45 int res = window->query(window, what, &value); 46 return res < 0 ? res : value; 47} 48 49int32_t ANativeWindow_getWidth(ANativeWindow* window) { 50 return getWindowProp(window, NATIVE_WINDOW_WIDTH); 51} 52 53int32_t ANativeWindow_getHeight(ANativeWindow* window) { 54 return getWindowProp(window, NATIVE_WINDOW_HEIGHT); 55} 56 57int32_t ANativeWindow_getFormat(ANativeWindow* window) { 58 return getWindowProp(window, NATIVE_WINDOW_FORMAT); 59} 60 61int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window, int32_t width, 62 int32_t height, int32_t format) { 63 int32_t err = native_window_set_buffers_geometry(window, width, height, format); 64 if (!err) { 65 int mode = NATIVE_WINDOW_SCALING_MODE_FREEZE; 66 if (width && height) { 67 mode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW; 68 } 69 err = native_window_set_scaling_mode(window, mode); 70 } 71 return err; 72} 73 74int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer, 75 ARect* inOutDirtyBounds) { 76 return window->perform(window, NATIVE_WINDOW_LOCK, outBuffer, inOutDirtyBounds); 77} 78 79int32_t ANativeWindow_unlockAndPost(ANativeWindow* window) { 80 return window->perform(window, NATIVE_WINDOW_UNLOCK_AND_POST); 81} 82