| 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 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 17 | #include <stdlib.h> | 
|  | 18 | #include <stdio.h> | 
|  | 19 | #include <stdint.h> | 
|  | 20 | #include <unistd.h> | 
|  | 21 | #include <fcntl.h> | 
|  | 22 | #include <errno.h> | 
|  | 23 | #include <math.h> | 
| Jean-Baptiste Queru | a837ba7 | 2009-01-26 11:51:12 -0800 | [diff] [blame] | 24 | #include <limits.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <sys/types.h> | 
|  | 26 | #include <sys/stat.h> | 
|  | 27 | #include <sys/ioctl.h> | 
|  | 28 |  | 
|  | 29 | #include <cutils/log.h> | 
|  | 30 | #include <cutils/properties.h> | 
|  | 31 |  | 
| Mathias Agopian | c5b2c0b | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 32 | #include <binder/IPCThreadState.h> | 
|  | 33 | #include <binder/IServiceManager.h> | 
| Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 34 | #include <binder/MemoryHeapBase.h> | 
|  | 35 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | #include <utils/String8.h> | 
|  | 37 | #include <utils/String16.h> | 
|  | 38 | #include <utils/StopWatch.h> | 
|  | 39 |  | 
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 40 | #include <ui/GraphicBufferAllocator.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | #include <ui/PixelFormat.h> | 
|  | 42 | #include <ui/DisplayInfo.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 |  | 
|  | 44 | #include <pixelflinger/pixelflinger.h> | 
|  | 45 | #include <GLES/gl.h> | 
|  | 46 |  | 
|  | 47 | #include "clz.h" | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | #include "Layer.h" | 
|  | 49 | #include "LayerBlur.h" | 
|  | 50 | #include "LayerBuffer.h" | 
|  | 51 | #include "LayerDim.h" | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | #include "SurfaceFlinger.h" | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 |  | 
|  | 54 | #include "DisplayHardware/DisplayHardware.h" | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 |  | 
| Mathias Agopian | a1ecca9 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 56 | /* ideally AID_GRAPHICS would be in a semi-public header | 
|  | 57 | * or there would be a way to map a user/group name to its id | 
|  | 58 | */ | 
|  | 59 | #ifndef AID_GRAPHICS | 
|  | 60 | #define AID_GRAPHICS 1003 | 
|  | 61 | #endif | 
|  | 62 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | #define DISPLAY_COUNT       1 | 
|  | 64 |  | 
|  | 65 | namespace android { | 
|  | 66 |  | 
|  | 67 | // --------------------------------------------------------------------------- | 
|  | 68 |  | 
|  | 69 | void SurfaceFlinger::instantiate() { | 
|  | 70 | defaultServiceManager()->addService( | 
|  | 71 | String16("SurfaceFlinger"), new SurfaceFlinger()); | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | void SurfaceFlinger::shutdown() { | 
|  | 75 | // we should unregister here, but not really because | 
|  | 76 | // when (if) the service manager goes away, all the services | 
|  | 77 | // it has a reference to will leave too. | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | // --------------------------------------------------------------------------- | 
|  | 81 |  | 
|  | 82 | SurfaceFlinger::LayerVector::LayerVector(const SurfaceFlinger::LayerVector& rhs) | 
|  | 83 | : lookup(rhs.lookup), layers(rhs.layers) | 
|  | 84 | { | 
|  | 85 | } | 
|  | 86 |  | 
|  | 87 | ssize_t SurfaceFlinger::LayerVector::indexOf( | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 88 | const sp<LayerBase>& key, size_t guess) const | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | { | 
|  | 90 | if (guess<size() && lookup.keyAt(guess) == key) | 
|  | 91 | return guess; | 
|  | 92 | const ssize_t i = lookup.indexOfKey(key); | 
|  | 93 | if (i>=0) { | 
|  | 94 | const size_t idx = lookup.valueAt(i); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 95 | LOGE_IF(layers[idx]!=key, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | "LayerVector[%p]: layers[%d]=%p, key=%p", | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 97 | this, int(idx), layers[idx].get(), key.get()); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | return idx; | 
|  | 99 | } | 
|  | 100 | return i; | 
|  | 101 | } | 
|  | 102 |  | 
|  | 103 | ssize_t SurfaceFlinger::LayerVector::add( | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 104 | const sp<LayerBase>& layer, | 
|  | 105 | Vector< sp<LayerBase> >::compar_t cmp) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | { | 
|  | 107 | size_t count = layers.size(); | 
|  | 108 | ssize_t l = 0; | 
|  | 109 | ssize_t h = count-1; | 
|  | 110 | ssize_t mid; | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 111 | sp<LayerBase> const* a = layers.array(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | while (l <= h) { | 
|  | 113 | mid = l + (h - l)/2; | 
|  | 114 | const int c = cmp(a+mid, &layer); | 
|  | 115 | if (c == 0)     { l = mid; break; } | 
|  | 116 | else if (c<0)   { l = mid+1; } | 
|  | 117 | else            { h = mid-1; } | 
|  | 118 | } | 
|  | 119 | size_t order = l; | 
|  | 120 | while (order<count && !cmp(&layer, a+order)) { | 
|  | 121 | order++; | 
|  | 122 | } | 
|  | 123 | count = lookup.size(); | 
|  | 124 | for (size_t i=0 ; i<count ; i++) { | 
|  | 125 | if (lookup.valueAt(i) >= order) { | 
|  | 126 | lookup.editValueAt(i)++; | 
|  | 127 | } | 
|  | 128 | } | 
|  | 129 | layers.insertAt(layer, order); | 
|  | 130 | lookup.add(layer, order); | 
|  | 131 | return order; | 
|  | 132 | } | 
|  | 133 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 134 | ssize_t SurfaceFlinger::LayerVector::remove(const sp<LayerBase>& layer) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | { | 
|  | 136 | const ssize_t keyIndex = lookup.indexOfKey(layer); | 
|  | 137 | if (keyIndex >= 0) { | 
|  | 138 | const size_t index = lookup.valueAt(keyIndex); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 139 | LOGE_IF(layers[index]!=layer, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | "LayerVector[%p]: layers[%u]=%p, layer=%p", | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 141 | this, int(index), layers[index].get(), layer.get()); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | layers.removeItemsAt(index); | 
|  | 143 | lookup.removeItemsAt(keyIndex); | 
|  | 144 | const size_t count = lookup.size(); | 
|  | 145 | for (size_t i=0 ; i<count ; i++) { | 
|  | 146 | if (lookup.valueAt(i) >= size_t(index)) { | 
|  | 147 | lookup.editValueAt(i)--; | 
|  | 148 | } | 
|  | 149 | } | 
|  | 150 | return index; | 
|  | 151 | } | 
|  | 152 | return NAME_NOT_FOUND; | 
|  | 153 | } | 
|  | 154 |  | 
|  | 155 | ssize_t SurfaceFlinger::LayerVector::reorder( | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 156 | const sp<LayerBase>& layer, | 
|  | 157 | Vector< sp<LayerBase> >::compar_t cmp) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | { | 
|  | 159 | // XXX: it's a little lame. but oh well... | 
|  | 160 | ssize_t err = remove(layer); | 
|  | 161 | if (err >=0) | 
|  | 162 | err = add(layer, cmp); | 
|  | 163 | return err; | 
|  | 164 | } | 
|  | 165 |  | 
|  | 166 | // --------------------------------------------------------------------------- | 
|  | 167 | #if 0 | 
|  | 168 | #pragma mark - | 
|  | 169 | #endif | 
|  | 170 |  | 
|  | 171 | SurfaceFlinger::SurfaceFlinger() | 
|  | 172 | :   BnSurfaceComposer(), Thread(false), | 
|  | 173 | mTransactionFlags(0), | 
|  | 174 | mTransactionCount(0), | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 175 | mResizeTransationPending(false), | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 176 | mLayersRemoved(false), | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | mBootTime(systemTime()), | 
| Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 178 | mHardwareTest("android.permission.HARDWARE_TEST"), | 
|  | 179 | mAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"), | 
|  | 180 | mDump("android.permission.DUMP"), | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | mVisibleRegionsDirty(false), | 
|  | 182 | mDeferReleaseConsole(false), | 
|  | 183 | mFreezeDisplay(false), | 
|  | 184 | mFreezeCount(0), | 
| The Android Open Source Project | bcef13b | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 185 | mFreezeDisplayTime(0), | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | mDebugRegion(0), | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | mDebugBackground(0), | 
| Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 188 | mDebugInSwapBuffers(0), | 
|  | 189 | mLastSwapBufferTime(0), | 
|  | 190 | mDebugInTransaction(0), | 
|  | 191 | mLastTransactionTime(0), | 
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 192 | mBootFinished(false), | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 193 | mConsoleSignals(0), | 
|  | 194 | mSecureFrameBuffer(0) | 
|  | 195 | { | 
|  | 196 | init(); | 
|  | 197 | } | 
|  | 198 |  | 
|  | 199 | void SurfaceFlinger::init() | 
|  | 200 | { | 
|  | 201 | LOGI("SurfaceFlinger is starting"); | 
|  | 202 |  | 
|  | 203 | // debugging stuff... | 
|  | 204 | char value[PROPERTY_VALUE_MAX]; | 
|  | 205 | property_get("debug.sf.showupdates", value, "0"); | 
|  | 206 | mDebugRegion = atoi(value); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 207 | property_get("debug.sf.showbackground", value, "0"); | 
|  | 208 | mDebugBackground = atoi(value); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 |  | 
|  | 210 | LOGI_IF(mDebugRegion,           "showupdates enabled"); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | LOGI_IF(mDebugBackground,       "showbackground enabled"); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | } | 
|  | 213 |  | 
|  | 214 | SurfaceFlinger::~SurfaceFlinger() | 
|  | 215 | { | 
|  | 216 | glDeleteTextures(1, &mWormholeTexName); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | } | 
|  | 218 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | overlay_control_device_t* SurfaceFlinger::getOverlayEngine() const | 
|  | 220 | { | 
|  | 221 | return graphicPlane(0).displayHardware().getOverlayEngine(); | 
|  | 222 | } | 
|  | 223 |  | 
| Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 224 | sp<IMemoryHeap> SurfaceFlinger::getCblk() const | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 225 | { | 
| Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 226 | return mServerHeap; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 227 | } | 
|  | 228 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | sp<ISurfaceFlingerClient> SurfaceFlinger::createConnection() | 
|  | 230 | { | 
|  | 231 | Mutex::Autolock _l(mStateLock); | 
|  | 232 | uint32_t token = mTokens.acquire(); | 
|  | 233 |  | 
| Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 234 | sp<Client> client = new Client(token, this); | 
|  | 235 | if (client->ctrlblk == 0) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | mTokens.release(token); | 
|  | 237 | return 0; | 
|  | 238 | } | 
|  | 239 | status_t err = mClientsMap.add(token, client); | 
|  | 240 | if (err < 0) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 241 | mTokens.release(token); | 
|  | 242 | return 0; | 
|  | 243 | } | 
|  | 244 | sp<BClient> bclient = | 
| Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 245 | new BClient(this, token, client->getControlBlockMemory()); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 246 | return bclient; | 
|  | 247 | } | 
|  | 248 |  | 
|  | 249 | void SurfaceFlinger::destroyConnection(ClientID cid) | 
|  | 250 | { | 
|  | 251 | Mutex::Autolock _l(mStateLock); | 
| Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 252 | sp<Client> client = mClientsMap.valueFor(cid); | 
|  | 253 | if (client != 0) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | // free all the layers this client owns | 
| Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 255 | Vector< wp<LayerBaseClient> > layers(client->getLayers()); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | const size_t count = layers.size(); | 
|  | 257 | for (size_t i=0 ; i<count ; i++) { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 258 | sp<LayerBaseClient> layer(layers[i].promote()); | 
|  | 259 | if (layer != 0) { | 
| Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 260 | purgatorizeLayer_l(layer); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 261 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 262 | } | 
|  | 263 |  | 
|  | 264 | // the resources associated with this client will be freed | 
|  | 265 | // during the next transaction, after these surfaces have been | 
|  | 266 | // properly removed from the screen | 
|  | 267 |  | 
|  | 268 | // remove this client from our ClientID->Client mapping. | 
|  | 269 | mClientsMap.removeItem(cid); | 
|  | 270 |  | 
|  | 271 | // and add it to the list of disconnected clients | 
|  | 272 | mDisconnectedClients.add(client); | 
|  | 273 |  | 
|  | 274 | // request a transaction | 
|  | 275 | setTransactionFlags(eTransactionNeeded); | 
|  | 276 | } | 
|  | 277 | } | 
|  | 278 |  | 
|  | 279 | const GraphicPlane& SurfaceFlinger::graphicPlane(int dpy) const | 
|  | 280 | { | 
|  | 281 | LOGE_IF(uint32_t(dpy) >= DISPLAY_COUNT, "Invalid DisplayID %d", dpy); | 
|  | 282 | const GraphicPlane& plane(mGraphicPlanes[dpy]); | 
|  | 283 | return plane; | 
|  | 284 | } | 
|  | 285 |  | 
|  | 286 | GraphicPlane& SurfaceFlinger::graphicPlane(int dpy) | 
|  | 287 | { | 
|  | 288 | return const_cast<GraphicPlane&>( | 
|  | 289 | const_cast<SurfaceFlinger const *>(this)->graphicPlane(dpy)); | 
|  | 290 | } | 
|  | 291 |  | 
|  | 292 | void SurfaceFlinger::bootFinished() | 
|  | 293 | { | 
|  | 294 | const nsecs_t now = systemTime(); | 
|  | 295 | const nsecs_t duration = now - mBootTime; | 
| Mathias Agopian | a1ecca9 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 296 | LOGI("Boot is finished (%ld ms)", long(ns2ms(duration)) ); | 
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 297 | mBootFinished = true; | 
| Mathias Agopian | a1ecca9 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 298 | property_set("ctl.stop", "bootanim"); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | } | 
|  | 300 |  | 
|  | 301 | void SurfaceFlinger::onFirstRef() | 
|  | 302 | { | 
|  | 303 | run("SurfaceFlinger", PRIORITY_URGENT_DISPLAY); | 
|  | 304 |  | 
|  | 305 | // Wait for the main thread to be done with its initialization | 
|  | 306 | mReadyToRunBarrier.wait(); | 
|  | 307 | } | 
|  | 308 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 309 | static inline uint16_t pack565(int r, int g, int b) { | 
|  | 310 | return (r<<11)|(g<<5)|b; | 
|  | 311 | } | 
|  | 312 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | status_t SurfaceFlinger::readyToRun() | 
|  | 314 | { | 
|  | 315 | LOGI(   "SurfaceFlinger's main thread ready to run. " | 
|  | 316 | "Initializing graphics H/W..."); | 
|  | 317 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 318 | // we only support one display currently | 
|  | 319 | int dpy = 0; | 
|  | 320 |  | 
|  | 321 | { | 
|  | 322 | // initialize the main display | 
|  | 323 | GraphicPlane& plane(graphicPlane(dpy)); | 
|  | 324 | DisplayHardware* const hw = new DisplayHardware(this, dpy); | 
|  | 325 | plane.setDisplayHardware(hw); | 
|  | 326 | } | 
|  | 327 |  | 
| Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 328 | // create the shared control-block | 
|  | 329 | mServerHeap = new MemoryHeapBase(4096, | 
|  | 330 | MemoryHeapBase::READ_ONLY, "SurfaceFlinger read-only heap"); | 
|  | 331 | LOGE_IF(mServerHeap==0, "can't create shared memory dealer"); | 
|  | 332 |  | 
|  | 333 | mServerCblk = static_cast<surface_flinger_cblk_t*>(mServerHeap->getBase()); | 
|  | 334 | LOGE_IF(mServerCblk==0, "can't get to shared control block's address"); | 
|  | 335 |  | 
|  | 336 | new(mServerCblk) surface_flinger_cblk_t; | 
|  | 337 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | // initialize primary screen | 
|  | 339 | // (other display should be initialized in the same manner, but | 
|  | 340 | // asynchronously, as they could come and go. None of this is supported | 
|  | 341 | // yet). | 
|  | 342 | const GraphicPlane& plane(graphicPlane(dpy)); | 
|  | 343 | const DisplayHardware& hw = plane.displayHardware(); | 
|  | 344 | const uint32_t w = hw.getWidth(); | 
|  | 345 | const uint32_t h = hw.getHeight(); | 
|  | 346 | const uint32_t f = hw.getFormat(); | 
|  | 347 | hw.makeCurrent(); | 
|  | 348 |  | 
|  | 349 | // initialize the shared control block | 
|  | 350 | mServerCblk->connected |= 1<<dpy; | 
|  | 351 | display_cblk_t* dcblk = mServerCblk->displays + dpy; | 
|  | 352 | memset(dcblk, 0, sizeof(display_cblk_t)); | 
|  | 353 | dcblk->w            = w; | 
|  | 354 | dcblk->h            = h; | 
|  | 355 | dcblk->format       = f; | 
|  | 356 | dcblk->orientation  = ISurfaceComposer::eOrientationDefault; | 
|  | 357 | dcblk->xdpi         = hw.getDpiX(); | 
|  | 358 | dcblk->ydpi         = hw.getDpiY(); | 
|  | 359 | dcblk->fps          = hw.getRefreshRate(); | 
|  | 360 | dcblk->density      = hw.getDensity(); | 
|  | 361 | asm volatile ("":::"memory"); | 
|  | 362 |  | 
|  | 363 | // Initialize OpenGL|ES | 
|  | 364 | glActiveTexture(GL_TEXTURE0); | 
|  | 365 | glBindTexture(GL_TEXTURE_2D, 0); | 
|  | 366 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | 
|  | 367 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); | 
|  | 368 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 
|  | 369 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 
|  | 370 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); | 
|  | 371 | glPixelStorei(GL_UNPACK_ALIGNMENT, 4); | 
|  | 372 | glPixelStorei(GL_PACK_ALIGNMENT, 4); | 
|  | 373 | glEnableClientState(GL_VERTEX_ARRAY); | 
|  | 374 | glEnable(GL_SCISSOR_TEST); | 
|  | 375 | glShadeModel(GL_FLAT); | 
|  | 376 | glDisable(GL_DITHER); | 
|  | 377 | glDisable(GL_CULL_FACE); | 
|  | 378 |  | 
|  | 379 | const uint16_t g0 = pack565(0x0F,0x1F,0x0F); | 
|  | 380 | const uint16_t g1 = pack565(0x17,0x2f,0x17); | 
|  | 381 | const uint16_t textureData[4] = { g0, g1, g1, g0 }; | 
|  | 382 | glGenTextures(1, &mWormholeTexName); | 
|  | 383 | glBindTexture(GL_TEXTURE_2D, mWormholeTexName); | 
|  | 384 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 
|  | 385 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 
|  | 386 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); | 
|  | 387 | glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); | 
|  | 388 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, | 
|  | 389 | GL_RGB, GL_UNSIGNED_SHORT_5_6_5, textureData); | 
|  | 390 |  | 
|  | 391 | glViewport(0, 0, w, h); | 
|  | 392 | glMatrixMode(GL_PROJECTION); | 
|  | 393 | glLoadIdentity(); | 
|  | 394 | glOrthof(0, w, h, 0, 0, 1); | 
|  | 395 |  | 
|  | 396 | LayerDim::initDimmer(this, w, h); | 
|  | 397 |  | 
|  | 398 | mReadyToRunBarrier.open(); | 
|  | 399 |  | 
|  | 400 | /* | 
|  | 401 | *  We're now ready to accept clients... | 
|  | 402 | */ | 
|  | 403 |  | 
| Mathias Agopian | a1ecca9 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 404 | // start boot animation | 
|  | 405 | property_set("ctl.start", "bootanim"); | 
|  | 406 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 407 | return NO_ERROR; | 
|  | 408 | } | 
|  | 409 |  | 
|  | 410 | // ---------------------------------------------------------------------------- | 
|  | 411 | #if 0 | 
|  | 412 | #pragma mark - | 
|  | 413 | #pragma mark Events Handler | 
|  | 414 | #endif | 
|  | 415 |  | 
|  | 416 | void SurfaceFlinger::waitForEvent() | 
|  | 417 | { | 
| Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 418 | while (true) { | 
|  | 419 | nsecs_t timeout = -1; | 
| Mathias Agopian | 0408772 | 2009-12-01 17:23:28 -0800 | [diff] [blame] | 420 | const nsecs_t freezeDisplayTimeout = ms2ns(5000); | 
| Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 421 | if (UNLIKELY(isFrozen())) { | 
|  | 422 | // wait 5 seconds | 
| Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 423 | const nsecs_t now = systemTime(); | 
|  | 424 | if (mFreezeDisplayTime == 0) { | 
|  | 425 | mFreezeDisplayTime = now; | 
|  | 426 | } | 
|  | 427 | nsecs_t waitTime = freezeDisplayTimeout - (now - mFreezeDisplayTime); | 
|  | 428 | timeout = waitTime>0 ? waitTime : 0; | 
| The Android Open Source Project | bcef13b | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 429 | } | 
| Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 430 |  | 
| Mathias Agopian | b6683b5 | 2009-04-28 03:17:50 -0700 | [diff] [blame] | 431 | MessageList::value_type msg = mEventQueue.waitMessage(timeout); | 
| Mathias Agopian | 0408772 | 2009-12-01 17:23:28 -0800 | [diff] [blame] | 432 |  | 
|  | 433 | // see if we timed out | 
|  | 434 | if (isFrozen()) { | 
|  | 435 | const nsecs_t now = systemTime(); | 
|  | 436 | nsecs_t frozenTime = (now - mFreezeDisplayTime); | 
|  | 437 | if (frozenTime >= freezeDisplayTimeout) { | 
|  | 438 | // we timed out and are still frozen | 
|  | 439 | LOGW("timeout expired mFreezeDisplay=%d, mFreezeCount=%d", | 
|  | 440 | mFreezeDisplay, mFreezeCount); | 
|  | 441 | mFreezeDisplayTime = 0; | 
|  | 442 | mFreezeCount = 0; | 
|  | 443 | mFreezeDisplay = false; | 
|  | 444 | } | 
|  | 445 | } | 
|  | 446 |  | 
| Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 447 | if (msg != 0) { | 
| Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 448 | switch (msg->what) { | 
|  | 449 | case MessageQueue::INVALIDATE: | 
|  | 450 | // invalidate message, just return to the main loop | 
|  | 451 | return; | 
|  | 452 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | } | 
|  | 455 | } | 
|  | 456 |  | 
|  | 457 | void SurfaceFlinger::signalEvent() { | 
| Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 458 | mEventQueue.invalidate(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | } | 
|  | 460 |  | 
|  | 461 | void SurfaceFlinger::signal() const { | 
| Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 462 | // this is the IPC call | 
|  | 463 | const_cast<SurfaceFlinger*>(this)->signalEvent(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 464 | } | 
|  | 465 |  | 
|  | 466 | void SurfaceFlinger::signalDelayedEvent(nsecs_t delay) | 
|  | 467 | { | 
| Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 468 | mEventQueue.postMessage( new MessageBase(MessageQueue::INVALIDATE), delay); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 469 | } | 
|  | 470 |  | 
|  | 471 | // ---------------------------------------------------------------------------- | 
|  | 472 | #if 0 | 
|  | 473 | #pragma mark - | 
|  | 474 | #pragma mark Main loop | 
|  | 475 | #endif | 
|  | 476 |  | 
|  | 477 | bool SurfaceFlinger::threadLoop() | 
|  | 478 | { | 
|  | 479 | waitForEvent(); | 
|  | 480 |  | 
|  | 481 | // check for transactions | 
|  | 482 | if (UNLIKELY(mConsoleSignals)) { | 
|  | 483 | handleConsoleEvents(); | 
|  | 484 | } | 
|  | 485 |  | 
|  | 486 | if (LIKELY(mTransactionCount == 0)) { | 
|  | 487 | // if we're in a global transaction, don't do anything. | 
|  | 488 | const uint32_t mask = eTransactionNeeded | eTraversalNeeded; | 
|  | 489 | uint32_t transactionFlags = getTransactionFlags(mask); | 
|  | 490 | if (LIKELY(transactionFlags)) { | 
|  | 491 | handleTransaction(transactionFlags); | 
|  | 492 | } | 
|  | 493 | } | 
|  | 494 |  | 
|  | 495 | // post surfaces (if needed) | 
|  | 496 | handlePageFlip(); | 
|  | 497 |  | 
|  | 498 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); | 
| Mathias Agopian | 8a77baa | 2009-09-27 22:47:27 -0700 | [diff] [blame] | 499 | if (LIKELY(hw.canDraw() && !isFrozen())) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | // repaint the framebuffer (if needed) | 
|  | 501 | handleRepaint(); | 
|  | 502 |  | 
| Mathias Agopian | 74faca2 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 503 | // inform the h/w that we're done compositing | 
|  | 504 | hw.compositionComplete(); | 
|  | 505 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 506 | // release the clients before we flip ('cause flip might block) | 
|  | 507 | unlockClients(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 508 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 509 | postFramebuffer(); | 
|  | 510 | } else { | 
|  | 511 | // pretend we did the post | 
|  | 512 | unlockClients(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | usleep(16667); // 60 fps period | 
|  | 514 | } | 
|  | 515 | return true; | 
|  | 516 | } | 
|  | 517 |  | 
|  | 518 | void SurfaceFlinger::postFramebuffer() | 
|  | 519 | { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 520 | if (!mInvalidRegion.isEmpty()) { | 
|  | 521 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); | 
| Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 522 | const nsecs_t now = systemTime(); | 
|  | 523 | mDebugInSwapBuffers = now; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 524 | hw.flip(mInvalidRegion); | 
| Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 525 | mLastSwapBufferTime = systemTime() - now; | 
|  | 526 | mDebugInSwapBuffers = 0; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 527 | mInvalidRegion.clear(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 528 | } | 
|  | 529 | } | 
|  | 530 |  | 
|  | 531 | void SurfaceFlinger::handleConsoleEvents() | 
|  | 532 | { | 
|  | 533 | // something to do with the console | 
|  | 534 | const DisplayHardware& hw = graphicPlane(0).displayHardware(); | 
|  | 535 |  | 
|  | 536 | int what = android_atomic_and(0, &mConsoleSignals); | 
|  | 537 | if (what & eConsoleAcquired) { | 
|  | 538 | hw.acquireScreen(); | 
|  | 539 | } | 
|  | 540 |  | 
|  | 541 | if (mDeferReleaseConsole && hw.canDraw()) { | 
| Mathias Agopian | 62b7444 | 2009-04-14 23:02:51 -0700 | [diff] [blame] | 542 | // We got the release signal before the acquire signal | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 543 | mDeferReleaseConsole = false; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 544 | hw.releaseScreen(); | 
|  | 545 | } | 
|  | 546 |  | 
|  | 547 | if (what & eConsoleReleased) { | 
|  | 548 | if (hw.canDraw()) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 549 | hw.releaseScreen(); | 
|  | 550 | } else { | 
|  | 551 | mDeferReleaseConsole = true; | 
|  | 552 | } | 
|  | 553 | } | 
|  | 554 |  | 
|  | 555 | mDirtyRegion.set(hw.bounds()); | 
|  | 556 | } | 
|  | 557 |  | 
|  | 558 | void SurfaceFlinger::handleTransaction(uint32_t transactionFlags) | 
|  | 559 | { | 
| Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 560 | Vector< sp<LayerBase> > ditchedLayers; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 |  | 
| Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 562 | { // scope for the lock | 
|  | 563 | Mutex::Autolock _l(mStateLock); | 
| Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 564 | const nsecs_t now = systemTime(); | 
|  | 565 | mDebugInTransaction = now; | 
| Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 566 | handleTransactionLocked(transactionFlags, ditchedLayers); | 
| Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 567 | mLastTransactionTime = systemTime() - now; | 
|  | 568 | mDebugInTransaction = 0; | 
| Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 569 | } | 
|  | 570 |  | 
|  | 571 | // do this without lock held | 
|  | 572 | const size_t count = ditchedLayers.size(); | 
|  | 573 | for (size_t i=0 ; i<count ; i++) { | 
| Mathias Agopian | 0852e67 | 2009-09-04 19:50:23 -0700 | [diff] [blame] | 574 | if (ditchedLayers[i] != 0) { | 
|  | 575 | //LOGD("ditching layer %p", ditchedLayers[i].get()); | 
|  | 576 | ditchedLayers[i]->ditch(); | 
|  | 577 | } | 
| Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 578 | } | 
|  | 579 | } | 
|  | 580 |  | 
|  | 581 | void SurfaceFlinger::handleTransactionLocked( | 
|  | 582 | uint32_t transactionFlags, Vector< sp<LayerBase> >& ditchedLayers) | 
|  | 583 | { | 
|  | 584 | const LayerVector& currentLayers(mCurrentState.layersSortedByZ); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 585 | const size_t count = currentLayers.size(); | 
|  | 586 |  | 
|  | 587 | /* | 
|  | 588 | * Traversal of the children | 
|  | 589 | * (perform the transaction for each of them if needed) | 
|  | 590 | */ | 
|  | 591 |  | 
|  | 592 | const bool layersNeedTransaction = transactionFlags & eTraversalNeeded; | 
|  | 593 | if (layersNeedTransaction) { | 
|  | 594 | for (size_t i=0 ; i<count ; i++) { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 595 | const sp<LayerBase>& layer = currentLayers[i]; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 596 | uint32_t trFlags = layer->getTransactionFlags(eTransactionNeeded); | 
|  | 597 | if (!trFlags) continue; | 
|  | 598 |  | 
|  | 599 | const uint32_t flags = layer->doTransaction(0); | 
|  | 600 | if (flags & Layer::eVisibleRegion) | 
|  | 601 | mVisibleRegionsDirty = true; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 602 | } | 
|  | 603 | } | 
|  | 604 |  | 
|  | 605 | /* | 
|  | 606 | * Perform our own transaction if needed | 
|  | 607 | */ | 
|  | 608 |  | 
|  | 609 | if (transactionFlags & eTransactionNeeded) { | 
|  | 610 | if (mCurrentState.orientation != mDrawingState.orientation) { | 
|  | 611 | // the orientation has changed, recompute all visible regions | 
|  | 612 | // and invalidate everything. | 
|  | 613 |  | 
|  | 614 | const int dpy = 0; | 
|  | 615 | const int orientation = mCurrentState.orientation; | 
| Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 616 | const uint32_t type = mCurrentState.orientationType; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 617 | GraphicPlane& plane(graphicPlane(dpy)); | 
|  | 618 | plane.setOrientation(orientation); | 
|  | 619 |  | 
|  | 620 | // update the shared control block | 
|  | 621 | const DisplayHardware& hw(plane.displayHardware()); | 
|  | 622 | volatile display_cblk_t* dcblk = mServerCblk->displays + dpy; | 
|  | 623 | dcblk->orientation = orientation; | 
|  | 624 | if (orientation & eOrientationSwapMask) { | 
|  | 625 | // 90 or 270 degrees orientation | 
|  | 626 | dcblk->w = hw.getHeight(); | 
|  | 627 | dcblk->h = hw.getWidth(); | 
|  | 628 | } else { | 
|  | 629 | dcblk->w = hw.getWidth(); | 
|  | 630 | dcblk->h = hw.getHeight(); | 
|  | 631 | } | 
|  | 632 |  | 
|  | 633 | mVisibleRegionsDirty = true; | 
|  | 634 | mDirtyRegion.set(hw.bounds()); | 
| Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 635 | mFreezeDisplayTime = 0; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 636 | } | 
|  | 637 |  | 
|  | 638 | if (mCurrentState.freezeDisplay != mDrawingState.freezeDisplay) { | 
|  | 639 | // freezing or unfreezing the display -> trigger animation if needed | 
|  | 640 | mFreezeDisplay = mCurrentState.freezeDisplay; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | } | 
|  | 642 |  | 
| Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 643 | if (currentLayers.size() > mDrawingState.layersSortedByZ.size()) { | 
|  | 644 | // layers have been added | 
|  | 645 | mVisibleRegionsDirty = true; | 
|  | 646 | } | 
|  | 647 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 648 | // some layers might have been removed, so | 
|  | 649 | // we need to update the regions they're exposing. | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 650 | if (mLayersRemoved) { | 
| Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 651 | mLayersRemoved = false; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 652 | mVisibleRegionsDirty = true; | 
| Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 653 | const LayerVector& previousLayers(mDrawingState.layersSortedByZ); | 
| Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 654 | const size_t count = previousLayers.size(); | 
|  | 655 | for (size_t i=0 ; i<count ; i++) { | 
| Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 656 | const sp<LayerBase>& layer(previousLayers[i]); | 
|  | 657 | if (currentLayers.indexOf( layer ) < 0) { | 
|  | 658 | // this layer is not visible anymore | 
| Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 659 | ditchedLayers.add(layer); | 
| Mathias Agopian | 5d7126b | 2009-07-28 14:20:21 -0700 | [diff] [blame] | 660 | mDirtyRegionRemovedLayer.orSelf(layer->visibleRegionScreen); | 
| Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 661 | } | 
|  | 662 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 663 | } | 
|  | 664 |  | 
|  | 665 | // get rid of all resources we don't need anymore | 
|  | 666 | // (layers and clients) | 
|  | 667 | free_resources_l(); | 
|  | 668 | } | 
|  | 669 |  | 
|  | 670 | commitTransaction(); | 
|  | 671 | } | 
|  | 672 |  | 
|  | 673 | sp<FreezeLock> SurfaceFlinger::getFreezeLock() const | 
|  | 674 | { | 
|  | 675 | return new FreezeLock(const_cast<SurfaceFlinger *>(this)); | 
|  | 676 | } | 
|  | 677 |  | 
|  | 678 | void SurfaceFlinger::computeVisibleRegions( | 
|  | 679 | LayerVector& currentLayers, Region& dirtyRegion, Region& opaqueRegion) | 
|  | 680 | { | 
|  | 681 | const GraphicPlane& plane(graphicPlane(0)); | 
|  | 682 | const Transform& planeTransform(plane.transform()); | 
|  | 683 |  | 
|  | 684 | Region aboveOpaqueLayers; | 
|  | 685 | Region aboveCoveredLayers; | 
|  | 686 | Region dirty; | 
|  | 687 |  | 
|  | 688 | bool secureFrameBuffer = false; | 
|  | 689 |  | 
|  | 690 | size_t i = currentLayers.size(); | 
|  | 691 | while (i--) { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 692 | const sp<LayerBase>& layer = currentLayers[i]; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 693 | layer->validateVisibility(planeTransform); | 
|  | 694 |  | 
|  | 695 | // start with the whole surface at its current location | 
| Mathias Agopian | 9701122 | 2009-07-28 10:57:27 -0700 | [diff] [blame] | 696 | const Layer::State& s(layer->drawingState()); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 697 |  | 
|  | 698 | // handle hidden surfaces by setting the visible region to empty | 
|  | 699 | Region opaqueRegion; | 
|  | 700 | Region visibleRegion; | 
|  | 701 | Region coveredRegion; | 
| Mathias Agopian | 9701122 | 2009-07-28 10:57:27 -0700 | [diff] [blame] | 702 | if (LIKELY(!(s.flags & ISurfaceComposer::eLayerHidden) && s.alpha)) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 703 | const bool translucent = layer->needsBlending(); | 
| Mathias Agopian | 9701122 | 2009-07-28 10:57:27 -0700 | [diff] [blame] | 704 | const Rect bounds(layer->visibleBounds()); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 705 | visibleRegion.set(bounds); | 
|  | 706 | coveredRegion = visibleRegion; | 
|  | 707 |  | 
|  | 708 | // Remove the transparent area from the visible region | 
|  | 709 | if (translucent) { | 
|  | 710 | visibleRegion.subtractSelf(layer->transparentRegionScreen); | 
|  | 711 | } | 
|  | 712 |  | 
|  | 713 | // compute the opaque region | 
|  | 714 | if (s.alpha==255 && !translucent && layer->getOrientation()>=0) { | 
|  | 715 | // the opaque region is the visible region | 
|  | 716 | opaqueRegion = visibleRegion; | 
|  | 717 | } | 
|  | 718 | } | 
|  | 719 |  | 
|  | 720 | // subtract the opaque region covered by the layers above us | 
|  | 721 | visibleRegion.subtractSelf(aboveOpaqueLayers); | 
|  | 722 | coveredRegion.andSelf(aboveCoveredLayers); | 
|  | 723 |  | 
|  | 724 | // compute this layer's dirty region | 
|  | 725 | if (layer->contentDirty) { | 
|  | 726 | // we need to invalidate the whole region | 
|  | 727 | dirty = visibleRegion; | 
|  | 728 | // as well, as the old visible region | 
|  | 729 | dirty.orSelf(layer->visibleRegionScreen); | 
|  | 730 | layer->contentDirty = false; | 
|  | 731 | } else { | 
| Mathias Agopian | a8d44f7 | 2009-06-28 02:54:16 -0700 | [diff] [blame] | 732 | /* compute the exposed region: | 
|  | 733 | *    exposed = what's VISIBLE and NOT COVERED now | 
|  | 734 | *    but was COVERED before | 
|  | 735 | */ | 
|  | 736 | dirty = (visibleRegion - coveredRegion) & layer->coveredRegionScreen; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 737 | } | 
|  | 738 | dirty.subtractSelf(aboveOpaqueLayers); | 
|  | 739 |  | 
|  | 740 | // accumulate to the screen dirty region | 
|  | 741 | dirtyRegion.orSelf(dirty); | 
|  | 742 |  | 
| Mathias Agopian | 62b7444 | 2009-04-14 23:02:51 -0700 | [diff] [blame] | 743 | // Update aboveOpaqueLayers/aboveCoveredLayers for next (lower) layer | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 744 | aboveOpaqueLayers.orSelf(opaqueRegion); | 
| Mathias Agopian | a8d44f7 | 2009-06-28 02:54:16 -0700 | [diff] [blame] | 745 | aboveCoveredLayers.orSelf(visibleRegion); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 746 |  | 
|  | 747 | // Store the visible region is screen space | 
|  | 748 | layer->setVisibleRegion(visibleRegion); | 
|  | 749 | layer->setCoveredRegion(coveredRegion); | 
|  | 750 |  | 
| Mathias Agopian | 9701122 | 2009-07-28 10:57:27 -0700 | [diff] [blame] | 751 | // If a secure layer is partially visible, lock-down the screen! | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 752 | if (layer->isSecure() && !visibleRegion.isEmpty()) { | 
|  | 753 | secureFrameBuffer = true; | 
|  | 754 | } | 
|  | 755 | } | 
|  | 756 |  | 
| Mathias Agopian | 9701122 | 2009-07-28 10:57:27 -0700 | [diff] [blame] | 757 | // invalidate the areas where a layer was removed | 
|  | 758 | dirtyRegion.orSelf(mDirtyRegionRemovedLayer); | 
|  | 759 | mDirtyRegionRemovedLayer.clear(); | 
|  | 760 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 761 | mSecureFrameBuffer = secureFrameBuffer; | 
|  | 762 | opaqueRegion = aboveOpaqueLayers; | 
|  | 763 | } | 
|  | 764 |  | 
|  | 765 |  | 
|  | 766 | void SurfaceFlinger::commitTransaction() | 
|  | 767 | { | 
|  | 768 | mDrawingState = mCurrentState; | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 769 | mResizeTransationPending = false; | 
|  | 770 | mTransactionCV.broadcast(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 771 | } | 
|  | 772 |  | 
|  | 773 | void SurfaceFlinger::handlePageFlip() | 
|  | 774 | { | 
|  | 775 | bool visibleRegions = mVisibleRegionsDirty; | 
|  | 776 | LayerVector& currentLayers = const_cast<LayerVector&>(mDrawingState.layersSortedByZ); | 
|  | 777 | visibleRegions |= lockPageFlip(currentLayers); | 
|  | 778 |  | 
|  | 779 | const DisplayHardware& hw = graphicPlane(0).displayHardware(); | 
|  | 780 | const Region screenRegion(hw.bounds()); | 
|  | 781 | if (visibleRegions) { | 
|  | 782 | Region opaqueRegion; | 
|  | 783 | computeVisibleRegions(currentLayers, mDirtyRegion, opaqueRegion); | 
|  | 784 | mWormholeRegion = screenRegion.subtract(opaqueRegion); | 
|  | 785 | mVisibleRegionsDirty = false; | 
|  | 786 | } | 
|  | 787 |  | 
|  | 788 | unlockPageFlip(currentLayers); | 
|  | 789 | mDirtyRegion.andSelf(screenRegion); | 
|  | 790 | } | 
|  | 791 |  | 
|  | 792 | bool SurfaceFlinger::lockPageFlip(const LayerVector& currentLayers) | 
|  | 793 | { | 
|  | 794 | bool recomputeVisibleRegions = false; | 
|  | 795 | size_t count = currentLayers.size(); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 796 | sp<LayerBase> const* layers = currentLayers.array(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 797 | for (size_t i=0 ; i<count ; i++) { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 798 | const sp<LayerBase>& layer = layers[i]; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | layer->lockPageFlip(recomputeVisibleRegions); | 
|  | 800 | } | 
|  | 801 | return recomputeVisibleRegions; | 
|  | 802 | } | 
|  | 803 |  | 
|  | 804 | void SurfaceFlinger::unlockPageFlip(const LayerVector& currentLayers) | 
|  | 805 | { | 
|  | 806 | const GraphicPlane& plane(graphicPlane(0)); | 
|  | 807 | const Transform& planeTransform(plane.transform()); | 
|  | 808 | size_t count = currentLayers.size(); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 809 | sp<LayerBase> const* layers = currentLayers.array(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 810 | for (size_t i=0 ; i<count ; i++) { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 811 | const sp<LayerBase>& layer = layers[i]; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | layer->unlockPageFlip(planeTransform, mDirtyRegion); | 
|  | 813 | } | 
|  | 814 | } | 
|  | 815 |  | 
| Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 816 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 817 | void SurfaceFlinger::handleRepaint() | 
|  | 818 | { | 
| Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 819 | // compute the invalid region | 
|  | 820 | mInvalidRegion.orSelf(mDirtyRegion); | 
|  | 821 | if (mInvalidRegion.isEmpty()) { | 
|  | 822 | // nothing to do | 
|  | 823 | return; | 
|  | 824 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 825 |  | 
|  | 826 | if (UNLIKELY(mDebugRegion)) { | 
|  | 827 | debugFlashRegions(); | 
|  | 828 | } | 
|  | 829 |  | 
| Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 830 | // set the frame buffer | 
|  | 831 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); | 
|  | 832 | glMatrixMode(GL_MODELVIEW); | 
|  | 833 | glLoadIdentity(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 |  | 
|  | 835 | uint32_t flags = hw.getFlags(); | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 836 | if ((flags & DisplayHardware::SWAP_RECTANGLE) || | 
|  | 837 | (flags & DisplayHardware::BUFFER_PRESERVED)) | 
|  | 838 | { | 
| Mathias Agopian | 29d06ac | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 839 | // we can redraw only what's dirty, but since SWAP_RECTANGLE only | 
|  | 840 | // takes a rectangle, we must make sure to update that whole | 
|  | 841 | // rectangle in that case | 
|  | 842 | if (flags & DisplayHardware::SWAP_RECTANGLE) { | 
|  | 843 | // FIXME: we really should be able to pass a region to | 
|  | 844 | // SWAP_RECTANGLE so that we don't have to redraw all this. | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 845 | mDirtyRegion.set(mInvalidRegion.bounds()); | 
|  | 846 | } else { | 
| Mathias Agopian | 29d06ac | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 847 | // in the BUFFER_PRESERVED case, obviously, we can update only | 
|  | 848 | // what's needed and nothing more. | 
|  | 849 | // NOTE: this is NOT a common case, as preserving the backbuffer | 
|  | 850 | // is costly and usually involves copying the whole update back. | 
|  | 851 | } | 
|  | 852 | } else { | 
| Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 853 | if (flags & DisplayHardware::PARTIAL_UPDATES) { | 
| Mathias Agopian | 29d06ac | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 854 | // We need to redraw the rectangle that will be updated | 
|  | 855 | // (pushed to the framebuffer). | 
| Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 856 | // This is needed because PARTIAL_UPDATES only takes one | 
| Mathias Agopian | 29d06ac | 2009-06-29 18:49:56 -0700 | [diff] [blame] | 857 | // rectangle instead of a region (see DisplayHardware::flip()) | 
|  | 858 | mDirtyRegion.set(mInvalidRegion.bounds()); | 
|  | 859 | } else { | 
|  | 860 | // we need to redraw everything (the whole screen) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | mDirtyRegion.set(hw.bounds()); | 
|  | 862 | mInvalidRegion = mDirtyRegion; | 
|  | 863 | } | 
|  | 864 | } | 
|  | 865 |  | 
|  | 866 | // compose all surfaces | 
|  | 867 | composeSurfaces(mDirtyRegion); | 
|  | 868 |  | 
|  | 869 | // clear the dirty regions | 
|  | 870 | mDirtyRegion.clear(); | 
|  | 871 | } | 
|  | 872 |  | 
|  | 873 | void SurfaceFlinger::composeSurfaces(const Region& dirty) | 
|  | 874 | { | 
|  | 875 | if (UNLIKELY(!mWormholeRegion.isEmpty())) { | 
|  | 876 | // should never happen unless the window manager has a bug | 
|  | 877 | // draw something... | 
|  | 878 | drawWormhole(); | 
|  | 879 | } | 
|  | 880 | const SurfaceFlinger& flinger(*this); | 
|  | 881 | const LayerVector& drawingLayers(mDrawingState.layersSortedByZ); | 
|  | 882 | const size_t count = drawingLayers.size(); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 883 | sp<LayerBase> const* const layers = drawingLayers.array(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 884 | for (size_t i=0 ; i<count ; ++i) { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 885 | const sp<LayerBase>& layer = layers[i]; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 886 | const Region& visibleRegion(layer->visibleRegionScreen); | 
|  | 887 | if (!visibleRegion.isEmpty())  { | 
|  | 888 | const Region clip(dirty.intersect(visibleRegion)); | 
|  | 889 | if (!clip.isEmpty()) { | 
|  | 890 | layer->draw(clip); | 
|  | 891 | } | 
|  | 892 | } | 
|  | 893 | } | 
|  | 894 | } | 
|  | 895 |  | 
|  | 896 | void SurfaceFlinger::unlockClients() | 
|  | 897 | { | 
|  | 898 | const LayerVector& drawingLayers(mDrawingState.layersSortedByZ); | 
|  | 899 | const size_t count = drawingLayers.size(); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 900 | sp<LayerBase> const* const layers = drawingLayers.array(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | for (size_t i=0 ; i<count ; ++i) { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 902 | const sp<LayerBase>& layer = layers[i]; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 903 | layer->finishPageFlip(); | 
|  | 904 | } | 
|  | 905 | } | 
|  | 906 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 907 | void SurfaceFlinger::debugFlashRegions() | 
|  | 908 | { | 
| Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 909 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); | 
|  | 910 | const uint32_t flags = hw.getFlags(); | 
| Mathias Agopian | df3ca30 | 2009-05-04 19:29:25 -0700 | [diff] [blame] | 911 |  | 
|  | 912 | if (!((flags & DisplayHardware::SWAP_RECTANGLE) || | 
|  | 913 | (flags & DisplayHardware::BUFFER_PRESERVED))) { | 
| Mathias Agopian | 95a666b | 2009-09-24 14:57:26 -0700 | [diff] [blame] | 914 | const Region repaint((flags & DisplayHardware::PARTIAL_UPDATES) ? | 
| Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 915 | mDirtyRegion.bounds() : hw.bounds()); | 
|  | 916 | composeSurfaces(repaint); | 
|  | 917 | } | 
|  | 918 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 919 | glDisable(GL_TEXTURE_2D); | 
|  | 920 | glDisable(GL_BLEND); | 
|  | 921 | glDisable(GL_DITHER); | 
|  | 922 | glDisable(GL_SCISSOR_TEST); | 
|  | 923 |  | 
| Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 924 | static int toggle = 0; | 
|  | 925 | toggle = 1 - toggle; | 
|  | 926 | if (toggle) { | 
|  | 927 | glColor4x(0x10000, 0, 0x10000, 0x10000); | 
|  | 928 | } else { | 
|  | 929 | glColor4x(0x10000, 0x10000, 0, 0x10000); | 
|  | 930 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 931 |  | 
| Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 932 | Region::const_iterator it = mDirtyRegion.begin(); | 
|  | 933 | Region::const_iterator const end = mDirtyRegion.end(); | 
|  | 934 | while (it != end) { | 
|  | 935 | const Rect& r = *it++; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 936 | GLfloat vertices[][2] = { | 
|  | 937 | { r.left,  r.top }, | 
|  | 938 | { r.left,  r.bottom }, | 
|  | 939 | { r.right, r.bottom }, | 
|  | 940 | { r.right, r.top } | 
|  | 941 | }; | 
|  | 942 | glVertexPointer(2, GL_FLOAT, 0, vertices); | 
|  | 943 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 
|  | 944 | } | 
| Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 945 |  | 
| Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 946 | if (mInvalidRegion.isEmpty()) { | 
|  | 947 | mDirtyRegion.dump("mDirtyRegion"); | 
|  | 948 | mInvalidRegion.dump("mInvalidRegion"); | 
|  | 949 | } | 
|  | 950 | hw.flip(mInvalidRegion); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 951 |  | 
|  | 952 | if (mDebugRegion > 1) | 
|  | 953 | usleep(mDebugRegion * 1000); | 
|  | 954 |  | 
|  | 955 | glEnable(GL_SCISSOR_TEST); | 
|  | 956 | //mDirtyRegion.dump("mDirtyRegion"); | 
|  | 957 | } | 
|  | 958 |  | 
|  | 959 | void SurfaceFlinger::drawWormhole() const | 
|  | 960 | { | 
|  | 961 | const Region region(mWormholeRegion.intersect(mDirtyRegion)); | 
|  | 962 | if (region.isEmpty()) | 
|  | 963 | return; | 
|  | 964 |  | 
|  | 965 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); | 
|  | 966 | const int32_t width = hw.getWidth(); | 
|  | 967 | const int32_t height = hw.getHeight(); | 
|  | 968 |  | 
|  | 969 | glDisable(GL_BLEND); | 
|  | 970 | glDisable(GL_DITHER); | 
|  | 971 |  | 
|  | 972 | if (LIKELY(!mDebugBackground)) { | 
|  | 973 | glClearColorx(0,0,0,0); | 
| Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 974 | Region::const_iterator it = region.begin(); | 
|  | 975 | Region::const_iterator const end = region.end(); | 
|  | 976 | while (it != end) { | 
|  | 977 | const Rect& r = *it++; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 978 | const GLint sy = height - (r.top + r.height()); | 
|  | 979 | glScissor(r.left, sy, r.width(), r.height()); | 
|  | 980 | glClear(GL_COLOR_BUFFER_BIT); | 
|  | 981 | } | 
|  | 982 | } else { | 
|  | 983 | const GLshort vertices[][2] = { { 0, 0 }, { width, 0 }, | 
|  | 984 | { width, height }, { 0, height }  }; | 
|  | 985 | const GLshort tcoords[][2] = { { 0, 0 }, { 1, 0 },  { 1, 1 }, { 0, 1 } }; | 
|  | 986 | glVertexPointer(2, GL_SHORT, 0, vertices); | 
|  | 987 | glTexCoordPointer(2, GL_SHORT, 0, tcoords); | 
|  | 988 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); | 
|  | 989 | glEnable(GL_TEXTURE_2D); | 
|  | 990 | glBindTexture(GL_TEXTURE_2D, mWormholeTexName); | 
|  | 991 | glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); | 
|  | 992 | glMatrixMode(GL_TEXTURE); | 
|  | 993 | glLoadIdentity(); | 
|  | 994 | glScalef(width*(1.0f/32.0f), height*(1.0f/32.0f), 1); | 
| Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 995 | Region::const_iterator it = region.begin(); | 
|  | 996 | Region::const_iterator const end = region.end(); | 
|  | 997 | while (it != end) { | 
|  | 998 | const Rect& r = *it++; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 999 | const GLint sy = height - (r.top + r.height()); | 
|  | 1000 | glScissor(r.left, sy, r.width(), r.height()); | 
|  | 1001 | glDrawArrays(GL_TRIANGLE_FAN, 0, 4); | 
|  | 1002 | } | 
|  | 1003 | glDisableClientState(GL_TEXTURE_COORD_ARRAY); | 
|  | 1004 | } | 
|  | 1005 | } | 
|  | 1006 |  | 
|  | 1007 | void SurfaceFlinger::debugShowFPS() const | 
|  | 1008 | { | 
|  | 1009 | static int mFrameCount; | 
|  | 1010 | static int mLastFrameCount = 0; | 
|  | 1011 | static nsecs_t mLastFpsTime = 0; | 
|  | 1012 | static float mFps = 0; | 
|  | 1013 | mFrameCount++; | 
|  | 1014 | nsecs_t now = systemTime(); | 
|  | 1015 | nsecs_t diff = now - mLastFpsTime; | 
|  | 1016 | if (diff > ms2ns(250)) { | 
|  | 1017 | mFps =  ((mFrameCount - mLastFrameCount) * float(s2ns(1))) / diff; | 
|  | 1018 | mLastFpsTime = now; | 
|  | 1019 | mLastFrameCount = mFrameCount; | 
|  | 1020 | } | 
|  | 1021 | // XXX: mFPS has the value we want | 
|  | 1022 | } | 
|  | 1023 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1024 | status_t SurfaceFlinger::addLayer(const sp<LayerBase>& layer) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1025 | { | 
|  | 1026 | Mutex::Autolock _l(mStateLock); | 
|  | 1027 | addLayer_l(layer); | 
|  | 1028 | setTransactionFlags(eTransactionNeeded|eTraversalNeeded); | 
|  | 1029 | return NO_ERROR; | 
|  | 1030 | } | 
|  | 1031 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1032 | status_t SurfaceFlinger::removeLayer(const sp<LayerBase>& layer) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1033 | { | 
|  | 1034 | Mutex::Autolock _l(mStateLock); | 
| Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 1035 | status_t err = purgatorizeLayer_l(layer); | 
|  | 1036 | if (err == NO_ERROR) | 
|  | 1037 | setTransactionFlags(eTransactionNeeded); | 
|  | 1038 | return err; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1039 | } | 
|  | 1040 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1041 | status_t SurfaceFlinger::invalidateLayerVisibility(const sp<LayerBase>& layer) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1042 | { | 
|  | 1043 | layer->forceVisibilityTransaction(); | 
|  | 1044 | setTransactionFlags(eTraversalNeeded); | 
|  | 1045 | return NO_ERROR; | 
|  | 1046 | } | 
|  | 1047 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1048 | status_t SurfaceFlinger::addLayer_l(const sp<LayerBase>& layer) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1049 | { | 
| Mathias Agopian | 0852e67 | 2009-09-04 19:50:23 -0700 | [diff] [blame] | 1050 | if (layer == 0) | 
|  | 1051 | return BAD_VALUE; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1052 | ssize_t i = mCurrentState.layersSortedByZ.add( | 
|  | 1053 | layer, &LayerBase::compareCurrentStateZ); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1054 | sp<LayerBaseClient> lbc = LayerBase::dynamicCast< LayerBaseClient* >(layer.get()); | 
|  | 1055 | if (lbc != 0) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1056 | mLayerMap.add(lbc->serverIndex(), lbc); | 
|  | 1057 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1058 | return NO_ERROR; | 
|  | 1059 | } | 
|  | 1060 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1061 | status_t SurfaceFlinger::removeLayer_l(const sp<LayerBase>& layerBase) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1062 | { | 
|  | 1063 | ssize_t index = mCurrentState.layersSortedByZ.remove(layerBase); | 
|  | 1064 | if (index >= 0) { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1065 | mLayersRemoved = true; | 
| Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1066 | sp<LayerBaseClient> layer = | 
|  | 1067 | LayerBase::dynamicCast< LayerBaseClient* >(layerBase.get()); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1068 | if (layer != 0) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1069 | mLayerMap.removeItem(layer->serverIndex()); | 
|  | 1070 | } | 
|  | 1071 | return NO_ERROR; | 
|  | 1072 | } | 
| Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 1073 | return status_t(index); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1074 | } | 
|  | 1075 |  | 
| Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1076 | status_t SurfaceFlinger::purgatorizeLayer_l(const sp<LayerBase>& layerBase) | 
|  | 1077 | { | 
| Mathias Agopian | 8c0a3d7 | 2009-09-23 16:44:00 -0700 | [diff] [blame] | 1078 | // remove the layer from the main list (through a transaction). | 
| Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1079 | ssize_t err = removeLayer_l(layerBase); | 
| Mathias Agopian | 8c0a3d7 | 2009-09-23 16:44:00 -0700 | [diff] [blame] | 1080 |  | 
| Mathias Agopian | 0b3ad46 | 2009-10-02 18:12:30 -0700 | [diff] [blame] | 1081 | layerBase->onRemoved(); | 
|  | 1082 |  | 
| Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 1083 | // it's possible that we don't find a layer, because it might | 
|  | 1084 | // have been destroyed already -- this is not technically an error | 
|  | 1085 | // from the user because there is a race between BClient::destroySurface(), | 
|  | 1086 | // ~BClient() and ~ISurface(). | 
| Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1087 | return (err == NAME_NOT_FOUND) ? status_t(NO_ERROR) : err; | 
|  | 1088 | } | 
|  | 1089 |  | 
|  | 1090 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1091 | void SurfaceFlinger::free_resources_l() | 
|  | 1092 | { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1093 | // free resources associated with disconnected clients | 
| Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1094 | Vector< sp<Client> >& disconnectedClients(mDisconnectedClients); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1095 | const size_t count = disconnectedClients.size(); | 
|  | 1096 | for (size_t i=0 ; i<count ; i++) { | 
| Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1097 | sp<Client> client = disconnectedClients[i]; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1098 | mTokens.release(client->cid); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1099 | } | 
|  | 1100 | disconnectedClients.clear(); | 
|  | 1101 | } | 
|  | 1102 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1103 | uint32_t SurfaceFlinger::getTransactionFlags(uint32_t flags) | 
|  | 1104 | { | 
|  | 1105 | return android_atomic_and(~flags, &mTransactionFlags) & flags; | 
|  | 1106 | } | 
|  | 1107 |  | 
|  | 1108 | uint32_t SurfaceFlinger::setTransactionFlags(uint32_t flags, nsecs_t delay) | 
|  | 1109 | { | 
|  | 1110 | uint32_t old = android_atomic_or(flags, &mTransactionFlags); | 
|  | 1111 | if ((old & flags)==0) { // wake the server up | 
|  | 1112 | if (delay > 0) { | 
|  | 1113 | signalDelayedEvent(delay); | 
|  | 1114 | } else { | 
|  | 1115 | signalEvent(); | 
|  | 1116 | } | 
|  | 1117 | } | 
|  | 1118 | return old; | 
|  | 1119 | } | 
|  | 1120 |  | 
|  | 1121 | void SurfaceFlinger::openGlobalTransaction() | 
|  | 1122 | { | 
|  | 1123 | android_atomic_inc(&mTransactionCount); | 
|  | 1124 | } | 
|  | 1125 |  | 
|  | 1126 | void SurfaceFlinger::closeGlobalTransaction() | 
|  | 1127 | { | 
|  | 1128 | if (android_atomic_dec(&mTransactionCount) == 1) { | 
|  | 1129 | signalEvent(); | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1130 |  | 
|  | 1131 | // if there is a transaction with a resize, wait for it to | 
|  | 1132 | // take effect before returning. | 
|  | 1133 | Mutex::Autolock _l(mStateLock); | 
|  | 1134 | while (mResizeTransationPending) { | 
| Mathias Agopian | 448f015 | 2009-09-30 14:42:13 -0700 | [diff] [blame] | 1135 | status_t err = mTransactionCV.waitRelative(mStateLock, s2ns(5)); | 
|  | 1136 | if (CC_UNLIKELY(err != NO_ERROR)) { | 
|  | 1137 | // just in case something goes wrong in SF, return to the | 
|  | 1138 | // called after a few seconds. | 
|  | 1139 | LOGW_IF(err == TIMED_OUT, "closeGlobalTransaction timed out!"); | 
|  | 1140 | mResizeTransationPending = false; | 
|  | 1141 | break; | 
|  | 1142 | } | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1143 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1144 | } | 
|  | 1145 | } | 
|  | 1146 |  | 
|  | 1147 | status_t SurfaceFlinger::freezeDisplay(DisplayID dpy, uint32_t flags) | 
|  | 1148 | { | 
|  | 1149 | if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) | 
|  | 1150 | return BAD_VALUE; | 
|  | 1151 |  | 
|  | 1152 | Mutex::Autolock _l(mStateLock); | 
|  | 1153 | mCurrentState.freezeDisplay = 1; | 
|  | 1154 | setTransactionFlags(eTransactionNeeded); | 
|  | 1155 |  | 
|  | 1156 | // flags is intended to communicate some sort of animation behavior | 
| Mathias Agopian | 62b7444 | 2009-04-14 23:02:51 -0700 | [diff] [blame] | 1157 | // (for instance fading) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1158 | return NO_ERROR; | 
|  | 1159 | } | 
|  | 1160 |  | 
|  | 1161 | status_t SurfaceFlinger::unfreezeDisplay(DisplayID dpy, uint32_t flags) | 
|  | 1162 | { | 
|  | 1163 | if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) | 
|  | 1164 | return BAD_VALUE; | 
|  | 1165 |  | 
|  | 1166 | Mutex::Autolock _l(mStateLock); | 
|  | 1167 | mCurrentState.freezeDisplay = 0; | 
|  | 1168 | setTransactionFlags(eTransactionNeeded); | 
|  | 1169 |  | 
|  | 1170 | // flags is intended to communicate some sort of animation behavior | 
| Mathias Agopian | 62b7444 | 2009-04-14 23:02:51 -0700 | [diff] [blame] | 1171 | // (for instance fading) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1172 | return NO_ERROR; | 
|  | 1173 | } | 
|  | 1174 |  | 
| Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 1175 | int SurfaceFlinger::setOrientation(DisplayID dpy, | 
|  | 1176 | int orientation, uint32_t flags) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1177 | { | 
|  | 1178 | if (UNLIKELY(uint32_t(dpy) >= DISPLAY_COUNT)) | 
|  | 1179 | return BAD_VALUE; | 
|  | 1180 |  | 
|  | 1181 | Mutex::Autolock _l(mStateLock); | 
|  | 1182 | if (mCurrentState.orientation != orientation) { | 
|  | 1183 | if (uint32_t(orientation)<=eOrientation270 || orientation==42) { | 
| Mathias Agopian | c08731e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 1184 | mCurrentState.orientationType = flags; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1185 | mCurrentState.orientation = orientation; | 
|  | 1186 | setTransactionFlags(eTransactionNeeded); | 
|  | 1187 | mTransactionCV.wait(mStateLock); | 
|  | 1188 | } else { | 
|  | 1189 | orientation = BAD_VALUE; | 
|  | 1190 | } | 
|  | 1191 | } | 
|  | 1192 | return orientation; | 
|  | 1193 | } | 
|  | 1194 |  | 
|  | 1195 | sp<ISurface> SurfaceFlinger::createSurface(ClientID clientId, int pid, | 
|  | 1196 | ISurfaceFlingerClient::surface_data_t* params, | 
|  | 1197 | DisplayID d, uint32_t w, uint32_t h, PixelFormat format, | 
|  | 1198 | uint32_t flags) | 
|  | 1199 | { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1200 | sp<LayerBaseClient> layer; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1201 | sp<LayerBaseClient::Surface> surfaceHandle; | 
| Mathias Agopian | 6e2d648 | 2009-07-09 18:16:43 -0700 | [diff] [blame] | 1202 |  | 
|  | 1203 | if (int32_t(w|h) < 0) { | 
|  | 1204 | LOGE("createSurface() failed, w or h is negative (w=%d, h=%d)", | 
|  | 1205 | int(w), int(h)); | 
|  | 1206 | return surfaceHandle; | 
|  | 1207 | } | 
|  | 1208 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1209 | Mutex::Autolock _l(mStateLock); | 
| Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1210 | sp<Client> client = mClientsMap.valueFor(clientId); | 
|  | 1211 | if (UNLIKELY(client == 0)) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1212 | LOGE("createSurface() failed, client not found (id=%d)", clientId); | 
|  | 1213 | return surfaceHandle; | 
|  | 1214 | } | 
|  | 1215 |  | 
|  | 1216 | //LOGD("createSurface for pid %d (%d x %d)", pid, w, h); | 
| Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1217 | int32_t id = client->generateId(pid); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1218 | if (uint32_t(id) >= NUM_LAYERS_MAX) { | 
|  | 1219 | LOGE("createSurface() failed, generateId = %d", id); | 
|  | 1220 | return surfaceHandle; | 
|  | 1221 | } | 
|  | 1222 |  | 
|  | 1223 | switch (flags & eFXSurfaceMask) { | 
|  | 1224 | case eFXSurfaceNormal: | 
|  | 1225 | if (UNLIKELY(flags & ePushBuffers)) { | 
| Mathias Agopian | 1c97d2e | 2009-08-19 17:46:26 -0700 | [diff] [blame] | 1226 | layer = createPushBuffersSurfaceLocked(client, d, id, | 
|  | 1227 | w, h, flags); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1228 | } else { | 
| Mathias Agopian | 1c97d2e | 2009-08-19 17:46:26 -0700 | [diff] [blame] | 1229 | layer = createNormalSurfaceLocked(client, d, id, | 
|  | 1230 | w, h, flags, format); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1231 | } | 
|  | 1232 | break; | 
|  | 1233 | case eFXSurfaceBlur: | 
| Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1234 | layer = createBlurSurfaceLocked(client, d, id, w, h, flags); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1235 | break; | 
|  | 1236 | case eFXSurfaceDim: | 
| Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1237 | layer = createDimSurfaceLocked(client, d, id, w, h, flags); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1238 | break; | 
|  | 1239 | } | 
|  | 1240 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1241 | if (layer != 0) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1242 | setTransactionFlags(eTransactionNeeded); | 
|  | 1243 | surfaceHandle = layer->getSurface(); | 
| Mathias Agopian | 1c97d2e | 2009-08-19 17:46:26 -0700 | [diff] [blame] | 1244 | if (surfaceHandle != 0) { | 
|  | 1245 | params->token = surfaceHandle->getToken(); | 
|  | 1246 | params->identity = surfaceHandle->getIdentity(); | 
|  | 1247 | params->width = w; | 
|  | 1248 | params->height = h; | 
|  | 1249 | params->format = format; | 
|  | 1250 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1251 | } | 
|  | 1252 |  | 
|  | 1253 | return surfaceHandle; | 
|  | 1254 | } | 
|  | 1255 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1256 | sp<LayerBaseClient> SurfaceFlinger::createNormalSurfaceLocked( | 
| Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1257 | const sp<Client>& client, DisplayID display, | 
| Mathias Agopian | 1c97d2e | 2009-08-19 17:46:26 -0700 | [diff] [blame] | 1258 | int32_t id, uint32_t w, uint32_t h, uint32_t flags, | 
|  | 1259 | PixelFormat& format) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1260 | { | 
|  | 1261 | // initialize the surfaces | 
|  | 1262 | switch (format) { // TODO: take h/w into account | 
|  | 1263 | case PIXEL_FORMAT_TRANSPARENT: | 
|  | 1264 | case PIXEL_FORMAT_TRANSLUCENT: | 
|  | 1265 | format = PIXEL_FORMAT_RGBA_8888; | 
|  | 1266 | break; | 
|  | 1267 | case PIXEL_FORMAT_OPAQUE: | 
|  | 1268 | format = PIXEL_FORMAT_RGB_565; | 
|  | 1269 | break; | 
|  | 1270 | } | 
|  | 1271 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1272 | sp<Layer> layer = new Layer(this, display, client, id); | 
| Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1273 | status_t err = layer->setBuffers(w, h, format, flags); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1274 | if (LIKELY(err == NO_ERROR)) { | 
|  | 1275 | layer->initStates(w, h, flags); | 
|  | 1276 | addLayer_l(layer); | 
|  | 1277 | } else { | 
|  | 1278 | LOGE("createNormalSurfaceLocked() failed (%s)", strerror(-err)); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1279 | layer.clear(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1280 | } | 
|  | 1281 | return layer; | 
|  | 1282 | } | 
|  | 1283 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1284 | sp<LayerBaseClient> SurfaceFlinger::createBlurSurfaceLocked( | 
| Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1285 | const sp<Client>& client, DisplayID display, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1286 | int32_t id, uint32_t w, uint32_t h, uint32_t flags) | 
|  | 1287 | { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1288 | sp<LayerBlur> layer = new LayerBlur(this, display, client, id); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1289 | layer->initStates(w, h, flags); | 
|  | 1290 | addLayer_l(layer); | 
|  | 1291 | return layer; | 
|  | 1292 | } | 
|  | 1293 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1294 | sp<LayerBaseClient> SurfaceFlinger::createDimSurfaceLocked( | 
| Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1295 | const sp<Client>& client, DisplayID display, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1296 | int32_t id, uint32_t w, uint32_t h, uint32_t flags) | 
|  | 1297 | { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1298 | sp<LayerDim> layer = new LayerDim(this, display, client, id); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1299 | layer->initStates(w, h, flags); | 
|  | 1300 | addLayer_l(layer); | 
|  | 1301 | return layer; | 
|  | 1302 | } | 
|  | 1303 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1304 | sp<LayerBaseClient> SurfaceFlinger::createPushBuffersSurfaceLocked( | 
| Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1305 | const sp<Client>& client, DisplayID display, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1306 | int32_t id, uint32_t w, uint32_t h, uint32_t flags) | 
|  | 1307 | { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1308 | sp<LayerBuffer> layer = new LayerBuffer(this, display, client, id); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1309 | layer->initStates(w, h, flags); | 
|  | 1310 | addLayer_l(layer); | 
|  | 1311 | return layer; | 
|  | 1312 | } | 
|  | 1313 |  | 
| Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1314 | status_t SurfaceFlinger::removeSurface(SurfaceID index) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1315 | { | 
| Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1316 | /* | 
|  | 1317 | * called by the window manager, when a surface should be marked for | 
|  | 1318 | * destruction. | 
| Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 1319 | * | 
|  | 1320 | * The surface is removed from the current and drawing lists, but placed | 
|  | 1321 | * in the purgatory queue, so it's not destroyed right-away (we need | 
|  | 1322 | * to wait for all client's references to go away first). | 
| Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1323 | */ | 
| Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1324 |  | 
| Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 1325 | status_t err = NAME_NOT_FOUND; | 
| Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 1326 | Mutex::Autolock _l(mStateLock); | 
|  | 1327 | sp<LayerBaseClient> layer = getLayerUser_l(index); | 
| Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 1328 | if (layer != 0) { | 
|  | 1329 | err = purgatorizeLayer_l(layer); | 
|  | 1330 | if (err == NO_ERROR) { | 
| Mathias Agopian | 48d819a | 2009-09-10 19:41:18 -0700 | [diff] [blame] | 1331 | setTransactionFlags(eTransactionNeeded); | 
|  | 1332 | } | 
| Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1333 | } | 
|  | 1334 | return err; | 
|  | 1335 | } | 
|  | 1336 |  | 
|  | 1337 | status_t SurfaceFlinger::destroySurface(const sp<LayerBaseClient>& layer) | 
|  | 1338 | { | 
| Mathias Agopian | 759fdb2 | 2009-07-02 17:33:40 -0700 | [diff] [blame] | 1339 | // called by ~ISurface() when all references are gone | 
| Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1340 |  | 
| Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 1341 | class MessageDestroySurface : public MessageBase { | 
| Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 1342 | SurfaceFlinger* flinger; | 
| Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 1343 | sp<LayerBaseClient> layer; | 
|  | 1344 | public: | 
| Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 1345 | MessageDestroySurface( | 
|  | 1346 | SurfaceFlinger* flinger, const sp<LayerBaseClient>& layer) | 
|  | 1347 | : flinger(flinger), layer(layer) { } | 
| Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 1348 | virtual bool handler() { | 
| Mathias Agopian | cd8c5e2 | 2009-06-19 16:24:02 -0700 | [diff] [blame] | 1349 | sp<LayerBaseClient> l(layer); | 
|  | 1350 | layer.clear(); // clear it outside of the lock; | 
| Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 1351 | Mutex::Autolock _l(flinger->mStateLock); | 
| Mathias Agopian | 759fdb2 | 2009-07-02 17:33:40 -0700 | [diff] [blame] | 1352 | /* | 
|  | 1353 | * remove the layer from the current list -- chances are that it's | 
|  | 1354 | * not in the list anyway, because it should have been removed | 
|  | 1355 | * already upon request of the client (eg: window manager). | 
|  | 1356 | * However, a buggy client could have not done that. | 
|  | 1357 | * Since we know we don't have any more clients, we don't need | 
|  | 1358 | * to use the purgatory. | 
|  | 1359 | */ | 
| Mathias Agopian | cd8c5e2 | 2009-06-19 16:24:02 -0700 | [diff] [blame] | 1360 | status_t err = flinger->removeLayer_l(l); | 
| Mathias Agopian | 8c0a3d7 | 2009-09-23 16:44:00 -0700 | [diff] [blame] | 1361 | LOGE_IF(err<0 && err != NAME_NOT_FOUND, | 
|  | 1362 | "error removing layer=%p (%s)", l.get(), strerror(-err)); | 
| Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 1363 | return true; | 
|  | 1364 | } | 
|  | 1365 | }; | 
| Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 1366 |  | 
| Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 1367 | mEventQueue.postMessage( new MessageDestroySurface(this, layer) ); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1368 | return NO_ERROR; | 
|  | 1369 | } | 
|  | 1370 |  | 
|  | 1371 | status_t SurfaceFlinger::setClientState( | 
|  | 1372 | ClientID cid, | 
|  | 1373 | int32_t count, | 
|  | 1374 | const layer_state_t* states) | 
|  | 1375 | { | 
|  | 1376 | Mutex::Autolock _l(mStateLock); | 
|  | 1377 | uint32_t flags = 0; | 
|  | 1378 | cid <<= 16; | 
|  | 1379 | for (int i=0 ; i<count ; i++) { | 
|  | 1380 | const layer_state_t& s = states[i]; | 
| Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 1381 | sp<LayerBaseClient> layer(getLayerUser_l(s.surface | cid)); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1382 | if (layer != 0) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1383 | const uint32_t what = s.what; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1384 | if (what & ePositionChanged) { | 
|  | 1385 | if (layer->setPosition(s.x, s.y)) | 
|  | 1386 | flags |= eTraversalNeeded; | 
|  | 1387 | } | 
|  | 1388 | if (what & eLayerChanged) { | 
|  | 1389 | if (layer->setLayer(s.z)) { | 
|  | 1390 | mCurrentState.layersSortedByZ.reorder( | 
|  | 1391 | layer, &Layer::compareCurrentStateZ); | 
|  | 1392 | // we need traversal (state changed) | 
|  | 1393 | // AND transaction (list changed) | 
|  | 1394 | flags |= eTransactionNeeded|eTraversalNeeded; | 
|  | 1395 | } | 
|  | 1396 | } | 
|  | 1397 | if (what & eSizeChanged) { | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1398 | if (layer->setSize(s.w, s.h)) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1399 | flags |= eTraversalNeeded; | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1400 | mResizeTransationPending = true; | 
|  | 1401 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1402 | } | 
|  | 1403 | if (what & eAlphaChanged) { | 
|  | 1404 | if (layer->setAlpha(uint8_t(255.0f*s.alpha+0.5f))) | 
|  | 1405 | flags |= eTraversalNeeded; | 
|  | 1406 | } | 
|  | 1407 | if (what & eMatrixChanged) { | 
|  | 1408 | if (layer->setMatrix(s.matrix)) | 
|  | 1409 | flags |= eTraversalNeeded; | 
|  | 1410 | } | 
|  | 1411 | if (what & eTransparentRegionChanged) { | 
|  | 1412 | if (layer->setTransparentRegionHint(s.transparentRegion)) | 
|  | 1413 | flags |= eTraversalNeeded; | 
|  | 1414 | } | 
|  | 1415 | if (what & eVisibilityChanged) { | 
|  | 1416 | if (layer->setFlags(s.flags, s.mask)) | 
|  | 1417 | flags |= eTraversalNeeded; | 
|  | 1418 | } | 
|  | 1419 | } | 
|  | 1420 | } | 
|  | 1421 | if (flags) { | 
|  | 1422 | setTransactionFlags(flags); | 
|  | 1423 | } | 
|  | 1424 | return NO_ERROR; | 
|  | 1425 | } | 
|  | 1426 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1427 | sp<LayerBaseClient> SurfaceFlinger::getLayerUser_l(SurfaceID s) const | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1428 | { | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1429 | sp<LayerBaseClient> layer = mLayerMap.valueFor(s); | 
|  | 1430 | return layer; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1431 | } | 
|  | 1432 |  | 
|  | 1433 | void SurfaceFlinger::screenReleased(int dpy) | 
|  | 1434 | { | 
|  | 1435 | // this may be called by a signal handler, we can't do too much in here | 
|  | 1436 | android_atomic_or(eConsoleReleased, &mConsoleSignals); | 
|  | 1437 | signalEvent(); | 
|  | 1438 | } | 
|  | 1439 |  | 
|  | 1440 | void SurfaceFlinger::screenAcquired(int dpy) | 
|  | 1441 | { | 
|  | 1442 | // this may be called by a signal handler, we can't do too much in here | 
|  | 1443 | android_atomic_or(eConsoleAcquired, &mConsoleSignals); | 
|  | 1444 | signalEvent(); | 
|  | 1445 | } | 
|  | 1446 |  | 
|  | 1447 | status_t SurfaceFlinger::dump(int fd, const Vector<String16>& args) | 
|  | 1448 | { | 
|  | 1449 | const size_t SIZE = 1024; | 
|  | 1450 | char buffer[SIZE]; | 
|  | 1451 | String8 result; | 
| Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 1452 | if (!mDump.checkCalling()) { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1453 | snprintf(buffer, SIZE, "Permission Denial: " | 
|  | 1454 | "can't dump SurfaceFlinger from pid=%d, uid=%d\n", | 
|  | 1455 | IPCThreadState::self()->getCallingPid(), | 
|  | 1456 | IPCThreadState::self()->getCallingUid()); | 
|  | 1457 | result.append(buffer); | 
|  | 1458 | } else { | 
| Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 1459 |  | 
|  | 1460 | // figure out if we're stuck somewhere | 
|  | 1461 | const nsecs_t now = systemTime(); | 
|  | 1462 | const nsecs_t inSwapBuffers(mDebugInSwapBuffers); | 
|  | 1463 | const nsecs_t inTransaction(mDebugInTransaction); | 
|  | 1464 | nsecs_t inSwapBuffersDuration = (inSwapBuffers) ? now-inSwapBuffers : 0; | 
|  | 1465 | nsecs_t inTransactionDuration = (inTransaction) ? now-inTransaction : 0; | 
|  | 1466 |  | 
|  | 1467 | // Try to get the main lock, but don't insist if we can't | 
|  | 1468 | // (this would indicate SF is stuck, but we want to be able to | 
|  | 1469 | // print something in dumpsys). | 
|  | 1470 | int retry = 3; | 
|  | 1471 | while (mStateLock.tryLock()<0 && --retry>=0) { | 
|  | 1472 | usleep(1000000); | 
|  | 1473 | } | 
|  | 1474 | const bool locked(retry >= 0); | 
|  | 1475 | if (!locked) { | 
|  | 1476 | snprintf(buffer, SIZE, | 
|  | 1477 | "SurfaceFlinger appears to be unresponsive, " | 
|  | 1478 | "dumping anyways (no locks held)\n"); | 
|  | 1479 | result.append(buffer); | 
|  | 1480 | } | 
|  | 1481 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1482 | size_t s = mClientsMap.size(); | 
|  | 1483 | char name[64]; | 
|  | 1484 | for (size_t i=0 ; i<s ; i++) { | 
| Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1485 | sp<Client> client = mClientsMap.valueAt(i); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1486 | sprintf(name, "  Client (id=0x%08x)", client->cid); | 
|  | 1487 | client->dump(name); | 
|  | 1488 | } | 
|  | 1489 | const LayerVector& currentLayers = mCurrentState.layersSortedByZ; | 
|  | 1490 | const size_t count = currentLayers.size(); | 
|  | 1491 | for (size_t i=0 ; i<count ; i++) { | 
|  | 1492 | /*** LayerBase ***/ | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1493 | const sp<LayerBase>& layer = currentLayers[i]; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1494 | const Layer::State& s = layer->drawingState(); | 
|  | 1495 | snprintf(buffer, SIZE, | 
|  | 1496 | "+ %s %p\n" | 
|  | 1497 | "      " | 
|  | 1498 | "z=%9d, pos=(%4d,%4d), size=(%4d,%4d), " | 
| Mathias Agopian | 401c257 | 2009-09-23 19:16:27 -0700 | [diff] [blame] | 1499 | "needsBlending=%1d, needsDithering=%1d, invalidate=%1d, " | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1500 | "alpha=0x%02x, flags=0x%08x, tr=[%.2f, %.2f][%.2f, %.2f]\n", | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1501 | layer->getTypeID(), layer.get(), | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1502 | s.z, layer->tx(), layer->ty(), s.w, s.h, | 
| Mathias Agopian | 401c257 | 2009-09-23 19:16:27 -0700 | [diff] [blame] | 1503 | layer->needsBlending(), layer->needsDithering(), | 
|  | 1504 | layer->contentDirty, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1505 | s.alpha, s.flags, | 
|  | 1506 | s.transform[0], s.transform[1], | 
|  | 1507 | s.transform[2], s.transform[3]); | 
|  | 1508 | result.append(buffer); | 
|  | 1509 | buffer[0] = 0; | 
|  | 1510 | /*** LayerBaseClient ***/ | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1511 | sp<LayerBaseClient> lbc = | 
|  | 1512 | LayerBase::dynamicCast< LayerBaseClient* >(layer.get()); | 
|  | 1513 | if (lbc != 0) { | 
| Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1514 | sp<Client> client(lbc->client.promote()); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1515 | snprintf(buffer, SIZE, | 
|  | 1516 | "      " | 
|  | 1517 | "id=0x%08x, client=0x%08x, identity=%u\n", | 
| Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 1518 | lbc->clientIndex(), client.get() ? client->cid : 0, | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1519 | lbc->getIdentity()); | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1520 |  | 
|  | 1521 | result.append(buffer); | 
|  | 1522 | buffer[0] = 0; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1523 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1524 | /*** Layer ***/ | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1525 | sp<Layer> l = LayerBase::dynamicCast< Layer* >(layer.get()); | 
|  | 1526 | if (l != 0) { | 
| Mathias Agopian | 86f7329 | 2009-09-17 01:35:28 -0700 | [diff] [blame] | 1527 | SharedBufferStack::Statistics stats = l->lcblk->getStats(); | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1528 | result.append( l->lcblk->dump("      ") ); | 
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 1529 | sp<const GraphicBuffer> buf0(l->getBuffer(0)); | 
|  | 1530 | sp<const GraphicBuffer> buf1(l->getBuffer(1)); | 
| Mathias Agopian | 4790a3c | 2009-09-14 15:59:16 -0700 | [diff] [blame] | 1531 | uint32_t w0=0, h0=0, s0=0; | 
|  | 1532 | uint32_t w1=0, h1=0, s1=0; | 
|  | 1533 | if (buf0 != 0) { | 
|  | 1534 | w0 = buf0->getWidth(); | 
|  | 1535 | h0 = buf0->getHeight(); | 
|  | 1536 | s0 = buf0->getStride(); | 
|  | 1537 | } | 
|  | 1538 | if (buf1 != 0) { | 
|  | 1539 | w1 = buf1->getWidth(); | 
|  | 1540 | h1 = buf1->getHeight(); | 
|  | 1541 | s1 = buf1->getStride(); | 
|  | 1542 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1543 | snprintf(buffer, SIZE, | 
|  | 1544 | "      " | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1545 | "format=%2d, [%3ux%3u:%3u] [%3ux%3u:%3u]," | 
| Mathias Agopian | 86f7329 | 2009-09-17 01:35:28 -0700 | [diff] [blame] | 1546 | " freezeLock=%p, dq-q-time=%u us\n", | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1547 | l->pixelFormat(), | 
| Mathias Agopian | 4790a3c | 2009-09-14 15:59:16 -0700 | [diff] [blame] | 1548 | w0, h0, s0, w1, h1, s1, | 
| Mathias Agopian | 86f7329 | 2009-09-17 01:35:28 -0700 | [diff] [blame] | 1549 | l->getFreezeLock().get(), stats.totalTime); | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1550 | result.append(buffer); | 
|  | 1551 | buffer[0] = 0; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1552 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1553 | s.transparentRegion.dump(result, "transparentRegion"); | 
|  | 1554 | layer->transparentRegionScreen.dump(result, "transparentRegionScreen"); | 
|  | 1555 | layer->visibleRegionScreen.dump(result, "visibleRegionScreen"); | 
|  | 1556 | } | 
|  | 1557 | mWormholeRegion.dump(result, "WormholeRegion"); | 
|  | 1558 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); | 
|  | 1559 | snprintf(buffer, SIZE, | 
|  | 1560 | "  display frozen: %s, freezeCount=%d, orientation=%d, canDraw=%d\n", | 
|  | 1561 | mFreezeDisplay?"yes":"no", mFreezeCount, | 
|  | 1562 | mCurrentState.orientation, hw.canDraw()); | 
|  | 1563 | result.append(buffer); | 
| Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 1564 | snprintf(buffer, SIZE, | 
|  | 1565 | "  last eglSwapBuffers() time: %f us\n" | 
|  | 1566 | "  last transaction time     : %f us\n", | 
|  | 1567 | mLastSwapBufferTime/1000.0, mLastTransactionTime/1000.0); | 
|  | 1568 | result.append(buffer); | 
|  | 1569 | if (inSwapBuffersDuration || !locked) { | 
|  | 1570 | snprintf(buffer, SIZE, "  eglSwapBuffers time: %f us\n", | 
|  | 1571 | inSwapBuffersDuration/1000.0); | 
|  | 1572 | result.append(buffer); | 
|  | 1573 | } | 
|  | 1574 | if (inTransactionDuration || !locked) { | 
|  | 1575 | snprintf(buffer, SIZE, "  transaction time: %f us\n", | 
|  | 1576 | inTransactionDuration/1000.0); | 
|  | 1577 | result.append(buffer); | 
|  | 1578 | } | 
| Mathias Agopian | 759fdb2 | 2009-07-02 17:33:40 -0700 | [diff] [blame] | 1579 | snprintf(buffer, SIZE, "  client count: %d\n", mClientsMap.size()); | 
| Mathias Agopian | 3d57964 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 1580 | result.append(buffer); | 
| Mathias Agopian | 3330b20 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 1581 | const GraphicBufferAllocator& alloc(GraphicBufferAllocator::get()); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1582 | alloc.dump(result); | 
| Mathias Agopian | 9795c42 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 1583 |  | 
|  | 1584 | if (locked) { | 
|  | 1585 | mStateLock.unlock(); | 
|  | 1586 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1587 | } | 
|  | 1588 | write(fd, result.string(), result.size()); | 
|  | 1589 | return NO_ERROR; | 
|  | 1590 | } | 
|  | 1591 |  | 
|  | 1592 | status_t SurfaceFlinger::onTransact( | 
|  | 1593 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) | 
|  | 1594 | { | 
|  | 1595 | switch (code) { | 
|  | 1596 | case CREATE_CONNECTION: | 
|  | 1597 | case OPEN_GLOBAL_TRANSACTION: | 
|  | 1598 | case CLOSE_GLOBAL_TRANSACTION: | 
|  | 1599 | case SET_ORIENTATION: | 
|  | 1600 | case FREEZE_DISPLAY: | 
|  | 1601 | case UNFREEZE_DISPLAY: | 
|  | 1602 | case BOOT_FINISHED: | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1603 | { | 
|  | 1604 | // codes that require permission check | 
|  | 1605 | IPCThreadState* ipc = IPCThreadState::self(); | 
|  | 1606 | const int pid = ipc->getCallingPid(); | 
| Mathias Agopian | a1ecca9 | 2009-05-21 19:21:59 -0700 | [diff] [blame] | 1607 | const int uid = ipc->getCallingUid(); | 
| Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 1608 | if ((uid != AID_GRAPHICS) && !mAccessSurfaceFlinger.check(pid, uid)) { | 
|  | 1609 | LOGE("Permission Denial: " | 
|  | 1610 | "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid); | 
|  | 1611 | return PERMISSION_DENIED; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1612 | } | 
|  | 1613 | } | 
|  | 1614 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1615 | status_t err = BnSurfaceComposer::onTransact(code, data, reply, flags); | 
|  | 1616 | if (err == UNKNOWN_TRANSACTION || err == PERMISSION_DENIED) { | 
| Mathias Agopian | b8a5560 | 2009-06-26 19:06:36 -0700 | [diff] [blame] | 1617 | CHECK_INTERFACE(ISurfaceComposer, data, reply); | 
| Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 1618 | if (UNLIKELY(!mHardwareTest.checkCalling())) { | 
|  | 1619 | IPCThreadState* ipc = IPCThreadState::self(); | 
|  | 1620 | const int pid = ipc->getCallingPid(); | 
|  | 1621 | const int uid = ipc->getCallingUid(); | 
|  | 1622 | LOGE("Permission Denial: " | 
|  | 1623 | "can't access SurfaceFlinger pid=%d, uid=%d", pid, uid); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1624 | return PERMISSION_DENIED; | 
|  | 1625 | } | 
|  | 1626 | int n; | 
|  | 1627 | switch (code) { | 
| Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 1628 | case 1000: // SHOW_CPU, NOT SUPPORTED ANYMORE | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1629 | return NO_ERROR; | 
| Mathias Agopian | cbc93ca | 2009-04-21 18:28:33 -0700 | [diff] [blame] | 1630 | case 1001:  // SHOW_FPS, NOT SUPPORTED ANYMORE | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1631 | return NO_ERROR; | 
|  | 1632 | case 1002:  // SHOW_UPDATES | 
|  | 1633 | n = data.readInt32(); | 
|  | 1634 | mDebugRegion = n ? n : (mDebugRegion ? 0 : 1); | 
|  | 1635 | return NO_ERROR; | 
|  | 1636 | case 1003:  // SHOW_BACKGROUND | 
|  | 1637 | n = data.readInt32(); | 
|  | 1638 | mDebugBackground = n ? 1 : 0; | 
|  | 1639 | return NO_ERROR; | 
|  | 1640 | case 1004:{ // repaint everything | 
|  | 1641 | Mutex::Autolock _l(mStateLock); | 
|  | 1642 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); | 
|  | 1643 | mDirtyRegion.set(hw.bounds()); // careful that's not thread-safe | 
|  | 1644 | signalEvent(); | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1645 | return NO_ERROR; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1646 | } | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1647 | case 1005:{ // force transaction | 
|  | 1648 | setTransactionFlags(eTransactionNeeded|eTraversalNeeded); | 
|  | 1649 | return NO_ERROR; | 
|  | 1650 | } | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1651 | case 1007: // set mFreezeCount | 
|  | 1652 | mFreezeCount = data.readInt32(); | 
| Mathias Agopian | 0408772 | 2009-12-01 17:23:28 -0800 | [diff] [blame] | 1653 | mFreezeDisplayTime = 0; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1654 | return NO_ERROR; | 
|  | 1655 | case 1010:  // interrogate. | 
| Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 1656 | reply->writeInt32(0); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1657 | reply->writeInt32(0); | 
|  | 1658 | reply->writeInt32(mDebugRegion); | 
|  | 1659 | reply->writeInt32(mDebugBackground); | 
|  | 1660 | return NO_ERROR; | 
|  | 1661 | case 1013: { | 
|  | 1662 | Mutex::Autolock _l(mStateLock); | 
|  | 1663 | const DisplayHardware& hw(graphicPlane(0).displayHardware()); | 
|  | 1664 | reply->writeInt32(hw.getPageFlipCount()); | 
|  | 1665 | } | 
|  | 1666 | return NO_ERROR; | 
|  | 1667 | } | 
|  | 1668 | } | 
|  | 1669 | return err; | 
|  | 1670 | } | 
|  | 1671 |  | 
|  | 1672 | // --------------------------------------------------------------------------- | 
|  | 1673 | #if 0 | 
|  | 1674 | #pragma mark - | 
|  | 1675 | #endif | 
|  | 1676 |  | 
|  | 1677 | Client::Client(ClientID clientID, const sp<SurfaceFlinger>& flinger) | 
|  | 1678 | : ctrlblk(0), cid(clientID), mPid(0), mBitmap(0), mFlinger(flinger) | 
|  | 1679 | { | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1680 | const int pgsize = getpagesize(); | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1681 | const int cblksize = ((sizeof(SharedClient)+(pgsize-1))&~(pgsize-1)); | 
| Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 1682 |  | 
|  | 1683 | mCblkHeap = new MemoryHeapBase(cblksize, 0, | 
|  | 1684 | "SurfaceFlinger Client control-block"); | 
|  | 1685 |  | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1686 | ctrlblk = static_cast<SharedClient *>(mCblkHeap->getBase()); | 
| Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 1687 | if (ctrlblk) { // construct the shared structure in-place. | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1688 | new(ctrlblk) SharedClient; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1689 | } | 
|  | 1690 | } | 
|  | 1691 |  | 
|  | 1692 | Client::~Client() { | 
|  | 1693 | if (ctrlblk) { | 
| Mathias Agopian | cbb288b | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 1694 | ctrlblk->~SharedClient();  // destroy our shared-structure. | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1695 | } | 
|  | 1696 | } | 
|  | 1697 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1698 | int32_t Client::generateId(int pid) | 
|  | 1699 | { | 
|  | 1700 | const uint32_t i = clz( ~mBitmap ); | 
|  | 1701 | if (i >= NUM_LAYERS_MAX) { | 
|  | 1702 | return NO_MEMORY; | 
|  | 1703 | } | 
|  | 1704 | mPid = pid; | 
|  | 1705 | mInUse.add(uint8_t(i)); | 
|  | 1706 | mBitmap |= 1<<(31-i); | 
|  | 1707 | return i; | 
|  | 1708 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1709 |  | 
|  | 1710 | status_t Client::bindLayer(const sp<LayerBaseClient>& layer, int32_t id) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1711 | { | 
|  | 1712 | ssize_t idx = mInUse.indexOf(id); | 
|  | 1713 | if (idx < 0) | 
|  | 1714 | return NAME_NOT_FOUND; | 
|  | 1715 | return mLayers.insertAt(layer, idx); | 
|  | 1716 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1717 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1718 | void Client::free(int32_t id) | 
|  | 1719 | { | 
|  | 1720 | ssize_t idx = mInUse.remove(uint8_t(id)); | 
|  | 1721 | if (idx >= 0) { | 
|  | 1722 | mBitmap &= ~(1<<(31-id)); | 
|  | 1723 | mLayers.removeItemsAt(idx); | 
|  | 1724 | } | 
|  | 1725 | } | 
|  | 1726 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1727 | bool Client::isValid(int32_t i) const { | 
|  | 1728 | return (uint32_t(i)<NUM_LAYERS_MAX) && (mBitmap & (1<<(31-i))); | 
|  | 1729 | } | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1730 |  | 
|  | 1731 | sp<LayerBaseClient> Client::getLayerUser(int32_t i) const { | 
|  | 1732 | sp<LayerBaseClient> lbc; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1733 | ssize_t idx = mInUse.indexOf(uint8_t(i)); | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1734 | if (idx >= 0) { | 
|  | 1735 | lbc = mLayers[idx].promote(); | 
|  | 1736 | LOGE_IF(lbc==0, "getLayerUser(i=%d), idx=%d is dead", int(i), int(idx)); | 
|  | 1737 | } | 
|  | 1738 | return lbc; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1739 | } | 
|  | 1740 |  | 
|  | 1741 | void Client::dump(const char* what) | 
|  | 1742 | { | 
|  | 1743 | } | 
|  | 1744 |  | 
|  | 1745 | // --------------------------------------------------------------------------- | 
|  | 1746 | #if 0 | 
|  | 1747 | #pragma mark - | 
|  | 1748 | #endif | 
|  | 1749 |  | 
| Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 1750 | BClient::BClient(SurfaceFlinger *flinger, ClientID cid, const sp<IMemoryHeap>& cblk) | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1751 | : mId(cid), mFlinger(flinger), mCblk(cblk) | 
|  | 1752 | { | 
|  | 1753 | } | 
|  | 1754 |  | 
|  | 1755 | BClient::~BClient() { | 
|  | 1756 | // destroy all resources attached to this client | 
|  | 1757 | mFlinger->destroyConnection(mId); | 
|  | 1758 | } | 
|  | 1759 |  | 
| Mathias Agopian | 7303c6b | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 1760 | sp<IMemoryHeap> BClient::getControlBlock() const { | 
|  | 1761 | return mCblk; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1762 | } | 
|  | 1763 |  | 
|  | 1764 | sp<ISurface> BClient::createSurface( | 
|  | 1765 | ISurfaceFlingerClient::surface_data_t* params, int pid, | 
|  | 1766 | DisplayID display, uint32_t w, uint32_t h, PixelFormat format, | 
|  | 1767 | uint32_t flags) | 
|  | 1768 | { | 
|  | 1769 | return mFlinger->createSurface(mId, pid, params, display, w, h, format, flags); | 
|  | 1770 | } | 
|  | 1771 |  | 
|  | 1772 | status_t BClient::destroySurface(SurfaceID sid) | 
|  | 1773 | { | 
|  | 1774 | sid |= (mId << 16); // add the client-part to id | 
| Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 1775 | return mFlinger->removeSurface(sid); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1776 | } | 
|  | 1777 |  | 
|  | 1778 | status_t BClient::setState(int32_t count, const layer_state_t* states) | 
|  | 1779 | { | 
|  | 1780 | return mFlinger->setClientState(mId, count, states); | 
|  | 1781 | } | 
|  | 1782 |  | 
|  | 1783 | // --------------------------------------------------------------------------- | 
|  | 1784 |  | 
|  | 1785 | GraphicPlane::GraphicPlane() | 
|  | 1786 | : mHw(0) | 
|  | 1787 | { | 
|  | 1788 | } | 
|  | 1789 |  | 
|  | 1790 | GraphicPlane::~GraphicPlane() { | 
|  | 1791 | delete mHw; | 
|  | 1792 | } | 
|  | 1793 |  | 
|  | 1794 | bool GraphicPlane::initialized() const { | 
|  | 1795 | return mHw ? true : false; | 
|  | 1796 | } | 
|  | 1797 |  | 
|  | 1798 | void GraphicPlane::setDisplayHardware(DisplayHardware *hw) { | 
|  | 1799 | mHw = hw; | 
|  | 1800 | } | 
|  | 1801 |  | 
|  | 1802 | void GraphicPlane::setTransform(const Transform& tr) { | 
|  | 1803 | mTransform = tr; | 
|  | 1804 | mGlobalTransform = mOrientationTransform * mTransform; | 
|  | 1805 | } | 
|  | 1806 |  | 
|  | 1807 | status_t GraphicPlane::orientationToTransfrom( | 
|  | 1808 | int orientation, int w, int h, Transform* tr) | 
|  | 1809 | { | 
|  | 1810 | float a, b, c, d, x, y; | 
|  | 1811 | switch (orientation) { | 
|  | 1812 | case ISurfaceComposer::eOrientationDefault: | 
|  | 1813 | a=1; b=0; c=0; d=1; x=0; y=0; | 
|  | 1814 | break; | 
|  | 1815 | case ISurfaceComposer::eOrientation90: | 
|  | 1816 | a=0; b=-1; c=1; d=0; x=w; y=0; | 
|  | 1817 | break; | 
|  | 1818 | case ISurfaceComposer::eOrientation180: | 
|  | 1819 | a=-1; b=0; c=0; d=-1; x=w; y=h; | 
|  | 1820 | break; | 
|  | 1821 | case ISurfaceComposer::eOrientation270: | 
|  | 1822 | a=0; b=1; c=-1; d=0; x=0; y=h; | 
|  | 1823 | break; | 
|  | 1824 | default: | 
|  | 1825 | return BAD_VALUE; | 
|  | 1826 | } | 
|  | 1827 | tr->set(a, b, c, d); | 
|  | 1828 | tr->set(x, y); | 
|  | 1829 | return NO_ERROR; | 
|  | 1830 | } | 
|  | 1831 |  | 
|  | 1832 | status_t GraphicPlane::setOrientation(int orientation) | 
|  | 1833 | { | 
|  | 1834 | const DisplayHardware& hw(displayHardware()); | 
|  | 1835 | const float w = hw.getWidth(); | 
|  | 1836 | const float h = hw.getHeight(); | 
|  | 1837 |  | 
|  | 1838 | if (orientation == ISurfaceComposer::eOrientationDefault) { | 
|  | 1839 | // make sure the default orientation is optimal | 
|  | 1840 | mOrientationTransform.reset(); | 
| Mathias Agopian | 0d1318b | 2009-03-27 17:58:20 -0700 | [diff] [blame] | 1841 | mOrientation = orientation; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1842 | mGlobalTransform = mTransform; | 
|  | 1843 | return NO_ERROR; | 
|  | 1844 | } | 
|  | 1845 |  | 
|  | 1846 | // If the rotation can be handled in hardware, this is where | 
|  | 1847 | // the magic should happen. | 
|  | 1848 | if (UNLIKELY(orientation == 42)) { | 
|  | 1849 | float a, b, c, d, x, y; | 
|  | 1850 | const float r = (3.14159265f / 180.0f) * 42.0f; | 
|  | 1851 | const float si = sinf(r); | 
|  | 1852 | const float co = cosf(r); | 
|  | 1853 | a=co; b=-si; c=si; d=co; | 
|  | 1854 | x = si*(h*0.5f) + (1-co)*(w*0.5f); | 
|  | 1855 | y =-si*(w*0.5f) + (1-co)*(h*0.5f); | 
|  | 1856 | mOrientationTransform.set(a, b, c, d); | 
|  | 1857 | mOrientationTransform.set(x, y); | 
|  | 1858 | } else { | 
|  | 1859 | GraphicPlane::orientationToTransfrom(orientation, w, h, | 
|  | 1860 | &mOrientationTransform); | 
|  | 1861 | } | 
| Mathias Agopian | 0d1318b | 2009-03-27 17:58:20 -0700 | [diff] [blame] | 1862 | mOrientation = orientation; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1863 | mGlobalTransform = mOrientationTransform * mTransform; | 
|  | 1864 | return NO_ERROR; | 
|  | 1865 | } | 
|  | 1866 |  | 
|  | 1867 | const DisplayHardware& GraphicPlane::displayHardware() const { | 
|  | 1868 | return *mHw; | 
|  | 1869 | } | 
|  | 1870 |  | 
|  | 1871 | const Transform& GraphicPlane::transform() const { | 
|  | 1872 | return mGlobalTransform; | 
|  | 1873 | } | 
|  | 1874 |  | 
| Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 1875 | EGLDisplay GraphicPlane::getEGLDisplay() const { | 
|  | 1876 | return mHw->getEGLDisplay(); | 
|  | 1877 | } | 
|  | 1878 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1879 | // --------------------------------------------------------------------------- | 
|  | 1880 |  | 
|  | 1881 | }; // namespace android |