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