Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / inc / openglgdiimpl.hxx
blobe0693495fd53caf21fcbf81a20d0b9b427634523
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_OPENGLGDIIMPL_HXX
21 #define INCLUDED_VCL_OPENGLGDIIMPL_HXX
23 #include "salgeom.hxx"
24 #include "salgdiimpl.hxx"
25 #include <vcl/dllapi.h>
27 #include "opengl/framebuffer.hxx"
28 #include "opengl/program.hxx"
29 #include "opengl/texture.hxx"
30 #include "regionband.hxx"
32 #include <tools/poly.hxx>
33 #include <vcl/opengl/OpenGLContext.hxx>
35 class SalFrame;
36 class SalVirtualDevice;
37 class OpenGLTests;
39 namespace basegfx
41 class B2DTrapezoid;
44 struct TextureCombo
46 std::unique_ptr<OpenGLTexture> mpTexture;
47 std::unique_ptr<OpenGLTexture> mpMask;
50 class VCL_DLLPUBLIC OpenGLSalGraphicsImpl : public SalGraphicsImpl
52 friend class OpenGLTests;
53 protected:
55 rtl::Reference<OpenGLContext> mpContext;
56 SalGraphics& mrParent;
57 /// Pointer to the SalFrame or SalVirtualDevice
58 SalGeometryProvider* mpProvider;
59 OpenGLFramebuffer* mpFramebuffer;
60 OpenGLProgram* mpProgram;
62 /// Is it someone else's context we shouldn't be fiddling with ?
63 static bool IsForeignContext(const rtl::Reference<OpenGLContext> &xContext);
65 // clipping
66 vcl::Region maClipRegion;
67 bool mbUseScissor;
68 bool mbUseStencil;
70 bool mbOffscreen;
71 OpenGLTexture maOffscreenTex;
73 SalColor mnLineColor;
74 SalColor mnFillColor;
75 #ifdef DBG_UTIL
76 bool mProgramIsSolidColor;
77 #endif
78 SalColor mProgramSolidColor;
79 double mProgramSolidTransparency;
81 void ImplInitClipRegion();
82 void ImplSetClipBit( const vcl::Region& rClip, GLuint nMask );
83 void ImplDrawLineAA( double nX1, double nY1, double nX2, double nY2, bool edge = false );
84 bool CheckOffscreenTexture();
86 void ApplyProgramMatrices(float fPixelOffset = 0.0);
88 public:
89 bool UseProgram( const OUString& rVertexShader, const OUString& rFragmentShader, const OString& preamble = "" );
90 bool UseSolid( SalColor nColor, sal_uInt8 nTransparency );
91 bool UseSolid( SalColor nColor, double fTransparency );
92 bool UseSolid( SalColor nColor );
93 bool UseSolidAA( SalColor nColor, double fTransparency );
94 bool UseSolidAA( SalColor nColor );
95 bool UseInvert();
97 void DrawPoint( long nX, long nY );
98 void DrawLine( double nX1, double nY1, double nX2, double nY2 );
99 void DrawLines( sal_uInt32 nPoints, const SalPoint* pPtAry, bool bClose );
100 void DrawLineAA( double nX1, double nY1, double nX2, double nY2 );
101 void DrawLinesAA( sal_uInt32 nPoints, const SalPoint* pPtAry, bool bClose );
102 void DrawEdgeAA( double nX1, double nY1, double nX2, double nY2 );
103 void DrawConvexPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry, bool blockAA = false );
104 void DrawConvexPolygon( const Polygon& rPolygon, bool blockAA = false );
105 void DrawTrapezoid( const basegfx::B2DTrapezoid& trapezoid, bool blockAA = false );
106 void DrawRect( long nX, long nY, long nWidth, long nHeight );
107 void DrawRect( const Rectangle& rRect );
108 void DrawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry );
109 void DrawPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPolygon, bool blockAA = false );
110 void DrawRegionBand( const RegionBand& rRegion );
111 void DrawTextureRect( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted = false );
112 void DrawTexture( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted = false );
113 void DrawTransformedTexture( OpenGLTexture& rTexture, OpenGLTexture& rMask, const basegfx::B2DPoint& rNull, const basegfx::B2DPoint& rX, const basegfx::B2DPoint& rY );
114 void DrawAlphaTexture( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted = false, bool pPremultiplied = false );
115 void DrawTextureDiff( OpenGLTexture& rTexture, OpenGLTexture& rMask, const SalTwoRect& rPosAry, bool bInverted = false );
116 void DrawTextureWithMask( OpenGLTexture& rTexture, OpenGLTexture& rMask, const SalTwoRect& rPosAry );
117 void DrawBlendedTexture( OpenGLTexture& rTexture, OpenGLTexture& rMask, OpenGLTexture& rAlpha, const SalTwoRect& rPosAry );
118 void DrawMask( OpenGLTexture& rTexture, SalColor nMaskColor, const SalTwoRect& rPosAry );
119 void DrawLinearGradient( const Gradient& rGradient, const Rectangle& rRect );
120 void DrawAxialGradient( const Gradient& rGradient, const Rectangle& rRect );
121 void DrawRadialGradient( const Gradient& rGradient, const Rectangle& rRect );
123 public:
124 // get the width of the device
125 GLfloat GetWidth() const { return mpProvider ? mpProvider->GetWidth() : 1; }
127 // get the height of the device
128 GLfloat GetHeight() const { return mpProvider ? mpProvider->GetHeight() : 1; }
130 // check whether this instance is used for offscreen rendering
131 bool IsOffscreen() const { return mpProvider == nullptr || mpProvider->IsOffScreen(); }
133 // operations to do before painting
134 void PreDraw();
136 // operations to do after painting
137 void PostDraw();
139 protected:
140 bool AcquireContext();
141 bool ReleaseContext();
143 // retrieve the default context for offscreen rendering
144 static rtl::Reference<OpenGLContext> GetDefaultContext();
146 // create a new context for window rendering
147 virtual rtl::Reference<OpenGLContext> CreateWinContext() = 0;
149 // check whether the given context can be used by this instance
150 virtual bool UseContext( const rtl::Reference<OpenGLContext> &pContext ) = 0;
152 public:
153 OpenGLSalGraphicsImpl(SalGraphics& pParent, SalGeometryProvider *pProvider);
154 virtual ~OpenGLSalGraphicsImpl ();
156 rtl::Reference<OpenGLContext> GetOpenGLContext();
158 virtual void Init() SAL_OVERRIDE;
160 virtual void DeInit() SAL_OVERRIDE;
162 virtual void freeResources() SAL_OVERRIDE;
164 const vcl::Region& getClipRegion() const;
165 virtual bool setClipRegion( const vcl::Region& ) SAL_OVERRIDE;
168 // get the depth of the device
169 virtual sal_uInt16 GetBitCount() const SAL_OVERRIDE;
171 // get the width of the device
172 virtual long GetGraphicsWidth() const SAL_OVERRIDE;
174 // set the clip region to empty
175 virtual void ResetClipRegion() SAL_OVERRIDE;
177 // set the line color to transparent (= don't draw lines)
179 virtual void SetLineColor() SAL_OVERRIDE;
181 // set the line color to a specific color
182 virtual void SetLineColor( SalColor nSalColor ) SAL_OVERRIDE;
184 // set the fill color to transparent (= don't fill)
185 virtual void SetFillColor() SAL_OVERRIDE;
187 // set the fill color to a specific color, shapes will be
188 // filled accordingly
189 virtual void SetFillColor( SalColor nSalColor ) SAL_OVERRIDE;
191 // enable/disable XOR drawing
192 virtual void SetXORMode( bool bSet, bool bInvertOnly ) SAL_OVERRIDE;
194 // set line color for raster operations
195 virtual void SetROPLineColor( SalROPColor nROPColor ) SAL_OVERRIDE;
197 // set fill color for raster operations
198 virtual void SetROPFillColor( SalROPColor nROPColor ) SAL_OVERRIDE;
200 // draw --> LineColor and FillColor and RasterOp and ClipRegion
201 virtual void drawPixel( long nX, long nY ) SAL_OVERRIDE;
202 virtual void drawPixel( long nX, long nY, SalColor nSalColor ) SAL_OVERRIDE;
204 virtual void drawLine( long nX1, long nY1, long nX2, long nY2 ) SAL_OVERRIDE;
206 virtual void drawRect( long nX, long nY, long nWidth, long nHeight ) SAL_OVERRIDE;
208 virtual void drawPolyLine( sal_uInt32 nPoints, const SalPoint* pPtAry ) SAL_OVERRIDE;
210 virtual void drawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry ) SAL_OVERRIDE;
212 virtual void drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* pPoints, PCONSTSALPOINT* pPtAry ) SAL_OVERRIDE;
213 virtual bool drawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double fTransparency ) SAL_OVERRIDE;
215 virtual bool drawPolyLine(
216 const ::basegfx::B2DPolygon&,
217 double fTransparency,
218 const ::basegfx::B2DVector& rLineWidths,
219 basegfx::B2DLineJoin,
220 com::sun::star::drawing::LineCap) SAL_OVERRIDE;
222 virtual bool drawPolyLineBezier(
223 sal_uInt32 nPoints,
224 const SalPoint* pPtAry,
225 const sal_uInt8* pFlgAry ) SAL_OVERRIDE;
227 virtual bool drawPolygonBezier(
228 sal_uInt32 nPoints,
229 const SalPoint* pPtAry,
230 const sal_uInt8* pFlgAry ) SAL_OVERRIDE;
232 virtual bool drawPolyPolygonBezier(
233 sal_uInt32 nPoly,
234 const sal_uInt32* pPoints,
235 const SalPoint* const* pPtAry,
236 const sal_uInt8* const* pFlgAry ) SAL_OVERRIDE;
238 // CopyArea --> No RasterOp, but ClipRegion
239 virtual void copyArea(
240 long nDestX, long nDestY,
241 long nSrcX, long nSrcY,
242 long nSrcWidth, long nSrcHeight,
243 sal_uInt16 nFlags ) SAL_OVERRIDE;
245 // CopyBits and DrawBitmap --> RasterOp and ClipRegion
246 // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
247 void DoCopyBits(const SalTwoRect& rPosAry, OpenGLSalGraphicsImpl &rSrcImpl);
249 virtual bool blendBitmap(
250 const SalTwoRect&,
251 const SalBitmap& rBitmap ) SAL_OVERRIDE;
253 virtual bool blendAlphaBitmap(
254 const SalTwoRect&,
255 const SalBitmap& rSrcBitmap,
256 const SalBitmap& rMaskBitmap,
257 const SalBitmap& rAlphaBitmap ) SAL_OVERRIDE;
259 virtual void drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap ) SAL_OVERRIDE;
261 virtual void drawBitmap(
262 const SalTwoRect& rPosAry,
263 const SalBitmap& rSalBitmap,
264 SalColor nTransparentColor ) SAL_OVERRIDE;
266 virtual void drawBitmap(
267 const SalTwoRect& rPosAry,
268 const SalBitmap& rSalBitmap,
269 const SalBitmap& rMaskBitmap ) SAL_OVERRIDE;
271 virtual void drawMask(
272 const SalTwoRect& rPosAry,
273 const SalBitmap& rSalBitmap,
274 SalColor nMaskColor ) SAL_OVERRIDE;
276 virtual SalBitmap* getBitmap( long nX, long nY, long nWidth, long nHeight ) SAL_OVERRIDE;
278 virtual SalColor getPixel( long nX, long nY ) SAL_OVERRIDE;
280 // invert --> ClipRegion (only Windows or VirDevs)
281 virtual void invert(
282 long nX, long nY,
283 long nWidth, long nHeight,
284 SalInvert nFlags) SAL_OVERRIDE;
286 virtual void invert( sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert nFlags ) SAL_OVERRIDE;
288 virtual bool drawEPS(
289 long nX, long nY,
290 long nWidth, long nHeight,
291 void* pPtr,
292 sal_uLong nSize ) SAL_OVERRIDE;
294 /** Render bitmap with alpha channel
296 @param rSourceBitmap
297 Source bitmap to blit
299 @param rAlphaBitmap
300 Alpha channel to use for blitting
302 @return true, if the operation succeeded, and false
303 otherwise. In this case, clients should try to emulate alpha
304 compositing themselves
306 virtual bool drawAlphaBitmap(
307 const SalTwoRect&,
308 const SalBitmap& rSourceBitmap,
309 const SalBitmap& rAlphaBitmap ) SAL_OVERRIDE;
311 /** draw transformed bitmap (maybe with alpha) where Null, X, Y define the coordinate system */
312 virtual bool drawTransformedBitmap(
313 const basegfx::B2DPoint& rNull,
314 const basegfx::B2DPoint& rX,
315 const basegfx::B2DPoint& rY,
316 const SalBitmap& rSourceBitmap,
317 const SalBitmap* pAlphaBitmap) SAL_OVERRIDE;
319 /** Render solid rectangle with given transparency
321 @param nTransparency
322 Transparency value (0-255) to use. 0 blits and opaque, 255 a
323 fully transparent rectangle
325 virtual bool drawAlphaRect(
326 long nX, long nY,
327 long nWidth, long nHeight,
328 sal_uInt8 nTransparency ) SAL_OVERRIDE;
330 virtual bool drawGradient(const tools::PolyPolygon& rPolygon, const Gradient& rGradient) SAL_OVERRIDE;
332 virtual OpenGLContext *beginPaint() SAL_OVERRIDE;
333 private:
336 #endif
338 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */