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
29
30using namespace ::cairo;
31using namespace ::com::sun::star;
32
33namespace cairocanvas
34{
35
37 mpSpriteCanvas( nullptr ),
38 mbFullScreen( false )
39 {}
40
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
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 {
92 "canvas.cairo",
93 "device size " << rSize.getWidth() << " x " << rSize.getHeight());
94
95 if( !mpSpriteCanvas )
96 return; // disposed
97
99
100 if( mpBufferSurface && maSize != rSize )
101 mpBufferSurface.reset();
102 if( !mpBufferSurface )
103 mpBufferSurface = getWindowSurface()->getSimilar(
104 CAIRO_CONTENT_COLOR,
105 rSize.getWidth(), rSize.getHeight() );
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 {
122 }
123
124 SurfaceSharedPtr SpriteDeviceHelper::createSurface( const ::basegfx::B2ISize& rSize, int aContent )
125 {
126 if( mpBufferSurface )
127 return mpBufferSurface->getSimilar( aContent, rSize.getWidth(), rSize.getHeight() );
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 {
148 if( pWinSurface )
149 pWinSurface->flush();
150 }
151}
152
153/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
cairo::SurfaceSharedPtr CreateBitmapSurface(const BitmapSystemData &rData, const Size &rSize) const
void init(SurfaceProvider &rSurfaceProvider, OutputDevice &rRefDevice)
init helper
void setSize(const ::basegfx::B2ISize &rSize)
const ::cairo::SurfaceSharedPtr & getSurface() const
css::uno::Any getSurfaceHandle() const
OutputDevice * getOutputDevice() const
css::uno::Any getDeviceHandle() const
Product of this component's factory.
void setSizePixel(const ::basegfx::B2ISize &rSize)
::cairo::SurfaceSharedPtr const & getWindowSurface() const
void flush()
SpriteDeviceHelper::flush Flush the platform native window.
void notifySizeUpdate(const css::awt::Rectangle &rBounds)
::cairo::SurfaceSharedPtr mpBufferSurface
SpriteCanvas * mpSpriteCanvas
Pointer to sprite canvas (owner of this helper), needed to create bitmaps.
void setSize(const ::basegfx::B2ISize &rSize)
bool switchBuffer(bool, bool bUpdateAll)
void disposing()
Dispose all internal references.
::cairo::SurfaceSharedPtr createSurface(const ::basegfx::B2ISize &rSize, int aContent)
void init(vcl::Window &rOutputWindow, SpriteCanvas &rSpriteCanvas, const ::basegfx::B2ISize &rSize, bool bFullscreen)
::OutputDevice const * GetOutDev() const
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
std::shared_ptr< Surface > SurfaceSharedPtr
const cppcanvas::SpriteCanvasSharedPtr mpSpriteCanvas