blob: 6e136a2ae7649c4172f5138967b5066fdbde6c83 [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
Mathias Agopian0926f502009-05-04 14:17:04 -070076 status_t lock(GGLSurface* surface, uint32_t usage);
77
Mathias Agopian076b1cc2009-04-10 14:24:30 -070078 android_native_buffer_t* getNativeBuffer() const;
79
80private:
81 friend class LightRefBase<Buffer>;
82 Buffer(const Buffer& rhs);
Mathias Agopian8b765b72009-04-10 20:34:46 -070083 virtual ~Buffer();
Mathias Agopian076b1cc2009-04-10 14:24:30 -070084 Buffer& operator = (const Buffer& rhs);
85 const Buffer& operator = (const Buffer& rhs) const;
86
87 status_t initSize(uint32_t w, uint32_t h);
88
89 ssize_t mInitCheck;
90 uint32_t mFlags;
91 uint32_t mVStride;
92};
93
94// ===========================================================================
95// LayerBitmap
96// ===========================================================================
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080097
98class LayerBitmap
99{
100public:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800101 enum {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700102 DONT_CLEAR = Buffer::DONT_CLEAR,
103 GPU = Buffer::GPU,
104 SECURE = Buffer::SECURE
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800105 };
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700106 LayerBitmap();
107 ~LayerBitmap();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800108
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700109 status_t init(surface_info_t* info,
110 uint32_t w, uint32_t h, PixelFormat format, uint32_t flags = 0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800111
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700112 status_t setSize(uint32_t w, uint32_t h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800113
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700114 sp<Buffer> allocate();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800115
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700116 sp<const Buffer> getBuffer() const { return mBuffer; }
117 sp<Buffer> getBuffer() { return mBuffer; }
118
119 uint32_t getWidth() const { return mWidth; }
120 uint32_t getHeight() const { return mHeight; }
121 PixelFormat getPixelFormat() const { return mBuffer->getPixelFormat(); }
122 Rect getBounds() const { return mBuffer->getBounds(); }
123
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800124private:
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700125 surface_info_t* mInfo;
126 sp<Buffer> mBuffer;
127 uint32_t mWidth;
128 uint32_t mHeight;
129 PixelFormat mFormat;
130 uint32_t mFlags;
131 // protects setSize() and allocate()
132 mutable Mutex mLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800133};
134
135}; // namespace android
136
137#endif // ANDROID_LAYER_BITMAP_H