INTEGRATION: CWS canvas05 (1.2.2); FILE MERGED

2008/06/03 11:11:24 thb 1.2.2.6: Cleaned up image debugging stuff; fixed a few d3d debug warnings; fixed one deadlock rendering a bitmap from the same surface to itself; fixed premature ReleaseDC call in GraphicsProvider::getGraphics()
2008/06/02 22:20:50 thb 1.2.2.5: Removed obsolete XTunnel now for real; re-added size getter for BitmapCanvas; smallish cleanups
2008/04/21 07:29:23 thb 1.2.2.4: RESYNC: (1.3-1.4); FILE MERGED
2008/01/22 00:51:07 thb 1.2.2.3: RESYNC: (1.2-1.3); FILE MERGED
2008/01/22 00:25:23 thb 1.2.2.2: #i81092# Making gdiplus and dx canvas more independent
2007/12/20 22:18:57 thb 1.2.2.1: #i81092# #i78888# #i78925# #i79258# #i79437# #i84784# Large canvas rework, completing various areas such as color spaces, bitmap data access, true sprite and non-sprite implementations, and upstreaming the canvas parts of rodos emf+ rendering
This commit is contained in:
Kurt Zenker 2008-06-24 09:35:44 +00:00
parent 48116fec28
commit 305355ad77

View file

