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 "dx_surfacegraphics.hxx" 28 #include "dx_impltools.hxx" 29 30 using namespace ::com::sun::star; 31 32 namespace dxcanvas 33 { 34 namespace 35 { 36 struct GraphicsDeleter 37 { 38 COMReference<surface_type> mpSurface; 39 HDC maHDC; 40 GraphicsDeleterdxcanvas::__anon7103cdda0111::GraphicsDeleter41 GraphicsDeleter(const COMReference<surface_type>& rSurface, HDC hdc) : 42 mpSurface(rSurface), 43 maHDC(hdc) 44 {} 45 operator ()dxcanvas::__anon7103cdda0111::GraphicsDeleter46 void operator()( Gdiplus::Graphics* pGraphics ) 47 { 48 if(!pGraphics) 49 return; 50 51 pGraphics->Flush(Gdiplus::FlushIntentionSync); 52 delete pGraphics; 53 54 if(mpSurface.is()) 55 mpSurface->ReleaseDC( maHDC ); 56 } 57 }; 58 } 59 createSurfaceGraphics(const COMReference<surface_type> & rSurface)60 GraphicsSharedPtr createSurfaceGraphics(const COMReference<surface_type>& rSurface ) 61 { 62 Gdiplus::Graphics* pGraphics; 63 GraphicsSharedPtr pRet; 64 HDC aHDC; 65 if( SUCCEEDED(rSurface->GetDC( &aHDC )) ) 66 { 67 pGraphics = Gdiplus::Graphics::FromHDC( aHDC ); 68 if(pGraphics) 69 { 70 tools::setupGraphics( *pGraphics ); 71 pRet.reset(pGraphics, 72 GraphicsDeleter(rSurface, aHDC)); 73 return pRet; 74 } 75 else 76 rSurface->ReleaseDC( aHDC ); 77 } 78 79 throw uno::RuntimeException(); 80 } 81 } 82