blob: 3bc7979ca8109b12a3e441ae733131ad5f1f4c7b [file] [log] [blame]
The Android Open Source Project89fa4ad2009-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
Mathias Agopian348514d2009-06-04 23:29:29 -070023#include <utils/Debug.h>
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080024#include <utils/threads.h>
25
26namespace android {
27
28/*
29 * These structures are shared between the composer process and its clients
30 */
31
32// ---------------------------------------------------------------------------
33
34struct surface_info_t { // 4 longs, 16 bytes
35 enum {
Mathias Agopianb1514c92009-04-10 14:24:30 -070036 eBufferDirty = 0x01,
37 eNeedNewBuffer = 0x02
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080038 };
Mathias Agopianb1514c92009-04-10 14:24:30 -070039 uint8_t reserved[11];
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080040 uint8_t flags;
Mathias Agopianb1514c92009-04-10 14:24:30 -070041 status_t status;
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -080042};
43
44// ---------------------------------------------------------------------------
45
46const uint32_t NUM_LAYERS_MAX = 31;
47
48enum { // layer_cblk_t swapState
49 eIndex = 0x00000001,
50 eFlipRequested = 0x00000002,
51
52 eResizeBuffer0 = 0x00000004,
53 eResizeBuffer1 = 0x00000008,
54 eResizeRequested = eResizeBuffer0 | eResizeBuffer1,
55
56 eBusy = 0x00000010,
57 eLocked = 0x00000020,
58 eNextFlipPending = 0x00000040,
59 eInvalidSurface = 0x00000080
60};
61
62enum { // layer_cblk_t flags
63 eLayerNotPosted = 0x00000001,
64 eNoCopyBack = 0x00000002,
65 eReserved = 0x0000007C,
66 eBufferIndexShift = 7,
67 eBufferIndex = 1<<eBufferIndexShift,
68};
69
70struct flat_region_t // 40 bytes
71{
72 int32_t count;
73 int16_t l;
74 int16_t t;
75 int16_t r;
76 int16_t b;
77 uint16_t runs[14];
78};
79
80struct layer_cblk_t // (128 bytes)
81{
82 volatile int32_t swapState; // 4
83 volatile int32_t flags; // 4
84 volatile int32_t identity; // 4
85 int32_t reserved; // 4
86 surface_info_t surface[2]; // 32
87 flat_region_t region[2]; // 80
88
89 static inline int backBuffer(uint32_t state) {
90 return ((state & eIndex) ^ ((state & eFlipRequested)>>1));
91 }
92 static inline int frontBuffer(uint32_t state) {
93 return 1 - backBuffer(state);
94 }
95};
96
97// ---------------------------------------------------------------------------
98
99struct per_client_cblk_t // 4KB max
100{
101 Mutex lock;
102 Condition cv;
103 layer_cblk_t layers[NUM_LAYERS_MAX] __attribute__((aligned(32)));
104
105 enum {
106 BLOCKING = 0x00000001,
107 INSPECT = 0x00000002
108 };
109
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800110 // these functions are used by the clients
111 status_t validate(size_t i) const;
112 int32_t lock_layer(size_t i, uint32_t flags);
113 uint32_t unlock_layer_and_post(size_t i);
114 void unlock_layer(size_t i);
115};
116// ---------------------------------------------------------------------------
117
118const uint32_t NUM_DISPLAY_MAX = 4;
119
120struct display_cblk_t
121{
122 uint16_t w;
123 uint16_t h;
124 uint8_t format;
125 uint8_t orientation;
126 uint8_t reserved[2];
127 float fps;
128 float density;
129 float xdpi;
130 float ydpi;
131 uint32_t pad[2];
132};
133
134struct surface_flinger_cblk_t // 4KB max
135{
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800136 uint8_t connected;
137 uint8_t reserved[3];
138 uint32_t pad[7];
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800139 display_cblk_t displays[NUM_DISPLAY_MAX];
140};
141
142// ---------------------------------------------------------------------------
143
Mathias Agopian348514d2009-06-04 23:29:29 -0700144COMPILE_TIME_ASSERT(sizeof(layer_cblk_t) == 128)
145COMPILE_TIME_ASSERT(sizeof(per_client_cblk_t) <= 4096)
146COMPILE_TIME_ASSERT(sizeof(surface_flinger_cblk_t) <= 4096)
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800147
Mathias Agopian348514d2009-06-04 23:29:29 -0700148// ---------------------------------------------------------------------------
The Android Open Source Project89fa4ad2009-03-03 19:31:44 -0800149}; // namespace android
150
151#endif // ANDROID_UI_SHARED_STATE_H
152