blob: b60b9f1d9cc439db8ae2d94f869804219dd2cacc [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 {
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070041 /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits. **/
Mathias Agopiane1c61d32012-03-23 14:19:36 -070042 WINDOW_FORMAT_RGBA_8888 = 1,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070043 /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Unused: 8 bits. **/
Mathias Agopiane1c61d32012-03-23 14:19:36 -070044 WINDOW_FORMAT_RGBX_8888 = 2,
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070045 /** Red: 5 bits, Green: 6 bits, Blue: 5 bits. **/
Mathias Agopiane1c61d32012-03-23 14:19:36 -070046 WINDOW_FORMAT_RGB_565 = 4,
47};
48
49struct ANativeWindow;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070050/**
51 * {@link ANativeWindow} is opaque type that provides access to a native window.
52 *
53 * A pointer can be obtained using ANativeWindow_fromSurface().
54 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070055typedef struct ANativeWindow ANativeWindow;
56
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070057/**
58 * {@link ANativeWindow} is a struct that represents a windows buffer.
59 *
60 * A pointer can be obtained using ANativeWindow_lock().
61 */
Mathias Agopiane1c61d32012-03-23 14:19:36 -070062typedef struct ANativeWindow_Buffer {
63 // The number of pixels that are show horizontally.
64 int32_t width;
65
66 // The number of pixels that are shown vertically.
67 int32_t height;
68
69 // The number of *pixels* that a line in the buffer takes in
70 // memory. This may be >= width.
71 int32_t stride;
72
73 // The format of the buffer. One of WINDOW_FORMAT_*
74 int32_t format;
75
76 // The actual bits.
77 void* bits;
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070078
Mathias Agopiane1c61d32012-03-23 14:19:36 -070079 // Do not touch.
80 uint32_t reserved[6];
81} ANativeWindow_Buffer;
82
83/**
84 * Acquire a reference on the given ANativeWindow object. This prevents the object
85 * from being deleted until the reference is removed.
86 */
87void ANativeWindow_acquire(ANativeWindow* window);
88
89/**
90 * Remove a reference that was previously acquired with ANativeWindow_acquire().
91 */
92void ANativeWindow_release(ANativeWindow* window);
93
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -070094/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -070095 * Return the current width in pixels of the window surface. Returns a
96 * negative value on error.
97 */
98int32_t ANativeWindow_getWidth(ANativeWindow* window);
99
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700100/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700101 * Return the current height in pixels of the window surface. Returns a
102 * negative value on error.
103 */
104int32_t ANativeWindow_getHeight(ANativeWindow* window);
105
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700106/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700107 * Return the current pixel format of the window surface. Returns a
108 * negative value on error.
109 */
110int32_t ANativeWindow_getFormat(ANativeWindow* window);
111
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700112/**
Mathias Agopiane1c61d32012-03-23 14:19:36 -0700113 * Change the format and size of the window buffers.
114 *
115 * The width and height control the number of pixels in the buffers, not the
116 * dimensions of the window on screen. If these are different than the
117 * window's physical size, then it buffer will be scaled to match that size
118 * when compositing it to the screen.
119 *
120 * For all of these parameters, if 0 is supplied then the window's base
121 * value will come back in force.
122 *
123 * width and height must be either both zero or both non-zero.
124 *
125 */
126int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window,
127 int32_t width, int32_t height, int32_t format);
128
129/**
130 * Lock the window's next drawing surface for writing.
131 * inOutDirtyBounds is used as an in/out parameter, upon entering the
132 * function, it contains the dirty region, that is, the region the caller
133 * intends to redraw. When the function returns, inOutDirtyBounds is updated
134 * with the actual area the caller needs to redraw -- this region is often
135 * extended by ANativeWindow_lock.
136 */
137int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer,
138 ARect* inOutDirtyBounds);
139
140/**
141 * Unlock the window's drawing surface after previously locking it,
142 * posting the new buffer to the display.
143 */
144int32_t ANativeWindow_unlockAndPost(ANativeWindow* window);
145
146#ifdef __cplusplus
147};
148#endif
149
150#endif // ANDROID_NATIVE_WINDOW_H
Johan Euphrosinebf6d5e02015-03-27 17:15:43 -0700151
152/** @} */