The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Agopian | 0c97ed3 | 2009-06-04 23:29:29 -0700 | [diff] [blame] | 23 | #include <utils/Debug.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <utils/threads.h> |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | /* |
| 29 | * These structures are shared between the composer process and its clients |
| 30 | */ |
| 31 | |
| 32 | // --------------------------------------------------------------------------- |
| 33 | |
| 34 | struct surface_info_t { // 4 longs, 16 bytes |
| 35 | enum { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 36 | eBufferDirty = 0x01, |
| 37 | eNeedNewBuffer = 0x02 |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | }; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 39 | uint8_t reserved[11]; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | uint8_t flags; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 41 | status_t status; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | // --------------------------------------------------------------------------- |
| 45 | |
| 46 | const uint32_t NUM_LAYERS_MAX = 31; |
| 47 | |
| 48 | enum { // 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 | |
| 62 | enum { // layer_cblk_t flags |
| 63 | eLayerNotPosted = 0x00000001, |
| 64 | eNoCopyBack = 0x00000002, |
| 65 | eReserved = 0x0000007C, |
| 66 | eBufferIndexShift = 7, |
| 67 | eBufferIndex = 1<<eBufferIndexShift, |
| 68 | }; |
| 69 | |
| 70 | struct 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 | |
| 80 | struct 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 | |
| 99 | struct per_client_cblk_t // 4KB max |
| 100 | { |
Mathias Agopian | eb9fd68 | 2009-07-13 21:59:37 -0700 | [diff] [blame] | 101 | per_client_cblk_t() : lock(Mutex::SHARED) { } |
| 102 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | // 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 | |
| 120 | const uint32_t NUM_DISPLAY_MAX = 4; |
| 121 | |
| 122 | struct 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 | |
| 136 | struct surface_flinger_cblk_t // 4KB max |
| 137 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | uint8_t connected; |
| 139 | uint8_t reserved[3]; |
| 140 | uint32_t pad[7]; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | display_cblk_t displays[NUM_DISPLAY_MAX]; |
| 142 | }; |
| 143 | |
| 144 | // --------------------------------------------------------------------------- |
| 145 | |
Mathias Agopian | 0c97ed3 | 2009-06-04 23:29:29 -0700 | [diff] [blame] | 146 | COMPILE_TIME_ASSERT(sizeof(layer_cblk_t) == 128) |
| 147 | COMPILE_TIME_ASSERT(sizeof(per_client_cblk_t) <= 4096) |
| 148 | COMPILE_TIME_ASSERT(sizeof(surface_flinger_cblk_t) <= 4096) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 149 | |
Mathias Agopian | 0c97ed3 | 2009-06-04 23:29:29 -0700 | [diff] [blame] | 150 | // --------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | }; // namespace android |
| 152 | |
| 153 | #endif // ANDROID_UI_SHARED_STATE_H |
| 154 | |