fix headless build

disables OpenGL and glew usage, lets --without-gui do what
--without-x did before and disables X related test

Change-Id: I680b47c9962a0d43c8ece593db0b82e347ceebdb
Reviewed-on: https://gerrit.libreoffice.org/23474
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Oliver Specht <oliver.specht@cib.de>
diff --git a/Repository.mk b/Repository.mk
index 423d58b..fc550d1 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -543,7 +543,6 @@ $(eval $(call gb_Helper_register_libraries_for_install,PLAINLIBS_OOO,ooo, \
	$(if $(ENABLE_GSTREAMER_1_0),avmediagst) \
	$(if $(ENABLE_GSTREAMER_0_10),avmediagst_0_10) \
	$(if $(ENABLE_DIRECTX),avmediawin) \
	$(if $(ENABLE_GLTF),avmediaogl) \
	cached1 \
	collator_data \
	comphelper \
@@ -606,6 +605,14 @@ $(eval $(call gb_Helper_register_libraries_for_install,PLAINLIBS_OOO,ooo, \
	) \
))

ifeq ($(ENABLE_OPENGL),TRUE)
ifeq ($(ENABLE_GLTF),TRUE)
$(eval $(call gb_Helper_register_libraries_for_install,PLAINLIBS_OOO,ooo, \
    avmediaogl \
))
endif
endif

ifeq ($(OS),WNT)
$(eval $(call gb_Helper_register_libraries_for_install,PLAINLIBS_OOO,activexbinarytable, \
	$(if $(DISABLE_ACTIVEX),,\
diff --git a/RepositoryExternal.mk b/RepositoryExternal.mk
index 491c398..8df085b 100644
--- a/RepositoryExternal.mk
+++ b/RepositoryExternal.mk
@@ -183,6 +183,7 @@ endef

endif # SYSTEM_CPPUNIT

ifeq ($(ENABLE_OPENGL),TRUE)
ifneq ($(SYSTEM_GLEW),)

define gb_LinkTarget__use_glew
@@ -228,6 +229,7 @@ $(call gb_ExternalProject_use_external_project,$(1),glew)
endef

endif # SYSTEM_GLEW
endif # ENABLE_OPENGL

ifneq ($(SYSTEM_GLYPHY),)

diff --git a/avmedia/Library_avmedia.mk b/avmedia/Library_avmedia.mk
index b8809f7..f091822 100644
--- a/avmedia/Library_avmedia.mk
+++ b/avmedia/Library_avmedia.mk
@@ -25,9 +25,15 @@ $(eval $(call gb_Library_add_defs,avmedia,\

$(eval $(call gb_Library_use_externals,avmedia,\
	boost_headers \
	glew \
))

ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_Library_use_externals,avmedia,\
    glew \
))
endif


$(eval $(call gb_Library_use_libraries,avmedia,\
	comphelper \
	ucbhelper \
@@ -45,10 +51,12 @@ $(eval $(call gb_Library_use_libraries,avmedia,\
))

ifeq ($(ENABLE_GLTF),TRUE)
ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_Library_add_exception_objects,avmedia,\
	avmedia/source/framework/modeltools \
))
endif
endif

ifeq ($(ENABLE_COLLADA),TRUE)

diff --git a/avmedia/Library_avmediaogl.mk b/avmedia/Library_avmediaogl.mk
index b7498bf..24133b8 100644
--- a/avmedia/Library_avmediaogl.mk
+++ b/avmedia/Library_avmediaogl.mk
@@ -7,6 +7,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_Library_Library,avmediaogl))

$(eval $(call gb_Library_set_componentfile,avmediaogl,avmedia/source/opengl/avmediaogl))
@@ -56,5 +57,5 @@ $(eval $(call gb_Library_add_libs,avmediaogl,\
    -lGL \
))
endif

endif
# vim: set noet sw=4 ts=4:
diff --git a/avmedia/Module_avmedia.mk b/avmedia/Module_avmedia.mk
index 06af36f..ff5ba90 100644
--- a/avmedia/Module_avmedia.mk
+++ b/avmedia/Module_avmedia.mk
@@ -55,7 +55,7 @@ $(eval $(call gb_Module_add_targets,avmedia,\
))
endif

ifeq ($(ENABLE_GLTF),TRUE)
ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_Module_add_targets,avmedia,\
	Library_avmediaogl \
))
diff --git a/avmedia/source/viewer/mediawindow_impl.cxx b/avmedia/source/viewer/mediawindow_impl.cxx
index 6206abb..ecd282d 100644
--- a/avmedia/source/viewer/mediawindow_impl.cxx
+++ b/avmedia/source/viewer/mediawindow_impl.cxx
@@ -39,8 +39,9 @@
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/media/XManager.hpp>
#include <vcl/sysdata.hxx>
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLContext.hxx>

#endif
using namespace ::com::sun::star;

namespace avmedia { namespace priv {
@@ -223,11 +224,13 @@ uno::Reference<media::XPlayer> MediaWindowImpl::createPlayer(const OUString& rUR
        }
    }
#if HAVE_FEATURE_GLTF
#if HAVE_FEATURE_OPENGL
    else if ( *pMimeType == AVMEDIA_MIMETYPE_JSON )
    {
        xPlayer = createPlayer(rURL, AVMEDIA_OPENGL_MANAGER_SERVICE_NAME, xContext);
    }
#endif
#endif

    return xPlayer;
}
diff --git a/canvas/source/factory/cf_service.cxx b/canvas/source/factory/cf_service.cxx
index e29a7fe..3aa53db 100644
--- a/canvas/source/factory/cf_service.cxx
+++ b/canvas/source/factory/cf_service.cxx
@@ -39,7 +39,10 @@
#include <osl/mutex.hxx>
#include <osl/process.h>
#include <o3tl/functional.hxx>
#include <config_features.h>
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLWrapper.hxx>
#endif

using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -309,8 +312,10 @@ Reference<XInterface> CanvasFactory::lookupAndUse(
                     "ForceSafeServiceImpl" );

    // tdf#93870 - force VCL canvas in OpenGL mode for now.
#if HAVE_FEATURE_OPENGL
    if( OpenGLWrapper::isVCLOpenGLEnabled() )
        bForceLastEntry = true;
#endif

    // use anti-aliasing canvas, if config flag set (or not existing)
    bool bUseAAEntry(true);
diff --git a/chart2/Library_chartcore.mk b/chart2/Library_chartcore.mk
index ce2043a..99d3c33 100644
--- a/chart2/Library_chartcore.mk
+++ b/chart2/Library_chartcore.mk
@@ -28,9 +28,14 @@ $(eval $(call gb_Library_set_precompiled_header,chartcore,$(SRCDIR)/chart2/inc/p
$(eval $(call gb_Library_use_externals,chartcore,\
	boost_headers \
	glm_headers \
	glew \
))

ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_Library_use_externals,chartcore,\
    glew \
))
endif

