blob: 63ec2cf92fa46b6fa50e308df5877a93285ecb47 [file] [log] [blame]
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -07001/*
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_BUFFER_H
18#define ANDROID_LAYER_BUFFER_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <utils/IMemory.h>
24#include <private/ui/LayerState.h>
25#include <GLES/eglnatives.h>
26
27#include "LayerBase.h"
28#include "LayerBitmap.h"
29
30namespace android {
31
32// ---------------------------------------------------------------------------
33
34class MemoryDealer;
35class Region;
The Android Open Source Projectb7986892009-01-09 17:51:23 -080036class OverlayRef;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070037
38class LayerBuffer : public LayerBaseClient
39{
The Android Open Source Projectb7986892009-01-09 17:51:23 -080040 class Source : public LightRefBase<Source> {
41 public:
42 Source(LayerBuffer& layer);
43 virtual ~Source();
44 virtual void onDraw(const Region& clip) const;
45 virtual void onTransaction(uint32_t flags);
46 virtual void onVisibilityResolved(const Transform& planeTransform);
47 virtual void postBuffer(ssize_t offset);
48 virtual void unregisterBuffers();
49 protected:
50 LayerBuffer& mLayer;
51 };
52
53
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070054public:
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 LayerBuffer(SurfaceFlinger* flinger, DisplayID display,
61 Client* client, int32_t i);
62 virtual ~LayerBuffer();
63
64 virtual bool needsBlending() const;
65
66 virtual sp<LayerBaseClient::Surface> getSurface() const;
67 virtual void onDraw(const Region& clip) const;
The Android Open Source Projectb7986892009-01-09 17:51:23 -080068 virtual uint32_t doTransaction(uint32_t flags);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070069 virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
70
71 status_t registerBuffers(int w, int h, int hstride, int vstride,
72 PixelFormat format, const sp<IMemoryHeap>& heap);
73 void postBuffer(ssize_t offset);
74 void unregisterBuffers();
The Android Open Source Projectb7986892009-01-09 17:51:23 -080075 sp<OverlayRef> createOverlay(uint32_t w, uint32_t h, int32_t format);
76
77 sp<Source> getSource() const;
78 void setNeedsBlending(bool blending);
79 const Rect& getTransformedBounds() const {
80 return mTransformedBounds;
81 }
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070082
83private:
The Android Open Source Projectb7986892009-01-09 17:51:23 -080084 struct NativeBuffer {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070085 copybit_image_t img;
86 copybit_rect_t crop;
87 };
88
The Android Open Source Projectb7986892009-01-09 17:51:23 -080089 class Buffer : public LightRefBase<Buffer> {
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070090 public:
91 Buffer(const sp<IMemoryHeap>& heap, ssize_t offset,
92 int w, int h, int hs, int vs, int f);
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -070093 inline status_t getStatus() const {
94 return mHeap!=0 ? NO_ERROR : NO_INIT;
95 }
96 inline const NativeBuffer& getBuffer() const {
97 return mNativeBuffer;
98 }
99 protected:
The Android Open Source Projectb7986892009-01-09 17:51:23 -0800100 friend class LightRefBase<Buffer>;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700101 Buffer& operator = (const Buffer& rhs);
102 Buffer(const Buffer& rhs);
103 ~Buffer();
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700104 private:
105 sp<IMemoryHeap> mHeap;
106 NativeBuffer mNativeBuffer;
107 };
108
The Android Open Source Projectb7986892009-01-09 17:51:23 -0800109 class BufferSource : public Source {
110 public:
111 BufferSource(LayerBuffer& layer,
112 int w, int h, int hstride, int vstride,
113 PixelFormat format, const sp<IMemoryHeap>& heap);
114 virtual ~BufferSource();
115
116 status_t getStatus() const { return mStatus; }
117 sp<Buffer> getBuffer() const;
118 void setBuffer(const sp<Buffer>& buffer);
119
120 virtual void onDraw(const Region& clip) const;
121 virtual void postBuffer(ssize_t offset);
122 virtual void unregisterBuffers();
123 private:
124 mutable Mutex mLock;
125 sp<IMemoryHeap> mHeap;
126 sp<Buffer> mBuffer;
127 status_t mStatus;
128 int mWidth;
129 int mHeight;
130 int mHStride;
131 int mVStride;
132 int mFormat;
133 mutable sp<MemoryDealer> mTemporaryDealer;
134 mutable LayerBitmap mTempBitmap;
135 mutable GLuint mTextureName;
136 };
137
138 class OverlaySource : public Source {
139 public:
140 OverlaySource(LayerBuffer& layer,
141 sp<OverlayRef>* overlayRef,
142 uint32_t w, uint32_t h, int32_t format);
143 virtual ~OverlaySource();
144 virtual void onTransaction(uint32_t flags);
145 virtual void onVisibilityResolved(const Transform& planeTransform);
146 private:
147 void serverDestroy();
148 class OverlayChanel : public BnOverlay {
149 mutable Mutex mLock;
150 sp<OverlaySource> mSource;
151 virtual void destroy() {
152 sp<OverlaySource> source;
153 { // scope for the lock;
154 Mutex::Autolock _l(mLock);
155 source = mSource;
156 mSource.clear();
157 }
158 if (source != 0) {
159 source->serverDestroy();
160 }
161 }
162 public:
163 OverlayChanel(const sp<OverlaySource>& source)
164 : mSource(source) {
165 }
166 };
167 friend class OverlayChanel;
168 bool mVisibilityChanged;
169
170 overlay_t* mOverlay;
171 overlay_handle_t const *mOverlayHandle;
172 uint32_t mWidth;
173 uint32_t mHeight;
174 int32_t mFormat;
175 int32_t mWidthStride;
176 int32_t mHeightStride;
177 mutable Mutex mLock;
178 };
179
180
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700181 class SurfaceBuffer : public LayerBaseClient::Surface
182 {
183 public:
184 SurfaceBuffer(SurfaceID id, LayerBuffer* owner);
185 virtual ~SurfaceBuffer();
186 virtual status_t registerBuffers(int w, int h, int hstride, int vstride,
187 PixelFormat format, const sp<IMemoryHeap>& heap);
188 virtual void postBuffer(ssize_t offset);
189 virtual void unregisterBuffers();
The Android Open Source Projectb7986892009-01-09 17:51:23 -0800190 virtual sp<OverlayRef> createOverlay(
The Android Open Source Projectf013e1a2008-12-17 18:05:43 -0800191 uint32_t w, uint32_t h, int32_t format);
192 void disown();
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700193 private:
194 LayerBuffer* getOwner() const {
195 Mutex::Autolock _l(mLock);
196 return mOwner;
197 }
198 mutable Mutex mLock;
199 LayerBuffer* mOwner;
200 };
201
202 friend class SurfaceFlinger;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700203 sp<SurfaceBuffer> getClientSurface() const;
204
205 mutable Mutex mLock;
The Android Open Source Projectb7986892009-01-09 17:51:23 -0800206 sp<Source> mSource;
207
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700208 bool mInvalidate;
209 bool mNeedsBlending;
210 mutable wp<SurfaceBuffer> mClientSurface;
The Android Open Source Project54b6cfa2008-10-21 07:00:00 -0700211};
212
213// ---------------------------------------------------------------------------
214
215}; // namespace android
216
217#endif // ANDROID_LAYER_BUFFER_H