blob: 2d441217f94e44347877c7f5e79fb322d737b1b9 [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
53
54public:
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,
61 Client* client, int32_t i);
62 virtual ~LayerBuffer();
63
64 virtual bool needsBlending() const;
65
Mathias Agopian076b1cc2009-04-10 14:24:30 -070066 virtual sp<LayerBaseClient::Surface> createSurface() const;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080067 virtual void onDraw(const Region& clip) const;
68 virtual uint32_t doTransaction(uint32_t flags);
69 virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
70 virtual bool transformed() const;
71
72 status_t registerBuffers(const ISurface::BufferHeap& buffers);
73 void postBuffer(ssize_t offset);
74 void unregisterBuffers();
75 sp<OverlayRef> createOverlay(uint32_t w, uint32_t h, int32_t format);
76
77 sp<Source> getSource() const;
78 sp<Source> clearSource();
79 void setNeedsBlending(bool blending);
80 const Rect& getTransformedBounds() const {
81 return mTransformedBounds;
82 }
83
84private:
85 struct NativeBuffer {
86 copybit_image_t img;
87 copybit_rect_t crop;
88 };
89
90 class Buffer : public LightRefBase<Buffer> {
91 public:
92 Buffer(const ISurface::BufferHeap& buffers, ssize_t offset);
93 inline status_t getStatus() const {
94 return mBufferHeap.heap!=0 ? NO_ERROR : NO_INIT;
95 }
96 inline const NativeBuffer& getBuffer() const {
97 return mNativeBuffer;
98 }
99 protected:
100 friend class LightRefBase<Buffer>;
101 Buffer& operator = (const Buffer& rhs);
102 Buffer(const Buffer& rhs);
103 ~Buffer();
104 private:
105 ISurface::BufferHeap mBufferHeap;
106 NativeBuffer mNativeBuffer;
107 };
108
109 class BufferSource : public Source {
110 public:
111 BufferSource(LayerBuffer& layer, const ISurface::BufferHeap& buffers);
112 virtual ~BufferSource();
113
114 status_t getStatus() const { return mStatus; }
115 sp<Buffer> getBuffer() const;
116 void setBuffer(const sp<Buffer>& buffer);
117
118 virtual void onDraw(const Region& clip) const;
119 virtual void postBuffer(ssize_t offset);
120 virtual void unregisterBuffers();
121 virtual bool transformed() const;
122 private:
123 mutable Mutex mLock;
124 sp<Buffer> mBuffer;
125 status_t mStatus;
126 ISurface::BufferHeap mBufferHeap;
127 size_t mBufferSize;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700128 mutable sp<android::Buffer> mTempBitmap;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800129 mutable GLuint mTextureName;
130 };
131
132 class OverlaySource : public Source {
133 public:
134 OverlaySource(LayerBuffer& layer,
135 sp<OverlayRef>* overlayRef,
136 uint32_t w, uint32_t h, int32_t format);
137 virtual ~OverlaySource();
138 virtual void onTransaction(uint32_t flags);
139 virtual void onVisibilityResolved(const Transform& planeTransform);
140 private:
141 void serverDestroy();
142 void destroyOverlay();
143 class OverlayChannel : public BnOverlay {
144 mutable Mutex mLock;
145 sp<OverlaySource> mSource;
146 virtual void destroy() {
147 sp<OverlaySource> source;
148 { // scope for the lock;
149 Mutex::Autolock _l(mLock);
150 source = mSource;
151 mSource.clear();
152 }
153 if (source != 0) {
154 source->serverDestroy();
155 }
156 }
157 public:
158 OverlayChannel(const sp<OverlaySource>& source)
159 : mSource(source) {
160 }
161 };
162 friend class OverlayChannel;
163 bool mVisibilityChanged;
164
165 overlay_t* mOverlay;
166 overlay_handle_t mOverlayHandle;
167 overlay_control_device_t* mOverlayDevice;
168 uint32_t mWidth;
169 uint32_t mHeight;
170 int32_t mFormat;
171 int32_t mWidthStride;
172 int32_t mHeightStride;
173 mutable Mutex mLock;
174 };
175
176
177 class SurfaceBuffer : public LayerBaseClient::Surface
178 {
179 public:
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700180 SurfaceBuffer(SurfaceID id, const sp<LayerBuffer>& owner);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800181 virtual ~SurfaceBuffer();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700182
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800183 virtual status_t registerBuffers(const ISurface::BufferHeap& buffers);
184 virtual void postBuffer(ssize_t offset);
185 virtual void unregisterBuffers();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700186
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800187 virtual sp<OverlayRef> createOverlay(
188 uint32_t w, uint32_t h, int32_t format);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800189 private:
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700190 sp<LayerBuffer> getOwner() const {
191 return static_cast<LayerBuffer*>(Surface::getOwner().get());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800192 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800193 };
194
195 friend class SurfaceFlinger;
196 sp<SurfaceBuffer> getClientSurface() const;
197
198 mutable Mutex mLock;
199 sp<Source> mSource;
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