blob: 87e8f42b145e345d737e3943fab09f568a9eea98 [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,
Mathias Agopian076b1cc2009-04-10 14:24:30 -070056 SECURE = 0x00000004
57 };
58
59 // creates w * h buffer
Mathias Agopian52212712009-08-11 22:34:02 -070060 Buffer(uint32_t w, uint32_t h, PixelFormat format,
61 uint32_t reqUsage, 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
Mathias Agopian52212712009-08-11 22:34:02 -070084 status_t initSize(uint32_t w, uint32_t h, uint32_t reqUsage);
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,
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700100 SECURE = Buffer::SECURE
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800101 };
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700102 LayerBitmap();
103 ~LayerBitmap();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800104
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700105 status_t init(surface_info_t* info,
106 uint32_t w, uint32_t h, PixelFormat format, uint32_t flags = 0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800107
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700108 status_t setSize(uint32_t w, uint32_t h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109
Mathias Agopian52212712009-08-11 22:34:02 -0700110 sp<Buffer> allocate(uint32_t reqUsage);
Mathias Agopian759fdb22009-07-02 17:33:40 -0700111 status_t free();
112
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700113 sp<const Buffer> getBuffer() const { return mBuffer; }
114 sp<Buffer> getBuffer() { return mBuffer; }
115
116 uint32_t getWidth() const { return mWidth; }
117 uint32_t getHeight() const { return mHeight; }
118 PixelFormat getPixelFormat() const { return mBuffer->getPixelFormat(); }
119 Rect getBounds() const { return mBuffer->getBounds(); }
120
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800121private:
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700122 surface_info_t* mInfo;
123 sp<Buffer> mBuffer;
124 uint32_t mWidth;
125 uint32_t mHeight;
126 PixelFormat mFormat;
127 uint32_t mFlags;
128 // protects setSize() and allocate()
129 mutable Mutex mLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800130};
131
132}; // namespace android
133
134#endif // ANDROID_LAYER_BITMAP_H