vcl/inc/canvasbitmap.hxx           |    8 +++++++-
 vcl/source/helper/canvasbitmap.cxx |   14 ++++++++++++--
 vcl/source/helper/canvastools.cxx  |    4 +++-
 3 files changed, 22 insertions(+), 4 deletions(-)

New commits:
commit 1be70dda02c12a60778b7607cff2520ae1aa611e
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Thu Dec 1 10:18:17 2022 +0100
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Thu Dec 22 12:34:09 2022 +0000

    loplugin:unocast (vcl::unotools::VclCanvasBitmap)
    
    (See the upcoming commit introducing that loplugin:unocast on why such
    dynamic_casts from UNO types are dangerous.)
    
    Change-Id: I78b54e0806d5c3a157b4bed94bd89933a0921052
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144747
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/vcl/inc/canvasbitmap.hxx b/vcl/inc/canvasbitmap.hxx
index 54586a1ad60e..141d15ef948a 100644
--- a/vcl/inc/canvasbitmap.hxx
+++ b/vcl/inc/canvasbitmap.hxx
@@ -21,6 +21,7 @@
 #define INCLUDED_VCL_INC_CANVASBITMAP_HXX
 
 #include <cppuhelper/implbase.hxx>
+#include <com/sun/star/lang/XUnoTunnel.hpp>
 #include <com/sun/star/rendering/XIntegerReadOnlyBitmap.hpp>
 #include <com/sun/star/rendering/XIntegerBitmapColorSpace.hpp>
 #include <com/sun/star/rendering/XBitmapPalette.hpp>
@@ -32,7 +33,8 @@ namespace vcl::unotools
     class VCL_DLLPUBLIC VclCanvasBitmap final :
         public cppu::WeakImplHelper< css::rendering::XIntegerReadOnlyBitmap,
                                      css::rendering::XBitmapPalette,
-                                     css::rendering::XIntegerBitmapColorSpace >
+                                     css::rendering::XIntegerBitmapColorSpace,
+                                     css::lang::XUnoTunnel >
     {
     private:
         BitmapEx                                       m_aBmpEx;
@@ -103,6 +105,10 @@ namespace vcl::unotools
         virtual css::uno::Sequence< ::sal_Int8 > SAL_CALL 
convertIntegerFromARGB( const css::uno::Sequence< css::rendering::ARGBColor >& 
rgbColor ) override;
         virtual css::uno::Sequence< ::sal_Int8 > SAL_CALL 
convertIntegerFromPARGB( const css::uno::Sequence< css::rendering::ARGBColor >& 
rgbColor ) override;
 
+        sal_Int64 SAL_CALL getSomething(
+            css::uno::Sequence<sal_Int8> const & aIdentifier) override;
+        static css::uno::Sequence<sal_Int8> const & getUnoTunnelId();
+
         /** Create API wrapper for given BitmapEx
 
             @param rBitmap
diff --git a/vcl/source/helper/canvasbitmap.cxx 
b/vcl/source/helper/canvasbitmap.cxx
index 3f8507178b4f..ac5a0815638a 100644
--- a/vcl/source/helper/canvasbitmap.cxx
+++ b/vcl/source/helper/canvasbitmap.cxx
@@ -26,6 +26,7 @@
 #include <com/sun/star/rendering/RenderingIntent.hpp>
 
 #include <comphelper/diagnose_ex.hxx>
+#include <comphelper/servicehelper.hxx>
 #include <canvasbitmap.hxx>
 #include <vcl/canvastools.hxx>
 #include <vcl/BitmapReadAccess.hxx>
@@ -948,7 +949,7 @@ sal_Int8 SAL_CALL VclCanvasBitmap::getEndianness(  )
 uno::Sequence<double> SAL_CALL VclCanvasBitmap::convertFromIntegerColorSpace( 
const uno::Sequence< ::sal_Int8 >& deviceColor,
                                                                               
const uno::Reference< ::rendering::XColorSpace >& targetColorSpace )
 {
-    if( dynamic_cast<VclCanvasBitmap*>(targetColorSpace.get()) )
+    if( comphelper::getFromUnoTunnel<VclCanvasBitmap>(targetColorSpace) )
     {
         SolarMutexGuard aGuard;
 
@@ -1012,7 +1013,7 @@ uno::Sequence<double> SAL_CALL 
VclCanvasBitmap::convertFromIntegerColorSpace( co
 uno::Sequence< ::sal_Int8 > SAL_CALL 
VclCanvasBitmap::convertToIntegerColorSpace( const uno::Sequence< ::sal_Int8 >& 
deviceColor,
                                                                                
   const uno::Reference< ::rendering::XIntegerBitmapColorSpace >& 
targetColorSpace )
 {
-    if( dynamic_cast<VclCanvasBitmap*>(targetColorSpace.get()) )
+    if( comphelper::getFromUnoTunnel<VclCanvasBitmap>(targetColorSpace) )
     {
         // it's us, so simply pass-through the data
         return deviceColor;
@@ -1344,5 +1345,14 @@ uno::Sequence< ::sal_Int8 > SAL_CALL 
VclCanvasBitmap::convertIntegerFromPARGB( c
     return aRes;
 }
 
+sal_Int64 VclCanvasBitmap::getSomething(css::uno::Sequence<sal_Int8> const & 
aIdentifier) {
+    return comphelper::getSomethingImpl(aIdentifier, this);
+}
+
+css::uno::Sequence<sal_Int8> const & VclCanvasBitmap::getUnoTunnelId() {
+    static comphelper::UnoIdInit const id;
+    return id.getSeq();
+}
+
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/helper/canvastools.cxx 
b/vcl/source/helper/canvastools.cxx
index 595f12a959c8..11b1588ecf04 100644
--- a/vcl/source/helper/canvastools.cxx
+++ b/vcl/source/helper/canvastools.cxx
@@ -38,6 +38,7 @@
 #include <sal/log.hxx>
 #include <tools/helpers.hxx>
 #include <comphelper/diagnose_ex.hxx>
+#include <comphelper/servicehelper.hxx>
 
 #include <vcl/bitmapex.hxx>
 
@@ -174,7 +175,8 @@ namespace vcl::unotools
                 return ::BitmapEx();
 
             // tunnel directly for known implementation
-            VclCanvasBitmap* pImplBitmap = 
dynamic_cast<VclCanvasBitmap*>(xInputBitmap.get());
+            VclCanvasBitmap* pImplBitmap
+                = comphelper::getFromUnoTunnel<VclCanvasBitmap>(xInputBitmap);
             if( pImplBitmap )
                 return pImplBitmap->getBitmapEx();
 

Reply via email to