LibreOffice Module vcl (master)  1
openglgdiimpl.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  void DeferredTextDraw(OpenGLTexture const & rTexture, const Color nMaskColor, const SalTwoRect& rPosAry);
145 
146  void FlushDeferredDrawing();
147  void FlushLinesOrTriangles(DrawShaderType eType, RenderParameters const & rParameters);
148 
149 public:
150  // get the width of the device
151  GLfloat GetWidth() const { return mpProvider ? mpProvider->GetWidth() : 1; }
152 
153  // get the height of the device
154  GLfloat GetHeight() const { return mpProvider ? mpProvider->GetHeight() : 1; }
155 
160  bool IsOffscreen() const { return mpProvider == nullptr || mpProvider->IsOffScreen(); }
161 
163  enum XOROption { IGNORE_XOR, IMPLEMENT_XOR };
164 
165  // initialize pre-draw state
166  void InitializePreDrawState(XOROption eOpt);
167 
168  // operations to do before painting
169  void PreDraw(XOROption eOpt = IGNORE_XOR);
170 
171  // operations to do after painting
172  void PostDraw();
173 
174  void PostBatchDraw();
175 
176 protected:
177  bool AcquireContext(bool bForceCreate = false);
178  void ReleaseContext();
179 
181  virtual rtl::Reference<OpenGLContext> CreateWinContext() = 0;
182 
184  static bool UseContext( const rtl::Reference<OpenGLContext> &pContext )
185  {
186  return pContext->isInitialized() && // not released by the OS etc.
187  pContext->isVCLOnly();
188  }
189 
190 public:
192  virtual ~OpenGLSalGraphicsImpl () override;
193 
194  rtl::Reference<OpenGLContext> GetOpenGLContext();
195 
196  virtual void Init() override;
197 
198  virtual void DeInit() override;
199 
200  virtual void freeResources() override;
201 
202  const vcl::Region& getClipRegion() const;
203  virtual bool setClipRegion( const vcl::Region& ) override;
204 
205  //
206  // get the depth of the device
207  virtual sal_uInt16 GetBitCount() const override;
208 
209  // get the width of the device
210  virtual long GetGraphicsWidth() const override;
211 
212  // set the clip region to empty
213  virtual void ResetClipRegion() override;
214 
215  // set the line color to transparent (= don't draw lines)
216 
217  virtual void SetLineColor() override;
218 
219  // set the line color to a specific color
220  virtual void SetLineColor( Color nColor ) override;
221 
222  // set the fill color to transparent (= don't fill)
223  virtual void SetFillColor() override;
224 
225  // set the fill color to a specific color, shapes will be
226  // filled accordingly
227  virtual void SetFillColor( Color nColor ) override;
228 
229  // enable/disable XOR drawing
230  virtual void SetXORMode( bool bSet, bool bInvertOnly ) override;
231 
232  // set line color for raster operations
233  virtual void SetROPLineColor( SalROPColor nROPColor ) override;
234 
235  // set fill color for raster operations
236  virtual void SetROPFillColor( SalROPColor nROPColor ) override;
237 
238  // draw --> LineColor and FillColor and RasterOp and ClipRegion
239  virtual void drawPixel( long nX, long nY ) override;
240  virtual void drawPixel( long nX, long nY, Color nColor ) override;
241 
242  virtual void drawLine( long nX1, long nY1, long nX2, long nY2 ) override;
243 
244  virtual void drawRect( long nX, long nY, long nWidth, long nHeight ) override;
245 
246  virtual void drawPolyLine( sal_uInt32 nPoints, const SalPoint* pPtAry ) override;
247 
248  virtual void drawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry ) override;
249 
250  virtual void drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* pPoints, PCONSTSALPOINT* pPtAry ) override;
251 
252  virtual bool drawPolyPolygon(
253  const basegfx::B2DHomMatrix& rObjectToDevice,
255  double fTransparency) override;
256 
257  virtual bool drawPolyLine(
258  const basegfx::B2DHomMatrix& rObjectToDevice,
259  const basegfx::B2DPolygon&,
260  double fTransparency,
261  const basegfx::B2DVector& rLineWidths,
263  css::drawing::LineCap,
264  double fMiterMinimumAngle,
265  bool bPixelSnapHairline) override;
266 
267  virtual bool drawPolyLineBezier(
268  sal_uInt32 nPoints,
269  const SalPoint* pPtAry,
270  const PolyFlags* pFlgAry ) override;
271 
272  virtual bool drawPolygonBezier(
273  sal_uInt32 nPoints,
274  const SalPoint* pPtAry,
275  const PolyFlags* pFlgAry ) override;
276 
277  virtual bool drawPolyPolygonBezier(
278  sal_uInt32 nPoly,
279  const sal_uInt32* pPoints,
280  const SalPoint* const* pPtAry,
281  const PolyFlags* const* pFlgAry ) override;
282 
283  // CopyArea --> No RasterOp, but ClipRegion
284  virtual void copyArea(
285  long nDestX, long nDestY,
286  long nSrcX, long nSrcY,
287  long nSrcWidth, long nSrcHeight,
288  bool bWindowInvalidate ) override;
289 
290  // CopyBits and DrawBitmap --> RasterOp and ClipRegion
291  // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
292  void DoCopyBits(const SalTwoRect& rPosAry, OpenGLSalGraphicsImpl &rSrcImpl);
293 
294  virtual bool blendBitmap(
295  const SalTwoRect&,
296  const SalBitmap& rBitmap ) override;
297 
298  virtual bool blendAlphaBitmap(
299  const SalTwoRect&,
300  const SalBitmap& rSrcBitmap,
301  const SalBitmap& rMaskBitmap,
302  const SalBitmap& rAlphaBitmap ) override;
303 
304  virtual void drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap ) override;
305 
306  virtual void drawBitmap(
307  const SalTwoRect& rPosAry,
308  const SalBitmap& rSalBitmap,
309  const SalBitmap& rMaskBitmap ) override;
310 
311  virtual void drawMask(
312  const SalTwoRect& rPosAry,
313  const SalBitmap& rSalBitmap,
314  Color nMaskColor ) override;
315 
316  virtual std::shared_ptr<SalBitmap> getBitmap( long nX, long nY, long nWidth, long nHeight ) override;
317 
318  virtual Color getPixel( long nX, long nY ) override;
319 
320  // invert --> ClipRegion (only Windows or VirDevs)
321  virtual void invert(
322  long nX, long nY,
323  long nWidth, long nHeight,
324  SalInvert nFlags) override;
325 
326  virtual void invert( sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert nFlags ) override;
327 
328  virtual bool drawEPS(
329  long nX, long nY,
330  long nWidth, long nHeight,
331  void* pPtr,
332  sal_uInt32 nSize ) override;
333 
346  virtual bool drawAlphaBitmap(
347  const SalTwoRect&,
348  const SalBitmap& rSourceBitmap,
349  const SalBitmap& rAlphaBitmap ) override;
350 
352  virtual bool drawTransformedBitmap(
353  const basegfx::B2DPoint& rNull,
354  const basegfx::B2DPoint& rX,
355  const basegfx::B2DPoint& rY,
356  const SalBitmap& rSourceBitmap,
357  const SalBitmap* pAlphaBitmap) override;
358 
374  virtual bool drawAlphaRect(
375  long nX, long nY,
376  long nWidth, long nHeight,
377  sal_uInt8 nTransparency ) override;
378 
379  virtual bool drawGradient(const tools::PolyPolygon& rPolygon, const Gradient& rGradient) override;
380 
382  void flush();
383 
384 public:
386  void doFlush();
387 };
388 
389 #endif
390 
391 /* 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 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
bool IsOffscreen() const
check whether this instance is used for offscreen (Virtual Device) rendering ie.
virtual void freeResources()=0
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
SalGraphics & mrParent
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:48
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