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