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 | |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 23 | #include <gui/SurfaceTexture.h> |
| 24 | |
| 25 | #include <pixelflinger/pixelflinger.h> |
Mathias Agopian | 6950e42 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 26 | #include <ui/GraphicBuffer.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | #include <ui/PixelFormat.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 29 | #include <EGL/egl.h> |
| 30 | #include <EGL/eglext.h> |
| 31 | #include <GLES/gl.h> |
| 32 | #include <GLES/glext.h> |
| 33 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | #include "LayerBase.h" |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 35 | #include "SurfaceTextureLayer.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | #include "Transform.h" |
| 37 | |
| 38 | namespace android { |
| 39 | |
| 40 | // --------------------------------------------------------------------------- |
| 41 | |
Andreas Huber | 330dd30 | 2010-06-25 09:25:19 -0700 | [diff] [blame] | 42 | class FreezeLock; |
Mathias Agopian | 781953d | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 43 | class Client; |
| 44 | class GLExtensions; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | |
| 46 | // --------------------------------------------------------------------------- |
| 47 | |
Mathias Agopian | 91b5398 | 2011-08-11 18:18:50 -0700 | [diff] [blame] | 48 | class Layer : public LayerBaseClient |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | { |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 50 | public: |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 51 | Layer(SurfaceFlinger* flinger, DisplayID display, |
| 52 | const sp<Client>& client); |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 53 | |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 54 | virtual ~Layer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 56 | virtual const char* getTypeId() const { return "Layer"; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 58 | // the this layer's size and format |
Mathias Agopian | 9779b22 | 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 | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | |
Mathias Agopian | 2be352a | 2010-05-21 17:24:35 -0700 | [diff] [blame] | 62 | bool isFixedSize() const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 64 | // LayerBase interface |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 65 | virtual void setGeometry(hwc_layer_t* hwcl); |
| 66 | virtual void setPerFrameData(hwc_layer_t* hwcl); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | virtual void onDraw(const Region& clip) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | virtual uint32_t doTransaction(uint32_t transactionFlags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | virtual void lockPageFlip(bool& recomputeVisibleRegions); |
| 70 | virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion); |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 71 | virtual bool isOpaque() const; |
Mathias Agopian | cc93476 | 2009-09-23 19:16:27 -0700 | [diff] [blame] | 72 | virtual bool needsDithering() const { return mNeedsDithering; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | virtual bool isSecure() const { return mSecure; } |
Jamie Gennis | f72606c | 2011-03-09 17:05:02 -0800 | [diff] [blame] | 74 | virtual bool isProtected() const; |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 75 | virtual void onRemoved(); |
Mathias Agopian | 880ac7a | 2011-09-20 15:13:14 -0700 | [diff] [blame] | 76 | virtual sp<Layer> getLayer() const { return const_cast<Layer*>(this); } |
Jamie Gennis | 5b315da | 2011-09-16 17:31:54 -0700 | [diff] [blame] | 77 | virtual void setName(const String8& name); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | |
Jamie Gennis | 9b8fc65 | 2011-08-17 18:19:00 -0700 | [diff] [blame] | 79 | // LayerBaseClient interface |
| 80 | virtual wp<IBinder> getSurfaceTextureBinder() const; |
| 81 | |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 82 | // only for debugging |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 83 | inline const sp<FreezeLock>& getFreezeLock() const { return mFreezeLock; } |
Mathias Agopian | 880ac7a | 2011-09-20 15:13:14 -0700 | [diff] [blame] | 84 | inline const sp<GraphicBuffer>& getActiveBuffer() const { return mActiveBuffer; } |
Mathias Agopian | 9bce873 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 85 | |
| 86 | protected: |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 87 | virtual void onFirstRef(); |
Mathias Agopian | 9bce873 | 2010-04-20 17:55:49 -0700 | [diff] [blame] | 88 | virtual void dump(String8& result, char* scratch, size_t size) const; |
| 89 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | private: |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 91 | friend class SurfaceTextureLayer; |
| 92 | void onFrameQueued(); |
| 93 | virtual sp<ISurface> createSurface(); |
Mathias Agopian | 6950e42 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 94 | uint32_t getEffectiveUsage(uint32_t usage) const; |
Mathias Agopian | 2143fe0 | 2011-08-23 18:03:18 -0700 | [diff] [blame] | 95 | uint32_t getTransformHint() const; |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 96 | bool isCropped() const; |
| 97 | static bool getOpacityForFormat(uint32_t format); |
Mathias Agopian | a3aa6c9 | 2009-04-22 15:23:34 -0700 | [diff] [blame] | 98 | |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 99 | // ----------------------------------------------------------------------- |
| 100 | |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 101 | // constants |
| 102 | sp<SurfaceTextureLayer> mSurfaceTexture; |
| 103 | GLuint mTextureName; |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 104 | |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 105 | // thread-safe |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 106 | volatile int32_t mQueuedFrames; |
| 107 | |
| 108 | // main thread |
| 109 | sp<GraphicBuffer> mActiveBuffer; |
| 110 | GLfloat mTextureMatrix[16]; |
| 111 | Rect mCurrentCrop; |
| 112 | uint32_t mCurrentTransform; |
Mathias Agopian | ff86f37 | 2011-07-18 16:15:08 -0700 | [diff] [blame] | 113 | uint32_t mCurrentScalingMode; |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 114 | bool mCurrentOpacity; |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 115 | |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 116 | // constants |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 117 | PixelFormat mFormat; |
Mathias Agopian | 781953d | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 118 | const GLExtensions& mGLExtensions; |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 119 | bool mOpaqueLayer; |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 120 | bool mNeedsDithering; |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 121 | |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 122 | // page-flip thread (currently main thread) |
Glenn Kasten | d6f5bde | 2011-01-19 15:27:27 -0800 | [diff] [blame] | 123 | bool mSecure; // no screenshots |
| 124 | bool mProtectedByApp; // application requires protected path to external sink |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 125 | Region mPostedDirtyRegion; |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 126 | |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 127 | // page-flip thread and transaction thread (currently main thread) |
| 128 | sp<FreezeLock> mFreezeLock; |
Mathias Agopian | 9f2c4fd | 2010-05-10 20:06:11 -0700 | [diff] [blame] | 129 | |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 130 | // binder thread, transaction thread |
| 131 | mutable Mutex mLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | // --------------------------------------------------------------------------- |
| 135 | |
| 136 | }; // namespace android |
| 137 | |
| 138 | #endif // ANDROID_LAYER_H |