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  mbFullScreen( false )
39  {}
40 
41  void SpriteDeviceHelper::init( vcl::Window& rOutputWindow,
42  SpriteCanvas& rSpriteCanvas,
43  const ::basegfx::B2ISize& rSize,
44  bool bFullscreen )
45  {
46  DeviceHelper::init(rSpriteCanvas,
47  *rOutputWindow.GetOutDev());
48 
49  mpSpriteCanvas = &rSpriteCanvas;
50  mbFullScreen = bFullscreen;
51 
52  setSize( rSize );
53  }
54 
56  {
57  // release all references
58  mpBufferSurface.reset();
59  mpSpriteCanvas = nullptr;
60  }
61 
62  bool SpriteDeviceHelper::showBuffer( bool, bool )
63  {
64  SAL_WARN("canvas.cairo", "showBuffer Not supposed to be called, handled by SpriteCanvas");
65  return false;
66  }
67 
69  {
70  SAL_WARN("canvas.cairo", "showBuffer Not supposed to be called, handled by SpriteCanvas");
71  return false;
72  }
73 
75  {
76  return css::uno::Any(true);
77  }
78 
80  {
82  }
83 
85  {
87  }
88 
89  void SpriteDeviceHelper::setSize( const ::basegfx::B2ISize& rSize )
90  {
91  SAL_INFO(
92  "canvas.cairo",
93  "device size " << rSize.getX() << " x " << rSize.getY());
94 
95  if( !mpSpriteCanvas )
96  return; // disposed
97 
98  DeviceHelper::setSize(rSize);
99 
100  if( mpBufferSurface && maSize != rSize )
101  mpBufferSurface.reset();
102  if( !mpBufferSurface )
103  mpBufferSurface = getWindowSurface()->getSimilar(
104  CAIRO_CONTENT_COLOR,
105  rSize.getX(), rSize.getY() );
106 
107  if( maSize != rSize )
108  maSize = rSize;
109 
111  }
112 
113 
114  void SpriteDeviceHelper::notifySizeUpdate( const awt::Rectangle& rBounds )
115  {
116  setSize( ::basegfx::B2ISize(rBounds.Width, rBounds.Height) );
117  }
118 
120  {
121  return DeviceHelper::getSurface();
122  }
123 
124  SurfaceSharedPtr SpriteDeviceHelper::createSurface( const ::basegfx::B2ISize& rSize, int aContent )
125  {
126  if( mpBufferSurface )
127  return mpBufferSurface->getSimilar( aContent, rSize.getX(), rSize.getY() );
128 
129  return SurfaceSharedPtr();
130  }
131 
133  {
134  OutputDevice *pDevice = getOutputDevice();
135  if (pDevice)
136  return pDevice->CreateBitmapSurface(rData, rSize);
137  return SurfaceSharedPtr();
138  }
139 
146  {
147  SurfaceSharedPtr pWinSurface=getWindowSurface();
148  if( pWinSurface )
149  pWinSurface->flush();
150  }
151 }
152 
153 /* 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)
::OutputDevice const * GetOutDev() const
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