LibreOffice Module canvas (master)  1
cairo_canvas.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <sal/config.h>
21 #include <sal/log.hxx>
22 
23 #include <com/sun/star/awt/Rectangle.hpp>
24 #include <com/sun/star/lang/NoSupportException.hpp>
25 #include <osl/mutex.hxx>
26 #include <tools/diagnose_ex.h>
27 #include <vcl/sysdata.hxx>
29 #include <vcl/skia/SkiaHelper.hxx>
30 
31 #include "cairo_canvas.hxx"
32 
33 using namespace ::cairo;
34 using namespace ::com::sun::star;
35 
36 namespace cairocanvas
37 {
38  Canvas::Canvas( const uno::Sequence< uno::Any >& aArguments,
39  const uno::Reference< uno::XComponentContext >& /*rxContext*/ ) :
40  maArguments(aArguments)
41  {
42  }
43 
45  {
46  // #i64742# Only perform initialization when not in probe mode
47  if( !maArguments.hasElements() )
48  return;
49 
50  // tdf#93870 - force VCL canvas in OpenGL mode for now.
52  assert( !SkiaHelper::isVCLSkiaEnabled() );
53 
54  /* maArguments:
55  0: ptr to creating instance (Window or VirtualDevice)
56  1: current bounds of creating instance
57  2: bool, denoting always on top state for Window (always false for VirtualDevice)
58  3: XWindow for creating Window (or empty for VirtualDevice)
59  4: SystemGraphicsData as a streamed Any
60  */
61  SAL_INFO("canvas.cairo","Canvas created " << this);
62 
63  ENSURE_ARG_OR_THROW( maArguments.getLength() >= 5 &&
64  maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER &&
65  maArguments[4].getValueTypeClass() == uno::TypeClass_SEQUENCE,
66  "Canvas::initialize: wrong number of arguments, or wrong types" );
67 
68  // We expect a single Any here, containing a pointer to a valid
69  // VCL output device, on which to output (mostly needed for text)
70  sal_Int64 nPtr = 0;
71  maArguments[0] >>= nPtr;
72  OutputDevice* pOutDev = reinterpret_cast<OutputDevice*>(nPtr);
73 
74  ENSURE_ARG_OR_THROW( pOutDev != nullptr,
75  "Canvas::initialize: invalid OutDev pointer" );
76 
77  awt::Rectangle aBounds;
78  maArguments[1] >>= aBounds;
79 
80  uno::Sequence<sal_Int8> aSeq;
81  maArguments[4] >>= aSeq;
82 
83  const SystemGraphicsData* pSysData=reinterpret_cast<const SystemGraphicsData*>(aSeq.getConstArray());
84  if( !pSysData || !pSysData->nSize )
85  throw lang::NoSupportException( "Passed SystemGraphicsData invalid!" );
86 
87  bool bHasCairo = pOutDev->SupportsCairo();
88  ENSURE_ARG_OR_THROW(bHasCairo, "SpriteCanvas::SpriteCanvas: No Cairo capability");
89 
90  // setup helper
91  maDeviceHelper.init( *this, *pOutDev );
92 
93  maCanvasHelper.init( basegfx::B2ISize(aBounds.Width, aBounds.Height), *this, this );
94 
95  // forward surface to render on to canvashelper
96  maCanvasHelper.setSurface( maDeviceHelper.getSurface(), false );
97 
98  maArguments.realloc(0);
99  }
100 
102  {
103  SAL_INFO("canvas.cairo", "CairoCanvas destroyed" );
104  }
105 
107  {
108  ::osl::MutexGuard aGuard( m_aMutex );
109 
110  // forward to parent
111  CanvasBaseT::disposeThis();
112  }
113 
114  OUString SAL_CALL Canvas::getServiceName( )
115  {
116  return CANVAS_SERVICE_NAME;
117  }
118 
119  bool Canvas::repaint( const SurfaceSharedPtr& pSurface,
120  const rendering::ViewState& viewState,
121  const rendering::RenderState& renderState )
122  {
123  return maCanvasHelper.repaint( pSurface, viewState, renderState );
124  }
125 
127  {
128  return maDeviceHelper.getSurface();
129  }
130 
131  SurfaceSharedPtr Canvas::createSurface( const ::basegfx::B2ISize& rSize, int aContent )
132  {
133  return maDeviceHelper.createSurface( rSize, aContent );
134  }
135 
137  {
138  SurfaceSharedPtr pSurface;
139 
141  if( rBitmap.GetSystemData( aData ) ) {
142  const Size& rSize = rBitmap.GetSizePixel();
143 
144  pSurface = maDeviceHelper.createSurface( aData, rSize );
145  }
146 
147  return pSurface;
148  }
149 
151  {
152  // non-modifiable surface here
153  return SurfaceSharedPtr();
154  }
155 
157  {
158  return maDeviceHelper.getOutputDevice();
159  }
160 }
161 
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Canvas(const css::uno::Sequence< css::uno::Any > &aArguments, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
osl::Mutex m_aMutex
const char aData[]
bool SupportsCairo() const
Size GetSizePixel() const
virtual void disposeThis() override
Dispose all internal references.
static bool isVCLOpenGLEnabled()
virtual ~Canvas() override
For resource tracking.
std::shared_ptr< Surface > SurfaceSharedPtr
virtual ::cairo::SurfaceSharedPtr changeSurface() override
bool GetSystemData(BitmapSystemData &rData) const
#define ENSURE_ARG_OR_THROW(c, m)
virtual OutputDevice * getOutputDevice() override
VCL_DLLPUBLIC bool isVCLSkiaEnabled()
#define CANVAS_SERVICE_NAME
#define SAL_INFO(area, stream)
css::uno::Sequence< css::uno::Any > maArguments
Sequence< sal_Int8 > aSeq
virtual ::cairo::SurfaceSharedPtr getSurface() override
virtual ::cairo::SurfaceSharedPtr createSurface(const ::basegfx::B2ISize &rSize, int aContent) override
virtual OUString SAL_CALL getServiceName() override
virtual bool repaint(const ::cairo::SurfaceSharedPtr &pSurface, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState) override