media/omx-plugin/include/ics/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/ics/ui/GraphicBuffer.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,159 @@
     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 +struct ANativeWindowBuffer;
    1.33 +
    1.34 +namespace android {
    1.35 +
    1.36 +class GraphicBufferMapper;
    1.37 +
    1.38 +// ===========================================================================
    1.39 +// GraphicBuffer
    1.40 +// ===========================================================================
    1.41 +
    1.42 +class GraphicBuffer
    1.43 +    : public EGLNativeBase<
    1.44 +        ANativeWindowBuffer,
    1.45 +        GraphicBuffer, 
    1.46 +        LightRefBase<GraphicBuffer> >, public Flattenable
    1.47 +{
    1.48 +public:
    1.49 +
    1.50 +    enum {
    1.51 +        USAGE_SW_READ_NEVER     = GRALLOC_USAGE_SW_READ_NEVER,
    1.52 +        USAGE_SW_READ_RARELY    = GRALLOC_USAGE_SW_READ_RARELY,
    1.53 +        USAGE_SW_READ_OFTEN     = GRALLOC_USAGE_SW_READ_OFTEN,
    1.54 +        USAGE_SW_READ_MASK      = GRALLOC_USAGE_SW_READ_MASK,
    1.55 +        
    1.56 +        USAGE_SW_WRITE_NEVER    = GRALLOC_USAGE_SW_WRITE_NEVER,
    1.57 +        USAGE_SW_WRITE_RARELY   = GRALLOC_USAGE_SW_WRITE_RARELY,
    1.58 +        USAGE_SW_WRITE_OFTEN    = GRALLOC_USAGE_SW_WRITE_OFTEN,
    1.59 +        USAGE_SW_WRITE_MASK     = GRALLOC_USAGE_SW_WRITE_MASK,
    1.60 +
    1.61 +        USAGE_SOFTWARE_MASK     = USAGE_SW_READ_MASK|USAGE_SW_WRITE_MASK,
    1.62 +
    1.63 +        USAGE_PROTECTED         = GRALLOC_USAGE_PROTECTED,
    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_COMPOSER       = GRALLOC_USAGE_HW_COMPOSER,
    1.69 +        USAGE_HW_VIDEO_ENCODER  = GRALLOC_USAGE_HW_VIDEO_ENCODER,
    1.70 +        USAGE_HW_MASK           = GRALLOC_USAGE_HW_MASK
    1.71 +    };
    1.72 +
    1.73 +    GraphicBuffer();
    1.74 +
    1.75 +    // creates w * h buffer
    1.76 +    GraphicBuffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage);
    1.77 +
    1.78 +    // create a buffer from an existing handle
    1.79 +    GraphicBuffer(uint32_t w, uint32_t h, PixelFormat format, uint32_t usage,
    1.80 +            uint32_t stride, native_handle_t* handle, bool keepOwnership);
    1.81 +
    1.82 +    // create a buffer from an existing ANativeWindowBuffer
    1.83 +    GraphicBuffer(ANativeWindowBuffer* buffer, bool keepOwnership);
    1.84 +
    1.85 +    // return status
    1.86 +    status_t initCheck() const;
    1.87 +
    1.88 +    uint32_t getWidth() const           { return width; }
    1.89 +    uint32_t getHeight() const          { return height; }
    1.90 +    uint32_t getStride() const          { return stride; }
    1.91 +    uint32_t getUsage() const           { return usage; }
    1.92 +    PixelFormat getPixelFormat() const  { return format; }
    1.93 +    Rect getBounds() const              { return Rect(width, height); }
    1.94 +    
    1.95 +    status_t reallocate(uint32_t w, uint32_t h, PixelFormat f, uint32_t usage);
    1.96 +
    1.97 +    status_t lock(uint32_t usage, void** vaddr);
    1.98 +    status_t lock(uint32_t usage, const Rect& rect, void** vaddr);
    1.99 +    status_t lock(GGLSurface* surface, uint32_t usage);
   1.100 +    status_t unlock();
   1.101 +
   1.102 +    ANativeWindowBuffer* getNativeBuffer() const;
   1.103 +    
   1.104 +    void setIndex(int index);
   1.105 +    int getIndex() const;
   1.106 +
   1.107 +    // for debugging
   1.108 +    static void dumpAllocationsToSystemLog();
   1.109 +
   1.110 +private:
   1.111 +    virtual ~GraphicBuffer();
   1.112 +
   1.113 +    enum {
   1.114 +        ownNone   = 0,
   1.115 +        ownHandle = 1,
   1.116 +        ownData   = 2,
   1.117 +    };
   1.118 +
   1.119 +    inline const GraphicBufferMapper& getBufferMapper() const {
   1.120 +        return mBufferMapper;
   1.121 +    }
   1.122 +    inline GraphicBufferMapper& getBufferMapper() {
   1.123 +        return mBufferMapper;
   1.124 +    }
   1.125 +    uint8_t mOwner;
   1.126 +
   1.127 +private:
   1.128 +    friend class Surface;
   1.129 +    friend class BpSurface;
   1.130 +    friend class BnSurface;
   1.131 +    friend class SurfaceTextureClient;
   1.132 +    friend class LightRefBase<GraphicBuffer>;
   1.133 +    GraphicBuffer(const GraphicBuffer& rhs);
   1.134 +    GraphicBuffer& operator = (const GraphicBuffer& rhs);
   1.135 +    const GraphicBuffer& operator = (const GraphicBuffer& rhs) const;
   1.136 +
   1.137 +    status_t initSize(uint32_t w, uint32_t h, PixelFormat format, 
   1.138 +            uint32_t usage);
   1.139 +
   1.140 +    void free_handle();
   1.141 +
   1.142 +    // Flattenable interface
   1.143 +    size_t getFlattenedSize() const;
   1.144 +    size_t getFdCount() const;
   1.145 +    status_t flatten(void* buffer, size_t size,
   1.146 +            int fds[], size_t count) const;
   1.147 +    status_t unflatten(void const* buffer, size_t size,
   1.148 +            int fds[], size_t count);
   1.149 +
   1.150 +
   1.151 +    GraphicBufferMapper& mBufferMapper;
   1.152 +    ssize_t mInitCheck;
   1.153 +    int mIndex;
   1.154 +
   1.155 +    // If we're wrapping another buffer then this reference will make sure it
   1.156 +    // doesn't get freed.
   1.157 +    sp<ANativeWindowBuffer> mWrappedBuffer;
   1.158 +};
   1.159 +
   1.160 +}; // namespace android
   1.161 +
   1.162 +#endif // ANDROID_GRAPHIC_BUFFER_H

mercurial