blob: bf30608c971319f80d663c7805ab13387a883f8f [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 Agopian7bb843c2011-04-20 14:20:59 -070023#include <gui/SurfaceTexture.h>
24
25#include <pixelflinger/pixelflinger.h>
Mathias Agopian6950e422009-10-05 17:07:12 -070026#include <ui/GraphicBuffer.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027#include <ui/PixelFormat.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028
Mathias Agopian1473f462009-04-10 14:24:30 -070029#include <EGL/egl.h>
30#include <EGL/eglext.h>
31#include <GLES/gl.h>
32#include <GLES/glext.h>
33
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034#include "LayerBase.h"
Mathias Agopian7bb843c2011-04-20 14:20:59 -070035#include "SurfaceTextureLayer.h"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036#include "Transform.h"
Mathias Agopian1d997952012-01-19 18:34:40 -080037#include <utils/Timers.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038
39namespace android {
40
41// ---------------------------------------------------------------------------
42
Mathias Agopian781953d2010-06-25 18:02:21 -070043class Client;
44class GLExtensions;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
46// ---------------------------------------------------------------------------
47
Mathias Agopian91b53982011-08-11 18:18:50 -070048class Layer : public LayerBaseClient
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049{
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -070050public:
Mathias Agopian7623da42010-06-01 15:12:58 -070051 Layer(SurfaceFlinger* flinger, DisplayID display,
52 const sp<Client>& client);
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -070053
Mathias Agopian7623da42010-06-01 15:12:58 -070054 virtual ~Layer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080055
Mathias Agopian7623da42010-06-01 15:12:58 -070056 virtual const char* getTypeId() const { return "Layer"; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080057
Mathias Agopian7623da42010-06-01 15:12:58 -070058 // the this layer's size and format
Mathias Agopian9779b2212009-09-07 16:32:45 -070059 status_t setBuffers(uint32_t w, uint32_t h,
60 PixelFormat format, uint32_t flags=0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061
Mathias Agopian2be352a2010-05-21 17:24:35 -070062 bool isFixedSize() const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063
Mathias Agopian7623da42010-06-01 15:12:58 -070064 // LayerBase interface
Mathias Agopiane0d5f5b2010-08-10 17:14:02 -070065 virtual void setGeometry(hwc_layer_t* hwcl);
66 virtual void setPerFrameData(hwc_layer_t* hwcl);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 virtual void onDraw(const Region& clip) const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 virtual uint32_t doTransaction(uint32_t transactionFlags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 virtual void lockPageFlip(bool& recomputeVisibleRegions);
70 virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
Mathias Agopian7bb843c2011-04-20 14:20:59 -070071 virtual bool isOpaque() const;
Mathias Agopiancc934762009-09-23 19:16:27 -070072 virtual bool needsDithering() const { return mNeedsDithering; }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 virtual bool isSecure() const { return mSecure; }
Jamie Gennisf72606c2011-03-09 17:05:02 -080074 virtual bool isProtected() const;
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -070075 virtual void onRemoved();
Mathias Agopian880ac7a2011-09-20 15:13:14 -070076 virtual sp<Layer> getLayer() const { return const_cast<Layer*>(this); }
Jamie Gennis5b315da2011-09-16 17:31:54 -070077 virtual void setName(const String8& name);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078
Jamie Gennis9b8fc652011-08-17 18:19:00 -070079 // LayerBaseClient interface
80 virtual wp<IBinder> getSurfaceTextureBinder() const;
81
Jamie Gennisb335fad2012-01-15 18:54:57 -080082 virtual void onLayerDisplayed();
Mathias Agopian9a9dbd52012-01-31 18:24:27 -080083 virtual bool onPreComposition();
Jamie Gennisb335fad2012-01-15 18:54:57 -080084
Mathias Agopian7623da42010-06-01 15:12:58 -070085 // only for debugging
Mathias Agopian880ac7a2011-09-20 15:13:14 -070086 inline const sp<GraphicBuffer>& getActiveBuffer() const { return mActiveBuffer; }
Mathias Agopian9bce8732010-04-20 17:55:49 -070087
88protected:
Mathias Agopian7bb843c2011-04-20 14:20:59 -070089 virtual void onFirstRef();
Mathias Agopian9bce8732010-04-20 17:55:49 -070090 virtual void dump(String8& result, char* scratch, size_t size) const;
Mathias Agopian1d997952012-01-19 18:34:40 -080091 virtual void dumpStats(String8& result, char* buffer, size_t SIZE) const;
Mathias Agopian8d1b5e32012-01-28 22:31:55 -080092 virtual void clearStats();
Mathias Agopian9bce8732010-04-20 17:55:49 -070093
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080094private:
Mathias Agopian7bb843c2011-04-20 14:20:59 -070095 friend class SurfaceTextureLayer;
96 void onFrameQueued();
97 virtual sp<ISurface> createSurface();
Mathias Agopian6950e422009-10-05 17:07:12 -070098 uint32_t getEffectiveUsage(uint32_t usage) const;
Mathias Agopian2143fe02011-08-23 18:03:18 -070099 uint32_t getTransformHint() const;
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700100 bool isCropped() const;
101 static bool getOpacityForFormat(uint32_t format);
Mathias Agopiana3aa6c92009-04-22 15:23:34 -0700102
Mathias Agopian7623da42010-06-01 15:12:58 -0700103 // -----------------------------------------------------------------------
104
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700105 // constants
106 sp<SurfaceTextureLayer> mSurfaceTexture;
107 GLuint mTextureName;
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700108
Mathias Agopian7623da42010-06-01 15:12:58 -0700109 // thread-safe
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700110 volatile int32_t mQueuedFrames;
111
112 // main thread
113 sp<GraphicBuffer> mActiveBuffer;
114 GLfloat mTextureMatrix[16];
115 Rect mCurrentCrop;
116 uint32_t mCurrentTransform;
Mathias Agopianff86f372011-07-18 16:15:08 -0700117 uint32_t mCurrentScalingMode;
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700118 bool mCurrentOpacity;
Mathias Agopian9a9dbd52012-01-31 18:24:27 -0800119 size_t mRefreshPending;
Jamie Gennisb335fad2012-01-15 18:54:57 -0800120 bool mFrameLatencyNeeded;
121 int mFrameLatencyOffset;
Mathias Agopian9a9dbd52012-01-31 18:24:27 -0800122
Mathias Agopian1d997952012-01-19 18:34:40 -0800123 struct Statistics {
124 Statistics() : timestamp(0), set(0), vsync(0) { }
125 nsecs_t timestamp; // buffer timestamp
126 nsecs_t set; // buffer displayed timestamp
127 nsecs_t vsync; // vsync immediately before set
128 };
Mathias Agopian9a9dbd52012-01-31 18:24:27 -0800129
Mathias Agopian1d997952012-01-19 18:34:40 -0800130 // protected by mLock
131 Statistics mFrameStats[128];
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700132
Mathias Agopian7623da42010-06-01 15:12:58 -0700133 // constants
Mathias Agopian7623da42010-06-01 15:12:58 -0700134 PixelFormat mFormat;
Mathias Agopian781953d2010-06-25 18:02:21 -0700135 const GLExtensions& mGLExtensions;
Mathias Agopian7bb843c2011-04-20 14:20:59 -0700136 bool mOpaqueLayer;
Mathias Agopian7623da42010-06-01 15:12:58 -0700137 bool mNeedsDithering;
Mathias Agopian9f2c4fd2010-05-10 20:06:11 -0700138
Mathias Agopian7623da42010-06-01 15:12:58 -0700139 // page-flip thread (currently main thread)
Glenn Kastend6f5bde2011-01-19 15:27:27 -0800140 bool mSecure; // no screenshots
141 bool mProtectedByApp; // application requires protected path to external sink
Mathias Agopian7623da42010-06-01 15:12:58 -0700142 Region mPostedDirtyRegion;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143};
144
145// ---------------------------------------------------------------------------
146
147}; // namespace android
148
149#endif // ANDROID_LAYER_H