The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 23 | #include <hardware/gralloc.h> |
| 24 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | #include <utils/Atomic.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 26 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | #include <ui/PixelFormat.h> |
| 28 | #include <ui/Rect.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 29 | #include <ui/Surface.h> |
| 30 | |
| 31 | #include <EGL/android_natives.h> |
| 32 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | #include <pixelflinger/pixelflinger.h> |
| 34 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 35 | #include <private/ui/SharedState.h> |
| 36 | |
| 37 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | class copybit_image_t; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 39 | struct android_native_buffer_t; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | |
| 41 | namespace android { |
| 42 | |
| 43 | // --------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | class IMemory; |
| 45 | class MemoryDealer; |
| 46 | class LayerBitmap; |
| 47 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 48 | // =========================================================================== |
| 49 | // Buffer |
| 50 | // =========================================================================== |
| 51 | |
| 52 | class NativeBuffer; |
| 53 | |
| 54 | class Buffer : public SurfaceBuffer |
| 55 | { |
| 56 | public: |
| 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 | |
| 81 | private: |
| 82 | friend class LightRefBase<Buffer>; |
| 83 | Buffer(const Buffer& rhs); |
Mathias Agopian | 8b765b7 | 2009-04-10 20:34:46 -0700 | [diff] [blame^] | 84 | virtual ~Buffer(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 85 | 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 98 | |
| 99 | class LayerBitmap |
| 100 | { |
| 101 | public: |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | enum { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 103 | DONT_CLEAR = Buffer::DONT_CLEAR, |
| 104 | GPU = Buffer::GPU, |
| 105 | SECURE = Buffer::SECURE |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | }; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 107 | LayerBitmap(); |
| 108 | ~LayerBitmap(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 109 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 110 | status_t init(surface_info_t* info, |
| 111 | uint32_t w, uint32_t h, PixelFormat format, uint32_t flags = 0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 113 | status_t setSize(uint32_t w, uint32_t h); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 115 | sp<Buffer> allocate(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 116 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 117 | 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 125 | private: |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 126 | 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | }; // namespace android |
| 137 | |
| 138 | #endif // ANDROID_LAYER_BITMAP_H |