blob: fe879ebd976e21396823d8cb71355fc78a0f20eb [file] [log] [blame]
The Android Open Source Project9066cfe2009-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 Agopian07952722009-05-19 19:08:10 -070023#include <binder/IMemory.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024#include <private/ui/LayerState.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025
26#include "LayerBase.h"
27#include "LayerBitmap.h"
28
Mathias Agopiancbc4c9f2009-06-23 21:11:43 -070029struct copybit_device_t;
30
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080031namespace android {
32
33// ---------------------------------------------------------------------------
34
The Android Open Source Project9066cfe2009-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 Project9066cfe2009-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 Agopian6edf5af2009-06-19 17:00:27 -070061 const sp<Client>& client, int32_t i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 virtual ~LayerBuffer();
63
Mathias Agopian6cf0db22009-04-17 19:36:26 -070064 virtual void onFirstRef();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 virtual bool needsBlending() const;
66
Mathias Agopian1473f462009-04-10 14:24:30 -070067 virtual sp<LayerBaseClient::Surface> createSurface() const;
Mathias Agopian6cf0db22009-04-17 19:36:26 -070068 virtual status_t ditch();
The Android Open Source Project9066cfe2009-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 Agopian999543b2009-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 Agopiancbc4c9f2009-06-23 21:11:43 -0700132 copybit_device_t* mBlitEngine;
The Android Open Source Project9066cfe2009-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();
141 virtual void onTransaction(uint32_t flags);
142 virtual void onVisibilityResolved(const Transform& planeTransform);
143 private:
144 void serverDestroy();
145 void destroyOverlay();
146 class OverlayChannel : public BnOverlay {
147 mutable Mutex mLock;
148 sp<OverlaySource> mSource;
149 virtual void destroy() {
150 sp<OverlaySource> source;
151 { // scope for the lock;
152 Mutex::Autolock _l(mLock);
153 source = mSource;
154 mSource.clear();
155 }
156 if (source != 0) {
157 source->serverDestroy();
158 }
159 }
160 public:
161 OverlayChannel(const sp<OverlaySource>& source)
162 : mSource(source) {
163 }
164 };
165 friend class OverlayChannel;
166 bool mVisibilityChanged;
167
168 overlay_t* mOverlay;
169 overlay_handle_t mOverlayHandle;
170 overlay_control_device_t* mOverlayDevice;
171 uint32_t mWidth;
172 uint32_t mHeight;
173 int32_t mFormat;
174 int32_t mWidthStride;
175 int32_t mHeightStride;
176 mutable Mutex mLock;
177 };
178
179
180 class SurfaceBuffer : public LayerBaseClient::Surface
181 {
182 public:
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700183 SurfaceBuffer(const sp<SurfaceFlinger>& flinger,
184 SurfaceID id, const sp<LayerBuffer>& owner);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800185 virtual ~SurfaceBuffer();
Mathias Agopian1473f462009-04-10 14:24:30 -0700186
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187 virtual status_t registerBuffers(const ISurface::BufferHeap& buffers);
188 virtual void postBuffer(ssize_t offset);
189 virtual void unregisterBuffers();
Mathias Agopian1473f462009-04-10 14:24:30 -0700190
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 virtual sp<OverlayRef> createOverlay(
192 uint32_t w, uint32_t h, int32_t format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 private:
Mathias Agopian1473f462009-04-10 14:24:30 -0700194 sp<LayerBuffer> getOwner() const {
195 return static_cast<LayerBuffer*>(Surface::getOwner().get());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800196 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800197 };
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700198
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800199 mutable Mutex mLock;
200 sp<Source> mSource;
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700201 sp<Surface> mSurface;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800202 bool mInvalidate;
203 bool mNeedsBlending;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204};
205
206// ---------------------------------------------------------------------------
207
208}; // namespace android
209
210#endif // ANDROID_LAYER_BUFFER_H