blob: b39c866c6f89c3f2620d32af950f33496e4ede58 [file] [log] [blame]
cdaltonc7103a12014-08-11 14:05:05 -07001/*
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"
kkinnunenccdaa042014-08-20 01:36:23 -070012#include "GrPathRendering.h"
13#include "GrStencil.h"
bsalomon2fc11d32015-10-19 09:03:23 -070014#include "gl/GrGLTypes.h"
egdaniel64c47282015-11-13 06:54:19 -080015#include "glsl/GrGLSLUtil.h"
cdaltonc7103a12014-08-11 14:05:05 -070016
17class GrGLNameAllocator;
bsalomon861e1032014-12-16 07:33:49 -080018class GrGLGpu;
cdaltonc7103a12014-08-11 14:05:05 -070019
20/**
21 * This class wraps the NV_path_rendering extension and manages its various
bsalomon861e1032014-12-16 07:33:49 -080022 * API versions. If a method is not present in the GrGLInterface of the GrGLGpu
kkinnunenccdaa042014-08-20 01:36:23 -070023 * (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.
cdaltonc7103a12014-08-11 14:05:05 -070026 */
kkinnunenccdaa042014-08-20 01:36:23 -070027class GrGLPathRendering : public GrPathRendering {
cdaltonc7103a12014-08-11 14:05:05 -070028public:
29 /**
bsalomon861e1032014-12-16 07:33:49 -080030 * Create a new GrGLPathRendering object from a given GrGLGpu.
cdaltonc7103a12014-08-11 14:05:05 -070031 */
bsalomon861e1032014-12-16 07:33:49 -080032 GrGLPathRendering(GrGLGpu* gpu);
cdaltonc7103a12014-08-11 14:05:05 -070033 virtual ~GrGLPathRendering();
34
kkinnunenccdaa042014-08-20 01:36:23 -070035 // GrPathRendering implementations.
kkinnunen50b58e62015-05-18 23:02:07 -070036 GrPath* createPath(const SkPath&, const GrStrokeInfo&) override;
cdalton855d83f2014-09-18 13:51:53 -070037 virtual GrPathRange* createPathRange(GrPathRange::PathGenerator*,
kkinnunen50b58e62015-05-18 23:02:07 -070038 const GrStrokeInfo&) override;
kkinnunenccdaa042014-08-20 01:36:23 -070039
kkinnunenccdaa042014-08-20 01:36:23 -070040 /* Called when the 3D context state is unknown. */
41 void resetContext();
42
cdaltonc7103a12014-08-11 14:05:05 -070043 /**
bsalomon6e2aad42016-04-01 11:54:31 -070044 * 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.
cdaltonc7103a12014-08-11 14:05:05 -070046 */
bsalomon6e2aad42016-04-01 11:54:31 -070047 void disconnect(GrGpu::DisconnectType);
cdaltonc7103a12014-08-11 14:05:05 -070048
kkinnunen6bb6d402015-07-14 10:59:23 -070049 bool shouldBindFragmentInputs() const {
50 return fCaps.bindFragmentInputSupport;
51 }
52
kkinnunen5b653572014-08-20 04:13:27 -070053 // 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 */
kkinnunenccdaa042014-08-20 01:36:23 -070059 void setProjectionMatrix(const SkMatrix& matrix,
60 const SkISize& renderTargetSize,
61 GrSurfaceOrigin renderTargetOrigin);
62
cdaltonc7103a12014-08-11 14:05:05 -070063 GrGLuint genPaths(GrGLsizei range);
64 GrGLvoid deletePaths(GrGLuint path, GrGLsizei range);
kkinnunen5b653572014-08-20 04:13:27 -070065
kkinnunencabe20c2015-06-01 01:37:26 -070066protected:
67 void onStencilPath(const StencilPathArgs&, const GrPath*) override;
egdaniel0e1853c2016-03-17 11:35:45 -070068 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;
kkinnunen5b653572014-08-20 04:13:27 -070081private:
kkinnunen6bb6d402015-07-14 10:59:23 -070082 /**
83 * Mark certain functionality as not supported.
84 */
85 struct Caps {
86 bool bindFragmentInputSupport : 1;
87 };
88
joshualitt92e496f2014-10-31 13:56:50 -070089 void flushPathStencilSettings(const GrStencilSettings&);
cdaltonc7103a12014-08-11 14:05:05 -070090
joshualittee2af952014-12-30 09:04:15 -080091 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 */
egdaniel018fb622015-10-28 07:26:40 -0700107 template<int Size> void getRTAdjustedGLMatrix(float* destMatrix) {
joshualittee2af952014-12-30 09:04:15 -0800108 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);
egdaniel64c47282015-11-13 06:54:19 -0800119 GrGLSLGetMatrix<Size>(destMatrix, combined);
joshualittee2af952014-12-30 09:04:15 -0800120 }
121 };
kkinnunencabe20c2015-06-01 01:37:26 -0700122 GrGLGpu* gpu();
joshualittee2af952014-12-30 09:04:15 -0800123
kkinnunen702501d2016-01-13 23:36:45 -0800124 GrGLuint fFirstPreallocatedPathID;
125 GrGLsizei fPreallocatedPathCount;
joshualittee2af952014-12-30 09:04:15 -0800126 MatrixState fHWProjectionMatrixState;
kkinnunenccdaa042014-08-20 01:36:23 -0700127 GrStencilSettings fHWPathStencilSettings;
kkinnunen6bb6d402015-07-14 10:59:23 -0700128 Caps fCaps;
cdaltonc7103a12014-08-11 14:05:05 -0700129};
130
131#endif