blob: 546d0adfd21ec06842ac5d187350d1854f154d82 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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#ifndef ANDROID_UI_SHARED_STATE_H
18#define ANDROID_UI_SHARED_STATE_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <utils/threads.h>
24
25namespace android {
26
27/*
28 * These structures are shared between the composer process and its clients
29 */
30
31// ---------------------------------------------------------------------------
32
33struct surface_info_t { // 4 longs, 16 bytes
34 enum {
35 eBufferDirty = 0x01
36 };
37 uint16_t w;
38 uint16_t h;
39 uint16_t stride;
40 uint16_t bpr;
41 uint16_t reserved;
42 uint8_t format;
43 uint8_t flags;
44 ssize_t bits_offset;
45};
46
47// ---------------------------------------------------------------------------
48
49const uint32_t NUM_LAYERS_MAX = 31;
50
51enum { // layer_cblk_t swapState
52 eIndex = 0x00000001,
53 eFlipRequested = 0x00000002,
54
55 eResizeBuffer0 = 0x00000004,
56 eResizeBuffer1 = 0x00000008,
57 eResizeRequested = eResizeBuffer0 | eResizeBuffer1,
58
59 eBusy = 0x00000010,
60 eLocked = 0x00000020,
61 eNextFlipPending = 0x00000040,
62 eInvalidSurface = 0x00000080
63};
64
65enum { // layer_cblk_t flags
66 eLayerNotPosted = 0x00000001,
67 eNoCopyBack = 0x00000002,
68 eReserved = 0x0000007C,
69 eBufferIndexShift = 7,
70 eBufferIndex = 1<<eBufferIndexShift,
71};
72
73struct flat_region_t // 40 bytes
74{
75 int32_t count;
76 int16_t l;
77 int16_t t;
78 int16_t r;
79 int16_t b;
80 uint16_t runs[14];
81};
82
83struct layer_cblk_t // (128 bytes)
84{
85 volatile int32_t swapState; // 4
86 volatile int32_t flags; // 4
87 volatile int32_t identity; // 4
88 int32_t reserved; // 4
89 surface_info_t surface[2]; // 32
90 flat_region_t region[2]; // 80
91
92 static inline int backBuffer(uint32_t state) {
93 return ((state & eIndex) ^ ((state & eFlipRequested)>>1));
94 }
95 static inline int frontBuffer(uint32_t state) {
96 return 1 - backBuffer(state);
97 }
98};
99
100// ---------------------------------------------------------------------------
101
102struct per_client_cblk_t // 4KB max
103{
104 Mutex lock;
105 Condition cv;
106 layer_cblk_t layers[NUM_LAYERS_MAX] __attribute__((aligned(32)));
107
108 enum {
109 BLOCKING = 0x00000001,
110 INSPECT = 0x00000002
111 };
112
113 per_client_cblk_t();
114
115 // these functions are used by the clients
116 status_t validate(size_t i) const;
117 int32_t lock_layer(size_t i, uint32_t flags);
118 uint32_t unlock_layer_and_post(size_t i);
119 void unlock_layer(size_t i);
120};
121// ---------------------------------------------------------------------------
122
123const uint32_t NUM_DISPLAY_MAX = 4;
124
125struct display_cblk_t
126{
127 uint16_t w;
128 uint16_t h;
129 uint8_t format;
130 uint8_t orientation;
131 uint8_t reserved[2];
132 float fps;
133 float density;
134 float xdpi;
135 float ydpi;
136 uint32_t pad[2];
137};
138
139struct surface_flinger_cblk_t // 4KB max
140{
141 surface_flinger_cblk_t();
142
143 uint8_t connected;
144 uint8_t reserved[3];
145 uint32_t pad[7];
146
147 display_cblk_t displays[NUM_DISPLAY_MAX];
148};
149
150// ---------------------------------------------------------------------------
151
152template<bool> struct CTA;
153template<> struct CTA<true> { };
154
155// compile-time assertions. just to avoid catastrophes.
156inline void compile_time_asserts() {
157 CTA<sizeof(layer_cblk_t) == 128> sizeof__layer_cblk_t__eq_128;
158 (void)sizeof__layer_cblk_t__eq_128; // we don't want a warning
159 CTA<sizeof(per_client_cblk_t) <= 4096> sizeof__per_client_cblk_t__le_4096;
160 (void)sizeof__per_client_cblk_t__le_4096; // we don't want a warning
161 CTA<sizeof(surface_flinger_cblk_t) <= 4096> sizeof__surface_flinger_cblk_t__le_4096;
162 (void)sizeof__surface_flinger_cblk_t__le_4096; // we don't want a warning
163}
164
165}; // namespace android
166
167#endif // ANDROID_UI_SHARED_STATE_H
168