summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2021-05-04 11:32:11 +0200
committerLuboš Luňák <l.lunak@collabora.com>2021-05-06 11:22:47 +0200
commit402acbcfadbc8fd9f45330b46a4bfaad3e02eb39 (patch)
treebb12f967f882208c1b13febbca435f8b68999c57 /vcl
parent834822413d687572691753c33d837ffdb5064f2b (diff)
make it possible to write canvas unittests
One of the problems is that canvas apparently works only with windows, but tests obviously need an offscreen surface. This patch moves Window::GetCanvas() to OutputDevice, and makes vclcanvas capable of working with OutputDevice classes that are not windows. Other canvas implementations still don't work, but presumably at least cairocanvas could be fixed too. This commit adds a "simple" test that just draws a line and tries to verify it's been drawn properly. Adding another test should be a matter of basing it on this existing one, and then copy&pasting the complicated UNO way of drawing using canvas from somewhere, such as canvas/workben/canvasdemo.cxx. Change-Id: I42db12b09433763cd31c3dd497c10157424b8598 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115117 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/window.h8
-rw-r--r--vcl/source/outdev/outdev.cxx80
-rw-r--r--vcl/source/window/window.cxx29
-rw-r--r--vcl/source/window/wrkwin.cxx8
4 files changed, 83 insertions, 42 deletions
diff --git a/vcl/inc/window.h b/vcl/inc/window.h
index 2411d2f7c663..b4a53a580a5c 100644
--- a/vcl/inc/window.h
+++ b/vcl/inc/window.h
@@ -29,7 +29,6 @@
#include <vcl/window.hxx>
#include <vcl/settings.hxx>
#include <o3tl/typed_flags_set.hxx>
-#include <cppuhelper/weakref.hxx>
#include <optional>
#include <list>
@@ -61,10 +60,6 @@ namespace com::sun::star {
class XAccessibleEditableText;
}
- namespace rendering {
- class XCanvas;
- }
-
namespace awt {
class XWindowPeer;
class XWindow;
@@ -249,9 +244,6 @@ public:
Link<vcl::Window&, bool> maMnemonicActivateHdl;
Link<tools::JsonWriter&, void> maDumpAsPropertyTreeHdl;
- // The canvas interface for this VCL window. Is persistent after the first GetCanvas() call
- css::uno::WeakReference< css::rendering::XCanvas > mxCanvas;
-
vcl::Cursor* mpCursor;
PointerStyle maPointer;
Fraction maZoom;
diff --git a/vcl/source/outdev/outdev.cxx b/vcl/source/outdev/outdev.cxx
index f2618c285b36..70ec9616ace7 100644
--- a/vcl/source/outdev/outdev.cxx
+++ b/vcl/source/outdev/outdev.cxx
@@ -29,12 +29,17 @@
#include <vcl/toolkit/unowrap.hxx>
#include <vcl/svapp.hxx>
#include <vcl/sysdata.hxx>
+#include <vcl/lazydelete.hxx>
+#include <comphelper/processfactory.hxx>
#include <salgdi.hxx>
#include <window.h>
#include <outdev.h>
#include <com/sun/star/awt/DeviceCapability.hpp>
+#include <com/sun/star/awt/XWindow.hpp>
+#include <com/sun/star/rendering/CanvasFactory.hpp>
+#include <com/sun/star/rendering/XSpriteCanvas.hpp>
#ifdef DISABLE_DYNLOADING
// Linking all needed LO code into one .so/executable, these already
@@ -46,6 +51,8 @@ namespace {
}
#endif
+using namespace ::com::sun::star::uno;
+
// Begin initializer and accessor public functions
OutputDevice::OutputDevice(OutDevType eOutDevType) :
@@ -738,4 +745,77 @@ css::awt::DeviceInfo OutputDevice::GetDeviceInfo() const
return aInfo;
}
+Reference< css::rendering::XCanvas > OutputDevice::GetCanvas() const
+{
+ // try to retrieve hard reference from weak member
+ Reference< css::rendering::XCanvas > xCanvas( mxCanvas );
+ // canvas still valid? Then we're done.
+ if( xCanvas.is() )
+ return xCanvas;
+ xCanvas = ImplGetCanvas( false );
+ mxCanvas = xCanvas;
+ return xCanvas;
+}
+
+Reference< css::rendering::XSpriteCanvas > OutputDevice::GetSpriteCanvas() const
+{
+ Reference< css::rendering::XCanvas > xCanvas( mxCanvas );
+ Reference< css::rendering::XSpriteCanvas > xSpriteCanvas( xCanvas, UNO_QUERY );
+ if( xSpriteCanvas.is() )
+ return xSpriteCanvas;
+ xCanvas = ImplGetCanvas( true );
+ mxCanvas = xCanvas;
+ return Reference< css::rendering::XSpriteCanvas >( xCanvas, UNO_QUERY );
+}
+
+// Generic implementation, Window will override.
+com::sun::star::uno::Reference< css::rendering::XCanvas > OutputDevice::ImplGetCanvas( bool bSpriteCanvas ) const
+{
+ /* Arguments:
+ 0: ptr to creating instance (Window or VirtualDevice)
+ 1: current bounds of creating instance
+ 2: bool, denoting always on top state for Window (always false for VirtualDevice)
+ 3: XWindow for creating Window (or empty for VirtualDevice)
+ 4: SystemGraphicsData as a streamed Any
+ */
+ Sequence< Any > aArg(5);
+ aArg[ 0 ] <<= reinterpret_cast<sal_Int64>(this);
+ aArg[ 1 ] <<= css::awt::Rectangle( mnOutOffX, mnOutOffY, mnOutWidth, mnOutHeight );
+ aArg[ 2 ] <<= false;
+ aArg[ 3 ] <<= Reference< css::awt::XWindow >();
+ aArg[ 4 ] = GetSystemGfxDataAny();
+
+ Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
+
+ static vcl::DeleteUnoReferenceOnDeinit<css::lang::XMultiComponentFactory> xStaticCanvasFactory(
+ css::rendering::CanvasFactory::create( xContext ) );
+ Reference<css::lang::XMultiComponentFactory> xCanvasFactory(xStaticCanvasFactory.get());
+ Reference< css::rendering::XCanvas > xCanvas;
+
+ if(xCanvasFactory.is())
+ {
+ xCanvas.set( xCanvasFactory->createInstanceWithArgumentsAndContext(
+ bSpriteCanvas ?
+ OUString( "com.sun.star.rendering.SpriteCanvas" ) :
+ OUString( "com.sun.star.rendering.Canvas" ),
+ aArg,
+ xContext ),
+ UNO_QUERY );
+ }
+
+ // no factory??? Empty reference, then.
+ return xCanvas;
+}
+
+void OutputDevice::ImplDisposeCanvas()
+{
+ css::uno::Reference< css::rendering::XCanvas > xCanvas( mxCanvas );
+ if( xCanvas.is() )
+ {
+ css::uno::Reference< css::lang::XComponent > xCanvasComponent( xCanvas, css::uno::UNO_QUERY );
+ if( xCanvasComponent.is() )
+ xCanvasComponent->dispose();
+ }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index 94c8cc2df391..44f5438e3864 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -154,13 +154,7 @@ void Window::dispose()
// Dispose of the canvas implementation (which, currently, has an
// own wrapper window as a child to this one.
- Reference< css::rendering::XCanvas > xCanvas( mpWindowImpl->mxCanvas );
- if( xCanvas.is() )
- {
- Reference < XComponent > xCanvasComponent( xCanvas, UNO_QUERY );
- if( xCanvasComponent.is() )
- xCanvasComponent->dispose();
- }
+ ImplDisposeCanvas();
mpWindowImpl->mbInDispose = true;
@@ -3680,13 +3674,6 @@ bool Window::IsNativeWidgetEnabled() const
Reference< css::rendering::XCanvas > Window::ImplGetCanvas( bool bSpriteCanvas ) const
{
- // try to retrieve hard reference from weak member
- Reference< css::rendering::XCanvas > xCanvas( mpWindowImpl->mxCanvas );
-
- // canvas still valid? Then we're done.
- if( xCanvas.is() )
- return xCanvas;
-
Sequence< Any > aArg(5);
// Feed any with operating system's window handle
@@ -3707,6 +3694,7 @@ Reference< css::rendering::XCanvas > Window::ImplGetCanvas( bool bSpriteCanvas )
static vcl::DeleteUnoReferenceOnDeinit<XMultiComponentFactory> xStaticCanvasFactory(
css::rendering::CanvasFactory::create( xContext ) );
Reference<XMultiComponentFactory> xCanvasFactory(xStaticCanvasFactory.get());
+ Reference< css::rendering::XCanvas > xCanvas;
if(xCanvasFactory.is())
{
@@ -3740,25 +3728,12 @@ Reference< css::rendering::XCanvas > Window::ImplGetCanvas( bool bSpriteCanvas )
UNO_QUERY );
}
- mpWindowImpl->mxCanvas = xCanvas;
}
// no factory??? Empty reference, then.
return xCanvas;
}
-Reference< css::rendering::XCanvas > Window::GetCanvas() const
-{
- return ImplGetCanvas( false );
-}
-
-Reference< css::rendering::XSpriteCanvas > Window::GetSpriteCanvas() const
-{
- Reference< css::rendering::XSpriteCanvas > xSpriteCanvas(
- ImplGetCanvas( true ), UNO_QUERY );
- return xSpriteCanvas;
-}
-
OUString Window::GetSurroundingText() const
{
return OUString();
diff --git a/vcl/source/window/wrkwin.cxx b/vcl/source/window/wrkwin.cxx
index 9f90025a74aa..beaa1d48dbd8 100644
--- a/vcl/source/window/wrkwin.cxx
+++ b/vcl/source/window/wrkwin.cxx
@@ -145,13 +145,7 @@ void WorkWindow::ShowFullScreenMode( bool bFullScreenMode, sal_Int32 nDisplayScr
// Dispose of the canvas implementation, which might rely on
// screen-specific system data.
- css::uno::Reference< css::rendering::XCanvas > xCanvas( mpWindowImpl->mxCanvas );
- if( xCanvas.is() )
- {
- css::uno::Reference< css::lang::XComponent > xCanvasComponent( xCanvas, css::uno::UNO_QUERY );
- if( xCanvasComponent.is() )
- xCanvasComponent->dispose();
- }
+ ImplDisposeCanvas();
mpWindowImpl->mpFrameWindow->mpWindowImpl->mbWaitSystemResize = true;
ImplGetFrame()->ShowFullScreen( bFullScreenMode, nDisplayScreen );