blob: f111840fd77a8205a638b2a7b3b85c27de56c99b [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
23#include <ui/PixelFormat.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080024#include <pixelflinger/pixelflinger.h>
25
Mathias Agopian076b1cc2009-04-10 14:24:30 -070026#include <EGL/egl.h>
27#include <EGL/eglext.h>
28#include <GLES/gl.h>
29#include <GLES/glext.h>
30
Mathias Agopiancbb288b2009-09-07 16:32:45 -070031#include "Buffer.h"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032#include "LayerBase.h"
33#include "Transform.h"
34
35namespace android {
36
37// ---------------------------------------------------------------------------
38
39class Client;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040class FreezeLock;
Mathias Agopiancbb288b2009-09-07 16:32:45 -070041class Buffer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
43// ---------------------------------------------------------------------------
44
Mathias Agopiancbb288b2009-09-07 16:32:45 -070045const size_t NUM_BUFFERS = 2;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070046
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080047class Layer : public LayerBaseClient
48{
49public:
50 static const uint32_t typeInfo;
51 static const char* const typeID;
52 virtual char const* getTypeID() const { return typeID; }
53 virtual uint32_t getTypeInfo() const { return typeInfo; }
Mathias Agopiancbb288b2009-09-07 16:32:45 -070054
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055 Layer(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopianf9d93272009-06-19 17:00:27 -070056 const sp<Client>& client, int32_t i);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057
58 virtual ~Layer();
59
Mathias Agopiancbb288b2009-09-07 16:32:45 -070060 status_t setBuffers(uint32_t w, uint32_t h,
61 PixelFormat format, uint32_t flags=0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062
Mathias Agopiancbb288b2009-09-07 16:32:45 -070063 void setDrawingSize(uint32_t w, uint32_t h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064
65 virtual void onDraw(const Region& clip) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066 virtual uint32_t doTransaction(uint32_t transactionFlags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080067 virtual void lockPageFlip(bool& recomputeVisibleRegions);
68 virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
69 virtual void finishPageFlip();
70 virtual bool needsBlending() const { return mNeedsBlending; }
Mathias Agopian401c2572009-09-23 19:16:27 -070071 virtual bool needsDithering() const { return mNeedsDithering; }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080072 virtual bool isSecure() const { return mSecure; }
Mathias Agopian076b1cc2009-04-10 14:24:30 -070073 virtual sp<Surface> createSurface() const;
Mathias Agopian9a112062009-04-17 19:36:26 -070074 virtual status_t ditch();
Mathias Agopiancbb288b2009-09-07 16:32:45 -070075
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076 // only for debugging
Mathias Agopiancbb288b2009-09-07 16:32:45 -070077 inline sp<Buffer> getBuffer(int i) { return mBuffers[i]; }
78 // only for debugging
79 inline const sp<FreezeLock>& getFreezeLock() const { return mFreezeLock; }
80 // only for debugging
81 inline PixelFormat pixelFormat() const { return mFormat; }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080082
83private:
Mathias Agopiancbb288b2009-09-07 16:32:45 -070084 inline sp<Buffer> getFrontBuffer() {
85 return mBuffers[mFrontBufferIndex];
86 }
87
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080088 void reloadTexture(const Region& dirty);
89
Mathias Agopiancbb288b2009-09-07 16:32:45 -070090 sp<SurfaceBuffer> requestBuffer(int index, int usage);
Mathias Agopian0aa758d2009-04-22 15:23:34 -070091 void destroy();
92
Mathias Agopiancbb288b2009-09-07 16:32:45 -070093 class SurfaceLayer : public LayerBaseClient::Surface {
Mathias Agopian076b1cc2009-04-10 14:24:30 -070094 public:
Mathias Agopiancbb288b2009-09-07 16:32:45 -070095 SurfaceLayer(const sp<SurfaceFlinger>& flinger,
96 SurfaceID id, const sp<Layer>& owner);
97 ~SurfaceLayer();
Mathias Agopian076b1cc2009-04-10 14:24:30 -070098 private:
Mathias Agopiancbb288b2009-09-07 16:32:45 -070099 virtual sp<SurfaceBuffer> requestBuffer(int index, int usage);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700100 sp<Layer> getOwner() const {
101 return static_cast<Layer*>(Surface::getOwner().get());
102 }
103 };
104 friend class SurfaceLayer;
105
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106 sp<Surface> mSurface;
107
108 bool mSecure;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109 int32_t mFrontBufferIndex;
110 bool mNeedsBlending;
Mathias Agopian401c2572009-09-23 19:16:27 -0700111 bool mNeedsDithering;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800112 Region mPostedDirtyRegion;
113 sp<FreezeLock> mFreezeLock;
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700114 PixelFormat mFormat;
115 uint32_t mBufferFlags;
116
117 // protected by mLock
118 sp<Buffer> mBuffers[NUM_BUFFERS];
119 Texture mTextures[NUM_BUFFERS];
120 uint32_t mWidth;
121 uint32_t mHeight;
122
123 mutable Mutex mLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800124};
125
126// ---------------------------------------------------------------------------
127
128}; // namespace android
129
130#endif // ANDROID_LAYER_H