blob: 3e8b2d635c5890578bdab1e173a48b6dea7bf3de [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
Jamie Gennis82dbc742012-11-08 19:23:28 -080037#include "FrameTracker.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038#include "LayerBase.h"
Mathias Agopiana67932f2011-04-20 14:20:59 -070039#include "SurfaceTextureLayer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040#include "Transform.h"
41
42namespace android {
43
44// ---------------------------------------------------------------------------
45
Mathias Agopian1f7bec62010-06-25 18:02:21 -070046class Client;
47class GLExtensions;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048
49// ---------------------------------------------------------------------------
50
Igor Murashkina4a31492012-10-29 13:36:11 -070051class Layer : public LayerBaseClient,
52 public SurfaceTexture::FrameAvailableListener
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053{
Mathias Agopiand606de62010-05-10 20:06:11 -070054public:
Mathias Agopian3ee454a2012-08-27 16:28:24 -070055 Layer(SurfaceFlinger* flinger, const sp<Client>& client);
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 Agopian42977342012-08-05 00:40:46 -070067 virtual void setGeometry(const sp<const DisplayDevice>& hw,
Mathias Agopian4fec8732012-06-29 14:12:52 -070068 HWComposer::HWCLayerInterface& layer);
Mathias Agopian42977342012-08-05 00:40:46 -070069 virtual void setPerFrameData(const sp<const DisplayDevice>& hw,
Mathias Agopiand3ee2312012-08-02 14:01:42 -070070 HWComposer::HWCLayerInterface& layer);
Mathias Agopian42977342012-08-05 00:40:46 -070071 virtual void setAcquireFence(const sp<const DisplayDevice>& hw,
Mathias Agopiand3ee2312012-08-02 14:01:42 -070072 HWComposer::HWCLayerInterface& layer);
Mathias Agopian42977342012-08-05 00:40:46 -070073 virtual void onLayerDisplayed(const sp<const DisplayDevice>& hw,
Mathias Agopiand3ee2312012-08-02 14:01:42 -070074 HWComposer::HWCLayerInterface* layer);
75 virtual bool onPreComposition();
76 virtual void onPostComposition();
Mathias Agopian4fec8732012-06-29 14:12:52 -070077
Mathias Agopian42977342012-08-05 00:40:46 -070078 virtual void onDraw(const sp<const DisplayDevice>& hw, const Region& clip) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080079 virtual uint32_t doTransaction(uint32_t transactionFlags);
Mathias Agopian4fec8732012-06-29 14:12:52 -070080 virtual Region latchBuffer(bool& recomputeVisibleRegions);
Mathias Agopiana67932f2011-04-20 14:20:59 -070081 virtual bool isOpaque() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080082 virtual bool isSecure() const { return mSecure; }
Jamie Gennis7a4d0df2011-03-09 17:05:02 -080083 virtual bool isProtected() const;
Mathias Agopiand606de62010-05-10 20:06:11 -070084 virtual void onRemoved();
Mathias Agopianfb4d5d52011-09-20 15:13:14 -070085 virtual sp<Layer> getLayer() const { return const_cast<Layer*>(this); }
Jamie Gennisa249f2d2011-09-16 17:31:54 -070086 virtual void setName(const String8& name);
Mathias Agopianda27af92012-09-13 18:17:13 -070087 virtual bool isVisible() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080088
Jamie Gennis582270d2011-08-17 18:19:00 -070089 // LayerBaseClient interface
90 virtual wp<IBinder> getSurfaceTextureBinder() const;
91
Mathias Agopianb7e930d2010-06-01 15:12:58 -070092 // only for debugging
Mathias Agopianfb4d5d52011-09-20 15:13:14 -070093 inline const sp<GraphicBuffer>& getActiveBuffer() const { return mActiveBuffer; }
Mathias Agopian1b5e1022010-04-20 17:55:49 -070094
Andy McFadden69052052012-09-14 16:10:11 -070095 // Updates the transform hint in our SurfaceTexture to match
96 // the current orientation of the default display device.
97 virtual void updateTransformHint() const;
98
Mathias Agopian1b5e1022010-04-20 17:55:49 -070099protected:
Mathias Agopiana67932f2011-04-20 14:20:59 -0700100 virtual void onFirstRef();
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700101 virtual void dump(String8& result, char* scratch, size_t size) const;
Mathias Agopian82d7ab62012-01-19 18:34:40 -0800102 virtual void dumpStats(String8& result, char* buffer, size_t SIZE) const;
Mathias Agopian25e66fc2012-01-28 22:31:55 -0800103 virtual void clearStats();
Mathias Agopian1b5e1022010-04-20 17:55:49 -0700104
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800105private:
Mathias Agopiana67932f2011-04-20 14:20:59 -0700106 friend class SurfaceTextureLayer;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700107 virtual sp<ISurface> createSurface();
Mathias Agopian3330b202009-10-05 17:07:12 -0700108 uint32_t getEffectiveUsage(uint32_t usage) const;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700109 bool isCropped() const;
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700110 Rect computeBufferCrop() const;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700111 static bool getOpacityForFormat(uint32_t format);
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700112
Igor Murashkina4a31492012-10-29 13:36:11 -0700113 // Interface implementation for SurfaceTexture::FrameAvailableListener
114 virtual void onFrameAvailable();
115
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700116 // -----------------------------------------------------------------------
117
Mathias Agopiana67932f2011-04-20 14:20:59 -0700118 // constants
Daniel Lamb2675792012-02-23 14:35:13 -0800119 sp<SurfaceTexture> mSurfaceTexture;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700120 GLuint mTextureName;
Mathias Agopiand606de62010-05-10 20:06:11 -0700121
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700122 // thread-safe
Mathias Agopiana67932f2011-04-20 14:20:59 -0700123 volatile int32_t mQueuedFrames;
124
125 // main thread
126 sp<GraphicBuffer> mActiveBuffer;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700127 Rect mCurrentCrop;
128 uint32_t mCurrentTransform;
Mathias Agopian933389f2011-07-18 16:15:08 -0700129 uint32_t mCurrentScalingMode;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700130 bool mCurrentOpacity;
Mathias Agopian4d143ee2012-02-23 20:05:39 -0800131 bool mRefreshPending;
Jamie Gennise8696a42012-01-15 18:54:57 -0800132 bool mFrameLatencyNeeded;
Jamie Gennis82dbc742012-11-08 19:23:28 -0800133 FrameTracker mFrameTracker;
Mathias Agopiand606de62010-05-10 20:06:11 -0700134
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700135 // constants
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700136 PixelFormat mFormat;
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700137 const GLExtensions& mGLExtensions;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700138 bool mOpaqueLayer;
Mathias Agopiand606de62010-05-10 20:06:11 -0700139
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700140 // page-flip thread (currently main thread)
Glenn Kasten16f04532011-01-19 15:27:27 -0800141 bool mSecure; // no screenshots
142 bool mProtectedByApp; // application requires protected path to external sink
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800143};
144
145// ---------------------------------------------------------------------------
146
147}; // namespace android
148
149#endif // ANDROID_LAYER_H