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