LibreOffice Module canvas (master) 1
ogl_spritecanvas.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
10#include <sal/config.h>
11#include <sal/log.hxx>
12
13#include <com/sun/star/lang/NoSupportException.hpp>
14#include <osl/mutex.hxx>
18#include <vcl/window.hxx>
19
21#include "ogl_spritecanvas.hxx"
22
23using namespace ::com::sun::star;
24
25namespace oglcanvas
26{
27 SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments,
28 const uno::Reference< uno::XComponentContext >& /*rxContext*/ ) :
29 maArguments(aArguments)
30 {
31 }
32
33 void SpriteCanvas::initialize()
34 {
35 // Only call initialize when not in probe mode
36 if( !maArguments.hasElements() )
37 return;
38
39 SAL_INFO("canvas.ogl", "SpriteCanvas::initialize called" );
40
41 /* aArguments:
42 0: ptr to creating instance (Window or VirtualDevice)
43 1: current bounds of creating instance
44 2: bool, denoting always on top state for Window (always false for VirtualDevice)
45 3: XWindow for creating Window (or empty for VirtualDevice)
46 4: SystemGraphicsData as a streamed Any
47 */
48 ENSURE_ARG_OR_THROW( maArguments.getLength() >= 4 &&
49 maArguments[3].getValueTypeClass() == uno::TypeClass_INTERFACE,
50 "OpenGL SpriteCanvas::initialize: wrong number of arguments, or wrong types" );
51
52 uno::Reference< awt::XWindow > xParentWindow;
53 maArguments[3] >>= xParentWindow;
54 VclPtr<vcl::Window> pParentWindow = VCLUnoHelper::GetWindow(xParentWindow);
55 if( !pParentWindow )
56 throw lang::NoSupportException(
57 "Parent window not VCL window, or canvas out-of-process!", nullptr);
58
59 awt::Rectangle aRect;
60 maArguments[1] >>= aRect;
61
62 // setup helper
63 maDeviceHelper.init( *pParentWindow,
64 *this,
65 aRect );
66 maCanvasHelper.init( *this, maDeviceHelper );
67 maArguments.realloc(0);
68 }
69
70 void SpriteCanvas::disposeThis()
71 {
72 ::osl::MutexGuard aGuard( m_aMutex );
73
74 // forward to parent
75 SpriteCanvasBaseT::disposeThis();
76 }
77
78 sal_Bool SAL_CALL SpriteCanvas::showBuffer( sal_Bool bUpdateAll )
79 {
80 ::osl::MutexGuard aGuard( m_aMutex );
81
82 // avoid repaints on hidden window (hidden: not mapped to
83 // screen). Return failure, since the screen really has _not_
84 // been updated (caller should try again later)
85 return mbIsVisible && SpriteCanvasBaseT::showBuffer( bUpdateAll );
86 }
87
88 sal_Bool SAL_CALL SpriteCanvas::switchBuffer( sal_Bool bUpdateAll )
89 {
90 ::osl::MutexGuard aGuard( m_aMutex );
91
92 // avoid repaints on hidden window (hidden: not mapped to
93 // screen). Return failure, since the screen really has _not_
94 // been updated (caller should try again later)
95 return mbIsVisible && SpriteCanvasBaseT::switchBuffer( bUpdateAll );
96 }
97
98 uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromAnimation(
99 const uno::Reference< rendering::XAnimation >& /*animation*/ )
100 {
101 return uno::Reference< rendering::XAnimatedSprite >();
102 }
103
104 uno::Reference< rendering::XAnimatedSprite > SAL_CALL SpriteCanvas::createSpriteFromBitmaps(
105 const uno::Sequence< uno::Reference< rendering::XBitmap > >& /*animationBitmaps*/,
106 ::sal_Int8 /*interpolationMode*/ )
107 {
108 return uno::Reference< rendering::XAnimatedSprite >();
109 }
110
111 uno::Reference< rendering::XCustomSprite > SAL_CALL SpriteCanvas::createCustomSprite(
112 const geometry::RealSize2D& spriteSize )
113 {
114 return uno::Reference< rendering::XCustomSprite >(
115 new CanvasCustomSprite(spriteSize, this, maDeviceHelper) );
116 }
117
118 uno::Reference< rendering::XSprite > SAL_CALL SpriteCanvas::createClonedSprite(
119 const uno::Reference< rendering::XSprite >& /*original*/ )
120 {
121 return uno::Reference< rendering::XSprite >();
122 }
123
124 sal_Bool SAL_CALL SpriteCanvas::updateScreen(sal_Bool bUpdateAll)
125 {
126 ::osl::MutexGuard aGuard( m_aMutex );
127 return maDeviceHelper.showBuffer(mbIsVisible, bUpdateAll);
128 }
129
130 OUString SAL_CALL SpriteCanvas::getServiceName( )
131 {
132 return "com.sun.star.rendering.SpriteCanvas.OGL";
133 }
134
135 void SpriteCanvas::show( const ::rtl::Reference< CanvasCustomSprite >& xSprite )
136 {
137 ::osl::MutexGuard aGuard( m_aMutex );
138 maDeviceHelper.show(xSprite);
139 }
140
141 void SpriteCanvas::hide( const ::rtl::Reference< CanvasCustomSprite >& xSprite )
142 {
143 ::osl::MutexGuard aGuard( m_aMutex );
144 maDeviceHelper.hide(xSprite);
145 }
146
147 void SpriteCanvas::renderRecordedActions() const
148 {
149 maCanvasHelper.renderRecordedActions();
150 }
151
152}
153
154
155extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
157 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& args)
158{
160 return nullptr;
162 p->initialize();
163 return cppu::acquire(p.get());
164}
165
166/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
Product of this component's factory.
SpriteCanvas(const css::uno::Sequence< css::uno::Any > &aArguments, const css::uno::Reference< css::uno::XComponentContext > &rxContext)
#define ENSURE_ARG_OR_THROW(c, m)
std::mutex m_aMutex
Sequence< PropertyValue > aArguments
void * p
#define SAL_INFO(area, stream)
args
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_rendering_SpriteCanvas_OGL_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &args)
static bool supportsOpenGL()
unsigned char sal_Bool
signed char sal_Int8