| 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 |  | 
| Craig Donner | c7e8dae | 2017-01-03 10:24:58 -0800 | [diff] [blame] | 31 | #include <android/hardware_buffer.h> | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 32 | #include <android/rect.h> | 
|  | 33 |  | 
|  | 34 | #ifdef __cplusplus | 
|  | 35 | extern "C" { | 
|  | 36 | #endif | 
|  | 37 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 38 | /** | 
| Craig Donner | c7e8dae | 2017-01-03 10:24:58 -0800 | [diff] [blame] | 39 | * Legacy window pixel format names, kept for backwards compatibility. | 
|  | 40 | * New code and APIs should use AHARDWAREBUFFER_FORMAT_*. | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 41 | */ | 
|  | 42 | enum { | 
| Romain Guy | ff41514 | 2016-12-13 16:51:25 -0800 | [diff] [blame] | 43 | // NOTE: these values must match the values from graphics/common/x.x/types.hal | 
|  | 44 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 45 | /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits. **/ | 
| Craig Donner | c7e8dae | 2017-01-03 10:24:58 -0800 | [diff] [blame] | 46 | WINDOW_FORMAT_RGBA_8888          = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM, | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 47 | /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Unused: 8 bits. **/ | 
| Craig Donner | c7e8dae | 2017-01-03 10:24:58 -0800 | [diff] [blame] | 48 | WINDOW_FORMAT_RGBX_8888          = AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM, | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 49 | /** Red: 5 bits, Green: 6 bits, Blue: 5 bits. **/ | 
| Craig Donner | c7e8dae | 2017-01-03 10:24:58 -0800 | [diff] [blame] | 50 | WINDOW_FORMAT_RGB_565            = AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM, | 
| Romain Guy | ff41514 | 2016-12-13 16:51:25 -0800 | [diff] [blame] | 51 | /** Red: 16 bits, Green: 16 bits, Blue: 16 bits, Alpha: 16 bits. **/ | 
|  | 52 | WINDOW_FORMAT_RGBA_FP16          = 0x16, | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 53 | }; | 
|  | 54 |  | 
|  | 55 | struct ANativeWindow; | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 56 | /** | 
|  | 57 | * {@link ANativeWindow} is opaque type that provides access to a native window. | 
|  | 58 | * | 
|  | 59 | * A pointer can be obtained using ANativeWindow_fromSurface(). | 
|  | 60 | */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 61 | typedef struct ANativeWindow ANativeWindow; | 
|  | 62 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 63 | /** | 
|  | 64 | * {@link ANativeWindow} is a struct that represents a windows buffer. | 
|  | 65 | * | 
|  | 66 | * A pointer can be obtained using ANativeWindow_lock(). | 
|  | 67 | */ | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 68 | typedef struct ANativeWindow_Buffer { | 
|  | 69 | // The number of pixels that are show horizontally. | 
|  | 70 | int32_t width; | 
|  | 71 |  | 
|  | 72 | // The number of pixels that are shown vertically. | 
|  | 73 | int32_t height; | 
|  | 74 |  | 
|  | 75 | // The number of *pixels* that a line in the buffer takes in | 
|  | 76 | // memory.  This may be >= width. | 
|  | 77 | int32_t stride; | 
|  | 78 |  | 
|  | 79 | // The format of the buffer.  One of WINDOW_FORMAT_* | 
|  | 80 | int32_t format; | 
|  | 81 |  | 
|  | 82 | // The actual bits. | 
|  | 83 | void* bits; | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 84 |  | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 85 | // Do not touch. | 
|  | 86 | uint32_t reserved[6]; | 
|  | 87 | } ANativeWindow_Buffer; | 
|  | 88 |  | 
|  | 89 | /** | 
|  | 90 | * Acquire a reference on the given ANativeWindow object.  This prevents the object | 
|  | 91 | * from being deleted until the reference is removed. | 
|  | 92 | */ | 
|  | 93 | void ANativeWindow_acquire(ANativeWindow* window); | 
|  | 94 |  | 
|  | 95 | /** | 
|  | 96 | * Remove a reference that was previously acquired with ANativeWindow_acquire(). | 
|  | 97 | */ | 
|  | 98 | void ANativeWindow_release(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 width in pixels of the window surface.  Returns a | 
|  | 102 | * negative value on error. | 
|  | 103 | */ | 
|  | 104 | int32_t ANativeWindow_getWidth(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 height in pixels of the window surface.  Returns a | 
|  | 108 | * negative value on error. | 
|  | 109 | */ | 
|  | 110 | int32_t ANativeWindow_getHeight(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 | * Return the current pixel format of the window surface.  Returns a | 
|  | 114 | * negative value on error. | 
|  | 115 | */ | 
|  | 116 | int32_t ANativeWindow_getFormat(ANativeWindow* window); | 
|  | 117 |  | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 118 | /** | 
| Mathias Agopian | e1c61d3 | 2012-03-23 14:19:36 -0700 | [diff] [blame] | 119 | * Change the format and size of the window buffers. | 
|  | 120 | * | 
|  | 121 | * The width and height control the number of pixels in the buffers, not the | 
|  | 122 | * dimensions of the window on screen.  If these are different than the | 
|  | 123 | * window's physical size, then it buffer will be scaled to match that size | 
|  | 124 | * when compositing it to the screen. | 
|  | 125 | * | 
|  | 126 | * For all of these parameters, if 0 is supplied then the window's base | 
|  | 127 | * value will come back in force. | 
|  | 128 | * | 
|  | 129 | * width and height must be either both zero or both non-zero. | 
|  | 130 | * | 
|  | 131 | */ | 
|  | 132 | int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window, | 
|  | 133 | int32_t width, int32_t height, int32_t format); | 
|  | 134 |  | 
|  | 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 ANativeWindow_lock. | 
|  | 142 | */ | 
|  | 143 | int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer, | 
|  | 144 | ARect* inOutDirtyBounds); | 
|  | 145 |  | 
|  | 146 | /** | 
|  | 147 | * Unlock the window's drawing surface after previously locking it, | 
|  | 148 | * posting the new buffer to the display. | 
|  | 149 | */ | 
|  | 150 | int32_t ANativeWindow_unlockAndPost(ANativeWindow* window); | 
|  | 151 |  | 
|  | 152 | #ifdef __cplusplus | 
|  | 153 | }; | 
|  | 154 | #endif | 
|  | 155 |  | 
|  | 156 | #endif // ANDROID_NATIVE_WINDOW_H | 
| Johan Euphrosine | bf6d5e0 | 2015-03-27 17:15:43 -0700 | [diff] [blame] | 157 |  | 
|  | 158 | /** @} */ |