The Android Open Source Project | 9066cfe | 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_H |
| 18 | #define ANDROID_LAYER_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <ui/PixelFormat.h> |
| 24 | |
| 25 | #include <private/ui/SharedState.h> |
| 26 | #include <private/ui/LayerState.h> |
| 27 | |
| 28 | #include <pixelflinger/pixelflinger.h> |
| 29 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 30 | #include <EGL/egl.h> |
| 31 | #include <EGL/eglext.h> |
| 32 | #include <GLES/gl.h> |
| 33 | #include <GLES/glext.h> |
| 34 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | #include "LayerBitmap.h" |
| 36 | #include "LayerBase.h" |
| 37 | #include "Transform.h" |
| 38 | |
| 39 | namespace android { |
| 40 | |
| 41 | // --------------------------------------------------------------------------- |
| 42 | |
| 43 | class Client; |
| 44 | class LayerBitmap; |
| 45 | class MemoryDealer; |
| 46 | class FreezeLock; |
| 47 | |
| 48 | // --------------------------------------------------------------------------- |
| 49 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 50 | const int NUM_BUFFERS = 2; |
| 51 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | class Layer : public LayerBaseClient |
| 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 | Layer(SurfaceFlinger* flinger, DisplayID display, |
Mathias Agopian | 6edf5af | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 61 | const sp<Client>& client, int32_t i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | |
| 63 | virtual ~Layer(); |
| 64 | |
| 65 | inline PixelFormat pixelFormat() const { |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 66 | return frontBuffer().getPixelFormat(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Mathias Agopian | 6edf5af | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 69 | status_t setBuffers( uint32_t w, uint32_t h, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | PixelFormat format, uint32_t flags=0); |
| 71 | |
| 72 | virtual void onDraw(const Region& clip) const; |
| 73 | virtual void initStates(uint32_t w, uint32_t h, uint32_t flags); |
| 74 | virtual void setSizeChanged(uint32_t w, uint32_t h); |
| 75 | virtual uint32_t doTransaction(uint32_t transactionFlags); |
| 76 | virtual Point getPhysicalSize() const; |
| 77 | virtual void lockPageFlip(bool& recomputeVisibleRegions); |
| 78 | virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion); |
| 79 | virtual void finishPageFlip(); |
| 80 | virtual bool needsBlending() const { return mNeedsBlending; } |
| 81 | virtual bool isSecure() const { return mSecure; } |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 82 | virtual sp<Surface> createSurface() const; |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 83 | virtual status_t ditch(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | |
| 85 | const LayerBitmap& getBuffer(int i) const { return mBuffers[i]; } |
| 86 | LayerBitmap& getBuffer(int i) { return mBuffers[i]; } |
| 87 | |
| 88 | // only for debugging |
| 89 | const sp<FreezeLock>& getFreezeLock() const { return mFreezeLock; } |
| 90 | |
| 91 | private: |
| 92 | inline const LayerBitmap& |
| 93 | frontBuffer() const { return getBuffer(mFrontBufferIndex); } |
| 94 | inline LayerBitmap& |
| 95 | frontBuffer() { return getBuffer(mFrontBufferIndex); } |
| 96 | inline const LayerBitmap& |
| 97 | backBuffer() const { return getBuffer(1-mFrontBufferIndex); } |
| 98 | inline LayerBitmap& |
| 99 | backBuffer() { return getBuffer(1-mFrontBufferIndex); } |
| 100 | |
| 101 | void reloadTexture(const Region& dirty); |
| 102 | |
| 103 | status_t resize(int32_t index, uint32_t w, uint32_t h, const char* what); |
| 104 | Region post(uint32_t* oldState, bool& recomputeVisibleRegions); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 105 | sp<SurfaceBuffer> peekBuffer(); |
Mathias Agopian | a3aa6c9 | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 106 | void destroy(); |
Mathias Agopian | 6edf5af | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 107 | void scheduleBroadcast(); |
Mathias Agopian | a3aa6c9 | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 108 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 109 | |
| 110 | class SurfaceLayer : public LayerBaseClient::Surface |
| 111 | { |
| 112 | public: |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 113 | SurfaceLayer(const sp<SurfaceFlinger>& flinger, |
| 114 | SurfaceID id, const sp<Layer>& owner); |
| 115 | ~SurfaceLayer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 117 | private: |
| 118 | virtual sp<SurfaceBuffer> getBuffer(); |
| 119 | |
| 120 | sp<Layer> getOwner() const { |
| 121 | return static_cast<Layer*>(Surface::getOwner().get()); |
| 122 | } |
| 123 | }; |
| 124 | friend class SurfaceLayer; |
| 125 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | sp<Surface> mSurface; |
| 127 | |
| 128 | bool mSecure; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 129 | LayerBitmap mBuffers[NUM_BUFFERS]; |
| 130 | Texture mTextures[NUM_BUFFERS]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | int32_t mFrontBufferIndex; |
| 132 | bool mNeedsBlending; |
| 133 | bool mResizeTransactionDone; |
| 134 | Region mPostedDirtyRegion; |
| 135 | sp<FreezeLock> mFreezeLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | // --------------------------------------------------------------------------- |
| 139 | |
| 140 | }; // namespace android |
| 141 | |
| 142 | #endif // ANDROID_LAYER_H |