native_window.h revision 89ed4c8cfd8ad64269dfcff9742e16bdd705b926
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 53struct ANativeWindow; 54/** 55 * {@link ANativeWindow} is opaque type that provides access to a native window. 56 * 57 * A pointer can be obtained using ANativeWindow_fromSurface(). 58 */ 59typedef struct ANativeWindow ANativeWindow; 60 61/** 62 * {@link ANativeWindow} is a struct that represents a windows buffer. 63 * 64 * A pointer can be obtained using ANativeWindow_lock(). 65 */ 66typedef 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; 82 83 // 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 98/** 99 * 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 104/** 105 * 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 110/** 111 * Return the current pixel format of the window surface. Returns a 112 * negative value on error. 113 */ 114int32_t ANativeWindow_getFormat(ANativeWindow* window); 115 116/** 117 * 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 155 156/** @} */ 157