cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 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" |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 12 | #include "GrPathRendering.h" |
| 13 | #include "GrStencil.h" |
bsalomon | 2fc11d3 | 2015-10-19 09:03:23 -0700 | [diff] [blame] | 14 | #include "gl/GrGLTypes.h" |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 15 | #include "glsl/GrGLSLUtil.h" |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 16 | |
| 17 | class GrGLNameAllocator; |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 18 | class GrGLGpu; |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * This class wraps the NV_path_rendering extension and manages its various |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 22 | * API versions. If a method is not present in the GrGLInterface of the GrGLGpu |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 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. |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 26 | */ |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 27 | class GrGLPathRendering : public GrPathRendering { |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 28 | public: |
| 29 | /** |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 30 | * Create a new GrGLPathRendering object from a given GrGLGpu. |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 31 | */ |
bsalomon | 861e103 | 2014-12-16 07:33:49 -0800 | [diff] [blame] | 32 | GrGLPathRendering(GrGLGpu* gpu); |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 33 | virtual ~GrGLPathRendering(); |
| 34 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 35 | // GrPathRendering implementations. |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 36 | GrPath* createPath(const SkPath&, const GrStrokeInfo&) override; |
cdalton | 855d83f | 2014-09-18 13:51:53 -0700 | [diff] [blame] | 37 | virtual GrPathRange* createPathRange(GrPathRange::PathGenerator*, |
kkinnunen | 50b58e6 | 2015-05-18 23:02:07 -0700 | [diff] [blame] | 38 | const GrStrokeInfo&) override; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 39 | |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 40 | /* Called when the 3D context state is unknown. */ |
| 41 | void resetContext(); |
| 42 | |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 43 | /** |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame^] | 44 | * Called when the context either is about to be lost or is lost. DisconnectType indicates |
| 45 | * whether GPU resources should be cleaned up or abandoned when this is called. |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 46 | */ |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame^] | 47 | void disconnect(GrGpu::DisconnectType); |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 48 | |
kkinnunen | 6bb6d40 | 2015-07-14 10:59:23 -0700 | [diff] [blame] | 49 | bool shouldBindFragmentInputs() const { |
| 50 | return fCaps.bindFragmentInputSupport; |
| 51 | } |
| 52 | |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 53 | // Functions for "separable shader" texturing support. |
| 54 | void setProgramPathFragmentInputTransform(GrGLuint program, GrGLint location, |
| 55 | GrGLenum genMode, GrGLint components, |
| 56 | const SkMatrix&); |
| 57 | |
| 58 | /* Sets the projection matrix for path rendering */ |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 59 | void setProjectionMatrix(const SkMatrix& matrix, |
| 60 | const SkISize& renderTargetSize, |
| 61 | GrSurfaceOrigin renderTargetOrigin); |
| 62 | |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 63 | GrGLuint genPaths(GrGLsizei range); |
| 64 | GrGLvoid deletePaths(GrGLuint path, GrGLsizei range); |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 65 | |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 66 | protected: |
| 67 | void onStencilPath(const StencilPathArgs&, const GrPath*) override; |
egdaniel | 0e1853c | 2016-03-17 11:35:45 -0700 | [diff] [blame] | 68 | void onDrawPath(const GrPipeline&, |
| 69 | const GrPrimitiveProcessor&, |
| 70 | const GrStencilSettings&, |
| 71 | const GrPath*) override; |
| 72 | void onDrawPaths(const GrPipeline&, |
| 73 | const GrPrimitiveProcessor&, |
| 74 | const GrStencilSettings&, |
| 75 | const GrPathRange*, |
| 76 | const void* indices, |
| 77 | PathIndexType, |
| 78 | const float transformValues[], |
| 79 | PathTransformType, |
| 80 | int count) override; |
kkinnunen | 5b65357 | 2014-08-20 04:13:27 -0700 | [diff] [blame] | 81 | private: |
kkinnunen | 6bb6d40 | 2015-07-14 10:59:23 -0700 | [diff] [blame] | 82 | /** |
| 83 | * Mark certain functionality as not supported. |
| 84 | */ |
| 85 | struct Caps { |
| 86 | bool bindFragmentInputSupport : 1; |
| 87 | }; |
| 88 | |
joshualitt | 92e496f | 2014-10-31 13:56:50 -0700 | [diff] [blame] | 89 | void flushPathStencilSettings(const GrStencilSettings&); |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 90 | |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 91 | struct MatrixState { |
| 92 | SkMatrix fViewMatrix; |
| 93 | SkISize fRenderTargetSize; |
| 94 | GrSurfaceOrigin fRenderTargetOrigin; |
| 95 | |
| 96 | MatrixState() { this->invalidate(); } |
| 97 | void invalidate() { |
| 98 | fViewMatrix = SkMatrix::InvalidMatrix(); |
| 99 | fRenderTargetSize.fWidth = -1; |
| 100 | fRenderTargetSize.fHeight = -1; |
| 101 | fRenderTargetOrigin = (GrSurfaceOrigin) -1; |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Gets a matrix that goes from local coordinates to GL normalized device coords. |
| 106 | */ |
egdaniel | 018fb62 | 2015-10-28 07:26:40 -0700 | [diff] [blame] | 107 | template<int Size> void getRTAdjustedGLMatrix(float* destMatrix) { |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 108 | SkMatrix combined; |
| 109 | if (kBottomLeft_GrSurfaceOrigin == fRenderTargetOrigin) { |
| 110 | combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1, |
| 111 | 0, -SkIntToScalar(2) / fRenderTargetSize.fHeight, SK_Scalar1, |
| 112 | 0, 0, 1); |
| 113 | } else { |
| 114 | combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1, |
| 115 | 0, SkIntToScalar(2) / fRenderTargetSize.fHeight, -SK_Scalar1, |
| 116 | 0, 0, 1); |
| 117 | } |
| 118 | combined.preConcat(fViewMatrix); |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 119 | GrGLSLGetMatrix<Size>(destMatrix, combined); |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 120 | } |
| 121 | }; |
kkinnunen | cabe20c | 2015-06-01 01:37:26 -0700 | [diff] [blame] | 122 | GrGLGpu* gpu(); |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 123 | |
kkinnunen | 702501d | 2016-01-13 23:36:45 -0800 | [diff] [blame] | 124 | GrGLuint fFirstPreallocatedPathID; |
| 125 | GrGLsizei fPreallocatedPathCount; |
joshualitt | ee2af95 | 2014-12-30 09:04:15 -0800 | [diff] [blame] | 126 | MatrixState fHWProjectionMatrixState; |
kkinnunen | ccdaa04 | 2014-08-20 01:36:23 -0700 | [diff] [blame] | 127 | GrStencilSettings fHWPathStencilSettings; |
kkinnunen | 6bb6d40 | 2015-07-14 10:59:23 -0700 | [diff] [blame] | 128 | Caps fCaps; |
cdalton | c7103a1 | 2014-08-11 14:05:05 -0700 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | #endif |