blob: ef473dd4b006eeebbc7deb700e4fdb9174660226 [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
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>
25#include <GLES/eglnatives.h>
26
27#include "LayerBase.h"
28#include "LayerBitmap.h"
29
30namespace android {
31
32// ---------------------------------------------------------------------------
33
34class MemoryDealer;
35class Region;
36
37class LayerBuffer : public LayerBaseClient
38{
39public:
40 static const uint32_t typeInfo;
41 static const char* const typeID;
42 virtual char const* getTypeID() const { return typeID; }
43 virtual uint32_t getTypeInfo() const { return typeInfo; }
44
45 LayerBuffer(SurfaceFlinger* flinger, DisplayID display,
46 Client* client, int32_t i);
47 virtual ~LayerBuffer();
48
49 virtual bool needsBlending() const;
50
51 virtual sp<LayerBaseClient::Surface> getSurface() const;
52 virtual void onDraw(const Region& clip) const;
53 virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
54
55 status_t registerBuffers(int w, int h, int hstride, int vstride,
56 PixelFormat format, const sp<IMemoryHeap>& heap);
57 void postBuffer(ssize_t offset);
58 void unregisterBuffers();
59 void invalidate();
60 void invalidateLocked();
61
62private:
63
64 struct NativeBuffer
65 {
66 copybit_image_t img;
67 copybit_rect_t crop;
68 };
69
70 class Buffer
71 {
72 public:
73 Buffer(const sp<IMemoryHeap>& heap, ssize_t offset,
74 int w, int h, int hs, int vs, int f);
75 inline void incStrong(void*) const {
76 android_atomic_inc(&mCount);
77 }
78 inline void decStrong(void*) const {
79 int32_t c = android_atomic_dec(&mCount);
80 //LOGE_IF(c<1, "Buffer::decStrong() called too many times");
81 if (c == 1) {
82 delete this;
83 }
84 }
85 inline status_t getStatus() const {
86 return mHeap!=0 ? NO_ERROR : NO_INIT;
87 }
88 inline const NativeBuffer& getBuffer() const {
89 return mNativeBuffer;
90 }
91 protected:
92 Buffer& operator = (const Buffer& rhs);
93 Buffer(const Buffer& rhs);
94 ~Buffer();
95 mutable volatile int32_t mCount;
96 private:
97 sp<IMemoryHeap> mHeap;
98 NativeBuffer mNativeBuffer;
99 };
100
101 class SurfaceBuffer : public LayerBaseClient::Surface
102 {
103 public:
104 SurfaceBuffer(SurfaceID id, LayerBuffer* owner);
105 virtual ~SurfaceBuffer();
106 virtual status_t registerBuffers(int w, int h, int hstride, int vstride,
107 PixelFormat format, const sp<IMemoryHeap>& heap);
108 virtual void postBuffer(ssize_t offset);
109 virtual void unregisterBuffers();
110 void disown();
111 private:
112 LayerBuffer* getOwner() const {
113 Mutex::Autolock _l(mLock);
114 return mOwner;
115 }
116 mutable Mutex mLock;
117 LayerBuffer* mOwner;
118 };
119
120 friend class SurfaceFlinger;
121 sp<Buffer> getBuffer() const;
122 void setBuffer(const sp<Buffer>& buffer);
123 sp<SurfaceBuffer> getClientSurface() const;
124
125 mutable Mutex mLock;
126 sp<IMemoryHeap> mHeap;
127 sp<Buffer> mBuffer;
128 int mWidth;
129 int mHeight;
130 int mHStride;
131 int mVStride;
132 int mFormat;
133 mutable GLuint mTextureName;
134 bool mInvalidate;
135 bool mNeedsBlending;
136 mutable wp<SurfaceBuffer> mClientSurface;
137 mutable sp<MemoryDealer> mTemporaryDealer;
138 mutable LayerBitmap mTempBitmap;
139};
140
141// ---------------------------------------------------------------------------
142
143}; // namespace android
144
145#endif // ANDROID_LAYER_BUFFER_H