blob: 021dc42d9a0be35006d78c63c352d3d72650f5d2 [file] [log] [blame]
Mathias Agopiane1c61d32012-03-23 14:19:36 -07001/*
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
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070017/**
18 * @addtogroup NativeActivity Native Activity
19 * @{
20 */
21
22/**
23 * @file native_window.h
24 */
25
Mathias Agopiane1c61d32012-03-23 14:19:36 -070026#ifndef ANDROID_NATIVE_WINDOW_H
27#define ANDROID_NATIVE_WINDOW_H
28
Dan Albert494ed552016-09-23 15:57:45 -070029#include <sys/cdefs.h>
30
Mathias Agopiane1c61d32012-03-23 14:19:36 -070031#include <android/rect.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070037/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -070038 * Pixel formats that a window can use.
39 */
40enum {
Romain Guyff415142016-12-13 16:51:25 -080041 // NOTE: these values must match the values from graphics/common/x.x/types.hal
42
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070043 /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits. **/
Mathias Agopiane1c61d32012-03-23 14:19:36 -070044 WINDOW_FORMAT_RGBA_8888 = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070045 /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Unused: 8 bits. **/
Mathias Agopiane1c61d32012-03-23 14:19:36 -070046 WINDOW_FORMAT_RGBX_8888 = 2,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070047 /** Red: 5 bits, Green: 6 bits, Blue: 5 bits. **/
Mathias Agopiane1c61d32012-03-23 14:19:36 -070048 WINDOW_FORMAT_RGB_565 = 4,
Romain Guyff415142016-12-13 16:51:25 -080049 /** Red: 16 bits, Green: 16 bits, Blue: 16 bits, Alpha: 16 bits. **/
50 WINDOW_FORMAT_RGBA_FP16 = 0x16,
Mathias Agopiane1c61d32012-03-23 14:19:36 -070051};
52
53struct ANativeWindow;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070054/**
55 * {@link ANativeWindow} is opaque type that provides access to a native window.
56 *
57 * A pointer can be obtained using ANativeWindow_fromSurface().
58 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070059typedef struct ANativeWindow ANativeWindow;
60
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070061/**
62 * {@link ANativeWindow} is a struct that represents a windows buffer.
63 *
64 * A pointer can be obtained using ANativeWindow_lock().
65 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070066typedef struct ANativeWindow_Buffer {
67 // The number of pixels that are show horizontally.
68 int32_t width;
69
70 // The number of pixels that are shown vertically.
71 int32_t height;
72
73 // The number of *pixels* that a line in the buffer takes in
74 // memory. This may be >= width.
75 int32_t stride;
76
77 // The format of the buffer. One of WINDOW_FORMAT_*
78 int32_t format;
79
80 // The actual bits.
81 void* bits;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070082
Mathias Agopiane1c61d32012-03-23 14:19:36 -070083 // Do not touch.
84 uint32_t reserved[6];
85} ANativeWindow_Buffer;
86
87/**
88 * Acquire a reference on the given ANativeWindow object. This prevents the object
89 * from being deleted until the reference is removed.
90 */
91void ANativeWindow_acquire(ANativeWindow* window);
92
93/**
94 * Remove a reference that was previously acquired with ANativeWindow_acquire().
95 */
96void ANativeWindow_release(ANativeWindow* window);
97
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070098/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -070099 * Return the current width in pixels of the window surface. Returns a
100 * negative value on error.
101 */
102int32_t ANativeWindow_getWidth(ANativeWindow* window);
103
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700104/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700105 * Return the current height in pixels of the window surface. Returns a
106 * negative value on error.
107 */
108int32_t ANativeWindow_getHeight(ANativeWindow* window);
109
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700110/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700111 * Return the current pixel format of the window surface. Returns a
112 * negative value on error.
113 */
114int32_t ANativeWindow_getFormat(ANativeWindow* window);
115
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700116/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700117 * 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 it buffer will be scaled to match that size
122 * when compositing it to the screen.
123 *
124 * For all of these parameters, if 0 is supplied then the window's base
125 * value will come back in force.
126 *
127 * width and height must be either both zero or both non-zero.
128 *
129 */
130int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window,
131 int32_t width, int32_t height, int32_t format);
132
133/**
134 * Lock the window's next drawing surface for writing.
135 * inOutDirtyBounds is used as an in/out parameter, upon entering the
136 * function, it contains the dirty region, that is, the region the caller
137 * intends to redraw. When the function returns, inOutDirtyBounds is updated
138 * with the actual area the caller needs to redraw -- this region is often
139 * extended by ANativeWindow_lock.
140 */
141int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer,
142 ARect* inOutDirtyBounds);
143
144/**
145 * Unlock the window's drawing surface after previously locking it,
146 * posting the new buffer to the display.
147 */
148int32_t ANativeWindow_unlockAndPost(ANativeWindow* window);
149
150#ifdef __cplusplus
151};
152#endif
153
154#endif // ANDROID_NATIVE_WINDOW_H
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700155
156/** @} */