| 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_LAYER_BUFFER_H | 
|  | 18 | #define ANDROID_LAYER_BUFFER_H | 
|  | 19 |  | 
|  | 20 | #include <stdint.h> | 
|  | 21 | #include <sys/types.h> | 
|  | 22 |  | 
|  | 23 | #include <utils/IMemory.h> | 
|  | 24 | #include <private/ui/LayerState.h> | 
|  | 25 | #include <EGL/eglnatives.h> | 
|  | 26 |  | 
|  | 27 | #include "LayerBase.h" | 
|  | 28 | #include "LayerBitmap.h" | 
|  | 29 |  | 
|  | 30 | namespace android { | 
|  | 31 |  | 
|  | 32 | // --------------------------------------------------------------------------- | 
|  | 33 |  | 
|  | 34 | class MemoryDealer; | 
|  | 35 | class Region; | 
|  | 36 | class OverlayRef; | 
|  | 37 |  | 
|  | 38 | class LayerBuffer : public LayerBaseClient | 
|  | 39 | { | 
|  | 40 | class Source : public LightRefBase<Source> { | 
|  | 41 | public: | 
|  | 42 | Source(LayerBuffer& layer); | 
|  | 43 | virtual ~Source(); | 
|  | 44 | virtual void onDraw(const Region& clip) const; | 
|  | 45 | virtual void onTransaction(uint32_t flags); | 
|  | 46 | virtual void onVisibilityResolved(const Transform& planeTransform); | 
|  | 47 | virtual void postBuffer(ssize_t offset); | 
|  | 48 | virtual void unregisterBuffers(); | 
|  | 49 | virtual bool transformed() const; | 
|  | 50 | protected: | 
|  | 51 | LayerBuffer& mLayer; | 
|  | 52 | }; | 
|  | 53 |  | 
|  | 54 |  | 
|  | 55 | public: | 
|  | 56 | static const uint32_t typeInfo; | 
|  | 57 | static const char* const typeID; | 
|  | 58 | virtual char const* getTypeID() const { return typeID; } | 
|  | 59 | virtual uint32_t getTypeInfo() const { return typeInfo; } | 
|  | 60 |  | 
|  | 61 | LayerBuffer(SurfaceFlinger* flinger, DisplayID display, | 
|  | 62 | Client* client, int32_t i); | 
|  | 63 | virtual ~LayerBuffer(); | 
|  | 64 |  | 
|  | 65 | virtual bool needsBlending() const; | 
|  | 66 |  | 
|  | 67 | virtual sp<LayerBaseClient::Surface> getSurface() const; | 
|  | 68 | virtual void onDraw(const Region& clip) const; | 
|  | 69 | virtual uint32_t doTransaction(uint32_t flags); | 
|  | 70 | virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion); | 
|  | 71 | virtual bool transformed() const; | 
|  | 72 |  | 
|  | 73 | status_t registerBuffers(const ISurface::BufferHeap& buffers); | 
|  | 74 | void postBuffer(ssize_t offset); | 
|  | 75 | void unregisterBuffers(); | 
|  | 76 | sp<OverlayRef> createOverlay(uint32_t w, uint32_t h, int32_t format); | 
|  | 77 |  | 
|  | 78 | sp<Source> getSource() const; | 
|  | 79 | sp<Source> clearSource(); | 
|  | 80 | void setNeedsBlending(bool blending); | 
|  | 81 | const Rect& getTransformedBounds() const { | 
|  | 82 | return mTransformedBounds; | 
|  | 83 | } | 
|  | 84 |  | 
|  | 85 | private: | 
|  | 86 | struct NativeBuffer { | 
|  | 87 | copybit_image_t   img; | 
|  | 88 | copybit_rect_t    crop; | 
|  | 89 | }; | 
|  | 90 |  | 
|  | 91 | class Buffer : public LightRefBase<Buffer> { | 
|  | 92 | public: | 
|  | 93 | Buffer(const ISurface::BufferHeap& buffers, ssize_t offset); | 
|  | 94 | inline status_t getStatus() const { | 
|  | 95 | return mBufferHeap.heap!=0 ? NO_ERROR : NO_INIT; | 
|  | 96 | } | 
|  | 97 | inline const NativeBuffer& getBuffer() const { | 
|  | 98 | return mNativeBuffer; | 
|  | 99 | } | 
|  | 100 | protected: | 
|  | 101 | friend class LightRefBase<Buffer>; | 
|  | 102 | Buffer& operator = (const Buffer& rhs); | 
|  | 103 | Buffer(const Buffer& rhs); | 
|  | 104 | ~Buffer(); | 
|  | 105 | private: | 
|  | 106 | ISurface::BufferHeap    mBufferHeap; | 
|  | 107 | NativeBuffer            mNativeBuffer; | 
|  | 108 | }; | 
|  | 109 |  | 
|  | 110 | class BufferSource : public Source { | 
|  | 111 | public: | 
|  | 112 | BufferSource(LayerBuffer& layer, const ISurface::BufferHeap& buffers); | 
|  | 113 | virtual ~BufferSource(); | 
|  | 114 |  | 
|  | 115 | status_t getStatus() const { return mStatus; } | 
|  | 116 | sp<Buffer> getBuffer() const; | 
|  | 117 | void setBuffer(const sp<Buffer>& buffer); | 
|  | 118 |  | 
|  | 119 | virtual void onDraw(const Region& clip) const; | 
|  | 120 | virtual void postBuffer(ssize_t offset); | 
|  | 121 | virtual void unregisterBuffers(); | 
|  | 122 | virtual bool transformed() const; | 
|  | 123 | private: | 
|  | 124 | mutable Mutex   mLock; | 
|  | 125 | sp<Buffer>      mBuffer; | 
|  | 126 | status_t        mStatus; | 
|  | 127 | ISurface::BufferHeap mBufferHeap; | 
|  | 128 | size_t          mBufferSize; | 
|  | 129 | mutable sp<MemoryDealer> mTemporaryDealer; | 
|  | 130 | mutable LayerBitmap mTempBitmap; | 
|  | 131 | mutable GLuint  mTextureName; | 
|  | 132 | }; | 
|  | 133 |  | 
|  | 134 | class OverlaySource : public Source { | 
|  | 135 | public: | 
|  | 136 | OverlaySource(LayerBuffer& layer, | 
|  | 137 | sp<OverlayRef>* overlayRef, | 
|  | 138 | uint32_t w, uint32_t h, int32_t format); | 
|  | 139 | virtual ~OverlaySource(); | 
|  | 140 | virtual void onTransaction(uint32_t flags); | 
|  | 141 | virtual void onVisibilityResolved(const Transform& planeTransform); | 
|  | 142 | private: | 
|  | 143 | void serverDestroy(); | 
|  | 144 | void destroyOverlay(); | 
|  | 145 | class OverlayChannel : public BnOverlay { | 
|  | 146 | mutable Mutex mLock; | 
|  | 147 | sp<OverlaySource> mSource; | 
|  | 148 | virtual void destroy() { | 
|  | 149 | sp<OverlaySource> source; | 
|  | 150 | { // scope for the lock; | 
|  | 151 | Mutex::Autolock _l(mLock); | 
|  | 152 | source = mSource; | 
|  | 153 | mSource.clear(); | 
|  | 154 | } | 
|  | 155 | if (source != 0) { | 
|  | 156 | source->serverDestroy(); | 
|  | 157 | } | 
|  | 158 | } | 
|  | 159 | public: | 
|  | 160 | OverlayChannel(const sp<OverlaySource>& source) | 
|  | 161 | : mSource(source) { | 
|  | 162 | } | 
|  | 163 | }; | 
|  | 164 | friend class OverlayChannel; | 
|  | 165 | bool mVisibilityChanged; | 
|  | 166 |  | 
|  | 167 | overlay_t* mOverlay; | 
|  | 168 | overlay_handle_t mOverlayHandle; | 
|  | 169 | overlay_control_device_t* mOverlayDevice; | 
|  | 170 | uint32_t mWidth; | 
|  | 171 | uint32_t mHeight; | 
|  | 172 | int32_t mFormat; | 
|  | 173 | int32_t mWidthStride; | 
|  | 174 | int32_t mHeightStride; | 
|  | 175 | mutable Mutex mLock; | 
|  | 176 | }; | 
|  | 177 |  | 
|  | 178 |  | 
|  | 179 | class SurfaceBuffer : public LayerBaseClient::Surface | 
|  | 180 | { | 
|  | 181 | public: | 
|  | 182 | SurfaceBuffer(SurfaceID id, LayerBuffer* owner); | 
|  | 183 | virtual ~SurfaceBuffer(); | 
|  | 184 | virtual status_t onTransact( | 
|  | 185 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); | 
|  | 186 | virtual status_t registerBuffers(const ISurface::BufferHeap& buffers); | 
|  | 187 | virtual void postBuffer(ssize_t offset); | 
|  | 188 | virtual void unregisterBuffers(); | 
|  | 189 | virtual sp<OverlayRef> createOverlay( | 
|  | 190 | uint32_t w, uint32_t h, int32_t format); | 
|  | 191 | void disown(); | 
|  | 192 | private: | 
|  | 193 | LayerBuffer* getOwner() const { | 
|  | 194 | Mutex::Autolock _l(mLock); | 
|  | 195 | return mOwner; | 
|  | 196 | } | 
|  | 197 | mutable Mutex   mLock; | 
|  | 198 | LayerBuffer*    mOwner; | 
|  | 199 | }; | 
|  | 200 |  | 
|  | 201 | friend class SurfaceFlinger; | 
|  | 202 | sp<SurfaceBuffer>   getClientSurface() const; | 
|  | 203 |  | 
|  | 204 | mutable Mutex   mLock; | 
|  | 205 | sp<Source>      mSource; | 
|  | 206 |  | 
|  | 207 | bool            mInvalidate; | 
|  | 208 | bool            mNeedsBlending; | 
|  | 209 | mutable wp<SurfaceBuffer> mClientSurface; | 
|  | 210 | }; | 
|  | 211 |  | 
|  | 212 | // --------------------------------------------------------------------------- | 
|  | 213 |  | 
|  | 214 | }; // namespace android | 
|  | 215 |  | 
|  | 216 | #endif // ANDROID_LAYER_BUFFER_H |