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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/omx-plugin/include/gb/ui/GraphicBuffer.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,157 @@
     1.4 +/*
     1.5 + * Copyright (C) 2007 The Android Open Source Project
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * Unless required by applicable law or agreed to in writing, software
    1.14 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 + * See the License for the specific language governing permissions and
    1.17 + * limitations under the License.
    1.18 + */
    1.19 +
    1.20 +#ifndef ANDROID_GRAPHIC_BUFFER_H
    1.21 +#define ANDROID_GRAPHIC_BUFFER_H
    1.22 +
    1.23 +#include <stdint.h>
    1.24 +#include <sys/types.h>
    1.25 +
    1.26 +#include <ui/android_native_buffer.h>
    1.27 +#include <ui/PixelFormat.h>
    1.28 +#include <ui/Rect.h>
    1.29 +#include <utils/Flattenable.h>
    1.30 +#include <pixelflinger/pixelflinger.h>
    1.31 +
    1.32 +#include <hardware/hardware.h>
    1.33 +
    1.34 +struct android_native_buffer_t;
    1.35 +
    1.36 +namespace android {
    1.37 +
    1.38 +class GraphicBufferMapper;
    1.39 +
    1.40 +// ===========================================================================
    1.41 +// GraphicBuffer
    1.42 +// ===========================================================================
    1.43 +
    1.44 +class GraphicBuffer
    1.45 +    : public EGLNativeBase<
    1.46 +        android_native_buffer_t, 
    1.47 +        GraphicBuffer, 
    1.48 +        LightRefBase<GraphicBuffer> >, public Flattenable
    1.49 +{
    1.50 +public:
    1.51 +
    1.52 +    enum {
    1.53 +        USAGE_SW_READ_NEVER     = GRALLOC_USAGE_SW_READ_NEVER,
    1.54 +        USAGE_SW_READ_RARELY    = GRALLOC_USAGE_SW_READ_RARELY,
    1.55 +        USAGE_SW_READ_OFTEN     = GRALLOC_USAGE_SW_READ_OFTEN,
    1.56 +        USAGE_SW_READ_MASK      = GRALLOC_USAGE_SW_READ_MASK,
    1.57 +        
    1.58 +        USAGE_SW_WRITE_NEVER    = GRALLOC_USAGE_SW_WRITE_NEVER,
    1.59 +        USAGE_SW_WRITE_RARELY   = GRALLOC_USAGE_SW_WRITE_RARELY,
    1.60 +        USAGE_SW_WRITE_OFTEN    = GRALLOC_USAGE_SW_WRITE_OFTEN,
    1.61 +        USAGE_SW_WRITE_MASK     = GRALLOC_USAGE_SW_WRITE_MASK,
    1.62 +        
    1.63 +        USAGE_SOFTWARE_MASK     = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK,
    1.64 +        
    1.65 +        USAGE_HW_TEXTURE        = GRALLOC_USAGE_HW_TEXTURE,
    1.66 +        USAGE_HW_RENDER         = GRALLOC_USAGE_HW_RENDER,
    1.67 +        USAGE_HW_2D             = GRALLOC_USAGE_HW_2D,
    1.68 +        USAGE_HW_MASK           = GRALLOC_USAGE_HW_MASK
    1.69 +    };
    1.70 +
    1.71 +    enum {
    1.72 +        TRANSFORM_IDENTITY      = 0,
    1.73 +        TRANSFORM_ROT_90        = HAL_TRANSFORM_ROT_90,
    1.74 +        TRANSFORM_ROT_180       = HAL_TRANSFORM_ROT_180,
    1.75 +        TRANSFORM_ROT_270       = HAL_TRANSFORM_ROT_270
    1.76 +    };
    1.77 +
    1.78 +    GraphicBuffer();
    1.79 +
    1.80 +    // creates w * h buffer
    1.81 +    GraphicBuffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage);
    1.82 +
    1.83 +    // create a buffer from an existing handle
    1.84 +    GraphicBuffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage,
    1.85 +            uint32_t stride, native_handle_t* handle, bool keepOwnership);
    1.86 +
    1.87 +    // return status
    1.88 +    status_t initCheck() const;
    1.89 +
    1.90 +    uint32_t getWidth() const           { return width; }
    1.91 +    uint32_t getHeight() const          { return height; }
    1.92 +    uint32_t getStride() const          { return stride; }
    1.93 +    uint32_t getUsage() const           { return usage; }
    1.94 +    uint32_t getTransform() const       { return transform; }
    1.95 +    PixelFormat getPixelFormat() const  { return format; }
    1.96 +    Rect getBounds() const              { return Rect(width, height); }
    1.97 +    
    1.98 +    status_t reallocate(uint32_t w, uint32_t h, PixelFormat f, uint32_t usage);
    1.99 +
   1.100 +    status_t lock(uint32_t usage, void** vaddr);
   1.101 +    status_t lock(uint32_t usage, const Rect& rect, void** vaddr);
   1.102 +    status_t lock(GGLSurface* surface, uint32_t usage);
   1.103 +    status_t unlock();
   1.104 +
   1.105 +    android_native_buffer_t* getNativeBuffer() const;
   1.106 +    
   1.107 +    void setIndex(int index);
   1.108 +    int getIndex() const;
   1.109 +
   1.110 +    // for debugging
   1.111 +    static void dumpAllocationsToSystemLog();
   1.112 +
   1.113 +private:
   1.114 +    virtual ~GraphicBuffer();
   1.115 +
   1.116 +    enum {
   1.117 +        ownNone   = 0,
   1.118 +        ownHandle = 1,
   1.119 +        ownData   = 2,
   1.120 +    };
   1.121 +
   1.122 +    inline const GraphicBufferMapper& getBufferMapper() const {
   1.123 +        return mBufferMapper;
   1.124 +    }
   1.125 +    inline GraphicBufferMapper& getBufferMapper() {
   1.126 +        return mBufferMapper;
   1.127 +    }
   1.128 +    uint8_t mOwner;
   1.129 +
   1.130 +private:
   1.131 +    friend class Surface;
   1.132 +    friend class BpSurface;
   1.133 +    friend class BnSurface;
   1.134 +    friend class LightRefBase<GraphicBuffer>;
   1.135 +    GraphicBuffer(const GraphicBuffer& rhs);
   1.136 +    GraphicBuffer& operator = (const GraphicBuffer& rhs);
   1.137 +    const GraphicBuffer& operator = (const GraphicBuffer& rhs) const;
   1.138 +
   1.139 +    status_t initSize(uint32_t w, uint32_t h, PixelFormat format, 
   1.140 +            uint32_t usage);
   1.141 +
   1.142 +    void free_handle();
   1.143 +
   1.144 +    // Flattenable interface
   1.145 +    size_t getFlattenedSize() const;
   1.146 +    size_t getFdCount() const;
   1.147 +    status_t flatten(void* buffer, size_t size,
   1.148 +            int fds[], size_t count) const;
   1.149 +    status_t unflatten(void const* buffer, size_t size,
   1.150 +            int fds[], size_t count);
   1.151 +
   1.152 +
   1.153 +    GraphicBufferMapper& mBufferMapper;
   1.154 +    ssize_t mInitCheck;
   1.155 +    int mIndex;
   1.156 +};
   1.157 +
   1.158 +}; // namespace android
   1.159 +
   1.160 +#endif // ANDROID_GRAPHIC_BUFFER_H

mercurial