LibreOffice Module vcl (master)  1
opengl/gdiimpl.hxx
Go to the documentation of this file.
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_VCL_OPENGLGDIIMPL_HXX
21 #define INCLUDED_VCL_OPENGLGDIIMPL_HXX
22 
23 #include <vcl/dllapi.h>
25 
26 #include <regionband.hxx>
27 #include <salgeom.hxx>
28 #include <salgdiimpl.hxx>
29 #include <opengl/program.hxx>
30 #include <opengl/texture.hxx>
31 #include <opengl/RenderList.hxx>
32 
33 #include <memory>
34 
35 class SalFrame;
36 class SalVirtualDevice;
37 class OpenGLTests;
38 
39 namespace basegfx
40 {
41 class B2DTrapezoid;
42 };
43 
44 namespace tools
45 {
46  class Polygon;
47  class PolyPolygon;
48 }
49 
51 {
52  std::unique_ptr<OpenGLTexture> mpTexture;
53  std::unique_ptr<OpenGLTexture> mpMask;
54 };
55 
56 class OpenGLFlushIdle;
57 
59 {
60  friend class OpenGLTests;
61 protected:
62 
65 
69 
74 
76  std::unique_ptr<OpenGLFlushIdle> mpFlush;
77 
78  // clipping
82 
83  bool mbXORMode;
84 
86 
93 
96 #ifdef DBG_UTIL
98 #endif
99  sal_uInt32 mnDrawCount;
100  sal_uInt32 mnDrawCountAtFlush;
103 
104  std::unique_ptr<RenderList> mpRenderList;
105 
106  void ImplInitClipRegion();
107  void ImplSetClipBit( const vcl::Region& rClip, GLuint nMask );
108  void ImplDrawLineAA( double nX1, double nY1, double nX2, double nY2, bool edge );
109  void CheckOffscreenTexture();
110 
111  void ApplyProgramMatrices(float fPixelOffset = 0.0);
112 
113 public:
114  bool UseProgram( const OUString& rVertexShader, const OUString& rFragmentShader, const OString& preamble = "" );
115  bool UseSolid( Color nColor, sal_uInt8 nTransparency );
116  bool UseSolid( Color nColor, double fTransparency );
117  bool UseSolid( Color nColor );
118  void UseSolid();
119  bool UseLine(Color nColor, double fTransparency, GLfloat fLineWidth, bool bUseAA);
120  void UseLine(GLfloat fLineWidth, bool bUseAA);
121  bool UseInvert50();
122  bool UseInvert(SalInvert nFlags);
123 
124  void DrawConvexPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry, bool blockAA = false );
125  void DrawConvexPolygon( const tools::Polygon& rPolygon, bool blockAA );
126  void DrawTrapezoid( const basegfx::B2DTrapezoid& trapezoid, bool blockAA );
127  void DrawRect( long nX, long nY, long nWidth, long nHeight );
128  void DrawRect( const tools::Rectangle& rRect );
129  void DrawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry );
130  void DrawLineSegment(float x1, float y1, float x2, float y2);
131  void DrawPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPolygon, bool blockAA = false );
132  void DrawRegionBand( const RegionBand& rRegion );
133  void DrawTextureRect( const SalTwoRect& rPosAry );
134  void DrawTexture( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted = false );
135  void DrawTransformedTexture( OpenGLTexture& rTexture, OpenGLTexture& rMask, const basegfx::B2DPoint& rNull, const basegfx::B2DPoint& rX, const basegfx::B2DPoint& rY );
136  void DrawAlphaTexture( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted, bool pPremultiplied );
137  void DrawTextureDiff( OpenGLTexture& rTexture, OpenGLTexture& rMask, const SalTwoRect& rPosAry, bool bInverted );
138  void DrawTextureWithMask( OpenGLTexture& rTexture, OpenGLTexture& rMask, const SalTwoRect& rPosAry );
139  void DrawBlendedTexture( OpenGLTexture& rTexture, OpenGLTexture& rMask, OpenGLTexture& rAlpha, const SalTwoRect& rPosAry );
140  void DrawMask( OpenGLTexture& rTexture, Color nMaskColor, const SalTwoRect& rPosAry );
141  void DrawLinearGradient( const Gradient& rGradient, const tools::Rectangle& rRect );
142  void DrawAxialGradient( const Gradient& rGradient, const tools::Rectangle& rRect );
143  void DrawRadialGradient( const Gradient& rGradient, const tools::Rectangle& rRect );
144 
145  void FlushDeferredDrawing();
146  void FlushLinesOrTriangles(DrawShaderType eType, RenderParameters const & rParameters);
147 
148 public:
149  // get the width of the device
150  GLfloat GetWidth() const { return mpProvider ? mpProvider->GetWidth() : 1; }
151 
152  // get the height of the device
153  GLfloat GetHeight() const { return mpProvider ? mpProvider->GetHeight() : 1; }
154 
159  bool IsOffscreen() const { return mpProvider == nullptr || mpProvider->IsOffScreen(); }
160 
162  enum XOROption { IGNORE_XOR, IMPLEMENT_XOR };
163 
164  // initialize pre-draw state
165  void InitializePreDrawState(XOROption eOpt);
166 
167  // operations to do before painting
168  void PreDraw(XOROption eOpt = IGNORE_XOR);
169 
170  // operations to do after painting
171  void PostDraw();
172 
173  void PostBatchDraw();
174 
175 protected:
176  bool AcquireContext(bool bForceCreate = false);
177  void ReleaseContext();
178 
180  virtual rtl::Reference<OpenGLContext> CreateWinContext() = 0;
181 
183  static bool UseContext( const rtl::Reference<OpenGLContext> &pContext )
184  {
185  return pContext->isInitialized() && // not released by the OS etc.
186  pContext->isVCLOnly();
187  }
188 
189 public:
191  virtual ~OpenGLSalGraphicsImpl () override;
192 
193  rtl::Reference<OpenGLContext> GetOpenGLContext();
194 
195  virtual void Init() override;
196 
197  virtual void DeInit() override;
198 
199  virtual void freeResources() override;
200 
201  virtual OUString getRenderBackendName() const override { return "opengl"; }
202 
203  const vcl::Region& getClipRegion() const;
204  virtual bool setClipRegion( const vcl::Region& ) override;
205 
206  //
207  // get the depth of the device
208  virtual sal_uInt16 GetBitCount() const override;
209 
210  // get the width of the device
211  virtual long GetGraphicsWidth() const override;
212 
213  // set the clip region to empty
214  virtual void ResetClipRegion() override;
215 
216  // set the line color to transparent (= don't draw lines)
217 
218  virtual void SetLineColor() override;
219 
220  // set the line color to a specific color
221  virtual void SetLineColor( Color nColor ) override;
222 
223  // set the fill color to transparent (= don't fill)
224  virtual void SetFillColor() override;
225 
226  // set the fill color to a specific color, shapes will be
227  // filled accordingly
228  virtual void SetFillColor( Color nColor ) override;
229 
230  // enable/disable XOR drawing
231  virtual void SetXORMode( bool bSet, bool bInvertOnly ) override;
232 
233  // set line color for raster operations
234  virtual void SetROPLineColor( SalROPColor nROPColor ) override;
235 
236  // set fill color for raster operations
237  virtual void SetROPFillColor( SalROPColor nROPColor ) override;
238 
239  // draw --> LineColor and FillColor and RasterOp and ClipRegion
240  virtual void drawPixel( long nX, long nY ) override;
241  virtual void drawPixel( long nX, long nY, Color nColor ) override;
242 
243  virtual void drawLine( long nX1, long nY1, long nX2, long nY2 ) override;
244 
245  virtual void drawRect( long nX, long nY, long nWidth, long nHeight ) override;
246 
247  virtual void drawPolyLine( sal_uInt32 nPoints, const SalPoint* pPtAry ) override;
248 
249  virtual void drawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry ) override;
250 
251  virtual void drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* pPoints, PCONSTSALPOINT* pPtAry ) override;
252 
253  virtual bool drawPolyPolygon(
254  const basegfx::B2DHomMatrix& rObjectToDevice,
256  double fTransparency) override;
257 
258  virtual bool drawPolyLine(
259  const basegfx::B2DHomMatrix& rObjectToDevice,
260  const basegfx::B2DPolygon&,
261  double fTransparency,
262  const basegfx::B2DVector& rLineWidths,
263  const std::vector< double >* pStroke, // MM01
265  css::drawing::LineCap,
266  double fMiterMinimumAngle,
267  bool bPixelSnapHairline) override;
268 
269  virtual bool drawPolyLineBezier(
270  sal_uInt32 nPoints,
271  const SalPoint* pPtAry,
272  const PolyFlags* pFlgAry ) override;
273 
274  virtual bool drawPolygonBezier(
275  sal_uInt32 nPoints,
276  const SalPoint* pPtAry,
277  const PolyFlags* pFlgAry ) override;
278 
279  virtual bool drawPolyPolygonBezier(
280  sal_uInt32 nPoly,
281  const sal_uInt32* pPoints,
282  const SalPoint* const* pPtAry,
283  const PolyFlags* const* pFlgAry ) override;
284 
285  // CopyArea --> No RasterOp, but ClipRegion
286  virtual void copyArea(
287  long nDestX, long nDestY,
288  long nSrcX, long nSrcY,
289  long nSrcWidth, long nSrcHeight,
290  bool bWindowInvalidate ) override;
291 
292  // CopyBits and DrawBitmap --> RasterOp and ClipRegion
293  // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
294  void DoCopyBits(const SalTwoRect& rPosAry, OpenGLSalGraphicsImpl &rSrcImpl);
295 
296  virtual bool blendBitmap(
297  const SalTwoRect&,
298  const SalBitmap& rBitmap ) override;
299 
300  virtual bool blendAlphaBitmap(
301  const SalTwoRect&,
302  const SalBitmap& rSrcBitmap,
303  const SalBitmap& rMaskBitmap,
304  const SalBitmap& rAlphaBitmap ) override;
305 
306  virtual void drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap ) override;
307 
308  virtual void drawBitmap(
309  const SalTwoRect& rPosAry,
310  const SalBitmap& rSalBitmap,
311  const SalBitmap& rMaskBitmap ) override;
312 
313  virtual void drawMask(
314  const SalTwoRect& rPosAry,
315  const SalBitmap& rSalBitmap,
316  Color nMaskColor ) override;
317 
318  virtual std::shared_ptr<SalBitmap> getBitmap( long nX, long nY, long nWidth, long nHeight ) override;
319 
320  virtual Color getPixel( long nX, long nY ) override;
321 
322  // invert --> ClipRegion (only Windows or VirDevs)
323  virtual void invert(
324  long nX, long nY,
325  long nWidth, long nHeight,
326  SalInvert nFlags) override;
327 
328  virtual void invert( sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert nFlags ) override;
329 
330  virtual bool drawEPS(
331  long nX, long nY,
332  long nWidth, long nHeight,
333  void* pPtr,
334  sal_uInt32 nSize ) override;
335 
348  virtual bool drawAlphaBitmap(
349  const SalTwoRect&,
350  const SalBitmap& rSourceBitmap,
351  const SalBitmap& rAlphaBitmap ) override;
352 
354  virtual bool drawTransformedBitmap(
355  const basegfx::B2DPoint& rNull,
356  const basegfx::B2DPoint& rX,
357  const basegfx::B2DPoint& rY,
358  const SalBitmap& rSourceBitmap,
359  const SalBitmap* pAlphaBitmap) override;
360 
376  virtual bool drawAlphaRect(
377  long nX, long nY,
378  long nWidth, long nHeight,
379  sal_uInt8 nTransparency ) override;
380 
381  virtual bool drawGradient(const tools::PolyPolygon& rPolygon, const Gradient& rGradient) override;
382 
383  virtual bool supportsOperation(OutDevSupportType eType) const override;
384 
386  void flush();
387 
388 public:
390  void doFlush();
391 };
392 
393 #endif
394 
395 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Interface used to share logic on sizing between SalVirtualDevices and SalFrames.
Definition: salgeom.hxx:62
std::unique_ptr< OpenGLTexture > mpMask
std::unique_ptr< OpenGLTexture > mpTexture
virtual std::shared_ptr< SalBitmap > getBitmap(long nX, long nY, long nWidth, long nHeight)=0
virtual void drawRect(long nX, long nY, long nWidth, long nHeight)=0
virtual void drawBitmap(const SalTwoRect &rPosAry, const SalBitmap &rSalBitmap)=0
SalROPColor
Definition: salgtype.hxx:80
SalGeometryProvider * mpProvider
Pointer to the SalFrame or SalVirtualDevice.
virtual OUString getRenderBackendName() const override
virtual bool drawAlphaBitmap(const SalTwoRect &, const SalBitmap &rSourceBitmap, const SalBitmap &rAlphaBitmap)=0
virtual Color getPixel(long nX, long nY)=0
virtual void SetXORMode(bool bSet, bool bInvertOnly)=0
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
virtual void copyArea(long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth, long nSrcHeight, bool bWindowInvalidate)=0
DrawShaderType
Definition: program.hxx:36
virtual void drawPolyLine(sal_uInt32 nPoints, const SalPoint *pPtAry)=0
virtual long GetWidth() const =0
virtual bool supportsOperation(OutDevSupportType eType) const =0
bool IsOffscreen() const
check whether this instance is used for offscreen (Virtual Device) rendering ie.
virtual void freeResources()=0
OutDevSupportType
Definition: vclenum.hxx:198
virtual void drawPixel(long nX, long nY)=0
virtual bool drawGradient(const tools::PolyPolygon &rPolygon, const Gradient &rGradient)=0
virtual bool blendBitmap(const SalTwoRect &, const SalBitmap &rBitmap)=0
virtual void invert(long nX, long nY, long nWidth, long nHeight, SalInvert nFlags)=0
virtual long GetGraphicsWidth() const =0
virtual void SetLineColor()=0
virtual bool drawAlphaRect(long nX, long nY, long nWidth, long nHeight, sal_uInt8 nTransparency)=0
XOROption
Oddly not all operations obey the XOR option.
virtual void drawPolygon(sal_uInt32 nPoints, const SalPoint *pPtAry)=0
virtual bool drawPolyPolygonBezier(sal_uInt32 nPoly, const sal_uInt32 *pPoints, const SalPoint *const *pPtAry, const PolyFlags *const *pFlgAry)=0
virtual void DeInit()
Definition: salgdiimpl.hxx:49
virtual bool drawTransformedBitmap(const basegfx::B2DPoint &rNull, const basegfx::B2DPoint &rX, const basegfx::B2DPoint &rY, const SalBitmap &rSourceBitmap, const SalBitmap *pAlphaBitmap)=0
draw transformed bitmap (maybe with alpha) where Null, X, Y define the coordinate system ...
virtual void drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32 *pPoints, PCONSTSALPOINT *pPtAry)=0
SalInvert
Definition: salgtype.hxx:84
virtual void drawLine(long nX1, long nY1, long nX2, long nY2)=0
virtual bool setClipRegion(const vcl::Region &)=0
std::unique_ptr< OpenGLFlushIdle > mpFlush
This idle handler is used to swap buffers after rendering.
virtual bool drawPolygonBezier(sal_uInt32 nPoints, const SalPoint *pPtAry, const PolyFlags *pFlgAry)=0
virtual void Init()=0
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:112
GLfloat GetWidth() const
virtual bool blendAlphaBitmap(const SalTwoRect &, const SalBitmap &rSrcBitmap, const SalBitmap &rMaskBitmap, const SalBitmap &rAlphaBitmap)=0
GLfloat GetHeight() const
unsigned char sal_uInt8
virtual long GetHeight() const =0
A non-visible drawable/buffer (e.g. an X11 Pixmap).
Definition: salvd.hxx:28
virtual void ResetClipRegion()=0
virtual void SetFillColor()=0
virtual void SetROPFillColor(SalROPColor nROPColor)=0
virtual bool drawEPS(long nX, long nY, long nWidth, long nHeight, void *pPtr, sal_uInt32 nSize)=0
rtl::Reference< OpenGLContext > mpContext
This context is whatever is most convenient to render to maOffscreenTex with.
virtual bool IsOffScreen() const =0
static bool UseContext(const rtl::Reference< OpenGLContext > &pContext)
check whether the given context can be used for off-screen rendering
virtual bool drawPolyLineBezier(sal_uInt32 nPoints, const SalPoint *pPtAry, const PolyFlags *pFlgAry)=0
OpenGLProgram * mpProgram
virtual void drawMask(const SalTwoRect &rPosAry, const SalBitmap &rSalBitmap, Color nMaskColor)=0
rtl::Reference< OpenGLContext > mpWindowContext
This context is solely for blitting maOffscreenTex.
virtual void SetROPLineColor(SalROPColor nROPColor)=0
std::unique_ptr< RenderList > mpRenderList
virtual sal_uInt16 GetBitCount() const =0
OpenGLTexture maOffscreenTex
All rendering happens to this off-screen texture.
PolyFlags