1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #ifndef INCLUDED_CANVAS_SOURCE_DIRECTX_DX_CANVASHELPER_HXX 21 #define INCLUDED_CANVAS_SOURCE_DIRECTX_DX_CANVASHELPER_HXX 22 23 #include <com/sun/star/rendering/XCanvas.hpp> 24 #include <com/sun/star/rendering/XBitmapCanvas.hpp> 25 #include <com/sun/star/rendering/XIntegerBitmap.hpp> 26 27 #include <basegfx/vector/b2isize.hxx> 28 #include <basegfx/vector/b2dsize.hxx> 29 30 #include "dx_graphicsprovider.hxx" 31 #include "dx_gdiplususer.hxx" 32 #include "dx_impltools.hxx" 33 34 35 namespace dxcanvas 36 { 37 /** Helper class for basic canvas functionality. Also offers 38 optional backbuffer painting, when providing it with a second 39 HDC to render into. 40 */ 41 class CanvasHelper 42 { 43 public: 44 CanvasHelper(); 45 46 /// make noncopyable 47 CanvasHelper(const CanvasHelper&) = delete; 48 const CanvasHelper& operator=(const CanvasHelper&) = delete; 49 50 /// Release all references 51 void disposing(); 52 53 /** Initialize canvas helper 54 55 This method late-initializes the canvas helper, providing 56 it with the necessary device and output objects. Note that 57 the CanvasHelper does <em>not</em> take ownership of the 58 passed rDevice reference, nor does it perform any 59 reference counting. Thus, to prevent the reference counted 60 SpriteCanvas object from deletion, the user of this class 61 is responsible for holding ref-counted references itself! 62 63 @param rDevice 64 Reference device this canvas is associated with 65 66 */ 67 void setDevice( css::rendering::XGraphicDevice& rDevice ); 68 69 /** Set the target for rendering operations 70 71 @param rTarget 72 Render target 73 */ 74 void setTarget( const GraphicsProviderSharedPtr& rTarget ); 75 76 /** Set the target for rendering operations 77 78 @param rTarget 79 Render target 80 81 @param rOutputOffset 82 Output offset in pixel 83 */ 84 void setTarget( const GraphicsProviderSharedPtr& rTarget, 85 const ::basegfx::B2ISize& rOutputOffset ); 86 87 88 // CanvasHelper functionality 89 // ========================== 90 91 // XCanvas (only providing, not implementing the 92 // interface. Also note subtle method parameter differences) 93 void clear(); 94 void drawPoint( const css::rendering::XCanvas* pCanvas, 95 const css::geometry::RealPoint2D& aPoint, 96 const css::rendering::ViewState& viewState, 97 const css::rendering::RenderState& renderState ); 98 void drawLine( const css::rendering::XCanvas* pCanvas, 99 const css::geometry::RealPoint2D& aStartPoint, 100 const css::geometry::RealPoint2D& aEndPoint, 101 const css::rendering::ViewState& viewState, 102 const css::rendering::RenderState& renderState ); 103 void drawBezier( const css::rendering::XCanvas* pCanvas, 104 const css::geometry::RealBezierSegment2D& aBezierSegment, 105 const css::geometry::RealPoint2D& aEndPoint, 106 const css::rendering::ViewState& viewState, 107 const css::rendering::RenderState& renderState ); 108 css::uno::Reference< css::rendering::XCachedPrimitive > 109 drawPolyPolygon( const css::rendering::XCanvas* pCanvas, 110 const css::uno::Reference< 111 css::rendering::XPolyPolygon2D >& xPolyPolygon, 112 const css::rendering::ViewState& viewState, 113 const css::rendering::RenderState& renderState ); 114 css::uno::Reference< css::rendering::XCachedPrimitive > 115 strokePolyPolygon( const css::rendering::XCanvas* pCanvas, 116 const css::uno::Reference< 117 css::rendering::XPolyPolygon2D >& xPolyPolygon, 118 const css::rendering::ViewState& viewState, 119 const css::rendering::RenderState& renderState, 120 const css::rendering::StrokeAttributes& strokeAttributes ); 121 css::uno::Reference< css::rendering::XCachedPrimitive > 122 strokeTexturedPolyPolygon( const css::rendering::XCanvas* pCanvas, 123 const css::uno::Reference< 124 css::rendering::XPolyPolygon2D >& xPolyPolygon, 125 const css::rendering::ViewState& viewState, 126 const css::rendering::RenderState& renderState, 127 const css::uno::Sequence< 128 css::rendering::Texture >& textures, 129 const css::rendering::StrokeAttributes& strokeAttributes ); 130 css::uno::Reference< css::rendering::XCachedPrimitive > 131 strokeTextureMappedPolyPolygon( const css::rendering::XCanvas* pCanvas, 132 const css::uno::Reference< 133 css::rendering::XPolyPolygon2D >& xPolyPolygon, 134 const css::rendering::ViewState& viewState, 135 const css::rendering::RenderState& renderState, 136 const css::uno::Sequence< 137 css::rendering::Texture >& textures, 138 const css::uno::Reference< 139 css::geometry::XMapping2D >& xMapping, 140 const css::rendering::StrokeAttributes& strokeAttributes ); 141 css::uno::Reference< css::rendering::XPolyPolygon2D > 142 queryStrokeShapes( const css::rendering::XCanvas* pCanvas, 143 const css::uno::Reference< 144 css::rendering::XPolyPolygon2D >& xPolyPolygon, 145 const css::rendering::ViewState& viewState, 146 const css::rendering::RenderState& renderState, 147 const css::rendering::StrokeAttributes& strokeAttributes ); 148 css::uno::Reference< css::rendering::XCachedPrimitive > 149 fillPolyPolygon( const css::rendering::XCanvas* pCanvas, 150 const css::uno::Reference< 151 css::rendering::XPolyPolygon2D >& xPolyPolygon, 152 const css::rendering::ViewState& viewState, 153 const css::rendering::RenderState& renderState ); 154 css::uno::Reference< css::rendering::XCachedPrimitive > 155 fillTexturedPolyPolygon( const css::rendering::XCanvas* pCanvas, 156 const css::uno::Reference< 157 css::rendering::XPolyPolygon2D >& xPolyPolygon, 158 const css::rendering::ViewState& viewState, 159 const css::rendering::RenderState& renderState, 160 const css::uno::Sequence< 161 css::rendering::Texture >& textures ); 162 css::uno::Reference< css::rendering::XCachedPrimitive > 163 fillTextureMappedPolyPolygon( const css::rendering::XCanvas* pCanvas, 164 const css::uno::Reference< 165 css::rendering::XPolyPolygon2D >& xPolyPolygon, 166 const css::rendering::ViewState& viewState, 167 const css::rendering::RenderState& renderState, 168 const css::uno::Sequence< 169 css::rendering::Texture >& textures, 170 const css::uno::Reference< 171 css::geometry::XMapping2D >& xMapping ); 172 173 css::uno::Reference< css::rendering::XCanvasFont > 174 createFont( const css::rendering::XCanvas* pCanvas, 175 const css::rendering::FontRequest& fontRequest, 176 const css::uno::Sequence< 177 css::beans::PropertyValue >& extraFontProperties, 178 const css::geometry::Matrix2D& fontMatrix ); 179 180 css::uno::Sequence< css::rendering::FontInfo > 181 queryAvailableFonts( const css::rendering::XCanvas* pCanvas, 182 const css::rendering::FontInfo& aFilter, 183 const css::uno::Sequence< 184 css::beans::PropertyValue >& aFontProperties ); 185 186 css::uno::Reference< css::rendering::XCachedPrimitive > 187 drawText( const css::rendering::XCanvas* pCanvas, 188 const css::rendering::StringContext& text, 189 const css::uno::Reference< 190 css::rendering::XCanvasFont >& xFont, 191 const css::rendering::ViewState& viewState, 192 const css::rendering::RenderState& renderState, 193 sal_Int8 textDirection ); 194 195 css::uno::Reference< css::rendering::XCachedPrimitive > 196 drawTextLayout( const css::rendering::XCanvas* pCanvas, 197 const css::uno::Reference< 198 css::rendering::XTextLayout >& laidOutText, 199 const css::rendering::ViewState& viewState, 200 const css::rendering::RenderState& renderState ); 201 202 css::uno::Reference< css::rendering::XCachedPrimitive > 203 drawBitmap( const css::rendering::XCanvas* pCanvas, 204 const css::uno::Reference< 205 css::rendering::XBitmap >& xBitmap, 206 const css::rendering::ViewState& viewState, 207 const css::rendering::RenderState& renderState ); 208 css::uno::Reference< css::rendering::XCachedPrimitive > 209 drawBitmapModulated( const css::rendering::XCanvas* pCanvas, 210 const css::uno::Reference< 211 css::rendering::XBitmap >& xBitmap, 212 const css::rendering::ViewState& viewState, 213 const css::rendering::RenderState& renderState ); 214 css::uno::Reference< css::rendering::XGraphicDevice > 215 getDevice(); 216 217 // Flush drawing queue to screen 218 void flush() const; 219 220 /** Called from XCanvas base classes, to notify that content 221 is _about_ to change 222 */ modifying()223 void modifying() {} 224 225 protected: 226 /// Refcounted global GDI+ state container 227 GDIPlusUserSharedPtr mpGdiPlusUser; 228 229 /** Phyical output device 230 231 Deliberately not a refcounted reference, because of 232 potential circular references for spritecanvas. 233 */ 234 css::rendering::XGraphicDevice* mpDevice; 235 236 /// Provides the Gdiplus::Graphics to render into 237 GraphicsProviderSharedPtr mpGraphicsProvider; 238 needOutput() const239 bool needOutput() const { return mpGraphicsProvider.get() != nullptr; }; 240 241 // returns transparency of color 242 void setupGraphicsState( GraphicsSharedPtr const & rGraphics, 243 const css::rendering::ViewState& viewState, 244 const css::rendering::RenderState& renderState ); 245 246 Gdiplus::CompositingMode calcCompositingMode( sal_Int8 nMode ); 247 248 /// Current (transformation-independent) output buffer offset 249 ::basegfx::B2ISize maOutputOffset; 250 }; 251 } 252 253 #endif // INCLUDED_CANVAS_SOURCE_DIRECTX_DX_CANVASHELPER_HXX 254 255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 256