blob: 22525cebdfc5145673b39d8116af8b926f3cf3fb [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_BITMAP_H
18#define ANDROID_LAYER_BITMAP_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
Mathias Agopian076b1cc2009-04-10 14:24:30 -070023#include <hardware/gralloc.h>
24
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025#include <utils/Atomic.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070026
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027#include <ui/PixelFormat.h>
28#include <ui/Rect.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070029#include <ui/Surface.h>
30
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080031#include <pixelflinger/pixelflinger.h>
32
Mathias Agopian076b1cc2009-04-10 14:24:30 -070033#include <private/ui/SharedState.h>
Mathias Agopian7189c002009-05-05 18:11:11 -070034#include <private/ui/SurfaceBuffer.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070035
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036class copybit_image_t;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070037struct android_native_buffer_t;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038
39namespace android {
40
41// ---------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042class IMemory;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080043class LayerBitmap;
44
Mathias Agopian076b1cc2009-04-10 14:24:30 -070045// ===========================================================================
46// Buffer
47// ===========================================================================
48
49class NativeBuffer;
50
51class Buffer : public SurfaceBuffer
52{
53public:
54 enum {
55 DONT_CLEAR = 0x00000001,
56 GPU = 0x00000002,
57 SECURE = 0x00000004
58 };
59
60 // creates w * h buffer
Fred Quintanab2fd4662009-08-11 20:49:35 -070061 Buffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t flags = 0);
Mathias Agopian076b1cc2009-04-10 14:24:30 -070062
63 // return status
64 status_t initCheck() const;
65
66 uint32_t getWidth() const { return width; }
67 uint32_t getHeight() const { return height; }
68 uint32_t getStride() const { return stride; }
69 uint32_t getUsage() const { return usage; }
70 PixelFormat getPixelFormat() const { return format; }
71 Rect getBounds() const { return Rect(width, height); }
72
Mathias Agopian0926f502009-05-04 14:17:04 -070073 status_t lock(GGLSurface* surface, uint32_t usage);
74
Mathias Agopian076b1cc2009-04-10 14:24:30 -070075 android_native_buffer_t* getNativeBuffer() const;
76
77private:
78 friend class LightRefBase<Buffer>;
79 Buffer(const Buffer& rhs);
Mathias Agopian8b765b72009-04-10 20:34:46 -070080 virtual ~Buffer();
Mathias Agopian076b1cc2009-04-10 14:24:30 -070081 Buffer& operator = (const Buffer& rhs);
82 const Buffer& operator = (const Buffer& rhs) const;
83
Fred Quintanab2fd4662009-08-11 20:49:35 -070084 status_t initSize(uint32_t w, uint32_t h);
Mathias Agopian076b1cc2009-04-10 14:24:30 -070085
86 ssize_t mInitCheck;
87 uint32_t mFlags;
88 uint32_t mVStride;
89};
90
91// ===========================================================================
92// LayerBitmap
93// ===========================================================================
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080094
95class LayerBitmap
96{
97public:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080098 enum {
Mathias Agopian076b1cc2009-04-10 14:24:30 -070099 DONT_CLEAR = Buffer::DONT_CLEAR,
100 GPU = Buffer::GPU,
101 SECURE = Buffer::SECURE
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102 };
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700103 LayerBitmap();
104 ~LayerBitmap();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800105
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700106 status_t init(surface_info_t* info,
107 uint32_t w, uint32_t h, PixelFormat format, uint32_t flags = 0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800108
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700109 status_t setSize(uint32_t w, uint32_t h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800110
Fred Quintanab2fd4662009-08-11 20:49:35 -0700111 sp<Buffer> allocate();
Mathias Agopian759fdb22009-07-02 17:33:40 -0700112 status_t free();
113
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700114 sp<const Buffer> getBuffer() const { return mBuffer; }
115 sp<Buffer> getBuffer() { return mBuffer; }
116
117 uint32_t getWidth() const { return mWidth; }
118 uint32_t getHeight() const { return mHeight; }
119 PixelFormat getPixelFormat() const { return mBuffer->getPixelFormat(); }
120 Rect getBounds() const { return mBuffer->getBounds(); }
121
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800122private:
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700123 surface_info_t* mInfo;
124 sp<Buffer> mBuffer;
125 uint32_t mWidth;
126 uint32_t mHeight;
127 PixelFormat mFormat;
128 uint32_t mFlags;
129 // protects setSize() and allocate()
130 mutable Mutex mLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800131};
132
133}; // namespace android
134
135#endif // ANDROID_LAYER_BITMAP_H