calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / qt5 / QtOpenGLContext.cxx
blob9dd75b69a1c9d424fc29027542ae3a042e5dcbae
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <QtOpenGLContext.hxx>
22 #include <epoxy/gl.h>
24 #include <vcl/sysdata.hxx>
25 #include <opengl/zone.hxx>
26 #include <sal/log.hxx>
28 #include <window.h>
30 #include <QtObject.hxx>
32 #include <QtGui/QOpenGLContext>
33 #include <QtGui/QWindow>
35 bool QtOpenGLContext::g_bAnyCurrent = false;
37 void QtOpenGLContext::swapBuffers()
39 OpenGLZone aZone;
41 if (m_pContext && m_pWindow && m_pWindow->isExposed())
43 m_pContext->swapBuffers(m_pWindow);
46 BuffersSwapped();
49 void QtOpenGLContext::resetCurrent()
51 clearCurrent();
53 OpenGLZone aZone;
55 if (m_pContext)
57 m_pContext->doneCurrent();
58 g_bAnyCurrent = false;
62 bool QtOpenGLContext::isCurrent()
64 OpenGLZone aZone;
65 return g_bAnyCurrent && (QOpenGLContext::currentContext() == m_pContext);
68 bool QtOpenGLContext::isAnyCurrent()
70 OpenGLZone aZone;
71 return g_bAnyCurrent && (QOpenGLContext::currentContext() != nullptr);
74 bool QtOpenGLContext::ImplInit()
76 if (!m_pWindow)
78 SAL_WARN("vcl.opengl.qt", "failed to create window");
79 return false;
82 m_pWindow->setSurfaceType(QSurface::OpenGLSurface);
83 m_pWindow->create();
85 m_pContext = new QOpenGLContext(m_pWindow);
86 if (!m_pContext->create())
88 SAL_WARN("vcl.opengl.qt", "failed to create context");
89 return false;
92 m_pContext->makeCurrent(m_pWindow);
93 g_bAnyCurrent = true;
95 bool bRet = InitGL();
96 InitGLDebugging();
98 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
100 registerAsCurrent();
102 return bRet;
105 void QtOpenGLContext::makeCurrent()
107 if (isCurrent())
108 return;
110 OpenGLZone aZone;
112 clearCurrent();
114 if (m_pContext && m_pWindow)
116 m_pContext->makeCurrent(m_pWindow);
117 g_bAnyCurrent = true;
120 registerAsCurrent();
123 void QtOpenGLContext::destroyCurrentContext()
125 OpenGLZone aZone;
127 if (m_pContext)
129 m_pContext->doneCurrent();
130 g_bAnyCurrent = false;
133 if (glGetError() != GL_NO_ERROR)
135 SAL_WARN("vcl.opengl.qt", "glError: " << glGetError());
139 void QtOpenGLContext::initWindow()
141 if (!m_pChildWindow)
143 SystemWindowData winData = generateWinData(mpWindow, mbRequestLegacyContext);
144 m_pChildWindow = VclPtr<SystemChildWindow>::Create(mpWindow, 0, &winData, false);
147 if (m_pChildWindow)
149 InitChildWindow(m_pChildWindow.get());
152 m_pWindow
153 = static_cast<QtObject*>(m_pChildWindow->ImplGetWindowImpl()->mpSysObj)->windowHandle();