blob: a82767b7559e4ea411aee990721bd6f0aada001c [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 Agopian90ac7992012-02-25 18:48:35 -080023#include <utils/Timers.h>
24
Mathias Agopian3330b202009-10-05 17:07:12 -070025#include <ui/GraphicBuffer.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026#include <ui/PixelFormat.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
Mathias Agopian90ac7992012-02-25 18:48:35 -080028#include <gui/ISurfaceComposerClient.h>
29
Mathias Agopian076b1cc2009-04-10 14:24:30 -070030#include <EGL/egl.h>
31#include <EGL/eglext.h>
32#include <GLES/gl.h>
33#include <GLES/glext.h>
34
Andy McFaddenbf974ab2012-12-04 16:51:15 -080035#include "SurfaceFlingerConsumer.h"
Jamie Gennis82dbc742012-11-08 19:23:28 -080036#include "FrameTracker.h"
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
Andy McFadden882e3a32013-01-08 16:06:15 -080050/*
51 * The Layer class is essentially a LayerBase combined with a BufferQueue.
52 * A new BufferQueue and a new SurfaceFlingerConsumer are created when the
53 * Layer is first referenced.
54 *
55 * This also implements onFrameAvailable(), which notifies SurfaceFlinger
56 * that new data has arrived.
57 */
Igor Murashkina4a31492012-10-29 13:36:11 -070058class Layer : public LayerBaseClient,
Andy McFaddenbf974ab2012-12-04 16:51:15 -080059 public SurfaceFlingerConsumer::FrameAvailableListener
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060{
Mathias Agopiand606de62010-05-10 20:06:11 -070061public:
Andy McFadden882e3a32013-01-08 16:06:15 -080062 Layer(SurfaceFlinger* flinger, const sp<Client>& client);
Mathias Agopianb7e930d2010-06-01 15:12:58 -070063 virtual ~Layer();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064
Mathias Agopianb7e930d2010-06-01 15:12:58 -070065 virtual const char* getTypeId() const { return "Layer"; }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066
Mathias Agopianb7e930d2010-06-01 15:12:58 -070067 // the this layer's size and format
Mathias Agopiancbb288b2009-09-07 16:32:45 -070068 status_t setBuffers(uint32_t w, uint32_t h,
69 PixelFormat format, uint32_t flags=0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080070
Mathias Agopiana138f892010-05-21 17:24:35 -070071 bool isFixedSize() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080072
Mathias Agopianb7e930d2010-06-01 15:12:58 -070073 // LayerBase interface
Mathias Agopian42977342012-08-05 00:40:46 -070074 virtual void setGeometry(const sp<const DisplayDevice>& hw,
Mathias Agopian4fec8732012-06-29 14:12:52 -070075 HWComposer::HWCLayerInterface& layer);
Mathias Agopian42977342012-08-05 00:40:46 -070076 virtual void setPerFrameData(const sp<const DisplayDevice>& hw,
Mathias Agopiand3ee2312012-08-02 14:01:42 -070077 HWComposer::HWCLayerInterface& layer);
Mathias Agopian42977342012-08-05 00:40:46 -070078 virtual void setAcquireFence(const sp<const DisplayDevice>& hw,
Mathias Agopiand3ee2312012-08-02 14:01:42 -070079 HWComposer::HWCLayerInterface& layer);
Mathias Agopian42977342012-08-05 00:40:46 -070080 virtual void onLayerDisplayed(const sp<const DisplayDevice>& hw,
Mathias Agopiand3ee2312012-08-02 14:01:42 -070081 HWComposer::HWCLayerInterface* layer);
82 virtual bool onPreComposition();
83 virtual void onPostComposition();
Mathias Agopian4fec8732012-06-29 14:12:52 -070084
Mathias Agopian42977342012-08-05 00:40:46 -070085 virtual void onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080086 virtual uint32_t doTransaction(uint32_t transactionFlags);
Mathias Agopian4fec8732012-06-29 14:12:52 -070087 virtual Region latchBuffer(bool& recomputeVisibleRegions);
Mathias Agopiana67932f2011-04-20 14:20:59 -070088 virtual bool isOpaque() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080089 virtual bool isSecure() const { return mSecure; }
Jamie Gennis7a4d0df2011-03-09 17:05:02 -080090 virtual bool isProtected() const;
Mathias Agopiand606de62010-05-10 20:06:11 -070091 virtual void onRemoved();
Mathias Agopianfb4d5d52011-09-20 15:13:14 -070092 virtual sp<Layer> getLayer() const { return const_cast<Layer*>(this); }
Jamie Gennisa249f2d2011-09-16 17:31:54 -070093 virtual void setName(const String8& name);
Mathias Agopianda27af92012-09-13 18:17:13 -070094 virtual bool isVisible() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080095
Jamie Gennis582270d2011-08-17 18:19:00 -070096 // LayerBaseClient interface
97 virtual wp<IBinder> getSurfaceTextureBinder() const;
98
Mathias Agopianb7e930d2010-06-01 15:12:58 -070099 // only for debugging
Mathias Agopianfb4d5d52011-09-20 15:13:14 -0700100 inline const sp<GraphicBuffer>& getActiveBuffer() const { return mActiveBuffer; }
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700101
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800102 // Updates the transform hint in our SurfaceFlingerConsumer to match
Mathias Agopian84300952012-11-21 16:02:13 -0800103 // the current orientation of the display device.
104 virtual void updateTransformHint(const sp<const DisplayDevice>& hw) const;
Andy McFadden69052052012-09-14 16:10:11 -0700105
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700106protected:
Mathias Agopiana67932f2011-04-20 14:20:59 -0700107 virtual void onFirstRef();
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700108 virtual void dump(String8& result, char* scratch, size_t size) const;
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800109 virtual void dumpStats(String8& result, char* buffer, size_t SIZE) const;
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800110 virtual void clearStats();
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700111
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800112private:
Andy McFadden882e3a32013-01-08 16:06:15 -0800113 // Creates an instance of ISurface for this Layer.
Mathias Agopiana67932f2011-04-20 14:20:59 -0700114 virtual sp<ISurface> createSurface();
Andy McFadden882e3a32013-01-08 16:06:15 -0800115
Mathias Agopian3330b202009-10-05 17:07:12 -0700116 uint32_t getEffectiveUsage(uint32_t usage) const;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700117 bool isCropped() const;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700118 Rect computeBufferCrop() const;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700119 static bool getOpacityForFormat(uint32_t format);
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700120
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800121 // Interface implementation for SurfaceFlingerConsumer::FrameAvailableListener
Igor Murashkina4a31492012-10-29 13:36:11 -0700122 virtual void onFrameAvailable();
123
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700124 // -----------------------------------------------------------------------
125
Mathias Agopiana67932f2011-04-20 14:20:59 -0700126 // constants
Andy McFaddenbf974ab2012-12-04 16:51:15 -0800127 sp<SurfaceFlingerConsumer> mSurfaceFlingerConsumer;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700128 GLuint mTextureName;
Mathias Agopiand606de62010-05-10 20:06:11 -0700129
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700130 // thread-safe
Mathias Agopiana67932f2011-04-20 14:20:59 -0700131 volatile int32_t mQueuedFrames;
Jamie Gennis4b0eba92013-02-05 13:30:24 -0800132 FrameTracker mFrameTracker;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700133
134 // main thread
135 sp<GraphicBuffer> mActiveBuffer;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700136 Rect mCurrentCrop;
137 uint32_t mCurrentTransform;
Mathias Agopian933389f2011-07-18 16:15:08 -0700138 uint32_t mCurrentScalingMode;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700139 bool mCurrentOpacity;
Mathias Agopian4d143ee2012-02-23 20:05:39 -0800140 bool mRefreshPending;
Jamie Gennise8696a42012-01-15 18:54:57 -0800141 bool mFrameLatencyNeeded;
Mathias Agopiand606de62010-05-10 20:06:11 -0700142
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700143 // constants
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700144 PixelFormat mFormat;
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700145 const GLExtensions& mGLExtensions;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700146 bool mOpaqueLayer;
Mathias Agopiand606de62010-05-10 20:06:11 -0700147
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700148 // page-flip thread (currently main thread)
Glenn Kasten16f04532011-01-19 15:27:27 -0800149 bool mSecure; // no screenshots
150 bool mProtectedByApp; // application requires protected path to external sink
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800151};
152
153// ---------------------------------------------------------------------------
154
155}; // namespace android
156
157#endif // ANDROID_LAYER_H