blob: 3b099984bde6f5d08906d93641fc9b1dc79c0784 [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"
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027
Mathias Agopiancbc4c9f2009-06-23 21:11:43 -070028struct copybit_device_t;
29
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030namespace android {
31
32// ---------------------------------------------------------------------------
33
Mathias Agopian9779b2212009-09-07 16:32:45 -070034class Buffer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035class Region;
36class OverlayRef;
37
Mathias Agopian9779b2212009-09-07 16:32:45 -070038// ---------------------------------------------------------------------------
39
The Android Open Source Project9066cfe2009-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 Project9066cfe2009-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 Agopian6edf5af2009-06-19 17:00:27 -070063 const sp<Client>& client, int32_t i);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080064 virtual ~LayerBuffer();
65
Mathias Agopian6cf0db22009-04-17 19:36:26 -070066 virtual void onFirstRef();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080067 virtual bool needsBlending() const;
68
Mathias Agopian1473f462009-04-10 14:24:30 -070069 virtual sp<LayerBaseClient::Surface> createSurface() const;
Mathias Agopian6cf0db22009-04-17 19:36:26 -070070 virtual status_t ditch();
The Android Open Source Project9066cfe2009-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 Agopianb34d1432009-09-08 20:02:47 -0700127 mutable Mutex mBufferSourceLock;
Mathias Agopian999543b2009-06-23 18:08:22 -0700128 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 Agopiancbc4c9f2009-06-23 21:11:43 -0700134 copybit_device_t* mBlitEngine;
The Android Open Source Project9066cfe2009-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 Zavin7ac5e692009-07-20 21:18:04 -0700143 virtual void onDraw(const Region& clip) const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800144 virtual void onTransaction(uint32_t flags);
145 virtual void onVisibilityResolved(const Transform& planeTransform);
146 private:
147 void serverDestroy();
Mathias Agopianb34d1432009-09-08 20:02:47 -0700148 void destroyOverlay();
149
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800150 class OverlayChannel : public BnOverlay {
Mathias Agopianb34d1432009-09-08 20:02:47 -0700151 public:
152 OverlayChannel(const sp<OverlaySource>& source)
153 : mSource(source) {
154 }
155 private:
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800156 virtual void destroy() {
157 sp<OverlaySource> source;
158 { // scope for the lock;
Mathias Agopianb34d1432009-09-08 20:02:47 -0700159 Mutex::Autolock _l(mDestroyLock);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 source = mSource;
161 mSource.clear();
162 }
163 if (source != 0) {
164 source->serverDestroy();
165 }
166 }
Mathias Agopianb34d1432009-09-08 20:02:47 -0700167 mutable Mutex mDestroyLock;
168 sp<OverlaySource> mSource;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 };
Mathias Agopianb34d1432009-09-08 20:02:47 -0700170
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800171 friend class OverlayChannel;
172 bool mVisibilityChanged;
173
174 overlay_t* mOverlay;
175 overlay_handle_t mOverlayHandle;
176 overlay_control_device_t* mOverlayDevice;
177 uint32_t mWidth;
178 uint32_t mHeight;
179 int32_t mFormat;
180 int32_t mWidthStride;
181 int32_t mHeightStride;
Mathias Agopianb34d1432009-09-08 20:02:47 -0700182 mutable Mutex mOverlaySourceLock;
Rebecca Schultz Zavin43ab7632009-07-21 16:17:59 -0700183 bool mInitialized;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800184 };
185
186
Mathias Agopian9779b2212009-09-07 16:32:45 -0700187 class SurfaceLayerBuffer : public LayerBaseClient::Surface
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800188 {
189 public:
Mathias Agopian9779b2212009-09-07 16:32:45 -0700190 SurfaceLayerBuffer(const sp<SurfaceFlinger>& flinger,
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700191 SurfaceID id, const sp<LayerBuffer>& owner);
Mathias Agopian9779b2212009-09-07 16:32:45 -0700192 virtual ~SurfaceLayerBuffer();
Mathias Agopian1473f462009-04-10 14:24:30 -0700193
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800194 virtual status_t registerBuffers(const ISurface::BufferHeap& buffers);
195 virtual void postBuffer(ssize_t offset);
196 virtual void unregisterBuffers();
Mathias Agopian1473f462009-04-10 14:24:30 -0700197
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800198 virtual sp<OverlayRef> createOverlay(
199 uint32_t w, uint32_t h, int32_t format);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 private:
Mathias Agopian1473f462009-04-10 14:24:30 -0700201 sp<LayerBuffer> getOwner() const {
202 return static_cast<LayerBuffer*>(Surface::getOwner().get());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800204 };
Mathias Agopianb34d1432009-09-08 20:02:47 -0700205
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800206 mutable Mutex mLock;
207 sp<Source> mSource;
Mathias Agopian6cf0db22009-04-17 19:36:26 -0700208 sp<Surface> mSurface;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800209 bool mInvalidate;
210 bool mNeedsBlending;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211};
212
213// ---------------------------------------------------------------------------
214
215}; // namespace android
216
217#endif // ANDROID_LAYER_BUFFER_H