xref: /AOO41X/main/canvas/source/vcl/spritedevicehelper.cxx (revision 25ea7f451e822ec0589487f23a9b6cc31f03fcc3)
1*25ea7f45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*25ea7f45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*25ea7f45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*25ea7f45SAndrew Rist  * distributed with this work for additional information
6*25ea7f45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*25ea7f45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*25ea7f45SAndrew Rist  * "License"); you may not use this file except in compliance
9*25ea7f45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*25ea7f45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*25ea7f45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*25ea7f45SAndrew Rist  * software distributed under the License is distributed on an
15*25ea7f45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*25ea7f45SAndrew Rist  * KIND, either express or implied.  See the License for the
17*25ea7f45SAndrew Rist  * specific language governing permissions and limitations
18*25ea7f45SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*25ea7f45SAndrew Rist  *************************************************************/
21*25ea7f45SAndrew Rist 
22*25ea7f45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_canvas.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <canvas/debug.hxx>
28cdf0e10cSrcweir #include <canvas/canvastools.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
31cdf0e10cSrcweir #include <vcl/canvastools.hxx>
32cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "spritedevicehelper.hxx"
35cdf0e10cSrcweir #include "spritecanvas.hxx"
36cdf0e10cSrcweir #include "spritecanvashelper.hxx"
37cdf0e10cSrcweir #include "canvasbitmap.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir using namespace ::com::sun::star;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir namespace vclcanvas
43cdf0e10cSrcweir {
44cdf0e10cSrcweir     SpriteDeviceHelper::SpriteDeviceHelper() :
45cdf0e10cSrcweir         mpBackBuffer()
46cdf0e10cSrcweir     {
47cdf0e10cSrcweir     }
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     void SpriteDeviceHelper::init( const OutDevProviderSharedPtr& pOutDev )
50cdf0e10cSrcweir     {
51cdf0e10cSrcweir         DeviceHelper::init(pOutDev);
52cdf0e10cSrcweir 
53cdf0e10cSrcweir         // setup back buffer
54cdf0e10cSrcweir         OutputDevice& rOutDev( pOutDev->getOutDev() );
55cdf0e10cSrcweir         mpBackBuffer.reset( new BackBuffer( rOutDev ));
56cdf0e10cSrcweir         mpBackBuffer->setSize( rOutDev.GetOutputSizePixel() );
57cdf0e10cSrcweir 
58cdf0e10cSrcweir         // #i95645#
59cdf0e10cSrcweir #if defined( QUARTZ )
60cdf0e10cSrcweir         // use AA on VCLCanvas for Mac
61cdf0e10cSrcweir         mpBackBuffer->getOutDev().SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW | mpBackBuffer->getOutDev().GetAntialiasing() );
62cdf0e10cSrcweir #else
63cdf0e10cSrcweir         // switch off AA for WIN32 and UNIX, the VCLCanvas does not look good with it and
64cdf0e10cSrcweir         // is not required to do AA. It would need to be adapted to use it correctly
65cdf0e10cSrcweir         // (especially gradient painting). This will need extra work.
66cdf0e10cSrcweir         mpBackBuffer->getOutDev().SetAntialiasing(mpBackBuffer->getOutDev().GetAntialiasing() & ~ANTIALIASING_ENABLE_B2DDRAW);
67cdf0e10cSrcweir #endif
68cdf0e10cSrcweir     }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     ::sal_Int32 SpriteDeviceHelper::createBuffers( ::sal_Int32 nBuffers )
71cdf0e10cSrcweir     {
72cdf0e10cSrcweir         (void)nBuffers;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir         // TODO(F3): implement XBufferStrategy interface. For now, we
75cdf0e10cSrcweir         // _always_ will have exactly one backbuffer
76cdf0e10cSrcweir         return 1;
77cdf0e10cSrcweir     }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     void SpriteDeviceHelper::destroyBuffers()
80cdf0e10cSrcweir     {
81cdf0e10cSrcweir         // TODO(F3): implement XBufferStrategy interface. For now, we
82cdf0e10cSrcweir         // _always_ will have exactly one backbuffer
83cdf0e10cSrcweir     }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     ::sal_Bool SpriteDeviceHelper::showBuffer( bool, ::sal_Bool )
86cdf0e10cSrcweir     {
87cdf0e10cSrcweir         OSL_ENSURE(false,"Not supposed to be called, handled by SpriteCanvas");
88cdf0e10cSrcweir         return sal_False;
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     ::sal_Bool SpriteDeviceHelper::switchBuffer( bool, ::sal_Bool )
92cdf0e10cSrcweir     {
93cdf0e10cSrcweir         OSL_ENSURE(false,"Not supposed to be called, handled by SpriteCanvas");
94cdf0e10cSrcweir         return sal_False;
95cdf0e10cSrcweir     }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     void SpriteDeviceHelper::disposing()
98cdf0e10cSrcweir     {
99cdf0e10cSrcweir         // release all references
100cdf0e10cSrcweir         mpBackBuffer.reset();
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         DeviceHelper::disposing();
103cdf0e10cSrcweir     }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     uno::Any SpriteDeviceHelper::isAccelerated() const
106cdf0e10cSrcweir     {
107cdf0e10cSrcweir         return DeviceHelper::isAccelerated();
108cdf0e10cSrcweir     }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     uno::Any SpriteDeviceHelper::getDeviceHandle() const
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         return DeviceHelper::getDeviceHandle();
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     uno::Any SpriteDeviceHelper::getSurfaceHandle() const
116cdf0e10cSrcweir     {
117cdf0e10cSrcweir         if( !mpBackBuffer )
118cdf0e10cSrcweir             return uno::Any();
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         return uno::makeAny(
121cdf0e10cSrcweir             reinterpret_cast< sal_Int64 >(&mpBackBuffer->getOutDev()) );
122cdf0e10cSrcweir     }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     void SpriteDeviceHelper::notifySizeUpdate( const awt::Rectangle& rBounds )
125cdf0e10cSrcweir     {
126cdf0e10cSrcweir         if( mpBackBuffer )
127cdf0e10cSrcweir             mpBackBuffer->setSize( ::Size(rBounds.Width,
128cdf0e10cSrcweir                                           rBounds.Height) );
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     void SpriteDeviceHelper::dumpScreenContent() const
132cdf0e10cSrcweir     {
133cdf0e10cSrcweir         DeviceHelper::dumpScreenContent();
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         static sal_uInt32 nFilePostfixCount(0);
136cdf0e10cSrcweir 
137cdf0e10cSrcweir         if( mpBackBuffer )
138cdf0e10cSrcweir         {
139cdf0e10cSrcweir             String aFilename( String::CreateFromAscii("dbg_backbuffer") );
140cdf0e10cSrcweir             aFilename += String::CreateFromInt32(nFilePostfixCount);
141cdf0e10cSrcweir             aFilename += String::CreateFromAscii(".bmp");
142cdf0e10cSrcweir 
143cdf0e10cSrcweir             SvFileStream aStream( aFilename, STREAM_STD_READWRITE );
144cdf0e10cSrcweir 
145cdf0e10cSrcweir             const ::Point aEmptyPoint;
146cdf0e10cSrcweir             mpBackBuffer->getOutDev().EnableMapMode( sal_False );
147cdf0e10cSrcweir             aStream << mpBackBuffer->getOutDev().GetBitmap(aEmptyPoint,
148cdf0e10cSrcweir                                                             mpBackBuffer->getOutDev().GetOutputSizePixel());
149cdf0e10cSrcweir         }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir         ++nFilePostfixCount;
152cdf0e10cSrcweir     }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir }
155