[Libreoffice-commits] core.git: include/vcl vcl/source

Chris Sherlock chris.sherlock79 at gmail.com
Tue Mar 11 09:29:22 PDT 2014


 include/vcl/outdev.hxx       |    2 
 include/vcl/print.hxx        |    1 
 include/vcl/virdev.hxx       |    8 +-
 include/vcl/window.hxx       |    1 
 vcl/source/gdi/outdev.cxx    |  149 -------------------------------------------
 vcl/source/gdi/print.cxx     |   71 ++++++++++++++++++++
 vcl/source/gdi/virdev.cxx    |   44 ++++++++++++
 vcl/source/window/window.cxx |   68 +++++++++++++++++++
 8 files changed, 192 insertions(+), 152 deletions(-)

New commits:
commit e69615ccb016de1c64864bbc9cf1bbef9f50c1da
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
Date:   Mon Mar 10 23:42:13 2014 +1100

    fdo#74702 Moved ImplInitGraphics into correct classes
    
    Currently we check to see what type of class is being used. This
    really violates the Single Responsibility Principle, and tightly
    couples the code to OutputDevice. The responsibility for initializing
    graphics should be done by Printer, VirtualDevice and Window.
    
    Please note: to get this working, I've had to make Printer a friend
    class of VirtualDevice. I'm not entirely happy about this, I'll
    need to revisit this later when I look at Printer in more detail.
    For now, this is a hack to allow me to seperate out this function.
    
    Change-Id: I9d5946c22fa70670a4f85bf338b4209499d0aa54
    Reviewed-on: https://gerrit.libreoffice.org/8528
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index 8595400..125948f 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -385,7 +385,7 @@ public:
 
      @returns true if was able to initialize the graphics device, false otherwise.
      */
