Line data Source code
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 "salgeom.hxx"
24 : #include "salgdiimpl.hxx"
25 : #include <vcl/dllapi.h>
26 :
27 : #include "opengl/framebuffer.hxx"
28 : #include "opengl/program.hxx"
29 : #include "opengl/texture.hxx"
30 : #include "regionband.hxx"
31 :
32 : #include <tools/poly.hxx>
33 : #include <vcl/opengl/OpenGLContext.hxx>
34 :
35 : class SalFrame;
36 : class SalVirtualDevice;
37 :
38 : namespace basegfx
39 : {
40 : class B2DTrapezoid;
41 : };
42 :
43 : class VCL_PLUGIN_PUBLIC OpenGLSalGraphicsImpl : public SalGraphicsImpl
44 : {
45 : protected:
46 :
47 : OpenGLContext* mpContext;
48 : SalGraphics& mrParent;
49 : /// Pointer to the SalFrame or SalVirtualDevice
50 : SalGeometryProvider* mpProvider;
51 : OpenGLFramebuffer* mpFramebuffer;
52 : OpenGLProgram* mpProgram;
53 :
54 : // clipping
55 : vcl::Region maClipRegion;
56 : bool mbUseScissor;
57 : bool mbUseStencil;
58 :
59 : bool mbOffscreen;
60 : OpenGLTexture maOffscreenTex;
61 :
62 : SalColor mnLineColor;
63 : SalColor mnFillColor;
64 : #ifdef DBG_UTIL
65 : bool mProgramIsSolidColor;
66 : #endif
67 : SalColor mProgramSolidColor;
68 : double mProgramSolidTransparency;
69 :
70 : void ImplInitClipRegion();
71 : void ImplSetClipBit( const vcl::Region& rClip, GLuint nMask );
72 : void ImplDrawLineAA( double nX1, double nY1, double nX2, double nY2, bool edge = false );
73 : bool CheckOffscreenTexture();
74 :
75 : public:
76 : bool UseProgram( const OUString& rVertexShader, const OUString& rFragmentShader, const OString& preamble = "" );
77 : bool UseSolid( SalColor nColor, sal_uInt8 nTransparency );
78 : bool UseSolid( SalColor nColor, double fTransparency );
79 : bool UseSolid( SalColor nColor );
80 : bool UseSolidAA( SalColor nColor, double fTransparency );
81 : bool UseSolidAA( SalColor nColor );
82 : bool UseInvert();
83 :
84 : void DrawPoint( long nX, long nY );
85 : void DrawLine( double nX1, double nY1, double nX2, double nY2 );
86 : void DrawLines( sal_uInt32 nPoints, const SalPoint* pPtAry, bool bClose );
87 : void DrawLineAA( double nX1, double nY1, double nX2, double nY2 );
88 : void DrawLinesAA( sal_uInt32 nPoints, const SalPoint* pPtAry, bool bClose );
89 : void DrawEdgeAA( double nX1, double nY1, double nX2, double nY2 );
90 : void DrawConvexPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry, bool blockAA = false );
91 : void DrawConvexPolygon( const Polygon& rPolygon, bool blockAA = false );
92 : void DrawTrapezoid( const basegfx::B2DTrapezoid& trapezoid, bool blockAA = false );
93 : void DrawRect( long nX, long nY, long nWidth, long nHeight );
94 : void DrawRect( const Rectangle& rRect );
95 : void DrawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry );
96 : void DrawPolyPolygon( const basegfx::B2DPolyPolygon& rPolyPolygon, bool blockAA = false );
97 : void DrawRegionBand( const RegionBand& rRegion );
98 : void DrawTextureRect( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted = false );
99 : void DrawTexture( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted = false );
100 : void DrawTransformedTexture( OpenGLTexture& rTexture, OpenGLTexture& rMask, const basegfx::B2DPoint& rNull, const basegfx::B2DPoint& rX, const basegfx::B2DPoint& rY );
101 : void DrawAlphaTexture( OpenGLTexture& rTexture, const SalTwoRect& rPosAry, bool bInverted = false, bool pPremultiplied = false );
102 : void DrawTextureDiff( OpenGLTexture& rTexture, OpenGLTexture& rMask, const SalTwoRect& rPosAry, bool bInverted = false );
103 : void DrawTextureWithMask( OpenGLTexture& rTexture, OpenGLTexture& rMask, const SalTwoRect& rPosAry );
104 : void DrawBlendedTexture( OpenGLTexture& rTexture, OpenGLTexture& rMask, OpenGLTexture& rAlpha, const SalTwoRect& rPosAry );
105 : void DrawMask( OpenGLTexture& rTexture, SalColor nMaskColor, const SalTwoRect& rPosAry );
106 : void DrawLinearGradient( const Gradient& rGradient, const Rectangle& rRect );
107 : void DrawAxialGradient( const Gradient& rGradient, const Rectangle& rRect );
108 : void DrawRadialGradient( const Gradient& rGradient, const Rectangle& rRect );
109 :
110 : public:
111 : // get the width of the device
112 0 : GLfloat GetWidth() const { return mpProvider ? mpProvider->GetWidth() : 1; }
113 :
114 : // get the height of the device
115 0 : GLfloat GetHeight() const { return mpProvider ? mpProvider->GetHeight() : 1; }
116 :
117 : // check whether this instance is used for offscreen rendering
118 0 : bool IsOffscreen() const { return mpProvider == nullptr || mpProvider->IsOffScreen(); }
119 :
120 : // operations to do before painting
121 : void PreDraw();
122 :
123 : // operations to do after painting
124 : void PostDraw();
125 :
126 : protected:
127 : bool AcquireContext();
128 : bool ReleaseContext();
129 :
130 : // retrieve the default context for offscreen rendering
131 : static OpenGLContext* GetDefaultContext();
132 :
133 : // create a new context for window rendering
134 : virtual OpenGLContext* CreateWinContext() = 0;
135 :
136 : // check whether the given context can be used by this instance
137 : virtual bool UseContext( OpenGLContext* pContext ) = 0;
138 :
139 : public:
140 : OpenGLSalGraphicsImpl(SalGraphics& pParent, SalGeometryProvider *pProvider);
141 : virtual ~OpenGLSalGraphicsImpl ();
142 :
143 : OpenGLContext* GetOpenGLContext();
144 :
145 : virtual void Init() SAL_OVERRIDE;
146 :
147 : virtual void freeResources() SAL_OVERRIDE;
148 :
149 : const vcl::Region& getClipRegion() const;
150 : virtual bool setClipRegion( const vcl::Region& ) SAL_OVERRIDE;
151 :
152 : //
153 : // get the depth of the device
154 : virtual sal_uInt16 GetBitCount() const SAL_OVERRIDE;
155 :
156 : // get the width of the device
157 : virtual long GetGraphicsWidth() const SAL_OVERRIDE;
158 :
159 : // set the clip region to empty
160 : virtual void ResetClipRegion() SAL_OVERRIDE;
161 :
162 : // set the line color to transparent (= don't draw lines)
163 :
164 : virtual void SetLineColor() SAL_OVERRIDE;
165 :
166 : // set the line color to a specific color
167 : virtual void SetLineColor( SalColor nSalColor ) SAL_OVERRIDE;
168 :
169 : // set the fill color to transparent (= don't fill)
170 : virtual void SetFillColor() SAL_OVERRIDE;
171 :
172 : // set the fill color to a specific color, shapes will be
173 : // filled accordingly
174 : virtual void SetFillColor( SalColor nSalColor ) SAL_OVERRIDE;
175 :
176 : // enable/disable XOR drawing
177 : virtual void SetXORMode( bool bSet, bool bInvertOnly ) SAL_OVERRIDE;
178 :
179 : // set line color for raster operations
180 : virtual void SetROPLineColor( SalROPColor nROPColor ) SAL_OVERRIDE;
181 :
182 : // set fill color for raster operations
183 : virtual void SetROPFillColor( SalROPColor nROPColor ) SAL_OVERRIDE;
184 :
185 : // draw --> LineColor and FillColor and RasterOp and ClipRegion
186 : virtual void drawPixel( long nX, long nY ) SAL_OVERRIDE;
187 : virtual void drawPixel( long nX, long nY, SalColor nSalColor ) SAL_OVERRIDE;
188 :
189 : virtual void drawLine( long nX1, long nY1, long nX2, long nY2 ) SAL_OVERRIDE;
190 :
191 : virtual void drawRect( long nX, long nY, long nWidth, long nHeight ) SAL_OVERRIDE;
192 :
193 : virtual void drawPolyLine( sal_uInt32 nPoints, const SalPoint* pPtAry ) SAL_OVERRIDE;
194 :
195 : virtual void drawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry ) SAL_OVERRIDE;
196 :
197 : virtual void drawPolyPolygon( sal_uInt32 nPoly, const sal_uInt32* pPoints, PCONSTSALPOINT* pPtAry ) SAL_OVERRIDE;
198 : virtual bool drawPolyPolygon( const ::basegfx::B2DPolyPolygon&, double fTransparency ) SAL_OVERRIDE;
199 :
200 : virtual bool drawPolyLine(
201 : const ::basegfx::B2DPolygon&,
202 : double fTransparency,
203 : const ::basegfx::B2DVector& rLineWidths,
204 : basegfx::B2DLineJoin,
205 : com::sun::star::drawing::LineCap) SAL_OVERRIDE;
206 :
207 : virtual bool drawPolyLineBezier(
208 : sal_uInt32 nPoints,
209 : const SalPoint* pPtAry,
210 : const sal_uInt8* pFlgAry ) SAL_OVERRIDE;
211 :
212 : virtual bool drawPolygonBezier(
213 : sal_uInt32 nPoints,
214 : const SalPoint* pPtAry,
215 : const sal_uInt8* pFlgAry ) SAL_OVERRIDE;
216 :
217 : virtual bool drawPolyPolygonBezier(
218 : sal_uInt32 nPoly,
219 : const sal_uInt32* pPoints,
220 : const SalPoint* const* pPtAry,
221 : const sal_uInt8* const* pFlgAry ) SAL_OVERRIDE;
222 :
223 : // CopyArea --> No RasterOp, but ClipRegion
224 : virtual void copyArea(
225 : long nDestX, long nDestY,
226 : long nSrcX, long nSrcY,
227 : long nSrcWidth, long nSrcHeight,
228 : sal_uInt16 nFlags ) SAL_OVERRIDE;
229 :
230 : // CopyBits and DrawBitmap --> RasterOp and ClipRegion
231 : // CopyBits() --> pSrcGraphics == NULL, then CopyBits on same Graphics
232 : void DoCopyBits(const SalTwoRect& rPosAry, OpenGLSalGraphicsImpl &rSrcImpl);
233 :
234 : virtual bool blendBitmap(
235 : const SalTwoRect&,
236 : const SalBitmap& rBitmap ) SAL_OVERRIDE;
237 :
238 : virtual bool blendAlphaBitmap(
239 : const SalTwoRect&,
240 : const SalBitmap& rSrcBitmap,
241 : const SalBitmap& rMaskBitmap,
242 : const SalBitmap& rAlphaBitmap ) SAL_OVERRIDE;
243 :
244 : virtual void drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap ) SAL_OVERRIDE;
245 :
246 : virtual void drawBitmap(
247 : const SalTwoRect& rPosAry,
248 : const SalBitmap& rSalBitmap,
249 : SalColor nTransparentColor ) SAL_OVERRIDE;
250 :
251 : virtual void drawBitmap(
252 : const SalTwoRect& rPosAry,
253 : const SalBitmap& rSalBitmap,
254 : const SalBitmap& rMaskBitmap ) SAL_OVERRIDE;
255 :
256 : virtual void drawMask(
257 : const SalTwoRect& rPosAry,
258 : const SalBitmap& rSalBitmap,
259 : SalColor nMaskColor ) SAL_OVERRIDE;
260 :
261 : virtual SalBitmap* getBitmap( long nX, long nY, long nWidth, long nHeight ) SAL_OVERRIDE;
262 :
263 : virtual SalColor getPixel( long nX, long nY ) SAL_OVERRIDE;
264 :
265 : // invert --> ClipRegion (only Windows or VirDevs)
266 : virtual void invert(
267 : long nX, long nY,
268 : long nWidth, long nHeight,
269 : SalInvert nFlags) SAL_OVERRIDE;
270 :
271 : virtual void invert( sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert nFlags ) SAL_OVERRIDE;
272 :
273 : virtual bool drawEPS(
274 : long nX, long nY,
275 : long nWidth, long nHeight,
276 : void* pPtr,
277 : sal_uLong nSize ) SAL_OVERRIDE;
278 :
279 : /** Render bitmap with alpha channel
280 :
281 : @param rSourceBitmap
282 : Source bitmap to blit
283 :
284 : @param rAlphaBitmap
285 : Alpha channel to use for blitting
286 :
287 : @return true, if the operation succeeded, and false
288 : otherwise. In this case, clients should try to emulate alpha
289 : compositing themselves
290 : */
291 : virtual bool drawAlphaBitmap(
292 : const SalTwoRect&,
293 : const SalBitmap& rSourceBitmap,
294 : const SalBitmap& rAlphaBitmap ) SAL_OVERRIDE;
295 :
296 : /** draw transformed bitmap (maybe with alpha) where Null, X, Y define the coordinate system */
297 : virtual bool drawTransformedBitmap(
298 : const basegfx::B2DPoint& rNull,
299 : const basegfx::B2DPoint& rX,
300 : const basegfx::B2DPoint& rY,
301 : const SalBitmap& rSourceBitmap,
302 : const SalBitmap* pAlphaBitmap) SAL_OVERRIDE;
303 :
304 : /** Render solid rectangle with given transparency
305 :
306 : @param nTransparency
307 : Transparency value (0-255) to use. 0 blits and opaque, 255 a
308 : fully transparent rectangle
309 : */
310 : virtual bool drawAlphaRect(
311 : long nX, long nY,
312 : long nWidth, long nHeight,
313 : sal_uInt8 nTransparency ) SAL_OVERRIDE;
314 :
315 : virtual bool drawGradient(const tools::PolyPolygon& rPolygon, const Gradient& rGradient) SAL_OVERRIDE;
316 :
317 : virtual void beginPaint() SAL_OVERRIDE;
318 : virtual void endPaint() SAL_OVERRIDE;
319 : private:
320 : };
321 :
322 : #endif
323 :
324 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|