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; |
| 45 | class MemoryDealer; |
| 46 | class FreezeLock; |
| 47 | |
| 48 | // --------------------------------------------------------------------------- |
| 49 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 50 | const int NUM_BUFFERS = 2; |
| 51 | |
The Android Open Source Project | edbf3b6 | 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, |
| 61 | Client* c, int32_t i); |
| 62 | |
| 63 | virtual ~Layer(); |
| 64 | |
| 65 | inline PixelFormat pixelFormat() const { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 66 | return frontBuffer().getPixelFormat(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | status_t setBuffers( Client* client, |
| 70 | uint32_t w, uint32_t h, |
| 71 | PixelFormat format, uint32_t flags=0); |
| 72 | |
| 73 | virtual void onDraw(const Region& clip) const; |
| 74 | virtual void initStates(uint32_t w, uint32_t h, uint32_t flags); |
| 75 | virtual void setSizeChanged(uint32_t w, uint32_t h); |
| 76 | virtual uint32_t doTransaction(uint32_t transactionFlags); |
| 77 | virtual Point getPhysicalSize() const; |
| 78 | virtual void lockPageFlip(bool& recomputeVisibleRegions); |
| 79 | virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion); |
| 80 | virtual void finishPageFlip(); |
| 81 | virtual bool needsBlending() const { return mNeedsBlending; } |
| 82 | virtual bool isSecure() const { return mSecure; } |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 83 | virtual sp<Surface> createSurface() const; |
The Android Open Source Project | edbf3b6 | 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 | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 105 | sp<SurfaceBuffer> peekBuffer(); |
| 106 | |
| 107 | |
| 108 | class SurfaceLayer : public LayerBaseClient::Surface |
| 109 | { |
| 110 | public: |
| 111 | SurfaceLayer(SurfaceID id, const sp<Layer>& owner); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 113 | private: |
| 114 | virtual sp<SurfaceBuffer> getBuffer(); |
| 115 | |
| 116 | sp<Layer> getOwner() const { |
| 117 | return static_cast<Layer*>(Surface::getOwner().get()); |
| 118 | } |
| 119 | }; |
| 120 | friend class SurfaceLayer; |
| 121 | |
| 122 | struct Texture { |
| 123 | Texture() : name(-1U), width(0), height(0), image(EGL_NO_IMAGE_KHR), |
| 124 | dirty(true) { } |
| 125 | GLuint name; |
| 126 | GLuint width; |
| 127 | GLuint height; |
| 128 | EGLImageKHR image; |
| 129 | bool dirty; |
| 130 | }; |
| 131 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | sp<Surface> mSurface; |
| 133 | |
| 134 | bool mSecure; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 135 | LayerBitmap mBuffers[NUM_BUFFERS]; |
| 136 | Texture mTextures[NUM_BUFFERS]; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | int32_t mFrontBufferIndex; |
| 138 | bool mNeedsBlending; |
| 139 | bool mResizeTransactionDone; |
| 140 | Region mPostedDirtyRegion; |
| 141 | sp<FreezeLock> mFreezeLock; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | // --------------------------------------------------------------------------- |
| 145 | |
| 146 | }; // namespace android |
| 147 | |
| 148 | #endif // ANDROID_LAYER_H |