Home | History | Annotate | Download | only in android
      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 <android/rect.h>
     30 
     31 #ifdef __cplusplus
     32 extern "C" {
     33 #endif
     34 
     35 /**
     36  * Pixel formats that a window can use.
     37  */
     38 enum {
     39     /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits. **/
     40     WINDOW_FORMAT_RGBA_8888          = 1,
     41     /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Unused: 8 bits. **/
     42     WINDOW_FORMAT_RGBX_8888          = 2,
     43     /** Red: 5 bits, Green: 6 bits, Blue: 5 bits. **/
     44     WINDOW_FORMAT_RGB_565            = 4,
     45 };
     46 
     47 struct ANativeWindow;
     48 /**
     49  * {@link ANativeWindow} is opaque type that provides access to a native window.
     50  *
     51  * A pointer can be obtained using ANativeWindow_fromSurface().
     52  */
     53 typedef struct ANativeWindow ANativeWindow;
     54 
     55 /**
     56  * {@link ANativeWindow} is a struct that represents a windows buffer.
     57  *
     58  * A pointer can be obtained using ANativeWindow_lock().
     59  */
     60 typedef struct ANativeWindow_Buffer {
     61     // The number of pixels that are show horizontally.
     62     int32_t width;
     63 
     64     // The number of pixels that are shown vertically.
     65     int32_t height;
     66 
     67     // The number of *pixels* that a line in the buffer takes in
     68     // memory.  This may be >= width.
     69     int32_t stride;
     70 
     71     // The format of the buffer.  One of WINDOW_FORMAT_*
     72     int32_t format;
     73 
     74     // The actual bits.
     75     void* bits;
     76 
     77     // Do not touch.
     78     uint32_t reserved[6];
     79 } ANativeWindow_Buffer;
     80 
     81 /**
     82  * Acquire a reference on the given ANativeWindow object.  This prevents the object
     83  * from being deleted until the reference is removed.
     84  */
     85 void ANativeWindow_acquire(ANativeWindow* window);
     86 
     87 /**
     88  * Remove a reference that was previously acquired with ANativeWindow_acquire().
     89  */
     90 void ANativeWindow_release(ANativeWindow* window);
     91 
     92 /**
     93  * Return the current width in pixels of the window surface.  Returns a
     94  * negative value on error.
     95  */
     96 int32_t ANativeWindow_getWidth(ANativeWindow* window);
     97 
     98 /**
     99  * Return the current height in pixels of the window surface.  Returns a
    100  * negative value on error.
    101  */
    102 int32_t ANativeWindow_getHeight(ANativeWindow* window);
    103 
    104 /**
    105  * Return the current pixel format of the window surface.  Returns a
    106  * negative value on error.
    107  */
    108 int32_t ANativeWindow_getFormat(ANativeWindow* window);
    109 
    110 /**
    111  * Change the format and size of the window buffers.
    112  *
    113  * The width and height control the number of pixels in the buffers, not the
    114  * dimensions of the window on screen.  If these are different than the
    115  * window's physical size, then it buffer will be scaled to match that size
    116  * when compositing it to the screen.
    117  *
    118  * For all of these parameters, if 0 is supplied then the window's base
    119  * value will come back in force.
    120  *
    121  * width and height must be either both zero or both non-zero.
    122  *
    123  */
    124 int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window,
    125         int32_t width, int32_t height, int32_t format);
    126 
    127 /**
    128  * Lock the window's next drawing surface for writing.
    129  * inOutDirtyBounds is used as an in/out parameter, upon entering the
    130  * function, it contains the dirty region, that is, the region the caller
    131  * intends to redraw. When the function returns, inOutDirtyBounds is updated
    132  * with the actual area the caller needs to redraw -- this region is often
    133  * extended by ANativeWindow_lock.
    134  */
    135 int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer,
    136         ARect* inOutDirtyBounds);
    137 
    138 /**
    139  * Unlock the window's drawing surface after previously locking it,
    140  * posting the new buffer to the display.
    141  */
    142 int32_t ANativeWindow_unlockAndPost(ANativeWindow* window);
    143 
    144 #ifdef __cplusplus
    145 };
    146 #endif
    147 
    148 #endif // ANDROID_NATIVE_WINDOW_H
    149 
    150 /** @} */
    151