diff options
author | Thorsten Behrens <tbehrens@suse.com> | 2013-10-11 16:19:15 +0200 |
---|---|---|
committer | Thorsten Behrens <thb@documentfoundation.org> | 2013-11-01 01:26:32 +0100 |
commit | 85e6215de5c332f651502c58931af609986a89d3 (patch) | |
tree | 8f9e166a070a478147db4802df0d61e54ffebf71 | |
parent | e0c1dc6fe6078eade26779a10f7410726d8d86c2 (diff) |
[API CHANGE] Have XCanvas provide all-surface erase-to-color.
And to make the names more telling, rename the old clear() method
to erase(), add new fill() for providing a color.
20 files changed, 178 insertions, 46 deletions
diff --git a/canvas/source/cairo/cairo_canvasbitmap.cxx b/canvas/source/cairo/cairo_canvasbitmap.cxx index 277c1333f4c9..db8607ae89f8 100644 --- a/canvas/source/cairo/cairo_canvasbitmap.cxx +++ b/canvas/source/cairo/cairo_canvasbitmap.cxx @@ -90,7 +90,7 @@ namespace cairocanvas maCanvasHelper.setSurface( mpBufferSurface, bHasAlpha ); // clear bitmap to 100% transparent - maCanvasHelper.clear(); + maCanvasHelper.erase(); } void CanvasBitmap::disposeThis() diff --git a/canvas/source/cairo/cairo_canvascustomsprite.cxx b/canvas/source/cairo/cairo_canvascustomsprite.cxx index e0c59b77a9b8..171336f73acb 100644 --- a/canvas/source/cairo/cairo_canvascustomsprite.cxx +++ b/canvas/source/cairo/cairo_canvascustomsprite.cxx @@ -60,7 +60,7 @@ namespace cairocanvas maSpriteHelper.setSurface( mpBufferSurface ); // clear sprite to 100% transparent - maCanvasHelper.clear(); + maCanvasHelper.erase(); } void CanvasCustomSprite::disposeThis() diff --git a/canvas/source/cairo/cairo_canvashelper.cxx b/canvas/source/cairo/cairo_canvashelper.cxx index ff2d71ed4064..28eb92e6b7fd 100644 --- a/canvas/source/cairo/cairo_canvashelper.cxx +++ b/canvas/source/cairo/cairo_canvashelper.cxx @@ -218,9 +218,9 @@ namespace cairocanvas cairo_set_operator( mpCairo.get(), compositingMode ); } - void CanvasHelper::clear() + void CanvasHelper::erase( double r, double g, double b, double alpha ) { - SAL_INFO( "canvas.cairo", "clear whole area: " << maSize.getX() << " x " << maSize.getY() ); + SAL_INFO( "canvas.cairo", "erase whole area: " << maSize.getX() << " x " << maSize.getY() ); if( mpCairo ) { @@ -231,9 +231,9 @@ namespace cairocanvas // internally converts to premultiplied alpha. but anyway, // this keeps it consistent with the other canvas impls if( mbHaveAlpha ) - cairo_set_source_rgba( mpCairo.get(), 1.0, 1.0, 1.0, 0.0 ); + cairo_set_source_rgba( mpCairo.get(), r, g, b, alpha ); else - cairo_set_source_rgb( mpCairo.get(), 1.0, 1.0, 1.0 ); + cairo_set_source_rgb( mpCairo.get(), r, g, b ); cairo_set_operator( mpCairo.get(), CAIRO_OPERATOR_SOURCE ); cairo_rectangle( mpCairo.get(), 0, 0, maSize.getX(), maSize.getY() ); @@ -243,6 +243,16 @@ namespace cairocanvas } } + void CanvasHelper::erase() + { + erase(1.0, 1.0, 1.0, 0.0); + } + + void CanvasHelper::fill(const uno::Sequence< double >& rColor) + { + erase(rColor[0], rColor[1], rColor[2], rColor[3] ); + } + void CanvasHelper::drawPoint( const rendering::XCanvas* , const geometry::RealPoint2D& , const rendering::ViewState& , diff --git a/canvas/source/cairo/cairo_canvashelper.hxx b/canvas/source/cairo/cairo_canvashelper.hxx index 8b83d2c292fa..c90e79a6764d 100644 --- a/canvas/source/cairo/cairo_canvashelper.hxx +++ b/canvas/source/cairo/cairo_canvashelper.hxx @@ -81,12 +81,17 @@ namespace cairocanvas void setSize( const ::basegfx::B2ISize& rSize ); void setSurface( const ::cairo::SurfaceSharedPtr& pSurface, bool bHasAlpha ); + /// erase whole viewport with given color + void erase( double r, double g, double b, double alpha ); + + // CanvasHelper functionality // ========================== // XCanvas (only providing, not implementing the // interface. Also note subtle method parameter differences) - void clear(); + void erase(); + void fill(const ::com::sun::star::uno::Sequence< double >& rColor); void drawPoint( const ::com::sun::star::rendering::XCanvas* pCanvas, const ::com::sun::star::geometry::RealPoint2D& aPoint, const ::com::sun::star::rendering::ViewState& viewState, diff --git a/canvas/source/directx/dx_canvascustomsprite.cxx b/canvas/source/directx/dx_canvascustomsprite.cxx index 96a01ca146d9..2eead3c588c4 100644 --- a/canvas/source/directx/dx_canvascustomsprite.cxx +++ b/canvas/source/directx/dx_canvascustomsprite.cxx @@ -68,7 +68,7 @@ namespace dxcanvas bShowSpriteBounds ); // clear sprite to 100% transparent - maCanvasHelper.clear(); + maCanvasHelper.erase(); } void CanvasCustomSprite::disposeThis() diff --git a/canvas/source/directx/dx_canvashelper.cxx b/canvas/source/directx/dx_canvashelper.cxx index 193c6f3b6c58..bdff93f56595 100644 --- a/canvas/source/directx/dx_canvashelper.cxx +++ b/canvas/source/directx/dx_canvashelper.cxx @@ -141,7 +141,7 @@ namespace dxcanvas maOutputOffset = rOutputOffset; } - void CanvasHelper::clear() + void CanvasHelper::erase() { if( needOutput() ) { @@ -151,10 +151,28 @@ namespace dxcanvas ENSURE_OR_THROW( Gdiplus::Ok == pGraphics->SetCompositingMode( Gdiplus::CompositingModeSourceCopy ), // force set, don't blend - "CanvasHelper::clear(): GDI+ SetCompositingMode call failed" ); + "CanvasHelper::erase(): GDI+ SetCompositingMode call failed" ); ENSURE_OR_THROW( Gdiplus::Ok == pGraphics->Clear( aClearColor ), - "CanvasHelper::clear(): GDI+ Clear call failed" ); + "CanvasHelper::erase(): GDI+ Clear call failed" ); + } + } + + void CanvasHelper::fill(const uno::Sequence< double >& rColor) + { + if( needOutput() ) + { + GraphicsSharedPtr pGraphics( mpGraphicsProvider->getGraphics() ); + Gdiplus::Color aClearColor = Gdiplus::Color( + tools::sequenceToArgb(rColor)); + + ENSURE_OR_THROW( + Gdiplus::Ok == pGraphics->SetCompositingMode( + Gdiplus::CompositingModeSourceCopy ), // force set, don't blend + "CanvasHelper::fill(): GDI+ SetCompositingMode call failed" ); + ENSURE_OR_THROW( + Gdiplus::Ok == pGraphics->Clear( aClearColor ), + "CanvasHelper::fill(): GDI+ Clear call failed" ); } } diff --git a/canvas/source/directx/dx_canvashelper.hxx b/canvas/source/directx/dx_canvashelper.hxx index 5a6527d2fd29..2a50695a8767 100644 --- a/canvas/source/directx/dx_canvashelper.hxx +++ b/canvas/source/directx/dx_canvashelper.hxx @@ -88,7 +88,8 @@ namespace dxcanvas // XCanvas (only providing, not implementing the // interface. Also note subtle method parameter differences) - void clear(); + void erase(); + void fill(const ::com::sun::star::uno::Sequence< double >& rColor); void drawPoint( const ::com::sun::star::rendering::XCanvas* pCanvas, const ::com::sun::star::geometry::RealPoint2D& aPoint, const ::com::sun::star::rendering::ViewState& viewState, diff --git a/canvas/source/opengl/ogl_canvashelper.cxx b/canvas/source/opengl/ogl_canvashelper.cxx index ae349b999839..017f5026a70a 100644 --- a/canvas/source/opengl/ogl_canvashelper.cxx +++ b/canvas/source/opengl/ogl_canvashelper.cxx @@ -407,11 +407,17 @@ namespace oglcanvas mpDeviceHelper = &rDeviceHelper; } - void CanvasHelper::clear() + void CanvasHelper::erase() { mpRecordedActions->clear(); } + void CanvasHelper::fill(const uno::Sequence< double >&) + { + // TODO(F3): implement color erase + mpRecordedActions->clear(); + } + void CanvasHelper::drawPoint( const rendering::XCanvas* /*pCanvas*/, const geometry::RealPoint2D& aPoint, const rendering::ViewState& viewState, diff --git a/canvas/source/opengl/ogl_canvashelper.hxx b/canvas/source/opengl/ogl_canvashelper.hxx index b7280ac1c9a1..606d4b2b4070 100644 --- a/canvas/source/opengl/ogl_canvashelper.hxx +++ b/canvas/source/opengl/ogl_canvashelper.hxx @@ -57,7 +57,8 @@ namespace oglcanvas // XCanvas (only providing, not implementing the // interface. Also note subtle method parameter differences) - void clear(); + void erase(); + void fill(const ::com::sun::star::uno::Sequence< double >& rColor); void drawPoint( const ::com::sun::star::rendering::XCanvas* pCanvas, const ::com::sun::star::geometry::RealPoint2D& aPoint, const ::com::sun::star::rendering::ViewState& viewState, diff --git a/canvas/source/tools/verifyinput.cxx b/canvas/source/tools/verifyinput.cxx index 48fdad5f6456..f123b7940c20 100644 --- a/canvas/source/tools/verifyinput.cxx +++ b/canvas/source/tools/verifyinput.cxx @@ -276,6 +276,28 @@ namespace canvas #endif } + void verifyInput( const uno::Sequence< double >& aColor, + const char* pStr, + const uno::Reference<uno::XInterface >& xIf, + ::sal_Int16 nArgPos ) + { + if( aColor.getLength() < 3 ) + { +#if OSL_DEBUG_LEVEL > 0 + throw lang::IllegalArgumentException( + OUString::createFromAscii(pStr) + + ": verifyInput(): device color has too few components (" + + OUString::number(3) + + " expected, " + + OUString::number(aColor.getLength()) + + " provided)", + xIf, nArgPos ); +#else + throw lang::IllegalArgumentException(); +#endif + } + } + void verifyInput( const rendering::ViewState& viewState, const char* pStr, const uno::Reference< uno::XInterface >& xIf, diff --git a/canvas/source/vcl/canvascustomsprite.cxx b/canvas/source/vcl/canvascustomsprite.cxx index 9dead83713de..adf876e289a3 100644 --- a/canvas/source/vcl/canvascustomsprite.cxx +++ b/canvas/source/vcl/canvascustomsprite.cxx @@ -114,7 +114,7 @@ namespace vclcanvas bShowSpriteBounds ); // clear sprite to 100% transparent - maCanvasHelper.clear(); + maCanvasHelper.erase(); } #define IMPLEMENTATION_NAME "VCLCanvas.CanvasCustomSprite" diff --git a/canvas/source/vcl/canvashelper.cxx b/canvas/source/vcl/canvashelper.cxx index 54fff82b4d74..3339a7c0543c 100644 --- a/canvas/source/vcl/canvashelper.cxx +++ b/canvas/source/vcl/canvashelper.cxx @@ -158,7 +158,7 @@ namespace vclcanvas mp2ndOutDev->getOutDev().SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW ); } - void CanvasHelper::clear() + void CanvasHelper::fill( Color aColor ) { // are we disposed? if( mpOutDev ) @@ -167,9 +167,8 @@ namespace vclcanvas tools::OutDevStateKeeper aStateKeeper( mpProtectedOutDev ); rOutDev.EnableMapMode( sal_False ); - rOutDev.SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW ); - rOutDev.SetLineColor( COL_WHITE ); - rOutDev.SetFillColor( COL_WHITE ); + rOutDev.SetLineColor( aColor ); + rOutDev.SetFillColor( aColor ); rOutDev.SetClipRegion(); rOutDev.DrawRect( Rectangle( Point(), rOutDev.GetOutputSizePixel()) ); @@ -180,7 +179,6 @@ namespace vclcanvas rOutDev2.SetDrawMode( DRAWMODE_DEFAULT ); rOutDev2.EnableMapMode( sal_False ); - rOutDev2.SetAntialiasing( ANTIALIASING_ENABLE_B2DDRAW ); rOutDev2.SetLineColor( COL_WHITE ); rOutDev2.SetFillColor( COL_WHITE ); rOutDev2.SetClipRegion(); @@ -192,6 +190,24 @@ namespace vclcanvas } } + void CanvasHelper::erase() + { + fill( Color(COL_WHITE) ); + } + + void CanvasHelper::fill(const uno::Sequence< double >& rColor) + { + Color aColor( COL_WHITE ); + if( rColor.getLength() > 2 ) + aColor = ::vcl::unotools::stdColorSpaceSequenceToColor(rColor); + + // make color opaque. Otherwise, OutputDevice won't draw + // anything + aColor.SetTransparency(0); + + fill( aColor ); + } + void CanvasHelper::drawPoint( const rendering::XCanvas* , const geometry::RealPoint2D& aPoint, const rendering::ViewState& viewState, diff --git a/canvas/source/vcl/canvashelper.hxx b/canvas/source/vcl/canvashelper.hxx index 69af00c13d6c..0291456587e4 100644 --- a/canvas/source/vcl/canvashelper.hxx +++ b/canvas/source/vcl/canvashelper.hxx @@ -95,13 +95,17 @@ namespace vclcanvas */ void setBackgroundOutDev( const OutDevProviderSharedPtr& rOutDev ); + /// Solid color fill of whole viewport + void fill( Color aColor ); + // CanvasHelper functionality // ========================== // XCanvas (only providing, not implementing the // interface. Also note subtle method parameter differences) - void clear(); + void erase(); + void fill(const ::com::sun::star::uno::Sequence< double >& rColor); void drawPoint( const ::com::sun::star::rendering::XCanvas* rCanvas, const ::com::sun::star::geometry::RealPoint2D& aPoint, const ::com::sun::star::rendering::ViewState& viewState, diff --git a/include/canvas/base/canvasbase.hxx b/include/canvas/base/canvasbase.hxx index 8f134d23289a..691311e34663 100644 --- a/include/canvas/base/canvasbase.hxx +++ b/include/canvas/base/canvasbase.hxx @@ -122,14 +122,28 @@ namespace canvas } // XCanvas - virtual void SAL_CALL clear() throw (::com::sun::star::uno::RuntimeException) + virtual void SAL_CALL erase() throw (::com::sun::star::uno::RuntimeException) { MutexType aGuard( BaseType::m_aMutex ); mbSurfaceDirty = true; maCanvasHelper.modifying(); - maCanvasHelper.clear(); + maCanvasHelper.erase(); + } + + virtual void SAL_CALL fill( const ::com::sun::star::uno::Sequence< double >& aColor ) throw (::com::sun::star::uno::RuntimeException) + { + tools::verifyArgs(aColor, + BOOST_CURRENT_FUNCTION, + static_cast< UnambiguousBaseType* >(this)); + + MutexType aGuard( BaseType::m_aMutex ); + + mbSurfaceDirty = true; + maCanvasHelper.modifying(); + + maCanvasHelper.fill( aColor ); } virtual void SAL_CALL drawPoint( const ::com::sun::star::geometry::RealPoint2D& aPoint, diff --git a/include/canvas/base/canvascustomspritebase.hxx b/include/canvas/base/canvascustomspritebase.hxx index 7c1b5508bb4e..19ba9738a783 100644 --- a/include/canvas/base/canvascustomspritebase.hxx +++ b/include/canvas/base/canvascustomspritebase.hxx @@ -105,14 +105,25 @@ namespace canvas } // XCanvas: selectively override base's methods here, for opacity tracking - virtual void SAL_CALL clear() throw (::com::sun::star::uno::RuntimeException) + virtual void SAL_CALL erase() throw (::com::sun::star::uno::RuntimeException) { typename BaseType::MutexType aGuard( BaseType::m_aMutex ); maSpriteHelper.clearingContent( this ); // and forward to base class, which handles the actual rendering - return BaseType::clear(); + BaseType::erase(); + } + + // XCanvas: selectively override base's methods here, for opacity tracking + virtual void SAL_CALL fill( const ::com::sun::star::uno::Sequence< double >& aColor ) throw (::com::sun::star::uno::RuntimeException) + { + typename BaseType::MutexType aGuard( BaseType::m_aMutex ); + + maSpriteHelper.clearingContent( this ); + + // and forward to base class, which handles the actual rendering + BaseType::fill( aColor ); } virtual ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XCachedPrimitive > SAL_CALL diff --git a/include/canvas/verifyinput.hxx b/include/canvas/verifyinput.hxx index 07d72b32ff6c..23a856acb169 100644 --- a/include/canvas/verifyinput.hxx +++ b/include/canvas/verifyinput.hxx @@ -208,6 +208,28 @@ namespace canvas ::com::sun::star::uno::XInterface >& xIf, ::sal_Int16 nArgPos ); + /** Basic check for color sequence validity. + + @param aColor + Device color value + + @param xIf + The interface that should be reported as the one + generating the exception. + + @param nArgPos + Argument position on the call site (i.e. the position of + the argument, checked here, on the UNO interface + method. Counting starts at 0). + + @throws an lang::IllegalArgumentException, if anything is wrong + */ + CANVASTOOLS_DLLPUBLIC void verifyInput( const ::com::sun::star::uno::Sequence< double >& aColor, + const char* pStr, + const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XInterface >& xIf, + ::sal_Int16 nArgPos ); + /** Basic check for view state validity. @param viewState diff --git a/offapi/com/sun/star/rendering/XCanvas.idl b/offapi/com/sun/star/rendering/XCanvas.idl index 28e2a8fe232e..5a97339d98d9 100644 --- a/offapi/com/sun/star/rendering/XCanvas.idl +++ b/offapi/com/sun/star/rendering/XCanvas.idl @@ -112,13 +112,20 @@ interface XTextLayout; */ interface XCanvas : ::com::sun::star::uno::XInterface { - /** Clear the whole canvas area.<p> + /** Erase the whole canvas area.<p> This method clears the whole canvas area to the device default - color (e.g. white for a printer, transparent for an + content (e.g. white for a printer, transparent for an XCustomSprite). */ - void clear(); + void erase(); + + /** Clears the whole canvas area to given color.<p> + + This method fills the whole canvas area with the given device + color. + */ + void clear( [in] sequence<ColorComponent> aColor ); /** Draw a point in device resolution on the device. diff --git a/sd/source/ui/presenter/PresenterCanvas.cxx b/sd/source/ui/presenter/PresenterCanvas.cxx index 415c339026ec..819f9eccc449 100644 --- a/sd/source/ui/presenter/PresenterCanvas.cxx +++ b/sd/source/ui/presenter/PresenterCanvas.cxx @@ -273,6 +273,13 @@ void SAL_CALL PresenterCanvas::clear (void) } +void SAL_CALL PresenterCanvas::fill (const css::uno::Sequence<double>&) + throw (css::uno::RuntimeException) +{ + ThrowIfDisposed(); + // ToDo: Clear the area covered by the child window. A simple forward + // would clear the whole shared canvas. +} void SAL_CALL PresenterCanvas::drawPoint ( diff --git a/sd/source/ui/presenter/PresenterCanvas.hxx b/sd/source/ui/presenter/PresenterCanvas.hxx index 46d637eabf05..fbf328c1561c 100644 --- a/sd/source/ui/presenter/PresenterCanvas.hxx +++ b/sd/source/ui/presenter/PresenterCanvas.hxx @@ -151,7 +151,10 @@ public: // XCanvas - virtual void SAL_CALL clear (void) + virtual void SAL_CALL erase (void) + throw (css::uno::RuntimeException); + + virtual void SAL_CALL fill (const css::uno::Sequence<double>& rColor) throw (css::uno::RuntimeException); virtual void SAL_CALL drawPoint ( diff --git a/sd/source/ui/slideshow/slideshowviewimpl.cxx b/sd/source/ui/slideshow/slideshowviewimpl.cxx index 45c9b2b1aa27..ec37c2028708 100644 --- a/sd/source/ui/slideshow/slideshowviewimpl.cxx +++ b/sd/source/ui/slideshow/slideshowviewimpl.cxx @@ -313,23 +313,8 @@ void SAL_CALL SlideShowView::clear() throw (::com::sun::star::uno::RuntimeExcept ::osl::MutexGuard aGuard( m_aMutex ); SolarMutexGuard aSolarGuard; - // fill the bounds rectangle in black - // ---------------------------------- - - const Size aWindowSize( mrOutputWindow.GetSizePixel() ); - - ::basegfx::B2DPolygon aPoly( ::basegfx::tools::createPolygonFromRect( - ::basegfx::B2DRectangle(0.0,0.0, - aWindowSize.Width(), - aWindowSize.Height() ) ) ); - ::cppcanvas::PolyPolygonSharedPtr pPolyPoly( - ::cppcanvas::BaseGfxFactory::getInstance().createPolyPolygon( mpCanvas, aPoly ) ); - - if( pPolyPoly.get() ) - { - pPolyPoly->setRGBAFillColor( 0x000000FFU ); - pPolyPoly->draw(); - } + // fill the whole slideshow window in black + mxSpriteCanvas->fill( vcl::unotools::colorToStdColorSpaceSequence( Color(0x000000FFU) )); } geometry::IntegerSize2D SAL_CALL SlideShowView::getTranslationOffset( ) throw (RuntimeException) |