-    SAL_DLLPRIVATE bool         ImplInitGraphics() const;
+    virtual bool                ImplInitGraphics() const = 0;
 
     /** Release the graphics device, and remove it from the graphics device
      list.
diff --git a/include/vcl/print.hxx b/include/vcl/print.hxx
index 4c25444..bc53bd6 100644
--- a/include/vcl/print.hxx
+++ b/include/vcl/print.hxx
@@ -247,6 +247,7 @@ private:
     bool                        mbUserSetupResult;
     Link                        maErrorHdl;
 
+    bool                        ImplInitGraphics() const;
     SAL_DLLPRIVATE void         ImplInitData();
     SAL_DLLPRIVATE void         ImplInit( SalPrinterQueueInfo* pInfo );
     SAL_DLLPRIVATE void         ImplInitDisplay( const Window* pWindow );
diff --git a/include/vcl/virdev.hxx b/include/vcl/virdev.hxx
index 3450509..25ef11c 100644
--- a/include/vcl/virdev.hxx
+++ b/include/vcl/virdev.hxx
@@ -31,15 +31,16 @@ class VCL_DLLPUBLIC VirtualDevice : public OutputDevice
 {
     friend class Application;
     friend class OutputDevice;
+    friend class Printer;
 
 private:
     SalVirtualDevice*   mpVirDev;
     VirtualDevice*      mpPrev;
     VirtualDevice*      mpNext;
-    sal_uInt16              mnBitCount;
+    sal_uInt16          mnBitCount;
     bool                mbScreenComp;
     sal_Int8            mnAlphaDepth;
-    sal_uInt8               meRefDevMode;
+    sal_uInt8           meRefDevMode;
 
     SAL_DLLPRIVATE void ImplInitVirDev( const OutputDevice* pOutDev, long nDX, long nDY, sal_uInt16 nBitCount, const SystemGraphicsData *pData = NULL );
     SAL_DLLPRIVATE bool InnerImplSetOutputSizePixel( const Size& rNewSize, bool bErase, const basebmp::RawMemorySharedArray &pBuffer );
@@ -60,6 +61,9 @@ private:
     SAL_DLLPRIVATE bool ForceZeroExtleadBug() const
         { return ((meRefDevMode & REFDEV_FORCE_ZERO_EXTLEAD) != 0); }
 public:
+    bool ImplInitGraphics() const;
+
+public:
     /** Create a virtual device of size 1x1
 
         @param nBitCount
diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx
index 7e226a6..62aa5c8 100644
--- a/include/vcl/window.hxx
+++ b/include/vcl/window.hxx
@@ -374,6 +374,7 @@ private:
     friend Window* ImplFindWindow( const SalFrame* pFrame, Point& rSalFramePos );
 public:
     SAL_DLLPRIVATE void                ImplInit( Window* pParent, WinBits nStyle, SystemParentData* pSystemParentData );
+    bool                               ImplInitGraphics() const;
     SAL_DLLPRIVATE WinBits             ImplInitRes( const ResId& rResId );
     SAL_DLLPRIVATE WindowResHeader     ImplLoadResHeader( const ResId& rResId );
     SAL_DLLPRIVATE void                ImplLoadRes( const ResId& rResId );
diff --git a/vcl/source/gdi/outdev.cxx b/vcl/source/gdi/outdev.cxx
index c1f42d7..1b797a1 100644
--- a/vcl/source/gdi/outdev.cxx
+++ b/vcl/source/gdi/outdev.cxx
@@ -550,155 +550,6 @@ SalGraphics const *OutputDevice::ImplGetGraphics() const
     return mpGraphics;
 }
 
-bool OutputDevice::ImplInitGraphics() const
-{
-    DBG_TESTSOLARMUTEX();
-
-    mbInitLineColor     = true;
-    mbInitFillColor     = true;
-    mbInitFont          = true;
-    mbInitTextColor     = true;
-    mbInitClipRegion    = true;
-
-    ImplSVData* pSVData = ImplGetSVData();
-
-    // TODO: move this out of OutputDevice and into subclasses
-    if ( meOutDevType == OUTDEV_WINDOW )
-    {
-        Window* pWindow = (Window*)this;
-
-        mpGraphics = pWindow->mpWindowImpl->mpFrame->AcquireGraphics();
-        // try harder if no wingraphics was available directly
-        if ( !mpGraphics )
-        {
-            // find another output device in the same frame
-            OutputDevice* pReleaseOutDev = pSVData->maGDIData.mpLastWinGraphics;
-            while ( pReleaseOutDev )
-            {
-                if ( ((Window*)pReleaseOutDev)->mpWindowImpl->mpFrame == pWindow->mpWindowImpl->mpFrame )
-                    break;
-                pReleaseOutDev = pReleaseOutDev->mpPrevGraphics;
-            }
-
-            if ( pReleaseOutDev )
-            {
-                // steal the wingraphics from the other outdev
-                mpGraphics = pReleaseOutDev->mpGraphics;
-                pReleaseOutDev->ImplReleaseGraphics( false );
-            }
-            else
-            {
-                // if needed retry after releasing least recently used wingraphics
-                while ( !mpGraphics )
-                {
-                    if ( !pSVData->maGDIData.mpLastWinGraphics )
-                        break;
-                    pSVData->maGDIData.mpLastWinGraphics->ImplReleaseGraphics();
-                    mpGraphics = pWindow->mpWindowImpl->mpFrame->AcquireGraphics();
-                }
-            }
-        }
-
-        // update global LRU list of wingraphics
-        if ( mpGraphics )
-        {
-            mpNextGraphics = pSVData->maGDIData.mpFirstWinGraphics;
-            pSVData->maGDIData.mpFirstWinGraphics = const_cast<OutputDevice*>(this);
-            if ( mpNextGraphics )
-                mpNextGraphics->mpPrevGraphics = const_cast<OutputDevice*>(this);
-            if ( !pSVData->maGDIData.mpLastWinGraphics )
-                pSVData->maGDIData.mpLastWinGraphics = const_cast<OutputDevice*>(this);
-        }
-    }
-    else if ( meOutDevType == OUTDEV_VIRDEV )
-    {
-        const VirtualDevice* pVirDev = (const VirtualDevice*)this;
-
-        if ( pVirDev->mpVirDev )
-        {
-            mpGraphics = pVirDev->mpVirDev->AcquireGraphics();
-            // if needed retry after releasing least recently used virtual device graphics
-            while ( !mpGraphics )
-            {
-                if ( !pSVData->maGDIData.mpLastVirGraphics )
-                    break;
-                pSVData->maGDIData.mpLastVirGraphics->ImplReleaseGraphics();
-                mpGraphics = pVirDev->mpVirDev->AcquireGraphics();
-            }
-            // update global LRU list of virtual device graphics
-            if ( mpGraphics )
-            {
-                mpNextGraphics = pSVData->maGDIData.mpFirstVirGraphics;
-                pSVData->maGDIData.mpFirstVirGraphics = const_cast<OutputDevice*>(this);
-                if ( mpNextGraphics )
-                    mpNextGraphics->mpPrevGraphics = const_cast<OutputDevice*>(this);
-                if ( !pSVData->maGDIData.mpLastVirGraphics )
-                    pSVData->maGDIData.mpLastVirGraphics = const_cast<OutputDevice*>(this);
-            }
-        }
-    }
-    else if ( meOutDevType == OUTDEV_PRINTER )
-    {
-        const Printer* pPrinter = (const Printer*)this;
-
-        if ( pPrinter->mpJobGraphics )
-            mpGraphics = pPrinter->mpJobGraphics;
-        else if ( pPrinter->mpDisplayDev )
-        {
-            const VirtualDevice* pVirDev = pPrinter->mpDisplayDev;
-            mpGraphics = pVirDev->mpVirDev->AcquireGraphics();
-            // if needed retry after releasing least recently used virtual device graphics
-            while ( !mpGraphics )
-            {
-                if ( !pSVData->maGDIData.mpLastVirGraphics )
-                    break;
-                pSVData->maGDIData.mpLastVirGraphics->ImplReleaseGraphics();
-                mpGraphics = pVirDev->mpVirDev->AcquireGraphics();
-            }
-            // update global LRU list of virtual device graphics
-            if ( mpGraphics )
-            {
-                mpNextGraphics = pSVData->maGDIData.mpFirstVirGraphics;
-                pSVData->maGDIData.mpFirstVirGraphics = const_cast<OutputDevice*>(this);
-                if ( mpNextGraphics )
-                    mpNextGraphics->mpPrevGraphics = const_cast<OutputDevice*>(this);
-                if ( !pSVData->maGDIData.mpLastVirGraphics )
-                    pSVData->maGDIData.mpLastVirGraphics = const_cast<OutputDevice*>(this);
-            }
-        }
-        else
-        {
-            mpGraphics = pPrinter->mpInfoPrinter->AcquireGraphics();
-            // if needed retry after releasing least recently used printer graphics
-            while ( !mpGraphics )
-            {
-                if ( !pSVData->maGDIData.mpLastPrnGraphics )
-                    break;
-                pSVData->maGDIData.mpLastPrnGraphics->ImplReleaseGraphics();
-                mpGraphics = pPrinter->mpInfoPrinter->AcquireGraphics();
-            }
-            // update global LRU list of printer graphics
-            if ( mpGraphics )
-            {
-                mpNextGraphics = pSVData->maGDIData.mpFirstPrnGraphics;
-                pSVData->maGDIData.mpFirstPrnGraphics = const_cast<OutputDevice*>(this);
-                if ( mpNextGraphics )
-                    mpNextGraphics->mpPrevGraphics = const_cast<OutputDevice*>(this);
-                if ( !pSVData->maGDIData.mpLastPrnGraphics )
-                    pSVData->maGDIData.mpLastPrnGraphics = const_cast<OutputDevice*>(this);
-            }
-        }
-    }
-
-    if ( mpGraphics )
-    {
-        mpGraphics->SetXORMode( (ROP_INVERT == meRasterOp) || (ROP_XOR == meRasterOp), ROP_INVERT == meRasterOp );
-        mpGraphics->setAntiAliasB2DDraw(mnAntialiasing & ANTIALIASING_ENABLE_B2DDRAW);
-    }
-
-    return mpGraphics ? true : false;
-}
-
 void OutputDevice::ImplReleaseGraphics( bool bRelease )
 {
     DBG_TESTSOLARMUTEX();
diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx
index a50770c..7eca283 100644
--- a/vcl/source/gdi/print.cxx
+++ b/vcl/source/gdi/print.cxx
@@ -35,6 +35,7 @@
 #include <vcl/print.hxx>
 
 #include <salinst.hxx>
+#include <salvd.hxx>
 #include <salgdi.hxx>
 #include <salptype.hxx>
 #include <salprn.hxx>
@@ -453,6 +454,76 @@ void Printer::ImplInitData()
     pSVData->maGDIData.mpFirstPrinter = this;
 }
 
+bool Printer::ImplInitGraphics() const
+{
+    DBG_TESTSOLARMUTEX();
+
+    mbInitLineColor     = true;
+    mbInitFillColor     = true;
+    mbInitFont          = true;
+    mbInitTextColor     = true;
+    mbInitClipRegion    = true;
+
+    ImplSVData* pSVData = ImplGetSVData();
+
+    const Printer* pPrinter = (const Printer*)this;
+
+    if ( pPrinter->mpJobGraphics )
+        mpGraphics = pPrinter->mpJobGraphics;
+    else if ( pPrinter->mpDisplayDev )
+    {
+        const VirtualDevice* pVirDev = pPrinter->mpDisplayDev;
+        mpGraphics = pVirDev->mpVirDev->AcquireGraphics();
+        // if needed retry after releasing least recently used virtual device graphics
+        while ( !mpGraphics )
+        {
+            if ( !pSVData->maGDIData.mpLastVirGraphics )
+                break;
+            pSVData->maGDIData.mpLastVirGraphics->ImplReleaseGraphics();
+            mpGraphics = pVirDev->mpVirDev->AcquireGraphics();
+        }
+        // update global LRU list of virtual device graphics
+        if ( mpGraphics )
+        {
+            mpNextGraphics = pSVData->maGDIData.mpFirstVirGraphics;
+            pSVData->maGDIData.mpFirstVirGraphics = const_cast<Printer*>(this);
+            if ( mpNextGraphics )
+                mpNextGraphics->mpPrevGraphics = const_cast<Printer*>(this);
+            if ( !pSVData->maGDIData.mpLastVirGraphics )
+                pSVData->maGDIData.mpLastVirGraphics = const_cast<Printer*>(this);
+        }
+    }
+    else
+    {
+        mpGraphics = pPrinter->mpInfoPrinter->AcquireGraphics();
+        // if needed retry after releasing least recently used printer graphics
+        while ( !mpGraphics )
+        {
+            if ( !pSVData->maGDIData.mpLastPrnGraphics )
+                break;
+            pSVData->maGDIData.mpLastPrnGraphics->ImplReleaseGraphics();
+            mpGraphics = pPrinter->mpInfoPrinter->AcquireGraphics();
+        }
+        // update global LRU list of printer graphics
+        if ( mpGraphics )
+        {
+            mpNextGraphics = pSVData->maGDIData.mpFirstPrnGraphics;
+            pSVData->maGDIData.mpFirstPrnGraphics = const_cast<Printer*>(this);
+            if ( mpNextGraphics )
+                mpNextGraphics->mpPrevGraphics = const_cast<Printer*>(this);
+            if ( !pSVData->maGDIData.mpLastPrnGraphics )
+                pSVData->maGDIData.mpLastPrnGraphics = const_cast<Printer*>(this);
+        }
+    }
+
+    if ( mpGraphics )
+    {
+        mpGraphics->SetXORMode( (ROP_INVERT == meRasterOp) || (ROP_XOR == meRasterOp), ROP_INVERT == meRasterOp );
+        mpGraphics->setAntiAliasB2DDraw(mnAntialiasing & ANTIALIASING_ENABLE_B2DDRAW);
+    }
+
+    return mpGraphics ? true : false;
+}
 
 void Printer::ImplInit( SalPrinterQueueInfo* pInfo )
 {
diff --git a/vcl/source/gdi/virdev.cxx b/vcl/source/gdi/virdev.cxx
index eda91c0..bb9d37f 100644
--- a/vcl/source/gdi/virdev.cxx
+++ b/vcl/source/gdi/virdev.cxx
@@ -34,7 +34,51 @@
 
 using namespace ::com::sun::star::uno;
 
+bool VirtualDevice::ImplInitGraphics() const
+{
+    DBG_TESTSOLARMUTEX();
+
+    mbInitLineColor     = true;
+    mbInitFillColor     = true;
+    mbInitFont          = true;
+    mbInitTextColor     = true;
+    mbInitClipRegion    = true;
+
+    ImplSVData* pSVData = ImplGetSVData();
+
+    const VirtualDevice* pVirDev = (const VirtualDevice*)this;
+
+    if ( pVirDev->mpVirDev )
+    {
+        mpGraphics = pVirDev->mpVirDev->AcquireGraphics();
+        // if needed retry after releasing least recently used virtual device graphics
+        while ( !mpGraphics )
+        {
+            if ( !pSVData->maGDIData.mpLastVirGraphics )
+                break;
+            pSVData->maGDIData.mpLastVirGraphics->ImplReleaseGraphics();
+            mpGraphics = pVirDev->mpVirDev->AcquireGraphics();
+        }
+        // update global LRU list of virtual device graphics
+        if ( mpGraphics )
+        {
+            mpNextGraphics = pSVData->maGDIData.mpFirstVirGraphics;
+            pSVData->maGDIData.mpFirstVirGraphics = const_cast<VirtualDevice*>(this);
+            if ( mpNextGraphics )
+                mpNextGraphics->mpPrevGraphics = const_cast<VirtualDevice*>(this);
+            if ( !pSVData->maGDIData.mpLastVirGraphics )
+                pSVData->maGDIData.mpLastVirGraphics = const_cast<VirtualDevice*>(this);
+        }
+    }
 
+    if ( mpGraphics )
+    {
+        mpGraphics->SetXORMode( (ROP_INVERT == meRasterOp) || (ROP_XOR == meRasterOp), ROP_INVERT == meRasterOp );
+        mpGraphics->setAntiAliasB2DDraw(mnAntialiasing & ANTIALIASING_ENABLE_B2DDRAW);
+    }
+
+    return mpGraphics ? true : false;
+}
 
 void VirtualDevice::ImplInitVirDev( const OutputDevice* pOutDev,
                                     long nDX, long nDY, sal_uInt16 nBitCount, const SystemGraphicsData *pData )
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index 691a17d..54a6835 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -352,6 +352,74 @@ const char* ImplDbgCheckWindow( const void* pObj )
 }
 #endif
 
+bool Window::ImplInitGraphics() const
+{
+    DBG_TESTSOLARMUTEX();
+
+    if ( mpGraphics )
+        return mpGraphics;
+
+    mbInitLineColor     = true;
+    mbInitFillColor     = true;
+    mbInitFont          = true;
+    mbInitTextColor     = true;
+    mbInitClipRegion    = true;
+
+    ImplSVData* pSVData = ImplGetSVData();
+
+    Window* pWindow = (Window*)this;
+
+    mpGraphics = pWindow->mpWindowImpl->mpFrame->AcquireGraphics();
+    // try harder if no wingraphics was available directly
+    if ( !mpGraphics )
+    {
+        // find another output device in the same frame
+        OutputDevice* pReleaseOutDev = pSVData->maGDIData.mpLastWinGraphics;
+        while ( pReleaseOutDev )
+        {
+            if ( ((Window*)pReleaseOutDev)->mpWindowImpl->mpFrame == pWindow->mpWindowImpl->mpFrame )
+                break;
+            pReleaseOutDev = pReleaseOutDev->mpPrevGraphics;
+        }
+
+        if ( pReleaseOutDev )
+        {
+            // steal the wingraphics from the other outdev
+            mpGraphics = pReleaseOutDev->mpGraphics;
+            pReleaseOutDev->ImplReleaseGraphics( false );
+        }
+        else
+        {
+            // if needed retry after releasing least recently used wingraphics
+            while ( !mpGraphics )
+            {
+                if ( !pSVData->maGDIData.mpLastWinGraphics )
+                    break;
+                pSVData->maGDIData.mpLastWinGraphics->ImplReleaseGraphics();
+                mpGraphics = pWindow->mpWindowImpl->mpFrame->AcquireGraphics();
+            }
+        }
+    }
+
+    // update global LRU list of wingraphics
+    if ( mpGraphics )
+    {
+        mpNextGraphics = pSVData->maGDIData.mpFirstWinGraphics;
+        pSVData->maGDIData.mpFirstWinGraphics = const_cast<Window*>(this);
+        if ( mpNextGraphics )
+            mpNextGraphics->mpPrevGraphics = const_cast<Window*>(this);
+        if ( !pSVData->maGDIData.mpLastWinGraphics )
+            pSVData->maGDIData.mpLastWinGraphics = const_cast<Window*>(this);
+    }
+
+    if ( mpGraphics )
+    {
+        mpGraphics->SetXORMode( (ROP_INVERT == meRasterOp) || (ROP_XOR == meRasterOp), ROP_INVERT == meRasterOp );
+        mpGraphics->setAntiAliasB2DDraw(mnAntialiasing & ANTIALIASING_ENABLE_B2DDRAW);
+    }
+
+    return mpGraphics ? true : false;
+}
 
 
 bool Window::HasMirroredGraphics() const


More information about the Libreoffice-commits mailing list