blob: e6737550f2812f8eda1ef647fb200016f37bc546 [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
31#include <EGL/android_natives.h>
32
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033#include <pixelflinger/pixelflinger.h>
34
Mathias Agopian076b1cc2009-04-10 14:24:30 -070035#include <private/ui/SharedState.h>
36
37
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080038class copybit_image_t;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070039struct android_native_buffer_t;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080040
41namespace android {
42
43// ---------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044class IMemory;
45class MemoryDealer;
46class LayerBitmap;
47
Mathias Agopian076b1cc2009-04-10 14:24:30 -070048// ===========================================================================
49// Buffer
50// ===========================================================================
51
52class NativeBuffer;
53
54class Buffer : public SurfaceBuffer
55{
56public:
57 enum {
58 DONT_CLEAR = 0x00000001,
59 GPU = 0x00000002,
60 SECURE = 0x00000004
61 };
62
63 // creates w * h buffer
64 Buffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t flags = 0);
65
66 // return status
67 status_t initCheck() const;
68
69 uint32_t getWidth() const { return width; }
70 uint32_t getHeight() const { return height; }
71 uint32_t getStride() const { return stride; }
72 uint32_t getUsage() const { return usage; }
73 PixelFormat getPixelFormat() const { return format; }
74 Rect getBounds() const { return Rect(width, height); }
75
76 status_t getBitmapSurface(copybit_image_t* img) const;
77 status_t getBitmapSurface(GGLSurface* surface) const;
78
79 android_native_buffer_t* getNativeBuffer() const;
80
81private:
82 friend class LightRefBase<Buffer>;
83 Buffer(const Buffer& rhs);
Mathias Agopian8b765b72009-04-10 20:34:46 -070084 virtual ~Buffer();
Mathias Agopian076b1cc2009-04-10 14:24:30 -070085 Buffer& operator = (const Buffer& rhs);
86 const Buffer& operator = (const Buffer& rhs) const;
87
88 status_t initSize(uint32_t w, uint32_t h);
89
90 ssize_t mInitCheck;
91 uint32_t mFlags;
92 uint32_t mVStride;
93};
94
95// ===========================================================================
96// LayerBitmap
97// ===========================================================================
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080098
99class LayerBitmap
100{
101public:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102 enum {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700103 DONT_CLEAR = Buffer::DONT_CLEAR,
104 GPU = Buffer::GPU,
105 SECURE = Buffer::SECURE
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106 };
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700107 LayerBitmap();
108 ~LayerBitmap();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700110 status_t init(surface_info_t* info,
111 uint32_t w, uint32_t h, PixelFormat format, uint32_t flags = 0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800112
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700113 status_t setSize(uint32_t w, uint32_t h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800114
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700115 sp<Buffer> allocate();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800116
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700117 sp<const Buffer> getBuffer() const { return mBuffer; }
118 sp<Buffer> getBuffer() { return mBuffer; }
119
120 uint32_t getWidth() const { return mWidth; }
121 uint32_t getHeight() const { return mHeight; }
122 PixelFormat getPixelFormat() const { return mBuffer->getPixelFormat(); }
123 Rect getBounds() const { return mBuffer->getBounds(); }
124
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800125private:
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700126 surface_info_t* mInfo;
127 sp<Buffer> mBuffer;
128 uint32_t mWidth;
129 uint32_t mHeight;
130 PixelFormat mFormat;
131 uint32_t mFlags;
132 // protects setSize() and allocate()
133 mutable Mutex mLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800134};
135
136}; // namespace android
137
138#endif // ANDROID_LAYER_BITMAP_H