LibreOffice Module canvas (master)  1
cairo_spritedevicehelper.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 <vcl/cairo.hxx>
24 
25 #include <cairo.h>
26 
27 #include "cairo_devicehelper.hxx"
28 #include "cairo_spritecanvas.hxx"
29 
30 using namespace ::cairo;
31 using namespace ::com::sun::star;
32 
33 namespace cairocanvas
34 {
35 
37  mpSpriteCanvas( nullptr ),
38  mpBufferSurface(),
39  maSize(),
40  mbFullScreen( false )
41  {}
42 
43  void SpriteDeviceHelper::init( vcl::Window& rOutputWindow,
44  SpriteCanvas& rSpriteCanvas,
45  const ::basegfx::B2ISize& rSize,
46  bool bFullscreen )
47  {
48  DeviceHelper::init(rSpriteCanvas,
49  rOutputWindow);
50 
51  mpSpriteCanvas = &rSpriteCanvas;
52  mbFullScreen = bFullscreen;
53 
54  setSize( rSize );
55  }
56 
58  {
59  // release all references
60  mpBufferSurface.reset();
61  mpSpriteCanvas = nullptr;
62  }
63 
64  bool SpriteDeviceHelper::showBuffer( bool, bool )
65  {
66  SAL_WARN("canvas.cairo", "showBuffer Not supposed to be called, handled by SpriteCanvas");
67  return false;
68  }
69 
71  {
72  SAL_WARN("canvas.cairo", "showBuffer Not supposed to be called, handled by SpriteCanvas");
73  return false;
74  }
75 
77  {
78  return css::uno::Any(true);
79  }
80 
82  {
84  }
85 
87  {
89  }
90 
91  void SpriteDeviceHelper::setSize( const ::basegfx::B2ISize& rSize )
92  {
93  SAL_INFO(
94  "canvas.cairo",
95  "device size " << rSize.getX() << " x " << rSize.getY());
96 
97  if( !mpSpriteCanvas )
98  return; // disposed
99 
100  DeviceHelper::setSize(rSize);
101 
102  if( mpBufferSurface && maSize != rSize )
103  mpBufferSurface.reset();
104  if( !mpBufferSurface )
105  mpBufferSurface = getWindowSurface()->getSimilar(
106  CAIRO_CONTENT_COLOR,
107  rSize.getX(), rSize.getY() );
108 
109  if( maSize != rSize )
110  maSize = rSize;
111 
113  }
114 
115 
116  void SpriteDeviceHelper::notifySizeUpdate( const awt::Rectangle& rBounds )
117  {
118  setSize( ::basegfx::B2ISize(rBounds.Width, rBounds.Height) );
119  }
120 
122  {
123  return DeviceHelper::getSurface();
124  }
125 
126  SurfaceSharedPtr SpriteDeviceHelper::createSurface( const ::basegfx::B2ISize& rSize, int aContent )
127  {
128  if( mpBufferSurface )
129  return mpBufferSurface->getSimilar( aContent, rSize.getX(), rSize.getY() );
130 
131  return SurfaceSharedPtr();
132  }
133 
135  {
136  OutputDevice *pDevice = getOutputDevice();
137  if (pDevice)
138  return pDevice->CreateBitmapSurface(rData, rSize);
139  return SurfaceSharedPtr();
140  }
141 
148  {
149  SurfaceSharedPtr pWinSurface=getWindowSurface();
150  if( pWinSurface )
151  pWinSurface->flush();
152  }
153 }
154 
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void notifySizeUpdate(const css::awt::Rectangle &rBounds)
const cppcanvas::SpriteCanvasSharedPtr mpSpriteCanvas
SpriteCanvas * mpSpriteCanvas
Pointer to sprite canvas (owner of this helper), needed to create bitmaps.
css::uno::Any getSurfaceHandle() const
cairo::SurfaceSharedPtr CreateBitmapSurface(const BitmapSystemData &rData, const Size &rSize) const
::cairo::SurfaceSharedPtr createSurface(const ::basegfx::B2ISize &rSize, int aContent)
bool switchBuffer(bool, bool bUpdateAll)
void init(SurfaceProvider &rSurfaceProvider, OutputDevice &rRefDevice)
init helper
std::shared_ptr< Surface > SurfaceSharedPtr
void setSize(const ::basegfx::B2ISize &rSize)
const ::cairo::SurfaceSharedPtr & getSurface() const
css::uno::Any getDeviceHandle() const
::cairo::SurfaceSharedPtr mpBufferSurface
Product of this component's factory.
void init(vcl::Window &rOutputWindow, SpriteCanvas &rSpriteCanvas, const ::basegfx::B2ISize &rSize, bool bFullscreen)
void flush()
SpriteDeviceHelper::flush Flush the platform native window.
#define SAL_INFO(area, stream)
void setSizePixel(const ::basegfx::B2ISize &rSize)
void disposing()
Dispose all internal references.
void setSize(const ::basegfx::B2ISize &rSize)
#define SAL_WARN(area, stream)
::cairo::SurfaceSharedPtr const & getWindowSurface() const
OutputDevice * getOutputDevice() const
::basegfx::B2IVector maSize
Definition: dx_9rm.cxx:116