KWin
Loading...
Searching...
No Matches
imageitem.cpp
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2022 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "scene/imageitem.h"
8
9#include "opengl/gltexture.h"
10
11namespace KWin
12{
13
15 : Item(scene, parent)
16{
17}
18
19QImage ImageItem::image() const
20{
21 return m_image;
22}
23
24void ImageItem::setImage(const QImage &image)
25{
26 m_image = image;
27}
28
30 : ImageItem(scene, parent)
31{
32}
33
37
39{
40 return m_texture.get();
41}
42
44{
45 if (m_image.isNull()) {
46 m_texture.reset();
47 m_textureKey = 0;
48 } else if (m_textureKey != m_image.cacheKey()) {
49 m_textureKey = m_image.cacheKey();
50
51 if (!m_texture || m_texture->size() != m_image.size()) {
52 m_texture = GLTexture::upload(m_image);
53 if (!m_texture) {
54 return;
55 }
56 m_texture->setFilter(GL_LINEAR);
57 m_texture->setWrapMode(GL_CLAMP_TO_EDGE);
58 } else {
59 m_texture->update(m_image);
60 }
61 }
62}
63
65{
66 const QRectF geometry = boundingRect();
67 if (geometry.isEmpty()) {
68 return WindowQuadList{};
69 }
70
71 WindowQuad quad;
72 quad[0] = WindowVertex(geometry.topLeft(), QPointF(0, 0));
73 quad[1] = WindowVertex(geometry.topRight(), QPointF(1, 0));
74 quad[2] = WindowVertex(geometry.bottomRight(), QPointF(1, 1));
75 quad[3] = WindowVertex(geometry.bottomLeft(), QPointF(0, 1));
76
78 ret.append(quad);
79 return ret;
80}
81
82} // namespace KWin
83
84#include "moc_imageitem.cpp"
static std::unique_ptr< GLTexture > upload(const QImage &image)
void setImage(const QImage &image)
Definition imageitem.cpp:24
QImage image() const
Definition imageitem.cpp:19
ImageItem(Scene *scene, Item *parent=nullptr)
Definition imageitem.cpp:14
ImageItemOpenGL(Scene *scene, Item *parent=nullptr)
Definition imageitem.cpp:29
void preprocess() override
Definition imageitem.cpp:43
GLTexture * texture() const
Definition imageitem.cpp:38
WindowQuadList buildQuads() const override
Definition imageitem.cpp:64
~ImageItemOpenGL() override
Definition imageitem.cpp:34
QRectF boundingRect() const
Definition item.cpp:157
Class representing one area of a window.
Vertex class.