2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #define LOG_TAG "Surface"
18 #include <utils/Log.h>
20 #include <android/native_window_jni.h>
21 #include <surfaceflinger/Surface.h>
22 #include <android_runtime/android_view_Surface.h>
24 using namespace android;
26 ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface) {
27 sp<ANativeWindow> win = android_Surface_getNativeWindow(env, surface);
29 win->incStrong((void*)ANativeWindow_acquire);
34 void ANativeWindow_acquire(ANativeWindow* window) {
35 window->incStrong((void*)ANativeWindow_acquire);
38 void ANativeWindow_release(ANativeWindow* window) {
39 window->decStrong((void*)ANativeWindow_acquire);
42 static int32_t getWindowProp(ANativeWindow* window, int what) {
44 int res = window->query(window, what, &value);
45 return res < 0 ? res : value;
48 int32_t ANativeWindow_getWidth(ANativeWindow* window) {
49 return getWindowProp(window, NATIVE_WINDOW_WIDTH);
52 int32_t ANativeWindow_getHeight(ANativeWindow* window) {
53 return getWindowProp(window, NATIVE_WINDOW_HEIGHT);
56 int32_t ANativeWindow_getFormat(ANativeWindow* window) {
57 return getWindowProp(window, NATIVE_WINDOW_FORMAT);
60 int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window, int32_t width,
61 int32_t height, int32_t format) {
62 native_window_set_buffers_geometry(window, width, height, format);
66 int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer,
67 ARect* inOutDirtyBounds) {
69 Region* dirtyParam = NULL;
70 if (inOutDirtyBounds != NULL) {
71 dirtyRegion.set(*(Rect*)inOutDirtyBounds);
72 dirtyParam = &dirtyRegion;
75 Surface::SurfaceInfo info;
76 status_t res = static_cast<Surface*>(window)->lock(&info, dirtyParam);
81 outBuffer->width = (int32_t)info.w;
82 outBuffer->height = (int32_t)info.h;
83 outBuffer->stride = (int32_t)info.s;
84 outBuffer->format = (int32_t)info.format;
85 outBuffer->bits = info.bits;
87 if (inOutDirtyBounds != NULL) {
88 *inOutDirtyBounds = dirtyRegion.getBounds();
94 int32_t ANativeWindow_unlockAndPost(ANativeWindow* window) {
95 status_t res = static_cast<Surface*>(window)->unlockAndPost();
96 return res == android::OK ? 0 : -1;