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