| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2007 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #ifndef ANDROID_UI_SURFACE_H | 
|  | 18 | #define ANDROID_UI_SURFACE_H | 
|  | 19 |  | 
|  | 20 | #include <stdint.h> | 
|  | 21 | #include <sys/types.h> | 
|  | 22 |  | 
|  | 23 | #include <utils/RefBase.h> | 
|  | 24 | #include <utils/threads.h> | 
|  | 25 |  | 
|  | 26 | #include <ui/ISurface.h> | 
|  | 27 | #include <ui/PixelFormat.h> | 
|  | 28 | #include <ui/Region.h> | 
|  | 29 | #include <ui/ISurfaceFlingerClient.h> | 
|  | 30 |  | 
|  | 31 | namespace android { | 
|  | 32 |  | 
|  | 33 | // --------------------------------------------------------------------------- | 
|  | 34 |  | 
|  | 35 | class Rect; | 
|  | 36 | class SurfaceComposerClient; | 
|  | 37 |  | 
|  | 38 | class Surface : public RefBase | 
|  | 39 | { | 
|  | 40 |  | 
|  | 41 | public: | 
|  | 42 | struct SurfaceInfo { | 
|  | 43 | uint32_t    w; | 
|  | 44 | uint32_t    h; | 
|  | 45 | uint32_t    bpr; | 
|  | 46 | PixelFormat format; | 
|  | 47 | void*       bits; | 
|  | 48 | void*       base; | 
|  | 49 | uint32_t    reserved[2]; | 
|  | 50 | }; | 
|  | 51 |  | 
|  | 52 | bool        isValid() const { return this && mToken>=0 && mClient!=0; } | 
|  | 53 | SurfaceID   ID() const      { return mToken; } | 
|  | 54 |  | 
|  | 55 | status_t    lock(SurfaceInfo* info, bool blocking = true); | 
|  | 56 | status_t    lock(SurfaceInfo* info, Region* dirty, bool blocking = true); | 
|  | 57 | status_t    unlockAndPost(); | 
|  | 58 | status_t    unlock(); | 
|  | 59 |  | 
|  | 60 | void*       heapBase(int i) const; | 
|  | 61 | uint32_t    getFlags() const { return mFlags; } | 
|  | 62 |  | 
|  | 63 | // setSwapRectangle() is mainly used by EGL | 
|  | 64 | void        setSwapRectangle(const Rect& r); | 
|  | 65 | const Rect& swapRectangle() const; | 
|  | 66 | status_t    nextBuffer(SurfaceInfo* info); | 
|  | 67 |  | 
|  | 68 | sp<Surface>         dup() const; | 
|  | 69 | static sp<Surface>  readFromParcel(Parcel* parcel); | 
|  | 70 | static status_t     writeToParcel(const sp<Surface>& surface, Parcel* parcel); | 
|  | 71 | static bool         isSameSurface(const sp<Surface>& lhs, const sp<Surface>& rhs); | 
|  | 72 |  | 
|  | 73 | status_t    setLayer(int32_t layer); | 
|  | 74 | status_t    setPosition(int32_t x, int32_t y); | 
|  | 75 | status_t    setSize(uint32_t w, uint32_t h); | 
|  | 76 | status_t    hide(); | 
|  | 77 | status_t    show(int32_t layer = -1); | 
|  | 78 | status_t    freeze(); | 
|  | 79 | status_t    unfreeze(); | 
|  | 80 | status_t    setFlags(uint32_t flags, uint32_t mask); | 
|  | 81 | status_t    setTransparentRegionHint(const Region& transparent); | 
|  | 82 | status_t    setAlpha(float alpha=1.0f); | 
|  | 83 | status_t    setMatrix(float dsdx, float dtdx, float dsdy, float dtdy); | 
|  | 84 | status_t    setFreezeTint(uint32_t tint); | 
|  | 85 |  | 
|  | 86 | uint32_t    getIdentity() const { return mIdentity; } | 
|  | 87 | private: | 
|  | 88 | friend class SurfaceComposerClient; | 
|  | 89 |  | 
|  | 90 | // camera and camcorder need access to the ISurface binder interface for preview | 
|  | 91 | friend class Camera; | 
|  | 92 | friend class MediaRecorder; | 
|  | 93 | // mediaplayer needs access to ISurface for display | 
|  | 94 | friend class MediaPlayer; | 
|  | 95 | friend class Test; | 
|  | 96 | const sp<ISurface>& getISurface() const { return mSurface; } | 
|  | 97 |  | 
|  | 98 | // can't be copied | 
|  | 99 | Surface& operator = (Surface& rhs); | 
|  | 100 | Surface(const Surface& rhs); | 
|  | 101 |  | 
|  | 102 | Surface(const sp<SurfaceComposerClient>& client, | 
|  | 103 | const sp<ISurface>& surface, | 
|  | 104 | const ISurfaceFlingerClient::surface_data_t& data, | 
|  | 105 | uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, | 
|  | 106 | bool owner = true); | 
|  | 107 |  | 
|  | 108 | Surface(Surface const* rhs); | 
|  | 109 |  | 
|  | 110 | ~Surface(); | 
|  | 111 |  | 
|  | 112 | Region dirtyRegion() const; | 
|  | 113 | void setDirtyRegion(const Region& region) const; | 
|  | 114 |  | 
|  | 115 | // this locks protects calls to lockSurface() / unlockSurface() | 
|  | 116 | // and is called by SurfaceComposerClient. | 
|  | 117 | Mutex& getLock() const { return mSurfaceLock; } | 
|  | 118 |  | 
|  | 119 | sp<SurfaceComposerClient>   mClient; | 
|  | 120 | sp<ISurface>                mSurface; | 
|  | 121 | sp<IMemoryHeap>             mHeap[2]; | 
|  | 122 | SurfaceID                   mToken; | 
|  | 123 | uint32_t                    mIdentity; | 
|  | 124 | PixelFormat                 mFormat; | 
|  | 125 | uint32_t                    mFlags; | 
|  | 126 | const bool                  mOwner; | 
|  | 127 | mutable void*               mSurfaceHeapBase[2]; | 
|  | 128 | mutable Region              mDirtyRegion; | 
|  | 129 | mutable Rect                mSwapRectangle; | 
|  | 130 | mutable uint8_t             mBackbufferIndex; | 
|  | 131 | mutable Mutex               mSurfaceLock; | 
|  | 132 | }; | 
|  | 133 |  | 
|  | 134 | }; // namespace android | 
|  | 135 |  | 
|  | 136 | #endif // ANDROID_UI_SURFACE_H | 
|  | 137 |  |