OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / frameworks / base / native / android / native_window.cpp
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
24 using namespace android;
25
26 ANativeWindow* ANativeWindow_fromSurface(JNIEnv* env, jobject surface) {
27     sp<ANativeWindow> win = android_Surface_getNativeWindow(env, surface);
28     if (win != NULL) {
29         win->incStrong((void*)ANativeWindow_acquire);
30     }
31     return win.get();
32 }
33
34 void ANativeWindow_acquire(ANativeWindow* window) {
35     window->incStrong((void*)ANativeWindow_acquire);
36 }
37
38 void ANativeWindow_release(ANativeWindow* window) {
39     window->decStrong((void*)ANativeWindow_acquire);
40 }
41
42 static int32_t getWindowProp(ANativeWindow* window, int what) {
43     int value;
44     int res = window->query(window, what, &value);
45     return res < 0 ? res : value;
46 }
47
48 int32_t ANativeWindow_getWidth(ANativeWindow* window) {
49     return getWindowProp(window, NATIVE_WINDOW_WIDTH);
50 }
51
52 int32_t ANativeWindow_getHeight(ANativeWindow* window) {
53     return getWindowProp(window, NATIVE_WINDOW_HEIGHT);
54 }
55
56 int32_t ANativeWindow_getFormat(ANativeWindow* window) {
57     return getWindowProp(window, NATIVE_WINDOW_FORMAT);
58 }
59
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);
63     return 0;
64 }
65
66 int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer,
67         ARect* inOutDirtyBounds) {
68     Region dirtyRegion;
69     Region* dirtyParam = NULL;
70     if (inOutDirtyBounds != NULL) {
71         dirtyRegion.set(*(Rect*)inOutDirtyBounds);
72         dirtyParam = &dirtyRegion;
73     }
74     
75     Surface::SurfaceInfo info;
76     status_t res = static_cast<Surface*>(window)->lock(&info, dirtyParam);
77     if (res != OK) {
78         return -1;
79     }
80     
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;
86     
87     if (inOutDirtyBounds != NULL) {
88         *inOutDirtyBounds = dirtyRegion.getBounds();
89     }
90     
91     return 0;
92 }
93
94 int32_t ANativeWindow_unlockAndPost(ANativeWindow* window) {
95     status_t res = static_cast<Surface*>(window)->unlockAndPost();
96     return res == android::OK ? 0 : -1;
97 }