File indexing completed on 2024-12-22 04:12:48
0001 /* 0002 * SPDX-FileCopyrightText: 2006 Boudewijn Rempt <boud@valdyas.org> 0003 * SPDX-FileCopyrightText: 2015 Michael Abrahams <miabraha@gmail.com> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef KIS_OPENGL_CANVAS_RENDERER_H 0009 #define KIS_OPENGL_CANVAS_RENDERER_H 0010 0011 #include <QtGlobal> 0012 0013 #ifndef Q_OS_MACOS 0014 #include <QOpenGLFunctions> 0015 #else 0016 #include <QOpenGLFunctions_3_2_Core> 0017 #endif 0018 #include "opengl/kis_opengl_image_textures.h" 0019 0020 #include "kritaui_export.h" 0021 #include "kis_ui_types.h" 0022 #include "KisWraparoundAxis.h" 0023 0024 class KisCanvas2; 0025 class KisCoordinatesConverter; 0026 class KisDisplayColorConverter; 0027 class KisDisplayFilter; 0028 class QOpenGLShaderProgram; 0029 class QPainterPath; 0030 class KisOptimizedBrushOutline; 0031 0032 #ifndef Q_MOC_RUN 0033 #ifndef Q_OS_MACOS 0034 #define GLFunctions QOpenGLFunctions 0035 #else 0036 #define GLFunctions QOpenGLFunctions_3_2_Core 0037 #endif 0038 0039 #endif 0040 /** 0041 * KisOpenGLCanvasRenderer is the class that shows the actual image using OpenGL 0042 * 0043 */ 0044 class KisOpenGLCanvasRenderer 0045 : private GLFunctions 0046 { 0047 public: 0048 class CanvasBridge; 0049 0050 KisOpenGLCanvasRenderer(CanvasBridge *canvasBridge, KisImageWSP image, KisDisplayColorConverter *colorConverter); 0051 0052 ~KisOpenGLCanvasRenderer(); 0053 0054 Q_DISABLE_COPY(KisOpenGLCanvasRenderer) 0055 0056 public: 0057 void resizeGL(int width, int height); 0058 void initializeGL(); 0059 0060 /** 0061 * Paint only the canvas background and image tiles. 0062 */ 0063 void paintCanvasOnly(const QRect &canvasImageDirtyRect, const QRect &viewportUpdateRect = QRect()); 0064 0065 private: 0066 void updateSize(const QSize &viewportSize); 0067 void renderCanvasGL(const QRect &updateRect); 0068 0069 public: 0070 void paintToolOutline(const KisOptimizedBrushOutline &path, const QRect &viewportUpdateRect, const int thickness = 1); 0071 0072 void setDisplayFilter(QSharedPointer<KisDisplayFilter> displayFilter); 0073 void notifyImageColorSpaceChanged(const KoColorSpace *cs); 0074 0075 void setWrapAroundViewingMode(bool value); 0076 bool wrapAroundViewingMode() const; 0077 0078 void setWrapAroundViewingModeAxis(WrapAroundAxis value); 0079 WrapAroundAxis wrapAroundViewingModeAxis() const; 0080 0081 void channelSelectionChanged(const QBitArray &channelFlags); 0082 void setDisplayColorConverter(KisDisplayColorConverter *colorConverter); 0083 void finishResizingImage(qint32 w, qint32 h); 0084 KisUpdateInfoSP startUpdateCanvasProjection(const QRect & rc); 0085 QRect updateCanvasProjection(KisUpdateInfoSP info); 0086 0087 void setLodResetInProgress(bool value); 0088 0089 private: 0090 void setDisplayFilterImpl(QSharedPointer<KisDisplayFilter> displayFilter, bool initializing); 0091 0092 public: 0093 KisOpenGLImageTexturesSP openGLImageTextures() const; 0094 0095 void updateConfig(); 0096 void updateCursorColor(); 0097 void updatePixelGridMode(); 0098 0099 private: 0100 void initializeShaders(); 0101 void initializeDisplayShader(); 0102 0103 void reportFailedShaderCompilation(const QString &context); 0104 void drawBackground(const QRect &updateRect); 0105 void drawImage(const QRect &updateRect); 0106 void drawImageTiles(int firstCol, int lastCol, int firstRow, int lastRow, qreal scaleX, qreal scaleY, const QPoint &wrapAroundOffset); 0107 void drawCheckers(const QRect &updateRect); 0108 void drawGrid(const QRect &updateRect); 0109 0110 QRectF widgetToSurface(const QRectF &rc); 0111 QRectF surfaceToWidget(const QRectF &rc); 0112 0113 private: 0114 struct Private; 0115 Private * const d; 0116 0117 KisCanvas2 *canvas() const; 0118 QOpenGLContext *context() const; 0119 qreal devicePixelRatioF() const; 0120 KisCoordinatesConverter *coordinatesConverter() const; 0121 QColor borderColor() const; 0122 }; 0123 0124 class KisOpenGLCanvasRenderer::CanvasBridge 0125 { 0126 friend class KisOpenGLCanvasRenderer; 0127 0128 public: 0129 CanvasBridge() = default; 0130 virtual ~CanvasBridge() = default; 0131 0132 Q_DISABLE_COPY(CanvasBridge) 0133 0134 protected: 0135 virtual KisCanvas2 *canvas() const = 0; 0136 virtual QOpenGLContext *openglContext() const = 0; 0137 virtual qreal devicePixelRatioF() const = 0; 0138 virtual KisCoordinatesConverter *coordinatesConverter() const = 0; 0139 virtual QColor borderColor() const = 0; 0140 }; 0141 0142 #endif // KIS_OPENGL_CANVAS_RENDERER_H