blob: 2f4f2d33bec9f7bdfcecbf1db48f829431defa0f [file] [log] [blame]
Dianne Hackborn8b49bd12010-06-30 13:56:17 -07001/*
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
Dianne Hackborn8b49bd12010-06-30 13:56:17 -070017#ifndef ANDROID_NATIVE_WINDOW_H
18#define ANDROID_NATIVE_WINDOW_H
19
Dianne Hackborn289b9b62010-07-09 11:44:11 -070020#include <android/rect.h>
21
Dianne Hackborn8b49bd12010-06-30 13:56:17 -070022#ifdef __cplusplus
23extern "C" {
24#endif
25
Dianne Hackborn8ae5a8e2010-07-01 18:44:46 -070026/*
27 * Pixel formats that a window can use.
28 */
29enum {
30 WINDOW_FORMAT_RGBA_8888 = 1,
31 WINDOW_FORMAT_RGBX_8888 = 2,
32 WINDOW_FORMAT_RGB_565 = 4,
33};
34
Dianne Hackborn8b49bd12010-06-30 13:56:17 -070035struct ANativeWindow;
36typedef struct ANativeWindow ANativeWindow;
37
Dianne Hackborn289b9b62010-07-09 11:44:11 -070038typedef struct ANativeWindow_Buffer {
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070039 // The number of pixels that are show horizontally.
Dianne Hackborn289b9b62010-07-09 11:44:11 -070040 int32_t width;
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070041
42 // The number of pixels that are shown vertically.
Dianne Hackborn289b9b62010-07-09 11:44:11 -070043 int32_t height;
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070044
45 // The number of *pixels* that a line in the buffer takes in
46 // memory. This may be >= width.
Dianne Hackborn289b9b62010-07-09 11:44:11 -070047 int32_t stride;
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070048
49 // The format of the buffer. One of WINDOW_FORMAT_*
Dianne Hackborn289b9b62010-07-09 11:44:11 -070050 int32_t format;
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070051
52 // The actual bits.
Dianne Hackborn289b9b62010-07-09 11:44:11 -070053 void* bits;
54
Dianne Hackborn08d5b8f2010-08-04 11:12:40 -070055 // Do not touch.
Dianne Hackborn289b9b62010-07-09 11:44:11 -070056 uint32_t reserved[6];
57} ANativeWindow_Buffer;
58
59/**
60 * Acquire a reference on the given ANativeWindow object. This prevents the object
61 * from being deleted until the reference is removed.
62 */
63void ANativeWindow_acquire(ANativeWindow* window);
64
65/**
66 * Remove a reference that was previously acquired with ANativeWindow_acquire().
67 */
68void ANativeWindow_release(ANativeWindow* window);
69
Dianne Hackborn54a181b2010-06-30 18:35:14 -070070/*
71 * Return the current width in pixels of the window surface. Returns a
72 * negative value on error.
73 */
74int32_t ANativeWindow_getWidth(ANativeWindow* window);
75
76/*
77 * Return the current height in pixels of the window surface. Returns a
78 * negative value on error.
79 */
80int32_t ANativeWindow_getHeight(ANativeWindow* window);
81
82/*
83 * Return the current pixel format of the window surface. Returns a
84 * negative value on error.
85 */
86int32_t ANativeWindow_getFormat(ANativeWindow* window);
Dianne Hackborn8b49bd12010-06-30 13:56:17 -070087
Dianne Hackborn8ae5a8e2010-07-01 18:44:46 -070088/*
89 * Change the format and size of the window buffers.
90 *
91 * The width and height control the number of pixels in the buffers, not the
92 * dimensions of the window on screen. If these are different than the
93 * window's physical size, then it buffer will be scaled to match that size
94 * when compositing it to the screen.
95 *
Dianne Hackborn289b9b62010-07-09 11:44:11 -070096 * For all of these parameters, if 0 is supplied then the window's base
Dianne Hackborn8ae5a8e2010-07-01 18:44:46 -070097 * value will come back in force.
Mathias Agopianda5a4442011-03-31 20:59:58 -070098 *
99 * width and height must be either both zero or both non-zero.
100 *
Dianne Hackborn8ae5a8e2010-07-01 18:44:46 -0700101 */
Mathias Agopian949be322011-07-13 17:39:11 -0700102int32_t ANativeWindow_setBuffersGeometry(ANativeWindow* window,
103 int32_t width, int32_t height, int32_t format);
Dianne Hackborn289b9b62010-07-09 11:44:11 -0700104
105/**
106 * Lock the window's next drawing surface for writing.
Mathias Agopian949be322011-07-13 17:39:11 -0700107 * inOutDirtyBounds is used as an in/out parameter, upon entering the
108 * function, it contains the dirty region, that is, the region the caller
109 * intends to redraw. When the function returns, inOutDirtyBounds is updated
110 * with the actual area the caller needs to redraw -- this region is often
111 * extended by ANativeWindow_lock.
Dianne Hackborn289b9b62010-07-09 11:44:11 -0700112 */
113int32_t ANativeWindow_lock(ANativeWindow* window, ANativeWindow_Buffer* outBuffer,
114 ARect* inOutDirtyBounds);
115
116/**
117 * Unlock the window's drawing surface after previously locking it,
118 * posting the new buffer to the display.
119 */
120int32_t ANativeWindow_unlockAndPost(ANativeWindow* window);
Dianne Hackborn8ae5a8e2010-07-01 18:44:46 -0700121
Dianne Hackborn8b49bd12010-06-30 13:56:17 -0700122#ifdef __cplusplus
123};
124#endif
125
126#endif // ANDROID_NATIVE_WINDOW_H