8#define GL_GLEXT_PROTOTYPES
29#include "config-qt-patches-present.h"
51 return m_canvas->devicePixelRatioF();
72#if KRITA_QT_HAS_UPDATE_COMPRESSION_PATCH
73 bool shouldSkipRenderingPass =
false;
88 : QOpenGLWidget(parent)
92 setProperty(
"krita_skip_srgb_surface_manager_assignment",
true);
100 SIGNAL(sigShowFloatingMessage(QString,
int,
bool)),
103 setAcceptDrops(
true);
104 setAutoFillBackground(
false);
106 setFocusPolicy(Qt::StrongFocus);
107 setAttribute(Qt::WA_NoSystemBackground,
true);
109 setAttribute(Qt::WA_AcceptTouchEvents,
false);
111 setAttribute(Qt::WA_AcceptTouchEvents,
true);
113 setAttribute(Qt::WA_InputMethodEnabled,
true);
114 setAttribute(Qt::WA_DontCreateNativeAncestors,
true);
118 if (qEnvironmentVariableIsSet(
"KRITA_USE_NATIVE_CANVAS_SURFACE")) {
119 useNativeSurfaceForCanvas = qEnvironmentVariableIntValue(
"KRITA_USE_NATIVE_CANVAS_SURFACE");
120 qDebug() <<
"FPS-DEBUG: Krita canvas mode is overridden:" << (useNativeSurfaceForCanvas ?
"native surface" :
"legacy mode") << useNativeSurfaceForCanvas << qEnvironmentVariableIsSet(
"KRITA_USE_NATIVE_CANVAS_SURFACE");
123 if (useNativeSurfaceForCanvas) {
124 setAttribute(Qt::WA_NativeWindow,
true);
127 setUpdateBehavior(PartialUpdate);
132 setTextureFormat(GL_RGBA16F);
135 if (QSurfaceFormat::defaultFormat().redBufferSize() < 10) {
137 "WARNING: KisOpenGLCanvas2 was created with a 10-bit surface, "
138 "while the global surface format is still set to 8-bit. Expect "
139 "color banding to appear";
141 setTextureFormat(GL_RGB10_A2);
153 setTextureFormat(GL_RGB8);
166 cfg.
writeEntry(
"canvasState",
"OPENGL_SUCCESS");
191 KisOpenGLContextSwitchLockSkipOnQt5 contextLock(
this);
197 KisOpenGLContextSwitchLockSkipOnQt5 contextLock(
this);
237#if KRITA_QT_HAS_UPDATE_COMPRESSION_PATCH
238 if (
d->shouldSkipRenderingPass) {
247 cfg.
writeEntry(
"canvasState",
"OPENGL_PAINT_STARTED");
256 if (!updateRect.isEmpty()) {
257 gc.setClipRect(updateRect);
262 if (!updateRect.isEmpty()) {
263 decorationsBoundingRect &= updateRect;
280 cfg.
writeEntry(
"canvasState",
"OPENGL_SUCCESS");
289 if (
qFuzzyCompare(devicePixelRatioF(), qRound(devicePixelRatioF()))) {
302#if KRITA_QT_HAS_UPDATE_COMPRESSION_PATCH
310 d->shouldSkipRenderingPass =
true;
311 QOpenGLWidget::paintEvent(e);
312 d->shouldSkipRenderingPass =
false;
313 QTimer::singleShot(0,
this,
315 if (updateRect.isEmpty()) {
318 this->update(updateRect);
324 QOpenGLWidget::paintEvent(e);
327 d->updateRect = boost::none;
403 QOpenGLWidget::hideEvent(e);
409 QOpenGLWidget::showEvent(e);
415 KisOpenGLContextSwitchLockSkipOnQt5 contextLock(
this);
427 KisOpenGLContextSwitchLockSkipOnQt5 contextLock(
this);
444 KisOpenGLContextSwitchLockSkipOnQt5 contextLock(
this);
451 update(imageUpdateRect);
456 update(decoUpdateRect);
460 return focusNextPrevChild(next);
471 textureFormat() == GL_RGB10_A2 &&
472 format().redBufferSize() == 10 &&
473 format().greenBufferSize() == 10 &&
474 format().blueBufferSize() == 10 ?
483 str <<
"Texture Format: " << Qt::hex << Qt::showbase << textureFormat() << Qt::reset;
485 switch (textureFormat()) {
487 str <<
" (" <<
"GL_RGB10_A2" <<
")";
492 str <<
" (" <<
"GL_RGB10" <<
")";
498 str <<
" (" <<
"GL_RGB12" <<
")";
504 str <<
" (" <<
"GL_RGBA16" <<
")";
510 str <<
" (" <<
"GL_RGB16" <<
")";
514 str <<
" (" <<
"GL_RGBA16F" <<
")";
517 str <<
" (" <<
"GL_RGB8" <<
")";
520 str <<
" (" <<
"GL_RGBA8" <<
")";
523 str <<
" (" <<
"<unknown>" <<
")";
528 str <<
"FBO Buffer Size: "
529 <<
"R: " << format().redBufferSize() <<
" "
530 <<
"G: " << format().greenBufferSize() <<
" "
531 <<
"B: " << format().blueBufferSize() <<
" "
532 <<
"A: " << format().alphaBufferSize() << Qt::endl;
534 QWindow *win = windowHandle();
536 str <<
"Window Buffer Size: "
537 <<
"R: " << win->format().redBufferSize() <<
" "
538 <<
"G: " << win->format().greenBufferSize() <<
" "
539 <<
"B: " << win->format().blueBufferSize() <<
" "
540 <<
"A: " << win->format().alphaBufferSize() << Qt::endl;
544 str <<
"Global Buffer Size: "
545 <<
"R: " << QSurfaceFormat::defaultFormat().redBufferSize() <<
" "
546 <<
"G: " << QSurfaceFormat::defaultFormat().greenBufferSize() <<
" "
547 <<
"B: " << QSurfaceFormat::defaultFormat().blueBufferSize() <<
" "
548 <<
"A: " << QSurfaceFormat::defaultFormat().alphaBufferSize() << Qt::endl;
float value(const T *src, size_t ch)
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisViewManager * viewManager() const
QPointer< KisView > imageView() const
static KisConfigNotifier * instance()
void setCanvasState(const QString &state) const
void writeEntry(const QString &name, const T &value)
bool enableCanvasSurfaceColorSpaceManagement(bool defaultValue=false) const
QRectF imageRectInWidgetPixels() const
KisDisplayConfig This class keeps track of the color management configuration for image to display....
QColor borderColor() const override
CanvasBridge(KisOpenGLCanvas2 *canvas)
KisCanvas2 * canvas() const override
qreal devicePixelRatioF() const override
GLenum internalTextureFormat() const override
QOpenGLContext * openglContext() const override
KisCoordinatesConverter * coordinatesConverter() const override
~CanvasBridge() override=default
KisOpenGLCanvas2 * m_canvas
void showEvent(QShowEvent *event) override
void initializeGL() override
QString currentBitDepthUserReport() const override
BitDepthMode currentBitDepthMode() const override
void setDisplayConfig(const KisDisplayConfig &config) override
void setDisplayFilter(QSharedPointer< KisDisplayFilter > displayFilter) override
set the specified display filter on the canvas
void updateCanvasDecorations(const QRect &decoUpdateRect) override
void slotShowFloatingMessage(const QString &message, int timeout, bool priority)
void notifyImageColorSpaceChanged(const KoColorSpace *cs) override
set/update the color space of the attached image
bool wrapAroundViewingMode() const override
void inputMethodEvent(QInputMethodEvent *event) override
QVariant inputMethodQuery(Qt::InputMethodQuery query) const override
void slotPixelGridModeChanged()
KisUpdateInfoSP startUpdateCanvasProjection(const QRect &rc) override
void setLodResetInProgress(bool value) override
void updateCanvasImage(const QRect &imageUpdateRect) override
bool isBusy() const override
KisOpenGLImageTexturesSP openGLImageTextures() const
void channelSelectionChanged(const QBitArray &channelFlags) override
void slotUpdateCursorColor()
void hideEvent(QHideEvent *event) override
KisOpenGLCanvas2(KisCanvas2 *canvas, KisCoordinatesConverter *coordinatesConverter, QWidget *parent, KisImageWSP image, const KisDisplayConfig &displayConfig, QSharedPointer< KisDisplayFilter > displayFilter, BitDepthMode bitDepthRequest)
void paintToolOutline(const KisOptimizedBrushOutline &path, int thickness=1)
QRect updateCanvasProjection(KisUpdateInfoSP info) override
void setWrapAroundViewingMode(bool value) override
void focusOutEvent(QFocusEvent *event) override
void resizeGL(int width, int height) override
void focusInEvent(QFocusEvent *event) override
WrapAroundAxis wrapAroundViewingModeAxis() const override
void setWrapAroundViewingModeAxis(WrapAroundAxis value) override
void paintEvent(QPaintEvent *e) override
bool callFocusNextPrevChild(bool next) override
To be implemented by the derived canvas.
void finishResizingImage(qint32 w, qint32 h) override
~KisOpenGLCanvas2() override
QRect updateCanvasProjection(KisUpdateInfoSP info)
void setDisplayFilter(QSharedPointer< KisDisplayFilter > displayFilter)
void resizeGL(int width, int height)
KisOpenGLImageTexturesSP openGLImageTextures() const
void channelSelectionChanged(const QBitArray &channelFlags)
KisUpdateInfoSP startUpdateCanvasProjection(const QRect &rc)
void paintCanvasOnly(const QRect &canvasImageDirtyRect, const QRect &viewportUpdateRect=QRect())
void setLodResetInProgress(bool value)
void setDisplayConfig(const KisDisplayConfig &config)
WrapAroundAxis wrapAroundViewingModeAxis() const
void setWrapAroundViewingModeAxis(WrapAroundAxis value)
bool wrapAroundViewingMode() const
void updatePixelGridMode()
void finishResizingImage(qint32 w, qint32 h)
void paintToolOutline(const KisOptimizedBrushOutline &path, const QRect &viewportUpdateRect, const int thickness=1)
void setWrapAroundViewingMode(bool value)
void notifyImageColorSpaceChanged(const KoColorSpace *cs)
static KisOpenGLModeProber * instance()
static void init(QOpenGLContext *ctx)
static bool hasOpenGLES()
void notifyPaintRequested()
static KisOpenglCanvasDebugger * instance()
void notifySyncStatus(bool value)
void paint(QPaintDevice *paintDevice, const QRect &widgetRect)
KisCanvasResourceProvider * canvasResourceProvider()
static bool qFuzzyCompare(half p1, half p2)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
static bool OPENGL_SUCCESS
boost::optional< QRect > updateRect
KisRepaintDebugger repaintDbg
QScopedPointer< KisOpenGLSync > glSyncObject
QRect canvasImageDirtyRect
KisOpenGLCanvasRenderer * renderer