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_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 | 076b1cc | 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 | edbf3b6 | 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; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | class FreezeLock; |
| 46 | |
| 47 | // --------------------------------------------------------------------------- |
| 48 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 49 | const int NUM_BUFFERS = 2; |
| 50 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | class Layer : public LayerBaseClient |
| 52 | { |
| 53 | public: |
| 54 | static const uint32_t typeInfo; |
| 55 | static const char* const typeID; |
| 56 | virtual char const* getTypeID() const { return typeID; } |
| 57 | virtual uint32_t getTypeInfo() const { return typeInfo; } |
| 58 | |
| 59 | Layer(SurfaceFlinger* flinger, DisplayID display, |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 60 | const sp<Client>& client, int32_t i); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | |
| 62 | virtual ~Layer(); |
| 63 | |
| 64 | inline PixelFormat pixelFormat() const { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 65 | return frontBuffer().getPixelFormat(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | } |
| 67 | |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 68 | status_t setBuffers( uint32_t w, uint32_t h, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | PixelFormat format, uint32_t flags=0); |
| 70 | |
| 71 | virtual void onDraw(const Region& clip) const; |
| 72 | virtual void initStates(uint32_t w, uint32_t h, uint32_t flags); |
| 73 | virtual void setSizeChanged(uint32_t w, uint32_t h); |
| 74 | virtual uint32_t doTransaction(uint32_t transactionFlags); |
| 75 | virtual Point getPhysicalSize() const; |
| 76 | virtual void lockPageFlip(bool& recomputeVisibleRegions); |
| 77 | virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion); |
| 78 | virtual void finishPageFlip(); |
| 79 | virtual bool needsBlending() const { return mNeedsBlending; } |
| 80 | virtual bool isSecure() const { return mSecure; } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 81 | virtual sp<Surface> createSurface() const; |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 82 | virtual status_t ditch(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | |
| 84 | const LayerBitmap& getBuffer(int i) const { return mBuffers[i]; } |
| 85 | LayerBitmap& getBuffer(int i) { return mBuffers[i]; } |
| 86 | |
| 87 | // only for debugging |
| 88 | const sp<FreezeLock>& getFreezeLock() const { return mFreezeLock; } |
| 89 | |
| 90 | private: |
| 91 | inline const LayerBitmap& |
| 92 | frontBuffer() const { return getBuffer(mFrontBufferIndex); } |
| 93 | inline LayerBitmap& |
| 94 | frontBuffer() { return getBuffer(mFrontBufferIndex); } |
| 95 | inline const LayerBitmap& |
| 96 | backBuffer() const { return getBuffer(1-mFrontBufferIndex); } |
| 97 | inline LayerBitmap& |
| 98 | backBuffer() { return getBuffer(1-mFrontBufferIndex); } |
| 99 | |
| 100 | void reloadTexture(const Region& dirty); |
| 101 | |
| 102 | status_t resize(int32_t index, uint32_t w, uint32_t h, const char* what); |
| 103 | Region post(uint32_t* oldState, bool& recomputeVisibleRegions); |
Fred Quintana | b2fd466 | 2009-08-11 20:49:35 -0700 | [diff] [blame^] | 104 | sp<SurfaceBuffer> peekBuffer(); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 105 | void destroy(); |
Mathias Agopian | f9d9327 | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 106 | void scheduleBroadcast(); |
Mathias Agopian | 0aa758d | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 107 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 108 | |
| 109 | class SurfaceLayer : public LayerBaseClient::Surface |
| 110 | { |
| 111 | public: |
Mathias Agopian | 9a11206 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 112 | SurfaceLayer(const sp<SurfaceFlinger>& flinger, |
| 113 | SurfaceID id, const sp<Layer>& owner); |
| 114 | ~SurfaceLayer(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 116 | private: |
Fred Quintana | b2fd466 | 2009-08-11 20:49:35 -0700 | [diff] [blame^] | 117 | virtual sp<SurfaceBuffer> getBuffer(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 118 | |
| 119 | sp<Layer> getOwner() const { |
| 120 | return static_cast<Layer*>(Surface::getOwner().get()); |
| 121 | } |
| 122 | }; |
| 123 | friend class SurfaceLayer; |
| 124 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | sp<Surface> mSurface; |
| 126 | |
| 127 | bool mSecure; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 128 | LayerBitmap mBuffers[NUM_BUFFERS]; |
| 129 | Texture mTextures[NUM_BUFFERS]; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | int32_t mFrontBufferIndex; |
| 131 | bool mNeedsBlending; |
| 132 | bool mResizeTransactionDone; |
| 133 | Region mPostedDirtyRegion; |
| 134 | sp<FreezeLock> mFreezeLock; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | // --------------------------------------------------------------------------- |
| 138 | |
| 139 | }; // namespace android |
| 140 | |
| 141 | #endif // ANDROID_LAYER_H |