summaryrefslogtreecommitdiffstats
path: root/vcl/inc/opengl
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /vcl/inc/opengl
parentInitial commit. (diff)
downloadlibreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz
libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--vcl/inc/opengl/BufferObject.hxx84
-rw-r--r--vcl/inc/opengl/DeviceInfo.hxx23
-rw-r--r--vcl/inc/opengl/FixedTextureAtlas.hxx47
-rw-r--r--vcl/inc/opengl/LineRenderUtils.hxx55
-rw-r--r--vcl/inc/opengl/PackedTextureAtlas.hxx57
-rw-r--r--vcl/inc/opengl/RenderList.hxx173
-rw-r--r--vcl/inc/opengl/RenderState.hxx188
-rw-r--r--vcl/inc/opengl/TextureState.hxx76
-rw-r--r--vcl/inc/opengl/VertexUtils.hxx120
-rw-r--r--vcl/inc/opengl/framebuffer.hxx48
-rw-r--r--vcl/inc/opengl/gdiimpl.hxx395
-rw-r--r--vcl/inc/opengl/program.hxx122
-rw-r--r--vcl/inc/opengl/salbmp.hxx113
-rw-r--r--vcl/inc/opengl/texture.hxx139
-rw-r--r--vcl/inc/opengl/win/WinDeviceInfo.hxx103
-rw-r--r--vcl/inc/opengl/win/gdiimpl.hxx97
-rw-r--r--vcl/inc/opengl/win/winlayout.hxx51
-rw-r--r--vcl/inc/opengl/x11/X11DeviceInfo.hxx75
-rw-r--r--vcl/inc/opengl/x11/cairotextrender.hxx27
-rw-r--r--vcl/inc/opengl/x11/gdiimpl.hxx42
-rw-r--r--vcl/inc/opengl/x11/glxtest.hxx21
-rw-r--r--vcl/inc/opengl/x11/salvd.hxx57
-rw-r--r--vcl/inc/opengl/zone.hxx46
23 files changed, 2159 insertions, 0 deletions
diff --git a/vcl/inc/opengl/BufferObject.hxx b/vcl/inc/opengl/BufferObject.hxx
new file mode 100644
index 000000000..396de89de
--- /dev/null
+++ b/vcl/inc/opengl/BufferObject.hxx
@@ -0,0 +1,84 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_BUFFEROBJECT_H
+#define INCLUDED_VCL_INC_OPENGL_BUFFEROBJECT_H
+
+namespace vcl
+{
+
+template<typename TYPE, GLenum BUFFER_TYPE>
+class BufferObject
+{
+private:
+ GLuint mId;
+
+public:
+ BufferObject()
+ : mId(0)
+ {
+ glGenBuffers(1, &mId);
+ CHECK_GL_ERROR();
+ }
+
+ virtual ~BufferObject()
+ {
+ if (mId)
+ {
+ glDeleteBuffers(1, &mId);
+ CHECK_GL_ERROR();
+ mId = 0;
+ }
+ }
+
+ void bind()
+ {
+ if (mId)
+ {
+ glBindBuffer(BUFFER_TYPE, mId);
+ CHECK_GL_ERROR();
+ }
+ }
+
+ void unbind()
+ {
+ if (mId)
+ {
+ glBindBuffer(BUFFER_TYPE, 0);
+ CHECK_GL_ERROR();
+ }
+ }
+
+ void upload(const std::vector<TYPE>& rData)
+ {
+ if (mId)
+ {
+ bind();
+ glBufferData(BUFFER_TYPE, sizeof(TYPE) * rData.size(), rData.data(), GL_STATIC_DRAW);
+ CHECK_GL_ERROR();
+ }
+ }
+
+};
+
+template<typename TYPE>
+class VertexBufferObject final : public BufferObject<TYPE, GL_ARRAY_BUFFER>
+{
+};
+
+class IndexBufferObject final : public BufferObject<GLuint, GL_ELEMENT_ARRAY_BUFFER>
+{
+};
+
+} // end vcl
+
+#endif // INCLUDED_VCL_INC_OPENGL_BUFFEROBJECT_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/DeviceInfo.hxx b/vcl/inc/opengl/DeviceInfo.hxx
new file mode 100644
index 000000000..b0ad3a6cf
--- /dev/null
+++ b/vcl/inc/opengl/DeviceInfo.hxx
@@ -0,0 +1,23 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_DEVICEINFO_HXX
+#define INCLUDED_VCL_INC_OPENGL_DEVICEINFO_HXX
+
+class OpenGLDeviceInfo
+{
+public:
+ virtual ~OpenGLDeviceInfo() = 0;
+
+ virtual bool isDeviceBlocked() = 0;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/FixedTextureAtlas.hxx b/vcl/inc/opengl/FixedTextureAtlas.hxx
new file mode 100644
index 000000000..e576fcb54
--- /dev/null
+++ b/vcl/inc/opengl/FixedTextureAtlas.hxx
@@ -0,0 +1,47 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_FIXEDTEXTUREATLAS_HXX
+#define INCLUDED_VCL_INC_OPENGL_FIXEDTEXTUREATLAS_HXX
+
+#include <memory>
+#include <opengl/texture.hxx>
+
+struct FixedTexture;
+
+class FixedTextureAtlasManager final
+{
+ std::vector<std::unique_ptr<FixedTexture>> maFixedTextures;
+
+ int mWidthFactor;
+ int mHeightFactor;
+ int mSubTextureSize;
+
+ void CreateNewTexture();
+
+ FixedTextureAtlasManager( const FixedTextureAtlasManager& ) = delete;
+ FixedTextureAtlasManager& operator=( const FixedTextureAtlasManager& ) = delete;
+
+public:
+ FixedTextureAtlasManager(int nWidthFactor, int nHeightFactor, int nTextureSize);
+ ~FixedTextureAtlasManager();
+
+ OpenGLTexture InsertBuffer(int nWidth, int nHeight, int nFormat, int nType, sal_uInt8 const * pData);
+ OpenGLTexture Reserve(int nWidth, int nHeight);
+
+ int GetSubtextureSize() const
+ {
+ return mSubTextureSize;
+ }
+};
+
+#endif // INCLUDED_VCL_INC_OPENGL_FIXEDTEXTUREATLAS_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/LineRenderUtils.hxx b/vcl/inc/opengl/LineRenderUtils.hxx
new file mode 100644
index 000000000..8d97fa3ee
--- /dev/null
+++ b/vcl/inc/opengl/LineRenderUtils.hxx
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_LINERENDERUTILS_H
+#define INCLUDED_VCL_INC_OPENGL_LINERENDERUTILS_H
+
+#include <opengl/RenderList.hxx>
+
+namespace vcl
+{
+class LineBuilder
+{
+private:
+ std::vector<Vertex>& mrVertices;
+ std::vector<GLuint>& mrIndices;
+ GLubyte mR, mG, mB, mA;
+ GLfloat mfLineWidth;
+ GLfloat mfLineWidthAndAA;
+ size_t mnInitialIndexSize;
+ bool mbIncomplete;
+
+public:
+ LineBuilder(std::vector<Vertex>& rVertices, std::vector<GLuint>& rIndices,
+ Color nColor, GLfloat fTransparency,
+ GLfloat fLineWidth, bool bUseAA);
+
+ void appendLineSegment(const glm::vec2& rPoint1, const glm::vec2& rNormal1, GLfloat aExtrusion1,
+ const glm::vec2& rPoint2, const glm::vec2& rNormal2, GLfloat aExtrusion2);
+
+ void appendLine(const glm::vec2& rPoint1, const glm::vec2& rPoint2);
+
+ void appendAndConnectLinePoint(const glm::vec2& rPoint, const glm::vec2& aNormal, GLfloat aExtrusion);
+
+ void appendMiterJoint(glm::vec2 const& point, const glm::vec2& prevLineVector,
+ glm::vec2 const& nextLineVector);
+ void appendBevelJoint(glm::vec2 const& point, const glm::vec2& prevLineVector,
+ const glm::vec2& nextLineVector);
+ void appendRoundJoint(glm::vec2 const& point, const glm::vec2& prevLineVector,
+ const glm::vec2& nextLineVector);
+ void appendRoundLineCapVertices(const glm::vec2& rPoint1, const glm::vec2& rPoint2);
+ void appendSquareLineCapVertices(const glm::vec2& rPoint1, const glm::vec2& rPoint2);
+};
+
+} // end vcl
+
+#endif // INCLUDED_VCL_INC_OPENGL_LINERENDERUTILS_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/PackedTextureAtlas.hxx b/vcl/inc/opengl/PackedTextureAtlas.hxx
new file mode 100644
index 000000000..7a283aa45
--- /dev/null
+++ b/vcl/inc/opengl/PackedTextureAtlas.hxx
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_PACKEDTEXTUREATLAS_HXX
+#define INCLUDED_VCL_INC_OPENGL_PACKEDTEXTUREATLAS_HXX
+
+#include <memory>
+#include <opengl/texture.hxx>
+
+struct PackedTexture;
+
+/**
+ * Pack textures into one texture atlas.
+ *
+ * This is based on algorithm described in [1] and is an
+ * adaptation of "texture atlas generator" from [2].
+ *
+ * [1]: http://www.blackpawn.com/texts/lightmaps/
+ * [2]: https://github.com/lukaszdk/texture-atlas-generator
+ *
+ */
+class VCL_DLLPUBLIC PackedTextureAtlasManager final
+{
+ std::vector<std::unique_ptr<PackedTexture>> maPackedTextures;
+
+ int mnTextureWidth;
+ int mnTextureHeight;
+
+ void CreateNewTexture();
+
+ PackedTextureAtlasManager( const PackedTextureAtlasManager& ) = delete;
+ PackedTextureAtlasManager& operator=( const PackedTextureAtlasManager& ) = delete;
+
+public:
+
+ /**
+ * nTextureWidth and nTextureHeight are the dimensions of the common texture(s)
+ * nTextureLimit is the maximum limit of that a texture atlas can have (0 or less - unlimited)
+ */
+ PackedTextureAtlasManager(int nTextureWidth, int nTextureHeight);
+ ~PackedTextureAtlasManager();
+
+ OpenGLTexture InsertBuffer(int nWidth, int nHeight, int nFormat, int nType, sal_uInt8 const * pData);
+ OpenGLTexture Reserve(int nWidth, int nHeight);
+ std::vector<GLuint> ReduceTextureNumber(int nMaxNumberOfTextures);
+};
+
+#endif // INCLUDED_VCL_INC_OPENGL_PACKEDTEXTUREATLAS_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/RenderList.hxx b/vcl/inc/opengl/RenderList.hxx
new file mode 100644
index 000000000..213a2f43b
--- /dev/null
+++ b/vcl/inc/opengl/RenderList.hxx
@@ -0,0 +1,173 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_RENDERLIST_H
+#define INCLUDED_VCL_INC_OPENGL_RENDERLIST_H
+
+#include <unordered_map>
+
+#include <glm/glm.hpp>
+
+#include <vcl/salgtype.hxx>
+#include <basegfx/range/b2drange.hxx>
+#include <basegfx/polygon/b2dpolypolygon.hxx>
+
+#include <opengl/texture.hxx>
+
+#include <com/sun/star/drawing/LineCap.hpp>
+
+struct Vertex
+{
+ glm::vec2 position;
+ glm::vec4 color;
+ glm::vec4 lineData;
+};
+
+static_assert(sizeof(Vertex) == (2*4 + 4*4 + 4*4), "Vertex struct has wrong size/alignment");
+
+
+struct RenderParameters
+{
+ std::vector<Vertex> maVertices;
+ std::vector<GLuint> maIndices;
+};
+
+struct RenderTextureParameters
+{
+ std::vector<GLfloat> maVertices;
+ std::vector<GLfloat> maTextureCoords;
+ std::vector<GLubyte> maColors;
+ OpenGLTexture maTexture;
+};
+
+struct RenderEntry
+{
+ basegfx::B2DRange maOverlapTrackingRectangle;
+
+ RenderParameters maTriangleParameters;
+ RenderParameters maLineParameters;
+
+ std::unordered_map<GLuint, RenderTextureParameters> maTextureParametersMap;
+
+ bool hasTriangles() const
+ {
+ return !maTriangleParameters.maVertices.empty();
+ }
+
+ bool hasLines() const
+ {
+ return !maLineParameters.maVertices.empty();
+ }
+
+ bool hasTextures() const
+ {
+ return !maTextureParametersMap.empty();
+ }
+};
+
+class RenderList
+{
+private:
+ std::vector<RenderEntry> maRenderEntries;
+ std::vector<basegfx::B2DRange> maRectangles;
+
+ bool doesOverlap(const basegfx::B2DRange& rDrawRectangle)
+ {
+ if (!maRenderEntries.back().maOverlapTrackingRectangle.overlaps(rDrawRectangle))
+ return false;
+
+ for (const basegfx::B2DRange& rRectangle : maRectangles)
+ {
+ if (rRectangle.overlaps(rDrawRectangle))
+ return true;
+ }
+ return false;
+ }
+
+ void checkOverlapping(const basegfx::B2DRange& rDrawRectangle)
+ {
+ if (maRenderEntries.empty() || doesOverlap(rDrawRectangle))
+ {
+ maRenderEntries.emplace_back();
+ maRenderEntries.back().maOverlapTrackingRectangle = rDrawRectangle;
+
+ maRectangles.clear();
+ maRectangles.reserve(30);
+ maRectangles.push_back(rDrawRectangle);
+ }
+ else
+ {
+ maRenderEntries.back().maOverlapTrackingRectangle.expand(rDrawRectangle);
+
+ if (maRectangles.size() < 30)
+ {
+ maRectangles.push_back(rDrawRectangle);
+ }
+ else
+ {
+ basegfx::B2DRange aTempRectangle(maRectangles[0]);
+ aTempRectangle.expand(rDrawRectangle);
+ double minArea = aTempRectangle.getWidth() * aTempRectangle.getHeight();
+ size_t index = 0;
+
+ double area;
+ for (size_t i = 1; i < maRectangles.size(); ++i)
+ {
+ aTempRectangle = maRectangles[i];
+ aTempRectangle.expand(rDrawRectangle);
+ area = aTempRectangle.getWidth() * aTempRectangle.getHeight();
+ if (area < minArea)
+ index = i;
+ }
+ maRectangles[index].expand(rDrawRectangle);
+ }
+ }
+ }
+
+public:
+
+ RenderList() = default;
+
+ bool empty()
+ {
+ return maRenderEntries.empty();
+ }
+
+ void clear()
+ {
+ maRenderEntries.clear();
+ }
+
+ std::vector<RenderEntry>& getEntries()
+ {
+ return maRenderEntries;
+ }
+
+ VCL_DLLPUBLIC void addDrawTextureWithMaskColor(OpenGLTexture const & rTexture, Color nColor, const SalTwoRect& r2Rect);
+
+ void addDrawPixel(long nX, long nY, Color nColor);
+
+ void addDrawRectangle(long nX, long nY, long nWidth, long nHeight, double fTransparency,
+ Color nLineColor, Color nFillColor);
+
+ void addDrawLine(long nX1, long nY1, long nX2, long nY2, Color nLineColor, bool bUseAA);
+
+ void addDrawPolyPolygon(const basegfx::B2DPolyPolygon& rPolyPolygon, double fTransparency,
+ Color nLineColor, Color nFillColor, bool bUseAA);
+
+ void addDrawPolyLine(const basegfx::B2DPolygon& rPolygon, double fTransparency,
+ double fLineWidth, basegfx::B2DLineJoin eLineJoin,
+ css::drawing::LineCap eLineCap, double fMiterMinimumAngle,
+ Color nLineColor, bool bUseAA);
+};
+
+#endif // INCLUDED_VCL_INC_OPENGL_RENDERLIST_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/RenderState.hxx b/vcl/inc/opengl/RenderState.hxx
new file mode 100644
index 000000000..3a89344e2
--- /dev/null
+++ b/vcl/inc/opengl/RenderState.hxx
@@ -0,0 +1,188 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_RENDER_STATE_H
+#define INCLUDED_VCL_INC_OPENGL_RENDER_STATE_H
+
+#include <opengl/TextureState.hxx>
+
+template<GLenum ENUM_TYPE, typename TYPE>
+class GenericCapabilityState
+{
+protected:
+ bool mbTest;
+
+ GenericCapabilityState()
+ : mbTest(false)
+ {
+ }
+
+ static bool readState()
+ {
+ return glIsEnabled(ENUM_TYPE);
+ }
+
+public:
+ void sync()
+ {
+ mbTest = readState();
+ }
+
+ void enable()
+ {
+ if (!mbTest)
+ {
+ glEnable(ENUM_TYPE);
+ CHECK_GL_ERROR();
+ mbTest = true;
+ }
+ else
+ {
+ VCL_GL_INFO(TYPE::className() << ": enable called but already enabled");
+ }
+#ifdef DBG_UTIL
+ checkState();
+#endif
+ }
+
+ void disable()
+ {
+ if (mbTest)
+ {
+ glDisable(ENUM_TYPE);
+ CHECK_GL_ERROR();
+ mbTest = false;
+ }
+ else
+ {
+ VCL_GL_INFO(TYPE::className() << ": disable called but already disabled");
+ }
+#ifdef DBG_UTIL
+ checkState();
+#endif
+ }
+
+#ifdef DBG_UTIL
+ void checkState()
+ {
+ bool bRealState = readState();
+ if (mbTest != bRealState)
+ {
+ VCL_GL_INFO(TYPE::className() << " mismatch! "
+ << "Expected: " << (mbTest ? "enabled" : "disabled")
+ << " but is: " << (bRealState ? "enabled" : "disabled"));
+ }
+ }
+#endif
+};
+
+class ScissorState : public GenericCapabilityState<GL_SCISSOR_TEST, ScissorState>
+{
+private:
+ int mX;
+ int mY;
+ int mWidth;
+ int mHeight;
+
+public:
+ static std::string className() { return std::string("ScissorState"); }
+
+ ScissorState()
+ : mX(0)
+ , mY(0)
+ , mWidth(0)
+ , mHeight(0)
+ {}
+
+ void set(int x, int y, int width, int height)
+ {
+ if (x != mX || y != mY || width != mWidth || height != mHeight)
+ {
+ glScissor(x, y, width, height);
+ CHECK_GL_ERROR();
+
+ mX = x;
+ mY = y;
+ mWidth = width;
+ mHeight = height;
+ }
+ }
+};
+
+class StencilState : public GenericCapabilityState<GL_STENCIL_TEST, StencilState>
+{
+public:
+ static std::string className() { return std::string("StencilState"); }
+};
+
+class BlendState : public GenericCapabilityState<GL_BLEND, BlendState>
+{
+ GLenum mnSourceMode;
+ GLenum mnDestinationMode;
+public:
+ BlendState()
+ : mnSourceMode(GL_ZERO)
+ , mnDestinationMode(GL_ZERO)
+ {}
+
+ static std::string className() { return std::string("BlendState"); }
+
+ void func(GLenum nSource, GLenum nDestination)
+ {
+ if (mnSourceMode != nSource || mnDestinationMode != nDestination)
+ {
+ glBlendFunc(nSource, nDestination);
+ CHECK_GL_ERROR();
+ mnSourceMode = nSource;
+ mnDestinationMode = nDestination;
+ }
+ }
+};
+
+class RenderState
+{
+ TextureState maTexture;
+ ScissorState maScissor;
+ StencilState maStencil;
+ BlendState maBlend;
+
+ tools::Rectangle maCurrentViewport;
+
+public:
+ RenderState()
+ {}
+
+ void viewport(tools::Rectangle aViewPort)
+ {
+ if (aViewPort != maCurrentViewport)
+ {
+ glViewport(aViewPort.Left(), aViewPort.Top(), aViewPort.GetWidth(), aViewPort.GetHeight());
+ CHECK_GL_ERROR();
+ maCurrentViewport = aViewPort;
+ }
+ }
+
+ TextureState& texture() { return maTexture; }
+ ScissorState& scissor() { return maScissor; }
+ StencilState& stencil() { return maStencil; }
+ BlendState& blend() { return maBlend; }
+
+ void sync()
+ {
+ VCL_GL_INFO("RenderState::sync");
+ maScissor.sync();
+ maStencil.sync();
+ maBlend.sync();
+ }
+};
+
+#endif // INCLUDED_VCL_INC_OPENGL_RENDER_STATE_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/TextureState.hxx b/vcl/inc/opengl/TextureState.hxx
new file mode 100644
index 000000000..fbf2b9cee
--- /dev/null
+++ b/vcl/inc/opengl/TextureState.hxx
@@ -0,0 +1,76 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_TEXTURE_STATE_H
+#define INCLUDED_VCL_INC_OPENGL_TEXTURE_STATE_H
+
+#include <vcl/opengl/OpenGLHelper.hxx>
+
+class TextureState
+{
+private:
+ GLuint mnCurrentTextureUnit;
+ std::vector<GLuint> maBoundTextures;
+
+public:
+ TextureState()
+ : mnCurrentTextureUnit(0)
+ , maBoundTextures(4, 0)
+ {}
+
+ static void generate(GLuint& nTexture)
+ {
+ glGenTextures(1, &nTexture);
+ CHECK_GL_ERROR();
+ }
+
+ void active(GLuint nTextureUnit)
+ {
+ if (mnCurrentTextureUnit != nTextureUnit)
+ {
+ glActiveTexture(GL_TEXTURE0 + nTextureUnit);
+ CHECK_GL_ERROR();
+ mnCurrentTextureUnit = nTextureUnit;
+ }
+
+ }
+
+ void bind(GLuint nTexture)
+ {
+ if (maBoundTextures[mnCurrentTextureUnit] != nTexture)
+ {
+ glBindTexture(GL_TEXTURE_2D, nTexture);
+ CHECK_GL_ERROR();
+ maBoundTextures[mnCurrentTextureUnit] = nTexture;
+ }
+ }
+
+ void unbindAndDelete(GLuint nTexture)
+ {
+ unbind(nTexture);
+ glDeleteTextures(1, &nTexture);
+ }
+
+ void unbind(GLuint nTexture)
+ {
+ for (size_t i = 0; i < maBoundTextures.size(); i++)
+ {
+ if (nTexture == maBoundTextures[i])
+ maBoundTextures[i] = 0;
+ }
+ }
+
+};
+
+
+
+#endif // INCLUDED_VCL_INC_OPENGL_TEXTURE_STATE_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/VertexUtils.hxx b/vcl/inc/opengl/VertexUtils.hxx
new file mode 100644
index 000000000..910b8725a
--- /dev/null
+++ b/vcl/inc/opengl/VertexUtils.hxx
@@ -0,0 +1,120 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_VERTEXUTILS_H
+#define INCLUDED_VCL_INC_OPENGL_VERTEXUTILS_H
+
+#include <basegfx/numeric/ftools.hxx>
+#include <epoxy/gl.h>
+#include <glm/gtx/norm.hpp>
+#include <tools/color.hxx>
+#include <vector>
+
+namespace vcl
+{
+namespace vertex
+{
+
+template<GLenum TYPE>
+inline void addRectangle(std::vector<GLfloat>& rVertices, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2);
+
+template<>
+inline void addRectangle<GL_TRIANGLES>(std::vector<GLfloat>& rVertices, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
+{
+ rVertices.insert(rVertices.end(), {
+ x1, y1, x2, y1, x1, y2,
+ x1, y2, x2, y1, x2, y2
+ });
+}
+
+template<>
+inline void addRectangle<GL_TRIANGLE_FAN>(std::vector<GLfloat>& rVertices, GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2)
+{
+ rVertices.insert(rVertices.end(), {
+ x1, y2, x1, y1,
+ x2, y1, x2, y2
+ });
+}
+
+inline void createColor(Color nColor, GLfloat fTransparency, GLubyte& nR, GLubyte& nG, GLubyte& nB, GLubyte& nA)
+{
+ nR = nColor.GetRed();
+ nG = nColor.GetGreen();
+ nB = nColor.GetBlue();
+ nA = (1.0f - fTransparency) * 255.0f;
+}
+
+template<GLenum TYPE>
+inline void addQuadColors(std::vector<GLubyte>& rColors, Color nColor, GLfloat fTransparency);
+
+template<>
+inline void addQuadColors<GL_TRIANGLES>(std::vector<GLubyte>& rColors, Color nColor, GLfloat fTransparency)
+{
+ GLubyte nR, nG, nB, nA;
+ createColor(nColor, fTransparency, nR, nG, nB, nA);
+
+ rColors.insert(rColors.end(), {
+ nR, nG, nB, nA,
+ nR, nG, nB, nA,
+ nR, nG, nB, nA,
+ nR, nG, nB, nA,
+ nR, nG, nB, nA,
+ nR, nG, nB, nA,
+ });
+}
+
+inline void addLineSegmentVertices(std::vector<GLfloat>& rVertices, std::vector<GLfloat>& rExtrusionVectors,
+ glm::vec2 prevPoint, glm::vec2 prevExtrusionVector, GLfloat prevLength,
+ glm::vec2 currPoint, glm::vec2 currExtrusionVector, GLfloat currLength)
+{
+ rVertices.insert(rVertices.end(), {
+ prevPoint.x, prevPoint.y,
+ prevPoint.x, prevPoint.y,
+ currPoint.x, currPoint.y,
+ currPoint.x, currPoint.y,
+ prevPoint.x, prevPoint.y,
+ currPoint.x, currPoint.y,
+ });
+
+ rExtrusionVectors.insert(rExtrusionVectors.end(), {
+ -prevExtrusionVector.x, -prevExtrusionVector.y, -prevLength,
+ prevExtrusionVector.x, prevExtrusionVector.y, prevLength,
+ -currExtrusionVector.x, -currExtrusionVector.y, -currLength,
+ -currExtrusionVector.x, -currExtrusionVector.y, -currLength,
+ prevExtrusionVector.x, prevExtrusionVector.y, prevLength,
+ currExtrusionVector.x, currExtrusionVector.y, currLength,
+ });
+}
+
+inline glm::vec2 normalize(const glm::vec2& vector)
+{
+ if (glm::length(vector) > 0.0)
+ return glm::normalize(vector);
+ return vector;
+}
+
+inline glm::vec2 perpendicular(const glm::vec2& vector)
+{
+ return glm::vec2(-vector.y, vector.x);
+}
+
+inline float lineVectorAngle(const glm::vec2& previous, const glm::vec2& next)
+{
+ float angle = std::atan2(previous.x * next.y - previous.y * next.x,
+ previous.x * next.x + previous.y * next.y);
+
+ return F_PI - std::fabs(angle);
+}
+
+}} // end vcl::vertex
+
+#endif // INCLUDED_VCL_INC_OPENGL_VERTEXUTILS_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/framebuffer.hxx b/vcl/inc/opengl/framebuffer.hxx
new file mode 100644
index 000000000..4445e6198
--- /dev/null
+++ b/vcl/inc/opengl/framebuffer.hxx
@@ -0,0 +1,48 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_FRAMEBUFFER_H
+#define INCLUDED_VCL_INC_OPENGL_FRAMEBUFFER_H
+
+#include <vcl/dllapi.h>
+
+#include <opengl/texture.hxx>
+
+class OpenGLFramebuffer final
+{
+private:
+ GLuint mnId;
+ int mnWidth;
+ int mnHeight;
+ GLuint mnAttachedTexture;
+
+public:
+ OpenGLFramebuffer();
+ ~OpenGLFramebuffer();
+
+ int GetWidth() const { return mnWidth; };
+ int GetHeight() const { return mnHeight; };
+
+ void Bind(GLenum eTarget = GL_FRAMEBUFFER);
+
+ static void Unbind(GLenum eTarget = GL_FRAMEBUFFER);
+
+ VCL_DLLPUBLIC bool IsFree() const;
+ bool IsAttached( GLuint nTexture ) const;
+ bool IsAttached( const OpenGLTexture& rTexture ) const;
+ void AttachTexture( const OpenGLTexture& rTexture );
+ void DetachTexture();
+
+public:
+ OpenGLFramebuffer* mpPrevFramebuffer;
+};
+
+#endif // INCLUDED_VCL_INC_OPENGL_FRAMEBUFFER_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/gdiimpl.hxx b/vcl/inc/opengl/gdiimpl.hxx
new file mode 100644
index 000000000..a6de106a6
--- /dev/null
+++ b/vcl/inc/opengl/gdiimpl.hxx
@@ -0,0 +1,395 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_VCL_OPENGLGDIIMPL_HXX
+#define INCLUDED_VCL_OPENGLGDIIMPL_HXX
+
+#include <vcl/dllapi.h>
+#include <vcl/opengl/OpenGLContext.hxx>
+
+#include <regionband.hxx>
+#include <salgeom.hxx>
+#include <salgdiimpl.hxx>
+#include <opengl/program.hxx>
+#include <opengl/texture.hxx>
+#include <opengl/RenderList.hxx>
+
+#include <memory>
+
+class SalFrame;
+class SalVirtualDevice;
+class OpenGLTests;
+
+namespace basegfx
+{
+class B2DTrapezoid;
+};
+
+namespace tools
+{
+ class Polygon;
+ class PolyPolygon;
+}
+
+struct TextureCombo
+{
+ std::unique_ptr<OpenGLTexture> mpTexture;
+ std::unique_ptr<OpenGLTexture> mpMask;
+};
+
+class OpenGLFlushIdle;
+
+class VCL_DLLPUBLIC OpenGLSalGraphicsImpl : public SalGraphicsImpl
+{
+ friend class OpenGLTests;
+protected:
+
+ /// This context is solely for blitting maOffscreenTex
+ rtl::Reference<OpenGLContext> mpWindowContext;
+
+ /// This context is whatever is most convenient to render
+ /// to maOffscreenTex with.
+ rtl::Reference<OpenGLContext> mpContext;
+
+ SalGraphics& mrParent;
+ /// Pointer to the SalFrame or SalVirtualDevice
+ SalGeometryProvider* mpProvider;
+ OpenGLProgram* mpProgram;
+
+ /// This idle handler is used to swap buffers after rendering.
+ std::unique_ptr<OpenGLFlushIdle> mpFlush;
+
+ // clipping
+ vcl::Region maClipRegion;
+ bool mbUseScissor;
+ bool mbUseStencil;
+
+ bool mbXORMode;
+
+ bool mbAcquiringOpenGLContext;
+
+ /**
+ * All rendering happens to this off-screen texture. For
+ * non-virtual devices, ie. windows - we will blit it and
+ * swapBuffers later.
+ */
+ OpenGLTexture maOffscreenTex;
+
+ Color mnLineColor;
+ Color mnFillColor;
+#ifdef DBG_UTIL
+ bool mProgramIsSolidColor;
+#endif
+ sal_uInt32 mnDrawCount;
+ sal_uInt32 mnDrawCountAtFlush;
+ Color mProgramSolidColor;
+ double mProgramSolidTransparency;
+
+ std::unique_ptr<RenderList> mpRenderList;
+
+ void ImplInitClipRegion();
+ void ImplSetClipBit( const vcl::Region& rClip, GLuint nMask );
+ void ImplDrawLineAA( double nX1, double nY1, double nX2, double nY2, bool edge );
+ void CheckOffscreenTexture();
+
+ void ApplyProgramMatrices(float fPixelOffset = 0.0);
+
+public:
+ bool UseProgram( const OUString& rVertexShader, const OUString& rFragmentShader, const OString& preamble = "" );
+ bool UseSolid( Color nColor, sal_uInt8 nTransparency );
+ bool UseSolid( Color nColor, double fTransparency );
+ bool UseSolid( Color nColor );
+ void UseSolid();
+ bool UseLine(Color nColor, double fTransparency, GLfloat fLineWidth, bool bUseAA);
+ void UseLine(GLfloat fLineWidth, bool bUseAA);
+ bool UseInvert50();
+ bool UseInvert(SalInvert nFlags);
+
+ void DrawConvexPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry, bool blockAA = false );
+ void DrawConvexPolygon( const tools::Polygon& rPolygon, bool blockAA );
+ void DrawTrapezoid( const basegfx::B2DTrapezoid& trapezoid, bool blockAA );
+ void DrawRect( long nX, long nY, long nWidth, long nHeight );
+ void DrawRect( const tools::Rectangle& rRect );
+ void DrawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry );
+ void DrawLineSegment(float x1, float y1, float x2, float y2);
+ void DrawPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPolygon, bool blockAA = false );
+ void DrawRegionBand( const RegionBand& rRegion );
+ void DrawTextureRect( const SalTwoRect& rPosAry );
+ void DrawTexture( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted = false );
+ void DrawTransformedTexture( OpenGLTexture& rTexture, OpenGLTexture& rMask, const basegfx::B2DPoint& rNull, const basegfx::B2DPoint& rX, const basegfx::B2DPoint& rY );
+ void DrawAlphaTexture( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted, bool pPremultiplied );
+ void DrawTextureDiff( OpenGLTexture& rTexture, OpenGLTexture& rMask, const SalTwoRect& rPosAry, bool bInverted );
+ void DrawTextureWithMask( OpenGLTexture& rTexture, OpenGLTexture& rMask, const SalTwoRect& rPosAry );
+ void DrawBlendedTexture( OpenGLTexture& rTexture, OpenGLTexture& rMask, OpenGLTexture& rAlpha, const SalTwoRect& rPosAry );
+ void DrawMask( OpenGLTexture& rTexture, Color nMaskColor, const SalTwoRect& rPosAry );
+ void DrawLinearGradient( const Gradient& rGradient, const tools::Rectangle& rRect );
+ void DrawAxialGradient( const Gradient& rGradient, const tools::Rectangle& rRect );
+ void DrawRadialGradient( const Gradient& rGradient, const tools::Rectangle& rRect );
+
+ void FlushDeferredDrawing();
+ void FlushLinesOrTriangles(DrawShaderType eType, RenderParameters const & rParameters);
+
+public:
+ // get the width of the device
+ GLfloat GetWidth() const { return mpProvider ? mpProvider->GetWidth() : 1; }
+
+ // get the height of the device
+ GLfloat GetHeight() const { return mpProvider ? mpProvider->GetHeight() : 1; }
+
+ /**
+ * check whether this instance is used for offscreen (Virtual Device)
+ * rendering ie. does it need its own context.
+ */
+ bool IsOffscreen() const { return mpProvider == nullptr || mpProvider->IsOffScreen(); }
+
+ /// Oddly not all operations obey the XOR option.
+ enum XOROption { IGNORE_XOR, IMPLEMENT_XOR };
+
+ // initialize pre-draw state
+ void InitializePreDrawState(XOROption eOpt);
+
+ // operations to do before painting
+ void PreDraw(XOROption eOpt = IGNORE_XOR);
+
+ // operations to do after painting
+ void PostDraw();
+
+ void PostBatchDraw();
+
+protected:
+ bool AcquireContext(bool bForceCreate = false);
+ void ReleaseContext();
+
+ /// create a new context for rendering to the underlying window
+ virtual rtl::Reference<OpenGLContext> CreateWinContext() = 0;
+
+ /// check whether the given context can be used for off-screen rendering
+ static bool UseContext( const rtl::Reference<OpenGLContext> &pContext )
+ {
+ return pContext->isInitialized() && // not released by the OS etc.
+ pContext->isVCLOnly();
+ }
+
+public:
+ OpenGLSalGraphicsImpl(SalGraphics& pParent, SalGeometryProvider *pProvider);
+ virtual ~OpenGLSalGraphicsImpl () override;
+
+ rtl::Reference<OpenGLContext> GetOpenGLContext();
+
+ virtual void Init() override;
+
+ virtual void DeInit() override;
+
+ virtual void freeResources() override;
+
+ virtual OUString getRenderBackendName() const override { return "opengl"; }
+
+ const vcl::Region& getClipRegion() const;
+ virtual bool setClipRegion( const vcl::Region& ) override;
+
+ //
+ // get the depth of the device
+ virtual sal_uInt16 GetBitCount() const override;
+
+ // get the width of the device
+ virtual long GetGraphicsWidth() const override;
+
+ // set the clip region to empty
+ virtual void ResetClipRegion() override;
+
+ // set the line color to transparent (= don't draw lines)
+
+ virtual void SetLineColor() override;
+
+ // set the line color to a specific color
+ virtual void SetLineColor( Color nColor ) override;
+
+ // set the fill color to transparent (= don't fill)
+ virtual void SetFillColor() override;
+
+ // set the fill color to a specific color, shapes will be
+ // filled accordingly
+ virtual void SetFillColor( Color nColor ) override;
+
+ // enable/disable XOR drawing
+ virtual void SetXORMode( bool bSet, bool bInvertOnly ) override;
+
+ // set line color for raster operations
+ virtual void SetROPLineColor( SalROPColor nROPColor ) override;
+
+ // set fill color for raster operations
+ virtual void SetROPFillColor( SalROPColor nROPColor ) override;
+
+ // draw --> LineColor and FillColor and RasterOp and ClipRegion
+ virtual void drawPixel( long nX, long nY ) override;
+ virtual void drawPixel( long nX, long nY, Color nColor ) override;
+
+ virtual void drawLine( long nX1, long nY1, long nX2, long nY2 ) override;
+
+ virtual void drawRect( long nX, long nY, long nWidth, long nHeight ) override;
+
+ virtual void drawPolyLine( sal_uInt32 nPoints, const SalPoint* pPtAry ) override;
+
+ virtual void drawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry ) override;
+
+ virtual void drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* pPoints, PCONSTSALPOINT* pPtAry ) override;
+
+ virtual bool drawPolyPolygon(
+ const basegfx::B2DHomMatrix& rObjectToDevice,
+ const basegfx::B2DPolyPolygon&,
+ double fTransparency) override;
+
+ virtual bool drawPolyLine(
+ const basegfx::B2DHomMatrix& rObjectToDevice,
+ const basegfx::B2DPolygon&,
+ double fTransparency,
+ double fLineWidth,
+ const std::vector< double >* pStroke, // MM01
+ basegfx::B2DLineJoin,
+ css::drawing::LineCap,
+ double fMiterMinimumAngle,
+ bool bPixelSnapHairline) override;
+
+ virtual bool drawPolyLineBezier(
+ sal_uInt32 nPoints,
+ const SalPoint* pPtAry,
+ const PolyFlags* pFlgAry ) override;
+
+ virtual bool drawPolygonBezier(
+ sal_uInt32 nPoints,
+ const SalPoint* pPtAry,
+ const PolyFlags* pFlgAry ) override;
+
+ virtual bool drawPolyPolygonBezier(
+ sal_uInt32 nPoly,
+ const sal_uInt32* pPoints,
+ const SalPoint* const* pPtAry,
+ const PolyFlags* const* pFlgAry ) override;
+
+ // CopyArea --> No RasterOp, but ClipRegion
+ virtual void copyArea(
+ long nDestX, long nDestY,
+ long nSrcX, long nSrcY,
+ long nSrcWidth, long nSrcHeight,
+ bool bWindowInvalidate ) override;
+
+ // CopyBits and DrawBitmap --> RasterOp and ClipRegion
+ // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
+ void DoCopyBits(const SalTwoRect& rPosAry, OpenGLSalGraphicsImpl &rSrcImpl);
+
+ virtual bool blendBitmap(
+ const SalTwoRect&,
+ const SalBitmap& rBitmap ) override;
+
+ virtual bool blendAlphaBitmap(
+ const SalTwoRect&,
+ const SalBitmap& rSrcBitmap,
+ const SalBitmap& rMaskBitmap,
+ const SalBitmap& rAlphaBitmap ) override;
+
+ virtual void drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap ) override;
+
+ virtual void drawBitmap(
+ const SalTwoRect& rPosAry,
+ const SalBitmap& rSalBitmap,
+ const SalBitmap& rMaskBitmap ) override;
+
+ virtual void drawMask(
+ const SalTwoRect& rPosAry,
+ const SalBitmap& rSalBitmap,
+ Color nMaskColor ) override;
+
+ virtual std::shared_ptr<SalBitmap> getBitmap( long nX, long nY, long nWidth, long nHeight ) override;
+
+ virtual Color getPixel( long nX, long nY ) override;
+
+ // invert --> ClipRegion (only Windows or VirDevs)
+ virtual void invert(
+ long nX, long nY,
+ long nWidth, long nHeight,
+ SalInvert nFlags) override;
+
+ virtual void invert( sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert nFlags ) override;
+
+ virtual bool drawEPS(
+ long nX, long nY,
+ long nWidth, long nHeight,
+ void* pPtr,
+ sal_uInt32 nSize ) override;
+
+ /** Render bitmap with alpha channel
+
+ @param rSourceBitmap
+ Source bitmap to blit
+
+ @param rAlphaBitmap
+ Alpha channel to use for blitting
+
+ @return true, if the operation succeeded, and false
+ otherwise. In this case, clients should try to emulate alpha
+ compositing themselves
+ */
+ virtual bool drawAlphaBitmap(
+ const SalTwoRect&,
+ const SalBitmap& rSourceBitmap,
+ const SalBitmap& rAlphaBitmap ) override;
+
+ /** draw transformed bitmap (maybe with alpha) where Null, X, Y define the coordinate system */
+ virtual bool drawTransformedBitmap(
+ const basegfx::B2DPoint& rNull,
+ const basegfx::B2DPoint& rX,
+ const basegfx::B2DPoint& rY,
+ const SalBitmap& rSourceBitmap,
+ const SalBitmap* pAlphaBitmap) override;
+
+ /** Render solid rectangle with given transparency
+
+ @param nX Top left coordinate of rectangle
+
+ @param nY Bottom right coordinate of rectangle
+
+ @param nWidth Width of rectangle
+
+ @param nHeight Height of rectangle
+
+ @param nTransparency Transparency value (0-255) to use. 0 blits and opaque, 255 a
+ fully transparent rectangle
+
+ @returns true if successfully drawn, false if not able to draw rectangle
+ */
+ virtual bool drawAlphaRect(
+ long nX, long nY,
+ long nWidth, long nHeight,
+ sal_uInt8 nTransparency ) override;
+
+ virtual bool drawGradient(const tools::PolyPolygon& rPolygon, const Gradient& rGradient) override;
+
+ virtual bool supportsOperation(OutDevSupportType eType) const override;
+
+ /// queue an idle flush of contents of the back-buffer to the screen
+ void flush();
+
+public:
+ /// do flush of contents of the back-buffer to the screen & swap.
+ void doFlush();
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/program.hxx b/vcl/inc/opengl/program.hxx
new file mode 100644
index 000000000..bff248d9b
--- /dev/null
+++ b/vcl/inc/opengl/program.hxx
@@ -0,0 +1,122 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_PROGRAM_H
+#define INCLUDED_VCL_INC_OPENGL_PROGRAM_H
+
+#include <sal/config.h>
+
+#include <vector>
+
+#include <vcl/dllapi.h>
+
+#include <basegfx/point/b2dpoint.hxx>
+#include <rtl/ustring.hxx>
+#include <opengl/texture.hxx>
+
+#include <unordered_map>
+
+class Color;
+
+enum class TextureShaderType
+{
+ Normal = 0,
+ Blend,
+ Masked,
+ Diff,
+ MaskedColor
+};
+
+enum class DrawShaderType
+{
+ Normal = 0,
+ Line
+};
+
+class OpenGLProgram
+{
+private:
+ GLuint mnId;
+ std::unordered_map< OString, GLuint >
+ maUniformLocations;
+ sal_uInt32 mnEnabledAttribs;
+ GLuint mnPositionAttrib;
+ GLuint mnTexCoordAttrib;
+ GLuint mnAlphaCoordAttrib;
+ GLuint mnMaskCoordAttrib;
+ GLuint mnExtrusionVectorsAttrib;
+ GLuint mnVertexColorsAttrib;
+
+ std::vector< OpenGLTexture > maTextures;
+ bool mbBlending;
+
+ float mfLastWidth;
+ float mfLastHeight;
+ float mfLastPixelOffset;
+
+
+ OpenGLProgram(const OpenGLProgram &) = delete;
+public:
+ OpenGLProgram();
+ ~OpenGLProgram();
+
+ GLuint Id() { return mnId; }
+
+ bool Load( const OUString& rVertexShader, const OUString& rFragmentShader,
+ const OString& preamble, const OString& rDigest );
+ void Use();
+ void Reuse();
+ void Clean();
+
+ void SetVertices( const GLvoid* pData );
+ void SetTextureCoord( const GLvoid* pData );
+ void SetAlphaCoord( const GLvoid* pData );
+ void SetMaskCoord(const GLvoid* pData);
+ void SetExtrusionVectors(const GLvoid* pData);
+ void SetVertexColors(std::vector<GLubyte>& rColorVector);
+
+ void SetUniform1f( const OString& rName, GLfloat v1 );
+ void SetUniform2f( const OString& rName, GLfloat v1, GLfloat v2 );
+ void SetUniform1fv( const OString& rName, GLsizei nCount, GLfloat const * aValues );
+ void SetUniform2fv( const OString& rName, GLsizei nCount, GLfloat const * aValues );
+ void SetUniform1i( const OString& rName, GLint v1 );
+ void SetColor( const OString& rName, const Color& rColor );
+ void SetColor( const OString& rName, Color nColor, sal_uInt8 nTransparency );
+ void SetColorf( const OString& rName, Color nColor, double fTransparency );
+ void SetColorWithIntensity( const OString& rName, const Color& rColor, long nFactor );
+ void SetTexture( const OString& rName, OpenGLTexture& rTexture );
+ void SetTransform( const OString& rName, const OpenGLTexture& rTexture,
+ const basegfx::B2DPoint& rNull, const basegfx::B2DPoint& rX,
+ const basegfx::B2DPoint& rY );
+ void SetIdentityTransform(const OString& rName);
+ void SetShaderType(TextureShaderType eTextureShaderType);
+ void SetShaderType(DrawShaderType eDrawShaderType);
+
+ void SetBlendMode( GLenum nSFactor, GLenum nDFactor );
+
+ void ApplyMatrix(float fWidth, float fHeight, float fPixelOffset = 0.0f);
+
+ void DrawTexture( const OpenGLTexture& rTexture );
+
+ void DrawArrays(GLenum aMode, std::vector<GLfloat>& aVertices);
+ void DrawElements(GLenum aMode, GLuint nNumberOfVertices);
+
+ bool EnableVertexAttrib(GLuint& rAttrib, const OString& rName);
+
+ void SetVertexAttrib(GLuint& rAttrib, const OString& rName, GLint nSize,
+ GLenum eType, GLboolean bNormalized, GLsizei aStride,
+ const GLvoid* pPointer);
+
+private:
+ GLuint GetUniformLocation( const OString& rName );
+};
+
+#endif // INCLUDED_VCL_INC_OPENGL_PROGRAM_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/salbmp.hxx b/vcl/inc/opengl/salbmp.hxx
new file mode 100644
index 000000000..a01eca89f
--- /dev/null
+++ b/vcl/inc/opengl/salbmp.hxx
@@ -0,0 +1,113 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_SALBMP_H
+#define INCLUDED_VCL_INC_OPENGL_SALBMP_H
+
+#include <vcl/opengl/OpenGLContext.hxx>
+
+#include <opengl/texture.hxx>
+
+#include <salbmp.hxx>
+
+#include <memory>
+
+struct BitmapBuffer;
+class BitmapPalette;
+namespace vcl
+{
+ class Kernel;
+}
+
+class VCL_PLUGIN_PUBLIC OpenGLSalBitmap final : public SalBitmap
+{
+private:
+ OpenGLTexture maTexture;
+ bool mbDirtyTexture;
+ BitmapPalette maPalette;
+ std::shared_ptr<sal_uInt8> mpUserBuffer;
+ sal_uInt16 mnBits;
+ sal_uInt32 mnBytesPerRow;
+ int mnWidth;
+ int mnHeight;
+
+ virtual void updateChecksum() const override;
+
+ bool calcChecksumGL(OpenGLTexture& rInputTexture, BitmapChecksum& rChecksum) const;
+
+public:
+ OpenGLSalBitmap();
+ virtual ~OpenGLSalBitmap() override;
+
+public:
+
+ // SalBitmap methods
+ bool Create( const Size& rSize, sal_uInt16 nBitCount, const BitmapPalette& rPal ) override;
+ bool Create( const SalBitmap& rSalBmp ) override;
+ bool Create( const SalBitmap& rSalBmp, SalGraphics* pGraphics ) override;
+ bool Create( const SalBitmap& rSalBmp, sal_uInt16 nNewBitCount ) override;
+ virtual bool Create( const css::uno::Reference< css::rendering::XBitmapCanvas >& rBitmapCanvas,
+ Size& rSize,
+ bool bMask = false ) override;
+
+ void Destroy() final override;
+
+ Size GetSize() const override;
+ sal_uInt16 GetBitCount() const override;
+
+ BitmapBuffer* AcquireBuffer( BitmapAccessMode nMode ) override;
+ void ReleaseBuffer( BitmapBuffer* pBuffer, BitmapAccessMode nMode ) override;
+
+ bool GetSystemData( BitmapSystemData& rData ) override;
+
+ bool ScalingSupported() const override;
+ bool Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag ) override;
+ bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uInt8 nTol ) override;
+ bool ConvertToGreyscale() override;
+ bool InterpretAs8Bit() override;
+
+public:
+
+ void Create( const OpenGLTexture& rTex, long nX, long nY, long nWidth, long nHeight );
+ OpenGLTexture& GetTexture() const;
+ const BitmapPalette& GetBitmapPalette() const { return maPalette; }
+
+private:
+
+ GLuint CreateTexture();
+ bool AllocateUserData();
+ void DeallocateUserData();
+ bool ReadTexture();
+
+private:
+
+ bool ImplScaleFilter( const rtl::Reference< OpenGLContext > &xContext, const double& rScaleX, const double& rScaleY, GLenum nFilter );
+ static void ImplCreateKernel( const double& fScale, const vcl::Kernel& rKernel, GLfloat*& pWeights, sal_uInt32& aKernelSize );
+ bool ImplScaleConvolution(const rtl::Reference< OpenGLContext > &xContext, const double& rScaleX, const double& rScaleY, const vcl::Kernel& rKernel);
+ bool ImplScaleArea( const rtl::Reference< OpenGLContext > &xContext,
+ double rScaleX, double rScaleY );
+
+public:
+
+ void ImplScale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag );
+};
+
+#endif // INCLUDED_VCL_INC_OPENGL_SALBMP_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/texture.hxx b/vcl/inc/opengl/texture.hxx
new file mode 100644
index 000000000..0438b9af1
--- /dev/null
+++ b/vcl/inc/opengl/texture.hxx
@@ -0,0 +1,139 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_TEXTURE_H
+#define INCLUDED_VCL_INC_OPENGL_TEXTURE_H
+
+#include <epoxy/gl.h>
+#include <vcl/dllapi.h>
+#include <vcl/salgtype.hxx>
+#include <rtl/ustring.hxx>
+#include <tools/gen.hxx>
+
+#include <functional>
+#include <memory>
+#include <vector>
+
+class ImplOpenGLTexture
+{
+public:
+ GLuint mnTexture;
+ int mnWidth;
+ int mnHeight;
+ GLenum mnFilter;
+ GLuint mnOptStencil;
+
+ std::unique_ptr<std::vector<int>> mpSlotReferences;
+ std::function<void(int)> mFunctSlotDeallocateCallback;
+
+ ImplOpenGLTexture( int nWidth, int nHeight, bool bAllocate );
+ ImplOpenGLTexture( int nWidth, int nHeight, int nFormat, int nType, void const * pData );
+ ImplOpenGLTexture( int nX, int nY, int nWidth, int nHeight );
+ ~ImplOpenGLTexture();
+
+ bool InsertBuffer(int nX, int nY, int nWidth, int nHeight, int nFormat, int nType, sal_uInt8 const * pData);
+
+ void IncreaseRefCount(int nSlotNumber);
+ void DecreaseRefCount(int nSlotNumber);
+
+ void InitializeSlotMechanism(int nInitialSlotSize);
+
+ void SetSlotDeallocateCallback(std::function<void(int)> aCallback)
+ {
+ mFunctSlotDeallocateCallback = aCallback;
+ }
+
+ void ResetSlotDeallocateCallback()
+ {
+ mFunctSlotDeallocateCallback = std::function<void(int)>();
+ }
+
+ GLuint AddStencil();
+};
+
+class VCL_DLLPUBLIC OpenGLTexture final
+{
+private:
+ // if the rect size doesn't match the mpImpl one, this instance
+ // is a sub-area from the real OpenGL texture
+ tools::Rectangle maRect;
+ std::shared_ptr<ImplOpenGLTexture> mpImpl;
+ int mnSlotNumber;
+
+ inline void GetTextureRect(const SalTwoRect& rPosAry, GLfloat& x1, GLfloat& x2, GLfloat& y1, GLfloat& y2) const;
+
+ bool IsValid() const
+ {
+ return (mpImpl && mpImpl->mnTexture != 0);
+ }
+
+public:
+ OpenGLTexture();
+ OpenGLTexture(const std::shared_ptr<ImplOpenGLTexture>& pImpl, tools::Rectangle aRectangle, int nSlotNumber);
+
+ OpenGLTexture( int nWidth, int nHeight, bool bAllocate = true );
+ OpenGLTexture( int nWidth, int nHeight, int nFormat, int nType, void const * pData );
+ OpenGLTexture( int nX, int nY, int nWidth, int nHeight );
+ OpenGLTexture( const OpenGLTexture& rTexture );
+ OpenGLTexture( OpenGLTexture&& rTexture ) noexcept;
+ OpenGLTexture( const OpenGLTexture& rTexture, int nX, int nY, int nWidth, int nHeight );
+ ~OpenGLTexture();
+
+ bool IsUnique() const;
+
+ GLuint Id() const;
+ int GetWidth() const;
+ int GetHeight() const;
+
+ void GetCoord( GLfloat* pCoord, const SalTwoRect& rPosAry, bool bInverted=false ) const;
+ void GetWholeCoord( GLfloat* pCoord ) const;
+ void Bind();
+ void Unbind();
+ void Read( GLenum nFormat, GLenum nType, sal_uInt8* pData );
+ GLuint AddStencil();
+ GLuint StencilId() const;
+
+ bool CopyData(int nWidth, int nHeight, int nFormat, int nType, sal_uInt8 const * pData);
+
+ void SaveToFile(const OUString& rFileName);
+
+ GLenum GetFilter() const;
+ void SetFilter( GLenum nFilter );
+
+ operator bool() const;
+ OpenGLTexture& operator=( const OpenGLTexture& rTexture );
+ OpenGLTexture& operator=( OpenGLTexture&& rTexture );
+ bool operator==( const OpenGLTexture& rTexture ) const;
+ bool operator!=( const OpenGLTexture& rTexture ) const;
+
+ template<GLenum type>
+ void FillCoords(std::vector<GLfloat>& aCoordVector, const SalTwoRect& rPosAry) const;
+};
+
+template<> void OpenGLTexture::FillCoords<GL_TRIANGLES>(
+ std::vector<GLfloat>& aCoord, const SalTwoRect& rPosAry)
+ const;
+
+template<> void OpenGLTexture::FillCoords<GL_TRIANGLE_FAN>(
+ std::vector<GLfloat>& aCoord, const SalTwoRect& rPosAry)
+ const;
+
+#endif // INCLUDED_VCL_INC_OPENGL_TEXTURE_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/win/WinDeviceInfo.hxx b/vcl/inc/opengl/win/WinDeviceInfo.hxx
new file mode 100644
index 000000000..04d97406b
--- /dev/null
+++ b/vcl/inc/opengl/win/WinDeviceInfo.hxx
@@ -0,0 +1,103 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_VCL_OPENGL_WIN_WINDEVICEINFO_HXX
+#define INCLUDED_VCL_OPENGL_WIN_WINDEVICEINFO_HXX
+
+#include <vcl/dllapi.h>
+
+#include <opengl/DeviceInfo.hxx>
+#include <driverblocklist.hxx>
+
+#include <rtl/ustring.hxx>
+#include <vector>
+#include <cstdint>
+
+class VCL_DLLPUBLIC WinOpenGLDeviceInfo : public OpenGLDeviceInfo
+{
+private:
+ OUString maDriverVersion;
+ OUString maDriverVersion2;
+
+ OUString maDriverDate;
+ OUString maDriverDate2;
+
+ OUString maDeviceID;
+ OUString maDeviceID2;
+
+ OUString maAdapterVendorID;
+ OUString maAdapterDeviceID;
+ OUString maAdapterSubsysID;
+
+ OUString maAdapterVendorID2;
+ OUString maAdapterDeviceID2;
+ OUString maAdapterSubsysID2;
+
+ OUString maDeviceKey;
+ OUString maDeviceKey2;
+
+ OUString maDeviceString;
+ OUString maDeviceString2;
+
+ bool mbHasDualGPU;
+ bool mbRDP;
+
+ void GetData();
+ bool FindBlocklistedDeviceInList();
+
+public:
+ WinOpenGLDeviceInfo();
+
+ virtual ~WinOpenGLDeviceInfo() override;
+
+ virtual bool isDeviceBlocked() override;
+
+ const OUString& GetDriverVersion() const
+ {
+ return maDriverVersion;
+ }
+
+ const OUString& GetDriverDate() const
+ {
+ return maDriverDate;
+ }
+
+ const OUString& GetDeviceID() const
+ {
+ return maDeviceID;
+ }
+
+ const OUString& GetAdapterVendorID() const
+ {
+ return maAdapterVendorID;
+ }
+
+ const OUString& GetAdapterDeviceID() const
+ {
+ return maAdapterDeviceID;
+ }
+
+ const OUString& GetAdapterSubsysID() const
+ {
+ return maAdapterSubsysID;
+ }
+ const OUString& GetDeviceKey() const
+ {
+ return maDeviceKey;
+ }
+
+ const OUString& GetDeviceString() const
+ {
+ return maDeviceString;
+ }
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/win/gdiimpl.hxx b/vcl/inc/opengl/win/gdiimpl.hxx
new file mode 100644
index 000000000..dff47ef7e
--- /dev/null
+++ b/vcl/inc/opengl/win/gdiimpl.hxx
@@ -0,0 +1,97 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_WIN_GDIIMPL_HXX
+#define INCLUDED_VCL_INC_OPENGL_WIN_GDIIMPL_HXX
+
+#include <memory>
+#include <vcl/dllapi.h>
+
+#include <opengl/gdiimpl.hxx>
+#include <svdata.hxx>
+#include <win/salgdi.h>
+#include <win/wingdiimpl.hxx>
+#include <o3tl/lru_map.hxx>
+#include <vcl/opengl/OpenGLContext.hxx>
+#include <ControlCacheKey.hxx>
+
+class OpenGLCompatibleDC : public CompatibleDC
+{
+public:
+ OpenGLCompatibleDC(SalGraphics &rGraphics, int x, int y, int width, int height);
+
+ virtual std::unique_ptr<Texture> getAsMaskTexture() const override;
+ // caller must delete
+ OpenGLTexture* getOpenGLTexture() const;
+
+ /// Copy bitmap data to the texture. Texture must be initialized and the correct size to hold the bitmap.
+ bool copyToTexture(Texture& aTexture) const;
+
+ struct Texture;
+};
+
+struct OpenGLCompatibleDC::Texture : public CompatibleDC::Texture
+{
+ OpenGLTexture texture;
+ virtual bool isValid() const { return !!texture; }
+ virtual int GetWidth() const { return texture.GetWidth(); }
+ virtual int GetHeight() const { return texture.GetHeight(); }
+};
+
+class WinOpenGLSalGraphicsImpl : public OpenGLSalGraphicsImpl, public WinSalGraphicsImplBase
+{
+ friend class WinLayout;
+private:
+ WinSalGraphics& mrWinParent;
+
+ bool RenderCompatibleDC(OpenGLCompatibleDC& rWhite, OpenGLCompatibleDC& rBlack,
+ int nX, int nY, TextureCombo& rCombo);
+
+public:
+ WinOpenGLSalGraphicsImpl(WinSalGraphics& rGraphics,
+ SalGeometryProvider *mpProvider);
+
+protected:
+ virtual rtl::Reference<OpenGLContext> CreateWinContext() override;
+
+ bool RenderTextureCombo(TextureCombo const & rCombo, int nX, int nY);
+
+public:
+ virtual void Init() override;
+ virtual void copyBits( const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics ) override;
+
+ virtual bool UseTextDraw() const override { return true; }
+ virtual void PreDrawText() override;
+ virtual void PostDrawText() override;
+ virtual void DrawTextMask( CompatibleDC::Texture* rTexture, Color nMaskColor, const SalTwoRect& rPosAry ) override;
+ using OpenGLSalGraphicsImpl::DrawMask;
+ virtual void DeferredTextDraw(const CompatibleDC::Texture* pTexture, Color nMaskColor, const SalTwoRect& rPosAry) override;
+
+ virtual bool UseRenderNativeControl() const override { return true; }
+ virtual bool TryRenderCachedNativeControl(ControlCacheKey const & rControlCacheKey, int nX, int nY) override;
+ virtual bool RenderAndCacheNativeControl(CompatibleDC& rWhite, CompatibleDC& rBlack,
+ int nX, int nY , ControlCacheKey& aControlCacheKey) override;
+
+};
+
+typedef std::pair<ControlCacheKey, std::unique_ptr<TextureCombo>> OpenGLControlCachePair;
+typedef o3tl::lru_map<ControlCacheKey, std::unique_ptr<TextureCombo>, ControlCacheHashFunction> OpenGLControlCacheType;
+
+class OpenGLControlsCache {
+ OpenGLControlCacheType cache;
+
+ OpenGLControlsCache();
+
+public:
+ static OpenGLControlCacheType & get();
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/win/winlayout.hxx b/vcl/inc/opengl/win/winlayout.hxx
new file mode 100644
index 000000000..d017bc250
--- /dev/null
+++ b/vcl/inc/opengl/win/winlayout.hxx
@@ -0,0 +1,51 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_WIN_WINLAYOUT_HXX
+#define INCLUDED_VCL_INC_OPENGL_WIN_WINLAYOUT_HXX
+
+#include <win/winlayout.hxx>
+#include <opengl/PackedTextureAtlas.hxx>
+
+struct OpenGLGlobalWinGlyphCache : public GlobalWinGlyphCache
+{
+ OpenGLGlobalWinGlyphCache()
+ : maPackedTextureAtlas(2048, 2048)
+ {
+ }
+
+ PackedTextureAtlasManager maPackedTextureAtlas;
+
+ virtual bool AllocateTexture(WinGlyphDrawElement& rElement, CompatibleDC* dc) override;
+ virtual void Prune() override;
+};
+
+class OpenGLWinGlyphCache : public WinGlyphCache
+{
+public:
+ void RemoveTextures(std::vector<GLuint>& rTextureIDs);
+
+private:
+ // This class just "adds" RemoveTextures() to the base class, it's never instantiated.
+ OpenGLWinGlyphCache() = delete;
+};
+
+#endif // INCLUDED_VCL_INC_OPENGL_WIN_WINLAYOUT_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/x11/X11DeviceInfo.hxx b/vcl/inc/opengl/x11/X11DeviceInfo.hxx
new file mode 100644
index 000000000..d51de3a69
--- /dev/null
+++ b/vcl/inc/opengl/x11/X11DeviceInfo.hxx
@@ -0,0 +1,75 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_X11_X11DEVICEINFO_HXX
+#define INCLUDED_VCL_INC_OPENGL_X11_X11DEVICEINFO_HXX
+
+#include <opengl/DeviceInfo.hxx>
+
+#include <rtl/string.hxx>
+
+class X11OpenGLDeviceInfo final : public OpenGLDeviceInfo
+{
+private:
+ bool mbIsMesa;
+ bool mbIsNVIDIA;
+ bool mbIsFGLRX;
+ bool mbIsNouveau;
+ bool mbIsIntel;
+ bool mbIsOldSwrast;
+ bool mbIsLlvmpipe;
+
+ OString maVendor;
+ OString maRenderer;
+ OString maVersion;
+ OString maOS;
+ OString maOSRelease;
+
+ size_t mnGLMajorVersion;
+ size_t mnMajorVersion;
+ size_t mnMinorVersion;
+ size_t mnRevisionVersion;
+
+ void GetData();
+
+public:
+ X11OpenGLDeviceInfo();
+
+ virtual bool isDeviceBlocked() override;
+
+ const OString& GetVendor() const
+ {
+ return maVendor;
+ }
+
+ const OString& GetRenderer() const
+ {
+ return maRenderer;
+ }
+
+ const OString& GetVersion() const
+ {
+ return maVersion;
+ }
+
+ const OString& GetOS() const
+ {
+ return maOS;
+ }
+
+ const OString& GetOSRelease() const
+ {
+ return maOSRelease;
+ }
+
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/x11/cairotextrender.hxx b/vcl/inc/opengl/x11/cairotextrender.hxx
new file mode 100644
index 000000000..137022fa8
--- /dev/null
+++ b/vcl/inc/opengl/x11/cairotextrender.hxx
@@ -0,0 +1,27 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_VCL_UNX_GENERIC_GDI_OPENGLX11CAIROTEXTRENDER_HXX
+#define INCLUDED_VCL_UNX_GENERIC_GDI_OPENGLX11CAIROTEXTRENDER_HXX
+
+#include <unx/x11/x11cairotextrender.hxx>
+
+class OpenGLX11CairoTextRender final : public X11CairoTextRender
+{
+public:
+ explicit OpenGLX11CairoTextRender(X11SalGraphics& rParent);
+
+ virtual cairo_t* getCairoContext() override;
+ virtual void getSurfaceOffset(double& nDX, double& nDY) override;
+ virtual void releaseCairoContext(cairo_t* cr) override;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/x11/gdiimpl.hxx b/vcl/inc/opengl/x11/gdiimpl.hxx
new file mode 100644
index 000000000..d86af9223
--- /dev/null
+++ b/vcl/inc/opengl/x11/gdiimpl.hxx
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_X11_GDIIMPL_HXX
+#define INCLUDED_VCL_INC_OPENGL_X11_GDIIMPL_HXX
+
+#include <vcl/dllapi.h>
+
+#include <unx/salgdi.h>
+#include <unx/x11/x11gdiimpl.h>
+#include <opengl/gdiimpl.hxx>
+#include <ControlCacheKey.hxx>
+
+struct TextureCombo;
+
+class X11OpenGLSalGraphicsImpl : public OpenGLSalGraphicsImpl, public X11GraphicsImpl
+{
+private:
+ X11SalGraphics& mrX11Parent;
+
+public:
+ X11OpenGLSalGraphicsImpl( X11SalGraphics& rParent );
+ virtual ~X11OpenGLSalGraphicsImpl() override;
+
+protected:
+ virtual rtl::Reference<OpenGLContext> CreateWinContext() override;
+
+public:
+ virtual void copyBits( const SalTwoRect& rPosAry, SalGraphics* pSrcGraphics ) override;
+
+ virtual void Init() override;
+};
+
+#endif // INCLUDED_VCL_INC_OPENGL_X11_GDIIMPL_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/x11/glxtest.hxx b/vcl/inc/opengl/x11/glxtest.hxx
new file mode 100644
index 000000000..5715a6d9f
--- /dev/null
+++ b/vcl/inc/opengl/x11/glxtest.hxx
@@ -0,0 +1,21 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_X11_GLXTEST_HXX
+#define INCLUDED_VCL_INC_OPENGL_X11_GLXTEST_HXX
+
+#include <vcl/dllapi.h>
+
+VCL_DLLPUBLIC int* getGlxPipe();
+
+VCL_DLLPUBLIC pid_t* getGlxPid();
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/x11/salvd.hxx b/vcl/inc/opengl/x11/salvd.hxx
new file mode 100644
index 000000000..a77b9874e
--- /dev/null
+++ b/vcl/inc/opengl/x11/salvd.hxx
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_X11_SALVD_H
+#define INCLUDED_VCL_INC_OPENGL_X11_SALVD_H
+
+#include <memory>
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+#include <unx/saltype.h>
+#include <salvd.hxx>
+
+class SalDisplay;
+class X11OpenGLSalGraphics;
+class X11SalGraphics;
+
+class X11OpenGLSalVirtualDevice : public SalVirtualDevice
+{
+ SalDisplay *mpDisplay;
+ std::unique_ptr<X11SalGraphics>
+ mpGraphics;
+ bool mbGraphics; // is Graphics used
+ SalX11Screen mnXScreen;
+ int mnWidth;
+ int mnHeight;
+
+public:
+ X11OpenGLSalVirtualDevice( SalGraphics const *pGraphics,
+ long nDX, long nDY,
+ const SystemGraphicsData *pData,
+ std::unique_ptr<X11SalGraphics> pNewGraphics);
+ virtual ~X11OpenGLSalVirtualDevice() override;
+
+ // SalGeometryProvider
+ virtual long GetWidth() const override { return mnWidth; }
+ virtual long GetHeight() const override { return mnHeight; }
+
+ SalDisplay * GetDisplay() const { return mpDisplay; }
+ const SalX11Screen& GetXScreenNumber() const { return mnXScreen; }
+
+ virtual SalGraphics* AcquireGraphics() override;
+ virtual void ReleaseGraphics( SalGraphics* pGraphics ) override;
+
+ // Set new size, without saving the old contents
+ virtual bool SetSize( long nNewDX, long nNewDY ) override;
+};
+
+#endif // INCLUDED_VCL_INC_OPENGL_X11_SALVD_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/opengl/zone.hxx b/vcl/inc/opengl/zone.hxx
new file mode 100644
index 000000000..4bcdf15dc
--- /dev/null
+++ b/vcl/inc/opengl/zone.hxx
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_VCL_INC_OPENGL_ZONE_H
+#define INCLUDED_VCL_INC_OPENGL_ZONE_H
+
+#include <sal/config.h>
+#include <sal/types.h>
+#include <vcl/dllapi.h>
+#include <comphelper/crashzone.hxx>
+
+/**
+ * We want to be able to detect if a given crash came
+ * from the OpenGL code, so use this helper to track that.
+ */
+class VCL_DLLPUBLIC OpenGLZone : public CrashZone< OpenGLZone > {
+public:
+ static void hardDisable();
+ static void relaxWatchdogTimings();
+ static const CrashWatchdogTimingsValues& getCrashWatchdogTimingsValues();
+ static void checkDebug( int nUnchanged, const CrashWatchdogTimingsValues& aTimingValues );
+ static const char* name() { return "OpenGL"; }
+};
+
+/// Create this to not only enter the zone, but set VCL context.
+class OpenGLVCLContextZone {
+ OpenGLZone aZone;
+public:
+ OpenGLVCLContextZone();
+};
+
+class VCL_DLLPUBLIC PreDefaultWinNoOpenGLZone {
+public:
+ PreDefaultWinNoOpenGLZone();
+ ~PreDefaultWinNoOpenGLZone();
+};
+
+#endif // INCLUDED_VCL_INC_OPENGL_ZONE_H
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */