blob: 72e290ca92bc09a994592bdc5a485e161276d717 [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
25#include <pixelflinger/pixelflinger.h>
Mathias Agopian3330b202009-10-05 17:07:12 -070026#include <ui/GraphicBuffer.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027#include <ui/PixelFormat.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028
Mathias Agopian076b1cc2009-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 Projectedbf3b62009-03-03 19:31:44 -080034#include "LayerBase.h"
Mathias Agopiana67932f2011-04-20 14:20:59 -070035#include "SurfaceTextureLayer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036#include "Transform.h"
37
38namespace android {
39
40// ---------------------------------------------------------------------------
41
Andreas Hubere049a952010-06-25 09:25:19 -070042class FreezeLock;
Mathias Agopian1f7bec62010-06-25 18:02:21 -070043class Client;
44class GLExtensions;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045
46// ---------------------------------------------------------------------------
47
48class Layer : public LayerBaseClient
49{
Mathias Agopiand606de62010-05-10 20:06:11 -070050public:
Mathias Agopianb7e930d2010-06-01 15:12:58 -070051 Layer(SurfaceFlinger* flinger, DisplayID display,
52 const sp<Client>& client);
Mathias Agopiand606de62010-05-10 20:06:11 -070053
Mathias Agopianb7e930d2010-06-01 15:12:58 -070054 virtual ~Layer();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055
Mathias Agopianb7e930d2010-06-01 15:12:58 -070056 virtual const char* getTypeId() const { return "Layer"; }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057
Mathias Agopianb7e930d2010-06-01 15:12:58 -070058 // the this layer's size and format
Mathias Agopiancbb288b2009-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 Projectedbf3b62009-03-03 19:31:44 -080061
Mathias Agopianb7e930d2010-06-01 15:12:58 -070062 // Set this Layer's buffers size
Mathias Agopiana138f892010-05-21 17:24:35 -070063 bool isFixedSize() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064
Mathias Agopianb7e930d2010-06-01 15:12:58 -070065 // LayerBase interface
Mathias Agopiana350ff92010-08-10 17:14:02 -070066 virtual void setGeometry(hwc_layer_t* hwcl);
67 virtual void setPerFrameData(hwc_layer_t* hwcl);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080068 virtual void onDraw(const Region& clip) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069 virtual uint32_t doTransaction(uint32_t transactionFlags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080070 virtual void lockPageFlip(bool& recomputeVisibleRegions);
71 virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
Mathias Agopiana67932f2011-04-20 14:20:59 -070072 virtual bool isOpaque() const;
Mathias Agopian401c2572009-09-23 19:16:27 -070073 virtual bool needsDithering() const { return mNeedsDithering; }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080074 virtual bool isSecure() const { return mSecure; }
Jamie Gennis7a4d0df2011-03-09 17:05:02 -080075 virtual bool isProtected() const;
Mathias Agopiand606de62010-05-10 20:06:11 -070076 virtual void onRemoved();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080077
Mathias Agopianb7e930d2010-06-01 15:12:58 -070078 // only for debugging
Mathias Agopiana67932f2011-04-20 14:20:59 -070079 inline const sp<FreezeLock>& getFreezeLock() const { return mFreezeLock; }
Mathias Agopian1b5e1022010-04-20 17:55:49 -070080
81protected:
Mathias Agopianca4d3602011-05-19 15:38:14 -070082 virtual void destroy() const;
Mathias Agopiana67932f2011-04-20 14:20:59 -070083 virtual void onFirstRef();
Mathias Agopian1b5e1022010-04-20 17:55:49 -070084 virtual void dump(String8& result, char* scratch, size_t size) const;
85
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080086private:
Mathias Agopiana67932f2011-04-20 14:20:59 -070087 friend class SurfaceTextureLayer;
88 void onFrameQueued();
89 virtual sp<ISurface> createSurface();
Mathias Agopian3330b202009-10-05 17:07:12 -070090 uint32_t getEffectiveUsage(uint32_t usage) const;
Mathias Agopiana67932f2011-04-20 14:20:59 -070091 void setFixedSize(bool fixedSize);
92 bool isCropped() const;
93 static bool getOpacityForFormat(uint32_t format);
Mathias Agopian0aa758d2009-04-22 15:23:34 -070094
Mathias Agopianb7e930d2010-06-01 15:12:58 -070095 // -----------------------------------------------------------------------
96
Mathias Agopiana67932f2011-04-20 14:20:59 -070097 // constants
98 sp<SurfaceTextureLayer> mSurfaceTexture;
99 GLuint mTextureName;
Mathias Agopiand606de62010-05-10 20:06:11 -0700100
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700101 // thread-safe
Mathias Agopiana67932f2011-04-20 14:20:59 -0700102 volatile int32_t mQueuedFrames;
103
104 // main thread
105 sp<GraphicBuffer> mActiveBuffer;
106 GLfloat mTextureMatrix[16];
107 Rect mCurrentCrop;
108 uint32_t mCurrentTransform;
109 bool mCurrentOpacity;
Mathias Agopiand606de62010-05-10 20:06:11 -0700110
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700111 // constants
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700112 PixelFormat mFormat;
Mathias Agopian1f7bec62010-06-25 18:02:21 -0700113 const GLExtensions& mGLExtensions;
Mathias Agopiana67932f2011-04-20 14:20:59 -0700114 bool mOpaqueLayer;
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700115 bool mNeedsDithering;
Mathias Agopiand606de62010-05-10 20:06:11 -0700116
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700117 // page-flip thread (currently main thread)
Glenn Kasten16f04532011-01-19 15:27:27 -0800118 bool mSecure; // no screenshots
119 bool mProtectedByApp; // application requires protected path to external sink
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700120 Region mPostedDirtyRegion;
Mathias Agopiand606de62010-05-10 20:06:11 -0700121
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700122 // page-flip thread and transaction thread (currently main thread)
123 sp<FreezeLock> mFreezeLock;
Mathias Agopiand606de62010-05-10 20:06:11 -0700124
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700125 // binder thread, transaction thread
126 mutable Mutex mLock;
Mathias Agopianb7e930d2010-06-01 15:12:58 -0700127 bool mFixedSize;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800128};
129
130// ---------------------------------------------------------------------------
131
132}; // namespace android
133
134#endif // ANDROID_LAYER_H