blob: e16d9f40d953890228ee25cc971e26930fef12a1 [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;
45class MemoryDealer;
46class FreezeLock;
47
48// ---------------------------------------------------------------------------
49
Mathias Agopian076b1cc2009-04-10 14:24:30 -070050const int NUM_BUFFERS = 2;
51
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052class Layer : public LayerBaseClient
53{
54public:
55 static const uint32_t typeInfo;
56 static const char* const typeID;
57 virtual char const* getTypeID() const { return typeID; }
58 virtual uint32_t getTypeInfo() const { return typeInfo; }
59
60 Layer(SurfaceFlinger* flinger, DisplayID display,
61 Client* c, int32_t i);
62
63 virtual ~Layer();
64
65 inline PixelFormat pixelFormat() const {
Mathias Agopian076b1cc2009-04-10 14:24:30 -070066 return frontBuffer().getPixelFormat();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080067 }
68
69 status_t setBuffers( Client* client,
70 uint32_t w, uint32_t h,
71 PixelFormat format, uint32_t flags=0);
72
73 virtual void onDraw(const Region& clip) const;
74 virtual void initStates(uint32_t w, uint32_t h, uint32_t flags);
75 virtual void setSizeChanged(uint32_t w, uint32_t h);
76 virtual uint32_t doTransaction(uint32_t transactionFlags);
77 virtual Point getPhysicalSize() const;
78 virtual void lockPageFlip(bool& recomputeVisibleRegions);
79 virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
80 virtual void finishPageFlip();
81 virtual bool needsBlending() const { return mNeedsBlending; }
82 virtual bool isSecure() const { return mSecure; }
Mathias Agopian076b1cc2009-04-10 14:24:30 -070083 virtual sp<Surface> createSurface() const;
Mathias Agopian9a112062009-04-17 19:36:26 -070084 virtual status_t ditch();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080085
86 const LayerBitmap& getBuffer(int i) const { return mBuffers[i]; }
87 LayerBitmap& getBuffer(int i) { return mBuffers[i]; }
88
89 // only for debugging
90 const sp<FreezeLock>& getFreezeLock() const { return mFreezeLock; }
91
92private:
93 inline const LayerBitmap&
94 frontBuffer() const { return getBuffer(mFrontBufferIndex); }
95 inline LayerBitmap&
96 frontBuffer() { return getBuffer(mFrontBufferIndex); }
97 inline const LayerBitmap&
98 backBuffer() const { return getBuffer(1-mFrontBufferIndex); }
99 inline LayerBitmap&
100 backBuffer() { return getBuffer(1-mFrontBufferIndex); }
101
102 void reloadTexture(const Region& dirty);
103
104 status_t resize(int32_t index, uint32_t w, uint32_t h, const char* what);
105 Region post(uint32_t* oldState, bool& recomputeVisibleRegions);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700106 sp<SurfaceBuffer> peekBuffer();
Mathias Agopian0aa758d2009-04-22 15:23:34 -0700107 void destroy();
108
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700109
110 class SurfaceLayer : public LayerBaseClient::Surface
111 {
112 public:
Mathias Agopian9a112062009-04-17 19:36:26 -0700113 SurfaceLayer(const sp<SurfaceFlinger>& flinger,
114 SurfaceID id, const sp<Layer>& owner);
115 ~SurfaceLayer();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800116
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700117 private:
118 virtual sp<SurfaceBuffer> getBuffer();
119
120 sp<Layer> getOwner() const {
121 return static_cast<Layer*>(Surface::getOwner().get());
122 }
123 };
124 friend class SurfaceLayer;
125
126 struct Texture {
127 Texture() : name(-1U), width(0), height(0), image(EGL_NO_IMAGE_KHR),
128 dirty(true) { }
129 GLuint name;
130 GLuint width;
131 GLuint height;
132 EGLImageKHR image;
133 bool dirty;
134 };
135
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800136 sp<Surface> mSurface;
137
138 bool mSecure;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700139 LayerBitmap mBuffers[NUM_BUFFERS];
140 Texture mTextures[NUM_BUFFERS];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800141 int32_t mFrontBufferIndex;
142 bool mNeedsBlending;
143 bool mResizeTransactionDone;
144 Region mPostedDirtyRegion;
145 sp<FreezeLock> mFreezeLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800146};
147
148// ---------------------------------------------------------------------------
149
150}; // namespace android
151
152#endif // ANDROID_LAYER_H