native_window.h revision bf6d5e012cd9b15568c2351831f3349cf564bf18
1e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/* 2e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Copyright (C) 2010 The Android Open Source Project 3e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * 4e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 5e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * you may not use this file except in compliance with the License. 6e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * You may obtain a copy of the License at 7e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * 8e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 9e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * 10e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Unless required by applicable law or agreed to in writing, software 11e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 12e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * See the License for the specific language governing permissions and 14e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * limitations under the License. 15e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */ 16e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 17bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** 18bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * @addtogroup NativeActivity Native Activity 19bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * @{ 20bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine */ 21bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine 22bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** 23bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * @file native_window.h 24bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine */ 25bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine 26e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#ifndef ANDROID_NATIVE_WINDOW_H 27e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#define ANDROID_NATIVE_WINDOW_H 28e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 29e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#include <android/rect.h> 30e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 31e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#ifdef __cplusplus 32e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianextern "C" { 33e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#endif 34e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 35bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** 36e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Pixel formats that a window can use. 37e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */ 38e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianenum { 39bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits. **/ 40e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian WINDOW_FORMAT_RGBA_8888 = 1, 41bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Unused: 8 bits. **/ 42e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian WINDOW_FORMAT_RGBX_8888 = 2, 43bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine /** Red: 5 bits, Green: 6 bits, Blue: 5 bits. **/ 44e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian WINDOW_FORMAT_RGB_565 = 4, 45e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian}; 46e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 47e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianstruct ANativeWindow; 48bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** 49bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * {@link ANativeWindow} is opaque type that provides access to a native window. 50bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * 51bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * A pointer can be obtained using ANativeWindow_fromSurface(). 52bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine */ 53e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopiantypedef struct ANativeWindow ANativeWindow; 54e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 55bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** 56bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * {@link ANativeWindow} is a struct that represents a windows buffer. 57bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * 58bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * A pointer can be obtained using ANativeWindow_lock(). 59bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine */ 60e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopiantypedef struct ANativeWindow_Buffer { 61e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian // The number of pixels that are show horizontally. 62e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian int32_t width; 63e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 64e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian // The number of pixels that are shown vertically. 65e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian int32_t height; 66e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 67e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian // The number of *pixels* that a line in the buffer takes in 68e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian // memory. This may be >= width. 69e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian int32_t stride; 70e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 71e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian // The format of the buffer. One of WINDOW_FORMAT_* 72e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian int32_t format; 73e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 74e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian // The actual bits. 75e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian void* bits; 76bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine 77e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian // Do not touch. 78e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian uint32_t reserved[6]; 79e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian} ANativeWindow_Buffer; 80e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 81e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/** 82e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Acquire a reference on the given ANativeWindow object. This prevents the object 83e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * from being deleted until the reference is removed. 84e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */ 85e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianvoid ANativeWindow_acquire(ANativeWindow* window); 86e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 87e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/** 88e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Remove a reference that was previously acquired with ANativeWindow_acquire(). 89e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */ 90e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianvoid ANativeWindow_release(ANativeWindow* window); 91e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 92bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** 93e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Return the current width in pixels of the window surface. Returns a 94e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * negative value on error. 95e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */ 96e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint32_t ANativeWindow_getWidth(ANativeWindow* window); 97e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 98bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** 99e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Return the current height in pixels of the window surface. Returns a 100e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * negative value on error. 101e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */ 102e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint32_t ANativeWindow_getHeight(ANativeWindow* window); 103e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 104bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** 105e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Return the current pixel format of the window surface. Returns a 106e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * negative value on error. 107e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */ 108e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint32_t ANativeWindow_getFormat(ANativeWindow* window); 109e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 110bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** 111e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Change the format and size of the window buffers. 112e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * 113e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * The width and height control the number of pixels in the buffers, not the 114e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * dimensions of the window on screen. If these are different than the 115e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * window's physical size, then it buffer will be scaled to match that size 116e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * when compositing it to the screen. 117e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * 118e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * For all of these parameters, if 0 is supplied then the window's base 119e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * value will come back in force. 120e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * 121e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * width and height must be either both zero or both non-zero. 122e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * 123e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */ 124e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window, 125e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian int32_t width, int32_t height, int32_t format); 126e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 127e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/** 128e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Lock the window's next drawing surface for writing. 129e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * inOutDirtyBounds is used as an in/out parameter, upon entering the 130e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * function, it contains the dirty region, that is, the region the caller 131e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * intends to redraw. When the function returns, inOutDirtyBounds is updated 132e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * with the actual area the caller needs to redraw -- this region is often 133e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * extended by ANativeWindow_lock. 134e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */ 135e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer, 136e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian ARect* inOutDirtyBounds); 137e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 138e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/** 139e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Unlock the window's drawing surface after previously locking it, 140e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * posting the new buffer to the display. 141e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */ 142e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint32_t ANativeWindow_unlockAndPost(ANativeWindow* window); 143e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 144e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#ifdef __cplusplus 145e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian}; 146e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#endif 147e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian 148e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#endif // ANDROID_NATIVE_WINDOW_H 149bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine 150bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** @} */ 151