LibreOffice Module canvas (master)  1
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 
22 #include <com/sun/star/lang/NoSupportException.hpp>
23 #include <sal/log.hxx>
24 #include <tools/diagnose_ex.h>
25 #include <vcl/outdev.hxx>
26 
27 #include "canvas.hxx"
28 
29 using namespace ::com::sun::star;
30 
31 namespace vclcanvas
32 {
33  namespace
34  {
35  class OutDevHolder : public OutDevProvider
36  {
37  public:
38  OutDevHolder(const OutDevHolder&) = delete;
39  const OutDevHolder& operator=(const OutDevHolder&) = delete;
40 
41  explicit OutDevHolder( OutputDevice& rOutDev ) :
42  mrOutDev(rOutDev)
43  {}
44 
45  private:
46  virtual OutputDevice& getOutDev() override { return mrOutDev; }
47  virtual const OutputDevice& getOutDev() const override { return mrOutDev; }
48 
49  // TODO(Q2): Lifetime issue. This _only_ works reliably,
50  // if disposing the Canvas correctly disposes all
51  // entities which hold this pointer.
53  };
54  }
55 
56  Canvas::Canvas( const uno::Sequence< uno::Any >& aArguments,
57  const uno::Reference< uno::XComponentContext >& /*rxContext*/ ) :
58  maArguments(aArguments)
59  {
60  }
61 
62  void Canvas::initialize()
63  {
64  // #i64742# Only perform initialization when not in probe mode
65  if( !maArguments.hasElements() )
66  return;
67 
68  /* maArguments:
69  0: ptr to creating instance (Window or VirtualDevice)
70  1: current bounds of creating instance
71  2: bool, denoting always on top state for Window (always false for VirtualDevice)
72  3: XWindow for creating Window (or empty for VirtualDevice)
73  4: SystemGraphicsData as a streamed Any
74  */
75  SolarMutexGuard aGuard;
76 
77  SAL_INFO("canvas.vcl", "VCLCanvas::initialize called" );
78 
79  ENSURE_ARG_OR_THROW( maArguments.getLength() >= 5 &&
80  maArguments[0].getValueTypeClass() == uno::TypeClass_HYPER,
81  "Canvas::initialize: wrong number of arguments, or wrong types" );
82 
83  sal_Int64 nPtr = 0;
84  maArguments[0] >>= nPtr;
85 
86  OutputDevice* pOutDev = reinterpret_cast<OutputDevice*>(nPtr);
87  if( !pOutDev )
88  throw lang::NoSupportException("Passed OutDev invalid!", nullptr);
89 
90  OutDevProviderSharedPtr pOutdevProvider = std::make_shared<OutDevHolder>(*pOutDev);
91 
92  // setup helper
93  maDeviceHelper.init( pOutdevProvider );
94  maCanvasHelper.init( *this,
95  pOutdevProvider,
96  true, // OutDev state preservation
97  false ); // no alpha on surface
98 
99  maArguments.realloc(0);
100  }
101 
102  Canvas::~Canvas()
103  {
104  SAL_INFO("canvas.vcl", "VCLCanvas destroyed" );
105  }
106 
107  void Canvas::disposeThis()
108  {
109  SolarMutexGuard aGuard;
110 
111  // forward to parent
112  CanvasBaseT::disposeThis();
113  }
114 
115  OUString SAL_CALL Canvas::getServiceName( )
116  {
117  return "com.sun.star.rendering.Canvas.VCL";
118  }
119 
120  bool Canvas::repaint( const GraphicObjectSharedPtr& rGrf,
121  const rendering::ViewState& viewState,
122  const rendering::RenderState& renderState,
123  const ::Point& rPt,
124  const ::Size& rSz,
125  const GraphicAttr& rAttr ) const
126  {
127  SolarMutexGuard aGuard;
128 
129  return maCanvasHelper.repaint( rGrf, viewState, renderState, rPt, rSz, rAttr );
130  }
131 }
132 
133 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
135  css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
136 {
137  auto p = new vclcanvas::Canvas(args, context);
138  cppu::acquire(p);
139  p->initialize();
140  return static_cast<cppu::OWeakObject*>(p);
141 }
142 
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< OutDevProvider > OutDevProviderSharedPtr
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_rendering_Canvas_VCL_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
Definition: canvas.cxx:134
Canvas(const css::uno::Sequence< css::uno::Any > &aArguments, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
std::shared_ptr< GraphicObject > GraphicObjectSharedPtr
Product of this component's factory.
Definition: canvas.hxx:73
#define ENSURE_ARG_OR_THROW(c, m)
OutputDevice & mrOutDev
Definition: canvas.cxx:52
#define SAL_INFO(area, stream)
void * p