blob: 9a04848593cd30d71025f87b92b26dd5fc8760c0 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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 Agopiana67932f2011-04-20 14:20:59 -070023#include <gui/SurfaceTexture.h>
24
Mathias Agopian90ac7992012-02-25 18:48:35 -080025#include <utils/Timers.h>
26
Mathias Agopian3330b202009-10-05 17:07:12 -070027#include <ui/GraphicBuffer.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028#include <ui/PixelFormat.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080029
Mathias Agopian90ac7992012-02-25 18:48:35 -080030#include <gui/ISurfaceComposerClient.h>
31
Mathias Agopian076b1cc2009-04-10 14:24:30 -070032#include <EGL/egl.h>
33#include <EGL/eglext.h>
34#include <GLES/gl.h>
35#include <GLES/glext.h>
36
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037#include "LayerBase.h"
Mathias Agopiana67932f2011-04-20 14:20:59 -070038#include "SurfaceTextureLayer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080039#include "Transform.h"
40
41namespace android {
42
43// ---------------------------------------------------------------------------
44
Mathias Agopian1f7bec62010-06-25 18:02:21 -070045class Client;
46class GLExtensions;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047
48// ---------------------------------------------------------------------------
49
Mathias Agopian47d08122011-08-11 18:18:50 -070050class Layer : public LayerBaseClient
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051{
Mathias Agopiand606de62010-05-10 20:06:11 -070052public:
Mathias Agopianb7e930d2010-06-01 15:12:58 -070053 Layer(SurfaceFlinger* flinger, DisplayID display,
54 const sp<Client>& client);
Mathias Agopiand606de62010-05-10 20:06:11 -070055
Mathias Agopianb7e930d2010-06-01 15:12:58 -070056 virtual ~Layer();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057
Mathias Agopianb7e930d2010-06-01 15:12:58 -070058 virtual const char* getTypeId() const { return "Layer"; }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080059
Mathias Agopianb7e930d2010-06-01 15:12:58 -070060 // the this layer's size and format
Mathias Agopiancbb288b2009-09-07 16:32:45 -070061 status_t setBuffers(uint32_t w, uint32_t h,
62 PixelFormat format, uint32_t flags=0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063
Mathias Agopiana138f892010-05-21 17:24:35 -070064 bool isFixedSize() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065
Mathias Agopianb7e930d2010-06-01 15:12:58 -070066 // LayerBase interface
Mathias Agopiana350ff92010-08-10 17:14:02 -070067 virtual void setGeometry(hwc_layer_t* hwcl);
68 virtual void setPerFrameData(hwc_layer_t* hwcl);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069 virtual void onDraw(const Region& clip) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080070 virtual uint32_t doTransaction(uint32_t transactionFlags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080071 virtual void lockPageFlip(bool& recomputeVisibleRegions);
72 virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
Mathias Agopiana67932f2011-04-20 14:20:59 -070073 virtual bool isOpaque() const;
Mathias Agopian401c2572009-09-23 19:16:27 -070074 virtual bool needsDithering() const { return mNeedsDithering; }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080075 virtual bool isSecure() const { return mSecure; }
Jamie Gennis7a4d0df2011-03-09 17:05:02 -080076 virtual bool isProtected() const;
Mathias Agopiand606de62010-05-10 20:06:11 -070077 virtual void onRemoved();
Mathias Agopianfb4d5d52011-09-20 15:13:14 -070078 virtual sp<Layer> getLayer() const { return const_cast<Layer*>(this); }
Jamie Gennisa249f2d2011-09-16 17:31:54 -070079 virtual void setName(const String8& name);
Daniel Lamb2675792012-02-23 14:35:13 -080080 virtual void validateVisibility(const Transform& globalTransform);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080081
Jamie Gennis582270d2011-08-17 18:19:00 -070082 // LayerBaseClient interface
83 virtual wp<IBinder> getSurfaceTextureBinder() const;
84
Jamie Gennise8696a42012-01-15 18:54:57 -080085 virtual void onLayerDisplayed();
Mathias Agopian99ce5cd2012-01-31 18:24:27 -080086 virtual bool onPreComposition();
Jamie Gennise8696a42012-01-15 18:54:57 -080087
Mathias Agopianb7e930d2010-06-01 15:12:58 -070088 // only for debugging
Mathias Agopianfb4d5d52011-09-20 15:13:14 -070089 inline const sp<GraphicBuffer>& getActiveBuffer() const { return mActiveBuffer; }
Mathias Agopian1b5e1022010-04-20 17:55:49 -070090
91protected:
Mathias Agopiana67932f2011-04-20 14:20:59 -070092 virtual void onFirstRef();
Mathias Agopian1b5e1022010-04-20 17:55:49 -070093 virtual void dump(String8& result, char* scratch, size_t size) const;
Mathias Agopian82d7ab62012-01-19 18:34:40 -080094 virtual void dumpStats(String8& result, char* buffer, size_t SIZE) const;
Mathias Agopian25e66fc2012-01-28 22:31:55 -080095 virtual void clearStats();
Mathias Agopian1b5e1022010-04-20 17:55:49 -070096
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080097private:
Mathias Agopiana67932f2011-04-20 14:20:59 -070098 friend class SurfaceTextureLayer;
99 void onFrameQueued();
100 virtual sp<ISurface> createSurface();
Mathias Agopian3330b202009-10-05 17:07:12 -0700101 uint32_t getEffectiveUsage(uint32_t usage) const;
Mathias Agopiana4583642011-08-23 18:03:18 -0700102 uint32_t getTransformHint() const;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700103 bool isCropped() const;
104 static bool getOpacityForFormat(uint32_t format);
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700105
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700106 // -----------------------------------------------------------------------
107
Mathias Agopiana67932f2011-04-20 14:20:59 -0700108 // constants
Daniel Lamb2675792012-02-23 14:35:13 -0800109 sp<SurfaceTexture> mSurfaceTexture;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700110 GLuint mTextureName;
Mathias Agopiand606de62010-05-10 20:06:11 -0700111
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700112 // thread-safe
Mathias Agopiana67932f2011-04-20 14:20:59 -0700113 volatile int32_t mQueuedFrames;
114
115 // main thread
116 sp<GraphicBuffer> mActiveBuffer;
117 GLfloat mTextureMatrix[16];
118 Rect mCurrentCrop;
119 uint32_t mCurrentTransform;
Mathias Agopian933389f2011-07-18 16:15:08 -0700120 uint32_t mCurrentScalingMode;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700121 bool mCurrentOpacity;
Mathias Agopian4d143ee2012-02-23 20:05:39 -0800122 bool mRefreshPending;
Jamie Gennise8696a42012-01-15 18:54:57 -0800123 bool mFrameLatencyNeeded;
124 int mFrameLatencyOffset;
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800125
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800126 struct Statistics {
127 Statistics() : timestamp(0), set(0), vsync(0) { }
128 nsecs_t timestamp; // buffer timestamp
129 nsecs_t set; // buffer displayed timestamp
130 nsecs_t vsync; // vsync immediately before set
131 };
Mathias Agopian99ce5cd2012-01-31 18:24:27 -0800132
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800133 // protected by mLock
134 Statistics mFrameStats[128];
Mathias Agopiand606de62010-05-10 20:06:11 -0700135
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700136 // constants
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700137 PixelFormat mFormat;
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700138 const GLExtensions& mGLExtensions;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700139 bool mOpaqueLayer;
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700140 bool mNeedsDithering;
Mathias Agopiand606de62010-05-10 20:06:11 -0700141
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700142 // page-flip thread (currently main thread)
Glenn Kasten16f04532011-01-19 15:27:27 -0800143 bool mSecure; // no screenshots
144 bool mProtectedByApp; // application requires protected path to external sink
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700145 Region mPostedDirtyRegion;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800146};
147
148// ---------------------------------------------------------------------------
149
150}; // namespace android
151
152#endif // ANDROID_LAYER_H