@ -7,7 +7,7 @@
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: dx_impltools.cxx,v $
* $Revision: 1.4 $
* $Revision: 1.5 $
*
* This file is part of OpenOffice.org.
*
@ -28,11 +28,15 @@
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_canvas.hxx"
#include <ctype.h> // don't ask. msdev breaks otherwise...
#include <basegfx/numeric/ftools.hxx>
#include <canvas/debug.hxx>
#include <canvas/verbosetrace.hxx>
#include <tools/diagnose_ex.h>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
@ -54,7 +58,8 @@
#include "dx_linepolypolygon.hxx"
#include "dx_canvasbitmap.hxx"
#include "dx_canvasfont.hxx"
#include "dx_surfacegraphics.hxx"
#include "dx_canvas.hxx"
#include "dx_spritecanvas.hxx"
#include <boost/scoped_array.hpp>
@ -103,7 +108,7 @@ namespace dxcanvas
// no implementation class and no data provider
// found - contract violation.
CHECK_AND_THROW( xLinePoly.is(),
ENSURE_ARG_OR_THROW( xLinePoly.is(),
"VCLCanvas::polyPolygonFromXPolyPolygon2D(): Invalid input "
"poly-polygon, cannot retrieve vertex data" );
@ -140,6 +145,22 @@ namespace dxcanvas
rGraphics.SetPageUnit(Gdiplus::UnitPixel);
}
Gdiplus::Graphics* createGraphicsFromHDC(HDC aHDC)
{
Gdiplus::Graphics* pRet = new Gdiplus::Graphics(aHDC);
if( pRet )
setupGraphics( *pRet );
return pRet;
}
Gdiplus::Graphics* createGraphicsFromBitmap(const BitmapSharedPtr& rBitmap)
{
Gdiplus::Graphics* pRet = Gdiplus::Graphics::FromImage(rBitmap.get());
if( pRet )
setupGraphics( *pRet );
return pRet;
}
void gdiPlusMatrixFromB2DHomMatrix( Gdiplus::Matrix& rGdiplusMatrix, const ::basegfx::B2DHomMatrix& rMatrix )
{
rGdiplusMatrix.SetElements( static_cast<Gdiplus::REAL>(rMatrix.get(0,0)),
@ -337,7 +358,7 @@ namespace dxcanvas
Gdiplus::ARGB sequenceToArgb( const uno::Sequence< sal_Int8 >& rColor )
{
ENSURE_AND_THROW( rColor.getLength() > 2,
ENSURE_OR_THROW( rColor.getLength() > 2,
"sequenceToArgb: need at least three channels" );
// TODO(F1): handle color space conversions, when defined on canvas/graphicDevice
@ -353,7 +374,7 @@ namespace dxcanvas
Gdiplus::ARGB sequenceToArgb( const uno::Sequence< double >& rColor )
{
ENSURE_AND_THROW( rColor.getLength() > 2,
ENSURE_OR_THROW( rColor.getLength() > 2,
"sequenceToColor: need at least three channels" );
// TODO(F1): handle color space conversions, when defined on canvas/graphicDevice
@ -446,20 +467,17 @@ namespace dxcanvas
}
}
namespace
bool drawGdiPlusBitmap( const GraphicsSharedPtr& rGraphics,
const BitmapSharedPtr& rBitmap )
{
bool drawGdiPlusBitmap( const SurfaceGraphicsSharedPtr& rGraphics,
const BitmapSharedPtr& rBitmap )
{
Gdiplus::PointF aPoint;
return (Gdiplus::Ok == (*rGraphics)->DrawImage( rBitmap.get(),
aPoint ) );
}
Gdiplus::PointF aPoint;
return (Gdiplus::Ok == rGraphics->DrawImage( rBitmap.get(),
aPoint ) );
}
bool drawDIBits( const SurfaceGraphicsSharedPtr& rGraphics,
const BITMAPINFO& rBI,
const void* pBits )
bool drawDIBits( const GraphicsSharedPtr& rGraphics,
const BITMAPINFO& rBI,
const void* pBits )
{
BitmapSharedPtr pBitmap(
Gdiplus::Bitmap::FromBITMAPINFO( &rBI,
@ -469,8 +487,8 @@ namespace dxcanvas
pBitmap );
}
bool drawRGBABits( const SurfaceGraphicsSharedPtr& rGraphics,
const RawRGBABitmap& rRawRGBAData )
bool drawRGBABits( const GraphicsSharedPtr& rGraphics,
const RawRGBABitmap& rRawRGBAData )
{
BitmapSharedPtr pBitmap( new Gdiplus::Bitmap( rRawRGBAData.mnWidth,
rRawRGBAData.mnHeight,
@ -499,59 +517,14 @@ namespace dxcanvas
pBitmap );
}
bool drawXBitmap( const SurfaceGraphicsSharedPtr& rGraphics,
const uno::Reference< rendering::XBitmap >& xBitmap )
{
CanvasBitmap* pBitmap = dynamic_cast< CanvasBitmap* >(xBitmap.get());
if( pBitmap )
{
// we're instructed to draw the xBitmap to the
// graphics object. moreover we know that the passed
// xBitmap is a disguised CanvasBitmap object from
// which we're able to directly access the pixel from
// the contained directx surface.
DXBitmapSharedPtr pDXBitmap( pBitmap->getSurface() );
return drawGdiPlusBitmap(rGraphics,pDXBitmap->getBitmap());
}
else if( drawVCLBitmapFromUnoTunnel(
rGraphics,
uno::Reference< lang::XUnoTunnel >( xBitmap,
uno::UNO_QUERY ) ) )
{
return true;
}
else
{
SpriteCanvas* pCanvas = dynamic_cast< SpriteCanvas* >(xBitmap.get());
if( pCanvas )
{
// we're instructed to draw the xBitmap to the
// graphics object. moreover we know that the passed
// xBitmap is a disguised SpriteCanvas object from
// which we're able to directly access the pixel from
// the contained directx surface.
DXBitmapSharedPtr pDXBitmap( pCanvas->getBackBuffer() );
return drawGdiPlusBitmap(rGraphics,pDXBitmap->getBitmap());
}
}
// TODO(F1): extract pixel from XBitmap interface
OSL_ENSURE( false,
"drawXBitmap(): could not extract bitmap" );
return false;
}
BitmapSharedPtr bitmapFromXBitmap( const uno::Reference< rendering::XBitmap >& xBitmap )
{
CanvasBitmap* pCanvasBitmap = dynamic_cast< CanvasBitmap* >(xBitmap.get());
BitmapProvider* pBitmapProvider = dynamic_cast< BitmapProvider* >(xBitmap.get());
if( pCanvasBitmap )
if( pBitmapProvider )
{
DXBitmapSharedPtr pDXBitmap( pCanvasBitmap->getSurface() );
return pDXBitmap->getBitmap();
IBitmapSharedPtr pBitmap( pBitmapProvider->getBitmap() );
return pBitmap->getBitmap();
}
else
{
@ -582,12 +555,11 @@ namespace dxcanvas
PixelFormat24bppRGB ) );
}
SurfaceGraphicsSharedPtr pSurface(new SurfaceGraphics(pBitmap));
tools::setupGraphics(*(pSurface->get()));
if( !drawVCLBitmapFromUnoTunnel(
pSurface,
uno::Reference< lang::XUnoTunnel >( xBitmap,
uno::UNO_QUERY ) ) )
GraphicsSharedPtr pGraphics(createGraphicsFromBitmap(pBitmap));
tools::setupGraphics(*pGraphics);
if( !drawVCLBitmapFromXBitmap(
pGraphics,
xBitmap) )
{
pBitmap.reset();
}
@ -600,7 +572,7 @@ namespace dxcanvas
{
CanvasFont* pCanvasFont = dynamic_cast< CanvasFont* >(xFont.get());
CHECK_AND_THROW( pCanvasFont,
ENSURE_ARG_OR_THROW( pCanvasFont,
"canvasFontFromXFont(): Invalid XFont (or incompatible font for this XCanvas)" );
return CanvasFont::ImplRef( pCanvasFont );