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