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 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_canvas.hxx"
24 
25 #include <canvas/debug.hxx>
26 #include <canvas/canvastools.hxx>
27 #include <toolkit/helper/vclunohelper.hxx>
28 #include <vcl/canvastools.hxx>
29 #include <basegfx/tools/canvastools.hxx>
30 #include <vcl/dibtools.hxx>
31 
32 #include "spritedevicehelper.hxx"
33 #include "spritecanvas.hxx"
34 #include "spritecanvashelper.hxx"
35 #include "canvasbitmap.hxx"
36 
37 using namespace ::com::sun::star;
38 
39 namespace vclcanvas
40 {
SpriteDeviceHelper()41     SpriteDeviceHelper::SpriteDeviceHelper() :
42         mpBackBuffer()
43     {
44     }
45 
init(const OutDevProviderSharedPtr & pOutDev)46     void SpriteDeviceHelper::init( const OutDevProviderSharedPtr& pOutDev )
47     {
48         DeviceHelper::init(pOutDev);
49 
50         // setup back buffer
51         OutputDevice& rOutDev( pOutDev->getOutDev() );
52         mpBackBuffer.reset( new BackBuffer( rOutDev ));
53         mpBackBuffer->setSize( rOutDev.GetOutputSizePixel() );
54 
55         // #i95645#
56 #if defined( QUARTZ )
57         // use AA on VCLCanvas for Mac
58         mpBackBuffer->getOutDev().SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW | mpBackBuffer->getOutDev().GetAntialiasing() );
59 #else
60         // switch off AA for WIN32 and UNIX, the VCLCanvas does not look good with it and
61         // is not required to do AA. It would need to be adapted to use it correctly
62         // (especially gradient painting). This will need extra work.
63         mpBackBuffer->getOutDev().SetAntialiasing(mpBackBuffer->getOutDev().GetAntialiasing() & ~ANTIALIASING_ENABLE_B2DDRAW);
64 #endif
65     }
66 
createBuffers(::sal_Int32 nBuffers)67     ::sal_Int32 SpriteDeviceHelper::createBuffers( ::sal_Int32 nBuffers )
68     {
69         (void)nBuffers;
70 
71         // TODO(F3): implement XBufferStrategy interface. For now, we
72         // _always_ will have exactly one backbuffer
73         return 1;
74     }
75 
destroyBuffers()76     void SpriteDeviceHelper::destroyBuffers()
77     {
78         // TODO(F3): implement XBufferStrategy interface. For now, we
79         // _always_ will have exactly one backbuffer
80     }
81 
showBuffer(bool,::sal_Bool)82     ::sal_Bool SpriteDeviceHelper::showBuffer( bool, ::sal_Bool )
83     {
84         OSL_ENSURE(false,"Not supposed to be called, handled by SpriteCanvas");
85         return sal_False;
86     }
87 
switchBuffer(bool,::sal_Bool)88     ::sal_Bool SpriteDeviceHelper::switchBuffer( bool, ::sal_Bool )
89     {
90         OSL_ENSURE(false,"Not supposed to be called, handled by SpriteCanvas");
91         return sal_False;
92     }
93 
disposing()94     void SpriteDeviceHelper::disposing()
95     {
96         // release all references
97         mpBackBuffer.reset();
98 
99         DeviceHelper::disposing();
100     }
101 
isAccelerated() const102     uno::Any SpriteDeviceHelper::isAccelerated() const
103     {
104         return DeviceHelper::isAccelerated();
105     }
106 
getDeviceHandle() const107     uno::Any SpriteDeviceHelper::getDeviceHandle() const
108     {
109         return DeviceHelper::getDeviceHandle();
110     }
111 
getSurfaceHandle() const112     uno::Any SpriteDeviceHelper::getSurfaceHandle() const
113     {
114         if( !mpBackBuffer )
115             return uno::Any();
116 
117         return uno::makeAny(
118             reinterpret_cast< sal_Int64 >(&mpBackBuffer->getOutDev()) );
119     }
120 
notifySizeUpdate(const awt::Rectangle & rBounds)121     void SpriteDeviceHelper::notifySizeUpdate( const awt::Rectangle& rBounds )
122     {
123         if( mpBackBuffer )
124             mpBackBuffer->setSize( ::Size(rBounds.Width,
125                                           rBounds.Height) );
126     }
127 
dumpScreenContent() const128     void SpriteDeviceHelper::dumpScreenContent() const
129     {
130         DeviceHelper::dumpScreenContent();
131 
132         static sal_uInt32 nFilePostfixCount(0);
133 
134         if( mpBackBuffer )
135         {
136             String aFilename( String::CreateFromAscii("dbg_backbuffer") );
137             aFilename += String::CreateFromInt32(nFilePostfixCount);
138             aFilename += String::CreateFromAscii(".bmp");
139 
140             SvFileStream aStream( aFilename, STREAM_STD_READWRITE );
141 
142             const ::Point aEmptyPoint;
143             mpBackBuffer->getOutDev().EnableMapMode( sal_False );
144             mpBackBuffer->getOutDev().SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW );
145             WriteDIB(mpBackBuffer->getOutDev().GetBitmap(aEmptyPoint, mpBackBuffer->getOutDev().GetOutputSizePixel()), aStream, false, true);
146         }
147 
148         ++nFilePostfixCount;
149     }
150 
151 }
152