File indexing completed on 2024-05-12 05:31:41

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #include "eglimagetexture.h"
0011 #include "egldisplay.h"
0012 #include "opengl/gltexture_p.h"
0013 
0014 #include <QDebug>
0015 #include <epoxy/egl.h>
0016 
0017 namespace KWin
0018 {
0019 
0020 EGLImageTexture::EGLImageTexture(EglDisplay *display, EGLImage image, uint textureId, int internalFormat, const QSize &size, uint32_t target)
0021     : GLTexture(target, textureId, internalFormat, size, 1, true, OutputTransform::FlipY)
0022     , m_image(image)
0023     , m_display(display)
0024 {
0025 }
0026 
0027 EGLImageTexture::~EGLImageTexture()
0028 {
0029     eglDestroyImageKHR(m_display->handle(), m_image);
0030 }
0031 
0032 std::shared_ptr<EGLImageTexture> EGLImageTexture::create(EglDisplay *display, EGLImageKHR image, int internalFormat, const QSize &size, bool externalOnly)
0033 {
0034     if (image == EGL_NO_IMAGE) {
0035         return nullptr;
0036     }
0037     GLuint texture = 0;
0038     glGenTextures(1, &texture);
0039     if (!texture) {
0040         return nullptr;
0041     }
0042     const uint32_t target = externalOnly ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D;
0043     glBindTexture(target, texture);
0044     glEGLImageTargetTexture2DOES(target, image);
0045     glBindTexture(target, 0);
0046     return std::make_shared<EGLImageTexture>(display, image, texture, internalFormat, size, target);
0047 }
0048 
0049 } // namespace KWin