$(eval $(call gb_Library_use_custom_headers,chartcore,\
	officecfg/registry \
))
@@ -82,7 +87,6 @@ $(eval $(call gb_Library_add_exception_objects,chartcore,\
    chart2/source/view/axes/VPolarCoordinateSystem \
    chart2/source/view/axes/VPolarGrid \
    chart2/source/view/axes/VPolarRadiusAxis \
    chart2/source/view/charttypes/GL3DBarChart \
    chart2/source/view/charttypes/AreaChart \
    chart2/source/view/charttypes/BarChart \
    chart2/source/view/charttypes/BarPositionHelper \
@@ -94,14 +98,11 @@ $(eval $(call gb_Library_add_exception_objects,chartcore,\
    chart2/source/view/charttypes/Splines \
    chart2/source/view/charttypes/VSeriesPlotter \
    chart2/source/view/diagram/VDiagram \
    chart2/source/view/main/3DChartObjects \
    chart2/source/view/main/ChartItemPool \
    chart2/source/view/main/ChartView \
    chart2/source/view/main/Clipping \
    chart2/source/view/main/DataPointSymbolSupplier \
    chart2/source/view/main/DrawModelWrapper \
    chart2/source/view/main/GL3DPlotterBase \
    chart2/source/view/main/GL3DRenderer \
    chart2/source/view/main/LabelPositionHelper \
    chart2/source/view/main/Linear3DTransformation \
    chart2/source/view/main/PlotterBase \
@@ -118,6 +119,14 @@ $(eval $(call gb_Library_add_exception_objects,chartcore,\
    chart2/source/view/main/VPolarTransformation \
    chart2/source/view/main/VTitle \
))
ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_Library_add_exception_objects,chartcore,\
    chart2/source/view/main/3DChartObjects \
    chart2/source/view/main/GL3DPlotterBase \
    chart2/source/view/main/GL3DRenderer \
    chart2/source/view/charttypes/GL3DBarChart \
))
endif

# model pieces ...
$(eval $(call gb_Library_add_exception_objects,chartcore,\
@@ -256,9 +265,14 @@ $(eval $(call gb_Library_use_system_darwin_frameworks,chartcore,\
else ifeq ($(OS), $(filter LINUX %BSD SOLARIS, $(OS)))
$(eval $(call gb_Library_add_libs,chartcore,\
	$(DLOPEN_LIBS) \
	-lGL \
	-lX11 \
))
ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_Library_add_libs,chartcore,\
    -lGL \
    -lX11 \
))
endif #ENABLE_OPENGL

endif

# vim: set noet sw=4 ts=4:
diff --git a/chart2/Module_chart2.mk b/chart2/Module_chart2.mk
index dedb5d7..3b32e1c 100644
--- a/chart2/Module_chart2.mk
+++ b/chart2/Module_chart2.mk
@@ -12,9 +12,13 @@ $(eval $(call gb_Module_Module,chart2))
$(eval $(call gb_Module_add_targets,chart2,\
    Library_chartcontroller \
    Library_chartcore \
    Library_chartopengl \
    Package_opengl \
))
ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_Module_add_targets,chart2,\
     Library_chartopengl \
     Package_opengl \
 ))
endif

$(eval $(call gb_Module_add_l10n_targets,chart2,\
    AllLangResTarget_chartcontroller \
diff --git a/chart2/source/controller/main/ChartWindow.cxx b/chart2/source/controller/main/ChartWindow.cxx
index 1c6d6ae..25bdc33 100644
--- a/chart2/source/controller/main/ChartWindow.cxx
+++ b/chart2/source/controller/main/ChartWindow.cxx
@@ -24,7 +24,7 @@
#include <vcl/help.hxx>
#include <vcl/openglwin.hxx>
#include <vcl/settings.hxx>

#include <config_features.h>
#include <com/sun/star/chart2/X3DChartWindowProvider.hpp>

using namespace ::com::sun::star;
@@ -49,7 +49,11 @@ ChartWindow::ChartWindow( ChartController* pController, vcl::Window* pParent, Wi
        : Window(pParent, nStyle)
        , m_pWindowController( pController )
        , m_bInPaint(false)
#if HAVE_FEATURE_OPENGL
        , m_pOpenGLWindow(VclPtr<OpenGLWindow>::Create(this))
#else
        , m_pOpenGLWindow(nullptr)
#endif
{
    this->SetHelpId( HID_SCH_WIN_DOCUMENT );
    this->SetMapMode( MapMode(MAP_100TH_MM) );
diff --git a/chart2/source/model/template/ChartTypeManager.cxx b/chart2/source/model/template/ChartTypeManager.cxx
index adee48e..a8b96e4 100644
--- a/chart2/source/model/template/ChartTypeManager.cxx
+++ b/chart2/source/model/template/ChartTypeManager.cxx
@@ -33,7 +33,10 @@
#include "StockChartTypeTemplate.hxx"
#include "NetChartTypeTemplate.hxx"
#include "BubbleChartTypeTemplate.hxx"
#include <config_features.h>
#if HAVE_FEATURE_OPENGL
#include "GL3DBarChartTypeTemplate.hxx"
#endif
#include <cppuhelper/component_context.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <comphelper/InlineContainer.hxx>
@@ -534,14 +537,16 @@ uno::Reference< uno::XInterface > SAL_CALL ChartTypeManager::createInstance(
            case TEMPLATE_BUBBLE:
                xTemplate.set( new BubbleChartTypeTemplate( m_xContext, aServiceSpecifier ));
                break;

#if HAVE_FEATURE_OPENGL
            case TEMPLATE_GL3DBAR:
                xTemplate.set(new GL3DBarChartTypeTemplate(m_xContext, aServiceSpecifier));
                break;
            case TEMPLATE_GL3DBAR_ROUNDED_RECTANGLE:
                xTemplate.set(new GL3DBarChartTypeTemplate(m_xContext, aServiceSpecifier));
                break;

#else
            default: break;
#endif
//            case TEMPLATE_SURFACE:
//            case TEMPLATE_ADDIN:
//               break;
diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx
index fc524b5..c9aba8d 100644
--- a/chart2/source/view/main/ChartView.cxx
+++ b/chart2/source/view/main/ChartView.cxx
@@ -50,8 +50,9 @@
#include "DateHelper.hxx"
#include "defines.hxx"
#include <unonames.hxx>
#if HAVE_FEATURE_OPENGL
#include <GL3DBarChart.hxx>

#endif
#include <editeng/frmdiritem.hxx>
#include <rtl/uuid.h>
#include <tools/globname.hxx>
@@ -68,8 +69,9 @@
#include <osl/mutex.hxx>
#include <svx/unofill.hxx>
#include <vcl/openglwin.hxx>
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLContext.hxx>

#endif
#include <drawinglayer/XShapeDumper.hxx>

#include <time.h>
@@ -1093,8 +1095,10 @@ GL2DRenderer::GL2DRenderer(ChartView* pView):
GL2DRenderer::~GL2DRenderer()
{
    SolarMutexGuard g;
#if HAVE_FEATURE_OPENGL
    if(!mbContextDestroyed && mpWindow)
        mpWindow->setRenderer(nullptr);
#endif
    mpWindow.reset();
}

@@ -1132,6 +1136,7 @@ void GL2DRenderer::updateOpenGLWindow()
        return;

    OpenGLWindow* pWindow = mpView->mrChartModel.getOpenGLWindow();
#if HAVE_FEATURE_OPENGL
    if(pWindow != mpWindow)
    {
        if(mpWindow)
@@ -1144,6 +1149,7 @@ void GL2DRenderer::updateOpenGLWindow()
            pWindow->setRenderer(this);
        }
    }
#endif
    mpWindow = pWindow;
}

@@ -2593,8 +2599,11 @@ void ChartView::impl_refreshAddIn()
bool ChartView::isReal3DChart()
{
    uno::Reference< XDiagram > xDiagram( mrChartModel.getFirstDiagram() );

#if HAVE_FEATURE_OPENGL
    return ChartHelper::isGL3DDiagram(xDiagram);
#else
    return false;
#endif
}

static const char* envChartDummyFactory = getenv("CHART_DUMMY_FACTORY");
@@ -2637,7 +2646,7 @@ void ChartView::createShapes()
    }
    pShapeFactory->setPageSize(mxRootShape, aPageSize);
    pShapeFactory->clearPage(mxRootShape);

#if HAVE_FEATURE_OPENGL
#if HAVE_FEATURE_DESKTOP
    if(isReal3DChart())
    {
@@ -2654,6 +2663,7 @@ void ChartView::createShapes()
            pWindow->Show(false);
    }
#endif
#endif

    createShapes2D(aPageSize);

@@ -2672,6 +2682,7 @@ void ChartView::createShapes()

void ChartView::render()
{
#if HAVE_FEATURE_OPENGL
    if(!isReal3DChart())
    {
        AbstractShapeFactory* pShapeFactory = AbstractShapeFactory::getOrCreateShapeFactory(m_xShapeFactory);
@@ -2685,6 +2696,7 @@ void ChartView::render()
            pShapeFactory->postRender(pWindow);
        }
    }
#endif
}

// util::XEventListener (base of XCloseListener)
@@ -3371,6 +3383,7 @@ void ChartView::createShapes3D()

    uno::Reference< XChartType > xChartType( aChartTypeList[0] );

#if HAVE_FEATURE_OPENGL
    if (!m_pGL3DPlotter)
    {
        m_pGL3DPlotter.reset(new GL3DBarChart(xChartType, pWindow));
@@ -3381,6 +3394,7 @@ void ChartView::createShapes3D()
        if (pChart)
            pChart->setOpenGLWindow(pWindow);
    }
#endif

    uno::Reference< XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY );
    OSL_ASSERT( xDataSeriesContainer.is());
@@ -3400,9 +3414,11 @@ void ChartView::createShapes3D()

    std::unique_ptr<ExplicitCategoriesProvider> pCatProvider(new ExplicitCategoriesProvider(xCooSys, mrChartModel));

#if HAVE_FEATURE_OPENGL
    m_pGL3DPlotter->create3DShapes(aDataSeries, *pCatProvider);

    m_pGL3DPlotter->render();
#endif
}

void ChartView::updateOpenGLWindow()
diff --git a/config_host/config_features.h.in b/config_host/config_features.h.in
index d80d134..0aa1d67 100644
--- a/config_host/config_features.h.in
+++ b/config_host/config_features.h.in
@@ -152,8 +152,18 @@
#define HAVE_FEATURE_BREAKPAD 0

/*
 * Whether to enable ATL
 */
 *  * Whether to enable ATL
 *   */
#define HAVE_FEATURE_ATL 0

/*
 *  Whether OpenGL is enabled
 *   */
#define HAVE_FEATURE_OPENGL 0

/*
 * Whether User Interface is available
 */
#define HAVE_FEATURE_UI 1

#endif
diff --git a/configure.ac b/configure.ac
index c81bd1a..7a2ec3b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3760,7 +3760,6 @@ if test "$_os" = "WINNT" -a "$WITH_MINGW" != yes; then
    AC_MSG_CHECKING([whether to use ATL])
    if test "$enable_atl" = "yes" -o "$enable_atl" = "" -a "$vcexpress" != Express; then
        DISABLE_ATL=""
        AC_DEFINE(HAVE_FEATURE_ATL, 1)
        AC_MSG_RESULT([yes])
    else
        DISABLE_ATL="TRUE"
@@ -4572,12 +4571,17 @@ if test "$with_x" = "no"; then
    AC_MSG_ERROR([Use --disable-gui instead. How can we get rid of this option? No idea where it comes from.])
fi

ENABLE_HEADLESS=""
if test "$enable_gui" = "no"; then
    if test "$USING_X11" != TRUE; then
        AC_MSG_ERROR([$host_os operating system is not suitable to build LibreOffice with --disable-gui.])
    fi
    USING_X11=
    ENABLE_HEADLESS=TRUE
    AC_DEFINE(HAVE_FEATURE_UI,0)
    test_cairo=yes
fi
AC_SUBST(ENABLE_HEADLESS)

WORKDIR="${BUILDDIR}/workdir"
INSTDIR="${BUILDDIR}/instdir"
@@ -10138,13 +10142,6 @@ if test "x$enable_kde4" = "xyes"; then
fi
AC_SUBST(ENABLE_KDE4)

ENABLE_HEADLESS=""
if test "x$with_x" = "xno" -o "$CXX" = "emcc"; then
    ENABLE_HEADLESS="TRUE"
    SCPDEFS="$SCPDEFS -DLIBO_HEADLESS"
    R="headless"
fi
AC_SUBST(ENABLE_HEADLESS)

build_vcl_plugins="$R"
if test -z "$build_vcl_plugins"; then
@@ -10431,16 +10428,18 @@ if test $_os = iOS -o $_os = Android; then
elif test "$_os" = "Darwin"; then
    # We use frameworks on Mac OS X, no need for detail checks
    ENABLE_OPENGL=TRUE
    AC_DEFINE(HAVE_FEATURE_OPENGL,1)
    ENABLE_OPENGL_CANVAS=TRUE
elif test $_os = WINNT; then
    ENABLE_OPENGL=TRUE
    AC_DEFINE(HAVE_FEATURE_OPENGL,1)
    ENABLE_OPENGL_CANVAS=TRUE
else
    if test "$USING_X11" = TRUE; then
        ENABLE_OPENGL=TRUE
        AC_CHECK_LIB(GL, glBegin, [:], AC_MSG_ERROR([libGL required.]))
        AC_DEFINE(HAVE_FEATURE_OPENGL,1)
        ENABLE_OPENGL_CANVAS=TRUE
    fi
    ENABLE_OPENGL_CANVAS=TRUE
fi

AC_SUBST(ENABLE_OPENGL)
diff --git a/cui/Library_cui.mk b/cui/Library_cui.mk
index 86cc379..427e5fa 100644
--- a/cui/Library_cui.mk
+++ b/cui/Library_cui.mk
@@ -69,8 +69,12 @@ $(eval $(call gb_Library_use_externals,cui,\
	boost_headers \
    icuuc \
    icu_headers \
    glew \
))
ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_Library_use_externals,cui,\
     glew \
 ))
