blob: f3636c03e03bcf39c137d323d58b4880a53f7cca [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;
43class MemoryDealer;
44class LayerBitmap;
45
Mathias Agopian076b1cc2009-04-10 14:24:30 -070046// ===========================================================================
47// Buffer
48// ===========================================================================
49
50class NativeBuffer;
51
52class Buffer : public SurfaceBuffer
53{
54public:
55 enum {
56 DONT_CLEAR = 0x00000001,
57 GPU = 0x00000002,
58 SECURE = 0x00000004
59 };
60
61 // creates w * h buffer
62 Buffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t flags = 0);
63
64 // return status
65 status_t initCheck() const;
66
67 uint32_t getWidth() const { return width; }
68 uint32_t getHeight() const { return height; }
69 uint32_t getStride() const { return stride; }
70 uint32_t getUsage() const { return usage; }
71 PixelFormat getPixelFormat() const { return format; }
72 Rect getBounds() const { return Rect(width, height); }
73
Mathias Agopian0926f502009-05-04 14:17:04 -070074 status_t lock(GGLSurface* surface, uint32_t usage);
75
Mathias Agopian076b1cc2009-04-10 14:24:30 -070076 android_native_buffer_t* getNativeBuffer() const;
77
78private:
79 friend class LightRefBase<Buffer>;
80 Buffer(const Buffer& rhs);
Mathias Agopian8b765b72009-04-10 20:34:46 -070081 virtual ~Buffer();
Mathias Agopian076b1cc2009-04-10 14:24:30 -070082 Buffer& operator = (const Buffer& rhs);
83 const Buffer& operator = (const Buffer& rhs) const;
84
85 status_t initSize(uint32_t w, uint32_t h);
86
87 ssize_t mInitCheck;
88 uint32_t mFlags;
89 uint32_t mVStride;
90};
91
92// ===========================================================================
93// LayerBitmap
94// ===========================================================================
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080095
96class LayerBitmap
97{
98public:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080099 enum {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700100 DONT_CLEAR = Buffer::DONT_CLEAR,
101 GPU = Buffer::GPU,
102 SECURE = Buffer::SECURE
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800103 };
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700104 LayerBitmap();
105 ~LayerBitmap();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700107 status_t init(surface_info_t* info,
108 uint32_t w, uint32_t h, PixelFormat format, uint32_t flags = 0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700110 status_t setSize(uint32_t w, uint32_t h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800111
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700112 sp<Buffer> allocate();
Mathias Agopian759fdb22009-07-02 17:33:40 -0700113 status_t free();
114
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700115 sp<const Buffer> getBuffer() const { return mBuffer; }
116 sp<Buffer> getBuffer() { return mBuffer; }
117
118 uint32_t getWidth() const { return mWidth; }
119 uint32_t getHeight() const { return mHeight; }
120 PixelFormat getPixelFormat() const { return mBuffer->getPixelFormat(); }
121 Rect getBounds() const { return mBuffer->getBounds(); }
122
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800123private:
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700124 surface_info_t* mInfo;
125 sp<Buffer> mBuffer;
126 uint32_t mWidth;
127 uint32_t mHeight;
128 PixelFormat mFormat;
129 uint32_t mFlags;
130 // protects setSize() and allocate()
131 mutable Mutex mLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800132};
133
134}; // namespace android
135
136#endif // ANDROID_LAYER_BITMAP_H