1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtQuick module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #include "qsgopenvgtexture.h"
41 #include "qsgopenvghelpers.h"
42 
43 QT_BEGIN_NAMESPACE
44 
QSGOpenVGTexture(const QImage & image,uint flags)45 QSGOpenVGTexture::QSGOpenVGTexture(const QImage &image, uint flags)
46 {
47     Q_UNUSED(flags)
48 
49     VGImageFormat format = QSGOpenVGHelpers::qImageFormatToVGImageFormat(image.format());
50     m_image = vgCreateImage(format, image.width(), image.height(), VG_IMAGE_QUALITY_BETTER);
51 
52     // Do Texture Upload
53     vgImageSubData(m_image, image.constBits(), image.bytesPerLine(), format, 0, 0, image.width(), image.height());
54 }
55 
~QSGOpenVGTexture()56 QSGOpenVGTexture::~QSGOpenVGTexture()
57 {
58     vgDestroyImage(m_image);
59 }
60 
textureId() const61 int QSGOpenVGTexture::textureId() const
62 {
63     return static_cast<int>(m_image);
64 }
65 
textureSize() const66 QSize QSGOpenVGTexture::textureSize() const
67 {
68     VGint imageWidth = vgGetParameteri(m_image, VG_IMAGE_WIDTH);
69     VGint imageHeight = vgGetParameteri(m_image, VG_IMAGE_HEIGHT);
70     return QSize(imageWidth, imageHeight);
71 }
72 
hasAlphaChannel() const73 bool QSGOpenVGTexture::hasAlphaChannel() const
74 {
75     VGImageFormat format = static_cast<VGImageFormat>(vgGetParameteri(m_image, VG_IMAGE_FORMAT));
76 
77     switch (format) {
78     case VG_sRGBA_8888:
79     case VG_sRGBA_8888_PRE:
80     case VG_sRGBA_5551:
81     case VG_sRGBA_4444:
82     case VG_lRGBA_8888:
83     case VG_lRGBA_8888_PRE:
84     case VG_A_8:
85     case VG_A_1:
86     case VG_A_4:
87     case VG_sARGB_8888:
88     case VG_sARGB_8888_PRE:
89     case VG_sARGB_1555:
90     case VG_sARGB_4444:
91     case VG_lARGB_8888:
92     case VG_lARGB_8888_PRE:
93     case VG_sBGRA_8888:
94     case VG_sBGRA_8888_PRE:
95     case VG_sBGRA_5551:
96     case VG_sBGRA_4444:
97     case VG_lBGRA_8888:
98     case VG_lBGRA_8888_PRE:
99     case VG_sABGR_8888:
100     case VG_sABGR_8888_PRE:
101     case VG_sABGR_1555:
102     case VG_sABGR_4444:
103     case VG_lABGR_8888:
104     case VG_lABGR_8888_PRE:
105         return true;
106         break;
107     default:
108         break;
109     }
110     return false;
111 }
112 
hasMipmaps() const113 bool QSGOpenVGTexture::hasMipmaps() const
114 {
115     return false;
116 }
117 
bind()118 void QSGOpenVGTexture::bind()
119 {
120     // No need to bind
121 }
122 
123 QT_END_NAMESPACE
124