1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_canvas.hxx"
30 
31 #include <canvas/debug.hxx>
32 #include <canvas/canvastools.hxx>
33 
34 #include <toolkit/helper/vclunohelper.hxx>
35 #include <vcl/canvastools.hxx>
36 #include <basegfx/tools/canvastools.hxx>
37 
38 #include "spritedevicehelper.hxx"
39 #include "spritecanvas.hxx"
40 #include "spritecanvashelper.hxx"
41 #include "canvasbitmap.hxx"
42 
43 
44 using namespace ::com::sun::star;
45 
46 namespace vclcanvas
47 {
48     SpriteDeviceHelper::SpriteDeviceHelper() :
49         mpBackBuffer()
50     {
51     }
52 
53     void SpriteDeviceHelper::init( const OutDevProviderSharedPtr& pOutDev )
54     {
55         DeviceHelper::init(pOutDev);
56 
57         // setup back buffer
58         OutputDevice& rOutDev( pOutDev->getOutDev() );
59         mpBackBuffer.reset( new BackBuffer( rOutDev ));
60         mpBackBuffer->setSize( rOutDev.GetOutputSizePixel() );
61 
62         // #i95645#
63 #if defined( QUARTZ )
64         // use AA on VCLCanvas for Mac
65         mpBackBuffer->getOutDev().SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW | mpBackBuffer->getOutDev().GetAntialiasing() );
66 #else
67         // switch off AA for WIN32 and UNIX, the VCLCanvas does not look good with it and
68         // is not required to do AA. It would need to be adapted to use it correctly
69         // (especially gradient painting). This will need extra work.
70         mpBackBuffer->getOutDev().SetAntialiasing(mpBackBuffer->getOutDev().GetAntialiasing() & ~ANTIALIASING_ENABLE_B2DDRAW);
71 #endif
72     }
73 
74     ::sal_Int32 SpriteDeviceHelper::createBuffers( ::sal_Int32 nBuffers )
75     {
76         (void)nBuffers;
77 
78         // TODO(F3): implement XBufferStrategy interface. For now, we
79         // _always_ will have exactly one backbuffer
80         return 1;
81     }
82 
83     void SpriteDeviceHelper::destroyBuffers()
84     {
85         // TODO(F3): implement XBufferStrategy interface. For now, we
86         // _always_ will have exactly one backbuffer
87     }
88 
89     ::sal_Bool SpriteDeviceHelper::showBuffer( bool, ::sal_Bool )
90     {
91         OSL_ENSURE(false,"Not supposed to be called, handled by SpriteCanvas");
92         return sal_False;
93     }
94 
95     ::sal_Bool SpriteDeviceHelper::switchBuffer( bool, ::sal_Bool )
96     {
97         OSL_ENSURE(false,"Not supposed to be called, handled by SpriteCanvas");
98         return sal_False;
99     }
100 
101     void SpriteDeviceHelper::disposing()
102     {
103         // release all references
104         mpBackBuffer.reset();
105 
106         DeviceHelper::disposing();
107     }
108 
109     uno::Any SpriteDeviceHelper::isAccelerated() const
110     {
111         return DeviceHelper::isAccelerated();
112     }
113 
114     uno::Any SpriteDeviceHelper::getDeviceHandle() const
115     {
116         return DeviceHelper::getDeviceHandle();
117     }
118 
119     uno::Any SpriteDeviceHelper::getSurfaceHandle() const
120     {
121         if( !mpBackBuffer )
122             return uno::Any();
123 
124         return uno::makeAny(
125             reinterpret_cast< sal_Int64 >(&mpBackBuffer->getOutDev()) );
126     }
127 
128     void SpriteDeviceHelper::notifySizeUpdate( const awt::Rectangle& rBounds )
129     {
130         if( mpBackBuffer )
131             mpBackBuffer->setSize( ::Size(rBounds.Width,
132                                           rBounds.Height) );
133     }
134 
135     void SpriteDeviceHelper::dumpScreenContent() const
136     {
137         DeviceHelper::dumpScreenContent();
138 
139         static sal_uInt32 nFilePostfixCount(0);
140 
141         if( mpBackBuffer )
142         {
143             String aFilename( String::CreateFromAscii("dbg_backbuffer") );
144             aFilename += String::CreateFromInt32(nFilePostfixCount);
145             aFilename += String::CreateFromAscii(".bmp");
146 
147             SvFileStream aStream( aFilename, STREAM_STD_READWRITE );
148 
149             const ::Point aEmptyPoint;
150             mpBackBuffer->getOutDev().EnableMapMode( sal_False );
151             aStream << mpBackBuffer->getOutDev().GetBitmap(aEmptyPoint,
152                                                             mpBackBuffer->getOutDev().GetOutputSizePixel());
153         }
154 
155         ++nFilePostfixCount;
156     }
157 
158 }
159