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 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | #include <pixelflinger/pixelflinger.h> |
| 32 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 33 | #include <private/ui/SharedState.h> |
Mathias Agopian | 7189c00 | 2009-05-05 18:11:11 -0700 | [diff] [blame] | 34 | #include <private/ui/SurfaceBuffer.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 35 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | class copybit_image_t; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 37 | struct android_native_buffer_t; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
| 39 | namespace android { |
| 40 | |
| 41 | // --------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | class IMemory; |
| 43 | class MemoryDealer; |
| 44 | class LayerBitmap; |
| 45 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 46 | // =========================================================================== |
| 47 | // Buffer |
| 48 | // =========================================================================== |
| 49 | |
| 50 | class NativeBuffer; |
| 51 | |
| 52 | class Buffer : public SurfaceBuffer |
| 53 | { |
| 54 | public: |
| 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 Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 74 | status_t lock(GGLSurface* surface, uint32_t usage); |
| 75 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 76 | android_native_buffer_t* getNativeBuffer() const; |
| 77 | |
| 78 | private: |
| 79 | friend class LightRefBase<Buffer>; |
| 80 | Buffer(const Buffer& rhs); |
Mathias Agopian | 8b765b7 | 2009-04-10 20:34:46 -0700 | [diff] [blame] | 81 | virtual ~Buffer(); |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 82 | 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | |
| 96 | class LayerBitmap |
| 97 | { |
| 98 | public: |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | enum { |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 100 | DONT_CLEAR = Buffer::DONT_CLEAR, |
| 101 | GPU = Buffer::GPU, |
| 102 | SECURE = Buffer::SECURE |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | }; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 104 | LayerBitmap(); |
| 105 | ~LayerBitmap(); |
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 | status_t init(surface_info_t* info, |
| 108 | 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] | 109 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 110 | status_t setSize(uint32_t w, uint32_t h); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 112 | sp<Buffer> allocate(); |
Mathias Agopian | 759fdb2 | 2009-07-02 17:33:40 -0700 | [diff] [blame^] | 113 | status_t free(); |
| 114 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 115 | 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | private: |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 124 | 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 Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | }; |
| 133 | |
| 134 | }; // namespace android |
| 135 | |
| 136 | #endif // ANDROID_LAYER_BITMAP_H |