media/omx-plugin/include/gb/ui/GraphicBuffer.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /*
michael@0 2 * Copyright (C) 2007 The Android Open Source Project
michael@0 3 *
michael@0 4 * Licensed under the Apache License, Version 2.0 (the "License");
michael@0 5 * you may not use this file except in compliance with the License.
michael@0 6 * You may obtain a copy of the License at
michael@0 7 *
michael@0 8 * http://www.apache.org/licenses/LICENSE-2.0
michael@0 9 *
michael@0 10 * Unless required by applicable law or agreed to in writing, software
michael@0 11 * distributed under the License is distributed on an "AS IS" BASIS,
michael@0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
michael@0 13 * See the License for the specific language governing permissions and
michael@0 14 * limitations under the License.
michael@0 15 */
michael@0 16
michael@0 17 #ifndef ANDROID_GRAPHIC_BUFFER_H
michael@0 18 #define ANDROID_GRAPHIC_BUFFER_H
michael@0 19
michael@0 20 #include <stdint.h>
michael@0 21 #include <sys/types.h>
michael@0 22
michael@0 23 #include <ui/android_native_buffer.h>
michael@0 24 #include <ui/PixelFormat.h>
michael@0 25 #include <ui/Rect.h>
michael@0 26 #include <utils/Flattenable.h>
michael@0 27 #include <pixelflinger/pixelflinger.h>
michael@0 28
michael@0 29 #include <hardware/hardware.h>
michael@0 30
michael@0 31 struct android_native_buffer_t;
michael@0 32
michael@0 33 namespace android {
michael@0 34
michael@0 35 class GraphicBufferMapper;
michael@0 36
michael@0 37 // ===========================================================================
michael@0 38 // GraphicBuffer
michael@0 39 // ===========================================================================
michael@0 40
michael@0 41 class GraphicBuffer
michael@0 42 : public EGLNativeBase<
michael@0 43 android_native_buffer_t,
michael@0 44 GraphicBuffer,
michael@0 45 LightRefBase<GraphicBuffer> >, public Flattenable
michael@0 46 {
michael@0 47 public:
michael@0 48
michael@0 49 enum {
michael@0 50 USAGE_SW_READ_NEVER = GRALLOC_USAGE_SW_READ_NEVER,
michael@0 51 USAGE_SW_READ_RARELY = GRALLOC_USAGE_SW_READ_RARELY,
michael@0 52 USAGE_SW_READ_OFTEN = GRALLOC_USAGE_SW_READ_OFTEN,
michael@0 53 USAGE_SW_READ_MASK = GRALLOC_USAGE_SW_READ_MASK,
michael@0 54
michael@0 55 USAGE_SW_WRITE_NEVER = GRALLOC_USAGE_SW_WRITE_NEVER,
michael@0 56 USAGE_SW_WRITE_RARELY = GRALLOC_USAGE_SW_WRITE_RARELY,
michael@0 57 USAGE_SW_WRITE_OFTEN = GRALLOC_USAGE_SW_WRITE_OFTEN,
michael@0 58 USAGE_SW_WRITE_MASK = GRALLOC_USAGE_SW_WRITE_MASK,
michael@0 59
michael@0 60 USAGE_SOFTWARE_MASK = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK,
michael@0 61
michael@0 62 USAGE_HW_TEXTURE = GRALLOC_USAGE_HW_TEXTURE,
michael@0 63 USAGE_HW_RENDER = GRALLOC_USAGE_HW_RENDER,
michael@0 64 USAGE_HW_2D = GRALLOC_USAGE_HW_2D,
michael@0 65 USAGE_HW_MASK = GRALLOC_USAGE_HW_MASK
michael@0 66 };
michael@0 67
michael@0 68 enum {
michael@0 69 TRANSFORM_IDENTITY = 0,
michael@0 70 TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90,
michael@0 71 TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180,
michael@0 72 TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270
michael@0 73 };
michael@0 74
michael@0 75 GraphicBuffer();
michael@0 76
michael@0 77 // creates w * h buffer
michael@0 78 GraphicBuffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage);
michael@0 79
michael@0 80 // create a buffer from an existing handle
michael@0 81 GraphicBuffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage,
michael@0 82 uint32_t stride, native_handle_t* handle, bool keepOwnership);
michael@0 83
michael@0 84 // return status
michael@0 85 status_t initCheck() const;
michael@0 86
michael@0 87 uint32_t getWidth() const { return width; }
michael@0 88 uint32_t getHeight() const { return height; }
michael@0 89 uint32_t getStride() const { return stride; }
michael@0 90 uint32_t getUsage() const { return usage; }
michael@0 91 uint32_t getTransform() const { return transform; }
michael@0 92 PixelFormat getPixelFormat() const { return format; }
michael@0 93 Rect getBounds() const { return Rect(width, height); }
michael@0 94
michael@0 95 status_t reallocate(uint32_t w, uint32_t h, PixelFormat f, uint32_t usage);
michael@0 96
michael@0 97 status_t lock(uint32_t usage, void** vaddr);
michael@0 98 status_t lock(uint32_t usage, const Rect& rect, void** vaddr);
michael@0 99 status_t lock(GGLSurface* surface, uint32_t usage);
michael@0 100 status_t unlock();
michael@0 101
michael@0 102 android_native_buffer_t* getNativeBuffer() const;
michael@0 103
michael@0 104 void setIndex(int index);
michael@0 105 int getIndex() const;
michael@0 106
michael@0 107 // for debugging
michael@0 108 static void dumpAllocationsToSystemLog();
michael@0 109
michael@0 110 private:
michael@0 111 virtual ~GraphicBuffer();
michael@0 112
michael@0 113 enum {
michael@0 114 ownNone = 0,
michael@0 115 ownHandle = 1,
michael@0 116 ownData = 2,
michael@0 117 };
michael@0 118
michael@0 119 inline const GraphicBufferMapper& getBufferMapper() const {
michael@0 120 return mBufferMapper;
michael@0 121 }
michael@0 122 inline GraphicBufferMapper& getBufferMapper() {
michael@0 123 return mBufferMapper;
michael@0 124 }
michael@0 125 uint8_t mOwner;
michael@0 126
michael@0 127 private:
michael@0 128 friend class Surface;
michael@0 129 friend class BpSurface;
michael@0 130 friend class BnSurface;
michael@0 131 friend class LightRefBase<GraphicBuffer>;
michael@0 132 GraphicBuffer(const GraphicBuffer& rhs);
michael@0 133 GraphicBuffer& operator = (const GraphicBuffer& rhs);
michael@0 134 const GraphicBuffer& operator = (const GraphicBuffer& rhs) const;
michael@0 135
michael@0 136 status_t initSize(uint32_t w, uint32_t h, PixelFormat format,
michael@0 137 uint32_t usage);
michael@0 138
michael@0 139 void free_handle();
michael@0 140
michael@0 141 // Flattenable interface
michael@0 142 size_t getFlattenedSize() const;
michael@0 143 size_t getFdCount() const;
michael@0 144 status_t flatten(void* buffer, size_t size,
michael@0 145 int fds[], size_t count) const;
michael@0 146 status_t unflatten(void const* buffer, size_t size,
michael@0 147 int fds[], size_t count);
michael@0 148
michael@0 149
michael@0 150 GraphicBufferMapper& mBufferMapper;
michael@0 151 ssize_t mInitCheck;
michael@0 152 int mIndex;
michael@0 153 };
michael@0 154
michael@0 155 }; // namespace android
michael@0 156
michael@0 157 #endif // ANDROID_GRAPHIC_BUFFER_H

mercurial