#ifndef _NUUOTEXTURE_H_
#define _NUUOTEXTURE_H_
#include <QSize>
typedef enum
{
    RGB = 1,
    YV12,
} RenderType;

class NuuoTexture
{
public:
    NuuoTexture() : m_width(0), m_height(0), m_newTexture(false), m_nbytes(0), m_data(NULL), m_type(YV12)
    {
    };
    ~NuuoTexture()
    {
        if (m_data)
        {
            free(m_data);
        }
    }
    void   loadTexture(const QSize& sz, uchar* data, size_t nbytes, RenderType type)
    {
        if (sz.width() != m_width || sz.height() != m_height)
        {
            m_width = sz.width();
            m_height = sz.height();            
        }
        if (!m_data || m_nbytes != nbytes)
        {
            m_nbytes = nbytes;
            m_data = (uchar*) qRealloc(m_data, m_nbytes);
            if (!m_data)
            {
                qWarning("Fails to realloc memory for Texture\n");
            }
        }
        if (type != m_type)
        {
            type = m_type;
        }
        m_newTexture = true;
        memcpy(m_data, data, m_nbytes);        
    }
    QSize  TextureSize() const
    {
        return QSize(m_width, m_height);
    }
    size_t numBytes() const
    {
        return m_nbytes;
    }
    uchar*  TextureContent()
    {
        m_newTexture = false;
        return m_data;
    }
    bool   isNewTexture()
    {
        return m_newTexture;
    }
    RenderType TextureType()
    {
        return m_type;
    }
private:
    int    m_width, m_height;    
    bool   m_newTexture;
    size_t m_nbytes;
    uchar*  m_data;
    RenderType m_type;
    
};
#endif