2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrGLPathRendering_DEFINED
9 #define GrGLPathRendering_DEFINED
12 #include "GrPathRendering.h"
13 #include "GrStencil.h"
14 #include "gl/GrGLTypes.h"
15 #include "glsl/GrGLSLUtil.h"
17 class GrGLNameAllocator;
21 * This class wraps the NV_path_rendering extension and manages its various
22 * API versions. If a method is not present in the GrGLInterface of the GrGLGpu
23 * (because the driver version is old), it tries to provide a backup
24 * implementation. But if a backup implementation is not practical, it marks the
25 * method as not supported.
27 class GrGLPathRendering : public GrPathRendering {
30 * Create a new GrGLPathRendering object from a given GrGLGpu.
32 GrGLPathRendering(GrGLGpu* gpu);
33 virtual ~GrGLPathRendering();
35 // GrPathRendering implementations.
36 GrPath* createPath(const SkPath&, const GrStrokeInfo&) override;
37 virtual GrPathRange* createPathRange(GrPathRange::PathGenerator*,
38 const GrStrokeInfo&) override;
40 /* Called when the 3D context state is unknown. */
44 * Called when the GPU resources have been lost and need to be abandoned
45 * (for example after a context loss).
47 void abandonGpuResources();
49 bool shouldBindFragmentInputs() const {
50 return fCaps.bindFragmentInputSupport;
53 // Functions for "separable shader" texturing support.
54 void setProgramPathFragmentInputTransform(GrGLuint program, GrGLint location,
55 GrGLenum genMode, GrGLint components,
58 /* Sets the projection matrix for path rendering */
59 void setProjectionMatrix(const SkMatrix& matrix,
60 const SkISize& renderTargetSize,
61 GrSurfaceOrigin renderTargetOrigin);
63 GrGLuint genPaths(GrGLsizei range);
64 GrGLvoid deletePaths(GrGLuint path, GrGLsizei range);
67 void onStencilPath(const StencilPathArgs&, const GrPath*) override;
68 void onDrawPath(const DrawPathArgs&, const GrPath*) override;
69 void onDrawPaths(const DrawPathArgs&, const GrPathRange*, const void* indices, PathIndexType,
70 const float transformValues[], PathTransformType, int count) override;
73 * Mark certain functionality as not supported.
76 bool bindFragmentInputSupport : 1;
79 void flushPathStencilSettings(const GrStencilSettings&);
83 SkISize fRenderTargetSize;
84 GrSurfaceOrigin fRenderTargetOrigin;
86 MatrixState() { this->invalidate(); }
88 fViewMatrix = SkMatrix::InvalidMatrix();
89 fRenderTargetSize.fWidth = -1;
90 fRenderTargetSize.fHeight = -1;
91 fRenderTargetOrigin = (GrSurfaceOrigin) -1;
95 * Gets a matrix that goes from local coordinates to GL normalized device coords.
97 template<int Size> void getRTAdjustedGLMatrix(float* destMatrix) {
99 if (kBottomLeft_GrSurfaceOrigin == fRenderTargetOrigin) {
100 combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1,
101 0, -SkIntToScalar(2) / fRenderTargetSize.fHeight, SK_Scalar1,
104 combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1,
105 0, SkIntToScalar(2) / fRenderTargetSize.fHeight, -SK_Scalar1,
108 combined.preConcat(fViewMatrix);
109 GrGLSLGetMatrix<Size>(destMatrix, combined);
114 SkAutoTDelete<GrGLNameAllocator> fPathNameAllocator;
115 MatrixState fHWProjectionMatrixState;
116 GrStencilSettings fHWPathStencilSettings;