blob: e539f681133d7509b2c866cd59d7a0328ecf0257 [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"
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
Mathias Agopian69029eb2009-06-23 21:11:43 -070028struct copybit_device_t;
29
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080030namespace android {
31
32// ---------------------------------------------------------------------------
33
Mathias Agopiancbb288b2009-09-07 16:32:45 -070034class Buffer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035class Region;
36class OverlayRef;
37
Mathias Agopiancbb288b2009-09-07 16:32:45 -070038// ---------------------------------------------------------------------------
39
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040class LayerBuffer : public LayerBaseClient
41{
42 class Source : public LightRefBase<Source> {
43 public:
44 Source(LayerBuffer& layer);
45 virtual ~Source();
46 virtual void onDraw(const Region& clip) const;
47 virtual void onTransaction(uint32_t flags);
48 virtual void onVisibilityResolved(const Transform& planeTransform);
49 virtual void postBuffer(ssize_t offset);
50 virtual void unregisterBuffers();
51 virtual bool transformed() const;
52 protected:
53 LayerBuffer& mLayer;
54 };
55
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056public:
57 static const uint32_t typeInfo;
58 static const char* const typeID;
59 virtual char const* getTypeID() const { return typeID; }
60 virtual uint32_t getTypeInfo() const { return typeInfo; }
61
62 LayerBuffer(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopianf9d93272009-06-19 17:00:27 -070063 const sp<Client>& client, int32_t i);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064 virtual ~LayerBuffer();
65
Mathias Agopian9a112062009-04-17 19:36:26 -070066 virtual void onFirstRef();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080067 virtual bool needsBlending() const;
68
Mathias Agopian076b1cc2009-04-10 14:24:30 -070069 virtual sp<LayerBaseClient::Surface> createSurface() const;
Mathias Agopian9a112062009-04-17 19:36:26 -070070 virtual status_t ditch();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080071 virtual void onDraw(const Region& clip) const;
72 virtual uint32_t doTransaction(uint32_t flags);
73 virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
74 virtual bool transformed() const;
75
76 status_t registerBuffers(const ISurface::BufferHeap& buffers);
77 void postBuffer(ssize_t offset);
78 void unregisterBuffers();
79 sp<OverlayRef> createOverlay(uint32_t w, uint32_t h, int32_t format);
80
81 sp<Source> getSource() const;
82 sp<Source> clearSource();
83 void setNeedsBlending(bool blending);
84 const Rect& getTransformedBounds() const {
85 return mTransformedBounds;
86 }
87
88private:
89 struct NativeBuffer {
90 copybit_image_t img;
91 copybit_rect_t crop;
92 };
93
94 class Buffer : public LightRefBase<Buffer> {
95 public:
96 Buffer(const ISurface::BufferHeap& buffers, ssize_t offset);
97 inline status_t getStatus() const {
98 return mBufferHeap.heap!=0 ? NO_ERROR : NO_INIT;
99 }
100 inline const NativeBuffer& getBuffer() const {
101 return mNativeBuffer;
102 }
103 protected:
104 friend class LightRefBase<Buffer>;
105 Buffer& operator = (const Buffer& rhs);
106 Buffer(const Buffer& rhs);
107 ~Buffer();
108 private:
109 ISurface::BufferHeap mBufferHeap;
110 NativeBuffer mNativeBuffer;
111 };
112
113 class BufferSource : public Source {
114 public:
115 BufferSource(LayerBuffer& layer, const ISurface::BufferHeap& buffers);
116 virtual ~BufferSource();
117
118 status_t getStatus() const { return mStatus; }
119 sp<Buffer> getBuffer() const;
120 void setBuffer(const sp<Buffer>& buffer);
121
122 virtual void onDraw(const Region& clip) const;
123 virtual void postBuffer(ssize_t offset);
124 virtual void unregisterBuffers();
125 virtual bool transformed() const;
126 private:
Mathias Agopian1fed11c2009-06-23 18:08:22 -0700127 mutable Mutex mLock;
128 sp<Buffer> mBuffer;
129 status_t mStatus;
130 ISurface::BufferHeap mBufferHeap;
131 size_t mBufferSize;
132 mutable sp<android::Buffer> mTempBitmap;
133 mutable LayerBase::Texture mTexture;
Mathias Agopian69029eb2009-06-23 21:11:43 -0700134 copybit_device_t* mBlitEngine;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800135 };
136
137 class OverlaySource : public Source {
138 public:
139 OverlaySource(LayerBuffer& layer,
140 sp<OverlayRef>* overlayRef,
141 uint32_t w, uint32_t h, int32_t format);
142 virtual ~OverlaySource();
Rebecca Schultz Zavin96df49b2009-07-20 21:18:04 -0700143 virtual void onDraw(const Region& clip) const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800144 virtual void onTransaction(uint32_t flags);
145 virtual void onVisibilityResolved(const Transform& planeTransform);
146 private:
147 void serverDestroy();
148 void destroyOverlay();
149 class OverlayChannel : public BnOverlay {
150 mutable Mutex mLock;
151 sp<OverlaySource> mSource;
152 virtual void destroy() {
153 sp<OverlaySource> source;
154 { // scope for the lock;
155 Mutex::Autolock _l(mLock);
156 source = mSource;
157 mSource.clear();
158 }
159 if (source != 0) {
160 source->serverDestroy();
161 }
162 }
163 public:
164 OverlayChannel(const sp<OverlaySource>& source)
165 : mSource(source) {
166 }
167 };
168 friend class OverlayChannel;
169 bool mVisibilityChanged;
170
171 overlay_t* mOverlay;
172 overlay_handle_t mOverlayHandle;
173 overlay_control_device_t* mOverlayDevice;
174 uint32_t mWidth;
175 uint32_t mHeight;
176 int32_t mFormat;
177 int32_t mWidthStride;
178 int32_t mHeightStride;
179 mutable Mutex mLock;
Rebecca Schultz Zavin10001702009-07-21 16:17:59 -0700180 bool mInitialized;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800181 };
182
183
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700184 class SurfaceLayerBuffer : public LayerBaseClient::Surface
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800185 {
186 public:
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700187 SurfaceLayerBuffer(const sp<SurfaceFlinger>& flinger,
Mathias Agopian9a112062009-04-17 19:36:26 -0700188 SurfaceID id, const sp<LayerBuffer>& owner);
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700189 virtual ~SurfaceLayerBuffer();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700190
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800191 virtual status_t registerBuffers(const ISurface::BufferHeap& buffers);
192 virtual void postBuffer(ssize_t offset);
193 virtual void unregisterBuffers();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700194
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800195 virtual sp<OverlayRef> createOverlay(
196 uint32_t w, uint32_t h, int32_t format);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800197 private:
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700198 sp<LayerBuffer> getOwner() const {
199 return static_cast<LayerBuffer*>(Surface::getOwner().get());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800200 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800201 };
Mathias Agopian9a112062009-04-17 19:36:26 -0700202
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800203 mutable Mutex mLock;
204 sp<Source> mSource;
Mathias Agopian9a112062009-04-17 19:36:26 -0700205 sp<Surface> mSurface;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800206 bool mInvalidate;
207 bool mNeedsBlending;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800208};
209
210// ---------------------------------------------------------------------------
211
212}; // namespace android
213
214#endif // ANDROID_LAYER_BUFFER_H