| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 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 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 17 | /** | 
 | 18 |  * @addtogroup NativeActivity Native Activity | 
 | 19 |  * @{ | 
 | 20 |  */ | 
 | 21 |  | 
 | 22 | /** | 
 | 23 |  * @file native_window.h | 
 | 24 |  */ | 
 | 25 |  | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 26 | #ifndef ANDROID_NATIVE_WINDOW_H | 
 | 27 | #define ANDROID_NATIVE_WINDOW_H | 
 | 28 |  | 
| Dan Albert | 494ed55 | 2016-09-23 15:57:45 -0700 | [diff] [blame] | 29 | #include <sys/cdefs.h> | 
 | 30 |  | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 31 | #include <android/rect.h> | 
 | 32 |  | 
 | 33 | #ifdef __cplusplus | 
 | 34 | extern "C" { | 
 | 35 | #endif | 
 | 36 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 37 | /** | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 38 |  * Pixel formats that a window can use. | 
 | 39 |  */ | 
 | 40 | enum { | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 41 |     /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits. **/ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 42 |     WINDOW_FORMAT_RGBA_8888          = 1, | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 43 |     /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Unused: 8 bits. **/ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 44 |     WINDOW_FORMAT_RGBX_8888          = 2, | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 45 |     /** Red: 5 bits, Green: 6 bits, Blue: 5 bits. **/ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 46 |     WINDOW_FORMAT_RGB_565            = 4, | 
 | 47 | }; | 
 | 48 |  | 
 | 49 | struct ANativeWindow; | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 50 | /** | 
 | 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 Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 55 | typedef struct ANativeWindow ANativeWindow; | 
 | 56 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 57 | /** | 
 | 58 |  * {@link ANativeWindow} is a struct that represents a windows buffer. | 
 | 59 |  * | 
 | 60 |  * A pointer can be obtained using ANativeWindow_lock(). | 
 | 61 |  */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 62 | typedef 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 Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 78 |  | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 79 |     // 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 |  */ | 
 | 87 | void ANativeWindow_acquire(ANativeWindow* window); | 
 | 88 |  | 
 | 89 | /** | 
 | 90 |  * Remove a reference that was previously acquired with ANativeWindow_acquire(). | 
 | 91 |  */ | 
 | 92 | void ANativeWindow_release(ANativeWindow* window); | 
 | 93 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 94 | /** | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 95 |  * Return the current width in pixels of the window surface.  Returns a | 
 | 96 |  * negative value on error. | 
 | 97 |  */ | 
 | 98 | int32_t ANativeWindow_getWidth(ANativeWindow* window); | 
 | 99 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 100 | /** | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 101 |  * Return the current height in pixels of the window surface.  Returns a | 
 | 102 |  * negative value on error. | 
 | 103 |  */ | 
 | 104 | int32_t ANativeWindow_getHeight(ANativeWindow* window); | 
 | 105 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 106 | /** | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 107 |  * Return the current pixel format of the window surface.  Returns a | 
 | 108 |  * negative value on error. | 
 | 109 |  */ | 
 | 110 | int32_t ANativeWindow_getFormat(ANativeWindow* window); | 
 | 111 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 112 | /** | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 113 |  * 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 |  */ | 
 | 126 | int32_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 |  */ | 
 | 137 | int32_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 |  */ | 
 | 144 | int32_t ANativeWindow_unlockAndPost(ANativeWindow* window); | 
 | 145 |  | 
 | 146 | #ifdef __cplusplus | 
 | 147 | }; | 
 | 148 | #endif | 
 | 149 |  | 
 | 150 | #endif // ANDROID_NATIVE_WINDOW_H | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 151 |  | 
 | 152 | /** @} */ |