endif

ifeq ($(OS),WNT)
$(eval $(call gb_Library_use_system_win32_libs,cui,\
diff --git a/cui/source/options/optgdlg.cxx b/cui/source/options/optgdlg.cxx
index f4d4d5c..b4da71f 100644
--- a/cui/source/options/optgdlg.cxx
+++ b/cui/source/options/optgdlg.cxx
@@ -17,6 +17,7 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <config_features.h>
#include <svl/zforlist.hxx>
#include <svl/currencytable.hxx>
#include <svtools/grfmgr.hxx>
@@ -89,8 +90,9 @@
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <vcl/IconThemeInfo.hxx>
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLWrapper.hxx>

#endif
#include "optgdlg.hxx"
#include <svx/ofaitem.hxx>
#include <svtools/apearcfg.hxx>
@@ -511,10 +513,13 @@ CanvasSettings::CanvasSettings() :

bool CanvasSettings::IsHardwareAccelerationAvailable() const
{
#if HAVE_FEATURE_OPENGL
    if( OpenGLWrapper::isVCLOpenGLEnabled() )
        mbHWAccelAvailable = false;

    else if( !mbHWAccelChecked )
    else
#endif
        if( !mbHWAccelChecked )
    {
        mbHWAccelChecked = true;

@@ -980,7 +985,11 @@ void OfaViewTabPage::UpdateOGLStatus()
    if (Application::GetToolkitName() == "gtk3")
        return;
    // Easier than a custom translation string.
#if HAVE_FEATURE_OPENGL
    bool bEnabled = OpenGLWrapper::isVCLOpenGLEnabled();
#else
    bool bEnabled = false;
#endif
    m_pOpenGLStatusEnabled->Show(bEnabled);
    m_pOpenGLStatusDisabled->Show(!bEnabled);
}
diff --git a/desktop/Library_sofficeapp.mk b/desktop/Library_sofficeapp.mk
index d24f615..30dc907 100644
--- a/desktop/Library_sofficeapp.mk
+++ b/desktop/Library_sofficeapp.mk
@@ -140,6 +140,13 @@ $(eval $(call gb_Library_add_exception_objects,sofficeapp,\
	desktop/source/lib/lokclipboard \
))
endif
ifeq ($(ENABLE_HEADLESS),TRUE)
$(eval $(call gb_Library_add_exception_objects,sofficeapp,\
    desktop/source/lib/init \
    desktop/source/lib/lokinteractionhandler \
    desktop/source/lib/lokclipboard \
))
endif
endif

ifeq ($(ENABLE_TELEPATHY),TRUE)
diff --git a/desktop/source/app/sofficemain.cxx b/desktop/source/app/sofficemain.cxx
index 21f1e0c..f850cff 100644
--- a/desktop/source/app/sofficemain.cxx
+++ b/desktop/source/app/sofficemain.cxx
@@ -95,7 +95,10 @@ extern "C" int DESKTOP_DLLPUBLIC soffice_main()
    /* Run test for OpenGL support in own process to avoid crash with broken
     * OpenGL drivers. Start process as early as possible.
     */
    bool bSuccess = fire_glxtest_process();
    bool bSuccess = false;
#if HAVE_FEATURE_OPENGL
    bSuccess = fire_glxtest_process();
#endif
    SAL_WARN_IF(!bSuccess, "desktop.opengl", "problems with glxtest");
#endif

diff --git a/external/cairo/ExternalProject_cairo.mk b/external/cairo/ExternalProject_cairo.mk
index 6bbe957..c826dcb 100644
--- a/external/cairo/ExternalProject_cairo.mk
+++ b/external/cairo/ExternalProject_cairo.mk
@@ -37,7 +37,8 @@ $(call gb_ExternalProject_get_state_target,cairo,build) :
	$(call gb_ExternalProject_run,build,\
	./configure \
		$(if $(debug),STRIP=" ") \
		CFLAGS="$(if $(debug),-g) $(ZLIB_CFLAGS) $(gb_VISIBILITY_FLAGS)" \
		$(if $(filter ANDROID IOS,$(OS)),CFLAGS="$(if $(debug),-g) $(ZLIB_CFLAGS) $(gb_VISIBILITY_FLAGS)") \
		$(if $(filter-out ANDROID IOS,$(OS)),CFLAGS="$(if $(debug),-g) $(ZLIB_CFLAGS)" ) \
		$(if $(filter ANDROID IOS,$(OS)),PKG_CONFIG=./dummy_pkg_config) \
		pixman_CFLAGS="-I$(call gb_UnpackedTarball_get_dir,pixman)/pixman" \
		pixman_LIBS="-L$(call gb_UnpackedTarball_get_dir,pixman)/pixman/.libs -lpixman-1" \
@@ -45,8 +46,8 @@ $(call gb_ExternalProject_get_state_target,cairo,build) :
		ZLIB3RDLIB="$(if $(SYSTEM_ZLIB),,-L$(WORKDIR)/LinkTarget/StaticLibrary) -lz" \
		png_REQUIRES="trick_configure_into_using_png_CFLAGS_and_LIBS" \
		png_CFLAGS="$(LIBPNG_CFLAGS)" png_LIBS="$(LIBPNG_LIBS)" \
		$(if $(SYSTEM_FREETYPE),,FREETYPE_CFLAGS="-I$(call gb_UnpackedTarball_get_dir,freetype)/include") \
		FONTCONFIG_CFLAGS="-I$(call gb_UnpackedTarball_get_dir,fontconfig)" \
		$(if $(SYSTEM_FREETYPE,),FREETYPE_CFLAGS="-I$(call gb_UnpackedTarball_get_dir,freetype)/include") \
		$(if $(SYSTEM_FONTCONFIG,),FONTCONFIG_CFLAGS="-I$(call gb_UnpackedTarball_get_dir,fontconfig)") \
		$(if $(filter IOS,$(OS)),--disable-shared,--disable-static) \
		$(if $(filter ANDROID,$(OS)),--disable-shared,--disable-static) \
		$(if $(filter ANDROID IOS,$(OS)),--disable-xlib,--enable-xlib) \
diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index f31eab2..1fb4f9b 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -20,6 +20,7 @@
#ifndef INCLUDED_VCL_OUTDEV_HXX
#define INCLUDED_VCL_OUTDEV_HXX

#include <config_features.h>
#include <tools/gen.hxx>
#include <tools/solar.h>
#include <tools/rc.hxx>
@@ -612,6 +613,7 @@ public:
     * the underlying SalGraphics and it's implementation
     * changing.
     */
#if HAVE_FEATURE_OPENGL
    class PaintScope {
        void *pHandle;
    public:
@@ -619,7 +621,7 @@ public:
        ~PaintScope();
        void flush();
    };

#endif
protected:

    virtual void                CopyDeviceArea( SalTwoRect& aPosAry, bool bWindowInvalidate = false);
diff --git a/postprocess/Rdb_services.mk b/postprocess/Rdb_services.mk
index 51c9eba..8f3405b 100644
--- a/postprocess/Rdb_services.mk
+++ b/postprocess/Rdb_services.mk
@@ -229,7 +229,7 @@ $(eval $(call gb_Rdb_add_components,services,\
		wizards/com/sun/star/wizards/report/report \
		wizards/com/sun/star/wizards/table/table \
	) \
	$(if $(ENABLE_GLTF), \
    $(if $(ENABLE_OPENGL), \
		$(call gb_Helper_optional,AVMEDIA,avmedia/source/opengl/avmediaogl) \
	) \
))
diff --git a/sd/source/ui/func/fuinsert.cxx b/sd/source/ui/func/fuinsert.cxx
index c26054d..01a795a 100644
--- a/sd/source/ui/func/fuinsert.cxx
+++ b/sd/source/ui/func/fuinsert.cxx
@@ -816,8 +816,9 @@ void FuInsert3DModel::DoExecute( SfxRequest& )
            aPos.X() -= aSize.Width() >> 1;
            aPos.Y() -= aSize.Height() >> 1;
        }

#if HAVE_FEATURE_OPENGL
        mpView->Insert3DModelURL( sURL, nAction, aPos, aSize ) ;
#endif

        if( mpWindow )
            mpWindow->LeaveWait();
diff --git a/sd/source/ui/view/sdview4.cxx b/sd/source/ui/view/sdview4.cxx
index d68de3a..b76b871 100644
--- a/sd/source/ui/view/sdview4.cxx
+++ b/sd/source/ui/view/sdview4.cxx
@@ -292,7 +292,7 @@ void View::InsertMediaURL( const OUString& rMediaURL, sal_Int8& rAction,

    InsertMediaObj( realURL, "application/vnd.sun.star.media", rAction, rPos, rSize );
}

#if HAVE_FEATURE_OPENGL
#if HAVE_FEATURE_GLTF
void View::Insert3DModelURL(
    const OUString& rModelURL, sal_Int8& rAction,
@@ -311,6 +311,7 @@ void View::Insert3DModelURL(
    pRetObject->setMediaProperties(aItem);
}
#endif
#endif

SdrMediaObj* View::InsertMediaObj( const OUString& rMediaURL, const OUString& rMimeType, sal_Int8& rAction,
                                   const Point& rPos, const Size& rSize )
diff --git a/slideshow/Library_slideshow.mk b/slideshow/Library_slideshow.mk
index af28616..3834dfdc 100644
--- a/slideshow/Library_slideshow.mk
+++ b/slideshow/Library_slideshow.mk
@@ -28,8 +28,12 @@ $(eval $(call gb_Library_set_precompiled_header,slideshow,$(SRCDIR)/slideshow/in

$(eval $(call gb_Library_use_externals,slideshow,\
	boost_headers \
	glew \
))
ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_Library_use_externals,slideshow,\
     glew \
 ))
endif

$(eval $(call gb_Library_use_sdk_api,slideshow))

diff --git a/slideshow/Module_slideshow.mk b/slideshow/Module_slideshow.mk
index 5d9978b..01d1058 100644
--- a/slideshow/Module_slideshow.mk
+++ b/slideshow/Module_slideshow.mk
@@ -10,10 +10,14 @@
$(eval $(call gb_Module_Module,slideshow))

$(eval $(call gb_Module_add_targets,slideshow,\
    $(if $(filter TRUE,$(ENABLE_OPENGL)),Library_OGLTrans) \
    Library_slideshow \
	Package_opengl \
))
ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_Module_add_targets,slideshow,\
    Library_OGLTrans \
    Package_opengl \
 ))
endif

# not working
    # CppunitTest_slideshow \
diff --git a/slideshow/source/engine/shapes/viewmediashape.cxx b/slideshow/source/engine/shapes/viewmediashape.cxx
index 4a21f1a..2fc4ea2 100644
--- a/slideshow/source/engine/shapes/viewmediashape.cxx
+++ b/slideshow/source/engine/shapes/viewmediashape.cxx
@@ -46,7 +46,9 @@
#include <avmedia/mediawindow.hxx>
#include <avmedia/modeltools.hxx>

#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLContext.hxx>
#endif

#include <com/sun/star/media/XManager.hpp>
#include <com/sun/star/media/XPlayer.hpp>
@@ -449,7 +451,7 @@ namespace slideshow
                                                                  rRangePix.getMinY(),
                                                                    rRangePix.getMaxX() - rRangePix.getMinX(),
                                                                    rRangePix.getMaxY() - rRangePix.getMinY() );
#if !HAVE_FEATURE_GLTF
#if !HAVE_FEATURE_GLTF || !HAVE_FEATURE_OPENGL
                            (void)rMimeType;
#else
                            if( avmedia::IsModel(rMimeType) )
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index 3ac82ba..40db407 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -84,9 +84,13 @@ $(eval $(call gb_Library_use_externals,svxcore,\
	boost_headers \
	icuuc \
	icu_headers \
	glew \
	libxml2 \
))
ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_Library_use_externals,svxcore,\
     glew \
 ))
