blob: c9f6b5edb9ab45e6288b4880643f64553ebdf319 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-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 Agopian0c97ed32009-06-04 23:29:29 -070023#include <utils/Debug.h>
The Android Open Source Projectedbf3b62009-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 Agopian076b1cc2009-04-10 14:24:30 -070036 eBufferDirty = 0x01,
37 eNeedNewBuffer = 0x02
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038 };
Mathias Agopian076b1cc2009-04-10 14:24:30 -070039 uint8_t reserved[11];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040 uint8_t flags;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070041 status_t status;
The Android Open Source Projectedbf3b62009-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{
Mathias Agopianeb9fd682009-07-13 21:59:37 -0700101 per_client_cblk_t() : lock(Mutex::SHARED) { }
102
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800103 Mutex lock;
104 Condition cv;
105 layer_cblk_t layers[NUM_LAYERS_MAX] __attribute__((aligned(32)));
106
107 enum {
108 BLOCKING = 0x00000001,
109 INSPECT = 0x00000002
110 };
111
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800112 // these functions are used by the clients
113 status_t validate(size_t i) const;
114 int32_t lock_layer(size_t i, uint32_t flags);
115 uint32_t unlock_layer_and_post(size_t i);
116 void unlock_layer(size_t i);
117};
118// ---------------------------------------------------------------------------
119
120const uint32_t NUM_DISPLAY_MAX = 4;
121
122struct display_cblk_t
123{
124 uint16_t w;
125 uint16_t h;
126 uint8_t format;
127 uint8_t orientation;
128 uint8_t reserved[2];
129 float fps;
130 float density;
131 float xdpi;
132 float ydpi;
133 uint32_t pad[2];
134};
135
136struct surface_flinger_cblk_t // 4KB max
137{
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800138 uint8_t connected;
139 uint8_t reserved[3];
140 uint32_t pad[7];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800141 display_cblk_t displays[NUM_DISPLAY_MAX];
142};
143
144// ---------------------------------------------------------------------------
145
Mathias Agopian0c97ed32009-06-04 23:29:29 -0700146COMPILE_TIME_ASSERT(sizeof(layer_cblk_t) == 128)
147COMPILE_TIME_ASSERT(sizeof(per_client_cblk_t) <= 4096)
148COMPILE_TIME_ASSERT(sizeof(surface_flinger_cblk_t) <= 4096)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800149
Mathias Agopian0c97ed32009-06-04 23:29:29 -0700150// ---------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800151}; // namespace android
152
153#endif // ANDROID_UI_SHARED_STATE_H
154