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