File indexing completed on 2024-11-10 04:57:14
0001 /* 0002 SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "scene/imageitem.h" 0008 0009 #include "opengl/gltexture.h" 0010 0011 namespace KWin 0012 { 0013 0014 ImageItem::ImageItem(Scene *scene, Item *parent) 0015 : Item(scene, parent) 0016 { 0017 } 0018 0019 QImage ImageItem::image() const 0020 { 0021 return m_image; 0022 } 0023 0024 void ImageItem::setImage(const QImage &image) 0025 { 0026 m_image = image; 0027 } 0028 0029 ImageItemOpenGL::ImageItemOpenGL(Scene *scene, Item *parent) 0030 : ImageItem(scene, parent) 0031 { 0032 } 0033 0034 ImageItemOpenGL::~ImageItemOpenGL() 0035 { 0036 } 0037 0038 GLTexture *ImageItemOpenGL::texture() const 0039 { 0040 return m_texture.get(); 0041 } 0042 0043 void ImageItemOpenGL::preprocess() 0044 { 0045 if (m_image.isNull()) { 0046 m_texture.reset(); 0047 m_textureKey = 0; 0048 } else if (m_textureKey != m_image.cacheKey()) { 0049 m_textureKey = m_image.cacheKey(); 0050 0051 if (!m_texture || m_texture->size() != m_image.size()) { 0052 m_texture = GLTexture::upload(m_image); 0053 if (!m_texture) { 0054 return; 0055 } 0056 m_texture->setFilter(GL_LINEAR); 0057 m_texture->setWrapMode(GL_CLAMP_TO_EDGE); 0058 } else { 0059 m_texture->update(m_image); 0060 } 0061 } 0062 } 0063 0064 WindowQuadList ImageItemOpenGL::buildQuads() const 0065 { 0066 const QRectF geometry = boundingRect(); 0067 if (geometry.isEmpty()) { 0068 return WindowQuadList{}; 0069 } 0070 0071 WindowQuad quad; 0072 quad[0] = WindowVertex(geometry.topLeft(), QPointF(0, 0)); 0073 quad[1] = WindowVertex(geometry.topRight(), QPointF(1, 0)); 0074 quad[2] = WindowVertex(geometry.bottomRight(), QPointF(1, 1)); 0075 quad[3] = WindowVertex(geometry.bottomLeft(), QPointF(0, 1)); 0076 0077 WindowQuadList ret; 0078 ret.append(quad); 0079 return ret; 0080 } 0081 0082 } // namespace KWin 0083 0084 #include "moc_imageitem.cpp"