blob: 4c13d6ea2887c0635e5703a027dbaba5a0d78226 [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>
24
25#include <private/ui/SharedState.h>
26#include <private/ui/LayerState.h>
27
28#include <pixelflinger/pixelflinger.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
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035#include "LayerBitmap.h"
36#include "LayerBase.h"
37#include "Transform.h"
38
39namespace android {
40
41// ---------------------------------------------------------------------------
42
43class Client;
44class LayerBitmap;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045class FreezeLock;
46
47// ---------------------------------------------------------------------------
48
Mathias Agopian076b1cc2009-04-10 14:24:30 -070049const int NUM_BUFFERS = 2;
50
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051class Layer : public LayerBaseClient
52{
53public:
54 static const uint32_t typeInfo;
55 static const char* const typeID;
56 virtual char const* getTypeID() const { return typeID; }
57 virtual uint32_t getTypeInfo() const { return typeInfo; }
58
59 Layer(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopianf9d93272009-06-19 17:00:27 -070060 const sp<Client>& client, int32_t i);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061
62 virtual ~Layer();
63
64 inline PixelFormat pixelFormat() const {
Mathias Agopian076b1cc2009-04-10 14:24:30 -070065 return frontBuffer().getPixelFormat();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066 }
67
Mathias Agopianf9d93272009-06-19 17:00:27 -070068 status_t setBuffers( uint32_t w, uint32_t h,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069 PixelFormat format, uint32_t flags=0);
70
71 virtual void onDraw(const Region& clip) const;
72 virtual void initStates(uint32_t w, uint32_t h, uint32_t flags);
73 virtual void setSizeChanged(uint32_t w, uint32_t h);
74 virtual uint32_t doTransaction(uint32_t transactionFlags);
75 virtual Point getPhysicalSize() const;
76 virtual void lockPageFlip(bool& recomputeVisibleRegions);
77 virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
78 virtual void finishPageFlip();
79 virtual bool needsBlending() const { return mNeedsBlending; }
80 virtual bool isSecure() const { return mSecure; }
Mathias Agopian076b1cc2009-04-10 14:24:30 -070081 virtual sp<Surface> createSurface() const;
Mathias Agopian9a112062009-04-17 19:36:26 -070082 virtual status_t ditch();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080083
84 const LayerBitmap& getBuffer(int i) const { return mBuffers[i]; }
85 LayerBitmap& getBuffer(int i) { return mBuffers[i]; }
86
87 // only for debugging
88 const sp<FreezeLock>& getFreezeLock() const { return mFreezeLock; }
89
90private:
91 inline const LayerBitmap&
92 frontBuffer() const { return getBuffer(mFrontBufferIndex); }
93 inline LayerBitmap&
94 frontBuffer() { return getBuffer(mFrontBufferIndex); }
95 inline const LayerBitmap&
96 backBuffer() const { return getBuffer(1-mFrontBufferIndex); }
97 inline LayerBitmap&
98 backBuffer() { return getBuffer(1-mFrontBufferIndex); }
99
100 void reloadTexture(const Region& dirty);
101
102 status_t resize(int32_t index, uint32_t w, uint32_t h, const char* what);
103 Region post(uint32_t* oldState, bool& recomputeVisibleRegions);
Fred Quintanab2fd4662009-08-11 20:49:35 -0700104 sp<SurfaceBuffer> peekBuffer();
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700105 void destroy();
Mathias Agopianf9d93272009-06-19 17:00:27 -0700106 void scheduleBroadcast();
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700107
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700108
109 class SurfaceLayer : public LayerBaseClient::Surface
110 {
111 public:
Mathias Agopian9a112062009-04-17 19:36:26 -0700112 SurfaceLayer(const sp<SurfaceFlinger>& flinger,
113 SurfaceID id, const sp<Layer>& owner);
114 ~SurfaceLayer();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800115
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700116 private:
Fred Quintanab2fd4662009-08-11 20:49:35 -0700117 virtual sp<SurfaceBuffer> getBuffer();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700118
119 sp<Layer> getOwner() const {
120 return static_cast<Layer*>(Surface::getOwner().get());
121 }
122 };
123 friend class SurfaceLayer;
124
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800125 sp<Surface> mSurface;
126
127 bool mSecure;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700128 LayerBitmap mBuffers[NUM_BUFFERS];
129 Texture mTextures[NUM_BUFFERS];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800130 int32_t mFrontBufferIndex;
131 bool mNeedsBlending;
132 bool mResizeTransactionDone;
133 Region mPostedDirtyRegion;
134 sp<FreezeLock> mFreezeLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800135};
136
137// ---------------------------------------------------------------------------
138
139}; // namespace android
140
141#endif // ANDROID_LAYER_H