blob: 34c136a17e2af94d79f34268d2134900e38722de [file] [log] [blame]
Mathias Agopian89ed4c82017-02-09 18:48:34 -08001/*
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 "ANativeWindow"
18
19#include <android/native_window.h>
20#include <system/window.h>
21
22void ANativeWindow_acquire(ANativeWindow* window) {
23 window->incStrong((void*)ANativeWindow_acquire);
24}
25
26void ANativeWindow_release(ANativeWindow* window) {
27 window->decStrong((void*)ANativeWindow_release);
28}
29
30static int32_t getWindowProp(ANativeWindow* window, int what) {
31 int value;
32 int res = window->query(window, what, &value);
33 return res < 0 ? res : value;
34}
35
36int32_t ANativeWindow_getWidth(ANativeWindow* window) {
37 return getWindowProp(window, NATIVE_WINDOW_WIDTH);
38}
39
40int32_t ANativeWindow_getHeight(ANativeWindow* window) {
41 return getWindowProp(window, NATIVE_WINDOW_HEIGHT);
42}
43
44int32_t ANativeWindow_getFormat(ANativeWindow* window) {
45 return getWindowProp(window, NATIVE_WINDOW_FORMAT);
46}
47
48int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window, int32_t width,
49 int32_t height, int32_t format) {
50 int32_t err = native_window_set_buffers_format(window, format);
51 if (!err) {
52 err = native_window_set_buffers_user_dimensions(window, width, height);
53 if (!err) {
54 int mode = NATIVE_WINDOW_SCALING_MODE_FREEZE;
55 if (width && height) {
56 mode = NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW;
57 }
58 err = native_window_set_scaling_mode(window, mode);
59 }
60 }
61 return err;
62}
63
64int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer,
65 ARect* inOutDirtyBounds) {
66 return window->perform(window, NATIVE_WINDOW_LOCK, outBuffer, inOutDirtyBounds);
67}
68
69int32_t ANativeWindow_unlockAndPost(ANativeWindow* window) {
70 return window->perform(window, NATIVE_WINDOW_UNLOCK_AND_POST);
71}