LibreOffice Module canvas (master) 1
cairo_canvascustomsprite.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
26
28#include <cairo.h>
29
32
33
34using namespace ::cairo;
35using namespace ::com::sun::star;
36
37namespace cairocanvas
38{
39 CanvasCustomSprite::CanvasCustomSprite( const css::geometry::RealSize2D& rSpriteSize,
40 const SpriteCanvasRef& rRefDevice ) :
41 mpSpriteCanvas( rRefDevice ),
42 maSize( ::canvas::tools::roundUp( rSpriteSize.Width ),
43 ::canvas::tools::roundUp( rSpriteSize.Height ) )
44 {
45 ENSURE_OR_THROW( rRefDevice,
46 "CanvasCustomSprite::CanvasCustomSprite(): Invalid sprite canvas" );
47
48 SAL_INFO( "canvas.cairo", "sprite size: " << ::canvas::tools::roundUp( rSpriteSize.Width ) << ", " << ::canvas::tools::roundUp( rSpriteSize.Height ));
49
50 mpBufferSurface = mpSpriteCanvas->createSurface( maSize, CAIRO_CONTENT_COLOR_ALPHA );
51
53 *rRefDevice,
54 rRefDevice.get() );
55 maCanvasHelper.setSurface( mpBufferSurface, true );
56
57 maSpriteHelper.init( rSpriteSize,
58 rRefDevice );
59 maSpriteHelper.setSurface( mpBufferSurface );
60
61 // clear sprite to 100% transparent
62 maCanvasHelper.clear();
63 }
64
66 {
67 ::osl::MutexGuard aGuard( m_aMutex );
68
69 mpSpriteCanvas.clear();
70 mpBufferSurface.reset();
71
72 // forward to parent
74 }
75
77 bool bBufferedUpdate ) const
78 {
79 ::osl::MutexGuard aGuard( m_aMutex );
80
81 redraw( pCairo, maSpriteHelper.getPosPixel(), bBufferedUpdate );
82 }
83
85 const ::basegfx::B2DPoint& rOrigOutputPos,
86 bool bBufferedUpdate ) const
87 {
88 ::osl::MutexGuard aGuard( m_aMutex );
89
90 maSpriteHelper.redraw( pCairo,
91 rOrigOutputPos,
93 bBufferedUpdate );
94
95 mbSurfaceDirty = false;
96 }
97
99 const rendering::ViewState& viewState,
100 const rendering::RenderState& renderState )
101 {
102 return maCanvasHelper.repaint( pSurface, viewState, renderState );
103 }
104
106 {
107 return mpBufferSurface;
108 }
109
110 SurfaceSharedPtr CanvasCustomSprite::createSurface( const ::basegfx::B2ISize& rSize, int aContent )
111 {
112 return mpSpriteCanvas->createSurface(rSize,aContent);
113 }
114
116 {
117 return mpSpriteCanvas->createSurface(rBitmap);
118 }
119
121 {
122 SAL_INFO( "canvas.cairo", "replacing sprite background surface");
123
124 mpBufferSurface = mpSpriteCanvas->createSurface( maSize, CAIRO_CONTENT_COLOR );
125 maSpriteHelper.setSurface( mpBufferSurface );
126
127 return mpBufferSurface;
128 }
129
131 {
132 return mpSpriteCanvas->getOutputDevice();
133 }
134
136 {
137 return "CairoCanvas.CanvasCustomSprite";
138 }
139
140 sal_Bool SAL_CALL CanvasCustomSprite::supportsService( const OUString& ServiceName )
141 {
142 return cppu::supportsService( this, ServiceName );
143 }
144
145 uno::Sequence< OUString > SAL_CALL CanvasCustomSprite::getSupportedServiceNames()
146 {
147 return { "com.sun.star.rendering.CanvasCustomSprite" };
148 }
149}
150
151/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ::cairo::SurfaceSharedPtr changeSurface() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual bool repaint(const ::cairo::SurfaceSharedPtr &pSurface, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState) override
virtual OutputDevice * getOutputDevice() override
virtual ::cairo::SurfaceSharedPtr getSurface() override
virtual void disposeThis() override
Object is being disposed.
SpriteCanvasRef mpSpriteCanvas
MUST hold here, too, since CanvasHelper only contains a raw pointer (without refcounting)
CanvasCustomSprite(const css::geometry::RealSize2D &rSpriteSize, const SpriteCanvasRef &rRefDevice)
Create a custom sprite.
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual void redraw(const ::cairo::CairoSharedPtr &pCairo, bool bBufferedUpdate) const override
virtual OUString SAL_CALL getImplementationName() override
virtual ::cairo::SurfaceSharedPtr createSurface(const ::basegfx::B2ISize &rSize, int aContent) override
virtual void disposeThis() override
Object is being disposed.
#define ENSURE_OR_THROW(c, m)
::basegfx::B2ISize maSize
Definition: dx_9rm.cxx:116
std::mutex m_aMutex
#define SAL_INFO(area, stream)
std::shared_ptr< Surface > SurfaceSharedPtr
std::shared_ptr< cairo_t > CairoSharedPtr
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
T roundUp(T input, T multiple)
const cppcanvas::SpriteCanvasSharedPtr mpSpriteCanvas
unsigned char sal_Bool