endif

ifeq ($(OS),MACOSX)

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index f6b9d74..135e1e9 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -90,6 +90,7 @@
#include <comphelper/propertysequence.hxx>
#include <sfx2/classificationhelper.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <config_features.h>

static const char* DATA_DIRECTORY = "/sw/qa/extras/uiwriter/data/";

@@ -173,7 +174,9 @@ public:
    void testUnicodeNotationToggle();
    void testTextTableCellNames();
    void testShapeAnchorUndo();
#if HAVE_FEATURE_UI
    void testDde();
#endif
    void testDocModState();
    void testTdf94804();
    void testTdf34957();
@@ -267,7 +270,9 @@ public:
    CPPUNIT_TEST(testUnicodeNotationToggle);
    CPPUNIT_TEST(testTextTableCellNames);
    CPPUNIT_TEST(testShapeAnchorUndo);
#if HAVE_FEATURE_UI
    CPPUNIT_TEST(testDde);
#endif
    CPPUNIT_TEST(testDocModState);
    CPPUNIT_TEST(testTdf94804);
    CPPUNIT_TEST(testTdf34957);
@@ -3057,7 +3062,7 @@ void lcl_dispatchCommand(const uno::Reference<lang::XComponent>& xComponent, con

    xDispatchHelper->executeDispatch(xFrame, rCommand, OUString(), 0, rPropertyValues);
}

