2010-06-30 18:35:14 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG_TAG "Surface"
|
|
|
|
#include <utils/Log.h>
|
|
|
|
|
2010-07-09 11:44:11 -07:00
|
|
|
#include <android/native_window_jni.h>
|
2012-02-25 18:48:35 -08:00
|
|
|
#include <gui/Surface.h>
|
2010-07-09 11:44:11 -07:00
|
|
|
#include <android_runtime/android_view_Surface.h>
|
2011-03-04 11:44:32 -08:00
|
|
|
#include <android_runtime/android_graphics_SurfaceTexture.h>
|
2010-06-30 18:35:14 -07:00
|
|
|
|
2010-07-09 11:44:11 -07:00
|
|
|
using namespace android;
|
|
|
|
|
|
|
|
ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface) {
|
2012-08-26 02:47:39 -07:00
|
|
|
sp<ANativeWindow> win = android_view_Surface_getNativeWindow(env, surface);
|
2010-07-09 11:44:11 -07:00
|
|
|
if (win != NULL) {
|
|
|
|
win->incStrong((void*)ANativeWindow_acquire);
|
|
|
|
}
|
|
|
|
return win.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ANativeWindow_acquire(ANativeWindow* window) {
|
|
|
|
window->incStrong((void*)ANativeWindow_acquire);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ANativeWindow_release(ANativeWindow* window) {
|
|
|
|
window->decStrong((void*)ANativeWindow_acquire);
|
|
|
|
}
|
2010-06-30 18:35:14 -07:00
|
|
|
|
|
|
|
static int32_t getWindowProp(ANativeWindow* window, int what) {
|
|
|
|
int value;
|
|
|
|
int res = window->query(window, what, &value);
|
|
|
|
return res < 0 ? res : value;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t ANativeWindow_getWidth(ANativeWindow* window) {
|
|
|
|
return getWindowProp(window, NATIVE_WINDOW_WIDTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t ANativeWindow_getHeight(ANativeWindow* window) {
|
|
|
|
return getWindowProp(window, NATIVE_WINDOW_HEIGHT);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t ANativeWindow_getFormat(ANativeWindow* window) {
|
|
|
|
return getWindowProp(window, NATIVE_WINDOW_FORMAT);
|
|
|
|
}
|
2010-07-01 18:44:46 -07:00
|
|
|
|
|
|
|
int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window, int32_t width,
|
2010-10-24 18:35:26 -07:00
|
|
|
int32_t height, int32_t format) {
|
2012-04-09 19:51:55 -07:00
|
|
|
int32_t err = native_window_set_buffers_format(window, format);
|
2011-07-13 15:24:42 -07:00
|
|
|
if (!err) {
|
2012-04-09 19:51:55 -07:00
|
|
|
err = native_window_set_buffers_user_dimensions(window, width, height);
|
|
|
|
if (!err) {
|
|
|
|
int mode = NATIVE_WINDOW_SCALING_MODE_FREEZE;
|
|
|
|
if (width && height) {
|
|
|
|
mode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW;
|
|
|
|
}
|
|
|
|
err = native_window_set_scaling_mode(window, mode);
|
|
|
|
}
|
2011-07-13 15:24:42 -07:00
|
|
|
}
|
|
|
|
return err;
|
2010-07-01 18:44:46 -07:00
|
|
|
}
|
2010-07-09 11:44:11 -07:00
|
|
|
|
|
|
|
int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer,
|
|
|
|
ARect* inOutDirtyBounds) {
|
2011-07-13 17:39:11 -07:00
|
|
|
return window->perform(window, NATIVE_WINDOW_LOCK, outBuffer, inOutDirtyBounds);
|
2010-07-09 11:44:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int32_t ANativeWindow_unlockAndPost(ANativeWindow* window) {
|
2011-07-13 17:39:11 -07:00
|
|
|
return window->perform(window, NATIVE_WINDOW_UNLOCK_AND_POST);
|
2010-07-09 11:44:11 -07:00
|
|
|
}
|