The Android Open Source Project | 89fa4ad | 2009-03-03 19:31:44 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
| 18 | #ifndef ANDROID_SURFACE_FLINGER_SYNCHRO_H |
| 19 | #define ANDROID_SURFACE_FLINGER_SYNCHRO_H |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
| 23 | #include <utils/Errors.h> |
| 24 | #include <utils/threads.h> |
| 25 | #include <ui/ISurfaceComposer.h> |
| 26 | |
| 27 | namespace android { |
| 28 | |
| 29 | class SurfaceFlinger; |
| 30 | |
| 31 | class SurfaceFlingerSynchro |
| 32 | { |
| 33 | public: |
| 34 | |
| 35 | // client constructor |
| 36 | SurfaceFlingerSynchro(const sp<ISurfaceComposer>& flinger); |
| 37 | ~SurfaceFlingerSynchro(); |
| 38 | |
| 39 | // signal surfaceflinger for some work |
| 40 | status_t signal(); |
| 41 | |
| 42 | private: |
| 43 | class Barrier { |
| 44 | public: |
| 45 | Barrier(); |
| 46 | ~Barrier(); |
| 47 | void open(); |
| 48 | void close(); |
| 49 | void waitAndClose(); |
| 50 | status_t waitAndClose(nsecs_t timeout); |
| 51 | private: |
| 52 | enum { OPENED, CLOSED }; |
| 53 | mutable Mutex lock; |
| 54 | mutable Condition cv; |
| 55 | volatile int state; |
| 56 | }; |
| 57 | |
| 58 | friend class SurfaceFlinger; |
| 59 | |
| 60 | // server constructor |
| 61 | SurfaceFlingerSynchro(); |
| 62 | |
| 63 | void open(); |
| 64 | |
| 65 | // wait until there is some work to do |
| 66 | status_t wait(); |
| 67 | status_t wait(nsecs_t timeout); |
| 68 | |
| 69 | sp<ISurfaceComposer> mSurfaceComposer; |
| 70 | Barrier mBarrier; |
| 71 | }; |
| 72 | |
| 73 | }; // namespace android |
| 74 | |
| 75 | #endif // ANDROID_SURFACE_FLINGER_SYNCHRO_H |
| 76 | |