#if HAVE_FEATURE_UI
void SwUiWriterTest::testDde()
{
    // Type asdf and copy it.
@@ -3081,7 +3086,7 @@ void SwUiWriterTest::testDde()
    CPPUNIT_ASSERT_EQUAL(OUString("TextField"), getProperty<OUString>(xField, "TextPortionType"));
    CPPUNIT_ASSERT(xField->getString().endsWith("asdf"));
}

#endif
//IdleTask class to add a low priority Idle task
class IdleTask
{
diff --git a/toolkit/Library_tk.mk b/toolkit/Library_tk.mk
index 1136e2e..ecb376e 100644
--- a/toolkit/Library_tk.mk
+++ b/toolkit/Library_tk.mk
@@ -23,9 +23,13 @@ $(eval $(call gb_Library_set_componentfile,tk,toolkit/util/tk))

$(eval $(call gb_Library_use_externals,tk,\
    boost_headers \
    glew \
))

ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_Library_use_externals,tk,\
    glew \
))
endif
$(eval $(call gb_Library_set_include,tk,\
    $$(INCLUDE) \
    -I$(SRCDIR)/toolkit/inc \
diff --git a/toolkit/source/awt/vclxtoolkit.cxx b/toolkit/source/awt/vclxtoolkit.cxx
index c72c1b6..45a6063 100644
--- a/toolkit/source/awt/vclxtoolkit.cxx
+++ b/toolkit/source/awt/vclxtoolkit.cxx
@@ -22,6 +22,7 @@
#include <prewin.h>
#include <postwin.h>
#endif
#include <config_features.h>
#include <com/sun/star/awt/WindowAttribute.hpp>
#include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
#include <com/sun/star/awt/WindowClass.hpp>
@@ -113,7 +114,9 @@
#include <vcl/window.hxx>
#include <vcl/wrkwin.hxx>
#include <vcl/throbber.hxx>
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLWrapper.hxx>
#endif
#include "toolkit/awt/vclxspinbutton.hxx"
#include <tools/debug.hxx>
#include <comphelper/processfactory.hxx>
@@ -1922,7 +1925,11 @@ void SAL_CALL VCLXToolkit::processEventsToIdle()
sal_Int64 SAL_CALL VCLXToolkit::getOpenGLBufferSwapCounter()
    throw (css::uno::RuntimeException, std::exception)
{
#if HAVE_FEATURE_OPENGL
     return OpenGLWrapper::getBufferSwapCounter();
#else
     return 0;
#endif
}

// css:awt:XToolkitRobot
diff --git a/vcl/CppunitTest_vcl_bitmap_test.mk b/vcl/CppunitTest_vcl_bitmap_test.mk
index a65ddb3..1104181 100644
--- a/vcl/CppunitTest_vcl_bitmap_test.mk
+++ b/vcl/CppunitTest_vcl_bitmap_test.mk
@@ -15,9 +15,13 @@ $(eval $(call gb_CppunitTest_add_exception_objects,vcl_bitmap_test, \

$(eval $(call gb_CppunitTest_use_externals,vcl_bitmap_test,\
	boost_headers \
	glew \
	glm_headers \
))
ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_CppunitTest_use_externals,vcl_bitmap_test,\
     glew \
 ))
endif

$(eval $(call gb_CppunitTest_set_include,vcl_bitmap_test,\
    $$(INCLUDE) \
diff --git a/vcl/Executable_icontest.mk b/vcl/Executable_icontest.mk
index 9a9a929..58efd05 100644
--- a/vcl/Executable_icontest.mk
+++ b/vcl/Executable_icontest.mk
@@ -11,9 +11,13 @@ $(eval $(call gb_Executable_Executable,icontest))

$(eval $(call gb_Executable_use_externals,icontest,\
    boost_headers \
    glew \
	glm_headers \
))
ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_Executable_use_externals,icontest,\
    glew \
))
endif

$(eval $(call gb_Executable_use_api,icontest,\
    offapi \
diff --git a/vcl/Executable_vcldemo.mk b/vcl/Executable_vcldemo.mk
index 834dc8d..6003ecd 100644
--- a/vcl/Executable_vcldemo.mk
+++ b/vcl/Executable_vcldemo.mk
@@ -17,9 +17,13 @@ $(eval $(call gb_Executable_use_api,vcldemo,\

$(eval $(call gb_Executable_use_externals,vcldemo,\
	boost_headers \
	glew \
	glm_headers \
))
ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_Executable_use_externals,vcldemo,\
    glew \
))
endif

$(eval $(call gb_Executable_set_include,vcldemo,\
    $$(INCLUDE) \
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 0ae7564..0592dd5 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -113,7 +113,6 @@ endif
$(eval $(call gb_Library_use_externals,vcl,\
	boost_headers \
	gio \
	glew \
	glm_headers \
	harfbuzz \
	icu_headers \
@@ -121,20 +120,14 @@ $(eval $(call gb_Library_use_externals,vcl,\
	lcms2 \
	mdds_headers \
))
ifeq ($(ENABLE_OPENGL),TRUE)
$(eval $(call gb_Library_use_externals,vcl,\
     glew \
 ))
endif

$(eval $(call gb_Library_add_exception_objects,vcl,\
	vcl/opengl/DeviceInfo \
	vcl/opengl/gdiimpl \
	vcl/opengl/salbmp \
	vcl/opengl/scale \
	vcl/opengl/framebuffer \
	vcl/opengl/program \
	vcl/opengl/texture \
	vcl/opengl/FixedTextureAtlas \
    vcl/source/opengl/OpenGLContext \
    vcl/source/opengl/OpenGLHelper \
    vcl/source/window/cairo_cairo \
    vcl/source/window/openglwin \
    vcl/source/window/settings \
    vcl/source/window/paint \
    vcl/source/window/resource \
@@ -613,9 +606,32 @@ $(eval $(call gb_Library_use_externals,vcl,\
	freetype \
))
ifneq ($(OS),EMSCRIPTEN)
	$(eval $(call gb_Library_use_externals,vcl,\
		fontconfig \
	))
$(eval $(call gb_Library_use_externals,vcl,\
	fontconfig \
))
endif
else
 $(eval $(call gb_Library_add_exception_objects,vcl,\
	vcl/opengl/DeviceInfo \
	vcl/opengl/gdiimpl \
	vcl/opengl/salbmp \
	vcl/opengl/scale \
	vcl/opengl/framebuffer \
	vcl/opengl/program \
	vcl/opengl/texture \
	vcl/opengl/FixedTextureAtlas \
    vcl/source/opengl/OpenGLContext \
    vcl/source/opengl/OpenGLHelper \
    vcl/source/window/openglwin \
 ))
ifeq ($(OS),LINUX)
$(eval $(call gb_Library_add_libs,vcl,\
	-lm \
	-ldl \
	-lpthread \
    -lGL \
    -lX11 \
))
endif
endif

@@ -727,11 +743,12 @@ $(eval $(call gb_Library_add_libs,vcl,\
    -lX11 \
	-lXext \
))

ifneq ($(ENABLE_HEADLESS),TRUE)
$(eval $(call gb_Library_add_exception_objects,vcl,\
	vcl/opengl/x11/X11DeviceInfo \
))
endif
endif

# Runtime dependency for unit-tests
$(eval $(call gb_Library_use_restarget,vcl,vcl))
diff --git a/vcl/headless/headlessinst.cxx b/vcl/headless/headlessinst.cxx
index a8c3085..a1c1da3 100644
--- a/vcl/headless/headlessinst.cxx
+++ b/vcl/headless/headlessinst.cxx
@@ -8,7 +8,7 @@
 */
#include <headless/svpinst.hxx>
#include <headless/svpdummies.hxx>
#include <generic/gendata.hxx>
#include <unx/gendata.hxx>

class HeadlessSalInstance : public SvpSalInstance
{
diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx
index 15c6f7b..e1292ce 100644
--- a/vcl/headless/svpgdi.cxx
+++ b/vcl/headless/svpgdi.cxx
@@ -36,9 +36,11 @@

#include <cairo.h>

#if CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 10, 0)
#if ENABLE_CAIRO_CANVAS
#if defined CAIRO_VERSION && CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 10, 0)
#   define CAIRO_OPERATOR_DIFFERENCE (static_cast<cairo_operator_t>(23))
#endif
#endif

namespace
{
diff --git a/vcl/inc/unx/salgdi.h b/vcl/inc/unx/salgdi.h
index b7aac7a..9b77c70 100644
--- a/vcl/inc/unx/salgdi.h
+++ b/vcl/inc/unx/salgdi.h
@@ -259,15 +259,12 @@ public:
                                        long nHeight, sal_uInt8 nTransparency ) override;

    virtual SystemGraphicsData      GetGraphicsData() const override;

#if ENABLE_CAIRO_CANVAS
    virtual bool                    SupportsCairo() const override;
    virtual cairo::SurfaceSharedPtr CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) const override;
    virtual cairo::SurfaceSharedPtr CreateSurface(const OutputDevice& rRefDevice, int x, int y, int width, int height) const override;
    virtual cairo::SurfaceSharedPtr CreateBitmapSurface(const OutputDevice& rRefDevice, const BitmapSystemData& rData, const Size& rSize) const override;
    virtual css::uno::Any           GetNativeSurfaceHandle(cairo::SurfaceSharedPtr& rSurface, const basegfx::B2ISize& rSize) const override;
    virtual SystemFontData          GetSysFontData( int nFallbackLevel ) const override;
#endif

    bool TryRenderCachedNativeControl(ControlCacheKey& aControlCacheKey,
                                      int nX, int nY);
diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx
index 4336e6b..d2444b1 100644
--- a/vcl/qa/cppunit/BitmapTest.cxx
+++ b/vcl/qa/cppunit/BitmapTest.cxx
@@ -21,7 +21,10 @@
#include <rtl/strbuf.hxx>
#include <tools/stream.hxx>
#include <vcl/graphicfilter.hxx>
#include <config_features.h>
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLHelper.hxx>
#endif

#include "BitmapSymmetryCheck.hxx"

@@ -55,9 +58,11 @@ void BitmapTest::testConvert()
        //it would be nice to find and change the stride for quartz to be the same as everyone else
        CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(10), pReadAccess->GetScanlineSize());
#else
#if HAVE_FEATURE_OPENGL
        if (!OpenGLHelper::isVCLOpenGLEnabled())
            CPPUNIT_ASSERT_EQUAL(static_cast<sal_uLong>(12), pReadAccess->GetScanlineSize());
#endif
#endif
        CPPUNIT_ASSERT(pReadAccess->HasPalette());
        const BitmapColor& rColor = pReadAccess->GetPaletteColor(pReadAccess->GetPixelIndex(1, 1));
        CPPUNIT_ASSERT_EQUAL(sal_Int32(204), sal_Int32(rColor.GetRed()));
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index 20bdca4..9c874a9 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -51,7 +51,9 @@
#include <vcl/scheduler.hxx>
#include <vcl/unohelp.hxx>
#include <vcl/lazydelete.hxx>
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLWrapper.hxx>
#endif

#include "salinst.hxx"
#include "salframe.hxx"
@@ -1220,9 +1222,11 @@ OUString Application::GetHWOSConfInfo()
    aDetails.append( "; " );

    aDetails.append( VclResId(SV_APP_UIRENDER).toString() );
#if HAVE_FEATURE_OPENGL
    if ( OpenGLWrapper::isVCLOpenGLEnabled() )
        aDetails.append( VclResId(SV_APP_GL).toString() );
    else
#endif
        aDetails.append( VclResId(SV_APP_DEFAULT).toString() );
    aDetails.append( "; " );

diff --git a/vcl/source/app/svdata.cxx b/vcl/source/app/svdata.cxx
index dd34d10..ddad3e3 100644
--- a/vcl/source/app/svdata.cxx
+++ b/vcl/source/app/svdata.cxx
@@ -52,7 +52,10 @@

#include "officecfg/Office/Common.hxx"

#include <config_features.h>
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLContext.hxx>
#endif

using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
@@ -154,10 +157,12 @@ vcl::Window *ImplGetDefaultContextWindow()
            pSVData->mpDefaultWin = VclPtr<WorkWindow>::Create( nullptr, WB_DEFAULTWIN );
            pSVData->mpDefaultWin->SetText( "VCL ImplGetDefaultWindow" );

#if HAVE_FEATURE_OPENGL
            // Add a reference to the default context so it never gets deleted
            rtl::Reference<OpenGLContext> pContext = pSVData->mpDefaultWin->GetGraphics()->GetOpenGLContext();
            if( pContext.is() )
                pContext->acquire();
#endif
        }
    }

diff --git a/vcl/source/app/svmain.cxx b/vcl/source/app/svmain.cxx
index 6ca4c07..e2e2ffd 100644
--- a/vcl/source/app/svmain.cxx
+++ b/vcl/source/app/svmain.cxx
@@ -72,7 +72,10 @@
#include "salimestatus.hxx"
#include "xconnection.hxx"

#include <config_features.h>
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLContext.hxx>
#endif

#include <osl/process.h>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
@@ -110,8 +113,10 @@ oslSignalAction SAL_CALL VCLExceptionSignal_impl( void* /*pData*/, oslSignalInfo
             (pInfo->Signal == osl_Signal_DebugBreak) )
        {
            nVCLException = EXCEPTION_SYSTEM;
#if HAVE_FEATURE_OPENGL
            if (OpenGLZone::isInZone())
                OpenGLZone::hardDisable();
#endif
        }

        // RC
@@ -188,8 +193,9 @@ int ImplSVMain()
      pSVData->mxAccessBridge.clear();
    }

#if HAVE_FEATURE_OPENGL
    OpenGLWatchdogThread::stop();

#endif
    DeInitVCL();

    return nReturn;
diff --git a/vcl/source/gdi/bitmap3.cxx b/vcl/source/gdi/bitmap3.cxx
index bd9b90a..5b6902c 100644
--- a/vcl/source/gdi/bitmap3.cxx
+++ b/vcl/source/gdi/bitmap3.cxx
@@ -24,8 +24,10 @@
#include <vcl/bitmapex.hxx>
#include <vcl/bitmap.hxx>
#include <vcl/bitmapscalesuper.hxx>
#include <config_features.h>
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLHelper.hxx>

#endif
#include <memory>

#include "impbmp.hxx"
@@ -1007,7 +1009,11 @@ bool Bitmap::Scale( const Size& rNewSize, BmpScaleFlag nScaleFlag )

bool Bitmap::HasFastScale()
{
#if HAVE_FEATURE_OPENGL
    return OpenGLHelper::isVCLOpenGLEnabled();
#else
    return false;
#endif
}

void Bitmap::AdaptBitCount(Bitmap& rNew) const
diff --git a/vcl/source/gdi/salgdilayout.cxx b/vcl/source/gdi/salgdilayout.cxx
index 9c2d221..d8abefa 100644
--- a/vcl/source/gdi/salgdilayout.cxx
+++ b/vcl/source/gdi/salgdilayout.cxx
@@ -17,7 +17,10 @@
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <config_features.h>
#if HAVE_FEATURE_OPENGL
#include "openglgdiimpl.hxx"
#endif
#include "salgdi.hxx"
#include "salframe.hxx"

@@ -50,7 +53,7 @@ SalGraphics::SalGraphics()
SalGraphics::~SalGraphics()
{
}

#if HAVE_FEATURE_OPENGL
rtl::Reference<OpenGLContext> SalGraphics::GetOpenGLContext() const
{
    OpenGLSalGraphicsImpl *pImpl = dynamic_cast<OpenGLSalGraphicsImpl*>(GetImpl());
@@ -59,6 +62,7 @@ rtl::Reference<OpenGLContext> SalGraphics::GetOpenGLContext() const

    return nullptr;
}
#endif

bool SalGraphics::drawTransformedBitmap(
    const basegfx::B2DPoint& /* rNull */,
diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx
index 5b63c89d..b6e86e3 100644
--- a/vcl/source/outdev/bitmap.cxx
+++ b/vcl/source/outdev/bitmap.cxx
@@ -22,7 +22,10 @@
#include <vcl/bitmap.hxx>
#include <vcl/bitmapex.hxx>
#include <vcl/bitmapaccess.hxx>
#include <config_features.h>
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLHelper.hxx>
#endif
#include <vcl/outdev.hxx>
#include <vcl/virdev.hxx>
#include <vcl/image.hxx>
@@ -688,8 +691,10 @@ void OutputDevice::DrawDeviceAlphaBitmap( const Bitmap& rBmp, const AlphaMask& r
        }

        // we need to make sure OpenGL never reaches this slow code path
        assert(!OpenGLHelper::isVCLOpenGLEnabled());

#if HAVE_FEATURE_OPENGL
        assert(!OpenGLHelper::isVCLOpenGLEnabled());
#endif
        Rectangle aBmpRect(Point(), rBmp.GetSizePixel());
        if (!aBmpRect.Intersection(Rectangle(rSrcPtPixel, rSrcSizePixel)).IsEmpty())
        {
diff --git a/vcl/source/window/event.cxx b/vcl/source/window/event.cxx
index af424e2..cb39104 100644
--- a/vcl/source/window/event.cxx
+++ b/vcl/source/window/event.cxx
@@ -26,7 +26,7 @@
#include <window.h>
#include <svdata.hxx>
#include <salframe.hxx>

#include <config_features.h>
#include <com/sun/star/awt/MouseEvent.hpp>
#include <com/sun/star/awt/KeyModifier.hpp>
#include <com/sun/star/awt/MouseButton.hpp>
@@ -492,11 +492,14 @@ void Window::ImplCallResize()
    // OpenGL has a charming feature of black clearing the whole window
    // some legacy code eg. the app-menu has the beautiful feature of
    // avoiding re-paints when width doesn't change => invalidate all.
#if HAVE_FEATURE_OPENGL
    if( OpenGLWrapper::isVCLOpenGLEnabled() )
        Invalidate();

    // Normally we avoid blanking on re-size unless people might notice:
    else if( GetBackground().IsGradient() )
    else
#endif
        if( GetBackground().IsGradient() )
        Invalidate();

    Resize();
diff --git a/vcl/source/window/paint.cxx b/vcl/source/window/paint.cxx
index 1e5b936..fc94b76 100644
--- a/vcl/source/window/paint.cxx
+++ b/vcl/source/window/paint.cxx
@@ -32,7 +32,9 @@
#include <salframe.hxx>
#include <svdata.hxx>
#include <comphelper/lok.hxx>
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLHelper.hxx>
#endif

#define IMPL_PAINT_PAINT            ((sal_uInt16)0x0001)
#define IMPL_PAINT_PAINTALL         ((sal_uInt16)0x0002)
@@ -273,11 +275,12 @@ void PaintHelper::DoPaint(const vcl::Region* pRegion)
    pWindowImpl->mnPaintFlags = 0;
    if (!pWindowImpl->maInvalidateRegion.IsEmpty())
    {
#if HAVE_FEATURE_OPENGL
        VCL_GL_INFO("PaintHelper::DoPaint on " <<
                    typeid( *m_pWindow ).name() << " '" << m_pWindow->GetText() << "' begin");

        OutputDevice::PaintScope aScope( m_pWindow );

#endif
        // double-buffering: setup the buffer if it does not exist
        if (!pFrameData->mbInBufferedPaint && m_pWindow->SupportsDoubleBuffering())
            StartBufferedPaint();
@@ -305,9 +308,10 @@ void PaintHelper::DoPaint(const vcl::Region* pRegion)
            m_pWindow->PushPaintHelper(this, *m_pWindow);
            m_pWindow->Paint(*m_pWindow, m_aPaintRect);
        }

#if HAVE_FEATURE_OPENGL
        VCL_GL_INFO("PaintHelper::DoPaint end on " <<
                    typeid( *m_pWindow ).name() << " '" << m_pWindow->GetText() << "'");
#endif
    }
}

@@ -625,7 +629,9 @@ void Window::ImplCallOverlapPaint()
    {
        // - RTL - notify ImplCallPaint to check for re-mirroring (CHECKRTL)
        //         because we were called from the Sal layer
#if HAVE_FEATURE_OPENGL
        OutputDevice::PaintScope aScope( GetOutDev() );
#endif
        ImplCallPaint(nullptr, mpWindowImpl->mnPaintFlags /*| IMPL_PAINT_CHECKRTL */);
    }
}
@@ -645,7 +651,9 @@ IMPL_LINK_NOARG_TYPED(Window, ImplHandlePaintHdl, Idle *, void)
        return;
    }

#if HAVE_FEATURE_OPENGL
    OutputDevice::PaintScope aScope(this);
#endif

    // save paint events until resizing or initial sizing done
    if (mpWindowImpl->mbFrame &&
@@ -664,8 +672,9 @@ IMPL_LINK_NOARG_TYPED(Window, ImplHandleResizeTimerHdl, Idle *, void)
{
    if( mpWindowImpl->mbReallyVisible )
    {
#if HAVE_FEATURE_OPENGL
        OutputDevice::PaintScope aScope(this);

#endif
        ImplCallResize();
        if( mpWindowImpl->mpFrameData->maPaintIdle.IsActive() )
        {
diff --git a/vcl/source/window/status.cxx b/vcl/source/window/status.cxx
index 671afb6..57a867e 100644
--- a/vcl/source/window/status.cxx
+++ b/vcl/source/window/status.cxx
@@ -27,8 +27,10 @@
#include <vcl/status.hxx>
#include <vcl/virdev.hxx>
#include <vcl/settings.hxx>
#include <config_features.h>
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLWrapper.hxx>

#endif
#include <svdata.hxx>
#include <window.h>

@@ -711,8 +713,10 @@ void StatusBar::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect

            // tdf#94213 - un-necessary virtual-device in GL mode
            // causes context switch & hence flicker during sizing.
#if HAVE_FEATURE_OPENGL
            if( OpenGLWrapper::isVCLOpenGLEnabled() )
                bOffscreen = false;
#endif

            if (!bOffscreen)
                rRenderContext.Erase(rRect);
diff --git a/vcl/unx/generic/app/geninst.cxx b/vcl/unx/generic/app/geninst.cxx
index 99b992c..daf54b0 100644
--- a/vcl/unx/generic/app/geninst.cxx
+++ b/vcl/unx/generic/app/geninst.cxx
@@ -29,8 +29,10 @@

#include <osl/module.hxx>
#include <comphelper/solarmutex.hxx>
#include <config_features.h>
#if HAVE_FEATURE_OPENGL
#include <vcl/opengl/OpenGLContext.hxx>

#endif
#include "unx/geninst.h"

// SalYieldMutex
@@ -60,7 +62,9 @@ void SalYieldMutex::release()
    assert(mnThreadId == osl::Thread::getCurrentIdentifier());
    if ( mnCount == 1 )
    {
#if HAVE_FEATURE_OPENGL
        OpenGLContext::prepareForYield();
#endif
        mnThreadId = 0;
    }
    mnCount--;
diff --git a/vcl/workben/vcldemo.cxx b/vcl/workben/vcldemo.cxx
index 507fdc4..f47dc31 100644
--- a/vcl/workben/vcldemo.cxx
+++ b/vcl/workben/vcldemo.cxx
@@ -45,13 +45,14 @@
#include <opengl/zone.hxx>

// internal headers for OpenGLTests class.
#if HAVE_FEATURE_OPENGL
#include "salgdi.hxx"
#include "salframe.hxx"
#include "openglgdiimpl.hxx"
#include "opengl/texture.hxx"
#include "opengl/framebuffer.hxx"
#include <vcl/opengl/OpenGLHelper.hxx>

#endif
#include <rtl/math.hxx>

#define FIXME_SELF_INTERSECTING_WORKING 0
@@ -2234,13 +2235,15 @@ public:
            VclPtr<DemoPopup> xPopup;

            aMainWin->SetText("Interactive VCL demo #1");

#if HAVE_FEATURE_OPENGL
            if (bGLTest)
            {
                OpenGLTests aTests;
                return aTests.execute();
            }
            else if (bWidgets)
            else
#endif
                 if (bWidgets)
                xWidgets = VclPtr< DemoWidgets >::Create ();
            else if (bPopup)
                xPopup = VclPtrInstance< DemoPopup> ();