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> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <pixelflinger/pixelflinger.h> |
| 25 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 26 | #include <EGL/egl.h> |
| 27 | #include <EGL/eglext.h> |
| 28 | #include <GLES/gl.h> |
| 29 | #include <GLES/glext.h> |
| 30 | |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 31 | #include "Buffer.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | #include "LayerBase.h" |
| 33 | #include "Transform.h" |
| 34 | |
| 35 | namespace android { |
| 36 | |
| 37 | // --------------------------------------------------------------------------- |
| 38 | |
| 39 | class Client; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | class FreezeLock; |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 41 | class Buffer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
| 43 | // --------------------------------------------------------------------------- |
| 44 | |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 45 | const size_t NUM_BUFFERS = 2; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 46 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | class Layer : public LayerBaseClient |
| 48 | { |
| 49 | public: |
| 50 | static const uint32_t typeInfo; |
| 51 | static const char* const typeID; |
| 52 | virtual char const* getTypeID() const { return typeID; } |
| 53 | virtual uint32_t getTypeInfo() const { return typeInfo; } |
| 54 | |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 55 | |
| 56 | SharedBufferServer* lcblk; |
| 57 | |
| 58 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | Layer(SurfaceFlinger* flinger, DisplayID display, |
Mathias Agopian | 6edf5af | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 60 | const sp<Client>& client, int32_t i); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | |
| 62 | virtual ~Layer(); |
| 63 | |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 64 | status_t setBuffers(uint32_t w, uint32_t h, |
| 65 | PixelFormat format, uint32_t flags=0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 67 | void setDrawingSize(uint32_t w, uint32_t h); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | |
| 69 | virtual void onDraw(const Region& clip) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | virtual uint32_t doTransaction(uint32_t transactionFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | virtual void lockPageFlip(bool& recomputeVisibleRegions); |
| 72 | virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion); |
| 73 | virtual void finishPageFlip(); |
| 74 | virtual bool needsBlending() const { return mNeedsBlending; } |
| 75 | virtual bool isSecure() const { return mSecure; } |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 76 | virtual sp<Surface> createSurface() const; |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 77 | virtual status_t ditch(); |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 78 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | // only for debugging |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 80 | inline sp<Buffer> getBuffer(int i) { return mBuffers[i]; } |
| 81 | // only for debugging |
| 82 | inline const sp<FreezeLock>& getFreezeLock() const { return mFreezeLock; } |
| 83 | // only for debugging |
| 84 | inline PixelFormat pixelFormat() const { return mFormat; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | |
| 86 | private: |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 87 | inline sp<Buffer> getFrontBuffer() { |
| 88 | return mBuffers[mFrontBufferIndex]; |
| 89 | } |
| 90 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | void reloadTexture(const Region& dirty); |
| 92 | |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 93 | sp<SurfaceBuffer> requestBuffer(int index, int usage); |
Mathias Agopian | a3aa6c9 | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 94 | void destroy(); |
| 95 | |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 96 | class SurfaceLayer : public LayerBaseClient::Surface { |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 97 | public: |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 98 | SurfaceLayer(const sp<SurfaceFlinger>& flinger, |
| 99 | SurfaceID id, const sp<Layer>& owner); |
| 100 | ~SurfaceLayer(); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 101 | private: |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 102 | virtual sp<SurfaceBuffer> requestBuffer(int index, int usage); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 103 | sp<Layer> getOwner() const { |
| 104 | return static_cast<Layer*>(Surface::getOwner().get()); |
| 105 | } |
| 106 | }; |
| 107 | friend class SurfaceLayer; |
| 108 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | sp<Surface> mSurface; |
| 110 | |
| 111 | bool mSecure; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | int32_t mFrontBufferIndex; |
| 113 | bool mNeedsBlending; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | Region mPostedDirtyRegion; |
| 115 | sp<FreezeLock> mFreezeLock; |
Mathias Agopian | 9779b221 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 116 | PixelFormat mFormat; |
| 117 | uint32_t mBufferFlags; |
| 118 | |
| 119 | // protected by mLock |
| 120 | sp<Buffer> mBuffers[NUM_BUFFERS]; |
| 121 | Texture mTextures[NUM_BUFFERS]; |
| 122 | uint32_t mWidth; |
| 123 | uint32_t mHeight; |
| 124 | |
| 125 | mutable Mutex mLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | // --------------------------------------------------------------------------- |
| 129 | |
| 130 | }; // namespace android |
| 131 | |
| 132 | #endif // ANDROID_LAYER_H |