native_window.h revision 09932eceb2fcec029edc6aaa0e2bca0591613281
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
29494ed550f5aea1332984fb9f0f11036fc58bd716Dan Albert#include <sys/cdefs.h>
30494ed550f5aea1332984fb9f0f11036fc58bd716Dan Albert
31c7e8daecb66a4875e16b03cf744fdd9ab867aa4fCraig Donner#include <android/hardware_buffer.h>
32e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#include <android/rect.h>
33e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
34e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#ifdef __cplusplus
35e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianextern "C" {
36e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#endif
37e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
38bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/**
39c7e8daecb66a4875e16b03cf744fdd9ab867aa4fCraig Donner * Legacy window pixel format names, kept for backwards compatibility.
40c7e8daecb66a4875e16b03cf744fdd9ab867aa4fCraig Donner * New code and APIs should use AHARDWAREBUFFER_FORMAT_*.
41e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
42e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianenum {
43ff415149dc5a83a4eb5960daf2cb2c310ef89847Romain Guy    // NOTE: these values must match the values from graphics/common/x.x/types.hal
44ff415149dc5a83a4eb5960daf2cb2c310ef89847Romain Guy
45bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine    /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Alpha: 8 bits. **/
46c7e8daecb66a4875e16b03cf744fdd9ab867aa4fCraig Donner    WINDOW_FORMAT_RGBA_8888          = AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM,
47bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine    /** Red: 8 bits, Green: 8 bits, Blue: 8 bits, Unused: 8 bits. **/
48c7e8daecb66a4875e16b03cf744fdd9ab867aa4fCraig Donner    WINDOW_FORMAT_RGBX_8888          = AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM,
49bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine    /** Red: 5 bits, Green: 6 bits, Blue: 5 bits. **/
50c7e8daecb66a4875e16b03cf744fdd9ab867aa4fCraig Donner    WINDOW_FORMAT_RGB_565            = AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM,
51e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian};
52e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
5309932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall/**
5409932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall * Transforms that can be applied to buffers as they are displayed to a window.
5509932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall *
5609932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall * Supported transforms are any combination of horizontal mirror, vertical
5709932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall * mirror, and clockwise 90 degree rotation, in that order. Rotations of 180
5809932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall * and 270 degrees are made up of those basic transforms.
5909932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall */
6009932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hallenum ANativeWindowTransform {
6109932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall    ANATIVEWINDOW_TRANSFORM_IDENTITY            = 0x00,
6209932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall    ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL   = 0x01,
6309932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall    ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL     = 0x02,
6409932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall    ANATIVEWINDOW_TRANSFORM_ROTATE_90           = 0x04,
6509932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall
6609932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall    ANATIVEWINDOW_TRANSFORM_ROTATE_180          = ANATIVEWINDOW_TRANSFORM_MIRROR_HORIZONTAL |
6709932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall                                                  ANATIVEWINDOW_TRANSFORM_MIRROR_VERTICAL,
6809932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall    ANATIVEWINDOW_TRANSFORM_ROTATE_270          = ANATIVEWINDOW_TRANSFORM_ROTATE_180 |
6909932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall                                                  ANATIVEWINDOW_TRANSFORM_ROTATE_90,
7009932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall};
7109932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall
72e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianstruct ANativeWindow;
73bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/**
74bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * {@link ANativeWindow} is opaque type that provides access to a native window.
75bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine *
76bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * A pointer can be obtained using ANativeWindow_fromSurface().
77bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine */
78e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopiantypedef struct ANativeWindow ANativeWindow;
79e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
80bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/**
81bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * {@link ANativeWindow} is a struct that represents a windows buffer.
82bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine *
83bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine * A pointer can be obtained using ANativeWindow_lock().
84bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine */
85e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopiantypedef struct ANativeWindow_Buffer {
86e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    // The number of pixels that are show horizontally.
87e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    int32_t width;
88e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
89e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    // The number of pixels that are shown vertically.
90e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    int32_t height;
91e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
92e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    // The number of *pixels* that a line in the buffer takes in
93e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    // memory.  This may be >= width.
94e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    int32_t stride;
95e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
96e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    // The format of the buffer.  One of WINDOW_FORMAT_*
97e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    int32_t format;
98e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
99e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    // The actual bits.
100e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    void* bits;
101bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine
102e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    // Do not touch.
103e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian    uint32_t reserved[6];
104e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian} ANativeWindow_Buffer;
105e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
106e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/**
107e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Acquire a reference on the given ANativeWindow object.  This prevents the object
108e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * from being deleted until the reference is removed.
109e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
110e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianvoid ANativeWindow_acquire(ANativeWindow* window);
111e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
112e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/**
113e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Remove a reference that was previously acquired with ANativeWindow_acquire().
114e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
115e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianvoid ANativeWindow_release(ANativeWindow* window);
116e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
117bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/**
118e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Return the current width in pixels of the window surface.  Returns a
119e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * negative value on error.
120e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
121e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint32_t ANativeWindow_getWidth(ANativeWindow* window);
122e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
123bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/**
124e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Return the current height in pixels of the window surface.  Returns a
125e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * negative value on error.
126e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
127e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint32_t ANativeWindow_getHeight(ANativeWindow* window);
128e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
129bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/**
130e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Return the current pixel format of the window surface.  Returns a
131e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * negative value on error.
132e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
133e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint32_t ANativeWindow_getFormat(ANativeWindow* window);
134e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
135bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/**
136e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Change the format and size of the window buffers.
137e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian *
138e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * The width and height control the number of pixels in the buffers, not the
139e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * dimensions of the window on screen.  If these are different than the
140e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * window's physical size, then it buffer will be scaled to match that size
141e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * when compositing it to the screen.
142e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian *
143e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * For all of these parameters, if 0 is supplied then the window's base
144e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * value will come back in force.
145e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian *
146e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * width and height must be either both zero or both non-zero.
147e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian *
148e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
149e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window,
150e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian        int32_t width, int32_t height, int32_t format);
151e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
152e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/**
153e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Lock the window's next drawing surface for writing.
154e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * inOutDirtyBounds is used as an in/out parameter, upon entering the
155e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * function, it contains the dirty region, that is, the region the caller
156e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * intends to redraw. When the function returns, inOutDirtyBounds is updated
157e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * with the actual area the caller needs to redraw -- this region is often
158e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * extended by ANativeWindow_lock.
159e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
160e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer,
161e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian        ARect* inOutDirtyBounds);
162e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
163e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian/**
164e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * Unlock the window's drawing surface after previously locking it,
165e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian * posting the new buffer to the display.
166e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian */
167e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopianint32_t ANativeWindow_unlockAndPost(ANativeWindow* window);
168e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
16909932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall#if __ANDROID_API__ >= __ANDROID_API_O__
17009932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall
17109932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall/**
17209932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall * Set a transform that will be applied to future buffers posted to the window.
17309932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall *
17409932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall * @param transform combination of {@link ANativeWindowTransform} flags
17509932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall * @return 0 if successful
17609932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall * @return -EINVAL if @param transform is invalid
17709932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall */
17809932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hallint32_t ANativeWindow_setBuffersTransform(ANativeWindow* window, int32_t transform);
17909932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall
18009932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall#endif // __ANDROID_API__ >= __ANDROID_API_O__
18109932eceb2fcec029edc6aaa0e2bca0591613281Jesse Hall
182e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#ifdef __cplusplus
183e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian};
184e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#endif
185e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian
186e1c61d3cc8458ce9a15d8109f728e60f5248939dMathias Agopian#endif // ANDROID_NATIVE_WINDOW_H
187bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine
188bf6d5e012cd9b15568c2351831f3349cf564bf18Johan Euphrosine/** @} */
189