Warning, /graphics/krita/3rdparty/ext_qt/0132-Resize-D3D-surface-to-reduce-flickering-on-resize.patch is written in an unsupported language. File is not indexed.

0001 From 4386bbe4283cd973d23ea0a906eb171ab7ee003f Mon Sep 17 00:00:00 2001
0002 From: Alvin Wong <alvinhochun@gmail.com>
0003 Date: Thu, 17 Mar 2022 23:56:51 +0800
0004 Subject: [PATCH] Resize D3D surface to reduce flickering on resize
0005 
0006 ---
0007  .../windows/qwindowsbackingstore.cpp          | 19 +++++++++++++++++
0008  .../platforms/windows/qwindowsbackingstore.h  |  6 ++++++
0009  .../platforms/windows/qwindowseglcontext.cpp  | 21 +++++++++++++++++++
0010  .../platforms/windows/qwindowseglcontext.h    |  2 ++
0011  .../platforms/windows/qwindowsopenglcontext.h |  2 ++
0012  5 files changed, 50 insertions(+)
0013 
0014 diff --git a/src/plugins/platforms/windows/qwindowsbackingstore.cpp b/src/plugins/platforms/windows/qwindowsbackingstore.cpp
0015 index 68807fabdd..9b8faffffd 100644
0016 --- a/src/plugins/platforms/windows/qwindowsbackingstore.cpp
0017 +++ b/src/plugins/platforms/windows/qwindowsbackingstore.cpp
0018 @@ -40,8 +40,10 @@
0019  #include "qwindowsbackingstore.h"
0020  #include "qwindowswindow.h"
0021  #include "qwindowscontext.h"
0022 +#include "qwindowsopenglcontext.h"
0023  
0024  #include <QtGui/qwindow.h>
0025 +#include <QtGui/private/qwindow_p.h>
0026  #include <QtGui/qpainter.h>
0027  #include <QtFontDatabaseSupport/private/qwindowsnativeimage_p.h>
0028  #include <private/qhighdpiscaling_p.h>
0029 @@ -220,4 +222,21 @@ QImage QWindowsBackingStore::toImage() const
0030      return m_image.data()->image();
0031  }
0032  
0033 +#ifndef QT_NO_OPENGL
0034 +void QWindowsBackingStore::composeAndFlush(QWindow *window, const QRegion &region, const QPoint &offset,
0035 +                                           QPlatformTextureList *textures,
0036 +                                           bool translucentBackground)
0037 +{
0038 +    QOpenGLContext *context = qt_window_private(window)->shareContext();
0039 +    if (!context) {
0040 +        qCWarning(lcQpaBackingStore) <<__FUNCTION__ << "missing OpenGL context.";
0041 +    } else {
0042 +        QPlatformOpenGLContext *pctx = context->handle();
0043 +        QWindowsOpenGLContext *ctx = static_cast<QWindowsOpenGLContext *>(pctx);
0044 +        ctx->beforeCompose(window);
0045 +    }
0046 +    QPlatformBackingStore::composeAndFlush(window, region, offset, textures, translucentBackground);
0047 +}
0048 +#endif // QT_NO_OPENGL
0049 +
0050  QT_END_NAMESPACE
0051 diff --git a/src/plugins/platforms/windows/qwindowsbackingstore.h b/src/plugins/platforms/windows/qwindowsbackingstore.h
0052 index 088ab3b257..c55eca741a 100644
0053 --- a/src/plugins/platforms/windows/qwindowsbackingstore.h
0054 +++ b/src/plugins/platforms/windows/qwindowsbackingstore.h
0055 @@ -63,6 +63,12 @@ public:
0056      bool scroll(const QRegion &area, int dx, int dy) override;
0057      void beginPaint(const QRegion &) override;
0058  
0059 +#ifndef QT_NO_OPENGL
0060 +    void composeAndFlush(QWindow *window, const QRegion &region, const QPoint &offset,
0061 +                         QPlatformTextureList *textures,
0062 +                         bool translucentBackground) override;
0063 +#endif
0064 +
0065      HDC getDC() const;
0066  
0067      QImage toImage() const override;
0068 diff --git a/src/plugins/platforms/windows/qwindowseglcontext.cpp b/src/plugins/platforms/windows/qwindowseglcontext.cpp
0069 index 4d2ce9fc05..f847521fb7 100644
0070 --- a/src/plugins/platforms/windows/qwindowseglcontext.cpp
0071 +++ b/src/plugins/platforms/windows/qwindowseglcontext.cpp
0072 @@ -43,6 +43,7 @@
0073  
0074  #include <QtCore/qdebug.h>
0075  #include <QtGui/qopenglcontext.h>
0076 +#include <QtGui/private/qwindow_p.h>
0077  
0078  #if defined(QT_OPENGL_ES_2_ANGLE) || defined(QT_OPENGL_DYNAMIC)
0079  #  include <EGL/eglext.h>
0080 @@ -152,6 +153,7 @@ bool QWindowsLibEGL::init()
0081      eglSwapBuffers = RESOLVE((EGLBoolean (EGLAPIENTRY *)(EGLDisplay , EGLSurface)), eglSwapBuffers);
0082      eglGetProcAddress = RESOLVE((QFunctionPointer (EGLAPIENTRY * )(const char *)), eglGetProcAddress);
0083      eglQueryString = RESOLVE((const char* (EGLAPIENTRY *)(EGLDisplay, EGLint)), eglQueryString);
0084 +    eglWaitNative = RESOLVE((EGLBoolean (EGLAPIENTRY *)(EGLint)), eglWaitNative);
0085  
0086      if (!eglGetError || !eglGetDisplay || !eglInitialize || !eglGetProcAddress || !eglQueryString)
0087          return false;
0088 @@ -795,6 +797,25 @@ QFunctionPointer QWindowsEGLContext::getProcAddress(const char *procName)
0089      return procAddress;
0090  }
0091  
0092 +void QWindowsEGLContext::beforeCompose(QWindow *window)
0093 +{
0094 +    // Resize buffer before composing to prevent window flicker during resize.
0095 +    QOpenGLContext *context = qt_window_private(window)->shareContext();
0096 +    if (!context) {
0097 +        qCWarning(lcQpaGl, "QWindowsEGLContext::beforeCompose: missing OpenGL context");
0098 +        return;
0099 +    }
0100 +    if (!context->makeCurrent(window)) {
0101 +        qCWarning(lcQpaGl, "QWindowsEGLContext::beforeCompose: makeCurrent failed");
0102 +        return;
0103 +    }
0104 +    // The D3D backend checks for buffer resizes inside eglWaitNative.
0105 +    EGLBoolean result = QWindowsEGLStaticContext::libEGL.eglWaitNative(EGL_CORE_NATIVE_ENGINE);
0106 +    if (result == EGL_FALSE) {
0107 +        qCWarning(lcQpaGl, "QWindowsEGLContext::beforeCompose: eglWaitNative failed");
0108 +    }
0109 +}
0110 +
0111  static QVector<EGLint> createConfigAttributesFromFormat(const QSurfaceFormat &format)
0112  {
0113      int redSize     = format.redBufferSize();
0114 diff --git a/src/plugins/platforms/windows/qwindowseglcontext.h b/src/plugins/platforms/windows/qwindowseglcontext.h
0115 index 1cf1236b81..ffe7b8736d 100644
0116 --- a/src/plugins/platforms/windows/qwindowseglcontext.h
0117 +++ b/src/plugins/platforms/windows/qwindowseglcontext.h
0118 @@ -78,6 +78,7 @@ struct QWindowsLibEGL
0119      EGLDisplay (EGLAPIENTRY * eglGetCurrentDisplay)(void);
0120      EGLBoolean (EGLAPIENTRY * eglSwapBuffers)(EGLDisplay dpy, EGLSurface surface);
0121      QFunctionPointer (EGLAPIENTRY *eglGetProcAddress)(const char *procname);
0122 +    EGLBoolean (EGLAPIENTRY * eglWaitNative)(EGLint engine);
0123  
0124      EGLDisplay (EGLAPIENTRY * eglGetPlatformDisplayEXT)(EGLenum platform, void *native_display, const EGLint *attrib_list);
0125      const char* (EGLAPIENTRY * eglQueryString)(EGLDisplay dpy, EGLint name);
0126 @@ -156,6 +157,7 @@ public:
0127      void doneCurrent() override;
0128      void swapBuffers(QPlatformSurface *surface) override;
0129      QFunctionPointer getProcAddress(const char *procName) override;
0130 +    void beforeCompose(QWindow *window) override;
0131  
0132      QSurfaceFormat format() const override { return m_format; }
0133      bool isSharing() const override { return m_shareContext != EGL_NO_CONTEXT; }
0134 diff --git a/src/plugins/platforms/windows/qwindowsopenglcontext.h b/src/plugins/platforms/windows/qwindowsopenglcontext.h
0135 index 61c0e28767..2398f6bec1 100644
0136 --- a/src/plugins/platforms/windows/qwindowsopenglcontext.h
0137 +++ b/src/plugins/platforms/windows/qwindowsopenglcontext.h
0138 @@ -80,6 +80,8 @@ public:
0139      // Returns the native context handle (e.g. HGLRC for WGL, EGLContext for EGL).
0140      virtual void *nativeContext() const = 0;
0141  
0142 +    virtual void beforeCompose(QWindow * /*window*/) { }
0143 +
0144      // These should be implemented only for some winsys interfaces, for example EGL.
0145      // For others, like WGL, they are not relevant.
0146      virtual void *nativeDisplay() const { return 0; }
0147 -- 
0148 2.24.1.windows.2
0149