blob: 3f3953fb9133e913fea1e2ccf4d5aeef0073767d [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();
107
108
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:
117 virtual sp<SurfaceBuffer> getBuffer();
118
119 sp<Layer> getOwner() const {
120 return static_cast<Layer*>(Surface::getOwner().get());
121 }
122 };
123 friend class SurfaceLayer;
124
125 struct Texture {
126 Texture() : name(-1U), width(0), height(0), image(EGL_NO_IMAGE_KHR),
127 dirty(true) { }
128 GLuint name;
129 GLuint width;
130 GLuint height;
131 EGLImageKHR image;
132 bool dirty;
133 };
134
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800135 sp<Surface> mSurface;
136
137 bool mSecure;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700138 LayerBitmap mBuffers[NUM_BUFFERS];
139 Texture mTextures[NUM_BUFFERS];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800140 int32_t mFrontBufferIndex;
141 bool mNeedsBlending;
142 bool mResizeTransactionDone;
143 Region mPostedDirtyRegion;
144 sp<FreezeLock> mFreezeLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800145};
146
147// ---------------------------------------------------------------------------
148
149}; // namespace android
150
151#endif // ANDROID_LAYER_H