blob: 5284409c164d2473c439b68985f6e97f7f3be266 [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
23#include <utils/IMemory.h>
24#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
29namespace android {
30
31// ---------------------------------------------------------------------------
32
33class MemoryDealer;
34class Region;
35class OverlayRef;
36
37class LayerBuffer : public LayerBaseClient
38{
39 class Source : public LightRefBase<Source> {
40 public:
41 Source(LayerBuffer& layer);
42 virtual ~Source();
43 virtual void onDraw(const Region& clip) const;
44 virtual void onTransaction(uint32_t flags);
45 virtual void onVisibilityResolved(const Transform& planeTransform);
46 virtual void postBuffer(ssize_t offset);
47 virtual void unregisterBuffers();
48 virtual bool transformed() const;
49 protected:
50 LayerBuffer& mLayer;
51 };
52
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053public:
54 static const uint32_t typeInfo;
55 static const char* const typeID;
56 virtual char const* getTypeID() const { return typeID; }
57 virtual uint32_t getTypeInfo() const { return typeInfo; }
58
59 LayerBuffer(SurfaceFlinger* flinger, DisplayID display,
60 Client* client, int32_t i);
61 virtual ~LayerBuffer();
62
Mathias Agopian9a112062009-04-17 19:36:26 -070063 virtual void onFirstRef();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064 virtual bool needsBlending() const;
65
Mathias Agopian076b1cc2009-04-10 14:24:30 -070066 virtual sp<LayerBaseClient::Surface> createSurface() const;
Mathias Agopian9a112062009-04-17 19:36:26 -070067 virtual status_t ditch();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080068 virtual void onDraw(const Region& clip) const;
69 virtual uint32_t doTransaction(uint32_t flags);
70 virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
71 virtual bool transformed() const;
72
73 status_t registerBuffers(const ISurface::BufferHeap& buffers);
74 void postBuffer(ssize_t offset);
75 void unregisterBuffers();
76 sp<OverlayRef> createOverlay(uint32_t w, uint32_t h, int32_t format);
77
78 sp<Source> getSource() const;
79 sp<Source> clearSource();
80 void setNeedsBlending(bool blending);
81 const Rect& getTransformedBounds() const {
82 return mTransformedBounds;
83 }
84
85private:
86 struct NativeBuffer {
87 copybit_image_t img;
88 copybit_rect_t crop;
89 };
90
91 class Buffer : public LightRefBase<Buffer> {
92 public:
93 Buffer(const ISurface::BufferHeap& buffers, ssize_t offset);
94 inline status_t getStatus() const {
95 return mBufferHeap.heap!=0 ? NO_ERROR : NO_INIT;
96 }
97 inline const NativeBuffer& getBuffer() const {
98 return mNativeBuffer;
99 }
100 protected:
101 friend class LightRefBase<Buffer>;
102 Buffer& operator = (const Buffer& rhs);
103 Buffer(const Buffer& rhs);
104 ~Buffer();
105 private:
106 ISurface::BufferHeap mBufferHeap;
107 NativeBuffer mNativeBuffer;
108 };
109
110 class BufferSource : public Source {
111 public:
112 BufferSource(LayerBuffer& layer, const ISurface::BufferHeap& buffers);
113 virtual ~BufferSource();
114
115 status_t getStatus() const { return mStatus; }
116 sp<Buffer> getBuffer() const;
117 void setBuffer(const sp<Buffer>& buffer);
118
119 virtual void onDraw(const Region& clip) const;
120 virtual void postBuffer(ssize_t offset);
121 virtual void unregisterBuffers();
122 virtual bool transformed() const;
123 private:
124 mutable Mutex mLock;
125 sp<Buffer> mBuffer;
126 status_t mStatus;
127 ISurface::BufferHeap mBufferHeap;
128 size_t mBufferSize;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700129 mutable sp<android::Buffer> mTempBitmap;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800130 mutable GLuint mTextureName;
131 };
132
133 class OverlaySource : public Source {
134 public:
135 OverlaySource(LayerBuffer& layer,
136 sp<OverlayRef>* overlayRef,
137 uint32_t w, uint32_t h, int32_t format);
138 virtual ~OverlaySource();
139 virtual void onTransaction(uint32_t flags);
140 virtual void onVisibilityResolved(const Transform& planeTransform);
141 private:
142 void serverDestroy();
143 void destroyOverlay();
144 class OverlayChannel : public BnOverlay {
145 mutable Mutex mLock;
146 sp<OverlaySource> mSource;
147 virtual void destroy() {
148 sp<OverlaySource> source;
149 { // scope for the lock;
150 Mutex::Autolock _l(mLock);
151 source = mSource;
152 mSource.clear();
153 }
154 if (source != 0) {
155 source->serverDestroy();
156 }
157 }
158 public:
159 OverlayChannel(const sp<OverlaySource>& source)
160 : mSource(source) {
161 }
162 };
163 friend class OverlayChannel;
164 bool mVisibilityChanged;
165
166 overlay_t* mOverlay;
167 overlay_handle_t mOverlayHandle;
168 overlay_control_device_t* mOverlayDevice;
169 uint32_t mWidth;
170 uint32_t mHeight;
171 int32_t mFormat;
172 int32_t mWidthStride;
173 int32_t mHeightStride;
174 mutable Mutex mLock;
175 };
176
177
178 class SurfaceBuffer : public LayerBaseClient::Surface
179 {
180 public:
Mathias Agopian9a112062009-04-17 19:36:26 -0700181 SurfaceBuffer(const sp<SurfaceFlinger>& flinger,
182 SurfaceID id, const sp<LayerBuffer>& owner);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800183 virtual ~SurfaceBuffer();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700184
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800185 virtual status_t registerBuffers(const ISurface::BufferHeap& buffers);
186 virtual void postBuffer(ssize_t offset);
187 virtual void unregisterBuffers();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700188
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800189 virtual sp<OverlayRef> createOverlay(
190 uint32_t w, uint32_t h, int32_t format);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800191 private:
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700192 sp<LayerBuffer> getOwner() const {
193 return static_cast<LayerBuffer*>(Surface::getOwner().get());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800194 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800195 };
Mathias Agopian9a112062009-04-17 19:36:26 -0700196
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800197 mutable Mutex mLock;
198 sp<Source> mSource;
Mathias Agopian9a112062009-04-17 19:36:26 -0700199 sp<Surface> mSurface;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800200 bool mInvalidate;
201 bool mNeedsBlending;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800202};
203
204// ---------------------------------------------------------------------------
205
206}; // namespace android
207
208#endif // ANDROID_LAYER_BUFFER_H