Changeset View
Changeset View
Standalone View
Standalone View
platformsupport/scenes/opengl/abstract_egl_backend.cpp
Show All 20 Lines | |||||
21 | #include "egl_dmabuf.h" | 21 | #include "egl_dmabuf.h" | ||
22 | #include "texture.h" | 22 | #include "texture.h" | ||
23 | #include "composite.h" | 23 | #include "composite.h" | ||
24 | #include "egl_context_attribute_builder.h" | 24 | #include "egl_context_attribute_builder.h" | ||
25 | #include "options.h" | 25 | #include "options.h" | ||
26 | #include "platform.h" | 26 | #include "platform.h" | ||
27 | #include "scene.h" | 27 | #include "scene.h" | ||
28 | #include "wayland_server.h" | 28 | #include "wayland_server.h" | ||
29 | #include <KWayland/Server/buffer_interface.h> | 29 | #include <KWaylandServer/buffer_interface.h> | ||
30 | #include <KWayland/Server/display.h> | 30 | #include <KWaylandServer/display.h> | ||
31 | #include <KWayland/Server/surface_interface.h> | 31 | #include <KWaylandServer/surface_interface.h> | ||
32 | // kwin libs | 32 | // kwin libs | ||
33 | #include <logging.h> | 33 | #include <logging.h> | ||
34 | #include <kwinglplatform.h> | 34 | #include <kwinglplatform.h> | ||
35 | #include <kwinglutils.h> | 35 | #include <kwinglutils.h> | ||
36 | // Qt | 36 | // Qt | ||
37 | #include <QOpenGLContext> | 37 | #include <QOpenGLContext> | ||
38 | #include <QOpenGLFramebufferObject> | 38 | #include <QOpenGLFramebufferObject> | ||
39 | 39 | | |||
▲ Show 20 Lines • Show All 352 Lines • ▼ Show 20 Line(s) | 390 | if (EglDmabufBuffer *dmabuf = static_cast<EglDmabufBuffer *>(buffer->linuxDmabufBuffer())) { | |||
392 | glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES) dmabuf->images()[0]); //TODO | 392 | glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES) dmabuf->images()[0]); //TODO | ||
393 | q->unbind(); | 393 | q->unbind(); | ||
394 | if (m_image != EGL_NO_IMAGE_KHR) { | 394 | if (m_image != EGL_NO_IMAGE_KHR) { | ||
395 | eglDestroyImageKHR(m_backend->eglDisplay(), m_image); | 395 | eglDestroyImageKHR(m_backend->eglDisplay(), m_image); | ||
396 | } | 396 | } | ||
397 | m_image = EGL_NO_IMAGE_KHR; // The wl_buffer has ownership of the image | 397 | m_image = EGL_NO_IMAGE_KHR; // The wl_buffer has ownership of the image | ||
398 | // The origin in a dmabuf-buffer is at the upper-left corner, so the meaning | 398 | // The origin in a dmabuf-buffer is at the upper-left corner, so the meaning | ||
399 | // of Y-inverted is the inverse of OpenGL. | 399 | // of Y-inverted is the inverse of OpenGL. | ||
400 | const bool yInverted = !(dmabuf->flags() & KWayland::Server::LinuxDmabufUnstableV1Interface::YInverted); | 400 | const bool yInverted = !(dmabuf->flags() & KWaylandServer::LinuxDmabufUnstableV1Interface::YInverted); | ||
401 | if (m_size != dmabuf->size() || yInverted != q->isYInverted()) { | 401 | if (m_size != dmabuf->size() || yInverted != q->isYInverted()) { | ||
402 | m_size = dmabuf->size(); | 402 | m_size = dmabuf->size(); | ||
403 | q->setYInverted(yInverted); | 403 | q->setYInverted(yInverted); | ||
404 | } | 404 | } | ||
405 | if (s) { | 405 | if (s) { | ||
406 | s->resetTrackedDamage(); | 406 | s->resetTrackedDamage(); | ||
407 | } | 407 | } | ||
408 | return; | 408 | return; | ||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Line(s) | 510 | for (const QRect &rect : damage) { | |||
511 | auto scaledRect = QRect(rect.x() * scale, rect.y() * scale, rect.width() * scale, rect.height() * scale); | 511 | auto scaledRect = QRect(rect.x() * scale, rect.y() * scale, rect.width() * scale, rect.height() * scale); | ||
512 | glTexSubImage2D(m_target, 0, scaledRect.x(), scaledRect.y(), scaledRect.width(), scaledRect.height(), | 512 | glTexSubImage2D(m_target, 0, scaledRect.x(), scaledRect.y(), scaledRect.width(), scaledRect.height(), | ||
513 | GL_BGRA, GL_UNSIGNED_BYTE, im.copy(scaledRect).bits()); | 513 | GL_BGRA, GL_UNSIGNED_BYTE, im.copy(scaledRect).bits()); | ||
514 | } | 514 | } | ||
515 | } | 515 | } | ||
516 | q->unbind(); | 516 | q->unbind(); | ||
517 | } | 517 | } | ||
518 | 518 | | |||
519 | bool AbstractEglTexture::loadShmTexture(const QPointer< KWayland::Server::BufferInterface > &buffer) | 519 | bool AbstractEglTexture::loadShmTexture(const QPointer< KWaylandServer::BufferInterface > &buffer) | ||
520 | { | 520 | { | ||
521 | return createTextureImage(buffer->data()); | 521 | return createTextureImage(buffer->data()); | ||
522 | } | 522 | } | ||
523 | 523 | | |||
524 | bool AbstractEglTexture::loadEglTexture(const QPointer< KWayland::Server::BufferInterface > &buffer) | 524 | bool AbstractEglTexture::loadEglTexture(const QPointer< KWaylandServer::BufferInterface > &buffer) | ||
525 | { | 525 | { | ||
526 | if (!eglQueryWaylandBufferWL) { | 526 | if (!eglQueryWaylandBufferWL) { | ||
527 | return false; | 527 | return false; | ||
528 | } | 528 | } | ||
529 | if (!buffer->resource()) { | 529 | if (!buffer->resource()) { | ||
530 | return false; | 530 | return false; | ||
531 | } | 531 | } | ||
532 | 532 | | |||
533 | glGenTextures(1, &m_texture); | 533 | glGenTextures(1, &m_texture); | ||
534 | q->setWrapMode(GL_CLAMP_TO_EDGE); | 534 | q->setWrapMode(GL_CLAMP_TO_EDGE); | ||
535 | q->setFilter(GL_LINEAR); | 535 | q->setFilter(GL_LINEAR); | ||
536 | q->bind(); | 536 | q->bind(); | ||
537 | m_image = attach(buffer); | 537 | m_image = attach(buffer); | ||
538 | q->unbind(); | 538 | q->unbind(); | ||
539 | 539 | | |||
540 | if (EGL_NO_IMAGE_KHR == m_image) { | 540 | if (EGL_NO_IMAGE_KHR == m_image) { | ||
541 | qCDebug(KWIN_OPENGL) << "failed to create egl image"; | 541 | qCDebug(KWIN_OPENGL) << "failed to create egl image"; | ||
542 | q->discard(); | 542 | q->discard(); | ||
543 | return false; | 543 | return false; | ||
544 | } | 544 | } | ||
545 | 545 | | |||
546 | return true; | 546 | return true; | ||
547 | } | 547 | } | ||
548 | 548 | | |||
549 | bool AbstractEglTexture::loadDmabufTexture(const QPointer< KWayland::Server::BufferInterface > &buffer) | 549 | bool AbstractEglTexture::loadDmabufTexture(const QPointer< KWaylandServer::BufferInterface > &buffer) | ||
550 | { | 550 | { | ||
551 | auto *dmabuf = static_cast<EglDmabufBuffer *>(buffer->linuxDmabufBuffer()); | 551 | auto *dmabuf = static_cast<EglDmabufBuffer *>(buffer->linuxDmabufBuffer()); | ||
552 | if (!dmabuf || dmabuf->images()[0] == EGL_NO_IMAGE_KHR) { | 552 | if (!dmabuf || dmabuf->images()[0] == EGL_NO_IMAGE_KHR) { | ||
553 | qCritical(KWIN_OPENGL) << "Invalid dmabuf-based wl_buffer"; | 553 | qCritical(KWIN_OPENGL) << "Invalid dmabuf-based wl_buffer"; | ||
554 | q->discard(); | 554 | q->discard(); | ||
555 | return false; | 555 | return false; | ||
556 | } | 556 | } | ||
557 | 557 | | |||
558 | Q_ASSERT(m_image == EGL_NO_IMAGE_KHR); | 558 | Q_ASSERT(m_image == EGL_NO_IMAGE_KHR); | ||
559 | 559 | | |||
560 | glGenTextures(1, &m_texture); | 560 | glGenTextures(1, &m_texture); | ||
561 | q->setWrapMode(GL_CLAMP_TO_EDGE); | 561 | q->setWrapMode(GL_CLAMP_TO_EDGE); | ||
562 | q->setFilter(GL_NEAREST); | 562 | q->setFilter(GL_NEAREST); | ||
563 | q->bind(); | 563 | q->bind(); | ||
564 | glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES) dmabuf->images()[0]); | 564 | glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, (GLeglImageOES) dmabuf->images()[0]); | ||
565 | q->unbind(); | 565 | q->unbind(); | ||
566 | 566 | | |||
567 | m_size = dmabuf->size(); | 567 | m_size = dmabuf->size(); | ||
568 | q->setYInverted(!(dmabuf->flags() & KWayland::Server::LinuxDmabufUnstableV1Interface::YInverted)); | 568 | q->setYInverted(!(dmabuf->flags() & KWaylandServer::LinuxDmabufUnstableV1Interface::YInverted)); | ||
569 | 569 | | |||
570 | return true; | 570 | return true; | ||
571 | } | 571 | } | ||
572 | 572 | | |||
573 | bool AbstractEglTexture::loadInternalImageObject(WindowPixmap *pixmap) | 573 | bool AbstractEglTexture::loadInternalImageObject(WindowPixmap *pixmap) | ||
574 | { | 574 | { | ||
575 | return createTextureImage(pixmap->internalImage()); | 575 | return createTextureImage(pixmap->internalImage()); | ||
576 | } | 576 | } | ||
577 | 577 | | |||
578 | EGLImageKHR AbstractEglTexture::attach(const QPointer< KWayland::Server::BufferInterface > &buffer) | 578 | EGLImageKHR AbstractEglTexture::attach(const QPointer< KWaylandServer::BufferInterface > &buffer) | ||
579 | { | 579 | { | ||
580 | EGLint format, yInverted; | 580 | EGLint format, yInverted; | ||
581 | eglQueryWaylandBufferWL(m_backend->eglDisplay(), buffer->resource(), EGL_TEXTURE_FORMAT, &format); | 581 | eglQueryWaylandBufferWL(m_backend->eglDisplay(), buffer->resource(), EGL_TEXTURE_FORMAT, &format); | ||
582 | if (format != EGL_TEXTURE_RGB && format != EGL_TEXTURE_RGBA) { | 582 | if (format != EGL_TEXTURE_RGB && format != EGL_TEXTURE_RGBA) { | ||
583 | qCDebug(KWIN_OPENGL) << "Unsupported texture format: " << format; | 583 | qCDebug(KWIN_OPENGL) << "Unsupported texture format: " << format; | ||
584 | return EGL_NO_IMAGE_KHR; | 584 | return EGL_NO_IMAGE_KHR; | ||
585 | } | 585 | } | ||
586 | if (!eglQueryWaylandBufferWL(m_backend->eglDisplay(), buffer->resource(), EGL_WAYLAND_Y_INVERTED_WL, &yInverted)) { | 586 | if (!eglQueryWaylandBufferWL(m_backend->eglDisplay(), buffer->resource(), EGL_WAYLAND_Y_INVERTED_WL, &yInverted)) { | ||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |