From 6469b6134e71f6fc2debd8c8812e2dc9ad8e60c3 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 5 Jul 2019 12:46:49 +0200 Subject: [PATCH] simplify and flatten OutDevStateStack Change-Id: Ic2ee5c2e122244e11770ab5fb73f65800828439a Reviewed-on: https://gerrit.libreoffice.org/75128 Tested-by: Jenkins Reviewed-by: Noel Grandin --- include/vcl/outdev.hxx | 4 +-- include/vcl/outdevstate.hxx | 4 +-- vcl/Library_vcl.mk | 1 - vcl/inc/outdevstatestack.hxx | 31 ----------------- vcl/source/outdev/outdev.cxx | 12 ++----- vcl/source/outdev/outdevstate.cxx | 48 +++++++++++++------------- vcl/source/outdev/outdevstatestack.cxx | 38 -------------------- vcl/source/outdev/vclreferencebase.cxx | 1 - 8 files changed, 30 insertions(+), 109 deletions(-) delete mode 100644 vcl/inc/outdevstatestack.hxx delete mode 100644 vcl/source/outdev/outdevstatestack.cxx diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx index cf1d5c09c685..b3159396f9a4 100644 --- a/include/vcl/outdev.hxx +++ b/include/vcl/outdev.hxx @@ -322,8 +322,8 @@ private: mutable std::shared_ptr mxFontCollection; mutable std::unique_ptr mpDeviceFontList; mutable std::unique_ptr mpDeviceFontSizeList; - std::unique_ptr mpOutDevStateStack; - std::unique_ptr mpOutDevData; + std::vector maOutDevStateStack; + std::unique_ptr mpOutDevData; std::vector< VCLXGraphics* >* mpUnoGraphicsList; vcl::ExtOutDevData* mpExtOutDevData; diff --git a/include/vcl/outdevstate.hxx b/include/vcl/outdevstate.hxx index d3c469eff513..493855248db0 100644 --- a/include/vcl/outdevstate.hxx +++ b/include/vcl/outdevstate.hxx @@ -75,10 +75,10 @@ namespace o3tl { template<> struct typed_flags : is_typed_flags {}; } -class OutDevState +struct OutDevState { -public: OutDevState(); + OutDevState(OutDevState&&); ~OutDevState(); boost::optional mpMapMode; diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 7d03373b3797..3540606d4b07 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -219,7 +219,6 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/toolkit/morebtn \ vcl/source/outdev/outdev \ vcl/source/outdev/outdevstate \ - vcl/source/outdev/outdevstatestack \ vcl/source/outdev/clipping \ vcl/source/outdev/polygon \ vcl/source/outdev/transparent \ diff --git a/vcl/inc/outdevstatestack.hxx b/vcl/inc/outdevstatestack.hxx deleted file mode 100644 index 0d83f5978b18..000000000000 --- a/vcl/inc/outdevstatestack.hxx +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- 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_OUTDEVSTATESTACK_HXX -#define INCLUDED_VCL_OUTDEVSTATESTACK_HXX - -#include -#include -#include - -class OutDevStateStack -{ - std::deque> maData; - -public: - bool empty() const; - size_t size() const; - void push_back( OutDevState* p ); - void pop_back(); - OutDevState& back(); -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/outdev/outdev.cxx b/vcl/source/outdev/outdev.cxx index a7fa60287a29..803fd6746db9 100644 --- a/vcl/source/outdev/outdev.cxx +++ b/vcl/source/outdev/outdev.cxx @@ -33,7 +33,6 @@ #include #include #include -#include #include #ifdef DISABLE_DYNLOADING @@ -63,7 +62,6 @@ OutputDevice::OutputDevice(OutDevType eOutDevType) : mpFontInstance = nullptr; mpDeviceFontList = nullptr; mpDeviceFontSizeList = nullptr; - mpOutDevStateStack.reset(new OutDevStateStack); mpAlphaVDev = nullptr; mpExtOutDevData = nullptr; mnOutOffX = 0; @@ -160,15 +158,9 @@ void OutputDevice::dispose() mpOutDevData.reset(); // for some reason, we haven't removed state from the stack properly - if ( !mpOutDevStateStack->empty() ) - { + if ( !maOutDevStateStack.empty() ) SAL_WARN( "vcl.gdi", "OutputDevice::~OutputDevice(): OutputDevice::Push() calls != OutputDevice::Pop() calls" ); - while ( !mpOutDevStateStack->empty() ) - { - mpOutDevStateStack->pop_back(); - } - } - mpOutDevStateStack.reset(); + maOutDevStateStack.clear(); // release the active font instance mpFontInstance.clear(); diff --git a/vcl/source/outdev/outdevstate.cxx b/vcl/source/outdev/outdevstate.cxx index d3a9fb5b6c14..21da20adaac6 100644 --- a/vcl/source/outdev/outdevstate.cxx +++ b/vcl/source/outdev/outdevstate.cxx @@ -29,7 +29,6 @@ #include #include -#include #include OutDevState::OutDevState() @@ -42,6 +41,8 @@ OutDevState::OutDevState() { } +OutDevState::OutDevState(OutDevState&&) = default; + OutDevState::~OutDevState() { mpLineColor.reset(); @@ -62,58 +63,57 @@ void OutputDevice::Push( PushFlags nFlags ) if ( mpMetaFile ) mpMetaFile->AddAction( new MetaPushAction( nFlags ) ); - OutDevState* pState = new OutDevState; + maOutDevStateStack.emplace_back(); + OutDevState& rState = maOutDevStateStack.back(); - pState->mnFlags = nFlags; + rState.mnFlags = nFlags; if (nFlags & PushFlags::LINECOLOR && mbLineColor) { - pState->mpLineColor = maLineColor; + rState.mpLineColor = maLineColor; } if (nFlags & PushFlags::FILLCOLOR && mbFillColor) { - pState->mpFillColor = maFillColor; + rState.mpFillColor = maFillColor; } if ( nFlags & PushFlags::FONT ) - pState->mpFont.reset( new vcl::Font( maFont ) ); + rState.mpFont.reset( new vcl::Font( maFont ) ); if ( nFlags & PushFlags::TEXTCOLOR ) - pState->mpTextColor = GetTextColor(); + rState.mpTextColor = GetTextColor(); if (nFlags & PushFlags::TEXTFILLCOLOR && IsTextFillColor()) { - pState->mpTextFillColor = GetTextFillColor(); + rState.mpTextFillColor = GetTextFillColor(); } if (nFlags & PushFlags::TEXTLINECOLOR && IsTextLineColor()) { - pState->mpTextLineColor = GetTextLineColor(); + rState.mpTextLineColor = GetTextLineColor(); } if (nFlags & PushFlags::OVERLINECOLOR && IsOverlineColor()) { - pState->mpOverlineColor = GetOverlineColor(); + rState.mpOverlineColor = GetOverlineColor(); } if ( nFlags & PushFlags::TEXTALIGN ) - pState->meTextAlign = GetTextAlign(); + rState.meTextAlign = GetTextAlign(); if( nFlags & PushFlags::TEXTLAYOUTMODE ) - pState->mnTextLayoutMode = GetLayoutMode(); + rState.mnTextLayoutMode = GetLayoutMode(); if( nFlags & PushFlags::TEXTLANGUAGE ) - pState->meTextLanguage = GetDigitLanguage(); + rState.meTextLanguage = GetDigitLanguage(); if ( nFlags & PushFlags::RASTEROP ) - pState->meRasterOp = GetRasterOp(); + rState.meRasterOp = GetRasterOp(); if ( nFlags & PushFlags::MAPMODE ) { - pState->mpMapMode = maMapMode; - pState->mbMapActive = mbMap; + rState.mpMapMode = maMapMode; + rState.mbMapActive = mbMap; } if (nFlags & PushFlags::CLIPREGION && mbClipRegion) { - pState->mpClipRegion.reset( new vcl::Region( maRegion ) ); + rState.mpClipRegion.reset( new vcl::Region( maRegion ) ); } if (nFlags & PushFlags::REFPOINT && mbRefPoint) { - pState->mpRefPoint = maRefPoint; + rState.mpRefPoint = maRefPoint; } - mpOutDevStateStack->push_back( pState ); - if( mpAlphaVDev ) mpAlphaVDev->Push(); } @@ -127,12 +127,12 @@ void OutputDevice::Pop() GDIMetaFile* pOldMetaFile = mpMetaFile; mpMetaFile = nullptr; - if ( mpOutDevStateStack->empty() ) + if ( maOutDevStateStack.empty() ) { SAL_WARN( "vcl.gdi", "OutputDevice::Pop() without OutputDevice::Push()" ); return; } - const OutDevState& rState = mpOutDevStateStack->back(); + const OutDevState& rState = maOutDevStateStack.back(); if( mpAlphaVDev ) mpAlphaVDev->Pop(); @@ -215,14 +215,14 @@ void OutputDevice::Pop() SetRefPoint(); } - mpOutDevStateStack->pop_back(); + maOutDevStateStack.pop_back(); mpMetaFile = pOldMetaFile; } sal_uInt32 OutputDevice::GetGCStackDepth() const { - return mpOutDevStateStack->size(); + return maOutDevStateStack.size(); } void OutputDevice::EnableOutput( bool bEnable ) diff --git a/vcl/source/outdev/outdevstatestack.cxx b/vcl/source/outdev/outdevstatestack.cxx deleted file mode 100644 index a5209439920f..000000000000 --- a/vcl/source/outdev/outdevstatestack.cxx +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- 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/. - */ - -#include -#include - -bool OutDevStateStack::empty() const -{ - return maData.empty(); -} - -size_t OutDevStateStack::size() const -{ - return maData.size(); -} - -void OutDevStateStack::push_back( OutDevState* p ) -{ - maData.push_back(std::unique_ptr(p)); -} - -void OutDevStateStack::pop_back() -{ - maData.pop_back(); -} - -OutDevState& OutDevStateStack::back() -{ - return *maData.back(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/outdev/vclreferencebase.cxx b/vcl/source/outdev/vclreferencebase.cxx index 94a2a2fc9539..6866931ebe77 100644 --- a/vcl/source/outdev/vclreferencebase.cxx +++ b/vcl/source/outdev/vclreferencebase.cxx @@ -21,7 +21,6 @@ #include #include #include -#include VclReferenceBase::VclReferenceBase() : mnRefCnt(1), // cf. VclPtrInstance and README.lifecycle