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