blob: 98e30d7597becd1c86f5aed773cb68b8d5a009f2 [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 Agopian3330b202009-10-05 17:07:12 -070023#include <ui/GraphicBuffer.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080024#include <ui/PixelFormat.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025#include <pixelflinger/pixelflinger.h>
26
Mathias Agopian076b1cc2009-04-10 14:24:30 -070027#include <EGL/egl.h>
28#include <EGL/eglext.h>
29#include <GLES/gl.h>
30#include <GLES/glext.h>
31
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;
41
42// ---------------------------------------------------------------------------
43
Mathias Agopiancbb288b2009-09-07 16:32:45 -070044const size_t NUM_BUFFERS = 2;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070045
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046class Layer : public LayerBaseClient
47{
48public:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049 Layer(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopianf9d93272009-06-19 17:00:27 -070050 const sp<Client>& client, int32_t i);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051
52 virtual ~Layer();
53
Mathias Agopiancbb288b2009-09-07 16:32:45 -070054 status_t setBuffers(uint32_t w, uint32_t h,
55 PixelFormat format, uint32_t flags=0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056
Mathias Agopiancbb288b2009-09-07 16:32:45 -070057 void setDrawingSize(uint32_t w, uint32_t h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080058
59 virtual void onDraw(const Region& clip) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060 virtual uint32_t doTransaction(uint32_t transactionFlags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061 virtual void lockPageFlip(bool& recomputeVisibleRegions);
62 virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
63 virtual void finishPageFlip();
64 virtual bool needsBlending() const { return mNeedsBlending; }
Mathias Agopian401c2572009-09-23 19:16:27 -070065 virtual bool needsDithering() const { return mNeedsDithering; }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066 virtual bool isSecure() const { return mSecure; }
Mathias Agopian076b1cc2009-04-10 14:24:30 -070067 virtual sp<Surface> createSurface() const;
Mathias Agopian9a112062009-04-17 19:36:26 -070068 virtual status_t ditch();
Mathias Agopiancbb288b2009-09-07 16:32:45 -070069
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080070 // only for debugging
Mathias Agopian1b5e1022010-04-20 17:55:49 -070071 inline sp<GraphicBuffer> getBuffer(int i) const { return mBuffers[i]; }
Mathias Agopiancbb288b2009-09-07 16:32:45 -070072 // only for debugging
73 inline const sp<FreezeLock>& getFreezeLock() const { return mFreezeLock; }
74 // only for debugging
75 inline PixelFormat pixelFormat() const { return mFormat; }
Mathias Agopian45853c92010-02-26 18:59:23 -080076 // only for debugging
77 inline int getFrontBufferIndex() const { return mFrontBufferIndex; }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080078
Mathias Agopian1b5e1022010-04-20 17:55:49 -070079 virtual const char* getTypeId() const { return "Layer"; }
80
81protected:
82 virtual void dump(String8& result, char* scratch, size_t size) const;
83
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080084private:
Mathias Agopian9ec430a2009-10-06 19:00:57 -070085 inline sp<GraphicBuffer> getFrontBufferLocked() {
Mathias Agopiancbb288b2009-09-07 16:32:45 -070086 return mBuffers[mFrontBufferIndex];
87 }
88
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080089 void reloadTexture(const Region& dirty);
90
Mathias Agopian3330b202009-10-05 17:07:12 -070091 uint32_t getEffectiveUsage(uint32_t usage) const;
92
93 sp<GraphicBuffer> requestBuffer(int index, int usage);
Mathias Agopian0aa758d2009-04-22 15:23:34 -070094 void destroy();
95
Mathias Agopiancbb288b2009-09-07 16:32:45 -070096 class SurfaceLayer : public LayerBaseClient::Surface {
Mathias Agopian076b1cc2009-04-10 14:24:30 -070097 public:
Mathias Agopiancbb288b2009-09-07 16:32:45 -070098 SurfaceLayer(const sp<SurfaceFlinger>& flinger,
99 SurfaceID id, const sp<Layer>& owner);
100 ~SurfaceLayer();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700101 private:
Mathias Agopian3330b202009-10-05 17:07:12 -0700102 virtual sp<GraphicBuffer> requestBuffer(int index, int usage);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700103 sp<Layer> getOwner() const {
104 return static_cast<Layer*>(Surface::getOwner().get());
105 }
106 };
107 friend class SurfaceLayer;
108
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109 sp<Surface> mSurface;
110
111 bool mSecure;
Mathias Agopiana4b740e2009-10-05 18:20:39 -0700112 bool mNoEGLImageForSwBuffers;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800113 int32_t mFrontBufferIndex;
114 bool mNeedsBlending;
Mathias Agopian401c2572009-09-23 19:16:27 -0700115 bool mNeedsDithering;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800116 Region mPostedDirtyRegion;
117 sp<FreezeLock> mFreezeLock;
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700118 PixelFormat mFormat;
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700119
120 // protected by mLock
Mathias Agopian3330b202009-10-05 17:07:12 -0700121 sp<GraphicBuffer> mBuffers[NUM_BUFFERS];
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700122 Texture mTextures[NUM_BUFFERS];
Mathias Agopian57720c32009-10-21 16:27:21 -0700123 sp<GraphicBuffer> mHybridBuffer;
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700124 uint32_t mWidth;
125 uint32_t mHeight;
126
127 mutable Mutex mLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800128};
129
130// ---------------------------------------------------------------------------
131
132}; // namespace android
133
134#endif // ANDROID_LAYER_H