blob: 80572193c1d97c3e0f847fea4f57176e27461b71 [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_BUFFER_H
18#define ANDROID_LAYER_BUFFER_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
Mathias Agopianc5b2c0b2009-05-19 19:08:10 -070023#include <binder/IMemory.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080024#include <private/ui/LayerState.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025
26#include "LayerBase.h"
27#include "LayerBitmap.h"
28
Mathias Agopian69029eb2009-06-23 21:11:43 -070029struct copybit_device_t;
30
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080031namespace android {
32
33// ---------------------------------------------------------------------------
34
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035class Region;
36class OverlayRef;
37
38class LayerBuffer : public LayerBaseClient
39{
40 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 virtual bool transformed() const;
50 protected:
51 LayerBuffer& mLayer;
52 };
53
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054public:
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,
Mathias Agopianf9d93272009-06-19 17:00:27 -070061 const sp<Client>& client, int32_t i);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062 virtual ~LayerBuffer();
63
Mathias Agopian9a112062009-04-17 19:36:26 -070064 virtual void onFirstRef();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080065 virtual bool needsBlending() const;
66
Mathias Agopian076b1cc2009-04-10 14:24:30 -070067 virtual sp<LayerBaseClient::Surface> createSurface() const;
Mathias Agopian9a112062009-04-17 19:36:26 -070068 virtual status_t ditch();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080069 virtual void onDraw(const Region& clip) const;
70 virtual uint32_t doTransaction(uint32_t flags);
71 virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
72 virtual bool transformed() const;
73
74 status_t registerBuffers(const ISurface::BufferHeap& buffers);
75 void postBuffer(ssize_t offset);
76 void unregisterBuffers();
77 sp<OverlayRef> createOverlay(uint32_t w, uint32_t h, int32_t format);
78
79 sp<Source> getSource() const;
80 sp<Source> clearSource();
81 void setNeedsBlending(bool blending);
82 const Rect& getTransformedBounds() const {
83 return mTransformedBounds;
84 }
85
86private:
87 struct NativeBuffer {
88 copybit_image_t img;
89 copybit_rect_t crop;
90 };
91
92 class Buffer : public LightRefBase<Buffer> {
93 public:
94 Buffer(const ISurface::BufferHeap& buffers, ssize_t offset);
95 inline status_t getStatus() const {
96 return mBufferHeap.heap!=0 ? NO_ERROR : NO_INIT;
97 }
98 inline const NativeBuffer& getBuffer() const {
99 return mNativeBuffer;
100 }
101 protected:
102 friend class LightRefBase<Buffer>;
103 Buffer& operator = (const Buffer& rhs);
104 Buffer(const Buffer& rhs);
105 ~Buffer();
106 private:
107 ISurface::BufferHeap mBufferHeap;
108 NativeBuffer mNativeBuffer;
109 };
110
111 class BufferSource : public Source {
112 public:
113 BufferSource(LayerBuffer& layer, const ISurface::BufferHeap& buffers);
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 virtual bool transformed() const;
124 private:
Mathias Agopian1fed11c2009-06-23 18:08:22 -0700125 mutable Mutex mLock;
126 sp<Buffer> mBuffer;
127 status_t mStatus;
128 ISurface::BufferHeap mBufferHeap;
129 size_t mBufferSize;
130 mutable sp<android::Buffer> mTempBitmap;
131 mutable LayerBase::Texture mTexture;
Mathias Agopian69029eb2009-06-23 21:11:43 -0700132 copybit_device_t* mBlitEngine;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800133 };
134
135 class OverlaySource : public Source {
136 public:
137 OverlaySource(LayerBuffer& layer,
138 sp<OverlayRef>* overlayRef,
139 uint32_t w, uint32_t h, int32_t format);
140 virtual ~OverlaySource();
Rebecca Schultz Zavin96df49b2009-07-20 21:18:04 -0700141 virtual void onDraw(const Region& clip) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800142 virtual void onTransaction(uint32_t flags);
143 virtual void onVisibilityResolved(const Transform& planeTransform);
144 private:
145 void serverDestroy();
146 void destroyOverlay();
147 class OverlayChannel : public BnOverlay {
148 mutable Mutex mLock;
149 sp<OverlaySource> mSource;
150 virtual void destroy() {
151 sp<OverlaySource> source;
152 { // scope for the lock;
153 Mutex::Autolock _l(mLock);
154 source = mSource;
155 mSource.clear();
156 }
157 if (source != 0) {
158 source->serverDestroy();
159 }
160 }
161 public:
162 OverlayChannel(const sp<OverlaySource>& source)
163 : mSource(source) {
164 }
165 };
166 friend class OverlayChannel;
167 bool mVisibilityChanged;
168
169 overlay_t* mOverlay;
170 overlay_handle_t mOverlayHandle;
171 overlay_control_device_t* mOverlayDevice;
172 uint32_t mWidth;
173 uint32_t mHeight;
174 int32_t mFormat;
175 int32_t mWidthStride;
176 int32_t mHeightStride;
177 mutable Mutex mLock;
Rebecca Schultz Zavin10001702009-07-21 16:17:59 -0700178 bool mInitialized;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800179 };
180
181
182 class SurfaceBuffer : public LayerBaseClient::Surface
183 {
184 public:
Mathias Agopian9a112062009-04-17 19:36:26 -0700185 SurfaceBuffer(const sp<SurfaceFlinger>& flinger,
186 SurfaceID id, const sp<LayerBuffer>& owner);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800187 virtual ~SurfaceBuffer();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700188
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800189 virtual status_t registerBuffers(const ISurface::BufferHeap& buffers);
190 virtual void postBuffer(ssize_t offset);
191 virtual void unregisterBuffers();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700192
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800193 virtual sp<OverlayRef> createOverlay(
194 uint32_t w, uint32_t h, int32_t format);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800195 private:
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700196 sp<LayerBuffer> getOwner() const {
197 return static_cast<LayerBuffer*>(Surface::getOwner().get());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800198 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800199 };
Mathias Agopian9a112062009-04-17 19:36:26 -0700200
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800201 mutable Mutex mLock;
202 sp<Source> mSource;
Mathias Agopian9a112062009-04-17 19:36:26 -0700203 sp<Surface> mSurface;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800204 bool mInvalidate;
205 bool mNeedsBlending;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800206};
207
208// ---------------------------------------------------------------------------
209
210}; // namespace android
211
212#endif // ANDROID_LAYER_BUFFER_H