• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * @addtogroup NativeActivity Native Activity
18  * @{
19  */
20 /**
21  * @file native_window.h
22  * @brief API for accessing a native window.
23  */
24 #ifndef ANDROID_NATIVE_WINDOW_H
25 #define ANDROID_NATIVE_WINDOW_H
26 #include <sys/cdefs.h>
27 #include <android/hardware_buffer.h>
28 #include <android/rect.h>
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 /**
33  * Legacy window pixel format names, kept for backwards compatibility.
34  * New code and APIs should use AHARDWAREBUFFER_FORMAT_*.
35  */
36 enum {
37     // NOTE: these values must match the values from graphics/common/x.x/types.hal
38     /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits. **/
39     WINDOW_FORMAT_RGBA_8888          = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM,
40     /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Unused: 8 bits. **/
41     WINDOW_FORMAT_RGBX_8888          = AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM,
42     /** Red: 5 bits, Green: 6 bits, Blue: 5 bits. **/
43     WINDOW_FORMAT_RGB_565            = AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM,
44 };
45 /**
46  * Transforms that can be applied to buffers as they are displayed to a window.
47  *
48  * Supported transforms are any combination of horizontal mirror, vertical
49  * mirror, and clockwise 90 degree rotation, in that order. Rotations of 180
50  * and 270 degrees are made up of those basic transforms.
51  */
52 enum ANativeWindowTransform {
53     ANATIVEWINDOW_TRANSFORM_IDENTITY            = 0x00,
54     ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL   = 0x01,
55     ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL     = 0x02,
56     ANATIVEWINDOW_TRANSFORM_ROTATE_90           = 0x04,
57     ANATIVEWINDOW_TRANSFORM_ROTATE_180          = ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL |
58                                                   ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL,
59     ANATIVEWINDOW_TRANSFORM_ROTATE_270          = ANATIVEWINDOW_TRANSFORM_ROTATE_180 |
60                                                   ANATIVEWINDOW_TRANSFORM_ROTATE_90,
61 };
62 struct ANativeWindow;
63 /**
64  * Opaque type that provides access to a native window.
65  *
66  * A pointer can be obtained using {@link ANativeWindow_fromSurface()}.
67  */
68 typedef struct ANativeWindow ANativeWindow;
69 /**
70  * Struct that represents a windows buffer.
71  *
72  * A pointer can be obtained using {@link ANativeWindow_lock()}.
73  */
74 typedef struct ANativeWindow_Buffer {
75     // The number of pixels that are show horizontally.
76     int32_t width;
77     // The number of pixels that are shown vertically.
78     int32_t height;
79     // The number of *pixels* that a line in the buffer takes in
80     // memory. This may be >= width.
81     int32_t stride;
82     // The format of the buffer. One of AHARDWAREBUFFER_FORMAT_*
83     int32_t format;
84     // The actual bits.
85     void* bits;
86     // Do not touch.
87     uint32_t reserved[6];
88 } ANativeWindow_Buffer;
89 /**
90  * Acquire a reference on the given {@link ANativeWindow} object. This prevents the object
91  * from being deleted until the reference is removed.
92  */
93 void ANativeWindow_acquire(ANativeWindow* window) __INTRODUCED_IN(26);
94 /**
95  * Remove a reference that was previously acquired with {@link ANativeWindow_acquire()}.
96  */
97 void ANativeWindow_release(ANativeWindow* window) __INTRODUCED_IN(26);
98 /**
99  * Return the current width in pixels of the window surface.
100  *
101  * \return negative value on error.
102  */
103 int32_t ANativeWindow_getWidth(ANativeWindow* window) __INTRODUCED_IN(26);
104 /**
105  * Return the current height in pixels of the window surface.
106  *
107  * \return a negative value on error.
108  */
109 int32_t ANativeWindow_getHeight(ANativeWindow* window) __INTRODUCED_IN(26);
110 /**
111  * Return the current pixel format (AHARDWAREBUFFER_FORMAT_*) of the window surface.
112  *
113  * \return a negative value on error.
114  */
115 int32_t ANativeWindow_getFormat(ANativeWindow* window) __INTRODUCED_IN(26);
116 /**
117  * Change the format and size of the window buffers.
118  *
119  * The width and height control the number of pixels in the buffers, not the
120  * dimensions of the window on screen. If these are different than the
121  * window's physical size, then its buffer will be scaled to match that size
122  * when compositing it to the screen. The width and height must be either both zero
123  * or both non-zero.
124  *
125  * For all of these parameters, if 0 is supplied then the window's base
126  * value will come back in force.
127  *
128  * \param width width of the buffers in pixels.
129  * \param height height of the buffers in pixels.
130  * \param format one of AHARDWAREBUFFER_FORMAT_* constants.
131  * \return 0 for success, or a negative value on error.
132  */
133 int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window,
134         int32_t width, int32_t height, int32_t format) __INTRODUCED_IN(26);
135 /**
136  * Lock the window's next drawing surface for writing.
137  * inOutDirtyBounds is used as an in/out parameter, upon entering the
138  * function, it contains the dirty region, that is, the region the caller
139  * intends to redraw. When the function returns, inOutDirtyBounds is updated
140  * with the actual area the caller needs to redraw -- this region is often
141  * extended by {@link ANativeWindow_lock}.
142  *
143  * \return 0 for success, or a negative value on error.
144  */
145 int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer,
146         ARect* inOutDirtyBounds) __INTRODUCED_IN(26);
147 /**
148  * Unlock the window's drawing surface after previously locking it,
149  * posting the new buffer to the display.
150  *
151  * \return 0 for success, or a negative value on error.
152  */
153 int32_t ANativeWindow_unlockAndPost(ANativeWindow* window) __INTRODUCED_IN(26);
154 /**
155  * Set a transform that will be applied to future buffers posted to the window.
156  *
157  * \param transform combination of {@link ANativeWindowTransform} flags
158  * \return 0 for success, or -EINVAL if \p transform is invalid
159  */
160 int32_t ANativeWindow_setBuffersTransform(ANativeWindow* window, int32_t transform) __INTRODUCED_IN(26);
161 #ifdef __cplusplus
162 };
163 #endif
164 #endif // ANDROID_NATIVE_WINDOW_H
165 /** @} */
166