blob: cd541a513024143963b1b5665c49fe34001054fa [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"
27#include "LayerBitmap.h"
28
Mathias Agopian69029eb2009-06-23 21:11:43 -070029struct copybit_device_t;
30
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080031namespace android {
32
33// ---------------------------------------------------------------------------
34
35class MemoryDealer;
36class Region;
37class OverlayRef;
38
39class LayerBuffer : public LayerBaseClient
40{
41 class Source : public LightRefBase<Source> {
42 public:
43 Source(LayerBuffer& layer);
44 virtual ~Source();
45 virtual void onDraw(const Region& clip) const;
46 virtual void onTransaction(uint32_t flags);
47 virtual void onVisibilityResolved(const Transform& planeTransform);
48 virtual void postBuffer(ssize_t offset);
49 virtual void unregisterBuffers();
50 virtual bool transformed() const;
51 protected:
52 LayerBuffer& mLayer;
53 };
54
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055public:
56 static const uint32_t typeInfo;
57 static const char* const typeID;
58 virtual char const* getTypeID() const { return typeID; }
59 virtual uint32_t getTypeInfo() const { return typeInfo; }
60
61 LayerBuffer(SurfaceFlinger* flinger, DisplayID display,
Mathias Agopianf9d93272009-06-19 17:00:27 -070062 const sp<Client>& client, int32_t i);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063 virtual ~LayerBuffer();
64
Mathias Agopian9a112062009-04-17 19:36:26 -070065 virtual void onFirstRef();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066 virtual bool needsBlending() const;
67
Mathias Agopian076b1cc2009-04-10 14:24:30 -070068 virtual sp<LayerBaseClient::Surface> createSurface() const;
Mathias Agopian9a112062009-04-17 19:36:26 -070069 virtual status_t ditch();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080070 virtual void onDraw(const Region& clip) const;
71 virtual uint32_t doTransaction(uint32_t flags);
72 virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
73 virtual bool transformed() const;
74
75 status_t registerBuffers(const ISurface::BufferHeap& buffers);
76 void postBuffer(ssize_t offset);
77 void unregisterBuffers();
78 sp<OverlayRef> createOverlay(uint32_t w, uint32_t h, int32_t format);
79
80 sp<Source> getSource() const;
81 sp<Source> clearSource();
82 void setNeedsBlending(bool blending);
83 const Rect& getTransformedBounds() const {
84 return mTransformedBounds;
85 }
86
87private:
88 struct NativeBuffer {
89 copybit_image_t img;
90 copybit_rect_t crop;
91 };
92
93 class Buffer : public LightRefBase<Buffer> {
94 public:
95 Buffer(const ISurface::BufferHeap& buffers, ssize_t offset);
96 inline status_t getStatus() const {
97 return mBufferHeap.heap!=0 ? NO_ERROR : NO_INIT;
98 }
99 inline const NativeBuffer& getBuffer() const {
100 return mNativeBuffer;
101 }
102 protected:
103 friend class LightRefBase<Buffer>;
104 Buffer& operator = (const Buffer& rhs);
105 Buffer(const Buffer& rhs);
106 ~Buffer();
107 private:
108 ISurface::BufferHeap mBufferHeap;
109 NativeBuffer mNativeBuffer;
110 };
111
112 class BufferSource : public Source {
113 public:
114 BufferSource(LayerBuffer& layer, const ISurface::BufferHeap& buffers);
115 virtual ~BufferSource();
116
117 status_t getStatus() const { return mStatus; }
118 sp<Buffer> getBuffer() const;
119 void setBuffer(const sp<Buffer>& buffer);
120
121 virtual void onDraw(const Region& clip) const;
122 virtual void postBuffer(ssize_t offset);
123 virtual void unregisterBuffers();
124 virtual bool transformed() const;
125 private:
Mathias Agopian1fed11c2009-06-23 18:08:22 -0700126 mutable Mutex mLock;
127 sp<Buffer> mBuffer;
128 status_t mStatus;
129 ISurface::BufferHeap mBufferHeap;
130 size_t mBufferSize;
131 mutable sp<android::Buffer> mTempBitmap;
132 mutable LayerBase::Texture mTexture;
Mathias Agopian69029eb2009-06-23 21:11:43 -0700133 copybit_device_t* mBlitEngine;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800134 };
135
136 class OverlaySource : public Source {
137 public:
138 OverlaySource(LayerBuffer& layer,
139 sp<OverlayRef>* overlayRef,
140 uint32_t w, uint32_t h, int32_t format);
141 virtual ~OverlaySource();
142 virtual void onTransaction(uint32_t flags);
143 virtual void onVisibilityResolved(const Transform& planeTransform);
144 private:
145 void serverDestroy();
146 void destroyOverlay();
147 class OverlayChannel : public BnOverlay {
148 mutable Mutex mLock;
149 sp<OverlaySource> mSource;
150 virtual void destroy() {
151 sp<OverlaySource> source;
152 { // scope for the lock;
153 Mutex::Autolock _l(mLock);
154 source = mSource;
155 mSource.clear();
156 }
157 if (source != 0) {
158 source->serverDestroy();
159 }
160 }
161 public:
162 OverlayChannel(const sp<OverlaySource>& source)
163 : mSource(source) {
164 }
165 };
166 friend class OverlayChannel;
167 bool mVisibilityChanged;
168
169 overlay_t* mOverlay;
170 overlay_handle_t mOverlayHandle;
171 overlay_control_device_t* mOverlayDevice;
172 uint32_t mWidth;
173 uint32_t mHeight;
174 int32_t mFormat;
175 int32_t mWidthStride;
176 int32_t mHeightStride;
177 mutable Mutex mLock;
178 };
179
180
181 class SurfaceBuffer : public LayerBaseClient::Surface
182 {
183 public:
Mathias Agopian9a112062009-04-17 19:36:26 -0700184 SurfaceBuffer(const sp<SurfaceFlinger>& flinger,
185 SurfaceID id, const sp<LayerBuffer>& owner);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800186 virtual ~SurfaceBuffer();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700187
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800188 virtual status_t registerBuffers(const ISurface::BufferHeap& buffers);
189 virtual void postBuffer(ssize_t offset);
190 virtual void unregisterBuffers();
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700191
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800192 virtual sp<OverlayRef> createOverlay(
193 uint32_t w, uint32_t h, int32_t format);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800194 private:
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700195 sp<LayerBuffer> getOwner() const {
196 return static_cast<LayerBuffer*>(Surface::getOwner().get());
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800197 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800198 };
Mathias Agopian9a112062009-04-17 19:36:26 -0700199
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800200 mutable Mutex mLock;
201 sp<Source> mSource;
Mathias Agopian9a112062009-04-17 19:36:26 -0700202 sp<Surface> mSurface;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800203 bool mInvalidate;
204 bool mNeedsBlending;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800205};
206
207// ---------------------------------------------------------------------------
208
209}; // namespace android
210
211#endif // ANDROID_LAYER_BUFFER_H