The Android Open Source Project | 9066cfe | 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 | |
| 23 | #include <utils/Atomic.h> |
| 24 | #include <ui/PixelFormat.h> |
| 25 | #include <ui/Rect.h> |
| 26 | #include <private/ui/SharedState.h> |
| 27 | #include <pixelflinger/pixelflinger.h> |
| 28 | |
| 29 | class copybit_image_t; |
| 30 | |
| 31 | namespace android { |
| 32 | |
| 33 | // --------------------------------------------------------------------------- |
| 34 | |
| 35 | class IMemory; |
| 36 | class MemoryDealer; |
| 37 | class LayerBitmap; |
| 38 | |
| 39 | // --------------------------------------------------------------------------- |
| 40 | |
| 41 | class LayerBitmap |
| 42 | { |
| 43 | public: |
| 44 | |
| 45 | enum { |
| 46 | // erase memory to ensure security when necessary |
| 47 | SECURE_BITS = 0x00000001 |
| 48 | }; |
| 49 | |
| 50 | LayerBitmap(); |
| 51 | ~LayerBitmap(); |
| 52 | status_t init(const sp<MemoryDealer>& allocator); |
| 53 | |
| 54 | status_t setBits(uint32_t w, uint32_t h, uint32_t alignment, |
| 55 | PixelFormat format, uint32_t flags = 0); |
| 56 | void clear(); |
| 57 | |
| 58 | status_t getInfo(surface_info_t* info) const; |
| 59 | status_t resize(uint32_t w, uint32_t h); |
| 60 | |
| 61 | const GGLSurface& surface() const { return mSurface; } |
| 62 | Rect bounds() const { return Rect(width(), height()); } |
| 63 | uint32_t width() const { return surface().width; } |
| 64 | uint32_t height() const { return surface().height; } |
| 65 | uint32_t stride() const { return surface().stride; } |
| 66 | PixelFormat pixelFormat() const { return surface().format; } |
| 67 | void* serverBits() const { return surface().data; } |
| 68 | size_t size() const; |
| 69 | const sp<MemoryDealer>& getAllocator() const { return mAllocator; } |
| 70 | void getBitmapSurface(copybit_image_t* img) const; |
| 71 | |
| 72 | private: |
| 73 | sp<MemoryDealer> mAllocator; |
| 74 | sp<IMemory> mBitsMemory; |
| 75 | uint32_t mAllocFlags; |
| 76 | ssize_t mOffset; |
| 77 | GGLSurface mSurface; |
| 78 | size_t mSize; |
| 79 | uint32_t mAlignment; |
| 80 | }; |
| 81 | |
| 82 | }; // namespace android |
| 83 | |
| 84 | #endif // ANDROID_LAYER_BITMAP_H |