Line data Source code
1 : /*
2 : * Copyright 2014 Google Inc.
3 : *
4 : * Use of this source code is governed by a BSD-style license that can be
5 : * found in the LICENSE file.
6 : */
7 :
8 : #ifndef GrGLPathRendering_DEFINED
9 : #define GrGLPathRendering_DEFINED
10 :
11 : #include "SkRefCnt.h"
12 : #include "GrPathRendering.h"
13 : #include "GrStencilSettings.h"
14 : #include "gl/GrGLTypes.h"
15 : #include "glsl/GrGLSLUtil.h"
16 :
17 : class GrGLNameAllocator;
18 : class GrGLGpu;
19 : class GrStyle;
20 :
21 : /**
22 : * This class wraps the NV_path_rendering extension and manages its various
23 : * API versions. If a method is not present in the GrGLInterface of the GrGLGpu
24 : * (because the driver version is old), it tries to provide a backup
25 : * implementation. But if a backup implementation is not practical, it marks the
26 : * method as not supported.
27 : */
28 : class GrGLPathRendering : public GrPathRendering {
29 : public:
30 : /**
31 : * Create a new GrGLPathRendering object from a given GrGLGpu.
32 : */
33 : GrGLPathRendering(GrGLGpu* gpu);
34 : ~GrGLPathRendering() override;
35 :
36 : // GrPathRendering implementations.
37 : GrPath* createPath(const SkPath&, const GrStyle&) override;
38 : virtual GrPathRange* createPathRange(GrPathRange::PathGenerator*,
39 : const GrStyle&) override;
40 :
41 : /* Called when the 3D context state is unknown. */
42 : void resetContext();
43 :
44 : /**
45 : * Called when the context either is about to be lost or is lost. DisconnectType indicates
46 : * whether GPU resources should be cleaned up or abandoned when this is called.
47 : */
48 : void disconnect(GrGpu::DisconnectType);
49 :
50 0 : bool shouldBindFragmentInputs() const {
51 0 : return fCaps.bindFragmentInputSupport;
52 : }
53 :
54 : // Functions for "separable shader" texturing support.
55 : void setProgramPathFragmentInputTransform(GrGLuint program, GrGLint location,
56 : GrGLenum genMode, GrGLint components,
57 : const SkMatrix&);
58 :
59 : /* Sets the projection matrix for path rendering */
60 : void setProjectionMatrix(const SkMatrix& matrix,
61 : const SkISize& renderTargetSize,
62 : GrSurfaceOrigin renderTargetOrigin);
63 :
64 : GrGLuint genPaths(GrGLsizei range);
65 : GrGLvoid deletePaths(GrGLuint path, GrGLsizei range);
66 :
67 : protected:
68 : void onStencilPath(const StencilPathArgs&, const GrPath*) override;
69 : void onDrawPath(const GrPipeline&,
70 : const GrPrimitiveProcessor&,
71 : const GrStencilSettings&,
72 : const GrPath*) override;
73 : void onDrawPaths(const GrPipeline&,
74 : const GrPrimitiveProcessor&,
75 : const GrStencilSettings&,
76 : const GrPathRange*,
77 : const void* indices,
78 : PathIndexType,
79 : const float transformValues[],
80 : PathTransformType,
81 : int count) override;
82 : private:
83 : /**
84 : * Mark certain functionality as not supported.
85 : */
86 : struct Caps {
87 : bool bindFragmentInputSupport : 1;
88 : };
89 :
90 : void flushPathStencilSettings(const GrStencilSettings&);
91 :
92 : struct MatrixState {
93 : SkMatrix fViewMatrix;
94 : SkISize fRenderTargetSize;
95 : GrSurfaceOrigin fRenderTargetOrigin;
96 :
97 0 : MatrixState() { this->invalidate(); }
98 0 : void invalidate() {
99 0 : fViewMatrix = SkMatrix::InvalidMatrix();
100 0 : fRenderTargetSize.fWidth = -1;
101 0 : fRenderTargetSize.fHeight = -1;
102 0 : fRenderTargetOrigin = (GrSurfaceOrigin) -1;
103 0 : }
104 :
105 : /**
106 : * Gets a matrix that goes from local coordinates to GL normalized device coords.
107 : */
108 0 : template<int Size> void getRTAdjustedGLMatrix(float* destMatrix) {
109 : SkMatrix combined;
110 0 : if (kBottomLeft_GrSurfaceOrigin == fRenderTargetOrigin) {
111 0 : combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1,
112 0 : 0, -SkIntToScalar(2) / fRenderTargetSize.fHeight, SK_Scalar1,
113 : 0, 0, 1);
114 : } else {
115 0 : combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1,
116 0 : 0, SkIntToScalar(2) / fRenderTargetSize.fHeight, -SK_Scalar1,
117 : 0, 0, 1);
118 : }
119 0 : combined.preConcat(fViewMatrix);
120 0 : GrGLSLGetMatrix<Size>(destMatrix, combined);
121 0 : }
122 : };
123 : GrGLGpu* gpu();
124 :
125 : GrGLuint fFirstPreallocatedPathID;
126 : GrGLsizei fPreallocatedPathCount;
127 : MatrixState fHWProjectionMatrixState;
128 : GrStencilSettings fHWPathStencilSettings;
129 : Caps fCaps;
130 : };
131 :
132 : #endif
|